[3978] | 1 | <?php |
---|
| 2 | /* |
---|
| 3 | Plugin Name: meta |
---|
| 4 | Version: 2.0.0.c |
---|
| 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'); |
---|
| 18 | |
---|
| 19 | add_event_handler('get_admin_plugin_menu_links', 'meta_admin_menu'); |
---|
| 20 | function meta_admin_menu($menu) |
---|
| 21 | { |
---|
| 22 | array_push($menu, array( |
---|
| 23 | 'NAME' => 'Meta', |
---|
| 24 | 'URL' => get_admin_plugin_menu_link(meta_PATH . 'admin/admin.php'))); |
---|
| 25 | return $menu; |
---|
| 26 | } |
---|
| 27 | |
---|
| 28 | //Gestion des meta dans le header |
---|
| 29 | add_event_handler('loc_begin_page_header', 'add_meta' ); |
---|
| 30 | function add_meta() |
---|
| 31 | { |
---|
| 32 | global $template, $page, $meta_infos; |
---|
| 33 | |
---|
| 34 | $meta_infos = array(); |
---|
| 35 | $meta_infos['author'] = $template->get_template_vars('INFO_AUTHOR'); |
---|
| 36 | $meta_infos['related_tags'] = $template->get_template_vars('related_tags'); |
---|
| 37 | $meta_infos['info'] = $template->get_template_vars('INFO_FILE'); |
---|
| 38 | |
---|
| 39 | $query = ' |
---|
| 40 | select id,metaname,metaval |
---|
| 41 | FROM ' . meta_TABLE . ' |
---|
| 42 | WHERE metaname IN (\'author\', \'keywords\', \'Description\', \'robots\') |
---|
| 43 | ;'; |
---|
| 44 | $result = pwg_query($query); |
---|
| 45 | $meta = array(); |
---|
| 46 | while ($row = mysql_fetch_assoc($result)) |
---|
| 47 | { |
---|
| 48 | $meta[$row['metaname']] = $row['metaval']; |
---|
| 49 | } |
---|
| 50 | |
---|
| 51 | // Authors |
---|
| 52 | if (!empty($meta_infos['author']) and !empty($meta['author'])) |
---|
| 53 | { |
---|
| 54 | $template->assign('INFO_AUTHOR', $meta_infos['author'] . ' - ' . $meta['author']); |
---|
| 55 | } |
---|
| 56 | elseif (!empty($meta['author'])) |
---|
| 57 | { |
---|
| 58 | $template->assign('INFO_AUTHOR', $meta['author']); |
---|
| 59 | } |
---|
| 60 | |
---|
| 61 | // Keywords |
---|
| 62 | if (!empty($meta['keywords'])) |
---|
| 63 | { |
---|
| 64 | $template->append('related_tags', array('name' => $meta['keywords'])); |
---|
| 65 | } |
---|
| 66 | |
---|
| 67 | // Description |
---|
| 68 | if (!empty($meta_infos['info']) and !empty($meta['Description'])) |
---|
| 69 | { |
---|
| 70 | $template->assign('INFO_FILE', $meta_infos['info'] . ', ' . $meta['Description']); |
---|
| 71 | } |
---|
| 72 | elseif (!empty($meta['Description'])) |
---|
| 73 | { |
---|
| 74 | $template->assign('INFO_FILE', $meta['Description']); |
---|
| 75 | } |
---|
| 76 | |
---|
| 77 | // Robots |
---|
| 78 | if (!empty($meta['robots'])) |
---|
| 79 | { |
---|
| 80 | $template->append('head_elements', '<meta name="robots" content="'.$meta['robots'].'">'); |
---|
| 81 | } |
---|
| 82 | |
---|
| 83 | //meta categories |
---|
| 84 | if ( !empty($page['category']['name']) ) |
---|
| 85 | { |
---|
| 86 | $page['category']['info'] = get_cat_info($page['category']['id']); |
---|
| 87 | $page['category']['name'] = $page['category']['info']['name']; |
---|
| 88 | |
---|
| 89 | $query = ' |
---|
| 90 | select id,name,metakeywords,comment |
---|
| 91 | FROM ' . CATEGORIES_TABLE . ' |
---|
| 92 | WHERE id = \''.$page['category']['id'].'\' |
---|
| 93 | ;'; |
---|
| 94 | $result = pwg_query($query); |
---|
| 95 | $row = mysql_fetch_array($result); |
---|
| 96 | if (!empty($row['metakeywords'])) |
---|
| 97 | { |
---|
| 98 | $template->append('related_tags', array('name' => $row['metakeywords'])); |
---|
| 99 | } |
---|
| 100 | } |
---|
| 101 | } |
---|
| 102 | |
---|
| 103 | |
---|
| 104 | add_event_handler('loc_after_page_header', 'set_meta_back'); |
---|
| 105 | function set_meta_back() |
---|
| 106 | { |
---|
| 107 | global $template, $meta_infos; |
---|
| 108 | |
---|
| 109 | $template->assign(array( |
---|
| 110 | 'INFO_AUTHOR' => $meta_infos['author'], |
---|
| 111 | 'related_tags' => $meta_infos['related_tags'], |
---|
| 112 | 'INFO_FILE' => $meta_infos['info'] |
---|
| 113 | ) |
---|
| 114 | ); |
---|
| 115 | } |
---|
| 116 | ?> |
---|