2013-04-03 13:14:01 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2014-01-28 09:36:04 +00:00
|
|
|
* wallabag, self hostable application allowing you to not miss any content anymore
|
2013-04-03 13:14:01 +00:00
|
|
|
*
|
2014-01-28 09:36:04 +00:00
|
|
|
* @category wallabag
|
|
|
|
* @author Nicolas Lœuillet <nicolas@loeuillet.org>
|
2013-04-03 13:14:01 +00:00
|
|
|
* @copyright 2013
|
|
|
|
* @license http://www.wtfpl.net/ see COPYING file
|
|
|
|
*/
|
|
|
|
|
2014-04-11 15:08:11 +00:00
|
|
|
define ('POCHE', '1.6.1');
|
2014-02-18 20:22:34 +00:00
|
|
|
require 'check_setup.php';
|
2013-09-20 08:21:39 +00:00
|
|
|
require_once 'inc/poche/global.inc.php';
|
2013-08-16 18:19:31 +00:00
|
|
|
|
2014-03-17 20:22:05 +00:00
|
|
|
# Start session
|
|
|
|
Session::$sessionName = 'poche';
|
2014-03-21 12:59:30 +00:00
|
|
|
Session::init();
|
2014-03-17 20:22:05 +00:00
|
|
|
|
2013-09-20 08:21:39 +00:00
|
|
|
# Start Poche
|
|
|
|
$poche = new Poche();
|
|
|
|
$notInstalledMessage = $poche -> getNotInstalledMessage();
|
2013-04-03 13:14:01 +00:00
|
|
|
|
2013-08-08 07:11:12 +00:00
|
|
|
# Parse GET & REFERER vars
|
2013-08-02 20:40:51 +00:00
|
|
|
$referer = empty($_SERVER['HTTP_REFERER']) ? '' : $_SERVER['HTTP_REFERER'];
|
2013-08-05 08:32:15 +00:00
|
|
|
$view = Tools::checkVar('view', 'home');
|
2013-08-04 20:35:08 +00:00
|
|
|
$action = Tools::checkVar('action');
|
|
|
|
$id = Tools::checkVar('id');
|
2013-08-05 21:11:10 +00:00
|
|
|
$_SESSION['sort'] = Tools::checkVar('sort', 'id');
|
2013-08-04 20:35:08 +00:00
|
|
|
$url = new Url((isset ($_GET['url'])) ? $_GET['url'] : '');
|
2013-04-20 08:22:00 +00:00
|
|
|
|
2013-09-20 08:21:39 +00:00
|
|
|
# vars to _always_ send to templates
|
|
|
|
$tpl_vars = array(
|
|
|
|
'referer' => $referer,
|
|
|
|
'view' => $view,
|
|
|
|
'poche_url' => Tools::getPocheUrl(),
|
2014-02-25 13:45:39 +00:00
|
|
|
'title' => _('wallabag, a read it later open source system'),
|
2013-09-20 08:21:39 +00:00
|
|
|
'token' => Session::getToken(),
|
|
|
|
'theme' => $poche->getTheme()
|
|
|
|
);
|
|
|
|
|
|
|
|
if (! empty($notInstalledMessage)) {
|
|
|
|
if (! Poche::$canRenderTemplates || ! Poche::$configFileAvailable) {
|
2014-04-02 17:55:19 +00:00
|
|
|
# We cannot use Twig to display the error message
|
2013-10-07 11:12:28 +00:00
|
|
|
echo '<h1>Errors</h1><ol>';
|
|
|
|
foreach ($notInstalledMessage as $message) {
|
|
|
|
echo '<li>' . $message . '</li>';
|
|
|
|
}
|
|
|
|
echo '</ol>';
|
|
|
|
die();
|
2013-09-20 08:21:39 +00:00
|
|
|
} else {
|
|
|
|
# Twig is installed, put the error message in the template
|
|
|
|
$tpl_file = Tools::getTplFile('error');
|
|
|
|
$tpl_vars = array_merge($tpl_vars, array('msg' => $poche->getNotInstalledMessage()));
|
|
|
|
echo $poche->tpl->render($tpl_file, $tpl_vars);
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-08 07:11:12 +00:00
|
|
|
# poche actions
|
2013-04-19 09:41:12 +00:00
|
|
|
if (isset($_GET['login'])) {
|
2013-08-03 17:26:54 +00:00
|
|
|
# hello you
|
2013-08-04 19:42:46 +00:00
|
|
|
$poche->login($referer);
|
2013-09-20 08:21:39 +00:00
|
|
|
} elseif (isset($_GET['logout'])) {
|
2013-08-03 17:26:54 +00:00
|
|
|
# see you soon !
|
2013-08-04 19:42:46 +00:00
|
|
|
$poche->logout();
|
2013-09-20 08:21:39 +00:00
|
|
|
} elseif (isset($_GET['config'])) {
|
2013-08-03 17:26:54 +00:00
|
|
|
# Update password
|
2013-08-04 19:42:46 +00:00
|
|
|
$poche->updatePassword();
|
2014-04-23 08:29:53 +00:00
|
|
|
} elseif (isset($_GET['newuser'])) {
|
|
|
|
$poche->createNewUser();
|
|
|
|
} elseif (isset($_GET['deluser'])) {
|
|
|
|
$poche->deleteUser();
|
2014-04-24 01:04:02 +00:00
|
|
|
} elseif (isset($_GET['epub'])) {
|
|
|
|
$poche->createEpub();
|
2013-09-20 08:21:39 +00:00
|
|
|
} elseif (isset($_GET['import'])) {
|
2014-04-02 17:55:19 +00:00
|
|
|
$import = $poche->import();
|
|
|
|
$tpl_vars = array_merge($tpl_vars, $import);
|
2013-12-12 08:42:19 +00:00
|
|
|
} elseif (isset($_GET['download'])) {
|
2014-02-14 14:11:57 +00:00
|
|
|
Tools::download_db();
|
|
|
|
} elseif (isset($_GET['empty-cache'])) {
|
|
|
|
$poche->emptyCache();
|
2013-09-20 08:21:39 +00:00
|
|
|
} elseif (isset($_GET['export'])) {
|
2013-08-04 20:35:08 +00:00
|
|
|
$poche->export();
|
2013-09-20 08:21:39 +00:00
|
|
|
} elseif (isset($_GET['updatetheme'])) {
|
|
|
|
$poche->updateTheme();
|
2013-10-07 12:26:25 +00:00
|
|
|
} elseif (isset($_GET['updatelanguage'])) {
|
|
|
|
$poche->updateLanguage();
|
2014-02-28 19:36:32 +00:00
|
|
|
} elseif (isset($_GET['uploadfile'])) {
|
|
|
|
$poche->uploadFile();
|
2013-12-03 09:40:27 +00:00
|
|
|
} elseif (isset($_GET['feed'])) {
|
2013-12-03 11:07:02 +00:00
|
|
|
if (isset($_GET['action']) && $_GET['action'] == 'generate') {
|
2013-12-03 09:40:27 +00:00
|
|
|
$poche->generateToken();
|
|
|
|
}
|
|
|
|
else {
|
2013-12-06 13:37:42 +00:00
|
|
|
$tag_id = (isset($_GET['tag_id']) ? intval($_GET['tag_id']) : 0);
|
|
|
|
$poche->generateFeeds($_GET['token'], $_GET['user_id'], $tag_id, $_GET['type']);
|
2013-12-03 09:40:27 +00:00
|
|
|
}
|
2013-08-04 20:35:08 +00:00
|
|
|
}
|
2013-10-07 12:26:25 +00:00
|
|
|
|
2013-09-10 12:41:58 +00:00
|
|
|
elseif (isset($_GET['plainurl']) && !empty($_GET['plainurl'])) {
|
|
|
|
$plain_url = new Url(base64_encode($_GET['plainurl']));
|
|
|
|
$poche->action('add', $plain_url);
|
|
|
|
}
|
2013-09-08 19:07:59 +00:00
|
|
|
|
2013-04-18 13:39:34 +00:00
|
|
|
if (Session::isLogged()) {
|
2013-08-04 18:58:31 +00:00
|
|
|
$poche->action($action, $url, $id);
|
|
|
|
$tpl_file = Tools::getTplFile($view);
|
|
|
|
$tpl_vars = array_merge($tpl_vars, $poche->displayView($view, $id));
|
2013-10-20 14:53:54 +00:00
|
|
|
} elseif(isset($_SERVER['PHP_AUTH_USER'])) {
|
2013-10-20 21:28:45 +00:00
|
|
|
if($poche->store->userExists($_SERVER['PHP_AUTH_USER'])) {
|
|
|
|
$poche->login($referer);
|
|
|
|
} else {
|
|
|
|
$poche->messages->add('e', _('login failed: user doesn\'t exist'));
|
|
|
|
Tools::logm('user doesn\'t exist');
|
|
|
|
$tpl_file = Tools::getTplFile('login');
|
|
|
|
$tpl_vars['http_auth'] = 1;
|
|
|
|
}
|
2013-12-23 08:09:10 +00:00
|
|
|
} elseif(isset($_SERVER['REMOTE_USER'])) {
|
|
|
|
if($poche->store->userExists($_SERVER['REMOTE_USER'])) {
|
|
|
|
$poche->login($referer);
|
|
|
|
} else {
|
|
|
|
$poche->messages->add('e', _('login failed: user doesn\'t exist'));
|
|
|
|
Tools::logm('user doesn\'t exist');
|
|
|
|
$tpl_file = Tools::getTplFile('login');
|
|
|
|
$tpl_vars['http_auth'] = 1;
|
|
|
|
}
|
2013-09-20 08:21:39 +00:00
|
|
|
} else {
|
|
|
|
$tpl_file = Tools::getTplFile('login');
|
2013-10-20 21:28:45 +00:00
|
|
|
$tpl_vars['http_auth'] = 0;
|
2014-03-21 12:59:30 +00:00
|
|
|
Session::logout();
|
2013-04-20 08:22:00 +00:00
|
|
|
}
|
2013-08-02 20:40:51 +00:00
|
|
|
|
2013-08-05 13:54:37 +00:00
|
|
|
# because messages can be added in $poche->action(), we have to add this entry now (we can add it before)
|
2013-08-05 19:56:32 +00:00
|
|
|
$messages = $poche->messages->display('all', FALSE);
|
|
|
|
$tpl_vars = array_merge($tpl_vars, array('messages' => $messages));
|
2013-08-05 13:54:37 +00:00
|
|
|
|
2013-08-08 07:11:12 +00:00
|
|
|
# display poche
|
2013-10-20 14:53:54 +00:00
|
|
|
echo $poche->tpl->render($tpl_file, $tpl_vars);
|