Profile-View.php 88 KB

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