Profile-View.php 82 KB

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