- Timestamp:
- Jul 1, 2010, 10:55:30 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/virtualAutoGrant/virtual_categories_granted_to_creator.php
r6619 r6650 4 4 global $conf; 5 5 include_once( VAG_PATH . 'VAG_default.php'); 6 $vag = & $conf['virtual_AutoGrant'];7 6 8 // General case for set private (exception synchronisation (categories are not virtual ones)) 9 if ( $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, $conf; 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)) 20 if ( $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, $conf; 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 32 if ( ($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; # Not Virtual 38 list($max_id) = pwg_db_fetch_row(pwg_query('SELECT MAX(id) FROM '.CATEGORIES_TABLE . ';')); 39 $vag['lastcat before'] == $max_id; 40 list($max_id) = pwg_db_fetch_row(pwg_query('SELECT MAX(id) FROM '.IMAGES_TABLE . ';')); 41 $vag['lastimg before'] == $max_id; 42 add_event_handler('loc_end_admin', 'VAG_grant_to_somebody'); 43 return $menu; 44 } 45 if ( !function_exists( 'VAG_grant_to_somebody' ) ) { 46 function VAG_grant_to_somebody() { 47 global $conf, $vag, $user; 48 if ( empty($vag['lastcat before']) ) $vag['lastcat before'] = 0; 49 if ( empty($vag['lastimg before']) ) $vag['lastimg before'] = 0; 50 list($new_id) = pwg_db_fetch_row(pwg_query('SELECT MAX(id) FROM '.CATEGORIES_TABLE 51 . ' WHERE id > ' . $vag['lastcat before'] . ' AND site_id IS NULL;')); 52 if ( empty($newid) ) return false; 53 if ( $vag['grant_to_creator'] == 1 or $vag['grant_to_webmaster'] == 1 ) { 54 if ( $vag['grant_to_creator'] == 1 ) $insert[] = array('user_id' => $user['id'], 'cat_id' => $newid); 55 if ( $user['id'] != $conf['webmaster_id'] and $vag['grant_to_webmaster'] == 1 ) 56 $insert[] = array('user_id' => $conf['webmaster_id'], 'cat_id' => $newid); 7 // Internal case 8 if ( defined('IN_ADMIN') and IN_ADMIN and !function_exists( 'VAG_internal_add_case' ) ) { 9 add_event_handler('invalidate_user_cache', 'VAG_internal_add_case', 21 ); 10 function VAG_internal_add_case($full) { 11 if ( !defined('PHOTOS_ADD_BASE_URL') ) return false; # Nothing else to do 12 global $conf, $user, $page, $category_id, $image_ids, $category_name; 13 load_language('plugin.lang', VAG_PATH); 14 $vag = & $conf['virtual_AutoGrant']; 15 # Note: don't change it if existing 16 if ( 'new' == $_POST['category_type'] ) { 17 if ( $vag['set_private'] == 1 ) set_cat_status(array($category_id), 'private'); 18 else set_cat_status(array($category_id), 'public'); 19 if ( $vag['grant_to_creator'] == 1 ) $insert[] = array('user_id' => $user['id'], 'cat_id' => $category_id); 20 if ( $user['id'] != $conf['webmaster_id'] and $vag['grant_to_webmaster'] == 1 ) 21 $insert[] = array('user_id' => $conf['webmaster_id'], 'cat_id' => $category_id); 22 if ( $vag['grant_to_creator'] == 1 or $vag['grant_to_webmaster'] == 1 and $vag['set_private'] == 1 ) 57 23 mass_inserts(USER_ACCESS_TABLE, array('user_id','cat_id'), $insert); 58 }59 // Who can see60 if ( $vag['set_who_can_see'] == 0 ) return false;61 if ( is_webmaster() and $vag['webmaster_set_who_can_see'] == 1) return false;62 // New image_ids63 $img_ids = array_from_query('SELECT id FROM ' . IMAGES_TABLE . ' WHERE id > ' . $vag['lastimg before'] . ';', 'id');64 if (count($img_ids) == 0) return false;65 // New image_ids which are associated to a public category at least66 if ($vag['ignore_who_can_see_on_private'] == 1)67 $img_ids = array_from_query('SELECT image_id FROM ' . IMAGE_CATEGORY_TABLE68 . ' WHERE category_id IN (SELECT id FROM ' . CATEGORIES_TABLE . ' WHERE status = \'public\')'69 . ' AND image_id IN ('.implode(',', $img_ids).');');24 array_push( $page['infos'], sprintf( l10n('You have got a private access to %s'), '<em>'.$category_name.'</em>') ); 25 } 26 // Who can see New image_ids 27 if (count($image_ids) == 0) return true; 28 if ( $vag['set_who_can_see'] == 0 ) return true; 29 if ( is_webmaster() and $vag['webmaster_set_who_can_see'] == 1) return true; 30 // New image_ids which are associated to a public category at least 31 if ($vag['ignore_who_can_see_on_private'] == 1) 32 $image_ids = array_from_query('SELECT image_id FROM ' . IMAGE_CATEGORY_TABLE 33 . ' WHERE category_id IN (SELECT id FROM ' . CATEGORIES_TABLE . ' WHERE status = \'public\')' 34 . ' AND image_id IN ('.implode(',', $image_ids).');'); 35 if (count($image_ids) > 0) { 70 36 $r = pwg_query('UPDATE '.IMAGES_TABLE.' SET level = ' . $user['level'] . ' WHERE level < '. $user['level'] 71 . ' AND id IN ('.implode(',', $img_ids).');'); 37 . ' AND id IN ('.implode(',', $image_ids).');'); 38 array_push( $page['infos'], 39 l10n_dec( 'Virtual AutoGrant has forced "Who can see" on %d image', 40 'Virtual AutoGrant has forced "Who can see" on %d images', 41 pwg_db_changes($r) ) . ' - ' . 42 sprintf( l10n('Privacy level set to "%s"'), l10n( sprintf('Level %d', $user['level']) ) ) 43 ); 72 44 } 45 return true; 73 46 } 74 47 } 75 48 76 49 // API cases : Just do it 77 if ( !function_exists( 'VAG_ set_private_by_API' ) ) {78 add_event_handler('invalidate_user_cache', 'VAG_ set_private_by_API', 20);50 if ( !function_exists( 'VAG_add_case_by_API' ) ) { 51 add_event_handler('invalidate_user_cache', 'VAG_add_case_by_API', 22 ); 79 52 80 function VAG_ set_private_by_API($full) {53 function VAG_add_case_by_API($full) { 81 54 if ( !function_exists( 'ws_categories_add' ) ) return false; // That isn't an API request 82 55 global $user, $conf; … … 94 67 mass_inserts(USER_ACCESS_TABLE, array('user_id','cat_id'), $insert); 95 68 } 96 $vag['lastcat before'] = $inserted_id; # Admin Photos Add does not need to redo the job97 69 } 98 70 // "Who can see" management ( only for API, Synchro or old HTTP management on gallery side are ignored ) … … 129 101 add_event_handler('get_admin_plugin_menu_links', 'VAG_admin_menu'); 130 102 function VAG_admin_menu($menu) { 103 global $conf; 131 104 array_push($menu, array( 132 105 'NAME' => 'Virtual AutoGrant',
Note: See TracChangeset
for help on using the changeset viewer.