Post.php 111 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064
  1. <?php
  2. /**
  3. * The job of this file is to handle everything related to posting replies,
  4. * new topics, quotes, and modifications to existing posts. It also handles
  5. * quoting posts by way of javascript.
  6. * Simple Machines Forum (SMF)
  7. *
  8. * @package SMF
  9. * @author Simple Machines http://www.simplemachines.org
  10. * @copyright 2011 Simple Machines
  11. * @license http://www.simplemachines.org/about/smf/license.php BSD
  12. *
  13. * @version 2.1 Alpha 1
  14. */
  15. if (!defined('SMF'))
  16. die('Hacking attempt...');
  17. /**
  18. * handles showing the post screen, loading the post to be modified, and loading any post quoted.
  19. *
  20. * - additionally handles previews of posts.
  21. * - @uses the Post template and language file, main sub template.
  22. * - allows wireless access using the protocol_post sub template.
  23. * - requires different permissions depending on the actions, but most notably post_new, post_reply_own, and post_reply_any.
  24. * - shows options for the editing and posting of calendar events and attachments, as well as the posting of polls.
  25. * - accessed from ?action=post.
  26. */
  27. function Post($post_errors = array())
  28. {
  29. global $txt, $scripturl, $topic, $modSettings, $board;
  30. global $user_info, $sc, $board_info, $context, $settings;
  31. global $sourcedir, $options, $smcFunc, $language;
  32. loadLanguage('Post');
  33. // You can't reply with a poll... hacker.
  34. if (isset($_REQUEST['poll']) && !empty($topic) && !isset($_REQUEST['msg']))
  35. unset($_REQUEST['poll']);
  36. // Posting an event?
  37. $context['make_event'] = isset($_REQUEST['calendar']);
  38. $context['robot_no_index'] = true;
  39. // You must be posting to *some* board.
  40. if (empty($board) && !$context['make_event'])
  41. fatal_lang_error('no_board', false);
  42. require_once($sourcedir . '/Subs-Post.php');
  43. if (isset($_REQUEST['xml']))
  44. {
  45. $context['sub_template'] = 'post';
  46. // Just in case of an earlier error...
  47. $context['preview_message'] = '';
  48. $context['preview_subject'] = '';
  49. }
  50. // No message is complete without a topic.
  51. if (empty($topic) && !empty($_REQUEST['msg']))
  52. {
  53. $request = $smcFunc['db_query']('', '
  54. SELECT id_topic
  55. FROM {db_prefix}messages
  56. WHERE id_msg = {int:msg}',
  57. array(
  58. 'msg' => (int) $_REQUEST['msg'],
  59. ));
  60. if ($smcFunc['db_num_rows']($request) != 1)
  61. unset($_REQUEST['msg'], $_POST['msg'], $_GET['msg']);
  62. else
  63. list ($topic) = $smcFunc['db_fetch_row']($request);
  64. $smcFunc['db_free_result']($request);
  65. }
  66. // Check if it's locked. It isn't locked if no topic is specified.
  67. if (!empty($topic))
  68. {
  69. $request = $smcFunc['db_query']('', '
  70. SELECT
  71. t.locked, IFNULL(ln.id_topic, 0) AS notify, t.is_sticky, t.id_poll, t.id_last_msg, mf.id_member,
  72. t.id_first_msg, mf.subject,
  73. CASE WHEN ml.poster_time > ml.modified_time THEN ml.poster_time ELSE ml.modified_time END AS last_post_time
  74. FROM {db_prefix}topics AS t
  75. LEFT JOIN {db_prefix}log_notify AS ln ON (ln.id_topic = t.id_topic AND ln.id_member = {int:current_member})
  76. LEFT JOIN {db_prefix}messages AS mf ON (mf.id_msg = t.id_first_msg)
  77. LEFT JOIN {db_prefix}messages AS ml ON (ml.id_msg = t.id_last_msg)
  78. WHERE t.id_topic = {int:current_topic}
  79. LIMIT 1',
  80. array(
  81. 'current_member' => $user_info['id'],
  82. 'current_topic' => $topic,
  83. )
  84. );
  85. list ($locked, $context['notify'], $sticky, $pollID, $context['topic_last_message'], $id_member_poster, $id_first_msg, $first_subject, $lastPostTime) = $smcFunc['db_fetch_row']($request);
  86. $smcFunc['db_free_result']($request);
  87. // If this topic already has a poll, they sure can't add another.
  88. if (isset($_REQUEST['poll']) && $pollID > 0)
  89. unset($_REQUEST['poll']);
  90. if (empty($_REQUEST['msg']))
  91. {
  92. if ($user_info['is_guest'] && !allowedTo('post_reply_any') && (!$modSettings['postmod_active'] || !allowedTo('post_unapproved_replies_any')))
  93. is_not_guest();
  94. // By default the reply will be approved...
  95. $context['becomes_approved'] = true;
  96. if ($id_member_poster != $user_info['id'])
  97. {
  98. if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_any') && !allowedTo('post_reply_any'))
  99. $context['becomes_approved'] = false;
  100. else
  101. isAllowedTo('post_reply_any');
  102. }
  103. elseif (!allowedTo('post_reply_any'))
  104. {
  105. if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_own') && !allowedTo('post_reply_own'))
  106. $context['becomes_approved'] = false;
  107. else
  108. isAllowedTo('post_reply_own');
  109. }
  110. }
  111. else
  112. $context['becomes_approved'] = true;
  113. $context['can_lock'] = allowedTo('lock_any') || ($user_info['id'] == $id_member_poster && allowedTo('lock_own'));
  114. $context['can_sticky'] = allowedTo('make_sticky') && !empty($modSettings['enableStickyTopics']);
  115. $context['notify'] = !empty($context['notify']);
  116. $context['sticky'] = isset($_REQUEST['sticky']) ? !empty($_REQUEST['sticky']) : $sticky;
  117. // Check whether this is a really old post being bumped...
  118. if (!empty($modSettings['oldTopicDays']) && $lastPostTime + $modSettings['oldTopicDays'] * 86400 < time() && empty($sticky) && !isset($_REQUEST['subject']))
  119. $post_errors[] = array('old_topic', array($modSettings['oldTopicDays']));
  120. }
  121. else
  122. {
  123. $context['becomes_approved'] = true;
  124. if ((!$context['make_event'] || !empty($board)))
  125. {
  126. if ($modSettings['postmod_active'] && !allowedTo('post_new') && allowedTo('post_unapproved_topics'))
  127. $context['becomes_approved'] = false;
  128. else
  129. isAllowedTo('post_new');
  130. }
  131. $locked = 0;
  132. // @todo These won't work if you're making an event.
  133. $context['can_lock'] = allowedTo(array('lock_any', 'lock_own'));
  134. $context['can_sticky'] = allowedTo('make_sticky') && !empty($modSettings['enableStickyTopics']);
  135. $context['notify'] = !empty($context['notify']);
  136. $context['sticky'] = !empty($_REQUEST['sticky']);
  137. }
  138. // @todo These won't work if you're posting an event!
  139. $context['can_notify'] = allowedTo('mark_any_notify');
  140. $context['can_move'] = allowedTo('move_any');
  141. $context['move'] = !empty($_REQUEST['move']);
  142. $context['announce'] = !empty($_REQUEST['announce']);
  143. // You can only announce topics that will get approved...
  144. $context['can_announce'] = allowedTo('announce_topic') && $context['becomes_approved'];
  145. $context['locked'] = !empty($locked) || !empty($_REQUEST['lock']);
  146. $context['can_quote'] = empty($modSettings['disabledBBC']) || !in_array('quote', explode(',', $modSettings['disabledBBC']));
  147. // Generally don't show the approval box... (Assume we want things approved)
  148. $context['show_approval'] = allowedTo('approve_posts') && $context['becomes_approved'] ? 2 : (allowedTo('approve_posts') ? 1 : 0);
  149. // An array to hold all the attachments for this topic.
  150. $context['current_attachments'] = array();
  151. // Don't allow a post if it's locked and you aren't all powerful.
  152. if ($locked && !allowedTo('moderate_board'))
  153. fatal_lang_error('topic_locked', false);
  154. // Check the users permissions - is the user allowed to add or post a poll?
  155. if (isset($_REQUEST['poll']) && $modSettings['pollMode'] == '1')
  156. {
  157. // New topic, new poll.
  158. if (empty($topic))
  159. isAllowedTo('poll_post');
  160. // This is an old topic - but it is yours! Can you add to it?
  161. elseif ($user_info['id'] == $id_member_poster && !allowedTo('poll_add_any'))
  162. isAllowedTo('poll_add_own');
  163. // If you're not the owner, can you add to any poll?
  164. else
  165. isAllowedTo('poll_add_any');
  166. require_once($sourcedir . '/Subs-Members.php');
  167. $allowedVoteGroups = groupsAllowedTo('poll_vote', $board);
  168. // Set up the poll options.
  169. $context['poll_options'] = array(
  170. 'max_votes' => empty($_POST['poll_max_votes']) ? '1' : max(1, $_POST['poll_max_votes']),
  171. 'hide' => empty($_POST['poll_hide']) ? 0 : $_POST['poll_hide'],
  172. 'expire' => !isset($_POST['poll_expire']) ? '' : $_POST['poll_expire'],
  173. 'change_vote' => isset($_POST['poll_change_vote']),
  174. 'guest_vote' => isset($_POST['poll_guest_vote']),
  175. 'guest_vote_enabled' => in_array(-1, $allowedVoteGroups['allowed']),
  176. );
  177. // Make all five poll choices empty.
  178. $context['choices'] = array(
  179. array('id' => 0, 'number' => 1, 'label' => '', 'is_last' => false),
  180. array('id' => 1, 'number' => 2, 'label' => '', 'is_last' => false),
  181. array('id' => 2, 'number' => 3, 'label' => '', 'is_last' => false),
  182. array('id' => 3, 'number' => 4, 'label' => '', 'is_last' => false),
  183. array('id' => 4, 'number' => 5, 'label' => '', 'is_last' => true)
  184. );
  185. $context['last_choice_id'] = 4;
  186. }
  187. if ($context['make_event'])
  188. {
  189. // They might want to pick a board.
  190. if (!isset($context['current_board']))
  191. $context['current_board'] = 0;
  192. // Start loading up the event info.
  193. $context['event'] = array();
  194. $context['event']['title'] = isset($_REQUEST['evtitle']) ? htmlspecialchars(stripslashes($_REQUEST['evtitle'])) : '';
  195. $context['event']['id'] = isset($_REQUEST['eventid']) ? (int) $_REQUEST['eventid'] : -1;
  196. $context['event']['new'] = $context['event']['id'] == -1;
  197. // Permissions check!
  198. isAllowedTo('calendar_post');
  199. // Editing an event? (but NOT previewing!?)
  200. if (empty($context['event']['new']) && !isset($_REQUEST['subject']))
  201. {
  202. // If the user doesn't have permission to edit the post in this topic, redirect them.
  203. if ((empty($id_member_poster) || $id_member_poster != $user_info['id'] || !allowedTo('modify_own')) && !allowedTo('modify_any'))
  204. {
  205. require_once($sourcedir . '/Calendar.php');
  206. return CalendarPost();
  207. }
  208. // Get the current event information.
  209. $request = $smcFunc['db_query']('', '
  210. SELECT
  211. id_member, title, MONTH(start_date) AS month, DAYOFMONTH(start_date) AS day,
  212. YEAR(start_date) AS year, (TO_DAYS(end_date) - TO_DAYS(start_date)) AS span
  213. FROM {db_prefix}calendar
  214. WHERE id_event = {int:id_event}
  215. LIMIT 1',
  216. array(
  217. 'id_event' => $context['event']['id'],
  218. )
  219. );
  220. $row = $smcFunc['db_fetch_assoc']($request);
  221. $smcFunc['db_free_result']($request);
  222. // Make sure the user is allowed to edit this event.
  223. if ($row['id_member'] != $user_info['id'])
  224. isAllowedTo('calendar_edit_any');
  225. elseif (!allowedTo('calendar_edit_any'))
  226. isAllowedTo('calendar_edit_own');
  227. $context['event']['month'] = $row['month'];
  228. $context['event']['day'] = $row['day'];
  229. $context['event']['year'] = $row['year'];
  230. $context['event']['title'] = $row['title'];
  231. $context['event']['span'] = $row['span'] + 1;
  232. }
  233. else
  234. {
  235. $today = getdate();
  236. // You must have a month and year specified!
  237. if (!isset($_REQUEST['month']))
  238. $_REQUEST['month'] = $today['mon'];
  239. if (!isset($_REQUEST['year']))
  240. $_REQUEST['year'] = $today['year'];
  241. $context['event']['month'] = (int) $_REQUEST['month'];
  242. $context['event']['year'] = (int) $_REQUEST['year'];
  243. $context['event']['day'] = isset($_REQUEST['day']) ? $_REQUEST['day'] : ($_REQUEST['month'] == $today['mon'] ? $today['mday'] : 0);
  244. $context['event']['span'] = isset($_REQUEST['span']) ? $_REQUEST['span'] : 1;
  245. // Make sure the year and month are in the valid range.
  246. if ($context['event']['month'] < 1 || $context['event']['month'] > 12)
  247. fatal_lang_error('invalid_month', false);
  248. if ($context['event']['year'] < $modSettings['cal_minyear'] || $context['event']['year'] > $modSettings['cal_maxyear'])
  249. fatal_lang_error('invalid_year', false);
  250. // Get a list of boards they can post in.
  251. $boards = boardsAllowedTo('post_new');
  252. if (empty($boards))
  253. fatal_lang_error('cannot_post_new', 'user');
  254. // Load a list of boards for this event in the context.
  255. require_once($sourcedir . '/Subs-MessageIndex.php');
  256. $boardListOptions = array(
  257. 'included_boards' => in_array(0, $boards) ? null : $boards,
  258. 'not_redirection' => true,
  259. 'use_permissions' => true,
  260. 'selected_board' => empty($context['current_board']) ? $modSettings['cal_defaultboard'] : $context['current_board'],
  261. );
  262. $context['event']['categories'] = getBoardList($boardListOptions);
  263. }
  264. // Find the last day of the month.
  265. $context['event']['last_day'] = (int) strftime('%d', mktime(0, 0, 0, $context['event']['month'] == 12 ? 1 : $context['event']['month'] + 1, 0, $context['event']['month'] == 12 ? $context['event']['year'] + 1 : $context['event']['year']));
  266. $context['event']['board'] = !empty($board) ? $board : $modSettings['cal_defaultboard'];
  267. }
  268. // See if any new replies have come along.
  269. // Huh, $_REQUEST['msg'] is set upon submit, so this doesn't get executed at submit
  270. // only at preview
  271. if (empty($_REQUEST['msg']) && !empty($topic))
  272. {
  273. if (empty($options['no_new_reply_warning']) && isset($_REQUEST['last_msg']) && $context['topic_last_message'] > $_REQUEST['last_msg'])
  274. {
  275. $request = $smcFunc['db_query']('', '
  276. SELECT COUNT(*)
  277. FROM {db_prefix}messages
  278. WHERE id_topic = {int:current_topic}
  279. AND id_msg > {int:last_msg}' . (!$modSettings['postmod_active'] || allowedTo('approve_posts') ? '' : '
  280. AND approved = {int:approved}') . '
  281. LIMIT 1',
  282. array(
  283. 'current_topic' => $topic,
  284. 'last_msg' => (int) $_REQUEST['last_msg'],
  285. 'approved' => 1,
  286. )
  287. );
  288. list ($context['new_replies']) = $smcFunc['db_fetch_row']($request);
  289. $smcFunc['db_free_result']($request);
  290. if (!empty($context['new_replies']))
  291. {
  292. if ($context['new_replies'] == 1)
  293. $txt['error_new_replies'] = isset($_GET['last_msg']) ? $txt['error_new_reply_reading'] : $txt['error_new_reply'];
  294. else
  295. $txt['error_new_replies'] = sprintf(isset($_GET['last_msg']) ? $txt['error_new_replies_reading'] : $txt['error_new_replies'], $context['new_replies']);
  296. $post_errors[] = 'new_replies';
  297. $modSettings['topicSummaryPosts'] = $context['new_replies'] > $modSettings['topicSummaryPosts'] ? max($modSettings['topicSummaryPosts'], 5) : $modSettings['topicSummaryPosts'];
  298. }
  299. }
  300. }
  301. // Get a response prefix (like 'Re:') in the default forum language.
  302. if (!isset($context['response_prefix']) && !($context['response_prefix'] = cache_get_data('response_prefix')))
  303. {
  304. if ($language === $user_info['language'])
  305. $context['response_prefix'] = $txt['response_prefix'];
  306. else
  307. {
  308. loadLanguage('index', $language, false);
  309. $context['response_prefix'] = $txt['response_prefix'];
  310. loadLanguage('index');
  311. }
  312. cache_put_data('response_prefix', $context['response_prefix'], 600);
  313. }
  314. // Previewing, modifying, or posting?
  315. // Do we have a body, but an error happened.
  316. if (isset($_REQUEST['message']) || !empty($context['post_error']))
  317. {
  318. // Validate inputs.
  319. if (empty($context['post_error']))
  320. {
  321. // This means they didn't click Post and get an error.
  322. $really_previewing = true;
  323. }
  324. else
  325. {
  326. if (!isset($_REQUEST['subject']))
  327. $_REQUEST['subject'] = '';
  328. if (!isset($_REQUEST['message']))
  329. $_REQUEST['message'] = '';
  330. if (!isset($_REQUEST['icon']))
  331. $_REQUEST['icon'] = 'xx';
  332. // They are previewing if they asked to preview (i.e. came from quick reply).
  333. $really_previewing = !empty($_POST['preview']);
  334. }
  335. // In order to keep the approval status flowing through, we have to pass it through the form...
  336. $context['becomes_approved'] = empty($_REQUEST['not_approved']);
  337. $context['show_approval'] = isset($_REQUEST['approve']) ? ($_REQUEST['approve'] ? 2 : 1) : 0;
  338. $context['can_announce'] &= $context['becomes_approved'];
  339. // Set up the inputs for the form.
  340. $form_subject = strtr($smcFunc['htmlspecialchars']($_REQUEST['subject']), array("\r" => '', "\n" => '', "\t" => ''));
  341. $form_message = $smcFunc['htmlspecialchars']($_REQUEST['message'], ENT_QUOTES);
  342. // Make sure the subject isn't too long - taking into account special characters.
  343. if ($smcFunc['strlen']($form_subject) > 100)
  344. $form_subject = $smcFunc['substr']($form_subject, 0, 100);
  345. if (isset($_REQUEST['poll']))
  346. {
  347. $context['question'] = isset($_REQUEST['question']) ? $smcFunc['htmlspecialchars'](trim($_REQUEST['question'])) : '';
  348. $context['choices'] = array();
  349. $choice_id = 0;
  350. $_POST['options'] = empty($_POST['options']) ? array() : htmlspecialchars__recursive($_POST['options']);
  351. foreach ($_POST['options'] as $option)
  352. {
  353. if (trim($option) == '')
  354. continue;
  355. $context['choices'][] = array(
  356. 'id' => $choice_id++,
  357. 'number' => $choice_id,
  358. 'label' => $option,
  359. 'is_last' => false
  360. );
  361. }
  362. // One empty option for those with js disabled...I know are few... :P
  363. $context['choices'][] = array(
  364. 'id' => $choice_id++,
  365. 'number' => $choice_id,
  366. 'label' => '',
  367. 'is_last' => false
  368. );
  369. if (count($context['choices']) < 2)
  370. {
  371. $context['choices'][] = array(
  372. 'id' => $choice_id++,
  373. 'number' => $choice_id,
  374. 'label' => '',
  375. 'is_last' => false
  376. );
  377. }
  378. $context['last_choice_id'] = $choice_id;
  379. $context['choices'][count($context['choices']) - 1]['is_last'] = true;
  380. }
  381. // Are you... a guest?
  382. if ($user_info['is_guest'])
  383. {
  384. $_REQUEST['guestname'] = !isset($_REQUEST['guestname']) ? '' : trim($_REQUEST['guestname']);
  385. $_REQUEST['email'] = !isset($_REQUEST['email']) ? '' : trim($_REQUEST['email']);
  386. $_REQUEST['guestname'] = htmlspecialchars($_REQUEST['guestname']);
  387. $context['name'] = $_REQUEST['guestname'];
  388. $_REQUEST['email'] = htmlspecialchars($_REQUEST['email']);
  389. $context['email'] = $_REQUEST['email'];
  390. $user_info['name'] = $_REQUEST['guestname'];
  391. }
  392. // Only show the preview stuff if they hit Preview.
  393. if (($really_previewing == true || isset($_REQUEST['xml'])) && !isset($_POST['id_draft']))
  394. {
  395. // Set up the preview message and subject and censor them...
  396. $context['preview_message'] = $form_message;
  397. preparsecode($form_message, true);
  398. preparsecode($context['preview_message']);
  399. // Do all bulletin board code tags, with or without smileys.
  400. $context['preview_message'] = parse_bbc($context['preview_message'], isset($_REQUEST['ns']) ? 0 : 1);
  401. censorText($context['preview_message']);
  402. if ($form_subject != '')
  403. {
  404. $context['preview_subject'] = $form_subject;
  405. censorText($context['preview_subject']);
  406. }
  407. else
  408. $context['preview_subject'] = '<em>' . $txt['no_subject'] . '</em>';
  409. // Protect any CDATA blocks.
  410. if (isset($_REQUEST['xml']))
  411. $context['preview_message'] = strtr($context['preview_message'], array(']]>' => ']]]]><![CDATA[>'));
  412. }
  413. // Set up the checkboxes.
  414. $context['notify'] = !empty($_REQUEST['notify']);
  415. $context['use_smileys'] = !isset($_REQUEST['ns']);
  416. $context['icon'] = isset($_REQUEST['icon']) ? preg_replace('~[\./\\\\*\':"<>]~', '', $_REQUEST['icon']) : 'xx';
  417. // Set the destination action for submission.
  418. $context['destination'] = 'post2;start=' . $_REQUEST['start'] . (isset($_REQUEST['msg']) ? ';msg=' . $_REQUEST['msg'] . ';' . $context['session_var'] . '=' . $context['session_id'] : '') . (isset($_REQUEST['poll']) ? ';poll' : '');
  419. $context['submit_label'] = isset($_REQUEST['msg']) ? $txt['save'] : $txt['post'];
  420. // Previewing an edit?
  421. if (isset($_REQUEST['msg']) && !empty($topic))
  422. {
  423. // Get the existing message.
  424. $request = $smcFunc['db_query']('', '
  425. SELECT
  426. m.id_member, m.modified_time, m.smileys_enabled, m.body,
  427. m.poster_name, m.poster_email, m.subject, m.icon, m.approved,
  428. IFNULL(a.size, -1) AS filesize, a.filename, a.id_attach,
  429. a.approved AS attachment_approved, t.id_member_started AS id_member_poster,
  430. m.poster_time, log.id_action
  431. FROM {db_prefix}messages AS m
  432. INNER JOIN {db_prefix}topics AS t ON (t.id_topic = {int:current_topic})
  433. LEFT JOIN {db_prefix}attachments AS a ON (a.id_msg = m.id_msg AND a.attachment_type = {int:attachment_type})
  434. LEFT JOIN {db_prefix}log_actions AS log ON (m.id_topic = log.id_topic AND log.action = {string:announce_action})
  435. WHERE m.id_msg = {int:id_msg}
  436. AND m.id_topic = {int:current_topic}',
  437. array(
  438. 'current_topic' => $topic,
  439. 'attachment_type' => 0,
  440. 'id_msg' => $_REQUEST['msg'],
  441. 'announce_action' => 'announce_topic',
  442. )
  443. );
  444. // The message they were trying to edit was most likely deleted.
  445. // @todo Change this error message?
  446. if ($smcFunc['db_num_rows']($request) == 0)
  447. fatal_lang_error('no_board', false);
  448. $row = $smcFunc['db_fetch_assoc']($request);
  449. $attachment_stuff = array($row);
  450. while ($row2 = $smcFunc['db_fetch_assoc']($request))
  451. $attachment_stuff[] = $row2;
  452. $smcFunc['db_free_result']($request);
  453. if ($row['id_member'] == $user_info['id'] && !allowedTo('modify_any'))
  454. {
  455. // Give an extra five minutes over the disable time threshold, so they can type - assuming the post is public.
  456. if ($row['approved'] && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time())
  457. fatal_lang_error('modify_post_time_passed', false);
  458. elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_own'))
  459. isAllowedTo('modify_replies');
  460. else
  461. isAllowedTo('modify_own');
  462. }
  463. elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_any'))
  464. isAllowedTo('modify_replies');
  465. else
  466. isAllowedTo('modify_any');
  467. if (!empty($modSettings['attachmentEnable']))
  468. {
  469. $request = $smcFunc['db_query']('', '
  470. SELECT IFNULL(size, -1) AS filesize, filename, id_attach, approved
  471. FROM {db_prefix}attachments
  472. WHERE id_msg = {int:id_msg}
  473. AND attachment_type = {int:attachment_type}
  474. ORDER BY id_attach',
  475. array(
  476. 'id_msg' => (int) $_REQUEST['msg'],
  477. 'attachment_type' => 0,
  478. )
  479. );
  480. while ($row = $smcFunc['db_fetch_assoc']($request))
  481. {
  482. if ($row['filesize'] <= 0)
  483. continue;
  484. $context['current_attachments'][] = array(
  485. 'name' => htmlspecialchars($row['filename']),
  486. 'size' => $row['filesize'],
  487. 'id' => $row['id_attach'],
  488. 'approved' => $row['approved'],
  489. );
  490. }
  491. $smcFunc['db_free_result']($request);
  492. }
  493. if ($context['can_announce'] && !empty($row['id_action']))
  494. {
  495. loadLanguage('Errors');
  496. $context['post_error']['messages'][] = $txt['error_topic_already_announced'];
  497. }
  498. // Allow moderators to change names....
  499. if (allowedTo('moderate_forum') && !empty($topic))
  500. {
  501. $request = $smcFunc['db_query']('', '
  502. SELECT id_member, poster_name, poster_email
  503. FROM {db_prefix}messages
  504. WHERE id_msg = {int:id_msg}
  505. AND id_topic = {int:current_topic}
  506. LIMIT 1',
  507. array(
  508. 'current_topic' => $topic,
  509. 'id_msg' => (int) $_REQUEST['msg'],
  510. )
  511. );
  512. $row = $smcFunc['db_fetch_assoc']($request);
  513. $smcFunc['db_free_result']($request);
  514. if (empty($row['id_member']))
  515. {
  516. $context['name'] = htmlspecialchars($row['poster_name']);
  517. $context['email'] = htmlspecialchars($row['poster_email']);
  518. }
  519. }
  520. }
  521. // No check is needed, since nothing is really posted.
  522. checkSubmitOnce('free');
  523. }
  524. // Editing a message...
  525. elseif (isset($_REQUEST['msg']) && !empty($topic))
  526. {
  527. $_REQUEST['msg'] = (int) $_REQUEST['msg'];
  528. // Get the existing message.
  529. $request = $smcFunc['db_query']('', '
  530. SELECT
  531. m.id_member, m.modified_time, m.smileys_enabled, m.body,
  532. m.poster_name, m.poster_email, m.subject, m.icon, m.approved,
  533. IFNULL(a.size, -1) AS filesize, a.filename, a.id_attach,
  534. a.approved AS attachment_approved, t.id_member_started AS id_member_poster,
  535. m.poster_time, log.id_action
  536. FROM {db_prefix}messages AS m
  537. INNER JOIN {db_prefix}topics AS t ON (t.id_topic = {int:current_topic})
  538. LEFT JOIN {db_prefix}attachments AS a ON (a.id_msg = m.id_msg AND a.attachment_type = {int:attachment_type})
  539. LEFT JOIN {db_prefix}log_actions AS log ON (m.id_topic = log.id_topic AND log.action = {string:announce_action})
  540. WHERE m.id_msg = {int:id_msg}
  541. AND m.id_topic = {int:current_topic}',
  542. array(
  543. 'current_topic' => $topic,
  544. 'attachment_type' => 0,
  545. 'id_msg' => $_REQUEST['msg'],
  546. 'announce_action' => 'announce_topic',
  547. )
  548. );
  549. // The message they were trying to edit was most likely deleted.
  550. if ($smcFunc['db_num_rows']($request) == 0)
  551. fatal_lang_error('no_message', false);
  552. $row = $smcFunc['db_fetch_assoc']($request);
  553. $attachment_stuff = array($row);
  554. while ($row2 = $smcFunc['db_fetch_assoc']($request))
  555. $attachment_stuff[] = $row2;
  556. $smcFunc['db_free_result']($request);
  557. if ($row['id_member'] == $user_info['id'] && !allowedTo('modify_any'))
  558. {
  559. // Give an extra five minutes over the disable time threshold, so they can type - assuming the post is public.
  560. if ($row['approved'] && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time())
  561. fatal_lang_error('modify_post_time_passed', false);
  562. elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_own'))
  563. isAllowedTo('modify_replies');
  564. else
  565. isAllowedTo('modify_own');
  566. }
  567. elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_any'))
  568. isAllowedTo('modify_replies');
  569. else
  570. isAllowedTo('modify_any');
  571. if ($context['can_announce'] && !empty($row['id_action']))
  572. {
  573. loadLanguage('Errors');
  574. $context['post_error']['messages'][] = $txt['error_topic_already_announced'];
  575. }
  576. // When was it last modified?
  577. if (!empty($row['modified_time']))
  578. $context['last_modified'] = timeformat($row['modified_time']);
  579. // Get the stuff ready for the form.
  580. $form_subject = $row['subject'];
  581. $form_message = un_preparsecode($row['body']);
  582. censorText($form_message);
  583. censorText($form_subject);
  584. // Check the boxes that should be checked.
  585. $context['use_smileys'] = !empty($row['smileys_enabled']);
  586. $context['icon'] = $row['icon'];
  587. // Show an "approve" box if the user can approve it, and the message isn't approved.
  588. if (!$row['approved'] && !$context['show_approval'])
  589. $context['show_approval'] = allowedTo('approve_posts');
  590. // Sort the attachments so they are in the order saved
  591. $temp = array();
  592. foreach ($attachment_stuff as $attachment)
  593. {
  594. if ($attachment['filesize'] >= 0 && !empty($modSettings['attachmentEnable']))
  595. $temp[$attachment['id_attach']] = $attachment;
  596. }
  597. ksort($temp);
  598. // Load up 'em attachments!
  599. foreach ($temp as $attachment)
  600. {
  601. $context['current_attachments'][] = array(
  602. 'name' => htmlspecialchars($attachment['filename']),
  603. 'size' => $attachment['filesize'],
  604. 'id' => $attachment['id_attach'],
  605. 'approved' => $attachment['attachment_approved'],
  606. );
  607. }
  608. // Allow moderators to change names....
  609. if (allowedTo('moderate_forum') && empty($row['id_member']))
  610. {
  611. $context['name'] = htmlspecialchars($row['poster_name']);
  612. $context['email'] = htmlspecialchars($row['poster_email']);
  613. }
  614. // Set the destinaton.
  615. $context['destination'] = 'post2;start=' . $_REQUEST['start'] . ';msg=' . $_REQUEST['msg'] . ';' . $context['session_var'] . '=' . $context['session_id'] . (isset($_REQUEST['poll']) ? ';poll' : '');
  616. $context['submit_label'] = $txt['save'];
  617. }
  618. // Posting...
  619. else
  620. {
  621. // By default....
  622. $context['use_smileys'] = true;
  623. $context['icon'] = 'xx';
  624. if ($user_info['is_guest'])
  625. {
  626. $context['name'] = isset($_SESSION['guest_name']) ? $_SESSION['guest_name'] : '';
  627. $context['email'] = isset($_SESSION['guest_email']) ? $_SESSION['guest_email'] : '';
  628. }
  629. $context['destination'] = 'post2;start=' . $_REQUEST['start'] . (isset($_REQUEST['poll']) ? ';poll' : '');
  630. $context['submit_label'] = $txt['post'];
  631. // Posting a quoted reply?
  632. if (!empty($topic) && !empty($_REQUEST['quote']))
  633. {
  634. // Make sure they _can_ quote this post, and if so get it.
  635. $request = $smcFunc['db_query']('', '
  636. SELECT m.subject, IFNULL(mem.real_name, m.poster_name) AS poster_name, m.poster_time, m.body
  637. FROM {db_prefix}messages AS m
  638. INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board AND {query_see_board})
  639. LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member)
  640. WHERE m.id_msg = {int:id_msg}' . (!$modSettings['postmod_active'] || allowedTo('approve_posts') ? '' : '
  641. AND m.approved = {int:is_approved}') . '
  642. LIMIT 1',
  643. array(
  644. 'id_msg' => (int) $_REQUEST['quote'],
  645. 'is_approved' => 1,
  646. )
  647. );
  648. if ($smcFunc['db_num_rows']($request) == 0)
  649. fatal_lang_error('quoted_post_deleted', false);
  650. list ($form_subject, $mname, $mdate, $form_message) = $smcFunc['db_fetch_row']($request);
  651. $smcFunc['db_free_result']($request);
  652. // Add 'Re: ' to the front of the quoted subject.
  653. if (trim($context['response_prefix']) != '' && $smcFunc['strpos']($form_subject, trim($context['response_prefix'])) !== 0)
  654. $form_subject = $context['response_prefix'] . $form_subject;
  655. // Censor the message and subject.
  656. censorText($form_message);
  657. censorText($form_subject);
  658. // But if it's in HTML world, turn them into htmlspecialchar's so they can be edited!
  659. if (strpos($form_message, '[html]') !== false)
  660. {
  661. $parts = preg_split('~(\[/code\]|\[code(?:=[^\]]+)?\])~i', $form_message, -1, PREG_SPLIT_DELIM_CAPTURE);
  662. for ($i = 0, $n = count($parts); $i < $n; $i++)
  663. {
  664. // It goes 0 = outside, 1 = begin tag, 2 = inside, 3 = close tag, repeat.
  665. if ($i % 4 == 0)
  666. $parts[$i] = preg_replace('~\[html\](.+?)\[/html\]~ise', '\'[html]\' . preg_replace(\'~<br\s?/?' . '>~i\', \'&lt;br /&gt;<br />\', \'$1\') . \'[/html]\'', $parts[$i]);
  667. }
  668. $form_message = implode('', $parts);
  669. }
  670. $form_message = preg_replace('~<br ?/?' . '>~i', "\n", $form_message);
  671. // Remove any nested quotes, if necessary.
  672. if (!empty($modSettings['removeNestedQuotes']))
  673. $form_message = preg_replace(array('~\n?\[quote.*?\].+?\[/quote\]\n?~is', '~^\n~', '~\[/quote\]~'), '', $form_message);
  674. // Add a quote string on the front and end.
  675. $form_message = '[quote author=' . $mname . ' link=topic=' . $topic . '.msg' . (int) $_REQUEST['quote'] . '#msg' . (int) $_REQUEST['quote'] . ' date=' . $mdate . ']' . "\n" . rtrim($form_message) . "\n" . '[/quote]';
  676. }
  677. // Posting a reply without a quote?
  678. elseif (!empty($topic) && empty($_REQUEST['quote']))
  679. {
  680. // Get the first message's subject.
  681. $form_subject = $first_subject;
  682. // Add 'Re: ' to the front of the subject.
  683. if (trim($context['response_prefix']) != '' && $form_subject != '' && $smcFunc['strpos']($form_subject, trim($context['response_prefix'])) !== 0)
  684. $form_subject = $context['response_prefix'] . $form_subject;
  685. // Censor the subject.
  686. censorText($form_subject);
  687. $form_message = '';
  688. }
  689. else
  690. {
  691. $form_subject = isset($_GET['subject']) ? $_GET['subject'] : '';
  692. $form_message = '';
  693. }
  694. }
  695. $context['can_post_attachment'] = !empty($modSettings['attachmentEnable']) && $modSettings['attachmentEnable'] == 1 && (allowedTo('post_attachment') || ($modSettings['postmod_active'] && allowedTo('post_unapproved_attachments')));
  696. if ($context['can_post_attachment'])
  697. {
  698. // If there are attachments, calculate the total size and how many.
  699. $context['attachments']['total_size'] = 0;
  700. $context['attachments']['quantity'] = 0;
  701. if (!empty($context['current_attachments']))
  702. if (!empty($modSettings['currentAttachmentUploadDir']))
  703. {
  704. if (!is_array($modSettings['attachmentUploadDir']))
  705. $modSettings['attachmentUploadDir'] = unserialize($modSettings['attachmentUploadDir']);
  706. // Just use the current path for temp files.
  707. $current_attach_dir = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']];
  708. }
  709. else
  710. $current_attach_dir = $modSettings['attachmentUploadDir'];
  711. // If this isn't a new post, check the current attachments.
  712. if (isset($_REQUEST['msg']))
  713. {
  714. $context['attachments']['quantity'] = count($context['current_attachments']);
  715. foreach ($context['current_attachments'] as $attachment)
  716. $context['attachments']['total_size'] += $attachment['size'];
  717. }
  718. // A bit of house keeping first.
  719. if (!empty($_SESSION['temp_attachments']) && count($_SESSION['temp_attachments']) == 1)
  720. unset($_SESSION['temp_attachments']);
  721. if (!empty($_SESSION['temp_attachments']))
  722. {
  723. // Is this a request to delete them?
  724. if (isset($_GET['delete_temp']))
  725. {
  726. foreach ($_SESSION['temp_attachments'] as $attachID => $attachment)
  727. {
  728. if (strpos($attachID, 'post_tmp_' . $user_info['id']) !== false)
  729. if (file_exists($attachment['tmp_name']))
  730. unlink($attachment['tmp_name']);
  731. }
  732. $post_errors[] = 'temp_attachments_gone';
  733. $_SESSION['temp_attachments'] = array();
  734. }
  735. // Hmm, coming in fresh and there are files in session.
  736. elseif ($context['current_action'] != 'post2' || !empty($_POST['from_qr']))
  737. {
  738. // Let's be nice and see if they belong here first.
  739. if ((empty($_REQUEST['msg']) && empty($_SESSION['temp_attachments']['post']['msg']) && $_SESSION['temp_attachments']['post']['board'] == $board) || (!empty($_REQUEST['msg']) && $_SESSION['temp_attachments']['post']['msg'] == $_REQUEST['msg']))
  740. {
  741. // See if any files still exist before showing the warning message and the files attached.
  742. foreach ($_SESSION['temp_attachments'] as $attachID => $attachment)
  743. {
  744. if (strpos($attachID, 'post_tmp_' . $user_info['id']) === false)
  745. continue;
  746. if (file_exists($attachment['tmp_name']))
  747. {
  748. $post_errors[] = 'temp_attachments_new';
  749. $context['files_in_session_warning'] = $txt['attached_files_in_session'];
  750. unset($_SESSION['temp_attachments']['post']['files']);
  751. break;
  752. }
  753. }
  754. }
  755. else
  756. {
  757. // Since, they don't belong here. Let's inform the user that they exist..
  758. if (!empty($topic))
  759. $delete_link = '<a href="' . $scripturl . '?action=post' .(!empty($_REQUEST['msg']) ? (';msg=' . $_REQUEST['msg']) : '') . (!empty($_REQUEST['last_msg']) ? (';last_msg=' . $_REQUEST['last_msg']) : '') . ';topic=' . $topic . ';delete_temp">' . $txt['here'] . '</a>';
  760. else
  761. $delete_link = '<a href="' . $scripturl . '?action=post;board=' . $board . ';delete_temp">' . $txt['here'] . '</a>';
  762. // Compile a list of the files to show the user.
  763. $file_list = array();
  764. foreach ($_SESSION['temp_attachments'] as $attachID => $attachment)
  765. if (strpos($attachID, 'post_tmp_' . $user_info['id']) !== false)
  766. $file_list[] = $attachment['name'];
  767. $_SESSION['temp_attachments']['post']['files'] = $file_list;
  768. $file_list = '<div class="attachments">' . implode('<br />', $file_list) . '</div>';
  769. if (!empty($_SESSION['temp_attachments']['post']['msg']))
  770. {
  771. // We have a message id, so we can link back to the old topic they were trying to edit..
  772. $goback_link = '<a href="' . $scripturl . '?action=post' .(!empty($_SESSION['temp_attachments']['post']['msg']) ? (';msg=' . $_SESSION['temp_attachments']['post']['msg']) : '') . (!empty($_SESSION['temp_attachments']['post']['last_msg']) ? (';last_msg=' . $_SESSION['temp_attachments']['post']['last_msg']) : '') . ';topic=' . $_SESSION['temp_attachments']['post']['topic'] . ';additionalOptions">' . $txt['here'] . '</a>';
  773. $post_errors[] = array('temp_attachments_found', array($delete_link, $goback_link, $file_list));
  774. $context['ignore_temp_attachments'] = true;
  775. }
  776. else
  777. {
  778. $post_errors[] = array('temp_attachments_lost', array($delete_link, $file_list));
  779. $context['ignore_temp_attachments'] = true;
  780. }
  781. }
  782. }
  783. if (!empty($context['we_are_history']))
  784. $post_errors[] = $context['we_are_history'];
  785. foreach ($_SESSION['temp_attachments'] as $attachID => $attachment)
  786. {
  787. if (isset($context['ignore_temp_attachments']) || isset($_SESSION['temp_attachments']['post']['files']))
  788. break;
  789. if ($attachID != 'initial_error' && strpos($attachID, 'post_tmp_' . $user_info['id']) === false)
  790. continue;
  791. if ($attachID == 'initial_error')
  792. {
  793. $txt['error_attach_initial_error'] = $txt['attach_no_upload'] . '<div style="padding: 0 1em;">' . (is_array($attachment) ? vsprintf($txt[$attachment[0]], $attachment[1]) : $txt[$attachment]) . '</div>';
  794. $post_errors[] = 'attach_initial_error';
  795. unset($_SESSION['temp_attachments']);
  796. break;
  797. }
  798. // Show any errors which might of occured.
  799. if (!empty($attachment['errors']))
  800. {
  801. $txt['error_attach_errrors'] = empty($txt['error_attach_errrors']) ? '<br />' : '';
  802. $txt['error_attach_errrors'] .= vsprintf($txt['attach_warning'], $attachment['name']) . '<div style="padding: 0 1em;">';
  803. foreach ($attachment['errors'] as $error)
  804. $txt['error_attach_errrors'] .= (is_array($error) ? vsprintf($txt[$error[0]], $error[1]) : $txt[$error]) . '<br />';
  805. $txt['error_attach_errrors'] .= '</div>';
  806. $post_errors[] = 'attach_errrors';
  807. // Take out the trash.
  808. unset($_SESSION['temp_attachments'][$attachID]);
  809. if (file_exists($attachment['tmp_name']))
  810. unlink($attachment['tmp_name']);
  811. continue;
  812. }
  813. // More house keeping.
  814. if (!file_exists($attachment['tmp_name']))
  815. {
  816. unset($_SESSION['temp_attachments'][$attachID]);
  817. continue;
  818. }
  819. $context['attachments']['quantity']++;
  820. $context['attachments']['total_size'] += $attachment['size'];
  821. if (!isset($context['files_in_session_warning']))
  822. $context['files_in_session_warning'] = $txt['attached_files_in_session'];
  823. $context['current_attachments'][] = array(
  824. 'name' => '<u>' . htmlspecialchars($attachment['name']) . '</u>',
  825. 'size' => $attachment['size'],
  826. 'id' => $attachID,
  827. 'unchecked' => false,
  828. 'approved' => 1,
  829. );
  830. }
  831. }
  832. }
  833. // Do we need to show the visual verification image?
  834. $context['require_verification'] = !$user_info['is_mod'] && !$user_info['is_admin'] && !empty($modSettings['posts_require_captcha']) && ($user_info['posts'] < $modSettings['posts_require_captcha'] || ($user_info['is_guest'] && $modSettings['posts_require_captcha'] == -1));
  835. if ($context['require_verification'])
  836. {
  837. require_once($sourcedir . '/Subs-Editor.php');
  838. $verificationOptions = array(
  839. 'id' => 'post',
  840. );
  841. $context['require_verification'] = create_control_verification($verificationOptions);
  842. $context['visual_verification_id'] = $verificationOptions['id'];
  843. }
  844. // If they came from quick reply, and have to enter verification details, give them some notice.
  845. if (!empty($_REQUEST['from_qr']) && !empty($context['require_verification']))
  846. $post_errors[] = 'need_qr_verification';
  847. /*
  848. * There are two error types: serious and miinor. Serious errors
  849. * actually tell the user that a real error has occurred, while minor
  850. * errors are like warnings that let them know that something with
  851. * their post isn't right.
  852. */
  853. $minor_errors = array('not_approved', 'new_replies', 'old_topic', 'need_qr_verification', 'no_subject');
  854. call_integration_hook('integrate_post_errors', array($post_errors, $minor_errors));
  855. // Any errors occurred?
  856. if (!empty($post_errors))
  857. {
  858. loadLanguage('Errors');
  859. $context['error_type'] = 'minor';
  860. foreach ($post_errors as $post_error)
  861. if (is_array($post_error))
  862. {
  863. $post_error_id = $post_error[0];
  864. $context['post_error'][$post_error_id] = vsprintf($txt['error_' . $post_error_id], $post_error[1]);
  865. // If it's not a minor error flag it as such.
  866. if (!in_array($post_error_id, $minor_errors))
  867. $context['error_type'] = 'serious';
  868. }
  869. else
  870. {
  871. $context['post_error'][$post_error] = $txt['error_' . $post_error];
  872. // If it's not a minor error flag it as such.
  873. if (!in_array($post_error, $minor_errors))
  874. $context['error_type'] = 'serious';
  875. }
  876. }
  877. // What are you doing? Posting a poll, modifying, previewing, new post, or reply...
  878. if (isset($_REQUEST['poll']))
  879. $context['page_title'] = $txt['new_poll'];
  880. elseif ($context['make_event'])
  881. $context['page_title'] = $context['event']['id'] == -1 ? $txt['calendar_post_event'] : $txt['calendar_edit'];
  882. elseif (isset($_REQUEST['msg']))
  883. $context['page_title'] = $txt['modify_msg'];
  884. elseif (isset($_REQUEST['subject'], $context['preview_subject']))
  885. $context['page_title'] = $txt['preview'] . ' - ' . strip_tags($context['preview_subject']);
  886. elseif (empty($topic))
  887. $context['page_title'] = $txt['start_new_topic'];
  888. else
  889. $context['page_title'] = $txt['post_reply'];
  890. // Build the link tree.
  891. if (empty($topic))
  892. $context['linktree'][] = array(
  893. 'name' => '<em>' . $txt['start_new_topic'] . '</em>'
  894. );
  895. else
  896. $context['linktree'][] = array(
  897. 'url' => $scripturl . '?topic=' . $topic . '.' . $_REQUEST['start'],
  898. 'name' => $form_subject,
  899. 'extra_before' => '<span><strong class="nav">' . $context['page_title'] . ' ( </strong></span>',
  900. 'extra_after' => '<span><strong class="nav"> )</strong></span>'
  901. );
  902. // Give wireless a linktree url to the post screen, so that they can switch to full version.
  903. if (WIRELESS)
  904. $context['linktree'][count($context['linktree']) - 1]['url'] = $scripturl . '?action=post;' . (!empty($topic) ? 'topic=' . $topic : 'board=' . $board) . '.' . $_REQUEST['start'] . (isset($_REQUEST['msg']) ? ';msg=' . (int) $_REQUEST['msg'] . ';' . $context['session_var'] . '=' . $context['session_id'] : '');
  905. $context['subject'] = addcslashes($form_subject, '"');
  906. $context['message'] = str_replace(array('"', '<', '>', '&nbsp;'), array('&quot;', '&lt;', '&gt;', ' '), $form_message);
  907. // Are post drafts enabled?
  908. $context['drafts_save'] = !empty($modSettings['drafts_enabled']) && !empty($modSettings['drafts_post_enabled']) && allowedTo('post_draft');
  909. $context['drafts_autosave'] = !empty($context['drafts_save']) && !empty($modSettings['drafts_autosave_enabled']) && allowedTo('post_autosave_draft');
  910. // Build a list of drafts that they can load in to the editor
  911. if (!empty($context['drafts_save']))
  912. {
  913. require_once($sourcedir . '/Drafts.php');
  914. ShowDrafts($user_info['id'], $topic);
  915. }
  916. // Needed for the editor and message icons.
  917. require_once($sourcedir . '/Subs-Editor.php');
  918. // Now create the editor.
  919. $editorOptions = array(
  920. 'id' => 'message',
  921. 'value' => $context['message'],
  922. 'labels' => array(
  923. 'post_button' => $context['submit_label'],
  924. ),
  925. // add height and width for the editor
  926. 'height' => '275px',
  927. 'width' => '100%',
  928. // We do XML preview here.
  929. 'preview_type' => 2,
  930. );
  931. create_control_richedit($editorOptions);
  932. // Store the ID.
  933. $context['post_box_name'] = $editorOptions['id'];
  934. $context['attached'] = '';
  935. $context['make_poll'] = isset($_REQUEST['poll']);
  936. // Message icons - customized icons are off?
  937. $context['icons'] = getMessageIcons($board);
  938. if (!empty($context['icons']))
  939. $context['icons'][count($context['icons']) - 1]['is_last'] = true;
  940. // Are we starting a poll? if set the poll icon as selected if its available
  941. if (isset($_REQUEST['poll']))
  942. {
  943. foreach ($context['icons'] as $icons)
  944. {
  945. if (isset($icons['value']) && $icons['value'] == 'poll')
  946. {
  947. // if found we are done
  948. $context['icon'] = 'poll';
  949. break;
  950. }
  951. }
  952. }
  953. $context['icon_url'] = '';
  954. for ($i = 0, $n = count($context['icons']); $i < $n; $i++)
  955. {
  956. $context['icons'][$i]['selected'] = $context['icon'] == $context['icons'][$i]['value'];
  957. if ($context['icons'][$i]['selected'])
  958. $context['icon_url'] = $context['icons'][$i]['url'];
  959. }
  960. if (empty($context['icon_url']))
  961. {
  962. $context['icon_url'] = $settings[file_exists($settings['theme_dir'] . '/images/post/' . $context['icon'] . '.png') ? 'images_url' : 'default_images_url'] . '/post/' . $context['icon'] . '.png';
  963. array_unshift($context['icons'], array(
  964. 'value' => $context['icon'],
  965. 'name' => $txt['current_icon'],
  966. 'url' => $context['icon_url'],
  967. 'is_last' => empty($context['icons']),
  968. 'selected' => true,
  969. ));
  970. }
  971. if (!empty($topic) && !empty($modSettings['topicSummaryPosts']))
  972. getTopic();
  973. // If the user can post attachments prepare the warning labels.
  974. if ($context['can_post_attachment'])
  975. {
  976. // If they've unchecked an attachment, they may still want to attach that many more files, but don't allow more than num_allowed_attachments.
  977. $context['num_allowed_attachments'] = empty($modSettings['attachmentNumPerPostLimit']) ? 50 : min($modSettings['attachmentNumPerPostLimit'] - count($context['current_attachments']), $modSettings['attachmentNumPerPostLimit']);
  978. $context['can_post_attachment_unapproved'] = allowedTo('post_attachment');
  979. $context['attachment_restrictions'] = array();
  980. $context['allowed_extensions'] = strtr(strtolower($modSettings['attachmentExtensions']), array(',' => ', '));
  981. $attachmentRestrictionTypes = array('attachmentNumPerPostLimit', 'attachmentPostLimit', 'attachmentSizeLimit');
  982. foreach ($attachmentRestrictionTypes as $type)
  983. if (!empty($modSettings[$type]))
  984. {
  985. $context['attachment_restrictions'][] = sprintf($txt['attach_restrict_' . $type], comma_format($modSettings[$type], 0));
  986. // Show some numbers. If they exist.
  987. if ($type == 'attachmentNumPerPostLimit' && $context['attachments']['quantity'] > 0)
  988. $context['attachment_restrictions'][] = sprintf($txt['attach_remaining'], $modSettings['attachmentNumPerPostLimit'] - $context['attachments']['quantity']);
  989. elseif ($type == 'attachmentPostLimit' && $context['attachments']['total_size'] > 0)
  990. $context['attachment_restrictions'][] = sprintf($txt['attach_available'], comma_format(round(max($modSettings['attachmentPostLimit'] - ($context['attachments']['total_size'] / 1028), 0)), 0));
  991. }
  992. }
  993. $context['back_to_topic'] = isset($_REQUEST['goback']) || (isset($_REQUEST['msg']) && !isset($_REQUEST['subject']));
  994. $context['show_additional_options'] = !empty($_POST['additional_options']) || isset($_SESSION['temp_attachments']['post']) || isset($_GET['additionalOptions']);
  995. $context['is_new_topic'] = empty($topic);
  996. $context['is_new_post'] = !isset($_REQUEST['msg']);
  997. $context['is_first_post'] = $context['is_new_topic'] || (isset($_REQUEST['msg']) && $_REQUEST['msg'] == $id_first_msg);
  998. // WYSIWYG only works if BBC is enabled
  999. $modSettings['disable_wysiwyg'] = !empty($modSettings['disable_wysiwyg']) || empty($modSettings['enableBBC']);
  1000. // Register this form in the session variables.
  1001. checkSubmitOnce('register');
  1002. // Finally, load the template.
  1003. if (WIRELESS && WIRELESS_PROTOCOL != 'wap')
  1004. $context['sub_template'] = WIRELESS_PROTOCOL . '_post';
  1005. elseif (!isset($_REQUEST['xml']))
  1006. loadTemplate('Post');
  1007. }
  1008. /**
  1009. * Posts or saves the message composed with Post().
  1010. *
  1011. * requires various permissions depending on the action.
  1012. * handles attachment, post, and calendar saving.
  1013. * sends off notifications, and allows for announcements and moderation.
  1014. * accessed from ?action=post2.
  1015. */
  1016. function Post2()
  1017. {
  1018. global $board, $topic, $txt, $modSettings, $sourcedir, $context;
  1019. global $user_info, $board_info, $options, $smcFunc;
  1020. // Sneaking off, are we?
  1021. if (empty($_POST) && empty($topic))
  1022. {
  1023. if (empty($_SERVER['CONTENT_LENGTH']))
  1024. redirectexit('action=post;board=' . $board . '.0');
  1025. else
  1026. fatal_lang_error('post_upload_error', false);
  1027. }
  1028. elseif (empty($_POST) && !empty($topic))
  1029. redirectexit('action=post;topic=' . $topic . '.0');
  1030. // No need!
  1031. $context['robot_no_index'] = true;
  1032. // Previewing? Go back to start.
  1033. if (isset($_REQUEST['preview']))
  1034. return Post();
  1035. // Prevent double submission of this form.
  1036. checkSubmitOnce('check');
  1037. // No errors as yet.
  1038. $post_errors = array();
  1039. // If the session has timed out, let the user re-submit their form.
  1040. if (checkSession('post', '', false) != '')
  1041. $post_errors[] = 'session_timeout';
  1042. // Wrong verification code?
  1043. if (!$user_info['is_admin'] && !$user_info['is_mod'] && !empty($modSettings['posts_require_captcha']) && ($user_info['posts'] < $modSettings['posts_require_captcha'] || ($user_info['is_guest'] && $modSettings['posts_require_captcha'] == -1)))
  1044. {
  1045. require_once($sourcedir . '/Subs-Editor.php');
  1046. $verificationOptions = array(
  1047. 'id' => 'post',
  1048. );
  1049. $context['require_verification'] = create_control_verification($verificationOptions, true);
  1050. if (is_array($context['require_verification']))
  1051. $post_errors = array_merge($post_errors, $context['require_verification']);
  1052. }
  1053. require_once($sourcedir . '/Subs-Post.php');
  1054. loadLanguage('Post');
  1055. // Drafts enabled?
  1056. if (!empty($modSettings['drafts_enabled']) && isset($_POST['save_draft']))
  1057. require_once($sourcedir . '/Drafts.php');
  1058. // First check to see if they are trying to delete any current attachments.
  1059. if (isset($_POST['attach_del']))
  1060. {
  1061. $keep_temp = array();
  1062. $keep_ids = array();
  1063. foreach ($_POST['attach_del'] as $dummy)
  1064. if (strpos($dummy, 'post_tmp_' . $user_info['id']) !== false)
  1065. $keep_temp[] = $dummy;
  1066. else
  1067. $keep_ids[] = (int) $dummy;
  1068. if (isset($_SESSION['temp_attachments']))
  1069. foreach($_SESSION['temp_attachments'] as $attachID => $attachment)
  1070. {
  1071. if ((isset($_SESSION['temp_attachments']['post']['files'], $attachment['name']) && in_array($attachment['name'], $_SESSION['temp_attachments']['post']['files'])) || in_array($attachID, $keep_temp) || strpos($attachID, 'post_tmp_' . $user_info['id']) === false)
  1072. continue;
  1073. unset($_SESSION['temp_attachments'][$attachID]);
  1074. unlink($attachment['tmp_name']);
  1075. }
  1076. if (!empty($_REQUEST['msg']))
  1077. {
  1078. require_once($sourcedir . '/ManageAttachments.php');
  1079. $attachmentQuery = array(
  1080. 'attachment_type' => 0,
  1081. 'id_msg' => (int) $_REQUEST['msg'],
  1082. 'not_id_attach' => $keep_ids,
  1083. );
  1084. removeAttachments($attachmentQuery);
  1085. }
  1086. }
  1087. // Then try to upload any attachments.
  1088. $context['can_post_attachment'] = !empty($modSettings['attachmentEnable']) && $modSettings['attachmentEnable'] == 1 && (allowedTo('post_attachment') || ($modSettings['postmod_active'] && allowedTo('post_unapproved_attachments')));
  1089. if ($context['can_post_attachment'] && !empty($_FILES['attachment']) && empty($_POST['from_qr']))
  1090. {
  1091. // Make sure we're uploading to the right place.
  1092. if (!empty($modSettings['currentAttachmentUploadDir']))
  1093. {
  1094. if (!is_array($modSettings['attachmentUploadDir']))
  1095. $modSettings['attachmentUploadDir'] = unserialize($modSettings['attachmentUploadDir']);
  1096. // The current directory, of course!
  1097. $context['attach_dir'] = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']];
  1098. }
  1099. else
  1100. $context['attach_dir'] = $modSettings['attachmentUploadDir'];
  1101. // Is the attachments folder actualy there?
  1102. if (!is_dir($context['attach_dir']))
  1103. {
  1104. $initial_error = 'attach_folder_warning';
  1105. log_error(sprintf($txt['attach_folder_admin_warning'], $context['attach_dir']), 'critical');
  1106. }
  1107. // Check that the attachments folder is writable. No sense in proceeding if it isn't.
  1108. if (empty($initial_error) && !is_writable($context['attach_dir']))
  1109. {
  1110. // But, let's try to make it writable first.
  1111. chmod($context['attach_dir'], 0755);
  1112. if (!is_writable($context['attach_dir']))
  1113. {
  1114. chmod($context['attach_dir'], 0775);
  1115. if (!is_writable($context['attach_dir']))
  1116. {
  1117. chmod($context['attach_dir'], 0777);
  1118. if (!is_writable($context['attach_dir']))
  1119. $initial_error = 'attachments_no_write';
  1120. }
  1121. }
  1122. }
  1123. if (!isset($initial_error) && !isset($context['attachments']))
  1124. {
  1125. // If this isn't a new post, check the current attachments.
  1126. if (isset($_REQUEST['msg']))
  1127. {
  1128. $request = $smcFunc['db_query']('', '
  1129. SELECT COUNT(*), SUM(size)
  1130. FROM {db_prefix}attachments
  1131. WHERE id_msg = {int:id_msg}
  1132. AND attachment_type = {int:attachment_type}',
  1133. array(
  1134. 'id_msg' => (int) $_REQUEST['msg'],
  1135. 'attachment_type' => 0,
  1136. )
  1137. );
  1138. list ($context['attachments']['quantity'], $context['attachments']['total_size']) = $smcFunc['db_fetch_row']($request);
  1139. $smcFunc['db_free_result']($request);
  1140. }
  1141. else
  1142. $context['attachments'] = array(
  1143. 'quantity' => 0,
  1144. 'total_size' => 0,
  1145. );
  1146. }
  1147. // Hmm. There are still files in session.
  1148. $ignore_temp = false;
  1149. if (!empty($_SESSION['temp_attachments']['post']['files']) && count($_SESSION['temp_attachments']) > 1)
  1150. {
  1151. // Let's try to keep them. But...
  1152. $ignore_temp = true;
  1153. // If new files are being added. We can't ignore those
  1154. foreach ($_FILES['attachment']['tmp_name'] as $dummy)
  1155. if (!empty($dummy))
  1156. {
  1157. $ignore_temp = false;
  1158. break;
  1159. }
  1160. // Need to make space for the new files. So, bye bye.
  1161. if (!$ignore_temp)
  1162. {
  1163. foreach ($_SESSION['temp_attachments'] as $attachID => $attachment)
  1164. if (strpos($attachID, 'post_tmp_' . $user_info['id']) !== false)
  1165. unlink($attachment['tmp_name']);
  1166. $context['we_are_history'] = 'temp_attachments_flushed';
  1167. $_SESSION['temp_attachments'] = array();
  1168. }
  1169. }
  1170. if (!isset($_FILES['attachment']['name']))
  1171. $_FILES['attachment']['tmp_name'] = array();
  1172. if (!isset($_SESSION['temp_attachments']))
  1173. $_SESSION['temp_attachments'] = array();
  1174. // Remember where we are at. If it's anywhere at all.
  1175. if (!$ignore_temp)
  1176. $_SESSION['temp_attachments']['post'] = array(
  1177. 'msg' => !empty($_REQUEST['msg']) ? $_REQUEST['msg'] : 0,
  1178. 'last_msg' => !empty($_REQUEST['last_msg']) ? $_REQUEST['last_msg'] : 0,
  1179. 'topic' => !empty($topic) ? $topic : 0,
  1180. 'board' => !empty($board) ? $board : 0,
  1181. );
  1182. // If we have an itital error, lets just display it.
  1183. if (!empty($initial_error))
  1184. {
  1185. $_SESSION['temp_attachments']['initial_error'] = $initial_error;
  1186. // And delete the files 'cos they ain't going nowhere.
  1187. foreach ($_FILES['attachment']['tmp_name'] as $n => $dummy)
  1188. if (file_exists($_FILES['attachment']['tmp_name'][$n]))
  1189. unlink($_FILES['attachment']['tmp_name'][$n]);
  1190. $_FILES['attachment']['tmp_name'] = array();
  1191. }
  1192. // Loop through $_FILES['attachment'] array and move each file to the current attachments folder.
  1193. foreach ($_FILES['attachment']['tmp_name'] as $n => $dummy)
  1194. {
  1195. if ($_FILES['attachment']['name'][$n] == '')
  1196. continue;
  1197. // First, let's first check for PHP upload errors.
  1198. $errors = array();
  1199. if (!empty($_FILES['attachment']['error'][$n]))
  1200. {
  1201. if ($_FILES['attachment']['error'][$n] == 2)
  1202. $errors[] = array('file_too_big', array($modSettings['attachmentSizeLimit']));
  1203. elseif ($_FILES['attachment']['error'][$n] == 6)
  1204. log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_6'], 'critical');
  1205. else
  1206. log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_' . $_FILES['attachment']['error'][$n]]);
  1207. if (empty($errors))
  1208. $errors[] = 'attach_php_error';
  1209. }
  1210. // Try to move and rename the file before doing any more checks on it.
  1211. $attachID = 'post_tmp_' . $user_info['id'] . '_' . md5(mt_rand());
  1212. $destName = $context['attach_dir'] . '/' . $attachID;
  1213. if (empty($errors))
  1214. {
  1215. $_SESSION['temp_attachments'][$attachID] = array(
  1216. 'name' => htmlspecialchars(basename($_FILES['attachment']['name'][$n])),
  1217. 'tmp_name' => $destName,
  1218. 'size' => $_FILES['attachment']['size'][$n],
  1219. 'type' => $_FILES['attachment']['type'][$n],
  1220. 'errors' => array(),
  1221. );
  1222. // Move the file to the attachments folder with a temp name for now.
  1223. if (@move_uploaded_file($_FILES['attachment']['tmp_name'][$n], $destName))
  1224. @chmod($destName, 0644);
  1225. else
  1226. {
  1227. $_SESSION['temp_attachments'][$attachID]['errors'][] = 'attach_timeout';
  1228. if (file_exists($_FILES['attachment']['tmp_name'][$n]))
  1229. unlink($_FILES['attachment']['tmp_name'][$n]);
  1230. }
  1231. }
  1232. else
  1233. {
  1234. $_SESSION['temp_attachments'][$attachID] = array(
  1235. 'name' => htmlspecialchars(basename($_FILES['attachment']['name'][$n])),
  1236. 'tmp_name' => $destName,
  1237. 'errors' => $errors,
  1238. );
  1239. if (file_exists($_FILES['attachment']['tmp_name'][$n]))
  1240. unlink($_FILES['attachment']['tmp_name'][$n]);
  1241. }
  1242. // If there's no errors to this pont. We still do need to apply some addtional checks before we are finished.
  1243. if (empty($_SESSION['temp_attachments'][$attachID]['errors']))
  1244. attachmentChecks($attachID);
  1245. }
  1246. }
  1247. // Mod authors, finally a hook to hang an alternate attachment upload system upon
  1248. // Upload to the current attachment folder with the file name $attachID or 'post_tmp_' . $user_info['id'] . '_' . md5(mt_rand())
  1249. // Populate $_SESSION['temp_attachments'][$attachID] with the following:
  1250. // name => The file name
  1251. // tmp_name => Path to the temp file ($context['attach_dir'] . '/' . $attachID).
  1252. // size => File size (required).
  1253. // type => MIME type (optional if not available on upload).
  1254. // errors => An array of errors (use the index of the $txt variable for that error).
  1255. // Template changes can be done using "integrate_upload_template".
  1256. call_integration_hook('integrate_attachment_upload');
  1257. // If this isn't a new topic load the topic info that we need.
  1258. if (!empty($topic))
  1259. {
  1260. $request = $smcFunc['db_query']('', '
  1261. SELECT locked, is_sticky, id_poll, approved, id_first_msg, id_last_msg, id_member_started, id_board
  1262. FROM {db_prefix}topics
  1263. WHERE id_topic = {int:current_topic}
  1264. LIMIT 1',
  1265. array(
  1266. 'current_topic' => $topic,
  1267. )
  1268. );
  1269. $topic_info = $smcFunc['db_fetch_assoc']($request);
  1270. $smcFunc['db_free_result']($request);
  1271. // Though the topic should be there, it might have vanished.
  1272. if (!is_array($topic_info))
  1273. fatal_lang_error('topic_doesnt_exist');
  1274. // Did this topic suddenly move? Just checking...
  1275. if ($topic_info['id_board'] != $board)
  1276. fatal_lang_error('not_a_topic');
  1277. }
  1278. // Replying to a topic?
  1279. if (!empty($topic) && !isset($_REQUEST['msg']))
  1280. {
  1281. // Don't allow a post if it's locked.
  1282. if ($topic_info['locked'] != 0 && !allowedTo('moderate_board'))
  1283. fatal_lang_error('topic_locked', false);
  1284. // Sorry, multiple polls aren't allowed... yet. You should stop giving me ideas :P.
  1285. if (isset($_REQUEST['poll']) && $topic_info['id_poll'] > 0)
  1286. unset($_REQUEST['poll']);
  1287. // Do the permissions and approval stuff...
  1288. $becomesApproved = true;
  1289. if ($topic_info['id_member_started'] != $user_info['id'])
  1290. {
  1291. if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_any') && !allowedTo('post_reply_any'))
  1292. $becomesApproved = false;
  1293. else
  1294. isAllowedTo('post_reply_any');
  1295. }
  1296. elseif (!allowedTo('post_reply_any'))
  1297. {
  1298. if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_own') && !allowedTo('post_reply_own'))
  1299. $becomesApproved = false;
  1300. else
  1301. isAllowedTo('post_reply_own');
  1302. }
  1303. if (isset($_POST['lock']))
  1304. {
  1305. // Nothing is changed to the lock.
  1306. if ((empty($topic_info['locked']) && empty($_POST['lock'])) || (!empty($_POST['lock']) && !empty($topic_info['locked'])))
  1307. unset($_POST['lock']);
  1308. // You're have no permission to lock this topic.
  1309. elseif (!allowedTo(array('lock_any', 'lock_own')) || (!allowedTo('lock_any') && $user_info['id'] != $topic_info['id_member_started']))
  1310. unset($_POST['lock']);
  1311. // You are allowed to (un)lock your own topic only.
  1312. elseif (!allowedTo('lock_any'))
  1313. {
  1314. // You cannot override a moderator lock.
  1315. if ($topic_info['locked'] == 1)
  1316. unset($_POST['lock']);
  1317. else
  1318. $_POST['lock'] = empty($_POST['lock']) ? 0 : 2;
  1319. }
  1320. // Hail mighty moderator, (un)lock this topic immediately.
  1321. else
  1322. $_POST['lock'] = empty($_POST['lock']) ? 0 : 1;
  1323. }
  1324. // So you wanna (un)sticky this...let's see.
  1325. if (isset($_POST['sticky']) && (empty($modSettings['enableStickyTopics']) || $_POST['sticky'] == $topic_info['is_sticky'] || !allowedTo('make_sticky')))
  1326. unset($_POST['sticky']);
  1327. // If drafts are enabled, then pass this off
  1328. if (!empty($modSettings['drafts_enabled']) && isset($_POST['save_draft']))
  1329. {
  1330. SaveDraft($post_errors);
  1331. return Post();
  1332. }
  1333. // If the number of replies has changed, if the setting is enabled, go back to Post() - which handles the error.
  1334. if (empty($options['no_new_reply_warning']) && isset($_POST['last_msg']) && $topic_info['id_last_msg'] > $_POST['last_msg'])
  1335. {
  1336. $_REQUEST['preview'] = true;
  1337. return Post();
  1338. }
  1339. $posterIsGuest = $user_info['is_guest'];
  1340. }
  1341. // Posting a new topic.
  1342. elseif (empty($topic))
  1343. {
  1344. // Now don't be silly, new topics will get their own id_msg soon enough.
  1345. unset($_REQUEST['msg'], $_POST['msg'], $_GET['msg']);
  1346. // Do like, the permissions, for safety and stuff...
  1347. $becomesApproved = true;
  1348. if ($modSettings['postmod_active'] && !allowedTo('post_new') && allowedTo('post_unapproved_topics'))
  1349. $becomesApproved = false;
  1350. else
  1351. isAllowedTo('post_new');
  1352. if (isset($_POST['lock']))
  1353. {
  1354. // New topics are by default not locked.
  1355. if (empty($_POST['lock']))
  1356. unset($_POST['lock']);
  1357. // Besides, you need permission.
  1358. elseif (!allowedTo(array('lock_any', 'lock_own')))
  1359. unset($_POST['lock']);
  1360. // A moderator-lock (1) can override a user-lock (2).
  1361. else
  1362. $_POST['lock'] = allowedTo('lock_any') ? 1 : 2;
  1363. }
  1364. if (isset($_POST['sticky']) && (empty($modSettings['enableStickyTopics']) || empty($_POST['sticky']) || !allowedTo('make_sticky')))
  1365. unset($_POST['sticky']);
  1366. // Saving your new topic as a draft first?
  1367. if (!empty($modSettings['drafts_enabled']) && isset($_POST['save_draft']))
  1368. {
  1369. SaveDraft($post_errors);
  1370. return Post();
  1371. }
  1372. $posterIsGuest = $user_info['is_guest'];
  1373. }
  1374. // Modifying an existing message?
  1375. elseif (isset($_REQUEST['msg']) && !empty($topic))
  1376. {
  1377. $_REQUEST['msg'] = (int) $_REQUEST['msg'];
  1378. $request = $smcFunc['db_query']('', '
  1379. SELECT id_member, poster_name, poster_email, poster_time, approved
  1380. FROM {db_prefix}messages
  1381. WHERE id_msg = {int:id_msg}
  1382. LIMIT 1',
  1383. array(
  1384. 'id_msg' => $_REQUEST['msg'],
  1385. )
  1386. );
  1387. if ($smcFunc['db_num_rows']($request) == 0)
  1388. fatal_lang_error('cant_find_messages', false);
  1389. $row = $smcFunc['db_fetch_assoc']($request);
  1390. $smcFunc['db_free_result']($request);
  1391. if (!empty($topic_info['locked']) && !allowedTo('moderate_board'))
  1392. fatal_lang_error('topic_locked', false);
  1393. if (isset($_POST['lock']))
  1394. {
  1395. // Nothing changes to the lock status.
  1396. if ((empty($_POST['lock']) && empty($topic_info['locked'])) || (!empty($_POST['lock']) && !empty($topic_info['locked'])))
  1397. unset($_POST['lock']);
  1398. // You're simply not allowed to (un)lock this.
  1399. elseif (!allowedTo(array('lock_any', 'lock_own')) || (!allowedTo('lock_any') && $user_info['id'] != $topic_info['id_member_started']))
  1400. unset($_POST['lock']);
  1401. // You're only allowed to lock your own topics.
  1402. elseif (!allowedTo('lock_any'))
  1403. {
  1404. // You're not allowed to break a moderator's lock.
  1405. if ($topic_info['locked'] == 1)
  1406. unset($_POST['lock']);
  1407. // Lock it with a soft lock or unlock it.
  1408. else
  1409. $_POST['lock'] = empty($_POST['lock']) ? 0 : 2;
  1410. }
  1411. // You must be the moderator.
  1412. else
  1413. $_POST['lock'] = empty($_POST['lock']) ? 0 : 1;
  1414. }
  1415. // Change the sticky status of this topic?
  1416. if (isset($_POST['sticky']) && (!allowedTo('make_sticky') || $_POST['sticky'] == $topic_info['is_sticky']))
  1417. unset($_POST['sticky']);
  1418. if ($row['id_member'] == $user_info['id'] && !allowedTo('modify_any'))
  1419. {
  1420. if ((!$modSettings['postmod_active'] || $row['approved']) && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time())
  1421. fatal_lang_error('modify_post_time_passed', false);
  1422. elseif ($topic_info['id_member_started'] == $user_info['id'] && !allowedTo('modify_own'))
  1423. isAllowedTo('modify_replies');
  1424. else
  1425. isAllowedTo('modify_own');
  1426. }
  1427. elseif ($topic_info['id_member_started'] == $user_info['id'] && !allowedTo('modify_any'))
  1428. {
  1429. isAllowedTo('modify_replies');
  1430. // If you're modifying a reply, I say it better be logged...
  1431. $moderationAction = true;
  1432. }
  1433. else
  1434. {
  1435. isAllowedTo('modify_any');
  1436. // Log it, assuming you're not modifying your own post.
  1437. if ($row['id_member'] != $user_info['id'])
  1438. $moderationAction = true;
  1439. }
  1440. // If drafts are enabled, then lets send this off to save
  1441. if (!empty($modSettings['drafts_enabled']) && isset($_POST['save_draft']))
  1442. {
  1443. SaveDraft($post_errors);
  1444. return Post();
  1445. }
  1446. $posterIsGuest = empty($row['id_member']);
  1447. // Can they approve it?
  1448. $can_approve = allowedTo('approve_posts');
  1449. $becomesApproved = $modSettings['postmod_active'] ? ($can_approve && !$row['approved'] ? (!empty($_REQUEST['approve']) ? 1 : 0) : $row['approved']) : 1;
  1450. $approve_has_changed = $row['approved'] != $becomesApproved;
  1451. if (!allowedTo('moderate_forum') || !$posterIsGuest)
  1452. {
  1453. $_POST['guestname'] = $row['poster_name'];
  1454. $_POST['email'] = $row['poster_email'];
  1455. }
  1456. }
  1457. // Incase we want to override
  1458. if (allowedTo('approve_posts'))
  1459. {
  1460. $becomesApproved = !isset($_REQUEST['approve']) || !empty($_REQUEST['approve']) ? 1 : 0;
  1461. $approve_has_changed = isset($row['approved']) ? $row['approved'] != $becomesApproved : false;
  1462. }
  1463. // If the poster is a guest evaluate the legality of name and email.
  1464. if ($posterIsGuest)
  1465. {
  1466. $_POST['guestname'] = !isset($_POST['guestname']) ? '' : trim($_POST['guestname']);
  1467. $_POST['email'] = !isset($_POST['email']) ? '' : trim($_POST['email']);
  1468. if ($_POST['guestname'] == '' || $_POST['guestname'] == '_')
  1469. $post_errors[] = 'no_name';
  1470. if ($smcFunc['strlen']($_POST['guestname']) > 25)
  1471. $post_errors[] = 'long_name';
  1472. if (empty($modSettings['guest_post_no_email']))
  1473. {
  1474. // Only check if they changed it!
  1475. if (!isset($row) || $row['poster_email'] != $_POST['email'])
  1476. {
  1477. if (!allowedTo('moderate_forum') && (!isset($_POST['email']) || $_POST['email'] == ''))
  1478. $post_errors[] = 'no_email';
  1479. if (!allowedTo('moderate_forum') && preg_match('~^[0-9A-Za-z=_+\-/][0-9A-Za-z=_\'+\-/\.]*@[\w\-]+(\.[\w\-]+)*(\.[\w]{2,6})$~', $_POST['email']) == 0)
  1480. $post_errors[] = 'bad_email';
  1481. }
  1482. // Now make sure this email address is not banned from posting.
  1483. isBannedEmail($_POST['email'], 'cannot_post', sprintf($txt['you_are_post_banned'], $txt['guest_title']));
  1484. }
  1485. // In case they are making multiple posts this visit, help them along by storing their name.
  1486. if (empty($post_errors))
  1487. {
  1488. $_SESSION['guest_name'] = $_POST['guestname'];
  1489. $_SESSION['guest_email'] = $_POST['email'];
  1490. }
  1491. }
  1492. // Check the subject and message.
  1493. if (!isset($_POST['subject']) || $smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_POST['subject'])) === '')
  1494. $post_errors[] = 'no_subject';
  1495. if (!isset($_POST['message']) || $smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_POST['message']), ENT_QUOTES) === '')
  1496. $post_errors[] = 'no_message';
  1497. elseif (!empty($modSettings['max_messageLength']) && $smcFunc['strlen']($_POST['message']) > $modSettings['max_messageLength'])
  1498. $post_errors[] = array('long_message', array($modSettings['max_messageLength']));
  1499. else
  1500. {
  1501. // Prepare the message a bit for some additional testing.
  1502. $_POST['message'] = $smcFunc['htmlspecialchars']($_POST['message'], ENT_QUOTES);
  1503. // Preparse code. (Zef)
  1504. if ($user_info['is_guest'])
  1505. $user_info['name'] = $_POST['guestname'];
  1506. preparsecode($_POST['message']);
  1507. // Let's see if there's still some content left without the tags.
  1508. if ($smcFunc['htmltrim'](strip_tags(parse_bbc($_POST['message'], false), '<img>')) === '' && (!allowedTo('admin_forum') || strpos($_POST['message'], '[html]') === false))
  1509. $post_errors[] = 'no_message';
  1510. }
  1511. if (isset($_POST['calendar']) && !isset($_REQUEST['deleteevent']) && $smcFunc['htmltrim']($_POST['evtitle']) === '')
  1512. $post_errors[] = 'no_event';
  1513. // You are not!
  1514. if (isset($_POST['message']) && strtolower($_POST['message']) == 'i am the administrator.' && !$user_info['is_admin'])
  1515. fatal_error('Knave! Masquerader! Charlatan!', false);
  1516. // Validate the poll...
  1517. if (isset($_REQUEST['poll']) && $modSettings['pollMode'] == '1')
  1518. {
  1519. if (!empty($topic) && !isset($_REQUEST['msg']))
  1520. fatal_lang_error('no_access', false);
  1521. // This is a new topic... so it's a new poll.
  1522. if (empty($topic))
  1523. isAllowedTo('poll_post');
  1524. // Can you add to your own topics?
  1525. elseif ($user_info['id'] == $topic_info['id_member_started'] && !allowedTo('poll_add_any'))
  1526. isAllowedTo('poll_add_own');
  1527. // Can you add polls to any topic, then?
  1528. else
  1529. isAllowedTo('poll_add_any');
  1530. if (!isset($_POST['question']) || trim($_POST['question']) == '')
  1531. $post_errors[] = 'no_question';
  1532. $_POST['options'] = empty($_POST['options']) ? array() : htmltrim__recursive($_POST['options']);
  1533. // Get rid of empty ones.
  1534. foreach ($_POST['options'] as $k => $option)
  1535. if ($option == '')
  1536. unset($_POST['options'][$k], $_POST['options'][$k]);
  1537. // What are you going to vote between with one choice?!?
  1538. if (count($_POST['options']) < 2)
  1539. $post_errors[] = 'poll_few';
  1540. elseif (count($_POST['options']) > 256)
  1541. $post_errors[] = 'poll_many';
  1542. }
  1543. if ($posterIsGuest)
  1544. {
  1545. // If user is a guest, make sure the chosen name isn't taken.
  1546. require_once($sourcedir . '/Subs-Members.php');
  1547. if (isReservedName($_POST['guestname'], 0, true, false) && (!isset($row['poster_name']) || $_POST['guestname'] != $row['poster_name']))
  1548. $post_errors[] = 'bad_name';
  1549. }
  1550. // If the user isn't a guest, get his or her name and email.
  1551. elseif (!isset($_REQUEST['msg']))
  1552. {
  1553. $_POST['guestname'] = $user_info['username'];
  1554. $_POST['email'] = $user_info['email'];
  1555. }
  1556. // Any mistakes?
  1557. if (!empty($post_errors))
  1558. {
  1559. // Previewing.
  1560. $_REQUEST['preview'] = true;
  1561. return Post($post_errors);
  1562. }
  1563. // Make sure the user isn't spamming the board.
  1564. if (!isset($_REQUEST['msg']))
  1565. spamProtection('post');
  1566. // At about this point, we're posting and that's that.
  1567. ignore_user_abort(true);
  1568. @set_time_limit(300);
  1569. // Add special html entities to the subject, name, and email.
  1570. $_POST['subject'] = strtr($smcFunc['htmlspecialchars']($_POST['subject']), array("\r" => '', "\n" => '', "\t" => ''));
  1571. $_POST['guestname'] = htmlspecialchars($_POST['guestname']);
  1572. $_POST['email'] = htmlspecialchars($_POST['email']);
  1573. // At this point, we want to make sure the subject isn't too long.
  1574. if ($smcFunc['strlen']($_POST['subject']) > 100)
  1575. $_POST['subject'] = $smcFunc['substr']($_POST['subject'], 0, 100);
  1576. // Make the poll...
  1577. if (isset($_REQUEST['poll']))
  1578. {
  1579. // Make sure that the user has not entered a ridiculous number of options..
  1580. if (empty($_POST['poll_max_votes']) || $_POST['poll_max_votes'] <= 0)
  1581. $_POST['poll_max_votes'] = 1;
  1582. elseif ($_POST['poll_max_votes'] > count($_POST['options']))
  1583. $_POST['poll_max_votes'] = count($_POST['options']);
  1584. else
  1585. $_POST['poll_max_votes'] = (int) $_POST['poll_max_votes'];
  1586. $_POST['poll_expire'] = (int) $_POST['poll_expire'];
  1587. $_POST['poll_expire'] = $_POST['poll_expire'] > 9999 ? 9999 : ($_POST['poll_expire'] < 0 ? 0 : $_POST['poll_expire']);
  1588. // Just set it to zero if it's not there..
  1589. if (!isset($_POST['poll_hide']))
  1590. $_POST['poll_hide'] = 0;
  1591. else
  1592. $_POST['poll_hide'] = (int) $_POST['poll_hide'];
  1593. $_POST['poll_change_vote'] = isset($_POST['poll_change_vote']) ? 1 : 0;
  1594. $_POST['poll_guest_vote'] = isset($_POST['poll_guest_vote']) ? 1 : 0;
  1595. // Make sure guests are actually allowed to vote generally.
  1596. if ($_POST['poll_guest_vote'])
  1597. {
  1598. require_once($sourcedir . '/Subs-Members.php');
  1599. $allowedVoteGroups = groupsAllowedTo('poll_vote', $board);
  1600. if (!in_array(-1, $allowedVoteGroups['allowed']))
  1601. $_POST['poll_guest_vote'] = 0;
  1602. }
  1603. // If the user tries to set the poll too far in advance, don't let them.
  1604. if (!empty($_POST['poll_expire']) && $_POST['poll_expire'] < 1)
  1605. fatal_lang_error('poll_range_error', false);
  1606. // Don't allow them to select option 2 for hidden results if it's not time limited.
  1607. elseif (empty($_POST['poll_expire']) && $_POST['poll_hide'] == 2)
  1608. $_POST['poll_hide'] = 1;
  1609. // Clean up the question and answers.
  1610. $_POST['question'] = htmlspecialchars($_POST['question']);
  1611. $_POST['question'] = $smcFunc['truncate']($_POST['question'], 255);
  1612. $_POST['question'] = preg_replace('~&amp;#(\d{4,5}|[2-9]\d{2,4}|1[2-9]\d);~', '&#$1;', $_POST['question']);
  1613. $_POST['options'] = htmlspecialchars__recursive($_POST['options']);
  1614. }
  1615. // ...or attach a new file...
  1616. if (empty($ignore_temp) && $context['can_post_attachment'] && !empty($_SESSION['temp_attachments']) && empty($_POST['from_qr']))
  1617. {
  1618. $attachIDs = array();
  1619. $attach_errors = array();
  1620. if (!empty($context['we_are_history']))
  1621. $attach_errors[] = '<dd>' . $txt['error_temp_attachments_flushed'] . '<br /><br /></dd>';
  1622. foreach ($_SESSION['temp_attachments'] as $attachID => $attachment)
  1623. {
  1624. if ($attachID != 'initial_error' && strpos($attachID, 'post_tmp_' . $user_info['id']) === false)
  1625. continue;
  1626. // If there was an initial error just show that message.
  1627. if ($attachID == 'initial_error')
  1628. {
  1629. $attach_errors[] = '<dt>' . $txt['attach_no_upload'] . '</dt>';
  1630. $attach_errors[] = '<dd>' . (is_array($attachment) ? vsprintf($txt[$attachment[0]], $attachment[1]) : $txt[$attachment]) . '</dd>';
  1631. unset($_SESSION['temp_attachments']);
  1632. break;
  1633. }
  1634. $attachmentOptions = array(
  1635. 'post' => isset($_REQUEST['msg']) ? $_REQUEST['msg'] : 0,
  1636. 'poster' => $user_info['id'],
  1637. 'name' => $attachment['name'],
  1638. 'tmp_name' => $attachment['tmp_name'],
  1639. 'size' => isset($attachment['size']) ? $attachment['size'] : 0,
  1640. 'mime_type' => isset($attachment['type']) ? $attachment['type'] : '',
  1641. 'approved' => !$modSettings['postmod_active'] || allowedTo('post_attachment'),
  1642. 'errors' => $attachment['errors'],
  1643. );
  1644. if (empty($attachment['errors']))
  1645. {
  1646. if (createAttachment($attachmentOptions))
  1647. {
  1648. $attachIDs[] = $attachmentOptions['id'];
  1649. if (!empty($attachmentOptions['thumb']))
  1650. $attachIDs[] = $attachmentOptions['thumb'];
  1651. }
  1652. }
  1653. if (!empty($attachmentOptions['errors']))
  1654. {
  1655. if (isset($br))
  1656. $attach_errors[] = '<dt>&nbsp;</dt>';
  1657. else
  1658. $br = '';
  1659. // Sort out the errors for display and delete any associated files.
  1660. $attach_errors[] = '<dt>' . vsprintf($txt['attach_warning'], $attachment['name']) . '</dt>';
  1661. $log_these = array('attachments_no_write', 'attach_timeout', 'ran_out_of_space', 'cant_access_upload_path', 'attach_0_byte_file');
  1662. foreach ($attachmentOptions['errors'] as $error)
  1663. {
  1664. if (!is_array($error))
  1665. {
  1666. $attach_errors[] = '<dd>' . $txt[$error] . '</dd>';
  1667. if (in_array($error, $log_these))
  1668. log_error($attachment['name'] . ': ' . $txt[$error], 'critical');
  1669. }
  1670. else
  1671. $attach_errors[] = '<dd>' . vsprintf($txt[$error[0]], $error[1]) . '</dd>';
  1672. }
  1673. if (file_exists($attachment['tmp_name']))
  1674. unlink($attachment['tmp_name']);
  1675. }
  1676. }
  1677. unset($_SESSION['temp_attachments']);
  1678. }
  1679. // Make the poll...
  1680. if (isset($_REQUEST['poll']))
  1681. {
  1682. // Create the poll.
  1683. $smcFunc['db_insert']('',
  1684. '{db_prefix}polls',
  1685. array(
  1686. 'question' => 'string-255', 'hide_results' => 'int', 'max_votes' => 'int', 'expire_time' => 'int', 'id_member' => 'int',
  1687. 'poster_name' => 'string-255', 'change_vote' => 'int', 'guest_vote' => 'int'
  1688. ),
  1689. array(
  1690. $_POST['question'], $_POST['poll_hide'], $_POST['poll_max_votes'], (empty($_POST['poll_expire']) ? 0 : time() + $_POST['poll_expire'] * 3600 * 24), $user_info['id'],
  1691. $_POST['guestname'], $_POST['poll_change_vote'], $_POST['poll_guest_vote'],
  1692. ),
  1693. array('id_poll')
  1694. );
  1695. $id_poll = $smcFunc['db_insert_id']('{db_prefix}polls', 'id_poll');
  1696. // Create each answer choice.
  1697. $i = 0;
  1698. $pollOptions = array();
  1699. foreach ($_POST['options'] as $option)
  1700. {
  1701. $pollOptions[] = array($id_poll, $i, $option);
  1702. $i++;
  1703. }
  1704. $smcFunc['db_insert']('insert',
  1705. '{db_prefix}poll_choices',
  1706. array('id_poll' => 'int', 'id_choice' => 'int', 'label' => 'string-255'),
  1707. $pollOptions,
  1708. array('id_poll', 'id_choice')
  1709. );
  1710. call_integration_hook('integrate_poll_add_edit', array($id_poll, false));
  1711. }
  1712. else
  1713. $id_poll = 0;
  1714. // Creating a new topic?
  1715. $newTopic = empty($_REQUEST['msg']) && empty($topic);
  1716. $_POST['icon'] = !empty($attachIDs) && $_POST['icon'] == 'xx' ? 'clip' : $_POST['icon'];
  1717. // Collect all parameters for the creation or modification of a post.
  1718. $msgOptions = array(
  1719. 'id' => empty($_REQUEST['msg']) ? 0 : (int) $_REQUEST['msg'],
  1720. 'subject' => $_POST['subject'],
  1721. 'body' => $_POST['message'],
  1722. 'icon' => preg_replace('~[\./\\\\*:"\'<>]~', '', $_POST['icon']),
  1723. 'smileys_enabled' => !isset($_POST['ns']),
  1724. 'attachments' => empty($attachIDs) ? array() : $attachIDs,
  1725. 'approved' => $becomesApproved,
  1726. );
  1727. $topicOptions = array(
  1728. 'id' => empty($topic) ? 0 : $topic,
  1729. 'board' => $board,
  1730. 'poll' => isset($_REQUEST['poll']) ? $id_poll : null,
  1731. 'lock_mode' => isset($_POST['lock']) ? (int) $_POST['lock'] : null,
  1732. 'sticky_mode' => isset($_POST['sticky']) && !empty($modSettings['enableStickyTopics']) ? (int) $_POST['sticky'] : null,
  1733. 'mark_as_read' => true,
  1734. 'is_approved' => !$modSettings['postmod_active'] || empty($topic) || !empty($board_info['cur_topic_approved']),
  1735. );
  1736. $posterOptions = array(
  1737. 'id' => $user_info['id'],
  1738. 'name' => $_POST['guestname'],
  1739. 'email' => $_POST['email'],
  1740. 'update_post_count' => !$user_info['is_guest'] && !isset($_REQUEST['msg']) && $board_info['posts_count'],
  1741. );
  1742. // This is an already existing message. Edit it.
  1743. if (!empty($_REQUEST['msg']))
  1744. {
  1745. // Have admins allowed people to hide their screwups?
  1746. if (time() - $row['poster_time'] > $modSettings['edit_wait_time'] || $user_info['id'] != $row['id_member'])
  1747. {
  1748. $msgOptions['modify_time'] = time();
  1749. $msgOptions['modify_name'] = $user_info['name'];
  1750. }
  1751. // This will save some time...
  1752. if (empty($approve_has_changed))
  1753. unset($msgOptions['approved']);
  1754. modifyPost($msgOptions, $topicOptions, $posterOptions);
  1755. }
  1756. // This is a new topic or an already existing one. Save it.
  1757. else
  1758. {
  1759. createPost($msgOptions, $topicOptions, $posterOptions);
  1760. if (isset($topicOptions['id']))
  1761. $topic = $topicOptions['id'];
  1762. }
  1763. // Editing or posting an event?
  1764. if (isset($_POST['calendar']) && (!isset($_REQUEST['eventid']) || $_REQUEST['eventid'] == -1))
  1765. {
  1766. require_once($sourcedir . '/Subs-Calendar.php');
  1767. // Make sure they can link an event to this post.
  1768. canLinkEvent();
  1769. // Insert the event.
  1770. $eventOptions = array(
  1771. 'board' => $board,
  1772. 'topic' => $topic,
  1773. 'title' => $_POST['evtitle'],
  1774. 'member' => $user_info['id'],
  1775. 'start_date' => sprintf('%04d-%02d-%02d', $_POST['year'], $_POST['month'], $_POST['day']),
  1776. 'span' => isset($_POST['span']) && $_POST['span'] > 0 ? min((int) $modSettings['cal_maxspan'], (int) $_POST['span'] - 1) : 0,
  1777. );
  1778. insertEvent($eventOptions);
  1779. }
  1780. elseif (isset($_POST['calendar']))
  1781. {
  1782. $_REQUEST['eventid'] = (int) $_REQUEST['eventid'];
  1783. // Validate the post...
  1784. require_once($sourcedir . '/Subs-Calendar.php');
  1785. validateEventPost();
  1786. // If you're not allowed to edit any events, you have to be the poster.
  1787. if (!allowedTo('calendar_edit_any'))
  1788. {
  1789. // Get the event's poster.
  1790. $request = $smcFunc['db_query']('', '
  1791. SELECT id_member
  1792. FROM {db_prefix}calendar
  1793. WHERE id_event = {int:id_event}',
  1794. array(
  1795. 'id_event' => $_REQUEST['eventid'],
  1796. )
  1797. );
  1798. $row2 = $smcFunc['db_fetch_assoc']($request);
  1799. $smcFunc['db_free_result']($request);
  1800. // Silly hacker, Trix are for kids. ...probably trademarked somewhere, this is FAIR USE! (parody...)
  1801. isAllowedTo('calendar_edit_' . ($row2['id_member'] == $user_info['id'] ? 'own' : 'any'));
  1802. }
  1803. // Delete it?
  1804. if (isset($_REQUEST['deleteevent']))
  1805. $smcFunc['db_query']('', '
  1806. DELETE FROM {db_prefix}calendar
  1807. WHERE id_event = {int:id_event}',
  1808. array(
  1809. 'id_event' => $_REQUEST['eventid'],
  1810. )
  1811. );
  1812. // ... or just update it?
  1813. else
  1814. {
  1815. $span = !empty($modSettings['cal_allowspan']) && !empty($_REQUEST['span']) ? min((int) $modSettings['cal_maxspan'], (int) $_REQUEST['span'] - 1) : 0;
  1816. $start_time = mktime(0, 0, 0, (int) $_REQUEST['month'], (int) $_REQUEST['day'], (int) $_REQUEST['year']);
  1817. $smcFunc['db_query']('', '
  1818. UPDATE {db_prefix}calendar
  1819. SET end_date = {date:end_date},
  1820. start_date = {date:start_date},
  1821. title = {string:title}
  1822. WHERE id_event = {int:id_event}',
  1823. array(
  1824. 'end_date' => strftime('%Y-%m-%d', $start_time + $span * 86400),
  1825. 'start_date' => strftime('%Y-%m-%d', $start_time),
  1826. 'id_event' => $_REQUEST['eventid'],
  1827. 'title' => $smcFunc['htmlspecialchars']($_REQUEST['evtitle'], ENT_QUOTES),
  1828. )
  1829. );
  1830. }
  1831. updateSettings(array(
  1832. 'calendar_updated' => time(),
  1833. ));
  1834. }
  1835. // Marking read should be done even for editing messages....
  1836. // Mark all the parents read. (since you just posted and they will be unread.)
  1837. if (!$user_info['is_guest'] && !empty($board_info['parent_boards']))
  1838. {
  1839. $smcFunc['db_query']('', '
  1840. UPDATE {db_prefix}log_boards
  1841. SET id_msg = {int:id_msg}
  1842. WHERE id_member = {int:current_member}
  1843. AND id_board IN ({array_int:board_list})',
  1844. array(
  1845. 'current_member' => $user_info['id'],
  1846. 'board_list' => array_keys($board_info['parent_boards']),
  1847. 'id_msg' => $modSettings['maxMsgID'],
  1848. )
  1849. );
  1850. }
  1851. // Turn notification on or off. (note this just blows smoke if it's already on or off.)
  1852. if (!empty($_POST['notify']) && allowedTo('mark_any_notify'))
  1853. {
  1854. $smcFunc['db_insert']('ignore',
  1855. '{db_prefix}log_notify',
  1856. array('id_member' => 'int', 'id_topic' => 'int', 'id_board' => 'int'),
  1857. array($user_info['id'], $topic, 0),
  1858. array('id_member', 'id_topic', 'id_board')
  1859. );
  1860. }
  1861. elseif (!$newTopic)
  1862. $smcFunc['db_query']('', '
  1863. DELETE FROM {db_prefix}log_notify
  1864. WHERE id_member = {int:current_member}
  1865. AND id_topic = {int:current_topic}',
  1866. array(
  1867. 'current_member' => $user_info['id'],
  1868. 'current_topic' => $topic,
  1869. )
  1870. );
  1871. // Log an act of moderation - modifying.
  1872. if (!empty($moderationAction))
  1873. logAction('modify', array('topic' => $topic, 'message' => (int) $_REQUEST['msg'], 'member' => $row['id_member'], 'board' => $board));
  1874. if (isset($_POST['lock']) && $_POST['lock'] != 2)
  1875. logAction(empty($_POST['lock']) ? 'unlock' : 'lock', array('topic' => $topicOptions['id'], 'board' => $topicOptions['board']));
  1876. if (isset($_POST['sticky']) && !empty($modSettings['enableStickyTopics']))
  1877. logAction('sticky', array('topic' => $topicOptions['id'], 'board' => $topicOptions['board']));
  1878. // Notify any members who have notification turned on for this topic - only do this if it's going to be approved(!)
  1879. if ($becomesApproved)
  1880. {
  1881. if ($newTopic)
  1882. {
  1883. $notifyData = array(
  1884. 'body' => $_POST['message'],
  1885. 'subject' => $_POST['subject'],
  1886. 'name' => $user_info['name'],
  1887. 'poster' => $user_info['id'],
  1888. 'msg' => $msgOptions['id'],
  1889. 'board' => $board,
  1890. 'topic' => $topic,
  1891. );
  1892. notifyMembersBoard($notifyData);
  1893. }
  1894. elseif (empty($_REQUEST['msg']))
  1895. {
  1896. // Only send it to everyone if the topic is approved, otherwise just to the topic starter if they want it.
  1897. if ($topic_info['approved'])
  1898. sendNotifications($topic, 'reply');
  1899. else
  1900. sendNotifications($topic, 'reply', array(), $topic_info['id_member_started']);
  1901. }
  1902. }
  1903. // Returning to the topic?
  1904. if (!empty($_REQUEST['goback']))
  1905. {
  1906. // Mark the board as read.... because it might get confusing otherwise.
  1907. $smcFunc['db_query']('', '
  1908. UPDATE {db_prefix}log_boards
  1909. SET id_msg = {int:maxMsgID}
  1910. WHERE id_member = {int:current_member}
  1911. AND id_board = {int:current_board}',
  1912. array(
  1913. 'current_board' => $board,
  1914. 'current_member' => $user_info['id'],
  1915. 'maxMsgID' => $modSettings['maxMsgID'],
  1916. )
  1917. );
  1918. }
  1919. if ($board_info['num_topics'] == 0)
  1920. cache_put_data('board-' . $board, null, 120);
  1921. if (!empty($_POST['announce_topic']))
  1922. redirectexit('action=announce;sa=selectgroup;topic=' . $topic . (!empty($_POST['move']) && allowedTo('move_any') ? ';move' : '') . (empty($_REQUEST['goback']) ? '' : ';goback'));
  1923. if (!empty($_POST['move']) && allowedTo('move_any'))
  1924. redirectexit('action=movetopic;topic=' . $topic . '.0' . (empty($_REQUEST['goback']) ? '' : ';goback'));
  1925. // If there are attachment errors. Let's show a list to the user.
  1926. if (!empty($attach_errors))
  1927. {
  1928. global $settings, $scripturl;
  1929. loadTemplate('Errors');
  1930. $context['sub_template'] = 'attachment_errors';
  1931. $context['page_title'] = $txt['error_occured'];
  1932. $context['error_message'] = '<dl>';
  1933. $context['error_message'] .= implode("\n", $attach_errors);
  1934. $context['error_message'] .= '</dl>';
  1935. $context['linktree'][] = array(
  1936. 'url' => $scripturl . '?topic=' . $topic . '.0',
  1937. 'name' => $_POST['subject'],
  1938. );
  1939. if (isset($_REQUEST['msg']))
  1940. $context['redirect_link'] = '?topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg'];
  1941. else
  1942. $context['redirect_link'] = '?topic=' . $topic . '.new#new';
  1943. $context['back_link'] = '?action=post;msg=' . $msgOptions['id'] . ';topic=' . $topic . ';additionalOptions#postAttachment';
  1944. obExit(null, true);
  1945. }
  1946. // Return to post if the mod is on.
  1947. if (isset($_REQUEST['msg']) && !empty($_REQUEST['goback']))
  1948. redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg'], isBrowser('ie'));
  1949. elseif (!empty($_REQUEST['goback']))
  1950. redirectexit('topic=' . $topic . '.new#new', isBrowser('ie'));
  1951. // Dut-dut-duh-duh-DUH-duh-dut-duh-duh! *dances to the Final Fantasy Fanfare...*
  1952. else
  1953. redirectexit('board=' . $board . '.0');
  1954. }
  1955. /**
  1956. * handle the announce topic function (action=announce).
  1957. *
  1958. * checks the topic announcement permissions and loads the announcement template.
  1959. * requires the announce_topic permission.
  1960. * uses the ManageMembers template and Post language file.
  1961. * call the right function based on the sub-action.
  1962. */
  1963. function AnnounceTopic()
  1964. {
  1965. global $context, $txt, $topic;
  1966. isAllowedTo('announce_topic');
  1967. validateSession();
  1968. if (empty($topic))
  1969. fatal_lang_error('topic_gone', false);
  1970. loadLanguage('Post');
  1971. loadTemplate('Post');
  1972. $subActions = array(
  1973. 'selectgroup' => 'AnnouncementSelectMembergroup',
  1974. 'send' => 'AnnouncementSend',
  1975. );
  1976. $context['page_title'] = $txt['announce_topic'];
  1977. // Call the function based on the sub-action.
  1978. $subActions[isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']]) ? $_REQUEST['sa'] : 'selectgroup']();
  1979. }
  1980. /**
  1981. * Allow a user to chose the membergroups to send the announcement to.
  1982. *
  1983. * lets the user select the membergroups that will receive the topic announcement.
  1984. */
  1985. function AnnouncementSelectMembergroup()
  1986. {
  1987. global $txt, $context, $topic, $board, $board_info, $smcFunc;
  1988. $groups = array_merge($board_info['groups'], array(1));
  1989. foreach ($groups as $id => $group)
  1990. $groups[$id] = (int) $group;
  1991. $context['groups'] = array();
  1992. if (in_array(0, $groups))
  1993. {
  1994. $context['groups'][0] = array(
  1995. 'id' => 0,
  1996. 'name' => $txt['announce_regular_members'],
  1997. 'member_count' => 'n/a',
  1998. );
  1999. }
  2000. // Get all membergroups that have access to the board the announcement was made on.
  2001. $request = $smcFunc['db_query']('', '
  2002. SELECT mg.id_group, COUNT(mem.id_member) AS num_members
  2003. FROM {db_prefix}membergroups AS mg
  2004. LEFT JOIN {db_prefix}members AS mem ON (mem.id_group = mg.id_group OR FIND_IN_SET(mg.id_group, mem.additional_groups) != 0 OR mg.id_group = mem.id_post_group)
  2005. WHERE mg.id_group IN ({array_int:group_list})
  2006. GROUP BY mg.id_group',
  2007. array(
  2008. 'group_list' => $groups,
  2009. 'newbie_id_group' => 4,
  2010. )
  2011. );
  2012. while ($row = $smcFunc['db_fetch_assoc']($request))
  2013. {
  2014. $context['groups'][$row['id_group']] = array(
  2015. 'id' => $row['id_group'],
  2016. 'name' => '',
  2017. 'member_count' => $row['num_members'],
  2018. );
  2019. }
  2020. $smcFunc['db_free_result']($request);
  2021. // Now get the membergroup names.
  2022. $request = $smcFunc['db_query']('', '
  2023. SELECT id_group, group_name
  2024. FROM {db_prefix}membergroups
  2025. WHERE id_group IN ({array_int:group_list})',
  2026. array(
  2027. 'group_list' => $groups,
  2028. )
  2029. );
  2030. while ($row = $smcFunc['db_fetch_assoc']($request))
  2031. $context['groups'][$row['id_group']]['name'] = $row['group_name'];
  2032. $smcFunc['db_free_result']($request);
  2033. // Get the subject of the topic we're about to announce.
  2034. $request = $smcFunc['db_query']('', '
  2035. SELECT m.subject
  2036. FROM {db_prefix}topics AS t
  2037. INNER JOIN {db_prefix}messages AS m ON (m.id_msg = t.id_first_msg)
  2038. WHERE t.id_topic = {int:current_topic}',
  2039. array(
  2040. 'current_topic' => $topic,
  2041. )
  2042. );
  2043. list ($context['topic_subject']) = $smcFunc['db_fetch_row']($request);
  2044. $smcFunc['db_free_result']($request);
  2045. censorText($context['announce_topic']['subject']);
  2046. $context['move'] = isset($_REQUEST['move']) ? 1 : 0;
  2047. $context['go_back'] = isset($_REQUEST['goback']) ? 1 : 0;
  2048. $context['sub_template'] = 'announce';
  2049. }
  2050. /**
  2051. * Send the announcement in chunks.
  2052. *
  2053. * splits the members to be sent a topic announcement into chunks.
  2054. * composes notification messages in all languages needed.
  2055. * does the actual sending of the topic announcements in chunks.
  2056. * calculates a rough estimate of the percentage items sent.
  2057. */
  2058. function AnnouncementSend()
  2059. {
  2060. global $topic, $board, $board_info, $context, $modSettings;
  2061. global $language, $scripturl, $txt, $user_info, $sourcedir, $smcFunc;
  2062. checkSession();
  2063. $context['start'] = empty($_REQUEST['start']) ? 0 : (int) $_REQUEST['start'];
  2064. $groups = array_merge($board_info['groups'], array(1));
  2065. if (isset($_POST['membergroups']))
  2066. $_POST['who'] = explode(',', $_POST['membergroups']);
  2067. // Check whether at least one membergroup was selected.
  2068. if (empty($_POST['who']))
  2069. fatal_lang_error('no_membergroup_selected');
  2070. // Make sure all membergroups are integers and can access the board of the announcement.
  2071. foreach ($_POST['who'] as $id => $mg)
  2072. $_POST['who'][$id] = in_array((int) $mg, $groups) ? (int) $mg : 0;
  2073. // Get the topic subject and censor it.
  2074. $request = $smcFunc['db_query']('', '
  2075. SELECT m.id_msg, m.subject, m.body
  2076. FROM {db_prefix}topics AS t
  2077. INNER JOIN {db_prefix}messages AS m ON (m.id_msg = t.id_first_msg)
  2078. WHERE t.id_topic = {int:current_topic}',
  2079. array(
  2080. 'current_topic' => $topic,
  2081. )
  2082. );
  2083. list ($id_msg, $context['topic_subject'], $message) = $smcFunc['db_fetch_row']($request);
  2084. $smcFunc['db_free_result']($request);
  2085. censorText($context['topic_subject']);
  2086. censorText($message);
  2087. $message = trim(un_htmlspecialchars(strip_tags(strtr(parse_bbc($message, false, $id_msg), array('<br />' => "\n", '</div>' => "\n", '</li>' => "\n", '&#91;' => '[', '&#93;' => ']')))));
  2088. // We need this in order to be able send emails.
  2089. require_once($sourcedir . '/Subs-Post.php');
  2090. // Select the email addresses for this batch.
  2091. $request = $smcFunc['db_query']('', '
  2092. SELECT mem.id_member, mem.email_address, mem.lngfile
  2093. FROM {db_prefix}members AS mem
  2094. WHERE (mem.id_group IN ({array_int:group_list}) OR mem.id_post_group IN ({array_int:group_list}) OR FIND_IN_SET({raw:additional_group_list}, mem.additional_groups) != 0)' . (!empty($modSettings['allow_disableAnnounce']) ? '
  2095. AND mem.notify_announcements = {int:notify_announcements}' : '') . '
  2096. AND mem.is_activated = {int:is_activated}
  2097. AND mem.id_member > {int:start}
  2098. ORDER BY mem.id_member
  2099. LIMIT {int:chunk_size}',
  2100. array(
  2101. 'group_list' => $_POST['who'],
  2102. 'notify_announcements' => 1,
  2103. 'is_activated' => 1,
  2104. 'start' => $context['start'],
  2105. 'additional_group_list' => implode(', mem.additional_groups) != 0 OR FIND_IN_SET(', $_POST['who']),
  2106. // @todo Might need an interface?
  2107. 'chunk_size' => empty($modSettings['mail_queue']) ? 50 : 500,
  2108. )
  2109. );
  2110. // All members have received a mail. Go to the next screen.
  2111. if ($smcFunc['db_num_rows']($request) == 0)
  2112. {
  2113. logAction('announce_topic', array('topic' => $topic), 'user');
  2114. if (!empty($_REQUEST['move']) && allowedTo('move_any'))
  2115. redirectexit('action=movetopic;topic=' . $topic . '.0' . (empty($_REQUEST['goback']) ? '' : ';goback'));
  2116. elseif (!empty($_REQUEST['goback']))
  2117. redirectexit('topic=' . $topic . '.new;boardseen#new', isBrowser('ie'));
  2118. else
  2119. redirectexit('board=' . $board . '.0');
  2120. }
  2121. $announcements = array();
  2122. // Loop through all members that'll receive an announcement in this batch.
  2123. while ($row = $smcFunc['db_fetch_assoc']($request))
  2124. {
  2125. $cur_language = empty($row['lngfile']) || empty($modSettings['userLanguage']) ? $language : $row['lngfile'];
  2126. // If the language wasn't defined yet, load it and compose a notification message.
  2127. if (!isset($announcements[$cur_language]))
  2128. {
  2129. $replacements = array(
  2130. 'TOPICSUBJECT' => $context['topic_subject'],
  2131. 'MESSAGE' => $message,
  2132. 'TOPICLINK' => $scripturl . '?topic=' . $topic . '.0',
  2133. );
  2134. $emaildata = loadEmailTemplate('new_announcement', $replacements, $cur_language);
  2135. $announcements[$cur_language] = array(
  2136. 'subject' => $emaildata['subject'],
  2137. 'body' => $emaildata['body'],
  2138. 'recipients' => array(),
  2139. );
  2140. }
  2141. $announcements[$cur_language]['recipients'][$row['id_member']] = $row['email_address'];
  2142. $context['start'] = $row['id_member'];
  2143. }
  2144. $smcFunc['db_free_result']($request);
  2145. // For each language send a different mail - low priority...
  2146. foreach ($announcements as $lang => $mail)
  2147. sendmail($mail['recipients'], $mail['subject'], $mail['body'], null, null, false, 5);
  2148. $context['percentage_done'] = round(100 * $context['start'] / $modSettings['latestMember'], 1);
  2149. $context['move'] = empty($_REQUEST['move']) ? 0 : 1;
  2150. $context['go_back'] = empty($_REQUEST['goback']) ? 0 : 1;
  2151. $context['membergroups'] = implode(',', $_POST['who']);
  2152. $context['sub_template'] = 'announcement_send';
  2153. // Go back to the correct language for the user ;).
  2154. if (!empty($modSettings['userLanguage']))
  2155. loadLanguage('Post');
  2156. }
  2157. /**
  2158. * Notifies members who have requested notification for new topics posted on a board of said posts.
  2159. *
  2160. * receives data on the topics to send out notifications to by the passed in array.
  2161. * only sends notifications to those who can *currently* see the topic (it doesn't matter if they could when they requested notification.)
  2162. * loads the Post language file multiple times for each language if the userLanguage setting is set.
  2163. * @param array &$topicData
  2164. */
  2165. function notifyMembersBoard(&$topicData)
  2166. {
  2167. global $txt, $scripturl, $language, $user_info;
  2168. global $modSettings, $sourcedir, $board, $smcFunc, $context;
  2169. require_once($sourcedir . '/Subs-Post.php');
  2170. // Do we have one or lots of topics?
  2171. if (isset($topicData['body']))
  2172. $topicData = array($topicData);
  2173. // Find out what boards we have... and clear out any rubbish!
  2174. $boards = array();
  2175. foreach ($topicData as $key => $topic)
  2176. {
  2177. if (!empty($topic['board']))
  2178. $boards[$topic['board']][] = $key;
  2179. else
  2180. {
  2181. unset($topic[$key]);
  2182. continue;
  2183. }
  2184. // Censor the subject and body...
  2185. censorText($topicData[$key]['subject']);
  2186. censorText($topicData[$key]['body']);
  2187. $topicData[$key]['subject'] = un_htmlspecialchars($topicData[$key]['subject']);
  2188. $topicData[$key]['body'] = trim(un_htmlspecialchars(strip_tags(strtr(parse_bbc($topicData[$key]['body'], false), array('<br />' => "\n", '</div>' => "\n", '</li>' => "\n", '&#91;' => '[', '&#93;' => ']')))));
  2189. }
  2190. // Just the board numbers.
  2191. $board_index = array_unique(array_keys($boards));
  2192. if (empty($board_index))
  2193. return;
  2194. // Yea, we need to add this to the digest queue.
  2195. $digest_insert = array();
  2196. foreach ($topicData as $id => $data)
  2197. $digest_insert[] = array($data['topic'], $data['msg'], 'topic', $user_info['id']);
  2198. $smcFunc['db_insert']('',
  2199. '{db_prefix}log_digest',
  2200. array(
  2201. 'id_topic' => 'int', 'id_msg' => 'int', 'note_type' => 'string', 'exclude' => 'int',
  2202. ),
  2203. $digest_insert,
  2204. array()
  2205. );
  2206. // Find the members with notification on for these boards.
  2207. $members = $smcFunc['db_query']('', '
  2208. SELECT
  2209. mem.id_member, mem.email_address, mem.notify_regularity, mem.notify_send_body, mem.lngfile,
  2210. ln.sent, ln.id_board, mem.id_group, mem.additional_groups, b.member_groups,
  2211. mem.id_post_group
  2212. FROM {db_prefix}log_notify AS ln
  2213. INNER JOIN {db_prefix}boards AS b ON (b.id_board = ln.id_board)
  2214. INNER JOIN {db_prefix}members AS mem ON (mem.id_member = ln.id_member)
  2215. WHERE ln.id_board IN ({array_int:board_list})
  2216. AND mem.id_member != {int:current_member}
  2217. AND mem.is_activated = {int:is_activated}
  2218. AND mem.notify_types != {int:notify_types}
  2219. AND mem.notify_regularity < {int:notify_regularity}
  2220. ORDER BY mem.lngfile',
  2221. array(
  2222. 'current_member' => $user_info['id'],
  2223. 'board_list' => $board_index,
  2224. 'is_activated' => 1,
  2225. 'notify_types' => 4,
  2226. 'notify_regularity' => 2,
  2227. )
  2228. );
  2229. while ($rowmember = $smcFunc['db_fetch_assoc']($members))
  2230. {
  2231. if ($rowmember['id_group'] != 1)
  2232. {
  2233. $allowed = explode(',', $rowmember['member_groups']);
  2234. $rowmember['additional_groups'] = explode(',', $rowmember['additional_groups']);
  2235. $rowmember['additional_groups'][] = $rowmember['id_group'];
  2236. $rowmember['additional_groups'][] = $rowmember['id_post_group'];
  2237. if (count(array_intersect($allowed, $rowmember['additional_groups'])) == 0)
  2238. continue;
  2239. }
  2240. $langloaded = loadLanguage('index', empty($rowmember['lngfile']) || empty($modSettings['userLanguage']) ? $language : $rowmember['lngfile'], false);
  2241. // Now loop through all the notifications to send for this board.
  2242. if (empty($boards[$rowmember['id_board']]))
  2243. continue;
  2244. $sentOnceAlready = 0;
  2245. foreach ($boards[$rowmember['id_board']] as $key)
  2246. {
  2247. // Don't notify the guy who started the topic!
  2248. // @todo In this case actually send them a "it's approved hooray" email :P
  2249. if ($topicData[$key]['poster'] == $rowmember['id_member'])
  2250. continue;
  2251. // Setup the string for adding the body to the message, if a user wants it.
  2252. $send_body = empty($modSettings['disallow_sendBody']) && !empty($rowmember['notify_send_body']);
  2253. $replacements = array(
  2254. 'TOPICSUBJECT' => $topicData[$key]['subject'],
  2255. 'TOPICLINK' => $scripturl . '?topic=' . $topicData[$key]['topic'] . '.new#new',
  2256. 'MESSAGE' => $topicData[$key]['body'],
  2257. 'UNSUBSCRIBELINK' => $scripturl . '?action=notifyboard;board=' . $topicData[$key]['board'] . '.0',
  2258. );
  2259. if (!$send_body)
  2260. unset($replacements['MESSAGE']);
  2261. // Figure out which email to send off
  2262. $emailtype = '';
  2263. // Send only if once is off or it's on and it hasn't been sent.
  2264. if (!empty($rowmember['notify_regularity']) && !$sentOnceAlready && empty($rowmember['sent']))
  2265. $emailtype = 'notify_boards_once';
  2266. elseif (empty($rowmember['notify_regularity']))
  2267. $emailtype = 'notify_boards';
  2268. if (!empty($emailtype))
  2269. {
  2270. $emailtype .= $send_body ? '_body' : '';
  2271. $emaildata = loadEmailTemplate($emailtype, $replacements, $langloaded);
  2272. sendmail($rowmember['email_address'], $emaildata['subject'], $emaildata['body'], null, null, false, 3);
  2273. }
  2274. $sentOnceAlready = 1;
  2275. }
  2276. }
  2277. $smcFunc['db_free_result']($members);
  2278. loadLanguage('index', $user_info['language']);
  2279. // Sent!
  2280. $smcFunc['db_query']('', '
  2281. UPDATE {db_prefix}log_notify
  2282. SET sent = {int:is_sent}
  2283. WHERE id_board IN ({array_int:board_list})
  2284. AND id_member != {int:current_member}',
  2285. array(
  2286. 'current_member' => $user_info['id'],
  2287. 'board_list' => $board_index,
  2288. 'is_sent' => 1,
  2289. )
  2290. );
  2291. }
  2292. /**
  2293. * Get the topic for display purposes.
  2294. *
  2295. * gets a summary of the most recent posts in a topic.
  2296. * depends on the topicSummaryPosts setting.
  2297. * if you are editing a post, only shows posts previous to that post.
  2298. */
  2299. function getTopic()
  2300. {
  2301. global $topic, $modSettings, $context, $smcFunc, $counter, $options;
  2302. if (isset($_REQUEST['xml']))
  2303. $limit = '
  2304. LIMIT ' . (empty($context['new_replies']) ? '0' : $context['new_replies']);
  2305. else
  2306. $limit = empty($modSettings['topicSummaryPosts']) ? '' : '
  2307. LIMIT ' . (int) $modSettings['topicSummaryPosts'];
  2308. // If you're modifying, get only those posts before the current one. (otherwise get all.)
  2309. $request = $smcFunc['db_query']('', '
  2310. SELECT
  2311. IFNULL(mem.real_name, m.poster_name) AS poster_name, m.poster_time,
  2312. m.body, m.smileys_enabled, m.id_msg, m.id_member
  2313. FROM {db_prefix}messages AS m
  2314. LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member)
  2315. WHERE m.id_topic = {int:current_topic}' . (isset($_REQUEST['msg']) ? '
  2316. AND m.id_msg < {int:id_msg}' : '') .(!$modSettings['postmod_active'] || allowedTo('approve_posts') ? '' : '
  2317. AND m.approved = {int:approved}') . '
  2318. ORDER BY m.id_msg DESC' . $limit,
  2319. array(
  2320. 'current_topic' => $topic,
  2321. 'id_msg' => isset($_REQUEST['msg']) ? (int) $_REQUEST['msg'] : 0,
  2322. 'approved' => 1,
  2323. )
  2324. );
  2325. $context['previous_posts'] = array();
  2326. while ($row = $smcFunc['db_fetch_assoc']($request))
  2327. {
  2328. // Censor, BBC, ...
  2329. censorText($row['body']);
  2330. $row['body'] = parse_bbc($row['body'], $row['smileys_enabled'], $row['id_msg']);
  2331. // ...and store.
  2332. $context['previous_posts'][] = array(
  2333. 'counter' => $counter++,
  2334. 'alternate' => $counter % 2,
  2335. 'poster' => $row['poster_name'],
  2336. 'message' => $row['body'],
  2337. 'time' => timeformat($row['poster_time']),
  2338. 'timestamp' => forum_time(true, $row['poster_time']),
  2339. 'id' => $row['id_msg'],
  2340. 'is_new' => !empty($context['new_replies']),
  2341. 'is_ignored' => !empty($modSettings['enable_buddylist']) && !empty($options['posts_apply_ignore_list']) && in_array($row['id_member'], $context['user']['ignoreusers']),
  2342. );
  2343. if (!empty($context['new_replies']))
  2344. $context['new_replies']--;
  2345. }
  2346. $smcFunc['db_free_result']($request);
  2347. }
  2348. /**
  2349. * loads a post an inserts it into the current editing text box.
  2350. * uses the Post language file.
  2351. * uses special (sadly browser dependent) javascript to parse entities for internationalization reasons.
  2352. * accessed with ?action=quotefast.
  2353. */
  2354. function QuoteFast()
  2355. {
  2356. global $modSettings, $user_info, $txt, $settings, $context;
  2357. global $sourcedir, $smcFunc;
  2358. loadLanguage('Post');
  2359. if (!isset($_REQUEST['xml']))
  2360. loadTemplate('Post');
  2361. include_once($sourcedir . '/Subs-Post.php');
  2362. $moderate_boards = boardsAllowedTo('moderate_board');
  2363. // Where we going if we need to?
  2364. $context['post_box_name'] = isset($_GET['pb']) ? $_GET['pb'] : '';
  2365. $request = $smcFunc['db_query']('', '
  2366. SELECT IFNULL(mem.real_name, m.poster_name) AS poster_name, m.poster_time, m.body, m.id_topic, m.subject,
  2367. m.id_board, m.id_member, m.approved
  2368. FROM {db_prefix}messages AS m
  2369. INNER JOIN {db_prefix}topics AS t ON (t.id_topic = m.id_topic)
  2370. INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board AND {query_see_board})
  2371. LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member)
  2372. WHERE m.id_msg = {int:id_msg}' . (isset($_REQUEST['modify']) || (!empty($moderate_boards) && $moderate_boards[0] == 0) ? '' : '
  2373. AND (t.locked = {int:not_locked}' . (empty($moderate_boards) ? '' : ' OR b.id_board IN ({array_int:moderation_board_list})') . ')') . '
  2374. LIMIT 1',
  2375. array(
  2376. 'current_member' => $user_info['id'],
  2377. 'moderation_board_list' => $moderate_boards,
  2378. 'id_msg' => (int) $_REQUEST['quote'],
  2379. 'not_locked' => 0,
  2380. )
  2381. );
  2382. $context['close_window'] = $smcFunc['db_num_rows']($request) == 0;
  2383. $row = $smcFunc['db_fetch_assoc']($request);
  2384. $smcFunc['db_free_result']($request);
  2385. $context['sub_template'] = 'quotefast';
  2386. if (!empty($row))
  2387. $can_view_post = $row['approved'] || ($row['id_member'] != 0 && $row['id_member'] == $user_info['id']) || allowedTo('approve_posts', $row['id_board']);
  2388. if (!empty($can_view_post))
  2389. {
  2390. // Remove special formatting we don't want anymore.
  2391. $row['body'] = un_preparsecode($row['body']);
  2392. // Censor the message!
  2393. censorText($row['body']);
  2394. $row['body'] = preg_replace('~<br ?/?' . '>~i', "\n", $row['body']);
  2395. // Want to modify a single message by double clicking it?
  2396. if (isset($_REQUEST['modify']))
  2397. {
  2398. censorText($row['subject']);
  2399. $context['sub_template'] = 'modifyfast';
  2400. $context['message'] = array(
  2401. 'id' => $_REQUEST['quote'],
  2402. 'body' => $row['body'],
  2403. 'subject' => addcslashes($row['subject'], '"'),
  2404. );
  2405. return;
  2406. }
  2407. // Remove any nested quotes.
  2408. if (!empty($modSettings['removeNestedQuotes']))
  2409. $row['body'] = preg_replace(array('~\n?\[quote.*?\].+?\[/quote\]\n?~is', '~^\n~', '~\[/quote\]~'), '', $row['body']);
  2410. $lb = "\n";
  2411. // Add a quote string on the front and end.
  2412. $context['quote']['xml'] = '[quote author=' . $row['poster_name'] . ' link=topic=' . $row['id_topic'] . '.msg' . (int) $_REQUEST['quote'] . '#msg' . (int) $_REQUEST['quote'] . ' date=' . $row['poster_time'] . ']' . $lb . $row['body'] . $lb . '[/quote]';
  2413. $context['quote']['text'] = strtr(un_htmlspecialchars($context['quote']['xml']), array('\'' => '\\\'', '\\' => '\\\\', "\n" => '\\n', '</script>' => '</\' + \'script>'));
  2414. $context['quote']['xml'] = strtr($context['quote']['xml'], array('&nbsp;' => '&#160;', '<' => '&lt;', '>' => '&gt;'));
  2415. $context['quote']['mozilla'] = strtr($smcFunc['htmlspecialchars']($context['quote']['text']), array('&quot;' => '"'));
  2416. }
  2417. //@todo Needs a nicer interface.
  2418. // In case our message has been removed in the meantime.
  2419. elseif (isset($_REQUEST['modify']))
  2420. {
  2421. $context['sub_template'] = 'modifyfast';
  2422. $context['message'] = array(
  2423. 'id' => 0,
  2424. 'body' => '',
  2425. 'subject' => '',
  2426. );
  2427. }
  2428. else
  2429. $context['quote'] = array(
  2430. 'xml' => '',
  2431. 'mozilla' => '',
  2432. 'text' => '',
  2433. );
  2434. }
  2435. /**
  2436. * Used to edit the body or subject of a message inline
  2437. * called from action=jsmodify from script and topic js
  2438. */
  2439. function JavaScriptModify()
  2440. {
  2441. global $sourcedir, $modSettings, $board, $topic, $txt;
  2442. global $user_info, $context, $smcFunc, $language;
  2443. // We have to have a topic!
  2444. if (empty($topic))
  2445. obExit(false);
  2446. checkSession('get');
  2447. require_once($sourcedir . '/Subs-Post.php');
  2448. // Assume the first message if no message ID was given.
  2449. $request = $smcFunc['db_query']('', '
  2450. SELECT
  2451. t.locked, t.num_replies, t.id_member_started, t.id_first_msg,
  2452. m.id_msg, m.id_member, m.poster_time, m.subject, m.smileys_enabled, m.body, m.icon,
  2453. m.modified_time, m.modified_name, m.approved
  2454. FROM {db_prefix}messages AS m
  2455. INNER JOIN {db_prefix}topics AS t ON (t.id_topic = {int:current_topic})
  2456. WHERE m.id_msg = {raw:id_msg}
  2457. AND m.id_topic = {int:current_topic}' . (allowedTo('modify_any') || allowedTo('approve_posts') ? '' : (!$modSettings['postmod_active'] ? '
  2458. AND (m.id_member != {int:guest_id} AND m.id_member = {int:current_member})' : '
  2459. AND (m.approved = {int:is_approved} OR (m.id_member != {int:guest_id} AND m.id_member = {int:current_member}))')),
  2460. array(
  2461. 'current_member' => $user_info['id'],
  2462. 'current_topic' => $topic,
  2463. 'id_msg' => empty($_REQUEST['msg']) ? 't.id_first_msg' : (int) $_REQUEST['msg'],
  2464. 'is_approved' => 1,
  2465. 'guest_id' => 0,
  2466. )
  2467. );
  2468. if ($smcFunc['db_num_rows']($request) == 0)
  2469. fatal_lang_error('no_board', false);
  2470. $row = $smcFunc['db_fetch_assoc']($request);
  2471. $smcFunc['db_free_result']($request);
  2472. // Change either body or subject requires permissions to modify messages.
  2473. if (isset($_POST['message']) || isset($_POST['subject']) || isset($_REQUEST['icon']))
  2474. {
  2475. if (!empty($row['locked']))
  2476. isAllowedTo('moderate_board');
  2477. if ($row['id_member'] == $user_info['id'] && !allowedTo('modify_any'))
  2478. {
  2479. if ((!$modSettings['postmod_active'] || $row['approved']) && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time())
  2480. fatal_lang_error('modify_post_time_passed', false);
  2481. elseif ($row['id_member_started'] == $user_info['id'] && !allowedTo('modify_own'))
  2482. isAllowedTo('modify_replies');
  2483. else
  2484. isAllowedTo('modify_own');
  2485. }
  2486. // Otherwise, they're locked out; someone who can modify the replies is needed.
  2487. elseif ($row['id_member_started'] == $user_info['id'] && !allowedTo('modify_any'))
  2488. isAllowedTo('modify_replies');
  2489. else
  2490. isAllowedTo('modify_any');
  2491. // Only log this action if it wasn't your message.
  2492. $moderationAction = $row['id_member'] != $user_info['id'];
  2493. }
  2494. $post_errors = array();
  2495. if (isset($_POST['subject']) && $smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_POST['subject'])) !== '')
  2496. {
  2497. $_POST['subject'] = strtr($smcFunc['htmlspecialchars']($_POST['subject']), array("\r" => '', "\n" => '', "\t" => ''));
  2498. // Maximum number of characters.
  2499. if ($smcFunc['strlen']($_POST['subject']) > 100)
  2500. $_POST['subject'] = $smcFunc['substr']($_POST['subject'], 0, 100);
  2501. }
  2502. elseif (isset($_POST['subject']))
  2503. {
  2504. $post_errors[] = 'no_subject';
  2505. unset($_POST['subject']);
  2506. }
  2507. if (isset($_POST['message']))
  2508. {
  2509. if ($smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_POST['message'])) === '')
  2510. {
  2511. $post_errors[] = 'no_message';
  2512. unset($_POST['message']);
  2513. }
  2514. elseif (!empty($modSettings['max_messageLength']) && $smcFunc['strlen']($_POST['message']) > $modSettings['max_messageLength'])
  2515. {
  2516. $post_errors[] = 'long_message';
  2517. unset($_POST['message']);
  2518. }
  2519. else
  2520. {
  2521. $_POST['message'] = $smcFunc['htmlspecialchars']($_POST['message'], ENT_QUOTES);
  2522. preparsecode($_POST['message']);
  2523. if ($smcFunc['htmltrim'](strip_tags(parse_bbc($_POST['message'], false), '<img>')) === '')
  2524. {
  2525. $post_errors[] = 'no_message';
  2526. unset($_POST['message']);
  2527. }
  2528. }
  2529. }
  2530. if (isset($_POST['lock']))
  2531. {
  2532. if (!allowedTo(array('lock_any', 'lock_own')) || (!allowedTo('lock_any') && $user_info['id'] != $row['id_member']))
  2533. unset($_POST['lock']);
  2534. elseif (!allowedTo('lock_any'))
  2535. {
  2536. if ($row['locked'] == 1)
  2537. unset($_POST['lock']);
  2538. else
  2539. $_POST['lock'] = empty($_POST['lock']) ? 0 : 2;
  2540. }
  2541. elseif (!empty($row['locked']) && !empty($_POST['lock']) || $_POST['lock'] == $row['locked'])
  2542. unset($_POST['lock']);
  2543. else
  2544. $_POST['lock'] = empty($_POST['lock']) ? 0 : 1;
  2545. }
  2546. if (isset($_POST['sticky']) && !allowedTo('make_sticky'))
  2547. unset($_POST['sticky']);
  2548. if (empty($post_errors))
  2549. {
  2550. $msgOptions = array(
  2551. 'id' => $row['id_msg'],
  2552. 'subject' => isset($_POST['subject']) ? $_POST['subject'] : null,
  2553. 'body' => isset($_POST['message']) ? $_POST['message'] : null,
  2554. 'icon' => isset($_REQUEST['icon']) ? preg_replace('~[\./\\\\*\':"<>]~', '', $_REQUEST['icon']) : null,
  2555. );
  2556. $topicOptions = array(
  2557. 'id' => $topic,
  2558. 'board' => $board,
  2559. 'lock_mode' => isset($_POST['lock']) ? (int) $_POST['lock'] : null,
  2560. 'sticky_mode' => isset($_POST['sticky']) && !empty($modSettings['enableStickyTopics']) ? (int) $_POST['sticky'] : null,
  2561. 'mark_as_read' => true,
  2562. );
  2563. $posterOptions = array();
  2564. // Only consider marking as editing if they have edited the subject, message or icon.
  2565. if ((isset($_POST['subject']) && $_POST['subject'] != $row['subject']) || (isset($_POST['message']) && $_POST['message'] != $row['body']) || (isset($_REQUEST['icon']) && $_REQUEST['icon'] != $row['icon']))
  2566. {
  2567. // And even then only if the time has passed...
  2568. if (time() - $row['poster_time'] > $modSettings['edit_wait_time'] || $user_info['id'] != $row['id_member'])
  2569. {
  2570. $msgOptions['modify_time'] = time();
  2571. $msgOptions['modify_name'] = $user_info['name'];
  2572. }
  2573. }
  2574. // If nothing was changed there's no need to add an entry to the moderation log.
  2575. else
  2576. $moderationAction = false;
  2577. modifyPost($msgOptions, $topicOptions, $posterOptions);
  2578. // If we didn't change anything this time but had before put back the old info.
  2579. if (!isset($msgOptions['modify_time']) && !empty($row['modified_time']))
  2580. {
  2581. $msgOptions['modify_time'] = $row['modified_time'];
  2582. $msgOptions['modify_name'] = $row['modified_name'];
  2583. }
  2584. // Changing the first subject updates other subjects to 'Re: new_subject'.
  2585. if (isset($_POST['subject']) && isset($_REQUEST['change_all_subjects']) && $row['id_first_msg'] == $row['id_msg'] && !empty($row['num_replies']) && (allowedTo('modify_any') || ($row['id_member_started'] == $user_info['id'] && allowedTo('modify_replies'))))
  2586. {
  2587. // Get the proper (default language) response prefix first.
  2588. if (!isset($context['response_prefix']) && !($context['response_prefix'] = cache_get_data('response_prefix')))
  2589. {
  2590. if ($language === $user_info['language'])
  2591. $context['response_prefix'] = $txt['response_prefix'];
  2592. else
  2593. {
  2594. loadLanguage('index', $language, false);
  2595. $context['response_prefix'] = $txt['response_prefix'];
  2596. loadLanguage('index');
  2597. }
  2598. cache_put_data('response_prefix', $context['response_prefix'], 600);
  2599. }
  2600. $smcFunc['db_query']('', '
  2601. UPDATE {db_prefix}messages
  2602. SET subject = {string:subject}
  2603. WHERE id_topic = {int:current_topic}
  2604. AND id_msg != {int:id_first_msg}',
  2605. array(
  2606. 'current_topic' => $topic,
  2607. 'id_first_msg' => $row['id_first_msg'],
  2608. 'subject' => $context['response_prefix'] . $_POST['subject'],
  2609. )
  2610. );
  2611. }
  2612. if (!empty($moderationAction))
  2613. logAction('modify', array('topic' => $topic, 'message' => $row['id_msg'], 'member' => $row['id_member'], 'board' => $board));
  2614. }
  2615. if (isset($_REQUEST['xml']))
  2616. {
  2617. $context['sub_template'] = 'modifydone';
  2618. if (empty($post_errors) && isset($msgOptions['subject']) && isset($msgOptions['body']))
  2619. {
  2620. $context['message'] = array(
  2621. 'id' => $row['id_msg'],
  2622. 'modified' => array(
  2623. 'time' => isset($msgOptions['modify_time']) ? timeformat($msgOptions['modify_time']) : '',
  2624. 'timestamp' => isset($msgOptions['modify_time']) ? forum_time(true, $msgOptions['modify_time']) : 0,
  2625. 'name' => isset($msgOptions['modify_time']) ? $msgOptions['modify_name'] : '',
  2626. ),
  2627. 'subject' => $msgOptions['subject'],
  2628. 'first_in_topic' => $row['id_msg'] == $row['id_first_msg'],
  2629. 'body' => strtr($msgOptions['body'], array(']]>' => ']]]]><![CDATA[>')),
  2630. );
  2631. censorText($context['message']['subject']);
  2632. censorText($context['message']['body']);
  2633. $context['message']['body'] = parse_bbc($context['message']['body'], $row['smileys_enabled'], $row['id_msg']);
  2634. }
  2635. // Topic?
  2636. elseif (empty($post_errors))
  2637. {
  2638. $context['sub_template'] = 'modifytopicdone';
  2639. $context['message'] = array(
  2640. 'id' => $row['id_msg'],
  2641. 'modified' => array(
  2642. 'time' => isset($msgOptions['modify_time']) ? timeformat($msgOptions['modify_time']) : '',
  2643. 'timestamp' => isset($msgOptions['modify_time']) ? forum_time(true, $msgOptions['modify_time']) : 0,
  2644. 'name' => isset($msgOptions['modify_time']) ? $msgOptions['modify_name'] : '',
  2645. ),
  2646. 'subject' => isset($msgOptions['subject']) ? $msgOptions['subject'] : '',
  2647. );
  2648. censorText($context['message']['subject']);
  2649. }
  2650. else
  2651. {
  2652. $context['message'] = array(
  2653. 'id' => $row['id_msg'],
  2654. 'errors' => array(),
  2655. 'error_in_subject' => in_array('no_subject', $post_errors),
  2656. 'error_in_body' => in_array('no_message', $post_errors) || in_array('long_message', $post_errors),
  2657. );
  2658. loadLanguage('Errors');
  2659. foreach ($post_errors as $post_error)
  2660. {
  2661. if ($post_error == 'long_message')
  2662. $context['message']['errors'][] = sprintf($txt['error_' . $post_error], $modSettings['max_messageLength']);
  2663. else
  2664. $context['message']['errors'][] = $txt['error_' . $post_error];
  2665. }
  2666. }
  2667. }
  2668. else
  2669. obExit(false);
  2670. }
  2671. ?>