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(ALLOW_REGISTER
&& isset($_GET['registerform'])) {
72 Tools
::logm('register');
73 $tplFile = Tools
::getTplFile('register');
74 } elseif (ALLOW_REGISTER
&& isset($_GET['register'])){
75 $this->wallabag
->createNewUser($_POST['newusername'], $_POST['password4newuser'], $_POST['newuseremail']);
77 } elseif(isset($_SERVER['PHP_AUTH_USER'])) {
78 if($this->wallabag
->store
->userExists($_SERVER['PHP_AUTH_USER'])) {
79 $this->wallabag
->login($this->referer
);
81 $this->wallabag
->messages
->add('e', _('login failed: user doesn\'t exist'));
82 Tools
::logm('user doesn\'t exist');
83 $tplFile = Tools
::getTplFile('login');
84 $tplVars['http_auth'] = 1;
86 } elseif(isset($_SERVER['REMOTE_USER'])) {
87 if($this->wallabag
->store
->userExists($_SERVER['REMOTE_USER'])) {
88 $this->wallabag
->login($this->referer
);
90 $this->wallabag
->messages
->add('e', _('login failed: user doesn\'t exist'));
91 Tools
::logm('user doesn\'t exist');
92 $tplFile = Tools
::getTplFile('login');
93 $tplVars['http_auth'] = 1;
96 $tplFile = Tools
::getTplFile('login');
97 $tplVars['http_auth'] = 0;
101 $this->file
= $tplFile;
102 $this->vars
= array_merge($this->defaultVars
, $tplVars);
105 private function _launchAction()
107 if (isset($_GET['login'])) {
109 $this->wallabag
->login($this->referer
);
110 } elseif (isset($_GET['feed']) && isset($_GET['user_id'])) {
111 $tag_id = (isset($_GET['tag_id']) ? intval($_GET['tag_id']) : 0);
112 $limit = (isset($_GET['limit']) ? intval($_GET['limit']) : 0);
113 $this->wallabag
->generateFeeds($_GET['token'], filter_var($_GET['user_id'],FILTER_SANITIZE_NUMBER_INT
), $tag_id, $_GET['type'], $limit);
116 //allowed ONLY to logged in user
117 if (\Session
::isLogged() === true)
119 if (isset($_GET['logout'])) {
121 $this->wallabag
->logout();
122 } elseif (isset($_GET['config'])) {
124 $this->wallabag
->updatePassword($_POST['password'], $_POST['password_repeat']);
125 } elseif (isset($_GET['newuser'])) {
126 $this->wallabag
->createNewUser($_POST['newusername'], $_POST['password4newuser'], $_POST['newuseremail'], true);
127 } elseif (isset($_GET['deluser'])) {
128 $this->wallabag
->deleteUser($_POST['password4deletinguser']);
129 } elseif (isset($_GET['epub'])) {
130 $epub = new WallabagEpub($this->wallabag
, $_GET['method'], $_GET['value']);
131 $epub->prepareData();
132 $epub->produceEpub();
133 } elseif (isset($_GET['mobi'])) {
134 $mobi = new WallabagMobi($this->wallabag
, $_GET['method'], $_GET['value']);
135 $mobi->prepareData();
136 $mobi->produceMobi();
137 } elseif (isset($_GET['pdf'])) {
138 $pdf = new WallabagPDF($this->wallabag
, $_GET['method'], $_GET['value']);
141 } elseif (isset($_GET['import'])) {
142 $import = $this->wallabag
->import();
143 $tplVars = array_merge($this->vars
, $import);
144 } elseif (isset($_GET['empty-cache'])) {
146 } elseif (isset($_GET['export'])) {
147 $this->wallabag
->export();
148 } elseif (isset($_GET['updatetheme'])) {
149 $this->wallabag
->tpl
->updateTheme($_POST['theme']);
150 } elseif (isset($_GET['updatelanguage'])) {
151 $this->wallabag
->language
->updateLanguage($_POST['language']);
152 } elseif (isset($_GET['uploadfile'])) {
153 $this->wallabag
->uploadFile();
154 } elseif (isset($_GET['feed']) && isset($_GET['action']) && $_GET['action'] == 'generate') {
155 $this->wallabag
->updateToken();
157 elseif (isset($_GET['plainurl']) && !empty($_GET['plainurl'])) {
158 $plainUrl = new Url(base64_encode($_GET['plainurl']));
159 $this->wallabag
->action('add', $plainUrl);
164 public function _render($file, $vars)
166 echo $this->wallabag
->tpl
->render($file, $vars);