1 | <?php |
---|
2 | /* |
---|
3 | Plugin Name: metasimple |
---|
4 | Version: auto |
---|
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 | |
---|
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); |
---|
24 | add_event_handler('loc_after_page_header', 'set_metadesc_back',80); |
---|
25 | |
---|
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'); |
---|
49 | $meta_infosdesc['title'] = $template->get_template_vars('PAGE_TITLE'); |
---|
50 | |
---|
51 | |
---|
52 | if (!empty($meta_infosdesc['title']) and !empty($meta_infosdesc['info'])) |
---|
53 | { |
---|
54 | $template->assign('PLUG_META', $meta_infosdesc['title']. ' - ' .$meta_infosdesc['info']); |
---|
55 | } |
---|
56 | elseif (!empty($meta_infosdesc['title'])) |
---|
57 | { |
---|
58 | $template->assign('PLUG_META', $meta_infosdesc['title']); |
---|
59 | |
---|
60 | } |
---|
61 | } |
---|
62 | |
---|
63 | function add_metadescacc() |
---|
64 | //meta homepage |
---|
65 | { |
---|
66 | global $template, $page, $meta_infosdesc, $conf; |
---|
67 | |
---|
68 | if (isset($page['section']) and $page['section'] == 'categories' and empty($page['category']['id'])) |
---|
69 | { |
---|
70 | $descindex = & $conf['metasimple']; |
---|
71 | if (!empty($descindex)) |
---|
72 | { |
---|
73 | $template->assign('PLUG_META', $descindex); |
---|
74 | } |
---|
75 | else |
---|
76 | { |
---|
77 | $template->assign('PLUG_META', $meta_infosdesc['title']); |
---|
78 | } |
---|
79 | } |
---|
80 | } |
---|
81 | |
---|
82 | function add_metadesccat() |
---|
83 | //meta albums |
---|
84 | { |
---|
85 | global $template, $page, $meta_infosdesc; |
---|
86 | |
---|
87 | if ( !empty($page['category']['id']) ) |
---|
88 | { |
---|
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); |
---|
96 | if (!empty($row['comment'])) |
---|
97 | { |
---|
98 | $template->assign('PLUG_META', $row['comment']); |
---|
99 | } |
---|
100 | } |
---|
101 | } |
---|
102 | |
---|
103 | function add_metadescimg() |
---|
104 | //meta photos |
---|
105 | { |
---|
106 | global $template, $page, $meta_infosdesc; |
---|
107 | if ( !empty($page['image_id']) ) |
---|
108 | { |
---|
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); |
---|
116 | if (!empty($row['comment'])) |
---|
117 | { |
---|
118 | $template->assign('PLUG_META', $row['comment']); |
---|
119 | } |
---|
120 | } |
---|
121 | } |
---|
122 | |
---|
123 | function set_metadesc_back() |
---|
124 | { |
---|
125 | global $template, $meta_infosdesc; |
---|
126 | |
---|
127 | $template->assign |
---|
128 | (array |
---|
129 | ( |
---|
130 | 'INFO_FILE' => $meta_infosdesc['info'], |
---|
131 | 'COMMENT_IMG' => $meta_infosdesc['comment'] |
---|
132 | ) |
---|
133 | ); |
---|
134 | } |
---|
135 | ?> |
---|