web-dev-qa-db-fra.com

plugin k2 non déclenché par aucun événement

te voila mon xml

<?xml version="1.0" encoding="utf-8"?>
<extension version="3.0" type="plugin" group="k2" method="upgrade">
<name>com_related_news_programme</name>
<author>IES</author>
<creationDate>March 4th, 2015</creationDate>
<copyright>IES</copyright>
<authorEmail></authorEmail>
<authorUrl></authorUrl>
<version>0.1</version>
<license>http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL</license>
<description>For Related News Programme</description>
<files>
    <filename plugin="plgiesrelatednewsprogramme">plgiesrelatednewsprogramme.php</filename>
    <filename plugin="plgiesrelatednewsprogramme">plgiesrelatednewsprogramme.xml</filename>
    <filename>plgiesrelatednewsprogramme.sql</filename>
</files>

<install>
    <sql>
          <file driver="mysql" charset="utf8">plgiesrelatednewsprogramme.sql</file>
    </sql>
</install>
<!-- Standard Joomla! plugin parameters to setup the K2 plugin once -->

<!-- K2 plugin parameters which extend K2 backend forms are defined here -->

</extension>

tu es ma classe

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

/**
 * Example K2 Plugin to render YouTube URLs entered in backend K2 forms to video players in the frontend.
 */

// Load the K2 Plugin API
JLoader::register('K2Plugin', JPATH_ADMINISTRATOR.'/components/com_k2/lib/k2plugin.php');

// Initiate class to hold plugin events
class plgK2iesrelatednewsprogramme extends K2Plugin
{

// Some params
var $pluginName = 'iesrelatednewsprogramme';
var $pluginNameHumanReadable = 'Related News Programme';

function plgK2iesrelatednewsprogramme(&$subject, $params)
{
    parent::__construct($subject, $params);
    echo "fk cc";
}

/**
 * Below we list all available FRONTEND events, to trigger K2 plugins.
 * Watch the different prefix "onK2" instead of just "on" as used in Joomla! already.
 * Most functions are empty to showcase what is available to trigger and output. A few are used to actually output some code for example reasons.
 */

/**
 * Brings the GUI of plugin in the content tab of the k2 item. 
 * 
 * @param   object      The k2 item.
 * @param   string      The view.
 * @param   string      The tab for assign the plugin.
 * @return  object
 */
function onRenderAdminForm(&$item, $type, $tab=''){
    $plugin = new JObject;

    $db = &JFactory::getDBO();
    $query = 'SELECT m.* FROM #__k2_categories AS m WHERE m.`trash` = 0 ORDER BY `parent`, `ordering`';
    $db->setQuery( $query );
    $mitems = $db->loadObjectList();

    $html = "<select>";
    foreach($mitems as $c) {
        $cName = $c->name;
        $cID = $c->id;
        $html.="<option value='$cID'>$cName</option>";
    }
    $html.="</select>";
    echo "<pre>".htmlentities(print_r($mitems , true))."</pre>";
    $plugin->set('fields', $html);
    return $plugin;
}

function onAfterK2Save(&$row, $isNew) 
{

}

function onK2PrepareContent(&$item, &$params, $limitstart)
{
    $mainframe = JFactory::getApplication();
    //$item->text = 'It works! '.$item->text;
}

function onK2AfterDisplay(&$item, &$params, $limitstart)
{
    $mainframe = JFactory::getApplication();
    return '';
}

function onK2BeforeDisplay(&$item, &$params, $limitstart)
{
    $mainframe = JFactory::getApplication();
    return '';
}

function onK2AfterDisplayTitle(&$item, &$params, $limitstart)
{
    $mainframe = JFactory::getApplication();
    return '';
}

function onK2BeforeDisplayContent(&$item, &$params, $limitstart)
{
    $mainframe = JFactory::getApplication();
    return '';
}

// Event to display (in the frontend) the YouTube URL as entered in the item form
function onK2AfterDisplayContent(&$item, &$params, $limitstart)
{
    $mainframe = JFactory::getApplication();

    // Get the output of the K2 plugin fields (the data entered by your site maintainers)
    $plugins = new K2Parameter($item->plugins, '', $this->pluginName);

    $videoURL = $plugins->get('videoURL_item');

    // Check if we have a value entered
    if (empty($videoURL))
        return;

    // Output
    preg_match('/youtube\.com\/watch\?v=([a-z0-9-_]+)/i', $videoURL, $matches);
    $video_id = $matches[1];

    $output = '';

    return $output;
}

// Event to display (in the frontend) the YouTube URL as entered in the category form
function onK2CategoryDisplay(&$category, &$params, $limitstart)
{
    $mainframe = JFactory::getApplication();

    // Get the output of the K2 plugin fields (the data entered by your site maintainers)
    $plugins = new K2Parameter($category->plugins, '', $this->pluginName);

    $output = $plugins->get('videoURL_cat');

    return $output;
}

// Event to display (in the frontend) the YouTube URL as entered in the user form
function onK2UserDisplay(&$user, &$params, $limitstart)
{
    $mainframe = JFactory::getApplication();

    // Get the output of the K2 plugin fields (the data entered by your site maintainers)
    $plugins = new K2Parameter($user->plugins, '', $this->pluginName);

    $output = $plugins->get('videoURL_user');

    return $output;
}

} // END CLASS

le plugin s'installe correctement et j'ai essayé echo somthing à la fin du fichier php, donc je suis sûr que la classe a été importée

mais je mets un exit () dans soit plgK2iesrelatednewsprogramme () ou onRenderAdminForm ()

aucun d'eux ne fonctionne

1
littleshell

Il y a un problème de nommage. Si la classe ne correspond pas exactement à ce que Joomla recherche, les événements ne seront pas déclenchés.

Si votre plugin est plgiesrelatednewsprogramme, le nom de la classe doit être PlgK2Plgiesrelatednewsprogramme.

2
Anibal