diff --git a/e107_core/shortcodes/batch/usersettings_shortcodes.php b/e107_core/shortcodes/batch/usersettings_shortcodes.php index 17cfda4a7..cf86f91f5 100755 --- a/e107_core/shortcodes/batch/usersettings_shortcodes.php +++ b/e107_core/shortcodes/batch/usersettings_shortcodes.php @@ -350,8 +350,12 @@ class usersettings_shortcodes extends e_shortcode $sql = e107::getDb(); $tp = e107::getParser(); $frm = e107::getForm(); - - + + if(empty($this->var['userclass_list']) && ADMIN) + { + return '$this->var[\'userclass_list\'] is empty'; + } + $qry = " SELECT * FROM #user_extended_struct WHERE user_extended_struct_applicable IN (".$tp -> toDB($this->var['userclass_list'], true).") @@ -392,9 +396,7 @@ class usersettings_shortcodes extends e_shortcode $tabs[] = array('caption'=>$catName, 'text'=>$text); } } - - - + if(($parm == 'tabs') && !empty($tabs) && deftrue('BOOTSTRAP')) { return e107::getForm()->tabs($tabs); @@ -445,6 +447,7 @@ class usersettings_shortcodes extends e_shortcode } } + if($catInfo) { $qry = " @@ -462,9 +465,7 @@ class usersettings_shortcodes extends e_shortcode foreach($fieldList as $field) { e107::setRegistry("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); } } } @@ -484,6 +485,28 @@ class usersettings_shortcodes extends e_shortcode return $ret; } + public function getUserExtendedFieldData($name) + { + $tp = e107::getParser(); + $sql = e107::getDb(); + + $fInfo = array(); + + $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($name, true) . "' + "; + if($sql->gen($qry)) + { + $fInfo = $sql->fetch(); + } + + return $fInfo; + } + + function sc_userextended_field($parm = null) { @@ -522,16 +545,7 @@ class usersettings_shortcodes extends e_shortcode 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) . "' - "; - if($sql->gen($qry)) - { - $fInfo = $sql->fetch(); - } + $fInfo = $this->getUserExtendedFieldData($parm); } if($fInfo) @@ -572,6 +586,8 @@ class usersettings_shortcodes extends e_shortcode $rVal = !empty($fInfo['user_extended_struct_required']) ; + + $ret = $USEREXTENDED_FIELD; $ret = str_replace("{FIELDNAME}", $fname, $ret); $ret = str_replace("{FIELDVAL}", $fval, $ret); diff --git a/e107_handlers/user_extended_class.php b/e107_handlers/user_extended_class.php index ddece3b82..71478e0e0 100644 --- a/e107_handlers/user_extended_class.php +++ b/e107_handlers/user_extended_class.php @@ -155,6 +155,9 @@ class e107_user_extended else { // Its a field definition $id = 'user_' . $row['user_extended_struct_name']; + + $row['user_extended_struct_parent'] = (int) $row['user_extended_struct_parent']; + $this->fieldDefinitions[$row['user_extended_struct_id']] = $row; @@ -575,17 +578,13 @@ class e107_user_extended // Get the definition of all fields, or those in a specific category, grouped by category ID // Reads non-system fields only - function user_extended_get_fields($cat = "") + public function user_extended_get_fields($cat = "") { - $sql = e107::getDb('ue'); + $list = $this->getFieldList($cat); $ret = array(); - $more = ($cat) ? " AND user_extended_struct_parent = ".intval($cat)." " : ""; - if($sql->select("user_extended_struct", "*", "user_extended_struct_type > 0 AND user_extended_struct_text != '_system_' {$more} ORDER BY user_extended_struct_order ASC")) + foreach($list as $row) { - while($row = $sql->fetch()) - { - $ret[$row['user_extended_struct_parent']][] = $row; - } + $ret[$row['user_extended_struct_parent']][] = $row; } return $ret; } @@ -646,7 +645,28 @@ class e107_user_extended { $indexField = 'user_extended_struct_id'; } - + + $ret = []; + foreach($this->fieldDefinitions as $row) + { + if(!empty($cat) && ($row['user_extended_struct_parent'] !== (int) $cat)) + { + continue; + } + + if($system == false && ($row['user_extended_struct_text'] === '_system_')) + { + continue; + } + + $id = $row[$indexField]; + $ret[$id] = $row; + + } + + return $ret; + + /* $sql = e107::getDb('ue'); $ret = array(); @@ -662,7 +682,7 @@ class e107_user_extended } } - return $ret; + return $ret;*/ } @@ -673,18 +693,14 @@ class e107_user_extended function getFieldNames() { $ret = array(); - - $sql = e107::getDb('ue'); - - if($sql->select("user_extended_struct", "*", "user_extended_struct_type > 0 ORDER BY user_extended_struct_order ASC")) + + foreach($this->fieldDefinitions as $row) { - while($row = $sql->fetch()) - { - $ret[] = 'user_'.$row['user_extended_struct_name']; - } + $ret[] = 'user_'.$row['user_extended_struct_name']; + } + return $ret; - } diff --git a/e107_tests/tests/unit/e107Test.php b/e107_tests/tests/unit/e107Test.php index 4f27c306c..6a5da6773 100644 --- a/e107_tests/tests/unit/e107Test.php +++ b/e107_tests/tests/unit/e107Test.php @@ -871,6 +871,7 @@ class e107Test extends \Codeception\Test\Unit e_PLUGIN_ABS . 'forum/forum_viewtopic.php?f=post&id=123', $url, "Generated href does not match expectation" ); + e107::getDb()->truncate('user_extended_struct');// reset. } public function testUrlOptionQueryUrlEncoded() @@ -888,6 +889,7 @@ class e107Test extends \Codeception\Test\Unit 'forum/post/?didn%27t=%3Ctag%20attr%3D%22such%20wow%22%3E%3C/tag%3E&did=much%20doge', $url, "Generated href query string did not have expected URL encoding" ); + e107::getDb()->truncate('user_extended_struct');// reset. } public function testUrlEscapesHtmlSpecialChars() @@ -904,6 +906,7 @@ class e107Test extends \Codeception\Test\Unit 'forum/<>/#Arts & Crafts <tag attr="can't inject here"></tag>', $url, "Generated href did not prevent HTML tag injection as expected" ); + e107::getDb()->truncate('user_extended_struct');// reset. } /* public function testRedirect() diff --git a/e107_tests/tests/unit/e107_user_extendedTest.php b/e107_tests/tests/unit/e107_user_extendedTest.php index 08746f82e..0e9cbc172 100644 --- a/e107_tests/tests/unit/e107_user_extendedTest.php +++ b/e107_tests/tests/unit/e107_user_extendedTest.php @@ -18,6 +18,7 @@ /** @var e107_user_extended */ protected $ue; + protected function _before() { @@ -37,7 +38,7 @@ 'homepage' => EUF_TEXT, 'radio' => EUF_RADIO, 'dropdown' => EUF_DROPDOWN, - 'dbfield' => EUF_DB_FIELD, + 'dbfield' => EUF_DB_FIELD, 'textarea' => EUF_TEXTAREA, 'integer' => EUF_INTEGER, 'date' => EUF_DATE, @@ -85,6 +86,15 @@ ); + $this->structParent = array( + 'list' => 16, + 'radio' => 16, + 'textarea' => 16, + 'country' => 17, + ); + + + // Add a field of each type. foreach($this->structTypes as $k=> $v) @@ -98,6 +108,7 @@ 'parms' => null, 'values' => (isset($this->structValues[$k])) ? $this->structValues[$k] : null, 'default' => (isset($this->structDefault[$k])) ? $this->structDefault[$k] : null, + 'parent' => (isset($this->structParent[$k])) ? $this->structParent[$k] : 0, ); $this->ue->user_extended_add($insert); @@ -148,12 +159,8 @@ ); - - - $this->ue->init(); - } public function testSetGet() @@ -274,6 +281,50 @@ } + public function testUserExtendedAllShortcode() + { + + $sc = e107::getScBatch('usersettings'); + + $sc->setVars(array('userclass_list' => '253,251,0,254,250')); + + $result = e107::getParser()->parseTemplate('{USEREXTENDED_ALL}', false, $sc); + + $this->assertStringContainsString('