1
0
mirror of https://github.com/e107inc/e107.git synced 2025-07-28 18:30:53 +02:00

Forum code cleanup

This commit is contained in:
Cameron
2016-06-22 15:59:18 -07:00
parent 92d67a886e
commit 581a9511fb
2 changed files with 119 additions and 70 deletions

View File

@@ -223,7 +223,7 @@ class forum_shortcodes extends e_shortcode
// $gen = new convert; // $gen = new convert;
$text = LAN_FORUM_0018." ".USERNAME."<br />"; $text = LAN_FORUM_0018." ".USERNAME."<br />";
$lastvisit_datestamp = $this->gen->convert_date(USERLV, 'long'); $lastvisit_datestamp = $this->gen->convert_date(USERLV, 'long'); //FIXME Use e107::getParser()->toDate();
$datestamp = $this->gen->convert_date(time(), "long"); $datestamp = $this->gen->convert_date(time(), "long");
/* /*
@@ -288,6 +288,8 @@ class forum_shortcodes extends e_shortcode
return $text; return $text;
} }
function sc_foruminfo() function sc_foruminfo()
{ {
$sql = e107::getDb(); $sql = e107::getDb();
@@ -322,17 +324,20 @@ class forum_shortcodes extends e_shortcode
return vartrue($status); return vartrue($status);
} }
function sc_parentname() function sc_parentname()
{ {
return $this->var['forum_name']; return $this->var['forum_name'];
} }
// Function to show the retrieval of parent ID, not really needed by core template // Function to show the retrieval of parent ID, not really needed by core template
function sc_parentid() function sc_parentid()
{ {
return $this->var['forum_id']; return $this->var['forum_id'];
} }
// START OF parse_forum function $FVARS // START OF parse_forum function $FVARS
function sc_newflag() function sc_newflag()
@@ -354,6 +359,7 @@ class forum_shortcodes extends e_shortcode
} }
function sc_forumname() function sc_forumname()
{ {
// global $f; // global $f;
@@ -369,6 +375,7 @@ class forum_shortcodes extends e_shortcode
} }
function sc_forumdescription() function sc_forumdescription()
{ {
// global $f, $restricted_string; // global $f, $restricted_string;
@@ -378,16 +385,19 @@ class forum_shortcodes extends e_shortcode
return $this->var['forum_description'].($restricted_string ? "<br /><span class='smalltext'><i>$restricted_string</i></span>" : ""); return $this->var['forum_description'].($restricted_string ? "<br /><span class='smalltext'><i>$restricted_string</i></span>" : "");
} }
function sc_threads() function sc_threads()
{ {
return $this->var['forum_threads']; return $this->var['forum_threads'];
} }
function sc_replies() function sc_replies()
{ {
return $this->var['forum_replies']; return $this->var['forum_replies'];
} }
function sc_threadsx() function sc_threadsx()
{ {
// global $f; // global $f;
@@ -395,6 +405,7 @@ class forum_shortcodes extends e_shortcode
return "<span class='badge ".(($this->var['forum_threads']) ? "badge-info" : "")."'>".$this->var['forum_threads']."</span>"; return "<span class='badge ".(($this->var['forum_threads']) ? "badge-info" : "")."'>".$this->var['forum_threads']."</span>";
} }
function sc_repliesx() function sc_repliesx()
{ {
// global $f; // global $f;
@@ -402,11 +413,10 @@ class forum_shortcodes extends e_shortcode
return "<span class='badge ".(($this->var['forum_replies']) ? "badge-info" : "")."'>".$this->var['forum_replies']."</span>"; return "<span class='badge ".(($this->var['forum_replies']) ? "badge-info" : "")."'>".$this->var['forum_replies']."</span>";
} }
function sc_forumsubforums() function sc_forumsubforums()
{ {
// VAR_DUMP ($this->ret); return (!empty($this->var['text'])) ? "<br /><div class='smalltext'>".LAN_FORUM_0069.": {$this->var['text']}</div>":"";
// return ($this->ret)?"<br /><div class='smalltext'>".LAN_FORUM_0069.": {$this->ret['text']}</div>":"";
return ($this->var['text'])?"<br /><div class='smalltext'>".LAN_FORUM_0069.": {$this->var['text']}</div>":"";
} }
//----- ######################################################## //----- ########################################################
@@ -548,38 +558,65 @@ $gen = new convert;
} }
-----*/ -----*/
function lastpostdata () function lastpostdata($mode='')
{ {
$caller = debug_backtrace()[1]['function'];
if ($this->var['forum_lastpost_info']) if (empty($this->var['forum_lastpost_info']))
{ {
$e107 = e107::getInstance(); return false;
// $gen = new convert; }
global $forum; global $forum;
list($lastpost_datestamp, $lastpost_thread) = explode('.', $this->var['forum_lastpost_info']); list($lastpost_datestamp, $lastpost_thread) = explode('.', $this->var['forum_lastpost_info']);
/*--
if ($this->var['user_name'])
{
$lastpost_name = "<a href='".$e107->url->create('user/profile/view', array('name' => $this->var['user_name'], 'id' => $this->var['forum_lastpost_user']))."'>{$this->var['user_name']}</a>"; // e107::getDebug()->log($this->var);
$lastpost = $forum->threadGetLastpost($lastpost_thread); //FIXME TODO inefficient to have SQL query here.
$urlData = array('forum_sef'=>$this->var['forum_sef'], 'thread_id'=>$lastpost['post_thread'],'thread_sef'=>$lastpost['thread_sef']);
$url = e107::url('forum', 'topic', $urlData)."?last=1#post-".$lastpost['post_id'];
if (!empty($this->var['user_name']))
{
$lastpost_name = "<a href='".e107::url('user/profile/view', array('name' => $this->var['user_name'], 'id' => $this->var['forum_lastpost_user']))."'>{$this->var['user_name']}</a>";
} }
else else
{ {
$lastpost_name = e107::getParser()->toHTML($this->var['forum_lastpost_user_anon']); $lastpost_name = e107::getParser()->toHTML($this->var['forum_lastpost_user_anon']);
} }
--*/
$lastpost_name = ($this->var['user_name'])?"<a href='".$e107->url->create('user/profile/view', array('name' => $this->var['user_name'], 'id' => $this->var['forum_lastpost_user']))."'>{$this->var['user_name']}</a>":e107::getParser()->toHTML($this->var['forum_lastpost_user_anon']);
$lastpost = $forum->threadGetLastpost($lastpost_thread); //XXX TODO inefficient to have SQL query here. $relativeDate = e107::getParser()->toDate($lastpost_datestamp,'relative');
switch($mode)
{
// $fVars->LASTPOSTUSER = $lastpost_name; // $fVars->LASTPOSTUSER = $lastpost_name;
// {forum_sef}/{thread_id}-{thread_sef} case "user":
return $lastpost_name;
break;
$urlData = array('forum_sef'=>$this->var['forum_sef'], 'thread_id'=>$lastpost['post_thread'],'thread_sef'=>$lastpost['thread_sef']);
$url = e107::url('forum', 'topic', $urlData)."?last=1#post-".$lastpost['post_id'];
// $fVars->LASTPOSTDATE .= "<a href='".$url."'>". $gen->computeLapse($lastpost_datestamp, time(), false, false, 'short')."</a>"; // $fVars->LASTPOSTDATE .= "<a href='".$url."'>". $gen->computeLapse($lastpost_datestamp, time(), false, false, 'short')."</a>";
$lastpost_datestamp = $this->gen->convert_date($lastpost_datestamp, 'forum'); case "date":
return "<a href='".$url."'>". $relativeDate."</a>";
break;
// $fVars->LASTPOST = $lastpost_datestamp.'<br />'.$lastpost_name." <a href='".$e107->url->create('forum/thread/last', array('name' => $lastpost_name, 'id' => $lastpost_thread))."'>".IMAGE_post2.'</a>';
case 'post':
return $relativeDate.'<br />'.$lastpost_name." <a href='".$url."'>".IMAGE_post2.'</a>';
// code to be executed if n is different from all labels;
}
return false;
// return $lastpost_datestamp;
/*--
--*/
// $fVars->LASTPOST = $lastpost_datestamp.'<br />'.$lastpost_name." <a href='".$e107->url->create('forum/thread/last', array('name' => $lastpost_name, 'id' => $lastpost_thread))."'>".IMAGE_post2.'</a>'; // $fVars->LASTPOST = $lastpost_datestamp.'<br />'.$lastpost_name." <a href='".$e107->url->create('forum/thread/last', array('name' => $lastpost_name, 'id' => $lastpost_thread))."'>".IMAGE_post2.'</a>';
/*---- /*----
@@ -588,8 +625,10 @@ $gen = new convert;
$fVars->LASTPOST = $lastpost_datestamp.'<br />'.$lastpost_name." <a href='".$e107->url->create('forum/thread/last', array('name' => $lastpost_name, 'id' => $lastpost_thread))."'>".IMAGE_post2.'</a>'; $fVars->LASTPOST = $lastpost_datestamp.'<br />'.$lastpost_name." <a href='".$e107->url->create('forum/thread/last', array('name' => $lastpost_name, 'id' => $lastpost_thread))."'>".IMAGE_post2.'</a>';
-----*/ -----*/
return ($caller == 'sc_lastpostuser'?$lastpost_name:($caller == 'sc_lastpostdate'?"<a href='".$url."'>". $this->gen->computeLapse($lastpost_datestamp, time(), false, false, 'short')."</a>":($caller == 'sc_lastpost'?$lastpost_datestamp.'<br />'.$lastpost_name." <a href='".$e107->url->create('forum/thread/last', array('name' => $lastpost_name, 'id' => $lastpost_thread))."'>".IMAGE_post2.'</a>':'')));
}
/*---- /*----
else else
{ {
@@ -598,29 +637,30 @@ $gen = new convert;
$fVars->LASTPOST = '-'; $fVars->LASTPOST = '-';
} }
----*/ ----*/
return ($caller == 'sc_lastpostuser'?'':'-');
// echo debug_backtrace()[1]['function'];
} }
function sc_lastpostuser() function sc_lastpostuser()
{ {
return $this->lastpostdata(); return $this->lastpostdata('user');
} }
function sc_lastpostdate() function sc_lastpostdate()
{ {
return $this->lastpostdata(); return $this->lastpostdata('date');
} }
function sc_lastpost() function sc_lastpost()
{ {
return $this->lastpostdata(); return $this->lastpostdata('post');
} }
function sc_startertitle() function sc_startertitle()
{ {
// global $thread;
// $gen = new convert;
$author_name = ($this->var['user_name'] ? $this->var['user_name'] : $this->var['lastuser_anon']); $author_name = ($this->var['user_name'] ? $this->var['user_name'] : $this->var['lastuser_anon']);
@@ -632,14 +672,13 @@ $gen = new convert;
{ {
return $author_name.'<br />'.$datestamp; return $author_name.'<br />'.$datestamp;
} }
//---- else
//---- {
// $e107 = e107::getInstance();
// return "<a href='".$e107->url->create('user/profile/view', array('id' => $thread['thread_lastuser'], 'name' => $sc->author_name))."'>{$sc->author_name}</a><br />".$sc->datestamp; // return "<a href='".$e107->url->create('user/profile/view', array('id' => $thread['thread_lastuser'], 'name' => $sc->author_name))."'>{$sc->author_name}</a><br />".$sc->datestamp;
return "<a href='".e107::getUrl()->create('user/profile/view', array('id' => $this->var['thread_lastuser'], 'name' => $author_name))."'>{$author_name}</a><br />".$datestamp; return "<a href='".e107::getUrl()->create('user/profile/view', array('id' => $this->var['thread_lastuser'], 'name' => $author_name))."'>{$author_name}</a><br />".$datestamp;
//---- } //---- }
} }
function sc_newspostname() function sc_newspostname()
{ {
// global $thread; // global $thread;
@@ -650,7 +689,7 @@ $gen = new convert;
// Only $this->var???' // Only $this->var???'
return empty($this->var) ? LAN_FORUM_0029:"<a href='".e107::getUrl()->create('forum/thread/last', $this->var)."'>".e107::getParser()->toHTML($this->var['thread_name'], TRUE, 'no_make_clickable, no_hook').'</a>'; return empty($this->var) ? LAN_FORUM_0029:"<a href='".e107::getUrl()->create('forum/thread/last', $this->var)."'>".e107::getParser()->toHTML($this->var['thread_name'], TRUE, 'no_make_clickable, no_hook').'</a>';
} }
// END OF $NVARS
function sc_forum_breadcrumb() function sc_forum_breadcrumb()

View File

@@ -24,6 +24,16 @@ class plugin_forum_view_shortcodes extends e_shortcode
$this->defaultImgAttachSize = e107::pref('forum','maxwidth',false); // don't resize here if set to 0. $this->defaultImgAttachSize = e107::pref('forum','maxwidth',false); // don't resize here if set to 0.
} }
function sc_breadcrumb()
{
return $this->var['breadcrumb'];
}
function sc_backlink()
{
return $this->var['breadcrumb'];
}
function sc_top($parm='') function sc_top($parm='')
{ {
$text = ($parm == 'caret') ? "<span class='caret'></span>" : LAN_FORUM_2030; $text = ($parm == 'caret') ? "<span class='caret'></span>" : LAN_FORUM_2030;