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

Last change on this file since 9034 was 6050, checked in by plg, 15 years ago

In Piwigo 2.1, we have a new pwg.images.checkUpload method and it requires
admin user status.

File size: 2.0 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    'pwg.images.checkUpload',
50    );
51
52  // permission_level 2 has all methods of level 1 + others
53  $methods_of_permission_level[2] = array_merge(
54    $methods_of_permission_level[1],
55    array(
56      'pwg.categories.add',
57      'pwg.categories.setInfo',
58      )
59    );
60   
61  $query = '
62SELECT
63    permission_level
64  FROM '.COMMUNITY_TABLE.'
65  WHERE user_id = '.$user['id'].'
66;';
67  $result = pwg_query($query);
68  if (1 == mysql_num_rows($result))
69  {
70    list($permission_level) = mysql_fetch_row($result);
71
72    if (in_array($methodName, $methods_of_permission_level[$permission_level]))
73    {
74      $user['status'] = 'admin';
75    }
76  }
77
78  return $res;
79}
80
81add_event_handler('delete_user', 'community_delete_user');
82function community_delete_user($user_id)
83{
84  $query = '
85DELETE
86  FROM '.COMMUNITY_TABLE.'
87  WHERE user_id = '.$user_id.'
88;';
89  pwg_query($query);
90}
91
92?>
Note: See TracBrowser for help on using the repository browser.