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