registerEvent( 'onPrepareContent', 'plgContentPagebreak' ); /** * Page break plugin * * Usage: *
*
* or *
* or *
* or *
* */ function plgContentPagebreak( &$row, &$params, $page=0 ) { // expression to search for $regex = '#]*?)class=(\"|\')system-pagebreak(\"|\')([^>]*?)\/*>#iU'; // Get Plugin info $plugin =& JPluginHelper::getPlugin('content', 'pagebreak'); $pluginParams = new JParameter( $plugin->params ); $print = JRequest::getBool('print'); $showall = JRequest::getBool('showall'); if (!$pluginParams->get('enabled', 1)) { $print = true; } if ($print) { $row->text = preg_replace( $regex, '
', $row->text ); return true; } //simple performance check to determine whether bot should process further if ( strpos( $row->text, 'class="system-pagebreak' ) === false && strpos( $row->text, 'class=\'system-pagebreak' ) === false ) { return true; } $db =& JFactory::getDBO(); $view = JRequest::getCmd('view'); if(!$page) { $page = 0; } // check whether plugin has been unpublished if (!JPluginHelper::isEnabled('content', 'pagebreak') || $params->get( 'intro_only' )|| $params->get( 'popup' ) || $view != 'article') { $row->text = preg_replace( $regex, '', $row->text ); return; } // find all instances of plugin and put in $matches $matches = array(); preg_match_all( $regex, $row->text, $matches, PREG_SET_ORDER ); if (($showall && $pluginParams->get('showall', 1) )) { $hasToc = $pluginParams->get( 'multipage_toc', 1 ); if ( $hasToc ) { // display TOC $page = 1; plgContentCreateTOC( $row, $matches, $page ); } else { $row->toc = ''; } $row->text = preg_replace( $regex, '
', $row->text ); return true; } // split the text around the plugin $text = preg_split( $regex, $row->text ); // count the number of pages $n = count( $text ); // we have found at least one plugin, therefore at least 2 pages if ($n > 1) { // Get plugin parameters $pluginParams = new JParameter( $plugin->params ); $title = $pluginParams->get( 'title', 1 ); $hasToc = $pluginParams->get( 'multipage_toc', 1 ); // adds heading or title to Title if ( $title ) { if ( $page ) { $page_text = $page + 1; if ( $page && @$matches[$page-1][2] ) { $attrs = JUtility::parseAttributes($matches[$page-1][1]); if ( @$attrs['title'] ) { $row->page_title = $attrs['title']; } } } } // reset the text, we already hold it in the $text array $row->text = ''; // display TOC if ( $hasToc ) { plgContentCreateTOC( $row, $matches, $page ); } else { $row->toc = ''; } // traditional mos page navigation jimport('joomla.html.pagination'); $pageNav = new JPagination( $n, $page, 1 ); // page counter $row->text .= ''; // page text $text[$page] = str_replace("
", "", $text[$page]); $row->text .= $text[$page]; $row->text .= '
'; $row->text .= '
'; } return true; } function plgContentCreateTOC( &$row, &$matches, &$page ) { $heading = $row->title; // TOC Header $row->toc = ' '; // TOC First Page link $row->toc .= ' '; $i = 2; foreach ( $matches as $bot ) { $link = JRoute::_( '&showall=&limitstart='. ($i-1) ); if ( @$bot[0] ) { $attrs2 = JUtility::parseAttributes($bot[0]); if ( @$attrs2['alt'] ) { $title = stripslashes( $attrs2['alt'] ); } elseif ( @$attrs2['title'] ) { $title = stripslashes( $attrs2['title'] ); } else { $title = JText::sprintf( 'Page #', $i ); } } else { $title = JText::sprintf( 'Page #', $i ); } $row->toc .= ' '; $i++; } // Get Plugin info $plugin =& JPluginHelper::getPlugin('content', 'pagebreak'); $params = new JParameter( $plugin->params ); if ($params->get('showall') ) { $link = JRoute::_( '&showall=1&limitstart='); $row->toc .= ' '; } $row->toc .= '
' . JText::_( 'Article Index' ) . '
' . $heading . '
' . $title . '
' . JText::_( 'All Pages' ) . '
'; } function plgContentCreateNavigation( &$row, $page, $n ) { $pnSpace = ""; if (JText::_( '<' ) || JText::_( '>' )) $pnSpace = " "; if ( $page < $n-1 ) { $page_next = $page + 1; $link_next = JRoute::_( '&limitstart='. ( $page_next ) ); // Next >> $next = '' . JText::_( 'Next' ) . $pnSpace . JText::_( '>' ) . JText::_( '>' ) .''; } else { $next = JText::_( 'Next' ); } if ( $page > 0 ) { $page_prev = $page - 1 == 0 ? "" : $page - 1; $link_prev = JRoute::_( '&limitstart='. ( $page_prev) ); // << Prev $prev = ''. JText::_( '<' ) . JText::_( '<' ) . $pnSpace . JText::_( 'Prev' ) .''; } else { $prev = JText::_( 'Prev' ); } $row->text .= '
' . $prev . ' - ' . $next .'
'; }