1 | <?php |
---|
2 | /* |
---|
3 | Plugin Name: Meta Open Graph |
---|
4 | Version: auto |
---|
5 | Description: Allows to add metadata Open Graph |
---|
6 | Plugin URI: http://piwigo.org/ext/extension_view.php?eid=889 |
---|
7 | Author: ddtddt |
---|
8 | Author URI: http://temmii.com/piwigo/ |
---|
9 | */ |
---|
10 | |
---|
11 | // +-----------------------------------------------------------------------+ |
---|
12 | // | meta_og plugin for Piwigo by TEMMII | |
---|
13 | // +-----------------------------------------------------------------------+ |
---|
14 | // | Copyright(C) 2008-2020 ddtddt http://temmii.com/piwigo/ | |
---|
15 | // +-----------------------------------------------------------------------+ |
---|
16 | // | This program is free software; you can redistribute it and/or modify | |
---|
17 | // | it under the terms of the GNU General Public License as published by | |
---|
18 | // | the Free Software Foundation | |
---|
19 | // | | |
---|
20 | // | This program is distributed in the hope that it will be useful, but | |
---|
21 | // | WITHOUT ANY WARRANTY; without even the implied warranty of | |
---|
22 | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
---|
23 | // | General Public License for more details. | |
---|
24 | // | | |
---|
25 | // | You should have received a copy of the GNU General Public License | |
---|
26 | // | along with this program; if not, write to the Free Software | |
---|
27 | // | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
---|
28 | // | USA. | |
---|
29 | // +-----------------------------------------------------------------------+ |
---|
30 | |
---|
31 | /* |
---|
32 | $conf['fb:app_id'] -> for use Insights Facebook |
---|
33 | $conf['mogsize'] > for size image |
---|
34 | $conf['moglocal'] > for local:og |
---|
35 | $conf['mogsitename'] > for og:site_name |
---|
36 | $conf['mogtwcard'] > for twitter:card |
---|
37 | $conf['mogtwsite'] > for twitter:site |
---|
38 | $conf['mogtwcreator'] > for twitter:creator |
---|
39 | $conf['mogshowpa'] > for change meta og photo on photo or album page |
---|
40 | $conf['moglista'] > list album for meta og photo |
---|
41 | |
---|
42 | type |
---|
43 | 1 : standart page |
---|
44 | 2 : photo |
---|
45 | 3 : Album |
---|
46 | 4 : AP |
---|
47 | |
---|
48 | */ |
---|
49 | |
---|
50 | if (!defined('PHPWG_ROOT_PATH')) |
---|
51 | die('Hacking attempt!'); |
---|
52 | |
---|
53 | global $prefixeTable, $page, $conf; |
---|
54 | |
---|
55 | define('metaog_DIR', basename(dirname(__FILE__))); |
---|
56 | define('metaog_PATH', PHPWG_PLUGINS_PATH . metaog_DIR . '/'); |
---|
57 | define('METAOG_ADMIN',get_root_url().'admin.php?page=plugin-'.metaog_DIR); |
---|
58 | if (!defined('METAOG_TABLE')) |
---|
59 | define('METAOG_TABLE', $prefixeTable . 'metaog'); |
---|
60 | |
---|
61 | |
---|
62 | add_event_handler('loading_lang', 'metaog_loading_lang'); |
---|
63 | function metaog_loading_lang(){ |
---|
64 | load_language('plugin.lang', metaog_PATH); |
---|
65 | } |
---|
66 | |
---|
67 | // Plugin for admin |
---|
68 | if (script_basename() == 'admin') { |
---|
69 | include_once(dirname(__FILE__) . '/initadmin.php'); |
---|
70 | } |
---|
71 | |
---|
72 | //Gestion des meta dans le header |
---|
73 | add_event_handler('loc_end_page_header', 'add_metaog', 66); |
---|
74 | |
---|
75 | |
---|
76 | function add_metaog(){ |
---|
77 | global $template, $page, $metaog, $conf, $protocol, $pwg_loaded_plugins; |
---|
78 | if(isset($_SERVER['HTTPS'])){if($_SERVER['HTTPS'] == 'on'){$protocol="https://";}} |
---|
79 | else{$protocol="http://";} |
---|
80 | |
---|
81 | if (isset($pwg_loaded_plugins['ExtendedDescription'])){ |
---|
82 | add_event_handler('AP_render_content', 'get_user_language_desc'); |
---|
83 | } |
---|
84 | |
---|
85 | $metaogurl=$protocol.$_SERVER['SERVER_NAME'].$_SERVER["REQUEST_URI"]; |
---|
86 | if (!empty($page['category']['id']) and empty($page['image_id'])){ |
---|
87 | |
---|
88 | $metaog = pwg_db_fetch_assoc(pwg_query("SELECT * FROM " . METAOG_TABLE . " WHERE type = 3 AND idobj = '".$page['category']['id']."';")); |
---|
89 | if(empty($metaog)){ |
---|
90 | $metaog['metaogtitle']=''; |
---|
91 | $metaog['metaogdescription']=''; |
---|
92 | $metaog['metaogimage']=''; |
---|
93 | } |
---|
94 | |
---|
95 | $albums = pwg_db_fetch_assoc(pwg_query("SELECT * FROM " . CATEGORIES_TABLE . " WHERE id = '".$page['category']['id']."';")); |
---|
96 | $metaog['type']="website"; |
---|
97 | if(empty($metaog['metaogtitle'])){$metaog['metaogtitle']=$albums['name'];} |
---|
98 | if(empty($metaog['metaogdescription'])){ |
---|
99 | $metaog['metaogdescription']=$albums['comment'];} |
---|
100 | if (isset($pwg_loaded_plugins['ExtendedDescription'])){ |
---|
101 | $metaog['metaogdescription']=trigger_change('AP_render_content', $metaog['metaogdescription']); |
---|
102 | if( strstr($metaog['metaogdescription'],'<!--complete-->')) { |
---|
103 | $desc=explode('<!--complete-->', $metaog['metaogdescription']); |
---|
104 | $metaog['metaogdescription']=$desc[0]; |
---|
105 | } |
---|
106 | if( strstr($metaog['metaogdescription'],'<!--more-->')) { |
---|
107 | $desc=explode('<!--more-->', $metaog['metaogdescription']); |
---|
108 | $metaog['metaogdescription']=$desc[0]; |
---|
109 | } |
---|
110 | if( strstr($metaog['metaogdescription'],'<!--up-down-->')) { |
---|
111 | $desc=explode('<!--up-down-->', $metaog['metaogdescription']); |
---|
112 | $metaog['metaogdescription']=$desc[0]; |
---|
113 | } |
---|
114 | } |
---|
115 | if(empty($metaog['metaogimage'])){ |
---|
116 | if(isset($albums['representative_picture_id'])){ |
---|
117 | $images = pwg_db_fetch_assoc(pwg_query("SELECT id,path FROM " . IMAGES_TABLE . " WHERE id = '".$albums['representative_picture_id']."';")); |
---|
118 | } |
---|
119 | }else{ |
---|
120 | $images = pwg_db_fetch_assoc(pwg_query("SELECT id,path FROM " . IMAGES_TABLE . " WHERE id = '".$metaog['metaogimage']."';")); |
---|
121 | } |
---|
122 | if(isset($images)){ |
---|
123 | $metaog['metaogimage']=PWG_DERIVATIVE_DIR.substr($images['path'], 2, -4)."-".$conf['mogsize'].substr($images['path'],-4); |
---|
124 | if (file_exists($metaog['metaogimage']) AND $conf['mogsize']!='original'){ |
---|
125 | $metaog['metaogimage']=get_absolute_root_url().PWG_DERIVATIVE_DIR.substr($images['path'], 2, -4)."-".$conf['mogsize'].substr($images['path'],-4); |
---|
126 | }else{ |
---|
127 | $metaog['metaogimage']=get_absolute_root_url().substr($images['path'],2); |
---|
128 | } |
---|
129 | } |
---|
130 | }else if (!empty($page['image_id'])) { |
---|
131 | $metaog = pwg_db_fetch_assoc(pwg_query("SELECT * FROM " . METAOG_TABLE . " WHERE type = 2 AND idobj = '".$page['image_id']."';")); |
---|
132 | if(empty($metaog)){ |
---|
133 | $metaog['metaogtitle']=''; |
---|
134 | $metaog['metaogdescription']=''; |
---|
135 | $metaog['metaogimage']=''; |
---|
136 | } |
---|
137 | |
---|
138 | $images = pwg_db_fetch_assoc(pwg_query("SELECT * FROM " . IMAGES_TABLE . " WHERE id = '".$page['image_id']."';")); |
---|
139 | $metaog['type']="website"; |
---|
140 | if(empty($metaog['metaogtitle'])){$metaog['metaogtitle']=$images['name'];} |
---|
141 | if(empty($metaog['metaogdescription'])){$metaog['metaogdescription']=$images['comment'];} |
---|
142 | if(!empty($metaog['metaogimage'])){ |
---|
143 | $images2 = pwg_db_fetch_assoc(pwg_query("SELECT id,path FROM " . IMAGES_TABLE . " WHERE id = '".$metaog['metaogimage']."';")); |
---|
144 | $images['path']=$images2['path']; |
---|
145 | } |
---|
146 | $metaog['metaogimage']=PWG_DERIVATIVE_DIR.substr($images['path'], 2, -4)."-".$conf['mogsize'].substr($images['path'],-4); |
---|
147 | if (file_exists($metaog['metaogimage']) AND $conf['mogsize']!='original'){ |
---|
148 | $metaog['metaogimage']=get_absolute_root_url().PWG_DERIVATIVE_DIR.substr($images['path'], 2, -4)."-".$conf['mogsize'].substr($images['path'],-4); |
---|
149 | }else{ |
---|
150 | $metaog['metaogimage']=get_absolute_root_url().substr($images['path'],2); |
---|
151 | } |
---|
152 | }else if(isset($page['section']) and empty($page['category']['id'])) { |
---|
153 | if($page['section'] == 'additional_page'){ |
---|
154 | $metaog = pwg_db_fetch_assoc(pwg_query("SELECT * FROM " . METAOG_TABLE . " WHERE type =4 AND page = '".$page['additional_page']['id']."';")); |
---|
155 | }else{ |
---|
156 | $metaog = pwg_db_fetch_assoc(pwg_query("SELECT * FROM " . METAOG_TABLE . " WHERE type =1 AND page = '".$page['section']."';")); |
---|
157 | } |
---|
158 | if(empty($metaog)){ |
---|
159 | $metaog['metaogtitle']=''; |
---|
160 | $metaog['metaogdescription']=''; |
---|
161 | $metaog['metaogimage']=''; |
---|
162 | } |
---|
163 | if(!empty($metaog['metaogimage'])){ |
---|
164 | $images = pwg_db_fetch_assoc(pwg_query("SELECT id,path FROM " . IMAGES_TABLE . " WHERE id = '".$metaog['metaogimage']."';")); |
---|
165 | $metaog['metaogimage']=PWG_DERIVATIVE_DIR.substr($images['path'], 2, -4)."-".$conf['mogsize'].substr($images['path'],-4); |
---|
166 | if (file_exists($metaog['metaogimage']) AND $conf['mogsize']!='original'){ |
---|
167 | $metaog['metaogimage']=get_absolute_root_url().PWG_DERIVATIVE_DIR.substr($images['path'], 2, -4)."-".$conf['mogsize'].substr($images['path'],-4); |
---|
168 | }else{ |
---|
169 | $metaog['metaogimage']=get_absolute_root_url().substr($images['path'],2); |
---|
170 | } |
---|
171 | } |
---|
172 | $metaog['type']="website"; |
---|
173 | }else if(script_basename() == 'tags' ||script_basename() == 'comments'||script_basename() == 'about'||script_basename() == 'search'||script_basename() == 'notification'){ |
---|
174 | $metaog = pwg_db_fetch_assoc(pwg_query("SELECT * FROM " . METAOG_TABLE . " WHERE type = 1 AND page = '".script_basename()."';")); |
---|
175 | if(empty($metaog)){ |
---|
176 | $metaog['metaogtitle']=''; |
---|
177 | $metaog['metaogdescription']=''; |
---|
178 | $metaog['metaogimage']=''; |
---|
179 | } |
---|
180 | |
---|
181 | if(!empty($metaog['metaogimage']) AND $conf['mogsize']!='original'){ |
---|
182 | $images = pwg_db_fetch_assoc(pwg_query("SELECT id,path FROM " . IMAGES_TABLE . " WHERE id = '".$metaog['metaogimage']."';")); |
---|
183 | $metaog['metaogimage']=PWG_DERIVATIVE_DIR.substr($images['path'], 2, -4)."-".$conf['mogsize'].substr($images['path'],-4); |
---|
184 | if (file_exists($metaog['metaogimage'])){ |
---|
185 | $metaog['metaogimage']=get_absolute_root_url().PWG_DERIVATIVE_DIR.substr($images['path'], 2, -4)."-".$conf['mogsize'].substr($images['path'],-4); |
---|
186 | }else{ |
---|
187 | $metaog['metaogimage']=get_absolute_root_url().substr($images['path'],2); |
---|
188 | } |
---|
189 | } |
---|
190 | $metaog['type']="website"; |
---|
191 | }else{ |
---|
192 | $metaog['type']="website"; |
---|
193 | $metaog['metaogtitle']=$template->get_template_vars('PAGE_TITLE'); |
---|
194 | $metaog['metaogdescription']=$template->get_template_vars('INFO_FILE'); |
---|
195 | } |
---|
196 | |
---|
197 | |
---|
198 | |
---|
199 | // og:url |
---|
200 | if (!empty($metaogurl)) { |
---|
201 | $template->append('head_elements', '<meta property="og:url" content="' . $metaogurl . '">'); |
---|
202 | } |
---|
203 | // og:type |
---|
204 | if (!empty($metaog['type'])) { |
---|
205 | $template->append('head_elements', '<meta property="og:type" content="' . $metaog['type'] . '">'); |
---|
206 | } |
---|
207 | |
---|
208 | // og:title |
---|
209 | if (!empty($metaog['metaogtitle'])) { |
---|
210 | $template->append('head_elements', '<meta property="og:title" content="' . strip_tags(trigger_change('AP_render_content', $metaog['metaogtitle'])) . '">'); |
---|
211 | } |
---|
212 | |
---|
213 | // og:description |
---|
214 | if (!empty($metaog['metaogdescription'])) { |
---|
215 | $template->append('head_elements', '<meta property="og:description" content="' . strip_tags($metaog['metaogdescription']) . '">'); |
---|
216 | } |
---|
217 | |
---|
218 | // og:image |
---|
219 | if (!empty($metaog['metaogimage'])) { |
---|
220 | $metaog['metaogimagetype']=substr($metaog['metaogimage'],-3); |
---|
221 | if($metaog['metaogimagetype']=='jpg'){$metaog['metaogimagetype']='jpeg';} |
---|
222 | $template->append('head_elements', '<meta property="og:image" content="' . $metaog['metaogimage'] . '">'); |
---|
223 | $template->append('head_elements', '<meta property="og:image:type" content="image/' . $metaog['metaogimagetype'] . '">'); |
---|
224 | } |
---|
225 | |
---|
226 | // og:app_id |
---|
227 | if (!empty($conf['fb:app_id'])) { |
---|
228 | $template->append('head_elements', '<meta property="fb:app_id" content="' . $conf['fb:app_id'] . '">'); |
---|
229 | } |
---|
230 | // og:local |
---|
231 | if (!empty($conf['moglocal'])) { |
---|
232 | $template->append('head_elements', '<meta property="og:locale" content="' . $conf['moglocal'] . '">'); |
---|
233 | } |
---|
234 | |
---|
235 | // og:site_name |
---|
236 | if (!empty($conf['mogsitename'])) { |
---|
237 | $template->append('head_elements', '<meta property="og:site_name" content="' . $conf['mogsitename'] . '">'); |
---|
238 | } |
---|
239 | |
---|
240 | // twitter:card |
---|
241 | if (!empty($conf['mogtwcard'])) { |
---|
242 | $template->append('head_elements', '<meta property="twitter:card" content="' . $conf['mogtwcard'] . '">'); |
---|
243 | } |
---|
244 | |
---|
245 | // twitter:site |
---|
246 | if (!empty($conf['mogtwsite'])) { |
---|
247 | $template->append('head_elements', '<meta property="twitter:site" content="' . $conf['mogtwsite'] . '">'); |
---|
248 | } |
---|
249 | |
---|
250 | // twitter:creator |
---|
251 | if (!empty($conf['mogtwcreator'])) { |
---|
252 | $template->append('head_elements', '<meta property="twitter:creator" content="' . $conf['mogtwcreator'] . '">'); |
---|
253 | } |
---|
254 | } |
---|
255 | ?> |
---|