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'])){$metaog['metaogdescription']=$albums['comment'];} |
---|
93 | if(empty($metaog['metaogimage'])){ |
---|
94 | if(isset($albums['representative_picture_id'])){ |
---|
95 | $images = pwg_db_fetch_assoc(pwg_query("SELECT id,path FROM " . IMAGES_TABLE . " WHERE id = '".$albums['representative_picture_id']."';")); |
---|
96 | } |
---|
97 | }else{ |
---|
98 | $images = pwg_db_fetch_assoc(pwg_query("SELECT id,path FROM " . IMAGES_TABLE . " WHERE id = '".$metaog['metaogimage']."';")); |
---|
99 | } |
---|
100 | if(isset($images)){ |
---|
101 | $metaog['metaogimage']=PWG_DERIVATIVE_DIR.substr($images['path'], 2, -4)."-".$conf['mogsize'].substr($images['path'],-4); |
---|
102 | if (file_exists($metaog['metaogimage']) AND $conf['mogsize']!='original'){ |
---|
103 | $metaog['metaogimage']=get_absolute_root_url().PWG_DERIVATIVE_DIR.substr($images['path'], 2, -4)."-".$conf['mogsize'].substr($images['path'],-4); |
---|
104 | }else{ |
---|
105 | $metaog['metaogimage']=get_absolute_root_url().substr($images['path'],2); |
---|
106 | } |
---|
107 | } |
---|
108 | }else if (!empty($page['image_id'])) { |
---|
109 | $metaog = pwg_db_fetch_assoc(pwg_query("SELECT * FROM " . METAOG_TABLE . " WHERE type = 2 AND idobj = '".$page['image_id']."';")); |
---|
110 | if(empty($metaog)){ |
---|
111 | $metaog['metaogtitle']=''; |
---|
112 | $metaog['metaogdescription']=''; |
---|
113 | $metaog['metaogimage']=''; |
---|
114 | } |
---|
115 | |
---|
116 | $images = pwg_db_fetch_assoc(pwg_query("SELECT * FROM " . IMAGES_TABLE . " WHERE id = '".$page['image_id']."';")); |
---|
117 | $metaog['type']="website"; |
---|
118 | if(empty($metaog['metaogtitle'])){$metaog['metaogtitle']=$images['name'];} |
---|
119 | if(empty($metaog['metaogdescription'])){$metaog['metaogdescription']=$images['comment'];} |
---|
120 | if(!empty($metaog['metaogimage'])){ |
---|
121 | $images2 = pwg_db_fetch_assoc(pwg_query("SELECT id,path FROM " . IMAGES_TABLE . " WHERE id = '".$metaog['metaogimage']."';")); |
---|
122 | $images['path']=$images2['path']; |
---|
123 | } |
---|
124 | $metaog['metaogimage']=PWG_DERIVATIVE_DIR.substr($images['path'], 2, -4)."-".$conf['mogsize'].substr($images['path'],-4); |
---|
125 | if (file_exists($metaog['metaogimage']) AND $conf['mogsize']!='original'){ |
---|
126 | $metaog['metaogimage']=get_absolute_root_url().PWG_DERIVATIVE_DIR.substr($images['path'], 2, -4)."-".$conf['mogsize'].substr($images['path'],-4); |
---|
127 | }else{ |
---|
128 | $metaog['metaogimage']=get_absolute_root_url().substr($images['path'],2); |
---|
129 | } |
---|
130 | }else if(isset($page['section']) and empty($page['category']['id'])) { |
---|
131 | if($page['section'] == 'additional_page'){ |
---|
132 | $metaog = pwg_db_fetch_assoc(pwg_query("SELECT * FROM " . METAOG_TABLE . " WHERE type =4 AND page = '".$page['additional_page']['id']."';")); |
---|
133 | }else{ |
---|
134 | $metaog = pwg_db_fetch_assoc(pwg_query("SELECT * FROM " . METAOG_TABLE . " WHERE type =1 AND page = '".$page['section']."';")); |
---|
135 | } |
---|
136 | if(empty($metaog)){ |
---|
137 | $metaog['metaogtitle']=''; |
---|
138 | $metaog['metaogdescription']=''; |
---|
139 | $metaog['metaogimage']=''; |
---|
140 | } |
---|
141 | if(!empty($metaog['metaogimage'])){ |
---|
142 | $images = pwg_db_fetch_assoc(pwg_query("SELECT id,path FROM " . IMAGES_TABLE . " WHERE id = '".$metaog['metaogimage']."';")); |
---|
143 | $metaog['metaogimage']=PWG_DERIVATIVE_DIR.substr($images['path'], 2, -4)."-".$conf['mogsize'].substr($images['path'],-4); |
---|
144 | if (file_exists($metaog['metaogimage']) AND $conf['mogsize']!='original'){ |
---|
145 | $metaog['metaogimage']=get_absolute_root_url().PWG_DERIVATIVE_DIR.substr($images['path'], 2, -4)."-".$conf['mogsize'].substr($images['path'],-4); |
---|
146 | }else{ |
---|
147 | $metaog['metaogimage']=get_absolute_root_url().substr($images['path'],2); |
---|
148 | } |
---|
149 | } |
---|
150 | $metaog['type']="website"; |
---|
151 | }else if(script_basename() == 'tags' ||script_basename() == 'comments'||script_basename() == 'about'||script_basename() == 'search'||script_basename() == 'notification'){ |
---|
152 | $metaog = pwg_db_fetch_assoc(pwg_query("SELECT * FROM " . METAOG_TABLE . " WHERE type = 1 AND page = '".script_basename()."';")); |
---|
153 | if(empty($metaog)){ |
---|
154 | $metaog['metaogtitle']=''; |
---|
155 | $metaog['metaogdescription']=''; |
---|
156 | $metaog['metaogimage']=''; |
---|
157 | } |
---|
158 | |
---|
159 | if(!empty($metaog['metaogimage']) AND $conf['mogsize']!='original'){ |
---|
160 | $images = pwg_db_fetch_assoc(pwg_query("SELECT id,path FROM " . IMAGES_TABLE . " WHERE id = '".$metaog['metaogimage']."';")); |
---|
161 | $metaog['metaogimage']=PWG_DERIVATIVE_DIR.substr($images['path'], 2, -4)."-".$conf['mogsize'].substr($images['path'],-4); |
---|
162 | if (file_exists($metaog['metaogimage'])){ |
---|
163 | $metaog['metaogimage']=get_absolute_root_url().PWG_DERIVATIVE_DIR.substr($images['path'], 2, -4)."-".$conf['mogsize'].substr($images['path'],-4); |
---|
164 | }else{ |
---|
165 | $metaog['metaogimage']=get_absolute_root_url().substr($images['path'],2); |
---|
166 | } |
---|
167 | } |
---|
168 | $metaog['type']="website"; |
---|
169 | }else{ |
---|
170 | $metaog['type']="website"; |
---|
171 | $metaog['metaogtitle']=$template->get_template_vars('PAGE_TITLE'); |
---|
172 | $metaog['metaogdescription']=$template->get_template_vars('INFO_FILE'); |
---|
173 | } |
---|
174 | |
---|
175 | |
---|
176 | if (isset($pwg_loaded_plugins['ExtendedDescription'])){ |
---|
177 | add_event_handler('AP_render_content', 'get_user_language_desc'); |
---|
178 | } |
---|
179 | // og:url |
---|
180 | if (!empty($metaogurl)) { |
---|
181 | $template->append('head_elements', '<meta property="og:url" content="' . $metaogurl . '">'); |
---|
182 | } |
---|
183 | // og:type |
---|
184 | if (!empty($metaog['type'])) { |
---|
185 | $template->append('head_elements', '<meta property="og:type" content="' . $metaog['type'] . '">'); |
---|
186 | } |
---|
187 | |
---|
188 | // og:title |
---|
189 | if (!empty($metaog['metaogtitle'])) { |
---|
190 | $template->append('head_elements', '<meta property="og:title" content="' . trigger_change('AP_render_content', $metaog['metaogtitle']) . '">'); |
---|
191 | } |
---|
192 | |
---|
193 | // og:description |
---|
194 | if (!empty($metaog['metaogdescription'])) { |
---|
195 | $template->append('head_elements', '<meta property="og:description" content="' . trigger_change('AP_render_content', $metaog['metaogdescription']) . '">'); |
---|
196 | } |
---|
197 | |
---|
198 | // og:image |
---|
199 | if (!empty($metaog['metaogimage'])) { |
---|
200 | $metaog['metaogimagetype']=substr($metaog['metaogimage'],-3); |
---|
201 | if($metaog['metaogimagetype']=='jpg'){$metaog['metaogimagetype']='jpeg';} |
---|
202 | $template->append('head_elements', '<meta property="og:image" content="' . $metaog['metaogimage'] . '">'); |
---|
203 | $template->append('head_elements', '<meta property="og:image:type" content="image/' . $metaog['metaogimagetype'] . '">'); |
---|
204 | } |
---|
205 | |
---|
206 | // og:app_id |
---|
207 | if (!empty($conf['fb:app_id'])) { |
---|
208 | $template->append('head_elements', '<meta property="fb:app_id" content="' . $conf['fb:app_id'] . '">'); |
---|
209 | } |
---|
210 | // og:local |
---|
211 | if (!empty($conf['moglocal'])) { |
---|
212 | $template->append('head_elements', '<meta property="og:locale" content="' . $conf['moglocal'] . '">'); |
---|
213 | } |
---|
214 | |
---|
215 | // og:site_name |
---|
216 | if (!empty($conf['mogsitename'])) { |
---|
217 | $template->append('head_elements', '<meta property="og:site_name" content="' . $conf['mogsitename'] . '">'); |
---|
218 | } |
---|
219 | |
---|
220 | // twitter:card |
---|
221 | if (!empty($conf['mogtwcard'])) { |
---|
222 | $template->append('head_elements', '<meta property="twitter:card" content="' . $conf['mogtwcard'] . '">'); |
---|
223 | } |
---|
224 | |
---|
225 | // twitter:site |
---|
226 | if (!empty($conf['mogtwsite'])) { |
---|
227 | $template->append('head_elements', '<meta property="twitter:site" content="' . $conf['mogtwsite'] . '">'); |
---|
228 | } |
---|
229 | |
---|
230 | // twitter:creator |
---|
231 | if (!empty($conf['mogtwcreator'])) { |
---|
232 | $template->append('head_elements', '<meta property="twitter:creator" content="' . $conf['mogtwcreator'] . '">'); |
---|
233 | } |
---|
234 | } |
---|
235 | ?> |
---|