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

Last change on this file since 5277 was 3673, checked in by plg, 15 years ago

first import for the Community plugin : basic feature to declare a list of
non admin users able to add photos with web API.

File size: 1.9 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__)).'/');
17include_once (COMMUNITY_PATH.'/include/constants.php');
18
19/* Plugin admin */
20add_event_handler('get_admin_plugin_menu_links', 'community_admin_menu');
21
22function 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
35add_event_handler('ws_invoke_allowed', 'community_switch_user_to_admin', EVENT_HANDLER_PRIORITY_NEUTRAL, 3);
36
37function 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 = '
61SELECT
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
80add_event_handler('delete_user', 'community_delete_user');
81function community_delete_user($user_id)
82{
83  $query = '
84DELETE
85  FROM '.COMMUNITY_TABLE.'
86  WHERE user_id = '.$user_id.'
87;';
88  pwg_query($query);
89}
90
91?>
Note: See TracBrowser for help on using the repository browser.