Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added "path" as a custom pageNavScheme #30

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion _build/properties/properties.getpage.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,25 @@
'type' => 'textfield',
'options' => '',
'value' => '',
),array(
'name' => 'pathUrlSeparator',
'desc' => 'If you use "path" as pageNavScheme this sets the separator between the resources URI and the pagination path.',
'type' => 'textfield',
'options' => '',
'value' => '/',
),array(
'name' => 'pathNumberSeparator',
'desc' => 'Separator between pageVarKey and page number if you use "path" as pageNavScheme.',
'type' => 'textfield',
'options' => '',
'value' => '-',
),array(
'name' => 'pathHidePageVarKey',
'desc' => 'Optionally hide the pageVarKey from the pagination path',
'type' => 'combo-boolean',
'options' => '',
'value' => false,
)
);

return $properties;
return $properties;
25 changes: 21 additions & 4 deletions core/components/getpage/include.getpage.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,30 @@ function getpage_buildControls(& $modx, $properties) {

function getpage_makeUrl(& $modx, $properties, $pageNo, $tpl) {
$qs = $properties['qs'];
if ($pageNo === 1) {
$scheme = !empty($properties['pageNavScheme']) ? $properties['pageNavScheme'] : $modx->getOption('link_tag_scheme', $properties, -1);

if ($properties['pageNavScheme'] === 'path') {

unset($qs[$properties['pageVarKey']]);
$properties['href'] = $modx->makeUrl($modx->resource->get('id'), '', '', $modx->getOption('link_tag_scheme', $properties, -1));
if ($pageNo !== 1) {
$properties['href'] = rtrim($properties['href'], '/').$properties['pathUrlSeparator'];
if (!$properties['pathHidePageVarKey']) $properties['href'] .= $properties['pageVarKey'].$properties['pathNumberSeparator'];
$properties['href'] .= $pageNo;
}
if (!empty($qs)) $properties['href'] .= '?'. http_build_query($qs);

} else {
$qs[$properties['pageVarKey']] = $pageNo;

if ($pageNo === 1) {
unset($qs[$properties['pageVarKey']]);
} else {
$qs[$properties['pageVarKey']] = $pageNo;
}
$properties['href'] = $modx->makeUrl($modx->resource->get('id'), '', $qs, $scheme);

}
$scheme = !empty($properties['pageNavScheme']) ? $properties['pageNavScheme'] : $modx->getOption('link_tag_scheme', $properties, -1);
$properties['href'] = $modx->makeUrl($modx->resource->get('id'), '', $qs, $scheme);

$properties['pageNo'] = $pageNo;
$nav= $modx->newObject('modChunk')->process($properties, $tpl);
return $nav;
Expand Down
3 changes: 3 additions & 0 deletions core/components/getpage/snippet.getpage.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
$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['pathUrlSeparator'] = !isset($pathUrlSeparator) ? "/" : $pathUrlSeparator;
$properties['pathNumberSeparator'] = !isset($pathNumberSeparator) ? "-" : $pathNumberSeparator;
$properties['pathHidePageVarKey'] = !isset($pathHidePageVarKey) ? false : $pathHidePageVarKey;
$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