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
11 namespace Wallabag\Wallabag
;
22 protected $defaultVars = array();
23 protected $vars = array();
25 public function __construct(Wallabag
$wallabag)
27 $this->wallabag
= $wallabag;
31 private function _init()
33 # Parse GET & REFERER vars
34 $this->referer
= empty($_SERVER['HTTP_REFERER']) ? '' : $_SERVER['HTTP_REFERER'];
35 $this->view
= Tools
::checkVar('view', 'home');
36 $this->action
= Tools
::checkVar('action');
37 $this->id
= Tools
::checkVar('id');
38 $_SESSION['sort'] = Tools
::checkVar('sort', 'id');
39 $this->url
= new Url((isset ($_GET['url'])) ? $_GET['url'] : '');
44 # vars to _always_ send to templates
45 $this->defaultVars
= array(
46 'referer' => $this->referer
,
47 'view' => $this->view
,
48 'poche_url' => Tools
::getPocheUrl(),
49 'title' => _('wallabag, a read it later open source system'),
50 'token' => \Session
::getToken(),
51 'theme' => $this->wallabag
->tpl
->getTheme()
54 $this->_launchAction();
55 $this->_defineTplInformation();
57 # because messages can be added in $poche->action(), we have to add this entry now (we can add it before)
58 $this->vars
= array_merge($this->vars
, array('messages' => $this->wallabag
->messages
->display('all', FALSE)));
60 $this->_render($this->file
, $this->vars
);
63 private function _defineTplInformation()
68 if (\Session
::isLogged()) {
69 $this->wallabag
->action($this->action
, $this->url
, $this->id
);
70 $tplFile = Tools
::getTplFile($this->view
);
71 $tplVars = array_merge($this->vars
, $this->wallabag
->displayView($this->view
, $this->id
));
72 } elseif(isset($_SERVER['PHP_AUTH_USER'])) {
73 if($this->wallabag
->store
->userExists($_SERVER['PHP_AUTH_USER'])) {
74 $this->wallabag
->login($this->referer
);
76 $this->wallabag
->messages
->add('e', _('login failed: user doesn\'t exist'));
77 Tools
::logm('user doesn\'t exist');
78 $tplFile = Tools
::getTplFile('login');
79 $tplVars['http_auth'] = 1;
81 } elseif(isset($_SERVER['REMOTE_USER'])) {
82 if($this->wallabag
->store
->userExists($_SERVER['REMOTE_USER'])) {
83 $this->wallabag
->login($this->referer
);
85 $this->wallabag
->messages
->add('e', _('login failed: user doesn\'t exist'));
86 Tools
::logm('user doesn\'t exist');
87 $tplFile = Tools
::getTplFile('login');
88 $tplVars['http_auth'] = 1;
91 $tplFile = Tools
::getTplFile('login');
92 $tplVars['http_auth'] = 0;
96 $this->file
= $tplFile;
97 $this->vars
= array_merge($this->defaultVars
, $tplVars);
100 private function _launchAction()
102 if (isset($_GET['login'])) {
104 $this->wallabag
->login($this->referer
);
105 } elseif (isset($_GET['feed']) && isset($_GET['user_id'])) {
106 $tag_id = (isset($_GET['tag_id']) ? intval($_GET['tag_id']) : 0);
107 $limit = (isset($_GET['limit']) ? intval($_GET['limit']) : 0);
108 $this->wallabag
->generateFeeds($_GET['token'], filter_var($_GET['user_id'],FILTER_SANITIZE_NUMBER_INT
), $tag_id, $_GET['type'], $limit);
111 //allowed ONLY to logged in user
112 if (\Session
::isLogged() === true)
114 if (isset($_GET['logout'])) {
116 $this->wallabag
->logout();
117 } elseif (isset($_GET['config'])) {
119 $this->wallabag
->updatePassword($_POST['password'], $_POST['password_repeat']);
120 } elseif (isset($_GET['newuser'])) {
121 $this->wallabag
->createNewUser($_POST['newusername'], $_POST['password4newuser']);
122 } elseif (isset($_GET['deluser'])) {
123 $this->wallabag
->deleteUser($_POST['password4deletinguser']);
124 } elseif (isset($_GET['epub'])) {
125 $epub = new WallabagEpub($this->wallabag
, $_GET['method'], $_GET['value']);
126 $epub->prepareData();
127 $epub->produceEpub();
128 } elseif (isset($_GET['mobi'])) {
129 $mobi = new WallabagMobi($this->wallabag
, $_GET['method'], $_GET['value']);
130 $mobi->prepareData();
131 $mobi->produceMobi();
132 } elseif (isset($_GET['pdf'])) {
133 $pdf = new WallabagPDF($this->wallabag
, $_GET['method'], $_GET['value']);
136 } elseif (isset($_GET['import'])) {
137 $import = $this->wallabag
->import();
138 $tplVars = array_merge($this->vars
, $import);
139 } elseif (isset($_GET['empty-cache'])) {
141 } elseif (isset($_GET['export'])) {
142 $this->wallabag
->export();
143 } elseif (isset($_GET['updatetheme'])) {
144 $this->wallabag
->tpl
->updateTheme($_POST['theme']);
145 } elseif (isset($_GET['updatelanguage'])) {
146 $this->wallabag
->language
->updateLanguage($_POST['language']);
147 } elseif (isset($_GET['uploadfile'])) {
148 $this->wallabag
->uploadFile();
149 } elseif (isset($_GET['feed']) && isset($_GET['action']) && $_GET['action'] == 'generate') {
150 $this->wallabag
->updateToken();
152 elseif (isset($_GET['plainurl']) && !empty($_GET['plainurl'])) {
153 $plainUrl = new Url(base64_encode($_GET['plainurl']));
154 $this->wallabag
->action('add', $plainUrl);
159 public function _render($file, $vars)
161 echo $this->wallabag
->tpl
->render($file, $vars);