From c765c3679fee3ed9e4bad9954a808116187a7e83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Sun, 4 Aug 2013 21:42:46 +0200 Subject: import in poche and not in an external file --- inc/poche/Poche.class.php | 108 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 107 insertions(+), 1 deletion(-) (limited to 'inc/poche/Poche.class.php') diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index 973ae3e2..9e407d41 100644 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php @@ -73,7 +73,7 @@ class Poche /** * Call action (mark as fav, archive, delete, etc.) */ - public function action($action, Url $url, $id) + public function action($action, Url $url, $id = 0) { switch ($action) { @@ -118,6 +118,8 @@ class Poche $this->store->archiveById($id); Tools::logm('archive link #' . $id); break; + case 'import': + break; default: break; } @@ -173,4 +175,108 @@ class Poche return $tpl_vars; } + + public function updatePassword() + { + if (isset($_POST['password']) && isset($_POST['password_repeat'])) { + if ($_POST['password'] == $_POST['password_repeat'] && $_POST['password'] != "") { + if (!MODE_DEMO) { + Tools::logm('password updated'); + $this->store->updatePassword(Tools::encodeString($_POST['password'] . $_SESSION['login'])); + Session::logout(); + Tools::redirect(); + } + else { + Tools::logm('in demo mode, you can\'t do this'); + } + } + } + } + + public function login($referer) + { + if (!empty($_POST['login']) && !empty($_POST['password'])) { + if (Session::login($_SESSION['login'], $_SESSION['pass'], $_POST['login'], Tools::encodeString($_POST['password'] . $_POST['login']))) { + Tools::logm('login successful'); + + if (!empty($_POST['longlastingsession'])) { + $_SESSION['longlastingsession'] = 31536000; + $_SESSION['expires_on'] = time() + $_SESSION['longlastingsession']; + session_set_cookie_params($_SESSION['longlastingsession']); + } else { + session_set_cookie_params(0); + } + session_regenerate_id(true); + Tools::redirect($referer); + } + Tools::logm('login failed'); + Tools::redirect(); + } else { + Tools::logm('login failed'); + Tools::redirect(); + } + } + + public function logout() + { + Tools::logm('logout'); + Session::logout(); + Tools::redirect(); + } + + public function import($from) + { + if ($from == 'pocket') { + $html = new simple_html_dom(); + $html->load_file('./ril_export.html'); + + $read = 0; + $errors = array(); + foreach($html->find('ul') as $ul) + { + foreach($ul->find('li') as $li) + { + $a = $li->find('a'); + $url = new Url($a[0]->href); + $this->action('add', $url); + if ($read == '1') { + $last_id = $this->store->lastInsertId(); + $sql_update = "UPDATE entries SET is_read=~is_read WHERE id=?"; + $params_update = array($last_id); + $query_update = $this->store->prepare($sql_update); + $query_update->execute($params_update); + } + } + # Pocket génère un fichier HTML avec deux