Joomla系统插件不止一次运行

时间:2016-05-09 23:19:22

标签: joomla joomla3.0

我创建了一个Joomla系统插件,该插件在数据库表上记录所有url参数,以便使用登录用户进行一些分析。

该插件工作正常,问题是它似乎在单个页面加载上运行了不止一次。当用户打开页面时,我得到2条新记录,并且它们在datahora列上有1或2秒的差异。

该插件正在onAfterRender上运行,请参阅下面的代码。

什么可能导致插件运行多次?我也试过在AfterInitialise上运行它,但我得到了相同的结果。 感谢

<?php
// no direct access
defined( '_JEXEC' ) or die;

jimport( 'joomla.factory' );

class plgSystemLogAccessUser extends JPlugin
{
    /**
     * Load the language file on instantiation. Note this is only available in Joomla 3.1 and higher.
     * If you want to support 3.0 series you must override the constructor
     *
     * @var    boolean
     * @since  3.1
     */
    protected $autoloadLanguage = true;

    /**
     * Plugin method with the same name as the event will be called automatically.
     */

    function onAfterRender()
    {       
        /*
        * Plugin code goes here.
        * You can access database and application objects and parameters via $this->db,
        * $this->app and $this->params respectively
        */

        $user = JFactory::getUser();

        $parametrosTask = $this->params->get('task');

        $ignorartask = explode(',', $parametrosTask);       

        if( !in_array(self::getTask(), $ignorartask) && !$user->guest && JURI::base( true ) != "/administrator"){
            self::saveLog(
                self::getDataHora(),
                self::getUsuario(),
                self::getUrl(),
                self::getOption(),
                self::getView(),
                self::getTask(),
                self::getId(),
                self::getItemid(),
                self::getUserid(),
                self::getActivity_id(),
                self::getCid(),
                self::getCatid(),
                self::getModule(),
                self::getFileid(),
                self::getGroupid()
            );
        }       
    }


    function getUsuario()
    {       
        $user = JFactory::getUser();

        if (!$user->guest) {
          return $user->id;
        }

        return '';
    }

    function getUrl()
    {   
        $uri = & JFactory::getURI();
        return $uri->toString();
    }

    function getTask()
    {
        $jinput = JFactory::getApplication()->input;
        return $jinput->get('task', '', 'string');
    }

    function getOption()
    {   
        $jinput = JFactory::getApplication()->input;
        return $jinput->get('option', '', 'string');        
    }

    function getView()
    {       
        $jinput = JFactory::getApplication()->input;
        return $jinput->get('view', '', 'string');
    }

    function getId()
    {       
        $jinput = JFactory::getApplication()->input;
        return $jinput->get('id', '', 'int');
    }

    function getItemid()
    {       
        $jinput = JFactory::getApplication()->input;
        return $jinput->get('Itemid', '', 'int');
    }

    function getUserid()
    {       
        $jinput = JFactory::getApplication()->input;
        return $jinput->get('userid', '', 'string');
    }

    function getActivity_id()
    {       
        $jinput = JFactory::getApplication()->input;
        return $jinput->get('activity_id', '', 'string');
    }

    function getCid()
    {       
        $jinput = JFactory::getApplication()->input;
        return $jinput->get('cid', '', 'string');
    }

    function getCatid()
    {       
        $jinput = JFactory::getApplication()->input;
        return $jinput->get('catid', '', 'string');
    }

    function getModule()
    {       
        $jinput = JFactory::getApplication()->input;
        return $jinput->get('module', '', 'string');
    }

    function getFileid()
    {       
        $jinput = JFactory::getApplication()->input;
        return $jinput->get('fileid', '', 'string');
    }

    function getDataHora()
    {
        return date("Y-m-d H:i:s");
    }

    function getGroupid()
    {       
        $jinput = JFactory::getApplication()->input;
        return $jinput->get('groupid', '', 'string');
    }

    function saveLog(
        $datahora = null,
        $usuario = null,
        $url = null,
        $option = null,
        $view = null,
        $task = null,
        $id = null,
        $Itemid = null,
        $userid = null,
        $activity_id = null,
        $cid = null,
        $catid = null,
        $module = null,
        $fileid = null,
        $groupid = null
        )
    {
        $logaccessuser = new stdClass();        
        $logaccessuser->datahora = $datahora;
        $logaccessuser->usuario = $usuario;
        $logaccessuser->url = $url;
        $logaccessuser->option = $option;
        $logaccessuser->view = $view;
        $logaccessuser->task = $task;
        $logaccessuser->id = $id;
        $logaccessuser->itemid = $Itemid;
        $logaccessuser->userid = $userid;
        $logaccessuser->activity_id = $activity_id;
        $logaccessuser->cid = $cid;
        $logaccessuser->catid = $catid;
        $logaccessuser->module = $module;
        $logaccessuser->fileid = $fileid;
        $logaccessuser->groupid = $groupid;

        // Insert the object into the user profile table.
        $result = JFactory::getDbo()->insertObject('#__logaccessuser', $logaccessuser);
    }
}

2 个答案:

答案 0 :(得分:0)

我只能想到造成这个问题的两个原因:

  • 您的网站上有某个iframe
  • 您已安装了两次相同的插件(可能使用不同的名称)

答案 1 :(得分:0)

可能是您的网站正在尝试加载无法找到的资源 - 使用Joomla!的.htaccess文件,任何不存在的文件/文件夹(如果请求不是以index.php)通过index.php。

进行路由

我会检查以确保所有资源都加载(JS / CSS / Images /等)(导致200响应)