Files
@ c7d7e38b2269
Branch filter:
Location: hot67beta/plugins/content/pagebreak.php
c7d7e38b2269
6.4 KiB
text/x-php
Initial import of the site.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 | <?php
/**
* @version $Id: pagebreak.php 10906 2008-09-05 07:27:34Z willebil $
* @package Joomla
* @copyright Copyright (C) 2005 - 2008 Open Source Matters. All rights reserved.
* @license GNU/GPL, see LICENSE.php
* Joomla! is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
*/
// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );
$mainframe->registerEvent( 'onPrepareContent', 'plgContentPagebreak' );
/**
* Page break plugin
*
* <b>Usage:</b>
* <code><hr class="system-pagebreak" /></code>
* <code><hr class="system-pagebreak" title="The page title" /></code>
* or
* <code><hr class="system-pagebreak" alt="The first page" /></code>
* or
* <code><hr class="system-pagebreak" title="The page title" alt="The first page" /></code>
* or
* <code><hr class="system-pagebreak" alt="The first page" title="The page title" /></code>
*
*/
function plgContentPagebreak( &$row, &$params, $page=0 )
{
// expression to search for
$regex = '#<hr([^>]*?)class=(\"|\')system-pagebreak(\"|\')([^>]*?)\/*>#iU';
// Get Plugin info
$plugin =& JPluginHelper::getPlugin('content', 'pagebreak');
$pluginParams = new JParameter( $plugin->params );
$print = JRequest::getBool('print');
$showall = JRequest::getBool('showall');
if (!$pluginParams->get('enabled', 1)) {
$print = true;
}
if ($print) {
$row->text = preg_replace( $regex, '<br />', $row->text );
return true;
}
//simple performance check to determine whether bot should process further
if ( strpos( $row->text, 'class="system-pagebreak' ) === false && strpos( $row->text, 'class=\'system-pagebreak' ) === false ) {
return true;
}
$db =& JFactory::getDBO();
$view = JRequest::getCmd('view');
if(!$page) {
$page = 0;
}
// check whether plugin has been unpublished
if (!JPluginHelper::isEnabled('content', 'pagebreak') || $params->get( 'intro_only' )|| $params->get( 'popup' ) || $view != 'article') {
$row->text = preg_replace( $regex, '', $row->text );
return;
}
// find all instances of plugin and put in $matches
$matches = array();
preg_match_all( $regex, $row->text, $matches, PREG_SET_ORDER );
if (($showall && $pluginParams->get('showall', 1) ))
{
$hasToc = $pluginParams->get( 'multipage_toc', 1 );
if ( $hasToc ) {
// display TOC
$page = 1;
plgContentCreateTOC( $row, $matches, $page );
} else {
$row->toc = '';
}
$row->text = preg_replace( $regex, '<BR/>', $row->text );
return true;
}
// split the text around the plugin
$text = preg_split( $regex, $row->text );
// count the number of pages
$n = count( $text );
// we have found at least one plugin, therefore at least 2 pages
if ($n > 1)
{
// Get plugin parameters
$pluginParams = new JParameter( $plugin->params );
$title = $pluginParams->get( 'title', 1 );
$hasToc = $pluginParams->get( 'multipage_toc', 1 );
// adds heading or title to <site> Title
if ( $title )
{
if ( $page ) {
$page_text = $page + 1;
if ( $page && @$matches[$page-1][2] )
{
$attrs = JUtility::parseAttributes($matches[$page-1][1]);
if ( @$attrs['title'] ) {
$row->page_title = $attrs['title'];
}
}
}
}
// reset the text, we already hold it in the $text array
$row->text = '';
// display TOC
if ( $hasToc ) {
plgContentCreateTOC( $row, $matches, $page );
} else {
$row->toc = '';
}
// traditional mos page navigation
jimport('joomla.html.pagination');
$pageNav = new JPagination( $n, $page, 1 );
// page counter
$row->text .= '<div class="pagenavcounter">';
$row->text .= $pageNav->getPagesCounter();
$row->text .= '</div>';
// page text
$text[$page] = str_replace("<hr id=\"\"system-readmore\"\" />", "", $text[$page]);
$row->text .= $text[$page];
$row->text .= '<br />';
$row->text .= '<div class="pagenavbar">';
// adds navigation between pages to bottom of text
if ( $hasToc ) {
plgContentCreateNavigation( $row, $page, $n );
}
// page links shown at bottom of page if TOC disabled
if (!$hasToc) {
$row->text .= $pageNav->getPagesLinks();
}
$row->text .= '</div><br />';
}
return true;
}
function plgContentCreateTOC( &$row, &$matches, &$page )
{
$heading = $row->title;
// TOC Header
$row->toc = '
<table cellpadding="0" cellspacing="0" class="contenttoc">
<tr>
<th>'
. JText::_( 'Article Index' ) .
'</th>
</tr>
';
// TOC First Page link
$row->toc .= '
<tr>
<td>
<a href="'. JRoute::_( '&showall=&limitstart=') .'" class="toclink">'
. $heading .
'</a>
</td>
</tr>
';
$i = 2;
foreach ( $matches as $bot )
{
$link = JRoute::_( '&showall=&limitstart='. ($i-1) );
if ( @$bot[0] )
{
$attrs2 = JUtility::parseAttributes($bot[0]);
if ( @$attrs2['alt'] )
{
$title = stripslashes( $attrs2['alt'] );
}
elseif ( @$attrs2['title'] )
{
$title = stripslashes( $attrs2['title'] );
}
else
{
$title = JText::sprintf( 'Page #', $i );
}
}
else
{
$title = JText::sprintf( 'Page #', $i );
}
$row->toc .= '
<tr>
<td>
<a href="'. $link .'" class="toclink">'
. $title .
'</a>
</td>
</tr>
';
$i++;
}
// Get Plugin info
$plugin =& JPluginHelper::getPlugin('content', 'pagebreak');
$params = new JParameter( $plugin->params );
if ($params->get('showall') )
{
$link = JRoute::_( '&showall=1&limitstart=');
$row->toc .= '
<tr>
<td>
<a href="'. $link .'" class="toclink">'
. JText::_( 'All Pages' ) .
'</a>
</td>
</tr>
';
}
$row->toc .= '</table>';
}
function plgContentCreateNavigation( &$row, $page, $n )
{
$pnSpace = "";
if (JText::_( '<' ) || JText::_( '>' )) $pnSpace = " ";
if ( $page < $n-1 )
{
$page_next = $page + 1;
$link_next = JRoute::_( '&limitstart='. ( $page_next ) );
// Next >>
$next = '<a href="'. $link_next .'">' . JText::_( 'Next' ) . $pnSpace . JText::_( '>' ) . JText::_( '>' ) .'</a>';
}
else
{
$next = JText::_( 'Next' );
}
if ( $page > 0 )
{
$page_prev = $page - 1 == 0 ? "" : $page - 1;
$link_prev = JRoute::_( '&limitstart='. ( $page_prev) );
// << Prev
$prev = '<a href="'. $link_prev .'">'. JText::_( '<' ) . JText::_( '<' ) . $pnSpace . JText::_( 'Prev' ) .'</a>';
}
else
{
$prev = JText::_( 'Prev' );
}
$row->text .= '<div>' . $prev . ' - ' . $next .'</div>';
}
|