parent
9732824a8d
commit
7f335a533d
@ -477,7 +477,7 @@ function update_all($feed_id, array $items)
|
|||||||
'id' => $item->getId(),
|
'id' => $item->getId(),
|
||||||
'title' => $item->getTitle(),
|
'title' => $item->getTitle(),
|
||||||
'url' => $item->getUrl(),
|
'url' => $item->getUrl(),
|
||||||
'updated' => $item->getDate(),
|
'updated' => $item->getDate()->getTimestamp(),
|
||||||
'author' => $item->getAuthor(),
|
'author' => $item->getAuthor(),
|
||||||
'content' => $nocontent ? '' : $item->getContent(),
|
'content' => $nocontent ? '' : $item->getContent(),
|
||||||
'status' => 'unread',
|
'status' => 'unread',
|
||||||
|
2
vendor/autoload.php
vendored
2
vendor/autoload.php
vendored
@ -4,4 +4,4 @@
|
|||||||
|
|
||||||
require_once __DIR__ . '/composer' . '/autoload_real.php';
|
require_once __DIR__ . '/composer' . '/autoload_real.php';
|
||||||
|
|
||||||
return ComposerAutoloaderInita6340803ab9f5b44ecc7aa3f90f789c5::getLoader();
|
return ComposerAutoloaderInit4a7335ffe176a1ef5c75eb89d06418db::getLoader();
|
||||||
|
10
vendor/composer/autoload_real.php
vendored
10
vendor/composer/autoload_real.php
vendored
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
// autoload_real.php @generated by Composer
|
// autoload_real.php @generated by Composer
|
||||||
|
|
||||||
class ComposerAutoloaderInita6340803ab9f5b44ecc7aa3f90f789c5
|
class ComposerAutoloaderInit4a7335ffe176a1ef5c75eb89d06418db
|
||||||
{
|
{
|
||||||
private static $loader;
|
private static $loader;
|
||||||
|
|
||||||
@ -19,9 +19,9 @@ class ComposerAutoloaderInita6340803ab9f5b44ecc7aa3f90f789c5
|
|||||||
return self::$loader;
|
return self::$loader;
|
||||||
}
|
}
|
||||||
|
|
||||||
spl_autoload_register(array('ComposerAutoloaderInita6340803ab9f5b44ecc7aa3f90f789c5', 'loadClassLoader'), true, true);
|
spl_autoload_register(array('ComposerAutoloaderInit4a7335ffe176a1ef5c75eb89d06418db', 'loadClassLoader'), true, true);
|
||||||
self::$loader = $loader = new \Composer\Autoload\ClassLoader();
|
self::$loader = $loader = new \Composer\Autoload\ClassLoader();
|
||||||
spl_autoload_unregister(array('ComposerAutoloaderInita6340803ab9f5b44ecc7aa3f90f789c5', 'loadClassLoader'));
|
spl_autoload_unregister(array('ComposerAutoloaderInit4a7335ffe176a1ef5c75eb89d06418db', 'loadClassLoader'));
|
||||||
|
|
||||||
$map = require __DIR__ . '/autoload_namespaces.php';
|
$map = require __DIR__ . '/autoload_namespaces.php';
|
||||||
foreach ($map as $namespace => $path) {
|
foreach ($map as $namespace => $path) {
|
||||||
@ -42,14 +42,14 @@ class ComposerAutoloaderInita6340803ab9f5b44ecc7aa3f90f789c5
|
|||||||
|
|
||||||
$includeFiles = require __DIR__ . '/autoload_files.php';
|
$includeFiles = require __DIR__ . '/autoload_files.php';
|
||||||
foreach ($includeFiles as $file) {
|
foreach ($includeFiles as $file) {
|
||||||
composerRequirea6340803ab9f5b44ecc7aa3f90f789c5($file);
|
composerRequire4a7335ffe176a1ef5c75eb89d06418db($file);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $loader;
|
return $loader;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function composerRequirea6340803ab9f5b44ecc7aa3f90f789c5($file)
|
function composerRequire4a7335ffe176a1ef5c75eb89d06418db($file)
|
||||||
{
|
{
|
||||||
require $file;
|
require $file;
|
||||||
}
|
}
|
||||||
|
94
vendor/composer/installed.json
vendored
94
vendor/composer/installed.json
vendored
@ -1,43 +1,4 @@
|
|||||||
[
|
[
|
||||||
{
|
|
||||||
"name": "fguillot/simple-validator",
|
|
||||||
"version": "dev-master",
|
|
||||||
"version_normalized": "9999999-dev",
|
|
||||||
"source": {
|
|
||||||
"type": "git",
|
|
||||||
"url": "https://github.com/fguillot/simpleValidator.git",
|
|
||||||
"reference": "9e9502c88ce239901c0fee12a1f504948342ab42"
|
|
||||||
},
|
|
||||||
"dist": {
|
|
||||||
"type": "zip",
|
|
||||||
"url": "https://api.github.com/repos/fguillot/simpleValidator/zipball/9e9502c88ce239901c0fee12a1f504948342ab42",
|
|
||||||
"reference": "9e9502c88ce239901c0fee12a1f504948342ab42",
|
|
||||||
"shasum": ""
|
|
||||||
},
|
|
||||||
"require": {
|
|
||||||
"php": ">=5.3.0"
|
|
||||||
},
|
|
||||||
"time": "2015-01-21 02:00:33",
|
|
||||||
"type": "library",
|
|
||||||
"installation-source": "dist",
|
|
||||||
"autoload": {
|
|
||||||
"psr-0": {
|
|
||||||
"SimpleValidator": "src/"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"notification-url": "https://packagist.org/downloads/",
|
|
||||||
"license": [
|
|
||||||
"MIT"
|
|
||||||
],
|
|
||||||
"authors": [
|
|
||||||
{
|
|
||||||
"name": "Frédéric Guillot",
|
|
||||||
"homepage": "http://fredericguillot.com"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"description": "The most easy to use validator library for PHP :)",
|
|
||||||
"homepage": "https://github.com/fguillot/simpleValidator"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"name": "fguillot/picodb",
|
"name": "fguillot/picodb",
|
||||||
"version": "v0.0.2",
|
"version": "v0.0.2",
|
||||||
@ -116,6 +77,45 @@
|
|||||||
"description": "Minimalist micro-framework",
|
"description": "Minimalist micro-framework",
|
||||||
"homepage": "https://github.com/fguillot/picoFarad"
|
"homepage": "https://github.com/fguillot/picoFarad"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "fguillot/simple-validator",
|
||||||
|
"version": "dev-master",
|
||||||
|
"version_normalized": "9999999-dev",
|
||||||
|
"source": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/fguillot/simpleValidator.git",
|
||||||
|
"reference": "5ebdb6df4c5f3aa2539b633eb4ae94c9e8c4ada7"
|
||||||
|
},
|
||||||
|
"dist": {
|
||||||
|
"type": "zip",
|
||||||
|
"url": "https://api.github.com/repos/fguillot/simpleValidator/zipball/5ebdb6df4c5f3aa2539b633eb4ae94c9e8c4ada7",
|
||||||
|
"reference": "5ebdb6df4c5f3aa2539b633eb4ae94c9e8c4ada7",
|
||||||
|
"shasum": ""
|
||||||
|
},
|
||||||
|
"require": {
|
||||||
|
"php": ">=5.3.0"
|
||||||
|
},
|
||||||
|
"time": "2015-02-14 21:04:14",
|
||||||
|
"type": "library",
|
||||||
|
"installation-source": "dist",
|
||||||
|
"autoload": {
|
||||||
|
"psr-0": {
|
||||||
|
"SimpleValidator": "src/"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"notification-url": "https://packagist.org/downloads/",
|
||||||
|
"license": [
|
||||||
|
"MIT"
|
||||||
|
],
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "Frédéric Guillot",
|
||||||
|
"homepage": "http://fredericguillot.com"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "The most easy to use validator library for PHP :)",
|
||||||
|
"homepage": "https://github.com/fguillot/simpleValidator"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "fguillot/json-rpc",
|
"name": "fguillot/json-rpc",
|
||||||
"version": "dev-master",
|
"version": "dev-master",
|
||||||
@ -123,18 +123,18 @@
|
|||||||
"source": {
|
"source": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/fguillot/JsonRPC.git",
|
"url": "https://github.com/fguillot/JsonRPC.git",
|
||||||
"reference": "514695af758060b2c89fd67c59a04ac5da91481a"
|
"reference": "d64090706507dccab53e35ad5fcf00ae2502c647"
|
||||||
},
|
},
|
||||||
"dist": {
|
"dist": {
|
||||||
"type": "zip",
|
"type": "zip",
|
||||||
"url": "https://api.github.com/repos/fguillot/JsonRPC/zipball/514695af758060b2c89fd67c59a04ac5da91481a",
|
"url": "https://api.github.com/repos/fguillot/JsonRPC/zipball/d64090706507dccab53e35ad5fcf00ae2502c647",
|
||||||
"reference": "514695af758060b2c89fd67c59a04ac5da91481a",
|
"reference": "d64090706507dccab53e35ad5fcf00ae2502c647",
|
||||||
"shasum": ""
|
"shasum": ""
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
"php": ">=5.3.0"
|
"php": ">=5.3.0"
|
||||||
},
|
},
|
||||||
"time": "2015-02-02 22:12:09",
|
"time": "2015-02-13 03:20:58",
|
||||||
"type": "library",
|
"type": "library",
|
||||||
"installation-source": "dist",
|
"installation-source": "dist",
|
||||||
"autoload": {
|
"autoload": {
|
||||||
@ -162,12 +162,12 @@
|
|||||||
"source": {
|
"source": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/fguillot/picoFeed.git",
|
"url": "https://github.com/fguillot/picoFeed.git",
|
||||||
"reference": "c6f0742ccda390c81782f788e289cd5d8b555c3a"
|
"reference": "beac91bf7cda7057d470c495b6616ced44ef1936"
|
||||||
},
|
},
|
||||||
"dist": {
|
"dist": {
|
||||||
"type": "zip",
|
"type": "zip",
|
||||||
"url": "https://api.github.com/repos/fguillot/picoFeed/zipball/c6f0742ccda390c81782f788e289cd5d8b555c3a",
|
"url": "https://api.github.com/repos/fguillot/picoFeed/zipball/beac91bf7cda7057d470c495b6616ced44ef1936",
|
||||||
"reference": "c6f0742ccda390c81782f788e289cd5d8b555c3a",
|
"reference": "beac91bf7cda7057d470c495b6616ced44ef1936",
|
||||||
"shasum": ""
|
"shasum": ""
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
@ -178,7 +178,7 @@
|
|||||||
"ext-xml": "*",
|
"ext-xml": "*",
|
||||||
"php": ">=5.3.0"
|
"php": ">=5.3.0"
|
||||||
},
|
},
|
||||||
"time": "2015-02-06 02:06:33",
|
"time": "2015-03-01 18:36:28",
|
||||||
"type": "library",
|
"type": "library",
|
||||||
"installation-source": "dist",
|
"installation-source": "dist",
|
||||||
"autoload": {
|
"autoload": {
|
||||||
|
12
vendor/fguillot/json-rpc/src/JsonRPC/Client.php
vendored
12
vendor/fguillot/json-rpc/src/JsonRPC/Client.php
vendored
@ -252,7 +252,7 @@ class Client
|
|||||||
public function getResult(array $payload)
|
public function getResult(array $payload)
|
||||||
{
|
{
|
||||||
if (isset($payload['error']['code'])) {
|
if (isset($payload['error']['code'])) {
|
||||||
$this->handleRpcErrors($payload['error']['code']);
|
$this->handleRpcErrors($payload['error']);
|
||||||
}
|
}
|
||||||
|
|
||||||
return isset($payload['result']) ? $payload['result'] : null;
|
return isset($payload['result']) ? $payload['result'] : null;
|
||||||
@ -264,15 +264,15 @@ class Client
|
|||||||
* @access public
|
* @access public
|
||||||
* @param integer $code
|
* @param integer $code
|
||||||
*/
|
*/
|
||||||
public function handleRpcErrors($code)
|
public function handleRpcErrors($error)
|
||||||
{
|
{
|
||||||
switch ($code) {
|
switch ($error['code']) {
|
||||||
case -32601:
|
case -32601:
|
||||||
throw new BadFunctionCallException('Procedure not found');
|
throw new BadFunctionCallException('Procedure not found: '. $error['message']);
|
||||||
case -32602:
|
case -32602:
|
||||||
throw new InvalidArgumentException('Invalid arguments');
|
throw new InvalidArgumentException('Invalid arguments: '. $error['message']);
|
||||||
default:
|
default:
|
||||||
throw new RuntimeException('Invalid request/response');
|
throw new RuntimeException('Invalid request/response: '. $error['message'], $error['code']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,23 +45,23 @@ Feed::id = tag:linuxfr.org,2005:/news
|
|||||||
Feed::title = LinuxFr.org : les dépêches
|
Feed::title = LinuxFr.org : les dépêches
|
||||||
Feed::feed_url = http://linuxfr.org/news.atom
|
Feed::feed_url = http://linuxfr.org/news.atom
|
||||||
Feed::site_url = http://linuxfr.org/news
|
Feed::site_url = http://linuxfr.org/news
|
||||||
Feed::date = 1415138079
|
|
||||||
Feed::language = en-US
|
Feed::language = en-US
|
||||||
Feed::description =
|
Feed::description =
|
||||||
Feed::logo =
|
Feed::logo =
|
||||||
Feed::items = 15 items
|
Feed::date = Thu, 26 Feb 15 09:33:08 +0100
|
||||||
Feed::isRTL() = false
|
Feed::isRTL() = false
|
||||||
|
Feed::items = 15 items
|
||||||
----
|
----
|
||||||
Item::id = 38d8f48284fb03940cbb3aff9101089b81e44efb1281641bdd7c3e7e4bf3b0cd
|
Item::id = 56198c98ae852d21c369bfb5ffbc2ad13db2f3227236dde3e21ca1a9eb943faf
|
||||||
Item::title = openSUSE 13.2 : nouvelle version du caméléon disponible !
|
Item::title = Les brevets logiciels : un frein à l'innovation et la recherche (un nouvel exemple aux États-Unis)
|
||||||
Item::url = http://linuxfr.org/news/opensuse-13-2-nouvelle-version-du-cameleon-disponible
|
Item::url = http://linuxfr.org/news/les-brevets-logiciels-un-frein-a-l-innovation-et-la-recherche-un-nouvel-exemple-aux-etats-unis
|
||||||
Item::date = 1415122640
|
|
||||||
Item::language = en-US
|
Item::language = en-US
|
||||||
Item::author = Syvolc
|
Item::author = alenvers
|
||||||
Item::enclosure_url =
|
Item::enclosure_url =
|
||||||
Item::enclosure_type =
|
Item::enclosure_type =
|
||||||
|
Item::date = Thu, 26 Feb 15 09:33:08 +0100
|
||||||
Item::isRTL() = false
|
Item::isRTL() = false
|
||||||
Item::content = 18307 bytes
|
Item::content = 6452 bytes
|
||||||
....
|
....
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -186,7 +186,7 @@ $feed->getId(); // Unique feed id
|
|||||||
$feed->getTitle(); // Feed title
|
$feed->getTitle(); // Feed title
|
||||||
$feed->getFeedUrl(); // Feed url
|
$feed->getFeedUrl(); // Feed url
|
||||||
$feed->getSiteUrl(); // Website url
|
$feed->getSiteUrl(); // Website url
|
||||||
$feed->getDate(); // Feed last updated date
|
$feed->getDate(); // Feed last updated date (DateTime object)
|
||||||
$feed->getLanguage(); // Feed language
|
$feed->getLanguage(); // Feed language
|
||||||
$feed->getDescription(); // Feed description
|
$feed->getDescription(); // Feed description
|
||||||
$feed->getLogo(); // Feed logo (can be a large image, different from icon)
|
$feed->getLogo(); // Feed logo (can be a large image, different from icon)
|
||||||
@ -196,7 +196,7 @@ $feed->getItems(); // List of item objects
|
|||||||
$feed->items[0]->getId(); // Item unique id (hash)
|
$feed->items[0]->getId(); // Item unique id (hash)
|
||||||
$feed->items[0]->getTitle(); // Item title
|
$feed->items[0]->getTitle(); // Item title
|
||||||
$feed->items[0]->getUrl(); // Item url
|
$feed->items[0]->getUrl(); // Item url
|
||||||
$feed->items[0]->getDate(); // Item published date (timestamp)
|
$feed->items[0]->getDate(); // Item published date (DateTime object)
|
||||||
$feed->items[0]->getLanguage(); // Item language
|
$feed->items[0]->getLanguage(); // Item language
|
||||||
$feed->items[0]->getAuthor(); // Item author
|
$feed->items[0]->getAuthor(); // Item author
|
||||||
$feed->items[0]->getEnclosureUrl(); // Enclosure url
|
$feed->items[0]->getEnclosureUrl(); // Enclosure url
|
||||||
|
@ -6,7 +6,8 @@ Versions
|
|||||||
|
|
||||||
- Development version: master
|
- Development version: master
|
||||||
- Available versions:
|
- Available versions:
|
||||||
- v0.1.1 (stable)
|
- v0.1.2 (stable)
|
||||||
|
- v0.1.1
|
||||||
- v0.1.0
|
- v0.1.0
|
||||||
- v0.0.2
|
- v0.0.2
|
||||||
- v0.0.1
|
- v0.0.1
|
||||||
@ -21,7 +22,7 @@ Configure your `composer.json`:
|
|||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
"require": {
|
"require": {
|
||||||
"fguillot/picofeed": "0.1.1"
|
"fguillot/picofeed": "0.1.2"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
@ -29,7 +30,7 @@ Configure your `composer.json`:
|
|||||||
Or simply:
|
Or simply:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
composer require fguillot/picofeed:0.1.1
|
composer require fguillot/picofeed:0.1.2
|
||||||
```
|
```
|
||||||
|
|
||||||
And download the code:
|
And download the code:
|
||||||
|
@ -143,7 +143,6 @@ class Curl extends Client
|
|||||||
{
|
{
|
||||||
$headers = array(
|
$headers = array(
|
||||||
'Connection: close',
|
'Connection: close',
|
||||||
'User-Agent: '.$this->user_agent,
|
|
||||||
);
|
);
|
||||||
|
|
||||||
if ($this->etag) {
|
if ($this->etag) {
|
||||||
@ -236,13 +235,23 @@ class Curl extends Client
|
|||||||
curl_setopt($ch, CURLOPT_URL, $this->url);
|
curl_setopt($ch, CURLOPT_URL, $this->url);
|
||||||
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
|
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
|
||||||
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $this->timeout);
|
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $this->timeout);
|
||||||
|
curl_setopt($ch, CURLOPT_USERAGENT, $this->user_agent);
|
||||||
curl_setopt($ch, CURLOPT_HTTPHEADER, $this->prepareHeaders());
|
curl_setopt($ch, CURLOPT_HTTPHEADER, $this->prepareHeaders());
|
||||||
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, ini_get('open_basedir') === '');
|
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, ini_get('open_basedir') === '');
|
||||||
curl_setopt($ch, CURLOPT_MAXREDIRS, $this->max_redirects);
|
curl_setopt($ch, CURLOPT_MAXREDIRS, $this->max_redirects);
|
||||||
curl_setopt($ch, CURLOPT_ENCODING, '');
|
curl_setopt($ch, CURLOPT_ENCODING, '');
|
||||||
curl_setopt($ch, CURLOPT_COOKIEJAR, 'php://memory');
|
curl_setopt($ch, CURLOPT_COOKIEJAR, 'php://memory');
|
||||||
curl_setopt($ch, CURLOPT_COOKIEFILE, 'php://memory');
|
curl_setopt($ch, CURLOPT_COOKIEFILE, 'php://memory');
|
||||||
curl_setopt($ch, CURLOPT_SSLVERSION, 1); // Enforce TLS v1
|
|
||||||
|
// Disable SSLv3 by enforcing TLSv1.x for curl >= 7.34.0 and < 7.39.0.
|
||||||
|
// Versions prior to 7.34 and at least when compiled against openssl
|
||||||
|
// interpret this parameter as "limit to TLSv1.0" which fails for sites
|
||||||
|
// which enforce TLS 1.1+.
|
||||||
|
// Starting with curl 7.39.0 SSLv3 is disabled by default.
|
||||||
|
$version = curl_version();
|
||||||
|
if ($version['version_number'] >= 467456 && $version['version_number'] < 468736) {
|
||||||
|
curl_setopt($ch, CURLOPT_SSLVERSION, 1);
|
||||||
|
}
|
||||||
|
|
||||||
$ch = $this->prepareDownloadMode($ch);
|
$ch = $this->prepareDownloadMode($ch);
|
||||||
$ch = $this->prepareProxyContext($ch);
|
$ch = $this->prepareProxyContext($ch);
|
||||||
|
@ -123,8 +123,6 @@ class Grabber
|
|||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
private $stripTags = array(
|
private $stripTags = array(
|
||||||
'script',
|
|
||||||
'style',
|
|
||||||
'nav',
|
'nav',
|
||||||
'header',
|
'header',
|
||||||
'footer',
|
'footer',
|
||||||
@ -276,11 +274,11 @@ class Grabber
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($this->html) {
|
if ($this->html) {
|
||||||
|
$html_encoding = XmlParser::getEncodingFromMetaTag($this->html);
|
||||||
|
|
||||||
Logger::setMessage(get_called_class().': Fix encoding');
|
// Encode everything in UTF-8
|
||||||
Logger::setMessage(get_called_class().': HTTP Encoding "'.$this->encoding.'"');
|
Logger::setMessage(get_called_class().': HTTP Encoding "'.$this->encoding.'" ; HTML Encoding "'.$html_encoding.'"');
|
||||||
|
$this->html = Encoding::convert($this->html, $html_encoding ?: $this->encoding);
|
||||||
$this->html = Encoding::convert($this->html, $this->encoding);
|
|
||||||
$this->html = Filter::stripHeadTags($this->html);
|
$this->html = Filter::stripHeadTags($this->html);
|
||||||
|
|
||||||
Logger::setMessage(get_called_class().': Content length: '.strlen($this->html).' bytes');
|
Logger::setMessage(get_called_class().': Content length: '.strlen($this->html).' bytes');
|
||||||
|
@ -2,6 +2,11 @@
|
|||||||
|
|
||||||
namespace PicoFeed\Encoding;
|
namespace PicoFeed\Encoding;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Encoding class
|
||||||
|
*
|
||||||
|
* @package Encoding
|
||||||
|
*/
|
||||||
class Encoding
|
class Encoding
|
||||||
{
|
{
|
||||||
public static function convert($input, $encoding)
|
public static function convert($input, $encoding)
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
namespace PicoFeed\Filter;
|
namespace PicoFeed\Filter;
|
||||||
|
|
||||||
use \PicoFeed\Client\Url;
|
use PicoFeed\Client\Url;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Attribute Filter class
|
* Attribute Filter class
|
||||||
@ -233,6 +233,7 @@ class Attribute
|
|||||||
'filterBlacklistResourceAttribute',
|
'filterBlacklistResourceAttribute',
|
||||||
'filterProtocolUrlAttribute',
|
'filterProtocolUrlAttribute',
|
||||||
'rewriteImageProxyUrl',
|
'rewriteImageProxyUrl',
|
||||||
|
'secureIframeSrc',
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -383,6 +384,25 @@ class Attribute
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Turns iframes' src attribute from http to https to prevent
|
||||||
|
* mixed active content
|
||||||
|
*
|
||||||
|
* @access public
|
||||||
|
* @param string $tag Tag name
|
||||||
|
* @param array $attribute Atttributes name
|
||||||
|
* @param string $value Attribute value
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public function secureIframeSrc($tag, $attribute, &$value)
|
||||||
|
{
|
||||||
|
if ($tag === 'iframe' && $attribute === 'src' && strpos($value, 'http://') === 0) {
|
||||||
|
$value = substr_replace($value, 's', 4, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Rewrite image url to use with a proxy
|
* Rewrite image url to use with a proxy
|
||||||
*
|
*
|
||||||
|
@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
namespace PicoFeed\Filter;
|
namespace PicoFeed\Filter;
|
||||||
|
|
||||||
use \PicoFeed\Client\Url;
|
use PicoFeed\Client\Url;
|
||||||
use \PicoFeed\Parser\XmlParser;
|
use PicoFeed\Parser\XmlParser;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* HTML Filter class
|
* HTML Filter class
|
||||||
@ -121,6 +121,8 @@ class Html
|
|||||||
*/
|
*/
|
||||||
public function execute()
|
public function execute()
|
||||||
{
|
{
|
||||||
|
$this->preFilter();
|
||||||
|
|
||||||
$parser = xml_parser_create();
|
$parser = xml_parser_create();
|
||||||
|
|
||||||
xml_set_object($parser, $this);
|
xml_set_object($parser, $this);
|
||||||
@ -135,6 +137,16 @@ class Html
|
|||||||
return $this->output;
|
return $this->output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called before XML parsing
|
||||||
|
*
|
||||||
|
* @access public
|
||||||
|
*/
|
||||||
|
public function preFilter()
|
||||||
|
{
|
||||||
|
$this->input = $this->tag->removeBlacklistedTags($this->input);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called after XML parsing
|
* Called after XML parsing
|
||||||
*
|
*
|
||||||
|
@ -2,6 +2,9 @@
|
|||||||
|
|
||||||
namespace PicoFeed\Filter;
|
namespace PicoFeed\Filter;
|
||||||
|
|
||||||
|
use DOMXpath;
|
||||||
|
use PicoFeed\Parser\XmlParser;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tag Filter class
|
* Tag Filter class
|
||||||
*
|
*
|
||||||
@ -10,6 +13,17 @@ namespace PicoFeed\Filter;
|
|||||||
*/
|
*/
|
||||||
class Tag
|
class Tag
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Tags blacklist (Xpath expressions)
|
||||||
|
*
|
||||||
|
* @access private
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
private $tag_blacklist = array(
|
||||||
|
'//script',
|
||||||
|
'//style',
|
||||||
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tags whitelist
|
* Tags whitelist
|
||||||
*
|
*
|
||||||
@ -104,7 +118,7 @@ class Tag
|
|||||||
*/
|
*/
|
||||||
public function isSelfClosingTag($tag)
|
public function isSelfClosingTag($tag)
|
||||||
{
|
{
|
||||||
return in_array($tag, array('br', 'img'));
|
return $tag === 'br' || $tag === 'img';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -134,6 +148,33 @@ class Tag
|
|||||||
$attributes['height'] == 1 && $attributes['width'] == 1;
|
$attributes['height'] == 1 && $attributes['width'] == 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove script tags
|
||||||
|
*
|
||||||
|
* @access public
|
||||||
|
* @param string $data Input data
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function removeBlacklistedTags($data)
|
||||||
|
{
|
||||||
|
$dom = XmlParser::getDomDocument($data);
|
||||||
|
|
||||||
|
if ($dom === false) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
$xpath = new DOMXpath($dom);
|
||||||
|
|
||||||
|
$nodes = $xpath->query(implode(' | ', $this->tag_blacklist));
|
||||||
|
|
||||||
|
foreach ($nodes as $node) {
|
||||||
|
$node->parentNode->removeChild($node);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $dom->saveXML();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove empty tags
|
* Remove empty tags
|
||||||
*
|
*
|
||||||
|
@ -131,7 +131,7 @@ class Atom extends Parser
|
|||||||
*/
|
*/
|
||||||
public function findFeedDate(SimpleXMLElement $xml, Feed $feed)
|
public function findFeedDate(SimpleXMLElement $xml, Feed $feed)
|
||||||
{
|
{
|
||||||
$feed->date = $this->date->getTimestamp((string) $xml->updated);
|
$feed->date = $this->date->getDateTime((string) $xml->updated);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -143,10 +143,15 @@ class Atom extends Parser
|
|||||||
*/
|
*/
|
||||||
public function findItemDate(SimpleXMLElement $entry, Item $item)
|
public function findItemDate(SimpleXMLElement $entry, Item $item)
|
||||||
{
|
{
|
||||||
$published = isset($entry->published) ? $this->date->getTimestamp((string) $entry->published) : 0;
|
$published = isset($entry->published) ? $this->date->getDateTime((string) $entry->published) : null;
|
||||||
$updated = isset($entry->updated) ? $this->date->getTimestamp((string) $entry->updated) : 0;
|
$updated = isset($entry->updated) ? $this->date->getDateTime((string) $entry->updated) : null;
|
||||||
|
|
||||||
$item->date = max($published, $updated) ?: time();
|
if ($published !== null && $updated !== null) {
|
||||||
|
$item->date = max($published, $updated);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$item->date = $updated ?: $published;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -60,9 +60,9 @@ class DateParser
|
|||||||
*
|
*
|
||||||
* @access public
|
* @access public
|
||||||
* @param string $value Original date format
|
* @param string $value Original date format
|
||||||
* @return integer Timestamp
|
* @return DateTime
|
||||||
*/
|
*/
|
||||||
public function getTimestamp($value)
|
public function getDateTime($value)
|
||||||
{
|
{
|
||||||
$value = trim($value);
|
$value = trim($value);
|
||||||
|
|
||||||
@ -73,14 +73,13 @@ class DateParser
|
|||||||
$truncated_value = substr($truncated_value, 0, $length);
|
$truncated_value = substr($truncated_value, 0, $length);
|
||||||
}
|
}
|
||||||
|
|
||||||
$timestamp = $this->getValidDate($format, $truncated_value);
|
$date = $this->getValidDate($format, $truncated_value);
|
||||||
if ($timestamp > 0) {
|
if ($date !== false) {
|
||||||
return $timestamp;
|
return $date;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$date = new DateTime('now', new DateTimeZone($this->timezone));
|
return $this->getCurrentDateTime();
|
||||||
return $date->getTimestamp();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -89,7 +88,7 @@ class DateParser
|
|||||||
* @access public
|
* @access public
|
||||||
* @param string $format Date format
|
* @param string $format Date format
|
||||||
* @param string $value Original date value
|
* @param string $value Original date value
|
||||||
* @return integer Timestamp
|
* @return DateTime
|
||||||
*/
|
*/
|
||||||
public function getValidDate($format, $value)
|
public function getValidDate($format, $value)
|
||||||
{
|
{
|
||||||
@ -100,10 +99,21 @@ class DateParser
|
|||||||
$errors = DateTime::getLastErrors();
|
$errors = DateTime::getLastErrors();
|
||||||
|
|
||||||
if ($errors['error_count'] === 0 && $errors['warning_count'] === 0) {
|
if ($errors['error_count'] === 0 && $errors['warning_count'] === 0) {
|
||||||
return $date->getTimestamp();
|
return $date;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the current datetime
|
||||||
|
*
|
||||||
|
* @access public
|
||||||
|
* @return DateTime
|
||||||
|
*/
|
||||||
|
public function getCurrentDateTime()
|
||||||
|
{
|
||||||
|
return new DateTime('now', new DateTimeZone($this->timezone));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -62,9 +62,9 @@ class Feed
|
|||||||
* Feed date
|
* Feed date
|
||||||
*
|
*
|
||||||
* @access public
|
* @access public
|
||||||
* @var integer
|
* @var \DateTime
|
||||||
*/
|
*/
|
||||||
public $date = 0;
|
public $date = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Feed language
|
* Feed language
|
||||||
@ -100,10 +100,11 @@ class Feed
|
|||||||
{
|
{
|
||||||
$output = '';
|
$output = '';
|
||||||
|
|
||||||
foreach (array('id', 'title', 'feed_url', 'site_url', 'date', 'language', 'description', 'logo') as $property) {
|
foreach (array('id', 'title', 'feed_url', 'site_url', 'language', 'description', 'logo') as $property) {
|
||||||
$output .= 'Feed::'.$property.' = '.$this->$property.PHP_EOL;
|
$output .= 'Feed::'.$property.' = '.$this->$property.PHP_EOL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$output .= 'Feed::date = '.$this->date->format(DATE_RFC822).PHP_EOL;
|
||||||
$output .= 'Feed::isRTL() = '.($this->isRTL() ? 'true' : 'false').PHP_EOL;
|
$output .= 'Feed::isRTL() = '.($this->isRTL() ? 'true' : 'false').PHP_EOL;
|
||||||
$output .= 'Feed::items = '.count($this->items).' items'.PHP_EOL;
|
$output .= 'Feed::items = '.count($this->items).' items'.PHP_EOL;
|
||||||
|
|
||||||
|
@ -63,9 +63,9 @@ class Item
|
|||||||
* Item date
|
* Item date
|
||||||
*
|
*
|
||||||
* @access public
|
* @access public
|
||||||
* @var integer
|
* @var \DateTime
|
||||||
*/
|
*/
|
||||||
public $date = 0;
|
public $date = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Item content
|
* Item content
|
||||||
@ -109,10 +109,11 @@ class Item
|
|||||||
{
|
{
|
||||||
$output = '';
|
$output = '';
|
||||||
|
|
||||||
foreach (array('id', 'title', 'url', 'date', 'language', 'author', 'enclosure_url', 'enclosure_type') as $property) {
|
foreach (array('id', 'title', 'url', 'language', 'author', 'enclosure_url', 'enclosure_type') as $property) {
|
||||||
$output .= 'Item::'.$property.' = '.$this->$property.PHP_EOL;
|
$output .= 'Item::'.$property.' = '.$this->$property.PHP_EOL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$output .= 'Item::date = '.$this->date->format(DATE_RFC822).PHP_EOL;
|
||||||
$output .= 'Item::isRTL() = '.($this->isRTL() ? 'true' : 'false').PHP_EOL;
|
$output .= 'Item::isRTL() = '.($this->isRTL() ? 'true' : 'false').PHP_EOL;
|
||||||
$output .= 'Item::content = '.strlen($this->content).' bytes'.PHP_EOL;
|
$output .= 'Item::content = '.strlen($this->content).' bytes'.PHP_EOL;
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ class Rss10 extends Rss20
|
|||||||
*/
|
*/
|
||||||
public function findFeedDate(SimpleXMLElement $xml, Feed $feed)
|
public function findFeedDate(SimpleXMLElement $xml, Feed $feed)
|
||||||
{
|
{
|
||||||
$feed->date = $this->date->getTimestamp(XmlParser::getNamespaceValue($xml->channel, $this->namespaces, 'date'));
|
$feed->date = $this->date->getDateTime(XmlParser::getNamespaceValue($xml->channel, $this->namespaces, 'date'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -134,7 +134,7 @@ class Rss20 extends Parser
|
|||||||
public function findFeedDate(SimpleXMLElement $xml, Feed $feed)
|
public function findFeedDate(SimpleXMLElement $xml, Feed $feed)
|
||||||
{
|
{
|
||||||
$date = isset($xml->channel->pubDate) ? $xml->channel->pubDate : $xml->channel->lastBuildDate;
|
$date = isset($xml->channel->pubDate) ? $xml->channel->pubDate : $xml->channel->lastBuildDate;
|
||||||
$feed->date = $this->date->getTimestamp((string) $date);
|
$feed->date = $this->date->getDateTime((string) $date);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -156,7 +156,7 @@ class Rss20 extends Parser
|
|||||||
$date = (string) $entry->pubDate;
|
$date = (string) $entry->pubDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
$item->date = $this->date->getTimestamp($date);
|
$item->date = $this->date->getDateTime($date);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -208,7 +208,7 @@ class Rss20 extends Parser
|
|||||||
{
|
{
|
||||||
$content = XmlParser::getNamespaceValue($entry, $this->namespaces, 'encoded');
|
$content = XmlParser::getNamespaceValue($entry, $this->namespaces, 'encoded');
|
||||||
|
|
||||||
if (empty($content) && $entry->description->count() > 0) {
|
if (trim($content) === '' && $entry->description->count() > 0) {
|
||||||
$content = (string) $entry->description;
|
$content = (string) $entry->description;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -90,10 +90,14 @@ class XmlParser
|
|||||||
* @static
|
* @static
|
||||||
* @access public
|
* @access public
|
||||||
* @param string $input XML content
|
* @param string $input XML content
|
||||||
* @return \DOMNode
|
* @return \DOMNDocument
|
||||||
*/
|
*/
|
||||||
public static function getDomDocument($input)
|
public static function getDomDocument($input)
|
||||||
{
|
{
|
||||||
|
if (empty($input)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
$dom = self::scanInput($input, function ($in) {
|
$dom = self::scanInput($input, function ($in) {
|
||||||
$dom = new DomDocument;
|
$dom = new DomDocument;
|
||||||
$dom->loadXml($in, LIBXML_NONET);
|
$dom->loadXml($in, LIBXML_NONET);
|
||||||
@ -207,6 +211,49 @@ class XmlParser
|
|||||||
return $encoding;
|
return $encoding;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extract charset from meta tag
|
||||||
|
*
|
||||||
|
* @static
|
||||||
|
* @access public
|
||||||
|
* @param string $data meta tag content
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public static function findCharset($data)
|
||||||
|
{
|
||||||
|
$result = explode('charset=', $data);
|
||||||
|
return isset($result[1]) ? $result[1] : $data;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the encoding from a xml tag
|
||||||
|
*
|
||||||
|
* @static
|
||||||
|
* @access public
|
||||||
|
* @param string $data Input data
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public static function getEncodingFromMetaTag($data)
|
||||||
|
{
|
||||||
|
$encoding = '';
|
||||||
|
|
||||||
|
$dom = static::getHtmlDocument($data);
|
||||||
|
$xpath = new DOMXPath($dom);
|
||||||
|
|
||||||
|
$tags = array(
|
||||||
|
'/html/head/meta[translate(@http-equiv, "CENOPTY", "cenopty")="content-type"]/@content', //HTML4, convert upper to lower-case
|
||||||
|
'/html/head/meta/@charset', //HTML5
|
||||||
|
);
|
||||||
|
|
||||||
|
$nodes = $xpath->query(implode(' | ', $tags));
|
||||||
|
|
||||||
|
foreach ($nodes as $node) {
|
||||||
|
$encoding = static::findCharset($node->nodeValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $encoding;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get xml:lang value
|
* Get xml:lang value
|
||||||
*
|
*
|
||||||
|
@ -5,8 +5,6 @@ return array(
|
|||||||
'//div[@class="entry"]',
|
'//div[@class="entry"]',
|
||||||
),
|
),
|
||||||
'strip' => array(
|
'strip' => array(
|
||||||
'//script',
|
|
||||||
'//style',
|
|
||||||
'//*[@id="linker_widget"]',
|
'//*[@id="linker_widget"]',
|
||||||
'//*[contains(@class, "bio")]',
|
'//*[contains(@class, "bio")]',
|
||||||
'//*[contains(@class, "entry-footer")]',
|
'//*[contains(@class, "entry-footer")]',
|
||||||
|
@ -5,7 +5,6 @@ return array(
|
|||||||
'//div[@class="article_ventre_box"]',
|
'//div[@class="article_ventre_box"]',
|
||||||
),
|
),
|
||||||
'strip' => array(
|
'strip' => array(
|
||||||
'//script',
|
|
||||||
'//link',
|
'//link',
|
||||||
'//*[contains(@class, "article_navigation")]',
|
'//*[contains(@class, "article_navigation")]',
|
||||||
'//h1',
|
'//h1',
|
||||||
|
@ -3,8 +3,5 @@ return array(
|
|||||||
'test_url' => 'http://www./2014/05/20/le-playstation-now-arrive-en-beta-fermee-aux-etats-unis/',
|
'test_url' => 'http://www./2014/05/20/le-playstation-now-arrive-en-beta-fermee-aux-etats-unis/',
|
||||||
'body' => array(
|
'body' => array(
|
||||||
'//div[@class="post-content"]',
|
'//div[@class="post-content"]',
|
||||||
),
|
|
||||||
'strip' => array(
|
|
||||||
'//style'
|
|
||||||
)
|
)
|
||||||
);
|
);
|
@ -5,7 +5,6 @@ return array(
|
|||||||
'//div[@class="entry"]'
|
'//div[@class="entry"]'
|
||||||
),
|
),
|
||||||
'strip' => array(
|
'strip' => array(
|
||||||
'//script',
|
|
||||||
'//*[contains(@class, "addthis_toolbox")]',
|
'//*[contains(@class, "addthis_toolbox")]',
|
||||||
'//*[contains(@class, "addthis_default_style")]',
|
'//*[contains(@class, "addthis_default_style")]',
|
||||||
'//*[@class="navigation small"]',
|
'//*[@class="navigation small"]',
|
||||||
|
@ -5,8 +5,6 @@ return array(
|
|||||||
'//div[@class="post-content"]',
|
'//div[@class="post-content"]',
|
||||||
),
|
),
|
||||||
'strip' => array(
|
'strip' => array(
|
||||||
'//style',
|
|
||||||
'//script',
|
|
||||||
'//*[contains(@class, "gallery")]',
|
'//*[contains(@class, "gallery")]',
|
||||||
'//*[contains(@class, "share")]',
|
'//*[contains(@class, "share")]',
|
||||||
'//*[contains(@class, "wpcnt")]',
|
'//*[contains(@class, "wpcnt")]',
|
||||||
|
@ -2,6 +2,6 @@
|
|||||||
return array(
|
return array(
|
||||||
'test_url' => 'http://www.spiegel.de/politik/ausland/afrika-angola-geht-gegen-islam-vor-und-schliesst-moscheen-a-935788.html',
|
'test_url' => 'http://www.spiegel.de/politik/ausland/afrika-angola-geht-gegen-islam-vor-und-schliesst-moscheen-a-935788.html',
|
||||||
'body' => array(
|
'body' => array(
|
||||||
'//h2[contains(@class, "article-section")]'
|
'//div[contains(@class, "article-section")]'
|
||||||
)
|
)
|
||||||
);
|
);
|
@ -6,8 +6,6 @@ return array(
|
|||||||
'//div[@class="body-copy"]',
|
'//div[@class="body-copy"]',
|
||||||
),
|
),
|
||||||
'strip' => array(
|
'strip' => array(
|
||||||
'//script',
|
|
||||||
'//style',
|
|
||||||
'//*[contains(@class, "module-crunchbase")]'
|
'//*[contains(@class, "module-crunchbase")]'
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
@ -5,7 +5,6 @@ return array(
|
|||||||
'/html/body/table[3]/tbody/tr/td[1]/table[2]/tr/td[1]'
|
'/html/body/table[3]/tbody/tr/td[1]/table[2]/tr/td[1]'
|
||||||
),
|
),
|
||||||
'strip' => array(
|
'strip' => array(
|
||||||
'//style',
|
|
||||||
'//font',
|
'//font',
|
||||||
),
|
),
|
||||||
);
|
);
|
@ -6,9 +6,7 @@ return array(
|
|||||||
'//div[@class="indPost"]'
|
'//div[@class="indPost"]'
|
||||||
),
|
),
|
||||||
'strip' => array(
|
'strip' => array(
|
||||||
'//script',
|
|
||||||
'//form',
|
'//form',
|
||||||
'//style',
|
|
||||||
'//*[@class="warning"]',
|
'//*[@class="warning"]',
|
||||||
'//*[@class="story-date"]',
|
'//*[@class="story-date"]',
|
||||||
'//*[@class="story-header"]',
|
'//*[@class="story-header"]',
|
||||||
|
@ -5,8 +5,6 @@ return array(
|
|||||||
'//div[@class="cnn_strycntntlft"]',
|
'//div[@class="cnn_strycntntlft"]',
|
||||||
),
|
),
|
||||||
'strip' => array(
|
'strip' => array(
|
||||||
'//script',
|
|
||||||
'//style',
|
|
||||||
'//div[@class="cnn_stryshrwdgtbtm"]',
|
'//div[@class="cnn_stryshrwdgtbtm"]',
|
||||||
'//div[@class="cnn_strybtmcntnt"]',
|
'//div[@class="cnn_strybtmcntnt"]',
|
||||||
'//div[@class="cnn_strylftcntnt"]',
|
'//div[@class="cnn_strylftcntnt"]',
|
||||||
|
@ -5,8 +5,6 @@ return array(
|
|||||||
'//article',
|
'//article',
|
||||||
),
|
),
|
||||||
'strip' => array(
|
'strip' => array(
|
||||||
'//script',
|
|
||||||
'//style',
|
|
||||||
'//*[contains(@class, "info_article")]',
|
'//*[contains(@class, "info_article")]',
|
||||||
'//*[contains(@class, "fildariane_titre")]',
|
'//*[contains(@class, "fildariane_titre")]',
|
||||||
'//*[contains(@class, "entete2_article")]',
|
'//*[contains(@class, "entete2_article")]',
|
||||||
|
@ -5,8 +5,6 @@ return array(
|
|||||||
'//div[@id="storytext"]',
|
'//div[@id="storytext"]',
|
||||||
),
|
),
|
||||||
'strip' => array(
|
'strip' => array(
|
||||||
'//script',
|
|
||||||
'//style',
|
|
||||||
'//*[@class="bucket img"]',
|
'//*[@class="bucket img"]',
|
||||||
'//*[@class="creditwrap"]',
|
'//*[@class="creditwrap"]',
|
||||||
'//*[@class="captionwrap"]',
|
'//*[@class="captionwrap"]',
|
||||||
|
@ -5,8 +5,6 @@ return array(
|
|||||||
'//div[@class="article_content"]',
|
'//div[@class="article_content"]',
|
||||||
),
|
),
|
||||||
'strip' => array(
|
'strip' => array(
|
||||||
'//script',
|
|
||||||
'//style',
|
|
||||||
'//*[@id="slate_associated_bn"]',
|
'//*[@id="slate_associated_bn"]',
|
||||||
'//*[@id="ligatus-article"]',
|
'//*[@id="ligatus-article"]',
|
||||||
'//*[@id="article_sidebar"]',
|
'//*[@id="article_sidebar"]',
|
||||||
|
@ -18,19 +18,18 @@ class ClientTest extends PHPUnit_Framework_TestCase
|
|||||||
$this->assertNotEmpty($client->getLastModified());
|
$this->assertNotEmpty($client->getLastModified());
|
||||||
}
|
}
|
||||||
|
|
||||||
// // disabled due to https://github.com/sebastianbergmann/phpunit/issues/1452
|
/**
|
||||||
// /**
|
* @runInSeparateProcess
|
||||||
// * @runInSeparateProcess
|
*/
|
||||||
// */
|
public function testPassthrough()
|
||||||
// public function testPassthrough()
|
{
|
||||||
// {
|
$client = Client::getInstance();
|
||||||
// $client = Client::getInstance();
|
$client->setUrl('http://miniflux.net/favicon.ico');
|
||||||
// $client->setUrl('http://miniflux.net/favicon.ico');
|
$client->enablePassthroughMode();
|
||||||
// $client->enablePassthroughMode();
|
$client->execute();
|
||||||
// $client->execute();
|
|
||||||
//
|
$this->expectOutputString(file_get_contents('tests/fixtures/miniflux_favicon.ico'));
|
||||||
// $this->expectOutputString('no_to_be_defined');
|
}
|
||||||
// }
|
|
||||||
|
|
||||||
public function testCacheBothHaveToMatch()
|
public function testCacheBothHaveToMatch()
|
||||||
{
|
{
|
||||||
|
@ -18,19 +18,18 @@ class CurlTest extends PHPUnit_Framework_TestCase
|
|||||||
$this->assertEquals('text/html; charset=utf-8', $result['headers']['Content-Type']);
|
$this->assertEquals('text/html; charset=utf-8', $result['headers']['Content-Type']);
|
||||||
}
|
}
|
||||||
|
|
||||||
// // disabled due to https://github.com/sebastianbergmann/phpunit/issues/1452
|
/**
|
||||||
// /**
|
* @runInSeparateProcess
|
||||||
// * @runInSeparateProcess
|
*/
|
||||||
// */
|
public function testPassthrough()
|
||||||
// public function testPassthrough()
|
{
|
||||||
// {
|
$client = new Curl;
|
||||||
// $client = new Curl;
|
$client->setUrl('http://miniflux.net/favicon.ico');
|
||||||
// $client->setUrl('http://miniflux.net/favicon.ico');
|
$client->enablePassthroughMode();
|
||||||
// $client->enablePassthroughMode();
|
$client->doRequest();
|
||||||
// $client->doRequest();
|
|
||||||
//
|
$this->expectOutputString(file_get_contents('tests/fixtures/miniflux_favicon.ico'));
|
||||||
// $this->expectOutputString('no_to_be_defined');
|
}
|
||||||
// }
|
|
||||||
|
|
||||||
public function testRedirect()
|
public function testRedirect()
|
||||||
{
|
{
|
||||||
|
@ -27,19 +27,18 @@ class StreamTest extends PHPUnit_Framework_TestCase
|
|||||||
$this->assertEquals('</html>', substr(trim($result['body']), -7));
|
$this->assertEquals('</html>', substr(trim($result['body']), -7));
|
||||||
}
|
}
|
||||||
|
|
||||||
// // disabled due to https://github.com/sebastianbergmann/phpunit/issues/1452
|
/**
|
||||||
// /**
|
* @runInSeparateProcess
|
||||||
// * @runInSeparateProcess
|
*/
|
||||||
// */
|
public function testPassthrough()
|
||||||
// public function testPassthrough()
|
{
|
||||||
// {
|
$client = new Stream;
|
||||||
// $client = new Stream;
|
$client->setUrl('http://miniflux.net/favicon.ico');
|
||||||
// $client->setUrl('http://miniflux.net/favicon.ico');
|
$client->enablePassthroughMode();
|
||||||
// $client->enablePassthroughMode();
|
$client->doRequest();
|
||||||
// $client->doRequest();
|
|
||||||
//
|
$this->expectOutputString(file_get_contents('tests/fixtures/miniflux_favicon.ico'));
|
||||||
// $this->expectOutputString('no_to_be_defined');
|
}
|
||||||
// }
|
|
||||||
|
|
||||||
public function testRedirect()
|
public function testRedirect()
|
||||||
{
|
{
|
||||||
|
@ -39,8 +39,8 @@ class AttributeFilterTest extends PHPUnit_Framework_TestCase
|
|||||||
$this->assertTrue($filter->filterIntegerAttribute('iframe', 'width', '450'));
|
$this->assertTrue($filter->filterIntegerAttribute('iframe', 'width', '450'));
|
||||||
$this->assertFalse($filter->filterIntegerAttribute('iframe', 'width', 'test'));
|
$this->assertFalse($filter->filterIntegerAttribute('iframe', 'width', 'test'));
|
||||||
|
|
||||||
$this->assertEquals(array('width' => '10', 'src' => 'http://www.youtube.com/test'), $filter->filter('iframe', array('width' => '10', 'src' => 'http://www.youtube.com/test')));
|
$this->assertEquals(array('width' => '10', 'src' => 'https://www.youtube.com/test'), $filter->filter('iframe', array('width' => '10', 'src' => 'http://www.youtube.com/test')));
|
||||||
$this->assertEquals(array('src' => 'http://www.youtube.com/test'), $filter->filter('iframe', array('width' => 'test', 'src' => 'http://www.youtube.com/test')));
|
$this->assertEquals(array('src' => 'https://www.youtube.com/test'), $filter->filter('iframe', array('width' => 'test', 'src' => 'http://www.youtube.com/test')));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testRewriteProxyImageUrl()
|
public function testRewriteProxyImageUrl()
|
||||||
@ -125,7 +125,7 @@ class AttributeFilterTest extends PHPUnit_Framework_TestCase
|
|||||||
$this->assertFalse($filter->filterIframeAttribute('iframe', 'src', '//www.youtube.com/test'));
|
$this->assertFalse($filter->filterIframeAttribute('iframe', 'src', '//www.youtube.com/test'));
|
||||||
$this->assertFalse($filter->filterIframeAttribute('iframe', 'src', '//www.bidule.com/test'));
|
$this->assertFalse($filter->filterIframeAttribute('iframe', 'src', '//www.bidule.com/test'));
|
||||||
|
|
||||||
$this->assertEquals(array('src' => 'http://www.youtube.com/test'), $filter->filter('iframe', array('src' => '//www.youtube.com/test')));
|
$this->assertEquals(array('src' => 'https://www.youtube.com/test'), $filter->filter('iframe', array('src' => '//www.youtube.com/test')));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testFilterBlacklistAttribute()
|
public function testFilterBlacklistAttribute()
|
||||||
|
@ -71,10 +71,11 @@ class FilterTest extends PHPUnit_Framework_TestCase
|
|||||||
public function testOverrideFilters()
|
public function testOverrideFilters()
|
||||||
{
|
{
|
||||||
$data = '<iframe src="http://www.kickstarter.com/projects/lefnire/habitrpg-mobile/widget/video.html" height="480" width="640" frameborder="0"></iframe>';
|
$data = '<iframe src="http://www.kickstarter.com/projects/lefnire/habitrpg-mobile/widget/video.html" height="480" width="640" frameborder="0"></iframe>';
|
||||||
|
$expected = '<iframe src="https://www.kickstarter.com/projects/lefnire/habitrpg-mobile/widget/video.html" height="480" width="640" frameborder="0"></iframe>';
|
||||||
|
|
||||||
$f = Filter::html($data, 'http://blabla');
|
$f = Filter::html($data, 'http://blabla');
|
||||||
$f->attribute->setIframeWhitelist(array('http://www.kickstarter.com'));
|
$f->attribute->setIframeWhitelist(array('http://www.kickstarter.com'));
|
||||||
$this->assertEquals($data, $f->execute());
|
$this->assertEquals($expected, $f->execute());
|
||||||
|
|
||||||
$data = '<iframe src="http://www.youtube.com/bla" height="480" width="640" frameborder="0"></iframe>';
|
$data = '<iframe src="http://www.youtube.com/bla" height="480" width="640" frameborder="0"></iframe>';
|
||||||
|
|
||||||
|
@ -1,11 +1,17 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace PicoFeed\Filter;
|
namespace PicoFeed\Filter;
|
||||||
|
|
||||||
use PHPUnit_Framework_TestCase;
|
use PHPUnit_Framework_TestCase;
|
||||||
|
|
||||||
|
|
||||||
class HtmlFilterTest extends PHPUnit_Framework_TestCase
|
class HtmlFilterTest extends PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
|
public function testEmpty()
|
||||||
|
{
|
||||||
|
$filter = new Html('', 'http://www.google.ca/');
|
||||||
|
$this->assertEquals('', $filter->execute());
|
||||||
|
}
|
||||||
|
|
||||||
public function testExecute()
|
public function testExecute()
|
||||||
{
|
{
|
||||||
$html = '<!DOCTYPE html><html><head>
|
$html = '<!DOCTYPE html><html><head>
|
||||||
@ -25,9 +31,28 @@ class HtmlFilterTest extends PHPUnit_Framework_TestCase
|
|||||||
$this->assertEmpty($f->execute());
|
$this->assertEmpty($f->execute());
|
||||||
|
|
||||||
$data = '<iframe src="http://www.youtube.com/bla" height="480" width="640" frameborder="0"></iframe>';
|
$data = '<iframe src="http://www.youtube.com/bla" height="480" width="640" frameborder="0"></iframe>';
|
||||||
|
$expected = '<iframe src="https://www.youtube.com/bla" height="480" width="640" frameborder="0"></iframe>';
|
||||||
|
|
||||||
$f = new Html($data, 'http://blabla');
|
$f = new Html($data, 'http://blabla');
|
||||||
$this->assertEquals($data, $f->execute());
|
$this->assertEquals($expected, $f->execute());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testClearScriptAttributes()
|
||||||
|
{
|
||||||
|
$data = '<div><script>this is the content</script><script>blubb content</script><p>something</p></div><p>hi</p>';
|
||||||
|
|
||||||
|
$f = new Html($data, 'http://blabla');
|
||||||
|
$expected = '<p>something</p><p>hi</p>';
|
||||||
|
$this->assertEquals($expected, $f->execute());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testClearStyleAttributes()
|
||||||
|
{
|
||||||
|
$data = '<div><style>this is the content</style><style>blubb content</style><p>something</p></div><p>hi</p>';
|
||||||
|
|
||||||
|
$f = new Html($data, 'http://blabla');
|
||||||
|
$expected = '<p>something</p><p>hi</p>';
|
||||||
|
$this->assertEquals($expected, $f->execute());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testEmptyTags()
|
public function testEmptyTags()
|
||||||
@ -50,7 +75,7 @@ EOD;
|
|||||||
$data = '<iframe src="http://www.youtube.com/bla" height="480px" width="100%" frameborder="0"></iframe>';
|
$data = '<iframe src="http://www.youtube.com/bla" height="480px" width="100%" frameborder="0"></iframe>';
|
||||||
|
|
||||||
$f = new Html($data, 'http://blabla');
|
$f = new Html($data, 'http://blabla');
|
||||||
$this->assertEquals('<iframe src="http://www.youtube.com/bla" frameborder="0"></iframe>', $f->execute());
|
$this->assertEquals('<iframe src="https://www.youtube.com/bla" frameborder="0"></iframe>', $f->execute());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testRelativeScheme()
|
public function testRelativeScheme()
|
||||||
@ -123,46 +148,4 @@ x-amz-id-2: DDjqfqz2ZJufzqRAcj1mh+9XvSogrPohKHwXlo8IlkzH67G6w4wnjn9HYgbs4uI0
|
|||||||
$f = new Html('<table><tr></tr></table>', 'http://blabla');
|
$f = new Html('<table><tr></tr></table>', 'http://blabla');
|
||||||
$this->assertEquals('', $f->execute());
|
$this->assertEquals('', $f->execute());
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
public function testFilter()
|
|
||||||
{
|
|
||||||
$input = <<<EOD
|
|
||||||
<div xmlns="http://www.w3.org/1999/xhtml"><article>
|
|
||||||
<figure>
|
|
||||||
<img src="/2014/08/06/4694-pluie" alt="Flaque de pluie"/>
|
|
||||||
<figcaption>La Saussaye, France, 6 août 2014</figcaption>
|
|
||||||
</figure>
|
|
||||||
|
|
||||||
<div lang="en" class="extrait">
|
|
||||||
<blockquote cite="urn:isbn:978-0-8248-3742-6">
|
|
||||||
<p>Spring had truly arrived. Countless streams suddenly materialized all over the roads, fields, grasslands, and thickets; flowing as if the melting snow's waters were spilling over. </p>
|
|
||||||
</blockquote>
|
|
||||||
<p class="source"><span class="auteur">Takiji Kobayashi</span>, <cite class="titre">Yasuko</cite>.</p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<p>La pluie abonde. La forêt humide resplendit. L'eau monte, l'eau déborde. Il reste pourtant notre humanité. Toute entière, resplendissante.</p>
|
|
||||||
|
|
||||||
</article>
|
|
||||||
</div>
|
|
||||||
EOD;
|
|
||||||
|
|
||||||
$expected = <<<EOD
|
|
||||||
<figure>
|
|
||||||
<img src="http://www.la-grange.net/2014/08/06/4694-pluie" alt="Flaque de pluie"/>
|
|
||||||
<figcaption>La Saussaye, France, 6 août 2014</figcaption>
|
|
||||||
</figure>
|
|
||||||
|
|
||||||
|
|
||||||
<blockquote>
|
|
||||||
<p>Spring had truly arrived. Countless streams suddenly materialized all over the roads, fields, grasslands, and thickets; flowing as if the melting snow's waters were spilling over. </p>
|
|
||||||
</blockquote>
|
|
||||||
<p>Takiji Kobayashi, <cite>Yasuko</cite>.</p>
|
|
||||||
|
|
||||||
|
|
||||||
<p>La pluie abonde. La forêt humide resplendit. L'eau monte, l'eau déborde. Il reste pourtant notre humanité. Toute entière, resplendissante.</p>
|
|
||||||
EOD;
|
|
||||||
|
|
||||||
$f = new Html($input, 'http://www.la-grange.net/');
|
|
||||||
$this->assertEquals($expected, $f->execute());
|
|
||||||
}*/
|
|
||||||
}
|
}
|
||||||
|
@ -119,11 +119,11 @@ class AtomParserTest extends PHPUnit_Framework_TestCase
|
|||||||
{
|
{
|
||||||
$parser = new Atom(file_get_contents('tests/fixtures/atom.xml'));
|
$parser = new Atom(file_get_contents('tests/fixtures/atom.xml'));
|
||||||
$feed = $parser->execute();
|
$feed = $parser->execute();
|
||||||
$this->assertEquals(1360148333, $feed->getDate());
|
$this->assertEquals(1360148333, $feed->getDate()->getTimestamp(), '', 1);
|
||||||
|
|
||||||
$parser = new Atom(file_get_contents('tests/fixtures/atomsample.xml'));
|
$parser = new Atom(file_get_contents('tests/fixtures/atomsample.xml'));
|
||||||
$feed = $parser->execute();
|
$feed = $parser->execute();
|
||||||
$this->assertEquals(1071340202, $feed->getDate());
|
$this->assertEquals(1071340202, $feed->getDate()->getTimestamp(), '', 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testFeedLanguage()
|
public function testFeedLanguage()
|
||||||
@ -196,17 +196,17 @@ class AtomParserTest extends PHPUnit_Framework_TestCase
|
|||||||
$parser = new Atom(file_get_contents('tests/fixtures/atom.xml'));
|
$parser = new Atom(file_get_contents('tests/fixtures/atom.xml'));
|
||||||
$feed = $parser->execute();
|
$feed = $parser->execute();
|
||||||
$this->assertNotEmpty($feed->items);
|
$this->assertNotEmpty($feed->items);
|
||||||
$this->assertEquals(1360011661, $feed->items[1]->getDate());
|
$this->assertEquals(1360011661, $feed->items[1]->getDate()->getTimestamp(), '', 1);
|
||||||
|
|
||||||
$parser = new Atom(file_get_contents('tests/fixtures/atomsample.xml'));
|
$parser = new Atom(file_get_contents('tests/fixtures/atomsample.xml'));
|
||||||
$feed = $parser->execute();
|
$feed = $parser->execute();
|
||||||
$this->assertNotEmpty($feed->items);
|
$this->assertNotEmpty($feed->items);
|
||||||
$this->assertEquals(1071340202, $feed->items[0]->getDate());
|
$this->assertEquals(1071340202, $feed->items[0]->getDate()->getTimestamp(), '', 1);
|
||||||
|
|
||||||
$parser = new Atom(file_get_contents('tests/fixtures/youtube.xml'));
|
$parser = new Atom(file_get_contents('tests/fixtures/youtube.xml'));
|
||||||
$feed = $parser->execute();
|
$feed = $parser->execute();
|
||||||
$this->assertNotEmpty($feed->items);
|
$this->assertNotEmpty($feed->items);
|
||||||
$this->assertEquals(1336825342, $feed->items[1]->getDate()); // Should return the published date
|
$this->assertEquals(1336825342, $feed->items[1]->getDate()->getTimestamp(), '', 1); // Should return the published date
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testItemLanguage()
|
public function testItemLanguage()
|
||||||
|
@ -12,37 +12,37 @@ class DateParserTest extends PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
date_default_timezone_set('UTC');
|
date_default_timezone_set('UTC');
|
||||||
|
|
||||||
$this->assertEquals(1359066183, $parser->getTimestamp('Thu, 24 Jan 2013 22:23:03 +0000'));
|
$this->assertEquals(1359066183, $parser->getDateTime('Thu, 24 Jan 2013 22:23:03 +0000')->getTimestamp(), '', 1);
|
||||||
$this->assertEquals(1362992761, $parser->getTimestamp('2013-03-11T09:06:01+00:00'));
|
$this->assertEquals(1362992761, $parser->getDateTime('2013-03-11T09:06:01+00:00')->getTimestamp(), '', 1);
|
||||||
$this->assertEquals(1363752990, $parser->getTimestamp('2013-03-20T04:16:30+00:00'));
|
$this->assertEquals(1363752990, $parser->getDateTime('2013-03-20T04:16:30+00:00')->getTimestamp(), '', 1);
|
||||||
$this->assertEquals(1359066183, $parser->getTimestamp('Thu, 24 Jan 2013 22:23:03 +0000'));
|
$this->assertEquals(1359066183, $parser->getDateTime('Thu, 24 Jan 2013 22:23:03 +0000')->getTimestamp(), '', 1);
|
||||||
$this->assertEquals(1380929699, $parser->getTimestamp('Sat, 04 Oct 2013 02:34:59 +0300'));
|
$this->assertEquals(1380929699, $parser->getDateTime('Sat, 04 Oct 2013 02:34:59 +0300')->getTimestamp(), '', 1);
|
||||||
$this->assertEquals(1054633161, $parser->getTimestamp('Tue, 03 Jun 2003 09:39:21 GMT'));
|
$this->assertEquals(1054633161, $parser->getDateTime('Tue, 03 Jun 2003 09:39:21 GMT')->getTimestamp(), '', 1);
|
||||||
$this->assertEquals(1071340202, $parser->getTimestamp('2003-12-13T18:30:02Z'));
|
$this->assertEquals(1071340202, $parser->getDateTime('2003-12-13T18:30:02Z')->getTimestamp(), '', 1);
|
||||||
$this->assertEquals(1364234797, $parser->getTimestamp('Mon, 25 Mar 2013 19:06:37 +0100'));
|
$this->assertEquals(1364234797, $parser->getDateTime('Mon, 25 Mar 2013 19:06:37 +0100')->getTimestamp(), '', 1);
|
||||||
$this->assertEquals(1360054941, $parser->getTimestamp('2013-02-05T09:02:21.880-08:00'));
|
$this->assertEquals(1360054941, $parser->getDateTime('2013-02-05T09:02:21.880-08:00')->getTimestamp(), '', 1);
|
||||||
$this->assertEquals(1286834400, $parser->getTimestamp('Tue, 12 Oct 2010 00:00:00 IST'));
|
$this->assertEquals(1286834400, $parser->getDateTime('Tue, 12 Oct 2010 00:00:00 IST')->getTimestamp(), '', 1);
|
||||||
$this->assertEquals('2014-12-15 19:49', date('Y-m-d H:i', $parser->getTimestamp('15 Dec 2014 19:49:07 +0100')));
|
$this->assertEquals('2014-12-15 19:49', $parser->getDateTime('15 Dec 2014 19:49:07 +0100')->format('Y-m-d H:i'));
|
||||||
$this->assertEquals('2012-05-15', date('Y-m-d', $parser->getTimestamp('Tue, 15 May 2012 24:05:00 UTC')));
|
$this->assertEquals('2012-05-15', $parser->getDateTime('Tue, 15 May 2012 24:05:00 UTC')->format('Y-m-d'));
|
||||||
$this->assertEquals('2013-09-12', date('Y-m-d', $parser->getTimestamp('Thu, 12 Sep 2013 7:00:00 UTC')));
|
$this->assertEquals('2013-09-12', $parser->getDateTime('Thu, 12 Sep 2013 7:00:00 UTC')->format('Y-m-d'));
|
||||||
$this->assertEquals('2012-01-31', date('Y-m-d', $parser->getTimestamp('01.31.2012')));
|
$this->assertEquals('2012-01-31', $parser->getDateTime('01.31.2012')->format('Y-m-d'));
|
||||||
$this->assertEquals('2012-01-31', date('Y-m-d', $parser->getTimestamp('01/31/2012')));
|
$this->assertEquals('2012-01-31', $parser->getDateTime('01/31/2012')->format('Y-m-d'));
|
||||||
$this->assertEquals('2012-01-31', date('Y-m-d', $parser->getTimestamp('2012-01-31')));
|
$this->assertEquals('2012-01-31', $parser->getDateTime('2012-01-31')->format('Y-m-d'));
|
||||||
$this->assertEquals('2010-02-24', date('Y-m-d', $parser->getTimestamp('2010-02-245T15:27:52Z')));
|
$this->assertEquals('2010-02-24', $parser->getDateTime('2010-02-245T15:27:52Z')->format('Y-m-d'));
|
||||||
$this->assertEquals('2010-08-20', date('Y-m-d', $parser->getTimestamp('2010-08-20Thh:08:ssZ')));
|
$this->assertEquals('2010-08-20', $parser->getDateTime('2010-08-20Thh:08:ssZ')->format('Y-m-d'));
|
||||||
$this->assertEquals(1288648057, $parser->getTimestamp('Mon, 01 Nov 2010 21:47:37 UT'));
|
$this->assertEquals(1288648057, $parser->getDateTime('Mon, 01 Nov 2010 21:47:37 UT')->getTimestamp(), '', 1);
|
||||||
$this->assertEquals(1346069615, $parser->getTimestamp('Mon Aug 27 2012 12:13:35 GMT-0700 (PDT)'));
|
$this->assertEquals(1346069615, $parser->getDateTime('Mon Aug 27 2012 12:13:35 GMT-0700 (PDT)')->getTimestamp(), '', 1);
|
||||||
$this->assertEquals(time(), $parser->getTimestamp('Tue, 3 Febuary 2010 00:00:00 IST'), '', 1);
|
$this->assertEquals($parser->getCurrentDateTime(), $parser->getDateTime('Tue, 3 Febuary 2010 00:00:00 IST'));
|
||||||
$this->assertEquals(time(), $parser->getTimestamp('############# EST'), '', 1);
|
$this->assertEquals($parser->getCurrentDateTime(), $parser->getDateTime('############# EST'));
|
||||||
$this->assertEquals(time(), $parser->getTimestamp('Wed, 30 Nov -0001 00:00:00 +0000'), '', 1);
|
$this->assertEquals($parser->getCurrentDateTime(), $parser->getDateTime('Wed, 30 Nov -0001 00:00:00 +0000'));
|
||||||
$this->assertEquals(time(), $parser->getTimestamp('čet, 24 maj 2012 00:00:00'), '', 1);
|
$this->assertEquals($parser->getCurrentDateTime(), $parser->getDateTime('čet, 24 maj 2012 00:00:00'));
|
||||||
$this->assertEquals(time(), $parser->getTimestamp('-0-0T::Z'), '', 1);
|
$this->assertEquals($parser->getCurrentDateTime(), $parser->getDateTime('-0-0T::Z'));
|
||||||
$this->assertEquals(time(), $parser->getTimestamp('Wed, 18 2012'), '', 1);
|
$this->assertEquals($parser->getCurrentDateTime(), $parser->getDateTime('Wed, 18 2012'));
|
||||||
$this->assertEquals(time(), $parser->getTimestamp("'2009-09-30 CDT16:09:54"), '', 1);
|
$this->assertEquals($parser->getCurrentDateTime(), $parser->getDateTime("'2009-09-30 CDT16:09:54"));
|
||||||
$this->assertEquals(time(), $parser->getTimestamp('ary 8 Jan 2013 00:00:00 GMT'), '', 1);
|
$this->assertEquals($parser->getCurrentDateTime(), $parser->getDateTime('ary 8 Jan 2013 00:00:00 GMT'));
|
||||||
$this->assertEquals(time(), $parser->getTimestamp('Sat, 11 00:00:01 GMT'), '', 1);
|
$this->assertEquals($parser->getCurrentDateTime(), $parser->getDateTime('Sat, 11 00:00:01 GMT'));
|
||||||
$this->assertEquals(1370631743, $parser->getTimestamp('Fri Jun 07 2013 19:02:23 GMT+0000 (UTC)'));
|
$this->assertEquals(1370631743, $parser->getDateTime('Fri Jun 07 2013 19:02:23 GMT+0000 (UTC)')->getTimestamp(), '', 1);
|
||||||
$this->assertEquals(1377412225, $parser->getTimestamp('25/08/2013 06:30:25 م'));
|
$this->assertEquals(1377412225, $parser->getDateTime('25/08/2013 06:30:25 م')->getTimestamp(), '', 1);
|
||||||
$this->assertEquals(time(), $parser->getTimestamp('+0400'), '', 1);
|
$this->assertEquals($parser->getCurrentDateTime(), $parser->getDateTime('+0400'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -47,7 +47,7 @@ class Rss10ParserTest extends PHPUnit_Framework_TestCase
|
|||||||
{
|
{
|
||||||
$parser = new Rss10(file_get_contents('tests/fixtures/planete-jquery.xml'));
|
$parser = new Rss10(file_get_contents('tests/fixtures/planete-jquery.xml'));
|
||||||
$feed = $parser->execute();
|
$feed = $parser->execute();
|
||||||
$this->assertEquals(1363752990, $feed->getDate());
|
$this->assertEquals(1363752990, $feed->getDate()->getTimestamp(), '', 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testFeedLanguage()
|
public function testFeedLanguage()
|
||||||
@ -90,7 +90,7 @@ class Rss10ParserTest extends PHPUnit_Framework_TestCase
|
|||||||
$parser = new Rss10(file_get_contents('tests/fixtures/planete-jquery.xml'));
|
$parser = new Rss10(file_get_contents('tests/fixtures/planete-jquery.xml'));
|
||||||
$feed = $parser->execute();
|
$feed = $parser->execute();
|
||||||
$this->assertNotEmpty($feed->items);
|
$this->assertNotEmpty($feed->items);
|
||||||
$this->assertEquals(1362647700, $feed->items[1]->getDate());
|
$this->assertEquals(1362647700, $feed->items[1]->getDate()->getTimestamp(), '', 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testItemLanguage()
|
public function testItemLanguage()
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace PicoFeed\Parser;
|
namespace PicoFeed\Parser;
|
||||||
|
|
||||||
use PHPUnit_Framework_TestCase;
|
use PHPUnit_Framework_TestCase;
|
||||||
|
use DateTime;
|
||||||
|
|
||||||
class Rss20ParserTest extends PHPUnit_Framework_TestCase
|
class Rss20ParserTest extends PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
@ -89,11 +90,11 @@ class Rss20ParserTest extends PHPUnit_Framework_TestCase
|
|||||||
{
|
{
|
||||||
$parser = new Rss20(file_get_contents('tests/fixtures/rss20.xml'));
|
$parser = new Rss20(file_get_contents('tests/fixtures/rss20.xml'));
|
||||||
$feed = $parser->execute();
|
$feed = $parser->execute();
|
||||||
$this->assertEquals(1359066183, $feed->getDate());
|
$this->assertEquals(1359066183, $feed->getDate()->getTimestamp());
|
||||||
|
|
||||||
$parser = new Rss20(file_get_contents('tests/fixtures/fulltextrss.xml'));
|
$parser = new Rss20(file_get_contents('tests/fixtures/fulltextrss.xml'));
|
||||||
$feed = $parser->execute();
|
$feed = $parser->execute();
|
||||||
$this->assertEquals(time(), $feed->getDate(), '', 1);
|
$this->assertEquals(new DateTime, $feed->getDate());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testFeedLanguage()
|
public function testFeedLanguage()
|
||||||
@ -171,12 +172,12 @@ class Rss20ParserTest extends PHPUnit_Framework_TestCase
|
|||||||
$parser = new Rss20(file_get_contents('tests/fixtures/rss20.xml'));
|
$parser = new Rss20(file_get_contents('tests/fixtures/rss20.xml'));
|
||||||
$feed = $parser->execute();
|
$feed = $parser->execute();
|
||||||
$this->assertNotEmpty($feed->items);
|
$this->assertNotEmpty($feed->items);
|
||||||
$this->assertEquals(1357006940, $feed->items[1]->getDate());
|
$this->assertEquals(1357006940, $feed->items[1]->getDate()->getTimestamp());
|
||||||
|
|
||||||
$parser = new Rss20(file_get_contents('tests/fixtures/fulltextrss.xml'));
|
$parser = new Rss20(file_get_contents('tests/fixtures/fulltextrss.xml'));
|
||||||
$feed = $parser->execute();
|
$feed = $parser->execute();
|
||||||
$this->assertNotEmpty($feed->items);
|
$this->assertNotEmpty($feed->items);
|
||||||
$this->assertEquals(1365781095, $feed->items[0]->getDate());
|
$this->assertEquals(1365781095, $feed->items[0]->getDate()->getTimestamp());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testItemLanguage()
|
public function testItemLanguage()
|
||||||
@ -202,6 +203,14 @@ class Rss20ParserTest extends PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
public function testItemContent()
|
public function testItemContent()
|
||||||
{
|
{
|
||||||
|
$parser = new Rss20(file_get_contents('tests/fixtures/allgemeine-zeitung.xml'));
|
||||||
|
$feed = $parser->execute();
|
||||||
|
$this->assertNotEmpty($feed->items);
|
||||||
|
$this->assertEquals(
|
||||||
|
'<p>OBER-FLÖRSHEIM - (red). Sein erheblich beschädigtes Fahrzeug hat ein Fahrer in der Nacht von Donnerstag auf Freitag mitten auf der Ober-Flörsheimer Hauptstraße stehen lassen. Beim Verlassen des Autos in Richtung ...</p>',
|
||||||
|
$feed->items[2]->getContent()
|
||||||
|
);
|
||||||
|
|
||||||
$parser = new Rss20(file_get_contents('tests/fixtures/rss20.xml'));
|
$parser = new Rss20(file_get_contents('tests/fixtures/rss20.xml'));
|
||||||
$feed = $parser->execute();
|
$feed = $parser->execute();
|
||||||
$this->assertNotEmpty($feed->items);
|
$this->assertNotEmpty($feed->items);
|
||||||
|
@ -18,13 +18,13 @@ class Rss91ParserTest extends PHPUnit_Framework_TestCase
|
|||||||
$this->assertEquals('', $feed->getFeedUrl());
|
$this->assertEquals('', $feed->getFeedUrl());
|
||||||
$this->assertEquals('http://writetheweb.com/', $feed->getSiteUrl());
|
$this->assertEquals('http://writetheweb.com/', $feed->getSiteUrl());
|
||||||
$this->assertEquals('http://writetheweb.com/', $feed->getId());
|
$this->assertEquals('http://writetheweb.com/', $feed->getId());
|
||||||
$this->assertEquals(time(), $feed->getDate(), '', 1);
|
$this->assertEquals(time(), $feed->getDate()->getTimestamp(), '', 1);
|
||||||
$this->assertEquals(6, count($feed->items));
|
$this->assertEquals(6, count($feed->items));
|
||||||
|
|
||||||
$this->assertEquals('Giving the world a pluggable Gnutella', $feed->items[0]->getTitle());
|
$this->assertEquals('Giving the world a pluggable Gnutella', $feed->items[0]->getTitle());
|
||||||
$this->assertEquals('http://writetheweb.com/read.php?item=24', $feed->items[0]->getUrl());
|
$this->assertEquals('http://writetheweb.com/read.php?item=24', $feed->items[0]->getUrl());
|
||||||
$this->assertEquals('085a9133a75542f878fa73ee2afbb6a2350b6c4fb125e6d8ca09478c47702111', $feed->items[0]->getId());
|
$this->assertEquals('085a9133a75542f878fa73ee2afbb6a2350b6c4fb125e6d8ca09478c47702111', $feed->items[0]->getId());
|
||||||
$this->assertEquals(time(), $feed->items[0]->getDate(), '', 1);
|
$this->assertEquals(time(), $feed->items[0]->getDate()->getTimestamp(), '', 1);
|
||||||
$this->assertEquals('webmaster@writetheweb.com', $feed->items[0]->getAuthor());
|
$this->assertEquals('webmaster@writetheweb.com', $feed->items[0]->getAuthor());
|
||||||
$this->assertTrue(strpos($feed->items[1]->getContent(), '<p>After a period of dormancy') === 0);
|
$this->assertTrue(strpos($feed->items[1]->getContent(), '<p>After a period of dormancy') === 0);
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@ class Rss92ParserTest extends PHPUnit_Framework_TestCase
|
|||||||
$this->assertEquals('', $feed->getFeedUrl());
|
$this->assertEquals('', $feed->getFeedUrl());
|
||||||
$this->assertEquals('http://www.universfreebox.com/', $feed->getSiteUrl());
|
$this->assertEquals('http://www.universfreebox.com/', $feed->getSiteUrl());
|
||||||
$this->assertEquals('http://www.universfreebox.com/', $feed->getId());
|
$this->assertEquals('http://www.universfreebox.com/', $feed->getId());
|
||||||
$this->assertEquals(time(), $feed->date, '', 1);
|
$this->assertEquals(time(), $feed->getDate()->getTimestamp(), '', 1);
|
||||||
$this->assertEquals(30, count($feed->items));
|
$this->assertEquals(30, count($feed->items));
|
||||||
|
|
||||||
$this->assertEquals('Retour de Xavier Niel sur Twitter, « sans initiative privée, pas de révolution #Born2code »', $feed->items[0]->title);
|
$this->assertEquals('Retour de Xavier Niel sur Twitter, « sans initiative privée, pas de révolution #Born2code »', $feed->items[0]->title);
|
||||||
|
@ -8,6 +8,19 @@ use PHPUnit_Framework_TestCase;
|
|||||||
|
|
||||||
class XmlParserTest extends PHPUnit_Framework_TestCase
|
class XmlParserTest extends PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
|
public function testEmpty()
|
||||||
|
{
|
||||||
|
$this->assertFalse(XmlParser::getDomDocument(''));
|
||||||
|
$this->assertFalse(XmlParser::getSimpleXml(''));
|
||||||
|
$this->assertNotFalse(XmlParser::getHtmlDocument(''));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetEncodingFromMetaTag()
|
||||||
|
{
|
||||||
|
$this->assertEquals('iso-8859-1', XmlParser::getEncodingFromMetaTag('<html><head><meta content="text/html; charset=iso-8859-1" http-equiv="Content-Type"/></head></html>'));
|
||||||
|
$this->assertEquals('iso-8859-1', XmlParser::getEncodingFromMetaTag('<html><head><meta charset="iso-8859-1"></head></html>'));
|
||||||
|
}
|
||||||
|
|
||||||
public function testGetEncodingFromXmlTag()
|
public function testGetEncodingFromXmlTag()
|
||||||
{
|
{
|
||||||
$this->assertEquals('utf-8', XmlParser::getEncodingFromXmlTag("<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet"));
|
$this->assertEquals('utf-8', XmlParser::getEncodingFromXmlTag("<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet"));
|
||||||
|
122
vendor/fguillot/picofeed/tests/fixtures/allgemeine-zeitung.xml
vendored
Normal file
122
vendor/fguillot/picofeed/tests/fixtures/allgemeine-zeitung.xml
vendored
Normal file
@ -0,0 +1,122 @@
|
|||||||
|
<?xml version="1.0" encoding="iso-8859-1" standalone="yes"?>
|
||||||
|
|
||||||
|
|
||||||
|
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" version="2.0">
|
||||||
|
<channel>
|
||||||
|
<title>Allgemeine Zeitung - Aktuelle Polizei-Meldungen aus der Region</title>
|
||||||
|
<description>Allgemeine Zeitung RSS-Feed für die Rubrik Aktuelle Polizei-Meldungen aus der Region</description>
|
||||||
|
<link>http://www.allgemeine-zeitung.de</link>
|
||||||
|
<language>de</language>
|
||||||
|
<pubDate>Sun, 01 Mar 2015 19:18:57 +0100</pubDate>
|
||||||
|
<image>
|
||||||
|
<title>Allgemeine Zeitung</title>
|
||||||
|
<link>http://www.allgemeine-zeitung.de</link>
|
||||||
|
<url>http://www.allgemeine-zeitung.de/pics/edition/az/rss.png</url>
|
||||||
|
</image>
|
||||||
|
|
||||||
|
<item>
|
||||||
|
<title>Bad Kreuznach: Ursache für Brand in der ehemaligen Rose-Barracks-Kantine geklärt</title>
|
||||||
|
<link>http://www.allgemeine-zeitung.de/lokales/polizei/bad-kreuznach-ursache-fuer-brand-in-der-ehemaligen-rose-barracks-kantine-geklaert_15063090.htm</link>
|
||||||
|
<description>BAD KREUZNACH - Die Ursache für den Brand im Gebäude der ehemaligen Rose Barracks ist geklärt. Die Vermutungen zu den Tätern von Freitag haben sich bestätigt.</description>
|
||||||
|
<category>Kirn</category>
|
||||||
|
<pubDate>Sun, 01 Mar 2015 16:15:00 +0100</pubDate>
|
||||||
|
<guid>http://www.allgemeine-zeitung.de/lokales/polizei/bad-kreuznach-ursache-fuer-brand-in-der-ehemaligen-rose-barracks-kantine-geklaert_15063090.htm</guid>
|
||||||
|
<content:encoded><![CDATA[
|
||||||
|
<img src="http://www.allgemeine-zeitung.de/fm/819/thumbnails/1425035953_feuerSturm.jpg.24232019.jpg" align="left" hspace="5" border="0" alt="Die Feuerwehr im Einsatz am Gebäude in den ehemaligen Rose-Barracks. Foto: Heidi Sturm" title="Die Feuerwehr im Einsatz am Gebäude in den ehemaligen Rose-Barracks. Foto: Heidi Sturm" />
|
||||||
|
]]></content:encoded>
|
||||||
|
<enclosure type="image/jpeg" url="http://www.allgemeine-zeitung.de/fm/819/thumbnails/1425035953_feuerSturm.jpg.24232020.jpg"/>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<title>Vier Verletzte bei Verkehrsunfall auf der A61 am Autobahndreieck Nahetal</title>
|
||||||
|
<link>http://www.allgemeine-zeitung.de/lokales/polizei/vier-verletzte-bei-verkehrsunfall-auf-der-a61-am-autobahndreieck-nahetal_15061411.htm</link>
|
||||||
|
<description>GENSINGEN - Bei einem Verkehrsunfall auf der A61 am Autobahndreieck Nahetal in Fahrtrichtung Koblenz sind vier Personen verletzt worden.</description>
|
||||||
|
<category>Kirn</category>
|
||||||
|
<pubDate>Sat, 28 Feb 2015 18:28:00 +0100</pubDate>
|
||||||
|
<guid>http://www.allgemeine-zeitung.de/lokales/polizei/vier-verletzte-bei-verkehrsunfall-auf-der-a61-am-autobahndreieck-nahetal_15061411.htm</guid>
|
||||||
|
<content:encoded><![CDATA[
|
||||||
|
<img src="http://www.allgemeine-zeitung.de/fm/819/thumbnails/1425145619_DSC_0300.jpg.24240870.jpg" align="left" hspace="5" border="0" alt="Unfall auf der A61 am Dreieck Nahetal. Foto: kreuznach112.de" title="Unfall auf der A61 am Dreieck Nahetal. Foto: kreuznach112.de" />
|
||||||
|
]]></content:encoded>
|
||||||
|
<enclosure type="image/jpeg" url="http://www.allgemeine-zeitung.de/fm/819/thumbnails/1425145619_DSC_0300.jpg.24240871.jpg"/>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<title>Unfallauto auf Ober-Flörsheimer Hauptstraße stehen gelassen</title>
|
||||||
|
<link>http://www.allgemeine-zeitung.de/lokales/polizei/unfallauto-auf-ober-floersheimer-hauptstrasse-stehen-gelassen_15058634.htm</link>
|
||||||
|
<description>OBER-FLÖRSHEIM - (red). Sein erheblich beschädigtes Fahrzeug hat ein Fahrer in der Nacht von Donnerstag auf Freitag mitten auf der Ober-Flörsheimer Hauptstraße stehen lassen. Beim Verlassen des Autos in Richtung ...</description>
|
||||||
|
<category>Kirn</category>
|
||||||
|
<pubDate>Sat, 28 Feb 2015 01:00:00 +0100</pubDate>
|
||||||
|
<guid>http://www.allgemeine-zeitung.de/lokales/polizei/unfallauto-auf-ober-floersheimer-hauptstrasse-stehen-gelassen_15058634.htm</guid>
|
||||||
|
<content:encoded><![CDATA[
|
||||||
|
]]></content:encoded>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<title>Bischofsheim: Nach Einbruch verdächtiges Pärchen beobachtet</title>
|
||||||
|
<link>http://www.allgemeine-zeitung.de/lokales/polizei/bischofsheim-nach-einbruch-verdaechtiges-paerchen-beobachtet_15058635.htm</link>
|
||||||
|
<description>BISCHOFSHEIM - (red). Im Zusammenhang mit einem Einbruch in der Königsberger Straße sind Zeugen aus der Nachbarschaft auf ein unbekanntes Pärchen aufmerksam geworden. Die Kriminalpolizei in Rüsselsheim ...</description>
|
||||||
|
<category>Kirn</category>
|
||||||
|
<pubDate>Sat, 28 Feb 2015 01:00:00 +0100</pubDate>
|
||||||
|
<guid>http://www.allgemeine-zeitung.de/lokales/polizei/bischofsheim-nach-einbruch-verdaechtiges-paerchen-beobachtet_15058635.htm</guid>
|
||||||
|
<content:encoded><![CDATA[
|
||||||
|
]]></content:encoded>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<title>Einbrecher erbeuten Schmuck in Niedernhausen</title>
|
||||||
|
<link>http://www.allgemeine-zeitung.de/lokales/polizei/einbrecher-erbeuten-schmuck-in-niedernhausen_15058636.htm</link>
|
||||||
|
<description>NIEDERNHAUSEN - (red). Beim Einbruch in ein Einfamilienhaus in der Breslauer Straße in Niedernhausen erbeuteten unbekannte Täter am Donnerstagvormittag einige Schmuckstücke. Die Einbrecher waren durch ein ...</description>
|
||||||
|
<category>Kirn</category>
|
||||||
|
<pubDate>Sat, 28 Feb 2015 01:00:00 +0100</pubDate>
|
||||||
|
<guid>http://www.allgemeine-zeitung.de/lokales/polizei/einbrecher-erbeuten-schmuck-in-niedernhausen_15058636.htm</guid>
|
||||||
|
<content:encoded><![CDATA[
|
||||||
|
]]></content:encoded>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<title>Zu weit links auf der B 41</title>
|
||||||
|
<link>http://www.allgemeine-zeitung.de/lokales/polizei/zu-weit-links-auf-der-b-41_15058637.htm</link>
|
||||||
|
<description>RÜDESHEIM - (red). Bereits am Mittwochmorgen stieß eine 21-jährige Pkw-Fahrerin auf der Landessstraße 236 in Richtung Bundesstraße 41 mit einem zu weit links fahrenden, entgegenkommenden weißen Audi, ...</description>
|
||||||
|
<category>Kirn</category>
|
||||||
|
<pubDate>Sat, 28 Feb 2015 01:00:00 +0100</pubDate>
|
||||||
|
<guid>http://www.allgemeine-zeitung.de/lokales/polizei/zu-weit-links-auf-der-b-41_15058637.htm</guid>
|
||||||
|
<content:encoded><![CDATA[
|
||||||
|
]]></content:encoded>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<title>Mann droht in Wiesbaden mit Pistole</title>
|
||||||
|
<link>http://www.allgemeine-zeitung.de/lokales/polizei/mann-droht-in-wiesbaden-mit-pistole_15058638.htm</link>
|
||||||
|
<description>WIESBADEN - (red). Die Polizei sucht nach einem Unbekannten, der am Donnerstagmittag in der Holzstraße eine Frau mit einer Pistole bedroht haben soll und dadurch einen größeren Einsatz von Polizei und ...</description>
|
||||||
|
<category>Kirn</category>
|
||||||
|
<pubDate>Sat, 28 Feb 2015 01:00:00 +0100</pubDate>
|
||||||
|
<guid>http://www.allgemeine-zeitung.de/lokales/polizei/mann-droht-in-wiesbaden-mit-pistole_15058638.htm</guid>
|
||||||
|
<content:encoded><![CDATA[
|
||||||
|
]]></content:encoded>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<title>Geparktes Auto beschädigt</title>
|
||||||
|
<link>http://www.allgemeine-zeitung.de/lokales/polizei/geparktes-auto-beschaedigt_15058641.htm</link>
|
||||||
|
<description>RÜSSELSHEIM - (red). Im Hasengrund in Höhe des Hauses Nummer 72 ist am Donnerstag zwischen 14 und 15.30 Uhr ein Auto beschädigt worden. Der schwarze Mercedes Benz, C-Klasse, war vor dem Haus abgestellt und ...</description>
|
||||||
|
<category>Kirn</category>
|
||||||
|
<pubDate>Sat, 28 Feb 2015 01:00:00 +0100</pubDate>
|
||||||
|
<guid>http://www.allgemeine-zeitung.de/lokales/polizei/geparktes-auto-beschaedigt_15058641.htm</guid>
|
||||||
|
<content:encoded><![CDATA[
|
||||||
|
]]></content:encoded>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<title>Diebe stehlen 85 Liter Diesel</title>
|
||||||
|
<link>http://www.allgemeine-zeitung.de/lokales/polizei/diebe-stehlen-85-liter-diesel_15058642.htm</link>
|
||||||
|
<description>RÜSSELSHEIM - (red). Dieselkraftstoff im Wert von rund 110 Euro haben unbekannte Diebe am Donnerstagabend mitgehen lassen. DieTäter hatten es in der Zeit von 20.40 Uhr bis 21.25 Uhr auf einen Lastwagen in ...</description>
|
||||||
|
<category>Kirn</category>
|
||||||
|
<pubDate>Sat, 28 Feb 2015 01:00:00 +0100</pubDate>
|
||||||
|
<guid>http://www.allgemeine-zeitung.de/lokales/polizei/diebe-stehlen-85-liter-diesel_15058642.htm</guid>
|
||||||
|
<content:encoded><![CDATA[
|
||||||
|
]]></content:encoded>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<title>Bad Kreuznach: Betrunkene Frauen am Steuer</title>
|
||||||
|
<link>http://www.allgemeine-zeitung.de/lokales/polizei/bad-kreuznach-betrunkene-frauen-am-steuer_15058643.htm</link>
|
||||||
|
<description>BAD KREUZNACH - (red). Gleich zwei Fälle von Trunkenheit am Steuer registrierte die Polizei am späten Donnerstagabend. Im Rahmen einer Verkehrskontrolle wurde am Europaplatz bei einer 41-jährigen Autofahrerin ...</description>
|
||||||
|
<category>Kirn</category>
|
||||||
|
<pubDate>Sat, 28 Feb 2015 01:00:00 +0100</pubDate>
|
||||||
|
<guid>http://www.allgemeine-zeitung.de/lokales/polizei/bad-kreuznach-betrunkene-frauen-am-steuer_15058643.htm</guid>
|
||||||
|
<content:encoded><![CDATA[
|
||||||
|
]]></content:encoded>
|
||||||
|
</item>
|
||||||
|
</channel>
|
||||||
|
</rss>
|
BIN
vendor/fguillot/picofeed/tests/fixtures/miniflux_favicon.ico
vendored
Normal file
BIN
vendor/fguillot/picofeed/tests/fixtures/miniflux_favicon.ico
vendored
Normal file
Binary file not shown.
After Width: | Height: | Size: 17 KiB |
@ -1,47 +1,32 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/*
|
|
||||||
* This file is part of Simple Validator.
|
|
||||||
*
|
|
||||||
* (c) Frédéric Guillot <contact@fredericguillot.com>
|
|
||||||
*
|
|
||||||
* This source file is subject to the MIT license that is bundled
|
|
||||||
* with this source code in the file LICENSE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace SimpleValidator;
|
namespace SimpleValidator;
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Frédéric Guillot <contact@fredericguillot.com>
|
|
||||||
*/
|
|
||||||
abstract class Base
|
abstract class Base
|
||||||
{
|
{
|
||||||
protected $field = '';
|
protected $field = '';
|
||||||
protected $error_message = '';
|
protected $error_message = '';
|
||||||
protected $data = array();
|
protected $data = array();
|
||||||
|
|
||||||
|
|
||||||
abstract public function execute(array $data);
|
abstract public function execute(array $data);
|
||||||
|
|
||||||
|
|
||||||
public function __construct($field, $error_message)
|
public function __construct($field, $error_message)
|
||||||
{
|
{
|
||||||
$this->field = $field;
|
$this->field = $field;
|
||||||
$this->error_message = $error_message;
|
$this->error_message = $error_message;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function getErrorMessage()
|
public function getErrorMessage()
|
||||||
{
|
{
|
||||||
return $this->error_message;
|
return $this->error_message;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function getField()
|
public function getField()
|
||||||
{
|
{
|
||||||
if (is_array($this->field)) {
|
if (is_array($this->field)) {
|
||||||
return $this->field[0];
|
return $this->field[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->field;
|
return $this->field;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,33 +1,19 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/*
|
|
||||||
* This file is part of Simple Validator.
|
|
||||||
*
|
|
||||||
* (c) Frédéric Guillot <contact@fredericguillot.com>
|
|
||||||
*
|
|
||||||
* This source file is subject to the MIT license that is bundled
|
|
||||||
* with this source code in the file LICENSE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace SimpleValidator;
|
namespace SimpleValidator;
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Frédéric Guillot <contact@fredericguillot.com>
|
|
||||||
*/
|
|
||||||
class Validator
|
class Validator
|
||||||
{
|
{
|
||||||
private $data = array();
|
private $data = array();
|
||||||
private $errors = array();
|
private $errors = array();
|
||||||
private $validators = array();
|
private $validators = array();
|
||||||
|
|
||||||
|
|
||||||
public function __construct(array $data, array $validators)
|
public function __construct(array $data, array $validators)
|
||||||
{
|
{
|
||||||
$this->data = $data;
|
$this->data = $data;
|
||||||
$this->validators = $validators;
|
$this->validators = $validators;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function execute()
|
public function execute()
|
||||||
{
|
{
|
||||||
$result = true;
|
$result = true;
|
||||||
@ -48,11 +34,9 @@ class Validator
|
|||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function addError($field, $message)
|
public function addError($field, $message)
|
||||||
{
|
{
|
||||||
if (! isset($this->errors[$field])) {
|
if (! isset($this->errors[$field])) {
|
||||||
|
|
||||||
$this->errors[$field] = array();
|
$this->errors[$field] = array();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,21 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/*
|
|
||||||
* This file is part of Simple Validator.
|
|
||||||
*
|
|
||||||
* (c) Frédéric Guillot <contact@fredericguillot.com>
|
|
||||||
*
|
|
||||||
* This source file is subject to the MIT license that is bundled
|
|
||||||
* with this source code in the file LICENSE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace SimpleValidator\Validators;
|
namespace SimpleValidator\Validators;
|
||||||
|
|
||||||
use SimpleValidator\Base;
|
use SimpleValidator\Base;
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Frédéric Guillot <contact@fredericguillot.com>
|
|
||||||
*/
|
|
||||||
class Alpha extends Base
|
class Alpha extends Base
|
||||||
{
|
{
|
||||||
public function execute(array $data)
|
public function execute(array $data)
|
||||||
@ -23,7 +11,6 @@ class Alpha extends Base
|
|||||||
if (isset($data[$this->field]) && $data[$this->field] !== '') {
|
if (isset($data[$this->field]) && $data[$this->field] !== '') {
|
||||||
|
|
||||||
if (! ctype_alpha($data[$this->field])) {
|
if (! ctype_alpha($data[$this->field])) {
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,21 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/*
|
|
||||||
* This file is part of Simple Validator.
|
|
||||||
*
|
|
||||||
* (c) Frédéric Guillot <contact@fredericguillot.com>
|
|
||||||
*
|
|
||||||
* This source file is subject to the MIT license that is bundled
|
|
||||||
* with this source code in the file LICENSE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace SimpleValidator\Validators;
|
namespace SimpleValidator\Validators;
|
||||||
|
|
||||||
use SimpleValidator\Base;
|
use SimpleValidator\Base;
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Frédéric Guillot <contact@fredericguillot.com>
|
|
||||||
*/
|
|
||||||
class AlphaNumeric extends Base
|
class AlphaNumeric extends Base
|
||||||
{
|
{
|
||||||
public function execute(array $data)
|
public function execute(array $data)
|
||||||
@ -23,7 +11,6 @@ class AlphaNumeric extends Base
|
|||||||
if (isset($data[$this->field]) && $data[$this->field] !== '') {
|
if (isset($data[$this->field]) && $data[$this->field] !== '') {
|
||||||
|
|
||||||
if (! ctype_alnum($data[$this->field])) {
|
if (! ctype_alnum($data[$this->field])) {
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
namespace SimpleValidator\Validators;
|
namespace SimpleValidator\Validators;
|
||||||
|
|
||||||
use SimpleValidator\Base;
|
use SimpleValidator\Base;
|
||||||
use \DateTime;
|
use DateTime;
|
||||||
|
|
||||||
class Date extends Base
|
class Date extends Base
|
||||||
{
|
{
|
||||||
|
@ -1,21 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/*
|
|
||||||
* This file is part of Simple Validator.
|
|
||||||
*
|
|
||||||
* (c) Frédéric Guillot <contact@fredericguillot.com>
|
|
||||||
*
|
|
||||||
* This source file is subject to the MIT license that is bundled
|
|
||||||
* with this source code in the file LICENSE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace SimpleValidator\Validators;
|
namespace SimpleValidator\Validators;
|
||||||
|
|
||||||
use SimpleValidator\Base;
|
use SimpleValidator\Base;
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Frédéric Guillot <contact@fredericguillot.com>
|
|
||||||
*/
|
|
||||||
class Email extends Base
|
class Email extends Base
|
||||||
{
|
{
|
||||||
public function execute(array $data)
|
public function execute(array $data)
|
||||||
|
@ -1,21 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/*
|
|
||||||
* This file is part of Simple Validator.
|
|
||||||
*
|
|
||||||
* (c) Frédéric Guillot <contact@fredericguillot.com>
|
|
||||||
*
|
|
||||||
* This source file is subject to the MIT license that is bundled
|
|
||||||
* with this source code in the file LICENSE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace SimpleValidator\Validators;
|
namespace SimpleValidator\Validators;
|
||||||
|
|
||||||
use SimpleValidator\Base;
|
use SimpleValidator\Base;
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Frédéric Guillot <contact@fredericguillot.com>
|
|
||||||
*/
|
|
||||||
class Equals extends Base
|
class Equals extends Base
|
||||||
{
|
{
|
||||||
private $field2;
|
private $field2;
|
||||||
@ -24,7 +12,6 @@ class Equals extends Base
|
|||||||
public function __construct($field1, $field2, $error_message)
|
public function __construct($field1, $field2, $error_message)
|
||||||
{
|
{
|
||||||
parent::__construct($field1, $error_message);
|
parent::__construct($field1, $error_message);
|
||||||
|
|
||||||
$this->field2 = $field2;
|
$this->field2 = $field2;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -33,7 +20,9 @@ class Equals extends Base
|
|||||||
{
|
{
|
||||||
if (isset($data[$this->field]) && $data[$this->field] !== '') {
|
if (isset($data[$this->field]) && $data[$this->field] !== '') {
|
||||||
|
|
||||||
if (! isset($data[$this->field2])) return false;
|
if (! isset($data[$this->field2])) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
return $data[$this->field] === $data[$this->field2];
|
return $data[$this->field] === $data[$this->field2];
|
||||||
}
|
}
|
||||||
|
@ -1,16 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/*
|
|
||||||
* This file is part of Simple Validator.
|
|
||||||
*
|
|
||||||
* (c) Frédéric Guillot <contact@fredericguillot.com>
|
|
||||||
*
|
|
||||||
* This source file is subject to the MIT license that is bundled
|
|
||||||
* with this source code in the file LICENSE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace SimpleValidator\Validators;
|
namespace SimpleValidator\Validators;
|
||||||
|
|
||||||
|
use PDO;
|
||||||
use SimpleValidator\Base;
|
use SimpleValidator\Base;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -23,7 +15,7 @@ class Exists extends Base
|
|||||||
private $table;
|
private $table;
|
||||||
|
|
||||||
|
|
||||||
public function __construct($field, $error_message, \PDO $pdo, $table, $key = '')
|
public function __construct($field, $error_message, PDO $pdo, $table, $key = '')
|
||||||
{
|
{
|
||||||
parent::__construct($field, $error_message);
|
parent::__construct($field, $error_message);
|
||||||
|
|
||||||
@ -38,21 +30,14 @@ class Exists extends Base
|
|||||||
if (! isset($data[$this->field]) || '' === $data[$this->field]) {
|
if (! isset($data[$this->field]) || '' === $data[$this->field]) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->key === '') {
|
if ($this->key === '') {
|
||||||
$this->key = $this->field;
|
$this->key = $this->field;
|
||||||
}
|
}
|
||||||
|
|
||||||
$rq = $this->pdo->prepare('SELECT COUNT(*) FROM '.$this->table.' WHERE '.$this->key.'=?');
|
$rq = $this->pdo->prepare('SELECT COUNT(*) FROM '.$this->table.' WHERE '.$this->key.'=?');
|
||||||
$rq->execute(array(
|
$rq->execute(array($data[$this->field]));
|
||||||
$data[$this->field]
|
|
||||||
));
|
|
||||||
|
|
||||||
$result = $rq->fetch(\PDO::FETCH_NUM);
|
return $rq->fetchColumn() >= 1;
|
||||||
|
|
||||||
if (isset($result[0]) && $result[0] >= '1') {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,14 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/*
|
|
||||||
* This file is part of Simple Validator.
|
|
||||||
*
|
|
||||||
* (c) Frédéric Guillot
|
|
||||||
*
|
|
||||||
* This source file is subject to the MIT license that is bundled
|
|
||||||
* with this source code in the file LICENSE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace SimpleValidator\Validators;
|
namespace SimpleValidator\Validators;
|
||||||
|
|
||||||
use SimpleValidator\Base;
|
use SimpleValidator\Base;
|
||||||
@ -17,14 +8,12 @@ class GreaterThan extends Base
|
|||||||
{
|
{
|
||||||
private $min;
|
private $min;
|
||||||
|
|
||||||
|
|
||||||
public function __construct($field, $error_message, $min)
|
public function __construct($field, $error_message, $min)
|
||||||
{
|
{
|
||||||
parent::__construct($field, $error_message);
|
parent::__construct($field, $error_message);
|
||||||
$this->min = $min;
|
$this->min = $min;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function execute(array $data)
|
public function execute(array $data)
|
||||||
{
|
{
|
||||||
if (isset($data[$this->field]) && $data[$this->field] !== '') {
|
if (isset($data[$this->field]) && $data[$this->field] !== '') {
|
||||||
|
@ -1,14 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/*
|
|
||||||
* This file is part of Simple Validator.
|
|
||||||
*
|
|
||||||
* (c) Frédéric Guillot <contact@fredericguillot.com>
|
|
||||||
*
|
|
||||||
* This source file is subject to the MIT license that is bundled
|
|
||||||
* with this source code in the file LICENSE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace SimpleValidator\Validators;
|
namespace SimpleValidator\Validators;
|
||||||
|
|
||||||
use SimpleValidator\Base;
|
use SimpleValidator\Base;
|
||||||
|
@ -1,21 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/*
|
|
||||||
* This file is part of Simple Validator.
|
|
||||||
*
|
|
||||||
* (c) Frédéric Guillot <contact@fredericguillot.com>
|
|
||||||
*
|
|
||||||
* This source file is subject to the MIT license that is bundled
|
|
||||||
* with this source code in the file LICENSE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace SimpleValidator\Validators;
|
namespace SimpleValidator\Validators;
|
||||||
|
|
||||||
use SimpleValidator\Base;
|
use SimpleValidator\Base;
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Frédéric Guillot <contact@fredericguillot.com>
|
|
||||||
*/
|
|
||||||
class Integer extends Base
|
class Integer extends Base
|
||||||
{
|
{
|
||||||
public function execute(array $data)
|
public function execute(array $data)
|
||||||
@ -25,7 +13,6 @@ class Integer extends Base
|
|||||||
if (is_string($data[$this->field])) {
|
if (is_string($data[$this->field])) {
|
||||||
|
|
||||||
if ($data[$this->field][0] === '-') {
|
if ($data[$this->field][0] === '-') {
|
||||||
|
|
||||||
return ctype_digit(substr($data[$this->field], 1));
|
return ctype_digit(substr($data[$this->field], 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,29 +1,15 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/*
|
|
||||||
* This file is part of Simple Validator.
|
|
||||||
*
|
|
||||||
* (c) Frédéric Guillot <contact@fredericguillot.com>
|
|
||||||
*
|
|
||||||
* This source file is subject to the MIT license that is bundled
|
|
||||||
* with this source code in the file LICENSE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace SimpleValidator\Validators;
|
namespace SimpleValidator\Validators;
|
||||||
|
|
||||||
use SimpleValidator\Base;
|
use SimpleValidator\Base;
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Frédéric Guillot <contact@fredericguillot.com>
|
|
||||||
*/
|
|
||||||
class Ip extends Base
|
class Ip extends Base
|
||||||
{
|
{
|
||||||
public function execute(array $data)
|
public function execute(array $data)
|
||||||
{
|
{
|
||||||
if (isset($data[$this->field]) && $data[$this->field] !== '') {
|
if (isset($data[$this->field]) && $data[$this->field] !== '') {
|
||||||
|
|
||||||
if (! filter_var($data[$this->field], FILTER_VALIDATE_IP)) {
|
if (! filter_var($data[$this->field], FILTER_VALIDATE_IP)) {
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,27 +1,14 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/*
|
|
||||||
* This file is part of Simple Validator.
|
|
||||||
*
|
|
||||||
* (c) Frédéric Guillot <contact@fredericguillot.com>
|
|
||||||
*
|
|
||||||
* This source file is subject to the MIT license that is bundled
|
|
||||||
* with this source code in the file LICENSE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace SimpleValidator\Validators;
|
namespace SimpleValidator\Validators;
|
||||||
|
|
||||||
use SimpleValidator\Base;
|
use SimpleValidator\Base;
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Frédéric Guillot <contact@fredericguillot.com>
|
|
||||||
*/
|
|
||||||
class Length extends Base
|
class Length extends Base
|
||||||
{
|
{
|
||||||
private $min;
|
private $min;
|
||||||
private $max;
|
private $max;
|
||||||
|
|
||||||
|
|
||||||
public function __construct($field, $error_message, $min, $max)
|
public function __construct($field, $error_message, $min, $max)
|
||||||
{
|
{
|
||||||
parent::__construct($field, $error_message);
|
parent::__construct($field, $error_message);
|
||||||
@ -30,7 +17,6 @@ class Length extends Base
|
|||||||
$this->max = $max;
|
$this->max = $max;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function execute(array $data)
|
public function execute(array $data)
|
||||||
{
|
{
|
||||||
if (isset($data[$this->field]) && $data[$this->field] !== '') {
|
if (isset($data[$this->field]) && $data[$this->field] !== '') {
|
||||||
@ -38,7 +24,6 @@ class Length extends Base
|
|||||||
$length = mb_strlen($data[$this->field], 'UTF-8');
|
$length = mb_strlen($data[$this->field], 'UTF-8');
|
||||||
|
|
||||||
if ($length < $this->min || $length > $this->max) {
|
if ($length < $this->min || $length > $this->max) {
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,21 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/*
|
|
||||||
* This file is part of Simple Validator.
|
|
||||||
*
|
|
||||||
* (c) Frédéric Guillot <contact@fredericguillot.com>
|
|
||||||
*
|
|
||||||
* This source file is subject to the MIT license that is bundled
|
|
||||||
* with this source code in the file LICENSE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace SimpleValidator\Validators;
|
namespace SimpleValidator\Validators;
|
||||||
|
|
||||||
use SimpleValidator\Base;
|
use SimpleValidator\Base;
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Frédéric Guillot <contact@fredericguillot.com>
|
|
||||||
*/
|
|
||||||
class MacAddress extends Base
|
class MacAddress extends Base
|
||||||
{
|
{
|
||||||
public function execute(array $data)
|
public function execute(array $data)
|
||||||
@ -24,11 +12,14 @@ class MacAddress extends Base
|
|||||||
|
|
||||||
$groups = explode(':', $data[$this->field]);
|
$groups = explode(':', $data[$this->field]);
|
||||||
|
|
||||||
if (count($groups) !== 6) return false;
|
if (count($groups) !== 6) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
foreach ($groups as $group) {
|
foreach ($groups as $group) {
|
||||||
|
if (! ctype_xdigit($group)) {
|
||||||
if (! ctype_xdigit($group)) return false;
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,34 +1,19 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/*
|
|
||||||
* This file is part of Simple Validator.
|
|
||||||
*
|
|
||||||
* (c) Frédéric Guillot <contact@fredericguillot.com>
|
|
||||||
*
|
|
||||||
* This source file is subject to the MIT license that is bundled
|
|
||||||
* with this source code in the file LICENSE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace SimpleValidator\Validators;
|
namespace SimpleValidator\Validators;
|
||||||
|
|
||||||
use SimpleValidator\Base;
|
use SimpleValidator\Base;
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Frédéric Guillot <contact@fredericguillot.com>
|
|
||||||
*/
|
|
||||||
class MaxLength extends Base
|
class MaxLength extends Base
|
||||||
{
|
{
|
||||||
private $max;
|
private $max;
|
||||||
|
|
||||||
|
|
||||||
public function __construct($field, $error_message, $max)
|
public function __construct($field, $error_message, $max)
|
||||||
{
|
{
|
||||||
parent::__construct($field, $error_message);
|
parent::__construct($field, $error_message);
|
||||||
|
|
||||||
$this->max = $max;
|
$this->max = $max;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function execute(array $data)
|
public function execute(array $data)
|
||||||
{
|
{
|
||||||
if (isset($data[$this->field]) && $data[$this->field] !== '') {
|
if (isset($data[$this->field]) && $data[$this->field] !== '') {
|
||||||
@ -36,7 +21,6 @@ class MaxLength extends Base
|
|||||||
$length = mb_strlen($data[$this->field], 'UTF-8');
|
$length = mb_strlen($data[$this->field], 'UTF-8');
|
||||||
|
|
||||||
if ($length > $this->max) {
|
if ($length > $this->max) {
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,34 +1,19 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/*
|
|
||||||
* This file is part of Simple Validator.
|
|
||||||
*
|
|
||||||
* (c) Frédéric Guillot <contact@fredericguillot.com>
|
|
||||||
*
|
|
||||||
* This source file is subject to the MIT license that is bundled
|
|
||||||
* with this source code in the file LICENSE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace SimpleValidator\Validators;
|
namespace SimpleValidator\Validators;
|
||||||
|
|
||||||
use SimpleValidator\Base;
|
use SimpleValidator\Base;
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Frédéric Guillot <contact@fredericguillot.com>
|
|
||||||
*/
|
|
||||||
class MinLength extends Base
|
class MinLength extends Base
|
||||||
{
|
{
|
||||||
private $min;
|
private $min;
|
||||||
|
|
||||||
|
|
||||||
public function __construct($field, $error_message, $min)
|
public function __construct($field, $error_message, $min)
|
||||||
{
|
{
|
||||||
parent::__construct($field, $error_message);
|
parent::__construct($field, $error_message);
|
||||||
|
|
||||||
$this->min = $min;
|
$this->min = $min;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function execute(array $data)
|
public function execute(array $data)
|
||||||
{
|
{
|
||||||
if (isset($data[$this->field]) && $data[$this->field] !== '') {
|
if (isset($data[$this->field]) && $data[$this->field] !== '') {
|
||||||
@ -36,7 +21,6 @@ class MinLength extends Base
|
|||||||
$length = mb_strlen($data[$this->field], 'UTF-8');
|
$length = mb_strlen($data[$this->field], 'UTF-8');
|
||||||
|
|
||||||
if ($length < $this->min) {
|
if ($length < $this->min) {
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,14 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/*
|
|
||||||
* This file is part of Simple Validator.
|
|
||||||
*
|
|
||||||
* (c) Frédéric Guillot <contact@fredericguillot.com>
|
|
||||||
*
|
|
||||||
* This source file is subject to the MIT license that is bundled
|
|
||||||
* with this source code in the file LICENSE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace SimpleValidator\Validators;
|
namespace SimpleValidator\Validators;
|
||||||
|
|
||||||
use SimpleValidator\Base;
|
use SimpleValidator\Base;
|
||||||
@ -20,7 +11,6 @@ class NotEquals extends Base
|
|||||||
{
|
{
|
||||||
private $field2;
|
private $field2;
|
||||||
|
|
||||||
|
|
||||||
public function __construct($field1, $field2, $error_message)
|
public function __construct($field1, $field2, $error_message)
|
||||||
{
|
{
|
||||||
parent::__construct($field1, $error_message);
|
parent::__construct($field1, $error_message);
|
||||||
@ -28,12 +18,13 @@ class NotEquals extends Base
|
|||||||
$this->field2 = $field2;
|
$this->field2 = $field2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function execute(array $data)
|
public function execute(array $data)
|
||||||
{
|
{
|
||||||
if (isset($data[$this->field]) && $data[$this->field] !== '') {
|
if (isset($data[$this->field]) && $data[$this->field] !== '') {
|
||||||
|
|
||||||
if (! isset($data[$this->field2])) return true;
|
if (! isset($data[$this->field2])) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
return $data[$this->field] !== $data[$this->field2];
|
return $data[$this->field] !== $data[$this->field2];
|
||||||
}
|
}
|
||||||
|
@ -1,14 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/*
|
|
||||||
* This file is part of Simple Validator.
|
|
||||||
*
|
|
||||||
* (c) Frédéric Guillot <contact@fredericguillot.com>
|
|
||||||
*
|
|
||||||
* This source file is subject to the MIT license that is bundled
|
|
||||||
* with this source code in the file LICENSE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace SimpleValidator\Validators;
|
namespace SimpleValidator\Validators;
|
||||||
|
|
||||||
class NotInArray extends InArray
|
class NotInArray extends InArray
|
||||||
|
@ -1,21 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/*
|
|
||||||
* This file is part of Simple Validator.
|
|
||||||
*
|
|
||||||
* (c) Frédéric Guillot <contact@fredericguillot.com>
|
|
||||||
*
|
|
||||||
* This source file is subject to the MIT license that is bundled
|
|
||||||
* with this source code in the file LICENSE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace SimpleValidator\Validators;
|
namespace SimpleValidator\Validators;
|
||||||
|
|
||||||
use SimpleValidator\Base;
|
use SimpleValidator\Base;
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Frédéric Guillot <contact@fredericguillot.com>
|
|
||||||
*/
|
|
||||||
class Numeric extends Base
|
class Numeric extends Base
|
||||||
{
|
{
|
||||||
public function execute(array $data)
|
public function execute(array $data)
|
||||||
@ -23,7 +11,6 @@ class Numeric extends Base
|
|||||||
if (isset($data[$this->field]) && $data[$this->field] !== '') {
|
if (isset($data[$this->field]) && $data[$this->field] !== '') {
|
||||||
|
|
||||||
if (! is_numeric($data[$this->field])) {
|
if (! is_numeric($data[$this->field])) {
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,27 +1,14 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/*
|
|
||||||
* This file is part of Simple Validator.
|
|
||||||
*
|
|
||||||
* (c) Frédéric Guillot <contact@fredericguillot.com>
|
|
||||||
*
|
|
||||||
* This source file is subject to the MIT license that is bundled
|
|
||||||
* with this source code in the file LICENSE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace SimpleValidator\Validators;
|
namespace SimpleValidator\Validators;
|
||||||
|
|
||||||
use SimpleValidator\Base;
|
use SimpleValidator\Base;
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Frédéric Guillot <contact@fredericguillot.com>
|
|
||||||
*/
|
|
||||||
class Range extends Base
|
class Range extends Base
|
||||||
{
|
{
|
||||||
private $min;
|
private $min;
|
||||||
private $max;
|
private $max;
|
||||||
|
|
||||||
|
|
||||||
public function __construct($field, $error_message, $min, $max)
|
public function __construct($field, $error_message, $min, $max)
|
||||||
{
|
{
|
||||||
parent::__construct($field, $error_message);
|
parent::__construct($field, $error_message);
|
||||||
@ -30,18 +17,15 @@ class Range extends Base
|
|||||||
$this->max = $max;
|
$this->max = $max;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function execute(array $data)
|
public function execute(array $data)
|
||||||
{
|
{
|
||||||
if (isset($data[$this->field]) && $data[$this->field] !== '') {
|
if (isset($data[$this->field]) && $data[$this->field] !== '') {
|
||||||
|
|
||||||
if (! is_numeric($data[$this->field])) {
|
if (! is_numeric($data[$this->field])) {
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($data[$this->field] < $this->min || $data[$this->field] > $this->max) {
|
if ($data[$this->field] < $this->min || $data[$this->field] > $this->max) {
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,27 +1,14 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/*
|
|
||||||
* This file is part of Simple Validator.
|
|
||||||
*
|
|
||||||
* (c) Frédéric Guillot <contact@fredericguillot.com>
|
|
||||||
*
|
|
||||||
* This source file is subject to the MIT license that is bundled
|
|
||||||
* with this source code in the file LICENSE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace SimpleValidator\Validators;
|
namespace SimpleValidator\Validators;
|
||||||
|
|
||||||
use SimpleValidator\Base;
|
use SimpleValidator\Base;
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Frédéric Guillot <contact@fredericguillot.com>
|
|
||||||
*/
|
|
||||||
class Required extends Base
|
class Required extends Base
|
||||||
{
|
{
|
||||||
public function execute(array $data)
|
public function execute(array $data)
|
||||||
{
|
{
|
||||||
if (! isset($data[$this->field]) || $data[$this->field] === '') {
|
if (! isset($data[$this->field]) || $data[$this->field] === '') {
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,30 +1,17 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/*
|
|
||||||
* This file is part of Simple Validator.
|
|
||||||
*
|
|
||||||
* (c) Frédéric Guillot <contact@fredericguillot.com>
|
|
||||||
*
|
|
||||||
* This source file is subject to the MIT license that is bundled
|
|
||||||
* with this source code in the file LICENSE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace SimpleValidator\Validators;
|
namespace SimpleValidator\Validators;
|
||||||
|
|
||||||
|
use PDO;
|
||||||
use SimpleValidator\Base;
|
use SimpleValidator\Base;
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Frédéric Guillot <contact@fredericguillot.com>
|
|
||||||
* @author Olivier Maridat
|
|
||||||
*/
|
|
||||||
class Unique extends Base
|
class Unique extends Base
|
||||||
{
|
{
|
||||||
private $pdo;
|
private $pdo;
|
||||||
private $primary_key;
|
private $primary_key;
|
||||||
private $table;
|
private $table;
|
||||||
|
|
||||||
|
public function __construct($field, $error_message, PDO $pdo, $table, $primary_key = 'id')
|
||||||
public function __construct($field, $error_message, \PDO $pdo, $table, $primary_key = 'id')
|
|
||||||
{
|
{
|
||||||
parent::__construct($field, $error_message);
|
parent::__construct($field, $error_message);
|
||||||
|
|
||||||
@ -33,37 +20,32 @@ class Unique extends Base
|
|||||||
$this->table = $table;
|
$this->table = $table;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function execute(array $data)
|
public function execute(array $data)
|
||||||
{
|
{
|
||||||
if (! is_array($this->field)) {
|
if (isset($data[$this->field]) && $data[$this->field] !== '') {
|
||||||
$this->field = array($this->field);
|
|
||||||
}
|
if (! isset($data[$this->primary_key])) {
|
||||||
$fields = array();
|
|
||||||
$parameters = array();
|
$rq = $this->pdo->prepare('SELECT COUNT(*) FROM '.$this->table.' WHERE '.$this->field.'=?');
|
||||||
foreach($this->field AS $field) {
|
$rq->execute(array($data[$this->field]));
|
||||||
if (! isset($data[$field]) || $data[$field] === '') {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
$fields[] = $field;
|
|
||||||
$parameters[] = $data[$field];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isset($data[$this->primary_key])) {
|
|
||||||
$parameters[] = $data[$this->primary_key];
|
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
|
||||||
$rq = $this->pdo->prepare(
|
$rq = $this->pdo->prepare(
|
||||||
'SELECT COUNT(*) FROM '.$this->table.' WHERE '.implode('=? AND ', $fields).'=?'.(isset($data[$this->primary_key]) ? ' AND '.$this->primary_key.'!=?' : '')
|
'SELECT COUNT(*) FROM '.$this->table.'
|
||||||
|
WHERE '.$this->field.'=? AND '.$this->primary_key.' != ?'
|
||||||
);
|
);
|
||||||
|
|
||||||
$rq->execute($parameters);
|
$rq->execute(array($data[$this->field], $data[$this->primary_key]));
|
||||||
|
}
|
||||||
|
|
||||||
$result = $rq->fetch(\PDO::FETCH_NUM);
|
$result = $rq->fetchColumn();
|
||||||
|
|
||||||
if (isset($result[0]) && $result[0] === '1') {
|
if ($result == 1) { // Postgresql returns an integer but other database returns a string '1'
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -1,28 +1,14 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/*
|
|
||||||
* This file is part of Simple Validator.
|
|
||||||
*
|
|
||||||
* (c) Frédéric Guillot <contact@fredericguillot.com>
|
|
||||||
*
|
|
||||||
* This source file is subject to the MIT license that is bundled
|
|
||||||
* with this source code in the file LICENSE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace SimpleValidator\Validators;
|
namespace SimpleValidator\Validators;
|
||||||
|
|
||||||
use SimpleValidator\Base;
|
use SimpleValidator\Base;
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Frédéric Guillot <contact@fredericguillot.com>
|
|
||||||
* @link http://semver.org/
|
|
||||||
*/
|
|
||||||
class Version extends Base
|
class Version extends Base
|
||||||
{
|
{
|
||||||
public function execute(array $data)
|
public function execute(array $data)
|
||||||
{
|
{
|
||||||
if (isset($data[$this->field]) && $data[$this->field] !== '') {
|
if (isset($data[$this->field]) && $data[$this->field] !== '') {
|
||||||
|
|
||||||
$pattern = '/^[0-9]+\.[0-9]+\.[0-9]+([+-][^+-][0-9A-Za-z-.]*)?$/';
|
$pattern = '/^[0-9]+\.[0-9]+\.[0-9]+([+-][^+-][0-9A-Za-z-.]*)?$/';
|
||||||
return (bool) preg_match($pattern, $data[$this->field]);
|
return (bool) preg_match($pattern, $data[$this->field]);
|
||||||
}
|
}
|
||||||
|
@ -35,49 +35,4 @@ class UniqueValidatorTest extends PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
$this->assertFalse($v->execute(array('toto' => 'truc', 'id' => '2')));
|
$this->assertFalse($v->execute(array('toto' => 'truc', 'id' => '2')));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testValidatorWithArray()
|
|
||||||
{
|
|
||||||
$pdo = new PDO('sqlite::memory:');
|
|
||||||
$pdo->exec('CREATE TABLE mytable (id INTEGER, toto TEXT, tata TEXT)');
|
|
||||||
|
|
||||||
$message = 'field must be unique';
|
|
||||||
|
|
||||||
$v = new Unique(array('toto', 'tata'), $message, $pdo, 'mytable');
|
|
||||||
|
|
||||||
$this->assertEquals($message, $v->getErrorMessage());
|
|
||||||
|
|
||||||
$this->assertTrue($v->execute(array('toto' => '')));
|
|
||||||
$this->assertTrue($v->execute(array('toto' => null)));
|
|
||||||
|
|
||||||
$this->assertTrue($v->execute(array('toto' => 'bidule')));
|
|
||||||
$this->assertTrue($v->execute(array('toto' => 'bidule', 'tata' => 'machin')));
|
|
||||||
$this->assertTrue($v->execute(array('toto' => 'bidule', 'toutou' => 'machin')));
|
|
||||||
|
|
||||||
$pdo->exec("INSERT INTO mytable VALUES ('1', 'truc', 'muche')");
|
|
||||||
|
|
||||||
$this->assertTrue($v->execute(array('toto' => 'truc')));
|
|
||||||
$this->assertTrue($v->execute(array('toto' => 'bidule')));
|
|
||||||
|
|
||||||
$this->assertTrue($v->execute(array('toto' => 'bidule', 'tata' => 'miouch')));
|
|
||||||
$this->assertTrue($v->execute(array('toto' => 'bidule', 'tata' => 'muche')));
|
|
||||||
$this->assertTrue($v->execute(array('toto' => 'bidule', 'toutou' => 'muche')));
|
|
||||||
|
|
||||||
$this->assertFalse($v->execute(array('toto' => 'truc', 'tata' => 'muche')));
|
|
||||||
$this->assertTrue($v->execute(array('toto' => 'truc', 'tata' => 'miouch')));
|
|
||||||
|
|
||||||
$pdo->exec("INSERT INTO mytable VALUES ('2', 'bidule', 'machin')");
|
|
||||||
|
|
||||||
$this->assertTrue($v->execute(array('toto' => 'bidule')));
|
|
||||||
$this->assertTrue($v->execute(array('toto' => 'truc')));
|
|
||||||
|
|
||||||
$this->assertTrue($v->execute(array('toto' => 'bidule', 'tata' => 'muche')));
|
|
||||||
$this->assertFalse($v->execute(array('toto' => 'bidule', 'tata' => 'machin')));
|
|
||||||
$this->assertTrue($v->execute(array('toto' => 'bidule', 'tata' => 'muche', 'id' => '2')));
|
|
||||||
$this->assertTrue($v->execute(array('toto' => 'bidule', 'tata' => 'machin', 'id' => '2')));
|
|
||||||
|
|
||||||
$this->assertTrue($v->execute(array('toto' => 'truc', 'id' => '2')));
|
|
||||||
$this->assertFalse($v->execute(array('toto' => 'truc', 'tata' => 'muche', 'id' => '2')));
|
|
||||||
$this->assertTrue($v->execute(array('toto' => 'truc', 'tata' => 'miouch', 'id' => '2')));
|
|
||||||
}
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user