Version Description
- updated to the latest version of the timthumb 2.8.10
Download this release
Release Info
Developer | oltdev |
Plugin | User Avatar |
Version | 1.4.8 |
Comparing to | |
See all releases |
Code changes from version 1.2 to 1.4.8
- css/user-avatar.css +51 -14
- languages/user-avatar-es_ES.mo +0 -0
- languages/user-avatar-es_ES.po +83 -0
- languages/user-avatar-it_IT.mo +0 -0
- languages/user-avatar-it_IT.po +83 -0
- languages/user-avatar-ru_RU.mo +0 -0
- languages/user-avatar-ru_RU.po +83 -0
- languages/user-avatar-zh_CN.mo +0 -0
- languages/user-avatar-zh_CN.po +83 -0
- languages/user-avatar.POT +81 -0
- readme.txt +64 -4
- screenshot-1.png +0 -0
- screenshot-5.png +0 -0
- screenshot-6.png +0 -0
- timthumb-config.php +44 -0
- user-avatar-pic.php +1244 -0
- user-avatar.php +252 -198
css/user-avatar.css
CHANGED
@@ -40,27 +40,64 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
40 |
float:left;
|
41 |
margin: 15px 0px 0px 15px;
|
42 |
}
|
|
|
|
|
|
|
43 |
#user-avatar-display{
|
44 |
-
position:absolute;
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
52 |
}
|
53 |
#user-avatar-display-image{
|
54 |
-
border:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
55 |
}
|
56 |
#user-avatar-link{
|
57 |
-
|
58 |
-
margin:0 0 10px 30px;
|
59 |
}
|
60 |
#user-avatar-remove{
|
61 |
-
|
62 |
-
|
63 |
-
margin:0 0 0 18px;
|
64 |
}
|
65 |
#uploadForm{
|
66 |
margin-left:230px;
|
40 |
float:left;
|
41 |
margin: 15px 0px 0px 15px;
|
42 |
}
|
43 |
+
.folded #user-avatar-display{
|
44 |
+
left:750px;
|
45 |
+
}
|
46 |
#user-avatar-display{
|
47 |
+
position: absolute;
|
48 |
+
top:100px;
|
49 |
+
right: 10%;
|
50 |
+
left:900px;
|
51 |
+
text-align: center;
|
52 |
+
padding: 0 10px 10px;
|
53 |
+
width: 170px;
|
54 |
+
background: #EEE;
|
55 |
+
-moz-border-radius: 6px; /* FF1+ */
|
56 |
+
-webkit-border-radius: 6px; /* Saf3-4, iOS 1+, Android 1.5+ */
|
57 |
+
border-radius: 6px; /* Opera 10.5, IE9, Saf5, Chrome, FF4 */
|
58 |
+
}
|
59 |
+
|
60 |
+
@media all and (max-width: 1104px) {
|
61 |
+
#user-avatar-display {
|
62 |
+
left: auto;
|
63 |
+
right:0;
|
64 |
+
|
65 |
+
}
|
66 |
+
}
|
67 |
+
|
68 |
+
@media all and (max-width: 930px) {
|
69 |
+
.folded #user-avatar-display {
|
70 |
+
left: auto;
|
71 |
+
right:0;
|
72 |
+
|
73 |
+
}
|
74 |
+
}
|
75 |
+
|
76 |
+
#user-avatar-display h3{
|
77 |
+
margin-bottom: 0;
|
78 |
+
margin-top: 5px;
|
79 |
+
text-shadow: 0 1px 0 #FFFFFF;
|
80 |
+
text-align: left;
|
81 |
+
font-size: 12px;
|
82 |
+
|
83 |
}
|
84 |
#user-avatar-display-image{
|
85 |
+
border:3px solid #E3E3E3;
|
86 |
+
background: #FFF;
|
87 |
+
padding: 8px;
|
88 |
+
width: 150px;
|
89 |
+
margin-top:2px;
|
90 |
+
border:1px solid #E3E3E3;
|
91 |
+
-moz-border-radius: 6px; /* FF1+ */
|
92 |
+
-webkit-border-radius: 6px; /* Saf3-4, iOS 1+, Android 1.5+ */
|
93 |
+
border-radius: 6px; /* Opera 10.5, IE9, Saf5, Chrome, FF4 */
|
94 |
}
|
95 |
#user-avatar-link{
|
96 |
+
user-avatar-remove
|
|
|
97 |
}
|
98 |
#user-avatar-remove{
|
99 |
+
font-size: 11px;
|
100 |
+
|
|
|
101 |
}
|
102 |
#uploadForm{
|
103 |
margin-left:230px;
|
languages/user-avatar-es_ES.mo
ADDED
Binary file
|
languages/user-avatar-es_ES.po
ADDED
@@ -0,0 +1,83 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
msgid ""
|
2 |
+
msgstr ""
|
3 |
+
"Project-Id-Version: User Avatar 1.3.3\n"
|
4 |
+
"Report-Msgid-Bugs-To: \n"
|
5 |
+
"POT-Creation-Date: 2011-03-22 11:20+0100\n"
|
6 |
+
"PO-Revision-Date: 2011-09-30 16:48+0100\n"
|
7 |
+
"Last-Translator: Gabriel <Gabriel@ElFrutero.es>\n"
|
8 |
+
"Language-Team: INTERNOZEROUNO <info@interno01.it>\n"
|
9 |
+
"MIME-Version: 1.0\n"
|
10 |
+
"Content-Type: text/plain; charset=UTF-8\n"
|
11 |
+
"Content-Transfer-Encoding: 8bit\n"
|
12 |
+
"X-Poedit-KeywordsList: __;gettext;gettext_noop;_e\n"
|
13 |
+
"X-Poedit-Basepath: .\n"
|
14 |
+
"X-Poedit-Language: Italian\n"
|
15 |
+
"X-Poedit-Country: ITALY\n"
|
16 |
+
"X-Poedit-SourceCharset: utf-8\n"
|
17 |
+
"X-Poedit-SearchPath-0: ..\n"
|
18 |
+
|
19 |
+
#: ../user-avatar.php:157
|
20 |
+
msgid "Uploads"
|
21 |
+
msgstr "Subidas"
|
22 |
+
|
23 |
+
#: ../user-avatar.php:157
|
24 |
+
msgid "WordPress"
|
25 |
+
msgstr "WordPress"
|
26 |
+
|
27 |
+
#: ../user-avatar.php:190
|
28 |
+
msgid "You are not allowed to do that."
|
29 |
+
msgstr "No estás autorizado a hacer eso."
|
30 |
+
|
31 |
+
#: ../user-avatar.php:213
|
32 |
+
msgid "Choose an image from your computer:"
|
33 |
+
msgstr "Selecciona una imagen desde tu ordenador:"
|
34 |
+
|
35 |
+
#: ../user-avatar.php:236
|
36 |
+
msgid "Please upload an image file (.jpeg, .gif, .png)."
|
37 |
+
msgstr "Por favor, sube un archivo de imagen (.jpeg, .gif, .png)."
|
38 |
+
|
39 |
+
#: ../user-avatar.php:278
|
40 |
+
msgid "Choose the part of the image you want to use as your profile image."
|
41 |
+
msgstr "Escoge la parte de la imagen que quieres usar como tu imagen de perfil."
|
42 |
+
|
43 |
+
#: ../user-avatar.php:390
|
44 |
+
msgid "Sorry, No file available"
|
45 |
+
msgstr "Perdona, archivo no disponible."
|
46 |
+
|
47 |
+
#: ../user-avatar.php:414
|
48 |
+
msgid "Image could not be processed. Please go back and try again."
|
49 |
+
msgstr "La imagen no puede ser procesada. Por favot, vuelve e inténtalo de nuevo."
|
50 |
+
|
51 |
+
#: ../user-avatar.php:414
|
52 |
+
msgid "Image Processing Error"
|
53 |
+
msgstr "Error procesando la imagen."
|
54 |
+
|
55 |
+
#: ../user-avatar.php:421
|
56 |
+
msgid "Here's your new profile picture..."
|
57 |
+
msgstr "Aquí tenemos tu nueva imagen de perfil..."
|
58 |
+
|
59 |
+
#: ../user-avatar.php:427
|
60 |
+
msgid "Close"
|
61 |
+
msgstr "Cerrar"
|
62 |
+
|
63 |
+
#: ../user-avatar.php:710
|
64 |
+
msgid "Picture"
|
65 |
+
msgstr "Imagen"
|
66 |
+
|
67 |
+
#: ../user-avatar.php:712
|
68 |
+
msgid "Upload and Crop an Image to be Displayed"
|
69 |
+
msgstr "Subir y recortar una imagen para mostrar"
|
70 |
+
|
71 |
+
#: ../user-avatar.php:712
|
72 |
+
msgid "Update Picture"
|
73 |
+
msgstr "Actualizar imagen"
|
74 |
+
|
75 |
+
#: ../user-avatar.php:724
|
76 |
+
msgid "Remove User Avatar Image"
|
77 |
+
msgstr "Eliminar imagen"
|
78 |
+
|
79 |
+
#: ../user-avatar.php:724
|
80 |
+
#: ../user-avatar.php:735
|
81 |
+
msgid "Remove"
|
82 |
+
msgstr "Eliminar"
|
83 |
+
|
languages/user-avatar-it_IT.mo
ADDED
Binary file
|
languages/user-avatar-it_IT.po
ADDED
@@ -0,0 +1,83 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
msgid ""
|
2 |
+
msgstr ""
|
3 |
+
"Project-Id-Version: User Avatar 1.3.3\n"
|
4 |
+
"Report-Msgid-Bugs-To: \n"
|
5 |
+
"POT-Creation-Date: 2011-03-22 11:20+0100\n"
|
6 |
+
"PO-Revision-Date: 2011-03-22 11:26+0100\n"
|
7 |
+
"Last-Translator: Mirko <mirko@interno01.it>\n"
|
8 |
+
"Language-Team: INTERNOZEROUNO <info@interno01.it>\n"
|
9 |
+
"MIME-Version: 1.0\n"
|
10 |
+
"Content-Type: text/plain; charset=UTF-8\n"
|
11 |
+
"Content-Transfer-Encoding: 8bit\n"
|
12 |
+
"X-Poedit-KeywordsList: __;gettext;gettext_noop;_e\n"
|
13 |
+
"X-Poedit-Basepath: .\n"
|
14 |
+
"X-Poedit-Language: Italian\n"
|
15 |
+
"X-Poedit-Country: ITALY\n"
|
16 |
+
"X-Poedit-SourceCharset: utf-8\n"
|
17 |
+
"X-Poedit-SearchPath-0: ..\n"
|
18 |
+
|
19 |
+
#: ../user-avatar.php:157
|
20 |
+
msgid "Uploads"
|
21 |
+
msgstr "Caricamenti"
|
22 |
+
|
23 |
+
#: ../user-avatar.php:157
|
24 |
+
msgid "WordPress"
|
25 |
+
msgstr ""
|
26 |
+
|
27 |
+
#: ../user-avatar.php:190
|
28 |
+
msgid "You are not allowed to do that."
|
29 |
+
msgstr "Non hai l'autorizzazione per questo."
|
30 |
+
|
31 |
+
#: ../user-avatar.php:213
|
32 |
+
msgid "Choose an image from your computer:"
|
33 |
+
msgstr "Seleziona un'immagine dal tuo computer:"
|
34 |
+
|
35 |
+
#: ../user-avatar.php:236
|
36 |
+
msgid "Please upload an image file (.jpeg, .gif, .png)."
|
37 |
+
msgstr "Carica un file di immagine (.jpg, .gif o .png)."
|
38 |
+
|
39 |
+
#: ../user-avatar.php:278
|
40 |
+
msgid "Choose the part of the image you want to use as your profile image."
|
41 |
+
msgstr "Scegli la porzione di immagine che vuoi usare per il tuo profilo."
|
42 |
+
|
43 |
+
#: ../user-avatar.php:390
|
44 |
+
msgid "Sorry, No file available"
|
45 |
+
msgstr "Nessun file disponibile"
|
46 |
+
|
47 |
+
#: ../user-avatar.php:414
|
48 |
+
msgid "Image could not be processed. Please go back and try again."
|
49 |
+
msgstr "L'immagine non può essere elaborata. Torna indietro e riprova."
|
50 |
+
|
51 |
+
#: ../user-avatar.php:414
|
52 |
+
msgid "Image Processing Error"
|
53 |
+
msgstr "Errore nell'elaborazione dell'immagine"
|
54 |
+
|
55 |
+
#: ../user-avatar.php:421
|
56 |
+
msgid "Here's your new profile picture..."
|
57 |
+
msgstr "Ecco la tua nuova immagine del profilo..."
|
58 |
+
|
59 |
+
#: ../user-avatar.php:427
|
60 |
+
msgid "Close"
|
61 |
+
msgstr "Chiudi"
|
62 |
+
|
63 |
+
#: ../user-avatar.php:710
|
64 |
+
msgid "Picture"
|
65 |
+
msgstr "Immagine"
|
66 |
+
|
67 |
+
#: ../user-avatar.php:712
|
68 |
+
msgid "Upload and Crop an Image to be Displayed"
|
69 |
+
msgstr "Carica e Ritaglia l'immagine che deve essere utilizzata"
|
70 |
+
|
71 |
+
#: ../user-avatar.php:712
|
72 |
+
msgid "Update Picture"
|
73 |
+
msgstr "Carica immagine"
|
74 |
+
|
75 |
+
#: ../user-avatar.php:724
|
76 |
+
msgid "Remove User Avatar Image"
|
77 |
+
msgstr "Rimuovi l'immagine"
|
78 |
+
|
79 |
+
#: ../user-avatar.php:724
|
80 |
+
#: ../user-avatar.php:735
|
81 |
+
msgid "Remove"
|
82 |
+
msgstr "Rimuovi"
|
83 |
+
|
languages/user-avatar-ru_RU.mo
ADDED
Binary file
|
languages/user-avatar-ru_RU.po
ADDED
@@ -0,0 +1,83 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
msgid ""
|
2 |
+
msgstr ""
|
3 |
+
"Project-Id-Version: User Avatar 1.3.3\n"
|
4 |
+
"Report-Msgid-Bugs-To: \n"
|
5 |
+
"POT-Creation-Date: 2011-03-23 10:13+0100\n"
|
6 |
+
"PO-Revision-Date: 2011-03-24 12:58+0200\n"
|
7 |
+
"Last-Translator: Иван Волков <ivan.volkov@live.ru>\n"
|
8 |
+
"Language-Team: Ivan Volkov <ivan.volkov@live.ru>\n"
|
9 |
+
"MIME-Version: 1.0\n"
|
10 |
+
"Content-Type: text/plain; charset=UTF-8\n"
|
11 |
+
"Content-Transfer-Encoding: 8bit\n"
|
12 |
+
"X-Poedit-KeywordsList: __;gettext;gettext_noop;_e\n"
|
13 |
+
"X-Poedit-Basepath: .\n"
|
14 |
+
"X-Poedit-SourceCharset: utf-8\n"
|
15 |
+
"X-Poedit-Language: Russian\n"
|
16 |
+
"X-Poedit-Country: RUSSIAN FEDERATION\n"
|
17 |
+
"X-Poedit-SearchPath-0: ..\n"
|
18 |
+
|
19 |
+
#: ../user-avatar.php:157
|
20 |
+
msgid "Uploads"
|
21 |
+
msgstr "Загрузки"
|
22 |
+
|
23 |
+
#: ../user-avatar.php:157
|
24 |
+
msgid "WordPress"
|
25 |
+
msgstr "WordPress"
|
26 |
+
|
27 |
+
#: ../user-avatar.php:190
|
28 |
+
msgid "You are not allowed to do that."
|
29 |
+
msgstr "У Вас нет прав это сделать"
|
30 |
+
|
31 |
+
#: ../user-avatar.php:213
|
32 |
+
msgid "Choose an image from your computer:"
|
33 |
+
msgstr "Выбирите картинку с Вашеко компьютера:"
|
34 |
+
|
35 |
+
#: ../user-avatar.php:236
|
36 |
+
msgid "Please upload an image file (.jpeg, .gif, .png)."
|
37 |
+
msgstr "Загрузите изображение (.jpeg, .gif, .png)."
|
38 |
+
|
39 |
+
#: ../user-avatar.php:278
|
40 |
+
msgid "Choose the part of the image you want to use as your profile image."
|
41 |
+
msgstr "Выбирите часть изображения, которые Вы хотите использовать в качестве аватара."
|
42 |
+
|
43 |
+
#: ../user-avatar.php:390
|
44 |
+
msgid "Sorry, No file available"
|
45 |
+
msgstr "Файл не доступен."
|
46 |
+
|
47 |
+
#: ../user-avatar.php:414
|
48 |
+
msgid "Image could not be processed. Please go back and try again."
|
49 |
+
msgstr "Изображение не может быть обработано. Вернитесь назад и попробуйте снова."
|
50 |
+
|
51 |
+
#: ../user-avatar.php:414
|
52 |
+
msgid "Image Processing Error"
|
53 |
+
msgstr "Ошибка обрабтки изображения"
|
54 |
+
|
55 |
+
#: ../user-avatar.php:421
|
56 |
+
msgid "Here's your new profile picture..."
|
57 |
+
msgstr "Ваш новый аватар..."
|
58 |
+
|
59 |
+
#: ../user-avatar.php:427
|
60 |
+
msgid "Close"
|
61 |
+
msgstr "Закрыть"
|
62 |
+
|
63 |
+
#: ../user-avatar.php:710
|
64 |
+
msgid "Picture"
|
65 |
+
msgstr "Ваш Аватар"
|
66 |
+
|
67 |
+
#: ../user-avatar.php:712
|
68 |
+
msgid "Upload and Crop an Image to be Displayed"
|
69 |
+
msgstr "Загрузить и обрезать изображение"
|
70 |
+
|
71 |
+
#: ../user-avatar.php:712
|
72 |
+
msgid "Update Picture"
|
73 |
+
msgstr "Обновить аватар"
|
74 |
+
|
75 |
+
#: ../user-avatar.php:724
|
76 |
+
msgid "Remove User Avatar Image"
|
77 |
+
msgstr "Удалить изображение аватара пользователя"
|
78 |
+
|
79 |
+
#: ../user-avatar.php:724
|
80 |
+
#: ../user-avatar.php:735
|
81 |
+
msgid "Remove"
|
82 |
+
msgstr "Удалить"
|
83 |
+
|
languages/user-avatar-zh_CN.mo
ADDED
Binary file
|
languages/user-avatar-zh_CN.po
ADDED
@@ -0,0 +1,83 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
msgid ""
|
2 |
+
msgstr ""
|
3 |
+
"Project-Id-Version: User Avatar 1.3.3\n"
|
4 |
+
"Report-Msgid-Bugs-To: \n"
|
5 |
+
"POT-Creation-Date: 2011-08-10 13:51+0800\n"
|
6 |
+
"PO-Revision-Date: 2011-08-10 14:15+0800\n"
|
7 |
+
"Last-Translator: 李明 ( Adim Lee ) <adim_lee@163.com>\n"
|
8 |
+
"Language-Team: 李明 ( Adim Lee ) <adim_lee@163.com>\n"
|
9 |
+
"MIME-Version: 1.0\n"
|
10 |
+
"Content-Type: text/plain; charset=UTF-8\n"
|
11 |
+
"Content-Transfer-Encoding: 8bit\n"
|
12 |
+
"X-Poedit-KeywordsList: __;gettext;gettext_noop;_e\n"
|
13 |
+
"X-Poedit-Basepath: .\n"
|
14 |
+
"X-Poedit-Language: Chinese\n"
|
15 |
+
"X-Poedit-Country: CHINA\n"
|
16 |
+
"X-Poedit-SourceCharset: utf-8\n"
|
17 |
+
"X-Poedit-SearchPath-0: ..\n"
|
18 |
+
|
19 |
+
#: ../user-avatar.php:157
|
20 |
+
msgid "Uploads"
|
21 |
+
msgstr "上传"
|
22 |
+
|
23 |
+
#: ../user-avatar.php:157
|
24 |
+
msgid "WordPress"
|
25 |
+
msgstr "WordPress"
|
26 |
+
|
27 |
+
#: ../user-avatar.php:208
|
28 |
+
msgid "You are not allowed to do that."
|
29 |
+
msgstr "你不能这么做哦."
|
30 |
+
|
31 |
+
#: ../user-avatar.php:231
|
32 |
+
msgid "Choose an image from your computer:"
|
33 |
+
msgstr "从电脑选择一张图片,只支持 .jpg .gif .png 格式:"
|
34 |
+
|
35 |
+
#: ../user-avatar.php:254
|
36 |
+
msgid "Please upload an image file (.jpeg, .gif, .png)."
|
37 |
+
msgstr "你太调皮了,只能上传 .jpg .gif .png 格式的图片哦!"
|
38 |
+
|
39 |
+
#: ../user-avatar.php:296
|
40 |
+
msgid "Choose the part of the image you want to use as your profile image."
|
41 |
+
msgstr "选择图片区域用作头像,你可以在右边看到预览哦!(完事后点 Crop Image 就行了)"
|
42 |
+
|
43 |
+
#: ../user-avatar.php:408
|
44 |
+
msgid "Sorry, No file available"
|
45 |
+
msgstr "抱歉,没有什么东东可以给你看的。"
|
46 |
+
|
47 |
+
#: ../user-avatar.php:432
|
48 |
+
msgid "Image could not be processed. Please go back and try again."
|
49 |
+
msgstr "好像没有成功,返回再重试一下吧."
|
50 |
+
|
51 |
+
#: ../user-avatar.php:432
|
52 |
+
msgid "Image Processing Error"
|
53 |
+
msgstr "出错啦"
|
54 |
+
|
55 |
+
#: ../user-avatar.php:439
|
56 |
+
msgid "Here's your new profile picture..."
|
57 |
+
msgstr "哇,你拥有新头像啦!我很看好你哦 ~"
|
58 |
+
|
59 |
+
#: ../user-avatar.php:445
|
60 |
+
msgid "Close"
|
61 |
+
msgstr "关闭"
|
62 |
+
|
63 |
+
#: ../user-avatar.php:728
|
64 |
+
msgid "Picture"
|
65 |
+
msgstr "头像"
|
66 |
+
|
67 |
+
#: ../user-avatar.php:730
|
68 |
+
msgid "Upload and Crop an Image to be Displayed"
|
69 |
+
msgstr "上传一张靓照做头像吧 ^_^"
|
70 |
+
|
71 |
+
#: ../user-avatar.php:730
|
72 |
+
msgid "Update Picture"
|
73 |
+
msgstr "更新头像"
|
74 |
+
|
75 |
+
#: ../user-avatar.php:742
|
76 |
+
msgid "Remove User Avatar Image"
|
77 |
+
msgstr "取消头像"
|
78 |
+
|
79 |
+
#: ../user-avatar.php:742
|
80 |
+
#: ../user-avatar.php:753
|
81 |
+
msgid "Remove"
|
82 |
+
msgstr "取消头像"
|
83 |
+
|
languages/user-avatar.POT
ADDED
@@ -0,0 +1,81 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
msgid ""
|
2 |
+
msgstr ""
|
3 |
+
"Project-Id-Version: User Avatar 1.3.3\n"
|
4 |
+
"Report-Msgid-Bugs-To: \n"
|
5 |
+
"POT-Creation-Date: 2011-03-23 10:13+0100\n"
|
6 |
+
"PO-Revision-Date: 2011-03-23 10:14+0100\n"
|
7 |
+
"Last-Translator: Mirko <mirko@interno01.it>\n"
|
8 |
+
"Language-Team: INTERNOZEROUNO <info@interno01.it>\n"
|
9 |
+
"MIME-Version: 1.0\n"
|
10 |
+
"Content-Type: text/plain; charset=UTF-8\n"
|
11 |
+
"Content-Transfer-Encoding: 8bit\n"
|
12 |
+
"X-Poedit-KeywordsList: __;gettext;gettext_noop;_e\n"
|
13 |
+
"X-Poedit-Basepath: .\n"
|
14 |
+
"X-Poedit-SourceCharset: utf-8\n"
|
15 |
+
"X-Poedit-SearchPath-0: ..\n"
|
16 |
+
|
17 |
+
#: ../user-avatar.php:157
|
18 |
+
msgid "Uploads"
|
19 |
+
msgstr ""
|
20 |
+
|
21 |
+
#: ../user-avatar.php:157
|
22 |
+
msgid "WordPress"
|
23 |
+
msgstr ""
|
24 |
+
|
25 |
+
#: ../user-avatar.php:190
|
26 |
+
msgid "You are not allowed to do that."
|
27 |
+
msgstr ""
|
28 |
+
|
29 |
+
#: ../user-avatar.php:213
|
30 |
+
msgid "Choose an image from your computer:"
|
31 |
+
msgstr ""
|
32 |
+
|
33 |
+
#: ../user-avatar.php:236
|
34 |
+
msgid "Please upload an image file (.jpeg, .gif, .png)."
|
35 |
+
msgstr ""
|
36 |
+
|
37 |
+
#: ../user-avatar.php:278
|
38 |
+
msgid "Choose the part of the image you want to use as your profile image."
|
39 |
+
msgstr ""
|
40 |
+
|
41 |
+
#: ../user-avatar.php:390
|
42 |
+
msgid "Sorry, No file available"
|
43 |
+
msgstr ""
|
44 |
+
|
45 |
+
#: ../user-avatar.php:414
|
46 |
+
msgid "Image could not be processed. Please go back and try again."
|
47 |
+
msgstr ""
|
48 |
+
|
49 |
+
#: ../user-avatar.php:414
|
50 |
+
msgid "Image Processing Error"
|
51 |
+
msgstr ""
|
52 |
+
|
53 |
+
#: ../user-avatar.php:421
|
54 |
+
msgid "Here's your new profile picture..."
|
55 |
+
msgstr ""
|
56 |
+
|
57 |
+
#: ../user-avatar.php:427
|
58 |
+
msgid "Close"
|
59 |
+
msgstr ""
|
60 |
+
|
61 |
+
#: ../user-avatar.php:710
|
62 |
+
msgid "Picture"
|
63 |
+
msgstr ""
|
64 |
+
|
65 |
+
#: ../user-avatar.php:712
|
66 |
+
msgid "Upload and Crop an Image to be Displayed"
|
67 |
+
msgstr ""
|
68 |
+
|
69 |
+
#: ../user-avatar.php:712
|
70 |
+
msgid "Update Picture"
|
71 |
+
msgstr ""
|
72 |
+
|
73 |
+
#: ../user-avatar.php:724
|
74 |
+
msgid "Remove User Avatar Image"
|
75 |
+
msgstr ""
|
76 |
+
|
77 |
+
#: ../user-avatar.php:724
|
78 |
+
#: ../user-avatar.php:735
|
79 |
+
msgid "Remove"
|
80 |
+
msgstr ""
|
81 |
+
|
readme.txt
CHANGED
@@ -1,13 +1,14 @@
|
|
1 |
=== User Avatar ===
|
2 |
-
Contributors: sgagan, enej, oltdev
|
3 |
Tags: people lists, people, list, form, user profile, user avatar, thumbnail, upload photo, user, users, profile, biography, profile biography, user profile, description, profile description, rich text, wysiwyg, tinyMCE, photos, images, members, directory, profiles, jQuery, sortable, tabbable, thickbox, overlay, media button, Your Profile
|
4 |
Requires at least: 3.0
|
5 |
-
Tested up to: 3.
|
6 |
Stable Tag: trunk
|
7 |
|
8 |
Provides a thumbnail area in Your Profile, for users to upload & crop new images in an overlay to be saved and stored to their profile.
|
9 |
|
10 |
== Description ==
|
|
|
11 |
|
12 |
This plugin provides a thumbnail area in the Your Profile section, where users can upload & crop new images in an overlay and upon cropping the image, the new image will be saved and stored. This gives users with any role the chance to easily upload an image and view their current thumbnail, all in one go. In Discussion, the default image associated with the user will be replaced with the user avatar image uploaded and this will then be the image shown in comments and also in People Lists (see below).
|
13 |
|
@@ -15,6 +16,9 @@ This plugin provides a thumbnail area in the Your Profile section, where users c
|
|
15 |
|
16 |
Take a look at the screenshots!
|
17 |
|
|
|
|
|
|
|
18 |
|
19 |
== Installation ==
|
20 |
|
@@ -28,10 +32,64 @@ Take a look at the screenshots!
|
|
28 |
2. Step 1: Upload an image
|
29 |
3. Step 2: Crop your image
|
30 |
4. Step 3: Image is ready
|
31 |
-
|
32 |
-
6. Newly updated remove user avatar button that defaults to Gravatar or default WordPress image chosen on Discussion Page.
|
33 |
|
34 |
== Changelog ==
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
|
36 |
= 1.2.1 =
|
37 |
* Fixed Error bug in comments
|
@@ -53,3 +111,5 @@ Take a look at the screenshots!
|
|
53 |
|
54 |
= No Upgrades yet =
|
55 |
* August 1st, 2010
|
|
|
|
1 |
=== User Avatar ===
|
2 |
+
Contributors: sgagan, enej, oltdev, ctlt-dev, ubcdev
|
3 |
Tags: people lists, people, list, form, user profile, user avatar, thumbnail, upload photo, user, users, profile, biography, profile biography, user profile, description, profile description, rich text, wysiwyg, tinyMCE, photos, images, members, directory, profiles, jQuery, sortable, tabbable, thickbox, overlay, media button, Your Profile
|
4 |
Requires at least: 3.0
|
5 |
+
Tested up to: 3.1
|
6 |
Stable Tag: trunk
|
7 |
|
8 |
Provides a thumbnail area in Your Profile, for users to upload & crop new images in an overlay to be saved and stored to their profile.
|
9 |
|
10 |
== Description ==
|
11 |
+
**1.4.7 is a Security Fix Please update your plugin to the latest version**
|
12 |
|
13 |
This plugin provides a thumbnail area in the Your Profile section, where users can upload & crop new images in an overlay and upon cropping the image, the new image will be saved and stored. This gives users with any role the chance to easily upload an image and view their current thumbnail, all in one go. In Discussion, the default image associated with the user will be replaced with the user avatar image uploaded and this will then be the image shown in comments and also in People Lists (see below).
|
14 |
|
16 |
|
17 |
Take a look at the screenshots!
|
18 |
|
19 |
+
This plugin was developed using PHP 5.1 and hasn't been tested on other version of php
|
20 |
+
But if you are able to run upload picture and set them as featured image then you
|
21 |
+
also shouldn't be have problems using this plugin.
|
22 |
|
23 |
== Installation ==
|
24 |
|
32 |
2. Step 1: Upload an image
|
33 |
3. Step 2: Crop your image
|
34 |
4. Step 3: Image is ready
|
35 |
+
|
|
|
36 |
|
37 |
== Changelog ==
|
38 |
+
= 1.4.8 =
|
39 |
+
* updated to the latest version of the timthumb 2.8.10
|
40 |
+
|
41 |
+
= 1.4.7 =
|
42 |
+
SECURITY FIX
|
43 |
+
= 1.4.6 =
|
44 |
+
* Bug fix: If you are running WordPress MU and don't have the a subdomain install this should will fix your problem
|
45 |
+
|
46 |
+
= 1.4.5 =
|
47 |
+
* Added the Mandarin CH Translation thanks to Adim Lee
|
48 |
+
|
49 |
+
= 1.4.4 =
|
50 |
+
* Minor: Removed Notice errors
|
51 |
+
|
52 |
+
= 1.4.3 =
|
53 |
+
* Bug fix: Sites that were installed in a sub directory had the problem where user avatars disappeared. Thanks to Woostotmar for pointing that out!
|
54 |
+
|
55 |
+
= 1.4.2 =
|
56 |
+
* Bug fix: Was displaying a PHP warning if folders were not present! Many Thanks to Gabriel Serafini!
|
57 |
+
|
58 |
+
= 1.4.1 =
|
59 |
+
* Bug fix: When the site has don't show avatars, users are not able to edit their avatars.
|
60 |
+
* Added the Spanish Translation many thanks to - GabrielBS
|
61 |
+
|
62 |
+
= 1.4 =
|
63 |
+
* Now using the latest timthumb script, this is a security update and will fix the
|
64 |
+
|
65 |
+
= 1.3.6 =
|
66 |
+
* Improved compatibility issues with some plugins. (this might fix the issue of having some js errors and the crop area not showing up.)
|
67 |
+
|
68 |
+
= 1.3.5 =
|
69 |
+
* Added the Russian Translation thanks to - iV@N1971
|
70 |
+
|
71 |
+
= 1.3.4 =
|
72 |
+
* Added the Italian Translation thanks to - Punxsutawney Phil
|
73 |
+
* generated html validates better in html strictmode
|
74 |
+
* This is not a necessary update
|
75 |
+
|
76 |
+
= 1.3.3 =
|
77 |
+
* some more bugs resolved. Thanks to @ronymehta and @lilos
|
78 |
+
* 3.1 backwards compatibility for editing user avatars for people that have these sort of privileges.
|
79 |
+
|
80 |
+
= 1.3.2 =
|
81 |
+
* Changed esc_url to esc_url_raw thanks to @ronymehta
|
82 |
+
* fixed a bug thanks to @BandB
|
83 |
+
|
84 |
+
= 1.3.1 =
|
85 |
+
* Caching fixes
|
86 |
+
* Translation ready
|
87 |
+
* Security improvements
|
88 |
+
|
89 |
+
= 1.3 =
|
90 |
+
* Fixed bugs that were result of the WP 3.1 update and also making it more future prof
|
91 |
+
* Resizes images and caches them using timthumb script.
|
92 |
+
* Better classes added to the avatar image so that less theme should break
|
93 |
|
94 |
= 1.2.1 =
|
95 |
* Fixed Error bug in comments
|
111 |
|
112 |
= No Upgrades yet =
|
113 |
* August 1st, 2010
|
114 |
+
|
115 |
+
|
screenshot-1.png
CHANGED
Binary file
|
screenshot-5.png
DELETED
Binary file
|
screenshot-6.png
DELETED
Binary file
|
timthumb-config.php
ADDED
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
if( isset($_GET['id']) && is_numeric($_GET['id']) ){
|
4 |
+
$id = $_GET['id'];
|
5 |
+
|
6 |
+
if( !strpos( $_GET['src'],"/avatars/".$id."/" ) )
|
7 |
+
die();
|
8 |
+
} else {
|
9 |
+
die();
|
10 |
+
}
|
11 |
+
// this is the standard set up with wp-content living 3 levels down
|
12 |
+
define ('WP_CONTENT_DIR', dirname(dirname(dirname(__FILE__))));
|
13 |
+
define ('AVATARS_DIR',WP_CONTENT_DIR.'/uploads/avatars/');
|
14 |
+
// cache the file inside the avatar directory
|
15 |
+
// please modify this to your hearts content
|
16 |
+
if(! defined('FILE_CACHE_DIRECTORY') ) define ('FILE_CACHE_DIRECTORY', AVATARS_DIR.$id.'/cache');
|
17 |
+
|
18 |
+
|
19 |
+
// this are pretty much the standard settings
|
20 |
+
if(! defined( 'DEBUG_ON' ) ) define ('DEBUG_ON', false); // Enable debug logging to web server error log (STDERR)
|
21 |
+
if(! defined('DEBUG_LEVEL') ) define ('DEBUG_LEVEL', 1); // Debug level 1 is less noisy and 3 is the most noisy
|
22 |
+
if(! defined('MEMORY_LIMIT') ) define ('MEMORY_LIMIT', '30M'); // Set PHP memory limit
|
23 |
+
if(! defined('BLOCK_EXTERNAL_LEECHERS') ) define ('BLOCK_EXTERNAL_LEECHERS', true); // If the image or webshot is being loaded on an external site, display a red "No Hotlinking" gif.
|
24 |
+
|
25 |
+
//Image fetching and caching
|
26 |
+
if(! defined('ALLOW_EXTERNAL') ) define ('ALLOW_EXTERNAL', false); // Allow image fetching from external websites. Will check against ALLOWED_SITES if ALLOW_ALL_EXTERNAL_SITES is false
|
27 |
+
if(! defined('ALLOW_ALL_EXTERNAL_SITES') ) define ('ALLOW_ALL_EXTERNAL_SITES', false); // Less secure.
|
28 |
+
if(! defined('FILE_CACHE_ENABLED') ) define ('FILE_CACHE_ENABLED', TRUE); // Should we store resized/modified images on disk to speed things up?
|
29 |
+
if(! defined('FILE_CACHE_TIME_BETWEEN_CLEANS')) define ('FILE_CACHE_TIME_BETWEEN_CLEANS', 86400); // How often the cache is cleaned
|
30 |
+
if(! defined('FILE_CACHE_MAX_FILE_AGE') ) define ('FILE_CACHE_MAX_FILE_AGE', 86400); // How old does a file have to be to be deleted from the cache
|
31 |
+
if(! defined('FILE_CACHE_SUFFIX') ) define ('FILE_CACHE_SUFFIX', '.timthumb.txt'); // What to put at the end of all files in the cache directory so we can identify them
|
32 |
+
// Directory where images are cached. Left blank it will use the system temporary directory (which is better for security)
|
33 |
+
if(! defined('MAX_FILE_SIZE') ) define ('MAX_FILE_SIZE', 10485760); // 10 Megs is 10485760. This is the max internal or external file size that we'll process.
|
34 |
+
if(! defined('CURL_TIMEOUT') ) define ('CURL_TIMEOUT', 20); // Timeout duration for Curl. This only applies if you have Curl installed and aren't using PHP's default URL fetching mechanism.
|
35 |
+
if(! defined('WAIT_BETWEEN_FETCH_ERRORS') ) define ('WAIT_BETWEEN_FETCH_ERRORS', 3600); //Time to wait between errors fetching remote file
|
36 |
+
//Browser caching
|
37 |
+
if(! defined('BROWSER_CACHE_MAX_AGE') ) define ('BROWSER_CACHE_MAX_AGE', 864000); // Time to cache in the browser
|
38 |
+
if(! defined('BROWSER_CACHE_DISABLE') ) define ('BROWSER_CACHE_DISABLE', false); // Use for testing if you want to disable all browser caching
|
39 |
+
|
40 |
+
//Image size and defaults
|
41 |
+
if(! defined('MAX_WIDTH') ) define ('MAX_WIDTH', 1500); // Maximum image width
|
42 |
+
if(! defined('MAX_HEIGHT') ) define ('MAX_HEIGHT', 1500); // Maximum image height
|
43 |
+
if(! defined('NOT_FOUND_IMAGE') ) define ('NOT_FOUND_IMAGE', ''); //Image to serve if any 404 occurs
|
44 |
+
if(! defined('ERROR_IMAGE') ) define ('ERROR_IMAGE', ''); //Image to serve if an error occurs instead of showing error message
|
user-avatar-pic.php
ADDED
@@ -0,0 +1,1244 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* TimThumb by Ben Gillbanks and Mark Maunder
|
4 |
+
* Based on work done by Tim McDaniels and Darren Hoyt
|
5 |
+
* http://code.google.com/p/timthumb/
|
6 |
+
*
|
7 |
+
* GNU General Public License, version 2
|
8 |
+
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
9 |
+
*
|
10 |
+
* Examples and documentation available on the project homepage
|
11 |
+
* http://www.binarymoon.co.uk/projects/timthumb/
|
12 |
+
*
|
13 |
+
* $Rev$
|
14 |
+
*/
|
15 |
+
|
16 |
+
/*
|
17 |
+
* --- TimThumb CONFIGURATION ---
|
18 |
+
* To edit the configs it is best to create a file called timthumb-config.php
|
19 |
+
* and define variables you want to customize in there. It will automatically be
|
20 |
+
* loaded by timthumb. This will save you having to re-edit these variables
|
21 |
+
* everytime you download a new version
|
22 |
+
*/
|
23 |
+
define ('VERSION', '2.8.10'); // Version of this script
|
24 |
+
//Load a config file if it exists. Otherwise, use the values below
|
25 |
+
if( file_exists(dirname(__FILE__) . '/timthumb-config.php')) require_once('timthumb-config.php');
|
26 |
+
if(! defined('DEBUG_ON') ) define ('DEBUG_ON', false); // Enable debug logging to web server error log (STDERR)
|
27 |
+
if(! defined('DEBUG_LEVEL') ) define ('DEBUG_LEVEL', 1); // Debug level 1 is less noisy and 3 is the most noisy
|
28 |
+
if(! defined('MEMORY_LIMIT') ) define ('MEMORY_LIMIT', '30M'); // Set PHP memory limit
|
29 |
+
if(! defined('BLOCK_EXTERNAL_LEECHERS') ) define ('BLOCK_EXTERNAL_LEECHERS', false); // If the image or webshot is being loaded on an external site, display a red "No Hotlinking" gif.
|
30 |
+
|
31 |
+
//Image fetching and caching
|
32 |
+
if(! defined('ALLOW_EXTERNAL') ) define ('ALLOW_EXTERNAL', TRUE); // Allow image fetching from external websites. Will check against ALLOWED_SITES if ALLOW_ALL_EXTERNAL_SITES is false
|
33 |
+
if(! defined('ALLOW_ALL_EXTERNAL_SITES') ) define ('ALLOW_ALL_EXTERNAL_SITES', false); // Less secure.
|
34 |
+
if(! defined('FILE_CACHE_ENABLED') ) define ('FILE_CACHE_ENABLED', TRUE); // Should we store resized/modified images on disk to speed things up?
|
35 |
+
if(! defined('FILE_CACHE_TIME_BETWEEN_CLEANS')) define ('FILE_CACHE_TIME_BETWEEN_CLEANS', 86400); // How often the cache is cleaned
|
36 |
+
|
37 |
+
if(! defined('FILE_CACHE_MAX_FILE_AGE') ) define ('FILE_CACHE_MAX_FILE_AGE', 86400); // How old does a file have to be to be deleted from the cache
|
38 |
+
if(! defined('FILE_CACHE_SUFFIX') ) define ('FILE_CACHE_SUFFIX', '.timthumb.txt'); // What to put at the end of all files in the cache directory so we can identify them
|
39 |
+
if(! defined('FILE_CACHE_PREFIX') ) define ('FILE_CACHE_PREFIX', 'timthumb'); // What to put at the beg of all files in the cache directory so we can identify them
|
40 |
+
if(! defined('FILE_CACHE_DIRECTORY') ) define ('FILE_CACHE_DIRECTORY', './cache'); // Directory where images are cached. Left blank it will use the system temporary directory (which is better for security)
|
41 |
+
if(! defined('MAX_FILE_SIZE') ) define ('MAX_FILE_SIZE', 10485760); // 10 Megs is 10485760. This is the max internal or external file size that we'll process.
|
42 |
+
if(! defined('CURL_TIMEOUT') ) define ('CURL_TIMEOUT', 20); // Timeout duration for Curl. This only applies if you have Curl installed and aren't using PHP's default URL fetching mechanism.
|
43 |
+
if(! defined('WAIT_BETWEEN_FETCH_ERRORS') ) define ('WAIT_BETWEEN_FETCH_ERRORS', 3600); //Time to wait between errors fetching remote file
|
44 |
+
|
45 |
+
//Browser caching
|
46 |
+
if(! defined('BROWSER_CACHE_MAX_AGE') ) define ('BROWSER_CACHE_MAX_AGE', 864000); // Time to cache in the browser
|
47 |
+
if(! defined('BROWSER_CACHE_DISABLE') ) define ('BROWSER_CACHE_DISABLE', false); // Use for testing if you want to disable all browser caching
|
48 |
+
|
49 |
+
//Image size and defaults
|
50 |
+
if(! defined('MAX_WIDTH') ) define ('MAX_WIDTH', 1500); // Maximum image width
|
51 |
+
if(! defined('MAX_HEIGHT') ) define ('MAX_HEIGHT', 1500); // Maximum image height
|
52 |
+
if(! defined('NOT_FOUND_IMAGE') ) define ('NOT_FOUND_IMAGE', ''); // Image to serve if any 404 occurs
|
53 |
+
if(! defined('ERROR_IMAGE') ) define ('ERROR_IMAGE', ''); // Image to serve if an error occurs instead of showing error message
|
54 |
+
if(! defined('PNG_IS_TRANSPARENT') ) define ('PNG_IS_TRANSPARENT', FALSE); //42 Define if a png image should have a transparent background color. Use False value if you want to display a custom coloured canvas_colour
|
55 |
+
if(! defined('DEFAULT_Q') ) define ('DEFAULT_Q', 90); // Default image quality. Allows overrid in timthumb-config.php
|
56 |
+
if(! defined('DEFAULT_ZC') ) define ('DEFAULT_ZC', 1); // Default zoom/crop setting. Allows overrid in timthumb-config.php
|
57 |
+
if(! defined('DEFAULT_F') ) define ('DEFAULT_F', ''); // Default image filters. Allows overrid in timthumb-config.php
|
58 |
+
if(! defined('DEFAULT_S') ) define ('DEFAULT_S', 0); // Default sharpen value. Allows overrid in timthumb-config.php
|
59 |
+
if(! defined('DEFAULT_CC') ) define ('DEFAULT_CC', 'ffffff'); // Default canvas colour. Allows overrid in timthumb-config.php
|
60 |
+
|
61 |
+
|
62 |
+
//Image compression is enabled if either of these point to valid paths
|
63 |
+
|
64 |
+
//These are now disabled by default because the file sizes of PNGs (and GIFs) are much smaller than we used to generate.
|
65 |
+
//They only work for PNGs. GIFs and JPEGs are not affected.
|
66 |
+
if(! defined('OPTIPNG_ENABLED') ) define ('OPTIPNG_ENABLED', false);
|
67 |
+
if(! defined('OPTIPNG_PATH') ) define ('OPTIPNG_PATH', '/usr/bin/optipng'); //This will run first because it gives better compression than pngcrush.
|
68 |
+
if(! defined('PNGCRUSH_ENABLED') ) define ('PNGCRUSH_ENABLED', false);
|
69 |
+
if(! defined('PNGCRUSH_PATH') ) define ('PNGCRUSH_PATH', '/usr/bin/pngcrush'); //This will only run if OPTIPNG_PATH is not set or is not valid
|
70 |
+
|
71 |
+
/*
|
72 |
+
-------====Website Screenshots configuration - BETA====-------
|
73 |
+
|
74 |
+
If you just want image thumbnails and don't want website screenshots, you can safely leave this as is.
|
75 |
+
|
76 |
+
If you would like to get website screenshots set up, you will need root access to your own server.
|
77 |
+
|
78 |
+
Enable ALLOW_ALL_EXTERNAL_SITES so you can fetch any external web page. This is more secure now that we're using a non-web folder for cache.
|
79 |
+
Enable BLOCK_EXTERNAL_LEECHERS so that your site doesn't generate thumbnails for the whole Internet.
|
80 |
+
|
81 |
+
Instructions to get website screenshots enabled on Ubuntu Linux:
|
82 |
+
|
83 |
+
1. Install Xvfb with the following command: sudo apt-get install subversion libqt4-webkit libqt4-dev g++ xvfb
|
84 |
+
2. Go to a directory where you can download some code
|
85 |
+
3. Check-out the latest version of CutyCapt with the following command: svn co https://cutycapt.svn.sourceforge.net/svnroot/cutycapt
|
86 |
+
4. Compile CutyCapt by doing: cd cutycapt/CutyCapt
|
87 |
+
5. qmake
|
88 |
+
6. make
|
89 |
+
7. cp CutyCapt /usr/local/bin/
|
90 |
+
8. Test it by running: xvfb-run --server-args="-screen 0, 1024x768x24" CutyCapt --url="http://markmaunder.com/" --out=test.png
|
91 |
+
9. If you get a file called test.png with something in it, it probably worked. Now test the script by accessing it as follows:
|
92 |
+
10. http://yoursite.com/path/to/timthumb.php?src=http://markmaunder.com/&webshot=1
|
93 |
+
|
94 |
+
Notes on performance:
|
95 |
+
The first time a webshot loads, it will take a few seconds.
|
96 |
+
From then on it uses the regular timthumb caching mechanism with the configurable options above
|
97 |
+
and loading will be very fast.
|
98 |
+
|
99 |
+
--ADVANCED USERS ONLY--
|
100 |
+
If you'd like a slight speedup (about 25%) and you know Linux, you can run the following command which will keep Xvfb running in the background.
|
101 |
+
nohup Xvfb :100 -ac -nolisten tcp -screen 0, 1024x768x24 > /dev/null 2>&1 &
|
102 |
+
Then set WEBSHOT_XVFB_RUNNING = true below. This will save your server having to fire off a new Xvfb server and shut it down every time a new shot is generated.
|
103 |
+
You will need to take responsibility for keeping Xvfb running in case it crashes. (It seems pretty stable)
|
104 |
+
You will also need to take responsibility for server security if you're running Xvfb as root.
|
105 |
+
|
106 |
+
|
107 |
+
*/
|
108 |
+
if(! defined('WEBSHOT_ENABLED') ) define ('WEBSHOT_ENABLED', false); //Beta feature. Adding webshot=1 to your query string will cause the script to return a browser screenshot rather than try to fetch an image.
|
109 |
+
if(! defined('WEBSHOT_CUTYCAPT') ) define ('WEBSHOT_CUTYCAPT', '/usr/local/bin/CutyCapt'); //The path to CutyCapt.
|
110 |
+
if(! defined('WEBSHOT_XVFB') ) define ('WEBSHOT_XVFB', '/usr/bin/xvfb-run'); //The path to the Xvfb server
|
111 |
+
if(! defined('WEBSHOT_SCREEN_X') ) define ('WEBSHOT_SCREEN_X', '1024'); //1024 works ok
|
112 |
+
if(! defined('WEBSHOT_SCREEN_Y') ) define ('WEBSHOT_SCREEN_Y', '768'); //768 works ok
|
113 |
+
if(! defined('WEBSHOT_COLOR_DEPTH') ) define ('WEBSHOT_COLOR_DEPTH', '24'); //I haven't tested anything besides 24
|
114 |
+
if(! defined('WEBSHOT_IMAGE_FORMAT') ) define ('WEBSHOT_IMAGE_FORMAT', 'png'); //png is about 2.5 times the size of jpg but is a LOT better quality
|
115 |
+
if(! defined('WEBSHOT_TIMEOUT') ) define ('WEBSHOT_TIMEOUT', '20'); //Seconds to wait for a webshot
|
116 |
+
if(! defined('WEBSHOT_USER_AGENT') ) define ('WEBSHOT_USER_AGENT', "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.2.18) Gecko/20110614 Firefox/3.6.18"); //I hate to do this, but a non-browser robot user agent might not show what humans see. So we pretend to be Firefox
|
117 |
+
if(! defined('WEBSHOT_JAVASCRIPT_ON') ) define ('WEBSHOT_JAVASCRIPT_ON', true); //Setting to false might give you a slight speedup and block ads. But it could cause other issues.
|
118 |
+
if(! defined('WEBSHOT_JAVA_ON') ) define ('WEBSHOT_JAVA_ON', false); //Have only tested this as fase
|
119 |
+
if(! defined('WEBSHOT_PLUGINS_ON') ) define ('WEBSHOT_PLUGINS_ON', true); //Enable flash and other plugins
|
120 |
+
if(! defined('WEBSHOT_PROXY') ) define ('WEBSHOT_PROXY', ''); //In case you're behind a proxy server.
|
121 |
+
if(! defined('WEBSHOT_XVFB_RUNNING') ) define ('WEBSHOT_XVFB_RUNNING', false); //ADVANCED: Enable this if you've got Xvfb running in the background.
|
122 |
+
|
123 |
+
|
124 |
+
// If ALLOW_EXTERNAL is true and ALLOW_ALL_EXTERNAL_SITES is false, then external images will only be fetched from these domains and their subdomains.
|
125 |
+
if(! isset($ALLOWED_SITES)){
|
126 |
+
$ALLOWED_SITES = array (
|
127 |
+
'flickr.com',
|
128 |
+
'staticflickr.com',
|
129 |
+
'picasa.com',
|
130 |
+
'img.youtube.com',
|
131 |
+
'upload.wikimedia.org',
|
132 |
+
'photobucket.com',
|
133 |
+
'imgur.com',
|
134 |
+
'imageshack.us',
|
135 |
+
'tinypic.com',
|
136 |
+
);
|
137 |
+
}
|
138 |
+
// -------------------------------------------------------------
|
139 |
+
// -------------- STOP EDITING CONFIGURATION HERE --------------
|
140 |
+
// -------------------------------------------------------------
|
141 |
+
|
142 |
+
timthumb::start();
|
143 |
+
|
144 |
+
class timthumb {
|
145 |
+
protected $src = "";
|
146 |
+
protected $is404 = false;
|
147 |
+
protected $docRoot = "";
|
148 |
+
protected $lastURLError = false;
|
149 |
+
protected $localImage = "";
|
150 |
+
protected $localImageMTime = 0;
|
151 |
+
protected $url = false;
|
152 |
+
protected $myHost = "";
|
153 |
+
protected $isURL = false;
|
154 |
+
protected $cachefile = '';
|
155 |
+
protected $errors = array();
|
156 |
+
protected $toDeletes = array();
|
157 |
+
protected $cacheDirectory = '';
|
158 |
+
protected $startTime = 0;
|
159 |
+
protected $lastBenchTime = 0;
|
160 |
+
protected $cropTop = false;
|
161 |
+
protected $salt = "";
|
162 |
+
protected $fileCacheVersion = 1; //Generally if timthumb.php is modifed (upgraded) then the salt changes and all cache files are recreated. This is a backup mechanism to force regen.
|
163 |
+
protected $filePrependSecurityBlock = "<?php die('Execution denied!'); //"; //Designed to have three letter mime type, space, question mark and greater than symbol appended. 6 bytes total.
|
164 |
+
protected static $curlDataWritten = 0;
|
165 |
+
protected static $curlFH = false;
|
166 |
+
public static function start(){
|
167 |
+
$tim = new timthumb();
|
168 |
+
$tim->handleErrors();
|
169 |
+
$tim->securityChecks();
|
170 |
+
if($tim->tryBrowserCache()){
|
171 |
+
exit(0);
|
172 |
+
}
|
173 |
+
$tim->handleErrors();
|
174 |
+
if(FILE_CACHE_ENABLED && $tim->tryServerCache()){
|
175 |
+
exit(0);
|
176 |
+
}
|
177 |
+
$tim->handleErrors();
|
178 |
+
$tim->run();
|
179 |
+
$tim->handleErrors();
|
180 |
+
exit(0);
|
181 |
+
}
|
182 |
+
public function __construct(){
|
183 |
+
global $ALLOWED_SITES;
|
184 |
+
$this->startTime = microtime(true);
|
185 |
+
date_default_timezone_set('UTC');
|
186 |
+
$this->debug(1, "Starting new request from " . $this->getIP() . " to " . $_SERVER['REQUEST_URI']);
|
187 |
+
$this->calcDocRoot();
|
188 |
+
//On windows systems I'm assuming fileinode returns an empty string or a number that doesn't change. Check this.
|
189 |
+
$this->salt = @filemtime(__FILE__) . '-' . @fileinode(__FILE__);
|
190 |
+
$this->debug(3, "Salt is: " . $this->salt);
|
191 |
+
if(FILE_CACHE_DIRECTORY){
|
192 |
+
if(! is_dir(FILE_CACHE_DIRECTORY)){
|
193 |
+
@mkdir(FILE_CACHE_DIRECTORY);
|
194 |
+
if(! is_dir(FILE_CACHE_DIRECTORY)){
|
195 |
+
$this->error("Could not create the file cache directory.");
|
196 |
+
return false;
|
197 |
+
}
|
198 |
+
}
|
199 |
+
$this->cacheDirectory = FILE_CACHE_DIRECTORY;
|
200 |
+
if (!touch($this->cacheDirectory . '/index.html')) {
|
201 |
+
$this->error("Could not create the index.html file - to fix this create an empty file named index.html file in the cache directory.");
|
202 |
+
}
|
203 |
+
} else {
|
204 |
+
$this->cacheDirectory = sys_get_temp_dir();
|
205 |
+
}
|
206 |
+
//Clean the cache before we do anything because we don't want the first visitor after FILE_CACHE_TIME_BETWEEN_CLEANS expires to get a stale image.
|
207 |
+
$this->cleanCache();
|
208 |
+
|
209 |
+
$this->myHost = preg_replace('/^www\./i', '', $_SERVER['HTTP_HOST']);
|
210 |
+
$this->src = $this->param('src');
|
211 |
+
$this->url = parse_url($this->src);
|
212 |
+
$this->src = preg_replace('/https?:\/\/(?:www\.)?' . $this->myHost . '/i', '', $this->src);
|
213 |
+
|
214 |
+
if(strlen($this->src) <= 3){
|
215 |
+
$this->error("No image specified");
|
216 |
+
return false;
|
217 |
+
}
|
218 |
+
if(BLOCK_EXTERNAL_LEECHERS && array_key_exists('HTTP_REFERER', $_SERVER) && (! preg_match('/^https?:\/\/(?:www\.)?' . $this->myHost . '(?:$|\/)/i', $_SERVER['HTTP_REFERER']))){
|
219 |
+
// base64 encoded red image that says 'no hotlinkers'
|
220 |
+
// nothing to worry about! :)
|
221 |
+
$imgData = base64_decode("R0lGODlhUAAMAIAAAP8AAP///yH5BAAHAP8ALAAAAABQAAwAAAJpjI+py+0Po5y0OgAMjjv01YUZ\nOGplhWXfNa6JCLnWkXplrcBmW+spbwvaVr/cDyg7IoFC2KbYVC2NQ5MQ4ZNao9Ynzjl9ScNYpneb\nDULB3RP6JuPuaGfuuV4fumf8PuvqFyhYtjdoeFgAADs=");
|
222 |
+
header('Content-Type: image/gif');
|
223 |
+
header('Content-Length: ' . sizeof($imgData));
|
224 |
+
header('Cache-Control: no-store, no-cache, must-revalidate, max-age=0');
|
225 |
+
header("Pragma: no-cache");
|
226 |
+
header('Expires: ' . gmdate ('D, d M Y H:i:s', time()));
|
227 |
+
echo $imgData;
|
228 |
+
return false;
|
229 |
+
exit(0);
|
230 |
+
}
|
231 |
+
if(preg_match('/^https?:\/\/[^\/]+/i', $this->src)){
|
232 |
+
$this->debug(2, "Is a request for an external URL: " . $this->src);
|
233 |
+
$this->isURL = true;
|
234 |
+
} else {
|
235 |
+
$this->debug(2, "Is a request for an internal file: " . $this->src);
|
236 |
+
}
|
237 |
+
if($this->isURL && (! ALLOW_EXTERNAL)){
|
238 |
+
$this->error("You are not allowed to fetch images from an external website.");
|
239 |
+
return false;
|
240 |
+
}
|
241 |
+
if($this->isURL){
|
242 |
+
if(ALLOW_ALL_EXTERNAL_SITES){
|
243 |
+
$this->debug(2, "Fetching from all external sites is enabled.");
|
244 |
+
} else {
|
245 |
+
$this->debug(2, "Fetching only from selected external sites is enabled.");
|
246 |
+
$allowed = false;
|
247 |
+
foreach($ALLOWED_SITES as $site){
|
248 |
+
if ((strtolower(substr($this->url['host'],-strlen($site)-1)) === strtolower(".$site")) || (strtolower($this->url['host'])===strtolower($site))) {
|
249 |
+
$this->debug(3, "URL hostname {$this->url['host']} matches $site so allowing.");
|
250 |
+
$allowed = true;
|
251 |
+
}
|
252 |
+
}
|
253 |
+
if(! $allowed){
|
254 |
+
return $this->error("You may not fetch images from that site. To enable this site in timthumb, you can either add it to \$ALLOWED_SITES and set ALLOW_EXTERNAL=true. Or you can set ALLOW_ALL_EXTERNAL_SITES=true, depending on your security needs.");
|
255 |
+
}
|
256 |
+
}
|
257 |
+
}
|
258 |
+
|
259 |
+
$cachePrefix = ($this->isURL ? '_ext_' : '_int_');
|
260 |
+
if($this->isURL){
|
261 |
+
$arr = explode('&', $_SERVER ['QUERY_STRING']);
|
262 |
+
asort($arr);
|
263 |
+
$this->cachefile = $this->cacheDirectory . '/' . FILE_CACHE_PREFIX . $cachePrefix . md5($this->salt . implode('', $arr) . $this->fileCacheVersion) . FILE_CACHE_SUFFIX;
|
264 |
+
} else {
|
265 |
+
$this->localImage = $this->getLocalImagePath($this->src);
|
266 |
+
if(! $this->localImage){
|
267 |
+
$this->debug(1, "Could not find the local image: {$this->localImage}");
|
268 |
+
$this->error("Could not find the internal image you specified.");
|
269 |
+
$this->set404();
|
270 |
+
return false;
|
271 |
+
}
|
272 |
+
$this->debug(1, "Local image path is {$this->localImage}");
|
273 |
+
$this->localImageMTime = @filemtime($this->localImage);
|
274 |
+
//We include the mtime of the local file in case in changes on disk.
|
275 |
+
$this->cachefile = $this->cacheDirectory . '/' . FILE_CACHE_PREFIX . $cachePrefix . md5($this->salt . $this->localImageMTime . $_SERVER ['QUERY_STRING'] . $this->fileCacheVersion) . FILE_CACHE_SUFFIX;
|
276 |
+
}
|
277 |
+
$this->debug(2, "Cache file is: " . $this->cachefile);
|
278 |
+
|
279 |
+
return true;
|
280 |
+
}
|
281 |
+
public function __destruct(){
|
282 |
+
foreach($this->toDeletes as $del){
|
283 |
+
$this->debug(2, "Deleting temp file $del");
|
284 |
+
@unlink($del);
|
285 |
+
}
|
286 |
+
}
|
287 |
+
public function run(){
|
288 |
+
if($this->isURL){
|
289 |
+
if(! ALLOW_EXTERNAL){
|
290 |
+
$this->debug(1, "Got a request for an external image but ALLOW_EXTERNAL is disabled so returning error msg.");
|
291 |
+
$this->error("You are not allowed to fetch images from an external website.");
|
292 |
+
return false;
|
293 |
+
}
|
294 |
+
$this->debug(3, "Got request for external image. Starting serveExternalImage.");
|
295 |
+
if($this->param('webshot')){
|
296 |
+
if(WEBSHOT_ENABLED){
|
297 |
+
$this->debug(3, "webshot param is set, so we're going to take a webshot.");
|
298 |
+
$this->serveWebshot();
|
299 |
+
} else {
|
300 |
+
$this->error("You added the webshot parameter but webshots are disabled on this server. You need to set WEBSHOT_ENABLED == true to enable webshots.");
|
301 |
+
}
|
302 |
+
} else {
|
303 |
+
$this->debug(3, "webshot is NOT set so we're going to try to fetch a regular image.");
|
304 |
+
$this->serveExternalImage();
|
305 |
+
|
306 |
+
}
|
307 |
+
} else {
|
308 |
+
$this->debug(3, "Got request for internal image. Starting serveInternalImage()");
|
309 |
+
$this->serveInternalImage();
|
310 |
+
}
|
311 |
+
return true;
|
312 |
+
}
|
313 |
+
protected function handleErrors(){
|
314 |
+
if($this->haveErrors()){
|
315 |
+
if(NOT_FOUND_IMAGE && $this->is404()){
|
316 |
+
if($this->serveImg(NOT_FOUND_IMAGE)){
|
317 |
+
exit(0);
|
318 |
+
} else {
|
319 |
+
$this->error("Additionally, the 404 image that is configured could not be found or there was an error serving it.");
|
320 |
+
}
|
321 |
+
}
|
322 |
+
if(ERROR_IMAGE){
|
323 |
+
if($this->serveImg(ERROR_IMAGE)){
|
324 |
+
exit(0);
|
325 |
+
} else {
|
326 |
+
$this->error("Additionally, the error image that is configured could not be found or there was an error serving it.");
|
327 |
+
}
|
328 |
+
}
|
329 |
+
$this->serveErrors();
|
330 |
+
exit(0);
|
331 |
+
}
|
332 |
+
return false;
|
333 |
+
}
|
334 |
+
protected function tryBrowserCache(){
|
335 |
+
if(BROWSER_CACHE_DISABLE){ $this->debug(3, "Browser caching is disabled"); return false; }
|
336 |
+
if(!empty($_SERVER['HTTP_IF_MODIFIED_SINCE']) ){
|
337 |
+
$this->debug(3, "Got a conditional get");
|
338 |
+
$mtime = false;
|
339 |
+
//We've already checked if the real file exists in the constructor
|
340 |
+
if(! is_file($this->cachefile)){
|
341 |
+
//If we don't have something cached, regenerate the cached image.
|
342 |
+
return false;
|
343 |
+
}
|
344 |
+
if($this->localImageMTime){
|
345 |
+
$mtime = $this->localImageMTime;
|
346 |
+
$this->debug(3, "Local real file's modification time is $mtime");
|
347 |
+
} else if(is_file($this->cachefile)){ //If it's not a local request then use the mtime of the cached file to determine the 304
|
348 |
+
$mtime = @filemtime($this->cachefile);
|
349 |
+
$this->debug(3, "Cached file's modification time is $mtime");
|
350 |
+
}
|
351 |
+
if(! $mtime){ return false; }
|
352 |
+
|
353 |
+
$iftime = strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']);
|
354 |
+
$this->debug(3, "The conditional get's if-modified-since unixtime is $iftime");
|
355 |
+
if($iftime < 1){
|
356 |
+
$this->debug(3, "Got an invalid conditional get modified since time. Returning false.");
|
357 |
+
return false;
|
358 |
+
}
|
359 |
+
if($iftime < $mtime){ //Real file or cache file has been modified since last request, so force refetch.
|
360 |
+
$this->debug(3, "File has been modified since last fetch.");
|
361 |
+
return false;
|
362 |
+
} else { //Otherwise serve a 304
|
363 |
+
$this->debug(3, "File has not been modified since last get, so serving a 304.");
|
364 |
+
header ($_SERVER['SERVER_PROTOCOL'] . ' 304 Not Modified');
|
365 |
+
$this->debug(1, "Returning 304 not modified");
|
366 |
+
return true;
|
367 |
+
}
|
368 |
+
}
|
369 |
+
return false;
|
370 |
+
}
|
371 |
+
protected function tryServerCache(){
|
372 |
+
$this->debug(3, "Trying server cache");
|
373 |
+
if(file_exists($this->cachefile)){
|
374 |
+
$this->debug(3, "Cachefile {$this->cachefile} exists");
|
375 |
+
if($this->isURL){
|
376 |
+
$this->debug(3, "This is an external request, so checking if the cachefile is empty which means the request failed previously.");
|
377 |
+
if(filesize($this->cachefile) < 1){
|
378 |
+
$this->debug(3, "Found an empty cachefile indicating a failed earlier request. Checking how old it is.");
|
379 |
+
//Fetching error occured previously
|
380 |
+
if(time() - @filemtime($this->cachefile) > WAIT_BETWEEN_FETCH_ERRORS){
|
381 |
+
$this->debug(3, "File is older than " . WAIT_BETWEEN_FETCH_ERRORS . " seconds. Deleting and returning false so app can try and load file.");
|
382 |
+
@unlink($this->cachefile);
|
383 |
+
return false; //to indicate we didn't serve from cache and app should try and load
|
384 |
+
} else {
|
385 |
+
$this->debug(3, "Empty cachefile is still fresh so returning message saying we had an error fetching this image from remote host.");
|
386 |
+
$this->set404();
|
387 |
+
$this->error("An error occured fetching image.");
|
388 |
+
return false;
|
389 |
+
}
|
390 |
+
}
|
391 |
+
} else {
|
392 |
+
$this->debug(3, "Trying to serve cachefile {$this->cachefile}");
|
393 |
+
}
|
394 |
+
if($this->serveCacheFile()){
|
395 |
+
$this->debug(3, "Succesfully served cachefile {$this->cachefile}");
|
396 |
+
return true;
|
397 |
+
} else {
|
398 |
+
$this->debug(3, "Failed to serve cachefile {$this->cachefile} - Deleting it from cache.");
|
399 |
+
//Image serving failed. We can't retry at this point, but lets remove it from cache so the next request recreates it
|
400 |
+
@unlink($this->cachefile);
|
401 |
+
return true;
|
402 |
+
}
|
403 |
+
}
|
404 |
+
}
|
405 |
+
protected function error($err){
|
406 |
+
$this->debug(3, "Adding error message: $err");
|
407 |
+
$this->errors[] = $err;
|
408 |
+
return false;
|
409 |
+
|
410 |
+
}
|
411 |
+
protected function haveErrors(){
|
412 |
+
if(sizeof($this->errors) > 0){
|
413 |
+
return true;
|
414 |
+
}
|
415 |
+
return false;
|
416 |
+
}
|
417 |
+
protected function serveErrors(){
|
418 |
+
header ($_SERVER['SERVER_PROTOCOL'] . ' 400 Bad Request');
|
419 |
+
$html = '<ul>';
|
420 |
+
foreach($this->errors as $err){
|
421 |
+
$html .= '<li>' . htmlentities($err) . '</li>';
|
422 |
+
}
|
423 |
+
$html .= '</ul>';
|
424 |
+
echo '<h1>A TimThumb error has occured</h1>The following error(s) occured:<br />' . $html . '<br />';
|
425 |
+
echo '<br />Query String : ' . htmlentities ($_SERVER['QUERY_STRING']);
|
426 |
+
echo '<br />TimThumb version : ' . VERSION . '</pre>';
|
427 |
+
}
|
428 |
+
protected function serveInternalImage(){
|
429 |
+
$this->debug(3, "Local image path is $this->localImage");
|
430 |
+
if(! $this->localImage){
|
431 |
+
$this->sanityFail("localImage not set after verifying it earlier in the code.");
|
432 |
+
return false;
|
433 |
+
}
|
434 |
+
$fileSize = filesize($this->localImage);
|
435 |
+
if($fileSize > MAX_FILE_SIZE){
|
436 |
+
$this->error("The file you specified is greater than the maximum allowed file size.");
|
437 |
+
return false;
|
438 |
+
}
|
439 |
+
if($fileSize <= 0){
|
440 |
+
$this->error("The file you specified is <= 0 bytes.");
|
441 |
+
return false;
|
442 |
+
}
|
443 |
+
$this->debug(3, "Calling processImageAndWriteToCache() for local image.");
|
444 |
+
if($this->processImageAndWriteToCache($this->localImage)){
|
445 |
+
$this->serveCacheFile();
|
446 |
+
return true;
|
447 |
+
} else {
|
448 |
+
return false;
|
449 |
+
}
|
450 |
+
}
|
451 |
+
protected function cleanCache(){
|
452 |
+
if (FILE_CACHE_TIME_BETWEEN_CLEANS < 0) {
|
453 |
+
return;
|
454 |
+
}
|
455 |
+
$this->debug(3, "cleanCache() called");
|
456 |
+
$lastCleanFile = $this->cacheDirectory . '/timthumb_cacheLastCleanTime.touch';
|
457 |
+
|
458 |
+
//If this is a new timthumb installation we need to create the file
|
459 |
+
if(! is_file($lastCleanFile)){
|
460 |
+
$this->debug(1, "File tracking last clean doesn't exist. Creating $lastCleanFile");
|
461 |
+
if (!touch($lastCleanFile)) {
|
462 |
+
$this->error("Could not create cache clean timestamp file.");
|
463 |
+
}
|
464 |
+
return;
|
465 |
+
}
|
466 |
+
if(@filemtime($lastCleanFile) < (time() - FILE_CACHE_TIME_BETWEEN_CLEANS) ){ //Cache was last cleaned more than 1 day ago
|
467 |
+
$this->debug(1, "Cache was last cleaned more than " . FILE_CACHE_TIME_BETWEEN_CLEANS . " seconds ago. Cleaning now.");
|
468 |
+
// Very slight race condition here, but worst case we'll have 2 or 3 servers cleaning the cache simultaneously once a day.
|
469 |
+
if (!touch($lastCleanFile)) {
|
470 |
+
$this->error("Could not create cache clean timestamp file.");
|
471 |
+
}
|
472 |
+
$files = glob($this->cacheDirectory . '/*' . FILE_CACHE_SUFFIX);
|
473 |
+
if ($files) {
|
474 |
+
$timeAgo = time() - FILE_CACHE_MAX_FILE_AGE;
|
475 |
+
foreach($files as $file){
|
476 |
+
if(@filemtime($file) < $timeAgo){
|
477 |
+
$this->debug(3, "Deleting cache file $file older than max age: " . FILE_CACHE_MAX_FILE_AGE . " seconds");
|
478 |
+
@unlink($file);
|
479 |
+
}
|
480 |
+
}
|
481 |
+
}
|
482 |
+
return true;
|
483 |
+
} else {
|
484 |
+
$this->debug(3, "Cache was cleaned less than " . FILE_CACHE_TIME_BETWEEN_CLEANS . " seconds ago so no cleaning needed.");
|
485 |
+
}
|
486 |
+
return false;
|
487 |
+
}
|
488 |
+
protected function processImageAndWriteToCache($localImage){
|
489 |
+
$sData = getimagesize($localImage);
|
490 |
+
$origType = $sData[2];
|
491 |
+
$mimeType = $sData['mime'];
|
492 |
+
|
493 |
+
$this->debug(3, "Mime type of image is $mimeType");
|
494 |
+
if(! preg_match('/^image\/(?:gif|jpg|jpeg|png)$/i', $mimeType)){
|
495 |
+
return $this->error("The image being resized is not a valid gif, jpg or png.");
|
496 |
+
}
|
497 |
+
|
498 |
+
if (!function_exists ('imagecreatetruecolor')) {
|
499 |
+
return $this->error('GD Library Error: imagecreatetruecolor does not exist - please contact your webhost and ask them to install the GD library');
|
500 |
+
}
|
501 |
+
|
502 |
+
if (function_exists ('imagefilter') && defined ('IMG_FILTER_NEGATE')) {
|
503 |
+
$imageFilters = array (
|
504 |
+
1 => array (IMG_FILTER_NEGATE, 0),
|
505 |
+
2 => array (IMG_FILTER_GRAYSCALE, 0),
|
506 |
+
3 => array (IMG_FILTER_BRIGHTNESS, 1),
|
507 |
+
4 => array (IMG_FILTER_CONTRAST, 1),
|
508 |
+
5 => array (IMG_FILTER_COLORIZE, 4),
|
509 |
+
6 => array (IMG_FILTER_EDGEDETECT, 0),
|
510 |
+
7 => array (IMG_FILTER_EMBOSS, 0),
|
511 |
+
8 => array (IMG_FILTER_GAUSSIAN_BLUR, 0),
|
512 |
+
9 => array (IMG_FILTER_SELECTIVE_BLUR, 0),
|
513 |
+
10 => array (IMG_FILTER_MEAN_REMOVAL, 0),
|
514 |
+
11 => array (IMG_FILTER_SMOOTH, 0),
|
515 |
+
);
|
516 |
+
}
|
517 |
+
|
518 |
+
// get standard input properties
|
519 |
+
$new_width = (int) abs ($this->param('w', 0));
|
520 |
+
$new_height = (int) abs ($this->param('h', 0));
|
521 |
+
$zoom_crop = (int) $this->param('zc', DEFAULT_ZC);
|
522 |
+
$quality = (int) abs ($this->param('q', DEFAULT_Q));
|
523 |
+
$align = $this->cropTop ? 't' : $this->param('a', 'c');
|
524 |
+
$filters = $this->param('f', DEFAULT_F);
|
525 |
+
$sharpen = (bool) $this->param('s', DEFAULT_S);
|
526 |
+
$canvas_color = $this->param('cc', DEFAULT_CC);
|
527 |
+
$canvas_trans = (bool) $this->param('ct', '1');
|
528 |
+
|
529 |
+
// set default width and height if neither are set already
|
530 |
+
if ($new_width == 0 && $new_height == 0) {
|
531 |
+
$new_width = 100;
|
532 |
+
$new_height = 100;
|
533 |
+
}
|
534 |
+
|
535 |
+
// ensure size limits can not be abused
|
536 |
+
$new_width = min ($new_width, MAX_WIDTH);
|
537 |
+
$new_height = min ($new_height, MAX_HEIGHT);
|
538 |
+
|
539 |
+
// set memory limit to be able to have enough space to resize larger images
|
540 |
+
$this->setMemoryLimit();
|
541 |
+
|
542 |
+
// open the existing image
|
543 |
+
$image = $this->openImage ($mimeType, $localImage);
|
544 |
+
if ($image === false) {
|
545 |
+
return $this->error('Unable to open image.');
|
546 |
+
}
|
547 |
+
|
548 |
+
// Get original width and height
|
549 |
+
$width = imagesx ($image);
|
550 |
+
$height = imagesy ($image);
|
551 |
+
$origin_x = 0;
|
552 |
+
$origin_y = 0;
|
553 |
+
|
554 |
+
// generate new w/h if not provided
|
555 |
+
if ($new_width && !$new_height) {
|
556 |
+
$new_height = floor ($height * ($new_width / $width));
|
557 |
+
} else if ($new_height && !$new_width) {
|
558 |
+
$new_width = floor ($width * ($new_height / $height));
|
559 |
+
}
|
560 |
+
|
561 |
+
// scale down and add borders
|
562 |
+
if ($zoom_crop == 3) {
|
563 |
+
|
564 |
+
$final_height = $height * ($new_width / $width);
|
565 |
+
|
566 |
+
if ($final_height > $new_height) {
|
567 |
+
$new_width = $width * ($new_height / $height);
|
568 |
+
} else {
|
569 |
+
$new_height = $final_height;
|
570 |
+
}
|
571 |
+
|
572 |
+
}
|
573 |
+
|
574 |
+
// create a new true color image
|
575 |
+
$canvas = imagecreatetruecolor ($new_width, $new_height);
|
576 |
+
imagealphablending ($canvas, false);
|
577 |
+
|
578 |
+
if (strlen($canvas_color) == 3) { //if is 3-char notation, edit string into 6-char notation
|
579 |
+
$canvas_color = str_repeat(substr($canvas_color, 0, 1), 2) . str_repeat(substr($canvas_color, 1, 1), 2) . str_repeat(substr($canvas_color, 2, 1), 2);
|
580 |
+
} else if (strlen($canvas_color) != 6) {
|
581 |
+
$canvas_color = DEFAULT_CC; // on error return default canvas color
|
582 |
+
}
|
583 |
+
|
584 |
+
$canvas_color_R = hexdec (substr ($canvas_color, 0, 2));
|
585 |
+
$canvas_color_G = hexdec (substr ($canvas_color, 2, 2));
|
586 |
+
$canvas_color_B = hexdec (substr ($canvas_color, 4, 2));
|
587 |
+
|
588 |
+
// Create a new transparent color for image
|
589 |
+
// If is a png and PNG_IS_TRANSPARENT is false then remove the alpha transparency
|
590 |
+
// (and if is set a canvas color show it in the background)
|
591 |
+
if(preg_match('/^image\/png$/i', $mimeType) && !PNG_IS_TRANSPARENT && $canvas_trans){
|
592 |
+
$color = imagecolorallocatealpha ($canvas, $canvas_color_R, $canvas_color_G, $canvas_color_B, 127);
|
593 |
+
}else{
|
594 |
+
$color = imagecolorallocatealpha ($canvas, $canvas_color_R, $canvas_color_G, $canvas_color_B, 0);
|
595 |
+
}
|
596 |
+
|
597 |
+
|
598 |
+
// Completely fill the background of the new image with allocated color.
|
599 |
+
imagefill ($canvas, 0, 0, $color);
|
600 |
+
|
601 |
+
// scale down and add borders
|
602 |
+
if ($zoom_crop == 2) {
|
603 |
+
|
604 |
+
$final_height = $height * ($new_width / $width);
|
605 |
+
|
606 |
+
if ($final_height > $new_height) {
|
607 |
+
|
608 |
+
$origin_x = $new_width / 2;
|
609 |
+
$new_width = $width * ($new_height / $height);
|
610 |
+
$origin_x = round ($origin_x - ($new_width / 2));
|
611 |
+
|
612 |
+
} else {
|
613 |
+
|
614 |
+
$origin_y = $new_height / 2;
|
615 |
+
$new_height = $final_height;
|
616 |
+
$origin_y = round ($origin_y - ($new_height / 2));
|
617 |
+
|
618 |
+
}
|
619 |
+
|
620 |
+
}
|
621 |
+
|
622 |
+
// Restore transparency blending
|
623 |
+
imagesavealpha ($canvas, true);
|
624 |
+
|
625 |
+
if ($zoom_crop > 0) {
|
626 |
+
|
627 |
+
$src_x = $src_y = 0;
|
628 |
+
$src_w = $width;
|
629 |
+
$src_h = $height;
|
630 |
+
|
631 |
+
$cmp_x = $width / $new_width;
|
632 |
+
$cmp_y = $height / $new_height;
|
633 |
+
|
634 |
+
// calculate x or y coordinate and width or height of source
|
635 |
+
if ($cmp_x > $cmp_y) {
|
636 |
+
|
637 |
+
$src_w = round ($width / $cmp_x * $cmp_y);
|
638 |
+
$src_x = round (($width - ($width / $cmp_x * $cmp_y)) / 2);
|
639 |
+
|
640 |
+
} else if ($cmp_y > $cmp_x) {
|
641 |
+
|
642 |
+
$src_h = round ($height / $cmp_y * $cmp_x);
|
643 |
+
$src_y = round (($height - ($height / $cmp_y * $cmp_x)) / 2);
|
644 |
+
|
645 |
+
}
|
646 |
+
|
647 |
+
// positional cropping!
|
648 |
+
if ($align) {
|
649 |
+
if (strpos ($align, 't') !== false) {
|
650 |
+
$src_y = 0;
|
651 |
+
}
|
652 |
+
if (strpos ($align, 'b') !== false) {
|
653 |
+
$src_y = $height - $src_h;
|
654 |
+
}
|
655 |
+
if (strpos ($align, 'l') !== false) {
|
656 |
+
$src_x = 0;
|
657 |
+
}
|
658 |
+
if (strpos ($align, 'r') !== false) {
|
659 |
+
$src_x = $width - $src_w;
|
660 |
+
}
|
661 |
+
}
|
662 |
+
|
663 |
+
imagecopyresampled ($canvas, $image, $origin_x, $origin_y, $src_x, $src_y, $new_width, $new_height, $src_w, $src_h);
|
664 |
+
|
665 |
+
} else {
|
666 |
+
|
667 |
+
// copy and resize part of an image with resampling
|
668 |
+
imagecopyresampled ($canvas, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
|
669 |
+
|
670 |
+
}
|
671 |
+
|
672 |
+
if ($filters != '' && function_exists ('imagefilter') && defined ('IMG_FILTER_NEGATE')) {
|
673 |
+
// apply filters to image
|
674 |
+
$filterList = explode ('|', $filters);
|
675 |
+
foreach ($filterList as $fl) {
|
676 |
+
|
677 |
+
$filterSettings = explode (',', $fl);
|
678 |
+
if (isset ($imageFilters[$filterSettings[0]])) {
|
679 |
+
|
680 |
+
for ($i = 0; $i < 4; $i ++) {
|
681 |
+
if (!isset ($filterSettings[$i])) {
|
682 |
+
$filterSettings[$i] = null;
|
683 |
+
} else {
|
684 |
+
$filterSettings[$i] = (int) $filterSettings[$i];
|
685 |
+
}
|
686 |
+
}
|
687 |
+
|
688 |
+
switch ($imageFilters[$filterSettings[0]][1]) {
|
689 |
+
|
690 |
+
case 1:
|
691 |
+
|
692 |
+
imagefilter ($canvas, $imageFilters[$filterSettings[0]][0], $filterSettings[1]);
|
693 |
+
break;
|
694 |
+
|
695 |
+
case 2:
|
696 |
+
|
697 |
+
imagefilter ($canvas, $imageFilters[$filterSettings[0]][0], $filterSettings[1], $filterSettings[2]);
|
698 |
+
break;
|
699 |
+
|
700 |
+
case 3:
|
701 |
+
|
702 |
+
imagefilter ($canvas, $imageFilters[$filterSettings[0]][0], $filterSettings[1], $filterSettings[2], $filterSettings[3]);
|
703 |
+
break;
|
704 |
+
|
705 |
+
case 4:
|
706 |
+
|
707 |
+
imagefilter ($canvas, $imageFilters[$filterSettings[0]][0], $filterSettings[1], $filterSettings[2], $filterSettings[3], $filterSettings[4]);
|
708 |
+
break;
|
709 |
+
|
710 |
+
default:
|
711 |
+
|
712 |
+
imagefilter ($canvas, $imageFilters[$filterSettings[0]][0]);
|
713 |
+
break;
|
714 |
+
|
715 |
+
}
|
716 |
+
}
|
717 |
+
}
|
718 |
+
}
|
719 |
+
|
720 |
+
// sharpen image
|
721 |
+
if ($sharpen && function_exists ('imageconvolution')) {
|
722 |
+
|
723 |
+
$sharpenMatrix = array (
|
724 |
+
array (-1,-1,-1),
|
725 |
+
array (-1,16,-1),
|
726 |
+
array (-1,-1,-1),
|
727 |
+
);
|
728 |
+
|
729 |
+
$divisor = 8;
|
730 |
+
$offset = 0;
|
731 |
+
|
732 |
+
imageconvolution ($canvas, $sharpenMatrix, $divisor, $offset);
|
733 |
+
|
734 |
+
}
|
735 |
+
//Straight from Wordpress core code. Reduces filesize by up to 70% for PNG's
|
736 |
+
if ( (IMAGETYPE_PNG == $origType || IMAGETYPE_GIF == $origType) && function_exists('imageistruecolor') && !imageistruecolor( $image ) && imagecolortransparent( $image ) > 0 ){
|
737 |
+
imagetruecolortopalette( $canvas, false, imagecolorstotal( $image ) );
|
738 |
+
}
|
739 |
+
|
740 |
+
$imgType = "";
|
741 |
+
$tempfile = tempnam($this->cacheDirectory, 'timthumb_tmpimg_');
|
742 |
+
if(preg_match('/^image\/(?:jpg|jpeg)$/i', $mimeType)){
|
743 |
+
$imgType = 'jpg';
|
744 |
+
imagejpeg($canvas, $tempfile, $quality);
|
745 |
+
} else if(preg_match('/^image\/png$/i', $mimeType)){
|
746 |
+
$imgType = 'png';
|
747 |
+
imagepng($canvas, $tempfile, floor($quality * 0.09));
|
748 |
+
} else if(preg_match('/^image\/gif$/i', $mimeType)){
|
749 |
+
$imgType = 'gif';
|
750 |
+
imagegif($canvas, $tempfile);
|
751 |
+
} else {
|
752 |
+
return $this->sanityFail("Could not match mime type after verifying it previously.");
|
753 |
+
}
|
754 |
+
|
755 |
+
if($imgType == 'png' && OPTIPNG_ENABLED && OPTIPNG_PATH && @is_file(OPTIPNG_PATH)){
|
756 |
+
$exec = OPTIPNG_PATH;
|
757 |
+
$this->debug(3, "optipng'ing $tempfile");
|
758 |
+
$presize = filesize($tempfile);
|
759 |
+
$out = `$exec -o1 $tempfile`; //you can use up to -o7 but it really slows things down
|
760 |
+
clearstatcache();
|
761 |
+
$aftersize = filesize($tempfile);
|
762 |
+
$sizeDrop = $presize - $aftersize;
|
763 |
+
if($sizeDrop > 0){
|
764 |
+
$this->debug(1, "optipng reduced size by $sizeDrop");
|
765 |
+
} else if($sizeDrop < 0){
|
766 |
+
$this->debug(1, "optipng increased size! Difference was: $sizeDrop");
|
767 |
+
} else {
|
768 |
+
$this->debug(1, "optipng did not change image size.");
|
769 |
+
}
|
770 |
+
} else if($imgType == 'png' && PNGCRUSH_ENABLED && PNGCRUSH_PATH && @is_file(PNGCRUSH_PATH)){
|
771 |
+
$exec = PNGCRUSH_PATH;
|
772 |
+
$tempfile2 = tempnam($this->cacheDirectory, 'timthumb_tmpimg_');
|
773 |
+
$this->debug(3, "pngcrush'ing $tempfile to $tempfile2");
|
774 |
+
$out = `$exec $tempfile $tempfile2`;
|
775 |
+
$todel = "";
|
776 |
+
if(is_file($tempfile2)){
|
777 |
+
$sizeDrop = filesize($tempfile) - filesize($tempfile2);
|
778 |
+
if($sizeDrop > 0){
|
779 |
+
$this->debug(1, "pngcrush was succesful and gave a $sizeDrop byte size reduction");
|
780 |
+
$todel = $tempfile;
|
781 |
+
$tempfile = $tempfile2;
|
782 |
+
} else {
|
783 |
+
$this->debug(1, "pngcrush did not reduce file size. Difference was $sizeDrop bytes.");
|
784 |
+
$todel = $tempfile2;
|
785 |
+
}
|
786 |
+
} else {
|
787 |
+
$this->debug(3, "pngcrush failed with output: $out");
|
788 |
+
$todel = $tempfile2;
|
789 |
+
}
|
790 |
+
@unlink($todel);
|
791 |
+
}
|
792 |
+
|
793 |
+
$this->debug(3, "Rewriting image with security header.");
|
794 |
+
$tempfile4 = tempnam($this->cacheDirectory, 'timthumb_tmpimg_');
|
795 |
+
$context = stream_context_create ();
|
796 |
+
$fp = fopen($tempfile,'r',0,$context);
|
797 |
+
file_put_contents($tempfile4, $this->filePrependSecurityBlock . $imgType . ' ?' . '>'); //6 extra bytes, first 3 being image type
|
798 |
+
file_put_contents($tempfile4, $fp, FILE_APPEND);
|
799 |
+
fclose($fp);
|
800 |
+
@unlink($tempfile);
|
801 |
+
$this->debug(3, "Locking and replacing cache file.");
|
802 |
+
$lockFile = $this->cachefile . '.lock';
|
803 |
+
$fh = fopen($lockFile, 'w');
|
804 |
+
if(! $fh){
|
805 |
+
return $this->error("Could not open the lockfile for writing an image.");
|
806 |
+
}
|
807 |
+
if(flock($fh, LOCK_EX)){
|
808 |
+
@unlink($this->cachefile); //rename generally overwrites, but doing this in case of platform specific quirks. File might not exist yet.
|
809 |
+
rename($tempfile4, $this->cachefile);
|
810 |
+
flock($fh, LOCK_UN);
|
811 |
+
fclose($fh);
|
812 |
+
@unlink($lockFile);
|
813 |
+
} else {
|
814 |
+
fclose($fh);
|
815 |
+
@unlink($lockFile);
|
816 |
+
@unlink($tempfile4);
|
817 |
+
return $this->error("Could not get a lock for writing.");
|
818 |
+
}
|
819 |
+
$this->debug(3, "Done image replace with security header. Cleaning up and running cleanCache()");
|
820 |
+
imagedestroy($canvas);
|
821 |
+
imagedestroy($image);
|
822 |
+
return true;
|
823 |
+
}
|
824 |
+
protected function calcDocRoot(){
|
825 |
+
$docRoot = @$_SERVER['DOCUMENT_ROOT'];
|
826 |
+
if (defined('LOCAL_FILE_BASE_DIRECTORY')) {
|
827 |
+
$docRoot = LOCAL_FILE_BASE_DIRECTORY;
|
828 |
+
}
|
829 |
+
if(!isset($docRoot)){
|
830 |
+
$this->debug(3, "DOCUMENT_ROOT is not set. This is probably windows. Starting search 1.");
|
831 |
+
if(isset($_SERVER['SCRIPT_FILENAME'])){
|
832 |
+
$docRoot = str_replace( '\\', '/', substr($_SERVER['SCRIPT_FILENAME'], 0, 0-strlen($_SERVER['PHP_SELF'])));
|
833 |
+
$this->debug(3, "Generated docRoot using SCRIPT_FILENAME and PHP_SELF as: $docRoot");
|
834 |
+
}
|
835 |
+
}
|
836 |
+
if(!isset($docRoot)){
|
837 |
+
$this->debug(3, "DOCUMENT_ROOT still is not set. Starting search 2.");
|
838 |
+
if(isset($_SERVER['PATH_TRANSLATED'])){
|
839 |
+
$docRoot = str_replace( '\\', '/', substr(str_replace('\\\\', '\\', $_SERVER['PATH_TRANSLATED']), 0, 0-strlen($_SERVER['PHP_SELF'])));
|
840 |
+
$this->debug(3, "Generated docRoot using PATH_TRANSLATED and PHP_SELF as: $docRoot");
|
841 |
+
}
|
842 |
+
}
|
843 |
+
if($docRoot && $_SERVER['DOCUMENT_ROOT'] != '/'){ $docRoot = preg_replace('/\/$/', '', $docRoot); }
|
844 |
+
$this->debug(3, "Doc root is: " . $docRoot);
|
845 |
+
$this->docRoot = $docRoot;
|
846 |
+
|
847 |
+
}
|
848 |
+
protected function getLocalImagePath($src){
|
849 |
+
$src = ltrim($src, '/'); //strip off the leading '/'
|
850 |
+
if(! $this->docRoot){
|
851 |
+
$this->debug(3, "We have no document root set, so as a last resort, lets check if the image is in the current dir and serve that.");
|
852 |
+
//We don't support serving images outside the current dir if we don't have a doc root for security reasons.
|
853 |
+
$file = preg_replace('/^.*?([^\/\\\\]+)$/', '$1', $src); //strip off any path info and just leave the filename.
|
854 |
+
if(is_file($file)){
|
855 |
+
return $this->realpath($file);
|
856 |
+
}
|
857 |
+
return $this->error("Could not find your website document root and the file specified doesn't exist in timthumbs directory. We don't support serving files outside timthumb's directory without a document root for security reasons.");
|
858 |
+
} //Do not go past this point without docRoot set
|
859 |
+
|
860 |
+
//Try src under docRoot
|
861 |
+
if(file_exists ($this->docRoot . '/' . $src)) {
|
862 |
+
$this->debug(3, "Found file as " . $this->docRoot . '/' . $src);
|
863 |
+
$real = $this->realpath($this->docRoot . '/' . $src);
|
864 |
+
if(stripos($real, $this->docRoot) === 0){
|
865 |
+
return $real;
|
866 |
+
} else {
|
867 |
+
$this->debug(1, "Security block: The file specified occurs outside the document root.");
|
868 |
+
//allow search to continue
|
869 |
+
}
|
870 |
+
}
|
871 |
+
//Check absolute paths and then verify the real path is under doc root
|
872 |
+
$absolute = $this->realpath('/' . $src);
|
873 |
+
if($absolute && file_exists($absolute)){ //realpath does file_exists check, so can probably skip the exists check here
|
874 |
+
$this->debug(3, "Found absolute path: $absolute");
|
875 |
+
if(! $this->docRoot){ $this->sanityFail("docRoot not set when checking absolute path."); }
|
876 |
+
if(stripos($absolute, $this->docRoot) === 0){
|
877 |
+
return $absolute;
|
878 |
+
} else {
|
879 |
+
$this->debug(1, "Security block: The file specified occurs outside the document root.");
|
880 |
+
//and continue search
|
881 |
+
}
|
882 |
+
}
|
883 |
+
|
884 |
+
$base = $this->docRoot;
|
885 |
+
|
886 |
+
// account for Windows directory structure
|
887 |
+
if (strstr($_SERVER['SCRIPT_FILENAME'],':')) {
|
888 |
+
$sub_directories = explode('\\', str_replace($this->docRoot, '', $_SERVER['SCRIPT_FILENAME']));
|
889 |
+
} else {
|
890 |
+
$sub_directories = explode('/', str_replace($this->docRoot, '', $_SERVER['SCRIPT_FILENAME']));
|
891 |
+
}
|
892 |
+
|
893 |
+
foreach ($sub_directories as $sub){
|
894 |
+
$base .= $sub . '/';
|
895 |
+
$this->debug(3, "Trying file as: " . $base . $src);
|
896 |
+
if(file_exists($base . $src)){
|
897 |
+
$this->debug(3, "Found file as: " . $base . $src);
|
898 |
+
$real = $this->realpath($base . $src);
|
899 |
+
if(stripos($real, $this->realpath($this->docRoot)) === 0){
|
900 |
+
return $real;
|
901 |
+
} else {
|
902 |
+
$this->debug(1, "Security block: The file specified occurs outside the document root.");
|
903 |
+
//And continue search
|
904 |
+
}
|
905 |
+
}
|
906 |
+
}
|
907 |
+
return false;
|
908 |
+
}
|
909 |
+
protected function realpath($path){
|
910 |
+
//try to remove any relative paths
|
911 |
+
$remove_relatives = '/\w+\/\.\.\//';
|
912 |
+
while(preg_match($remove_relatives,$path)){
|
913 |
+
$path = preg_replace($remove_relatives, '', $path);
|
914 |
+
}
|
915 |
+
//if any remain use PHP realpath to strip them out, otherwise return $path
|
916 |
+
//if using realpath, any symlinks will also be resolved
|
917 |
+
return preg_match('#^\.\./|/\.\./#', $path) ? realpath($path) : $path;
|
918 |
+
}
|
919 |
+
protected function toDelete($name){
|
920 |
+
$this->debug(3, "Scheduling file $name to delete on destruct.");
|
921 |
+
$this->toDeletes[] = $name;
|
922 |
+
}
|
923 |
+
protected function serveWebshot(){
|
924 |
+
$this->debug(3, "Starting serveWebshot");
|
925 |
+
$instr = "Please follow the instructions at http://code.google.com/p/timthumb/ to set your server up for taking website screenshots.";
|
926 |
+
if(! is_file(WEBSHOT_CUTYCAPT)){
|
927 |
+
return $this->error("CutyCapt is not installed. $instr");
|
928 |
+
}
|
929 |
+
if(! is_file(WEBSHOT_XVFB)){
|
930 |
+
return $this->Error("Xvfb is not installed. $instr");
|
931 |
+
}
|
932 |
+
$cuty = WEBSHOT_CUTYCAPT;
|
933 |
+
$xv = WEBSHOT_XVFB;
|
934 |
+
$screenX = WEBSHOT_SCREEN_X;
|
935 |
+
$screenY = WEBSHOT_SCREEN_Y;
|
936 |
+
$colDepth = WEBSHOT_COLOR_DEPTH;
|
937 |
+
$format = WEBSHOT_IMAGE_FORMAT;
|
938 |
+
$timeout = WEBSHOT_TIMEOUT * 1000;
|
939 |
+
$ua = WEBSHOT_USER_AGENT;
|
940 |
+
$jsOn = WEBSHOT_JAVASCRIPT_ON ? 'on' : 'off';
|
941 |
+
$javaOn = WEBSHOT_JAVA_ON ? 'on' : 'off';
|
942 |
+
$pluginsOn = WEBSHOT_PLUGINS_ON ? 'on' : 'off';
|
943 |
+
$proxy = WEBSHOT_PROXY ? ' --http-proxy=' . WEBSHOT_PROXY : '';
|
944 |
+
$tempfile = tempnam($this->cacheDirectory, 'timthumb_webshot');
|
945 |
+
$url = $this->src;
|
946 |
+
if(! preg_match('/^https?:\/\/[a-zA-Z0-9\.\-]+/i', $url)){
|
947 |
+
return $this->error("Invalid URL supplied.");
|
948 |
+
}
|
949 |
+
$url = preg_replace('/[^A-Za-z0-9\-\.\_\~:\/\?\#\[\]\@\!\$\&\'\(\)\*\+\,\;\=]+/', '', $url); //RFC 3986
|
950 |
+
//Very important we don't allow injection of shell commands here. URL is between quotes and we are only allowing through chars allowed by a the RFC
|
951 |
+
// which AFAIKT can't be used for shell injection.
|
952 |
+
if(WEBSHOT_XVFB_RUNNING){
|
953 |
+
putenv('DISPLAY=:100.0');
|
954 |
+
$command = "$cuty $proxy --max-wait=$timeout --user-agent=\"$ua\" --javascript=$jsOn --java=$javaOn --plugins=$pluginsOn --js-can-open-windows=off --url=\"$url\" --out-format=$format --out=$tempfile";
|
955 |
+
} else {
|
956 |
+
$command = "$xv --server-args=\"-screen 0, {$screenX}x{$screenY}x{$colDepth}\" $cuty $proxy --max-wait=$timeout --user-agent=\"$ua\" --javascript=$jsOn --java=$javaOn --plugins=$pluginsOn --js-can-open-windows=off --url=\"$url\" --out-format=$format --out=$tempfile";
|
957 |
+
}
|
958 |
+
$this->debug(3, "Executing command: $command");
|
959 |
+
$out = `$command`;
|
960 |
+
$this->debug(3, "Received output: $out");
|
961 |
+
if(! is_file($tempfile)){
|
962 |
+
$this->set404();
|
963 |
+
return $this->error("The command to create a thumbnail failed.");
|
964 |
+
}
|
965 |
+
$this->cropTop = true;
|
966 |
+
if($this->processImageAndWriteToCache($tempfile)){
|
967 |
+
$this->debug(3, "Image processed succesfully. Serving from cache");
|
968 |
+
return $this->serveCacheFile();
|
969 |
+
} else {
|
970 |
+
return false;
|
971 |
+
}
|
972 |
+
}
|
973 |
+
protected function serveExternalImage(){
|
974 |
+
if(! preg_match('/^https?:\/\/[a-zA-Z0-9\-\.]+/i', $this->src)){
|
975 |
+
$this->error("Invalid URL supplied.");
|
976 |
+
return false;
|
977 |
+
}
|
978 |
+
$tempfile = tempnam($this->cacheDirectory, 'timthumb');
|
979 |
+
$this->debug(3, "Fetching external image into temporary file $tempfile");
|
980 |
+
$this->toDelete($tempfile);
|
981 |
+
#fetch file here
|
982 |
+
if(! $this->getURL($this->src, $tempfile)){
|
983 |
+
@unlink($this->cachefile);
|
984 |
+
touch($this->cachefile);
|
985 |
+
$this->debug(3, "Error fetching URL: " . $this->lastURLError);
|
986 |
+
$this->error("Error reading the URL you specified from remote host." . $this->lastURLError);
|
987 |
+
return false;
|
988 |
+
}
|
989 |
+
|
990 |
+
$mimeType = $this->getMimeType($tempfile);
|
991 |
+
if(! preg_match("/^image\/(?:jpg|jpeg|gif|png)$/i", $mimeType)){
|
992 |
+
$this->debug(3, "Remote file has invalid mime type: $mimeType");
|
993 |
+
@unlink($this->cachefile);
|
994 |
+
touch($this->cachefile);
|
995 |
+
$this->error("The remote file is not a valid image.");
|
996 |
+
return false;
|
997 |
+
}
|
998 |
+
if($this->processImageAndWriteToCache($tempfile)){
|
999 |
+
$this->debug(3, "Image processed succesfully. Serving from cache");
|
1000 |
+
return $this->serveCacheFile();
|
1001 |
+
} else {
|
1002 |
+
return false;
|
1003 |
+
}
|
1004 |
+
}
|
1005 |
+
public static function curlWrite($h, $d){
|
1006 |
+
fwrite(self::$curlFH, $d);
|
1007 |
+
self::$curlDataWritten += strlen($d);
|
1008 |
+
if(self::$curlDataWritten > MAX_FILE_SIZE){
|
1009 |
+
return 0;
|
1010 |
+
} else {
|
1011 |
+
return strlen($d);
|
1012 |
+
}
|
1013 |
+
}
|
1014 |
+
protected function serveCacheFile(){
|
1015 |
+
$this->debug(3, "Serving {$this->cachefile}");
|
1016 |
+
if(! is_file($this->cachefile)){
|
1017 |
+
$this->error("serveCacheFile called in timthumb but we couldn't find the cached file.");
|
1018 |
+
return false;
|
1019 |
+
}
|
1020 |
+
$fp = fopen($this->cachefile, 'rb');
|
1021 |
+
if(! $fp){ return $this->error("Could not open cachefile."); }
|
1022 |
+
fseek($fp, strlen($this->filePrependSecurityBlock), SEEK_SET);
|
1023 |
+
$imgType = fread($fp, 3);
|
1024 |
+
fseek($fp, 3, SEEK_CUR);
|
1025 |
+
if(ftell($fp) != strlen($this->filePrependSecurityBlock) + 6){
|
1026 |
+
@unlink($this->cachefile);
|
1027 |
+
return $this->error("The cached image file seems to be corrupt.");
|
1028 |
+
}
|
1029 |
+
$imageDataSize = filesize($this->cachefile) - (strlen($this->filePrependSecurityBlock) + 6);
|
1030 |
+
$this->sendImageHeaders($imgType, $imageDataSize);
|
1031 |
+
$bytesSent = @fpassthru($fp);
|
1032 |
+
fclose($fp);
|
1033 |
+
if($bytesSent > 0){
|
1034 |
+
return true;
|
1035 |
+
}
|
1036 |
+
$content = file_get_contents ($this->cachefile);
|
1037 |
+
if ($content != FALSE) {
|
1038 |
+
$content = substr($content, strlen($this->filePrependSecurityBlock) + 6);
|
1039 |
+
echo $content;
|
1040 |
+
$this->debug(3, "Served using file_get_contents and echo");
|
1041 |
+
return true;
|
1042 |
+
} else {
|
1043 |
+
$this->error("Cache file could not be loaded.");
|
1044 |
+
return false;
|
1045 |
+
}
|
1046 |
+
}
|
1047 |
+
protected function sendImageHeaders($mimeType, $dataSize){
|
1048 |
+
if(! preg_match('/^image\//i', $mimeType)){
|
1049 |
+
$mimeType = 'image/' . $mimeType;
|
1050 |
+
}
|
1051 |
+
if(strtolower($mimeType) == 'image/jpg'){
|
1052 |
+
$mimeType = 'image/jpeg';
|
1053 |
+
}
|
1054 |
+
$gmdate_expires = gmdate ('D, d M Y H:i:s', strtotime ('now +10 days')) . ' GMT';
|
1055 |
+
$gmdate_modified = gmdate ('D, d M Y H:i:s') . ' GMT';
|
1056 |
+
// send content headers then display image
|
1057 |
+
header ('Content-Type: ' . $mimeType);
|
1058 |
+
header ('Accept-Ranges: none'); //Changed this because we don't accept range requests
|
1059 |
+
header ('Last-Modified: ' . $gmdate_modified);
|
1060 |
+
header ('Content-Length: ' . $dataSize);
|
1061 |
+
if(BROWSER_CACHE_DISABLE){
|
1062 |
+
$this->debug(3, "Browser cache is disabled so setting non-caching headers.");
|
1063 |
+
header('Cache-Control: no-store, no-cache, must-revalidate, max-age=0');
|
1064 |
+
header("Pragma: no-cache");
|
1065 |
+
header('Expires: ' . gmdate ('D, d M Y H:i:s', time()));
|
1066 |
+
} else {
|
1067 |
+
$this->debug(3, "Browser caching is enabled");
|
1068 |
+
header('Cache-Control: max-age=' . BROWSER_CACHE_MAX_AGE . ', must-revalidate');
|
1069 |
+
header('Expires: ' . $gmdate_expires);
|
1070 |
+
}
|
1071 |
+
return true;
|
1072 |
+
}
|
1073 |
+
protected function securityChecks(){
|
1074 |
+
}
|
1075 |
+
protected function param($property, $default = ''){
|
1076 |
+
if (isset ($_GET[$property])) {
|
1077 |
+
return $_GET[$property];
|
1078 |
+
} else {
|
1079 |
+
return $default;
|
1080 |
+
}
|
1081 |
+
}
|
1082 |
+
protected function openImage($mimeType, $src){
|
1083 |
+
switch ($mimeType) {
|
1084 |
+
case 'image/jpeg':
|
1085 |
+
$image = imagecreatefromjpeg ($src);
|
1086 |
+
break;
|
1087 |
+
|
1088 |
+
case 'image/png':
|
1089 |
+
$image = imagecreatefrompng ($src);
|
1090 |
+
break;
|
1091 |
+
|
1092 |
+
case 'image/gif':
|
1093 |
+
$image = imagecreatefromgif ($src);
|
1094 |
+
break;
|
1095 |
+
|
1096 |
+
default:
|
1097 |
+
$this->error("Unrecognised mimeType");
|
1098 |
+
}
|
1099 |
+
|
1100 |
+
return $image;
|
1101 |
+
}
|
1102 |
+
protected function getIP(){
|
1103 |
+
$rem = @$_SERVER["REMOTE_ADDR"];
|
1104 |
+
$ff = @$_SERVER["HTTP_X_FORWARDED_FOR"];
|
1105 |
+
$ci = @$_SERVER["HTTP_CLIENT_IP"];
|
1106 |
+
if(preg_match('/^(?:192\.168|172\.16|10\.|127\.)/', $rem)){
|
1107 |
+
if($ff){ return $ff; }
|
1108 |
+
if($ci){ return $ci; }
|
1109 |
+
return $rem;
|
1110 |
+
} else {
|
1111 |
+
if($rem){ return $rem; }
|
1112 |
+
if($ff){ return $ff; }
|
1113 |
+
if($ci){ return $ci; }
|
1114 |
+
return "UNKNOWN";
|
1115 |
+
}
|
1116 |
+
}
|
1117 |
+
protected function debug($level, $msg){
|
1118 |
+
if(DEBUG_ON && $level <= DEBUG_LEVEL){
|
1119 |
+
$execTime = sprintf('%.6f', microtime(true) - $this->startTime);
|
1120 |
+
$tick = sprintf('%.6f', 0);
|
1121 |
+
if($this->lastBenchTime > 0){
|
1122 |
+
$tick = sprintf('%.6f', microtime(true) - $this->lastBenchTime);
|
1123 |
+
}
|
1124 |
+
$this->lastBenchTime = microtime(true);
|
1125 |
+
error_log("TimThumb Debug line " . __LINE__ . " [$execTime : $tick]: $msg");
|
1126 |
+
}
|
1127 |
+
}
|
1128 |
+
protected function sanityFail($msg){
|
1129 |
+
return $this->error("There is a problem in the timthumb code. Message: Please report this error at <a href='http://code.google.com/p/timthumb/issues/list'>timthumb's bug tracking page</a>: $msg");
|
1130 |
+
}
|
1131 |
+
protected function getMimeType($file){
|
1132 |
+
$info = getimagesize($file);
|
1133 |
+
if(is_array($info) && $info['mime']){
|
1134 |
+
return $info['mime'];
|
1135 |
+
}
|
1136 |
+
return '';
|
1137 |
+
}
|
1138 |
+
protected function setMemoryLimit(){
|
1139 |
+
$inimem = ini_get('memory_limit');
|
1140 |
+
$inibytes = timthumb::returnBytes($inimem);
|
1141 |
+
$ourbytes = timthumb::returnBytes(MEMORY_LIMIT);
|
1142 |
+
if($inibytes < $ourbytes){
|
1143 |
+
ini_set ('memory_limit', MEMORY_LIMIT);
|
1144 |
+
$this->debug(3, "Increased memory from $inimem to " . MEMORY_LIMIT);
|
1145 |
+
} else {
|
1146 |
+
$this->debug(3, "Not adjusting memory size because the current setting is " . $inimem . " and our size of " . MEMORY_LIMIT . " is smaller.");
|
1147 |
+
}
|
1148 |
+
}
|
1149 |
+
protected static function returnBytes($size_str){
|
1150 |
+
switch (substr ($size_str, -1))
|
1151 |
+
{
|
1152 |
+
case 'M': case 'm': return (int)$size_str * 1048576;
|
1153 |
+
case 'K': case 'k': return (int)$size_str * 1024;
|
1154 |
+
case 'G': case 'g': return (int)$size_str * 1073741824;
|
1155 |
+
default: return $size_str;
|
1156 |
+
}
|
1157 |
+
}
|
1158 |
+
protected function getURL($url, $tempfile){
|
1159 |
+
$this->lastURLError = false;
|
1160 |
+
$url = preg_replace('/ /', '%20', $url);
|
1161 |
+
if(function_exists('curl_init')){
|
1162 |
+
$this->debug(3, "Curl is installed so using it to fetch URL.");
|
1163 |
+
self::$curlFH = fopen($tempfile, 'w');
|
1164 |
+
if(! self::$curlFH){
|
1165 |
+
$this->error("Could not open $tempfile for writing.");
|
1166 |
+
return false;
|
1167 |
+
}
|
1168 |
+
self::$curlDataWritten = 0;
|
1169 |
+
$this->debug(3, "Fetching url with curl: $url");
|
1170 |
+
$curl = curl_init($url);
|
1171 |
+
curl_setopt ($curl, CURLOPT_TIMEOUT, CURL_TIMEOUT);
|
1172 |
+
curl_setopt ($curl, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/534.30 (KHTML, like Gecko) Chrome/12.0.742.122 Safari/534.30");
|
1173 |
+
curl_setopt ($curl, CURLOPT_RETURNTRANSFER, TRUE);
|
1174 |
+
curl_setopt ($curl, CURLOPT_HEADER, 0);
|
1175 |
+
curl_setopt ($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
|
1176 |
+
curl_setopt ($curl, CURLOPT_WRITEFUNCTION, 'timthumb::curlWrite');
|
1177 |
+
@curl_setopt ($curl, CURLOPT_FOLLOWLOCATION, true);
|
1178 |
+
@curl_setopt ($curl, CURLOPT_MAXREDIRS, 10);
|
1179 |
+
|
1180 |
+
$curlResult = curl_exec($curl);
|
1181 |
+
fclose(self::$curlFH);
|
1182 |
+
$httpStatus = curl_getinfo($curl, CURLINFO_HTTP_CODE);
|
1183 |
+
if($httpStatus == 404){
|
1184 |
+
$this->set404();
|
1185 |
+
}
|
1186 |
+
if($curlResult){
|
1187 |
+
curl_close($curl);
|
1188 |
+
return true;
|
1189 |
+
} else {
|
1190 |
+
$this->lastURLError = curl_error($curl);
|
1191 |
+
curl_close($curl);
|
1192 |
+
return false;
|
1193 |
+
}
|
1194 |
+
} else {
|
1195 |
+
$img = @file_get_contents ($url);
|
1196 |
+
if($img === false){
|
1197 |
+
$err = error_get_last();
|
1198 |
+
if(is_array($err) && $err['message']){
|
1199 |
+
$this->lastURLError = $err['message'];
|
1200 |
+
} else {
|
1201 |
+
$this->lastURLError = $err;
|
1202 |
+
}
|
1203 |
+
if(preg_match('/404/', $this->lastURLError)){
|
1204 |
+
$this->set404();
|
1205 |
+
}
|
1206 |
+
|
1207 |
+
return false;
|
1208 |
+
}
|
1209 |
+
if(! file_put_contents($tempfile, $img)){
|
1210 |
+
$this->error("Could not write to $tempfile.");
|
1211 |
+
return false;
|
1212 |
+
}
|
1213 |
+
return true;
|
1214 |
+
}
|
1215 |
+
|
1216 |
+
}
|
1217 |
+
protected function serveImg($file){
|
1218 |
+
$s = getimagesize($file);
|
1219 |
+
if(! ($s && $s['mime'])){
|
1220 |
+
return false;
|
1221 |
+
}
|
1222 |
+
header ('Content-Type: ' . $s['mime']);
|
1223 |
+
header ('Content-Length: ' . filesize($file) );
|
1224 |
+
header ('Cache-Control: no-store, no-cache, must-revalidate, max-age=0');
|
1225 |
+
header ("Pragma: no-cache");
|
1226 |
+
$bytes = @readfile($file);
|
1227 |
+
if($bytes > 0){
|
1228 |
+
return true;
|
1229 |
+
}
|
1230 |
+
$content = @file_get_contents ($file);
|
1231 |
+
if ($content != FALSE){
|
1232 |
+
echo $content;
|
1233 |
+
return true;
|
1234 |
+
}
|
1235 |
+
return false;
|
1236 |
+
|
1237 |
+
}
|
1238 |
+
protected function set404(){
|
1239 |
+
$this->is404 = true;
|
1240 |
+
}
|
1241 |
+
protected function is404(){
|
1242 |
+
return $this->is404;
|
1243 |
+
}
|
1244 |
+
}
|
user-avatar.php
CHANGED
@@ -3,7 +3,7 @@
|
|
3 |
Plugin Name: User Avatar
|
4 |
Plugin URI: http://wordpress.org/extend/plugins/user-avatar/
|
5 |
Description: Allows users to associate photos with their accounts by accessing their "Your Profile" page that default as Gravatar or WordPress Default image (from Discussion Page).
|
6 |
-
Version: 1.
|
7 |
Author: Enej Bajgoric / Gagan Sandhu / CTLT DEV
|
8 |
|
9 |
|
@@ -30,12 +30,16 @@ add_action('wp_ajax_user_avatar_add_photo', 'user_avatar_add_photo');
|
|
30 |
add_action('user_avatar_iframe_head','user_avatar_init');
|
31 |
|
32 |
|
33 |
-
|
|
|
|
|
|
|
34 |
wp_enqueue_script("thickbox");
|
35 |
wp_enqueue_style("thickbox");
|
36 |
-
|
37 |
}
|
38 |
|
|
|
39 |
/**
|
40 |
* user_avatar_init function.
|
41 |
* Description: Initializing user avatar style.
|
@@ -43,9 +47,19 @@ if($GLOBALS['pagenow'] == 'profile.php' or $GLOBALS['pagenow'] == 'user-edit.php
|
|
43 |
* @return void
|
44 |
*/
|
45 |
function user_avatar_init(){
|
|
|
|
|
|
|
|
|
|
|
46 |
wp_enqueue_style('user-avatar', plugins_url('/user-avatar/css/user-avatar.css'), 'css');
|
47 |
-
|
|
|
|
|
|
|
|
|
48 |
|
|
|
49 |
/**
|
50 |
* user_avatar_core_set_avatar_constants function.
|
51 |
* Description: Establishing restraints on sizes of files and dimensions of images.
|
@@ -54,6 +68,7 @@ function user_avatar_init(){
|
|
54 |
* @return void
|
55 |
*/
|
56 |
function user_avatar_core_set_avatar_constants() {
|
|
|
57 |
global $bp;
|
58 |
|
59 |
if ( !defined( 'USER_AVATAR_UPLOAD_PATH' ) )
|
@@ -86,6 +101,10 @@ function user_avatar_core_set_avatar_constants() {
|
|
86 |
|
87 |
if ( !defined( 'USER_AVATAR_DEFAULT_THUMB' ) )
|
88 |
define( 'USER_AVATAR_DEFAULT_THUMB', plugins_url('/user-avatar/images/mystery-man-50.jpg') );
|
|
|
|
|
|
|
|
|
89 |
}
|
90 |
|
91 |
/**
|
@@ -123,30 +142,39 @@ function user_avatar_core_avatar_url()
|
|
123 |
function user_avatar_add_photo() {
|
124 |
global $current_user;
|
125 |
|
126 |
-
|
127 |
-
if(($_GET['uid'] == $current_user->ID || is_super_admin($current_user->ID)) && is_numeric($_GET['uid']))
|
128 |
{
|
129 |
$uid = $_GET['uid'];
|
130 |
-
|
131 |
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
132 |
<html xmlns="http://www.w3.org/1999/xhtml" <?php do_action('admin_xml_ns'); ?> <?php language_attributes(); ?>>
|
133 |
<head>
|
134 |
<meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php echo get_option('blog_charset'); ?>" />
|
135 |
<title><?php bloginfo('name') ?> › <?php _e('Uploads'); ?> — <?php _e('WordPress'); ?></title>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
136 |
<?php
|
137 |
|
138 |
-
wp_enqueue_style( 'global' );
|
139 |
-
wp_enqueue_style( 'wp-admin' );
|
140 |
-
wp_enqueue_style( 'colors' );
|
141 |
-
wp_enqueue_style( 'ie' );
|
142 |
|
143 |
-
wp_enqueue_style('imgareaselect');
|
144 |
-
wp_enqueue_script('imgareaselect');
|
145 |
do_action('user_avatar_iframe_head');
|
146 |
-
|
147 |
-
|
148 |
-
do_action('admin_head');
|
149 |
?>
|
|
|
150 |
</head>
|
151 |
<body>
|
152 |
<?php
|
@@ -172,7 +200,7 @@ function user_avatar_add_photo() {
|
|
172 |
</html>
|
173 |
<?php
|
174 |
}else {
|
175 |
-
wp_die("You are not allowed to do that.");
|
176 |
}
|
177 |
die();
|
178 |
}
|
@@ -190,12 +218,12 @@ function user_avatar_add_photo_step1($uid)
|
|
190 |
?>
|
191 |
<p id="step1-image" >
|
192 |
<?php
|
193 |
-
echo
|
194 |
?>
|
195 |
</p>
|
196 |
<div id="user-avatar-step1">
|
197 |
<form enctype="multipart/form-data" id="uploadForm" method="POST" action="<?php echo admin_url('admin-ajax.php'); ?>?action=user_avatar_add_photo&step=2&uid=<?php echo $uid; ?>" >
|
198 |
-
<label for="upload"><?php _e('Choose an image from your computer:'); ?></label><br /><input type="file" id="upload" name="uploadedfile" />
|
199 |
<input type="hidden" name="action" value="save" />
|
200 |
<?php wp_nonce_field('user-avatar') ?>
|
201 |
<p class="submit"><input type="submit" value="<?php esc_attr_e('Upload'); ?>" /></p>
|
@@ -215,10 +243,10 @@ function user_avatar_add_photo_step1($uid)
|
|
215 |
*/
|
216 |
function user_avatar_add_photo_step2($uid)
|
217 |
{
|
218 |
-
|
219 |
|
220 |
if (!(($_FILES["uploadedfile"]["type"] == "image/gif") || ($_FILES["uploadedfile"]["type"] == "image/jpeg") || ($_FILES["uploadedfile"]["type"] == "image/png") || ($_FILES["uploadedfile"]["type"] == "image/pjpeg") || ($_FILES["uploadedfile"]["type"] == "image/x-png"))){
|
221 |
-
echo "<div class='error'><p>Please upload an image file (.jpeg, .gif, .png)
|
222 |
user_avatar_add_photo_step1($uid);
|
223 |
die();
|
224 |
}
|
@@ -234,6 +262,7 @@ function user_avatar_add_photo_step2($uid)
|
|
234 |
$file = $file['file'];
|
235 |
$filename = basename($file);
|
236 |
|
|
|
237 |
// Construct the object array
|
238 |
$object = array(
|
239 |
'post_title' => $filename,
|
@@ -244,9 +273,9 @@ function user_avatar_add_photo_step2($uid)
|
|
244 |
// Save the data
|
245 |
list($width, $height, $type, $attr) = getimagesize( $file );
|
246 |
|
247 |
-
if ( $width >
|
248 |
-
$oitar = $width /
|
249 |
-
$image = wp_crop_image($file, 0, 0, $width, $height,
|
250 |
|
251 |
|
252 |
$url = str_replace(basename($url), basename($image), $url);
|
@@ -255,32 +284,30 @@ function user_avatar_add_photo_step2($uid)
|
|
255 |
} else {
|
256 |
$oitar = 1;
|
257 |
}
|
258 |
-
|
259 |
-
|
260 |
?>
|
261 |
-
<form id="iframe-crop-form" method="POST" action="<?php echo admin_url('admin-ajax.php'); ?>?action=user_avatar_add_photo&step=3&uid=<?php echo $uid; ?>">
|
262 |
|
263 |
-
<h4><?php _e('Choose the part of the image you want to use as your profile image.');
|
264 |
|
265 |
<div id="testWrap">
|
266 |
-
<img src="<?php echo $url; ?>" id="upload" width="<?php echo $width; ?>" height="<?php echo $height; ?>" />
|
267 |
</div>
|
268 |
<div id="user-avatar-preview">
|
269 |
<h4>Preview</h4>
|
270 |
<div id="preview" style="width: <?php echo USER_AVATAR_FULL_WIDTH; ?>px; height: <?php echo USER_AVATAR_FULL_HEIGHT; ?>px; overflow: hidden;">
|
271 |
-
<img src="<?php echo $url; ?>" width="<?php echo $width; ?>" height="<?php echo $height; ?>">
|
272 |
</div>
|
273 |
<p class="submit" >
|
274 |
<input type="hidden" name="x1" id="x1" value="0" />
|
275 |
<input type="hidden" name="y1" id="y1" value="0" />
|
276 |
<input type="hidden" name="x2" id="x2" />
|
277 |
<input type="hidden" name="y2" id="y2" />
|
278 |
-
<input type="hidden" name="width" id="width" value="<?php echo $width ?>" />
|
279 |
-
<input type="hidden" name="height" id="height" value="<?php echo $height ?>" />
|
280 |
-
|
281 |
<input type="hidden" name="oitar" id="oitar" value="<?php echo esc_attr($oitar); ?>" />
|
282 |
-
<?php wp_nonce_field('user-avatar') ?>
|
283 |
-
|
284 |
</div>
|
285 |
</form>
|
286 |
|
@@ -362,7 +389,7 @@ function user_avatar_add_photo_step2($uid)
|
|
362 |
*/
|
363 |
function user_avatar_add_photo_step3($uid)
|
364 |
{
|
365 |
-
|
366 |
|
367 |
if ( $_POST['oitar'] > 1 ) {
|
368 |
$_POST['x1'] = $_POST['x1'] * $_POST['oitar'];
|
@@ -370,13 +397,13 @@ function user_avatar_add_photo_step3($uid)
|
|
370 |
$_POST['width'] = $_POST['width'] * $_POST['oitar'];
|
371 |
$_POST['height'] = $_POST['height'] * $_POST['oitar'];
|
372 |
}
|
373 |
-
|
374 |
-
|
375 |
-
|
|
|
|
|
376 |
return true;
|
377 |
}
|
378 |
-
|
379 |
-
$original_file = $_POST['attachment_file'];
|
380 |
|
381 |
$cropped_full = USER_AVATAR_UPLOAD_PATH."{$uid}/".time()."-bpfull.jpg";
|
382 |
$cropped_thumb = USER_AVATAR_UPLOAD_PATH."{$uid}/".time()."-bpthumb.jpg";
|
@@ -398,18 +425,18 @@ function user_avatar_add_photo_step3($uid)
|
|
398 |
if ( is_wp_error( $cropped_full ) )
|
399 |
wp_die( __( 'Image could not be processed. Please go back and try again.' ), __( 'Image Processing Error' ) );
|
400 |
?>
|
401 |
-
|
402 |
<script type="text/javascript">
|
403 |
-
self.parent.user_avatar_refresh_image('<?php echo
|
|
|
404 |
</script>
|
405 |
<div id="user-avatar-step3">
|
406 |
-
<h3
|
407 |
<span style="float:left;">
|
408 |
<?php
|
409 |
-
echo
|
410 |
?>
|
411 |
</span>
|
412 |
-
<a id="user-avatar-step3-close" class="button" onclick="self.parent.tb_remove();"
|
413 |
</div>
|
414 |
<?php
|
415 |
}
|
@@ -426,13 +453,12 @@ function user_avatar_delete_files($uid)
|
|
426 |
if ( !file_exists( $avatar_folder_dir ) )
|
427 |
return false;
|
428 |
|
429 |
-
if ( $av_dir = opendir( $avatar_folder_dir ) ) {
|
430 |
while ( false !== ( $avatar_file = readdir($av_dir) ) ) {
|
431 |
-
if ( ( preg_match( "/-bpfull/", $avatar_file ) || preg_match( "/-bpthumb/", $avatar_file ) ) && '.' != $avatar_file && '..' != $avatar_file )
|
432 |
@unlink( $avatar_folder_dir . '/' . $avatar_file );
|
433 |
}
|
|
|
434 |
}
|
435 |
-
closedir($av_dir);
|
436 |
|
437 |
@rmdir( $avatar_folder_dir );
|
438 |
|
@@ -475,18 +501,20 @@ function user_avatar_fetch_avatar_filter( $avatar, $user, $size, $default, $alt
|
|
475 |
// If somehow $id hasn't been assigned, return the result of get_avatar
|
476 |
if ( empty( $id ) )
|
477 |
return !empty( $avatar ) ? $avatar : $default;
|
478 |
-
|
479 |
-
//
|
480 |
-
|
481 |
-
|
482 |
-
|
483 |
-
|
484 |
-
|
485 |
-
|
486 |
-
|
487 |
-
else
|
488 |
-
return $avatar;
|
489 |
-
|
|
|
|
|
490 |
}
|
491 |
|
492 |
add_filter( 'get_avatar', 'user_avatar_fetch_avatar_filter', 10, 5 );
|
@@ -503,17 +531,17 @@ add_filter( 'get_avatar', 'user_avatar_fetch_avatar_filter', 10, 5 );
|
|
503 |
* @return string Formatted HTML <img> element, or raw avatar URL based on $html arg
|
504 |
*/
|
505 |
function user_avatar_fetch_avatar( $args = '' ) {
|
506 |
-
|
507 |
$defaults = array(
|
508 |
'item_id' => false,
|
509 |
-
'object' =>
|
510 |
-
'type' =>
|
511 |
'avatar_dir' => false, // Specify a custom avatar directory for your object
|
512 |
'width' => false, // Custom width (int)
|
513 |
'height' => false, // Custom height (int)
|
514 |
-
'class' =>
|
515 |
'css_id' => false, // Custom <img> ID (string)
|
516 |
-
'alt' =>
|
517 |
'email' => false, // Pass the user email (for gravatar) to prevent querying the DB for it
|
518 |
'no_grav' => false, // If there is no avatar found, return false instead of a grav?
|
519 |
'html' => true // Wrap the return img URL in <img />
|
@@ -525,9 +553,19 @@ function user_avatar_fetch_avatar( $args = '' ) {
|
|
525 |
|
526 |
$avatar_folder_dir = USER_AVATAR_UPLOAD_PATH."{$item_id}/";
|
527 |
$avatar_folder_url = USER_AVATAR_URL."{$item_id}";
|
|
|
528 |
if($width > 50)
|
529 |
-
|
|
|
530 |
$avatar_size = ( 'full' == $type ) ? '-bpfull' : '-bpthumb';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
531 |
|
532 |
|
533 |
// Add an identifying class to each item
|
@@ -535,116 +573,70 @@ function user_avatar_fetch_avatar( $args = '' ) {
|
|
535 |
|
536 |
// Set CSS ID if passed
|
537 |
if ( !empty( $css_id ) )
|
538 |
-
$css_id = " id=\"
|
539 |
|
540 |
// Set avatar width
|
541 |
if ( $width )
|
542 |
-
$html_width = " width=\"
|
543 |
else
|
544 |
-
$html_width = ( 'thumb' == $type ) ? ' width="' . USER_AVATAR_THUMB_WIDTH . '"' : ' width="' . USER_AVATAR_FULL_WIDTH . '"';
|
545 |
|
546 |
// Set avatar height
|
547 |
if ( $height )
|
548 |
-
$html_height = " height=\"
|
549 |
else
|
550 |
-
$html_height = ( 'thumb' == $type ) ? ' height="' . USER_AVATAR_THUMB_HEIGHT . '"' : ' height="' . USER_AVATAR_FULL_HEIGHT . '"';
|
551 |
|
|
|
552 |
|
553 |
-
|
554 |
-
if ( file_exists( $avatar_folder_dir ) ) {
|
555 |
|
556 |
-
|
557 |
-
if
|
558 |
-
|
559 |
-
// Stash files in an array once to check for one that matches
|
560 |
-
$avatar_files = array();
|
561 |
-
while ( false !== ( $avatar_file = readdir($av_dir) ) ) {
|
562 |
-
// Only add files to the array (skip directories)
|
563 |
-
if ( 2 < strlen( $avatar_file ) )
|
564 |
-
$avatar_files[] = $avatar_file;
|
565 |
-
}
|
566 |
-
|
567 |
-
// Check for array
|
568 |
-
if ( 0 < count( $avatar_files ) ) {
|
569 |
-
|
570 |
-
// Check for current avatar
|
571 |
-
if( is_array($avatar_files) ):
|
572 |
-
foreach( $avatar_files as $key => $value ) {
|
573 |
-
if ( strpos ( $value, $avatar_size )!== false )
|
574 |
-
$avatar_url = $avatar_folder_url . '/' . $avatar_files[$key];
|
575 |
-
}
|
576 |
-
endif;
|
577 |
-
|
578 |
-
}
|
579 |
-
}
|
580 |
-
|
581 |
-
// Close the avatar directory
|
582 |
-
closedir( $av_dir );
|
583 |
|
584 |
-
|
585 |
-
|
586 |
-
|
587 |
-
|
588 |
-
|
589 |
-
|
590 |
-
|
591 |
-
|
592 |
-
|
593 |
-
|
594 |
-
}
|
595 |
-
|
596 |
-
|
597 |
-
// Skips gravatar check if $no_grav is passed
|
598 |
-
if ( !$no_grav ) {
|
599 |
-
|
600 |
-
// Set gravatar size
|
601 |
-
if ( $width )
|
602 |
-
$grav_size = $width;
|
603 |
-
else if ( 'full' == $type )
|
604 |
-
$grav_size = USER_AVATAR_FULL_WIDTH;
|
605 |
-
else if ( 'thumb' == $type )
|
606 |
-
$grav_size = USER_AVATAR_THUMB_WIDTH;
|
607 |
-
|
608 |
-
// Set gravatar type
|
609 |
-
if ( empty( $bp->grav_default->{$object} ) )
|
610 |
-
$default_grav = 'wavatar';
|
611 |
-
else if ( 'mystery' == $bp->grav_default->{$object} )
|
612 |
-
$default_grav = apply_filters( 'bp_core_mysteryman_src', BP_AVATAR_DEFAULT, $grav_size );
|
613 |
-
else
|
614 |
-
$default_grav = $bp->grav_default->{$object};
|
615 |
-
|
616 |
-
// Set gravatar object
|
617 |
-
if ( empty( $email ) ) {
|
618 |
-
if ( 'user' == $object ) {
|
619 |
-
$email = bp_core_get_user_email( $item_id );
|
620 |
-
} else if ( 'group' == $object || 'blog' == $object ) {
|
621 |
-
$email = "{$item_id}-{$object}@{$bp->root_domain}";
|
622 |
-
}
|
623 |
}
|
624 |
-
|
625 |
-
|
626 |
-
|
627 |
-
|
628 |
-
|
629 |
-
|
630 |
-
|
631 |
-
|
632 |
-
|
633 |
-
|
634 |
-
|
635 |
-
|
636 |
-
|
637 |
-
|
638 |
-
|
639 |
-
|
640 |
-
|
641 |
-
|
642 |
-
|
643 |
-
|
644 |
-
|
645 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
646 |
}
|
647 |
-
|
648 |
/**
|
649 |
* user_avatar_form function.
|
650 |
* Description: Creation and calling of appropriate functions on the overlay form.
|
@@ -660,51 +652,113 @@ function user_avatar_form($profile)
|
|
660 |
if(($profile->ID == $current_user->ID || is_super_admin($current_user->ID)))
|
661 |
{
|
662 |
$avatar_folder_dir = USER_AVATAR_UPLOAD_PATH."{$profile->ID}/";
|
663 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
664 |
// Remove the User-Avatar button if there is no uploaded image
|
665 |
-
if ( !file_exists( $avatar_folder_dir ) ){
|
666 |
-
?> <style type="text/css">#user-avatar-remove{display:none;}</style>
|
667 |
-
<?php
|
668 |
-
}
|
669 |
|
670 |
-
|
671 |
-
|
672 |
-
|
673 |
-
$
|
674 |
-
|
675 |
-
|
676 |
-
|
677 |
-
|
678 |
-
|
679 |
-
|
680 |
-
else{
|
681 |
-
if ( $av_dir = opendir( $avatar_folder_dir ) ) {
|
682 |
-
while ( false !== ( $avatar_file = readdir($av_dir) ) ) {
|
683 |
-
if ( ( preg_match( "/-bpfull/", $avatar_file ) || preg_match( "/-bpthumb/", $avatar_file ) ) && '.' != $avatar_file && '..' != $avatar_file )
|
684 |
-
@unlink( $avatar_folder_dir . '/' . $avatar_file );
|
685 |
-
}
|
686 |
-
}
|
687 |
-
closedir($av_dir);
|
688 |
-
|
689 |
-
@rmdir( $avatar_folder_dir );
|
690 |
-
}
|
691 |
-
}
|
692 |
-
|
693 |
?>
|
694 |
-
<div id="user-avatar-display" >
|
695 |
-
<h3>Picture</h3>
|
696 |
-
<p id="user-avatar-display-image"><?php echo get_avatar($profile->ID, 150); ?></p>
|
697 |
-
<a id="user-avatar-link" class="button thickbox" href="<?php echo admin_url('admin-ajax.php'); ?>?action=user_avatar_add_photo&step=1&uid=<?php echo $profile->ID; ?>&TB_iframe=true&width=720&height=450" title="Upload and Crop an Image to be Displayed" >Change Picture</a>
|
698 |
-
<a id="user-avatar-remove" class="button" href="?delete_avatar=true" title="Remove User Avatar Image" >Remove User Avatar</a>
|
699 |
</div>
|
700 |
-
<script>
|
701 |
function user_avatar_refresh_image(img){
|
702 |
jQuery('#user-avatar-display-image').html(img);
|
703 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
704 |
</script>
|
705 |
<?php
|
706 |
}
|
707 |
}
|
708 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
709 |
/* --- END OF FILE --- */
|
710 |
-
|
3 |
Plugin Name: User Avatar
|
4 |
Plugin URI: http://wordpress.org/extend/plugins/user-avatar/
|
5 |
Description: Allows users to associate photos with their accounts by accessing their "Your Profile" page that default as Gravatar or WordPress Default image (from Discussion Page).
|
6 |
+
Version: 1.4.8
|
7 |
Author: Enej Bajgoric / Gagan Sandhu / CTLT DEV
|
8 |
|
9 |
|
30 |
add_action('user_avatar_iframe_head','user_avatar_init');
|
31 |
|
32 |
|
33 |
+
add_action('admin_print_styles-user-edit.php', 'user_avatar_admin_print_styles');
|
34 |
+
add_action('admin_print_styles-profile.php', 'user_avatar_admin_print_styles');
|
35 |
+
function user_avatar_admin_print_styles() {
|
36 |
+
global $hook_suffix;
|
37 |
wp_enqueue_script("thickbox");
|
38 |
wp_enqueue_style("thickbox");
|
39 |
+
wp_enqueue_style('user-avatar', plugins_url('/user-avatar/css/user-avatar.css'), 'css');
|
40 |
}
|
41 |
|
42 |
+
|
43 |
/**
|
44 |
* user_avatar_init function.
|
45 |
* Description: Initializing user avatar style.
|
47 |
* @return void
|
48 |
*/
|
49 |
function user_avatar_init(){
|
50 |
+
|
51 |
+
wp_enqueue_style( 'global' );
|
52 |
+
wp_enqueue_style( 'wp-admin' );
|
53 |
+
wp_enqueue_style( 'colors' );
|
54 |
+
wp_enqueue_style( 'ie' );
|
55 |
wp_enqueue_style('user-avatar', plugins_url('/user-avatar/css/user-avatar.css'), 'css');
|
56 |
+
wp_enqueue_style('imgareaselect');
|
57 |
+
wp_enqueue_script('imgareaselect');
|
58 |
+
do_action('admin_print_styles');
|
59 |
+
do_action('admin_print_scripts');
|
60 |
+
do_action('admin_head');
|
61 |
|
62 |
+
}
|
63 |
/**
|
64 |
* user_avatar_core_set_avatar_constants function.
|
65 |
* Description: Establishing restraints on sizes of files and dimensions of images.
|
68 |
* @return void
|
69 |
*/
|
70 |
function user_avatar_core_set_avatar_constants() {
|
71 |
+
|
72 |
global $bp;
|
73 |
|
74 |
if ( !defined( 'USER_AVATAR_UPLOAD_PATH' ) )
|
101 |
|
102 |
if ( !defined( 'USER_AVATAR_DEFAULT_THUMB' ) )
|
103 |
define( 'USER_AVATAR_DEFAULT_THUMB', plugins_url('/user-avatar/images/mystery-man-50.jpg') );
|
104 |
+
|
105 |
+
|
106 |
+
// set the language
|
107 |
+
load_plugin_textdomain( 'user-avatar', false , basename( dirname( __FILE__ ) ) . '/languages' );
|
108 |
}
|
109 |
|
110 |
/**
|
142 |
function user_avatar_add_photo() {
|
143 |
global $current_user;
|
144 |
|
145 |
+
if(($_GET['uid'] == $current_user->ID || current_user_can('edit_users')) && is_numeric($_GET['uid']))
|
|
|
146 |
{
|
147 |
$uid = $_GET['uid'];
|
|
|
148 |
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
149 |
<html xmlns="http://www.w3.org/1999/xhtml" <?php do_action('admin_xml_ns'); ?> <?php language_attributes(); ?>>
|
150 |
<head>
|
151 |
<meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php echo get_option('blog_charset'); ?>" />
|
152 |
<title><?php bloginfo('name') ?> › <?php _e('Uploads'); ?> — <?php _e('WordPress'); ?></title>
|
153 |
+
<script type="text/javascript">
|
154 |
+
//<![CDATA[
|
155 |
+
addLoadEvent = function(func){if(typeof jQuery!="undefined")jQuery(document).ready(func);else if(typeof wpOnload!='function'){wpOnload=func;}else{var oldonload=wpOnload;wpOnload=function(){oldonload();func();}}};
|
156 |
+
var userSettings = {
|
157 |
+
'url': '<?php echo SITECOOKIEPATH; ?>',
|
158 |
+
'uid': '<?php if ( ! isset($current_user) ) $current_user = wp_get_current_user(); echo $current_user->ID; ?>',
|
159 |
+
'time':'<?php echo time() ?>'
|
160 |
+
},
|
161 |
+
ajaxurl = '<?php echo admin_url('admin-ajax.php'); ?>',
|
162 |
+
pagenow = '<?php echo $current_screen->id; ?>',
|
163 |
+
typenow = '<?php if ( isset($current_screen->post_type) ) echo $current_screen->post_type; ?>',
|
164 |
+
adminpage = '<?php echo $admin_body_class; ?>',
|
165 |
+
thousandsSeparator = '<?php echo addslashes( $wp_locale->number_format['thousands_sep'] ); ?>',
|
166 |
+
decimalPoint = '<?php echo addslashes( $wp_locale->number_format['decimal_point'] ); ?>',
|
167 |
+
isRtl = <?php echo (int) is_rtl(); ?>;
|
168 |
+
//]]>
|
169 |
+
</script>
|
170 |
<?php
|
171 |
|
|
|
|
|
|
|
|
|
172 |
|
|
|
|
|
173 |
do_action('user_avatar_iframe_head');
|
174 |
+
|
175 |
+
|
|
|
176 |
?>
|
177 |
+
|
178 |
</head>
|
179 |
<body>
|
180 |
<?php
|
200 |
</html>
|
201 |
<?php
|
202 |
}else {
|
203 |
+
wp_die(__("You are not allowed to do that.",'user-avatar'));
|
204 |
}
|
205 |
die();
|
206 |
}
|
218 |
?>
|
219 |
<p id="step1-image" >
|
220 |
<?php
|
221 |
+
echo user_avatar_get_avatar( $uid , 150);
|
222 |
?>
|
223 |
</p>
|
224 |
<div id="user-avatar-step1">
|
225 |
<form enctype="multipart/form-data" id="uploadForm" method="POST" action="<?php echo admin_url('admin-ajax.php'); ?>?action=user_avatar_add_photo&step=2&uid=<?php echo $uid; ?>" >
|
226 |
+
<label for="upload"><?php _e('Choose an image from your computer:','user-avatar'); ?></label><br /><input type="file" id="upload" name="uploadedfile" />
|
227 |
<input type="hidden" name="action" value="save" />
|
228 |
<?php wp_nonce_field('user-avatar') ?>
|
229 |
<p class="submit"><input type="submit" value="<?php esc_attr_e('Upload'); ?>" /></p>
|
243 |
*/
|
244 |
function user_avatar_add_photo_step2($uid)
|
245 |
{
|
246 |
+
|
247 |
|
248 |
if (!(($_FILES["uploadedfile"]["type"] == "image/gif") || ($_FILES["uploadedfile"]["type"] == "image/jpeg") || ($_FILES["uploadedfile"]["type"] == "image/png") || ($_FILES["uploadedfile"]["type"] == "image/pjpeg") || ($_FILES["uploadedfile"]["type"] == "image/x-png"))){
|
249 |
+
echo "<div class='error'><p>".__("Please upload an image file (.jpeg, .gif, .png).",'user-avatar')."</p></div>";
|
250 |
user_avatar_add_photo_step1($uid);
|
251 |
die();
|
252 |
}
|
262 |
$file = $file['file'];
|
263 |
$filename = basename($file);
|
264 |
|
265 |
+
set_transient( 'avatar_file_'.$uid, $file, 60 * 60 * 5 );
|
266 |
// Construct the object array
|
267 |
$object = array(
|
268 |
'post_title' => $filename,
|
273 |
// Save the data
|
274 |
list($width, $height, $type, $attr) = getimagesize( $file );
|
275 |
|
276 |
+
if ( $width > 420 ) {
|
277 |
+
$oitar = $width / 420;
|
278 |
+
$image = wp_crop_image($file, 0, 0, $width, $height, 420, $height / $oitar, false, str_replace(basename($file), 'midsize-'.basename($file), $file));
|
279 |
|
280 |
|
281 |
$url = str_replace(basename($url), basename($image), $url);
|
284 |
} else {
|
285 |
$oitar = 1;
|
286 |
}
|
|
|
|
|
287 |
?>
|
288 |
+
<form id="iframe-crop-form" method="POST" action="<?php echo admin_url('admin-ajax.php'); ?>?action=user_avatar_add_photo&step=3&uid=<?php echo esc_attr($uid); ?>">
|
289 |
|
290 |
+
<h4><?php _e('Choose the part of the image you want to use as your profile image.','user-avatar'); ?> <input type="submit" class="button" id="user-avatar-crop-button" value="<?php esc_attr_e('Crop Image','user-avatar'); ?>" /></h4>
|
291 |
|
292 |
<div id="testWrap">
|
293 |
+
<img src="<?php echo $url; ?>" id="upload" width="<?php echo esc_attr($width); ?>" height="<?php echo esc_attr($height); ?>" />
|
294 |
</div>
|
295 |
<div id="user-avatar-preview">
|
296 |
<h4>Preview</h4>
|
297 |
<div id="preview" style="width: <?php echo USER_AVATAR_FULL_WIDTH; ?>px; height: <?php echo USER_AVATAR_FULL_HEIGHT; ?>px; overflow: hidden;">
|
298 |
+
<img src="<?php echo esc_url_raw($url); ?>" width="<?php echo esc_attr($width); ?>" height="<?php echo $height; ?>">
|
299 |
</div>
|
300 |
<p class="submit" >
|
301 |
<input type="hidden" name="x1" id="x1" value="0" />
|
302 |
<input type="hidden" name="y1" id="y1" value="0" />
|
303 |
<input type="hidden" name="x2" id="x2" />
|
304 |
<input type="hidden" name="y2" id="y2" />
|
305 |
+
<input type="hidden" name="width" id="width" value="<?php echo esc_attr($width) ?>" />
|
306 |
+
<input type="hidden" name="height" id="height" value="<?php echo esc_attr($height) ?>" />
|
307 |
+
|
308 |
<input type="hidden" name="oitar" id="oitar" value="<?php echo esc_attr($oitar); ?>" />
|
309 |
+
<?php wp_nonce_field('user-avatar'); ?>
|
310 |
+
</p>
|
311 |
</div>
|
312 |
</form>
|
313 |
|
389 |
*/
|
390 |
function user_avatar_add_photo_step3($uid)
|
391 |
{
|
392 |
+
|
393 |
|
394 |
if ( $_POST['oitar'] > 1 ) {
|
395 |
$_POST['x1'] = $_POST['x1'] * $_POST['oitar'];
|
397 |
$_POST['width'] = $_POST['width'] * $_POST['oitar'];
|
398 |
$_POST['height'] = $_POST['height'] * $_POST['oitar'];
|
399 |
}
|
400 |
+
|
401 |
+
$original_file = get_transient( 'avatar_file_'.$uid );
|
402 |
+
delete_transient('avatar_file_'.$uid );
|
403 |
+
if( !file_exists($original_file) ) {
|
404 |
+
echo "<div class='error'><p>". __('Sorry, No file available','user-avatar')."</p></div>";
|
405 |
return true;
|
406 |
}
|
|
|
|
|
407 |
|
408 |
$cropped_full = USER_AVATAR_UPLOAD_PATH."{$uid}/".time()."-bpfull.jpg";
|
409 |
$cropped_thumb = USER_AVATAR_UPLOAD_PATH."{$uid}/".time()."-bpthumb.jpg";
|
425 |
if ( is_wp_error( $cropped_full ) )
|
426 |
wp_die( __( 'Image could not be processed. Please go back and try again.' ), __( 'Image Processing Error' ) );
|
427 |
?>
|
|
|
428 |
<script type="text/javascript">
|
429 |
+
self.parent.user_avatar_refresh_image('<?php echo user_avatar_get_avatar($uid, 150); ?>');
|
430 |
+
self.parent.add_remove_avatar_link();
|
431 |
</script>
|
432 |
<div id="user-avatar-step3">
|
433 |
+
<h3><?php _e("Here's your new profile picture...",'user-avatar'); ?></h3>
|
434 |
<span style="float:left;">
|
435 |
<?php
|
436 |
+
echo user_avatar_get_avatar( $uid, 150);
|
437 |
?>
|
438 |
</span>
|
439 |
+
<a id="user-avatar-step3-close" class="button" onclick="self.parent.tb_remove();" ><?php _e('Close','user-avatar'); ?></a>
|
440 |
</div>
|
441 |
<?php
|
442 |
}
|
453 |
if ( !file_exists( $avatar_folder_dir ) )
|
454 |
return false;
|
455 |
|
456 |
+
if ( is_dir( $avatar_folder_dir ) && $av_dir = opendir( $avatar_folder_dir ) ) {
|
457 |
while ( false !== ( $avatar_file = readdir($av_dir) ) ) {
|
|
|
458 |
@unlink( $avatar_folder_dir . '/' . $avatar_file );
|
459 |
}
|
460 |
+
closedir($av_dir);
|
461 |
}
|
|
|
462 |
|
463 |
@rmdir( $avatar_folder_dir );
|
464 |
|
501 |
// If somehow $id hasn't been assigned, return the result of get_avatar
|
502 |
if ( empty( $id ) )
|
503 |
return !empty( $avatar ) ? $avatar : $default;
|
504 |
+
|
505 |
+
// check yo see if there is a file that was uploaded by the user
|
506 |
+
if( user_avatar_avatar_exists($id) ):
|
507 |
+
|
508 |
+
$user_avatar = user_avatar_fetch_avatar( array( 'item_id' => $id, 'width' => $size, 'height' => $size, 'alt' => $alt ) );
|
509 |
+
if($user_avatar)
|
510 |
+
return $user_avatar;
|
511 |
+
else
|
512 |
+
return !empty( $avatar ) ? $avatar : $default;
|
513 |
+
else:
|
514 |
+
return !empty( $avatar ) ? $avatar : $default;
|
515 |
+
endif;
|
516 |
+
// for good measure
|
517 |
+
return !empty( $avatar ) ? $avatar : $default;
|
518 |
}
|
519 |
|
520 |
add_filter( 'get_avatar', 'user_avatar_fetch_avatar_filter', 10, 5 );
|
531 |
* @return string Formatted HTML <img> element, or raw avatar URL based on $html arg
|
532 |
*/
|
533 |
function user_avatar_fetch_avatar( $args = '' ) {
|
534 |
+
|
535 |
$defaults = array(
|
536 |
'item_id' => false,
|
537 |
+
'object' => "user", // user/group/blog/custom type (if you use filters)
|
538 |
+
'type' => 'full', // thumb or full
|
539 |
'avatar_dir' => false, // Specify a custom avatar directory for your object
|
540 |
'width' => false, // Custom width (int)
|
541 |
'height' => false, // Custom height (int)
|
542 |
+
'class' => '', // Custom <img> class (string)
|
543 |
'css_id' => false, // Custom <img> ID (string)
|
544 |
+
'alt' => '', // Custom <img> alt (string)
|
545 |
'email' => false, // Pass the user email (for gravatar) to prevent querying the DB for it
|
546 |
'no_grav' => false, // If there is no avatar found, return false instead of a grav?
|
547 |
'html' => true // Wrap the return img URL in <img />
|
553 |
|
554 |
$avatar_folder_dir = USER_AVATAR_UPLOAD_PATH."{$item_id}/";
|
555 |
$avatar_folder_url = USER_AVATAR_URL."{$item_id}";
|
556 |
+
|
557 |
if($width > 50)
|
558 |
+
$type = "full";
|
559 |
+
|
560 |
$avatar_size = ( 'full' == $type ) ? '-bpfull' : '-bpthumb';
|
561 |
+
$class .= " avatar ";
|
562 |
+
$class .= " avatar-". $width ." ";
|
563 |
+
$class .= " photo";
|
564 |
+
|
565 |
+
if ( false === $alt)
|
566 |
+
$safe_alt = '';
|
567 |
+
else
|
568 |
+
$safe_alt = esc_attr( $alt );
|
569 |
|
570 |
|
571 |
// Add an identifying class to each item
|
573 |
|
574 |
// Set CSS ID if passed
|
575 |
if ( !empty( $css_id ) )
|
576 |
+
$css_id = " id=\"".esc_attr($css_id)."\"";
|
577 |
|
578 |
// Set avatar width
|
579 |
if ( $width )
|
580 |
+
$html_width = " width=\"".esc_attr($width)."\"";
|
581 |
else
|
582 |
+
$html_width = ( 'thumb' == $type ) ? ' width="' . esc_attr(USER_AVATAR_THUMB_WIDTH) . '"' : ' width="' . esc_attr(USER_AVATAR_FULL_WIDTH) . '"';
|
583 |
|
584 |
// Set avatar height
|
585 |
if ( $height )
|
586 |
+
$html_height = " height=\"".esc_attr($height)."\"";
|
587 |
else
|
588 |
+
$html_height = ( 'thumb' == $type ) ? ' height="' . esc_attr(USER_AVATAR_THUMB_HEIGHT) . '"' : ' height="' . esc_attr(USER_AVATAR_FULL_HEIGHT) . '"';
|
589 |
|
590 |
+
|
591 |
|
592 |
+
if( $avatar_img = user_avatar_avatar_exists( $item_id ) ):
|
|
|
593 |
|
594 |
+
$avatar_src = get_site_url()."/wp-content/uploads/avatars/".$item_id."/".$avatar_img;
|
595 |
+
if(function_exists('is_subdomain_install') && !is_subdomain_install())
|
596 |
+
$avatar_src = "/wp-content/uploads/avatars/".$item_id."/".$avatar_img;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
597 |
|
598 |
+
$avatar_folder_dir = USER_AVATAR_UPLOAD_PATH."{$item_id}/";
|
599 |
+
|
600 |
+
$file_time = filemtime ($avatar_folder_dir."/".$avatar_img);
|
601 |
+
|
602 |
+
$avatar_url = plugins_url('/user-avatar/user-avatar-pic.php')."?src=".$avatar_src ."&w=".$width."&id=".$item_id."&random=".$file_time;
|
603 |
+
|
604 |
+
// Return it wrapped in an <img> element
|
605 |
+
if ( true === $html ) { // this helps validate stuff
|
606 |
+
return '<img src="' . esc_url($avatar_url) . '" alt="' . esc_attr($alt) . '" class="' . esc_attr($class) . '"' . $css_id . $html_width . $html_height . ' />';
|
607 |
+
// ...or only the URL
|
608 |
+
} else {
|
609 |
+
return $avatar_url ;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
610 |
}
|
611 |
+
else:
|
612 |
+
return false;
|
613 |
+
endif;
|
614 |
+
}
|
615 |
+
add_action("admin_init", "user_avatar_delete");
|
616 |
+
/**
|
617 |
+
* user_avatar_delete function.
|
618 |
+
*
|
619 |
+
* @access public
|
620 |
+
* @return void
|
621 |
+
*/
|
622 |
+
function user_avatar_delete(){
|
623 |
+
|
624 |
+
global $pagenow;
|
625 |
+
|
626 |
+
$current_user = wp_get_current_user();
|
627 |
+
|
628 |
+
// If user clicks the remove avatar button, in URL deleter_avatar=true
|
629 |
+
if( isset($_GET['delete_avatar']) && wp_verify_nonce($_GET['_nononce'], 'user_avatar') && ( $_GET['u'] == $current_user->id || current_user_can('edit_users')) )
|
630 |
+
{
|
631 |
+
$user_id = $_GET['user_id'];
|
632 |
+
if(is_numeric($user_id))
|
633 |
+
$user_id = "?user_id=".$user_id;
|
634 |
+
|
635 |
+
user_avatar_delete_files($_GET['u']);
|
636 |
+
wp_redirect(get_option('siteurl') . '/wp-admin/'.$pagenow.$user_id);
|
637 |
+
|
638 |
+
}
|
639 |
}
|
|
|
640 |
/**
|
641 |
* user_avatar_form function.
|
642 |
* Description: Creation and calling of appropriate functions on the overlay form.
|
652 |
if(($profile->ID == $current_user->ID || is_super_admin($current_user->ID)))
|
653 |
{
|
654 |
$avatar_folder_dir = USER_AVATAR_UPLOAD_PATH."{$profile->ID}/";
|
655 |
+
?>
|
656 |
+
<div id="user-avatar-display" class="submitbox" >
|
657 |
+
<h3 ><?php _e('Picture','user-avatar'); ?></h3>
|
658 |
+
<p id="user-avatar-display-image"><?php echo user_avatar_get_avatar($profile->ID, 150); ?></p>
|
659 |
+
<a id="user-avatar-link" class="button-primary thickbox" href="<?php echo admin_url('admin-ajax.php'); ?>?action=user_avatar_add_photo&step=1&uid=<?php echo $profile->ID; ?>&TB_iframe=true&width=720&height=450" title="<?php _e('Upload and Crop an Image to be Displayed','user-avatar'); ?>" ><?php _e('Update Picture','user-avatar'); ?></a>
|
660 |
+
|
661 |
+
<?php
|
662 |
// Remove the User-Avatar button if there is no uploaded image
|
|
|
|
|
|
|
|
|
663 |
|
664 |
+
if(isset($_GET['user_id'])):
|
665 |
+
$remove_url = admin_url('user-edit.php')."?user_id=".$_GET['user_id']."&delete_avatar=true&_nononce=". wp_create_nonce('user_avatar')."&u=".$profile->ID;
|
666 |
+
else:
|
667 |
+
$remove_url = admin_url('profile.php')."?delete_avatar=true&_nononce=". wp_create_nonce('user_avatar')."&u=".$profile->ID;
|
668 |
+
|
669 |
+
endif;
|
670 |
+
if ( user_avatar_avatar_exists($profile->ID) ):?>
|
671 |
+
<a id="user-avatar-remove" class="submitdelete deleteaction" href="<?php echo esc_url_raw($remove_url); ?>" title="<?php _e('Remove User Avatar Image','user-avatar'); ?>" ><?php _e('Remove','user-avatar'); ?></a>
|
672 |
+
<?php
|
673 |
+
endif;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
674 |
?>
|
|
|
|
|
|
|
|
|
|
|
675 |
</div>
|
676 |
+
<script type="text/javascript">
|
677 |
function user_avatar_refresh_image(img){
|
678 |
jQuery('#user-avatar-display-image').html(img);
|
679 |
}
|
680 |
+
function add_remove_avatar_link(){
|
681 |
+
if(!jQuery("#user-avatar-remove").is('a')){
|
682 |
+
jQuery('#user-avatar-link').after(" <a href='<?php echo $remove_url; ?>' class='submitdelete' id='user-avatar-remove' ><?php _e('Remove','user-avatar'); ?></a>")
|
683 |
+
}
|
684 |
+
|
685 |
+
|
686 |
+
}
|
687 |
+
|
688 |
</script>
|
689 |
<?php
|
690 |
}
|
691 |
}
|
692 |
|
693 |
+
/*-- HELPER FUNCTIONS --*/
|
694 |
+
/**
|
695 |
+
* user_avatar_avatar_exists function.
|
696 |
+
*
|
697 |
+
* @access public
|
698 |
+
* @param mixed $id
|
699 |
+
* @return void
|
700 |
+
*/
|
701 |
+
function user_avatar_avatar_exists($id){
|
702 |
+
|
703 |
+
$avatar_folder_dir = USER_AVATAR_UPLOAD_PATH."{$id}/";
|
704 |
+
$return = false;
|
705 |
+
|
706 |
+
if ( is_dir( $avatar_folder_dir ) && $av_dir = opendir( $avatar_folder_dir ) ) {
|
707 |
+
|
708 |
+
// Stash files in an array once to check for one that matches
|
709 |
+
$avatar_files = array();
|
710 |
+
while ( false !== ( $avatar_file = readdir($av_dir) ) ) {
|
711 |
+
// Only add files to the array (skip directories)
|
712 |
+
if ( 2 < strlen( $avatar_file ) )
|
713 |
+
$avatar_files[] = $avatar_file;
|
714 |
+
}
|
715 |
+
|
716 |
+
// Check for array
|
717 |
+
if ( 0 < count( $avatar_files ) ) {
|
718 |
+
// Check for current avatar
|
719 |
+
if( is_array($avatar_files) ):
|
720 |
+
foreach( $avatar_files as $key => $value ) {
|
721 |
+
if(strpos($value, "-bpfull")):
|
722 |
+
$return = $value;
|
723 |
+
endif;
|
724 |
+
}
|
725 |
+
endif;
|
726 |
+
|
727 |
+
}
|
728 |
+
|
729 |
+
// Close the avatar directory
|
730 |
+
closedir( $av_dir );
|
731 |
+
|
732 |
+
}
|
733 |
+
|
734 |
+
return $return;
|
735 |
+
}
|
736 |
+
/**
|
737 |
+
* user_avatar_get_avatar function.
|
738 |
+
*
|
739 |
+
* @access public
|
740 |
+
* @param mixed $id
|
741 |
+
* @param mixed $width
|
742 |
+
* @return void
|
743 |
+
*/
|
744 |
+
function user_avatar_get_avatar($id,$width) {
|
745 |
+
|
746 |
+
if(! get_option('show_avatars')):
|
747 |
+
|
748 |
+
if( user_avatar_avatar_exists($id) ):
|
749 |
+
|
750 |
+
$user_avatar = user_avatar_fetch_avatar( array( 'item_id' => $id, 'width' => $width, 'height' => $width, 'alt' => '' ) );
|
751 |
+
if($user_avatar):
|
752 |
+
return $user_avatar;
|
753 |
+
else:
|
754 |
+
return '<img src="'.USER_AVATAR_DEFAULT.'" width="'.$width.'" height="'.$width.'" class="avatar" />';
|
755 |
+
endif;
|
756 |
+
else:
|
757 |
+
return '<img src="'.USER_AVATAR_DEFAULT.'" width="'.$width.'" height="'.$width.'" class="avatar" />';
|
758 |
+
endif;
|
759 |
+
else:
|
760 |
+
return get_avatar($id,$width);
|
761 |
+
endif;
|
762 |
+
}
|
763 |
/* --- END OF FILE --- */
|
764 |
+
|