Post.php 111 KB

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