registerFunction( 'onPrepareContent', 'botMosPaging' ); /** * Page break mambot * * Usage: * {mospagebreak} * {mospagebreak title=The page title} * or * {mospagebreak heading=The first page} * or * {mospagebreak title=The page title&heading=The first page} * or * {mospagebreak heading=The first page&title=The page title} * */ function botMosPaging( $published, &$row, &$params, $page=0 ) { global $mainframe, $Itemid, $database, $_MAMBOTS; // simple performance check to determine whether bot should process further if ( strpos( $row->text, 'mospagebreak' ) === false ) { return true; } // expression to search for $regex = '/{(mospagebreak)\s*(.*?)}/i'; // check whether mambot has been unpublished if (!$published || $params->get( 'intro_only' )|| $params->get( 'popup' )) { $row->text = preg_replace( $regex, '', $row->text ); return; } // find all instances of mambot and put in $matches $matches = array(); preg_match_all( $regex, $row->text, $matches, PREG_SET_ORDER ); // split the text around the mambot $text = preg_split( $regex, $row->text ); // count the number of pages $n = count( $text ); // we have found at least one mambot, therefore at least 2 pages if ($n > 1) { // check if param query has previously been processed if ( !isset($_MAMBOTS->_content_mambot_params['mospaging']) ) { // load mambot params info $query = "SELECT params" . "\n FROM #__mambots" . "\n WHERE element = 'mospaging'" . "\n AND folder = 'content'" ; $database->setQuery( $query ); $database->loadObject($mambot); // save query to class variable $_MAMBOTS->_content_mambot_params['mospaging'] = $mambot; } // pull query data from class variable $mambot = $_MAMBOTS->_content_mambot_params['mospaging']; $botParams = new mosParameters( $mambot->params ); $title = $botParams->def( 'title', 1 ); // adds heading or title to Title if ( $title ) { $page_text = $page + 1; $row->page_title = _PN_PAGE .' '. $page_text; if ( !$page ) { // processing for first page parse_str( html_entity_decode( $matches[0][2] ), $args ); if ( @$args['heading'] ) { //$row->page_title = $args['heading']; $row->page_title = ''; } else { $row->page_title = ''; } } else if ( $matches[$page-1][2] ) { parse_str( html_entity_decode( $matches[$page-1][2] ), $args ); if ( @$args['title'] ) { $row->page_title = ': '. stripslashes( $args['title'] ); } } } // reset the text, we already hold it in the $text array $row->text = ''; $hasToc = $mainframe->getCfg( 'multipage_toc' ); if ( $hasToc ) { // display TOC createTOC( $row, $matches, $page ); } else { $row->toc = ''; } // traditional mos page navigation require_once( $GLOBALS['mosConfig_absolute_path'] . '/includes/pageNavigation.php' ); $pageNav = new mosPageNav( $n, $page, 1 ); // page counter $row->text .= ''; // page text $row->text .= $text[$page]; $row->text .= '
'; $row->text .= '
'; } return true; } function createTOC( &$row, &$matches, &$page ) { global $Itemid; $nonseflink = 'index.php?option=com_content&task=view&id='. $row->id .'&Itemid='. $Itemid; $link = 'index.php?option=com_content&task=view&id='. $row->id .'&Itemid='. $Itemid; $link = sefRelToAbs( $link ); $heading = $row->title; // allows customization of first page title by checking for `heading` attribute in first bot if ( @$matches[0][2] ) { parse_str( html_entity_decode( $matches[0][2] ), $args ); if ( @$args['heading'] ) { $heading = $args['heading']; $row->title .= ' - '. $heading; } } // TOC Header $row->toc = ' '; // TOC First Page link $row->toc .= ' '; $i = 2; $args2 = array(); foreach ( $matches as $bot ) { $link = $nonseflink .'&limit=1&limitstart='. ($i-1); $link = sefRelToAbs( $link ); if ( @$bot[2] ) { parse_str( html_entity_decode( $bot[2] ), $args2 ); if ( @$args2['title'] ) { $row->toc .= ' '; } else { $row->toc .= ' '; } } else { $row->toc .= ' '; } $i++; } $row->toc .= '
' . _TOC_JUMPTO . '
' . $heading . '
' . stripslashes( $args2['title'] ) . '
' . _PN_PAGE .' '. $i . '
' . _PN_PAGE .' '. $i . '
'; } function createNavigation( &$row, $page, $n ) { global $Itemid; $link = 'index.php?option=com_content&task=view&id='. $row->id .'&Itemid='. $Itemid; if ( $page < $n-1 ) { $link_next = $link .'&limit=1&limitstart='. ( $page + 1 ); $link_next = sefRelToAbs( $link_next ); $next = '' ._CMN_NEXT . _CMN_NEXT_ARROW .''; } else { $next = _CMN_NEXT; } if ( $page > 0 ) { $link_prev = $link .'&limit=1&limitstart='. ( $page - 1 ); $link_prev = sefRelToAbs( $link_prev ); $prev = ''. _CMN_PREV_ARROW . _CMN_PREV .''; } else { $prev = _CMN_PREV; } $row->text .= '
' . $prev . ' - ' . $next .'
'; } ?>