Changeset 6610


Ignore:
Timestamp:
06/27/10 16:34:44 (10 years ago)
Author:
vdigital
Message:

Configuration and a complete virtual management ( Physical are not managed at all ).

Location:
extensions/virtualAutoGrant
Files:
11 added
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/virtualAutoGrant/virtual_categories_granted_to_creator.php

    r6603 r6610  
    22/* Virtual AutoGrant */ 
    33if (!defined('PHPWG_ROOT_PATH') or !defined('VAG_DIR')) die('Hacking attempt!'); 
    4 if ( !function_exists( 'virtual_categories_granted_to_creator' ) ) { 
    5         add_event_handler('invalidate_user_cache', 'virtual_categories_granted_to_creator', 20); 
     4global $conf; 
     5include_once( VAG_PATH . 'VAG_default.php'); 
     6$vag = & $conf['virtual_AutoGrant']; 
    67 
    7         function  virtual_categories_granted_to_creator($full) { 
    8     if ( !function_exists( 'ws_categories_add' ) ) return false; 
    9           global $user, $conf; 
     8// General case for set private (exception synchronisation (categories are not virtual ones)) 
     9if ( $conf['newcat_default_status'] == 'public' and $vag['set_private'] == 1  
     10    and defined('IN_ADMIN') and IN_ADMIN and !function_exists( 'VAG_set_private' ) ) { 
     11  add_event_handler('get_admin_plugin_menu_links', 'VAG_set_private'); 
     12  function VAG_set_private($menu) { 
     13    global $page; 
     14    if ( isset($page['page']) and $page['page'] != 'site_manager' ) 
     15      $conf['newcat_default_status'] = 'private'; 
     16    return $menu; 
     17  } 
     18}  
     19// General case for set public (exception synchronisation (categories are not virtual ones)) 
     20if ( $conf['newcat_default_status'] == 'private' and $vag['set_private'] == 0  
     21    and defined('IN_ADMIN') and IN_ADMIN and !function_exists( 'VAG_set_public' ) ) { 
     22  add_event_handler('get_admin_plugin_menu_links', 'VAG_set_public'); 
     23  function VAG_set_public($menu) { 
     24    global $page; 
     25    if ( isset($page['page']) and $page['page'] != 'site_manager' ) 
     26      $conf['newcat_default_status'] = 'public'; 
     27    return $menu; 
     28  } 
     29}  
     30// General case for grant to someone 
     31// Don't grant on physical categories  
     32if ( ($vag['grant_to_creator'] == 1 or $vag['grant_to_webmaster'] == 1) 
     33    and defined('IN_ADMIN') and IN_ADMIN and !function_exists( 'VAG_grant_to_prepare' ) ) { 
     34                add_event_handler('get_admin_plugin_menu_links', 'VAG_grant_to_prepare'); 
     35  function VAG_grant_to_prepare($menu) { 
     36    global $conf, $page, $vag; 
     37    if ( !isset($page['page']) or $page['page'] == 'site_manager' ) return false; 
     38    list($max_id) = pwg_db_fetch_row(pwg_query('SELECT MAX(id) FROM '.CATEGORIES_TABLE . ';')); 
     39    $vag['lastcat before'] == $max_id; 
     40    add_event_handler('loc_end_admin', 'VAG_grant_to_somebody'); 
     41    return $menu; 
     42  } 
     43  if ( !function_exists( 'VAG_grant_to_somebody' ) ) { 
     44    function VAG_grant_to_somebody() { 
     45      global $conf, $vag, $user; 
     46      if ( !isset($vag['lastcat before']) ) return false; 
     47      list($new_id) = pwg_db_fetch_row(pwg_query('SELECT MAX(id) FROM '.CATEGORIES_TABLE 
     48      . ' WHERE id > ' . $vag['lastcat before'] . ' AND site_id IS NULL;')); 
     49      if ( empty($newid) ) return false; 
     50      if ( $vag['grant_to_creator'] == 1 or $vag['grant_to_webmaster'] == 1 ) { 
     51        if ( $vag['grant_to_creator'] == 1 ) $insert[] = array('user_id' => $user['id'], 'cat_id' => $newid); 
     52        if ( $user['id'] != $conf['webmaster_id'] and $vag['grant_to_webmaster'] == 1 ) 
     53          $insert[] = array('user_id' => $conf['webmaster_id'], 'cat_id' => $newid); 
     54        mass_inserts(USER_ACCESS_TABLE, array('user_id','cat_id'), $insert); 
     55      } 
     56    } 
     57  } 
     58}  
     59 
     60// API cases : Just do it (even in Admin Photos Add case or other plugins cases)   
     61if ( !function_exists( 'VAG_set_private_by_API' ) ) { 
     62        add_event_handler('invalidate_user_cache', 'VAG_set_private_by_API', 20); 
     63 
     64        function  VAG_set_private_by_API($full) { 
     65    if ( !function_exists( 'ws_categories_add' ) ) return false; // That isn't an API request 
     66          global $user, $conf, $vag; 
    1067    if ( $_REQUEST['method'] == 'pwg.categories.add' ) { 
    1168      list($inserted_id) = pwg_db_fetch_row(pwg_query('SELECT MAX(id) FROM '.CATEGORIES_TABLE 
    12       . ' WHERE name = \'' .pwg_db_real_escape_string($_REQUEST['name']) . '\';')); 
    13       set_cat_status(array($inserted_id), 'private');       
    14       $insert[] = array('user_id' => $user['id'], 'cat_id' => $inserted_id); 
    15       $insert[] = array('user_id' => $conf['webmaster_id'], 'cat_id' => $inserted_id); 
    16       mass_inserts(USER_ACCESS_TABLE, array('user_id','cat_id'), $insert); 
     69      . ' WHERE name = \'' .pwg_db_real_escape_string($_REQUEST['name']) . '\' AND site_id IS NULL;')); 
     70      # Note:  AND site_id IS NULL because synchro could be running in // 
     71      if ( $vag['set_private_by_API'] == 1 ) set_cat_status(array($inserted_id), 'private'); 
     72        else set_cat_status(array($inserted_id), 'public'); 
     73      if ( ($vag['grant_to_creator'] == 1 or $vag['grant_to_webmaster'] == 1 ) and $vag['set_private_by_API'] == 1 ) { 
     74        if ( $vag['grant_to_creator'] == 1 ) $insert[] = array('user_id' => $user['id'], 'cat_id' => $inserted_id); 
     75        if ( $user['id'] != $conf['webmaster_id'] and $vag['grant_to_webmaster'] == 1 ) 
     76          $insert[] = array('user_id' => $conf['webmaster_id'], 'cat_id' => $inserted_id); 
     77        mass_inserts(USER_ACCESS_TABLE, array('user_id','cat_id'), $insert); 
     78      } 
     79      $vag['lastcat before'] = $inserted_id; # Admin Photos Add does not need to redo the job 
    1780    } 
    18     if ( $_REQUEST['method'] == 'pwg.images.add' and isset($_REQUEST['original_sum']) ) { 
     81    // "Who can see" management ( only for API, Synchro or old HTTP management on gallery side are ignored ) 
     82    if ( $_REQUEST['method'] == 'pwg.images.add' and isset($_REQUEST['original_sum'])  
     83        and $vag['set_who_can_see'] == 1 ) { 
    1984      # image to update 
    2085      if ('md5sum' == $conf['uniqueness_mode']) $where_clause = "md5sum = '".pwg_db_real_escape_string($_REQUEST['original_sum'])."'"; 
    2186      if ('filename' == $conf['uniqueness_mode'] and isset($_REQUEST['original_filename']) )  
    2287          $where_clause = "file = '".pwg_db_real_escape_string($_REQUEST['original_filename'])."'"; 
    23       if ( !isset($where_clause) or is_webmaster() ) return false; 
    24       if ( $user['level'] == $conf['available_permission_levels'][0] ) return false;     
     88      if ( !isset($where_clause) or (is_webmaster() and $vag['webmaster_set_who_can_see'] == 1) ) return false; 
     89      if ( $user['level'] == $conf['available_permission_levels'][0] ) return false;   // Non privacy level won't force it 
     90      if (!isset($_REQUEST['categories'])) return false; 
     91      $tokens = explode(';', pwg_db_real_escape_string($_REQUEST['categories'])); 
     92      $cat_ids = array(); 
     93      foreach ($tokens as $token) { 
     94        list($cat_id) = explode(',', $token); 
     95        if (!preg_match('/^\d+$/', $cat_id)) continue; 
     96        array_push($cat_ids, $cat_id); 
     97      } 
     98      $cat_ids = array_unique($cat_ids); 
     99      if (count($cat_ids) != 0) $w = ' AND id IN ('.implode(',', $cat_ids).')'; else $w =''; 
     100      list($count_public_cat) = pwg_db_fetch_row(pwg_query('SELECT count(*) FROM '.CATEGORIES_TABLE 
     101      . ' WHERE status = \'public\' ' . $w . ' AND site_id IS NULL;')); 
     102      // No public category = all are private => maybe we can ignore "Who can see" 
     103      if ( $count_public_cat == 0 and $vag['ignore_who_can_see_on_private'] == 1 ) return false; 
    25104      $r = pwg_query('UPDATE '.IMAGES_TABLE.' SET level = ' . $user['level'] . ' WHERE level < '. $user['level']  
    26105          .' AND ' . $where_clause . ';'); 
     
    28107        } 
    29108} 
     109// Configuration menu 
     110if ( !function_exists( 'VAG_admin_menu' ) ) { 
     111        if ( defined('IN_ADMIN') and IN_ADMIN ) { 
     112                add_event_handler('get_admin_plugin_menu_links', 'VAG_admin_menu'); 
     113    function VAG_admin_menu($menu) { 
     114        array_push($menu, array( 
     115                'NAME' => 'Virtual AutoGrant', 
     116                'URL' => get_admin_plugin_menu_link(dirname(__FILE__).'/VAG_admin.php') 
     117        )); 
     118        return $menu; 
     119    } 
     120  } 
     121} 
    30122?> 
Note: See TracChangeset for help on using the changeset viewer.