Skip to content

Commit

Permalink
Merge pull request #2 from splitbrain-forks/master
Browse files Browse the repository at this point in the history
various fixes and improvements
  • Loading branch information
flack authored May 17, 2017
2 parents 55778f7 + 99034fa commit 6a75dbf
Show file tree
Hide file tree
Showing 24 changed files with 260 additions and 168 deletions.
22 changes: 16 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
language: php

php:
- "5.3"
- "5.4"
- "5.5"
- "5.6"
- "7.0"
- "7.1"
- "nightly"
- "hhvm"

- 5.3
- 5.4
- 5.5
- 5.6
- 7.0
matrix:
allow_failures:
- php: "hhvm"
- php: "nightly"

before_script:
composer install
composer install

script: ./vendor/bin/phpunit
3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,8 @@
},
"autoload": {
"classmap": ["lib"]
},
"require-dev": {
"phpunit/phpunit": "*"
}
}
10 changes: 7 additions & 3 deletions lib/Creator/AtomCreator03.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "<?xml version=\"1.0\" encoding=\"".$this->encoding."\"?>\n";
$feed.= $this->_createGeneratorComment();
$feed.= $this->_createStylesheetReferences();
Expand Down Expand Up @@ -82,4 +86,4 @@ function createFeed() {
$feed.= "</feed>\n";
return $feed;
}
}
}
9 changes: 6 additions & 3 deletions lib/Creator/AtomCreator10.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "<?xml version=\"1.0\" encoding=\"".$this->encoding."\"?>\n";
$feed.= $this->_createGeneratorComment();
$feed.= $this->_createStylesheetReferences();
Expand Down Expand Up @@ -150,4 +154,3 @@ function createFeed() {
return $feed;
}
}
?>
72 changes: 38 additions & 34 deletions lib/Creator/FeedCreator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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[] */
public $items = Array();

/**
* Generator string
*
*/
var $generator = "[email protected]";
public $generator = "[email protected]";

/**
* 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
Expand All @@ -59,19 +56,24 @@ 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.
*
* @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)
{
$this->items[] = $item;
}

function version()
/**
* Get the version string for the generator
*
* @return string
*/
public function version()
{
return FEEDCREATOR_VERSION." (".$this->generator.")";
}
Expand All @@ -83,8 +85,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) {
Expand Down Expand Up @@ -119,18 +121,18 @@ public static function iTrunc($string, $length) {
* The format of this comment seems to be recognized by
* Syndic8.com.
*/
function _createGeneratorComment() {
protected function _createGeneratorComment() {
return "<!-- generator=\"".FEEDCREATOR_VERSION."\" -->\n";
}

/**
* 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="") {
protected function _createAdditionalElements($elements, $indentString="") {
$ae = "";
if (is_array($elements)) {
foreach($elements AS $key => $value) {
Expand All @@ -140,7 +142,7 @@ function _createAdditionalElements($elements, $indentString="") {
return $ae;
}

function _createStylesheetReferences() {
protected function _createStylesheetReferences() {
$xml = "";
if (!empty($this->cssStyleSheet)) $xml .= "<?xml-stylesheet href=\"".$this->cssStyleSheet."\" type=\"text/css\"?>\n";
if (!empty($this->xslStyleSheet)) $xml .= "<?xml-stylesheet href=\"".$this->xslStyleSheet."\" type=\"text/xsl\"?>\n";
Expand All @@ -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.
Expand All @@ -170,15 +172,18 @@ 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";
}

/**
* Send given file to Browser
*
* @since 1.4
* @param string $filename
*/
private function _redirect($filename) {
protected function _redirect($filename) {
// attention, heavily-commented-out-area

// maybe use this in addition to file time checking
Expand All @@ -193,12 +198,12 @@ private 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));
}
readfile($filename, "r");
readfile($filename);
exit();
}

Expand All @@ -209,10 +214,10 @@ 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) {
public function useCached($filename="", $timeout=3600) {
$this->_timeout = $timeout;
if ($filename=="") {
$filename = $this->_generateFilename();
Expand All @@ -227,10 +232,10 @@ 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) {
public function saveFeed($filename="", $displayContents=true) {
if ($filename=="") {
$filename = $this->_generateFilename();
}
Expand All @@ -246,4 +251,3 @@ function saveFeed($filename="", $displayContents=true) {
}
}
}
?>
9 changes: 6 additions & 3 deletions lib/Creator/GPXCreator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "<?xml version=\"1.0\" encoding=\"".$this->encoding."\"?>\n";
$feed.= $this->_createStylesheetReferences();
$feed.= "<gpx xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" version=\"1.0\"
Expand All @@ -39,4 +43,3 @@ function createFeed() {
return $feed;
}
}
?>
Loading

0 comments on commit 6a75dbf

Please sign in to comment.