aboutsummaryrefslogtreecommitdiffhomepage
path: root/inc/poche
diff options
context:
space:
mode:
Diffstat (limited to 'inc/poche')
-rwxr-xr-xinc/poche/Database.class.php4
-rwxr-xr-xinc/poche/Poche.class.php85
-rwxr-xr-x[-rw-r--r--]inc/poche/Routing.class.php79
-rwxr-xr-xinc/poche/Tools.class.php19
-rwxr-xr-xinc/poche/config.inc.default.php2
-rw-r--r--inc/poche/pochePictures.php2
6 files changed, 96 insertions, 95 deletions
diff --git a/inc/poche/Database.class.php b/inc/poche/Database.class.php
index 8b52a9df..b5dd2120 100755
--- a/inc/poche/Database.class.php
+++ b/inc/poche/Database.class.php
@@ -23,6 +23,10 @@ class Database {
23 { 23 {
24 switch (STORAGE) { 24 switch (STORAGE) {
25 case 'sqlite': 25 case 'sqlite':
26 // Check if /db is writeable
27 if ( !is_writable(STORAGE_SQLITE) || !is_writable(dirname(STORAGE_SQLITE))) {
28 die('An error occured: "db" directory must be writeable for your web server user!');
29 }
26 $db_path = 'sqlite:' . STORAGE_SQLITE; 30 $db_path = 'sqlite:' . STORAGE_SQLITE;
27 $this->handle = new PDO($db_path); 31 $this->handle = new PDO($db_path);
28 break; 32 break;
diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php
index c8a09f30..8cebafa3 100755
--- a/inc/poche/Poche.class.php
+++ b/inc/poche/Poche.class.php
@@ -525,6 +525,14 @@ class Poche
525 $longlastingsession = isset($_POST['longlastingsession']); 525 $longlastingsession = isset($_POST['longlastingsession']);
526 $passwordTest = ($isauthenticated) ? $user['password'] : Tools::encodeString($password . $login); 526 $passwordTest = ($isauthenticated) ? $user['password'] : Tools::encodeString($password . $login);
527 Session::login($user['username'], $user['password'], $login, $passwordTest, $longlastingsession, array('poche_user' => new User($user))); 527 Session::login($user['username'], $user['password'], $login, $passwordTest, $longlastingsession, array('poche_user' => new User($user)));
528
529 # reload l10n
530 $language = $user['config']['language'];
531 @putenv('LC_ALL=' . $language);
532 setlocale(LC_ALL, $language);
533 bindtextdomain($language, LOCALE);
534 textdomain($language);
535
528 $this->messages->add('s', _('welcome to your wallabag')); 536 $this->messages->add('s', _('welcome to your wallabag'));
529 Tools::logm('login successful'); 537 Tools::logm('login successful');
530 Tools::redirect($referer); 538 Tools::redirect($referer);
@@ -552,42 +560,39 @@ class Poche
552 * import datas into your wallabag 560 * import datas into your wallabag
553 * @return boolean 561 * @return boolean
554 */ 562 */
555 public function import()
556 {
557 if (isset($_FILES['file'])) {
558 Tools::logm('Import stated: parsing file');
559
560 // assume, that file is in json format
561
562 $str_data = file_get_contents($_FILES['file']['tmp_name']);
563 $data = json_decode($str_data, true);
564 if ($data === null) {
565
566 // not json - assume html
567
568 $html = new simple_html_dom();
569 $html->load_file($_FILES['file']['tmp_name']);
570 $data = array();
571 $read = 0;
572 foreach(array('ol','ul') as $list) {
573 foreach($html->find($list) as $ul) {
574 foreach($ul->find('li') as $li) {
575 $tmpEntry = array();
576 $a = $li->find('a');
577 $tmpEntry['url'] = $a[0]->href;
578 $tmpEntry['tags'] = $a[0]->tags;
579 $tmpEntry['is_read'] = $read;
580 if ($tmpEntry['url']) {
581 $data[] = $tmpEntry;
582 }
583 }
584
585 // the second <ol/ul> is for read links
586 563
587 $read = ((sizeof($data) && $read) ? 0 : 1); 564 public function import() {
588 } 565
589 } 566 if ( isset($_FILES['file']) && $_FILES['file']['tmp_name'] ) {
567 Tools::logm('Import stated: parsing file');
568
569 // assume, that file is in json format
570 $str_data = file_get_contents($_FILES['file']['tmp_name']);
571 $data = json_decode($str_data, true);
572
573 if ( $data === null ) {
574 //not json - assume html
575 $html = new simple_html_dom();
576 $html->load_file($_FILES['file']['tmp_name']);
577 $data = array();
578 $read = 0;
579 foreach (array('ol','ul') as $list) {
580 foreach ($html->find($list) as $ul) {
581 foreach ($ul->find('li') as $li) {
582 $tmpEntry = array();
583 $a = $li->find('a');
584 $tmpEntry['url'] = $a[0]->href;
585 $tmpEntry['tags'] = $a[0]->tags;
586 $tmpEntry['is_read'] = $read;
587 if ($tmpEntry['url']) {
588 $data[] = $tmpEntry;
589 }
590 }
591 # the second <ol/ul> is for read links
592 $read = ((sizeof($data) && $read)?0:1);
590 } 593 }
594 }
595 }
591 596
592 // for readability structure 597 // for readability structure
593 598
@@ -630,9 +635,11 @@ class Poche
630 $this->messages->add('s', _('Articles inserted: ') . $i . _('. Please note, that some may be marked as "read".')); 635 $this->messages->add('s', _('Articles inserted: ') . $i . _('. Please note, that some may be marked as "read".'));
631 } 636 }
632 637
633 Tools::logm('Import of articles finished: ' . $i . ' articles added (w/o content if not provided).'); 638 Tools::logm('Import of articles finished: '.$i.' articles added (w/o content if not provided).');
634 } 639 }
635 640 else {
641 $this->messages->add('s', _('Did you forget to select a file?'));
642 }
636 // file parsing finished here 643 // file parsing finished here
637 // now download article contents if any 644 // now download article contents if any
638 // check if we need to download any content 645 // check if we need to download any content
@@ -751,8 +758,8 @@ class Poche
751 die(sprintf(_('User with this id (%d) does not exist.'), $user_id)); 758 die(sprintf(_('User with this id (%d) does not exist.'), $user_id));
752 } 759 }
753 760
754 if (!in_array($type, $allowed_types) || $token != $config['token']) { 761 if (!in_array($type, $allowed_types) || !isset($config['token']) || $token != $config['token']) {
755 die(_('Uh, there is a problem while generating feeds.')); 762 die(_('Uh, there is a problem while generating feed. Wrong token used?'));
756 } 763 }
757 764
758 $feed = new FeedWriter(RSS2); 765 $feed = new FeedWriter(RSS2);
diff --git a/inc/poche/Routing.class.php b/inc/poche/Routing.class.php
index 6643397a..0b373058 100644..100755
--- a/inc/poche/Routing.class.php
+++ b/inc/poche/Routing.class.php
@@ -98,49 +98,50 @@ class Routing
98 private function _launchAction() 98 private function _launchAction()
99 { 99 {
100 if (isset($_GET['login'])) { 100 if (isset($_GET['login'])) {
101 // hello you 101 // hello to you
102 $this->wallabag->login($this->referer); 102 $this->wallabag->login($this->referer);
103 } elseif (isset($_GET['logout'])) { 103 } elseif (isset($_GET['feed']) && isset($_GET['user_id'])) {
104 // see you soon ! 104 $tag_id = (isset($_GET['tag_id']) ? intval($_GET['tag_id']) : 0);
105 $this->wallabag->logout(); 105 $this->wallabag->generateFeeds($_GET['token'], filter_var($_GET['user_id'],FILTER_SANITIZE_NUMBER_INT), $tag_id, $_GET['type']);
106 } elseif (isset($_GET['config'])) { 106 }
107 // update password 107
108 $this->wallabag->updatePassword($_POST['password'], $_POST['password_repeat']); 108 //allowed ONLY to logged in user
109 } elseif (isset($_GET['newuser'])) { 109 if (\Session::isLogged() === true)
110 $this->wallabag->createNewUser($_POST['newusername'], $_POST['password4newuser'], $_POST['newuseremail']); 110 {
111 } elseif (isset($_GET['deluser'])) { 111 if (isset($_GET['logout'])) {
112 $this->wallabag->deleteUser($_POST['password4deletinguser']); 112 // see you soon !
113 } elseif (isset($_GET['epub'])) { 113 $this->wallabag->logout();
114 $epub = new WallabagEpub($this->wallabag, $_GET['method'], $_GET['value']); 114 } elseif (isset($_GET['config'])) {
115 $epub->run(); 115 // update password
116 } elseif (isset($_GET['import'])) { 116 $this->wallabag->updatePassword($_POST['password'], $_POST['password_repeat']);
117 $import = $this->wallabag->import(); 117 } elseif (isset($_GET['newuser'])) {
118 $tplVars = array_merge($this->vars, $import); 118 $this->wallabag->createNewUser($_POST['newusername'], $_POST['password4newuser']);
119 } elseif (isset($_GET['download'])) { 119 } elseif (isset($_GET['deluser'])) {
120 Tools::downloadDb(); 120 $this->wallabag->deleteUser($_POST['password4deletinguser']);
121 } elseif (isset($_GET['empty-cache'])) { 121 } elseif (isset($_GET['epub'])) {
122 Tools::emptyCache(); 122 $epub = new WallabagEpub($this->wallabag, $_GET['method'], $_GET['id'], $_GET['value']);
123 } elseif (isset($_GET['export'])) { 123 $epub->run();
124 $this->wallabag->export(); 124 } elseif (isset($_GET['import'])) {
125 } elseif (isset($_GET['updatetheme'])) { 125 $import = $this->wallabag->import();
126 $this->wallabag->tpl->updateTheme($_POST['theme']); 126 $tplVars = array_merge($this->vars, $import);
127 } elseif (isset($_GET['updatelanguage'])) { 127 } elseif (isset($_GET['empty-cache'])) {
128 $this->wallabag->language->updateLanguage($_POST['language']); 128 Tools::emptyCache();
129 } elseif (isset($_GET['uploadfile'])) { 129 } elseif (isset($_GET['export'])) {
130 $this->wallabag->uploadFile(); 130 $this->wallabag->export();
131 } elseif (isset($_GET['feed'])) { 131 } elseif (isset($_GET['updatetheme'])) {
132 if (isset($_GET['action']) && $_GET['action'] == 'generate') { 132 $this->wallabag->tpl->updateTheme($_POST['theme']);
133 } elseif (isset($_GET['updatelanguage'])) {
134 $this->wallabag->language->updateLanguage($_POST['language']);
135 } elseif (isset($_GET['uploadfile'])) {
136 $this->wallabag->uploadFile();
137 } elseif (isset($_GET['feed']) && isset($_GET['action']) && $_GET['action'] == 'generate') {
133 $this->wallabag->updateToken(); 138 $this->wallabag->updateToken();
134 } 139 }
135 else { 140 elseif (isset($_GET['plainurl']) && !empty($_GET['plainurl'])) {
136 $tag_id = (isset($_GET['tag_id']) ? intval($_GET['tag_id']) : 0); 141 $plainUrl = new Url(base64_encode($_GET['plainurl']));
137 $this->wallabag->generateFeeds($_GET['token'], filter_var($_GET['user_id'],FILTER_SANITIZE_NUMBER_INT), $tag_id, $_GET['type']); 142 $this->wallabag->action('add', $plainUrl);
138 } 143 }
139 } 144 }
140 elseif (isset($_GET['plainurl']) && !empty($_GET['plainurl'])) {
141 $plainUrl = new Url(base64_encode($_GET['plainurl']));
142 $this->wallabag->action('add', $plainUrl);
143 }
144 } 145 }
145 146
146 public function _render($file, $vars) 147 public function _render($file, $vars)
diff --git a/inc/poche/Tools.class.php b/inc/poche/Tools.class.php
index 63137d76..93ec3fc6 100755
--- a/inc/poche/Tools.class.php
+++ b/inc/poche/Tools.class.php
@@ -54,6 +54,10 @@ final class Tools
54 || ($https && $_SERVER["SERVER_PORT"] == '443') 54 || ($https && $_SERVER["SERVER_PORT"] == '443')
55 || ($https && $_SERVER["SERVER_PORT"]==SSL_PORT) //Custom HTTPS port detection 55 || ($https && $_SERVER["SERVER_PORT"]==SSL_PORT) //Custom HTTPS port detection
56 ? '' : ':' . $_SERVER["SERVER_PORT"]); 56 ? '' : ':' . $_SERVER["SERVER_PORT"]);
57
58 if (isset($_SERVER["HTTP_X_FORWARDED_PORT"])) {
59 $serverport = ':' . $_SERVER["HTTP_X_FORWARDED_PORT"];
60 }
57 61
58 $scriptname = str_replace('/index.php', '/', $_SERVER["SCRIPT_NAME"]); 62 $scriptname = str_replace('/index.php', '/', $_SERVER["SCRIPT_NAME"]);
59 63
@@ -295,21 +299,6 @@ final class Tools
295 } 299 }
296 300
297 /** 301 /**
298 * Download the sqlite database
299 */
300 public static function downloadDb()
301 {
302 header('Content-Disposition: attachment; filename="poche.sqlite.gz"');
303 self::_status(200);
304
305 header('Content-Transfer-Encoding: binary');
306 header('Content-Type: application/octet-stream');
307 echo gzencode(file_get_contents(STORAGE_SQLITE));
308
309 exit;
310 }
311
312 /**
313 * Get the content for a given URL (by a call to FullTextFeed) 302 * Get the content for a given URL (by a call to FullTextFeed)
314 * 303 *
315 * @param Url $url 304 * @param Url $url
diff --git a/inc/poche/config.inc.default.php b/inc/poche/config.inc.default.php
index 6f03af18..2a458544 100755
--- a/inc/poche/config.inc.default.php
+++ b/inc/poche/config.inc.default.php
@@ -59,7 +59,7 @@
59@define ('LOCALE', ROOT . '/locale'); 59@define ('LOCALE', ROOT . '/locale');
60@define ('CACHE', ROOT . '/cache'); 60@define ('CACHE', ROOT . '/cache');
61 61
62@define ('PAGINATION', '10'); 62@define ('PAGINATION', '12');
63 63
64//limit for download of articles during import 64//limit for download of articles during import
65@define ('IMPORT_LIMIT', 5); 65@define ('IMPORT_LIMIT', 5);
diff --git a/inc/poche/pochePictures.php b/inc/poche/pochePictures.php
index 7a914f90..52394c70 100644
--- a/inc/poche/pochePictures.php
+++ b/inc/poche/pochePictures.php
@@ -33,7 +33,7 @@ final class Picture
33 } 33 }
34 34
35 if (self::_downloadPictures($absolute_path, $fullpath) === true) { 35 if (self::_downloadPictures($absolute_path, $fullpath) === true) {
36 $content = str_replace($matches[$i][2], $fullpath, $content); 36 $content = str_replace($matches[$i][2], Tools::getPocheUrl() . $fullpath, $content);
37 } 37 }
38 38
39 $processing_pictures[] = $absolute_path; 39 $processing_pictures[] = $absolute_path;