Skip to content

Commit 6a75dbf

Browse files
authored
Merge pull request #2 from splitbrain-forks/master
various fixes and improvements
2 parents 55778f7 + 99034fa commit 6a75dbf

24 files changed

+260
-168
lines changed

.travis.yml

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
11
language: php
2+
23
php:
4+
- "5.3"
5+
- "5.4"
6+
- "5.5"
7+
- "5.6"
8+
- "7.0"
9+
- "7.1"
10+
- "nightly"
11+
- "hhvm"
312

4-
- 5.3
5-
- 5.4
6-
- 5.5
7-
- 5.6
8-
- 7.0
13+
matrix:
14+
allow_failures:
15+
- php: "hhvm"
16+
- php: "nightly"
917

1018
before_script:
11-
composer install
19+
composer install
20+
21+
script: ./vendor/bin/phpunit

composer.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,8 @@
1616
},
1717
"autoload": {
1818
"classmap": ["lib"]
19+
},
20+
"require-dev": {
21+
"phpunit/phpunit": "*"
1922
}
2023
}

lib/Creator/AtomCreator03.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,16 @@
1818
*/
1919
class AtomCreator03 extends FeedCreator {
2020

21-
function __construct() {
21+
/**
22+
* AtomCreator03 constructor.
23+
*/
24+
public function __construct() {
2225
$this->contentType = "application/atom+xml";
2326
$this->encoding = "utf-8";
2427
}
2528

26-
function createFeed() {
29+
/** @inheritdoc */
30+
public function createFeed() {
2731
$feed = "<?xml version=\"1.0\" encoding=\"".$this->encoding."\"?>\n";
2832
$feed.= $this->_createGeneratorComment();
2933
$feed.= $this->_createStylesheetReferences();
@@ -82,4 +86,4 @@ function createFeed() {
8286
$feed.= "</feed>\n";
8387
return $feed;
8488
}
85-
}
89+
}

lib/Creator/AtomCreator10.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,16 @@
1818
*/
1919
class AtomCreator10 extends FeedCreator {
2020

21-
function __construct() {
21+
/**
22+
* AtomCreator10 constructor.
23+
*/
24+
public function __construct() {
2225
$this->contentType = "application/atom+xml";
2326
$this->encoding = "utf-8";
2427
}
2528

26-
function createFeed() {
29+
/** @inheritdoc */
30+
public function createFeed() {
2731
$feed = "<?xml version=\"1.0\" encoding=\"".$this->encoding."\"?>\n";
2832
$feed.= $this->_createGeneratorComment();
2933
$feed.= $this->_createStylesheetReferences();
@@ -150,4 +154,3 @@ function createFeed() {
150154
return $feed;
151155
}
152156
}
153-
?>

lib/Creator/FeedCreator.php

Lines changed: 38 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -12,44 +12,41 @@ abstract class FeedCreator extends HtmlDescribable {
1212
/**
1313
* Mandatory attributes of a feed.
1414
*/
15-
var $title, $description, $link;
16-
var $format = 'BASE';
15+
public $title, $description, $link;
16+
public $format = 'BASE';
1717

1818
/**
1919
* Optional attributes of a feed.
2020
*/
21-
var $syndicationURL, $image, $language, $copyright, $pubDate, $lastBuildDate, $editor, $editorEmail, $webmaster, $category, $docs, $ttl, $rating, $skipHours, $skipDays;
21+
public $syndicationURL, $image, $language, $copyright, $pubDate, $lastBuildDate, $editor, $editorEmail, $webmaster, $category, $docs, $ttl, $rating, $skipHours, $skipDays;
2222

2323
/**
2424
* The url of the external xsl stylesheet used to format the naked rss feed.
2525
* Ignored in the output when empty.
2626
*/
27-
var $xslStyleSheet = "";
27+
public $xslStyleSheet = "";
2828

2929

30-
/**
31-
* @access private
32-
*/
33-
var $items = Array();
30+
/** @var FeedItem[] */
31+
public $items = Array();
3432

3533
/**
3634
* Generator string
37-
*
3835
*/
39-
var $generator = "info@mypapit.net";
36+
public $generator = "info@mypapit.net";
4037

4138
/**
4239
* This feed's MIME content type.
4340
* @since 1.4
4441
* @access private
4542
*/
46-
var $contentType = "application/xml";
43+
protected $contentType = "application/xml";
4744

4845
/**
4946
* This feed's character encoding.
5047
* @since 1.6.1
5148
*/
52-
var $encoding = "UTF-8"; //"ISO-8859-1";
49+
protected $encoding = "UTF-8"; //"ISO-8859-1";
5350

5451
/**
5552
* Any additional elements to include as an associated array. All $key => $value pairs
@@ -59,19 +56,24 @@ abstract class FeedCreator extends HtmlDescribable {
5956
* if $value contains markup. This may be abused to embed tags not implemented by
6057
* the FeedCreator class used.
6158
*/
62-
var $additionalElements = Array();
59+
public $additionalElements = Array();
6360

6461
/**
6562
* Adds a FeedItem to the feed.
6663
*
67-
* @param object FeedItem $item The FeedItem to add to the feed.
64+
* @param FeedItem $item The FeedItem to add to the feed.
6865
*/
6966
public function addItem($item)
7067
{
7168
$this->items[] = $item;
7269
}
7370

74-
function version()
71+
/**
72+
* Get the version string for the generator
73+
*
74+
* @return string
75+
*/
76+
public function version()
7577
{
7678
return FEEDCREATOR_VERSION." (".$this->generator.")";
7779
}
@@ -83,8 +85,8 @@ function version()
8385
* If the string is truncated, " ..." is appended.
8486
* If the string is already shorter than $length, it is returned unchanged.
8587
*
86-
* @param string string A string to be truncated.
87-
* @param int length the maximum length the string should be truncated to
88+
* @param string $string A string to be truncated.
89+
* @param int $length the maximum length the string should be truncated to
8890
* @return string the truncated string
8991
*/
9092
public static function iTrunc($string, $length) {
@@ -119,18 +121,18 @@ public static function iTrunc($string, $length) {
119121
* The format of this comment seems to be recognized by
120122
* Syndic8.com.
121123
*/
122-
function _createGeneratorComment() {
124+
protected function _createGeneratorComment() {
123125
return "<!-- generator=\"".FEEDCREATOR_VERSION."\" -->\n";
124126
}
125127

126128
/**
127129
* Creates a string containing all additional elements specified in
128130
* $additionalElements.
129-
* @param elements array an associative array containing key => value pairs
130-
* @param indentString string a string that will be inserted before every generated line
131+
* @param array $elements an associative array containing key => value pairs
132+
* @param string $indentString a string that will be inserted before every generated line
131133
* @return string the XML tags corresponding to $additionalElements
132134
*/
133-
function _createAdditionalElements($elements, $indentString="") {
135+
protected function _createAdditionalElements($elements, $indentString="") {
134136
$ae = "";
135137
if (is_array($elements)) {
136138
foreach($elements AS $key => $value) {
@@ -140,7 +142,7 @@ function _createAdditionalElements($elements, $indentString="") {
140142
return $ae;
141143
}
142144

143-
function _createStylesheetReferences() {
145+
protected function _createStylesheetReferences() {
144146
$xml = "";
145147
if (!empty($this->cssStyleSheet)) $xml .= "<?xml-stylesheet href=\"".$this->cssStyleSheet."\" type=\"text/css\"?>\n";
146148
if (!empty($this->xslStyleSheet)) $xml .= "<?xml-stylesheet href=\"".$this->xslStyleSheet."\" type=\"text/xsl\"?>\n";
@@ -152,7 +154,7 @@ function _createStylesheetReferences() {
152154
*
153155
* @return string the feed's complete text
154156
*/
155-
abstract function createFeed();
157+
abstract public function createFeed();
156158

157159
/**
158160
* Generate a filename for the feed cache file. The result will be $_SERVER["PHP_SELF"] with the extension changed to .xml.
@@ -170,15 +172,18 @@ abstract function createFeed();
170172
* @since 1.4
171173
* @access private
172174
*/
173-
function _generateFilename() {
175+
protected function _generateFilename() {
174176
$fileInfo = pathinfo($_SERVER["PHP_SELF"]);
175177
return substr($fileInfo["basename"],0,-(strlen($fileInfo["extension"])+1)).".xml";
176178
}
177179

178180
/**
181+
* Send given file to Browser
182+
*
179183
* @since 1.4
184+
* @param string $filename
180185
*/
181-
private function _redirect($filename) {
186+
protected function _redirect($filename) {
182187
// attention, heavily-commented-out-area
183188

184189
// maybe use this in addition to file time checking
@@ -193,12 +198,12 @@ private function _redirect($filename) {
193198
//header("Location: ".$filename);
194199

195200
header("Content-Type: ".$this->contentType."; charset=".$this->encoding."; filename=".basename($filename));
196-
if (preg_match("/\.(kml|gpx)$/",$filename)) {
201+
if (preg_match('/\.(kml|gpx)$/',$filename)) {
197202
header("Content-Disposition: attachment; filename=".basename($filename));
198203
} else {
199204
header("Content-Disposition: inline; filename=".basename($filename));
200205
}
201-
readfile($filename, "r");
206+
readfile($filename);
202207
exit();
203208
}
204209

@@ -209,10 +214,10 @@ private function _redirect($filename) {
209214
* before anything else, especially before you do the time consuming task to build the feed
210215
* (web fetching, for example).
211216
* @since 1.4
212-
* @param filename string optional the filename where a recent version of the feed is saved. If not specified, the filename is $_SERVER["PHP_SELF"] with the extension changed to .xml (see _generateFilename()).
213-
* @param timeout int optional the timeout in seconds before a cached version is refreshed (defaults to 3600 = 1 hour)
217+
* @param string $filename optional the filename where a recent version of the feed is saved. If not specified, the filename is $_SERVER["PHP_SELF"] with the extension changed to .xml (see _generateFilename()).
218+
* @param int $timeout optional the timeout in seconds before a cached version is refreshed (defaults to 3600 = 1 hour)
214219
*/
215-
function useCached($filename="", $timeout=3600) {
220+
public function useCached($filename="", $timeout=3600) {
216221
$this->_timeout = $timeout;
217222
if ($filename=="") {
218223
$filename = $this->_generateFilename();
@@ -227,10 +232,10 @@ function useCached($filename="", $timeout=3600) {
227232
* header may be sent to redirect the user to the newly created file.
228233
* @since 1.4
229234
*
230-
* @param filename string optional the filename where a recent version of the feed is saved. If not specified, the filename is $_SERVER["PHP_SELF"] with the extension changed to .xml (see _generateFilename()).
231-
* @param redirect boolean optional send an HTTP redirect header or not. If true, the user will be automatically redirected to the created file.
235+
* @param string $filename optional the filename where a recent version of the feed is saved. If not specified, the filename is $_SERVER["PHP_SELF"] with the extension changed to .xml (see _generateFilename()).
236+
* @param bool $displayContents optional send an HTTP redirect header or not. If true, the user will be automatically redirected to the created file.
232237
*/
233-
function saveFeed($filename="", $displayContents=true) {
238+
public function saveFeed($filename="", $displayContents=true) {
234239
if ($filename=="") {
235240
$filename = $this->_generateFilename();
236241
}
@@ -246,4 +251,3 @@ function saveFeed($filename="", $displayContents=true) {
246251
}
247252
}
248253
}
249-
?>

lib/Creator/GPXCreator.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,16 @@
88
*/
99
class GPXCreator extends FeedCreator {
1010

11-
function __construct() {
11+
/**
12+
* GPXCreator constructor.
13+
*/
14+
public function __construct() {
1215
$this->contentType = "text/xml";
1316
$this->encoding = "utf-8";
1417
}
1518

16-
function createFeed() {
19+
/** @inheritdoc */
20+
public function createFeed() {
1721
$feed = "<?xml version=\"1.0\" encoding=\"".$this->encoding."\"?>\n";
1822
$feed.= $this->_createStylesheetReferences();
1923
$feed.= "<gpx xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" version=\"1.0\"
@@ -39,4 +43,3 @@ function createFeed() {
3943
return $feed;
4044
}
4145
}
42-
?>

0 commit comments

Comments
 (0)