Profile-View.php 88 KB

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