diff --git a/README.markdown b/README.markdown index 6a23198..d096a2b 100644 --- a/README.markdown +++ b/README.markdown @@ -175,8 +175,8 @@ Actually, the following constants can be overrided: - `HTTP_TIMEOUT` => default value is 10 seconds - `APP_VERSION` => default value is master - `DB_FILENAME` => default value is `data/db.sqlite` -- `DEBUG` => default is false (enable logs dump of picoFeed) -- `DEBUG_DIRECTORY` => default is /tmp (place to store log files) +- `DEBUG` => default is true (enable logging of PicoFeed) +- `DEBUG_FILENAME` => default is `data/debug.log` - `THEME_DIRECTORY` => default is themes - `SESSION_SAVE_PATH` => default is empty (used to store session files in a custom directory) diff --git a/assets/css/app.css b/assets/css/app.css index c26dfa5..91086c8 100644 --- a/assets/css/app.css +++ b/assets/css/app.css @@ -15,7 +15,7 @@ body { body { margin: 0 auto; - max-width: 750px; + max-width: 780px; color: #333; font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; -webkit-font-smoothing: antialiased; @@ -116,7 +116,7 @@ pre, code { border: 1px solid #ccc; font-family: monospace; color: brown; - line-height: 1.0em; + line-height: 1.3em; border-radius: 5px; } diff --git a/common.php b/common.php index de62204..d815135 100644 --- a/common.php +++ b/common.php @@ -14,8 +14,8 @@ if (file_exists('config.php')) require 'config.php'; defined('APP_VERSION') or define('APP_VERSION', 'master'); defined('HTTP_TIMEOUT') or define('HTTP_TIMEOUT', 10); defined('DB_FILENAME') or define('DB_FILENAME', 'data/db.sqlite'); -defined('DEBUG') or define('DEBUG', false); -defined('DEBUG_DIRECTORY') or define('DEBUG_DIRECTORY', '/tmp'); +defined('DEBUG') or define('DEBUG', true); +defined('DEBUG_FILENAME') or define('DEBUG_FILENAME', 'data/debug.log'); defined('THEME_DIRECTORY') or define('THEME_DIRECTORY', 'themes'); defined('SESSION_SAVE_PATH') or define('SESSION_SAVE_PATH', ''); diff --git a/index.php b/index.php index 0d8ea33..4cad2fe 100644 --- a/index.php +++ b/index.php @@ -317,8 +317,6 @@ Router\get_action('flush-history', function() { Router\get_action('refresh-all', function() { Model\update_feeds(); - Model\write_debug(); - Session\flash(t('Your subscriptions are updated')); Response\redirect('?action=unread'); }); @@ -403,7 +401,6 @@ Router\get_action('refresh-feed', function() { $id = Request\int_param('feed_id'); if ($id) Model\update_feed($id); - Model\write_debug(); Response\redirect('?action=unread'); }); @@ -415,7 +412,6 @@ Router\post_action('refresh-feed', function() { if ($id) { $result = Model\update_feed($id); - Model\write_debug(); } Response\json(array('feed_id' => $id, 'result' => $result)); @@ -472,7 +468,6 @@ Router\get_action('add', function() { Router\post_action('add', function() { $result = Model\import_feed(trim($_POST['url'])); - Model\write_debug(); if ($result) { @@ -492,30 +487,6 @@ Router\post_action('add', function() { }); -// Re-generate tokens -Router\get_action('generate-tokens', function() { - - Model\new_tokens(); - Response\redirect('?action=config#api'); -}); - - -// Optimize the database manually -Router\get_action('optimize-db', function() { - - \PicoTools\singleton('db')->getConnection()->exec('VACUUM'); - Response\redirect('?action=config'); -}); - - -// Download the compressed database -Router\get_action('download-db', function() { - - Response\force_download('db.sqlite.gz'); - Response\binary(gzencode(file_get_contents(DB_FILENAME))); -}); - - // OPML export Router\get_action('export', function() { @@ -551,6 +522,48 @@ Router\post_action('import', function() { }); +// Re-generate tokens +Router\get_action('generate-tokens', function() { + + Model\new_tokens(); + Response\redirect('?action=config#api'); +}); + + +// Optimize the database manually +Router\get_action('optimize-db', function() { + + \PicoTools\singleton('db')->getConnection()->exec('VACUUM'); + Response\redirect('?action=config'); +}); + + +// Download the compressed database +Router\get_action('download-db', function() { + + Response\force_download('db.sqlite.gz'); + Response\binary(gzencode(file_get_contents(DB_FILENAME))); +}); + + +// Flush console messages +Router\get_action('flush-console', function() { + + @unlink(DEBUG_FILENAME); + Response\redirect('?action=console'); +}); + + +// Display console +Router\get_action('console', function() { + + Response\html(Template\layout('console', array( + 'content' => @file_get_contents(DEBUG_FILENAME), + 'title' => t('Console') + ))); +}); + + // Display preferences page Router\get_action('config', function() { diff --git a/locales/fr_FR/translations.php b/locales/fr_FR/translations.php index c0542d3..d513432 100644 --- a/locales/fr_FR/translations.php +++ b/locales/fr_FR/translations.php @@ -1,6 +1,7 @@ 'supprimer les messages', 'API endpoint:' => 'URL de l\'API : ', 'API username:' => 'Identifiant pour l\'API : ', 'API token:' => 'Clé pour l\'API : ', diff --git a/model.php b/model.php index c238757..35a36ac 100644 --- a/model.php +++ b/model.php @@ -93,11 +93,13 @@ function write_debug() { if (DEBUG) { - file_put_contents( - DEBUG_DIRECTORY.'/miniflux_'.date('YmdH').'.debug', - var_export(\PicoFeed\Logging::$messages, true).PHP_EOL, - FILE_APPEND | LOCK_EX - ); + $data = ''; + + foreach (\PicoFeed\Logging::$messages as $line) { + $data .= $line.PHP_EOL; + } + + file_put_contents(DEBUG_FILENAME, $data); } } @@ -156,9 +158,13 @@ function import_feeds($content) $db->closeTransaction(); + write_debug(); + return true; } + write_debug(); + return false; } @@ -192,12 +198,15 @@ function import_feed($url) $feed_id = $db->getConnection()->getLastId(); update_items($feed_id, $feed->items); + write_debug(); return (int) $feed_id; } } } + write_debug(); + return false; } @@ -212,6 +221,8 @@ function update_feeds($limit = LIMIT_ALL) // Auto-vacuum for people using the cronjob \PicoTools\singleton('db')->getConnection()->exec('VACUUM'); + + return true; } @@ -233,7 +244,10 @@ function update_feed($feed_id) // Update the `last_checked` column each time, HTTP cache or not update_feed_last_checked($feed_id); - if (! $resource->isModified()) return true; + if (! $resource->isModified()) { + write_debug(); + return true; + } $parser = $reader->getParser(); @@ -245,11 +259,14 @@ function update_feed($feed_id) update_feed_cache_infos($feed_id, $resource->getLastModified(), $resource->getEtag()); update_items($feed_id, $feed->items); + write_debug(); return true; } } + write_debug(); + return false; } diff --git a/templates/config.php b/templates/config.php index adffba6..a813680 100644 --- a/templates/config.php +++ b/templates/config.php @@ -63,6 +63,7 @@
= t('No messages') ?>
+ += Helper\escape($content) ?>
+
diff --git a/vendor/PicoFeed/Client.php b/vendor/PicoFeed/Client.php
index e88ecaa..8e00ced 100644
--- a/vendor/PicoFeed/Client.php
+++ b/vendor/PicoFeed/Client.php
@@ -46,9 +46,9 @@ abstract class Client
throw new \LogicException('The URL is missing');
}
- Logging::log('Fetch URL: '.$this->url);
- Logging::log('Etag: '.$this->etag);
- Logging::log('Last-Modified: '.$this->last_modified);
+ Logging::log(\get_called_class().' Fetch URL: '.$this->url);
+ Logging::log(\get_called_class().' Etag provided: '.$this->etag);
+ Logging::log(\get_called_class().' Last-Modified provided: '.$this->last_modified);
$response = $this->doRequest();
@@ -84,10 +84,10 @@ abstract class Client
}
}
- Logging::log('HTTP status code: '.$status);
+ Logging::log(\get_called_class().' HTTP status code: '.$status);
foreach ($headers as $name => $value) {
- Logging::log('HTTP headers: '.$name.' => '.$value);
+ Logging::log(\get_called_class().' HTTP headers: '.$name.' => '.$value);
}
return array($status, $headers);
diff --git a/vendor/PicoFeed/Clients/Curl.php b/vendor/PicoFeed/Clients/Curl.php
index a4d64d9..cbb935c 100644
--- a/vendor/PicoFeed/Clients/Curl.php
+++ b/vendor/PicoFeed/Clients/Curl.php
@@ -66,14 +66,14 @@ class Curl extends \PicoFeed\Client
curl_setopt($ch, CURLOPT_HEADERFUNCTION, array($this, 'readHeaders'));
curl_exec($ch);
- Logging::log('cURL total time: '.curl_getinfo($ch, CURLINFO_TOTAL_TIME));
- Logging::log('cURL dns lookup time: '.curl_getinfo($ch, CURLINFO_NAMELOOKUP_TIME));
- Logging::log('cURL connect time: '.curl_getinfo($ch, CURLINFO_CONNECT_TIME));
- Logging::log('cURL speed download: '.curl_getinfo($ch, CURLINFO_SPEED_DOWNLOAD));
+ Logging::log(\get_called_class().' cURL total time: '.curl_getinfo($ch, CURLINFO_TOTAL_TIME));
+ Logging::log(\get_called_class().' cURL dns lookup time: '.curl_getinfo($ch, CURLINFO_NAMELOOKUP_TIME));
+ Logging::log(\get_called_class().' cURL connect time: '.curl_getinfo($ch, CURLINFO_CONNECT_TIME));
+ Logging::log(\get_called_class().' cURL speed download: '.curl_getinfo($ch, CURLINFO_SPEED_DOWNLOAD));
if (curl_errno($ch)) {
- Logging::log('cURL error: '.curl_error($ch));
+ Logging::log(\get_called_class().' cURL error: '.curl_error($ch));
curl_close($ch);
return false;
diff --git a/vendor/PicoFeed/Import.php b/vendor/PicoFeed/Import.php
index f2a0ab4..76469bf 100644
--- a/vendor/PicoFeed/Import.php
+++ b/vendor/PicoFeed/Import.php
@@ -16,6 +16,8 @@ class Import
public function execute()
{
+ \PicoFeed\Logging::log(\get_called_class().': start importation');
+
try {
\libxml_use_internal_errors(true);
@@ -23,14 +25,16 @@ class Import
$xml = new \SimpleXMLElement(trim($this->content));
if ($xml->getName() !== 'opml' || ! isset($xml->body)) {
-
+ \PicoFeed\Logging::log(\get_called_class().': OPML tag not found');
return false;
}
$this->parseEntries($xml->body);
+
+ \PicoFeed\Logging::log(\get_called_class().': '.count($this->items).' subscriptions found');
}
catch (\Exception $e) {
-
+ \PicoFeed\Logging::log(\get_called_class().': '.$e->getMessage());
return false;
}
diff --git a/vendor/PicoFeed/Logging.php b/vendor/PicoFeed/Logging.php
index 4b53d19..c753fe4 100644
--- a/vendor/PicoFeed/Logging.php
+++ b/vendor/PicoFeed/Logging.php
@@ -8,6 +8,6 @@ class Logging
public static function log($message)
{
- self::$messages[] = $message;
+ self::$messages[] = '['.date('Y-m-d H:i:s').'] '.$message;
}
}
\ No newline at end of file
diff --git a/vendor/PicoFeed/Parsers/Atom.php b/vendor/PicoFeed/Parsers/Atom.php
index 3e79fd1..4959c51 100644
--- a/vendor/PicoFeed/Parsers/Atom.php
+++ b/vendor/PicoFeed/Parsers/Atom.php
@@ -6,11 +6,13 @@ class Atom extends \PicoFeed\Parser
{
public function execute()
{
+ \PicoFeed\Logging::log(\get_called_class().': begin parsing');
+
\libxml_use_internal_errors(true);
$xml = \simplexml_load_string($this->content);
if ($xml === false) {
-
+ \PicoFeed\Logging::log(\get_called_class().': XML parsing error');
\PicoFeed\Logging::log($this->getXmlErrors());
return false;
}
@@ -43,6 +45,8 @@ class Atom extends \PicoFeed\Parser
$this->items[] = $item;
}
+ \PicoFeed\Logging::log(\get_called_class().': parsing finished ('.count($this->items).' items)');
+
return $this;
}
diff --git a/vendor/PicoFeed/Parsers/Rss10.php b/vendor/PicoFeed/Parsers/Rss10.php
index 0f4d531..7e534ec 100644
--- a/vendor/PicoFeed/Parsers/Rss10.php
+++ b/vendor/PicoFeed/Parsers/Rss10.php
@@ -6,11 +6,13 @@ class Rss10 extends \PicoFeed\Parser
{
public function execute()
{
+ \PicoFeed\Logging::log(\get_called_class().': begin parsing');
+
\libxml_use_internal_errors(true);
$xml = \simplexml_load_string($this->content);
if ($xml === false) {
-
+ \PicoFeed\Logging::log(\get_called_class().': XML parsing error');
\PicoFeed\Logging::log($this->getXmlErrors());
return false;
}
@@ -78,6 +80,8 @@ class Rss10 extends \PicoFeed\Parser
$this->items[] = $item;
}
+ \PicoFeed\Logging::log(\get_called_class().': parsing finished ('.count($this->items).' items)');
+
return $this;
}
}
\ No newline at end of file
diff --git a/vendor/PicoFeed/Parsers/Rss20.php b/vendor/PicoFeed/Parsers/Rss20.php
index 7d4a6de..1c64516 100644
--- a/vendor/PicoFeed/Parsers/Rss20.php
+++ b/vendor/PicoFeed/Parsers/Rss20.php
@@ -6,11 +6,13 @@ class Rss20 extends \PicoFeed\Parser
{
public function execute()
{
+ \PicoFeed\Logging::log(\get_called_class().': begin parsing');
+
\libxml_use_internal_errors(true);
$xml = \simplexml_load_string($this->content);
if ($xml === false) {
-
+ \PicoFeed\Logging::log(\get_called_class().': XML parsing error');
\PicoFeed\Logging::log($this->getXmlErrors());
return false;
}
@@ -41,7 +43,10 @@ class Rss20 extends \PicoFeed\Parser
$this->updated = $this->updated ? strtotime($this->updated) : time();
// RSS feed might be empty
- if (! $xml->channel->item) return $this;
+ if (! $xml->channel->item) {
+ \PicoFeed\Logging::log(\get_called_class().': feed empty or malformed');
+ return $this;
+ }
foreach ($xml->channel->item as $entry) {
@@ -108,6 +113,8 @@ class Rss20 extends \PicoFeed\Parser
$this->items[] = $item;
}
+ \PicoFeed\Logging::log(\get_called_class().': parsing finished ('.count($this->items).' items)');
+
return $this;
}
}
\ No newline at end of file
diff --git a/vendor/PicoFeed/Reader.php b/vendor/PicoFeed/Reader.php
index 282c6ff..a4720c8 100644
--- a/vendor/PicoFeed/Reader.php
+++ b/vendor/PicoFeed/Reader.php
@@ -87,7 +87,7 @@ class Reader
if (strpos($first_tag, '