[3673] | 1 | <?php |
---|
| 2 | /* |
---|
| 3 | Plugin Name: Community |
---|
| 4 | Version: auto |
---|
| 5 | Description: Non admin users can add photos |
---|
| 6 | Plugin URI: http://piwigo.org/ext/extension_view.php?eid=303 |
---|
| 7 | Author: plg |
---|
| 8 | Author URI: http://piwigo.wordpress.com |
---|
| 9 | */ |
---|
| 10 | |
---|
| 11 | if (!defined('PHPWG_ROOT_PATH')) |
---|
| 12 | { |
---|
| 13 | die('Hacking attempt!'); |
---|
| 14 | } |
---|
| 15 | |
---|
| 16 | define('COMMUNITY_PATH' , PHPWG_PLUGINS_PATH.basename(dirname(__FILE__)).'/'); |
---|
| 17 | include_once (COMMUNITY_PATH.'/include/constants.php'); |
---|
| 18 | |
---|
| 19 | /* Plugin admin */ |
---|
| 20 | add_event_handler('get_admin_plugin_menu_links', 'community_admin_menu'); |
---|
| 21 | |
---|
| 22 | function community_admin_menu($menu) |
---|
| 23 | { |
---|
| 24 | array_push( |
---|
| 25 | $menu, |
---|
| 26 | array( |
---|
| 27 | 'NAME' => 'Community', |
---|
| 28 | 'URL' => get_admin_plugin_menu_link(dirname(__FILE__).'/admin.php') |
---|
| 29 | ) |
---|
| 30 | ); |
---|
| 31 | |
---|
| 32 | return $menu; |
---|
| 33 | } |
---|
| 34 | |
---|
| 35 | add_event_handler('ws_invoke_allowed', 'community_switch_user_to_admin', EVENT_HANDLER_PRIORITY_NEUTRAL, 3); |
---|
| 36 | |
---|
| 37 | function community_switch_user_to_admin($res, $methodName, $params) |
---|
| 38 | { |
---|
| 39 | global $user; |
---|
| 40 | |
---|
| 41 | $methods_of_permission_level[1] = array( |
---|
| 42 | 'pwg.categories.getList', |
---|
| 43 | 'pwg.tags.getAdminList', |
---|
| 44 | 'pwg.tags.add', |
---|
| 45 | 'pwg.images.exist', |
---|
| 46 | 'pwg.images.add', |
---|
| 47 | 'pwg.images.setInfo', |
---|
| 48 | 'pwg.images.addChunk', |
---|
| 49 | ); |
---|
| 50 | |
---|
| 51 | // permission_level 2 has all methods of level 1 + others |
---|
| 52 | $methods_of_permission_level[2] = array_merge( |
---|
| 53 | $methods_of_permission_level[1], |
---|
| 54 | array( |
---|
| 55 | 'pwg.categories.add', |
---|
| 56 | 'pwg.categories.setInfo', |
---|
| 57 | ) |
---|
| 58 | ); |
---|
| 59 | |
---|
| 60 | $query = ' |
---|
| 61 | SELECT |
---|
| 62 | permission_level |
---|
| 63 | FROM '.COMMUNITY_TABLE.' |
---|
| 64 | WHERE user_id = '.$user['id'].' |
---|
| 65 | ;'; |
---|
| 66 | $result = pwg_query($query); |
---|
| 67 | if (1 == mysql_num_rows($result)) |
---|
| 68 | { |
---|
| 69 | list($permission_level) = mysql_fetch_row($result); |
---|
| 70 | |
---|
| 71 | if (in_array($methodName, $methods_of_permission_level[$permission_level])) |
---|
| 72 | { |
---|
| 73 | $user['status'] = 'admin'; |
---|
| 74 | } |
---|
| 75 | } |
---|
| 76 | |
---|
| 77 | return $res; |
---|
| 78 | } |
---|
| 79 | |
---|
| 80 | add_event_handler('delete_user', 'community_delete_user'); |
---|
| 81 | function community_delete_user($user_id) |
---|
| 82 | { |
---|
| 83 | $query = ' |
---|
| 84 | DELETE |
---|
| 85 | FROM '.COMMUNITY_TABLE.' |
---|
| 86 | WHERE user_id = '.$user_id.' |
---|
| 87 | ;'; |
---|
| 88 | pwg_query($query); |
---|
| 89 | } |
---|
| 90 | |
---|
| 91 | ?> |
---|