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 | |
---|
18 | global $prefixeTable; |
---|
19 | define('COMMUNITY_PERMISSIONS_TABLE', $prefixeTable.'community_permissions'); |
---|
20 | define('COMMUNITY_PENDINGS_TABLE', $prefixeTable.'community_pendings'); |
---|
21 | |
---|
22 | include_once(COMMUNITY_PATH.'include/functions_community.inc.php'); |
---|
23 | |
---|
24 | /* Plugin admin */ |
---|
25 | add_event_handler('get_admin_plugin_menu_links', 'community_admin_menu'); |
---|
26 | |
---|
27 | function community_admin_menu($menu) |
---|
28 | { |
---|
29 | array_push( |
---|
30 | $menu, |
---|
31 | array( |
---|
32 | 'NAME' => 'Community', |
---|
33 | 'URL' => get_root_url().'admin.php?page=plugin-community' |
---|
34 | ) |
---|
35 | ); |
---|
36 | |
---|
37 | return $menu; |
---|
38 | } |
---|
39 | |
---|
40 | add_event_handler('loc_end_section_init', 'community_section_init'); |
---|
41 | function community_section_init() |
---|
42 | { |
---|
43 | global $tokens, $page; |
---|
44 | |
---|
45 | if ($tokens[0] == 'add_photos') |
---|
46 | { |
---|
47 | $page['section'] = 'add_photos'; |
---|
48 | } |
---|
49 | } |
---|
50 | |
---|
51 | add_event_handler('loc_end_index', 'community_index'); |
---|
52 | function community_index() |
---|
53 | { |
---|
54 | global $page; |
---|
55 | |
---|
56 | if (isset($page['section']) and $page['section'] == 'add_photos') |
---|
57 | { |
---|
58 | include(COMMUNITY_PATH.'add_photos.php'); |
---|
59 | } |
---|
60 | } |
---|
61 | |
---|
62 | add_event_handler('blockmanager_apply' , 'community_gallery_menu'); |
---|
63 | function community_gallery_menu($menu_ref_arr) |
---|
64 | { |
---|
65 | global $conf, $user; |
---|
66 | |
---|
67 | // conditional : depending on community permissions, display the "Add |
---|
68 | // photos" link in the gallery menu |
---|
69 | $user_permissions = community_get_user_permissions($user['id']); |
---|
70 | |
---|
71 | if (!$user_permissions['upload_whole_gallery'] and count($user_permissions['upload_categories']) == 0) |
---|
72 | { |
---|
73 | return; |
---|
74 | } |
---|
75 | |
---|
76 | $menu = & $menu_ref_arr[0]; |
---|
77 | |
---|
78 | if (($block = $menu->get_block('mbMenu')) != null ) |
---|
79 | { |
---|
80 | load_language('plugin.lang', COMMUNITY_PATH); |
---|
81 | |
---|
82 | array_splice( |
---|
83 | $block->data, |
---|
84 | count($block->data), |
---|
85 | 0, |
---|
86 | array( |
---|
87 | '' => array( |
---|
88 | 'URL' => make_index_url(array('section' => 'add_photos')), |
---|
89 | 'TITLE' => l10n('Upload your own photos'), |
---|
90 | 'NAME' => l10n('Upload Photos') |
---|
91 | ) |
---|
92 | ) |
---|
93 | ); |
---|
94 | } |
---|
95 | } |
---|
96 | |
---|
97 | |
---|
98 | add_event_handler('ws_invoke_allowed', 'community_switch_user_to_admin', EVENT_HANDLER_PRIORITY_NEUTRAL, 3); |
---|
99 | |
---|
100 | function community_switch_user_to_admin($res, $methodName, $params) |
---|
101 | { |
---|
102 | global $user; |
---|
103 | |
---|
104 | $methods_of_permission_level[1] = array( |
---|
105 | 'pwg.categories.getList', |
---|
106 | 'pwg.tags.getAdminList', |
---|
107 | 'pwg.tags.add', |
---|
108 | 'pwg.images.exist', |
---|
109 | 'pwg.images.add', |
---|
110 | 'pwg.images.setInfo', |
---|
111 | 'pwg.images.addChunk', |
---|
112 | 'pwg.images.checkUpload', |
---|
113 | ); |
---|
114 | |
---|
115 | // permission_level 2 has all methods of level 1 + others |
---|
116 | $methods_of_permission_level[2] = array_merge( |
---|
117 | $methods_of_permission_level[1], |
---|
118 | array( |
---|
119 | 'pwg.categories.add', |
---|
120 | 'pwg.categories.setInfo', |
---|
121 | ) |
---|
122 | ); |
---|
123 | |
---|
124 | $query = ' |
---|
125 | SELECT |
---|
126 | permission_level |
---|
127 | FROM '.COMMUNITY_TABLE.' |
---|
128 | WHERE user_id = '.$user['id'].' |
---|
129 | ;'; |
---|
130 | $result = pwg_query($query); |
---|
131 | if (1 == mysql_num_rows($result)) |
---|
132 | { |
---|
133 | list($permission_level) = mysql_fetch_row($result); |
---|
134 | |
---|
135 | if (in_array($methodName, $methods_of_permission_level[$permission_level])) |
---|
136 | { |
---|
137 | $user['status'] = 'admin'; |
---|
138 | } |
---|
139 | } |
---|
140 | |
---|
141 | return $res; |
---|
142 | } |
---|
143 | |
---|
144 | add_event_handler('delete_user', 'community_delete_user'); |
---|
145 | function community_delete_user($user_id) |
---|
146 | { |
---|
147 | $query = ' |
---|
148 | DELETE |
---|
149 | FROM '.COMMUNITY_PERMISSIONS_TABLE.' |
---|
150 | WHERE user_id = '.$user_id.' |
---|
151 | ;'; |
---|
152 | pwg_query($query); |
---|
153 | |
---|
154 | community_reject_user_pendings($user_id); |
---|
155 | } |
---|
156 | |
---|
157 | ?> |
---|