public static function getInstance($params) { if (!is_object(self::$instance)) { self::$instance = new JLNodoublesHelper($params); } return self::$instance; }
public function onAfterRoute() { $app = JFactory::getApplication(); if ($app->getName() != 'site' || self::$noRedirect) { return true; } $option = $app->input->getCmd('option', ''); $Itemid = $app->input->getInt('Itemid', 0); $view = $app->input->getCmd('view', ''); $id = $app->input->getString('id', 0); $task = $app->input->getCmd('task', ''); $layout = $app->input->getCmd('layout', ''); $lang = $app->input->getCmd('lang', ''); $allGet = array('Itemid' => $Itemid, 'option' => $option, 'view' => $view, 'id' => $id, 'task' => $task, 'layout' => $layout, 'lang' => $lang); $u = JUri::getInstance(); $currentLink = $u->toString(array('path')); $uir = $_SERVER['REQUEST_URI']; $defValue = array(array('var_name' => array('task', 'format', 'no_html', 'tmpl'), 'var_value' => array('save, edit, add, delete, apply', 'nohtml', '1', 'component')), 'com_content' => array('checkbox' => 'on', 'var_name' => array(''), 'var_value' => array(''))); $componentsvars = $this->params->get('componentsvars', $defValue); if (is_object($componentsvars)) { $tmp = array(); foreach ($componentsvars as $k => $val) { $tmp[$k] = (array) $val; } $componentsvars = $tmp; unset($tmp); } if (!isset($componentsvars[$option]["checkbox"])) { self::$noRedirect = true; return true; } if (isset($componentsvars[$option])) { for ($i = 0; $i < sizeof($componentsvars[$option]["var_name"]); $i++) { $var_name = $componentsvars[$option]["var_name"][$i]; if (trim($componentsvars[$option]["var_value"][$i])) { $var_values = array_map('trim', explode(',', $componentsvars[$option]["var_value"][$i])); foreach ($var_values as $vvalue) { if (isset($allGet[trim($var_name)]) && $allGet[trim($var_name)] == trim($vvalue)) { self::$noRedirect = true; return true; } } } else { if (isset($allGet[$var_name])) { self::$noRedirect = true; return true; } } } } $helperPath = JPATH_ROOT . '/plugins/system/jlnodoubles/helpers/' . $option . '.php'; $return = true; if (is_file($helperPath) && ($option == 'com_content' || self::$isPro)) { require_once $helperPath; $class = 'JLNodoubles_' . $option . '_helper'; if (class_exists($class)) { $this->params->set('isPro', self::$isPro); $helper = new $class($this->params); if (method_exists($helper, 'go')) { $return = $helper->go($allGet); } } } if ($option && $return == false) { $allGetArr = array(); foreach ($allGet as $ag_name => $ag_value) { if ($ag_name && $ag_value) { $allGetArr[] = $ag_name . '=' . $ag_value; } } if (!$Itemid) { $app = JFactory::getApplication(); $menus = $app->getMenu(); //$menus = &JApplication::getMenu('site', array()); $component_menu = $menus->getItems('component', $option); $Itemid = $component_menu[0]->id; if ($Itemid) { $allGetArr[] = 'Itemid=' . $Itemid; } } $redirectLink = JRoute::_('index.php?' . implode('&', $allGetArr)); if ($redirectLink != $currentLink) { JLNodoublesHelper::getInstance($this->params)->shRedirect($redirectLink); } } return true; }
function __construct($params) { parent::__construct($params); }
protected function getInput() { $db = JFactory::getDBO(); $doc = JFactory::getDocument(); $db->setQuery('SELECT element FROM #__extensions WHERE type="component" ORDER BY name'); $components = $db->loadColumn(); jimport('joomla.filesystem.folder'); $folders = JFolder::folders(JPATH_ROOT . '/components', 'com_(.*)'); if (!$this->value) { $this->value = array(0 => array('var_name' => array('task', 'format', 'no_html', 'tmpl'), 'var_value' => array('save, edit, add, delete, apply', 'nohtml', '1', 'component')), 'com_content' => array('checkbox' => 'on', 'var_name' => array(''), 'var_value' => array(''))); } $this->components = JFolder::files(JPATH_ROOT . '/plugins/system/jlnodoubles/helpers'); $plugin = JPluginHelper::getPlugin('system', 'jlnodoubles'); $pluginParams = new JRegistry($plugin->params); $allow = JLNodoublesHelper::allow($pluginParams->get('key', '')) ? true : false; $all = JText::_('PLG_JLNODUBLES_ALL_COMPONENTS'); array_unshift($components, $all); ?> <div id="sh_component_wrapper"> <?php var_dump($allow); foreach ($components as $component) { if (in_array($component, $folders) || $component == $all) { $componentName = $component; if ($component == $all) { $component = 0; } $checked = isset($this->value[$component]["checkbox"]) ? ' checked="checked" ' : ''; $unchecked_class = $checked || !$component ? '' : ' unchecked '; $disabled = !$allow && $componentName != 'com_content' && in_array($componentName . '.php', $this->components) ? ' disabled="disabled"' : ''; ?> <div class="sh_component_inner <?php echo $unchecked_class; ?> " id="sh_component_<?php echo $component; ?> "> <div class="sh_component_name"> <?php if ($component) { ?> <input type="checkbox" onclick="shnodoubles.com_checkbox(this, '<?php echo $component; ?> ')" class="shnodoubles_com_checkbox" name="<?php echo $this->name . '[' . $component . '][checkbox]'; ?> " <?php echo $checked; ?> <?php echo $disabled; ?> /> <?php } ?> <?php echo $componentName; ?> <input type="button" value="<?php echo JText::_('PLG_JLNODUBLES_ADD_VAR'); ?> " onclick="shnodoubles.add_var(this, '<?php echo $component; ?> ')" class="shnodoubles_add_var"> </div> <?php if (!isset($this->value[$component]) || !isset($this->value[$component]["var_name"])) { $this->value[$component] = array('var_name' => array(''), 'var_value' => array('')); } for ($i = 0; $i < sizeof($this->value[$component]["var_name"]); $i++) { ?> <div class="sh_component_value"> <input name="<?php echo $this->name . '[' . $component . '][var_name][]'; ?> '" placeholder="<?php echo JText::_('PLG_JLNODUBLES_VAR'); ?> " value="<?php echo $this->value[$component]["var_name"][$i]; ?> "> <input name="<?php echo $this->name . '[' . $component . '][var_value][]'; ?> " placeholder="<?php echo JText::_('PLG_JLNODUBLES_COMPONENT_VAR_VALUE'); ?> " class="sh_component_var_value" value="<?php echo $this->value[$component]["var_value"][$i]; ?> "> <input type="button" value="<?php echo JText::_('PLG_JLNODUBLES_DEL'); ?> " onclick="shnodoubles.remove_var(this)" class="shnodoubles_remove_var"> </div> <?php } ?> </div> <?php } ?> <?php } ?> </div> <?php $script = ' var jlnodoubles = { "name": "' . $this->name . '", "lang": { "VAR": "' . JText::_('PLG_JLNODUBLES_VAR') . '", "VALUE": "' . JText::_('PLG_JLNODUBLES_COMPONENT_VAR_VALUE') . '", "DEL": "' . JText::_('PLG_JLNODUBLES_DEL') . '" } }; '; $doc->addScriptDeclaration($script); $doc->addScript(JUri::root() . 'plugins/system/jlnodoubles/assets/jlnodoubles.js'); $doc->addStyleSheet(JUri::root() . 'plugins/system/jlnodoubles/assets/jlnodoubles.css'); }