Joomla Facebook插件使用onContentAfterSave触发器不起作用


Joomla Facebook plugin using onContentAfterSave trigger not working

我已经通过在onContentAfterSave()函数的第一行放置一个die('test')语句来检查此触发器是否正常工作。我想知道为什么里面的其余代码不起作用。

defined('_JEXEC') or die ('Access Deny');
class plgContentMypost extends JPlugin {
    public function onContentAfterSave( $context, $article, $isNew  )
    {
    require_once JPATH_ROOT  . '/plugins/content/mypost/src/facebook.php';
        $appId = '233015226851759';
        $secret = '95daba36aa48679229e';
        $returnurl = 'http://localhost/sample/examples';
        $permissions = 'manage_pages, publish_stream, publish_actions';
        // Create our Application instance (replace this with your appId and secret).
        $fb = new Facebook(array(
          'appId'  => $appId,
          'secret' => $secret,
        ));
        $access_token = $fb->getAccessToken();
        $name = 'LUPIN'; 
        $message = 'this is a message'; 
        $description = 'this is my description';
        $pictureUrl = 'http://rofi.philfire.com.ph/joomla16/images/iphone-4-top-new-1.jpg';
        $link = 'http://rofi.philfire.com.ph/joomla16/'; 
        $attachment =  array(
            'access_token' => $access_token,
            'message' => "$message",
            'name' => "$name",
            'description' => "$description",
            'link' => "$link",
            'picture' => "$pictureUrl",
            // 'actions' => array('name'=>'Try it now', 'link' => "$appUrl")
        );
        $post_id = $fb->api("me/feed","POST",$attachment);
    }
}
如果我将此代码

用作独立代码,它可以正常工作并将内容发布在Facebook上。

require_once '/src/facebook.php';
$appId = '233015226851759';
$secret = '95daba36aa48679229e';
$returnurl = 'http://localhost/sample/examples';
$permissions = 'manage_pages, publish_stream, publish_actions';
// Create our Application instance (replace this with your appId and secret).
$fb = new Facebook(array(
    'appId'  => $appId,
    'secret' => $secret,      
));
$access_token = $fb->getAccessToken();
$name = 'LUPIN'; 
$message = 'this is a message'; 
$description = 'this is my description';
$pictureUrl = 'http://rofi.philfire.com.ph/joomla16/images/iphone-4-top-new-1.jpg';
$link = 'http://rofi.philfire.com.ph/joomla16/'; 
$attachment =  array(
    'access_token' => $access_token,
    'message' => "$message",
    'name' => "$name",
    'description' => "$description",
    'link' => "$link",
    'picture' => "$pictureUrl",
    // 'actions' => array('name'=>'Try it now', 'link' => "$appUrl")
);
$post_id = $fb->api("me/feed","POST",$attachment);

下面是我的XML文件:

<?xml version="1.0" ?>
<extension type="plugin" version="2.5.0" method="upgrade" group="content">
    <name>My Post</name>
    <author>Mark Orosa</author>
    <version>1.0.0</version>
    <description>This is My FB Post Plugin</description>
    <files>
        <filename plugin="mypost">mypost.php</filename>
        <folder>src</folder>
        <filename>mypost.xml</filename>
        <filename>index.html</filename>
    </files>
    <config></config>
</extension>

您在require_once上使用的文件路径不正确。src 目录位于/path_to_your_install/plugins/content/mypost 下

所以你最好尝试这样的东西:

require_once JPATH_ROOT . '/plugins/content/mypost/src/facebook.php'

在此处检查要使用的正确 JPATH 常量 http://docs.joomla.org/Constants

也许这个 http://docs.joomla.org/J2.5:Creating_a_Plugin_for_Joomla 也可以帮助你。

问候!

相关文章:
  • 没有找到相关文章