aboutsummaryrefslogtreecommitdiffhomepage
path: root/inc/poche/Poche.class.php
diff options
context:
space:
mode:
authorNicolas LÅ“uillet <nicolas.loeuillet@gmail.com>2013-12-23 02:28:56 -0800
committerNicolas LÅ“uillet <nicolas.loeuillet@gmail.com>2013-12-23 02:28:56 -0800
commit60fc4f4b1ab37fbfe9021f3fa1395d66a4424ed2 (patch)
tree515c4b9c8286ae363f77722c91acb878151dc386 /inc/poche/Poche.class.php
parentcbfd5a1019f47fadefd8490dae9f039ae894298d (diff)
parentda5fc42f615eeb45a702604970f94967507fb432 (diff)
downloadwallabag-60fc4f4b1ab37fbfe9021f3fa1395d66a4424ed2.tar.gz
wallabag-60fc4f4b1ab37fbfe9021f3fa1395d66a4424ed2.tar.zst
wallabag-60fc4f4b1ab37fbfe9021f3fa1395d66a4424ed2.zip
Merge pull request #363 from inthepoche/dev1.3.0
poche 1.3.0
Diffstat (limited to 'inc/poche/Poche.class.php')
-rw-r--r--inc/poche/Poche.class.php159
1 files changed, 142 insertions, 17 deletions
diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php
index 3ecaf084..4f70afb7 100644
--- a/inc/poche/Poche.class.php
+++ b/inc/poche/Poche.class.php
@@ -49,6 +49,7 @@ class Poche
49 if (! $this->store->isInstalled()) { 49 if (! $this->store->isInstalled()) {
50 $this->install(); 50 $this->install();
51 } 51 }
52 $this->store->checkTags();
52 } 53 }
53 } 54 }
54 55
@@ -332,9 +333,12 @@ class Poche
332 switch ($action) 333 switch ($action)
333 { 334 {
334 case 'add': 335 case 'add':
335 $content = $url->extract(); 336 $json = file_get_contents(Tools::getPocheUrl() . '/inc/3rdparty/makefulltextfeed.php?url='.urlencode($url->getUrl()).'&max=5&links=preserve&exc=&format=json&submit=Create+Feed');
337 $content = json_decode($json, true);
338 $title = $content['rss']['channel']['item']['title'];
339 $body = $content['rss']['channel']['item']['description'];
336 340
337 if ($this->store->add($url->getUrl(), $content['title'], $content['body'], $this->user->getId())) { 341 if ($this->store->add($url->getUrl(), $title, $body, $this->user->getId())) {
338 Tools::logm('add link ' . $url->getUrl()); 342 Tools::logm('add link ' . $url->getUrl());
339 $sequence = ''; 343 $sequence = '';
340 if (STORAGE == 'postgres') { 344 if (STORAGE == 'postgres') {
@@ -342,7 +346,7 @@ class Poche
342 } 346 }
343 $last_id = $this->store->getLastId($sequence); 347 $last_id = $this->store->getLastId($sequence);
344 if (DOWNLOAD_PICTURES) { 348 if (DOWNLOAD_PICTURES) {
345 $content = filtre_picture($content['body'], $url->getUrl(), $last_id); 349 $content = filtre_picture($body, $url->getUrl(), $last_id);
346 Tools::logm('updating content article'); 350 Tools::logm('updating content article');
347 $this->store->updateContent($last_id, $content, $this->user->getId()); 351 $this->store->updateContent($last_id, $content, $this->user->getId());
348 } 352 }
@@ -394,6 +398,36 @@ class Poche
394 Tools::redirect(); 398 Tools::redirect();
395 } 399 }
396 break; 400 break;
401 case 'add_tag' :
402 $tags = explode(',', $_POST['value']);
403 $entry_id = $_POST['entry_id'];
404 foreach($tags as $key => $tag_value) {
405 $value = trim($tag_value);
406 $tag = $this->store->retrieveTagByValue($value);
407
408 if (is_null($tag)) {
409 # we create the tag
410 $tag = $this->store->createTag($value);
411 $sequence = '';
412 if (STORAGE == 'postgres') {
413 $sequence = 'tags_id_seq';
414 }
415 $tag_id = $this->store->getLastId($sequence);
416 }
417 else {
418 $tag_id = $tag['id'];
419 }
420
421 # we assign the tag to the article
422 $this->store->setTagToEntry($tag_id, $entry_id);
423 }
424 Tools::redirect();
425 break;
426 case 'remove_tag' :
427 $tag_id = $_GET['tag_id'];
428 $this->store->removeTagForEntry($id, $tag_id);
429 Tools::redirect();
430 break;
397 default: 431 default:
398 break; 432 break;
399 } 433 }
@@ -412,7 +446,8 @@ class Poche
412 $compare_prod = version_compare(POCHE, $prod); 446 $compare_prod = version_compare(POCHE, $prod);
413 $themes = $this->getInstalledThemes(); 447 $themes = $this->getInstalledThemes();
414 $languages = $this->getInstalledLanguages(); 448 $languages = $this->getInstalledLanguages();
415 $http_auth = (isset($_SERVER['PHP_AUTH_USER']))?true:false; 449 $token = $this->user->getConfigValue('token');
450 $http_auth = (isset($_SERVER['PHP_AUTH_USER']) || isset($_SERVER['REMOTE_USER'])) ? true : false;
416 $tpl_vars = array( 451 $tpl_vars = array(
417 'themes' => $themes, 452 'themes' => $themes,
418 'languages' => $languages, 453 'languages' => $languages,
@@ -420,10 +455,37 @@ class Poche
420 'prod' => $prod, 455 'prod' => $prod,
421 'compare_dev' => $compare_dev, 456 'compare_dev' => $compare_dev,
422 'compare_prod' => $compare_prod, 457 'compare_prod' => $compare_prod,
458 'token' => $token,
459 'user_id' => $this->user->getId(),
423 'http_auth' => $http_auth, 460 'http_auth' => $http_auth,
424 ); 461 );
425 Tools::logm('config view'); 462 Tools::logm('config view');
426 break; 463 break;
464 case 'edit-tags':
465 # tags
466 $tags = $this->store->retrieveTagsByEntry($id);
467 $tpl_vars = array(
468 'entry_id' => $id,
469 'tags' => $tags,
470 );
471 break;
472 case 'tag':
473 $entries = $this->store->retrieveEntriesByTag($id);
474 $tag = $this->store->retrieveTag($id);
475 $tpl_vars = array(
476 'tag' => $tag,
477 'entries' => $entries,
478 );
479 break;
480 case 'tags':
481 $token = $this->user->getConfigValue('token');
482 $tags = $this->store->retrieveAllTags();
483 $tpl_vars = array(
484 'token' => $token,
485 'user_id' => $this->user->getId(),
486 'tags' => $tags,
487 );
488 break;
427 case 'view': 489 case 'view':
428 $entry = $this->store->retrieveOneById($id, $this->user->getId()); 490 $entry = $this->store->retrieveOneById($id, $this->user->getId());
429 if ($entry != NULL) { 491 if ($entry != NULL) {
@@ -437,12 +499,16 @@ class Poche
437 499
438 # flattr checking 500 # flattr checking
439 $flattr = new FlattrItem(); 501 $flattr = new FlattrItem();
440 $flattr->checkItem($entry['url'],$entry['id']); 502 $flattr->checkItem($entry['url'], $entry['id']);
503
504 # tags
505 $tags = $this->store->retrieveTagsByEntry($entry['id']);
441 506
442 $tpl_vars = array( 507 $tpl_vars = array(
443 'entry' => $entry, 508 'entry' => $entry,
444 'content' => $content, 509 'content' => $content,
445 'flattr' => $flattr 510 'flattr' => $flattr,
511 'tags' => $tags
446 ); 512 );
447 } 513 }
448 else { 514 else {
@@ -584,14 +650,18 @@ class Poche
584 * it redirects the user to the $referer link 650 * it redirects the user to the $referer link
585 * @return array 651 * @return array
586 */ 652 */
587 private function credentials() { 653 private function credentials() {
588 if(isset($_SERVER['PHP_AUTH_USER'])) { 654 if(isset($_SERVER['PHP_AUTH_USER'])) {
589 return array($_SERVER['PHP_AUTH_USER'],'php_auth'); 655 return array($_SERVER['PHP_AUTH_USER'],'php_auth');
590 } 656 }
591 if(!empty($_POST['login']) && !empty($_POST['password'])) { 657 if(!empty($_POST['login']) && !empty($_POST['password'])) {
592 return array($_POST['login'],$_POST['password']); 658 return array($_POST['login'],$_POST['password']);
593 } 659 }
594 return array(false,false); 660 if(isset($_SERVER['REMOTE_USER'])) {
661 return array($_SERVER['REMOTE_USER'],'http_auth');
662 }
663
664 return array(false,false);
595 } 665 }
596 666
597 /** 667 /**
@@ -613,7 +683,8 @@ class Poche
613 $user = $this->store->login($login, Tools::encodeString($password . $login)); 683 $user = $this->store->login($login, Tools::encodeString($password . $login));
614 if ($user != array()) { 684 if ($user != array()) {
615 # Save login into Session 685 # Save login into Session
616 Session::login($user['username'], $user['password'], $login, Tools::encodeString($password . $login), array('poche_user' => new User($user))); 686 $longlastingsession = isset($_POST['longlastingsession']);
687 Session::login($user['username'], $user['password'], $login, Tools::encodeString($password . $login), $longlastingsession, array('poche_user' => new User($user)));
617 $this->messages->add('s', _('welcome to your poche')); 688 $this->messages->add('s', _('welcome to your poche'));
618 Tools::logm('login successful'); 689 Tools::logm('login successful');
619 Tools::redirect($referer); 690 Tools::redirect($referer);
@@ -837,4 +908,58 @@ class Poche
837 } 908 }
838 return $version; 909 return $version;
839 } 910 }
911
912 public function generateToken()
913 {
914 if (ini_get('open_basedir') === '') {
915 $token = substr(base64_encode(file_get_contents('/dev/urandom', false, null, 0, 20)), 0, 15);
916 }
917 else {
918 $token = substr(base64_encode(uniqid(mt_rand(), true)), 0, 20);
919 }
920
921 $this->store->updateUserConfig($this->user->getId(), 'token', $token);
922 $currentConfig = $_SESSION['poche_user']->config;
923 $currentConfig['token'] = $token;
924 $_SESSION['poche_user']->setConfig($currentConfig);
925 }
926
927 public function generateFeeds($token, $user_id, $tag_id, $type = 'home')
928 {
929 $allowed_types = array('home', 'fav', 'archive', 'tag');
930 $config = $this->store->getConfigUser($user_id);
931
932 if (!in_array($type, $allowed_types) ||
933 $token != $config['token']) {
934 die(_('Uh, there is a problem while generating feeds.'));
935 }
936 // Check the token
937
938 $feed = new FeedWriter(RSS2);
939 $feed->setTitle('poche - ' . $type . ' feed');
940 $feed->setLink(Tools::getPocheUrl());
941 $feed->setChannelElement('updated', date(DATE_RSS , time()));
942 $feed->setChannelElement('author', 'poche');
943
944 if ($type == 'tag') {
945 $entries = $this->store->retrieveEntriesByTag($tag_id);
946 }
947 else {
948 $entries = $this->store->getEntriesByView($type, $user_id);
949 }
950
951 if (count($entries) > 0) {
952 foreach ($entries as $entry) {
953 $newItem = $feed->createNewItem();
954 $newItem->setTitle(htmlentities($entry['title']));
955 $newItem->setLink(Tools::getPocheUrl() . '?view=view&amp;id=' . $entry['id']);
956 $newItem->setDate(time());
957 $newItem->setDescription($entry['content']);
958 $feed->addItem($newItem);
959 }
960 }
961
962 $feed->genarateFeed();
963 exit;
964 }
840} 965}