mirror of
https://github.com/e107inc/e107.git
synced 2025-04-20 04:32:01 +02:00
Nextprev rewrite: more flexible parameters, totally skinnable (simple parser), core templates, option to use plugin templates, no inline styles, BC granted
This commit is contained in:
parent
1c2c1ee4a8
commit
18479a95f4
515
e107_core/shortcodes/single/nextprev.php
Normal file
515
e107_core/shortcodes/single/nextprev.php
Normal file
@ -0,0 +1,515 @@
|
||||
<?php
|
||||
/*
|
||||
* e107 website system
|
||||
*
|
||||
* Copyright (C) 2008-2010 e107 Inc (e107.org)
|
||||
* Released under the terms and conditions of the
|
||||
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt)
|
||||
*
|
||||
* Core NEXTPREV shortcode
|
||||
*
|
||||
* $URL$
|
||||
* $Id$
|
||||
*/
|
||||
|
||||
/**
|
||||
* @package e107
|
||||
* @subpackage shortcodes
|
||||
* @version $Id$
|
||||
*
|
||||
* Render page navigation bar
|
||||
*/
|
||||
|
||||
/**
|
||||
* Core NEXTPREV shortcode
|
||||
* Comma separated parameters are now deprecated.
|
||||
* Parameter string should be formatted as if it were the query string passed via a URL:
|
||||
* <code>$parm = 'total=10&amount=5¤t=0&type=...'</code>
|
||||
*
|
||||
* Parameter list:
|
||||
* - total (integer) [required]: total records/pages
|
||||
* - amount (integer| string 'all') [required]: Records per page, always 1 when we counting pages (see 'type' parameter), ignored where tmpl_prefix is not set and 'old_np' pref is false
|
||||
* - current (integer)[required]: Current record/page
|
||||
* - type (string page|record) [optional]: What kind of navigation logic we need, default is 'record' (the old way)
|
||||
* - url (rawurlencode'd string) [required]: URL template, will be rawurldecode'd after parameters are parsed to array
|
||||
* Preffered 'FROM' template is now '--FROM--' (instead '[FROM]')
|
||||
* - caption (rawurlencode'd string) [optional]: Label, rawurldecode'd after parameters are parsed to array, language constants are supported
|
||||
* - pagetitle (rawurlencode'd string) [optional]: Page labels, rawurldecode'd after parameters are parsed to array,
|
||||
* separated by '|', if present they will be used as lablels instead page numbers; language constants are supported
|
||||
* - plugins (string) [optional]: plugin name used for template loading
|
||||
* - tmpl_prefix (string) [optional]: template keys prefix; core supported are 'default' and 'dropdown', default depends on 'old_np' pref
|
||||
* - navcount (integer) [optional]: number of navigation items to be shown, minimal allowed value is 4, default is 10
|
||||
*
|
||||
* WARNING: You have to do rawuldecode() on url, caption and title parameter values (before passing them to the shortcode)
|
||||
* or you'll break the whole script
|
||||
*
|
||||
* @param string $parm
|
||||
* @return string page navigation bar HTML
|
||||
*/
|
||||
function nextprev_shortcode($parm = '')
|
||||
{
|
||||
$e107 = e107::getInstance();
|
||||
$pref = e107::getPref();
|
||||
|
||||
include_lan(e_LANGUAGEDIR.e_LANGUAGE.'/lan_np.php');
|
||||
|
||||
/**
|
||||
* The NEW way.
|
||||
* New parameter requirements formatted as a GET string.
|
||||
* Template support.
|
||||
*/
|
||||
if(strpos($parm, 'total=') !== false)
|
||||
{
|
||||
// Calculate
|
||||
parse_str($parm, $parm);
|
||||
|
||||
$total_items = intval($parm['total']);
|
||||
// search for template keys - default_start, default_end etc.
|
||||
if(isset($parm['tmpl_prefix']))
|
||||
{
|
||||
// forced
|
||||
$tprefix = vartrue($parm['tmpl_prefix'], 'default');
|
||||
$perpage = $parm['amount'] !== 'all' ? intval($parm['amount']) : $total_items;
|
||||
}
|
||||
// default, based on prefs
|
||||
elseif($pref['old_np'])
|
||||
{
|
||||
|
||||
$tprefix = 'default';
|
||||
$perpage = $parm['amount'] !== 'all' ? intval($parm['amount']) : $total_items;
|
||||
}
|
||||
else
|
||||
{
|
||||
$tprefix = 'dropdown';
|
||||
$perpage = $total_items; // amount is ignored
|
||||
}
|
||||
$tprefix .= '_';
|
||||
// TODO - rename old_np to something more meaningful
|
||||
|
||||
$current_start = intval($parm['current']);
|
||||
$nptype = varset($parm['type'], 'record');
|
||||
switch ($nptype)
|
||||
{
|
||||
case 'page':
|
||||
$perpage = 1;
|
||||
$current_page = $current_start;
|
||||
$first_page = 1;
|
||||
$next_page = $current_page + 1;
|
||||
$prev_page = $current_page - 1;
|
||||
$total_pages = $total_items;
|
||||
$index_add = 1;
|
||||
break;
|
||||
|
||||
default:
|
||||
$total_pages = ceil($total_items/$perpage);
|
||||
$current_page = ($current_start/$perpage) + 1;
|
||||
$next_page = $current_page*$perpage;
|
||||
$prev_page = $current_start/$perpage;
|
||||
$first_page = 0;
|
||||
$index_add = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
if($total_pages <= 1) { return ''; }
|
||||
|
||||
// urldecoded by parse_str()
|
||||
$url = str_replace('--FROM--', '[FROM]', $parm['url']);
|
||||
|
||||
// Simple parser vars
|
||||
$e_vars = new e_vars(array(
|
||||
'total_pages' => $total_pages,
|
||||
'current_page' => $current_page
|
||||
));
|
||||
|
||||
// urldecoded by parse_str()
|
||||
if(!varset($parm['caption']))
|
||||
{
|
||||
$e_vars->caption = 'LAN_NP_CAPTION';
|
||||
}
|
||||
// Advanced multilingual support: 'Page %1$d of %2$d' -> match the exact argument, result would be 'Page 1 of 20'
|
||||
$e_vars->caption = sprintf(defset($e_vars->caption, $e_vars->caption), $current_page, $total_pages);
|
||||
|
||||
// urldecoded by parse_str()
|
||||
$pagetitle = explode('|',$parm['pagetitle']);
|
||||
|
||||
// navigation number settings
|
||||
$navcount = abs(intval(varset($parm['navcount'], 10))); // prevent infinite loop!
|
||||
if($navcount < 4) $navcount = 4;
|
||||
$navmid = floor($navcount/2);
|
||||
|
||||
// get template - nextprev_template.php, support for plugin template locations - myplug/templates/nextprev_template.php
|
||||
$tmpl = e107::getTemplate(varset($parm['plugin'], null), 'nextprev');
|
||||
|
||||
// init advanced navigation visibility
|
||||
$show_first = $show_prev = ($current_page != 1);
|
||||
$show_last = $show_next = ($current_page != $total_pages);
|
||||
|
||||
// Render
|
||||
// XXX - parseTemplate vs simpleParse ??? Currently can't find a reason why we should parse via parseTemplate
|
||||
$tp = e107::getParser();
|
||||
|
||||
// Nextprev navigation start
|
||||
$ret = $tp->simpleParse($tmpl[$tprefix.'start'], $e_vars);
|
||||
|
||||
// caption, e.g. 'Page 1 of 20' box
|
||||
if($e_vars->caption)
|
||||
{
|
||||
$ret .= $tp->simpleParse($tmpl[$tprefix.'nav_caption'], $e_vars);
|
||||
}
|
||||
|
||||
$ret_array = array();
|
||||
|
||||
// Show from 1 to $navcount || $total_pages
|
||||
if($current_page <= $navmid || $total_pages <= $navcount)
|
||||
{
|
||||
$loop_start = 0;
|
||||
$loop_end = $navcount;
|
||||
$show_first = false;
|
||||
if($navcount >= $total_pages)
|
||||
{
|
||||
$loop_end = $total_pages;
|
||||
$show_last = false;
|
||||
}
|
||||
}
|
||||
// Calculate without producing infinite loop ;)
|
||||
else
|
||||
{
|
||||
if($current_page + $navmid >= $total_pages)
|
||||
{
|
||||
$loop_start = $total_pages - $navcount;
|
||||
if($loop_start < 0) $loop_start = 0;
|
||||
$loop_end = $total_pages;
|
||||
$show_last = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
$loop_start = $current_page - $navmid;
|
||||
$loop_end = $current_page + ($navcount - $navmid); // odd/even $navcount support
|
||||
if($loop_start < 0)
|
||||
{
|
||||
$loop_start = 0;
|
||||
}
|
||||
elseif($loop_end > $total_pages)
|
||||
{
|
||||
$loop_end = $total_pages;
|
||||
$show_last = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Add 'first', 'previous' navigation
|
||||
if($show_prev)
|
||||
{
|
||||
if($show_first && !empty($tmpl[$tprefix.'nav_first']))
|
||||
{
|
||||
$e_vars->url = str_replace('[FROM]', $first_page, $url);
|
||||
$e_vars->label = LAN_NP_FIRST;
|
||||
$e_vars->url_label = LAN_NP_URLFIRST;
|
||||
$ret_array[] = $tp->simpleParse($tmpl[$tprefix.'nav_first'], $e_vars);
|
||||
}
|
||||
|
||||
if(!empty($tmpl[$tprefix.'nav_prev']))
|
||||
{
|
||||
$e_vars->url = str_replace('[FROM]', $prev_page, $url);
|
||||
$e_vars->label = LAN_NP_PREVIOUS;
|
||||
$e_vars->url_label = LAN_NP_URLPREVIOUS;
|
||||
$ret_array[] = $tp->simpleParse($tmpl[$tprefix.'nav_prev'], $e_vars);
|
||||
}
|
||||
}
|
||||
|
||||
$e_vars_loop = new e_vars();
|
||||
$ret_items = array();
|
||||
for($c = $loop_start; $c < $loop_end; $c++)
|
||||
{
|
||||
$label = '';
|
||||
if(varset($pagetitle[$c]))
|
||||
{
|
||||
$label = defset($pagetitle[$c], $pagetitle[$c]);
|
||||
}
|
||||
$e_vars_loop->url = str_replace('[FROM]', ($perpage * ($c + $index_add)), $url);
|
||||
$e_vars_loop->label = $label ? $tp->toHTML($label, false, 'TITLE') : $c + 1;
|
||||
|
||||
if($c + 1 == $current_page)
|
||||
{
|
||||
$e_vars_loop->url_label = $label ? $tp->toAttribute($label) : LAN_NP_URLCURRENT;
|
||||
$ret_items[] = $tp->simpleParse($tmpl[$tprefix.'item_current'], $e_vars_loop);
|
||||
}
|
||||
else
|
||||
{
|
||||
$e_vars_loop->url_label = $label ? $tp->toAttribute($label) : LAN_NP_GOTO;
|
||||
$e_vars_loop->url_label = sprintf($e_vars_loop->url_label, ($c + 1));
|
||||
$ret_items[] = $tp->simpleParse($tmpl[$tprefix.'item'], $e_vars_loop);
|
||||
}
|
||||
}
|
||||
$ret_array[] = $tp->simpleParse($tmpl[$tprefix.'items_start'], $e_vars).implode($tmpl[$tprefix.'separator'], $ret_items).$tp->simpleParse($tmpl[$tprefix.'items_end'], $e_vars);
|
||||
unset($ret_items, $e_vars_loop);
|
||||
|
||||
if($show_next)
|
||||
{
|
||||
if(!empty($tmpl[$tprefix.'nav_next']))
|
||||
{
|
||||
$e_vars->url = str_replace('[FROM]', $next_page, $url);
|
||||
$e_vars->label = LAN_NP_NEXT;
|
||||
$e_vars->url_label = LAN_NP_URLNEXT;
|
||||
$ret_array[] = $tp->simpleParse($tmpl[$tprefix.'nav_next'], $e_vars);
|
||||
}
|
||||
|
||||
if($show_last && !empty($tmpl[$tprefix.'nav_last']))
|
||||
{
|
||||
$e_vars->url = str_replace('[FROM]', $last_page, $url);
|
||||
$e_vars->label = LAN_NP_LAST;
|
||||
$e_vars->url_label = LAN_NP_URLLAST;
|
||||
$ret_array[] = $tp->simpleParse($tmpl[$tprefix.'nav_last'], $e_vars);
|
||||
}
|
||||
}
|
||||
|
||||
$ret .= implode($tmpl[$tprefix.'separator'], $ret_array);
|
||||
|
||||
// Nextprev navigation end
|
||||
$ret .= $tp->simpleParse($tmpl[$tprefix.'end'], $e_vars);
|
||||
unset($e_vars, $ret_array);
|
||||
|
||||
return $ret;
|
||||
}
|
||||
/**
|
||||
* The old way, ALL BELOW IS DEPRECATED
|
||||
*/
|
||||
else
|
||||
{
|
||||
$parm_count = substr_count($parm, ',');
|
||||
while($parm_count < 5)
|
||||
{
|
||||
$parm .= ',';
|
||||
$parm_count++;
|
||||
}
|
||||
|
||||
$p = explode(',', $parm, 6);
|
||||
|
||||
$total_items = intval($p[0]);
|
||||
$perpage = intval($p[1]);
|
||||
|
||||
// page number instead record start now supported
|
||||
if(is_numeric($p[2]))
|
||||
{
|
||||
$current_start = intval($p[2]);
|
||||
$current_page = ($current_start/$perpage) + 1;
|
||||
$total_pages = ceil($total_items/$perpage);
|
||||
$index_add = 0;
|
||||
}
|
||||
else // new - page support in format 'p:1'
|
||||
{
|
||||
$perpage = 1;
|
||||
$current_start = intval(array_pop(explode(':', $p[2], 2)));
|
||||
$current_page = $current_start;
|
||||
$total_pages = $total_items;
|
||||
$index_add = 1;
|
||||
}
|
||||
|
||||
if($total_items < $perpage) { return ''; }
|
||||
|
||||
$url = trim($p[3]);
|
||||
$caption = trim($p[4]);
|
||||
$pagetitle = explode('|',trim($p[5]));
|
||||
|
||||
$caption = (!$caption || $caption == 'off') ? NP_3.' ' : $caption;
|
||||
|
||||
while(substr($url, -1) == '.')
|
||||
{
|
||||
$url=substr($url, 0, -1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if($total_pages > 1)
|
||||
{
|
||||
if(varsettrue($pref['old_np']))
|
||||
{
|
||||
|
||||
$NP_PRE_ACTIVE = '';
|
||||
$NP_POST_ACTIVE = '';
|
||||
$NP_STYLE = '';
|
||||
|
||||
if(!defined('NEXTPREV_NOSTYLE') || NEXTPREV_NOSTYLE==FALSE){
|
||||
$NP_PRE_ACTIVE = '[';
|
||||
$NP_POST_ACTIVE = '] ';
|
||||
$NP_STYLE = "style='text-decoration:underline'";
|
||||
}
|
||||
|
||||
|
||||
// Use OLD nextprev method
|
||||
$nppage = '';
|
||||
$nppage .= "\n\n<!-- Start of Next/Prev -->\n\n";
|
||||
if ($total_pages > 10)
|
||||
{
|
||||
//$current_page = ($current_start/$perpage)+1;
|
||||
|
||||
for($c = 0; $c <= 2; $c++)
|
||||
{
|
||||
if($perpage * ($c + $index_add) == $current_start)
|
||||
{
|
||||
$nppage .= $NP_PRE_ACTIVE."<span class='nextprev_current' {$NP_STYLE} >".($c+1)."</span>".$NP_POST_ACTIVE."\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
$link = str_replace("[FROM]", ($perpage * ($c + $index_add)), $url);
|
||||
$nppage .= "<a class='nextprev_link' href='{$link}'>".($c+1)."</a> \n";
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if ($current_page >= 3 && $current_page <= 5)
|
||||
{
|
||||
for($c = 3; $c <= $current_page; $c++)
|
||||
{
|
||||
if($perpage * ($c + $index_add) == $current_start)
|
||||
{
|
||||
$nppage .= $NP_PRE_ACTIVE."<span class='nextprev_current' {$NP_STYLE} >".($c+1)."</span>".$NP_POST_ACTIVE."\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
$link = str_replace("[FROM]", ($perpage * ($c + $index_add)), $url);
|
||||
$nppage .= "<a class='nextprev_link' href='{$link}'>".($c+1)."</a> \n";
|
||||
}
|
||||
}
|
||||
}
|
||||
else if($current_page >= 6 && $current_page <= ($total_pages-5))
|
||||
{
|
||||
$nppage .= " ... ";
|
||||
for($c = ($current_page-2); $c <= $current_page; $c++)
|
||||
{
|
||||
if($perpage * ($c + $index_add) == $current_start)
|
||||
{
|
||||
$nppage .= $NP_PRE_ACTIVE."<span class='nextprev_current' {$NP_STYLE} >".($c+1)."</span>".$NP_POST_ACTIVE."\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
$link = str_replace("[FROM]", ($perpage * ($c + $index_add)), $url);
|
||||
$nppage .= "<a class='nextprev_link' href='{$link}'>".($c+1)."</a> \n";
|
||||
}
|
||||
}
|
||||
}
|
||||
$nppage .= " ... ";
|
||||
|
||||
if (($current_page+5) > $total_pages && $current_page != $total_pages)
|
||||
{
|
||||
$tmp = ($current_page-2);
|
||||
}
|
||||
else
|
||||
{
|
||||
$tmp = $total_pages-3;
|
||||
}
|
||||
|
||||
for($c = $tmp; $c <= ($total_pages-1); $c++)
|
||||
{
|
||||
if($perpage * ($c + $index_add) == $current_start)
|
||||
{
|
||||
$nppage .= $NP_PRE_ACTIVE."<span class='nextprev_current' {$NP_STYLE} >".($c+1)."</span>".$NP_POST_ACTIVE."\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
$link = str_replace("[FROM]", ($perpage * ($c + $index_add)), $url);
|
||||
$nppage .= "<a class='nextprev_link' href='{$link}'>".($c+1)."</a> \n";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
for($c = 0; $c < $total_pages; $c++)
|
||||
{
|
||||
if($perpage * ($c + $index_add) == $current_start)
|
||||
{
|
||||
$nppage .= $NP_PRE_ACTIVE."<span class='nextprev_current' {$NP_STYLE} >".($c+1)."</span>".$NP_POST_ACTIVE."\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
$link = str_replace("[FROM]", ($perpage * ($c + $index_add)), $url);
|
||||
$nppage .= "<a class='nextprev_link' href='{$link}'>".($c+1)."</a> \n";
|
||||
}
|
||||
}
|
||||
}
|
||||
$nppage .= "\n\n<!-- End of Next/Prev -->\n\n";
|
||||
return $caption.$nppage;
|
||||
}
|
||||
|
||||
// Use NEW nextprev method
|
||||
$np_parm['template'] = "[PREV] [DROPDOWN] [NEXT]";
|
||||
$np_parms['prev'] = ' << ';
|
||||
$np_parms['next'] = ' >> ';
|
||||
$np_parms['np_class'] = 'tbox npbutton';
|
||||
$np_parms['dropdown_class'] = 'tbox npdropdown';
|
||||
|
||||
if($cached_parms = getcachedvars('nextprev'))
|
||||
{
|
||||
$tmp = $cached_parms;
|
||||
foreach($tmp as $key => $val)
|
||||
{
|
||||
$np_parms[$key]=$val;
|
||||
}
|
||||
}
|
||||
|
||||
$prev='';
|
||||
$next='';
|
||||
if($current_page > 1)
|
||||
{
|
||||
$prevstart = ($current_start - $perpage);
|
||||
|
||||
if(substr($url, 0, 5) == 'url::')
|
||||
{
|
||||
$urlParms = explode('::', $url);
|
||||
$urlParms[3] = str_replace('[FROM]', $prevstart, $urlParms[3]);
|
||||
$link = $e107->url->getUrl($urlParms[1], $urlParms[2], $urlParms[3]);
|
||||
}
|
||||
else
|
||||
{
|
||||
$link = str_replace('[FROM]', $prevstart, $url);
|
||||
}
|
||||
$prev = "<a class='{$np_parms['np_class']}' style='text-decoration:none' href='{$link}'>{$np_parms['prev']}</a>";
|
||||
}
|
||||
if($current_page < $total_pages)
|
||||
{
|
||||
$nextstart = ($current_start + $perpage);
|
||||
if(substr($url, 0, 5) == 'url::')
|
||||
{
|
||||
$urlParms = explode('::', $url);
|
||||
$urlParms[3] = str_replace('[FROM]', $nextstart, $urlParms[3]);
|
||||
$link = $e107->url->getUrl($urlParms[1], $urlParms[2], $urlParms[3]);
|
||||
}
|
||||
else
|
||||
{
|
||||
$link = str_replace('[FROM]', $nextstart, $url);
|
||||
}
|
||||
$next = "<a class='{$np_parms['np_class']}' style='text-decoration:none' href='{$link}'>{$np_parms['next']}</a>";
|
||||
}
|
||||
$dropdown = "<select class='{$np_parms['dropdown_class']}' name='pageSelect' onchange='location.href=this.options[selectedIndex].value'>";
|
||||
for($i = 1; $i <= $total_pages; $i++)
|
||||
{
|
||||
$sel = '';
|
||||
if($current_page == $i)
|
||||
{
|
||||
$sel = " selected='selected' ";
|
||||
}
|
||||
$newstart = ($i-1 + $index_add)*$perpage;
|
||||
if(substr($url, 0, 5) == 'url::')
|
||||
{
|
||||
$urlParms = explode('::', $url);
|
||||
$urlParms[3] = str_replace('[FROM]', $newstart, $urlParms[3]);
|
||||
$link = $e107->url->getUrl($urlParms[1], $urlParms[2], $urlParms[3]);
|
||||
}
|
||||
else
|
||||
{
|
||||
$link = str_replace('[FROM]', $newstart, $url);
|
||||
}
|
||||
$c = $i-1 + $index_add;
|
||||
$title = ($pagetitle[$c]) ? $pagetitle[$c] : $i;
|
||||
$dropdown .= "<option value='{$link}' {$sel}>{$title}</option>\n";
|
||||
}
|
||||
$dropdown .= '</select>';
|
||||
$ret = $np_parm['template'];
|
||||
$ret = str_replace('[DROPDOWN]', $dropdown, $ret);
|
||||
$ret = str_replace('[PREV]', $prev, $ret);
|
||||
$ret = str_replace('[NEXT]', $next, $ret);
|
||||
return $caption.$ret;
|
||||
}
|
||||
}
|
||||
return '';
|
@ -1,227 +0,0 @@
|
||||
global $pref;
|
||||
$e107 = e107::getInstance();
|
||||
|
||||
include_lan(e_LANGUAGEDIR.e_LANGUAGE.'/lan_np.php');
|
||||
$parm_count = substr_count($parm, ',');
|
||||
|
||||
while($parm_count < 5)
|
||||
{
|
||||
$parm .= ',';
|
||||
$parm_count++;
|
||||
}
|
||||
|
||||
$p = explode(',', $parm, 6);
|
||||
|
||||
$total_items = intval($p[0]);
|
||||
$perpage = intval($p[1]);
|
||||
$current_start = intval($p[2]);
|
||||
$url = trim($p[3]);
|
||||
$caption = trim($p[4]);
|
||||
$pagetitle = explode('|',trim($p[5]));
|
||||
|
||||
if($total_items < $perpage) { return ''; }
|
||||
|
||||
|
||||
|
||||
$caption = (!$caption || $caption == 'off') ? NP_3.' ' : $caption;
|
||||
|
||||
while(substr($url, -1) == '.')
|
||||
{
|
||||
$url=substr($url, 0, -1);
|
||||
}
|
||||
|
||||
$current_page = ($current_start/$perpage) + 1;
|
||||
$total_pages = ceil($total_items/$perpage);
|
||||
|
||||
if($total_pages > 1)
|
||||
{
|
||||
if(varsettrue($pref['old_np']))
|
||||
{
|
||||
|
||||
$NP_PRE_ACTIVE = '';
|
||||
$NP_POST_ACTIVE = '';
|
||||
$NP_STYLE = '';
|
||||
|
||||
if(!defined('NEXTPREV_NOSTYLE') || NEXTPREV_NOSTYLE==FALSE){
|
||||
$NP_PRE_ACTIVE = '[';
|
||||
$NP_POST_ACTIVE = '] ';
|
||||
$NP_STYLE = "style='text-decoration:underline'";
|
||||
}
|
||||
|
||||
|
||||
// Use OLD nextprev method
|
||||
$nppage = '';
|
||||
$nppage .= "\n\n<!-- Start of Next/Prev -->\n\n";
|
||||
if ($total_pages > 10)
|
||||
{
|
||||
$current_page = ($current_start/$perpage)+1;
|
||||
|
||||
for($c = 0; $c <= 2; $c++)
|
||||
{
|
||||
if($perpage * $c == $current_start)
|
||||
{
|
||||
$nppage .= $NP_PRE_ACTIVE."<span class='nextprev_current' {$NP_STYLE} >".($c+1)."</span>".$NP_POST_ACTIVE."\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
$link = str_replace("[FROM]", ($perpage * $c), $url);
|
||||
$nppage .= "<a class='nextprev_link' href='{$link}'>".($c+1)."</a> \n";
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if ($current_page >= 3 && $current_page <= 5)
|
||||
{
|
||||
for($c = 3; $c <= $current_page; $c++)
|
||||
{
|
||||
if($perpage * $c == $current_start)
|
||||
{
|
||||
$nppage .= $NP_PRE_ACTIVE."<span class='nextprev_current' {$NP_STYLE} >".($c+1)."</span>".$NP_POST_ACTIVE."\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
$link = str_replace("[FROM]", ($perpage * $c), $url);
|
||||
$nppage .= "<a class='nextprev_link' href='{$link}'>".($c+1)."</a> \n";
|
||||
}
|
||||
}
|
||||
}
|
||||
else if($current_page >= 6 && $current_page <= ($total_pages-5))
|
||||
{
|
||||
$nppage .= " ... ";
|
||||
for($c = ($current_page-2); $c <= $current_page; $c++)
|
||||
{
|
||||
if($perpage * $c == $current_start)
|
||||
{
|
||||
$nppage .= $NP_PRE_ACTIVE."<span class='nextprev_current' {$NP_STYLE} >".($c+1)."</span>".$NP_POST_ACTIVE."\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
$link = str_replace("[FROM]", ($perpage * $c), $url);
|
||||
$nppage .= "<a class='nextprev_link' href='{$link}'>".($c+1)."</a> \n";
|
||||
}
|
||||
}
|
||||
}
|
||||
$nppage .= " ... ";
|
||||
|
||||
if (($current_page+5) > $total_pages && $current_page != $total_pages)
|
||||
{
|
||||
$tmp = ($current_page-2);
|
||||
}
|
||||
else
|
||||
{
|
||||
$tmp = $total_pages-3;
|
||||
}
|
||||
|
||||
for($c = $tmp; $c <= ($total_pages-1); $c++)
|
||||
{
|
||||
if($perpage * $c == $current_start)
|
||||
{
|
||||
$nppage .= $NP_PRE_ACTIVE."<span class='nextprev_current' {$NP_STYLE} >".($c+1)."</span>".$NP_POST_ACTIVE."\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
$link = str_replace("[FROM]", ($perpage * $c), $url);
|
||||
$nppage .= "<a class='nextprev_link' href='{$link}'>".($c+1)."</a> \n";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
for($c = 0; $c < $total_pages; $c++)
|
||||
{
|
||||
if($perpage * $c == $current_start)
|
||||
{
|
||||
$nppage .= $NP_PRE_ACTIVE."<span class='nextprev_current' {$NP_STYLE} >".($c+1)."</span>".$NP_POST_ACTIVE."\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
$link = str_replace("[FROM]", ($perpage * $c), $url);
|
||||
$nppage .= "<a class='nextprev_link' href='{$link}'>".($c+1)."</a> \n";
|
||||
}
|
||||
}
|
||||
}
|
||||
$nppage .= "\n\n<!-- End of Next/Prev -->\n\n";
|
||||
return $caption.$nppage;
|
||||
}
|
||||
|
||||
// Use NEW nextprev method
|
||||
$np_parm['template'] = "[PREV] [DROPDOWN] [NEXT]";
|
||||
$np_parms['prev'] = ' << ';
|
||||
$np_parms['next'] = ' >> ';
|
||||
$np_parms['np_class'] = 'tbox npbutton';
|
||||
$np_parms['dropdown_class'] = 'tbox npdropdown';
|
||||
|
||||
if($cached_parms = getcachedvars('nextprev'))
|
||||
{
|
||||
$tmp = $cached_parms;
|
||||
foreach($tmp as $key => $val)
|
||||
{
|
||||
$np_parms[$key]=$val;
|
||||
}
|
||||
}
|
||||
|
||||
$prev='';
|
||||
$next='';
|
||||
if($current_page > 1)
|
||||
{
|
||||
$prevstart = ($current_start - $perpage);
|
||||
|
||||
if(substr($url, 0, 5) == 'url::')
|
||||
{
|
||||
$urlParms = explode('::', $url);
|
||||
$urlParms[3] = str_replace('[FROM]', $prevstart, $urlParms[3]);
|
||||
$link = $e107->url->getUrl($urlParms[1], $urlParms[2], $urlParms[3]);
|
||||
}
|
||||
else
|
||||
{
|
||||
$link = str_replace('[FROM]', $prevstart, $url);
|
||||
}
|
||||
$prev = "<a class='{$np_parms['np_class']}' style='text-decoration:none' href='{$link}'>{$np_parms['prev']}</a>";
|
||||
}
|
||||
if($current_page < $total_pages)
|
||||
{
|
||||
$nextstart = ($current_start + $perpage);
|
||||
if(substr($url, 0, 5) == 'url::')
|
||||
{
|
||||
$urlParms = explode('::', $url);
|
||||
$urlParms[3] = str_replace('[FROM]', $nextstart, $urlParms[3]);
|
||||
$link = $e107->url->getUrl($urlParms[1], $urlParms[2], $urlParms[3]);
|
||||
}
|
||||
else
|
||||
{
|
||||
$link = str_replace('[FROM]', $nextstart, $url);
|
||||
}
|
||||
$next = "<a class='{$np_parms['np_class']}' style='text-decoration:none' href='{$link}'>{$np_parms['next']}</a>";
|
||||
}
|
||||
$dropdown = "<select class='{$np_parms['dropdown_class']}' name='pageSelect' onchange='location.href=this.options[selectedIndex].value'>";
|
||||
for($i = 1; $i <= $total_pages; $i++)
|
||||
{
|
||||
$sel = '';
|
||||
if($current_page == $i)
|
||||
{
|
||||
$sel = " selected='selected' ";
|
||||
}
|
||||
$newstart = ($i-1)*$perpage;
|
||||
if(substr($url, 0, 5) == 'url::')
|
||||
{
|
||||
$urlParms = explode('::', $url);
|
||||
$urlParms[3] = str_replace('[FROM]', $newstart, $urlParms[3]);
|
||||
$link = $e107->url->getUrl($urlParms[1], $urlParms[2], $urlParms[3]);
|
||||
}
|
||||
else
|
||||
{
|
||||
$link = str_replace('[FROM]', $newstart, $url);
|
||||
}
|
||||
$c = $i-1;
|
||||
$title = ($pagetitle[$c]) ? $pagetitle[$c] : $i;
|
||||
$dropdown .= "<option value='{$link}' {$sel}>{$title}</option>\n";
|
||||
}
|
||||
$dropdown .= '</select>';
|
||||
$ret = $np_parm['template'];
|
||||
$ret = str_replace('[DROPDOWN]', $dropdown, $ret);
|
||||
$ret = str_replace('[PREV]', $prev, $ret);
|
||||
$ret = str_replace('[NEXT]', $next, $ret);
|
||||
return $caption.$ret;
|
||||
}
|
||||
return '';
|
@ -1340,7 +1340,7 @@ class e107
|
||||
* - $USER_TEMPLATE array which contains all user templates
|
||||
* - $USER_TEMPLATE['short_start'] (if key is null, $USER_TEMPLATE will be returned)
|
||||
*
|
||||
* @param string $plug_name
|
||||
* @param string $plug_name if null getCoreTemplate method will be called
|
||||
* @param string $id - file prefix, e.g. calendar for calendar_template.php
|
||||
* @param string|null $key
|
||||
* @param boolean $override see {@link getThemeInfo()}
|
||||
@ -1350,6 +1350,10 @@ class e107
|
||||
*/
|
||||
public static function getTemplate($plug_name, $id, $key = null, $override = true, $merge = false, $info = false)
|
||||
{
|
||||
if(null === $plug_name)
|
||||
{
|
||||
return self::getCoreTemplate($id, $key, $override, $merge, $info);
|
||||
}
|
||||
$reg_path = 'plugin/'.$plug_name.'/templates/'.$id.($override ? '/ext' : '');
|
||||
$path = self::templatePath($plug_name, $id, $override);
|
||||
$id = str_replace('/', '_', $id);
|
||||
|
@ -1,16 +1,29 @@
|
||||
<?php
|
||||
/*
|
||||
+ ----------------------------------------------------------------------------+
|
||||
| e107 website system - Language File.
|
||||
|
|
||||
| $Source: /cvs_backup/e107_0.8/e107_languages/English/lan_np.php,v $
|
||||
| $Revision$
|
||||
| $Date$
|
||||
| $Author$
|
||||
+----------------------------------------------------------------------------+
|
||||
* Copyright 2008-2010 e107 Inc e107.org, Licensed under GNU GPL (http://www.gnu.org/licenses/gpl.txt)
|
||||
* $Id$
|
||||
*
|
||||
* Nexptrev Shortcode Language File
|
||||
*/
|
||||
define("NP_1", "Previous page");
|
||||
define("NP_2", "Next page");
|
||||
define("NP_3", "Go to page");
|
||||
|
||||
define('NP_1', 'Previous page');
|
||||
define('NP_2', 'Next page');
|
||||
define('NP_3', 'Go to page');
|
||||
|
||||
// 0.8
|
||||
define('LAN_NP_FIRST', 'first');
|
||||
define('LAN_NP_URLFIRST', 'Go to the first page');
|
||||
define('LAN_NP_PREVIOUS', 'previous');
|
||||
define('LAN_NP_URLPREVIOUS', 'Go to the previous page');
|
||||
define('LAN_NP_NEXT', 'next');
|
||||
define('LAN_NP_URLNEXT', 'Go to the next page');
|
||||
define('LAN_NP_LAST', 'last');
|
||||
define('LAN_NP_URLLAST', 'Go to the last page');
|
||||
define('LAN_NP_GOTO', 'Go to page %s');
|
||||
define('LAN_NP_URLCURRENT', 'Currently viewed');
|
||||
|
||||
// WARNING - USE SINGLE QUOTES!!!
|
||||
// Replacement: '%1$d' - current page; '%2$d' - total pages
|
||||
define('NP_CAPTION', 'Page %1$d of %2$d');
|
||||
|
||||
?>
|
77
e107_themes/templates/nextprev_template.php
Normal file
77
e107_themes/templates/nextprev_template.php
Normal file
@ -0,0 +1,77 @@
|
||||
<?php
|
||||
/*
|
||||
* Copyright (c) e107 Inc 2009 - e107.org, Licensed under GNU GPL (http://www.gnu.org/licenses/gpl.txt)
|
||||
* $Id$
|
||||
*
|
||||
* NEXTPREV shortcode template
|
||||
*/
|
||||
|
||||
/*
|
||||
* Default (old) page navigation, key prefix 'default'
|
||||
* Shortcodes are lowercase (simple parser)
|
||||
*/
|
||||
|
||||
$NEXTPREV_TEMPLATE['default_start'] = '
|
||||
<!-- Start of Next/Prev -->
|
||||
<div class="nextprev">
|
||||
';
|
||||
|
||||
$NEXTPREV_TEMPLATE['default_end'] = '
|
||||
</div>
|
||||
<!-- End of Next/Prev -->
|
||||
';
|
||||
|
||||
//$NEXTPREV_TEMPLATE['default_nav_caption'] = '<span class="nexprev-caption center">{caption}</span> '; XXX - awaiting the new front-end themes & templates
|
||||
$NEXTPREV_TEMPLATE['default_nav_caption'] = NP_3.' ';
|
||||
|
||||
$NEXTPREV_TEMPLATE['default_nav_first'] = '<a class="nextprev-item first" href="{url}" title="{url_label}">{label}</a>';
|
||||
$NEXTPREV_TEMPLATE['default_nav_prev'] = '<a class="nextprev-item prev" href="{url}" title="{url_label}">{label}</a>';
|
||||
$NEXTPREV_TEMPLATE['default_nav_last'] = '<a class="nextprev-item last" href="{url}" title="{url_label}">{label}</a>';
|
||||
$NEXTPREV_TEMPLATE['default_nav_next'] = '<a class="nextprev-item next" href="{url}" title="{url_label}">{label}</a>';
|
||||
|
||||
$NEXTPREV_TEMPLATE['default_items_start'] = '';
|
||||
$NEXTPREV_TEMPLATE['default_item'] = '<a class="nextprev-item" href="{url}" title="{url_label}">{label}</a>';
|
||||
$NEXTPREV_TEMPLATE['default_item_current'] = '<a class="nextprev-item current" href="#" onclick="return false;" title="{url_label}">{label}</a>';
|
||||
$NEXTPREV_TEMPLATE['default_items_end'] = '';
|
||||
|
||||
//$NEXTPREV_TEMPLATE['default_separator'] = '<span class="nextprev-sep"><!-- --></span>';
|
||||
$NEXTPREV_TEMPLATE['default_separator'] = ' ';
|
||||
|
||||
|
||||
/*
|
||||
* Dropdown page navigation, key prefix 'dropdown'
|
||||
* Shortcodes are lowercase (simple parser)
|
||||
* TODO - do the slide-down via JS, make it unobtrusive
|
||||
*/
|
||||
|
||||
$NEXTPREV_TEMPLATE['dropdown_start'] = '
|
||||
<!-- Start of Next/Prev -->
|
||||
<div class="nextprev">
|
||||
';
|
||||
|
||||
$NEXTPREV_TEMPLATE['dropdown_end'] = '
|
||||
</div>
|
||||
<!-- End of Next/Prev -->
|
||||
';
|
||||
|
||||
//$NEXTPREV_TEMPLATE['default_nav_caption'] = '<span class="nexprev-caption center">{caption}</span> '; XXX - awaiting the new front-end themes & templates
|
||||
$NEXTPREV_TEMPLATE['default_nav_caption'] = NP_3.' ';
|
||||
|
||||
$NEXTPREV_TEMPLATE['dropdown_nav_first'] = '';
|
||||
$NEXTPREV_TEMPLATE['dropdown_nav_last'] = '';
|
||||
|
||||
// 'tbox npbutton' classes are deprecated!!!
|
||||
$NEXTPREV_TEMPLATE['dropdown_nav_prev'] = '<a class="nextprev-item prev tbox npbutton" href="{url}" title="{url_label}">{label}</a>';
|
||||
// 'tbox npbutton' classes are deprecated!!!
|
||||
$NEXTPREV_TEMPLATE['dropdown_nav_next'] = '<a class="nextprev-item next tbox npbutton" href="{url}" title="{url_label}">{label}</a>';
|
||||
|
||||
// 'npdropdown' class is deprecated!!!
|
||||
$NEXTPREV_TEMPLATE['dropdown_items_start'] = '<select class="tbox npdropdown nextprev-select" name="pageSelect" onchange="window.location.href=this.options[selectedIndex].value">';
|
||||
$NEXTPREV_TEMPLATE['dropdown_item'] = '<option value="{url}">{label}</option>';
|
||||
$NEXTPREV_TEMPLATE['dropdown_item_current'] = '<option value="{url}" selected="selected">{label}</option>';
|
||||
$NEXTPREV_TEMPLATE['dropdown_items_end'] = '</select>';
|
||||
|
||||
//$NEXTPREV_TEMPLATE['dropdown_separator'] = '<span class="nextprev-sep"><!-- --></span>';
|
||||
$NEXTPREV_TEMPLATE['dropdown_separator'] = ' ';
|
||||
|
||||
?>
|
Loading…
x
Reference in New Issue
Block a user