Advertisement:

Author Topic: Add info in RSS Feed  (Read 3139 times)

Alessandro

  • Newbie
  • *
  • Posts: 17
Add info in RSS Feed
« on: October 12, 2015, 02:44:02 pm »
Hi all,
how can I add the ID and address info for each ad in the RSS code?
Is there a safe way to duplicate the feed stream (es: feed1, feed2, etc.)?

Here below the actual code applied in the Osclass feed.

Code: [Select]
<?php if ( ! defined('ABS_PATH')) exit('ABS_PATH is not loaded. Direct access is not allowed.');
/*
 * Copyright 2014 Osclass
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
    /**
     * This class takes items descriptions and generates a RSS feed from that information.
     * @author Osclass
     */
    
class RSSFeed {
        private 
$title;
        private 
$link;
        private 
$description;
        private 
$items;
        public function 
__construct() {
            
$this->items = array();
        }
        public function 
setTitle($title) {
            
$this->title $title;
        }
        public function 
setLink($link) {
            
$this->link $link;
        }
        public function 
setDescription($description) {
            
$this->description $description;
        }
        public function 
addItem($item) {
            
$this->items[] = $item;
        }
        public function 
dumpXML() {
            echo 
'<?xml version="1.0" encoding="UTF-8"?>
', PHP_EOL;
            echo '<rss version="2.0">', PHP_EOL;
            echo '<channel>', PHP_EOL;
            echo '<title>', $this->title, '</title>', PHP_EOL;
            echo '<link>', $this->link, '</link>', PHP_EOL;
            echo '<description>', $this->description, '</description>', PHP_EOL;
            foreach ($this->items as $item) {
                echo '<item>', PHP_EOL;
                echo '<title><![CDATA[', $item['title'], ']]></title>', PHP_EOL;
                echo '<link>', $item['link'], '</link>', PHP_EOL;
                echo '<guid>', $item['link'], '</guid>', PHP_EOL;
                echo '<description><![CDATA[';
                if(@$item['image']) {
                    echo '<a href="'.$item['image']['link'].'" title="'.$item['image']['title'].'" rel="nofollow">';
                    echo '<img style="float:left;border:0px;" src="'.$item['image']['url'].'" alt="'.$item['image']['title'].'"/> </a>';
                }
                echo $item['description'], ']]>';
                echo '</description>', PHP_EOL;
                echo '<country>', $item['country'], '</country>', PHP_EOL;
                echo '<region>', $item['region'], '</region>', PHP_EOL;
                echo '<city>', $item['city'], '</city>', PHP_EOL;
                echo '<cityArea>', $item['city_area'], '</cityArea>', PHP_EOL;
                echo '<category>', $item['category'], '</category>', PHP_EOL;
                echo '<pubDate>', date('r',strtotime($item['dt_pub_date'])) , '</pubDate>', PHP_EOL;
               
                echo '</item>', PHP_EOL;
            }
            echo '</channel>', PHP_EOL;
            echo '</rss>', PHP_EOL;
        }
    }
?>

Alessandro

  • Newbie
  • *
  • Posts: 17
Re: Add info in RSS Feed
« Reply #1 on: October 23, 2015, 01:32:26 pm »
in order to resolve my issue, how can I add a custom field in Osclass RSS Feed?

Malefol7

  • Full Member
  • ***
  • Posts: 134
Re: Add info in RSS Feed
« Reply #2 on: October 23, 2015, 03:40:44 pm »
hello, I did not understand well what would you do, change the core osclass not recommended, I would install rss feed plugins (free) and then if necessary would the changes of my interest.

Alessandro

  • Newbie
  • *
  • Posts: 17
Re: Add info in RSS Feed
« Reply #3 on: October 23, 2015, 06:57:14 pm »
I need to add in the RSS Feed a custom field added in item post page.

I have already installed the extra feed plugin but it doesn't create a standard xml output.
Can you advise me of other free plugins?

Malefol7

  • Full Member
  • ***
  • Posts: 134
Re: Add info in RSS Feed
« Reply #4 on: October 24, 2015, 01:03:18 pm »
hello, there are other free plugins, the only way is to create one specifically for your needs, I'm sorry, nothing else. :)

Alessandro

  • Newbie
  • *
  • Posts: 17
Re: Add info in RSS Feed
« Reply #5 on: October 24, 2015, 09:03:48 pm »
hello, there are other free plugins, the only way is to create one specifically for your needs, I'm sorry, nothing else. :)
So there aren't other plugins, I must create one...  ;)

Malefol7

  • Full Member
  • ***
  • Posts: 134
Re: Add info in RSS Feed
« Reply #6 on: October 24, 2015, 11:56:19 pm »
hello, try adding these two fields to the class rss feed:



echo '<address>', $item['s_address'], '</address>', PHP_EOL;
echo '<id>', $item['pk_i_id'], '</id>', PHP_EOL;


 ;)

Alessandro

  • Newbie
  • *
  • Posts: 17
Re: Add info in RSS Feed
« Reply #7 on: October 27, 2015, 12:39:35 pm »
hello, try adding these two fields to the class rss feed:

echo '<address>', $item['s_address'], '</address>', PHP_EOL;
echo '<id>', $item['pk_i_id'], '</id>', PHP_EOL;

 ;)

It doesn't work  :(
ID and Address tag are still blank

Code: [Select]
<ad>
<id/>
<company/>
<title>
Hai passione verso il settore wellness e nutrizione?
</title>
<url>
http://www.buzzajob.it/piemonte/torino/hai-passione-verso-il-settore-wellness-e-nutrizione_i673
</url>
<address/>
<id/>
<content>
<![CDATA[
Selezioni per nuove figure richieste dal mercato Hai passione verso il settore wellness e nutrizione? Selezioniamo 4 candidati, per opportunità di lavoro come consulente. Possibilità in part time o in tempo pieno. Per avere maggiori informazioni e fissare un appuntamento per un colloquio, inviare il proprio CV.
]]>
</content>
<city>Torino</city>
<pubDate>Tue, 20 Oct 2015 21:47:37 +0200</pubDate>
</ad>

Malefol7

  • Full Member
  • ***
  • Posts: 134
Re: Add info in RSS Feed
« Reply #8 on: October 27, 2015, 11:10:22 pm »

Hello,
I did some tests and saw that just as I said it will never work because some parameters are passed in the array variable item,
the 'only way to customize the feed is to create one specifically for your purpose.

Alessandro

  • Newbie
  • *
  • Posts: 17
Re: Add info in RSS Feed
« Reply #9 on: October 28, 2015, 01:16:41 am »

Hello,
I did some tests and saw that just as I said it will never work because some parameters are passed in the array variable item,
the 'only way to customize the feed is to create one specifically for your purpose.
Ok, thanks for your kindly support.
So, as I said some posts ago, "there aren't other plugins, I must create one".
Bye

Alessandro

  • Newbie
  • *
  • Posts: 17
Re: Add info in RSS Feed
« Reply #10 on: October 31, 2015, 10:03:23 pm »
Eureka! I have fixed my RSS feed  :)

Here below how to do:

add this in class RSSFeed
Code: [Select]
private $id;
and then declare the pubblic function:
Code: [Select]
public function setId($id) {
$this->id = $id;
}

and this in the public function dumpXML
Code: [Select]
echo '<id>', $item['id'], '</id>', PHP_EOL;
Hope this will help to those who need it.
Bye

Alessandro

  • Newbie
  • *
  • Posts: 17
Re: Add info in RSS Feed
« Reply #11 on: November 03, 2015, 07:39:44 pm »
Is there a way to duplicate my RSS feed (built in OSclass, no extra-feed thanks  ;))?
Different partners need to have populated the xml output with different tags and I would like to offer one url for each of them.

http://www.example.com/feed_partner1
http://www.example.com/feed_partner2
...

Alessandro

  • Newbie
  • *
  • Posts: 17
Re: Add info in RSS Feed
« Reply #12 on: January 19, 2016, 04:41:00 pm »
Is there a way to duplicate my RSS feed (built in OSclass, no extra-feed thanks  ;))?
Different partners need to have populated the xml output with different tags and I would like to offer one url for each of them.

http://www.example.com/feed_partner1
http://www.example.com/feed_partner2
...

Any tips to create more feed on my osclass website?