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 $_SESSION['sort'] = Tools
::checkVar('sort', 'id');
37 $this->url
= new Url((isset ($_GET['url'])) ? $_GET['url'] : '');
42 # vars to _always_ send to templates
43 $this->defaultVars
= array(
44 'referer' => $this->referer
,
45 'view' => $this->view
,
46 'poche_url' => Tools
::getPocheUrl(),
47 'title' => _('wallabag, a read it later open source system'),
48 'token' => \Session
::getToken(),
49 'theme' => $this->wallabag
->tpl
->getTheme()
52 $this->_launchAction();
53 $this->_defineTplInformation();
55 # because messages can be added in $poche->action(), we have to add this entry now (we can add it before)
56 $this->vars
= array_merge($this->vars
, array('messages' => $this->wallabag
->messages
->display('all', FALSE)));
58 $this->_render($this->file
, $this->vars
);
61 private function _defineTplInformation()
66 if (\Session
::isLogged()) {
67 $this->wallabag
->action($this->action
, $this->url
, $this->id
);
68 $tplFile = Tools
::getTplFile($this->view
);
69 $tplVars = array_merge($this->vars
, $this->wallabag
->displayView($this->view
, $this->id
));
70 } elseif(isset($_SERVER['PHP_AUTH_USER'])) {
71 if($this->wallabag
->store
->userExists($_SERVER['PHP_AUTH_USER'])) {
72 $this->wallabag
->login($this->referer
);
74 $this->wallabag
->messages
->add('e', _('login failed: user doesn\'t exist'));
75 Tools
::logm('user doesn\'t exist');
76 $tplFile = Tools
::getTplFile('login');
77 $tplVars['http_auth'] = 1;
79 } elseif(isset($_SERVER['REMOTE_USER'])) {
80 if($this->wallabag
->store
->userExists($_SERVER['REMOTE_USER'])) {
81 $this->wallabag
->login($this->referer
);
83 $this->wallabag
->messages
->add('e', _('login failed: user doesn\'t exist'));
84 Tools
::logm('user doesn\'t exist');
85 $tplFile = Tools
::getTplFile('login');
86 $tplVars['http_auth'] = 1;
89 $tplFile = Tools
::getTplFile('login');
90 $tplVars['http_auth'] = 0;
94 $this->file
= $tplFile;
95 $this->vars
= array_merge($this->defaultVars
, $tplVars);
98 private function _launchAction()
100 if (isset($_GET['login'])) {
102 $this->wallabag
->login($this->referer
);
103 } elseif (isset($_GET['logout'])) {
105 $this->wallabag
->logout();
106 } elseif (isset($_GET['config'])) {
108 $this->wallabag
->updatePassword();
109 } elseif (isset($_GET['newuser'])) {
110 $this->wallabag
->createNewUser();
111 } elseif (isset($_GET['deluser'])) {
112 $this->wallabag
->deleteUser();
113 } elseif (isset($_GET['epub'])) {
114 $this->wallabag
->createEpub();
115 } elseif (isset($_GET['import'])) {
116 $import = $this->wallabag
->import();
117 $tplVars = array_merge($this->vars
, $import);
118 } elseif (isset($_GET['download'])) {
120 } elseif (isset($_GET['empty-cache'])) {
121 $this->wallabag
->emptyCache();
122 } elseif (isset($_GET['export'])) {
123 $this->wallabag
->export();
124 } elseif (isset($_GET['updatetheme'])) {
125 $this->wallabag
->tpl
->updateTheme($_POST['theme']);
126 } elseif (isset($_GET['updatelanguage'])) {
127 $this->wallabag
->language
->updateLanguage($_POST['language']);
128 } elseif (isset($_GET['uploadfile'])) {
129 $this->wallabag
->uploadFile();
130 } elseif (isset($_GET['feed'])) {
131 if (isset($_GET['action']) && $_GET['action'] == 'generate') {
132 $this->wallabag
->generateToken();
135 $tag_id = (isset($_GET['tag_id']) ? intval($_GET['tag_id']) : 0);
136 $this->wallabag
->generateFeeds($_GET['token'], filter_var($_GET['user_id'],FILTER_SANITIZE_NUMBER_INT
), $tag_id, $_GET['type']);
139 elseif (isset($_GET['plainurl']) && !empty($_GET['plainurl'])) {
140 $plainUrl = new Url(base64_encode($_GET['plainurl']));
141 $this->wallabag
->action('add', $plainUrl);
145 private function _render($file, $vars)
147 echo $this->wallabag
->tpl
->render($file, $vars);