From 28de9f2be164f06267eaff7560ab7dac8a402e7f Mon Sep 17 00:00:00 2001 From: Cameron Date: Mon, 23 Jan 2017 17:54:43 -0800 Subject: [PATCH] Fixes #2270: Usersettings : Custom User Fields on Legacy themes. Fixes #2165: Country field added (doesn't required database) Fixes #1297: Extended fields failing --- .../batch/usersettings_shortcodes.php | 136 +++++++++++------- e107_core/templates/header_default.php | 2 +- e107_core/xml/user_extended.xml | 3 +- e107_handlers/user_extended_class.php | 20 ++- e107_languages/English/lan_user_extended.php | 5 +- e107_web/css/backcompat.css | 4 +- usersettings.php | 10 ++ 7 files changed, 119 insertions(+), 61 deletions(-) diff --git a/e107_core/shortcodes/batch/usersettings_shortcodes.php b/e107_core/shortcodes/batch/usersettings_shortcodes.php index 5f2e61ec3..29f36637a 100755 --- a/e107_core/shortcodes/batch/usersettings_shortcodes.php +++ b/e107_core/shortcodes/batch/usersettings_shortcodes.php @@ -18,6 +18,7 @@ if (!defined('e107_INIT')) { exit; } class usersettings_shortcodes extends e_shortcode { private $extendedTabs = false; + public $legacyTemplate = array(); function sc_username($parm) // This is the 'display name' { @@ -375,22 +376,25 @@ class usersettings_shortcodes extends e_shortcode return $ret; } - - - - function sc_userextended_cat($parm='') - { - global $usersettings_shortcodes, $USER_EXTENDED_CAT, $extended_showed; - - if(deftrue('BOOTSTRAP')===3) + + + function sc_userextended_cat($parm = '') + { + global $extended_showed; + + if(THEME_LEGACY === true) { - $USER_EXTENDED_CAT = e107::getCoreTemplate('usersettings','extended-category'); + $USER_EXTENDED_CAT = $this->legacyTemplate['USER_EXTENDED_CAT']; } - - + else + { + $USER_EXTENDED_CAT = e107::getCoreTemplate('usersettings', 'extended-category'); + } + + $sql = e107::getDb(); $tp = e107::getParser(); - + if(isset($extended_showed['cat'][$parm])) { return ""; @@ -401,26 +405,27 @@ class usersettings_shortcodes extends e_shortcode { $qry = " SELECT * FROM #user_extended_struct - WHERE user_extended_struct_applicable IN (".$tp -> toDB($this->var['userclass_list'], true).") - AND user_extended_struct_write IN (".USERCLASS_LIST.") - AND user_extended_struct_id = ".intval($parm)." + WHERE user_extended_struct_applicable IN (" . $tp->toDB($this->var['userclass_list'], true) . ") + AND user_extended_struct_write IN (" . USERCLASS_LIST . ") + AND user_extended_struct_id = " . intval($parm) . " "; if($sql->gen($qry)) { $catInfo = $sql->fetch(); } } - + if($catInfo) { $qry = " SELECT * FROM #user_extended_struct - WHERE user_extended_struct_applicable IN (".$tp -> toDB($this->var['userclass_list'], true).") - AND user_extended_struct_write IN (".USERCLASS_LIST.") - AND user_extended_struct_parent = ".intval($parm)." + WHERE user_extended_struct_applicable IN (" . $tp->toDB($this->var['userclass_list'], true) . ") + AND user_extended_struct_write IN (" . USERCLASS_LIST . ") + AND user_extended_struct_parent = " . intval($parm) . " AND user_extended_struct_type != 0 ORDER BY user_extended_struct_order ASC "; + if($sql->gen($qry)) { $fieldList = $sql->db_getList(); @@ -429,94 +434,115 @@ class usersettings_shortcodes extends e_shortcode cachevars("extendedfield_{$field['user_extended_struct_name']}", $field); //TODO use $this instead of parseTemplate(); $ret .= $this->sc_userextended_field($field['user_extended_struct_name']); - // $ret .= $tp->parseTemplate("{USEREXTENDED_FIELD={$field['user_extended_struct_name']}}", TRUE, $usersettings_shortcodes); + // $ret .= $tp->parseTemplate("{USEREXTENDED_FIELD={$field['user_extended_struct_name']}}", TRUE, $usersettings_shortcodes); } } } - + if($ret && $this->extendedTabs == false) { $catName = $catInfo['user_extended_struct_text'] ? $catInfo['user_extended_struct_text'] : $catInfo['user_extended_struct_name']; - if(defined($catName)) $catName = constant($catName); - $ret = str_replace("{CATNAME}", $tp->toHTML($catName, FALSE, 'emotes_off,defs'), $USER_EXTENDED_CAT).$ret; + if(defined($catName)) + { + $catName = constant($catName); + } + $ret = str_replace("{CATNAME}", $tp->toHTML($catName, false, 'emotes_off,defs'), $USER_EXTENDED_CAT) . $ret; } - + $extended_showed['cat'][$parm] = 1; + return $ret; } - - - - function sc_userextended_field($parm='') - { - global $usersettings_shortcodes, $extended_showed, $ue, $USEREXTENDED_FIELD, $REQUIRED_FIELD; - - if(deftrue('BOOTSTRAP')===3) + + + function sc_userextended_field($parm = '') + { + global $extended_showed; + + $ue = e107::getUserExt(); + + + if(THEME_LEGACY === true) { - $USEREXTENDED_FIELD = e107::getCoreTemplate('usersettings','extended-field'); + $USEREXTENDED_FIELD = $this->legacyTemplate['USEREXTENDED_FIELD']; + $REQUIRED_FIELD = $this->legacyTemplate['REQUIRED_FIELD']; } - - + else + { + $USEREXTENDED_FIELD = e107::getCoreTemplate('usersettings', 'extended-field'); + $REQUIRED_FIELD = ''; + } + + if(isset($extended_showed['field'][$parm])) { return ""; } - + $sql = e107::getDb(); $tp = e107::getParser(); - - + $ret = ""; - + $fInfo = getcachedvars("extendeddata_{$parm}"); + if(!$fInfo) { $qry = " SELECT * FROM #user_extended_struct - WHERE user_extended_struct_applicable IN (".$tp -> toDB($this->var['userclass_list'], true).") - AND user_extended_struct_write IN (".USERCLASS_LIST.") - AND user_extended_struct_name = '".$tp -> toDB($parm, true)."' + WHERE user_extended_struct_applicable IN (" . $tp->toDB($this->var['userclass_list'], true) . ") + AND user_extended_struct_write IN (" . USERCLASS_LIST . ") + AND user_extended_struct_name = '" . $tp->toDB($parm, true) . "' "; if($sql->gen($qry)) { $fInfo = $sql->fetch(); } } - + if($fInfo) { $fname = $fInfo['user_extended_struct_text']; - if(defined($fname)) $fname = constant($fname); + + if(defined($fname)) + { + $fname = constant($fname); + } + $fname = $tp->toHTML($fname, "", "emotes_off, defs"); - + if($fInfo['user_extended_struct_required'] == 1 && !deftrue('BOOTSTRAP')) { $fname = str_replace("{FIELDNAME}", $fname, $REQUIRED_FIELD); } - - $parms = explode("^,^",$fInfo['user_extended_struct_parms']); - - $fhide=""; + + $parms = explode("^,^", $fInfo['user_extended_struct_parms']); + + $fhide = ""; + if(varset($parms[3])) { - $chk = (strpos($this->var['user_hidden_fields'], "^user_".$parm."^") === FALSE) ? FALSE : TRUE; + $chk = (strpos($this->var['user_hidden_fields'], "^user_" . $parm . "^") === false) ? false : true; + if(isset($_POST['updatesettings'])) { - $chk = isset($_POST['hide']['user_'.$parm]); + $chk = isset($_POST['hide']['user_' . $parm]); } + $fhide = $ue->user_extended_hide($fInfo, $chk); } - - $uVal = str_replace(chr(1), "", $this->var['user_'.$parm]); + + $uVal = str_replace(chr(1), "", $this->var['user_' . $parm]); $fval = $ue->user_extended_edit($fInfo, $uVal); - + $ret = $USEREXTENDED_FIELD; $ret = str_replace("{FIELDNAME}", $fname, $ret); $ret = str_replace("{FIELDVAL}", $fval, $ret); $ret = str_replace("{HIDEFIELD}", $fhide, $ret); } - + $extended_showed['field'][$parm] = 1; + return $ret; } diff --git a/e107_core/templates/header_default.php b/e107_core/templates/header_default.php index 0df1232c3..d5c8a9f6b 100644 --- a/e107_core/templates/header_default.php +++ b/e107_core/templates/header_default.php @@ -187,7 +187,7 @@ if (/*!defined("PREVIEWTHEME") && */! (isset($no_core_css) && $no_core_css !==tr $e_js->otherCSS('{e_WEB_CSS}e107.css'); } -if(!deftrue('BOOTSTRAP')) +if(THEME_LEGACY === true) { $e_js->otherCSS('{e_WEB_CSS}backcompat.css'); } diff --git a/e107_core/xml/user_extended.xml b/e107_core/xml/user_extended.xml index 04dfd5bf4..7447269f5 100644 --- a/e107_core/xml/user_extended.xml +++ b/e107_core/xml/user_extended.xml @@ -8,8 +8,7 @@ 253 - db field - user_extended_country,country_iso,country_name,country_name + country 253 253 diff --git a/e107_handlers/user_extended_class.php b/e107_handlers/user_extended_class.php index 8488a8b78..e7fa024e3 100644 --- a/e107_handlers/user_extended_class.php +++ b/e107_handlers/user_extended_class.php @@ -67,6 +67,7 @@ class e107_user_extended define('EUF_CHECKBOX',10); define('EUF_PREFIELD',11); // should be EUF_PREDEFINED, useful when creating fields from e.g. plugin XML define('EUF_ADDON', 12); // defined within e_user.php addon + define('EUF_COUNTRY', 13); // $frm->country() $this->typeArray = array( 'text' => 1, @@ -80,7 +81,8 @@ class e107_user_extended 'list' => 9, 'checkbox' => 10, 'predefined' => 11, // DON'T USE IT IN PREDEFINED FIELD XML!!! Used in plugin installation routine. - 'addon' => 12 + 'addon' => 12, + 'country' => 13, ); $this->user_extended_types = array( @@ -488,6 +490,10 @@ class e107_user_extended switch ($type) { + case EUF_COUNTRY : + $db_type = 'VARCHAR(2)'; + break; + case EUF_INTEGER : $db_type = 'INT(11)'; break; @@ -577,6 +583,7 @@ class e107_user_extended if ($this->user_extended_reserved($name)) { + e107::getMessage()->addDebug("Reserved Field"); return false; } @@ -753,6 +760,12 @@ class e107_user_extended switch($struct['user_extended_struct_type']) { + + case EUF_COUNTRY: + return e107::getForm()->country($fname,$curval); + break; + + case EUF_TEXT : //textbox case EUF_INTEGER : //integer $ret = ""; @@ -921,6 +934,11 @@ class e107_user_extended { $curval = ''; } + + if(THEME_LEGACY === true) + { + return e107::getForm()->text($fname,$curval,10,array('placeholder'=>'yyyy-mm-dd')); + } return e107::getForm()->datepicker($fname,$curval,array('format'=>'yyyy-mm-dd','return'=>'string')); break; diff --git a/e107_languages/English/lan_user_extended.php b/e107_languages/English/lan_user_extended.php index 7b59afecc..00cddfb6b 100644 --- a/e107_languages/English/lan_user_extended.php +++ b/e107_languages/English/lan_user_extended.php @@ -20,6 +20,9 @@ define("UE_LAN_6", "Integer"); define("UE_LAN_8", "Language"); define("UE_LAN_9", "Predefined list"); define("UE_LAN_10", "Checkboxes"); +//v2.1.5 +define("UE_LAN_13", "Country"); + // Leave a gap to allow for more field types define("UE_LAN_21", "Name"); define("UE_LAN_22", "Type"); @@ -44,7 +47,7 @@ define("UE_LAN_BIRTHDAY_DESC", "Birthday"); define("UE_LAN_LANGUAGE", "Language"); define("UE_LAN_LANGUAGE_DESC", "User Language"); define("UE_LAN_COUNTRY", "Country"); -define("UE_LAN_COUNTRY_DESC", "User Country (includes db table)"); +define("UE_LAN_COUNTRY_DESC", "User Country"); define("UE_LAN_TIMEZONE", "Timezone"); define("UE_LAN_TIMEZONE_DESC", "User Timezone (from predefined list)"); diff --git a/e107_web/css/backcompat.css b/e107_web/css/backcompat.css index e9032b301..3961a360e 100644 --- a/e107_web/css/backcompat.css +++ b/e107_web/css/backcompat.css @@ -52,4 +52,6 @@ ul.breadcrumb li span.divider { padding-left:5px; } } .media-left, .media > .pull-left { padding-right: 10px; -} \ No newline at end of file +} + +.form-control { max-width:100% } \ No newline at end of file diff --git a/usersettings.php b/usersettings.php index 99a7a3ec6..794e5cea2 100644 --- a/usersettings.php +++ b/usersettings.php @@ -89,6 +89,9 @@ class usersettings_front // Begin Usersettings rewrite. else { global $sc_style; + $REQUIRED_FIELD = ''; + $USER_EXTENDED_CAT = ''; + $USEREXTENDED_FIELD = ''; $USERSETTINGS_MESSAGE = ''; $USERSETTINGS_MESSAGE_CAPTION = ''; $USERSETTINGS_EDIT_CAPTION = ''; @@ -97,6 +100,13 @@ class usersettings_front // Begin Usersettings rewrite. include_once($coreTemplatePath); //correct way to load a core template. e107::scStyle($sc_style); $usersettings_shortcodes = e107::getScBatch('usersettings'); + + $usersettings_shortcodes->legacyTemplate = array( + 'USER_EXTENDED_CAT' => $USER_EXTENDED_CAT, + 'USEREXTENDED_FIELD' => $USEREXTENDED_FIELD, + 'REQUIRED_FIELD' => $REQUIRED_FIELD + ); + } $this->sc = $usersettings_shortcodes;