diff options
Diffstat (limited to 'inc/poche')
-rw-r--r-- | inc/poche/Poche.class.php | 121 | ||||
-rw-r--r-- | inc/poche/Tools.class.php | 26 | ||||
-rw-r--r-- | inc/poche/Url.class.php | 2 | ||||
-rwxr-xr-x[-rw-r--r--] | inc/poche/config.inc.php | 57 | ||||
-rw-r--r-- | inc/poche/define.inc.php | 30 |
5 files changed, 164 insertions, 72 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 | } |
diff --git a/inc/poche/Tools.class.php b/inc/poche/Tools.class.php index 0eb0d9ea..1baf745d 100644 --- a/inc/poche/Tools.class.php +++ b/inc/poche/Tools.class.php | |||
@@ -233,4 +233,30 @@ class Tools | |||
233 | 233 | ||
234 | return $minutes; | 234 | return $minutes; |
235 | } | 235 | } |
236 | |||
237 | |||
238 | public static function createMyConfig() | ||
239 | { | ||
240 | $myconfig_file = './inc/poche/myconfig.inc.php'; | ||
241 | |||
242 | if (version_compare(POCHE_VERSION, '1.0-beta3') == 1) { | ||
243 | # $myconfig_file is only created with poche > 1.0-beta3 | ||
244 | # in 1.0-beta3, the update script creates $myconfig_file | ||
245 | |||
246 | if (!is_writable('./inc/poche/')) { | ||
247 | self::logm('you don\'t have write access to create ./inc/poche/myconfig.inc.php'); | ||
248 | die('You don\'t have write access to create ./inc/poche/myconfig.inc.php.'); | ||
249 | } | ||
250 | |||
251 | if (!file_exists($myconfig_file)) | ||
252 | { | ||
253 | $fp = fopen($myconfig_file, 'w'); | ||
254 | fwrite($fp, '<?php'."\r\n"); | ||
255 | fwrite($fp, "define ('POCHE_VERSION', '1.0-beta3');" . "\r\n"); | ||
256 | fwrite($fp, "define ('SALT', '" . md5(time() . $_SERVER['SCRIPT_FILENAME'] . rand()) . "');" . "\r\n"); | ||
257 | fwrite($fp, "define ('LANG', 'en_EN.utf8');" . "\r\n"); | ||
258 | fclose($fp); | ||
259 | } | ||
260 | } | ||
261 | } | ||
236 | } \ No newline at end of file | 262 | } \ No newline at end of file |
diff --git a/inc/poche/Url.class.php b/inc/poche/Url.class.php index f4a8f99e..00b0b257 100644 --- a/inc/poche/Url.class.php +++ b/inc/poche/Url.class.php | |||
@@ -27,7 +27,7 @@ class Url | |||
27 | 27 | ||
28 | public function isCorrect() | 28 | public function isCorrect() |
29 | { | 29 | { |
30 | $pattern = '|^http(s)?://[a-z0-9-]+(.[a-z0-9-]+)*(:[0-9]+)?(/.*)?$|i'; | 30 | $pattern = '|^(.*:)//([a-z\-.]+)(:[0-9]+)?(.*)$|i'; |
31 | 31 | ||
32 | return preg_match($pattern, $this->url); | 32 | return preg_match($pattern, $this->url); |
33 | } | 33 | } |
diff --git a/inc/poche/config.inc.php b/inc/poche/config.inc.php index 321784d7..4122ff10 100644..100755 --- a/inc/poche/config.inc.php +++ b/inc/poche/config.inc.php | |||
@@ -8,47 +8,30 @@ | |||
8 | * @license http://www.wtfpl.net/ see COPYING file | 8 | * @license http://www.wtfpl.net/ see COPYING file |
9 | */ | 9 | */ |
10 | 10 | ||
11 | # storage | 11 | require_once __DIR__ . '/../../inc/poche/define.inc.php'; |
12 | define ('STORAGE','sqlite'); # postgres, mysql, sqlite | ||
13 | define ('STORAGE_SERVER', 'localhost'); # leave blank for sqlite | ||
14 | define ('STORAGE_DB', 'poche'); # only for postgres & mysql | ||
15 | define ('STORAGE_SQLITE', './db/poche.sqlite'); | ||
16 | define ('STORAGE_USER', 'postgres'); # leave blank for sqlite | ||
17 | define ('STORAGE_PASSWORD', 'postgres'); # leave blank for sqlite | ||
18 | |||
19 | define ('POCHE_VERSION', '1.0-beta1'); | ||
20 | define ('MODE_DEMO', FALSE); | ||
21 | define ('DEBUG_POCHE', FALSE); | ||
22 | define ('CONVERT_LINKS_FOOTNOTES', FALSE); | ||
23 | define ('REVERT_FORCED_PARAGRAPH_ELEMENTS', FALSE); | ||
24 | define ('DOWNLOAD_PICTURES', FALSE); | ||
25 | define ('SHARE_TWITTER', TRUE); | ||
26 | define ('SHARE_MAIL', TRUE); | ||
27 | define ('SALT', '464v54gLLw928uz4zUBqkRJeiPY68zCX'); | ||
28 | define ('ABS_PATH', 'assets/'); | ||
29 | define ('TPL', './tpl'); | ||
30 | define ('LOCALE', './locale'); | ||
31 | define ('CACHE', './cache'); | ||
32 | define ('LANG', 'en_EN.UTF8'); | ||
33 | define ('PAGINATION', '10'); | ||
34 | define ('THEME', 'light'); | ||
35 | 12 | ||
36 | # /!\ Be careful if you change the lines below /!\ | 13 | # /!\ Be careful if you change the lines below /!\ |
37 | require_once './inc/poche/User.class.php'; | 14 | if (!file_exists(__DIR__ . '/../../vendor/autoload.php')) { |
38 | require_once './inc/poche/Tools.class.php'; | 15 | die('Twig does not seem installed. Have a look at <a href="http://inthepoche.com/?pages/Documentation">the documentation.</a>'); |
39 | require_once './inc/poche/Url.class.php'; | 16 | } |
40 | require_once './inc/3rdparty/class.messages.php'; | 17 | |
41 | require_once './inc/poche/Poche.class.php'; | 18 | if (file_exists(__DIR__ . '/../../inc/poche/myconfig.inc.php')) { |
42 | require_once './inc/3rdparty/Readability.php'; | 19 | require_once __DIR__ . '/../../inc/poche/myconfig.inc.php'; |
43 | require_once './inc/3rdparty/Encoding.php'; | 20 | } |
44 | require_once './inc/poche/Database.class.php'; | 21 | require_once __DIR__ . '/../../inc/poche/User.class.php'; |
45 | require_once './vendor/autoload.php'; | 22 | require_once __DIR__ . '/../../inc/poche/Url.class.php'; |
46 | require_once './inc/3rdparty/simple_html_dom.php'; | 23 | require_once __DIR__ . '/../../inc/3rdparty/class.messages.php'; |
47 | require_once './inc/3rdparty/paginator.php'; | 24 | require_once __DIR__ . '/../../inc/poche/Poche.class.php'; |
48 | require_once './inc/3rdparty/Session.class.php'; | 25 | require_once __DIR__ . '/../../inc/3rdparty/Readability.php'; |
26 | require_once __DIR__ . '/../../inc/3rdparty/Encoding.php'; | ||
27 | require_once __DIR__ . '/../../inc/poche/Database.class.php'; | ||
28 | require_once __DIR__ . '/../../vendor/autoload.php'; | ||
29 | require_once __DIR__ . '/../../inc/3rdparty/simple_html_dom.php'; | ||
30 | require_once __DIR__ . '/../../inc/3rdparty/paginator.php'; | ||
31 | require_once __DIR__ . '/../../inc/3rdparty/Session.class.php'; | ||
49 | 32 | ||
50 | if (DOWNLOAD_PICTURES) { | 33 | if (DOWNLOAD_PICTURES) { |
51 | require_once './inc/poche/pochePictures.php'; | 34 | require_once __DIR__ . '/../../inc/poche/pochePictures.php'; |
52 | } | 35 | } |
53 | 36 | ||
54 | $poche = new Poche(); | 37 | $poche = new Poche(); |
diff --git a/inc/poche/define.inc.php b/inc/poche/define.inc.php new file mode 100644 index 00000000..c32ca098 --- /dev/null +++ b/inc/poche/define.inc.php | |||
@@ -0,0 +1,30 @@ | |||
1 | <?php | ||
2 | /** | ||
3 | * poche, a read it later open source system | ||
4 | * | ||
5 | * @category poche | ||
6 | * @author Nicolas LÅ“uillet <nicolas@loeuillet.org> | ||
7 | * @copyright 2013 | ||
8 | * @license http://www.wtfpl.net/ see COPYING file | ||
9 | */ | ||
10 | |||
11 | define ('STORAGE','sqlite'); # postgres, mysql, sqlite | ||
12 | define ('STORAGE_SERVER', 'localhost'); # leave blank for sqlite | ||
13 | define ('STORAGE_DB', 'poche'); # only for postgres & mysql | ||
14 | define ('STORAGE_SQLITE', __DIR__ . '/../../db/poche.sqlite'); | ||
15 | define ('STORAGE_USER', 'postgres'); # leave blank for sqlite | ||
16 | define ('STORAGE_PASSWORD', 'postgres'); # leave blank for sqlite | ||
17 | |||
18 | define ('MODE_DEMO', FALSE); | ||
19 | define ('DEBUG_POCHE', FALSE); | ||
20 | define ('CONVERT_LINKS_FOOTNOTES', FALSE); | ||
21 | define ('REVERT_FORCED_PARAGRAPH_ELEMENTS', FALSE); | ||
22 | define ('DOWNLOAD_PICTURES', FALSE); | ||
23 | define ('SHARE_TWITTER', TRUE); | ||
24 | define ('SHARE_MAIL', TRUE); | ||
25 | define ('ABS_PATH', 'assets/'); | ||
26 | define ('TPL', __DIR__ . '/../../tpl'); | ||
27 | define ('LOCALE', __DIR__ . '/../../locale'); | ||
28 | define ('CACHE', __DIR__ . '/../../cache'); | ||
29 | define ('PAGINATION', '10'); | ||
30 | define ('THEME', 'light'); \ No newline at end of file | ||