Once again, I require help from the brightest people on the internet. What this plugin does is it paginates content but the problem is it strips away all the <p> tags from the content.
class Pagination
{
var $return_data = "";
function Pagination()
{
global $TMPL, $SESS, $FNS;
$page = '';
// Search for {pagination} tags in case the user wants prev / next page links
$pagination_regex = '!{simplepaginate}(.*){/simplepaginate}!Usi';
$pagination_enabled = preg_match_all($pagination_regex, $TMPL->tagdata, $pagination_content, PREG_PATTERN_ORDER);
if($pagination_enabled == 0) {
// The user has added no {pagination} tags so there's no need to do anything here.
}
else {
// Remove {pagination} tags from the markup
$TMPL->tagdata = preg_replace($pagination_regex, '', $TMPL->tagdata);
}
// Create an array of the pages
$data = explode('{pagebreak}', $TMPL->tagdata);
$number_pages = count($data);
// No pagebreaks? Return the data as-is
if($number_pages == 1) {
$this->return_data = $data[0];
return;
}
// Determine which page to display based on current url
// Start by determining the last segment of the url
$trackerdata = trim($SESS->tracker['0'], '/'); // remove beginning and trailing slashes
$location = explode('/', $trackerdata);
$url_segments = count($location);
$final_segment = $location[$url_segments - 1]; // determine the last segment of the url
// Does the last segment refer to a specific page?
if( preg_match('/^[P][0-9]+$/i', $final_segment) ) {
// We need a specific page - which?
$selected_page = substr($final_segment, 1);
if( array_key_exists($selected_page - 1, $data) ) {
// EE confuses pagebreaks with paragraphs, so some unwanted p tags may need to go
[COLOR="#ff0000"]$selected_page_data = $this->PageTidy($data[$selected_page - 1]);[/COLOR]
$page .= $selected_page_data;
}
else {
$this->return_data = "<strong>Error: This page does not appear to exist.</strong>
";
return;
}
// Determine the base URL of the overall document
$pagenav_url = '';
foreach($location as $key => $val) {
if($val != $final_segment) {
$pagenav_url .= $val . "/";
}
}
$document_root = $FNS->create_url( "/".$pagenav_url );
// What would the next and previous page's URL be?
$nextpagenum = $selected_page + 1;
$prevpagenum = $selected_page - 1;
$nextpage = $FNS->create_url( "/".$pagenav_url."P".$nextpagenum."/" );
if($prevpagenum > 1) { // other pages need the number appended
$prevpage = $document_root."P".$prevpagenum."/";
}
else { // no need for 'p1' to be appended to the url
$prevpage = $document_root;
}
}
else {
// No page requested in the url; print page 1
$selected_page = 1;
[COLOR="#ff0000"]$page .= $this->PageTidy($data[0]);[/COLOR]
// What would the next and previous page's URL be?
$document_root = $FNS->create_url($SESS->tracker['0']);
$nextpage = $document_root."P2/";
$prevpage = '';
}
// Print pagination links if requested
if($pagination_enabled) {
$pagination_data = '';
$pagination_links = '';
foreach($pagination_content[1] as $key => $val) {
// Replace variables
$total_pages = count($data);
$val = str_replace('{current_page}', $selected_page, $val);
$val = str_replace('{total_pages}', $total_pages, $val);
$val = str_replace('{previous_auto_path}', $prevpage, $val);
$val = str_replace('{next_auto_path}', $nextpage, $val);
// Do we need to generate complex pagination links? (i.e. « First < 11 12 13 14 15 > Last »)
// (Replace this with a single function in the future)
if(strpos($val, '{pagination_links}')) {
if($selected_page > 1 AND $total_pages > 3) { // Show first page link
$pagination_links .= "<a href=\"".$document_root."\">« First</a>
";
}
$previous_page_num = $selected_page - 1;
if( $previous_page_num > 0 ) { // Previous page link
$pagination_links .= "<a href=\"".$document_root."P".$previous_page_num."/\"><</a>
";
}
$two_pages_back_num = $selected_page - 2;
if( $two_pages_back_num > 0 ) { // Selected page - 2 link
$pagination_links .= "<a href=\"".$document_root."P".$two_pages_back_num."/\">".$two_pages_back_num."</a>
";
}
if( $previous_page_num > 0 ) { // Selected page - 1 link
$pagination_links .= "<a href=\"".$document_root."P".$previous_page_num."/\">".$previous_page_num."</a>
";
}
// Current page
$pagination_links .= "<strong>".$selected_page."</strong>
";
$next_page_num = $selected_page + 1;
if( $next_page_num <= $total_pages ) { // Selected page + 1 link
$pagination_links .= "<a href=\"".$document_root."P".$next_page_num."/\">".$next_page_num."</a>
";
}
$two_pages_forward_num = $selected_page + 2;
if( $two_pages_forward_num <= $total_pages ) { // Selected page + 2 link
$pagination_links .= "<a href=\"".$document_root."P".$two_pages_forward_num."/\">".$two_pages_forward_num."</a>
";
}
if( $next_page_num <= $total_pages ) { // Next page link
$pagination_links .= "<a href=\"".$document_root."P".$next_page_num."/\">></a>
";
}
if($selected_page < $total_pages AND $total_pages > 3) { // Final page link
$pagination_links .= "<a href=\"".$document_root."P".$total_pages."/\">Last »</a>
";
}
$val = str_replace('{pagination_links}', $pagination_links, $val);
}
if($selected_page < count($data)) {
// the next page link should appear if the markup is there
$val = preg_replace('!{if next_page}(.*){/if}!Usi', '\\1', $val);
}
if($selected_page > 1) {
// show the previous page link
$val = preg_replace('!{if previous_page}(.*){/if}!Usi', '\\1', $val);
}
$pagination_data .= $val;
}
// Place the pagination links in the markup
switch( $TMPL->fetch_param('paginate') ) {
case '': // defaults to bottom
case 'bottom':
$page = $page . $val;
break;
case 'top':
$page = $val . $page;
break;
case 'both':
$page = $val . $page . $val;
}
}
$this->return_data = $page;
}
// An internal function which removes unwanted paragraph tags from pages
[COLOR="Red"] function PageTidy($data) {
$data = trim($data);
if( substr($data, -3, 3) == '<p>' ) { // remove trailing <p> tag
$data = substr($data, 0, strlen($data) - 3);
}
if( substr($data, 0, 4) == '</p>' ) { // remove </p> prefix
$data = substr($data, 4, strlen($data));
}[/COLOR]
return $data;
}
I can’t seem to stop this plugin from removing the tags. I tried getting rid of the function and all of it’s instance but no luck. Thank you for looking at it.