Add debug_mode config option and update vendor

This commit is contained in:
Frederic Guillot 2015-01-28 21:57:34 -05:00
parent fa9dc3ab8f
commit 33a6e50c96
22 changed files with 179 additions and 288 deletions

View File

@ -759,6 +759,20 @@ iframe {
color: #339966;
}
#config-form {
border-left: none;
padding: 0;
}
#config-form h3 {
border-bottom: 1px dotted #ccc;
}
.options {
border-left: 3px dotted #eee;
padding-left: 20px;
}
/* desktop design */
@media only screen and (min-width: 480px) {

View File

@ -16,7 +16,6 @@ defined('DATA_DIRECTORY') or define('DATA_DIRECTORY', ROOT_DIRECTORY.DIRECTORY_S
defined('ENABLE_MULTIPLE_DB') or define('ENABLE_MULTIPLE_DB', true);
defined('DB_FILENAME') or define('DB_FILENAME', 'db.sqlite');
defined('DEBUG') or define('DEBUG', true);
defined('DEBUG_FILENAME') or define('DEBUG_FILENAME', DATA_DIRECTORY.DIRECTORY_SEPARATOR.'debug.log');
defined('THEME_DIRECTORY') or define('THEME_DIRECTORY', 'themes');
@ -34,10 +33,6 @@ defined('AUTO_UPDATE_BACKUP_DIRECTORY') or define('AUTO_UPDATE_BACKUP_DIRECTORY'
require __DIR__.'/check_setup.php';
if (DEBUG) {
PicoFeed\Logging\Logger::enable();
}
PicoDb\Database::bootstrap('db', function() {
$db = new PicoDb\Database(array(

View File

@ -12,9 +12,6 @@ define('DB_FILENAME', 'db.sqlite');
// ENABLE_MULTIPLE_DB => default value is true (multiple users support)
define('ENABLE_MULTIPLE_DB', true);
// DEBUG => default is true (enable logging of PicoFeed)
define('DEBUG', true);
// DEBUG_FILENAME => default is data/debug.log
define('DEBUG_FILENAME', DATA_DIRECTORY.'/debug.log');

View File

@ -138,7 +138,7 @@ Router\get_action('config', function() {
// Update preferences
Router\post_action('config', function() {
$values = Request\values() + array('nocontent' => 0, 'image_proxy' => 0, 'favicons' => 0);
$values = Request\values() + array('nocontent' => 0, 'image_proxy' => 0, 'favicons' => 0, 'debug_mode' => 0);
Model\Config\check_csrf_values($values);
list($valid, $errors) = Model\Config\validate_modification($values);

View File

@ -26,9 +26,6 @@ define('DB_FILENAME', 'db.sqlite');
// ENABLE_MULTIPLE_DB => default value is true (multiple users support)
define('ENABLE_MULTIPLE_DB', true);
// DEBUG => default is true (enable logging of PicoFeed)
define('DEBUG', true);
// DEBUG_FILENAME => default is data/debug.log
define('DEBUG_FILENAME', DATA_DIRECTORY.'/debug.log');

View File

@ -232,4 +232,6 @@ return array(
'general' => 'général',
'An error occurred during the last check. Refresh the feed manually and check the %sconsole%s for errors afterwards!' => 'Une erreur est survenue pendant la dernière vérification. Actualisez, le flux manuellement and vérifiez les erreurs dans la %sconsole%s !',
'Refresh interval in minutes for unread counter' => 'Fréquence d\'actualisation en minute du compteur de non lus',
'Nothing to show. Enable the debug mode to see log messages.' => 'Rien à montrer. Activez le mode debug pour voir les messages de log.',
'Enable debug mode' => 'Activer le mode debug',
);

View File

@ -36,6 +36,10 @@ function get_reader_config()
$config->setFilterImageProxyUrl('?action=proxy&url=%s');
}
if ((bool) get('debug_mode')) {
Logger::enable();
}
// Parser
$config->setParserHashAlgo('crc32b');
@ -64,7 +68,7 @@ function debug($line)
// Write PicoFeed debug output to a file
function write_debug()
{
if (DEBUG) {
if ((bool) get('debug_mode')) {
file_put_contents(DEBUG_FILENAME, implode(PHP_EOL, Logger::getMessages()));
}
}
@ -219,7 +223,7 @@ function check_csrf($token)
function generate_token()
{
if (function_exists('openssl_random_pseudo_bytes')) {
return bin2hex(\openssl_random_pseudo_bytes(25));
return bin2hex(openssl_random_pseudo_bytes(25));
}
else if (ini_get('open_basedir') === '' && strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN') {
return hash('sha256', file_get_contents('/dev/urandom', false, null, 0, 30));
@ -283,6 +287,7 @@ function validate_modification(array $values)
new Validators\Integer('items_per_page', t('Must be an integer')),
new Validators\Required('theme', t('Value required')),
new Validators\Integer('frontend_updatecheck_interval', t('Must be an integer')),
new Validators\Integer('debug_mode', t('Must be an integer')),
);
if (ENABLE_AUTO_UPDATE) {

View File

@ -5,7 +5,12 @@ namespace Schema;
use PDO;
use Model\Config;
const VERSION = 36;
const VERSION = 37;
function version_37($pdo)
{
$pdo->exec('INSERT INTO settings ("key", "value") VALUES ("debug_mode", 0)');
}
function version_36($pdo)
{

View File

@ -12,62 +12,69 @@
</nav>
</div>
<section>
<form method="post" action="?action=config" autocomplete="off">
<form method="post" action="?action=config" autocomplete="off" id="config-form">
<h3><?= t('Authentication') ?></h3>
<?= Helper\form_hidden('csrf', $values) ?>
<?= Helper\form_label(t('Username'), 'username') ?>
<?= Helper\form_text('username', $values, $errors, array('required')) ?><br/>
<div class="options">
<?= Helper\form_hidden('csrf', $values) ?>
<?= Helper\form_label(t('Username'), 'username') ?>
<?= Helper\form_text('username', $values, $errors, array('required')) ?><br/>
<?= Helper\form_label(t('Password'), 'password') ?>
<?= Helper\form_password('password', $values, $errors) ?><br/>
<?= Helper\form_label(t('Password'), 'password') ?>
<?= Helper\form_password('password', $values, $errors) ?><br/>
<?= Helper\form_label(t('Confirmation'), 'confirmation') ?>
<?= Helper\form_password('confirmation', $values, $errors) ?><br/>
<?= Helper\form_label(t('Confirmation'), 'confirmation') ?>
<?= Helper\form_password('confirmation', $values, $errors) ?><br/>
</div>
<h3><?= t('Application') ?></h3>
<?= Helper\form_label(t('Timezone'), 'timezone') ?>
<?= Helper\form_select('timezone', $timezones, $values, $errors) ?><br/>
<div class="options">
<?= Helper\form_label(t('Timezone'), 'timezone') ?>
<?= Helper\form_select('timezone', $timezones, $values, $errors) ?><br/>
<?= Helper\form_label(t('Language'), 'language') ?>
<?= Helper\form_select('language', $languages, $values, $errors) ?><br/>
<?= Helper\form_label(t('Language'), 'language') ?>
<?= Helper\form_select('language', $languages, $values, $errors) ?><br/>
<?= Helper\form_label(t('Theme'), 'theme') ?>
<?= Helper\form_select('theme', $theme_options, $values, $errors) ?><br/>
<?= Helper\form_label(t('Theme'), 'theme') ?>
<?= Helper\form_select('theme', $theme_options, $values, $errors) ?><br/>
<?php if (ENABLE_AUTO_UPDATE): ?>
<?= Helper\form_label(t('Auto-Update URL'), 'auto_update_url') ?>
<?= Helper\form_text('auto_update_url', $values, $errors, array('required')) ?><br/>
<?php endif ?>
<?php if (ENABLE_AUTO_UPDATE): ?>
<?= Helper\form_label(t('Auto-Update URL'), 'auto_update_url') ?>
<?= Helper\form_text('auto_update_url', $values, $errors, array('required')) ?><br/><br/>
<?php endif ?>
<?= Helper\form_checkbox('image_proxy', t('Enable image proxy'), 1, isset($values['image_proxy']) && $values['image_proxy'] == 1) ?>
<div class="form-help"><?= t('Avoid mixed content warnings with HTTPS') ?></div>
<?= Helper\form_checkbox('debug_mode', t('Enable debug mode'), 1, isset($values['debug_mode']) && $values['debug_mode'] == 1) ?><br/>
<?= Helper\form_checkbox('image_proxy', t('Enable image proxy'), 1, isset($values['image_proxy']) && $values['image_proxy'] == 1) ?>
<div class="form-help"><?= t('Avoid mixed content warnings with HTTPS') ?></div>
</div>
<h3><?= t('Reading') ?></h3>
<?= Helper\form_label(t('Remove automatically read items'), 'autoflush') ?>
<?= Helper\form_select('autoflush', $autoflush_read_options, $values, $errors) ?><br/>
<div class="options">
<?= Helper\form_label(t('Remove automatically read items'), 'autoflush') ?>
<?= Helper\form_select('autoflush', $autoflush_read_options, $values, $errors) ?><br/>
<?= Helper\form_label(t('Remove automatically unread items'), 'autoflush_unread') ?>
<?= Helper\form_select('autoflush_unread', $autoflush_unread_options, $values, $errors) ?><br/>
<?= Helper\form_label(t('Remove automatically unread items'), 'autoflush_unread') ?>
<?= Helper\form_select('autoflush_unread', $autoflush_unread_options, $values, $errors) ?><br/>
<?= Helper\form_label(t('Items per page'), 'items_per_page') ?>
<?= Helper\form_select('items_per_page', $paging_options, $values, $errors) ?><br/>
<?= Helper\form_label(t('Items per page'), 'items_per_page') ?>
<?= Helper\form_select('items_per_page', $paging_options, $values, $errors) ?><br/>
<?= Helper\form_label(t('Default sorting order for items'), 'items_sorting_direction') ?>
<?= Helper\form_select('items_sorting_direction', $sorting_options, $values, $errors) ?><br/>
<?= Helper\form_label(t('Default sorting order for items'), 'items_sorting_direction') ?>
<?= Helper\form_select('items_sorting_direction', $sorting_options, $values, $errors) ?><br/>
<?= Helper\form_label(t('Display items on lists'), 'items_display_mode') ?>
<?= Helper\form_select('items_display_mode', $display_mode, $values, $errors) ?><br/>
<?= Helper\form_label(t('Display items on lists'), 'items_display_mode') ?>
<?= Helper\form_select('items_display_mode', $display_mode, $values, $errors) ?><br/>
<?= Helper\form_label(t('When there is nothing to read, redirect me to this page'), 'redirect_nothing_to_read') ?>
<?= Helper\form_select('redirect_nothing_to_read', $redirect_nothing_to_read_options, $values, $errors) ?><br/>
<?= Helper\form_label(t('When there is nothing to read, redirect me to this page'), 'redirect_nothing_to_read') ?>
<?= Helper\form_select('redirect_nothing_to_read', $redirect_nothing_to_read_options, $values, $errors) ?><br/>
<?= Helper\form_label(t('Refresh interval in minutes for unread counter'), 'frontend_updatecheck_interval') ?>
<?= Helper\form_number('frontend_updatecheck_interval', $values, $errors, array('min="0"')) ?><br/>
<?= Helper\form_label(t('Refresh interval in minutes for unread counter'), 'frontend_updatecheck_interval') ?>
<?= Helper\form_number('frontend_updatecheck_interval', $values, $errors, array('min="0"')) ?><br/>
<?= Helper\form_checkbox('nocontent', t('Do not fetch the content of articles'), 1, isset($values['nocontent']) && $values['nocontent'] == 1) ?><br />
<?= Helper\form_checkbox('favicons', t('Download favicons'), 1, isset($values['favicons']) && $values['favicons'] == 1) ?><br />
<?= Helper\form_checkbox('nocontent', t('Do not fetch the content of articles'), 1, isset($values['nocontent']) && $values['nocontent'] == 1) ?><br/>
<?= Helper\form_checkbox('favicons', t('Download favicons'), 1, isset($values['favicons']) && $values['favicons'] == 1) ?><br/>
</div>
<div class="form-actions">
<input type="submit" value="<?= t('Save') ?>" class="btn btn-blue"/>

View File

@ -7,7 +7,7 @@
</div>
<?php if (empty($content)): ?>
<p class="alert alert-info"><?= t('No message') ?></p>
<p class="alert alert-info"><?= t('Nothing to show. Enable the debug mode to see log messages.') ?></p>
<?php else: ?>
<pre id="console"><code><?= Helper\escape($content) ?></code></pre>
<?php endif ?>

View File

@ -13,29 +13,33 @@
</div>
<section>
<form method="post" action="?action=services" autocomplete="off">
<form method="post" action="?action=services" autocomplete="off" id="config-form">
<h3><?= t('Pinboard') ?></h3>
<?= Helper\form_hidden('csrf', $values) ?>
<h3><?= t('Pinboard') ?></h3>
<div class="options">
<?= Helper\form_checkbox('pinboard_enabled', t('Send bookmarks to Pinboard'), 1, isset($values['pinboard_enabled']) && $values['pinboard_enabled'] == 1) ?><br />
<?= Helper\form_checkbox('pinboard_enabled', t('Send bookmarks to Pinboard'), 1, isset($values['pinboard_enabled']) && $values['pinboard_enabled'] == 1) ?><br />
<?= Helper\form_label(t('Pinboard API token'), 'pinboard_token') ?>
<?= Helper\form_text('pinboard_token', $values, $errors) ?><br/>
<?= Helper\form_label(t('Pinboard API token'), 'pinboard_token') ?>
<?= Helper\form_text('pinboard_token', $values, $errors) ?><br/>
<?= Helper\form_label(t('Pinboard tags'), 'pinboard_tags') ?>
<?= Helper\form_text('pinboard_tags', $values, $errors) ?>
<?= Helper\form_label(t('Pinboard tags'), 'pinboard_tags') ?>
<?= Helper\form_text('pinboard_tags', $values, $errors) ?>
</div>
<h3><?= t('Instapaper') ?></h3>
<?= Helper\form_checkbox('instapaper_enabled', t('Send bookmarks to Instapaper'), 1, isset($values['instapaper_enabled']) && $values['instapaper_enabled'] == 1) ?><br />
<div class="options">
<?= Helper\form_checkbox('instapaper_enabled', t('Send bookmarks to Instapaper'), 1, isset($values['instapaper_enabled']) && $values['instapaper_enabled'] == 1) ?><br />
<?= Helper\form_label(t('Instapaper username'), 'instapaper_username') ?>
<?= Helper\form_text('instapaper_username', $values, $errors) ?><br/>
<?= Helper\form_label(t('Instapaper password'), 'instapaper_password') ?>
<?= Helper\form_password('instapaper_password', $values, $errors) ?><br/>
<?= Helper\form_label(t('Instapaper username'), 'instapaper_username') ?>
<?= Helper\form_text('instapaper_username', $values, $errors) ?><br/>
<?= Helper\form_label(t('Instapaper password'), 'instapaper_password') ?>
<?= Helper\form_password('instapaper_password', $values, $errors) ?><br/>
</div>
<div class="form-actions">
<input type="submit" value="<?= t('Save') ?>" class="btn btn-blue"/>
</div>

2
vendor/autoload.php vendored
View File

@ -4,4 +4,4 @@
require_once __DIR__ . '/composer' . '/autoload_real.php';
return ComposerAutoloaderInit489790cbd05fef7749a4adcb52f440da::getLoader();
return ComposerAutoloaderInit5f8b99c769a3ccbc962bd7a5595128da::getLoader();

View File

@ -2,7 +2,7 @@
// autoload_real.php @generated by Composer
class ComposerAutoloaderInit489790cbd05fef7749a4adcb52f440da
class ComposerAutoloaderInit5f8b99c769a3ccbc962bd7a5595128da
{
private static $loader;
@ -19,9 +19,9 @@ class ComposerAutoloaderInit489790cbd05fef7749a4adcb52f440da
return self::$loader;
}
spl_autoload_register(array('ComposerAutoloaderInit489790cbd05fef7749a4adcb52f440da', 'loadClassLoader'), true, true);
spl_autoload_register(array('ComposerAutoloaderInit5f8b99c769a3ccbc962bd7a5595128da', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader();
spl_autoload_unregister(array('ComposerAutoloaderInit489790cbd05fef7749a4adcb52f440da', 'loadClassLoader'));
spl_autoload_unregister(array('ComposerAutoloaderInit5f8b99c769a3ccbc962bd7a5595128da', 'loadClassLoader'));
$map = require __DIR__ . '/autoload_namespaces.php';
foreach ($map as $namespace => $path) {
@ -42,14 +42,14 @@ class ComposerAutoloaderInit489790cbd05fef7749a4adcb52f440da
$includeFiles = require __DIR__ . '/autoload_files.php';
foreach ($includeFiles as $file) {
composerRequire489790cbd05fef7749a4adcb52f440da($file);
composerRequire5f8b99c769a3ccbc962bd7a5595128da($file);
}
return $loader;
}
}
function composerRequire489790cbd05fef7749a4adcb52f440da($file)
function composerRequire5f8b99c769a3ccbc962bd7a5595128da($file)
{
require $file;
}

View File

@ -116,45 +116,6 @@
"description": "The most easy to use validator library for PHP :)",
"homepage": "https://github.com/fguillot/simpleValidator"
},
{
"name": "fguillot/picofeed",
"version": "dev-master",
"version_normalized": "9999999-dev",
"source": {
"type": "git",
"url": "https://github.com/fguillot/picoFeed.git",
"reference": "83e406cbfbd188dbfbc0330c0757b037a87b0928"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/fguillot/picoFeed/zipball/83e406cbfbd188dbfbc0330c0757b037a87b0928",
"reference": "83e406cbfbd188dbfbc0330c0757b037a87b0928",
"shasum": ""
},
"require": {
"php": ">=5.3.0"
},
"time": "2015-01-28 01:01:28",
"type": "library",
"installation-source": "dist",
"autoload": {
"psr-0": {
"PicoFeed": "lib/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"Unlicense"
],
"authors": [
{
"name": "Frédéric Guillot",
"homepage": "http://fredericguillot.com"
}
],
"description": "Modern library to write or read feeds (RSS/Atom)",
"homepage": "http://fguillot.github.io/picoFeed"
},
{
"name": "fguillot/picodb",
"version": "v0.0.2",
@ -193,5 +154,49 @@
],
"description": "Minimalist database query builder",
"homepage": "https://github.com/fguillot/picoDb"
},
{
"name": "fguillot/picofeed",
"version": "dev-master",
"version_normalized": "9999999-dev",
"source": {
"type": "git",
"url": "https://github.com/fguillot/picoFeed.git",
"reference": "9253c3d5ff1148a5175bf24633b73725832437c8"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/fguillot/picoFeed/zipball/9253c3d5ff1148a5175bf24633b73725832437c8",
"reference": "9253c3d5ff1148a5175bf24633b73725832437c8",
"shasum": ""
},
"require": {
"ext-dom": "*",
"ext-iconv": "*",
"ext-libxml": "*",
"ext-simplexml": "*",
"ext-xml": "*",
"php": ">=5.3.0"
},
"time": "2015-01-29 02:00:49",
"type": "library",
"installation-source": "dist",
"autoload": {
"psr-0": {
"PicoFeed": "lib/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"Unlicense"
],
"authors": [
{
"name": "Frédéric Guillot",
"homepage": "http://fredericguillot.com"
}
],
"description": "Modern library to write or read feeds (RSS/Atom)",
"homepage": "http://fguillot.github.io/picoFeed"
}
]

View File

@ -33,6 +33,7 @@ Requirements
- libxml >= 2.7
- XML PHP extensions: DOM and SimpleXML
- cURL or Stream Context (`allow_url_fopen=On`)
- iconv extension
Authors
-------

View File

@ -11,7 +11,12 @@
}
],
"require": {
"php": ">=5.3.0"
"php": ">=5.3.0",
"ext-iconv": "*",
"ext-dom": "*",
"ext-xml": "*",
"ext-libxml": "*",
"ext-SimpleXML": "*"
},
"autoload": {
"psr-0": {"PicoFeed": "lib/"}

View File

@ -2,167 +2,15 @@
namespace PicoFeed\Encoding;
/**
* @author "Sebastián Grignoli" <grignoli@framework2.com.ar>
* @package Encoding
* @version 1.2
* @link https://github.com/neitanod/forceutf8
* @example https://github.com/neitanod/forceutf8
* @license Revised BSD
*/
class Encoding
{
protected static $win1252ToUtf8 = array(
128 => "\xe2\x82\xac",
130 => "\xe2\x80\x9a",
131 => "\xc6\x92",
132 => "\xe2\x80\x9e",
133 => "\xe2\x80\xa6",
134 => "\xe2\x80\xa0",
135 => "\xe2\x80\xa1",
136 => "\xcb\x86",
137 => "\xe2\x80\xb0",
138 => "\xc5\xa0",
139 => "\xe2\x80\xb9",
140 => "\xc5\x92",
142 => "\xc5\xbd",
145 => "\xe2\x80\x98",
146 => "\xe2\x80\x99",
147 => "\xe2\x80\x9c",
148 => "\xe2\x80\x9d",
149 => "\xe2\x80\xa2",
150 => "\xe2\x80\x93",
151 => "\xe2\x80\x94",
152 => "\xcb\x9c",
153 => "\xe2\x84\xa2",
154 => "\xc5\xa1",
155 => "\xe2\x80\xba",
156 => "\xc5\x93",
158 => "\xc5\xbe",
159 => "\xc5\xb8"
);
/**
* Function Encoding::toUTF8
*
* This function leaves UTF8 characters alone, while converting almost all non-UTF8 to UTF8.
*
* It assumes that the encoding of the original string is either Windows-1252 or ISO 8859-1.
*
* It may fail to convert characters to UTF-8 if they fall into one of these scenarios:
*
* 1) when any of these characters: ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞß
* are followed by any of these: ("group B")
* ¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶•¸¹º»¼½¾¿
* For example: %ABREPRESENT%C9%BB. «REPRESENTÉ»
* The "«" (%AB) character will be converted, but the "É" followed by "»" (%C9%BB)
* is also a valid unicode character, and will be left unchanged.
*
* 2) when any of these: àáâãäåæçèéêëìíîï are followed by TWO chars from group B,
* 3) when any of these: ðñòó are followed by THREE chars from group B.
*
* @name toUTF8
* @param string $text Any string.
* @return string The same string, UTF8 encoded
*
*/
public static function toUTF8($text)
{
if (is_array($text)) {
foreach ($text as $k => $v) {
$text[$k] = self::toUTF8($v);
}
return $text;
}
elseif (is_string($text)) {
$max = strlen($text);
$buf = "";
for ($i = 0; $i < $max; $i++) {
$c1 = $text{$i};
if ($c1>="\xc0") { //Should be converted to UTF8, if it's not UTF8 already
$c2 = $i+1 >= $max? "\x00" : $text{$i+1};
$c3 = $i+2 >= $max? "\x00" : $text{$i+2};
$c4 = $i+3 >= $max? "\x00" : $text{$i+3};
if ($c1 >= "\xc0" & $c1 <= "\xdf") { //looks like 2 bytes UTF8
if ($c2 >= "\x80" && $c2 <= "\xbf") { //yeah, almost sure it's UTF8 already
$buf .= $c1 . $c2;
$i++;
}
else { //not valid UTF8. Convert it.
$buf .= self::convertInvalidCharacter($c1);
}
}
else if ($c1 >= "\xe0" & $c1 <= "\xef") { //looks like 3 bytes UTF8
if ($c2 >= "\x80" && $c2 <= "\xbf" && $c3 >= "\x80" && $c3 <= "\xbf") { //yeah, almost sure it's UTF8 already
$buf .= $c1 . $c2 . $c3;
$i = $i + 2;
}
else { //not valid UTF8. Convert it.
$buf .= self::convertInvalidCharacter($c1);
}
}
else if ($c1 >= "\xf0" & $c1 <= "\xf7") { //looks like 4 bytes UTF8
if ($c2 >= "\x80" && $c2 <= "\xbf" && $c3 >= "\x80" && $c3 <= "\xbf" && $c4 >= "\x80" && $c4 <= "\xbf") { //yeah, almost sure it's UTF8 already
$buf .= $c1 . $c2 . $c3;
$i = $i + 2;
}
else { //not valid UTF8. Convert it.
$buf .= self::convertInvalidCharacter($c1);
}
}
else { //doesn't look like UTF8, but should be converted
$buf .= self::convertInvalidCharacter($c1);
}
}
elseif (($c1 & "\xc0") == "\x80") { // needs conversion
if (isset(self::$win1252ToUtf8[ord($c1)])) { //found in Windows-1252 special cases
$buf .= self::$win1252ToUtf8[ord($c1)];
}
else {
$buf .= self::convertInvalidCharacter($c1);
}
}
else { // it doesn't need conversion
$buf .= $c1;
}
}
return $buf;
}
else {
return $text;
}
}
public static function convertInvalidCharacter($c1)
{
$cc1 = chr(ord($c1) / 64) | "\xc0";
$cc2 = ($c1 & "\x3f") | "\x80";
return $cc1.$cc2;
}
public static function convert($input, $encoding)
{
switch ($encoding) {
case 'utf-8':
return $input;
case 'windows-1251':
case 'windows-1255':
case 'windows-1256':
return iconv($encoding, 'UTF-8//TRANSLIT', $input);
default:
return self::toUTF8($input);
if ($encoding === 'utf-8' || $encoding === '') {
return $input;
}
// convert input to utf-8; ignore malformed characters
return iconv($encoding, 'UTF-8//IGNORE', $input);
}
}

View File

@ -0,0 +1,10 @@
<?php
return array(
'test_url' => 'http://www.alainonline.net/news_details.php?lang=arabic&sid=18907',
'body' => array(
'//div[@class="news_details"]'
),
'strip' => array(
'//div[@class="news_details"]/div/div[last()]',
),
);

View File

@ -32,17 +32,17 @@ class DateParserTest extends PHPUnit_Framework_TestCase
$this->assertEquals('2010-08-20', date('Y-m-d', $parser->getTimestamp('2010-08-20Thh:08:ssZ')));
$this->assertEquals(1288648057, $parser->getTimestamp('Mon, 01 Nov 2010 21:47:37 UT'));
$this->assertEquals(1346069615, $parser->getTimestamp('Mon Aug 27 2012 12:13:35 GMT-0700 (PDT)'));
$this->assertEquals(time(), $parser->getTimestamp('Tue, 3 Febuary 2010 00:00:00 IST'));
$this->assertEquals(time(), $parser->getTimestamp('############# EST'));
$this->assertEquals(time(), $parser->getTimestamp('Wed, 30 Nov -0001 00:00:00 +0000'));
$this->assertEquals(time(), $parser->getTimestamp('čet, 24 maj 2012 00:00:00'));
$this->assertEquals(time(), $parser->getTimestamp('-0-0T::Z'));
$this->assertEquals(time(), $parser->getTimestamp('Wed, 18 2012'));
$this->assertEquals(time(), $parser->getTimestamp("'2009-09-30 CDT16:09:54"));
$this->assertEquals(time(), $parser->getTimestamp('ary 8 Jan 2013 00:00:00 GMT'));
$this->assertEquals(time(), $parser->getTimestamp('Sat, 11 00:00:01 GMT'));
$this->assertEquals(time(), $parser->getTimestamp('Tue, 3 Febuary 2010 00:00:00 IST'), 1);
$this->assertEquals(time(), $parser->getTimestamp('############# EST'), 1);
$this->assertEquals(time(), $parser->getTimestamp('Wed, 30 Nov -0001 00:00:00 +0000'), 1);
$this->assertEquals(time(), $parser->getTimestamp('čet, 24 maj 2012 00:00:00'), 1);
$this->assertEquals(time(), $parser->getTimestamp('-0-0T::Z'), 1);
$this->assertEquals(time(), $parser->getTimestamp('Wed, 18 2012'), 1);
$this->assertEquals(time(), $parser->getTimestamp("'2009-09-30 CDT16:09:54"), 1);
$this->assertEquals(time(), $parser->getTimestamp('ary 8 Jan 2013 00:00:00 GMT'), 1);
$this->assertEquals(time(), $parser->getTimestamp('Sat, 11 00:00:01 GMT'), 1);
$this->assertEquals(1370631743, $parser->getTimestamp('Fri Jun 07 2013 19:02:23 GMT+0000 (UTC)'));
$this->assertEquals(1377412225, $parser->getTimestamp('25/08/2013 06:30:25 م'));
$this->assertEquals(time(), $parser->getTimestamp('+0400'));
$this->assertEquals(time(), $parser->getTimestamp('+0400'),1);
}
}

View File

@ -93,7 +93,7 @@ class Rss20ParserTest extends PHPUnit_Framework_TestCase
$parser = new Rss20(file_get_contents('tests/fixtures/fulltextrss.xml'));
$feed = $parser->execute();
$this->assertEquals(time(), $feed->getDate());
$this->assertEquals(time(), $feed->getDate(), 1);
}
public function testFeedLanguage()
@ -259,9 +259,5 @@ class Rss20ParserTest extends PHPUnit_Framework_TestCase
$parser = new Rss20(file_get_contents('tests/fixtures/jeux-linux.fr.xml'));
$feed = $parser->execute();
$this->assertNotEmpty($feed->items);
$parser = new Rss20(file_get_contents('tests/fixtures/cercle.psy.xml'));
$feed = $parser->execute();
$this->assertNotEmpty($feed->items);
}
}

View File

@ -18,13 +18,13 @@ class Rss91ParserTest extends PHPUnit_Framework_TestCase
$this->assertEquals('', $feed->getFeedUrl());
$this->assertEquals('http://writetheweb.com/', $feed->getSiteUrl());
$this->assertEquals('http://writetheweb.com/', $feed->getId());
$this->assertEquals(time(), $feed->getDate());
$this->assertEquals(time(), $feed->getDate(), 1);
$this->assertEquals(6, count($feed->items));
$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('085a9133a75542f878fa73ee2afbb6a2350b6c4fb125e6d8ca09478c47702111', $feed->items[0]->getId());
$this->assertEquals(time(), $feed->items[0]->getDate());
$this->assertEquals(time(), $feed->items[0]->getDate(), 1);
$this->assertEquals('webmaster@writetheweb.com', $feed->items[0]->getAuthor());
$this->assertTrue(strpos($feed->items[1]->getContent(), '<p>After a period of dormancy') === 0);
}

View File

@ -18,7 +18,7 @@ class Rss92ParserTest extends PHPUnit_Framework_TestCase
$this->assertEquals('', $feed->getFeedUrl());
$this->assertEquals('http://www.universfreebox.com/', $feed->getSiteUrl());
$this->assertEquals('http://www.universfreebox.com/', $feed->getId());
$this->assertEquals(time(), $feed->date);
$this->assertEquals(time(), $feed->date, 1);
$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);