mirror of
https://github.com/e107inc/e107.git
synced 2025-07-31 20:00:37 +02:00
Forum and User-extended shortcode improvements and test tweaks.
This commit is contained in:
@@ -20,17 +20,24 @@
|
||||
|
||||
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);
|
||||
$fieldname = $tmp[0];
|
||||
$type = $tmp[1];
|
||||
|
||||
$fieldname = trim($tmp[0]);
|
||||
$type = trim($tmp[1]);
|
||||
$user = varset($tmp[2], 0);
|
||||
|
||||
if(isset($loop_uid) && intval($loop_uid) == 0)
|
||||
if(isset($loop_uid) && $loop_uid === 0)
|
||||
{
|
||||
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']['post'] = (isset($sc_style['USER_EXTENDED'][$key]['post']) ? $sc_style['USER_EXTENDED'][$key]['post'] : '');
|
||||
@@ -39,7 +46,7 @@
|
||||
|
||||
if($uid === 0)
|
||||
{
|
||||
if(isset($loop_uid) && intval($loop_uid) > 0)
|
||||
if(isset($loop_uid) && $loop_uid > 0)
|
||||
{
|
||||
$uid = $loop_uid;
|
||||
}
|
||||
@@ -52,7 +59,7 @@
|
||||
$udata = e107::user($uid);
|
||||
|
||||
$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']))
|
||||
{
|
||||
@@ -70,9 +77,9 @@
|
||||
|
||||
if(($type !== 'icon') && ($ue->getCategoryAttribute($fieldname, 'read') === false))
|
||||
{
|
||||
$fkeyApplic = $ue->getFieldAttribute("user_" . $fieldname, 'applicable');
|
||||
$fkeyRead = $ue->getFieldAttribute("user_" . $fieldname, 'read');
|
||||
$fkeyStruct = $ue->getFieldAttribute("user_" . $fieldname, 'parms');
|
||||
$fkeyApplic = $ue->getFieldAttribute('user_' . $fieldname, 'applicable');
|
||||
$fkeyRead = $ue->getFieldAttribute('user_' . $fieldname, 'read');
|
||||
$fkeyStruct = $ue->getFieldAttribute('user_' . $fieldname, 'parms');
|
||||
|
||||
$ret_cause = 0;
|
||||
|
||||
@@ -91,7 +98,7 @@
|
||||
$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;
|
||||
}
|
||||
@@ -108,8 +115,8 @@
|
||||
|
||||
switch($type)
|
||||
{
|
||||
case "text_value":
|
||||
$_value = user_extended_shortcode($fieldname.".value.".$user);
|
||||
case 'text_value':
|
||||
$_value = user_extended_shortcode($fieldname. '.value.' .$user);
|
||||
|
||||
if($_value)
|
||||
{
|
||||
@@ -122,7 +129,7 @@
|
||||
|
||||
break;
|
||||
|
||||
case "text":
|
||||
case 'text':
|
||||
if(isset($fieldname))
|
||||
{
|
||||
$ret = $ue->getFieldLabel($fieldname);
|
||||
@@ -130,7 +137,7 @@
|
||||
break;
|
||||
|
||||
|
||||
case "icon":
|
||||
case 'icon':
|
||||
if(defined(strtoupper($fieldname).'_ICON'))
|
||||
{
|
||||
$ret = constant(strtoupper($fieldname).'_ICON');
|
||||
@@ -146,19 +153,24 @@
|
||||
break;
|
||||
|
||||
|
||||
case "value":
|
||||
$uVal = isset($fieldname) && isset($udata['user_'.$fieldname]) ? str_replace(chr(1), '', $udata['user_'.$fieldname]) : '';
|
||||
case 'value':
|
||||
$fullField = 'user_'.$fieldname;
|
||||
$uVal = isset($fieldname, $udata[$fullField]) ? str_replace(chr(1), '', $udata[$fullField]) : '';
|
||||
|
||||
if(!empty($uVal))
|
||||
{
|
||||
|
||||
$ret = $ue->renderValue($uVal, "user_".$fieldname);
|
||||
$ret = $ue->renderValue($uVal, $fullField);
|
||||
|
||||
if(!empty($ret))
|
||||
{
|
||||
$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;
|
||||
|
||||
// code to be executed if n is different from all labels;
|
||||
|
@@ -209,7 +209,7 @@ class e_ranks
|
||||
$userData = e107::getSystemUser($userId)->getData(); //get_usXer_data($userId);
|
||||
}
|
||||
|
||||
if($userData['user_admin'])
|
||||
if(isset($userData['user_admin']))
|
||||
{
|
||||
if($userData['user_perms'] == '0')
|
||||
{
|
||||
|
@@ -730,7 +730,7 @@ class e107_user_extended
|
||||
{
|
||||
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;
|
||||
@@ -761,7 +761,7 @@ class e107_user_extended
|
||||
{
|
||||
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;
|
||||
@@ -953,7 +953,8 @@ class e107_user_extended
|
||||
|
||||
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)."'");
|
||||
}
|
||||
@@ -963,7 +964,7 @@ class e107_user_extended
|
||||
return true;
|
||||
}
|
||||
|
||||
echo $sql->getLastErrorText()."\n\n";
|
||||
trigger_error("Extended User Field ".$name." doesn't exist", E_USER_NOTICE);
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -1128,7 +1129,7 @@ class e107_user_extended
|
||||
foreach($choices as $choice)
|
||||
{
|
||||
$choice = trim($choice);
|
||||
$choice = $tp->toHTML($choice);
|
||||
$choice = html_entity_decode($choice);
|
||||
|
||||
if(strpos($choice,"|")!==FALSE)
|
||||
{
|
||||
@@ -1573,7 +1574,7 @@ class e107_user_extended
|
||||
|
||||
if(!$result = $sql->gen($qry))
|
||||
{
|
||||
$this->lastError = $sql->getLastErrorText();
|
||||
// $this->lastError = $sql->getLastErrorText();
|
||||
echo (ADMIN) ? $this->lastError : '';
|
||||
}
|
||||
|
||||
@@ -1661,18 +1662,23 @@ class e107_user_extended
|
||||
$tmp = $this->getFieldAttribute($fieldname, 'values');
|
||||
$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)
|
||||
{
|
||||
$choice = trim($choice);
|
||||
$choice = e107::getParser()->toHTML($choice);
|
||||
|
||||
if(strpos($choice,"|")!==FALSE)
|
||||
if(strpos($choice,"|") !==false)
|
||||
{
|
||||
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);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1698,7 +1704,10 @@ class e107_user_extended
|
||||
break;
|
||||
|
||||
case EUF_CHECKBOX:
|
||||
if(is_string($value))
|
||||
{
|
||||
$value = e107::unserialize($value);
|
||||
}
|
||||
|
||||
if(!empty($value))
|
||||
{
|
||||
|
@@ -20,6 +20,7 @@ class plugin_forum_view_shortcodes extends e_shortcode
|
||||
public $pref;
|
||||
public $param;
|
||||
|
||||
|
||||
// $param is sent from nfp menu.
|
||||
|
||||
function __construct()
|
||||
@@ -633,9 +634,9 @@ class plugin_forum_view_shortcodes extends e_shortcode
|
||||
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()
|
||||
{
|
||||
|
||||
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']);
|
||||
$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');
|
||||
// $text .= $this->sc_level('pic');
|
||||
|
||||
$ue = $tp->parseTemplate("{USER_EXTENDED=location.text_value}", true);
|
||||
$uid = (int) $this->postInfo['post_user'];
|
||||
$ue = $tp->parseTemplate("{USER_EXTENDED=location.text_value".$uid."}", true);
|
||||
$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));
|
||||
@@ -939,7 +940,7 @@ class plugin_forum_view_shortcodes extends e_shortcode
|
||||
}
|
||||
|
||||
// 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
|
||||
* 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>";
|
||||
}
|
||||
@@ -977,7 +978,7 @@ class plugin_forum_view_shortcodes extends e_shortcode
|
||||
|
||||
// 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&id=" . $threadID . "&post=" . $postID;
|
||||
|
@@ -14,6 +14,7 @@
|
||||
|
||||
private $structTypes;
|
||||
private $structLabels;
|
||||
private $userValues;
|
||||
|
||||
/** @var e107_user_extended */
|
||||
protected $ue;
|
||||
@@ -272,6 +273,11 @@
|
||||
|
||||
foreach($this->userValues as $field => $value)
|
||||
{
|
||||
if(empty($value))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$parm = $field.'.icon.1';
|
||||
$result = $tp->parseTemplate('{USER_EXTENDED='.$parm.'}', true); // retrieve value for $field of user_id: 1.
|
||||
$this->assertStringContainsString($legacyExpectedIcons[$field], $result);
|
||||
@@ -351,9 +357,15 @@
|
||||
*/
|
||||
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()
|
||||
@@ -551,12 +563,36 @@
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
*/
|
||||
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()
|
||||
{
|
||||
$expected = array (
|
||||
|
@@ -1032,20 +1032,27 @@ class e_parse_shortcodeTest extends \Codeception\Test\Unit
|
||||
'post_forum' => '4',
|
||||
'post_status' => '0',
|
||||
'post_datestamp' => '1367307189',
|
||||
'post_user' => '2',
|
||||
'post_user' => 1,
|
||||
'post_edit_datestamp' => NULL,
|
||||
'post_edit_user' => NULL,
|
||||
'post_ip' => NULL,
|
||||
'post_user_anon' => 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->setVars($vars);
|
||||
$sc->setScVar('postInfo', $vars);
|
||||
|
||||
$this->processShortcodeMethods($sc);
|
||||
|
||||
|
Reference in New Issue
Block a user