aboutsummaryrefslogtreecommitdiffhomepage
path: root/inc/poche
diff options
context:
space:
mode:
authorNicolas LÅ“uillet <nicolas.loeuillet@gmail.com>2013-08-05 21:56:32 +0200
committerNicolas LÅ“uillet <nicolas.loeuillet@gmail.com>2013-08-05 21:56:32 +0200
commit6a361945eaf86a978b82bd6fb3442fe64428d9df (patch)
treeab7e2cff6301b22e5e54ce0321b13502806d7546 /inc/poche
parent55821e04c188997d258645975220828e195d0df4 (diff)
downloadwallabag-6a361945eaf86a978b82bd6fb3442fe64428d9df.tar.gz
wallabag-6a361945eaf86a978b82bd6fb3442fe64428d9df.tar.zst
wallabag-6a361945eaf86a978b82bd6fb3442fe64428d9df.zip
new design, pagination & more
Diffstat (limited to 'inc/poche')
-rw-r--r--inc/poche/Poche.class.php40
-rw-r--r--inc/poche/Tools.class.php2
-rw-r--r--inc/poche/config.inc.php12
3 files changed, 37 insertions, 17 deletions
diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php
index 80bf6919..789d6647 100644
--- a/inc/poche/Poche.class.php
+++ b/inc/poche/Poche.class.php
@@ -13,11 +13,13 @@ class Poche
13 public $store; 13 public $store;
14 public $tpl; 14 public $tpl;
15 public $messages; 15 public $messages;
16 public $pagination;
16 17
17 function __construct($storage_type) 18 function __construct($storage_type)
18 { 19 {
19 $this->store = new $storage_type(); 20 $this->store = new $storage_type();
20 $this->init(); 21 $this->init();
22 $this->messages = new Messages();
21 23
22 # installation 24 # installation
23 if(!$this->store->isInstalled()) 25 if(!$this->store->isInstalled())
@@ -46,6 +48,8 @@ class Poche
46 $filter = new Twig_SimpleFilter('getDomain', 'Tools::getDomain'); 48 $filter = new Twig_SimpleFilter('getDomain', 'Tools::getDomain');
47 $this->tpl->addFilter($filter); 49 $this->tpl->addFilter($filter);
48 50
51 $this->pagination = new Paginator(PAGINATION, 'p');
52
49 Tools::initPhp(); 53 Tools::initPhp();
50 Session::init(); 54 Session::init();
51 } 55 }
@@ -54,7 +58,7 @@ class Poche
54 { 58 {
55 Tools::logm('poche still not installed'); 59 Tools::logm('poche still not installed');
56 echo $this->tpl->render('install.twig', array( 60 echo $this->tpl->render('install.twig', array(
57 'token' => Session::getToken(), 61 'token' => Session::getToken()
58 )); 62 ));
59 if (isset($_GET['install'])) { 63 if (isset($_GET['install'])) {
60 if (($_POST['password'] == $_POST['password_repeat']) 64 if (($_POST['password'] == $_POST['password_repeat'])
@@ -62,6 +66,11 @@ class Poche
62 # let's rock, install poche baby ! 66 # let's rock, install poche baby !
63 $this->store->install($_POST['login'], Tools::encodeString($_POST['password'] . $_POST['login'])); 67 $this->store->install($_POST['login'], Tools::encodeString($_POST['password'] . $_POST['login']));
64 Session::logout(); 68 Session::logout();
69 Tools::logm('poche is now installed');
70 Tools::redirect();
71 }
72 else {
73 Tools::logm('error during installation');
65 Tools::redirect(); 74 Tools::redirect();
66 } 75 }
67 } 76 }
@@ -89,30 +98,32 @@ class Poche
89 if (DOWNLOAD_PICTURES) { 98 if (DOWNLOAD_PICTURES) {
90 $content = filtre_picture($parametres_url['content'], $url->getUrl(), $last_id); 99 $content = filtre_picture($parametres_url['content'], $url->getUrl(), $last_id);
91 } 100 }
92 #$msg->add('s', _('the link has been added successfully')); 101 $this->messages->add('s', _('the link has been added successfully'));
93 } 102 }
94 else { 103 else {
95 #$msg->add('e', _('error during insertion : the link wasn\'t added')); 104 $this->messages->add('e', _('error during insertion : the link wasn\'t added'));
96 Tools::logm('error during insertion : the link wasn\'t added'); 105 Tools::logm('error during insertion : the link wasn\'t added');
97 } 106 }
98 } 107 }
99 else { 108 else {
100 #$msg->add('e', _('error during url preparation : the link wasn\'t added')); 109 $this->messages->add('e', _('error during fetching content : the link wasn\'t added'));
101 Tools::logm('error during content fetch'); 110 Tools::logm('error during content fetch');
102 } 111 }
112 Tools::redirect();
103 break; 113 break;
104 case 'delete': 114 case 'delete':
105 if ($this->store->deleteById($id)) { 115 if ($this->store->deleteById($id)) {
106 if (DOWNLOAD_PICTURES) { 116 if (DOWNLOAD_PICTURES) {
107 remove_directory(ABS_PATH . $id); 117 remove_directory(ABS_PATH . $id);
108 } 118 }
109 #$msg->add('s', _('the link has been deleted successfully')); 119 $this->messages->add('s', _('the link has been deleted successfully'));
110 Tools::logm('delete link #' . $id); 120 Tools::logm('delete link #' . $id);
111 } 121 }
112 else { 122 else {
113 #$msg->add('e', _('the link wasn\'t deleted')); 123 $this->messages->add('e', _('the link wasn\'t deleted'));
114 Tools::logm('error : can\'t delete link #' . $id); 124 Tools::logm('error : can\'t delete link #' . $id);
115 } 125 }
126 Tools::redirect();
116 break; 127 break;
117 case 'toggle_fav' : 128 case 'toggle_fav' :
118 $this->store->favoriteById($id); 129 $this->store->favoriteById($id);
@@ -169,9 +180,14 @@ class Poche
169 break; 180 break;
170 default: # home view 181 default: # home view
171 $entries = $this->store->getEntriesByView($view); 182 $entries = $this->store->getEntriesByView($view);
183 $this->pagination->set_total(count($entries));
184 $page_links = $this->pagination->page_links('?view=' . $view . '&sort=' . $_SESSION['sort'] . '&');
185 $datas = $this->store->getEntriesByView($view, $this->pagination->get_limit());
172 $tpl_vars = array( 186 $tpl_vars = array(
173 'entries' => $entries, 187 'entries' => $datas,
188 'page_links' => $page_links,
174 ); 189 );
190 Tools::logm('display ' . $view . ' view');
175 break; 191 break;
176 } 192 }
177 193
@@ -183,6 +199,7 @@ class Poche
183 if (MODE_DEMO) { 199 if (MODE_DEMO) {
184 $this->messages->add('i', 'in demo mode, you can\'t update your password'); 200 $this->messages->add('i', 'in demo mode, you can\'t update your password');
185 Tools::logm('in demo mode, you can\'t do this'); 201 Tools::logm('in demo mode, you can\'t do this');
202 Tools::redirect('?view=config');
186 } 203 }
187 else { 204 else {
188 if (isset($_POST['password']) && isset($_POST['password_repeat'])) { 205 if (isset($_POST['password']) && isset($_POST['password_repeat'])) {
@@ -195,6 +212,7 @@ class Poche
195 } 212 }
196 else { 213 else {
197 $this->messages->add('e', 'the two fields have to be filled & the password must be the same in the two fields'); 214 $this->messages->add('e', 'the two fields have to be filled & the password must be the same in the two fields');
215 Tools::redirect('?view=config');
198 } 216 }
199 } 217 }
200 } 218 }
@@ -205,7 +223,7 @@ class Poche
205 if (!empty($_POST['login']) && !empty($_POST['password'])) { 223 if (!empty($_POST['login']) && !empty($_POST['password'])) {
206 if (Session::login($_SESSION['login'], $_SESSION['pass'], $_POST['login'], Tools::encodeString($_POST['password'] . $_POST['login']))) { 224 if (Session::login($_SESSION['login'], $_SESSION['pass'], $_POST['login'], Tools::encodeString($_POST['password'] . $_POST['login']))) {
207 Tools::logm('login successful'); 225 Tools::logm('login successful');
208 $this->messages->add('s', 'login successful, welcome to your poche'); 226 $this->messages->add('s', 'welcome to your poche');
209 if (!empty($_POST['longlastingsession'])) { 227 if (!empty($_POST['longlastingsession'])) {
210 $_SESSION['longlastingsession'] = 31536000; 228 $_SESSION['longlastingsession'] = 31536000;
211 $_SESSION['expires_on'] = time() + $_SESSION['longlastingsession']; 229 $_SESSION['expires_on'] = time() + $_SESSION['longlastingsession'];
@@ -216,11 +234,11 @@ class Poche
216 session_regenerate_id(true); 234 session_regenerate_id(true);
217 Tools::redirect($referer); 235 Tools::redirect($referer);
218 } 236 }
219 $this->messages->add('e', 'login failed, bad login or password'); 237 $this->messages->add('e', 'login failed: bad login or password');
220 Tools::logm('login failed'); 238 Tools::logm('login failed');
221 Tools::redirect(); 239 Tools::redirect();
222 } else { 240 } else {
223 $this->messages->add('e', 'login failed, you have to fill all fields'); 241 $this->messages->add('e', 'login failed: you have to fill all fields');
224 Tools::logm('login failed'); 242 Tools::logm('login failed');
225 Tools::redirect(); 243 Tools::redirect();
226 } 244 }
@@ -228,7 +246,7 @@ class Poche
228 246
229 public function logout() 247 public function logout()
230 { 248 {
231 $this->messages->add('s', 'logout successful, see you soon!'); 249 $this->messages->add('s', 'see you soon!');
232 Tools::logm('logout'); 250 Tools::logm('logout');
233 Session::logout(); 251 Session::logout();
234 Tools::redirect(); 252 Tools::redirect();
diff --git a/inc/poche/Tools.class.php b/inc/poche/Tools.class.php
index 7bc8830a..8b339ea5 100644
--- a/inc/poche/Tools.class.php
+++ b/inc/poche/Tools.class.php
@@ -197,7 +197,7 @@ class Tools
197 { 197 {
198 if (DEBUG_POCHE) { 198 if (DEBUG_POCHE) {
199 $t = strval(date('Y/m/d_H:i:s')) . ' - ' . $_SERVER["REMOTE_ADDR"] . ' - ' . strval($message) . "\n"; 199 $t = strval(date('Y/m/d_H:i:s')) . ' - ' . $_SERVER["REMOTE_ADDR"] . ' - ' . strval($message) . "\n";
200 file_put_contents('./log.txt', $t, FILE_APPEND); 200 file_put_contents(CACHE . '/log.txt', $t, FILE_APPEND);
201 } 201 }
202 } 202 }
203 203
diff --git a/inc/poche/config.inc.php b/inc/poche/config.inc.php
index d49df190..d91a44be 100644
--- a/inc/poche/config.inc.php
+++ b/inc/poche/config.inc.php
@@ -8,7 +8,7 @@
8 * @license http://www.wtfpl.net/ see COPYING file 8 * @license http://www.wtfpl.net/ see COPYING file
9 */ 9 */
10 10
11define ('POCHE_VERSION', '1.0-alpha'); 11define ('POCHE_VERSION', '1.0-beta');
12define ('MODE_DEMO', FALSE); 12define ('MODE_DEMO', FALSE);
13define ('DEBUG_POCHE', FALSE); 13define ('DEBUG_POCHE', FALSE);
14define ('CONVERT_LINKS_FOOTNOTES', FALSE); 14define ('CONVERT_LINKS_FOOTNOTES', FALSE);
@@ -22,24 +22,26 @@ define ('TPL', './tpl');
22define ('LOCALE', './locale'); 22define ('LOCALE', './locale');
23define ('CACHE', './cache'); 23define ('CACHE', './cache');
24define ('LANG', 'fr_FR.UTF8'); 24define ('LANG', 'fr_FR.UTF8');
25define ('PAGINATION', '10');
26define ('THEME', 'light');
25$storage_type = 'sqlite'; # sqlite, mysql, (file, not yet) 27$storage_type = 'sqlite'; # sqlite, mysql, (file, not yet)
26 28
27# /!\ Be careful if you change the lines below /!\ 29# /!\ Be careful if you change the lines below /!\
28require_once './inc/poche/Tools.class.php'; 30require_once './inc/poche/Tools.class.php';
29require_once './inc/poche/Url.class.php'; 31require_once './inc/poche/Url.class.php';
32require_once './inc/3rdparty/Session.class.php';
33require_once './inc/3rdparty/class.messages.php';
30require_once './inc/poche/Poche.class.php'; 34require_once './inc/poche/Poche.class.php';
31require_once './inc/3rdparty/Readability.php'; 35require_once './inc/3rdparty/Readability.php';
32require_once './inc/3rdparty/Encoding.php'; 36require_once './inc/3rdparty/Encoding.php';
33require_once './inc/3rdparty/Session.class.php';
34require_once './inc/store/store.class.php'; 37require_once './inc/store/store.class.php';
35require_once './inc/store/' . $storage_type . '.class.php'; 38require_once './inc/store/' . $storage_type . '.class.php';
36require_once './vendor/autoload.php'; 39require_once './vendor/autoload.php';
37require_once './inc/3rdparty/simple_html_dom.php'; 40require_once './inc/3rdparty/simple_html_dom.php';
38require_once './inc/3rdparty/class.messages.php'; 41require_once './inc/3rdparty/paginator.php';
39 42
40if (DOWNLOAD_PICTURES) { 43if (DOWNLOAD_PICTURES) {
41 require_once './inc/poche/pochePictures.php'; 44 require_once './inc/poche/pochePictures.php';
42} 45}
43 46
44$poche = new Poche($storage_type); 47$poche = new Poche($storage_type); \ No newline at end of file
45$poche->messages = new Messages(); \ No newline at end of file