From 746f93c290881d97997b8179395de2875eb57c71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Tue, 20 Aug 2013 11:23:32 +0200 Subject: fix bug #148 Use of undefined constant POCHE_VERSION --- inc/poche/config.inc.php | 6 +++--- inc/poche/define.inc.php | 2 ++ 2 files changed, 5 insertions(+), 3 deletions(-) (limited to 'inc/poche') diff --git a/inc/poche/config.inc.php b/inc/poche/config.inc.php index 4122ff10..cb882cd0 100755 --- a/inc/poche/config.inc.php +++ b/inc/poche/config.inc.php @@ -15,9 +15,9 @@ if (!file_exists(__DIR__ . '/../../vendor/autoload.php')) { die('Twig does not seem installed. Have a look at the documentation.'); } -if (file_exists(__DIR__ . '/../../inc/poche/myconfig.inc.php')) { - require_once __DIR__ . '/../../inc/poche/myconfig.inc.php'; -} +// if (file_exists(__DIR__ . '/../../inc/poche/myconfig.inc.php')) { + // require_once __DIR__ . '/../../inc/poche/myconfig.inc.php'; +// } require_once __DIR__ . '/../../inc/poche/User.class.php'; require_once __DIR__ . '/../../inc/poche/Url.class.php'; require_once __DIR__ . '/../../inc/3rdparty/class.messages.php'; diff --git a/inc/poche/define.inc.php b/inc/poche/define.inc.php index c32ca098..80d1f29d 100644 --- a/inc/poche/define.inc.php +++ b/inc/poche/define.inc.php @@ -22,6 +22,8 @@ define ('REVERT_FORCED_PARAGRAPH_ELEMENTS', FALSE); define ('DOWNLOAD_PICTURES', FALSE); define ('SHARE_TWITTER', TRUE); define ('SHARE_MAIL', TRUE); +define ('SHARE_SHAARLI', TRUE); +define ('SHAARLI_URL', 'http://myshaarliurl.com'); define ('ABS_PATH', 'assets/'); define ('TPL', __DIR__ . '/../../tpl'); define ('LOCALE', __DIR__ . '/../../locale'); -- cgit v1.2.3 From 2bf93dc0345e304656ed9a931f9941fd7117ddfe Mon Sep 17 00:00:00 2001 From: Nicolas Frandeboeuf Date: Thu, 22 Aug 2013 00:49:23 +0200 Subject: Fix #149 --- inc/poche/Url.class.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'inc/poche') diff --git a/inc/poche/Url.class.php b/inc/poche/Url.class.php index 00b0b257..77ed5398 100644 --- a/inc/poche/Url.class.php +++ b/inc/poche/Url.class.php @@ -64,8 +64,15 @@ class Url if (function_exists('tidy_parse_string')) { $tidy = tidy_parse_string($html, array(), 'UTF8'); $tidy->cleanRepair(); - $html = $tidy->value; - } + + //Warning: tidy might fail so, ensure there is still a content + $body = $tidy->body(); + + //hasChildren does not seem to work, just check the string + //returned (and do not forget to clean the white spaces) + if (preg_replace('/\s+/', '', $body->value) !== "") + $html = $tidy->value; + } $parameters = array(); if (isset($html) and strlen($html) > 0) -- cgit v1.2.3 From 8340fedd6403e5ef68df443476a548ff0d241b67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Fri, 23 Aug 2013 18:29:36 +0200 Subject: fix bug #150 Add support of text files by setting a default title --- inc/poche/Url.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'inc/poche') diff --git a/inc/poche/Url.class.php b/inc/poche/Url.class.php index 77ed5398..36fdd0f5 100644 --- a/inc/poche/Url.class.php +++ b/inc/poche/Url.class.php @@ -84,7 +84,7 @@ class Url if($readability->init()) { $content = $readability->articleContent->innerHTML; - $parameters['title'] = $readability->articleTitle->innerHTML; + $parameters['title'] = ($readability->articleTitle->innerHTML != '' ? $readability->articleTitle->innerHTML : _('Untitled')); $parameters['content'] = $content; return $parameters; -- cgit v1.2.3 From 1e0f9166cc9a9d99d48ac1d9b3159adb8a1f8c9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Fri, 23 Aug 2013 19:49:17 +0200 Subject: set shaarli to false --- inc/poche/define.inc.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'inc/poche') diff --git a/inc/poche/define.inc.php b/inc/poche/define.inc.php index 80d1f29d..2154ce88 100644 --- a/inc/poche/define.inc.php +++ b/inc/poche/define.inc.php @@ -22,7 +22,7 @@ define ('REVERT_FORCED_PARAGRAPH_ELEMENTS', FALSE); define ('DOWNLOAD_PICTURES', FALSE); define ('SHARE_TWITTER', TRUE); define ('SHARE_MAIL', TRUE); -define ('SHARE_SHAARLI', TRUE); +define ('SHARE_SHAARLI', FALSE); define ('SHAARLI_URL', 'http://myshaarliurl.com'); define ('ABS_PATH', 'assets/'); define ('TPL', __DIR__ . '/../../tpl'); -- cgit v1.2.3 From 70c39d16185698c0cc937cc4104694cd97e36d33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Fri, 23 Aug 2013 21:07:32 +0200 Subject: tabs2spaces --- inc/poche/Url.class.php | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'inc/poche') diff --git a/inc/poche/Url.class.php b/inc/poche/Url.class.php index 36fdd0f5..3c74fb43 100644 --- a/inc/poche/Url.class.php +++ b/inc/poche/Url.class.php @@ -65,13 +65,14 @@ class Url $tidy = tidy_parse_string($html, array(), 'UTF8'); $tidy->cleanRepair(); - //Warning: tidy might fail so, ensure there is still a content - $body = $tidy->body(); + //Warning: tidy might fail so, ensure there is still a content + $body = $tidy->body(); - //hasChildren does not seem to work, just check the string - //returned (and do not forget to clean the white spaces) - if (preg_replace('/\s+/', '', $body->value) !== "") - $html = $tidy->value; + //hasChildren does not seem to work, just check the string + //returned (and do not forget to clean the white spaces) + if (preg_replace('/\s+/', '', $body->value) !== "") { + $html = $tidy->value; + } } $parameters = array(); -- cgit v1.2.3 From b64a882696ba6c403c36f9434230fc636741b7d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Fri, 23 Aug 2013 21:30:55 +0200 Subject: notice with poche_version undefined' --- inc/poche/Tools.class.php | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-) (limited to 'inc/poche') diff --git a/inc/poche/Tools.class.php b/inc/poche/Tools.class.php index 1baf745d..52d0f2d5 100644 --- a/inc/poche/Tools.class.php +++ b/inc/poche/Tools.class.php @@ -238,25 +238,20 @@ class Tools public static function createMyConfig() { $myconfig_file = './inc/poche/myconfig.inc.php'; + + if (!is_writable('./inc/poche/')) { + self::logm('you don\'t have write access to create ./inc/poche/myconfig.inc.php'); + die('You don\'t have write access to create ./inc/poche/myconfig.inc.php.'); + } - if (version_compare(POCHE_VERSION, '1.0-beta3') == 1) { - # $myconfig_file is only created with poche > 1.0-beta3 - # in 1.0-beta3, the update script creates $myconfig_file - - if (!is_writable('./inc/poche/')) { - self::logm('you don\'t have write access to create ./inc/poche/myconfig.inc.php'); - die('You don\'t have write access to create ./inc/poche/myconfig.inc.php.'); - } - - if (!file_exists($myconfig_file)) - { - $fp = fopen($myconfig_file, 'w'); - fwrite($fp, ' Date: Fri, 23 Aug 2013 22:24:41 +0200 Subject: new messages when update / install --- inc/poche/Poche.class.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'inc/poche') diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index e0dc0d20..4832f816 100644 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php @@ -47,16 +47,16 @@ class Poche die('You don\'t have write access on cache directory.'); } else if (file_exists('./install/update.php') && !DEBUG_POCHE) { - $msg = 'A poche update is needed. Please execute this update by clicking here. If you have already do the update, please delete /install folder.'; + $msg = '

setup

It\'s your first time here? Please copy /install/poche.sqlite in db folder. Then, delete install folder.
If you have already installed poche, an update is needed by clicking here.

'; $allIsGood = FALSE; } else if (file_exists('./install') && !DEBUG_POCHE) { - $msg = 'If you want to update your poche, you just have to delete /install folder.
To install your poche with sqlite, copy /install/poche.sqlite in /db and delete the folder /install. you have to delete the /install folder before using poche.'; + $msg = '

setup

If you want to update your poche, you just have to delete /install folder.
To install your poche with sqlite, copy /install/poche.sqlite in /db and delete the folder /install. you have to delete the /install folder before using poche.

'; $allIsGood = FALSE; } else if (STORAGE == 'sqlite' && !is_writable(STORAGE_SQLITE)) { Tools::logm('you don\'t have write access on sqlite file'); - $msg = 'You don\'t have write access on sqlite file.'; + $msg = '

error

You don\'t have write access on sqlite file.

'; $allIsGood = FALSE; } -- cgit v1.2.3 From 679b6b85ad1f8c9110334101a1568510ad15891b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Fri, 23 Aug 2013 22:43:16 +0200 Subject: preparing to beta4 --- inc/poche/Tools.class.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'inc/poche') diff --git a/inc/poche/Tools.class.php b/inc/poche/Tools.class.php index 52d0f2d5..8661ab6e 100644 --- a/inc/poche/Tools.class.php +++ b/inc/poche/Tools.class.php @@ -238,7 +238,7 @@ class Tools public static function createMyConfig() { $myconfig_file = './inc/poche/myconfig.inc.php'; - + if (!is_writable('./inc/poche/')) { self::logm('you don\'t have write access to create ./inc/poche/myconfig.inc.php'); die('You don\'t have write access to create ./inc/poche/myconfig.inc.php.'); @@ -248,7 +248,7 @@ class Tools { $fp = fopen($myconfig_file, 'w'); fwrite($fp, ' Date: Sat, 24 Aug 2013 11:10:07 +0200 Subject: Add IPv4 url support (and others beginning by a digit) --- inc/poche/Url.class.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'inc/poche') diff --git a/inc/poche/Url.class.php b/inc/poche/Url.class.php index 3c74fb43..b73f3a46 100644 --- a/inc/poche/Url.class.php +++ b/inc/poche/Url.class.php @@ -27,7 +27,7 @@ class Url public function isCorrect() { - $pattern = '|^(.*:)//([a-z\-.]+)(:[0-9]+)?(.*)$|i'; + $pattern = '|^(.*:)//([a-z\-.\d]+)(:[0-9]+)?(.*)$|i'; return preg_match($pattern, $this->url); } @@ -73,7 +73,7 @@ class Url if (preg_replace('/\s+/', '', $body->value) !== "") { $html = $tidy->value; } - } + } $parameters = array(); if (isset($html) and strlen($html) > 0) -- cgit v1.2.3 From 66b6a3b5e2410827ac23bea0439f2fad03240018 Mon Sep 17 00:00:00 2001 From: EliasZ Date: Sat, 24 Aug 2013 15:59:51 +0200 Subject: graceful error-handling with imports, define where import files are stored --- inc/poche/Poche.class.php | 43 +++++++++++++++++++++++++++++++------------ inc/poche/define.inc.php | 6 +++++- 2 files changed, 36 insertions(+), 13 deletions(-) (limited to 'inc/poche') diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index 4832f816..cb338766 100644 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php @@ -364,13 +364,14 @@ class Poche /** * import from Instapaper. poche needs a ./instapaper-export.html file * @todo add the return value + * @param string $targetFile the file used for importing * @return boolean */ - private function importFromInstapaper() + private function importFromInstapaper($targetFile) { # TODO gestion des articles favs $html = new simple_html_dom(); - $html->load_file('./instapaper-export.html'); + $html->load_file($targetFile); Tools::logm('starting import from instapaper'); $read = 0; @@ -403,13 +404,14 @@ class Poche /** * import from Pocket. poche needs a ./ril_export.html file * @todo add the return value + * @param string $targetFile the file used for importing * @return boolean */ - private function importFromPocket() + private function importFromPocket($targetFile) { # TODO gestion des articles favs $html = new simple_html_dom(); - $html->load_file('./ril_export.html'); + $html->load_file($targetFile); Tools::logm('starting import from pocket'); $read = 0; @@ -442,12 +444,13 @@ class Poche /** * import from Readability. poche needs a ./readability file * @todo add the return value + * @param string $targetFile the file used for importing * @return boolean */ - private function importFromReadability() + private function importFromReadability($targetFile) { # TODO gestion des articles lus / favs - $str_data = file_get_contents("./readability"); + $str_data = file_get_contents($targetFile); $data = json_decode($str_data,true); Tools::logm('starting import from Readability'); $count = 0; @@ -499,15 +502,31 @@ class Poche */ public function import($from) { - if ($from == 'pocket') { - return $this->importFromPocket(); + $providers = array( + 'pocket' => 'importFromPocket', + 'readability' => 'importFromReadability', + 'instapaper' => 'importFromInstapaper' + ); + + if (! isset($providers[$from])) { + $this->messages->add('e', _('Unknown import provider.')); + Tools::redirect(); } - else if ($from == 'readability') { - return $this->importFromReadability(); + + $targetDefinition = 'IMPORT_' . strtoupper($from) . '_FILE'; + $targetFile = constant($targetDefinition); + + if (! defined($targetDefinition)) { + $this->messages->add('e', _('Incomplete inc/poche/define.inc.php file, please define "' . $targetDefinition . '".')); + Tools::redirect(); } - else if ($from == 'instapaper') { - return $this->importFromInstapaper(); + + if (! file_exists($targetFile)) { + $this->messages->add('e', _('Could not find required "' . $targetFile . '" import file.')); + Tools::redirect(); } + + $this->$providers[$from]($targetFile); } /** diff --git a/inc/poche/define.inc.php b/inc/poche/define.inc.php index 2154ce88..2d0a39ec 100644 --- a/inc/poche/define.inc.php +++ b/inc/poche/define.inc.php @@ -29,4 +29,8 @@ define ('TPL', __DIR__ . '/../../tpl'); define ('LOCALE', __DIR__ . '/../../locale'); define ('CACHE', __DIR__ . '/../../cache'); define ('PAGINATION', '10'); -define ('THEME', 'light'); \ No newline at end of file +define ('THEME', 'light'); + +define ('IMPORT_POCKET_FILE', './ril_export.html'); +define ('IMPORT_READABILITY_FILE', './readability'); +define ('IMPORT_INSTAPAPER_FILE', './instapaper-export.html'); \ No newline at end of file -- cgit v1.2.3 From 38b95e7be9ce68a86c50486462bee485419a67a8 Mon Sep 17 00:00:00 2001 From: nicofrand Date: Sat, 24 Aug 2013 16:31:22 +0200 Subject: Add IPv4 url support (and others beginning by a digit) --- inc/poche/Url.class.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'inc/poche') diff --git a/inc/poche/Url.class.php b/inc/poche/Url.class.php index b73f3a46..302700a9 100644 --- a/inc/poche/Url.class.php +++ b/inc/poche/Url.class.php @@ -27,9 +27,7 @@ class Url public function isCorrect() { - $pattern = '|^(.*:)//([a-z\-.\d]+)(:[0-9]+)?(.*)$|i'; - - return preg_match($pattern, $this->url); + return filter_var($this->url, FILTER_VALIDATE_URL); } public function clean() -- cgit v1.2.3 From 149df445d6a13317bf0777e042230ff3386243a8 Mon Sep 17 00:00:00 2001 From: nicofrand Date: Sat, 24 Aug 2013 16:50:28 +0200 Subject: Add IPv4 url support (and others beginning by a digit) --- inc/poche/Url.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'inc/poche') diff --git a/inc/poche/Url.class.php b/inc/poche/Url.class.php index 302700a9..d7ee911f 100644 --- a/inc/poche/Url.class.php +++ b/inc/poche/Url.class.php @@ -27,7 +27,7 @@ class Url public function isCorrect() { - return filter_var($this->url, FILTER_VALIDATE_URL); + return filter_var($this->url, FILTER_VALIDATE_URL) !== FALSE; } public function clean() -- cgit v1.2.3 From d7c2f0cc47d829b1f242a10f03d15d80d28f3c0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Sun, 25 Aug 2013 08:01:18 +0200 Subject: fix bug #175 IP addresses do not appear in view original --- inc/poche/Tools.class.php | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) (limited to 'inc/poche') diff --git a/inc/poche/Tools.class.php b/inc/poche/Tools.class.php index 8661ab6e..3a792d43 100644 --- a/inc/poche/Tools.class.php +++ b/inc/poche/Tools.class.php @@ -216,13 +216,7 @@ class Tools public static function getDomain($url) { - $pieces = parse_url($url); - $domain = isset($pieces['host']) ? $pieces['host'] : ''; - if (preg_match('/(?P[a-z0-9][a-z0-9\-]{1,63}\.[a-z\.]{2,6})$/i', $domain, $regs)) { - return $regs['domain']; - } - - return FALSE; + return parse_url($url, PHP_URL_HOST); } public static function getReadingTime($text) { -- cgit v1.2.3 From ec3972361d95f6f5956df77f7a76105b5ae6af72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Sun, 25 Aug 2013 20:10:23 +0200 Subject: poche now uses Full Text RSS to fetch content --- inc/poche/Poche.class.php | 42 +++-- inc/poche/Url.class.php | 399 ++++++++++++++++++++++++++++++++++++++++------ inc/poche/config.inc.php | 15 ++ inc/poche/define.inc.php | 2 - 4 files changed, 380 insertions(+), 78 deletions(-) (limited to 'inc/poche') diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index cb338766..646193f7 100644 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php @@ -156,36 +156,31 @@ class Poche switch ($action) { case 'add': - if($parametres_url = $url->fetchContent()) { - if ($this->store->add($url->getUrl(), $parametres_url['title'], $parametres_url['content'], $this->user->getId())) { - Tools::logm('add link ' . $url->getUrl()); - $sequence = ''; - if (STORAGE == 'postgres') { - $sequence = 'entries_id_seq'; - } - $last_id = $this->store->getLastId($sequence); - if (DOWNLOAD_PICTURES) { - $content = filtre_picture($parametres_url['content'], $url->getUrl(), $last_id); - Tools::logm('updating content article'); - $this->store->updateContent($last_id, $content, $this->user->getId()); - } - if (!$import) { - $this->messages->add('s', _('the link has been added successfully')); - } + $content = $url->extract(); + + if ($this->store->add($url->getUrl(), $content['title'], $content['body'], $this->user->getId())) { + Tools::logm('add link ' . $url->getUrl()); + $sequence = ''; + if (STORAGE == 'postgres') { + $sequence = 'entries_id_seq'; } - else { - if (!$import) { - $this->messages->add('e', _('error during insertion : the link wasn\'t added')); - Tools::logm('error during insertion : the link wasn\'t added ' . $url->getUrl()); - } + $last_id = $this->store->getLastId($sequence); + if (DOWNLOAD_PICTURES) { + $content = filtre_picture($parametres_url['body'], $url->getUrl(), $last_id); + Tools::logm('updating content article'); + $this->store->updateContent($last_id, $content, $this->user->getId()); + } + if (!$import) { + $this->messages->add('s', _('the link has been added successfully')); } } else { if (!$import) { - $this->messages->add('e', _('error during fetching content : the link wasn\'t added')); - Tools::logm('error during content fetch ' . $url->getUrl()); + $this->messages->add('e', _('error during insertion : the link wasn\'t added')); + Tools::logm('error during insertion : the link wasn\'t added ' . $url->getUrl()); } } + if (!$import) { Tools::redirect(); } @@ -220,7 +215,6 @@ class Poche } break; default: - Tools::logm('action ' . $action . 'doesn\'t exist'); break; } } diff --git a/inc/poche/Url.class.php b/inc/poche/Url.class.php index d7ee911f..5a893014 100644 --- a/inc/poche/Url.class.php +++ b/inc/poche/Url.class.php @@ -12,6 +12,45 @@ class Url { public $url; + private $fingerprints = array( + // Posterous + ' array('hostname'=>'fingerprint.posterous.com', 'head'=>true), + // Blogger + ' array('hostname'=>'fingerprint.blogspot.com', 'head'=>true), + ' array('hostname'=>'fingerprint.blogspot.com', 'head'=>true), + // WordPress (self-hosted and hosted) + '\"$_name\""; + } else { + $html = "Download $_name"; + } + $title = $_name; + $do_content_extraction = false; + break; + } + } + } + unset($_mime, $_act, $_name, $match); + } + if ($do_content_extraction) { + $html = $response['body']; + // remove strange things + $html = str_replace('', '', $html); + $html = $this->convert_to_utf8($html, $response['headers']); - //hasChildren does not seem to work, just check the string - //returned (and do not forget to clean the white spaces) - if (preg_replace('/\s+/', '', $body->value) !== "") { - $html = $tidy->value; + // check site config for single page URL - fetch it if found + if ($single_page_response = $this->getSinglePage($item, $html, $effective_url)) { + $html = $single_page_response['body']; + // remove strange things + $html = str_replace('', '', $html); + $html = $this->convert_to_utf8($html, $single_page_response['headers']); + $effective_url = $single_page_response['effective_url']; + unset($single_page_response); + } + $extract_result = $extractor->process($html, $effective_url); + $readability = $extractor->readability; + $content_block = ($extract_result) ? $extractor->getContent() : null; + } + } + if ($do_content_extraction) { + // if we failed to extract content... + if (!$extract_result) { + $html = $this->error_message; + // keep the original item description + $html .= $item->get_description(); + } else { + $readability->clean($content_block, 'select'); + if ($this->rewrite_relative_urls) $this->makeAbsolute($effective_url, $content_block); + if ($content_block->childNodes->length == 1 && $content_block->firstChild->nodeType === XML_ELEMENT_NODE) { + $html = $content_block->firstChild->innerHTML; + } else { + $html = $content_block->innerHTML; + } + // post-processing cleanup + $html = preg_replace('!

[\s\h\v]*

!u', '', $html); } } + } + + $title = ($extractor->getTitle() != '' ? $extractor->getTitle() : _('Untitled')); + $content = array ('title' => $title, 'body' => $html); - $parameters = array(); - if (isset($html) and strlen($html) > 0) - { - $readability = new Readability($html, $this->getUrl()); - $readability->convertLinksToFootnotes = CONVERT_LINKS_FOOTNOTES; - $readability->revertForcedParagraphElements = REVERT_FORCED_PARAGRAPH_ELEMENTS; + return $content; + } + + private 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 + } 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 35000 characters + $html_head = substr($html, 0, 40000); + 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) { + $encoding = 'utf-8'; + } else { + if (strtolower($encoding) != '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; + } - if($readability->init()) - { - $content = $readability->articleContent->innerHTML; - $parameters['title'] = ($readability->articleTitle->innerHTML != '' ? $readability->articleTitle->innerHTML : _('Untitled')); - $parameters['content'] = $content; + private 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); + $this->makeAbsoluteAttr($base, $e, $attr); + } + if (strtolower($elem->tagName) == $tag) $this->makeAbsoluteAttr($base, $elem, $attr); + } + } - return $parameters; + private 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); } } } - else { - #$msg->add('e', _('error during url preparation : the link is not valid')); - Tools::logm($this->getUrl() . ' is not a valid url'); + } + + private 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; } + } - return FALSE; + // returns single page response, or false if not found + private function getSinglePage($item, $html, $url) { + global $http, $extractor; + $host = @parse_url($url, PHP_URL_HOST); + $site_config = SiteConfig::build($host); + if ($site_config === false) { + // check for fingerprints + if (!empty($extractor->fingerprints) && ($_fphost = $extractor->findHostUsingFingerprints($html))) { + $site_config = SiteConfig::build($_fphost); + } + if ($site_config === false) $site_config = new SiteConfig(); + SiteConfig::add_to_cache($host, $site_config); + return false; + } else { + SiteConfig::add_to_cache($host, $site_config); + } + $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; + } elseif ($item instanceof DOMAttr && $item->value) { + $single_page_url = $item->value; + break; + } + } + } + } + // If we've got URL, resolve against $url + if (isset($single_page_url) && ($single_page_url = $this->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; } } \ No newline at end of file diff --git a/inc/poche/config.inc.php b/inc/poche/config.inc.php index cb882cd0..a1917295 100755 --- a/inc/poche/config.inc.php +++ b/inc/poche/config.inc.php @@ -30,10 +30,25 @@ require_once __DIR__ . '/../../inc/3rdparty/simple_html_dom.php'; require_once __DIR__ . '/../../inc/3rdparty/paginator.php'; require_once __DIR__ . '/../../inc/3rdparty/Session.class.php'; +require_once __DIR__ . '/../../inc/3rdparty/simplepie/SimplePieAutoloader.php'; +require_once __DIR__ . '/../../inc/3rdparty/simplepie/SimplePie/Core.php'; +require_once __DIR__ . '/../../inc/3rdparty/content-extractor/ContentExtractor.php'; +require_once __DIR__ . '/../../inc/3rdparty/content-extractor/SiteConfig.php'; +require_once __DIR__ . '/../../inc/3rdparty/humble-http-agent/HumbleHttpAgent.php'; +require_once __DIR__ . '/../../inc/3rdparty/humble-http-agent/SimplePie_HumbleHttpAgent.php'; +require_once __DIR__ . '/../../inc/3rdparty/humble-http-agent/CookieJar.php'; +require_once __DIR__ . '/../../inc/3rdparty/feedwriter/FeedItem.php'; +require_once __DIR__ . '/../../inc/3rdparty/feedwriter/FeedWriter.php'; +require_once __DIR__ . '/../../inc/3rdparty/feedwriter/DummySingleItemFeed.php'; + if (DOWNLOAD_PICTURES) { require_once __DIR__ . '/../../inc/poche/pochePictures.php'; } +if (!ini_get('date.timezone') || !@date_default_timezone_set(ini_get('date.timezone'))) { + date_default_timezone_set('UTC'); +} + $poche = new Poche(); #XSRF protection with token // if (!empty($_POST)) { diff --git a/inc/poche/define.inc.php b/inc/poche/define.inc.php index 2d0a39ec..3f667430 100644 --- a/inc/poche/define.inc.php +++ b/inc/poche/define.inc.php @@ -17,8 +17,6 @@ define ('STORAGE_PASSWORD', 'postgres'); # leave blank for sqlite define ('MODE_DEMO', FALSE); define ('DEBUG_POCHE', FALSE); -define ('CONVERT_LINKS_FOOTNOTES', FALSE); -define ('REVERT_FORCED_PARAGRAPH_ELEMENTS', FALSE); define ('DOWNLOAD_PICTURES', FALSE); define ('SHARE_TWITTER', TRUE); define ('SHARE_MAIL', TRUE); -- cgit v1.2.3