[3978] | 1 | <?php |
---|
| 2 | /* |
---|
[31491] | 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://temmii.com/piwigo/ |
---|
| 9 | */ |
---|
[3978] | 10 | |
---|
[31491] | 11 | // +-----------------------------------------------------------------------+ |
---|
| 12 | // | meta plugin for Piwigo | |
---|
| 13 | // +-----------------------------------------------------------------------+ |
---|
| 14 | // | Copyright(C) 2008-2016 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 | |
---|
[29125] | 31 | if (!defined('PHPWG_ROOT_PATH')) |
---|
| 32 | die('Hacking attempt!'); |
---|
[3978] | 33 | |
---|
[24393] | 34 | global $prefixeTable, $page; |
---|
[3978] | 35 | |
---|
[29125] | 36 | define('meta_DIR', basename(dirname(__FILE__))); |
---|
| 37 | define('meta_PATH', PHPWG_PLUGINS_PATH . meta_DIR . '/'); |
---|
| 38 | define('meta_TABLE', $prefixeTable . 'meta'); |
---|
| 39 | define('meta_img_TABLE', $prefixeTable . 'meta_img'); |
---|
| 40 | define('meta_cat_TABLE', $prefixeTable . 'meta_cat'); |
---|
[31491] | 41 | if (!defined('METAPERSO_TABLE')) |
---|
| 42 | define('METAPERSO_TABLE', $prefixeTable . 'metaperso'); |
---|
| 43 | if (!defined('META_AP_TABLE')) |
---|
| 44 | define('META_AP_TABLE', $prefixeTable . 'meta_ap'); |
---|
| 45 | define('META_ADMIN',get_root_url().'admin.php?page=plugin-'.meta_DIR); |
---|
[3978] | 46 | |
---|
[31491] | 47 | add_event_handler('loading_lang', 'meta_loading_lang'); |
---|
| 48 | function meta_loading_lang(){ |
---|
| 49 | load_language('plugin.lang', meta_PATH); |
---|
| 50 | } |
---|
| 51 | |
---|
[29125] | 52 | // Plugin for admin |
---|
| 53 | if (script_basename() == 'admin') { |
---|
| 54 | include_once(dirname(__FILE__) . '/initadmin.php'); |
---|
[3978] | 55 | } |
---|
| 56 | |
---|
| 57 | //Gestion des meta dans le header |
---|
[29125] | 58 | add_event_handler('loc_begin_page_header', 'Change_Meta', 20); |
---|
| 59 | add_event_handler('loc_end_page_header', 'add_meta', 56); |
---|
| 60 | add_event_handler('loc_end_page_header', 'add_metacat', 61); |
---|
| 61 | add_event_handler('loc_end_page_header', 'add_metaimg', 71); |
---|
[7651] | 62 | add_event_handler('loc_after_page_header', 'set_meta_back'); |
---|
[7518] | 63 | |
---|
[31491] | 64 | function Change_Meta(){ |
---|
| 65 | global $template; |
---|
| 66 | $template->set_prefilter('header', 'upmata'); |
---|
| 67 | $PAED = pwg_db_fetch_assoc(pwg_query("SELECT state FROM " . PLUGINS_TABLE . " WHERE id = 'ExtendedDescription';")); |
---|
| 68 | if ($PAED['state'] == 'active') |
---|
| 69 | add_event_handler('AP_render_content', 'get_user_language_desc'); |
---|
| 70 | } |
---|
[7624] | 71 | |
---|
[31491] | 72 | function upmata($content, &$smarty){ |
---|
| 73 | $search = '#<meta name="description" content=".*?">#'; |
---|
| 74 | $replacement = '<meta name="description" content="{$PLUG_META}">'; |
---|
| 75 | return preg_replace($search, $replacement, $content); |
---|
[29125] | 76 | } |
---|
[7624] | 77 | |
---|
[31491] | 78 | function add_meta(){ |
---|
| 79 | global $template, $page, $meta_infos; |
---|
| 80 | $meta_infos = array(); |
---|
| 81 | $meta_infos['author'] = $template->get_template_vars('INFO_AUTHOR'); |
---|
| 82 | $meta_infos['related_tags'] = $template->get_template_vars('related_tags'); |
---|
| 83 | $meta_infos['info'] = $template->get_template_vars('INFO_FILE'); |
---|
| 84 | $meta_infos['title'] = $template->get_template_vars('PAGE_TITLE'); |
---|
[7624] | 85 | |
---|
[31491] | 86 | $query = 'SELECT id,metaname,metaval FROM ' . meta_TABLE . ' WHERE metaname IN (\'author\', \'keywords\', \'Description\', \'robots\');'; |
---|
| 87 | $result = pwg_query($query); |
---|
| 88 | $meta = array(); |
---|
| 89 | while ($row = pwg_db_fetch_assoc($result)){ |
---|
| 90 | $meta[$row['metaname']] = $row['metaval']; |
---|
| 91 | $metaED[$row['metaname']] = trigger_change('AP_render_content', $meta[$row['metaname']]); |
---|
| 92 | } |
---|
[7624] | 93 | |
---|
[31491] | 94 | // Authors |
---|
| 95 | if (!empty($meta_infos['author']) and ! empty($metaED['author'])){ |
---|
| 96 | $template->assign('INFO_AUTHOR', $meta_infos['author'] . ' - ' . $metaED['author']); |
---|
| 97 | } elseif (!empty($metaED['author'])){ |
---|
| 98 | $template->assign('INFO_AUTHOR', $metaED['author']); |
---|
| 99 | } |
---|
[7624] | 100 | |
---|
[31491] | 101 | // Keywords |
---|
| 102 | if (!empty($metaED['keywords'])){ |
---|
| 103 | $template->append('related_tags', array('name' => $metaED['keywords'])); |
---|
| 104 | } |
---|
[3978] | 105 | |
---|
[31491] | 106 | // Description |
---|
| 107 | if (!empty($meta_infos['title']) and ! empty($meta_infos['info']) and ! empty($metaED['Description'])) { |
---|
| 108 | $template->assign('PLUG_META', $meta_infos['title'] . ' - ' . $meta_infos['info'] . ', ' . $metaED['Description']); |
---|
| 109 | } elseif (!empty($meta_infos['title']) and ! empty($metaED['Description'])) { |
---|
| 110 | $template->assign('PLUG_META', $meta_infos['title'] . ' - ' . $metaED['Description']); |
---|
| 111 | } elseif (!empty($metaED['Description'])) { |
---|
| 112 | $template->assign('PLUG_META', $metaED['Description']); |
---|
| 113 | } |
---|
[3978] | 114 | |
---|
[31491] | 115 | // Robots |
---|
| 116 | if (!empty($meta['robots'])) { |
---|
| 117 | $template->append('head_elements', '<meta name="robots" content="' . $meta['robots'] . '">'); |
---|
| 118 | } |
---|
[3978] | 119 | |
---|
[31491] | 120 | //Metaperso |
---|
| 121 | if (script_basename() !== 'admin') { |
---|
| 122 | $metapersos = pwg_query("SELECT * FROM " . METAPERSO_TABLE . ";"); |
---|
[3978] | 123 | |
---|
[31491] | 124 | if (pwg_db_num_rows($metapersos)) { |
---|
| 125 | while ($metaperso = pwg_db_fetch_assoc($metapersos)) { |
---|
| 126 | $items = array( |
---|
| 127 | 'METANAME' => $metaperso['metaname'], |
---|
| 128 | 'METAVAL' => $metaperso['metaval'], |
---|
| 129 | 'METATYPE' => $metaperso['metatype'] |
---|
| 130 | ); |
---|
| 131 | $template->append('metapersos', $items); |
---|
| 132 | } |
---|
[29125] | 133 | } |
---|
[24393] | 134 | |
---|
[31491] | 135 | $template->set_filename('PERSO_META', realpath(meta_PATH . 'persometa.tpl')); |
---|
| 136 | $template->append('head_elements', $template->parse('PERSO_META', true)); |
---|
| 137 | } |
---|
[29125] | 138 | |
---|
[31491] | 139 | $MPC = pwg_db_fetch_assoc(pwg_query("SELECT state FROM " . PLUGINS_TABLE . " WHERE id = 'ContactForm';")); |
---|
| 140 | if ($MPC['state'] == 'active'){ |
---|
| 141 | global $conf; |
---|
| 142 | if (isset($page['section']) and $page['section'] == 'contact' and isset($conf['contactmeta']) and strpos($conf['contactmeta'], ',') !== false){ |
---|
| 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 | $template->append('related_tags', array('name' => $metakeyED)); |
---|
| 148 | } |
---|
| 149 | if (!empty($metadesED)){ |
---|
| 150 | $template->assign('PLUG_META', $metadesED); |
---|
| 151 | } |
---|
[29125] | 152 | } |
---|
[31491] | 153 | } |
---|
[29125] | 154 | |
---|
[31491] | 155 | $MAP = pwg_db_fetch_assoc(pwg_query("SELECT state FROM " . PLUGINS_TABLE . " WHERE id = 'AdditionalPages';")); |
---|
| 156 | if ($MAP['state'] == 'active') { |
---|
| 157 | if (!empty($page['additional_page']['id'])) { |
---|
| 158 | $lire = $page['additional_page']['id']; |
---|
| 159 | $query = 'SELECT id, metaKeyap, metadesap FROM ' . META_AP_TABLE . ' WHERE id = \'' . $lire . '\';'; |
---|
| 160 | $result = pwg_query($query); |
---|
| 161 | $row = pwg_db_fetch_assoc($result); |
---|
| 162 | $metaKeyapap = $row['metaKeyap']; |
---|
| 163 | $metadesapap = $row['metadesap']; |
---|
| 164 | $metaKeyapapED = trigger_change('AP_render_content', $metaKeyapap); |
---|
| 165 | $metadesapED = trigger_change('AP_render_content', $metadesapap); |
---|
[29125] | 166 | } |
---|
[31491] | 167 | if (isset($page['section']) and $page['section'] == 'additional_page') { |
---|
| 168 | if (!empty($metaKeyapapED)) { |
---|
| 169 | $template->append('related_tags', array('name' => $metaKeyapapED)); |
---|
| 170 | } |
---|
| 171 | if (!empty($metadesapED)) { |
---|
| 172 | $template->assign('PLUG_META', $metadesapED); |
---|
| 173 | } |
---|
| 174 | } |
---|
| 175 | } |
---|
[29125] | 176 | } |
---|
[24393] | 177 | |
---|
[29125] | 178 | function add_metacat() { |
---|
[31491] | 179 | global $template, $page, $meta_infos; |
---|
| 180 | if (!empty($page['category']['id'])) { |
---|
| 181 | $query = 'SELECT id,metaKeycat,metadescat FROM ' . meta_cat_TABLE . ' WHERE id = \'' . $page['category']['id'] . '\';'; |
---|
| 182 | $result = pwg_query($query); |
---|
| 183 | $row = pwg_db_fetch_assoc($result); |
---|
| 184 | $albumKeyED = trigger_change('AP_render_content', $row['metaKeycat']); |
---|
| 185 | if (!empty($row['metaKeycat'])) { |
---|
| 186 | $template->append('related_tags', array('name' => $albumKeyED)); |
---|
| 187 | } |
---|
| 188 | $albumDesED = trigger_change('AP_render_content', $row['metadescat']); |
---|
| 189 | if (!empty($row['metadescat'])) { |
---|
| 190 | $template->assign('PLUG_META', $albumDesED); |
---|
| 191 | } |
---|
| 192 | } |
---|
[7518] | 193 | } |
---|
[4174] | 194 | |
---|
[31491] | 195 | function add_metaimg(){ |
---|
| 196 | global $template, $page, $meta_infos; |
---|
| 197 | if (!empty($page['image_id'])) { |
---|
| 198 | $query = 'SELECT id,metaKeyimg,metadesimg FROM ' . meta_img_TABLE . ' WHERE id = \'' . $page['image_id'] . '\';'; |
---|
| 199 | $result = pwg_query($query); |
---|
| 200 | $row = pwg_db_fetch_assoc($result); |
---|
| 201 | $photoKeyED = trigger_change('AP_render_content', $row['metaKeyimg']); |
---|
| 202 | if (!empty($row['metaKeyimg'])) { |
---|
| 203 | $template->append('related_tags', array('name' => $photoKeyED)); |
---|
| 204 | } |
---|
| 205 | $photoDesED = trigger_change('AP_render_content', $row['metadesimg']); |
---|
| 206 | if (!empty($row['metadesimg'])) { |
---|
| 207 | $template->assign('PLUG_META', $photoDesED); |
---|
| 208 | }else{ |
---|
| 209 | $meta_infosph = array(); |
---|
| 210 | $meta_infosph['title'] = $template->get_template_vars('PAGE_TITLE'); |
---|
| 211 | $meta_infosph['gt'] = $template->get_template_vars('GALLERY_TITLE'); |
---|
| 212 | $meta_infosph['descimg'] = $template->get_template_vars('COMMENT_IMG'); |
---|
| 213 | if (!empty($meta_infosph['descimg'])) { |
---|
| 214 | $template->assign('PLUG_META', strip_tags($meta_infosph['descimg']) . ' - ' . $meta_infosph['title']); |
---|
| 215 | }else{ |
---|
| 216 | $template->assign('PLUG_META', $meta_infosph['title'] . ' - ' . $meta_infosph['gt']); |
---|
| 217 | } |
---|
| 218 | } |
---|
| 219 | } |
---|
[3978] | 220 | } |
---|
| 221 | |
---|
[31491] | 222 | function set_meta_back(){ |
---|
| 223 | global $template, $meta_infos; |
---|
| 224 | $template->assign( |
---|
| 225 | array( |
---|
| 226 | 'INFO_AUTHOR' => $meta_infos['author'], |
---|
| 227 | 'related_tags' => $meta_infos['related_tags'], |
---|
| 228 | 'INFO_FILE' => $meta_infos['info'], |
---|
| 229 | ) |
---|
| 230 | ); |
---|
[3978] | 231 | } |
---|
[29125] | 232 | |
---|
[3978] | 233 | ?> |
---|