PageRenderTime 24ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/4.8/mambots/content/mospaging.php

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