2012-04-11 77 views
1

我想部署一個簡單的插件到Joomla 2.5安裝。插件中的代碼位於類聲明之外,並將兩個腳本標記添加到頭部。但是,內部的代碼什麼都不做。我無法更改$ article-> title或$ article->文字。我從不同的文章中複製和粘貼,但是一切似乎只談1.5。 1.7的東西,我找到只提到更改onPrepareContent onContentPrepare。兩者似乎都沒有做任何事情。我將不勝感激任何幫助!Joomla 2.5內容插件

<?php 
    // No direct access. 
    defined('_JEXEC') or die('Restricted access'); 

    class plgContentPicasaGallery extends JPlugin 
    { 
     /** 
     * 
     * @param string The context of the content being passed to the plugin. 
     * @param mixed An object with a "text" property. 
     * @param array Additional parameters. 
     * @param int  Optional page number. Unused. Defaults to zero. 
     * @return boolean True on success. 
     */ 
     public function onContentBeforeDisplay($context, &$article, &$params, $page = 0) 
     { 

      if (is_object($article)) { 
       $article->text = "omfg, wtf?"; 
       return true; 
      } else { 
       $article = "omfg, I'm not an object, wtf?"; 
       return true; 
      } 
     } 

    } 

回答

2

的Joomla文檔&教程過時了一點,新的框架改變了一些事情。 要查找正確的簽名,只需查看/plugins/content/...文件。

下面是適當的功能簽名& phpdoc爲onContentPrepare

/** 
* @param string The context of the content being passed to the plugin. 
* @param object The article object. Note $article->text is also available 
* @param object The article params 
* @param int  The 'page' number 
*/ 
public function onContentPrepare($context, &$article, &$params, $page = 0) 
{ 
    ... 
} 
+0

我更新了我上面的代碼的東西,我直接從/插件/的emailcloak插件了內容/目錄。我刪除了除$ article->文本引用之外的所有內容...仍然沒有對頁面內容的實際內容做任何事情。 – pendo 2012-04-12 16:18:54

+0

你註冊並啓用了插件嗎? – Alex 2012-04-12 17:50:04

+0

我做過了,但我只是更新文件,我需要做的是重新上傳軟件包,或者刷新插件的緩存。現在我明白了,我明白了。再次感謝你的幫助!! – pendo 2012-04-12 21:52:13

1

我對Joomla的好感勝過我的良知。我正在編輯服務器上的插件文件,並期待更新插件。謝謝您的幫助!

0

您可以使用此方法

jimport('joomla.form.helper'); 
$urla= JRequest::getVar('id'); 
$urlview= JRequest::getVar('view'); 
if ($urlview=='article') 
{} 
if ($urla==10<- number id article) 
{} 

我知道框架Joomla是好的,但其理解方法