Skip to content

Commit

Permalink
getPage 1.2.0-pl
Browse files Browse the repository at this point in the history
Merge branch 'release-1.2'

* release-1.2:
  Bump version for 2.1.0-pl release
  [#5] Add pageNavOuterTpl for layout control of page nav elements
  Small fixes to allow limit=0
  Allow unlimited pages listing.   Snippet call: &pageLimit=`0`
  Allow *Tpl parameters to be empty in snippet call.
  • Loading branch information
opengeek committed Sep 14, 2011
2 parents e25114c + f804645 commit d33e084
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 16 deletions.
2 changes: 1 addition & 1 deletion _build/build.transport.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

/* package defines */
define('PKG_NAME','getPage');
define('PKG_VERSION','1.1.0');
define('PKG_VERSION','1.2.0');
define('PKG_RELEASE','pl');
define('PKG_LNAME',strtolower(PKG_NAME));

Expand Down
7 changes: 7 additions & 0 deletions _build/properties/properties.getpage.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,13 @@
'options' => '',
'value' => '<li[[+classes]]><a[[+classes]][[+title]] href="[[+href]]">[[+pageNo]]</a></li>',
)
,array(
'name' => 'pageNavOuterTpl',
'desc' => 'Content representing the layout of the page navigation controls.',
'type' => 'textfield',
'options' => '',
'value' => '[[+first]][[+prev]][[+pages]][[+next]][[+last]]',
)
,array(
'name' => 'pageActiveTpl',
'desc' => 'Content representing the current page navigation control.',
Expand Down
7 changes: 7 additions & 0 deletions core/components/getpage/docs/changelog.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
Changelog for getPage.

getPage 1.2.0-pl (September 14, 2011)
====================================
- [#5] Add pageNavOuterTpl for layout control of page nav elements
- Allow limit of 0 in $_REQUEST to bypass paging
- Allow empty nav tpl parameters
- Allow unlimited page listing with &pageLimit=`0`

getPage 1.1.0-pl (March 27, 2011)
====================================
- Change default cacheKey property to use 'resource' (for MODX 2.1+)
Expand Down
2 changes: 1 addition & 1 deletion core/components/getpage/docs/readme.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
--------------------
Snippet: getPage
--------------------
Version: 1.1.0-pl
Version: 1.2.0-pl
Since: March 19, 2010
Author: Jason Coward <[email protected]>

Expand Down
10 changes: 6 additions & 4 deletions core/components/getpage/include.getpage.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@ function getpage_buildControls(& $modx, $properties) {
$nav['prev'] = getpage_makeUrl($modx, $properties, $page - 1, $pagePrevTpl);
}
}
if ($i >= $page - $pageLimit && $i <= $page + $pageLimit) {
if (empty($pageLimit) || ($i >= $page - $pageLimit && $i <= $page + $pageLimit)) {
if (!array_key_exists('pages', $nav)) $nav['pages'] = array();
if ($i == $page) {
$nav[$i] = getpage_makeUrl($modx, $properties, $i, $pageActiveTpl);
$nav['pages'][$i] = getpage_makeUrl($modx, $properties, $i, $pageActiveTpl);
} else {
$nav[$i] = getpage_makeUrl($modx, $properties, $i, $pageNavTpl);
$nav['pages'][$i] = getpage_makeUrl($modx, $properties, $i, $pageNavTpl);
}
}
if ($i == $pageCount && $i != $page && !empty($pageLastTpl)) {
Expand All @@ -31,8 +32,9 @@ function getpage_buildControls(& $modx, $properties) {
$nav['last'] = getpage_makeUrl($modx, $properties, $i, $pageLastTpl);
}
}
$nav['pages'] = implode("\n", $nav['pages']);
}
return implode("\n", $nav);
return $nav;
}

function getpage_makeUrl(& $modx, $properties, $pageNo, $tpl) {
Expand Down
23 changes: 13 additions & 10 deletions core/components/getpage/snippet.getpage.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,21 @@

$properties =& $scriptProperties;
$properties['page'] = (isset($_REQUEST[$properties['pageVarKey']]) && ($page = intval($_REQUEST[$properties['pageVarKey']]))) ? $page : 1;
$properties['limit'] = (!empty($_REQUEST['limit']) && ($limit = intval($_REQUEST['limit']))) ? $limit : intval($limit);
$properties['limit'] = (isset($_REQUEST['limit'])) ? intval($_REQUEST['limit']) : intval($limit);
$properties['offset'] = (!empty($properties['limit']) && !empty($properties['page'])) ? ($properties['limit'] * ($properties['page'] - 1)) : 0;
$properties['totalVar'] = empty($totalVar) ? "total" : $totalVar;
$properties['total'] = !empty($properties['total']) && $total = intval($properties['total']) ? $total : 0;
$properties['pageLimit'] = !empty($pageLimit) && ($pageLimit = intval($pageLimit)) ? $pageLimit : 5;
$properties['pageLimit'] = isset($pageLimit) && is_numeric($pageLimit) ? intval($pageLimit) : 5;
$properties['element'] = empty($element) ? '' : $element;
$properties['elementClass'] = empty($elementClass) ? 'modChunk' : $elementClass;
$properties['pageNavVar'] = empty($pageNavVar) ? 'page.nav' : $pageNavVar;
$properties['pageNavTpl'] = empty($pageNavTpl) ? "<li[[+classes]]><a[[+classes]][[+title]] href=\"[[+href]]\">[[+pageNo]]</a></li>" : $pageNavTpl;
$properties['pageActiveTpl'] = empty($pageActiveTpl) ? "<li[[+activeClasses:default=` class=\"active\"`]]><a[[+activeClasses:default=` class=\"active\"`]][[+title]] href=\"[[+href]]\">[[+pageNo]]</a></li>" : $pageActiveTpl;
$properties['pageFirstTpl'] = empty($pageFirstTpl) ? "<li class=\"control\"><a[[+title]] href=\"[[+href]]\">First</a></li>" : $pageFirstTpl;
$properties['pageLastTpl'] = empty($pageLastTpl) ? "<li class=\"control\"><a[[+title]] href=\"[[+href]]\">Last</a></li>" : $pageLastTpl;
$properties['pagePrevTpl'] = empty($pagePrevTpl) ? "<li class=\"control\"><a[[+title]] href=\"[[+href]]\">&lt;&lt;</a></li>" : $pagePrevTpl;
$properties['pageNextTpl'] = empty($pageNextTpl) ? "<li class=\"control\"><a[[+title]] href=\"[[+href]]\">&gt;&gt;</a></li>" : $pageNextTpl;
$properties['pageNavTpl'] = !isset($pageNavTpl) ? "<li[[+classes]]><a[[+classes]][[+title]] href=\"[[+href]]\">[[+pageNo]]</a></li>" : $pageNavTpl;
$properties['pageNavOuterTpl'] = !isset($pageNavOuterTpl) ? "[[+first]][[+prev]][[+pages]][[+next]][[+last]]" : $pageNavOuterTpl;
$properties['pageActiveTpl'] = !isset($pageActiveTpl) ? "<li[[+activeClasses:default=` class=\"active\"`]]><a[[+activeClasses:default=` class=\"active\"`]][[+title]] href=\"[[+href]]\">[[+pageNo]]</a></li>" : $pageActiveTpl;
$properties['pageFirstTpl'] = !isset($pageFirstTpl) ? "<li class=\"control\"><a[[+title]] href=\"[[+href]]\">First</a></li>" : $pageFirstTpl;
$properties['pageLastTpl'] = !isset($pageLastTpl) ? "<li class=\"control\"><a[[+title]] href=\"[[+href]]\">Last</a></li>" : $pageLastTpl;
$properties['pagePrevTpl'] = !isset($pagePrevTpl) ? "<li class=\"control\"><a[[+title]] href=\"[[+href]]\">&lt;&lt;</a></li>" : $pagePrevTpl;
$properties['pageNextTpl'] = !isset($pageNextTpl) ? "<li class=\"control\"><a[[+title]] href=\"[[+href]]\">&gt;&gt;</a></li>" : $pageNextTpl;
$properties['toPlaceholder'] = !empty($toPlaceholder) ? $toPlaceholder : '';
$properties['cache'] = isset($cache) ? (boolean) $cache : (boolean) $modx->getOption('cache_resource', null, false);
if (empty($cache_key)) $properties[xPDO::OPT_CACHE_KEY] = $modx->getOption('cache_resource_key', null, 'resource');
Expand Down Expand Up @@ -63,7 +64,9 @@
if (empty($properties['total']) || empty($properties['limit']) || $properties['total'] <= $properties['limit']) {
$properties['page'] = 1;
} else {
$properties[$properties['pageNavVar']] = getpage_buildControls($modx, $properties);
$pageNav = getpage_buildControls($modx, $properties);
var_dump($pageNav);
$properties[$properties['pageNavVar']] = $modx->newObject('modChunk')->process(array_merge($properties, $pageNav), $properties['pageNavOuterTpl']);
if ($properties['page'] > 1) {
$qs[$properties['pageVarKey']] = $properties['page'];
}
Expand All @@ -87,4 +90,4 @@
$output = '';
}

return $output;
return $output;

0 comments on commit d33e084

Please sign in to comment.