Joomla 2.5插件无法正常工作

时间:2013-09-18 12:37:29

标签: plugins joomla

我是初学者,我想为我的网站编写一个简单的插件,但我遇到了一些问题。

当我尝试通过div将我的插件导入文章

<div id="locker-464" class="like-dl blue"> </div>

我只获得css帧没有js。

jimport('joomla.plugin.plugin');
$document = & JFactory::getDocument();
$document->addStyleSheet(JURI::root() . 'plugins/content/plugin/tmpl/css/style.css', 'text/css', null, array() );
$document->addScript(JURI::root() . 'plugins/content/plugin/tmpl/js/liketodownlad.js');
$document->addScript ("https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js");
$document->addScript ("http://connect.facebook.net/en_US/all.js#xfbml=1");

class plgContentLiketoDownload extends JPlugin {

function plgContentLiketoDownload( &$subject, $params ) 
    {
        parent::__construct( $subject, $params );
    }

 function onContentPrepare($context, &$params)
 {
 global $mainframe;
    $app = JFactory::getApplication();
    $plugin = & JPluginHelper::getPlugin('content', 'plugin');
    echo "<script type=\"text/javascript\">
        var $jx = jQuery.noConflict();
            $jx(document).ready(function(){        

                $jx('#locker-464').liketodl({
                download_url: 'http://website.com/sampleDownload.zip',
                like_url: 'https://www.facebook.com/FBpage',
                like_colorscheme: 'light'
                });

                $jx('#locker-564').liketodl({
                download_url: 'sampleDownload.zip',
                like_url: 'http://google.com',
                like_colorscheme: 'list'
                });

            });";
</script>";

    return true;
 }
}

?>

1 个答案:

答案 0 :(得分:0)

onContentPrepare方法签名是:

public function onContentPrepare($context, &$row, &$params, $page = 0)
{
... your stuff
}

如果要替换文章内容,分配$ row-&gt;文本将改变输出。请查看/plugins/content/pagebreak/pagebreak.php以获取示例。

如果您使用的是PHP 5.x,请不要使用plgContentLikeToDownload作为构造函数:

public function __construct(& $subject, $config)
{
        parent::__construct($subject, $config);
        $this->loadLanguage(); // if needed
}

请参阅http://docs.joomla.org/J2.5:Creating_a_Plugin_for_Joomla

修改


删除类声明之外的所有代码并尝试:

jimport('joomla.plugin.plugin');
class plgContentLiketoDownload extends JPlugin {

    function plgContentLiketoDownload( &$subject, $params ) 
    {
        parent::__construct( $subject, $params );
    }

    public function onContentPrepare($context, &$row, &$params, $page = 0)
    {
       $row->text = "Hello world!";
       return true;
    }
}

结束编辑

此致