[7470] | 1 | <?php |
---|
| 2 | /* |
---|
| 3 | Plugin Name: metasimple |
---|
[7525] | 4 | Version: auto |
---|
[7470] | 5 | Description: Replaces the entire contents of the metadata "description" with the category description or pictures if any. Ability to customize the description of the home page |
---|
| 6 | Plugin URI: http://piwigo.org/ext/extension_view.php?eid=456 |
---|
| 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('metasimple_DIR' , basename(dirname(__FILE__))); |
---|
| 16 | define('metasimple_PATH' , PHPWG_PLUGINS_PATH . metasimple_DIR . '/'); |
---|
| 17 | |
---|
| 18 | |
---|
[7637] | 19 | add_event_handler('loc_begin_page_header', 'Change_Metasimple',10 ); |
---|
| 20 | add_event_handler('loc_end_page_header', 'add_metasimple',53); |
---|
| 21 | add_event_handler('loc_end_page_header', 'add_metadescacc',55); |
---|
| 22 | add_event_handler('loc_end_page_header', 'add_metadesccat',60); |
---|
| 23 | add_event_handler('loc_end_page_header', 'add_metadescimg',70); |
---|
[7517] | 24 | add_event_handler('loc_after_page_header', 'set_metadesc_back',80); |
---|
[7470] | 25 | |
---|
[7637] | 26 | function Change_Metasimple() |
---|
| 27 | { |
---|
| 28 | global $template; |
---|
| 29 | $template->set_prefilter('header', 'upmatasimple'); |
---|
| 30 | } |
---|
| 31 | |
---|
| 32 | function upmatasimple ($content, &$smarty) |
---|
| 33 | { |
---|
| 34 | $search = '#<meta name="description" content=".*?">#'; |
---|
| 35 | |
---|
| 36 | $replacement = '<meta name="description" content="{$PLUG_META}">'; |
---|
| 37 | |
---|
| 38 | return preg_replace($search, $replacement, $content); |
---|
| 39 | } |
---|
| 40 | |
---|
| 41 | function add_metasimple() |
---|
| 42 | //meta homepage |
---|
| 43 | { |
---|
| 44 | global $template, $page, $meta_infosdesc, $conf; |
---|
| 45 | $meta_infosdesc = array(); |
---|
| 46 | $meta_infosdesc['info'] = $template->get_template_vars('INFO_FILE'); |
---|
| 47 | $meta_infosdesc['page'] = $template->get_template_vars('PAGE_TITLE'); |
---|
| 48 | $meta_infosdesc['comment'] = $template->get_template_vars('COMMENT_IMG'); |
---|
[7675] | 49 | $meta_infosdesc['title'] = $template->get_template_vars('PAGE_TITLE'); |
---|
[7637] | 50 | |
---|
| 51 | |
---|
[7675] | 52 | if (!empty($meta_infosdesc['title']) and !empty($meta_infosdesc['info'])) |
---|
[7637] | 53 | { |
---|
[7675] | 54 | $template->assign('PLUG_META', $meta_infosdesc['title']. ' - ' .$meta_infosdesc['info']); |
---|
[7637] | 55 | } |
---|
[7675] | 56 | elseif (!empty($meta_infosdesc['title'])) |
---|
[7637] | 57 | { |
---|
[7675] | 58 | $template->assign('PLUG_META', $meta_infosdesc['title']); |
---|
[7637] | 59 | |
---|
| 60 | } |
---|
| 61 | } |
---|
| 62 | |
---|
[7517] | 63 | function add_metadescacc() |
---|
| 64 | //meta homepage |
---|
| 65 | { |
---|
[7524] | 66 | global $template, $page, $meta_infosdesc, $conf; |
---|
[7637] | 67 | |
---|
[7524] | 68 | if (isset($page['section']) and $page['section'] == 'categories' and empty($page['category']['id'])) |
---|
[7517] | 69 | { |
---|
[7524] | 70 | $descindex = & $conf['metasimple']; |
---|
| 71 | if (!empty($descindex)) |
---|
| 72 | { |
---|
[7637] | 73 | $template->assign('PLUG_META', $descindex); |
---|
[7524] | 74 | } |
---|
[7637] | 75 | else |
---|
| 76 | { |
---|
[7675] | 77 | $template->assign('PLUG_META', $meta_infosdesc['title']); |
---|
[7637] | 78 | } |
---|
[7517] | 79 | } |
---|
| 80 | } |
---|
[7470] | 81 | |
---|
[7517] | 82 | function add_metadesccat() |
---|
[7524] | 83 | //meta albums |
---|
[7517] | 84 | { |
---|
| 85 | global $template, $page, $meta_infosdesc; |
---|
[7650] | 86 | |
---|
[7517] | 87 | if ( !empty($page['category']['id']) ) |
---|
| 88 | { |
---|
[7470] | 89 | $query = ' |
---|
| 90 | select id,comment |
---|
| 91 | FROM ' . CATEGORIES_TABLE . ' |
---|
| 92 | WHERE id = \''.$page['category']['id'].'\' |
---|
| 93 | ;'; |
---|
| 94 | $result = pwg_query($query); |
---|
| 95 | $row = mysql_fetch_array($result); |
---|
[7517] | 96 | if (!empty($row['comment'])) |
---|
| 97 | { |
---|
[7637] | 98 | $template->assign('PLUG_META', $row['comment']); |
---|
[7517] | 99 | } |
---|
| 100 | } |
---|
| 101 | } |
---|
| 102 | |
---|
| 103 | function add_metadescimg() |
---|
[7524] | 104 | //meta photos |
---|
[7517] | 105 | { |
---|
| 106 | global $template, $page, $meta_infosdesc; |
---|
| 107 | if ( !empty($page['image_id']) ) |
---|
| 108 | { |
---|
[7470] | 109 | $query = ' |
---|
| 110 | select id,comment |
---|
| 111 | FROM ' . IMAGES_TABLE . ' |
---|
| 112 | WHERE id = \''.$page['image_id'].'\' |
---|
| 113 | ;'; |
---|
| 114 | $result = pwg_query($query); |
---|
| 115 | $row = mysql_fetch_array($result); |
---|
[7517] | 116 | if (!empty($row['comment'])) |
---|
| 117 | { |
---|
[7637] | 118 | $template->assign('PLUG_META', $row['comment']); |
---|
[7517] | 119 | } |
---|
| 120 | } |
---|
| 121 | } |
---|
[7470] | 122 | |
---|
| 123 | function set_metadesc_back() |
---|
[7517] | 124 | { |
---|
| 125 | global $template, $meta_infosdesc; |
---|
[7470] | 126 | |
---|
[7517] | 127 | $template->assign |
---|
| 128 | (array |
---|
| 129 | ( |
---|
| 130 | 'INFO_FILE' => $meta_infosdesc['info'], |
---|
| 131 | 'COMMENT_IMG' => $meta_infosdesc['comment'] |
---|
| 132 | ) |
---|
| 133 | ); |
---|
| 134 | } |
---|
[7470] | 135 | ?> |
---|