Profile-View.php 70 KB

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