Changeset 9372


Ignore:
Timestamp:
Feb 25, 2011, 12:22:52 AM (9 years ago)
Author:
plg
Message:

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

Location:
extensions/community
Files:
7 added
14 deleted
6 edited

Legend:

Unmodified
Added
Removed
  • extensions/community/admin.php

    r3673 r9372  
    33// | Piwigo - a PHP based picture gallery                                  |
    44// +-----------------------------------------------------------------------+
    5 // | Copyright(C) 2009      Pierrick LE GALL             http://piwigo.org |
     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 |
    68// +-----------------------------------------------------------------------+
    79// | This program is free software; you can redistribute it and/or modify  |
     
    2628
    2729include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
     30include_once(PHPWG_ROOT_PATH.'admin/include/tabsheet.class.php');
     31
    2832load_language('plugin.lang', COMMUNITY_PATH);
    2933
    30 $conf['community_permission_levels'] = array(1,2);
    31 $admin_base_url = get_root_url().'admin.php?page=plugin&section=community%2Fadmin.php';
     34define('COMMUNITY_BASE_URL', get_root_url().'admin.php?page=plugin-community');
    3235
    3336// +-----------------------------------------------------------------------+
    3437// | Check Access and exit when user status is not ok                      |
    3538// +-----------------------------------------------------------------------+
     39
    3640check_status(ACCESS_ADMINISTRATOR);
    3741
    3842// +-----------------------------------------------------------------------+
    39 // |                               functions                               |
     43// | Tabs                                                                  |
    4044// +-----------------------------------------------------------------------+
    4145
    42 function get_permission_level_label($level)
     46$tabs = array(
     47  array(
     48    'code' => 'permissions',
     49    'label' => l10n('Upload Permissions'),
     50    ),
     51  array(
     52    'code' => 'pendings',
     53    'label' => l10n('Pending Photos'),
     54    ),
     55  );
     56
     57$tab_codes = array_map(
     58  create_function('$a', 'return $a["code"];'),
     59  $tabs
     60  );
     61
     62if (isset($_GET['tab']) and in_array($_GET['tab'], $tab_codes))
    4363{
    44   return '('.$level.') '.l10n( sprintf('Community level %d', $level) );
     64  $page['tab'] = $_GET['tab'];
     65}
     66else
     67{
     68  $page['tab'] = $tabs[0]['code'];
    4569}
    4670
    47 // +-----------------------------------------------------------------------+
    48 // |                            add permissions                            |
    49 // +-----------------------------------------------------------------------+
    50 
    51 if (isset($_POST['submit_add']) and !is_adviser())
     71$tabsheet = new tabsheet();
     72foreach ($tabs as $tab)
    5273{
    53   if (!is_numeric($_POST['user_options']))
    54   {
    55     array_push($page['errors'], 'invalid user');
    56   }
    57   if (!is_numeric($_POST['permission_level_options']))
    58   {
    59     array_push($page['errors'], 'invalid permission level');
    60   }
    61 
    62   if (count($page['errors']) == 0)
    63   {
    64     $query = '
    65 SELECT
    66     '.$conf['user_fields']['username'].' AS username
    67   FROM '.USERS_TABLE.'
    68   WHERE '.$conf['user_fields']['id'].' = '.$_POST['user_options'].'
    69 ;';
    70     list($username) = mysql_fetch_row(pwg_query($query));
    71     // remove any existing permission for this user
    72     $query = '
    73 DELETE
    74   FROM '.COMMUNITY_TABLE.'
    75   WHERE user_id = '.$_POST['user_options'].'
    76 ;';
    77     pwg_query($query);
    78 
    79     // creating the permission
    80     $query = '
    81 INSERT INTO '.COMMUNITY_TABLE.'
    82   (user_id, permission_level)
    83   VALUES
    84   ('.$_POST['user_options'].', '.$_POST['permission_level_options'].')
    85 ;';
    86     pwg_query($query);
    87 
    88     array_push(
    89       $page['infos'],
    90       sprintf(
    91         l10n('community permissions "%s" added/updated for "%s"'),
    92         get_permission_level_label($_POST['permission_level_options']),
    93         $username
    94         )
    95       );
    96   }
    97 
     74  $tabsheet->add(
     75    $tab['code'],
     76    $tab['label'],
     77    COMMUNITY_BASE_URL.'-'.$tab['code']
     78    );
    9879}
    99 
    100 // +-----------------------------------------------------------------------+
    101 // |                           remove permissions                          |
    102 // +-----------------------------------------------------------------------+
    103 
    104 if (isset($_GET['delete']) and !is_adviser())
    105 {
    106   if (is_numeric($_GET['delete']))
    107   {
    108     $query = '
    109 SELECT
    110     community.user_id,
    111     community.permission_level,
    112     u.'.$conf['user_fields']['username'].' AS username
    113   FROM '.COMMUNITY_TABLE.' AS community
    114     INNER JOIN '.USERS_TABLE.' AS u
    115       ON u.'.$conf['user_fields']['id'].' = community.user_id
    116   WHERE community.user_id = '.$_GET['delete'].'
    117 ;';
    118     $result = pwg_query($query);
    119     if (mysql_num_rows($result) == 0)
    120     {
    121       array_push($page['errors'], 'this user has no community permission yet');
    122     }
    123 
    124     if (count($page['errors']) == 0)
    125     {
    126       list($user_id, $permission_level, $username) = mysql_fetch_row($result);
    127 
    128       $query = '
    129 DELETE
    130   FROM '.COMMUNITY_TABLE.'
    131   WHERE user_id = '.$user_id.'
    132 ;';
    133       pwg_query($query);
    134 
    135       array_push(
    136         $page['infos'],
    137         sprintf(
    138           l10n('community permissions "%s" removed for "%s"'),
    139           get_permission_level_label($permission_level),
    140           $username
    141         )
    142       );
    143     }
    144   }
    145 }
     80$tabsheet->select($page['tab']);
     81$tabsheet->assign();
    14682
    14783// +-----------------------------------------------------------------------+
     
    15187$template->set_filenames(
    15288  array(
    153     'plugin_admin_content' => dirname(__FILE__).'/admin.tpl'
     89    'photos_add' => 'photos_add_'.$page['tab'].'.tpl'
    15490    )
    15591  );
    15692
    157 $template->assign(
    158     array(
    159       'F_ADD_ACTION'=> $admin_base_url,
    160     )
    161   );
    162 
    163 
    164 // user options
    165 $query = '
    166 SELECT
    167     u.'.$conf['user_fields']['id'].' AS id,
    168     u.'.$conf['user_fields']['username'].' AS username
    169   FROM '.USERS_TABLE.' AS u
    170     INNER JOIN '.USER_INFOS_TABLE.' AS ui
    171       ON u.'.$conf['user_fields']['id'].' = ui.user_id
    172   WHERE ui.status = "normal"
    173   ORDER BY username
    174 ;';
    175 $user_options = array();
    176 $result = pwg_query($query);
    177 while ($row = mysql_fetch_assoc($result))
    178 {
    179   $user_options[ $row['id'] ] = $row['username'];
    180 }
    181 $template->assign(
    182     array(
    183       'user_options'=> $user_options,
    184     )
    185   );
    186 
    187  
    188 // permission level options
    189 $permission_level_options = array();
    190 foreach ($conf['community_permission_levels'] as $level)
    191 {
    192   $permission_level_options[$level] = get_permission_level_label($level);
    193 }
    194 $template->assign(
    195     array(
    196       'permission_level_options'=> $permission_level_options,
    197     )
    198   );
    199 
    200 // user with community permissions
    201 $query = '
    202 SELECT
    203     community.user_id,
    204     community.permission_level,
    205     u.'.$conf['user_fields']['username'].' AS username
    206   FROM '.COMMUNITY_TABLE.' AS community
    207     INNER JOIN '.USERS_TABLE.' AS u
    208       ON u.'.$conf['user_fields']['id'].' = community.user_id
    209   ORDER BY username
    210 ;';
    211 $result = pwg_query($query);
    212 
    213 while ($row = mysql_fetch_assoc($result))
    214 {
    215   $template->append(
    216     'users',
    217     array(
    218       'NAME' => $row['username'],
    219       'PERMISSION_LEVEL' => get_permission_level_label($row['permission_level']),
    220       'U_DELETE' => $admin_base_url.'&delete='.$row['user_id']
    221       )
    222     );
    223 }
    224 
    22593// +-----------------------------------------------------------------------+
    226 // |                           sending html code                           |
     94// |                             Load the tab                              |
    22795// +-----------------------------------------------------------------------+
    22896
    229 $template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content');
     97include(COMMUNITY_PATH.'admin_'.$page['tab'].'.php');
    23098?>
  • extensions/community/language/en_UK/plugin.lang.php

    r3993 r9372  
    2020// +-----------------------------------------------------------------------+
    2121
    22 $lang['Community'] = 'Community';
    23 $lang['Add permissions'] = 'Add permissions';
    24 $lang['Permission level'] = 'Permission level';
    25 $lang['Community level 1'] = 'add photos';
    26 $lang['Community level 2'] = 'add photos + categories';
    27 $lang['community permissions "%s" added/updated for "%s"'] = 'community permissions "%s" added/updated for "%s"';
    28 $lang['community permissions "%s" removed for "%s"'] = 'community permissions "%s" removed for "%s"';
     22$lang['Add a permission'] = 'Add a permission';
     23$lang['Who?'] = 'Who?';
     24$lang['any visitor'] = 'any visitor';
     25$lang['any registered user'] = 'any registered user';
     26$lang['a specific user'] = 'a specific user';
     27$lang['a group'] = 'a group';
     28$lang['Where?'] = 'Where?';
     29$lang['The whole gallery'] = 'The whole gallery';
     30$lang['ability to create sub-albums'] = 'ability to create sub-albums';
     31$lang['Which level of trust?'] = 'Which level of trust?';
     32$lang['sub-albums creation'] = 'sub-albums creation';
     33$lang['Upload Permissions'] = 'Upload Permissions';
     34$lang['Pending Photos'] = 'Pending Photos';
     35$lang['Permission added'] = 'Permission added';
     36$lang['Permission removed'] = 'Permission removed';
     37$lang['%s (the user)'] = '%s (the user)';
     38$lang['%s (the group)'] = '%s (the group)';
     39$lang['low trust'] = 'low trust';
     40$lang['uploaded photos must be validated by an administrator'] = 'uploaded photos must be validated by an administrator';
     41$lang['high trust'] = 'high trust';
     42$lang['uploaded photos are directly displayed in the gallery'] = 'uploaded photos are directly displayed in the gallery';
     43$lang['%d photos validated'] = '%d photos validated';
     44$lang['%d photos rejected'] = '%d photos rejected';
     45$lang['web size'] = 'web size';
     46$lang['Zoom'] = 'Zoom';
     47$lang['Upload your own photos'] = 'Upload your own photos';
     48$lang['%d photos uploaded by %s'] = '%d photos uploaded by %s';
     49$lang['Validation page: %s'] = 'Validation page: %s';
     50$lang['%d photos uploaded into album "%s"'] = '%d photos uploaded into album "%s"';
     51$lang['Hi administrators,'] = 'Hi administrators,';
    2952?>
  • extensions/community/language/fr_FR/description.txt

    r4842 r9372  
    1 Permettre à des utilisateurs d'ajouter des photos avec pLoader
     1Permet aux utilisateurs d'ajouter des photos sans être administrateur
  • extensions/community/language/fr_FR/plugin.lang.php

    r3673 r9372  
    33// | Piwigo - a PHP based picture gallery                                  |
    44// +-----------------------------------------------------------------------+
    5 // | Copyright(C) 2009      Pierrick LE GALL             http://piwigo.org |
     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 |
    68// +-----------------------------------------------------------------------+
    79// | This program is free software; you can redistribute it and/or modify  |
     
    2022// +-----------------------------------------------------------------------+
    2123
    22 $lang['Community'] = 'Communauté';
    23 $lang['Add permissions'] = 'Ajouter des permissions';
    24 $lang['Permission level'] = 'Niveau de permission';
    25 $lang['Community level 1'] = 'ajouter des photos';
    26 $lang['Community level 2'] = 'ajouter des photos + categories';
    27 $lang['community permissions "%s" added/updated for "%s"'] = 'permissions communautaires "%s" ajoutées ou mises à jour pour "%s"';
    28 $lang['community permissions "%s" removed for "%s"'] = 'permissions communautaires "%s" supprimées pour "%s"';
     24$lang['Add a permission'] = 'Ajouter une permission';
     25$lang['Who?'] = 'Qui ?';
     26$lang['any visitor'] = 'n\'importe quel visiteur';
     27$lang['any registered user'] = 'n\'importe quel utilisateur enregistré';
     28$lang['a specific user'] = 'un utilisateur en particulier';
     29$lang['a group'] = 'un groupe';
     30$lang['Where?'] = 'Où ?';
     31$lang['The whole gallery'] = 'La galerie toute entière';
     32$lang['ability to create sub-albums'] = 'possibilité de créer des sous-albums';
     33$lang['Which level of trust?'] = 'Quel degré de confiance ?';
     34$lang['sub-albums creation'] = 'création de sous-albums';
     35$lang['Upload Permissions'] = 'Permissions d\'ajout';
     36$lang['Pending Photos'] = 'Photos en attente';
     37$lang['Permission added'] = 'Permission enregistrée';
     38$lang['Permission removed'] = 'Permission supprimée';
     39$lang['%s (the user)'] = '%s (l\'utilisateur)';
     40$lang['%s (the group)'] = '%s (le groupe)';
     41$lang['low trust'] = 'confiance faible';
     42$lang['uploaded photos must be validated by an administrator'] = 'les photos ajoutées doivent être validées par un administrateur';
     43$lang['high trust'] = 'confiance élevée';
     44$lang['uploaded photos are directly displayed in the gallery'] = 'les photos ajoutées sont directement visibles dans la galerie';
     45$lang['%d photos validated'] = '%d photos validées';
     46$lang['%d photos rejected'] = '%d photos rejetées';
     47$lang['web size'] = 'taille web';
     48$lang['Zoom'] = 'Zoom';
     49$lang['Upload your own photos'] = 'Ajoutez vos propres photos';
     50$lang['%d photos uploaded by %s'] = '%d photos ajoutées par %s';
     51$lang['Validation page: %s'] = 'Page de validation : %s';
     52$lang['%d photos uploaded into album "%s"'] = '%d photos ajoutée à l\'album "%s"';
     53$lang['Hi administrators,'] = 'Bonjours chers administrateurs,';
    2954?>
  • extensions/community/main.inc.php

    r6050 r9372  
    1515
    1616define('COMMUNITY_PATH' , PHPWG_PLUGINS_PATH.basename(dirname(__FILE__)).'/');
    17 include_once (COMMUNITY_PATH.'/include/constants.php');
     17
     18global $prefixeTable;
     19define('COMMUNITY_TABLE', $prefixeTable.'community');
     20define('COMMUNITY_PERMISSIONS_TABLE', $prefixeTable.'community_permissions');
     21define('COMMUNITY_PENDINGS_TABLE', $prefixeTable.'community_pendings');
    1822
    1923/* Plugin admin */
     
    2630    array(
    2731      'NAME' => 'Community',
    28       'URL'  => get_admin_plugin_menu_link(dirname(__FILE__).'/admin.php')
     32      'URL'  => get_root_url().'admin.php?page=plugin-community'
    2933      )
    3034    );
     
    3236  return $menu;
    3337}
     38
     39add_event_handler('loc_end_section_init', 'community_section_init');
     40function community_section_init()
     41{
     42  global $tokens, $page;
     43 
     44  if ($tokens[0] == 'add_photos')
     45  {
     46    $page['section'] = 'add_photos';
     47  }
     48}
     49
     50add_event_handler('loc_end_index', 'community_index');
     51function community_index()
     52{
     53  global $page;
     54 
     55  if (isset($page['section']) and $page['section'] == 'add_photos')
     56  {
     57    include(COMMUNITY_PATH.'add_photos.php');
     58  }
     59}
     60
     61add_event_handler('blockmanager_apply' , 'community_gallery_menu');
     62function community_gallery_menu($menu_ref_arr)
     63{
     64  global $conf, $user;
     65
     66  // conditional : depending on community permissions, display the "Add
     67  // photos" link in the gallery menu
     68 
     69  // admins are not concerned about community permissions
     70  if (!is_admin())
     71  {
     72    // what are the user groups?
     73    $query = '
     74SELECT
     75    group_id
     76  FROM '.USER_GROUP_TABLE.'
     77  WHERE user_id = '.$user['id'].'
     78;';
     79    $user_group_ids = array_from_query($query, 'group_id');
     80
     81    $query = '
     82SELECT
     83    COUNT(*)
     84  FROM '.COMMUNITY_PERMISSIONS_TABLE.'
     85  WHERE (type = \'any_visitor\')';
     86
     87    if ($user['id'] != $conf['guest_id'])
     88    {
     89      $query.= '
     90    OR (type = \'any_registered_user\')
     91    OR (type = \'user\' AND user_id = '.$user['id'].')
     92    OR (type = \'group\' AND group_id IN ('.implode(',', $user_group_ids).'))
     93';
     94    }
     95   
     96    $query.= '
     97;';
     98
     99    list($counter) = pwg_db_fetch_row(pwg_query($query));
     100    if (0 == $counter)
     101    {
     102      return;
     103    }
     104  }
     105
     106  $menu = & $menu_ref_arr[0];
     107
     108  if (($block = $menu->get_block('mbMenu')) != null )
     109  {
     110    load_language('plugin.lang', COMMUNITY_PATH);
     111
     112    array_splice(
     113      $block->data,
     114      count($block->data),
     115      0,
     116      array(
     117        '' => array(
     118          'URL' => make_index_url(array('section' => 'add_photos')),
     119          'TITLE' => l10n('Upload your own photos'),
     120          'NAME' => l10n('Upload Photos')
     121          )
     122        )
     123      );
     124  }
     125}
     126
    34127
    35128add_event_handler('ws_invoke_allowed', 'community_switch_user_to_admin', EVENT_HANDLER_PRIORITY_NEUTRAL, 3);
  • extensions/community/maintain.inc.php

    r3673 r9372  
    1010function plugin_install()
    1111{
    12   $query = "
    13 CREATE TABLE IF NOT EXISTS ".COMMUNITY_TABLE." (
    14   user_id smallint(5) NOT NULL default '0',
    15   permission_level tinyint NOT NULL default 1,
    16   PRIMARY KEY  (user_id)
     12  global $conf, $prefixeTable;
     13
     14  if ('mysql' == $conf['dblayer'])
     15  {
     16    $query = '
     17CREATE TABLE '.$prefixeTable.'community_permissions (
     18  id int(11) NOT NULL AUTO_INCREMENT,
     19  type varchar(255) NOT NULL,
     20  group_id smallint(5) unsigned DEFAULT NULL,
     21  user_id smallint(5) DEFAULT NULL,
     22  category_id smallint(5) unsigned DEFAULT NULL,
     23  create_subcategories enum(\'true\',\'false\') NOT NULL DEFAULT \'false\',
     24  moderated enum(\'true\',\'false\') NOT NULL DEFAULT \'true\',
     25  PRIMARY KEY (id)
     26) ENGINE=MyISAM DEFAULT CHARACTER SET utf8
     27;';
     28    pwg_query($query);
     29
     30    $query = '
     31CREATE TABLE '.$prefixeTable.'community_pendings (
     32  image_id mediumint(8) unsigned NOT NULL,
     33  state varchar(255) NOT NULL,
     34  added_on datetime NOT NULL,
     35  validated_by smallint(5) DEFAULT NULL
     36) ENGINE=MyISAM DEFAULT CHARACTER SET utf8
     37;';
     38    pwg_query($query);
     39  }
     40  elseif ('pgsql' == $conf['dblayer'])
     41  {
     42    $query = '
     43CREATE TABLE "'.$prefixeTable.'community_permissions" (
     44  "id" serial NOT NULL,
     45  "type" VARCHAR(255) NOT NULL,
     46  "group_id" INTEGER,
     47  "user_id" INTEGER,
     48  "category_id" INTEGER,
     49  "create_subcategories" BOOLEAN default false,
     50  "moderated" BOOLEAN default true,
     51  PRIMARY KEY ("id")
    1752)
    18 ;";
    19   pwg_query($query);
     53;';
     54    pwg_query($query);
     55
     56    $query = '
     57CREATE TABLE "'.$prefixeTable.'community_pendings" (
     58  image_id INTEGER NOT NULL,
     59  state VARCHAR(255) NOT NULL,
     60  added_on TIMESTAMP NOT NULL,
     61  validated_by INTEGER
     62)
     63;';
     64    pwg_query($query);
     65  }
     66  else
     67  {
     68    $query = '
     69CREATE TABLE "'.$prefixeTable.'community_permissions" (
     70  "id" INTEGER NOT NULL,
     71  "type" VARCHAR(255) NOT NULL,
     72  "group_id" INTEGER,
     73  "user_id" INTEGER,
     74  "category_id" INTEGER,
     75  "create_subcategories" BOOLEAN default false,
     76  "moderated" BOOLEAN default true,
     77  PRIMARY KEY ("id")
     78)
     79;';
     80    pwg_query($query);
     81
     82    $query = '
     83CREATE TABLE "'.$prefixeTable.'community_pendings" (
     84  image_id INTEGER NOT NULL,
     85  state VARCHAR(255) NOT NULL,
     86  added_on TIMESTAMP NOT NULL,
     87  validated_by INTEGER
     88)
     89;';
     90    pwg_query($query);
     91  }
    2092}
    2193
    2294function plugin_uninstall()
    2395{
    24   $query = 'DROP TABLE '.COMMUNITY_TABLE.';';
     96  global $prefixeTable;
     97 
     98  $query = 'DROP TABLE '.$prefixeTable.'community_permissions;';
     99  pwg_query($query);
     100
     101  $query = 'DROP TABLE '.$prefixeTable.'community_pendings;';
    25102  pwg_query($query);
    26103}
Note: See TracChangeset for help on using the changeset viewer.