Profile-Modify.php 127 KB

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