From 3d5e44690c4055d6a105c93bb35594b1dee4997a Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Sun, 14 May 2017 08:23:55 +0200 Subject: [PATCH 01/19] added phpunit to dev dependencies This way the proper version of PHP unit is available. Run tests with ./vendor/bin/phpunit --- composer.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/composer.json b/composer.json index db6be3f..fdb9362 100644 --- a/composer.json +++ b/composer.json @@ -16,5 +16,8 @@ }, "autoload": { "classmap": ["lib"] + }, + "require-dev": { + "phpunit/phpunit": "^5.7" } } From 50b79d9489a3e8acc458a26069f3d5364fbba47d Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Sun, 14 May 2017 08:35:59 +0200 Subject: [PATCH 02/19] fixed phpdoc variable types --- lib/Creator/FeedCreator.php | 18 +++++++++--------- lib/Element/FeedHtmlField.php | 2 +- lib/Element/HtmlDescribable.php | 4 +++- lib/UniversalFeedCreator.php | 15 ++++++++------- 4 files changed, 21 insertions(+), 18 deletions(-) diff --git a/lib/Creator/FeedCreator.php b/lib/Creator/FeedCreator.php index 53c6d56..1a86ed0 100644 --- a/lib/Creator/FeedCreator.php +++ b/lib/Creator/FeedCreator.php @@ -64,7 +64,7 @@ abstract class FeedCreator extends HtmlDescribable { /** * Adds a FeedItem to the feed. * - * @param object FeedItem $item The FeedItem to add to the feed. + * @param FeedItem $item The FeedItem to add to the feed. */ public function addItem($item) { @@ -83,8 +83,8 @@ function version() * If the string is truncated, " ..." is appended. * If the string is already shorter than $length, it is returned unchanged. * - * @param string string A string to be truncated. - * @param int length the maximum length the string should be truncated to + * @param string $string A string to be truncated. + * @param int $length the maximum length the string should be truncated to * @return string the truncated string */ public static function iTrunc($string, $length) { @@ -126,8 +126,8 @@ function _createGeneratorComment() { /** * Creates a string containing all additional elements specified in * $additionalElements. - * @param elements array an associative array containing key => value pairs - * @param indentString string a string that will be inserted before every generated line + * @param array $elements an associative array containing key => value pairs + * @param string $indentString a string that will be inserted before every generated line * @return string the XML tags corresponding to $additionalElements */ function _createAdditionalElements($elements, $indentString="") { @@ -209,8 +209,8 @@ private function _redirect($filename) { * before anything else, especially before you do the time consuming task to build the feed * (web fetching, for example). * @since 1.4 - * @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()). - * @param timeout int optional the timeout in seconds before a cached version is refreshed (defaults to 3600 = 1 hour) + * @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()). + * @param int $timeout optional the timeout in seconds before a cached version is refreshed (defaults to 3600 = 1 hour) */ function useCached($filename="", $timeout=3600) { $this->_timeout = $timeout; @@ -227,8 +227,8 @@ function useCached($filename="", $timeout=3600) { * header may be sent to redirect the user to the newly created file. * @since 1.4 * - * @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()). - * @param redirect boolean optional send an HTTP redirect header or not. If true, the user will be automatically redirected to the created file. + * @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()). + * @param bool $displayContents optional send an HTTP redirect header or not. If true, the user will be automatically redirected to the created file. */ function saveFeed($filename="", $displayContents=true) { if ($filename=="") { diff --git a/lib/Element/FeedHtmlField.php b/lib/Element/FeedHtmlField.php index 93ad0a1..67f3293 100644 --- a/lib/Element/FeedHtmlField.php +++ b/lib/Element/FeedHtmlField.php @@ -23,7 +23,7 @@ class FeedHtmlField { /** * Creates a new instance of FeedHtmlField. * - * @param $string: if given, sets the rawFieldContent property + * @param string $parFieldContent if given, sets the rawFieldContent property */ public function __construct($parFieldContent) { if ($parFieldContent) { diff --git a/lib/Element/HtmlDescribable.php b/lib/Element/HtmlDescribable.php index d2fc587..7ba8c04 100644 --- a/lib/Element/HtmlDescribable.php +++ b/lib/Element/HtmlDescribable.php @@ -19,7 +19,9 @@ class HtmlDescribable { /** * Returns a formatted description field, depending on descriptionHtmlSyndicated and * $descriptionTruncSize properties - * @return string the formatted description + * + * @param bool $overrideSyndicateHtml + * @return string the formatted description */ function getDescription($overrideSyndicateHtml = false) { $descriptionField = new FeedHtmlField($this->description); diff --git a/lib/UniversalFeedCreator.php b/lib/UniversalFeedCreator.php index 3aa9a11..0416a73 100644 --- a/lib/UniversalFeedCreator.php +++ b/lib/UniversalFeedCreator.php @@ -18,6 +18,7 @@ * @package de.bitfolge.feedcreator */ class UniversalFeedCreator extends FeedCreator { + /** @var FeedCreator */ var $_feed; function _setFormat($format) { @@ -109,7 +110,7 @@ function _setFormat($format) { * Creates a syndication feed based on the items previously added. * * @see FeedCreator::addItem() - * @param string format format the feed should comply to. Valid values are: + * @param string $format format the feed should comply to. Valid values are: * "PIE0.1", "mbox", "RSS0.91", "RSS1.0", "RSS2.0", "OPML", "ATOM0.3", "HTML", "JS" * @return string the contents of the feed. */ @@ -123,10 +124,10 @@ function createFeed($format = "RSS0.91") { * header may be sent to redirect the use to the newly created file. * @since 1.4 * - * @param string format format the feed should comply to. Valid values are: + * @param string $format format the feed should comply to. Valid values are: * "PIE0.1" (deprecated), "mbox", "RSS0.91", "RSS1.0", "RSS2.0", "OPML", "ATOM", "ATOM0.3", "HTML", "JS" - * @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()). - * @param boolean displayContents optional send the content of the file or not. If true, the file will be sent in the body of the response. + * @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()). + * @param boolean $displayContents optional send the content of the file or not. If true, the file will be sent in the body of the response. */ function saveFeed($format="RSS0.91", $filename="", $displayContents=true) { $this->_setFormat($format); @@ -140,10 +141,10 @@ function saveFeed($format="RSS0.91", $filename="", $displayContents=true) { * before anything else, especially before you do the time consuming task to build the feed * (web fetching, for example). * - * @param string format format the feed should comply to. Valid values are: + * @param string $format format the feed should comply to. Valid values are: * "PIE0.1" (deprecated), "mbox", "RSS0.91", "RSS1.0", "RSS2.0", "OPML", "ATOM0.3". - * @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()). - * @param timeout int optional the timeout in seconds before a cached version is refreshed (defaults to 3600 = 1 hour) + * @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()). + * @param int $timeout optional the timeout in seconds before a cached version is refreshed (defaults to 3600 = 1 hour) */ function useCached($format="RSS0.91", $filename="", $timeout=3600) { $this->_setFormat($format); From dc735169e97d6a28451c0575bf7316583206266f Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Sun, 14 May 2017 08:39:22 +0200 Subject: [PATCH 03/19] removed closing php tags The PHP manual says these should be omitted for all included files to avoid premature header sending. --- lib/Creator/AtomCreator03.php | 2 +- lib/Creator/AtomCreator10.php | 1 - lib/Creator/FeedCreator.php | 1 - lib/Creator/GPXCreator.php | 1 - lib/Creator/HTMLCreator.php | 1 - lib/Creator/JSCreator.php | 1 - lib/Creator/KMLCreator.php | 1 - lib/Creator/MBOXCreator.php | 1 - lib/Creator/OPMLCreator.php | 1 - lib/Creator/PHPCreator.php | 1 - lib/Creator/PIECreator01.php | 1 - lib/Creator/RSSCreator091.php | 1 - lib/Creator/RSSCreator10.php | 1 - lib/Creator/RSSCreator20.php | 1 - lib/Element/FeedDate.php | 1 - lib/Element/FeedHtmlField.php | 1 - lib/Element/FeedImage.php | 1 - lib/Element/FeedItem.php | 1 - lib/Element/HtmlDescribable.php | 1 - lib/UniversalFeedCreator.php | 1 - 20 files changed, 1 insertion(+), 20 deletions(-) diff --git a/lib/Creator/AtomCreator03.php b/lib/Creator/AtomCreator03.php index 0a51546..ad3a6d2 100644 --- a/lib/Creator/AtomCreator03.php +++ b/lib/Creator/AtomCreator03.php @@ -82,4 +82,4 @@ function createFeed() { $feed.= "\n"; return $feed; } -} \ No newline at end of file +} diff --git a/lib/Creator/AtomCreator10.php b/lib/Creator/AtomCreator10.php index e3073d5..5a7801b 100644 --- a/lib/Creator/AtomCreator10.php +++ b/lib/Creator/AtomCreator10.php @@ -150,4 +150,3 @@ function createFeed() { return $feed; } } -?> \ No newline at end of file diff --git a/lib/Creator/FeedCreator.php b/lib/Creator/FeedCreator.php index 1a86ed0..1a0e24a 100644 --- a/lib/Creator/FeedCreator.php +++ b/lib/Creator/FeedCreator.php @@ -246,4 +246,3 @@ function saveFeed($filename="", $displayContents=true) { } } } -?> diff --git a/lib/Creator/GPXCreator.php b/lib/Creator/GPXCreator.php index 525941f..8d87c2e 100644 --- a/lib/Creator/GPXCreator.php +++ b/lib/Creator/GPXCreator.php @@ -39,4 +39,3 @@ function createFeed() { return $feed; } } -?> \ No newline at end of file diff --git a/lib/Creator/HTMLCreator.php b/lib/Creator/HTMLCreator.php index 8bd76e5..792257a 100644 --- a/lib/Creator/HTMLCreator.php +++ b/lib/Creator/HTMLCreator.php @@ -149,4 +149,3 @@ function _generateFilename() { return substr($fileInfo["basename"],0,-(strlen($fileInfo["extension"])+1)).".html"; } } -?> \ No newline at end of file diff --git a/lib/Creator/JSCreator.php b/lib/Creator/JSCreator.php index a3c82ad..4ee56b7 100644 --- a/lib/Creator/JSCreator.php +++ b/lib/Creator/JSCreator.php @@ -38,4 +38,3 @@ function _generateFilename() { return substr($fileInfo["basename"],0,-(strlen($fileInfo["extension"])+1)).".js"; } } -?> \ No newline at end of file diff --git a/lib/Creator/KMLCreator.php b/lib/Creator/KMLCreator.php index 5a70be1..9387008 100644 --- a/lib/Creator/KMLCreator.php +++ b/lib/Creator/KMLCreator.php @@ -92,4 +92,3 @@ function _generateFilename() { return substr($fileInfo["basename"],0,-(strlen($fileInfo["extension"])+1)).".kml"; } } -?> \ No newline at end of file diff --git a/lib/Creator/MBOXCreator.php b/lib/Creator/MBOXCreator.php index a93d600..6e565b5 100644 --- a/lib/Creator/MBOXCreator.php +++ b/lib/Creator/MBOXCreator.php @@ -83,4 +83,3 @@ function _generateFilename() { return substr($fileInfo["basename"],0,-(strlen($fileInfo["extension"])+1)).".mbox"; } } -?> \ No newline at end of file diff --git a/lib/Creator/OPMLCreator.php b/lib/Creator/OPMLCreator.php index 5654f93..f3d65c4 100644 --- a/lib/Creator/OPMLCreator.php +++ b/lib/Creator/OPMLCreator.php @@ -60,4 +60,3 @@ function createFeed() { return $feed; } } -?> \ No newline at end of file diff --git a/lib/Creator/PHPCreator.php b/lib/Creator/PHPCreator.php index f7e7885..f0ae389 100644 --- a/lib/Creator/PHPCreator.php +++ b/lib/Creator/PHPCreator.php @@ -44,4 +44,3 @@ function createFeed() { return $feed; } } -?> \ No newline at end of file diff --git a/lib/Creator/PIECreator01.php b/lib/Creator/PIECreator01.php index a8a82de..6088df0 100644 --- a/lib/Creator/PIECreator01.php +++ b/lib/Creator/PIECreator01.php @@ -48,4 +48,3 @@ function createFeed() { return $feed; } } -?> \ No newline at end of file diff --git a/lib/Creator/RSSCreator091.php b/lib/Creator/RSSCreator091.php index 8945ef6..1bf9714 100644 --- a/lib/Creator/RSSCreator091.php +++ b/lib/Creator/RSSCreator091.php @@ -161,4 +161,3 @@ function createFeed() { return $feed; } } -?> diff --git a/lib/Creator/RSSCreator10.php b/lib/Creator/RSSCreator10.php index 3183af8..603b67f 100644 --- a/lib/Creator/RSSCreator10.php +++ b/lib/Creator/RSSCreator10.php @@ -89,4 +89,3 @@ function createFeed() { return $feed; } } -?> \ No newline at end of file diff --git a/lib/Creator/RSSCreator20.php b/lib/Creator/RSSCreator20.php index 80f1b11..5c04a9d 100644 --- a/lib/Creator/RSSCreator20.php +++ b/lib/Creator/RSSCreator20.php @@ -14,4 +14,3 @@ function __construct() { } } -?> \ No newline at end of file diff --git a/lib/Element/FeedDate.php b/lib/Element/FeedDate.php index ba1c94f..fd41e39 100644 --- a/lib/Element/FeedDate.php +++ b/lib/Element/FeedDate.php @@ -93,4 +93,3 @@ function unix() { return $this->unix; } } -?> \ No newline at end of file diff --git a/lib/Element/FeedHtmlField.php b/lib/Element/FeedHtmlField.php index 67f3293..6a82927 100644 --- a/lib/Element/FeedHtmlField.php +++ b/lib/Element/FeedHtmlField.php @@ -54,4 +54,3 @@ public function output() { return $result; } } -?> \ No newline at end of file diff --git a/lib/Element/FeedImage.php b/lib/Element/FeedImage.php index b667fbc..e41619d 100644 --- a/lib/Element/FeedImage.php +++ b/lib/Element/FeedImage.php @@ -16,4 +16,3 @@ class FeedImage extends HtmlDescribable { */ var $width, $height, $description; } -?> \ No newline at end of file diff --git a/lib/Element/FeedItem.php b/lib/Element/FeedItem.php index ad25b0b..6d1798c 100644 --- a/lib/Element/FeedItem.php +++ b/lib/Element/FeedItem.php @@ -56,4 +56,3 @@ class FeedItem extends HtmlDescribable { // on hold // var $source; } -?> \ No newline at end of file diff --git a/lib/Element/HtmlDescribable.php b/lib/Element/HtmlDescribable.php index 7ba8c04..6e07173 100644 --- a/lib/Element/HtmlDescribable.php +++ b/lib/Element/HtmlDescribable.php @@ -30,4 +30,3 @@ function getDescription($overrideSyndicateHtml = false) { return $descriptionField->output(); } } -?> \ No newline at end of file diff --git a/lib/UniversalFeedCreator.php b/lib/UniversalFeedCreator.php index 0416a73..b35dada 100644 --- a/lib/UniversalFeedCreator.php +++ b/lib/UniversalFeedCreator.php @@ -151,4 +151,3 @@ function useCached($format="RSS0.91", $filename="", $timeout=3600) { $this->_feed->useCached($filename, $timeout); } } -?> \ No newline at end of file From 8b8e1d8336d44adb9ef8c47326557abfee2e8b7e Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Sun, 14 May 2017 09:31:21 +0200 Subject: [PATCH 04/19] added proper visibility keywords, removed var --- lib/Creator/AtomCreator03.php | 8 ++++-- lib/Creator/AtomCreator10.php | 8 ++++-- lib/Creator/FeedCreator.php | 46 +++++++++++++++++---------------- lib/Creator/GPXCreator.php | 8 ++++-- lib/Creator/HTMLCreator.php | 27 ++++++++++--------- lib/Creator/JSCreator.php | 9 +++---- lib/Creator/KMLCreator.php | 10 ++++--- lib/Creator/MBOXCreator.php | 20 ++++++++++---- lib/Creator/OPMLCreator.php | 8 ++++-- lib/Creator/PHPCreator.php | 8 ++++-- lib/Creator/PIECreator01.php | 8 ++++-- lib/Creator/RSSCreator091.php | 23 ++++++----------- lib/Creator/RSSCreator10.php | 8 ++---- lib/Creator/RSSCreator20.php | 6 ++++- lib/Element/FeedDate.php | 16 ++++++------ lib/Element/FeedHtmlField.php | 4 +-- lib/Element/FeedImage.php | 4 +-- lib/Element/FeedItem.php | 10 +++---- lib/Element/HtmlDescribable.php | 9 ++++--- lib/UniversalFeedCreator.php | 13 ++++++---- 20 files changed, 145 insertions(+), 108 deletions(-) diff --git a/lib/Creator/AtomCreator03.php b/lib/Creator/AtomCreator03.php index ad3a6d2..7cfc184 100644 --- a/lib/Creator/AtomCreator03.php +++ b/lib/Creator/AtomCreator03.php @@ -18,12 +18,16 @@ */ class AtomCreator03 extends FeedCreator { - function __construct() { + /** + * AtomCreator03 constructor. + */ + public function __construct() { $this->contentType = "application/atom+xml"; $this->encoding = "utf-8"; } - function createFeed() { + /** @inheritdoc */ + public function createFeed() { $feed = "encoding."\"?>\n"; $feed.= $this->_createGeneratorComment(); $feed.= $this->_createStylesheetReferences(); diff --git a/lib/Creator/AtomCreator10.php b/lib/Creator/AtomCreator10.php index 5a7801b..ee21405 100644 --- a/lib/Creator/AtomCreator10.php +++ b/lib/Creator/AtomCreator10.php @@ -18,12 +18,16 @@ */ class AtomCreator10 extends FeedCreator { - function __construct() { + /** + * AtomCreator10 constructor. + */ + public function __construct() { $this->contentType = "application/atom+xml"; $this->encoding = "utf-8"; } - function createFeed() { + /** @inheritdoc */ + public function createFeed() { $feed = "encoding."\"?>\n"; $feed.= $this->_createGeneratorComment(); $feed.= $this->_createStylesheetReferences(); diff --git a/lib/Creator/FeedCreator.php b/lib/Creator/FeedCreator.php index 1a0e24a..128e6ae 100644 --- a/lib/Creator/FeedCreator.php +++ b/lib/Creator/FeedCreator.php @@ -12,44 +12,41 @@ abstract class FeedCreator extends HtmlDescribable { /** * Mandatory attributes of a feed. */ - var $title, $description, $link; - var $format = 'BASE'; + public $title, $description, $link; + public $format = 'BASE'; /** * Optional attributes of a feed. */ - var $syndicationURL, $image, $language, $copyright, $pubDate, $lastBuildDate, $editor, $editorEmail, $webmaster, $category, $docs, $ttl, $rating, $skipHours, $skipDays; + public $syndicationURL, $image, $language, $copyright, $pubDate, $lastBuildDate, $editor, $editorEmail, $webmaster, $category, $docs, $ttl, $rating, $skipHours, $skipDays; /** * The url of the external xsl stylesheet used to format the naked rss feed. * Ignored in the output when empty. */ - var $xslStyleSheet = ""; + public $xslStyleSheet = ""; - /** - * @access private - */ - var $items = Array(); + /** @var FeedItem[] */ + protected $items = Array(); /** * Generator string - * */ - var $generator = "info@mypapit.net"; + public $generator = "info@mypapit.net"; /** * This feed's MIME content type. * @since 1.4 * @access private */ - var $contentType = "application/xml"; + protected $contentType = "application/xml"; /** * This feed's character encoding. * @since 1.6.1 */ - var $encoding = "UTF-8"; //"ISO-8859-1"; + protected $encoding = "UTF-8"; //"ISO-8859-1"; /** * Any additional elements to include as an associated array. All $key => $value pairs @@ -59,7 +56,7 @@ abstract class FeedCreator extends HtmlDescribable { * if $value contains markup. This may be abused to embed tags not implemented by * the FeedCreator class used. */ - var $additionalElements = Array(); + public $additionalElements = Array(); /** * Adds a FeedItem to the feed. @@ -71,7 +68,12 @@ public function addItem($item) $this->items[] = $item; } - function version() + /** + * Get the version string for the generator + * + * @return string + */ + public function version() { return FEEDCREATOR_VERSION." (".$this->generator.")"; } @@ -119,7 +121,7 @@ public static function iTrunc($string, $length) { * The format of this comment seems to be recognized by * Syndic8.com. */ - function _createGeneratorComment() { + protected function _createGeneratorComment() { return "\n"; } @@ -130,7 +132,7 @@ function _createGeneratorComment() { * @param string $indentString a string that will be inserted before every generated line * @return string the XML tags corresponding to $additionalElements */ - function _createAdditionalElements($elements, $indentString="") { + protected function _createAdditionalElements($elements, $indentString="") { $ae = ""; if (is_array($elements)) { foreach($elements AS $key => $value) { @@ -140,7 +142,7 @@ function _createAdditionalElements($elements, $indentString="") { return $ae; } - function _createStylesheetReferences() { + protected function _createStylesheetReferences() { $xml = ""; if (!empty($this->cssStyleSheet)) $xml .= "cssStyleSheet."\" type=\"text/css\"?>\n"; if (!empty($this->xslStyleSheet)) $xml .= "xslStyleSheet."\" type=\"text/xsl\"?>\n"; @@ -152,7 +154,7 @@ function _createStylesheetReferences() { * * @return string the feed's complete text */ - abstract function createFeed(); + abstract public function createFeed(); /** * Generate a filename for the feed cache file. The result will be $_SERVER["PHP_SELF"] with the extension changed to .xml. @@ -170,7 +172,7 @@ abstract function createFeed(); * @since 1.4 * @access private */ - function _generateFilename() { + protected function _generateFilename() { $fileInfo = pathinfo($_SERVER["PHP_SELF"]); return substr($fileInfo["basename"],0,-(strlen($fileInfo["extension"])+1)).".xml"; } @@ -178,7 +180,7 @@ function _generateFilename() { /** * @since 1.4 */ - private function _redirect($filename) { + protected function _redirect($filename) { // attention, heavily-commented-out-area // maybe use this in addition to file time checking @@ -212,7 +214,7 @@ private function _redirect($filename) { * @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()). * @param int $timeout optional the timeout in seconds before a cached version is refreshed (defaults to 3600 = 1 hour) */ - function useCached($filename="", $timeout=3600) { + public function useCached($filename="", $timeout=3600) { $this->_timeout = $timeout; if ($filename=="") { $filename = $this->_generateFilename(); @@ -230,7 +232,7 @@ function useCached($filename="", $timeout=3600) { * @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()). * @param bool $displayContents optional send an HTTP redirect header or not. If true, the user will be automatically redirected to the created file. */ - function saveFeed($filename="", $displayContents=true) { + public function saveFeed($filename="", $displayContents=true) { if ($filename=="") { $filename = $this->_generateFilename(); } diff --git a/lib/Creator/GPXCreator.php b/lib/Creator/GPXCreator.php index 8d87c2e..0527604 100644 --- a/lib/Creator/GPXCreator.php +++ b/lib/Creator/GPXCreator.php @@ -8,12 +8,16 @@ */ class GPXCreator extends FeedCreator { - function __construct() { + /** + * GPXCreator constructor. + */ + public function __construct() { $this->contentType = "text/xml"; $this->encoding = "utf-8"; } - function createFeed() { + /** @inheritdoc */ + public function createFeed() { $feed = "encoding."\"?>\n"; $feed.= $this->_createStylesheetReferences(); $feed.= "stylelessOutput!="") { return $this->stylelessOutput; @@ -144,7 +143,7 @@ function createFeed() { * @since 1.4 * @access private */ - function _generateFilename() { + protected function _generateFilename() { $fileInfo = pathinfo($_SERVER["PHP_SELF"]); return substr($fileInfo["basename"],0,-(strlen($fileInfo["extension"])+1)).".html"; } diff --git a/lib/Creator/JSCreator.php b/lib/Creator/JSCreator.php index 4ee56b7..225e62b 100644 --- a/lib/Creator/JSCreator.php +++ b/lib/Creator/JSCreator.php @@ -7,14 +7,13 @@ * @package de.bitfolge.feedcreator */ class JSCreator extends HTMLCreator { - var $contentType = "text/javascript"; + protected $contentType = "text/javascript"; /** * writes the javascript - * - * @return string the scripts's complete text + * @inheritdoc */ - function createFeed() + public function createFeed() { $feed = parent::createFeed(); $feedArray = explode("\n",$feed); @@ -33,7 +32,7 @@ function createFeed() * @since 1.4 * @access private */ - function _generateFilename() { + protected function _generateFilename() { $fileInfo = pathinfo($_SERVER["PHP_SELF"]); return substr($fileInfo["basename"],0,-(strlen($fileInfo["extension"])+1)).".js"; } diff --git a/lib/Creator/KMLCreator.php b/lib/Creator/KMLCreator.php index 9387008..b29c21a 100644 --- a/lib/Creator/KMLCreator.php +++ b/lib/Creator/KMLCreator.php @@ -8,12 +8,16 @@ */ class KMLCreator extends FeedCreator { - function __construct() { + /** + * KMLCreator constructor. + */ + public function __construct() { $this->contentType = "application/vnd.google-earth.kml+xml"; $this->encoding = "utf-8"; } - function createFeed() { + /** @inheritdoc */ + public function createFeed() { $feed = "encoding."\"?>\n"; $feed.= $this->_createStylesheetReferences(); $feed.= "\n"; @@ -87,7 +91,7 @@ function createFeed() { * @since 1.4 * @access private */ - function _generateFilename() { + protected function _generateFilename() { $fileInfo = pathinfo($_SERVER["PHP_SELF"]); return substr($fileInfo["basename"],0,-(strlen($fileInfo["extension"])+1)).".kml"; } diff --git a/lib/Creator/MBOXCreator.php b/lib/Creator/MBOXCreator.php index 6e565b5..bdfab35 100644 --- a/lib/Creator/MBOXCreator.php +++ b/lib/Creator/MBOXCreator.php @@ -9,12 +9,22 @@ */ class MBOXCreator extends FeedCreator { - function __construct() { + /** + * MBOXCreator constructor. + */ + public function __construct() { $this->contentType = "text/plain"; $this->encoding = "ISO-8859-15"; } - function qp_enc($input = "", $line_max = 76) { + /** + * Quoted Printable encoding + * + * @param string $input + * @param int $line_max wrap lines after these number of characters + * @return string + */ + protected function qp_enc($input = "", $line_max = 76) { $hex = array('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'); $lines = preg_split("/(?:\r\n|\r|\n)/", $input); $eol = "\r\n"; @@ -45,9 +55,9 @@ function qp_enc($input = "", $line_max = 76) { /** * Builds the MBOX contents. - * @return string the feed's complete text + * @inheritdoc */ - function createFeed() { + public function createFeed() { for ($i=0;$iitems);$i++) { if ($this->items[$i]->author!="") { $from = $this->items[$i]->author; @@ -78,7 +88,7 @@ function createFeed() { * @since 1.4 * @access private */ - function _generateFilename() { + protected function _generateFilename() { $fileInfo = pathinfo($_SERVER["PHP_SELF"]); return substr($fileInfo["basename"],0,-(strlen($fileInfo["extension"])+1)).".mbox"; } diff --git a/lib/Creator/OPMLCreator.php b/lib/Creator/OPMLCreator.php index f3d65c4..5f4816a 100644 --- a/lib/Creator/OPMLCreator.php +++ b/lib/Creator/OPMLCreator.php @@ -10,11 +10,15 @@ */ class OPMLCreator extends FeedCreator { - function __construct() { + /** + * OPMLCreator constructor. + */ + public function __construct() { $this->encoding = "utf-8"; } - function createFeed() { + /** @inheritdoc */ + public function createFeed() { $feed = "encoding."\"?>\n"; $feed.= $this->_createGeneratorComment(); $feed.= $this->_createStylesheetReferences(); diff --git a/lib/Creator/PHPCreator.php b/lib/Creator/PHPCreator.php index f0ae389..8748713 100644 --- a/lib/Creator/PHPCreator.php +++ b/lib/Creator/PHPCreator.php @@ -8,12 +8,16 @@ */ class PHPCreator extends FeedCreator { - function __construct() { + /** + * PHPCreator constructor. + */ + public function __construct() { $this->contentType = "text/plain"; $this->encoding = "utf-8"; } - function createFeed() { + /** @inheritdoc */ + public function createFeed() { $feed = "title),100))."';\n"; diff --git a/lib/Creator/PIECreator01.php b/lib/Creator/PIECreator01.php index 6088df0..0dd0b42 100644 --- a/lib/Creator/PIECreator01.php +++ b/lib/Creator/PIECreator01.php @@ -10,11 +10,15 @@ */ class PIECreator01 extends FeedCreator { - function __construct() { + /** + * PIECreator01 constructor. + */ + public function __construct() { $this->encoding = "utf-8"; } - function createFeed() { + /** @inheritdoc */ + public function createFeed() { $feed = "encoding."\"?>\n"; $feed.= $this->_createStylesheetReferences(); $feed.= "\n"; diff --git a/lib/Creator/RSSCreator091.php b/lib/Creator/RSSCreator091.php index 1bf9714..831dcef 100644 --- a/lib/Creator/RSSCreator091.php +++ b/lib/Creator/RSSCreator091.php @@ -9,13 +9,12 @@ */ class RSSCreator091 extends FeedCreator { + /** @var string Stores this RSS feed's version number. */ + protected $RSSVersion; + /** - * Stores this RSS feed's version number. - * - * @access private + * RSSCreator091 constructor. */ - var $RSSVersion; - function __construct() { $this->_setRSSVersion("0.91"); $this->contentType = "application/rss+xml"; @@ -23,20 +22,14 @@ function __construct() { /** * Sets this RSS feed's version number. - * - * @access private + * @param string $version */ - function _setRSSVersion($version) { + protected function _setRSSVersion($version) { $this->RSSVersion = $version; } - /** - * Builds the RSS feed's text. The feed will be compliant to RDF Site Summary (RSS) 1.0. - * The feed will contain all items previously added in the same order. - * - * @return string the feed's complete text - */ - function createFeed() { + /** @inheritdoc */ + public function createFeed() { $feed = "encoding."\"?>\n"; $feed.= $this->_createGeneratorComment(); $feed.= $this->_createStylesheetReferences(); diff --git a/lib/Creator/RSSCreator10.php b/lib/Creator/RSSCreator10.php index 603b67f..6e3b838 100644 --- a/lib/Creator/RSSCreator10.php +++ b/lib/Creator/RSSCreator10.php @@ -9,12 +9,8 @@ */ class RSSCreator10 extends FeedCreator { - /** - * Builds the RSS feed's text. The feed will be compliant to RDF Site Summary (RSS) 1.0. - * The feed will contain all items previously added in the same order. - * @return string the feed's complete text - */ - function createFeed() { + /** @inheritdoc */ + public function createFeed() { $feed = "encoding."\"?>\n"; $feed.= $this->_createGeneratorComment(); if (empty($this->cssStyleSheet)) { diff --git a/lib/Creator/RSSCreator20.php b/lib/Creator/RSSCreator20.php index 5c04a9d..e06211a 100644 --- a/lib/Creator/RSSCreator20.php +++ b/lib/Creator/RSSCreator20.php @@ -9,7 +9,11 @@ */ class RSSCreator20 extends RSSCreator091 { - function __construct() { + /** + * RSSCreator20 constructor. + */ + public function __construct() { + parent::__construct(); parent::_setRSSVersion("2.0"); } diff --git a/lib/Element/FeedDate.php b/lib/Element/FeedDate.php index fd41e39..3ffd4f3 100644 --- a/lib/Element/FeedDate.php +++ b/lib/Element/FeedDate.php @@ -6,7 +6,7 @@ * @package de.bitfolge.feedcreator */ class FeedDate { - var $unix; + protected $unix; /** * Creates a new instance of FeedDate representing a given date. @@ -14,7 +14,7 @@ class FeedDate { * * @param mixed $dateString optional the date this FeedDate will represent. If not specified, the current date and time is used. */ - function __construct($dateString="") { + public function __construct($dateString="") { if ($dateString=="") $dateString = date("r"); if (is_integer($dateString)) { @@ -64,9 +64,9 @@ function __construct($dateString="") { /** * Gets the date stored in this FeedDate as an RFC 822 date. * - * @return a date in RFC 822 format + * @return string a date in RFC 822 format */ - function rfc822() { + public function rfc822() { //return gmdate("r",$this->unix); $date = gmdate("D, d M Y H:i:s O", $this->unix); return $date; @@ -75,9 +75,9 @@ function rfc822() { /** * Gets the date stored in this FeedDate as an ISO 8601 date. * - * @return a date in ISO 8601 format + * @return string a date in ISO 8601 format */ - function iso8601() { + public function iso8601() { $date = gmdate("Y-m-d\TH:i:sO",$this->unix); $date = substr($date,0,22) . ':' . substr($date,-2); if (TIME_ZONE!="") $date = str_replace("+00:00",TIME_ZONE,$date); @@ -87,9 +87,9 @@ function iso8601() { /** * Gets the date stored in this FeedDate as unix time stamp. * - * @return a date as a unix time stamp + * @return int a date as a unix time stamp */ - function unix() { + public function unix() { return $this->unix; } } diff --git a/lib/Element/FeedHtmlField.php b/lib/Element/FeedHtmlField.php index 6a82927..052ccef 100644 --- a/lib/Element/FeedHtmlField.php +++ b/lib/Element/FeedHtmlField.php @@ -12,13 +12,13 @@ class FeedHtmlField { /** * Mandatory attributes of a FeedHtmlField. */ - var $rawFieldContent; + protected $rawFieldContent; /** * Optional attributes of a FeedHtmlField. * */ - var $truncSize, $syndicateHtml; + public $truncSize, $syndicateHtml; /** * Creates a new instance of FeedHtmlField. diff --git a/lib/Element/FeedImage.php b/lib/Element/FeedImage.php index e41619d..adec7f0 100644 --- a/lib/Element/FeedImage.php +++ b/lib/Element/FeedImage.php @@ -9,10 +9,10 @@ class FeedImage extends HtmlDescribable { /** * Mandatory attributes of an image. */ - var $title, $url, $link; + public $title, $url, $link; /** * Optional attributes of an image. */ - var $width, $height, $description; + public $width, $height, $description; } diff --git a/lib/Element/FeedItem.php b/lib/Element/FeedItem.php index 6d1798c..f8c6627 100644 --- a/lib/Element/FeedItem.php +++ b/lib/Element/FeedItem.php @@ -10,12 +10,12 @@ class FeedItem extends HtmlDescribable { /** * Mandatory attributes of an item. */ - var $title, $description, $link; + public $title, $description, $link; /** * Optional attributes of an item. */ - var $author, $authorEmail, $authorURL,$image, $category, $categoryScheme, $comments, $guid, $source, $creator, $contributor, $lat, $long, $thumb; + public $author, $authorEmail, $authorURL,$image, $category, $categoryScheme, $comments, $guid, $source, $creator, $contributor, $lat, $long, $thumb; /** * Publishing date of an item. May be in one of the following formats: @@ -30,7 +30,7 @@ class FeedItem extends HtmlDescribable { * Unix: * 1043082341 */ - var $date; + public $date; /** * Add element tag RSS 2.0, supported by ATOM 1.0 too @@ -41,7 +41,7 @@ class FeedItem extends HtmlDescribable { * * */ - var $enclosure; + public $enclosure; /** * Any additional elements to include as an associated array. All $key => $value pairs @@ -51,7 +51,7 @@ class FeedItem extends HtmlDescribable { * if $value contains markup. This may be abused to embed tags not implemented by * the FeedCreator class used. */ - var $additionalElements = Array(); + public $additionalElements = Array(); // on hold // var $source; diff --git a/lib/Element/HtmlDescribable.php b/lib/Element/HtmlDescribable.php index 6e07173..1b5b618 100644 --- a/lib/Element/HtmlDescribable.php +++ b/lib/Element/HtmlDescribable.php @@ -9,12 +9,15 @@ class HtmlDescribable { /** * Indicates whether the description field should be rendered in HTML. */ - var $descriptionHtmlSyndicated; + public $descriptionHtmlSyndicated; /** * Indicates whether and to how many characters a description should be truncated. */ - var $descriptionTruncSize; + public $descriptionTruncSize; + + /** @var string the Description */ + public $description; /** * Returns a formatted description field, depending on descriptionHtmlSyndicated and @@ -23,7 +26,7 @@ class HtmlDescribable { * @param bool $overrideSyndicateHtml * @return string the formatted description */ - function getDescription($overrideSyndicateHtml = false) { + public function getDescription($overrideSyndicateHtml = false) { $descriptionField = new FeedHtmlField($this->description); $descriptionField->syndicateHtml = $overrideSyndicateHtml || $this->descriptionHtmlSyndicated; $descriptionField->truncSize = $this->descriptionTruncSize; diff --git a/lib/UniversalFeedCreator.php b/lib/UniversalFeedCreator.php index b35dada..685e70f 100644 --- a/lib/UniversalFeedCreator.php +++ b/lib/UniversalFeedCreator.php @@ -19,9 +19,12 @@ */ class UniversalFeedCreator extends FeedCreator { /** @var FeedCreator */ - var $_feed; + protected $_feed; - function _setFormat($format) { + /** + * @param string $format + */ + protected function _setFormat($format) { switch (strtoupper($format)) { case "BASE": @@ -114,7 +117,7 @@ function _setFormat($format) { * "PIE0.1", "mbox", "RSS0.91", "RSS1.0", "RSS2.0", "OPML", "ATOM0.3", "HTML", "JS" * @return string the contents of the feed. */ - function createFeed($format = "RSS0.91") { + public function createFeed($format = "RSS0.91") { $this->_setFormat($format); return $this->_feed->createFeed(); } @@ -129,7 +132,7 @@ function createFeed($format = "RSS0.91") { * @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()). * @param boolean $displayContents optional send the content of the file or not. If true, the file will be sent in the body of the response. */ - function saveFeed($format="RSS0.91", $filename="", $displayContents=true) { + public function saveFeed($format="RSS0.91", $filename="", $displayContents=true) { $this->_setFormat($format); $this->_feed->saveFeed($filename, $displayContents); } @@ -146,7 +149,7 @@ function saveFeed($format="RSS0.91", $filename="", $displayContents=true) { * @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()). * @param int $timeout optional the timeout in seconds before a cached version is refreshed (defaults to 3600 = 1 hour) */ - function useCached($format="RSS0.91", $filename="", $timeout=3600) { + public function useCached($format="RSS0.91", $filename="", $timeout=3600) { $this->_setFormat($format); $this->_feed->useCached($filename, $timeout); } From 2288f013b1237a6e2c73385ca6dd3453b7838b5a Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Sun, 14 May 2017 09:33:03 +0200 Subject: [PATCH 05/19] Bugfix: FeedImage has no getDescription method --- lib/Creator/RSSCreator091.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Creator/RSSCreator091.php b/lib/Creator/RSSCreator091.php index 831dcef..d550129 100644 --- a/lib/Creator/RSSCreator091.php +++ b/lib/Creator/RSSCreator091.php @@ -71,7 +71,7 @@ public function createFeed() { $feed.= " ".$this->image->height."\n"; } if ($this->image->description!="") { - $feed.= " ".$this->image->getDescription()."\n"; + $feed.= " ".htmlspecialchars($this->image->description)."\n"; } $feed.= " \n"; } From dd7b0cba0037313a24a851a48f0bd675c497913e Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Sun, 14 May 2017 09:34:16 +0200 Subject: [PATCH 06/19] initialize variables --- lib/Creator/HTMLCreator.php | 2 ++ lib/Creator/MBOXCreator.php | 1 + lib/Element/FeedDate.php | 1 + 3 files changed, 4 insertions(+) diff --git a/lib/Creator/HTMLCreator.php b/lib/Creator/HTMLCreator.php index 0e3d49d..d5cd3df 100644 --- a/lib/Creator/HTMLCreator.php +++ b/lib/Creator/HTMLCreator.php @@ -70,6 +70,8 @@ public function createFeed() { //set an openInNewWindow_token_to be inserted or not if ($this->openInNewWindow) { $targetInsert = " class='target_blank'"; + } else { + $targetInsert = ''; } // use this array to put the lines in and implode later with "document.write" javascript diff --git a/lib/Creator/MBOXCreator.php b/lib/Creator/MBOXCreator.php index bdfab35..bbebfa6 100644 --- a/lib/Creator/MBOXCreator.php +++ b/lib/Creator/MBOXCreator.php @@ -58,6 +58,7 @@ protected function qp_enc($input = "", $line_max = 76) { * @inheritdoc */ public function createFeed() { + $feed = ''; for ($i=0;$iitems);$i++) { if ($this->items[$i]->author!="") { $from = $this->items[$i]->author; diff --git a/lib/Element/FeedDate.php b/lib/Element/FeedDate.php index 3ffd4f3..fd811b4 100644 --- a/lib/Element/FeedDate.php +++ b/lib/Element/FeedDate.php @@ -21,6 +21,7 @@ public function __construct($dateString="") { $this->unix = $dateString; return; } + $tzOffset = 0; if (preg_match("~(?:(?:Mon|Tue|Wed|Thu|Fri|Sat|Sun),\\s+)?(\\d{1,2})\\s+([a-zA-Z]{3})\\s+(\\d{4})\\s+(\\d{2}):(\\d{2}):(\\d{2})\\s+(.*)~",$dateString,$matches)) { $months = Array("Jan"=>1,"Feb"=>2,"Mar"=>3,"Apr"=>4,"May"=>5,"Jun"=>6,"Jul"=>7,"Aug"=>8,"Sep"=>9,"Oct"=>10,"Nov"=>11,"Dec"=>12); $this->unix = mktime($matches[4],$matches[5],$matches[6],$months[$matches[2]],$matches[1],$matches[3]); From e9d065316840d51baa8bfb29ce7a0e0e9253a298 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Sun, 14 May 2017 09:41:41 +0200 Subject: [PATCH 07/19] add missing doc block --- lib/Creator/FeedCreator.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/Creator/FeedCreator.php b/lib/Creator/FeedCreator.php index 128e6ae..4da4d60 100644 --- a/lib/Creator/FeedCreator.php +++ b/lib/Creator/FeedCreator.php @@ -178,7 +178,10 @@ protected function _generateFilename() { } /** + * Send given file to Browser + * * @since 1.4 + * @param string $filename */ protected function _redirect($filename) { // attention, heavily-commented-out-area From 5930eaecfa3557b35f90f812f4715eacde179033 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Sun, 14 May 2017 09:46:51 +0200 Subject: [PATCH 08/19] replace deprecated each() each() is deprecated and foreach() is faster and easier to read anyway. --- lib/Creator/MBOXCreator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Creator/MBOXCreator.php b/lib/Creator/MBOXCreator.php index bbebfa6..2fb4b0f 100644 --- a/lib/Creator/MBOXCreator.php +++ b/lib/Creator/MBOXCreator.php @@ -30,7 +30,7 @@ protected function qp_enc($input = "", $line_max = 76) { $eol = "\r\n"; $escape = "="; $output = ""; - while( list(, $line) = each($lines) ) { + foreach($lines as $line) { $linlen = strlen($line); $newline = ""; for($i = 0; $i < $linlen; $i++) { From 789d8ad50e172f615bb3c69fe010bef45a1424b8 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Sun, 14 May 2017 09:48:25 +0200 Subject: [PATCH 09/19] readfile does not have a file mode parameter --- lib/Creator/FeedCreator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Creator/FeedCreator.php b/lib/Creator/FeedCreator.php index 4da4d60..25e4777 100644 --- a/lib/Creator/FeedCreator.php +++ b/lib/Creator/FeedCreator.php @@ -203,7 +203,7 @@ protected function _redirect($filename) { } else { header("Content-Disposition: inline; filename=".basename($filename)); } - readfile($filename, "r"); + readfile($filename); exit(); } From 1f6e3a27f35e34009f0b4433dd13a5381dde5503 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Sun, 14 May 2017 09:49:06 +0200 Subject: [PATCH 10/19] use single quotes in regexp This avoids having to escape the backslash --- lib/Creator/FeedCreator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Creator/FeedCreator.php b/lib/Creator/FeedCreator.php index 25e4777..b6ad828 100644 --- a/lib/Creator/FeedCreator.php +++ b/lib/Creator/FeedCreator.php @@ -198,7 +198,7 @@ protected function _redirect($filename) { //header("Location: ".$filename); header("Content-Type: ".$this->contentType."; charset=".$this->encoding."; filename=".basename($filename)); - if (preg_match("/\.(kml|gpx)$/",$filename)) { + if (preg_match('/\.(kml|gpx)$/',$filename)) { header("Content-Disposition: attachment; filename=".basename($filename)); } else { header("Content-Disposition: inline; filename=".basename($filename)); From 528a2015e13bd05d99442e5e0de736594e25a3fe Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Mon, 15 May 2017 23:51:04 +0200 Subject: [PATCH 11/19] ensure integer in timezone offset calculation --- lib/Element/FeedDate.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Element/FeedDate.php b/lib/Element/FeedDate.php index fd811b4..8d488cb 100644 --- a/lib/Element/FeedDate.php +++ b/lib/Element/FeedDate.php @@ -26,7 +26,7 @@ public function __construct($dateString="") { $months = Array("Jan"=>1,"Feb"=>2,"Mar"=>3,"Apr"=>4,"May"=>5,"Jun"=>6,"Jul"=>7,"Aug"=>8,"Sep"=>9,"Oct"=>10,"Nov"=>11,"Dec"=>12); $this->unix = mktime($matches[4],$matches[5],$matches[6],$months[$matches[2]],$matches[1],$matches[3]); if (substr($matches[7],0,1)=='+' OR substr($matches[7],0,1)=='-') { - $tzOffset = (substr($matches[7],0,3) * 60 + substr($matches[7],-2)) * 60; + $tzOffset = (((int)substr($matches[7], 0, 3) * 60) + (int)substr($matches[7], -2)) * 60; } else { if (strlen($matches[7])==1) { $oneHour = 3600; @@ -50,7 +50,7 @@ public function __construct($dateString="") { if (preg_match("~(\\d{4})-(\\d{2})-(\\d{2})T(\\d{2}):(\\d{2}):(\\d{2})(.*)~",$dateString,$matches)) { $this->unix = mktime($matches[4],$matches[5],$matches[6],$matches[2],$matches[3],$matches[1]); if (substr($matches[7],0,1)=='+' OR substr($matches[7],0,1)=='-') { - $tzOffset = (substr($matches[7],0,3) * 60 + substr($matches[7],-2)) * 60; + $tzOffset = (((int) substr($matches[7],0,3) * 60) + (int)substr($matches[7], -2)) * 60; } else { if ($matches[7]=="Z") { $tzOffset = 0; From 9b7f84a58533ec811a831771cbd3ef7f50a1d6df Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Mon, 15 May 2017 23:57:29 +0200 Subject: [PATCH 12/19] allow multiple item categories for RSS format --- lib/Creator/RSSCreator091.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/Creator/RSSCreator091.php b/lib/Creator/RSSCreator091.php index d550129..012e14e 100644 --- a/lib/Creator/RSSCreator091.php +++ b/lib/Creator/RSSCreator091.php @@ -130,8 +130,10 @@ public function createFeed() { if ($this->items[$i]->lat!="") { $feed.= " ".$this->items[$i]->lat." ".$this->items[$i]->long."\n"; } - if ($this->items[$i]->category!="") { - $feed.= " ".htmlspecialchars($this->items[$i]->category)."\n"; + if(is_array($this->items[$i]->category)) foreach($this->items[$i]->category as $cat){ + $feed.= " ".htmlspecialchars($cat)."\n"; + }else if($this->items[$i]->category!=""){ + $feed.= " ".htmlspecialchars($this->items[$i]->category)."\n"; } if ($this->items[$i]->comments!="") { $feed.= " ".htmlspecialchars($this->items[$i]->comments)."\n"; From ed42e694af752f5e418a17edbeed9490766625fa Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Tue, 16 May 2017 00:01:20 +0200 Subject: [PATCH 13/19] reuse currently set timezone by default Allows defining the timezone before loading the library. See https://bugs.dokuwiki.org/424.html for original bug report --- lib/UniversalFeedCreator.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/UniversalFeedCreator.php b/lib/UniversalFeedCreator.php index 685e70f..82b0145 100644 --- a/lib/UniversalFeedCreator.php +++ b/lib/UniversalFeedCreator.php @@ -1,6 +1,8 @@ Date: Tue, 16 May 2017 00:13:42 +0200 Subject: [PATCH 14/19] fix author/email handling in RSS feeds --- lib/Creator/RSSCreator091.php | 18 ++++++++++++++++-- lib/Creator/RSSCreator10.php | 23 +++++++++++++++++++++-- 2 files changed, 37 insertions(+), 4 deletions(-) diff --git a/lib/Creator/RSSCreator091.php b/lib/Creator/RSSCreator091.php index 012e14e..d781024 100644 --- a/lib/Creator/RSSCreator091.php +++ b/lib/Creator/RSSCreator091.php @@ -118,9 +118,11 @@ public function createFeed() { $feed.= " ".htmlspecialchars($this->items[$i]->link)."\n"; $feed.= " ".$this->items[$i]->getDescription()."\n"; - if ($this->items[$i]->author!="") { - $feed.= " ".htmlspecialchars($this->items[$i]->author)."\n"; + $creator = $this->getAuthor($this->items[$i]->author, $this->items[$i]->authorEmail); + if ($creator) { + $feed .= " " . htmlspecialchars($creator) . "\n"; } + /* // on hold if ($this->items[$i]->source!="") { @@ -155,4 +157,16 @@ public function createFeed() { $feed.= "\n"; return $feed; } + + /** + * Compose the RSS-0.91 and RSS-2.0 author field. + * + * @author Joe Lapp + */ + function getAuthor($author, $email) { + if ($author && $email) { + return $email . ' (' . $author . ')'; + } + return $email; + } } diff --git a/lib/Creator/RSSCreator10.php b/lib/Creator/RSSCreator10.php index 6e3b838..ac9d225 100644 --- a/lib/Creator/RSSCreator10.php +++ b/lib/Creator/RSSCreator10.php @@ -66,8 +66,9 @@ public function createFeed() { if ($this->items[$i]->source!="") { $feed.= " ".htmlspecialchars($this->items[$i]->source)."\n"; } - if ($this->items[$i]->author!="") { - $feed.= " ".htmlspecialchars($this->items[$i]->author)."\n"; + $creator = $this->getAuthor($this->items[$i]->author, $this->items[$i]->authorEmail); + if ($creator) { + $feed.= " ".htmlspecialchars($creator)."\n"; } if ($this->items[$i]->lat!="") { $feed.= " ".$this->items[$i]->lat." ".$this->items[$i]->long."\n"; @@ -84,4 +85,22 @@ public function createFeed() { $feed.= "\n"; return $feed; } + + /** + * Compose the RSS-1.0 author field. + * + * @author Joe Lapp + * @param string $author + * @param string $email + * @return string + */ + protected function getAuthor($author, $email) { + if ($author) { + if ($email) { + return $author . ' (' . $email . ')'; + } + return $author; + } + return $email; + } } From 8e5f3826946cbd486424d2cf6f4f0866eb71898f Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Tue, 16 May 2017 18:01:54 +0200 Subject: [PATCH 15/19] use the most recent phpunit available for the current PHP release Composer will install the most modern phpunit which's requirements (namely the PHP version) can be satisfied by the current environment. The travis config was adjusted to make use of that phpunit release and to test all currently available PHP versions. The bootstrap file will alias the namespaced phpunit classes to their non-namespaced names. --- .travis.yml | 20 ++++++++++++++------ composer.json | 2 +- test/rootfile.php | 17 ++++++++++++++++- 3 files changed, 31 insertions(+), 8 deletions(-) diff --git a/.travis.yml b/.travis.yml index d44aa3e..dc0e7ea 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,11 +1,19 @@ language: php + php: + - "5.3" + - "5.4" + - "5.5" + - "5.6" + - "7.0" + - "7.1" + - "nightly" - - 5.3 - - 5.4 - - 5.5 - - 5.6 - - 7.0 +allow_failures: + - php: "hhvm" + - php: "nightly" before_script: - composer install \ No newline at end of file + composer install + +script: ./vendor/bin/phpunit \ No newline at end of file diff --git a/composer.json b/composer.json index fdb9362..caabfce 100644 --- a/composer.json +++ b/composer.json @@ -18,6 +18,6 @@ "classmap": ["lib"] }, "require-dev": { - "phpunit/phpunit": "^5.7" + "phpunit/phpunit": "*" } } diff --git a/test/rootfile.php b/test/rootfile.php index 6d3a3ae..b312d4f 100644 --- a/test/rootfile.php +++ b/test/rootfile.php @@ -1,3 +1,18 @@ \ No newline at end of file + +if ( + !class_exists('\PHPUnit_Framework_TestCase') + && class_exists('\PHPUnit\Framework\TestCase') +) { + class_alias('\PHPUnit\Framework\TestCase', '\PHPUnit_Framework_TestCase'); + class_alias('\PHPUnit\Framework\Constraint\IsEqual', '\PHPUnit_Framework_Constraint_IsEqual'); + class_alias('\PHPUnit\Util\InvalidArgumentHelper', '\PHPUnit_Util_InvalidArgumentHelper'); +} From 32e050b9d7d9ac4b8d3cafbd18c78743b9932005 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Tue, 16 May 2017 18:11:44 +0200 Subject: [PATCH 16/19] added hhvm to the test matrix failures are allowed --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index dc0e7ea..31f6220 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,6 +8,7 @@ php: - "7.0" - "7.1" - "nightly" + - "hhvm" allow_failures: - php: "hhvm" From 8c3c9b9e2449470185dda370b4db4ed4e2be568d Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Tue, 16 May 2017 18:13:42 +0200 Subject: [PATCH 17/19] fixed typo in test name --- test/UniversalFeedCreatorTest.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/UniversalFeedCreatorTest.php b/test/UniversalFeedCreatorTest.php index c29a6ab..6fd54cf 100644 --- a/test/UniversalFeedCreatorTest.php +++ b/test/UniversalFeedCreatorTest.php @@ -1,5 +1,5 @@ \ No newline at end of file From d05aa7ecaa017d0390787f517b50d2fb49283dfb Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Tue, 16 May 2017 18:15:54 +0200 Subject: [PATCH 18/19] make items public for compatibility all properties used to be public, other software may depend on accessing the items directly. --- lib/Creator/FeedCreator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Creator/FeedCreator.php b/lib/Creator/FeedCreator.php index b6ad828..c55b145 100644 --- a/lib/Creator/FeedCreator.php +++ b/lib/Creator/FeedCreator.php @@ -28,7 +28,7 @@ abstract class FeedCreator extends HtmlDescribable { /** @var FeedItem[] */ - protected $items = Array(); + public $items = Array(); /** * Generator string From 99034fa36d20e26540bebc7aa451e4579c7e473f Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Tue, 16 May 2017 18:26:38 +0200 Subject: [PATCH 19/19] fixed travis failure configuration --- .travis.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 31f6220..4da0abe 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,9 +10,10 @@ php: - "nightly" - "hhvm" -allow_failures: - - php: "hhvm" - - php: "nightly" +matrix: + allow_failures: + - php: "hhvm" + - php: "nightly" before_script: composer install