Changeset 23085 for extensions/community
- Timestamp:
- Jun 7, 2013, 2:41:14 PM (11 years ago)
- Location:
- extensions/community
- Files:
-
- 2 added
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/community/add_photos.php
r23037 r23085 32 32 define('PHOTOS_ADD_BASE_URL', make_index_url(array('section' => 'add_photos'))); 33 33 34 $user_permissions = community_get_user_permissions($user['id']);35 36 if ( count($user_permissions['upload_categories']) == 0 and !$user_permissions ['create_whole_gallery'])34 $user_permissions = $user['community_permissions']; 35 36 if (!$user_permissions['community_enabled']) 37 37 { 38 38 redirect(make_index_url()); … … 393 393 if ($remaining_storage <= 0) 394 394 { 395 echo 'limit storage reached<br>';396 395 // limit reached 397 396 $setup_errors[] = sprintf( … … 426 425 if ($remaining_nb_photos <= 0) 427 426 { 428 echo 'limit nb_photos reached<br>';429 427 // limit reached 430 428 $setup_errors[] = sprintf( -
extensions/community/admin.php
r9516 r23085 57 57 'label' => $pendings_label, 58 58 ), 59 array( 60 'code' => 'config', 61 'label' => l10n('Configuration'), 62 ), 59 63 ); 60 64 -
extensions/community/admin_permissions.php
r23037 r23085 51 51 if (isset($_POST['submit_add'])) 52 52 { 53 // echo '<pre>'; print_r($_POST); echo '</pre>'; 53 54 if (!in_array($_POST['who'], array_keys($who_options))) 54 55 { … … 81 82 { 82 83 check_input_parameter('storage', $_POST, false, PATTERN_ID); 84 } 85 86 // it is already blocked by Javascript, but an extra check is usefull 87 if ('any_visitor' == $_POST['who'] and -1 == $_POST['category']) 88 { 89 die('hacking attempt: invalid "where" option for this user'); 90 } 91 92 if (-1 == $_POST['category']) 93 { 94 unset($_POST['recursive']); 95 unset($_POST['create_subcategories']); 83 96 } 84 97 … … 89 102 'user_id' => ('user' == $_POST['who']) ? $_POST['who_user'] : null, 90 103 'category_id' => ($_POST['category'] > 0) ? $_POST['category'] : null, 104 'user_album' => boolean_to_string(-1 == $_POST['category']), 91 105 'recursive' => isset($_POST['recursive']) ? 'true' : 'false', 92 106 'create_subcategories' => isset($_POST['create_subcategories']) ? 'true' : 'false', … … 107 121 AND group_id '.(isset($insert['group_id']) ? '= '.$insert['group_id'] : 'is null').' 108 122 AND category_id '.(isset($insert['category_id']) ? '= '.$insert['category_id'] : 'is null').' 123 AND user_album = \''.$insert['user_album'].'\' 109 124 ;'; 110 125 $result = pwg_query($query); … … 231 246 'user_options_selected' => $row['user_id'], 232 247 'group_options_selected' => $row['group_id'], 248 'whole_gallery_selected' => empty($row['category_id']) and !get_boolean($row['user_album']), 249 'user_album_selected' => get_boolean($row['user_album']), 233 250 'recursive' => get_boolean($row['recursive']), 234 251 'create_subcategories' => get_boolean($row['create_subcategories']), … … 244 261 $template->assign( 245 262 array( 263 'whole_gallery_selected' => !$conf['community']['user_albums'], 264 'user_album_selected' => $conf['community']['user_albums'], 246 265 'moderated' => true, 247 266 'nb_photos' => -1, … … 310 329 array( 311 330 'F_ADD_ACTION' => COMMUNITY_BASE_URL.'-'.$page['tab'], 331 'community_conf' => $conf['community'], 312 332 ) 313 333 ); … … 418 438 foreach ($permissions as $permission) 419 439 { 420 $where = l10n('The whole gallery'); 421 if (isset($permission['category_id'])) 422 { 423 $where = $name_of_category[ $permission['category_id'] ]; 440 $where = l10n('User album only'); 441 if (!get_boolean($permission['user_album'])) 442 { 443 $where = l10n('The whole gallery'); 444 if (isset($permission['category_id'])) 445 { 446 $where = $name_of_category[ $permission['category_id'] ]; 447 } 424 448 } 425 449 -
extensions/community/admin_permissions.tpl
r23037 r23085 60 60 $("[name^=who_]").hide(); 61 61 $("[name=who_"+$(this).attr("value")+"]").show(); 62 }); 62 checkWhoOptions(); 63 }); 64 65 function checkWhoOptions() { 66 if ('any_visitor' == $("select[name=who] option:selected").val()) { 67 $("#userAlbumOption").attr("disabled", true); 68 $("#userAlbumInfo").hide(); 69 70 if (-1 == $("select[name=category] option:selected").val()) { 71 $("select[name=category]").val("0"); 72 checkWhereOptions(); 73 } 74 } 75 else { 76 $("#userAlbumOption").attr("disabled", false); 77 $("#userAlbumInfo").show(); 78 } 79 } 80 checkWhoOptions(); 63 81 64 82 function checkWhereOptions() { … … 69 87 $(recursive).attr("disabled", true); 70 88 $(recursive).attr('checked', true); 89 } 90 else if ($("select[name=category] option:selected").val() == -1) { 91 /* user upload only */ 92 $(recursive).attr("disabled", true).attr('checked', false); 93 $(create).attr("disabled", true).attr('checked', false); 71 94 } 72 95 else { … … 207 230 208 231 <p> 209 <strong>{'Where?'|@translate}</strong> 232 <strong>{'Where?'|@translate}</strong> {if $community_conf.user_albums}<em id="userAlbumInfo">{'(in addition to user album)'|@translate}</em>{/if} 210 233 <br> 211 234 <select class="categoryDropDown" name="category"> 212 <option value="0" {if not isset($category_options_selected)}selected="selected"{/if}>{'The whole gallery'|@translate}</option> 235 {if $community_conf.user_albums} 236 <option value="-1"{if $user_album_selected} selected="selected"{/if} id="userAlbumOption">{'User album only'|@translate}</option> 237 {/if} 238 <option value="0"{if $whole_gallery_selected} selected="selected"{/if}>{'The whole gallery'|@translate}</option> 213 239 <option disabled="disabled">------------</option> 214 240 {html_options options=$category_options selected=$category_options_selected} -
extensions/community/include/functions_community.inc.php
r23037 r23085 24 24 function community_get_user_permissions($user_id) 25 25 { 26 // echo __FUNCTION__.' => call for user '.$user_id.'<br>'; 27 26 28 global $conf, $user; 27 29 … … 49 51 'upload_whole_gallery' => false, 50 52 'create_whole_gallery' => false, 53 'user_album' => false, 51 54 'create_categories' => array(), 52 55 'upload_categories' => array(), … … 68 71 SELECT 69 72 id, 73 type, 70 74 category_id, 75 user_album, 71 76 recursive, 72 77 create_subcategories, … … 98 103 { 99 104 array_push($return['permission_ids'], $row['id']); 100 101 if (empty($row['category_id'])) 102 { 103 $return ['upload_whole_gallery'] = true; 104 } 105 else 106 { 107 array_push($return['upload_categories'], $row['category_id']); 108 109 if ('true' == $row['recursive']) 110 { 111 array_push($recursive_categories, $row['category_id']); 105 106 if ('false' == $row['user_album']) 107 { 108 if (empty($row['category_id'])) 109 { 110 $return['upload_whole_gallery'] = true; 111 } 112 else 113 { 114 array_push($return['upload_categories'], $row['category_id']); 115 116 if ('true' == $row['recursive']) 117 { 118 array_push($recursive_categories, $row['category_id']); 119 } 112 120 } 113 121 } … … 149 157 $return['storage'] = $row['storage']; 150 158 } 159 } 160 161 if ($conf['community']['user_albums'] and 'any_visitor' != $row['type']) 162 { 163 $return['user_album'] = true; 151 164 } 152 165 } … … 237 250 } 238 251 252 if ($return['user_album']) 253 { 254 $user_album_category_id = community_get_user_album($user_id); 255 256 if (!empty($user_album_category_id) and !in_array($user_album_category_id, $return['upload_categories'])) 257 { 258 array_push($return['upload_categories'], $user_album_category_id); 259 } 260 } 261 262 // is the user allowed to use community upload? 263 if (count($return['upload_categories']) > 0 or $return['create_whole_gallery'] or $return['user_album']) 264 { 265 $return['community_enabled'] = true; 266 } 267 else 268 { 269 $return['community_enabled'] = false; 270 } 271 239 272 $_SESSION['community_user_permissions'] = $return; 240 273 $_SESSION['community_cache_key'] = $cache_key; 241 274 $_SESSION['community_user_id'] = $user_id; 242 275 276 // echo __FUNCTION__.' => cache reset for user '.$user_id.'<br>'; 277 243 278 return $_SESSION['community_user_permissions']; 279 } 280 281 /** 282 * return the user album category_id. The album is automatically created if 283 * it does not exist (or has been deleted) 284 */ 285 function community_get_user_album($user_id) 286 { 287 global $conf; 288 289 $user_album_category_id = null; 290 291 $query = ' 292 SELECT * 293 FROM '.CATEGORIES_TABLE.' 294 WHERE community_user = '.$user_id.' 295 ;'; 296 $result = pwg_query($query); 297 while ($row = pwg_db_fetch_assoc($result)) 298 { 299 $user_album_category_id = $row['id']; 300 break; 301 } 302 303 if (!isset($user_album_category_id)) 304 { 305 $user_infos = getuserdata($user_id, false); 306 307 include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); 308 $category_info = create_virtual_category($user_infos['username'], $conf['community']['user_albums_parent']); 309 310 single_update( 311 CATEGORIES_TABLE, 312 array('community_user' => $user_id), 313 array('id' => $category_info['id']) 314 ); 315 316 $user_album_category_id = $category_info['id']; 317 318 // in functions_html::get_cat_display_name_cache we use a cache and this 319 // cache must be reset so that new album is included inside it. 320 global $cache; 321 unset($cache['cat_names']); 322 } 323 324 return $user_album_category_id; 244 325 } 245 326 -
extensions/community/include/install.inc.php
r23037 r23085 33 33 user_id smallint(5) DEFAULT NULL, 34 34 category_id smallint(5) unsigned DEFAULT NULL, 35 user_album enum(\'true\',\'false\') NOT NULL DEFAULT \'false\', 35 36 recursive enum(\'true\',\'false\') NOT NULL DEFAULT \'true\', 36 37 create_subcategories enum(\'true\',\'false\') NOT NULL DEFAULT \'false\', … … 66 67 pwg_query('ALTER TABLE `'.$prefixeTable .'community_permissions` ADD `storage` INT DEFAULT NULL;'); 67 68 } 69 70 // column community_permissions.user_album added for version 2.5.d 71 $result = pwg_query('SHOW COLUMNS FROM `'.$prefixeTable.'community_permissions` LIKE "user_album";'); 72 if (!pwg_db_num_rows($result)) 73 { 74 pwg_query('ALTER TABLE `'.$prefixeTable .'community_permissions` ADD `user_album` enum(\'true\',\'false\') NOT NULL DEFAULT \'false\' after `category_id`;'); 75 } 76 77 // column categories.community_user added for version 2.5.d 78 $result = pwg_query('SHOW COLUMNS FROM `'.$prefixeTable.'categories` LIKE "community_user";'); 79 if (!pwg_db_num_rows($result)) 80 { 81 pwg_query('ALTER TABLE `'.$prefixeTable .'categories` ADD `community_user` smallint(5) DEFAULT NULL;'); 82 } 83 84 if (!isset($conf['community'])) 85 { 86 $community_default_config = serialize( 87 array( 88 'user_albums' => false, 89 ) 90 ); 91 92 conf_update_param('community', $community_default_config); 93 $conf['community'] = $community_default_config; 94 } 68 95 } 69 96 ?> -
extensions/community/language/en_UK/plugin.lang.php
r23037 r23085 75 75 $lang['How much disk space?'] = 'How much disk space?'; 76 76 $lang['How many photos?'] = 'How many photos?'; 77 $lang['User albums'] = 'User albums'; 78 $lang['Piwigo automatically creates an album for each user, on first connection'] = 'Piwigo automatically creates an album for each user, on first connection'; 79 $lang['Where should Piwigo create user albums?'] = 'Where should Piwigo create user albums?'; 80 $lang['Gallery root'] = 'Gallery root'; 81 $lang['(in addition to user album)'] = '(in addition to user album)'; 82 $lang['User album only'] = 'User album only'; 77 83 ?> -
extensions/community/language/fr_FR/plugin.lang.php
r23037 r23085 77 77 $lang['How much disk space?'] = 'Combien d\'espace disque ?'; 78 78 $lang['How many photos?'] = 'Combien de photos ?'; 79 $lang['User albums'] = 'Albums utilisateur'; 80 $lang['Piwigo automatically creates an album for each user, on first connection'] = 'Piwigo créée automatiquement un album pour chaque utilisateur, lors de sa première connexion'; 81 $lang['Where should Piwigo create user albums?'] = 'Où Piwigo doit-il créer les albums utilisateur ?'; 82 $lang['Gallery root'] = 'Racine de la galerie'; 83 $lang['(in addition to user album)'] = '(en plus de l\'album utilisateur)'; 84 $lang['User album only'] = 'Uniquement l\'album utilisateur'; 79 85 ?> -
extensions/community/main.inc.php
r23037 r23085 38 38 function community_init() 39 39 { 40 global $conf, $ pwg_loaded_plugins;40 global $conf, $user, $pwg_loaded_plugins; 41 41 42 42 // apply upgrade if needed … … 63 63 } 64 64 } 65 66 // prepare plugin configuration 67 $conf['community'] = unserialize($conf['community']); 68 69 // TODO: generate permissions in $user['community_permissions'] if ws.php 70 // + remove all calls of community_get_user_permissions related to webservices 71 if (!defined('IN_ADMIN') or !IN_ADMIN) 72 { 73 $user['community_permissions'] = community_get_user_permissions($user['id']); 74 } 65 75 } 66 76 … … 88 98 $style.= '-moz-border-radius:10px;'; 89 99 $style.= '-webkit-border-radius:10px;'; 90 $style.= ' -border-radius:10px;';100 $style.= 'border-radius:10px;'; 91 101 $style.= 'margin-left:5px;'; 92 102 … … 169 179 // conditional : depending on community permissions, display the "Add 170 180 // photos" link in the gallery menu 171 $user_permissions = community_get_user_permissions($user['id']);172 173 if ( count($user_permissions['upload_categories']) == 0 and !$user_permissions ['create_whole_gallery'])181 $user_permissions = $user['community_permissions']; 182 183 if (!$user_permissions['community_enabled']) 174 184 { 175 185 return; -
extensions/community/maintain.inc.php
r23037 r23085 24 24 $query = 'DROP TABLE '.$prefixeTable.'community_pendings;'; 25 25 pwg_query($query); 26 27 $query = 'ALTER TABLE '.$prefixeTable.'categories drop column community_user;'; 28 pwg_query($query); 29 30 // delete configuration 31 pwg_query('DELETE FROM `'. CONFIG_TABLE .'` WHERE param IN ("community", "community_cache_key");'); 26 32 } 27 33 … … 241 247 { 242 248 global $prefixeTable; 243 244 // create an album "Community" 245 $category_info = create_virtual_category('Community'); 249 250 // is there a "Community" album? 251 $query = ' 252 SELECT 253 id 254 FROM '.CATEGORIES_TABLE.' 255 WHERE name = \'Community\' 256 ;'; 257 $result = pwg_query($query); 258 while ($row = pwg_db_fetch_assoc($result)) 259 { 260 $category_id = $row['id']; 261 break; 262 } 263 264 if (!isset($category_id)) 265 { 266 // create an album "Community" 267 $category_info = create_virtual_category('Community'); 268 $category_id = $category_info['id']; 269 } 246 270 247 271 $insert = array( 248 272 'type' => 'any_registered_user', 249 'category_id' => $category_i nfo['id'],273 'category_id' => $category_id, 250 274 'recursive' => 'true', 251 275 'create_subcategories' => 'true',
Note: See TracChangeset
for help on using the changeset viewer.