1 | <?php |
---|
2 | // +-----------------------------------------------------------------------+ |
---|
3 | // | Title plugin for piwigo | |
---|
4 | // +-----------------------------------------------------------------------+ |
---|
5 | // | Copyright(C) 2011 - 2016 ddtddt http://temmii.com/piwigo/ | |
---|
6 | // +-----------------------------------------------------------------------+ |
---|
7 | // | This program is free software; you can redistribute it and/or modify | |
---|
8 | // | it under the terms of the GNU General Public License as published by | |
---|
9 | // | the Free Software Foundation | |
---|
10 | // | | |
---|
11 | // | This program is distributed in the hope that it will be useful, but | |
---|
12 | // | WITHOUT ANY WARRANTY; without even the implied warranty of | |
---|
13 | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
---|
14 | // | General Public License for more details. | |
---|
15 | // | | |
---|
16 | // | You should have received a copy of the GNU General Public License | |
---|
17 | // | along with this program; if not, write to the Free Software | |
---|
18 | // | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
---|
19 | // | USA. | |
---|
20 | // +-----------------------------------------------------------------------+ |
---|
21 | |
---|
22 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
23 | |
---|
24 | //Add link menu |
---|
25 | add_event_handler('get_admin_plugin_menu_links', 'metaog_admin_menu'); |
---|
26 | function metaog_admin_menu($menu){ |
---|
27 | $menu[] = array( |
---|
28 | 'NAME' => l10n('Metadata Open Graph'), |
---|
29 | 'URL' => METAOG_ADMIN, |
---|
30 | ); |
---|
31 | return $menu; |
---|
32 | } |
---|
33 | |
---|
34 | //add prefiltre photo |
---|
35 | add_event_handler('loc_begin_admin', 'metaogPadminf',60); |
---|
36 | add_event_handler('loc_begin_admin_page', 'metaogPadminA',60); |
---|
37 | |
---|
38 | function metaogPadminf() |
---|
39 | { |
---|
40 | global $template; |
---|
41 | $template->set_prefilter('picture_modify', 'metaogPadminfT'); |
---|
42 | } |
---|
43 | |
---|
44 | function metaogPadminfT($content, &$smarty) |
---|
45 | { |
---|
46 | $search = '#<p style="margin:40px 0 0 0">#'; |
---|
47 | |
---|
48 | $replacement = ' |
---|
49 | <p> |
---|
50 | <strong>{\'Metadata Open Graph - Plugin meta og\'|@translate}</strong> |
---|
51 | <br> |
---|
52 | <br> |
---|
53 | <span style="margin: 0 0 0 20px">{\'Metadata Open Graph title\'|@translate}</span> |
---|
54 | <br> |
---|
55 | <input type="hidden" name="metaogidP" value="{$metaog_editP.metaogidid}"> |
---|
56 | <input type="hidden" name="metaogidobjP" value="{$metaog_editP.metaogidobj}"> |
---|
57 | <span style="margin: 0 0 0 20px"><input type="text" name="metaogtitlesaveP" value="{$metaog_editP.metaogtitle}" size="100" maxlenght="100"></span> |
---|
58 | <br> |
---|
59 | <br> |
---|
60 | <span style="margin: 0 0 0 20px">{\'Metadata Open Graph description\'|@translate}</span> |
---|
61 | <br> |
---|
62 | <span style="margin: 0 0 0 20px"><textarea rows="2" cols="60" name="metaogdescriptionsaveP" id="metaogdescriptionsaveP" class="metaogdescriptionsaveP">{$metaog_editP.metaogdescription}</textarea></span> |
---|
63 | <br> |
---|
64 | <br> |
---|
65 | <span style="margin: 0 0 0 20px">{\'Metadata Open Graph link image\'|@translate}</span> |
---|
66 | <br> |
---|
67 | <span style="margin: 0 0 0 20px"> |
---|
68 | <select name="metaogimagesaveP"> |
---|
69 | <option value="a">-----</option> |
---|
70 | <option value="b">{\'no photo\'|@translate}no photo</option> |
---|
71 | {foreach from=$info_photos item=infophoto} |
---|
72 | <option value="{$infophoto.PHOTOID}" {$infophoto.PHOTOSELECT}>{$infophoto.PHOTOINFO}</option> |
---|
73 | {/foreach} |
---|
74 | </select> |
---|
75 | </span> |
---|
76 | <br> |
---|
77 | {if empty($metaog_editP.metaogpath)}<span style="margin: 0 0 0 20px">{\'use photo for this page\'|@translate}</span>{/if} |
---|
78 | <br> |
---|
79 | <img src="{$metaog_editP.metaogpath}"><br> |
---|
80 | <br> |
---|
81 | </p> |
---|
82 | <p style="margin:40px 0 0 0">'; |
---|
83 | |
---|
84 | return preg_replace($search, $replacement, $content); |
---|
85 | } |
---|
86 | |
---|
87 | function metaogPadminA(){ |
---|
88 | if (isset($_GET['image_id'])){ |
---|
89 | global $template, $prefixeTable, $conf; |
---|
90 | $pageog=$_GET['image_id']; |
---|
91 | $metaog = pwg_db_fetch_assoc(pwg_query("SELECT * FROM " . METAOG_TABLE . " WHERE type = 2 AND idobj = '".$_GET['image_id']."';")); |
---|
92 | if(empty($metaog)){ |
---|
93 | $metaog['id']=''; |
---|
94 | $metaog['metaogtitle']=''; |
---|
95 | $metaog['metaogdescription']=''; |
---|
96 | $metaog['metaogimage']=''; |
---|
97 | } |
---|
98 | $tab_picture = pwg_query('SELECT id,name,path FROM ' . IMAGES_TABLE . ' order by id;'); |
---|
99 | if (pwg_db_num_rows($tab_picture)){ |
---|
100 | while ($info_photos = pwg_db_fetch_assoc($tab_picture)) { |
---|
101 | if($info_photos['id']==$metaog['metaogimage']){ |
---|
102 | $select="SELECTED"; |
---|
103 | $metaog['path']=$info_photos['path']; |
---|
104 | }else{ |
---|
105 | $select=""; |
---|
106 | } |
---|
107 | $items = array( |
---|
108 | 'PHOTOID' => $info_photos['id'], |
---|
109 | 'PHOTOINFO' => $info_photos['id'].' - '.$info_photos['name'], |
---|
110 | 'PHOTOSELECT' => $select, |
---|
111 | ); |
---|
112 | $template->append('info_photos', $items); |
---|
113 | } |
---|
114 | } |
---|
115 | if (empty($metaog['metaogimage'])){unset($metaog['metaogimage']);} |
---|
116 | if(isset($metaog['metaogimage'])){ |
---|
117 | if(isset($_SERVER['HTTPS'])){if($_SERVER['HTTPS'] == 'on'){$protocol="https://";}} |
---|
118 | else{$protocol="http://";} |
---|
119 | $metaogpath=PWG_DERIVATIVE_DIR.substr($metaog['path'], 2, -4)."-".$conf['mogsize'].substr($metaog['path'],-4); |
---|
120 | if (file_exists($metaogpath) AND $conf['mogsize']!='original'){ |
---|
121 | $metaogpath=$protocol.$_SERVER['SERVER_NAME']."/".substr($_SERVER['PHP_SELF'],0,11).PWG_DERIVATIVE_DIR.substr($metaog['path'], 2, -4)."-".$conf['mogsize'].substr($metaog['path'],-4); |
---|
122 | }else{ |
---|
123 | $metaogpath=$protocol.$_SERVER['SERVER_NAME']."/".substr($_SERVER['PHP_SELF'],0,11).substr($metaog['path'],2); |
---|
124 | } |
---|
125 | }else{ |
---|
126 | $metaogpath=""; |
---|
127 | $metaog['metaogimage']=""; |
---|
128 | } |
---|
129 | $template->assign( |
---|
130 | 'metaog_editP', |
---|
131 | array( |
---|
132 | 'metaogidid' => $metaog['id'], |
---|
133 | 'metaogidobj' => $pageog, |
---|
134 | 'metaogtitle' => $metaog['metaogtitle'], |
---|
135 | 'metaogdescription' => $metaog['metaogdescription'], |
---|
136 | 'metaogimage' => $metaog['metaogimage'], |
---|
137 | 'metaogpath' => $metaogpath, |
---|
138 | )); |
---|
139 | } |
---|
140 | if(isset($_POST['metaogtitlesaveP']) or isset($_POST['metaogdescriptionsaveP'])or isset($_POST['metaogimagesaveP'])){ |
---|
141 | if($_POST['metaogimagesaveP']=="a" || $_POST['metaogimagesaveP']=="b" || $_POST['metaogimagesaveP']==$_POST['metaogidobjP']){$_POST['metaogimagesaveP']='';} |
---|
142 | if(!empty($_POST['metaogidP'])){ |
---|
143 | $query = ' |
---|
144 | UPDATE ' . METAOG_TABLE . ' |
---|
145 | SET metaogtitle= \''.$_POST['metaogtitlesaveP'].'\' |
---|
146 | ,metaogdescription= \''.$_POST['metaogdescriptionsaveP'].'\' |
---|
147 | ,metaogimage= \''.$_POST['metaogimagesaveP'].'\' |
---|
148 | WHERE id = \''.$_POST['metaogidP'].'\' |
---|
149 | ;'; |
---|
150 | pwg_query($query); |
---|
151 | }else{ |
---|
152 | $q = 'INSERT INTO ' . $prefixeTable . 'metaog(type,idobj,metaogtitle,metaogdescription,metaogimage)VALUES (2,"' . $_POST['metaogidobjP'] . '","' . $_POST['metaogtitlesaveP'] . '","' . $_POST['metaogdescriptionsaveP'] . '","' . $_POST['metaogimagesaveP'] .'");'; |
---|
153 | pwg_query($q); |
---|
154 | } |
---|
155 | $metaog = pwg_db_fetch_assoc(pwg_query("SELECT * FROM " . METAOG_TABLE . " WHERE type = 2 AND idobj = '".$_POST['metaogidobjP']."';")); |
---|
156 | while ($info_photos = pwg_db_fetch_assoc($tab_picture)) { |
---|
157 | if($info_photos['id']==$metaog['metaogimage']){ |
---|
158 | $select="SELECTED"; |
---|
159 | $metaog['path']=$info_photos['path']; |
---|
160 | }else{ |
---|
161 | $select=""; |
---|
162 | } |
---|
163 | $items = array( |
---|
164 | 'PHOTOID' => $info_photos['id'], |
---|
165 | 'PHOTOINFO' => $info_photos['id'].' - '.$info_photos['name'], |
---|
166 | 'PHOTOSELECT' => $select, |
---|
167 | ); |
---|
168 | $template->append('info_photos', $items); |
---|
169 | } |
---|
170 | if (empty($metaog['metaogimage'])){unset($metaog['metaogimage']);} |
---|
171 | if(isset($metaog['metaogimage'])){ |
---|
172 | $picturepth = pwg_db_fetch_assoc(pwg_query('SELECT path FROM ' . IMAGES_TABLE . " WHERE id = '".$_POST['metaogidobjP']."';")); |
---|
173 | $metaog['path']=$picturepth['path']; |
---|
174 | if(isset($_SERVER['HTTPS'])){if($_SERVER['HTTPS'] == 'on'){$protocol="https://";}} |
---|
175 | else{$protocol="http://";} |
---|
176 | $metaogpath=PWG_DERIVATIVE_DIR.substr($metaog['path'], 2, -4)."-".$conf['mogsize'].substr($metaog['path'],-4); |
---|
177 | if (file_exists($metaogpath) AND $conf['mogsize']!='original'){ |
---|
178 | $metaogpath=$protocol.$_SERVER['SERVER_NAME']."/".substr($_SERVER['PHP_SELF'],0,11).PWG_DERIVATIVE_DIR.substr($metaog['path'], 2, -4)."-".$conf['mogsize'].substr($metaog['path'],-4); |
---|
179 | }else{ |
---|
180 | $metaogpath=$protocol.$_SERVER['SERVER_NAME']."/".substr($_SERVER['PHP_SELF'],0,11).substr($metaog['path'],2); |
---|
181 | } |
---|
182 | }else{ |
---|
183 | $metaogpath=""; |
---|
184 | $metaog['metaogimage']=""; |
---|
185 | } |
---|
186 | $template->assign( |
---|
187 | 'metaog_editP', |
---|
188 | array( |
---|
189 | 'metaogidid' => $metaog['id'], |
---|
190 | 'metaogidobj' => $pageog, |
---|
191 | 'metaogtitle' => $metaog['metaogtitle'], |
---|
192 | 'metaogdescription' => $metaog['metaogdescription'], |
---|
193 | 'metaogimage' => $metaog['metaogimage'], |
---|
194 | 'metaogpath' => $metaogpath, |
---|
195 | )); |
---|
196 | } |
---|
197 | } |
---|
198 | |
---|
199 | //add prefiltre album |
---|
200 | add_event_handler('loc_begin_admin', 'metaogAadminf', 60); |
---|
201 | add_event_handler('loc_begin_admin_page', 'metaogAadminA', 60); |
---|
202 | |
---|
203 | function metaogAadminf() |
---|
204 | { |
---|
205 | global $template; |
---|
206 | $template->set_prefilter('album_properties', 'metaogAadminfT'); |
---|
207 | } |
---|
208 | |
---|
209 | function metaogAadminfT($content, &$smarty) |
---|
210 | { |
---|
211 | $search = '#<p style="margin:0">#'; |
---|
212 | |
---|
213 | $replacement = ' |
---|
214 | <p> |
---|
215 | <strong>{\'Metadata Open Graph - Plugin meta og\'|@translate}</strong> |
---|
216 | <br> |
---|
217 | <br> |
---|
218 | <span style="margin: 0 0 0 20px">{\'Metadata Open Graph title\'|@translate}</span> |
---|
219 | <br> |
---|
220 | <input type="hidden" name="metaogidA" value="{$metaog_editA.metaogidid}"> |
---|
221 | <input type="hidden" name="metaogidobjA" value="{$metaog_editA.metaogidobj}"> |
---|
222 | <span style="margin: 0 0 0 20px"><input type="text" name="metaogtitlesaveA" value="{$metaog_editA.metaogtitle}" size="100" maxlenght="100"></span> |
---|
223 | <br> |
---|
224 | <br> |
---|
225 | <span style="margin: 0 0 0 20px">{\'Metadata Open Graph description\'|@translate}</span> |
---|
226 | <br> |
---|
227 | <span style="margin: 0 0 0 20px"><textarea rows="2" cols="60" name="metaogdescriptionsaveA" id="metaogdescriptionsaveA" class="metaogdescriptionsaveA">{$metaog_editA.metaogdescription}</textarea></span> |
---|
228 | <br> |
---|
229 | <br> |
---|
230 | <span style="margin: 0 0 0 20px">{\'Metadata Open Graph link image\'|@translate}</span> |
---|
231 | <br> |
---|
232 | <span style="margin: 0 0 0 20px"> |
---|
233 | <select name="metaogimagesaveA"> |
---|
234 | <option value="a">-----</option> |
---|
235 | <option value="b">{\'no photo\'|@translate}no photo</option> |
---|
236 | {foreach from=$info_photos item=infophoto} |
---|
237 | <option value="{$infophoto.PHOTOID}" {$infophoto.PHOTOSELECT}>{$infophoto.PHOTOINFO}</option> |
---|
238 | {/foreach} |
---|
239 | </select> |
---|
240 | </span> |
---|
241 | <br> |
---|
242 | {if empty($metaog_editA.metaogpath)}<span style="margin: 0 0 0 20px">{\'use representative photo for this album\'|@translate}</span>{/if} |
---|
243 | <br> |
---|
244 | <img src="{$metaog_editA.metaogpath}"><br> |
---|
245 | <br> |
---|
246 | </p> |
---|
247 | <p style="margin:0">'; |
---|
248 | |
---|
249 | return preg_replace($search, $replacement, $content); |
---|
250 | } |
---|
251 | |
---|
252 | function metaogAadminA(){ |
---|
253 | if (isset($_GET['cat_id']) and !isset($_GET['image_id'])){ |
---|
254 | global $template, $prefixeTable, $conf; |
---|
255 | $pageog=$_GET['cat_id']; |
---|
256 | $metaog = pwg_db_fetch_assoc(pwg_query("SELECT * FROM " . METAOG_TABLE . " WHERE type = 3 AND idobj = '".$_GET['cat_id']."';")); |
---|
257 | if(empty($metaog)){ |
---|
258 | $metaog['id']=''; |
---|
259 | $metaog['metaogtitle']=''; |
---|
260 | $metaog['metaogdescription']=''; |
---|
261 | $metaog['metaogimage']=''; |
---|
262 | } |
---|
263 | $tab_picture = pwg_query('SELECT id,name,path FROM ' . IMAGES_TABLE . ' order by id;'); |
---|
264 | $metaog['path']=''; |
---|
265 | if (pwg_db_num_rows($tab_picture)){ |
---|
266 | while ($info_photos = pwg_db_fetch_assoc($tab_picture)) { |
---|
267 | if($info_photos['id']==$metaog['metaogimage']){ |
---|
268 | $select="SELECTED"; |
---|
269 | $metaog['path']=$info_photos['path']; |
---|
270 | }else{ |
---|
271 | $select=""; |
---|
272 | } |
---|
273 | $items = array( |
---|
274 | 'PHOTOID' => $info_photos['id'], |
---|
275 | 'PHOTOINFO' => $info_photos['id'].' - '.$info_photos['name'], |
---|
276 | 'PHOTOSELECT' => $select, |
---|
277 | ); |
---|
278 | $template->append('info_photos', $items); |
---|
279 | } |
---|
280 | } |
---|
281 | if (empty($metaog['metaogimage'])){unset($metaog['metaogimage']);} |
---|
282 | if(isset($metaog['metaogimage'])){ |
---|
283 | if(isset($_SERVER['HTTPS'])){if($_SERVER['HTTPS'] == 'on'){$protocol="https://";}} |
---|
284 | else{$protocol="http://";} |
---|
285 | $metaogpath=PWG_DERIVATIVE_DIR.substr($metaog['path'], 2, -4)."-".$conf['mogsize'].substr($metaog['path'],-4); |
---|
286 | if (file_exists($metaogpath) AND $conf['mogsize']!='original'){ |
---|
287 | $metaogpath=$protocol.$_SERVER['SERVER_NAME']."/".substr($_SERVER['PHP_SELF'],0,11).PWG_DERIVATIVE_DIR.substr($metaog['path'], 2, -4)."-".$conf['mogsize'].substr($metaog['path'],-4); |
---|
288 | }else{ |
---|
289 | $metaogpath=$protocol.$_SERVER['SERVER_NAME']."/".substr($_SERVER['PHP_SELF'],0,11).substr($metaog['path'],2); |
---|
290 | } |
---|
291 | }else{ |
---|
292 | $metaogpath=""; |
---|
293 | $metaog['metaogimage']=""; |
---|
294 | } |
---|
295 | $template->assign( |
---|
296 | 'metaog_editA', |
---|
297 | array( |
---|
298 | 'metaogidid' => $metaog['id'], |
---|
299 | 'metaogidobj' => $pageog, |
---|
300 | 'metaogtitle' => $metaog['metaogtitle'], |
---|
301 | 'metaogdescription' => $metaog['metaogdescription'], |
---|
302 | 'metaogimage' => $metaog['metaogimage'], |
---|
303 | 'metaogpath' => $metaogpath, |
---|
304 | )); |
---|
305 | |
---|
306 | } |
---|
307 | if(isset($_POST['metaogtitlesaveA']) or isset($_POST['metaogdescriptionsaveA'])or isset($_POST['metaogimagesaveA'])){ |
---|
308 | if($_POST['metaogimagesaveA']=="a"){$_POST['metaogimagesaveA']='';} |
---|
309 | if(!empty($_POST['metaogidA'])){ |
---|
310 | if($_POST['metaogidobjA'] == $_POST['metaogimagesaveA']){$_POST['metaogimagesaveA']='';} |
---|
311 | $query = ' |
---|
312 | UPDATE ' . METAOG_TABLE . ' |
---|
313 | SET metaogtitle= \''.$_POST['metaogtitlesaveA'].'\' |
---|
314 | ,metaogdescription= \''.$_POST['metaogdescriptionsaveA'].'\' |
---|
315 | ,metaogimage= \''.$_POST['metaogimagesaveA'].'\' |
---|
316 | WHERE id = \''.$_POST['metaogidA'].'\' |
---|
317 | ;'; |
---|
318 | pwg_query($query); |
---|
319 | }else{ |
---|
320 | $q = 'INSERT INTO ' . $prefixeTable . 'metaog(type,idobj,metaogtitle,metaogdescription,metaogimage)VALUES (3,"' . $_POST['metaogidobjA'] . '","' . $_POST['metaogtitlesaveA'] . '","' . $_POST['metaogdescriptionsaveA'] . '","' . $_POST['metaogimagesaveA'] .'");'; |
---|
321 | pwg_query($q); |
---|
322 | } |
---|
323 | $metaog = pwg_db_fetch_assoc(pwg_query("SELECT * FROM " . METAOG_TABLE . " WHERE type = 3 AND idobj = '".$_POST['metaogidobjA']."';")); |
---|
324 | $metaog['path']=''; |
---|
325 | while ($info_photos = pwg_db_fetch_assoc($tab_picture)) { |
---|
326 | if($info_photos['id']==$metaog['metaogimage']){ |
---|
327 | $select="SELECTED"; |
---|
328 | $metaog['path']=$info_photos['path']; |
---|
329 | }else{ |
---|
330 | $select=""; |
---|
331 | } |
---|
332 | $items = array( |
---|
333 | 'PHOTOID' => $info_photos['id'], |
---|
334 | 'PHOTOINFO' => $info_photos['id'].' - '.$info_photos['name'], |
---|
335 | 'PHOTOSELECT' => $select, |
---|
336 | ); |
---|
337 | $template->append('info_photos', $items); |
---|
338 | } |
---|
339 | if (empty($metaog['metaogimage'])){unset($metaog['metaogimage']);} |
---|
340 | if(isset($metaog['metaogimage'])){ |
---|
341 | $picturepth = pwg_db_fetch_assoc(pwg_query('SELECT path FROM ' . IMAGES_TABLE . " WHERE id = '".$_POST['metaogidobjA']."';")); |
---|
342 | $metaog['path']=$picturepth['path']; |
---|
343 | if(isset($_SERVER['HTTPS'])){if($_SERVER['HTTPS'] == 'on'){$protocol="https://";}} |
---|
344 | else{$protocol="http://";} |
---|
345 | $metaogpath=PWG_DERIVATIVE_DIR.substr($metaog['path'], 2, -4)."-".$conf['mogsize'].substr($metaog['path'],-4); |
---|
346 | if (file_exists($metaogpath) AND $conf['mogsize']!='original'){ |
---|
347 | $metaogpath=$protocol.$_SERVER['SERVER_NAME']."/".substr($_SERVER['PHP_SELF'],0,11).PWG_DERIVATIVE_DIR.substr($metaog['path'], 2, -4)."-".$conf['mogsize'].substr($metaog['path'],-4); |
---|
348 | }else{ |
---|
349 | $metaogpath=$protocol.$_SERVER['SERVER_NAME']."/".substr($_SERVER['PHP_SELF'],0,11).substr($metaog['path'],2); |
---|
350 | } |
---|
351 | }else{ |
---|
352 | $metaogpath=""; |
---|
353 | $metaog['metaogimage']=""; |
---|
354 | } |
---|
355 | $template->assign( |
---|
356 | 'metaog_editA', |
---|
357 | array( |
---|
358 | 'metaogidid' => $metaog['id'], |
---|
359 | 'metaogidobj' => $pageog, |
---|
360 | 'metaogtitle' => $metaog['metaogtitle'], |
---|
361 | 'metaogdescription' => $metaog['metaogdescription'], |
---|
362 | 'metaogimage' => $metaog['metaogimage'], |
---|
363 | 'metaogpath' => $metaogpath, |
---|
364 | )); |
---|
365 | } |
---|
366 | } |
---|
367 | |
---|
368 | |
---|
369 | ?> |
---|