Profile-View.php 76 KB

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