I wrote a function in an article override to search a folder for images and create a pagebreak behavior per image in an article. All works fine except for a 404 error being returned for each pagination link.
I determined that the error is caused by Joomla's pagebreak content plugin pagebreak.php where the condition is:
if (StringHelper::strpos($row->text, 'class="system-pagebreak') === false)
{
if ($page > 0)
{
throw new Exception(JText::_('JERROR_PAGE_NOT_FOUND'), 404);
}
return true;
}
If I comment out the line throw new Exception(JText::_('JERROR_PAGE_NOT_FOUND'), 404); or disable the plugin the process works perfectly. However, being that the file is subject to overwriting on updates, that is not an ideal option.
My code is:
$pagebreak='';
if(preg_match('#\{pagebreakgallery=\"(.*?)\"\}#i', $item->text, $folder))
{
$imagesDir = JPATH_ROOT.'/images/photogallery/'.$folder[1].'/';
$images = str_replace(JPATH_ROOT, Juri::root(true), glob($imagesDir . '*.{jpg,jpeg,png,gif}', GLOB_BRACE));
foreach($images as $image) {
$page_break[] = '<img src="'.$image.'" />';
}
$item->text = str_replace($folder[0], '', $item->text);
$pagenum = 0;
if($app->input->get('start') != '')
$pagenum = $app->input->getInt('start');
$pages = count($page_break);
if($pages > 0)
{
$pagelinks = new JPagination($pages, $pagenum, 1);
$pagebreak .= $page_break[$pagenum];
$pagebreak .= '
<div class="paging">
<div class="pagecount">' . $pagelinks->getPagesCounter() . '</div>
<div class="pager">' . $pagelinks->getPagesLinks() . '</div>
</div>
';
}
}
How can I resolve this error occurrence?