]>
git.immae.eu Git - github/wallabag/wallabag.git/blob - inc/poche/Poche.class.php
12cb1b42afa2334cdbfc8815cc7e7ab1d730c4a2
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 = 0)
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('config view');
136 $entry = $this->store
->retrieveOneById($id);
137 if ($entry != NULL) {
138 Tools
::logm('view link #' . $id);
139 $content = $entry['content'];
140 if (function_exists('tidy_parse_string')) {
141 $tidy = tidy_parse_string($content, array('indent'=>true, 'show-body-only' => true), 'UTF8');
142 $tidy->cleanRepair();
143 $content = $tidy->value
;
147 'content' => $content,
151 Tools
::logm('error in view call : entry is NULL');
155 $entries = $this->store
->getEntriesByView($view);
157 'entries' => $entries,
165 public function updatePassword()
167 if (isset($_POST['password']) && isset($_POST['password_repeat'])) {
168 if ($_POST['password'] == $_POST['password_repeat'] && $_POST['password'] != "") {
170 Tools
::logm('password updated');
171 $this->store
->updatePassword(Tools
::encodeString($_POST['password'] . $_SESSION['login']));
176 Tools
::logm('in demo mode, you can\'t do this');
182 public function login($referer)
184 if (!empty($_POST['login']) && !empty($_POST['password'])) {
185 if (Session
::login($_SESSION['login'], $_SESSION['pass'], $_POST['login'], Tools
::encodeString($_POST['password'] . $_POST['login']))) {
186 Tools
::logm('login successful');
188 if (!empty($_POST['longlastingsession'])) {
189 $_SESSION['longlastingsession'] = 31536000;
190 $_SESSION['expires_on'] = time() +
$_SESSION['longlastingsession'];
191 session_set_cookie_params($_SESSION['longlastingsession']);
193 session_set_cookie_params(0);
195 session_regenerate_id(true);
196 Tools
::redirect($referer);
198 Tools
::logm('login failed');
201 Tools
::logm('login failed');
206 public function logout()
208 Tools
::logm('logout');
213 private function importFromInstapaper()
215 # TODO gestion des articles favs
216 $html = new simple_html_dom();
217 $html->load_file('./instapaper-export.html');
221 foreach($html->find('ol') as $ul)
223 foreach($ul->find('li') as $li)
226 $url = new Url(base64_encode($a[0]->href
));
227 $this->action('add', $url);
229 $last_id = $this->store
->getLastId();
230 $this->store
->archiveById($last_id);
234 # the second <ol> is for read links
237 Tools
::logm('import from instapaper completed');
241 private function importFromPocket()
243 # TODO gestion des articles favs
244 $html = new simple_html_dom();
245 $html->load_file('./ril_export.html');
249 foreach($html->find('ul') as $ul)
251 foreach($ul->find('li') as $li)
254 $url = new Url(base64_encode($a[0]->href
));
255 $this->action('add', $url);
257 $last_id = $this->store
->getLastId();
258 $this->store
->archiveById($last_id);
262 # the second <ul> is for read links
265 Tools
::logm('import from pocket completed');
269 private function importFromReadability()
271 # TODO gestion des articles lus / favs
272 $str_data = file_get_contents("./readability");
273 $data = json_decode($str_data,true);
275 foreach ($data as $key => $value) {
277 foreach ($value as $attr => $attr_value) {
278 if ($attr == 'article__url') {
279 $url = new Url(base64_encode($attr_value));
281 // if ($attr_value == 'favorite' && $attr_value == 'true') {
282 // $last_id = $this->store->getLastId();
283 // $this->store->favoriteById($last_id);
285 // if ($attr_value == 'archive' && $attr_value == 'true') {
286 // $last_id = $this->store->getLastId();
287 // $this->store->archiveById($last_id);
290 if ($url->isCorrect())
291 $this->action('add', $url);
293 Tools
::logm('import from Readability completed');
297 public function import($from)
299 if ($from == 'pocket') {
300 $this->importFromPocket();
302 else if ($from == 'readability') {
303 $this->importFromReadability();
305 else if ($from == 'instapaper') {
306 $this->importFromInstapaper();
310 public function export()
312 $entries = $this->store
->retrieveAll();
313 echo $this->tpl
->render('export.twig', array(
314 'export' => Tools
::renderJson($entries),
316 Tools
::logm('export view');