[ Index ]

PHP Cross Reference of Mambo 4.6.5

[ Variables ]     [ Functions ]     [ Classes ]     [ Constants ]     [ Statistics ]

title

Body

[close]

/mambots/content/ -> mospaging.php (source)

   1  <?php
   2  /**
   3  * @package Mambo
   4  * @author Mambo Foundation Inc see README.php
   5  * @copyright (C) 2000 - 2009 Mambo Foundation Inc.
   6  * See COPYRIGHT.php for copyright notices and details.
   7  * @license GNU/GPL Version 2, see LICENSE.php
   8  *
   9  * Redistributions of files must retain the above copyright notice.
  10  *
  11  * Mambo is free software; you can redistribute it and/or
  12  * modify it under the terms of the GNU General Public License
  13  * as published by the Free Software Foundation; version 2 of the License.
  14  */
  15  
  16  /** ensure this file is being included by a parent file */
  17  defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );
  18  
  19  $this->registerFunction( 'onPrepareContent', 'botMosPaging' );
  20  
  21  /**
  22  * Page break mambot
  23  *
  24  * <strong>Usage:</strong>
  25  * <code>{mospagebreak}</code>
  26  * <code>{mospagebreak title=The page title}</code>
  27  * or
  28  * <code>{mospagebreak heading=The first page}</code>
  29  * or
  30  * <code>{mospagebreak title=The page title&heading=The first page}</code>
  31  * or
  32  * <code>{mospagebreak heading=The first page&title=The page title}</code>
  33  *
  34  */
  35  function botMosPaging( $published, &$row, &$cparams, $page=0, $params ) {
  36      global $mainframe, $Itemid, $database, $configuration;
  37  
  38      if (strtolower(get_class($row)) != 'mosextendedcontent') return;
  39  
  40       // expression to search for
  41       $regex = '/{(mospagebreak)\s*(.*?)}/i';
  42  
  43       if (!$published || $cparams->get( 'intro_only' )|| $cparams->get( 'popup' )) {
  44          $row->text = preg_replace( $regex, '', $row->text );
  45          return;
  46      }
  47  
  48      // find all instances of mambot and put in $matches
  49      $matches = array();
  50      preg_match_all( $regex, $row->text, $matches, PREG_SET_ORDER );
  51  
  52      // split the text around the mambot
  53      $text = preg_split( $regex, $row->text );
  54  
  55      $matches[0][2] = @html_entity_decode ( $matches[0][2], ENT_QUOTES, strtoupper($configuration->current_language->charset) );
  56      // count the number of pages
  57      $n = count( $text );
  58  
  59      // we have found at least one mambot, therefore at least 2 pages
  60      if ($n > 1) {
  61          // load mambot params info
  62           $title    = $params->def( 'title', 1 );
  63  
  64           // adds heading or title to <site> Title
  65           if ( $title ) {
  66              $page_text = $page + 1;
  67              $row->page_title = T_('Page') .' '. $page_text;
  68              if ( !$page ) {
  69                  // processing for first page
  70                  parse_str( $matches[0][2], $args );
  71  
  72                  if ( @$args['heading'] ) {
  73                      $row->page_title = $args['heading'];
  74                  } else {
  75                      $row->page_title = '';
  76                  }
  77              } else if ( $matches[$page-1][2] ) {
  78                  parse_str( $matches[$page-1][2], $args );
  79  
  80                  if ( @$args['title'] ) {
  81                      $row->page_title = $args['title'];
  82                  }
  83              }
  84           }
  85  
  86          // reset the text, we already hold it in the $text array
  87          $row->text = '';
  88  
  89          $hasToc = $mainframe->getCfg( 'multipage_toc' );
  90  
  91          if ( $hasToc ) {
  92              // display TOC
  93              createTOC( $row, $matches, $page );
  94          } else {
  95              $row->toc = '';
  96          }
  97  
  98          // traditional mos page navigation
  99          require_once( $GLOBALS['mosConfig_absolute_path'] . '/includes/pageNavigation.php' );
 100          $pageNav = new mosPageNav( $n, $page, 1 );
 101  
 102          // page counter
 103          $row->text .= '<div class="pagenavcounter">';
 104          $row->text .= $pageNav->writeLeafsCounter();
 105          $row->text .= '</div>';
 106  
 107          // page text
 108          $row->text .= $text[$page];
 109  
 110          $row->text .= '<br />';
 111          $row->text .= '<div class="pagenavbar">';
 112  
 113          // adds navigation between pages to bottom of text
 114          if ( $hasToc ) {
 115              createNavigation( $row, $page, $n );
 116          }
 117  
 118          // page links shown at bottom of page if TOC disabled
 119          if (!$hasToc) {
 120              $row->text .= $pageNav->writePagesLinks( 'index.php?option=com_content&amp;task=view&amp;id='. $row->id .'&amp;Itemid='. $Itemid );
 121          }
 122  
 123          $row->text .= '</div><br />';
 124      }
 125  
 126      return true;
 127  }
 128  
 129  function createTOC( &$row, &$matches, &$page ) {
 130      global $Itemid;
 131  
 132      $nonseflink = 'index.php?option=com_content&amp;task=view&amp;id='. $row->id .'&amp;Itemid='. $Itemid;
 133      $link = 'index.php?option=com_content&amp;task=view&amp;id='. $row->id .'&amp;Itemid='. $Itemid;
 134      $link = sefRelToAbs( $link );
 135  
 136      $heading = $row->title;
 137      // allows customization of first page title by checking for `heading` attribute in first bot
 138      if ( @$matches[0][2] ) {
 139          parse_str( $matches[0][2], $args );
 140  
 141          if ( @$args['heading'] ) {
 142              $heading = $args['heading'];
 143          }
 144      }
 145  
 146      // TOC Header
 147      $row->toc = '
 148      <table cellpadding="0" cellspacing="0" class="contenttoc" align="right">
 149      <tr>
 150          <th>'
 151          . T_('Article Index') .
 152          '</th>
 153      </tr>
 154      ';
 155  
 156      // TOC First Page link
 157      $row->toc .= '
 158      <tr>
 159          <td>
 160          <a href="'. $link .'" class="toclink">'
 161          . $heading .
 162          '</a>
 163          </td>
 164      </tr>
 165      ';
 166  
 167      $i = 2;
 168      $args2 = array();
 169  
 170      foreach ( $matches as $bot ) {
 171          $link = $nonseflink .'&amp;limit=1&amp;limitstart='. ($i-1);
 172          $link = sefRelToAbs( $link );
 173  
 174          if ( @$bot[2] ) {
 175              parse_str( str_replace( '&amp;', '&', $bot[2] ), $args2 );
 176  
 177              if ( @$args2['title'] ) {
 178                  $row->toc .= '
 179                  <tr>
 180                      <td>
 181                      <a href="'. $link .'" class="toclink">'
 182                      . $args2['title'] .
 183                      '</a>
 184                      </td>
 185                  </tr>
 186                  ';
 187              } else {
 188                  $row->toc .= '
 189                  <tr>
 190                      <td>
 191                      <a href="'. $link .'" class="toclink">'
 192                      . T_('Page') .' '. $i .
 193                      '</a>
 194                      </td>
 195                  </tr>
 196                  ';
 197              }
 198          } else {
 199              $row->toc .= '
 200              <tr>
 201                  <td>
 202                  <a href="'. $link .'" class="toclink">'
 203                  . T_('Page') .' '. $i .
 204                  '</a>
 205                  </td>
 206              </tr>
 207              ';
 208          }
 209          $i++;
 210      }
 211  
 212      $row->toc .= '</table>';
 213  }
 214  
 215  function createNavigation( &$row, $page, $n ) {
 216      global $Itemid;
 217  
 218      $link = 'index.php?option=com_content&amp;task=view&amp;id='. $row->id .'&amp;Itemid='. $Itemid;
 219  
 220      if ( $page < $n-1 ) {
 221          $link_next = $link .'&amp;limit=1&amp;limitstart='. ( $page + 1 );
 222          $link_next = sefRelToAbs( $link_next );
 223  
 224          $next = '<a href="'. $link_next .'">' .T_('Next').' &raquo;</a>';
 225      } else {
 226          $next = T_('Next');
 227      }
 228  
 229      if ( $page > 0 ) {
 230          $link_prev = $link .'&amp;limit=1&amp;limitstart='. ( $page - 1 );
 231          $link_prev = sefRelToAbs( $link_prev );
 232  
 233          $prev = '<a href="'. $link_prev .'">&laquo; '. T_('Previous') .'</a>';
 234      } else {
 235          $prev = T_('Previous');
 236      }
 237  
 238      $row->text .= '<div>' . $prev . ' - ' . $next .'</div>';
 239  }
 240  ?>