Profile-Modify.php 126 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782
  1. <?php
  2. /**
  3. * This file has the primary job of showing and editing people's profiles.
  4. * It also allows the user to change some of their or another's preferences,
  5. * and such things
  6. *
  7. * Simple Machines Forum (SMF)
  8. *
  9. * @package SMF
  10. * @author Simple Machines http://www.simplemachines.org
  11. * @copyright 2014 Simple Machines and individual contributors
  12. * @license http://www.simplemachines.org/about/smf/license.php BSD
  13. *
  14. * @version 2.1 Alpha 1
  15. */
  16. if (!defined('SMF'))
  17. die('No direct access...');
  18. /**
  19. * This defines every profile field known to man.
  20. *
  21. * @param bool $force_reload = false
  22. */
  23. function loadProfileFields($force_reload = false)
  24. {
  25. global $context, $profile_fields, $txt, $scripturl, $modSettings, $user_info, $old_profile, $smcFunc, $cur_profile, $language;
  26. // Don't load this twice!
  27. if (!empty($profile_fields) && !$force_reload)
  28. return;
  29. /* This horrific array defines all the profile fields in the whole world!
  30. In general each "field" has one array - the key of which is the database column name associated with said field. Each item
  31. can have the following attributes:
  32. string $type: The type of field this is - valid types are:
  33. - callback: This is a field which has its own callback mechanism for templating.
  34. - check: A simple checkbox.
  35. - hidden: This doesn't have any visual aspects but may have some validity.
  36. - password: A password box.
  37. - select: A select box.
  38. - text: A string of some description.
  39. string $label: The label for this item - default will be $txt[$key] if this isn't set.
  40. string $subtext: The subtext (Small label) for this item.
  41. int $size: Optional size for a text area.
  42. array $input_attr: An array of text strings to be added to the input box for this item.
  43. string $value: The value of the item. If not set $cur_profile[$key] is assumed.
  44. string $permission: Permission required for this item (Excluded _any/_own subfix which is applied automatically).
  45. function $input_validate: A runtime function which validates the element before going to the database. It is passed
  46. the relevant $_POST element if it exists and should be treated like a reference.
  47. Return types:
  48. - true: Element can be stored.
  49. - false: Skip this element.
  50. - a text string: An error occured - this is the error message.
  51. function $preload: A function that is used to load data required for this element to be displayed. Must return
  52. true to be displayed at all.
  53. string $cast_type: If set casts the element to a certain type. Valid types (bool, int, float).
  54. string $save_key: If the index of this element isn't the database column name it can be overriden
  55. with this string.
  56. bool $is_dummy: If set then nothing is acted upon for this element.
  57. bool $enabled: A test to determine whether this is even available - if not is unset.
  58. string $link_with: Key which links this field to an overall set.
  59. Note that all elements that have a custom input_validate must ensure they set the value of $cur_profile correct to enable
  60. the changes to be displayed correctly on submit of the form.
  61. */
  62. $profile_fields = array(
  63. 'aim' => array(
  64. 'type' => 'text',
  65. 'label' => $txt['aim'],
  66. 'subtext' => $txt['your_aim'],
  67. 'size' => 24,
  68. 'value' => strtr(empty($cur_profile['aim']) ? '' : $cur_profile['aim'], '+', ' '),
  69. 'permission' => 'profile_extra',
  70. 'input_validate' => create_function('&$value', '
  71. $value = strtr($value, \' \', \'+\');
  72. if (strlen($value) > 32)
  73. return \'aim_too_long\';
  74. return true;
  75. '),
  76. ),
  77. 'avatar_choice' => array(
  78. 'type' => 'callback',
  79. 'callback_func' => 'avatar_select',
  80. // This handles the permissions too.
  81. 'preload' => 'profileLoadAvatarData',
  82. 'input_validate' => 'profileSaveAvatarData',
  83. 'save_key' => 'avatar',
  84. ),
  85. 'bday1' => array(
  86. 'type' => 'callback',
  87. 'callback_func' => 'birthdate',
  88. 'permission' => 'profile_extra',
  89. 'preload' => create_function('', '
  90. global $cur_profile, $context;
  91. // Split up the birthdate....
  92. list ($uyear, $umonth, $uday) = explode(\'-\', empty($cur_profile[\'birthdate\']) || $cur_profile[\'birthdate\'] == \'0001-01-01\' ? \'0000-00-00\' : $cur_profile[\'birthdate\']);
  93. $context[\'member\'][\'birth_date\'] = array(
  94. \'year\' => $uyear == \'0004\' ? \'0000\' : $uyear,
  95. \'month\' => $umonth,
  96. \'day\' => $uday,
  97. );
  98. return true;
  99. '),
  100. 'input_validate' => create_function('&$value', '
  101. global $profile_vars, $cur_profile;
  102. if (isset($_POST[\'bday2\'], $_POST[\'bday3\']) && $value > 0 && $_POST[\'bday2\'] > 0)
  103. {
  104. // Set to blank?
  105. if ((int) $_POST[\'bday3\'] == 1 && (int) $_POST[\'bday2\'] == 1 && (int) $value == 1)
  106. $value = \'0001-01-01\';
  107. else
  108. $value = checkdate($value, $_POST[\'bday2\'], $_POST[\'bday3\'] < 4 ? 4 : $_POST[\'bday3\']) ? sprintf(\'%04d-%02d-%02d\', $_POST[\'bday3\'] < 4 ? 4 : $_POST[\'bday3\'], $_POST[\'bday1\'], $_POST[\'bday2\']) : \'0001-01-01\';
  109. }
  110. else
  111. $value = \'0001-01-01\';
  112. $profile_vars[\'birthdate\'] = $value;
  113. $cur_profile[\'birthdate\'] = $value;
  114. return false;
  115. '),
  116. ),
  117. // Setting the birthdate the old style way?
  118. 'birthdate' => array(
  119. 'type' => 'hidden',
  120. 'permission' => 'profile_extra',
  121. 'input_validate' => create_function('&$value', '
  122. global $cur_profile;
  123. // @todo Should we check for this year and tell them they made a mistake :P? (based on coppa at least?)
  124. if (preg_match(\'/(\d{4})[\-\., ](\d{2})[\-\., ](\d{2})/\', $value, $dates) === 1)
  125. {
  126. $value = checkdate($dates[2], $dates[3], $dates[1] < 4 ? 4 : $dates[1]) ? sprintf(\'%04d-%02d-%02d\', $dates[1] < 4 ? 4 : $dates[1], $dates[2], $dates[3]) : \'0001-01-01\';
  127. return true;
  128. }
  129. else
  130. {
  131. $value = empty($cur_profile[\'birthdate\']) ? \'0001-01-01\' : $cur_profile[\'birthdate\'];
  132. return false;
  133. }
  134. '),
  135. ),
  136. 'date_registered' => array(
  137. 'type' => 'text',
  138. 'value' => empty($cur_profile['date_registered']) ? $txt['not_applicable'] : strftime('%Y-%m-%d', $cur_profile['date_registered'] + ($user_info['time_offset'] + $modSettings['time_offset']) * 3600),
  139. 'label' => $txt['date_registered'],
  140. 'log_change' => true,
  141. 'permission' => 'moderate_forum',
  142. 'input_validate' => create_function('&$value', '
  143. global $txt, $user_info, $modSettings, $cur_profile, $context;
  144. // Bad date! Go try again - please?
  145. if (($value = strtotime($value)) === -1)
  146. {
  147. $value = $cur_profile[\'date_registered\'];
  148. return $txt[\'invalid_registration\'] . \' \' . strftime(\'%d %b %Y \' . (strpos($user_info[\'time_format\'], \'%H\') !== false ? \'%I:%M:%S %p\' : \'%H:%M:%S\'), forum_time(false));
  149. }
  150. // As long as it doesn\'t equal "N/A"...
  151. elseif ($value != $txt[\'not_applicable\'] && $value != strtotime(strftime(\'%Y-%m-%d\', $cur_profile[\'date_registered\'] + ($user_info[\'time_offset\'] + $modSettings[\'time_offset\']) * 3600)))
  152. $value = $value - ($user_info[\'time_offset\'] + $modSettings[\'time_offset\']) * 3600;
  153. else
  154. $value = $cur_profile[\'date_registered\'];
  155. return true;
  156. '),
  157. ),
  158. 'email_address' => array(
  159. 'type' => 'text',
  160. 'label' => $txt['user_email_address'],
  161. 'subtext' => $txt['valid_email'],
  162. 'log_change' => true,
  163. 'permission' => 'profile_password',
  164. 'js_submit' => !empty($modSettings['send_validation_onChange']) ? '
  165. if (document.forms.creator.email_address.value != "'. $cur_profile['email_address'] .'")
  166. {
  167. alert("'. $txt['email_change_logout'] .'");
  168. return true;
  169. }' : '',
  170. 'input_validate' => create_function('&$value', '
  171. global $context, $old_profile, $profile_vars, $sourcedir, $modSettings;
  172. if (strtolower($value) == strtolower($old_profile[\'email_address\']))
  173. return false;
  174. $isValid = profileValidateEmail($value, $context[\'id_member\']);
  175. // Do they need to revalidate? If so schedule the function!
  176. if ($isValid === true && !empty($modSettings[\'send_validation_onChange\']) && !allowedTo(\'moderate_forum\'))
  177. {
  178. require_once($sourcedir . \'/Subs-Members.php\');
  179. $profile_vars[\'validation_code\'] = generateValidationCode();
  180. $profile_vars[\'is_activated\'] = 2;
  181. $context[\'profile_execute_on_save\'][] = \'profileSendActivation\';
  182. unset($context[\'profile_execute_on_save\'][\'reload_user\']);
  183. }
  184. return $isValid;
  185. '),
  186. ),
  187. 'gender' => array(
  188. 'type' => 'select',
  189. 'cast_type' => 'int',
  190. 'options' => 'return array(0 => \'\', 1 => $txt[\'male\'], 2 => $txt[\'female\']);',
  191. 'label' => $txt['gender'],
  192. 'permission' => 'profile_extra',
  193. ),
  194. 'hide_email' => array(
  195. 'type' => 'check',
  196. 'value' => empty($cur_profile['hide_email']) ? true : false,
  197. 'label' => $txt['allow_user_email'],
  198. 'permission' => 'profile_identity',
  199. 'input_validate' => create_function('&$value', '
  200. $value = $value == 0 ? 1 : 0;
  201. return true;
  202. '),
  203. ),
  204. 'icq' => array(
  205. 'type' => 'text',
  206. 'label' => $txt['icq'],
  207. 'subtext' => $txt['your_icq'],
  208. 'size' => 24,
  209. 'permission' => 'profile_extra',
  210. // Need to make sure ICQ doesn't equal 0.
  211. 'input_validate' => create_function('&$value', '
  212. if (empty($value))
  213. $value = \'\';
  214. else
  215. $value = (int) $value;
  216. return true;
  217. '),
  218. ),
  219. // Selecting group membership is a complicated one so we treat it separate!
  220. 'id_group' => array(
  221. 'type' => 'callback',
  222. 'callback_func' => 'group_manage',
  223. 'permission' => 'manage_membergroups',
  224. 'preload' => 'profileLoadGroups',
  225. 'log_change' => true,
  226. 'input_validate' => 'profileSaveGroups',
  227. ),
  228. 'id_theme' => array(
  229. 'type' => 'callback',
  230. 'callback_func' => 'theme_pick',
  231. 'permission' => 'profile_extra',
  232. 'enabled' => $modSettings['theme_allow'] || allowedTo('admin_forum'),
  233. 'preload' => create_function('', '
  234. global $smcFunc, $context, $cur_profile, $txt;
  235. $request = $smcFunc[\'db_query\'](\'\', \'
  236. SELECT value
  237. FROM {db_prefix}themes
  238. WHERE id_theme = {int:id_theme}
  239. AND variable = {string:variable}
  240. LIMIT 1\', array(
  241. \'id_theme\' => $cur_profile[\'id_theme\'],
  242. \'variable\' => \'name\',
  243. )
  244. );
  245. list ($name) = $smcFunc[\'db_fetch_row\']($request);
  246. $smcFunc[\'db_free_result\']($request);
  247. $context[\'member\'][\'theme\'] = array(
  248. \'id\' => $cur_profile[\'id_theme\'],
  249. \'name\' => empty($cur_profile[\'id_theme\']) ? $txt[\'theme_forum_default\'] : $name
  250. );
  251. return true;
  252. '),
  253. 'input_validate' => create_function('&$value', '
  254. $value = (int) $value;
  255. return true;
  256. '),
  257. ),
  258. 'karma_good' => array(
  259. 'type' => 'callback',
  260. 'callback_func' => 'karma_modify',
  261. 'permission' => 'admin_forum',
  262. // Set karma_bad too!
  263. 'input_validate' => create_function('&$value', '
  264. global $profile_vars, $cur_profile;
  265. $value = (int) $value;
  266. if (isset($_POST[\'karma_bad\']))
  267. {
  268. $profile_vars[\'karma_bad\'] = $_POST[\'karma_bad\'] != \'\' ? (int) $_POST[\'karma_bad\'] : 0;
  269. $cur_profile[\'karma_bad\'] = $_POST[\'karma_bad\'] != \'\' ? (int) $_POST[\'karma_bad\'] : 0;
  270. }
  271. return true;
  272. '),
  273. 'preload' => create_function('', '
  274. global $context, $cur_profile;
  275. $context[\'member\'][\'karma\'][\'good\'] = $cur_profile[\'karma_good\'];
  276. $context[\'member\'][\'karma\'][\'bad\'] = $cur_profile[\'karma_bad\'];
  277. return true;
  278. '),
  279. 'enabled' => !empty($modSettings['karmaMode']),
  280. ),
  281. 'lngfile' => array(
  282. 'type' => 'select',
  283. 'options' => 'return $context[\'profile_languages\'];',
  284. 'label' => $txt['preferred_language'],
  285. 'permission' => 'profile_identity',
  286. 'preload' => 'profileLoadLanguages',
  287. 'enabled' => !empty($modSettings['userLanguage']),
  288. 'value' => empty($cur_profile['lngfile']) ? $language : $cur_profile['lngfile'],
  289. 'input_validate' => create_function('&$value', '
  290. global $context, $cur_profile;
  291. // Load the languages.
  292. profileLoadLanguages();
  293. if (isset($context[\'profile_languages\'][$value]))
  294. {
  295. if ($context[\'user\'][\'is_owner\'] && empty($context[\'password_auth_failed\']))
  296. $_SESSION[\'language\'] = $value;
  297. return true;
  298. }
  299. else
  300. {
  301. $value = $cur_profile[\'lngfile\'];
  302. return false;
  303. }
  304. '),
  305. ),
  306. 'location' => array(
  307. 'type' => 'text',
  308. 'label' => $txt['location'],
  309. 'log_change' => true,
  310. 'size' => 50,
  311. 'permission' => 'profile_other',
  312. ),
  313. // The username is not always editable - so adjust it as such.
  314. 'member_name' => array(
  315. 'type' => allowedTo('admin_forum') && isset($_GET['changeusername']) ? 'text' : 'label',
  316. 'label' => $txt['username'],
  317. 'subtext' => allowedTo('admin_forum') && !isset($_GET['changeusername']) ? '[<a href="' . $scripturl . '?action=profile;u=' . $context['id_member'] . ';area=account;changeusername" style="font-style: italic;">' . $txt['username_change'] . '</a>]' : '',
  318. 'log_change' => true,
  319. 'permission' => 'profile_identity',
  320. 'prehtml' => allowedTo('admin_forum') && isset($_GET['changeusername']) ? '<div class="alert">' . $txt['username_warning'] . '</div>' : '',
  321. 'input_validate' => create_function('&$value', '
  322. global $sourcedir, $context, $user_info, $cur_profile;
  323. if (allowedTo(\'admin_forum\'))
  324. {
  325. // We\'ll need this...
  326. require_once($sourcedir . \'/Subs-Auth.php\');
  327. // Maybe they are trying to change their password as well?
  328. $resetPassword = true;
  329. if (isset($_POST[\'passwrd1\']) && $_POST[\'passwrd1\'] != \'\' && isset($_POST[\'passwrd2\']) && $_POST[\'passwrd1\'] == $_POST[\'passwrd2\'] && validatePassword($_POST[\'passwrd1\'], $value, array($cur_profile[\'real_name\'], $user_info[\'username\'], $user_info[\'name\'], $user_info[\'email\'])) == null)
  330. $resetPassword = false;
  331. // Do the reset... this will send them an email too.
  332. if ($resetPassword)
  333. resetPassword($context[\'id_member\'], $value);
  334. elseif ($value !== null)
  335. {
  336. validateUsername($context[\'id_member\'], trim(preg_replace(\'~[\t\n\r \x0B\0\' . ($context[\'utf8\'] ? \'\x{A0}\x{AD}\x{2000}-\x{200F}\x{201F}\x{202F}\x{3000}\x{FEFF}\' : \'\x00-\x08\x0B\x0C\x0E-\x19\xA0\') . \']+~\' . ($context[\'utf8\'] ? \'u\' : \'\'), \' \', $value)));
  337. updateMemberData($context[\'id_member\'], array(\'member_name\' => $value));
  338. }
  339. }
  340. return false;
  341. '),
  342. ),
  343. 'skype' => array(
  344. 'type' => 'text',
  345. 'label' => $txt['skype'],
  346. 'subtext' => $txt['skype_username'],
  347. 'size' => 24,
  348. 'permission' => 'profile_extra',
  349. ),
  350. 'passwrd1' => array(
  351. 'type' => 'password',
  352. 'label' => ucwords($txt['choose_pass']),
  353. 'subtext' => $txt['password_strength'],
  354. 'size' => 20,
  355. 'value' => '',
  356. 'enabled' => empty($cur_profile['openid_uri']),
  357. 'permission' => 'profile_password',
  358. 'save_key' => 'passwd',
  359. // Note this will only work if passwrd2 also exists!
  360. 'input_validate' => create_function('&$value', '
  361. global $sourcedir, $user_info, $smcFunc, $cur_profile;
  362. // If we didn\'t try it then ignore it!
  363. if ($value == \'\')
  364. return false;
  365. // Do the two entries for the password even match?
  366. if (!isset($_POST[\'passwrd2\']) || $value != $_POST[\'passwrd2\'])
  367. return \'bad_new_password\';
  368. // Let\'s get the validation function into play...
  369. require_once($sourcedir . \'/Subs-Auth.php\');
  370. $passwordErrors = validatePassword($value, $cur_profile[\'member_name\'], array($cur_profile[\'real_name\'], $user_info[\'username\'], $user_info[\'name\'], $user_info[\'email\']));
  371. // Were there errors?
  372. if ($passwordErrors != null)
  373. return \'password_\' . $passwordErrors;
  374. // Set up the new password variable... ready for storage.
  375. $value = sha1(strtolower($cur_profile[\'member_name\']) . un_htmlspecialchars($value));
  376. return true;
  377. '),
  378. ),
  379. 'passwrd2' => array(
  380. 'type' => 'password',
  381. 'label' => ucwords($txt['verify_pass']),
  382. 'enabled' => empty($cur_profile['openid_uri']),
  383. 'size' => 20,
  384. 'value' => '',
  385. 'permission' => 'profile_password',
  386. 'is_dummy' => true,
  387. ),
  388. 'personal_text' => array(
  389. 'type' => 'text',
  390. 'label' => $txt['personal_text'],
  391. 'log_change' => true,
  392. 'input_attr' => array('maxlength="50"'),
  393. 'size' => 50,
  394. 'permission' => 'profile_blurb',
  395. 'input_validate' => create_function('&$value', '
  396. global $smcFunc;
  397. if ($smcFunc[\'strlen\']($value) > 50)
  398. return \'personal_text_too_long\';
  399. return true;
  400. '),
  401. ),
  402. // This does ALL the pm settings
  403. 'pm_prefs' => array(
  404. 'type' => 'callback',
  405. 'callback_func' => 'pm_settings',
  406. 'permission' => 'pm_read',
  407. 'preload' => create_function('', '
  408. global $context, $cur_profile;
  409. $context[\'display_mode\'] = $cur_profile[\'pm_prefs\'] & 3;
  410. $context[\'send_email\'] = $cur_profile[\'pm_email_notify\'];
  411. $context[\'receive_from\'] = !empty($cur_profile[\'pm_receive_from\']) ? $cur_profile[\'pm_receive_from\'] : 0;
  412. return true;
  413. '),
  414. 'input_validate' => create_function('&$value', '
  415. global $cur_profile, $profile_vars;
  416. // Simple validate and apply the two "sub settings"
  417. $value = max(min($value, 2), 0);
  418. $cur_profile[\'pm_email_notify\'] = $profile_vars[\'pm_email_notify\'] = max(min((int) $_POST[\'pm_email_notify\'], 2), 0);
  419. $cur_profile[\'pm_receive_from\'] = $profile_vars[\'pm_receive_from\'] = max(min((int) $_POST[\'pm_receive_from\'], 4), 0);
  420. return true;
  421. '),
  422. ),
  423. 'posts' => array(
  424. 'type' => 'int',
  425. 'label' => $txt['profile_posts'],
  426. 'log_change' => true,
  427. 'size' => 7,
  428. 'permission' => 'moderate_forum',
  429. 'input_validate' => create_function('&$value', '
  430. if (!is_numeric($value))
  431. return \'digits_only\';
  432. else
  433. $value = $value != \'\' ? strtr($value, array(\',\' => \'\', \'.\' => \'\', \' \' => \'\')) : 0;
  434. return true;
  435. '),
  436. ),
  437. 'real_name' => array(
  438. 'type' => allowedTo('profile_displayed_name_own') || allowedTo('profile_displayed_name_any') || allowedTo('moderate_forum') ? 'text' : 'label',
  439. 'label' => $txt['name'],
  440. 'subtext' => $txt['display_name_desc'],
  441. 'log_change' => true,
  442. 'input_attr' => array('maxlength="60"'),
  443. 'permission' => 'profile_displayed_name',
  444. 'enabled' => allowedTo('profile_displayed_name_own') || allowedTo('profile_displayed_name_any') || allowedTo('moderate_forum'),
  445. 'input_validate' => create_function('&$value', '
  446. global $context, $smcFunc, $sourcedir, $cur_profile;
  447. $value = trim(preg_replace(\'~[\t\n\r \x0B\0\' . ($context[\'utf8\'] ? \'\x{A0}\x{AD}\x{2000}-\x{200F}\x{201F}\x{202F}\x{3000}\x{FEFF}\' : \'\x00-\x08\x0B\x0C\x0E-\x19\xA0\') . \']+~\' . ($context[\'utf8\'] ? \'u\' : \'\'), \' \', $value));
  448. if (trim($value) == \'\')
  449. return \'no_name\';
  450. elseif ($smcFunc[\'strlen\']($value) > 60)
  451. return \'name_too_long\';
  452. elseif ($cur_profile[\'real_name\'] != $value)
  453. {
  454. require_once($sourcedir . \'/Subs-Members.php\');
  455. if (isReservedName($value, $context[\'id_member\']))
  456. return \'name_taken\';
  457. }
  458. return true;
  459. '),
  460. ),
  461. 'secret_question' => array(
  462. 'type' => 'text',
  463. 'label' => $txt['secret_question'],
  464. 'subtext' => $txt['secret_desc'],
  465. 'size' => 50,
  466. 'permission' => 'profile_password',
  467. ),
  468. 'secret_answer' => array(
  469. 'type' => 'text',
  470. 'label' => $txt['secret_answer'],
  471. 'subtext' => $txt['secret_desc2'],
  472. 'size' => 20,
  473. 'postinput' => '<span class="smalltext" style="margin-left: 4ex;">[<a href="' . $scripturl . '?action=helpadmin;help=secret_why_blank" onclick="return reqOverlayDiv(this.href);">' . $txt['secret_why_blank'] . '</a>]</span>',
  474. 'value' => '',
  475. 'permission' => 'profile_password',
  476. 'input_validate' => create_function('&$value', '
  477. $value = $value != \'\' ? md5($value) : \'\';
  478. return true;
  479. '),
  480. ),
  481. 'signature' => array(
  482. 'type' => 'callback',
  483. 'callback_func' => 'signature_modify',
  484. 'permission' => 'profile_signature',
  485. 'enabled' => substr($modSettings['signature_settings'], 0, 1) == 1,
  486. 'preload' => 'profileLoadSignatureData',
  487. 'input_validate' => 'profileValidateSignature',
  488. ),
  489. 'show_online' => array(
  490. 'type' => 'check',
  491. 'label' => $txt['show_online'],
  492. 'permission' => 'profile_identity',
  493. 'enabled' => !empty($modSettings['allow_hideOnline']) || allowedTo('moderate_forum'),
  494. ),
  495. 'smiley_set' => array(
  496. 'type' => 'callback',
  497. 'callback_func' => 'smiley_pick',
  498. 'enabled' => !empty($modSettings['smiley_sets_enable']),
  499. 'permission' => 'profile_extra',
  500. 'preload' => create_function('', '
  501. global $modSettings, $context, $txt, $cur_profile, $smcFunc;
  502. $context[\'member\'][\'smiley_set\'][\'id\'] = empty($cur_profile[\'smiley_set\']) ? \'\' : $cur_profile[\'smiley_set\'];
  503. $context[\'smiley_sets\'] = explode(\',\', \'none,,\' . $modSettings[\'smiley_sets_known\']);
  504. $set_names = explode("\n", $txt[\'smileys_none\'] . "\n" . $txt[\'smileys_forum_board_default\'] . "\n" . $modSettings[\'smiley_sets_names\']);
  505. foreach ($context[\'smiley_sets\'] as $i => $set)
  506. {
  507. $context[\'smiley_sets\'][$i] = array(
  508. \'id\' => $smcFunc[\'htmlspecialchars\']($set),
  509. \'name\' => $smcFunc[\'htmlspecialchars\']($set_names[$i]),
  510. \'selected\' => $set == $context[\'member\'][\'smiley_set\'][\'id\']
  511. );
  512. if ($context[\'smiley_sets\'][$i][\'selected\'])
  513. $context[\'member\'][\'smiley_set\'][\'name\'] = $set_names[$i];
  514. }
  515. return true;
  516. '),
  517. 'input_validate' => create_function('&$value', '
  518. global $modSettings;
  519. $smiley_sets = explode(\',\', $modSettings[\'smiley_sets_known\']);
  520. if (!in_array($value, $smiley_sets) && $value != \'none\')
  521. $value = \'\';
  522. return true;
  523. '),
  524. ),
  525. // Pretty much a dummy entry - it populates all the theme settings.
  526. 'theme_settings' => array(
  527. 'type' => 'callback',
  528. 'callback_func' => 'theme_settings',
  529. 'permission' => 'profile_extra',
  530. 'is_dummy' => true,
  531. 'preload' => create_function('', '
  532. global $context, $user_info, $modSettings;
  533. loadLanguage(\'Settings\');
  534. $context[\'allow_no_censored\'] = false;
  535. if ($user_info[\'is_admin\'] || $context[\'user\'][\'is_owner\'])
  536. $context[\'allow_no_censored\'] = !empty($modSettings[\'allow_no_censored\']);
  537. return true;
  538. '),
  539. ),
  540. 'time_format' => array(
  541. 'type' => 'callback',
  542. 'callback_func' => 'timeformat_modify',
  543. 'permission' => 'profile_extra',
  544. 'preload' => create_function('', '
  545. global $context, $user_info, $txt, $cur_profile, $modSettings;
  546. $context[\'easy_timeformats\'] = array(
  547. array(\'format\' => \'\', \'title\' => $txt[\'timeformat_default\']),
  548. array(\'format\' => \'%B %d, %Y, %I:%M:%S %p\', \'title\' => $txt[\'timeformat_easy1\']),
  549. array(\'format\' => \'%B %d, %Y, %H:%M:%S\', \'title\' => $txt[\'timeformat_easy2\']),
  550. array(\'format\' => \'%Y-%m-%d, %H:%M:%S\', \'title\' => $txt[\'timeformat_easy3\']),
  551. array(\'format\' => \'%d %B %Y, %H:%M:%S\', \'title\' => $txt[\'timeformat_easy4\']),
  552. array(\'format\' => \'%d-%m-%Y, %H:%M:%S\', \'title\' => $txt[\'timeformat_easy5\'])
  553. );
  554. $context[\'member\'][\'time_format\'] = $cur_profile[\'time_format\'];
  555. $context[\'current_forum_time\'] = timeformat(time() - $user_info[\'time_offset\'] * 3600, false);
  556. $context[\'current_forum_time_js\'] = strftime(\'%Y,\' . ((int) strftime(\'%m\', time() + $modSettings[\'time_offset\'] * 3600) - 1) . \',%d,%H,%M,%S\', time() + $modSettings[\'time_offset\'] * 3600);
  557. $context[\'current_forum_time_hour\'] = (int) strftime(\'%H\', forum_time(false));
  558. return true;
  559. '),
  560. ),
  561. 'time_offset' => array(
  562. 'type' => 'callback',
  563. 'callback_func' => 'timeoffset_modify',
  564. 'permission' => 'profile_extra',
  565. 'preload' => create_function('', '
  566. global $context, $cur_profile;
  567. $context[\'member\'][\'time_offset\'] = $cur_profile[\'time_offset\'];
  568. return true;
  569. '),
  570. 'input_validate' => create_function('&$value', '
  571. // Validate the time_offset...
  572. $value = (float) strtr($value, \',\', \'.\');
  573. if ($value < -23.5 || $value > 23.5)
  574. return \'bad_offset\';
  575. return true;
  576. '),
  577. ),
  578. 'usertitle' => array(
  579. 'type' => 'text',
  580. 'label' => $txt['custom_title'],
  581. 'log_change' => true,
  582. 'input_attr' => array('maxlength="50"'),
  583. 'size' => 50,
  584. 'permission' => 'profile_other',
  585. 'enabled' => !empty($modSettings['titlesEnable']),
  586. 'input_validate' => create_function('&$value', '
  587. global $smcFunc;
  588. if ($smcFunc[\'strlen\']($value) > 50)
  589. return \'user_title_too_long\';
  590. return true;
  591. '),
  592. ),
  593. 'website_title' => array(
  594. 'type' => 'text',
  595. 'label' => $txt['website_title'],
  596. 'subtext' => $txt['include_website_url'],
  597. 'size' => 50,
  598. 'permission' => 'profile_other',
  599. 'link_with' => 'website',
  600. ),
  601. 'website_url' => array(
  602. 'type' => 'text',
  603. 'label' => $txt['website_url'],
  604. 'subtext' => $txt['complete_url'],
  605. 'size' => 50,
  606. 'permission' => 'profile_other',
  607. // Fix the URL...
  608. 'input_validate' => create_function('&$value', '
  609. if (strlen(trim($value)) > 0 && strpos($value, \'://\') === false)
  610. $value = \'http://\' . $value;
  611. if (strlen($value) < 8 || (substr($value, 0, 7) !== \'http://\' && substr($value, 0, 8) !== \'https://\'))
  612. $value = \'\';
  613. return true;
  614. '),
  615. 'link_with' => 'website',
  616. ),
  617. 'yim' => array(
  618. 'type' => 'text',
  619. 'label' => $txt['yim'],
  620. 'subtext' => $txt['your_yim'],
  621. 'size' => 24,
  622. 'input_attr' => array('maxlength="32"'),
  623. 'permission' => 'profile_extra',
  624. ),
  625. );
  626. call_integration_hook('integrate_load_profile_fields', array(&$profile_fields));
  627. $disabled_fields = !empty($modSettings['disabled_profile_fields']) ? explode(',', $modSettings['disabled_profile_fields']) : array();
  628. // For each of the above let's take out the bits which don't apply - to save memory and security!
  629. foreach ($profile_fields as $key => $field)
  630. {
  631. // Do we have permission to do this?
  632. if (isset($field['permission']) && !allowedTo(($context['user']['is_owner'] ? array($field['permission'] . '_own', $field['permission'] . '_any') : $field['permission'] . '_any')) && !allowedTo($field['permission']))
  633. unset($profile_fields[$key]);
  634. // Is it enabled?
  635. if (isset($field['enabled']) && !$field['enabled'])
  636. unset($profile_fields[$key]);
  637. // Is it specifically disabled?
  638. if (in_array($key, $disabled_fields) || (isset($field['link_with']) && in_array($field['link_with'], $disabled_fields)))
  639. unset($profile_fields[$key]);
  640. }
  641. }
  642. /**
  643. * Setup the context for a page load!
  644. *
  645. * @param array $fields
  646. */
  647. function setupProfileContext($fields)
  648. {
  649. global $profile_fields, $context, $cur_profile, $smcFunc, $txt;
  650. // Make sure we have this!
  651. loadProfileFields(true);
  652. // First check for any linked sets.
  653. foreach ($profile_fields as $key => $field)
  654. if (isset($field['link_with']) && in_array($field['link_with'], $fields))
  655. $fields[] = $key;
  656. // Some default bits.
  657. $context['profile_prehtml'] = '';
  658. $context['profile_posthtml'] = '';
  659. $context['profile_javascript'] = '';
  660. $context['profile_onsubmit_javascript'] = '';
  661. $i = 0;
  662. $last_type = '';
  663. foreach ($fields as $key => $field)
  664. {
  665. if (isset($profile_fields[$field]))
  666. {
  667. // Shortcut.
  668. $cur_field = &$profile_fields[$field];
  669. // Does it have a preload and does that preload succeed?
  670. if (isset($cur_field['preload']) && !$cur_field['preload']())
  671. continue;
  672. // If this is anything but complex we need to do more cleaning!
  673. if ($cur_field['type'] != 'callback' && $cur_field['type'] != 'hidden')
  674. {
  675. if (!isset($cur_field['label']))
  676. $cur_field['label'] = isset($txt[$field]) ? $txt[$field] : $field;
  677. // Everything has a value!
  678. if (!isset($cur_field['value']))
  679. {
  680. $cur_field['value'] = isset($cur_profile[$field]) ? $cur_profile[$field] : '';
  681. }
  682. // Any input attributes?
  683. $cur_field['input_attr'] = !empty($cur_field['input_attr']) ? implode(',', $cur_field['input_attr']) : '';
  684. }
  685. // Was there an error with this field on posting?
  686. if (isset($context['profile_errors'][$field]))
  687. $cur_field['is_error'] = true;
  688. // Any javascript stuff?
  689. if (!empty($cur_field['js_submit']))
  690. $context['profile_onsubmit_javascript'] .= $cur_field['js_submit'];
  691. if (!empty($cur_field['js']))
  692. $context['profile_javascript'] .= $cur_field['js'];
  693. // Any template stuff?
  694. if (!empty($cur_field['prehtml']))
  695. $context['profile_prehtml'] .= $cur_field['prehtml'];
  696. if (!empty($cur_field['posthtml']))
  697. $context['profile_posthtml'] .= $cur_field['posthtml'];
  698. // Finally put it into context?
  699. if ($cur_field['type'] != 'hidden')
  700. {
  701. $last_type = $cur_field['type'];
  702. $context['profile_fields'][$field] = &$profile_fields[$field];
  703. }
  704. }
  705. // Bodge in a line break - without doing two in a row ;)
  706. elseif ($field == 'hr' && $last_type != 'hr' && $last_type != '')
  707. {
  708. $last_type = 'hr';
  709. $context['profile_fields'][$i++]['type'] = 'hr';
  710. }
  711. }
  712. // Free up some memory.
  713. unset($profile_fields);
  714. }
  715. /**
  716. * Save the profile changes.
  717. */
  718. function saveProfileFields()
  719. {
  720. global $profile_fields, $profile_vars, $context, $old_profile, $post_errors, $sourcedir, $cur_profile, $smcFunc;
  721. // Load them up.
  722. loadProfileFields();
  723. // This makes things easier...
  724. $old_profile = $cur_profile;
  725. // This allows variables to call activities when they save - by default just to reload their settings
  726. $context['profile_execute_on_save'] = array();
  727. if ($context['user']['is_owner'])
  728. $context['profile_execute_on_save']['reload_user'] = 'profileReloadUser';
  729. // Assume we log nothing.
  730. $context['log_changes'] = array();
  731. // Cycle through the profile fields working out what to do!
  732. foreach ($profile_fields as $key => $field)
  733. {
  734. if (!isset($_POST[$key]) || !empty($field['is_dummy']) || (isset($_POST['preview_signature']) && $key == 'signature'))
  735. continue;
  736. // What gets updated?
  737. $db_key = isset($field['save_key']) ? $field['save_key'] : $key;
  738. // Right - we have something that is enabled, we can act upon and has a value posted to it. Does it have a validation function?
  739. if (isset($field['input_validate']))
  740. {
  741. $is_valid = $field['input_validate']($_POST[$key]);
  742. // An error occured - set it as such!
  743. if ($is_valid !== true)
  744. {
  745. // Is this an actual error?
  746. if ($is_valid !== false)
  747. {
  748. $post_errors[$key] = $is_valid;
  749. $profile_fields[$key]['is_error'] = $is_valid;
  750. }
  751. // Retain the old value.
  752. $cur_profile[$key] = $_POST[$key];
  753. continue;
  754. }
  755. }
  756. // Are we doing a cast?
  757. $field['cast_type'] = empty($field['cast_type']) ? $field['type'] : $field['cast_type'];
  758. // Finally, clean up certain types.
  759. if ($field['cast_type'] == 'int')
  760. $_POST[$key] = (int) $_POST[$key];
  761. elseif ($field['cast_type'] == 'float')
  762. $_POST[$key] = (float) $_POST[$key];
  763. elseif ($field['cast_type'] == 'check')
  764. $_POST[$key] = !empty($_POST[$key]) ? 1 : 0;
  765. // If we got here we're doing OK.
  766. if ($field['type'] != 'hidden' && (!isset($old_profile[$key]) || $_POST[$key] != $old_profile[$key]))
  767. {
  768. // Set the save variable.
  769. $profile_vars[$db_key] = $_POST[$key];
  770. // And update the user profile.
  771. $cur_profile[$key] = $_POST[$key];
  772. // Are we logging it?
  773. if (!empty($field['log_change']) && isset($old_profile[$key]))
  774. $context['log_changes'][$key] = array(
  775. 'previous' => $old_profile[$key],
  776. 'new' => $_POST[$key],
  777. );
  778. }
  779. // Logging group changes are a bit different...
  780. if ($key == 'id_group' && $field['log_change'])
  781. {
  782. profileLoadGroups();
  783. // Any changes to primary group?
  784. if ($_POST['id_group'] != $old_profile['id_group'])
  785. {
  786. $context['log_changes']['id_group'] = array(
  787. 'previous' => !empty($old_profile[$key]) && isset($context['member_groups'][$old_profile[$key]]) ? $context['member_groups'][$old_profile[$key]]['name'] : '',
  788. 'new' => !empty($_POST[$key]) && isset($context['member_groups'][$_POST[$key]]) ? $context['member_groups'][$_POST[$key]]['name'] : '',
  789. );
  790. }
  791. // Prepare additional groups for comparison.
  792. $additional_groups = array(
  793. 'previous' => !empty($old_profile['additional_groups']) ? explode(',', $old_profile['additional_groups']) : array(),
  794. 'new' => !empty($_POST['additional_groups']) ? array_diff($_POST['additional_groups'], array(0)) : array(),
  795. );
  796. sort($additional_groups['previous']);
  797. sort($additional_groups['new']);
  798. // What about additional groups?
  799. if ($additional_groups['previous'] != $additional_groups['new'])
  800. {
  801. foreach ($additional_groups as $type => $groups)
  802. {
  803. foreach ($groups as $id => $group)
  804. {
  805. if (isset($context['member_groups'][$group]))
  806. $additional_groups[$type][$id] = $context['member_groups'][$group]['name'];
  807. else
  808. unset($additional_groups[$type][$id]);
  809. }
  810. $additional_groups[$type] = implode(', ', $additional_groups[$type]);
  811. }
  812. $context['log_changes']['additional_groups'] = $additional_groups;
  813. }
  814. }
  815. }
  816. // @todo Temporary
  817. if ($context['user']['is_owner'])
  818. $changeOther = allowedTo(array('profile_extra_any', 'profile_extra_own'));
  819. else
  820. $changeOther = allowedTo('profile_extra_any');
  821. if ($changeOther && empty($post_errors))
  822. {
  823. makeThemeChanges($context['id_member'], isset($_POST['id_theme']) ? (int) $_POST['id_theme'] : $old_profile['id_theme']);
  824. if (!empty($_REQUEST['sa']))
  825. makeCustomFieldChanges($context['id_member'], $_REQUEST['sa'], false);
  826. }
  827. // Free memory!
  828. unset($profile_fields);
  829. }
  830. /**
  831. * Save the profile changes
  832. *
  833. * @param array &$profile_variables
  834. * @param array &$post_errors
  835. * @param int $memID id_member
  836. */
  837. function saveProfileChanges(&$profile_vars, &$post_errors, $memID)
  838. {
  839. global $user_info, $txt, $user_profile;
  840. global $context, $sourcedir;
  841. global $smcFunc;
  842. // These make life easier....
  843. $old_profile = &$user_profile[$memID];
  844. // Permissions...
  845. if ($context['user']['is_owner'])
  846. {
  847. $changeIdentity = allowedTo(array('profile_identity_any', 'profile_identity_own', 'profile_password_any', 'profile_password_own'));
  848. $changeOther = allowedTo(array('profile_extra_any', 'profile_extra_own', 'profile_other_any', 'profile_other_own', 'profile_signature_any', 'profile_signature_own'));
  849. }
  850. else
  851. {
  852. $changeIdentity = allowedTo('profile_identity_any', 'profile_signature_any');
  853. $changeOther = allowedTo('profile_extra_any', 'profile_other_any', 'profile_signature_any');
  854. }
  855. // Arrays of all the changes - makes things easier.
  856. $profile_bools = array(
  857. 'notify_announcements', 'notify_send_body',
  858. );
  859. $profile_ints = array(
  860. 'notify_regularity',
  861. 'notify_types',
  862. );
  863. $profile_floats = array(
  864. );
  865. $profile_strings = array(
  866. 'buddy_list',
  867. 'ignore_boards',
  868. );
  869. if (isset($_POST['sa']) && $_POST['sa'] == 'ignoreboards' && empty($_POST['ignore_brd']))
  870. $_POST['ignore_brd'] = array();
  871. unset($_POST['ignore_boards']); // Whatever it is set to is a dirty fithy thing. Kinda like our minds.
  872. if (isset($_POST['ignore_brd']))
  873. {
  874. if (!is_array($_POST['ignore_brd']))
  875. $_POST['ignore_brd'] = array ($_POST['ignore_brd']);
  876. foreach ($_POST['ignore_brd'] as $k => $d)
  877. {
  878. $d = (int) $d;
  879. if ($d != 0)
  880. $_POST['ignore_brd'][$k] = $d;
  881. else
  882. unset($_POST['ignore_brd'][$k]);
  883. }
  884. $_POST['ignore_boards'] = implode(',', $_POST['ignore_brd']);
  885. unset($_POST['ignore_brd']);
  886. }
  887. // Here's where we sort out all the 'other' values...
  888. if ($changeOther)
  889. {
  890. makeThemeChanges($memID, isset($_POST['id_theme']) ? (int) $_POST['id_theme'] : $old_profile['id_theme']);
  891. //makeAvatarChanges($memID, $post_errors);
  892. if (!empty($_REQUEST['sa']))
  893. makeCustomFieldChanges($memID, $_REQUEST['sa'], false);
  894. foreach ($profile_bools as $var)
  895. if (isset($_POST[$var]))
  896. $profile_vars[$var] = empty($_POST[$var]) ? '0' : '1';
  897. foreach ($profile_ints as $var)
  898. if (isset($_POST[$var]))
  899. $profile_vars[$var] = $_POST[$var] != '' ? (int) $_POST[$var] : '';
  900. foreach ($profile_floats as $var)
  901. if (isset($_POST[$var]))
  902. $profile_vars[$var] = (float) $_POST[$var];
  903. foreach ($profile_strings as $var)
  904. if (isset($_POST[$var]))
  905. $profile_vars[$var] = $_POST[$var];
  906. }
  907. }
  908. /**
  909. * Make any theme changes that are sent with the profile.
  910. *
  911. * @param int $memID
  912. * @param int $id_theme
  913. */
  914. function makeThemeChanges($memID, $id_theme)
  915. {
  916. global $modSettings, $smcFunc, $context, $user_info;
  917. $reservedVars = array(
  918. 'actual_theme_url',
  919. 'actual_images_url',
  920. 'base_theme_dir',
  921. 'base_theme_url',
  922. 'default_images_url',
  923. 'default_theme_dir',
  924. 'default_theme_url',
  925. 'default_template',
  926. 'images_url',
  927. 'number_recent_posts',
  928. 'smiley_sets_default',
  929. 'theme_dir',
  930. 'theme_id',
  931. 'theme_layers',
  932. 'theme_templates',
  933. 'theme_url',
  934. );
  935. // Can't change reserved vars.
  936. if ((isset($_POST['options']) && count(array_intersect(array_keys($_POST['options']), $reservedVars)) != 0) || (isset($_POST['default_options']) && count(array_intersect(array_keys($_POST['default_options']), $reservedVars)) != 0))
  937. fatal_lang_error('no_access', false);
  938. // Don't allow any overriding of custom fields with default or non-default options.
  939. $request = $smcFunc['db_query']('', '
  940. SELECT col_name
  941. FROM {db_prefix}custom_fields
  942. WHERE active = {int:is_active}',
  943. array(
  944. 'is_active' => 1,
  945. )
  946. );
  947. $custom_fields = array();
  948. while ($row = $smcFunc['db_fetch_assoc']($request))
  949. $custom_fields[] = $row['col_name'];
  950. $smcFunc['db_free_result']($request);
  951. // These are the theme changes...
  952. $themeSetArray = array();
  953. if (isset($_POST['options']) && is_array($_POST['options']))
  954. {
  955. foreach ($_POST['options'] as $opt => $val)
  956. {
  957. if (in_array($opt, $custom_fields))
  958. continue;
  959. // These need to be controlled.
  960. if ($opt == 'topics_per_page' || $opt == 'messages_per_page')
  961. $val = max(0, min($val, 50));
  962. // We don't set this per theme anymore.
  963. elseif ($opt == 'allow_no_censored')
  964. continue;
  965. $themeSetArray[] = array($memID, $id_theme, $opt, is_array($val) ? implode(',', $val) : $val);
  966. }
  967. }
  968. $erase_options = array();
  969. if (isset($_POST['default_options']) && is_array($_POST['default_options']))
  970. foreach ($_POST['default_options'] as $opt => $val)
  971. {
  972. if (in_array($opt, $custom_fields))
  973. continue;
  974. // These need to be controlled.
  975. if ($opt == 'topics_per_page' || $opt == 'messages_per_page')
  976. $val = max(0, min($val, 50));
  977. // Only let admins and owners change the censor.
  978. elseif ($opt == 'allow_no_censored' && !$user_info['is_admin'] && !$context['user']['is_owner'])
  979. continue;
  980. $themeSetArray[] = array($memID, 1, $opt, is_array($val) ? implode(',', $val) : $val);
  981. $erase_options[] = $opt;
  982. }
  983. // If themeSetArray isn't still empty, send it to the database.
  984. if (empty($context['password_auth_failed']))
  985. {
  986. if (!empty($themeSetArray))
  987. {
  988. $smcFunc['db_insert']('replace',
  989. '{db_prefix}themes',
  990. array('id_member' => 'int', 'id_theme' => 'int', 'variable' => 'string-255', 'value' => 'string-65534'),
  991. $themeSetArray,
  992. array('id_member', 'id_theme', 'variable')
  993. );
  994. }
  995. if (!empty($erase_options))
  996. {
  997. $smcFunc['db_query']('', '
  998. DELETE FROM {db_prefix}themes
  999. WHERE id_theme != {int:id_theme}
  1000. AND variable IN ({array_string:erase_variables})
  1001. AND id_member = {int:id_member}',
  1002. array(
  1003. 'id_theme' => 1,
  1004. 'id_member' => $memID,
  1005. 'erase_variables' => $erase_options
  1006. )
  1007. );
  1008. }
  1009. // Admins can choose any theme, even if it's not enabled...
  1010. $themes = allowedTo('admin_forum') ? explode(',', $modSettings['knownThemes']) : explode(',', $modSettings['enableThemes']);
  1011. foreach ($themes as $t)
  1012. cache_put_data('theme_settings-' . $t . ':' . $memID, null, 60);
  1013. }
  1014. }
  1015. /**
  1016. * Make any notification changes that need to be made.
  1017. *
  1018. * @param int $memID id_member
  1019. */
  1020. function makeNotificationChanges($memID)
  1021. {
  1022. global $smcFunc;
  1023. // Update the boards they are being notified on.
  1024. if (isset($_POST['edit_notify_boards']) && !empty($_POST['notify_boards']))
  1025. {
  1026. // Make sure only integers are deleted.
  1027. foreach ($_POST['notify_boards'] as $index => $id)
  1028. $_POST['notify_boards'][$index] = (int) $id;
  1029. // id_board = 0 is reserved for topic notifications.
  1030. $_POST['notify_boards'] = array_diff($_POST['notify_boards'], array(0));
  1031. $smcFunc['db_query']('', '
  1032. DELETE FROM {db_prefix}log_notify
  1033. WHERE id_board IN ({array_int:board_list})
  1034. AND id_member = {int:selected_member}',
  1035. array(
  1036. 'board_list' => $_POST['notify_boards'],
  1037. 'selected_member' => $memID,
  1038. )
  1039. );
  1040. }
  1041. // We are editing topic notifications......
  1042. elseif (isset($_POST['edit_notify_topics']) && !empty($_POST['notify_topics']))
  1043. {
  1044. foreach ($_POST['notify_topics'] as $index => $id)
  1045. $_POST['notify_topics'][$index] = (int) $id;
  1046. // Make sure there are no zeros left.
  1047. $_POST['notify_topics'] = array_diff($_POST['notify_topics'], array(0));
  1048. $smcFunc['db_query']('', '
  1049. DELETE FROM {db_prefix}log_notify
  1050. WHERE id_topic IN ({array_int:topic_list})
  1051. AND id_member = {int:selected_member}',
  1052. array(
  1053. 'topic_list' => $_POST['notify_topics'],
  1054. 'selected_member' => $memID,
  1055. )
  1056. );
  1057. }
  1058. }
  1059. /**
  1060. * Save any changes to the custom profile fields
  1061. *
  1062. * @param int $memID
  1063. * @param string $area
  1064. * @param bool $sanitize = true
  1065. */
  1066. function makeCustomFieldChanges($memID, $area, $sanitize = true)
  1067. {
  1068. global $context, $smcFunc, $user_profile, $user_info, $modSettings, $sourcedir;
  1069. if ($sanitize && isset($_POST['customfield']))
  1070. $_POST['customfield'] = htmlspecialchars__recursive($_POST['customfield']);
  1071. $where = $area == 'register' ? 'show_reg != 0' : 'show_profile = {string:area}';
  1072. // Load the fields we are saving too - make sure we save valid data (etc).
  1073. $request = $smcFunc['db_query']('', '
  1074. SELECT col_name, field_name, field_desc, field_type, field_length, field_options, default_value, show_reg, mask, private
  1075. FROM {db_prefix}custom_fields
  1076. WHERE ' . $where . '
  1077. AND active = {int:is_active}',
  1078. array(
  1079. 'is_active' => 1,
  1080. 'area' => $area,
  1081. )
  1082. );
  1083. $changes = array();
  1084. $log_changes = array();
  1085. while ($row = $smcFunc['db_fetch_assoc']($request))
  1086. {
  1087. /* This means don't save if:
  1088. - The user is NOT an admin.
  1089. - The data is not freely viewable and editable by users.
  1090. - The data is not invisible to users but editable by the owner (or if it is the user is not the owner)
  1091. - The area isn't registration, and if it is that the field is not suppossed to be shown there.
  1092. */
  1093. if ($row['private'] != 0 && !allowedTo('admin_forum') && ($memID != $user_info['id'] || $row['private'] != 2) && ($area != 'register' || $row['show_reg'] == 0))
  1094. continue;
  1095. // Validate the user data.
  1096. if ($row['field_type'] == 'check')
  1097. $value = isset($_POST['customfield'][$row['col_name']]) ? 1 : 0;
  1098. elseif ($row['field_type'] == 'select' || $row['field_type'] == 'radio')
  1099. {
  1100. $value = $row['default_value'];
  1101. foreach (explode(',', $row['field_options']) as $k => $v)
  1102. if (isset($_POST['customfield'][$row['col_name']]) && $_POST['customfield'][$row['col_name']] == $k)
  1103. $value = $v;
  1104. }
  1105. // Otherwise some form of text!
  1106. else
  1107. {
  1108. $value = isset($_POST['customfield'][$row['col_name']]) ? $_POST['customfield'][$row['col_name']] : '';
  1109. if ($row['field_length'])
  1110. $value = $smcFunc['substr']($value, 0, $row['field_length']);
  1111. // Any masks?
  1112. if ($row['field_type'] == 'text' && !empty($row['mask']) && $row['mask'] != 'none')
  1113. {
  1114. // @todo We never error on this - just ignore it at the moment...
  1115. if ($row['mask'] == 'email' && (preg_match('~^[0-9A-Za-z=_+\-/][0-9A-Za-z=_\'+\-/\.]*@[\w\-]+(\.[\w\-]+)*(\.[\w]{2,6})$~', $value) === 0 || strlen($value) > 255))
  1116. $value = '';
  1117. elseif ($row['mask'] == 'number')
  1118. {
  1119. $value = (int) $value;
  1120. }
  1121. elseif (substr($row['mask'], 0, 5) == 'regex' && trim($value) != '' && preg_match(substr($row['mask'], 5), $value) === 0)
  1122. $value = '';
  1123. }
  1124. }
  1125. // Did it change?
  1126. if (!isset($user_profile[$memID]['options'][$row['col_name']]) || $user_profile[$memID]['options'][$row['col_name']] != $value)
  1127. {
  1128. $log_changes[] = array(
  1129. 'action' => 'customfield_' . $row['col_name'],
  1130. 'log_type' => 'user',
  1131. 'extra' => array(
  1132. 'previous' => !empty($user_profile[$memID]['options'][$row['col_name']]) ? $user_profile[$memID]['options'][$row['col_name']] : '',
  1133. 'new' => $value,
  1134. 'applicator' => $user_info['id'],
  1135. 'member_affected' => $memID,
  1136. ),
  1137. );
  1138. $changes[] = array(1, $row['col_name'], $value, $memID);
  1139. $user_profile[$memID]['options'][$row['col_name']] = $value;
  1140. }
  1141. }
  1142. $smcFunc['db_free_result']($request);
  1143. call_integration_hook('integrate_save_custom_profile_fields', array(&$changes, &$log_changes, $memID, $area, $sanitize));
  1144. // Make those changes!
  1145. if (!empty($changes) && empty($context['password_auth_failed']))
  1146. {
  1147. $smcFunc['db_insert']('replace',
  1148. '{db_prefix}themes',
  1149. array('id_theme' => 'int', 'variable' => 'string-255', 'value' => 'string-65534', 'id_member' => 'int'),
  1150. $changes,
  1151. array('id_theme', 'variable', 'id_member')
  1152. );
  1153. if (!empty($log_changes) && !empty($modSettings['modlog_enabled']))
  1154. {
  1155. require_once($sourcedir . '/Logging.php');
  1156. logActions($log_changes);
  1157. }
  1158. }
  1159. }
  1160. /**
  1161. * Show all the users buddies, as well as a add/delete interface.
  1162. *
  1163. * @param int $memID id_member
  1164. */
  1165. function editBuddyIgnoreLists($memID)
  1166. {
  1167. global $sourcedir, $context, $txt, $scripturl, $modSettings, $user_profile;
  1168. // Do a quick check to ensure people aren't getting here illegally!
  1169. if (!$context['user']['is_owner'] || empty($modSettings['enable_buddylist']))
  1170. fatal_lang_error('no_access', false);
  1171. // Can we email the user direct?
  1172. $context['can_moderate_forum'] = allowedTo('moderate_forum');
  1173. $context['can_send_email'] = allowedTo('send_email_to_members');
  1174. $subActions = array(
  1175. 'buddies' => array('editBuddies', $txt['editBuddies']),
  1176. 'ignore' => array('editIgnoreList', $txt['editIgnoreList']),
  1177. );
  1178. $context['list_area'] = isset($_GET['sa']) && isset($subActions[$_GET['sa']]) ? $_GET['sa'] : 'buddies';
  1179. // Create the tabs for the template.
  1180. $context[$context['profile_menu_name']]['tab_data'] = array(
  1181. 'title' => $txt['editBuddyIgnoreLists'],
  1182. 'description' => $txt['buddy_ignore_desc'],
  1183. 'icon' => 'profile_hd.png',
  1184. 'tabs' => array(
  1185. 'buddies' => array(),
  1186. 'ignore' => array(),
  1187. ),
  1188. );
  1189. // Pass on to the actual function.
  1190. $context['sub_template'] = $subActions[$context['list_area']][0];
  1191. $subActions[$context['list_area']][0]($memID);
  1192. }
  1193. /**
  1194. * Show all the users buddies, as well as a add/delete interface.
  1195. *
  1196. * @param int $memID id_member
  1197. */
  1198. function editBuddies($memID)
  1199. {
  1200. global $txt, $scripturl;
  1201. global $context, $user_profile, $memberContext, $smcFunc;
  1202. // For making changes!
  1203. $buddiesArray = explode(',', $user_profile[$memID]['buddy_list']);
  1204. foreach ($buddiesArray as $k => $dummy)
  1205. if ($dummy == '')
  1206. unset($buddiesArray[$k]);
  1207. // Removing a buddy?
  1208. if (isset($_GET['remove']))
  1209. {
  1210. checkSession('get');
  1211. call_integration_hook('integrate_remove_buddy', array($memID));
  1212. $_SESSION['prf-save'] = $txt['could_not_remove_person'];
  1213. // Heh, I'm lazy, do it the easy way...
  1214. foreach ($buddiesArray as $key => $buddy)
  1215. if ($buddy == (int) $_GET['remove'])
  1216. {
  1217. unset($buddiesArray[$key]);
  1218. $_SESSION['prf-save'] = true;
  1219. }
  1220. // Make the changes.
  1221. $user_profile[$memID]['buddy_list'] = implode(',', $buddiesArray);
  1222. updateMemberData($memID, array('buddy_list' => $user_profile[$memID]['buddy_list']));
  1223. // Redirect off the page because we don't like all this ugly query stuff to stick in the history.
  1224. redirectexit('action=profile;area=lists;sa=buddies;u=' . $memID);
  1225. }
  1226. elseif (isset($_POST['new_buddy']))
  1227. {
  1228. checkSession();
  1229. // Prepare the string for extraction...
  1230. $_POST['new_buddy'] = strtr($smcFunc['htmlspecialchars']($_POST['new_buddy'], ENT_QUOTES), array('&quot;' => '"'));
  1231. preg_match_all('~"([^"]+)"~', $_POST['new_buddy'], $matches);
  1232. $new_buddies = array_unique(array_merge($matches[1], explode(',', preg_replace('~"[^"]+"~', '', $_POST['new_buddy']))));
  1233. foreach ($new_buddies as $k => $dummy)
  1234. {
  1235. $new_buddies[$k] = strtr(trim($new_buddies[$k]), array('\'' => '&#039;'));
  1236. if (strlen($new_buddies[$k]) == 0 || in_array($new_buddies[$k], array($user_profile[$memID]['member_name'], $user_profile[$memID]['real_name'])))
  1237. unset($new_buddies[$k]);
  1238. }
  1239. call_integration_hook('integrate_add_buddies', array($memID, &$new_buddies));
  1240. $_SESSION['prf-save'] = $txt['could_not_add_person'];
  1241. if (!empty($new_buddies))
  1242. {
  1243. // Now find out the id_member of the buddy.
  1244. $request = $smcFunc['db_query']('', '
  1245. SELECT id_member
  1246. FROM {db_prefix}members
  1247. WHERE member_name IN ({array_string:new_buddies}) OR real_name IN ({array_string:new_buddies})
  1248. LIMIT {int:count_new_buddies}',
  1249. array(
  1250. 'new_buddies' => $new_buddies,
  1251. 'count_new_buddies' => count($new_buddies),
  1252. )
  1253. );
  1254. if ($smcFunc['db_num_rows']($request) != 0)
  1255. $_SESSION['prf-save'] = true;
  1256. // Add the new member to the buddies array.
  1257. while ($row = $smcFunc['db_fetch_assoc']($request))
  1258. $buddiesArray[] = (int) $row['id_member'];
  1259. $smcFunc['db_free_result']($request);
  1260. // Now update the current users buddy list.
  1261. $user_profile[$memID]['buddy_list'] = implode(',', $buddiesArray);
  1262. updateMemberData($memID, array('buddy_list' => $user_profile[$memID]['buddy_list']));
  1263. }
  1264. // Back to the buddy list!
  1265. redirectexit('action=profile;area=lists;sa=buddies;u=' . $memID);
  1266. }
  1267. // Get all the users "buddies"...
  1268. $buddies = array();
  1269. if (!empty($buddiesArray))
  1270. {
  1271. $result = $smcFunc['db_query']('', '
  1272. SELECT id_member
  1273. FROM {db_prefix}members
  1274. WHERE id_member IN ({array_int:buddy_list})
  1275. ORDER BY real_name
  1276. LIMIT {int:buddy_list_count}',
  1277. array(
  1278. 'buddy_list' => $buddiesArray,
  1279. 'buddy_list_count' => substr_count($user_profile[$memID]['buddy_list'], ',') + 1,
  1280. )
  1281. );
  1282. while ($row = $smcFunc['db_fetch_assoc']($result))
  1283. $buddies[] = $row['id_member'];
  1284. $smcFunc['db_free_result']($result);
  1285. }
  1286. $context['buddy_count'] = count($buddies);
  1287. // Load all the members up.
  1288. loadMemberData($buddies, false, 'profile');
  1289. // Setup the context for each buddy.
  1290. $context['buddies'] = array();
  1291. foreach ($buddies as $buddy)
  1292. {
  1293. loadMemberContext($buddy);
  1294. $context['buddies'][$buddy] = $memberContext[$buddy];
  1295. }
  1296. if (isset($_SESSION['prf-save']))
  1297. {
  1298. if ($_SESSION['prf-save'] === true)
  1299. $context['saved_successful'] = true;
  1300. else
  1301. $context['saved_failed'] = $_SESSION['prf-save'];
  1302. unset($_SESSION['prf-save']);
  1303. }
  1304. call_integration_hook('integrate_view_buddies', array($memID));
  1305. }
  1306. /**
  1307. * Allows the user to view their ignore list, as well as the option to manage members on it.
  1308. *
  1309. * @param int $memID id_member
  1310. */
  1311. function editIgnoreList($memID)
  1312. {
  1313. global $txt, $scripturl;
  1314. global $context, $user_profile, $memberContext, $smcFunc;
  1315. // For making changes!
  1316. $ignoreArray = explode(',', $user_profile[$memID]['pm_ignore_list']);
  1317. foreach ($ignoreArray as $k => $dummy)
  1318. if ($dummy == '')
  1319. unset($ignoreArray[$k]);
  1320. // Removing a member from the ignore list?
  1321. if (isset($_GET['remove']))
  1322. {
  1323. checkSession('get');
  1324. $_SESSION['prf-save'] = $txt['could_not_remove_person'];
  1325. // Heh, I'm lazy, do it the easy way...
  1326. foreach ($ignoreArray as $key => $id_remove)
  1327. if ($id_remove == (int) $_GET['remove'])
  1328. {
  1329. unset($ignoreArray[$key]);
  1330. $_SESSION['prf-save'] = true;
  1331. }
  1332. // Make the changes.
  1333. $user_profile[$memID]['pm_ignore_list'] = implode(',', $ignoreArray);
  1334. updateMemberData($memID, array('pm_ignore_list' => $user_profile[$memID]['pm_ignore_list']));
  1335. // Redirect off the page because we don't like all this ugly query stuff to stick in the history.
  1336. redirectexit('action=profile;area=lists;sa=ignore;u=' . $memID);
  1337. }
  1338. elseif (isset($_POST['new_ignore']))
  1339. {
  1340. checkSession();
  1341. // Prepare the string for extraction...
  1342. $_POST['new_ignore'] = strtr($smcFunc['htmlspecialchars']($_POST['new_ignore'], ENT_QUOTES), array('&quot;' => '"'));
  1343. preg_match_all('~"([^"]+)"~', $_POST['new_ignore'], $matches);
  1344. $new_entries = array_unique(array_merge($matches[1], explode(',', preg_replace('~"[^"]+"~', '', $_POST['new_ignore']))));
  1345. foreach ($new_entries as $k => $dummy)
  1346. {
  1347. $new_entries[$k] = strtr(trim($new_entries[$k]), array('\'' => '&#039;'));
  1348. if (strlen($new_entries[$k]) == 0 || in_array($new_entries[$k], array($user_profile[$memID]['member_name'], $user_profile[$memID]['real_name'])))
  1349. unset($new_entries[$k]);
  1350. }
  1351. $_SESSION['prf-save'] = $txt['could_not_add_person'];
  1352. if (!empty($new_entries))
  1353. {
  1354. // Now find out the id_member for the members in question.
  1355. $request = $smcFunc['db_query']('', '
  1356. SELECT id_member
  1357. FROM {db_prefix}members
  1358. WHERE member_name IN ({array_string:new_entries}) OR real_name IN ({array_string:new_entries})
  1359. LIMIT {int:count_new_entries}',
  1360. array(
  1361. 'new_entries' => $new_entries,
  1362. 'count_new_entries' => count($new_entries),
  1363. )
  1364. );
  1365. if ($smcFunc['db_num_rows']($request) != 0)
  1366. $_SESSION['prf-save'] = true;
  1367. // Add the new member to the buddies array.
  1368. while ($row = $smcFunc['db_fetch_assoc']($request))
  1369. $ignoreArray[] = (int) $row['id_member'];
  1370. $smcFunc['db_free_result']($request);
  1371. // Now update the current users buddy list.
  1372. $user_profile[$memID]['pm_ignore_list'] = implode(',', $ignoreArray);
  1373. updateMemberData($memID, array('pm_ignore_list' => $user_profile[$memID]['pm_ignore_list']));
  1374. }
  1375. // Back to the list of pityful people!
  1376. redirectexit('action=profile;area=lists;sa=ignore;u=' . $memID);
  1377. }
  1378. // Initialise the list of members we're ignoring.
  1379. $ignored = array();
  1380. if (!empty($ignoreArray))
  1381. {
  1382. $result = $smcFunc['db_query']('', '
  1383. SELECT id_member
  1384. FROM {db_prefix}members
  1385. WHERE id_member IN ({array_int:ignore_list})
  1386. ORDER BY real_name
  1387. LIMIT {int:ignore_list_count}',
  1388. array(
  1389. 'ignore_list' => $ignoreArray,
  1390. 'ignore_list_count' => substr_count($user_profile[$memID]['pm_ignore_list'], ',') + 1,
  1391. )
  1392. );
  1393. while ($row = $smcFunc['db_fetch_assoc']($result))
  1394. $ignored[] = $row['id_member'];
  1395. $smcFunc['db_free_result']($result);
  1396. }
  1397. $context['ignore_count'] = count($ignored);
  1398. // Load all the members up.
  1399. loadMemberData($ignored, false, 'profile');
  1400. // Setup the context for each buddy.
  1401. $context['ignore_list'] = array();
  1402. foreach ($ignored as $ignore_member)
  1403. {
  1404. loadMemberContext($ignore_member);
  1405. $context['ignore_list'][$ignore_member] = $memberContext[$ignore_member];
  1406. }
  1407. if (isset($_SESSION['prf-save']))
  1408. {
  1409. if ($_SESSION['prf-save'] === true)
  1410. $context['saved_successful'] = true;
  1411. else
  1412. $context['saved_failed'] = $_SESSION['prf-save'];
  1413. unset($_SESSION['prf-save']);
  1414. }
  1415. }
  1416. /**
  1417. * @todo Needs a description
  1418. *
  1419. * @param int $memID id_member
  1420. */
  1421. function account($memID)
  1422. {
  1423. global $context, $txt;
  1424. loadThemeOptions($memID);
  1425. if (allowedTo(array('profile_identity_own', 'profile_identity_any', 'profile_password_own', 'profile_password_any')))
  1426. loadCustomFields($memID, 'account');
  1427. $context['sub_template'] = 'edit_options';
  1428. $context['page_desc'] = $txt['account_info'];
  1429. setupProfileContext(
  1430. array(
  1431. 'member_name', 'real_name', 'date_registered', 'posts', 'lngfile', 'hr',
  1432. 'id_group', 'hr',
  1433. 'email_address', 'hide_email', 'show_online', 'hr',
  1434. 'passwrd1', 'passwrd2', 'hr',
  1435. 'secret_question', 'secret_answer',
  1436. )
  1437. );
  1438. }
  1439. /**
  1440. * @todo Needs a description
  1441. *
  1442. * @param int $memID id_member
  1443. */
  1444. function forumProfile($memID)
  1445. {
  1446. global $context, $txt;
  1447. loadThemeOptions($memID);
  1448. if (allowedTo(array('profile_forum_own', 'profile_forum_any')))
  1449. loadCustomFields($memID, 'forumprofile');
  1450. $context['sub_template'] = 'edit_options';
  1451. $context['page_desc'] = $txt['forumProfile_info'];
  1452. $context['show_preview_button'] = true;
  1453. setupProfileContext(
  1454. array(
  1455. 'avatar_choice', 'hr', 'personal_text', 'hr',
  1456. 'bday1', 'location', 'gender', 'hr',
  1457. 'icq', 'aim', 'yim', 'skype', 'hr',
  1458. 'usertitle', 'signature', 'hr',
  1459. 'karma_good', 'hr',
  1460. 'website_title', 'website_url',
  1461. )
  1462. );
  1463. }
  1464. /**
  1465. * Recursive function to retrieve server-stored avatar files
  1466. *
  1467. * @param string $directory
  1468. * @param int $level
  1469. * @return array
  1470. */
  1471. function getAvatars($directory, $level)
  1472. {
  1473. global $context, $txt, $modSettings, $smcFunc;
  1474. $result = array();
  1475. // Open the directory..
  1476. $dir = dir($modSettings['avatar_directory'] . (!empty($directory) ? '/' : '') . $directory);
  1477. $dirs = array();
  1478. $files = array();
  1479. if (!$dir)
  1480. return array();
  1481. while ($line = $dir->read())
  1482. {
  1483. if (in_array($line, array('.', '..', 'blank.png', 'index.php')))
  1484. continue;
  1485. if (is_dir($modSettings['avatar_directory'] . '/' . $directory . (!empty($directory) ? '/' : '') . $line))
  1486. $dirs[] = $line;
  1487. else
  1488. $files[] = $line;
  1489. }
  1490. $dir->close();
  1491. // Sort the results...
  1492. natcasesort($dirs);
  1493. natcasesort($files);
  1494. if ($level == 0)
  1495. {
  1496. $result[] = array(
  1497. 'filename' => 'blank.png',
  1498. 'checked' => in_array($context['member']['avatar']['server_pic'], array('', 'blank.png')),
  1499. 'name' => $txt['no_pic'],
  1500. 'is_dir' => false
  1501. );
  1502. }
  1503. foreach ($dirs as $line)
  1504. {
  1505. $tmp = getAvatars($directory . (!empty($directory) ? '/' : '') . $line, $level + 1);
  1506. if (!empty($tmp))
  1507. $result[] = array(
  1508. 'filename' => $smcFunc['htmlspecialchars']($line),
  1509. 'checked' => strpos($context['member']['avatar']['server_pic'], $line . '/') !== false,
  1510. 'name' => '[' . $smcFunc['htmlspecialchars'](str_replace('_', ' ', $line)) . ']',
  1511. 'is_dir' => true,
  1512. 'files' => $tmp
  1513. );
  1514. unset($tmp);
  1515. }
  1516. foreach ($files as $line)
  1517. {
  1518. $filename = substr($line, 0, (strlen($line) - strlen(strrchr($line, '.'))));
  1519. $extension = substr(strrchr($line, '.'), 1);
  1520. // Make sure it is an image.
  1521. if (strcasecmp($extension, 'gif') != 0 && strcasecmp($extension, 'jpg') != 0 && strcasecmp($extension, 'jpeg') != 0 && strcasecmp($extension, 'png') != 0 && strcasecmp($extension, 'bmp') != 0)
  1522. continue;
  1523. $result[] = array(
  1524. 'filename' => $smcFunc['htmlspecialchars']($line),
  1525. 'checked' => $line == $context['member']['avatar']['server_pic'],
  1526. 'name' => $smcFunc['htmlspecialchars'](str_replace('_', ' ', $filename)),
  1527. 'is_dir' => false
  1528. );
  1529. if ($level == 1)
  1530. $context['avatar_list'][] = $directory . '/' . $line;
  1531. }
  1532. return $result;
  1533. }
  1534. /**
  1535. * @todo needs a description
  1536. *
  1537. * @param int $memID id_member
  1538. */
  1539. function theme($memID)
  1540. {
  1541. global $txt, $context, $user_profile, $user_info, $smcFunc;
  1542. loadThemeOptions($memID);
  1543. if (allowedTo(array('profile_extra_own', 'profile_extra_any')))
  1544. loadCustomFields($memID, 'theme');
  1545. $context['sub_template'] = 'edit_options';
  1546. $context['page_desc'] = $txt['theme_info'];
  1547. setupProfileContext(
  1548. array(
  1549. 'id_theme', 'smiley_set', 'hr',
  1550. 'time_format', 'time_offset', 'hr',
  1551. 'theme_settings',
  1552. )
  1553. );
  1554. }
  1555. /**
  1556. * Changing authentication method? Only appropriate for people using OpenID.
  1557. *
  1558. * @param int $memID id_member
  1559. * @param bool $saving = false
  1560. */
  1561. function authentication($memID, $saving = false)
  1562. {
  1563. global $context, $cur_profile, $sourcedir, $txt, $post_errors, $modSettings;
  1564. loadLanguage('Login');
  1565. // We are saving?
  1566. if ($saving)
  1567. {
  1568. // Moving to password passed authentication?
  1569. if ($_POST['authenticate'] == 'passwd')
  1570. {
  1571. // Didn't enter anything?
  1572. if ($_POST['passwrd1'] == '')
  1573. $post_errors[] = 'no_password';
  1574. // Do the two entries for the password even match?
  1575. elseif (!isset($_POST['passwrd2']) || $_POST['passwrd1'] != $_POST['passwrd2'])
  1576. $post_errors[] = 'bad_new_password';
  1577. // Is it valid?
  1578. else
  1579. {
  1580. require_once($sourcedir . '/Subs-Auth.php');
  1581. $passwordErrors = validatePassword($_POST['passwrd1'], $cur_profile['member_name'], array($cur_profile['real_name'], $cur_profile['email_address']));
  1582. // Were there errors?
  1583. if ($passwordErrors != null)
  1584. $post_errors[] = 'password_' . $passwordErrors;
  1585. }
  1586. if (empty($post_errors))
  1587. {
  1588. // Integration?
  1589. call_integration_hook('integrate_reset_pass', array($cur_profile['member_name'], $cur_profile['member_name'], $_POST['passwrd1']));
  1590. // Go then.
  1591. $passwd = sha1(strtolower($cur_profile['member_name']) . un_htmlspecialchars($_POST['passwrd1']));
  1592. // Do the important bits.
  1593. updateMemberData($memID, array('openid_uri' => '', 'passwd' => $passwd));
  1594. if ($context['user']['is_owner'])
  1595. {
  1596. setLoginCookie(60 * $modSettings['cookieTime'], $memID, sha1(sha1(strtolower($cur_profile['member_name']) . un_htmlspecialchars($_POST['passwrd2'])) . $cur_profile['password_salt']));
  1597. redirectexit('action=profile;area=authentication;updated');
  1598. }
  1599. else
  1600. redirectexit('action=profile;u=' . $memID);
  1601. }
  1602. return true;
  1603. }
  1604. // Not right yet!
  1605. elseif ($_POST['authenticate'] == 'openid' && !empty($_POST['openid_identifier']))
  1606. {
  1607. require_once($sourcedir . '/Subs-OpenID.php');
  1608. $_POST['openid_identifier'] = smf_openID_canonize($_POST['openid_identifier']);
  1609. if (smf_openid_member_exists($_POST['openid_identifier']))
  1610. $post_errors[] = 'openid_in_use';
  1611. elseif (empty($post_errors))
  1612. {
  1613. // Authenticate using the new OpenID URI first to make sure they didn't make a mistake.
  1614. if ($context['user']['is_owner'])
  1615. {
  1616. $_SESSION['new_openid_uri'] = $_POST['openid_identifier'];
  1617. smf_openID_validate($_POST['openid_identifier'], false, null, 'change_uri');
  1618. }
  1619. else
  1620. updateMemberData($memID, array('openid_uri' => $_POST['openid_identifier']));
  1621. }
  1622. }
  1623. }
  1624. // Some stuff.
  1625. $context['member']['openid_uri'] = $cur_profile['openid_uri'];
  1626. $context['auth_method'] = empty($cur_profile['openid_uri']) ? 'password' : 'openid';
  1627. $context['sub_template'] = 'authentication_method';
  1628. }
  1629. /**
  1630. * Display the notifications and settings for changes.
  1631. *
  1632. * @param int $memID id_member
  1633. */
  1634. function notification($memID)
  1635. {
  1636. global $txt, $scripturl, $user_profile, $user_info, $context, $smcFunc, $sourcedir;
  1637. // Going to want this for consistency.
  1638. loadCSSFile('admin.css', array(), 'admin');
  1639. // This is just a bootstrap for everything else.
  1640. $sa = array(
  1641. 'alerts' => 'alert_configuration',
  1642. 'topics' => 'alert_notifications_topics',
  1643. 'boards' => 'alert_notifications_boards',
  1644. );
  1645. $subAction = !empty($_GET['sa']) && isset($sa[$_GET['sa']]) ? $_GET['sa'] : 'alerts';
  1646. $context['sub_template'] = $sa[$subAction];
  1647. $context[$context['profile_menu_name']]['tab_data'] = array(
  1648. 'title' => $txt['notification'],
  1649. 'help' => '',
  1650. 'description' => $txt['notification_info'],
  1651. );
  1652. $sa[$subAction]($memID);
  1653. }
  1654. function alert_configuration($memID)
  1655. {
  1656. global $txt, $scripturl, $user_profile, $user_info, $context, $modSettings, $smcFunc, $sourcedir;
  1657. $context['token_check'] = 'profile-nt' . $memID;
  1658. is_not_guest();
  1659. if (!$context['user']['is_owner'])
  1660. isAllowedTo('profile_extra_any');
  1661. // What options are set?
  1662. $context['member'] += array(
  1663. 'notify_announcements' => $user_profile[$memID]['notify_announcements'],
  1664. 'notify_send_body' => $user_profile[$memID]['notify_send_body'],
  1665. 'notify_types' => $user_profile[$memID]['notify_types'],
  1666. 'notify_regularity' => $user_profile[$memID]['notify_regularity'],
  1667. );
  1668. loadThemeOptions($memID);
  1669. // Now load all the values for this user.
  1670. require_once($sourcedir . '/Subs-Notify.php');
  1671. $prefs = getNotifyPrefs($memID);
  1672. // And we might as well now perform the splicing of default values.
  1673. if (!empty($prefs[0]))
  1674. foreach ($prefs[0] as $this_pref => $value)
  1675. if (!isset($prefs[$memID][$this_pref]))
  1676. $prefs[$memID][$this_pref] = $value;
  1677. $context['alert_prefs'] = !empty($prefs[$memID]) ? $prefs[$memID] : array();
  1678. // Now for the exciting stuff.
  1679. // We have groups of items, each item has both an alert and an email key as well as an optional help string.
  1680. // Valid values for these keys are 'always', 'yes', 'never'; if using always or never you should add a help string.
  1681. $alert_types = array(
  1682. 'msg' => array(
  1683. 'topic_notify' => array('alert' => 'yes', 'email' => 'yes'),
  1684. 'board_notify' => array('alert' => 'yes', 'email' => 'yes'),
  1685. 'msg_mention' => array('alert' => 'yes', 'email' => 'yes'),
  1686. 'msg_quote' => array('alert' => 'yes', 'email' => 'yes'),
  1687. 'msg_like' => array('alert' => 'yes', 'email' => 'never'),
  1688. ),
  1689. 'pm' => array(
  1690. 'pm_new' => array('alert' => 'always', 'email' => 'yes', 'help' => 'alert_pm_new', 'permission' => array('name' => 'pm_read', 'is_board' => false)),
  1691. 'pm_reply' => array('alert' => 'always', 'email' => 'yes', 'help' => 'alert_pm_new', 'permission' => array('name' => 'pm_send', 'is_board' => false)),
  1692. ),
  1693. 'moderation' => array(
  1694. 'msg_report' => array('alert' => 'yes', 'email' => 'yes', 'permission' => array('name' => 'moderate_board', 'is_board' => true)),
  1695. 'msg_report_reply' => array('alert' => 'yes', 'email' => 'yes', 'permission' => array('name' => 'moderate_board', 'is_board' => true)),
  1696. ),
  1697. 'members' => array(
  1698. 'member_register' => array('alert' => 'yes', 'email' => 'yes', 'permission' => array('name' => 'moderate_forum', 'is_board' => false)),
  1699. 'request_group' => array('alert' => 'yes', 'email' => 'yes'),
  1700. 'warn_any' => array('alert' => 'yes', 'email' => 'yes', 'permission' => array('name' => 'issue_warning', 'is_board' => false)),
  1701. ),
  1702. 'calendar' => array(
  1703. 'event_new' => array('alert' => 'yes', 'email' => 'yes', 'help' => 'alert_event_new'),
  1704. ),
  1705. );
  1706. $group_options = array(
  1707. 'msg' => array(
  1708. array('check', 'msg_auto_notify', 'label' => 'after'),
  1709. array('select', 'msg_notify_pref', 'label' => 'before', 'opts' => array(
  1710. 0 => $txt['alert_opt_msg_notify_pref_nothing'],
  1711. 1 => $txt['alert_opt_msg_notify_pref_instant'],
  1712. 2 => $txt['alert_opt_msg_notify_pref_first'],
  1713. 3 => $txt['alert_opt_msg_notify_pref_daily'],
  1714. 4 => $txt['alert_opt_msg_notify_pref_weekly'],
  1715. )),
  1716. ),
  1717. );
  1718. $disabled_options = array();
  1719. // There are certain things that are disabled at the group level.
  1720. if (empty($modSettings['cal_enabled']))
  1721. {
  1722. foreach ($alert_types['calendar'] as $k => $v)
  1723. $disabled_options[] = $k;
  1724. unset ($alert_types['calendar']);
  1725. }
  1726. // Now, now, we could pass this through global but we should really get into the habit of
  1727. // passing content to hooks, not expecting hooks to splatter everything everywhere.
  1728. call_integration_hook('integrate_alert_types', array(&$alert_types, &$group_options, &$disabled_options));
  1729. // Now we have to do some permissions testing.
  1730. require_once($sourcedir . '/Subs-Members.php');
  1731. $perms_cache = array();
  1732. foreach ($alert_types as $group => $items)
  1733. {
  1734. foreach ($items as $alert_key => $alert_value)
  1735. {
  1736. if (!isset($alert_value['permission']))
  1737. continue;
  1738. if (!isset($perms_cache[$alert_value['permission']['name']]))
  1739. {
  1740. $in_board = !empty($alert_value['permission']['is_board']) ? 0 : null;
  1741. $members = membersAllowedTo($alert_value['permission']['name'], $in_board);
  1742. $perms_cache[$alert_value['permission']['name']] = in_array($memID, $members);
  1743. }
  1744. if (!$perms_cache[$alert_value['permission']['name']])
  1745. {
  1746. $disabled_options[] = $alert_key;
  1747. unset ($alert_types[$group][$alert_key]);
  1748. }
  1749. }
  1750. if (empty($alert_types[$group]))
  1751. unset ($alert_types[$group]);
  1752. }
  1753. // Slightly different for group requests
  1754. $request = $smcFunc['db_query']('', '
  1755. SELECT COUNT(*)
  1756. FROM {db_prefix}group_moderators
  1757. WHERE id_member = {int:memID}',
  1758. array(
  1759. 'memID' => $memID,
  1760. )
  1761. );
  1762. list($can_mod) = $smcFunc['db_fetch_row']($request);
  1763. if (!isset($perms_cache['manage_membergroups']))
  1764. {
  1765. $members = membersAllowedTo('manage_membergroups');
  1766. $perms_cache['manage_membergroups'] = in_array($memID, $members);
  1767. }
  1768. if (!($perms_cache['manage_membergroups'] || $can_mod != 0))
  1769. unset($alert_types['members']['request_group']);
  1770. // And finally, exporting it to be useful later.
  1771. $context['alert_types'] = $alert_types;
  1772. $context['alert_group_options'] = $group_options;
  1773. $context['disabled_alerts'] = $disabled_options;
  1774. $context['alert_bits'] = array(
  1775. 'alert' => 0x01,
  1776. 'email' => 0x02,
  1777. );
  1778. if (isset($_POST['notify_submit']))
  1779. {
  1780. checkSession();
  1781. validateToken($context['token_check'], 'post');
  1782. // We need to step through the list of valid settings and figure out what the user has set.
  1783. $update_prefs = array();
  1784. // Now the group level options
  1785. foreach ($context['alert_group_options'] as $opt_group => $group)
  1786. {
  1787. foreach ($group as $this_option)
  1788. {
  1789. switch ($this_option[0])
  1790. {
  1791. case 'check':
  1792. $update_prefs[$this_option[1]] = !empty($_POST['opt_' . $this_option[1]]) ? 1 : 0;
  1793. break;
  1794. case 'select':
  1795. if (isset($_POST['opt_' . $this_option[1]], $this_option['opts'][$_POST['opt_' . $this_option[1]]]))
  1796. $update_prefs[$this_option[1]] = $_POST['opt_' . $this_option[1]];
  1797. else
  1798. {
  1799. // We didn't have a sane value. Let's grab the first item from the possibles.
  1800. $keys = array_keys($this_option['opts']);
  1801. $first = array_shift($keys);
  1802. $update_prefs[$this_option[1]] = $first;
  1803. }
  1804. break;
  1805. }
  1806. }
  1807. }
  1808. // Now the individual options
  1809. foreach ($context['alert_types'] as $alert_group => $items)
  1810. {
  1811. foreach ($items as $item_key => $this_options)
  1812. {
  1813. $this_value = 0;
  1814. foreach ($context['alert_bits'] as $type => $bitvalue)
  1815. {
  1816. if ($this_options[$type] == 'yes' && !empty($_POST[$type . '_' . $item_key]))
  1817. $this_value |= $bitvalue;
  1818. }
  1819. $update_prefs[$item_key] = $this_value;
  1820. }
  1821. }
  1822. setNotifyPrefs($memID, $update_prefs);
  1823. foreach ($update_prefs as $pref => $value)
  1824. $context['alert_prefs'][$pref] = $value;
  1825. makeNotificationChanges($memID);
  1826. $context['profile_updated'] = $txt['profile_updated_own'];
  1827. }
  1828. createToken($context['token_check'], 'post');
  1829. }
  1830. function alert_notifications_topics($memID)
  1831. {
  1832. global $txt, $scripturl, $user_profile, $user_info, $context, $modSettings, $smcFunc, $sourcedir;
  1833. // Because of the way this stuff works, we want to do this ourselves.
  1834. if (isset($_POST['edit_notify_topics']))
  1835. {
  1836. checkSession();
  1837. validateToken(str_replace('%u', $memID, 'profile-nt%u'), 'post');
  1838. makeNotificationChanges($memID);
  1839. $context['profile_updated'] = $txt['profile_updated_own'];
  1840. }
  1841. // Now set up for the token check.
  1842. $context['token_check'] = str_replace('%u', $memID, 'profile-nt%u');
  1843. createToken($context['token_check'], 'post');
  1844. // Gonna want this for the list.
  1845. require_once($sourcedir . '/Subs-List.php');
  1846. // Do the topic notifications.
  1847. $listOptions = array(
  1848. 'id' => 'topic_notification_list',
  1849. 'width' => '100%',
  1850. 'items_per_page' => $modSettings['defaultMaxMessages'],
  1851. 'no_items_label' => $txt['notifications_topics_none'] . '<br><br>' . $txt['notifications_topics_howto'],
  1852. 'no_items_align' => 'left',
  1853. 'base_href' => $scripturl . '?action=profile;u=' . $memID . ';area=notification;sa=topics',
  1854. 'default_sort_col' => 'last_post',
  1855. 'get_items' => array(
  1856. 'function' => 'list_getTopicNotifications',
  1857. 'params' => array(
  1858. $memID,
  1859. ),
  1860. ),
  1861. 'get_count' => array(
  1862. 'function' => 'list_getTopicNotificationCount',
  1863. 'params' => array(
  1864. $memID,
  1865. ),
  1866. ),
  1867. 'columns' => array(
  1868. 'subject' => array(
  1869. 'header' => array(
  1870. 'value' => $txt['notifications_topics'],
  1871. 'class' => 'lefttext first_th',
  1872. ),
  1873. 'data' => array(
  1874. 'function' => create_function('$topic', '
  1875. global $txt;
  1876. $link = $topic[\'link\'];
  1877. if ($topic[\'new\'])
  1878. $link .= \' <a href="\' . $topic[\'new_href\'] . \'"><span class="new_posts">\' . $txt[\'new\'] . \'</span></a>\';
  1879. $link .= \'<br><span class="smalltext"><em>\' . $txt[\'in\'] . \' \' . $topic[\'board_link\'] . \'</em></span>\';
  1880. return $link;
  1881. '),
  1882. ),
  1883. 'sort' => array(
  1884. 'default' => 'ms.subject',
  1885. 'reverse' => 'ms.subject DESC',
  1886. ),
  1887. ),
  1888. 'started_by' => array(
  1889. 'header' => array(
  1890. 'value' => $txt['started_by'],
  1891. 'class' => 'lefttext',
  1892. ),
  1893. 'data' => array(
  1894. 'db' => 'poster_link',
  1895. ),
  1896. 'sort' => array(
  1897. 'default' => 'real_name_col',
  1898. 'reverse' => 'real_name_col DESC',
  1899. ),
  1900. ),
  1901. 'last_post' => array(
  1902. 'header' => array(
  1903. 'value' => $txt['last_post'],
  1904. 'class' => 'lefttext',
  1905. ),
  1906. 'data' => array(
  1907. 'sprintf' => array(
  1908. 'format' => '<span class="smalltext">%1$s<br>' . $txt['by'] . ' %2$s</span>',
  1909. 'params' => array(
  1910. 'updated' => false,
  1911. 'poster_updated_link' => false,
  1912. ),
  1913. ),
  1914. ),
  1915. 'sort' => array(
  1916. 'default' => 'ml.id_msg DESC',
  1917. 'reverse' => 'ml.id_msg',
  1918. ),
  1919. ),
  1920. 'delete' => array(
  1921. 'header' => array(
  1922. 'value' => '<input type="checkbox" class="input_check" onclick="invertAll(this, this.form);">',
  1923. 'style' => 'width: 4%;',
  1924. 'class' => 'centercol',
  1925. ),
  1926. 'data' => array(
  1927. 'sprintf' => array(
  1928. 'format' => '<input type="checkbox" name="notify_topics[]" value="%1$d" class="input_check">',
  1929. 'params' => array(
  1930. 'id' => false,
  1931. ),
  1932. ),
  1933. 'class' => 'centercol',
  1934. ),
  1935. ),
  1936. ),
  1937. 'form' => array(
  1938. 'href' => $scripturl . '?action=profile;area=notification;sa=topics',
  1939. 'include_sort' => true,
  1940. 'include_start' => true,
  1941. 'hidden_fields' => array(
  1942. 'u' => $memID,
  1943. 'sa' => $context['menu_item_selected'],
  1944. $context['session_var'] => $context['session_id'],
  1945. ),
  1946. 'token' => $context['token_check'],
  1947. ),
  1948. 'additional_rows' => array(
  1949. array(
  1950. 'position' => 'bottom_of_list',
  1951. 'value' => '<input type="submit" name="edit_notify_topics" value="' . $txt['notifications_update'] . '" class="button_submit">',
  1952. 'align' => 'right',
  1953. ),
  1954. ),
  1955. );
  1956. // Create the notification list.
  1957. createList($listOptions);
  1958. }
  1959. function alert_notifications_boards($memID)
  1960. {
  1961. global $txt, $scripturl, $user_profile, $user_info, $context, $smcFunc, $sourcedir;
  1962. // Because of the way this stuff works, we want to do this ourselves.
  1963. if (isset($_POST['edit_notify_boards']))
  1964. {
  1965. checkSession();
  1966. validateToken(str_replace('%u', $memID, 'profile-nt%u'), 'post');
  1967. makeNotificationChanges($memID);
  1968. $context['profile_updated'] = $txt['profile_updated_own'];
  1969. }
  1970. // Now set up for the token check.
  1971. $context['token_check'] = str_replace('%u', $memID, 'profile-nt%u');
  1972. createToken($context['token_check'], 'post');
  1973. // Gonna want this for the list.
  1974. require_once($sourcedir . '/Subs-List.php');
  1975. // Fine, start with the board list.
  1976. $listOptions = array(
  1977. 'id' => 'board_notification_list',
  1978. 'width' => '100%',
  1979. 'no_items_label' => $txt['notifications_boards_none'] . '<br><br>' . $txt['notifications_boards_howto'],
  1980. 'no_items_align' => 'left',
  1981. 'base_href' => $scripturl . '?action=profile;u=' . $memID . ';area=notification;sa=boards',
  1982. 'default_sort_col' => 'board_name',
  1983. 'get_items' => array(
  1984. 'function' => 'list_getBoardNotifications',
  1985. 'params' => array(
  1986. $memID,
  1987. ),
  1988. ),
  1989. 'columns' => array(
  1990. 'board_name' => array(
  1991. 'header' => array(
  1992. 'value' => $txt['notifications_boards'],
  1993. 'class' => 'lefttext first_th',
  1994. ),
  1995. 'data' => array(
  1996. 'function' => create_function('$board', '
  1997. global $txt;
  1998. $link = $board[\'link\'];
  1999. if ($board[\'new\'])
  2000. $link .= \' <a href="\' . $board[\'href\'] . \'"><span class="new_posts">' . $txt['new'] . '</span></a>\';
  2001. return $link;
  2002. '),
  2003. ),
  2004. 'sort' => array(
  2005. 'default' => 'name',
  2006. 'reverse' => 'name DESC',
  2007. ),
  2008. ),
  2009. 'delete' => array(
  2010. 'header' => array(
  2011. 'value' => '<input type="checkbox" class="input_check" onclick="invertAll(this, this.form);">',
  2012. 'style' => 'width: 4%;',
  2013. 'class' => 'centercol',
  2014. ),
  2015. 'data' => array(
  2016. 'sprintf' => array(
  2017. 'format' => '<input type="checkbox" name="notify_boards[]" value="%1$d" class="input_check">',
  2018. 'params' => array(
  2019. 'id' => false,
  2020. ),
  2021. ),
  2022. 'class' => 'centercol',
  2023. ),
  2024. ),
  2025. ),
  2026. 'form' => array(
  2027. 'href' => $scripturl . '?action=profile;area=notification;sa=boards',
  2028. 'include_sort' => true,
  2029. 'include_start' => true,
  2030. 'hidden_fields' => array(
  2031. 'u' => $memID,
  2032. 'sa' => $context['menu_item_selected'],
  2033. $context['session_var'] => $context['session_id'],
  2034. ),
  2035. 'token' => $context['token_check'],
  2036. ),
  2037. 'additional_rows' => array(
  2038. array(
  2039. 'position' => 'bottom_of_list',
  2040. 'value' => '<input type="submit" name="edit_notify_boards" value="' . $txt['notifications_update'] . '" class="button_submit">',
  2041. 'align' => 'right',
  2042. ),
  2043. ),
  2044. );
  2045. // Create the board notification list.
  2046. createList($listOptions);
  2047. }
  2048. /**
  2049. * @todo needs a description
  2050. *
  2051. * @param int $memID id_member
  2052. * @return string
  2053. */
  2054. function list_getTopicNotificationCount($memID)
  2055. {
  2056. global $smcFunc, $user_info, $context, $modSettings;
  2057. $request = $smcFunc['db_query']('', '
  2058. SELECT COUNT(*)
  2059. FROM {db_prefix}log_notify AS ln' . (!$modSettings['postmod_active'] && $user_info['query_see_board'] === '1=1' ? '' : '
  2060. INNER JOIN {db_prefix}topics AS t ON (t.id_topic = ln.id_topic)') . ($user_info['query_see_board'] === '1=1' ? '' : '
  2061. INNER JOIN {db_prefix}boards AS b ON (b.id_board = t.id_board)') . '
  2062. WHERE ln.id_member = {int:selected_member}' . ($user_info['query_see_board'] === '1=1' ? '' : '
  2063. AND {query_see_board}') . ($modSettings['postmod_active'] ? '
  2064. AND t.approved = {int:is_approved}' : ''),
  2065. array(
  2066. 'selected_member' => $memID,
  2067. 'is_approved' => 1,
  2068. )
  2069. );
  2070. list ($totalNotifications) = $smcFunc['db_fetch_row']($request);
  2071. $smcFunc['db_free_result']($request);
  2072. // @todo make this an integer before it gets returned
  2073. return $totalNotifications;
  2074. }
  2075. /**
  2076. * @todo Needs a description
  2077. *
  2078. * @param int $start
  2079. * @param int $items_per_page
  2080. * @param string $sort
  2081. * @param int $memID id_member
  2082. * @return array $notification_topics
  2083. */
  2084. function list_getTopicNotifications($start, $items_per_page, $sort, $memID)
  2085. {
  2086. global $smcFunc, $txt, $scripturl, $user_info, $context, $modSettings;
  2087. // All the topics with notification on...
  2088. $request = $smcFunc['db_query']('', '
  2089. SELECT
  2090. IFNULL(lt.id_msg, IFNULL(lmr.id_msg, -1)) + 1 AS new_from, b.id_board, b.name,
  2091. t.id_topic, ms.subject, ms.id_member, IFNULL(mem.real_name, ms.poster_name) AS real_name_col,
  2092. ml.id_msg_modified, ml.poster_time, ml.id_member AS id_member_updated,
  2093. IFNULL(mem2.real_name, ml.poster_name) AS last_real_name
  2094. FROM {db_prefix}log_notify AS ln
  2095. INNER JOIN {db_prefix}topics AS t ON (t.id_topic = ln.id_topic' . ($modSettings['postmod_active'] ? ' AND t.approved = {int:is_approved}' : '') . ')
  2096. INNER JOIN {db_prefix}boards AS b ON (b.id_board = t.id_board AND {query_see_board})
  2097. INNER JOIN {db_prefix}messages AS ms ON (ms.id_msg = t.id_first_msg)
  2098. INNER JOIN {db_prefix}messages AS ml ON (ml.id_msg = t.id_last_msg)
  2099. LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = ms.id_member)
  2100. LEFT JOIN {db_prefix}members AS mem2 ON (mem2.id_member = ml.id_member)
  2101. LEFT JOIN {db_prefix}log_topics AS lt ON (lt.id_topic = t.id_topic AND lt.id_member = {int:current_member})
  2102. LEFT JOIN {db_prefix}log_mark_read AS lmr ON (lmr.id_board = b.id_board AND lmr.id_member = {int:current_member})
  2103. WHERE ln.id_member = {int:selected_member}
  2104. ORDER BY {raw:sort}
  2105. LIMIT {int:offset}, {int:items_per_page}',
  2106. array(
  2107. 'current_member' => $user_info['id'],
  2108. 'is_approved' => 1,
  2109. 'selected_member' => $memID,
  2110. 'sort' => $sort,
  2111. 'offset' => $start,
  2112. 'items_per_page' => $items_per_page,
  2113. )
  2114. );
  2115. $notification_topics = array();
  2116. while ($row = $smcFunc['db_fetch_assoc']($request))
  2117. {
  2118. censorText($row['subject']);
  2119. $notification_topics[] = array(
  2120. 'id' => $row['id_topic'],
  2121. 'poster_link' => empty($row['id_member']) ? $row['real_name_col'] : '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name_col'] . '</a>',
  2122. 'poster_updated_link' => empty($row['id_member_updated']) ? $row['last_real_name'] : '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member_updated'] . '">' . $row['last_real_name'] . '</a>',
  2123. 'subject' => $row['subject'],
  2124. 'href' => $scripturl . '?topic=' . $row['id_topic'] . '.0',
  2125. 'link' => '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0">' . $row['subject'] . '</a>',
  2126. 'new' => $row['new_from'] <= $row['id_msg_modified'],
  2127. 'new_from' => $row['new_from'],
  2128. 'updated' => timeformat($row['poster_time']),
  2129. 'new_href' => $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['new_from'] . '#new',
  2130. 'new_link' => '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['new_from'] . '#new">' . $row['subject'] . '</a>',
  2131. 'board_link' => '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['name'] . '</a>',
  2132. );
  2133. }
  2134. $smcFunc['db_free_result']($request);
  2135. return $notification_topics;
  2136. }
  2137. /**
  2138. * @todo needs a description
  2139. *
  2140. * @param int $start
  2141. * @param int $items_per_page
  2142. * @param string $sort
  2143. * @param int $memID id_member
  2144. * @return array
  2145. */
  2146. function list_getBoardNotifications($start, $items_per_page, $sort, $memID)
  2147. {
  2148. global $smcFunc, $txt, $scripturl, $user_info;
  2149. $request = $smcFunc['db_query']('', '
  2150. SELECT b.id_board, b.name, IFNULL(lb.id_msg, 0) AS board_read, b.id_msg_updated
  2151. FROM {db_prefix}log_notify AS ln
  2152. INNER JOIN {db_prefix}boards AS b ON (b.id_board = ln.id_board)
  2153. LEFT JOIN {db_prefix}log_boards AS lb ON (lb.id_board = b.id_board AND lb.id_member = {int:current_member})
  2154. WHERE ln.id_member = {int:selected_member}
  2155. AND {query_see_board}
  2156. ORDER BY ' . $sort,
  2157. array(
  2158. 'current_member' => $user_info['id'],
  2159. 'selected_member' => $memID,
  2160. )
  2161. );
  2162. $notification_boards = array();
  2163. while ($row = $smcFunc['db_fetch_assoc']($request))
  2164. $notification_boards[] = array(
  2165. 'id' => $row['id_board'],
  2166. 'name' => $row['name'],
  2167. 'href' => $scripturl . '?board=' . $row['id_board'] . '.0',
  2168. 'link' => '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['name'] . '</a>',
  2169. 'new' => $row['board_read'] < $row['id_msg_updated']
  2170. );
  2171. $smcFunc['db_free_result']($request);
  2172. return $notification_boards;
  2173. }
  2174. /**
  2175. * @todo needs a description
  2176. *
  2177. * @param int $memID id_member
  2178. */
  2179. function loadThemeOptions($memID)
  2180. {
  2181. global $context, $options, $cur_profile, $smcFunc;
  2182. if (isset($_POST['default_options']))
  2183. $_POST['options'] = isset($_POST['options']) ? $_POST['options'] + $_POST['default_options'] : $_POST['default_options'];
  2184. if ($context['user']['is_owner'])
  2185. {
  2186. $context['member']['options'] = $options;
  2187. if (isset($_POST['options']) && is_array($_POST['options']))
  2188. foreach ($_POST['options'] as $k => $v)
  2189. $context['member']['options'][$k] = $v;
  2190. }
  2191. else
  2192. {
  2193. $request = $smcFunc['db_query']('', '
  2194. SELECT id_member, variable, value
  2195. FROM {db_prefix}themes
  2196. WHERE id_theme IN (1, {int:member_theme})
  2197. AND id_member IN (-1, {int:selected_member})',
  2198. array(
  2199. 'member_theme' => (int) $cur_profile['id_theme'],
  2200. 'selected_member' => $memID,
  2201. )
  2202. );
  2203. $temp = array();
  2204. while ($row = $smcFunc['db_fetch_assoc']($request))
  2205. {
  2206. if ($row['id_member'] == -1)
  2207. {
  2208. $temp[$row['variable']] = $row['value'];
  2209. continue;
  2210. }
  2211. if (isset($_POST['options'][$row['variable']]))
  2212. $row['value'] = $_POST['options'][$row['variable']];
  2213. $context['member']['options'][$row['variable']] = $row['value'];
  2214. }
  2215. $smcFunc['db_free_result']($request);
  2216. // Load up the default theme options for any missing.
  2217. foreach ($temp as $k => $v)
  2218. {
  2219. if (!isset($context['member']['options'][$k]))
  2220. $context['member']['options'][$k] = $v;
  2221. }
  2222. }
  2223. }
  2224. /**
  2225. * @todo needs a description
  2226. *
  2227. * @param int $memID id_member
  2228. */
  2229. function ignoreboards($memID)
  2230. {
  2231. global $txt, $user_info, $context, $modSettings, $smcFunc, $cur_profile;
  2232. // Have the admins enabled this option?
  2233. if (empty($modSettings['allow_ignore_boards']))
  2234. fatal_lang_error('ignoreboards_disallowed', 'user');
  2235. // Find all the boards this user is allowed to see.
  2236. $request = $smcFunc['db_query']('order_by_board_order', '
  2237. SELECT b.id_cat, c.name AS cat_name, b.id_board, b.name, b.child_level,
  2238. '. (!empty($cur_profile['ignore_boards']) ? 'b.id_board IN ({array_int:ignore_boards})' : '0') . ' AS is_ignored
  2239. FROM {db_prefix}boards AS b
  2240. LEFT JOIN {db_prefix}categories AS c ON (c.id_cat = b.id_cat)
  2241. WHERE {query_see_board}
  2242. AND redirect = {string:empty_string}',
  2243. array(
  2244. 'ignore_boards' => !empty($cur_profile['ignore_boards']) ? explode(',', $cur_profile['ignore_boards']) : array(),
  2245. 'empty_string' => '',
  2246. )
  2247. );
  2248. $context['num_boards'] = $smcFunc['db_num_rows']($request);
  2249. $context['categories'] = array();
  2250. while ($row = $smcFunc['db_fetch_assoc']($request))
  2251. {
  2252. // This category hasn't been set up yet..
  2253. if (!isset($context['categories'][$row['id_cat']]))
  2254. $context['categories'][$row['id_cat']] = array(
  2255. 'id' => $row['id_cat'],
  2256. 'name' => $row['cat_name'],
  2257. 'boards' => array()
  2258. );
  2259. // Set this board up, and let the template know when it's a child. (indent them..)
  2260. $context['categories'][$row['id_cat']]['boards'][$row['id_board']] = array(
  2261. 'id' => $row['id_board'],
  2262. 'name' => $row['name'],
  2263. 'child_level' => $row['child_level'],
  2264. 'selected' => $row['is_ignored'],
  2265. );
  2266. }
  2267. $smcFunc['db_free_result']($request);
  2268. // Now, let's sort the list of categories into the boards for templates that like that.
  2269. $temp_boards = array();
  2270. foreach ($context['categories'] as $category)
  2271. {
  2272. // Include a list of boards per category for easy toggling.
  2273. $context['categories'][$category['id']]['child_ids'] = array_keys($category['boards']);
  2274. $temp_boards[] = array(
  2275. 'name' => $category['name'],
  2276. 'child_ids' => array_keys($category['boards'])
  2277. );
  2278. $temp_boards = array_merge($temp_boards, array_values($category['boards']));
  2279. }
  2280. $max_boards = ceil(count($temp_boards) / 2);
  2281. if ($max_boards == 1)
  2282. $max_boards = 2;
  2283. // Now, alternate them so they can be shown left and right ;).
  2284. $context['board_columns'] = array();
  2285. for ($i = 0; $i < $max_boards; $i++)
  2286. {
  2287. $context['board_columns'][] = $temp_boards[$i];
  2288. if (isset($temp_boards[$i + $max_boards]))
  2289. $context['board_columns'][] = $temp_boards[$i + $max_boards];
  2290. else
  2291. $context['board_columns'][] = array();
  2292. }
  2293. loadThemeOptions($memID);
  2294. }
  2295. /**
  2296. * Load all the languages for the profile.
  2297. * @return boolean
  2298. */
  2299. function profileLoadLanguages()
  2300. {
  2301. global $context, $cur_profile, $language, $smcFunc;
  2302. $context['profile_languages'] = array();
  2303. // Get our languages!
  2304. getLanguages(true, true);
  2305. // Setup our languages.
  2306. foreach ($context['languages'] as $lang)
  2307. {
  2308. $context['profile_languages'][$lang['filename']] = strtr($lang['name'], array('-utf8' => ''));
  2309. }
  2310. ksort($context['profile_languages']);
  2311. // Return whether we should proceed with this.
  2312. return count($context['profile_languages']) > 1 ? true : false;
  2313. }
  2314. /**
  2315. * @todo needs description
  2316. *
  2317. * @return true
  2318. */
  2319. function profileLoadGroups()
  2320. {
  2321. global $cur_profile, $txt, $context, $smcFunc, $user_settings;
  2322. $context['member_groups'] = array(
  2323. 0 => array(
  2324. 'id' => 0,
  2325. 'name' => $txt['no_primary_membergroup'],
  2326. 'is_primary' => $cur_profile['id_group'] == 0,
  2327. 'can_be_additional' => false,
  2328. 'can_be_primary' => true,
  2329. )
  2330. );
  2331. $curGroups = explode(',', $cur_profile['additional_groups']);
  2332. // Load membergroups, but only those groups the user can assign.
  2333. $request = $smcFunc['db_query']('', '
  2334. SELECT group_name, id_group, hidden
  2335. FROM {db_prefix}membergroups
  2336. WHERE id_group != {int:moderator_group}
  2337. AND min_posts = {int:min_posts}' . (allowedTo('admin_forum') ? '' : '
  2338. AND group_type != {int:is_protected}') . '
  2339. ORDER BY min_posts, CASE WHEN id_group < {int:newbie_group} THEN id_group ELSE 4 END, group_name',
  2340. array(
  2341. 'moderator_group' => 3,
  2342. 'min_posts' => -1,
  2343. 'is_protected' => 1,
  2344. 'newbie_group' => 4,
  2345. )
  2346. );
  2347. while ($row = $smcFunc['db_fetch_assoc']($request))
  2348. {
  2349. // We should skip the administrator group if they don't have the admin_forum permission!
  2350. if ($row['id_group'] == 1 && !allowedTo('admin_forum'))
  2351. continue;
  2352. $context['member_groups'][$row['id_group']] = array(
  2353. 'id' => $row['id_group'],
  2354. 'name' => $row['group_name'],
  2355. 'is_primary' => $cur_profile['id_group'] == $row['id_group'],
  2356. 'is_additional' => in_array($row['id_group'], $curGroups),
  2357. 'can_be_additional' => true,
  2358. 'can_be_primary' => $row['hidden'] != 2,
  2359. );
  2360. }
  2361. $smcFunc['db_free_result']($request);
  2362. $context['member']['group_id'] = $user_settings['id_group'];
  2363. return true;
  2364. }
  2365. /**
  2366. * Load key signature context data.
  2367. *
  2368. * @return true
  2369. */
  2370. function profileLoadSignatureData()
  2371. {
  2372. global $modSettings, $context, $txt, $cur_profile, $smcFunc, $memberContext;
  2373. // Signature limits.
  2374. list ($sig_limits, $sig_bbc) = explode(':', $modSettings['signature_settings']);
  2375. $sig_limits = explode(',', $sig_limits);
  2376. $context['signature_enabled'] = isset($sig_limits[0]) ? $sig_limits[0] : 0;
  2377. $context['signature_limits'] = array(
  2378. 'max_length' => isset($sig_limits[1]) ? $sig_limits[1] : 0,
  2379. 'max_lines' => isset($sig_limits[2]) ? $sig_limits[2] : 0,
  2380. 'max_images' => isset($sig_limits[3]) ? $sig_limits[3] : 0,
  2381. 'max_smileys' => isset($sig_limits[4]) ? $sig_limits[4] : 0,
  2382. 'max_image_width' => isset($sig_limits[5]) ? $sig_limits[5] : 0,
  2383. 'max_image_height' => isset($sig_limits[6]) ? $sig_limits[6] : 0,
  2384. 'max_font_size' => isset($sig_limits[7]) ? $sig_limits[7] : 0,
  2385. 'bbc' => !empty($sig_bbc) ? explode(',', $sig_bbc) : array(),
  2386. );
  2387. // Kept this line in for backwards compatibility!
  2388. $context['max_signature_length'] = $context['signature_limits']['max_length'];
  2389. // Warning message for signature image limits?
  2390. $context['signature_warning'] = '';
  2391. if ($context['signature_limits']['max_image_width'] && $context['signature_limits']['max_image_height'])
  2392. $context['signature_warning'] = sprintf($txt['profile_error_signature_max_image_size'], $context['signature_limits']['max_image_width'], $context['signature_limits']['max_image_height']);
  2393. elseif ($context['signature_limits']['max_image_width'] || $context['signature_limits']['max_image_height'])
  2394. $context['signature_warning'] = sprintf($txt['profile_error_signature_max_image_' . ($context['signature_limits']['max_image_width'] ? 'width' : 'height')], $context['signature_limits'][$context['signature_limits']['max_image_width'] ? 'max_image_width' : 'max_image_height']);
  2395. $context['show_spellchecking'] = !empty($modSettings['enableSpellChecking']) && function_exists('pspell_new');
  2396. if (empty($context['do_preview']))
  2397. $context['member']['signature'] = empty($cur_profile['signature']) ? '' : str_replace(array('<br>', '<', '>', '"', '\''), array("\n", '&lt;', '&gt;', '&quot;', '&#039;'), $cur_profile['signature']);
  2398. else
  2399. {
  2400. $signature = !empty($_POST['signature']) ? $_POST['signature'] : '';
  2401. $validation = profileValidateSignature($signature);
  2402. if (empty($context['post_errors']))
  2403. {
  2404. loadLanguage('Errors');
  2405. $context['post_errors'] = array();
  2406. }
  2407. $context['post_errors'][] = 'signature_not_yet_saved';
  2408. if ($validation !== true && $validation !== false)
  2409. $context['post_errors'][] = $validation;
  2410. censorText($context['member']['signature']);
  2411. $context['member']['current_signature'] = $context['member']['signature'];
  2412. censorText($signature);
  2413. $context['member']['signature_preview'] = parse_bbc($signature, true, 'sig' . $memberContext[$context['id_member']]);
  2414. $context['member']['signature'] = $_POST['signature'];
  2415. }
  2416. return true;
  2417. }
  2418. /**
  2419. * Load avatar context data.
  2420. *
  2421. * @return true
  2422. */
  2423. function profileLoadAvatarData()
  2424. {
  2425. global $context, $cur_profile, $modSettings, $scripturl;
  2426. $context['avatar_url'] = $modSettings['avatar_url'];
  2427. // Default context.
  2428. $context['member']['avatar'] += array(
  2429. 'custom' => stristr($cur_profile['avatar'], 'http://') || stristr($cur_profile['avatar'], 'https://') ? $cur_profile['avatar'] : 'http://',
  2430. 'selection' => $cur_profile['avatar'] == '' || (stristr($cur_profile['avatar'], 'http://') || stristr($cur_profile['avatar'], 'https://')) ? '' : $cur_profile['avatar'],
  2431. 'id_attach' => $cur_profile['id_attach'],
  2432. 'filename' => $cur_profile['filename'],
  2433. 'allow_server_stored' => allowedTo('profile_server_avatar') || (!$context['user']['is_owner'] && allowedTo('profile_extra_any')),
  2434. 'allow_upload' => allowedTo('profile_upload_avatar') || (!$context['user']['is_owner'] && allowedTo('profile_extra_any')),
  2435. 'allow_external' => allowedTo('profile_remote_avatar') || (!$context['user']['is_owner'] && allowedTo('profile_extra_any')),
  2436. );
  2437. if ($cur_profile['avatar'] == '' && $cur_profile['id_attach'] > 0 && $context['member']['avatar']['allow_upload'])
  2438. {
  2439. $context['member']['avatar'] += array(
  2440. 'choice' => 'upload',
  2441. 'server_pic' => 'blank.png',
  2442. 'external' => 'http://'
  2443. );
  2444. $context['member']['avatar']['href'] = empty($cur_profile['attachment_type']) ? $scripturl . '?action=dlattach;attach=' . $cur_profile['id_attach'] . ';type=avatar' : $modSettings['custom_avatar_url'] . '/' . $cur_profile['filename'];
  2445. }
  2446. elseif ((stristr($cur_profile['avatar'], 'http://') || stristr($cur_profile['avatar'], 'https://')) && $context['member']['avatar']['allow_external'])
  2447. $context['member']['avatar'] += array(
  2448. 'choice' => 'external',
  2449. 'server_pic' => 'blank.png',
  2450. 'external' => $cur_profile['avatar']
  2451. );
  2452. elseif ($cur_profile['avatar'] != '' && file_exists($modSettings['avatar_directory'] . '/' . $cur_profile['avatar']) && $context['member']['avatar']['allow_server_stored'])
  2453. $context['member']['avatar'] += array(
  2454. 'choice' => 'server_stored',
  2455. 'server_pic' => $cur_profile['avatar'] == '' ? 'blank.png' : $cur_profile['avatar'],
  2456. 'external' => 'http://'
  2457. );
  2458. else
  2459. $context['member']['avatar'] += array(
  2460. 'choice' => 'none',
  2461. 'server_pic' => 'blank.png',
  2462. 'external' => 'http://'
  2463. );
  2464. // Get a list of all the avatars.
  2465. if ($context['member']['avatar']['allow_server_stored'])
  2466. {
  2467. $context['avatar_list'] = array();
  2468. $context['avatars'] = is_dir($modSettings['avatar_directory']) ? getAvatars('', 0) : array();
  2469. }
  2470. else
  2471. $context['avatars'] = array();
  2472. // Second level selected avatar...
  2473. $context['avatar_selected'] = substr(strrchr($context['member']['avatar']['server_pic'], '/'), 1);
  2474. return true;
  2475. }
  2476. /**
  2477. * Save a members group.
  2478. *
  2479. * @param int &$value
  2480. * @return true
  2481. */
  2482. function profileSaveGroups(&$value)
  2483. {
  2484. global $profile_vars, $old_profile, $context, $smcFunc, $cur_profile;
  2485. // Do we need to protect some groups?
  2486. if (!allowedTo('admin_forum'))
  2487. {
  2488. $request = $smcFunc['db_query']('', '
  2489. SELECT id_group
  2490. FROM {db_prefix}membergroups
  2491. WHERE group_type = {int:is_protected}',
  2492. array(
  2493. 'is_protected' => 1,
  2494. )
  2495. );
  2496. $protected_groups = array(1);
  2497. while ($row = $smcFunc['db_fetch_assoc']($request))
  2498. $protected_groups[] = $row['id_group'];
  2499. $smcFunc['db_free_result']($request);
  2500. $protected_groups = array_unique($protected_groups);
  2501. }
  2502. // The account page allows the change of your id_group - but not to a protected group!
  2503. if (empty($protected_groups) || count(array_intersect(array((int) $value, $old_profile['id_group']), $protected_groups)) == 0)
  2504. $value = (int) $value;
  2505. // ... otherwise it's the old group sir.
  2506. else
  2507. $value = $old_profile['id_group'];
  2508. // Find the additional membergroups (if any)
  2509. if (isset($_POST['additional_groups']) && is_array($_POST['additional_groups']))
  2510. {
  2511. $additional_groups = array();
  2512. foreach ($_POST['additional_groups'] as $group_id)
  2513. {
  2514. $group_id = (int) $group_id;
  2515. if (!empty($group_id) && (empty($protected_groups) || !in_array($group_id, $protected_groups)))
  2516. $additional_groups[] = $group_id;
  2517. }
  2518. // Put the protected groups back in there if you don't have permission to take them away.
  2519. $old_additional_groups = explode(',', $old_profile['additional_groups']);
  2520. foreach ($old_additional_groups as $group_id)
  2521. {
  2522. if (!empty($protected_groups) && in_array($group_id, $protected_groups))
  2523. $additional_groups[] = $group_id;
  2524. }
  2525. if (implode(',', $additional_groups) !== $old_profile['additional_groups'])
  2526. {
  2527. $profile_vars['additional_groups'] = implode(',', $additional_groups);
  2528. $cur_profile['additional_groups'] = implode(',', $additional_groups);
  2529. }
  2530. }
  2531. // Too often, people remove delete their own account, or something.
  2532. if (in_array(1, explode(',', $old_profile['additional_groups'])) || $old_profile['id_group'] == 1)
  2533. {
  2534. $stillAdmin = $value == 1 || (isset($additional_groups) && in_array(1, $additional_groups));
  2535. // If they would no longer be an admin, look for any other...
  2536. if (!$stillAdmin)
  2537. {
  2538. $request = $smcFunc['db_query']('', '
  2539. SELECT id_member
  2540. FROM {db_prefix}members
  2541. WHERE (id_group = {int:admin_group} OR FIND_IN_SET({int:admin_group}, additional_groups) != 0)
  2542. AND id_member != {int:selected_member}
  2543. LIMIT 1',
  2544. array(
  2545. 'admin_group' => 1,
  2546. 'selected_member' => $context['id_member'],
  2547. )
  2548. );
  2549. list ($another) = $smcFunc['db_fetch_row']($request);
  2550. $smcFunc['db_free_result']($request);
  2551. if (empty($another))
  2552. fatal_lang_error('at_least_one_admin', 'critical');
  2553. }
  2554. }
  2555. // If we are changing group status, update permission cache as necessary.
  2556. if ($value != $old_profile['id_group'] || isset($profile_vars['additional_groups']))
  2557. {
  2558. if ($context['user']['is_owner'])
  2559. $_SESSION['mc']['time'] = 0;
  2560. else
  2561. updateSettings(array('settings_updated' => time()));
  2562. }
  2563. return true;
  2564. }
  2565. /**
  2566. * The avatar is incredibly complicated, what with the options... and what not.
  2567. * @todo argh, the avatar here. Take this out of here!
  2568. *
  2569. * @param array &$value
  2570. * @return mixed
  2571. */
  2572. function profileSaveAvatarData(&$value)
  2573. {
  2574. global $modSettings, $sourcedir, $smcFunc, $profile_vars, $cur_profile, $context;
  2575. $memID = $context['id_member'];
  2576. if (empty($memID) && !empty($context['password_auth_failed']))
  2577. return false;
  2578. require_once($sourcedir . '/ManageAttachments.php');
  2579. // We need to know where we're going to be putting it..
  2580. if (!empty($modSettings['custom_avatar_enabled']))
  2581. {
  2582. $uploadDir = $modSettings['custom_avatar_dir'];
  2583. $id_folder = 1;
  2584. }
  2585. elseif (!empty($modSettings['currentAttachmentUploadDir']))
  2586. {
  2587. if (!is_array($modSettings['attachmentUploadDir']))
  2588. $modSettings['attachmentUploadDir'] = unserialize($modSettings['attachmentUploadDir']);
  2589. // Just use the current path for temp files.
  2590. $uploadDir = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']];
  2591. $id_folder = $modSettings['currentAttachmentUploadDir'];
  2592. }
  2593. else
  2594. {
  2595. $uploadDir = $modSettings['attachmentUploadDir'];
  2596. $id_folder = 1;
  2597. }
  2598. $downloadedExternalAvatar = false;
  2599. if ($value == 'external' && allowedTo('profile_remote_avatar') && (stripos($_POST['userpicpersonal'], 'http://') === 0 || stripos($_POST['userpicpersonal'], 'https://') === 0) && strlen($_POST['userpicpersonal']) > 7 && !empty($modSettings['avatar_download_external']))
  2600. {
  2601. if (!is_writable($uploadDir))
  2602. fatal_lang_error('attachments_no_write', 'critical');
  2603. require_once($sourcedir . '/Subs-Package.php');
  2604. $url = parse_url($_POST['userpicpersonal']);
  2605. $contents = fetch_web_data($url['scheme'] . '://' . $url['host'] . (empty($url['port']) ? '' : ':' . $url['port']) . str_replace(' ', '%20', trim($url['path'])));
  2606. $new_filename = $uploadDir . '/' . getAttachmentFilename('avatar_tmp_' . $memID, false, null, true);
  2607. if ($contents != false && $tmpAvatar = fopen($new_filename, 'wb'))
  2608. {
  2609. fwrite($tmpAvatar, $contents);
  2610. fclose($tmpAvatar);
  2611. $downloadedExternalAvatar = true;
  2612. $_FILES['attachment']['tmp_name'] = $new_filename;
  2613. }
  2614. }
  2615. if ($value == 'none')
  2616. {
  2617. $profile_vars['avatar'] = '';
  2618. // Reset the attach ID.
  2619. $cur_profile['id_attach'] = 0;
  2620. $cur_profile['attachment_type'] = 0;
  2621. $cur_profile['filename'] = '';
  2622. removeAttachments(array('id_member' => $memID));
  2623. }
  2624. elseif ($value == 'server_stored' && allowedTo('profile_server_avatar'))
  2625. {
  2626. $profile_vars['avatar'] = strtr(empty($_POST['file']) ? (empty($_POST['cat']) ? '' : $_POST['cat']) : $_POST['file'], array('&amp;' => '&'));
  2627. $profile_vars['avatar'] = preg_match('~^([\w _!@%*=\-#()\[\]&.,]+/)?[\w _!@%*=\-#()\[\]&.,]+$~', $profile_vars['avatar']) != 0 && preg_match('/\.\./', $profile_vars['avatar']) == 0 && file_exists($modSettings['avatar_directory'] . '/' . $profile_vars['avatar']) ? ($profile_vars['avatar'] == 'blank.png' ? '' : $profile_vars['avatar']) : '';
  2628. // Clear current profile...
  2629. $cur_profile['id_attach'] = 0;
  2630. $cur_profile['attachment_type'] = 0;
  2631. $cur_profile['filename'] = '';
  2632. // Get rid of their old avatar. (if uploaded.)
  2633. removeAttachments(array('id_member' => $memID));
  2634. }
  2635. elseif ($value == 'external' && allowedTo('profile_remote_avatar') && (stripos($_POST['userpicpersonal'], 'http://') === 0 || stripos($_POST['userpicpersonal'], 'https://') === 0) && empty($modSettings['avatar_download_external']))
  2636. {
  2637. // We need these clean...
  2638. $cur_profile['id_attach'] = 0;
  2639. $cur_profile['attachment_type'] = 0;
  2640. $cur_profile['filename'] = '';
  2641. // Remove any attached avatar...
  2642. removeAttachments(array('id_member' => $memID));
  2643. // @todo http://www.simplemachines.org/community/index.php?topic=462089.msg3226650#msg3226650
  2644. $profile_vars['avatar'] = str_replace(' ', '%20', preg_replace('~action(?:=|%3d)(?!dlattach)~i', 'action-', $_POST['userpicpersonal']));
  2645. if ($profile_vars['avatar'] == 'http://' || $profile_vars['avatar'] == 'http:///')
  2646. $profile_vars['avatar'] = '';
  2647. // Trying to make us do something we'll regret?
  2648. elseif (substr($profile_vars['avatar'], 0, 7) != 'http://' && substr($profile_vars['avatar'], 0, 8) != 'https://')
  2649. return 'bad_avatar';
  2650. // Should we check dimensions?
  2651. elseif (!empty($modSettings['avatar_max_height_external']) || !empty($modSettings['avatar_max_width_external']))
  2652. {
  2653. // Now let's validate the avatar.
  2654. $sizes = url_image_size($profile_vars['avatar']);
  2655. if (is_array($sizes) && (($sizes[0] > $modSettings['avatar_max_width_external'] && !empty($modSettings['avatar_max_width_external'])) || ($sizes[1] > $modSettings['avatar_max_height_external'] && !empty($modSettings['avatar_max_height_external']))))
  2656. {
  2657. // Houston, we have a problem. The avatar is too large!!
  2658. if ($modSettings['avatar_action_too_large'] == 'option_refuse')
  2659. return 'bad_avatar';
  2660. elseif ($modSettings['avatar_action_too_large'] == 'option_download_and_resize')
  2661. {
  2662. // @todo remove this if appropriate
  2663. require_once($sourcedir . '/Subs-Graphics.php');
  2664. if (downloadAvatar($profile_vars['avatar'], $memID, $modSettings['avatar_max_width_external'], $modSettings['avatar_max_height_external']))
  2665. {
  2666. $profile_vars['avatar'] = '';
  2667. $cur_profile['id_attach'] = $modSettings['new_avatar_data']['id'];
  2668. $cur_profile['filename'] = $modSettings['new_avatar_data']['filename'];
  2669. $cur_profile['attachment_type'] = $modSettings['new_avatar_data']['type'];
  2670. }
  2671. else
  2672. return 'bad_avatar';
  2673. }
  2674. }
  2675. }
  2676. }
  2677. elseif (($value == 'upload' && allowedTo('profile_upload_avatar')) || $downloadedExternalAvatar)
  2678. {
  2679. if ((isset($_FILES['attachment']['name']) && $_FILES['attachment']['name'] != '') || $downloadedExternalAvatar)
  2680. {
  2681. // Get the dimensions of the image.
  2682. if (!$downloadedExternalAvatar)
  2683. {
  2684. if (!is_writable($uploadDir))
  2685. fatal_lang_error('attachments_no_write', 'critical');
  2686. $new_filename = $uploadDir . '/' . getAttachmentFilename('avatar_tmp_' . $memID, false, null, true);
  2687. if (!move_uploaded_file($_FILES['attachment']['tmp_name'], $new_filename))
  2688. fatal_lang_error('attach_timeout', 'critical');
  2689. $_FILES['attachment']['tmp_name'] = $new_filename;
  2690. }
  2691. $sizes = @getimagesize($_FILES['attachment']['tmp_name']);
  2692. // No size, then it's probably not a valid pic.
  2693. if ($sizes === false)
  2694. {
  2695. @unlink($_FILES['attachment']['tmp_name']);
  2696. return 'bad_avatar';
  2697. }
  2698. // Check whether the image is too large.
  2699. elseif ((!empty($modSettings['avatar_max_width_upload']) && $sizes[0] > $modSettings['avatar_max_width_upload']) || (!empty($modSettings['avatar_max_height_upload']) && $sizes[1] > $modSettings['avatar_max_height_upload']))
  2700. {
  2701. if (!empty($modSettings['avatar_resize_upload']))
  2702. {
  2703. // Attempt to chmod it.
  2704. @chmod($_FILES['attachment']['tmp_name'], 0644);
  2705. // @todo remove this require when appropriate
  2706. require_once($sourcedir . '/Subs-Graphics.php');
  2707. if (!downloadAvatar($_FILES['attachment']['tmp_name'], $memID, $modSettings['avatar_max_width_upload'], $modSettings['avatar_max_height_upload']))
  2708. {
  2709. @unlink($_FILES['attachment']['tmp_name']);
  2710. return 'bad_avatar';
  2711. }
  2712. // Reset attachment avatar data.
  2713. $cur_profile['id_attach'] = $modSettings['new_avatar_data']['id'];
  2714. $cur_profile['filename'] = $modSettings['new_avatar_data']['filename'];
  2715. $cur_profile['attachment_type'] = $modSettings['new_avatar_data']['type'];
  2716. }
  2717. else
  2718. {
  2719. @unlink($_FILES['attachment']['tmp_name']);
  2720. return 'bad_avatar';
  2721. }
  2722. }
  2723. elseif (is_array($sizes))
  2724. {
  2725. // Now try to find an infection.
  2726. require_once($sourcedir . '/Subs-Graphics.php');
  2727. if (!checkImageContents($_FILES['attachment']['tmp_name'], !empty($modSettings['avatar_paranoid'])))
  2728. {
  2729. // It's bad. Try to re-encode the contents?
  2730. if (empty($modSettings['avatar_reencode']) || (!reencodeImage($_FILES['attachment']['tmp_name'], $sizes[2])))
  2731. {
  2732. @unlink($_FILES['attachment']['tmp_name']);
  2733. return 'bad_avatar';
  2734. }
  2735. // We were successful. However, at what price?
  2736. $sizes = @getimagesize($_FILES['attachment']['tmp_name']);
  2737. // Hard to believe this would happen, but can you bet?
  2738. if ($sizes === false)
  2739. {
  2740. @unlink($_FILES['attachment']['tmp_name']);
  2741. return 'bad_avatar';
  2742. }
  2743. }
  2744. $extensions = array(
  2745. '1' => 'gif',
  2746. '2' => 'jpg',
  2747. '3' => 'png',
  2748. '6' => 'bmp'
  2749. );
  2750. $extension = isset($extensions[$sizes[2]]) ? $extensions[$sizes[2]] : 'bmp';
  2751. $mime_type = 'image/' . ($extension === 'jpg' ? 'jpeg' : ($extension === 'bmp' ? 'x-ms-bmp' : $extension));
  2752. $destName = 'avatar_' . $memID . '_' . time() . '.' . $extension;
  2753. list ($width, $height) = getimagesize($_FILES['attachment']['tmp_name']);
  2754. $file_hash = empty($modSettings['custom_avatar_enabled']) ? getAttachmentFilename($destName, false, null, true) : '';
  2755. // Remove previous attachments this member might have had.
  2756. removeAttachments(array('id_member' => $memID));
  2757. $smcFunc['db_insert']('',
  2758. '{db_prefix}attachments',
  2759. array(
  2760. 'id_member' => 'int', 'attachment_type' => 'int', 'filename' => 'string', 'file_hash' => 'string', 'fileext' => 'string', 'size' => 'int',
  2761. 'width' => 'int', 'height' => 'int', 'mime_type' => 'string', 'id_folder' => 'int',
  2762. ),
  2763. array(
  2764. $memID, (empty($modSettings['custom_avatar_enabled']) ? 0 : 1), $destName, $file_hash, $extension, filesize($_FILES['attachment']['tmp_name']),
  2765. (int) $width, (int) $height, $mime_type, $id_folder,
  2766. ),
  2767. array('id_attach')
  2768. );
  2769. $cur_profile['id_attach'] = $smcFunc['db_insert_id']('{db_prefix}attachments', 'id_attach');
  2770. $cur_profile['filename'] = $destName;
  2771. $cur_profile['attachment_type'] = empty($modSettings['custom_avatar_enabled']) ? 0 : 1;
  2772. $destinationPath = $uploadDir . '/' . (empty($file_hash) ? $destName : $cur_profile['id_attach'] . '_' . $file_hash . '.dat');
  2773. if (!rename($_FILES['attachment']['tmp_name'], $destinationPath))
  2774. {
  2775. // I guess a man can try.
  2776. removeAttachments(array('id_member' => $memID));
  2777. fatal_lang_error('attach_timeout', 'critical');
  2778. }
  2779. // Attempt to chmod it.
  2780. @chmod($uploadDir . '/' . $destinationPath, 0644);
  2781. }
  2782. $profile_vars['avatar'] = '';
  2783. // Delete any temporary file.
  2784. if (file_exists($_FILES['attachment']['tmp_name']))
  2785. @unlink($_FILES['attachment']['tmp_name']);
  2786. }
  2787. // Selected the upload avatar option and had one already uploaded before or didn't upload one.
  2788. else
  2789. $profile_vars['avatar'] = '';
  2790. }
  2791. else
  2792. $profile_vars['avatar'] = '';
  2793. // Setup the profile variables so it shows things right on display!
  2794. $cur_profile['avatar'] = $profile_vars['avatar'];
  2795. return false;
  2796. }
  2797. /**
  2798. * Validate the signature
  2799. *
  2800. * @param mixed &$value
  2801. * @return boolean|string
  2802. */
  2803. function profileValidateSignature(&$value)
  2804. {
  2805. global $sourcedir, $modSettings, $smcFunc, $txt;
  2806. require_once($sourcedir . '/Subs-Post.php');
  2807. // Admins can do whatever they hell they want!
  2808. if (!allowedTo('admin_forum'))
  2809. {
  2810. // Load all the signature limits.
  2811. list ($sig_limits, $sig_bbc) = explode(':', $modSettings['signature_settings']);
  2812. $sig_limits = explode(',', $sig_limits);
  2813. $disabledTags = !empty($sig_bbc) ? explode(',', $sig_bbc) : array();
  2814. $unparsed_signature = strtr(un_htmlspecialchars($value), array("\r" => '', '&#039' => '\''));
  2815. // Too many lines?
  2816. if (!empty($sig_limits[2]) && substr_count($unparsed_signature, "\n") >= $sig_limits[2])
  2817. {
  2818. $txt['profile_error_signature_max_lines'] = sprintf($txt['profile_error_signature_max_lines'], $sig_limits[2]);
  2819. return 'signature_max_lines';
  2820. }
  2821. // Too many images?!
  2822. if (!empty($sig_limits[3]) && (substr_count(strtolower($unparsed_signature), '[img') + substr_count(strtolower($unparsed_signature), '<img')) > $sig_limits[3])
  2823. {
  2824. $txt['profile_error_signature_max_image_count'] = sprintf($txt['profile_error_signature_max_image_count'], $sig_limits[3]);
  2825. return 'signature_max_image_count';
  2826. }
  2827. // What about too many smileys!
  2828. $smiley_parsed = $unparsed_signature;
  2829. parsesmileys($smiley_parsed);
  2830. $smiley_count = substr_count(strtolower($smiley_parsed), '<img') - substr_count(strtolower($unparsed_signature), '<img');
  2831. if (!empty($sig_limits[4]) && $sig_limits[4] == -1 && $smiley_count > 0)
  2832. return 'signature_allow_smileys';
  2833. elseif (!empty($sig_limits[4]) && $sig_limits[4] > 0 && $smiley_count > $sig_limits[4])
  2834. {
  2835. $txt['profile_error_signature_max_smileys'] = sprintf($txt['profile_error_signature_max_smileys'], $sig_limits[4]);
  2836. return 'signature_max_smileys';
  2837. }
  2838. // Maybe we are abusing font sizes?
  2839. if (!empty($sig_limits[7]) && preg_match_all('~\[size=([\d\.]+)?(px|pt|em|x-large|larger)~i', $unparsed_signature, $matches) !== false && isset($matches[2]))
  2840. {
  2841. foreach ($matches[1] as $ind => $size)
  2842. {
  2843. $limit_broke = 0;
  2844. // Attempt to allow all sizes of abuse, so to speak.
  2845. if ($matches[2][$ind] == 'px' && $size > $sig_limits[7])
  2846. $limit_broke = $sig_limits[7] . 'px';
  2847. elseif ($matches[2][$ind] == 'pt' && $size > ($sig_limits[7] * 0.75))
  2848. $limit_broke = ((int) $sig_limits[7] * 0.75) . 'pt';
  2849. elseif ($matches[2][$ind] == 'em' && $size > ((float) $sig_limits[7] / 16))
  2850. $limit_broke = ((float) $sig_limits[7] / 16) . 'em';
  2851. elseif ($matches[2][$ind] != 'px' && $matches[2][$ind] != 'pt' && $matches[2][$ind] != 'em' && $sig_limits[7] < 18)
  2852. $limit_broke = 'large';
  2853. if ($limit_broke)
  2854. {
  2855. $txt['profile_error_signature_max_font_size'] = sprintf($txt['profile_error_signature_max_font_size'], $limit_broke);
  2856. return 'signature_max_font_size';
  2857. }
  2858. }
  2859. }
  2860. // The difficult one - image sizes! Don't error on this - just fix it.
  2861. if ((!empty($sig_limits[5]) || !empty($sig_limits[6])))
  2862. {
  2863. // Get all BBC tags...
  2864. preg_match_all('~\[img(\s+width=([\d]+))?(\s+height=([\d]+))?(\s+width=([\d]+))?\s*\](?:<br>)*([^<">]+?)(?:<br>)*\[/img\]~i', $unparsed_signature, $matches);
  2865. // ... and all HTML ones.
  2866. preg_match_all('~<img\s+src=(?:")?((?:http://|ftp://|https://|ftps://).+?)(?:")?(?:\s+alt=(?:")?(.*?)(?:")?)?(?:\s?/)?>~i', $unparsed_signature, $matches2, PREG_PATTERN_ORDER);
  2867. // And stick the HTML in the BBC.
  2868. if (!empty($matches2))
  2869. {
  2870. foreach ($matches2[0] as $ind => $dummy)
  2871. {
  2872. $matches[0][] = $matches2[0][$ind];
  2873. $matches[1][] = '';
  2874. $matches[2][] = '';
  2875. $matches[3][] = '';
  2876. $matches[4][] = '';
  2877. $matches[5][] = '';
  2878. $matches[6][] = '';
  2879. $matches[7][] = $matches2[1][$ind];
  2880. }
  2881. }
  2882. $replaces = array();
  2883. // Try to find all the images!
  2884. if (!empty($matches))
  2885. {
  2886. foreach ($matches[0] as $key => $image)
  2887. {
  2888. $width = -1; $height = -1;
  2889. // Does it have predefined restraints? Width first.
  2890. if ($matches[6][$key])
  2891. $matches[2][$key] = $matches[6][$key];
  2892. if ($matches[2][$key] && $sig_limits[5] && $matches[2][$key] > $sig_limits[5])
  2893. {
  2894. $width = $sig_limits[5];
  2895. $matches[4][$key] = $matches[4][$key] * ($width / $matches[2][$key]);
  2896. }
  2897. elseif ($matches[2][$key])
  2898. $width = $matches[2][$key];
  2899. // ... and height.
  2900. if ($matches[4][$key] && $sig_limits[6] && $matches[4][$key] > $sig_limits[6])
  2901. {
  2902. $height = $sig_limits[6];
  2903. if ($width != -1)
  2904. $width = $width * ($height / $matches[4][$key]);
  2905. }
  2906. elseif ($matches[4][$key])
  2907. $height = $matches[4][$key];
  2908. // If the dimensions are still not fixed - we need to check the actual image.
  2909. if (($width == -1 && $sig_limits[5]) || ($height == -1 && $sig_limits[6]))
  2910. {
  2911. $sizes = url_image_size($matches[7][$key]);
  2912. if (is_array($sizes))
  2913. {
  2914. // Too wide?
  2915. if ($sizes[0] > $sig_limits[5] && $sig_limits[5])
  2916. {
  2917. $width = $sig_limits[5];
  2918. $sizes[1] = $sizes[1] * ($width / $sizes[0]);
  2919. }
  2920. // Too high?
  2921. if ($sizes[1] > $sig_limits[6] && $sig_limits[6])
  2922. {
  2923. $height = $sig_limits[6];
  2924. if ($width == -1)
  2925. $width = $sizes[0];
  2926. $width = $width * ($height / $sizes[1]);
  2927. }
  2928. elseif ($width != -1)
  2929. $height = $sizes[1];
  2930. }
  2931. }
  2932. // Did we come up with some changes? If so remake the string.
  2933. if ($width != -1 || $height != -1)
  2934. $replaces[$image] = '[img' . ($width != -1 ? ' width=' . round($width) : '') . ($height != -1 ? ' height=' . round($height) : '') . ']' . $matches[7][$key] . '[/img]';
  2935. }
  2936. if (!empty($replaces))
  2937. $value = str_replace(array_keys($replaces), array_values($replaces), $value);
  2938. }
  2939. }
  2940. // Any disabled BBC?
  2941. $disabledSigBBC = implode('|', $disabledTags);
  2942. if (!empty($disabledSigBBC))
  2943. {
  2944. if (preg_match('~\[(' . $disabledSigBBC . '[ =\]/])~i', $unparsed_signature, $matches) !== false && isset($matches[1]))
  2945. {
  2946. $disabledTags = array_unique($disabledTags);
  2947. $txt['profile_error_signature_disabled_bbc'] = sprintf($txt['profile_error_signature_disabled_bbc'], implode(', ', $disabledTags));
  2948. return 'signature_disabled_bbc';
  2949. }
  2950. }
  2951. }
  2952. preparsecode($value);
  2953. // Too long?
  2954. if (!allowedTo('admin_forum') && !empty($sig_limits[1]) && $smcFunc['strlen'](str_replace('<br>', "\n", $value)) > $sig_limits[1])
  2955. {
  2956. $_POST['signature'] = trim($smcFunc['htmlspecialchars'](str_replace('<br>', "\n", $value), ENT_QUOTES));
  2957. $txt['profile_error_signature_max_length'] = sprintf($txt['profile_error_signature_max_length'], $sig_limits[1]);
  2958. return 'signature_max_length';
  2959. }
  2960. return true;
  2961. }
  2962. /**
  2963. * Validate an email address.
  2964. *
  2965. * @param string $email
  2966. * @param int $memID = 0
  2967. * @return boolean|string
  2968. */
  2969. function profileValidateEmail($email, $memID = 0)
  2970. {
  2971. global $smcFunc, $context;
  2972. $email = strtr($email, array('&#039;' => '\''));
  2973. // Check the name and email for validity.
  2974. if (trim($email) == '')
  2975. return 'no_email';
  2976. if (preg_match('~^[0-9A-Za-z=_+\-/][0-9A-Za-z=_\'+\-/\.]*@[\w\-]+(\.[\w\-]+)*(\.[\w]{2,6})$~', $email) == 0)
  2977. return 'bad_email';
  2978. // Email addresses should be and stay unique.
  2979. $request = $smcFunc['db_query']('', '
  2980. SELECT id_member
  2981. FROM {db_prefix}members
  2982. WHERE ' . ($memID != 0 ? 'id_member != {int:selected_member} AND ' : '') . '
  2983. email_address = {string:email_address}
  2984. LIMIT 1',
  2985. array(
  2986. 'selected_member' => $memID,
  2987. 'email_address' => $email,
  2988. )
  2989. );
  2990. if ($smcFunc['db_num_rows']($request) > 0)
  2991. return 'email_taken';
  2992. $smcFunc['db_free_result']($request);
  2993. return true;
  2994. }
  2995. /**
  2996. * Reload a users settings.
  2997. */
  2998. function profileReloadUser()
  2999. {
  3000. global $sourcedir, $modSettings, $context, $cur_profile, $smcFunc, $profile_vars;
  3001. // Log them back in - using the verify password as they must have matched and this one doesn't get changed by anyone!
  3002. if (isset($_POST['passwrd2']) && $_POST['passwrd2'] != '')
  3003. {
  3004. require_once($sourcedir . '/Subs-Auth.php');
  3005. setLoginCookie(60 * $modSettings['cookieTime'], $context['id_member'], sha1(sha1(strtolower($cur_profile['member_name']) . un_htmlspecialchars($_POST['passwrd2'])) . $cur_profile['password_salt']));
  3006. }
  3007. loadUserSettings();
  3008. writeLog();
  3009. }
  3010. /**
  3011. * Send the user a new activation email if they need to reactivate!
  3012. */
  3013. function profileSendActivation()
  3014. {
  3015. global $sourcedir, $profile_vars, $txt, $context, $scripturl, $smcFunc, $cookiename, $cur_profile, $language, $modSettings;
  3016. require_once($sourcedir . '/Subs-Post.php');
  3017. // Shouldn't happen but just in case.
  3018. if (empty($profile_vars['email_address']))
  3019. return;
  3020. $replacements = array(
  3021. 'ACTIVATIONLINK' => $scripturl . '?action=activate;u=' . $context['id_member'] . ';code=' . $profile_vars['validation_code'],
  3022. 'ACTIVATIONCODE' => $profile_vars['validation_code'],
  3023. 'ACTIVATIONLINKWITHOUTCODE' => $scripturl . '?action=activate;u=' . $context['id_member'],
  3024. );
  3025. // Send off the email.
  3026. $emaildata = loadEmailTemplate('activate_reactivate', $replacements, empty($cur_profile['lngfile']) || empty($modSettings['userLanguage']) ? $language : $cur_profile['lngfile']);
  3027. sendmail($profile_vars['email_address'], $emaildata['subject'], $emaildata['body'], null, 'reactivate', false, 0);
  3028. // Log the user out.
  3029. $smcFunc['db_query']('', '
  3030. DELETE FROM {db_prefix}log_online
  3031. WHERE id_member = {int:selected_member}',
  3032. array(
  3033. 'selected_member' => $context['id_member'],
  3034. )
  3035. );
  3036. $_SESSION['log_time'] = 0;
  3037. $_SESSION['login_' . $cookiename] = serialize(array(0, '', 0));
  3038. if (isset($_COOKIE[$cookiename]))
  3039. $_COOKIE[$cookiename] = '';
  3040. loadUserSettings();
  3041. $context['user']['is_logged'] = false;
  3042. $context['user']['is_guest'] = true;
  3043. redirectexit('action=sendactivation');
  3044. }
  3045. /**
  3046. * Function to allow the user to choose group membership etc...
  3047. *
  3048. * @param int $memID id_member
  3049. */
  3050. function groupMembership($memID)
  3051. {
  3052. global $txt, $scripturl, $user_profile, $user_info, $context, $smcFunc;
  3053. $curMember = $user_profile[$memID];
  3054. $context['primary_group'] = $curMember['id_group'];
  3055. // Can they manage groups?
  3056. $context['can_manage_membergroups'] = allowedTo('manage_membergroups');
  3057. $context['can_manage_protected'] = allowedTo('admin_forum');
  3058. $context['can_edit_primary'] = $context['can_manage_protected'];
  3059. $context['update_message'] = isset($_GET['msg']) && isset($txt['group_membership_msg_' . $_GET['msg']]) ? $txt['group_membership_msg_' . $_GET['msg']] : '';
  3060. // Get all the groups this user is a member of.
  3061. $groups = explode(',', $curMember['additional_groups']);
  3062. $groups[] = $curMember['id_group'];
  3063. // Ensure the query doesn't croak!
  3064. if (empty($groups))
  3065. $groups = array(0);
  3066. // Just to be sure...
  3067. foreach ($groups as $k => $v)
  3068. $groups[$k] = (int) $v;
  3069. // Get all the membergroups they can join.
  3070. $request = $smcFunc['db_query']('', '
  3071. SELECT mg.id_group, mg.group_name, mg.description, mg.group_type, mg.online_color, mg.hidden,
  3072. IFNULL(lgr.id_member, 0) AS pending
  3073. FROM {db_prefix}membergroups AS mg
  3074. LEFT JOIN {db_prefix}log_group_requests AS lgr ON (lgr.id_member = {int:selected_member} AND lgr.id_group = mg.id_group AND lgr.status = {int:status_open})
  3075. WHERE (mg.id_group IN ({array_int:group_list})
  3076. OR mg.group_type > {int:nonjoin_group_id})
  3077. AND mg.min_posts = {int:min_posts}
  3078. AND mg.id_group != {int:moderator_group}
  3079. ORDER BY group_name',
  3080. array(
  3081. 'group_list' => $groups,
  3082. 'selected_member' => $memID,
  3083. 'status_open' => 0,
  3084. 'nonjoin_group_id' => 1,
  3085. 'min_posts' => -1,
  3086. 'moderator_group' => 3,
  3087. )
  3088. );
  3089. // This beast will be our group holder.
  3090. $context['groups'] = array(
  3091. 'member' => array(),
  3092. 'available' => array()
  3093. );
  3094. while ($row = $smcFunc['db_fetch_assoc']($request))
  3095. {
  3096. // Can they edit their primary group?
  3097. if (($row['id_group'] == $context['primary_group'] && $row['group_type'] > 1) || ($row['hidden'] != 2 && $context['primary_group'] == 0 && in_array($row['id_group'], $groups)))
  3098. $context['can_edit_primary'] = true;
  3099. // If they can't manage (protected) groups, and it's not publically joinable or already assigned, they can't see it.
  3100. if (((!$context['can_manage_protected'] && $row['group_type'] == 1) || (!$context['can_manage_membergroups'] && $row['group_type'] == 0)) && $row['id_group'] != $context['primary_group'])
  3101. continue;
  3102. $context['groups'][in_array($row['id_group'], $groups) ? 'member' : 'available'][$row['id_group']] = array(
  3103. 'id' => $row['id_group'],
  3104. 'name' => $row['group_name'],
  3105. 'desc' => $row['description'],
  3106. 'color' => $row['online_color'],
  3107. 'type' => $row['group_type'],
  3108. 'pending' => $row['pending'],
  3109. 'is_primary' => $row['id_group'] == $context['primary_group'],
  3110. 'can_be_primary' => $row['hidden'] != 2,
  3111. // Anything more than this needs to be done through account settings for security.
  3112. 'can_leave' => $row['id_group'] != 1 && $row['group_type'] > 1 ? true : false,
  3113. );
  3114. }
  3115. $smcFunc['db_free_result']($request);
  3116. // Add registered members on the end.
  3117. $context['groups']['member'][0] = array(
  3118. 'id' => 0,
  3119. 'name' => $txt['regular_members'],
  3120. 'desc' => $txt['regular_members_desc'],
  3121. 'type' => 0,
  3122. 'is_primary' => $context['primary_group'] == 0 ? true : false,
  3123. 'can_be_primary' => true,
  3124. 'can_leave' => 0,
  3125. );
  3126. // No changing primary one unless you have enough groups!
  3127. if (count($context['groups']['member']) < 2)
  3128. $context['can_edit_primary'] = false;
  3129. // In the special case that someone is requesting membership of a group, setup some special context vars.
  3130. if (isset($_REQUEST['request']) && isset($context['groups']['available'][(int) $_REQUEST['request']]) && $context['groups']['available'][(int) $_REQUEST['request']]['type'] == 2)
  3131. $context['group_request'] = $context['groups']['available'][(int) $_REQUEST['request']];
  3132. }
  3133. /**
  3134. * This function actually makes all the group changes
  3135. *
  3136. * @param array $profile_vars
  3137. * @param array $post_errors
  3138. * @param int $memID id_member
  3139. * @return mixed
  3140. */
  3141. function groupMembership2($profile_vars, $post_errors, $memID)
  3142. {
  3143. global $user_info, $sourcedir, $context, $user_profile, $modSettings, $txt, $smcFunc, $scripturl, $language;
  3144. // Let's be extra cautious...
  3145. if (!$context['user']['is_owner'] || empty($modSettings['show_group_membership']))
  3146. isAllowedTo('manage_membergroups');
  3147. if (!isset($_REQUEST['gid']) && !isset($_POST['primary']))
  3148. fatal_lang_error('no_access', false);
  3149. checkSession(isset($_GET['gid']) ? 'get' : 'post');
  3150. $old_profile = &$user_profile[$memID];
  3151. $context['can_manage_membergroups'] = allowedTo('manage_membergroups');
  3152. $context['can_manage_protected'] = allowedTo('admin_forum');
  3153. // By default the new primary is the old one.
  3154. $newPrimary = $old_profile['id_group'];
  3155. $addGroups = array_flip(explode(',', $old_profile['additional_groups']));
  3156. $canChangePrimary = $old_profile['id_group'] == 0 ? 1 : 0;
  3157. $changeType = isset($_POST['primary']) ? 'primary' : (isset($_POST['req']) ? 'request' : 'free');
  3158. // One way or another, we have a target group in mind...
  3159. $group_id = isset($_REQUEST['gid']) ? (int) $_REQUEST['gid'] : (int) $_POST['primary'];
  3160. $foundTarget = $changeType == 'primary' && $group_id == 0 ? true : false;
  3161. // Sanity check!!
  3162. if ($group_id == 1)
  3163. isAllowedTo('admin_forum');
  3164. // Protected groups too!
  3165. else
  3166. {
  3167. $request = $smcFunc['db_query']('', '
  3168. SELECT group_type
  3169. FROM {db_prefix}membergroups
  3170. WHERE id_group = {int:current_group}
  3171. LIMIT {int:limit}',
  3172. array(
  3173. 'current_group' => $group_id,
  3174. 'limit' => 1,
  3175. )
  3176. );
  3177. list ($is_protected) = $smcFunc['db_fetch_row']($request);
  3178. $smcFunc['db_free_result']($request);
  3179. if ($is_protected == 1)
  3180. isAllowedTo('admin_forum');
  3181. }
  3182. // What ever we are doing, we need to determine if changing primary is possible!
  3183. $request = $smcFunc['db_query']('', '
  3184. SELECT id_group, group_type, hidden, group_name
  3185. FROM {db_prefix}membergroups
  3186. WHERE id_group IN ({int:group_list}, {int:current_group})',
  3187. array(
  3188. 'group_list' => $group_id,
  3189. 'current_group' => $old_profile['id_group'],
  3190. )
  3191. );
  3192. while ($row = $smcFunc['db_fetch_assoc']($request))
  3193. {
  3194. // Is this the new group?
  3195. if ($row['id_group'] == $group_id)
  3196. {
  3197. $foundTarget = true;
  3198. $group_name = $row['group_name'];
  3199. // Does the group type match what we're doing - are we trying to request a non-requestable group?
  3200. if ($changeType == 'request' && $row['group_type'] != 2)
  3201. fatal_lang_error('no_access', false);
  3202. // What about leaving a requestable group we are not a member of?
  3203. elseif ($changeType == 'free' && $row['group_type'] == 2 && $old_profile['id_group'] != $row['id_group'] && !isset($addGroups[$row['id_group']]))
  3204. fatal_lang_error('no_access', false);
  3205. elseif ($changeType == 'free' && $row['group_type'] != 3 && $row['group_type'] != 2)
  3206. fatal_lang_error('no_access', false);
  3207. // We can't change the primary group if this is hidden!
  3208. if ($row['hidden'] == 2)
  3209. $canChangePrimary = false;
  3210. }
  3211. // If this is their old primary, can we change it?
  3212. if ($row['id_group'] == $old_profile['id_group'] && ($row['group_type'] > 1 || $context['can_manage_membergroups']) && $canChangePrimary !== false)
  3213. $canChangePrimary = 1;
  3214. // If we are not doing a force primary move, don't do it automatically if current primary is not 0.
  3215. if ($changeType != 'primary' && $old_profile['id_group'] != 0)
  3216. $canChangePrimary = false;
  3217. // If this is the one we are acting on, can we even act?
  3218. if ((!$context['can_manage_protected'] && $row['group_type'] == 1) || (!$context['can_manage_membergroups'] && $row['group_type'] == 0))
  3219. $canChangePrimary = false;
  3220. }
  3221. $smcFunc['db_free_result']($request);
  3222. // Didn't find the target?
  3223. if (!$foundTarget)
  3224. fatal_lang_error('no_access', false);
  3225. // Final security check, don't allow users to promote themselves to admin.
  3226. if ($context['can_manage_membergroups'] && !allowedTo('admin_forum'))
  3227. {
  3228. $request = $smcFunc['db_query']('', '
  3229. SELECT COUNT(permission)
  3230. FROM {db_prefix}permissions
  3231. WHERE id_group = {int:selected_group}
  3232. AND permission = {string:admin_forum}
  3233. AND add_deny = {int:not_denied}',
  3234. array(
  3235. 'selected_group' => $group_id,
  3236. 'not_denied' => 1,
  3237. 'admin_forum' => 'admin_forum',
  3238. )
  3239. );
  3240. list ($disallow) = $smcFunc['db_fetch_row']($request);
  3241. $smcFunc['db_free_result']($request);
  3242. if ($disallow)
  3243. isAllowedTo('admin_forum');
  3244. }
  3245. // If we're requesting, add the note then return.
  3246. if ($changeType == 'request')
  3247. {
  3248. $request = $smcFunc['db_query']('', '
  3249. SELECT id_member
  3250. FROM {db_prefix}log_group_requests
  3251. WHERE id_member = {int:selected_member}
  3252. AND id_group = {int:selected_group}
  3253. AND status = {int:status_open}',
  3254. array(
  3255. 'selected_member' => $memID,
  3256. 'selected_group' => $group_id,
  3257. 'status_open' => 0,
  3258. )
  3259. );
  3260. if ($smcFunc['db_num_rows']($request) != 0)
  3261. fatal_lang_error('profile_error_already_requested_group');
  3262. $smcFunc['db_free_result']($request);
  3263. // Log the request.
  3264. $smcFunc['db_insert']('',
  3265. '{db_prefix}log_group_requests',
  3266. array(
  3267. 'id_member' => 'int', 'id_group' => 'int', 'time_applied' => 'int', 'reason' => 'string-65534',
  3268. 'status' => 'int', 'id_member_acted' => 'int', 'member_name_acted' => 'string', 'time_acted' => 'int', 'act_reason' => 'string',
  3269. ),
  3270. array(
  3271. $memID, $group_id, time(), $_POST['reason'],
  3272. 0, 0, '', 0, '',
  3273. ),
  3274. array('id_request')
  3275. );
  3276. // Set up some data for our background task...
  3277. $data = serialize(array('id_member' => $memID, 'member_name' => $user_info['name'], 'id_group' => $group_id, 'group_name' => $group_name, 'reason' => $_POST['reason'], 'time' => time()));
  3278. // Add a background task to handle notifying people of this request
  3279. $smcFunc['db_insert']('insert', '{db_prefix}background_tasks',
  3280. array('task_file' => 'string-255', 'task_class' => 'string-255', 'task_data' => 'string', 'claimed_time' => 'int'),
  3281. array('$sourcedir/tasks/GroupReq-Notify.php', 'GroupReq_Notify_Background', $data, 0), array()
  3282. );
  3283. return $changeType;
  3284. }
  3285. // Otherwise we are leaving/joining a group.
  3286. elseif ($changeType == 'free')
  3287. {
  3288. // Are we leaving?
  3289. if ($old_profile['id_group'] == $group_id || isset($addGroups[$group_id]))
  3290. {
  3291. if ($old_profile['id_group'] == $group_id)
  3292. $newPrimary = 0;
  3293. else
  3294. unset($addGroups[$group_id]);
  3295. }
  3296. // ... if not, must be joining.
  3297. else
  3298. {
  3299. // Can we change the primary, and do we want to?
  3300. if ($canChangePrimary)
  3301. {
  3302. if ($old_profile['id_group'] != 0)
  3303. $addGroups[$old_profile['id_group']] = -1;
  3304. $newPrimary = $group_id;
  3305. }
  3306. // Otherwise it's an additional group...
  3307. else
  3308. $addGroups[$group_id] = -1;
  3309. }
  3310. }
  3311. // Finally, we must be setting the primary.
  3312. elseif ($canChangePrimary)
  3313. {
  3314. if ($old_profile['id_group'] != 0)
  3315. $addGroups[$old_profile['id_group']] = -1;
  3316. if (isset($addGroups[$group_id]))
  3317. unset($addGroups[$group_id]);
  3318. $newPrimary = $group_id;
  3319. }
  3320. // Finally, we can make the changes!
  3321. foreach ($addGroups as $id => $dummy)
  3322. if (empty($id))
  3323. unset($addGroups[$id]);
  3324. $addGroups = implode(',', array_flip($addGroups));
  3325. // Ensure that we don't cache permissions if the group is changing.
  3326. if ($context['user']['is_owner'])
  3327. $_SESSION['mc']['time'] = 0;
  3328. else
  3329. updateSettings(array('settings_updated' => time()));
  3330. updateMemberData($memID, array('id_group' => $newPrimary, 'additional_groups' => $addGroups));
  3331. return $changeType;
  3332. }
  3333. ?>