);
}
+ 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.)
*/
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'];
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);
+ $this->action('toggle_fav', $url, $last_id, TRUE);
+ }
+ if ($archive) {
+ $last_id = $this->store->getLastId($sequence);
+ $this->action('toggle_archive', $url, $last_id, TRUE);
+ }
+ }
+
+ }
+ $this->messages->add('s', _('import from Poche completed. ' . $count . ' new links.'));
+ Tools::logm('import from Poche completed');
+ Tools::redirect();
+ }
+
/**
* import datas into your poche
* @param string $from name of the service to import : pocket, instapaper or readability
$providers = array(
'pocket' => 'importFromPocket',
'readability' => 'importFromReadability',
- 'instapaper' => 'importFromInstapaper'
+ 'instapaper' => 'importFromInstapaper',
+ 'poche' => 'importFromPoche',
);
if (! isset($providers[$from])) {