Start of using Attribute objects, rendering jpegphoto

This commit is contained in:
Deon George 2021-12-10 22:39:09 +11:00
parent dabca67fc8
commit 10a2d2161b
5 changed files with 20 additions and 52 deletions

View File

@ -95,6 +95,11 @@ class Attribute
*/
}
/**
* Determine how we render this attribute's value
*
* @return string
*/
public function __toString(): string
{
return join('<br>',$this->values);

View File

@ -6,55 +6,7 @@ use App\Classes\LDAP\Attribute;
/**
* Represents an attribute whose values are binary
*
* @package phpLDAPadmin
* @subpackage Templates
*/
class Binary extends Attribute
{
/*
protected $filepaths;
protected $filenames;
public function __construct($name,$values,$server_id,$source=null) {
parent::__construct($name,$values,$server_id,$source);
$this->filepaths = array();
$this->filenames = array();
}
public function getFileNames() {
return $this->filenames;
}
public function getFileName($i) {
if (isset($this->filenames[$i])) return $this->filenames[$i];
else return null;
}
public function addFileName($name, $i = -1) {
if ($i < 0) {
$this->filenames[] = $name;
} else {
$this->filenames[$i] = $name;
}
}
public function getFilePaths() {
return $this->filepaths;
}
public function getFilePath($i) {
if (isset($this->filepaths[$i])) return $this->filepaths[$i];
else return null;
}
public function addFilePath($path, $i = -1) {
if ($i < 0) {
$this->filepaths[] = $path;
} else {
$this->filepaths[$i] = $path;
}
}
*/
}

View File

@ -7,18 +7,19 @@ use App\Classes\LDAP\Attribute\Binary;
/**
* Represents an attribute whose values are jpeg pictures
*/
class JpegPhoto extends Binary
final class JpegPhoto extends Binary
{
public function __toString(): string
{
$result = '';
// We'll use finfo to try and figure out what type of image is stored
$f = new \finfo;
foreach ($this->values as $value) {
switch ($x=$f->buffer($value,FILEINFO_MIME_TYPE)) {
case 'image/jpeg':
default:
$result .= sprintf("<img style='display:block; width:100px;height:100px;' src='data:%s;base64, %s' />",$x,base64_encode($value));
$result .= sprintf('<img class="jpegphoto" src="data:%s;base64, %s" />',$x,base64_encode($value));
}
}

View File

@ -7,19 +7,24 @@ use Illuminate\Support\Facades\Log;
use App\Classes\LDAP\{Attribute};
/**
* This factory is used to return LDAP attributes as an object
*
* If there is no specific Attribute defined, then the default Attribute::class is return
*/
class Factory
{
private const LOGKEY = 'LAf';
/**
* @var array event type to event class mapping
* Map of attributes to appropriate class
*/
public const map = [
'jpegphoto'=>Attribute\Binary\JpegPhoto::class,
];
/**
* Returns new event instance
* Create the new Object for an attribute
*
* @param string $attribute
* @param array $values

5
public/css/custom.css vendored Normal file
View File

@ -0,0 +1,5 @@
img.jpegphoto {
display:block;
max-width:100px;
height:100px;
}