Changeset 29125 for extensions/meta
- Timestamp:
- Jul 30, 2014, 10:05:53 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/meta/main.inc.php
r28916 r29125 1 1 <?php 2 2 /* 3 Plugin Name: meta 4 Version: auto 5 Description: Allows to add metadata 6 Plugin URI: http://piwigo.org/ext/extension_view.php?eid=220 7 Author: ddtddt 8 Author URI: http://piwigo.org/ 9 */ 10 11 if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); 3 Plugin Name: meta 4 Version: auto 5 Description: Allows to add metadata 6 Plugin URI: http://piwigo.org/ext/extension_view.php?eid=220 7 Author: ddtddt 8 Author URI: http://piwigo.org/ 9 */ 10 11 if (!defined('PHPWG_ROOT_PATH')) 12 die('Hacking attempt!'); 12 13 13 14 global $prefixeTable, $page; 14 15 15 define('meta_DIR' , basename(dirname(__FILE__))); 16 define('meta_PATH' , PHPWG_PLUGINS_PATH . meta_DIR . '/'); 17 define('meta_TABLE' , $prefixeTable . 'meta'); 18 define('meta_img_TABLE' , $prefixeTable . 'meta_img'); 19 define('meta_cat_TABLE' , $prefixeTable . 'meta_cat'); 20 define('METAPERSO_TABLE', $prefixeTable.'metaperso'); 21 define('META_AP_TABLE', $prefixeTable.'meta_ap'); 22 23 // Plugin for admin 24 if (script_basename() == 'admin') 25 { 26 include_once(dirname(__FILE__).'/initadmin.php'); 16 define('meta_DIR', basename(dirname(__FILE__))); 17 define('meta_PATH', PHPWG_PLUGINS_PATH . meta_DIR . '/'); 18 define('meta_TABLE', $prefixeTable . 'meta'); 19 define('meta_img_TABLE', $prefixeTable . 'meta_img'); 20 define('meta_cat_TABLE', $prefixeTable . 'meta_cat'); 21 define('METAPERSO_TABLE', $prefixeTable . 'metaperso'); 22 define('META_AP_TABLE', $prefixeTable . 'meta_ap'); 23 24 // Plugin for admin 25 if (script_basename() == 'admin') { 26 include_once(dirname(__FILE__) . '/initadmin.php'); 27 27 } 28 28 29 29 30 30 //Gestion des meta dans le header 31 add_event_handler('loc_begin_page_header', 'Change_Meta', 20);32 add_event_handler('loc_end_page_header', 'add_meta', 56);33 add_event_handler('loc_end_page_header', 'add_metacat', 61);34 add_event_handler('loc_end_page_header', 'add_metaimg', 71);31 add_event_handler('loc_begin_page_header', 'Change_Meta', 20); 32 add_event_handler('loc_end_page_header', 'add_meta', 56); 33 add_event_handler('loc_end_page_header', 'add_metacat', 61); 34 add_event_handler('loc_end_page_header', 'add_metaimg', 71); 35 35 add_event_handler('loc_after_page_header', 'set_meta_back'); 36 36 37 function Change_Meta() 38 { 39 global $template; 40 $template->set_prefilter('header', 'upmata'); 41 42 $PAED = pwg_db_fetch_assoc(pwg_query("SELECT state FROM " . PLUGINS_TABLE . " WHERE id = 'ExtendedDescription';")); 43 if($PAED['state'] == 'active') add_event_handler('AP_render_content', 'get_user_language_desc'); 44 } 45 46 function upmata ($content, &$smarty) 47 { 48 $search = '#<meta name="description" content=".*?">#'; 49 50 $replacement = '<meta name="description" content="{$PLUG_META}">'; 51 52 return preg_replace($search, $replacement, $content); 53 } 54 55 56 57 function add_meta() 58 { 59 global $template, $page, $meta_infos; 60 $meta_infos = array(); 61 $meta_infos['author'] = $template->get_template_vars('INFO_AUTHOR'); 62 $meta_infos['related_tags'] = $template->get_template_vars('related_tags'); 63 $meta_infos['info'] = $template->get_template_vars('INFO_FILE'); 64 $meta_infos['title'] = $template->get_template_vars('PAGE_TITLE'); 65 66 $query = ' 37 function Change_Meta() { 38 global $template; 39 $template->set_prefilter('header', 'upmata'); 40 41 $PAED = pwg_db_fetch_assoc(pwg_query("SELECT state FROM " . PLUGINS_TABLE . " WHERE id = 'ExtendedDescription';")); 42 if ($PAED['state'] == 'active') 43 add_event_handler('AP_render_content', 'get_user_language_desc'); 44 } 45 46 function upmata($content, &$smarty) { 47 $search = '#<meta name="description" content=".*?">#'; 48 49 $replacement = '<meta name="description" content="{$PLUG_META}">'; 50 51 return preg_replace($search, $replacement, $content); 52 } 53 54 function add_meta() { 55 global $template, $page, $meta_infos; 56 $meta_infos = array(); 57 $meta_infos['author'] = $template->get_template_vars('INFO_AUTHOR'); 58 $meta_infos['related_tags'] = $template->get_template_vars('related_tags'); 59 $meta_infos['info'] = $template->get_template_vars('INFO_FILE'); 60 $meta_infos['title'] = $template->get_template_vars('PAGE_TITLE'); 61 62 $query = ' 67 63 select id,metaname,metaval 68 64 FROM ' . meta_TABLE . ' 69 65 WHERE metaname IN (\'author\', \'keywords\', \'Description\', \'robots\') 70 66 ;'; 71 $result = pwg_query($query); 72 $meta = array(); 73 while ($row = pwg_db_fetch_assoc($result)) 74 { 75 $meta[$row['metaname']] = $row['metaval']; 76 $metaED[$row['metaname']]=trigger_change('AP_render_content', $meta[$row['metaname']]); 77 } 78 79 // Authors 80 if (!empty($meta_infos['author']) and !empty($metaED['author'])) 81 { 82 $template->assign('INFO_AUTHOR', $meta_infos['author'] . ' - ' . $metaED['author']); 83 } 84 elseif (!empty($metaED['author'])) 85 { 86 $template->assign('INFO_AUTHOR', $metaED['author']); 87 } 88 89 // Keywords 90 if (!empty($metaED['keywords'])) 91 { 92 $template->append('related_tags', array('name' => $metaED['keywords'])); 93 } 94 95 // Description 96 if (!empty($meta_infos['title']) and !empty($meta_infos['info']) and !empty($metaED['Description'])) 97 { 98 $template->assign('PLUG_META', $meta_infos['title']. ' - ' .$meta_infos['info'] . ', ' . $metaED['Description']); 99 } 100 elseif (!empty($meta_infos['title']) and !empty($metaED['Description'])) 101 { 102 $template->assign('PLUG_META', $meta_infos['title']. ' - ' .$metaED['Description']); 103 } 104 elseif (!empty($metaED['Description'])) 105 { 106 $template->assign('PLUG_META', $metaED['Description']); 107 } 108 109 // Robots 110 if (!empty($meta['robots'])) 111 { 112 $template->append('head_elements', '<meta name="robots" content="'.$meta['robots'].'">'); 113 } 114 115 //Metaperso 116 if (script_basename() !== 'admin') 117 { 118 $metapersos = pwg_query("SELECT * FROM `". METAPERSO_TABLE .";"); 119 120 if (pwg_db_num_rows($metapersos)) { 121 while ($metaperso = pwg_db_fetch_assoc($metapersos)) 122 { 123 $items = array( 124 'METANAME' => $metaperso['metaname'], 125 'METAVAL' => $metaperso['metaval'], 126 'METATYPE' => $metaperso['metatype'] 127 ); 128 129 $template->append('metapersos', $items); 130 } 131 } 132 133 $template->set_filename('PERSO_META', realpath(meta_PATH.'persometa.tpl')); 134 $template->append('head_elements', $template->parse('PERSO_META', true)); 135 } 136 137 $MPC = pwg_db_fetch_assoc(pwg_query("SELECT state FROM " . PLUGINS_TABLE . " WHERE id = 'ContactForm';")); 138 if($MPC['state'] == 'active') 139 { 140 global $conf; 141 if (isset($page['section']) and $page['section'] == 'contact' and isset($conf['contactmeta']) and strpos($conf['contactmeta'], ',') !== false) 142 { 143 $metacontact = explode(',', $conf['contactmeta']); 144 $metakeyED=trigger_change('AP_render_content', $metacontact[0]); 145 $metadesED=trigger_change('AP_render_content', $metacontact[1]); 146 if (!empty($metakeyED)) 147 { 148 $template->append('related_tags', array('name' => $metakeyED)); 149 } 150 if (!empty($metadesED)) 151 { 152 $template->assign('PLUG_META', $metadesED); 153 } 154 } 155 } 156 157 $MAP = pwg_db_fetch_assoc(pwg_query("SELECT state FROM " . PLUGINS_TABLE . " WHERE id = 'AdditionalPages';")); 158 if($MAP['state'] == 'active') 159 { 160 if ( !empty($page['additional_page']['id']) ) 161 { 162 $lire=$page['additional_page']['id']; 163 $query = ' 67 $result = pwg_query($query); 68 $meta = array(); 69 while ($row = pwg_db_fetch_assoc($result)) { 70 $meta[$row['metaname']] = $row['metaval']; 71 $metaED[$row['metaname']] = trigger_change('AP_render_content', $meta[$row['metaname']]); 72 } 73 74 // Authors 75 if (!empty($meta_infos['author']) and ! empty($metaED['author'])) { 76 $template->assign('INFO_AUTHOR', $meta_infos['author'] . ' - ' . $metaED['author']); 77 } elseif (!empty($metaED['author'])) { 78 $template->assign('INFO_AUTHOR', $metaED['author']); 79 } 80 81 // Keywords 82 if (!empty($metaED['keywords'])) { 83 $template->append('related_tags', array('name' => $metaED['keywords'])); 84 } 85 86 // Description 87 if (!empty($meta_infos['title']) and ! empty($meta_infos['info']) and ! empty($metaED['Description'])) { 88 $template->assign('PLUG_META', $meta_infos['title'] . ' - ' . $meta_infos['info'] . ', ' . $metaED['Description']); 89 } elseif (!empty($meta_infos['title']) and ! empty($metaED['Description'])) { 90 $template->assign('PLUG_META', $meta_infos['title'] . ' - ' . $metaED['Description']); 91 } elseif (!empty($metaED['Description'])) { 92 $template->assign('PLUG_META', $metaED['Description']); 93 } 94 95 // Robots 96 if (!empty($meta['robots'])) { 97 $template->append('head_elements', '<meta name="robots" content="' . $meta['robots'] . '">'); 98 } 99 100 //Metaperso 101 if (script_basename() !== 'admin') { 102 $metapersos = pwg_query("SELECT * FROM `" . METAPERSO_TABLE . ";"); 103 104 if (pwg_db_num_rows($metapersos)) { 105 while ($metaperso = pwg_db_fetch_assoc($metapersos)) { 106 $items = array( 107 'METANAME' => $metaperso['metaname'], 108 'METAVAL' => $metaperso['metaval'], 109 'METATYPE' => $metaperso['metatype'] 110 ); 111 112 $template->append('metapersos', $items); 113 } 114 } 115 116 $template->set_filename('PERSO_META', realpath(meta_PATH . 'persometa.tpl')); 117 $template->append('head_elements', $template->parse('PERSO_META', true)); 118 } 119 120 $MPC = pwg_db_fetch_assoc(pwg_query("SELECT state FROM " . PLUGINS_TABLE . " WHERE id = 'ContactForm';")); 121 if ($MPC['state'] == 'active') { 122 global $conf; 123 if (isset($page['section']) and $page['section'] == 'contact' and isset($conf['contactmeta']) and strpos($conf['contactmeta'], ',') !== false) { 124 $metacontact = explode(',', $conf['contactmeta']); 125 $metakeyED = trigger_change('AP_render_content', $metacontact[0]); 126 $metadesED = trigger_change('AP_render_content', $metacontact[1]); 127 if (!empty($metakeyED)) { 128 $template->append('related_tags', array('name' => $metakeyED)); 129 } 130 if (!empty($metadesED)) { 131 $template->assign('PLUG_META', $metadesED); 132 } 133 } 134 } 135 136 $MAP = pwg_db_fetch_assoc(pwg_query("SELECT state FROM " . PLUGINS_TABLE . " WHERE id = 'AdditionalPages';")); 137 if ($MAP['state'] == 'active') { 138 if (!empty($page['additional_page']['id'])) { 139 $lire = $page['additional_page']['id']; 140 $query = ' 164 141 select id, metaKeyap, metadesap 165 142 FROM ' . META_AP_TABLE . ' 166 WHERE id = \'' .$lire.'\'143 WHERE id = \'' . $lire . '\' 167 144 ;'; 168 $result = pwg_query($query); 169 $row = pwg_db_fetch_assoc($result); 170 $metaKeyapap=$row['metaKeyap']; 171 $metadesapap=$row['metadesap']; 172 $metaKeyapapED=trigger_change('AP_render_content', $metaKeyapap); 173 $metadesapED=trigger_change('AP_render_content', $metadesapap); 174 } 175 if (isset($page['section']) and $page['section'] == 'additional_page') 176 { 177 if (!empty($metaKeyapapED)) 178 { 179 $template->append('related_tags', array('name' => $metaKeyapapED)); 180 } 181 if (!empty($metadesapED)) 182 { 183 $template->assign('PLUG_META', $metadesapED); 184 } 185 } 186 } 187 188 189 } 190 function add_metacat() 191 { 192 global $template, $page, $meta_infos; 193 194 //meta categories 195 if ( !empty($page['category']['id']) ) 196 { 197 $query = ' 145 $result = pwg_query($query); 146 $row = pwg_db_fetch_assoc($result); 147 $metaKeyapap = $row['metaKeyap']; 148 $metadesapap = $row['metadesap']; 149 $metaKeyapapED = trigger_change('AP_render_content', $metaKeyapap); 150 $metadesapED = trigger_change('AP_render_content', $metadesapap); 151 } 152 if (isset($page['section']) and $page['section'] == 'additional_page') { 153 if (!empty($metaKeyapapED)) { 154 $template->append('related_tags', array('name' => $metaKeyapapED)); 155 } 156 if (!empty($metadesapED)) { 157 $template->assign('PLUG_META', $metadesapED); 158 } 159 } 160 } 161 } 162 163 function add_metacat() { 164 global $template, $page, $meta_infos; 165 166 //meta categories 167 if (!empty($page['category']['id'])) { 168 $query = ' 198 169 select id,metaKeycat 199 170 FROM ' . meta_cat_TABLE . ' 200 WHERE id = \''.$page['category']['id'].'\' 201 ;'; 202 $result = pwg_query($query); 203 $row = pwg_db_fetch_assoc($result); 204 $albumKeyED=trigger_change('AP_render_content', $row['metaKeycat']); 205 if (!empty($row['metaKeycat'])) 206 { 207 $template->append('related_tags', array('name' => $albumKeyED)); 208 } 209 210 $query = ' 171 WHERE id = \'' . $page['category']['id'] . '\' 172 ;'; 173 $result = pwg_query($query); 174 $row = pwg_db_fetch_assoc($result); 175 $albumKeyED = trigger_change('AP_render_content', $row['metaKeycat']); 176 if (!empty($row['metaKeycat'])) { 177 $template->append('related_tags', array('name' => $albumKeyED)); 178 } 179 180 $query = ' 211 181 select id,metadescat 212 182 FROM ' . meta_cat_TABLE . ' 213 WHERE id = \''.$page['category']['id'].'\' 214 ;'; 215 $result = pwg_query($query); 216 $row = pwg_db_fetch_assoc($result); 217 $albumDesED=trigger_change('AP_render_content', $row['metadescat']); 218 if (!empty($row['metadescat'])) 219 { 220 $template->assign('PLUG_META', $albumDesED); 221 } 222 } 223 } 224 225 function add_metaimg() 226 { 227 global $template, $page, $meta_infos; 228 229 //meta images 230 if ( !empty($page['image_id']) ) 231 { 232 $query = ' 183 WHERE id = \'' . $page['category']['id'] . '\' 184 ;'; 185 $result = pwg_query($query); 186 $row = pwg_db_fetch_assoc($result); 187 $albumDesED = trigger_change('AP_render_content', $row['metadescat']); 188 if (!empty($row['metadescat'])) { 189 $template->assign('PLUG_META', $albumDesED); 190 } 191 } 192 } 193 194 function add_metaimg() { 195 global $template, $page, $meta_infos; 196 197 //meta images 198 if (!empty($page['image_id'])) { 199 $query = ' 233 200 select id,metaKeyimg 234 201 FROM ' . meta_img_TABLE . ' 235 WHERE id = \''.$page['image_id'].'\' 236 ;'; 237 $result = pwg_query($query); 238 $row = pwg_db_fetch_assoc($result); 239 $photoKeyED=trigger_change('AP_render_content', $row['metaKeyimg']); 240 if (!empty($row['metaKeyimg'])) 241 { 242 $template->append('related_tags', array('name' => $photoKeyED)); 243 } 244 245 $query = ' 202 WHERE id = \'' . $page['image_id'] . '\' 203 ;'; 204 $result = pwg_query($query); 205 $row = pwg_db_fetch_assoc($result); 206 $photoKeyED = trigger_change('AP_render_content', $row['metaKeyimg']); 207 if (!empty($row['metaKeyimg'])) { 208 $template->append('related_tags', array('name' => $photoKeyED)); 209 } 210 211 $query = ' 246 212 select id,metadesimg 247 213 FROM ' . meta_img_TABLE . ' 248 WHERE id = \''.$page['image_id'].'\' 249 ;'; 250 $result = pwg_query($query); 251 $row = pwg_db_fetch_assoc($result); 252 $photoDesED=trigger_change('AP_render_content', $row['metadesimg']); 253 if (!empty($row['metadesimg'])) 254 { 255 $template->assign('PLUG_META', $photoDesED); 256 } 257 258 } 259 } 260 261 function set_meta_back() 262 { 263 global $template, $meta_infos; 264 265 $template->assign 266 (array 267 ( 268 'INFO_AUTHOR' => $meta_infos['author'], 269 'related_tags' => $meta_infos['related_tags'], 270 'INFO_FILE' => $meta_infos['info'], 271 ) 272 ); 273 } 214 WHERE id = \'' . $page['image_id'] . '\' 215 ;'; 216 $result = pwg_query($query); 217 $row = pwg_db_fetch_assoc($result); 218 $photoDesED = trigger_change('AP_render_content', $row['metadesimg']); 219 if (!empty($row['metadesimg'])) { 220 $template->assign('PLUG_META', $photoDesED); 221 }else { 222 $meta_infosph = array(); 223 $meta_infosph['title'] = $template->get_template_vars('PAGE_TITLE'); 224 $meta_infosph['gt'] = $template->get_template_vars('GALLERY_TITLE'); 225 $meta_infosph['descimg'] = $template->get_template_vars('COMMENT_IMG'); 226 if (!empty($meta_infosph['descimg'])) { 227 $template->assign('PLUG_META', strip_tags($meta_infosph['descimg']).' - '.$meta_infosph['title']); 228 }else{ 229 $template->assign('PLUG_META', $meta_infosph['title'].' - '.$meta_infosph['gt']); 230 } 231 } 232 } 233 } 234 235 function set_meta_back() { 236 global $template, $meta_infos; 237 238 $template->assign 239 (array 240 ( 241 'INFO_AUTHOR' => $meta_infos['author'], 242 'related_tags' => $meta_infos['related_tags'], 243 'INFO_FILE' => $meta_infos['info'], 244 ) 245 ); 246 } 247 274 248 ?>
Note: See TracChangeset
for help on using the changeset viewer.