diff options
Diffstat (limited to 'inc/poche/Poche.class.php')
-rw-r--r-- | inc/poche/Poche.class.php | 121 |
1 files changed, 87 insertions, 34 deletions
diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index 2af49acd..e0dc0d20 100644 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php | |||
@@ -18,11 +18,10 @@ class Poche | |||
18 | 18 | ||
19 | function __construct() | 19 | function __construct() |
20 | { | 20 | { |
21 | if (file_exists('./install') && !DEBUG_POCHE) { | 21 | $this->initTpl(); |
22 | Tools::logm('folder /install exists'); | 22 | if (!$this->checkBeforeInstall()) { |
23 | die('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.'); | 23 | exit; |
24 | } | 24 | } |
25 | |||
26 | $this->store = new Database(); | 25 | $this->store = new Database(); |
27 | $this->init(); | 26 | $this->init(); |
28 | $this->messages = new Messages(); | 27 | $this->messages = new Messages(); |
@@ -34,27 +33,44 @@ class Poche | |||
34 | } | 33 | } |
35 | } | 34 | } |
36 | 35 | ||
37 | private function init() | 36 | /** |
37 | * all checks before installation. | ||
38 | * @return boolean | ||
39 | */ | ||
40 | private function checkBeforeInstall() | ||
38 | { | 41 | { |
39 | Tools::initPhp(); | 42 | $msg = ''; |
40 | Session::init(); | 43 | $allIsGood = TRUE; |
41 | 44 | ||
42 | if (isset($_SESSION['poche_user']) && $_SESSION['poche_user'] != array()) { | 45 | if (!is_writable(CACHE)) { |
43 | $this->user = $_SESSION['poche_user']; | 46 | Tools::logm('you don\'t have write access on cache directory'); |
47 | die('You don\'t have write access on cache directory.'); | ||
44 | } | 48 | } |
45 | else { | 49 | else if (file_exists('./install/update.php') && !DEBUG_POCHE) { |
46 | # fake user, just for install & login screens | 50 | $msg = 'A poche update is needed. Please execute this update <a href="install/update.php">by clicking here</a>. If you have already do the update, please delete /install folder.'; |
47 | $this->user = new User(); | 51 | $allIsGood = FALSE; |
48 | $this->user->setConfig($this->getDefaultConfig()); | 52 | } |
53 | else if (file_exists('./install') && !DEBUG_POCHE) { | ||
54 | $msg = 'If you want to update your poche, you just have to delete /install folder. <br />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.'; | ||
55 | $allIsGood = FALSE; | ||
56 | } | ||
57 | else if (STORAGE == 'sqlite' && !is_writable(STORAGE_SQLITE)) { | ||
58 | Tools::logm('you don\'t have write access on sqlite file'); | ||
59 | $msg = 'You don\'t have write access on sqlite file.'; | ||
60 | $allIsGood = FALSE; | ||
61 | } | ||
62 | |||
63 | if (!$allIsGood) { | ||
64 | echo $this->tpl->render('error.twig', array( | ||
65 | 'msg' => $msg | ||
66 | )); | ||
49 | } | 67 | } |
50 | 68 | ||
51 | # l10n | 69 | return $allIsGood; |
52 | $language = $this->user->getConfigValue('language'); | 70 | } |
53 | putenv('LC_ALL=' . $language); | ||
54 | setlocale(LC_ALL, $language); | ||
55 | bindtextdomain($language, LOCALE); | ||
56 | textdomain($language); | ||
57 | 71 | ||
72 | private function initTpl() | ||
73 | { | ||
58 | # template engine | 74 | # template engine |
59 | $loader = new Twig_Loader_Filesystem(TPL); | 75 | $loader = new Twig_Loader_Filesystem(TPL); |
60 | if (DEBUG_POCHE) { | 76 | if (DEBUG_POCHE) { |
@@ -72,6 +88,28 @@ class Poche | |||
72 | # filter for reading time | 88 | # filter for reading time |
73 | $filter = new Twig_SimpleFilter('getReadingTime', 'Tools::getReadingTime'); | 89 | $filter = new Twig_SimpleFilter('getReadingTime', 'Tools::getReadingTime'); |
74 | $this->tpl->addFilter($filter); | 90 | $this->tpl->addFilter($filter); |
91 | } | ||
92 | |||
93 | private function init() | ||
94 | { | ||
95 | Tools::initPhp(); | ||
96 | Session::init(); | ||
97 | |||
98 | if (isset($_SESSION['poche_user']) && $_SESSION['poche_user'] != array()) { | ||
99 | $this->user = $_SESSION['poche_user']; | ||
100 | } | ||
101 | else { | ||
102 | # fake user, just for install & login screens | ||
103 | $this->user = new User(); | ||
104 | $this->user->setConfig($this->getDefaultConfig()); | ||
105 | } | ||
106 | |||
107 | # l10n | ||
108 | $language = $this->user->getConfigValue('language'); | ||
109 | putenv('LC_ALL=' . $language); | ||
110 | setlocale(LC_ALL, $language); | ||
111 | bindtextdomain($language, LOCALE); | ||
112 | textdomain($language); | ||
75 | 113 | ||
76 | # Pagination | 114 | # Pagination |
77 | $this->pagination = new Paginator($this->user->getConfigValue('pager'), 'p'); | 115 | $this->pagination = new Paginator($this->user->getConfigValue('pager'), 'p'); |
@@ -87,10 +125,12 @@ class Poche | |||
87 | if (($_POST['password'] == $_POST['password_repeat']) | 125 | if (($_POST['password'] == $_POST['password_repeat']) |
88 | && $_POST['password'] != "" && $_POST['login'] != "") { | 126 | && $_POST['password'] != "" && $_POST['login'] != "") { |
89 | # let's rock, install poche baby ! | 127 | # let's rock, install poche baby ! |
90 | $this->store->install($_POST['login'], Tools::encodeString($_POST['password'] . $_POST['login'])); | 128 | if ($this->store->install($_POST['login'], Tools::encodeString($_POST['password'] . $_POST['login']))) |
91 | Session::logout(); | 129 | { |
92 | Tools::logm('poche is now installed'); | 130 | Session::logout(); |
93 | Tools::redirect(); | 131 | Tools::logm('poche is now installed'); |
132 | Tools::redirect(); | ||
133 | } | ||
94 | } | 134 | } |
95 | else { | 135 | else { |
96 | Tools::logm('error during installation'); | 136 | Tools::logm('error during installation'); |
@@ -180,6 +220,7 @@ class Poche | |||
180 | } | 220 | } |
181 | break; | 221 | break; |
182 | default: | 222 | default: |
223 | Tools::logm('action ' . $action . 'doesn\'t exist'); | ||
183 | break; | 224 | break; |
184 | } | 225 | } |
185 | } | 226 | } |
@@ -409,9 +450,11 @@ class Poche | |||
409 | $str_data = file_get_contents("./readability"); | 450 | $str_data = file_get_contents("./readability"); |
410 | $data = json_decode($str_data,true); | 451 | $data = json_decode($str_data,true); |
411 | Tools::logm('starting import from Readability'); | 452 | Tools::logm('starting import from Readability'); |
412 | 453 | $count = 0; | |
413 | foreach ($data as $key => $value) { | 454 | foreach ($data as $key => $value) { |
414 | $url = ''; | 455 | $url = NULL; |
456 | $favorite = FALSE; | ||
457 | $archive = FALSE; | ||
415 | foreach ($value as $attr => $attr_value) { | 458 | foreach ($value as $attr => $attr_value) { |
416 | if ($attr == 'article__url') { | 459 | if ($attr == 'article__url') { |
417 | $url = new Url(base64_encode($attr_value)); | 460 | $url = new Url(base64_encode($attr_value)); |
@@ -420,20 +463,30 @@ class Poche | |||
420 | if (STORAGE == 'postgres') { | 463 | if (STORAGE == 'postgres') { |
421 | $sequence = 'entries_id_seq'; | 464 | $sequence = 'entries_id_seq'; |
422 | } | 465 | } |
423 | // if ($attr_value == 'favorite' && $attr_value == 'true') { | 466 | if ($attr_value == 'true') { |
424 | // $last_id = $this->store->getLastId($sequence); | 467 | if ($attr == 'favorite') { |
425 | // $this->store->favoriteById($last_id); | 468 | $favorite = TRUE; |
426 | // $this->action('toogle_fav', $url, $last_id, TRUE); | 469 | } |
427 | // } | 470 | if ($attr == 'archive') { |
428 | if ($attr_value == 'archive' && $attr_value == 'true') { | 471 | $archive = TRUE; |
472 | } | ||
473 | } | ||
474 | } | ||
475 | # we can add the url | ||
476 | if (!is_null($url) && $url->isCorrect()) { | ||
477 | $this->action('add', $url, 0, TRUE); | ||
478 | $count++; | ||
479 | if ($favorite) { | ||
480 | $last_id = $this->store->getLastId($sequence); | ||
481 | $this->action('toggle_fav', $url, $last_id, TRUE); | ||
482 | } | ||
483 | if ($archive) { | ||
429 | $last_id = $this->store->getLastId($sequence); | 484 | $last_id = $this->store->getLastId($sequence); |
430 | $this->action('toggle_archive', $url, $last_id, TRUE); | 485 | $this->action('toggle_archive', $url, $last_id, TRUE); |
431 | } | 486 | } |
432 | } | 487 | } |
433 | if ($url->isCorrect()) | ||
434 | $this->action('add', $url, 0, TRUE); | ||
435 | } | 488 | } |
436 | $this->messages->add('s', _('import from Readability completed')); | 489 | $this->messages->add('s', _('import from Readability completed. ' . $count . ' new links.')); |
437 | Tools::logm('import from Readability completed'); | 490 | Tools::logm('import from Readability completed'); |
438 | Tools::redirect(); | 491 | Tools::redirect(); |
439 | } | 492 | } |