1
0
mirror of https://github.com/e107inc/e107.git synced 2025-08-01 12:20:44 +02:00

Forum and User-extended shortcode improvements and test tweaks.

This commit is contained in:
Cameron
2021-01-11 08:45:08 -08:00
parent d4df39bc75
commit 3d217bc49b
6 changed files with 111 additions and 46 deletions

View File

@@ -20,17 +20,24 @@
global $loop_uid, $e107, $sc_style; global $loop_uid, $e107, $sc_style;
if(empty($parm))
{
trigger_error('{USER_EXTENDED} was sent an empty $parm',E_USER_NOTICE);
return null;
}
$tmp = explode('.', $parm); $tmp = explode('.', $parm);
$fieldname = $tmp[0];
$type = $tmp[1]; $fieldname = trim($tmp[0]);
$type = trim($tmp[1]);
$user = varset($tmp[2], 0); $user = varset($tmp[2], 0);
if(isset($loop_uid) && intval($loop_uid) == 0) if(isset($loop_uid) && $loop_uid === 0)
{ {
return ''; return '';
} }
$key = $fieldname.".".$type; $key = $fieldname. '.' .$type;
$sc_style['USER_EXTENDED']['pre'] = (isset($sc_style['USER_EXTENDED'][$key]['pre']) ? $sc_style['USER_EXTENDED'][$key]['pre'] : ''); $sc_style['USER_EXTENDED']['pre'] = (isset($sc_style['USER_EXTENDED'][$key]['pre']) ? $sc_style['USER_EXTENDED'][$key]['pre'] : '');
$sc_style['USER_EXTENDED']['post'] = (isset($sc_style['USER_EXTENDED'][$key]['post']) ? $sc_style['USER_EXTENDED'][$key]['post'] : ''); $sc_style['USER_EXTENDED']['post'] = (isset($sc_style['USER_EXTENDED'][$key]['post']) ? $sc_style['USER_EXTENDED'][$key]['post'] : '');
@@ -39,7 +46,7 @@
if($uid === 0) if($uid === 0)
{ {
if(isset($loop_uid) && intval($loop_uid) > 0) if(isset($loop_uid) && $loop_uid > 0)
{ {
$uid = $loop_uid; $uid = $loop_uid;
} }
@@ -52,7 +59,7 @@
$udata = e107::user($uid); $udata = e107::user($uid);
$udata['user_class'] .= ($udata['user_class'] == '' ? '' : ','); $udata['user_class'] .= ($udata['user_class'] == '' ? '' : ',');
$udata['user_class'] .= e_UC_PUBLIC.",".e_UC_MEMBER; $udata['user_class'] .= e_UC_PUBLIC. ',' .e_UC_MEMBER;
if(!empty($udata['user_admin'])) if(!empty($udata['user_admin']))
{ {
@@ -70,9 +77,9 @@
if(($type !== 'icon') && ($ue->getCategoryAttribute($fieldname, 'read') === false)) if(($type !== 'icon') && ($ue->getCategoryAttribute($fieldname, 'read') === false))
{ {
$fkeyApplic = $ue->getFieldAttribute("user_" . $fieldname, 'applicable'); $fkeyApplic = $ue->getFieldAttribute('user_' . $fieldname, 'applicable');
$fkeyRead = $ue->getFieldAttribute("user_" . $fieldname, 'read'); $fkeyRead = $ue->getFieldAttribute('user_' . $fieldname, 'read');
$fkeyStruct = $ue->getFieldAttribute("user_" . $fieldname, 'parms'); $fkeyStruct = $ue->getFieldAttribute('user_' . $fieldname, 'parms');
$ret_cause = 0; $ret_cause = 0;
@@ -91,7 +98,7 @@
$ret_cause = 3; $ret_cause = 3;
} }
if((!ADMIN && substr($fkeyStruct, -1) == 1 && strpos($udata['user_hidden_fields'], "^user_" . $fieldname . "^") !== false && $uid != USERID)) if((!ADMIN && substr($fkeyStruct, -1) == 1 && strpos($udata['user_hidden_fields'], '^user_' . $fieldname . '^') !== false && $uid != USERID))
{ {
$ret_cause = 4; $ret_cause = 4;
} }
@@ -108,8 +115,8 @@
switch($type) switch($type)
{ {
case "text_value": case 'text_value':
$_value = user_extended_shortcode($fieldname.".value.".$user); $_value = user_extended_shortcode($fieldname. '.value.' .$user);
if($_value) if($_value)
{ {
@@ -122,7 +129,7 @@
break; break;
case "text": case 'text':
if(isset($fieldname)) if(isset($fieldname))
{ {
$ret = $ue->getFieldLabel($fieldname); $ret = $ue->getFieldLabel($fieldname);
@@ -130,7 +137,7 @@
break; break;
case "icon": case 'icon':
if(defined(strtoupper($fieldname).'_ICON')) if(defined(strtoupper($fieldname).'_ICON'))
{ {
$ret = constant(strtoupper($fieldname).'_ICON'); $ret = constant(strtoupper($fieldname).'_ICON');
@@ -146,19 +153,24 @@
break; break;
case "value": case 'value':
$uVal = isset($fieldname) && isset($udata['user_'.$fieldname]) ? str_replace(chr(1), '', $udata['user_'.$fieldname]) : ''; $fullField = 'user_'.$fieldname;
$uVal = isset($fieldname, $udata[$fullField]) ? str_replace(chr(1), '', $udata[$fullField]) : '';
if(!empty($uVal)) if(!empty($uVal))
{ {
$ret = $ue->renderValue($uVal, $fullField);
$ret = $ue->renderValue($uVal, "user_".$fieldname);
if(!empty($ret)) if(!empty($ret))
{ {
$ret = $tp->toHTML($ret, TRUE, 'no_make_clickable', "class:{$udata['user_class']}"); $ret = $tp->toHTML($ret, TRUE, 'no_make_clickable', "class:{$udata['user_class']}");
} }
} }
elseif(!isset($udata[$fullField]))
{
// trigger_error($fullField. ' is not defined: '.print_r($udata, true), E_USER_NOTICE);
}
break; break;
// code to be executed if n is different from all labels; // code to be executed if n is different from all labels;

View File

@@ -209,7 +209,7 @@ class e_ranks
$userData = e107::getSystemUser($userId)->getData(); //get_usXer_data($userId); $userData = e107::getSystemUser($userId)->getData(); //get_usXer_data($userId);
} }
if($userData['user_admin']) if(isset($userData['user_admin']))
{ {
if($userData['user_perms'] == '0') if($userData['user_perms'] == '0')
{ {

View File

@@ -730,7 +730,7 @@ class e107_user_extended
{ {
if(isset($this->fieldAttributes[$field][$att])) if(isset($this->fieldAttributes[$field][$att]))
{ {
return e107::getParser()->toHtml($this->fieldAttributes[$field][$att],false); return html_entity_decode($this->fieldAttributes[$field][$att]);
} }
return false; return false;
@@ -761,7 +761,7 @@ class e107_user_extended
{ {
if(!empty($this->fieldAttributes[$field]['values'])) if(!empty($this->fieldAttributes[$field]['values']))
{ {
return e107::getParser()->toHTML($this->fieldAttributes[$field]['values'], false); return html_entity_decode($this->fieldAttributes[$field]['values']);
} }
return false; return false;
@@ -953,7 +953,8 @@ class e107_user_extended
if(!$this->user_extended_field_exist($name)) if(!$this->user_extended_field_exist($name))
{ {
$sql->insert('user_extended_struct', $extStructInsert); $nid = $sql->insert('user_extended_struct', $extStructInsert);
$this->init(); // rebuild the list.
// $sql->insert('user_extended_struct',"null,'".$tp -> toDB($name, true)."','".$tp -> toDB($text, true)."','".intval($type)."','".$tp -> toDB($parms, true)."','".$tp -> toDB($values, true)."', '".$tp -> toDB($default, true)."', '".intval($read)."', '".intval($write)."', '".intval($required)."', '0', '".intval($applicable)."', '".intval($order)."', '".intval($parent)."'"); // $sql->insert('user_extended_struct',"null,'".$tp -> toDB($name, true)."','".$tp -> toDB($text, true)."','".intval($type)."','".$tp -> toDB($parms, true)."','".$tp -> toDB($values, true)."', '".$tp -> toDB($default, true)."', '".intval($read)."', '".intval($write)."', '".intval($required)."', '0', '".intval($applicable)."', '".intval($order)."', '".intval($parent)."'");
} }
@@ -963,7 +964,7 @@ class e107_user_extended
return true; return true;
} }
echo $sql->getLastErrorText()."\n\n"; trigger_error("Extended User Field ".$name." doesn't exist", E_USER_NOTICE);
return false; return false;
} }
@@ -1128,7 +1129,7 @@ class e107_user_extended
foreach($choices as $choice) foreach($choices as $choice)
{ {
$choice = trim($choice); $choice = trim($choice);
$choice = $tp->toHTML($choice); $choice = html_entity_decode($choice);
if(strpos($choice,"|")!==FALSE) if(strpos($choice,"|")!==FALSE)
{ {
@@ -1573,7 +1574,7 @@ class e107_user_extended
if(!$result = $sql->gen($qry)) if(!$result = $sql->gen($qry))
{ {
$this->lastError = $sql->getLastErrorText(); // $this->lastError = $sql->getLastErrorText();
echo (ADMIN) ? $this->lastError : ''; echo (ADMIN) ? $this->lastError : '';
} }
@@ -1661,16 +1662,21 @@ class e107_user_extended
$tmp = $this->getFieldAttribute($fieldname, 'values'); $tmp = $this->getFieldAttribute($fieldname, 'values');
$choices = explode(',', $tmp); $choices = explode(',', $tmp);
if(empty($choices))
{
trigger_error('User Extended RADIO field is missing configured selection values', E_USER_NOTICE);
return null;
}
foreach($choices as $choice) foreach($choices as $choice)
{ {
$choice = trim($choice); $choice = trim($choice);
$choice = e107::getParser()->toHTML($choice);
if(strpos($choice,"|")!==FALSE) if(strpos($choice,"|") !==false)
{ {
list($val,$label) = explode("|",$choice); list($val,$label) = explode("|",$choice);
} }
elseif(strpos($choice," => ")!==FALSE) // new in v2.x elseif(strpos($choice," => ") !==false) // new in v2.x
{ {
list($val, $label) = explode(" => ",$choice); list($val, $label) = explode(" => ",$choice);
} }
@@ -1698,7 +1704,10 @@ class e107_user_extended
break; break;
case EUF_CHECKBOX: case EUF_CHECKBOX:
if(is_string($value))
{
$value = e107::unserialize($value); $value = e107::unserialize($value);
}
if(!empty($value)) if(!empty($value))
{ {

View File

@@ -20,6 +20,7 @@ class plugin_forum_view_shortcodes extends e_shortcode
public $pref; public $pref;
public $param; public $param;
// $param is sent from nfp menu. // $param is sent from nfp menu.
function __construct() function __construct()
@@ -633,9 +634,9 @@ class plugin_forum_view_shortcodes extends e_shortcode
function sc_visits() function sc_visits()
{ {
if(!empty($this->postInfo['user_name'])) if(!empty($this->postInfo['user_name']) && isset($this->postInfo['user_visits']))
{ {
return LAN_FORUM_2033 . ': ' . varset($this->postInfo['user_visits']) . '<br />'; return LAN_FORUM_2033 . ': ' . ($this->postInfo['user_visits']) . '<br />';
} }
} }
@@ -669,7 +670,7 @@ class plugin_forum_view_shortcodes extends e_shortcode
function sc_editimg() function sc_editimg()
{ {
if(USER && !empty($this->postInfo['post_user']) && $this->postInfo['post_user'] == USERID && $this->thread->threadInfo['thread_active']) if(USER && !empty($this->postInfo['post_user']) && $this->postInfo['post_user'] == USERID && $this->var['thread_active'])
{ {
$qry = array('f' => 'edit', 'id' => $this->postInfo['post_thread'], 'post' => $this->postInfo['post_id']); $qry = array('f' => 'edit', 'id' => $this->postInfo['post_thread'], 'post' => $this->postInfo['post_id']);
$editURL = e107::url('forum', 'post', null, array('query' => $qry)); $editURL = e107::url('forum', 'post', null, array('query' => $qry));
@@ -854,8 +855,8 @@ class plugin_forum_view_shortcodes extends e_shortcode
// $text2 = $this->sc_level('special'); // $text2 = $this->sc_level('special');
// $text .= $this->sc_level('pic'); // $text .= $this->sc_level('pic');
$uid = (int) $this->postInfo['post_user'];
$ue = $tp->parseTemplate("{USER_EXTENDED=location.text_value}", true); $ue = $tp->parseTemplate("{USER_EXTENDED=location.text_value".$uid."}", true);
$username = (empty($this->postInfo['user_name'])) ? LAN_ANONYMOUS : $this->postInfo['user_name']; $username = (empty($this->postInfo['user_name'])) ? LAN_ANONYMOUS : $this->postInfo['user_name'];
$userUrl = empty($this->postInfo['post_user']) ? '#' : e107::getUrl()->create('user/profile/view', array('user_id' => $this->postInfo['post_user'], 'user_name' => $username)); $userUrl = empty($this->postInfo['post_user']) ? '#' : e107::getUrl()->create('user/profile/view', array('user_id' => $this->postInfo['post_user'], 'user_name' => $username));
@@ -939,7 +940,7 @@ class plugin_forum_view_shortcodes extends e_shortcode
} }
// Edit // Edit
if((USER && isset($this->postInfo['post_user']) && $this->postInfo['post_user'] == USERID && $this->thread->threadInfo['thread_active'])) if((USER && isset($this->postInfo['post_user']) && $this->postInfo['post_user'] == USERID && $this->var['thread_active']))
{ {
@@ -954,7 +955,7 @@ class plugin_forum_view_shortcodes extends e_shortcode
{ {
/* only show delete button when post is not the initial post of the topic /* only show delete button when post is not the initial post of the topic
* AND if this post is the last post in the thread */ * AND if this post is the last post in the thread */
if($this->thread->threadInfo['thread_active'] && empty($this->postInfo['thread_start'])) if($this->var['thread_active'] && empty($this->postInfo['thread_start']))
{ {
$text .= "<li class='text-right float-right'><a href='" . e_REQUEST_URI . "' data-forum-action='deletepost' data-confirm='" . LAN_JSCONFIRM . "' data-forum-post='" . $postID . "'>" . LAN_DELETE . " " . $tp->toGlyph('fa-trash') . "</a></li>"; $text .= "<li class='text-right float-right'><a href='" . e_REQUEST_URI . "' data-forum-action='deletepost' data-confirm='" . LAN_JSCONFIRM . "' data-forum-post='" . $postID . "'>" . LAN_DELETE . " " . $tp->toGlyph('fa-trash') . "</a></li>";
} }
@@ -977,7 +978,7 @@ class plugin_forum_view_shortcodes extends e_shortcode
// print_a($this->postInfo); // print_a($this->postInfo);
if((USER && isset($this->postInfo['post_user']) && $this->postInfo['post_user'] != USERID && $this->thread->threadInfo['thread_active'])) if((USER && isset($this->postInfo['post_user']) && $this->postInfo['post_user'] != USERID && $this->var['thread_active']))
{ {
$url = e107::url('forum', 'post') . "?f=edit&amp;id=" . $threadID . "&amp;post=" . $postID; $url = e107::url('forum', 'post') . "?f=edit&amp;id=" . $threadID . "&amp;post=" . $postID;

View File

@@ -14,6 +14,7 @@
private $structTypes; private $structTypes;
private $structLabels; private $structLabels;
private $userValues;
/** @var e107_user_extended */ /** @var e107_user_extended */
protected $ue; protected $ue;
@@ -272,6 +273,11 @@
foreach($this->userValues as $field => $value) foreach($this->userValues as $field => $value)
{ {
if(empty($value))
{
continue;
}
$parm = $field.'.icon.1'; $parm = $field.'.icon.1';
$result = $tp->parseTemplate('{USER_EXTENDED='.$parm.'}', true); // retrieve value for $field of user_id: 1. $result = $tp->parseTemplate('{USER_EXTENDED='.$parm.'}', true); // retrieve value for $field of user_id: 1.
$this->assertStringContainsString($legacyExpectedIcons[$field], $result); $this->assertStringContainsString($legacyExpectedIcons[$field], $result);
@@ -351,9 +357,15 @@
*/ */
public function testGetFieldType() public function testGetFieldType()
{ {
$result = $this->ue->getFieldType('user_radio');
$this->assertEquals(EUF_RADIO,$result); foreach($this->structTypes as $field=>$type)
{
$fieldname = 'user_'.$field;
$result = $this->ue->getFieldType($fieldname);
$this->assertEquals($type, $result);
}
} }
public function testGetFieldValues() public function testGetFieldValues()
@@ -551,12 +563,36 @@
{ {
} }
*/
public function testRenderValue() public function testRenderValue()
{ {
$expectedRenderedValues = array (
'text' => 'Some Text',
'homepage' => 'https://e107.org',
'radio' => 'Male',
'dropdown' => 'drop3',
'dbfield' => 'News',
'textarea' => 'Text area value',
'integer' => '21',
'date' => '2001-01-11',
'language' => 'English',
'list' => 'America/Aruba (-04:00)',
'checkbox' => 'value2, value3',
'predefined' => 'predefined',
'country' => 'United States',
'richtextarea' => '<b>Rich text</b>',
);
foreach($this->userValues as $field => $v)
{
$name = 'user_'.$field;
$result = $this->ue->renderValue($v, $name);
$this->assertEquals($expectedRenderedValues[$field], $result);
}
} }
*/
public function testGetFieldNames() public function testGetFieldNames()
{ {
$expected = array ( $expected = array (

View File

@@ -1032,20 +1032,27 @@ class e_parse_shortcodeTest extends \Codeception\Test\Unit
'post_forum' => '4', 'post_forum' => '4',
'post_status' => '0', 'post_status' => '0',
'post_datestamp' => '1367307189', 'post_datestamp' => '1367307189',
'post_user' => '2', 'post_user' => 1,
'post_edit_datestamp' => NULL, 'post_edit_datestamp' => NULL,
'post_edit_user' => NULL, 'post_edit_user' => NULL,
'post_ip' => NULL, 'post_ip' => NULL,
'post_user_anon' => NULL, 'post_user_anon' => NULL,
'post_attachments' => NULL, 'post_attachments' => NULL,
'post_options' => NULL 'post_options' => NULL,
'user_join' => time(),
'user_id' => 1,
'user_name' => USERNAME,
'user_hideemail' => 1,
'user_plugin_forum_posts' => 3,
'user_visits' => 6,
'user_admin' => 1,
'user_join' => time() - 8000,
); );
$sc->__construct(); $sc->__construct();
$sc->setVars($vars); $sc->setVars($vars);
$sc->setScVar('postInfo', $vars);
$this->processShortcodeMethods($sc); $this->processShortcodeMethods($sc);