开发者

Joomla get plugin id

开发者 https://www.devze.com 2023-01-29 10:17 出处:网络
I wrote a Joomla plugin which will eventually load a library. The path to library is a plugin parameter, as such when the path is incorrect, a message pops up in the backend, together with a link to

I wrote a Joomla plugin which will eventually load a library.

The path to library is a plugin parameter, as such when the path is incorrect, a message pops up in the backend, together with a link to edit the plugin parameters:

/administrator/index.php?option=com_plugins&view=plugin&client=site&task=edit&cid[]=36

See the 36 at the end? That's my plugin's id in the database (table jos_plugins).

My issue is that this id changes on installation, ie, on different installs, it would be something else. So I need to find this id programmatically.

The problem is that I couldn't find this id from the plugin object itself (as to why not, that would be joomla's arguably short-sighted design decision).

So unless you know about some neat trick, (I've checked and double checked JPlugin and JPluginHelper classes), I'll be using the DB.

Edit; So开发者_开发问答me useful links:

  • http://docs.joomla.org/Plugin_Developer_Overview
  • http://api.joomla.org/Joomla-Framework/Plugin/JPlugin.html
  • http://api.joomla.org/Joomla-Framework/Plugin/JPluginHelper.html
  • http://forum.joomla.org/viewtopic.php?p=2227737

Guess I'll be using the wisdom from that last link...


For joomla 2.5.x and 3.x Christian's function improvement would be;

function getId($folder,$name){
    $db=    JFactory::getDBO();
    $sql='SELECT extension_id FROM #__extensions WHERE folder ="'.$db->getEscaped($folder).'" AND element ="'.$db->getEscaped($name).'"';
    $db->setQuery($sql);
    if(!($plg=$db->loadObject())){
        JError::raiseError(100,'Fatal: Plugin is not installed or your SQL server is NUTS.');
    }else return (int)$plg->extension_id;
}


function getId($folder,$name){
    $db=&JFactory::getDBO();
    $sql='SELECT `id` FROM `#__plugins` WHERE `folder`="'.$db->getEscaped($folder).'" AND `element`="'.$db->getEscaped($name).'"';
    $db->setQuery($sql);
    if(!($plg=$db->loadObject())){
        JError::raiseError(100,'Fatal: Plugin is not installed or your SQL server is NUTS.');
    }else return (int)$plg->id;
}

That did the trick.


In Joomla 3.x this is the way!!!

function pluginId($name,$type,$element,$folder)
{
    $db = JFactory::getDBO();
    $query = $db->getQuery(true);
    $query
        ->select($db->quoteName('a.extension_id'))
        ->from($db->quoteName('#__extensions', 'a'))
        ->where($db->quoteName('a.name').' = '.$db->quote($name))
        ->where($db->quoteName('a.type').' = '.$db->quote($type))
        ->where($db->quoteName('a.element').' = '.$db->quote($element))
        ->where($db->quoteName('a.folder').' = '.$db->quote($folder));
    $db->setQuery($query);
    $db->execute();
    if($db->getNumRows()){
        return $db->loadResult();
    }
    return false;
}

Then to use the function:

$pluginId = pluginId('plg_system_getbibleactivitycron','plugin','getbibleactivitycron','system');

if($pluginId){
    echo 'Plugin id is: '. $pluginId;
} else {
    echo 'Plugin not installed';
}


maybe this code useful for you you can use this in modal

$urla= JRequest::getVar('id'); // id article 
$urlb=JURI::current(); 
0

精彩评论

暂无评论...
验证码 换一张
取 消