function Who()
{
global $db_prefix, $context, $scripturl, $user_info, $txt, $modSettings, $ID_MEMBER, $memberContext;
// Permissions, permissions, permissions.
isAllowedTo('who_view');
// You can't do anything if this is off.
if (empty($modSettings['who_enabled'])) {
fatal_lang_error('who_off', false);
}
// Load the 'Who' template.
loadTemplate('Who');
// Sort out... the column sorting.
$sort_methods = array('user' => 'mem.realName', 'time' => 'lo.logTime');
// By default order by last time online.
if (!isset($_REQUEST['sort']) || !isset($sort_methods[$_REQUEST['sort']])) {
$context['sort_by'] = 'time';
$_REQUEST['sort'] = 'lo.logTime';
} else {
$context['sort_by'] = $_REQUEST['sort'];
$_REQUEST['sort'] = $sort_methods[$_REQUEST['sort']];
}
$context['sort_direction'] = isset($_REQUEST['asc']) ? 'up' : 'down';
// Get the total amount of members online.
$request = db_query("\n\t\tSELECT COUNT(*)\n\t\tFROM {$db_prefix}log_online AS lo\n\t\t\tLEFT JOIN {$db_prefix}members AS mem ON (lo.ID_MEMBER = mem.ID_MEMBER)" . (!allowedTo('moderate_forum') ? "\n\t\tWHERE IFNULL(mem.showOnline, 1) = 1" : ''), __FILE__, __LINE__);
list($totalMembers) = mysql_fetch_row($request);
mysql_free_result($request);
// Prepare some page index variables.
$context['page_index'] = constructPageIndex($scripturl . '?action=who;sort=' . $context['sort_by'] . (isset($_REQUEST['asc']) ? ';asc' : ''), $_REQUEST['start'], $totalMembers, $modSettings['defaultMaxMembers']);
$context['start'] = $_REQUEST['start'];
// Look for people online, provided they don't mind if you see they are.
$request = db_query("\n\t\tSELECT\n\t\t\t(UNIX_TIMESTAMP(lo.logTime) - UNIX_TIMESTAMP() + " . time() . ") AS logTime,\n\t\t\tlo.ID_MEMBER, lo.url, INET_NTOA(lo.ip) AS ip, mem.realName, lo.session,\n\t\t\tmg.onlineColor, IFNULL(mem.showOnline, 1) AS showOnline\n\t\tFROM {$db_prefix}log_online AS lo\n\t\t\tLEFT JOIN {$db_prefix}members AS mem ON (lo.ID_MEMBER = mem.ID_MEMBER)\n\t\t\tLEFT JOIN {$db_prefix}membergroups AS mg ON (mg.ID_GROUP = IF(mem.ID_GROUP = 0, mem.ID_POST_GROUP, mem.ID_GROUP))" . (!allowedTo('moderate_forum') ? "\n\t\tWHERE IFNULL(mem.showOnline, 1) = 1" : '') . "\n\t\tORDER BY {$_REQUEST['sort']} " . (isset($_REQUEST['asc']) ? 'ASC' : 'DESC') . "\n\t\tLIMIT {$context['start']}, {$modSettings['defaultMaxMembers']}", __FILE__, __LINE__);
$context['members'] = array();
$member_ids = array();
$url_data = array();
while ($row = mysql_fetch_assoc($request)) {
$actions = @unserialize($row['url']);
if ($actions === false) {
continue;
}
// Send the information to the template.
$context['members'][$row['session']] = array('id' => $row['ID_MEMBER'], 'ip' => allowedTo('moderate_forum') ? $row['ip'] : '', 'time' => strtr(timeformat($row['logTime']), array($txt['smf10'] => '', $txt['smf10b'] => '')), 'timestamp' => forum_time(true, $row['logTime']), 'query' => $actions, 'is_hidden' => $row['showOnline'] == 0, 'color' => empty($row['onlineColor']) ? '' : $row['onlineColor']);
$url_data[$row['session']] = array($row['url'], $row['ID_MEMBER']);
$member_ids[] = $row['ID_MEMBER'];
}
mysql_free_result($request);
// Load the user data for these members.
loadMemberData($member_ids);
// Load up the guest user.
$memberContext[0] = array('id' => 0, 'name' => $txt[28], 'group' => $txt[28], 'href' => '', 'link' => $txt[28], 'email' => $txt[28], 'is_guest' => true);
$url_data = determineActions($url_data);
// Setup the linktree and page title (do it down here because the language files are now loaded..)
$context['page_title'] = $txt['who_title'];
$context['linktree'][] = array('url' => $scripturl . '?action=who', 'name' => $txt['who_title']);
// Put it in the context variables.
foreach ($context['members'] as $i => $member) {
if ($member['id'] != 0) {
$member['id'] = loadMemberContext($member['id']) ? $member['id'] : 0;
}
// Keep the IP that came from the database.
$memberContext[$member['id']]['ip'] = $member['ip'];
$context['members'][$i]['action'] = isset($url_data[$i]) ? $url_data[$i] : $txt['who_hidden'];
$context['members'][$i] += $memberContext[$member['id']];
}
// Some people can't send personal messages...
$context['can_send_pm'] = allowedTo('pm_send');
}
开发者ID:VBGAMER45,项目名称:SMFMods,代码行数:66,代码来源:Who.php
示例5: foreach
*
*/
require_once $_SERVER['DOCUMENT_ROOT'] . '/functions.php';
require_once $link['root'] . 'classes/MailManager.php';
//Initalize Value
$from = "[email protected]";
$pending_addon_count = 5;
$dashboard_link = "";
$official_link = "";
$memberContext = null;
//Clear any previously stored value
//Unfortunately we don't store user personal details such as email in website's database
//so get them from SMF using user ID
foreach (MailManager::getAdminEmailList() as $user) {
loadMemberData($user['ID_MEMBER']);
loadMemberContext($user['ID_MEMBER']);
}
$subject = "There are " . $pending_addon_count . " addons require your approval!";
$message = file_get_contents($link['root'] . 'pages/mail_templates/pending.addon.dashboard.html');
//now loop through member data and put all the valid email in an array
foreach ($memberContext as $user) {
//Make sure the emails are valid
if (!filter_var($user['email'], FILTER_VALIDATE_EMAIL) === false) {
$bindedvalarray = array("{username}" => $user['username'], "{pending_request_count}" => $pending_addon_count, "{dashboard_link}" => $link['addon']['dashboard'], "{official_link}" => $link['home'], "{subject}" => $subject);
if (MailManager::sendMail($user['email'], $from, "UTF-8", "text/html", $subject, $message, $bindedvalarray)) {
//put some logging function to monitor
echo "Mail delivered to " . $user['username'] . "<br/>";
} else {
//put some logging function to monitor
echo "Mail Could not be delivered";
}
/**
* Used to see if a user is banned
*
* - Checks banning by ip, hostname, email or member id
*
* @package Bans
* @param int $memID
* @param string $hostname
* @param string $email
*/
function BanCheckUser($memID, $hostname = '', $email = '')
{
global $memberContext, $scripturl, $txt;
$db = database();
$bans = array();
// This is a valid member id, we at least need that
if (loadMemberContext($memID) && isset($memberContext[$memID])) {
$ban_query = array();
$ban_query_vars = array('time' => time());
// Member id and ip
$ban_query[] = 'id_member = ' . $memID;
require_once SOURCEDIR . '/Security.php';
$ban_query[] = constructBanQueryIP($memberContext[$memID]['ip']);
// Do we have a hostname?
if (!empty($hostname)) {
$ban_query[] = '({string:hostname} LIKE hostname)';
$ban_query_vars['hostname'] = $hostname;
}
// Check their email as well...
if (strlen($email) != 0) {
$ban_query[] = '({string:email} LIKE bi.email_address)';
$ban_query_vars['email'] = $email;
}
// So... are they banned? Dying to know!
$request = $db->query('', '
SELECT bg.id_ban_group, bg.name, bg.cannot_access, bg.cannot_post, bg.cannot_register,
bg.cannot_login, bg.reason
FROM {db_prefix}ban_items AS bi
INNER JOIN {db_prefix}ban_groups AS bg ON (bg.id_ban_group = bi.id_ban_group AND (bg.expire_time IS NULL OR bg.expire_time > {int:time}))
WHERE (' . implode(' OR ', $ban_query) . ')', $ban_query_vars);
$bans = array();
while ($row = $db->fetch_assoc($request)) {
// Work out what restrictions we actually have.
$ban_restrictions = array();
foreach (array('access', 'register', 'login', 'post') as $type) {
if ($row['cannot_' . $type]) {
$ban_restrictions[] = $txt['ban_type_' . $type];
}
}
// No actual ban in place?
if (empty($ban_restrictions)) {
continue;
}
// Prepare the link for context.
$ban_explanation = sprintf($txt['user_cannot_due_to'], implode(', ', $ban_restrictions), '<a href="' . $scripturl . '?action=admin;area=ban;sa=edit;bg=' . $row['id_ban_group'] . '">' . $row['name'] . '</a>');
$bans[$row['id_ban_group']] = array('reason' => empty($row['reason']) ? '' : '<br /><br /><strong>' . $txt['ban_reason'] . ':</strong> ' . $row['reason'], 'cannot' => array('access' => !empty($row['cannot_access']), 'register' => !empty($row['cannot_register']), 'post' => !empty($row['cannot_post']), 'login' => !empty($row['cannot_login'])), 'explanation' => $ban_explanation);
}
$db->free_result($request);
}
return $bans;
}
function editBuddies($memID)
{
global $txt, $scripturl, $modSettings, $db_prefix;
global $context, $user_profile, $memberContext, $func;
// Do a quick check to ensure people aren't getting here illegally!
if (!$context['user']['is_owner'] || empty($modSettings['enable_buddylist'])) {
fatal_lang_error(1, false);
}
// !!! No page_title.
// For making changes!
$buddiesArray = explode(',', $user_profile[$memID]['buddy_list']);
foreach ($buddiesArray as $k => $dummy) {
if ($dummy == '') {
unset($buddiesArray[$k]);
}
}
// Removing a buddy?
if (isset($_GET['remove'])) {
// Heh, I'm lazy, do it the easy way...
foreach ($buddiesArray as $key => $buddy) {
if ($buddy == (int) $_GET['remove']) {
unset($buddiesArray[$key]);
}
}
// Make the changes.
$user_profile[$memID]['buddy_list'] = implode(',', $buddiesArray);
updateMemberData($memID, array('buddy_list' => "'" . $user_profile[$memID]['buddy_list'] . "'"));
// Redirect off the page because we don't like all this ugly query stuff to stick in the history.
redirectexit('action=profile;u=' . $memID . ';sa=editBuddies');
} elseif (isset($_POST['new_buddy'])) {
// Prepare the string for extraction...
$_POST['new_buddy'] = strtr(addslashes($func['htmlspecialchars'](stripslashes($_POST['new_buddy']), ENT_QUOTES)), array('"' => '"'));
preg_match_all('~"([^"]+)"~', $_POST['new_buddy'], $matches);
$new_buddies = array_unique(array_merge($matches[1], explode(',', preg_replace('~"([^"]+)"~', '', $_POST['new_buddy']))));
foreach ($new_buddies as $k => $dummy) {
$new_buddies[$k] = strtr(trim($new_buddies[$k]), array('\\\'' => '''));
if (strlen($new_buddies[$k]) == 0) {
unset($new_buddies[$k]);
}
}
if (!empty($new_buddies)) {
// Now find out the ID_MEMBER of the buddy.
$request = db_query("\n\t\t\t\tSELECT ID_MEMBER\n\t\t\t\tFROM {$db_prefix}members\n\t\t\t\tWHERE memberName IN ('" . implode("','", $new_buddies) . "') OR realName IN ('" . implode("','", $new_buddies) . "')\n\t\t\t\tLIMIT " . count($new_buddies), __FILE__, __LINE__);
// Add the new member to the buddies array.
while ($row = mysql_fetch_assoc($request)) {
$buddiesArray[] = (int) $row['ID_MEMBER'];
}
mysql_free_result($request);
// Now update the current users buddy list.
$user_profile[$memID]['buddy_list'] = implode(',', $buddiesArray);
updateMemberData($memID, array('buddy_list' => "'" . $user_profile[$memID]['buddy_list'] . "'"));
}
// Back to the buddy list!
redirectexit('action=profile;u=' . $memID . ';sa=editBuddies');
}
// Get all the users "buddies"...
$buddies = array();
if (!empty($buddiesArray)) {
$result = db_query("\n\t\t\tSELECT ID_MEMBER\n\t\t\tFROM {$db_prefix}members\n\t\t\tWHERE ID_MEMBER IN (" . implode(', ', $buddiesArray) . ")\n\t\t\tORDER BY realName\n\t\t\tLIMIT " . (substr_count($user_profile[$memID]['buddy_list'], ',') + 1), __FILE__, __LINE__);
while ($row = mysql_fetch_assoc($result)) {
$buddies[] = $row['ID_MEMBER'];
}
mysql_free_result($result);
}
$context['buddy_count'] = count($buddies);
// Load all the members up.
loadMemberData($buddies, false, 'profile');
// Setup the context for each buddy.
$context['buddies'] = array();
foreach ($buddies as $buddy) {
loadMemberContext($buddy);
$context['buddies'][$buddy] = $memberContext[$buddy];
}
}
开发者ID:alencarmo,项目名称:OCF,代码行数:74,代码来源:Profile.php
示例11: editIgnoreList
function editIgnoreList($memID)
{
global $txt, $scripturl, $modSettings;
global $context, $user_profile, $memberContext, $smcFunc;
// For making changes!
$ignoreArray = explode(',', $user_profile[$memID]['pm_ignore_list']);
foreach ($ignoreArray as $k => $dummy) {
if ($dummy == '') {
unset($ignoreArray[$k]);
}
}
// Removing a member from the ignore list?
if (isset($_GET['remove'])) {
checkSession('get');
// Heh, I'm lazy, do it the easy way...
foreach ($ignoreArray as $key => $id_remove) {
if ($id_remove == (int) $_GET['remove']) {
unset($ignoreArray[$key]);
}
}
// Make the changes.
$user_profile[$memID]['pm_ignore_list'] = implode(',', $ignoreArray);
updateMemberData($memID, array('pm_ignore_list' => $user_profile[$memID]['pm_ignore_list']));
// Redirect off the page because we don't like all this ugly query stuff to stick in the history.
redirectexit('action=profile;area=lists;sa=ignore;u=' . $memID);
} elseif (isset($_POST['new_ignore'])) {
// Prepare the string for extraction...
$_POST['new_ignore'] = strtr($smcFunc['htmlspecialchars']($_POST['new_ignore'], ENT_QUOTES), array('"' => '"'));
preg_match_all('~"([^"]+)"~', $_POST['new_ignore'], $matches);
$new_entries = array_unique(array_merge($matches[1], explode(',', preg_replace('~"[^"]+"~', '', $_POST['new_ignore']))));
foreach ($new_entries as $k => $dummy) {
$new_entries[$k] = strtr(trim($new_entries[$k]), array('\'' => '''));
if (strlen($new_entries[$k]) == 0 || in_array($new_entries[$k], array($user_profile[$memID]['member_name'], $user_profile[$memID]['real_name']))) {
unset($new_entries[$k]);
}
}
if (!empty($new_entries)) {
// Now find out the id_member for the members in question.
$request = $smcFunc['db_query']('', '
SELECT id_member
FROM {db_prefix}members
WHERE member_name IN ({array_string:new_entries}) OR real_name IN ({array_string:new_entries})
LIMIT {int:count_new_entries}', array('new_entries' => $new_entries, 'count_new_entries' => count($new_entries)));
// Add the new member to the buddies array.
while ($row = $smcFunc['db_fetch_assoc']($request)) {
$ignoreArray[] = (int) $row['id_member'];
}
$smcFunc['db_free_result']($request);
// Now update the current users buddy list.
$user_profile[$memID]['pm_ignore_list'] = implode(',', $ignoreArray);
updateMemberData($memID, array('pm_ignore_list' => $user_profile[$memID]['pm_ignore_list']));
}
// Back to the list of pityful people!
redirectexit('action=profile;area=lists;sa=ignore;u=' . $memID);
}
// Initialise the list of members we're ignoring.
$ignored = array();
if (!empty($ignoreArray)) {
$result = $smcFunc['db_query']('', '
SELECT id_member
FROM {db_prefix}members
WHERE id_member IN ({array_int:ignore_list})
ORDER BY real_name
LIMIT {int:ignore_list_count}', array('ignore_list' => $ignoreArray, 'ignore_list_count' => substr_count($user_profile[$memID]['pm_ignore_list'], ',') + 1));
while ($row = $smcFunc['db_fetch_assoc']($result)) {
$ignored[] = $row['id_member'];
}
$smcFunc['db_free_result']($result);
}
$context['ignore_count'] = count($ignored);
// Load all the members up.
loadMemberData($ignored, false, 'profile');
// Setup the context for each buddy.
$context['ignore_list'] = array();
foreach ($ignored as $ignore_member) {
loadMemberContext($ignore_member);
$context['ignore_list'][$ignore_member] = $memberContext[$ignore_member];
}
}
请发表评论