Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #1 from Mav/master

New link formatting options for Pager
  • Loading branch information...
commit b63ad272ab1c2ea5e524fd72dbb4cdafd727bb93 2 parents 53ad625 + f58be5b
@quipo quipo authored
View
56 Common.php
@@ -287,6 +287,33 @@ class Pager_Common
var $_spacesAfterSeparator = 1;
/**
+ * @var string HTML tag to wrap each page link
+ * (use 'li' for pagination in a list)
+ * @access private
+ */
+ var $_linkContainer = '';
+
+ /**
+ * @var string HTML tag used to combine _linkContainer and _curLinkContainerClassName
+ * @access private
+ */
+ var $_linkContainerPre = '';
+
+ /**
+ * @var string CSS class name for linkContainer
+ * @access private
+ */
+ var $_curLinkContainerClassName = '';
+
+ /**
+ * @var string HTML tag to wrap current page link
+ * (use 'a' to keep it like all other links and set a class with $_curPageLinkClassName)
+ * defaults to 'span' for backwards compatibility
+ * @access private
+ */
+ var $_curTag = 'span';
+
+ /**
* @var string CSS class name for current page link
* @access private
*/
@@ -483,6 +510,9 @@ class Pager_Common
'separator',
'spacesBeforeSeparator',
'spacesAfterSeparator',
+ 'linkContainer',
+ 'curLinkContainerClassName',
+ 'curTag',
'curPageLinkClassName',
'curPageSpanPre',
'curPageSpanPost',
@@ -838,27 +868,31 @@ function _renderLink($altText, $linkText)
if (array_key_exists($this->_urlVar, $this->_linkData)) {
$onclick = str_replace('%d', $this->_linkData[$this->_urlVar], $this->_onclick);
}
- return sprintf('<a href="%s"%s%s%s%s title="%s">%s</a>',
+ return sprintf('%s<a href="%s"%s%s%s%s title="%s">%s</a>%s',
+ empty($this->_linkContainer) ? '' : '<'.$this->_linkContainer.'>',
htmlentities($this->_url . $href, ENT_COMPAT, 'UTF-8'),
empty($this->_classString) ? '' : ' '.$this->_classString,
empty($this->_attributes) ? '' : ' '.$this->_attributes,
empty($this->_accesskey) ? '' : ' accesskey="'.$this->_linkData[$this->_urlVar].'"',
empty($onclick) ? '' : ' onclick="'.$onclick.'"',
$altText,
- $linkText
+ $linkText,
+ empty($this->_linkContainer) ? '' : '</'.$this->_linkContainer.'>'
);
} elseif ($this->_httpMethod == 'POST') {
$href = $this->_url;
if (!empty($_GET)) {
$href .= '?' . $this->_http_build_query_wrapper($_GET);
}
- return sprintf("<a href='javascript:void(0)' onclick='%s'%s%s%s title='%s'>%s</a>",
+ return sprintf("%s<a href='javascript:void(0)' onclick='%s'%s%s%s title='%s'>%s</a>%s",
+ empty($this->_linkContainer) ? '' : '<'.$this->_linkContainer.'>',
$this->_generateFormOnClick($href, $this->_linkData),
empty($this->_classString) ? '' : ' '.$this->_classString,
empty($this->_attributes) ? '' : ' '.$this->_attributes,
empty($this->_accesskey) ? '' : ' accesskey=\''.$this->_linkData[$this->_urlVar].'\'',
$altText,
- $linkText
+ $linkText,
+ empty($this->_linkContainer) ? '' : '<'.$this->_linkContainer.'>'
);
}
return '';
@@ -1593,9 +1627,17 @@ function setOptions($options)
$this->_classString = 'class="'.$this->_linkClass.'"';
}
- if (strlen($this->_curPageLinkClassName)) {
- $this->_curPageSpanPre .= '<span class="'.$this->_curPageLinkClassName.'">';
- $this->_curPageSpanPost = '</span>' . $this->_curPageSpanPost;
+ if (strlen($this->_linkContainer)) {
+ $this->_linkContainerPre .= empty($this->_curLinkContainerClassName) ? $this->_linkContainer : $this->_linkContainer . ' class="'.$this->_curLinkContainerClassName.'"';
+ }
+
+ if (strlen($this->_curTag)) {
+ if (strlen($this->_curPageLinkClassName)) {
+ $this->_curPageSpanPre = '<' . $this->_curTag . ' class="'.$this->_curPageLinkClassName.'">' . $this->_curPageSpanPre;
+ }else{
+ $this->_curPageSpanPre = '<' . $this->_curTag . '>' . $this->_curPageSpanPre;
+ }
+ $this->_curPageSpanPost = $this->_curPageSpanPost . '</' . $this->_curTag . '>';
}
$this->_perPage = max($this->_perPage, 1); //avoid possible user errors
View
6 Jumping.php
@@ -247,7 +247,11 @@ function _getPageLinks($url = '')
$links .= $this->_renderLink(str_replace('%d', $i, $this->_altPage), $i);
} else {
$this->range[$i] = true;
- $links .= $this->_curPageSpanPre . $i . $this->_curPageSpanPost;
+ if (!empty($this->_linkContainer)) {
+ $links .= '<'.$this->_linkContainerPre.'>' . $this->_curPageSpanPre . $i . $this->_curPageSpanPost . '</'.$this->_linkContainer.'>';
+ } else {
+ $links .= $this->_curPageSpanPre . $i . $this->_curPageSpanPost;
+ }
}
$links .= $this->_spacesBefore
. (($i != $this->_totalPages) ? $this->_separator.$this->_spacesAfter : '');
View
12 Sliding.php
@@ -256,7 +256,11 @@ function _getPageLinks($url = '')
if ($i == $this->_currentPage) {
$this->range[$i] = true;
- $links .= $this->_curPageSpanPre . $i . $this->_curPageSpanPost;
+ if (!empty($this->_linkContainer)) {
+ $links .= '<'.$this->_linkContainerPre.'>' . $this->_curPageSpanPre . $i . $this->_curPageSpanPost . '</'.$this->_linkContainer.'>';
+ } else {
+ $links .= $this->_curPageSpanPre . $i . $this->_curPageSpanPost;
+ }
} else {
$this->range[$i] = false;
$this->_linkData[$this->_urlVar] = $i;
@@ -287,7 +291,11 @@ function _getPageLinks($url = '')
$links .= $this->_renderLink(str_replace('%d', $i, $this->_altPage), $i);
} else {
$this->range[$i] = true;
- $links .= $this->_curPageSpanPre . $i . $this->_curPageSpanPost;
+ if (!empty($this->_linkContainer)) {
+ $links .= '<'.$this->_linkContainerPre.'>' . $this->_curPageSpanPre . $i . $this->_curPageSpanPost . '</'.$this->_linkContainer.'>';
+ } else {
+ $links .= $this->_curPageSpanPre . $i . $this->_curPageSpanPost;
+ }
}
$links .= $this->_spacesBefore
. (($i != $this->_totalPages) ? $this->_separator.$this->_spacesAfter : '');
View
113 examples/example_unordered_list.php
@@ -0,0 +1,113 @@
+<?php
+require_once 'Pager/Pager.php';
+
+//create dummy array of data
+$myData = array();
+for ($i=0; $i<200; $i++) {
+ $myData[] = $i;
+}
+
+$params = array(
+ 'itemData' => $myData,
+ 'perPage' => 10,
+ 'delta' => 8, // for 'Jumping'-style a lower number is better
+ 'append' => true,
+ 'clearIfVoid' => false,
+ 'urlVar' => 'entrant',
+ 'useSessions' => true,
+ 'closeSession' => true,
+ //'mode' => 'Sliding', //try switching modes
+ 'mode' => 'Jumping',
+ 'prevImg' => '« Previous',
+ 'nextImg' => ' Next »',
+//settings best used for lists:
+ 'separator' => '', //you shouldn't use &nbsp; anywhere, especially in lists
+ 'spacesBeforeSeparator' => 0, //or spaces
+ 'spacesAfterSeparator' => 0,
+ 'linkContainer' => 'li', //default is nothing, now optionally wraps links with a html tag
+ 'curLinkContainerClassName' => 'active', //if you want <li class="active"><a>page#</a></li>
+ 'curTag' => 'a', //default is span as that's what it used to be, now it's changeable
+ //'curPageLinkClassName' => 'active', //if you want <li><a class="active">page#</a></li> instead of using curLinkContainerClassName
+);
+$pager = & Pager::factory($params);
+$page_data = $pager->getPageData();
+$links = $pager->getLinks();
+
+$selectBox = $pager->getPerPageSelectBox();
+?>
+
+<html>
+<head>
+<title>new PEAR::Pager example using a list</title>
+<style>
+ul.pagination li {display:inline; margin:3px;}
+ul.pagination li a {
+ display: inline-block;
+ margin: 0;
+ padding:2px 5px;
+ border:1px solid #000000;
+ background-color:#EEEEEE;
+ color:#000;
+ text-decoration: none;
+ font-size:11px;
+ font-weight:bold;
+}
+ul.pagination li.active a {
+ color: white;
+ border:1px solid black;
+ background-color:maroon;
+ cursor:pointer;
+}
+ul.pagination li a:hover {
+ color: maroon;
+ border:1px solid maroon;
+ background-color:#FFFFE0;
+}
+</style>
+</head>
+<body>
+
+<table border="1" width="500" summary="example 1">
+ <tr>
+ <td colspan="3" align="center">
+ <ul class="pagination">
+ <?php echo $links['all']; ?>
+ </ul>
+ </td>
+ </tr>
+
+
+ <tr>
+ <td colspan="3">
+ <pre><?php print_r($page_data); ?></pre>
+ </td>
+ </tr>
+</table>
+
+<h4>Results from methods:</h4>
+
+<pre>
+getCurrentPageID()...: <?php var_dump($pager->getCurrentPageID()); ?>
+getNextPageID()......: <?php var_dump($pager->getNextPageID()); ?>
+getPreviousPageID()..: <?php var_dump($pager->getPreviousPageID()); ?>
+numItems()...........: <?php var_dump($pager->numItems()); ?>
+numPages()...........: <?php var_dump($pager->numPages()); ?>
+isFirstPage()........: <?php var_dump($pager->isFirstPage()); ?>
+isLastPage().........: <?php var_dump($pager->isLastPage()); ?>
+isLastPageComplete().: <?php var_dump($pager->isLastPageComplete()); ?>
+$pager->range........: <?php var_dump($pager->range); ?>
+</pre>
+
+
+<hr />
+
+<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="GET">
+Select how many items per page should be shown:<br />
+<?php echo $selectBox; ?> &nbsp;
+<input type="submit" value="submit" />
+</form>
+
+<hr />
+
+</body>
+</html>

1 comment on commit b63ad27

@cokegen

THANK YOU ;-) I needed this mod to use Pager with the pagination component of Twitter Bootstrap.

Please sign in to comment.
Something went wrong with that request. Please try again.