diff options
Diffstat (limited to 'inc/poche/Poche.class.php')
-rw-r--r-- | inc/poche/Poche.class.php | 40 |
1 files changed, 29 insertions, 11 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(); |