Clean PHP code.

This commit is contained in:
Lars Jung 2015-05-12 01:18:14 +02:00
parent 788f4f047c
commit e199be6363
5 changed files with 16 additions and 15 deletions

View file

@ -2,7 +2,7 @@
class App {
const AS_ADMIN_SESSION_KEY = 'AS_ADMIN';
private static $AS_ADMIN_SESSION_KEY = 'AS_ADMIN';
private $request;
private $setup;
@ -49,19 +49,19 @@ class App {
public function login_admin($pass) {
$hash = $this->setup->get('PASSHASH');
$this->session->set(App::AS_ADMIN_SESSION_KEY, strcasecmp(hash('sha512', $pass), $hash) === 0);
return $this->session->get(App::AS_ADMIN_SESSION_KEY);
$this->session->set(App::$AS_ADMIN_SESSION_KEY, strcasecmp(hash('sha512', $pass), $hash) === 0);
return $this->session->get(App::$AS_ADMIN_SESSION_KEY);
}
public function logout_admin() {
$this->session->set(App::AS_ADMIN_SESSION_KEY, false);
return $this->session->get(App::AS_ADMIN_SESSION_KEY);
$this->session->set(App::$AS_ADMIN_SESSION_KEY, false);
return $this->session->get(App::$AS_ADMIN_SESSION_KEY);
}
public function is_admin() {
return $this->session->get(App::AS_ADMIN_SESSION_KEY);
return $this->session->get(App::$AS_ADMIN_SESSION_KEY);
}
public function to_href($path, $trailing_slash = true) {

View file

@ -2,7 +2,8 @@
class Session {
private static $key_prefix = '__H5AI__';
private static $KEY_PREFIX = '__H5AI__';
private $store;
public function __construct(&$store) {
@ -12,13 +13,13 @@ class Session {
public function set($key, $value) {
$key = Session::$key_prefix . $key;
$key = Session::$KEY_PREFIX . $key;
$this->store[$key] = $value;
}
public function get($key, $default = null) {
$key = Session::$key_prefix . $key;
$key = Session::$KEY_PREFIX . $key;
return array_key_exists($key, $this->store) ? $this->store[$key] : $default;
}
}

View file

@ -2,7 +2,7 @@
class Setup {
const DEFAULT_PASSHASH = 'cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e';
private static $DEFAULT_PASSHASH = 'cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e';
private $store;
@ -85,7 +85,7 @@ class Setup {
private function add_admin_check() {
$this->set('HAS_CUSTOM_PASSHASH', strtolower(PASSHASH) === strtolower(Setup::DEFAULT_PASSHASH));
$this->set('HAS_CUSTOM_PASSHASH', strtolower(PASSHASH) === Setup::$DEFAULT_PASSHASH);
}
private function add_server_metadata_and_check() {

View file

@ -2,7 +2,7 @@
class Theme {
private static $extensions = ['svg', 'png', 'jpg'];
private static $EXTENSIONS = ['svg', 'png', 'jpg'];
public function __construct($app) {
@ -21,7 +21,7 @@ class Theme {
if ($dir = opendir($theme_path)) {
while (($name = readdir($dir)) !== false) {
$path_parts = pathinfo($name);
if (in_array(@$path_parts['extension'], Theme::$extensions)) {
if (in_array(@$path_parts['extension'], Theme::$EXTENSIONS)) {
$icons[$path_parts['filename']] = $theme . '/' . $name;
}
}

View file

@ -2,7 +2,7 @@
class Custom {
private static $extensions = ['html', 'md'];
private static $EXTENSIONS = ['html', 'md'];
public function __construct($app) {
@ -13,7 +13,7 @@ class Custom {
$file_prefix = $this->app->get_setup()->get('FILE_PREFIX');
foreach (Custom::$extensions as $ext) {
foreach (Custom::$EXTENSIONS as $ext) {
$file = $path . '/' . $file_prefix . '.' . $name . '.' . $ext;
if (is_readable($file)) {
$content = file_get_contents($file);