Profile-View.php 65 KB

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