3 * wallabag, self hostable application allowing you to not miss any content anymore
6 * @author Nicolas LÅ“uillet <nicolas@loeuillet.org>
8 * @license http://opensource.org/licenses/MIT see COPYING file
20 protected $defaultVars = array();
21 protected $vars = array();
23 public function __construct(Poche
$wallabag)
25 $this->wallabag
= $wallabag;
29 private function _init()
31 # Parse GET & REFERER vars
32 $this->referer
= empty($_SERVER['HTTP_REFERER']) ? '' : $_SERVER['HTTP_REFERER'];
33 $this->view
= Tools
::checkVar('view', 'home');
34 $this->action
= Tools
::checkVar('action');
35 $this->id
= Tools
::checkVar('id');
36 $this->autoclose
= Tools
::checkVar('autoclose',FALSE);
37 $_SESSION['sort'] = Tools
::checkVar('sort', 'id');
38 $this->url
= new Url((isset ($_GET['url'])) ? $_GET['url'] : '');
43 # vars to _always_ send to templates
44 $this->defaultVars
= array(
45 'referer' => $this->referer
,
46 'view' => $this->view
,
47 'poche_url' => Tools
::getPocheUrl(),
48 'title' => _('wallabag, a read it later open source system'),
49 'token' => \Session
::getToken(),
50 'theme' => $this->wallabag
->tpl
->getTheme()
53 $this->_launchAction();
54 $this->_defineTplInformation();
56 # because messages can be added in $poche->action(), we have to add this entry now (we can add it before)
57 $this->vars
= array_merge($this->vars
, array('messages' => $this->wallabag
->messages
->display('all', FALSE)));
59 $this->_render($this->file
, $this->vars
);
62 private function _defineTplInformation()
67 if (\Session
::isLogged()) {
68 $this->wallabag
->action($this->action
, $this->url
, $this->id
, FALSE, $this->autoclose
);
69 $tplFile = Tools
::getTplFile($this->view
);
70 $tplVars = array_merge($this->vars
, $this->wallabag
->displayView($this->view
, $this->id
));
71 } elseif(isset($_SERVER['PHP_AUTH_USER'])) {
72 if($this->wallabag
->store
->userExists($_SERVER['PHP_AUTH_USER'])) {
73 $this->wallabag
->login($this->referer
);
75 $this->wallabag
->messages
->add('e', _('login failed: user doesn\'t exist'));
76 Tools
::logm('user doesn\'t exist');
77 $tplFile = Tools
::getTplFile('login');
78 $tplVars['http_auth'] = 1;
80 } elseif(isset($_SERVER['REMOTE_USER'])) {
81 if($this->wallabag
->store
->userExists($_SERVER['REMOTE_USER'])) {
82 $this->wallabag
->login($this->referer
);
84 $this->wallabag
->messages
->add('e', _('login failed: user doesn\'t exist'));
85 Tools
::logm('user doesn\'t exist');
86 $tplFile = Tools
::getTplFile('login');
87 $tplVars['http_auth'] = 1;
90 $tplFile = Tools
::getTplFile('login');
91 $tplVars['http_auth'] = 0;
95 $this->file
= $tplFile;
96 $this->vars
= array_merge($this->defaultVars
, $tplVars);
99 private function _launchAction()
101 if (isset($_GET['login'])) {
103 $this->wallabag
->login($this->referer
);
104 } elseif (isset($_GET['feed']) && isset($_GET['user_id'])) {
105 $tag_id = (isset($_GET['tag_id']) ? intval($_GET['tag_id']) : 0);
106 $limit = (isset($_GET['limit']) ? intval($_GET['limit']) : 0);
107 $this->wallabag
->generateFeeds($_GET['token'], filter_var($_GET['user_id'],FILTER_SANITIZE_NUMBER_INT
), $tag_id, $_GET['type'], $limit);
110 //allowed ONLY to logged in user
111 if (\Session
::isLogged() === true)
113 if (isset($_GET['logout'])) {
115 $this->wallabag
->logout();
116 } elseif (isset($_GET['config'])) {
118 $this->wallabag
->updatePassword($_POST['password'], $_POST['password_repeat']);
119 } elseif (isset($_GET['newuser'])) {
120 $this->wallabag
->createNewUser($_POST['newusername'], $_POST['password4newuser'], $_POST['newuseremail']);
121 } elseif (isset($_GET['deluser'])) {
122 $this->wallabag
->deleteUser($_POST['password4deletinguser']);
123 } elseif (isset($_GET['epub'])) {
124 $epub = new WallabagEpub($this->wallabag
, $_GET['method'], $_GET['value']);
125 $epub->prepareData();
126 $epub->produceEpub();
127 } elseif (isset($_GET['mobi'])) {
128 $mobi = new WallabagMobi($this->wallabag
, $_GET['method'], $_GET['value']);
129 $mobi->prepareData();
130 $mobi->produceMobi();
131 } elseif (isset($_GET['pdf'])) {
132 $pdf = new WallabagPDF($this->wallabag
, $_GET['method'], $_GET['value']);
135 } elseif (isset($_GET['import'])) {
136 $import = $this->wallabag
->import();
137 $tplVars = array_merge($this->vars
, $import);
138 } elseif (isset($_GET['empty-cache'])) {
140 } elseif (isset($_GET['export'])) {
141 $this->wallabag
->export();
142 } elseif (isset($_GET['updatetheme'])) {
143 $this->wallabag
->tpl
->updateTheme($_POST['theme']);
144 } elseif (isset($_GET['updatelanguage'])) {
145 $this->wallabag
->language
->updateLanguage($_POST['language']);
146 } elseif (isset($_GET['uploadfile'])) {
147 $this->wallabag
->uploadFile();
148 } elseif (isset($_GET['feed']) && isset($_GET['action']) && $_GET['action'] == 'generate') {
149 $this->wallabag
->updateToken();
151 elseif (isset($_GET['plainurl']) && !empty($_GET['plainurl'])) {
152 $plainUrl = new Url(base64_encode($_GET['plainurl']));
153 $this->wallabag
->action('add', $plainUrl);
158 public function _render($file, $vars)
160 echo $this->wallabag
->tpl
->render($file, $vars);