[ Index ] |
|
Code source de Joomla 1.0.13 |
1 <?php 2 /** 3 * @version $Id: mospaging.php 2576 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 14 // no direct access 15 defined( '_VALID_MOS' ) or die( 'Restricted access' ); 16 17 $_MAMBOTS->registerFunction( 'onPrepareContent', 'botMosPaging' ); 18 19 /** 20 * Page break mambot 21 * 22 * <b>Usage:</b> 23 * <code>{mospagebreak}</code> 24 * <code>{mospagebreak title=The page title}</code> 25 * or 26 * <code>{mospagebreak heading=The first page}</code> 27 * or 28 * <code>{mospagebreak title=The page title&heading=The first page}</code> 29 * or 30 * <code>{mospagebreak heading=The first page&title=The page title}</code> 31 * 32 */ 33 function botMosPaging( $published, &$row, &$params, $page=0 ) { 34 global $mainframe, $Itemid, $database, $_MAMBOTS; 35 36 // simple performance check to determine whether bot should process further 37 if ( strpos( $row->text, 'mospagebreak' ) === false ) { 38 return true; 39 } 40 41 // expression to search for 42 $regex = '/{(mospagebreak)\s*(.*?)}/i'; 43 44 // check whether mambot has been unpublished 45 if (!$published || $params->get( 'intro_only' )|| $params->get( 'popup' )) { 46 $row->text = preg_replace( $regex, '', $row->text ); 47 return; 48 } 49 50 // find all instances of mambot and put in $matches 51 $matches = array(); 52 preg_match_all( $regex, $row->text, $matches, PREG_SET_ORDER ); 53 54 // split the text around the mambot 55 $text = preg_split( $regex, $row->text ); 56 57 // count the number of pages 58 $n = count( $text ); 59 60 // we have found at least one mambot, therefore at least 2 pages 61 if ($n > 1) { 62 // check if param query has previously been processed 63 if ( !isset($_MAMBOTS->_content_mambot_params['mospaging']) ) { 64 // load mambot params info 65 $query = "SELECT params" 66 . "\n FROM #__mambots" 67 . "\n WHERE element = 'mospaging'" 68 . "\n AND folder = 'content'" 69 ; 70 $database->setQuery( $query ); 71 $database->loadObject($mambot); 72 73 // save query to class variable 74 $_MAMBOTS->_content_mambot_params['mospaging'] = $mambot; 75 } 76 77 // pull query data from class variable 78 $mambot = $_MAMBOTS->_content_mambot_params['mospaging']; 79 80 $botParams = new mosParameters( $mambot->params ); 81 82 $title = $botParams->def( 'title', 1 ); 83 84 // adds heading or title to <site> Title 85 if ( $title ) { 86 $page_text = $page + 1; 87 $row->page_title = _PN_PAGE .' '. $page_text; 88 if ( !$page ) { 89 // processing for first page 90 parse_str( html_entity_decode( $matches[0][2] ), $args ); 91 92 if ( @$args['heading'] ) { 93 //$row->page_title = $args['heading']; 94 $row->page_title = ''; 95 } else { 96 $row->page_title = ''; 97 } 98 } else if ( $matches[$page-1][2] ) { 99 parse_str( html_entity_decode( $matches[$page-1][2] ), $args ); 100 101 if ( @$args['title'] ) { 102 $row->page_title = ': '. stripslashes( $args['title'] ); 103 } 104 } 105 } 106 107 // reset the text, we already hold it in the $text array 108 $row->text = ''; 109 110 $hasToc = $mainframe->getCfg( 'multipage_toc' ); 111 112 if ( $hasToc ) { 113 // display TOC 114 createTOC( $row, $matches, $page ); 115 } else { 116 $row->toc = ''; 117 } 118 119 // traditional mos page navigation 120 require_once( $GLOBALS['mosConfig_absolute_path'] . '/includes/pageNavigation.php' ); 121 $pageNav = new mosPageNav( $n, $page, 1 ); 122 123 // page counter 124 $row->text .= '<div class="pagenavcounter">'; 125 $row->text .= $pageNav->writeLeafsCounter(); 126 $row->text .= '</div>'; 127 128 // page text 129 $row->text .= $text[$page]; 130 131 $row->text .= '<br />'; 132 $row->text .= '<div class="pagenavbar">'; 133 134 // adds navigation between pages to bottom of text 135 if ( $hasToc ) { 136 createNavigation( $row, $page, $n ); 137 } 138 139 // page links shown at bottom of page if TOC disabled 140 if (!$hasToc) { 141 $row->text .= $pageNav->writePagesLinks( 'index.php?option=com_content&task=view&id='. $row->id .'&Itemid='. $Itemid ); 142 } 143 144 $row->text .= '</div><br />'; 145 } 146 147 return true; 148 } 149 150 function createTOC( &$row, &$matches, &$page ) { 151 global $Itemid; 152 153 $nonseflink = 'index.php?option=com_content&task=view&id='. $row->id .'&Itemid='. $Itemid; 154 $link = 'index.php?option=com_content&task=view&id='. $row->id .'&Itemid='. $Itemid; 155 $link = sefRelToAbs( $link ); 156 157 $heading = $row->title; 158 // allows customization of first page title by checking for `heading` attribute in first bot 159 if ( @$matches[0][2] ) { 160 parse_str( html_entity_decode( $matches[0][2] ), $args ); 161 162 if ( @$args['heading'] ) { 163 $heading = $args['heading']; 164 $row->title .= ' - '. $heading; 165 } 166 } 167 168 // TOC Header 169 $row->toc = ' 170 <table cellpadding="0" cellspacing="0" class="contenttoc" align="right"> 171 <tr> 172 <th>' 173 . _TOC_JUMPTO . 174 '</th> 175 </tr> 176 '; 177 178 // TOC First Page link 179 $row->toc .= ' 180 <tr> 181 <td> 182 <a href="'. $link .'" class="toclink">' 183 . $heading . 184 '</a> 185 </td> 186 </tr> 187 '; 188 189 $i = 2; 190 $args2 = array(); 191 192 foreach ( $matches as $bot ) { 193 $link = $nonseflink .'&limit=1&limitstart='. ($i-1); 194 $link = sefRelToAbs( $link ); 195 196 if ( @$bot[2] ) { 197 parse_str( html_entity_decode( $bot[2] ), $args2 ); 198 199 if ( @$args2['title'] ) { 200 $row->toc .= ' 201 <tr> 202 <td> 203 <a href="'. $link .'" class="toclink">' 204 . stripslashes( $args2['title'] ) . 205 '</a> 206 </td> 207 </tr> 208 '; 209 } else { 210 $row->toc .= ' 211 <tr> 212 <td> 213 <a href="'. $link .'" class="toclink">' 214 . _PN_PAGE .' '. $i . 215 '</a> 216 </td> 217 </tr> 218 '; 219 } 220 } else { 221 $row->toc .= ' 222 <tr> 223 <td> 224 <a href="'. $link .'" class="toclink">' 225 . _PN_PAGE .' '. $i . 226 '</a> 227 </td> 228 </tr> 229 '; 230 } 231 $i++; 232 } 233 234 $row->toc .= '</table>'; 235 } 236 237 function createNavigation( &$row, $page, $n ) { 238 global $Itemid; 239 240 $link = 'index.php?option=com_content&task=view&id='. $row->id .'&Itemid='. $Itemid; 241 242 if ( $page < $n-1 ) { 243 $link_next = $link .'&limit=1&limitstart='. ( $page + 1 ); 244 $link_next = sefRelToAbs( $link_next ); 245 246 $next = '<a href="'. $link_next .'">' ._CMN_NEXT . _CMN_NEXT_ARROW .'</a>'; 247 } else { 248 $next = _CMN_NEXT; 249 } 250 251 if ( $page > 0 ) { 252 $link_prev = $link .'&limit=1&limitstart='. ( $page - 1 ); 253 $link_prev = sefRelToAbs( $link_prev ); 254 255 $prev = '<a href="'. $link_prev .'">'. _CMN_PREV_ARROW . _CMN_PREV .'</a>'; 256 } else { 257 $prev = _CMN_PREV; 258 } 259 260 $row->text .= '<div>' . $prev . ' - ' . $next .'</div>'; 261 } 262 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Wed Nov 21 14:43:32 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |