Changeset 9372 for extensions/community
- Timestamp:
- Feb 25, 2011, 12:22:52 AM (13 years ago)
- Location:
- extensions/community
- Files:
-
- 7 added
- 14 deleted
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/community/admin.php
r3673 r9372 3 3 // | Piwigo - a PHP based picture gallery | 4 4 // +-----------------------------------------------------------------------+ 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 | 6 8 // +-----------------------------------------------------------------------+ 7 9 // | This program is free software; you can redistribute it and/or modify | … … 26 28 27 29 include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); 30 include_once(PHPWG_ROOT_PATH.'admin/include/tabsheet.class.php'); 31 28 32 load_language('plugin.lang', COMMUNITY_PATH); 29 33 30 $conf['community_permission_levels'] = array(1,2); 31 $admin_base_url = get_root_url().'admin.php?page=plugin§ion=community%2Fadmin.php'; 34 define('COMMUNITY_BASE_URL', get_root_url().'admin.php?page=plugin-community'); 32 35 33 36 // +-----------------------------------------------------------------------+ 34 37 // | Check Access and exit when user status is not ok | 35 38 // +-----------------------------------------------------------------------+ 39 36 40 check_status(ACCESS_ADMINISTRATOR); 37 41 38 42 // +-----------------------------------------------------------------------+ 39 // | functions|43 // | Tabs | 40 44 // +-----------------------------------------------------------------------+ 41 45 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 62 if (isset($_GET['tab']) and in_array($_GET['tab'], $tab_codes)) 43 63 { 44 return '('.$level.') '.l10n( sprintf('Community level %d', $level) ); 64 $page['tab'] = $_GET['tab']; 65 } 66 else 67 { 68 $page['tab'] = $tabs[0]['code']; 45 69 } 46 70 47 // +-----------------------------------------------------------------------+ 48 // | add permissions | 49 // +-----------------------------------------------------------------------+ 50 51 if (isset($_POST['submit_add']) and !is_adviser()) 71 $tabsheet = new tabsheet(); 72 foreach ($tabs as $tab) 52 73 { 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 ); 98 79 } 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(); 146 82 147 83 // +-----------------------------------------------------------------------+ … … 151 87 $template->set_filenames( 152 88 array( 153 'p lugin_admin_content' => dirname(__FILE__).'/admin.tpl'89 'photos_add' => 'photos_add_'.$page['tab'].'.tpl' 154 90 ) 155 91 ); 156 92 157 $template->assign(158 array(159 'F_ADD_ACTION'=> $admin_base_url,160 )161 );162 163 164 // user options165 $query = '166 SELECT167 u.'.$conf['user_fields']['id'].' AS id,168 u.'.$conf['user_fields']['username'].' AS username169 FROM '.USERS_TABLE.' AS u170 INNER JOIN '.USER_INFOS_TABLE.' AS ui171 ON u.'.$conf['user_fields']['id'].' = ui.user_id172 WHERE ui.status = "normal"173 ORDER BY username174 ;';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 options189 $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 permissions201 $query = '202 SELECT203 community.user_id,204 community.permission_level,205 u.'.$conf['user_fields']['username'].' AS username206 FROM '.COMMUNITY_TABLE.' AS community207 INNER JOIN '.USERS_TABLE.' AS u208 ON u.'.$conf['user_fields']['id'].' = community.user_id209 ORDER BY username210 ;';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 225 93 // +-----------------------------------------------------------------------+ 226 // | sending html code|94 // | Load the tab | 227 95 // +-----------------------------------------------------------------------+ 228 96 229 $template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content');97 include(COMMUNITY_PATH.'admin_'.$page['tab'].'.php'); 230 98 ?> -
extensions/community/language/en_UK/plugin.lang.php
r3993 r9372 20 20 // +-----------------------------------------------------------------------+ 21 21 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,'; 29 52 ?> -
extensions/community/language/fr_FR/description.txt
r4842 r9372 1 Permet tre à des utilisateurs d'ajouter des photos avec pLoader1 Permet aux utilisateurs d'ajouter des photos sans être administrateur -
extensions/community/language/fr_FR/plugin.lang.php
r3673 r9372 3 3 // | Piwigo - a PHP based picture gallery | 4 4 // +-----------------------------------------------------------------------+ 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 | 6 8 // +-----------------------------------------------------------------------+ 7 9 // | This program is free software; you can redistribute it and/or modify | … … 20 22 // +-----------------------------------------------------------------------+ 21 23 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,'; 29 54 ?> -
extensions/community/main.inc.php
r6050 r9372 15 15 16 16 define('COMMUNITY_PATH' , PHPWG_PLUGINS_PATH.basename(dirname(__FILE__)).'/'); 17 include_once (COMMUNITY_PATH.'/include/constants.php'); 17 18 global $prefixeTable; 19 define('COMMUNITY_TABLE', $prefixeTable.'community'); 20 define('COMMUNITY_PERMISSIONS_TABLE', $prefixeTable.'community_permissions'); 21 define('COMMUNITY_PENDINGS_TABLE', $prefixeTable.'community_pendings'); 18 22 19 23 /* Plugin admin */ … … 26 30 array( 27 31 'NAME' => 'Community', 28 'URL' => get_ admin_plugin_menu_link(dirname(__FILE__).'/admin.php')32 'URL' => get_root_url().'admin.php?page=plugin-community' 29 33 ) 30 34 ); … … 32 36 return $menu; 33 37 } 38 39 add_event_handler('loc_end_section_init', 'community_section_init'); 40 function community_section_init() 41 { 42 global $tokens, $page; 43 44 if ($tokens[0] == 'add_photos') 45 { 46 $page['section'] = 'add_photos'; 47 } 48 } 49 50 add_event_handler('loc_end_index', 'community_index'); 51 function 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 61 add_event_handler('blockmanager_apply' , 'community_gallery_menu'); 62 function 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 = ' 74 SELECT 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 = ' 82 SELECT 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 34 127 35 128 add_event_handler('ws_invoke_allowed', 'community_switch_user_to_admin', EVENT_HANDLER_PRIORITY_NEUTRAL, 3); -
extensions/community/maintain.inc.php
r3673 r9372 10 10 function plugin_install() 11 11 { 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 = ' 17 CREATE 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 = ' 31 CREATE 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 = ' 43 CREATE 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") 17 52 ) 18 ;"; 19 pwg_query($query); 53 ;'; 54 pwg_query($query); 55 56 $query = ' 57 CREATE 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 = ' 69 CREATE 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 = ' 83 CREATE 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 } 20 92 } 21 93 22 94 function plugin_uninstall() 23 95 { 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;'; 25 102 pwg_query($query); 26 103 }
Note: See TracChangeset
for help on using the changeset viewer.