mirror of
https://github.com/e107inc/e107.git
synced 2025-04-21 13:11:52 +02:00
Issue #4344 Signup shortcode Extended user field fix.
This commit is contained in:
parent
3bae6306b7
commit
182164a4a0
@ -20,6 +20,7 @@ e107::coreLan('signup');
|
||||
|
||||
class signup_shortcodes extends e_shortcode
|
||||
{
|
||||
public $template = array();
|
||||
|
||||
function sc_signup_coppa_text($parm=null)
|
||||
{
|
||||
@ -462,78 +463,76 @@ class signup_shortcodes extends e_shortcode
|
||||
return $tp->simpleParse($USERCLASS_SUBSCRIBE_ROW, $shortcodes);*/
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
function sc_signup_extended_user_fields($parm=null)
|
||||
{
|
||||
global $SIGNUP_EXTENDED_USER_FIELDS, $SIGNUP_EXTENDED_CAT;
|
||||
|
||||
|
||||
function sc_signup_extended_user_fields($parm = null)
|
||||
{
|
||||
|
||||
$text = "";
|
||||
|
||||
|
||||
$search = array(
|
||||
'{EXTENDED_USER_FIELD_TEXT}',
|
||||
'{EXTENDED_USER_FIELD_REQUIRED}',
|
||||
'{EXTENDED_USER_FIELD_EDIT}'
|
||||
'{EXTENDED_USER_FIELD_TEXT}',
|
||||
'{EXTENDED_USER_FIELD_REQUIRED}',
|
||||
'{EXTENDED_USER_FIELD_EDIT}'
|
||||
);
|
||||
|
||||
|
||||
/** @var e107_user_extended $ue */
|
||||
$ue = e107::getUserExt();
|
||||
$tp = e107::getParser();
|
||||
// What we need is a list of fields, ordered first by parent, and then by display order?
|
||||
// category entries are `user_extended_struct_type` = 0
|
||||
// 'unallocated' entries are `user_extended_struct_parent` = 0
|
||||
|
||||
// Get a list of defined categories
|
||||
$catList = $ue->getCategories();
|
||||
// Add in category zero - the 'no category' category
|
||||
array_unshift($catList,array('user_extended_struct_parent' => 0, 'user_extended_struct_id' => '0'));
|
||||
|
||||
|
||||
|
||||
$catList = $ue->getCategories();
|
||||
|
||||
// Add in category zero - the 'no category' category
|
||||
array_unshift($catList, array('user_extended_struct_parent' => 0, 'user_extended_struct_id' => '0'));
|
||||
|
||||
foreach($catList as $cat)
|
||||
{
|
||||
$extList = $ue->user_extended_get_fieldList($cat['user_extended_struct_id']);
|
||||
|
||||
$done_heading = FALSE;
|
||||
|
||||
if(!count($extList))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
$extList = $ue->getFieldList($cat['user_extended_struct_id']);
|
||||
|
||||
$done_heading = false;
|
||||
|
||||
if(empty($extList))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach($extList as $ext)
|
||||
{
|
||||
$opts = $parm;
|
||||
if($ext['user_extended_struct_required'] == 1 || $ext['user_extended_struct_required'] == 2)
|
||||
$opts = $parm;
|
||||
$required = (int) $ext['user_extended_struct_required'];
|
||||
|
||||
if($required === 0) // "No - Will not show on Signup page".
|
||||
{
|
||||
if(!$done_heading && ($cat['user_extended_struct_id'] > 0))
|
||||
{ // Add in a heading
|
||||
$catName = $cat['user_extended_struct_text'] ? $cat['user_extended_struct_text'] : $cat['user_extended_struct_name'];
|
||||
if(defined($catName))
|
||||
{
|
||||
$catName = constant($catName);
|
||||
}
|
||||
$text .= str_replace('{EXTENDED_CAT_TEXT}', $tp->toHTML($catName, false, 'emotes_off,defs'), $SIGNUP_EXTENDED_CAT);
|
||||
$done_heading = true;
|
||||
}
|
||||
|
||||
$label = $tp->toHTML(deftrue($ext['user_extended_struct_text'], $ext['user_extended_struct_text']), false, 'emotes_off,defs');
|
||||
|
||||
if(isset($opts['placeholder']))
|
||||
{
|
||||
$opts['placeholder'] = str_replace('[label]', $label, $opts['placeholder']);
|
||||
}
|
||||
|
||||
$replace = array(
|
||||
$label,
|
||||
($ext['user_extended_struct_required'] == 1 ? $this->sc_signup_is_mandatory('true') : ''),
|
||||
$ue->renderElement($ext, $_POST['ue']['user_' . $ext['user_extended_struct_name']], $opts)
|
||||
);
|
||||
|
||||
$text .= str_replace($search, $replace, $SIGNUP_EXTENDED_USER_FIELDS);
|
||||
continue;
|
||||
}
|
||||
|
||||
if(!$done_heading && !empty($cat['user_extended_struct_id'])) // Add in a heading
|
||||
{
|
||||
$catName = $cat['user_extended_struct_text'] ? $cat['user_extended_struct_text'] : $cat['user_extended_struct_name'];
|
||||
$catName = defset($catName, $catName);
|
||||
|
||||
$text .= str_replace('{EXTENDED_CAT_TEXT}', $tp->toHTML($catName, false, 'emotes_off,defs'), $this->template['extended-category']);
|
||||
$done_heading = true;
|
||||
}
|
||||
|
||||
$label = $tp->toHTML(deftrue($ext['user_extended_struct_text'], $ext['user_extended_struct_text']), false, 'emotes_off,defs');
|
||||
|
||||
if(isset($opts['placeholder']))
|
||||
{
|
||||
$opts['placeholder'] = str_replace('[label]', $label, $opts['placeholder']);
|
||||
}
|
||||
|
||||
$replace = array(
|
||||
$label,
|
||||
($required === 1 ? $this->sc_signup_is_mandatory('true') : ''),
|
||||
$ue->renderElement($ext, varset($_POST['ue']['user_' . $ext['user_extended_struct_name']]), $opts)
|
||||
);
|
||||
|
||||
$text .= str_replace($search, $replace, $this->template['extended-user-fields']);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return $text;
|
||||
}
|
||||
|
||||
|
@ -591,12 +591,12 @@ class e107_user_extended
|
||||
|
||||
|
||||
/**
|
||||
* Alias of user_extended_get_fieldList().
|
||||
* Get a list of fields in a particular category.
|
||||
* @param string $cat
|
||||
* @param string $indexField
|
||||
* @return mixed
|
||||
*/
|
||||
function getFieldList($cat = "", $indexField = 'user_extended_struct_id')
|
||||
function getFieldList($cat = null, $indexField = 'user_extended_struct_id')
|
||||
{
|
||||
return $this->user_extended_get_fieldList($cat, $indexField);
|
||||
}
|
||||
@ -639,17 +639,18 @@ class e107_user_extended
|
||||
* @param $system - include system fields.
|
||||
* @return array
|
||||
*/
|
||||
function user_extended_get_fieldList($cat = "", $indexField = 'user_extended_struct_id', $system = false)
|
||||
function user_extended_get_fieldList($cat = null, $indexField = 'user_extended_struct_id', $system = false)
|
||||
{
|
||||
if(!$indexField)
|
||||
if(empty($indexField))
|
||||
{
|
||||
$indexField = 'user_extended_struct_id';
|
||||
$indexField = 'user_extended_struct_id';
|
||||
}
|
||||
|
||||
$ret = [];
|
||||
|
||||
foreach($this->fieldDefinitions as $row)
|
||||
{
|
||||
if(!empty($cat) && ($row['user_extended_struct_parent'] !== (int) $cat))
|
||||
if($cat !== null && ($row['user_extended_struct_parent'] !== (int) $cat))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
@ -115,6 +115,7 @@
|
||||
'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,
|
||||
'required' => 1, // show in signup shortcode.
|
||||
);
|
||||
|
||||
$this->ue->user_extended_add($insert);
|
||||
@ -315,6 +316,27 @@
|
||||
|
||||
}
|
||||
|
||||
public function testSignupExtendedUserFieldsShortcode()
|
||||
{
|
||||
|
||||
$sc = e107::getScBatch('signup');
|
||||
|
||||
$template = array(
|
||||
'extended-category' => "-- {EXTENDED_CAT_TEXT} --",
|
||||
'extended-user-fields' => "<label>{EXTENDED_USER_FIELD_TEXT}{EXTENDED_USER_FIELD_REQUIRED}</label>" // {EXTENDED_USER_FIELD_EDIT}
|
||||
);
|
||||
|
||||
$expected = "<label>Text<span class='required'><!-- empty --></span></label><label>Homepage<span class='required'><!-- empty --></span></label><label>Dropdown<span class='required'><!-- empty --></span></label><label>Dbfield<span class='required'><!-- empty --></span></label><label>Integer<span class='required'><!-- empty --></span></label><label>Date<span class='required'><!-- empty --></span></label><label>Language<span class='required'><!-- empty --></span></label><label>Checkbox<span class='required'><!-- empty --></span></label><label>Predefined<span class='required'><!-- empty --></span></label><label>Addon<span class='required'><!-- empty --></span></label><label>Richtextarea<span class='required'><!-- empty --></span></label>-- Category Name --<label>Radio<span class='required'><!-- empty --></span></label><label>Textarea<span class='required'><!-- empty --></span></label><label>List<span class='required'><!-- empty --></span></label>-- Category Name 2 --<label>Country<span class='required'><!-- empty --></span></label>";
|
||||
|
||||
$sc->template = $template;
|
||||
|
||||
$result = e107::getParser()->parseTemplate('{SIGNUP_EXTENDED_USER_FIELDS}', false, $sc);
|
||||
$this->assertSame($expected, $result);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function testGetUserExtendedFieldData()
|
||||
{
|
||||
$sc = e107::getScBatch('usersettings');
|
||||
|
@ -83,10 +83,15 @@ if($template = e107::getCoreTemplate('signup'))
|
||||
else
|
||||
{
|
||||
require_once(e107::coreTemplatePath('signup')); //correct way to load a core template.
|
||||
$template = array(
|
||||
'extended-user-fields' => $SIGNUP_EXTENDED_USER_FIELDS,
|
||||
'extended-category' => $SIGNUP_EXTENDED_CAT
|
||||
);
|
||||
}
|
||||
|
||||
$signup_shortcodes = e107::getScBatch('signup');
|
||||
$signup_shortcodes->wrapper('signup');
|
||||
$signup_shortcodes->template = $template;
|
||||
// $facebook_shortcodes = e107::getScBatch('facebook',TRUE);
|
||||
|
||||
$signup_imagecode = ($pref['signcode'] && extension_loaded('gd'));
|
||||
|
Loading…
x
Reference in New Issue
Block a user