From 25e1213d1bcb7f8777fbe664f96b54fb5fe547bf Mon Sep 17 00:00:00 2001 From: Maryana Rozhankivska Date: Mon, 24 Feb 2014 12:19:46 +0200 Subject: fix of global $http visibility, issues #493, #494 --- inc/3rdparty/makefulltextfeed.php | 1 + 1 file changed, 1 insertion(+) (limited to 'inc/3rdparty') diff --git a/inc/3rdparty/makefulltextfeed.php b/inc/3rdparty/makefulltextfeed.php index 2852c4c2..313397d2 100755 --- a/inc/3rdparty/makefulltextfeed.php +++ b/inc/3rdparty/makefulltextfeed.php @@ -415,6 +415,7 @@ if (!$debug_mode) { ////////////////////////////////// // Set up HTTP agent ////////////////////////////////// +global $http; $http = new HumbleHttpAgent(); $http->debug = $debug_mode; $http->userAgentMap = $options->user_agents; -- cgit v1.2.3 From 4b842b20cecb198baccdeac76916df367da0400a Mon Sep 17 00:00:00 2001 From: Maryana Rozhankivska Date: Mon, 24 Feb 2014 19:13:54 +0200 Subject: fix of #486 - import issue --- inc/3rdparty/makefulltextfeed.php | 353 +----------------------------- inc/3rdparty/makefulltextfeedHelpers.php | 355 +++++++++++++++++++++++++++++++ 2 files changed, 357 insertions(+), 351 deletions(-) create mode 100755 inc/3rdparty/makefulltextfeedHelpers.php (limited to 'inc/3rdparty') diff --git a/inc/3rdparty/makefulltextfeed.php b/inc/3rdparty/makefulltextfeed.php index 313397d2..b024547f 100755 --- a/inc/3rdparty/makefulltextfeed.php +++ b/inc/3rdparty/makefulltextfeed.php @@ -55,42 +55,8 @@ if (get_magic_quotes_gpc()) { // set include path set_include_path(realpath(dirname(__FILE__).'/libraries').PATH_SEPARATOR.get_include_path()); -// Autoloading of classes allows us to include files only when they're -// needed. If we've got a cached copy, for example, only Zend_Cache is loaded. -function autoload($class_name) { - static $dir = null; - if ($dir === null) $dir = dirname(__FILE__).'/libraries/'; - static $mapping = array( - // Include FeedCreator for RSS/Atom creation - 'FeedWriter' => 'feedwriter/FeedWriter.php', - 'FeedItem' => 'feedwriter/FeedItem.php', - // Include ContentExtractor and Readability for identifying and extracting content from URLs - 'ContentExtractor' => 'content-extractor/ContentExtractor.php', - 'SiteConfig' => 'content-extractor/SiteConfig.php', - 'Readability' => 'readability/Readability.php', - // Include Humble HTTP Agent to allow parallel requests and response caching - 'HumbleHttpAgent' => 'humble-http-agent/HumbleHttpAgent.php', - 'SimplePie_HumbleHttpAgent' => 'humble-http-agent/SimplePie_HumbleHttpAgent.php', - 'CookieJar' => 'humble-http-agent/CookieJar.php', - // Include Zend Cache to improve performance (cache results) - 'Zend_Cache' => 'Zend/Cache.php', - // Language detect - 'Text_LanguageDetect' => 'language-detect/LanguageDetect.php', - // HTML5 Lib - 'HTML5_Parser' => 'html5/Parser.php', - // htmLawed - used if XSS filter is enabled (xss_filter) - 'htmLawed' => 'htmLawed/htmLawed.php' - ); - if (isset($mapping[$class_name])) { - debug("** Loading class $class_name ({$mapping[$class_name]})"); - require $dir.$mapping[$class_name]; - return true; - } else { - return false; - } -} -spl_autoload_register('autoload'); -require dirname(__FILE__).'/libraries/simplepie/autoloader.php'; + +require_once dirname(__FILE__).'/makefulltextfeedHelpers.php'; //////////////////////////////// // Load config file @@ -415,7 +381,6 @@ if (!$debug_mode) { ////////////////////////////////// // Set up HTTP agent ////////////////////////////////// -global $http; $http = new HumbleHttpAgent(); $http->debug = $debug_mode; $http->userAgentMap = $options->user_agents; @@ -479,29 +444,6 @@ if ($html_only || !$result) { $isDummyFeed = true; unset($feed, $result); // create single item dummy feed object - class DummySingleItemFeed { - public $item; - function __construct($url) { $this->item = new DummySingleItem($url); } - public function get_title() { return ''; } - public function get_description() { return 'Content extracted from '.$this->item->url; } - public function get_link() { return $this->item->url; } - public function get_language() { return false; } - public function get_image_url() { return false; } - public function get_items($start=0, $max=1) { return array(0=>$this->item); } - } - class DummySingleItem { - public $url; - function __construct($url) { $this->url = $url; } - public function get_permalink() { return $this->url; } - public function get_title() { return null; } - public function get_date($format='') { return false; } - public function get_author($key=0) { return null; } - public function get_authors() { return null; } - public function get_description() { return ''; } - public function get_enclosure($key=0, $prefer=null) { return null; } - public function get_enclosures() { return null; } - public function get_categories() { return null; } - } $feed = new DummySingleItemFeed($url); } @@ -904,294 +846,3 @@ if (!$debug_mode) { if ($callback) echo ');'; } -/////////////////////////////// -// HELPER FUNCTIONS -/////////////////////////////// - -function url_allowed($url) { - global $options; - if (!empty($options->allowed_urls)) { - $allowed = false; - foreach ($options->allowed_urls as $allowurl) { - if (stristr($url, $allowurl) !== false) { - $allowed = true; - break; - } - } - if (!$allowed) return false; - } else { - foreach ($options->blocked_urls as $blockurl) { - if (stristr($url, $blockurl) !== false) { - return false; - } - } - } - return true; -} - -////////////////////////////////////////////// -// Convert $html to UTF8 -// (uses HTTP headers and HTML to find encoding) -// adapted from http://stackoverflow.com/questions/910793/php-detect-encoding-and-make-everything-utf-8 -////////////////////////////////////////////// -function convert_to_utf8($html, $header=null) -{ - $encoding = null; - if ($html || $header) { - if (is_array($header)) $header = implode("\n", $header); - if (!$header || !preg_match_all('/^Content-Type:\s+([^;]+)(?:;\s*charset=["\']?([^;"\'\n]*))?/im', $header, $match, PREG_SET_ORDER)) { - // error parsing the response - debug('Could not find Content-Type header in HTTP response'); - } else { - $match = end($match); // get last matched element (in case of redirects) - if (isset($match[2])) $encoding = trim($match[2], "\"' \r\n\0\x0B\t"); - } - // TODO: check to see if encoding is supported (can we convert it?) - // If it's not, result will be empty string. - // For now we'll check for invalid encoding types returned by some sites, e.g. 'none' - // Problem URL: http://facta.co.jp/blog/archives/20111026001026.html - if (!$encoding || $encoding == 'none') { - // search for encoding in HTML - only look at the first 50000 characters - // Why 50000? See, for example, http://www.lemonde.fr/festival-de-cannes/article/2012/05/23/deux-cretes-en-goguette-sur-la-croisette_1705732_766360.html - // TODO: improve this so it looks at smaller chunks first - $html_head = substr($html, 0, 50000); - if (preg_match('/^<\?xml\s+version=(?:"[^"]*"|\'[^\']*\')\s+encoding=("[^"]*"|\'[^\']*\')/s', $html_head, $match)) { - $encoding = trim($match[1], '"\''); - } elseif (preg_match('/]+)/i', $html_head, $match)) { - $encoding = trim($match[1]); - } elseif (preg_match_all('/]+)>/i', $html_head, $match)) { - foreach ($match[1] as $_test) { - if (preg_match('/charset=["\']?([^"\']+)/i', $_test, $_m)) { - $encoding = trim($_m[1]); - break; - } - } - } - } - if (isset($encoding)) $encoding = trim($encoding); - // trim is important here! - if (!$encoding || (strtolower($encoding) == 'iso-8859-1')) { - // replace MS Word smart qutoes - $trans = array(); - $trans[chr(130)] = '‚'; // Single Low-9 Quotation Mark - $trans[chr(131)] = 'ƒ'; // Latin Small Letter F With Hook - $trans[chr(132)] = '„'; // Double Low-9 Quotation Mark - $trans[chr(133)] = '…'; // Horizontal Ellipsis - $trans[chr(134)] = '†'; // Dagger - $trans[chr(135)] = '‡'; // Double Dagger - $trans[chr(136)] = 'ˆ'; // Modifier Letter Circumflex Accent - $trans[chr(137)] = '‰'; // Per Mille Sign - $trans[chr(138)] = 'Š'; // Latin Capital Letter S With Caron - $trans[chr(139)] = '‹'; // Single Left-Pointing Angle Quotation Mark - $trans[chr(140)] = 'Œ'; // Latin Capital Ligature OE - $trans[chr(145)] = '‘'; // Left Single Quotation Mark - $trans[chr(146)] = '’'; // Right Single Quotation Mark - $trans[chr(147)] = '“'; // Left Double Quotation Mark - $trans[chr(148)] = '”'; // Right Double Quotation Mark - $trans[chr(149)] = '•'; // Bullet - $trans[chr(150)] = '–'; // En Dash - $trans[chr(151)] = '—'; // Em Dash - $trans[chr(152)] = '˜'; // Small Tilde - $trans[chr(153)] = '™'; // Trade Mark Sign - $trans[chr(154)] = 'š'; // Latin Small Letter S With Caron - $trans[chr(155)] = '›'; // Single Right-Pointing Angle Quotation Mark - $trans[chr(156)] = 'œ'; // Latin Small Ligature OE - $trans[chr(159)] = 'Ÿ'; // Latin Capital Letter Y With Diaeresis - $html = strtr($html, $trans); - } - if (!$encoding) { - debug('No character encoding found, so treating as UTF-8'); - $encoding = 'utf-8'; - } else { - debug('Character encoding: '.$encoding); - if (strtolower($encoding) != 'utf-8') { - debug('Converting to UTF-8'); - $html = SimplePie_Misc::change_encoding($html, $encoding, 'utf-8'); - /* - if (function_exists('iconv')) { - // iconv appears to handle certain character encodings better than mb_convert_encoding - $html = iconv($encoding, 'utf-8', $html); - } else { - $html = mb_convert_encoding($html, 'utf-8', $encoding); - } - */ - } - } - } - return $html; -} - -function makeAbsolute($base, $elem) { - $base = new SimplePie_IRI($base); - // remove '//' in URL path (used to prevent URLs from resolving properly) - // TODO: check if this is still the case - if (isset($base->path)) $base->path = preg_replace('!//+!', '/', $base->path); - foreach(array('a'=>'href', 'img'=>'src') as $tag => $attr) { - $elems = $elem->getElementsByTagName($tag); - for ($i = $elems->length-1; $i >= 0; $i--) { - $e = $elems->item($i); - //$e->parentNode->replaceChild($articleContent->ownerDocument->createTextNode($e->textContent), $e); - makeAbsoluteAttr($base, $e, $attr); - } - if (strtolower($elem->tagName) == $tag) makeAbsoluteAttr($base, $elem, $attr); - } -} -function makeAbsoluteAttr($base, $e, $attr) { - if ($e->hasAttribute($attr)) { - // Trim leading and trailing white space. I don't really like this but - // unfortunately it does appear on some sites. e.g. - $url = trim(str_replace('%20', ' ', $e->getAttribute($attr))); - $url = str_replace(' ', '%20', $url); - if (!preg_match('!https?://!i', $url)) { - if ($absolute = SimplePie_IRI::absolutize($base, $url)) { - $e->setAttribute($attr, $absolute); - } - } - } -} -function makeAbsoluteStr($base, $url) { - $base = new SimplePie_IRI($base); - // remove '//' in URL path (causes URLs not to resolve properly) - if (isset($base->path)) $base->path = preg_replace('!//+!', '/', $base->path); - if (preg_match('!^https?://!i', $url)) { - // already absolute - return $url; - } else { - if ($absolute = SimplePie_IRI::absolutize($base, $url)) { - return $absolute; - } - return false; - } -} -// returns single page response, or false if not found -function getSinglePage($item, $html, $url) { - global $http, $extractor; - debug('Looking for site config files to see if single page link exists'); - $site_config = $extractor->buildSiteConfig($url, $html); - $splink = null; - if (!empty($site_config->single_page_link)) { - $splink = $site_config->single_page_link; - } elseif (!empty($site_config->single_page_link_in_feed)) { - // single page link xpath is targeted at feed - $splink = $site_config->single_page_link_in_feed; - // so let's replace HTML with feed item description - $html = $item->get_description(); - } - if (isset($splink)) { - // Build DOM tree from HTML - $readability = new Readability($html, $url); - $xpath = new DOMXPath($readability->dom); - // Loop through single_page_link xpath expressions - $single_page_url = null; - foreach ($splink as $pattern) { - $elems = @$xpath->evaluate($pattern, $readability->dom); - if (is_string($elems)) { - $single_page_url = trim($elems); - break; - } elseif ($elems instanceof DOMNodeList && $elems->length > 0) { - foreach ($elems as $item) { - if ($item instanceof DOMElement && $item->hasAttribute('href')) { - $single_page_url = $item->getAttribute('href'); - break 2; - } elseif ($item instanceof DOMAttr && $item->value) { - $single_page_url = $item->value; - break 2; - } - } - } - } - // If we've got URL, resolve against $url - if (isset($single_page_url) && ($single_page_url = makeAbsoluteStr($url, $single_page_url))) { - // check it's not what we have already! - if ($single_page_url != $url) { - // it's not, so let's try to fetch it... - $_prev_ref = $http->referer; - $http->referer = $single_page_url; - if (($response = $http->get($single_page_url, true)) && $response['status_code'] < 300) { - $http->referer = $_prev_ref; - return $response; - } - $http->referer = $_prev_ref; - } - } - } - return false; -} - -// based on content-type http header, decide what to do -// param: HTTP headers string -// return: array with keys: 'mime', 'type', 'subtype', 'action', 'name' -// e.g. array('mime'=>'image/jpeg', 'type'=>'image', 'subtype'=>'jpeg', 'action'=>'link', 'name'=>'Image') -function get_mime_action_info($headers) { - global $options; - // check if action defined for returned Content-Type - $info = array(); - if (preg_match('!^Content-Type:\s*(([-\w]+)/([-\w\+]+))!im', $headers, $match)) { - // look for full mime type (e.g. image/jpeg) or just type (e.g. image) - // match[1] = full mime type, e.g. image/jpeg - // match[2] = first part, e.g. image - // match[3] = last part, e.g. jpeg - $info['mime'] = strtolower(trim($match[1])); - $info['type'] = strtolower(trim($match[2])); - $info['subtype'] = strtolower(trim($match[3])); - foreach (array($info['mime'], $info['type']) as $_mime) { - if (isset($options->content_type_exc[$_mime])) { - $info['action'] = $options->content_type_exc[$_mime]['action']; - $info['name'] = $options->content_type_exc[$_mime]['name']; - break; - } - } - } - return $info; -} - -function remove_url_cruft($url) { - // remove google analytics for the time being - // regex adapted from http://navitronic.co.uk/2010/12/removing-google-analytics-cruft-from-urls/ - // https://gist.github.com/758177 - return preg_replace('/(\?|\&)utm_[a-z]+=[^\&]+/', '', $url); -} - -function make_substitutions($string) { - if ($string == '') return $string; - global $item, $effective_url; - $string = str_replace('{url}', htmlspecialchars($item->get_permalink()), $string); - $string = str_replace('{effective-url}', htmlspecialchars($effective_url), $string); - return $string; -} - -function get_cache() { - global $options, $valid_key; - static $cache = null; - if ($cache === null) { - $frontendOptions = array( - 'lifetime' => 10*60, // cache lifetime of 10 minutes - 'automatic_serialization' => false, - 'write_control' => false, - 'automatic_cleaning_factor' => $options->cache_cleanup, - 'ignore_user_abort' => false - ); - $backendOptions = array( - 'cache_dir' => ($valid_key) ? $options->cache_dir.'/rss-with-key/' : $options->cache_dir.'/rss/', // directory where to put the cache files - 'file_locking' => false, - 'read_control' => true, - 'read_control_type' => 'strlen', - 'hashed_directory_level' => $options->cache_directory_level, - 'hashed_directory_perm' => 0777, - 'cache_file_perm' => 0664, - 'file_name_prefix' => 'ff' - ); - // getting a Zend_Cache_Core object - $cache = Zend_Cache::factory('Core', 'File', $frontendOptions, $backendOptions); - } - return $cache; -} - -function debug($msg) { - global $debug_mode; - if ($debug_mode) { - echo '* ',$msg,"\n"; - ob_flush(); - flush(); - } -} \ No newline at end of file diff --git a/inc/3rdparty/makefulltextfeedHelpers.php b/inc/3rdparty/makefulltextfeedHelpers.php new file mode 100755 index 00000000..1c11b8f6 --- /dev/null +++ b/inc/3rdparty/makefulltextfeedHelpers.php @@ -0,0 +1,355 @@ + 'feedwriter/FeedWriter.php', + 'FeedItem' => 'feedwriter/FeedItem.php', + // Include ContentExtractor and Readability for identifying and extracting content from URLs + 'ContentExtractor' => 'content-extractor/ContentExtractor.php', + 'SiteConfig' => 'content-extractor/SiteConfig.php', + 'Readability' => 'readability/Readability.php', + // Include Humble HTTP Agent to allow parallel requests and response caching + 'HumbleHttpAgent' => 'humble-http-agent/HumbleHttpAgent.php', + 'SimplePie_HumbleHttpAgent' => 'humble-http-agent/SimplePie_HumbleHttpAgent.php', + 'CookieJar' => 'humble-http-agent/CookieJar.php', + // Include Zend Cache to improve performance (cache results) + 'Zend_Cache' => 'Zend/Cache.php', + // Language detect + 'Text_LanguageDetect' => 'language-detect/LanguageDetect.php', + // HTML5 Lib + 'HTML5_Parser' => 'html5/Parser.php', + // htmLawed - used if XSS filter is enabled (xss_filter) + 'htmLawed' => 'htmLawed/htmLawed.php' + ); + if (isset($mapping[$class_name])) { + debug("** Loading class $class_name ({$mapping[$class_name]})"); + require $dir.$mapping[$class_name]; + return true; + } else { + return false; + } +} +spl_autoload_register('autoload'); +require dirname(__FILE__).'/libraries/simplepie/autoloader.php'; + + +class DummySingleItemFeed { + public $item; + function __construct($url) { $this->item = new DummySingleItem($url); } + public function get_title() { return ''; } + public function get_description() { return 'Content extracted from '.$this->item->url; } + public function get_link() { return $this->item->url; } + public function get_language() { return false; } + public function get_image_url() { return false; } + public function get_items($start=0, $max=1) { return array(0=>$this->item); } +} +class DummySingleItem { + public $url; + function __construct($url) { $this->url = $url; } + public function get_permalink() { return $this->url; } + public function get_title() { return null; } + public function get_date($format='') { return false; } + public function get_author($key=0) { return null; } + public function get_authors() { return null; } + public function get_description() { return ''; } + public function get_enclosure($key=0, $prefer=null) { return null; } + public function get_enclosures() { return null; } + public function get_categories() { return null; } +} + +/////////////////////////////// +// HELPER FUNCTIONS +/////////////////////////////// + +function url_allowed($url) { + global $options; + if (!empty($options->allowed_urls)) { + $allowed = false; + foreach ($options->allowed_urls as $allowurl) { + if (stristr($url, $allowurl) !== false) { + $allowed = true; + break; + } + } + if (!$allowed) return false; + } else { + foreach ($options->blocked_urls as $blockurl) { + if (stristr($url, $blockurl) !== false) { + return false; + } + } + } + return true; +} + +////////////////////////////////////////////// +// Convert $html to UTF8 +// (uses HTTP headers and HTML to find encoding) +// adapted from http://stackoverflow.com/questions/910793/php-detect-encoding-and-make-everything-utf-8 +////////////////////////////////////////////// +function convert_to_utf8($html, $header=null) +{ + $encoding = null; + if ($html || $header) { + if (is_array($header)) $header = implode("\n", $header); + if (!$header || !preg_match_all('/^Content-Type:\s+([^;]+)(?:;\s*charset=["\']?([^;"\'\n]*))?/im', $header, $match, PREG_SET_ORDER)) { + // error parsing the response + debug('Could not find Content-Type header in HTTP response'); + } else { + $match = end($match); // get last matched element (in case of redirects) + if (isset($match[2])) $encoding = trim($match[2], "\"' \r\n\0\x0B\t"); + } + // TODO: check to see if encoding is supported (can we convert it?) + // If it's not, result will be empty string. + // For now we'll check for invalid encoding types returned by some sites, e.g. 'none' + // Problem URL: http://facta.co.jp/blog/archives/20111026001026.html + if (!$encoding || $encoding == 'none') { + // search for encoding in HTML - only look at the first 50000 characters + // Why 50000? See, for example, http://www.lemonde.fr/festival-de-cannes/article/2012/05/23/deux-cretes-en-goguette-sur-la-croisette_1705732_766360.html + // TODO: improve this so it looks at smaller chunks first + $html_head = substr($html, 0, 50000); + if (preg_match('/^<\?xml\s+version=(?:"[^"]*"|\'[^\']*\')\s+encoding=("[^"]*"|\'[^\']*\')/s', $html_head, $match)) { + $encoding = trim($match[1], '"\''); + } elseif (preg_match('/]+)/i', $html_head, $match)) { + $encoding = trim($match[1]); + } elseif (preg_match_all('/]+)>/i', $html_head, $match)) { + foreach ($match[1] as $_test) { + if (preg_match('/charset=["\']?([^"\']+)/i', $_test, $_m)) { + $encoding = trim($_m[1]); + break; + } + } + } + } + if (isset($encoding)) $encoding = trim($encoding); + // trim is important here! + if (!$encoding || (strtolower($encoding) == 'iso-8859-1')) { + // replace MS Word smart qutoes + $trans = array(); + $trans[chr(130)] = '‚'; // Single Low-9 Quotation Mark + $trans[chr(131)] = 'ƒ'; // Latin Small Letter F With Hook + $trans[chr(132)] = '„'; // Double Low-9 Quotation Mark + $trans[chr(133)] = '…'; // Horizontal Ellipsis + $trans[chr(134)] = '†'; // Dagger + $trans[chr(135)] = '‡'; // Double Dagger + $trans[chr(136)] = 'ˆ'; // Modifier Letter Circumflex Accent + $trans[chr(137)] = '‰'; // Per Mille Sign + $trans[chr(138)] = 'Š'; // Latin Capital Letter S With Caron + $trans[chr(139)] = '‹'; // Single Left-Pointing Angle Quotation Mark + $trans[chr(140)] = 'Œ'; // Latin Capital Ligature OE + $trans[chr(145)] = '‘'; // Left Single Quotation Mark + $trans[chr(146)] = '’'; // Right Single Quotation Mark + $trans[chr(147)] = '“'; // Left Double Quotation Mark + $trans[chr(148)] = '”'; // Right Double Quotation Mark + $trans[chr(149)] = '•'; // Bullet + $trans[chr(150)] = '–'; // En Dash + $trans[chr(151)] = '—'; // Em Dash + $trans[chr(152)] = '˜'; // Small Tilde + $trans[chr(153)] = '™'; // Trade Mark Sign + $trans[chr(154)] = 'š'; // Latin Small Letter S With Caron + $trans[chr(155)] = '›'; // Single Right-Pointing Angle Quotation Mark + $trans[chr(156)] = 'œ'; // Latin Small Ligature OE + $trans[chr(159)] = 'Ÿ'; // Latin Capital Letter Y With Diaeresis + $html = strtr($html, $trans); + } + if (!$encoding) { + debug('No character encoding found, so treating as UTF-8'); + $encoding = 'utf-8'; + } else { + debug('Character encoding: '.$encoding); + if (strtolower($encoding) != 'utf-8') { + debug('Converting to UTF-8'); + $html = SimplePie_Misc::change_encoding($html, $encoding, 'utf-8'); + /* + if (function_exists('iconv')) { + // iconv appears to handle certain character encodings better than mb_convert_encoding + $html = iconv($encoding, 'utf-8', $html); + } else { + $html = mb_convert_encoding($html, 'utf-8', $encoding); + } + */ + } + } + } + return $html; +} + +function makeAbsolute($base, $elem) { + $base = new SimplePie_IRI($base); + // remove '//' in URL path (used to prevent URLs from resolving properly) + // TODO: check if this is still the case + if (isset($base->path)) $base->path = preg_replace('!//+!', '/', $base->path); + foreach(array('a'=>'href', 'img'=>'src') as $tag => $attr) { + $elems = $elem->getElementsByTagName($tag); + for ($i = $elems->length-1; $i >= 0; $i--) { + $e = $elems->item($i); + //$e->parentNode->replaceChild($articleContent->ownerDocument->createTextNode($e->textContent), $e); + makeAbsoluteAttr($base, $e, $attr); + } + if (strtolower($elem->tagName) == $tag) makeAbsoluteAttr($base, $elem, $attr); + } +} +function makeAbsoluteAttr($base, $e, $attr) { + if ($e->hasAttribute($attr)) { + // Trim leading and trailing white space. I don't really like this but + // unfortunately it does appear on some sites. e.g. + $url = trim(str_replace('%20', ' ', $e->getAttribute($attr))); + $url = str_replace(' ', '%20', $url); + if (!preg_match('!https?://!i', $url)) { + if ($absolute = SimplePie_IRI::absolutize($base, $url)) { + $e->setAttribute($attr, $absolute); + } + } + } +} +function makeAbsoluteStr($base, $url) { + $base = new SimplePie_IRI($base); + // remove '//' in URL path (causes URLs not to resolve properly) + if (isset($base->path)) $base->path = preg_replace('!//+!', '/', $base->path); + if (preg_match('!^https?://!i', $url)) { + // already absolute + return $url; + } else { + if ($absolute = SimplePie_IRI::absolutize($base, $url)) { + return $absolute; + } + return false; + } +} +// returns single page response, or false if not found +function getSinglePage($item, $html, $url) { + global $http, $extractor; + debug('Looking for site config files to see if single page link exists'); + $site_config = $extractor->buildSiteConfig($url, $html); + $splink = null; + if (!empty($site_config->single_page_link)) { + $splink = $site_config->single_page_link; + } elseif (!empty($site_config->single_page_link_in_feed)) { + // single page link xpath is targeted at feed + $splink = $site_config->single_page_link_in_feed; + // so let's replace HTML with feed item description + $html = $item->get_description(); + } + if (isset($splink)) { + // Build DOM tree from HTML + $readability = new Readability($html, $url); + $xpath = new DOMXPath($readability->dom); + // Loop through single_page_link xpath expressions + $single_page_url = null; + foreach ($splink as $pattern) { + $elems = @$xpath->evaluate($pattern, $readability->dom); + if (is_string($elems)) { + $single_page_url = trim($elems); + break; + } elseif ($elems instanceof DOMNodeList && $elems->length > 0) { + foreach ($elems as $item) { + if ($item instanceof DOMElement && $item->hasAttribute('href')) { + $single_page_url = $item->getAttribute('href'); + break 2; + } elseif ($item instanceof DOMAttr && $item->value) { + $single_page_url = $item->value; + break 2; + } + } + } + } + // If we've got URL, resolve against $url + if (isset($single_page_url) && ($single_page_url = makeAbsoluteStr($url, $single_page_url))) { + // check it's not what we have already! + if ($single_page_url != $url) { + // it's not, so let's try to fetch it... + $_prev_ref = $http->referer; + $http->referer = $single_page_url; + if (($response = $http->get($single_page_url, true)) && $response['status_code'] < 300) { + $http->referer = $_prev_ref; + return $response; + } + $http->referer = $_prev_ref; + } + } + } + return false; +} + +// based on content-type http header, decide what to do +// param: HTTP headers string +// return: array with keys: 'mime', 'type', 'subtype', 'action', 'name' +// e.g. array('mime'=>'image/jpeg', 'type'=>'image', 'subtype'=>'jpeg', 'action'=>'link', 'name'=>'Image') +function get_mime_action_info($headers) { + global $options; + // check if action defined for returned Content-Type + $info = array(); + if (preg_match('!^Content-Type:\s*(([-\w]+)/([-\w\+]+))!im', $headers, $match)) { + // look for full mime type (e.g. image/jpeg) or just type (e.g. image) + // match[1] = full mime type, e.g. image/jpeg + // match[2] = first part, e.g. image + // match[3] = last part, e.g. jpeg + $info['mime'] = strtolower(trim($match[1])); + $info['type'] = strtolower(trim($match[2])); + $info['subtype'] = strtolower(trim($match[3])); + foreach (array($info['mime'], $info['type']) as $_mime) { + if (isset($options->content_type_exc[$_mime])) { + $info['action'] = $options->content_type_exc[$_mime]['action']; + $info['name'] = $options->content_type_exc[$_mime]['name']; + break; + } + } + } + return $info; +} + +function remove_url_cruft($url) { + // remove google analytics for the time being + // regex adapted from http://navitronic.co.uk/2010/12/removing-google-analytics-cruft-from-urls/ + // https://gist.github.com/758177 + return preg_replace('/(\?|\&)utm_[a-z]+=[^\&]+/', '', $url); +} + +function make_substitutions($string) { + if ($string == '') return $string; + global $item, $effective_url; + $string = str_replace('{url}', htmlspecialchars($item->get_permalink()), $string); + $string = str_replace('{effective-url}', htmlspecialchars($effective_url), $string); + return $string; +} + +function get_cache() { + global $options, $valid_key; + static $cache = null; + if ($cache === null) { + $frontendOptions = array( + 'lifetime' => 10*60, // cache lifetime of 10 minutes + 'automatic_serialization' => false, + 'write_control' => false, + 'automatic_cleaning_factor' => $options->cache_cleanup, + 'ignore_user_abort' => false + ); + $backendOptions = array( + 'cache_dir' => ($valid_key) ? $options->cache_dir.'/rss-with-key/' : $options->cache_dir.'/rss/', // directory where to put the cache files + 'file_locking' => false, + 'read_control' => true, + 'read_control_type' => 'strlen', + 'hashed_directory_level' => $options->cache_directory_level, + 'hashed_directory_perm' => 0777, + 'cache_file_perm' => 0664, + 'file_name_prefix' => 'ff' + ); + // getting a Zend_Cache_Core object + $cache = Zend_Cache::factory('Core', 'File', $frontendOptions, $backendOptions); + } + return $cache; +} + +function debug($msg) { + global $debug_mode; + if ($debug_mode) { + echo '* ',$msg,"\n"; + ob_flush(); + flush(); + } +} -- cgit v1.2.3 From f5b5622a89fc24dcf9b65db5dd0d0306b3fba17f Mon Sep 17 00:00:00 2001 From: Maryana Rozhankivska Date: Tue, 25 Feb 2014 19:08:18 +0200 Subject: fix of #498, #493, #494 - because disappeared in last commit --- inc/3rdparty/makefulltextfeed.php | 1 + 1 file changed, 1 insertion(+) (limited to 'inc/3rdparty') diff --git a/inc/3rdparty/makefulltextfeed.php b/inc/3rdparty/makefulltextfeed.php index b024547f..135964f1 100755 --- a/inc/3rdparty/makefulltextfeed.php +++ b/inc/3rdparty/makefulltextfeed.php @@ -381,6 +381,7 @@ if (!$debug_mode) { ////////////////////////////////// // Set up HTTP agent ////////////////////////////////// +global $http; $http = new HumbleHttpAgent(); $http->debug = $debug_mode; $http->userAgentMap = $options->user_agents; -- cgit v1.2.3 From 223268c2fa34c497d91338e2553bc74bb1b26859 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Sat, 1 Mar 2014 13:09:37 +0100 Subject: [fix] RSS Feeds don't validate / W3C #384 --- inc/3rdparty/libraries/feedwriter/FeedItem.php | 1 + 1 file changed, 1 insertion(+) (limited to 'inc/3rdparty') diff --git a/inc/3rdparty/libraries/feedwriter/FeedItem.php b/inc/3rdparty/libraries/feedwriter/FeedItem.php index 9373deeb..0eae5e08 100644 --- a/inc/3rdparty/libraries/feedwriter/FeedItem.php +++ b/inc/3rdparty/libraries/feedwriter/FeedItem.php @@ -156,6 +156,7 @@ if($this->version == RSS2 || $this->version == RSS1) { $this->setElement('link', $link); + $this->setElement('guid', $link); } else { -- cgit v1.2.3 From 71b0d53c5e5d44a928870f7c98beac7b34199ba0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Sun, 2 Mar 2014 08:38:26 +0100 Subject: [fix] #115 cookie lifetime was empty --- inc/3rdparty/Session.class.php | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'inc/3rdparty') diff --git a/inc/3rdparty/Session.class.php b/inc/3rdparty/Session.class.php index b30a31f3..599b68cd 100644 --- a/inc/3rdparty/Session.class.php +++ b/inc/3rdparty/Session.class.php @@ -33,7 +33,7 @@ class Session // his/her session is considered expired (3600 sec. = 1 hour) public static $inactivityTimeout = 86400; // Extra timeout for long sessions (if enabled) (82800 sec. = 23 hours) - public static $longSessionTimeout = 31536000; + public static $longSessionTimeout = 604800; // 604800 = a week // If you get disconnected often or if your IP address changes often. // Let you disable session cookie hijacking protection public static $disableSessionProtection = false; @@ -61,7 +61,7 @@ class Session if (isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == "on") { $ssl = true; } - session_set_cookie_params($cookie['lifetime'], $cookiedir, $_SERVER['HTTP_HOST'], $ssl); + session_set_cookie_params(self::$longSessionTimeout, $cookiedir, $_SERVER['HTTP_HOST'], $ssl); // Use cookies to store session. ini_set('session.use_cookies', 1); // Force cookies for session (phpsessionID forbidden in URL) @@ -143,7 +143,14 @@ class Session */ public static function logout() { - unset($_SESSION['uid'],$_SESSION['ip'],$_SESSION['expires_on'],$_SESSION['tokens'], $_SESSION['login'], $_SESSION['pass'], $_SESSION['longlastingsession'], $_SESSION['poche_user']); + // unset($_SESSION['uid'],$_SESSION['ip'],$_SESSION['expires_on'],$_SESSION['tokens'], $_SESSION['login'], $_SESSION['pass'], $_SESSION['longlastingsession'], $_SESSION['poche_user']); + + // Destruction du cookie (le code peut paraître complexe mais c'est pour être certain de reprendre les mêmes paramètres) + $args = array_merge(array(session_name(), ''), array_values(session_get_cookie_params())); + $args[2] = time() - 3600; + call_user_func_array('setcookie', $args); + // Suppression physique de la session + session_destroy(); } /** -- cgit v1.2.3 From eb5b677250d16e6831bda43661c82e730358de65 Mon Sep 17 00:00:00 2001 From: Maryana Rozhankivska Date: Mon, 17 Mar 2014 22:22:05 +0200 Subject: fix of #115 - stay connected and session livetime --- inc/3rdparty/Session.class.php | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) (limited to 'inc/3rdparty') diff --git a/inc/3rdparty/Session.class.php b/inc/3rdparty/Session.class.php index 599b68cd..4ee5d1da 100644 --- a/inc/3rdparty/Session.class.php +++ b/inc/3rdparty/Session.class.php @@ -31,9 +31,9 @@ class Session public static $sessionName = ''; // If the user does not access any page within this time, // his/her session is considered expired (3600 sec. = 1 hour) - public static $inactivityTimeout = 86400; + public static $inactivityTimeout = 3600; // Extra timeout for long sessions (if enabled) (82800 sec. = 23 hours) - public static $longSessionTimeout = 604800; // 604800 = a week + public static $longSessionTimeout = 7776000; // 7776000 = 90 days // If you get disconnected often or if your IP address changes often. // Let you disable session cookie hijacking protection public static $disableSessionProtection = false; @@ -48,8 +48,13 @@ class Session /** * Initialize session */ - public static function init() + public static function init($longlastingsession = false) { + //check if session name is correct + if ( session_id() && session_id()!=self::$sessionName ) { + session_destroy(); + } + // Force cookie path (but do not change lifetime) $cookie = session_get_cookie_params(); // Default cookie expiration and path. @@ -61,12 +66,19 @@ class Session if (isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == "on") { $ssl = true; } - session_set_cookie_params(self::$longSessionTimeout, $cookiedir, $_SERVER['HTTP_HOST'], $ssl); + + if ( $longlastingsession ) { + session_set_cookie_params(self::$longSessionTimeout, $cookiedir, $_SERVER['HTTP_HOST'], $ssl, true); + } + else { + session_set_cookie_params('', $cookiedir, $_SERVER['HTTP_HOST'], $ssl, true); + } + // Use cookies to store session. ini_set('session.use_cookies', 1); // Force cookies for session (phpsessionID forbidden in URL) ini_set('session.use_only_cookies', 1); - if (!session_id()) { + if ( !session_id() ) { // Prevent php to use sessionID in URL if cookies are disabled. ini_set('session.use_trans_sid', false); if (!empty(self::$sessionName)) { @@ -115,6 +127,9 @@ class Session if (self::banCanLogin()) { if ($login === $loginTest && $password === $passwordTest) { self::banLoginOk(); + + self::init($longlastingsession); + // Generate unique random number to sign forms (HMAC) $_SESSION['uid'] = sha1(uniqid('', true).'_'.mt_rand()); $_SESSION['ip'] = self::_allIPs(); @@ -135,6 +150,7 @@ class Session self::banLoginFailed(); } + self::init(); return false; } -- cgit v1.2.3 From 2a97194253cf128aa5fb6e608f0831efbe0dc9bf Mon Sep 17 00:00:00 2001 From: Maryana Rozhankivska Date: Tue, 18 Mar 2014 17:39:19 +0200 Subject: fix of #115, server relater config value added --- inc/3rdparty/Session.class.php | 3 +++ 1 file changed, 3 insertions(+) (limited to 'inc/3rdparty') diff --git a/inc/3rdparty/Session.class.php b/inc/3rdparty/Session.class.php index 4ee5d1da..da7a4353 100644 --- a/inc/3rdparty/Session.class.php +++ b/inc/3rdparty/Session.class.php @@ -73,6 +73,9 @@ class Session else { session_set_cookie_params('', $cookiedir, $_SERVER['HTTP_HOST'], $ssl, true); } + //set server side valid session timeout + //WARNING! this may not work in shared session environment. See http://www.php.net/manual/en/session.configuration.php#ini.session.gc-maxlifetime about min value: it can be set in any application + ini_set('session.gc_maxlifetime', self::$longSessionTimeout); // Use cookies to store session. ini_set('session.use_cookies', 1); -- cgit v1.2.3 From 6fa3f70bc217bbc4a352c287d3b896a6dd50994c Mon Sep 17 00:00:00 2001 From: Maryana Rozhankivska Date: Wed, 19 Mar 2014 19:22:04 +0200 Subject: fix of _SESSION - indefined variable --- inc/3rdparty/class.messages.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'inc/3rdparty') diff --git a/inc/3rdparty/class.messages.php b/inc/3rdparty/class.messages.php index e60bd3a1..27c28f43 100644 --- a/inc/3rdparty/class.messages.php +++ b/inc/3rdparty/class.messages.php @@ -59,6 +59,7 @@ class Messages { $this->msgId = md5(uniqid()); // Create the session array if it doesnt already exist + settype($_SESSION, 'array'); if( !array_key_exists('flash_messages', $_SESSION) ) $_SESSION['flash_messages'] = array(); } @@ -228,4 +229,4 @@ class Messages { } // end class -?> \ No newline at end of file +?> -- cgit v1.2.3 From ad53faf25cc2f83594f3f756923a042351f4f202 Mon Sep 17 00:00:00 2001 From: Maryana Rozhankivska Date: Fri, 21 Mar 2014 14:59:30 +0200 Subject: fix of issue under nginx and php-fpm --- inc/3rdparty/Session.class.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'inc/3rdparty') diff --git a/inc/3rdparty/Session.class.php b/inc/3rdparty/Session.class.php index da7a4353..8c747558 100644 --- a/inc/3rdparty/Session.class.php +++ b/inc/3rdparty/Session.class.php @@ -51,7 +51,7 @@ class Session public static function init($longlastingsession = false) { //check if session name is correct - if ( session_id() && session_id()!=self::$sessionName ) { + if ( (session_id() && !empty(self::$sessionName) && session_name()!=self::$sessionName) || $longlastingsession ) { session_destroy(); } @@ -71,7 +71,7 @@ class Session session_set_cookie_params(self::$longSessionTimeout, $cookiedir, $_SERVER['HTTP_HOST'], $ssl, true); } else { - session_set_cookie_params('', $cookiedir, $_SERVER['HTTP_HOST'], $ssl, true); + session_set_cookie_params(0, $cookiedir, $_SERVER['HTTP_HOST'], $ssl, true); } //set server side valid session timeout //WARNING! this may not work in shared session environment. See http://www.php.net/manual/en/session.configuration.php#ini.session.gc-maxlifetime about min value: it can be set in any application @@ -183,7 +183,7 @@ class Session || (self::$disableSessionProtection === false && $_SESSION['ip'] !== self::_allIPs()) || time() >= $_SESSION['expires_on']) { - self::logout(); + //self::logout(); return false; } -- cgit v1.2.3 From 03832b45e1d29fe2c301ba34412e1de0ae4c57c0 Mon Sep 17 00:00:00 2001 From: Maryana Rozhankivska Date: Fri, 21 Mar 2014 21:56:40 +0200 Subject: fix of localhost cookie related to nginx binding to 0.0.0.0 --- inc/3rdparty/Session.class.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'inc/3rdparty') diff --git a/inc/3rdparty/Session.class.php b/inc/3rdparty/Session.class.php index 8c747558..59dfbe67 100644 --- a/inc/3rdparty/Session.class.php +++ b/inc/3rdparty/Session.class.php @@ -68,10 +68,10 @@ class Session } if ( $longlastingsession ) { - session_set_cookie_params(self::$longSessionTimeout, $cookiedir, $_SERVER['HTTP_HOST'], $ssl, true); + session_set_cookie_params(self::$longSessionTimeout, $cookiedir, null, $ssl, true); } else { - session_set_cookie_params(0, $cookiedir, $_SERVER['HTTP_HOST'], $ssl, true); + session_set_cookie_params(0, $cookiedir, null, $ssl, true); } //set server side valid session timeout //WARNING! this may not work in shared session environment. See http://www.php.net/manual/en/session.configuration.php#ini.session.gc-maxlifetime about min value: it can be set in any application -- cgit v1.2.3 From 182faf2696b38502d4784efc3f84f2f00290343f Mon Sep 17 00:00:00 2001 From: Maryana Rozhankivska Date: Wed, 2 Apr 2014 20:55:19 +0300 Subject: import without cron --- inc/3rdparty/libraries/feedwriter/FeedWriter.php | 168 +++++++++++------------ 1 file changed, 84 insertions(+), 84 deletions(-) mode change 100644 => 100755 inc/3rdparty/libraries/feedwriter/FeedWriter.php (limited to 'inc/3rdparty') diff --git a/inc/3rdparty/libraries/feedwriter/FeedWriter.php b/inc/3rdparty/libraries/feedwriter/FeedWriter.php old mode 100644 new mode 100755 index adb2526c..5d16e765 --- a/inc/3rdparty/libraries/feedwriter/FeedWriter.php +++ b/inc/3rdparty/libraries/feedwriter/FeedWriter.php @@ -9,9 +9,9 @@ define('JSONP', 3, true); * Genarate RSS2 or JSON (original: RSS 1.0, RSS2.0 and ATOM Feed) * * Modified for FiveFilters.org's Full-Text RSS project - * to allow for inclusion of hubs, JSON output. + * to allow for inclusion of hubs, JSON output. * Stripped RSS1 and ATOM support. - * + * * @package UnivarselFeedWriter * @author Anis uddin Ahmad * @link http://www.ajaxray.com/projects/rss @@ -26,32 +26,32 @@ define('JSONP', 3, true); private $CDATAEncoding = array(); // The tag names which have to encoded as CDATA private $xsl = null; // stylesheet to render RSS (used by Chrome) private $json = null; // JSON object - - private $version = null; - + + private $version = null; + /** * Constructor - * - * @param constant the version constant (RSS2 or JSON). - */ + * + * @param constant the version constant (RSS2 or JSON). + */ function __construct($version = RSS2) - { + { $this->version = $version; - + // Setting default value for assential channel elements $this->channels['title'] = $version . ' Feed'; $this->channels['link'] = 'http://www.ajaxray.com/blog'; - + //Tag names to encode in CDATA $this->CDATAEncoding = array('description', 'content:encoded', 'content', 'subtitle', 'summary'); } - + public function setFormat($format) { $this->version = $format; } // Start # public functions --------------------------------------------- - + /** * Set a channel element * @access public @@ -63,11 +63,11 @@ define('JSONP', 3, true); { $this->channels[$elementName] = $content ; } - + /** - * Set multiple channel elements from an array. Array elements + * Set multiple channel elements from an array. Array elements * should be 'channelName' => 'channelContent' format. - * + * * @access public * @param array array of channels * @return void @@ -75,30 +75,30 @@ define('JSONP', 3, true); public function setChannelElementsFromArray($elementArray) { if(! is_array($elementArray)) return; - foreach ($elementArray as $elementName => $content) + foreach ($elementArray as $elementName => $content) { $this->setChannelElement($elementName, $content); } } - + /** * Genarate the actual RSS/JSON file - * + * * @access public * @return void - */ + */ public function genarateFeed() { if ($this->version == RSS2) { - header('Content-type: text/xml; charset=UTF-8'); +// header('Content-type: text/xml; charset=UTF-8'); // this line prevents Chrome 20 from prompting download // used by Google: https://news.google.com/news/feeds?ned=us&topic=b&output=rss - header('X-content-type-options: nosniff'); +// header('X-content-type-options: nosniff'); } elseif ($this->version == JSON) { - header('Content-type: application/json; charset=UTF-8'); +// header('Content-type: application/json; charset=UTF-8'); $this->json = new stdClass(); } elseif ($this->version == JSONP) { - header('Content-type: application/javascript; charset=UTF-8'); +// header('Content-type: application/javascript; charset=UTF-8'); $this->json = new stdClass(); } $this->printHead(); @@ -109,10 +109,10 @@ define('JSONP', 3, true); echo json_encode($this->json); } } - + /** * Create a new FeedItem. - * + * * @access public * @return object instance of FeedItem class */ @@ -121,24 +121,24 @@ define('JSONP', 3, true); $Item = new FeedItem($this->version); return $Item; } - + /** * Add a FeedItem to the main class - * + * * @access public * @param object instance of FeedItem class * @return void */ public function addItem($feedItem) { - $this->items[] = $feedItem; + $this->items[] = $feedItem; } - + // Wrapper functions ------------------------------------------------------------------- - + /** * Set the 'title' channel element - * + * * @access public * @param srting value of 'title' channel tag * @return void @@ -147,59 +147,59 @@ define('JSONP', 3, true); { $this->setChannelElement('title', $title); } - + /** * Add a hub to the channel element - * + * * @access public * @param string URL * @return void */ public function addHub($hub) { - $this->hubs[] = $hub; + $this->hubs[] = $hub; } - + /** * Set XSL URL - * + * * @access public * @param string URL * @return void */ public function setXsl($xsl) { - $this->xsl = $xsl; - } - + $this->xsl = $xsl; + } + /** * Set self URL - * + * * @access public * @param string URL * @return void */ public function setSelf($self) { - $this->self = $self; - } - + $this->self = $self; + } + /** * Set the 'description' channel element - * + * * @access public * @param srting value of 'description' channel tag * @return void */ public function setDescription($desciption) { - $tag = ($this->version == ATOM)? 'subtitle' : 'description'; + $tag = ($this->version == ATOM)? 'subtitle' : 'description'; $this->setChannelElement($tag, $desciption); } - + /** * Set the 'link' channel element - * + * * @access public * @param srting value of 'link' channel tag * @return void @@ -208,10 +208,10 @@ define('JSONP', 3, true); { $this->setChannelElement('link', $link); } - + /** * Set the 'image' channel element - * + * * @access public * @param srting title of image * @param srting link url of the imahe @@ -222,14 +222,14 @@ define('JSONP', 3, true); { $this->setChannelElement('image', array('title'=>$title, 'link'=>$link, 'url'=>$url)); } - + // End # public functions ---------------------------------------------- - + // Start # private functions ---------------------------------------------- - + /** * Prints the xml and rss namespace - * + * * @access private * @return void */ @@ -247,10 +247,10 @@ define('JSONP', 3, true); $this->json->rss = array('@attributes' => array('version' => '2.0')); } } - + /** * Closes the open tags at the end of file - * + * * @access private * @return void */ @@ -258,14 +258,14 @@ define('JSONP', 3, true); { if ($this->version == RSS2) { - echo '',PHP_EOL,''; - } + echo '',PHP_EOL,''; + } // do nothing for JSON } /** * Creates a single node as xml format - * + * * @access private * @param string name of the tag * @param mixed tag value as string or array of nested tags in 'tagName' => 'tagValue' format @@ -273,22 +273,22 @@ define('JSONP', 3, true); * @return string formatted xml tag */ private function makeNode($tagName, $tagContent, $attributes = null) - { + { if ($this->version == RSS2) { $nodeText = ''; $attrText = ''; if (is_array($attributes)) { - foreach ($attributes as $key => $value) + foreach ($attributes as $key => $value) { $attrText .= " $key=\"$value\" "; } } $nodeText .= "<{$tagName}{$attrText}>"; if (is_array($tagContent)) - { - foreach ($tagContent as $key => $value) + { + foreach ($tagContent as $key => $value) { $nodeText .= $this->makeNode($key, $value); } @@ -297,7 +297,7 @@ define('JSONP', 3, true); { //$nodeText .= (in_array($tagName, $this->CDATAEncoding))? $tagContent : htmlentities($tagContent); $nodeText .= htmlspecialchars($tagContent); - } + } //$nodeText .= (in_array($tagName, $this->CDATAEncoding))? "]]>" : ""; $nodeText .= ""; return $nodeText . PHP_EOL; @@ -321,7 +321,7 @@ define('JSONP', 3, true); } return ''; // should not get here } - + private function json_keys(array $array) { $new = array(); foreach ($array as $key => $val) { @@ -334,7 +334,7 @@ define('JSONP', 3, true); } return $new; } - + /** * @desc Print channels * @access private @@ -344,7 +344,7 @@ define('JSONP', 3, true); { //Start channel tag if ($this->version == RSS2) { - echo '' . PHP_EOL; + echo '' . PHP_EOL; // add hubs foreach ($this->hubs as $hub) { //echo $this->makeNode('link', '', array('rel'=>'hub', 'href'=>$hub, 'xmlns'=>'http://www.w3.org/2005/Atom')); @@ -356,7 +356,7 @@ define('JSONP', 3, true); echo '' . PHP_EOL; } //Print Items of channel - foreach ($this->channels as $key => $value) + foreach ($this->channels as $key => $value) { echo $this->makeNode($key, $value); } @@ -364,26 +364,26 @@ define('JSONP', 3, true); $this->json->rss['channel'] = (object)$this->json_keys($this->channels); } } - + /** * Prints formatted feed items - * + * * @access private * @return void */ private function printItems() - { + { foreach ($this->items as $item) { $itemElements = $item->getElements(); - + echo $this->startItem(); - + if ($this->version == JSON || $this->version == JSONP) { $json_item = array(); } - + foreach ($itemElements as $thisElement) { - foreach ($thisElement as $instance) { + foreach ($thisElement as $instance) { if ($this->version == RSS2) { echo $this->makeNode($instance['name'], $instance['content'], $instance['attributes']); } elseif ($this->version == JSON || $this->version == JSONP) { @@ -406,10 +406,10 @@ define('JSONP', 3, true); } } } - + /** * Make the starting tag of channels - * + * * @access private * @return void */ @@ -417,14 +417,14 @@ define('JSONP', 3, true); { if ($this->version == RSS2) { - echo '' . PHP_EOL; - } + echo '' . PHP_EOL; + } // nothing for JSON } - + /** * Closes feed item tag - * + * * @access private * @return void */ @@ -432,10 +432,10 @@ define('JSONP', 3, true); { if ($this->version == RSS2) { - echo '' . PHP_EOL; - } + echo '' . PHP_EOL; + } // nothing for JSON } - + // End # private functions ---------------------------------------------- } \ No newline at end of file -- cgit v1.2.3