Show
Ignore:
Timestamp:
02/25/11 00:22:52 (2 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

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • 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);