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/poche/Poche.class.php') 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 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/poche/Poche.class.php') 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/poche/Poche.class.php') 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/poche/Poche.class.php') 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/poche/Poche.class.php') 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/poche/Poche.class.php') 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/poche/Poche.class.php') 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/poche/Poche.class.php') 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/poche/Poche.class.php') 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 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 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'inc/poche/Poche.class.php') 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)) -- 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/poche/Poche.class.php | 1 + 1 file changed, 1 insertion(+) (limited to 'inc/poche/Poche.class.php') 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()) { -- 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/poche/Poche.class.php | 9 --------- 1 file changed, 9 deletions(-) (limited to 'inc/poche/Poche.class.php') 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/poche/Poche.class.php | 293 ++++++++++++++++++++++++++++++++++++---------- 1 file changed, 232 insertions(+), 61 deletions(-) (limited to 'inc/poche/Poche.class.php') 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. -- 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/poche/Poche.class.php') 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