123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496 |
- <?php
- /**
- * Simple Machines Forum (SMF)
- *
- * @package SMF
- * @author Simple Machines http://www.simplemachines.org
- * @copyright 2013 Simple Machines and individual contributors
- * @license http://www.simplemachines.org/about/smf/license.php BSD
- *
- * @version 2.1 Alpha 1
- */
- if (!defined('SMF'))
- die('No direct access...');
- /**
- * View a summary.
- * @param int $memID id_member
- */
- function summary($memID)
- {
- global $context, $memberContext, $txt, $modSettings, $user_info, $user_profile, $sourcedir, $scripturl, $smcFunc;
- // Attempt to load the member's profile data.
- if (!loadMemberContext($memID) || !isset($memberContext[$memID]))
- fatal_lang_error('not_a_user', false);
- // Set up the stuff and load the user.
- $context += array(
- 'page_title' => sprintf($txt['profile_of_username'], $memberContext[$memID]['name']),
- 'can_send_pm' => allowedTo('pm_send'),
- 'can_send_email' => allowedTo('send_email_to_members'),
- 'can_have_buddy' => allowedTo('profile_identity_own') && !empty($modSettings['enable_buddylist']),
- 'can_issue_warning' => in_array('w', $context['admin_features']) && allowedTo('issue_warning') && $modSettings['warning_settings'][0] == 1,
- );
- $context['member'] = &$memberContext[$memID];
- $context['can_view_warning'] = in_array('w', $context['admin_features']) && (allowedTo('issue_warning') && !$context['user']['is_owner']) || (!empty($modSettings['warning_show']) && ($modSettings['warning_show'] > 1 || $context['user']['is_owner']));
- // Set a canonical URL for this page.
- $context['canonical_url'] = $scripturl . '?action=profile;u=' . $memID;
- // Are there things we don't show?
- $context['disabled_fields'] = isset($modSettings['disabled_profile_fields']) ? array_flip(explode(',', $modSettings['disabled_profile_fields'])) : array();
- // Menu tab
- $context[$context['profile_menu_name']]['tab_data'] = array(
- 'title' => $txt['summary'],
- 'icon' => 'profile_hd.png'
- );
- // See if they have broken any warning levels...
- list ($modSettings['warning_enable'], $modSettings['user_limit']) = explode(',', $modSettings['warning_settings']);
- if (!empty($modSettings['warning_mute']) && $modSettings['warning_mute'] <= $context['member']['warning'])
- $context['warning_status'] = $txt['profile_warning_is_muted'];
- elseif (!empty($modSettings['warning_moderate']) && $modSettings['warning_moderate'] <= $context['member']['warning'])
- $context['warning_status'] = $txt['profile_warning_is_moderation'];
- elseif (!empty($modSettings['warning_watch']) && $modSettings['warning_watch'] <= $context['member']['warning'])
- $context['warning_status'] = $txt['profile_warning_is_watch'];
- // They haven't even been registered for a full day!?
- $days_registered = (int) ((time() - $user_profile[$memID]['date_registered']) / (3600 * 24));
- if (empty($user_profile[$memID]['date_registered']) || $days_registered < 1)
- $context['member']['posts_per_day'] = $txt['not_applicable'];
- else
- $context['member']['posts_per_day'] = comma_format($context['member']['real_posts'] / $days_registered, 3);
- // Set the age...
- if (empty($context['member']['birth_date']))
- {
- $context['member'] += array(
- 'age' => $txt['not_applicable'],
- 'today_is_birthday' => false
- );
- }
- else
- {
- list ($birth_year, $birth_month, $birth_day) = sscanf($context['member']['birth_date'], '%d-%d-%d');
- $datearray = getdate(forum_time());
- $context['member'] += array(
- 'age' => $birth_year <= 4 ? $txt['not_applicable'] : $datearray['year'] - $birth_year - (($datearray['mon'] > $birth_month || ($datearray['mon'] == $birth_month && $datearray['mday'] >= $birth_day)) ? 0 : 1),
- 'today_is_birthday' => $datearray['mon'] == $birth_month && $datearray['mday'] == $birth_day
- );
- }
- if (allowedTo('moderate_forum'))
- {
- // Make sure it's a valid ip address; otherwise, don't bother...
- if (preg_match('/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/', $memberContext[$memID]['ip']) == 1 && empty($modSettings['disableHostnameLookup']))
- $context['member']['hostname'] = host_from_ip($memberContext[$memID]['ip']);
- else
- $context['member']['hostname'] = '';
- $context['can_see_ip'] = true;
- }
- else
- $context['can_see_ip'] = false;
- if (!empty($modSettings['who_enabled']))
- {
- include_once($sourcedir . '/Who.php');
- $action = determineActions($user_profile[$memID]['url']);
- if ($action !== false)
- $context['member']['action'] = $action;
- }
- // If the user is awaiting activation, and the viewer has permission - setup some activation context messages.
- if ($context['member']['is_activated'] % 10 != 1 && allowedTo('moderate_forum'))
- {
- $context['activate_type'] = $context['member']['is_activated'];
- // What should the link text be?
- $context['activate_link_text'] = in_array($context['member']['is_activated'], array(3, 4, 5, 13, 14, 15)) ? $txt['account_approve'] : $txt['account_activate'];
- // Should we show a custom message?
- $context['activate_message'] = isset($txt['account_activate_method_' . $context['member']['is_activated'] % 10]) ? $txt['account_activate_method_' . $context['member']['is_activated'] % 10] : $txt['account_not_activated'];
- }
- // Is the signature even enabled on this forum?
- $context['signature_enabled'] = substr($modSettings['signature_settings'], 0, 1) == 1;
- // How about, are they banned?
- $context['member']['bans'] = array();
- if (allowedTo('moderate_forum'))
- {
- // Can they edit the ban?
- $context['can_edit_ban'] = allowedTo('manage_bans');
- $ban_query = array();
- $ban_query_vars = array(
- 'time' => time(),
- );
- $ban_query[] = 'id_member = ' . $context['member']['id'];
- $ban_query[] = constructBanQueryIP($memberContext[$memID]['ip']);
- // Do we have a hostname already?
- if (!empty($context['member']['hostname']))
- {
- $ban_query[] = '({string:hostname} LIKE hostname)';
- $ban_query_vars['hostname'] = $context['member']['hostname'];
- }
- // Check their email as well...
- if (strlen($context['member']['email']) != 0)
- {
- $ban_query[] = '({string:email} LIKE bi.email_address)';
- $ban_query_vars['email'] = $context['member']['email'];
- }
- // So... are they banned? Dying to know!
- $request = $smcFunc['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
- );
- while ($row = $smcFunc['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>');
- $context['member']['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,
- );
- }
- $smcFunc['db_free_result']($request);
- }
- loadCustomFields($memID);
- }
- /**
- * Show all posts by the current user
- * @todo This function needs to be split up properly.
- *
- * @param int $memID id_member
- */
- function showPosts($memID)
- {
- global $txt, $user_info, $scripturl, $modSettings;
- global $context, $user_profile, $sourcedir, $smcFunc, $board;
- // Some initial context.
- $context['start'] = (int) $_REQUEST['start'];
- $context['current_member'] = $memID;
- // Create the tabs for the template.
- $context[$context['profile_menu_name']]['tab_data'] = array(
- 'title' => $txt['showPosts'],
- 'description' => $txt['showPosts_help'],
- 'icon' => 'profile_hd.png',
- 'tabs' => array(
- 'messages' => array(
- ),
- 'topics' => array(
- ),
- 'disregardedtopics' => array(
- ),
- 'attach' => array(
- ),
- ),
- );
- // Shortcut used to determine which $txt['show*'] string to use for the title, based on the SA
- $title = array(
- 'attach' => 'Attachments',
- 'disregardedtopics' => 'Disregarded',
- 'topics' => 'Topics'
- );
- // Set the page title
- if (isset($_GET['sa']) && array_key_exists($_GET['sa'], $title))
- $context['page_title'] = $txt['show' . $title[$_GET['sa']]];
- else
- $context['page_title'] = $txt['showPosts'];
- $context['page_title'] .= ' - ' . $user_profile[$memID]['real_name'];
- // Is the load average too high to allow searching just now?
- if (!empty($context['load_average']) && !empty($modSettings['loadavg_show_posts']) && $context['load_average'] >= $modSettings['loadavg_show_posts'])
- fatal_lang_error('loadavg_show_posts_disabled', false);
- // If we're specifically dealing with attachments use that function!
- if (isset($_GET['sa']) && $_GET['sa'] == 'attach')
- return showAttachments($memID);
- // Instead, if we're dealing with disregarded topics (and the feature is enabled) use that other function.
- elseif (isset($_GET['sa']) && $_GET['sa'] == 'disregardedtopics' && $modSettings['enable_disregard'])
- return showDisregarded($memID);
- // Are we just viewing topics?
- $context['is_topics'] = isset($_GET['sa']) && $_GET['sa'] == 'topics' ? true : false;
- // If just deleting a message, do it and then redirect back.
- if (isset($_GET['delete']) && !$context['is_topics'])
- {
- checkSession('get');
- // We need msg info for logging.
- $request = $smcFunc['db_query']('', '
- SELECT subject, id_member, id_topic, id_board
- FROM {db_prefix}messages
- WHERE id_msg = {int:id_msg}',
- array(
- 'id_msg' => (int) $_GET['delete'],
- )
- );
- $info = $smcFunc['db_fetch_row']($request);
- $smcFunc['db_free_result']($request);
- // Trying to remove a message that doesn't exist.
- if (empty($info))
- redirectexit('action=profile;u=' . $memID . ';area=showposts;start=' . $_GET['start']);
- // We can be lazy, since removeMessage() will check the permissions for us.
- require_once($sourcedir . '/RemoveTopic.php');
- removeMessage((int) $_GET['delete']);
- // Add it to the mod log.
- if (allowedTo('delete_any') && (!allowedTo('delete_own') || $info[1] != $user_info['id']))
- logAction('delete', array('topic' => $info[2], 'subject' => $info[0], 'member' => $info[1], 'board' => $info[3]));
- // Back to... where we are now ;).
- redirectexit('action=profile;u=' . $memID . ';area=showposts;start=' . $_GET['start']);
- }
- // Default to 10.
- if (empty($_REQUEST['viewscount']) || !is_numeric($_REQUEST['viewscount']))
- $_REQUEST['viewscount'] = '10';
- if ($context['is_topics'])
- $request = $smcFunc['db_query']('', '
- SELECT COUNT(*)
- FROM {db_prefix}topics AS t' . ($user_info['query_see_board'] == '1=1' ? '' : '
- INNER JOIN {db_prefix}boards AS b ON (b.id_board = t.id_board AND {query_see_board})') . '
- WHERE t.id_member_started = {int:current_member}' . (!empty($board) ? '
- AND t.id_board = {int:board}' : '') . (!$modSettings['postmod_active'] || $context['user']['is_owner'] ? '' : '
- AND t.approved = {int:is_approved}'),
- array(
- 'current_member' => $memID,
- 'is_approved' => 1,
- 'board' => $board,
- )
- );
- else
- $request = $smcFunc['db_query']('', '
- SELECT COUNT(*)
- FROM {db_prefix}messages AS m' . ($user_info['query_see_board'] == '1=1' ? '' : '
- INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board AND {query_see_board})') . '
- WHERE m.id_member = {int:current_member}' . (!empty($board) ? '
- AND m.id_board = {int:board}' : '') . (!$modSettings['postmod_active'] || $context['user']['is_owner'] ? '' : '
- AND m.approved = {int:is_approved}'),
- array(
- 'current_member' => $memID,
- 'is_approved' => 1,
- 'board' => $board,
- )
- );
- list ($msgCount) = $smcFunc['db_fetch_row']($request);
- $smcFunc['db_free_result']($request);
- $request = $smcFunc['db_query']('', '
- SELECT MIN(id_msg), MAX(id_msg)
- FROM {db_prefix}messages AS m
- WHERE m.id_member = {int:current_member}' . (!empty($board) ? '
- AND m.id_board = {int:board}' : '') . (!$modSettings['postmod_active'] || $context['user']['is_owner'] ? '' : '
- AND m.approved = {int:is_approved}'),
- array(
- 'current_member' => $memID,
- 'is_approved' => 1,
- 'board' => $board,
- )
- );
- list ($min_msg_member, $max_msg_member) = $smcFunc['db_fetch_row']($request);
- $smcFunc['db_free_result']($request);
- $reverse = false;
- $range_limit = '';
- $maxIndex = (int) $modSettings['defaultMaxMessages'];
- // Make sure the starting place makes sense and construct our friend the page index.
- $context['page_index'] = constructPageIndex($scripturl . '?action=profile;u=' . $memID . ';area=showposts' . ($context['is_topics'] ? ';sa=topics' : '') . (!empty($board) ? ';board=' . $board : ''), $context['start'], $msgCount, $maxIndex);
- $context['current_page'] = $context['start'] / $maxIndex;
- // Reverse the query if we're past 50% of the pages for better performance.
- $start = $context['start'];
- $reverse = $_REQUEST['start'] > $msgCount / 2;
- if ($reverse)
- {
- $maxIndex = $msgCount < $context['start'] + $modSettings['defaultMaxMessages'] + 1 && $msgCount > $context['start'] ? $msgCount - $context['start'] : (int) $modSettings['defaultMaxMessages'];
- $start = $msgCount < $context['start'] + $modSettings['defaultMaxMessages'] + 1 || $msgCount < $context['start'] + $modSettings['defaultMaxMessages'] ? 0 : $msgCount - $context['start'] - $modSettings['defaultMaxMessages'];
- }
- // Guess the range of messages to be shown.
- if ($msgCount > 1000)
- {
- $margin = floor(($max_msg_member - $min_msg_member) * (($start + $modSettings['defaultMaxMessages']) / $msgCount) + .1 * ($max_msg_member - $min_msg_member));
- // Make a bigger margin for topics only.
- if ($context['is_topics'])
- {
- $margin *= 5;
- $range_limit = $reverse ? 't.id_first_msg < ' . ($min_msg_member + $margin) : 't.id_first_msg > ' . ($max_msg_member - $margin);
- }
- else
- $range_limit = $reverse ? 'm.id_msg < ' . ($min_msg_member + $margin) : 'm.id_msg > ' . ($max_msg_member - $margin);
- }
- // Find this user's posts. The left join on categories somehow makes this faster, weird as it looks.
- $looped = false;
- while (true)
- {
- if ($context['is_topics'])
- {
- $request = $smcFunc['db_query']('', '
- SELECT
- b.id_board, b.name AS bname, c.id_cat, c.name AS cname, t.id_member_started, t.id_first_msg, t.id_last_msg,
- t.approved, m.body, m.smileys_enabled, m.subject, m.poster_time, m.id_topic, m.id_msg
- FROM {db_prefix}topics AS t
- INNER JOIN {db_prefix}boards AS b ON (b.id_board = t.id_board)
- LEFT JOIN {db_prefix}categories AS c ON (c.id_cat = b.id_cat)
- INNER JOIN {db_prefix}messages AS m ON (m.id_msg = t.id_first_msg)
- WHERE t.id_member_started = {int:current_member}' . (!empty($board) ? '
- AND t.id_board = {int:board}' : '') . (empty($range_limit) ? '' : '
- AND ' . $range_limit) . '
- AND {query_see_board}' . (!$modSettings['postmod_active'] || $context['user']['is_owner'] ? '' : '
- AND t.approved = {int:is_approved} AND m.approved = {int:is_approved}') . '
- ORDER BY t.id_first_msg ' . ($reverse ? 'ASC' : 'DESC') . '
- LIMIT ' . $start . ', ' . $maxIndex,
- array(
- 'current_member' => $memID,
- 'is_approved' => 1,
- 'board' => $board,
- )
- );
- }
- else
- {
- $request = $smcFunc['db_query']('', '
- SELECT
- b.id_board, b.name AS bname, c.id_cat, c.name AS cname, m.id_topic, m.id_msg,
- t.id_member_started, t.id_first_msg, t.id_last_msg, m.body, m.smileys_enabled,
- m.subject, m.poster_time, m.approved
- FROM {db_prefix}messages AS m
- INNER JOIN {db_prefix}topics AS t ON (t.id_topic = m.id_topic)
- INNER JOIN {db_prefix}boards AS b ON (b.id_board = t.id_board)
- LEFT JOIN {db_prefix}categories AS c ON (c.id_cat = b.id_cat)
- WHERE m.id_member = {int:current_member}' . (!empty($board) ? '
- AND b.id_board = {int:board}' : '') . (empty($range_limit) ? '' : '
- AND ' . $range_limit) . '
- AND {query_see_board}' . (!$modSettings['postmod_active'] || $context['user']['is_owner'] ? '' : '
- AND t.approved = {int:is_approved} AND m.approved = {int:is_approved}') . '
- ORDER BY m.id_msg ' . ($reverse ? 'ASC' : 'DESC') . '
- LIMIT ' . $start . ', ' . $maxIndex,
- array(
- 'current_member' => $memID,
- 'is_approved' => 1,
- 'board' => $board,
- )
- );
- }
- // Make sure we quit this loop.
- if ($smcFunc['db_num_rows']($request) === $maxIndex || $looped)
- break;
- $looped = true;
- $range_limit = '';
- }
- // Start counting at the number of the first message displayed.
- $counter = $reverse ? $context['start'] + $maxIndex + 1 : $context['start'];
- $context['posts'] = array();
- $board_ids = array('own' => array(), 'any' => array());
- while ($row = $smcFunc['db_fetch_assoc']($request))
- {
- // Censor....
- censorText($row['body']);
- censorText($row['subject']);
- // Do the code.
- $row['body'] = parse_bbc($row['body'], $row['smileys_enabled'], $row['id_msg']);
- // And the array...
- $context['posts'][$counter += $reverse ? -1 : 1] = array(
- 'body' => $row['body'],
- 'counter' => $counter,
- 'alternate' => $counter % 2,
- 'category' => array(
- 'name' => $row['cname'],
- 'id' => $row['id_cat']
- ),
- 'board' => array(
- 'name' => $row['bname'],
- 'id' => $row['id_board']
- ),
- 'topic' => $row['id_topic'],
- 'subject' => $row['subject'],
- 'start' => 'msg' . $row['id_msg'],
- 'time' => timeformat($row['poster_time']),
- 'timestamp' => forum_time(true, $row['poster_time']),
- 'id' => $row['id_msg'],
- 'can_reply' => false,
- 'can_mark_notify' => false,
- 'can_delete' => false,
- 'delete_possible' => ($row['id_first_msg'] != $row['id_msg'] || $row['id_last_msg'] == $row['id_msg']) && (empty($modSettings['edit_disable_time']) || $row['poster_time'] + $modSettings['edit_disable_time'] * 60 >= time()),
- 'approved' => $row['approved'],
- );
- if ($user_info['id'] == $row['id_member_started'])
- $board_ids['own'][$row['id_board']][] = $counter;
- $board_ids['any'][$row['id_board']][] = $counter;
- }
- $smcFunc['db_free_result']($request);
- // All posts were retrieved in reverse order, get them right again.
- if ($reverse)
- $context['posts'] = array_reverse($context['posts'], true);
- // These are all the permissions that are different from board to board..
- if ($context['is_topics'])
- $permissions = array(
- 'own' => array(
- 'post_reply_own' => 'can_reply',
- ),
- 'any' => array(
- 'post_reply_any' => 'can_reply',
- 'mark_any_notify' => 'can_mark_notify',
- )
- );
- else
- $permissions = array(
- 'own' => array(
- 'post_reply_own' => 'can_reply',
- 'delete_own' => 'can_delete',
- ),
- 'any' => array(
- 'post_reply_any' => 'can_reply',
- 'mark_any_notify' => 'can_mark_notify',
- 'delete_any' => 'can_delete',
- )
- );
- // For every permission in the own/any lists...
- foreach ($permissions as $type => $list)
- {
- foreach ($list as $permission => $allowed)
- {
- // Get the boards they can do this on...
- $boards = boardsAllowedTo($permission);
- // Hmm, they can do it on all boards, can they?
- if (!empty($boards) && $boards[0] == 0)
- $boards = array_keys($board_ids[$type]);
- // Now go through each board they can do the permission on.
- foreach ($boards as $board_id)
- {
- // There aren't any posts displayed from this board.
- if (!isset($board_ids[$type][$board_id]))
- continue;
- // Set the permission to true ;).
- foreach ($board_ids[$type][$board_id] as $counter)
- $context['posts'][$counter][$allowed] = true;
- }
- }
- }
- // Clean up after posts that cannot be deleted and quoted.
- $quote_enabled = empty($modSettings['disabledBBC']) || !in_array('quote', explode(',', $modSettings['disabledBBC']));
- foreach ($context['posts'] as $counter => $dummy)
- {
- $context['posts'][$counter]['can_delete'] &= $context['posts'][$counter]['delete_possible'];
- $context['posts'][$counter]['can_quote'] = $context['posts'][$counter]['can_reply'] && $quote_enabled;
- }
- }
- /**
- * Show all the attachments of a user.
- *
- * @param int $memID id_member
- */
- function showAttachments($memID)
- {
- global $txt, $user_info, $scripturl, $modSettings, $board;
- global $context, $user_profile, $sourcedir, $smcFunc;
- // OBEY permissions!
- $boardsAllowed = boardsAllowedTo('view_attachments');
- // Make sure we can't actually see anything...
- if (empty($boardsAllowed))
- $boardsAllowed = array(-1);
- require_once($sourcedir . '/Subs-List.php');
- // This is all the information required to list attachments.
- $listOptions = array(
- 'id' => 'attachments',
- 'width' => '100%',
- 'items_per_page' => $modSettings['defaultMaxMessages'],
- 'no_items_label' => $txt['show_attachments_none'],
- 'base_href' => $scripturl . '?action=profile;area=showposts;sa=attach;u=' . $memID,
- 'default_sort_col' => 'filename',
- 'get_items' => array(
- 'function' => 'list_getAttachments',
- 'params' => array(
- $boardsAllowed,
- $memID,
- ),
- ),
- 'get_count' => array(
- 'function' => 'list_getNumAttachments',
- 'params' => array(
- $boardsAllowed,
- $memID,
- ),
- ),
- 'data_check' => array(
- 'class' => create_function('$data', '
- return $data[\'approved\'] ? \'\' : \'approvebg\';
- ')
- ),
- 'columns' => array(
- 'filename' => array(
- 'header' => array(
- 'value' => $txt['show_attach_filename'],
- 'class' => 'lefttext',
- 'style' => 'width: 25%;',
- ),
- 'data' => array(
- 'sprintf' => array(
- 'format' => '<a href="' . $scripturl . '?action=dlattach;topic=%1$d.0;attach=%2$d">%3$s</a>',
- 'params' => array(
- 'topic' => true,
- 'id' => true,
- 'filename' => false,
- ),
- ),
- ),
- 'sort' => array(
- 'default' => 'a.filename',
- 'reverse' => 'a.filename DESC',
- ),
- ),
- 'downloads' => array(
- 'header' => array(
- 'value' => $txt['show_attach_downloads'],
- 'style' => 'width: 12%;',
- ),
- 'data' => array(
- 'db' => 'downloads',
- 'comma_format' => true,
- ),
- 'sort' => array(
- 'default' => 'a.downloads',
- 'reverse' => 'a.downloads DESC',
- ),
- ),
- 'subject' => array(
- 'header' => array(
- 'value' => $txt['message'],
- 'class' => 'lefttext',
- 'style' => 'width: 30%;',
- ),
- 'data' => array(
- 'sprintf' => array(
- 'format' => '<a href="' . $scripturl . '?msg=%1$d">%2$s</a>',
- 'params' => array(
- 'msg' => true,
- 'subject' => false,
- ),
- ),
- ),
- 'sort' => array(
- 'default' => 'm.subject',
- 'reverse' => 'm.subject DESC',
- ),
- ),
- 'posted' => array(
- 'header' => array(
- 'value' => $txt['show_attach_posted'],
- 'class' => 'lefttext',
- ),
- 'data' => array(
- 'db' => 'posted',
- 'timeformat' => true,
- ),
- 'sort' => array(
- 'default' => 'm.poster_time',
- 'reverse' => 'm.poster_time DESC',
- ),
- ),
- ),
- );
- // Create the request list.
- createList($listOptions);
- }
- /**
- * Get a list of attachments for this user
- *
- * @param int $start
- * @param int $items_per_page
- * @param string $sort
- * @param array $boardsAllowed
- * @param ing $memID
- * @return array
- */
- function list_getAttachments($start, $items_per_page, $sort, $boardsAllowed, $memID)
- {
- global $smcFunc, $board, $modSettings, $context;
- // Retrieve some attachments.
- $request = $smcFunc['db_query']('', '
- SELECT a.id_attach, a.id_msg, a.filename, a.downloads, a.approved, m.id_msg, m.id_topic,
- m.id_board, m.poster_time, m.subject, b.name
- FROM {db_prefix}attachments AS a
- INNER JOIN {db_prefix}messages AS m ON (m.id_msg = a.id_msg)
- INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board AND {query_see_board})
- WHERE a.attachment_type = {int:attachment_type}
- AND a.id_msg != {int:no_message}
- AND m.id_member = {int:current_member}' . (!empty($board) ? '
- AND b.id_board = {int:board}' : '') . (!in_array(0, $boardsAllowed) ? '
- AND b.id_board IN ({array_int:boards_list})' : '') . (!$modSettings['postmod_active'] || $context['user']['is_owner'] ? '' : '
- AND m.approved = {int:is_approved}') . '
- ORDER BY {raw:sort}
- LIMIT {int:offset}, {int:limit}',
- array(
- 'boards_list' => $boardsAllowed,
- 'attachment_type' => 0,
- 'no_message' => 0,
- 'current_member' => $memID,
- 'is_approved' => 1,
- 'board' => $board,
- 'sort' => $sort,
- 'offset' => $start,
- 'limit' => $items_per_page,
- )
- );
- $attachments = array();
- while ($row = $smcFunc['db_fetch_assoc']($request))
- $attachments[] = array(
- 'id' => $row['id_attach'],
- 'filename' => $row['filename'],
- 'downloads' => $row['downloads'],
- 'subject' => censorText($row['subject']),
- 'posted' => $row['poster_time'],
- 'msg' => $row['id_msg'],
- 'topic' => $row['id_topic'],
- 'board' => $row['id_board'],
- 'board_name' => $row['name'],
- 'approved' => $row['approved'],
- );
- $smcFunc['db_free_result']($request);
- return $attachments;
- }
- /**
- * Gets the total number of attachments for the user
- *
- * @param type $boardsAllowed
- * @param type $memID
- * @return type
- */
- function list_getNumAttachments($boardsAllowed, $memID)
- {
- global $board, $smcFunc, $modSettings, $context;
- // Get the total number of attachments they have posted.
- $request = $smcFunc['db_query']('', '
- SELECT COUNT(*)
- FROM {db_prefix}attachments AS a
- INNER JOIN {db_prefix}messages AS m ON (m.id_msg = a.id_msg)
- INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board AND {query_see_board})
- WHERE a.attachment_type = {int:attachment_type}
- AND a.id_msg != {int:no_message}
- AND m.id_member = {int:current_member}' . (!empty($board) ? '
- AND b.id_board = {int:board}' : '') . (!in_array(0, $boardsAllowed) ? '
- AND b.id_board IN ({array_int:boards_list})' : '') . (!$modSettings['postmod_active'] || $context['user']['is_owner'] ? '' : '
- AND m.approved = {int:is_approved}'),
- array(
- 'boards_list' => $boardsAllowed,
- 'attachment_type' => 0,
- 'no_message' => 0,
- 'current_member' => $memID,
- 'is_approved' => 1,
- 'board' => $board,
- )
- );
- list ($attachCount) = $smcFunc['db_fetch_row']($request);
- $smcFunc['db_free_result']($request);
- return $attachCount;
- }
- /**
- * Show all the disregarded topics.
- *
- * @param int $memID id_member
- */
- function showDisregarded($memID)
- {
- global $txt, $user_info, $scripturl, $modSettings, $board, $context, $sourcedir, $smcFunc;
- // Only the owner can see the list (if the function is enabled of course)
- if ($user_info['id'] != $memID || !$modSettings['enable_disregard'])
- return;
- require_once($sourcedir . '/Subs-List.php');
- // And here they are: the topics you don't like
- $listOptions = array(
- 'id' => 'disregarded_topics',
- 'width' => '100%',
- 'items_per_page' => $modSettings['defaultMaxMessages'],
- 'no_items_label' => $txt['disregarded_topics_none'],
- 'base_href' => $scripturl . '?action=profile;area=showposts;sa=disregardedtopics;u=' . $memID,
- 'default_sort_col' => 'started_on',
- 'get_items' => array(
- 'function' => 'list_getDisregarded',
- 'params' => array(
- $memID,
- ),
- ),
- 'get_count' => array(
- 'function' => 'list_getNumDisregarded',
- 'params' => array(
- $memID,
- ),
- ),
- 'columns' => array(
- 'subject' => array(
- 'header' => array(
- 'value' => $txt['subject'],
- 'class' => 'lefttext',
- 'style' => 'width: 30%;',
- ),
- 'data' => array(
- 'sprintf' => array(
- 'format' => '<a href="' . $scripturl . '?topic=%1$d.0">%2$s</a>',
- 'params' => array(
- 'id_topic' => false,
- 'subject' => false,
- ),
- ),
- ),
- 'sort' => array(
- 'default' => 'm.subject',
- 'reverse' => 'm.subject DESC',
- ),
- ),
- 'started_by' => array(
- 'header' => array(
- 'value' => $txt['started_by'],
- 'style' => 'width: 15%;',
- ),
- 'data' => array(
- 'db' => 'started_by',
- ),
- 'sort' => array(
- 'default' => 'mem.real_name',
- 'reverse' => 'mem.real_name DESC',
- ),
- ),
- 'started_on' => array(
- 'header' => array(
- 'value' => $txt['on'],
- 'class' => 'lefttext',
- 'style' => 'width: 20%;',
- ),
- 'data' => array(
- 'db' => 'started_on',
- 'timeformat' => true,
- ),
- 'sort' => array(
- 'default' => 'm.poster_time',
- 'reverse' => 'm.poster_time DESC',
- ),
- ),
- 'last_post_by' => array(
- 'header' => array(
- 'value' => $txt['last_post'],
- 'style' => 'width: 15%;',
- ),
- 'data' => array(
- 'db' => 'last_post_by',
- ),
- 'sort' => array(
- 'default' => 'mem.real_name',
- 'reverse' => 'mem.real_name DESC',
- ),
- ),
- 'last_post_on' => array(
- 'header' => array(
- 'value' => $txt['on'],
- 'class' => 'lefttext',
- 'style' => 'width: 20%;',
- ),
- 'data' => array(
- 'db' => 'last_post_on',
- 'timeformat' => true,
- ),
- 'sort' => array(
- 'default' => 'm.poster_time',
- 'reverse' => 'm.poster_time DESC',
- ),
- ),
- ),
- );
- // Create the request list.
- createList($listOptions);
- $context['sub_template'] = 'show_list';
- $context['default_list'] = 'disregarded_topics';
- }
- /**
- * Get the relevant topics in the disregarded list
- */
- function list_getDisregarded($start, $items_per_page, $sort, $memID)
- {
- global $smcFunc, $board, $modSettings, $context;
- // Get the list of topics we can see
- $request = $smcFunc['db_query']('', '
- SELECT lt.id_topic
- FROM {db_prefix}log_topics as lt
- LEFT JOIN {db_prefix}topics as t ON (lt.id_topic = t.id_topic)
- LEFT JOIN {db_prefix}boards as b ON (t.id_board = b.id_board)
- LEFT JOIN {db_prefix}messages as m ON (t.id_first_msg = m.id_msg)' . (in_array($sort, array('mem.real_name', 'mem.real_name DESC', 'mem.poster_time', 'mem.poster_time DESC')) ? '
- LEFT JOIN {db_prefix}members as mem ON (m.id_member = mem.id_member)' : '') . '
- WHERE lt.id_member = {int:current_member}
- AND disregarded = 1
- AND {query_see_board}
- ORDER BY {raw:sort}
- LIMIT {int:offset}, {int:limit}',
- array(
- 'current_member' => $memID,
- 'sort' => $sort,
- 'offset' => $start,
- 'limit' => $items_per_page,
- )
- );
- $topics = array();
- while ($row = $smcFunc['db_fetch_assoc']($request))
- $topics[] = $row['id_topic'];
- $smcFunc['db_free_result']($request);
- // Any topics found?
- $topicsInfo = array();
- if (!empty($topics))
- {
- $request = $smcFunc['db_query']('', '
- SELECT mf.subject, mf.poster_time as started_on, IFNULL(memf.real_name, mf.poster_name) as started_by, ml.poster_time as last_post_on, IFNULL(meml.real_name, ml.poster_name) as last_post_by, t.id_topic
- FROM {db_prefix}topics AS t
- INNER JOIN {db_prefix}messages AS ml ON (ml.id_msg = t.id_last_msg)
- INNER JOIN {db_prefix}messages AS mf ON (mf.id_msg = t.id_first_msg)
- LEFT JOIN {db_prefix}members AS meml ON (meml.id_member = ml.id_member)
- LEFT JOIN {db_prefix}members AS memf ON (memf.id_member = mf.id_member)
- WHERE t.id_topic IN ({array_int:topics})',
- array(
- 'topics' => $topics,
- )
- );
- while ($row = $smcFunc['db_fetch_assoc']($request))
- $topicsInfo[] = $row;
- $smcFunc['db_free_result']($request);
- }
- return $topicsInfo;
- }
- /**
- * Count the number of topics in the disregarded list
- *
- * @param int $memID
- */
- function list_getNumDisregarded($memID)
- {
- global $smcFunc, $user_info;
- // Get the total number of attachments they have posted.
- $request = $smcFunc['db_query']('', '
- SELECT COUNT(*)
- FROM {db_prefix}log_topics as lt
- LEFT JOIN {db_prefix}topics as t ON (lt.id_topic = t.id_topic)
- LEFT JOIN {db_prefix}boards as b ON (t.id_board = b.id_board)
- WHERE id_member = {int:current_member}
- AND disregarded = 1
- AND {query_see_board}',
- array(
- 'current_member' => $memID,
- )
- );
- list ($disregardedCount) = $smcFunc['db_fetch_row']($request);
- $smcFunc['db_free_result']($request);
- return $disregardedCount;
- }
- /**
- * Gets the user stats for display
- *
- * @param int $memID id_member
- */
- function statPanel($memID)
- {
- global $txt, $scripturl, $context, $user_profile, $user_info, $modSettings, $smcFunc;
- $context['page_title'] = $txt['statPanel_showStats'] . ' ' . $user_profile[$memID]['real_name'];
- // Is the load average too high to allow searching just now?
- if (!empty($context['load_average']) && !empty($modSettings['loadavg_userstats']) && $context['load_average'] >= $modSettings['loadavg_userstats'])
- fatal_lang_error('loadavg_userstats_disabled', false);
- // General user statistics.
- $timeDays = floor($user_profile[$memID]['total_time_logged_in'] / 86400);
- $timeHours = floor(($user_profile[$memID]['total_time_logged_in'] % 86400) / 3600);
- $context['time_logged_in'] = ($timeDays > 0 ? $timeDays . $txt['totalTimeLogged2'] : '') . ($timeHours > 0 ? $timeHours . $txt['totalTimeLogged3'] : '') . floor(($user_profile[$memID]['total_time_logged_in'] % 3600) / 60) . $txt['totalTimeLogged4'];
- $context['num_posts'] = comma_format($user_profile[$memID]['posts']);
- // Menu tab
- $context[$context['profile_menu_name']]['tab_data'] = array(
- 'title' => $txt['statPanel_generalStats'] . ' - ' . $context['member']['name'],
- 'icon' => 'stats_info_hd.png'
- );
- // Number of topics started.
- $result = $smcFunc['db_query']('', '
- SELECT COUNT(*)
- FROM {db_prefix}topics
- WHERE id_member_started = {int:current_member}' . (!empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0 ? '
- AND id_board != {int:recycle_board}' : ''),
- array(
- 'current_member' => $memID,
- 'recycle_board' => $modSettings['recycle_board'],
- )
- );
- list ($context['num_topics']) = $smcFunc['db_fetch_row']($result);
- $smcFunc['db_free_result']($result);
- // Number polls started.
- $result = $smcFunc['db_query']('', '
- SELECT COUNT(*)
- FROM {db_prefix}topics
- WHERE id_member_started = {int:current_member}' . (!empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0 ? '
- AND id_board != {int:recycle_board}' : '') . '
- AND id_poll != {int:no_poll}',
- array(
- 'current_member' => $memID,
- 'recycle_board' => $modSettings['recycle_board'],
- 'no_poll' => 0,
- )
- );
- list ($context['num_polls']) = $smcFunc['db_fetch_row']($result);
- $smcFunc['db_free_result']($result);
- // Number polls voted in.
- $result = $smcFunc['db_query']('distinct_poll_votes', '
- SELECT COUNT(DISTINCT id_poll)
- FROM {db_prefix}log_polls
- WHERE id_member = {int:current_member}',
- array(
- 'current_member' => $memID,
- )
- );
- list ($context['num_votes']) = $smcFunc['db_fetch_row']($result);
- $smcFunc['db_free_result']($result);
- // Format the numbers...
- $context['num_topics'] = comma_format($context['num_topics']);
- $context['num_polls'] = comma_format($context['num_polls']);
- $context['num_votes'] = comma_format($context['num_votes']);
- // Grab the board this member posted in most often.
- $result = $smcFunc['db_query']('', '
- SELECT
- b.id_board, MAX(b.name) AS name, MAX(b.num_posts) AS num_posts, COUNT(*) AS message_count
- FROM {db_prefix}messages AS m
- INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board)
- WHERE m.id_member = {int:current_member}
- AND b.count_posts = {int:count_enabled}
- AND {query_see_board}
- GROUP BY b.id_board
- ORDER BY message_count DESC
- LIMIT 10',
- array(
- 'current_member' => $memID,
- 'count_enabled' => 0,
- )
- );
- $context['popular_boards'] = array();
- while ($row = $smcFunc['db_fetch_assoc']($result))
- {
- $context['popular_boards'][$row['id_board']] = array(
- 'id' => $row['id_board'],
- 'posts' => $row['message_count'],
- 'href' => $scripturl . '?board=' . $row['id_board'] . '.0',
- 'link' => '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['name'] . '</a>',
- 'posts_percent' => $user_profile[$memID]['posts'] == 0 ? 0 : ($row['message_count'] * 100) / $user_profile[$memID]['posts'],
- 'total_posts' => $row['num_posts'],
- 'total_posts_member' => $user_profile[$memID]['posts'],
- );
- }
- $smcFunc['db_free_result']($result);
- // Now get the 10 boards this user has most often participated in.
- $result = $smcFunc['db_query']('profile_board_stats', '
- SELECT
- b.id_board, MAX(b.name) AS name, b.num_posts, COUNT(*) AS message_count,
- CASE WHEN COUNT(*) > MAX(b.num_posts) THEN 1 ELSE COUNT(*) / MAX(b.num_posts) END * 100 AS percentage
- FROM {db_prefix}messages AS m
- INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board)
- WHERE m.id_member = {int:current_member}
- AND {query_see_board}
- GROUP BY b.id_board, b.num_posts
- ORDER BY percentage DESC
- LIMIT 10',
- array(
- 'current_member' => $memID,
- )
- );
- $context['board_activity'] = array();
- while ($row = $smcFunc['db_fetch_assoc']($result))
- {
- $context['board_activity'][$row['id_board']] = array(
- 'id' => $row['id_board'],
- 'posts' => $row['message_count'],
- 'href' => $scripturl . '?board=' . $row['id_board'] . '.0',
- 'link' => '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['name'] . '</a>',
- 'percent' => comma_format((float) $row['percentage'], 2),
- 'posts_percent' => (float) $row['percentage'],
- 'total_posts' => $row['num_posts'],
- );
- }
- $smcFunc['db_free_result']($result);
- // Posting activity by time.
- $result = $smcFunc['db_query']('user_activity_by_time', '
- SELECT
- HOUR(FROM_UNIXTIME(poster_time + {int:time_offset})) AS hour,
- COUNT(*) AS post_count
- FROM {db_prefix}messages
- WHERE id_member = {int:current_member}' . ($modSettings['totalMessages'] > 100000 ? '
- AND id_topic > {int:top_ten_thousand_topics}' : '') . '
- GROUP BY hour',
- array(
- 'current_member' => $memID,
- 'top_ten_thousand_topics' => $modSettings['totalTopics'] - 10000,
- 'time_offset' => (($user_info['time_offset'] + $modSettings['time_offset']) * 3600),
- )
- );
- $maxPosts = $realPosts = 0;
- $context['posts_by_time'] = array();
- while ($row = $smcFunc['db_fetch_assoc']($result))
- {
- // Cast as an integer to remove the leading 0.
- $row['hour'] = (int) $row['hour'];
- $maxPosts = max($row['post_count'], $maxPosts);
- $realPosts += $row['post_count'];
- $context['posts_by_time'][$row['hour']] = array(
- 'hour' => $row['hour'],
- 'hour_format' => stripos($user_info['time_format'], '%p') === false ? $row['hour'] : date('g a', mktime($row['hour'])),
- 'posts' => $row['post_count'],
- 'posts_percent' => 0,
- 'is_last' => $row['hour'] == 23,
- );
- }
- $smcFunc['db_free_result']($result);
- if ($maxPosts > 0)
- for ($hour = 0; $hour < 24; $hour++)
- {
- if (!isset($context['posts_by_time'][$hour]))
- $context['posts_by_time'][$hour] = array(
- 'hour' => $hour,
- 'hour_format' => stripos($user_info['time_format'], '%p') === false ? $hour : date('g a', mktime($hour)),
- 'posts' => 0,
- 'posts_percent' => 0,
- 'relative_percent' => 0,
- 'is_last' => $hour == 23,
- );
- else
- {
- $context['posts_by_time'][$hour]['posts_percent'] = round(($context['posts_by_time'][$hour]['posts'] * 100) / $realPosts);
- $context['posts_by_time'][$hour]['relative_percent'] = round(($context['posts_by_time'][$hour]['posts'] * 100) / $maxPosts);
- }
- }
- // Put it in the right order.
- ksort($context['posts_by_time']);
- // Custom stats (just add a template_layer to add it to the template!)
- call_integration_hook('integrate_profile_stats', array($memID));
- }
- /**
- * @todo needs a description
- *
- * @param int $memID id_member
- */
- function tracking($memID)
- {
- global $sourcedir, $context, $txt, $scripturl, $modSettings, $user_profile;
- $subActions = array(
- 'activity' => array('trackActivity', $txt['trackActivity']),
- 'ip' => array('TrackIP', $txt['trackIP']),
- 'edits' => array('trackEdits', $txt['trackEdits']),
- 'logins' => array('TrackLogins', $txt['trackLogins']),
- );
- $context['tracking_area'] = isset($_GET['sa']) && isset($subActions[$_GET['sa']]) ? $_GET['sa'] : 'activity';
- // @todo what is $types? it is never set so this will never be true
- if (isset($types[$context['tracking_area']][1]))
- require_once($sourcedir . '/' . $types[$context['tracking_area']][1]);
- // Create the tabs for the template.
- $context[$context['profile_menu_name']]['tab_data'] = array(
- 'title' => $txt['tracking'],
- 'description' => $txt['tracking_description'],
- 'icon' => 'profile_hd.png',
- 'tabs' => array(
- 'activity' => array(),
- 'ip' => array(),
- 'edits' => array(),
- ),
- );
- // Moderation must be on to track edits.
- if (empty($modSettings['modlog_enabled']))
- unset($context[$context['profile_menu_name']]['tab_data']['edits']);
- // Set a page title.
- $context['page_title'] = $txt['trackUser'] . ' - ' . $subActions[$context['tracking_area']][1] . ' - ' . $user_profile[$memID]['real_name'];
- // Pass on to the actual function.
- $context['sub_template'] = $subActions[$context['tracking_area']][0];
- $subActions[$context['tracking_area']][0]($memID);
- }
- /**
- * @todo needs a description
- *
- * @param int $memID id_member
- */
- function trackActivity($memID)
- {
- global $scripturl, $txt, $modSettings, $sourcedir;
- global $user_profile, $context, $smcFunc;
- // Verify if the user has sufficient permissions.
- isAllowedTo('moderate_forum');
- $context['last_ip'] = $user_profile[$memID]['member_ip'];
- if ($context['last_ip'] != $user_profile[$memID]['member_ip2'])
- $context['last_ip2'] = $user_profile[$memID]['member_ip2'];
- $context['member']['name'] = $user_profile[$memID]['real_name'];
- // Set the options for the list component.
- $listOptions = array(
- 'id' => 'track_user_list',
- 'title' => $txt['errors_by'] . ' ' . $context['member']['name'],
- 'items_per_page' => $modSettings['defaultMaxMessages'],
- 'no_items_label' => $txt['no_errors_from_user'],
- 'base_href' => $scripturl . '?action=profile;area=tracking;sa=user;u=' . $memID,
- 'default_sort_col' => 'date',
- 'get_items' => array(
- 'function' => 'list_getUserErrors',
- 'params' => array(
- 'le.id_member = {int:current_member}',
- array('current_member' => $memID),
- ),
- ),
- 'get_count' => array(
- 'function' => 'list_getUserErrorCount',
- 'params' => array(
- 'id_member = {int:current_member}',
- array('current_member' => $memID),
- ),
- ),
- 'columns' => array(
- 'ip_address' => array(
- 'header' => array(
- 'value' => $txt['ip_address'],
- ),
- 'data' => array(
- 'sprintf' => array(
- 'format' => '<a href="' . $scripturl . '?action=profile;area=tracking;sa=ip;searchip=%1$s;u=' . $memID. '">%1$s</a>',
- 'params' => array(
- 'ip' => false,
- ),
- ),
- ),
- 'sort' => array(
- 'default' => 'le.ip',
- 'reverse' => 'le.ip DESC',
- ),
- ),
- 'message' => array(
- 'header' => array(
- 'value' => $txt['message'],
- ),
- 'data' => array(
- 'sprintf' => array(
- 'format' => '%1$s<br /><a href="%2$s">%2$s</a>',
- 'params' => array(
- 'message' => false,
- 'url' => false,
- ),
- ),
- ),
- ),
- 'date' => array(
- 'header' => array(
- 'value' => $txt['date'],
- ),
- 'data' => array(
- 'db' => 'time',
- ),
- 'sort' => array(
- 'default' => 'le.id_error DESC',
- 'reverse' => 'le.id_error',
- ),
- ),
- ),
- 'additional_rows' => array(
- array(
- 'position' => 'after_title',
- 'value' => $txt['errors_desc'],
- 'class' => 'windowbg2',
- 'style' => 'padding: 1ex 2ex;',
- ),
- ),
- );
- // Create the list for viewing.
- require_once($sourcedir . '/Subs-List.php');
- createList($listOptions);
- // @todo cache this
- // If this is a big forum, or a large posting user, let's limit the search.
- if ($modSettings['totalMessages'] > 50000 && $user_profile[$memID]['posts'] > 500)
- {
- $request = $smcFunc['db_query']('', '
- SELECT MAX(id_msg)
- FROM {db_prefix}messages AS m
- WHERE m.id_member = {int:current_member}',
- array(
- 'current_member' => $memID,
- )
- );
- list ($max_msg_member) = $smcFunc['db_fetch_row']($request);
- $smcFunc['db_free_result']($request);
- // There's no point worrying ourselves with messages made yonks ago, just get recent ones!
- $min_msg_member = max(0, $max_msg_member - $user_profile[$memID]['posts'] * 3);
- }
- // Default to at least the ones we know about.
- $ips = array(
- $user_profile[$memID]['member_ip'],
- $user_profile[$memID]['member_ip2'],
- );
- // @todo cache this
- // Get all IP addresses this user has used for his messages.
- $request = $smcFunc['db_query']('', '
- SELECT poster_ip
- FROM {db_prefix}messages
- WHERE id_member = {int:current_member}
- ' . (isset($min_msg_member) ? '
- AND id_msg >= {int:min_msg_member} AND id_msg <= {int:max_msg_member}' : '') . '
- GROUP BY poster_ip',
- array(
- 'current_member' => $memID,
- 'min_msg_member' => !empty($min_msg_member) ? $min_msg_member : 0,
- 'max_msg_member' => !empty($max_msg_member) ? $max_msg_member : 0,
- )
- );
- $context['ips'] = array();
- while ($row = $smcFunc['db_fetch_assoc']($request))
- {
- $context['ips'][] = '<a href="' . $scripturl . '?action=profile;area=tracking;sa=ip;searchip=' . $row['poster_ip'] . ';u=' . $memID . '">' . $row['poster_ip'] . '</a>';
- $ips[] = $row['poster_ip'];
- }
- $smcFunc['db_free_result']($request);
- // Now also get the IP addresses from the error messages.
- $request = $smcFunc['db_query']('', '
- SELECT COUNT(*) AS error_count, ip
- FROM {db_prefix}log_errors
- WHERE id_member = {int:current_member}
- GROUP BY ip',
- array(
- 'current_member' => $memID,
- )
- );
- $context['error_ips'] = array();
- while ($row = $smcFunc['db_fetch_assoc']($request))
- {
- $context['error_ips'][] = '<a href="' . $scripturl . '?action=profile;area=tracking;sa=ip;searchip=' . $row['ip'] . ';u=' . $memID . '">' . $row['ip'] . '</a>';
- $ips[] = $row['ip'];
- }
- $smcFunc['db_free_result']($request);
- // Find other users that might use the same IP.
- $ips = array_unique($ips);
- $context['members_in_range'] = array();
- if (!empty($ips))
- {
- // Get member ID's which are in messages...
- $request = $smcFunc['db_query']('', '
- SELECT mem.id_member
- FROM {db_prefix}messages AS m
- INNER JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member)
- WHERE m.poster_ip IN ({array_string:ip_list})
- GROUP BY mem.id_member
- HAVING mem.id_member != {int:current_member}',
- array(
- 'current_member' => $memID,
- 'ip_list' => $ips,
- )
- );
- $message_members = array();
- while ($row = $smcFunc['db_fetch_assoc']($request))
- $message_members[] = $row['id_member'];
- $smcFunc['db_free_result']($request);
- // Fetch their names, cause of the GROUP BY doesn't like giving us that normally.
- if (!empty($message_members))
- {
- $request = $smcFunc['db_query']('', '
- SELECT id_member, real_name
- FROM {db_prefix}members
- WHERE id_member IN ({array_int:message_members})',
- array(
- 'message_members' => $message_members,
- 'ip_list' => $ips,
- )
- );
- while ($row = $smcFunc['db_fetch_assoc']($request))
- $context['members_in_range'][$row['id_member']] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>';
- $smcFunc['db_free_result']($request);
- }
- $request = $smcFunc['db_query']('', '
- SELECT id_member, real_name
- FROM {db_prefix}members
- WHERE id_member != {int:current_member}
- AND member_ip IN ({array_string:ip_list})',
- array(
- 'current_member' => $memID,
- 'ip_list' => $ips,
- )
- );
- while ($row = $smcFunc['db_fetch_assoc']($request))
- $context['members_in_range'][$row['id_member']] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>';
- $smcFunc['db_free_result']($request);
- }
- }
- /**
- * Get the number of user errors
- *
- * @param string $where
- * @param array $where_vars = array()
- * @return string number of user errors
- */
- function list_getUserErrorCount($where, $where_vars = array())
- {
- global $smcFunc;
- $request = $smcFunc['db_query']('', '
- SELECT COUNT(*) AS error_count
- FROM {db_prefix}log_errors
- WHERE ' . $where,
- $where_vars
- );
- list ($count) = $smcFunc['db_fetch_row']($request);
- $smcFunc['db_free_result']($request);
- // @todo cast this to an integer
- return $count;
- }
- /**
- * @todo needs a description
- *
- * @param int $start
- * @param int $items_per_page
- * @param string $sort
- * @param string $where
- * @param array $where_vars
- * @return array error messages
- */
- function list_getUserErrors($start, $items_per_page, $sort, $where, $where_vars = array())
- {
- global $smcFunc, $txt, $scripturl;
- // Get a list of error messages from this ip (range).
- $request = $smcFunc['db_query']('', '
- SELECT
- le.log_time, le.ip, le.url, le.message, IFNULL(mem.id_member, 0) AS id_member,
- IFNULL(mem.real_name, {string:guest_title}) AS display_name, mem.member_name
- FROM {db_prefix}log_errors AS le
- LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = le.id_member)
- WHERE ' . $where . '
- ORDER BY ' . $sort . '
- LIMIT ' . $start . ', ' . $items_per_page,
- array_merge($where_vars, array(
- 'guest_title' => $txt['guest_title'],
- ))
- );
- $error_messages = array();
- while ($row = $smcFunc['db_fetch_assoc']($request))
- $error_messages[] = array(
- 'ip' => $row['ip'],
- 'member_link' => $row['id_member'] > 0 ? '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['display_name'] . '</a>' : $row['display_name'],
- 'message' => strtr($row['message'], array('<span class="remove">' => '', '</span>' => '')),
- 'url' => $row['url'],
- 'time' => timeformat($row['log_time']),
- 'timestamp' => forum_time(true, $row['log_time']),
- );
- $smcFunc['db_free_result']($request);
- return $error_messages;
- }
- /**
- * @todo needs a description
- *
- * @param string $where
- * @param array $where_vars
- * @return string count of messages matching the IP
- */
- function list_getIPMessageCount($where, $where_vars = array())
- {
- global $smcFunc;
- $request = $smcFunc['db_query']('', '
- SELECT COUNT(*) AS message_count
- FROM {db_prefix}messages AS m
- INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board)
- WHERE {query_see_board} AND ' . $where,
- $where_vars
- );
- list ($count) = $smcFunc['db_fetch_row']($request);
- $smcFunc['db_free_result']($request);
- // @todo cast to integer
- return $count;
- }
- /**
- * @todo needs a description
- *
- * @param int $start
- * @param int $items_per_page
- * @param string $sort
- * @param string $where
- * @param array $where_vars
- * @return array an array of messages
- */
- function list_getIPMessages($start, $items_per_page, $sort, $where, $where_vars = array())
- {
- global $smcFunc, $txt, $scripturl;
- // Get all the messages fitting this where clause.
- // @todo SLOW This query is using a filesort.
- $request = $smcFunc['db_query']('', '
- SELECT
- m.id_msg, m.poster_ip, IFNULL(mem.real_name, m.poster_name) AS display_name, mem.id_member,
- m.subject, m.poster_time, m.id_topic, m.id_board
- FROM {db_prefix}messages AS m
- INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board)
- LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member)
- WHERE {query_see_board} AND ' . $where . '
- ORDER BY ' . $sort . '
- LIMIT ' . $start . ', ' . $items_per_page,
- array_merge($where_vars, array(
- ))
- );
- $messages = array();
- while ($row = $smcFunc['db_fetch_assoc']($request))
- $messages[] = array(
- 'ip' => $row['poster_ip'],
- 'member_link' => empty($row['id_member']) ? $row['display_name'] : '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['display_name'] . '</a>',
- 'board' => array(
- 'id' => $row['id_board'],
- 'href' => $scripturl . '?board=' . $row['id_board']
- ),
- 'topic' => $row['id_topic'],
- 'id' => $row['id_msg'],
- 'subject' => $row['subject'],
- 'time' => timeformat($row['poster_time']),
- 'timestamp' => forum_time(true, $row['poster_time'])
- );
- $smcFunc['db_free_result']($request);
- return $messages;
- }
- /**
- * @todo needs a description
- *
- * @param int $memID = 0 id_member
- */
- function TrackIP($memID = 0)
- {
- global $user_profile, $scripturl, $txt, $user_info, $modSettings, $sourcedir;
- global $context, $smcFunc;
- // Can the user do this?
- isAllowedTo('moderate_forum');
- if ($memID == 0)
- {
- $context['ip'] = $user_info['ip'];
- loadTemplate('Profile');
- loadLanguage('Profile');
- $context['sub_template'] = 'trackIP';
- $context['page_title'] = $txt['profile'];
- $context['base_url'] = $scripturl . '?action=trackip';
- }
- else
- {
- $context['ip'] = $user_profile[$memID]['member_ip'];
- $context['base_url'] = $scripturl . '?action=profile;area=tracking;sa=ip;u=' . $memID;
- }
- // Searching?
- if (isset($_REQUEST['searchip']))
- $context['ip'] = trim($_REQUEST['searchip']);
- if (preg_match('/^\d{1,3}\.(\d{1,3}|\*)\.(\d{1,3}|\*)\.(\d{1,3}|\*)$/', $context['ip']) == 0 && isValidIPv6($context['ip']) === false)
- fatal_lang_error('invalid_tracking_ip', false);
- $ip_var = str_replace('*', '%', $context['ip']);
- $ip_string = strpos($ip_var, '%') === false ? '= {string:ip_address}' : 'LIKE {string:ip_address}';
- if (empty($context['tracking_area']))
- $context['page_title'] = $txt['trackIP'] . ' - ' . $context['ip'];
- $request = $smcFunc['db_query']('', '
- SELECT id_member, real_name AS display_name, member_ip
- FROM {db_prefix}members
- WHERE member_ip ' . $ip_string,
- array(
- 'ip_address' => $ip_var,
- )
- );
- $context['ips'] = array();
- while ($row = $smcFunc['db_fetch_assoc']($request))
- $context['ips'][$row['member_ip']][] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['display_name'] . '</a>';
- $smcFunc['db_free_result']($request);
- ksort($context['ips']);
- // Gonna want this for the list.
- require_once($sourcedir . '/Subs-List.php');
- // Start with the user messages.
- $listOptions = array(
- 'id' => 'track_message_list',
- 'title' => $txt['messages_from_ip'] . ' ' . $context['ip'],
- 'start_var_name' => 'messageStart',
- 'items_per_page' => $modSettings['defaultMaxMessages'],
- 'no_items_label' => $txt['no_messages_from_ip'],
- 'base_href' => $context['base_url'] . ';searchip=' . $context['ip'],
- 'default_sort_col' => 'date',
- 'get_items' => array(
- 'function' => 'list_getIPMessages',
- 'params' => array(
- 'm.poster_ip ' . $ip_string,
- array('ip_address' => $ip_var),
- ),
- ),
- 'get_count' => array(
- 'function' => 'list_getIPMessageCount',
- 'params' => array(
- 'm.poster_ip ' . $ip_string,
- array('ip_address' => $ip_var),
- ),
- ),
- 'columns' => array(
- 'ip_address' => array(
- 'header' => array(
- 'value' => $txt['ip_address'],
- ),
- 'data' => array(
- 'sprintf' => array(
- 'format' => '<a href="' . $context['base_url'] . ';searchip=%1$s">%1$s</a>',
- 'params' => array(
- 'ip' => false,
- ),
- ),
- ),
- 'sort' => array(
- 'default' => 'INET_ATON(m.poster_ip)',
- 'reverse' => 'INET_ATON(m.poster_ip) DESC',
- ),
- ),
- 'poster' => array(
- 'header' => array(
- 'value' => $txt['poster'],
- ),
- 'data' => array(
- 'db' => 'member_link',
- ),
- ),
- 'subject' => array(
- 'header' => array(
- 'value' => $txt['subject'],
- ),
- 'data' => array(
- 'sprintf' => array(
- 'format' => '<a href="' . $scripturl . '?topic=%1$s.msg%2$s#msg%2$s" rel="nofollow">%3$s</a>',
- 'params' => array(
- 'topic' => false,
- 'id' => false,
- 'subject' => false,
- ),
- ),
- ),
- ),
- 'date' => array(
- 'header' => array(
- 'value' => $txt['date'],
- ),
- 'data' => array(
- 'db' => 'time',
- ),
- 'sort' => array(
- 'default' => 'm.id_msg DESC',
- 'reverse' => 'm.id_msg',
- ),
- ),
- ),
- 'additional_rows' => array(
- array(
- 'position' => 'after_title',
- 'value' => $txt['messages_from_ip_desc'],
- 'class' => 'windowbg2',
- 'style' => 'padding: 1ex 2ex;',
- ),
- ),
- );
- // Create the messages list.
- createList($listOptions);
- // Set the options for the error lists.
- $listOptions = array(
- 'id' => 'track_user_list',
- 'title' => $txt['errors_from_ip'] . ' ' . $context['ip'],
- 'start_var_name' => 'errorStart',
- 'items_per_page' => $modSettings['defaultMaxMessages'],
- 'no_items_label' => $txt['no_errors_from_ip'],
- 'base_href' => $context['base_url'] . ';searchip=' . $context['ip'],
- 'default_sort_col' => 'date2',
- 'get_items' => array(
- 'function' => 'list_getUserErrors',
- 'params' => array(
- 'le.ip ' . $ip_string,
- array('ip_address' => $ip_var),
- ),
- ),
- 'get_count' => array(
- 'function' => 'list_getUserErrorCount',
- 'params' => array(
- 'ip ' . $ip_string,
- array('ip_address' => $ip_var),
- ),
- ),
- 'columns' => array(
- 'ip_address2' => array(
- 'header' => array(
- 'value' => $txt['ip_address'],
- ),
- 'data' => array(
- 'sprintf' => array(
- 'format' => '<a href="' . $context['base_url'] . ';searchip=%1$s">%1$s</a>',
- 'params' => array(
- 'ip' => false,
- ),
- ),
- ),
- 'sort' => array(
- 'default' => 'INET_ATON(le.ip)',
- 'reverse' => 'INET_ATON(le.ip) DESC',
- ),
- ),
- 'display_name' => array(
- 'header' => array(
- 'value' => $txt['display_name'],
- ),
- 'data' => array(
- 'db' => 'member_link',
- ),
- ),
- 'message' => array(
- 'header' => array(
- 'value' => $txt['message'],
- ),
- 'data' => array(
- 'sprintf' => array(
- 'format' => '%1$s<br /><a href="%2$s">%2$s</a>',
- 'params' => array(
- 'message' => false,
- 'url' => false,
- ),
- ),
- ),
- ),
- 'date2' => array(
- 'header' => array(
- 'value' => $txt['date'],
- ),
- 'data' => array(
- 'db' => 'time',
- ),
- 'sort' => array(
- 'default' => 'le.id_error DESC',
- 'reverse' => 'le.id_error',
- ),
- ),
- ),
- 'additional_rows' => array(
- array(
- 'position' => 'after_title',
- 'value' => $txt['errors_from_ip_desc'],
- 'class' => 'windowbg2',
- 'style' => 'padding: 1ex 2ex;',
- ),
- ),
- );
- // Create the error list.
- createList($listOptions);
- $context['single_ip'] = strpos($context['ip'], '*') === false;
- if ($context['single_ip'])
- {
- $context['whois_servers'] = array(
- 'afrinic' => array(
- 'name' => $txt['whois_afrinic'],
- 'url' => 'http://www.afrinic.net/cgi-bin/whois?searchtext=' . $context['ip'],
- 'range' => array(41, 154, 196),
- ),
- 'apnic' => array(
- 'name' => $txt['whois_apnic'],
- 'url' => 'http://wq.apnic.net/apnic-bin/whois.pl?searchtext=' . $context['ip'],
- 'range' => array(58, 59, 60, 61, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124,
- 125, 126, 133, 150, 153, 163, 171, 202, 203, 210, 211, 218, 219, 220, 221, 222),
- ),
- 'arin' => array(
- 'name' => $txt['whois_arin'],
- 'url' => 'http://whois.arin.net/rest/ip/' . $context['ip'],
- 'range' => array(7, 24, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 96, 97, 98, 99,
- 128, 129, 130, 131, 132, 134, 135, 136, 137, 138, 139, 140, 142, 143, 144, 146, 147, 148, 149,
- 152, 155, 156, 157, 158, 159, 160, 161, 162, 164, 165, 166, 167, 168, 169, 170, 172, 173, 174,
- 192, 198, 199, 204, 205, 206, 207, 208, 209, 216),
- ),
- 'lacnic' => array(
- 'name' => $txt['whois_lacnic'],
- 'url' => 'http://lacnic.net/cgi-bin/lacnic/whois?query=' . $context['ip'],
- 'range' => array(186, 187, 189, 190, 191, 200, 201),
- ),
- 'ripe' => array(
- 'name' => $txt['whois_ripe'],
- 'url' => 'https://apps.db.ripe.net/search/query.html?searchtext=' . $context['ip'],
- 'range' => array(62, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
- 141, 145, 151, 188, 193, 194, 195, 212, 213, 217),
- ),
- );
- foreach ($context['whois_servers'] as $whois)
- {
- // Strip off the "decimal point" and anything following...
- if (in_array((int) $context['ip'], $whois['range']))
- $context['auto_whois_server'] = $whois;
- }
- }
- }
- /**
- * Tracks a users logins.
- *
- * @param int $memID = 0 id_member
- */
- function TrackLogins($memID = 0)
- {
- global $user_profile, $scripturl, $txt, $user_info, $modSettings, $sourcedir;
- global $context, $smcFunc;
- // Gonna want this for the list.
- require_once($sourcedir . '/Subs-List.php');
- if ($memID == 0)
- $context['base_url'] = $scripturl . '?action=trackip';
- else
- $context['base_url'] = $scripturl . '?action=profile;area=tracking;sa=ip;u=' . $memID;
- // Start with the user messages.
- $listOptions = array(
- 'id' => 'track_logins_list',
- 'title' => $txt['trackLogins'],
- 'no_items_label' => $txt['trackLogins_none_found'],
- 'base_href' => $context['base_url'],
- 'get_items' => array(
- 'function' => 'list_getLogins',
- 'params' => array(
- 'id_member = {int:current_member}',
- array('current_member' => $memID),
- ),
- ),
- 'get_count' => array(
- 'function' => 'list_getLoginCount',
- 'params' => array(
- 'id_member = {int:current_member}',
- array('current_member' => $memID),
- ),
- ),
- 'columns' => array(
- 'time' => array(
- 'header' => array(
- 'value' => $txt['date'],
- ),
- 'data' => array(
- 'db' => 'time',
- ),
- ),
- 'ip' => array(
- 'header' => array(
- 'value' => $txt['ip_address'],
- ),
- 'data' => array(
- 'sprintf' => array(
- 'format' => '<a href="' . $context['base_url'] . ';searchip=%1$s">%1$s</a> (<a href="' . $context['base_url'] . ';searchip=%2$s">%2$s</a>) ',
- 'params' => array(
- 'ip' => false,
- 'ip2' => false
- ),
- ),
- ),
- ),
- ),
- 'additional_rows' => array(
- array(
- 'position' => 'after_title',
- 'value' => $txt['trackLogins_desc'],
- 'class' => 'windowbg2',
- 'style' => 'padding: 1ex 2ex;',
- ),
- ),
- );
- // Create the messages list.
- createList($listOptions);
- $context['sub_template'] = 'show_list';
- $context['default_list'] = 'track_logins_list';
- }
- /**
- * Callback for trackLogins for counting history.
- *
- * @param string $where
- * @param array $where_vars
- * @return string count of messages matching the IP
- */
- function list_getLoginCount($where, $where_vars = array())
- {
- global $smcFunc;
- $request = $smcFunc['db_query']('', '
- SELECT COUNT(*) AS message_count
- FROM {db_prefix}member_logins
- WHERE id_member = {int:id_member}',
- array(
- 'id_member' => $where_vars['current_member'],
- )
- );
- list ($count) = $smcFunc['db_fetch_row']($request);
- $smcFunc['db_free_result']($request);
- // @todo cast to integer
- return $count;
- }
- /**
- * Callback for trackLogins data.
- *
- * @param int $start
- * @param int $items_per_page
- * @param string $sort
- * @param string $where
- * @param array $where_vars
- * @return array an array of messages
- */
- function list_getLogins($start, $items_per_page, $sort, $where, $where_vars = array())
- {
- global $smcFunc, $txt, $scripturl;
- $request = $smcFunc['db_query']('', '
- SELECT time, ip, ip2
- FROM {db_prefix}member_logins
- WHERE {int:id_member}
- ORDER BY time DESC',
- array(
- 'id_member' => $where_vars['current_member'],
- )
- );
- $logins = array();
- while ($row = $smcFunc['db_fetch_assoc']($request))
- $logins[] = array(
- 'time' => timeformat($row['time']),
- 'ip' => $row['ip'],
- 'ip2' => $row['ip2'],
- );
- $smcFunc['db_free_result']($request);
- return $logins;
- }
- /**
- * @todo needs a description
- *
- * @param int $memID id_member
- */
- function trackEdits($memID)
- {
- global $scripturl, $txt, $modSettings, $sourcedir, $context, $smcFunc;
- require_once($sourcedir . '/Subs-List.php');
- // Get the names of any custom fields.
- $request = $smcFunc['db_query']('', '
- SELECT col_name, field_name, bbc
- FROM {db_prefix}custom_fields',
- array(
- )
- );
- $context['custom_field_titles'] = array();
- while ($row = $smcFunc['db_fetch_assoc']($request))
- $context['custom_field_titles']['customfield_' . $row['col_name']] = array(
- 'title' => $row['field_name'],
- 'parse_bbc' => $row['bbc'],
- );
- $smcFunc['db_free_result']($request);
- // Set the options for the error lists.
- $listOptions = array(
- 'id' => 'edit_list',
- 'title' => $txt['trackEdits'],
- 'items_per_page' => $modSettings['defaultMaxMessages'],
- 'no_items_label' => $txt['trackEdit_no_edits'],
- 'base_href' => $scripturl . '?action=profile;area=tracking;sa=edits;u=' . $memID,
- 'default_sort_col' => 'time',
- 'get_items' => array(
- 'function' => 'list_getProfileEdits',
- 'params' => array(
- $memID,
- ),
- ),
- 'get_count' => array(
- 'function' => 'list_getProfileEditCount',
- 'params' => array(
- $memID,
- ),
- ),
- 'columns' => array(
- 'action' => array(
- 'header' => array(
- 'value' => $txt['trackEdit_action'],
- ),
- 'data' => array(
- 'db' => 'action_text',
- ),
- ),
- 'before' => array(
- 'header' => array(
- 'value' => $txt['trackEdit_before'],
- ),
- 'data' => array(
- 'db' => 'before',
- ),
- ),
- 'after' => array(
- 'header' => array(
- 'value' => $txt['trackEdit_after'],
- ),
- 'data' => array(
- 'db' => 'after',
- ),
- ),
- 'time' => array(
- 'header' => array(
- 'value' => $txt['date'],
- ),
- 'data' => array(
- 'db' => 'time',
- ),
- 'sort' => array(
- 'default' => 'id_action DESC',
- 'reverse' => 'id_action',
- ),
- ),
- 'applicator' => array(
- 'header' => array(
- 'value' => $txt['trackEdit_applicator'],
- ),
- 'data' => array(
- 'db' => 'member_link',
- ),
- ),
- ),
- );
- // Create the error list.
- createList($listOptions);
- $context['sub_template'] = 'show_list';
- $context['default_list'] = 'edit_list';
- }
- /**
- * How many edits?
- *
- * @param int $memID id_member
- * @return string number of profile edits
- */
- function list_getProfileEditCount($memID)
- {
- global $smcFunc;
- $request = $smcFunc['db_query']('', '
- SELECT COUNT(*) AS edit_count
- FROM {db_prefix}log_actions
- WHERE id_log = {int:log_type}
- AND id_member = {int:owner}',
- array(
- 'log_type' => 2,
- 'owner' => $memID,
- )
- );
- list ($edit_count) = $smcFunc['db_fetch_row']($request);
- $smcFunc['db_free_result']($request);
- // @todo cast to integer
- return $edit_count;
- }
- /**
- * @todo needs a description
- *
- * @param int $start
- * @param int $items_per_page
- * @param string $sort
- * @param int $memID
- * @return array
- */
- function list_getProfileEdits($start, $items_per_page, $sort, $memID)
- {
- global $smcFunc, $txt, $scripturl, $context;
- // Get a list of error messages from this ip (range).
- $request = $smcFunc['db_query']('', '
- SELECT
- id_action, id_member, ip, log_time, action, extra
- FROM {db_prefix}log_actions
- WHERE id_log = {int:log_type}
- AND id_member = {int:owner}
- ORDER BY ' . $sort . '
- LIMIT ' . $start . ', ' . $items_per_page,
- array(
- 'log_type' => 2,
- 'owner' => $memID,
- )
- );
- $edits = array();
- $members = array();
- while ($row = $smcFunc['db_fetch_assoc']($request))
- {
- $extra = @unserialize($row['extra']);
- if (!empty($extra['applicator']))
- $members[] = $extra['applicator'];
- // Work out what the name of the action is.
- if (isset($txt['trackEdit_action_' . $row['action']]))
- $action_text = $txt['trackEdit_action_' . $row['action']];
- elseif (isset($txt[$row['action']]))
- $action_text = $txt[$row['action']];
- // Custom field?
- elseif (isset($context['custom_field_titles'][$row['action']]))
- $action_text = $context['custom_field_titles'][$row['action']]['title'];
- else
- $action_text = $row['action'];
- // Parse BBC?
- $parse_bbc = isset($context['custom_field_titles'][$row['action']]) && $context['custom_field_titles'][$row['action']]['parse_bbc'] ? true : false;
- $edits[] = array(
- 'id' => $row['id_action'],
- 'ip' => $row['ip'],
- 'id_member' => !empty($extra['applicator']) ? $extra['applicator'] : 0,
- 'member_link' => $txt['trackEdit_deleted_member'],
- 'action' => $row['action'],
- 'action_text' => $action_text,
- 'before' => !empty($extra['previous']) ? ($parse_bbc ? parse_bbc($extra['previous']) : $extra['previous']) : '',
- 'after' => !empty($extra['new']) ? ($parse_bbc ? parse_bbc($extra['new']) : $extra['new']) : '',
- 'time' => timeformat($row['log_time']),
- );
- }
- $smcFunc['db_free_result']($request);
- // Get any member names.
- if (!empty($members))
- {
- $request = $smcFunc['db_query']('', '
- SELECT
- id_member, real_name
- FROM {db_prefix}members
- WHERE id_member IN ({array_int:members})',
- array(
- 'members' => $members,
- )
- );
- $members = array();
- while ($row = $smcFunc['db_fetch_assoc']($request))
- $members[$row['id_member']] = $row['real_name'];
- $smcFunc['db_free_result']($request);
- foreach ($edits as $key => $value)
- if (isset($members[$value['id_member']]))
- $edits[$key]['member_link'] = '<a href="' . $scripturl . '?action=profile;u=' . $value['id_member'] . '">' . $members[$value['id_member']] . '</a>';
- }
- return $edits;
- }
- /**
- * @todo needs a description
- *
- * @param int $memID id_member
- */
- function showPermissions($memID)
- {
- global $scripturl, $txt, $board, $modSettings;
- global $user_profile, $context, $user_info, $sourcedir, $smcFunc;
- // Verify if the user has sufficient permissions.
- isAllowedTo('manage_permissions');
- loadLanguage('ManagePermissions');
- loadLanguage('Admin');
- loadTemplate('ManageMembers');
- // Load all the permission profiles.
- require_once($sourcedir . '/ManagePermissions.php');
- loadPermissionProfiles();
- $context['member']['id'] = $memID;
- $context['member']['name'] = $user_profile[$memID]['real_name'];
- $context['page_title'] = $txt['showPermissions'];
- $board = empty($board) ? 0 : (int) $board;
- $context['board'] = $board;
- // Determine which groups this user is in.
- if (empty($user_profile[$memID]['additional_groups']))
- $curGroups = array();
- else
- $curGroups = explode(',', $user_profile[$memID]['additional_groups']);
- $curGroups[] = $user_profile[$memID]['id_group'];
- $curGroups[] = $user_profile[$memID]['id_post_group'];
- // Load a list of boards for the jump box - except the defaults.
- $request = $smcFunc['db_query']('order_by_board_order', '
- SELECT b.id_board, b.name, b.id_profile, b.member_groups, IFNULL(mods.id_member, IFNULL(modgs.id_group, 0)) AS is_mod
- FROM {db_prefix}boards AS b
- LEFT JOIN {db_prefix}moderators AS mods ON (mods.id_board = b.id_board AND mods.id_member = {int:current_member})
- LEFT JOIN {db_prefix}moderator_groups AS modgs ON (modgs.id_board = b.id_board AND modgs.id_group IN ({array_int:current_groups}))
- WHERE {query_see_board}',
- array(
- 'current_member' => $memID,
- 'current_groups' => $curGroups,
- )
- );
- $context['boards'] = array();
- $context['no_access_boards'] = array();
- while ($row = $smcFunc['db_fetch_assoc']($request))
- {
- if (count(array_intersect($curGroups, explode(',', $row['member_groups']))) === 0 && !$row['is_mod'])
- $context['no_access_boards'][] = array(
- 'id' => $row['id_board'],
- 'name' => $row['name'],
- 'is_last' => false,
- );
- elseif ($row['id_profile'] != 1 || $row['is_mod'])
- $context['boards'][$row['id_board']] = array(
- 'id' => $row['id_board'],
- 'name' => $row['name'],
- 'selected' => $board == $row['id_board'],
- 'profile' => $row['id_profile'],
- 'profile_name' => $context['profiles'][$row['id_profile']]['name'],
- );
- }
- $smcFunc['db_free_result']($request);
- if (!empty($context['no_access_boards']))
- $context['no_access_boards'][count($context['no_access_boards']) - 1]['is_last'] = true;
- $context['member']['permissions'] = array(
- 'general' => array(),
- 'board' => array()
- );
- // If you're an admin we know you can do everything, we might as well leave.
- $context['member']['has_all_permissions'] = in_array(1, $curGroups);
- if ($context['member']['has_all_permissions'])
- return;
- $denied = array();
- // Get all general permissions.
- $result = $smcFunc['db_query']('', '
- SELECT p.permission, p.add_deny, mg.group_name, p.id_group
- FROM {db_prefix}permissions AS p
- LEFT JOIN {db_prefix}membergroups AS mg ON (mg.id_group = p.id_group)
- WHERE p.id_group IN ({array_int:group_list})
- ORDER BY p.add_deny DESC, p.permission, mg.min_posts, CASE WHEN mg.id_group < {int:newbie_group} THEN mg.id_group ELSE 4 END, mg.group_name',
- array(
- 'group_list' => $curGroups,
- 'newbie_group' => 4,
- )
- );
- while ($row = $smcFunc['db_fetch_assoc']($result))
- {
- // We don't know about this permission, it doesn't exist :P.
- if (!isset($txt['permissionname_' . $row['permission']]))
- continue;
- if (empty($row['add_deny']))
- $denied[] = $row['permission'];
- // Permissions that end with _own or _any consist of two parts.
- if (in_array(substr($row['permission'], -4), array('_own', '_any')) && isset($txt['permissionname_' . substr($row['permission'], 0, -4)]))
- $name = $txt['permissionname_' . substr($row['permission'], 0, -4)] . ' - ' . $txt['permissionname_' . $row['permission']];
- else
- $name = $txt['permissionname_' . $row['permission']];
- // Add this permission if it doesn't exist yet.
- if (!isset($context['member']['permissions']['general'][$row['permission']]))
- $context['member']['permissions']['general'][$row['permission']] = array(
- 'id' => $row['permission'],
- 'groups' => array(
- 'allowed' => array(),
- 'denied' => array()
- ),
- 'name' => $name,
- 'is_denied' => false,
- 'is_global' => true,
- );
- // Add the membergroup to either the denied or the allowed groups.
- $context['member']['permissions']['general'][$row['permission']]['groups'][empty($row['add_deny']) ? 'denied' : 'allowed'][] = $row['id_group'] == 0 ? $txt['membergroups_members'] : $row['group_name'];
- // Once denied is always denied.
- $context['member']['permissions']['general'][$row['permission']]['is_denied'] |= empty($row['add_deny']);
- }
- $smcFunc['db_free_result']($result);
- $request = $smcFunc['db_query']('', '
- SELECT
- bp.add_deny, bp.permission, bp.id_group, mg.group_name' . (empty($board) ? '' : ',
- b.id_profile, CASE WHEN (mods.id_member IS NULL AND modgs.id_group IS NULL) THEN 0 ELSE 1 END AS is_moderator') . '
- FROM {db_prefix}board_permissions AS bp' . (empty($board) ? '' : '
- INNER JOIN {db_prefix}boards AS b ON (b.id_board = {int:current_board})
- LEFT JOIN {db_prefix}moderators AS mods ON (mods.id_board = b.id_board AND mods.id_member = {int:current_member})
- LEFT JOIN {db_prefix}moderator_groups AS modgs ON (modgs.id_board = b.id_board AND modgs.id_group IN ({array_int:group_list}))') . '
- LEFT JOIN {db_prefix}membergroups AS mg ON (mg.id_group = bp.id_group)
- WHERE bp.id_profile = {raw:current_profile}
- AND bp.id_group IN ({array_int:group_list}' . (empty($board) ? ')' : ', {int:moderator_group})
- AND (mods.id_member IS NOT NULL OR modgs.id_group IS NOT NULL OR bp.id_group != {int:moderator_group})'),
- array(
- 'current_board' => $board,
- 'group_list' => $curGroups,
- 'current_member' => $memID,
- 'current_profile' => empty($board) ? '1' : 'b.id_profile',
- 'moderator_group' => 3,
- )
- );
- while ($row = $smcFunc['db_fetch_assoc']($request))
- {
- // We don't know about this permission, it doesn't exist :P.
- if (!isset($txt['permissionname_' . $row['permission']]))
- continue;
- // The name of the permission using the format 'permission name' - 'own/any topic/event/etc.'.
- if (in_array(substr($row['permission'], -4), array('_own', '_any')) && isset($txt['permissionname_' . substr($row['permission'], 0, -4)]))
- $name = $txt['permissionname_' . substr($row['permission'], 0, -4)] . ' - ' . $txt['permissionname_' . $row['permission']];
- else
- $name = $txt['permissionname_' . $row['permission']];
- // Create the structure for this permission.
- if (!isset($context['member']['permissions']['board'][$row['permission']]))
- $context['member']['permissions']['board'][$row['permission']] = array(
- 'id' => $row['permission'],
- 'groups' => array(
- 'allowed' => array(),
- 'denied' => array()
- ),
- 'name' => $name,
- 'is_denied' => false,
- 'is_global' => empty($board),
- );
- $context['member']['permissions']['board'][$row['permission']]['groups'][empty($row['add_deny']) ? 'denied' : 'allowed'][$row['id_group']] = $row['id_group'] == 0 ? $txt['membergroups_members'] : $row['group_name'];
- $context['member']['permissions']['board'][$row['permission']]['is_denied'] |= empty($row['add_deny']);
- }
- $smcFunc['db_free_result']($request);
- }
- /**
- * View a members warnings?
- *
- * @param int $memID id_member
- */
- function viewWarning($memID)
- {
- global $modSettings, $context, $sourcedir, $txt, $scripturl;
- // Firstly, can we actually even be here?
- if (!allowedTo('issue_warning') && (empty($modSettings['warning_show']) || ($modSettings['warning_show'] == 1 && !$context['user']['is_owner'])))
- fatal_lang_error('no_access', false);
- // Make sure things which are disabled stay disabled.
- $modSettings['warning_watch'] = !empty($modSettings['warning_watch']) ? $modSettings['warning_watch'] : 110;
- $modSettings['warning_moderate'] = !empty($modSettings['warning_moderate']) && !empty($modSettings['postmod_active']) ? $modSettings['warning_moderate'] : 110;
- $modSettings['warning_mute'] = !empty($modSettings['warning_mute']) ? $modSettings['warning_mute'] : 110;
- // Let's use a generic list to get all the current warnings, and use the issue warnings grab-a-granny thing.
- require_once($sourcedir . '/Subs-List.php');
- require_once($sourcedir . '/Profile-Actions.php');
- $listOptions = array(
- 'id' => 'view_warnings',
- 'title' => $txt['profile_viewwarning_previous_warnings'],
- 'items_per_page' => $modSettings['defaultMaxMessages'],
- 'no_items_label' => $txt['profile_viewwarning_no_warnings'],
- 'base_href' => $scripturl . '?action=profile;area=viewwarning;sa=user;u=' . $memID,
- 'default_sort_col' => 'log_time',
- 'get_items' => array(
- 'function' => 'list_getUserWarnings',
- 'params' => array(
- $memID,
- ),
- ),
- 'get_count' => array(
- 'function' => 'list_getUserWarningCount',
- 'params' => array(
- $memID,
- ),
- ),
- 'columns' => array(
- 'log_time' => array(
- 'header' => array(
- 'value' => $txt['profile_warning_previous_time'],
- ),
- 'data' => array(
- 'db' => 'time',
- ),
- 'sort' => array(
- 'default' => 'lc.log_time DESC',
- 'reverse' => 'lc.log_time',
- ),
- ),
- 'reason' => array(
- 'header' => array(
- 'value' => $txt['profile_warning_previous_reason'],
- 'style' => 'width: 50%;',
- ),
- 'data' => array(
- 'db' => 'reason',
- ),
- ),
- 'level' => array(
- 'header' => array(
- 'value' => $txt['profile_warning_previous_level'],
- ),
- 'data' => array(
- 'db' => 'counter',
- ),
- 'sort' => array(
- 'default' => 'lc.counter DESC',
- 'reverse' => 'lc.counter',
- ),
- ),
- ),
- 'additional_rows' => array(
- array(
- 'position' => 'after_title',
- 'value' => $txt['profile_viewwarning_desc'],
- 'class' => 'smalltext',
- 'style' => 'padding: 2ex;',
- ),
- ),
- );
- // Create the list for viewing.
- require_once($sourcedir . '/Subs-List.php');
- createList($listOptions);
- // Create some common text bits for the template.
- $context['level_effects'] = array(
- 0 => '',
- $modSettings['warning_watch'] => $txt['profile_warning_effect_own_watched'],
- $modSettings['warning_moderate'] => $txt['profile_warning_effect_own_moderated'],
- $modSettings['warning_mute'] => $txt['profile_warning_effect_own_muted'],
- );
- $context['current_level'] = 0;
- foreach ($context['level_effects'] as $limit => $dummy)
- if ($context['member']['warning'] >= $limit)
- $context['current_level'] = $limit;
- }
- ?>
|