1 | <?php |
---|
2 | load_language('plugin.lang', CM_PATH); |
---|
3 | |
---|
4 | |
---|
5 | /** |
---|
6 | * Triggered on get_admin_plugin_menu_links |
---|
7 | * |
---|
8 | * Plugin's administration menu |
---|
9 | */ |
---|
10 | function CM_admin_menu($menu) |
---|
11 | { |
---|
12 | // +-----------------------------------------------------------------------+ |
---|
13 | // | Getting plugin name | |
---|
14 | // +-----------------------------------------------------------------------+ |
---|
15 | $plugin = CM_Infos(CM_PATH); |
---|
16 | $name = $plugin['name']; |
---|
17 | |
---|
18 | array_push($menu, |
---|
19 | array( |
---|
20 | 'NAME' => $name, |
---|
21 | 'URL' => get_root_url().'admin.php?page=plugin-'.basename(CM_PATH) |
---|
22 | ) |
---|
23 | ); |
---|
24 | |
---|
25 | return $menu; |
---|
26 | } |
---|
27 | |
---|
28 | |
---|
29 | /** |
---|
30 | * checks if author is mandatory and set on comments post when comments for all is set |
---|
31 | * |
---|
32 | * cheks if author is in an allowed group to post comment when comments for all is not set |
---|
33 | * |
---|
34 | * @param : comment action, comment |
---|
35 | * |
---|
36 | * @return : comment action |
---|
37 | * |
---|
38 | */ |
---|
39 | function CM_CheckCommentAuthor($comment_action, $comm) |
---|
40 | { |
---|
41 | load_language('plugin.lang', CM_PATH); |
---|
42 | global $infos, $conf, $user; |
---|
43 | |
---|
44 | $conf_CM = unserialize($conf['CommentsManager']); |
---|
45 | |
---|
46 | // Does not allow empty author name on comments for all |
---|
47 | if (isset($conf_CM[1]) and $conf_CM[1] == 'true' and $comm['author'] == 'guest' and $conf['comments_forall']) |
---|
48 | { |
---|
49 | $comment_action = 'reject'; |
---|
50 | |
---|
51 | array_push($infos, l10n('CM_Empty Author')); |
---|
52 | } |
---|
53 | |
---|
54 | |
---|
55 | // Do not allow comments if user is not in an allowed group |
---|
56 | if (isset($conf_CM[2]) and $conf_CM[2] == 'true' and !$conf['comments_forall'] and !is_admin()) |
---|
57 | { |
---|
58 | if (!CM_CheckAuthor($comm['author'])) |
---|
59 | { |
---|
60 | $comment_action = 'reject'; |
---|
61 | |
---|
62 | array_push($infos, l10n('CM_Not_Allowed_Author')); |
---|
63 | } |
---|
64 | } |
---|
65 | |
---|
66 | return $comment_action; |
---|
67 | } |
---|
68 | |
---|
69 | |
---|
70 | /** |
---|
71 | * Checks if comment's author name is in the allowed group |
---|
72 | * |
---|
73 | * @author : author's name |
---|
74 | * |
---|
75 | * @returns : Boolean (true is user is allowed to post / false if not allowed) |
---|
76 | * |
---|
77 | */ |
---|
78 | function CM_CheckAuthor($author) |
---|
79 | { |
---|
80 | global $conf; |
---|
81 | |
---|
82 | // Get CM configuration |
---|
83 | $conf_CM = unserialize($conf['CommentsManager']); |
---|
84 | |
---|
85 | if (isset($conf_CM[3]) and $conf_CM[3] <> -1) |
---|
86 | { |
---|
87 | $query = ' |
---|
88 | SELECT u.id, |
---|
89 | u.username, |
---|
90 | ug.user_id, |
---|
91 | ug.group_id |
---|
92 | FROM '.USERS_TABLE.' AS u |
---|
93 | INNER JOIN '.USER_GROUP_TABLE.' AS ug |
---|
94 | ON u.id = ug.user_id |
---|
95 | WHERE u.username LIKE "'.$author.'" |
---|
96 | AND ug.group_id = '.$conf_CM[3].' |
---|
97 | ;'; |
---|
98 | |
---|
99 | $count = pwg_db_num_rows(pwg_query($query)); |
---|
100 | |
---|
101 | if (is_null($count) or $count == 0) |
---|
102 | { |
---|
103 | return false; |
---|
104 | } |
---|
105 | else |
---|
106 | return true; |
---|
107 | } |
---|
108 | } |
---|
109 | |
---|
110 | |
---|
111 | /** |
---|
112 | * Get the plugin version and name |
---|
113 | * |
---|
114 | * @param : plugin directory |
---|
115 | * |
---|
116 | * @return : plugin's version and name |
---|
117 | * |
---|
118 | */ |
---|
119 | function CM_Infos($dir) |
---|
120 | { |
---|
121 | $path = $dir; |
---|
122 | |
---|
123 | $plg_data = implode( '', file($path.'main.inc.php') ); |
---|
124 | if ( preg_match("|Plugin Name: (.*)|", $plg_data, $val) ) |
---|
125 | { |
---|
126 | $plugin['name'] = trim( $val[1] ); |
---|
127 | } |
---|
128 | if (preg_match("|Version: (.*)|", $plg_data, $val)) |
---|
129 | { |
---|
130 | $plugin['version'] = trim($val[1]); |
---|
131 | } |
---|
132 | if ( preg_match("|Plugin URI: (.*)|", $plg_data, $val) ) |
---|
133 | { |
---|
134 | $plugin['uri'] = trim($val[1]); |
---|
135 | } |
---|
136 | if ($desc = load_language('description.txt', $path.'/', array('return' => true))) |
---|
137 | { |
---|
138 | $plugin['description'] = trim($desc); |
---|
139 | } |
---|
140 | elseif ( preg_match("|Description: (.*)|", $plg_data, $val) ) |
---|
141 | { |
---|
142 | $plugin['description'] = trim($val[1]); |
---|
143 | } |
---|
144 | if ( preg_match("|Author: (.*)|", $plg_data, $val) ) |
---|
145 | { |
---|
146 | $plugin['author'] = trim($val[1]); |
---|
147 | } |
---|
148 | if ( preg_match("|Author URI: (.*)|", $plg_data, $val) ) |
---|
149 | { |
---|
150 | $plugin['author uri'] = trim($val[1]); |
---|
151 | } |
---|
152 | if (!empty($plugin['uri']) and strpos($plugin['uri'] , 'extension_view.php?eid=')) |
---|
153 | { |
---|
154 | list( , $extension) = explode('extension_view.php?eid=', $plugin['uri']); |
---|
155 | if (is_numeric($extension)) $plugin['extension'] = $extension; |
---|
156 | } |
---|
157 | // IMPORTANT SECURITY ! |
---|
158 | $plugin = array_map('htmlspecialchars', $plugin); |
---|
159 | |
---|
160 | return $plugin ; |
---|
161 | } |
---|
162 | |
---|
163 | |
---|
164 | /** |
---|
165 | * Delete obsolete files on plugin upgrade |
---|
166 | * Obsolete files are listed in file obsolete.list |
---|
167 | * |
---|
168 | */ |
---|
169 | function CM_Obsolete_Files() |
---|
170 | { |
---|
171 | if (file_exists(CM_PATH.'obsolete.list') |
---|
172 | and $old_files = file(CM_PATH.'obsolete.list', FILE_IGNORE_NEW_LINES) |
---|
173 | and !empty($old_files)) |
---|
174 | { |
---|
175 | array_push($old_files, 'obsolete.list'); |
---|
176 | foreach($old_files as $old_file) |
---|
177 | { |
---|
178 | $path = CM_PATH.$old_file; |
---|
179 | if (is_file($path)) |
---|
180 | { |
---|
181 | @unlink($path); |
---|
182 | } |
---|
183 | } |
---|
184 | } |
---|
185 | } |
---|
186 | ?> |
---|