2014-07-11 14:03:59 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* wallabag, self hostable application allowing you to not miss any content anymore
|
|
|
|
*
|
|
|
|
* @category wallabag
|
|
|
|
* @author Nicolas Lœuillet <nicolas@loeuillet.org>
|
|
|
|
* @copyright 2013
|
|
|
|
* @license http://opensource.org/licenses/MIT see COPYING file
|
|
|
|
*/
|
|
|
|
|
|
|
|
class Routing
|
|
|
|
{
|
|
|
|
protected $wallabag;
|
2014-07-12 14:39:31 +00:00
|
|
|
protected $referer;
|
|
|
|
protected $view;
|
2014-07-11 14:03:59 +00:00
|
|
|
protected $action;
|
|
|
|
protected $id;
|
|
|
|
protected $url;
|
|
|
|
protected $file;
|
|
|
|
protected $defaultVars = array();
|
|
|
|
protected $vars = array();
|
|
|
|
|
|
|
|
public function __construct(Poche $wallabag)
|
|
|
|
{
|
|
|
|
$this->wallabag = $wallabag;
|
|
|
|
$this->_init();
|
|
|
|
}
|
|
|
|
|
|
|
|
private function _init()
|
|
|
|
{
|
|
|
|
# Parse GET & REFERER vars
|
|
|
|
$this->referer = empty($_SERVER['HTTP_REFERER']) ? '' : $_SERVER['HTTP_REFERER'];
|
|
|
|
$this->view = Tools::checkVar('view', 'home');
|
|
|
|
$this->action = Tools::checkVar('action');
|
|
|
|
$this->id = Tools::checkVar('id');
|
|
|
|
$_SESSION['sort'] = Tools::checkVar('sort', 'id');
|
|
|
|
$this->url = new Url((isset ($_GET['url'])) ? $_GET['url'] : '');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function run()
|
|
|
|
{
|
|
|
|
# vars to _always_ send to templates
|
|
|
|
$this->defaultVars = array(
|
|
|
|
'referer' => $this->referer,
|
|
|
|
'view' => $this->view,
|
|
|
|
'poche_url' => Tools::getPocheUrl(),
|
|
|
|
'title' => _('wallabag, a read it later open source system'),
|
|
|
|
'token' => \Session::getToken(),
|
|
|
|
'theme' => $this->wallabag->tpl->getTheme()
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->_launchAction();
|
|
|
|
$this->_defineTplInformation();
|
|
|
|
|
|
|
|
# because messages can be added in $poche->action(), we have to add this entry now (we can add it before)
|
|
|
|
$this->vars = array_merge($this->vars, array('messages' => $this->wallabag->messages->display('all', FALSE)));
|
|
|
|
|
2014-07-12 14:39:31 +00:00
|
|
|
$this->_render($this->file, $this->vars);
|
2014-07-11 14:03:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private function _defineTplInformation()
|
|
|
|
{
|
|
|
|
$tplFile = array();
|
|
|
|
$tplVars = array();
|
|
|
|
|
|
|
|
if (\Session::isLogged()) {
|
|
|
|
$this->wallabag->action($this->action, $this->url, $this->id);
|
|
|
|
$tplFile = Tools::getTplFile($this->view);
|
|
|
|
$tplVars = array_merge($this->vars, $this->wallabag->displayView($this->view, $this->id));
|
|
|
|
} elseif(isset($_SERVER['PHP_AUTH_USER'])) {
|
|
|
|
if($this->wallabag->store->userExists($_SERVER['PHP_AUTH_USER'])) {
|
|
|
|
$this->wallabag->login($this->referer);
|
|
|
|
} else {
|
|
|
|
$this->wallabag->messages->add('e', _('login failed: user doesn\'t exist'));
|
|
|
|
Tools::logm('user doesn\'t exist');
|
|
|
|
$tplFile = Tools::getTplFile('login');
|
|
|
|
$tplVars['http_auth'] = 1;
|
|
|
|
}
|
|
|
|
} elseif(isset($_SERVER['REMOTE_USER'])) {
|
|
|
|
if($this->wallabag->store->userExists($_SERVER['REMOTE_USER'])) {
|
|
|
|
$this->wallabag->login($this->referer);
|
|
|
|
} else {
|
|
|
|
$this->wallabag->messages->add('e', _('login failed: user doesn\'t exist'));
|
|
|
|
Tools::logm('user doesn\'t exist');
|
|
|
|
$tplFile = Tools::getTplFile('login');
|
|
|
|
$tplVars['http_auth'] = 1;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$tplFile = Tools::getTplFile('login');
|
|
|
|
$tplVars['http_auth'] = 0;
|
|
|
|
\Session::logout();
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->file = $tplFile;
|
|
|
|
$this->vars = array_merge($this->defaultVars, $tplVars);
|
|
|
|
}
|
|
|
|
|
|
|
|
private function _launchAction()
|
|
|
|
{
|
|
|
|
if (isset($_GET['login'])) {
|
|
|
|
// hello you
|
|
|
|
$this->wallabag->login($this->referer);
|
|
|
|
} elseif (isset($_GET['logout'])) {
|
|
|
|
// see you soon !
|
|
|
|
$this->wallabag->logout();
|
|
|
|
} elseif (isset($_GET['config'])) {
|
|
|
|
// update password
|
2014-07-12 17:01:11 +00:00
|
|
|
$this->wallabag->updatePassword($_POST['password'], $_POST['password_repeat']);
|
2014-07-11 14:03:59 +00:00
|
|
|
} elseif (isset($_GET['newuser'])) {
|
2014-07-12 17:01:11 +00:00
|
|
|
$this->wallabag->createNewUser($_POST['newusername'], $_POST['password4newuser']);
|
2014-07-11 14:03:59 +00:00
|
|
|
} elseif (isset($_GET['deluser'])) {
|
2014-07-12 17:01:11 +00:00
|
|
|
$this->wallabag->deleteUser($_POST['password4deletinguser']);
|
2014-07-11 14:03:59 +00:00
|
|
|
} elseif (isset($_GET['epub'])) {
|
2014-07-19 22:45:45 +00:00
|
|
|
$epub = new WallabagEpub($this->wallabag, $_GET['method'], $_GET['value']);
|
2014-07-12 17:01:11 +00:00
|
|
|
$epub->run();
|
2014-07-11 14:03:59 +00:00
|
|
|
} elseif (isset($_GET['import'])) {
|
|
|
|
$import = $this->wallabag->import();
|
|
|
|
$tplVars = array_merge($this->vars, $import);
|
|
|
|
} elseif (isset($_GET['download'])) {
|
|
|
|
Tools::downloadDb();
|
|
|
|
} elseif (isset($_GET['empty-cache'])) {
|
2014-07-12 17:01:11 +00:00
|
|
|
Tools::emptyCache();
|
2014-07-11 14:03:59 +00:00
|
|
|
} elseif (isset($_GET['export'])) {
|
|
|
|
$this->wallabag->export();
|
|
|
|
} elseif (isset($_GET['updatetheme'])) {
|
|
|
|
$this->wallabag->tpl->updateTheme($_POST['theme']);
|
|
|
|
} elseif (isset($_GET['updatelanguage'])) {
|
|
|
|
$this->wallabag->language->updateLanguage($_POST['language']);
|
|
|
|
} elseif (isset($_GET['uploadfile'])) {
|
|
|
|
$this->wallabag->uploadFile();
|
|
|
|
} elseif (isset($_GET['feed'])) {
|
|
|
|
if (isset($_GET['action']) && $_GET['action'] == 'generate') {
|
2014-07-12 17:01:11 +00:00
|
|
|
$this->wallabag->updateToken();
|
2014-07-11 14:03:59 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
$tag_id = (isset($_GET['tag_id']) ? intval($_GET['tag_id']) : 0);
|
|
|
|
$this->wallabag->generateFeeds($_GET['token'], filter_var($_GET['user_id'],FILTER_SANITIZE_NUMBER_INT), $tag_id, $_GET['type']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
elseif (isset($_GET['plainurl']) && !empty($_GET['plainurl'])) {
|
|
|
|
$plainUrl = new Url(base64_encode($_GET['plainurl']));
|
|
|
|
$this->wallabag->action('add', $plainUrl);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-12 14:39:31 +00:00
|
|
|
public function _render($file, $vars)
|
2014-07-11 14:03:59 +00:00
|
|
|
{
|
|
|
|
echo $this->wallabag->tpl->render($file, $vars);
|
|
|
|
}
|
|
|
|
}
|