Profile-View.php 70 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224
  1. <?php
  2. /**
  3. * Simple Machines Forum (SMF)
  4. *
  5. * @package SMF
  6. * @author Simple Machines http://www.simplemachines.org
  7. * @copyright 2011 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. ),
  547. ),
  548. );
  549. // Create the request list.
  550. createList($listOptions);
  551. }
  552. function list_getAttachments($start, $items_per_page, $sort, $boardsAllowed, $memID)
  553. {
  554. global $smcFunc, $board, $modSettings, $context;
  555. // Retrieve some attachments.
  556. $request = $smcFunc['db_query']('', '
  557. SELECT a.id_attach, a.id_msg, a.filename, a.downloads, a.approved, m.id_msg, m.id_topic,
  558. m.id_board, m.poster_time, m.subject, b.name
  559. FROM {db_prefix}attachments AS a
  560. INNER JOIN {db_prefix}messages AS m ON (m.id_msg = a.id_msg)
  561. INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board AND {query_see_board})
  562. WHERE a.attachment_type = {int:attachment_type}
  563. AND a.id_msg != {int:no_message}
  564. AND m.id_member = {int:current_member}' . (!empty($board) ? '
  565. AND b.id_board = {int:board}' : '') . (!in_array(0, $boardsAllowed) ? '
  566. AND b.id_board IN ({array_int:boards_list})' : '') . (!$modSettings['postmod_active'] || $context['user']['is_owner'] ? '' : '
  567. AND m.approved = {int:is_approved}') . '
  568. ORDER BY {raw:sort}
  569. LIMIT {int:offset}, {int:limit}',
  570. array(
  571. 'boards_list' => $boardsAllowed,
  572. 'attachment_type' => 0,
  573. 'no_message' => 0,
  574. 'current_member' => $memID,
  575. 'is_approved' => 1,
  576. 'board' => $board,
  577. 'sort' => $sort,
  578. 'offset' => $start,
  579. 'limit' => $items_per_page,
  580. )
  581. );
  582. $attachments = array();
  583. while ($row = $smcFunc['db_fetch_assoc']($request))
  584. $attachments[] = array(
  585. 'id' => $row['id_attach'],
  586. 'filename' => $row['filename'],
  587. 'downloads' => $row['downloads'],
  588. 'subject' => censorText($row['subject']),
  589. 'posted' => $row['poster_time'],
  590. 'msg' => $row['id_msg'],
  591. 'topic' => $row['id_topic'],
  592. 'board' => $row['id_board'],
  593. 'board_name' => $row['name'],
  594. 'approved' => $row['approved'],
  595. );
  596. $smcFunc['db_free_result']($request);
  597. return $attachments;
  598. }
  599. function list_getNumAttachments($boardsAllowed, $memID)
  600. {
  601. global $board, $smcFunc, $modSettings, $context;
  602. // Get the total number of attachments they have posted.
  603. $request = $smcFunc['db_query']('', '
  604. SELECT COUNT(*)
  605. FROM {db_prefix}attachments AS a
  606. INNER JOIN {db_prefix}messages AS m ON (m.id_msg = a.id_msg)
  607. INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board AND {query_see_board})
  608. WHERE a.attachment_type = {int:attachment_type}
  609. AND a.id_msg != {int:no_message}
  610. AND m.id_member = {int:current_member}' . (!empty($board) ? '
  611. AND b.id_board = {int:board}' : '') . (!in_array(0, $boardsAllowed) ? '
  612. AND b.id_board IN ({array_int:boards_list})' : '') . (!$modSettings['postmod_active'] || $context['user']['is_owner'] ? '' : '
  613. AND m.approved = {int:is_approved}'),
  614. array(
  615. 'boards_list' => $boardsAllowed,
  616. 'attachment_type' => 0,
  617. 'no_message' => 0,
  618. 'current_member' => $memID,
  619. 'is_approved' => 1,
  620. 'board' => $board,
  621. )
  622. );
  623. list ($attachCount) = $smcFunc['db_fetch_row']($request);
  624. $smcFunc['db_free_result']($request);
  625. return $attachCount;
  626. }
  627. /**
  628. * Gets the user stats for display
  629. *
  630. * @param int $memID id_member
  631. */
  632. function statPanel($memID)
  633. {
  634. global $txt, $scripturl, $context, $user_profile, $user_info, $modSettings, $smcFunc;
  635. $context['page_title'] = $txt['statPanel_showStats'] . ' ' . $user_profile[$memID]['real_name'];
  636. // Is the load average too high to allow searching just now?
  637. if (!empty($context['load_average']) && !empty($modSettings['loadavg_userstats']) && $context['load_average'] >= $modSettings['loadavg_userstats'])
  638. fatal_lang_error('loadavg_userstats_disabled', false);
  639. // General user statistics.
  640. $timeDays = floor($user_profile[$memID]['total_time_logged_in'] / 86400);
  641. $timeHours = floor(($user_profile[$memID]['total_time_logged_in'] % 86400) / 3600);
  642. $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'];
  643. $context['num_posts'] = comma_format($user_profile[$memID]['posts']);
  644. // Number of topics started.
  645. $result = $smcFunc['db_query']('', '
  646. SELECT COUNT(*)
  647. FROM {db_prefix}topics
  648. WHERE id_member_started = {int:current_member}' . (!empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0 ? '
  649. AND id_board != {int:recycle_board}' : ''),
  650. array(
  651. 'current_member' => $memID,
  652. 'recycle_board' => $modSettings['recycle_board'],
  653. )
  654. );
  655. list ($context['num_topics']) = $smcFunc['db_fetch_row']($result);
  656. $smcFunc['db_free_result']($result);
  657. // Number polls started.
  658. $result = $smcFunc['db_query']('', '
  659. SELECT COUNT(*)
  660. FROM {db_prefix}topics
  661. WHERE id_member_started = {int:current_member}' . (!empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0 ? '
  662. AND id_board != {int:recycle_board}' : '') . '
  663. AND id_poll != {int:no_poll}',
  664. array(
  665. 'current_member' => $memID,
  666. 'recycle_board' => $modSettings['recycle_board'],
  667. 'no_poll' => 0,
  668. )
  669. );
  670. list ($context['num_polls']) = $smcFunc['db_fetch_row']($result);
  671. $smcFunc['db_free_result']($result);
  672. // Number polls voted in.
  673. $result = $smcFunc['db_query']('distinct_poll_votes', '
  674. SELECT COUNT(DISTINCT id_poll)
  675. FROM {db_prefix}log_polls
  676. WHERE id_member = {int:current_member}',
  677. array(
  678. 'current_member' => $memID,
  679. )
  680. );
  681. list ($context['num_votes']) = $smcFunc['db_fetch_row']($result);
  682. $smcFunc['db_free_result']($result);
  683. // Format the numbers...
  684. $context['num_topics'] = comma_format($context['num_topics']);
  685. $context['num_polls'] = comma_format($context['num_polls']);
  686. $context['num_votes'] = comma_format($context['num_votes']);
  687. // Grab the board this member posted in most often.
  688. $result = $smcFunc['db_query']('', '
  689. SELECT
  690. b.id_board, MAX(b.name) AS name, MAX(b.num_posts) AS num_posts, COUNT(*) AS message_count
  691. FROM {db_prefix}messages AS m
  692. INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board)
  693. WHERE m.id_member = {int:current_member}
  694. AND b.count_posts = {int:count_enabled}
  695. AND {query_see_board}
  696. GROUP BY b.id_board
  697. ORDER BY message_count DESC
  698. LIMIT 10',
  699. array(
  700. 'current_member' => $memID,
  701. 'count_enabled' => 0,
  702. )
  703. );
  704. $context['popular_boards'] = array();
  705. while ($row = $smcFunc['db_fetch_assoc']($result))
  706. {
  707. $context['popular_boards'][$row['id_board']] = array(
  708. 'id' => $row['id_board'],
  709. 'posts' => $row['message_count'],
  710. 'href' => $scripturl . '?board=' . $row['id_board'] . '.0',
  711. 'link' => '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['name'] . '</a>',
  712. 'posts_percent' => $user_profile[$memID]['posts'] == 0 ? 0 : ($row['message_count'] * 100) / $user_profile[$memID]['posts'],
  713. 'total_posts' => $row['num_posts'],
  714. 'total_posts_member' => $user_profile[$memID]['posts'],
  715. );
  716. }
  717. $smcFunc['db_free_result']($result);
  718. // Now get the 10 boards this user has most often participated in.
  719. $result = $smcFunc['db_query']('profile_board_stats', '
  720. SELECT
  721. b.id_board, MAX(b.name) AS name, b.num_posts, COUNT(*) AS message_count,
  722. CASE WHEN COUNT(*) > MAX(b.num_posts) THEN 1 ELSE COUNT(*) / MAX(b.num_posts) END * 100 AS percentage
  723. FROM {db_prefix}messages AS m
  724. INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board)
  725. WHERE m.id_member = {int:current_member}
  726. AND {query_see_board}
  727. GROUP BY b.id_board, b.num_posts
  728. ORDER BY percentage DESC
  729. LIMIT 10',
  730. array(
  731. 'current_member' => $memID,
  732. )
  733. );
  734. $context['board_activity'] = array();
  735. while ($row = $smcFunc['db_fetch_assoc']($result))
  736. {
  737. $context['board_activity'][$row['id_board']] = array(
  738. 'id' => $row['id_board'],
  739. 'posts' => $row['message_count'],
  740. 'href' => $scripturl . '?board=' . $row['id_board'] . '.0',
  741. 'link' => '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['name'] . '</a>',
  742. 'percent' => comma_format((float) $row['percentage'], 2),
  743. 'posts_percent' => (float) $row['percentage'],
  744. 'total_posts' => $row['num_posts'],
  745. );
  746. }
  747. $smcFunc['db_free_result']($result);
  748. // Posting activity by time.
  749. $result = $smcFunc['db_query']('user_activity_by_time', '
  750. SELECT
  751. HOUR(FROM_UNIXTIME(poster_time + {int:time_offset})) AS hour,
  752. COUNT(*) AS post_count
  753. FROM {db_prefix}messages
  754. WHERE id_member = {int:current_member}' . ($modSettings['totalMessages'] > 100000 ? '
  755. AND id_topic > {int:top_ten_thousand_topics}' : '') . '
  756. GROUP BY hour',
  757. array(
  758. 'current_member' => $memID,
  759. 'top_ten_thousand_topics' => $modSettings['totalTopics'] - 10000,
  760. 'time_offset' => (($user_info['time_offset'] + $modSettings['time_offset']) * 3600),
  761. )
  762. );
  763. $maxPosts = $realPosts = 0;
  764. $context['posts_by_time'] = array();
  765. while ($row = $smcFunc['db_fetch_assoc']($result))
  766. {
  767. // Cast as an integer to remove the leading 0.
  768. $row['hour'] = (int) $row['hour'];
  769. $maxPosts = max($row['post_count'], $maxPosts);
  770. $realPosts += $row['post_count'];
  771. $context['posts_by_time'][$row['hour']] = array(
  772. 'hour' => $row['hour'],
  773. 'hour_format' => stripos($user_info['time_format'], '%p') === false ? $row['hour'] : date('g a', mktime($row['hour'])),
  774. 'posts' => $row['post_count'],
  775. 'posts_percent' => 0,
  776. 'is_last' => $row['hour'] == 23,
  777. );
  778. }
  779. $smcFunc['db_free_result']($result);
  780. if ($maxPosts > 0)
  781. for ($hour = 0; $hour < 24; $hour++)
  782. {
  783. if (!isset($context['posts_by_time'][$hour]))
  784. $context['posts_by_time'][$hour] = array(
  785. 'hour' => $hour,
  786. 'hour_format' => stripos($user_info['time_format'], '%p') === false ? $hour : date('g a', mktime($hour)),
  787. 'posts' => 0,
  788. 'posts_percent' => 0,
  789. 'relative_percent' => 0,
  790. 'is_last' => $hour == 23,
  791. );
  792. else
  793. {
  794. $context['posts_by_time'][$hour]['posts_percent'] = round(($context['posts_by_time'][$hour]['posts'] * 100) / $realPosts);
  795. $context['posts_by_time'][$hour]['relative_percent'] = round(($context['posts_by_time'][$hour]['posts'] * 100) / $maxPosts);
  796. }
  797. }
  798. // Put it in the right order.
  799. ksort($context['posts_by_time']);
  800. // Custom stats (just add a template_layer to add it to the template!)
  801. call_integration_hook('integrate_profile_stats', array($memID));
  802. }
  803. /**
  804. * @todo needs a description
  805. *
  806. * @param int $memID id_member
  807. */
  808. function tracking($memID)
  809. {
  810. global $sourcedir, $context, $txt, $scripturl, $modSettings, $user_profile;
  811. $subActions = array(
  812. 'activity' => array('trackActivity', $txt['trackActivity']),
  813. 'ip' => array('TrackIP', $txt['trackIP']),
  814. 'edits' => array('trackEdits', $txt['trackEdits']),
  815. 'logins' => array('TrackLogins', $txt['trackLogins']),
  816. );
  817. $context['tracking_area'] = isset($_GET['sa']) && isset($subActions[$_GET['sa']]) ? $_GET['sa'] : 'activity';
  818. // @todo what is $types? it is never set so this will never be true
  819. if (isset($types[$context['tracking_area']][1]))
  820. require_once($sourcedir . '/' . $types[$context['tracking_area']][1]);
  821. // Create the tabs for the template.
  822. $context[$context['profile_menu_name']]['tab_data'] = array(
  823. 'title' => $txt['tracking'],
  824. 'description' => $txt['tracking_description'],
  825. 'icon' => 'profile_sm.png',
  826. 'tabs' => array(
  827. 'activity' => array(),
  828. 'ip' => array(),
  829. 'edits' => array(),
  830. ),
  831. );
  832. // Moderation must be on to track edits.
  833. if (empty($modSettings['modlog_enabled']))
  834. unset($context[$context['profile_menu_name']]['tab_data']['edits']);
  835. // Set a page title.
  836. $context['page_title'] = $txt['trackUser'] . ' - ' . $subActions[$context['tracking_area']][1] . ' - ' . $user_profile[$memID]['real_name'];
  837. // Pass on to the actual function.
  838. $context['sub_template'] = $subActions[$context['tracking_area']][0];
  839. $subActions[$context['tracking_area']][0]($memID);
  840. }
  841. /**
  842. * @todo needs a description
  843. *
  844. * @param int $memID id_member
  845. */
  846. function trackActivity($memID)
  847. {
  848. global $scripturl, $txt, $modSettings, $sourcedir;
  849. global $user_profile, $context, $smcFunc;
  850. // Verify if the user has sufficient permissions.
  851. isAllowedTo('moderate_forum');
  852. $context['last_ip'] = $user_profile[$memID]['member_ip'];
  853. if ($context['last_ip'] != $user_profile[$memID]['member_ip2'])
  854. $context['last_ip2'] = $user_profile[$memID]['member_ip2'];
  855. $context['member']['name'] = $user_profile[$memID]['real_name'];
  856. // Set the options for the list component.
  857. $listOptions = array(
  858. 'id' => 'track_user_list',
  859. 'title' => $txt['errors_by'] . ' ' . $context['member']['name'],
  860. 'items_per_page' => $modSettings['defaultMaxMessages'],
  861. 'no_items_label' => $txt['no_errors_from_user'],
  862. 'base_href' => $scripturl . '?action=profile;area=tracking;sa=user;u=' . $memID,
  863. 'default_sort_col' => 'date',
  864. 'get_items' => array(
  865. 'function' => 'list_getUserErrors',
  866. 'params' => array(
  867. 'le.id_member = {int:current_member}',
  868. array('current_member' => $memID),
  869. ),
  870. ),
  871. 'get_count' => array(
  872. 'function' => 'list_getUserErrorCount',
  873. 'params' => array(
  874. 'id_member = {int:current_member}',
  875. array('current_member' => $memID),
  876. ),
  877. ),
  878. 'columns' => array(
  879. 'ip_address' => array(
  880. 'header' => array(
  881. 'value' => $txt['ip_address'],
  882. ),
  883. 'data' => array(
  884. 'sprintf' => array(
  885. 'format' => '<a href="' . $scripturl . '?action=profile;area=tracking;sa=ip;searchip=%1$s;u=' . $memID. '">%1$s</a>',
  886. 'params' => array(
  887. 'ip' => false,
  888. ),
  889. ),
  890. ),
  891. 'sort' => array(
  892. 'default' => 'le.ip',
  893. 'reverse' => 'le.ip DESC',
  894. ),
  895. ),
  896. 'message' => array(
  897. 'header' => array(
  898. 'value' => $txt['message'],
  899. ),
  900. 'data' => array(
  901. 'sprintf' => array(
  902. 'format' => '%1$s<br /><a href="%2$s">%2$s</a>',
  903. 'params' => array(
  904. 'message' => false,
  905. 'url' => false,
  906. ),
  907. ),
  908. ),
  909. ),
  910. 'date' => array(
  911. 'header' => array(
  912. 'value' => $txt['date'],
  913. ),
  914. 'data' => array(
  915. 'db' => 'time',
  916. ),
  917. 'sort' => array(
  918. 'default' => 'le.id_error DESC',
  919. 'reverse' => 'le.id_error',
  920. ),
  921. ),
  922. ),
  923. 'additional_rows' => array(
  924. array(
  925. 'position' => 'after_title',
  926. 'value' => $txt['errors_desc'],
  927. 'class' => 'windowbg2',
  928. 'style' => 'padding: 1ex 2ex;',
  929. ),
  930. ),
  931. );
  932. // Create the list for viewing.
  933. require_once($sourcedir . '/Subs-List.php');
  934. createList($listOptions);
  935. // @todo cache this
  936. // If this is a big forum, or a large posting user, let's limit the search.
  937. if ($modSettings['totalMessages'] > 50000 && $user_profile[$memID]['posts'] > 500)
  938. {
  939. $request = $smcFunc['db_query']('', '
  940. SELECT MAX(id_msg)
  941. FROM {db_prefix}messages AS m
  942. WHERE m.id_member = {int:current_member}',
  943. array(
  944. 'current_member' => $memID,
  945. )
  946. );
  947. list ($max_msg_member) = $smcFunc['db_fetch_row']($request);
  948. $smcFunc['db_free_result']($request);
  949. // There's no point worrying ourselves with messages made yonks ago, just get recent ones!
  950. $min_msg_member = max(0, $max_msg_member - $user_profile[$memID]['posts'] * 3);
  951. }
  952. // Default to at least the ones we know about.
  953. $ips = array(
  954. $user_profile[$memID]['member_ip'],
  955. $user_profile[$memID]['member_ip2'],
  956. );
  957. // @todo cache this
  958. // Get all IP addresses this user has used for his messages.
  959. $request = $smcFunc['db_query']('', '
  960. SELECT poster_ip
  961. FROM {db_prefix}messages
  962. WHERE id_member = {int:current_member}
  963. ' . (isset($min_msg_member) ? '
  964. AND id_msg >= {int:min_msg_member} AND id_msg <= {int:max_msg_member}' : '') . '
  965. GROUP BY poster_ip',
  966. array(
  967. 'current_member' => $memID,
  968. 'min_msg_member' => !empty($min_msg_member) ? $min_msg_member : 0,
  969. 'max_msg_member' => !empty($max_msg_member) ? $max_msg_member : 0,
  970. )
  971. );
  972. $context['ips'] = array();
  973. while ($row = $smcFunc['db_fetch_assoc']($request))
  974. {
  975. $context['ips'][] = '<a href="' . $scripturl . '?action=profile;area=tracking;sa=ip;searchip=' . $row['poster_ip'] . ';u=' . $memID . '">' . $row['poster_ip'] . '</a>';
  976. $ips[] = $row['poster_ip'];
  977. }
  978. $smcFunc['db_free_result']($request);
  979. // Now also get the IP addresses from the error messages.
  980. $request = $smcFunc['db_query']('', '
  981. SELECT COUNT(*) AS error_count, ip
  982. FROM {db_prefix}log_errors
  983. WHERE id_member = {int:current_member}
  984. GROUP BY ip',
  985. array(
  986. 'current_member' => $memID,
  987. )
  988. );
  989. $context['error_ips'] = array();
  990. while ($row = $smcFunc['db_fetch_assoc']($request))
  991. {
  992. $context['error_ips'][] = '<a href="' . $scripturl . '?action=profile;area=tracking;sa=ip;searchip=' . $row['ip'] . ';u=' . $memID . '">' . $row['ip'] . '</a>';
  993. $ips[] = $row['ip'];
  994. }
  995. $smcFunc['db_free_result']($request);
  996. // Find other users that might use the same IP.
  997. $ips = array_unique($ips);
  998. $context['members_in_range'] = array();
  999. if (!empty($ips))
  1000. {
  1001. // Get member ID's which are in messages...
  1002. $request = $smcFunc['db_query']('', '
  1003. SELECT mem.id_member
  1004. FROM {db_prefix}messages AS m
  1005. INNER JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member)
  1006. WHERE m.poster_ip IN ({array_string:ip_list})
  1007. GROUP BY mem.id_member
  1008. HAVING mem.id_member != {int:current_member}',
  1009. array(
  1010. 'current_member' => $memID,
  1011. 'ip_list' => $ips,
  1012. )
  1013. );
  1014. $message_members = array();
  1015. while ($row = $smcFunc['db_fetch_assoc']($request))
  1016. $message_members[] = $row['id_member'];
  1017. $smcFunc['db_free_result']($request);
  1018. // Fetch their names, cause of the GROUP BY doesn't like giving us that normally.
  1019. if (!empty($message_members))
  1020. {
  1021. $request = $smcFunc['db_query']('', '
  1022. SELECT id_member, real_name
  1023. FROM {db_prefix}members
  1024. WHERE id_member IN ({array_int:message_members})',
  1025. array(
  1026. 'message_members' => $message_members,
  1027. 'ip_list' => $ips,
  1028. )
  1029. );
  1030. while ($row = $smcFunc['db_fetch_assoc']($request))
  1031. $context['members_in_range'][$row['id_member']] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>';
  1032. $smcFunc['db_free_result']($request);
  1033. }
  1034. $request = $smcFunc['db_query']('', '
  1035. SELECT id_member, real_name
  1036. FROM {db_prefix}members
  1037. WHERE id_member != {int:current_member}
  1038. AND member_ip IN ({array_string:ip_list})',
  1039. array(
  1040. 'current_member' => $memID,
  1041. 'ip_list' => $ips,
  1042. )
  1043. );
  1044. while ($row = $smcFunc['db_fetch_assoc']($request))
  1045. $context['members_in_range'][$row['id_member']] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>';
  1046. $smcFunc['db_free_result']($request);
  1047. }
  1048. }
  1049. /**
  1050. * Get the number of user errors
  1051. *
  1052. * @param string $where
  1053. * @param array $where_vars = array()
  1054. * @return string number of user errors
  1055. */
  1056. function list_getUserErrorCount($where, $where_vars = array())
  1057. {
  1058. global $smcFunc;
  1059. $request = $smcFunc['db_query']('', '
  1060. SELECT COUNT(*) AS error_count
  1061. FROM {db_prefix}log_errors
  1062. WHERE ' . $where,
  1063. $where_vars
  1064. );
  1065. list ($count) = $smcFunc['db_fetch_row']($request);
  1066. $smcFunc['db_free_result']($request);
  1067. // @todo cast this to an integer
  1068. return $count;
  1069. }
  1070. /**
  1071. * @todo needs a description
  1072. *
  1073. * @param int $start
  1074. * @param int $items_per_page
  1075. * @param string $sort
  1076. * @param string $where
  1077. * @param array $where_vars
  1078. * @return array error messages
  1079. */
  1080. function list_getUserErrors($start, $items_per_page, $sort, $where, $where_vars = array())
  1081. {
  1082. global $smcFunc, $txt, $scripturl;
  1083. // Get a list of error messages from this ip (range).
  1084. $request = $smcFunc['db_query']('', '
  1085. SELECT
  1086. le.log_time, le.ip, le.url, le.message, IFNULL(mem.id_member, 0) AS id_member,
  1087. IFNULL(mem.real_name, {string:guest_title}) AS display_name, mem.member_name
  1088. FROM {db_prefix}log_errors AS le
  1089. LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = le.id_member)
  1090. WHERE ' . $where . '
  1091. ORDER BY ' . $sort . '
  1092. LIMIT ' . $start . ', ' . $items_per_page,
  1093. array_merge($where_vars, array(
  1094. 'guest_title' => $txt['guest_title'],
  1095. ))
  1096. );
  1097. $error_messages = array();
  1098. while ($row = $smcFunc['db_fetch_assoc']($request))
  1099. $error_messages[] = array(
  1100. 'ip' => $row['ip'],
  1101. 'member_link' => $row['id_member'] > 0 ? '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['display_name'] . '</a>' : $row['display_name'],
  1102. 'message' => strtr($row['message'], array('&lt;span class=&quot;remove&quot;&gt;' => '', '&lt;/span&gt;' => '')),
  1103. 'url' => $row['url'],
  1104. 'time' => timeformat($row['log_time']),
  1105. 'timestamp' => forum_time(true, $row['log_time']),
  1106. );
  1107. $smcFunc['db_free_result']($request);
  1108. return $error_messages;
  1109. }
  1110. /**
  1111. * @todo needs a description
  1112. *
  1113. * @param string $where
  1114. * @param array $where_vars
  1115. * @return string count of messages matching the IP
  1116. */
  1117. function list_getIPMessageCount($where, $where_vars = array())
  1118. {
  1119. global $smcFunc;
  1120. $request = $smcFunc['db_query']('', '
  1121. SELECT COUNT(*) AS message_count
  1122. FROM {db_prefix}messages AS m
  1123. INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board)
  1124. WHERE {query_see_board} AND ' . $where,
  1125. $where_vars
  1126. );
  1127. list ($count) = $smcFunc['db_fetch_row']($request);
  1128. $smcFunc['db_free_result']($request);
  1129. // @todo cast to integer
  1130. return $count;
  1131. }
  1132. /**
  1133. * @todo needs a description
  1134. *
  1135. * @param int $start
  1136. * @param int $items_per_page
  1137. * @param string $sort
  1138. * @param string $where
  1139. * @param array $where_vars
  1140. * @return array an array of messages
  1141. */
  1142. function list_getIPMessages($start, $items_per_page, $sort, $where, $where_vars = array())
  1143. {
  1144. global $smcFunc, $txt, $scripturl;
  1145. // Get all the messages fitting this where clause.
  1146. // @todo SLOW This query is using a filesort.
  1147. $request = $smcFunc['db_query']('', '
  1148. SELECT
  1149. m.id_msg, m.poster_ip, IFNULL(mem.real_name, m.poster_name) AS display_name, mem.id_member,
  1150. m.subject, m.poster_time, m.id_topic, m.id_board
  1151. FROM {db_prefix}messages AS m
  1152. INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board)
  1153. LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member)
  1154. WHERE {query_see_board} AND ' . $where . '
  1155. ORDER BY ' . $sort . '
  1156. LIMIT ' . $start . ', ' . $items_per_page,
  1157. array_merge($where_vars, array(
  1158. ))
  1159. );
  1160. $messages = array();
  1161. while ($row = $smcFunc['db_fetch_assoc']($request))
  1162. $messages[] = array(
  1163. 'ip' => $row['poster_ip'],
  1164. 'member_link' => empty($row['id_member']) ? $row['display_name'] : '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['display_name'] . '</a>',
  1165. 'board' => array(
  1166. 'id' => $row['id_board'],
  1167. 'href' => $scripturl . '?board=' . $row['id_board']
  1168. ),
  1169. 'topic' => $row['id_topic'],
  1170. 'id' => $row['id_msg'],
  1171. 'subject' => $row['subject'],
  1172. 'time' => timeformat($row['poster_time']),
  1173. 'timestamp' => forum_time(true, $row['poster_time'])
  1174. );
  1175. $smcFunc['db_free_result']($request);
  1176. return $messages;
  1177. }
  1178. /**
  1179. * @todo needs a description
  1180. *
  1181. * @param int $memID = 0 id_member
  1182. */
  1183. function TrackIP($memID = 0)
  1184. {
  1185. global $user_profile, $scripturl, $txt, $user_info, $modSettings, $sourcedir;
  1186. global $context, $smcFunc;
  1187. // Can the user do this?
  1188. isAllowedTo('moderate_forum');
  1189. if ($memID == 0)
  1190. {
  1191. $context['ip'] = $user_info['ip'];
  1192. loadTemplate('Profile');
  1193. loadLanguage('Profile');
  1194. $context['sub_template'] = 'trackIP';
  1195. $context['page_title'] = $txt['profile'];
  1196. $context['base_url'] = $scripturl . '?action=trackip';
  1197. }
  1198. else
  1199. {
  1200. $context['ip'] = $user_profile[$memID]['member_ip'];
  1201. $context['base_url'] = $scripturl . '?action=profile;area=tracking;sa=ip;u=' . $memID;
  1202. }
  1203. // Searching?
  1204. if (isset($_REQUEST['searchip']))
  1205. $context['ip'] = trim($_REQUEST['searchip']);
  1206. if (preg_match('/^\d{1,3}\.(\d{1,3}|\*)\.(\d{1,3}|\*)\.(\d{1,3}|\*)$/', $context['ip']) == 0 && isValidIPv6($context['ip']) === false)
  1207. fatal_lang_error('invalid_tracking_ip', false);
  1208. $ip_var = str_replace('*', '%', $context['ip']);
  1209. $ip_string = strpos($ip_var, '%') === false ? '= {string:ip_address}' : 'LIKE {string:ip_address}';
  1210. if (empty($context['tracking_area']))
  1211. $context['page_title'] = $txt['trackIP'] . ' - ' . $context['ip'];
  1212. $request = $smcFunc['db_query']('', '
  1213. SELECT id_member, real_name AS display_name, member_ip
  1214. FROM {db_prefix}members
  1215. WHERE member_ip ' . $ip_string,
  1216. array(
  1217. 'ip_address' => $ip_var,
  1218. )
  1219. );
  1220. $context['ips'] = array();
  1221. while ($row = $smcFunc['db_fetch_assoc']($request))
  1222. $context['ips'][$row['member_ip']][] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['display_name'] . '</a>';
  1223. $smcFunc['db_free_result']($request);
  1224. ksort($context['ips']);
  1225. // Gonna want this for the list.
  1226. require_once($sourcedir . '/Subs-List.php');
  1227. // Start with the user messages.
  1228. $listOptions = array(
  1229. 'id' => 'track_message_list',
  1230. 'title' => $txt['messages_from_ip'] . ' ' . $context['ip'],
  1231. 'start_var_name' => 'messageStart',
  1232. 'items_per_page' => $modSettings['defaultMaxMessages'],
  1233. 'no_items_label' => $txt['no_messages_from_ip'],
  1234. 'base_href' => $context['base_url'] . ';searchip=' . $context['ip'],
  1235. 'default_sort_col' => 'date',
  1236. 'get_items' => array(
  1237. 'function' => 'list_getIPMessages',
  1238. 'params' => array(
  1239. 'm.poster_ip ' . $ip_string,
  1240. array('ip_address' => $ip_var),
  1241. ),
  1242. ),
  1243. 'get_count' => array(
  1244. 'function' => 'list_getIPMessageCount',
  1245. 'params' => array(
  1246. 'm.poster_ip ' . $ip_string,
  1247. array('ip_address' => $ip_var),
  1248. ),
  1249. ),
  1250. 'columns' => array(
  1251. 'ip_address' => array(
  1252. 'header' => array(
  1253. 'value' => $txt['ip_address'],
  1254. ),
  1255. 'data' => array(
  1256. 'sprintf' => array(
  1257. 'format' => '<a href="' . $context['base_url'] . ';searchip=%1$s">%1$s</a>',
  1258. 'params' => array(
  1259. 'ip' => false,
  1260. ),
  1261. ),
  1262. ),
  1263. 'sort' => array(
  1264. 'default' => 'INET_ATON(m.poster_ip)',
  1265. 'reverse' => 'INET_ATON(m.poster_ip) DESC',
  1266. ),
  1267. ),
  1268. 'poster' => array(
  1269. 'header' => array(
  1270. 'value' => $txt['poster'],
  1271. ),
  1272. 'data' => array(
  1273. 'db' => 'member_link',
  1274. ),
  1275. ),
  1276. 'subject' => array(
  1277. 'header' => array(
  1278. 'value' => $txt['subject'],
  1279. ),
  1280. 'data' => array(
  1281. 'sprintf' => array(
  1282. 'format' => '<a href="' . $scripturl . '?topic=%1$s.msg%2$s#msg%2$s" rel="nofollow">%3$s</a>',
  1283. 'params' => array(
  1284. 'topic' => false,
  1285. 'id' => false,
  1286. 'subject' => false,
  1287. ),
  1288. ),
  1289. ),
  1290. ),
  1291. 'date' => array(
  1292. 'header' => array(
  1293. 'value' => $txt['date'],
  1294. ),
  1295. 'data' => array(
  1296. 'db' => 'time',
  1297. ),
  1298. 'sort' => array(
  1299. 'default' => 'm.id_msg DESC',
  1300. 'reverse' => 'm.id_msg',
  1301. ),
  1302. ),
  1303. ),
  1304. 'additional_rows' => array(
  1305. array(
  1306. 'position' => 'after_title',
  1307. 'value' => $txt['messages_from_ip_desc'],
  1308. 'class' => 'windowbg2',
  1309. 'style' => 'padding: 1ex 2ex;',
  1310. ),
  1311. ),
  1312. );
  1313. // Create the messages list.
  1314. createList($listOptions);
  1315. // Set the options for the error lists.
  1316. $listOptions = array(
  1317. 'id' => 'track_user_list',
  1318. 'title' => $txt['errors_from_ip'] . ' ' . $context['ip'],
  1319. 'start_var_name' => 'errorStart',
  1320. 'items_per_page' => $modSettings['defaultMaxMessages'],
  1321. 'no_items_label' => $txt['no_errors_from_ip'],
  1322. 'base_href' => $context['base_url'] . ';searchip=' . $context['ip'],
  1323. 'default_sort_col' => 'date2',
  1324. 'get_items' => array(
  1325. 'function' => 'list_getUserErrors',
  1326. 'params' => array(
  1327. 'le.ip ' . $ip_string,
  1328. array('ip_address' => $ip_var),
  1329. ),
  1330. ),
  1331. 'get_count' => array(
  1332. 'function' => 'list_getUserErrorCount',
  1333. 'params' => array(
  1334. 'ip ' . $ip_string,
  1335. array('ip_address' => $ip_var),
  1336. ),
  1337. ),
  1338. 'columns' => array(
  1339. 'ip_address2' => array(
  1340. 'header' => array(
  1341. 'value' => $txt['ip_address'],
  1342. ),
  1343. 'data' => array(
  1344. 'sprintf' => array(
  1345. 'format' => '<a href="' . $context['base_url'] . ';searchip=%1$s">%1$s</a>',
  1346. 'params' => array(
  1347. 'ip' => false,
  1348. ),
  1349. ),
  1350. ),
  1351. 'sort' => array(
  1352. 'default' => 'INET_ATON(le.ip)',
  1353. 'reverse' => 'INET_ATON(le.ip) DESC',
  1354. ),
  1355. ),
  1356. 'display_name' => array(
  1357. 'header' => array(
  1358. 'value' => $txt['display_name'],
  1359. ),
  1360. 'data' => array(
  1361. 'db' => 'member_link',
  1362. ),
  1363. ),
  1364. 'message' => array(
  1365. 'header' => array(
  1366. 'value' => $txt['message'],
  1367. ),
  1368. 'data' => array(
  1369. 'sprintf' => array(
  1370. 'format' => '%1$s<br /><a href="%2$s">%2$s</a>',
  1371. 'params' => array(
  1372. 'message' => false,
  1373. 'url' => false,
  1374. ),
  1375. ),
  1376. ),
  1377. ),
  1378. 'date2' => array(
  1379. 'header' => array(
  1380. 'value' => $txt['date'],
  1381. ),
  1382. 'data' => array(
  1383. 'db' => 'time',
  1384. ),
  1385. 'sort' => array(
  1386. 'default' => 'le.id_error DESC',
  1387. 'reverse' => 'le.id_error',
  1388. ),
  1389. ),
  1390. ),
  1391. 'additional_rows' => array(
  1392. array(
  1393. 'position' => 'after_title',
  1394. 'value' => $txt['errors_from_ip_desc'],
  1395. 'class' => 'windowbg2',
  1396. 'style' => 'padding: 1ex 2ex;',
  1397. ),
  1398. ),
  1399. );
  1400. // Create the error list.
  1401. createList($listOptions);
  1402. $context['single_ip'] = strpos($context['ip'], '*') === false;
  1403. if ($context['single_ip'])
  1404. {
  1405. $context['whois_servers'] = array(
  1406. 'afrinic' => array(
  1407. 'name' => $txt['whois_afrinic'],
  1408. 'url' => 'http://www.afrinic.net/cgi-bin/whois?searchtext=' . $context['ip'],
  1409. 'range' => array(41, 154, 196),
  1410. ),
  1411. 'apnic' => array(
  1412. 'name' => $txt['whois_apnic'],
  1413. 'url' => 'http://wq.apnic.net/apnic-bin/whois.pl?searchtext=' . $context['ip'],
  1414. 'range' => array(58, 59, 60, 61, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124,
  1415. 125, 126, 133, 150, 153, 163, 171, 202, 203, 210, 211, 218, 219, 220, 221, 222),
  1416. ),
  1417. 'arin' => array(
  1418. 'name' => $txt['whois_arin'],
  1419. 'url' => 'http://whois.arin.net/rest/ip/' . $context['ip'],
  1420. 'range' => array(7, 24, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 96, 97, 98, 99,
  1421. 128, 129, 130, 131, 132, 134, 135, 136, 137, 138, 139, 140, 142, 143, 144, 146, 147, 148, 149,
  1422. 152, 155, 156, 157, 158, 159, 160, 161, 162, 164, 165, 166, 167, 168, 169, 170, 172, 173, 174,
  1423. 192, 198, 199, 204, 205, 206, 207, 208, 209, 216),
  1424. ),
  1425. 'lacnic' => array(
  1426. 'name' => $txt['whois_lacnic'],
  1427. 'url' => 'http://lacnic.net/cgi-bin/lacnic/whois?query=' . $context['ip'],
  1428. 'range' => array(186, 187, 189, 190, 191, 200, 201),
  1429. ),
  1430. 'ripe' => array(
  1431. 'name' => $txt['whois_ripe'],
  1432. 'url' => 'http://www.db.ripe.net/whois?searchtext=' . $context['ip'],
  1433. 'range' => array(62, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
  1434. 141, 145, 151, 188, 193, 194, 195, 212, 213, 217),
  1435. ),
  1436. );
  1437. foreach ($context['whois_servers'] as $whois)
  1438. {
  1439. // Strip off the "decimal point" and anything following...
  1440. if (in_array((int) $context['ip'], $whois['range']))
  1441. $context['auto_whois_server'] = $whois;
  1442. }
  1443. }
  1444. }
  1445. /**
  1446. * Tracks a users logins.
  1447. *
  1448. * @param int $memID = 0 id_member
  1449. */
  1450. function TrackLogins($memID = 0)
  1451. {
  1452. global $user_profile, $scripturl, $txt, $user_info, $modSettings, $sourcedir;
  1453. global $context, $smcFunc;
  1454. // Gonna want this for the list.
  1455. require_once($sourcedir . '/Subs-List.php');
  1456. if ($memID == 0)
  1457. $context['base_url'] = $scripturl . '?action=trackip';
  1458. else
  1459. $context['base_url'] = $scripturl . '?action=profile;area=tracking;sa=ip;u=' . $memID;
  1460. // Start with the user messages.
  1461. $listOptions = array(
  1462. 'id' => 'track_logins_list',
  1463. 'title' => $txt['trackLogins'],
  1464. 'no_items_label' => $txt['trackLogins_none_found'],
  1465. 'base_href' => $context['base_url'],
  1466. 'get_items' => array(
  1467. 'function' => 'list_getLogins',
  1468. 'params' => array(
  1469. 'id_member = {int:current_member}',
  1470. array('current_member' => $memID),
  1471. ),
  1472. ),
  1473. 'get_count' => array(
  1474. 'function' => 'list_getLoginCount',
  1475. 'params' => array(
  1476. 'id_member = {int:current_member}',
  1477. array('current_member' => $memID),
  1478. ),
  1479. ),
  1480. 'columns' => array(
  1481. 'time' => array(
  1482. 'header' => array(
  1483. 'value' => $txt['date'],
  1484. ),
  1485. 'data' => array(
  1486. 'db' => 'time',
  1487. ),
  1488. ),
  1489. 'ip' => array(
  1490. 'header' => array(
  1491. 'value' => $txt['ip_address'],
  1492. ),
  1493. 'data' => array(
  1494. 'sprintf' => array(
  1495. 'format' => '<a href="' . $context['base_url'] . ';searchip=%1$s">%1$s</a> (<a href="' . $context['base_url'] . ';searchip=%2$s">%2$s</a>) ',
  1496. 'params' => array(
  1497. 'ip' => false,
  1498. 'ip2' => false
  1499. ),
  1500. ),
  1501. ),
  1502. ),
  1503. ),
  1504. 'additional_rows' => array(
  1505. array(
  1506. 'position' => 'after_title',
  1507. 'value' => $txt['trackLogins_desc'],
  1508. 'class' => 'windowbg2',
  1509. 'style' => 'padding: 1ex 2ex;',
  1510. ),
  1511. ),
  1512. );
  1513. // Create the messages list.
  1514. createList($listOptions);
  1515. $context['sub_template'] = 'show_list';
  1516. $context['default_list'] = 'track_logins_list';
  1517. }
  1518. /**
  1519. * Callback for trackLogins for counting history.
  1520. *
  1521. * @param string $where
  1522. * @param array $where_vars
  1523. * @return string count of messages matching the IP
  1524. */
  1525. function list_getLoginCount($where, $where_vars = array())
  1526. {
  1527. global $smcFunc;
  1528. $request = $smcFunc['db_query']('', '
  1529. SELECT COUNT(*) AS message_count
  1530. FROM {db_prefix}member_logins
  1531. WHERE id_member = {int:id_member}',
  1532. array(
  1533. 'id_member' => $where_vars['current_member'],
  1534. )
  1535. );
  1536. list ($count) = $smcFunc['db_fetch_row']($request);
  1537. $smcFunc['db_free_result']($request);
  1538. // @todo cast to integer
  1539. return $count;
  1540. }
  1541. /**
  1542. * Callback for trackLogins data.
  1543. *
  1544. * @param int $start
  1545. * @param int $items_per_page
  1546. * @param string $sort
  1547. * @param string $where
  1548. * @param array $where_vars
  1549. * @return array an array of messages
  1550. */
  1551. function list_getLogins($start, $items_per_page, $sort, $where, $where_vars = array())
  1552. {
  1553. global $smcFunc, $txt, $scripturl;
  1554. $request = $smcFunc['db_query']('', '
  1555. SELECT time, ip, ip2
  1556. FROM {db_prefix}member_logins
  1557. WHERE {int:id_member}
  1558. ORDER BY time DESC',
  1559. array(
  1560. 'id_member' => $where_vars['current_member'],
  1561. )
  1562. );
  1563. $logins = array();
  1564. while ($row = $smcFunc['db_fetch_assoc']($request))
  1565. $logins[] = array(
  1566. 'time' => timeformat($row['time']),
  1567. 'ip' => $row['ip'],
  1568. 'ip2' => $row['ip2'],
  1569. );
  1570. $smcFunc['db_free_result']($request);
  1571. return $logins;
  1572. }
  1573. /**
  1574. * @todo needs a description
  1575. *
  1576. * @param int $memID id_member
  1577. */
  1578. function trackEdits($memID)
  1579. {
  1580. global $scripturl, $txt, $modSettings, $sourcedir, $context, $smcFunc;
  1581. require_once($sourcedir . '/Subs-List.php');
  1582. // Get the names of any custom fields.
  1583. $request = $smcFunc['db_query']('', '
  1584. SELECT col_name, field_name, bbc
  1585. FROM {db_prefix}custom_fields',
  1586. array(
  1587. )
  1588. );
  1589. $context['custom_field_titles'] = array();
  1590. while ($row = $smcFunc['db_fetch_assoc']($request))
  1591. $context['custom_field_titles']['customfield_' . $row['col_name']] = array(
  1592. 'title' => $row['field_name'],
  1593. 'parse_bbc' => $row['bbc'],
  1594. );
  1595. $smcFunc['db_free_result']($request);
  1596. // Set the options for the error lists.
  1597. $listOptions = array(
  1598. 'id' => 'edit_list',
  1599. 'title' => $txt['trackEdits'],
  1600. 'items_per_page' => $modSettings['defaultMaxMessages'],
  1601. 'no_items_label' => $txt['trackEdit_no_edits'],
  1602. 'base_href' => $scripturl . '?action=profile;area=tracking;sa=edits;u=' . $memID,
  1603. 'default_sort_col' => 'time',
  1604. 'get_items' => array(
  1605. 'function' => 'list_getProfileEdits',
  1606. 'params' => array(
  1607. $memID,
  1608. ),
  1609. ),
  1610. 'get_count' => array(
  1611. 'function' => 'list_getProfileEditCount',
  1612. 'params' => array(
  1613. $memID,
  1614. ),
  1615. ),
  1616. 'columns' => array(
  1617. 'action' => array(
  1618. 'header' => array(
  1619. 'value' => $txt['trackEdit_action'],
  1620. ),
  1621. 'data' => array(
  1622. 'db' => 'action_text',
  1623. ),
  1624. ),
  1625. 'before' => array(
  1626. 'header' => array(
  1627. 'value' => $txt['trackEdit_before'],
  1628. ),
  1629. 'data' => array(
  1630. 'db' => 'before',
  1631. ),
  1632. ),
  1633. 'after' => array(
  1634. 'header' => array(
  1635. 'value' => $txt['trackEdit_after'],
  1636. ),
  1637. 'data' => array(
  1638. 'db' => 'after',
  1639. ),
  1640. ),
  1641. 'time' => array(
  1642. 'header' => array(
  1643. 'value' => $txt['date'],
  1644. ),
  1645. 'data' => array(
  1646. 'db' => 'time',
  1647. ),
  1648. 'sort' => array(
  1649. 'default' => 'id_action DESC',
  1650. 'reverse' => 'id_action',
  1651. ),
  1652. ),
  1653. 'applicator' => array(
  1654. 'header' => array(
  1655. 'value' => $txt['trackEdit_applicator'],
  1656. ),
  1657. 'data' => array(
  1658. 'db' => 'member_link',
  1659. ),
  1660. ),
  1661. ),
  1662. );
  1663. // Create the error list.
  1664. createList($listOptions);
  1665. $context['sub_template'] = 'show_list';
  1666. $context['default_list'] = 'edit_list';
  1667. }
  1668. /**
  1669. * How many edits?
  1670. *
  1671. * @param int $memID id_member
  1672. * @return string number of profile edits
  1673. */
  1674. function list_getProfileEditCount($memID)
  1675. {
  1676. global $smcFunc;
  1677. $request = $smcFunc['db_query']('', '
  1678. SELECT COUNT(*) AS edit_count
  1679. FROM {db_prefix}log_actions
  1680. WHERE id_log = {int:log_type}
  1681. AND id_member = {int:owner}',
  1682. array(
  1683. 'log_type' => 2,
  1684. 'owner' => $memID,
  1685. )
  1686. );
  1687. list ($edit_count) = $smcFunc['db_fetch_row']($request);
  1688. $smcFunc['db_free_result']($request);
  1689. // @todo cast to integer
  1690. return $edit_count;
  1691. }
  1692. /**
  1693. * @todo needs a description
  1694. *
  1695. * @param int $start
  1696. * @param int $items_per_page
  1697. * @param string $sort
  1698. * @param int $memID
  1699. * @return array
  1700. */
  1701. function list_getProfileEdits($start, $items_per_page, $sort, $memID)
  1702. {
  1703. global $smcFunc, $txt, $scripturl, $context;
  1704. // Get a list of error messages from this ip (range).
  1705. $request = $smcFunc['db_query']('', '
  1706. SELECT
  1707. id_action, id_member, ip, log_time, action, extra
  1708. FROM {db_prefix}log_actions
  1709. WHERE id_log = {int:log_type}
  1710. AND id_member = {int:owner}
  1711. ORDER BY ' . $sort . '
  1712. LIMIT ' . $start . ', ' . $items_per_page,
  1713. array(
  1714. 'log_type' => 2,
  1715. 'owner' => $memID,
  1716. )
  1717. );
  1718. $edits = array();
  1719. $members = array();
  1720. while ($row = $smcFunc['db_fetch_assoc']($request))
  1721. {
  1722. $extra = @unserialize($row['extra']);
  1723. if (!empty($extra['applicator']))
  1724. $members[] = $extra['applicator'];
  1725. // Work out what the name of the action is.
  1726. if (isset($txt['trackEdit_action_' . $row['action']]))
  1727. $action_text = $txt['trackEdit_action_' . $row['action']];
  1728. elseif (isset($txt[$row['action']]))
  1729. $action_text = $txt[$row['action']];
  1730. // Custom field?
  1731. elseif (isset($context['custom_field_titles'][$row['action']]))
  1732. $action_text = $context['custom_field_titles'][$row['action']]['title'];
  1733. else
  1734. $action_text = $row['action'];
  1735. // Parse BBC?
  1736. $parse_bbc = isset($context['custom_field_titles'][$row['action']]) && $context['custom_field_titles'][$row['action']]['parse_bbc'] ? true : false;
  1737. $edits[] = array(
  1738. 'id' => $row['id_action'],
  1739. 'ip' => $row['ip'],
  1740. 'id_member' => !empty($extra['applicator']) ? $extra['applicator'] : 0,
  1741. 'member_link' => $txt['trackEdit_deleted_member'],
  1742. 'action' => $row['action'],
  1743. 'action_text' => $action_text,
  1744. 'before' => !empty($extra['previous']) ? ($parse_bbc ? parse_bbc($extra['previous']) : $extra['previous']) : '',
  1745. 'after' => !empty($extra['new']) ? ($parse_bbc ? parse_bbc($extra['new']) : $extra['new']) : '',
  1746. 'time' => timeformat($row['log_time']),
  1747. );
  1748. }
  1749. $smcFunc['db_free_result']($request);
  1750. // Get any member names.
  1751. if (!empty($members))
  1752. {
  1753. $request = $smcFunc['db_query']('', '
  1754. SELECT
  1755. id_member, real_name
  1756. FROM {db_prefix}members
  1757. WHERE id_member IN ({array_int:members})',
  1758. array(
  1759. 'members' => $members,
  1760. )
  1761. );
  1762. $members = array();
  1763. while ($row = $smcFunc['db_fetch_assoc']($request))
  1764. $members[$row['id_member']] = $row['real_name'];
  1765. $smcFunc['db_free_result']($request);
  1766. foreach ($edits as $key => $value)
  1767. if (isset($members[$value['id_member']]))
  1768. $edits[$key]['member_link'] = '<a href="' . $scripturl . '?action=profile;u=' . $value['id_member'] . '">' . $members[$value['id_member']] . '</a>';
  1769. }
  1770. return $edits;
  1771. }
  1772. /**
  1773. * @todo needs a description
  1774. *
  1775. * @param int $memID id_member
  1776. */
  1777. function showPermissions($memID)
  1778. {
  1779. global $scripturl, $txt, $board, $modSettings;
  1780. global $user_profile, $context, $user_info, $sourcedir, $smcFunc;
  1781. // Verify if the user has sufficient permissions.
  1782. isAllowedTo('manage_permissions');
  1783. loadLanguage('ManagePermissions');
  1784. loadLanguage('Admin');
  1785. loadTemplate('ManageMembers');
  1786. // Load all the permission profiles.
  1787. require_once($sourcedir . '/ManagePermissions.php');
  1788. loadPermissionProfiles();
  1789. $context['member']['id'] = $memID;
  1790. $context['member']['name'] = $user_profile[$memID]['real_name'];
  1791. $context['page_title'] = $txt['showPermissions'];
  1792. $board = empty($board) ? 0 : (int) $board;
  1793. $context['board'] = $board;
  1794. // Determine which groups this user is in.
  1795. if (empty($user_profile[$memID]['additional_groups']))
  1796. $curGroups = array();
  1797. else
  1798. $curGroups = explode(',', $user_profile[$memID]['additional_groups']);
  1799. $curGroups[] = $user_profile[$memID]['id_group'];
  1800. $curGroups[] = $user_profile[$memID]['id_post_group'];
  1801. // Load a list of boards for the jump box - except the defaults.
  1802. $request = $smcFunc['db_query']('order_by_board_order', '
  1803. SELECT b.id_board, b.name, b.id_profile, b.member_groups, IFNULL(mods.id_member, 0) AS is_mod
  1804. FROM {db_prefix}boards AS b
  1805. LEFT JOIN {db_prefix}moderators AS mods ON (mods.id_board = b.id_board AND mods.id_member = {int:current_member})
  1806. WHERE {query_see_board}',
  1807. array(
  1808. 'current_member' => $memID,
  1809. )
  1810. );
  1811. $context['boards'] = array();
  1812. $context['no_access_boards'] = array();
  1813. while ($row = $smcFunc['db_fetch_assoc']($request))
  1814. {
  1815. if (count(array_intersect($curGroups, explode(',', $row['member_groups']))) === 0 && !$row['is_mod'])
  1816. $context['no_access_boards'][] = array(
  1817. 'id' => $row['id_board'],
  1818. 'name' => $row['name'],
  1819. 'is_last' => false,
  1820. );
  1821. elseif ($row['id_profile'] != 1 || $row['is_mod'])
  1822. $context['boards'][$row['id_board']] = array(
  1823. 'id' => $row['id_board'],
  1824. 'name' => $row['name'],
  1825. 'selected' => $board == $row['id_board'],
  1826. 'profile' => $row['id_profile'],
  1827. 'profile_name' => $context['profiles'][$row['id_profile']]['name'],
  1828. );
  1829. }
  1830. $smcFunc['db_free_result']($request);
  1831. if (!empty($context['no_access_boards']))
  1832. $context['no_access_boards'][count($context['no_access_boards']) - 1]['is_last'] = true;
  1833. $context['member']['permissions'] = array(
  1834. 'general' => array(),
  1835. 'board' => array()
  1836. );
  1837. // If you're an admin we know you can do everything, we might as well leave.
  1838. $context['member']['has_all_permissions'] = in_array(1, $curGroups);
  1839. if ($context['member']['has_all_permissions'])
  1840. return;
  1841. $denied = array();
  1842. // Get all general permissions.
  1843. $result = $smcFunc['db_query']('', '
  1844. SELECT p.permission, p.add_deny, mg.group_name, p.id_group
  1845. FROM {db_prefix}permissions AS p
  1846. LEFT JOIN {db_prefix}membergroups AS mg ON (mg.id_group = p.id_group)
  1847. WHERE p.id_group IN ({array_int:group_list})
  1848. 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',
  1849. array(
  1850. 'group_list' => $curGroups,
  1851. 'newbie_group' => 4,
  1852. )
  1853. );
  1854. while ($row = $smcFunc['db_fetch_assoc']($result))
  1855. {
  1856. // We don't know about this permission, it doesn't exist :P.
  1857. if (!isset($txt['permissionname_' . $row['permission']]))
  1858. continue;
  1859. if (empty($row['add_deny']))
  1860. $denied[] = $row['permission'];
  1861. // Permissions that end with _own or _any consist of two parts.
  1862. if (in_array(substr($row['permission'], -4), array('_own', '_any')) && isset($txt['permissionname_' . substr($row['permission'], 0, -4)]))
  1863. $name = $txt['permissionname_' . substr($row['permission'], 0, -4)] . ' - ' . $txt['permissionname_' . $row['permission']];
  1864. else
  1865. $name = $txt['permissionname_' . $row['permission']];
  1866. // Add this permission if it doesn't exist yet.
  1867. if (!isset($context['member']['permissions']['general'][$row['permission']]))
  1868. $context['member']['permissions']['general'][$row['permission']] = array(
  1869. 'id' => $row['permission'],
  1870. 'groups' => array(
  1871. 'allowed' => array(),
  1872. 'denied' => array()
  1873. ),
  1874. 'name' => $name,
  1875. 'is_denied' => false,
  1876. 'is_global' => true,
  1877. );
  1878. // Add the membergroup to either the denied or the allowed groups.
  1879. $context['member']['permissions']['general'][$row['permission']]['groups'][empty($row['add_deny']) ? 'denied' : 'allowed'][] = $row['id_group'] == 0 ? $txt['membergroups_members'] : $row['group_name'];
  1880. // Once denied is always denied.
  1881. $context['member']['permissions']['general'][$row['permission']]['is_denied'] |= empty($row['add_deny']);
  1882. }
  1883. $smcFunc['db_free_result']($result);
  1884. $request = $smcFunc['db_query']('', '
  1885. SELECT
  1886. bp.add_deny, bp.permission, bp.id_group, mg.group_name' . (empty($board) ? '' : ',
  1887. b.id_profile, CASE WHEN mods.id_member IS NULL THEN 0 ELSE 1 END AS is_moderator') . '
  1888. FROM {db_prefix}board_permissions AS bp' . (empty($board) ? '' : '
  1889. INNER JOIN {db_prefix}boards AS b ON (b.id_board = {int:current_board})
  1890. LEFT JOIN {db_prefix}moderators AS mods ON (mods.id_board = b.id_board AND mods.id_member = {int:current_member})') . '
  1891. LEFT JOIN {db_prefix}membergroups AS mg ON (mg.id_group = bp.id_group)
  1892. WHERE bp.id_profile = {raw:current_profile}
  1893. AND bp.id_group IN ({array_int:group_list}' . (empty($board) ? ')' : ', {int:moderator_group})
  1894. AND (mods.id_member IS NOT NULL OR bp.id_group != {int:moderator_group})'),
  1895. array(
  1896. 'current_board' => $board,
  1897. 'group_list' => $curGroups,
  1898. 'current_member' => $memID,
  1899. 'current_profile' => empty($board) ? '1' : 'b.id_profile',
  1900. 'moderator_group' => 3,
  1901. )
  1902. );
  1903. while ($row = $smcFunc['db_fetch_assoc']($request))
  1904. {
  1905. // We don't know about this permission, it doesn't exist :P.
  1906. if (!isset($txt['permissionname_' . $row['permission']]))
  1907. continue;
  1908. // The name of the permission using the format 'permission name' - 'own/any topic/event/etc.'.
  1909. if (in_array(substr($row['permission'], -4), array('_own', '_any')) && isset($txt['permissionname_' . substr($row['permission'], 0, -4)]))
  1910. $name = $txt['permissionname_' . substr($row['permission'], 0, -4)] . ' - ' . $txt['permissionname_' . $row['permission']];
  1911. else
  1912. $name = $txt['permissionname_' . $row['permission']];
  1913. // Create the structure for this permission.
  1914. if (!isset($context['member']['permissions']['board'][$row['permission']]))
  1915. $context['member']['permissions']['board'][$row['permission']] = array(
  1916. 'id' => $row['permission'],
  1917. 'groups' => array(
  1918. 'allowed' => array(),
  1919. 'denied' => array()
  1920. ),
  1921. 'name' => $name,
  1922. 'is_denied' => false,
  1923. 'is_global' => empty($board),
  1924. );
  1925. $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'];
  1926. $context['member']['permissions']['board'][$row['permission']]['is_denied'] |= empty($row['add_deny']);
  1927. }
  1928. $smcFunc['db_free_result']($request);
  1929. }
  1930. /**
  1931. * View a members warnings?
  1932. *
  1933. * @param int $memID id_member
  1934. */
  1935. function viewWarning($memID)
  1936. {
  1937. global $modSettings, $context, $sourcedir, $txt, $scripturl;
  1938. // Firstly, can we actually even be here?
  1939. if (!allowedTo('issue_warning') && (empty($modSettings['warning_show']) || ($modSettings['warning_show'] == 1 && !$context['user']['is_owner'])))
  1940. fatal_lang_error('no_access', false);
  1941. // Make sure things which are disabled stay disabled.
  1942. $modSettings['warning_watch'] = !empty($modSettings['warning_watch']) ? $modSettings['warning_watch'] : 110;
  1943. $modSettings['warning_moderate'] = !empty($modSettings['warning_moderate']) && !empty($modSettings['postmod_active']) ? $modSettings['warning_moderate'] : 110;
  1944. $modSettings['warning_mute'] = !empty($modSettings['warning_mute']) ? $modSettings['warning_mute'] : 110;
  1945. // Let's use a generic list to get all the current warnings, and use the issue warnings grab-a-granny thing.
  1946. require_once($sourcedir . '/Subs-List.php');
  1947. require_once($sourcedir . '/Profile-Actions.php');
  1948. $listOptions = array(
  1949. 'id' => 'view_warnings',
  1950. 'title' => $txt['profile_viewwarning_previous_warnings'],
  1951. 'items_per_page' => $modSettings['defaultMaxMessages'],
  1952. 'no_items_label' => $txt['profile_viewwarning_no_warnings'],
  1953. 'base_href' => $scripturl . '?action=profile;area=viewwarning;sa=user;u=' . $memID,
  1954. 'default_sort_col' => 'log_time',
  1955. 'get_items' => array(
  1956. 'function' => 'list_getUserWarnings',
  1957. 'params' => array(
  1958. $memID,
  1959. ),
  1960. ),
  1961. 'get_count' => array(
  1962. 'function' => 'list_getUserWarningCount',
  1963. 'params' => array(
  1964. $memID,
  1965. ),
  1966. ),
  1967. 'columns' => array(
  1968. 'log_time' => array(
  1969. 'header' => array(
  1970. 'value' => $txt['profile_warning_previous_time'],
  1971. ),
  1972. 'data' => array(
  1973. 'db' => 'time',
  1974. ),
  1975. 'sort' => array(
  1976. 'default' => 'lc.log_time DESC',
  1977. 'reverse' => 'lc.log_time',
  1978. ),
  1979. ),
  1980. 'reason' => array(
  1981. 'header' => array(
  1982. 'value' => $txt['profile_warning_previous_reason'],
  1983. 'style' => 'width: 50%',
  1984. ),
  1985. 'data' => array(
  1986. 'db' => 'reason',
  1987. ),
  1988. ),
  1989. 'level' => array(
  1990. 'header' => array(
  1991. 'value' => $txt['profile_warning_previous_level'],
  1992. ),
  1993. 'data' => array(
  1994. 'db' => 'counter',
  1995. ),
  1996. 'sort' => array(
  1997. 'default' => 'lc.counter DESC',
  1998. 'reverse' => 'lc.counter',
  1999. ),
  2000. ),
  2001. ),
  2002. 'additional_rows' => array(
  2003. array(
  2004. 'position' => 'after_title',
  2005. 'value' => $txt['profile_viewwarning_desc'],
  2006. 'class' => 'smalltext',
  2007. 'style' => 'padding: 2ex;',
  2008. ),
  2009. ),
  2010. );
  2011. // Create the list for viewing.
  2012. require_once($sourcedir . '/Subs-List.php');
  2013. createList($listOptions);
  2014. // Create some common text bits for the template.
  2015. $context['level_effects'] = array(
  2016. 0 => '',
  2017. $modSettings['warning_watch'] => $txt['profile_warning_effect_own_watched'],
  2018. $modSettings['warning_moderate'] => $txt['profile_warning_effect_own_moderated'],
  2019. $modSettings['warning_mute'] => $txt['profile_warning_effect_own_muted'],
  2020. );
  2021. $context['current_level'] = 0;
  2022. foreach ($context['level_effects'] as $limit => $dummy)
  2023. if ($context['member']['warning'] >= $limit)
  2024. $context['current_level'] = $limit;
  2025. }
  2026. ?>