[11017] | 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 | /** |
---|
[11204] | 30 | * Check comment rules set in plugin before accepting it |
---|
[11017] | 31 | * |
---|
| 32 | * @param : comment action, comment |
---|
| 33 | * |
---|
| 34 | * @return : comment action |
---|
| 35 | * |
---|
| 36 | */ |
---|
[11204] | 37 | function CM_CheckComment($comment_action, $comm) |
---|
[11017] | 38 | { |
---|
| 39 | load_language('plugin.lang', CM_PATH); |
---|
| 40 | global $infos, $conf, $user; |
---|
| 41 | |
---|
| 42 | $conf_CM = unserialize($conf['CommentsManager']); |
---|
| 43 | |
---|
[11070] | 44 | if ($conf['comments_forall']) |
---|
[11017] | 45 | { |
---|
[11070] | 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') |
---|
| 48 | { |
---|
| 49 | $comment_action = 'reject'; |
---|
[11017] | 50 | |
---|
[11070] | 51 | array_push($infos, l10n('CM_Empty Author')); |
---|
| 52 | } |
---|
[11208] | 53 | |
---|
[11214] | 54 | if ((isset($conf_CM[6]) and $conf_CM[6] == 'true') and !is_a_guest() and $conf['comments_validation']) |
---|
[11070] | 55 | { |
---|
| 56 | if (CM_CheckValidGroup($comm['author']) or is_admin()) |
---|
| 57 | { |
---|
| 58 | $comment_action = 'validate'; // Comment is validated if author is not in the validated group |
---|
| 59 | } |
---|
| 60 | else |
---|
| 61 | { |
---|
| 62 | $comment_action = 'moderate'; // Comment needs moderation if author is not in the validated group |
---|
| 63 | } |
---|
| 64 | } |
---|
[11017] | 65 | } |
---|
| 66 | |
---|
[11069] | 67 | // Rules on comments NOT for all |
---|
| 68 | if (!$conf['comments_forall'] and !is_admin()) |
---|
[11017] | 69 | { |
---|
[11069] | 70 | if ((isset($conf_CM[2]) and $conf_CM[2] == 'true') and (isset($conf_CM[4]) and $conf_CM[4] == 'false') and !CM_CheckAuthor($comm['author'])) // Comments authorized group set - Auto validation group unset |
---|
[11017] | 71 | { |
---|
[11069] | 72 | $comment_action = 'reject'; // Comment rejected if author is not in the allowed group |
---|
[11017] | 73 | array_push($infos, l10n('CM_Not_Allowed_Author')); |
---|
| 74 | } |
---|
[11069] | 75 | elseif ((isset($conf_CM[2]) and $conf_CM[2] == 'false') and (isset($conf_CM[4]) and $conf_CM[4] == 'true') and $conf['comments_validation']) // Comments authorized group unset - Auto validation group set |
---|
| 76 | { |
---|
[11214] | 77 | if (CM_CheckValidGroup($comm['author']) and $conf['comments_validation']) |
---|
[11069] | 78 | { |
---|
| 79 | $comment_action = 'validate'; // Comment is validated if author is not in the validated group |
---|
| 80 | } |
---|
| 81 | else |
---|
| 82 | { |
---|
| 83 | $comment_action = 'moderate'; // Comment needs moderation if author is not in the validated group |
---|
| 84 | } |
---|
| 85 | } |
---|
| 86 | elseif ((isset($conf_CM[2]) and $conf_CM[2] == 'true') and (isset($conf_CM[4]) and $conf_CM[4] == 'true') and $conf['comments_validation']) // Comments authorized group set - Auto validation group set |
---|
| 87 | { |
---|
| 88 | if (!CM_CheckAuthor($comm['author'])) |
---|
| 89 | { |
---|
| 90 | $comment_action = 'reject'; // Comment rejected if author is not in the allowed group |
---|
| 91 | array_push($infos, l10n('CM_Not_Allowed_Author')); |
---|
| 92 | } |
---|
[11214] | 93 | elseif (CM_CheckValidGroup($comm['author']) and $conf['comments_validation']) |
---|
[11069] | 94 | { |
---|
| 95 | $comment_action = 'validate'; // Comment is validated if author is not in the validated group |
---|
| 96 | } |
---|
| 97 | else |
---|
| 98 | $comment_action = 'moderate'; // Comment needs moderation if author is not in the validated group |
---|
| 99 | } |
---|
[11017] | 100 | } |
---|
| 101 | |
---|
| 102 | return $comment_action; |
---|
| 103 | } |
---|
| 104 | |
---|
| 105 | |
---|
| 106 | /** |
---|
| 107 | * Checks if comment's author name is in the allowed group |
---|
| 108 | * |
---|
| 109 | * @author : author's name |
---|
| 110 | * |
---|
| 111 | * @returns : Boolean (true is user is allowed to post / false if not allowed) |
---|
| 112 | * |
---|
| 113 | */ |
---|
| 114 | function CM_CheckAuthor($author) |
---|
| 115 | { |
---|
| 116 | global $conf; |
---|
| 117 | |
---|
| 118 | // Get CM configuration |
---|
| 119 | $conf_CM = unserialize($conf['CommentsManager']); |
---|
| 120 | |
---|
| 121 | if (isset($conf_CM[3]) and $conf_CM[3] <> -1) |
---|
| 122 | { |
---|
| 123 | $query = ' |
---|
| 124 | SELECT u.id, |
---|
| 125 | u.username, |
---|
| 126 | ug.user_id, |
---|
| 127 | ug.group_id |
---|
| 128 | FROM '.USERS_TABLE.' AS u |
---|
| 129 | INNER JOIN '.USER_GROUP_TABLE.' AS ug |
---|
| 130 | ON u.id = ug.user_id |
---|
| 131 | WHERE u.username LIKE "'.$author.'" |
---|
| 132 | AND ug.group_id = '.$conf_CM[3].' |
---|
| 133 | ;'; |
---|
| 134 | |
---|
| 135 | $count = pwg_db_num_rows(pwg_query($query)); |
---|
| 136 | |
---|
| 137 | if (is_null($count) or $count == 0) |
---|
| 138 | { |
---|
| 139 | return false; |
---|
| 140 | } |
---|
| 141 | else |
---|
| 142 | return true; |
---|
| 143 | } |
---|
| 144 | } |
---|
| 145 | |
---|
| 146 | |
---|
| 147 | /** |
---|
[11069] | 148 | * Checks if comment's author name is in the admin's pre-validated group |
---|
| 149 | * avoid admins to validate comments for the members of this group |
---|
| 150 | * |
---|
| 151 | * @author : author's name |
---|
| 152 | * |
---|
| 153 | * @returns : Boolean (true if user's comment doesn't need validation / false if user's comment is moderated) |
---|
| 154 | * |
---|
| 155 | */ |
---|
| 156 | function CM_CheckValidGroup($author) |
---|
| 157 | { |
---|
| 158 | global $conf; |
---|
| 159 | |
---|
| 160 | // Get CM configuration |
---|
| 161 | $conf_CM = unserialize($conf['CommentsManager']); |
---|
| 162 | |
---|
[11070] | 163 | if ($conf['comments_forall']) |
---|
[11069] | 164 | { |
---|
[11070] | 165 | if (isset($conf_CM[7]) and $conf_CM[7] <> -1) |
---|
| 166 | { |
---|
| 167 | $group_id = $conf_CM[7]; |
---|
| 168 | } |
---|
| 169 | } |
---|
| 170 | else |
---|
| 171 | { |
---|
| 172 | if (isset($conf_CM[5]) and $conf_CM[5] <> -1) |
---|
| 173 | { |
---|
| 174 | $group_id = $conf_CM[5]; |
---|
| 175 | } |
---|
| 176 | } |
---|
| 177 | |
---|
| 178 | $query = ' |
---|
[11069] | 179 | SELECT u.id, |
---|
| 180 | u.username, |
---|
| 181 | ug.user_id, |
---|
| 182 | ug.group_id |
---|
| 183 | FROM '.USERS_TABLE.' AS u |
---|
| 184 | INNER JOIN '.USER_GROUP_TABLE.' AS ug |
---|
| 185 | ON u.id = ug.user_id |
---|
| 186 | WHERE u.username LIKE "'.$author.'" |
---|
[11070] | 187 | AND ug.group_id = '.$group_id.' |
---|
[11069] | 188 | ;'; |
---|
| 189 | |
---|
[11070] | 190 | $count = pwg_db_num_rows(pwg_query($query)); |
---|
[11069] | 191 | |
---|
[11070] | 192 | if (is_null($count) or $count == 0) |
---|
| 193 | { |
---|
| 194 | return false; |
---|
[11069] | 195 | } |
---|
[11070] | 196 | else |
---|
| 197 | return true; |
---|
[11069] | 198 | } |
---|
| 199 | |
---|
| 200 | |
---|
| 201 | /** |
---|
[11017] | 202 | * Get the plugin version and name |
---|
| 203 | * |
---|
| 204 | * @param : plugin directory |
---|
| 205 | * |
---|
| 206 | * @return : plugin's version and name |
---|
| 207 | * |
---|
| 208 | */ |
---|
| 209 | function CM_Infos($dir) |
---|
| 210 | { |
---|
| 211 | $path = $dir; |
---|
| 212 | |
---|
| 213 | $plg_data = implode( '', file($path.'main.inc.php') ); |
---|
| 214 | if ( preg_match("|Plugin Name: (.*)|", $plg_data, $val) ) |
---|
| 215 | { |
---|
| 216 | $plugin['name'] = trim( $val[1] ); |
---|
| 217 | } |
---|
| 218 | if (preg_match("|Version: (.*)|", $plg_data, $val)) |
---|
| 219 | { |
---|
| 220 | $plugin['version'] = trim($val[1]); |
---|
| 221 | } |
---|
| 222 | if ( preg_match("|Plugin URI: (.*)|", $plg_data, $val) ) |
---|
| 223 | { |
---|
| 224 | $plugin['uri'] = trim($val[1]); |
---|
| 225 | } |
---|
| 226 | if ($desc = load_language('description.txt', $path.'/', array('return' => true))) |
---|
| 227 | { |
---|
| 228 | $plugin['description'] = trim($desc); |
---|
| 229 | } |
---|
| 230 | elseif ( preg_match("|Description: (.*)|", $plg_data, $val) ) |
---|
| 231 | { |
---|
| 232 | $plugin['description'] = trim($val[1]); |
---|
| 233 | } |
---|
| 234 | if ( preg_match("|Author: (.*)|", $plg_data, $val) ) |
---|
| 235 | { |
---|
| 236 | $plugin['author'] = trim($val[1]); |
---|
| 237 | } |
---|
| 238 | if ( preg_match("|Author URI: (.*)|", $plg_data, $val) ) |
---|
| 239 | { |
---|
| 240 | $plugin['author uri'] = trim($val[1]); |
---|
| 241 | } |
---|
| 242 | if (!empty($plugin['uri']) and strpos($plugin['uri'] , 'extension_view.php?eid=')) |
---|
| 243 | { |
---|
| 244 | list( , $extension) = explode('extension_view.php?eid=', $plugin['uri']); |
---|
| 245 | if (is_numeric($extension)) $plugin['extension'] = $extension; |
---|
| 246 | } |
---|
| 247 | // IMPORTANT SECURITY ! |
---|
| 248 | $plugin = array_map('htmlspecialchars', $plugin); |
---|
| 249 | |
---|
| 250 | return $plugin ; |
---|
| 251 | } |
---|
| 252 | |
---|
| 253 | |
---|
| 254 | /** |
---|
| 255 | * Delete obsolete files on plugin upgrade |
---|
| 256 | * Obsolete files are listed in file obsolete.list |
---|
| 257 | * |
---|
| 258 | */ |
---|
| 259 | function CM_Obsolete_Files() |
---|
| 260 | { |
---|
| 261 | if (file_exists(CM_PATH.'obsolete.list') |
---|
| 262 | and $old_files = file(CM_PATH.'obsolete.list', FILE_IGNORE_NEW_LINES) |
---|
| 263 | and !empty($old_files)) |
---|
| 264 | { |
---|
| 265 | array_push($old_files, 'obsolete.list'); |
---|
| 266 | foreach($old_files as $old_file) |
---|
| 267 | { |
---|
| 268 | $path = CM_PATH.$old_file; |
---|
| 269 | if (is_file($path)) |
---|
| 270 | { |
---|
| 271 | @unlink($path); |
---|
| 272 | } |
---|
| 273 | } |
---|
| 274 | } |
---|
| 275 | } |
---|
| 276 | ?> |
---|