[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 | |
---|
| 13 | global $prefixeTable; |
---|
| 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'); |
---|
[3978] | 20 | |
---|
[9406] | 21 | // Plugin for admin |
---|
| 22 | if (script_basename() == 'admin') |
---|
[3978] | 23 | { |
---|
[9406] | 24 | include_once(dirname(__FILE__).'/initadmin.php'); |
---|
[3978] | 25 | } |
---|
| 26 | |
---|
[9406] | 27 | |
---|
[3978] | 28 | //Gestion des meta dans le header |
---|
[7624] | 29 | add_event_handler('loc_begin_page_header', 'Change_Meta',20 ); |
---|
| 30 | add_event_handler('loc_end_page_header', 'add_meta',56 ); |
---|
[7636] | 31 | add_event_handler('loc_end_page_header', 'add_metacat',61 ); |
---|
| 32 | add_event_handler('loc_end_page_header', 'add_metaimg',71 ); |
---|
[7651] | 33 | add_event_handler('loc_after_page_header', 'set_meta_back'); |
---|
[7518] | 34 | |
---|
[7624] | 35 | function Change_Meta() |
---|
| 36 | { |
---|
| 37 | global $template; |
---|
| 38 | $template->set_prefilter('header', 'upmata'); |
---|
[9406] | 39 | |
---|
| 40 | $PAED = pwg_db_fetch_assoc(pwg_query("SELECT state FROM " . PLUGINS_TABLE . " WHERE id = 'ExtendedDescription';")); |
---|
| 41 | if($PAED['state'] == 'active') add_event_handler('AP_render_content', 'get_user_language_desc'); |
---|
[7624] | 42 | } |
---|
| 43 | |
---|
| 44 | function upmata ($content, &$smarty) |
---|
| 45 | { |
---|
| 46 | $search = '#<meta name="description" content=".*?">#'; |
---|
| 47 | |
---|
| 48 | $replacement = '<meta name="description" content="{$PLUG_META}">'; |
---|
| 49 | |
---|
| 50 | return preg_replace($search, $replacement, $content); |
---|
| 51 | } |
---|
| 52 | |
---|
| 53 | |
---|
| 54 | |
---|
[3978] | 55 | function add_meta() |
---|
| 56 | { |
---|
[7518] | 57 | global $template, $page, $meta_infos; |
---|
| 58 | $meta_infos = array(); |
---|
| 59 | $meta_infos['author'] = $template->get_template_vars('INFO_AUTHOR'); |
---|
| 60 | $meta_infos['related_tags'] = $template->get_template_vars('related_tags'); |
---|
| 61 | $meta_infos['info'] = $template->get_template_vars('INFO_FILE'); |
---|
[7624] | 62 | $meta_infos['title'] = $template->get_template_vars('PAGE_TITLE'); |
---|
[3978] | 63 | |
---|
[7518] | 64 | $query = ' |
---|
[3978] | 65 | select id,metaname,metaval |
---|
| 66 | FROM ' . meta_TABLE . ' |
---|
| 67 | WHERE metaname IN (\'author\', \'keywords\', \'Description\', \'robots\') |
---|
| 68 | ;'; |
---|
[7518] | 69 | $result = pwg_query($query); |
---|
| 70 | $meta = array(); |
---|
| 71 | while ($row = mysql_fetch_assoc($result)) |
---|
| 72 | { |
---|
| 73 | $meta[$row['metaname']] = $row['metaval']; |
---|
[9406] | 74 | $metaED[$row['metaname']]=trigger_event('AP_render_content', $meta[$row['metaname']]); |
---|
[7518] | 75 | } |
---|
[3978] | 76 | |
---|
[7518] | 77 | // Authors |
---|
[9406] | 78 | if (!empty($meta_infos['author']) and !empty($metaED['author'])) |
---|
[7518] | 79 | { |
---|
[9406] | 80 | $template->assign('INFO_AUTHOR', $meta_infos['author'] . ' - ' . $metaED['author']); |
---|
[7518] | 81 | } |
---|
[9406] | 82 | elseif (!empty($metaED['author'])) |
---|
[7518] | 83 | { |
---|
[9406] | 84 | $template->assign('INFO_AUTHOR', $metaED['author']); |
---|
[7518] | 85 | } |
---|
[3978] | 86 | |
---|
[7518] | 87 | // Keywords |
---|
[9406] | 88 | if (!empty($metaED['keywords'])) |
---|
[7518] | 89 | { |
---|
[9406] | 90 | $template->append('related_tags', array('name' => $metaED['keywords'])); |
---|
[7518] | 91 | } |
---|
[3978] | 92 | |
---|
[7518] | 93 | // Description |
---|
[9406] | 94 | if (!empty($meta_infos['title']) and !empty($meta_infos['info']) and !empty($metaED['Description'])) |
---|
[7518] | 95 | { |
---|
[9406] | 96 | $template->assign('PLUG_META', $meta_infos['title']. ' - ' .$meta_infos['info'] . ', ' . $metaED['Description']); |
---|
[7518] | 97 | } |
---|
[9406] | 98 | elseif (!empty($meta_infos['title']) and !empty($metaED['Description'])) |
---|
[7624] | 99 | { |
---|
[9406] | 100 | $template->assign('PLUG_META', $meta_infos['title']. ' - ' .$metaED['Description']); |
---|
[7624] | 101 | } |
---|
[9406] | 102 | elseif (!empty($metaED['Description'])) |
---|
[7518] | 103 | { |
---|
[9406] | 104 | $template->assign('PLUG_META', $metaED['Description']); |
---|
[7518] | 105 | } |
---|
[7624] | 106 | |
---|
[7518] | 107 | // Robots |
---|
| 108 | if (!empty($meta['robots'])) |
---|
| 109 | { |
---|
[3978] | 110 | $template->append('head_elements', '<meta name="robots" content="'.$meta['robots'].'">'); |
---|
[7518] | 111 | } |
---|
[3978] | 112 | |
---|
[7518] | 113 | } |
---|
| 114 | function add_metacat() |
---|
| 115 | { |
---|
| 116 | global $template, $page, $meta_infos; |
---|
| 117 | |
---|
| 118 | //meta categories |
---|
[4174] | 119 | if ( !empty($page['category']['id']) ) |
---|
[3978] | 120 | { |
---|
| 121 | $query = ' |
---|
[4174] | 122 | select id,metaKeycat |
---|
| 123 | FROM ' . meta_cat_TABLE . ' |
---|
[3978] | 124 | WHERE id = \''.$page['category']['id'].'\' |
---|
| 125 | ;'; |
---|
| 126 | $result = pwg_query($query); |
---|
| 127 | $row = mysql_fetch_array($result); |
---|
[9406] | 128 | $albumKeyED=trigger_event('AP_render_content', $row['metaKeycat']); |
---|
[4174] | 129 | if (!empty($row['metaKeycat'])) |
---|
[3978] | 130 | { |
---|
[9406] | 131 | $template->append('related_tags', array('name' => $albumKeyED)); |
---|
[3978] | 132 | } |
---|
[7468] | 133 | |
---|
| 134 | $query = ' |
---|
| 135 | select id,metadescat |
---|
| 136 | FROM ' . meta_cat_TABLE . ' |
---|
| 137 | WHERE id = \''.$page['category']['id'].'\' |
---|
| 138 | ;'; |
---|
| 139 | $result = pwg_query($query); |
---|
| 140 | $row = mysql_fetch_array($result); |
---|
[9406] | 141 | $albumDesED=trigger_event('AP_render_content', $row['metadescat']); |
---|
[7468] | 142 | if (!empty($row['metadescat'])) |
---|
| 143 | { |
---|
[9406] | 144 | $template->assign('PLUG_META', $albumDesED); |
---|
[7468] | 145 | } |
---|
[3978] | 146 | } |
---|
[7518] | 147 | } |
---|
[4174] | 148 | |
---|
[7518] | 149 | function add_metaimg() |
---|
| 150 | { |
---|
| 151 | global $template, $page, $meta_infos; |
---|
[7624] | 152 | |
---|
[4174] | 153 | //meta images |
---|
| 154 | if ( !empty($page['image_id']) ) |
---|
| 155 | { |
---|
| 156 | $query = ' |
---|
| 157 | select id,metaKeyimg |
---|
| 158 | FROM ' . meta_img_TABLE . ' |
---|
| 159 | WHERE id = \''.$page['image_id'].'\' |
---|
| 160 | ;'; |
---|
| 161 | $result = pwg_query($query); |
---|
| 162 | $row = mysql_fetch_array($result); |
---|
[9406] | 163 | $photoKeyED=trigger_event('AP_render_content', $row['metaKeyimg']); |
---|
[4174] | 164 | if (!empty($row['metaKeyimg'])) |
---|
| 165 | { |
---|
[9406] | 166 | $template->append('related_tags', array('name' => $photoKeyED)); |
---|
[4174] | 167 | } |
---|
[7468] | 168 | |
---|
| 169 | $query = ' |
---|
| 170 | select id,metadesimg |
---|
| 171 | FROM ' . meta_img_TABLE . ' |
---|
| 172 | WHERE id = \''.$page['image_id'].'\' |
---|
| 173 | ;'; |
---|
| 174 | $result = pwg_query($query); |
---|
| 175 | $row = mysql_fetch_array($result); |
---|
[9406] | 176 | $photoDesED=trigger_event('AP_render_content', $row['metadesimg']); |
---|
[7468] | 177 | if (!empty($row['metadesimg'])) |
---|
| 178 | { |
---|
[9406] | 179 | $template->assign('PLUG_META', $photoDesED); |
---|
[7468] | 180 | } |
---|
| 181 | |
---|
[4174] | 182 | } |
---|
[3978] | 183 | } |
---|
| 184 | |
---|
[7518] | 185 | |
---|
[3978] | 186 | function set_meta_back() |
---|
| 187 | { |
---|
| 188 | global $template, $meta_infos; |
---|
| 189 | |
---|
[7518] | 190 | $template->assign |
---|
| 191 | (array |
---|
| 192 | ( |
---|
[3978] | 193 | 'INFO_AUTHOR' => $meta_infos['author'], |
---|
| 194 | 'related_tags' => $meta_infos['related_tags'], |
---|
[7518] | 195 | 'INFO_FILE' => $meta_infos['info'], |
---|
[3978] | 196 | ) |
---|
| 197 | ); |
---|
| 198 | } |
---|
| 199 | ?> |
---|