[ Index ]

PHP Cross Reference of Joomla 2.5.4 DE

title

Body

[close]

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

   1  <?php
   2  /**
   3   * @copyright    Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
   4   * @license        GNU General Public License version 2 or later; see LICENSE.txt
   5   */
   6  
   7  // No direct access.
   8  defined('_JEXEC') or die;
   9  
  10  jimport('joomla.html.pagination');
  11  jimport('joomla.html.html.sliders');
  12  jimport('joomla.html.html.tabs');
  13  
  14  /**
  15   * Page break plugin
  16   *
  17   * <b>Usage:</b>
  18   * <code><hr class="system-pagebreak" /></code>
  19   * <code><hr class="system-pagebreak" title="The page title" /></code>
  20   * or
  21   * <code><hr class="system-pagebreak" alt="The first page" /></code>
  22   * or
  23   * <code><hr class="system-pagebreak" title="The page title" alt="The first page" /></code>
  24   * or
  25   * <code><hr class="system-pagebreak" alt="The first page" title="The page title" /></code>
  26   *
  27   * @package        Joomla.Plugin
  28   * @subpackage    Content.pagebreak
  29   * @since        1.6
  30   */
  31  class plgContentPagebreak extends JPlugin
  32  {
  33      /**
  34       * Constructor
  35       *
  36       * @access      protected
  37       * @param       object  $subject The object to observe
  38       * @param       array   $config  An array that holds the plugin configuration
  39       * @since       1.5
  40       */
  41  	public function __construct(& $subject, $config)
  42      {
  43          parent::__construct($subject, $config);
  44          $this->loadLanguage();
  45      }
  46  
  47      /**
  48       * @param    string    The context of the content being passed to the plugin.
  49       * @param    object    The article object.  Note $article->text is also available
  50       * @param    object    The article params
  51       * @param    int        The 'page' number
  52       *
  53       * @return    void
  54       * @since    1.6
  55       */
  56  	public function onContentPrepare($context, &$row, &$params, $page = 0)
  57      {
  58          $canProceed = $context == 'com_content.article';
  59          if (!$canProceed) {
  60              return;
  61          }
  62  
  63          $style = $this->params->get('style', 'pages');
  64  
  65          // Expression to search for.
  66          $regex = '#<hr(.*)class="system-pagebreak"(.*)\/>#iU';
  67  
  68          $print = JRequest::getBool('print');
  69          $showall = JRequest::getBool('showall');
  70  
  71          if (!$this->params->get('enabled', 1)) {
  72              $print = true;
  73          }
  74  
  75          if ($print) {
  76              $row->text = preg_replace($regex, '<br />', $row->text);
  77              return true;
  78          }
  79  
  80          // Simple performance check to determine whether bot should process further.
  81          if (JString::strpos($row->text, 'class="system-pagebreak') === false) {
  82              return true;
  83          }
  84  
  85          $db = JFactory::getDbo();
  86          $view = JRequest::getString('view');
  87          $full = JRequest::getBool('fullview');
  88  
  89          if (!$page) {
  90              $page = 0;
  91          }
  92  
  93          if ($params->get('intro_only') || $params->get('popup') || $full || $view != 'article') {
  94              $row->text = preg_replace($regex, '', $row->text);
  95              return;
  96          }
  97  
  98          // Find all instances of plugin and put in $matches.
  99          $matches = array();
 100          preg_match_all($regex, $row->text, $matches, PREG_SET_ORDER);
 101  
 102          if (($showall && $this->params->get('showall', 1))) {
 103              $hasToc = $this->params->get('multipage_toc', 1);
 104              if ($hasToc) {
 105                  // Display TOC.
 106                  $page = 1;
 107                  $this->_createToc($row, $matches, $page);
 108              } else {
 109                  $row->toc = '';
 110              }
 111              $row->text = preg_replace($regex, '<br />', $row->text);
 112  
 113              return true;
 114          }
 115  
 116          // Split the text around the plugin.
 117          $text = preg_split($regex, $row->text);
 118  
 119          // Count the number of pages.
 120          $n = count($text);
 121  
 122          // We have found at least one plugin, therefore at least 2 pages.
 123          if ($n > 1) {
 124              $title    = $this->params->get('title', 1);
 125              $hasToc = $this->params->get('multipage_toc', 1);
 126  
 127              // Adds heading or title to <site> Title.
 128              if ($title) {
 129                  if ($page) {
 130                      $page_text = $page + 1;
 131  
 132                      if ($page && @$matches[$page-1][2]) {
 133                          $attrs = JUtility::parseAttributes($matches[$page-1][1]);
 134  
 135                          if (@$attrs['title']) {
 136                              $row->page_title = $attrs['title'];
 137                          }
 138                      }
 139                  }
 140              }
 141  
 142              // Reset the text, we already hold it in the $text array.
 143              $row->text = '';
 144              if ($style == 'pages') {
 145  
 146                  // Display TOC.
 147                  if ($hasToc) {
 148                      $this->_createToc($row, $matches, $page);
 149                  } else {
 150                      $row->toc = '';
 151                  }
 152  
 153                  // traditional mos page navigation
 154                  $pageNav = new JPagination($n, $page, 1);
 155  
 156                  // Page counter.
 157                  $row->text .= '<div class="pagenavcounter">';
 158                  $row->text .= $pageNav->getPagesCounter();
 159                  $row->text .= '</div>';
 160  
 161                  // Page text.
 162                  $text[$page] = str_replace('<hr id="system-readmore" />', '', $text[$page]);
 163                  $row->text .= $text[$page];
 164                  // $row->text .= '<br />';
 165                  $row->text .= '<div class="pagination">';
 166  
 167                  // Adds navigation between pages to bottom of text.
 168                  if ($hasToc) {
 169                      $this->_createNavigation($row, $page, $n);
 170                  }
 171  
 172                  // Page links shown at bottom of page if TOC disabled.
 173                  if (!$hasToc) {
 174                      $row->text .= $pageNav->getPagesLinks();
 175                  }
 176                  $row->text .= '</div>';
 177  
 178              }
 179              else {
 180                  $t[] = $text[0];
 181  
 182                  $t[] = (string) JHtml::_($style.'.start');
 183  
 184                  foreach ($text as $key => $subtext) {
 185  
 186                      if ($key >= 1) {
 187                          $match= $matches[$key-1];
 188                          $match = (array) JUtility::parseAttributes($match[0]);
 189                          if (isset($match['alt'])) {
 190                              $title    = stripslashes($match["alt"]);
 191                          } elseif (isset($match['title'])) {
 192                              $title    = stripslashes($match['title']);
 193                          } else {
 194                              $title    = JText::sprintf('PLG_CONTENT_PAGEBREAK_PAGE_NUM', $key);
 195                          }
 196                          $t[] = (string) JHtml::_($style.'.panel', $match['title'], 'basic-details');
 197                      }
 198                      $t[] = (string) $subtext;
 199                  }
 200  
 201                  $t[] = (string) JHtml::_($style.'.end');
 202  
 203                  $row->text = implode(' ', $t);
 204              }
 205          }
 206          return true;
 207      }
 208  
 209      /**
 210       * @return    void
 211       * @return    1.6
 212       */
 213  	protected function _createTOC(&$row, &$matches, &$page)
 214      {
 215          $heading = isset($row->title) ? $row->title : JText::_('PLG_CONTENT_PAGEBREAK_NO_TITLE');
 216          $limitstart = JRequest::getInt('limitstart', 0);
 217          $showall = JRequest::getInt('showall', 0);
 218          // TOC header.
 219          $row->toc .= '<div id="article-index">';
 220  
 221          if($this->params->get('article_index')==1)
 222          {
 223              $headingtext= JText::_('PLG_CONTENT_PAGEBREAK_ARTICLE_INDEX');
 224  
 225              if($this->params->get('article_index_text')) {
 226                  htmlspecialchars($headingtext=$this->params->get('article_index_text'));
 227              }
 228              $row->toc .='<h3>'.$headingtext.'</h3>';
 229  
 230          }
 231  
 232          // TOC first Page link.
 233          $class = ($limitstart === 0 && $showall === 0) ? 'toclink active' : 'toclink';
 234          $row->toc .= '<ul>
 235          <li>
 236  
 237              <a href="'. JRoute::_(ContentHelperRoute::getArticleRoute($row->slug, $row->catid).'&showall=&limitstart=') .'" class="'.$class.'">'
 238              . $heading .
 239              '</a>
 240  
 241          </li>
 242          ';
 243  
 244          $i = 2;
 245  
 246          foreach ($matches as $bot) {
 247              $link = JRoute::_(ContentHelperRoute::getArticleRoute($row->slug, $row->catid).'&showall=&limitstart='. ($i-1));
 248  
 249  
 250              if (@$bot[0]) {
 251                  $attrs2 = JUtility::parseAttributes($bot[0]);
 252  
 253                  if (@$attrs2['alt']) {
 254                      $title    = stripslashes($attrs2['alt']);
 255                  } elseif (@$attrs2['title']) {
 256                      $title    = stripslashes($attrs2['title']);
 257                  } else {
 258                      $title    = JText::sprintf('PLG_CONTENT_PAGEBREAK_PAGE_NUM', $i);
 259                  }
 260              } else {
 261                  $title    = JText::sprintf('PLG_CONTENT_PAGEBREAK_PAGE_NUM', $i);
 262              }
 263              $class = ($limitstart == $i-1) ? 'toclink active' : 'toclink';
 264              $row->toc .= '
 265                  <li>
 266  
 267                      <a href="'. $link .'" class="'.$class.'">'
 268                      . $title .
 269                      '</a>
 270  
 271                  </li>
 272                  ';
 273              $i++;
 274          }
 275  
 276          if ($this->params->get('showall')) {
 277              $link = JRoute::_(ContentHelperRoute::getArticleRoute($row->slug, $row->catid).'&showall=1&limitstart=');
 278              $class = ($showall == 1) ? 'toclink active' : 'toclink';
 279              $row->toc .= '
 280              <li>
 281  
 282                      <a href="'. $link .'" class="'.$class.'">'
 283                      . JText::_('PLG_CONTENT_PAGEBREAK_ALL_PAGES') .
 284                      '</a>
 285  
 286              </li>
 287              ';
 288          }
 289          $row->toc .= '</ul></div>';
 290      }
 291  
 292      /**
 293       * @return    void
 294       * @since    1.6
 295       */
 296  	protected function _createNavigation(&$row, $page, $n)
 297      {
 298          $pnSpace = '';
 299          if (JText::_('JGLOBAL_LT') || JText::_('JGLOBAL_LT')) {
 300              $pnSpace = ' ';
 301          }
 302  
 303          if ($page < $n-1) {
 304              $page_next = $page + 1;
 305  
 306              $link_next = JRoute::_(ContentHelperRoute::getArticleRoute($row->slug, $row->catid).'&showall=&limitstart='. ($page_next));
 307              // Next >>
 308              $next = '<a href="'. $link_next .'">' . JText::_('JNEXT') . $pnSpace . JText::_('JGLOBAL_GT') . JText::_('JGLOBAL_GT') .'</a>';
 309          } else {
 310              $next = JText::_('JNEXT');
 311          }
 312  
 313          if ($page > 0) {
 314              $page_prev = $page - 1 == 0 ? '' : $page - 1;
 315  
 316              $link_prev = JRoute::_(ContentHelperRoute::getArticleRoute($row->slug, $row->catid).'&showall=&limitstart='. ($page_prev));
 317              // << Prev
 318              $prev = '<a href="'. $link_prev .'">'. JText::_('JGLOBAL_LT') . JText::_('JGLOBAL_LT') . $pnSpace . JText::_('JPREV') .'</a>';
 319          } else {
 320              $prev = JText::_('JPREV');
 321          }
 322  
 323          $row->text .= '<ul><li>' . $prev . ' </li><li>' . $next .'</li></ul>';
 324      }
 325  
 326  }


Generated: Tue Apr 3 11:40:28 2012 Cross-referenced by PHPXref 0.7.1