如何处理来自Joomla';WordPress的RSS数据;的RSS模块


How to handle RSS data coming from WordPress for Joomla's RSS Module?

我正在尝试开发Bootstrap的旋转木马模块,用于使用Joomla 3.3.3网站的RSS提要从远程网站获取新闻。这是一个WordPress网站。我已经将以下代码添加到WP网站的theme/functions.php

function zkanoca_add_image_to_rss() {
    $thumb_id = get_post_thumbnail_id( get_the_ID() );
    if ( ! empty( $thumb_id ) ) {
        echo '<myimage>' . wp_get_attachment_url( $thumb_id ) . '</myimage>';
    }
}
add_action('rss2_item', 'zkanoca_add_image_to_rss');
add_action('rss_item', 'zkanoca_add_image_to_rss');

现在,当我查看源代码时,可以在rss提要中看到<myimage>[image_url]</myimage>行。

但我不知道如何在Joomla的RSS提要模块(mod_feed)上处理它。

我已经尝试使用提取图像url

 $feed[$i]->myimage;

就像CCD_ 2一样处于循环中,但不起作用。

我为一个项目调用了var_dump()函数,但看不到<myimage>信息的关键元素。

我找到了/librarys/joomla/feed/parser/rss.php,然后添加了

protected function handleMyimage(JFeed $feed, SimpleXMLElement $el) {
        $feed->myimage = (string) $el;
    }

之后,我修改了/librarys/joomla/feed/feed.php

// /libraries/joomla/feed/feed.php
protected $properties = array(
    'uri' => '',
    'title' => '',
    'updatedDate' => '',
    'description' => '',
    'categories' => array(),
    'contributors' => array(),
    'myimage' => '' //added this key
);

然后我添加了

 // /libraries/joomla/feed/link.php line 60s
 public $myimage;

转换为JFeedLink类并修改

// /libraries/joomla/feed/link.php line 90s
public function __construct($uri = null, $relation = null, $type = null, $language = null, $title = null, $length = null ) {
        $this->uri = $uri;
        $this->relation = $relation;
        $this->type = $type;
        $this->language = $language;
        $this->title = $title;
        // Validate the length input.
        if (isset($length) && !is_numeric($length)) {
            throw new InvalidArgumentException('Length must be numeric.');
        }
        $this->length = (int) $length;
    }

// /libraries/joomla/feed/link.php line 90s 
public function __construct($uri = null, $relation = null, $type = null, $language = null, $title = null, $length = null,  /* added this */ $myimage = null /**/) {
        $this->uri = $uri;
        $this->relation = $relation;
        $this->type = $type;
        $this->language = $language;
        $this->title = $title;
        $this->myimage = $myimage; //added this line too
        // Validate the length input.
        if (isset($length) && !is_numeric($length)) {
            throw new InvalidArgumentException('Length must be numeric.');
        }
        $this->length = (int) $length;
    }

/librarys/joomla/feed/link.php中

输出如下

<item>
    <title>Title here</title>
    <link>http://example.com/?p=112</link>
    <comments>http://example.com/?p=112#comments</comments>
    <pubDate>Fri, 08 Aug 2014 06:05:56 +0000</pubDate>
    <dc:creator><![CDATA[Creator Information here]]></dc:creator>
    <category><![CDATA[General]]></category>
    <category><![CDATA[Arts]]></category>
    <guid isPermaLink="false">http://example.com/?p=112</guid>
    <description><![CDATA[ some text here [&#8230;]]]></description>
    <content:encoded><![CDATA[more text here]]></content:encoded>
    <wfw:commentRss>http://example.com/?feed=rss2&#038;p=112</wfw:commentRss>
    <slash:comments>0</slash:comments>
    <myimage>http://example.com/wp-content/uploads/2014/08/013.jpg</myimage>
</item>

我几乎要成功地完成它了:)我忘了在/librarys/joomla/feed/parser/rss.php中只添加一行

protected function processFeedEntry(JFeedEntry $entry, SimpleXMLElement $el) {
        $entry->uri = (string) $el->link;
        $entry->title = (string) $el->title;
        $entry->publishedDate = (string) $el->pubDate;
        $entry->updatedDate = (string) $el->pubDate;
        $entry->content = (string) $el->description;
        $entry->guid = (string) $el->guid;
        $entry->comments = (string) $el->comments;
        //this line
        $entry->myimage= (string) $el->myimage;

现在,我的问题已经解决了。