Post.php 111 KB

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