Profile-View.php 68 KB

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