wallabag/index.php

123 lines
3.9 KiB
PHP
Raw Normal View History

2013-04-03 15:14:01 +02:00
<?php
/**
* poche, a read it later open source system
*
* @category poche
2013-04-13 11:08:31 +02:00
* @author Nicolas Lœuillet <support@inthepoche.com>
2013-04-03 15:14:01 +02:00
* @copyright 2013
* @license http://www.wtfpl.net/ see COPYING file
*/
2013-11-25 09:57:10 +01:00
define ('POCHE', '1.2.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-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
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
$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 !
$poche->logout();
2013-09-20 10:21:39 +02:00
} elseif (isset($_GET['config'])) {
2013-08-03 19:26:54 +02:00
# Update password
$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']);
} 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();
} elseif (isset($_GET['updatelanguage'])) {
$poche->updateLanguage();
} elseif (isset($_GET['feed'])) {
2013-12-03 12:07:02 +01:00
if (isset($_GET['action']) && $_GET['action'] == 'generate') {
$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-08-04 22:35:08 +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);
}
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;
}
} 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-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);