Profile-View.php 70 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228
  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. }
  2030. ?>