X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=inc%2Fpoche%2FPoche.class.php;h=7d9faed14e386d04391891d3ea3c8ee3890bfe56;hb=ad697686c00432964528226588a8cbea909c9e36;hp=b6b3b73f5bb51d5d2b5cf04e15a8ab853a169f24;hpb=926acd7bba2780009eb5abec7bbf71a08b2ef1bf;p=github%2Fwallabag%2Fwallabag.git diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php old mode 100644 new mode 100755 index b6b3b73f..7d9faed1 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php @@ -23,6 +23,20 @@ class Poche private $currentLanguage = ''; private $notInstalledMessage = array(); + private $language_names = array( + 'cs_CZ.utf8' => 'čeština', + 'de_DE.utf8' => 'German', + 'en_EN.utf8' => 'English', + 'es_ES.utf8' => 'Español', + 'fa_IR.utf8' => 'فارسی', + 'fr_FR.utf8' => 'Français', + 'it_IT.utf8' => 'Italiano', + 'pl_PL.utf8' => 'Polski', + 'pt_BR.utf8' => 'Português (Brasil)', + 'ru_RU.utf8' => 'Pусский', + 'sl_SI.utf8' => 'Slovenščina', + 'uk_UA.utf8' => 'Українська', + ); public function __construct() { if ($this->configFileIsAvailable()) { @@ -47,8 +61,6 @@ class Poche private function init() { Tools::initPhp(); - Session::$sessionName = 'poche'; - Session::init(); if (isset($_SESSION['poche_user']) && $_SESSION['poche_user'] != array()) { $this->user = $_SESSION['poche_user']; @@ -307,6 +319,8 @@ class Poche $themes[$theme] = $this->getThemeInfo($theme); } + ksort($themes); + return $themes; } @@ -321,7 +335,7 @@ class Poche while (($language = readdir($handle)) !== false) { # Languages are stored in a directory, so all directory names are languages # @todo move language installation data to database - if (! is_dir(LOCALE . '/' . $language) || in_array($language, array('..', '.'))) { + if (! is_dir(LOCALE . '/' . $language) || in_array($language, array('..', '.', 'tools'))) { continue; } @@ -331,7 +345,7 @@ class Poche $current = true; } - $languages[] = array('name' => $language, 'current' => $current); + $languages[] = array('name' => (isset($this->language_names[$language]) ? $this->language_names[$language] : $language), 'value' => $language, 'current' => $current); } return $languages; @@ -346,22 +360,6 @@ class Poche ); } - protected function getPageContent(Url $url) - { - $options = array('http' => array('user_agent' => 'poche')); - if (isset($_SERVER['AUTH_TYPE']) && "basic" === strtolower($_SERVER['AUTH_TYPE'])) { - $options['http']['header'] = sprintf( - "Authorization: Basic %s", - base64_encode( - sprintf('%s:%s', $_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']) - ) - ); - } - $context = stream_context_create($options); - $json = file_get_contents(Tools::getPocheUrl() . '/inc/3rdparty/makefulltextfeed.php?url='.urlencode($url->getUrl()).'&max=5&links=preserve&exc=&format=json&submit=Create+Feed', false, $context); - return json_decode($json, true); - } - /** * Call action (mark as fav, archive, delete, etc.) */ @@ -370,11 +368,25 @@ class Poche switch ($action) { case 'add': - $content = $this->getPageContent($url); - $title = ($content['rss']['channel']['item']['title'] != '') ? $content['rss']['channel']['item']['title'] : _('Untitled'); - $body = $content['rss']['channel']['item']['description']; + if (!$import) { + $content = Tools::getPageContent($url); + $title = ($content['rss']['channel']['item']['title'] != '') ? $content['rss']['channel']['item']['title'] : _('Untitled'); + $body = $content['rss']['channel']['item']['description']; + + // clean content from prevent xss attack + $config = HTMLPurifier_Config::createDefault(); + $config->set('Cache.SerializerPath', CACHE); + $purifier = new HTMLPurifier($config); + $title = $purifier->purify($title); + $body = $purifier->purify($body); + } + else { + $title = ''; + $body = ''; + } //search for possible duplicate if not in import mode + $duplicate = NULL; if (!$import) { $duplicate = $this->store->retrieveOneByURL($url->getUrl(), $this->user->getId()); } @@ -475,25 +487,33 @@ class Poche Tools::logm('error : article not found'); Tools::redirect(); } + //get all already set tags to preven duplicates + $already_set_tags = array(); + $entry_tags = $this->store->retrieveTagsByEntry($entry_id); + foreach ($entry_tags as $tag) { + $already_set_tags[] = $tag['value']; + } foreach($tags as $key => $tag_value) { $value = trim($tag_value); - $tag = $this->store->retrieveTagByValue($value); - - if (is_null($tag)) { - # we create the tag - $tag = $this->store->createTag($value); - $sequence = ''; - if (STORAGE == 'postgres') { - $sequence = 'tags_id_seq'; - } - $tag_id = $this->store->getLastId($sequence); + if ($value && !in_array($value, $already_set_tags)) { + $tag = $this->store->retrieveTagByValue($value); + + if (is_null($tag)) { + # we create the tag + $tag = $this->store->createTag($value); + $sequence = ''; + if (STORAGE == 'postgres') { + $sequence = 'tags_id_seq'; + } + $tag_id = $this->store->getLastId($sequence); + } + else { + $tag_id = $tag['id']; + } + + # we assign the tag to the article + $this->store->setTagToEntry($tag_id, $entry_id); } - else { - $tag_id = $tag['id']; - } - - # we assign the tag to the article - $this->store->setTagToEntry($tag_id, $entry_id); } if(!$import) { Tools::redirect(); @@ -522,8 +542,12 @@ class Poche switch ($view) { case 'config': - $dev = trim($this->getPocheVersion('dev')); - $prod = trim($this->getPocheVersion('prod')); + $dev_infos = $this->getPocheVersion('dev'); + $dev = trim($dev_infos[0]); + $check_time_dev = date('d-M-Y H:i', $dev_infos[1]); + $prod_infos = $this->getPocheVersion('prod'); + $prod = trim($prod_infos[0]); + $check_time_prod = date('d-M-Y H:i', $prod_infos[1]); $compare_dev = version_compare(POCHE, $dev); $compare_prod = version_compare(POCHE, $prod); $themes = $this->getInstalledThemes(); @@ -535,6 +559,8 @@ class Poche 'languages' => $languages, 'dev' => $dev, 'prod' => $prod, + 'check_time_dev' => $check_time_dev, + 'check_time_prod' => $check_time_prod, 'compare_dev' => $compare_dev, 'compare_prod' => $compare_prod, 'token' => $token, @@ -555,25 +581,36 @@ class Poche $tpl_vars = array( 'entry_id' => $id, 'tags' => $tags, - ); - break; - case 'tag': - $entries = $this->store->retrieveEntriesByTag($id, $this->user->getId()); - $tag = $this->store->retrieveTag($id, $this->user->getId()); - $tpl_vars = array( - 'tag' => $tag, - 'entries' => $entries, + 'entry' => $entry, ); break; case 'tags': $token = $this->user->getConfigValue('token'); - $tags = $this->store->retrieveAllTags($this->user->getId()); + //if term is set - search tags for this term + $term = Tools::checkVar('term'); + $tags = $this->store->retrieveAllTags($this->user->getId(), $term); + if (Tools::isAjaxRequest()) { + $result = array(); + foreach ($tags as $tag) { + $result[] = $tag['value']; + } + echo json_encode($result); + exit; + } $tpl_vars = array( 'token' => $token, 'user_id' => $this->user->getId(), 'tags' => $tags, ); break; + + case 'search': + if (isset($_GET['search'])){ + $search = $_GET['search']; + $tpl_vars['entries'] = $this->store->search($search); + $tpl_vars['nb_results'] = count($tpl_vars['entries']); + } + break; case 'view': $entry = $this->store->retrieveOneById($id, $this->user->getId()); if ($entry != NULL) { @@ -603,22 +640,29 @@ class Poche Tools::logm('error in view call : entry is null'); } break; - default: # home, favorites and archive views - $entries = $this->store->getEntriesByView($view, $this->user->getId()); + default: # home, favorites, archive and tag views $tpl_vars = array( 'entries' => '', 'page_links' => '', 'nb_results' => '', + 'listmode' => (isset($_COOKIE['listmode']) ? true : false), ); - if (count($entries) > 0) { - $this->pagination->set_total(count($entries)); + //if id is given - we retrive entries by tag: id is tag id + if ($id) { + $tpl_vars['tag'] = $this->store->retrieveTag($id, $this->user->getId()); + $tpl_vars['id'] = intval($id); + } + + $count = $this->store->getEntriesByViewCount($view, $this->user->getId(), $id); + + if ($count > 0) { + $this->pagination->set_total($count); $page_links = str_replace(array('previous', 'next'), array(_('previous'), _('next')), - $this->pagination->page_links('?view=' . $view . '&sort=' . $_SESSION['sort'] . '&')); - $datas = $this->store->getEntriesByView($view, $this->user->getId(), $this->pagination->get_limit()); - $tpl_vars['entries'] = $datas; + $this->pagination->page_links('?view=' . $view . '&sort=' . $_SESSION['sort'] . (($id)?'&id='.$id:'') . '&' )); + $tpl_vars['entries'] = $this->store->getEntriesByView($view, $this->user->getId(), $this->pagination->get_limit(), $id); $tpl_vars['page_links'] = $page_links; - $tpl_vars['nb_results'] = count($entries); + $tpl_vars['nb_results'] = $count; } Tools::logm('display ' . $view . ' view'); break; @@ -692,6 +736,8 @@ class Poche $currentConfig['theme'] = $_POST['theme']; $_SESSION['poche_user']->setConfig($currentConfig); + + $this->emptyCache(); Tools::redirect('?view=config'); } @@ -712,7 +758,7 @@ class Poche $actualLanguage = false; foreach ($languages as $language) { - if ($language['name'] == $_POST['language']) { + if ($language['value'] == $_POST['language']) { $actualLanguage = true; break; } @@ -730,10 +776,11 @@ class Poche $currentConfig['language'] = $_POST['language']; $_SESSION['poche_user']->setConfig($currentConfig); + + $this->emptyCache(); Tools::redirect('?view=config'); - } - + } /** * get credentials from differents sources * it redirects the user to the $referer link @@ -833,7 +880,9 @@ class Poche # the second
    is for read links $read = 1; } - $this->messages->add('s', _('import from instapaper completed')); + + $unlink = unlink($targetFile); + $this->messages->add('s', _('import from instapaper completed. You have to execute the cron to fetch content.')); Tools::logm('import from instapaper completed'); Tools::redirect(); } @@ -877,7 +926,9 @@ class Poche # the second