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 | |
---|
40 | type |
---|
41 | 1 : standart page |
---|
42 | 2 : photo |
---|
43 | 3 : Album |
---|
44 | 4 : AP |
---|
45 | |
---|
46 | */ |
---|
47 | |
---|
48 | if (!defined('PHPWG_ROOT_PATH')) |
---|
49 | die('Hacking attempt!'); |
---|
50 | |
---|
51 | global $prefixeTable, $page, $conf; |
---|
52 | |
---|
53 | define('metaog_DIR', basename(dirname(__FILE__))); |
---|
54 | define('metaog_PATH', PHPWG_PLUGINS_PATH . metaog_DIR . '/'); |
---|
55 | define('METAOG_ADMIN',get_root_url().'admin.php?page=plugin-'.metaog_DIR); |
---|
56 | if (!defined('METAOG_TABLE')) |
---|
57 | define('METAOG_TABLE', $prefixeTable . 'metaog'); |
---|
58 | |
---|
59 | |
---|
60 | add_event_handler('loading_lang', 'metaog_loading_lang'); |
---|
61 | function metaog_loading_lang(){ |
---|
62 | load_language('plugin.lang', metaog_PATH); |
---|
63 | } |
---|
64 | |
---|
65 | // Plugin for admin |
---|
66 | if (script_basename() == 'admin') { |
---|
67 | include_once(dirname(__FILE__) . '/initadmin.php'); |
---|
68 | } |
---|
69 | |
---|
70 | //Gestion des meta dans le header |
---|
71 | add_event_handler('loc_end_page_header', 'add_metaog', 66); |
---|
72 | |
---|
73 | |
---|
74 | function add_metaog(){ |
---|
75 | global $template, $page, $metaog, $conf, $protocol, $pwg_loaded_plugins; |
---|
76 | if(isset($_SERVER['HTTPS'])){if($_SERVER['HTTPS'] == 'on'){$protocol="https://";}} |
---|
77 | else{$protocol="http://";} |
---|
78 | |
---|
79 | $metaogurl=$protocol.$_SERVER['SERVER_NAME'].$_SERVER["REQUEST_URI"]; |
---|
80 | if (!empty($page['category']['id']) and empty($page['image_id'])){ |
---|
81 | |
---|
82 | $metaog = pwg_db_fetch_assoc(pwg_query("SELECT * FROM " . METAOG_TABLE . " WHERE type = 3 AND idobj = '".$page['category']['id']."';")); |
---|
83 | if(empty($metaog)){ |
---|
84 | $metaog['metaogtitle']=''; |
---|
85 | $metaog['metaogdescription']=''; |
---|
86 | $metaog['metaogimage']=''; |
---|
87 | } |
---|
88 | |
---|
89 | $albums = pwg_db_fetch_assoc(pwg_query("SELECT * FROM " . CATEGORIES_TABLE . " WHERE id = '".$page['category']['id']."';")); |
---|
90 | $metaog['type']="website"; |
---|
91 | if(empty($metaog['metaogtitle'])){$metaog['metaogtitle']=$albums['name'];} |
---|
92 | if(empty($metaog['metaogdescription'])){ |
---|
93 | $metaog['metaogdescription']=$albums['comment'];} |
---|
94 | if (isset($pwg_loaded_plugins['ExtendedDescription'])){ |
---|
95 | if( strstr($metaog['metaogdescription'],'<!--complete-->')) { |
---|
96 | $desc=explode('<!--complete-->', $metaog['metaogdescription']); |
---|
97 | $metaog['metaogdescription']=$desc[0]; |
---|
98 | } |
---|
99 | if( strstr($metaog['metaogdescription'],'<!--more-->')) { |
---|
100 | $desc=explode('<!--more-->', $metaog['metaogdescription']); |
---|
101 | $metaog['metaogdescription']=$desc[0]; |
---|
102 | } |
---|
103 | if( strstr($metaog['metaogdescription'],'<!--up-down-->')) { |
---|
104 | $desc=explode('<!--up-down-->', $metaog['metaogdescription']); |
---|
105 | $metaog['metaogdescription']=$desc[0]; |
---|
106 | } |
---|
107 | } |
---|
108 | if(empty($metaog['metaogimage'])){ |
---|
109 | if(isset($albums['representative_picture_id'])){ |
---|
110 | $images = pwg_db_fetch_assoc(pwg_query("SELECT id,path FROM " . IMAGES_TABLE . " WHERE id = '".$albums['representative_picture_id']."';")); |
---|
111 | } |
---|
112 | }else{ |
---|
113 | $images = pwg_db_fetch_assoc(pwg_query("SELECT id,path FROM " . IMAGES_TABLE . " WHERE id = '".$metaog['metaogimage']."';")); |
---|
114 | } |
---|
115 | if(isset($images)){ |
---|
116 | $metaog['metaogimage']=PWG_DERIVATIVE_DIR.substr($images['path'], 2, -4)."-".$conf['mogsize'].substr($images['path'],-4); |
---|
117 | if (file_exists($metaog['metaogimage']) AND $conf['mogsize']!='original'){ |
---|
118 | $metaog['metaogimage']=get_absolute_root_url().PWG_DERIVATIVE_DIR.substr($images['path'], 2, -4)."-".$conf['mogsize'].substr($images['path'],-4); |
---|
119 | }else{ |
---|
120 | $metaog['metaogimage']=get_absolute_root_url().substr($images['path'],2); |
---|
121 | } |
---|
122 | } |
---|
123 | }else if (!empty($page['image_id'])) { |
---|
124 | $metaog = pwg_db_fetch_assoc(pwg_query("SELECT * FROM " . METAOG_TABLE . " WHERE type = 2 AND idobj = '".$page['image_id']."';")); |
---|
125 | if(empty($metaog)){ |
---|
126 | $metaog['metaogtitle']=''; |
---|
127 | $metaog['metaogdescription']=''; |
---|
128 | $metaog['metaogimage']=''; |
---|
129 | } |
---|
130 | |
---|
131 | $images = pwg_db_fetch_assoc(pwg_query("SELECT * FROM " . IMAGES_TABLE . " WHERE id = '".$page['image_id']."';")); |
---|
132 | $metaog['type']="website"; |
---|
133 | if(empty($metaog['metaogtitle'])){$metaog['metaogtitle']=$images['name'];} |
---|
134 | if(empty($metaog['metaogdescription'])){$metaog['metaogdescription']=$images['comment'];} |
---|
135 | if(!empty($metaog['metaogimage'])){ |
---|
136 | $images2 = pwg_db_fetch_assoc(pwg_query("SELECT id,path FROM " . IMAGES_TABLE . " WHERE id = '".$metaog['metaogimage']."';")); |
---|
137 | $images['path']=$images2['path']; |
---|
138 | } |
---|
139 | $metaog['metaogimage']=PWG_DERIVATIVE_DIR.substr($images['path'], 2, -4)."-".$conf['mogsize'].substr($images['path'],-4); |
---|
140 | if (file_exists($metaog['metaogimage']) AND $conf['mogsize']!='original'){ |
---|
141 | $metaog['metaogimage']=get_absolute_root_url().PWG_DERIVATIVE_DIR.substr($images['path'], 2, -4)."-".$conf['mogsize'].substr($images['path'],-4); |
---|
142 | }else{ |
---|
143 | $metaog['metaogimage']=get_absolute_root_url().substr($images['path'],2); |
---|
144 | } |
---|
145 | }else if(isset($page['section']) and empty($page['category']['id'])) { |
---|
146 | if($page['section'] == 'additional_page'){ |
---|
147 | $metaog = pwg_db_fetch_assoc(pwg_query("SELECT * FROM " . METAOG_TABLE . " WHERE type =4 AND page = '".$page['additional_page']['id']."';")); |
---|
148 | }else{ |
---|
149 | $metaog = pwg_db_fetch_assoc(pwg_query("SELECT * FROM " . METAOG_TABLE . " WHERE type =1 AND page = '".$page['section']."';")); |
---|
150 | } |
---|
151 | if(empty($metaog)){ |
---|
152 | $metaog['metaogtitle']=''; |
---|
153 | $metaog['metaogdescription']=''; |
---|
154 | $metaog['metaogimage']=''; |
---|
155 | } |
---|
156 | if(!empty($metaog['metaogimage'])){ |
---|
157 | $images = pwg_db_fetch_assoc(pwg_query("SELECT id,path FROM " . IMAGES_TABLE . " WHERE id = '".$metaog['metaogimage']."';")); |
---|
158 | $metaog['metaogimage']=PWG_DERIVATIVE_DIR.substr($images['path'], 2, -4)."-".$conf['mogsize'].substr($images['path'],-4); |
---|
159 | if (file_exists($metaog['metaogimage']) AND $conf['mogsize']!='original'){ |
---|
160 | $metaog['metaogimage']=get_absolute_root_url().PWG_DERIVATIVE_DIR.substr($images['path'], 2, -4)."-".$conf['mogsize'].substr($images['path'],-4); |
---|
161 | }else{ |
---|
162 | $metaog['metaogimage']=get_absolute_root_url().substr($images['path'],2); |
---|
163 | } |
---|
164 | } |
---|
165 | $metaog['type']="website"; |
---|
166 | }else if(script_basename() == 'tags' ||script_basename() == 'comments'||script_basename() == 'about'||script_basename() == 'search'||script_basename() == 'notification'){ |
---|
167 | $metaog = pwg_db_fetch_assoc(pwg_query("SELECT * FROM " . METAOG_TABLE . " WHERE type = 1 AND page = '".script_basename()."';")); |
---|
168 | if(empty($metaog)){ |
---|
169 | $metaog['metaogtitle']=''; |
---|
170 | $metaog['metaogdescription']=''; |
---|
171 | $metaog['metaogimage']=''; |
---|
172 | } |
---|
173 | |
---|
174 | if(!empty($metaog['metaogimage']) AND $conf['mogsize']!='original'){ |
---|
175 | $images = pwg_db_fetch_assoc(pwg_query("SELECT id,path FROM " . IMAGES_TABLE . " WHERE id = '".$metaog['metaogimage']."';")); |
---|
176 | $metaog['metaogimage']=PWG_DERIVATIVE_DIR.substr($images['path'], 2, -4)."-".$conf['mogsize'].substr($images['path'],-4); |
---|
177 | if (file_exists($metaog['metaogimage'])){ |
---|
178 | $metaog['metaogimage']=get_absolute_root_url().PWG_DERIVATIVE_DIR.substr($images['path'], 2, -4)."-".$conf['mogsize'].substr($images['path'],-4); |
---|
179 | }else{ |
---|
180 | $metaog['metaogimage']=get_absolute_root_url().substr($images['path'],2); |
---|
181 | } |
---|
182 | } |
---|
183 | $metaog['type']="website"; |
---|
184 | }else{ |
---|
185 | $metaog['type']="website"; |
---|
186 | $metaog['metaogtitle']=$template->get_template_vars('PAGE_TITLE'); |
---|
187 | $metaog['metaogdescription']=$template->get_template_vars('INFO_FILE'); |
---|
188 | } |
---|
189 | |
---|
190 | |
---|
191 | if (isset($pwg_loaded_plugins['ExtendedDescription'])){ |
---|
192 | add_event_handler('AP_render_content', 'get_user_language_desc'); |
---|
193 | } |
---|
194 | // og:url |
---|
195 | if (!empty($metaogurl)) { |
---|
196 | $template->append('head_elements', '<meta property="og:url" content="' . $metaogurl . '">'); |
---|
197 | } |
---|
198 | // og:type |
---|
199 | if (!empty($metaog['type'])) { |
---|
200 | $template->append('head_elements', '<meta property="og:type" content="' . $metaog['type'] . '">'); |
---|
201 | } |
---|
202 | |
---|
203 | // og:title |
---|
204 | if (!empty($metaog['metaogtitle'])) { |
---|
205 | $template->append('head_elements', '<meta property="og:title" content="' . strip_tags(trigger_change('AP_render_content', $metaog['metaogtitle'])) . '">'); |
---|
206 | } |
---|
207 | |
---|
208 | // og:description |
---|
209 | if (!empty($metaog['metaogdescription'])) { |
---|
210 | $template->append('head_elements', '<meta property="og:description" content="' . strip_tags(trigger_change('AP_render_content', $metaog['metaogdescription'])) . '">'); |
---|
211 | } |
---|
212 | |
---|
213 | // og:image |
---|
214 | if (!empty($metaog['metaogimage'])) { |
---|
215 | $metaog['metaogimagetype']=substr($metaog['metaogimage'],-3); |
---|
216 | if($metaog['metaogimagetype']=='jpg'){$metaog['metaogimagetype']='jpeg';} |
---|
217 | $template->append('head_elements', '<meta property="og:image" content="' . $metaog['metaogimage'] . '">'); |
---|
218 | $template->append('head_elements', '<meta property="og:image:type" content="image/' . $metaog['metaogimagetype'] . '">'); |
---|
219 | } |
---|
220 | |
---|
221 | // og:app_id |
---|
222 | if (!empty($conf['fb:app_id'])) { |
---|
223 | $template->append('head_elements', '<meta property="fb:app_id" content="' . $conf['fb:app_id'] . '">'); |
---|
224 | } |
---|
225 | // og:local |
---|
226 | if (!empty($conf['moglocal'])) { |
---|
227 | $template->append('head_elements', '<meta property="og:locale" content="' . $conf['moglocal'] . '">'); |
---|
228 | } |
---|
229 | |
---|
230 | // og:site_name |
---|
231 | if (!empty($conf['mogsitename'])) { |
---|
232 | $template->append('head_elements', '<meta property="og:site_name" content="' . $conf['mogsitename'] . '">'); |
---|
233 | } |
---|
234 | |
---|
235 | // twitter:card |
---|
236 | if (!empty($conf['mogtwcard'])) { |
---|
237 | $template->append('head_elements', '<meta property="twitter:card" content="' . $conf['mogtwcard'] . '">'); |
---|
238 | } |
---|
239 | |
---|
240 | // twitter:site |
---|
241 | if (!empty($conf['mogtwsite'])) { |
---|
242 | $template->append('head_elements', '<meta property="twitter:site" content="' . $conf['mogtwsite'] . '">'); |
---|
243 | } |
---|
244 | |
---|
245 | // twitter:creator |
---|
246 | if (!empty($conf['mogtwcreator'])) { |
---|
247 | $template->append('head_elements', '<meta property="twitter:creator" content="' . $conf['mogtwcreator'] . '">'); |
---|
248 | } |
---|
249 | } |
---|
250 | ?> |
---|