2
0

Profile-Modify.php 125 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726
  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 2013 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, $context, $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, $modSettings, $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, $modSettings, $user_profile;
  834. global $context, $settings, $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, $modSettings;
  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. // Heh, I'm lazy, do it the easy way...
  1207. foreach ($buddiesArray as $key => $buddy)
  1208. if ($buddy == (int) $_GET['remove'])
  1209. unset($buddiesArray[$key]);
  1210. // Make the changes.
  1211. $user_profile[$memID]['buddy_list'] = implode(',', $buddiesArray);
  1212. updateMemberData($memID, array('buddy_list' => $user_profile[$memID]['buddy_list']));
  1213. // Redirect off the page because we don't like all this ugly query stuff to stick in the history.
  1214. redirectexit('action=profile;area=lists;sa=buddies;u=' . $memID);
  1215. }
  1216. elseif (isset($_POST['new_buddy']))
  1217. {
  1218. checkSession();
  1219. // Prepare the string for extraction...
  1220. $_POST['new_buddy'] = strtr($smcFunc['htmlspecialchars']($_POST['new_buddy'], ENT_QUOTES), array('&quot;' => '"'));
  1221. preg_match_all('~"([^"]+)"~', $_POST['new_buddy'], $matches);
  1222. $new_buddies = array_unique(array_merge($matches[1], explode(',', preg_replace('~"[^"]+"~', '', $_POST['new_buddy']))));
  1223. foreach ($new_buddies as $k => $dummy)
  1224. {
  1225. $new_buddies[$k] = strtr(trim($new_buddies[$k]), array('\'' => '&#039;'));
  1226. if (strlen($new_buddies[$k]) == 0 || in_array($new_buddies[$k], array($user_profile[$memID]['member_name'], $user_profile[$memID]['real_name'])))
  1227. unset($new_buddies[$k]);
  1228. }
  1229. call_integration_hook('integrate_add_buddies', array($memID, &$new_buddies));
  1230. if (!empty($new_buddies))
  1231. {
  1232. // Now find out the id_member of the buddy.
  1233. $request = $smcFunc['db_query']('', '
  1234. SELECT id_member
  1235. FROM {db_prefix}members
  1236. WHERE member_name IN ({array_string:new_buddies}) OR real_name IN ({array_string:new_buddies})
  1237. LIMIT {int:count_new_buddies}',
  1238. array(
  1239. 'new_buddies' => $new_buddies,
  1240. 'count_new_buddies' => count($new_buddies),
  1241. )
  1242. );
  1243. // Add the new member to the buddies array.
  1244. while ($row = $smcFunc['db_fetch_assoc']($request))
  1245. $buddiesArray[] = (int) $row['id_member'];
  1246. $smcFunc['db_free_result']($request);
  1247. // Now update the current users buddy list.
  1248. $user_profile[$memID]['buddy_list'] = implode(',', $buddiesArray);
  1249. updateMemberData($memID, array('buddy_list' => $user_profile[$memID]['buddy_list']));
  1250. }
  1251. // Back to the buddy list!
  1252. redirectexit('action=profile;area=lists;sa=buddies;u=' . $memID);
  1253. }
  1254. // Get all the users "buddies"...
  1255. $buddies = array();
  1256. if (!empty($buddiesArray))
  1257. {
  1258. $result = $smcFunc['db_query']('', '
  1259. SELECT id_member
  1260. FROM {db_prefix}members
  1261. WHERE id_member IN ({array_int:buddy_list})
  1262. ORDER BY real_name
  1263. LIMIT {int:buddy_list_count}',
  1264. array(
  1265. 'buddy_list' => $buddiesArray,
  1266. 'buddy_list_count' => substr_count($user_profile[$memID]['buddy_list'], ',') + 1,
  1267. )
  1268. );
  1269. while ($row = $smcFunc['db_fetch_assoc']($result))
  1270. $buddies[] = $row['id_member'];
  1271. $smcFunc['db_free_result']($result);
  1272. }
  1273. $context['buddy_count'] = count($buddies);
  1274. // Load all the members up.
  1275. loadMemberData($buddies, false, 'profile');
  1276. // Setup the context for each buddy.
  1277. $context['buddies'] = array();
  1278. foreach ($buddies as $buddy)
  1279. {
  1280. loadMemberContext($buddy);
  1281. $context['buddies'][$buddy] = $memberContext[$buddy];
  1282. }
  1283. call_integration_hook('integrate_view_buddies', array($memID));
  1284. }
  1285. /**
  1286. * Allows the user to view their ignore list, as well as the option to manage members on it.
  1287. *
  1288. * @param int $memID id_member
  1289. */
  1290. function editIgnoreList($memID)
  1291. {
  1292. global $txt, $scripturl, $modSettings;
  1293. global $context, $user_profile, $memberContext, $smcFunc;
  1294. // For making changes!
  1295. $ignoreArray = explode(',', $user_profile[$memID]['pm_ignore_list']);
  1296. foreach ($ignoreArray as $k => $dummy)
  1297. if ($dummy == '')
  1298. unset($ignoreArray[$k]);
  1299. // Removing a member from the ignore list?
  1300. if (isset($_GET['remove']))
  1301. {
  1302. checkSession('get');
  1303. // Heh, I'm lazy, do it the easy way...
  1304. foreach ($ignoreArray as $key => $id_remove)
  1305. if ($id_remove == (int) $_GET['remove'])
  1306. unset($ignoreArray[$key]);
  1307. // Make the changes.
  1308. $user_profile[$memID]['pm_ignore_list'] = implode(',', $ignoreArray);
  1309. updateMemberData($memID, array('pm_ignore_list' => $user_profile[$memID]['pm_ignore_list']));
  1310. // Redirect off the page because we don't like all this ugly query stuff to stick in the history.
  1311. redirectexit('action=profile;area=lists;sa=ignore;u=' . $memID);
  1312. }
  1313. elseif (isset($_POST['new_ignore']))
  1314. {
  1315. checkSession();
  1316. // Prepare the string for extraction...
  1317. $_POST['new_ignore'] = strtr($smcFunc['htmlspecialchars']($_POST['new_ignore'], ENT_QUOTES), array('&quot;' => '"'));
  1318. preg_match_all('~"([^"]+)"~', $_POST['new_ignore'], $matches);
  1319. $new_entries = array_unique(array_merge($matches[1], explode(',', preg_replace('~"[^"]+"~', '', $_POST['new_ignore']))));
  1320. foreach ($new_entries as $k => $dummy)
  1321. {
  1322. $new_entries[$k] = strtr(trim($new_entries[$k]), array('\'' => '&#039;'));
  1323. if (strlen($new_entries[$k]) == 0 || in_array($new_entries[$k], array($user_profile[$memID]['member_name'], $user_profile[$memID]['real_name'])))
  1324. unset($new_entries[$k]);
  1325. }
  1326. if (!empty($new_entries))
  1327. {
  1328. // Now find out the id_member for the members in question.
  1329. $request = $smcFunc['db_query']('', '
  1330. SELECT id_member
  1331. FROM {db_prefix}members
  1332. WHERE member_name IN ({array_string:new_entries}) OR real_name IN ({array_string:new_entries})
  1333. LIMIT {int:count_new_entries}',
  1334. array(
  1335. 'new_entries' => $new_entries,
  1336. 'count_new_entries' => count($new_entries),
  1337. )
  1338. );
  1339. // Add the new member to the buddies array.
  1340. while ($row = $smcFunc['db_fetch_assoc']($request))
  1341. $ignoreArray[] = (int) $row['id_member'];
  1342. $smcFunc['db_free_result']($request);
  1343. // Now update the current users buddy list.
  1344. $user_profile[$memID]['pm_ignore_list'] = implode(',', $ignoreArray);
  1345. updateMemberData($memID, array('pm_ignore_list' => $user_profile[$memID]['pm_ignore_list']));
  1346. }
  1347. // Back to the list of pityful people!
  1348. redirectexit('action=profile;area=lists;sa=ignore;u=' . $memID);
  1349. }
  1350. // Initialise the list of members we're ignoring.
  1351. $ignored = array();
  1352. if (!empty($ignoreArray))
  1353. {
  1354. $result = $smcFunc['db_query']('', '
  1355. SELECT id_member
  1356. FROM {db_prefix}members
  1357. WHERE id_member IN ({array_int:ignore_list})
  1358. ORDER BY real_name
  1359. LIMIT {int:ignore_list_count}',
  1360. array(
  1361. 'ignore_list' => $ignoreArray,
  1362. 'ignore_list_count' => substr_count($user_profile[$memID]['pm_ignore_list'], ',') + 1,
  1363. )
  1364. );
  1365. while ($row = $smcFunc['db_fetch_assoc']($result))
  1366. $ignored[] = $row['id_member'];
  1367. $smcFunc['db_free_result']($result);
  1368. }
  1369. $context['ignore_count'] = count($ignored);
  1370. // Load all the members up.
  1371. loadMemberData($ignored, false, 'profile');
  1372. // Setup the context for each buddy.
  1373. $context['ignore_list'] = array();
  1374. foreach ($ignored as $ignore_member)
  1375. {
  1376. loadMemberContext($ignore_member);
  1377. $context['ignore_list'][$ignore_member] = $memberContext[$ignore_member];
  1378. }
  1379. }
  1380. /**
  1381. * @todo Needs a description
  1382. *
  1383. * @param int $memID id_member
  1384. */
  1385. function account($memID)
  1386. {
  1387. global $context, $txt;
  1388. loadThemeOptions($memID);
  1389. if (allowedTo(array('profile_identity_own', 'profile_identity_any', 'profile_password_own', 'profile_password_any')))
  1390. loadCustomFields($memID, 'account');
  1391. $context['sub_template'] = 'edit_options';
  1392. $context['page_desc'] = $txt['account_info'];
  1393. setupProfileContext(
  1394. array(
  1395. 'member_name', 'real_name', 'date_registered', 'posts', 'lngfile', 'hr',
  1396. 'id_group', 'hr',
  1397. 'email_address', 'hide_email', 'show_online', 'hr',
  1398. 'passwrd1', 'passwrd2', 'hr',
  1399. 'secret_question', 'secret_answer',
  1400. )
  1401. );
  1402. }
  1403. /**
  1404. * @todo Needs a description
  1405. *
  1406. * @param int $memID id_member
  1407. */
  1408. function forumProfile($memID)
  1409. {
  1410. global $context, $txt;
  1411. loadThemeOptions($memID);
  1412. if (allowedTo(array('profile_forum_own', 'profile_forum_any')))
  1413. loadCustomFields($memID, 'forumprofile');
  1414. $context['sub_template'] = 'edit_options';
  1415. $context['page_desc'] = $txt['forumProfile_info'];
  1416. $context['show_preview_button'] = true;
  1417. setupProfileContext(
  1418. array(
  1419. 'avatar_choice', 'hr', 'personal_text', 'hr',
  1420. 'bday1', 'location', 'gender', 'hr',
  1421. 'icq', 'aim', 'yim', 'skype', 'hr',
  1422. 'usertitle', 'signature', 'hr',
  1423. 'karma_good', 'hr',
  1424. 'website_title', 'website_url',
  1425. )
  1426. );
  1427. }
  1428. /**
  1429. * Recursive function to retrieve server-stored avatar files
  1430. *
  1431. * @param string $directory
  1432. * @param int $level
  1433. * @return array
  1434. */
  1435. function getAvatars($directory, $level)
  1436. {
  1437. global $context, $txt, $modSettings, $smcFunc;
  1438. $result = array();
  1439. // Open the directory..
  1440. $dir = dir($modSettings['avatar_directory'] . (!empty($directory) ? '/' : '') . $directory);
  1441. $dirs = array();
  1442. $files = array();
  1443. if (!$dir)
  1444. return array();
  1445. while ($line = $dir->read())
  1446. {
  1447. if (in_array($line, array('.', '..', 'blank.png', 'index.php')))
  1448. continue;
  1449. if (is_dir($modSettings['avatar_directory'] . '/' . $directory . (!empty($directory) ? '/' : '') . $line))
  1450. $dirs[] = $line;
  1451. else
  1452. $files[] = $line;
  1453. }
  1454. $dir->close();
  1455. // Sort the results...
  1456. natcasesort($dirs);
  1457. natcasesort($files);
  1458. if ($level == 0)
  1459. {
  1460. $result[] = array(
  1461. 'filename' => 'blank.png',
  1462. 'checked' => in_array($context['member']['avatar']['server_pic'], array('', 'blank.png')),
  1463. 'name' => $txt['no_pic'],
  1464. 'is_dir' => false
  1465. );
  1466. }
  1467. foreach ($dirs as $line)
  1468. {
  1469. $tmp = getAvatars($directory . (!empty($directory) ? '/' : '') . $line, $level + 1);
  1470. if (!empty($tmp))
  1471. $result[] = array(
  1472. 'filename' => $smcFunc['htmlspecialchars']($line),
  1473. 'checked' => strpos($context['member']['avatar']['server_pic'], $line . '/') !== false,
  1474. 'name' => '[' . $smcFunc['htmlspecialchars'](str_replace('_', ' ', $line)) . ']',
  1475. 'is_dir' => true,
  1476. 'files' => $tmp
  1477. );
  1478. unset($tmp);
  1479. }
  1480. foreach ($files as $line)
  1481. {
  1482. $filename = substr($line, 0, (strlen($line) - strlen(strrchr($line, '.'))));
  1483. $extension = substr(strrchr($line, '.'), 1);
  1484. // Make sure it is an image.
  1485. if (strcasecmp($extension, 'gif') != 0 && strcasecmp($extension, 'jpg') != 0 && strcasecmp($extension, 'jpeg') != 0 && strcasecmp($extension, 'png') != 0 && strcasecmp($extension, 'bmp') != 0)
  1486. continue;
  1487. $result[] = array(
  1488. 'filename' => $smcFunc['htmlspecialchars']($line),
  1489. 'checked' => $line == $context['member']['avatar']['server_pic'],
  1490. 'name' => $smcFunc['htmlspecialchars'](str_replace('_', ' ', $filename)),
  1491. 'is_dir' => false
  1492. );
  1493. if ($level == 1)
  1494. $context['avatar_list'][] = $directory . '/' . $line;
  1495. }
  1496. return $result;
  1497. }
  1498. /**
  1499. * @todo needs a description
  1500. *
  1501. * @param int $memID id_member
  1502. */
  1503. function theme($memID)
  1504. {
  1505. global $txt, $context, $user_profile, $modSettings, $settings, $user_info, $smcFunc;
  1506. loadThemeOptions($memID);
  1507. if (allowedTo(array('profile_extra_own', 'profile_extra_any')))
  1508. loadCustomFields($memID, 'theme');
  1509. $context['sub_template'] = 'edit_options';
  1510. $context['page_desc'] = $txt['theme_info'];
  1511. setupProfileContext(
  1512. array(
  1513. 'id_theme', 'smiley_set', 'hr',
  1514. 'time_format', 'time_offset', 'hr',
  1515. 'theme_settings',
  1516. )
  1517. );
  1518. }
  1519. /**
  1520. * Changing authentication method? Only appropriate for people using OpenID.
  1521. *
  1522. * @param int $memID id_member
  1523. * @param bool $saving = false
  1524. */
  1525. function authentication($memID, $saving = false)
  1526. {
  1527. global $context, $cur_profile, $sourcedir, $txt, $post_errors, $modSettings;
  1528. loadLanguage('Login');
  1529. // We are saving?
  1530. if ($saving)
  1531. {
  1532. // Moving to password passed authentication?
  1533. if ($_POST['authenticate'] == 'passwd')
  1534. {
  1535. // Didn't enter anything?
  1536. if ($_POST['passwrd1'] == '')
  1537. $post_errors[] = 'no_password';
  1538. // Do the two entries for the password even match?
  1539. elseif (!isset($_POST['passwrd2']) || $_POST['passwrd1'] != $_POST['passwrd2'])
  1540. $post_errors[] = 'bad_new_password';
  1541. // Is it valid?
  1542. else
  1543. {
  1544. require_once($sourcedir . '/Subs-Auth.php');
  1545. $passwordErrors = validatePassword($_POST['passwrd1'], $cur_profile['member_name'], array($cur_profile['real_name'], $cur_profile['email_address']));
  1546. // Were there errors?
  1547. if ($passwordErrors != null)
  1548. $post_errors[] = 'password_' . $passwordErrors;
  1549. }
  1550. if (empty($post_errors))
  1551. {
  1552. // Integration?
  1553. call_integration_hook('integrate_reset_pass', array($cur_profile['member_name'], $cur_profile['member_name'], $_POST['passwrd1']));
  1554. // Go then.
  1555. $passwd = sha1(strtolower($cur_profile['member_name']) . un_htmlspecialchars($_POST['passwrd1']));
  1556. // Do the important bits.
  1557. updateMemberData($memID, array('openid_uri' => '', 'passwd' => $passwd));
  1558. if ($context['user']['is_owner'])
  1559. {
  1560. setLoginCookie(60 * $modSettings['cookieTime'], $memID, sha1(sha1(strtolower($cur_profile['member_name']) . un_htmlspecialchars($_POST['passwrd2'])) . $cur_profile['password_salt']));
  1561. redirectexit('action=profile;area=authentication;updated');
  1562. }
  1563. else
  1564. redirectexit('action=profile;u=' . $memID);
  1565. }
  1566. return true;
  1567. }
  1568. // Not right yet!
  1569. elseif ($_POST['authenticate'] == 'openid' && !empty($_POST['openid_identifier']))
  1570. {
  1571. require_once($sourcedir . '/Subs-OpenID.php');
  1572. $_POST['openid_identifier'] = smf_openID_canonize($_POST['openid_identifier']);
  1573. if (smf_openid_member_exists($_POST['openid_identifier']))
  1574. $post_errors[] = 'openid_in_use';
  1575. elseif (empty($post_errors))
  1576. {
  1577. // Authenticate using the new OpenID URI first to make sure they didn't make a mistake.
  1578. if ($context['user']['is_owner'])
  1579. {
  1580. $_SESSION['new_openid_uri'] = $_POST['openid_identifier'];
  1581. smf_openID_validate($_POST['openid_identifier'], false, null, 'change_uri');
  1582. }
  1583. else
  1584. updateMemberData($memID, array('openid_uri' => $_POST['openid_identifier']));
  1585. }
  1586. }
  1587. }
  1588. // Some stuff.
  1589. $context['member']['openid_uri'] = $cur_profile['openid_uri'];
  1590. $context['auth_method'] = empty($cur_profile['openid_uri']) ? 'password' : 'openid';
  1591. $context['sub_template'] = 'authentication_method';
  1592. }
  1593. /**
  1594. * Display the notifications and settings for changes.
  1595. *
  1596. * @param int $memID id_member
  1597. */
  1598. function notification($memID)
  1599. {
  1600. global $txt, $scripturl, $user_profile, $user_info, $context, $modSettings, $smcFunc, $sourcedir, $settings;
  1601. // Going to want this for consistency.
  1602. loadCSSFile('admin.css', array(), 'admin');
  1603. // This is just a bootstrap for everything else.
  1604. $sa = array(
  1605. 'alerts' => 'alert_configuration',
  1606. 'topics' => 'alert_notifications_topics',
  1607. 'boards' => 'alert_notifications_boards',
  1608. );
  1609. $subAction = !empty($_GET['sa']) && isset($sa[$_GET['sa']]) ? $_GET['sa'] : 'alerts';
  1610. $context['sub_template'] = $sa[$subAction];
  1611. $context[$context['profile_menu_name']]['tab_data'] = array(
  1612. 'title' => $txt['notification'],
  1613. 'help' => '',
  1614. 'description' => $txt['notification_info'],
  1615. );
  1616. $sa[$subAction]($memID);
  1617. }
  1618. function alert_configuration($memID)
  1619. {
  1620. global $txt, $scripturl, $user_profile, $user_info, $context, $modSettings, $smcFunc, $sourcedir, $settings;
  1621. $context['token_check'] = 'profile-nt' . $memID;
  1622. is_not_guest();
  1623. if (!$context['user']['is_owner'])
  1624. isAllowedTo('profile_extra_any');
  1625. // What options are set?
  1626. $context['member'] += array(
  1627. 'notify_announcements' => $user_profile[$memID]['notify_announcements'],
  1628. 'notify_send_body' => $user_profile[$memID]['notify_send_body'],
  1629. 'notify_types' => $user_profile[$memID]['notify_types'],
  1630. 'notify_regularity' => $user_profile[$memID]['notify_regularity'],
  1631. );
  1632. loadThemeOptions($memID);
  1633. // Now load all the values for this user.
  1634. require_once($sourcedir . '/Subs-Notify.php');
  1635. $prefs = getNotifyPrefs($memID);
  1636. // And we might as well now perform the splicing of default values.
  1637. if (!empty($prefs[0]))
  1638. foreach ($prefs[0] as $this_pref => $value)
  1639. if (!isset($prefs[$memID][$this_pref]))
  1640. $prefs[$memID][$this_pref] = $value;
  1641. $context['alert_prefs'] = !empty($prefs[$memID]) ? $prefs[$memID] : array();
  1642. // Now for the exciting stuff.
  1643. // We have groups of items, each item has both an alert and an email key as well as an optional help string.
  1644. // Valid values for these keys are 'always', 'yes', 'never'; if using always or never you should add a help string.
  1645. $alert_types = array(
  1646. 'msg' => array(
  1647. 'topic_notify' => array('alert' => 'yes', 'email' => 'yes'),
  1648. 'board_notify' => array('alert' => 'yes', 'email' => 'yes'),
  1649. 'msg_mention' => array('alert' => 'yes', 'email' => 'yes'),
  1650. 'msg_quote' => array('alert' => 'yes', 'email' => 'yes'),
  1651. 'msg_like' => array('alert' => 'yes', 'email' => 'never'),
  1652. ),
  1653. 'pm' => array(
  1654. 'pm_new' => array('alert' => 'always', 'email' => 'yes', 'help' => 'alert_pm_new', 'permission' => array('name' => 'pm_read', 'is_board' => false)),
  1655. 'pm_reply' => array('alert' => 'always', 'email' => 'yes', 'help' => 'alert_pm_new', 'permission' => array('name' => 'pm_send', 'is_board' => false)),
  1656. ),
  1657. 'moderation' => array(
  1658. 'msg_report' => array('alert' => 'yes', 'email' => 'yes', 'permission' => array('name' => 'moderate_board', 'is_board' => true)),
  1659. 'msg_report_reply' => array('alert' => 'yes', 'email' => 'yes', 'permission' => array('name' => 'moderate_board', 'is_board' => true)),
  1660. ),
  1661. 'members' => array(
  1662. 'member_register' => array('alert' => 'yes', 'email' => 'yes', 'permission' => array('name' => 'moderate_forum', 'is_board' => false)),
  1663. 'request_group' => array('alert' => 'yes', 'email' => 'yes'),
  1664. 'warn_own' => array('alert' => 'yes', 'email' => 'yes'),
  1665. 'warn_any' => array('alert' => 'yes', 'email' => 'yes', 'permission' => array('name' => 'issue_warning', 'is_board' => false)),
  1666. ),
  1667. 'calendar' => array(
  1668. 'event_new' => array('alert' => 'yes', 'email' => 'yes', 'help' => 'alert_event_new'),
  1669. ),
  1670. );
  1671. $group_options = array(
  1672. 'msg' => array(
  1673. array('check', 'msg_auto_notify', 'label' => 'after'),
  1674. array('select', 'msg_notify_pref', 'label' => 'before', 'opts' => array(
  1675. 0 => $txt['alert_opt_msg_notify_pref_nothing'],
  1676. 1 => $txt['alert_opt_msg_notify_pref_instant'],
  1677. 2 => $txt['alert_opt_msg_notify_pref_first'],
  1678. 3 => $txt['alert_opt_msg_notify_pref_daily'],
  1679. 4 => $txt['alert_opt_msg_notify_pref_weekly'],
  1680. )),
  1681. ),
  1682. );
  1683. $disabled_options = array();
  1684. // There are certain things that are disabled at the group level.
  1685. if (empty($modSettings['cal_enabled']))
  1686. {
  1687. foreach ($alert_types['calendar'] as $k => $v)
  1688. $disabled_options[] = $k;
  1689. unset ($alert_types['calendar']);
  1690. }
  1691. // Now, now, we could pass this through global but we should really get into the habit of
  1692. // passing content to hooks, not expecting hooks to splatter everything everywhere.
  1693. call_integration_hook('integrate_alert_types', array(&$alert_types, &$group_options, &$disabled_options));
  1694. // Now we have to do some permissions testing.
  1695. require_once($sourcedir . '/Subs-Members.php');
  1696. $perms_cache = array();
  1697. foreach ($alert_types as $group => $items)
  1698. {
  1699. foreach ($items as $alert_key => $alert_value)
  1700. {
  1701. if (!isset($alert_value['permission']))
  1702. continue;
  1703. if (!isset($perms_cache[$alert_value['permission']['name']]))
  1704. {
  1705. $in_board = !empty($alert_value['permission']['is_board']) ? 0 : null;
  1706. $members = membersAllowedTo($alert_value['permission']['name'], $in_board);
  1707. $perms_cache[$alert_value['permission']['name']] = in_array($memID, $members);
  1708. }
  1709. if (!$perms_cache[$alert_value['permission']['name']])
  1710. {
  1711. $disabled_options[] = $alert_key;
  1712. unset ($alert_types[$group][$alert_key]);
  1713. }
  1714. }
  1715. if (empty($alert_types[$group]))
  1716. unset ($alert_types[$group]);
  1717. }
  1718. // Slightly different for group requests
  1719. $request = $smcFunc['db_query']('', '
  1720. SELECT COUNT(*)
  1721. FROM {db_prefix}group_moderators
  1722. WHERE id_member = {int:memID}',
  1723. array(
  1724. 'memID' => $memID,
  1725. )
  1726. );
  1727. list($can_mod) = $smcFunc['db_fetch_row']($request);
  1728. if (!isset($perms_cache['manage_membergroups']))
  1729. {
  1730. $members = membersAllowedTo('manage_membergroups');
  1731. $perms_cache['manage_membergroups'] = in_array($memID, $members);
  1732. }
  1733. if (!($perms_cache['manage_membergroups'] || $can_mod != 0))
  1734. unset($alert_types['members']['request_group']);
  1735. // And finally, exporting it to be useful later.
  1736. $context['alert_types'] = $alert_types;
  1737. $context['alert_group_options'] = $group_options;
  1738. $context['disabled_alerts'] = $disabled_options;
  1739. $context['alert_bits'] = array(
  1740. 'alert' => 0x01,
  1741. 'email' => 0x02,
  1742. );
  1743. if (isset($_POST['notify_submit']))
  1744. {
  1745. checkSession('post');
  1746. validateToken($context['token_check'], 'post');
  1747. // We need to step through the list of valid settings and figure out what the user has set.
  1748. $update_prefs = array();
  1749. // Now the group level options
  1750. foreach ($context['alert_group_options'] as $opt_group => $group)
  1751. {
  1752. foreach ($group as $this_option)
  1753. {
  1754. switch ($this_option[0])
  1755. {
  1756. case 'check':
  1757. $update_prefs[$this_option[1]] = !empty($_POST['opt_' . $this_option[1]]) ? 1 : 0;
  1758. break;
  1759. case 'select':
  1760. if (isset($_POST['opt_' . $this_option[1]], $this_option['opts'][$_POST['opt_' . $this_option[1]]]))
  1761. $update_prefs[$this_option[1]] = $_POST['opt_' . $this_option[1]];
  1762. else
  1763. {
  1764. // We didn't have a sane value. Let's grab the first item from the possibles.
  1765. $keys = array_keys($this_option['opts']);
  1766. $first = array_shift($keys);
  1767. $update_prefs[$this_option[1]] = $first;
  1768. }
  1769. break;
  1770. }
  1771. }
  1772. }
  1773. // Now the individual options
  1774. foreach ($context['alert_types'] as $alert_group => $items)
  1775. {
  1776. foreach ($items as $item_key => $this_options)
  1777. {
  1778. $this_value = 0;
  1779. foreach ($context['alert_bits'] as $type => $bitvalue)
  1780. {
  1781. if ($this_options[$type] == 'yes' && !empty($_POST[$type . '_' . $item_key]))
  1782. $this_value |= $bitvalue;
  1783. }
  1784. $update_prefs[$item_key] = $this_value;
  1785. }
  1786. }
  1787. setNotifyPrefs($memID, $update_prefs);
  1788. foreach ($update_prefs as $pref => $value)
  1789. $context['alert_prefs'][$pref] = $value;
  1790. makeNotificationChanges($memID);
  1791. $context['profile_updated'] = $txt['profile_updated_own'];
  1792. }
  1793. createToken($context['token_check'], 'post');
  1794. }
  1795. function alert_notifications_topics($memID)
  1796. {
  1797. global $txt, $scripturl, $user_profile, $user_info, $context, $modSettings, $smcFunc, $sourcedir, $settings;
  1798. // Because of the way this stuff works, we want to do this ourselves.
  1799. if (isset($_POST['edit_notify_topics']))
  1800. {
  1801. checkSession('post');
  1802. validateToken(str_replace('%u', $memID, 'profile-nt%u'), 'post');
  1803. makeNotificationChanges($memID);
  1804. $context['profile_updated'] = $txt['profile_updated_own'];
  1805. }
  1806. // Now set up for the token check.
  1807. $context['token_check'] = str_replace('%u', $memID, 'profile-nt%u');
  1808. createToken($context['token_check'], 'post');
  1809. // Gonna want this for the list.
  1810. require_once($sourcedir . '/Subs-List.php');
  1811. // Do the topic notifications.
  1812. $listOptions = array(
  1813. 'id' => 'topic_notification_list',
  1814. 'width' => '100%',
  1815. 'items_per_page' => $modSettings['defaultMaxMessages'],
  1816. 'no_items_label' => $txt['notifications_topics_none'] . '<br /><br />' . $txt['notifications_topics_howto'],
  1817. 'no_items_align' => 'left',
  1818. 'base_href' => $scripturl . '?action=profile;u=' . $memID . ';area=notification;sa=topics',
  1819. 'default_sort_col' => 'last_post',
  1820. 'get_items' => array(
  1821. 'function' => 'list_getTopicNotifications',
  1822. 'params' => array(
  1823. $memID,
  1824. ),
  1825. ),
  1826. 'get_count' => array(
  1827. 'function' => 'list_getTopicNotificationCount',
  1828. 'params' => array(
  1829. $memID,
  1830. ),
  1831. ),
  1832. 'columns' => array(
  1833. 'subject' => array(
  1834. 'header' => array(
  1835. 'value' => $txt['notifications_topics'],
  1836. 'class' => 'lefttext first_th',
  1837. ),
  1838. 'data' => array(
  1839. 'function' => create_function('$topic', '
  1840. global $settings, $txt;
  1841. $link = $topic[\'link\'];
  1842. if ($topic[\'new\'])
  1843. $link .= \' <a href="\' . $topic[\'new_href\'] . \'"><span class="new_posts">\' . $txt[\'new\'] . \'</span></a>\';
  1844. $link .= \'<br /><span class="smalltext"><em>\' . $txt[\'in\'] . \' \' . $topic[\'board_link\'] . \'</em></span>\';
  1845. return $link;
  1846. '),
  1847. ),
  1848. 'sort' => array(
  1849. 'default' => 'ms.subject',
  1850. 'reverse' => 'ms.subject DESC',
  1851. ),
  1852. ),
  1853. 'started_by' => array(
  1854. 'header' => array(
  1855. 'value' => $txt['started_by'],
  1856. 'class' => 'lefttext',
  1857. ),
  1858. 'data' => array(
  1859. 'db' => 'poster_link',
  1860. ),
  1861. 'sort' => array(
  1862. 'default' => 'real_name_col',
  1863. 'reverse' => 'real_name_col DESC',
  1864. ),
  1865. ),
  1866. 'last_post' => array(
  1867. 'header' => array(
  1868. 'value' => $txt['last_post'],
  1869. 'class' => 'lefttext',
  1870. ),
  1871. 'data' => array(
  1872. 'sprintf' => array(
  1873. 'format' => '<span class="smalltext">%1$s<br />' . $txt['by'] . ' %2$s</span>',
  1874. 'params' => array(
  1875. 'updated' => false,
  1876. 'poster_updated_link' => false,
  1877. ),
  1878. ),
  1879. ),
  1880. 'sort' => array(
  1881. 'default' => 'ml.id_msg DESC',
  1882. 'reverse' => 'ml.id_msg',
  1883. ),
  1884. ),
  1885. 'delete' => array(
  1886. 'header' => array(
  1887. 'value' => '<input type="checkbox" class="input_check" onclick="invertAll(this, this.form);" />',
  1888. 'style' => 'width: 4%;',
  1889. 'class' => 'centercol',
  1890. ),
  1891. 'data' => array(
  1892. 'sprintf' => array(
  1893. 'format' => '<input type="checkbox" name="notify_topics[]" value="%1$d" class="input_check" />',
  1894. 'params' => array(
  1895. 'id' => false,
  1896. ),
  1897. ),
  1898. 'class' => 'centercol',
  1899. ),
  1900. ),
  1901. ),
  1902. 'form' => array(
  1903. 'href' => $scripturl . '?action=profile;area=notification;sa=topics',
  1904. 'include_sort' => true,
  1905. 'include_start' => true,
  1906. 'hidden_fields' => array(
  1907. 'u' => $memID,
  1908. 'sa' => $context['menu_item_selected'],
  1909. $context['session_var'] => $context['session_id'],
  1910. ),
  1911. 'token' => $context['token_check'],
  1912. ),
  1913. 'additional_rows' => array(
  1914. array(
  1915. 'position' => 'bottom_of_list',
  1916. 'value' => '<input type="submit" name="edit_notify_topics" value="' . $txt['notifications_update'] . '" class="button_submit" />',
  1917. 'align' => 'right',
  1918. ),
  1919. ),
  1920. );
  1921. // Create the notification list.
  1922. createList($listOptions);
  1923. }
  1924. function alert_notifications_boards($memID)
  1925. {
  1926. global $txt, $scripturl, $user_profile, $user_info, $context, $modSettings, $smcFunc, $sourcedir, $settings;
  1927. // Because of the way this stuff works, we want to do this ourselves.
  1928. if (isset($_POST['edit_notify_boards']))
  1929. {
  1930. checkSession('post');
  1931. validateToken(str_replace('%u', $memID, 'profile-nt%u'), 'post');
  1932. makeNotificationChanges($memID);
  1933. $context['profile_updated'] = $txt['profile_updated_own'];
  1934. }
  1935. // Now set up for the token check.
  1936. $context['token_check'] = str_replace('%u', $memID, 'profile-nt%u');
  1937. createToken($context['token_check'], 'post');
  1938. // Gonna want this for the list.
  1939. require_once($sourcedir . '/Subs-List.php');
  1940. // Fine, start with the board list.
  1941. $listOptions = array(
  1942. 'id' => 'board_notification_list',
  1943. 'width' => '100%',
  1944. 'no_items_label' => $txt['notifications_boards_none'] . '<br /><br />' . $txt['notifications_boards_howto'],
  1945. 'no_items_align' => 'left',
  1946. 'base_href' => $scripturl . '?action=profile;u=' . $memID . ';area=notification;sa=boards',
  1947. 'default_sort_col' => 'board_name',
  1948. 'get_items' => array(
  1949. 'function' => 'list_getBoardNotifications',
  1950. 'params' => array(
  1951. $memID,
  1952. ),
  1953. ),
  1954. 'columns' => array(
  1955. 'board_name' => array(
  1956. 'header' => array(
  1957. 'value' => $txt['notifications_boards'],
  1958. 'class' => 'lefttext first_th',
  1959. ),
  1960. 'data' => array(
  1961. 'function' => create_function('$board', '
  1962. global $settings, $txt;
  1963. $link = $board[\'link\'];
  1964. if ($board[\'new\'])
  1965. $link .= \' <a href="\' . $board[\'href\'] . \'"><span class="new_posts">' . $txt['new'] . '</span></a>\';
  1966. return $link;
  1967. '),
  1968. ),
  1969. 'sort' => array(
  1970. 'default' => 'name',
  1971. 'reverse' => 'name DESC',
  1972. ),
  1973. ),
  1974. 'delete' => array(
  1975. 'header' => array(
  1976. 'value' => '<input type="checkbox" class="input_check" onclick="invertAll(this, this.form);" />',
  1977. 'style' => 'width: 4%;',
  1978. 'class' => 'centercol',
  1979. ),
  1980. 'data' => array(
  1981. 'sprintf' => array(
  1982. 'format' => '<input type="checkbox" name="notify_boards[]" value="%1$d" class="input_check" />',
  1983. 'params' => array(
  1984. 'id' => false,
  1985. ),
  1986. ),
  1987. 'class' => 'centercol',
  1988. ),
  1989. ),
  1990. ),
  1991. 'form' => array(
  1992. 'href' => $scripturl . '?action=profile;area=notification;sa=boards',
  1993. 'include_sort' => true,
  1994. 'include_start' => true,
  1995. 'hidden_fields' => array(
  1996. 'u' => $memID,
  1997. 'sa' => $context['menu_item_selected'],
  1998. $context['session_var'] => $context['session_id'],
  1999. ),
  2000. 'token' => $context['token_check'],
  2001. ),
  2002. 'additional_rows' => array(
  2003. array(
  2004. 'position' => 'bottom_of_list',
  2005. 'value' => '<input type="submit" name="edit_notify_boards" value="' . $txt['notifications_update'] . '" class="button_submit" />',
  2006. 'align' => 'right',
  2007. ),
  2008. ),
  2009. );
  2010. // Create the board notification list.
  2011. createList($listOptions);
  2012. }
  2013. /**
  2014. * @todo needs a description
  2015. *
  2016. * @param int $memID id_member
  2017. * @return string
  2018. */
  2019. function list_getTopicNotificationCount($memID)
  2020. {
  2021. global $smcFunc, $user_info, $context, $modSettings;
  2022. $request = $smcFunc['db_query']('', '
  2023. SELECT COUNT(*)
  2024. FROM {db_prefix}log_notify AS ln' . (!$modSettings['postmod_active'] && $user_info['query_see_board'] === '1=1' ? '' : '
  2025. INNER JOIN {db_prefix}topics AS t ON (t.id_topic = ln.id_topic)') . ($user_info['query_see_board'] === '1=1' ? '' : '
  2026. INNER JOIN {db_prefix}boards AS b ON (b.id_board = t.id_board)') . '
  2027. WHERE ln.id_member = {int:selected_member}' . ($user_info['query_see_board'] === '1=1' ? '' : '
  2028. AND {query_see_board}') . ($modSettings['postmod_active'] ? '
  2029. AND t.approved = {int:is_approved}' : ''),
  2030. array(
  2031. 'selected_member' => $memID,
  2032. 'is_approved' => 1,
  2033. )
  2034. );
  2035. list ($totalNotifications) = $smcFunc['db_fetch_row']($request);
  2036. $smcFunc['db_free_result']($request);
  2037. // @todo make this an integer before it gets returned
  2038. return $totalNotifications;
  2039. }
  2040. /**
  2041. * @todo Needs a description
  2042. *
  2043. * @param int $start
  2044. * @param int $items_per_page
  2045. * @param string $sort
  2046. * @param int $memID id_member
  2047. * @return array $notification_topics
  2048. */
  2049. function list_getTopicNotifications($start, $items_per_page, $sort, $memID)
  2050. {
  2051. global $smcFunc, $txt, $scripturl, $user_info, $context, $modSettings;
  2052. // All the topics with notification on...
  2053. $request = $smcFunc['db_query']('', '
  2054. SELECT
  2055. IFNULL(lt.id_msg, IFNULL(lmr.id_msg, -1)) + 1 AS new_from, b.id_board, b.name,
  2056. t.id_topic, ms.subject, ms.id_member, IFNULL(mem.real_name, ms.poster_name) AS real_name_col,
  2057. ml.id_msg_modified, ml.poster_time, ml.id_member AS id_member_updated,
  2058. IFNULL(mem2.real_name, ml.poster_name) AS last_real_name
  2059. FROM {db_prefix}log_notify AS ln
  2060. INNER JOIN {db_prefix}topics AS t ON (t.id_topic = ln.id_topic' . ($modSettings['postmod_active'] ? ' AND t.approved = {int:is_approved}' : '') . ')
  2061. INNER JOIN {db_prefix}boards AS b ON (b.id_board = t.id_board AND {query_see_board})
  2062. INNER JOIN {db_prefix}messages AS ms ON (ms.id_msg = t.id_first_msg)
  2063. INNER JOIN {db_prefix}messages AS ml ON (ml.id_msg = t.id_last_msg)
  2064. LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = ms.id_member)
  2065. LEFT JOIN {db_prefix}members AS mem2 ON (mem2.id_member = ml.id_member)
  2066. LEFT JOIN {db_prefix}log_topics AS lt ON (lt.id_topic = t.id_topic AND lt.id_member = {int:current_member})
  2067. LEFT JOIN {db_prefix}log_mark_read AS lmr ON (lmr.id_board = b.id_board AND lmr.id_member = {int:current_member})
  2068. WHERE ln.id_member = {int:selected_member}
  2069. ORDER BY {raw:sort}
  2070. LIMIT {int:offset}, {int:items_per_page}',
  2071. array(
  2072. 'current_member' => $user_info['id'],
  2073. 'is_approved' => 1,
  2074. 'selected_member' => $memID,
  2075. 'sort' => $sort,
  2076. 'offset' => $start,
  2077. 'items_per_page' => $items_per_page,
  2078. )
  2079. );
  2080. $notification_topics = array();
  2081. while ($row = $smcFunc['db_fetch_assoc']($request))
  2082. {
  2083. censorText($row['subject']);
  2084. $notification_topics[] = array(
  2085. 'id' => $row['id_topic'],
  2086. 'poster_link' => empty($row['id_member']) ? $row['real_name_col'] : '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name_col'] . '</a>',
  2087. '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>',
  2088. 'subject' => $row['subject'],
  2089. 'href' => $scripturl . '?topic=' . $row['id_topic'] . '.0',
  2090. 'link' => '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0">' . $row['subject'] . '</a>',
  2091. 'new' => $row['new_from'] <= $row['id_msg_modified'],
  2092. 'new_from' => $row['new_from'],
  2093. 'updated' => timeformat($row['poster_time']),
  2094. 'new_href' => $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['new_from'] . '#new',
  2095. 'new_link' => '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['new_from'] . '#new">' . $row['subject'] . '</a>',
  2096. 'board_link' => '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['name'] . '</a>',
  2097. );
  2098. }
  2099. $smcFunc['db_free_result']($request);
  2100. return $notification_topics;
  2101. }
  2102. /**
  2103. * @todo needs a description
  2104. *
  2105. * @param int $start
  2106. * @param int $items_per_page
  2107. * @param string $sort
  2108. * @param int $memID id_member
  2109. * @return array
  2110. */
  2111. function list_getBoardNotifications($start, $items_per_page, $sort, $memID)
  2112. {
  2113. global $smcFunc, $txt, $scripturl, $user_info;
  2114. $request = $smcFunc['db_query']('', '
  2115. SELECT b.id_board, b.name, IFNULL(lb.id_msg, 0) AS board_read, b.id_msg_updated
  2116. FROM {db_prefix}log_notify AS ln
  2117. INNER JOIN {db_prefix}boards AS b ON (b.id_board = ln.id_board)
  2118. LEFT JOIN {db_prefix}log_boards AS lb ON (lb.id_board = b.id_board AND lb.id_member = {int:current_member})
  2119. WHERE ln.id_member = {int:selected_member}
  2120. AND {query_see_board}
  2121. ORDER BY ' . $sort,
  2122. array(
  2123. 'current_member' => $user_info['id'],
  2124. 'selected_member' => $memID,
  2125. )
  2126. );
  2127. $notification_boards = array();
  2128. while ($row = $smcFunc['db_fetch_assoc']($request))
  2129. $notification_boards[] = array(
  2130. 'id' => $row['id_board'],
  2131. 'name' => $row['name'],
  2132. 'href' => $scripturl . '?board=' . $row['id_board'] . '.0',
  2133. 'link' => '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['name'] . '</a>',
  2134. 'new' => $row['board_read'] < $row['id_msg_updated']
  2135. );
  2136. $smcFunc['db_free_result']($request);
  2137. return $notification_boards;
  2138. }
  2139. /**
  2140. * @todo needs a description
  2141. *
  2142. * @param int $memID id_member
  2143. */
  2144. function loadThemeOptions($memID)
  2145. {
  2146. global $context, $options, $cur_profile, $smcFunc;
  2147. if (isset($_POST['default_options']))
  2148. $_POST['options'] = isset($_POST['options']) ? $_POST['options'] + $_POST['default_options'] : $_POST['default_options'];
  2149. if ($context['user']['is_owner'])
  2150. {
  2151. $context['member']['options'] = $options;
  2152. if (isset($_POST['options']) && is_array($_POST['options']))
  2153. foreach ($_POST['options'] as $k => $v)
  2154. $context['member']['options'][$k] = $v;
  2155. }
  2156. else
  2157. {
  2158. $request = $smcFunc['db_query']('', '
  2159. SELECT id_member, variable, value
  2160. FROM {db_prefix}themes
  2161. WHERE id_theme IN (1, {int:member_theme})
  2162. AND id_member IN (-1, {int:selected_member})',
  2163. array(
  2164. 'member_theme' => (int) $cur_profile['id_theme'],
  2165. 'selected_member' => $memID,
  2166. )
  2167. );
  2168. $temp = array();
  2169. while ($row = $smcFunc['db_fetch_assoc']($request))
  2170. {
  2171. if ($row['id_member'] == -1)
  2172. {
  2173. $temp[$row['variable']] = $row['value'];
  2174. continue;
  2175. }
  2176. if (isset($_POST['options'][$row['variable']]))
  2177. $row['value'] = $_POST['options'][$row['variable']];
  2178. $context['member']['options'][$row['variable']] = $row['value'];
  2179. }
  2180. $smcFunc['db_free_result']($request);
  2181. // Load up the default theme options for any missing.
  2182. foreach ($temp as $k => $v)
  2183. {
  2184. if (!isset($context['member']['options'][$k]))
  2185. $context['member']['options'][$k] = $v;
  2186. }
  2187. }
  2188. }
  2189. /**
  2190. * @todo needs a description
  2191. *
  2192. * @param int $memID id_member
  2193. */
  2194. function ignoreboards($memID)
  2195. {
  2196. global $txt, $user_info, $context, $modSettings, $smcFunc, $cur_profile;
  2197. // Have the admins enabled this option?
  2198. if (empty($modSettings['allow_ignore_boards']))
  2199. fatal_lang_error('ignoreboards_disallowed', 'user');
  2200. // Find all the boards this user is allowed to see.
  2201. $request = $smcFunc['db_query']('order_by_board_order', '
  2202. SELECT b.id_cat, c.name AS cat_name, b.id_board, b.name, b.child_level,
  2203. '. (!empty($cur_profile['ignore_boards']) ? 'b.id_board IN ({array_int:ignore_boards})' : '0') . ' AS is_ignored
  2204. FROM {db_prefix}boards AS b
  2205. LEFT JOIN {db_prefix}categories AS c ON (c.id_cat = b.id_cat)
  2206. WHERE {query_see_board}
  2207. AND redirect = {string:empty_string}',
  2208. array(
  2209. 'ignore_boards' => !empty($cur_profile['ignore_boards']) ? explode(',', $cur_profile['ignore_boards']) : array(),
  2210. 'empty_string' => '',
  2211. )
  2212. );
  2213. $context['num_boards'] = $smcFunc['db_num_rows']($request);
  2214. $context['categories'] = array();
  2215. while ($row = $smcFunc['db_fetch_assoc']($request))
  2216. {
  2217. // This category hasn't been set up yet..
  2218. if (!isset($context['categories'][$row['id_cat']]))
  2219. $context['categories'][$row['id_cat']] = array(
  2220. 'id' => $row['id_cat'],
  2221. 'name' => $row['cat_name'],
  2222. 'boards' => array()
  2223. );
  2224. // Set this board up, and let the template know when it's a child. (indent them..)
  2225. $context['categories'][$row['id_cat']]['boards'][$row['id_board']] = array(
  2226. 'id' => $row['id_board'],
  2227. 'name' => $row['name'],
  2228. 'child_level' => $row['child_level'],
  2229. 'selected' => $row['is_ignored'],
  2230. );
  2231. }
  2232. $smcFunc['db_free_result']($request);
  2233. // Now, let's sort the list of categories into the boards for templates that like that.
  2234. $temp_boards = array();
  2235. foreach ($context['categories'] as $category)
  2236. {
  2237. // Include a list of boards per category for easy toggling.
  2238. $context['categories'][$category['id']]['child_ids'] = array_keys($category['boards']);
  2239. $temp_boards[] = array(
  2240. 'name' => $category['name'],
  2241. 'child_ids' => array_keys($category['boards'])
  2242. );
  2243. $temp_boards = array_merge($temp_boards, array_values($category['boards']));
  2244. }
  2245. $max_boards = ceil(count($temp_boards) / 2);
  2246. if ($max_boards == 1)
  2247. $max_boards = 2;
  2248. // Now, alternate them so they can be shown left and right ;).
  2249. $context['board_columns'] = array();
  2250. for ($i = 0; $i < $max_boards; $i++)
  2251. {
  2252. $context['board_columns'][] = $temp_boards[$i];
  2253. if (isset($temp_boards[$i + $max_boards]))
  2254. $context['board_columns'][] = $temp_boards[$i + $max_boards];
  2255. else
  2256. $context['board_columns'][] = array();
  2257. }
  2258. loadThemeOptions($memID);
  2259. }
  2260. /**
  2261. * Load all the languages for the profile.
  2262. * @return boolean
  2263. */
  2264. function profileLoadLanguages()
  2265. {
  2266. global $context, $modSettings, $settings, $cur_profile, $language, $smcFunc;
  2267. $context['profile_languages'] = array();
  2268. // Get our languages!
  2269. getLanguages(true, true);
  2270. // Setup our languages.
  2271. foreach ($context['languages'] as $lang)
  2272. {
  2273. $context['profile_languages'][$lang['filename']] = strtr($lang['name'], array('-utf8' => ''));
  2274. }
  2275. ksort($context['profile_languages']);
  2276. // Return whether we should proceed with this.
  2277. return count($context['profile_languages']) > 1 ? true : false;
  2278. }
  2279. /**
  2280. * @todo needs description
  2281. *
  2282. * @return true
  2283. */
  2284. function profileLoadGroups()
  2285. {
  2286. global $cur_profile, $txt, $context, $smcFunc, $user_settings;
  2287. $context['member_groups'] = array(
  2288. 0 => array(
  2289. 'id' => 0,
  2290. 'name' => $txt['no_primary_membergroup'],
  2291. 'is_primary' => $cur_profile['id_group'] == 0,
  2292. 'can_be_additional' => false,
  2293. 'can_be_primary' => true,
  2294. )
  2295. );
  2296. $curGroups = explode(',', $cur_profile['additional_groups']);
  2297. // Load membergroups, but only those groups the user can assign.
  2298. $request = $smcFunc['db_query']('', '
  2299. SELECT group_name, id_group, hidden
  2300. FROM {db_prefix}membergroups
  2301. WHERE id_group != {int:moderator_group}
  2302. AND min_posts = {int:min_posts}' . (allowedTo('admin_forum') ? '' : '
  2303. AND group_type != {int:is_protected}') . '
  2304. ORDER BY min_posts, CASE WHEN id_group < {int:newbie_group} THEN id_group ELSE 4 END, group_name',
  2305. array(
  2306. 'moderator_group' => 3,
  2307. 'min_posts' => -1,
  2308. 'is_protected' => 1,
  2309. 'newbie_group' => 4,
  2310. )
  2311. );
  2312. while ($row = $smcFunc['db_fetch_assoc']($request))
  2313. {
  2314. // We should skip the administrator group if they don't have the admin_forum permission!
  2315. if ($row['id_group'] == 1 && !allowedTo('admin_forum'))
  2316. continue;
  2317. $context['member_groups'][$row['id_group']] = array(
  2318. 'id' => $row['id_group'],
  2319. 'name' => $row['group_name'],
  2320. 'is_primary' => $cur_profile['id_group'] == $row['id_group'],
  2321. 'is_additional' => in_array($row['id_group'], $curGroups),
  2322. 'can_be_additional' => true,
  2323. 'can_be_primary' => $row['hidden'] != 2,
  2324. );
  2325. }
  2326. $smcFunc['db_free_result']($request);
  2327. $context['member']['group_id'] = $user_settings['id_group'];
  2328. return true;
  2329. }
  2330. /**
  2331. * Load key signature context data.
  2332. *
  2333. * @return true
  2334. */
  2335. function profileLoadSignatureData()
  2336. {
  2337. global $modSettings, $context, $txt, $cur_profile, $smcFunc, $memberContext;
  2338. // Signature limits.
  2339. list ($sig_limits, $sig_bbc) = explode(':', $modSettings['signature_settings']);
  2340. $sig_limits = explode(',', $sig_limits);
  2341. $context['signature_enabled'] = isset($sig_limits[0]) ? $sig_limits[0] : 0;
  2342. $context['signature_limits'] = array(
  2343. 'max_length' => isset($sig_limits[1]) ? $sig_limits[1] : 0,
  2344. 'max_lines' => isset($sig_limits[2]) ? $sig_limits[2] : 0,
  2345. 'max_images' => isset($sig_limits[3]) ? $sig_limits[3] : 0,
  2346. 'max_smileys' => isset($sig_limits[4]) ? $sig_limits[4] : 0,
  2347. 'max_image_width' => isset($sig_limits[5]) ? $sig_limits[5] : 0,
  2348. 'max_image_height' => isset($sig_limits[6]) ? $sig_limits[6] : 0,
  2349. 'max_font_size' => isset($sig_limits[7]) ? $sig_limits[7] : 0,
  2350. 'bbc' => !empty($sig_bbc) ? explode(',', $sig_bbc) : array(),
  2351. );
  2352. // Kept this line in for backwards compatibility!
  2353. $context['max_signature_length'] = $context['signature_limits']['max_length'];
  2354. // Warning message for signature image limits?
  2355. $context['signature_warning'] = '';
  2356. if ($context['signature_limits']['max_image_width'] && $context['signature_limits']['max_image_height'])
  2357. $context['signature_warning'] = sprintf($txt['profile_error_signature_max_image_size'], $context['signature_limits']['max_image_width'], $context['signature_limits']['max_image_height']);
  2358. elseif ($context['signature_limits']['max_image_width'] || $context['signature_limits']['max_image_height'])
  2359. $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']);
  2360. $context['show_spellchecking'] = !empty($modSettings['enableSpellChecking']) && function_exists('pspell_new');
  2361. if (empty($context['do_preview']))
  2362. $context['member']['signature'] = empty($cur_profile['signature']) ? '' : str_replace(array('<br />', '<', '>', '"', '\''), array("\n", '&lt;', '&gt;', '&quot;', '&#039;'), $cur_profile['signature']);
  2363. else
  2364. {
  2365. $signature = !empty($_POST['signature']) ? $_POST['signature'] : '';
  2366. $validation = profileValidateSignature($signature);
  2367. if (empty($context['post_errors']))
  2368. {
  2369. loadLanguage('Errors');
  2370. $context['post_errors'] = array();
  2371. }
  2372. $context['post_errors'][] = 'signature_not_yet_saved';
  2373. if ($validation !== true && $validation !== false)
  2374. $context['post_errors'][] = $validation;
  2375. censorText($context['member']['signature']);
  2376. $context['member']['current_signature'] = $context['member']['signature'];
  2377. censorText($signature);
  2378. $context['member']['signature_preview'] = parse_bbc($signature, true, 'sig' . $memberContext[$context['id_member']]);
  2379. $context['member']['signature'] = $_POST['signature'];
  2380. }
  2381. return true;
  2382. }
  2383. /**
  2384. * Load avatar context data.
  2385. *
  2386. * @return true
  2387. */
  2388. function profileLoadAvatarData()
  2389. {
  2390. global $context, $cur_profile, $modSettings, $scripturl;
  2391. $context['avatar_url'] = $modSettings['avatar_url'];
  2392. // Default context.
  2393. $context['member']['avatar'] += array(
  2394. 'custom' => stristr($cur_profile['avatar'], 'http://') ? $cur_profile['avatar'] : 'http://',
  2395. 'selection' => $cur_profile['avatar'] == '' || stristr($cur_profile['avatar'], 'http://') ? '' : $cur_profile['avatar'],
  2396. 'id_attach' => $cur_profile['id_attach'],
  2397. 'filename' => $cur_profile['filename'],
  2398. 'allow_server_stored' => allowedTo('profile_server_avatar') || (!$context['user']['is_owner'] && allowedTo('profile_extra_any')),
  2399. 'allow_upload' => allowedTo('profile_upload_avatar') || (!$context['user']['is_owner'] && allowedTo('profile_extra_any')),
  2400. 'allow_external' => allowedTo('profile_remote_avatar') || (!$context['user']['is_owner'] && allowedTo('profile_extra_any')),
  2401. );
  2402. if ($cur_profile['avatar'] == '' && $cur_profile['id_attach'] > 0 && $context['member']['avatar']['allow_upload'])
  2403. {
  2404. $context['member']['avatar'] += array(
  2405. 'choice' => 'upload',
  2406. 'server_pic' => 'blank.png',
  2407. 'external' => 'http://'
  2408. );
  2409. $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'];
  2410. }
  2411. elseif (stristr($cur_profile['avatar'], 'http://') && $context['member']['avatar']['allow_external'])
  2412. $context['member']['avatar'] += array(
  2413. 'choice' => 'external',
  2414. 'server_pic' => 'blank.png',
  2415. 'external' => $cur_profile['avatar']
  2416. );
  2417. elseif ($cur_profile['avatar'] != '' && file_exists($modSettings['avatar_directory'] . '/' . $cur_profile['avatar']) && $context['member']['avatar']['allow_server_stored'])
  2418. $context['member']['avatar'] += array(
  2419. 'choice' => 'server_stored',
  2420. 'server_pic' => $cur_profile['avatar'] == '' ? 'blank.png' : $cur_profile['avatar'],
  2421. 'external' => 'http://'
  2422. );
  2423. else
  2424. $context['member']['avatar'] += array(
  2425. 'choice' => 'none',
  2426. 'server_pic' => 'blank.png',
  2427. 'external' => 'http://'
  2428. );
  2429. // Get a list of all the avatars.
  2430. if ($context['member']['avatar']['allow_server_stored'])
  2431. {
  2432. $context['avatar_list'] = array();
  2433. $context['avatars'] = is_dir($modSettings['avatar_directory']) ? getAvatars('', 0) : array();
  2434. }
  2435. else
  2436. $context['avatars'] = array();
  2437. // Second level selected avatar...
  2438. $context['avatar_selected'] = substr(strrchr($context['member']['avatar']['server_pic'], '/'), 1);
  2439. return true;
  2440. }
  2441. /**
  2442. * Save a members group.
  2443. *
  2444. * @param int &$value
  2445. * @return true
  2446. */
  2447. function profileSaveGroups(&$value)
  2448. {
  2449. global $profile_vars, $old_profile, $context, $smcFunc, $cur_profile;
  2450. // Do we need to protect some groups?
  2451. if (!allowedTo('admin_forum'))
  2452. {
  2453. $request = $smcFunc['db_query']('', '
  2454. SELECT id_group
  2455. FROM {db_prefix}membergroups
  2456. WHERE group_type = {int:is_protected}',
  2457. array(
  2458. 'is_protected' => 1,
  2459. )
  2460. );
  2461. $protected_groups = array(1);
  2462. while ($row = $smcFunc['db_fetch_assoc']($request))
  2463. $protected_groups[] = $row['id_group'];
  2464. $smcFunc['db_free_result']($request);
  2465. $protected_groups = array_unique($protected_groups);
  2466. }
  2467. // The account page allows the change of your id_group - but not to a protected group!
  2468. if (empty($protected_groups) || count(array_intersect(array((int) $value, $old_profile['id_group']), $protected_groups)) == 0)
  2469. $value = (int) $value;
  2470. // ... otherwise it's the old group sir.
  2471. else
  2472. $value = $old_profile['id_group'];
  2473. // Find the additional membergroups (if any)
  2474. if (isset($_POST['additional_groups']) && is_array($_POST['additional_groups']))
  2475. {
  2476. $additional_groups = array();
  2477. foreach ($_POST['additional_groups'] as $group_id)
  2478. {
  2479. $group_id = (int) $group_id;
  2480. if (!empty($group_id) && (empty($protected_groups) || !in_array($group_id, $protected_groups)))
  2481. $additional_groups[] = $group_id;
  2482. }
  2483. // Put the protected groups back in there if you don't have permission to take them away.
  2484. $old_additional_groups = explode(',', $old_profile['additional_groups']);
  2485. foreach ($old_additional_groups as $group_id)
  2486. {
  2487. if (!empty($protected_groups) && in_array($group_id, $protected_groups))
  2488. $additional_groups[] = $group_id;
  2489. }
  2490. if (implode(',', $additional_groups) !== $old_profile['additional_groups'])
  2491. {
  2492. $profile_vars['additional_groups'] = implode(',', $additional_groups);
  2493. $cur_profile['additional_groups'] = implode(',', $additional_groups);
  2494. }
  2495. }
  2496. // Too often, people remove delete their own account, or something.
  2497. if (in_array(1, explode(',', $old_profile['additional_groups'])) || $old_profile['id_group'] == 1)
  2498. {
  2499. $stillAdmin = $value == 1 || (isset($additional_groups) && in_array(1, $additional_groups));
  2500. // If they would no longer be an admin, look for any other...
  2501. if (!$stillAdmin)
  2502. {
  2503. $request = $smcFunc['db_query']('', '
  2504. SELECT id_member
  2505. FROM {db_prefix}members
  2506. WHERE (id_group = {int:admin_group} OR FIND_IN_SET({int:admin_group}, additional_groups) != 0)
  2507. AND id_member != {int:selected_member}
  2508. LIMIT 1',
  2509. array(
  2510. 'admin_group' => 1,
  2511. 'selected_member' => $context['id_member'],
  2512. )
  2513. );
  2514. list ($another) = $smcFunc['db_fetch_row']($request);
  2515. $smcFunc['db_free_result']($request);
  2516. if (empty($another))
  2517. fatal_lang_error('at_least_one_admin', 'critical');
  2518. }
  2519. }
  2520. // If we are changing group status, update permission cache as necessary.
  2521. if ($value != $old_profile['id_group'] || isset($profile_vars['additional_groups']))
  2522. {
  2523. if ($context['user']['is_owner'])
  2524. $_SESSION['mc']['time'] = 0;
  2525. else
  2526. updateSettings(array('settings_updated' => time()));
  2527. }
  2528. return true;
  2529. }
  2530. /**
  2531. * The avatar is incredibly complicated, what with the options... and what not.
  2532. * @todo argh, the avatar here. Take this out of here!
  2533. *
  2534. * @param array &$value
  2535. * @return mixed
  2536. */
  2537. function profileSaveAvatarData(&$value)
  2538. {
  2539. global $modSettings, $sourcedir, $smcFunc, $profile_vars, $cur_profile, $context;
  2540. $memID = $context['id_member'];
  2541. if (empty($memID) && !empty($context['password_auth_failed']))
  2542. return false;
  2543. require_once($sourcedir . '/ManageAttachments.php');
  2544. // We're going to put this on a nice custom dir.
  2545. $uploadDir = $modSettings['custom_avatar_dir'];
  2546. $id_folder = 1;
  2547. $downloadedExternalAvatar = false;
  2548. if ($value == 'external' && allowedTo('profile_remote_avatar') && stripos($_POST['userpicpersonal'], 'http://') === 0 && strlen($_POST['userpicpersonal']) > 7 && !empty($modSettings['avatar_download_external']))
  2549. {
  2550. if (!is_writable($uploadDir))
  2551. fatal_lang_error('attachments_no_write', 'critical');
  2552. require_once($sourcedir . '/Subs-Package.php');
  2553. $url = parse_url($_POST['userpicpersonal']);
  2554. $contents = fetch_web_data('http://' . $url['host'] . (empty($url['port']) ? '' : ':' . $url['port']) . str_replace(' ', '%20', trim($url['path'])));
  2555. $new_filename = $uploadDir . '/' . getAttachmentFilename('avatar_tmp_' . $memID, false, null, true);
  2556. if ($contents != false && $tmpAvatar = fopen($new_filename, 'wb'))
  2557. {
  2558. fwrite($tmpAvatar, $contents);
  2559. fclose($tmpAvatar);
  2560. $downloadedExternalAvatar = true;
  2561. $_FILES['attachment']['tmp_name'] = $new_filename;
  2562. }
  2563. }
  2564. if ($value == 'none')
  2565. {
  2566. $profile_vars['avatar'] = '';
  2567. // Reset the attach ID.
  2568. $cur_profile['id_attach'] = 0;
  2569. $cur_profile['attachment_type'] = 0;
  2570. $cur_profile['filename'] = '';
  2571. removeAttachments(array('id_member' => $memID));
  2572. }
  2573. elseif ($value == 'server_stored' && allowedTo('profile_server_avatar'))
  2574. {
  2575. $profile_vars['avatar'] = strtr(empty($_POST['file']) ? (empty($_POST['cat']) ? '' : $_POST['cat']) : $_POST['file'], array('&amp;' => '&'));
  2576. $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']) : '';
  2577. // Clear current profile...
  2578. $cur_profile['id_attach'] = 0;
  2579. $cur_profile['attachment_type'] = 0;
  2580. $cur_profile['filename'] = '';
  2581. // Get rid of their old avatar. (if uploaded.)
  2582. removeAttachments(array('id_member' => $memID));
  2583. }
  2584. elseif ($value == 'external' && allowedTo('profile_remote_avatar') && stripos($_POST['userpicpersonal'], 'http://') === 0 && empty($modSettings['avatar_download_external']))
  2585. {
  2586. // We need these clean...
  2587. $cur_profile['id_attach'] = 0;
  2588. $cur_profile['attachment_type'] = 0;
  2589. $cur_profile['filename'] = '';
  2590. // Remove any attached avatar...
  2591. removeAttachments(array('id_member' => $memID));
  2592. // @todo http://www.simplemachines.org/community/index.php?topic=462089.msg3226650#msg3226650
  2593. $profile_vars['avatar'] = str_replace(' ', '%20', preg_replace('~action(?:=|%3d)(?!dlattach)~i', 'action-', $_POST['userpicpersonal']));
  2594. if ($profile_vars['avatar'] == 'http://' || $profile_vars['avatar'] == 'http:///')
  2595. $profile_vars['avatar'] = '';
  2596. // Trying to make us do something we'll regret?
  2597. elseif (substr($profile_vars['avatar'], 0, 7) != 'http://')
  2598. return 'bad_avatar';
  2599. // Should we check dimensions?
  2600. elseif (!empty($modSettings['avatar_max_height_external']) || !empty($modSettings['avatar_max_width_external']))
  2601. {
  2602. // Now let's validate the avatar.
  2603. $sizes = url_image_size($profile_vars['avatar']);
  2604. 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']))))
  2605. {
  2606. // Houston, we have a problem. The avatar is too large!!
  2607. if ($modSettings['avatar_action_too_large'] == 'option_refuse')
  2608. return 'bad_avatar';
  2609. elseif ($modSettings['avatar_action_too_large'] == 'option_download_and_resize')
  2610. {
  2611. // @todo remove this if appropriate
  2612. require_once($sourcedir . '/Subs-Graphics.php');
  2613. if (downloadAvatar($profile_vars['avatar'], $memID, $modSettings['avatar_max_width_external'], $modSettings['avatar_max_height_external']))
  2614. {
  2615. $profile_vars['avatar'] = '';
  2616. $cur_profile['id_attach'] = $modSettings['new_avatar_data']['id'];
  2617. $cur_profile['filename'] = $modSettings['new_avatar_data']['filename'];
  2618. $cur_profile['attachment_type'] = $modSettings['new_avatar_data']['type'];
  2619. }
  2620. else
  2621. return 'bad_avatar';
  2622. }
  2623. }
  2624. }
  2625. }
  2626. elseif (($value == 'upload' && allowedTo('profile_upload_avatar')) || $downloadedExternalAvatar)
  2627. {
  2628. if ((isset($_FILES['attachment']['name']) && $_FILES['attachment']['name'] != '') || $downloadedExternalAvatar)
  2629. {
  2630. // Get the dimensions of the image.
  2631. if (!$downloadedExternalAvatar)
  2632. {
  2633. if (!is_writable($uploadDir))
  2634. fatal_lang_error('attachments_no_write', 'critical');
  2635. $new_filename = $uploadDir . '/' . getAttachmentFilename('avatar_tmp_' . $memID, false, null, true);
  2636. if (!move_uploaded_file($_FILES['attachment']['tmp_name'], $new_filename))
  2637. fatal_lang_error('attach_timeout', 'critical');
  2638. $_FILES['attachment']['tmp_name'] = $new_filename;
  2639. }
  2640. $sizes = @getimagesize($_FILES['attachment']['tmp_name']);
  2641. // No size, then it's probably not a valid pic.
  2642. if ($sizes === false)
  2643. {
  2644. @unlink($_FILES['attachment']['tmp_name']);
  2645. return 'bad_avatar';
  2646. }
  2647. // Check whether the image is too large.
  2648. 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']))
  2649. {
  2650. if (!empty($modSettings['avatar_resize_upload']))
  2651. {
  2652. // Attempt to chmod it.
  2653. @chmod($_FILES['attachment']['tmp_name'], 0644);
  2654. // @todo remove this require when appropriate
  2655. require_once($sourcedir . '/Subs-Graphics.php');
  2656. if (!downloadAvatar($_FILES['attachment']['tmp_name'], $memID, $modSettings['avatar_max_width_upload'], $modSettings['avatar_max_height_upload']))
  2657. {
  2658. @unlink($_FILES['attachment']['tmp_name']);
  2659. return 'bad_avatar';
  2660. }
  2661. // Reset attachment avatar data.
  2662. $cur_profile['id_attach'] = $modSettings['new_avatar_data']['id'];
  2663. $cur_profile['filename'] = $modSettings['new_avatar_data']['filename'];
  2664. $cur_profile['attachment_type'] = $modSettings['new_avatar_data']['type'];
  2665. }
  2666. else
  2667. {
  2668. @unlink($_FILES['attachment']['tmp_name']);
  2669. return 'bad_avatar';
  2670. }
  2671. }
  2672. elseif (is_array($sizes))
  2673. {
  2674. // Now try to find an infection.
  2675. require_once($sourcedir . '/Subs-Graphics.php');
  2676. if (!checkImageContents($_FILES['attachment']['tmp_name'], !empty($modSettings['avatar_paranoid'])))
  2677. {
  2678. // It's bad. Try to re-encode the contents?
  2679. if (empty($modSettings['avatar_reencode']) || (!reencodeImage($_FILES['attachment']['tmp_name'], $sizes[2])))
  2680. {
  2681. @unlink($_FILES['attachment']['tmp_name']);
  2682. return 'bad_avatar';
  2683. }
  2684. // We were successful. However, at what price?
  2685. $sizes = @getimagesize($_FILES['attachment']['tmp_name']);
  2686. // Hard to believe this would happen, but can you bet?
  2687. if ($sizes === false)
  2688. {
  2689. @unlink($_FILES['attachment']['tmp_name']);
  2690. return 'bad_avatar';
  2691. }
  2692. }
  2693. $extensions = array(
  2694. '1' => 'gif',
  2695. '2' => 'jpg',
  2696. '3' => 'png',
  2697. '6' => 'bmp'
  2698. );
  2699. $extension = isset($extensions[$sizes[2]]) ? $extensions[$sizes[2]] : 'bmp';
  2700. $mime_type = 'image/' . ($extension === 'jpg' ? 'jpeg' : ($extension === 'bmp' ? 'x-ms-bmp' : $extension));
  2701. $destName = 'avatar_' . $memID . '_' . time() . '.' . $extension;
  2702. list ($width, $height) = getimagesize($_FILES['attachment']['tmp_name']);
  2703. $file_hash = '';
  2704. // Remove previous attachments this member might have had.
  2705. removeAttachments(array('id_member' => $memID));
  2706. $smcFunc['db_insert']('',
  2707. '{db_prefix}attachments',
  2708. array(
  2709. 'id_member' => 'int', 'attachment_type' => 'int', 'filename' => 'string', 'file_hash' => 'string', 'fileext' => 'string', 'size' => 'int',
  2710. 'width' => 'int', 'height' => 'int', 'mime_type' => 'string', 'id_folder' => 'int',
  2711. ),
  2712. array(
  2713. $memID, 1, $destName, $file_hash, $extension, filesize($_FILES['attachment']['tmp_name']),
  2714. (int) $width, (int) $height, $mime_type, $id_folder,
  2715. ),
  2716. array('id_attach')
  2717. );
  2718. $cur_profile['id_attach'] = $smcFunc['db_insert_id']('{db_prefix}attachments', 'id_attach');
  2719. $cur_profile['filename'] = $destName;
  2720. $cur_profile['attachment_type'] = 1;
  2721. $destinationPath = $uploadDir . '/' . $destName;
  2722. if (!rename($_FILES['attachment']['tmp_name'], $destinationPath))
  2723. {
  2724. // I guess a man can try.
  2725. removeAttachments(array('id_member' => $memID));
  2726. fatal_lang_error('attach_timeout', 'critical');
  2727. }
  2728. // Attempt to chmod it.
  2729. @chmod($uploadDir . '/' . $destinationPath, 0644);
  2730. }
  2731. $profile_vars['avatar'] = '';
  2732. // Delete any temporary file.
  2733. if (file_exists($_FILES['attachment']['tmp_name']))
  2734. @unlink($_FILES['attachment']['tmp_name']);
  2735. }
  2736. // Selected the upload avatar option and had one already uploaded before or didn't upload one.
  2737. else
  2738. $profile_vars['avatar'] = '';
  2739. }
  2740. else
  2741. $profile_vars['avatar'] = '';
  2742. // Setup the profile variables so it shows things right on display!
  2743. $cur_profile['avatar'] = $profile_vars['avatar'];
  2744. return false;
  2745. }
  2746. /**
  2747. * Validate the signature
  2748. *
  2749. * @param mixed &$value
  2750. * @return boolean|string
  2751. */
  2752. function profileValidateSignature(&$value)
  2753. {
  2754. global $sourcedir, $modSettings, $smcFunc, $txt;
  2755. require_once($sourcedir . '/Subs-Post.php');
  2756. // Admins can do whatever they hell they want!
  2757. if (!allowedTo('admin_forum'))
  2758. {
  2759. // Load all the signature limits.
  2760. list ($sig_limits, $sig_bbc) = explode(':', $modSettings['signature_settings']);
  2761. $sig_limits = explode(',', $sig_limits);
  2762. $disabledTags = !empty($sig_bbc) ? explode(',', $sig_bbc) : array();
  2763. $unparsed_signature = strtr(un_htmlspecialchars($value), array("\r" => '', '&#039' => '\''));
  2764. // Too many lines?
  2765. if (!empty($sig_limits[2]) && substr_count($unparsed_signature, "\n") >= $sig_limits[2])
  2766. {
  2767. $txt['profile_error_signature_max_lines'] = sprintf($txt['profile_error_signature_max_lines'], $sig_limits[2]);
  2768. return 'signature_max_lines';
  2769. }
  2770. // Too many images?!
  2771. if (!empty($sig_limits[3]) && (substr_count(strtolower($unparsed_signature), '[img') + substr_count(strtolower($unparsed_signature), '<img')) > $sig_limits[3])
  2772. {
  2773. $txt['profile_error_signature_max_image_count'] = sprintf($txt['profile_error_signature_max_image_count'], $sig_limits[3]);
  2774. return 'signature_max_image_count';
  2775. }
  2776. // What about too many smileys!
  2777. $smiley_parsed = $unparsed_signature;
  2778. parsesmileys($smiley_parsed);
  2779. $smiley_count = substr_count(strtolower($smiley_parsed), '<img') - substr_count(strtolower($unparsed_signature), '<img');
  2780. if (!empty($sig_limits[4]) && $sig_limits[4] == -1 && $smiley_count > 0)
  2781. return 'signature_allow_smileys';
  2782. elseif (!empty($sig_limits[4]) && $sig_limits[4] > 0 && $smiley_count > $sig_limits[4])
  2783. {
  2784. $txt['profile_error_signature_max_smileys'] = sprintf($txt['profile_error_signature_max_smileys'], $sig_limits[4]);
  2785. return 'signature_max_smileys';
  2786. }
  2787. // Maybe we are abusing font sizes?
  2788. if (!empty($sig_limits[7]) && preg_match_all('~\[size=([\d\.]+)?(px|pt|em|x-large|larger)~i', $unparsed_signature, $matches) !== false && isset($matches[2]))
  2789. {
  2790. foreach ($matches[1] as $ind => $size)
  2791. {
  2792. $limit_broke = 0;
  2793. // Attempt to allow all sizes of abuse, so to speak.
  2794. if ($matches[2][$ind] == 'px' && $size > $sig_limits[7])
  2795. $limit_broke = $sig_limits[7] . 'px';
  2796. elseif ($matches[2][$ind] == 'pt' && $size > ($sig_limits[7] * 0.75))
  2797. $limit_broke = ((int) $sig_limits[7] * 0.75) . 'pt';
  2798. elseif ($matches[2][$ind] == 'em' && $size > ((float) $sig_limits[7] / 16))
  2799. $limit_broke = ((float) $sig_limits[7] / 16) . 'em';
  2800. elseif ($matches[2][$ind] != 'px' && $matches[2][$ind] != 'pt' && $matches[2][$ind] != 'em' && $sig_limits[7] < 18)
  2801. $limit_broke = 'large';
  2802. if ($limit_broke)
  2803. {
  2804. $txt['profile_error_signature_max_font_size'] = sprintf($txt['profile_error_signature_max_font_size'], $limit_broke);
  2805. return 'signature_max_font_size';
  2806. }
  2807. }
  2808. }
  2809. // The difficult one - image sizes! Don't error on this - just fix it.
  2810. if ((!empty($sig_limits[5]) || !empty($sig_limits[6])))
  2811. {
  2812. // Get all BBC tags...
  2813. preg_match_all('~\[img(\s+width=([\d]+))?(\s+height=([\d]+))?(\s+width=([\d]+))?\s*\](?:<br />)*([^<">]+?)(?:<br />)*\[/img\]~i', $unparsed_signature, $matches);
  2814. // ... and all HTML ones.
  2815. preg_match_all('~<img\s+src=(?:")?((?:http://|ftp://|https://|ftps://).+?)(?:")?(?:\s+alt=(?:")?(.*?)(?:")?)?(?:\s?/)?>~i', $unparsed_signature, $matches2, PREG_PATTERN_ORDER);
  2816. // And stick the HTML in the BBC.
  2817. if (!empty($matches2))
  2818. {
  2819. foreach ($matches2[0] as $ind => $dummy)
  2820. {
  2821. $matches[0][] = $matches2[0][$ind];
  2822. $matches[1][] = '';
  2823. $matches[2][] = '';
  2824. $matches[3][] = '';
  2825. $matches[4][] = '';
  2826. $matches[5][] = '';
  2827. $matches[6][] = '';
  2828. $matches[7][] = $matches2[1][$ind];
  2829. }
  2830. }
  2831. $replaces = array();
  2832. // Try to find all the images!
  2833. if (!empty($matches))
  2834. {
  2835. foreach ($matches[0] as $key => $image)
  2836. {
  2837. $width = -1; $height = -1;
  2838. // Does it have predefined restraints? Width first.
  2839. if ($matches[6][$key])
  2840. $matches[2][$key] = $matches[6][$key];
  2841. if ($matches[2][$key] && $sig_limits[5] && $matches[2][$key] > $sig_limits[5])
  2842. {
  2843. $width = $sig_limits[5];
  2844. $matches[4][$key] = $matches[4][$key] * ($width / $matches[2][$key]);
  2845. }
  2846. elseif ($matches[2][$key])
  2847. $width = $matches[2][$key];
  2848. // ... and height.
  2849. if ($matches[4][$key] && $sig_limits[6] && $matches[4][$key] > $sig_limits[6])
  2850. {
  2851. $height = $sig_limits[6];
  2852. if ($width != -1)
  2853. $width = $width * ($height / $matches[4][$key]);
  2854. }
  2855. elseif ($matches[4][$key])
  2856. $height = $matches[4][$key];
  2857. // If the dimensions are still not fixed - we need to check the actual image.
  2858. if (($width == -1 && $sig_limits[5]) || ($height == -1 && $sig_limits[6]))
  2859. {
  2860. $sizes = url_image_size($matches[7][$key]);
  2861. if (is_array($sizes))
  2862. {
  2863. // Too wide?
  2864. if ($sizes[0] > $sig_limits[5] && $sig_limits[5])
  2865. {
  2866. $width = $sig_limits[5];
  2867. $sizes[1] = $sizes[1] * ($width / $sizes[0]);
  2868. }
  2869. // Too high?
  2870. if ($sizes[1] > $sig_limits[6] && $sig_limits[6])
  2871. {
  2872. $height = $sig_limits[6];
  2873. if ($width == -1)
  2874. $width = $sizes[0];
  2875. $width = $width * ($height / $sizes[1]);
  2876. }
  2877. elseif ($width != -1)
  2878. $height = $sizes[1];
  2879. }
  2880. }
  2881. // Did we come up with some changes? If so remake the string.
  2882. if ($width != -1 || $height != -1)
  2883. $replaces[$image] = '[img' . ($width != -1 ? ' width=' . round($width) : '') . ($height != -1 ? ' height=' . round($height) : '') . ']' . $matches[7][$key] . '[/img]';
  2884. }
  2885. if (!empty($replaces))
  2886. $value = str_replace(array_keys($replaces), array_values($replaces), $value);
  2887. }
  2888. }
  2889. // Any disabled BBC?
  2890. $disabledSigBBC = implode('|', $disabledTags);
  2891. if (!empty($disabledSigBBC))
  2892. {
  2893. if (preg_match('~\[(' . $disabledSigBBC . '[ =\]/])~i', $unparsed_signature, $matches) !== false && isset($matches[1]))
  2894. {
  2895. $disabledTags = array_unique($disabledTags);
  2896. $txt['profile_error_signature_disabled_bbc'] = sprintf($txt['profile_error_signature_disabled_bbc'], implode(', ', $disabledTags));
  2897. return 'signature_disabled_bbc';
  2898. }
  2899. }
  2900. }
  2901. preparsecode($value);
  2902. // Too long?
  2903. if (!allowedTo('admin_forum') && !empty($sig_limits[1]) && $smcFunc['strlen'](str_replace('<br />', "\n", $value)) > $sig_limits[1])
  2904. {
  2905. $_POST['signature'] = trim($smcFunc['htmlspecialchars'](str_replace('<br />', "\n", $value), ENT_QUOTES));
  2906. $txt['profile_error_signature_max_length'] = sprintf($txt['profile_error_signature_max_length'], $sig_limits[1]);
  2907. return 'signature_max_length';
  2908. }
  2909. return true;
  2910. }
  2911. /**
  2912. * Validate an email address.
  2913. *
  2914. * @param string $email
  2915. * @param int $memID = 0
  2916. * @return boolean|string
  2917. */
  2918. function profileValidateEmail($email, $memID = 0)
  2919. {
  2920. global $smcFunc, $context;
  2921. $email = strtr($email, array('&#039;' => '\''));
  2922. // Check the name and email for validity.
  2923. if (trim($email) == '')
  2924. return 'no_email';
  2925. if (preg_match('~^[0-9A-Za-z=_+\-/][0-9A-Za-z=_\'+\-/\.]*@[\w\-]+(\.[\w\-]+)*(\.[\w]{2,6})$~', $email) == 0)
  2926. return 'bad_email';
  2927. // Email addresses should be and stay unique.
  2928. $request = $smcFunc['db_query']('', '
  2929. SELECT id_member
  2930. FROM {db_prefix}members
  2931. WHERE ' . ($memID != 0 ? 'id_member != {int:selected_member} AND ' : '') . '
  2932. email_address = {string:email_address}
  2933. LIMIT 1',
  2934. array(
  2935. 'selected_member' => $memID,
  2936. 'email_address' => $email,
  2937. )
  2938. );
  2939. if ($smcFunc['db_num_rows']($request) > 0)
  2940. return 'email_taken';
  2941. $smcFunc['db_free_result']($request);
  2942. return true;
  2943. }
  2944. /**
  2945. * Reload a users settings.
  2946. */
  2947. function profileReloadUser()
  2948. {
  2949. global $sourcedir, $modSettings, $context, $cur_profile, $smcFunc, $profile_vars;
  2950. // Log them back in - using the verify password as they must have matched and this one doesn't get changed by anyone!
  2951. if (isset($_POST['passwrd2']) && $_POST['passwrd2'] != '')
  2952. {
  2953. require_once($sourcedir . '/Subs-Auth.php');
  2954. setLoginCookie(60 * $modSettings['cookieTime'], $context['id_member'], sha1(sha1(strtolower($cur_profile['member_name']) . un_htmlspecialchars($_POST['passwrd2'])) . $cur_profile['password_salt']));
  2955. }
  2956. loadUserSettings();
  2957. writeLog();
  2958. }
  2959. /**
  2960. * Send the user a new activation email if they need to reactivate!
  2961. */
  2962. function profileSendActivation()
  2963. {
  2964. global $sourcedir, $profile_vars, $txt, $context, $scripturl, $smcFunc, $cookiename, $cur_profile, $language, $modSettings;
  2965. require_once($sourcedir . '/Subs-Post.php');
  2966. // Shouldn't happen but just in case.
  2967. if (empty($profile_vars['email_address']))
  2968. return;
  2969. $replacements = array(
  2970. 'ACTIVATIONLINK' => $scripturl . '?action=activate;u=' . $context['id_member'] . ';code=' . $profile_vars['validation_code'],
  2971. 'ACTIVATIONCODE' => $profile_vars['validation_code'],
  2972. 'ACTIVATIONLINKWITHOUTCODE' => $scripturl . '?action=activate;u=' . $context['id_member'],
  2973. );
  2974. // Send off the email.
  2975. $emaildata = loadEmailTemplate('activate_reactivate', $replacements, empty($cur_profile['lngfile']) || empty($modSettings['userLanguage']) ? $language : $cur_profile['lngfile']);
  2976. sendmail($profile_vars['email_address'], $emaildata['subject'], $emaildata['body'], null, null, false, 0);
  2977. // Log the user out.
  2978. $smcFunc['db_query']('', '
  2979. DELETE FROM {db_prefix}log_online
  2980. WHERE id_member = {int:selected_member}',
  2981. array(
  2982. 'selected_member' => $context['id_member'],
  2983. )
  2984. );
  2985. $_SESSION['log_time'] = 0;
  2986. $_SESSION['login_' . $cookiename] = serialize(array(0, '', 0));
  2987. if (isset($_COOKIE[$cookiename]))
  2988. $_COOKIE[$cookiename] = '';
  2989. loadUserSettings();
  2990. $context['user']['is_logged'] = false;
  2991. $context['user']['is_guest'] = true;
  2992. // Send them to the done-with-registration-login screen.
  2993. loadTemplate('Register');
  2994. $context['page_title'] = $txt['profile'];
  2995. $context['sub_template'] = 'after';
  2996. $context['title'] = $txt['activate_changed_email_title'];
  2997. $context['description'] = $txt['activate_changed_email_desc'];
  2998. // We're gone!
  2999. obExit();
  3000. }
  3001. /**
  3002. * Function to allow the user to choose group membership etc...
  3003. *
  3004. * @param int $memID id_member
  3005. */
  3006. function groupMembership($memID)
  3007. {
  3008. global $txt, $scripturl, $user_profile, $user_info, $context, $modSettings, $smcFunc;
  3009. $curMember = $user_profile[$memID];
  3010. $context['primary_group'] = $curMember['id_group'];
  3011. // Can they manage groups?
  3012. $context['can_manage_membergroups'] = allowedTo('manage_membergroups');
  3013. $context['can_manage_protected'] = allowedTo('admin_forum');
  3014. $context['can_edit_primary'] = $context['can_manage_protected'];
  3015. $context['update_message'] = isset($_GET['msg']) && isset($txt['group_membership_msg_' . $_GET['msg']]) ? $txt['group_membership_msg_' . $_GET['msg']] : '';
  3016. // Get all the groups this user is a member of.
  3017. $groups = explode(',', $curMember['additional_groups']);
  3018. $groups[] = $curMember['id_group'];
  3019. // Ensure the query doesn't croak!
  3020. if (empty($groups))
  3021. $groups = array(0);
  3022. // Just to be sure...
  3023. foreach ($groups as $k => $v)
  3024. $groups[$k] = (int) $v;
  3025. // Get all the membergroups they can join.
  3026. $request = $smcFunc['db_query']('', '
  3027. SELECT mg.id_group, mg.group_name, mg.description, mg.group_type, mg.online_color, mg.hidden,
  3028. IFNULL(lgr.id_member, 0) AS pending
  3029. FROM {db_prefix}membergroups AS mg
  3030. LEFT JOIN {db_prefix}log_group_requests AS lgr ON (lgr.id_member = {int:selected_member} AND lgr.id_group = mg.id_group)
  3031. WHERE (mg.id_group IN ({array_int:group_list})
  3032. OR mg.group_type > {int:nonjoin_group_id})
  3033. AND mg.min_posts = {int:min_posts}
  3034. AND mg.id_group != {int:moderator_group}
  3035. ORDER BY group_name',
  3036. array(
  3037. 'group_list' => $groups,
  3038. 'selected_member' => $memID,
  3039. 'nonjoin_group_id' => 1,
  3040. 'min_posts' => -1,
  3041. 'moderator_group' => 3,
  3042. )
  3043. );
  3044. // This beast will be our group holder.
  3045. $context['groups'] = array(
  3046. 'member' => array(),
  3047. 'available' => array()
  3048. );
  3049. while ($row = $smcFunc['db_fetch_assoc']($request))
  3050. {
  3051. // Can they edit their primary group?
  3052. if (($row['id_group'] == $context['primary_group'] && $row['group_type'] > 1) || ($row['hidden'] != 2 && $context['primary_group'] == 0 && in_array($row['id_group'], $groups)))
  3053. $context['can_edit_primary'] = true;
  3054. // If they can't manage (protected) groups, and it's not publically joinable or already assigned, they can't see it.
  3055. if (((!$context['can_manage_protected'] && $row['group_type'] == 1) || (!$context['can_manage_membergroups'] && $row['group_type'] == 0)) && $row['id_group'] != $context['primary_group'])
  3056. continue;
  3057. $context['groups'][in_array($row['id_group'], $groups) ? 'member' : 'available'][$row['id_group']] = array(
  3058. 'id' => $row['id_group'],
  3059. 'name' => $row['group_name'],
  3060. 'desc' => $row['description'],
  3061. 'color' => $row['online_color'],
  3062. 'type' => $row['group_type'],
  3063. 'pending' => $row['pending'],
  3064. 'is_primary' => $row['id_group'] == $context['primary_group'],
  3065. 'can_be_primary' => $row['hidden'] != 2,
  3066. // Anything more than this needs to be done through account settings for security.
  3067. 'can_leave' => $row['id_group'] != 1 && $row['group_type'] > 1 ? true : false,
  3068. );
  3069. }
  3070. $smcFunc['db_free_result']($request);
  3071. // Add registered members on the end.
  3072. $context['groups']['member'][0] = array(
  3073. 'id' => 0,
  3074. 'name' => $txt['regular_members'],
  3075. 'desc' => $txt['regular_members_desc'],
  3076. 'type' => 0,
  3077. 'is_primary' => $context['primary_group'] == 0 ? true : false,
  3078. 'can_be_primary' => true,
  3079. 'can_leave' => 0,
  3080. );
  3081. // No changing primary one unless you have enough groups!
  3082. if (count($context['groups']['member']) < 2)
  3083. $context['can_edit_primary'] = false;
  3084. // In the special case that someone is requesting membership of a group, setup some special context vars.
  3085. if (isset($_REQUEST['request']) && isset($context['groups']['available'][(int) $_REQUEST['request']]) && $context['groups']['available'][(int) $_REQUEST['request']]['type'] == 2)
  3086. $context['group_request'] = $context['groups']['available'][(int) $_REQUEST['request']];
  3087. }
  3088. /**
  3089. * This function actually makes all the group changes
  3090. *
  3091. * @param array $profile_vars
  3092. * @param array $post_errors
  3093. * @param int $memID id_member
  3094. * @return mixed
  3095. */
  3096. function groupMembership2($profile_vars, $post_errors, $memID)
  3097. {
  3098. global $user_info, $sourcedir, $context, $user_profile, $modSettings, $txt, $smcFunc, $scripturl, $language;
  3099. // Let's be extra cautious...
  3100. if (!$context['user']['is_owner'] || empty($modSettings['show_group_membership']))
  3101. isAllowedTo('manage_membergroups');
  3102. if (!isset($_REQUEST['gid']) && !isset($_POST['primary']))
  3103. fatal_lang_error('no_access', false);
  3104. checkSession(isset($_GET['gid']) ? 'get' : 'post');
  3105. $old_profile = &$user_profile[$memID];
  3106. $context['can_manage_membergroups'] = allowedTo('manage_membergroups');
  3107. $context['can_manage_protected'] = allowedTo('admin_forum');
  3108. // By default the new primary is the old one.
  3109. $newPrimary = $old_profile['id_group'];
  3110. $addGroups = array_flip(explode(',', $old_profile['additional_groups']));
  3111. $canChangePrimary = $old_profile['id_group'] == 0 ? 1 : 0;
  3112. $changeType = isset($_POST['primary']) ? 'primary' : (isset($_POST['req']) ? 'request' : 'free');
  3113. // One way or another, we have a target group in mind...
  3114. $group_id = isset($_REQUEST['gid']) ? (int) $_REQUEST['gid'] : (int) $_POST['primary'];
  3115. $foundTarget = $changeType == 'primary' && $group_id == 0 ? true : false;
  3116. // Sanity check!!
  3117. if ($group_id == 1)
  3118. isAllowedTo('admin_forum');
  3119. // Protected groups too!
  3120. else
  3121. {
  3122. $request = $smcFunc['db_query']('', '
  3123. SELECT group_type
  3124. FROM {db_prefix}membergroups
  3125. WHERE id_group = {int:current_group}
  3126. LIMIT {int:limit}',
  3127. array(
  3128. 'current_group' => $group_id,
  3129. 'limit' => 1,
  3130. )
  3131. );
  3132. list ($is_protected) = $smcFunc['db_fetch_row']($request);
  3133. $smcFunc['db_free_result']($request);
  3134. if ($is_protected == 1)
  3135. isAllowedTo('admin_forum');
  3136. }
  3137. // What ever we are doing, we need to determine if changing primary is possible!
  3138. $request = $smcFunc['db_query']('', '
  3139. SELECT id_group, group_type, hidden, group_name
  3140. FROM {db_prefix}membergroups
  3141. WHERE id_group IN ({int:group_list}, {int:current_group})',
  3142. array(
  3143. 'group_list' => $group_id,
  3144. 'current_group' => $old_profile['id_group'],
  3145. )
  3146. );
  3147. while ($row = $smcFunc['db_fetch_assoc']($request))
  3148. {
  3149. // Is this the new group?
  3150. if ($row['id_group'] == $group_id)
  3151. {
  3152. $foundTarget = true;
  3153. $group_name = $row['group_name'];
  3154. // Does the group type match what we're doing - are we trying to request a non-requestable group?
  3155. if ($changeType == 'request' && $row['group_type'] != 2)
  3156. fatal_lang_error('no_access', false);
  3157. // What about leaving a requestable group we are not a member of?
  3158. elseif ($changeType == 'free' && $row['group_type'] == 2 && $old_profile['id_group'] != $row['id_group'] && !isset($addGroups[$row['id_group']]))
  3159. fatal_lang_error('no_access', false);
  3160. elseif ($changeType == 'free' && $row['group_type'] != 3 && $row['group_type'] != 2)
  3161. fatal_lang_error('no_access', false);
  3162. // We can't change the primary group if this is hidden!
  3163. if ($row['hidden'] == 2)
  3164. $canChangePrimary = false;
  3165. }
  3166. // If this is their old primary, can we change it?
  3167. if ($row['id_group'] == $old_profile['id_group'] && ($row['group_type'] > 1 || $context['can_manage_membergroups']) && $canChangePrimary !== false)
  3168. $canChangePrimary = 1;
  3169. // If we are not doing a force primary move, don't do it automatically if current primary is not 0.
  3170. if ($changeType != 'primary' && $old_profile['id_group'] != 0)
  3171. $canChangePrimary = false;
  3172. // If this is the one we are acting on, can we even act?
  3173. if ((!$context['can_manage_protected'] && $row['group_type'] == 1) || (!$context['can_manage_membergroups'] && $row['group_type'] == 0))
  3174. $canChangePrimary = false;
  3175. }
  3176. $smcFunc['db_free_result']($request);
  3177. // Didn't find the target?
  3178. if (!$foundTarget)
  3179. fatal_lang_error('no_access', false);
  3180. // Final security check, don't allow users to promote themselves to admin.
  3181. if ($context['can_manage_membergroups'] && !allowedTo('admin_forum'))
  3182. {
  3183. $request = $smcFunc['db_query']('', '
  3184. SELECT COUNT(permission)
  3185. FROM {db_prefix}permissions
  3186. WHERE id_group = {int:selected_group}
  3187. AND permission = {string:admin_forum}
  3188. AND add_deny = {int:not_denied}',
  3189. array(
  3190. 'selected_group' => $group_id,
  3191. 'not_denied' => 1,
  3192. 'admin_forum' => 'admin_forum',
  3193. )
  3194. );
  3195. list ($disallow) = $smcFunc['db_fetch_row']($request);
  3196. $smcFunc['db_free_result']($request);
  3197. if ($disallow)
  3198. isAllowedTo('admin_forum');
  3199. }
  3200. // If we're requesting, add the note then return.
  3201. if ($changeType == 'request')
  3202. {
  3203. $request = $smcFunc['db_query']('', '
  3204. SELECT id_member
  3205. FROM {db_prefix}log_group_requests
  3206. WHERE id_member = {int:selected_member}
  3207. AND id_group = {int:selected_group}',
  3208. array(
  3209. 'selected_member' => $memID,
  3210. 'selected_group' => $group_id,
  3211. )
  3212. );
  3213. if ($smcFunc['db_num_rows']($request) != 0)
  3214. fatal_lang_error('profile_error_already_requested_group');
  3215. $smcFunc['db_free_result']($request);
  3216. // Log the request.
  3217. $smcFunc['db_insert']('',
  3218. '{db_prefix}log_group_requests',
  3219. array(
  3220. 'id_member' => 'int', 'id_group' => 'int', 'time_applied' => 'int', 'reason' => 'string-65534',
  3221. ),
  3222. array(
  3223. $memID, $group_id, time(), $_POST['reason'],
  3224. ),
  3225. array('id_request')
  3226. );
  3227. // Set up some data for our background task...
  3228. $data = serialize(array('id_member' => $memID, 'member_name' => $user_info['name'], 'id_group' => $group_id, 'group_name' => $group_name, 'reason' => $_POST['reason'], 'time' => time()));
  3229. // Add a background task to handle notifying people of this request
  3230. $smcFunc['db_insert']('insert', '{db_prefix}background_tasks',
  3231. array('task_file' => 'string-255', 'task_class' => 'string-255', 'task_data' => 'string', 'claimed_time' => 'int'),
  3232. array('$sourcedir/tasks/GroupReq-Notify.php', 'GroupReq_Notify_Background', $data, 0), array()
  3233. );
  3234. return $changeType;
  3235. }
  3236. // Otherwise we are leaving/joining a group.
  3237. elseif ($changeType == 'free')
  3238. {
  3239. // Are we leaving?
  3240. if ($old_profile['id_group'] == $group_id || isset($addGroups[$group_id]))
  3241. {
  3242. if ($old_profile['id_group'] == $group_id)
  3243. $newPrimary = 0;
  3244. else
  3245. unset($addGroups[$group_id]);
  3246. }
  3247. // ... if not, must be joining.
  3248. else
  3249. {
  3250. // Can we change the primary, and do we want to?
  3251. if ($canChangePrimary)
  3252. {
  3253. if ($old_profile['id_group'] != 0)
  3254. $addGroups[$old_profile['id_group']] = -1;
  3255. $newPrimary = $group_id;
  3256. }
  3257. // Otherwise it's an additional group...
  3258. else
  3259. $addGroups[$group_id] = -1;
  3260. }
  3261. }
  3262. // Finally, we must be setting the primary.
  3263. elseif ($canChangePrimary)
  3264. {
  3265. if ($old_profile['id_group'] != 0)
  3266. $addGroups[$old_profile['id_group']] = -1;
  3267. if (isset($addGroups[$group_id]))
  3268. unset($addGroups[$group_id]);
  3269. $newPrimary = $group_id;
  3270. }
  3271. // Finally, we can make the changes!
  3272. foreach ($addGroups as $id => $dummy)
  3273. if (empty($id))
  3274. unset($addGroups[$id]);
  3275. $addGroups = implode(',', array_flip($addGroups));
  3276. // Ensure that we don't cache permissions if the group is changing.
  3277. if ($context['user']['is_owner'])
  3278. $_SESSION['mc']['time'] = 0;
  3279. else
  3280. updateSettings(array('settings_updated' => time()));
  3281. updateMemberData($memID, array('id_group' => $newPrimary, 'additional_groups' => $addGroups));
  3282. return $changeType;
  3283. }
  3284. ?>