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

