]>
git.immae.eu Git - github/wallabag/wallabag.git/blob - inc/poche/Poche.class.php
3 * poche, a read it later open source system
6 * @author Nicolas LÅ“uillet <support@inthepoche.com>
8 * @license http://www.wtfpl.net/ see COPYING file
16 function __construct($storage_type)
18 $this->store
= new $storage_type();
22 if(!$this->store
->isInstalled())
30 private function init()
33 putenv('LC_ALL=' . LANG
);
34 setlocale(LC_ALL
, LANG
);
35 bindtextdomain(LANG
, LOCALE
);
39 $loader = new Twig_Loader_Filesystem(TPL
);
40 $this->tpl
= new Twig_Environment($loader, array(
43 $this->tpl
->addExtension(new Twig_Extensions_Extension_I18n());
49 private function install()
51 Tools
::logm('poche still not installed');
52 echo $this->tpl
->render('install.twig', array(
53 'token' => Session
::getToken(),
55 if (isset($_GET['install'])) {
56 if (($_POST['password'] == $_POST['password_repeat'])
57 && $_POST['password'] != "" && $_POST['login'] != "") {
58 # let's rock, install poche baby !
59 $this->store
->install($_POST['login'], Tools
::encodeString($_POST['password'] . $_POST['login']));
67 private function saveUser()
69 $_SESSION['login'] = (isset ($_SESSION['login'])) ? $_SESSION['login'] : $this->store
->getLogin();
70 $_SESSION['pass'] = (isset ($_SESSION['pass'])) ? $_SESSION['pass'] : $this->store
->getPassword();
74 * Call action (mark as fav, archive, delete, etc.)
76 public function action($action, Url
$url, $id)
81 if($parametres_url = $url->fetchContent()) {
82 if ($this->store
->add($url->getUrl(), $parametres_url['title'], $parametres_url['content'])) {
83 Tools
::logm('add link ' . $url->getUrl());
84 $last_id = $this->store
->getLastId();
85 if (DOWNLOAD_PICTURES
) {
86 $content = filtre_picture($parametres_url['content'], $url->getUrl(), $last_id);
88 #$msg->add('s', _('the link has been added successfully'));
91 #$msg->add('e', _('error during insertion : the link wasn\'t added'));
92 Tools
::logm('error during insertion : the link wasn\'t added');
96 #$msg->add('e', _('error during url preparation : the link wasn\'t added'));
97 Tools
::logm('error during content fetch');
101 if ($this->store
->deleteById($id)) {
102 if (DOWNLOAD_PICTURES
) {
103 remove_directory(ABS_PATH
. $id);
105 #$msg->add('s', _('the link has been deleted successfully'));
106 Tools
::logm('delete link #' . $id);
109 #$msg->add('e', _('the link wasn\'t deleted'));
110 Tools
::logm('error : can\'t delete link #' . $id);
114 $this->store
->favoriteById($id);
115 Tools
::logm('mark as favorite link #' . $id);
117 case 'toggle_archive' :
118 $this->store
->archiveById($id);
119 Tools
::logm('archive link #' . $id);
126 function displayView($view, $id = 0)
133 Tools
::logm('install mode');
136 Tools
::logm('import mode');
139 $entries = $this->store
->retrieveAll();
140 // $tpl->assign('export', Tools::renderJson($entries));
141 // $tpl->draw('export');
142 Tools
::logm('export view');
145 Tools
::logm('config view');
148 $entry = $this->store
->retrieveOneById($id);
149 if ($entry != NULL) {
150 Tools
::logm('view link #' . $id);
151 $content = $entry['content'];
152 if (function_exists('tidy_parse_string')) {
153 $tidy = tidy_parse_string($content, array('indent'=>true, 'show-body-only' => true), 'UTF8');
154 $tidy->cleanRepair();
155 $content = $tidy->value
;
159 'content' => $content,
163 Tools
::logm('error in view call : entry is NULL');
167 $entries = $this->store
->getEntriesByView($view);
169 'entries' => $entries,