english/plugins/content/pagebreak/pagebreak.php
/**
	 * @param	string	The context of the content being passed to the plugin.
	 * @param	object	The article object.  Note $article->text is also available
	 * @param	object	The article params
	 * @param	int		The 'page' number
	 *
	 * @return	void
	 * @since	1.6
	 */
@param       string  The context of the content being passed to the plugin.
@param       object  The article object.  Note $article->text is also available
@param       object  The article params
@param       int             The 'page' number


@param string The context of the content being passed to the plugin . @param object The article object . Note $article - > text is also available @param object The article params @param int The ' page ' number
public function onContentPrepare($context, &$row, &$params, $page = 0)
	{
		$canProceed = $context == 'com_content.article';
		if (!$canProceed) {
			return;
		}
		$style = $this->params->get('style','pages');
		$regex = '#<hr(.*)class="system-pagebreak"(.*)\/>#iU';
		$print = JRequest::getBool('print');
		$showall = JRequest::getBool('showall');
		if (!$this->params->get('enabled', 1)) {
			$print = true;
		}
		if ($print) {
			$row->text = preg_replace($regex, '<br />', $row->text);
			return true;
		}
		if (JString::strpos($row->text, 'class="system-pagebreak') === false) {
			return true;
		}
		$db = JFactory::getDbo();
		$view = JRequest::getString('view');
		$full = JRequest::getBool('fullview');
		if (!$page) {
			$page = 0;
		}
		if ($params->get('intro_only') || $params->get('popup') || $full || $view != 'article') {
			$row->text = preg_replace($regex, '', $row->text);
			return;
		}
		$matches = array();
		preg_match_all($regex, $row->text, $matches, PREG_SET_ORDER);
		if (($showall && $this->params->get('showall', 1))) {
			$hasToc = $this->params->get('multipage_toc', 1);
			if ($hasToc) {
				$page = 1;
				$this->_createToc($row, $matches, $page);
			} else {
				$row->toc = '';
			}
			$row->text = preg_replace($regex, '<br />', $row->text);
			return true;
		}
		$text = preg_split($regex, $row->text);
		$n = count($text);
		if ($n > 1) {
			$title	= $this->params->get('title', 1);
			$hasToc = $this->params->get('multipage_toc', 1);
			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'];
						}
					}
				}
			}
			$row->text = '';
			if ($style == 'pages') {
				if ($hasToc) {
					$this->_createToc($row, $matches, $page);
				} else {
					$row->toc = '';
				}
				$pageNav = new JPagination($n, $page, 1);
				$row->text .= '<div class="pagenavcounter">';
				$row->text .= $pageNav->getPagesCounter();
				$row->text .= '</div>';
				$text[$page] = str_replace('<hr id="system-readmore" />', '', $text[$page]);
				$row->text .= $text[$page];
				$row->text .= '<div class="pagination">';
				if ($hasToc) {
					$this->_createNavigation($row, $page, $n);
				}
				if (!$hasToc) {
					$row->text .= $pageNav->getPagesLinks();
				}
				$row->text .= '</div>';
			}
			else {
				$t[] = $text[0];
				$t[] = (string) JHtml::_($style.'.start');
				foreach ($text as $key => $subtext) {
					if ($key >= 1) {
						$match= $matches[$key-1];
						$match = (array) JUtility::parseAttributes($match[0]);
						if (isset($match['alt'])) {
							$title	= stripslashes($match["alt"]);
						} elseif (isset($match['title'])) {
							$title	= stripslashes($match['title']);
						} else {
							$title	= JText::sprintf('PLG_CONTENT_PAGEBREAK_PAGE_NUM', $key);
						}
						$t[] = (string) JHtml::_($style.'.panel', $match['title'],'basic-details');
					}
					$t[] = (string) $subtext; 
				}
				$t[] = (string) JHtml::_($style.'.end');
				$row->text = implode(' ',$t);
			}
		}
		return true;
	}
public function onContentPrepare ( $ context , & $ row , & $ params , $ page = 0 ) { $ canProceed = $ context == 'com_content.article' ; if ( ! $ canProceed ) { return ; } $ style = $ this -> params -> get ( 'style' , 'pages' ) ; $ regex = '#<hr(.*)class="system-pagebreak"(.*)\/>#iU' ; $ print = JRequest :: getBool ( 'print' ) ; $ showall = JRequest :: getBool ( 'showall' ) ; if ( ! $ this -> params -> get ( 'enabled' , 1 ) ) { $ print = true ; } if ( $ print ) { $ row -> text = preg_replace ( $ regex , '<br />' , $ row -> text ) ; return true ; } if ( JString :: strpos ( $ row -> text , 'class="system-pagebreak' ) === false ) { return true ; } $ db = JFactory :: getDbo ( ) ; $ view = JRequest :: getString ( 'view' ) ; $ full = JRequest :: getBool ( 'fullview' ) ; if ( ! $ page ) { $ page = 0 ; } if ( $ params -> get ( 'intro_only' ) || $ params -> get ( 'popup' ) || $ full || $ view != 'article' ) { $ row -> text = preg_replace ( $ regex , '' , $ row -> text ) ; return ; } $ matches = array ( ) ; preg_match_all ( $ regex , $ row -> text , $ matches , PREG_SET_ORDER ) ; if ( ( $ showall && $ this -> params -> get ( 'showall' , 1 ) ) ) { $ hasToc = $ this -> params -> get ( 'multipage_toc' , 1 ) ; if ( $ hasToc ) { $ page = 1 ; $ this -> _createToc ( $ row , $ matches , $ page ) ; } else { $ row -> toc = '' ; } $ row -> text = preg_replace ( $ regex , '<br />' , $ row -> text ) ; return true ; } $ text = preg_split ( $ regex , $ row -> text ) ; $ n = count ( $ text ) ; if ( $ n > 1 ) { $ title = $ this -> params -> get ( 'title' , 1 ) ; $ hasToc = $ this -> params -> get ( 'multipage_toc' , 1 ) ; 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' ] ; } } } } $ row -> text = '' ; if ( $ style == 'pages' ) { if ( $ hasToc ) { $ this -> _createToc ( $ row , $ matches , $ page ) ; } else { $ row -> toc = '' ; } $ pageNav = new JPagination ( $ n , $ page , 1 ) ; $ row -> text .= '<div class="pagenavcounter">' ; $ row -> text .= $ pageNav -> getPagesCounter ( ) ; $ row -> text .= '</div>' ; $ text [ $ page ] = str_replace ( '<hr id="system-readmore" />' , '' , $ text [ $ page ] ) ; $ row -> text .= $ text [ $ page ] ; $ row -> text .= '<div class="pagination">' ; if ( $ hasToc ) { $ this -> _createNavigation ( $ row , $ page , $ n ) ; } if ( ! $ hasToc ) { $ row -> text .= $ pageNav -> getPagesLinks ( ) ; } $ row -> text .= '</div>' ; } else { $ t [ ] = $ text [ 0 ] ; $ t [ ] = ( string ) JHtml :: _ ( $ style . '.start' ) ; foreach ( $ text as $ key => $ subtext ) { if ( $ key >= 1 ) { $ match = $ matches [ $ key - 1 ] ; $ match = ( array ) JUtility :: parseAttributes ( $ match [ 0 ] ) ; if ( isset ( $ match [ 'alt' ] ) ) { $ title = stripslashes ( $ match [ " alt " ] ) ; } elseif ( isset ( $ match [ 'title' ] ) ) { $ title = stripslashes ( $ match [ 'title' ] ) ; } else { $ title = JText :: sprintf ( 'PLG_CONTENT_PAGEBREAK_PAGE_NUM' , $ key ) ; } $ t [ ] = ( string ) JHtml :: _ ( $ style . '.panel' , $ match [ 'title' ] , 'basic-details' ) ; } $ t [ ] = ( string ) $ subtext ; } $ t [ ] = ( string ) JHtml :: _ ( $ style . '.end' ) ; $ row -> text = implode ( ' ' , $ t ) ; } } return true ; }
@param       string  The context of the content being passed to the plugin.
@param string The context of the content being passed to the plugin .
// Expression to search for. // Simple performance check to determine whether bot should process further. // Find all instances of plugin and put in $matches. // Display TOC. // Split the text around the plugin. // Count the number of pages. // We have found at least one plugin, therefore at least 2 pages. // Adds heading or title to <site> Title. // Reset the text, we already hold it in the $text array. // Display TOC. // traditional mos page navigation // Page counter. // Page text. // $row->text .= '<br />'; // Adds navigation between pages to bottom of text. // Page links shown at bottom of page if TOC disabled.