PageRenderTime 41ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/mambots/content/mospaging.php

https://bitbucket.org/dgough/annamaria-daneswood-25102012
PHP | 243 lines | 148 code | 45 blank | 50 comment | 26 complexity | ef5e04570a37dc00f7bb5b93eb478b59 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1
  1. <?php
  2. /**
  3. * @version $Id: mospaging.php 2574 2006-02-23 18:48:16Z stingrey $
  4. * @package Joomla
  5. * @copyright Copyright (C) 2005 Open Source Matters. All rights reserved.
  6. * @license http://www.gnu.org/copyleft/gpl.html 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. // no direct access
  14. defined( '_VALID_MOS' ) or die( 'Restricted access' );
  15. $_MAMBOTS->registerFunction( 'onPrepareContent', 'botMosPaging' );
  16. /**
  17. * Page break mambot
  18. *
  19. * <b>Usage:</b>
  20. * <code>{mospagebreak}</code>
  21. * <code>{mospagebreak title=The page title}</code>
  22. * or
  23. * <code>{mospagebreak heading=The first page}</code>
  24. * or
  25. * <code>{mospagebreak title=The page title&heading=The first page}</code>
  26. * or
  27. * <code>{mospagebreak heading=The first page&title=The page title}</code>
  28. *
  29. */
  30. function botMosPaging( $published, &$row, &$params, $page=0 ) {
  31. global $mainframe, $Itemid, $database, $_MAMBOTS;
  32. // simple performance check to determine whether bot should process further
  33. if ( strpos( $row->text, 'mospagebreak' ) === false ) {
  34. return true;
  35. }
  36. // expression to search for
  37. $regex = '/{(mospagebreak)\s*(.*?)}/i';
  38. // check whether mambot has been unpublished
  39. if (!$published || $params->get( 'intro_only' )|| $params->get( 'popup' )) {
  40. $row->text = preg_replace( $regex, '', $row->text );
  41. return;
  42. }
  43. // find all instances of mambot and put in $matches
  44. $matches = array();
  45. preg_match_all( $regex, $row->text, $matches, PREG_SET_ORDER );
  46. // split the text around the mambot
  47. $text = preg_split( $regex, $row->text );
  48. // count the number of pages
  49. $n = count( $text );
  50. // we have found at least one mambot, therefore at least 2 pages
  51. if ($n > 1) {
  52. // check if param query has previously been processed
  53. if ( !isset($_MAMBOTS->_content_mambot_params['mospaging']) ) {
  54. // load mambot params info
  55. $query = "SELECT params"
  56. . "\n FROM #__mambots"
  57. . "\n WHERE element = 'mospaging'"
  58. . "\n AND folder = 'content'"
  59. ;
  60. $database->setQuery( $query );
  61. $database->loadObject($mambot);
  62. // save query to class variable
  63. $_MAMBOTS->_content_mambot_params['mospaging'] = $mambot;
  64. }
  65. // pull query data from class variable
  66. $mambot = $_MAMBOTS->_content_mambot_params['mospaging'];
  67. $botParams = new mosParameters( $mambot->params );
  68. $title = $botParams->def( 'title', 1 );
  69. // adds heading or title to <site> Title
  70. if ( $title ) {
  71. $page_text = $page + 1;
  72. $row->page_title = _PN_PAGE .' '. $page_text;
  73. if ( !$page ) {
  74. // processing for first page
  75. parse_str( html_entity_decode( $matches[0][2] ), $args );
  76. if ( @$args['heading'] ) {
  77. //$row->page_title = $args['heading'];
  78. $row->page_title = '';
  79. } else {
  80. $row->page_title = '';
  81. }
  82. } else if ( $matches[$page-1][2] ) {
  83. parse_str( html_entity_decode( $matches[$page-1][2] ), $args );
  84. if ( @$args['title'] ) {
  85. $row->page_title = ': '. stripslashes( $args['title'] );
  86. }
  87. }
  88. }
  89. // reset the text, we already hold it in the $text array
  90. $row->text = '';
  91. $hasToc = $mainframe->getCfg( 'multipage_toc' );
  92. if ( $hasToc ) {
  93. // display TOC
  94. createTOC( $row, $matches, $page );
  95. } else {
  96. $row->toc = '';
  97. }
  98. // traditional mos page navigation
  99. require_once( $GLOBALS['mosConfig_absolute_path'] . '/includes/pageNavigation.php' );
  100. $pageNav = new mosPageNav( $n, $page, 1 );
  101. // page counter
  102. $row->text .= '<div class="pagenavcounter">';
  103. $row->text .= $pageNav->writeLeafsCounter();
  104. $row->text .= '</div>';
  105. // page text
  106. $row->text .= $text[$page];
  107. return true;
  108. $row->text .= '</p><div class="pagenavbar">';
  109. // adds navigation between pages to bottom of text
  110. if ( $hasToc ) {
  111. createNavigation( $row, $page, $n );
  112. }
  113. // page links shown at bottom of page if TOC disabled
  114. if (!$hasToc) {
  115. $row->text .= $pageNav->writePagesLinks( 'index.php?option=com_content&amp;task=view&amp;id='. $row->id .'&amp;Itemid='. $Itemid );
  116. }
  117. $row->text .= '</div>';
  118. }
  119. }
  120. function createTOC( &$row, &$matches, &$page ) {
  121. global $Itemid;
  122. $nonseflink = 'index.php?option=com_content&amp;task=view&amp;id='. $row->id .'&amp;Itemid='. $Itemid;
  123. $link = 'index.php?option=com_content&amp;task=view&amp;id='. $row->id .'&amp;Itemid='. $Itemid;
  124. $link = sefRelToAbs( $link );
  125. $heading = $row->title;
  126. // allows customization of first page title by checking for `heading` attribute in first bot
  127. if ( @$matches[0][2] ) {
  128. parse_str( html_entity_decode( $matches[0][2] ), $args );
  129. if ( @$args['heading'] ) {
  130. $heading = $args['heading'];
  131. $row->title .= ' - '. $heading;
  132. }
  133. }
  134. // TOC Header
  135. $row->toc = '
  136. <div class="contenttoc" style="float: right">
  137. <div>'. _TOC_JUMPTO .'</div>';
  138. // TOC First Page link
  139. $row->toc .= '
  140. <div>
  141. <a href="'. $link .'" class="toclink">'
  142. . $heading .
  143. '</a>
  144. </div>';
  145. $i = 2;
  146. $args2 = array();
  147. foreach ( $matches as $bot ) {
  148. $link = $nonseflink .'&amp;limit=1&amp;limitstart='. ($i-1);
  149. $link = sefRelToAbs( $link );
  150. if ( @$bot[2] ) {
  151. parse_str( html_entity_decode( $bot[2] ), $args2 );
  152. if ( @$args2['title'] ) {
  153. $row->toc .= '
  154. <div>
  155. <a href="'. $link .'" class="toclink">'
  156. . stripslashes( $args2['title'] ) .
  157. '</a>
  158. </div>';
  159. } else {
  160. $row->toc .= '
  161. <div>
  162. <a href="'. $link .'" class="toclink">'
  163. . _PN_PAGE .' '. $i .
  164. '</a>
  165. </div>';
  166. }
  167. } else {
  168. $row->toc .= '
  169. <div>
  170. <a href="'. $link .'" class="toclink">'
  171. . _PN_PAGE .' '. $i .
  172. '</a>
  173. </div>';
  174. }
  175. $i++;
  176. }
  177. $row->toc .= '</div>';
  178. }
  179. function createNavigation( &$row, $page, $n ) {
  180. global $Itemid;
  181. $link = 'index.php?option=com_content&amp;task=view&amp;id='. $row->id .'&amp;Itemid='. $Itemid;
  182. if ( $page < $n-1 ) {
  183. $link_next = $link .'&amp;limit=1&amp;limitstart='. ( $page + 1 );
  184. $link_next = sefRelToAbs( $link_next );
  185. $next = '<a href="'. $link_next .'">' ._CMN_NEXT . _CMN_NEXT_ARROW .'</a>';
  186. } else {
  187. $next = _CMN_NEXT;
  188. }
  189. if ( $page > 0 ) {
  190. $link_prev = $link .'&amp;limit=1&amp;limitstart='. ( $page - 1 );
  191. $link_prev = sefRelToAbs( $link_prev );
  192. $prev = '<a href="'. $link_prev .'">'. _CMN_PREV_ARROW . _CMN_PREV .'</a>';
  193. } else {
  194. $prev = _CMN_PREV;
  195. }
  196. $row->text .= '<div>' . $prev . ' - ' . $next .'</div>';
  197. }
  198. ?>