login/list: retrieve optional user data on demand
authorMischa POSLAWSKY <perl@shiar.org>
Sat, 7 Jul 2018 20:27:19 +0000 (22:27 +0200)
committerMischa POSLAWSKY <perl@shiar.org>
Sat, 7 Jul 2018 21:41:08 +0000 (23:41 +0200)
Generic interface to run methods for missing variables.
Provides delay and caching to prevent unnecessary disk access.

auth.inc.php
login/list.php

index e4e8bb9b30dc4fb078b9907f15557a9505e1f9f0..af02ec3b41b6e915ce3b5fbbc1a2883695db5ab3 100644 (file)
@@ -8,6 +8,16 @@ class User
                $this->dir = $dir;
                $this->login = basename($dir);
        }
+
+       function __get($col)
+       {
+               return $this->$col = $this->$col();  # run method and cache
+       }
+
+       function name()
+       {
+               return @file_get_contents("{$this->dir}/name.txt");
+       }
 }
 
 function login_password_verify($input, $test)
index 86e8daf5490788316af492873f093bafd5472bf5..eee2dc57a59197bc735250a7949ea7848d1d88a7 100644 (file)
@@ -5,9 +5,7 @@ $users = glob("$basepath/*/");
 if (!$users) return;
 
 foreach ($users as $col => $userdir) {
-       $user = new User($userdir);
-       $user->name = @file_get_contents("{$user->dir}/name.txt");
-       $users[$col] = $user;
+       $users[$col] = new User($userdir);
 }
 
 print '<ul class="gallery cat">';