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