/**
* Get an array of registered users and guests.
*
* @return array containing number of registered users and guests ('registered' and 'guests')
*/
function init()
{
if ($this->_initialized) {
return true;
}
global $DB, $UserSettings, $localtimenow;
$this->_count_guests = 0;
$this->_registered_Users = array();
$timeout_YMD = date('Y-m-d H:i:s', $localtimenow - $this->_timeout_online_user);
$UserCache =& get_UserCache();
// We get all sessions that have been seen in $timeout_YMD and that have a session key.
// NOTE: we do not use DISTINCT here, because guest users are all "NULL".
$online_user_ids = $DB->get_col("\n\t\t\tSELECT SQL_NO_CACHE sess_user_ID\n\t\t\t FROM T_sessions\n\t\t\t WHERE sess_lastseen_ts > '" . $timeout_YMD . "'\n\t\t\t AND sess_key IS NOT NULL\n\t\t\t GROUP BY sess_ID", 0, 'Sessions: get list of relevant users.');
$registered_online_user_ids = array_diff($online_user_ids, array(NULL));
// load all online users into the cache because we need information ( login, avatar ) about them
$UserCache->load_list($registered_online_user_ids);
foreach ($online_user_ids as $user_ID) {
if (!empty($user_ID) && ($User =& $UserCache->get_by_ID($user_ID, false))) {
if ($UserSettings->get('show_online', $User->ID)) {
// Assign by ID so that each user is only counted once (he could use multiple user agents at the same time):
$this->_registered_Users[$user_ID] =& $User;
} else {
// Count this user as guest when he doesn't want to be visible:
$this->_count_guests++;
}
} else {
$this->_count_guests++;
}
}
$this->_initialized = true;
}
/**
* Generate a title for the current list, depending on its filtering params
*
* @todo cleanup some displays
* @todo implement HMS part of YMDHMS
*
* @return array List of titles to display, which are escaped for HTML display
* (dh> only checked this for 'authors'/?authors=, where the output was not escaped)
*/
function get_filter_titles($ignore = array(), $params = array())
{
global $month;
$params = array_merge(array('category_text' => T_('Category') . ': ', 'categories_text' => T_('Categories') . ': ', 'tags_text' => T_('Tags') . ': '), $params);
if (empty($this->filters)) {
// Filters have no been set before, we'll use the default filterset:
// echo ' setting default filterset ';
$this->set_filters($this->default_filters);
}
$title_array = array();
if ($this->single_post) {
// We have requested a specific post:
// Should be in first position
$Item =& $this->get_by_idx(0);
if (is_null($Item)) {
$title_array[] = T_('Invalid request');
} else {
$title_array[] = $Item->get_titletag();
}
return $title_array;
}
// CATEGORIES:
if (!empty($this->filters['cat_array'])) {
// We have requested specific categories...
$cat_names = array();
$ChapterCache =& get_ChapterCache();
foreach ($this->filters['cat_array'] as $cat_ID) {
if (($my_Chapter =& $ChapterCache->get_by_ID($cat_ID, false)) !== false) {
// It is almost never meaningful to die over an invalid cat when generating title
$cat_names[] = $my_Chapter->name;
}
}
if ($this->filters['cat_modifier'] == '*') {
$cat_names_string = implode(' + ', $cat_names);
} else {
$cat_names_string = implode(', ', $cat_names);
}
if (!empty($cat_names_string)) {
if ($this->filters['cat_modifier'] == '-') {
$cat_names_string = T_('All but ') . ' ' . $cat_names_string;
$title_array['cats'] = $params['categories_text'] . $cat_names_string;
} else {
if (count($this->filters['cat_array']) > 1) {
$title_array['cats'] = $params['categories_text'] . $cat_names_string;
} else {
$title_array['cats'] = $params['category_text'] . $cat_names_string;
}
}
}
}
// ARCHIVE TIMESLOT:
if (!empty($this->filters['ymdhms'])) {
// We have asked for a specific timeframe:
$my_year = substr($this->filters['ymdhms'], 0, 4);
if (strlen($this->filters['ymdhms']) > 4) {
// We have requested a month too:
$my_month = T_($month[substr($this->filters['ymdhms'], 4, 2)]);
} else {
$my_month = '';
}
// Requested a day?
$my_day = substr($this->filters['ymdhms'], 6, 2);
$arch = T_('Archives for') . ': ' . $my_month . ' ' . $my_year;
if (!empty($my_day)) {
// We also want to display a day
$arch .= ', ' . $my_day;
}
if (!empty($this->filters['week']) || $this->filters['week'] === 0) {
// We also want to display a week number
$arch .= ', ' . T_('week') . ' ' . $this->filters['week'];
}
$title_array['ymdhms'] = $arch;
}
// KEYWORDS:
if (!empty($this->filters['keywords'])) {
$title_array['keywords'] = T_('Keyword(s)') . ': ' . $this->filters['keywords'];
}
// TAGS:
if (!empty($this->filters['tags'])) {
$title_array[] = $params['tags_text'] . $this->filters['tags'];
}
// AUTHORS:
if (!empty($this->filters['authors']) || !empty($this->filters['authors_login'])) {
$authors = trim($this->filters['authors'] . ',' . get_users_IDs_by_logins($this->filters['authors_login']), ',');
$authors = preg_split('~\\s*,\\s*~', $authors, -1, PREG_SPLIT_NO_EMPTY);
$author_names = array();
if ($authors) {
$UserCache =& get_UserCache();
foreach ($authors as $author_ID) {
if ($tmp_User = $UserCache->get_by_ID($author_ID, false, false)) {
$author_names[] = $tmp_User->get_identity_link(array('link_text' => 'login'));
//.........这里部分代码省略.........
/**
* Skip to previous/next User
*
* @param integer the currently selected user ID ( Note: it must be set only if we would like to skip some users from the list )
* @param string prev | next (relative to the current sort order)
*/
function &get_prevnext_User($direction = 'next', $selected_user_ID = NULL)
{
$users_list = $this->filters['users'];
if (count($users_list) < 2) {
// Short users list
$r = NULL;
return $r;
}
// ID of selected user
if ($selected_user_ID === NULL) {
// get currently selected user ID from param
$selected_user_ID = get_param('user_ID');
}
$user_key = array_search($selected_user_ID, $users_list);
if (is_int($user_key)) {
// Selected user is located in the list
$prevnext_key = $direction == 'next' ? $user_key + 1 : $user_key - 1;
if (isset($users_list[$prevnext_key])) {
// Prev/next user is located in the list
$prevnext_ID = $users_list[$prevnext_key];
}
}
if (empty($prevnext_ID)) {
// No prev/next user
$r = NULL;
return $r;
}
$UserCache =& get_UserCache();
$User =& $UserCache->get_by_ID($prevnext_ID, false, false);
return $User;
}
/**
* Display the edited items results table
*
* @param array Params
*/
function items_edited_results_block($params = array())
{
// Make sure we are not missing any param:
$params = array_merge(array('edited_User' => NULL, 'results_param_prefix' => 'actv_postedit_', 'results_title' => T_('Posts edited by the user'), 'results_no_text' => T_('User has not edited any posts')), $params);
if (!is_logged_in()) {
// Only logged in users can access to this function
return;
}
global $current_User;
if (!$current_User->check_perm('users', 'edit')) {
// Check minimum permission:
return;
}
$edited_User = $params['edited_User'];
if (!$edited_User) {
// No defined User, probably the function is calling from AJAX request
$user_ID = param('user_ID', 'integer', 0);
if (empty($user_ID)) {
// Bad request, Exit here
return;
}
$UserCache =& get_UserCache();
if (($edited_User =& $UserCache->get_by_ID($user_ID, false)) === false) {
// Bad request, Exit here
return;
}
}
global $DB;
param('user_tab', 'string', '', true);
param('user_ID', 'integer', 0, true);
$edited_versions_SQL = new SQL();
$edited_versions_SQL->SELECT('DISTINCT( iver_itm_ID )');
$edited_versions_SQL->FROM('T_items__version');
$edited_versions_SQL->WHERE('iver_edit_user_ID = ' . $DB->quote($edited_User->ID));
$SQL = new SQL();
$SQL->SELECT('*');
$SQL->FROM('T_items__item ');
$SQL->WHERE('( ( post_lastedit_user_ID = ' . $DB->quote($edited_User->ID) . ' ) OR ( post_ID IN ( ' . $edited_versions_SQL->get() . ' ) ) )');
$SQL->WHERE_and('post_creator_user_ID != ' . $DB->quote($edited_User->ID));
// Create result set:
$edited_items_Results = new Results($SQL->get(), $params['results_param_prefix'], 'D');
$edited_items_Results->Cache =& get_ItemCache();
$edited_items_Results->title = $params['results_title'];
$edited_items_Results->no_results_text = $params['results_no_text'];
// Get a count of the post which current user can delete
$deleted_posts_edited_count = count($edited_User->get_deleted_posts('edited'));
if ($edited_items_Results->total_rows > 0 && $deleted_posts_edited_count > 0) {
// Display actino icon to delete all records if at least one record exists & current user can delete at least one item created by user
$edited_items_Results->global_icon(sprintf(T_('Delete all post edited by %s'), $edited_User->login), 'delete', '?ctrl=user&user_tab=activity&action=delete_all_posts_edited&user_ID=' . $edited_User->ID . '&' . url_crumb('user'), ' ' . T_('Delete all'), 3, 4);
}
// Initialize Results object
items_results($edited_items_Results, array('field_prefix' => 'post_', 'display_ord' => false, 'display_history' => false));
if (is_ajax_content()) {
// init results param by template name
if (!isset($params['skin_type']) || !isset($params['skin_name'])) {
debug_die('Invalid ajax results request!');
}
$edited_items_Results->init_params_by_skin($params['skin_type'], $params['skin_name']);
}
$display_params = array('before' => '<div class="results" style="margin-top:25px" id="edited_posts_result">');
$edited_items_Results->display($display_params);
if (!is_ajax_content()) {
// Create this hidden div to get a function name for AJAX request
echo '<div id="' . $params['results_param_prefix'] . 'ajax_callback" style="display:none">' . __FUNCTION__ . '</div>';
}
}
/**
* Resolve user ID of owner
*
* @return User
*/
function &get_owner_User()
{
if (!isset($this->owner_User)) {
$UserCache =& get_UserCache();
$this->owner_User =& $UserCache->get_by_ID($this->owner_user_ID);
}
return $this->owner_User;
}
/**
* Check if user has a permission to moderate the user
*
* @param integer User ID
* @return boolean TRUE on success
*/
function can_moderate_user($user_ID, $assert = false)
{
if ($this->ID == $user_ID) {
// User can edit own profile
return true;
}
if ($this->check_perm('users', 'edit')) {
// User can edit all users
return true;
}
if ($this->check_perm('users', 'moderate', $assert)) {
// User can moderate other user but we should to compare levels of users groups
$UserCache =& get_UserCache();
if ($target_User = $UserCache->get_by_ID($user_ID, false, false)) {
if ($target_User->get_Group()->get('level') < $this->get_Group()->get('level')) {
// User can moderate only users with level lower than own level
return true;
}
}
}
if ($assert) {
// We can't let this go on!
debug_die(sprintf(T_('User #%s has no permission to edit user #%s!'), $this->ID, $user_ID));
}
return false;
}
function pbm_validate_user_password($user_login, $user_pass)
{
$UserCache =& get_UserCache();
$User =& $UserCache->get_by_login($user_login);
if (!$User) {
return false;
}
// First check unhashed password
if (!$User->check_password($user_pass, false)) {
if (preg_match('~^[a-f0-9]{32}$~i', $user_pass)) {
// This is a hashed password, see if it's valid
// We check it here because some crazy user may use a real 32-chars password!
if ($User->check_password($user_pass, true)) {
// Valid password
return $User;
}
}
return false;
}
return $User;
}
/**
* Constructor
*
* Will fail if non existent User or Blog is requested.
* But specific access permissions on (threfore existence of) this User or Blog should have been tested before anyway.
*
* @param string Root type: 'user', 'group' or 'collection'
* @param integer ID of the user, the group or the collection the file belongs to...
* @param boolean Create the directory, if it does not exist yet?
*/
function FileRoot($root_type, $root_in_type_ID, $create = true)
{
/**
* @var User
*/
global $current_User;
global $Messages;
global $Settings, $Debuglog;
global $Blog;
// Store type:
$this->type = $root_type;
// Store ID in type:
$this->in_type_ID = $root_in_type_ID;
// Generate unique ID:
$this->ID = FileRoot::gen_ID($root_type, $root_in_type_ID);
switch ($root_type) {
case 'user':
$UserCache =& get_UserCache();
if (!($User =& $UserCache->get_by_ID($root_in_type_ID, false, false))) {
// User not found
return false;
}
$this->name = $User->get('login');
//.' ('. /* TRANS: short for "user" */ T_('u').')';
$this->ads_path = $User->get_media_dir($create);
$this->ads_url = $User->get_media_url();
return;
case 'collection':
$BlogCache =& get_BlogCache();
if (!($Blog =& $BlogCache->get_by_ID($root_in_type_ID, false, false))) {
// Blog not found
return false;
}
$this->name = $Blog->get('shortname');
//.' ('. /* TRANS: short for "blog" */ T_('b').')';
$this->ads_path = $Blog->get_media_dir($create);
$this->ads_url = $Blog->get_media_url();
return;
case 'shared':
// fp> TODO: handle multiple shared directories
global $media_path, $media_url;
$rds_shared_subdir = 'shared/global/';
$ads_shared_dir = $media_path . $rds_shared_subdir;
if (!$Settings->get('fm_enable_roots_shared')) {
// Shared dir is disabled:
$Debuglog->add('Attempt to access shared dir, but this feature is globally disabled', 'files');
} elseif (!mkdir_r($ads_shared_dir)) {
// Only display error on an admin page:
if (is_admin_page()) {
$Messages->add(sprintf(T_('The directory «%s» could not be created.'), $rds_shared_subdir) . get_manual_link('directory_creation_error'), 'error');
}
} else {
$this->name = T_('Shared');
$this->ads_path = $ads_shared_dir;
if (isset($Blog)) {
// (for now) Let's make shared files appear as being part of the currently displayed blog:
$this->ads_url = $Blog->get_local_media_url() . 'shared/global/';
} else {
$this->ads_url = $media_url . 'shared/global/';
}
}
return;
case 'skins':
// fp> some stuff here should go out of here... but I don't know where to put it yet. I'll see after the Skin refactoring.
if (!$Settings->get('fm_enable_roots_skins')) {
// Skins root is disabled:
$Debuglog->add('Attempt to access skins dir, but this feature is globally disabled', 'files');
} elseif (empty($current_User) || !$current_User->check_perm('templates')) {
// No perm to access templates:
$Debuglog->add('Attempt to access skins dir, but no permission', 'files');
} else {
global $skins_path, $skins_url;
$this->name = T_('Skins');
$this->ads_path = $skins_path;
if (isset($Blog)) {
// (for now) Let's make skin files appear as being part of the currently displayed blog:
$this->ads_url = $Blog->get_local_skins_url();
} else {
$this->ads_url = $skins_url;
}
}
return;
}
debug_die("Invalid root type");
}
/**
* Automagically login every user as "demouser" who is not logged in and does not
* try to currently.
*
* To enable/test it, change the "if-0" check below to "if( 1 )".
*
* @see Plugin::AlternateAuthentication()
*/
function AlternateAuthentication()
{
if (0) {
global $Session, $Messages;
$UserCache =& get_UserCache();
if ($demo_User =& $UserCache->get_by_login('demouser')) {
// demouser exists:
$Session->set_User($demo_User);
$Messages->add('Logged in as demouser.', 'success');
return true;
}
}
}
//.........这里部分代码省略.........
}
break;
case 'register':
// We are requesting the registration form:
$r[] = $params['register_text'];
break;
case 'activateinfo':
// We are requesting the activate info form:
$r[] = $params['account_activation'];
break;
case 'lostpassword':
// We are requesting the lost password form:
$r[] = $params['lostpassword_text'];
break;
case 'single':
case 'page':
// We are displaying a single message:
if ($preview) {
// We are requesting a post preview:
$r[] = T_('PREVIEW');
} elseif ($params['title_' . $disp . '_disp'] && isset($MainList)) {
$r = array_merge($r, $MainList->get_filter_titles(array('visibility', 'hide_future'), $params));
}
if ($params['title_' . $disp . '_before'] != '#') {
$before = $params['title_' . $disp . '_before'];
}
if ($params['title_' . $disp . '_after'] != '#') {
$after = $params['title_' . $disp . '_after'];
}
break;
case 'user':
// We are requesting the user page:
$user_ID = param('user_ID', 'integer', 0);
$UserCache =& get_UserCache();
$User =& $UserCache->get_by_ID($user_ID, false, false);
$user_login = $User ? $User->get('login') : '';
$r[] = sprintf($params['user_text'], $user_login);
break;
case 'users':
$r[] = $params['users_text'];
break;
case 'closeaccount':
$r[] = $params['closeaccount_text'];
break;
case 'edit':
$action = param_action();
// Edit post by switching into 'In skin' mode from Back-office
$p = param('p', 'integer', 0);
// Edit post from Front-office
$cp = param('cp', 'integer', 0);
// Copy post from Front-office
if ($action == 'edit_switchtab' || $p > 0) {
// Edit post
$title = $params['edit_text_update'];
} else {
if ($cp > 0) {
// Copy post
$title = $params['edit_text_copy'];
} else {
// Create post
$title = $params['edit_text_create'];
}
}
if ($params['auto_pilot'] != 'seo_title') {
// Add advanced edit and close icon
global $edited_Item;
请发表评论