Browse Source

applies PSR-1 and PSR-2 coding standards

Kristián Valentín 5 years ago
parent
commit
048768bc02
9 changed files with 1534 additions and 1609 deletions
  1. 8
    8
      ATOM.php
  2. 813
    869
      Feed.php
  3. 373
    392
      Item.php
  4. 9
    9
      RSS1.php
  5. 7
    7
      RSS2.php
  6. 71
    71
      examples/example_atom.php
  7. 64
    64
      examples/example_minimum.php
  8. 70
    70
      examples/example_rss1.php
  9. 119
    119
      examples/example_rss2.php

+ 8
- 8
ATOM.php View File

@@ -25,14 +25,14 @@ namespace FeedWriter;
25 25
  *
26 26
  * @package     UniversalFeedWriter
27 27
  */
28
-class Atom extends Feed
28
+class ATOM extends Feed
29 29
 {
30
-	/**
31
-	* {@inheritdoc}
32
-	*/
33
-	function __construct()
34
-	{
35
-		parent::__construct(Feed::ATOM);
36
-	}
30
+    /**
31
+    * {@inheritdoc}
32
+    */
33
+    public function __construct()
34
+    {
35
+        parent::__construct(Feed::ATOM);
36
+    }
37 37
 
38 38
 }

+ 813
- 869
Feed.php
File diff suppressed because it is too large
View File


+ 373
- 392
Item.php View File

@@ -1,392 +1,373 @@
1
-<?php
2
-namespace FeedWriter;
3
-
4
-use \DateTime;
5
-
6
-/*
7
- * Copyright (C) 2008 Anis uddin Ahmad <anisniit@gmail.com>
8
- * Copyright (C) 2010-2013 Michael Bemmerl <mail@mx-server.de>
9
- *
10
- * This file is part of the "Universal Feed Writer" project.
11
- *
12
- * This program is free software: you can redistribute it and/or modify
13
- * it under the terms of the GNU General Public License as published by
14
- * the Free Software Foundation, either version 3 of the License, or
15
- * (at your option) any later version.
16
- *
17
- * This program is distributed in the hope that it will be useful,
18
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
- * GNU General Public License for more details.
21
- *
22
- * You should have received a copy of the GNU General Public License
23
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
24
- */
25
-
26
-/**
27
- * Universal Feed Writer
28
- *
29
- * Item class - Used as feed element in Feed class
30
- *
31
- * @package         UniversalFeedWriter
32
- * @author          Anis uddin Ahmad <anisniit@gmail.com>
33
- * @link            http://www.ajaxray.com/projects/rss
34
- */
35
-class Item
36
-{
37
-	/**
38
-	* Collection of feed item elements
39
-	*/
40
-	private $elements = array();
41
-
42
-	/**
43
-	* Contains the format of this feed.
44
-	*/
45
-	private $version;
46
-
47
-	/**
48
-	 * Is used as a suffix when multiple elements have the same name.
49
-	 **/
50
-	private $_cpt = 0;
51
-
52
-	/**
53
-	* Constructor
54
-	*
55
-	* @param    constant     (RSS1/RSS2/ATOM) RSS2 is default.
56
-	*/
57
-	function __construct($version = Feed::RSS2)
58
-	{
59
-		$this->version = $version;
60
-	}
61
-
62
-	/**
63
-	 * Return an unique number
64
-	 * @access private
65
-	 * @return int
66
-	 **/
67
-	private function cpt() {
68
-		return $this->_cpt++;
69
-	}
70
-
71
-	/**
72
-	* Add an element to elements array
73
-	*
74
-	* @access   public
75
-	* @param    string  The tag name of an element
76
-	* @param    string  The content of tag
77
-	* @param    array   Attributes(if any) in 'attrName' => 'attrValue' format
78
-	* @param    boolean Specifies if an already existing element is overwritten.
79
-	* @param    boolean Specifies if multiple elements of the same name are allowed.
80
-	* @return   void
81
-	*/
82
-	public function addElement($elementName, $content, $attributes = null, $overwrite = FALSE, $allowMultiple = FALSE)
83
-	{
84
-
85
-		$key = $elementName;
86
-
87
-		// return if element already exists & if overwriting is disabled
88
-		// & if multiple elements are not allowed.
89
-		if (isset($this->elements[$elementName]) && !$overwrite) {
90
-			if (!$allowMultiple)
91
-				return;
92
-
93
-			$key .= '-' . $this->cpt();
94
-		}
95
-
96
-
97
-		$this->elements[$key]['name']       = $elementName;
98
-		$this->elements[$key]['content']    = $content;
99
-		$this->elements[$key]['attributes'] = $attributes;
100
-
101
-		return $this;
102
-	}
103
-
104
-	/**
105
-	* Set multiple feed elements from an array.
106
-	* Elements which have attributes cannot be added by this method
107
-	*
108
-	* @access   public
109
-	* @param    array   array of elements in 'tagName' => 'tagContent' format.
110
-	* @return   void
111
-	*/
112
-	public function addElementArray($elementArray)
113
-	{
114
-		if (!is_array($elementArray))
115
-			return;
116
-
117
-		foreach ($elementArray as $elementName => $content)
118
-		{
119
-			$this->addElement($elementName, $content);
120
-		}
121
-
122
-		return $this;
123
-	}
124
-
125
-	/**
126
-	* Return the collection of elements in this feed item
127
-	*
128
-	* @access   public
129
-	* @return   array
130
-	*/
131
-	public function getElements()
132
-	{
133
-		return $this->elements;
134
-	}
135
-
136
-	/**
137
-	* Return the type of this feed item
138
-	*
139
-	* @access   public
140
-	* @return   string  The feed type, as defined in Feed.php
141
-	*/
142
-	public function getVersion()
143
-	{
144
-		return $this->version;
145
-	}
146
-
147
-	// Wrapper functions ------------------------------------------------------
148
-
149
-	/**
150
-	* Set the 'description' element of feed item
151
-	*
152
-	* @access   public
153
-	* @param    string  The content of 'description' or 'summary' element
154
-	* @return   void
155
-	*/
156
-	public function setDescription($description)
157
-	{
158
-		$tag = ($this->version == Feed::ATOM) ? 'summary' : 'description';
159
-		return $this->addElement($tag, $description);
160
-	}
161
-
162
-	/**
163
-	 * Set the 'content' element of the feed item
164
-	 * For ATOM feeds only
165
-	 *
166
-	 * @access public
167
-	 * @param string Content for the item (i.e., the body of a blog post).
168
-	 * @return void
169
-	 */
170
-	public function setContent($content)
171
-	{
172
-		if ($this->version != Feed::ATOM)
173
-			die('The content element is supported in ATOM feeds only.');
174
-
175
-		return $this->addElement('content', $content, array('type' => 'html'));
176
-	}
177
-
178
-
179
-	/**
180
-	* Set the 'title' element of feed item
181
-	*
182
-	* @access   public
183
-	* @param    string  The content of 'title' element
184
-	* @return   void
185
-	*/
186
-	public function setTitle($title)
187
-	{
188
-		return $this->addElement('title', $title);
189
-	}
190
-
191
-	/**
192
-	* Set the 'date' element of the feed item.
193
-	*
194
-	* The value of the date parameter can be either an instance of the
195
-	* DateTime class, an integer containing a UNIX timestamp or a string
196
-	* which is parseable by PHP's 'strtotime' function.
197
-	*
198
-	* @access   public
199
-	* @param    DateTime|int|string  Date which should be used.
200
-	* @return   void
201
-	*/
202
-	public function setDate($date)
203
-	{
204
-		if(!is_numeric($date))
205
-		{
206
-			if ($date instanceof DateTime)
207
-				$date = $date->getTimestamp();
208
-			else
209
-			{
210
-				$date = strtotime($date);
211
-
212
-				if ($date === FALSE)
213
-					die('The given date string was not parseable.');
214
-			}
215
-		}
216
-		else if ($date < 0)
217
-			die('The given date is not an UNIX timestamp.');
218
-
219
-		if($this->version == Feed::ATOM)
220
-		{
221
-			$tag    = 'updated';
222
-			$value  = date(\DATE_ATOM, $date);
223
-		}
224
-		elseif($this->version == Feed::RSS2)
225
-		{
226
-			$tag    = 'pubDate';
227
-			$value  = date(\DATE_RSS, $date);
228
-		}
229
-		else
230
-		{
231
-			$tag    = 'dc:date';
232
-			$value  = date("Y-m-d", $date);
233
-		}
234
-
235
-		return $this->addElement($tag, $value);
236
-	}
237
-
238
-	/**
239
-	* Set the 'link' element of feed item
240
-	*
241
-	* @access   public
242
-	* @param    string  The content of 'link' element
243
-	* @return   void
244
-	*/
245
-	public function setLink($link)
246
-	{
247
-		if($this->version == Feed::RSS2 || $this->version == Feed::RSS1)
248
-		{
249
-			$this->addElement('link', $link);
250
-		}
251
-		else
252
-		{
253
-			$this->addElement('link','',array('href'=>$link));
254
-			$this->addElement('id', Feed::uuid($link,'urn:uuid:'));
255
-		}
256
-
257
-		return $this;
258
-	}
259
-
260
-	/**
261
-	* Attach a external media to the feed item.
262
-	* Not supported in RSS 1.0 feeds.
263
-	*
264
-	* See RFC 4288 for syntactical correct MIME types.
265
-	*
266
-	* Note that you should avoid the use of more than one enclosure in one item,
267
-	* since some RSS aggregators don't support it.
268
-	*
269
-	* @access   public
270
-	* @param    string  The URL of the media.
271
-	* @param    integer The length of the media.
272
-	* @param    string  The MIME type attribute of the media.
273
-	* @param    boolean Specifies, if multiple enclosures are allowed
274
-	* @return   void
275
-	* @link     https://tools.ietf.org/html/rfc4288
276
-	*/
277
-	public function addEnclosure($url, $length, $type, $multiple = TRUE)
278
-	{
279
-		if ($this->version == Feed::RSS1)
280
-			die('Media attachment is not supported in RSS1 feeds.');
281
-
282
-		// the length parameter should be set to 0 if it can't be determined
283
-		// see http://www.rssboard.org/rss-profile#element-channel-item-enclosure
284
-		if (!is_numeric($length) || $length < 0)
285
-			die('The length parameter must be an integer and greater or equals to zero.');
286
-
287
-		// Regex used from RFC 4287, page 41
288
-		if (!is_string($type) || preg_match('/.+\/.+/', $type) != 1)
289
-			die('type parameter must be a string and a MIME type.');
290
-
291
-		$attributes = array('length' => $length, 'type' => $type);
292
-
293
-		if ($this->version == Feed::RSS2)
294
-		{
295
-			$attributes['url'] = $url;
296
-			$this->addElement('enclosure', '', $attributes, FALSE, $multiple);
297
-		}
298
-		else
299
-		{
300
-			$attributes['href'] = $url;
301
-			$attributes['rel'] = 'enclosure';
302
-			$this->addElement('atom:link', '', $attributes, FALSE, $multiple);
303
-		}
304
-
305
-		return $this;
306
-	}
307
-
308
-	/**
309
-	* Alias of addEnclosure, for backward compatibility. Using only this
310
-	* method ensure that the 'enclosure' element will be present only once.
311
-	*
312
-	* @access   public
313
-	* @param    string  The URL of the media.
314
-	* @param    integer The length of the media.
315
-	* @param    string  The MIME type attribute of the media.
316
-	* @return   void
317
-	* @link     https://tools.ietf.org/html/rfc4288
318
-	*
319
-	**/
320
-	public function setEnclosure($url, $length, $type) {
321
-		return $this->addEnclosure($url, $length, $type, false);
322
-	}
323
-
324
-	/**
325
-	* Set the 'author' element of feed item.
326
-	* Not supported in RSS 1.0 feeds.
327
-	*
328
-	* @access   public
329
-	* @param    string  The author of this item
330
-	* @param    string  Optional email address of the author
331
-	* @param    string  Optional URI related to the author
332
-	* @return   void
333
-	*/
334
-	public function setAuthor($author, $email = null, $uri = null)
335
-	{
336
-		switch($this->version)
337
-		{
338
-			case Feed::RSS1: die('The author element is not supported in RSS1 feeds.');
339
-				break;
340
-			case Feed::RSS2:
341
-				if ($email != null)
342
-					$author = $email . ' (' . $author . ')';
343
-
344
-				$this->addElement('author', $author);
345
-				break;
346
-			case Feed::ATOM:
347
-				$elements = array('name' => $author);
348
-
349
-				// Regex from RFC 4287 page 41
350
-				if ($email != null && preg_match('/.+@.+/', $email) == 1)
351
-					$elements['email'] = $email;
352
-
353
-				if ($uri != null)
354
-					$elements['uri'] = $uri;
355
-
356
-				$this->addElement('author', $elements);
357
-				break;
358
-		}
359
-
360
-		return $this;
361
-	}
362
-
363
-	/**
364
-	* Set the unique identifier of the feed item
365
-	*
366
-	* @access   public
367
-	* @param    string  The unique identifier of this item
368
-	* @param    boolean The value of the 'isPermaLink' attribute in RSS 2 feeds.
369
-	* @return   void
370
-	*/
371
-	public function setId($id, $permaLink = false)
372
-	{
373
-		if ($this->version == Feed::RSS2)
374
-		{
375
-			if (!is_bool($permaLink))
376
-				die('The permaLink parameter must be boolean.');
377
-
378
-			$permaLink = $permaLink ? 'true' : 'false';
379
-
380
-			$this->addElement('guid', $id, array('isPermaLink' => $permaLink));
381
-		}
382
-		else if ($this->version == Feed::ATOM)
383
-		{
384
-			$this->addElement('id', Feed::uuid($id,'urn:uuid:'), NULL, TRUE);
385
-		}
386
-		else
387
-			die('A unique ID is not supported in RSS1 feeds.');
388
-
389
-		return $this;
390
-	}
391
-
392
- } // end of class Item
1
+<?php
2
+namespace FeedWriter;
3
+
4
+use \DateTime;
5
+
6
+/*
7
+ * Copyright (C) 2008 Anis uddin Ahmad <anisniit@gmail.com>
8
+ * Copyright (C) 2010-2013 Michael Bemmerl <mail@mx-server.de>
9
+ *
10
+ * This file is part of the "Universal Feed Writer" project.
11
+ *
12
+ * This program is free software: you can redistribute it and/or modify
13
+ * it under the terms of the GNU General Public License as published by
14
+ * the Free Software Foundation, either version 3 of the License, or
15
+ * (at your option) any later version.
16
+ *
17
+ * This program is distributed in the hope that it will be useful,
18
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
+ * GNU General Public License for more details.
21
+ *
22
+ * You should have received a copy of the GNU General Public License
23
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
24
+ */
25
+
26
+/**
27
+ * Universal Feed Writer
28
+ *
29
+ * Item class - Used as feed element in Feed class
30
+ *
31
+ * @package         UniversalFeedWriter
32
+ * @author          Anis uddin Ahmad <anisniit@gmail.com>
33
+ * @link            http://www.ajaxray.com/projects/rss
34
+ */
35
+class Item
36
+{
37
+    /**
38
+    * Collection of feed item elements
39
+    */
40
+    private $elements = array();
41
+
42
+    /**
43
+    * Contains the format of this feed.
44
+    */
45
+    private $version;
46
+
47
+    /**
48
+     * Is used as a suffix when multiple elements have the same name.
49
+     **/
50
+    private $_cpt = 0;
51
+
52
+    /**
53
+    * Constructor
54
+    *
55
+    * @param    constant     (RSS1/RSS2/ATOM) RSS2 is default.
56
+    */
57
+    public function __construct($version = Feed::RSS2)
58
+    {
59
+        $this->version = $version;
60
+    }
61
+
62
+    /**
63
+     * Return an unique number
64
+     * @access private
65
+     * @return int
66
+     **/
67
+    private function cpt()
68
+    {
69
+        return $this->_cpt++;
70
+    }
71
+
72
+    /**
73
+    * Add an element to elements array
74
+    *
75
+    * @access   public
76
+    * @param    string  The tag name of an element
77
+    * @param    string  The content of tag
78
+    * @param    array   Attributes(if any) in 'attrName' => 'attrValue' format
79
+    * @param    boolean Specifies if an already existing element is overwritten.
80
+    * @param    boolean Specifies if multiple elements of the same name are allowed.
81
+    * @return   void
82
+    */
83
+    public function addElement($elementName, $content, $attributes = null, $overwrite = FALSE, $allowMultiple = FALSE)
84
+    {
85
+
86
+        $key = $elementName;
87
+
88
+        // return if element already exists & if overwriting is disabled
89
+        // & if multiple elements are not allowed.
90
+        if (isset($this->elements[$elementName]) && !$overwrite) {
91
+            if (!$allowMultiple)
92
+                return;
93
+
94
+            $key .= '-' . $this->cpt();
95
+        }
96
+
97
+        $this->elements[$key]['name']       = $elementName;
98
+        $this->elements[$key]['content']    = $content;
99
+        $this->elements[$key]['attributes'] = $attributes;
100
+
101
+        return $this;
102
+    }
103
+
104
+    /**
105
+    * Set multiple feed elements from an array.
106
+    * Elements which have attributes cannot be added by this method
107
+    *
108
+    * @access   public
109
+    * @param    array   array of elements in 'tagName' => 'tagContent' format.
110
+    * @return   void
111
+    */
112
+    public function addElementArray($elementArray)
113
+    {
114
+        if (!is_array($elementArray))
115
+            return;
116
+
117
+        foreach ($elementArray as $elementName => $content) {
118
+            $this->addElement($elementName, $content);
119
+        }
120
+
121
+        return $this;
122
+    }
123
+
124
+    /**
125
+    * Return the collection of elements in this feed item
126
+    *
127
+    * @access   public
128
+    * @return   array
129
+    */
130
+    public function getElements()
131
+    {
132
+        return $this->elements;
133
+    }
134
+
135
+    /**
136
+    * Return the type of this feed item
137
+    *
138
+    * @access   public
139
+    * @return   string  The feed type, as defined in Feed.php
140
+    */
141
+    public function getVersion()
142
+    {
143
+        return $this->version;
144
+    }
145
+
146
+    // Wrapper functions ------------------------------------------------------
147
+
148
+    /**
149
+    * Set the 'description' element of feed item
150
+    *
151
+    * @access   public
152
+    * @param    string  The content of 'description' or 'summary' element
153
+    * @return   void
154
+    */
155
+    public function setDescription($description)
156
+    {
157
+        $tag = ($this->version == Feed::ATOM) ? 'summary' : 'description';
158
+
159
+        return $this->addElement($tag, $description);
160
+    }
161
+
162
+    /**
163
+     * Set the 'content' element of the feed item
164
+     * For ATOM feeds only
165
+     *
166
+     * @access public
167
+     * @param string Content for the item (i.e., the body of a blog post).
168
+     * @return void
169
+     */
170
+    public function setContent($content)
171
+    {
172
+        if ($this->version != Feed::ATOM)
173
+            die('The content element is supported in ATOM feeds only.');
174
+
175
+        return $this->addElement('content', $content, array('type' => 'html'));
176
+    }
177
+
178
+    /**
179
+    * Set the 'title' element of feed item
180
+    *
181
+    * @access   public
182
+    * @param    string  The content of 'title' element
183
+    * @return   void
184
+    */
185
+    public function setTitle($title)
186
+    {
187
+        return $this->addElement('title', $title);
188
+    }
189
+
190
+    /**
191
+    * Set the 'date' element of the feed item.
192
+    *
193
+    * The value of the date parameter can be either an instance of the
194
+    * DateTime class, an integer containing a UNIX timestamp or a string
195
+    * which is parseable by PHP's 'strtotime' function.
196
+    *
197
+    * @access   public
198
+    * @param    DateTime|int|string  Date which should be used.
199
+    * @return   void
200
+    */
201
+    public function setDate($date)
202
+    {
203
+        if (!is_numeric($date)) {
204
+            if ($date instanceof DateTime)
205
+                $date = $date->getTimestamp();
206
+            else {
207
+                $date = strtotime($date);
208
+
209
+                if ($date === FALSE)
210
+                    die('The given date string was not parseable.');
211
+            }
212
+        } elseif ($date < 0)
213
+            die('The given date is not an UNIX timestamp.');
214
+
215
+        if ($this->version == Feed::ATOM) {
216
+            $tag    = 'updated';
217
+            $value  = date(\DATE_ATOM, $date);
218
+        } elseif ($this->version == Feed::RSS2) {
219
+            $tag    = 'pubDate';
220
+            $value  = date(\DATE_RSS, $date);
221
+        } else {
222
+            $tag    = 'dc:date';
223
+            $value  = date("Y-m-d", $date);
224
+        }
225
+
226
+        return $this->addElement($tag, $value);
227
+    }
228
+
229
+    /**
230
+    * Set the 'link' element of feed item
231
+    *
232
+    * @access   public
233
+    * @param    string  The content of 'link' element
234
+    * @return   void
235
+    */
236
+    public function setLink($link)
237
+    {
238
+        if ($this->version == Feed::RSS2 || $this->version == Feed::RSS1) {
239
+            $this->addElement('link', $link);
240
+        } else {
241
+            $this->addElement('link','',array('href'=>$link));
242
+            $this->addElement('id', Feed::uuid($link,'urn:uuid:'));
243
+        }
244
+
245
+        return $this;
246
+    }
247
+
248
+    /**
249
+    * Attach a external media to the feed item.
250
+    * Not supported in RSS 1.0 feeds.
251
+    *
252
+    * See RFC 4288 for syntactical correct MIME types.
253
+    *
254
+    * Note that you should avoid the use of more than one enclosure in one item,
255
+    * since some RSS aggregators don't support it.
256
+    *
257
+    * @access   public
258
+    * @param    string  The URL of the media.
259
+    * @param    integer The length of the media.
260
+    * @param    string  The MIME type attribute of the media.
261
+    * @param    boolean Specifies, if multiple enclosures are allowed
262
+    * @return   void
263
+    * @link     https://tools.ietf.org/html/rfc4288
264
+    */
265
+    public function addEnclosure($url, $length, $type, $multiple = TRUE)
266
+    {
267
+        if ($this->version == Feed::RSS1)
268
+            die('Media attachment is not supported in RSS1 feeds.');
269
+
270
+        // the length parameter should be set to 0 if it can't be determined
271
+        // see http://www.rssboard.org/rss-profile#element-channel-item-enclosure
272
+        if (!is_numeric($length) || $length < 0)
273
+            die('The length parameter must be an integer and greater or equals to zero.');
274
+
275
+        // Regex used from RFC 4287, page 41
276
+        if (!is_string($type) || preg_match('/.+\/.+/', $type) != 1)
277
+            die('type parameter must be a string and a MIME type.');
278
+
279
+        $attributes = array('length' => $length, 'type' => $type);
280
+
281
+        if ($this->version == Feed::RSS2) {
282
+            $attributes['url'] = $url;
283
+            $this->addElement('enclosure', '', $attributes, FALSE, $multiple);
284
+        } else {
285
+            $attributes['href'] = $url;
286
+            $attributes['rel'] = 'enclosure';
287
+            $this->addElement('atom:link', '', $attributes, FALSE, $multiple);
288
+        }
289
+
290
+        return $this;
291
+    }
292
+
293
+    /**
294
+    * Alias of addEnclosure, for backward compatibility. Using only this
295
+    * method ensure that the 'enclosure' element will be present only once.
296
+    *
297
+    * @access   public
298
+    * @param    string  The URL of the media.
299
+    * @param    integer The length of the media.
300
+    * @param    string  The MIME type attribute of the media.
301
+    * @return   void
302
+    * @link     https://tools.ietf.org/html/rfc4288
303
+    *
304
+    **/
305
+    public function setEnclosure($url, $length, $type)
306
+    {
307
+        return $this->addEnclosure($url, $length, $type, false);
308
+    }
309
+
310
+    /**
311
+    * Set the 'author' element of feed item.
312
+    * Not supported in RSS 1.0 feeds.
313
+    *
314
+    * @access   public
315
+    * @param    string  The author of this item
316
+    * @param    string  Optional email address of the author
317
+    * @param    string  Optional URI related to the author
318
+    * @return   void
319
+    */
320
+    public function setAuthor($author, $email = null, $uri = null)
321
+    {
322
+        switch ($this->version) {
323
+            case Feed::RSS1: die('The author element is not supported in RSS1 feeds.');
324
+                break;
325
+            case Feed::RSS2:
326
+                if ($email != null)
327
+                    $author = $email . ' (' . $author . ')';
328
+
329
+                $this->addElement('author', $author);
330
+                break;
331
+            case Feed::ATOM:
332
+                $elements = array('name' => $author);
333
+
334
+                // Regex from RFC 4287 page 41
335
+                if ($email != null && preg_match('/.+@.+/', $email) == 1)
336
+                    $elements['email'] = $email;
337
+
338
+                if ($uri != null)
339
+                    $elements['uri'] = $uri;
340
+
341
+                $this->addElement('author', $elements);
342
+                break;
343
+        }
344
+
345
+        return $this;
346
+    }
347
+
348
+    /**
349
+    * Set the unique identifier of the feed item
350
+    *
351
+    * @access   public
352
+    * @param    string  The unique identifier of this item
353
+    * @param    boolean The value of the 'isPermaLink' attribute in RSS 2 feeds.
354
+    * @return   void
355
+    */
356
+    public function setId($id, $permaLink = false)
357
+    {
358
+        if ($this->version == Feed::RSS2) {
359
+            if (!is_bool($permaLink))
360
+                die('The permaLink parameter must be boolean.');
361
+
362
+            $permaLink = $permaLink ? 'true' : 'false';
363
+
364
+            $this->addElement('guid', $id, array('isPermaLink' => $permaLink));
365
+        } elseif ($this->version == Feed::ATOM) {
366
+            $this->addElement('id', Feed::uuid($id,'urn:uuid:'), NULL, TRUE);
367
+        } else
368
+            die('A unique ID is not supported in RSS1 feeds.');
369
+
370
+        return $this;
371
+    }
372
+
373
+ } // end of class Item

+ 9
- 9
RSS1.php View File

@@ -1,7 +1,7 @@
1 1
 <?php
2 2
 namespace FeedWriter;
3 3
 
4
-/* 
4
+/*
5 5
  * Copyright (C) 2012 Michael Bemmerl <mail@mx-server.de>
6 6
  *
7 7
  * This file is part of the "Universal Feed Writer" project.
@@ -15,7 +15,7 @@ namespace FeedWriter;
15 15
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 16
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 17
  * GNU General Public License for more details.
18
- * 
18
+ *
19 19
  * You should have received a copy of the GNU General Public License
20 20
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21 21
  */
@@ -27,11 +27,11 @@ namespace FeedWriter;
27 27
  */
28 28
 class RSS1 extends Feed
29 29
 {
30
-	/**
31
-	* {@inheritdoc}
32
-	*/
33
-	function __construct()
34
-	{
35
-		parent::__construct(Feed::RSS1);
36
-	}
30
+    /**
31
+    * {@inheritdoc}
32
+    */
33
+    public function __construct()
34
+    {
35
+        parent::__construct(Feed::RSS1);
36
+    }
37 37
 }

+ 7
- 7
RSS2.php View File

@@ -27,11 +27,11 @@ namespace FeedWriter;
27 27
  */
28 28
 class RSS2 extends Feed
29 29
 {
30
-	/**
31
-	* {@inheritdoc}
32
-	*/
33
-	function __construct()
34
-	{
35
-		parent::__construct(Feed::RSS2);
36
-	}
30
+    /**
31
+    * {@inheritdoc}
32
+    */
33
+    public function __construct()
34
+    {
35
+        parent::__construct(Feed::RSS2);
36
+    }
37 37
 }

+ 71
- 71
examples/example_atom.php View File

@@ -1,71 +1,71 @@
1
-<?php
2
-
3
-// You should use an autoloader instead of including the files directly.
4
-// This is done here only to make the examples work out of the box.
5
-include('../Item.php');
6
-include('../Feed.php');
7
-include('../ATOM.php');
8
-
9
-date_default_timezone_set('UTC');
10
-
11
-use \FeedWriter\ATOM;
12
-
13
-/*
14
- * Copyright (C) 2008 Anis uddin Ahmad <anisniit@gmail.com>
15
- *
16
- * This file is part of the "Universal Feed Writer" project.
17
- *
18
- * This program is free software: you can redistribute it and/or modify
19
- * it under the terms of the GNU General Public License as published by
20
- * the Free Software Foundation, either version 3 of the License, or
21
- * (at your option) any later version.
22
- *
23
- * This program is distributed in the hope that it will be useful,
24
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
25
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
26
- * GNU General Public License for more details.
27
- *
28
- * You should have received a copy of the GNU General Public License
29
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
30
- */
31
-
32
-// IMPORTANT : No need to add id for feed or channel. It will be automatically created from link.
33
-
34
-//Creating an instance of ATOM class.
35
-$TestFeed = new ATOM;
36
-
37
-//Setting the channel elements
38
-//Use wrapper functions for common elements
39
-$TestFeed->setTitle('Testing the RSS writer class');
40
-$TestFeed->setLink('http://www.ajaxray.com/rss2/channel/about');
41
-$TestFeed->setDate(new DateTime());
42
-
43
-//For other channel elements, use setChannelElement() function
44
-$TestFeed->setChannelElement('author', array('name'=>'Anis uddin Ahmad'));
45
-
46
-//You can add additional link elements, e.g. to a PubSubHubbub server with custom relations.
47
-$TestFeed->setSelfLink('http://example.com/myfeed');
48
-$TestFeed->setAtomLink('http://pubsubhubbub.appspot.com', 'hub');
49
-
50
-//Adding a feed. Generally this portion will be in a loop and add all feeds.
51
-
52
-//Create an empty Item
53
-$newItem = $TestFeed->createNewItem();
54
-
55
-//Add elements to the feed item
56
-//Use wrapper functions to add common feed elements
57
-$newItem->setTitle('The first feed');
58
-$newItem->setLink('http://www.yahoo.com');
59
-$newItem->setDate(time());
60
-$newItem->setAuthor('Anis uddin Ahmad', 'anis@example.invalid');
61
-$newItem->setEnclosure('http://upload.wikimedia.org/wikipedia/commons/4/49/En-us-hello-1.ogg', 11779, 'audio/ogg');
62
-
63
-//Internally changed to "summary" tag for ATOM feed
64
-$newItem->setDescription('This is a test of adding CDATA encoded description by the php <b>Universal Feed Writer</b> class');
65
-$newItem->setContent('<h1>hi.</h1> <p>This is the content for the entry.</p>');
66
-
67
-//Now add the feed item	
68
-$TestFeed->addItem($newItem);
69
-
70
-//OK. Everything is done. Now generate the feed.
71
-$TestFeed->printFeed();
1
+<?php
2
+
3
+// You should use an autoloader instead of including the files directly.
4
+// This is done here only to make the examples work out of the box.
5
+include '../Item.php';
6
+include '../Feed.php';
7
+include '../ATOM.php';
8
+
9
+date_default_timezone_set('UTC');
10
+
11
+use \FeedWriter\ATOM;
12
+
13
+/*
14
+ * Copyright (C) 2008 Anis uddin Ahmad <anisniit@gmail.com>
15
+ *
16
+ * This file is part of the "Universal Feed Writer" project.
17
+ *
18
+ * This program is free software: you can redistribute it and/or modify
19
+ * it under the terms of the GNU General Public License as published by
20
+ * the Free Software Foundation, either version 3 of the License, or
21
+ * (at your option) any later version.
22
+ *
23
+ * This program is distributed in the hope that it will be useful,
24
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
25
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
26
+ * GNU General Public License for more details.
27
+ *
28
+ * You should have received a copy of the GNU General Public License
29
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
30
+ */
31
+
32
+// IMPORTANT : No need to add id for feed or channel. It will be automatically created from link.
33
+
34
+//Creating an instance of ATOM class.
35
+$TestFeed = new ATOM;
36
+
37
+//Setting the channel elements
38
+//Use wrapper functions for common elements
39
+$TestFeed->setTitle('Testing the RSS writer class');
40
+$TestFeed->setLink('http://www.ajaxray.com/rss2/channel/about');
41
+$TestFeed->setDate(new DateTime());
42
+
43
+//For other channel elements, use setChannelElement() function
44
+$TestFeed->setChannelElement('author', array('name'=>'Anis uddin Ahmad'));
45
+
46
+//You can add additional link elements, e.g. to a PubSubHubbub server with custom relations.
47
+$TestFeed->setSelfLink('http://example.com/myfeed');
48
+$TestFeed->setAtomLink('http://pubsubhubbub.appspot.com', 'hub');
49
+
50
+//Adding a feed. Generally this portion will be in a loop and add all feeds.
51
+
52
+//Create an empty Item
53
+$newItem = $TestFeed->createNewItem();
54
+
55
+//Add elements to the feed item
56
+//Use wrapper functions to add common feed elements
57
+$newItem->setTitle('The first feed');
58
+$newItem->setLink('http://www.yahoo.com');
59
+$newItem->setDate(time());
60
+$newItem->setAuthor('Anis uddin Ahmad', 'anis@example.invalid');
61
+$newItem->setEnclosure('http://upload.wikimedia.org/wikipedia/commons/4/49/En-us-hello-1.ogg', 11779, 'audio/ogg');
62
+
63
+//Internally changed to "summary" tag for ATOM feed
64
+$newItem->setDescription('This is a test of adding CDATA encoded description by the php <b>Universal Feed Writer</b> class');
65
+$newItem->setContent('<h1>hi.</h1> <p>This is the content for the entry.</p>');
66
+
67
+//Now add the feed item
68
+$TestFeed->addItem($newItem);
69
+
70
+//OK. Everything is done. Now generate the feed.
71
+$TestFeed->printFeed();

+ 64
- 64
examples/example_minimum.php View File

@@ -1,64 +1,64 @@
1
-<?php
2
-
3
-// You should use an autoloader instead of including the files directly.
4
-// This is done here only to make the examples work out of the box.
5
-include('../Item.php');
6
-include('../Feed.php');
7
-include('../RSS2.php');
8
-
9
-date_default_timezone_set('UTC');
10
-
11
-use \FeedWriter\RSS2;
12
-
13
-/* 
14
- * Copyright (C) 2008 Anis uddin Ahmad <anisniit@gmail.com>
15
- *
16
- * This file is part of the "Universal Feed Writer" project.
17
- *
18
- * This program is free software: you can redistribute it and/or modify
19
- * it under the terms of the GNU General Public License as published by
20
- * the Free Software Foundation, either version 3 of the License, or
21
- * (at your option) any later version.
22
- *
23
- * This program is distributed in the hope that it will be useful,
24
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
25
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
26
- * GNU General Public License for more details.
27
- * 
28
- * You should have received a copy of the GNU General Public License
29
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
30
- */
31
-
32
-//Creating an instance of RSS2 class.
33
-$TestFeed = new RSS2;
34
-
35
-//Setting the channel elements
36
-//Use wrapper functions for common channel elements
37
-$TestFeed->setTitle('Testing & Checking the RSS writer class');
38
-$TestFeed->setLink('http://www.ajaxray.com/projects/rss');
39
-$TestFeed->setDescription('This is a test of creating a RSS 2.0 feed Universal Feed Writer');
40
-
41
-//Image title and link must match with the 'title' and 'link' channel elements for valid RSS 2.0
42
-$TestFeed->setImage('Testing & Checking the RSS writer class','http://www.ajaxray.com/projects/rss','http://www.rightbrainsolution.com/_resources/img/logo.png');
43
-
44
-//Let's add some feed items: Create two empty Item instances
45
-$itemOne = $TestFeed->createNewItem();
46
-$itemTwo = $TestFeed->createNewItem();
47
-
48
-//Add item details
49
-$itemOne->setTitle('The title of the first entry.');
50
-$itemOne->setLink('http://www.google.de');
51
-$itemOne->setDate(time());
52
-$itemOne->setDescription('And here\'s the description of the entry.');
53
-
54
-$itemTwo->setTitle('Lorem ipsum');
55
-$itemTwo->setLink('http://www.example.com');
56
-$itemTwo->setDate(1234567890);
57
-$itemTwo->setDescription('Lorem ipsum dolor sit amet, consectetur, adipisci velit');
58
-
59
-//Now add the feed item
60
-$TestFeed->addItem($itemOne);
61
-$TestFeed->addItem($itemTwo);
62
-
63
-//OK. Everything is done. Now generate the feed.
64
-$TestFeed->printFeed();
1
+<?php
2
+
3
+// You should use an autoloader instead of including the files directly.
4
+// This is done here only to make the examples work out of the box.
5
+include '../Item.php';
6
+include '../Feed.php';
7
+include '../RSS2.php';
8
+
9
+date_default_timezone_set('UTC');
10
+
11
+use \FeedWriter\RSS2;
12
+
13
+/*
14
+ * Copyright (C) 2008 Anis uddin Ahmad <anisniit@gmail.com>
15
+ *
16
+ * This file is part of the "Universal Feed Writer" project.
17
+ *
18
+ * This program is free software: you can redistribute it and/or modify
19
+ * it under the terms of the GNU General Public License as published by
20
+ * the Free Software Foundation, either version 3 of the License, or
21
+ * (at your option) any later version.
22
+ *
23
+ * This program is distributed in the hope that it will be useful,
24
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
25
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
26
+ * GNU General Public License for more details.
27
+ *
28
+ * You should have received a copy of the GNU General Public License
29
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
30
+ */
31
+
32
+//Creating an instance of RSS2 class.
33
+$TestFeed = new RSS2;
34
+
35
+//Setting the channel elements
36
+//Use wrapper functions for common channel elements
37
+$TestFeed->setTitle('Testing & Checking the RSS writer class');
38
+$TestFeed->setLink('http://www.ajaxray.com/projects/rss');
39
+$TestFeed->setDescription('This is a test of creating a RSS 2.0 feed Universal Feed Writer');
40
+
41
+//Image title and link must match with the 'title' and 'link' channel elements for valid RSS 2.0
42
+$TestFeed->setImage('Testing & Checking the RSS writer class','http://www.ajaxray.com/projects/rss','http://www.rightbrainsolution.com/_resources/img/logo.png');
43
+
44
+//Let's add some feed items: Create two empty Item instances
45
+$itemOne = $TestFeed->createNewItem();
46
+$itemTwo = $TestFeed->createNewItem();
47
+
48
+//Add item details
49
+$itemOne->setTitle('The title of the first entry.');
50
+$itemOne->setLink('http://www.google.de');
51
+$itemOne->setDate(time());
52
+$itemOne->setDescription('And here\'s the description of the entry.');
53
+
54
+$itemTwo->setTitle('Lorem ipsum');
55
+$itemTwo->setLink('http://www.example.com');
56
+$itemTwo->setDate(1234567890);
57
+$itemTwo->setDescription('Lorem ipsum dolor sit amet, consectetur, adipisci velit');
58
+
59
+//Now add the feed item
60
+$TestFeed->addItem($itemOne);
61
+$TestFeed->addItem($itemTwo);
62
+
63
+//OK. Everything is done. Now generate the feed.
64
+$TestFeed->printFeed();

+ 70
- 70
examples/example_rss1.php View File

@@ -1,70 +1,70 @@
1
-<?php
2
-
3
-// You should use an autoloader instead of including the files directly.
4
-// This is done here only to make the examples work out of the box.
5
-include('../Item.php');
6
-include('../Feed.php');
7
-include('../RSS1.php');
8
-
9
-date_default_timezone_set('UTC');
10
-
11
-use \FeedWriter\RSS1;
12
-
13
-/* 
14
- * Copyright (C) 2008 Anis uddin Ahmad <anisniit@gmail.com>
15
- *
16
- * This file is part of the "Universal Feed Writer" project.
17
- *
18
- * This program is free software: you can redistribute it and/or modify
19
- * it under the terms of the GNU General Public License as published by
20
- * the Free Software Foundation, either version 3 of the License, or
21
- * (at your option) any later version.
22
- *
23
- * This program is distributed in the hope that it will be useful,
24
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
25
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
26
- * GNU General Public License for more details.
27
- * 
28
- * You should have received a copy of the GNU General Public License
29
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
30
- */
31
-
32
-//Creating an instance of RSS1 class.
33
-$TestFeed = new RSS1;
34
-
35
-//Setting the channel elements
36
-//Use wrapper functions for common elements
37
-//For other optional channel elements, use setChannelElement() function
38
-$TestFeed->setTitle('Testing the RSS writer class');
39
-$TestFeed->setLink('http://www.ajaxray.com/rss2/channel/about');
40
-$TestFeed->setDescription('This is test of creating a RSS 1.0 feed by Universal Feed Writer');
41
-
42
-//It's important for RSS 1.0 
43
-$TestFeed->setChannelAbout('http://www.ajaxray.com/rss2/channel/about');
44
-
45
-//Adding a feed. Generally this portion will be in a loop and add all feeds.
46
-
47
-//Create an empty FeedItem
48
-$newItem = $TestFeed->createNewItem();
49
-
50
-//Add elements to the feed item
51
-//Use wrapper functions to add common feed elements
52
-$newItem->setTitle('The first feed');
53
-$newItem->setLink('http://www.yahoo.com');
54
-//The parameter is a timestamp for setDate() function
55
-$newItem->setDate(time());
56
-$newItem->setDescription('This is test of adding CDATA encoded description by the php <b>Universal Feed Writer</b> class');
57
-//Use core addElement() function for other supported optional elements
58
-$newItem->addElement('dc:subject', 'Nothing but test');
59
-
60
-//Now add the feed item
61
-$TestFeed->addItem($newItem);
62
-
63
-//Adding multiple elements from array
64
-//Elements which have an attribute cannot be added by this way
65
-$newItem = $TestFeed->createNewItem();
66
-$newItem->addElementArray(array('title'=>'The 2nd feed', 'link'=>'http://www.google.com', 'description'=>'This is a test of the FeedWriter class'));
67
-$TestFeed->addItem($newItem);
68
-
69
-//OK. Everything is done. Now generate the feed.
70
-$TestFeed->printFeed();
1
+<?php
2
+
3
+// You should use an autoloader instead of including the files directly.
4
+// This is done here only to make the examples work out of the box.
5
+include '../Item.php';
6
+include '../Feed.php';
7
+include '../RSS1.php';
8
+
9
+date_default_timezone_set('UTC');
10
+
11
+use \FeedWriter\RSS1;
12
+
13
+/*
14
+ * Copyright (C) 2008 Anis uddin Ahmad <anisniit@gmail.com>
15
+ *
16
+ * This file is part of the "Universal Feed Writer" project.
17
+ *
18
+ * This program is free software: you can redistribute it and/or modify
19
+ * it under the terms of the GNU General Public License as published by
20
+ * the Free Software Foundation, either version 3 of the License, or
21
+ * (at your option) any later version.
22
+ *
23
+ * This program is distributed in the hope that it will be useful,
24
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
25
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
26
+ * GNU General Public License for more details.
27
+ *
28
+ * You should have received a copy of the GNU General Public License
29
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
30
+ */
31
+
32
+//Creating an instance of RSS1 class.
33
+$TestFeed = new RSS1;
34
+
35
+//Setting the channel elements
36
+//Use wrapper functions for common elements
37
+//For other optional channel elements, use setChannelElement() function
38
+$TestFeed->setTitle('Testing the RSS writer class');
39
+$TestFeed->setLink('http://www.ajaxray.com/rss2/channel/about');
40
+$TestFeed->setDescription('This is test of creating a RSS 1.0 feed by Universal Feed Writer');
41
+
42
+//It's important for RSS 1.0
43
+$TestFeed->setChannelAbout('http://www.ajaxray.com/rss2/channel/about');
44
+
45
+//Adding a feed. Generally this portion will be in a loop and add all feeds.
46
+
47
+//Create an empty FeedItem
48
+$newItem = $TestFeed->createNewItem();
49
+
50
+//Add elements to the feed item
51
+//Use wrapper functions to add common feed elements
52
+$newItem->setTitle('The first feed');
53
+$newItem->setLink('http://www.yahoo.com');
54
+//The parameter is a timestamp for setDate() function
55
+$newItem->setDate(time());
56
+$newItem->setDescription('This is test of adding CDATA encoded description by the php <b>Universal Feed Writer</b> class');
57
+//Use core addElement() function for other supported optional elements
58
+$newItem->addElement('dc:subject', 'Nothing but test');
59
+
60
+//Now add the feed item
61
+$TestFeed->addItem($newItem);
62
+
63
+//Adding multiple elements from array
64
+//Elements which have an attribute cannot be added by this way
65
+$newItem = $TestFeed->createNewItem();
66
+$newItem->addElementArray(array('title'=>'The 2nd feed', 'link'=>'http://www.google.com', 'description'=>'This is a test of the FeedWriter class'));
67
+$TestFeed->addItem($newItem);
68
+
69
+//OK. Everything is done. Now generate the feed.
70
+$TestFeed->printFeed();

+ 119
- 119
examples/example_rss2.php View File

@@ -1,119 +1,119 @@
1
-<?php
2
-
3
-// You should use an autoloader instead of including the files directly.
4
-// This is done here only to make the examples work out of the box.
5
-include('../Item.php');
6
-include('../Feed.php');
7
-include('../RSS2.php');
8
-
9
-date_default_timezone_set('UTC');
10
-
11
-use \FeedWriter\RSS2;
12
-
13
-/**
14
- * Copyright (C) 2008 Anis uddin Ahmad <anisniit@gmail.com>
15
- * Copyright (C) 2013 Michael Bemmerl <mail@mx-server.de>
16
- *
17
- * This file is part of the "Universal Feed Writer" project.
18
- *
19
- * This program is free software: you can redistribute it and/or modify
20
- * it under the terms of the GNU General Public License as published by
21
- * the Free Software Foundation, either version 3 of the License, or
22
- * (at your option) any later version.
23
- *
24
- * This program is distributed in the hope that it will be useful,
25
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
26
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
27
- * GNU General Public License for more details.
28
- *
29
- * You should have received a copy of the GNU General Public License
30
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
31
- */
32
-
33
-// Creating an instance of RSS2 class.
34
-$TestFeed = new RSS2;
35
-
36
-// Setting some basic channel elements. These three elements are mandatory.
37
-$TestFeed->setTitle('Testing & Checking the Feed Writer project');
38
-$TestFeed->setLink('https://github.com/mibe/FeedWriter');
39
-$TestFeed->setDescription('This is just an example how to use the Feed Writer project in your code.');
40
-
41
-// Image title and link must match with the 'title' and 'link' channel elements for RSS 2.0,
42
-// which were set above.
43
-$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');
44
-
45
-// Use core setChannelElement() function for other optional channel elements.
46
-// See http://www.rssboard.org/rss-specification#optionalChannelElements
47
-// for other optional channel elements. Here the language code for American English and
48
-$TestFeed->setChannelElement('language', 'en-US');
49
-
50
-// The date when this feed was lastly updated. The publication date is also set.
51
-$TestFeed->setDate(date(DATE_RSS, time()));
52
-$TestFeed->setChannelElement('pubDate', date(\DATE_RSS, strtotime('2013-04-06')));
53
-
54
-// You can add additional link elements, e.g. to a PubSubHubbub server with custom relations.
55
-// It's recommended to provide a backlink to the feed URL.
56
-$TestFeed->setSelfLink('http://example.com/myfeed');
57
-$TestFeed->setAtomLink('http://pubsubhubbub.appspot.com', 'hub');
58
-
59
-// You can add more XML namespaces for more custom channel elements which are not defined
60
-// in the RSS 2 specification. Here the 'creativeCommons' element is used. There are much more
61
-// available. Have a look at this list: http://feedvalidator.org/docs/howto/declare_namespaces.html
62
-$TestFeed->addNamespace('creativeCommons', 'http://backend.userland.com/creativeCommonsRssModule');
63
-$TestFeed->setChannelElement('creativeCommons:license', 'http://www.creativecommons.org/licenses/by/1.0');
64
-
65
-// If you want you can also add a line to publicly announce that you used
66
-// this fine piece of software to generate the feed. ;-)
67
-$TestFeed->addGenerator();
68
-
69
-// Here we are done setting up the feed. What's next is adding some feed items.
70
-
71
-// Create a new feed item.
72
-$newItem = $TestFeed->createNewItem();
73
-
74
-// Add basic elements to the feed item
75
-// These are again mandatory for a valid feed.
76
-$newItem->setTitle('Hello World!');
77
-$newItem->setLink('http://www.example.com');
78
-$newItem->setDescription('This is a test of adding a description by the <b>Feed Writer</b> classes. It\'s automatically CDATA encoded.');
79
-
80
-// The following method calls add some optional elements to the feed item.
81
-
82
-// Let's set the publication date of this item. You could also use a UNIX timestamp or
83
-// an instance of PHP's DateTime class.
84
-$newItem->setDate('2013-04-07 00:50:30');
85
-
86
-// You can also attach a media object to a feed item. You just need the URL, the byte length
87
-// and the MIME type of the media. Here's a quirk: The RSS2 spec says "The url must be an http url.".
88
-// Other schemes like ftp, https, etc. produce an error in feed validators.
89
-$newItem->setEnclosure('http://upload.wikimedia.org/wikipedia/commons/4/49/En-us-hello-1.ogg', 11779, 'audio/ogg');
90
-
91
-// If you want you can set the name (and email address) of the author of this feed item.
92
-$newItem->setAuthor('Anis uddin Ahmad', 'admin@ajaxray.com');
93
-
94
-// You can set a globally unique identifier. This can be a URL or any other string.
95
-// If you set permaLink to true, the identifier must be an URL. The default of the
96
-// permaLink parameter is false.
97
-$newItem->setId('http://example.com/URL/to/article', true);
98
-
99
-// Use the addElement() method for other optional elements.
100
-// This here will add the 'source' element. The second parameter is the value of the element
101
-// and the third is an array containing the element attributes.
102
-$newItem->addElement('source', 'Mike\'s page', array('url' => 'http://www.example.com'));
103
-
104
-// Now add the feed item to the main feed.
105
-$TestFeed->addItem($newItem);
106
-
107
-// Another method to add feeds items is by using an array which contains key-value pairs
108
-// of every item element. Elements which have attributes cannot be added by this way.
109
-$newItem = $TestFeed->createNewItem();
110
-$newItem->addElementArray(array('title'=> 'The 2nd item', 'link' => 'http://www.google.com', 'description' => 'Just another test.'));
111
-$TestFeed->addItem($newItem);
112
-
113
-// OK. Everything is done. Now generate the feed.
114
-// If you want to send the feed directly to the browser, use the printFeed() method.
115
-$myFeed = $TestFeed->generateFeed();
116
-
117
-// Do anything you want with the feed in $myFeed. Why not send it to the browser? ;-)
118
-// You could also save it to a file if you don't want to invoke your script every time.
119
-echo $myFeed;
1
+<?php
2
+
3
+// You should use an autoloader instead of including the files directly.
4
+// This is done here only to make the examples work out of the box.
5
+include '../Item.php';
6
+include '../Feed.php';
7
+include '../RSS2.php';
8
+
9
+date_default_timezone_set('UTC');
10
+
11
+use \FeedWriter\RSS2;
12
+
13
+/**
14
+ * Copyright (C) 2008 Anis uddin Ahmad <anisniit@gmail.com>
15
+ * Copyright (C) 2013 Michael Bemmerl <mail@mx-server.de>
16
+ *
17
+ * This file is part of the "Universal Feed Writer" project.
18
+ *
19
+ * This program is free software: you can redistribute it and/or modify
20
+ * it under the terms of the GNU General Public License as published by
21
+ * the Free Software Foundation, either version 3 of the License, or
22
+ * (at your option) any later version.
23
+ *
24
+ * This program is distributed in the hope that it will be useful,
25
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
26
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
27
+ * GNU General Public License for more details.
28
+ *
29
+ * You should have received a copy of the GNU General Public License
30
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
31
+ */
32
+
33
+// Creating an instance of RSS2 class.
34
+$TestFeed = new RSS2;
35
+
36
+// Setting some basic channel elements. These three elements are mandatory.
37
+$TestFeed->setTitle('Testing & Checking the Feed Writer project');
38
+$TestFeed->setLink('https://github.com/mibe/FeedWriter');
39
+$TestFeed->setDescription('This is just an example how to use the Feed Writer project in your code.');
40
+
41
+// Image title and link must match with the 'title' and 'link' channel elements for RSS 2.0,
42
+// which were set above.
43
+$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');
44
+
45
+// Use core setChannelElement() function for other optional channel elements.
46
+// See http://www.rssboard.org/rss-specification#optionalChannelElements
47
+// for other optional channel elements. Here the language code for American English and
48
+$TestFeed->setChannelElement('language', 'en-US');
49
+
50
+// The date when this feed was lastly updated. The publication date is also set.
51
+$TestFeed->setDate(date(DATE_RSS, time()));
52
+$TestFeed->setChannelElement('pubDate', date(\DATE_RSS, strtotime('2013-04-06')));
53
+
54
+// You can add additional link elements, e.g. to a PubSubHubbub server with custom relations.
55
+// It's recommended to provide a backlink to the feed URL.
56
+$TestFeed->setSelfLink('http://example.com/myfeed');
57
+$TestFeed->setAtomLink('http://pubsubhubbub.appspot.com', 'hub');
58
+
59
+// You can add more XML namespaces for more custom channel elements which are not defined
60
+// in the RSS 2 specification. Here the 'creativeCommons' element is used. There are much more
61
+// available. Have a look at this list: http://feedvalidator.org/docs/howto/declare_namespaces.html
62
+$TestFeed->addNamespace('creativeCommons', 'http://backend.userland.com/creativeCommonsRssModule');
63
+$TestFeed->setChannelElement('creativeCommons:license', 'http://www.creativecommons.org/licenses/by/1.0');
64
+
65
+// If you want you can also add a line to publicly announce that you used
66
+// this fine piece of software to generate the feed. ;-)
67
+$TestFeed->addGenerator();
68
+
69
+// Here we are done setting up the feed. What's next is adding some feed items.
70
+
71
+// Create a new feed item.
72
+$newItem = $TestFeed->createNewItem();
73
+
74
+// Add basic elements to the feed item
75
+// These are again mandatory for a valid feed.
76
+$newItem->setTitle('Hello World!');
77
+$newItem->setLink('http://www.example.com');
78
+$newItem->setDescription('This is a test of adding a description by the <b>Feed Writer</b> classes. It\'s automatically CDATA encoded.');
79
+
80
+// The following method calls add some optional elements to the feed item.
81
+
82
+// Let's set the publication date of this item. You could also use a UNIX timestamp or
83
+// an instance of PHP's DateTime class.
84
+$newItem->setDate('2013-04-07 00:50:30');
85
+
86
+// You can also attach a media object to a feed item. You just need the URL, the byte length
87
+// and the MIME type of the media. Here's a quirk: The RSS2 spec says "The url must be an http url.".
88
+// Other schemes like ftp, https, etc. produce an error in feed validators.
89
+$newItem->setEnclosure('http://upload.wikimedia.org/wikipedia/commons/4/49/En-us-hello-1.ogg', 11779, 'audio/ogg');
90
+
91
+// If you want you can set the name (and email address) of the author of this feed item.
92
+$newItem->setAuthor('Anis uddin Ahmad', 'admin@ajaxray.com');
93
+
94
+// You can set a globally unique identifier. This can be a URL or any other string.
95
+// If you set permaLink to true, the identifier must be an URL. The default of the
96
+// permaLink parameter is false.
97
+$newItem->setId('http://example.com/URL/to/article', true);
98
+
99
+// Use the addElement() method for other optional elements.
100
+// This here will add the 'source' element. The second parameter is the value of the element
101
+// and the third is an array containing the element attributes.
102
+$newItem->addElement('source', 'Mike\'s page', array('url' => 'http://www.example.com'));
103
+
104
+// Now add the feed item to the main feed.
105
+$TestFeed->addItem($newItem);
106
+
107
+// Another method to add feeds items is by using an array which contains key-value pairs
108
+// of every item element. Elements which have attributes cannot be added by this way.
109
+$newItem = $TestFeed->createNewItem();
110
+$newItem->addElementArray(array('title'=> 'The 2nd item', 'link' => 'http://www.google.com', 'description' => 'Just another test.'));
111
+$TestFeed->addItem($newItem);
112
+
113
+// OK. Everything is done. Now generate the feed.
114
+// If you want to send the feed directly to the browser, use the printFeed() method.
115
+$myFeed = $TestFeed->generateFeed();
116
+
117
+// Do anything you want with the feed in $myFeed. Why not send it to the browser? ;-)
118
+// You could also save it to a file if you don't want to invoke your script every time.
119
+echo $myFeed;

Loading…
Cancel
Save