From 6fb46003340dc96c3a9fa876949c39eb25f14773 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Mon, 26 Aug 2013 17:38:01 +0200 Subject: fix bug #186: content was empty when enabling downloading pictures --- inc/poche/Poche.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'inc') diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index 646193f7..bca8bfd5 100644 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php @@ -166,7 +166,7 @@ class Poche } $last_id = $this->store->getLastId($sequence); if (DOWNLOAD_PICTURES) { - $content = filtre_picture($parametres_url['body'], $url->getUrl(), $last_id); + $content = filtre_picture($content['body'], $url->getUrl(), $last_id); Tools::logm('updating content article'); $this->store->updateContent($last_id, $content, $this->user->getId()); } -- cgit v1.2.3 From 5ebf6eeca1a1096efa3027fa082ec6b60a7ac1e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Tue, 27 Aug 2013 11:05:57 +0200 Subject: add configuration to parse bfmtv.com --- inc/3rdparty/site_config/custom/bfmtv.com.txt | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 inc/3rdparty/site_config/custom/bfmtv.com.txt (limited to 'inc') diff --git a/inc/3rdparty/site_config/custom/bfmtv.com.txt b/inc/3rdparty/site_config/custom/bfmtv.com.txt new file mode 100644 index 00000000..0ff28d56 --- /dev/null +++ b/inc/3rdparty/site_config/custom/bfmtv.com.txt @@ -0,0 +1,6 @@ +title: //title +body: //h2 | //span[@class='masque'] | //article[@class='corps_article_right'] +prune: no +tidy: no + +test_url: http://www.bfmtv.com/societe/cigarette-electronique-dangers-588622.html \ No newline at end of file -- cgit v1.2.3 From 7d1778bbd20030dd37b47a87bfa10bff61f6457e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Tue, 27 Aug 2013 12:52:35 +0200 Subject: config file for tldp.org --- inc/3rdparty/site_config/custom/tldp.org.txt | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 inc/3rdparty/site_config/custom/tldp.org.txt (limited to 'inc') diff --git a/inc/3rdparty/site_config/custom/tldp.org.txt b/inc/3rdparty/site_config/custom/tldp.org.txt new file mode 100644 index 00000000..7dd5cdb5 --- /dev/null +++ b/inc/3rdparty/site_config/custom/tldp.org.txt @@ -0,0 +1,6 @@ +title: //title +body: //h2 | //p | //ul +prune: no +tidy: no + +test_url: http://www.tldp.org/HOWTO/Plug-and-Play-HOWTO-7.html \ No newline at end of file -- cgit v1.2.3 From 093f1efb213ce43e76ad7416eef347c80d8b0e17 Mon Sep 17 00:00:00 2001 From: NumEricR Date: Tue, 27 Aug 2013 02:14:15 +0200 Subject: Update comment --- inc/poche/Poche.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'inc') diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index bca8bfd5..57e8b7b3 100644 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php @@ -257,7 +257,7 @@ class Poche Tools::logm('error in view call : entry is null'); } break; - default: # home view + default: # home, favorites and archive views $entries = $this->store->getEntriesByView($view, $this->user->getId()); $this->pagination->set_total(count($entries)); $page_links = $this->pagination->page_links('?view=' . $view . '&sort=' . $_SESSION['sort'] . '&'); -- cgit v1.2.3 From 3eb049036e601c1978cf5f7f0d5be8c577933b72 Mon Sep 17 00:00:00 2001 From: NumEricR Date: Tue, 27 Aug 2013 16:02:25 +0200 Subject: Add warning message when there is no entry in current view --- inc/poche/Poche.class.php | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'inc') diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index 57e8b7b3..a8f64151 100644 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php @@ -259,13 +259,17 @@ class Poche break; default: # home, favorites and archive views $entries = $this->store->getEntriesByView($view, $this->user->getId()); - $this->pagination->set_total(count($entries)); - $page_links = $this->pagination->page_links('?view=' . $view . '&sort=' . $_SESSION['sort'] . '&'); - $datas = $this->store->getEntriesByView($view, $this->user->getId(), $this->pagination->get_limit()); $tpl_vars = array( - 'entries' => $datas, - 'page_links' => $page_links, + 'entries' => '', + 'page_links' => '', ); + if (count($entries) > 0) { + $this->pagination->set_total(count($entries)); + $page_links = $this->pagination->page_links('?view=' . $view . '&sort=' . $_SESSION['sort'] . '&'); + $datas = $this->store->getEntriesByView($view, $this->user->getId(), $this->pagination->get_limit()); + $tpl_vars['entries'] = $datas; + $tpl_vars['page_links'] = $page_links; + } Tools::logm('display ' . $view . ' view'); break; } -- cgit v1.2.3 From 7f9f5281e5fe6dd92c810f7945c7761ca17fd2e6 Mon Sep 17 00:00:00 2001 From: NumEricR Date: Wed, 28 Aug 2013 19:12:11 +0200 Subject: Add number of results next to pager --- inc/poche/Poche.class.php | 2 ++ 1 file changed, 2 insertions(+) (limited to 'inc') diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index a8f64151..89e94a3a 100644 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php @@ -262,6 +262,7 @@ class Poche $tpl_vars = array( 'entries' => '', 'page_links' => '', + 'nb_results' => '', ); if (count($entries) > 0) { $this->pagination->set_total(count($entries)); @@ -269,6 +270,7 @@ class Poche $datas = $this->store->getEntriesByView($view, $this->user->getId(), $this->pagination->get_limit()); $tpl_vars['entries'] = $datas; $tpl_vars['page_links'] = $page_links; + $tpl_vars['nb_results'] = count($entries); } Tools::logm('display ' . $view . ' view'); break; -- cgit v1.2.3 From a32231274060ec2de453124117518458c4fa00df Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Sun, 8 Sep 2013 20:54:11 +0200 Subject: Implemented Flattr changes Added a button to say if the article is flattrable or not and how many people have flattred this object. --- inc/poche/Poche.class.php | 59 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 57 insertions(+), 2 deletions(-) (limited to 'inc') diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index a8f64151..5dab10df 100644 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php @@ -247,10 +247,15 @@ class Poche $tidy = tidy_parse_string($content, array('indent'=>true, 'show-body-only' => true), 'UTF8'); $tidy->cleanRepair(); $content = $tidy->value; - } + + // flattr checking + $flattr = new FlattrItem(); + $flattr->checkitem($entry['url']); + $tpl_vars = array( 'entry' => $entry, 'content' => $content, + 'flattr' => $flattr, ); } else { @@ -558,4 +563,54 @@ class Poche } return $version; } -} \ No newline at end of file +} + +/* class for Flattr querying. Should be put in a separate file +* Or maybe just create an array instead of a complete class... My mistake. :-° +*/ +class FlattrItem{ + public $status; + public $urltoflattr; + public $flattrItemURL; + public $numflattrs; + + public function checkitem($urltoflattr){ + $this->cacheflattrfile($urltoflattr); + $flattrResponse = file_get_contents("cache/flattr/".base64_encode($urltoflattr).".cache"); + var_dump($flattrResponse); + if($flattrResponse != FALSE){ + $result = json_decode($flattrResponse); + if (isset($result->message)){ + if ($result->message == "flattrable"){ + $this->status = "flattrable"; + } + } + elseif ($result->link) { + $this->status = "flattred"; + $this->flattrItemURL = $result->link; + $this->numflattrs = $result->flattrs_user_count; + } + else{ + $this->status = "not flattrable"; + } + } + else + { + $this->status = "FLATTR_ERR_CONNECTION"; + } + } + + private function cacheflattrfile($urltoflattr){ + if (!is_dir('cache/flattr')){ + mkdir('./cache/flattr', 0700); + } + // if a cache flattr file for this url already exists and it's been less than one day than it have been updated, see in /cache + if ((!file_exists("cache/flattr/".base64_encode($urltoflattr).".cache")) || (time() - filemtime("cache/flattr/".base64_encode($urltoflattr).".cache") > 86400)) + { + $askForFlattr = Tools::getFile("https://api.flattr.com/rest/v2/things/lookup/?url=".$urltoflattr); + $flattrCacheFile = fopen("cache/flattr/".base64_encode($urltoflattr).".cache", 'w+'); + fwrite($flattrCacheFile, $askForFlattr); + fclose($flattrCacheFile); + } + } +} -- cgit v1.2.3 From 693b3f86776ae236d69ac6ed085b5e46b9054642 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Sun, 8 Sep 2013 21:07:59 +0200 Subject: Implemented Add Button Added a button to add an URL when directly into Poche. If JS isn't enabled, nothing happens. --- inc/poche/Poche.class.php | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'inc') diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index a8f64151..a7479ad8 100644 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php @@ -558,4 +558,9 @@ class Poche } return $version; } + + function convertURLToBase64($plainurl){ + $convertedURL = base64_encode($plainurl); + $this->action('add', new Url($convertedURL)) + } } \ No newline at end of file -- cgit v1.2.3 From d5ce28df67fcddfb957ce28424f3e5751f433695 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Sun, 8 Sep 2013 21:26:30 +0200 Subject: Fixed bugs due to migration --- inc/poche/Poche.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'inc') diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index a7479ad8..4fe938fb 100644 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php @@ -561,6 +561,6 @@ class Poche function convertURLToBase64($plainurl){ $convertedURL = base64_encode($plainurl); - $this->action('add', new Url($convertedURL)) + $this->action('add', new Url($convertedURL)); } } \ No newline at end of file -- cgit v1.2.3 From af1d2792263d45c5ffea2e5485dd81bf59b7bded Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Sun, 8 Sep 2013 21:52:01 +0200 Subject: Fixed errors and changed source of flattrs Fixed errors, and the number displayed is no longer the number of peope who has flattred an article, but the number of flattrs he has got. --- inc/poche/Poche.class.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'inc') diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index 5dab10df..8b24e5cd 100644 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php @@ -249,20 +249,21 @@ class Poche $content = $tidy->value; // flattr checking - $flattr = new FlattrItem(); - $flattr->checkitem($entry['url']); + $flattr = new FlattrItem(); + $flattr->checkitem($entry['url']); - $tpl_vars = array( + $tpl_vars = array( 'entry' => $entry, 'content' => $content, - 'flattr' => $flattr, - ); + 'flattr' => $flattr + ); + } } else { Tools::logm('error in view call : entry is null'); } break; - default: # home, favorites and archive views + default : // home, favorites and archive views $entries = $this->store->getEntriesByView($view, $this->user->getId()); $tpl_vars = array( 'entries' => '', @@ -577,7 +578,6 @@ class FlattrItem{ public function checkitem($urltoflattr){ $this->cacheflattrfile($urltoflattr); $flattrResponse = file_get_contents("cache/flattr/".base64_encode($urltoflattr).".cache"); - var_dump($flattrResponse); if($flattrResponse != FALSE){ $result = json_decode($flattrResponse); if (isset($result->message)){ @@ -588,7 +588,7 @@ class FlattrItem{ elseif ($result->link) { $this->status = "flattred"; $this->flattrItemURL = $result->link; - $this->numflattrs = $result->flattrs_user_count; + $this->numflattrs = $result->flattrs; } else{ $this->status = "not flattrable"; -- cgit v1.2.3 From ce4a1dcc193d3124fc51c4942137621d3d806a19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Tue, 10 Sep 2013 14:41:58 +0200 Subject: changes to add url directly from poche --- inc/poche/Poche.class.php | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) (limited to 'inc') diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index 4fe938fb..5030c9aa 100644 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php @@ -182,7 +182,7 @@ class Poche } if (!$import) { - Tools::redirect(); + Tools::redirect('?view=home'); } break; case 'delete': @@ -558,9 +558,4 @@ class Poche } return $version; } - - function convertURLToBase64($plainurl){ - $convertedURL = base64_encode($plainurl); - $this->action('add', new Url($convertedURL)); - } } \ No newline at end of file -- cgit v1.2.3 From 3c33e40b614db7d14fec1d9b87963def4fac46a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Tue, 10 Sep 2013 15:43:01 +0200 Subject: change email address in header --- inc/poche/config.inc.php | 5 +---- inc/poche/define.inc.php | 2 +- 2 files changed, 2 insertions(+), 5 deletions(-) (limited to 'inc') diff --git a/inc/poche/config.inc.php b/inc/poche/config.inc.php index a1917295..2268808e 100755 --- a/inc/poche/config.inc.php +++ b/inc/poche/config.inc.php @@ -3,7 +3,7 @@ * poche, a read it later open source system * * @category poche - * @author Nicolas Lœuillet + * @author Nicolas Lœuillet * @copyright 2013 * @license http://www.wtfpl.net/ see COPYING file */ @@ -15,9 +15,6 @@ 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'; -// } 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 3f667430..53c275dd 100644 --- a/inc/poche/define.inc.php +++ b/inc/poche/define.inc.php @@ -3,7 +3,7 @@ * poche, a read it later open source system * * @category poche - * @author Nicolas Lœuillet + * @author Nicolas Lœuillet * @copyright 2013 * @license http://www.wtfpl.net/ see COPYING file */ -- cgit v1.2.3 From d11e2bcf48badc1da0e3914eec49d9ab1d781f4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Tue, 10 Sep 2013 15:46:05 +0200 Subject: change doc url --- inc/poche/config.inc.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'inc') diff --git a/inc/poche/config.inc.php b/inc/poche/config.inc.php index 2268808e..7f1b8c92 100755 --- a/inc/poche/config.inc.php +++ b/inc/poche/config.inc.php @@ -12,7 +12,7 @@ require_once __DIR__ . '/../../inc/poche/define.inc.php'; # /!\ Be careful if you change the lines below /!\ if (!file_exists(__DIR__ . '/../../vendor/autoload.php')) { - die('Twig does not seem installed. Have a look at the documentation.'); + die('Twig does not seem installed. Have a look at the documentation.'); } require_once __DIR__ . '/../../inc/poche/User.class.php'; -- cgit v1.2.3 From 964481d023676bee964141a1d14f638995ac8d30 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Tue, 10 Sep 2013 18:23:56 +0200 Subject: Fixed bugs, added a flattr button and an option There's a button and an option in define.inc.php to show the button or not. --- inc/poche/Poche.class.php | 2 +- inc/poche/define.inc.php | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) (limited to 'inc') diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index 8b24e5cd..b0efe69a 100644 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php @@ -602,7 +602,7 @@ class FlattrItem{ private function cacheflattrfile($urltoflattr){ if (!is_dir('cache/flattr')){ - mkdir('./cache/flattr', 0700); + mkdir('./cache/flattr', 0777); } // if a cache flattr file for this url already exists and it's been less than one day than it have been updated, see in /cache if ((!file_exists("cache/flattr/".base64_encode($urltoflattr).".cache")) || (time() - filemtime("cache/flattr/".base64_encode($urltoflattr).".cache") > 86400)) diff --git a/inc/poche/define.inc.php b/inc/poche/define.inc.php index 3f667430..62777282 100644 --- a/inc/poche/define.inc.php +++ b/inc/poche/define.inc.php @@ -20,8 +20,9 @@ define ('DEBUG_POCHE', FALSE); define ('DOWNLOAD_PICTURES', FALSE); define ('SHARE_TWITTER', TRUE); define ('SHARE_MAIL', TRUE); -define ('SHARE_SHAARLI', FALSE); +define ('SHARE_SHAARLI', TRUE); define ('SHAARLI_URL', 'http://myshaarliurl.com'); +define ('FLATTR', TRUE); define ('ABS_PATH', 'assets/'); define ('TPL', __DIR__ . '/../../tpl'); define ('LOCALE', __DIR__ . '/../../locale'); -- cgit v1.2.3 From f16b0747a45bfd91de03d22ecd7dbe70bf3d98a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Tue, 10 Sep 2013 18:28:17 +0200 Subject: remove site_config to manage them by a submodule --- inc/3rdparty/site_config/README.txt | 6 ------ inc/3rdparty/site_config/custom/bfmtv.com.txt | 6 ------ inc/3rdparty/site_config/custom/inthepoche.com.txt | 7 ------- inc/3rdparty/site_config/custom/tldp.org.txt | 6 ------ inc/3rdparty/site_config/index.php | 3 --- inc/3rdparty/site_config/standard/.wikipedia.org.txt | 19 ------------------- inc/3rdparty/site_config/standard/index.php | 3 --- inc/3rdparty/site_config/standard/version.php | 2 -- 8 files changed, 52 deletions(-) delete mode 100644 inc/3rdparty/site_config/README.txt delete mode 100644 inc/3rdparty/site_config/custom/bfmtv.com.txt delete mode 100644 inc/3rdparty/site_config/custom/inthepoche.com.txt delete mode 100644 inc/3rdparty/site_config/custom/tldp.org.txt delete mode 100644 inc/3rdparty/site_config/index.php delete mode 100644 inc/3rdparty/site_config/standard/.wikipedia.org.txt delete mode 100644 inc/3rdparty/site_config/standard/index.php delete mode 100644 inc/3rdparty/site_config/standard/version.php (limited to 'inc') diff --git a/inc/3rdparty/site_config/README.txt b/inc/3rdparty/site_config/README.txt deleted file mode 100644 index 0aff456b..00000000 --- a/inc/3rdparty/site_config/README.txt +++ /dev/null @@ -1,6 +0,0 @@ -Full-Text RSS Site Patterns ---------------------------- - -Site patterns allow you to specify what should be extracted from specific sites. - -Please see http://help.fivefilters.org/customer/portal/articles/223153-site-patterns for more information. \ No newline at end of file diff --git a/inc/3rdparty/site_config/custom/bfmtv.com.txt b/inc/3rdparty/site_config/custom/bfmtv.com.txt deleted file mode 100644 index 0ff28d56..00000000 --- a/inc/3rdparty/site_config/custom/bfmtv.com.txt +++ /dev/null @@ -1,6 +0,0 @@ -title: //title -body: //h2 | //span[@class='masque'] | //article[@class='corps_article_right'] -prune: no -tidy: no - -test_url: http://www.bfmtv.com/societe/cigarette-electronique-dangers-588622.html \ No newline at end of file diff --git a/inc/3rdparty/site_config/custom/inthepoche.com.txt b/inc/3rdparty/site_config/custom/inthepoche.com.txt deleted file mode 100644 index ede74b97..00000000 --- a/inc/3rdparty/site_config/custom/inthepoche.com.txt +++ /dev/null @@ -1,7 +0,0 @@ -title: //title -body: //div[@class='post-content'] - -prune: no -tidy: no - -test_url: http://www.inthepoche.com/?post/poche-hosting \ No newline at end of file diff --git a/inc/3rdparty/site_config/custom/tldp.org.txt b/inc/3rdparty/site_config/custom/tldp.org.txt deleted file mode 100644 index 7dd5cdb5..00000000 --- a/inc/3rdparty/site_config/custom/tldp.org.txt +++ /dev/null @@ -1,6 +0,0 @@ -title: //title -body: //h2 | //p | //ul -prune: no -tidy: no - -test_url: http://www.tldp.org/HOWTO/Plug-and-Play-HOWTO-7.html \ No newline at end of file diff --git a/inc/3rdparty/site_config/index.php b/inc/3rdparty/site_config/index.php deleted file mode 100644 index a3d5f739..00000000 --- a/inc/3rdparty/site_config/index.php +++ /dev/null @@ -1,3 +0,0 @@ - \ No newline at end of file diff --git a/inc/3rdparty/site_config/standard/.wikipedia.org.txt b/inc/3rdparty/site_config/standard/.wikipedia.org.txt deleted file mode 100644 index 8b98ae4b..00000000 --- a/inc/3rdparty/site_config/standard/.wikipedia.org.txt +++ /dev/null @@ -1,19 +0,0 @@ -title: //h1[@id='firstHeading'] -body: //div[@id = 'bodyContent'] -strip_id_or_class: editsection -#strip_id_or_class: toc -strip_id_or_class: vertical-navbox -strip: //table[@id='toc'] -strip: //div[@id='catlinks'] -strip: //div[@id='jump-to-nav'] -strip: //div[@class='thumbcaption']//div[@class='magnify'] -strip: //table[@class='navbox'] -strip: //table[contains(@class, 'infobox')] -strip: //div[@class='dablink'] -strip: //div[@id='contentSub'] -strip: //table[contains(@class, 'metadata')] -strip: //*[contains(@class, 'noprint')] -strip: //span[@title='pronunciation:'] -prune: no -tidy: no -test_url: http://en.wikipedia.org/wiki/Christopher_Lloyd \ No newline at end of file diff --git a/inc/3rdparty/site_config/standard/index.php b/inc/3rdparty/site_config/standard/index.php deleted file mode 100644 index a3d5f739..00000000 --- a/inc/3rdparty/site_config/standard/index.php +++ /dev/null @@ -1,3 +0,0 @@ - \ No newline at end of file diff --git a/inc/3rdparty/site_config/standard/version.php b/inc/3rdparty/site_config/standard/version.php deleted file mode 100644 index e61807ed..00000000 --- a/inc/3rdparty/site_config/standard/version.php +++ /dev/null @@ -1,2 +0,0 @@ - Date: Tue, 10 Sep 2013 18:50:42 +0200 Subject: add site_config submodule --- inc/3rdparty/site_config | 1 + 1 file changed, 1 insertion(+) create mode 160000 inc/3rdparty/site_config (limited to 'inc') diff --git a/inc/3rdparty/site_config b/inc/3rdparty/site_config new file mode 160000 index 00000000..fe9f0d3f --- /dev/null +++ b/inc/3rdparty/site_config @@ -0,0 +1 @@ +Subproject commit fe9f0d3f60d44a8701f3ecab0c4077a4ed39bfe8 -- cgit v1.2.3 From b9523a0ba09b5641e93fcd8300dd1a9f5145da2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Thu, 12 Sep 2013 19:28:59 +0200 Subject: fix bug #209: titles with colon bad parsed --- inc/poche/PocheReadability.php | 46 ++++++++++++++++++++++++++++++++++++++++++ inc/poche/Url.class.php | 2 +- inc/poche/config.inc.php | 10 ++------- 3 files changed, 49 insertions(+), 9 deletions(-) create mode 100644 inc/poche/PocheReadability.php (limited to 'inc') diff --git a/inc/poche/PocheReadability.php b/inc/poche/PocheReadability.php new file mode 100644 index 00000000..48ae90d0 --- /dev/null +++ b/inc/poche/PocheReadability.php @@ -0,0 +1,46 @@ +getInnerText($this->dom->getElementsByTagName('title')->item(0)); + } catch(Exception $e) {} + + if (preg_match('/ [\|\-] /', $curTitle)) + { + $curTitle = preg_replace('/(.*)[\|\-] .*/i', '$1', $origTitle); + + if (count(explode(' ', $curTitle)) < 3) { + $curTitle = preg_replace('/[^\|\-]*[\|\-](.*)/i', '$1', $origTitle); + } + } + else if(strlen($curTitle) > 150 || strlen($curTitle) < 15) + { + $hOnes = $this->dom->getElementsByTagName('h1'); + if($hOnes->length == 1) + { + $curTitle = $this->getInnerText($hOnes->item(0)); + } + } + + $curTitle = trim($curTitle); + + if (count(explode(' ', $curTitle)) <= 4) { + $curTitle = $origTitle; + } + + $articleTitle = $this->dom->createElement('h1'); + $articleTitle->innerHTML = $curTitle; + + return $articleTitle; + } +} \ No newline at end of file diff --git a/inc/poche/Url.class.php b/inc/poche/Url.class.php index 5a893014..600a2166 100644 --- a/inc/poche/Url.class.php +++ b/inc/poche/Url.class.php @@ -354,7 +354,7 @@ class Url } if (isset($splink)) { // Build DOM tree from HTML - $readability = new Readability($html, $url); + $readability = new PocheReadability($html, $url); $xpath = new DOMXPath($readability->dom); // Loop through single_page_link xpath expressions $single_page_url = null; diff --git a/inc/poche/config.inc.php b/inc/poche/config.inc.php index 45526695..aaa26af8 100755 --- a/inc/poche/config.inc.php +++ b/inc/poche/config.inc.php @@ -20,6 +20,7 @@ require_once __DIR__ . '/../../inc/poche/Url.class.php'; require_once __DIR__ . '/../../inc/3rdparty/class.messages.php'; require_once __DIR__ . '/../../inc/poche/Poche.class.php'; require_once __DIR__ . '/../../inc/3rdparty/Readability.php'; +require_once __DIR__ . '/../../inc/poche/PocheReadability.php'; require_once __DIR__ . '/../../inc/3rdparty/Encoding.php'; require_once __DIR__ . '/../../inc/poche/Database.class.php'; require_once __DIR__ . '/../../vendor/autoload.php'; @@ -47,11 +48,4 @@ if (!ini_get('date.timezone') || !@date_default_timezone_set(ini_get('date.timez date_default_timezone_set('UTC'); } -$poche = new Poche(); -#XSRF protection with token -// if (!empty($_POST)) { -// if (!Session::isToken($_POST['token'])) { -// die(_('Wrong token')); -// } -// unset($_SESSION['tokens']); -// } \ No newline at end of file +$poche = new Poche(); \ No newline at end of file -- cgit v1.2.3 From 1a08e7b6f6f4dead5556435033e8ac7634144ae0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Fri, 13 Sep 2013 09:01:33 +0200 Subject: titles with colon bad parsed --- inc/3rdparty/content-extractor/ContentExtractor.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'inc') diff --git a/inc/3rdparty/content-extractor/ContentExtractor.php b/inc/3rdparty/content-extractor/ContentExtractor.php index db371c6a..26878392 100644 --- a/inc/3rdparty/content-extractor/ContentExtractor.php +++ b/inc/3rdparty/content-extractor/ContentExtractor.php @@ -138,7 +138,7 @@ class ContentExtractor } // load and parse html - $this->readability = new Readability($html, $url); + $this->readability = new PocheReadability($html, $url); // we use xpath to find elements in the given HTML document // see http://en.wikipedia.org/wiki/XPath_1.0 -- cgit v1.2.3 From 1b2abab6ddbb3460b8981a296fe04477a42801b3 Mon Sep 17 00:00:00 2001 From: NumEricR Date: Mon, 26 Aug 2013 22:25:03 +0200 Subject: Add lang attribute in html tag --- inc/poche/Tools.class.php | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'inc') diff --git a/inc/poche/Tools.class.php b/inc/poche/Tools.class.php index 3a792d43..1ab90be1 100644 --- a/inc/poche/Tools.class.php +++ b/inc/poche/Tools.class.php @@ -248,4 +248,9 @@ class Tools fclose($fp); } } + + public static function getDocLanguage($userlanguage) { + $lang = explode('.', $userlanguage); + return str_replace('_', '-', $lang[0]); + } } \ No newline at end of file -- cgit v1.2.3 From f6597c7cb90e9bfa96f01f5f78f98cd72696da55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Tue, 17 Sep 2013 14:48:16 +0200 Subject: fix bug #127: update session class --- inc/3rdparty/Session.class.php | 283 +++++++++++++++++++++++++++++++---------- inc/poche/Poche.class.php | 1 + inc/poche/config.inc.php | 10 +- 3 files changed, 223 insertions(+), 71 deletions(-) (limited to 'inc') diff --git a/inc/3rdparty/Session.class.php b/inc/3rdparty/Session.class.php index 3162f507..08126bad 100644 --- a/inc/3rdparty/Session.class.php +++ b/inc/3rdparty/Session.class.php @@ -1,136 +1,279 @@ $value) { - $_SESSION[$key] = $value; - } - if ($login==$login_test && $password==$password_test){ - // generate unique random number to sign forms (HMAC) - $_SESSION['uid'] = sha1(uniqid('',true).'_'.mt_rand()); - $_SESSION['info']=Session::_allInfos(); - $_SESSION['username']=$login; - // Set session expiration. - $_SESSION['expires_on']=time()+Session::$inactivity_timeout; - return true; + self::banInit(); + if (self::banCanLogin()) { + if ($login === $loginTest && $password === $passwordTest) { + self::banLoginOk(); + // Generate unique random number to sign forms (HMAC) + $_SESSION['uid'] = sha1(uniqid('', true).'_'.mt_rand()); + $_SESSION['ip'] = self::_allIPs(); + $_SESSION['username'] = $login; + // Set session expiration. + $_SESSION['expires_on'] = time() + self::$inactivityTimeout; + + foreach ($pValues as $key => $value) { + $_SESSION[$key] = $value; + } + + return true; + } + self::banLoginFailed(); } + return false; } - // Force logout + /** + * Unset SESSION variable to force logout + */ public static function logout() { - unset($_SESSION['uid'],$_SESSION['info'],$_SESSION['expires_on'],$_SESSION['tokens'], $_SESSION['login'], $_SESSION['pass'], $_SESSION['poche_user']); + unset($_SESSION['uid'], $_SESSION['ip'], $_SESSION['expires_on']); } - // Make sure user is logged in. + /** + * Make sure user is logged in. + * + * @return true|false True if user is logged in, false otherwise + */ public static function isLogged() { if (!isset ($_SESSION['uid']) - || $_SESSION['info']!=Session::_allInfos() - || time()>=$_SESSION['expires_on']){ - Session::logout(); + || (self::$disableSessionProtection === false + && $_SESSION['ip'] !== self::_allIPs()) + || time() >= $_SESSION['expires_on']) { + self::logout(); + return false; } // User accessed a page : Update his/her session expiration date. - $_SESSION['expires_on']=time()+Session::$inactivity_timeout; + $_SESSION['expires_on'] = time() + self::$inactivityTimeout; + if (!empty($_SESSION['longlastingsession'])) { + $_SESSION['expires_on'] += $_SESSION['longlastingsession']; + } + return true; } - // Returns a token. - public static function getToken() + /** + * Create a token, store it in SESSION and return it + * + * @param string $salt to prevent birthday attack + * + * @return string Token created + */ + public static function getToken($salt = '') { - if (!isset($_SESSION['tokens'])){ + if (!isset($_SESSION['tokens'])) { $_SESSION['tokens']=array(); } // We generate a random string and store it on the server side. - $rnd = sha1(uniqid('',true).'_'.mt_rand()); + $rnd = sha1(uniqid('', true).'_'.mt_rand().$salt); $_SESSION['tokens'][$rnd]=1; + return $rnd; } - // Tells if a token is ok. Using this function will destroy the token. - // return true if token is ok. + /** + * Tells if a token is ok. Using this function will destroy the token. + * + * @param string $token Token to test + * + * @return true|false True if token is correct, false otherwise + */ public static function isToken($token) { - if (isset($_SESSION['tokens'][$token])) - { + if (isset($_SESSION['tokens'][$token])) { unset($_SESSION['tokens'][$token]); // Token is used: destroy it. + return true; // Token is ok. } + return false; // Wrong token, or already used. } -} \ No newline at end of file + + /** + * Signal a failed login. Will ban the IP if too many failures: + */ + public static function banLoginFailed() + { + if (self::$banFile !== '') { + $ip = $_SERVER["REMOTE_ADDR"]; + $gb = $GLOBALS['IPBANS']; + + if (!isset($gb['FAILURES'][$ip])) { + $gb['FAILURES'][$ip] = 0; + } + $gb['FAILURES'][$ip]++; + if ($gb['FAILURES'][$ip] > (self::$banAfter - 1)) { + $gb['BANS'][$ip]= time() + self::$banDuration; + } + + $GLOBALS['IPBANS'] = $gb; + file_put_contents(self::$banFile, ""); + } + } + + /** + * Signals a successful login. Resets failed login counter. + */ + public static function banLoginOk() + { + if (self::$banFile !== '') { + $ip = $_SERVER["REMOTE_ADDR"]; + $gb = $GLOBALS['IPBANS']; + unset($gb['FAILURES'][$ip]); unset($gb['BANS'][$ip]); + $GLOBALS['IPBANS'] = $gb; + file_put_contents(self::$banFile, ""); + } + } + + /** + * Ban init + */ + public static function banInit() + { + if (self::$banFile !== '') { + if (!is_file(self::$banFile)) { + file_put_contents(self::$banFile, "array(), 'BANS'=>array()), true).";\n?>"); + } + include self::$banFile; + } + } + + /** + * Checks if the user CAN login. If 'true', the user can try to login. + * + * @return boolean true if user is banned, false otherwise + */ + public static function banCanLogin() + { + if (self::$banFile !== '') { + $ip = $_SERVER["REMOTE_ADDR"]; + $gb = $GLOBALS['IPBANS']; + if (isset($gb['BANS'][$ip])) { + // User is banned. Check if the ban has expired: + if ($gb['BANS'][$ip] <= time()) { + // Ban expired, user can try to login again. + unset($gb['FAILURES'][$ip]); + unset($gb['BANS'][$ip]); + file_put_contents(self::$banFile, ""); + + return true; // Ban has expired, user can login. + } + + return false; // User is banned. + } + } + + return true; // User is not banned. + } +} diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index 9db4a034..2f0f7038 100644 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php @@ -93,6 +93,7 @@ class Poche private function init() { Tools::initPhp(); + Session::$sessionName = 'poche'; Session::init(); if (isset($_SESSION['poche_user']) && $_SESSION['poche_user'] != array()) { diff --git a/inc/poche/config.inc.php b/inc/poche/config.inc.php index aaa26af8..9247c292 100755 --- a/inc/poche/config.inc.php +++ b/inc/poche/config.inc.php @@ -48,4 +48,12 @@ if (!ini_get('date.timezone') || !@date_default_timezone_set(ini_get('date.timez date_default_timezone_set('UTC'); } -$poche = new Poche(); \ No newline at end of file +$poche = new Poche(); + +#XSRF protection with token +if (!empty($_POST)) { + if (!Session::isToken($_POST['token'])) { + die(_('Wrong token')); + } + unset($_SESSION['tokens']); +} \ No newline at end of file -- cgit v1.2.3 From 0d64be15de12cd949fc9b9d2b8352a1815da965a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Wed, 18 Sep 2013 09:25:28 +0200 Subject: remove csrf check --- inc/poche/config.inc.php | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) (limited to 'inc') diff --git a/inc/poche/config.inc.php b/inc/poche/config.inc.php index 9247c292..aaa26af8 100755 --- a/inc/poche/config.inc.php +++ b/inc/poche/config.inc.php @@ -48,12 +48,4 @@ if (!ini_get('date.timezone') || !@date_default_timezone_set(ini_get('date.timez date_default_timezone_set('UTC'); } -$poche = new Poche(); - -#XSRF protection with token -if (!empty($_POST)) { - if (!Session::isToken($_POST['token'])) { - die(_('Wrong token')); - } - unset($_SESSION['tokens']); -} \ No newline at end of file +$poche = new Poche(); \ No newline at end of file -- cgit v1.2.3 From 705250b93dc71ae91d3c305b51e7a20611873805 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Fri, 20 Sep 2013 09:32:49 +0200 Subject: fixes with new session class --- inc/3rdparty/Session.class.php | 2 +- inc/poche/Poche.class.php | 9 --------- 2 files changed, 1 insertion(+), 10 deletions(-) (limited to 'inc') diff --git a/inc/3rdparty/Session.class.php b/inc/3rdparty/Session.class.php index 08126bad..df913a06 100644 --- a/inc/3rdparty/Session.class.php +++ b/inc/3rdparty/Session.class.php @@ -136,7 +136,7 @@ class Session */ public static function logout() { - unset($_SESSION['uid'], $_SESSION['ip'], $_SESSION['expires_on']); + unset($_SESSION['uid'],$_SESSION['ip'],$_SESSION['expires_on'],$_SESSION['tokens'], $_SESSION['login'], $_SESSION['pass'], $_SESSION['poche_user']); } /** diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index 2f0f7038..8770c7f7 100644 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php @@ -331,16 +331,7 @@ class Poche if ($user != array()) { # Save login into Session Session::login($user['username'], $user['password'], $_POST['login'], Tools::encodeString($_POST['password'] . $_POST['login']), array('poche_user' => new User($user))); - $this->messages->add('s', _('welcome to your poche')); - if (!empty($_POST['longlastingsession'])) { - $_SESSION['longlastingsession'] = 31536000; - $_SESSION['expires_on'] = time() + $_SESSION['longlastingsession']; - session_set_cookie_params($_SESSION['longlastingsession']); - } else { - session_set_cookie_params(0); - } - session_regenerate_id(true); Tools::logm('login successful'); Tools::redirect($referer); } -- cgit v1.2.3 From 00dbaf90bc44ef3ed0abaebb15307756e054a027 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Fri, 20 Sep 2013 10:21:39 +0200 Subject: merge #224 --- inc/3rdparty/site_config | 1 - inc/poche/Database.class.php | 16 ++- inc/poche/Poche.class.php | 293 ++++++++++++++++++++++++++++++++++--------- inc/poche/Tools.class.php | 40 +++--- inc/poche/config.inc.php | 89 ++++++------- inc/poche/config.inc.php.new | 56 +++++++++ inc/poche/global.inc.php | 72 +++++++++++ 7 files changed, 435 insertions(+), 132 deletions(-) delete mode 160000 inc/3rdparty/site_config create mode 100755 inc/poche/config.inc.php.new create mode 100644 inc/poche/global.inc.php (limited to 'inc') diff --git a/inc/3rdparty/site_config b/inc/3rdparty/site_config deleted file mode 160000 index fe9f0d3f..00000000 --- a/inc/3rdparty/site_config +++ /dev/null @@ -1 +0,0 @@ -Subproject commit fe9f0d3f60d44a8701f3ecab0c4077a4ed39bfe8 diff --git a/inc/poche/Database.class.php b/inc/poche/Database.class.php index 84916b83..4d664992 100644 --- a/inc/poche/Database.class.php +++ b/inc/poche/Database.class.php @@ -60,11 +60,15 @@ class Database { $id_user = intval($this->getLastId($sequence)); $sql = 'INSERT INTO users_config ( user_id, name, value ) VALUES (?, ?, ?)'; - $params = array($id_user, 'pager', '10'); + $params = array($id_user, 'pager', PAGINATION); $query = $this->executeQuery($sql, $params); $sql = 'INSERT INTO users_config ( user_id, name, value ) VALUES (?, ?, ?)'; - $params = array($id_user, 'language', 'en_EN.UTF8'); + $params = array($id_user, 'language', LANG); + $query = $this->executeQuery($sql, $params); + + $sql = 'INSERT INTO users_config ( user_id, name, value ) VALUES (?, ?, ?)'; + $params = array($id_user, 'theme', DEFAULT_THEME); $query = $this->executeQuery($sql, $params); return TRUE; @@ -101,10 +105,16 @@ class Database { return $user; } - public function updatePassword($id, $password) + public function updatePassword($userId, $password) { $sql_update = "UPDATE users SET password=? WHERE id=?"; $params_update = array($password, $id); + $this->updateUserConfig($userId, 'password', $password); + } + + public function updateUserConfig($userId, $key, $value) { + $sql_update = "UPDATE users_config SET `value`=? WHERE `user_id`=? AND `name`=?"; + $params_update = array($value, $userId, $key); $query = $this->executeQuery($sql_update, $params_update); } diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index 8770c7f7..67fbd529 100644 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php @@ -10,77 +10,200 @@ class Poche { + public static $canRenderTemplates = true; + public static $configFileAvailable = true; + public $user; public $store; public $tpl; public $messages; public $pagination; - - function __construct() + + private $currentTheme = ''; + private $notInstalledMessage = ''; + + # @todo make this dynamic (actually install themes and save them in the database including author information et cetera) + private $installedThemes = array( + 'default' => array('requires' => array()), + 'dark' => array('requires' => array('default')), + 'dmagenta' => array('requires' => array('default')), + 'solarized' => array('requires' => array('default')), + 'solarized-dark' => array('requires' => array('default')) + ); + + public function __construct() { + if (! $this->configFileIsAvailable()) { + return; + } + + $this->init(); + + if (! $this->themeIsInstalled()) { + return; + } + $this->initTpl(); - if (!$this->checkBeforeInstall()) { - exit; + + if (! $this->systemIsInstalled()) { + return; } + $this->store = new Database(); - $this->init(); $this->messages = new Messages(); # installation - if(!$this->store->isInstalled()) - { + if (! $this->store->isInstalled()) { $this->install(); } } + + private function init() + { + Tools::initPhp(); + Session::$sessionName = 'poche'; + Session::init(); + + if (isset($_SESSION['poche_user']) && $_SESSION['poche_user'] != array()) { + $this->user = $_SESSION['poche_user']; + } else { + # fake user, just for install & login screens + $this->user = new User(); + $this->user->setConfig($this->getDefaultConfig()); + } + + # l10n + $language = $this->user->getConfigValue('language'); + putenv('LC_ALL=' . $language); + setlocale(LC_ALL, $language); + bindtextdomain($language, LOCALE); + textdomain($language); + + # Pagination + $this->pagination = new Paginator($this->user->getConfigValue('pager'), 'p'); + + # Set up theme + $themeDirectory = $this->user->getConfigValue('theme'); + + if ($themeDirectory === false) { + $themeDirectory = DEFAULT_THEME; + } + + $this->currentTheme = $themeDirectory; + } + + public function configFileIsAvailable() { + if (! self::$configFileAvailable) { + $this->notInstalledMessage = 'You have to rename inc/poche/config.inc.php.new to inc/poche/config.inc.php.'; + + return false; + } + return true; + } + + public function themeIsInstalled() { + # Twig is an absolute requirement for Poche to function. Abort immediately if the Composer installer hasn't been run yet + if (! self::$canRenderTemplates) { + $this->notInstalledMessage = 'Twig does not seem to be installed. Please initialize the Composer installation to automatically fetch dependencies. Have a look at the documentation.'; + + return false; + } + + # Check if the selected theme and its requirements are present + if (! is_dir(THEME . '/' . $this->getTheme())) { + $this->notInstalledMessage = 'The currently selected theme (' . $this->getTheme() . ') does not seem to be properly installed (Missing directory: ' . THEME . '/' . $this->getTheme() . ')'; + + self::$canRenderTemplates = false; + + return false; + } + + foreach ($this->installedThemes[$this->getTheme()]['requires'] as $requiredTheme) { + if (! is_dir(THEME . '/' . $requiredTheme)) { + $this->notInstalledMessage = 'The required "' . $requiredTheme . '" theme is missing for the current theme (' . $this->getTheme() . ')'; + + self::$canRenderTemplates = false; + + return false; + } + } + + return true; + } + /** * all checks before installation. + * @todo move HTML to template * @return boolean */ - private function checkBeforeInstall() + public function systemIsInstalled() { $msg = ''; - $allIsGood = TRUE; - - if (!is_writable(CACHE)) { + + $configSalt = defined('SALT') ? constant('SALT') : ''; + + if (empty($configSalt)) { + $msg = '

error

You have not yet filled in the SALT value in the config.inc.php file.

'; + } else if (! is_writable(CACHE)) { Tools::logm('you don\'t have write access on cache directory'); - die('You don\'t have write access on cache directory.'); - } - else if (file_exists('./install/update.php') && !DEBUG_POCHE) { + $msg = '

error

You don\'t have write access on cache directory.

'; + } else if (STORAGE == 'sqlite' && ! file_exists(STORAGE_SQLITE)) { + Tools::logm('sqlite file doesn\'t exist'); + $msg = '

error

sqlite file doesn\'t exist, you can find it in install folder.

'; + } else if (file_exists(ROOT . '/install/update.php') && ! DEBUG_POCHE) { $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) { + } else if (is_dir(ROOT . '/install') && ! DEBUG_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)) { + } else if (STORAGE == 'sqlite' && ! is_writable(STORAGE_SQLITE)) { Tools::logm('you don\'t have write access on sqlite file'); $msg = '

error

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

'; - $allIsGood = FALSE; } - - if (!$allIsGood) { - echo $this->tpl->render('error.twig', array( - 'msg' => $msg - )); + + if (! empty($msg)) { + $this->notInstalledMessage = $msg; + + return false; } - return $allIsGood; + return true; + } + + public function getNotInstalledMessage() { + return $this->notInstalledMessage; } private function initTpl() { - # template engine - $loader = new Twig_Loader_Filesystem(TPL); + $loaderChain = new Twig_Loader_Chain(); + + # add the current theme as first to the loader chain so Twig will look there first for overridden template files + try { + $loaderChain->addLoader(new Twig_Loader_Filesystem(THEME . '/' . $this->getTheme())); + } catch (Twig_Error_Loader $e) { + # @todo isInstalled() should catch this, inject Twig later + die('The currently selected theme (' . $this->getTheme() . ') does not seem to be properly installed (' . THEME . '/' . $this->getTheme() .' is missing)'); + } + + # add all required themes to the loader chain + foreach ($this->installedThemes[$this->getTheme()]['requires'] as $requiredTheme) { + try { + $loaderChain->addLoader(new Twig_Loader_Filesystem(THEME . '/' . DEFAULT_THEME)); + } catch (Twig_Error_Loader $e) { + # @todo isInstalled() should catch this, inject Twig later + die('The required "' . $requiredTheme . '" theme is missing for the current theme (' . $this->getTheme() . ')'); + } + } + if (DEBUG_POCHE) { $twig_params = array(); - } - else { + } else { $twig_params = array('cache' => CACHE); } - $this->tpl = new Twig_Environment($loader, $twig_params); + + $this->tpl = new Twig_Environment($loaderChain, $twig_params); $this->tpl->addExtension(new Twig_Extensions_Extension_I18n()); + # filter to display domain name of an url $filter = new Twig_SimpleFilter('getDomain', 'Tools::getDomain'); $this->tpl->addFilter($filter); @@ -88,39 +211,19 @@ class Poche # filter for reading time $filter = new Twig_SimpleFilter('getReadingTime', 'Tools::getReadingTime'); $this->tpl->addFilter($filter); - } - - private function init() - { - Tools::initPhp(); - Session::$sessionName = 'poche'; - Session::init(); - - if (isset($_SESSION['poche_user']) && $_SESSION['poche_user'] != array()) { - $this->user = $_SESSION['poche_user']; - } - else { - # fake user, just for install & login screens - $this->user = new User(); - $this->user->setConfig($this->getDefaultConfig()); - } - - # l10n - $language = $this->user->getConfigValue('language'); - putenv('LC_ALL=' . $language); - setlocale(LC_ALL, $language); - bindtextdomain($language, LOCALE); - textdomain($language); - - # Pagination - $this->pagination = new Paginator($this->user->getConfigValue('pager'), 'p'); + + # filter for simple filenames in config view + $filter = new Twig_SimpleFilter('getPrettyFilename', function($string) { return str_replace(ROOT, '', $string); }); + $this->tpl->addFilter($filter); } private function install() { Tools::logm('poche still not installed'); echo $this->tpl->render('install.twig', array( - 'token' => Session::getToken() + 'token' => Session::getToken(), + 'theme' => $this->getTheme(), + 'poche_url' => Tools::getPocheUrl() )); if (isset($_GET['install'])) { if (($_POST['password'] == $_POST['password_repeat']) @@ -140,13 +243,41 @@ class Poche } exit(); } + + public function getTheme() { + return $this->currentTheme; + } + + public function getInstalledThemes() { + $handle = opendir(THEME); + $themes = array(); + + while (($theme = readdir($handle)) !== false) { + # Themes are stored in a directory, so all directory names are themes + # @todo move theme installation data to database + if (! is_dir(THEME . '/' . $theme) || in_array($theme, array('..', '.'))) { + continue; + } + + $current = false; + + if ($theme === $this->getTheme()) { + $current = true; + } + + $themes[] = array('name' => $theme, 'current' => $current); + } + + return $themes; + } public function getDefaultConfig() - { + { return array( 'pager' => PAGINATION, 'language' => LANG, - ); + 'theme' => DEFAULT_THEME + ); } /** @@ -231,7 +362,9 @@ class Poche $prod = $this->getPocheVersion('prod'); $compare_dev = version_compare(POCHE_VERSION, $dev); $compare_prod = version_compare(POCHE_VERSION, $prod); + $themes = $this->getInstalledThemes(); $tpl_vars = array( + 'themes' => $themes, 'dev' => $dev, 'prod' => $prod, 'compare_dev' => $compare_dev, @@ -316,6 +449,44 @@ class Poche } } } + + public function updateTheme() + { + # no data + if (empty($_POST['theme'])) { + } + + # we are not going to change it to the current theme... + if ($_POST['theme'] == $this->getTheme()) { + $this->messages->add('w', _('still using the "' . $this->getTheme() . '" theme!')); + Tools::redirect('?view=config'); + } + + $themes = $this->getInstalledThemes(); + $actualTheme = false; + + foreach ($themes as $theme) { + if ($theme['name'] == $_POST['theme']) { + $actualTheme = true; + break; + } + } + + if (! $actualTheme) { + $this->messages->add('e', _('that theme does not seem to be installed')); + Tools::redirect('?view=config'); + } + + $this->store->updateUserConfig($this->user->getId(), 'theme', $_POST['theme']); + $this->messages->add('s', _('you have changed your theme preferences')); + + $currentConfig = $_SESSION['poche_user']->config; + $currentConfig['theme'] = $_POST['theme']; + + $_SESSION['poche_user']->setConfig($currentConfig); + + Tools::redirect('?view=config'); + } /** * checks if login & password are correct and save the user in session. diff --git a/inc/poche/Tools.class.php b/inc/poche/Tools.class.php index 1ab90be1..8eb988f4 100644 --- a/inc/poche/Tools.class.php +++ b/inc/poche/Tools.class.php @@ -84,9 +84,9 @@ class Tools public static function getTplFile($view) { - $tpl_file = 'home.twig'; - switch ($view) - { + $default_tpl = 'home.twig'; + + switch ($view) { case 'install': $tpl_file = 'install.twig'; break; @@ -102,9 +102,20 @@ class Tools case 'view': $tpl_file = 'view.twig'; break; + + case 'login': + $tpl_file = 'login.twig'; + break; + + case 'error': + $tpl_file = 'error.twig'; + break; + default: - break; + $tpl_file = $default_tpl; + break; } + return $tpl_file; } @@ -228,27 +239,6 @@ class Tools return $minutes; } - - 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 (!file_exists($myconfig_file)) - { - $fp = fopen($myconfig_file, 'w'); - fwrite($fp, ' + * @author Nicolas Lœuillet * @copyright 2013 * @license http://www.wtfpl.net/ see COPYING file */ -require_once __DIR__ . '/../../inc/poche/define.inc.php'; - -# /!\ Be careful if you change the lines below /!\ -if (!file_exists(__DIR__ . '/../../vendor/autoload.php')) { - die('Twig does not seem installed. Have a look at the documentation.'); -} - -require_once __DIR__ . '/../../inc/poche/User.class.php'; -require_once __DIR__ . '/../../inc/poche/Url.class.php'; -require_once __DIR__ . '/../../inc/3rdparty/class.messages.php'; -require_once __DIR__ . '/../../inc/poche/Poche.class.php'; -require_once __DIR__ . '/../../inc/3rdparty/Readability.php'; -require_once __DIR__ . '/../../inc/poche/PocheReadability.php'; -require_once __DIR__ . '/../../inc/3rdparty/Encoding.php'; -require_once __DIR__ . '/../../inc/poche/Database.class.php'; -require_once __DIR__ . '/../../vendor/autoload.php'; -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'; -require_once __DIR__ . '/../../inc/3rdparty/FlattrItem.class.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(); \ No newline at end of file +define ('SALT', ''); # put a strong string here +define ('LANG', 'en_EN.utf8'); + +define ('STORAGE', 'sqlite'); # postgres, mysql or sqlite + +define ('STORAGE_SQLITE', ROOT . '/db/poche.sqlite'); # if you are using sqlite, where the database file is located + +# only for postgres & mysql +define ('STORAGE_SERVER', 'localhost'); +define ('STORAGE_DB', 'poche'); +define ('STORAGE_USER', 'poche'); +define ('STORAGE_PASSWORD', 'poche'); + +################################################################################# +# Do not trespass unless you know what you are doing +################################################################################# + +define ('MODE_DEMO', FALSE); +define ('DEBUG_POCHE', true); +define ('DOWNLOAD_PICTURES', FALSE); +define ('CONVERT_LINKS_FOOTNOTES', FALSE); +define ('REVERT_FORCED_PARAGRAPH_ELEMENTS', FALSE); +define ('SHARE_TWITTER', TRUE); +define ('SHARE_MAIL', TRUE); +define ('SHARE_SHAARLI', FALSE); +define ('SHAARLI_URL', 'http://myshaarliurl.com'); +define ('FLATTR', TRUE); +define ('FLATTR_API', 'https://api.flattr.com/rest/v2/things/lookup/?url='); +define ('NOT_FLATTRABLE', '0'); +define ('FLATTRABLE', '1'); +define ('FLATTRED', '2'); +define ('ABS_PATH', 'assets/'); + +define ('DEFAULT_THEME', 'default'); + +define ('THEME', ROOT . '/themes'); +define ('LOCALE', ROOT . '/locale'); +define ('CACHE', ROOT . '/cache'); + +define ('PAGINATION', '10'); + +define ('POCHE_VERSION', '1.0-beta5'); + +define ('IMPORT_POCKET_FILE', ROOT . '/ril_export.html'); +define ('IMPORT_READABILITY_FILE', ROOT . '/readability'); +define ('IMPORT_INSTAPAPER_FILE', ROOT . '/instapaper-export.html'); \ No newline at end of file diff --git a/inc/poche/config.inc.php.new b/inc/poche/config.inc.php.new new file mode 100755 index 00000000..5c304d14 --- /dev/null +++ b/inc/poche/config.inc.php.new @@ -0,0 +1,56 @@ + + * @copyright 2013 + * @license http://www.wtfpl.net/ see COPYING file + */ + +define ('SALT', ''); # put a strong string here +define ('LANG', 'en_EN.utf8'); + +define ('STORAGE', 'sqlite'); # postgres, mysql or sqlite + +define ('STORAGE_SQLITE', ROOT . '/db/poche.sqlite'); # if you are using sqlite, where the database file is located + +# only for postgres & mysql +define ('STORAGE_SERVER', 'localhost'); +define ('STORAGE_DB', 'poche'); +define ('STORAGE_USER', 'poche'); +define ('STORAGE_PASSWORD', 'poche'); + +################################################################################# +# Do not trespass unless you know what you are doing +################################################################################# + +define ('MODE_DEMO', FALSE); +define ('DEBUG_POCHE', true); +define ('DOWNLOAD_PICTURES', FALSE); +define ('CONVERT_LINKS_FOOTNOTES', FALSE); +define ('REVERT_FORCED_PARAGRAPH_ELEMENTS', FALSE); +define ('SHARE_TWITTER', TRUE); +define ('SHARE_MAIL', TRUE); +define ('SHARE_SHAARLI', FALSE); +define ('SHAARLI_URL', 'http://myshaarliurl.com'); +define ('FLATTR', TRUE); +define ('FLATTR_API', 'https://api.flattr.com/rest/v2/things/lookup/?url='); +define ('NOT_FLATTRABLE', '0'); +define ('FLATTRABLE', '1'); +define ('FLATTRED', '2'); +define ('ABS_PATH', 'assets/'); + +define ('DEFAULT_THEME', 'default'); + +define ('THEME', ROOT . '/themes'); +define ('LOCALE', ROOT . '/locale'); +define ('CACHE', ROOT . '/cache'); + +define ('PAGINATION', '10'); + +define ('POCHE_VERSION', '1.0-beta5'); + +define ('IMPORT_POCKET_FILE', ROOT . '/ril_export.html'); +define ('IMPORT_READABILITY_FILE', ROOT . '/readability'); +define ('IMPORT_INSTAPAPER_FILE', ROOT . '/instapaper-export.html'); \ No newline at end of file diff --git a/inc/poche/global.inc.php b/inc/poche/global.inc.php new file mode 100644 index 00000000..2437d065 --- /dev/null +++ b/inc/poche/global.inc.php @@ -0,0 +1,72 @@ + + * @copyright 2013 + * @license http://www.wtfpl.net/ see COPYING file + */ + +# the poche system root directory (/inc) +define('INCLUDES', dirname(__FILE__) . '/..'); + +# the poche root directory +define('ROOT', INCLUDES . '/..'); + +require_once INCLUDES . '/poche/Tools.class.php'; +require_once INCLUDES . '/poche/User.class.php'; +require_once INCLUDES . '/poche/Url.class.php'; +require_once INCLUDES . '/3rdparty/class.messages.php'; +require_once INCLUDES . '/poche/Poche.class.php'; + +require_once INCLUDES . '/3rdparty/Readability.php'; +require_once INCLUDES . '/poche/PocheReadability.php'; + +require_once INCLUDES . '/3rdparty/Encoding.php'; +require_once INCLUDES . '/poche/Database.class.php'; +require_once INCLUDES . '/3rdparty/simple_html_dom.php'; +require_once INCLUDES . '/3rdparty/paginator.php'; +require_once INCLUDES . '/3rdparty/Session.class.php'; + +require_once INCLUDES . '/3rdparty/simplepie/SimplePieAutoloader.php'; +require_once INCLUDES . '/3rdparty/simplepie/SimplePie/Core.php'; +require_once INCLUDES . '/3rdparty/content-extractor/ContentExtractor.php'; +require_once INCLUDES . '/3rdparty/content-extractor/SiteConfig.php'; +require_once INCLUDES . '/3rdparty/humble-http-agent/HumbleHttpAgent.php'; +require_once INCLUDES . '/3rdparty/humble-http-agent/SimplePie_HumbleHttpAgent.php'; +require_once INCLUDES . '/3rdparty/humble-http-agent/CookieJar.php'; +require_once INCLUDES . '/3rdparty/feedwriter/FeedItem.php'; +require_once INCLUDES . '/3rdparty/feedwriter/FeedWriter.php'; +require_once INCLUDES . '/3rdparty/feedwriter/DummySingleItemFeed.php'; +require_once INCLUDES . '/3rdparty/FlattrItem.class.php'; + +# Composer its autoloader for automatically loading Twig +if (! file_exists(ROOT . '/vendor/autoload.php')) { + Poche::$canRenderTemplates = false; +} else { + require_once ROOT . '/vendor/autoload.php'; +} + +# system configuration; database credentials et cetera +if (! file_exists(INCLUDES . '/poche/config.inc.php')) { + Poche::$configFileAvailable = false; +} else { + require_once INCLUDES . '/poche/config.inc.php'; +} + +if (Poche::$configFileAvailable && DOWNLOAD_PICTURES) { + require_once INCLUDES . '/poche/pochePictures.php'; +} + +if (!ini_get('date.timezone') || !@date_default_timezone_set(ini_get('date.timezone'))) { + date_default_timezone_set('UTC'); +} + +#XSRF protection with token +if (!empty($_POST)) { + if (!Session::isToken($_POST['token'])) { + die(_('Wrong token')); + } + unset($_SESSION['token']); +} \ No newline at end of file -- cgit v1.2.3 From 5801355cbcfc00be56d3745ae0a82ee7797bd0dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Fri, 20 Sep 2013 11:04:36 +0200 Subject: chmod & mail address --- inc/3rdparty/class.messages.php | 0 inc/poche/config.inc.php.new | 2 +- inc/poche/global.inc.php | 10 +--------- 3 files changed, 2 insertions(+), 10 deletions(-) mode change 100755 => 100644 inc/3rdparty/class.messages.php (limited to 'inc') diff --git a/inc/3rdparty/class.messages.php b/inc/3rdparty/class.messages.php old mode 100755 new mode 100644 diff --git a/inc/poche/config.inc.php.new b/inc/poche/config.inc.php.new index 5c304d14..48cc5783 100755 --- a/inc/poche/config.inc.php.new +++ b/inc/poche/config.inc.php.new @@ -3,7 +3,7 @@ * poche, a read it later open source system * * @category poche - * @author Nicolas Lœuillet + * @author Nicolas Lœuillet * @copyright 2013 * @license http://www.wtfpl.net/ see COPYING file */ diff --git a/inc/poche/global.inc.php b/inc/poche/global.inc.php index 2437d065..65a026a7 100644 --- a/inc/poche/global.inc.php +++ b/inc/poche/global.inc.php @@ -3,7 +3,7 @@ * poche, a read it later open source system * * @category poche - * @author Nicolas Lœuillet + * @author Nicolas Lœuillet * @copyright 2013 * @license http://www.wtfpl.net/ see COPYING file */ @@ -61,12 +61,4 @@ if (Poche::$configFileAvailable && DOWNLOAD_PICTURES) { if (!ini_get('date.timezone') || !@date_default_timezone_set(ini_get('date.timezone'))) { date_default_timezone_set('UTC'); -} - -#XSRF protection with token -if (!empty($_POST)) { - if (!Session::isToken($_POST['token'])) { - die(_('Wrong token')); - } - unset($_SESSION['token']); } \ No newline at end of file -- cgit v1.2.3 From 2af501566896ba9027830c278ad881daa35cae89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Fri, 20 Sep 2013 11:05:12 +0200 Subject: remove config.inc.php --- inc/poche/config.inc.php | 56 ------------------------------------------------ 1 file changed, 56 deletions(-) delete mode 100755 inc/poche/config.inc.php (limited to 'inc') diff --git a/inc/poche/config.inc.php b/inc/poche/config.inc.php deleted file mode 100755 index 5c304d14..00000000 --- a/inc/poche/config.inc.php +++ /dev/null @@ -1,56 +0,0 @@ - - * @copyright 2013 - * @license http://www.wtfpl.net/ see COPYING file - */ - -define ('SALT', ''); # put a strong string here -define ('LANG', 'en_EN.utf8'); - -define ('STORAGE', 'sqlite'); # postgres, mysql or sqlite - -define ('STORAGE_SQLITE', ROOT . '/db/poche.sqlite'); # if you are using sqlite, where the database file is located - -# only for postgres & mysql -define ('STORAGE_SERVER', 'localhost'); -define ('STORAGE_DB', 'poche'); -define ('STORAGE_USER', 'poche'); -define ('STORAGE_PASSWORD', 'poche'); - -################################################################################# -# Do not trespass unless you know what you are doing -################################################################################# - -define ('MODE_DEMO', FALSE); -define ('DEBUG_POCHE', true); -define ('DOWNLOAD_PICTURES', FALSE); -define ('CONVERT_LINKS_FOOTNOTES', FALSE); -define ('REVERT_FORCED_PARAGRAPH_ELEMENTS', FALSE); -define ('SHARE_TWITTER', TRUE); -define ('SHARE_MAIL', TRUE); -define ('SHARE_SHAARLI', FALSE); -define ('SHAARLI_URL', 'http://myshaarliurl.com'); -define ('FLATTR', TRUE); -define ('FLATTR_API', 'https://api.flattr.com/rest/v2/things/lookup/?url='); -define ('NOT_FLATTRABLE', '0'); -define ('FLATTRABLE', '1'); -define ('FLATTRED', '2'); -define ('ABS_PATH', 'assets/'); - -define ('DEFAULT_THEME', 'default'); - -define ('THEME', ROOT . '/themes'); -define ('LOCALE', ROOT . '/locale'); -define ('CACHE', ROOT . '/cache'); - -define ('PAGINATION', '10'); - -define ('POCHE_VERSION', '1.0-beta5'); - -define ('IMPORT_POCKET_FILE', ROOT . '/ril_export.html'); -define ('IMPORT_READABILITY_FILE', ROOT . '/readability'); -define ('IMPORT_INSTAPAPER_FILE', ROOT . '/instapaper-export.html'); \ No newline at end of file -- cgit v1.2.3 From 7bda34c66b8f07284111c2df580cac1c9cae109d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Fri, 20 Sep 2013 11:25:44 +0200 Subject: help when sqlite file not found --- inc/poche/Poche.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'inc') diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index 67fbd529..18860ddc 100644 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php @@ -150,7 +150,7 @@ class Poche $msg = '

error

You don\'t have write access on cache directory.

'; } else if (STORAGE == 'sqlite' && ! file_exists(STORAGE_SQLITE)) { Tools::logm('sqlite file doesn\'t exist'); - $msg = '

error

sqlite file doesn\'t exist, you can find it in install folder.

'; + $msg = '

error

sqlite file doesn\'t exist, you can find it in install folder. Copy it in /db folder.

'; } else if (file_exists(ROOT . '/install/update.php') && ! DEBUG_POCHE) { $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.

'; } else if (is_dir(ROOT . '/install') && ! DEBUG_POCHE) { -- cgit v1.2.3