mirror of
https://github.com/e107inc/e107.git
synced 2025-01-17 12:48:24 +01:00
New feature: Previous/Next News item navigation.
This commit is contained in:
parent
180b6d8432
commit
58f129799b
@ -192,20 +192,7 @@ class news_shortcodes extends e_shortcode
|
||||
*/
|
||||
function sc_newsnavlink($parm=null) //TODO add more options.
|
||||
{
|
||||
$url = e107::getUrl()->create('news/list/items'); // default for now.
|
||||
|
||||
if(varset($parm['list']) == 'all') // A list of all items - usually headings and thumbnails
|
||||
{
|
||||
$url = e107::getUrl()->create('news/list/all');
|
||||
}
|
||||
elseif(varset($parm['list']) == 'category')
|
||||
{
|
||||
$url = e107::getUrl()->create('news/list/short', $this->news_item); //default for now.
|
||||
}
|
||||
elseif(varset($parm['items']) == 'category')
|
||||
{
|
||||
$url = e107::getUrl()->create('news/list/category', $this->news_item);
|
||||
}
|
||||
$url = $this->sc_news_nav_url($parm);
|
||||
|
||||
$caption = vartrue($parm['text'], LAN_BACK);
|
||||
|
||||
@ -223,6 +210,27 @@ class news_shortcodes extends e_shortcode
|
||||
|
||||
|
||||
|
||||
public function sc_news_nav_url($parm)
|
||||
{
|
||||
$url = e107::getUrl()->create('news/list/items'); // default for now.
|
||||
|
||||
if(varset($parm['list']) == 'all') // A list of all items - usually headings and thumbnails
|
||||
{
|
||||
$url = e107::getUrl()->create('news/list/all');
|
||||
}
|
||||
elseif(varset($parm['list']) == 'category')
|
||||
{
|
||||
$url = e107::getUrl()->create('news/list/short', $this->news_item); //default for now.
|
||||
}
|
||||
elseif(varset($parm['items']) == 'category')
|
||||
{
|
||||
$url = e107::getUrl()->create('news/list/category', $this->news_item);
|
||||
}
|
||||
|
||||
return $url;
|
||||
|
||||
}
|
||||
|
||||
|
||||
function sc_newsheader($parm=null)
|
||||
{
|
||||
@ -1186,5 +1194,82 @@ class news_shortcodes extends e_shortcode
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @example {NEWS_NAV_NEXT}
|
||||
* @return string|null
|
||||
*/
|
||||
function sc_news_nav_next()
|
||||
{
|
||||
return $this->parseNavTemplate('next');
|
||||
}
|
||||
|
||||
/**
|
||||
* {NEWS_NAV_PREVIOUS}
|
||||
* @return string|null
|
||||
*/
|
||||
function sc_news_nav_previous()
|
||||
{
|
||||
return $this->parseNavTemplate('previous');
|
||||
}
|
||||
|
||||
/**
|
||||
* {NEWS_NAV_PREVIOUS}
|
||||
* @return string|null
|
||||
*/
|
||||
function sc_news_nav_current()
|
||||
{
|
||||
$template = e107::getTemplate('news', 'news_view', 'nav');
|
||||
return e107::getParser()->parseTemplate($template['current'], true, $this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the data from the previous/next news record and renders the corresponding template.
|
||||
* @param string $type next|previous
|
||||
* @return string|null
|
||||
*/
|
||||
private function parseNavTemplate($type)
|
||||
{
|
||||
if(!$data = $this->getNavQuery($type))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
$template = e107::getTemplate('news', 'news_view', 'nav');
|
||||
$orig = $this->getScVar('news_item');
|
||||
$this->setScVar('news_item', $data);
|
||||
$text = e107::getParser()->parseTemplate($template[$type], true, $this);
|
||||
$this->setScVar('news_item', $orig);
|
||||
|
||||
return $text;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve table data from the previous or next news item.
|
||||
* @param string $type next/previous
|
||||
* @return array|string
|
||||
*/
|
||||
private function getNavQuery($type)
|
||||
{
|
||||
$nobody_regexp = "'(^|,)(".str_replace(",", "|", e_UC_NOBODY).")(,|$)'";
|
||||
|
||||
$var = $this->getScVar('news_item');
|
||||
|
||||
$dir = ($type === 'next') ? '>=' : '<=';
|
||||
$sort = ($type === 'next') ? 'ASC' : 'DESC';
|
||||
|
||||
$query = "
|
||||
SELECT SQL_CALC_FOUND_ROWS n.*, u.user_id, u.user_name, u.user_customtitle, u.user_image, nc.category_id, nc.category_name, nc.category_sef, nc.category_icon,
|
||||
nc.category_meta_keywords, nc.category_meta_description, nc.category_template
|
||||
FROM #news AS n
|
||||
LEFT JOIN #user AS u ON n.news_author = u.user_id
|
||||
LEFT JOIN #news_category AS nc ON n.news_category = nc.category_id
|
||||
WHERE n.news_class REGEXP '".e_CLASS_REGEXP."' AND NOT (n.news_class REGEXP ".$nobody_regexp.")
|
||||
AND n.news_start < ".time()." AND (n.news_end=0 || n.news_end>".time().")
|
||||
AND (FIND_IN_SET('0', n.news_render_type) OR FIND_IN_SET(1, n.news_render_type))
|
||||
AND n.news_datestamp ".$dir . (int) $var['news_datestamp']. " AND n.news_id != ".(int) $var['news_id']." ORDER by n.news_datestamp ".$sort." LIMIT 1";
|
||||
|
||||
return e107::getDb()->retrieve($query);
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
||||
|
||||
|
@ -14,13 +14,13 @@
|
||||
$NEWS_VIEW_INFO = array(
|
||||
|
||||
'default' => array('title' => LAN_DEFAULT, 'description' => 'unused'),
|
||||
'videos' => array('title' => "Videos (experimental)", 'description' => 'unused'),
|
||||
'videos' => array('title' => "Videos (experimental)", 'description' => 'unused'),
|
||||
);
|
||||
|
||||
|
||||
// Default
|
||||
$NEWS_VIEW_WRAPPER['default']['item']['NEWSIMAGE: item=1'] = '<span class="news-images-main pull-left float-left col-xs-12 col-sm-6 col-md-6">{---}</span>';
|
||||
|
||||
$NEWS_VIEW_WRAPPER['default']['item']['NEWSRELATED'] = '<hr />{---}<hr />';
|
||||
|
||||
$NEWS_VIEW_TEMPLATE['default']['caption'] = '{NEWS_TITLE}'; // null; // add a value to user tablerender()
|
||||
$NEWS_VIEW_TEMPLATE['default']['item'] = '
|
||||
@ -77,10 +77,13 @@ $NEWS_VIEW_TEMPLATE['default']['item'] = '
|
||||
|
||||
</div>
|
||||
|
||||
<hr />
|
||||
{NEWSRELATED}
|
||||
<hr>
|
||||
{NEWSNAVLINK}
|
||||
|
||||
<ul class="pagination justify-content-between my-5 news-view-pagination">
|
||||
<li class="page-item col-md-4">{NEWS_NAV_PREVIOUS}</li>
|
||||
<li class="page-item col-md-4 text-center">{NEWS_NAV_CURRENT}</li>
|
||||
<li class="page-item col-md-4 text-right text-end">{NEWS_NAV_NEXT}</li>
|
||||
</ul>
|
||||
|
||||
';
|
||||
|
||||
@ -103,7 +106,10 @@ $NEWS_VIEW_TEMPLATE['default']['item'] = '
|
||||
|
||||
|
||||
// Videos
|
||||
$NEWS_VIEW_TEMPLATE['videos']['item'] = '<div class="view-item"><div class="alert alert-warning">Empty news_view_template.php (videos) - have ideas? let us know.</div></div>';
|
||||
|
||||
$NEWS_VIEW_TEMPLATE['videos']['item'] = '<div class="view-item"><div class="alert alert-warning">Empty news_view_template.php (videos) - have ideas? let us know.</div></div>';
|
||||
|
||||
|
||||
// Navigation/Pagination
|
||||
$NEWS_VIEW_TEMPLATE['nav']['previous'] = '<a href="{NEWS_URL}">{GLYPH=fa-chevron-left}<span class="mx-1">{NEWS_TITLE} {NEWS_ID}</span></a>';
|
||||
$NEWS_VIEW_TEMPLATE['nav']['current'] = '<a class="text-center" href="{NEWS_NAV_URL}">{LAN=BACK}</span></a>';
|
||||
$NEWS_VIEW_TEMPLATE['nav']['next'] = '<a class="text-right" href="{NEWS_URL}"><span class="mx-1">{NEWS_ID} {NEWS_TITLE}</span>{GLYPH=fa-chevron-right}</a> ';
|
||||
|
Loading…
x
Reference in New Issue
Block a user