1 | <?php |
---|
2 | // +-----------------------------------------------------------------------+ |
---|
3 | // | Meta Open Graph plugin for Piwigo by TEMMII | |
---|
4 | // +-----------------------------------------------------------------------+ |
---|
5 | // | Copyright(C) 2020-2022 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 | include_once(metaog_PATH . 'include/function.mog.inc.php'); |
---|
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_page', 'metaogPadminf',95); |
---|
36 | |
---|
37 | function metaogPadminf(){ |
---|
38 | global $template; |
---|
39 | $template->set_prefilter('picture_modify', 'metaogPadminfT'); |
---|
40 | $template->set_filename('mog_adminphoto', realpath(metaog_PATH.'mog_adminphoto.tpl')); |
---|
41 | $template->assign_var_from_handle('MOG_ADMINPHOTO', 'mog_adminphoto'); |
---|
42 | } |
---|
43 | |
---|
44 | function metaogPadminfT($content){ |
---|
45 | $search = '#<input type="hidden" name="pwg_token"#'; |
---|
46 | return preg_replace($search,'{$MOG_ADMINPHOTO}', $content); |
---|
47 | } |
---|
48 | |
---|
49 | add_event_handler('loc_begin_admin_page', 'metaogPadminA',60); |
---|
50 | |
---|
51 | function metaogPadminA(){ |
---|
52 | if (isset($_GET['image_id'])){ |
---|
53 | global $template, $prefixeTable, $conf; |
---|
54 | $pageog=$_GET['image_id']; |
---|
55 | $metaog = pwg_db_fetch_assoc(pwg_query("SELECT * FROM " . METAOG_TABLE . " WHERE type = 2 AND idobj = '".$_GET['image_id']."';")); |
---|
56 | if(empty($metaog)){ |
---|
57 | $metaog['id']=''; |
---|
58 | $metaog['metaogtitle']=''; |
---|
59 | $metaog['metaogdescription']=''; |
---|
60 | $metaog['metaogimage']=''; |
---|
61 | } |
---|
62 | if($conf['mogshowpa']==2||$conf['mogshowpa']==4){ |
---|
63 | $tab_picture = listphotosmog(); |
---|
64 | if (pwg_db_num_rows($tab_picture)){ |
---|
65 | while ($info_photos = pwg_db_fetch_assoc($tab_picture)) { |
---|
66 | if($info_photos['id']==$metaog['metaogimage']){ |
---|
67 | $select="SELECTED"; |
---|
68 | $metaog['path']=$info_photos['path']; |
---|
69 | }else{ |
---|
70 | $select=""; |
---|
71 | } |
---|
72 | if(empty($info_photos['name'])){$legend=$info_photos['file'];}else{$legend=$info_photos['name'];} |
---|
73 | $metaoglistphotoT[] = $info_photos['id'].' - '.$legend; |
---|
74 | $metaoglistphoto[] = $info_photos['id']; |
---|
75 | $metaoglistphotodataurl[] = get_absolute_root_url().PWG_DERIVATIVE_DIR.substr($info_photos['path'], 2, -4)."-th".substr($info_photos['path'],-4); |
---|
76 | $items = array( |
---|
77 | 'PHOTOID' => $info_photos['id'], |
---|
78 | 'PHOTOINFO' => $info_photos['id'].' - '.$legend, |
---|
79 | 'PHOTOSELECT' => $select, |
---|
80 | 'PHOTOURL' => get_absolute_root_url().PWG_DERIVATIVE_DIR.substr($info_photos['path'], 2, -4)."-th".substr($info_photos['path'],-4), |
---|
81 | ); |
---|
82 | $template->append('info_photos', $items); |
---|
83 | } |
---|
84 | } |
---|
85 | if (empty($metaog['metaogimage'])){unset($metaog['metaogimage']);} |
---|
86 | if(isset($metaog['metaogimage'])){ |
---|
87 | $metaogpath=get_absolute_root_url().PWG_DERIVATIVE_DIR.substr($metaog['path'], 2, -4)."-th".substr($metaog['path'],-4); |
---|
88 | }else{ |
---|
89 | $metaogpath=""; |
---|
90 | $metaog['metaogimage']=""; |
---|
91 | } |
---|
92 | $template->assign('SHOWMOGI', "1"); |
---|
93 | }else{ |
---|
94 | $template->assign('SHOWMOGI', "0"); |
---|
95 | } |
---|
96 | if(!isset($metaogpath)){$metaogpath="";} |
---|
97 | $template->assign( |
---|
98 | 'metaog_editP', |
---|
99 | array( |
---|
100 | 'metaogidid' => $metaog['id'], |
---|
101 | 'metaogidobj' => $pageog, |
---|
102 | 'metaogtitle' => $metaog['metaogtitle'], |
---|
103 | 'metaogdescription' => $metaog['metaogdescription'], |
---|
104 | 'metaogimage' => $metaog['metaogimage'], |
---|
105 | 'metaogpath' => $metaogpath, |
---|
106 | )); |
---|
107 | } |
---|
108 | if(isset($_POST['metaogtitlesaveP']) or isset($_POST['metaogdescriptionsaveP'])or isset($_POST['metaogimagesaveP'])){ |
---|
109 | if($_POST['metaogimagesaveP']=="-10" || $_POST['metaogimagesaveP']=="-20" || $_POST['metaogimagesaveP']==$_POST['metaogidobjP']){$_POST['metaogimagesaveP']='';} |
---|
110 | if(!empty($_POST['metaogidP'])){ |
---|
111 | $query = ' |
---|
112 | UPDATE ' . METAOG_TABLE . ' |
---|
113 | SET metaogtitle= \''.$_POST['metaogtitlesaveP'].'\' |
---|
114 | ,metaogdescription= \''.$_POST['metaogdescriptionsaveP'].'\' |
---|
115 | ,metaogimage= \''.$_POST['metaogimagesaveP'].'\' |
---|
116 | WHERE id = \''.$_POST['metaogidP'].'\' |
---|
117 | ;'; |
---|
118 | pwg_query($query); |
---|
119 | }else{ |
---|
120 | $q = 'INSERT INTO ' . $prefixeTable . 'metaog(type,idobj,metaogtitle,metaogdescription,metaogimage)VALUES (2,"' . $_POST['metaogidobjP'] . '","' . $_POST['metaogtitlesaveP'] . '","' . $_POST['metaogdescriptionsaveP'] . '","' . $_POST['metaogimagesaveP'] .'");'; |
---|
121 | pwg_query($q); |
---|
122 | } |
---|
123 | header('Location:'.get_root_url().'admin.php?page=photo-'.$_POST['metaogidobjP'].'-properties'); |
---|
124 | } |
---|
125 | } |
---|
126 | |
---|
127 | //add prefiltre album |
---|
128 | add_event_handler('loc_begin_admin_page', 'metaogAadminf', 95); |
---|
129 | |
---|
130 | function metaogAadminf(){ |
---|
131 | global $template; |
---|
132 | $template->set_prefilter('album_properties', 'metaogAadminfT'); |
---|
133 | $template->set_filename('mog_adminalbum', realpath(metaog_PATH.'mog_adminalbum.tpl')); |
---|
134 | $template->assign_var_from_handle('MOG_ADMINALBUM', 'mog_adminalbum'); |
---|
135 | } |
---|
136 | |
---|
137 | function metaogAadminfT($content){ |
---|
138 | $search = '#<p style="margin:0">#'; |
---|
139 | return preg_replace($search, '{$MOG_ADMINALBUM}', $content); |
---|
140 | } |
---|
141 | |
---|
142 | add_event_handler('loc_begin_admin_page', 'metaogAadminA', 60); |
---|
143 | |
---|
144 | function metaogAadminA(){ |
---|
145 | if (isset($_GET['cat_id']) and !isset($_GET['image_id'])){ |
---|
146 | global $template, $prefixeTable, $conf; |
---|
147 | $pageog=$_GET['cat_id']; |
---|
148 | $metaog = pwg_db_fetch_assoc(pwg_query("SELECT * FROM " . METAOG_TABLE . " WHERE type = 3 AND idobj = '".$_GET['cat_id']."';")); |
---|
149 | if(empty($metaog)){ |
---|
150 | $metaog['id']=''; |
---|
151 | $metaog['metaogtitle']=''; |
---|
152 | $metaog['metaogdescription']=''; |
---|
153 | $metaog['metaogimage']=''; |
---|
154 | } |
---|
155 | if($conf['mogshowpa']==3||$conf['mogshowpa']==4){ |
---|
156 | $tab_picture = listphotosmog(); |
---|
157 | $metaog['path']=''; |
---|
158 | if (pwg_db_num_rows($tab_picture)){ |
---|
159 | while ($info_photos = pwg_db_fetch_assoc($tab_picture)) { |
---|
160 | if($info_photos['id']==$metaog['metaogimage']){ |
---|
161 | $select="SELECTED"; |
---|
162 | $metaog['path']=$info_photos['path']; |
---|
163 | }else{ |
---|
164 | $select=""; |
---|
165 | } |
---|
166 | if(empty($info_photos['name'])){$legend=$info_photos['file'];}else{$legend=$info_photos['name'];} |
---|
167 | $items = array( |
---|
168 | 'PHOTOID' => $info_photos['id'], |
---|
169 | 'PHOTOINFO' => $info_photos['id'].' - '.$legend, |
---|
170 | 'PHOTOSELECT' => $select, |
---|
171 | 'PHOTOURL' => get_absolute_root_url().PWG_DERIVATIVE_DIR.substr($info_photos['path'], 2, -4)."-th".substr($info_photos['path'],-4), |
---|
172 | ); |
---|
173 | $template->append('info_photos', $items); |
---|
174 | } |
---|
175 | } |
---|
176 | if (empty($metaog['metaogimage'])){unset($metaog['metaogimage']);} |
---|
177 | if(isset($metaog['metaogimage'])){ |
---|
178 | $metaogpath=get_absolute_root_url().PWG_DERIVATIVE_DIR.substr($metaog['path'], 2, -4)."-th".substr($metaog['path'],-4); |
---|
179 | }else{ |
---|
180 | $metaogpath=""; |
---|
181 | $metaog['metaogimage']=""; |
---|
182 | } |
---|
183 | $template->assign('SHOWMOGI', "1"); |
---|
184 | }else{ |
---|
185 | $template->assign('SHOWMOGI', "0"); |
---|
186 | } |
---|
187 | if(!isset($metaogpath)){$metaogpath="";} |
---|
188 | $tab_album = pwg_db_fetch_assoc(pwg_query("SELECT id,representative_picture_id FROM " . CATEGORIES_TABLE . " WHERE id = '".$_GET['cat_id']."';")); |
---|
189 | $template->assign( |
---|
190 | 'metaog_editA', |
---|
191 | array( |
---|
192 | 'metaogidid' => $metaog['id'], |
---|
193 | 'metaogidobj' => $pageog, |
---|
194 | 'metaogtitle' => $metaog['metaogtitle'], |
---|
195 | 'metaogdescription' => $metaog['metaogdescription'], |
---|
196 | 'metaogimage' => $metaog['metaogimage'], |
---|
197 | 'metaogpath' => $metaogpath, |
---|
198 | 'metaogrealbum' => $tab_album['representative_picture_id'], |
---|
199 | )); |
---|
200 | |
---|
201 | } |
---|
202 | if(isset($_POST['metaogtitlesaveA']) or isset($_POST['metaogdescriptionsaveA'])or isset($_POST['metaogimagesaveA'])){ |
---|
203 | if($_POST['metaogimagesaveA']=="-10"|| $_POST['metaogimagesaveA']=="-20" || $_POST['metaogimagesaveA']==$tab_album['representative_picture_id']){$_POST['metaogimagesaveA']='';} |
---|
204 | if(!empty($_POST['metaogidA'])){ |
---|
205 | if($_POST['metaogidobjA'] == $_POST['metaogimagesaveA']){$_POST['metaogimagesaveA']='';} |
---|
206 | $query = ' |
---|
207 | UPDATE ' . METAOG_TABLE . ' |
---|
208 | SET metaogtitle= \''.$_POST['metaogtitlesaveA'].'\' |
---|
209 | ,metaogdescription= \''.$_POST['metaogdescriptionsaveA'].'\' |
---|
210 | ,metaogimage= \''.$_POST['metaogimagesaveA'].'\' |
---|
211 | WHERE id = \''.$_POST['metaogidA'].'\' |
---|
212 | ;'; |
---|
213 | pwg_query($query); |
---|
214 | }else{ |
---|
215 | $q = 'INSERT INTO ' . $prefixeTable . 'metaog(type,idobj,metaogtitle,metaogdescription,metaogimage)VALUES (3,"' . $_POST['metaogidobjA'] . '","' . $_POST['metaogtitlesaveA'] . '","' . $_POST['metaogdescriptionsaveA'] . '","' . $_POST['metaogimagesaveA'] .'");'; |
---|
216 | pwg_query($q); |
---|
217 | } |
---|
218 | header('Location:'.get_root_url().'admin.php?page=album-'.$_POST['metaogidobjP'].'-properties'); |
---|
219 | } |
---|
220 | } |
---|
221 | |
---|
222 | |
---|
223 | ?> |
---|