test
Viewing 1 post (of 1 total)
  • Author
    Posts
  • cgc0202 Friend
    #160109

    Hello,

    I think this should be quite easily done by anyone who has some comand of the scripting.

    Here is a typical example where this would be needed, an article with 65 page, as part of a book:

    AFFAIRS IN FILIPINAS, 1644-47***

    Usually, there are several dozen “chapters”, some even longer than the example, others much shorter, about 360 pages per volume, in a 55-volume series. One of the book series planned to be included, in an online history site.

    For online layout purposes, it is best to keep each chapter intact, as a multipage. It will require page break, therefore; but the result is a very long Article TOC index, as shown in the link, and repeated at teh top of each page, in the multipage article.

    Not very nice, aesthetically. But, more important, the visitor would think that the next page has not loaded, after the click.

    I already isolated the file needed to be changed:

    root dreictory

    • => plugin
    • => content
    • => pagebreak
    • => pagebreak.php

    and here’s the file:

    [PHP]
    <?php
    /**
    * @version $Id: pagebreak.php 20240 2011-01-10 05:46:24Z dextercowley $
    * @copyright Copyright (C) 2005 – 2011 Open Source Matters, Inc. All rights reserved.
    * @license GNU General Public License version 2 or later; see LICENSE.txt
    */

    // No direct access.
    defined(‘_JEXEC’) or die;

    /**
    * Page break plugin
    *
    * <b>Usage:</b>
    * <code><hr class=”system-pagebreak” /></code>
    * <code><hr class=”system-pagebreak” title=”The page title” /></code>
    * or
    * <code><hr class=”system-pagebreak” alt=”The first page” /></code>
    * or
    * <code><hr class=”system-pagebreak” title=”The page title” alt=”The first page” /></code>
    * or
    * <code><hr class=”system-pagebreak” alt=”The first page” title=”The page title” /></code>
    *
    * @package Joomla
    * @subpackage plg_pagebreak
    * @since 1.6
    */
    class plgContentPagebreak extends JPlugin
    {
    /**
    * Constructor
    *
    * @access protected
    * @param object $subject The object to observe
    * @param array $config An array that holds the plugin configuration
    * @since 1.5
    */
    public function __construct(& $subject, $config)
    {
    parent::__construct($subject, $config);
    $this->loadLanguage();
    }

    /**
    * @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
    */
    public function onContentPrepare($context, &$row, &$params, $page = 0)
    {
    // Expression to search for.
    $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;
    }

    // Simple performance check to determine whether bot should process further.
    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;
    }

    // Find all instances of plugin and put in $matches.
    $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) {
    // Display TOC.
    $page = 1;
    $this->_createToc($row, $matches, $page);
    } else {
    $row->toc = ”;
    }
    $row->text = preg_replace($regex, ‘<br />’, $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) {
    $title = $this->params->get(‘title’, 1);
    $hasToc = $this->params->get(‘multipage_toc’, 1);

    // Adds heading or title to <site> 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) {
    $this->_createToc($row, $matches, $page);
    } else {
    $row->toc = ”;
    }

    // traditional mos page navigation
    jimport(‘joomla.html.pagination’);
    $pageNav = new JPagination($n, $page, 1);

    // Page counter.
    $row->text .= ‘<div class=”pagenavcounter”>’;
    $row->text .= $pageNav->getPagesCounter();
    $row->text .= ‘</div>’;

    // Page text.
    $text[$page] = str_replace(‘<hr id=”system-readmore” />’, ”, $text[$page]);
    $row->text .= $text[$page];

    // $row->text .= ‘<br />’;
    $row->text .= ‘<div class=”pagination”>’;

    // Adds navigation between pages to bottom of text.
    if ($hasToc) {
    $this->_createNavigation($row, $page, $n);
    }

    // Page links shown at bottom of page if TOC disabled.
    if (!$hasToc) {
    $row->text .= $pageNav->getPagesLinks();
    }

    $row->text .= ‘</div>’;
    }

    return true;
    }

    /**
    * @return void
    * @return 1.6
    */
    protected function _createTOC(&$row, &$matches, &$page)
    {
    $heading = isset($row->title) ? $row->title : JText::_(‘PLG_CONTENT_PAGEBREAK_NO_TITLE’);

    // TOC header.
    $row->toc .= ‘<div id=”article-index”>’;

    if($this->params->get(‘article_index’)==1)
    {
    $headingtext= JText::_(‘PLG_CONTENT_PAGEBREAK_ARTICLE_INDEX’);

    if($this->params->get(‘article_index_text’))
    {
    htmlspecialchars($headingtext=$this->params->get(‘article_index_text’));
    }
    $row->toc .='<h3>’.$headingtext.'</h3>’;

    }

    // TOC first Page link.
    $row->toc .= ‘<ul>
    <li>

    <a href=”‘. JRoute::_(‘&showall=&limitstart=’) .'” class=”toclink”>’
    . $heading .
    ‘</a>

    </li>
    ‘;

    $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 .= ‘
    <li>

    <a href=”‘. $link .'” class=”toclink”>’
    . $title .
    ‘</a>

    </li>
    ‘;
    $i++;
    }

    if ($this->params->get(‘showall’)) {
    $link = JRoute::_(‘&showall=1&limitstart=’);
    $row->toc .= ‘
    <li>

    <a href=”‘. $link .'” class=”toclink”>’
    . JText::_(‘PLG_CONTENT_PAGEBREAK_ALL_PAGES’) .
    ‘</a>

    </li>
    ‘;
    }
    $row->toc .= ‘</ul></div>’;
    }

    /**
    * @return void
    * @since 1.6
    */
    protected function _createNavigation(&$row, $page, $n)
    {
    $pnSpace = ”;
    if (JText::_(‘JGLOBAL_LT’) || JText::_(‘JGLOBAL_LT’)) {
    $pnSpace = ‘ ‘;
    }

    if ($page < $n-1) {
    $page_next = $page + 1;

    $link_next = JRoute::_(‘&limitstart=’. ($page_next));
    // Next >>
    $next = ‘<a href=”‘. $link_next .'”>’ . JText::_(‘JNEXT’) . $pnSpace . JText::_(‘JGLOBAL_GT’) . JText::_(‘JGLOBAL_GT’) .'</a>’;
    } else {
    $next = JText::_(‘JNEXT’);
    }

    if ($page > 0) {
    $page_prev = $page – 1 == 0 ? ” : $page – 1;

    $link_prev = JRoute::_( ‘&limitstart=’. ($page_prev));
    // << Prev
    $prev = ‘<a href=”‘. $link_prev .'”>’. JText::_(‘JGLOBAL_LT’) . JText::_(‘JGLOBAL_LT’) . $pnSpace . JText::_(‘JPREV’) .'</a>’;
    } else {
    $prev = JText::_(‘JPREV’);
    }

    $row->text .= ‘<ul><li>’ . $prev . ‘ </li><li>’ . $next .'</li></ul>’;
    }
    }

    [/PHP]

    I know slready how to manipulate the script to collapse the long article TOC index. I also know the general section in the script that needed to be moved around:

    “general area” of the article TOC index script

    [PHP]

    // Reset the text, we already hold it in the $text array.
    $row->text = ”;

    // Display TOC.
    if ($hasToc) {
    $this->_createToc($row, $matches, $page);
    } else {
    $row->toc = ”;
    }

    // traditional mos page navigation
    jimport(‘joomla.html.pagination’);
    $pageNav = new JPagination($n, $page, 1);

    // Page counter.
    $row->text .= ‘<div class=”pagenavcounter”>’;
    $row->text .= $pageNav->getPagesCounter();
    $row->text .= ‘</div>’;

    // Page text.
    $text[$page] = str_replace(‘<hr id=”system-readmore” />’, ”, $text[$page]);
    $row->text .= $text[$page];

    // $row->text .= ‘<br />’;
    $row->text .= ‘<div class=”pagination”>’;

    // Adds navigation between pages to bottom of text.
    if ($hasToc) {
    $this->_createNavigation($row, $page, $n);
    }

    // Page links shown at bottom of page if TOC disabled.
    if (!$hasToc) {
    $row->text .= $pageNav->getPagesLinks();
    }

    $row->text .= ‘</div>’;
    }

    return true;
    }

    [/PHP]

    Unfortunately, either the script section, I was trying to move is

    • incomplete or has other scripts,
    • perhaps missing a command, or open or close bracket to complete the command.

    The bottom line is that I get an error, when I moved what I thought would be the “complete command script” for the article TOC index.

    If you respond, kindly include the “complete script of the article TOC index”, including the border “top and bottom” line scripts, just outside the script segment to be moved, The same also for the border “top and bottom” line scripts where the “complete script of the article TOC index” would be inserted to achieve this layout:

    1. Title of article
    2. byline
    3. text for each page
    4. Previous Next navigation
    5. Article TOC Index

    for each page in a multipage article.

    Any help would be much appreciated. Thanks.

    Cornelio

    N.B.
    *** The article AFFAIRS IN FILIPINAS, 1644-47 was inserted into a Demo Teline IV- Joomla 1.6. to demonstrate that the Demo site is functional. The actual layout and contents of the final site would be different.

Viewing 1 post (of 1 total)

This topic contains 1 reply, has 1 voice, and was last updated by  cgc0202 13 years, 9 months ago.

We moved to new unified forum. Please post all new support queries in our New Forum