Profile-View.php 70 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226
  1. <?php
  2. /**
  3. * Simple Machines Forum (SMF)
  4. *
  5. * @package SMF
  6. * @author Simple Machines http://www.simplemachines.org
  7. * @copyright 2012 Simple Machines
  8. * @license http://www.simplemachines.org/about/smf/license.php BSD
  9. *
  10. * @version 2.1 Alpha 1
  11. */
  12. if (!defined('SMF'))
  13. die('Hacking attempt...');
  14. /**
  15. * View a summary.
  16. * @param int $memID id_member
  17. */
  18. function summary($memID)
  19. {
  20. global $context, $memberContext, $txt, $modSettings, $user_info, $user_profile, $sourcedir, $scripturl, $smcFunc;
  21. // Attempt to load the member's profile data.
  22. if (!loadMemberContext($memID) || !isset($memberContext[$memID]))
  23. fatal_lang_error('not_a_user', false);
  24. // Set up the stuff and load the user.
  25. $context += array(
  26. 'page_title' => sprintf($txt['profile_of_username'], $memberContext[$memID]['name']),
  27. 'can_send_pm' => allowedTo('pm_send'),
  28. 'can_send_email' => allowedTo('send_email_to_members'),
  29. 'can_have_buddy' => allowedTo('profile_identity_own') && !empty($modSettings['enable_buddylist']),
  30. 'can_issue_warning' => in_array('w', $context['admin_features']) && allowedTo('issue_warning') && $modSettings['warning_settings'][0] == 1,
  31. );
  32. $context['member'] = &$memberContext[$memID];
  33. $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']));
  34. // Set a canonical URL for this page.
  35. $context['canonical_url'] = $scripturl . '?action=profile;u=' . $memID;
  36. // Are there things we don't show?
  37. $context['disabled_fields'] = isset($modSettings['disabled_profile_fields']) ? array_flip(explode(',', $modSettings['disabled_profile_fields'])) : array();
  38. // See if they have broken any warning levels...
  39. list ($modSettings['warning_enable'], $modSettings['user_limit']) = explode(',', $modSettings['warning_settings']);
  40. if (!empty($modSettings['warning_mute']) && $modSettings['warning_mute'] <= $context['member']['warning'])
  41. $context['warning_status'] = $txt['profile_warning_is_muted'];
  42. elseif (!empty($modSettings['warning_moderate']) && $modSettings['warning_moderate'] <= $context['member']['warning'])
  43. $context['warning_status'] = $txt['profile_warning_is_moderation'];
  44. elseif (!empty($modSettings['warning_watch']) && $modSettings['warning_watch'] <= $context['member']['warning'])
  45. $context['warning_status'] = $txt['profile_warning_is_watch'];
  46. // They haven't even been registered for a full day!?
  47. $days_registered = (int) ((time() - $user_profile[$memID]['date_registered']) / (3600 * 24));
  48. if (empty($user_profile[$memID]['date_registered']) || $days_registered < 1)
  49. $context['member']['posts_per_day'] = $txt['not_applicable'];
  50. else
  51. $context['member']['posts_per_day'] = comma_format($context['member']['real_posts'] / $days_registered, 3);
  52. // Set the age...
  53. if (empty($context['member']['birth_date']))
  54. {
  55. $context['member'] += array(
  56. 'age' => $txt['not_applicable'],
  57. 'today_is_birthday' => false
  58. );
  59. }
  60. else
  61. {
  62. list ($birth_year, $birth_month, $birth_day) = sscanf($context['member']['birth_date'], '%d-%d-%d');
  63. $datearray = getdate(forum_time());
  64. $context['member'] += array(
  65. '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),
  66. 'today_is_birthday' => $datearray['mon'] == $birth_month && $datearray['mday'] == $birth_day
  67. );
  68. }
  69. if (allowedTo('moderate_forum'))
  70. {
  71. // Make sure it's a valid ip address; otherwise, don't bother...
  72. if (preg_match('/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/', $memberContext[$memID]['ip']) == 1 && empty($modSettings['disableHostnameLookup']))
  73. $context['member']['hostname'] = host_from_ip($memberContext[$memID]['ip']);
  74. else
  75. $context['member']['hostname'] = '';
  76. $context['can_see_ip'] = true;
  77. }
  78. else
  79. $context['can_see_ip'] = false;
  80. if (!empty($modSettings['who_enabled']))
  81. {
  82. include_once($sourcedir . '/Who.php');
  83. $action = determineActions($user_profile[$memID]['url']);
  84. if ($action !== false)
  85. $context['member']['action'] = $action;
  86. }
  87. // If the user is awaiting activation, and the viewer has permission - setup some activation context messages.
  88. if ($context['member']['is_activated'] % 10 != 1 && allowedTo('moderate_forum'))
  89. {
  90. $context['activate_type'] = $context['member']['is_activated'];
  91. // What should the link text be?
  92. $context['activate_link_text'] = in_array($context['member']['is_activated'], array(3, 4, 5, 13, 14, 15)) ? $txt['account_approve'] : $txt['account_activate'];
  93. // Should we show a custom message?
  94. $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'];
  95. }
  96. // Is the signature even enabled on this forum?
  97. $context['signature_enabled'] = substr($modSettings['signature_settings'], 0, 1) == 1;
  98. // How about, are they banned?
  99. $context['member']['bans'] = array();
  100. if (allowedTo('moderate_forum'))
  101. {
  102. // Can they edit the ban?
  103. $context['can_edit_ban'] = allowedTo('manage_bans');
  104. $ban_query = array();
  105. $ban_query_vars = array(
  106. 'time' => time(),
  107. );
  108. $ban_query[] = 'id_member = ' . $context['member']['id'];
  109. $ban_query[] = constructBanQueryIP($memberContext[$memID]['ip']);
  110. // Do we have a hostname already?
  111. if (!empty($context['member']['hostname']))
  112. {
  113. $ban_query[] = '({string:hostname} LIKE hostname)';
  114. $ban_query_vars['hostname'] = $context['member']['hostname'];
  115. }
  116. // Check their email as well...
  117. if (strlen($context['member']['email']) != 0)
  118. {
  119. $ban_query[] = '({string:email} LIKE bi.email_address)';
  120. $ban_query_vars['email'] = $context['member']['email'];
  121. }
  122. // So... are they banned? Dying to know!
  123. $request = $smcFunc['db_query']('', '
  124. SELECT bg.id_ban_group, bg.name, bg.cannot_access, bg.cannot_post, bg.cannot_register,
  125. bg.cannot_login, bg.reason
  126. FROM {db_prefix}ban_items AS bi
  127. 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}))
  128. WHERE (' . implode(' OR ', $ban_query) . ')',
  129. $ban_query_vars
  130. );
  131. while ($row = $smcFunc['db_fetch_assoc']($request))
  132. {
  133. // Work out what restrictions we actually have.
  134. $ban_restrictions = array();
  135. foreach (array('access', 'register', 'login', 'post') as $type)
  136. if ($row['cannot_' . $type])
  137. $ban_restrictions[] = $txt['ban_type_' . $type];
  138. // No actual ban in place?
  139. if (empty($ban_restrictions))
  140. continue;
  141. // Prepare the link for context.
  142. $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>');
  143. $context['member']['bans'][$row['id_ban_group']] = array(
  144. 'reason' => empty($row['reason']) ? '' : '<br /><br /><strong>' . $txt['ban_reason'] . ':</strong> ' . $row['reason'],
  145. 'cannot' => array(
  146. 'access' => !empty($row['cannot_access']),
  147. 'register' => !empty($row['cannot_register']),
  148. 'post' => !empty($row['cannot_post']),
  149. 'login' => !empty($row['cannot_login']),
  150. ),
  151. 'explanation' => $ban_explanation,
  152. );
  153. }
  154. $smcFunc['db_free_result']($request);
  155. }
  156. loadCustomFields($memID);
  157. }
  158. /**
  159. * Show all posts by the current user
  160. * @todo This function needs to be split up properly.
  161. *
  162. * @param int $memID id_member
  163. */
  164. function showPosts($memID)
  165. {
  166. global $txt, $user_info, $scripturl, $modSettings;
  167. global $context, $user_profile, $sourcedir, $smcFunc, $board;
  168. // Some initial context.
  169. $context['start'] = (int) $_REQUEST['start'];
  170. $context['current_member'] = $memID;
  171. // Create the tabs for the template.
  172. $context[$context['profile_menu_name']]['tab_data'] = array(
  173. 'title' => $txt['showPosts'],
  174. 'description' => $txt['showPosts_help'],
  175. 'icon' => 'profile_sm.png',
  176. 'tabs' => array(
  177. 'messages' => array(
  178. ),
  179. 'topics' => array(
  180. ),
  181. 'attach' => array(
  182. ),
  183. ),
  184. );
  185. // Set the page title
  186. $context['page_title'] = $txt['showPosts'] . ' - ' . $user_profile[$memID]['real_name'];
  187. // Is the load average too high to allow searching just now?
  188. if (!empty($context['load_average']) && !empty($modSettings['loadavg_show_posts']) && $context['load_average'] >= $modSettings['loadavg_show_posts'])
  189. fatal_lang_error('loadavg_show_posts_disabled', false);
  190. // If we're specifically dealing with attachments use that function!
  191. if (isset($_GET['sa']) && $_GET['sa'] == 'attach')
  192. return showAttachments($memID);
  193. // Are we just viewing topics?
  194. $context['is_topics'] = isset($_GET['sa']) && $_GET['sa'] == 'topics' ? true : false;
  195. // If just deleting a message, do it and then redirect back.
  196. if (isset($_GET['delete']) && !$context['is_topics'])
  197. {
  198. checkSession('get');
  199. // We need msg info for logging.
  200. $request = $smcFunc['db_query']('', '
  201. SELECT subject, id_member, id_topic, id_board
  202. FROM {db_prefix}messages
  203. WHERE id_msg = {int:id_msg}',
  204. array(
  205. 'id_msg' => (int) $_GET['delete'],
  206. )
  207. );
  208. $info = $smcFunc['db_fetch_row']($request);
  209. $smcFunc['db_free_result']($request);
  210. // Trying to remove a message that doesn't exist.
  211. if (empty($info))
  212. redirectexit('action=profile;u=' . $memID . ';area=showposts;start=' . $_GET['start']);
  213. // We can be lazy, since removeMessage() will check the permissions for us.
  214. require_once($sourcedir . '/RemoveTopic.php');
  215. removeMessage((int) $_GET['delete']);
  216. // Add it to the mod log.
  217. if (allowedTo('delete_any') && (!allowedTo('delete_own') || $info[1] != $user_info['id']))
  218. logAction('delete', array('topic' => $info[2], 'subject' => $info[0], 'member' => $info[1], 'board' => $info[3]));
  219. // Back to... where we are now ;).
  220. redirectexit('action=profile;u=' . $memID . ';area=showposts;start=' . $_GET['start']);
  221. }
  222. // Default to 10.
  223. if (empty($_REQUEST['viewscount']) || !is_numeric($_REQUEST['viewscount']))
  224. $_REQUEST['viewscount'] = '10';
  225. if ($context['is_topics'])
  226. $request = $smcFunc['db_query']('', '
  227. SELECT COUNT(*)
  228. FROM {db_prefix}topics AS t' . ($user_info['query_see_board'] == '1=1' ? '' : '
  229. INNER JOIN {db_prefix}boards AS b ON (b.id_board = t.id_board AND {query_see_board})') . '
  230. WHERE t.id_member_started = {int:current_member}' . (!empty($board) ? '
  231. AND t.id_board = {int:board}' : '') . (!$modSettings['postmod_active'] || $context['user']['is_owner'] ? '' : '
  232. AND t.approved = {int:is_approved}'),
  233. array(
  234. 'current_member' => $memID,
  235. 'is_approved' => 1,
  236. 'board' => $board,
  237. )
  238. );
  239. else
  240. $request = $smcFunc['db_query']('', '
  241. SELECT COUNT(*)
  242. FROM {db_prefix}messages AS m' . ($user_info['query_see_board'] == '1=1' ? '' : '
  243. INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board AND {query_see_board})') . '
  244. WHERE m.id_member = {int:current_member}' . (!empty($board) ? '
  245. AND m.id_board = {int:board}' : '') . (!$modSettings['postmod_active'] || $context['user']['is_owner'] ? '' : '
  246. AND m.approved = {int:is_approved}'),
  247. array(
  248. 'current_member' => $memID,
  249. 'is_approved' => 1,
  250. 'board' => $board,
  251. )
  252. );
  253. list ($msgCount) = $smcFunc['db_fetch_row']($request);
  254. $smcFunc['db_free_result']($request);
  255. $request = $smcFunc['db_query']('', '
  256. SELECT MIN(id_msg), MAX(id_msg)
  257. FROM {db_prefix}messages AS m
  258. WHERE m.id_member = {int:current_member}' . (!empty($board) ? '
  259. AND m.id_board = {int:board}' : '') . (!$modSettings['postmod_active'] || $context['user']['is_owner'] ? '' : '
  260. AND m.approved = {int:is_approved}'),
  261. array(
  262. 'current_member' => $memID,
  263. 'is_approved' => 1,
  264. 'board' => $board,
  265. )
  266. );
  267. list ($min_msg_member, $max_msg_member) = $smcFunc['db_fetch_row']($request);
  268. $smcFunc['db_free_result']($request);
  269. $reverse = false;
  270. $range_limit = '';
  271. $maxIndex = (int) $modSettings['defaultMaxMessages'];
  272. // Make sure the starting place makes sense and construct our friend the page index.
  273. $context['page_index'] = constructPageIndex($scripturl . '?action=profile;u=' . $memID . ';area=showposts' . ($context['is_topics'] ? ';sa=topics' : '') . (!empty($board) ? ';board=' . $board : ''), $context['start'], $msgCount, $maxIndex);
  274. $context['current_page'] = $context['start'] / $maxIndex;
  275. // Reverse the query if we're past 50% of the pages for better performance.
  276. $start = $context['start'];
  277. $reverse = $_REQUEST['start'] > $msgCount / 2;
  278. if ($reverse)
  279. {
  280. $maxIndex = $msgCount < $context['start'] + $modSettings['defaultMaxMessages'] + 1 && $msgCount > $context['start'] ? $msgCount - $context['start'] : (int) $modSettings['defaultMaxMessages'];
  281. $start = $msgCount < $context['start'] + $modSettings['defaultMaxMessages'] + 1 || $msgCount < $context['start'] + $modSettings['defaultMaxMessages'] ? 0 : $msgCount - $context['start'] - $modSettings['defaultMaxMessages'];
  282. }
  283. // Guess the range of messages to be shown.
  284. if ($msgCount > 1000)
  285. {
  286. $margin = floor(($max_msg_member - $min_msg_member) * (($start + $modSettings['defaultMaxMessages']) / $msgCount) + .1 * ($max_msg_member - $min_msg_member));
  287. // Make a bigger margin for topics only.
  288. if ($context['is_topics'])
  289. {
  290. $margin *= 5;
  291. $range_limit = $reverse ? 't.id_first_msg < ' . ($min_msg_member + $margin) : 't.id_first_msg > ' . ($max_msg_member - $margin);
  292. }
  293. else
  294. $range_limit = $reverse ? 'm.id_msg < ' . ($min_msg_member + $margin) : 'm.id_msg > ' . ($max_msg_member - $margin);
  295. }
  296. // Find this user's posts. The left join on categories somehow makes this faster, weird as it looks.
  297. $looped = false;
  298. while (true)
  299. {
  300. if ($context['is_topics'])
  301. {
  302. $request = $smcFunc['db_query']('', '
  303. SELECT
  304. 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,
  305. t.approved, m.body, m.smileys_enabled, m.subject, m.poster_time, m.id_topic, m.id_msg
  306. FROM {db_prefix}topics AS t
  307. INNER JOIN {db_prefix}boards AS b ON (b.id_board = t.id_board)
  308. LEFT JOIN {db_prefix}categories AS c ON (c.id_cat = b.id_cat)
  309. INNER JOIN {db_prefix}messages AS m ON (m.id_msg = t.id_first_msg)
  310. WHERE t.id_member_started = {int:current_member}' . (!empty($board) ? '
  311. AND t.id_board = {int:board}' : '') . (empty($range_limit) ? '' : '
  312. AND ' . $range_limit) . '
  313. AND {query_see_board}' . (!$modSettings['postmod_active'] || $context['user']['is_owner'] ? '' : '
  314. AND t.approved = {int:is_approved} AND m.approved = {int:is_approved}') . '
  315. ORDER BY t.id_first_msg ' . ($reverse ? 'ASC' : 'DESC') . '
  316. LIMIT ' . $start . ', ' . $maxIndex,
  317. array(
  318. 'current_member' => $memID,
  319. 'is_approved' => 1,
  320. 'board' => $board,
  321. )
  322. );
  323. }
  324. else
  325. {
  326. $request = $smcFunc['db_query']('', '
  327. SELECT
  328. b.id_board, b.name AS bname, c.id_cat, c.name AS cname, m.id_topic, m.id_msg,
  329. t.id_member_started, t.id_first_msg, t.id_last_msg, m.body, m.smileys_enabled,
  330. m.subject, m.poster_time, m.approved
  331. FROM {db_prefix}messages AS m
  332. INNER JOIN {db_prefix}topics AS t ON (t.id_topic = m.id_topic)
  333. INNER JOIN {db_prefix}boards AS b ON (b.id_board = t.id_board)
  334. LEFT JOIN {db_prefix}categories AS c ON (c.id_cat = b.id_cat)
  335. WHERE m.id_member = {int:current_member}' . (!empty($board) ? '
  336. AND b.id_board = {int:board}' : '') . (empty($range_limit) ? '' : '
  337. AND ' . $range_limit) . '
  338. AND {query_see_board}' . (!$modSettings['postmod_active'] || $context['user']['is_owner'] ? '' : '
  339. AND t.approved = {int:is_approved} AND m.approved = {int:is_approved}') . '
  340. ORDER BY m.id_msg ' . ($reverse ? 'ASC' : 'DESC') . '
  341. LIMIT ' . $start . ', ' . $maxIndex,
  342. array(
  343. 'current_member' => $memID,
  344. 'is_approved' => 1,
  345. 'board' => $board,
  346. )
  347. );
  348. }
  349. // Make sure we quit this loop.
  350. if ($smcFunc['db_num_rows']($request) === $maxIndex || $looped)
  351. break;
  352. $looped = true;
  353. $range_limit = '';
  354. }
  355. // Start counting at the number of the first message displayed.
  356. $counter = $reverse ? $context['start'] + $maxIndex + 1 : $context['start'];
  357. $context['posts'] = array();
  358. $board_ids = array('own' => array(), 'any' => array());
  359. while ($row = $smcFunc['db_fetch_assoc']($request))
  360. {
  361. // Censor....
  362. censorText($row['body']);
  363. censorText($row['subject']);
  364. // Do the code.
  365. $row['body'] = parse_bbc($row['body'], $row['smileys_enabled'], $row['id_msg']);
  366. // And the array...
  367. $context['posts'][$counter += $reverse ? -1 : 1] = array(
  368. 'body' => $row['body'],
  369. 'counter' => $counter,
  370. 'alternate' => $counter % 2,
  371. 'category' => array(
  372. 'name' => $row['cname'],
  373. 'id' => $row['id_cat']
  374. ),
  375. 'board' => array(
  376. 'name' => $row['bname'],
  377. 'id' => $row['id_board']
  378. ),
  379. 'topic' => $row['id_topic'],
  380. 'subject' => $row['subject'],
  381. 'start' => 'msg' . $row['id_msg'],
  382. 'time' => timeformat($row['poster_time']),
  383. 'timestamp' => forum_time(true, $row['poster_time']),
  384. 'id' => $row['id_msg'],
  385. 'can_reply' => false,
  386. 'can_mark_notify' => false,
  387. 'can_delete' => false,
  388. '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()),
  389. 'approved' => $row['approved'],
  390. );
  391. if ($user_info['id'] == $row['id_member_started'])
  392. $board_ids['own'][$row['id_board']][] = $counter;
  393. $board_ids['any'][$row['id_board']][] = $counter;
  394. }
  395. $smcFunc['db_free_result']($request);
  396. // All posts were retrieved in reverse order, get them right again.
  397. if ($reverse)
  398. $context['posts'] = array_reverse($context['posts'], true);
  399. // These are all the permissions that are different from board to board..
  400. if ($context['is_topics'])
  401. $permissions = array(
  402. 'own' => array(
  403. 'post_reply_own' => 'can_reply',
  404. ),
  405. 'any' => array(
  406. 'post_reply_any' => 'can_reply',
  407. 'mark_any_notify' => 'can_mark_notify',
  408. )
  409. );
  410. else
  411. $permissions = array(
  412. 'own' => array(
  413. 'post_reply_own' => 'can_reply',
  414. 'delete_own' => 'can_delete',
  415. ),
  416. 'any' => array(
  417. 'post_reply_any' => 'can_reply',
  418. 'mark_any_notify' => 'can_mark_notify',
  419. 'delete_any' => 'can_delete',
  420. )
  421. );
  422. // For every permission in the own/any lists...
  423. foreach ($permissions as $type => $list)
  424. {
  425. foreach ($list as $permission => $allowed)
  426. {
  427. // Get the boards they can do this on...
  428. $boards = boardsAllowedTo($permission);
  429. // Hmm, they can do it on all boards, can they?
  430. if (!empty($boards) && $boards[0] == 0)
  431. $boards = array_keys($board_ids[$type]);
  432. // Now go through each board they can do the permission on.
  433. foreach ($boards as $board_id)
  434. {
  435. // There aren't any posts displayed from this board.
  436. if (!isset($board_ids[$type][$board_id]))
  437. continue;
  438. // Set the permission to true ;).
  439. foreach ($board_ids[$type][$board_id] as $counter)
  440. $context['posts'][$counter][$allowed] = true;
  441. }
  442. }
  443. }
  444. // Clean up after posts that cannot be deleted and quoted.
  445. $quote_enabled = empty($modSettings['disabledBBC']) || !in_array('quote', explode(',', $modSettings['disabledBBC']));
  446. foreach ($context['posts'] as $counter => $dummy)
  447. {
  448. $context['posts'][$counter]['can_delete'] &= $context['posts'][$counter]['delete_possible'];
  449. $context['posts'][$counter]['can_quote'] = $context['posts'][$counter]['can_reply'] && $quote_enabled;
  450. }
  451. }
  452. /**
  453. * Show all the attachments of a user.
  454. *
  455. * @param int $memID id_member
  456. */
  457. function showAttachments($memID)
  458. {
  459. global $txt, $user_info, $scripturl, $modSettings, $board;
  460. global $context, $user_profile, $sourcedir, $smcFunc;
  461. // OBEY permissions!
  462. $boardsAllowed = boardsAllowedTo('view_attachments');
  463. // Make sure we can't actually see anything...
  464. if (empty($boardsAllowed))
  465. $boardsAllowed = array(-1);
  466. require_once($sourcedir . '/Subs-List.php');
  467. // This is all the information required for a group listing.
  468. $listOptions = array(
  469. 'id' => 'attachments',
  470. 'width' => '100%',
  471. 'items_per_page' => $modSettings['defaultMaxMessages'],
  472. 'no_items_label' => $txt['show_attachments_none'],
  473. 'base_href' => $scripturl . '?action=profile;area=showposts;sa=attach;sort=filename;u=' . $memID,
  474. 'default_sort_col' => 'filename',
  475. 'get_items' => array(
  476. 'function' => 'list_getAttachments',
  477. 'params' => array(
  478. $boardsAllowed,
  479. $memID,
  480. ),
  481. ),
  482. 'get_count' => array(
  483. 'function' => 'list_getNumAttachments',
  484. 'params' => array(
  485. $boardsAllowed,
  486. $memID,
  487. ),
  488. ),
  489. 'data_check' => array(
  490. 'class' => create_function('$data', '
  491. return $data[\'approved\'] ? \'\' : \'approvebg\';
  492. ')
  493. ),
  494. 'columns' => array(
  495. 'filename' => array(
  496. 'header' => array(
  497. 'value' => $txt['show_attach_downloads'],
  498. 'class' => 'lefttext',
  499. 'style' => 'width: 25%',
  500. ),
  501. 'data' => array(
  502. 'db' => 'filename',
  503. ),
  504. 'sort' => array(
  505. 'default' => 'a.filename',
  506. 'reverse' => 'a.filename DESC',
  507. ),
  508. ),
  509. 'downloads' => array(
  510. 'header' => array(
  511. 'value' => $txt['show_attach_downloads'],
  512. 'style' => 'width: 12%',
  513. ),
  514. 'data' => array(
  515. 'db' => 'downloads',
  516. 'comma_format' => true,
  517. ),
  518. 'sort' => array(
  519. 'default' => 'a.downloads',
  520. 'reverse' => 'a.downloads DESC',
  521. ),
  522. ),
  523. 'subject' => array(
  524. 'header' => array(
  525. 'value' => $txt['message'],
  526. 'class' => 'lefttext',
  527. 'style' => 'width: 30%',
  528. ),
  529. 'data' => array(
  530. 'db' => 'subject',
  531. ),
  532. 'sort' => array(
  533. 'default' => 'm.subject',
  534. 'reverse' => 'm.subject DESC',
  535. ),
  536. ),
  537. 'posted' => array(
  538. 'header' => array(
  539. 'value' => $txt['show_attach_posted'],
  540. 'class' => 'lefttext',
  541. ),
  542. 'data' => array(
  543. 'db' => 'posted',
  544. 'timeformat' => true,
  545. ),
  546. 'sort' => array(
  547. 'default' => 'm.poster_time',
  548. 'reverse' => 'm.poster_time DESC',
  549. ),
  550. ),
  551. ),
  552. );
  553. // Create the request list.
  554. createList($listOptions);
  555. }
  556. function list_getAttachments($start, $items_per_page, $sort, $boardsAllowed, $memID)
  557. {
  558. global $smcFunc, $board, $modSettings, $context;
  559. // Retrieve some attachments.
  560. $request = $smcFunc['db_query']('', '
  561. SELECT a.id_attach, a.id_msg, a.filename, a.downloads, a.approved, m.id_msg, m.id_topic,
  562. m.id_board, m.poster_time, m.subject, b.name
  563. FROM {db_prefix}attachments AS a
  564. INNER JOIN {db_prefix}messages AS m ON (m.id_msg = a.id_msg)
  565. INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board AND {query_see_board})
  566. WHERE a.attachment_type = {int:attachment_type}
  567. AND a.id_msg != {int:no_message}
  568. AND m.id_member = {int:current_member}' . (!empty($board) ? '
  569. AND b.id_board = {int:board}' : '') . (!in_array(0, $boardsAllowed) ? '
  570. AND b.id_board IN ({array_int:boards_list})' : '') . (!$modSettings['postmod_active'] || $context['user']['is_owner'] ? '' : '
  571. AND m.approved = {int:is_approved}') . '
  572. ORDER BY {raw:sort}
  573. LIMIT {int:offset}, {int:limit}',
  574. array(
  575. 'boards_list' => $boardsAllowed,
  576. 'attachment_type' => 0,
  577. 'no_message' => 0,
  578. 'current_member' => $memID,
  579. 'is_approved' => 1,
  580. 'board' => $board,
  581. 'sort' => $sort,
  582. 'offset' => $start,
  583. 'limit' => $items_per_page,
  584. )
  585. );
  586. $attachments = array();
  587. while ($row = $smcFunc['db_fetch_assoc']($request))
  588. $attachments[] = array(
  589. 'id' => $row['id_attach'],
  590. 'filename' => $row['filename'],
  591. 'downloads' => $row['downloads'],
  592. 'subject' => censorText($row['subject']),
  593. 'posted' => $row['poster_time'],
  594. 'msg' => $row['id_msg'],
  595. 'topic' => $row['id_topic'],
  596. 'board' => $row['id_board'],
  597. 'board_name' => $row['name'],
  598. 'approved' => $row['approved'],
  599. );
  600. $smcFunc['db_free_result']($request);
  601. return $attachments;
  602. }
  603. function list_getNumAttachments($boardsAllowed, $memID)
  604. {
  605. global $board, $smcFunc, $modSettings, $context;
  606. // Get the total number of attachments they have posted.
  607. $request = $smcFunc['db_query']('', '
  608. SELECT COUNT(*)
  609. FROM {db_prefix}attachments AS a
  610. INNER JOIN {db_prefix}messages AS m ON (m.id_msg = a.id_msg)
  611. INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board AND {query_see_board})
  612. WHERE a.attachment_type = {int:attachment_type}
  613. AND a.id_msg != {int:no_message}
  614. AND m.id_member = {int:current_member}' . (!empty($board) ? '
  615. AND b.id_board = {int:board}' : '') . (!in_array(0, $boardsAllowed) ? '
  616. AND b.id_board IN ({array_int:boards_list})' : '') . (!$modSettings['postmod_active'] || $context['user']['is_owner'] ? '' : '
  617. AND m.approved = {int:is_approved}'),
  618. array(
  619. 'boards_list' => $boardsAllowed,
  620. 'attachment_type' => 0,
  621. 'no_message' => 0,
  622. 'current_member' => $memID,
  623. 'is_approved' => 1,
  624. 'board' => $board,
  625. )
  626. );
  627. list ($attachCount) = $smcFunc['db_fetch_row']($request);
  628. $smcFunc['db_free_result']($request);
  629. return $attachCount;
  630. }
  631. /**
  632. * Gets the user stats for display
  633. *
  634. * @param int $memID id_member
  635. */
  636. function statPanel($memID)
  637. {
  638. global $txt, $scripturl, $context, $user_profile, $user_info, $modSettings, $smcFunc;
  639. $context['page_title'] = $txt['statPanel_showStats'] . ' ' . $user_profile[$memID]['real_name'];
  640. // Is the load average too high to allow searching just now?
  641. if (!empty($context['load_average']) && !empty($modSettings['loadavg_userstats']) && $context['load_average'] >= $modSettings['loadavg_userstats'])
  642. fatal_lang_error('loadavg_userstats_disabled', false);
  643. // General user statistics.
  644. $timeDays = floor($user_profile[$memID]['total_time_logged_in'] / 86400);
  645. $timeHours = floor(($user_profile[$memID]['total_time_logged_in'] % 86400) / 3600);
  646. $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'];
  647. $context['num_posts'] = comma_format($user_profile[$memID]['posts']);
  648. // Number of topics started.
  649. $result = $smcFunc['db_query']('', '
  650. SELECT COUNT(*)
  651. FROM {db_prefix}topics
  652. WHERE id_member_started = {int:current_member}' . (!empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0 ? '
  653. AND id_board != {int:recycle_board}' : ''),
  654. array(
  655. 'current_member' => $memID,
  656. 'recycle_board' => $modSettings['recycle_board'],
  657. )
  658. );
  659. list ($context['num_topics']) = $smcFunc['db_fetch_row']($result);
  660. $smcFunc['db_free_result']($result);
  661. // Number polls started.
  662. $result = $smcFunc['db_query']('', '
  663. SELECT COUNT(*)
  664. FROM {db_prefix}topics
  665. WHERE id_member_started = {int:current_member}' . (!empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0 ? '
  666. AND id_board != {int:recycle_board}' : '') . '
  667. AND id_poll != {int:no_poll}',
  668. array(
  669. 'current_member' => $memID,
  670. 'recycle_board' => $modSettings['recycle_board'],
  671. 'no_poll' => 0,
  672. )
  673. );
  674. list ($context['num_polls']) = $smcFunc['db_fetch_row']($result);
  675. $smcFunc['db_free_result']($result);
  676. // Number polls voted in.
  677. $result = $smcFunc['db_query']('distinct_poll_votes', '
  678. SELECT COUNT(DISTINCT id_poll)
  679. FROM {db_prefix}log_polls
  680. WHERE id_member = {int:current_member}',
  681. array(
  682. 'current_member' => $memID,
  683. )
  684. );
  685. list ($context['num_votes']) = $smcFunc['db_fetch_row']($result);
  686. $smcFunc['db_free_result']($result);
  687. // Format the numbers...
  688. $context['num_topics'] = comma_format($context['num_topics']);
  689. $context['num_polls'] = comma_format($context['num_polls']);
  690. $context['num_votes'] = comma_format($context['num_votes']);
  691. // Grab the board this member posted in most often.
  692. $result = $smcFunc['db_query']('', '
  693. SELECT
  694. b.id_board, MAX(b.name) AS name, MAX(b.num_posts) AS num_posts, COUNT(*) AS message_count
  695. FROM {db_prefix}messages AS m
  696. INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board)
  697. WHERE m.id_member = {int:current_member}
  698. AND b.count_posts = {int:count_enabled}
  699. AND {query_see_board}
  700. GROUP BY b.id_board
  701. ORDER BY message_count DESC
  702. LIMIT 10',
  703. array(
  704. 'current_member' => $memID,
  705. 'count_enabled' => 0,
  706. )
  707. );
  708. $context['popular_boards'] = array();
  709. while ($row = $smcFunc['db_fetch_assoc']($result))
  710. {
  711. $context['popular_boards'][$row['id_board']] = array(
  712. 'id' => $row['id_board'],
  713. 'posts' => $row['message_count'],
  714. 'href' => $scripturl . '?board=' . $row['id_board'] . '.0',
  715. 'link' => '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['name'] . '</a>',
  716. 'posts_percent' => $user_profile[$memID]['posts'] == 0 ? 0 : ($row['message_count'] * 100) / $user_profile[$memID]['posts'],
  717. 'total_posts' => $row['num_posts'],
  718. 'total_posts_member' => $user_profile[$memID]['posts'],
  719. );
  720. }
  721. $smcFunc['db_free_result']($result);
  722. // Now get the 10 boards this user has most often participated in.
  723. $result = $smcFunc['db_query']('profile_board_stats', '
  724. SELECT
  725. b.id_board, MAX(b.name) AS name, b.num_posts, COUNT(*) AS message_count,
  726. CASE WHEN COUNT(*) > MAX(b.num_posts) THEN 1 ELSE COUNT(*) / MAX(b.num_posts) END * 100 AS percentage
  727. FROM {db_prefix}messages AS m
  728. INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board)
  729. WHERE m.id_member = {int:current_member}
  730. AND {query_see_board}
  731. GROUP BY b.id_board, b.num_posts
  732. ORDER BY percentage DESC
  733. LIMIT 10',
  734. array(
  735. 'current_member' => $memID,
  736. )
  737. );
  738. $context['board_activity'] = array();
  739. while ($row = $smcFunc['db_fetch_assoc']($result))
  740. {
  741. $context['board_activity'][$row['id_board']] = array(
  742. 'id' => $row['id_board'],
  743. 'posts' => $row['message_count'],
  744. 'href' => $scripturl . '?board=' . $row['id_board'] . '.0',
  745. 'link' => '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['name'] . '</a>',
  746. 'percent' => comma_format((float) $row['percentage'], 2),
  747. 'posts_percent' => (float) $row['percentage'],
  748. 'total_posts' => $row['num_posts'],
  749. );
  750. }
  751. $smcFunc['db_free_result']($result);
  752. // Posting activity by time.
  753. $result = $smcFunc['db_query']('user_activity_by_time', '
  754. SELECT
  755. HOUR(FROM_UNIXTIME(poster_time + {int:time_offset})) AS hour,
  756. COUNT(*) AS post_count
  757. FROM {db_prefix}messages
  758. WHERE id_member = {int:current_member}' . ($modSettings['totalMessages'] > 100000 ? '
  759. AND id_topic > {int:top_ten_thousand_topics}' : '') . '
  760. GROUP BY hour',
  761. array(
  762. 'current_member' => $memID,
  763. 'top_ten_thousand_topics' => $modSettings['totalTopics'] - 10000,
  764. 'time_offset' => (($user_info['time_offset'] + $modSettings['time_offset']) * 3600),
  765. )
  766. );
  767. $maxPosts = $realPosts = 0;
  768. $context['posts_by_time'] = array();
  769. while ($row = $smcFunc['db_fetch_assoc']($result))
  770. {
  771. // Cast as an integer to remove the leading 0.
  772. $row['hour'] = (int) $row['hour'];
  773. $maxPosts = max($row['post_count'], $maxPosts);
  774. $realPosts += $row['post_count'];
  775. $context['posts_by_time'][$row['hour']] = array(
  776. 'hour' => $row['hour'],
  777. 'hour_format' => stripos($user_info['time_format'], '%p') === false ? $row['hour'] : date('g a', mktime($row['hour'])),
  778. 'posts' => $row['post_count'],
  779. 'posts_percent' => 0,
  780. 'is_last' => $row['hour'] == 23,
  781. );
  782. }
  783. $smcFunc['db_free_result']($result);
  784. if ($maxPosts > 0)
  785. for ($hour = 0; $hour < 24; $hour++)
  786. {
  787. if (!isset($context['posts_by_time'][$hour]))
  788. $context['posts_by_time'][$hour] = array(
  789. 'hour' => $hour,
  790. 'hour_format' => stripos($user_info['time_format'], '%p') === false ? $hour : date('g a', mktime($hour)),
  791. 'posts' => 0,
  792. 'posts_percent' => 0,
  793. 'relative_percent' => 0,
  794. 'is_last' => $hour == 23,
  795. );
  796. else
  797. {
  798. $context['posts_by_time'][$hour]['posts_percent'] = round(($context['posts_by_time'][$hour]['posts'] * 100) / $realPosts);
  799. $context['posts_by_time'][$hour]['relative_percent'] = round(($context['posts_by_time'][$hour]['posts'] * 100) / $maxPosts);
  800. }
  801. }
  802. // Put it in the right order.
  803. ksort($context['posts_by_time']);
  804. // Custom stats (just add a template_layer to add it to the template!)
  805. call_integration_hook('integrate_profile_stats', array($memID));
  806. }
  807. /**
  808. * @todo needs a description
  809. *
  810. * @param int $memID id_member
  811. */
  812. function tracking($memID)
  813. {
  814. global $sourcedir, $context, $txt, $scripturl, $modSettings, $user_profile;
  815. $subActions = array(
  816. 'activity' => array('trackActivity', $txt['trackActivity']),
  817. 'ip' => array('TrackIP', $txt['trackIP']),
  818. 'edits' => array('trackEdits', $txt['trackEdits']),
  819. 'logins' => array('TrackLogins', $txt['trackLogins']),
  820. );
  821. $context['tracking_area'] = isset($_GET['sa']) && isset($subActions[$_GET['sa']]) ? $_GET['sa'] : 'activity';
  822. // @todo what is $types? it is never set so this will never be true
  823. if (isset($types[$context['tracking_area']][1]))
  824. require_once($sourcedir . '/' . $types[$context['tracking_area']][1]);
  825. // Create the tabs for the template.
  826. $context[$context['profile_menu_name']]['tab_data'] = array(
  827. 'title' => $txt['tracking'],
  828. 'description' => $txt['tracking_description'],
  829. 'icon' => 'profile_sm.png',
  830. 'tabs' => array(
  831. 'activity' => array(),
  832. 'ip' => array(),
  833. 'edits' => array(),
  834. ),
  835. );
  836. // Moderation must be on to track edits.
  837. if (empty($modSettings['modlog_enabled']))
  838. unset($context[$context['profile_menu_name']]['tab_data']['edits']);
  839. // Set a page title.
  840. $context['page_title'] = $txt['trackUser'] . ' - ' . $subActions[$context['tracking_area']][1] . ' - ' . $user_profile[$memID]['real_name'];
  841. // Pass on to the actual function.
  842. $context['sub_template'] = $subActions[$context['tracking_area']][0];
  843. $subActions[$context['tracking_area']][0]($memID);
  844. }
  845. /**
  846. * @todo needs a description
  847. *
  848. * @param int $memID id_member
  849. */
  850. function trackActivity($memID)
  851. {
  852. global $scripturl, $txt, $modSettings, $sourcedir;
  853. global $user_profile, $context, $smcFunc;
  854. // Verify if the user has sufficient permissions.
  855. isAllowedTo('moderate_forum');
  856. $context['last_ip'] = $user_profile[$memID]['member_ip'];
  857. if ($context['last_ip'] != $user_profile[$memID]['member_ip2'])
  858. $context['last_ip2'] = $user_profile[$memID]['member_ip2'];
  859. $context['member']['name'] = $user_profile[$memID]['real_name'];
  860. // Set the options for the list component.
  861. $listOptions = array(
  862. 'id' => 'track_user_list',
  863. 'title' => $txt['errors_by'] . ' ' . $context['member']['name'],
  864. 'items_per_page' => $modSettings['defaultMaxMessages'],
  865. 'no_items_label' => $txt['no_errors_from_user'],
  866. 'base_href' => $scripturl . '?action=profile;area=tracking;sa=user;u=' . $memID,
  867. 'default_sort_col' => 'date',
  868. 'get_items' => array(
  869. 'function' => 'list_getUserErrors',
  870. 'params' => array(
  871. 'le.id_member = {int:current_member}',
  872. array('current_member' => $memID),
  873. ),
  874. ),
  875. 'get_count' => array(
  876. 'function' => 'list_getUserErrorCount',
  877. 'params' => array(
  878. 'id_member = {int:current_member}',
  879. array('current_member' => $memID),
  880. ),
  881. ),
  882. 'columns' => array(
  883. 'ip_address' => array(
  884. 'header' => array(
  885. 'value' => $txt['ip_address'],
  886. ),
  887. 'data' => array(
  888. 'sprintf' => array(
  889. 'format' => '<a href="' . $scripturl . '?action=profile;area=tracking;sa=ip;searchip=%1$s;u=' . $memID. '">%1$s</a>',
  890. 'params' => array(
  891. 'ip' => false,
  892. ),
  893. ),
  894. ),
  895. 'sort' => array(
  896. 'default' => 'le.ip',
  897. 'reverse' => 'le.ip DESC',
  898. ),
  899. ),
  900. 'message' => array(
  901. 'header' => array(
  902. 'value' => $txt['message'],
  903. ),
  904. 'data' => array(
  905. 'sprintf' => array(
  906. 'format' => '%1$s<br /><a href="%2$s">%2$s</a>',
  907. 'params' => array(
  908. 'message' => false,
  909. 'url' => false,
  910. ),
  911. ),
  912. ),
  913. ),
  914. 'date' => array(
  915. 'header' => array(
  916. 'value' => $txt['date'],
  917. ),
  918. 'data' => array(
  919. 'db' => 'time',
  920. ),
  921. 'sort' => array(
  922. 'default' => 'le.id_error DESC',
  923. 'reverse' => 'le.id_error',
  924. ),
  925. ),
  926. ),
  927. 'additional_rows' => array(
  928. array(
  929. 'position' => 'after_title',
  930. 'value' => $txt['errors_desc'],
  931. 'class' => 'windowbg2',
  932. 'style' => 'padding: 1ex 2ex;',
  933. ),
  934. ),
  935. );
  936. // Create the list for viewing.
  937. require_once($sourcedir . '/Subs-List.php');
  938. createList($listOptions);
  939. // @todo cache this
  940. // If this is a big forum, or a large posting user, let's limit the search.
  941. if ($modSettings['totalMessages'] > 50000 && $user_profile[$memID]['posts'] > 500)
  942. {
  943. $request = $smcFunc['db_query']('', '
  944. SELECT MAX(id_msg)
  945. FROM {db_prefix}messages AS m
  946. WHERE m.id_member = {int:current_member}',
  947. array(
  948. 'current_member' => $memID,
  949. )
  950. );
  951. list ($max_msg_member) = $smcFunc['db_fetch_row']($request);
  952. $smcFunc['db_free_result']($request);
  953. // There's no point worrying ourselves with messages made yonks ago, just get recent ones!
  954. $min_msg_member = max(0, $max_msg_member - $user_profile[$memID]['posts'] * 3);
  955. }
  956. // Default to at least the ones we know about.
  957. $ips = array(
  958. $user_profile[$memID]['member_ip'],
  959. $user_profile[$memID]['member_ip2'],
  960. );
  961. // @todo cache this
  962. // Get all IP addresses this user has used for his messages.
  963. $request = $smcFunc['db_query']('', '
  964. SELECT poster_ip
  965. FROM {db_prefix}messages
  966. WHERE id_member = {int:current_member}
  967. ' . (isset($min_msg_member) ? '
  968. AND id_msg >= {int:min_msg_member} AND id_msg <= {int:max_msg_member}' : '') . '
  969. GROUP BY poster_ip',
  970. array(
  971. 'current_member' => $memID,
  972. 'min_msg_member' => !empty($min_msg_member) ? $min_msg_member : 0,
  973. 'max_msg_member' => !empty($max_msg_member) ? $max_msg_member : 0,
  974. )
  975. );
  976. $context['ips'] = array();
  977. while ($row = $smcFunc['db_fetch_assoc']($request))
  978. {
  979. $context['ips'][] = '<a href="' . $scripturl . '?action=profile;area=tracking;sa=ip;searchip=' . $row['poster_ip'] . ';u=' . $memID . '">' . $row['poster_ip'] . '</a>';
  980. $ips[] = $row['poster_ip'];
  981. }
  982. $smcFunc['db_free_result']($request);
  983. // Now also get the IP addresses from the error messages.
  984. $request = $smcFunc['db_query']('', '
  985. SELECT COUNT(*) AS error_count, ip
  986. FROM {db_prefix}log_errors
  987. WHERE id_member = {int:current_member}
  988. GROUP BY ip',
  989. array(
  990. 'current_member' => $memID,
  991. )
  992. );
  993. $context['error_ips'] = array();
  994. while ($row = $smcFunc['db_fetch_assoc']($request))
  995. {
  996. $context['error_ips'][] = '<a href="' . $scripturl . '?action=profile;area=tracking;sa=ip;searchip=' . $row['ip'] . ';u=' . $memID . '">' . $row['ip'] . '</a>';
  997. $ips[] = $row['ip'];
  998. }
  999. $smcFunc['db_free_result']($request);
  1000. // Find other users that might use the same IP.
  1001. $ips = array_unique($ips);
  1002. $context['members_in_range'] = array();
  1003. if (!empty($ips))
  1004. {
  1005. // Get member ID's which are in messages...
  1006. $request = $smcFunc['db_query']('', '
  1007. SELECT mem.id_member
  1008. FROM {db_prefix}messages AS m
  1009. INNER JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member)
  1010. WHERE m.poster_ip IN ({array_string:ip_list})
  1011. GROUP BY mem.id_member
  1012. HAVING mem.id_member != {int:current_member}',
  1013. array(
  1014. 'current_member' => $memID,
  1015. 'ip_list' => $ips,
  1016. )
  1017. );
  1018. $message_members = array();
  1019. while ($row = $smcFunc['db_fetch_assoc']($request))
  1020. $message_members[] = $row['id_member'];
  1021. $smcFunc['db_free_result']($request);
  1022. // Fetch their names, cause of the GROUP BY doesn't like giving us that normally.
  1023. if (!empty($message_members))
  1024. {
  1025. $request = $smcFunc['db_query']('', '
  1026. SELECT id_member, real_name
  1027. FROM {db_prefix}members
  1028. WHERE id_member IN ({array_int:message_members})',
  1029. array(
  1030. 'message_members' => $message_members,
  1031. 'ip_list' => $ips,
  1032. )
  1033. );
  1034. while ($row = $smcFunc['db_fetch_assoc']($request))
  1035. $context['members_in_range'][$row['id_member']] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>';
  1036. $smcFunc['db_free_result']($request);
  1037. }
  1038. $request = $smcFunc['db_query']('', '
  1039. SELECT id_member, real_name
  1040. FROM {db_prefix}members
  1041. WHERE id_member != {int:current_member}
  1042. AND member_ip IN ({array_string:ip_list})',
  1043. array(
  1044. 'current_member' => $memID,
  1045. 'ip_list' => $ips,
  1046. )
  1047. );
  1048. while ($row = $smcFunc['db_fetch_assoc']($request))
  1049. $context['members_in_range'][$row['id_member']] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>';
  1050. $smcFunc['db_free_result']($request);
  1051. }
  1052. }
  1053. /**
  1054. * Get the number of user errors
  1055. *
  1056. * @param string $where
  1057. * @param array $where_vars = array()
  1058. * @return string number of user errors
  1059. */
  1060. function list_getUserErrorCount($where, $where_vars = array())
  1061. {
  1062. global $smcFunc;
  1063. $request = $smcFunc['db_query']('', '
  1064. SELECT COUNT(*) AS error_count
  1065. FROM {db_prefix}log_errors
  1066. WHERE ' . $where,
  1067. $where_vars
  1068. );
  1069. list ($count) = $smcFunc['db_fetch_row']($request);
  1070. $smcFunc['db_free_result']($request);
  1071. // @todo cast this to an integer
  1072. return $count;
  1073. }
  1074. /**
  1075. * @todo needs a description
  1076. *
  1077. * @param int $start
  1078. * @param int $items_per_page
  1079. * @param string $sort
  1080. * @param string $where
  1081. * @param array $where_vars
  1082. * @return array error messages
  1083. */
  1084. function list_getUserErrors($start, $items_per_page, $sort, $where, $where_vars = array())
  1085. {
  1086. global $smcFunc, $txt, $scripturl;
  1087. // Get a list of error messages from this ip (range).
  1088. $request = $smcFunc['db_query']('', '
  1089. SELECT
  1090. le.log_time, le.ip, le.url, le.message, IFNULL(mem.id_member, 0) AS id_member,
  1091. IFNULL(mem.real_name, {string:guest_title}) AS display_name, mem.member_name
  1092. FROM {db_prefix}log_errors AS le
  1093. LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = le.id_member)
  1094. WHERE ' . $where . '
  1095. ORDER BY ' . $sort . '
  1096. LIMIT ' . $start . ', ' . $items_per_page,
  1097. array_merge($where_vars, array(
  1098. 'guest_title' => $txt['guest_title'],
  1099. ))
  1100. );
  1101. $error_messages = array();
  1102. while ($row = $smcFunc['db_fetch_assoc']($request))
  1103. $error_messages[] = array(
  1104. 'ip' => $row['ip'],
  1105. 'member_link' => $row['id_member'] > 0 ? '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['display_name'] . '</a>' : $row['display_name'],
  1106. 'message' => strtr($row['message'], array('&lt;span class=&quot;remove&quot;&gt;' => '', '&lt;/span&gt;' => '')),
  1107. 'url' => $row['url'],
  1108. 'time' => timeformat($row['log_time']),
  1109. 'timestamp' => forum_time(true, $row['log_time']),
  1110. );
  1111. $smcFunc['db_free_result']($request);
  1112. return $error_messages;
  1113. }
  1114. /**
  1115. * @todo needs a description
  1116. *
  1117. * @param string $where
  1118. * @param array $where_vars
  1119. * @return string count of messages matching the IP
  1120. */
  1121. function list_getIPMessageCount($where, $where_vars = array())
  1122. {
  1123. global $smcFunc;
  1124. $request = $smcFunc['db_query']('', '
  1125. SELECT COUNT(*) AS message_count
  1126. FROM {db_prefix}messages AS m
  1127. INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board)
  1128. WHERE {query_see_board} AND ' . $where,
  1129. $where_vars
  1130. );
  1131. list ($count) = $smcFunc['db_fetch_row']($request);
  1132. $smcFunc['db_free_result']($request);
  1133. // @todo cast to integer
  1134. return $count;
  1135. }
  1136. /**
  1137. * @todo needs a description
  1138. *
  1139. * @param int $start
  1140. * @param int $items_per_page
  1141. * @param string $sort
  1142. * @param string $where
  1143. * @param array $where_vars
  1144. * @return array an array of messages
  1145. */
  1146. function list_getIPMessages($start, $items_per_page, $sort, $where, $where_vars = array())
  1147. {
  1148. global $smcFunc, $txt, $scripturl;
  1149. // Get all the messages fitting this where clause.
  1150. // @todo SLOW This query is using a filesort.
  1151. $request = $smcFunc['db_query']('', '
  1152. SELECT
  1153. m.id_msg, m.poster_ip, IFNULL(mem.real_name, m.poster_name) AS display_name, mem.id_member,
  1154. m.subject, m.poster_time, m.id_topic, m.id_board
  1155. FROM {db_prefix}messages AS m
  1156. INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board)
  1157. LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member)
  1158. WHERE {query_see_board} AND ' . $where . '
  1159. ORDER BY ' . $sort . '
  1160. LIMIT ' . $start . ', ' . $items_per_page,
  1161. array_merge($where_vars, array(
  1162. ))
  1163. );
  1164. $messages = array();
  1165. while ($row = $smcFunc['db_fetch_assoc']($request))
  1166. $messages[] = array(
  1167. 'ip' => $row['poster_ip'],
  1168. 'member_link' => empty($row['id_member']) ? $row['display_name'] : '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['display_name'] . '</a>',
  1169. 'board' => array(
  1170. 'id' => $row['id_board'],
  1171. 'href' => $scripturl . '?board=' . $row['id_board']
  1172. ),
  1173. 'topic' => $row['id_topic'],
  1174. 'id' => $row['id_msg'],
  1175. 'subject' => $row['subject'],
  1176. 'time' => timeformat($row['poster_time']),
  1177. 'timestamp' => forum_time(true, $row['poster_time'])
  1178. );
  1179. $smcFunc['db_free_result']($request);
  1180. return $messages;
  1181. }
  1182. /**
  1183. * @todo needs a description
  1184. *
  1185. * @param int $memID = 0 id_member
  1186. */
  1187. function TrackIP($memID = 0)
  1188. {
  1189. global $user_profile, $scripturl, $txt, $user_info, $modSettings, $sourcedir;
  1190. global $context, $smcFunc;
  1191. // Can the user do this?
  1192. isAllowedTo('moderate_forum');
  1193. if ($memID == 0)
  1194. {
  1195. $context['ip'] = $user_info['ip'];
  1196. loadTemplate('Profile');
  1197. loadLanguage('Profile');
  1198. $context['sub_template'] = 'trackIP';
  1199. $context['page_title'] = $txt['profile'];
  1200. $context['base_url'] = $scripturl . '?action=trackip';
  1201. }
  1202. else
  1203. {
  1204. $context['ip'] = $user_profile[$memID]['member_ip'];
  1205. $context['base_url'] = $scripturl . '?action=profile;area=tracking;sa=ip;u=' . $memID;
  1206. }
  1207. // Searching?
  1208. if (isset($_REQUEST['searchip']))
  1209. $context['ip'] = trim($_REQUEST['searchip']);
  1210. if (preg_match('/^\d{1,3}\.(\d{1,3}|\*)\.(\d{1,3}|\*)\.(\d{1,3}|\*)$/', $context['ip']) == 0 && isValidIPv6($context['ip']) === false)
  1211. fatal_lang_error('invalid_tracking_ip', false);
  1212. $ip_var = str_replace('*', '%', $context['ip']);
  1213. $ip_string = strpos($ip_var, '%') === false ? '= {string:ip_address}' : 'LIKE {string:ip_address}';
  1214. if (empty($context['tracking_area']))
  1215. $context['page_title'] = $txt['trackIP'] . ' - ' . $context['ip'];
  1216. $request = $smcFunc['db_query']('', '
  1217. SELECT id_member, real_name AS display_name, member_ip
  1218. FROM {db_prefix}members
  1219. WHERE member_ip ' . $ip_string,
  1220. array(
  1221. 'ip_address' => $ip_var,
  1222. )
  1223. );
  1224. $context['ips'] = array();
  1225. while ($row = $smcFunc['db_fetch_assoc']($request))
  1226. $context['ips'][$row['member_ip']][] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['display_name'] . '</a>';
  1227. $smcFunc['db_free_result']($request);
  1228. ksort($context['ips']);
  1229. // Gonna want this for the list.
  1230. require_once($sourcedir . '/Subs-List.php');
  1231. // Start with the user messages.
  1232. $listOptions = array(
  1233. 'id' => 'track_message_list',
  1234. 'title' => $txt['messages_from_ip'] . ' ' . $context['ip'],
  1235. 'start_var_name' => 'messageStart',
  1236. 'items_per_page' => $modSettings['defaultMaxMessages'],
  1237. 'no_items_label' => $txt['no_messages_from_ip'],
  1238. 'base_href' => $context['base_url'] . ';searchip=' . $context['ip'],
  1239. 'default_sort_col' => 'date',
  1240. 'get_items' => array(
  1241. 'function' => 'list_getIPMessages',
  1242. 'params' => array(
  1243. 'm.poster_ip ' . $ip_string,
  1244. array('ip_address' => $ip_var),
  1245. ),
  1246. ),
  1247. 'get_count' => array(
  1248. 'function' => 'list_getIPMessageCount',
  1249. 'params' => array(
  1250. 'm.poster_ip ' . $ip_string,
  1251. array('ip_address' => $ip_var),
  1252. ),
  1253. ),
  1254. 'columns' => array(
  1255. 'ip_address' => array(
  1256. 'header' => array(
  1257. 'value' => $txt['ip_address'],
  1258. ),
  1259. 'data' => array(
  1260. 'sprintf' => array(
  1261. 'format' => '<a href="' . $context['base_url'] . ';searchip=%1$s">%1$s</a>',
  1262. 'params' => array(
  1263. 'ip' => false,
  1264. ),
  1265. ),
  1266. ),
  1267. 'sort' => array(
  1268. 'default' => 'INET_ATON(m.poster_ip)',
  1269. 'reverse' => 'INET_ATON(m.poster_ip) DESC',
  1270. ),
  1271. ),
  1272. 'poster' => array(
  1273. 'header' => array(
  1274. 'value' => $txt['poster'],
  1275. ),
  1276. 'data' => array(
  1277. 'db' => 'member_link',
  1278. ),
  1279. ),
  1280. 'subject' => array(
  1281. 'header' => array(
  1282. 'value' => $txt['subject'],
  1283. ),
  1284. 'data' => array(
  1285. 'sprintf' => array(
  1286. 'format' => '<a href="' . $scripturl . '?topic=%1$s.msg%2$s#msg%2$s" rel="nofollow">%3$s</a>',
  1287. 'params' => array(
  1288. 'topic' => false,
  1289. 'id' => false,
  1290. 'subject' => false,
  1291. ),
  1292. ),
  1293. ),
  1294. ),
  1295. 'date' => array(
  1296. 'header' => array(
  1297. 'value' => $txt['date'],
  1298. ),
  1299. 'data' => array(
  1300. 'db' => 'time',
  1301. ),
  1302. 'sort' => array(
  1303. 'default' => 'm.id_msg DESC',
  1304. 'reverse' => 'm.id_msg',
  1305. ),
  1306. ),
  1307. ),
  1308. 'additional_rows' => array(
  1309. array(
  1310. 'position' => 'after_title',
  1311. 'value' => $txt['messages_from_ip_desc'],
  1312. 'class' => 'windowbg2',
  1313. 'style' => 'padding: 1ex 2ex;',
  1314. ),
  1315. ),
  1316. );
  1317. // Create the messages list.
  1318. createList($listOptions);
  1319. // Set the options for the error lists.
  1320. $listOptions = array(
  1321. 'id' => 'track_user_list',
  1322. 'title' => $txt['errors_from_ip'] . ' ' . $context['ip'],
  1323. 'start_var_name' => 'errorStart',
  1324. 'items_per_page' => $modSettings['defaultMaxMessages'],
  1325. 'no_items_label' => $txt['no_errors_from_ip'],
  1326. 'base_href' => $context['base_url'] . ';searchip=' . $context['ip'],
  1327. 'default_sort_col' => 'date2',
  1328. 'get_items' => array(
  1329. 'function' => 'list_getUserErrors',
  1330. 'params' => array(
  1331. 'le.ip ' . $ip_string,
  1332. array('ip_address' => $ip_var),
  1333. ),
  1334. ),
  1335. 'get_count' => array(
  1336. 'function' => 'list_getUserErrorCount',
  1337. 'params' => array(
  1338. 'ip ' . $ip_string,
  1339. array('ip_address' => $ip_var),
  1340. ),
  1341. ),
  1342. 'columns' => array(
  1343. 'ip_address2' => array(
  1344. 'header' => array(
  1345. 'value' => $txt['ip_address'],
  1346. ),
  1347. 'data' => array(
  1348. 'sprintf' => array(
  1349. 'format' => '<a href="' . $context['base_url'] . ';searchip=%1$s">%1$s</a>',
  1350. 'params' => array(
  1351. 'ip' => false,
  1352. ),
  1353. ),
  1354. ),
  1355. 'sort' => array(
  1356. 'default' => 'INET_ATON(le.ip)',
  1357. 'reverse' => 'INET_ATON(le.ip) DESC',
  1358. ),
  1359. ),
  1360. 'display_name' => array(
  1361. 'header' => array(
  1362. 'value' => $txt['display_name'],
  1363. ),
  1364. 'data' => array(
  1365. 'db' => 'member_link',
  1366. ),
  1367. ),
  1368. 'message' => array(
  1369. 'header' => array(
  1370. 'value' => $txt['message'],
  1371. ),
  1372. 'data' => array(
  1373. 'sprintf' => array(
  1374. 'format' => '%1$s<br /><a href="%2$s">%2$s</a>',
  1375. 'params' => array(
  1376. 'message' => false,
  1377. 'url' => false,
  1378. ),
  1379. ),
  1380. ),
  1381. ),
  1382. 'date2' => array(
  1383. 'header' => array(
  1384. 'value' => $txt['date'],
  1385. ),
  1386. 'data' => array(
  1387. 'db' => 'time',
  1388. ),
  1389. 'sort' => array(
  1390. 'default' => 'le.id_error DESC',
  1391. 'reverse' => 'le.id_error',
  1392. ),
  1393. ),
  1394. ),
  1395. 'additional_rows' => array(
  1396. array(
  1397. 'position' => 'after_title',
  1398. 'value' => $txt['errors_from_ip_desc'],
  1399. 'class' => 'windowbg2',
  1400. 'style' => 'padding: 1ex 2ex;',
  1401. ),
  1402. ),
  1403. );
  1404. // Create the error list.
  1405. createList($listOptions);
  1406. $context['single_ip'] = strpos($context['ip'], '*') === false;
  1407. if ($context['single_ip'])
  1408. {
  1409. $context['whois_servers'] = array(
  1410. 'afrinic' => array(
  1411. 'name' => $txt['whois_afrinic'],
  1412. 'url' => 'http://www.afrinic.net/cgi-bin/whois?searchtext=' . $context['ip'],
  1413. 'range' => array(41, 154, 196),
  1414. ),
  1415. 'apnic' => array(
  1416. 'name' => $txt['whois_apnic'],
  1417. 'url' => 'http://wq.apnic.net/apnic-bin/whois.pl?searchtext=' . $context['ip'],
  1418. 'range' => array(58, 59, 60, 61, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124,
  1419. 125, 126, 133, 150, 153, 163, 171, 202, 203, 210, 211, 218, 219, 220, 221, 222),
  1420. ),
  1421. 'arin' => array(
  1422. 'name' => $txt['whois_arin'],
  1423. 'url' => 'http://whois.arin.net/rest/ip/' . $context['ip'],
  1424. 'range' => array(7, 24, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 96, 97, 98, 99,
  1425. 128, 129, 130, 131, 132, 134, 135, 136, 137, 138, 139, 140, 142, 143, 144, 146, 147, 148, 149,
  1426. 152, 155, 156, 157, 158, 159, 160, 161, 162, 164, 165, 166, 167, 168, 169, 170, 172, 173, 174,
  1427. 192, 198, 199, 204, 205, 206, 207, 208, 209, 216),
  1428. ),
  1429. 'lacnic' => array(
  1430. 'name' => $txt['whois_lacnic'],
  1431. 'url' => 'http://lacnic.net/cgi-bin/lacnic/whois?query=' . $context['ip'],
  1432. 'range' => array(186, 187, 189, 190, 191, 200, 201),
  1433. ),
  1434. 'ripe' => array(
  1435. 'name' => $txt['whois_ripe'],
  1436. 'url' => 'http://www.db.ripe.net/whois?searchtext=' . $context['ip'],
  1437. 'range' => array(62, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
  1438. 141, 145, 151, 188, 193, 194, 195, 212, 213, 217),
  1439. ),
  1440. );
  1441. foreach ($context['whois_servers'] as $whois)
  1442. {
  1443. // Strip off the "decimal point" and anything following...
  1444. if (in_array((int) $context['ip'], $whois['range']))
  1445. $context['auto_whois_server'] = $whois;
  1446. }
  1447. }
  1448. }
  1449. /**
  1450. * Tracks a users logins.
  1451. *
  1452. * @param int $memID = 0 id_member
  1453. */
  1454. function TrackLogins($memID = 0)
  1455. {
  1456. global $user_profile, $scripturl, $txt, $user_info, $modSettings, $sourcedir;
  1457. global $context, $smcFunc;
  1458. // Gonna want this for the list.
  1459. require_once($sourcedir . '/Subs-List.php');
  1460. if ($memID == 0)
  1461. $context['base_url'] = $scripturl . '?action=trackip';
  1462. else
  1463. $context['base_url'] = $scripturl . '?action=profile;area=tracking;sa=ip;u=' . $memID;
  1464. // Start with the user messages.
  1465. $listOptions = array(
  1466. 'id' => 'track_logins_list',
  1467. 'title' => $txt['trackLogins'],
  1468. 'no_items_label' => $txt['trackLogins_none_found'],
  1469. 'base_href' => $context['base_url'],
  1470. 'get_items' => array(
  1471. 'function' => 'list_getLogins',
  1472. 'params' => array(
  1473. 'id_member = {int:current_member}',
  1474. array('current_member' => $memID),
  1475. ),
  1476. ),
  1477. 'get_count' => array(
  1478. 'function' => 'list_getLoginCount',
  1479. 'params' => array(
  1480. 'id_member = {int:current_member}',
  1481. array('current_member' => $memID),
  1482. ),
  1483. ),
  1484. 'columns' => array(
  1485. 'time' => array(
  1486. 'header' => array(
  1487. 'value' => $txt['date'],
  1488. ),
  1489. 'data' => array(
  1490. 'db' => 'time',
  1491. ),
  1492. ),
  1493. 'ip' => array(
  1494. 'header' => array(
  1495. 'value' => $txt['ip_address'],
  1496. ),
  1497. 'data' => array(
  1498. 'sprintf' => array(
  1499. 'format' => '<a href="' . $context['base_url'] . ';searchip=%1$s">%1$s</a> (<a href="' . $context['base_url'] . ';searchip=%2$s">%2$s</a>) ',
  1500. 'params' => array(
  1501. 'ip' => false,
  1502. 'ip2' => false
  1503. ),
  1504. ),
  1505. ),
  1506. ),
  1507. ),
  1508. 'additional_rows' => array(
  1509. array(
  1510. 'position' => 'after_title',
  1511. 'value' => $txt['trackLogins_desc'],
  1512. 'class' => 'windowbg2',
  1513. 'style' => 'padding: 1ex 2ex;',
  1514. ),
  1515. ),
  1516. );
  1517. // Create the messages list.
  1518. createList($listOptions);
  1519. $context['sub_template'] = 'show_list';
  1520. $context['default_list'] = 'track_logins_list';
  1521. }
  1522. /**
  1523. * Callback for trackLogins for counting history.
  1524. *
  1525. * @param string $where
  1526. * @param array $where_vars
  1527. * @return string count of messages matching the IP
  1528. */
  1529. function list_getLoginCount($where, $where_vars = array())
  1530. {
  1531. global $smcFunc;
  1532. $request = $smcFunc['db_query']('', '
  1533. SELECT COUNT(*) AS message_count
  1534. FROM {db_prefix}member_logins
  1535. WHERE id_member = {int:id_member}',
  1536. array(
  1537. 'id_member' => $where_vars['current_member'],
  1538. )
  1539. );
  1540. list ($count) = $smcFunc['db_fetch_row']($request);
  1541. $smcFunc['db_free_result']($request);
  1542. // @todo cast to integer
  1543. return $count;
  1544. }
  1545. /**
  1546. * Callback for trackLogins data.
  1547. *
  1548. * @param int $start
  1549. * @param int $items_per_page
  1550. * @param string $sort
  1551. * @param string $where
  1552. * @param array $where_vars
  1553. * @return array an array of messages
  1554. */
  1555. function list_getLogins($start, $items_per_page, $sort, $where, $where_vars = array())
  1556. {
  1557. global $smcFunc, $txt, $scripturl;
  1558. $request = $smcFunc['db_query']('', '
  1559. SELECT time, ip, ip2
  1560. FROM {db_prefix}member_logins
  1561. WHERE {int:id_member}
  1562. ORDER BY time DESC',
  1563. array(
  1564. 'id_member' => $where_vars['current_member'],
  1565. )
  1566. );
  1567. $logins = array();
  1568. while ($row = $smcFunc['db_fetch_assoc']($request))
  1569. $logins[] = array(
  1570. 'time' => timeformat($row['time']),
  1571. 'ip' => $row['ip'],
  1572. 'ip2' => $row['ip2'],
  1573. );
  1574. $smcFunc['db_free_result']($request);
  1575. return $logins;
  1576. }
  1577. /**
  1578. * @todo needs a description
  1579. *
  1580. * @param int $memID id_member
  1581. */
  1582. function trackEdits($memID)
  1583. {
  1584. global $scripturl, $txt, $modSettings, $sourcedir, $context, $smcFunc;
  1585. require_once($sourcedir . '/Subs-List.php');
  1586. // Get the names of any custom fields.
  1587. $request = $smcFunc['db_query']('', '
  1588. SELECT col_name, field_name, bbc
  1589. FROM {db_prefix}custom_fields',
  1590. array(
  1591. )
  1592. );
  1593. $context['custom_field_titles'] = array();
  1594. while ($row = $smcFunc['db_fetch_assoc']($request))
  1595. $context['custom_field_titles']['customfield_' . $row['col_name']] = array(
  1596. 'title' => $row['field_name'],
  1597. 'parse_bbc' => $row['bbc'],
  1598. );
  1599. $smcFunc['db_free_result']($request);
  1600. // Set the options for the error lists.
  1601. $listOptions = array(
  1602. 'id' => 'edit_list',
  1603. 'title' => $txt['trackEdits'],
  1604. 'items_per_page' => $modSettings['defaultMaxMessages'],
  1605. 'no_items_label' => $txt['trackEdit_no_edits'],
  1606. 'base_href' => $scripturl . '?action=profile;area=tracking;sa=edits;u=' . $memID,
  1607. 'default_sort_col' => 'time',
  1608. 'get_items' => array(
  1609. 'function' => 'list_getProfileEdits',
  1610. 'params' => array(
  1611. $memID,
  1612. ),
  1613. ),
  1614. 'get_count' => array(
  1615. 'function' => 'list_getProfileEditCount',
  1616. 'params' => array(
  1617. $memID,
  1618. ),
  1619. ),
  1620. 'columns' => array(
  1621. 'action' => array(
  1622. 'header' => array(
  1623. 'value' => $txt['trackEdit_action'],
  1624. ),
  1625. 'data' => array(
  1626. 'db' => 'action_text',
  1627. ),
  1628. ),
  1629. 'before' => array(
  1630. 'header' => array(
  1631. 'value' => $txt['trackEdit_before'],
  1632. ),
  1633. 'data' => array(
  1634. 'db' => 'before',
  1635. ),
  1636. ),
  1637. 'after' => array(
  1638. 'header' => array(
  1639. 'value' => $txt['trackEdit_after'],
  1640. ),
  1641. 'data' => array(
  1642. 'db' => 'after',
  1643. ),
  1644. ),
  1645. 'time' => array(
  1646. 'header' => array(
  1647. 'value' => $txt['date'],
  1648. ),
  1649. 'data' => array(
  1650. 'db' => 'time',
  1651. ),
  1652. 'sort' => array(
  1653. 'default' => 'id_action DESC',
  1654. 'reverse' => 'id_action',
  1655. ),
  1656. ),
  1657. 'applicator' => array(
  1658. 'header' => array(
  1659. 'value' => $txt['trackEdit_applicator'],
  1660. ),
  1661. 'data' => array(
  1662. 'db' => 'member_link',
  1663. ),
  1664. ),
  1665. ),
  1666. );
  1667. // Create the error list.
  1668. createList($listOptions);
  1669. $context['sub_template'] = 'show_list';
  1670. $context['default_list'] = 'edit_list';
  1671. }
  1672. /**
  1673. * How many edits?
  1674. *
  1675. * @param int $memID id_member
  1676. * @return string number of profile edits
  1677. */
  1678. function list_getProfileEditCount($memID)
  1679. {
  1680. global $smcFunc;
  1681. $request = $smcFunc['db_query']('', '
  1682. SELECT COUNT(*) AS edit_count
  1683. FROM {db_prefix}log_actions
  1684. WHERE id_log = {int:log_type}
  1685. AND id_member = {int:owner}',
  1686. array(
  1687. 'log_type' => 2,
  1688. 'owner' => $memID,
  1689. )
  1690. );
  1691. list ($edit_count) = $smcFunc['db_fetch_row']($request);
  1692. $smcFunc['db_free_result']($request);
  1693. // @todo cast to integer
  1694. return $edit_count;
  1695. }
  1696. /**
  1697. * @todo needs a description
  1698. *
  1699. * @param int $start
  1700. * @param int $items_per_page
  1701. * @param string $sort
  1702. * @param int $memID
  1703. * @return array
  1704. */
  1705. function list_getProfileEdits($start, $items_per_page, $sort, $memID)
  1706. {
  1707. global $smcFunc, $txt, $scripturl, $context;
  1708. // Get a list of error messages from this ip (range).
  1709. $request = $smcFunc['db_query']('', '
  1710. SELECT
  1711. id_action, id_member, ip, log_time, action, extra
  1712. FROM {db_prefix}log_actions
  1713. WHERE id_log = {int:log_type}
  1714. AND id_member = {int:owner}
  1715. ORDER BY ' . $sort . '
  1716. LIMIT ' . $start . ', ' . $items_per_page,
  1717. array(
  1718. 'log_type' => 2,
  1719. 'owner' => $memID,
  1720. )
  1721. );
  1722. $edits = array();
  1723. $members = array();
  1724. while ($row = $smcFunc['db_fetch_assoc']($request))
  1725. {
  1726. $extra = @unserialize($row['extra']);
  1727. if (!empty($extra['applicator']))
  1728. $members[] = $extra['applicator'];
  1729. // Work out what the name of the action is.
  1730. if (isset($txt['trackEdit_action_' . $row['action']]))
  1731. $action_text = $txt['trackEdit_action_' . $row['action']];
  1732. elseif (isset($txt[$row['action']]))
  1733. $action_text = $txt[$row['action']];
  1734. // Custom field?
  1735. elseif (isset($context['custom_field_titles'][$row['action']]))
  1736. $action_text = $context['custom_field_titles'][$row['action']]['title'];
  1737. else
  1738. $action_text = $row['action'];
  1739. // Parse BBC?
  1740. $parse_bbc = isset($context['custom_field_titles'][$row['action']]) && $context['custom_field_titles'][$row['action']]['parse_bbc'] ? true : false;
  1741. $edits[] = array(
  1742. 'id' => $row['id_action'],
  1743. 'ip' => $row['ip'],
  1744. 'id_member' => !empty($extra['applicator']) ? $extra['applicator'] : 0,
  1745. 'member_link' => $txt['trackEdit_deleted_member'],
  1746. 'action' => $row['action'],
  1747. 'action_text' => $action_text,
  1748. 'before' => !empty($extra['previous']) ? ($parse_bbc ? parse_bbc($extra['previous']) : $extra['previous']) : '',
  1749. 'after' => !empty($extra['new']) ? ($parse_bbc ? parse_bbc($extra['new']) : $extra['new']) : '',
  1750. 'time' => timeformat($row['log_time']),
  1751. );
  1752. }
  1753. $smcFunc['db_free_result']($request);
  1754. // Get any member names.
  1755. if (!empty($members))
  1756. {
  1757. $request = $smcFunc['db_query']('', '
  1758. SELECT
  1759. id_member, real_name
  1760. FROM {db_prefix}members
  1761. WHERE id_member IN ({array_int:members})',
  1762. array(
  1763. 'members' => $members,
  1764. )
  1765. );
  1766. $members = array();
  1767. while ($row = $smcFunc['db_fetch_assoc']($request))
  1768. $members[$row['id_member']] = $row['real_name'];
  1769. $smcFunc['db_free_result']($request);
  1770. foreach ($edits as $key => $value)
  1771. if (isset($members[$value['id_member']]))
  1772. $edits[$key]['member_link'] = '<a href="' . $scripturl . '?action=profile;u=' . $value['id_member'] . '">' . $members[$value['id_member']] . '</a>';
  1773. }
  1774. return $edits;
  1775. }
  1776. /**
  1777. * @todo needs a description
  1778. *
  1779. * @param int $memID id_member
  1780. */
  1781. function showPermissions($memID)
  1782. {
  1783. global $scripturl, $txt, $board, $modSettings;
  1784. global $user_profile, $context, $user_info, $sourcedir, $smcFunc;
  1785. // Verify if the user has sufficient permissions.
  1786. isAllowedTo('manage_permissions');
  1787. loadLanguage('ManagePermissions');
  1788. loadLanguage('Admin');
  1789. loadTemplate('ManageMembers');
  1790. // Load all the permission profiles.
  1791. require_once($sourcedir . '/ManagePermissions.php');
  1792. loadPermissionProfiles();
  1793. $context['member']['id'] = $memID;
  1794. $context['member']['name'] = $user_profile[$memID]['real_name'];
  1795. $context['page_title'] = $txt['showPermissions'];
  1796. $board = empty($board) ? 0 : (int) $board;
  1797. $context['board'] = $board;
  1798. // Determine which groups this user is in.
  1799. if (empty($user_profile[$memID]['additional_groups']))
  1800. $curGroups = array();
  1801. else
  1802. $curGroups = explode(',', $user_profile[$memID]['additional_groups']);
  1803. $curGroups[] = $user_profile[$memID]['id_group'];
  1804. $curGroups[] = $user_profile[$memID]['id_post_group'];
  1805. // Load a list of boards for the jump box - except the defaults.
  1806. $request = $smcFunc['db_query']('order_by_board_order', '
  1807. SELECT b.id_board, b.name, b.id_profile, b.member_groups, IFNULL(mods.id_member, 0) AS is_mod
  1808. FROM {db_prefix}boards AS b
  1809. LEFT JOIN {db_prefix}moderators AS mods ON (mods.id_board = b.id_board AND mods.id_member = {int:current_member})
  1810. WHERE {query_see_board}',
  1811. array(
  1812. 'current_member' => $memID,
  1813. )
  1814. );
  1815. $context['boards'] = array();
  1816. $context['no_access_boards'] = array();
  1817. while ($row = $smcFunc['db_fetch_assoc']($request))
  1818. {
  1819. if (count(array_intersect($curGroups, explode(',', $row['member_groups']))) === 0 && !$row['is_mod'])
  1820. $context['no_access_boards'][] = array(
  1821. 'id' => $row['id_board'],
  1822. 'name' => $row['name'],
  1823. 'is_last' => false,
  1824. );
  1825. elseif ($row['id_profile'] != 1 || $row['is_mod'])
  1826. $context['boards'][$row['id_board']] = array(
  1827. 'id' => $row['id_board'],
  1828. 'name' => $row['name'],
  1829. 'selected' => $board == $row['id_board'],
  1830. 'profile' => $row['id_profile'],
  1831. 'profile_name' => $context['profiles'][$row['id_profile']]['name'],
  1832. );
  1833. }
  1834. $smcFunc['db_free_result']($request);
  1835. if (!empty($context['no_access_boards']))
  1836. $context['no_access_boards'][count($context['no_access_boards']) - 1]['is_last'] = true;
  1837. $context['member']['permissions'] = array(
  1838. 'general' => array(),
  1839. 'board' => array()
  1840. );
  1841. // If you're an admin we know you can do everything, we might as well leave.
  1842. $context['member']['has_all_permissions'] = in_array(1, $curGroups);
  1843. if ($context['member']['has_all_permissions'])
  1844. return;
  1845. $denied = array();
  1846. // Get all general permissions.
  1847. $result = $smcFunc['db_query']('', '
  1848. SELECT p.permission, p.add_deny, mg.group_name, p.id_group
  1849. FROM {db_prefix}permissions AS p
  1850. LEFT JOIN {db_prefix}membergroups AS mg ON (mg.id_group = p.id_group)
  1851. WHERE p.id_group IN ({array_int:group_list})
  1852. 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',
  1853. array(
  1854. 'group_list' => $curGroups,
  1855. 'newbie_group' => 4,
  1856. )
  1857. );
  1858. while ($row = $smcFunc['db_fetch_assoc']($result))
  1859. {
  1860. // We don't know about this permission, it doesn't exist :P.
  1861. if (!isset($txt['permissionname_' . $row['permission']]))
  1862. continue;
  1863. if (empty($row['add_deny']))
  1864. $denied[] = $row['permission'];
  1865. // Permissions that end with _own or _any consist of two parts.
  1866. if (in_array(substr($row['permission'], -4), array('_own', '_any')) && isset($txt['permissionname_' . substr($row['permission'], 0, -4)]))
  1867. $name = $txt['permissionname_' . substr($row['permission'], 0, -4)] . ' - ' . $txt['permissionname_' . $row['permission']];
  1868. else
  1869. $name = $txt['permissionname_' . $row['permission']];
  1870. // Add this permission if it doesn't exist yet.
  1871. if (!isset($context['member']['permissions']['general'][$row['permission']]))
  1872. $context['member']['permissions']['general'][$row['permission']] = array(
  1873. 'id' => $row['permission'],
  1874. 'groups' => array(
  1875. 'allowed' => array(),
  1876. 'denied' => array()
  1877. ),
  1878. 'name' => $name,
  1879. 'is_denied' => false,
  1880. 'is_global' => true,
  1881. );
  1882. // Add the membergroup to either the denied or the allowed groups.
  1883. $context['member']['permissions']['general'][$row['permission']]['groups'][empty($row['add_deny']) ? 'denied' : 'allowed'][] = $row['id_group'] == 0 ? $txt['membergroups_members'] : $row['group_name'];
  1884. // Once denied is always denied.
  1885. $context['member']['permissions']['general'][$row['permission']]['is_denied'] |= empty($row['add_deny']);
  1886. }
  1887. $smcFunc['db_free_result']($result);
  1888. $request = $smcFunc['db_query']('', '
  1889. SELECT
  1890. bp.add_deny, bp.permission, bp.id_group, mg.group_name' . (empty($board) ? '' : ',
  1891. b.id_profile, CASE WHEN mods.id_member IS NULL THEN 0 ELSE 1 END AS is_moderator') . '
  1892. FROM {db_prefix}board_permissions AS bp' . (empty($board) ? '' : '
  1893. INNER JOIN {db_prefix}boards AS b ON (b.id_board = {int:current_board})
  1894. LEFT JOIN {db_prefix}moderators AS mods ON (mods.id_board = b.id_board AND mods.id_member = {int:current_member})') . '
  1895. LEFT JOIN {db_prefix}membergroups AS mg ON (mg.id_group = bp.id_group)
  1896. WHERE bp.id_profile = {raw:current_profile}
  1897. AND bp.id_group IN ({array_int:group_list}' . (empty($board) ? ')' : ', {int:moderator_group})
  1898. AND (mods.id_member IS NOT NULL OR bp.id_group != {int:moderator_group})'),
  1899. array(
  1900. 'current_board' => $board,
  1901. 'group_list' => $curGroups,
  1902. 'current_member' => $memID,
  1903. 'current_profile' => empty($board) ? '1' : 'b.id_profile',
  1904. 'moderator_group' => 3,
  1905. )
  1906. );
  1907. while ($row = $smcFunc['db_fetch_assoc']($request))
  1908. {
  1909. // We don't know about this permission, it doesn't exist :P.
  1910. if (!isset($txt['permissionname_' . $row['permission']]))
  1911. continue;
  1912. // The name of the permission using the format 'permission name' - 'own/any topic/event/etc.'.
  1913. if (in_array(substr($row['permission'], -4), array('_own', '_any')) && isset($txt['permissionname_' . substr($row['permission'], 0, -4)]))
  1914. $name = $txt['permissionname_' . substr($row['permission'], 0, -4)] . ' - ' . $txt['permissionname_' . $row['permission']];
  1915. else
  1916. $name = $txt['permissionname_' . $row['permission']];
  1917. // Create the structure for this permission.
  1918. if (!isset($context['member']['permissions']['board'][$row['permission']]))
  1919. $context['member']['permissions']['board'][$row['permission']] = array(
  1920. 'id' => $row['permission'],
  1921. 'groups' => array(
  1922. 'allowed' => array(),
  1923. 'denied' => array()
  1924. ),
  1925. 'name' => $name,
  1926. 'is_denied' => false,
  1927. 'is_global' => empty($board),
  1928. );
  1929. $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'];
  1930. $context['member']['permissions']['board'][$row['permission']]['is_denied'] |= empty($row['add_deny']);
  1931. }
  1932. $smcFunc['db_free_result']($request);
  1933. }
  1934. /**
  1935. * View a members warnings?
  1936. *
  1937. * @param int $memID id_member
  1938. */
  1939. function viewWarning($memID)
  1940. {
  1941. global $modSettings, $context, $sourcedir, $txt, $scripturl;
  1942. // Firstly, can we actually even be here?
  1943. if (!allowedTo('issue_warning') && (empty($modSettings['warning_show']) || ($modSettings['warning_show'] == 1 && !$context['user']['is_owner'])))
  1944. fatal_lang_error('no_access', false);
  1945. // Make sure things which are disabled stay disabled.
  1946. $modSettings['warning_watch'] = !empty($modSettings['warning_watch']) ? $modSettings['warning_watch'] : 110;
  1947. $modSettings['warning_moderate'] = !empty($modSettings['warning_moderate']) && !empty($modSettings['postmod_active']) ? $modSettings['warning_moderate'] : 110;
  1948. $modSettings['warning_mute'] = !empty($modSettings['warning_mute']) ? $modSettings['warning_mute'] : 110;
  1949. // Let's use a generic list to get all the current warnings, and use the issue warnings grab-a-granny thing.
  1950. require_once($sourcedir . '/Subs-List.php');
  1951. require_once($sourcedir . '/Profile-Actions.php');
  1952. $listOptions = array(
  1953. 'id' => 'view_warnings',
  1954. 'title' => $txt['profile_viewwarning_previous_warnings'],
  1955. 'items_per_page' => $modSettings['defaultMaxMessages'],
  1956. 'no_items_label' => $txt['profile_viewwarning_no_warnings'],
  1957. 'base_href' => $scripturl . '?action=profile;area=viewwarning;sa=user;u=' . $memID,
  1958. 'default_sort_col' => 'log_time',
  1959. 'get_items' => array(
  1960. 'function' => 'list_getUserWarnings',
  1961. 'params' => array(
  1962. $memID,
  1963. ),
  1964. ),
  1965. 'get_count' => array(
  1966. 'function' => 'list_getUserWarningCount',
  1967. 'params' => array(
  1968. $memID,
  1969. ),
  1970. ),
  1971. 'columns' => array(
  1972. 'log_time' => array(
  1973. 'header' => array(
  1974. 'value' => $txt['profile_warning_previous_time'],
  1975. ),
  1976. 'data' => array(
  1977. 'db' => 'time',
  1978. ),
  1979. 'sort' => array(
  1980. 'default' => 'lc.log_time DESC',
  1981. 'reverse' => 'lc.log_time',
  1982. ),
  1983. ),
  1984. 'reason' => array(
  1985. 'header' => array(
  1986. 'value' => $txt['profile_warning_previous_reason'],
  1987. 'style' => 'width: 50%',
  1988. ),
  1989. 'data' => array(
  1990. 'db' => 'reason',
  1991. ),
  1992. ),
  1993. 'level' => array(
  1994. 'header' => array(
  1995. 'value' => $txt['profile_warning_previous_level'],
  1996. ),
  1997. 'data' => array(
  1998. 'db' => 'counter',
  1999. ),
  2000. 'sort' => array(
  2001. 'default' => 'lc.counter DESC',
  2002. 'reverse' => 'lc.counter',
  2003. ),
  2004. ),
  2005. ),
  2006. 'additional_rows' => array(
  2007. array(
  2008. 'position' => 'after_title',
  2009. 'value' => $txt['profile_viewwarning_desc'],
  2010. 'class' => 'smalltext',
  2011. 'style' => 'padding: 2ex;',
  2012. ),
  2013. ),
  2014. );
  2015. // Create the list for viewing.
  2016. require_once($sourcedir . '/Subs-List.php');
  2017. createList($listOptions);
  2018. // Create some common text bits for the template.
  2019. $context['level_effects'] = array(
  2020. 0 => '',
  2021. $modSettings['warning_watch'] => $txt['profile_warning_effect_own_watched'],
  2022. $modSettings['warning_moderate'] => $txt['profile_warning_effect_own_moderated'],
  2023. $modSettings['warning_mute'] => $txt['profile_warning_effect_own_muted'],
  2024. );
  2025. $context['current_level'] = 0;
  2026. foreach ($context['level_effects'] as $limit => $dummy)
  2027. if ($context['member']['warning'] >= $limit)
  2028. $context['current_level'] = $limit;
  2029. }