[3978] | 1 | <?php |
---|
| 2 | /* |
---|
| 3 | Plugin Name: meta |
---|
[7468] | 4 | Version: auto |
---|
[3978] | 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!'); |
---|
| 12 | |
---|
[24393] | 13 | global $prefixeTable, $page; |
---|
[3978] | 14 | |
---|
| 15 | define('meta_DIR' , basename(dirname(__FILE__))); |
---|
| 16 | define('meta_PATH' , PHPWG_PLUGINS_PATH . meta_DIR . '/'); |
---|
| 17 | define('meta_TABLE' , $prefixeTable . 'meta'); |
---|
[4174] | 18 | define('meta_img_TABLE' , $prefixeTable . 'meta_img'); |
---|
| 19 | define('meta_cat_TABLE' , $prefixeTable . 'meta_cat'); |
---|
[22769] | 20 | define('METAPERSO_TABLE', $prefixeTable.'metaperso'); |
---|
[24393] | 21 | define('META_AP_TABLE', $prefixeTable.'meta_ap'); |
---|
[3978] | 22 | |
---|
[9406] | 23 | // Plugin for admin |
---|
| 24 | if (script_basename() == 'admin') |
---|
[3978] | 25 | { |
---|
[9406] | 26 | include_once(dirname(__FILE__).'/initadmin.php'); |
---|
[3978] | 27 | } |
---|
| 28 | |
---|
[9406] | 29 | |
---|
[3978] | 30 | //Gestion des meta dans le header |
---|
[7624] | 31 | add_event_handler('loc_begin_page_header', 'Change_Meta',20 ); |
---|
| 32 | add_event_handler('loc_end_page_header', 'add_meta',56 ); |
---|
[7636] | 33 | add_event_handler('loc_end_page_header', 'add_metacat',61 ); |
---|
| 34 | add_event_handler('loc_end_page_header', 'add_metaimg',71 ); |
---|
[7651] | 35 | add_event_handler('loc_after_page_header', 'set_meta_back'); |
---|
[7518] | 36 | |
---|
[7624] | 37 | function Change_Meta() |
---|
| 38 | { |
---|
| 39 | global $template; |
---|
| 40 | $template->set_prefilter('header', 'upmata'); |
---|
[9406] | 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'); |
---|
[7624] | 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 | |
---|
[3978] | 57 | function add_meta() |
---|
| 58 | { |
---|
[7518] | 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'); |
---|
[7624] | 64 | $meta_infos['title'] = $template->get_template_vars('PAGE_TITLE'); |
---|
[3978] | 65 | |
---|
[7518] | 66 | $query = ' |
---|
[3978] | 67 | select id,metaname,metaval |
---|
| 68 | FROM ' . meta_TABLE . ' |
---|
| 69 | WHERE metaname IN (\'author\', \'keywords\', \'Description\', \'robots\') |
---|
| 70 | ;'; |
---|
[7518] | 71 | $result = pwg_query($query); |
---|
| 72 | $meta = array(); |
---|
[21161] | 73 | while ($row = pwg_db_fetch_assoc($result)) |
---|
[7518] | 74 | { |
---|
| 75 | $meta[$row['metaname']] = $row['metaval']; |
---|
[9406] | 76 | $metaED[$row['metaname']]=trigger_event('AP_render_content', $meta[$row['metaname']]); |
---|
[7518] | 77 | } |
---|
[3978] | 78 | |
---|
[7518] | 79 | // Authors |
---|
[9406] | 80 | if (!empty($meta_infos['author']) and !empty($metaED['author'])) |
---|
[7518] | 81 | { |
---|
[9406] | 82 | $template->assign('INFO_AUTHOR', $meta_infos['author'] . ' - ' . $metaED['author']); |
---|
[7518] | 83 | } |
---|
[9406] | 84 | elseif (!empty($metaED['author'])) |
---|
[7518] | 85 | { |
---|
[9406] | 86 | $template->assign('INFO_AUTHOR', $metaED['author']); |
---|
[7518] | 87 | } |
---|
[3978] | 88 | |
---|
[7518] | 89 | // Keywords |
---|
[9406] | 90 | if (!empty($metaED['keywords'])) |
---|
[7518] | 91 | { |
---|
[9406] | 92 | $template->append('related_tags', array('name' => $metaED['keywords'])); |
---|
[7518] | 93 | } |
---|
[3978] | 94 | |
---|
[7518] | 95 | // Description |
---|
[9406] | 96 | if (!empty($meta_infos['title']) and !empty($meta_infos['info']) and !empty($metaED['Description'])) |
---|
[7518] | 97 | { |
---|
[9406] | 98 | $template->assign('PLUG_META', $meta_infos['title']. ' - ' .$meta_infos['info'] . ', ' . $metaED['Description']); |
---|
[7518] | 99 | } |
---|
[9406] | 100 | elseif (!empty($meta_infos['title']) and !empty($metaED['Description'])) |
---|
[7624] | 101 | { |
---|
[9406] | 102 | $template->assign('PLUG_META', $meta_infos['title']. ' - ' .$metaED['Description']); |
---|
[7624] | 103 | } |
---|
[9406] | 104 | elseif (!empty($metaED['Description'])) |
---|
[7518] | 105 | { |
---|
[9406] | 106 | $template->assign('PLUG_META', $metaED['Description']); |
---|
[7518] | 107 | } |
---|
[7624] | 108 | |
---|
[7518] | 109 | // Robots |
---|
| 110 | if (!empty($meta['robots'])) |
---|
| 111 | { |
---|
[3978] | 112 | $template->append('head_elements', '<meta name="robots" content="'.$meta['robots'].'">'); |
---|
[7518] | 113 | } |
---|
[22769] | 114 | |
---|
| 115 | //Metaperso |
---|
| 116 | if (script_basename() !== 'admin') |
---|
| 117 | { |
---|
| 118 | $metapersos = pwg_query("SELECT * FROM `". METAPERSO_TABLE .";"); |
---|
[3978] | 119 | |
---|
[22769] | 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 | } |
---|
[24393] | 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') |
---|
| 142 | { |
---|
| 143 | $metacontact = explode(',', $conf['contactmeta']); |
---|
| 144 | $metakeyED=trigger_event('AP_render_content', $metacontact[0]); |
---|
| 145 | $metadesED=trigger_event('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 | } |
---|
[22769] | 156 | |
---|
[24393] | 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']) ) |
---|
[24394] | 161 | { |
---|
[24393] | 162 | $lire=$page['additional_page']['id']; |
---|
| 163 | $query = ' |
---|
| 164 | select id, metaKeyap, metadesap |
---|
| 165 | FROM ' . META_AP_TABLE . ' |
---|
| 166 | WHERE id = \''.$lire.'\' |
---|
| 167 | ;'; |
---|
| 168 | $result = pwg_query($query); |
---|
| 169 | $row = pwg_db_fetch_assoc($result); |
---|
| 170 | $metaKeyapap=$row['metaKeyap']; |
---|
| 171 | $metadesapap=$row['metadesap']; |
---|
| 172 | $metaKeyapapED=trigger_event('AP_render_content', $metaKeyapap); |
---|
| 173 | $metadesapED=trigger_event('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 | |
---|
[7518] | 189 | } |
---|
| 190 | function add_metacat() |
---|
| 191 | { |
---|
| 192 | global $template, $page, $meta_infos; |
---|
| 193 | |
---|
| 194 | //meta categories |
---|
[4174] | 195 | if ( !empty($page['category']['id']) ) |
---|
[3978] | 196 | { |
---|
| 197 | $query = ' |
---|
[4174] | 198 | select id,metaKeycat |
---|
| 199 | FROM ' . meta_cat_TABLE . ' |
---|
[3978] | 200 | WHERE id = \''.$page['category']['id'].'\' |
---|
| 201 | ;'; |
---|
| 202 | $result = pwg_query($query); |
---|
[21161] | 203 | $row = pwg_db_fetch_assoc($result); |
---|
[9406] | 204 | $albumKeyED=trigger_event('AP_render_content', $row['metaKeycat']); |
---|
[4174] | 205 | if (!empty($row['metaKeycat'])) |
---|
[3978] | 206 | { |
---|
[9406] | 207 | $template->append('related_tags', array('name' => $albumKeyED)); |
---|
[3978] | 208 | } |
---|
[7468] | 209 | |
---|
| 210 | $query = ' |
---|
| 211 | select id,metadescat |
---|
| 212 | FROM ' . meta_cat_TABLE . ' |
---|
| 213 | WHERE id = \''.$page['category']['id'].'\' |
---|
| 214 | ;'; |
---|
| 215 | $result = pwg_query($query); |
---|
[21161] | 216 | $row = pwg_db_fetch_assoc($result); |
---|
[9406] | 217 | $albumDesED=trigger_event('AP_render_content', $row['metadescat']); |
---|
[7468] | 218 | if (!empty($row['metadescat'])) |
---|
| 219 | { |
---|
[9406] | 220 | $template->assign('PLUG_META', $albumDesED); |
---|
[7468] | 221 | } |
---|
[3978] | 222 | } |
---|
[7518] | 223 | } |
---|
[4174] | 224 | |
---|
[7518] | 225 | function add_metaimg() |
---|
| 226 | { |
---|
| 227 | global $template, $page, $meta_infos; |
---|
[7624] | 228 | |
---|
[4174] | 229 | //meta images |
---|
| 230 | if ( !empty($page['image_id']) ) |
---|
| 231 | { |
---|
| 232 | $query = ' |
---|
| 233 | select id,metaKeyimg |
---|
| 234 | FROM ' . meta_img_TABLE . ' |
---|
| 235 | WHERE id = \''.$page['image_id'].'\' |
---|
| 236 | ;'; |
---|
| 237 | $result = pwg_query($query); |
---|
[21161] | 238 | $row = pwg_db_fetch_assoc($result); |
---|
[9406] | 239 | $photoKeyED=trigger_event('AP_render_content', $row['metaKeyimg']); |
---|
[4174] | 240 | if (!empty($row['metaKeyimg'])) |
---|
| 241 | { |
---|
[9406] | 242 | $template->append('related_tags', array('name' => $photoKeyED)); |
---|
[4174] | 243 | } |
---|
[7468] | 244 | |
---|
| 245 | $query = ' |
---|
| 246 | select id,metadesimg |
---|
| 247 | FROM ' . meta_img_TABLE . ' |
---|
| 248 | WHERE id = \''.$page['image_id'].'\' |
---|
| 249 | ;'; |
---|
| 250 | $result = pwg_query($query); |
---|
[21161] | 251 | $row = pwg_db_fetch_assoc($result); |
---|
[9406] | 252 | $photoDesED=trigger_event('AP_render_content', $row['metadesimg']); |
---|
[7468] | 253 | if (!empty($row['metadesimg'])) |
---|
| 254 | { |
---|
[9406] | 255 | $template->assign('PLUG_META', $photoDesED); |
---|
[7468] | 256 | } |
---|
| 257 | |
---|
[4174] | 258 | } |
---|
[3978] | 259 | } |
---|
| 260 | |
---|
| 261 | function set_meta_back() |
---|
| 262 | { |
---|
| 263 | global $template, $meta_infos; |
---|
| 264 | |
---|
[7518] | 265 | $template->assign |
---|
| 266 | (array |
---|
| 267 | ( |
---|
[3978] | 268 | 'INFO_AUTHOR' => $meta_infos['author'], |
---|
| 269 | 'related_tags' => $meta_infos['related_tags'], |
---|
[7518] | 270 | 'INFO_FILE' => $meta_infos['info'], |
---|
[3978] | 271 | ) |
---|
| 272 | ); |
---|
| 273 | } |
---|
| 274 | ?> |
---|