Profile-View.php 88 KB

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