Profile-View.php 77 KB

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