Current File : /home/pacjaorg/public_html/kmm/plugins/djclassifieds/pagebreak/pagebreak.php |
<?php
/**
* @package DJ-Classifieds
* @copyright Copyright (C) DJ-Extensions.com, All rights reserved.
* @license http://www.gnu.org/licenses GNU/GPL
* @author url: http://dj-extensions.com
* @author email: contact@dj-extensions.com
*/
use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Utility\Utility;
defined( '_JEXEC' ) or die( 'Restricted access' );
class plgDJClassifiedsPagebreak extends JPlugin
{
public function __construct(& $subject, $config)
{
parent::__construct($subject, $config);
$this->loadLanguage();
}
function onPrepareItemDescription( &$row, &$params, $page=0 )
{
$app = JFactory::getApplication();
if($app->input->getVar('view') != 'item' || empty($row->description)){
return true;
}
// expression to search for
$regex = '#<hr([^>]*?)class=(\"|\')system-pagebreak(\"|\')([^>]*?)\/*>#iU';
JPlugin::loadLanguage( 'plg_djclassifieds_pagebreak', JPATH_ADMINISTRATOR );
// replacing readmore with <br /> - we don't need it
$row->description = str_replace("<hr id=\"system-readmore\" />", "<br />", $row->description);
if ( strpos( $row->description, 'class="system-pagebreak' ) === false && strpos( $row->description, 'class=\'system-pagebreak' ) === false ) {
return true;
}
$view = $app->input->get('view', null, 'string');
if (!JPluginHelper::isEnabled('djclassifieds', 'pagebreak') || ($view != 'item' && $view != 'itemstable' && $view != 'items' && $view != 'producer')) {
$row->description = preg_replace( $regex, '', $row->description );
return;
}
// find all instances of plugin and put in $matches
$matches = array();
preg_match_all( $regex, $row->description, $matches, PREG_SET_ORDER );
// split the text around the plugin
$text = preg_split( $regex, $row->description );
$title = array();
// count the number of pages
$n = count( $text );
if ($n > 1)
{
$pluginParams = $this->params;
$style = $pluginParams->get( 'accordion', 2 );
$row->description = '';
$row->description .= $text[0];
$row->tabs = '';
if ($style == '1' || $style == '2') {
$style = $style == '2' ? 'tabs' : 'sliders';
$t = array();
if(version_compare(JVERSION, '4', '>=')){
if ($style === 'tabs') {
$t[] = (string) HTMLHelper::_('uitab.startTabSet', 'myTab', ['active' => 'item' . $row->id . '-' . $style . '0', 'view' => 'tabs']);
} else {
$t[] = (string) HTMLHelper::_('bootstrap.startAccordion', 'myAccordion', ['active' => 'item' . $row->id . '-' . $style . '0']);
}
foreach ($text as $key => $subtext) {
$index = 'item' . $row->id . '-' . $style . $key;
if ($key >= 1) {
$match = $matches[$key - 1];
$match = (array) Utility::parseAttributes($match[0]);
if (isset($match['alt'])) {
$title = stripslashes($match['alt']);
} elseif (isset($match['title'])) {
$title = stripslashes($match['title']);
} else {
$title = Text::sprintf('PLG_CONTENT_PAGEBREAK_PAGE_NUM', $key + 1);
}
if ($style === 'tabs') {
$t[] = (string) HTMLHelper::_('uitab.addTab', 'myTab', $index, $title);
} else {
$t[] = (string) HTMLHelper::_('bootstrap.addSlide', 'myAccordion', $title, $index);
}
$t[] = (string) $subtext;
if ($style === 'tabs') {
$t[] = (string) HTMLHelper::_('uitab.endTab');
} else {
$t[] = (string) HTMLHelper::_('bootstrap.endSlide');
}
}
}
if ($style === 'tabs') {
$t[] = (string) HTMLHelper::_('uitab.endTabSet');
} else {
$t[] = (string) HTMLHelper::_('bootstrap.endAccordion');
}
} else {
$t[] = (string) JHtml::_($style . '.start', 'article' . $row->id . '-' . $style);
foreach ($text as $key => $subtext)
{
if ($key >= 1)
{
$match = $matches[$key - 1];
$match = (array) JUtility::parseAttributes($match[0]);
if (isset($match['alt']))
{
$title = stripslashes($match['alt']);
}
elseif (isset($match['title']))
{
$title = stripslashes($match['title']);
}
else
{
$title = JText::sprintf('PLG_CONTENT_PAGEBREAK_PAGE_NUM', $key + 1);
}
$t[] = (string) JHtml::_($style . '.panel', $title, 'article' . $row->id . '-' . $style . $key);
}
$t[] = (string) $subtext;
}
$t[] = (string) JHtml::_($style . '.end');
}
$row->tabs = str_replace(array('<h2 ','</h2>'), array('<h3 ', '</h3>'), implode(' ', $t));
} else {
$row->tabs .= '<div class="djcf_pagebreak">';
for($i = 1; $i < $n; $i++) {
$row->tabs .= '<h3 class="djcf_pagebreak-title">'.$title[$i-1].'</h3>';
$row->tabs .= '<div class="djcf_pagebreak-content">'.$text[$i].'</div>';
}
$row->tabs .= '</div>';
}
}
}
}