Плагин MODX Revolution для разбития длинного текста на страницы

Текст между <!– content –> будет разбит на страницы с навигацией внизу. Считает количество <p. На каждой страницы 30 ($count_delimiter_per_page=30;)  знаков <p ($delimiter = ‘<p’;)

 

## CUSTOMIZE ##
$separator = ‘<!– content –>’;
$delimiter = ‘<p’;
$count_delimiter_per_page=30;
/* sample 1 */
/*
$tplLinkNext = ‘<a href=”[[+link]]”>Next page</a>’;
$tplLinkPrev = ‘<a href=”[[+link]]”>Prev page</a>’;
$tplLinkNav = ‘
<div style=”margin-top:1.2em;font-size:.9em; text-align:center”>
[[+linkprev]]
 Page [[+current]] of [[+total]] 
[[+linknext]]
</div>’;
*/
/* sample 2 */
$tplLinkNext = ‘<a href=”[[+link]]”>Next</a>’;
$tplLinkPrev = ‘<a href=”[[+link]]”>Prev</a>’;
$tplLinkNav = ‘<div style=”margin-top:1.2em;font-size:.9em; text-align:center”>
Pages: 
[[+linkprev]]
 [[+pages]] 
[[+linknext]]
</div>’;

## DO NOT EDIT BELOW THIS LINE ##
/*
$e = &$modx->Event;

switch($e->name) {
case ‘OnWebPagePrerender’:
*/

switch ($modx->event->name) {
case ‘OnWebPagePrerender’:
$all_content = explode($separator,$modx->resource->_output);

if (count($all_content) > 2) {$pip_content = $all_content[1];}
else {return;}

$pip_content_p = explode($delimiter,$pip_content);
$pip_content_first = array_shift($pip_content_p);
$pip_pagecount=ceil(count($pip_content_p)/$count_delimiter_per_page);

if ($pip_pagecount > 1)
{
$pip_currentpage = isset($_GET['page']) ? intval($_GET['page']): 1;
if ($pip_currentpage > $pip_pagecount || $pip_currentpage < 1) { $pip_currentpage = 1; }

$char = ($modx->config['friendly_urls'] == 0) ? “&” : “?”;
/* $url = $modx->makeurl($modx->documentObject['id'],”,$char.’page=’);*/
$url = $modx->makeurl($modx->resource->get(‘id’),”,$char.’page=’);

$prevpage = $pip_currentpage-1;
$nextpage = $pip_currentpage+1;
$linkprev = ($prevpage>0) ? str_replace(‘[[+link]]’,$url.$prevpage,$tplLinkPrev) : ”;
$linknext = ($nextpage>$pip_pagecount) ? ” : str_replace(“[[+link]]”,$url.$nextpage,$tplLinkNext);

$pip_template = str_replace(‘[[+linkprev]]’,$linkprev,$tplLinkNav);
$pip_template = str_replace(‘[[+linknext]]’,$linknext,$pip_template);
$pip_template = str_replace(‘[[+total]]’,$pip_pagecount,$pip_template);
$pip_template = str_replace(‘[[+current]]’,$pip_currentpage,$pip_template);

$pages=”;
for ($i=1;$i<=$pip_pagecount;$i++){
$pages .= ($i==$pip_currentpage) ? $i : ‘<a href=”‘.$url.$i.’”>’.$i.’</a>’;
$pages .= ($i==$pip_pagecount) ? ” : ‘ | ‘;
}
$pip_template=str_replace(‘[[+pages]]’,$pages,$pip_template);

$pip_content_p=array_slice($pip_content_p,$count_delimiter_per_page*$pip_currentpage-$count_delimiter_per_page,$count_delimiter_per_page);
$all_content[1]= (($pip_currentpage==1)?$pip_content_first:”).$delimiter.implode($delimiter,$pip_content_p).$pip_template;
$modx->resource->_output=implode(”,$all_content);
}

break;
}
return;
/*
break;
default:
return;
break;
}
*/

Leave a Reply