1

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

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>
4

1 回答 1

2

您在 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也可以帮助你。

问候!

于 2013-09-06T22:03:34.647 回答