Profile-View.php 87 KB

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