Profile-Modify.php 126 KB

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