| @ -1,21 +1,20 @@ | |||
| { | |||
| "config": { | |||
| "vendor-dir": "system/vendor/", | |||
| "optimize-autoloader": true | |||
| }, | |||
| "require": { | |||
| "michelf/php-markdown": "~1.4", | |||
| "suin/php-rss-writer": "~1", | |||
| "kanti/hub-updater": "~0.3", | |||
| "ircmaxell/password-compat": "~1.0" | |||
| }, | |||
| "autoload": { | |||
| "files": [ | |||
| "system/includes/dispatch.php", | |||
| "system/includes/functions.php", | |||
| "system/admin/admin.php", | |||
| "system/includes/session.php", | |||
| "system/includes/opml.php" | |||
| ] | |||
| } | |||
| "config": { | |||
| "vendor-dir": "system/vendor/", | |||
| "optimize-autoloader": true | |||
| }, | |||
| "require": { | |||
| "michelf/php-markdown": "~1.4", | |||
| "suin/php-rss-writer": "~1", | |||
| "kanti/hub-updater": "~0.3" | |||
| }, | |||
| "autoload": { | |||
| "files": [ | |||
| "system/includes/dispatch.php", | |||
| "system/includes/functions.php", | |||
| "system/admin/admin.php", | |||
| "system/includes/session.php", | |||
| "system/includes/opml.php" | |||
| ] | |||
| } | |||
| } | |||
| @ -0,0 +1,39 @@ | |||
| <?php | |||
| namespace Kanti; | |||
| class CacheOneFile | |||
| { | |||
| protected $fileName = ""; | |||
| protected $holdTime = 43200; //12h | |||
| public function __construct($fileName, $holdTime = 43200) | |||
| { | |||
| $this->fileName = $fileName; | |||
| $this->holdTime = $holdTime; | |||
| } | |||
| public function is() | |||
| { | |||
| if (! HelperClass::fileExists($this->fileName)) { | |||
| return false; | |||
| } | |||
| if (filemtime($this->fileName) < ( time() - $this->holdTime )) { | |||
| unlink($this->fileName); | |||
| return false; | |||
| } | |||
| return true; | |||
| } | |||
| public function get() | |||
| { | |||
| return file_get_contents($this->fileName); | |||
| } | |||
| public function set($content) | |||
| { | |||
| file_put_contents($this->fileName, $content); | |||
| } | |||
| } | |||
| @ -0,0 +1,12 @@ | |||
| <?php | |||
| namespace Kanti; | |||
| class HelperClass{ | |||
| static public function fileExists($file){ | |||
| return file_exists(dirname($_SERVER["SCRIPT_FILENAME"]) . "/" . $file); | |||
| } | |||
| static public function isInPhar() { | |||
| return substr(__FILE__,0,7) === "phar://"; | |||
| } | |||
| } | |||
| @ -0,0 +1,293 @@ | |||
| <?php | |||
| namespace Kanti; | |||
| class HubUpdater | |||
| { | |||
| protected $options = array( | |||
| "cacheFile" => "downloadInfo.json", | |||
| "holdTime" => 43200, | |||
| "versionFile" => "installedVersion.json", | |||
| "zipFile" => "tmpZipFile.zip", | |||
| "updateignore" => ".updateignore", | |||
| "name" => "", | |||
| "branch" => "master", | |||
| "cache" => "cache/", | |||
| "save" => "", | |||
| "prerelease" => false, | |||
| "exceptions" => false, | |||
| ); | |||
| protected $allRelease = array(); | |||
| protected $streamContext = null; | |||
| public function __construct($option) | |||
| { | |||
| //options | |||
| if (is_array($option)) { | |||
| if (!isset($option['name'])) { | |||
| throw new \Exception('No Name in Option Set'); | |||
| } | |||
| $this->options = $option + $this->options; | |||
| } elseif (is_string($option)) { | |||
| $this->options['name'] = $option; | |||
| } else { | |||
| throw new \Exception('No Option Set'); | |||
| } | |||
| $this->options['save'] = rtrim($this->options['save'], '/'); | |||
| if ($this->options['save'] !== '') { | |||
| $this->options['save'] .= '/'; | |||
| if (!HelperClass::fileExists($this->options['save'])) { | |||
| mkdir($this->options['save']); | |||
| } | |||
| } | |||
| $this->options['cache'] = $this->options['save'] . rtrim($this->options['cache'], '/'); | |||
| if ($this->options['cache'] !== '') { | |||
| $this->options['cache'] .= '/'; | |||
| if (!HelperClass::fileExists($this->options['cache'])) { | |||
| mkdir($this->options['cache']); | |||
| } | |||
| } | |||
| $caBundleDir = dirname(__FILE__); | |||
| if (HelperClass::isInPhar()) { | |||
| $caBundleDir = dirname($_SERVER["SCRIPT_FILENAME"]) . "/" . $this->options['cache']; | |||
| if (!HelperClass::fileExists($this->options['cache'] . "ca_bundle.crt")) { | |||
| copy(dirname(__FILE__) . "/ca_bundle.crt", $caBundleDir . "ca_bundle.crt"); | |||
| } | |||
| } | |||
| $this->cachedInfo = new CacheOneFile(dirname($_SERVER["SCRIPT_FILENAME"]) . "/" . $this->options['cache'] . $this->options['cacheFile'], $this->options['holdTime']); | |||
| $this->streamContext = stream_context_create( | |||
| array( | |||
| 'http' => array( | |||
| 'header' => "User-Agent: Awesome-Update-My-Self-" . $this->options['name'] . "\r\nAccept: application/vnd.github.v3+json\r\n", | |||
| ), | |||
| 'ssl' => array( | |||
| 'cafile' => $caBundleDir . '/ca_bundle.crt', | |||
| 'verify_peer' => true, | |||
| ), | |||
| ) | |||
| ); | |||
| $this->streamContext2 = stream_context_create( | |||
| array( | |||
| 'http' => array( | |||
| 'header' => "User-Agent: Awesome-Update-My-Self-" . $this->options['name'] . "\r\n", | |||
| ), | |||
| 'ssl' => array( | |||
| 'cafile' => $caBundleDir . '/ca_bundle.crt', | |||
| 'verify_peer' => true, | |||
| ), | |||
| ) | |||
| ); | |||
| $this->allRelease = $this->getRemoteInfos(); | |||
| } | |||
| protected function getRemoteInfos() | |||
| { | |||
| $path = "https://api.github.com/repos/" . $this->options['name'] . "/releases"; | |||
| if ($this->cachedInfo->is()) { | |||
| $fileContent = $this->cachedInfo->get(); | |||
| } else { | |||
| if (!in_array('https', stream_get_wrappers())) { | |||
| if ($this->options["exceptions"]) { | |||
| throw new \Exception("No HTTPS Wrapper Exception"); | |||
| } else { | |||
| return array(); | |||
| } | |||
| } | |||
| $fileContent = @file_get_contents($path, false, $this->streamContext); | |||
| if ($fileContent === false) { | |||
| if ($this->options["exceptions"]) { | |||
| throw new \Exception("No Internet Exception"); | |||
| } else { | |||
| return array(); | |||
| } | |||
| } | |||
| $json = json_decode($fileContent, true); | |||
| if (isset($json['message'])) { | |||
| if ($this->options["exceptions"]) { | |||
| throw new \Exception("API Exception[" . $json['message'] . "]"); | |||
| } else { | |||
| $json = array(); | |||
| } | |||
| } | |||
| if (defined("JSON_PRETTY_PRINT")) { | |||
| $fileContent = json_encode($json, JSON_PRETTY_PRINT); | |||
| } else { | |||
| $fileContent = json_encode($json); | |||
| } | |||
| $this->cachedInfo->set($fileContent); | |||
| return $json; | |||
| } | |||
| return json_decode($fileContent, true); | |||
| } | |||
| public function able() | |||
| { | |||
| if (!in_array('https', stream_get_wrappers())) { | |||
| return false; | |||
| } | |||
| if (empty($this->allRelease)) { | |||
| return false; | |||
| } | |||
| $this->getNewestInfo(); | |||
| if (HelperClass::fileExists($this->options['cache'] . $this->options['versionFile'])) { | |||
| $fileContent = file_get_contents($this->options['cache'] . $this->options['versionFile']); | |||
| $current = json_decode($fileContent, true); | |||
| if (isset($current['id']) && $current['id'] == $this->newestInfo['id']) { | |||
| return false; | |||
| } | |||
| if (isset($current['tag_name']) && $current['tag_name'] == $this->newestInfo['tag_name']) { | |||
| return false; | |||
| } | |||
| } | |||
| return true; | |||
| } | |||
| public function update() | |||
| { | |||
| $newestRelease = $this->getNewestInfo(); | |||
| if ($this->able()) { | |||
| if ($this->download($newestRelease['zipball_url'])) { | |||
| if ($this->unZip()) { | |||
| unlink($this->options['cache'] . $this->options['zipFile']); | |||
| if (defined("JSON_PRETTY_PRINT")) { | |||
| file_put_contents($this->options['cache'] . $this->options['versionFile'], json_encode(array( | |||
| "id" => $newestRelease['id'], | |||
| "tag_name" => $newestRelease['tag_name'] | |||
| ), JSON_PRETTY_PRINT)); | |||
| } else { | |||
| file_put_contents($this->options['cache'] . $this->options['versionFile'], json_encode(array( | |||
| "id" => $newestRelease['id'], | |||
| "tag_name" => $newestRelease['tag_name'] | |||
| ))); | |||
| } | |||
| return true; | |||
| } | |||
| } | |||
| } | |||
| return false; | |||
| } | |||
| protected function download($url) | |||
| { | |||
| $file = @fopen($url, 'r', false, $this->streamContext2); | |||
| if ($file == false) { | |||
| if ($this->options["exceptions"]) { | |||
| throw new \Exception("Download faild Exception"); | |||
| } else { | |||
| return false; | |||
| } | |||
| } | |||
| file_put_contents( | |||
| dirname($_SERVER['SCRIPT_FILENAME']) . "/" . $this->options['cache'] . $this->options['zipFile'], | |||
| $file | |||
| ); | |||
| fclose($file); | |||
| return true; | |||
| } | |||
| protected function unZip() | |||
| { | |||
| $path = dirname($_SERVER['SCRIPT_FILENAME']) . "/" . $this->options['cache'] . $this->options['zipFile']; | |||
| $updateIgnore = array(); | |||
| if (HelperClass::fileExists($this->options['updateignore'])) { | |||
| $updateIgnore = file($this->options['updateignore']); | |||
| foreach ($updateIgnore as &$ignore) { | |||
| $ignore = $this->options['save'] . trim($ignore); | |||
| } | |||
| } | |||
| $zip = new \ZipArchive(); | |||
| if ($zip->open($path) === true) { | |||
| $cutLength = strlen($zip->getNameIndex(0)); | |||
| for ($i = 1; $i < $zip->numFiles; $i++) {//iterate throw the Zip | |||
| $name = $this->options['save'] . substr($zip->getNameIndex($i), $cutLength); | |||
| $do = true; | |||
| foreach ($updateIgnore as $ignore) { | |||
| if (substr($name, 0, strlen($ignore)) == $ignore) { | |||
| $do = false; | |||
| break; | |||
| } | |||
| } | |||
| if ($do) { | |||
| $stat = $zip->statIndex($i); | |||
| if ($stat["crc"] == 0) { | |||
| if (!HelperClass::fileExists($name)) { | |||
| mkdir($name); | |||
| } | |||
| } else { | |||
| copy("zip://" . $path . "#" . $zip->getNameIndex($i), $name); | |||
| } | |||
| } | |||
| } | |||
| $zip->close(); | |||
| return true; | |||
| } else { | |||
| return false; | |||
| } | |||
| } | |||
| public function getCurrentInfo() | |||
| { | |||
| if (isset($this->currentInfo)) { | |||
| return $this->currentInfo; | |||
| } | |||
| $this->currentInfo = null; | |||
| if (HelperClass::fileExists($this->options['cache'] . $this->options['versionFile'])) { | |||
| $fileContent = file_get_contents($this->options['cache'] . $this->options['versionFile']); | |||
| $current = json_decode($fileContent, true); | |||
| foreach ($this->allRelease as $release) { | |||
| if (isset($current['id']) && $current['id'] == $release['id']) { | |||
| $this->currentInfo = $release; | |||
| break; | |||
| } | |||
| if (isset($current['tag_name']) && $current['tag_name'] == $release['tag_name']) { | |||
| $this->currentInfo = $release; | |||
| break; | |||
| } | |||
| } | |||
| } | |||
| return $this->currentInfo; | |||
| } | |||
| public function getNewestInfo() | |||
| { | |||
| if (isset($this->newestInfo)) { | |||
| return $this->newestInfo; | |||
| } | |||
| foreach ($this->allRelease as $release) { | |||
| if (!$this->options['prerelease'] && $release['prerelease']) { | |||
| continue; | |||
| } | |||
| if ($this->options['branch'] !== $release['target_commitish']) { | |||
| continue; | |||
| } | |||
| $this->newestInfo = $release; | |||
| break; | |||
| } | |||
| return $this->newestInfo; | |||
| } | |||
| } | |||
| @ -0,0 +1,36 @@ | |||
| PHP Markdown Lib | |||
| Copyright (c) 2004-2014 Michel Fortin | |||
| <http://michelf.ca/> | |||
| All rights reserved. | |||
| Based on Markdown | |||
| Copyright (c) 2003-2006 John Gruber | |||
| <http://daringfireball.net/> | |||
| All rights reserved. | |||
| Redistribution and use in source and binary forms, with or without | |||
| modification, are permitted provided that the following conditions are | |||
| met: | |||
| * Redistributions of source code must retain the above copyright notice, | |||
| this list of conditions and the following disclaimer. | |||
| * Redistributions in binary form must reproduce the above copyright | |||
| notice, this list of conditions and the following disclaimer in the | |||
| documentation and/or other materials provided with the distribution. | |||
| * Neither the name "Markdown" nor the names of its contributors may | |||
| be used to endorse or promote products derived from this software | |||
| without specific prior written permission. | |||
| This software is provided by the copyright holders and contributors "as | |||
| is" and any express or implied warranties, including, but not limited | |||
| to, the implied warranties of merchantability and fitness for a | |||
| particular purpose are disclaimed. In no event shall the copyright owner | |||
| or contributors be liable for any direct, indirect, incidental, special, | |||
| exemplary, or consequential damages (including, but not limited to, | |||
| procurement of substitute goods or services; loss of use, data, or | |||
| profits; or business interruption) however caused and on any theory of | |||
| liability, whether in contract, strict liability, or tort (including | |||
| negligence or otherwise) arising in any way out of the use of this | |||
| software, even if advised of the possibility of such damage. | |||
| @ -0,0 +1,10 @@ | |||
| <?php | |||
| # Use this file if you cannot use class autoloading. It will include all the | |||
| # files needed for the Markdown parser. | |||
| # | |||
| # Take a look at the PSR-0-compatible class autoloading implementation | |||
| # in the Readme.php file if you want a simple autoloader setup. | |||
| require_once dirname(__FILE__) . '/MarkdownInterface.php'; | |||
| require_once dirname(__FILE__) . '/Markdown.php'; | |||
| @ -0,0 +1,11 @@ | |||
| <?php | |||
| # Use this file if you cannot use class autoloading. It will include all the | |||
| # files needed for the MarkdownExtra parser. | |||
| # | |||
| # Take a look at the PSR-0-compatible class autoloading implementation | |||
| # in the Readme.php file if you want a simple autoloader setup. | |||
| require_once dirname(__FILE__) . '/MarkdownInterface.php'; | |||
| require_once dirname(__FILE__) . '/Markdown.php'; | |||
| require_once dirname(__FILE__) . '/MarkdownExtra.php'; | |||
| @ -0,0 +1,38 @@ | |||
| <?php | |||
| # | |||
| # Markdown Extra - A text-to-HTML conversion tool for web writers | |||
| # | |||
| # PHP Markdown Extra | |||
| # Copyright (c) 2004-2014 Michel Fortin | |||
| # <http://michelf.com/projects/php-markdown/> | |||
| # | |||
| # Original Markdown | |||
| # Copyright (c) 2004-2006 John Gruber | |||
| # <http://daringfireball.net/projects/markdown/> | |||
| # | |||
| namespace Michelf; | |||
| # Just force Michelf/Markdown.php to load. This is needed to load | |||
| # the temporary implementation class. See below for details. | |||
| \Michelf\Markdown::MARKDOWNLIB_VERSION; | |||
| # | |||
| # Markdown Extra Parser Class | |||
| # | |||
| # Note: Currently the implementation resides in the temporary class | |||
| # \Michelf\MarkdownExtra_TmpImpl (in the same file as \Michelf\Markdown). | |||
| # This makes it easier to propagate the changes between the three different | |||
| # packaging styles of PHP Markdown. Once this issue is resolved, the | |||
| # _MarkdownExtra_TmpImpl will disappear and this one will contain the code. | |||
| # | |||
| class MarkdownExtra extends \Michelf\_MarkdownExtra_TmpImpl { | |||
| ### Parser Implementation ### | |||
| # Temporarily, the implemenation is in the _MarkdownExtra_TmpImpl class. | |||
| # See note above. | |||
| } | |||
| @ -0,0 +1,9 @@ | |||
| <?php | |||
| # Use this file if you cannot use class autoloading. It will include all the | |||
| # files needed for the MarkdownInterface interface. | |||
| # | |||
| # Take a look at the PSR-0-compatible class autoloading implementation | |||
| # in the Readme.php file if you want a simple autoloader setup. | |||
| require_once dirname(__FILE__) . '/MarkdownInterface.php'; | |||
| @ -0,0 +1,37 @@ | |||
| <?php | |||
| # | |||
| # Markdown - A text-to-HTML conversion tool for web writers | |||
| # | |||
| # PHP Markdown | |||
| # Copyright (c) 2004-2014 Michel Fortin | |||
| # <http://michelf.com/projects/php-markdown/> | |||
| # | |||
| # Original Markdown | |||
| # Copyright (c) 2004-2006 John Gruber | |||
| # <http://daringfireball.net/projects/markdown/> | |||
| # | |||
| namespace Michelf; | |||
| # | |||
| # Markdown Parser Interface | |||
| # | |||
| interface MarkdownInterface { | |||
| # | |||
| # Initialize the parser and return the result of its transform method. | |||
| # This will work fine for derived classes too. | |||
| # | |||
| public static function defaultTransform($text); | |||
| # | |||
| # Main function. Performs some preprocessing on the input text | |||
| # and pass it through the document gamut. | |||
| # | |||
| public function transform($text); | |||
| } | |||
| ?> | |||
| @ -0,0 +1,305 @@ | |||
| PHP Markdown | |||
| ============ | |||
| PHP Markdown Lib 1.4.1 - 4 May 2013 | |||
| by Michel Fortin | |||
| <http://michelf.ca/> | |||
| based on Markdown by John Gruber | |||
| <http://daringfireball.net/> | |||
| Introduction | |||
| ------------ | |||
| This is a library package that includes the PHP Markdown parser and its | |||
| sibling PHP Markdown Extra with additional features. | |||
| Markdown is a text-to-HTML conversion tool for web writers. Markdown | |||
| allows you to write using an easy-to-read, easy-to-write plain text | |||
| format, then convert it to structurally valid XHTML (or HTML). | |||
| "Markdown" is actually two things: a plain text markup syntax, and a | |||
| software tool, originally written in Perl, that converts the plain text | |||
| markup to HTML. PHP Markdown is a port to PHP of the original Markdown | |||
| program by John Gruber. | |||
| * [Full documentation of the Markdown syntax](<http://daringfireball.net/projects/markdown/>) | |||
| - Daring Fireball (John Gruber) | |||
| * [Markdown Extra syntax additions](<http://michelf.ca/projects/php-markdown/extra/>) | |||
| - Michel Fortin | |||
| Requirement | |||
| ----------- | |||
| This library package requires PHP 5.3 or later. | |||
| Note: The older plugin/library hybrid package for PHP Markdown and | |||
| PHP Markdown Extra is still maintained and will work with PHP 4.0.5 and later. | |||
| Before PHP 5.3.7, pcre.backtrack_limit defaults to 100 000, which is too small | |||
| in many situations. You might need to set it to higher values. Later PHP | |||
| releases defaults to 1 000 000, which is usually fine. | |||
| Usage | |||
| ----- | |||
| This library package is meant to be used with class autoloading. For autoloading | |||
| to work, your project needs have setup a PSR-0-compatible autoloader. See the | |||
| included Readme.php file for a minimal autoloader setup. (If you cannot use | |||
| autoloading, see below.) | |||
| With class autoloading in place, putting the 'Michelf' folder in your | |||
| include path should be enough for this to work: | |||
| use \Michelf\Markdown; | |||
| $my_html = Markdown::defaultTransform($my_text); | |||
| Markdown Extra syntax is also available the same way: | |||
| use \Michelf\MarkdownExtra; | |||
| $my_html = MarkdownExtra::defaultTransform($my_text); | |||
| If you wish to use PHP Markdown with another text filter function | |||
| built to parse HTML, you should filter the text *after* the `transform` | |||
| function call. This is an example with [PHP SmartyPants][psp]: | |||
| use \Michelf\Markdown, \Michelf\SmartyPants; | |||
| $my_html = Markdown::defaultTransform($my_text); | |||
| $my_html = SmartyPants::defaultTransform($my_html); | |||
| All these examples are using the static `defaultTransform` static function | |||
| found inside the parser class. If you want to customize the parser | |||
| configuration, you can also instantiate it directly and change some | |||
| configuration variables: | |||
| use \Michelf\MarkdownExtra; | |||
| $parser = new MarkdownExtra; | |||
| $parser->fn_id_prefix = "post22-"; | |||
| $my_html = $parser->transform($my_text); | |||
| To learn more, see the full list of [configuration variables]. | |||
| [configuration variables]: http://michelf.ca/projects/php-markdown/configuration/ | |||
| ### Usage without an autoloader | |||
| If you cannot use class autoloading, you can still use `include` or `require` | |||
| to access the parser. To load the `\Michelf\Markdown` parser, do it this way: | |||
| require_once 'Michelf/Markdown.inc.php'; | |||
| Or, if you need the `\Michelf\MarkdownExtra` parser: | |||
| require_once 'Michelf/MarkdownExtra.inc.php'; | |||
| While the plain `.php` files depend on autoloading to work correctly, using the | |||
| `.inc.php` files instead will eagerly load the dependencies that would be | |||
| loaded on demand if you were using autoloading. | |||
| Public API and Versioning Policy | |||
| --------------------------------- | |||
| Version numbers are of the form *major*.*minor*.*patch*. | |||
| The public API of PHP Markdown consist of the two parser classes `Markdown` | |||
| and `MarkdownExtra`, their constructors, the `transform` and `defaultTransform` | |||
| functions and their configuration variables. The public API is stable for | |||
| a given major version number. It might get additions when the minor version | |||
| number increments. | |||
| **Protected members are not considered public API.** This is unconventional | |||
| and deserves an explanation. Incrementing the major version number every time | |||
| the underlying implementation of something changes is going to give | |||
| nonessential version numbers for the vast majority of people who just use the | |||
| parser. Protected members are meant to create parser subclasses that behave in | |||
| different ways. Very few people create parser subclasses. I don't want to | |||
| discourage it by making everything private, but at the same time I can't | |||
| guarantee any stable hook between versions if you use protected members. | |||
| **Syntax changes** will increment the minor number for new features, and the | |||
| patch number for small corrections. A *new feature* is something that needs a | |||
| change in the syntax documentation. Note that since PHP Markdown Lib includes | |||
| two parsers, a syntax change for either of them will increment the minor | |||
| number. Also note that there is nothing perfectly backward-compatible with the | |||
| Markdown syntax: all inputs are always valid, so new features always replace | |||
| something that was previously legal, although generally nonsensical to do. | |||
| Bugs | |||
| ---- | |||
| To file bug reports please send email to: | |||
| <michel.fortin@michelf.ca> | |||
| Please include with your report: (1) the example input; (2) the output you | |||
| expected; (3) the output PHP Markdown actually produced. | |||
| If you have a problem where Markdown gives you an empty result, first check | |||
| that the backtrack limit is not too low by running `php --info | grep pcre`. | |||
| See Installation and Requirement above for details. | |||
| Development and Testing | |||
| ----------------------- | |||
| Pull requests for fixing bugs are welcome. Proposed new features are | |||
| going meticulously reviewed -- taking into account backward compatibility, | |||
| potential side effects, and future extensibility -- before deciding on | |||
| acceptance or rejection. | |||
| If you make a pull request that includes changes to the parser please add | |||
| tests for what is being changed to [MDTest][] and make a pull request there | |||
| too. | |||
| [MDTest]: https://github.com/michelf/mdtest/ | |||
| Donations | |||
| --------- | |||
| If you wish to make a donation that will help me devote more time to | |||
| PHP Markdown, please visit [michelf.ca/donate] or send Bitcoin to | |||
| [1HiuX34czvVPPdhXbUAsAu7pZcesniDCGH]. | |||
| [michelf.ca/donate]: https://michelf.ca/donate/#!Thanks%20for%20PHP%20Markdown | |||
| [1HiuX34czvVPPdhXbUAsAu7pZcesniDCGH]: bitcoin:1HiuX34czvVPPdhXbUAsAu7pZcesniDCGH | |||
| Version History | |||
| --------------- | |||
| PHP Markdown Lib 1.4.1 (4 May 2014) | |||
| * The HTML block parser will now treat `<figure>` as a block-level element | |||
| (as it should) and no longer wrap it in `<p>` or parse it's content with | |||
| the as Markdown syntax (although with Extra you can use `markdown="1"` | |||
| if you wish to use the Markdown syntax inside it). | |||
| * The content of `<style>` elements will now be left alone, its content | |||
| won't be interpreted as Markdown. | |||
| * Corrected an bug where some inline links with spaces in them would not | |||
| work even when surounded with angle brackets: | |||
| [link](<s p a c e s>) | |||
| * Fixed an issue where email addresses with quotes in them would not always | |||
| have the quotes escaped in the link attribute, causing broken links (and | |||
| invalid HTML). | |||
| * Fixed the case were a link definition following a footnote definition would | |||
| be swallowed by the footnote unless it was separated by a blank line. | |||
| PHP Markdown Lib 1.4.0 (29 Nov 2013) | |||
| * Added support for the `tel:` URL scheme in automatic links. | |||
| <tel:+1-111-111-1111> | |||
| It gets converted to this (note the `tel:` prefix becomes invisible): | |||
| <a href="tel:+1-111-111-1111">+1-111-111-1111</a> | |||
| * Added backtick fenced code blocks to MarkdownExtra, originally from | |||
| Github-Flavored Markdown. | |||
| * Added an interface called MarkdownInterface implemented by both | |||
| the Markdown and MarkdownExtra parsers. You can use the interface if | |||
| you want to create a mockup parser object for unit testing. | |||
| * For those of you who cannot use class autoloading, you can now | |||
| include `Michelf/Markdown.inc.php` or `Michelf/MarkdownExtra.inc.php` (note | |||
| the `.inc.php` extension) to automatically include other files required | |||
| by the parser. | |||
| PHP Markdown Lib 1.3 (11 Apr 2013) | |||
| This is the first release of PHP Markdown Lib. This package requires PHP | |||
| version 5.3 or later and is designed to work with PSR-0 autoloading and, | |||
| optionally with Composer. Here is a list of the changes since | |||
| PHP Markdown Extra 1.2.6: | |||
| * Plugin interface for WordPress and other systems is no longer present in | |||
| the Lib package. The classic package is still available if you need it: | |||
| <http://michelf.ca/projects/php-markdown/classic/> | |||
| * Added `public` and `protected` protection attributes, plus a section about | |||
| what is "public API" and what isn't in the Readme file. | |||
| * Changed HTML output for footnotes: now instead of adding `rel` and `rev` | |||
| attributes, footnotes links have the class name `footnote-ref` and | |||
| backlinks `footnote-backref`. | |||
| * Fixed some regular expressions to make PCRE not shout warnings about POSIX | |||
| collation classes (dependent on your version of PCRE). | |||
| * Added optional class and id attributes to images and links using the same | |||
| syntax as for headers: | |||
| [link](url){#id .class} | |||
| {#id .class} | |||
| It work too for reference-style links and images. In this case you need | |||
| to put those attributes at the reference definition: | |||
| [link][linkref] or [linkref] | |||
| ![img][linkref] | |||
| [linkref]: url "optional title" {#id .class} | |||
| * Fixed a PHP notice message triggered when some table column separator | |||
| markers are missing on the separator line below column headers. | |||
| * Fixed a small mistake that could cause the parser to retain an invalid | |||
| state related to parsing links across multiple runs. This was never | |||
| observed (that I know of), but it's still worth fixing. | |||
| Copyright and License | |||
| --------------------- | |||
| PHP Markdown Lib | |||
| Copyright (c) 2004-2014 Michel Fortin | |||
| <http://michelf.ca/> | |||
| All rights reserved. | |||
| Based on Markdown | |||
| Copyright (c) 2003-2005 John Gruber | |||
| <http://daringfireball.net/> | |||
| All rights reserved. | |||
| Redistribution and use in source and binary forms, with or without | |||
| modification, are permitted provided that the following conditions are | |||
| met: | |||
| * Redistributions of source code must retain the above copyright | |||
| notice, this list of conditions and the following disclaimer. | |||
| * Redistributions in binary form must reproduce the above copyright | |||
| notice, this list of conditions and the following disclaimer in the | |||
| documentation and/or other materials provided with the | |||
| distribution. | |||
| * Neither the name "Markdown" nor the names of its contributors may | |||
| be used to endorse or promote products derived from this software | |||
| without specific prior written permission. | |||
| This software is provided by the copyright holders and contributors "as | |||
| is" and any express or implied warranties, including, but not limited | |||
| to, the implied warranties of merchantability and fitness for a | |||
| particular purpose are disclaimed. In no event shall the copyright owner | |||
| or contributors be liable for any direct, indirect, incidental, special, | |||
| exemplary, or consequential damages (including, but not limited to, | |||
| procurement of substitute goods or services; loss of use, data, or | |||
| profits; or business interruption) however caused and on any theory of | |||
| liability, whether in contract, strict liability, or tort (including | |||
| negligence or otherwise) arising in any way out of the use of this | |||
| software, even if advised of the possibility of such damage. | |||
| @ -0,0 +1,31 @@ | |||
| <?php | |||
| # This file passes the content of the Readme.md file in the same directory | |||
| # through the Markdown filter. You can adapt this sample code in any way | |||
| # you like. | |||
| # Install PSR-0-compatible class autoloader | |||
| spl_autoload_register(function($class){ | |||
| require preg_replace('{\\\\|_(?!.*\\\\)}', DIRECTORY_SEPARATOR, ltrim($class, '\\')).'.php'; | |||
| }); | |||
| # Get Markdown class | |||
| use \Michelf\Markdown; | |||
| # Read file and pass content through the Markdown parser | |||
| $text = file_get_contents('Readme.md'); | |||
| $html = Markdown::defaultTransform($text); | |||
| ?> | |||
| <!DOCTYPE html> | |||
| <html> | |||
| <head> | |||
| <title>PHP Markdown Lib - Readme</title> | |||
| </head> | |||
| <body> | |||
| <?php | |||
| # Put HTML content in the document | |||
| echo $html; | |||
| ?> | |||
| </body> | |||
| </html> | |||
| @ -0,0 +1,31 @@ | |||
| { | |||
| "name": "michelf/php-markdown", | |||
| "type": "library", | |||
| "description": "PHP Markdown", | |||
| "homepage": "http://michelf.ca/projects/php-markdown/", | |||
| "keywords": ["markdown"], | |||
| "license": "BSD-3-Clause", | |||
| "authors": [ | |||
| { | |||
| "name": "Michel Fortin", | |||
| "email": "michel.fortin@michelf.ca", | |||
| "homepage": "http://michelf.ca/", | |||
| "role": "Developer" | |||
| }, | |||
| { | |||
| "name": "John Gruber", | |||
| "homepage": "http://daringfireball.net/" | |||
| } | |||
| ], | |||
| "require": { | |||
| "php": ">=5.3.0" | |||
| }, | |||
| "autoload": { | |||
| "psr-0": { "Michelf": "" } | |||
| }, | |||
| "extra": { | |||
| "branch-alias": { | |||
| "dev-lib": "1.4.x-dev" | |||
| } | |||
| } | |||
| } | |||
| @ -0,0 +1,11 @@ | |||
| language: php | |||
| php: | |||
| - 5.3 | |||
| - 5.4 | |||
| before_script: | |||
| - cd Tests | |||
| - wget http://getcomposer.org/composer.phar | |||
| - php composer.phar install | |||
| script: ./phpunit --coverage-text --configuration phpunit.xml.dist | |||
| @ -0,0 +1,96 @@ | |||
| # \Suin\RSSWriter | |||
| `\Suin\RSSWriter` is yet another simple RSS writer library for PHP 5.3 or later. This component is Licensed under MIT license. | |||
| This library can also be used to publish Podcasts. | |||
| The build status of the current master branch is tracked by Travis CI: [](http://travis-ci.org/suin/php-rss-writer) | |||
| Implementation: | |||
| ```php | |||
| <?php | |||
| $feed = new Feed(); | |||
| $channel = new Channel(); | |||
| $channel | |||
| ->title("Channel Title") | |||
| ->description("Channel Description") | |||
| ->url('http://blog.example.com') | |||
| ->appendTo($feed); | |||
| // RSS item | |||
| $item = new Item(); | |||
| $item | |||
| ->title("Blog Entry Title") | |||
| ->description("<div>Blog body</div>") | |||
| ->url('http://blog.example.com/2012/08/21/blog-entry/') | |||
| ->appendTo($channel); | |||
| // Podcast item | |||
| $item = new Item(); | |||
| $item | |||
| ->title("Some Podcast Entry") | |||
| ->description("<div>Podcast body</div>") | |||
| ->url('http://podcast.example.com/2012/08/21/podcast-entry/') | |||
| ->enclosure('http://link-to-audio-file.com/2013/08/21/podcast.mp3', 4889, 'audio/mpeg') | |||
| ->appendTo($channel); | |||
| echo $feed; | |||
| ``` | |||
| Output: | |||
| ```xml | |||
| <?xml version="1.0"?> | |||
| <rss version="2.0"> | |||
| <channel> | |||
| <title>Channel Title</title> | |||
| <link>http://blog.example.com</link> | |||
| <description>Channel Description</description> | |||
| <item> | |||
| <title>Blog Entry Title</title> | |||
| <link>http://blog.example.com/2012/08/21/blog-entry/</link> | |||
| <description><div>Blog body</div></description> | |||
| </item> | |||
| </channel> | |||
| </rss> | |||
| ``` | |||
| ## Installation | |||
| You can install via Composer. | |||
| At first create `composer.json` file: | |||
| ```json | |||
| { | |||
| "require": { | |||
| "suin/php-rss-writer": ">=1.0" | |||
| } | |||
| } | |||
| ``` | |||
| Run composer to install. | |||
| ``` | |||
| $ composer install | |||
| ``` | |||
| Finally, include `vendor/autoload.php` in your product. | |||
| ``` | |||
| require_once 'vendor/autoload.php'; | |||
| ``` | |||
| ## How to Use | |||
| `example.php` is an example usage of RSSWriter. | |||
| If you want to know APIs, please see `FeedInterface`, `ChannelInterface` and `ItemInterface`. | |||
| ## License | |||
| MIT license | |||
| @ -0,0 +1,189 @@ | |||
| <?php | |||
| namespace Suin\RSSWriter; | |||
| use \Suin\RSSWriter\SimpleXMLElement; | |||
| class Channel implements \Suin\RSSWriter\ChannelInterface | |||
| { | |||
| /** @var string */ | |||
| protected $title; | |||
| /** @var string */ | |||
| protected $url; | |||
| /** @var string */ | |||
| protected $description; | |||
| /** @var string */ | |||
| protected $language; | |||
| /** @var string */ | |||
| protected $copyright; | |||
| /** @var int */ | |||
| protected $pubDate; | |||
| /** @var int */ | |||
| protected $lastBuildDate; | |||
| /** @var int */ | |||
| protected $ttl; | |||
| /** @var \Suin\RSSWriter\ItemInterface[] */ | |||
| protected $items = array(); | |||
| /** | |||
| * Set channel title | |||
| * @param string $title | |||
| * @return $this | |||
| */ | |||
| public function title($title) | |||
| { | |||
| $this->title = $title; | |||
| return $this; | |||
| } | |||
| /** | |||
| * Set channel URL | |||
| * @param string $url | |||
| * @return $this | |||
| */ | |||
| public function url($url) | |||
| { | |||
| $this->url = $url; | |||
| return $this; | |||
| } | |||
| /** | |||
| * Set channel description | |||
| * @param string $description | |||
| * @return $this | |||
| */ | |||
| public function description($description) | |||
| { | |||
| $this->description = $description; | |||
| return $this; | |||
| } | |||
| /** | |||
| * Set ISO639 language code | |||
| * | |||
| * The language the channel is written in. This allows aggregators to group all | |||
| * Italian language sites, for example, on a single page. A list of allowable | |||
| * values for this element, as provided by Netscape, is here. You may also use | |||
| * values defined by the W3C. | |||
| * | |||
| * @param string $language | |||
| * @return $this | |||
| */ | |||
| public function language($language) | |||
| { | |||
| $this->language = $language; | |||
| return $this; | |||
| } | |||
| /** | |||
| * Set channel copyright | |||
| * @param string $copyright | |||
| * @return $this | |||
| */ | |||
| public function copyright($copyright) | |||
| { | |||
| $this->copyright = $copyright; | |||
| return $this; | |||
| } | |||
| /** | |||
| * Set channel published date | |||
| * @param int $pubDate Unix timestamp | |||
| * @return $this | |||
| */ | |||
| public function pubDate($pubDate) | |||
| { | |||
| $this->pubDate = $pubDate; | |||
| return $this; | |||
| } | |||
| /** | |||
| * Set channel last build date | |||
| * @param int $lastBuildDate Unix timestamp | |||
| * @return $this | |||
| */ | |||
| public function lastBuildDate($lastBuildDate) | |||
| { | |||
| $this->lastBuildDate = $lastBuildDate; | |||
| return $this; | |||
| } | |||
| /** | |||
| * Set channel ttl (minutes) | |||
| * @param int $ttl | |||
| * @return $this | |||
| */ | |||
| public function ttl($ttl) | |||
| { | |||
| $this->ttl = $ttl; | |||
| return $this; | |||
| } | |||
| /** | |||
| * Add item object | |||
| * @param \Suin\RSSWriter\ItemInterface $item | |||
| * @return $this | |||
| */ | |||
| public function addItem(ItemInterface $item) | |||
| { | |||
| $this->items[] = $item; | |||
| return $this; | |||
| } | |||
| /** | |||
| * Append to feed | |||
| * @param \Suin\RSSWriter\FeedInterface $feed | |||
| * @return $this | |||
| */ | |||
| public function appendTo(FeedInterface $feed) | |||
| { | |||
| $feed->addChannel($this); | |||
| return $this; | |||
| } | |||
| /** | |||
| * Return XML object | |||
| * @return \Suin\RSSWriter\SimpleXMLElement | |||
| */ | |||
| public function asXML() | |||
| { | |||
| $xml = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8" ?><channel></channel>', LIBXML_NOERROR|LIBXML_ERR_NONE|LIBXML_ERR_FATAL); | |||
| $xml->addChild('title', $this->title); | |||
| $xml->addChild('link', $this->url); | |||
| $xml->addChild('description', $this->description); | |||
| if ( $this->language !== null ) | |||
| { | |||
| $xml->addChild('language', $this->language); | |||
| } | |||
| if ( $this->copyright !== null ) | |||
| { | |||
| $xml->addChild('copyright', $this->copyright); | |||
| } | |||
| if ( $this->pubDate !== null ) | |||
| { | |||
| $xml->addChild('pubDate', date(DATE_RSS, $this->pubDate)); | |||
| } | |||
| if ( $this->lastBuildDate !== null ) | |||
| { | |||
| $xml->addChild('lastBuildDate', date(DATE_RSS, $this->lastBuildDate)); | |||
| } | |||
| if ( $this->ttl !== null ) | |||
| { | |||
| $xml->addChild('ttl', $this->ttl); | |||
| } | |||
| foreach ( $this->items as $item ) | |||
| { | |||
| $toDom = dom_import_simplexml($xml); | |||
| $fromDom = dom_import_simplexml($item->asXML()); | |||
| $toDom->appendChild($toDom->ownerDocument->importNode($fromDom, true)); | |||
| } | |||
| return $xml; | |||
| } | |||
| } | |||
| @ -0,0 +1,91 @@ | |||
| <?php | |||
| namespace Suin\RSSWriter; | |||
| use \Suin\RSSWriter\FeedInterface; | |||
| use \Suin\RSSWriter\ItemInterface; | |||
| interface ChannelInterface | |||
| { | |||
| /** | |||
| * Set channel title | |||
| * @param string $title | |||
| * @return $this | |||
| */ | |||
| public function title($title); | |||
| /** | |||
| * Set channel URL | |||
| * @param string $url | |||
| * @return $this | |||
| */ | |||
| public function url($url); | |||
| /** | |||
| * Set channel description | |||
| * @param string $description | |||
| * @return $this | |||
| */ | |||
| public function description($description); | |||
| /** | |||
| * Set ISO639 language code | |||
| * | |||
| * The language the channel is written in. This allows aggregators to group all | |||
| * Italian language sites, for example, on a single page. A list of allowable | |||
| * values for this element, as provided by Netscape, is here. You may also use | |||
| * values defined by the W3C. | |||
| * | |||
| * @param string $language | |||
| * @return $this | |||
| */ | |||
| public function language($language); | |||
| /** | |||
| * Set channel copyright | |||
| * @param string $copyright | |||
| * @return $this | |||
| */ | |||
| public function copyright($copyright); | |||
| /** | |||
| * Set channel published date | |||
| * @param int $pubDate Unix timestamp | |||
| * @return $this | |||
| */ | |||
| public function pubDate($pubDate); | |||
| /** | |||
| * Set channel last build date | |||
| * @param int $lastBuildDate Unix timestamp | |||
| * @return $this | |||
| */ | |||
| public function lastBuildDate($lastBuildDate); | |||
| /** | |||
| * Set channel ttl (minutes) | |||
| * @param int $ttl | |||
| * @return $this | |||
| */ | |||
| public function ttl($ttl); | |||
| /** | |||
| * Add item object | |||
| * @param \Suin\RSSWriter\ItemInterface $item | |||
| * @return $this | |||
| */ | |||
| public function addItem(ItemInterface $item); | |||
| /** | |||
| * Append to feed | |||
| * @param \Suin\RSSWriter\FeedInterface $feed | |||
| * @return $this | |||
| */ | |||
| public function appendTo(FeedInterface $feed); | |||
| /** | |||
| * Return XML object | |||
| * @return \Suin\RSSWriter\SimpleXMLElement | |||
| */ | |||
| public function asXML(); | |||
| } | |||
| @ -0,0 +1,54 @@ | |||
| <?php | |||
| namespace Suin\RSSWriter; | |||
| use \DOMDocument; | |||
| use \Suin\RSSWriter\ChannelInterface; | |||
| use \Suin\RSSWriter\SimpleXMLElement; | |||
| class Feed implements \Suin\RSSWriter\FeedInterface | |||
| { | |||
| /** @var \Suin\RSSWriter\ChannelInterface[] */ | |||
| protected $channels = array(); | |||
| /** | |||
| * Add channel | |||
| * @param \Suin\RSSWriter\ChannelInterface $channel | |||
| * @return $this | |||
| */ | |||
| public function addChannel(ChannelInterface $channel) | |||
| { | |||
| $this->channels[] = $channel; | |||
| return $this; | |||
| } | |||
| /** | |||
| * Render XML | |||
| * @return string | |||
| */ | |||
| public function render() | |||
| { | |||
| $xml = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8" ?><rss version="2.0" />', LIBXML_NOERROR|LIBXML_ERR_NONE|LIBXML_ERR_FATAL); | |||
| foreach ( $this->channels as $channel ) | |||
| { | |||
| $toDom = dom_import_simplexml($xml); | |||
| $fromDom = dom_import_simplexml($channel->asXML()); | |||
| $toDom->appendChild($toDom->ownerDocument->importNode($fromDom, true)); | |||
| } | |||
| $dom = new DOMDocument('1.0', 'UTF-8'); | |||
| $dom->appendChild($dom->importNode(dom_import_simplexml($xml), true)); | |||
| $dom->formatOutput = true; | |||
| return $dom->saveXML(); | |||
| } | |||
| /** | |||
| * Render XML | |||
| * @return string | |||
| */ | |||
| public function __toString() | |||
| { | |||
| return $this->render(); | |||
| } | |||
| } | |||
| @ -0,0 +1,27 @@ | |||
| <?php | |||
| namespace Suin\RSSWriter; | |||
| use \Suin\RSSWriter\ChannelInterface; | |||
| interface FeedInterface | |||
| { | |||
| /** | |||
| * Add channel | |||
| * @param \Suin\RSSWriter\ChannelInterface $channel | |||
| * @return $thisJ | |||
| */ | |||
| public function addChannel(ChannelInterface $channel); | |||
| /** | |||
| * Render XML | |||
| * @return string | |||
| */ | |||
| public function render(); | |||
| /** | |||
| * Render XML | |||
| * @return string | |||
| */ | |||
| public function __toString(); | |||
| } | |||
| @ -0,0 +1,169 @@ | |||
| <?php | |||
| namespace Suin\RSSWriter; | |||
| use \Suin\RSSWriter\SimpleXMLElement; | |||
| class Item implements \Suin\RSSWriter\ItemInterface | |||
| { | |||
| /** @var string */ | |||
| protected $title; | |||
| /** @var string */ | |||
| protected $url; | |||
| /** @var string */ | |||
| protected $description; | |||
| /** @var array */ | |||
| protected $categories = array(); | |||
| /** @var string */ | |||
| protected $guid; | |||
| /** @var bool */ | |||
| protected $isPermalink; | |||
| /** @var int */ | |||
| protected $pubDate; | |||
| /** @var array */ | |||
| protected $enclosure; | |||
| /** | |||
| * Set item title | |||
| * @param string $title | |||
| * @return $this | |||
| */ | |||
| public function title($title) | |||
| { | |||
| $this->title = $title; | |||
| return $this; | |||
| } | |||
| /** | |||
| * Set item URL | |||
| * @param string $url | |||
| * @return $this | |||
| */ | |||
| public function url($url) | |||
| { | |||
| $this->url = $url; | |||
| return $this; | |||
| } | |||
| /** | |||
| * Set item description | |||
| * @param string $description | |||
| * @return $this | |||
| */ | |||
| public function description($description) | |||
| { | |||
| $this->description = $description; | |||
| return $this; | |||
| } | |||
| /** | |||
| * Set item category | |||
| * @param string $name Category name | |||
| * @param string $domain Category URL | |||
| * @return $this | |||
| */ | |||
| public function category($name, $domain = null) | |||
| { | |||
| $this->categories[] = array($name, $domain); | |||
| return $this; | |||
| } | |||
| /** | |||
| * Set GUID | |||
| * @param string $guid | |||
| * @param bool $isPermalink | |||
| * @return $this | |||
| */ | |||
| public function guid($guid, $isPermalink = false) | |||
| { | |||
| $this->guid = $guid; | |||
| $this->isPermalink = $isPermalink; | |||
| return $this; | |||
| } | |||
| /** | |||
| * Set published date | |||
| * @param int $pubDate Unix timestamp | |||
| * @return $this | |||
| */ | |||
| public function pubDate($pubDate) | |||
| { | |||
| $this->pubDate = $pubDate; | |||
| return $this; | |||
| } | |||
| /** | |||
| * Set enclosure | |||
| * @param var $url Url to media file | |||
| * @param int $length Length in bytes of the media file | |||
| * @param var $type Media type, default is audio/mpeg | |||
| * @return $this | |||
| */ | |||
| public function enclosure($url, $length = 0, $type = 'audio/mpeg') | |||
| { | |||
| $this->enclosure = array('url' => $url, 'length' => $length, 'type' => $type); | |||
| return $this; | |||
| } | |||
| /** | |||
| * Append item to the channel | |||
| * @param \Suin\RSSWriter\ChannelInterface $channel | |||
| * @return $this | |||
| */ | |||
| public function appendTo(ChannelInterface $channel) | |||
| { | |||
| $channel->addItem($this); | |||
| return $this; | |||
| } | |||
| /** | |||
| * Return XML object | |||
| * @return \Suin\RSSWriter\SimpleXMLElement | |||
| */ | |||
| public function asXML() | |||
| { | |||
| $xml = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8" ?><item></item>', LIBXML_NOERROR|LIBXML_ERR_NONE|LIBXML_ERR_FATAL); | |||
| $xml->addChild('title', $this->title); | |||
| $xml->addChild('link', $this->url); | |||
| $xml->addChild('description', $this->description); | |||
| foreach ( $this->categories as $category ) | |||
| { | |||
| $element = $xml->addChild('category', $category[0]); | |||
| if ( isset($category[1]) ) | |||
| { | |||
| $element->addAttribute('domain', $category[1]); | |||
| } | |||
| } | |||
| if ( $this->guid ) | |||
| { | |||
| $guid = $xml->addChild('guid', $this->guid); | |||
| if ( $this->isPermalink ) | |||
| { | |||
| $guid->addAttribute('isPermaLink', 'true'); | |||
| } | |||
| } | |||
| if ( $this->pubDate !== null ) | |||
| { | |||
| $xml->addChild('pubDate', date(DATE_RSS, $this->pubDate)); | |||
| } | |||
| if (is_array($this->enclosure) && (count($this->enclosure) == 3)) | |||
| { | |||
| $element = $xml->addChild('enclosure'); | |||
| $element->addAttribute('url', $this->enclosure['url']); | |||
| $element->addAttribute('type', $this->enclosure['type']); | |||
| if ($this->enclosure['length']) | |||
| { | |||
| $element->addAttribute('length', $this->enclosure['length']); | |||
| } | |||
| } | |||
| return $xml; | |||
| } | |||
| } | |||
| @ -0,0 +1,75 @@ | |||
| <?php | |||
| namespace Suin\RSSWriter; | |||
| use \Suin\RSSWriter\ChannelInterface; | |||
| use \Suin\RSSWriter\SimpleXMLElement; | |||
| interface ItemInterface | |||
| { | |||
| /** | |||
| * Set item title | |||
| * @param string $title | |||
| * @return $this | |||
| */ | |||
| public function title($title); | |||
| /** | |||
| * Set item URL | |||
| * @param string $url | |||
| * @return $this | |||
| */ | |||
| public function url($url); | |||
| /** | |||
| * Set item description | |||
| * @param string $description | |||
| * @return $this | |||
| */ | |||
| public function description($description); | |||
| /** | |||
| * Set item category | |||
| * @param string $name Category name | |||
| * @param string $domain Category URL | |||
| * @return $this | |||
| */ | |||
| public function category($name, $domain = null); | |||
| /** | |||
| * Set GUID | |||
| * @param string $guid | |||
| * @param bool $isPermalink | |||
| * @return $this | |||
| */ | |||
| public function guid($guid, $isPermalink = false); | |||
| /** | |||
| * Set published date | |||
| * @param int $pubDate Unix timestamp | |||
| * @return $this | |||
| */ | |||
| public function pubDate($pubDate); | |||
| /** | |||
| * Set enclosure | |||
| * @param var $url Url to media file | |||
| * @param int $length Length in bytes of the media file | |||
| * @param var $type Media type, default is audio/mpeg | |||
| * @return $this | |||
| */ | |||
| public function enclosure($url, $length = 0, $type = 'audio/mpeg'); | |||
| /** | |||
| * Append item to the channel | |||
| * @param \Suin\RSSWriter\ChannelInterface $channel | |||
| * @return $this | |||
| */ | |||
| public function appendTo(ChannelInterface $channel); | |||
| /** | |||
| * Return XML object | |||
| * @return \Suin\RSSWriter\SimpleXMLElement | |||
| */ | |||
| public function asXML(); | |||
| } | |||
| @ -0,0 +1,16 @@ | |||
| <?php | |||
| namespace Suin\RSSWriter; | |||
| class SimpleXMLElement extends \SimpleXMLElement | |||
| { | |||
| public function addChild($name, $value = null, $namespace = null) | |||
| { | |||
| if ( $value !== null and is_string($value) === true ) | |||
| { | |||
| $value = str_replace('&', '&', $value); | |||
| } | |||
| return parent::addChild($name, $value, $namespace); | |||
| } | |||
| } | |||
| @ -0,0 +1,8 @@ | |||
| <?php | |||
| // For composer | |||
| require_once 'Vendor/autoload.php'; | |||
| // Load test target classes | |||
| spl_autoload_register(function($c) { @include_once strtr($c, '\\_', '//').'.php'; }); | |||
| set_include_path(get_include_path() . PATH_SEPARATOR . dirname(__DIR__).'/Source'); | |||
| @ -0,0 +1,28 @@ | |||
| # How to Test | |||
| ## Installation | |||
| Install [composer](https://github.com/composer/composer) to your ~/bin: | |||
| ```sh | |||
| $ curl -s http://getcomposer.org/installer | php | |||
| ``` | |||
| Run composer and install depending packages: | |||
| ```sh | |||
| $ composer.phar install | |||
| ``` | |||
| ## Executing Tests | |||
| Run phpunit: | |||
| ```sh | |||
| $ ./phpunit | |||
| ``` | |||
| ## View Reports | |||
| If you want to see code coverages, open Coverage/index.html. | |||
| @ -0,0 +1,252 @@ | |||
| <?php | |||
| namespace Suin\RSSWriter; | |||
| class ChannelTest extends \XoopsUnit\TestCase | |||
| { | |||
| private $itemInterface = '\Suin\RSSWriter\ItemInterface'; | |||
| private $feedInterface = '\Suin\RSSWriter\FeedInterface'; | |||
| public function testTitle() | |||
| { | |||
| $title = uniqid(); | |||
| $channel = new Channel(); | |||
| $this->assertSame($channel, $channel->title($title)); | |||
| $this->assertAttributeSame($title, 'title', $channel); | |||
| } | |||
| public function testUrl() | |||
| { | |||
| $url = uniqid(); | |||
| $channel = new Channel(); | |||
| $this->assertSame($channel, $channel->url($url)); | |||
| $this->assertAttributeSame($url, 'url', $channel); | |||
| } | |||
| public function testDescription() | |||
| { | |||
| $description = uniqid(); | |||
| $channel = new Channel(); | |||
| $this->assertSame($channel, $channel->description($description)); | |||
| $this->assertAttributeSame($description, 'description', $channel); | |||
| } | |||
| public function testLanguage() | |||
| { | |||
| $language = uniqid(); | |||
| $channel = new Channel(); | |||
| $this->assertSame($channel, $channel->language($language)); | |||
| $this->assertAttributeSame($language, 'language', $channel); | |||
| } | |||
| public function testCopyright() | |||
| { | |||
| $copyright = uniqid(); | |||
| $channel = new Channel(); | |||
| $this->assertSame($channel, $channel->copyright($copyright)); | |||
| $this->assertAttributeSame($copyright, 'copyright', $channel); | |||
| } | |||
| public function testPubDate() | |||
| { | |||
| $pubDate = mt_rand(0, 9999999); | |||
| $channel = new Channel(); | |||
| $this->assertSame($channel, $channel->pubDate($pubDate)); | |||
| $this->assertAttributeSame($pubDate, 'pubDate', $channel); | |||
| } | |||
| public function testLastBuildDate() | |||
| { | |||
| $lastBuildDate = mt_rand(0, 9999999); | |||
| $channel = new Channel(); | |||
| $this->assertSame($channel, $channel->lastBuildDate($lastBuildDate)); | |||
| $this->assertAttributeSame($lastBuildDate, 'lastBuildDate', $channel); | |||
| } | |||
| public function testTtl() | |||
| { | |||
| $ttl = mt_rand(0, 99999999); | |||
| $channel = new Channel(); | |||
| $this->assertSame($channel, $channel->ttl($ttl)); | |||
| $this->assertAttributeSame($ttl, 'ttl', $channel); | |||
| } | |||
| public function testAddItem() | |||
| { | |||
| $item = $this->getMock($this->itemInterface); | |||
| $channel = new Channel(); | |||
| $this->assertSame($channel, $channel->addItem($item)); | |||
| $this->assertAttributeSame(array($item), 'items', $channel); | |||
| } | |||
| public function testAppendTo() | |||
| { | |||
| $channel = new Channel(); | |||
| $feed = $this->getMock($this->feedInterface); | |||
| $feed->expects($this->once())->method('addChannel')->with($channel); | |||
| $this->assertSame($channel, $channel->appendTo($feed)); | |||
| } | |||
| /** | |||
| * @param $expect | |||
| * @param array $data | |||
| * @dataProvider dataForAsXML | |||
| */ | |||
| public function testAsXML($expect, array $data) | |||
| { | |||
| $data = (object) $data; | |||
| $channel = new Channel(); | |||
| foreach ( $data as $key => $value ) | |||
| { | |||
| $this->reveal($channel)->attr($key, $value); | |||
| } | |||
| $this->assertXmlStringEqualsXmlString($expect, $channel->asXML()->asXML()); | |||
| } | |||
| public static function dataForAsXML() | |||
| { | |||
| $now = time(); | |||
| $nowString = date(DATE_RSS, $now); | |||
| return array( | |||
| array( | |||
| " | |||
| <channel> | |||
| <title>GoUpstate.com News Headlines</title> | |||
| <link>http://www.goupstate.com/</link> | |||
| <description>The latest news from GoUpstate.com, a Spartanburg Herald-Journal Web site.</description> | |||
| </channel> | |||
| ", | |||
| array( | |||
| 'title' => "GoUpstate.com News Headlines", | |||
| 'url' => 'http://www.goupstate.com/', | |||
| 'description' => "The latest news from GoUpstate.com, a Spartanburg Herald-Journal Web site.", | |||
| ) | |||
| ), | |||
| array( | |||
| " | |||
| <channel> | |||
| <title>GoUpstate.com News Headlines</title> | |||
| <link>http://www.goupstate.com/</link> | |||
| <description>The latest news from GoUpstate.com, a Spartanburg Herald-Journal Web site.</description> | |||
| <language>en-us</language> | |||
| </channel> | |||
| ", | |||
| array( | |||
| 'title' => "GoUpstate.com News Headlines", | |||
| 'url' => 'http://www.goupstate.com/', | |||
| 'description' => "The latest news from GoUpstate.com, a Spartanburg Herald-Journal Web site.", | |||
| 'language' => 'en-us', | |||
| ) | |||
| ), | |||
| array( | |||
| " | |||
| <channel> | |||
| <title>GoUpstate.com News Headlines</title> | |||
| <link>http://www.goupstate.com/</link> | |||
| <description>The latest news from GoUpstate.com, a Spartanburg Herald-Journal Web site.</description> | |||
| <pubDate>{$nowString}</pubDate> | |||
| </channel> | |||
| ", | |||
| array( | |||
| 'title' => "GoUpstate.com News Headlines", | |||
| 'url' => 'http://www.goupstate.com/', | |||
| 'description' => "The latest news from GoUpstate.com, a Spartanburg Herald-Journal Web site.", | |||
| 'pubDate' => $now, | |||
| ) | |||
| ), | |||
| array( | |||
| " | |||
| <channel> | |||
| <title>GoUpstate.com News Headlines</title> | |||
| <link>http://www.goupstate.com/</link> | |||
| <description>The latest news from GoUpstate.com, a Spartanburg Herald-Journal Web site.</description> | |||
| <lastBuildDate>{$nowString}</lastBuildDate> | |||
| </channel> | |||
| ", | |||
| array( | |||
| 'title' => "GoUpstate.com News Headlines", | |||
| 'url' => 'http://www.goupstate.com/', | |||
| 'description' => "The latest news from GoUpstate.com, a Spartanburg Herald-Journal Web site.", | |||
| 'lastBuildDate' => $now, | |||
| ) | |||
| ), | |||
| array( | |||
| " | |||
| <channel> | |||
| <title>GoUpstate.com News Headlines</title> | |||
| <link>http://www.goupstate.com/</link> | |||
| <description>The latest news from GoUpstate.com, a Spartanburg Herald-Journal Web site.</description> | |||
| <ttl>60</ttl> | |||
| </channel> | |||
| ", | |||
| array( | |||
| 'title' => "GoUpstate.com News Headlines", | |||
| 'url' => 'http://www.goupstate.com/', | |||
| 'description' => "The latest news from GoUpstate.com, a Spartanburg Herald-Journal Web site.", | |||
| 'ttl' => 60, | |||
| ) | |||
| ), | |||
| array( | |||
| " | |||
| <channel> | |||
| <title>GoUpstate.com News Headlines</title> | |||
| <link>http://www.goupstate.com/</link> | |||
| <description>The latest news from GoUpstate.com, a Spartanburg Herald-Journal Web site.</description> | |||
| <copyright>Copyright 2002, Spartanburg Herald-Journal</copyright> | |||
| </channel> | |||
| ", | |||
| array( | |||
| 'title' => "GoUpstate.com News Headlines", | |||
| 'url' => 'http://www.goupstate.com/', | |||
| 'description' => "The latest news from GoUpstate.com, a Spartanburg Herald-Journal Web site.", | |||
| 'copyright' => "Copyright 2002, Spartanburg Herald-Journal", | |||
| ) | |||
| ), | |||
| ); | |||
| } | |||
| public function testAppendTo_with_items() | |||
| { | |||
| $channel = new Channel(); | |||
| $xml1 = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8" ?><item><title>item1</title></item>'); | |||
| $xml2 = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8" ?><item><title>item2</title></item>'); | |||
| $xml3 = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8" ?><item><title>item3</title></item>'); | |||
| $item1 = $this->getMock($this->itemInterface); | |||
| $item1->expects($this->once())->method('asXML')->will($this->returnValue($xml1)); | |||
| $item2= $this->getMock($this->itemInterface); | |||
| $item2->expects($this->once())->method('asXML')->will($this->returnValue($xml2)); | |||
| $item3 = $this->getMock($this->itemInterface); | |||
| $item3->expects($this->once())->method('asXML')->will($this->returnValue($xml3)); | |||
| $this->reveal($channel) | |||
| ->attr('title', "GoUpstate.com News Headlines") | |||
| ->attr('url', 'http://www.goupstate.com/') | |||
| ->attr('description', "The latest news from GoUpstate.com, a Spartanburg Herald-Journal Web site.") | |||
| ->attr('items', array($item1, $item2, $item3)); | |||
| $expect = '<?xml version="1.0" encoding="UTF-8" ?> | |||
| <channel> | |||
| <title>GoUpstate.com News Headlines</title> | |||
| <link>http://www.goupstate.com/</link> | |||
| <description>The latest news from GoUpstate.com, a Spartanburg Herald-Journal Web site.</description> | |||
| <item> | |||
| <title>item1</title> | |||
| </item> | |||
| <item> | |||
| <title>item2</title> | |||
| </item> | |||
| <item> | |||
| <title>item3</title> | |||
| </item> | |||
| </channel> | |||
| '; | |||
| $this->assertXmlStringEqualsXmlString($expect, $channel->asXML()->asXML()); | |||
| } | |||
| } | |||
| @ -0,0 +1,96 @@ | |||
| <?php | |||
| namespace Suin\RSSWriter; | |||
| use \Mockery; | |||
| class FeedTest extends \XoopsUnit\TestCase | |||
| { | |||
| private $channelInterface = '\Suin\RSSWriter\ChannelInterface'; | |||
| public function testAddChannel() | |||
| { | |||
| $channel = Mockery::mock($this->channelInterface); | |||
| $feed = new Feed(); | |||
| $this->assertSame($feed, $feed->addChannel($channel)); | |||
| $this->assertAttributeSame(array($channel), 'channels', $feed); | |||
| } | |||
| public function testRender() | |||
| { | |||
| $feed = new Feed(); | |||
| $xml1 = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8" ?><channel><title>channel1</title></channel>'); | |||
| $xml2 = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8" ?><channel><title>channel2</title></channel>'); | |||
| $xml3 = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8" ?><channel><title>channel3</title></channel>'); | |||
| $channel1 = $this->getMock($this->channelInterface); | |||
| $channel1->expects($this->once())->method('asXML')->will($this->returnValue($xml1)); | |||
| $channel2 = $this->getMock($this->channelInterface); | |||
| $channel2->expects($this->once())->method('asXML')->will($this->returnValue($xml2)); | |||
| $channel3 = $this->getMock($this->channelInterface); | |||
| $channel3->expects($this->once())->method('asXML')->will($this->returnValue($xml3)); | |||
| $this->reveal($feed)->attr('channels', array($channel1, $channel2, $channel3)); | |||
| $expect = '<?xml version="1.0" encoding="UTF-8" ?> | |||
| <rss version="2.0"> | |||
| <channel><title>channel1</title></channel> | |||
| <channel><title>channel2</title></channel> | |||
| <channel><title>channel3</title></channel> | |||
| </rss> | |||
| '; | |||
| $this->assertXmlStringEqualsXmlString($expect, $feed->render()); | |||
| } | |||
| public function testRender_with_japanese() | |||
| { | |||
| $feed = new Feed(); | |||
| $xml1 = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8" ?><channel><title>日本語1</title></channel>'); | |||
| $xml2 = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8" ?><channel><title>日本語2</title></channel>'); | |||
| $xml3 = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8" ?><channel><title>日本語3</title></channel>'); | |||
| $channel1 = $this->getMock($this->channelInterface); | |||
| $channel1->expects($this->once())->method('asXML')->will($this->returnValue($xml1)); | |||
| $channel2 = $this->getMock($this->channelInterface); | |||
| $channel2->expects($this->once())->method('asXML')->will($this->returnValue($xml2)); | |||
| $channel3 = $this->getMock($this->channelInterface); | |||
| $channel3->expects($this->once())->method('asXML')->will($this->returnValue($xml3)); | |||
| $this->reveal($feed)->attr('channels', array($channel1, $channel2, $channel3)); | |||
| $expect = <<< 'XML' | |||
| <?xml version="1.0" encoding="UTF-8"?> | |||
| <rss version="2.0"> | |||
| <channel> | |||
| <title>日本語1</title> | |||
| </channel> | |||
| <channel> | |||
| <title>日本語2</title> | |||
| </channel> | |||
| <channel> | |||
| <title>日本語3</title> | |||
| </channel> | |||
| </rss> | |||
| XML; | |||
| $this->assertSame($expect, $feed->render()); | |||
| } | |||
| public function test__toString() | |||
| { | |||
| $feed = new Feed(); | |||
| $xml1 = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8" ?><channel><title>channel1</title></channel>'); | |||
| $xml2 = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8" ?><channel><title>channel2</title></channel>'); | |||
| $xml3 = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8" ?><channel><title>channel3</title></channel>'); | |||
| $channel1 = $this->getMock($this->channelInterface); | |||
| $channel1->expects($this->once())->method('asXML')->will($this->returnValue($xml1)); | |||
| $channel2 = $this->getMock($this->channelInterface); | |||
| $channel2->expects($this->once())->method('asXML')->will($this->returnValue($xml2)); | |||
| $channel3 = $this->getMock($this->channelInterface); | |||
| $channel3->expects($this->once())->method('asXML')->will($this->returnValue($xml3)); | |||
| $this->reveal($feed)->attr('channels', array($channel1, $channel2, $channel3)); | |||
| $expect = '<?xml version="1.0" encoding="UTF-8" ?> | |||
| <rss version="2.0"> | |||
| <channel><title>channel1</title></channel> | |||
| <channel><title>channel2</title></channel> | |||
| <channel><title>channel3</title></channel> | |||
| </rss> | |||
| '; | |||
| $this->assertXmlStringEqualsXmlString($expect, $feed); | |||
| } | |||
| } | |||
| @ -0,0 +1,200 @@ | |||
| <?php | |||
| namespace Suin\RSSWriter; | |||
| class ItemTest extends \XoopsUnit\TestCase | |||
| { | |||
| private $channelInterface = '\Suin\RSSWriter\ChannelInterface'; | |||
| public function testTitle() | |||
| { | |||
| $title = uniqid(); | |||
| $item = new Item(); | |||
| $this->assertSame($item, $item->title($title)); | |||
| $this->assertAttributeSame($title, 'title', $item); | |||
| } | |||
| public function testUrl() | |||
| { | |||
| $url = uniqid(); | |||
| $item = new Item(); | |||
| $this->assertSame($item, $item->url($url)); | |||
| $this->assertAttributeSame($url, 'url', $item); | |||
| } | |||
| public function testDescription() | |||
| { | |||
| $description = uniqid(); | |||
| $item = new Item(); | |||
| $this->assertSame($item, $item->description($description)); | |||
| $this->assertAttributeSame($description, 'description', $item); | |||
| } | |||
| public function testCategory() | |||
| { | |||
| $category = uniqid(); | |||
| $item = new Item(); | |||
| $this->assertSame($item, $item->category($category)); | |||
| $this->assertAttributeSame(array( | |||
| array($category, null), | |||
| ), 'categories', $item); | |||
| } | |||
| public function testCategory_with_domain() | |||
| { | |||
| $category = uniqid(); | |||
| $domain = uniqid(); | |||
| $item = new Item(); | |||
| $this->assertSame($item, $item->category($category, $domain)); | |||
| $this->assertAttributeSame(array( | |||
| array($category, $domain), | |||
| ), 'categories', $item); | |||
| } | |||
| public function testGuid() | |||
| { | |||
| $guid = uniqid(); | |||
| $item = new Item(); | |||
| $this->assertSame($item, $item->guid($guid)); | |||
| $this->assertAttributeSame($guid, 'guid', $item); | |||
| } | |||
| public function testGuid_with_permalink() | |||
| { | |||
| $item = new Item(); | |||
| $item->guid('guid', true); | |||
| $this->assertAttributeSame(true, 'isPermalink', $item); | |||
| $item->guid('guid', false); | |||
| $this->assertAttributeSame(false, 'isPermalink', $item); | |||
| $item->guid('guid'); // default | |||
| $this->assertAttributeSame(false, 'isPermalink', $item); | |||
| } | |||
| public function testPubDate() | |||
| { | |||
| $pubDate = mt_rand(1000000, 9999999); | |||
| $item = new Item(); | |||
| $this->assertSame($item, $item->pubDate($pubDate)); | |||
| $this->assertAttributeSame($pubDate, 'pubDate', $item); | |||
| } | |||
| public function testAppendTo() | |||
| { | |||
| $item = new Item(); | |||
| $channel = $this->getMock($this->channelInterface); | |||
| $channel->expects($this->once())->method('addItem')->with($item); | |||
| $this->assertSame($item, $item->appendTo($channel)); | |||
| } | |||
| public function testEnclosure() | |||
| { | |||
| $url = uniqid(); | |||
| $enclosure = array('url' => $url, 'length' => 0, 'type' => 'audio/mpeg'); | |||
| $item = new Item(); | |||
| $this->assertSame($item, $item->enclosure($url)); | |||
| $this->assertAttributeSame($enclosure, 'enclosure', $item); | |||
| } | |||
| public function testAsXML() | |||
| { | |||
| $now = time(); | |||
| $nowString = date(DATE_RSS, $now); | |||
| $data = array( | |||
| 'title' => "Venice Film Festival Tries to Quit Sinking", | |||
| 'url' => 'http://nytimes.com/2004/12/07FEST.html', | |||
| 'description' => "Some of the most heated chatter at the Venice Film Festival this week was about the way that the arrival of the stars at the Palazzo del Cinema was being staged.", | |||
| 'categories' => array( | |||
| array("Grateful Dead", null), | |||
| array("MSFT", 'http://www.fool.com/cusips'), | |||
| ), | |||
| 'guid' => "http://inessential.com/2002/09/01.php#a2", | |||
| 'isPermalink' => true, | |||
| 'pubDate' => $now, | |||
| 'enclosure' => array( | |||
| 'url' => 'http://link-to-audio-file.com/test.mp3', | |||
| 'length' => 4992, | |||
| 'type' => 'audio/mpeg') | |||
| ); | |||
| $item = new Item(); | |||
| foreach ( $data as $key => $value ) | |||
| { | |||
| $this->reveal($item)->attr($key, $value); | |||
| } | |||
| $expect =" | |||
| <item> | |||
| <title>{$data['title']}</title> | |||
| <link>{$data['url']}</link> | |||
| <description>{$data['description']}</description> | |||
| <category>{$data['categories'][0][0]}</category> | |||
| <category domain=\"{$data['categories'][1][1]}\">{$data['categories'][1][0]}</category> | |||
| <guid isPermaLink=\"true\">{$data['guid']}</guid> | |||
| <pubDate>{$nowString}</pubDate> | |||
| <enclosure url=\"{$data['enclosure']['url']}\" length=\"{$data['enclosure']['length']}\" type=\"{$data['enclosure']['type']}\"/> | |||
| </item> | |||
| "; | |||
| $this->assertXmlStringEqualsXmlString($expect, $item->asXML()->asXML()); | |||
| } | |||
| public function testAsXML_test_Japanese() | |||
| { | |||
| $now = time(); | |||
| $nowString = date(DATE_RSS, $now); | |||
| $data = array( | |||
| 'title' => "Venice Film Festival", | |||
| 'url' => 'http://nytimes.com/2004/12/07FEST.html', | |||
| 'description' => "Some of the most heated chatter at the Venice Film Festival this week was about the way that the arrival of the stars at the Palazzo del Cinema was being staged.", | |||
| ); | |||
| $item = new Item(); | |||
| foreach ( $data as $key => $value ) | |||
| { | |||
| $this->reveal($item)->attr($key, $value); | |||
| } | |||
| $expect = " | |||
| <item> | |||
| <title>{$data['title']}</title> | |||
| <link>{$data['url']}</link> | |||
| <description>{$data['description']}</description> | |||
| </item> | |||
| "; | |||
| $this->assertXmlStringEqualsXmlString($expect, $item->asXML()->asXML()); | |||
| } | |||
| public function test_with_amp() | |||
| { | |||
| $item = new Item(); | |||
| $item | |||
| ->title('test&test') | |||
| ->url('url&url') | |||
| ->description('desc&desc'); | |||
| $expect = '<?xml version="1.0" encoding="UTF-8"?> | |||
| <item><title>test&test</title><link>url&url</link><description>desc&desc</description></item> | |||
| '; | |||
| $this->assertSame($expect, $item->asXML()->asXML()); | |||
| } | |||
| public function test_fail_safe_against_invalid_string() | |||
| { | |||
| $item = new Item(); | |||
| $item | |||
| ->title("test\0test") | |||
| ->url("url\0test") | |||
| ->description("desc\0desc"); | |||
| $expect = '<?xml version="1.0" encoding="UTF-8"?> | |||
| <item><title>test</title><link>url</link><description>desc</description></item> | |||
| '; | |||
| $this->assertSame($expect, $item->asXML()->asXML()); | |||
| } | |||
| } | |||
| @ -0,0 +1,12 @@ | |||
| { | |||
| "config": { | |||
| "bin-dir": ".", | |||
| "vendor-dir": "Vendor" | |||
| }, | |||
| "require": { | |||
| "php": ">=5.3.2", | |||
| "EHER/PHPUnit": ">=1.6", | |||
| "suin/xoopsunit": ">=1.2", | |||
| "mockery/mockery": ">=0.7.2" | |||
| } | |||
| } | |||
| @ -0,0 +1,42 @@ | |||
| <?xml version="1.0" encoding="UTF-8"?> | |||
| <phpunit | |||
| bootstrap="Bootstrap.php" | |||
| processIsolation="false" | |||
| verbose="true" | |||
| strict="false" | |||
| colors="true"> | |||
| <testsuites> | |||
| <testsuite name="PHPUnit"> | |||
| <directory>Suin</directory> | |||
| </testsuite> | |||
| </testsuites> | |||
| <logging> | |||
| <log | |||
| type="coverage-html" | |||
| target="Coverage" | |||
| charset="UTF-8" | |||
| yui="true" | |||
| highlight="false" | |||
| lowUpperBound="35" | |||
| highLowerBound="70" /> | |||
| <!-- <log type="coverage-text" target="php://stdout" lowUpperBound="35" highLowerBound="70" /> --> | |||
| </logging> | |||
| <filter> | |||
| <whitelist> | |||
| <directory suffix=".php">../Source</directory> | |||
| <!-- <file>/path/to/file</file> --> | |||
| <exclude> | |||
| <file>../Public/index.php</file> | |||
| <directory suffix="Interface.php">../Source</directory> | |||
| </exclude> | |||
| </whitelist> | |||
| <blacklist> | |||
| <directory suffix=".php" group="PHPUNIT">../Vendor</directory> | |||
| </blacklist> | |||
| </filter> | |||
| <listeners> | |||
| <listener class="\Mockery\Adapter\Phpunit\TestListener" file="Vendor/mockery/mockery/library/Mockery/Adapter/Phpunit/TestListener.php" /> | |||
| </listeners> | |||
| </phpunit> | |||
| @ -0,0 +1,20 @@ | |||
| { | |||
| "name": "suin/php-rss-writer", | |||
| "type": "library", | |||
| "description": "Yet another simple RSS writer library for PHP 5.3 or later.", | |||
| "keywords": ["rss", "generator", "writer", "feed"], | |||
| "homepage": "https://github.com/suin/php-rss-writer", | |||
| "license": "MIT", | |||
| "authors": [ | |||
| { | |||
| "name": "Hidehito Nozawa aka Suin", | |||
| "email": "suinyeze@gmail.com" | |||
| } | |||
| ], | |||
| "require": { | |||
| "php": ">=5.3.0" | |||
| }, | |||
| "autoload": { | |||
| "psr-0": { "Suin\\RSSWriter": "Source" } | |||
| } | |||
| } | |||
| @ -0,0 +1,35 @@ | |||
| <?php | |||
| // Load test target classes | |||
| spl_autoload_register(function($c) { @include_once strtr($c, '\\_', '//').'.php'; }); | |||
| set_include_path(get_include_path() . PATH_SEPARATOR . __DIR__.'/Source'); | |||
| use \Suin\RSSWriter\Feed; | |||
| use \Suin\RSSWriter\Channel; | |||
| use \Suin\RSSWriter\Item; | |||
| $feed = new Feed(); | |||
| $channel = new Channel(); | |||
| $channel | |||
| ->title("Channel Title") | |||
| ->description("Channel Description") | |||
| ->url('http://blog.example.com') | |||
| ->language('en-US') | |||
| ->copyright('Copyright 2012, Foo Bar') | |||
| ->pubDate(strtotime('Tue, 21 Aug 2012 19:50:37 +0900')) | |||
| ->lastBuildDate(strtotime('Tue, 21 Aug 2012 19:50:37 +0900')) | |||
| ->ttl(60) | |||
| ->appendTo($feed); | |||
| $item = new Item(); | |||
| $item | |||
| ->title("Blog Entry Title") | |||
| ->description("<div>Blog body</div>") | |||
| ->url('http://blog.example.com/2012/08/21/blog-entry/') | |||
| ->pubDate(strtotime('Tue, 21 Aug 2012 19:50:37 +0900')) | |||
| ->guid('http://blog.example.com/2012/08/21/blog-entry/', true) | |||
| ->appendTo($channel); | |||
| echo $feed; // or echo $feed->render(); | |||