k24
19-12-2011, 21:31
Witam Was,
Mój problem dotyczy dodatku jkefel - dodatek do tworzenia zakładek z modułami, bądź jak kto woli - tabsów (w sumie nie wiem jak fachowo to się nazywa). Z wielu pdoobnych ten spełnia moje oczekiwania, wyświetla się dobrze poza IE. Niżej fragment strony, u góry prawidłowo pod Firefoxem i Operą, niżej z dużym odstępem pod IE
4814
Konfuguracja modułu z poziomu panelu administracyjnego nie daje możliwości zmiany, natomiast kod źródłowy dodatku, podstawową wiedzę mam, ale nie moge sobie z tym poradzić. Brak mi fachowego spojrzenia na całość.
Poniżej zamieszczam:
<?php
defined('_JEXEC') or die('Restricted access');
jimport('joomla.plugin.plugin');
require_once JPATH_ROOT . '/libraries/joomla/html/pane.php';
class plgContentjkefel extends JPlugin {
static $counter = 0, $stack = array();
static $jkefelRoot = '';
function plgContentjkefel(&$subject, $config) {
parent::__construct($subject, $config);
plgContentjkefel::$jkefelRoot = JURI::root().'plugins/content/jkefel/'.(plgSystemjkefel::isJ16() ? 'jkefel/' : '');
$this->loadLanguage();
}
public function onContentPrepare($context, &$article, &$params, $limitstart) {
$this->onPrepareContent($article, $params);
}
function onPrepareContent(&$article, &$params ) {
plgContentjkefel::jkefel($article->text);
plgContentjkefel::$stack = array();
}
public static function jkefel(&$text) {
$pos = 0;
$found = false;
$curr = true;
while ($pos !== false && $curr) {
$curr = plgContentjkefel::recur($text, $pos);
if ($curr === true) {
plgContentjkefel::$counter++;
$found = true;
}
$pos = strpos($text, '{jkefel');
}
}
static function removeJKefel(&$text) {
$text = preg_replace('#{jkefel.*?{/jkefelend}#Ui', '', $text);
}
protected static function recur(&$content, $pos = 0) {
$tabGroup = null;
$tabsFound = 0;
$groupStart = strpos($content, '{jkefel', $pos);
if ($groupStart === false) {
return false;
}
$ending = strpos($content, '{/jkefel}', $pos);
if ($ending === false) {
$ending = strpos($content, '{/jkefelend}', $pos);
}
if ($ending <= $groupStart) {
JError::raiseWarning( 'SOME_ERROR_CODE', 'jkefel: '.JText::_('Incorrect jkefel definition: premature jkefel end.'));
return false;
}
$groupEnd = strpos($content, '{/jkefelend}', $groupStart);
if ($groupEnd === false) {
JError::raiseWarning( 'SOME_ERROR_CODE', 'jkefel: '.JText::_('Incorrect jkefel definition: no jkefel end found.'));
return false;
}
$continueTab = true;
$tabGroup = plgContentjkefel::processTabGroupStart($content, $groupStart);
while ($continueTab) {
$tabStart = strpos($content, '{jkefel', $pos);
if ($tabStart === false) {
$continueTab = false;
break;
}
$tabEnd = strpos($content, '{/jkefel}', $tabStart);
$nextTabStart = strpos($content, '{jkefel', $tabStart + 1);
if ($tabEnd === false || $tabEnd > $groupEnd) {
$tabEnd = $groupEnd;
$continueTab = false;
}
// a new tab group found inside a tab
if ($nextTabStart !== false && $nextTabStart < $tabEnd) {
plgContentjkefel::recur($content, $nextTabStart);
// reposition tab ends since content is now modified
$groupEnd = strpos($content, '{/jkefelend}', $nextTabStart);
$tabEnd = strpos($content, '{/jkefel}', $nextTabStart);
if ($tabEnd === false || $tabEnd > $groupEnd) {
$tabEnd = $groupEnd;
$continueTab = false;
} else {
$continueTab = true;
}
}
plgContentjkefel::processTab($content, $tabStart, ($continueTab ? false : $groupEnd), $tabGroup);
$pos = $tabEnd;
$tabsFound++;
}
plgContentjkefel::processTabGroupEnd($tabGroup);
$content =
substr($content, 0, $groupStart)
. $tabGroup['ui']
. substr($content, $groupEnd + strlen('{/jkefelend}'));
return $tabsFound > 0;
}
protected static function value($name, $definition, $value = '') {
$pos = plgContentjkefel::strpos_balanced('[', ']', $definition, ' '.$name.'=');
if ($pos !== false) {
return substr($definition, $pos[0], $pos[1]);
}
return $value !== '' ? $value : false;
}
static function strpos_balanced($findStart, $findEnd, $str, $startAt) {
if (!is_numeric($startAt)) {
$_startAt = $startAt;
$startAt = strpos($str, $startAt);
if ($startAt !== false) $startAt += strlen($_startAt) + 1;
}
if ($startAt === false) return false;
$pos = $startAt;
$max = strlen($str);
$found = false;
$ch = '';
while ($pos < $max) {
$ch = $str[$pos];
if ($ch == $findStart) {
$found = true;
} else if ($ch == $findEnd) {
if ($found) {
$found = false;
} else {
break;
}
}
$pos++;
}
if ($ch == $findEnd) {
return array($startAt, $pos - $startAt);
}
return false;
}
protected static function processTab($content, $tabStart, $groupEnd, &$tabGroup) {
$tabDefinition = substr($content, $tabStart, strpos($content, '}', $tabStart) - $tabStart + 1);
$contentStart = strpos($content, '}', $tabStart);
$contentEnd = $groupEnd === false ? strpos($content, '{/jkefel}', $contentStart) : $groupEnd;
$content = substr($content, $contentStart + 1, $contentEnd - $contentStart - 1);
$title = plgContentjkefel::value('title', $tabDefinition, '');
$tabId = 'jkefel-'.$tabGroup['count'].'-'.$tabGroup['tabId'];
$tabId = plgContentjkefel::value('id', $tabDefinition, $tabId);
$isAjax = false;
$pos = plgContentjkefel::value('pos', $tabDefinition, plgContentjkefel::param('remoteContentPos'));
$addContent = '';
$wire = array();
if (($val = plgContentjkefel::value('url', $tabDefinition, false)) !== false) {
$isAjax = true;
$addContent = '<span class="ajax_container"></span>';
$wire[] = 'href:"'.$val.'"';
}
if (($val = plgContentjkefel::value('onsuccessp', $tabDefinition, false)) !== false) {
$wire[] = 'onsuccessp:"'.$val.'"';
}
if (($val = plgContentjkefel::value('onsuccess', $tabDefinition, false)) !== false) {
$wire[] = 'onsuccess:"'.$val.'"';
}
if (($val = plgContentjkefel::value('refresh', $tabDefinition, false)) !== false) {
$wire[] = 'refresh:"'.($val == 'true' || $val == '1' ? 'true' : 'false').'"';
}
if (($val = plgContentjkefel::value('freq', $tabDefinition, false)) !== false) {
$wire[] = 'freq:'.$val;
}
if (($val = plgContentjkefel::value('mod', $tabDefinition, false)) !== false) {
$_addContent = plgContentjkefel::getModule($val);
if (strtolower($title) == 'moduletitle' || empty($title)) {
$title = $_addContent['title'];
}
$addContent .= $_addContent['content'];
}
if ($addContent) {
if ($pos == 'replace') {
$content = $addContent;
} else if ($pos == 'append') {
$content .= $addContent;
} else if ($pos == 'prepend') {
$content = $addContent.$content;
}
}
if (empty($title)) {
$title = 'Tab '.$tabGroup['tabId'];
}
$tabGroup['ui'] .= $tabGroup['pane']->startPanel($title, $tabId);
$tabGroup['ui'] .= $content.'<div class="clr"> </div>';
$tabGroup['ui'] .= $tabGroup['pane']->endPanel();
if (!empty($wire)) {
$wire[] = 'id:"'.$tabId.'"';
$tabGroup['wire'] .= (!empty($tabGroup['wire']) ? ', ' : '') . '{'. implode(',', $wire) . '}';
}
$tabGroup['tabId']++;
}
protected static function processTabGroupStart($content, $groupStart) {
static $lastKefelId = 1;
$tabDefinition = substr($content, $groupStart, strpos($content, '}', $groupStart) - $groupStart + 1);
$jpaneId = 'jkefel'.$lastKefelId;
$jpaneId = plgContentjkefel::value('kefelid', $tabDefinition, $jpaneId);
$ui = plgContentjkefel::param('ui');
$ui = plgContentjkefel::value('kefelui', $tabDefinition, $ui);
$persistTab = plgContentjkefel::param('persistTab');
$persistTab = plgContentjkefel::value('persist', $tabDefinition, $persistTab);
$triggerEvent = plgContentjkefel::value('trigger', $tabDefinition, 'click');
if (JString::substr($ui, 0, 3) == 'tab') {
$ui = 'tabs';
} else if (JString::substr($ui, 0, 5) == 'slide') {
$ui = 'sliders';
}
$paneParams = array('firstElementsOpen' => '');
if (($val = plgContentjkefel::value('initial', $tabDefinition, false)) !== false) {
$ps = explode(',', $val);
for ($i = 0, $n = count($ps); $i < $n; $i++) {
$ps[$i]--;
}
if ($ui == 'tabs') {
if ($n > 0) {
$paneParams['firstElementsOpen'] = $ps[0];
}
} else {
$paneParams['firstElementsOpen'] = implode(',', $ps);
}
}
jimport( 'joomla.html.pane' );
$pane = null;
if (strtolower($ui) == 'sliders') {
$paneParams['allowMultipleOpen'] = 'true';
if (($val = plgContentjkefel::value('single', $tabDefinition, false)) !== false) {
$paneParams['allowMultipleOpen'] = $val ? 'false' : 'true';
}
$pane = new JKefelSliders($paneParams);
} else {
$pane = new JKefelTabs($paneParams);
}
$result = array('pane'=>$pane);
$result['uitype'] = $ui;
$result['ui'] = '<div class="jkefel">'.$result['pane']->startPane($jpaneId);
$result['id'] = $jpaneId;
$result['wire'] = '';
$result['count'] = $lastKefelId;
$result['tabId'] = 1;
$result['persist'] = $persistTab;
$result['initial'] = $paneParams['firstElementsOpen'];
$result['trigger'] = $triggerEvent;
$lastKefelId++;
plgContentjkefel::$stack[] = '_'.$jpaneId;
return $result;
}
public static function includeResource($resource, $type) {
$document = JFactory::getDocument();
if ($type == 'css') {
$document->addStyleSheet(plgContentjkefel::$jkefelRoot . $resource);
} else if ($type == 'js') {
$document->addScript(plgContentjkefel::$jkefelRoot . $resource);
}
}
protected static function processTabGroupEnd(&$tabGroup) {
static $loaded = array();
$tabGroup['ui'] .= $tabGroup['pane']->endPane().'</div><div class="clr"> </div>';
$tabGroup['wire'] = '['.$tabGroup['wire'].']';
$document = JFactory::getDocument();
if (!isset($loaded[$tabGroup['uitype']])) {
plgContentjkefel::includeResource('jkefel.js', 'js');
plgContentjkefel::includeResource('jkefel.css', 'css');
$loaded[$tabGroup['uitype']] = true;
}
$initial = '';
if ($tabGroup['uitype'] == 'tabs') {
$initial = ', initial: ' . (!empty($tabGroup['initial']) ? $tabGroup['initial'] : '0');
}
$containerKefel = 'null';
$cnt = count(plgContentjkefel::$stack);
if ($cnt > 1) {
$containerKefel = plgContentjkefel::$stack[$cnt - 2];
}
$document->addScriptDeclaration('
var _'.$tabGroup['id'].' = new jkefel({
kefelId: "'.$tabGroup['id'].'",
cookieName: "_plgcontent_jkefel_",
ui: "'.$tabGroup['uitype'].'",
persistTab: '.((bool) $tabGroup['persist'] ? 'true' : 'false').',
persistMode: "'.plgContentjkefel::param('persistMode').'",
trigger: "'.$tabGroup['trigger'].'",
refreshTab: '.((bool) plgContentjkefel::param('refreshTab') ? 'true' : 'false').',
tracker: '.((bool) plgContentjkefel::param('tracker') ? 'true' : 'false').$initial.'
}, '.$tabGroup['wire'].', "'.$containerKefel.'");
');
array_pop(plgContentjkefel::$stack);
}
protected static function getModule($module) {
// Slightly customized version of joomla.application.module.helper._load to load a specific module
$app = JFactory::getApplication();
$user = JFactory::getUser();
$db = JFactory::getDBO();
$access = plgSystemjkefel::isJ16() ?
'IN (' . implode(',', $user->getAuthorisedViewLevels()) . ')' :
'<= '. (int) $user->get('aid', 0);
$modules = array();
$query = 'SELECT id, title, module, position, content, showtitle, params'
. ' FROM #__modules AS m'
. ' WHERE m.published = 1'
. ' AND m.access ' . $access
. ' AND m.client_id = '. (int)$app->getClientId()
. ' AND m.id = ' . (int)$module
. ' ORDER BY position, ordering';
$db->setQuery( $query );
if (null === ($modules = $db->loadObjectList())) {
JError::raiseWarning( 'SOME_ERROR_CODE', JText::_( 'Error loading given module' ).' (<em>'.$module .'</em>)');
return false;
}
$total = count($modules);
for($i = 0; $i < $total; $i++)
{
//determine if this is a custom module
$file = $modules[$i]->module;
$custom = substr( $file, 0, 4 ) == 'mod_' ? 0 : 1;
$modules[$i]->user = $custom;
// CHECK: custom module name is given by the title field, otherwise it's just 'om' ??
$modules[$i]->name = $custom ? $modules[$i]->title : substr( $file, 4 );
$modules[$i]->style = null;
$modules[$i]->position = strtolower($modules[$i]->position);
}
jimport('joomla.application.module.helper');
return array('content'=>JModuleHelper::renderModule($modules[0]), 'title'=>$modules[0]->title);
}
public static function param($name, $value = '') {
static $params, $_params;
if (!isset($params)) {
$plg = JPluginHelper::getPlugin('content', 'jkefel');
jimport('joomla.html.parameter');
$params = new JParameter($plg->params);
}
if (!isset($_params[$name])) {
$_params[$name] = $params->get($name);
if (is_string($_params[$name])) $_params[$name] = trim($_params[$name]);
if (!$_params[$name]) {
$_params[$name] = $value;
}
}
return $_params[$name];
}
/**
* taken from Articles Anywhere with the following copyright and with a
* slight modification as noticed in code with removed
* @package Articles Anywhere
* @version 1.5.0
*
* @author Peter van Westen <peter@nonumber.nl>
* @link http://www.nonumber.nl
* @copyright Copyright (C) 2010 NoNumber! All Rights Reserved
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
*/
public static function updateHead( $orig_document )
{
$document = JFactory::getDocument();
$hashead = 0;
if ( !isset( $document->_buffer ) || !isset( $document->_buffer['component'] ) ) {
return;
}
/** removed by gobezu <info@jproven.com>
*
foreach( $document->_buffer['component'] as $buffer ) {
if ( !( strpos( $buffer, '</head>' ) === false ) ) {
$hashead = 1;
break;
}
}
if ( !$hashead ) {
return;
}
*/
$head = JDocumentRendererHead::fetchHead( $document );
// get line endings
$lnEnd = $document->_getLineEnd();
$tab = $document->_getTab();
$tagEnd = ' />';
$strHtml = '';
// Generate link declarations
foreach ($document->_links as $link) {
if ( !in_array( $link, $orig_document->_links ) ) {
$strHtml .= $tab.$link.$tagEnd.$lnEnd;
}
}
// Generate stylesheet links
foreach ($document->_styleSheets as $strSrc => $strAttr ) {
if ( !array_key_exists( $strSrc, $orig_document->_styleSheets ) ) {
$strHtml .= $tab . '<link rel="stylesheet" href="'.$strSrc.'" type="'.$strAttr['mime'].'"';
if (!is_null($strAttr['media'])){
$strHtml .= ' media="'.$strAttr['media'].'" ';
}
$temp = JArrayHelper::toString($strAttr['attribs']);
if ( $temp ) {
$strHtml .= ' '.$temp;
}
$strHtml .= $tagEnd.$lnEnd;
}
}
// Generate stylesheet declarations
foreach ($document->_style as $type => $content) {
if ( !in_array( $content, $orig_document->_style ) ) {
$strHtml .= $tab.'<style type="'.$type.'">'.$lnEnd;
// This is for full XHTML support.
if ($document->_mime == 'text/html' ) {
$strHtml .= $tab.$tab.'<!--'.$lnEnd;
} else {
$strHtml .= $tab.$tab.'<![CDATA['.$lnEnd;
}
$strHtml .= $content . $lnEnd;
// See above note
if ($document->_mime == 'text/html' ) {
$strHtml .= $tab.$tab.'-->'.$lnEnd;
} else {
$strHtml .= $tab.$tab.']]>'.$lnEnd;
}
$strHtml .= $tab.'</style>'.$lnEnd;
}
}
// Generate script file links
foreach ($document->_scripts as $strSrc => $strType) {
if ( !array_key_exists( $strSrc, $orig_document->_scripts ) ) {
$strHtml .= $tab.'<script type="'.$strType.'" src="'.$strSrc.'"></script>'.$lnEnd;
}
}
// Generate script declarations
foreach ($document->_script as $type => $content) {
if ( !in_array( $content, $orig_document->_script ) ) {
$content = trim(str_replace($orig_document->_script[$type], '', $content));
if (empty($content)) continue;
$strHtml .= $tab.'<script type="'.$type.'">'.$lnEnd;
// This is for full XHTML support.
if ($document->_mime != 'text/html' ) {
$strHtml .= $tab.$tab.'<![CDATA['.$lnEnd;
}
$strHtml .= $content . $lnEnd;
// See above note
if ($document->_mime != 'text/html' ) {
$strHtml .= $tab.$tab.'// ]]>'.$lnEnd;
}
$strHtml .= $tab.'</script>'.$lnEnd;
}
}
foreach($document->_custom as $custom) {
if ( !in_array( $custom, $orig_document->_custom ) ) {
$strHtml .= $tab.$custom.$lnEnd;
}
}
JResponse::setBody( str_replace( '</head>', $strHtml."\n".'</head>', JResponse::getBody() ) );
}
public static function replaceElsewhere() {
$app = JFactory::getApplication();
if (!$app->isSite()) {
return;
}
if (!(bool) plgContentjkefel::param('elsewhereEnabled')) {
return;
}
$task = JRequest::getCmd('task');
if ($task == 'edit') {
return;
}
$document = JFactory::getDocument();
$docType = $document->getType();
$doc = clone($document);
if ($docType == 'pdf') {
return;
}
$html = JResponse::getBody();
if ($docType != 'html') {
plgContentjkefel::removeJKefel($html);
JResponse::setBody($html);
} else {
plgContentjkefel::jkefel($html);
JResponse::setBody($html);
plgContentjkefel::updateHead($doc);
}
}
/*
* Since current core implementation can't handle recursively included tabs
* its removed and is replaced by a corrected one...
*/
public static function removeJTABS() {
if (!JPluginHelper::isEnabled('content', 'jkefel') || plgContentjkefel::$counter <= 0) {
return;
}
$app = JFactory::getApplication();
if (!$app->isSite()) {
return;
}
$task = JRequest::getCmd('task');
if ($task == 'edit') {
return;
}
$html = JResponse::getBody();
$cnt = 0;
$src = plgContentjkefel::$jkefelRoot.'jtabs.js';
$html = preg_replace('#(<script.+src=)([\"\'])([^\"\']*)(media\/system\/js\/tabs\.js)(\2[^>]*>)#Ui', '$1$2'.$src.'$5', $html, -1, $cnt);
if ($cnt <= 0) {
$html = str_ireplace('</head>', '<script type="text/javascript" src="'.$src.'"></script></head>', $html);
}
JResponse::setBody($html);
}
}
class JKefelSliders extends JPaneSliders {
var $id = '';
var $params = array();
function __construct( $params = array() ) {
$this->params = $params;
}
function startPane( $id ) {
$this->id = $id;
$this->_loadBehavior();
return '<div id="'.$id.'" class="pane-sliders">';
}
function startPanel( $text, $id ) {
return '<div class="panel">'
.'<h3 class="jpane-toggler title" id="'.$id.'"><span>'.$text.'</span></h3>'
.'<div class="jpane-slider content">';
}
function _loadBehavior() {
$params = $this->params;
JHTML::_('behavior.mootools');
$document = JFactory::getDocument();
$check = JFactory::getApplication()->get('MooToolsVersion');
$is12 = !empty($check) || plgSystemjkefel::isJ16();
$options = $is12 ? '' : '{';
$opt['onActive'] = 'function(toggler, i) { toggler.addClass(\'jpane-toggler-down\'); toggler.removeClass(\'jpane-toggler\'); }';
$opt['onBackground'] = 'function(toggler, i) { toggler.addClass(\'jpane-toggler\'); toggler.removeClass(\'jpane-toggler-down\'); }';
$opt['duration'] = (isset($params['duration'])) ? (int)$params['duration'] : 300;
$opt['display'] = (isset($params['startOffset']) && ($params['startTransition'])) ? (int)$params['startOffset'] : null ;
$opt['show'] = (isset($params['startOffset']) && (!$params['startTransition'])) ? (int)$params['startOffset'] : null ;
$opt['opacity'] = (isset($params['opacityTransition']) && ($params['opacityTransition'])) ? 'true' : 'false' ;
$opt['alwaysHide'] = (isset($params['allowAllClose']) && ($params['allowAllClose'])) ? 'true' : null ;
$opt['firstElementsOpen'] = (isset($params['firstElementsOpen']) ? '['.$params['firstElementsOpen'].']' : '[]');
$opt['openAll'] = (isset($params['openAll']) ? $params['openAll'] : 'false');
$opt['allowMultipleOpen'] = $params['allowMultipleOpen'];
$allowMultipleOpen = $opt['allowMultipleOpen'];
$firstElementsOpen = $opt['firstElementsOpen'];
if ($is12) {
$opt['allowMultipleOpen'] = null;
if ($allowMultipleOpen == 'false') {
$opt['firstElementsOpen'] = null;
if ($firstElementsOpen) {
$firstElementsOpen = str_replace(array('[',']'), '', $firstElementsOpen);
$firstElementsOpen = explode(',',$firstElementsOpen);
$opt['display'] = $firstElementsOpen[0];
}
}
}
foreach ($opt as $k => $v)
{
if ($v) {
$options .= $k.': '.$v.',';
}
}
if (substr($options, -1) == ',') {
$options = substr($options, 0, -1);
}
$options .= $is12 ? '' : '}';
if ($is12) {
if ($allowMultipleOpen == 'false') {
if (!empty($options)) $options = ', {' . $options.'}';
$js = ' window.addEvent(\'domready\', function(){ new Accordion($$(\'#'.$this->id.' .panel h3.jpane-toggler\'), $$(\'#'.$this->id.' .panel div.jpane-slider\')'.$options.'); });';
} else {
if (!empty($options)) $options = ', ' . $options;
$js = ' window.addEvent(\'domready\', function(){ new MultipleOpenAccordion($$(\'#'.$this->id.' .pane-sliders\'), {togglers: $$(\'#'.$this->id.' .panel h3.jpane-toggler\'), elements: $$(\'#'.$this->id.' .panel div.jpane-slider\')'.$options.'}); });';
}
} else {
$js = ' window.addEvent(\'domready\', function(){ new MultipleOpenAccordion($$(\'#'.$this->id.' .panel h3.jpane-toggler\'), $$(\'#'.$this->id.' .panel div.jpane-slider\'), '.$options.'); });';
}
$document->addScriptDeclaration( $js );
if (!$is12 || $is12 && $allowMultipleOpen != 'false') {
plgContentjkefel::includeResource('accordion.1.' . ($is12 ? '2' : '1') . '.js', 'js');
if ($is12) {
plgContentjkefel::includeResource('fx.reveal.js', 'js');
}
}
}
}
class JKefelTabs extends JPaneTabs {
public function startPanel($text, $id) {
return '<dt id="'.$id.'"><span>'.$text.'</span></dt><dd>';
}
}
jest to kod z pliku jkefel.php z katalogu content w dodatkach
W jaki spsoób naprawić błąd, tj. wyświetlanie pod IE?
Z góry bardzo dziękuję za pomoc
Mój problem dotyczy dodatku jkefel - dodatek do tworzenia zakładek z modułami, bądź jak kto woli - tabsów (w sumie nie wiem jak fachowo to się nazywa). Z wielu pdoobnych ten spełnia moje oczekiwania, wyświetla się dobrze poza IE. Niżej fragment strony, u góry prawidłowo pod Firefoxem i Operą, niżej z dużym odstępem pod IE
4814
Konfuguracja modułu z poziomu panelu administracyjnego nie daje możliwości zmiany, natomiast kod źródłowy dodatku, podstawową wiedzę mam, ale nie moge sobie z tym poradzić. Brak mi fachowego spojrzenia na całość.
Poniżej zamieszczam:
<?php
defined('_JEXEC') or die('Restricted access');
jimport('joomla.plugin.plugin');
require_once JPATH_ROOT . '/libraries/joomla/html/pane.php';
class plgContentjkefel extends JPlugin {
static $counter = 0, $stack = array();
static $jkefelRoot = '';
function plgContentjkefel(&$subject, $config) {
parent::__construct($subject, $config);
plgContentjkefel::$jkefelRoot = JURI::root().'plugins/content/jkefel/'.(plgSystemjkefel::isJ16() ? 'jkefel/' : '');
$this->loadLanguage();
}
public function onContentPrepare($context, &$article, &$params, $limitstart) {
$this->onPrepareContent($article, $params);
}
function onPrepareContent(&$article, &$params ) {
plgContentjkefel::jkefel($article->text);
plgContentjkefel::$stack = array();
}
public static function jkefel(&$text) {
$pos = 0;
$found = false;
$curr = true;
while ($pos !== false && $curr) {
$curr = plgContentjkefel::recur($text, $pos);
if ($curr === true) {
plgContentjkefel::$counter++;
$found = true;
}
$pos = strpos($text, '{jkefel');
}
}
static function removeJKefel(&$text) {
$text = preg_replace('#{jkefel.*?{/jkefelend}#Ui', '', $text);
}
protected static function recur(&$content, $pos = 0) {
$tabGroup = null;
$tabsFound = 0;
$groupStart = strpos($content, '{jkefel', $pos);
if ($groupStart === false) {
return false;
}
$ending = strpos($content, '{/jkefel}', $pos);
if ($ending === false) {
$ending = strpos($content, '{/jkefelend}', $pos);
}
if ($ending <= $groupStart) {
JError::raiseWarning( 'SOME_ERROR_CODE', 'jkefel: '.JText::_('Incorrect jkefel definition: premature jkefel end.'));
return false;
}
$groupEnd = strpos($content, '{/jkefelend}', $groupStart);
if ($groupEnd === false) {
JError::raiseWarning( 'SOME_ERROR_CODE', 'jkefel: '.JText::_('Incorrect jkefel definition: no jkefel end found.'));
return false;
}
$continueTab = true;
$tabGroup = plgContentjkefel::processTabGroupStart($content, $groupStart);
while ($continueTab) {
$tabStart = strpos($content, '{jkefel', $pos);
if ($tabStart === false) {
$continueTab = false;
break;
}
$tabEnd = strpos($content, '{/jkefel}', $tabStart);
$nextTabStart = strpos($content, '{jkefel', $tabStart + 1);
if ($tabEnd === false || $tabEnd > $groupEnd) {
$tabEnd = $groupEnd;
$continueTab = false;
}
// a new tab group found inside a tab
if ($nextTabStart !== false && $nextTabStart < $tabEnd) {
plgContentjkefel::recur($content, $nextTabStart);
// reposition tab ends since content is now modified
$groupEnd = strpos($content, '{/jkefelend}', $nextTabStart);
$tabEnd = strpos($content, '{/jkefel}', $nextTabStart);
if ($tabEnd === false || $tabEnd > $groupEnd) {
$tabEnd = $groupEnd;
$continueTab = false;
} else {
$continueTab = true;
}
}
plgContentjkefel::processTab($content, $tabStart, ($continueTab ? false : $groupEnd), $tabGroup);
$pos = $tabEnd;
$tabsFound++;
}
plgContentjkefel::processTabGroupEnd($tabGroup);
$content =
substr($content, 0, $groupStart)
. $tabGroup['ui']
. substr($content, $groupEnd + strlen('{/jkefelend}'));
return $tabsFound > 0;
}
protected static function value($name, $definition, $value = '') {
$pos = plgContentjkefel::strpos_balanced('[', ']', $definition, ' '.$name.'=');
if ($pos !== false) {
return substr($definition, $pos[0], $pos[1]);
}
return $value !== '' ? $value : false;
}
static function strpos_balanced($findStart, $findEnd, $str, $startAt) {
if (!is_numeric($startAt)) {
$_startAt = $startAt;
$startAt = strpos($str, $startAt);
if ($startAt !== false) $startAt += strlen($_startAt) + 1;
}
if ($startAt === false) return false;
$pos = $startAt;
$max = strlen($str);
$found = false;
$ch = '';
while ($pos < $max) {
$ch = $str[$pos];
if ($ch == $findStart) {
$found = true;
} else if ($ch == $findEnd) {
if ($found) {
$found = false;
} else {
break;
}
}
$pos++;
}
if ($ch == $findEnd) {
return array($startAt, $pos - $startAt);
}
return false;
}
protected static function processTab($content, $tabStart, $groupEnd, &$tabGroup) {
$tabDefinition = substr($content, $tabStart, strpos($content, '}', $tabStart) - $tabStart + 1);
$contentStart = strpos($content, '}', $tabStart);
$contentEnd = $groupEnd === false ? strpos($content, '{/jkefel}', $contentStart) : $groupEnd;
$content = substr($content, $contentStart + 1, $contentEnd - $contentStart - 1);
$title = plgContentjkefel::value('title', $tabDefinition, '');
$tabId = 'jkefel-'.$tabGroup['count'].'-'.$tabGroup['tabId'];
$tabId = plgContentjkefel::value('id', $tabDefinition, $tabId);
$isAjax = false;
$pos = plgContentjkefel::value('pos', $tabDefinition, plgContentjkefel::param('remoteContentPos'));
$addContent = '';
$wire = array();
if (($val = plgContentjkefel::value('url', $tabDefinition, false)) !== false) {
$isAjax = true;
$addContent = '<span class="ajax_container"></span>';
$wire[] = 'href:"'.$val.'"';
}
if (($val = plgContentjkefel::value('onsuccessp', $tabDefinition, false)) !== false) {
$wire[] = 'onsuccessp:"'.$val.'"';
}
if (($val = plgContentjkefel::value('onsuccess', $tabDefinition, false)) !== false) {
$wire[] = 'onsuccess:"'.$val.'"';
}
if (($val = plgContentjkefel::value('refresh', $tabDefinition, false)) !== false) {
$wire[] = 'refresh:"'.($val == 'true' || $val == '1' ? 'true' : 'false').'"';
}
if (($val = plgContentjkefel::value('freq', $tabDefinition, false)) !== false) {
$wire[] = 'freq:'.$val;
}
if (($val = plgContentjkefel::value('mod', $tabDefinition, false)) !== false) {
$_addContent = plgContentjkefel::getModule($val);
if (strtolower($title) == 'moduletitle' || empty($title)) {
$title = $_addContent['title'];
}
$addContent .= $_addContent['content'];
}
if ($addContent) {
if ($pos == 'replace') {
$content = $addContent;
} else if ($pos == 'append') {
$content .= $addContent;
} else if ($pos == 'prepend') {
$content = $addContent.$content;
}
}
if (empty($title)) {
$title = 'Tab '.$tabGroup['tabId'];
}
$tabGroup['ui'] .= $tabGroup['pane']->startPanel($title, $tabId);
$tabGroup['ui'] .= $content.'<div class="clr"> </div>';
$tabGroup['ui'] .= $tabGroup['pane']->endPanel();
if (!empty($wire)) {
$wire[] = 'id:"'.$tabId.'"';
$tabGroup['wire'] .= (!empty($tabGroup['wire']) ? ', ' : '') . '{'. implode(',', $wire) . '}';
}
$tabGroup['tabId']++;
}
protected static function processTabGroupStart($content, $groupStart) {
static $lastKefelId = 1;
$tabDefinition = substr($content, $groupStart, strpos($content, '}', $groupStart) - $groupStart + 1);
$jpaneId = 'jkefel'.$lastKefelId;
$jpaneId = plgContentjkefel::value('kefelid', $tabDefinition, $jpaneId);
$ui = plgContentjkefel::param('ui');
$ui = plgContentjkefel::value('kefelui', $tabDefinition, $ui);
$persistTab = plgContentjkefel::param('persistTab');
$persistTab = plgContentjkefel::value('persist', $tabDefinition, $persistTab);
$triggerEvent = plgContentjkefel::value('trigger', $tabDefinition, 'click');
if (JString::substr($ui, 0, 3) == 'tab') {
$ui = 'tabs';
} else if (JString::substr($ui, 0, 5) == 'slide') {
$ui = 'sliders';
}
$paneParams = array('firstElementsOpen' => '');
if (($val = plgContentjkefel::value('initial', $tabDefinition, false)) !== false) {
$ps = explode(',', $val);
for ($i = 0, $n = count($ps); $i < $n; $i++) {
$ps[$i]--;
}
if ($ui == 'tabs') {
if ($n > 0) {
$paneParams['firstElementsOpen'] = $ps[0];
}
} else {
$paneParams['firstElementsOpen'] = implode(',', $ps);
}
}
jimport( 'joomla.html.pane' );
$pane = null;
if (strtolower($ui) == 'sliders') {
$paneParams['allowMultipleOpen'] = 'true';
if (($val = plgContentjkefel::value('single', $tabDefinition, false)) !== false) {
$paneParams['allowMultipleOpen'] = $val ? 'false' : 'true';
}
$pane = new JKefelSliders($paneParams);
} else {
$pane = new JKefelTabs($paneParams);
}
$result = array('pane'=>$pane);
$result['uitype'] = $ui;
$result['ui'] = '<div class="jkefel">'.$result['pane']->startPane($jpaneId);
$result['id'] = $jpaneId;
$result['wire'] = '';
$result['count'] = $lastKefelId;
$result['tabId'] = 1;
$result['persist'] = $persistTab;
$result['initial'] = $paneParams['firstElementsOpen'];
$result['trigger'] = $triggerEvent;
$lastKefelId++;
plgContentjkefel::$stack[] = '_'.$jpaneId;
return $result;
}
public static function includeResource($resource, $type) {
$document = JFactory::getDocument();
if ($type == 'css') {
$document->addStyleSheet(plgContentjkefel::$jkefelRoot . $resource);
} else if ($type == 'js') {
$document->addScript(plgContentjkefel::$jkefelRoot . $resource);
}
}
protected static function processTabGroupEnd(&$tabGroup) {
static $loaded = array();
$tabGroup['ui'] .= $tabGroup['pane']->endPane().'</div><div class="clr"> </div>';
$tabGroup['wire'] = '['.$tabGroup['wire'].']';
$document = JFactory::getDocument();
if (!isset($loaded[$tabGroup['uitype']])) {
plgContentjkefel::includeResource('jkefel.js', 'js');
plgContentjkefel::includeResource('jkefel.css', 'css');
$loaded[$tabGroup['uitype']] = true;
}
$initial = '';
if ($tabGroup['uitype'] == 'tabs') {
$initial = ', initial: ' . (!empty($tabGroup['initial']) ? $tabGroup['initial'] : '0');
}
$containerKefel = 'null';
$cnt = count(plgContentjkefel::$stack);
if ($cnt > 1) {
$containerKefel = plgContentjkefel::$stack[$cnt - 2];
}
$document->addScriptDeclaration('
var _'.$tabGroup['id'].' = new jkefel({
kefelId: "'.$tabGroup['id'].'",
cookieName: "_plgcontent_jkefel_",
ui: "'.$tabGroup['uitype'].'",
persistTab: '.((bool) $tabGroup['persist'] ? 'true' : 'false').',
persistMode: "'.plgContentjkefel::param('persistMode').'",
trigger: "'.$tabGroup['trigger'].'",
refreshTab: '.((bool) plgContentjkefel::param('refreshTab') ? 'true' : 'false').',
tracker: '.((bool) plgContentjkefel::param('tracker') ? 'true' : 'false').$initial.'
}, '.$tabGroup['wire'].', "'.$containerKefel.'");
');
array_pop(plgContentjkefel::$stack);
}
protected static function getModule($module) {
// Slightly customized version of joomla.application.module.helper._load to load a specific module
$app = JFactory::getApplication();
$user = JFactory::getUser();
$db = JFactory::getDBO();
$access = plgSystemjkefel::isJ16() ?
'IN (' . implode(',', $user->getAuthorisedViewLevels()) . ')' :
'<= '. (int) $user->get('aid', 0);
$modules = array();
$query = 'SELECT id, title, module, position, content, showtitle, params'
. ' FROM #__modules AS m'
. ' WHERE m.published = 1'
. ' AND m.access ' . $access
. ' AND m.client_id = '. (int)$app->getClientId()
. ' AND m.id = ' . (int)$module
. ' ORDER BY position, ordering';
$db->setQuery( $query );
if (null === ($modules = $db->loadObjectList())) {
JError::raiseWarning( 'SOME_ERROR_CODE', JText::_( 'Error loading given module' ).' (<em>'.$module .'</em>)');
return false;
}
$total = count($modules);
for($i = 0; $i < $total; $i++)
{
//determine if this is a custom module
$file = $modules[$i]->module;
$custom = substr( $file, 0, 4 ) == 'mod_' ? 0 : 1;
$modules[$i]->user = $custom;
// CHECK: custom module name is given by the title field, otherwise it's just 'om' ??
$modules[$i]->name = $custom ? $modules[$i]->title : substr( $file, 4 );
$modules[$i]->style = null;
$modules[$i]->position = strtolower($modules[$i]->position);
}
jimport('joomla.application.module.helper');
return array('content'=>JModuleHelper::renderModule($modules[0]), 'title'=>$modules[0]->title);
}
public static function param($name, $value = '') {
static $params, $_params;
if (!isset($params)) {
$plg = JPluginHelper::getPlugin('content', 'jkefel');
jimport('joomla.html.parameter');
$params = new JParameter($plg->params);
}
if (!isset($_params[$name])) {
$_params[$name] = $params->get($name);
if (is_string($_params[$name])) $_params[$name] = trim($_params[$name]);
if (!$_params[$name]) {
$_params[$name] = $value;
}
}
return $_params[$name];
}
/**
* taken from Articles Anywhere with the following copyright and with a
* slight modification as noticed in code with removed
* @package Articles Anywhere
* @version 1.5.0
*
* @author Peter van Westen <peter@nonumber.nl>
* @link http://www.nonumber.nl
* @copyright Copyright (C) 2010 NoNumber! All Rights Reserved
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
*/
public static function updateHead( $orig_document )
{
$document = JFactory::getDocument();
$hashead = 0;
if ( !isset( $document->_buffer ) || !isset( $document->_buffer['component'] ) ) {
return;
}
/** removed by gobezu <info@jproven.com>
*
foreach( $document->_buffer['component'] as $buffer ) {
if ( !( strpos( $buffer, '</head>' ) === false ) ) {
$hashead = 1;
break;
}
}
if ( !$hashead ) {
return;
}
*/
$head = JDocumentRendererHead::fetchHead( $document );
// get line endings
$lnEnd = $document->_getLineEnd();
$tab = $document->_getTab();
$tagEnd = ' />';
$strHtml = '';
// Generate link declarations
foreach ($document->_links as $link) {
if ( !in_array( $link, $orig_document->_links ) ) {
$strHtml .= $tab.$link.$tagEnd.$lnEnd;
}
}
// Generate stylesheet links
foreach ($document->_styleSheets as $strSrc => $strAttr ) {
if ( !array_key_exists( $strSrc, $orig_document->_styleSheets ) ) {
$strHtml .= $tab . '<link rel="stylesheet" href="'.$strSrc.'" type="'.$strAttr['mime'].'"';
if (!is_null($strAttr['media'])){
$strHtml .= ' media="'.$strAttr['media'].'" ';
}
$temp = JArrayHelper::toString($strAttr['attribs']);
if ( $temp ) {
$strHtml .= ' '.$temp;
}
$strHtml .= $tagEnd.$lnEnd;
}
}
// Generate stylesheet declarations
foreach ($document->_style as $type => $content) {
if ( !in_array( $content, $orig_document->_style ) ) {
$strHtml .= $tab.'<style type="'.$type.'">'.$lnEnd;
// This is for full XHTML support.
if ($document->_mime == 'text/html' ) {
$strHtml .= $tab.$tab.'<!--'.$lnEnd;
} else {
$strHtml .= $tab.$tab.'<![CDATA['.$lnEnd;
}
$strHtml .= $content . $lnEnd;
// See above note
if ($document->_mime == 'text/html' ) {
$strHtml .= $tab.$tab.'-->'.$lnEnd;
} else {
$strHtml .= $tab.$tab.']]>'.$lnEnd;
}
$strHtml .= $tab.'</style>'.$lnEnd;
}
}
// Generate script file links
foreach ($document->_scripts as $strSrc => $strType) {
if ( !array_key_exists( $strSrc, $orig_document->_scripts ) ) {
$strHtml .= $tab.'<script type="'.$strType.'" src="'.$strSrc.'"></script>'.$lnEnd;
}
}
// Generate script declarations
foreach ($document->_script as $type => $content) {
if ( !in_array( $content, $orig_document->_script ) ) {
$content = trim(str_replace($orig_document->_script[$type], '', $content));
if (empty($content)) continue;
$strHtml .= $tab.'<script type="'.$type.'">'.$lnEnd;
// This is for full XHTML support.
if ($document->_mime != 'text/html' ) {
$strHtml .= $tab.$tab.'<![CDATA['.$lnEnd;
}
$strHtml .= $content . $lnEnd;
// See above note
if ($document->_mime != 'text/html' ) {
$strHtml .= $tab.$tab.'// ]]>'.$lnEnd;
}
$strHtml .= $tab.'</script>'.$lnEnd;
}
}
foreach($document->_custom as $custom) {
if ( !in_array( $custom, $orig_document->_custom ) ) {
$strHtml .= $tab.$custom.$lnEnd;
}
}
JResponse::setBody( str_replace( '</head>', $strHtml."\n".'</head>', JResponse::getBody() ) );
}
public static function replaceElsewhere() {
$app = JFactory::getApplication();
if (!$app->isSite()) {
return;
}
if (!(bool) plgContentjkefel::param('elsewhereEnabled')) {
return;
}
$task = JRequest::getCmd('task');
if ($task == 'edit') {
return;
}
$document = JFactory::getDocument();
$docType = $document->getType();
$doc = clone($document);
if ($docType == 'pdf') {
return;
}
$html = JResponse::getBody();
if ($docType != 'html') {
plgContentjkefel::removeJKefel($html);
JResponse::setBody($html);
} else {
plgContentjkefel::jkefel($html);
JResponse::setBody($html);
plgContentjkefel::updateHead($doc);
}
}
/*
* Since current core implementation can't handle recursively included tabs
* its removed and is replaced by a corrected one...
*/
public static function removeJTABS() {
if (!JPluginHelper::isEnabled('content', 'jkefel') || plgContentjkefel::$counter <= 0) {
return;
}
$app = JFactory::getApplication();
if (!$app->isSite()) {
return;
}
$task = JRequest::getCmd('task');
if ($task == 'edit') {
return;
}
$html = JResponse::getBody();
$cnt = 0;
$src = plgContentjkefel::$jkefelRoot.'jtabs.js';
$html = preg_replace('#(<script.+src=)([\"\'])([^\"\']*)(media\/system\/js\/tabs\.js)(\2[^>]*>)#Ui', '$1$2'.$src.'$5', $html, -1, $cnt);
if ($cnt <= 0) {
$html = str_ireplace('</head>', '<script type="text/javascript" src="'.$src.'"></script></head>', $html);
}
JResponse::setBody($html);
}
}
class JKefelSliders extends JPaneSliders {
var $id = '';
var $params = array();
function __construct( $params = array() ) {
$this->params = $params;
}
function startPane( $id ) {
$this->id = $id;
$this->_loadBehavior();
return '<div id="'.$id.'" class="pane-sliders">';
}
function startPanel( $text, $id ) {
return '<div class="panel">'
.'<h3 class="jpane-toggler title" id="'.$id.'"><span>'.$text.'</span></h3>'
.'<div class="jpane-slider content">';
}
function _loadBehavior() {
$params = $this->params;
JHTML::_('behavior.mootools');
$document = JFactory::getDocument();
$check = JFactory::getApplication()->get('MooToolsVersion');
$is12 = !empty($check) || plgSystemjkefel::isJ16();
$options = $is12 ? '' : '{';
$opt['onActive'] = 'function(toggler, i) { toggler.addClass(\'jpane-toggler-down\'); toggler.removeClass(\'jpane-toggler\'); }';
$opt['onBackground'] = 'function(toggler, i) { toggler.addClass(\'jpane-toggler\'); toggler.removeClass(\'jpane-toggler-down\'); }';
$opt['duration'] = (isset($params['duration'])) ? (int)$params['duration'] : 300;
$opt['display'] = (isset($params['startOffset']) && ($params['startTransition'])) ? (int)$params['startOffset'] : null ;
$opt['show'] = (isset($params['startOffset']) && (!$params['startTransition'])) ? (int)$params['startOffset'] : null ;
$opt['opacity'] = (isset($params['opacityTransition']) && ($params['opacityTransition'])) ? 'true' : 'false' ;
$opt['alwaysHide'] = (isset($params['allowAllClose']) && ($params['allowAllClose'])) ? 'true' : null ;
$opt['firstElementsOpen'] = (isset($params['firstElementsOpen']) ? '['.$params['firstElementsOpen'].']' : '[]');
$opt['openAll'] = (isset($params['openAll']) ? $params['openAll'] : 'false');
$opt['allowMultipleOpen'] = $params['allowMultipleOpen'];
$allowMultipleOpen = $opt['allowMultipleOpen'];
$firstElementsOpen = $opt['firstElementsOpen'];
if ($is12) {
$opt['allowMultipleOpen'] = null;
if ($allowMultipleOpen == 'false') {
$opt['firstElementsOpen'] = null;
if ($firstElementsOpen) {
$firstElementsOpen = str_replace(array('[',']'), '', $firstElementsOpen);
$firstElementsOpen = explode(',',$firstElementsOpen);
$opt['display'] = $firstElementsOpen[0];
}
}
}
foreach ($opt as $k => $v)
{
if ($v) {
$options .= $k.': '.$v.',';
}
}
if (substr($options, -1) == ',') {
$options = substr($options, 0, -1);
}
$options .= $is12 ? '' : '}';
if ($is12) {
if ($allowMultipleOpen == 'false') {
if (!empty($options)) $options = ', {' . $options.'}';
$js = ' window.addEvent(\'domready\', function(){ new Accordion($$(\'#'.$this->id.' .panel h3.jpane-toggler\'), $$(\'#'.$this->id.' .panel div.jpane-slider\')'.$options.'); });';
} else {
if (!empty($options)) $options = ', ' . $options;
$js = ' window.addEvent(\'domready\', function(){ new MultipleOpenAccordion($$(\'#'.$this->id.' .pane-sliders\'), {togglers: $$(\'#'.$this->id.' .panel h3.jpane-toggler\'), elements: $$(\'#'.$this->id.' .panel div.jpane-slider\')'.$options.'}); });';
}
} else {
$js = ' window.addEvent(\'domready\', function(){ new MultipleOpenAccordion($$(\'#'.$this->id.' .panel h3.jpane-toggler\'), $$(\'#'.$this->id.' .panel div.jpane-slider\'), '.$options.'); });';
}
$document->addScriptDeclaration( $js );
if (!$is12 || $is12 && $allowMultipleOpen != 'false') {
plgContentjkefel::includeResource('accordion.1.' . ($is12 ? '2' : '1') . '.js', 'js');
if ($is12) {
plgContentjkefel::includeResource('fx.reveal.js', 'js');
}
}
}
}
class JKefelTabs extends JPaneTabs {
public function startPanel($text, $id) {
return '<dt id="'.$id.'"><span>'.$text.'</span></dt><dd>';
}
}
jest to kod z pliku jkefel.php z katalogu content w dodatkach
W jaki spsoób naprawić błąd, tj. wyświetlanie pod IE?
Z góry bardzo dziękuję za pomoc