source: extensions/community/main.inc.php @ 9452

Last change on this file since 9452 was 9452, checked in by plg, 13 years ago

bug fixed: deleting a user also deletes upload permissions linked to this user and reject pending photos added by this user

File size: 3.5 KB
Line 
1<?php
2/*
3Plugin Name: Community
4Version: auto
5Description: Non admin users can add photos
6Plugin URI: http://piwigo.org/ext/extension_view.php?eid=303
7Author: plg
8Author URI: http://piwigo.wordpress.com
9*/
10
11if (!defined('PHPWG_ROOT_PATH'))
12{
13  die('Hacking attempt!');
14}
15
16define('COMMUNITY_PATH' , PHPWG_PLUGINS_PATH.basename(dirname(__FILE__)).'/');
17
18global $prefixeTable;
19define('COMMUNITY_PERMISSIONS_TABLE', $prefixeTable.'community_permissions');
20define('COMMUNITY_PENDINGS_TABLE', $prefixeTable.'community_pendings');
21
22include_once(COMMUNITY_PATH.'include/functions_community.inc.php');
23
24/* Plugin admin */
25add_event_handler('get_admin_plugin_menu_links', 'community_admin_menu');
26
27function 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
40add_event_handler('loc_end_section_init', 'community_section_init');
41function community_section_init()
42{
43  global $tokens, $page;
44 
45  if ($tokens[0] == 'add_photos')
46  {
47    $page['section'] = 'add_photos';
48  }
49}
50
51add_event_handler('loc_end_index', 'community_index');
52function 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
62add_event_handler('blockmanager_apply' , 'community_gallery_menu');
63function 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
98add_event_handler('ws_invoke_allowed', 'community_switch_user_to_admin', EVENT_HANDLER_PRIORITY_NEUTRAL, 3);
99
100function 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 = '
125SELECT
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
144add_event_handler('delete_user', 'community_delete_user');
145function community_delete_user($user_id)
146{
147  $query = '
148DELETE
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?>
Note: See TracBrowser for help on using the repository browser.