Simplify code not having to check for object existence.
class User
{
- function __construct($dir, $existing = TRUE)
+ public $dir, $login;
+
+ function __construct($dir = NULL, $existing = TRUE)
{
+ if (empty($dir)) {
+ return;
+ }
if (!file_exists($dir) and $existing) {
throw new Exception("Gebruiker niet gevonden in $dir");
}
}
return isset($this->admin[$permission]); # check level
}
- if (!@file_exists("{$this->dir}/.admin")) {
+ if (!$this->dir or !@file_exists("{$this->dir}/.admin")) {
return FALSE; # not an admin
}
return array_fill_keys(explode("\n", file_get_contents("{$this->dir}/.admin")), TRUE);
return $user;
}
+global $User;
if (isset($_COOKIE['login'])) {
- global $User;
$User = login($_COOKIE['login']);
}
+if (!$User) {
+ $User = new User;
+}
<?php
-if (!$User or !$User->admin('foto')) {
+if (!$User->admin('foto')) {
http_response_code(403);
print "Beheerrechten verplicht voor instellen van covers\n";
exit;
abort("pagina niet opgegeven", '409 input error');
$pagename = ltrim($Args, '/').'.html';
-if (!$User or !$User->admin("edit $pagename"))
+if (!$User->admin("edit $pagename"))
abort("geen beheersrechten", '401 unauthorised');
@list ($category, $year, $article) = explode('/', $pagename);
<?php
-if (!$User or !$User->admin("edit $Page$Args"))
+if (!$User->admin("edit $Page$Args"))
abort("geen beheersrechten", '401 unauthorised');
if ($_FILES) {
closeElClasses: [],
shareButtons: [
<?php
-if ($User and $User->admin('foto')) {
+if ($User->admin('foto')) {
printf("\t\t\t{id:'%s', label:'%s', url:'%s'},\n",
'cover', 'Cover instellen', "/edit/foto/cover$Args?img={{image_url}}"
);
<?php
$rootdir = $Page . $Args;
-if ($User and $User->admin('foto')) {
+if ($User->admin('foto')) {
$access = '🔓 Openbaar';
if (!empty($PageAccess)) {
$access = "🔒 Bewoners";
$html = '<img src="/'.$cover.'" />';
$html .= "<figcaption>$album</figcaption>";
- if (empty($User) and file_exists("$path/.private")) {
+ if (!$User->login and file_exists("$path/.private")) {
$html = '<strike title="bewoners">'.$html.'</strike>';
}
$html = "<figure>$html</figure>";
<?php
-if (!$User or !$User->admin('site')) {
+if (!$User->admin('site')) {
http_response_code(403);
?>
<h2>Verboden toegang</h2>
$message = "Je bent uitgelogd. Graag tot ziens!";
}
-if (empty($User)) {
+if (!$User or !$User->login) {
$Article->title = 'Inloggen';
if (isset($_REQUEST['goto'])) {
$target = ltrim($_REQUEST['goto'], '/');
if (isset($Article->raw)) {
print $Article->raw;
}
-if (empty($Args) and $User and $User->admin) {
+if (empty($Args) and $User->admin) {
include_once 'login/admin.html';
}
return TRUE;
}
}
-elseif (!$User) {
+elseif (!$User->login) {
http_response_code(303);
$target = urlencode($_SERVER['REQUEST_URI']);
header("Location: /login?goto=$target");
Dit zal de huidige code vervangen.
</p>
<p>
-<?php if ($User and strlen($User->pass)) { ?>
+<?php if ($User->login and strlen($User->pass)) { ?>
<input type="password" name="oldpass" value="" placeholder="Huidig wachtwoord" />
<?php } ?>
<input type="password" name="newpass" value="" placeholder="Nieuw wachtwoord" />
<?php
-if (!$User) {
+if (!$User->login) {
http_response_code(303);
$target = urlencode($_SERVER['REQUEST_URI']);
header("Location: /login?goto=$target");
<?php
-$replyform = $Page == 'melding' && !empty($User);
+$replyform = $Page == 'melding' && $User->login;
@list ($year, $page) = explode('/', trim($Args, '/'));
-if ($User and $User->admin("edit $Page")) {
+if ($User->admin("edit $Page")) {
print '<script src="/nieuws/edit.js"></script>'."\n";
}
if ($page and !is_numeric($page)) {
$Article->meta['og:type'] = 'article';
- $edit = $User && $User->admin("edit $Page$Args") ? htmlspecialchars(@$_GET['edit']) : NULL;
+ $edit = $User->admin("edit $Page$Args") ? htmlspecialchars(@$_GET['edit']) : NULL;
if ($edit) {
$Article->title = $edit;
}
$Place[1] = ' <small class="date">'.$Article->date.'</small>';
}
print preg_replace('{(?<=<h2>)(.*?)(?=</h2>)}', ($edit ?: '\1').' [[1]]', $Article->raw);
- if ($User and $User->admin("edit $Page$Args")) {
+ if ($User->admin("edit $Page$Args")) {
$taglist = [];
foreach (glob("$Page/.tags/*") as $tagpath) {
$tagname = pathinfo($tagpath, PATHINFO_BASENAME);
ob_start();
include 'menu.inc.html';
ob_start();
-if (!empty($User)) {
+if ($User and $User->login) {
print '<div class="login"><p>';
printf('<span>Ingelogd: <b><a href="%s">%s</a></b></span>', '/login', $User->login);
if ($User->admin("edit $Page$Args")) {
print "</footer>\n";
global $User, $Page, $Args;
- if (!empty($User) and $User->admin("edit $Page$Args")) {
+ if ($User and $User->admin("edit $Page$Args")) {
$ckesrc = '/lib/ckeditor'; # local install
if (!file_exists(DOCROOT . $ckesrc)) {
$ckesrc = '//cdn.ckeditor.com/4.7.3/full-all'; # remote fallback
# keep either login or logout parts depending on user level
global $User;
- $hideclass = empty($User) ? 'login' : 'logout';
+ $hideclass = $User && $User->login ? 'logout' : 'login';
$doc = preg_replace('{\s*<([a-z]+) class="'.$hideclass.'">.*?</\1>}s', '', $doc);
return preg_replace_callback(
# user login and control
-$User = NULL;
-include_once 'auth.inc.php';
+include_once 'auth.inc.php'; // sets global $User
$Edit = isset($_GET['edit']);
# setup requested page
if ($PageAccess = $Article->restricted) {
# access restriction
- if (empty($User)) {
+ if (!$User->login) {
http_response_code(303);
$target = urlencode($Article->link);
header("Location: /login?goto=$target");
ob_start(); # page body
$Place = [
- 'user' => $User ? $User->login : '',
+ 'user' => $User->login ?: '',
'url' => htmlspecialchars($_SERVER['REQUEST_URI']),
];
if (isset($Article->raw)) {
- if ($User and $User->admin("edit $Page$Args")) {
+ if ($User->admin("edit $Page$Args")) {
# restore meta tags in static contents for editing
foreach (array_reverse($Article->meta) as $metaprop => $val) {
$Article->raw = sprintf(
}
}
}
-elseif ($User and $User->admin("edit {$Article->link}")) {
+elseif ($User->admin("edit {$Article->link}")) {
$Article->raw(file_exists("$Page/template.inc.html") ? "$Page/template.inc.html" : 'template.inc.html');
}
if (isset($Article->raw)) {
if (empty($input)) {
return;
}
- if ($User and $User->admin and preg_match('/\A<[a-z][^>]*>/', $input)) {
+ if ($User->admin and preg_match('/\A<[a-z][^>]*>/', $input)) {
return $input; # allow html input as is if privileged
}
$html = preg_replace(
$error = NULL;
if ($_POST) {
global $User;
- if ($User) {
+ if ($User->login) {
$_REQUEST['login'] = $User->login;
$_REQUEST['email'] = $_REQUEST['email'] ?: $User->email;
}
<?php
global $User;
-if (empty($User)) {
+if (!$User->login) {
print '<em>niet ingelogd</em>';
return;
}
print "</li>\n";
}
-if ($User) {
+if ($User->login) {
print '<li>';
print '<form method="post" action="" enctype="multipart/form-data">';
if (isset($Issue) and $User->admin("edit $Page")) {