wallabag/index.php

144 lines
4.6 KiB
PHP
Raw Normal View History

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-05-29 16:52:34 +00:00
define ('POCHE', '1.7.0');
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
# Set error reporting level
2014-06-30 20:15:55 +00:00
if (defined('ERROR_REPORTING')) {
error_reporting(ERROR_REPORTING);
}
# Start session
Session::$sessionName = 'poche';
2014-03-21 12:59:30 +00:00
Session::init();
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-09-20 08:21:39 +00:00
# vars to _always_ send to templates
$tpl_vars = array(
'referer' => $referer,
'view' => $view,
'poche_url' => Tools::getPocheUrl(),
'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
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
$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 !
$poche->logout();
2013-09-20 08:21:39 +00:00
} elseif (isset($_GET['config'])) {
2013-08-03 17:26:54 +00:00
# Update password
$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);
} elseif (isset($_GET['download'])) {
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();
} elseif (isset($_GET['updatelanguage'])) {
$poche->updateLanguage();
2014-02-28 19:36:32 +00:00
} elseif (isset($_GET['uploadfile'])) {
$poche->uploadFile();
} elseif (isset($_GET['feed'])) {
2013-12-03 11:07:02 +00:00
if (isset($_GET['action']) && $_GET['action'] == 'generate') {
$poche->generateToken();
}
else {
2013-12-06 13:37:42 +00:00
$tag_id = (isset($_GET['tag_id']) ? intval($_GET['tag_id']) : 0);
2014-06-30 20:15:55 +00:00
$poche->generateFeeds($_GET['token'], filter_var($_GET['user_id'],FILTER_SANITIZE_NUMBER_INT), $tag_id, $_GET['type']);
}
2013-08-04 20:35:08 +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);
}
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;
}
} 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-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);