Profile-View.php 66 KB

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