2014-08-29 61 views
0

我正在嘗試開發Bootstrap的輪播模塊,用於從遠程網站使用RSS源爲我的Joomla 3.3.3網站獲取的新聞。這是一個WordPress網站。我加入以下代碼WP網站的主題/ functions.php中如何處理來自WordPress的Joomla RSS模塊的RSS數據?

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)。

我試圖提取就像$feed[$i]->title;循環中使用

$feed[$i]->myimage; 

圖像的URL,但沒有奏效。

我打電話var_dump()功能的項目,但看不到<myimage>信息的關鍵要素。

我發現/libraries/joomla/feed/parser/rss.php,然後加入

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

在那之後,我已經修改/libraries/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; 
    } 

的/libraries/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> 

回答

0

我幾乎要完成它了成功:) 我已經忘記了,只是一個行加入/libraries/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; 

現在,我的問題已經沒有了。