From a1e7d29661cfd5577b29c62e431b70b8ac096de9 Mon Sep 17 00:00:00 2001 From: Cameron Date: Mon, 14 Jun 2021 14:42:17 -0700 Subject: [PATCH] Optional {NEWS_PAGINATION} shortcode added. --- .../shortcodes/batch/news_shortcodes.php | 11 ++++ e107_plugins/news/news.php | 63 ++++++++++++------- 2 files changed, 53 insertions(+), 21 deletions(-) diff --git a/e107_core/shortcodes/batch/news_shortcodes.php b/e107_core/shortcodes/batch/news_shortcodes.php index e12f74fd4..48e1a8b18 100644 --- a/e107_core/shortcodes/batch/news_shortcodes.php +++ b/e107_core/shortcodes/batch/news_shortcodes.php @@ -1202,6 +1202,17 @@ class news_shortcodes extends e_shortcode } + /** New in v2.3 {NEWS_PAGINATION} */ + function sc_news_pagination($parm=null) + { + $params = e107::getRegistry('core/news/pagination'); + + return e107::getParser()->parseTemplate("{NEXTPREV=".$params."}"); + + } + + + /** * @example {NEWS_NAV_NEXT} * @return string|null diff --git a/e107_plugins/news/news.php b/e107_plugins/news/news.php index d1a23ed3c..3f1d385ad 100644 --- a/e107_plugins/news/news.php +++ b/e107_plugins/news/news.php @@ -1073,10 +1073,7 @@ class news_front $text .= "
".(strpos(e_QUERY, "month") !== false ? LAN_NEWS_462 : LAN_NEWS_83)."
"; } - if(!empty($template['end'])) - { - $text .= $tp->parseTemplate($template['end'], true); - } + $icon = ($row['category_icon']) ? "" : ""; @@ -1089,7 +1086,23 @@ class news_front $this->addDebug('newsUrlParms',$this->newsUrlparms); - $text .= $tp->parseTemplate("{NEXTPREV={$parms}}"); + $paginationSC = false; + if(!empty($template['end'])) + { + e107::setRegistry('core/news/pagination', $parms); + $text .= $tp->parseTemplate($template['end'], true); + if(strpos($template['end'], '{NEWS_PAGINATION') !== false) + { + $paginationSC = true; + $this->addDebug("Pagination Shortcode", 'true'); + } + } + + if($paginationSC === false) // BC Fix + { + $text .= $tp->parseTemplate("{NEXTPREV={$parms}}"); + $this->addDebug("Pagination Shortcode", 'false'); + } if(isset($template['caption'])) // v2.x @@ -1105,7 +1118,7 @@ class news_front $NEWSLISTTITLE = str_replace("{NEWSCATEGORY}",$tp->toHTML($category_name,FALSE,'TITLE'),$NEWSLISTTITLE); } - if($this->defaultTemplate != 'list') + if($this->defaultTemplate != 'list' && ($paginationSC === false)) { $text .= ""; } @@ -1682,10 +1695,7 @@ class news_front $parms = 'tmpl_prefix='.deftrue('NEWS_NEXTPREV_TMPL', 'default').'&total='.$news_total.'&amount='.$amount.'¤t='.$this->from.$nitems.'&url='.$url; $text .= $tp->parseTemplate("{NEXTPREV={$parms}}"); - - // $nextprev = $tp->parseTemplate("{NEXTPREV={$parms}}"); - // $text .= ($nextprev ? "
".$nextprev."
" : ""); - // $text=''.$text.'
'.$nextprev.'
'; + // This section is deprecated so no pagination shortcode support should be added. // echo $text; $this->setNewsCache($this->cacheString, $text); @@ -1869,28 +1879,39 @@ class news_front $i++; } - if(!empty($tmpl['end'])) - { - $nsc = e107::getScBatch('news')->setScVar('news_item', $newsAr[1])->setScVar('param', $param); - echo $tp->parseTemplate($tmpl['end'], true, $nsc); - } - $amount = ITEMVIEW; $nitems = defined('NEWS_NEXTPREV_NAVCOUNT') ? '&navcount='.NEWS_NEXTPREV_NAVCOUNT : '' ; $url = rawurlencode(e107::getUrl()->create($this->route, $this->newsUrlparms)); - + + $this->addDebug('News Pagination Parms', $this->newsUrlparms); + // Example of passing route data instead building the URL outside the shortcode - for a reference only // $url = rawurlencode('url::'.$newsRoute.'::'.http_build_query($newsUrlparms, null, '&')); + $parms = 'tmpl_prefix='.deftrue('NEWS_NEXTPREV_TMPL', 'default').'&total='.$news_total.'&amount='.$amount.'¤t='.$this->from.$nitems.'&url='.$url; - echo $tp->parseTemplate("{NEXTPREV={$parms}}"); + $paginationSC = false; - // $parms = $news_total.",".ITEMVIEW.",".$newsfrom.",".e_SELF.'?'.($action ? $action : 'default' ).($sub_action ? ".".$sub_action : ".0").".[FROM]"; - // $nextprev = $tp->parseTemplate("{NEXTPREV={$parms}}"); - // echo ($nextprev ? "
".$nextprev."
" : ""); + if(!empty($tmpl['end'])) + { + e107::setRegistry('core/news/pagination', $parms); + $nsc = e107::getScBatch('news')->setScVar('news_item', $newsAr[1])->setScVar('param', $param); + echo $tp->parseTemplate($tmpl['end'], true, $nsc); + if(strpos($tmpl['end'], '{NEWS_PAGINATION') !== false) // BC fix. + { + $paginationSC = true; + $this->addDebug("Pagination Shortcode", 'true'); + } + } + + if($paginationSC === false) // BC Fix. + { + echo $tp->parseTemplate("{NEXTPREV={$parms}}"); + $this->addDebug("Pagination Shortcode", 'false'); + } $cache_data = ob_get_clean();