1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390 |
- <?php
- if (!defined('SMF'))
- die('No direct access...');
- function updateStats($type, $parameter1 = null, $parameter2 = null)
- {
- global $sourcedir, $modSettings, $smcFunc;
- switch ($type)
- {
- case 'member':
- $changes = array(
- 'memberlist_updated' => time(),
- );
-
- if (is_numeric($parameter1))
- {
- $changes['latestMember'] = $parameter1;
- $changes['latestRealName'] = $parameter2;
- updateSettings(array('totalMembers' => true), true);
- }
-
- else
- {
-
- $result = $smcFunc['db_query']('', '
- SELECT COUNT(*), MAX(id_member)
- FROM {db_prefix}members
- WHERE is_activated = {int:is_activated}',
- array(
- 'is_activated' => 1,
- )
- );
- list ($changes['totalMembers'], $changes['latestMember']) = $smcFunc['db_fetch_row']($result);
- $smcFunc['db_free_result']($result);
-
- $result = $smcFunc['db_query']('', '
- SELECT real_name
- FROM {db_prefix}members
- WHERE id_member = {int:id_member}
- LIMIT 1',
- array(
- 'id_member' => (int) $changes['latestMember'],
- )
- );
- list ($changes['latestRealName']) = $smcFunc['db_fetch_row']($result);
- $smcFunc['db_free_result']($result);
-
- if ((!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 2) || !empty($modSettings['approveAccountDeletion']))
- {
-
- $result = $smcFunc['db_query']('', '
- SELECT COUNT(*)
- FROM {db_prefix}members
- WHERE is_activated IN ({array_int:activation_status})',
- array(
- 'activation_status' => array(3, 4),
- )
- );
- list ($changes['unapprovedMembers']) = $smcFunc['db_fetch_row']($result);
- $smcFunc['db_free_result']($result);
- }
- }
- updateSettings($changes);
- break;
- case 'message':
- if ($parameter1 === true && $parameter2 !== null)
- updateSettings(array('totalMessages' => true, 'maxMsgID' => $parameter2), true);
- else
- {
-
- $result = $smcFunc['db_query']('', '
- SELECT SUM(num_posts + unapproved_posts) AS total_messages, MAX(id_last_msg) AS max_msg_id
- FROM {db_prefix}boards
- WHERE redirect = {string:blank_redirect}' . (!empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0 ? '
- AND id_board != {int:recycle_board}' : ''),
- array(
- 'recycle_board' => isset($modSettings['recycle_board']) ? $modSettings['recycle_board'] : 0,
- 'blank_redirect' => '',
- )
- );
- $row = $smcFunc['db_fetch_assoc']($result);
- $smcFunc['db_free_result']($result);
- updateSettings(array(
- 'totalMessages' => $row['total_messages'] === null ? 0 : $row['total_messages'],
- 'maxMsgID' => $row['max_msg_id'] === null ? 0 : $row['max_msg_id']
- ));
- }
- break;
- case 'subject':
-
- $smcFunc['db_query']('', '
- DELETE FROM {db_prefix}log_search_subjects
- WHERE id_topic = {int:id_topic}',
- array(
- 'id_topic' => (int) $parameter1,
- )
- );
-
- if ($parameter2 !== null)
- {
- $parameter1 = (int) $parameter1;
- $parameter2 = text2words($parameter2);
- $inserts = array();
- foreach ($parameter2 as $word)
- $inserts[] = array($word, $parameter1);
- if (!empty($inserts))
- $smcFunc['db_insert']('ignore',
- '{db_prefix}log_search_subjects',
- array('word' => 'string', 'id_topic' => 'int'),
- $inserts,
- array('word', 'id_topic')
- );
- }
- break;
- case 'topic':
- if ($parameter1 === true)
- updateSettings(array('totalTopics' => true), true);
- else
- {
-
-
- $result = $smcFunc['db_query']('', '
- SELECT SUM(num_topics + unapproved_topics) AS total_topics
- FROM {db_prefix}boards' . (!empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0 ? '
- WHERE id_board != {int:recycle_board}' : ''),
- array(
- 'recycle_board' => !empty($modSettings['recycle_board']) ? $modSettings['recycle_board'] : 0,
- )
- );
- $row = $smcFunc['db_fetch_assoc']($result);
- $smcFunc['db_free_result']($result);
- updateSettings(array('totalTopics' => $row['total_topics'] === null ? 0 : $row['total_topics']));
- }
- break;
- case 'postgroups':
-
- if ($parameter2 !== null && !in_array('posts', $parameter2))
- return;
- $postgroups = cache_get_data('updateStats:postgroups', 360);
- if ($postgroups == null || $parameter1 == null)
- {
-
- $request = $smcFunc['db_query']('', '
- SELECT id_group, min_posts
- FROM {db_prefix}membergroups
- WHERE min_posts != {int:min_posts}',
- array(
- 'min_posts' => -1,
- )
- );
- $postgroups = array();
- while ($row = $smcFunc['db_fetch_assoc']($request))
- $postgroups[$row['id_group']] = $row['min_posts'];
- $smcFunc['db_free_result']($request);
-
- arsort($postgroups);
- cache_put_data('updateStats:postgroups', $postgroups, 360);
- }
-
- if (empty($postgroups))
- return;
-
- $conditions = '';
- $lastMin = 0;
- foreach ($postgroups as $id => $min_posts)
- {
- $conditions .= '
- WHEN posts >= ' . $min_posts . (!empty($lastMin) ? ' AND posts <= ' . $lastMin : '') . ' THEN ' . $id;
- $lastMin = $min_posts;
- }
-
- $smcFunc['db_query']('', '
- UPDATE {db_prefix}members
- SET id_post_group = CASE ' . $conditions . '
- ELSE 0
- END' . ($parameter1 != null ? '
- WHERE ' . (is_array($parameter1) ? 'id_member IN ({array_int:members})' : 'id_member = {int:members}') : ''),
- array(
- 'members' => $parameter1,
- )
- );
- break;
- default:
- trigger_error('updateStats(): Invalid statistic type \'' . $type . '\'', E_USER_NOTICE);
- }
- }
- function updateMemberData($members, $data)
- {
- global $modSettings, $user_info, $smcFunc;
- $parameters = array();
- if (is_array($members))
- {
- $condition = 'id_member IN ({array_int:members})';
- $parameters['members'] = $members;
- }
- elseif ($members === null)
- $condition = '1=1';
- else
- {
- $condition = 'id_member = {int:member}';
- $parameters['member'] = $members;
- }
-
- $knownInts = array(
- 'date_registered', 'posts', 'id_group', 'last_login', 'instant_messages', 'unread_messages',
- 'new_pm', 'pm_prefs', 'gender', 'hide_email', 'show_online', 'pm_email_notify', 'pm_receive_from', 'karma_good', 'karma_bad',
- 'notify_announcements', 'notify_send_body', 'notify_regularity', 'notify_types', 'alerts',
- 'id_theme', 'is_activated', 'id_msg_last_visit', 'id_post_group', 'total_time_logged_in', 'warning',
- );
- $knownFloats = array(
- 'time_offset',
- );
- if (!empty($modSettings['integrate_change_member_data']))
- {
-
- $integration_vars = array(
- 'member_name',
- 'real_name',
- 'email_address',
- 'id_group',
- 'gender',
- 'birthdate',
- 'website_title',
- 'website_url',
- 'location',
- 'hide_email',
- 'time_format',
- 'time_offset',
- 'avatar',
- 'lngfile',
- );
- $vars_to_integrate = array_intersect($integration_vars, array_keys($data));
-
- if (count($vars_to_integrate) != 0)
- {
-
- if ((!is_array($members) && $members === $user_info['id']) || (is_array($members) && count($members) == 1 && in_array($user_info['id'], $members)))
- $member_names = array($user_info['username']);
- else
- {
- $member_names = array();
- $request = $smcFunc['db_query']('', '
- SELECT member_name
- FROM {db_prefix}members
- WHERE ' . $condition,
- $parameters
- );
- while ($row = $smcFunc['db_fetch_assoc']($request))
- $member_names[] = $row['member_name'];
- $smcFunc['db_free_result']($request);
- }
- if (!empty($member_names))
- foreach ($vars_to_integrate as $var)
- call_integration_hook('integrate_change_member_data', array($member_names, $var, &$data[$var], &$knownInts, &$knownFloats));
- }
- }
- $setString = '';
- foreach ($data as $var => $val)
- {
- $type = 'string';
- if (in_array($var, $knownInts))
- $type = 'int';
- elseif (in_array($var, $knownFloats))
- $type = 'float';
- elseif ($var == 'birthdate')
- $type = 'date';
-
- if ($type == 'int' && ($val === '+' || $val === '-'))
- {
- $val = $var . ' ' . $val . ' 1';
- $type = 'raw';
- }
-
- if (in_array($var, array('posts', 'instant_messages', 'unread_messages')))
- {
- if (preg_match('~^' . $var . ' (\+ |- |\+ -)([\d]+)~', $val, $match))
- {
- if ($match[1] != '+ ')
- $val = 'CASE WHEN ' . $var . ' <= ' . abs($match[2]) . ' THEN 0 ELSE ' . $val . ' END';
- $type = 'raw';
- }
- }
- $setString .= ' ' . $var . ' = {' . $type . ':p_' . $var . '},';
- $parameters['p_' . $var] = $val;
- }
- $smcFunc['db_query']('', '
- UPDATE {db_prefix}members
- SET' . substr($setString, 0, -1) . '
- WHERE ' . $condition,
- $parameters
- );
- updateStats('postgroups', $members, array_keys($data));
-
- if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2 && !empty($members))
- {
- if (!is_array($members))
- $members = array($members);
- foreach ($members as $member)
- {
- if ($modSettings['cache_enable'] >= 3)
- {
- cache_put_data('member_data-profile-' . $member, null, 120);
- cache_put_data('member_data-normal-' . $member, null, 120);
- cache_put_data('member_data-minimal-' . $member, null, 120);
- }
- cache_put_data('user_settings-' . $member, null, 60);
- }
- }
- }
- function updateSettings($changeArray, $update = false)
- {
- global $modSettings, $smcFunc;
- if (empty($changeArray) || !is_array($changeArray))
- return;
-
- if ($update)
- {
- foreach ($changeArray as $variable => $value)
- {
- $smcFunc['db_query']('', '
- UPDATE {db_prefix}settings
- SET value = {' . ($value === false || $value === true ? 'raw' : 'string') . ':value}
- WHERE variable = {string:variable}',
- array(
- 'value' => $value === true ? 'value + 1' : ($value === false ? 'value - 1' : $value),
- 'variable' => $variable,
- )
- );
- $modSettings[$variable] = $value === true ? $modSettings[$variable] + 1 : ($value === false ? $modSettings[$variable] - 1 : $value);
- }
-
- cache_put_data('modSettings', null, 90);
- return;
- }
- $replaceArray = array();
- foreach ($changeArray as $variable => $value)
- {
-
- if (isset($modSettings[$variable]) && $modSettings[$variable] == $value)
- continue;
-
- elseif (!isset($modSettings[$variable]) && empty($value))
- continue;
- $replaceArray[] = array($variable, $value);
- $modSettings[$variable] = $value;
- }
- if (empty($replaceArray))
- return;
- $smcFunc['db_insert']('replace',
- '{db_prefix}settings',
- array('variable' => 'string-255', 'value' => 'string-65534'),
- $replaceArray,
- array('variable')
- );
-
- cache_put_data('modSettings', null, 90);
- }
- function constructPageIndex($base_url, &$start, $max_value, $num_per_page, $flexible_start = false, $show_prevnext = true)
- {
- global $modSettings, $context, $txt, $smcFunc;
-
- $start = (int) $start;
- $start_invalid = $start < 0;
-
- if ($start_invalid)
- $start = 0;
-
- elseif ($start >= $max_value)
- $start = max(0, (int) $max_value - (((int) $max_value % (int) $num_per_page) == 0 ? $num_per_page : ((int) $max_value % (int) $num_per_page)));
-
- else
- $start = max(0, (int) $start - ((int) $start % (int) $num_per_page));
- $context['current_page'] = $start / $num_per_page;
-
- if (WIRELESS)
- $base_url .= ';' . WIRELESS_PROTOCOL;
- $base_link = '<a class="navPages" href="' . ($flexible_start ? $base_url : strtr($base_url, array('%' => '%%')) . ';start=%1$d') . '">%2$s</a> ';
-
- if (empty($modSettings['compactTopicPagesEnable']))
- {
-
- $pageindex = $start == 0 ? ' ' : sprintf($base_link, $start - $num_per_page, '<span class="previous_page">' . $txt['prev'] . '</span>');
-
- $display_page = 1;
- for ($counter = 0; $counter < $max_value; $counter += $num_per_page)
- $pageindex .= $start == $counter && !$start_invalid ? '<span class="current_page"><strong>' . $display_page++ . '</strong></span> ' : sprintf($base_link, $counter, $display_page++);
-
- $display_page = ($start + $num_per_page) > $max_value ? $max_value : ($start + $num_per_page);
- if ($start != $counter - $max_value && !$start_invalid)
- $pageindex .= $display_page > $counter - $num_per_page ? ' ' : sprintf($base_link, $display_page, '<span class="next_page">' . $txt['next'] . '</span>');
- }
- else
- {
-
- $PageContiguous = (int) ($modSettings['compactTopicPagesContiguous'] - ($modSettings['compactTopicPagesContiguous'] % 2)) / 2;
-
- if (!empty($start) && $show_prevnext)
- $pageindex = sprintf($base_link, $start - $num_per_page, '<span class="previous_page">' . $txt['prev'] . '</span>');
- else
- $pageindex = '';
-
- if ($start > $num_per_page * $PageContiguous)
- $pageindex .= sprintf($base_link, 0, '1');
-
- if ($start > $num_per_page * ($PageContiguous + 1))
- $pageindex .= '<span class="expand_pages" onclick="' . $smcFunc['htmlspecialchars']('expandPages(this, ' . JavaScriptEscape(($flexible_start ? $base_url : strtr($base_url, array('%' => '%%')) . ';start=%1$d')) . ', ' . $num_per_page . ', ' . ($start - $num_per_page * $PageContiguous) . ', ' . $num_per_page . ');') . '"><strong> ... </strong></span>';
-
- for ($nCont = $PageContiguous; $nCont >= 1; $nCont--)
- if ($start >= $num_per_page * $nCont)
- {
- $tmpStart = $start - $num_per_page * $nCont;
- $pageindex.= sprintf($base_link, $tmpStart, $tmpStart / $num_per_page + 1);
- }
-
- if (!$start_invalid)
- $pageindex .= '<span class="current_page"><strong>' . ($start / $num_per_page + 1) . '</strong></span>';
- else
- $pageindex .= sprintf($base_link, $start, $start / $num_per_page + 1);
-
- $tmpMaxPages = (int) (($max_value - 1) / $num_per_page) * $num_per_page;
- for ($nCont = 1; $nCont <= $PageContiguous; $nCont++)
- if ($start + $num_per_page * $nCont <= $tmpMaxPages)
- {
- $tmpStart = $start + $num_per_page * $nCont;
- $pageindex .= sprintf($base_link, $tmpStart, $tmpStart / $num_per_page + 1);
- }
-
- if ($start + $num_per_page * ($PageContiguous + 1) < $tmpMaxPages)
- $pageindex .= '<span class="expand_pages" onclick="' . $smcFunc['htmlspecialchars']('expandPages(this, ' . JavaScriptEscape(($flexible_start ? $base_url : strtr($base_url, array('%' => '%%')) . ';start=%1$d')) . ', ' . ($start + $num_per_page * ($PageContiguous + 1)) . ', ' . $tmpMaxPages . ', ' . $num_per_page . ');') . '" onmouseover="this.style.cursor=\'pointer\';"> ... </span>';
-
- if ($start + $num_per_page * $PageContiguous < $tmpMaxPages)
- $pageindex .= sprintf($base_link, $tmpMaxPages, $tmpMaxPages / $num_per_page + 1);
-
- if ($start != $tmpMaxPages && $show_prevnext)
- $pageindex .= sprintf($base_link, $start + $num_per_page, '<span class="next_page">' . $txt['next'] . '</span>');
- }
- return $pageindex;
- }
- function comma_format($number, $override_decimal_count = false)
- {
- global $txt;
- static $thousands_separator = null, $decimal_separator = null, $decimal_count = null;
-
- if ($decimal_separator === null)
- {
-
- if (empty($txt['number_format']) || preg_match('~^1([^\d]*)?234([^\d]*)(0*?)$~', $txt['number_format'], $matches) != 1)
- return $number;
-
- $thousands_separator = $matches[1];
- $decimal_separator = $matches[2];
- $decimal_count = strlen($matches[3]);
- }
-
- return number_format($number, (float) $number === $number ? ($override_decimal_count === false ? $decimal_count : $override_decimal_count) : 0, $decimal_separator, $thousands_separator);
- }
- function timeformat($log_time, $show_today = true, $offset_type = false)
- {
- global $context, $user_info, $txt, $modSettings;
- static $non_twelve_hour;
-
- if (!$offset_type)
- $time = $log_time + ($user_info['time_offset'] + $modSettings['time_offset']) * 3600;
-
- elseif ($offset_type == 'forum')
- $time = $log_time + $modSettings['time_offset'] * 3600;
- else
- $time = $log_time;
-
- if ($log_time < 0)
- $log_time = 0;
-
- if ($modSettings['todayMod'] >= 1 && $show_today === true)
- {
-
- $nowtime = forum_time();
- $then = @getdate($time);
- $now = @getdate($nowtime);
-
- $s = strpos($user_info['time_format'], '%S') === false ? '' : ':%S';
- if (strpos($user_info['time_format'], '%H') === false && strpos($user_info['time_format'], '%T') === false)
- {
- $h = strpos($user_info['time_format'], '%l') === false ? '%I' : '%l';
- $today_fmt = $h . ':%M' . $s . ' %p';
- }
- else
- $today_fmt = '%H:%M' . $s;
-
- if ($then['yday'] == $now['yday'] && $then['year'] == $now['year'])
- return $txt['today'] . timeformat($log_time, $today_fmt, $offset_type);
-
- if ($modSettings['todayMod'] == '2' && (($then['yday'] == $now['yday'] - 1 && $then['year'] == $now['year']) || ($now['yday'] == 0 && $then['year'] == $now['year'] - 1) && $then['mon'] == 12 && $then['mday'] == 31))
- return $txt['yesterday'] . timeformat($log_time, $today_fmt, $offset_type);
- }
- $str = !is_bool($show_today) ? $show_today : $user_info['time_format'];
- if (setlocale(LC_TIME, $txt['lang_locale']))
- {
- if (!isset($non_twelve_hour))
- $non_twelve_hour = trim(strftime('%p')) === '';
- if ($non_twelve_hour && strpos($str, '%p') !== false)
- $str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str);
- foreach (array('%a', '%A', '%b', '%B') as $token)
- if (strpos($str, $token) !== false)
- $str = str_replace($token, strftime($token, $time), $str);
- }
- else
- {
-
- foreach (array('%a' => 'days_short', '%A' => 'days', '%b' => 'months_short', '%B' => 'months') as $token => $text_label)
- if (strpos($str, $token) !== false)
- $str = str_replace($token, $txt[$text_label][(int) strftime($token === '%a' || $token === '%A' ? '%w' : '%m', $time)], $str);
- if (strpos($str, '%p') !== false)
- $str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str);
- }
-
- if ($context['server']['is_windows'] && strpos($str, '%e') !== false)
- $str = str_replace('%e', ltrim(strftime('%d', $time), '0'), $str);
-
- return strftime($str, $time);
- }
- function un_htmlspecialchars($string)
- {
- static $translation = array();
- if (empty($translation))
- $translation = array_flip(get_html_translation_table(HTML_SPECIALCHARS, ENT_QUOTES)) + array(''' => '\'', ' ' => ' ');
- return strtr($string, $translation);
- }
- function shorten_subject($subject, $len)
- {
- global $smcFunc;
-
- if ($smcFunc['strlen']($subject) <= $len)
- return $subject;
-
- return $smcFunc['substr']($subject, 0, $len) . '...';
- }
- function forum_time($use_user_offset = true, $timestamp = null)
- {
- global $user_info, $modSettings;
- if ($timestamp === null)
- $timestamp = time();
- elseif ($timestamp == 0)
- return 0;
- return $timestamp + ($modSettings['time_offset'] + ($use_user_offset ? $user_info['time_offset'] : 0)) * 3600;
- }
- function permute($array)
- {
- $orders = array($array);
- $n = count($array);
- $p = range(0, $n);
- for ($i = 1; $i < $n; null)
- {
- $p[$i]--;
- $j = $i % 2 != 0 ? $p[$i] : 0;
- $temp = $array[$i];
- $array[$i] = $array[$j];
- $array[$j] = $temp;
- for ($i = 1; $p[$i] == 0; $i++)
- $p[$i] = 1;
- $orders[] = $array;
- }
- return $orders;
- }
- function parse_bbc($message, $smileys = true, $cache_id = '', $parse_tags = array())
- {
- global $txt, $scripturl, $context, $modSettings, $user_info;
- static $bbc_codes = array(), $itemcodes = array(), $no_autolink_tags = array();
- static $disabled;
-
- if ($message === '')
- return '';
-
- if (!isset($context['utf8']))
- $context['utf8'] = (empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set']) === 'UTF-8';
-
- $message = sanitizeMSCutPaste($message);
-
- if (!empty($context['load_average']) && !empty($modSettings['bbc']) && $context['load_average'] >= $modSettings['bbc'])
- {
- $context['disabled_parse_bbc'] = true;
- return $message;
- }
-
- if (WIRELESS)
- $smileys = false;
- elseif ($smileys !== null && ($smileys == '1' || $smileys == '0'))
- $smileys = (bool) $smileys;
- if (empty($modSettings['enableBBC']) && $message !== false)
- {
- if ($smileys === true)
- parsesmileys($message);
- return $message;
- }
-
- if (!empty($parse_tags) && !empty($bbc_codes))
- {
- $temp_bbc = $bbc_codes;
- $bbc_codes = array();
- }
-
- call_integration_hook('integrate_pre_parsebbc', array(&$message, &$smileys, &$cache_id, &$parse_tags));
-
- if (empty($bbc_codes) || $message === false || !empty($parse_tags))
- {
- if (!empty($modSettings['disabledBBC']))
- {
- $temp = explode(',', strtolower($modSettings['disabledBBC']));
- foreach ($temp as $tag)
- $disabled[trim($tag)] = true;
- }
- if (empty($modSettings['enableEmbeddedFlash']))
- $disabled['flash'] = true;
-
- $codes = array(
- array(
- 'tag' => 'abbr',
- 'type' => 'unparsed_equals',
- 'before' => '<abbr title="$1">',
- 'after' => '</abbr>',
- 'quoted' => 'optional',
- 'disabled_after' => ' ($1)',
- ),
- array(
- 'tag' => 'acronym',
- 'type' => 'unparsed_equals',
- 'before' => '<abbr title="$1">',
- 'after' => '</abbr>',
- 'quoted' => 'optional',
- 'disabled_after' => ' ($1)',
- ),
- array(
- 'tag' => 'anchor',
- 'type' => 'unparsed_equals',
- 'test' => '[#]?([A-Za-z][A-Za-z0-9_\-]*)\]',
- 'before' => '<span id="post_$1">',
- 'after' => '</span>',
- ),
- array(
- 'tag' => 'b',
- 'before' => '<span class="bbc_bold">',
- 'after' => '</span>',
- ),
- array(
- 'tag' => 'bdo',
- 'type' => 'unparsed_equals',
- 'before' => '<bdo dir="$1">',
- 'after' => '</bdo>',
- 'test' => '(rtl|ltr)\]',
- 'block_level' => true,
- ),
- array(
- 'tag' => 'black',
- 'before' => '<span style="color: black;" class="bbc_color">',
- 'after' => '</span>',
- ),
- array(
- 'tag' => 'blue',
- 'before' => '<span style="color: blue;" class="bbc_color">',
- 'after' => '</span>',
- ),
- array(
- 'tag' => 'br',
- 'type' => 'closed',
- 'content' => '<br />',
- ),
- array(
- 'tag' => 'center',
- 'before' => '<div class="centertext">',
- 'after' => '</div>',
- 'block_level' => true,
- ),
- array(
- 'tag' => 'code',
- 'type' => 'unparsed_content',
- 'content' => '<div class="codeheader">' . $txt['code'] . ': <a href="javascript:void(0);" onclick="return smfSelectText(this);" class="codeoperation">' . $txt['code_select'] . '</a></div>' . (isBrowser('gecko') || isBrowser('opera') ? '<pre style="margin: 0; padding: 0;">' : '') . '<code class="bbc_code">$1</code>' . (isBrowser('gecko') || isBrowser('opera') ? '</pre>' : ''),
-
- 'validate' => isset($disabled['code']) ? null : create_function('&$tag, &$data, $disabled', '
- global $context;
- if (!isset($disabled[\'code\']))
- {
- $php_parts = preg_split(\'~(<\?php|\?>)~\', $data, -1, PREG_SPLIT_DELIM_CAPTURE);
- for ($php_i = 0, $php_n = count($php_parts); $php_i < $php_n; $php_i++)
- {
- // Do PHP code coloring?
- if ($php_parts[$php_i] != \'<?php\')
- continue;
- $php_string = \'\';
- while ($php_i + 1 < count($php_parts) && $php_parts[$php_i] != \'?>\')
- {
- $php_string .= $php_parts[$php_i];
- $php_parts[$php_i++] = \'\';
- }
- $php_parts[$php_i] = highlight_php_code($php_string . $php_parts[$php_i]);
- }
- // Fix the PHP code stuff...
- $data = str_replace("<pre style=\"display: inline;\">\t</pre>", "\t", implode(\'\', $php_parts));
- $data = str_replace("\t", "<span style=\"white-space: pre;\">\t</span>", $data);
- // Recent Opera bug requiring temporary fix. &nsbp; is needed before </code> to avoid broken selection.
- if ($context[\'browser\'][\'is_opera\'])
- $data .= \' \';
- }'),
- 'block_level' => true,
- ),
- array(
- 'tag' => 'code',
- 'type' => 'unparsed_equals_content',
- 'content' => '<div class="codeheader">' . $txt['code'] . ': ($2) <a href="#" onclick="return smfSelectText(this);" class="codeoperation">' . $txt['code_select'] . '</a></div>' . (isBrowser('gecko') || isBrowser('opera') ? '<pre style="margin: 0; padding: 0;">' : '') . '<code class="bbc_code">$1</code>' . (isBrowser('gecko') || isBrowser('opera') ? '</pre>' : ''),
-
- 'validate' => isset($disabled['code']) ? null : create_function('&$tag, &$data, $disabled', '
- global $context;
- if (!isset($disabled[\'code\']))
- {
- $php_parts = preg_split(\'~(<\?php|\?>)~\', $data[0], -1, PREG_SPLIT_DELIM_CAPTURE);
- for ($php_i = 0, $php_n = count($php_parts); $php_i < $php_n; $php_i++)
- {
- // Do PHP code coloring?
- if ($php_parts[$php_i] != \'<?php\')
- continue;
- $php_string = \'\';
- while ($php_i + 1 < count($php_parts) && $php_parts[$php_i] != \'?>\')
- {
- $php_string .= $php_parts[$php_i];
- $php_parts[$php_i++] = \'\';
- }
- $php_parts[$php_i] = highlight_php_code($php_string . $php_parts[$php_i]);
- }
- // Fix the PHP code stuff...
- $data[0] = str_replace("<pre style=\"display: inline;\">\t</pre>", "\t", implode(\'\', $php_parts));
- $data[0] = str_replace("\t", "<span style=\"white-space: pre;\">\t</span>", $data[0]);
- // Recent Opera bug requiring temporary fix. &nsbp; is needed before </code> to avoid broken selection.
- if ($context[\'browser\'][\'is_opera\'])
- $data[0] .= \' \';
- }'),
- 'block_level' => true,
- ),
- array(
- 'tag' => 'color',
- 'type' => 'unparsed_equals',
- 'test' => '(#[\da-fA-F]{3}|#[\da-fA-F]{6}|[A-Za-z]{1,20}|rgb\(\d{1,3}, ?\d{1,3}, ?\d{1,3}\))\]',
- 'before' => '<span style="color: $1;" class="bbc_color">',
- 'after' => '</span>',
- ),
- array(
- 'tag' => 'email',
- 'type' => 'unparsed_content',
- 'content' => '<a href="mailto:$1" class="bbc_email">$1</a>',
-
- 'validate' => create_function('&$tag, &$data, $disabled', '$data = strtr($data, array(\'<br />\' => \'\'));'),
- ),
- array(
- 'tag' => 'email',
- 'type' => 'unparsed_equals',
- 'before' => '<a href="mailto:$1" class="bbc_email">',
- 'after' => '</a>',
-
- 'disallow_children' => array('email', 'ftp', 'url', 'iurl'),
- 'disabled_after' => ' ($1)',
- ),
- array(
- 'tag' => 'flash',
- 'type' => 'unparsed_commas_content',
- 'test' => '\d+,\d+\]',
- 'content' => (isBrowser('ie') ? '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="$2" height="$3"><param name="movie" value="$1" /><param name="play" value="true" /><param name="loop" value="true" /><param name="quality" value="high" /><param name="AllowScriptAccess" value="never" /><embed src="$1" width="$2" height="$3" play="true" loop="true" quality="high" AllowScriptAccess="never" /><noembed><a href="$1" target="_blank" class="new_win">$1</a></noembed></object>' : '<embed type="application/x-shockwave-flash" src="$1" width="$2" height="$3" play="true" loop="true" quality="high" AllowScriptAccess="never" /><noembed><a href="$1" target="_blank" class="new_win">$1</a></noembed>'),
- 'validate' => create_function('&$tag, &$data, $disabled', '
- if (isset($disabled[\'url\']))
- $tag[\'content\'] = \'$1\';
- elseif (strpos($data[0], \'http://\') !== 0 && strpos($data[0], \'https://\') !== 0)
- $data[0] = \'http://\' . $data[0];
- '),
- 'disabled_content' => '<a href="$1" target="_blank" class="new_win">$1</a>',
- ),
- array(
- 'tag' => 'font',
- 'type' => 'unparsed_equals',
- 'test' => '[A-Za-z0-9_,\-\s]+?\]',
- 'before' => '<span style="font-family: $1;" class="bbc_font">',
- 'after' => '</span>',
- ),
- array(
- 'tag' => 'ftp',
- 'type' => 'unparsed_content',
- 'content' => '<a href="$1" class="bbc_ftp new_win" target="_blank">$1</a>',
- 'validate' => create_function('&$tag, &$data, $disabled', '
- $data = strtr($data, array(\'<br />\' => \'\'));
- if (strpos($data, \'ftp://\') !== 0 && strpos($data, \'ftps://\') !== 0)
- $data = \'ftp://\' . $data;
- '),
- ),
- array(
- 'tag' => 'ftp',
- 'type' => 'unparsed_equals',
- 'before' => '<a href="$1" class="bbc_ftp new_win" target="_blank">',
- 'after' => '</a>',
- 'validate' => create_function('&$tag, &$data, $disabled', '
- if (strpos($data, \'ftp://\') !== 0 && strpos($data, \'ftps://\') !== 0)
- $data = \'ftp://\' . $data;
- '),
- 'disallow_children' => array('email', 'ftp', 'url', 'iurl'),
- 'disabled_after' => ' ($1)',
- ),
- array(
- 'tag' => 'glow',
- 'type' => 'unparsed_commas',
- 'test' => '[#0-9a-zA-Z\-]{3,12},([012]\d{1,2}|\d{1,2})(,[^]]+)?\]',
- 'before' => isBrowser('ie') ? '<table style="border: 0; border-spacing: 0; padding: 0; display: inline; vertical-align: middle; font: inherit;"><tr><td style="filter: Glow(color=$1, strength=$2); font: inherit;">' : '<span style="text-shadow: $1 1px 1px 1px">',
- 'after' => isBrowser('ie') ? '</td></tr></table> ' : '</span>',
- ),
- array(
- 'tag' => 'green',
- 'before' => '<span style="color: green;" class="bbc_color">',
- 'after' => '</span>',
- ),
- array(
- 'tag' => 'html',
- 'type' => 'unparsed_content',
- 'content' => '$1',
- 'block_level' => true,
- 'disabled_content' => '$1',
- ),
- array(
- 'tag' => 'hr',
- 'type' => 'closed',
- 'content' => '<hr />',
- 'block_level' => true,
- ),
- array(
- 'tag' => 'i',
- 'before' => '<em>',
- 'after' => '</em>',
- ),
- array(
- 'tag' => 'img',
- 'type' => 'unparsed_content',
- 'parameters' => array(
- 'alt' => array('optional' => true),
- 'width' => array('optional' => true, 'value' => ' width="$1"', 'match' => '(\d+)'),
- 'height' => array('optional' => true, 'value' => ' height="$1"', 'match' => '(\d+)'),
- ),
- 'content' => '<img src="$1" alt="{alt}"{width}{height} class="bbc_img resized" />',
- 'validate' => create_function('&$tag, &$data, $disabled', '
- $data = strtr($data, array(\'<br />\' => \'\'));
- if (strpos($data, \'http://\') !== 0 && strpos($data, \'https://\') !== 0)
- $data = \'http://\' . $data;
- '),
- 'disabled_content' => '($1)',
- ),
- array(
- 'tag' => 'img',
- 'type' => 'unparsed_content',
- 'content' => '<img src="$1" alt="" class="bbc_img" />',
- 'validate' => create_function('&$tag, &$data, $disabled', '
- $data = strtr($data, array(\'<br />\' => \'\'));
- if (strpos($data, \'http://\') !== 0 && strpos($data, \'https://\') !== 0)
- $data = \'http://\' . $data;
- '),
- 'disabled_content' => '($1)',
- ),
- array(
- 'tag' => 'iurl',
- 'type' => 'unparsed_content',
- 'content' => '<a href="$1" class="bbc_link">$1</a>',
- 'validate' => create_function('&$tag, &$data, $disabled', '
- $data = strtr($data, array(\'<br />\' => \'\'));
- if (strpos($data, \'http://\') !== 0 && strpos($data, \'https://\') !== 0)
- $data = \'http://\' . $data;
- '),
- ),
- array(
- 'tag' => 'iurl',
- 'type' => 'unparsed_equals',
- 'before' => '<a href="$1" class="bbc_link">',
- 'after' => '</a>',
- 'validate' => create_function('&$tag, &$data, $disabled', '
- if (substr($data, 0, 1) == \'#\')
- $data = \'#post_\' . substr($data, 1);
- elseif (strpos($data, \'http://\') !== 0 && strpos($data, \'https://\') !== 0)
- $data = \'http://\' . $data;
- '),
- 'disallow_children' => array('email', 'ftp', 'url', 'iurl'),
- 'disabled_after' => ' ($1)',
- ),
- array(
- 'tag' => 'left',
- 'before' => '<div style="text-align: left;">',
- 'after' => '</div>',
- 'block_level' => true,
- ),
- array(
- 'tag' => 'li',
- 'before' => '<li>',
- 'after' => '</li>',
- 'trim' => 'outside',
- 'require_parents' => array('list'),
- 'block_level' => true,
- 'disabled_before' => '',
- 'disabled_after' => '<br />',
- ),
- array(
- 'tag' => 'list',
- 'before' => '<ul class="bbc_list">',
- 'after' => '</ul>',
- 'trim' => 'inside',
- 'require_children' => array('li', 'list'),
- 'block_level' => true,
- ),
- array(
- 'tag' => 'list',
- 'parameters' => array(
- 'type' => array('match' => '(none|disc|circle|square|decimal|decimal-leading-zero|lower-roman|upper-roman|lower-alpha|upper-alpha|lower-greek|lower-latin|upper-latin|hebrew|armenian|georgian|cjk-ideographic|hiragana|katakana|hiragana-iroha|katakana-iroha)'),
- ),
- 'before' => '<ul class="bbc_list" style="list-style-type: {type};">',
- 'after' => '</ul>',
- 'trim' => 'inside',
- 'require_children' => array('li'),
- 'block_level' => true,
- ),
- array(
- 'tag' => 'ltr',
- 'before' => '<div dir="ltr">',
- 'after' => '</div>',
- 'block_level' => true,
- ),
- array(
- 'tag' => 'me',
- 'type' => 'unparsed_equals',
- 'before' => '<div class="meaction">* $1 ',
- 'after' => '</div>',
- 'quoted' => 'optional',
- 'block_level' => true,
- 'disabled_before' => '/me ',
- 'disabled_after' => '<br />',
- ),
- array(
- 'tag' => 'move',
- 'before' => '<marquee>',
- 'after' => '</marquee>',
- 'block_level' => true,
- 'disallow_children' => array('move'),
- ),
- array(
- 'tag' => 'nobbc',
- 'type' => 'unparsed_content',
- 'content' => '$1',
- ),
- array(
- 'tag' => 'php',
- 'type' => 'unparsed_content',
- 'content' => '<span class="phpcode">$1</span>',
- 'validate' => isset($disabled['php']) ? null : create_function('&$tag, &$data, $disabled', '
- if (!isset($disabled[\'php\']))
- {
- $add_begin = substr(trim($data), 0, 5) != \'<?\';
- $data = highlight_php_code($add_begin ? \'<?php \' . $data . \'?>\' : $data);
- if ($add_begin)
- $data = preg_replace(array(\'~^(.+?)<\?.{0,40}?php(?: |\s)~\', \'~\?>((?:</(font|span)>)*)$~\'), \'$1\', $data, 2);
- }'),
- 'block_level' => false,
- 'disabled_content' => '$1',
- ),
- array(
- 'tag' => 'pre',
- 'before' => '<pre>',
- 'after' => '</pre>',
- ),
- array(
- 'tag' => 'quote',
- 'before' => '<div class="quoteheader"><div class="topslice_quote">' . $txt['quote'] . '</div></div><blockquote>',
- 'after' => '</blockquote><div class="quotefooter"><div class="botslice_quote"></div></div>',
- 'block_level' => true,
- ),
- array(
- 'tag' => 'quote',
- 'parameters' => array(
- 'author' => array('match' => '(.{1,192}?)', 'quoted' => true),
- ),
- 'before' => '<div class="quoteheader"><div class="topslice_quote">' . $txt['quote_from'] . ': {author}</div></div><blockquote>',
- 'after' => '</blockquote><div class="quotefooter"><div class="botslice_quote"></div></div>',
- 'block_level' => true,
- ),
- array(
- 'tag' => 'quote',
- 'type' => 'parsed_equals',
- 'before' => '<div class="quoteheader"><div class="topslice_quote">' . $txt['quote_from'] . ': $1</div></div><blockquote>',
- 'after' => '</blockquote><div class="quotefooter"><div class="botslice_quote"></div></div>',
- 'quoted' => 'optional',
-
- 'parsed_tags_allowed' => array('url', 'iurl', 'ftp'),
- 'block_level' => true,
- ),
- array(
- 'tag' => 'quote',
- 'parameters' => array(
- 'author' => array('match' => '([^<>]{1,192}?)'),
- 'link' => array('match' => '(?:board=\d+;)?((?:topic|threadid)=[\dmsg#\./]{1,40}(?:;start=[\dmsg#\./]{1,40})?|msg=\d+?|action=profile;u=\d+)'),
- 'date' => array('match' => '(\d+)', 'validate' => 'timeformat'),
- ),
- 'before' => '<div class="quoteheader"><div class="topslice_quote"><a href="' . $scripturl . '?{link}">' . $txt['quote_from'] . ': {author} ' . $txt['search_on'] . ' {date}</a></div></div><blockquote>',
- 'after' => '</blockquote><div class="quotefooter"><div class="botslice_quote"></div></div>',
- 'block_level' => true,
- ),
- array(
- 'tag' => 'quote',
- 'parameters' => array(
- 'author' => array('match' => '(.{1,192}?)'),
- ),
- 'before' => '<div class="quoteheader"><div class="topslice_quote">' . $txt['quote_from'] . ': {author}</div></div><blockquote>',
- 'after' => '</blockquote><div class="quotefooter"><div class="botslice_quote"></div></div>',
- 'block_level' => true,
- ),
- array(
- 'tag' => 'red',
- 'before' => '<span style="color: red;" class="bbc_color">',
- 'after' => '</span>',
- ),
- array(
- 'tag' => 'right',
- 'before' => '<div style="text-align: right;">',
- 'after' => '</div>',
- 'block_level' => true,
- ),
- array(
- 'tag' => 'rtl',
- 'before' => '<div dir="rtl">',
- 'after' => '</div>',
- 'block_level' => true,
- ),
- array(
- 'tag' => 's',
- 'before' => '<del>',
- 'after' => '</del>',
- ),
- array(
- 'tag' => 'shadow',
- 'type' => 'unparsed_commas',
- 'test' => '[#0-9a-zA-Z\-]{3,12},(left|right|top|bottom|[0123]\d{0,2})\]',
- 'before' => isBrowser('ie') ? '<span style="display: inline-block; filter: Shadow(color=$1, direction=$2); height: 1.2em;">' : '<span style="text-shadow: $1 $2">',
- 'after' => '</span>',
- 'validate' => isBrowser('ie') ? create_function('&$tag, &$data, $disabled', '
- if ($data[1] == \'left\')
- $data[1] = 270;
- elseif ($data[1] == \'right\')
- $data[1] = 90;
- elseif ($data[1] == \'top\')
- $data[1] = 0;
- elseif ($data[1] == \'bottom\')
- $data[1] = 180;
- else
- $data[1] = (int) $data[1];') : create_function('&$tag, &$data, $disabled', '
- if ($data[1] == \'top\' || (is_numeric($data[1]) && $data[1] < 50))
- $data[1] = \'0 -2px 1px\';
- elseif ($data[1] == \'right\' || (is_numeric($data[1]) && $data[1] < 100))
- $data[1] = \'2px 0 1px\';
- elseif ($data[1] == \'bottom\' || (is_numeric($data[1]) && $data[1] < 190))
- $data[1] = \'0 2px 1px\';
- elseif ($data[1] == \'left\' || (is_numeric($data[1]) && $data[1] < 280))
- $data[1] = \'-2px 0 1px\';
- else
- $data[1] = \'1px 1px 1px\';'),
- ),
- array(
- 'tag' => 'size',
- 'type' => 'unparsed_equals',
- 'test' => '([1-9][\d]?p[xt]|small(?:er)?|large[r]?|x[x]?-(?:small|large)|medium|(0\.[1-9]|[1-9](\.[\d][\d]?)?)?em)\]',
- 'before' => '<span style="font-size: $1;" class="bbc_size">',
- 'after' => '</span>',
- ),
- array(
- 'tag' => 'size',
- 'type' => 'unparsed_equals',
- 'test' => '[1-7]\]',
- 'before' => '<span style="font-size: $1;" class="bbc_size">',
- 'after' => '</span>',
- 'validate' => create_function('&$tag, &$data, $disabled', '
- $sizes = array(1 => 0.7, 2 => 1.0, 3 => 1.35, 4 => 1.45, 5 => 2.0, 6 => 2.65, 7 => 3.95);
- $data = $sizes[$data] . \'em\';'
- ),
- ),
- array(
- 'tag' => 'sub',
- 'before' => '<sub>',
- 'after' => '</sub>',
- ),
- array(
- 'tag' => 'sup',
- 'before' => '<sup>',
- 'after' => '</sup>',
- ),
- array(
- 'tag' => 'table',
- 'before' => '<table class="bbc_table">',
- 'after' => '</table>',
- 'trim' => 'inside',
- 'require_children' => array('tr'),
- 'block_level' => true,
- ),
- array(
- 'tag' => 'td',
- 'before' => '<td>',
- 'after' => '</td>',
- 'require_parents' => array('tr'),
- 'trim' => 'outside',
- 'block_level' => true,
- 'disabled_before' => '',
- 'disabled_after' => '',
- ),
- array(
- 'tag' => 'time',
- 'type' => 'unparsed_content',
- 'content' => '$1',
- 'validate' => create_function('&$tag, &$data, $disabled', '
- if (is_numeric($data))
- $data = timeformat($data);
- else
- $tag[\'content\'] = \'[time]$1[/time]\';'),
- ),
- array(
- 'tag' => 'tr',
- 'before' => '<tr>',
- 'after' => '</tr>',
- 'require_parents' => array('table'),
- 'require_children' => array('td'),
- 'trim' => 'both',
- 'block_level' => true,
- 'disabled_before' => '',
- 'disabled_after' => '',
- ),
- array(
- 'tag' => 'tt',
- 'before' => '<span class="bbc_tt">',
- 'after' => '</span>',
- ),
- array(
- 'tag' => 'u',
- 'before' => '<span class="bbc_u">',
- 'after' => '</span>',
- ),
- array(
- 'tag' => 'url',
- 'type' => 'unparsed_content',
- 'content' => '<a href="$1" class="bbc_link" target="_blank">$1</a>',
- 'validate' => create_function('&$tag, &$data, $disabled', '
- $data = strtr($data, array(\'<br />\' => \'\'));
- if (strpos($data, \'http://\') !== 0 && strpos($data, \'https://\') !== 0)
- $data = \'http://\' . $data;
- '),
- ),
- array(
- 'tag' => 'url',
- 'type' => 'unparsed_equals',
- 'before' => '<a href="$1" class="bbc_link" target="_blank">',
- 'after' => '</a>',
- 'validate' => create_function('&$tag, &$data, $disabled', '
- if (strpos($data, \'http://\') !== 0 && strpos($data, \'https://\') !== 0)
- $data = \'http://\' . $data;
- '),
- 'disallow_children' => array('email', 'ftp', 'url', 'iurl'),
- 'disabled_after' => ' ($1)',
- ),
- array(
- 'tag' => 'white',
- 'before' => '<span style="color: white;" class="bbc_color">',
- 'after' => '</span>',
- ),
- );
-
- call_integration_hook('integrate_bbc_codes', array(&$codes));
-
- if ($message === false)
- {
- if (isset($temp_bbc))
- $bbc_codes = $temp_bbc;
- return $codes;
- }
-
- $itemcodes = array(
- '*' => 'disc',
- '@' => 'disc',
- '+' => 'square',
- 'x' => 'square',
- '#' => 'square',
- 'o' => 'circle',
- 'O' => 'circle',
- '0' => 'circle',
- );
- if (!isset($disabled['li']) && !isset($disabled['list']))
- {
- foreach ($itemcodes as $c => $dummy)
- $bbc_codes[$c] = array();
- }
-
- $no_autolink_tags = array(
- 'url',
- 'iurl',
- 'ftp',
- 'email',
- );
-
- if (!isset($disabled['color']))
- {
- $codes[] = array(
- 'tag' => 'chrissy',
- 'before' => '<span style="color: #cc0099;">',
- 'after' => ' :-*</span>',
- );
- $codes[] = array(
- 'tag' => 'kissy',
- 'before' => '<span style="color: #cc0099;">',
- 'after' => ' :-*</span>',
- );
- }
- foreach ($codes as $code)
- {
-
- if (empty($parse_tags) || in_array($code['tag'], $parse_tags))
- $bbc_codes[substr($code['tag'], 0, 1)][] = $code;
- }
- $codes = null;
- }
-
- if ($cache_id != '' && !empty($modSettings['cache_enable']) && (($modSettings['cache_enable'] >= 2 && isset($message[1000])) || isset($message[2400])) && empty($parse_tags))
- {
-
- $cache_key = 'parse:' . $cache_id . '-' . md5(md5($message) . '-' . $smileys . (empty($disabled) ? '' : implode(',', array_keys($disabled))) . serialize($context['browser']) . $txt['lang_locale'] . $user_info['time_offset'] . $user_info['time_format']);
- if (($temp = cache_get_data($cache_key, 240)) != null)
- return $temp;
- $cache_t = microtime();
- }
- if ($smileys === 'print')
- {
-
- $disabled['glow'] = true;
- $disabled['shadow'] = true;
- $disabled['move'] = true;
-
- $disabled['color'] = true;
- $disabled['black'] = true;
- $disabled['blue'] = true;
- $disabled['white'] = true;
- $disabled['red'] = true;
- $disabled['green'] = true;
- $disabled['me'] = true;
-
- $disabled['php'] = true;
-
- $disabled['ftp'] = true;
- $disabled['url'] = true;
- $disabled['iurl'] = true;
- $disabled['email'] = true;
- $disabled['flash'] = true;
-
- if (!isset($_GET['images']))
- $disabled['img'] = true;
-
- }
- $open_tags = array();
- $message = strtr($message, array("\n" => '<br />'));
-
- $non_breaking_space = $context['utf8'] ? '\x{A0}' : '\xA0';
- $pos = -1;
- while ($pos !== false)
- {
- $last_pos = isset($last_pos) ? max($pos, $last_pos) : $pos;
- $pos = strpos($message, '[', $pos + 1);
-
- if ($pos === false || $last_pos > $pos)
- $pos = strlen($message) + 1;
-
- if ($last_pos < $pos - 1)
- {
-
- $last_pos = max($last_pos, 0);
-
- $data = substr($message, $last_pos, $pos - $last_pos);
-
- if (!empty($modSettings['enablePostHTML']) && strpos($data, '<') !== false)
- {
- $data = preg_replace('~<a\s+href=((?:")?)((?:https?://|ftps?://|mailto:)\S+?)\\1>~i', '[url=$2]', $data);
- $data = preg_replace('~</a>~i', '[/url]', $data);
-
- $empty_tags = array('br', 'hr');
- foreach ($empty_tags as $tag)
- $data = str_replace(array('<' . $tag . '>', '<' . $tag . '/>', '<' . $tag . ' />'), '[' . $tag . ' /]', $data);
-
- $closable_tags = array('b', 'u', 'i', 's', 'em', 'ins', 'del', 'pre', 'blockquote');
- foreach ($closable_tags as $tag)
- {
- $diff = substr_count($data, '<' . $tag . '>') - substr_count($data, '</' . $tag . '>');
- $data = strtr($data, array('<' . $tag . '>' => '<' . $tag . '>', '</' . $tag . '>' => '</' . $tag . '>'));
- if ($diff > 0)
- $data = substr($data, 0, -1) . str_repeat('</' . $tag . '>', $diff) . substr($data, -1);
- }
-
- preg_match_all('~<img\s+src=((?:")?)((?:https?://|ftps?://)\S+?)\\1(?:\s+alt=(".*?"|\S*?))?(?:\s?/)?>~i', $data, $matches, PREG_PATTERN_ORDER);
- if (!empty($matches[0]))
- {
- $replaces = array();
- foreach ($matches[2] as $match => $imgtag)
- {
- $alt = empty($matches[3][$match]) ? '' : ' alt=' . preg_replace('~^"|"$~', '', $matches[3][$match]);
-
- if (preg_match('~action(=|%3d)(?!dlattach)~i', $imgtag) != 0)
- $imgtag = preg_replace('~action(?:=|%3d)(?!dlattach)~i', 'action-', $imgtag);
-
- if (!empty($modSettings['max_image_width']) && !empty($modSettings['max_image_height']))
- {
- list ($width, $height) = url_image_size($imgtag);
- if (!empty($modSettings['max_image_width']) && $width > $modSettings['max_image_width'])
- {
- $height = (int) (($modSettings['max_image_width'] * $height) / $width);
- $width = $modSettings['max_image_width'];
- }
- if (!empty($modSettings['max_image_height']) && $height > $modSettings['max_image_height'])
- {
- $width = (int) (($modSettings['max_image_height'] * $width) / $height);
- $height = $modSettings['max_image_height'];
- }
-
- $replaces[$matches[0][$match]] = '[img width=' . $width . ' height=' . $height . $alt . ']' . $imgtag . '[/img]';
- }
- else
- $replaces[$matches[0][$match]] = '[img' . $alt . ']' . $imgtag . '[/img]';
- }
- $data = strtr($data, $replaces);
- }
- }
- if (!empty($modSettings['autoLinkUrls']))
- {
-
- $no_autolink_area = false;
- if (!empty($open_tags))
- {
- foreach ($open_tags as $open_tag)
- if (in_array($open_tag['tag'], $no_autolink_tags))
- $no_autolink_area = true;
- }
-
-
- $lastAutoPos = isset($lastAutoPos) ? $lastAutoPos : 0;
- if ($pos < $lastAutoPos)
- $no_autolink_area = true;
- $lastAutoPos = $pos;
- if (!$no_autolink_area)
- {
-
- if (!isset($disabled['url']) && (strpos($data, '://') !== false || strpos($data, 'www.') !== false) && strpos($data, '[url') === false)
- {
-
- $data = strtr($data, array(''' => '\'', ' ' => $context['utf8'] ? "\xC2\xA0" : "\xA0", '"' => '>">', '"' => '<"<', '<' => '<lt<'));
-
- if (is_string($result = preg_replace(array(
- '~(?<=[\s>\.(;\'"]|^)((?:http|https)://[\w\-_%@:|]+(?:\.[\w\-_%]+)*(?::\d+)?(?:/[\w\-_\~%\.@!,\?&;=#(){}+:\'\\\\]*)*[/\w\-_\~%@\?;=#}\\\\]?)~i',
- '~(?<=[\s>\.(;\'"]|^)((?:ftp|ftps)://[\w\-_%@:|]+(?:\.[\w\-_%]+)*(?::\d+)?(?:/[\w\-_\~%\.@,\?&;=#(){}+:\'\\\\]*)*[/\w\-_\~%@\?;=#}\\\\]?)~i',
- '~(?<=[\s>(\'<]|^)(www(?:\.[\w\-_]+)+(?::\d+)?(?:/[\w\-_\~%\.@!,\?&;=#(){}+:\'\\\\]*)*[/\w\-_\~%@\?;=#}\\\\])~i'
- ), array(
- '[url]$1[/url]',
- '[ftp]$1[/ftp]',
- '[url=http://$1]$1[/url]'
- ), $data)))
- $data = $result;
- $data = strtr($data, array('\'' => ''', $context['utf8'] ? "\xC2\xA0" : "\xA0" => ' ', '>">' => '"', '<"<' => '"', '<lt<' => '<'));
- }
-
- if (!isset($disabled['email']) && strpos($data, '@') !== false && strpos($data, '[email') === false)
- {
- $data = preg_replace('~(?<=[\?\s' . $non_breaking_space . '\[\]()*\\\;>]|^)([\w\-\.]{1,80}@[\w\-]+\.[\w\-\.]+[\w\-])(?=[?,\s' . $non_breaking_space . '\[\]()*\\\]|$|<br />| |>|<|"|'|\.(?:\.|;| |\s|$|<br />))~' . ($context['utf8'] ? 'u' : ''), '[email]$1[/email]', $data);
- $data = preg_replace('~(?<=<br />)([\w\-\.]{1,80}@[\w\-]+\.[\w\-\.]+[\w\-])(?=[?\.,;\s' . $non_breaking_space . '\[\]()*\\\]|$|<br />| |>|<|"|')~' . ($context['utf8'] ? 'u' : ''), '[email]$1[/email]', $data);
- }
- }
- }
- $data = strtr($data, array("\t" => ' '));
-
- if ($data != substr($message, $last_pos, $pos - $last_pos))
- {
- $message = substr($message, 0, $last_pos) . $data . substr($message, $pos);
-
- $old_pos = strlen($data) + $last_pos;
- $pos = strpos($message, '[', $last_pos);
- $pos = $pos === false ? $old_pos : min($pos, $old_pos);
- }
- }
-
- if ($pos >= strlen($message) - 1)
- break;
- $tags = strtolower($message[$pos + 1]);
- if ($tags == '/' && !empty($open_tags))
- {
- $pos2 = strpos($message, ']', $pos + 1);
- if ($pos2 == $pos + 2)
- continue;
- $look_for = strtolower(substr($message, $pos + 2, $pos2 - $pos - 2));
- $to_close = array();
- $block_level = null;
- do
- {
- $tag = array_pop($open_tags);
- if (!$tag)
- break;
- if (!empty($tag['block_level']))
- {
-
- if ($block_level === false)
- {
- array_push($open_tags, $tag);
- break;
- }
-
- if (strlen($look_for) > 0 && isset($bbc_codes[$look_for[0]]))
- {
- foreach ($bbc_codes[$look_for[0]] as $temp)
- if ($temp['tag'] == $look_for)
- {
- $block_level = !empty($temp['block_level']);
- break;
- }
- }
- if ($block_level !== true)
- {
- $block_level = false;
- array_push($open_tags, $tag);
- break;
- }
- }
- $to_close[] = $tag;
- }
- while ($tag['tag'] != $look_for);
-
- if ((empty($open_tags) && (empty($tag) || $tag['tag'] != $look_for)))
- {
- $open_tags = $to_close;
- continue;
- }
- elseif (!empty($to_close) && $tag['tag'] != $look_for)
- {
- if ($block_level === null && isset($look_for[0], $bbc_codes[$look_for[0]]))
- {
- foreach ($bbc_codes[$look_for[0]] as $temp)
- if ($temp['tag'] == $look_for)
- {
- $block_level = !empty($temp['block_level']);
- break;
- }
- }
-
- if (!$block_level)
- {
- foreach ($to_close as $tag)
- array_push($open_tags, $tag);
- continue;
- }
- }
- foreach ($to_close as $tag)
- {
- $message = substr($message, 0, $pos) . "\n" . $tag['after'] . "\n" . substr($message, $pos2 + 1);
- $pos += strlen($tag['after']) + 2;
- $pos2 = $pos - 1;
-
- if (!empty($tag['block_level']) && substr($message, $pos, 6) == '<br />')
- $message = substr($message, 0, $pos) . substr($message, $pos + 6);
- if (!empty($tag['trim']) && $tag['trim'] != 'inside' && preg_match('~(<br />| |\s)*~', substr($message, $pos), $matches) != 0)
- $message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0]));
- }
- if (!empty($to_close))
- {
- $to_close = array();
- $pos--;
- }
- continue;
- }
-
- if (!isset($bbc_codes[$tags]))
- continue;
- $inside = empty($open_tags) ? null : $open_tags[count($open_tags) - 1];
- $tag = null;
- foreach ($bbc_codes[$tags] as $possible)
- {
- $pt_strlen = strlen($possible['tag']);
-
- if (strtolower(substr($message, $pos + 1, $pt_strlen)) != $possible['tag'])
- continue;
- $next_c = $message[$pos + 1 + $pt_strlen];
-
- if (isset($possible['test']) && preg_match('~^' . $possible['test'] . '~', substr($message, $pos + 1 + $pt_strlen + 1)) === 0)
- continue;
-
- elseif (!empty($possible['parameters']))
- {
- if ($next_c != ' ')
- continue;
- }
- elseif (isset($possible['type']))
- {
-
- if (in_array($possible['type'], array('unparsed_equals', 'unparsed_commas', 'unparsed_commas_content', 'unparsed_equals_content', 'parsed_equals')) && $next_c != '=')
- continue;
-
- if ($possible['type'] == 'closed' && $next_c != ']' && substr($message, $pos + 1 + $pt_strlen, 2) != '/]' && substr($message, $pos + 1 + $pt_strlen, 3) != ' /]')
- continue;
-
- if ($possible['type'] == 'unparsed_content' && $next_c != ']')
- continue;
- }
-
- elseif ($next_c != ']')
- continue;
-
- if (isset($possible['require_parents']) && ($inside === null || !in_array($inside['tag'], $possible['require_parents'])))
- continue;
- elseif (isset($inside['require_children']) && !in_array($possible['tag'], $inside['require_children']))
- continue;
-
- elseif (isset($inside['disallow_children']) && in_array($possible['tag'], $inside['disallow_children']))
- continue;
- $pos1 = $pos + 1 + $pt_strlen + 1;
-
- if ($possible['tag'] == 'quote')
- {
-
- $quote_alt = false;
- foreach ($open_tags as $open_quote)
- {
-
- if ($open_quote['tag'] == 'quote')
- $quote_alt = !$quote_alt;
- }
-
- $possible['before'] = strtr($possible['before'], array('<blockquote>' => '<blockquote class="bbc_' . ($quote_alt ? 'alternate' : 'standard') . '_quote">'));
- }
-
- if (!empty($possible['parameters']))
- {
- $preg = array();
- foreach ($possible['parameters'] as $p => $info)
- $preg[] = '(\s+' . $p . '=' . (empty($info['quoted']) ? '' : '"') . (isset($info['match']) ? $info['match'] : '(.+?)') . (empty($info['quoted']) ? '' : '"') . ')' . (empty($info['optional']) ? '' : '?');
-
- $match = false;
- $orders = permute($preg);
- foreach ($orders as $p)
- if (preg_match('~^' . implode('', $p) . '\]~i', substr($message, $pos1 - 1), $matches) != 0)
- {
- $match = true;
- break;
- }
-
- if (!$match)
- continue;
- $params = array();
- for ($i = 1, $n = count($matches); $i < $n; $i += 2)
- {
- $key = strtok(ltrim($matches[$i]), '=');
- if (isset($possible['parameters'][$key]['value']))
- $params['{' . $key . '}'] = strtr($possible['parameters'][$key]['value'], array('$1' => $matches[$i + 1]));
- elseif (isset($possible['parameters'][$key]['validate']))
- $params['{' . $key . '}'] = $possible['parameters'][$key]['validate']($matches[$i + 1]);
- else
- $params['{' . $key . '}'] = $matches[$i + 1];
-
- $params['{' . $key . '}'] = strtr($params['{' . $key . '}'], array('$' => '$', '{' => '{'));
- }
- foreach ($possible['parameters'] as $p => $info)
- {
- if (!isset($params['{' . $p . '}']))
- $params['{' . $p . '}'] = '';
- }
- $tag = $possible;
-
- if (isset($tag['before']))
- $tag['before'] = strtr($tag['before'], $params);
- if (isset($tag['after']))
- $tag['after'] = strtr($tag['after'], $params);
- if (isset($tag['content']))
- $tag['content'] = strtr($tag['content'], $params);
- $pos1 += strlen($matches[0]) - 1;
- }
- else
- $tag = $possible;
- break;
- }
-
- if ($smileys !== false && $tag === null && isset($itemcodes[$message[$pos + 1]]) && $message[$pos + 2] == ']' && !isset($disabled['list']) && !isset($disabled['li']))
- {
- if ($message[$pos + 1] == '0' && !in_array($message[$pos - 1], array(';', ' ', "\t", '>')))
- continue;
- $tag = $itemcodes[$message[$pos + 1]];
-
- if ($inside === null || ($inside['tag'] != 'list' && $inside['tag'] != 'li'))
- {
- $open_tags[] = array(
- 'tag' => 'list',
- 'after' => '</ul>',
- 'block_level' => true,
- 'require_children' => array('li'),
- 'disallow_children' => isset($inside['disallow_children']) ? $inside['disallow_children'] : null,
- );
- $code = '<ul class="bbc_list">';
- }
-
- elseif ($inside['tag'] == 'li')
- {
- array_pop($open_tags);
- $code = '</li>';
- }
- else
- $code = '';
-
- $open_tags[] = array(
- 'tag' => 'li',
- 'after' => '</li>',
- 'trim' => 'outside',
- 'block_level' => true,
- 'disallow_children' => isset($inside['disallow_children']) ? $inside['disallow_children'] : null,
- );
-
- $code .= '<li' . ($tag == '' ? '' : ' type="' . $tag . '"') . '>';
- $message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos + 3);
- $pos += strlen($code) - 1 + 2;
-
- $pos2 = strpos($message, '<br />', $pos);
- $pos3 = strpos($message, '[/', $pos);
- if ($pos2 !== false && ($pos2 <= $pos3 || $pos3 === false))
- {
- preg_match('~^(<br />| |\s|\[)+~', substr($message, $pos2 + 6), $matches);
- $message = substr($message, 0, $pos2) . "\n" . (!empty($matches[0]) && substr($matches[0], -1) == '[' ? '[/li]' : '[/li][/list]') . "\n" . substr($message, $pos2);
- $open_tags[count($open_tags) - 2]['after'] = '</ul>';
- }
-
- else
- {
-
- $open_tags[count($open_tags) - 1]['after'] = '';
- $open_tags[count($open_tags) - 2]['after'] = '</li></ul>';
- }
- continue;
- }
-
- if ($tag === null && $inside !== null && !empty($inside['require_children']))
- {
- array_pop($open_tags);
- $message = substr($message, 0, $pos) . "\n" . $inside['after'] . "\n" . substr($message, $pos);
- $pos += strlen($inside['after']) - 1 + 2;
- }
-
- if ($tag === null)
- continue;
-
- if (isset($inside['disallow_children']))
- $tag['disallow_children'] = isset($tag['disallow_children']) ? array_unique(array_merge($tag['disallow_children'], $inside['disallow_children'])) : $inside['disallow_children'];
-
- if (isset($disabled[$tag['tag']]))
- {
- if (!isset($tag['disabled_before']) && !isset($tag['disabled_after']) && !isset($tag['disabled_content']))
- {
- $tag['before'] = !empty($tag['block_level']) ? '<div>' : '';
- $tag['after'] = !empty($tag['block_level']) ? '</div>' : '';
- $tag['content'] = isset($tag['type']) && $tag['type'] == 'closed' ? '' : (!empty($tag['block_level']) ? '<div>$1</div>' : '$1');
- }
- elseif (isset($tag['disabled_before']) || isset($tag['disabled_after']))
- {
- $tag['before'] = isset($tag['disabled_before']) ? $tag['disabled_before'] : (!empty($tag['block_level']) ? '<div>' : '');
- $tag['after'] = isset($tag['disabled_after']) ? $tag['disabled_after'] : (!empty($tag['block_level']) ? '</div>' : '');
- }
- else
- $tag['content'] = $tag['disabled_content'];
- }
-
- $tag_strlen = strlen($tag['tag']);
-
- if (!empty($tag['block_level']) && $tag['tag'] != 'html' && empty($inside['block_level']))
- {
- $n = count($open_tags) - 1;
- while (empty($open_tags[$n]['block_level']) && $n >= 0)
- $n--;
-
- for ($i = count($open_tags) - 1; $i > $n; $i--)
- {
- $message = substr($message, 0, $pos) . "\n" . $open_tags[$i]['after'] . "\n" . substr($message, $pos);
- $ot_strlen = strlen($open_tags[$i]['after']);
- $pos += $ot_strlen + 2;
- $pos1 += $ot_strlen + 2;
-
- if (!empty($open_tags[$i]['block_level']) && substr($message, $pos, 6) == '<br />')
- $message = substr($message, 0, $pos) . substr($message, $pos + 6);
- if (!empty($open_tags[$i]['trim']) && $tag['trim'] != 'inside' && preg_match('~(<br />| |\s)*~', substr($message, $pos), $matches) != 0)
- $message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0]));
- array_pop($open_tags);
- }
- }
-
- if (!isset($tag['type']))
- {
-
- $open_tags[] = $tag;
- $message = substr($message, 0, $pos) . "\n" . $tag['before'] . "\n" . substr($message, $pos1);
- $pos += strlen($tag['before']) - 1 + 2;
- }
-
- elseif ($tag['type'] == 'unparsed_content')
- {
- $pos2 = stripos($message, '[/' . substr($message, $pos + 1, $tag_strlen) . ']', $pos1);
- if ($pos2 === false)
- continue;
- $data = substr($message, $pos1, $pos2 - $pos1);
- if (!empty($tag['block_level']) && substr($data, 0, 6) == '<br />')
- $data = substr($data, 6);
- if (isset($tag['validate']))
- $tag['validate']($tag, $data, $disabled);
- $code = strtr($tag['content'], array('$1' => $data));
- $message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos2 + 3 + $tag_strlen);
- $pos += strlen($code) - 1 + 2;
- $last_pos = $pos + 1;
- }
-
- elseif ($tag['type'] == 'unparsed_equals_content')
- {
-
- if (isset($tag['quoted']))
- {
- $quoted = substr($message, $pos1, 6) == '"';
- if ($tag['quoted'] != 'optional' && !$quoted)
- continue;
- if ($quoted)
- $pos1 += 6;
- }
- else
- $quoted = false;
- $pos2 = strpos($message, $quoted == false ? ']' : '"]', $pos1);
- if ($pos2 === false)
- continue;
- $pos3 = stripos($message, '[/' . substr($message, $pos + 1, $tag_strlen) . ']', $pos2);
- if ($pos3 === false)
- continue;
- $data = array(
- substr($message, $pos2 + ($quoted == false ? 1 : 7), $pos3 - ($pos2 + ($quoted == false ? 1 : 7))),
- substr($message, $pos1, $pos2 - $pos1)
- );
- if (!empty($tag['block_level']) && substr($data[0], 0, 6) == '<br />')
- $data[0] = substr($data[0], 6);
-
- if (isset($tag['validate']))
- $tag['validate']($tag, $data, $disabled);
- $code = strtr($tag['content'], array('$1' => $data[0], '$2' => $data[1]));
- $message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos3 + 3 + $tag_strlen);
- $pos += strlen($code) - 1 + 2;
- }
-
- elseif ($tag['type'] == 'closed')
- {
- $pos2 = strpos($message, ']', $pos);
- $message = substr($message, 0, $pos) . "\n" . $tag['content'] . "\n" . substr($message, $pos2 + 1);
- $pos += strlen($tag['content']) - 1 + 2;
- }
-
- elseif ($tag['type'] == 'unparsed_commas_content')
- {
- $pos2 = strpos($message, ']', $pos1);
- if ($pos2 === false)
- continue;
- $pos3 = stripos($message, '[/' . substr($message, $pos + 1, $tag_strlen) . ']', $pos2);
- if ($pos3 === false)
- continue;
-
- $data = explode(',', ',' . substr($message, $pos1, $pos2 - $pos1));
- $data[0] = substr($message, $pos2 + 1, $pos3 - $pos2 - 1);
- if (isset($tag['validate']))
- $tag['validate']($tag, $data, $disabled);
- $code = $tag['content'];
- foreach ($data as $k => $d)
- $code = strtr($code, array('$' . ($k + 1) => trim($d)));
- $message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos3 + 3 + $tag_strlen);
- $pos += strlen($code) - 1 + 2;
- }
-
- elseif ($tag['type'] == 'unparsed_commas')
- {
- $pos2 = strpos($message, ']', $pos1);
- if ($pos2 === false)
- continue;
- $data = explode(',', substr($message, $pos1, $pos2 - $pos1));
- if (isset($tag['validate']))
- $tag['validate']($tag, $data, $disabled);
-
- foreach ($data as $k => $d)
- $tag['after'] = strtr($tag['after'], array('$' . ($k + 1) => trim($d)));
- $open_tags[] = $tag;
-
- $code = $tag['before'];
- foreach ($data as $k => $d)
- $code = strtr($code, array('$' . ($k + 1) => trim($d)));
- $message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos2 + 1);
- $pos += strlen($code) - 1 + 2;
- }
-
- elseif ($tag['type'] == 'unparsed_equals' || $tag['type'] == 'parsed_equals')
- {
-
- if (isset($tag['quoted']))
- {
- $quoted = substr($message, $pos1, 6) == '"';
- if ($tag['quoted'] != 'optional' && !$quoted)
- continue;
- if ($quoted)
- $pos1 += 6;
- }
- else
- $quoted = false;
- $pos2 = strpos($message, $quoted == false ? ']' : '"]', $pos1);
- if ($pos2 === false)
- continue;
- $data = substr($message, $pos1, $pos2 - $pos1);
-
- if (isset($tag['validate']))
- $tag['validate']($tag, $data, $disabled);
-
- if ($tag['type'] != 'unparsed_equals')
- $data = parse_bbc($data, !empty($tag['parsed_tags_allowed']) ? false : true, '', !empty($tag['parsed_tags_allowed']) ? $tag['parsed_tags_allowed'] : array());
- $tag['after'] = strtr($tag['after'], array('$1' => $data));
- $open_tags[] = $tag;
- $code = strtr($tag['before'], array('$1' => $data));
- $message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos2 + ($quoted == false ? 1 : 7));
- $pos += strlen($code) - 1 + 2;
- }
-
- if (!empty($tag['block_level']) && substr($message, $pos + 1, 6) == '<br />')
- $message = substr($message, 0, $pos + 1) . substr($message, $pos + 7);
-
- if (!empty($tag['trim']) && $tag['trim'] != 'outside' && preg_match('~(<br />| |\s)*~', substr($message, $pos + 1), $matches) != 0)
- $message = substr($message, 0, $pos + 1) . substr($message, $pos + 1 + strlen($matches[0]));
- }
-
- while ($tag = array_pop($open_tags))
- $message .= "\n" . $tag['after'] . "\n";
-
- if ($smileys === true)
- {
- $message_parts = explode("\n", $message);
- for ($i = 0, $n = count($message_parts); $i < $n; $i += 2)
- parsesmileys($message_parts[$i]);
- $message = implode('', $message_parts);
- }
-
- else
- $message = strtr($message, array("\n" => ''));
- if ($message[0] === ' ')
- $message = ' ' . substr($message, 1);
-
- $message = strtr($message, array(' ' => ' ', "\r" => '', "\n" => '<br />', '<br /> ' => '<br /> ', ' ' => "\n"));
-
- call_integration_hook('integrate_post_parsebbc', array(&$message, &$smileys, &$cache_id, &$parse_tags));
-
- if (isset($cache_key, $cache_t) && array_sum(explode(' ', microtime())) - array_sum(explode(' ', $cache_t)) > 0.05)
- cache_put_data($cache_key, $message, 240);
-
- if (!empty($parse_tags))
- {
- if (empty($temp_bbc))
- $bbc_codes = array();
- else
- {
- $bbc_codes = $temp_bbc;
- unset($temp_bbc);
- }
- }
- return $message;
- }
- function parsesmileys(&$message)
- {
- global $modSettings, $txt, $user_info, $context, $smcFunc;
- static $smileyPregSearch = null, $smileyPregReplacements = array();
-
- if ($user_info['smiley_set'] == 'none' || trim($message) == '')
- return;
-
- if (empty($smileyPregSearch))
- {
-
- if (empty($modSettings['smiley_enable']))
- {
- $smileysfrom = array('>:D', ':D', '::)', '>:(', ':))', ':)', ';)', ';D', ':(', ':o', '8)', ':P', '???', ':-[', ':-X', ':-*', ':\'(', ':-\\', '^-^', 'O0', 'C:-)', '0:)');
- $smileysto = array('evil.gif', 'cheesy.gif', 'rolleyes.gif', 'angry.gif', 'laugh.gif', 'smiley.gif', 'wink.gif', 'grin.gif', 'sad.gif', 'shocked.gif', 'cool.gif', 'tongue.gif', 'huh.gif', 'embarrassed.gif', 'lipsrsealed.gif', 'kiss.gif', 'cry.gif', 'undecided.gif', 'azn.gif', 'afro.gif', 'police.gif', 'angel.gif');
- $smileysdescs = array('', $txt['icon_cheesy'], $txt['icon_rolleyes'], $txt['icon_angry'], '', $txt['icon_smiley'], $txt['icon_wink'], $txt['icon_grin'], $txt['icon_sad'], $txt['icon_shocked'], $txt['icon_cool'], $txt['icon_tongue'], $txt['icon_huh'], $txt['icon_embarrassed'], $txt['icon_lips'], $txt['icon_kiss'], $txt['icon_cry'], $txt['icon_undecided'], '', '', '', '');
- }
- else
- {
-
- if (($temp = cache_get_data('parsing_smileys', 480)) == null)
- {
- $result = $smcFunc['db_query']('', '
- SELECT code, filename, description
- FROM {db_prefix}smileys
- ORDER BY LENGTH(code) DESC',
- array(
- )
- );
- $smileysfrom = array();
- $smileysto = array();
- $smileysdescs = array();
- while ($row = $smcFunc['db_fetch_assoc']($result))
- {
- $smileysfrom[] = $row['code'];
- $smileysto[] = $smcFunc['htmlspecialchars']($row['filename']);
- $smileysdescs[] = $row['description'];
- }
- $smcFunc['db_free_result']($result);
- cache_put_data('parsing_smileys', array($smileysfrom, $smileysto, $smileysdescs), 480);
- }
- else
- list ($smileysfrom, $smileysto, $smileysdescs) = $temp;
- }
-
- $non_breaking_space = $context['utf8'] ? '\x{A0}' : '\xA0';
-
- $smileyPregReplacements = array();
- $searchParts = array();
- $smileys_path = $smcFunc['htmlspecialchars']($modSettings['smileys_url'] . '/' . $user_info['smiley_set'] . '/');
- for ($i = 0, $n = count($smileysfrom); $i < $n; $i++)
- {
- $specialChars = $smcFunc['htmlspecialchars']($smileysfrom[$i], ENT_QUOTES);
- $smileyCode = '<img src="' . $smileys_path . $smileysto[$i] . '" alt="' . strtr($specialChars, array(':' => ':', '(' => '(', ')' => ')', '$' => '$', '[' => '[')). '" title="' . strtr($smcFunc['htmlspecialchars']($smileysdescs[$i]), array(':' => ':', '(' => '(', ')' => ')', '$' => '$', '[' => '[')) . '" class="smiley" />';
- $smileyPregReplacements[$smileysfrom[$i]] = $smileyCode;
- $searchParts[] = preg_quote($smileysfrom[$i], '~');
- if ($smileysfrom[$i] != $specialChars)
- {
- $smileyPregReplacements[$specialChars] = $smileyCode;
- $searchParts[] = preg_quote($specialChars, '~');
- }
- }
- $smileyPregSearch = '~(?<=[>:\?\.\s' . $non_breaking_space . '[\]()*\\\;]|^)(' . implode('|', $searchParts) . ')(?=[^[:alpha:]0-9]|$)~' . ($context['utf8'] ? 'u' : '');
- }
-
-
- $callback = pregReplaceCurry('smielyPregReplaceCallback', 2);
- $message = preg_replace_callback($smileyPregSearch, $callback($smileyPregReplacements), $message);
- }
- function pregReplaceCurry($func, $arity)
- {
- return create_function('', "
- \$args = func_get_args();
- if(count(\$args) >= $arity)
- return call_user_func_array('$func', \$args);
- \$args = var_export(\$args, 1);
- return create_function('','
- \$a = func_get_args();
- \$z = ' . \$args . ';
- \$a = array_merge(\$z,\$a);
- return call_user_func_array(\'$func\', \$a);
- ');
- ");
- }
- function smielyPregReplaceCallback($replacements, $matches)
- {
- return $replacements[$matches[1]];
- }
- function highlight_php_code($code)
- {
- global $context;
-
- $code = un_htmlspecialchars(strtr($code, array('<br />' => "\n", "\t" => 'SMF_TAB();', '[' => '[')));
- $oldlevel = error_reporting(0);
- $buffer = str_replace(array("\n", "\r"), '', @highlight_string($code, true));
- error_reporting($oldlevel);
-
- $buffer = preg_replace('~SMF_TAB(?:</(?:font|span)><(?:font color|span style)="[^"]*?">)?\\(\\);~', '<pre style="display: inline;">' . "\t" . '</pre>', $buffer);
- return strtr($buffer, array('\'' => ''', '<code>' => '', '</code>' => ''));
- }
- function redirectexit($setLocation = '', $refresh = false)
- {
- global $scripturl, $context, $modSettings, $db_show_debug, $db_cache;
-
- if (!empty($context['flush_mail']))
-
- AddMailQueue(true);
- $add = preg_match('~^(ftp|http)[s]?://~', $setLocation) == 0 && substr($setLocation, 0, 6) != 'about:';
- if (WIRELESS)
- {
-
- if ($add)
- $setLocation = $scripturl . '?' . $setLocation;
- $char = strpos($setLocation, '?') === false ? '?' : ';';
- if (strpos($setLocation, '#') !== false)
- $setLocation = strtr($setLocation, array('#' => $char . WIRELESS_PROTOCOL . '#'));
- else
- $setLocation .= $char . WIRELESS_PROTOCOL;
- }
- elseif ($add)
- $setLocation = $scripturl . ($setLocation != '' ? '?' . $setLocation : '');
-
- if (defined('SID') && SID != '')
- $setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '(?!\?' . preg_quote(SID, '/') . ')\\??/', $scripturl . '?' . SID . ';', $setLocation);
-
- elseif (isset($_GET['debug']))
- $setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '\\??/', $scripturl . '?debug;', $setLocation);
- if (!empty($modSettings['queryless_urls']) && (empty($context['server']['is_cgi']) || ini_get('cgi.fix_pathinfo') == 1 || @get_cfg_var('cgi.fix_pathinfo') == 1) && (!empty($context['server']['is_apache']) || !empty($context['server']['is_lighttpd']) || !empty($context['server']['is_litespeed'])))
- {
- if (defined('SID') && SID != '')
- $setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?(?:' . SID . '(?:;|&|&))((?:board|topic)=[^#]+?)(#[^"]*?)?$~', create_function('$m', 'global $scripturl; return $scripturl . \'/\' . strtr("$m[1]", \'&;=\', \'//,\') . \'.html?\' . SID. (isset($m[2]) ? "$m[2]" : "");'), $setLocation);
- else
- $setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?$~', create_function('$m', 'global $scripturl; return $scripturl . \'/\' . strtr("$m[1]", \'&;=\', \'//,\') . \'.html\' . (isset($m[2]) ? "$m[2]" : "");'), $setLocation);
- }
-
- call_integration_hook('integrate_redirect', array(&$setLocation, &$refresh));
-
- if ($refresh && !WIRELESS)
- header('Refresh: 0; URL=' . strtr($setLocation, array(' ' => '%20')));
- else
- header('Location: ' . str_replace(' ', '%20', $setLocation));
-
- if (isset($db_show_debug) && $db_show_debug === true)
- $_SESSION['debug_redirect'] = $db_cache;
- obExit(false);
- }
- function obExit($header = null, $do_footer = null, $from_index = false, $from_fatal_error = false)
- {
- global $context, $settings, $modSettings, $txt, $smcFunc;
- static $header_done = false, $footer_done = false, $level = 0, $has_fatal_error = false;
-
- ++$level;
- if ($level > 1 && !$from_fatal_error && !$has_fatal_error)
- exit;
- if ($from_fatal_error)
- $has_fatal_error = true;
-
- trackStats();
-
- if (!empty($context['flush_mail']))
-
- AddMailQueue(true);
- $do_header = $header === null ? !$header_done : $header;
- if ($do_footer === null)
- $do_footer = $do_header;
-
- if ($do_header)
- {
-
- if (!empty($context['page_title']) && empty($context['page_title_html_safe']))
- $context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : '');
-
- ob_start('ob_sessrewrite');
- if (!empty($settings['output_buffers']) && is_string($settings['output_buffers']))
- $buffers = explode(',', $settings['output_buffers']);
- elseif (!empty($settings['output_buffers']))
- $buffers = $settings['output_buffers'];
- else
- $buffers = array();
- if (isset($modSettings['integrate_buffer']))
- $buffers = array_merge(explode(',', $modSettings['integrate_buffer']), $buffers);
- if (!empty($buffers))
- foreach ($buffers as $function)
- {
- $function = trim($function);
- $call = strpos($function, '::') !== false ? explode('::', $function) : $function;
-
- if (is_callable($call))
- ob_start($call);
- }
-
- template_header();
- $header_done = true;
- }
- if ($do_footer)
- {
- if (WIRELESS && !isset($context['sub_template']))
- fatal_lang_error('wireless_error_notyet', false);
-
- loadSubTemplate(isset($context['sub_template']) ? $context['sub_template'] : 'main');
-
- if (!empty($context['insert_after_template']) && !isset($_REQUEST['xml']))
- echo $context['insert_after_template'];
-
- if (!$footer_done)
- {
- $footer_done = true;
- template_footer();
-
- if (!isset($_REQUEST['xml']))
- displayDebug();
- }
- }
-
- if (strpos($_SERVER['REQUEST_URL'], 'action=dlattach') === false && strpos($_SERVER['REQUEST_URL'], 'action=viewsmfile') === false)
- $_SESSION['old_url'] = $_SERVER['REQUEST_URL'];
-
- $_SESSION['USER_AGENT'] = empty($_SERVER['HTTP_USER_AGENT']) ? '' : $_SERVER['HTTP_USER_AGENT'];
-
- call_integration_hook('integrate_exit', array($do_footer && !WIRELESS));
-
- if (!$from_index || WIRELESS)
- exit;
- }
- function url_image_size($url)
- {
- global $sourcedir;
-
- $url = str_replace(' ', '%20', $url);
-
- if (($temp = cache_get_data('url_image_size-' . md5($url), 240)) !== null)
- return $temp;
- $t = microtime();
-
- preg_match('~^\w+://(.+?)/(.*)$~', $url, $match);
-
- if ($url == '' || $url == 'http://' || $url == 'https://')
- {
- return false;
- }
- elseif (!isset($match[1]))
- {
- $size = @getimagesize($url);
- }
- else
- {
-
- $temp = 0;
- $fp = @fsockopen($match[1], 80, $temp, $temp, 0.5);
-
- if ($fp != false)
- {
-
- fwrite($fp, 'HEAD /' . $match[2] . ' HTTP/1.1' . "\r\n" . 'Host: ' . $match[1] . "\r\n" . 'User-Agent: PHP/SMF' . "\r\n" . 'Connection: close' . "\r\n\r\n");
-
- $test = substr(fgets($fp, 11), -1);
- fclose($fp);
-
- if ($test < 4)
- {
- $size = @getimagesize($url);
-
- if ($size === false && function_exists('imagecreatefromstring'))
- {
- include_once($sourcedir . '/Subs-Package.php');
-
- $image = @imagecreatefromstring(fetch_web_data($url));
- if ($image !== false)
- {
- $size = array(imagesx($image), imagesy($image));
- imagedestroy($image);
- }
- }
- }
- }
- }
-
- if (!isset($size))
- $size = false;
-
- if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.8)
- cache_put_data('url_image_size-' . md5($url), $size, 240);
-
- return $size;
- }
- function determineTopicClass(&$topic_context)
- {
-
- $topic_context['class'] = 'normal';
- $topic_context['class'] .= $topic_context['is_poll'] ? '_poll' : '_post';
- if ($topic_context['is_locked'])
- $topic_context['class'] .= '_locked';
- if ($topic_context['is_sticky'])
- $topic_context['class'] .= '_sticky';
-
- $topic_context['extended_class'] = &$topic_context['class'];
- }
- function setupThemeContext($forceload = false)
- {
- global $modSettings, $user_info, $scripturl, $context, $settings, $options, $txt, $maintenance;
- global $user_settings, $smcFunc;
- static $loaded = false;
-
-
- if ($loaded && !$forceload)
- return;
- $loaded = true;
- $context['in_maintenance'] = !empty($maintenance);
- $context['current_time'] = timeformat(time(), false);
- $context['current_action'] = isset($_GET['action']) ? $smcFunc['htmlspecialchars']($_GET['action']) : '';
- $context['show_quick_login'] = !empty($modSettings['enableVBStyleLogin']) && $user_info['is_guest'];
-
- $context['news_lines'] = array_filter(explode("\n", str_replace("\r", '', trim(addslashes($modSettings['news'])))));
- for ($i = 0, $n = count($context['news_lines']); $i < $n; $i++)
- {
- if (trim($context['news_lines'][$i]) == '')
- continue;
-
- $context['news_lines'][$i] = parse_bbc(stripslashes(trim($context['news_lines'][$i])), true, 'news' . $i);
- }
- if (!empty($context['news_lines']))
- $context['random_news_line'] = $context['news_lines'][mt_rand(0, count($context['news_lines']) - 1)];
- if (!$user_info['is_guest'])
- {
- $context['user']['messages'] = &$user_info['messages'];
- $context['user']['unread_messages'] = &$user_info['unread_messages'];
- $context['user']['alerts'] = &$user_info['alerts'];
-
- if ($user_info['unread_messages'] > (isset($_SESSION['unread_messages']) ? $_SESSION['unread_messages'] : 0))
- $context['user']['popup_messages'] = true;
- else
- $context['user']['popup_messages'] = false;
- $_SESSION['unread_messages'] = $user_info['unread_messages'];
- if (allowedTo('moderate_forum'))
- $context['unapproved_members'] = (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 2) || !empty($modSettings['approveAccountDeletion']) ? $modSettings['unapprovedMembers'] : 0;
- $context['user']['avatar'] = array();
-
- if ($user_info['avatar']['url'] == '' && !empty($user_info['avatar']['id_attach']))
- $context['user']['avatar']['href'] = $user_info['avatar']['custom_dir'] ? $modSettings['custom_avatar_url'] . '/' . $user_info['avatar']['filename'] : $scripturl . '?action=dlattach;attach=' . $user_info['avatar']['id_attach'] . ';type=avatar';
-
- elseif (strpos($user_info['avatar']['url'], 'http://') === 0 || strpos($user_info['avatar']['url'], 'https://') === 0)
- {
- $context['user']['avatar']['href'] = $user_info['avatar']['url'];
- if ($modSettings['avatar_action_too_large'] == 'option_html_resize' || $modSettings['avatar_action_too_large'] == 'option_js_resize')
- {
- if (!empty($modSettings['avatar_max_width_external']))
- $context['user']['avatar']['width'] = $modSettings['avatar_max_width_external'];
- if (!empty($modSettings['avatar_max_height_external']))
- $context['user']['avatar']['height'] = $modSettings['avatar_max_height_external'];
- }
- }
-
- elseif ($user_info['avatar']['url'] != '')
- $context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/' . $smcFunc['htmlspecialchars']($user_info['avatar']['url']);
- if (!empty($context['user']['avatar']))
- $context['user']['avatar']['image'] = '<img src="' . $context['user']['avatar']['href'] . '"' . (isset($context['user']['avatar']['width']) ? ' width="' . $context['user']['avatar']['width'] . '"' : '') . (isset($context['user']['avatar']['height']) ? ' height="' . $context['user']['avatar']['height'] . '"' : '') . ' alt="" class="avatar" />';
-
- $context['user']['total_time_logged_in'] = array(
- 'days' => floor($user_info['total_time_logged_in'] / 86400),
- 'hours' => floor(($user_info['total_time_logged_in'] % 86400) / 3600),
- 'minutes' => floor(($user_info['total_time_logged_in'] % 3600) / 60)
- );
- }
- else
- {
- $context['user']['messages'] = 0;
- $context['user']['unread_messages'] = 0;
- $context['user']['avatar'] = array();
- $context['user']['total_time_logged_in'] = array('days' => 0, 'hours' => 0, 'minutes' => 0);
- $context['user']['popup_messages'] = false;
- if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 1)
- $txt['welcome_guest'] .= $txt['welcome_guest_activate'];
-
- if (!empty($modSettings['disableHashTime']) && ($modSettings['disableHashTime'] == 1 || time() < $modSettings['disableHashTime']))
- $context['disable_login_hashing'] = true;
- }
-
- setupMenuContext();
- if (empty($settings['theme_version']))
- $context['show_vBlogin'] = $context['show_quick_login'];
-
- $context['show_news'] = !empty($settings['enable_news']);
-
- $context['show_pm_popup'] = $context['user']['popup_messages'] && !empty($options['popup_messages']) && (!isset($_REQUEST['action']) || $_REQUEST['action'] != 'pm');
-
- if ($context['show_pm_popup'])
- addInlineJavascript('
- jQuery(document).ready(function($) {
- new smc_Popup({
- heading: ' . JavaScriptEscape($txt['show_personal_messages_heading']) . ',
- content: ' . JavaScriptEscape(sprintf($txt['show_personal_messages'], $context['user']['unread_messages'], $scripturl . '?action=pm')) . ',
- icon_class: \'generic_icons mail_new\'
- });
- });');
-
- if ($modSettings['avatar_action_too_large'] == 'option_js_resize' && (!empty($modSettings['avatar_max_width_external']) || !empty($modSettings['avatar_max_height_external'])))
- {
-
- addJavascriptVar('smf_avatarMaxWidth', (int) $modSettings['avatar_max_width_external']);
- addJavascriptVar('smf_avatarMaxHeight', (int) $modSettings['avatar_max_height_external']);
- if (!isBrowser('ie'))
- addInlineJavascript('window.addEventListener("load", smf_avatarResize, false);');
- else
- {
- addJavascriptVar('window_oldAvatarOnload', 'window.onload');
- addInlineJavascript('window.onload = smf_avatarResize;');
- }
- }
-
- $context['common_stats']['latest_member'] = array(
- 'id' => $modSettings['latestMember'],
- 'name' => $modSettings['latestRealName'],
- 'href' => $scripturl . '?action=profile;u=' . $modSettings['latestMember'],
- 'link' => '<a href="' . $scripturl . '?action=profile;u=' . $modSettings['latestMember'] . '">' . $modSettings['latestRealName'] . '</a>',
- );
- $context['common_stats'] = array(
- 'total_posts' => comma_format($modSettings['totalMessages']),
- 'total_topics' => comma_format($modSettings['totalTopics']),
- 'total_members' => comma_format($modSettings['totalMembers']),
- 'latest_member' => $context['common_stats']['latest_member'],
- );
- $context['common_stats']['boardindex_total_posts'] = sprintf($txt['boardindex_total_posts'], $context['common_stats']['total_posts'], $context['common_stats']['total_topics'], $context['common_stats']['total_members']);
- if (empty($settings['theme_version']))
- addJavascriptVar('smf_scripturl', $scripturl);
- if (!isset($context['page_title']))
- $context['page_title'] = '';
-
- $context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : '');
- $context['meta_keywords'] = !empty($modSettings['meta_keywords']) ? $smcFunc['htmlspecialchars']($modSettings['meta_keywords']) : '';
- }
- function setMemoryLimit($needed, $in_use = false)
- {
-
- $memory_used = 0;
- $memory_current = memoryReturnBytes(ini_get('memory_limit'));
- $memory_needed = memoryReturnBytes($needed);
-
- if ($in_use)
- $memory_needed += function_exists('memory_get_usage') ? memory_get_usage() : (2 * 1048576);
-
- if ($memory_current < $memory_needed)
- {
- @ini_set('memory_limit', ceil($memory_needed / 1048576) . 'M');
- $memory_current = memoryReturnBytes(ini_get('memory_limit'));
- }
- $memory_current = max($memory_current, memoryReturnBytes(get_cfg_var('memory_limit')));
-
- return (bool) ($memory_current >= $memory_needed);
- }
- function memoryReturnBytes($val)
- {
- if (is_integer($val))
- return $val;
-
- $val = trim($val);
- $num = intval(substr($val, 0, strlen($val) - 1));
- $last = strtolower(substr($val, -1));
-
- switch ($last)
- {
- case 'g':
- $num *= 1024;
- case 'm':
- $num *= 1024;
- case 'k':
- $num *= 1024;
- }
- return $num;
- }
- function template_rawdata()
- {
- global $context;
- echo $context['raw_data'];
- }
- function template_header()
- {
- global $txt, $modSettings, $context, $settings, $user_info, $boarddir, $cachedir;
- setupThemeContext();
-
- if (empty($context['no_last_modified']))
- {
- header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
- header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
-
- if (!isset($_REQUEST['xml']) && isset($_GET['debug']) && !isBrowser('ie') && !WIRELESS)
- header('Content-Type: application/xhtml+xml');
- elseif (!isset($_REQUEST['xml']) && !WIRELESS)
- header('Content-Type: text/html; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
- }
- header('Content-Type: text/' . (isset($_REQUEST['xml']) ? 'xml' : 'html') . '; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
-
- if ($context['in_maintenance'] && $context['user']['is_admin'])
- {
- $position = array_search('body', $context['template_layers']);
- if ($position === false)
- $position = array_search('main', $context['template_layers']);
- if ($position !== false)
- {
- $before = array_slice($context['template_layers'], 0, $position + 1);
- $after = array_slice($context['template_layers'], $position + 1);
- $context['template_layers'] = array_merge($before, array('maint_warning'), $after);
- }
- }
- $checked_securityFiles = false;
- $showed_banned = false;
- foreach ($context['template_layers'] as $layer)
- {
- loadSubTemplate($layer . '_above', true);
-
- if (in_array($layer, array('body', 'main')) && allowedTo('admin_forum') && !$user_info['is_guest'] && !$checked_securityFiles)
- {
- $checked_securityFiles = true;
- $securityFiles = array('install.php', 'webinstall.php', 'upgrade.php', 'convert.php', 'repair_paths.php', 'repair_settings.php', 'Settings.php~', 'Settings_bak.php~');
-
- call_integration_hook('integrate_security_files', array(&$securityFiles));
- foreach ($securityFiles as $i => $securityFile)
- {
- if (!file_exists($boarddir . '/' . $securityFile))
- unset($securityFiles[$i]);
- }
-
- if (!empty($modSettings['currentAttachmentUploadDir']))
- {
- if (!is_array($modSettings['attachmentUploadDir']))
- $modSettings['attachmentUploadDir'] = @unserialize($modSettings['attachmentUploadDir']);
- $path = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']];
- }
- else
- {
- $path = $modSettings['attachmentUploadDir'];
- $id_folder_thumb = 1;
- }
- secureDirectory($path, true);
- secureDirectory($cachedir);
-
- if ($modSettings['requireAgreement'])
- $agreement = !file_exists($boarddir . '/agreement.txt');
- if (!empty($securityFiles) || (!empty($modSettings['cache_enable']) && !is_writable($cachedir)) || !empty($agreement))
- {
- echo '
- <div class="errorbox">
- <p class="alert">!!</p>
- <h3>', empty($securityFiles) ? $txt['generic_warning'] : $txt['security_risk'], '</h3>
- <p>';
- foreach ($securityFiles as $securityFile)
- {
- echo '
- ', $txt['not_removed'], '<strong>', $securityFile, '</strong>!<br />';
- if ($securityFile == 'Settings.php~' || $securityFile == 'Settings_bak.php~')
- echo '
- ', sprintf($txt['not_removed_extra'], $securityFile, substr($securityFile, 0, -1)), '<br />';
- }
- if (!empty($modSettings['cache_enable']) && !is_writable($cachedir))
- echo '
- <strong>', $txt['cache_writable'], '</strong><br />';
- if (!empty($agreement))
- echo '
- <strong>', $txt['agreement_missing'], '</strong><br />';
- echo '
- </p>
- </div>';
- }
- }
-
- elseif (in_array($layer, array('main', 'body')) && isset($_SESSION['ban']['cannot_post']) && !$showed_banned)
- {
- $showed_banned = true;
- echo '
- <div class="windowbg alert" style="margin: 2ex; padding: 2ex; border: 2px dashed red;">
- ', sprintf($txt['you_are_post_banned'], $user_info['is_guest'] ? $txt['guest_title'] : $user_info['name']);
- if (!empty($_SESSION['ban']['cannot_post']['reason']))
- echo '
- <div style="padding-left: 4ex; padding-top: 1ex;">', $_SESSION['ban']['cannot_post']['reason'], '</div>';
- if (!empty($_SESSION['ban']['expire_time']))
- echo '
- <div>', sprintf($txt['your_ban_expires'], timeformat($_SESSION['ban']['expire_time'], false)), '</div>';
- else
- echo '
- <div>', $txt['your_ban_expires_never'], '</div>';
- echo '
- </div>';
- }
- }
- if (isset($settings['use_default_images']) && $settings['use_default_images'] == 'defaults' && isset($settings['default_template']))
- {
- $settings['theme_url'] = $settings['default_theme_url'];
- $settings['images_url'] = $settings['default_images_url'];
- $settings['theme_dir'] = $settings['default_theme_dir'];
- }
- }
- function theme_copyright()
- {
- global $forum_copyright, $software_year, $forum_version;
-
- if (!isset($forum_version) || !isset($software_year))
- return;
-
- $forum_copyright = sprintf($forum_copyright, $forum_version, $software_year);
- echo '
- <span class="smalltext" style="display: inline; visibility: visible; font-family: Verdana, Arial, sans-serif;">' . $forum_copyright . '
- </span>';
- }
- function template_footer()
- {
- global $context, $settings, $modSettings, $time_start, $db_count;
-
- $context['show_load_time'] = !empty($modSettings['timeLoadPageEnable']);
- $context['load_time'] = round(array_sum(explode(' ', microtime())) - array_sum(explode(' ', $time_start)), 3);
- $context['load_queries'] = $db_count;
- if (isset($settings['use_default_images']) && $settings['use_default_images'] == 'defaults' && isset($settings['default_template']))
- {
- $settings['theme_url'] = $settings['actual_theme_url'];
- $settings['images_url'] = $settings['actual_images_url'];
- $settings['theme_dir'] = $settings['actual_theme_dir'];
- }
- foreach (array_reverse($context['template_layers']) as $layer)
- loadSubTemplate($layer . '_below', true);
- }
- function template_javascript($do_defered = false)
- {
- global $context, $modSettings, $settings;
-
- call_integration_hook('integrate_pre_javascript_output');
-
- if (!empty($context['javascript_vars']) && !$do_defered)
- {
- echo '
- <script><!-- // --><![CDATA[';
- foreach ($context['javascript_vars'] as $key => $value)
- {
- if (empty($value))
- {
- echo '
- var ', $key, ';';
- }
- else
- {
- echo '
- var ', $key, ' = ', $value, ';';
- }
- }
- echo '
- // ]]></script>';
- }
-
- foreach ($context['javascript_files'] as $id => $js_file)
- {
- if ((!$do_defered && empty($js_file['options']['defer'])) || ($do_defered && !empty($js_file['options']['defer'])))
- echo '
- <script src="', $js_file['filename'], '"', !empty($js_file['options']['async']) ? ' async="async"' : '', '></script>';
-
- if ($id == 'jquery' && (!isset($modSettings['jquery_source']) || !in_array($modSettings['jquery_source'], array('local', 'cdn'))))
- echo '
- <script><!-- // --><![CDATA[
- window.jQuery || document.write(\'<script src="' . $settings['default_theme_url'] . '/scripts/jquery-1.7.1.min.js"><\/script>\');
- // ]]></script>';
- }
-
- if (!empty($context['javascript_inline']))
- {
- if (!empty($context['javascript_inline']['defer']) && $do_defered)
- {
- echo '
- <script><!-- // --><![CDATA[';
- foreach ($context['javascript_inline']['defer'] as $js_code)
- echo $js_code;
- echo '
- // ]]></script>';
- }
- if (!empty($context['javascript_inline']['standard']) && !$do_defered)
- {
- echo '
- <script><!-- // --><![CDATA[';
- foreach ($context['javascript_inline']['standard'] as $js_code)
- echo $js_code;
- echo '
- // ]]></script>';
- }
- }
- }
- function template_css()
- {
- global $context;
-
- call_integration_hook('integrate_pre_css_output');
- foreach ($context['css_files'] as $id => $file)
- echo '
- <link rel="stylesheet" type="text/css" href="', $file['filename'], '" />';
- }
- function getAttachmentFilename($filename, $attachment_id, $dir = null, $new = false, $file_hash = '')
- {
- global $modSettings, $smcFunc;
-
- if ($new)
- return sha1(md5($filename . time()) . mt_rand());
-
-
- if ($file_hash === '')
- {
- $request = $smcFunc['db_query']('', '
- SELECT file_hash
- FROM {db_prefix}attachments
- WHERE id_attach = {int:id_attach}',
- array(
- 'id_attach' => $attachment_id,
- ));
- if ($smcFunc['db_num_rows']($request) === 0)
- return false;
- list ($file_hash) = $smcFunc['db_fetch_row']($request);
- $smcFunc['db_free_result']($request);
- }
-
- if (empty($file_hash))
- $file_hash = sha1(md5($filename . time()) . mt_rand());
-
- if (!empty($modSettings['currentAttachmentUploadDir']))
- {
- if (!is_array($modSettings['attachmentUploadDir']))
- $modSettings['attachmentUploadDir'] = unserialize($modSettings['attachmentUploadDir']);
- $path = $modSettings['attachmentUploadDir'][$dir];
- }
- else
- $path = $modSettings['attachmentUploadDir'];
- return $path . '/' . $attachment_id . '_' . $file_hash .'.dat';
- }
- function ip2range($fullip)
- {
-
- if (isValidIPv6($fullip) !== false)
- {
- $ip_parts = explode(':', expandIPv6($fullip, false));
- $ip_array = array();
- if (count($ip_parts) != 8)
- return array();
- for ($i = 0; $i < 8; $i++)
- {
- if ($ip_parts[$i] == '*')
- $ip_array[$i] = array('low' => '0', 'high' => hexdec('ffff'));
- elseif (preg_match('/^([0-9A-Fa-f]{1,4})\-([0-9A-Fa-f]{1,4})$/', $ip_parts[$i], $range) == 1)
- $ip_array[$i] = array('low' => hexdec($range[1]), 'high' => hexdec($range[2]));
- elseif (is_numeric(hexdec($ip_parts[$i])))
- $ip_array[$i] = array('low' => hexdec($ip_parts[$i]), 'high' => hexdec($ip_parts[$i]));
- }
- return $ip_array;
- }
-
- if ($fullip == 'unknown')
- $fullip = '255.255.255.255';
- $ip_parts = explode('.', $fullip);
- $ip_array = array();
- if (count($ip_parts) != 4)
- return array();
- for ($i = 0; $i < 4; $i++)
- {
- if ($ip_parts[$i] == '*')
- $ip_array[$i] = array('low' => '0', 'high' => '255');
- elseif (preg_match('/^(\d{1,3})\-(\d{1,3})$/', $ip_parts[$i], $range) == 1)
- $ip_array[$i] = array('low' => $range[1], 'high' => $range[2]);
- elseif (is_numeric($ip_parts[$i]))
- $ip_array[$i] = array('low' => $ip_parts[$i], 'high' => $ip_parts[$i]);
- }
-
- $ip_array[4] = array('low' => 0, 'high' => 0);
- $ip_array[5] = array('low' => 0, 'high' => 0);
- $ip_array[6] = array('low' => 0, 'high' => 0);
- $ip_array[7] = array('low' => 0, 'high' => 0);
- return $ip_array;
- }
- function host_from_ip($ip)
- {
- global $modSettings;
- if (($host = cache_get_data('hostlookup-' . $ip, 600)) !== null)
- return $host;
- $t = microtime();
-
- if (!isset($host) && (strpos(strtolower(PHP_OS), 'win') === false || strpos(strtolower(PHP_OS), 'darwin') !== false) && mt_rand(0, 1) == 1)
- {
- if (!isset($modSettings['host_to_dis']))
- $test = @shell_exec('host -W 1 ' . @escapeshellarg($ip));
- else
- $test = @shell_exec('host ' . @escapeshellarg($ip));
-
- if (strpos($test, 'not found') !== false)
- $host = '';
-
- elseif ((strpos($test, 'invalid option') || strpos($test, 'Invalid query name 1')) && !isset($modSettings['host_to_dis']))
- updateSettings(array('host_to_dis' => 1));
-
- elseif (preg_match('~\s([^\s]+?)\.\s~', $test, $match) == 1)
- $host = $match[1];
- }
-
- if (!isset($host) && stripos(PHP_OS, 'win') !== false && strpos(strtolower(PHP_OS), 'darwin') === false && mt_rand(0, 1) == 1)
- {
- $test = @shell_exec('nslookup -timeout=1 ' . @escapeshellarg($ip));
- if (strpos($test, 'Non-existent domain') !== false)
- $host = '';
- elseif (preg_match('~Name:\s+([^\s]+)~', $test, $match) == 1)
- $host = $match[1];
- }
-
- if (!isset($host) || $host === false)
- $host = @gethostbyaddr($ip);
-
- if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.5)
- cache_put_data('hostlookup-' . $ip, $host, 600);
- return $host;
- }
- function text2words($text, $max_chars = 20, $encrypt = false)
- {
- global $smcFunc, $context;
-
- $words = preg_replace('~(?:[\x0B\0' . ($context['utf8'] ? '\x{A0}' : '\xA0') . '\t\r\s\n(){}\\[\\]<>!@$%^*.,:+=`\~\?/\\\\]+|&(?:amp|lt|gt|quot);)+~' . ($context['utf8'] ? 'u' : ''), ' ', strtr($text, array('<br />' => ' ')));
-
- $words = un_htmlspecialchars($smcFunc['strtolower']($words));
-
- $words = explode(' ', $words);
- if ($encrypt)
- {
- $possible_chars = array_flip(array_merge(range(46, 57), range(65, 90), range(97, 122)));
- $returned_ints = array();
- foreach ($words as $word)
- {
- if (($word = trim($word, '-_\'')) !== '')
- {
- $encrypted = substr(crypt($word, 'uk'), 2, $max_chars);
- $total = 0;
- for ($i = 0; $i < $max_chars; $i++)
- $total += $possible_chars[ord($encrypted{$i})] * pow(63, $i);
- $returned_ints[] = $max_chars == 4 ? min($total, 16777215) : $total;
- }
- }
- return array_unique($returned_ints);
- }
- else
- {
-
- $returned_words = array();
- foreach ($words as $word)
- if (($word = trim($word, '-_\'')) !== '')
- $returned_words[] = $max_chars === null ? $word : substr($word, 0, $max_chars);
-
- return array_unique($returned_words);
- }
- }
- function create_button($name, $alt, $label = '', $custom = '', $force_use = false)
- {
- global $settings, $txt, $context;
-
- if (function_exists('template_create_button') && !$force_use)
- return template_create_button($name, $alt, $label = '', $custom = '');
- if (!$settings['use_image_buttons'])
- return $txt[$alt];
- elseif (!empty($settings['use_buttons']))
- return '<img src="' . $settings['images_url'] . '/buttons/' . $name . '" alt="' . $txt[$alt] . '" ' . $custom . ' />' . ($label != '' ? ' <strong>' . $txt[$label] . '</strong>' : '');
- else
- return '<img src="' . $settings['lang_images_url'] . '/' . $name . '" alt="' . $txt[$alt] . '" ' . $custom . ' />';
- }
- function clean_cache($type = '')
- {
- global $cachedir, $sourcedir, $cache_accelerator, $modSettings, $memcached;
- switch ($cache_accelerator)
- {
- case 'memcached':
- if (function_exists('memcache_flush') || function_exists('memcached_flush') && isset($modSettings['cache_memcached']) && trim($modSettings['cache_memcached']) != '')
- {
-
- if (empty($memcached))
- get_memcached_server();
- if (!$memcached)
- return;
-
- if (function_exists('memcache_flush'))
- memcache_flush($memcached);
- else
- memcached_flush($memcached);
- }
- break;
- case 'apc':
- if (function_exists('apc_clear_cache'))
- {
-
- if ($type === '' || $type === 'data')
- {
- apc_clear_cache('user');
- apc_clear_cache('system');
- }
- elseif ($type === 'user')
- apc_clear_cache('user');
- }
- break;
- case 'zend':
- if (function_exists('zend_shm_cache_clear'))
- zend_shm_cache_clear('SMF');
- break;
- case 'xcache':
- if (function_exists('xcache_clear_cache'))
- {
-
- if ($type === '')
- {
- xcache_clear_cache(XC_TYPE_VAR, 0);
- xcache_clear_cache(XC_TYPE_PHP, 0);
- }
- if ($type === 'user')
- xcache_clear_cache(XC_TYPE_VAR, 0);
- if ($type === 'data')
- xcache_clear_cache(XC_TYPE_PHP, 0);
- }
- break;
- default:
-
- if (!is_dir($cachedir))
- return;
-
- $dh = opendir($cachedir);
- while ($file = readdir($dh))
- {
- if ($file != '.' && $file != '..' && $file != 'index.php' && $file != '.htaccess' && (!$type || substr($file, 0, strlen($type)) == $type))
- @unlink($cachedir . '/' . $file);
- }
- closedir($dh);
- break;
- }
-
-
- @touch($sourcedir . '/' . 'Load.php');
- call_integration_hook('integrate_clean_cache');
- clearstatcache();
- }
- function loadClassFile($filename)
- {
- global $sourcedir;
- if (!file_exists($sourcedir . '/' . $filename))
- fatal_lang_error('error_bad_file', 'general', array($sourcedir . '/' . $filename));
- require_once($sourcedir . '/' . $filename);
- }
- function setupMenuContext()
- {
- global $context, $modSettings, $user_info, $txt, $scripturl;
-
- $context['allow_search'] = !empty($modSettings['allow_guestAccess']) ? allowedTo('search_posts') : (!$user_info['is_guest'] && allowedTo('search_posts'));
- $context['allow_admin'] = allowedTo(array('admin_forum', 'manage_boards', 'manage_permissions', 'moderate_forum', 'manage_membergroups', 'manage_bans', 'send_mail', 'edit_news', 'manage_attachments', 'manage_smileys'));
- $context['allow_memberlist'] = allowedTo('view_mlist');
- $context['allow_calendar'] = allowedTo('calendar_view') && !empty($modSettings['cal_enabled']);
- $context['allow_moderation_center'] = $context['user']['can_mod'];
- $context['allow_pm'] = allowedTo('pm_read');
- $cacheTime = $modSettings['lastActive'] * 60;
-
- if (!$context['user']['is_guest'])
- {
- addInlineJavascript('
- var user_menus = new smc_PopupMenu();
- user_menus.add("profile", "' . $scripturl . '?action=profile;area=popup");
- user_menus.add("alerts", "' . $scripturl . '?action=profile;area=alerts_popup");', true);
- if ($context['allow_pm'])
- addInlineJavascript('
- user_menus.add("pm", "' . $scripturl . '?action=pm;sa=popup");', true);
- }
-
- if (($menu_buttons = cache_get_data('menu_buttons-' . implode('_', $user_info['groups']) . '-' . $user_info['language'], $cacheTime)) === null || time() - $cacheTime <= $modSettings['settings_updated'])
- {
- $buttons = array(
- 'home' => array(
- 'title' => $txt['home'],
- 'href' => $scripturl,
- 'show' => true,
- 'sub_buttons' => array(
- ),
- 'is_last' => $context['right_to_left'],
- ),
- 'help' => array(
- 'title' => $txt['help'],
- 'href' => $scripturl . '?action=help',
- 'show' => true,
- 'sub_buttons' => array(
- ),
- ),
- 'search' => array(
- 'title' => $txt['search'],
- 'href' => $scripturl . '?action=search',
- 'show' => $context['allow_search'],
- 'sub_buttons' => array(
- ),
- ),
- 'admin' => array(
- 'title' => $txt['admin'],
- 'href' => $scripturl . '?action=admin',
- 'show' => $context['allow_admin'],
- 'sub_buttons' => array(
- 'featuresettings' => array(
- 'title' => $txt['modSettings_title'],
- 'href' => $scripturl . '?action=admin;area=featuresettings',
- 'show' => allowedTo('admin_forum'),
- ),
- 'packages' => array(
- 'title' => $txt['package'],
- 'href' => $scripturl . '?action=admin;area=packages',
- 'show' => allowedTo('admin_forum'),
- ),
- 'errorlog' => array(
- 'title' => $txt['errlog'],
- 'href' => $scripturl . '?action=admin;area=logs;sa=errorlog;desc',
- 'show' => allowedTo('admin_forum') && !empty($modSettings['enableErrorLogging']),
- ),
- 'permissions' => array(
- 'title' => $txt['edit_permissions'],
- 'href' => $scripturl . '?action=admin;area=permissions',
- 'show' => allowedTo('manage_permissions'),
- ),
- 'memberapprove' => array(
- 'title' => $txt['approve_members_waiting'],
- 'href' => $scripturl . '?action=admin;area=viewmembers;sa=browse;type=approve',
- 'show' => !empty($context['unapproved_members']),
- 'is_last' => true,
- ),
- ),
- ),
- 'moderate' => array(
- 'title' => $txt['moderate'],
- 'href' => $scripturl . '?action=moderate',
- 'show' => $context['allow_moderation_center'],
- 'sub_buttons' => array(
- 'modlog' => array(
- 'title' => $txt['modlog_view'],
- 'href' => $scripturl . '?action=moderate;area=modlog',
- 'show' => !empty($modSettings['modlog_enabled']) && !empty($user_info['mod_cache']) && $user_info['mod_cache']['bq'] != '0=1',
- ),
- 'poststopics' => array(
- 'title' => $txt['mc_unapproved_poststopics'],
- 'href' => $scripturl . '?action=moderate;area=postmod;sa=posts',
- 'show' => $modSettings['postmod_active'] && !empty($user_info['mod_cache']['ap']),
- ),
- 'attachments' => array(
- 'title' => $txt['mc_unapproved_attachments'],
- 'href' => $scripturl . '?action=moderate;area=attachmod;sa=attachments',
- 'show' => $modSettings['postmod_active'] && !empty($user_info['mod_cache']['ap']),
- ),
- 'reports' => array(
- 'title' => $txt['mc_reported_posts'],
- 'href' => $scripturl . '?action=moderate;area=reports',
- 'show' => !empty($user_info['mod_cache']) && $user_info['mod_cache']['bq'] != '0=1',
- 'is_last' => true,
- ),
- ),
- ),
- 'calendar' => array(
- 'title' => $txt['calendar'],
- 'href' => $scripturl . '?action=calendar',
- 'show' => $context['allow_calendar'],
- 'sub_buttons' => array(
- 'view' => array(
- 'title' => $txt['calendar_menu'],
- 'href' => $scripturl . '?action=calendar',
- 'show' => allowedTo('calendar_post'),
- ),
- 'post' => array(
- 'title' => $txt['calendar_post_event'],
- 'href' => $scripturl . '?action=calendar;sa=post',
- 'show' => allowedTo('calendar_post'),
- 'is_last' => true,
- ),
- ),
- ),
- 'mlist' => array(
- 'title' => $txt['members_title'],
- 'href' => $scripturl . '?action=mlist',
- 'show' => $context['allow_memberlist'],
- 'sub_buttons' => array(
- 'mlist_view' => array(
- 'title' => $txt['mlist_menu_view'],
- 'href' => $scripturl . '?action=mlist',
- 'show' => true,
- ),
- 'mlist_search' => array(
- 'title' => $txt['mlist_search'],
- 'href' => $scripturl . '?action=mlist;sa=search',
- 'show' => true,
- 'is_last' => true,
- ),
- ),
- ),
- 'login' => array(
- 'title' => $txt['login'],
- 'href' => $scripturl . '?action=login',
- 'show' => $user_info['is_guest'],
- 'sub_buttons' => array(
- ),
- ),
- 'register' => array(
- 'title' => $txt['register'],
- 'href' => $scripturl . '?action=register',
- 'show' => $user_info['is_guest'] && $context['can_register'],
- 'sub_buttons' => array(
- ),
- 'is_last' => !$context['right_to_left'],
- ),
- 'logout' => array(
- 'title' => $txt['logout'],
- 'href' => $scripturl . '?action=logout;%1$s=%2$s',
- 'show' => !$user_info['is_guest'],
- 'sub_buttons' => array(
- ),
- 'is_last' => !$context['right_to_left'],
- ),
- );
-
- call_integration_hook('integrate_menu_buttons', array(&$buttons));
-
- $menu_buttons = array();
- foreach ($buttons as $act => $button)
- if (!empty($button['show']))
- {
- $button['active_button'] = false;
-
- if (isset($button['action_hook']))
- $needs_action_hook = true;
-
- if (!empty($button['is_last']))
- {
- if (isset($last_button))
- unset($menu_buttons[$last_button]['is_last']);
- $last_button = $act;
- }
-
- if (!empty($button['sub_buttons']))
- foreach ($button['sub_buttons'] as $key => $subbutton)
- {
- if (empty($subbutton['show']))
- unset($button['sub_buttons'][$key]);
-
- if (!empty($subbutton['sub_buttons']))
- {
- foreach ($subbutton['sub_buttons'] as $key2 => $sub_button2)
- {
- if (empty($sub_button2['show']))
- unset($button['sub_buttons'][$key]['sub_buttons'][$key2]);
- }
- }
- }
- $menu_buttons[$act] = $button;
- }
- if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
- cache_put_data('menu_buttons-' . implode('_', $user_info['groups']) . '-' . $user_info['language'], $menu_buttons, $cacheTime);
- }
- $context['menu_buttons'] = $menu_buttons;
-
- if (isset($context['menu_buttons']['logout']))
- $context['menu_buttons']['logout']['href'] = sprintf($context['menu_buttons']['logout']['href'], $context['session_var'], $context['session_id']);
-
-
- $current_action = 'home';
- if (isset($context['menu_buttons'][$context['current_action']]))
- $current_action = $context['current_action'];
- elseif ($context['current_action'] == 'search2')
- $current_action = 'search';
- elseif ($context['current_action'] == 'theme')
- $current_action = isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'pick' ? 'profile' : 'admin';
- elseif ($context['current_action'] == 'register2')
- $current_action = 'register';
- elseif ($context['current_action'] == 'login2' || ($user_info['is_guest'] && $context['current_action'] == 'reminder'))
- $current_action = 'login';
- elseif ($context['current_action'] == 'groups' && $context['allow_moderation_center'])
- $current_action = 'moderate';
-
- if ($context['current_action'] == 'profile' && !empty($context['user']['is_owner']))
- {
- $current_action = !empty($_GET['area']) && $_GET['area'] == 'alerts_popup' ? 'self_alerts' : 'self_profile';
- $context[$current_action] = true;
- }
- elseif ($context['current_action'] == 'pm')
- {
- $current_action = 'self_pm';
- $context['self_pm'] = true;
- }
-
- if (!empty($needs_action_hook))
- call_integration_hook('integrate_current_action', array(&$current_action));
- if (isset($context['menu_buttons'][$current_action]))
- $context['menu_buttons'][$current_action]['active_button'] = true;
- if (!empty($user_info['mod_cache']) && $user_info['mod_cache']['bq'] != '0=1' && $context['open_mod_reports'] > 0)
- {
- $context['menu_buttons']['moderate']['title'] .= ' <span class="amt">' . $context['open_mod_reports'] . '</span>';
- $context['menu_buttons']['moderate']['sub_buttons']['reports']['title'] .= ' <span class="amt">' . $context['open_mod_reports'] . '</span>';
- }
- if (!empty($context['unapproved_members']))
- {
- $context['menu_buttons']['admin']['sub_buttons']['memberapprove']['title'] .= ' <span class="amt">' . $context['unapproved_members'] . '</span>';
- $context['menu_buttons']['admin']['title'] .= ' <span class="amt">' . $context['unapproved_members'] . '</span>';
- }
- }
- function smf_seed_generator()
- {
- global $modSettings;
-
- if (empty($modSettings['rand_seed']))
- {
- $modSettings['rand_seed'] = microtime() * 1000000;
- updateSettings(array('rand_seed' => $modSettings['rand_seed']));
- }
-
- updateSettings(array('rand_seed' => mt_rand()));
- }
- function call_integration_hook($hook, $parameters = array())
- {
- global $modSettings, $settings, $boarddir, $sourcedir, $db_show_debug;
- global $context, $txt;
- if ($db_show_debug === true)
- $context['debug']['hooks'][] = $hook;
-
- if (!isset($context['instances']))
- $context['instances'] = array();
- loadLanguage('Errors');
- $results = array();
- if (empty($modSettings[$hook]))
- return $results;
- $functions = explode(',', $modSettings[$hook]);
-
- foreach ($functions as $function)
- {
- $function = trim($function);
-
- if (strpos($function, '::') !== false)
- {
- $call = explode('::', $function);
-
- if (strpos($call[1], ':') !== false)
- {
- list($func, $file) = explode(':', $call[1]);
-
- if (strpos($file, '#') !== false)
- $file = str_replace('#', '', $file);
-
- if (empty($settings['theme_dir']))
- $absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir));
- else
- $absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir']));
-
- if (file_exists($absPath))
- require_once($absPath);
-
- else
- log_error(sprintf($txt['hook_fail_loading_file'], $absPath), 'general');
-
- if (strpos($call[1], '#') !== false)
- {
-
- if (empty($context['instances'][$call[0]]) || !($context['instances'][$call[0]] instanceof $call[0]))
- {
- $context['instances'][$call[0]] = new $call[0];
-
- if ($db_show_debug === true)
- $context['debug']['instances'][$call[0]] = $hook;
- }
- $call = array($context['instances'][$call[0]], $func);
- }
-
- else
- $call = array($call[0], $func);
- }
- }
- else
- {
- $call = $function;
- if (strpos($function, ':') !== false)
- {
- list($func, $file) = explode(':', $function);
- if (empty($settings['theme_dir']))
- $absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir));
- else
- $absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir']));
- if (file_exists($absPath))
- require_once($absPath);
- $call = $func;
- }
- }
-
- if (is_callable($call))
- $results[$function] = call_user_func_array($call, $parameters);
-
- elseif (!empty($func) && !empty($absPath))
- log_error(sprintf($txt['hook_fail_call_to'], $func, $absPath), 'general');
- }
- return $results;
- }
- function add_integration_function($hook, $function, $file = '', $object = false, $permanent = true)
- {
- global $smcFunc, $modSettings;
- $integration_call = (!empty($file) && $file !== true) ? ($function . ':' . $file . ($object ? '#' : '')) : $function;
-
- if ($permanent)
- {
- $request = $smcFunc['db_query']('', '
- SELECT value
- FROM {db_prefix}settings
- WHERE variable = {string:variable}',
- array(
- 'variable' => $hook,
- )
- );
- list($current_functions) = $smcFunc['db_fetch_row']($request);
- $smcFunc['db_free_result']($request);
- if (!empty($current_functions))
- {
- $current_functions = explode(',', $current_functions);
- if (in_array($integration_call, $current_functions))
- return;
- $permanent_functions = array_merge($current_functions, array($integration_call));
- }
- else
- $permanent_functions = array($integration_call);
- updateSettings(array($hook => implode(',', $permanent_functions)));
- }
-
- $functions = empty($modSettings[$hook]) ? array() : explode(',', $modSettings[$hook]);
-
- if (in_array($integration_call, $functions))
- return;
- $functions[] = $integration_call;
- $modSettings[$hook] = implode(',', $functions);
- }
- function remove_integration_function($hook, $function, $file = '', $object = false)
- {
- global $smcFunc, $modSettings;
- $integration_call = (!empty($file)) ? $function . ':' . $file .($object ? '#' : '') : $function;
-
- $request = $smcFunc['db_query']('', '
- SELECT value
- FROM {db_prefix}settings
- WHERE variable = {string:variable}',
- array(
- 'variable' => $hook,
- )
- );
- list($current_functions) = $smcFunc['db_fetch_row']($request);
- $smcFunc['db_free_result']($request);
- if (!empty($current_functions))
- {
- $current_functions = explode(',', $current_functions);
- if (in_array($integration_call, $current_functions))
- updateSettings(array($hook => implode(',', array_diff($current_functions, array($integration_call)))));
- }
-
- $functions = empty($modSettings[$hook]) ? array() : explode(',', $modSettings[$hook]);
-
- if (!in_array($integration_call, $functions))
- return;
- $functions = array_diff($functions, array($integration_call));
- $modSettings[$hook] = implode(',', $functions);
- }
- function sanitizeMSCutPaste($string)
- {
- global $context;
- if (empty($string))
- return $string;
-
- $findchars_utf8 = array(
- "\xe2\80\x9a",
- "\xe2\80\x9e",
- "\xe2\80\xa6",
- "\xe2\x80\x98",
- "\xe2\x80\x99",
- "\xe2\x80\x9c",
- "\xe2\x80\x9d",
- "\xe2\x80\x93",
- "\xe2\x80\x94",
- );
-
- $findchars_iso = array(
- chr(130),
- chr(132),
- chr(133),
- chr(145),
- chr(146),
- chr(147),
- chr(148),
- chr(150),
- chr(151),
- );
-
- $replacechars = array(
- ',',
- ',,',
- '...',
- "'",
- "'",
- '"',
- '"',
- '-',
- '--',
- );
- if ($context['utf8'])
- $string = str_replace($findchars_utf8, $replacechars, $string);
- else
- $string = str_replace($findchars_iso, $replacechars, $string);
- return $string;
- }
- function replaceEntities__callback($matches)
- {
- global $context;
- if (!isset($matches[2]))
- return '';
- $num = $matches[2][0] === 'x' ? hexdec(substr($matches[2], 1)) : (int) $matches[2];
-
- if ($num === 0x202D || $num === 0x202E)
- return '';
-
- if (in_array($num, array(0x22, 0x26, 0x27, 0x3C, 0x3E)))
- return '&#' . $num . ';';
- if (empty($context['utf8']))
- {
-
- if ($num < 0x20)
- return '';
-
- elseif ($num < 0x80)
- return chr($num);
-
- else
- return '&#' . $matches[2] . ';';
- }
- else
- {
-
-
- if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF))
- return '';
-
- elseif ($num < 0x80)
- return chr($num);
-
- elseif ($num < 0x800)
- return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
-
- elseif ($num < 0x10000)
- return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
-
- else
- return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
- }
- }
- function fixchar__callback($matches)
- {
- if (!isset($matches[1]))
- return '';
- $num = $matches[1][0] === 'x' ? hexdec(substr($matches[1], 1)) : (int) $matches[1];
-
-
- if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num === 0x202D || $num === 0x202E)
- return '';
-
- elseif ($num < 0x80)
- return chr($num);
-
- elseif ($num < 0x800)
- return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
-
- elseif ($num < 0x10000)
- return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
-
- else
- return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
- }
- function entity_fix__callback($matches)
- {
- if (!isset($matches[2]))
- return '';
- $num = $matches[2][0] === 'x' ? hexdec(substr($matches[2], 1)) : (int) $matches[2];
-
- if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num == 0x202D || $num == 0x202E)
- return '';
- else
- return '&#' . $num . ';';
- }
- ?>
|