12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293 |
- <?php
- if (!defined('SMF'))
- die('Hacking attempt...');
- function preparsecode(&$message, $previewing = false)
- {
- global $user_info, $modSettings, $smcFunc, $context;
-
- $message = preg_replace('~&#(\d{4,5}|[2-9]\d{2,4}|1[2-9]\d);~', '&#$1;', $message);
-
- $message = preg_replace('~\[nobbc\](.+?)\[/nobbc\]~ie', '\'[nobbc]\' . strtr(\'$1\', array(\'[\' => \'[\', \']\' => \']\', \':\' => \':\', \'@\' => \'@\')) . \'[/nobbc]\'', $message);
-
- $message = strtr($message, array("\r" => ''));
-
- $message = preg_replace('~\.{100,}~', '...', $message);
-
- while (substr($message, -7) == '[quote]')
- $message = substr($message, 0, -7);
- while (substr($message, 0, 8) == '[/quote]')
- $message = substr($message, 8);
-
- $in_tag = false;
- $had_tag = false;
- $codeopen = 0;
- if (preg_match_all('~(\[(/)*code(?:=[^\]]+)?\])~is', $message, $matches))
- foreach ($matches[0] as $index => $dummy)
- {
-
- if (!empty($matches[2][$index]))
- {
-
- if (!$in_tag)
- $codeopen = true;
-
- $in_tag = false;
- }
-
- else
- {
- $had_tag = true;
-
- if (!$in_tag)
- $in_tag = true;
- }
- }
-
- if ($in_tag)
- $message .= '[/code]';
-
- if ($codeopen && !$had_tag)
- $message = '[code]' . $message;
-
- $parts = preg_split('~(\[/code\]|\[code(?:=[^\]]+)?\])~i', $message, -1, PREG_SPLIT_DELIM_CAPTURE);
-
- $non_breaking_space = $context['utf8'] ? '\x{A0}' : '\xA0';
-
- for ($i = 0, $n = count($parts); $i < $n; $i++)
- {
-
- if ($i % 4 == 0)
- {
- fixTags($parts[$i]);
-
- if (strpos($user_info['name'], '[') !== false || strpos($user_info['name'], ']') !== false || strpos($user_info['name'], '\'') !== false || strpos($user_info['name'], '"') !== false)
- $parts[$i] = preg_replace('~(\A|\n)/me(?: | )([^\n]*)(?:\z)?~i', '$1[me="' . $user_info['name'] . '"]$2[/me]', $parts[$i]);
- else
- $parts[$i] = preg_replace('~(\A|\n)/me(?: | )([^\n]*)(?:\z)?~i', '$1[me=' . $user_info['name'] . ']$2[/me]', $parts[$i]);
- if (!$previewing && strpos($parts[$i], '[html]') !== false)
- {
- if (allowedTo('admin_forum'))
- $parts[$i] = preg_replace('~\[html\](.+?)\[/html\]~ise', '\'[html]\' . strtr(un_htmlspecialchars(\'$1\'), array("\n" => \' \', \' \' => \'  \', \'[\' => \'[\', \']\' => \']\')) . \'[/html]\'', $parts[$i]);
-
- else
- {
- while (strpos($parts[$i], '[html]') !== false)
- $parts[$i] = preg_replace('~\[[/]?html\]~i', '', $parts[$i]);
- }
- }
-
- $parts[$i] = preg_replace('~\[time(?:=(absolute))*\](.+?)\[/time\]~ie', '\'[time]\' . (is_numeric(\'$2\') || @strtotime(\'$2\') == 0 ? \'$2\' : strtotime(\'$2\') - (\'$1\' == \'absolute\' ? 0 : (($modSettings[\'time_offset\'] + $user_info[\'time_offset\']) * 3600))) . \'[/time]\'', $parts[$i]);
-
- $parts[$i] = preg_replace('~\[(black|blue|green|red|white)\]~', '[color=$1]', $parts[$i]);
- $parts[$i] = preg_replace('~\[/(black|blue|green|red|white)\]~', '[/color]', $parts[$i]);
-
- $parts[$i] = preg_replace('~\[([/]?)(list|li|table|tr|td)((\s[^\]]+)*)\]~ie', '\'[$1\' . strtolower(\'$2\') . \'$3]\'', $parts[$i]);
- $list_open = substr_count($parts[$i], '[list]') + substr_count($parts[$i], '[list ');
- $list_close = substr_count($parts[$i], '[/list]');
- if ($list_close - $list_open > 0)
- $parts[$i] = str_repeat('[list]', $list_close - $list_open) . $parts[$i];
- if ($list_open - $list_close > 0)
- $parts[$i] = $parts[$i] . str_repeat('[/list]', $list_open - $list_close);
- $mistake_fixes = array(
-
- '~\[table\](?![\s' . $non_breaking_space . ']*\[tr\])~s' . ($context['utf8'] ? 'u' : '') => '[table][tr]',
-
- '~\[tr\](?![\s' . $non_breaking_space . ']*\[td\])~s' . ($context['utf8'] ? 'u' : '') => '[tr][td]',
-
- '~\[/td\](?![\s' . $non_breaking_space . ']*(?:\[td\]|\[/tr\]|\[/table\]))~s' . ($context['utf8'] ? 'u' : '') => '[/td][/tr]',
-
- '~\[/tr\](?![\s' . $non_breaking_space . ']*(?:\[tr\]|\[/table\]))~s' . ($context['utf8'] ? 'u' : '') => '[/tr][/table]',
-
- '~\[/td\][\s' . $non_breaking_space . ']*\[/table\]~s' . ($context['utf8'] ? 'u' : '') => '[/td][/tr][/table]',
-
- '~\[(table|tr|/td)\]([\s' . $non_breaking_space . ']*)\[td\]~s' . ($context['utf8'] ? 'u' : '') => '[$1]$2[_td_]',
-
- '~\[td\]~s' => '[tr][td]',
-
- '~\[(table|/tr)\]([\s' . $non_breaking_space . ']*)\[tr\]~s' . ($context['utf8'] ? 'u' : '') => '[$1]$2[_tr_]',
-
- '~\[tr\]~s' => '[table][tr]',
-
- '~\[/td\]([\s' . $non_breaking_space . ']*)\[/tr\]~s' . ($context['utf8'] ? 'u' : '') => '[/td]$1[_/tr_]',
-
- '~\[/tr\]~s' => '[/td][/tr]',
-
- '~\[li\]([^\[\]]+?)\[li\]~s' => '[li]$1[_/li_][_li_]',
- '~\[li\]([^\[\]]+?)\[/list\]~s' => '[_li_]$1[_/li_][/list]',
- '~\[li\]([^\[\]]+?)$~s' => '[li]$1[/li]',
-
- '~\[/li\]([\s' . $non_breaking_space . ']*)\[/list\]~s' . ($context['utf8'] ? 'u' : '') => '[_/li_]$1[/list]',
-
- '~\[/li\]([\s' . $non_breaking_space . ']*)\[li\]~s' . ($context['utf8'] ? 'u' : '') => '[_/li_]$1[_li_]',
-
- '~\[(list(?: [^\]]*?)?|/li)\]([\s' . $non_breaking_space . ']*)\[li\]~s' . ($context['utf8'] ? 'u' : '') => '[$1]$2[_li_]',
-
- '~\[/li\]([\s' . $non_breaking_space . ']*)\[list\]~' . ($context['utf8'] ? 'u' : '') => '[_/li_]$1[list]',
- '~\[/list\]([\s' . $non_breaking_space . ']*)\[li\]~' . ($context['utf8'] ? 'u' : '') => '[/list]$1[_li_]',
-
- '~\[li\]~' => '[list][li]',
-
- '~\[/li\]~' => '[/li][/list]',
-
- '~\[_(li|/li|td|tr|/tr)_\]~' => '[$1]',
-
- '~\[img\]https?://.{0,7}\[/img\]~' => '',
- );
-
- for ($j = 0; $j < 3; $j++)
- $parts[$i] = preg_replace(array_keys($mistake_fixes), $mistake_fixes, $parts[$i]);
-
- $table_check = $parts[$i];
- $table_offset = 0;
- $table_array = array();
- $table_order = array(
- 'table' => 'td',
- 'tr' => 'table',
- 'td' => 'tr',
- );
- while (preg_match('~\[(/)*(table|tr|td)\]~', $table_check, $matches) != false)
- {
-
- $offset = strpos($table_check, $matches[0]);
- $remove_tag = false;
-
- if ($matches[1] != '/')
- {
-
- if ((!empty($table_array) && $table_array[0] != $table_order[$matches[2]]) || (empty($table_array) && $matches[2] != 'table'))
- $remove_tag = true;
-
- else
- array_unshift($table_array, $matches[2]);
- }
-
- else
- {
-
- if (empty($table_array) || ($table_array[0] != $matches[2]))
- $remove_tag = true;
- else
- array_shift($table_array);
- }
-
- if ($remove_tag)
- {
- $parts[$i] = substr($parts[$i], 0, $table_offset + $offset) . substr($parts[$i], $table_offset + strlen($matches[0]) + $offset);
-
- $table_offset -= strlen($matches[0]);
- }
-
- $table_offset += $offset + strlen($matches[0]);
- $table_check = substr($table_check, $offset + strlen($matches[0]));
- }
-
- foreach ($table_array as $tag)
- $parts[$i] .= '[/' . $tag . ']';
- }
- }
-
- if (!$previewing)
- $message = strtr(implode('', $parts), array(' ' => ' ', "\n" => '<br />', $context['utf8'] ? "\xC2\xA0" : "\xA0" => ' '));
- else
- $message = strtr(implode('', $parts), array(' ' => ' ', $context['utf8'] ? "\xC2\xA0" : "\xA0" => ' '));
-
- $message = strtr($message, array('[]' => '[]', '['' => '[''));
-
- $message = preg_replace('~\[[bisu]\]\s*\[/[bisu]\]~', '', $message);
- $message = preg_replace('~\[quote\]\s*\[/quote\]~', '', $message);
- }
- function un_preparsecode($message)
- {
- global $smcFunc;
- $parts = preg_split('~(\[/code\]|\[code(?:=[^\]]+)?\])~i', $message, -1, PREG_SPLIT_DELIM_CAPTURE);
-
- for ($i = 0, $n = count($parts); $i < $n; $i++)
- {
-
- if ($i % 4 == 0)
- {
- $parts[$i] = preg_replace('~\[html\](.+?)\[/html\]~ie', '\'[html]\' . strtr(htmlspecialchars(\'$1\', ENT_QUOTES), array(\'\\"\' => \'"\', \'&#13;\' => \'<br />\', \'&#32;\' => \' \', \'&#91;\' => \'[\', \'&#93;\' => \']\')) . \'[/html]\'', $parts[$i]);
-
-
- $parts[$i] = preg_replace('~\[time\](\d{0,10})\[/time\]~ie', '\'[time]\' . timeformat(\'$1\', false) . \'[/time]\'', $parts[$i]);
- }
- }
-
- return preg_replace('~<br( /)?' . '>~', "\n", str_replace(' ', ' ', implode('', $parts)));
- }
- function fixTags(&$message)
- {
- global $modSettings;
-
-
- $fixArray = array(
-
- array(
- 'tag' => 'img',
- 'protocols' => array('http', 'https'),
- 'embeddedUrl' => false,
- 'hasEqualSign' => false,
- 'hasExtra' => true,
- ),
-
- array(
- 'tag' => 'url',
- 'protocols' => array('http', 'https'),
- 'embeddedUrl' => true,
- 'hasEqualSign' => false,
- ),
-
- array(
- 'tag' => 'url',
- 'protocols' => array('http', 'https'),
- 'embeddedUrl' => true,
- 'hasEqualSign' => true,
- ),
-
- array(
- 'tag' => 'iurl',
- 'protocols' => array('http', 'https'),
- 'embeddedUrl' => true,
- 'hasEqualSign' => false,
- ),
-
- array(
- 'tag' => 'iurl',
- 'protocols' => array('http', 'https'),
- 'embeddedUrl' => true,
- 'hasEqualSign' => true,
- ),
-
- array(
- 'tag' => 'ftp',
- 'protocols' => array('ftp', 'ftps'),
- 'embeddedUrl' => true,
- 'hasEqualSign' => false,
- ),
-
- array(
- 'tag' => 'ftp',
- 'protocols' => array('ftp', 'ftps'),
- 'embeddedUrl' => true,
- 'hasEqualSign' => true,
- ),
-
- array(
- 'tag' => 'flash',
- 'protocols' => array('http', 'https'),
- 'embeddedUrl' => false,
- 'hasEqualSign' => false,
- 'hasExtra' => true,
- ),
- );
-
- foreach ($fixArray as $param)
- fixTag($message, $param['tag'], $param['protocols'], $param['embeddedUrl'], $param['hasEqualSign'], !empty($param['hasExtra']));
-
- $message = preg_replace('~(\[img.*?\])(.+?)\[/img\]~eis', '\'$1\' . preg_replace(\'~action(=|%3d)(?!dlattach)~i\', \'action-\', \'$2\') . \'[/img]\'', $message);
-
- if (!empty($modSettings['max_image_width']) || !empty($modSettings['max_image_height']))
- {
-
- preg_match_all('~\[img(\s+width=\d+)?(\s+height=\d+)?(\s+width=\d+)?\](.+?)\[/img\]~is', $message, $matches, PREG_PATTERN_ORDER);
- $replaces = array();
- foreach ($matches[0] as $match => $dummy)
- {
-
- $matches[1][$match] = !empty($matches[3][$match]) ? $matches[3][$match] : $matches[1][$match];
-
- $desired_width = !empty($matches[1][$match]) ? (int) substr(trim($matches[1][$match]), 6) : 0;
- $desired_height = !empty($matches[2][$match]) ? (int) substr(trim($matches[2][$match]), 7) : 0;
-
- if (empty($desired_width) || empty($desired_height))
- {
- list ($width, $height) = url_image_size(un_htmlspecialchars($matches[4][$match]));
-
- if (empty($desired_width) && empty($desired_height))
- {
- $desired_width = $width;
- $desired_height = $height;
- }
-
- elseif (empty($desired_width) && !empty($height))
- $desired_width = (int) (($desired_height * $width) / $height);
-
- elseif (!empty($width))
- $desired_height = (int) (($desired_width * $height) / $width);
- }
-
- if ($desired_width <= $modSettings['max_image_width'] && $desired_height <= $modSettings['max_image_height'])
- continue;
-
- if ($desired_width > $modSettings['max_image_width'] && !empty($modSettings['max_image_width']))
- {
- $desired_height = (int) (($modSettings['max_image_width'] * $desired_height) / $desired_width);
- $desired_width = $modSettings['max_image_width'];
- }
-
- if ($desired_height > $modSettings['max_image_height'] && !empty($modSettings['max_image_height']))
- {
- $desired_width = (int) (($modSettings['max_image_height'] * $desired_width) / $desired_height);
- $desired_height = $modSettings['max_image_height'];
- }
- $replaces[$matches[0][$match]] = '[img' . (!empty($desired_width) ? ' width=' . $desired_width : '') . (!empty($desired_height) ? ' height=' . $desired_height : '') . ']' . $matches[4][$match] . '[/img]';
- }
-
- if (!empty($replaces))
- $message = strtr($message, $replaces);
- }
- }
- function fixTag(&$message, $myTag, $protocols, $embeddedUrl = false, $hasEqualSign = false, $hasExtra = false)
- {
- global $boardurl, $scripturl;
- if (preg_match('~^([^:]+://[^/]+)~', $boardurl, $match) != 0)
- $domain_url = $match[1];
- else
- $domain_url = $boardurl . '/';
- $replaces = array();
- if ($hasEqualSign)
- preg_match_all('~\[(' . $myTag . ')=([^\]]*?)\](?:(.+?)\[/(' . $myTag . ')\])?~is', $message, $matches);
- else
- preg_match_all('~\[(' . $myTag . ($hasExtra ? '(?:[^\]]*?)' : '') . ')\](.+?)\[/(' . $myTag . ')\]~is', $message, $matches);
- foreach ($matches[0] as $k => $dummy)
- {
-
- $replace = trim($matches[2][$k]);
- $this_tag = $matches[1][$k];
- $this_close = $hasEqualSign ? (empty($matches[4][$k]) ? '' : $matches[4][$k]) : $matches[3][$k];
- $found = false;
- foreach ($protocols as $protocol)
- {
- $found = strncasecmp($replace, $protocol . '://', strlen($protocol) + 3) === 0;
- if ($found)
- break;
- }
- if (!$found && $protocols[0] == 'http')
- {
- if (substr($replace, 0, 1) == '/')
- $replace = $domain_url . $replace;
- elseif (substr($replace, 0, 1) == '?')
- $replace = $scripturl . $replace;
- elseif (substr($replace, 0, 1) == '#' && $embeddedUrl)
- {
- $replace = '#' . preg_replace('~[^A-Za-z0-9_\-#]~', '', substr($replace, 1));
- $this_tag = 'iurl';
- $this_close = 'iurl';
- }
- else
- $replace = $protocols[0] . '://' . $replace;
- }
- elseif (!$found && $protocols[0] == 'ftp')
- $replace = $protocols[0] . '://' . preg_replace('~^(?!ftps?)[^:]+://~', '', $replace);
- elseif (!$found)
- $replace = $protocols[0] . '://' . $replace;
- if ($hasEqualSign && $embeddedUrl)
- $replaces[$matches[0][$k]] = '[' . $this_tag . '=' . $replace . ']' . (empty($matches[4][$k]) ? '' : $matches[3][$k] . '[/' . $this_close . ']');
- elseif ($hasEqualSign)
- $replaces['[' . $matches[1][$k] . '=' . $matches[2][$k] . ']'] = '[' . $this_tag . '=' . $replace . ']';
- elseif ($embeddedUrl)
- $replaces['[' . $matches[1][$k] . ']' . $matches[2][$k] . '[/' . $matches[3][$k] . ']'] = '[' . $this_tag . '=' . $replace . ']' . $matches[2][$k] . '[/' . $this_close . ']';
- else
- $replaces['[' . $matches[1][$k] . ']' . $matches[2][$k] . '[/' . $matches[3][$k] . ']'] = '[' . $this_tag . ']' . $replace . '[/' . $this_close . ']';
- }
- foreach ($replaces as $k => $v)
- {
- if ($k == $v)
- unset($replaces[$k]);
- }
- if (!empty($replaces))
- $message = strtr($message, $replaces);
- }
- function sendmail($to, $subject, $message, $from = null, $message_id = null, $send_html = false, $priority = 3, $hotmail_fix = null, $is_private = false)
- {
- global $webmaster_email, $context, $modSettings, $txt, $scripturl;
- global $smcFunc;
-
- $use_sendmail = empty($modSettings['mail_type']) || $modSettings['smtp_host'] == '';
-
- $line_break = $context['server']['is_windows'] || !$use_sendmail ? "\r\n" : "\n";
-
- $mail_result = true;
-
- $to_array = is_array($to) ? $to : array($to);
-
-
- if ($hotmail_fix === null)
- {
- $hotmail_to = array();
- foreach ($to_array as $i => $to_address)
- {
- if (preg_match('~@(att|comcast|bellsouth)\.[a-zA-Z\.]{2,6}$~i', $to_address) === 1)
- {
- $hotmail_to[] = $to_address;
- $to_array = array_diff($to_array, array($to_address));
- }
- }
-
- if (!empty($hotmail_to))
- $mail_result = sendmail($hotmail_to, $subject, $message, $from, $message_id, $send_html, $priority, true, $is_private);
-
- $hotmail_fix = false;
-
- if (empty($to_array))
- return $mail_result;
- }
-
- $subject = un_htmlspecialchars($subject);
-
- $message = str_replace(array("\r", "\n"), array('', $line_break), $message);
-
- if ($hotmail_fix && !$send_html)
- {
- $send_html = true;
- $message = strtr($message, array($line_break => '<br />' . $line_break));
- $message = preg_replace('~(' . preg_quote($scripturl, '~') . '(?:[?/][\w\-_%\.,\?&;=#]+)?)~', '<a href="$1">$1</a>', $message);
- }
- list (, $from_name) = mimespecialchars(addcslashes($from !== null ? $from : $context['forum_name'], '<>()\'\\"'), true, $hotmail_fix, $line_break);
- list (, $subject) = mimespecialchars($subject, true, $hotmail_fix, $line_break);
-
- $headers = 'From: "' . $from_name . '" <' . (empty($modSettings['mail_from']) ? $webmaster_email : $modSettings['mail_from']) . '>' . $line_break;
- $headers .= $from !== null ? 'Reply-To: <' . $from . '>' . $line_break : '';
- $headers .= 'Return-Path: ' . (empty($modSettings['mail_from']) ? $webmaster_email : $modSettings['mail_from']) . $line_break;
- $headers .= 'Date: ' . gmdate('D, d M Y H:i:s') . ' -0000' . $line_break;
- if ($message_id !== null && empty($modSettings['mail_no_message_id']))
- $headers .= 'Message-ID: <' . md5($scripturl . microtime()) . '-' . $message_id . strstr(empty($modSettings['mail_from']) ? $webmaster_email : $modSettings['mail_from'], '@') . '>' . $line_break;
- $headers .= 'X-Mailer: SMF' . $line_break;
-
- if (in_array(false, call_integration_hook('integrate_outgoing_email', array(&$subject, &$message, &$headers)), true))
- return false;
-
- $orig_message = $message;
-
- $mime_boundary = 'SMF-' . md5($message . time());
-
- $headers .= 'Mime-Version: 1.0' . $line_break;
- $headers .= 'Content-Type: multipart/alternative; boundary="' . $mime_boundary . '"' . $line_break;
- $headers .= 'Content-Transfer-Encoding: 7bit' . $line_break;
-
- if ($send_html)
- {
- $no_html_message = un_htmlspecialchars(strip_tags(strtr($orig_message, array('</title>' => $line_break))));
-
- list(, $plain_message) = mimespecialchars($no_html_message, false, true, $line_break);
- $message = $plain_message . $line_break . '--' . $mime_boundary . $line_break;
-
- list($charset, $plain_charset_message, $encoding) = mimespecialchars($no_html_message, false, false, $line_break);
- $message .= 'Content-Type: text/plain; charset=' . $charset . $line_break;
- $message .= 'Content-Transfer-Encoding: ' . $encoding . $line_break . $line_break;
- $message .= $plain_charset_message . $line_break . '--' . $mime_boundary . $line_break;
-
- list($charset, $html_message, $encoding) = mimespecialchars($orig_message, false, $hotmail_fix, $line_break);
- $message .= 'Content-Type: text/html; charset=' . $charset . $line_break;
- $message .= 'Content-Transfer-Encoding: ' . ($encoding == '' ? '7bit' : $encoding) . $line_break . $line_break;
- $message .= $html_message . $line_break . '--' . $mime_boundary . '--';
- }
-
- else
- {
-
- list(, $plain_message) = mimespecialchars($orig_message, false, true, $line_break);
- $message = $plain_message . $line_break . '--' . $mime_boundary . $line_break;
-
- list ($charset, $encoded_message, $encoding) = mimespecialchars($orig_message, false, false, $line_break);
- $message .= 'Content-Type: text/plain; charset=' . $charset . $line_break;
- $message .= 'Content-Transfer-Encoding: ' . $encoding . $line_break . $line_break;
- $message .= $encoded_message . $line_break . '--' . $mime_boundary . '--';
- }
-
- if (!empty($modSettings['mail_queue']) && $priority != 0)
- return AddMailQueue(false, $to_array, $subject, $message, $headers, $send_html, $priority, $is_private);
-
- elseif (!empty($modSettings['mail_queue']) && !empty($modSettings['mail_limit']))
- {
- list ($last_mail_time, $mails_this_minute) = @explode('|', $modSettings['mail_recent']);
- if (empty($mails_this_minute) || time() > $last_mail_time + 60)
- $new_queue_stat = time() . '|' . 1;
- else
- $new_queue_stat = $last_mail_time . '|' . ((int) $mails_this_minute + 1);
- updateSettings(array('mail_recent' => $new_queue_stat));
- }
-
- if ($use_sendmail)
- {
- $subject = strtr($subject, array("\r" => '', "\n" => ''));
- if (!empty($modSettings['mail_strip_carriage']))
- {
- $message = strtr($message, array("\r" => ''));
- $headers = strtr($headers, array("\r" => ''));
- }
- foreach ($to_array as $to)
- {
- if (!mail(strtr($to, array("\r" => '', "\n" => '')), $subject, $message, $headers))
- {
- log_error(sprintf($txt['mail_send_unable'], $to));
- $mail_result = false;
- }
-
- @set_time_limit(300);
- if (function_exists('apache_reset_timeout'))
- @apache_reset_timeout();
- }
- }
- else
- $mail_result = $mail_result && smtp_mail($to_array, $subject, $message, $headers);
-
- return $mail_result;
- }
- function AddMailQueue($flush = false, $to_array = array(), $subject = '', $message = '', $headers = '', $send_html = false, $priority = 3, $is_private = false)
- {
- global $context, $modSettings, $smcFunc;
- static $cur_insert = array();
- static $cur_insert_len = 0;
- if ($cur_insert_len == 0)
- $cur_insert = array();
-
- if (($flush || $cur_insert_len > 800000) && !empty($cur_insert))
- {
-
- $cur_insert_len = 0;
-
- $smcFunc['db_insert']('',
- '{db_prefix}mail_queue',
- array(
- 'time_sent' => 'int', 'recipient' => 'string-255', 'body' => 'string-65534', 'subject' => 'string-255',
- 'headers' => 'string-65534', 'send_html' => 'int', 'priority' => 'int', 'private' => 'int',
- ),
- $cur_insert,
- array('id_mail')
- );
- $cur_insert = array();
- $context['flush_mail'] = false;
- }
-
- if ($flush)
- {
- $nextSendTime = time() + 10;
- $smcFunc['db_query']('', '
- UPDATE {db_prefix}settings
- SET value = {string:nextSendTime}
- WHERE variable = {string:mail_next_send}
- AND value = {string:no_outstanding}',
- array(
- 'nextSendTime' => $nextSendTime,
- 'mail_next_send' => 'mail_next_send',
- 'no_outstanding' => '0',
- )
- );
- return true;
- }
-
- $context['flush_mail'] = true;
- foreach ($to_array as $to)
- {
-
- $this_insert_len = strlen($to) + strlen($message) + strlen($headers) + 700;
-
- if ($this_insert_len + $cur_insert_len > 1000000)
- {
-
- $smcFunc['db_insert']('',
- '{db_prefix}mail_queue',
- array(
- 'time_sent' => 'int', 'recipient' => 'string-255', 'body' => 'string-65534', 'subject' => 'string-255',
- 'headers' => 'string-65534', 'send_html' => 'int', 'priority' => 'int', 'private' => 'int',
- ),
- $cur_insert,
- array('id_mail')
- );
-
- $cur_insert = array();
- $cur_insert_len = 0;
- }
-
- $cur_insert[] = array(time(), (string) $to, (string) $message, (string) $subject, (string) $headers, ($send_html ? 1 : 0), $priority, (int) $is_private);
- $cur_insert_len += $this_insert_len;
- }
-
- if (SMF === 'SSI')
- return AddMailQueue(true);
- return true;
- }
- function sendpm($recipients, $subject, $message, $store_outbox = false, $from = null, $pm_head = 0)
- {
- global $scripturl, $txt, $user_info, $language;
- global $modSettings, $smcFunc;
-
- loadLanguage('PersonalMessage');
- $onBehalf = $from !== null;
-
- $log = array(
- 'failed' => array(),
- 'sent' => array()
- );
- if ($from === null)
- $from = array(
- 'id' => $user_info['id'],
- 'name' => $user_info['name'],
- 'username' => $user_info['username']
- );
-
- else
- $user_info['name'] = $from['name'];
-
- $htmlmessage = $smcFunc['htmlspecialchars']($message, ENT_QUOTES);
- $htmlsubject = $smcFunc['htmlspecialchars']($subject);
- preparsecode($htmlmessage);
-
- call_integration_hook('integrate_personal_message', array(&$recipients, &$from['username'], &$subject, &$message));
-
- $usernames = array();
- foreach ($recipients as $rec_type => $rec)
- {
- foreach ($rec as $id => $member)
- {
- if (!is_numeric($recipients[$rec_type][$id]))
- {
- $recipients[$rec_type][$id] = $smcFunc['strtolower'](trim(preg_replace('/[<>&"\'=\\\]/', '', $recipients[$rec_type][$id])));
- $usernames[$recipients[$rec_type][$id]] = 0;
- }
- }
- }
- if (!empty($usernames))
- {
- $request = $smcFunc['db_query']('pm_find_username', '
- SELECT id_member, member_name
- FROM {db_prefix}members
- WHERE ' . ($smcFunc['db_case_sensitive'] ? 'LOWER(member_name)' : 'member_name') . ' IN ({array_string:usernames})',
- array(
- 'usernames' => array_keys($usernames),
- )
- );
- while ($row = $smcFunc['db_fetch_assoc']($request))
- if (isset($usernames[$smcFunc['strtolower']($row['member_name'])]))
- $usernames[$smcFunc['strtolower']($row['member_name'])] = $row['id_member'];
- $smcFunc['db_free_result']($request);
-
- foreach ($recipients as $rec_type => $rec)
- foreach ($rec as $id => $member)
- {
- if (is_numeric($recipients[$rec_type][$id]))
- continue;
- if (!empty($usernames[$member]))
- $recipients[$rec_type][$id] = $usernames[$member];
- else
- {
- $log['failed'][$id] = sprintf($txt['pm_error_user_not_found'], $recipients[$rec_type][$id]);
- unset($recipients[$rec_type][$id]);
- }
- }
- }
-
- $recipients['to'] = array_unique($recipients['to']);
-
- $recipients['bcc'] = array_diff(array_unique($recipients['bcc']), $recipients['to']);
-
- $all_to = array_merge($recipients['to'], $recipients['bcc']);
-
- $request = $smcFunc['db_query']('', '
- SELECT
- id_member, criteria, is_or
- FROM {db_prefix}pm_rules
- WHERE id_member IN ({array_int:to_members})
- AND delete_pm = {int:delete_pm}',
- array(
- 'to_members' => $all_to,
- 'delete_pm' => 1,
- )
- );
- $deletes = array();
-
- while ($row = $smcFunc['db_fetch_assoc']($request))
- {
- $criteria = unserialize($row['criteria']);
-
- $delete = false;
- foreach ($criteria as $criterium)
- {
- $match = false;
- if (($criterium['t'] == 'mid' && $criterium['v'] == $from['id']) || ($criterium['t'] == 'gid' && in_array($criterium['v'], $user_info['groups'])) || ($criterium['t'] == 'sub' && strpos($subject, $criterium['v']) !== false) || ($criterium['t'] == 'msg' && strpos($message, $criterium['v']) !== false))
- $delete = true;
-
- elseif (!$row['is_or'])
- {
- $delete = false;
- break;
- }
- }
- if ($delete)
- $deletes[$row['id_member']] = 1;
- }
- $smcFunc['db_free_result']($request);
-
-
- static $message_limit_cache = array();
- if (!allowedTo('moderate_forum') && empty($message_limit_cache))
- {
- $request = $smcFunc['db_query']('', '
- SELECT id_group, max_messages
- FROM {db_prefix}membergroups',
- array(
- )
- );
- while ($row = $smcFunc['db_fetch_assoc']($request))
- $message_limit_cache[$row['id_group']] = $row['max_messages'];
- $smcFunc['db_free_result']($request);
- }
-
-
- $allowed_groups = array();
- $disallowed_groups = array();
- $request = $smcFunc['db_query']('', '
- SELECT id_group, add_deny
- FROM {db_prefix}permissions
- WHERE permission = {string:read_permission}',
- array(
- 'read_permission' => 'pm_read',
- )
- );
- while ($row = $smcFunc['db_fetch_assoc']($request))
- {
- if (empty($row['add_deny']))
- $disallowed_groups[] = $row['id_group'];
- else
- $allowed_groups[] = $row['id_group'];
- }
- $smcFunc['db_free_result']($request);
- if (empty($modSettings['permission_enable_deny']))
- $disallowed_groups = array();
- $request = $smcFunc['db_query']('', '
- SELECT
- member_name, real_name, id_member, email_address, lngfile,
- pm_email_notify, instant_messages,' . (allowedTo('moderate_forum') ? ' 0' : '
- (pm_receive_from = {int:admins_only}' . (empty($modSettings['enable_buddylist']) ? '' : ' OR
- (pm_receive_from = {int:buddies_only} AND FIND_IN_SET({string:from_id}, buddy_list) = 0) OR
- (pm_receive_from = {int:not_on_ignore_list} AND FIND_IN_SET({string:from_id}, pm_ignore_list) != 0)') . ')') . ' AS ignored,
- FIND_IN_SET({string:from_id}, buddy_list) != 0 AS is_buddy, is_activated,
- additional_groups, id_group, id_post_group
- FROM {db_prefix}members
- WHERE id_member IN ({array_int:recipients})
- ORDER BY lngfile
- LIMIT {int:count_recipients}',
- array(
- 'not_on_ignore_list' => 1,
- 'buddies_only' => 2,
- 'admins_only' => 3,
- 'recipients' => $all_to,
- 'count_recipients' => count($all_to),
- 'from_id' => $from['id'],
- )
- );
- $notifications = array();
- while ($row = $smcFunc['db_fetch_assoc']($request))
- {
-
- if (isset($deletes[$row['id_member']]))
- continue;
-
- $groups = explode(',', $row['additional_groups']);
- $groups[] = $row['id_group'];
- $groups[] = $row['id_post_group'];
- $message_limit = -1;
-
- if (!in_array(1, $groups))
- {
- foreach ($groups as $id)
- {
- if (isset($message_limit_cache[$id]) && $message_limit != 0 && $message_limit < $message_limit_cache[$id])
- $message_limit = $message_limit_cache[$id];
- }
- if ($message_limit > 0 && $message_limit <= $row['instant_messages'])
- {
- $log['failed'][$row['id_member']] = sprintf($txt['pm_error_data_limit_reached'], $row['real_name']);
- unset($all_to[array_search($row['id_member'], $all_to)]);
- continue;
- }
-
- if (count(array_intersect($allowed_groups, $groups)) == 0 || count(array_intersect($disallowed_groups, $groups)) != 0)
- {
- $log['failed'][$row['id_member']] = sprintf($txt['pm_error_user_cannot_read'], $row['real_name']);
- unset($all_to[array_search($row['id_member'], $all_to)]);
- continue;
- }
- }
-
- if (!empty($row['ignored']) && $row['ignored'] != 'f' && $row['id_member'] != $from['id'])
- {
- $log['failed'][$row['id_member']] = sprintf($txt['pm_error_ignored_by_user'], $row['real_name']);
- unset($all_to[array_search($row['id_member'], $all_to)]);
- continue;
- }
-
- if ($row['is_activated'] >= 10 || ($row['is_activated'] == 4 && !$user_info['is_admin']))
- {
- $log['failed'][$row['id_member']] = sprintf($txt['pm_error_user_cannot_read'], $row['real_name']);
- unset($all_to[array_search($row['id_member'], $all_to)]);
- continue;
- }
-
- if (!empty($row['email_address']) && ($row['pm_email_notify'] == 1 || ($row['pm_email_notify'] > 1 && (!empty($modSettings['enable_buddylist']) && $row['is_buddy']))) && $row['is_activated'] == 1)
- $notifications[empty($row['lngfile']) || empty($modSettings['userLanguage']) ? $language : $row['lngfile']][] = $row['email_address'];
- $log['sent'][$row['id_member']] = sprintf(isset($txt['pm_successfully_sent']) ? $txt['pm_successfully_sent'] : '', $row['real_name']);
- }
- $smcFunc['db_free_result']($request);
-
- if (empty($all_to))
- return $log;
-
- $smcFunc['db_insert']('',
- '{db_prefix}personal_messages',
- array(
- 'id_pm_head' => 'int', 'id_member_from' => 'int', 'deleted_by_sender' => 'int',
- 'from_name' => 'string-255', 'msgtime' => 'int', 'subject' => 'string-255', 'body' => 'string-65534',
- ),
- array(
- $pm_head, $from['id'], ($store_outbox ? 0 : 1),
- $from['username'], time(), $htmlsubject, $htmlmessage,
- ),
- array('id_pm')
- );
- $id_pm = $smcFunc['db_insert_id']('{db_prefix}personal_messages', 'id_pm');
-
- if (!empty($id_pm))
- {
-
- if (empty($pm_head))
- $smcFunc['db_query']('', '
- UPDATE {db_prefix}personal_messages
- SET id_pm_head = {int:id_pm_head}
- WHERE id_pm = {int:id_pm_head}',
- array(
- 'id_pm_head' => $id_pm,
- )
- );
-
- $smcFunc['db_query']('', '
- DELETE FROM {db_prefix}pm_recipients
- WHERE id_pm = {int:id_pm}',
- array(
- 'id_pm' => $id_pm,
- )
- );
- $insertRows = array();
- foreach ($all_to as $to)
- {
- $insertRows[] = array($id_pm, $to, in_array($to, $recipients['bcc']) ? 1 : 0, isset($deletes[$to]) ? 1 : 0, 1);
- }
- $smcFunc['db_insert']('insert',
- '{db_prefix}pm_recipients',
- array(
- 'id_pm' => 'int', 'id_member' => 'int', 'bcc' => 'int', 'deleted' => 'int', 'is_new' => 'int'
- ),
- $insertRows,
- array('id_pm', 'id_member')
- );
- }
- censorText($message);
- censorText($subject);
- $message = trim(un_htmlspecialchars(strip_tags(strtr(parse_bbc(htmlspecialchars($message), false), array('<br />' => "\n", '</div>' => "\n", '</li>' => "\n", '[' => '[', ']' => ']')))));
- foreach ($notifications as $lang => $notification_list)
- {
-
- loadLanguage('index+PersonalMessage', $lang, false);
-
- $mailsubject = str_replace(array('SUBJECT', 'SENDER'), array($subject, un_htmlspecialchars($from['name'])), $txt['new_pm_subject']);
- $mailmessage = str_replace(array('SUBJECT', 'MESSAGE', 'SENDER'), array($subject, $message, un_htmlspecialchars($from['name'])), $txt['pm_email']);
- $mailmessage .= "\n\n" . $txt['instant_reply'] . ' ' . $scripturl . '?action=pm;sa=send;f=inbox;pmsg=' . $id_pm . ';quote;u=' . $from['id'];
-
- sendmail($notification_list, $mailsubject, $mailmessage, null, 'p' . $id_pm, false, 2, null, true);
- }
-
- loadLanguage('index+PersonalMessage');
-
- foreach ($all_to as $k => $id)
- if (isset($deletes[$id]))
- unset($all_to[$k]);
- if (!empty($all_to))
- updateMemberData($all_to, array('instant_messages' => '+', 'unread_messages' => '+', 'new_pm' => 1));
- return $log;
- }
- function mimespecialchars($string, $with_charset = true, $hotmail_fix = false, $line_break = "\r\n", $custom_charset = null)
- {
- global $context;
- $charset = $custom_charset !== null ? $custom_charset : $context['character_set'];
-
- if (preg_match_all('~&#(\d{3,8});~', $string, $matches) !== 0 && !$hotmail_fix)
- {
-
- $simple = true;
- foreach ($matches[1] as $entity)
- if ($entity > 128)
- $simple = false;
- unset($matches);
- if ($simple)
- $string = preg_replace('~&#(\d{3,8});~e', 'chr(\'$1\')', $string);
- else
- {
-
- if (!$context['utf8'] && function_exists('iconv'))
- {
- $newstring = @iconv($context['character_set'], 'UTF-8', $string);
- if ($newstring)
- $string = $newstring;
- }
- $fixchar = create_function('$n', '
- if ($n < 128)
- return chr($n);
- elseif ($n < 2048)
- return chr(192 | $n >> 6) . chr(128 | $n & 63);
- elseif ($n < 65536)
- return chr(224 | $n >> 12) . chr(128 | $n >> 6 & 63) . chr(128 | $n & 63);
- else
- return chr(240 | $n >> 18) . chr(128 | $n >> 12 & 63) . chr(128 | $n >> 6 & 63) . chr(128 | $n & 63);');
- $string = preg_replace('~&#(\d{3,8});~e', '$fixchar(\'$1\')', $string);
-
- $charset = 'UTF-8';
- }
- }
-
- if ($hotmail_fix && ($context['utf8'] || function_exists('iconv') || $context['character_set'] === 'ISO-8859-1'))
- {
- if (!$context['utf8'] && function_exists('iconv'))
- {
- $newstring = @iconv($context['character_set'], 'UTF-8', $string);
- if ($newstring)
- $string = $newstring;
- }
- $entityConvert = create_function('$c', '
- if (strlen($c) === 1 && ord($c[0]) <= 0x7F)
- return $c;
- elseif (strlen($c) === 2 && ord($c[0]) >= 0xC0 && ord($c[0]) <= 0xDF)
- return "&#" . (((ord($c[0]) ^ 0xC0) << 6) + (ord($c[1]) ^ 0x80)) . ";";
- elseif (strlen($c) === 3 && ord($c[0]) >= 0xE0 && ord($c[0]) <= 0xEF)
- return "&#" . (((ord($c[0]) ^ 0xE0) << 12) + ((ord($c[1]) ^ 0x80) << 6) + (ord($c[2]) ^ 0x80)) . ";";
- elseif (strlen($c) === 4 && ord($c[0]) >= 0xF0 && ord($c[0]) <= 0xF7)
- return "&#" . (((ord($c[0]) ^ 0xF0) << 18) + ((ord($c[1]) ^ 0x80) << 12) + ((ord($c[2]) ^ 0x80) << 6) + (ord($c[3]) ^ 0x80)) . ";";
- else
- return "";');
-
- return array($charset, preg_replace('~([\x80-\x{10FFFF}])~eu', '$entityConvert(\'\1\')', $string), '7bit');
- }
-
- elseif (!$hotmail_fix && preg_match('~([^\x09\x0A\x0D\x20-\x7F])~', $string) === 1)
- {
-
- $string = base64_encode($string);
-
- if ($with_charset)
- $string = '=?' . $charset . '?B?' . $string . '?=';
-
- else
- $string = chunk_split($string, 76, $line_break);
- return array($charset, $string, 'base64');
- }
- else
- return array($charset, $string, '7bit');
- }
- function smtp_mail($mail_to_array, $subject, $message, $headers)
- {
- global $modSettings, $webmaster_email, $txt;
- $modSettings['smtp_host'] = trim($modSettings['smtp_host']);
-
-
- if ($modSettings['mail_type'] == 2 && $modSettings['smtp_username'] != '' && $modSettings['smtp_password'] != '')
- {
- $socket = fsockopen($modSettings['smtp_host'], 110, $errno, $errstr, 2);
- if (!$socket && (substr($modSettings['smtp_host'], 0, 5) == 'smtp.' || substr($modSettings['smtp_host'], 0, 11) == 'ssl://smtp.'))
- $socket = fsockopen(strtr($modSettings['smtp_host'], array('smtp.' => 'pop.')), 110, $errno, $errstr, 2);
- if ($socket)
- {
- fgets($socket, 256);
- fputs($socket, 'USER ' . $modSettings['smtp_username'] . "\r\n");
- fgets($socket, 256);
- fputs($socket, 'PASS ' . base64_decode($modSettings['smtp_password']) . "\r\n");
- fgets($socket, 256);
- fputs($socket, 'QUIT' . "\r\n");
- fclose($socket);
- }
- }
-
- if (!$socket = fsockopen($modSettings['smtp_host'], empty($modSettings['smtp_port']) ? 25 : $modSettings['smtp_port'], $errno, $errstr, 3))
- {
-
- if (substr($modSettings['smtp_host'], 0, 4) == 'ssl:' && (empty($modSettings['smtp_port']) || $modSettings['smtp_port'] == 25))
- {
- if ($socket = fsockopen($modSettings['smtp_host'], 465, $errno, $errstr, 3))
- log_error($txt['smtp_port_ssl']);
- }
-
- if (!$socket)
- {
- log_error($txt['smtp_no_connect'] . ': ' . $errno . ' : ' . $errstr);
- return false;
- }
- }
-
- if (!server_parse(null, $socket, '220'))
- return false;
- if ($modSettings['mail_type'] == 1 && $modSettings['smtp_username'] != '' && $modSettings['smtp_password'] != '')
- {
-
-
- if (server_parse('EHLO ' . $modSettings['smtp_host'], $socket, null) == '250')
- {
- if (!server_parse('AUTH LOGIN', $socket, '334'))
- return false;
-
- if (!server_parse(base64_encode($modSettings['smtp_username']), $socket, '334'))
- return false;
-
- if (!server_parse($modSettings['smtp_password'], $socket, '235'))
- return false;
- }
- elseif (!server_parse('HELO ' . $modSettings['smtp_host'], $socket, '250'))
- return false;
- }
- else
- {
-
- if (!server_parse('HELO ' . $modSettings['smtp_host'], $socket, '250'))
- return false;
- }
-
- $message = strtr($message, array("\r\n" . '.' => "\r\n" . '..'));
-
- $mail_to_array = array_values($mail_to_array);
- foreach ($mail_to_array as $i => $mail_to)
- {
-
- if ($i != 0)
- {
- if (!server_parse('RSET', $socket, '250'))
- return false;
- }
-
- if (!server_parse('MAIL FROM: <' . (empty($modSettings['mail_from']) ? $webmaster_email : $modSettings['mail_from']) . '>', $socket, '250'))
- return false;
- if (!server_parse('RCPT TO: <' . $mail_to . '>', $socket, '250'))
- return false;
- if (!server_parse('DATA', $socket, '354'))
- return false;
- fputs($socket, 'Subject: ' . $subject . "\r\n");
- if (strlen($mail_to) > 0)
- fputs($socket, 'To: <' . $mail_to . '>' . "\r\n");
- fputs($socket, $headers . "\r\n\r\n");
- fputs($socket, $message . "\r\n");
-
- if (!server_parse('.', $socket, '250'))
- return false;
-
- @set_time_limit(300);
- if (function_exists('apache_reset_timeout'))
- @apache_reset_timeout();
- }
- fputs($socket, 'QUIT' . "\r\n");
- fclose($socket);
- return true;
- }
- function server_parse($message, $socket, $response)
- {
- global $txt;
- if ($message !== null)
- fputs($socket, $message . "\r\n");
-
- $server_response = '';
- while (substr($server_response, 3, 1) != ' ')
- if (!($server_response = fgets($socket, 256)))
- {
-
- log_error($txt['smtp_bad_response']);
- return false;
- }
- if ($response === null)
- return substr($server_response, 0, 3);
- if (substr($server_response, 0, 3) != $response)
- {
- log_error($txt['smtp_error'] . $server_response);
- return false;
- }
- return true;
- }
- function SpellCheck()
- {
- global $txt, $context, $smcFunc;
-
- $known_words = array('smf', 'php', 'mysql', 'www', 'gif', 'jpeg', 'png', 'http', 'smfisawesome', 'grandia', 'terranigma', 'rpgs');
- loadLanguage('Post');
- loadTemplate('Post');
-
- ob_start();
- $old = error_reporting(0);
-
- pspell_new('en');
-
- $pspell_link = pspell_new($txt['lang_dictionary'], $txt['lang_spelling'], '', strtr($context['character_set'], array('iso-' => 'iso', 'ISO-' => 'iso')), PSPELL_FAST | PSPELL_RUN_TOGETHER);
-
- if (!$pspell_link)
- $pspell_link = pspell_new('en', '', '', '', PSPELL_FAST | PSPELL_RUN_TOGETHER);
- error_reporting($old);
- ob_end_clean();
- if (!isset($_POST['spellstring']) || !$pspell_link)
- die;
-
- $context['spell_js'] = '
- var txt = {"done": "' . $txt['spellcheck_done'] . '"};
- var mispstr = window.opener.document.forms[spell_formname][spell_fieldname].value;
- var misps = Array(';
-
- $alphas = explode("\n", strtr($_POST['spellstring'], array("\r" => '')));
- $found_words = false;
- for ($i = 0, $n = count($alphas); $i < $n; $i++)
- {
-
- $check_word = explode('|', $alphas[$i]);
-
- if (in_array($smcFunc['strtolower']($check_word[0]), $known_words) || pspell_check($pspell_link, $check_word[0]) || !isset($check_word[2]))
- continue;
-
- $found_words = true;
-
- $context['spell_js'] .= '
- new misp("' . strtr($check_word[0], array('\\' => '\\\\', '"' => '\\"', '<' => '', '>' => '')) . '", ' . (int) $check_word[1] . ', ' . (int) $check_word[2] . ', [';
-
- $suggestions = pspell_suggest($pspell_link, $check_word[0]);
- if (!empty($suggestions))
- {
-
- foreach ($suggestions as $k => $word)
- if ($suggestions[$k] != censorText($word))
- unset($suggestions[$k]);
- if (!empty($suggestions))
- $context['spell_js'] .= '"' . implode('", "', $suggestions) . '"';
- }
- $context['spell_js'] .= ']),';
- }
-
- if ($found_words)
- $context['spell_js'] = substr($context['spell_js'], 0, -1);
- $context['spell_js'] .= '
- );';
-
- $context['template_layers'] = array();
- $context['sub_template'] = 'spellcheck';
- }
- function sendNotifications($topics, $type, $exclude = array(), $members_only = array())
- {
- global $txt, $scripturl, $language, $user_info;
- global $modSettings, $sourcedir, $context, $smcFunc;
-
- if (empty($topics))
- return;
-
- if (!is_array($topics))
- $topics = array($topics);
-
- $result = $smcFunc['db_query']('', '
- SELECT mf.subject, ml.body, ml.id_member, t.id_last_msg, t.id_topic,
- IFNULL(mem.real_name, ml.poster_name) AS poster_name
- FROM {db_prefix}topics AS t
- INNER JOIN {db_prefix}messages AS mf ON (mf.id_msg = t.id_first_msg)
- INNER JOIN {db_prefix}messages AS ml ON (ml.id_msg = t.id_last_msg)
- LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = ml.id_member)
- WHERE t.id_topic IN ({array_int:topic_list})
- LIMIT 1',
- array(
- 'topic_list' => $topics,
- )
- );
- $topicData = array();
- while ($row = $smcFunc['db_fetch_assoc']($result))
- {
-
- censorText($row['subject']);
- censorText($row['body']);
- $row['subject'] = un_htmlspecialchars($row['subject']);
- $row['body'] = trim(un_htmlspecialchars(strip_tags(strtr(parse_bbc($row['body'], false, $row['id_last_msg']), array('<br />' => "\n", '</div>' => "\n", '</li>' => "\n", '[' => '[', ']' => ']')))));
- $topicData[$row['id_topic']] = array(
- 'subject' => $row['subject'],
- 'body' => $row['body'],
- 'last_id' => $row['id_last_msg'],
- 'topic' => $row['id_topic'],
- 'name' => $user_info['name'],
- 'exclude' => '',
- );
- }
- $smcFunc['db_free_result']($result);
-
- foreach ($topics as $key => $id)
- if (isset($topicData[$id]) && !empty($exclude[$key]))
- $topicData[$id]['exclude'] = (int) $exclude[$key];
-
- if (empty($topicData))
- trigger_error('sendNotifications(): topics not found', E_USER_NOTICE);
- $topics = array_keys($topicData);
-
- if (empty($topics))
- return;
-
- $digest_insert = array();
- foreach ($topicData as $id => $data)
- $digest_insert[] = array($data['topic'], $data['last_id'], $type, (int) $data['exclude']);
- $smcFunc['db_insert']('',
- '{db_prefix}log_digest',
- array(
- 'id_topic' => 'int', 'id_msg' => 'int', 'note_type' => 'string', 'exclude' => 'int',
- ),
- $digest_insert,
- array()
- );
-
- $members = $smcFunc['db_query']('', '
- SELECT
- mem.id_member, mem.email_address, mem.notify_regularity, mem.notify_types, mem.notify_send_body, mem.lngfile,
- ln.sent, mem.id_group, mem.additional_groups, b.member_groups, mem.id_post_group, t.id_member_started,
- ln.id_topic
- FROM {db_prefix}log_notify AS ln
- INNER JOIN {db_prefix}members AS mem ON (mem.id_member = ln.id_member)
- INNER JOIN {db_prefix}topics AS t ON (t.id_topic = ln.id_topic)
- INNER JOIN {db_prefix}boards AS b ON (b.id_board = t.id_board)
- WHERE ln.id_topic IN ({array_int:topic_list})
- AND mem.notify_types < {int:notify_types}
- AND mem.notify_regularity < {int:notify_regularity}
- AND mem.is_activated = {int:is_activated}
- AND ln.id_member != {int:current_member}' .
- (empty($members_only) ? '' : ' AND ln.id_member IN ({array_int:members_only})') . '
- ORDER BY mem.lngfile',
- array(
- 'current_member' => $user_info['id'],
- 'topic_list' => $topics,
- 'notify_types' => $type == 'reply' ? '4' : '3',
- 'notify_regularity' => 2,
- 'is_activated' => 1,
- 'members_only' => is_array($members_only) ? $members_only : array($members_only),
- )
- );
- $sent = 0;
- $current_language = '';
- while ($row = $smcFunc['db_fetch_assoc']($members))
- {
-
- if ($topicData[$row['id_topic']]['exclude'] == $row['id_member'])
- continue;
-
- if ($type != 'reply' && $row['notify_types'] == 2 && $row['id_member'] != $row['id_member_started'])
- continue;
- if ($row['id_group'] != 1)
- {
- $allowed = explode(',', $row['member_groups']);
- $row['additional_groups'] = explode(',', $row['additional_groups']);
- $row['additional_groups'][] = $row['id_group'];
- $row['additional_groups'][] = $row['id_post_group'];
- if (count(array_intersect($allowed, $row['additional_groups'])) == 0)
- continue;
- }
- $needed_language = empty($row['lngfile']) || empty($modSettings['userLanguage']) ? $language : $row['lngfile'];
- if (empty($current_language) || $current_language != $needed_language)
- $current_language = loadLanguage('Post', $needed_language, false);
- $message_type = 'notification_' . $type;
- $replacements = array(
- 'TOPICSUBJECT' => $topicData[$row['id_topic']]['subject'],
- 'POSTERNAME' => un_htmlspecialchars($topicData[$row['id_topic']]['name']),
- 'TOPICLINK' => $scripturl . '?topic=' . $row['id_topic'] . '.new;topicseen#new',
- 'UNSUBSCRIBELINK' => $scripturl . '?action=notify;topic=' . $row['id_topic'] . '.0',
- );
- if ($type == 'remove')
- unset($replacements['TOPICLINK'], $replacements['UNSUBSCRIBELINK']);
-
- if (!empty($row['notify_send_body']) && $type == 'reply' && empty($modSettings['disallow_sendBody']))
- {
- $message_type .= '_body';
- $replacements['MESSAGE'] = $topicData[$row['id_topic']]['body'];
- }
- if (!empty($row['notify_regularity']) && $type == 'reply')
- $message_type .= '_once';
-
- if ($type != 'reply' || empty($row['notify_regularity']) || empty($row['sent']))
- {
- $emaildata = loadEmailTemplate($message_type, $replacements, $needed_language);
- sendmail($row['email_address'], $emaildata['subject'], $emaildata['body'], null, 'm' . $topicData[$row['id_topic']]['last_id']);
- $sent++;
- }
- }
- $smcFunc['db_free_result']($members);
- if (isset($current_language) && $current_language != $user_info['language'])
- loadLanguage('Post');
-
- if ($type == 'reply' && !empty($sent))
- $smcFunc['db_query']('', '
- UPDATE {db_prefix}log_notify
- SET sent = {int:is_sent}
- WHERE id_topic IN ({array_int:topic_list})
- AND id_member != {int:current_member}',
- array(
- 'current_member' => $user_info['id'],
- 'topic_list' => $topics,
- 'is_sent' => 1,
- )
- );
-
- if (!empty($sent) && !empty($exclude))
- {
- foreach ($topicData as $id => $data)
- if ($data['exclude'])
- $smcFunc['db_query']('', '
- UPDATE {db_prefix}log_notify
- SET sent = {int:not_sent}
- WHERE id_topic = {int:id_topic}
- AND id_member = {int:id_member}',
- array(
- 'not_sent' => 0,
- 'id_topic' => $id,
- 'id_member' => $data['exclude'],
- )
- );
- }
- }
- function createPost(&$msgOptions, &$topicOptions, &$posterOptions)
- {
- global $user_info, $txt, $modSettings, $smcFunc, $context;
-
- $msgOptions['icon'] = empty($msgOptions['icon']) ? 'xx' : $msgOptions['icon'];
- $msgOptions['smileys_enabled'] = !empty($msgOptions['smileys_enabled']);
- $msgOptions['attachments'] = empty($msgOptions['attachments']) ? array() : $msgOptions['attachments'];
- $msgOptions['approved'] = isset($msgOptions['approved']) ? (int) $msgOptions['approved'] : 1;
- $topicOptions['id'] = empty($topicOptions['id']) ? 0 : (int) $topicOptions['id'];
- $topicOptions['poll'] = isset($topicOptions['poll']) ? (int) $topicOptions['poll'] : null;
- $topicOptions['lock_mode'] = isset($topicOptions['lock_mode']) ? $topicOptions['lock_mode'] : null;
- $topicOptions['sticky_mode'] = isset($topicOptions['sticky_mode']) ? $topicOptions['sticky_mode'] : null;
- $posterOptions['id'] = empty($posterOptions['id']) ? 0 : (int) $posterOptions['id'];
- $posterOptions['ip'] = empty($posterOptions['ip']) ? $user_info['ip'] : $posterOptions['ip'];
-
- if (!$modSettings['postmod_active'])
- $topicOptions['is_approved'] = true;
- elseif (!empty($topicOptions['id']) && !isset($topicOptions['is_approved']))
- {
- $request = $smcFunc['db_query']('', '
- SELECT approved
- FROM {db_prefix}topics
- WHERE id_topic = {int:id_topic}
- LIMIT 1',
- array(
- 'id_topic' => $topicOptions['id'],
- )
- );
- list ($topicOptions['is_approved']) = $smcFunc['db_fetch_row']($request);
- $smcFunc['db_free_result']($request);
- }
-
- if (!isset($posterOptions['name']) || $posterOptions['name'] == '' || (empty($posterOptions['email']) && !empty($posterOptions['id'])))
- {
- if (empty($posterOptions['id']))
- {
- $posterOptions['id'] = 0;
- $posterOptions['name'] = $txt['guest_title'];
- $posterOptions['email'] = '';
- }
- elseif ($posterOptions['id'] != $user_info['id'])
- {
- $request = $smcFunc['db_query']('', '
- SELECT member_name, email_address
- FROM {db_prefix}members
- WHERE id_member = {int:id_member}
- LIMIT 1',
- array(
- 'id_member' => $posterOptions['id'],
- )
- );
-
- if ($smcFunc['db_num_rows']($request) == 0)
- {
- trigger_error('createPost(): Invalid member id ' . $posterOptions['id'], E_USER_NOTICE);
- $posterOptions['id'] = 0;
- $posterOptions['name'] = $txt['guest_title'];
- $posterOptions['email'] = '';
- }
- else
- list ($posterOptions['name'], $posterOptions['email']) = $smcFunc['db_fetch_row']($request);
- $smcFunc['db_free_result']($request);
- }
- else
- {
- $posterOptions['name'] = $user_info['name'];
- $posterOptions['email'] = $user_info['email'];
- }
- }
-
- $previous_ignore_user_abort = ignore_user_abort(true);
- $new_topic = empty($topicOptions['id']);
-
- $smcFunc['db_insert']('',
- '{db_prefix}messages',
- array(
- 'id_board' => 'int', 'id_topic' => 'int', 'id_member' => 'int', 'subject' => 'string-255', 'body' => (!empty($modSettings['max_messageLength']) && $modSettings['max_messageLength'] > 65534 ? 'string-' . $modSettings['max_messageLength'] : 'string-65534'),
- 'poster_name' => 'string-255', 'poster_email' => 'string-255', 'poster_time' => 'int', 'poster_ip' => 'string-255',
- 'smileys_enabled' => 'int', 'modified_name' => 'string', 'icon' => 'string-16', 'approved' => 'int',
- ),
- array(
- $topicOptions['board'], $topicOptions['id'], $posterOptions['id'], $msgOptions['subject'], $msgOptions['body'],
- $posterOptions['name'], $posterOptions['email'], time(), $posterOptions['ip'],
- $msgOptions['smileys_enabled'] ? 1 : 0, '', $msgOptions['icon'], $msgOptions['approved'],
- ),
- array('id_msg')
- );
- $msgOptions['id'] = $smcFunc['db_insert_id']('{db_prefix}messages', 'id_msg');
-
- if (empty($msgOptions['id']))
- return false;
-
- if (!empty($msgOptions['attachments']))
- $smcFunc['db_query']('', '
- UPDATE {db_prefix}attachments
- SET id_msg = {int:id_msg}
- WHERE id_attach IN ({array_int:attachment_list})',
- array(
- 'attachment_list' => $msgOptions['attachments'],
- 'id_msg' => $msgOptions['id'],
- )
- );
-
- if ($new_topic)
- {
- $smcFunc['db_insert']('',
- '{db_prefix}topics',
- array(
- 'id_board' => 'int', 'id_member_started' => 'int', 'id_member_updated' => 'int', 'id_first_msg' => 'int',
- 'id_last_msg' => 'int', 'locked' => 'int', 'is_sticky' => 'int', 'num_views' => 'int',
- 'id_poll' => 'int', 'unapproved_posts' => 'int', 'approved' => 'int',
- ),
- array(
- $topicOptions['board'], $posterOptions['id'], $posterOptions['id'], $msgOptions['id'],
- $msgOptions['id'], $topicOptions['lock_mode'] === null ? 0 : $topicOptions['lock_mode'], $topicOptions['sticky_mode'] === null ? 0 : $topicOptions['sticky_mode'], 0,
- $topicOptions['poll'] === null ? 0 : $topicOptions['poll'], $msgOptions['approved'] ? 0 : 1, $msgOptions['approved'],
- ),
- array('id_topic')
- );
- $topicOptions['id'] = $smcFunc['db_insert_id']('{db_prefix}topics', 'id_topic');
-
- if (empty($topicOptions['id']))
- {
-
- $smcFunc['db_query']('', '
- DELETE FROM {db_prefix}messages
- WHERE id_msg = {int:id_msg}',
- array(
- 'id_msg' => $msgOptions['id'],
- )
- );
- return false;
- }
-
- $smcFunc['db_query']('', '
- UPDATE {db_prefix}messages
- SET id_topic = {int:id_topic}
- WHERE id_msg = {int:id_msg}',
- array(
- 'id_topic' => $topicOptions['id'],
- 'id_msg' => $msgOptions['id'],
- )
- );
-
- trackStats(array('topics' => '+', 'posts' => '+'));
- updateStats('topic', true);
- updateStats('subject', $topicOptions['id'], $msgOptions['subject']);
-
- call_integration_hook('integrate_create_topic', array($msgOptions, $topicOptions, $posterOptions));
- }
-
- else
- {
- $countChange = $msgOptions['approved'] ? 'num_replies = num_replies + 1' : 'unapproved_posts = unapproved_posts + 1';
-
- $smcFunc['db_query']('', '
- UPDATE {db_prefix}topics
- SET
- ' . ($msgOptions['approved'] ? 'id_member_updated = {int:poster_id}, id_last_msg = {int:id_msg},' : '') . '
- ' . $countChange . ($topicOptions['lock_mode'] === null ? '' : ',
- locked = {int:locked}') . ($topicOptions['sticky_mode'] === null ? '' : ',
- is_sticky = {int:is_sticky}') . '
- WHERE id_topic = {int:id_topic}',
- array(
- 'poster_id' => $posterOptions['id'],
- 'id_msg' => $msgOptions['id'],
- 'locked' => $topicOptions['lock_mode'],
- 'is_sticky' => $topicOptions['sticky_mode'],
- 'id_topic' => $topicOptions['id'],
- )
- );
-
- trackStats(array('posts' => '+'));
- }
-
-
- $smcFunc['db_query']('', '
- UPDATE {db_prefix}messages
- SET id_msg_modified = {int:id_msg}
- WHERE id_msg = {int:id_msg}',
- array(
- 'id_msg' => $msgOptions['id'],
- )
- );
-
- if ($msgOptions['approved'])
- $smcFunc['db_query']('', '
- UPDATE {db_prefix}boards
- SET num_posts = num_posts + 1' . ($new_topic ? ', num_topics = num_topics + 1' : '') . '
- WHERE id_board = {int:id_board}',
- array(
- 'id_board' => $topicOptions['board'],
- )
- );
- else
- {
- $smcFunc['db_query']('', '
- UPDATE {db_prefix}boards
- SET unapproved_posts = unapproved_posts + 1' . ($new_topic ? ', unapproved_topics = unapproved_topics + 1' : '') . '
- WHERE id_board = {int:id_board}',
- array(
- 'id_board' => $topicOptions['board'],
- )
- );
-
- $smcFunc['db_insert']('',
- '{db_prefix}approval_queue',
- array(
- 'id_msg' => 'int',
- ),
- array(
- $msgOptions['id'],
- ),
- array()
- );
- }
-
- if (!empty($topicOptions['mark_as_read']) && !$user_info['is_guest'])
- {
-
- if (!$new_topic)
- {
- $smcFunc['db_query']('', '
- UPDATE {db_prefix}log_topics
- SET id_msg = {int:id_msg}
- WHERE id_member = {int:current_member}
- AND id_topic = {int:id_topic}',
- array(
- 'current_member' => $posterOptions['id'],
- 'id_msg' => $msgOptions['id'],
- 'id_topic' => $topicOptions['id'],
- )
- );
- $flag = $smcFunc['db_affected_rows']() != 0;
- }
- if (empty($flag))
- {
- $smcFunc['db_insert']('ignore',
- '{db_prefix}log_topics',
- array('id_topic' => 'int', 'id_member' => 'int', 'id_msg' => 'int'),
- array($topicOptions['id'], $posterOptions['id'], $msgOptions['id']),
- array('id_topic', 'id_member')
- );
- }
- }
-
- if (!empty($modSettings['search_custom_index_config']))
- {
- $customIndexSettings = unserialize($modSettings['search_custom_index_config']);
- $inserts = array();
- foreach (text2words($msgOptions['body'], $customIndexSettings['bytes_per_word'], true) as $word)
- $inserts[] = array($word, $msgOptions['id']);
- if (!empty($inserts))
- $smcFunc['db_insert']('ignore',
- '{db_prefix}log_search_words',
- array('id_word' => 'int', 'id_msg' => 'int'),
- $inserts,
- array('id_word', 'id_msg')
- );
- }
-
- if (!empty($posterOptions['update_post_count']) && !empty($posterOptions['id']) && $msgOptions['approved'])
- {
-
- if ($user_info['id'] == $posterOptions['id'])
- $user_info['posts']++;
- updateMemberData($posterOptions['id'], array('posts' => '+'));
- }
-
- $_SESSION['last_read_topic'] = 0;
-
- if (isset($_SESSION['topicseen_cache'][$topicOptions['board']]))
- $_SESSION['topicseen_cache'][$topicOptions['board']]--;
-
- updateStats('message', true, $msgOptions['id']);
-
- if ($msgOptions['approved'])
- updateLastMessages($topicOptions['board'], $new_topic || !empty($topicOptions['is_approved']) ? $msgOptions['id'] : 0);
-
- ignore_user_abort($previous_ignore_user_abort);
-
- return true;
- }
- function createAttachment(&$attachmentOptions)
- {
- global $modSettings, $sourcedir, $smcFunc, $context;
- require_once($sourcedir . '/Subs-Graphics.php');
-
- if (!empty($modSettings['currentAttachmentUploadDir']))
- {
- if (!is_array($modSettings['attachmentUploadDir']))
- $modSettings['attachmentUploadDir'] = unserialize($modSettings['attachmentUploadDir']);
-
- $attach_dir = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']];
- $id_folder = $modSettings['currentAttachmentUploadDir'];
- }
- else
- {
- $attach_dir = $modSettings['attachmentUploadDir'];
- $id_folder = 1;
- }
- $attachmentOptions['errors'] = array();
- if (!isset($attachmentOptions['post']))
- $attachmentOptions['post'] = 0;
- if (!isset($attachmentOptions['approved']))
- $attachmentOptions['approved'] = 1;
- $already_uploaded = preg_match('~^post_tmp_' . $attachmentOptions['poster'] . '_\d+$~', $attachmentOptions['tmp_name']) != 0;
- $file_restricted = ini_get('open_basedir') != '' && !$already_uploaded;
- if ($already_uploaded)
- $attachmentOptions['tmp_name'] = $attach_dir . '/' . $attachmentOptions['tmp_name'];
-
- if ((!$file_restricted && !file_exists($attachmentOptions['tmp_name'])) || (!$already_uploaded && !is_uploaded_file($attachmentOptions['tmp_name'])))
- {
- $attachmentOptions['errors'] = array('could_not_upload');
- return false;
- }
-
- $validImageTypes = array(
- 1 => 'gif',
- 2 => 'jpeg',
- 3 => 'png',
- 5 => 'psd',
- 6 => 'bmp',
- 7 => 'tiff',
- 8 => 'tiff',
- 9 => 'jpeg',
- 14 => 'iff'
- );
- if (!$file_restricted || $already_uploaded)
- {
- $size = @getimagesize($attachmentOptions['tmp_name']);
- list ($attachmentOptions['width'], $attachmentOptions['height']) = $size;
-
- if (empty($attachmentOptions['mime_type']) && $attachmentOptions['width'])
- {
-
- if (!empty($size['mime']))
- $attachmentOptions['mime_type'] = $size['mime'];
-
- elseif (isset($validImageTypes[$size[2]]))
- $attachmentOptions['mime_type'] = 'image/' . $validImageTypes[$size[2]];
- }
- }
-
- if (empty($attachmentOptions['file_hash']))
- $attachmentOptions['file_hash'] = getAttachmentFilename($attachmentOptions['name'], false, null, true);
-
- if (!empty($modSettings['attachmentSizeLimit']) && $attachmentOptions['size'] > $modSettings['attachmentSizeLimit'] * 1024)
- $attachmentOptions['errors'][] = 'too_large';
- if (!empty($modSettings['attachmentCheckExtensions']))
- {
- $allowed = explode(',', strtolower($modSettings['attachmentExtensions']));
- foreach ($allowed as $k => $dummy)
- $allowed[$k] = trim($dummy);
- if (!in_array(strtolower(substr(strrchr($attachmentOptions['name'], '.'), 1)), $allowed))
- $attachmentOptions['errors'][] = 'bad_extension';
- }
- if (!empty($modSettings['attachmentDirSizeLimit']))
- {
-
- $dirSize = 0;
- $dir = @opendir($attach_dir) or fatal_lang_error('cant_access_upload_path', 'critical');
- while ($file = readdir($dir))
- {
- if ($file == '.' || $file == '..')
- continue;
- if (preg_match('~^post_tmp_\d+_\d+$~', $file) != 0)
- {
-
- if (filemtime($attach_dir . '/' . $file) < time() - 18000)
- @unlink($attach_dir . '/' . $file);
- continue;
- }
- $dirSize += filesize($attach_dir . '/' . $file);
- }
- closedir($dir);
-
- if ($attachmentOptions['size'] + $dirSize > $modSettings['attachmentDirSizeLimit'] * 1024)
- $attachmentOptions['errors'][] = 'directory_full';
-
- elseif (!isset($modSettings['attachment_full_notified']) && $modSettings['attachmentDirSizeLimit'] > 4000 && $attachmentOptions['size'] + $dirSize > ($modSettings['attachmentDirSizeLimit'] - 2000) * 1024)
- {
- require_once($sourcedir . '/Subs-Admin.php');
- emailAdmins('admin_attachments_full');
- updateSettings(array('attachment_full_notified' => 1));
- }
- }
-
- if (empty($modSettings['attachmentEncryptFilenames']))
- {
-
- $disabledFiles = array('con', 'com1', 'com2', 'com3', 'com4', 'prn', 'aux', 'lpt1', '.htaccess', 'index.php');
- if (in_array(strtolower(basename($attachmentOptions['name'])), $disabledFiles))
- $attachmentOptions['errors'][] = 'bad_filename';
-
- $request = $smcFunc['db_query']('', '
- SELECT id_attach
- FROM {db_prefix}attachments
- WHERE filename = {string:filename}
- LIMIT 1',
- array(
- 'filename' => strtolower($attachmentOptions['name']),
- )
- );
- if ($smcFunc['db_num_rows']($request) > 0)
- $attachmentOptions['errors'][] = 'taken_filename';
- $smcFunc['db_free_result']($request);
- }
- if (!empty($attachmentOptions['errors']))
- return false;
- if (!is_writable($attach_dir))
- fatal_lang_error('attachments_no_write', 'critical');
-
- if (empty($attachmentOptions['fileext']))
- {
- $attachmentOptions['fileext'] = strtolower(strrpos($attachmentOptions['name'], '.') !== false ? substr($attachmentOptions['name'], strrpos($attachmentOptions['name'], '.') + 1) : '');
- if (strlen($attachmentOptions['fileext']) > 8 || '.' . $attachmentOptions['fileext'] == $attachmentOptions['name'])
- $attachmentOptions['fileext'] = '';
- }
- $smcFunc['db_insert']('',
- '{db_prefix}attachments',
- array(
- 'id_folder' => 'int', 'id_msg' => 'int', 'filename' => 'string-255', 'file_hash' => 'string-40', 'fileext' => 'string-8',
- 'size' => 'int', 'width' => 'int', 'height' => 'int',
- 'mime_type' => 'string-20', 'approved' => 'int',
- ),
- array(
- $id_folder, (int) $attachmentOptions['post'], $attachmentOptions['name'], $attachmentOptions['file_hash'], $attachmentOptions['fileext'],
- (int) $attachmentOptions['size'], (empty($attachmentOptions['width']) ? 0 : (int) $attachmentOptions['width']), (empty($attachmentOptions['height']) ? '0' : (int) $attachmentOptions['height']),
- (!empty($attachmentOptions['mime_type']) ? $attachmentOptions['mime_type'] : ''), (int) $attachmentOptions['approved'],
- ),
- array('id_attach')
- );
- $attachmentOptions['id'] = $smcFunc['db_insert_id']('{db_prefix}attachments', 'id_attach');
- if (empty($attachmentOptions['id']))
- return false;
-
- if (!$attachmentOptions['approved'])
- $smcFunc['db_insert']('',
- '{db_prefix}approval_queue',
- array(
- 'id_attach' => 'int', 'id_msg' => 'int',
- ),
- array(
- $attachmentOptions['id'], (int) $attachmentOptions['post'],
- ),
- array()
- );
- $attachmentOptions['destination'] = getAttachmentFilename(basename($attachmentOptions['name']), $attachmentOptions['id'], $id_folder, false, $attachmentOptions['file_hash']);
- if ($already_uploaded)
- rename($attachmentOptions['tmp_name'], $attachmentOptions['destination']);
- elseif (!move_uploaded_file($attachmentOptions['tmp_name'], $attachmentOptions['destination']))
- fatal_lang_error('attach_timeout', 'critical');
-
- @chmod($attachmentOptions['destination'], 0644);
- $size = @getimagesize($attachmentOptions['destination']);
- list ($attachmentOptions['width'], $attachmentOptions['height']) = empty($size) ? array(null, null, null) : $size;
-
- if ($file_restricted)
- {
-
- if (empty($attachmentOptions['mime_type']) && $attachmentOptions['width'])
- {
- if (!empty($size['mime']))
- $attachmentOptions['mime_type'] = $size['mime'];
- elseif (isset($validImageTypes[$size[2]]))
- $attachmentOptions['mime_type'] = 'image/' . $validImageTypes[$size[2]];
- }
- if (!empty($attachmentOptions['width']) && !empty($attachmentOptions['height']))
- $smcFunc['db_query']('', '
- UPDATE {db_prefix}attachments
- SET
- width = {int:width},
- height = {int:height},
- mime_type = {string:mime_type}
- WHERE id_attach = {int:id_attach}',
- array(
- 'width' => (int) $attachmentOptions['width'],
- 'height' => (int) $attachmentOptions['height'],
- 'id_attach' => $attachmentOptions['id'],
- 'mime_type' => empty($attachmentOptions['mime_type']) ? '' : $attachmentOptions['mime_type'],
- )
- );
- }
-
-
- if (isset($validImageTypes[$size[2]]))
- {
- if (!checkImageContents($attachmentOptions['destination'], !empty($modSettings['attachment_image_paranoid'])))
- {
-
- if (empty($modSettings['attachment_image_reencode']) || (!reencodeImage($attachmentOptions['destination'], $size[2])))
- {
-
- require_once($sourcedir . '/ManageAttachments.php');
- removeAttachments(array(
- 'id_attach' => $attachmentOptions['id']
- ));
- $attachmentOptions['id'] = null;
- $attachmentOptions['errors'][] = 'bad_attachment';
- return false;
- }
-
-
- $old_format = $size[2];
- $size = @getimagesize($attachmentOptions['destination']);
- if (!(empty($size)) && ($size[2] != $old_format))
- {
-
-
-
- if (isset($validImageTypes[$size[2]]))
- {
- $attachmentOptions['mime_type'] = 'image/' . $validImageTypes[$size[2]];
- $smcFunc['db_query']('', '
- UPDATE {db_prefix}attachments
- SET
- mime_type = {string:mime_type}
- WHERE id_attach = {int:id_attach}',
- array(
- 'id_attach' => $attachmentOptions['id'],
- 'mime_type' => $attachmentOptions['mime_type'],
- )
- );
- }
- }
- }
- }
- if (!empty($attachmentOptions['skip_thumbnail']) || (empty($attachmentOptions['width']) && empty($attachmentOptions['height'])))
- return true;
-
- if (!empty($modSettings['attachmentThumbnails']) && !empty($modSettings['attachmentThumbWidth']) && !empty($modSettings['attachmentThumbHeight']) && ($attachmentOptions['width'] > $modSettings['attachmentThumbWidth'] || $attachmentOptions['height'] > $modSettings['attachmentThumbHeight']))
- {
- if (createThumbnail($attachmentOptions['destination'], $modSettings['attachmentThumbWidth'], $modSettings['attachmentThumbHeight']))
- {
-
- $size = @getimagesize($attachmentOptions['destination'] . '_thumb');
- list ($thumb_width, $thumb_height) = $size;
- if (!empty($size['mime']))
- $thumb_mime = $size['mime'];
- elseif (isset($validImageTypes[$size[2]]))
- $thumb_mime = 'image/' . $validImageTypes[$size[2]];
-
- else
- $thumb_mime = '';
- $thumb_filename = $attachmentOptions['name'] . '_thumb';
- $thumb_size = filesize($attachmentOptions['destination'] . '_thumb');
- $thumb_file_hash = getAttachmentFilename($thumb_filename, false, null, true);
-
- $smcFunc['db_insert']('',
- '{db_prefix}attachments',
- array(
- 'id_folder' => 'int', 'id_msg' => 'int', 'attachment_type' => 'int', 'filename' => 'string-255', 'file_hash' => 'string-40', 'fileext' => 'string-8',
- 'size' => 'int', 'width' => 'int', 'height' => 'int', 'mime_type' => 'string-20', 'approved' => 'int',
- ),
- array(
- $id_folder, (int) $attachmentOptions['post'], 3, $thumb_filename, $thumb_file_hash, $attachmentOptions['fileext'],
- $thumb_size, $thumb_width, $thumb_height, $thumb_mime, (int) $attachmentOptions['approved'],
- ),
- array('id_attach')
- );
- $attachmentOptions['thumb'] = $smcFunc['db_insert_id']('{db_prefix}attachments', 'id_attach');
- if (!empty($attachmentOptions['thumb']))
- {
- $smcFunc['db_query']('', '
- UPDATE {db_prefix}attachments
- SET id_thumb = {int:id_thumb}
- WHERE id_attach = {int:id_attach}',
- array(
- 'id_thumb' => $attachmentOptions['thumb'],
- 'id_attach' => $attachmentOptions['id'],
- )
- );
- rename($attachmentOptions['destination'] . '_thumb', getAttachmentFilename($thumb_filename, $attachmentOptions['thumb'], $id_folder, false, $thumb_file_hash));
- }
- }
- }
- return true;
- }
- function modifyPost(&$msgOptions, &$topicOptions, &$posterOptions)
- {
- global $user_info, $modSettings, $smcFunc, $context;
- $topicOptions['poll'] = isset($topicOptions['poll']) ? (int) $topicOptions['poll'] : null;
- $topicOptions['lock_mode'] = isset($topicOptions['lock_mode']) ? $topicOptions['lock_mode'] : null;
- $topicOptions['sticky_mode'] = isset($topicOptions['sticky_mode']) ? $topicOptions['sticky_mode'] : null;
-
- $messages_columns = array();
- if (isset($posterOptions['name']))
- $messages_columns['poster_name'] = $posterOptions['name'];
- if (isset($posterOptions['email']))
- $messages_columns['poster_email'] = $posterOptions['email'];
- if (isset($msgOptions['icon']))
- $messages_columns['icon'] = $msgOptions['icon'];
- if (isset($msgOptions['subject']))
- $messages_columns['subject'] = $msgOptions['subject'];
- if (isset($msgOptions['body']))
- {
- $messages_columns['body'] = $msgOptions['body'];
-
-
- if (!empty($modSettings['search_custom_index_config']))
- {
- $request = $smcFunc['db_query']('', '
- SELECT body
- FROM {db_prefix}messages
- WHERE id_msg = {int:id_msg}',
- array(
- 'id_msg' => $msgOptions['id'],
- )
- );
- list ($msgOptions['old_body']) = $smcFunc['db_fetch_row']($request);
- $smcFunc['db_free_result']($request);
- }
- }
- if (!empty($msgOptions['modify_time']))
- {
- $messages_columns['modified_time'] = $msgOptions['modify_time'];
- $messages_columns['modified_name'] = $msgOptions['modify_name'];
- $messages_columns['id_msg_modified'] = $modSettings['maxMsgID'];
- }
- if (isset($msgOptions['smileys_enabled']))
- $messages_columns['smileys_enabled'] = empty($msgOptions['smileys_enabled']) ? 0 : 1;
-
- $messageInts = array('modified_time', 'id_msg_modified', 'smileys_enabled');
- $update_parameters = array(
- 'id_msg' => $msgOptions['id'],
- );
- foreach ($messages_columns as $var => $val)
- {
- $messages_columns[$var] = $var . ' = {' . (in_array($var, $messageInts) ? 'int' : 'string') . ':var_' . $var . '}';
- $update_parameters['var_' . $var] = $val;
- }
-
- if (empty($messages_columns))
- return true;
-
- $smcFunc['db_query']('', '
- UPDATE {db_prefix}messages
- SET ' . implode(', ', $messages_columns) . '
- WHERE id_msg = {int:id_msg}',
- $update_parameters
- );
-
- if ($topicOptions['sticky_mode'] !== null || $topicOptions['lock_mode'] !== null || $topicOptions['poll'] !== null)
- {
- $smcFunc['db_query']('', '
- UPDATE {db_prefix}topics
- SET
- is_sticky = {raw:is_sticky},
- locked = {raw:locked},
- id_poll = {raw:id_poll}
- WHERE id_topic = {int:id_topic}',
- array(
- 'is_sticky' => $topicOptions['sticky_mode'] === null ? 'is_sticky' : (int) $topicOptions['sticky_mode'],
- 'locked' => $topicOptions['lock_mode'] === null ? 'locked' : (int) $topicOptions['lock_mode'],
- 'id_poll' => $topicOptions['poll'] === null ? 'id_poll' : (int) $topicOptions['poll'],
- 'id_topic' => $topicOptions['id'],
- )
- );
- }
-
- if (!empty($topicOptions['mark_as_read']) && !$user_info['is_guest'])
- {
-
- $smcFunc['db_query']('', '
- UPDATE {db_prefix}log_topics
- SET id_msg = {int:id_msg}
- WHERE id_member = {int:current_member}
- AND id_topic = {int:id_topic}',
- array(
- 'current_member' => $user_info['id'],
- 'id_msg' => $modSettings['maxMsgID'],
- 'id_topic' => $topicOptions['id'],
- )
- );
- $flag = $smcFunc['db_affected_rows']() != 0;
- if (empty($flag))
- {
- $smcFunc['db_insert']('ignore',
- '{db_prefix}log_topics',
- array('id_topic' => 'int', 'id_member' => 'int', 'id_msg' => 'int'),
- array($topicOptions['id'], $user_info['id'], $modSettings['maxMsgID']),
- array('id_topic', 'id_member')
- );
- }
- }
-
- if (isset($msgOptions['body']) && !empty($modSettings['search_custom_index_config']))
- {
- $customIndexSettings = unserialize($modSettings['search_custom_index_config']);
- $stopwords = empty($modSettings['search_stopwords']) ? array() : explode(',', $modSettings['search_stopwords']);
- $old_body = isset($msgOptions['old_body']) ? $msgOptions['old_body'] : '';
- $old_index = text2words($old_body, $customIndexSettings['bytes_per_word'], true);
- $new_index = text2words($msgOptions['body'], $customIndexSettings['bytes_per_word'], true);
-
- $removed_words = array_diff(array_diff($old_index, $new_index), $stopwords);
- $inserted_words = array_diff(array_diff($new_index, $old_index), $stopwords);
-
-
- if (!empty($removed_words))
- {
- $removed_words = array_merge($removed_words, $inserted_words);
- $smcFunc['db_query']('', '
- DELETE FROM {db_prefix}log_search_words
- WHERE id_msg = {int:id_msg}
- AND id_word IN ({array_int:removed_words})',
- array(
- 'removed_words' => $removed_words,
- 'id_msg' => $msgOptions['id'],
- )
- );
- }
-
- if (!empty($inserted_words))
- {
- $inserts = array();
- foreach ($inserted_words as $word)
- $inserts[] = array($word, $msgOptions['id']);
- $smcFunc['db_insert']('insert',
- '{db_prefix}log_search_words',
- array('id_word' => 'string', 'id_msg' => 'int'),
- $inserts,
- array('id_word', 'id_msg')
- );
- }
- }
- if (isset($msgOptions['subject']))
- {
-
- $request = $smcFunc['db_query']('', '
- SELECT id_topic
- FROM {db_prefix}topics
- WHERE id_first_msg = {int:id_first_msg}
- LIMIT 1',
- array(
- 'id_first_msg' => $msgOptions['id'],
- )
- );
- if ($smcFunc['db_num_rows']($request) == 1)
- updateStats('subject', $topicOptions['id'], $msgOptions['subject']);
- $smcFunc['db_free_result']($request);
- }
-
- if ($modSettings['postmod_active'] && isset($msgOptions['approved']))
- approvePosts($msgOptions['id'], $msgOptions['approved']);
- return true;
- }
- function approvePosts($msgs, $approve = true)
- {
- global $sourcedir, $smcFunc;
- if (!is_array($msgs))
- $msgs = array($msgs);
- if (empty($msgs))
- return false;
-
- $request = $smcFunc['db_query']('', '
- SELECT m.id_msg, m.approved, m.id_topic, m.id_board, t.id_first_msg, t.id_last_msg,
- m.body, m.subject, IFNULL(mem.real_name, m.poster_name) AS poster_name, m.id_member,
- t.approved AS topic_approved, b.count_posts
- FROM {db_prefix}messages AS m
- INNER JOIN {db_prefix}topics AS t ON (t.id_topic = m.id_topic)
- INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board)
- LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member)
- WHERE m.id_msg IN ({array_int:message_list})
- AND m.approved = {int:approved_state}',
- array(
- 'message_list' => $msgs,
- 'approved_state' => $approve ? 0 : 1,
- )
- );
- $msgs = array();
- $topics = array();
- $topic_changes = array();
- $board_changes = array();
- $notification_topics = array();
- $notification_posts = array();
- $member_post_changes = array();
- while ($row = $smcFunc['db_fetch_assoc']($request))
- {
-
- $msgs[] = $row['id_msg'];
- $topics[] = $row['id_topic'];
-
- if (!isset($topic_changes[$row['id_topic']]))
- $topic_changes[$row['id_topic']] = array(
- 'id_last_msg' => $row['id_last_msg'],
- 'approved' => $row['topic_approved'],
- 'replies' => 0,
- 'unapproved_posts' => 0,
- );
- if (!isset($board_changes[$row['id_board']]))
- $board_changes[$row['id_board']] = array(
- 'posts' => 0,
- 'topics' => 0,
- 'unapproved_posts' => 0,
- 'unapproved_topics' => 0,
- );
-
- if ($row['id_msg'] == $row['id_first_msg'])
- {
- $topic_changes[$row['id_topic']]['approved'] = $approve ? 1 : 0;
- $board_changes[$row['id_board']]['unapproved_topics'] += $approve ? -1 : 1;
- $board_changes[$row['id_board']]['topics'] += $approve ? 1 : -1;
-
- $notification_topics[] = array(
- 'body' => $row['body'],
- 'subject' => $row['subject'],
- 'name' => $row['poster_name'],
- 'board' => $row['id_board'],
- 'topic' => $row['id_topic'],
- 'msg' => $row['id_first_msg'],
- 'poster' => $row['id_member'],
- );
- }
- else
- {
- $topic_changes[$row['id_topic']]['replies'] += $approve ? 1 : -1;
-
- if ($row['id_msg'] > $row['id_last_msg'])
- $notification_posts[$row['id_topic']][] = array(
- 'id' => $row['id_msg'],
- 'body' => $row['body'],
- 'subject' => $row['subject'],
- 'name' => $row['poster_name'],
- 'topic' => $row['id_topic'],
- );
- }
-
- if ($approve && $row['id_msg'] > $topic_changes[$row['id_topic']]['id_last_msg'])
- $topic_changes[$row['id_topic']]['id_last_msg'] = $row['id_msg'];
-
- elseif (!$approve)
-
- $topic_changes[$row['id_topic']]['id_last_msg'] = $row['id_first_msg'];
- $topic_changes[$row['id_topic']]['unapproved_posts'] += $approve ? -1 : 1;
- $board_changes[$row['id_board']]['unapproved_posts'] += $approve ? -1 : 1;
- $board_changes[$row['id_board']]['posts'] += $approve ? 1 : -1;
-
- if ($row['id_member'] && empty($row['count_posts']))
- $member_post_changes[$row['id_member']] = isset($member_post_changes[$row['id_member']]) ? $member_post_changes[$row['id_member']] + 1 : 1;
- }
- $smcFunc['db_free_result']($request);
- if (empty($msgs))
- return;
-
- $smcFunc['db_query']('', '
- UPDATE {db_prefix}messages
- SET approved = {int:approved_state}
- WHERE id_msg IN ({array_int:message_list})',
- array(
- 'message_list' => $msgs,
- 'approved_state' => $approve ? 1 : 0,
- )
- );
-
- if (!$approve)
- {
- $request = $smcFunc['db_query']('', '
- SELECT id_topic, MAX(id_msg) AS id_last_msg
- FROM {db_prefix}messages
- WHERE id_topic IN ({array_int:topic_list})
- AND approved = {int:approved}
- GROUP BY id_topic',
- array(
- 'topic_list' => $topics,
- 'approved' => 1,
- )
- );
- while ($row = $smcFunc['db_fetch_assoc']($request))
- $topic_changes[$row['id_topic']]['id_last_msg'] = $row['id_last_msg'];
- $smcFunc['db_free_result']($request);
- }
-
- foreach ($topic_changes as $id => $changes)
- $smcFunc['db_query']('', '
- UPDATE {db_prefix}topics
- SET approved = {int:approved}, unapproved_posts = unapproved_posts + {int:unapproved_posts},
- num_replies = num_replies + {int:num_replies}, id_last_msg = {int:id_last_msg}
- WHERE id_topic = {int:id_topic}',
- array(
- 'approved' => $changes['approved'],
- 'unapproved_posts' => $changes['unapproved_posts'],
- 'num_replies' => $changes['replies'],
- 'id_last_msg' => $changes['id_last_msg'],
- 'id_topic' => $id,
- )
- );
-
- foreach ($board_changes as $id => $changes)
- $smcFunc['db_query']('', '
- UPDATE {db_prefix}boards
- SET num_posts = num_posts + {int:num_posts}, unapproved_posts = unapproved_posts + {int:unapproved_posts},
- num_topics = num_topics + {int:num_topics}, unapproved_topics = unapproved_topics + {int:unapproved_topics}
- WHERE id_board = {int:id_board}',
- array(
- 'num_posts' => $changes['posts'],
- 'unapproved_posts' => $changes['unapproved_posts'],
- 'num_topics' => $changes['topics'],
- 'unapproved_topics' => $changes['unapproved_topics'],
- 'id_board' => $id,
- )
- );
-
- if ($approve)
- {
- if (!empty($notification_topics))
- {
- require_once($sourcedir . '/Post.php');
- notifyMembersBoard($notification_topics);
- }
- if (!empty($notification_posts))
- sendApprovalNotifications($notification_posts);
- $smcFunc['db_query']('', '
- DELETE FROM {db_prefix}approval_queue
- WHERE id_msg IN ({array_int:message_list})
- AND id_attach = {int:id_attach}',
- array(
- 'message_list' => $msgs,
- 'id_attach' => 0,
- )
- );
- }
-
- else
- {
- $msgInserts = array();
- foreach ($msgs as $msg)
- $msgInserts[] = array($msg);
- $smcFunc['db_insert']('ignore',
- '{db_prefix}approval_queue',
- array('id_msg' => 'int'),
- $msgInserts,
- array('id_msg')
- );
- }
-
- updateLastMessages(array_keys($board_changes));
-
- if (!empty($member_post_changes))
- foreach ($member_post_changes as $id_member => $count_change)
- updateMemberData($id_member, array('posts' => 'posts ' . ($approve ? '+' : '-') . ' ' . $count_change));
- return true;
- }
- function approveTopics($topics, $approve = true)
- {
- global $smcFunc;
- if (!is_array($topics))
- $topics = array($topics);
- if (empty($topics))
- return false;
- $approve_type = $approve ? 0 : 1;
-
- $request = $smcFunc['db_query']('', '
- SELECT id_msg
- FROM {db_prefix}messages
- WHERE id_topic IN ({array_int:topic_list})
- AND approved = {int:approve_type}',
- array(
- 'topic_list' => $topics,
- 'approve_type' => $approve_type,
- )
- );
- $msgs = array();
- while ($row = $smcFunc['db_fetch_assoc']($request))
- $msgs[] = $row['id_msg'];
- $smcFunc['db_free_result']($request);
- return approvePosts($msgs, $approve);
- }
- function sendApprovalNotifications(&$topicData)
- {
- global $txt, $scripturl, $language, $user_info;
- global $modSettings, $sourcedir, $context, $smcFunc;
-
- if (!is_array($topicData) || empty($topicData))
- return;
- $topics = array();
- $digest_insert = array();
- foreach ($topicData as $topic => $msgs)
- foreach ($msgs as $msgKey => $msg)
- {
- censorText($topicData[$topic][$msgKey]['subject']);
- censorText($topicData[$topic][$msgKey]['body']);
- $topicData[$topic][$msgKey]['subject'] = un_htmlspecialchars($topicData[$topic][$msgKey]['subject']);
- $topicData[$topic][$msgKey]['body'] = trim(un_htmlspecialchars(strip_tags(strtr(parse_bbc($topicData[$topic][$msgKey]['body'], false), array('<br />' => "\n", '</div>' => "\n", '</li>' => "\n", '[' => '[', ']' => ']')))));
- $topics[] = $msg['id'];
- $digest_insert[] = array($msg['topic'], $msg['id'], 'reply', $user_info['id']);
- }
-
- $smcFunc['db_insert']('',
- '{db_prefix}log_digest',
- array(
- 'id_topic' => 'int', 'id_msg' => 'int', 'note_type' => 'string', 'exclude' => 'int',
- ),
- $digest_insert,
- array()
- );
-
- $members = $smcFunc['db_query']('', '
- SELECT
- mem.id_member, mem.email_address, mem.notify_regularity, mem.notify_types, mem.notify_send_body, mem.lngfile,
- ln.sent, mem.id_group, mem.additional_groups, b.member_groups, mem.id_post_group, t.id_member_started,
- ln.id_topic
- FROM {db_prefix}log_notify AS ln
- INNER JOIN {db_prefix}members AS mem ON (mem.id_member = ln.id_member)
- INNER JOIN {db_prefix}topics AS t ON (t.id_topic = ln.id_topic)
- INNER JOIN {db_prefix}boards AS b ON (b.id_board = t.id_board)
- WHERE ln.id_topic IN ({array_int:topic_list})
- AND mem.is_activated = {int:is_activated}
- AND mem.notify_types < {int:notify_types}
- AND mem.notify_regularity < {int:notify_regularity}
- GROUP BY mem.id_member, ln.id_topic, mem.email_address, mem.notify_regularity, mem.notify_types, mem.notify_send_body, mem.lngfile, ln.sent, mem.id_group, mem.additional_groups, b.member_groups, mem.id_post_group, t.id_member_started
- ORDER BY mem.lngfile',
- array(
- 'topic_list' => $topics,
- 'is_activated' => 1,
- 'notify_types' => 4,
- 'notify_regularity' => 2,
- )
- );
- $sent = 0;
- $current_language = $user_info['language'];
- while ($row = $smcFunc['db_fetch_assoc']($members))
- {
- if ($row['id_group'] != 1)
- {
- $allowed = explode(',', $row['member_groups']);
- $row['additional_groups'] = explode(',', $row['additional_groups']);
- $row['additional_groups'][] = $row['id_group'];
- $row['additional_groups'][] = $row['id_post_group'];
- if (count(array_intersect($allowed, $row['additional_groups'])) == 0)
- continue;
- }
- $needed_language = empty($row['lngfile']) || empty($modSettings['userLanguage']) ? $language : $row['lngfile'];
- if (empty($current_language) || $current_language != $needed_language)
- $current_language = loadLanguage('Post', $needed_language, false);
- $sent_this_time = false;
-
- foreach ($topicData[$row['id_topic']] as $msg)
- {
- $replacements = array(
- 'TOPICSUBJECT' => $topicData[$row['id_topic']]['subject'],
- 'POSTERNAME' => un_htmlspecialchars($topicData[$row['id_topic']]['name']),
- 'TOPICLINK' => $scripturl . '?topic=' . $row['id_topic'] . '.new;topicseen#new',
- 'UNSUBSCRIBELINK' => $scripturl . '?action=notify;topic=' . $row['id_topic'] . '.0',
- );
- $message_type = 'notification_reply';
-
- if (!empty($row['notify_send_body']) && empty($modSettings['disallow_sendBody']))
- {
- $message_type .= '_body';
- $replacements['BODY'] = $topicData[$row['id_topic']]['body'];
- }
- if (!empty($row['notify_regularity']))
- $message_type .= '_once';
-
- if (empty($row['notify_regularity']) || (empty($row['sent']) && !$sent_this_time))
- {
- $emaildata = loadEmailTemplate($message_type, $replacements, $needed_language);
- sendmail($row['email_address'], $emaildata['subject'], $emaildata['body'], null, 'm' . $topicData[$row['id_topic']]['last_id']);
- $sent++;
- }
- $sent_this_time = true;
- }
- }
- $smcFunc['db_free_result']($members);
- if (isset($current_language) && $current_language != $user_info['language'])
- loadLanguage('Post');
-
- if (!empty($sent))
- $smcFunc['db_query']('', '
- UPDATE {db_prefix}log_notify
- SET sent = {int:is_sent}
- WHERE id_topic IN ({array_int:topic_list})
- AND id_member != {int:current_member}',
- array(
- 'current_member' => $user_info['id'],
- 'topic_list' => $topics,
- 'is_sent' => 1,
- )
- );
- }
- function updateLastMessages($setboards, $id_msg = 0)
- {
- global $board_info, $board, $modSettings, $smcFunc;
-
- if (empty($setboards))
- return false;
- if (!is_array($setboards))
- $setboards = array($setboards);
-
- if (!$id_msg)
- {
-
- $request = $smcFunc['db_query']('', '
- SELECT id_board, MAX(id_last_msg) AS id_msg
- FROM {db_prefix}topics
- WHERE id_board IN ({array_int:board_list})
- AND approved = {int:approved}
- GROUP BY id_board',
- array(
- 'board_list' => $setboards,
- 'approved' => 1,
- )
- );
- $lastMsg = array();
- while ($row = $smcFunc['db_fetch_assoc']($request))
- $lastMsg[$row['id_board']] = $row['id_msg'];
- $smcFunc['db_free_result']($request);
- }
- else
- {
-
- foreach ($setboards as $id_board)
- $lastMsg[$id_board] = $id_msg;
- }
- $parent_boards = array();
-
- $lastModified = $lastMsg;
-
- foreach ($setboards as $id_board)
- {
- if (!isset($lastMsg[$id_board]))
- {
- $lastMsg[$id_board] = 0;
- $lastModified[$id_board] = 0;
- }
- if (!empty($board) && $id_board == $board)
- $parents = $board_info['parent_boards'];
- else
- $parents = getBoardParents($id_board);
-
-
- foreach ($parents as $id => $parent)
- {
- if ($parent['level'] != 0)
- {
-
- if (isset($lastModified[$id]) && $lastModified[$id_board] > $lastModified[$id])
- $lastModified[$id] = $lastModified[$id_board];
- elseif (!isset($lastModified[$id]) && (!isset($parent_boards[$id]) || $parent_boards[$id] < $lastModified[$id_board]))
- $parent_boards[$id] = $lastModified[$id_board];
- }
- }
- }
-
-
- $board_updates = array();
- $parent_updates = array();
-
- foreach ($parent_boards as $id => $msg)
- {
- if (!isset($parent_updates[$msg]))
- $parent_updates[$msg] = array($id);
- else
- $parent_updates[$msg][] = $id;
- }
- foreach ($lastMsg as $id => $msg)
- {
- if (!isset($board_updates[$msg . '-' . $lastModified[$id]]))
- $board_updates[$msg . '-' . $lastModified[$id]] = array(
- 'id' => $msg,
- 'updated' => $lastModified[$id],
- 'boards' => array($id)
- );
- else
- $board_updates[$msg . '-' . $lastModified[$id]]['boards'][] = $id;
- }
-
- foreach ($parent_updates as $id_msg => $boards)
- {
- $smcFunc['db_query']('', '
- UPDATE {db_prefix}boards
- SET id_msg_updated = {int:id_msg_updated}
- WHERE id_board IN ({array_int:board_list})
- AND id_msg_updated < {int:id_msg_updated}',
- array(
- 'board_list' => $boards,
- 'id_msg_updated' => $id_msg,
- )
- );
- }
- foreach ($board_updates as $board_data)
- {
- $smcFunc['db_query']('', '
- UPDATE {db_prefix}boards
- SET id_last_msg = {int:id_last_msg}, id_msg_updated = {int:id_msg_updated}
- WHERE id_board IN ({array_int:board_list})',
- array(
- 'board_list' => $board_data['boards'],
- 'id_last_msg' => $board_data['id'],
- 'id_msg_updated' => $board_data['updated'],
- )
- );
- }
- }
- function adminNotify($type, $memberID, $member_name = null)
- {
- global $txt, $modSettings, $language, $scripturl, $user_info, $context, $smcFunc;
-
- if (empty($modSettings['notify_new_registration']))
- return;
- if ($member_name == null)
- {
-
- $request = $smcFunc['db_query']('', '
- SELECT real_name
- FROM {db_prefix}members
- WHERE id_member = {int:id_member}
- LIMIT 1',
- array(
- 'id_member' => $memberID,
- )
- );
- list ($member_name) = $smcFunc['db_fetch_row']($request);
- $smcFunc['db_free_result']($request);
- }
- $toNotify = array();
- $groups = array();
-
- $request = $smcFunc['db_query']('', '
- SELECT id_group
- FROM {db_prefix}permissions
- WHERE permission = {string:moderate_forum}
- AND add_deny = {int:add_deny}
- AND id_group != {int:id_group}',
- array(
- 'add_deny' => 1,
- 'id_group' => 0,
- 'moderate_forum' => 'moderate_forum',
- )
- );
- while ($row = $smcFunc['db_fetch_assoc']($request))
- $groups[] = $row['id_group'];
- $smcFunc['db_free_result']($request);
-
- $groups[] = 1;
- $groups = array_unique($groups);
-
- $request = $smcFunc['db_query']('', '
- SELECT id_member, lngfile, email_address
- FROM {db_prefix}members
- WHERE (id_group IN ({array_int:group_list}) OR FIND_IN_SET({raw:group_array_implode}, additional_groups) != 0)
- AND notify_types != {int:notify_types}
- ORDER BY lngfile',
- array(
- 'group_list' => $groups,
- 'notify_types' => 4,
- 'group_array_implode' => implode(', additional_groups) != 0 OR FIND_IN_SET(', $groups),
- )
- );
- $current_language = $user_info['language'];
- while ($row = $smcFunc['db_fetch_assoc']($request))
- {
- $replacements = array(
- 'USERNAME' => $member_name,
- 'PROFILELINK' => $scripturl . '?action=profile;u=' . $memberID
- );
- $emailtype = 'admin_notify';
-
- if ($type == 'approval')
- {
- $replacements['APPROVALLINK'] = $scripturl . '?action=admin;area=viewmembers;sa=browse;type=approve';
- $emailtype .= '_approval';
- }
- $emaildata = loadEmailTemplate($emailtype, $replacements, empty($row['lngfile']) || empty($modSettings['userLanguage']) ? $language : $row['lngfile']);
-
- sendmail($row['email_address'], $emaildata['subject'], $emaildata['body'], null, null, false, 0);
- }
- $smcFunc['db_free_result']($request);
- if (isset($current_language) && $current_language != $user_info['language'])
- loadLanguage('Login');
- }
- function loadEmailTemplate($template, $replacements = array(), $lang = '', $loadLang = true)
- {
- global $txt, $mbname, $scripturl, $settings, $user_info;
-
- if ($loadLang)
- loadLanguage('EmailTemplates', $lang);
- if (!isset($txt['emails'][$template]))
- fatal_lang_error('email_no_template', 'template', array($template));
- $ret = array(
- 'subject' => $txt['emails'][$template]['subject'],
- 'body' => $txt['emails'][$template]['body'],
- );
-
- $replacements += array(
- 'FORUMNAME' => $mbname,
- 'SCRIPTURL' => $scripturl,
- 'THEMEURL' => $settings['theme_url'],
- 'IMAGESURL' => $settings['images_url'],
- 'DEFAULT_THEMEURL' => $settings['default_theme_url'],
- 'REGARDS' => $txt['regards_team'],
- );
-
- $find = array();
- $replace = array();
- foreach ($replacements as $f => $r)
- {
- $find[] = '{' . $f . '}';
- $replace[] = $r;
- }
-
- $ret['subject'] = str_replace($find, $replace, $ret['subject']);
- $ret['body'] = str_replace($find, $replace, $ret['body']);
-
- $ret['subject'] = preg_replace_callback('~{USER.([^}]+)}~', 'user_info_callback', $ret['subject']);
- $ret['body'] = preg_replace_callback('~{USER.([^}]+)}~', 'user_info_callback', $ret['body']);
-
- return $ret;
- }
- function user_info_callback($matches)
- {
- global $user_info;
- if (empty($matches[1]))
- return '';
- $use_ref = true;
- $ref = &$user_info;
- foreach (explode('.', $matches[1]) as $index)
- {
- if ($use_ref && isset($ref[$index]))
- $ref = &$ref[$index];
- else
- {
- $use_ref = false;
- break;
- }
- }
- return $use_ref ? $ref : $matches[0];
- }
- ?>
|