X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=inc%2Fpoche%2FPoche.class.php;h=8b0d3a19fad82d1a828772a82d88e591a98689f1;hb=c78c1a3f08815aab99752026ccdf1dcf63cf43c1;hp=c80e5d2a972e13bb6e7856fd4367395138d0a01b;hpb=4362417495b116b6bd4c3011187968f68f09430f;p=github%2Fwallabag%2Fwallabag.git diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index c80e5d2a..8b0d3a19 100755 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php @@ -74,12 +74,13 @@ class Poche /** * Creates a new user */ - public function createNewUser($username, $password) + public function createNewUser($username, $password, $email = "") { if (!empty($username) && !empty($password)){ $newUsername = filter_var($username, FILTER_SANITIZE_STRING); + $email = filter_var($email, FILTER_SANITIZE_STRING); if (!$this->store->userExists($newUsername)){ - if ($this->store->install($newUsername, Tools::encodeString($password . $newUsername))) { + if ($this->store->install($newUsername, Tools::encodeString($password . $newUsername), $email)) { Tools::logm('The new user ' . $newUsername . ' has been installed'); $this->messages->add('s', sprintf(_('The new user %s has been installed. Do you want to logout ?'), $newUsername)); Tools::redirect(); @@ -179,6 +180,13 @@ class Poche } } + // if there are tags, add them to the new article + if (isset($_GET['tags'])) { + $_POST['value'] = $_GET['tags']; + $_POST['entry_id'] = $last_id; + $this->action('add_tag', $url); + } + $this->messages->add('s', _('the link has been added successfully')); } else { @@ -193,18 +201,31 @@ class Poche } break; case 'delete': - $msg = 'delete link #' . $id; - if ($this->store->deleteById($id, $this->user->getId())) { - if (DOWNLOAD_PICTURES) { - Picture::removeDirectory(ABS_PATH . $id); + if (isset($_GET['search'])) { + //when we want to apply a delete to a search + $tags = array($_GET['search']); + $allentry_ids = $this->store->search($tags[0], $this->user->getId()); + $entry_ids = array(); + foreach ($allentry_ids as $eachentry) { + $entry_ids[] = $eachentry[0]; } - $this->messages->add('s', _('the link has been deleted successfully')); + } else { // delete a single article + $entry_ids = array($id); } - else { - $this->messages->add('e', _('the link wasn\'t deleted')); - $msg = 'error : can\'t delete link #' . $id; + foreach($entry_ids as $id) { + $msg = 'delete link #' . $id; + if ($this->store->deleteById($id, $this->user->getId())) { + if (DOWNLOAD_PICTURES) { + Picture::removeDirectory(ABS_PATH . $id); + } + $this->messages->add('s', _('the link has been deleted successfully')); + } + else { + $this->messages->add('e', _('the link wasn\'t deleted')); + $msg = 'error : can\'t delete link #' . $id; + } + Tools::logm($msg); } - Tools::logm($msg); Tools::redirect('?'); break; case 'toggle_fav' : @@ -219,8 +240,21 @@ class Poche } break; case 'toggle_archive' : - $this->store->archiveById($id, $this->user->getId()); - Tools::logm('archive link #' . $id); + if (isset($_GET['tag_id'])) { + //when we want to archive a whole tag + $tag_id = $_GET['tag_id']; + $allentry_ids = $this->store->retrieveEntriesByTag($tag_id, $this->user->getId()); + $entry_ids = array(); + foreach ($allentry_ids as $eachentry) { + $entry_ids[] = $eachentry[0]; + } + } else { //archive a single article + $entry_ids = array($id); + } + foreach($entry_ids as $id) { + $this->store->archiveById($id, $this->user->getId()); + Tools::logm('archive link #' . $id); + } if ( Tools::isAjaxRequest() ) { echo 1; exit; @@ -313,6 +347,8 @@ class Poche switch ($view) { + case 'about': + break; case 'config': $dev_infos = $this->_getPocheVersion('dev'); $dev = trim($dev_infos[0]); @@ -387,7 +423,7 @@ class Poche $this->pagination->page_links('?view=' . $view . '?search=' . $search . '&sort=' . $_SESSION['sort'] . '&' )); $tpl_vars['page_links'] = $page_links; $tpl_vars['nb_results'] = $count; - $tpl_vars['search_term'] = $search; + $tpl_vars['searchterm'] = $search; } break; case 'view': @@ -402,9 +438,12 @@ class Poche } # flattr checking - $flattr = new FlattrItem(); - $flattr->checkItem($entry['url'], $entry['id']); - + $flattr = NULL; + if (FLATTR) { + $flattr = new FlattrItem(); + $flattr->checkItem($entry['url'], $entry['id']); + } + # tags $tags = $this->store->retrieveTagsByEntry($entry['id']); @@ -537,6 +576,8 @@ class Poche Tools::redirect($referer); } $this->messages->add('e', _('login failed: bad login or password')); + // log login failure in web server log to allow fail2ban usage + error_log('user '.$login.' authentication failure'); Tools::logm('login failed'); Tools::redirect(); } @@ -745,10 +786,11 @@ class Poche * * @param $token * @param $user_id - * @param $tag_id - * @param string $type + * @param $tag_id if $type is 'tag', the id of the tag to generate feed for + * @param string $type the type of feed to generate + * @param int $limit the maximum number of items (0 means all) */ - public function generateFeeds($token, $user_id, $tag_id, $type = 'home') + public function generateFeeds($token, $user_id, $tag_id, $type = 'home', $limit = 0) { $allowed_types = array('home', 'fav', 'archive', 'tag'); $config = $this->store->getConfigUser($user_id); @@ -775,8 +817,13 @@ class Poche $entries = $this->store->getEntriesByView($type, $user_id); } + // if $limit is set to zero, use all entries + if (0 == $limit) { + $limit = count($entries); + } if (count($entries) > 0) { - foreach ($entries as $entry) { + for ($i = 0; $i < min(count($entries), $limit); $i++) { + $entry = $entries[$i]; $newItem = $feed->createNewItem(); $newItem->setTitle($entry['title']); $newItem->setSource(Tools::getPocheUrl() . '?view=view&id=' . $entry['id']);