[ Index ]

PHP Cross Reference of Joomla 1.5.26 DE

title

Body

[close]

/plugins/content/ -> pagebreak.php (source)

   1  <?php
   2  /**
   3  * @version        $Id: pagebreak.php 14401 2010-01-26 14:10:00Z louis $
   4  * @package        Joomla
   5  * @copyright    Copyright (C) 2005 - 2010 Open Source Matters. All rights reserved.
   6  * @license        GNU/GPL, see LICENSE.php
   7  * Joomla! is free software. This version may have been modified pursuant
   8  * to the GNU General Public License, and as distributed it includes or
   9  * is derivative of works licensed under the GNU General Public License or
  10  * other free or open source software licenses.
  11  * See COPYRIGHT.php for copyright notices and details.
  12  */
  13  
  14  // no direct access
  15  defined( '_JEXEC' ) or die( 'Restricted access' );
  16  
  17  $mainframe->registerEvent( 'onPrepareContent', 'plgContentPagebreak' );
  18  
  19  /**
  20  * Page break plugin
  21  *
  22  * <b>Usage:</b>
  23  * <code><hr class="system-pagebreak" /></code>
  24  * <code><hr class="system-pagebreak" title="The page title" /></code>
  25  * or
  26  * <code><hr class="system-pagebreak" alt="The first page" /></code>
  27  * or
  28  * <code><hr class="system-pagebreak" title="The page title" alt="The first page" /></code>
  29  * or
  30  * <code><hr class="system-pagebreak" alt="The first page" title="The page title" /></code>
  31  *
  32  */
  33  function plgContentPagebreak( &$row, &$params, $page=0 )
  34  {
  35      // expression to search for
  36      $regex = '#<hr([^>]*?)class=(\"|\')system-pagebreak(\"|\')([^>]*?)\/*>#iU';
  37  
  38      // Get Plugin info
  39      $plugin            =& JPluginHelper::getPlugin('content', 'pagebreak');
  40      $pluginParams    = new JParameter( $plugin->params );
  41  
  42      $print   = JRequest::getBool('print');
  43      $showall = JRequest::getBool('showall');
  44  
  45      JPlugin::loadLanguage( 'plg_content_pagebreak' );
  46  
  47      if (!$pluginParams->get('enabled', 1)) {
  48          $print = true;
  49      }
  50  
  51      if ($print) {
  52          $row->text = preg_replace( $regex, '<br />', $row->text );
  53          return true;
  54      }
  55  
  56      //simple performance check to determine whether bot should process further
  57      if ( strpos( $row->text, 'class="system-pagebreak' ) === false && strpos( $row->text, 'class=\'system-pagebreak' ) === false ) {
  58          return true;
  59      }
  60  
  61      $db        =& JFactory::getDBO();
  62      $view  = JRequest::getCmd('view');
  63  
  64      if(!$page) {
  65          $page = 0;
  66      }
  67  
  68  
  69      // check whether plugin has been unpublished
  70      if (!JPluginHelper::isEnabled('content', 'pagebreak') || $params->get( 'intro_only' )|| $params->get( 'popup' ) || $view != 'article') {
  71          $row->text = preg_replace( $regex, '', $row->text );
  72          return;
  73      }
  74  
  75      // find all instances of plugin and put in $matches
  76      $matches = array();
  77      preg_match_all( $regex, $row->text, $matches, PREG_SET_ORDER );
  78  
  79      if (($showall && $pluginParams->get('showall', 1) ))
  80      {
  81          $hasToc = $pluginParams->get( 'multipage_toc', 1 );
  82          if ( $hasToc ) {
  83              // display TOC
  84              $page = 1;
  85              plgContentCreateTOC( $row, $matches, $page );
  86          } else {
  87              $row->toc = '';
  88          }
  89          $row->text = preg_replace( $regex, '<br/>', $row->text );
  90          return true;
  91      }
  92  
  93      // split the text around the plugin
  94      $text = preg_split( $regex, $row->text );
  95  
  96      // count the number of pages
  97      $n = count( $text );
  98      
  99      $row->pagebreaktitle = $row->title;
 100      
 101      // we have found at least one plugin, therefore at least 2 pages
 102      if ($n > 1)
 103      {
 104          // Get plugin parameters
 105          $pluginParams = new JParameter( $plugin->params );
 106          $title    = $pluginParams->get( 'title', 1 );
 107          $hasToc = $pluginParams->get( 'multipage_toc', 1 );
 108  
 109          // adds heading or title to <site> Title
 110          if ( $title )
 111          {
 112              if ( $page ) {
 113                  $page_text = $page + 1;
 114                  if ( $page && @$matches[$page-1][2] )
 115                  {
 116                      $attrs = JUtility::parseAttributes($matches[$page-1][0]);
 117  
 118                      if ( @$attrs['title'] ) {
 119                          $row->title = $row->title.' - '.$attrs['title'];
 120                      } else {
 121                          $thispage = $page + 1;
 122                          $row->title = $row->title.' - '.JText::_( 'Page' ).' '.$thispage;
 123                      }
 124                  }
 125              }
 126          }
 127  
 128          // reset the text, we already hold it in the $text array
 129          $row->text = '';
 130  
 131          // display TOC
 132          if ( $hasToc ) {
 133              plgContentCreateTOC( $row, $matches, $page );
 134          } else {
 135              $row->toc = '';
 136          }
 137  
 138          // traditional mos page navigation
 139          jimport('joomla.html.pagination');
 140          $pageNav = new JPagination( $n, $page, 1 );
 141  
 142          // page counter
 143          $row->text .= '<div class="pagenavcounter">';
 144          $row->text .= $pageNav->getPagesCounter();
 145          $row->text .= '</div>';
 146  
 147          // page text
 148          $text[$page] = str_replace("<hr id=\"\"system-readmore\"\" />", "", $text[$page]);
 149          $row->text .= $text[$page];
 150  
 151          $row->text .= '<br />';
 152          $row->text .= '<div class="pagenavbar">';
 153  
 154          // adds navigation between pages to bottom of text
 155          if ( $hasToc ) {
 156              plgContentCreateNavigation( $row, $page, $n );
 157          }
 158  
 159          // page links shown at bottom of page if TOC disabled
 160          if (!$hasToc) {
 161              $row->text .= $pageNav->getPagesLinks();
 162          }
 163  
 164          $row->text .= '</div><br />';
 165      }
 166  
 167      return true;
 168  }
 169  
 170  function plgContentCreateTOC( &$row, &$matches, &$page )
 171  {
 172  
 173      if (isset($row->pagebreaktitle)) {$heading = $row->pagebreaktitle;} else {$heading = $row->title;}
 174      $limitstart = JRequest::getInt('limitstart', 0);
 175      $showall = JRequest::getInt('showall', 0);
 176  
 177      // TOC Header
 178      $row->toc = '
 179      <table cellpadding="0" cellspacing="0" class="contenttoc">
 180      <tr>
 181          <th>'
 182          . JText::_( 'Article Index' ) .
 183          '</th>
 184      </tr>
 185      ';
 186  
 187      // TOC First Page link
 188      $class = ($limitstart === 0 && $showall === 0) ? 'toclink active' : 'toclink';
 189      $row->toc .= '
 190      <tr>
 191          <td>
 192          <a href="'. JRoute::_( '&showall=&limitstart=') .'" class="'. $class .'">'
 193          . $heading .
 194          '</a>
 195          </td>
 196      </tr>
 197      ';
 198  
 199      $i = 2;
 200  
 201      foreach ( $matches as $bot )
 202      {
 203          $link = JRoute::_( '&showall=&limitstart='. ($i-1) );
 204  
 205  
 206          if ( @$bot[0] )
 207          {
 208              $attrs2 = JUtility::parseAttributes($bot[0]);
 209  
 210              if ( @$attrs2['alt'] )
 211              {
 212                  $title    = stripslashes( $attrs2['alt'] );
 213              }
 214              elseif ( @$attrs2['title'] )
 215              {
 216                  $title    = stripslashes( $attrs2['title'] );
 217              }
 218              else
 219              {
 220                  $title    = JText::sprintf( 'Page #', $i );
 221              }
 222          }
 223          else
 224          {
 225              $title    = JText::sprintf( 'Page #', $i );
 226          }
 227  
 228          $class = ($limitstart == $i-1) ? 'toclink active' : 'toclink';
 229          $row->toc .= '
 230              <tr>
 231                  <td>
 232                  <a href="'. $link .'" class="'. $class .'">'
 233                  . $title .
 234                  '</a>
 235                  </td>
 236              </tr>
 237              ';
 238          $i++;
 239      }
 240  
 241      // Get Plugin info
 242      $plugin =& JPluginHelper::getPlugin('content', 'pagebreak');
 243  
 244      $params = new JParameter( $plugin->params );
 245  
 246      if ($params->get('showall') )
 247      {
 248          $link = JRoute::_( '&showall=1&limitstart=');
 249          $class = ($showall == 1) ? 'toclink active' : 'toclink';
 250          $row->toc .= '
 251          <tr>
 252              <td>
 253                  <a href="'. $link .'" class="'. $class .'">'
 254                  . JText::_( 'All Pages' ) .
 255                  '</a>
 256              </td>
 257          </tr>
 258          ';
 259      }
 260      $row->toc .= '</table>';
 261  }
 262  
 263  function plgContentCreateNavigation( &$row, $page, $n )
 264  {
 265      $pnSpace = "";
 266      if (JText::_( '&lt' ) || JText::_( '&gt' )) $pnSpace = " ";
 267  
 268      if ( $page < $n-1 )
 269      {
 270          $page_next = $page + 1;
 271  
 272          $link_next = JRoute::_( '&limitstart='. ( $page_next ) );
 273          // Next >>
 274          $next = '<a href="'. $link_next .'">' . JText::_( 'Next' ) . $pnSpace . JText::_( '&gt' ) . JText::_( '&gt' ) .'</a>';
 275      }
 276      else
 277      {
 278          $next = JText::_( 'Next' );
 279      }
 280  
 281      if ( $page > 0 )
 282      {
 283          $page_prev = $page - 1 == 0 ? "" : $page - 1;
 284  
 285          $link_prev = JRoute::_(  '&limitstart='. ( $page_prev) );
 286          // << Prev
 287          $prev = '<a href="'. $link_prev .'">'. JText::_( '&lt' ) . JText::_( '&lt' ) . $pnSpace . JText::_( 'Prev' ) .'</a>';
 288      }
 289      else
 290      {
 291          $prev = JText::_( 'Prev' );
 292      }
 293  
 294      $row->text .= '<div>' . $prev . ' - ' . $next .'</div>';
 295  }


Generated: Wed Mar 28 15:54:07 2012 Cross-referenced by PHPXref 0.7.1