[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 | |
---|
[9372] | 18 | global $prefixeTable; |
---|
| 19 | define('COMMUNITY_PERMISSIONS_TABLE', $prefixeTable.'community_permissions'); |
---|
| 20 | define('COMMUNITY_PENDINGS_TABLE', $prefixeTable.'community_pendings'); |
---|
| 21 | |
---|
[9444] | 22 | include_once(COMMUNITY_PATH.'include/functions_community.inc.php'); |
---|
[9516] | 23 | load_language('plugin.lang', COMMUNITY_PATH); |
---|
[9444] | 24 | |
---|
[3673] | 25 | /* Plugin admin */ |
---|
| 26 | add_event_handler('get_admin_plugin_menu_links', 'community_admin_menu'); |
---|
| 27 | function community_admin_menu($menu) |
---|
| 28 | { |
---|
[9516] | 29 | global $page; |
---|
| 30 | |
---|
| 31 | $query = ' |
---|
| 32 | SELECT |
---|
| 33 | COUNT(*) |
---|
| 34 | FROM '.COMMUNITY_PENDINGS_TABLE.' |
---|
| 35 | WHERE state = \'moderation_pending\' |
---|
| 36 | ;'; |
---|
| 37 | $result = pwg_query($query); |
---|
| 38 | list($page['community_nb_pendings']) = pwg_db_fetch_row($result); |
---|
| 39 | |
---|
| 40 | $name = 'Community'; |
---|
| 41 | if ($page['community_nb_pendings'] > 0) |
---|
| 42 | { |
---|
| 43 | $style = 'background-color:#666;'; |
---|
| 44 | $style.= 'color:white;'; |
---|
| 45 | $style.= 'padding:1px 5px;'; |
---|
| 46 | $style.= '-moz-border-radius:10px;'; |
---|
| 47 | $style.= '-webkit-border-radius:10px;'; |
---|
| 48 | $style.= '-border-radius:10px;'; |
---|
| 49 | $style.= 'margin-left:5px;'; |
---|
| 50 | |
---|
| 51 | $name.= '<span style="'.$style.'">'.$page['community_nb_pendings'].'</span>'; |
---|
| 52 | |
---|
| 53 | if (defined('IN_ADMIN') and IN_ADMIN and $page['page'] == 'intro') |
---|
| 54 | { |
---|
| 55 | global $template; |
---|
| 56 | |
---|
| 57 | $template->set_prefilter('intro', 'community_pendings_on_intro'); |
---|
| 58 | $template->assign( |
---|
| 59 | array( |
---|
| 60 | 'COMMUNITY_PENDINGS' => sprintf( |
---|
| 61 | '<a href="%s">'.l10n('%u pending photos').'</a>', |
---|
| 62 | get_root_url().'admin.php?page=plugin-community-pendings', |
---|
| 63 | $page['community_nb_pendings'] |
---|
| 64 | ), |
---|
| 65 | ) |
---|
| 66 | ); |
---|
| 67 | } |
---|
| 68 | } |
---|
| 69 | |
---|
[3673] | 70 | array_push( |
---|
| 71 | $menu, |
---|
| 72 | array( |
---|
[9516] | 73 | 'NAME' => $name, |
---|
[9372] | 74 | 'URL' => get_root_url().'admin.php?page=plugin-community' |
---|
[3673] | 75 | ) |
---|
| 76 | ); |
---|
| 77 | |
---|
| 78 | return $menu; |
---|
| 79 | } |
---|
| 80 | |
---|
[9516] | 81 | function community_pendings_on_intro($content, &$smarty) |
---|
| 82 | { |
---|
| 83 | $pattern = '#<li>\s*{\$DB_ELEMENTS\}#ms'; |
---|
| 84 | $replacement = '<li>{$COMMUNITY_PENDINGS}</li><li>{$DB_ELEMENTS}'; |
---|
| 85 | return preg_replace($pattern, $replacement, $content); |
---|
| 86 | } |
---|
| 87 | |
---|
[9372] | 88 | add_event_handler('loc_end_section_init', 'community_section_init'); |
---|
| 89 | function community_section_init() |
---|
| 90 | { |
---|
| 91 | global $tokens, $page; |
---|
| 92 | |
---|
| 93 | if ($tokens[0] == 'add_photos') |
---|
| 94 | { |
---|
| 95 | $page['section'] = 'add_photos'; |
---|
| 96 | } |
---|
| 97 | } |
---|
| 98 | |
---|
| 99 | add_event_handler('loc_end_index', 'community_index'); |
---|
| 100 | function community_index() |
---|
| 101 | { |
---|
| 102 | global $page; |
---|
| 103 | |
---|
| 104 | if (isset($page['section']) and $page['section'] == 'add_photos') |
---|
| 105 | { |
---|
| 106 | include(COMMUNITY_PATH.'add_photos.php'); |
---|
| 107 | } |
---|
| 108 | } |
---|
| 109 | |
---|
| 110 | add_event_handler('blockmanager_apply' , 'community_gallery_menu'); |
---|
| 111 | function community_gallery_menu($menu_ref_arr) |
---|
| 112 | { |
---|
| 113 | global $conf, $user; |
---|
| 114 | |
---|
| 115 | // conditional : depending on community permissions, display the "Add |
---|
| 116 | // photos" link in the gallery menu |
---|
[9444] | 117 | $user_permissions = community_get_user_permissions($user['id']); |
---|
[9372] | 118 | |
---|
[9444] | 119 | if (!$user_permissions['upload_whole_gallery'] and count($user_permissions['upload_categories']) == 0) |
---|
[9372] | 120 | { |
---|
[9444] | 121 | return; |
---|
[9372] | 122 | } |
---|
| 123 | |
---|
| 124 | $menu = & $menu_ref_arr[0]; |
---|
| 125 | |
---|
| 126 | if (($block = $menu->get_block('mbMenu')) != null ) |
---|
| 127 | { |
---|
| 128 | load_language('plugin.lang', COMMUNITY_PATH); |
---|
| 129 | |
---|
| 130 | array_splice( |
---|
| 131 | $block->data, |
---|
| 132 | count($block->data), |
---|
| 133 | 0, |
---|
| 134 | array( |
---|
| 135 | '' => array( |
---|
| 136 | 'URL' => make_index_url(array('section' => 'add_photos')), |
---|
| 137 | 'TITLE' => l10n('Upload your own photos'), |
---|
| 138 | 'NAME' => l10n('Upload Photos') |
---|
| 139 | ) |
---|
| 140 | ) |
---|
| 141 | ); |
---|
| 142 | } |
---|
| 143 | } |
---|
| 144 | |
---|
| 145 | |
---|
[3673] | 146 | add_event_handler('ws_invoke_allowed', 'community_switch_user_to_admin', EVENT_HANDLER_PRIORITY_NEUTRAL, 3); |
---|
| 147 | |
---|
| 148 | function community_switch_user_to_admin($res, $methodName, $params) |
---|
| 149 | { |
---|
| 150 | global $user; |
---|
| 151 | |
---|
| 152 | $methods_of_permission_level[1] = array( |
---|
| 153 | 'pwg.categories.getList', |
---|
| 154 | 'pwg.tags.getAdminList', |
---|
| 155 | 'pwg.tags.add', |
---|
| 156 | 'pwg.images.exist', |
---|
| 157 | 'pwg.images.add', |
---|
| 158 | 'pwg.images.setInfo', |
---|
| 159 | 'pwg.images.addChunk', |
---|
[6050] | 160 | 'pwg.images.checkUpload', |
---|
[3673] | 161 | ); |
---|
| 162 | |
---|
| 163 | // permission_level 2 has all methods of level 1 + others |
---|
| 164 | $methods_of_permission_level[2] = array_merge( |
---|
| 165 | $methods_of_permission_level[1], |
---|
| 166 | array( |
---|
| 167 | 'pwg.categories.add', |
---|
| 168 | 'pwg.categories.setInfo', |
---|
| 169 | ) |
---|
| 170 | ); |
---|
| 171 | |
---|
| 172 | $query = ' |
---|
| 173 | SELECT |
---|
| 174 | permission_level |
---|
| 175 | FROM '.COMMUNITY_TABLE.' |
---|
| 176 | WHERE user_id = '.$user['id'].' |
---|
| 177 | ;'; |
---|
| 178 | $result = pwg_query($query); |
---|
| 179 | if (1 == mysql_num_rows($result)) |
---|
| 180 | { |
---|
| 181 | list($permission_level) = mysql_fetch_row($result); |
---|
| 182 | |
---|
| 183 | if (in_array($methodName, $methods_of_permission_level[$permission_level])) |
---|
| 184 | { |
---|
| 185 | $user['status'] = 'admin'; |
---|
| 186 | } |
---|
| 187 | } |
---|
| 188 | |
---|
| 189 | return $res; |
---|
| 190 | } |
---|
| 191 | |
---|
| 192 | add_event_handler('delete_user', 'community_delete_user'); |
---|
| 193 | function community_delete_user($user_id) |
---|
| 194 | { |
---|
| 195 | $query = ' |
---|
| 196 | DELETE |
---|
[9452] | 197 | FROM '.COMMUNITY_PERMISSIONS_TABLE.' |
---|
[3673] | 198 | WHERE user_id = '.$user_id.' |
---|
| 199 | ;'; |
---|
| 200 | pwg_query($query); |
---|
[9452] | 201 | |
---|
| 202 | community_reject_user_pendings($user_id); |
---|
[3673] | 203 | } |
---|
| 204 | ?> |
---|