В php пока не рублю, поэтому прошу знающих людей помочь.
<?php
/**
* Joomla! 1.7 autoPageBreak plugin
*
* @url http://joomalungma.com
* date generated:
* @version 0.4
* @author Nikita Zonov
* @package plg_content_autopagebreak
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
**/
defined( '_JEXEC' ) or die( 'Restricted access' );
// Import library dependencies
jimport('joomla.event.plugin');
class plgContentAutopagebreak extends JPlugin
{
//function onPrepareContent(&$row, &$params, $limitstart) {
function onContentPrepare($context, &$row, &$params, $page = 0)
{
$text = $this->paging($row->text);
$row->text = $text;
}
private function paging($text)
{
$denyPattern ='#{!apb}#iU';
if(preg_match($denyPattern, $text)) return $text;
$regex = '#<hr(.*)class="system-pagebreak"(.*)\/>#iU';
if (!preg_match($regex, $text)) // there is no PageBreak in the article
{
//params
$paging_number = $this->params->get('paging_number', 3000);
$skiplist = $this->params->get('skiplist', 1);
$skiptable = $this->params->get('skiptable', 1);
// change Tables and List to the simple-one-word-tags
$tmp_text = $text;
$lists = array();
$tables = array();
if($skiplist)
{
$pattern= '/<ul[\s,>](.*)\/ul>/s';
preg_match_all($pattern,$text,$matches);
$lists = $matches[0];
$tmp_text = str_replace($lists, '{list}', $text);
}
if($skiptable)
{
$pattern= '/<table[\s,>](.*)\/table>/s';
preg_match_all($pattern,$tmp_text,$matches);
$tables = $matches[0];
$tmp_text = str_replace($tables, '{table}', $tmp_text);
}
//break into pages
$ids = explode(':',JRequest::getString('id'));
$article_id = $ids[0];
$article =& JTable::getInstance("content");
$article->load($article_id);
$articleTitle = $article->get("title");
$body = $tmp_text;
$words_count = mb_strlen($body,'UTF-8');
$i = 0;
$bodycount = 0;
if ($words_count > $paging_number) {
while (strlen(trim($body)) && ($i<1000)) {
$bodypart[$i] = $this->paging_paragraph_split($body, $paging_number);
$bodycount += mb_strlen($bodypart[$i],'UTF-8');
$body = mb_substr($tmp_text, $bodycount, $paging_number, 'UTF-8');
$i++;
}
//$text = implode('<hr title="Page title" alt="Toc ALiase" class="system-pagebreak" />', $bodypart);
$text ='';
$pageNumber = 1;
foreach ($bodypart as $page)
{
$pageNumber++;
$text .= $page;
if (next($bodypart)) {
$text .= '<hr title="'. $articleTitle . '" alt="Стр. ' . $pageNumber . '" class="system-pagebreak" />';
}
}
}
// insert Tables and lists back into Article
$text = str_replace('{table}',implode('',$tables),$text);
$text = str_replace('{list}',implode('',$lists),$text);
}
return $text;
}
private function paging_paragraph_split($body, $size) {
if (mb_strlen($body,'UTF-8') < $size) {
return $body;
}
$teaser = mb_substr($body, 0, $size,'UTF-8');
$position = 0;
$length = 0;
$breakpoints = array('</p>','<br />','<br>',"\n","</table>","</ul>");
foreach ($breakpoints as $point) {
$length_ = mb_strrpos($teaser, $point,'UTF-8');
if ($length_ > $length) $length = $length_;
}
if ($length) {
$position = $length;
return ($position == 0)? $teaser : mb_substr($teaser, 0, $position,'UTF-8');
}
$breakpoints = array('. ', '!', '?', ' - ');
foreach ($breakpoints as $point) {
$length_ = mb_strrpos($teaser, $point,'UTF-8');
if ($length_ > $length) $length = $length_;
}
if ($length) {
$position = $length;
}
return ($position == 0)? $teaser : mb_substr($teaser, 0, $position,'UTF-8');
}
}