2

(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.

1 Answer 1

1

May I ask you what plugin event you are using? Because your code should work fine after the routing is done.

During the routing, Joomla parses the URL and maps them internally back to a non SEF URL. Which will get you the option, Itemid and that stuff.

4
  • Its the CM Group buying plugin. I see they are using some legacy commands which makes me think that this has not been updated. I am aware that later versions of their mobile displays are using responsive CSS, but this is not usable with my clients template YET as it would mean a complete restyle. I will inlcude the full code in my initial post
    – MOLEDesign
    Commented Jun 13, 2014 at 15:43
  • 1
    It will not work in the 'onAfterInitialise' event because that is fired before the routing is done.
    – Bakual
    Commented Jun 13, 2014 at 15:55
  • Oh well spotted! Another fresh pair of eyes makes all the difference! I will try to work with that and see what can be done
    – MOLEDesign
    Commented Jun 13, 2014 at 18:33
  • that little prompt was all I needed. I just changed onAfterInitialise to onAfterRoute
    – MOLEDesign
    Commented Jun 13, 2014 at 18:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.