Source for file mospaging.php

Documentation is available at mospaging.php

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

Documentation generated on Mon, 05 May 2008 16:21:32 +0400 by phpDocumentor 1.4.0