Profile-View.php 88 KB

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