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