Profile-Modify.php 122 KB

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