aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar logmanoriginal <logmanoriginal@users.noreply.github.com> 2018-11-10 20:03:03 +0100
committerGravatar logmanoriginal <logmanoriginal@users.noreply.github.com> 2018-11-10 20:03:05 +0100
commitc63af2e7ad34c7a900259eddc0c65877ba3cfeb5 (patch)
tree247ad9fd1636a3bf3665902097e9995a95beb2da
parent9379854f7a41a52b34b12fb7cd086a4cda15dbbe (diff)
downloadrss-bridge-c63af2e7ad34c7a900259eddc0c65877ba3cfeb5.tar.gz
rss-bridge-c63af2e7ad34c7a900259eddc0c65877ba3cfeb5.tar.zst
rss-bridge-c63af2e7ad34c7a900259eddc0c65877ba3cfeb5.zip
core: Add separate Debug class
Replaces 'debugMessage' by specialized debug function 'Debug::log'. This function takes the same arguments as the previous 'debugMessage'. A separate Debug class allows for further optimization and separation of concern.
-rw-r--r--bridges/JustETFBridge.php8
-rw-r--r--bridges/WordPressPluginUpdateBridge.php2
-rw-r--r--bridges/XenForoBridge.php2
-rw-r--r--lib/Debug.php19
-rw-r--r--lib/FeedExpander.php22
-rw-r--r--lib/contents.php14
-rw-r--r--lib/error.php16
-rw-r--r--lib/rssbridge.php1
8 files changed, 44 insertions, 40 deletions
diff --git a/bridges/JustETFBridge.php b/bridges/JustETFBridge.php
index f0223e91..32aa65e6 100644
--- a/bridges/JustETFBridge.php
+++ b/bridges/JustETFBridge.php
@@ -132,7 +132,7 @@ class JustETFBridge extends BridgeAbstract {
date_time_set($df, 0, 0);
- // debugMessage(date_format($df, 'U'));
+ // Debug::log(date_format($df, 'U'));
return date_format($df, 'U');
}
@@ -210,7 +210,7 @@ class JustETFBridge extends BridgeAbstract {
$element = $article->find('div.subheadline', 0)
or returnServerError('Date not found!');
- // debugMessage($element->plaintext);
+ // Debug::log($element->plaintext);
$date = trim(explode('|', $element->plaintext)[0]);
@@ -223,7 +223,7 @@ class JustETFBridge extends BridgeAbstract {
$element->find('a', 0)->onclick = '';
- // debugMessage($element->innertext);
+ // Debug::log($element->innertext);
return $element->innertext;
}
@@ -288,7 +288,7 @@ class JustETFBridge extends BridgeAbstract {
$element = $html->find('div.infobox div.vallabel', 0)
or returnServerError('Date not found!');
- // debugMessage($element->plaintext);
+ // Debug::log($element->plaintext);
$date = trim(explode("\r\n", $element->plaintext)[1]);
diff --git a/bridges/WordPressPluginUpdateBridge.php b/bridges/WordPressPluginUpdateBridge.php
index 63b3a70d..19ec02be 100644
--- a/bridges/WordPressPluginUpdateBridge.php
+++ b/bridges/WordPressPluginUpdateBridge.php
@@ -74,7 +74,7 @@ class WordPressPluginUpdateBridge extends BridgeAbstract {
}
private function getCachedDate($url){
- debugMessage('getting pubdate from url ' . $url . '');
+ Debug::log('getting pubdate from url ' . $url . '');
// Initialize cache
$cache = Cache::create('FileCache');
$cache->setPath(PATH_CACHE . 'pages/');
diff --git a/bridges/XenForoBridge.php b/bridges/XenForoBridge.php
index 75c0f6d0..ad4df84c 100644
--- a/bridges/XenForoBridge.php
+++ b/bridges/XenForoBridge.php
@@ -453,7 +453,7 @@ class XenForoBridge extends BridgeAbstract {
}
- // debugMessage(date_format($df, 'U'));
+ // Debug::log(date_format($df, 'U'));
return date_format($df, 'U');
diff --git a/lib/Debug.php b/lib/Debug.php
new file mode 100644
index 00000000..7d1f498d
--- /dev/null
+++ b/lib/Debug.php
@@ -0,0 +1,19 @@
+<?php
+
+class Debug {
+ public static function log($text) {
+ if(!DEBUG) {
+ return;
+ }
+
+ $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 3);
+ $calling = $backtrace[2];
+ $message = $calling['file'] . ':'
+ . $calling['line'] . ' class '
+ . (isset($calling['class']) ? $calling['class'] : '<no-class>') . '->'
+ . $calling['function'] . ' - '
+ . $text;
+
+ error_log($message);
+ }
+}
diff --git a/lib/FeedExpander.php b/lib/FeedExpander.php
index 269de494..893c3ba1 100644
--- a/lib/FeedExpander.php
+++ b/lib/FeedExpander.php
@@ -11,7 +11,7 @@ abstract class FeedExpander extends BridgeAbstract {
returnServerError('There is no $url for this RSS expander');
}
- debugMessage('Loading from ' . $url);
+ Debug::log('Loading from ' . $url);
/* Notice we do not use cache here on purpose:
* we want a fresh view of the RSS stream each time
@@ -20,34 +20,34 @@ abstract class FeedExpander extends BridgeAbstract {
or returnServerError('Could not request ' . $url);
$rssContent = simplexml_load_string(trim($content));
- debugMessage('Detecting feed format/version');
+ Debug::log('Detecting feed format/version');
switch(true) {
case isset($rssContent->item[0]):
- debugMessage('Detected RSS 1.0 format');
+ Debug::log('Detected RSS 1.0 format');
$this->feedType = 'RSS_1_0';
break;
case isset($rssContent->channel[0]):
- debugMessage('Detected RSS 0.9x or 2.0 format');
+ Debug::log('Detected RSS 0.9x or 2.0 format');
$this->feedType = 'RSS_2_0';
break;
case isset($rssContent->entry[0]):
- debugMessage('Detected ATOM format');
+ Debug::log('Detected ATOM format');
$this->feedType = 'ATOM_1_0';
break;
default:
- debugMessage('Unknown feed format/version');
+ Debug::log('Unknown feed format/version');
returnServerError('The feed format is unknown!');
break;
}
- debugMessage('Calling function "collect_' . $this->feedType . '_data"');
+ Debug::log('Calling function "collect_' . $this->feedType . '_data"');
$this->{'collect_' . $this->feedType . '_data'}($rssContent, $maxItems);
}
protected function collect_RSS_1_0_data($rssContent, $maxItems){
$this->load_RSS_2_0_feed_data($rssContent->channel[0]);
foreach($rssContent->item as $item) {
- debugMessage('parsing item ' . var_export($item, true));
+ Debug::log('parsing item ' . var_export($item, true));
$tmp_item = $this->parseItem($item);
if (!empty($tmp_item)) {
$this->items[] = $tmp_item;
@@ -58,13 +58,13 @@ abstract class FeedExpander extends BridgeAbstract {
protected function collect_RSS_2_0_data($rssContent, $maxItems){
$rssContent = $rssContent->channel[0];
- debugMessage('RSS content is ===========\n'
+ Debug::log('RSS content is ===========\n'
. var_export($rssContent, true)
. '===========');
$this->load_RSS_2_0_feed_data($rssContent);
foreach($rssContent->item as $item) {
- debugMessage('parsing item ' . var_export($item, true));
+ Debug::log('parsing item ' . var_export($item, true));
$tmp_item = $this->parseItem($item);
if (!empty($tmp_item)) {
$this->items[] = $tmp_item;
@@ -76,7 +76,7 @@ abstract class FeedExpander extends BridgeAbstract {
protected function collect_ATOM_1_0_data($content, $maxItems){
$this->load_ATOM_feed_data($content);
foreach($content->entry as $item) {
- debugMessage('parsing item ' . var_export($item, true));
+ Debug::log('parsing item ' . var_export($item, true));
$tmp_item = $this->parseItem($item);
if (!empty($tmp_item)) {
$this->items[] = $tmp_item;
diff --git a/lib/contents.php b/lib/contents.php
index 41b30703..4d17add1 100644
--- a/lib/contents.php
+++ b/lib/contents.php
@@ -1,6 +1,6 @@
<?php
function getContents($url, $header = array(), $opts = array()){
- debugMessage('Reading contents from "' . $url . '"');
+ Debug::log('Reading contents from "' . $url . '"');
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
@@ -8,7 +8,7 @@ function getContents($url, $header = array(), $opts = array()){
if(is_array($header) && count($header) !== 0) {
- debugMessage('Setting headers: ' . json_encode($header));
+ Debug::log('Setting headers: ' . json_encode($header));
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
}
@@ -19,7 +19,7 @@ function getContents($url, $header = array(), $opts = array()){
if(is_array($opts) && count($opts) !== 0) {
- debugMessage('Setting options: ' . json_encode($opts));
+ Debug::log('Setting options: ' . json_encode($opts));
foreach($opts as $key => $value) {
curl_setopt($ch, $key, $value);
@@ -29,7 +29,7 @@ function getContents($url, $header = array(), $opts = array()){
if(defined('PROXY_URL') && !defined('NOPROXY')) {
- debugMessage('Setting proxy url: ' . PROXY_URL);
+ Debug::log('Setting proxy url: ' . PROXY_URL);
curl_setopt($ch, CURLOPT_PROXY, PROXY_URL);
}
@@ -42,13 +42,13 @@ function getContents($url, $header = array(), $opts = array()){
$curlErrno = curl_errno($ch);
if($data === false)
- debugMessage('Cant\'t download ' . $url . ' cUrl error: ' . $curlError . ' (' . $curlErrno . ')');
+ Debug::log('Cant\'t download ' . $url . ' cUrl error: ' . $curlError . ' (' . $curlErrno . ')');
$headerSize = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
$errorCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$header = substr($data, 0, $headerSize);
- debugMessage('Response header: ' . $header);
+ Debug::log('Response header: ' . $header);
$headers = parseResponseHeader($header);
$finalHeader = end($headers);
@@ -109,7 +109,7 @@ $target_charset = DEFAULT_TARGET_CHARSET,
$stripRN = true,
$defaultBRText = DEFAULT_BR_TEXT,
$defaultSpanText = DEFAULT_SPAN_TEXT){
- debugMessage('Caching url ' . $url . ', duration ' . $duration);
+ Debug::log('Caching url ' . $url . ', duration ' . $duration);
// Initialize cache
$cache = Cache::create('FileCache');
diff --git a/lib/error.php b/lib/error.php
index 34ad9dd3..abf3c2db 100644
--- a/lib/error.php
+++ b/lib/error.php
@@ -10,19 +10,3 @@ function returnClientError($message){
function returnServerError($message){
returnError($message, 500);
}
-
-function debugMessage($text){
- if(!file_exists('DEBUG')) {
- return;
- }
-
- $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 3);
- $calling = $backtrace[2];
- $message = $calling['file'] . ':'
- . $calling['line'] . ' class '
- . (isset($calling['class']) ? $calling['class'] : '<no-class>') . '->'
- . $calling['function'] . ' - '
- . $text;
-
- error_log($message);
-}
diff --git a/lib/rssbridge.php b/lib/rssbridge.php
index 458300fb..ac70580b 100644
--- a/lib/rssbridge.php
+++ b/lib/rssbridge.php
@@ -15,6 +15,7 @@ require_once PATH_LIB . 'CacheInterface.php';
require_once PATH_LIB . 'FormatInterface.php';
// Classes
+require_once PATH_LIB . 'Debug.php';
require_once PATH_LIB . 'Exceptions.php';
require_once PATH_LIB . 'Format.php';
require_once PATH_LIB . 'FormatAbstract.php';