beginnings of NAA data import
[disclosr.git] / lib / FeedWriter / examples / example_rss2.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
<<<<<<< HEAD
<?php
 
/* 
 * Copyright (C) 2008 Anis uddin Ahmad <anisniit@gmail.com>
 *
 * This file is part of the "Universal Feed Writer" project.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
* 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
  
  include("../FeedTypes.php");
  
  //Creating an instance of RSS2FeedWriter class. 
  //The constant RSS2 is passed to mention the version
  $TestFeed = new RSS2FeedWriter();
  
  //Setting the channel elements
  //Use wrapper functions for common channel elements
  $TestFeed->setTitle('Testing & Checking the RSS writer class');
  $TestFeed->setLink('http://www.ajaxray.com/projects/rss');
  $TestFeed->setDescription('This is a test of creating a RSS 2.0 feed with Universal Feed Writer');
  
  //Image title and link must match with the 'title' and 'link' channel elements for RSS 2.0
  $TestFeed->setImage('Testing the RSS writer class','http://www.ajaxray.com/projects/rss','http://www.rightbrainsolution.com/_resources/img/logo.png');
  
  //Use core setChannelElement() function for other optional channels
  $TestFeed->setChannelElement('language', 'en-us');
  $TestFeed->setChannelElement('pubDate', date(DATE_RSS, time()));
  
  //Adding a feed. Genarally this portion will be in a loop and add all feeds.
  
  //Create an empty FeedItem
  $newItem = $TestFeed->createNewItem();
  
  //Add elements to the feed item
  //Use wrapper functions to add common feed elements
  $newItem->setTitle('The first feed');
  $newItem->setLink('http://www.yahoo.com');
  //The parameter is a timestamp for setDate() function
  $newItem->setDate(time());
  $newItem->setDescription('This is a test of adding CDATA encoded description by the php <b>Universal Feed Writer</b> class');
  $newItem->setEncloser('http://www.attrtest.com', '1283629', 'audio/mpeg');
  //Use core addElement() function for other supported optional elements
  $newItem->addElement('author', 'admin@ajaxray.com (Anis uddin Ahmad)');
  //Attributes have to passed as array in 3rd parameter
  $newItem->addElement('guid', 'http://www.ajaxray.com',array('isPermaLink'=>'true'));
  
  //Now add the feed item
  $TestFeed->addItem($newItem);
  
  //Another method to add feeds from array()
  //Elements which have attribute cannot be added by this way
  $newItem = $TestFeed->createNewItem();
  $newItem->addElementArray(array('title'=>'The 2nd feed', 'link'=>'http://www.google.com', 'description'=>'This is a test of the FeedWriter class'));
  $TestFeed->addItem($newItem);
  
  //OK. Everything is done. Now genarate the feed.
  $TestFeed->generateFeed();
  
?>
=======
<?php
 
// You should use an autoloader instead of including the files directly.
// This is done here only to make the examples work out of the box.
include('../Item.php');
include('../Feed.php');
include('../RSS2.php');
 
date_default_timezone_set('UTC');
 
use \FeedWriter\RSS2;
 
/**
 * Copyright (C) 2008 Anis uddin Ahmad <anisniit@gmail.com>
 * Copyright (C) 2013 Michael Bemmerl <mail@mx-server.de>
 *
 * This file is part of the "Universal Feed Writer" project.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
// Creating an instance of RSS2 class.
$TestFeed = new RSS2;
 
// Setting some basic channel elements. These three elements are mandatory.
$TestFeed->setTitle('Testing & Checking the Feed Writer project');
$TestFeed->setLink('https://github.com/mibe/FeedWriter');
$TestFeed->setDescription('This is just an example how to use the Feed Writer project in your code.');
 
// Image title and link must match with the 'title' and 'link' channel elements for RSS 2.0,
// which were set above.
$TestFeed->setImage('Testing & Checking the Feed Writer project', 'https://github.com/mibe/FeedWriter', 'https://upload.wikimedia.org/wikipedia/commons/thumb/d/d9/Rss-feed.svg/256px-Rss-feed.svg.png');
 
// Use core setChannelElement() function for other optional channel elements.
// See http://www.rssboard.org/rss-specification#optionalChannelElements
// for other optional channel elements. Here the language code for American English and
$TestFeed->setChannelElement('language', 'en-US');
 
// The date when this feed was lastly updated. The publication date is also set.
$TestFeed->setDate(date(DATE_RSS, time()));
$TestFeed->setChannelElement('pubDate', date(\DATE_RSS, strtotime('2013-04-06')));
 
// You can add additional link elements, e.g. to a PubSubHubbub server with custom relations.
// It's recommended to provide a backlink to the feed URL.
$TestFeed->setSelfLink('http://example.com/myfeed');
$TestFeed->setAtomLink('http://pubsubhubbub.appspot.com', 'hub');
 
// You can add more XML namespaces for more custom channel elements which are not defined
// in the RSS 2 specification. Here the 'creativeCommons' element is used. There are much more
// available. Have a look at this list: http://feedvalidator.org/docs/howto/declare_namespaces.html
$TestFeed->addNamespace('creativeCommons', 'http://backend.userland.com/creativeCommonsRssModule');
$TestFeed->setChannelElement('creativeCommons:license', 'http://www.creativecommons.org/licenses/by/1.0');
 
// If you want you can also add a line to publicly announce that you used
// this fine piece of software to generate the feed. ;-)
$TestFeed->addGenerator();
 
// Here we are done setting up the feed. What's next is adding some feed items.
 
// Create a new feed item.
$newItem = $TestFeed->createNewItem();
 
// Add basic elements to the feed item
// These are again mandatory for a valid feed.
$newItem->setTitle('Hello World!');
$newItem->setLink('http://www.example.com');
$newItem->setDescription('This is a test of adding a description by the <b>Feed Writer</b> classes. It\'s automatically CDATA encoded.');
 
// The following method calls add some optional elements to the feed item.
 
// Let's set the publication date of this item. You could also use a UNIX timestamp or
// an instance of PHP's DateTime class.
$newItem->setDate('2013-04-07 00:50:30');
 
// You can also attach a media object to a feed item. You just need the URL, the byte length
// and the MIME type of the media. Here's a quirk: The RSS2 spec says "The url must be an http url.".
// Other schemes like ftp, https, etc. produce an error in feed validators.
$newItem->setEnclosure('http://upload.wikimedia.org/wikipedia/commons/4/49/En-us-hello-1.ogg', 11779, 'audio/ogg');
 
// If you want you can set the name (and email address) of the author of this feed item.
$newItem->setAuthor('Anis uddin Ahmad', 'admin@ajaxray.com');
 
// You can set a globally unique identifier. This can be a URL or any other string.
// If you set permaLink to true, the identifier must be an URL. The default of the
// permaLink parameter is false.
$newItem->setId('http://example.com/URL/to/article', true);
 
// Use the addElement() method for other optional elements.
// This here will add the 'source' element. The second parameter is the value of the element
// and the third is an array containing the element attributes.
$newItem->addElement('source', 'Mike\'s page', array('url' => 'http://www.example.com'));
 
// Now add the feed item to the main feed.
$TestFeed->addItem($newItem);
 
// Another method to add feeds items is by using an array which contains key-value pairs
// of every item element. Elements which have attributes cannot be added by this way.
$newItem = $TestFeed->createNewItem();
$newItem->addElementArray(array('title'=> 'The 2nd item', 'link' => 'http://www.google.com', 'description' => 'Just another test.'));
$TestFeed->addItem($newItem);
 
// OK. Everything is done. Now generate the feed.
// If you want to send the feed directly to the browser, use the printFeed() method.
$myFeed = $TestFeed->generateFeed();
 
// Do anything you want with the feed in $myFeed. Why not send it to the browser? ;-)
// You could also save it to a file if you don't want to invoke your script every time.
echo $myFeed;
>>>>>>> origin/master