source: extensions/community/include/functions_community.inc.php @ 9372

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

Rewritten version of Community plugin :

  • user upload (web form on gallery side)
  • precise permission manage (who, where, with moderation or not, ability to create sub-albums)
  • email notification to administrators when photos are uploaded

Requires Piwigo 2.2.0RC3

File size: 3.4 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Piwigo - a PHP based photo gallery                                    |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2008-2011 Piwigo Team                  http://piwigo.org |
6// | Copyright(C) 2003-2008 PhpWebGallery Team    http://phpwebgallery.net |
7// | Copyright(C) 2002-2003 Pierrick LE GALL   http://le-gall.net/pierrick |
8// +-----------------------------------------------------------------------+
9// | This program is free software; you can redistribute it and/or modify  |
10// | it under the terms of the GNU General Public License as published by  |
11// | the Free Software Foundation                                          |
12// |                                                                       |
13// | This program is distributed in the hope that it will be useful, but   |
14// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
15// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
16// | General Public License for more details.                              |
17// |                                                                       |
18// | You should have received a copy of the GNU General Public License     |
19// | along with this program; if not, write to the Free Software           |
20// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
21// | USA.                                                                  |
22// +-----------------------------------------------------------------------+
23
24function community_get_user_permissions($user_id)
25{
26  global $conf;
27
28  $return = array(
29    'upload_whole_gallery' => false,
30    'create_whole_gallery' => false,
31    'create_categories' => array(),
32    'upload_categories' => array(),
33    'permission_ids' => array(),
34    );
35
36  $user_permissions = array();
37 
38  // what are the user groups?
39  $query = '
40SELECT
41    group_id
42  FROM '.USER_GROUP_TABLE.'
43  WHERE user_id = '.$user_id.'
44;';
45  $user_group_ids = array_from_query($query, 'group_id');
46
47  $query = '
48SELECT
49    id,
50    category_id,
51    create_subcategories
52  FROM '.COMMUNITY_PERMISSIONS_TABLE.'
53  WHERE (type = \'any_visitor\')';
54
55  if ($user_id != $conf['guest_id'])
56  {
57  $query.= '
58    OR (type = \'any_registered_user\')
59    OR (type = \'user\' AND user_id = '.$user_id.')
60    OR (type = \'group\' AND group_id IN ('.implode(',', $user_group_ids).'))
61';
62  }
63   
64  $query.= '
65;';
66
67  $result = pwg_query($query);
68  while ($row = pwg_db_fetch_assoc($result))
69  {
70    array_push($return['permission_ids'], $row['id']);
71   
72    if (empty($row['category_id']))
73    {
74      $return ['upload_whole_gallery'] = true;
75    }
76    else
77    {
78      array_push($return['upload_categories'], $row['category_id']);
79    }
80
81    if ('true' == $row['create_subcategories'])
82    {
83      if (empty($row['category_id']))
84      {
85        $return ['create_whole_gallery'] = true;
86      }
87      else
88      {
89        array_push($return['create_categories'], $row['category_id']);
90      }
91    }
92  }
93
94  if (!$return['upload_whole_gallery'])
95  {
96    $return['upload_categories'] = get_subcat_ids($return['upload_categories']);
97  }
98
99  if (!$return ['create_whole_gallery'] and count($return['create_categories']) > 0)
100  {
101    $return['create_categories'] = get_subcat_ids($return['create_categories']);
102  }
103
104  return $return;
105}
106
107?>
Note: See TracBrowser for help on using the repository browser.