Profile-View.php 68 KB

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