(Migrated this question from Stack Overflow)
I am working on a client's website which is based on the Joomla 2.5 framework. With SEF turned off (the in built Joomla version) the URL is this
http://(domain)/index.php?option=com_cmgroupbuying&view=alldeals&Itemid=424
The user has a plugin, I have built into a plugin the line to make sure this plugin only fires when the component CMGroupbuying is in use
$component = JRequest::getCmd('option');
if($component =='com_cmgroupbuying')
{ etc etc }
With SEF turned off, this works beautifully. However when I enable SEF the URL turns into
http://(domain)/the-deals
and the detection script stops working as joomla just no longer sees the Request::getCmd('option'); being equal to com_cmgroupbuying which to be honest, blows me away as it renders getCmd totally useless. I have seen other prople suffer with this in the part but not found any definitive fix
Can anyone offer a solution to stop this failure of Joomla, either by some extra lines in the DEFAULT htaccess fault to retain this information for joomla to use.
An alternative solution, though I have not found anything that does this, is to limit the plugin to only certain menu items like you can do with a module.
EDIT
This is the full code of the plugin. I have not included the helper as this is just a mass list of all agents for lookups.
<?php /** * @package CMMobileDetection plugin * @copyright Copyright (C) 2012-2013 CMExtension Team http://www.cmext.vn/ * @license http://www.gnu.org/licenses/gpl-3.0.html GNU/GPL */
// No direct access defined('_JEXEC') or die;
jimport('joomla.plugin.plugin');
require_once 'helper.php';
class plgSystemCMMobileDetection extends JPlugin {
public function onAfterInitialise()
{
if(JPATH_BASE != JPATH_ADMINISTRATOR)
{
$browser = new Mobile_Detect();
$mobileCookie = JFactory::getApplication()->input->cookie->get('cmmobileRequestDesktop',
-1, 'int');
$component = JRequest::getVar('option');
if(($browser->isMobile() || $browser->isTablet()) && ($mobileCookie == 0 || $mobileCookie == -1) && $component == 'com_cmgroupbuying')
{
$configuration = $this->getConfiguration();
$db = JFactory::getDBO();
$query = "SELECT params FROM #__template_styles WHERE client_id = 0 AND template = ".$db->Quote($configuration['mobile_template'])." ORDER BY id LIMIT 1";
$db->setQuery($query);
$params = $db->loadResult();
if(empty($params))
$params = '{}';
JFactory::getApplication()->setTemplate($configuration['mobile_template'], $params);
}
}
}
public function getConfiguration()
{
$db = JFactory::getDBO();
$query = 'SELECT * FROM #__cmgroupbuying_configuration WHERE id = 1';
$db->setQuery($query);
$configuration = $db->loadAssoc();
if($db->getErrorNum())
{
//JError::raiseError(500, implode('<br />', $errors));
return false;
}
return $configuration;
} } ?>
This does include my alteration, which basically has one function, stop the plugin loading on ANY page that is NOT using option=com_cmgroupbuying as it interferes with the mobile template of all the other pages. As already stated, this works beautifully when SEF is turned off.