X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=inc%2Fpoche%2FPoche.class.php;h=004cca8e558ed0092ce6b20b970eec386e88c6a2;hb=f878daeb8bc9245a294677e4ac141f8bd37c2b4f;hp=adec9b288714c4424d59bf1d1289c0349a578c59;hpb=a0aa150418b628b32b18c70436d6be495129ee38;p=github%2Fwallabag%2Fwallabag.git diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index adec9b28..004cca8e 100644 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php @@ -49,6 +49,7 @@ class Poche if (! $this->store->isInstalled()) { $this->install(); } + $this->store->checkTags(); } } @@ -324,6 +325,22 @@ 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.) */ @@ -332,8 +349,7 @@ class Poche switch ($action) { case 'add': - $json = file_get_contents(Tools::getPocheUrl() . '/inc/3rdparty/makefulltextfeed.php?url='.urlencode($url->getUrl()).'&max=5&links=preserve&exc=&format=json&submit=Create+Feed'); - $content = json_decode($json, true); + $content = $this->getPageContent($url); $title = $content['rss']['channel']['item']['title']; $body = $content['rss']['channel']['item']['description']; @@ -446,7 +462,7 @@ class Poche $themes = $this->getInstalledThemes(); $languages = $this->getInstalledLanguages(); $token = $this->user->getConfigValue('token'); - $http_auth = (isset($_SERVER['PHP_AUTH_USER']))?true:false; + $http_auth = (isset($_SERVER['PHP_AUTH_USER']) || isset($_SERVER['REMOTE_USER'])) ? true : false; $tpl_vars = array( 'themes' => $themes, 'languages' => $languages, @@ -649,14 +665,18 @@ class Poche * it redirects the user to the $referer link * @return array */ - private function credentials() { - if(isset($_SERVER['PHP_AUTH_USER'])) { - return array($_SERVER['PHP_AUTH_USER'],'php_auth'); - } - if(!empty($_POST['login']) && !empty($_POST['password'])) { - return array($_POST['login'],$_POST['password']); - } - return array(false,false); + private function credentials() { + if(isset($_SERVER['PHP_AUTH_USER'])) { + return array($_SERVER['PHP_AUTH_USER'],'php_auth'); + } + if(!empty($_POST['login']) && !empty($_POST['password'])) { + return array($_POST['login'],$_POST['password']); + } + if(isset($_SERVER['REMOTE_USER'])) { + return array($_SERVER['REMOTE_USER'],'http_auth'); + } + + return array(false,false); } /** @@ -801,26 +821,74 @@ class Poche $url = NULL; $favorite = FALSE; $archive = FALSE; - foreach ($value as $attr => $attr_value) { - if ($attr == 'article__url') { - $url = new Url(base64_encode($attr_value)); - } - $sequence = ''; - if (STORAGE == 'postgres') { - $sequence = 'entries_id_seq'; + foreach ($value as $item) { + foreach ($item as $attr => $value) { + if ($attr == 'article__url') { + $url = new Url(base64_encode($value)); + } + $sequence = ''; + if (STORAGE == 'postgres') { + $sequence = 'entries_id_seq'; + } + if ($value == 'true') { + if ($attr == 'favorite') { + $favorite = TRUE; + } + if ($attr == 'archive') { + $archive = TRUE; + } + } } - if ($attr_value == 'true') { - if ($attr == 'favorite') { - $favorite = TRUE; + + # we can add the url + if (!is_null($url) && $url->isCorrect()) { + $this->action('add', $url, 0, TRUE); + $count++; + if ($favorite) { + $last_id = $this->store->getLastId($sequence); + $this->action('toggle_fav', $url, $last_id, TRUE); } - if ($attr == 'archive') { - $archive = TRUE; + if ($archive) { + $last_id = $this->store->getLastId($sequence); + $this->action('toggle_archive', $url, $last_id, TRUE); } } } + } + $this->messages->add('s', _('import from Readability completed. ' . $count . ' new links.')); + Tools::logm('import from Readability completed'); + Tools::redirect(); + } + + /** + * import from Poche exported file + * @param string $targetFile the file used for importing + * @return boolean + */ + private function importFromPoche($targetFile) + { + $str_data = file_get_contents($targetFile); + $data = json_decode($str_data,true); + Tools::logm('starting import from Poche'); + + + $sequence = ''; + if (STORAGE == 'postgres') { + $sequence = 'entries_id_seq'; + } + + $count = 0; + foreach ($data as $value) { + + $url = new Url(base64_encode($value['url'])); + $favorite = ($value['is_fav'] == -1); + $archive = ($value['is_read'] == -1); + # we can add the url if (!is_null($url) && $url->isCorrect()) { + $this->action('add', $url, 0, TRUE); + $count++; if ($favorite) { $last_id = $this->store->getLastId($sequence); @@ -831,9 +899,10 @@ class Poche $this->action('toggle_archive', $url, $last_id, TRUE); } } + } - $this->messages->add('s', _('import from Readability completed. ' . $count . ' new links.')); - Tools::logm('import from Readability completed'); + $this->messages->add('s', _('import from Poche completed. ' . $count . ' new links.')); + Tools::logm('import from Poche completed'); Tools::redirect(); } @@ -848,7 +917,8 @@ class Poche $providers = array( 'pocket' => 'importFromPocket', 'readability' => 'importFromReadability', - 'instapaper' => 'importFromInstapaper' + 'instapaper' => 'importFromInstapaper', + 'poche' => 'importFromPoche', ); if (! isset($providers[$from])) { @@ -946,7 +1016,7 @@ class Poche if (count($entries) > 0) { foreach ($entries as $entry) { $newItem = $feed->createNewItem(); - $newItem->setTitle(htmlentities($entry['title'])); + $newItem->setTitle($entry['title']); $newItem->setLink(Tools::getPocheUrl() . '?view=view&id=' . $entry['id']); $newItem->setDate(time()); $newItem->setDescription($entry['content']);