26 protected $binary = TRUE;
28 function loadPostValue ()
30 $this->postValue = $this->value;
31 if (!empty($_FILES[$this->getHtmlId()][
'name']) && $this->isVisible()) {
32 if ($_FILES[$this->getHtmlId()][
'size'] <= 0) {
36 _(
'Cannot read uploaded file: %s'),
41 } elseif (!file_exists($_FILES[$this->getHtmlId()][
'tmp_name'])) {
46 _(
'Cannot read uploaded file: %s'),
51 } elseif (!$handle = @fopen($_FILES[$this->getHtmlId()][
'tmp_name'],
'r')) {
56 _(
'Cannot read uploaded file: %s'),
57 _(
'file not readable')
68 $_FILES[$this->getHtmlId()][
'name'] =
"";
78 $postValue = fread($handle, 1024);
79 while (!feof($handle)) {
80 $postValue .= fread($handle, 1024);
86 function renderFormInput ():
string 88 $id = $this->getHtmlId();
89 $display = $this->renderInputField(
'file', $id);
93 function displayValue ($value):
string 95 return sprintf(_(
'%s (%d bytes)'), $this->getLabel(), mb_strlen($value,
'8bit'));
105 if (!$form || $this->visible) {
106 parent::serializeAttribute($attributes, $form);
109 $attributes[$this->getLdapName()][
'binary'] = TRUE;
120 if ($value === NULL) {
121 $value = $this->getValue();
124 return base64_encode($value);
136 if ($this->disabled) {
139 htmlescape(sprintf(_(
'Attribute %s is disabled, its value could not be set'), $this->getLdapName()))
143 $data = base64_decode($value, TRUE);
144 if ($data === FALSE) {
150 $this->setValue($data);
152 $this->setValue($value);
162 protected $extension;
164 protected $download = TRUE;
166 function __construct ($label, $description, $ldapName, $required = FALSE, $extension =
'', $upload = FALSE, $defaultValue =
"", $acl =
"")
168 parent::__construct($label, $description, $ldapName, $required, $defaultValue, $acl);
169 $this->extension = $extension;
170 $this->upload = $upload;
171 $this->binary = ($extension !=
'.txt');
174 function computeFilename ()
176 return $this->getLdapName().$this->extension;
179 function loadPostValue ()
181 if ($this->isVisible()) {
182 $this->postValue = $this->value;
183 if ($this->download) {
184 foreach (array_keys($_POST) as $name) {
185 if (preg_match(
'/^download'.$this->getHtmlId().
'/', $name)) {
189 header(
'location: getbin.php');
194 if ($this->upload && isset($_POST[
'upload'.$this->getHtmlId()])) {
195 parent::loadPostValue();
200 function renderFormInput ():
string 202 $id = $this->getHtmlId();
205 $display .= $this->renderInputField(
'file', $id);
206 $display .= $this->renderInputField(
'submit',
'upload'.$id, [
'value' => _(
'Upload'),
'formnovalidate' =>
'formnovalidate']);
208 if ($this->download) {
209 $display .= $this->renderInputField(
210 'image',
'download'.$id,
212 'title' => _(
'Download'),
213 'alt' => _(
'Download'),
215 'src' =>
'geticon.php?context=actions&icon=document-save&size=16',
222 public function htmlIds (): array
224 $id = $this->getHtmlId();
226 if ($this->download) {
227 $ids[] =
'download'.$id;
231 $ids[] =
'upload'.$id;
236 function renderAttribute (array &$attributes,
bool $readOnly,
bool $readable,
bool $writable)
238 if ($this->upload === FALSE) {
239 parent::renderAttribute($attributes, FALSE, $readable, $writable);
241 parent::renderAttribute($attributes, $readOnly, $readable, $writable);
252 function __construct ($label, $description, $ldapName, $required = FALSE, $extension =
'.txt', $upload = TRUE, $download = TRUE, $defaultValue =
'', $acl =
'')
255 $label, $description, $ldapName, $required,
256 $extension, $upload, $defaultValue, $acl
258 $this->download = $download;
265 if ($this->isVisible()) {
266 $this->postValue = $this->value;
267 if ($this->download) {
268 foreach (array_keys($_POST) as $name) {
269 if (preg_match(
'/^download'.$this->getHtmlId().
'/', $name)) {
273 header(
'location: getbin.php');
279 if (isset($_POST[
'upload'.$this->getHtmlId()])) {
280 parent::loadPostValue();
282 $id = $this->getHtmlId().
'_text';
283 if (isset($_POST[$id])) {
294 return str_replace([
"\r\n",
"\r"],
"\n", $value);
297 function renderFormInput ():
string 299 $id = $this->getHtmlId();
300 $display =
'<textarea name="'.$id.
'_text" id="'.$id.
'_text"'.
301 ($this->disabled ?
'disabled="disabled"' :
'').
'>'.
302 '{literal}'.
htmlescape($this->getValue()).
'{/literal}</textarea><br/>';
303 return $this->
renderAcl($display).parent::renderFormInput();
306 public function htmlIds (): array
308 $id = $this->getHtmlId();
309 $ids = parent::htmlIds();
310 $ids[] = $id.
'_text';
323 protected $forceSize;
324 protected $placeholder;
326 protected $imagickException;
328 function __construct ($label, $description, $ldapName, $required = FALSE, $width = 48, $height = 48, $format =
'png', $forceSize = FALSE, $defaultValue =
"", $acl =
"")
330 parent::__construct($label, $description, $ldapName, $required, $defaultValue, $acl);
331 $this->width = $width;
332 $this->height = $height;
333 $this->format = $format;
334 $this->forceSize = $forceSize;
337 function setPlaceholder ($placeholder)
339 $this->placeholder = $placeholder;
346 $this->postValue = $this->value;
347 $id = $this->getHtmlId();
348 if (!$this->disabled && $this->isVisible()) {
349 foreach (array_keys($_POST) as $name) {
350 if (!$this->isRequired() && preg_match(
'/^'.$id.
'_remove_/', $name)) {
354 if (preg_match(
'/^'.$id.
'_upload_/', $name)) {
355 parent::loadPostValue();
362 function setValue ($value)
364 $this->imagickException = NULL;
369 if (class_exists(
'Imagick')) {
373 $im->readImageBlob($value);
375 $size = $im->getImageGeometry();
378 ($size[
'width'] > 0 && $size[
'height'] > 0) &&
380 ($size[
'width'] < $this->width && $size[
'height'] < $this->height) ||
381 ($size[
'width'] > $this->width) ||
382 ($size[
'height'] > $this->height)
386 $im->resizeImage($this->width, $this->height, Imagick::FILTER_GAUSSIAN, 1, !$this->forceSize);
389 if ($modify || !preg_match(
'/^'.$this->format.
'$/i', $im->getImageFormat())) {
390 if ($this->format ==
'jpeg') {
391 $im->setImageCompression(Imagick::COMPRESSION_JPEG);
392 $im->setImageCompressionQuality(90);
394 $im->setImageFormat($this->format);
397 $this->value = $im->getImageBlob();
399 $this->value = $value;
401 }
catch (ImagickException $e) {
409 $this->imagickException->display();
414 htmlescape(_(
'Cannot save user picture, FusionDirectory requires the PHP module "imagick" to be installed!'))
426 $error = parent::deserializeValue($value);
427 if (!empty($error)) {
430 if ($this->imagickException !== NULL) {
431 return $this->imagickException;
435 function renderFormInput ():
string 437 $this->setValue($this->
inputValue($this->getValue()));
438 $id = $this->getHtmlId();
440 $key = $this->getLdapName().random_int(0, 10000);
441 $display =
'<img id="'.$id.
'_img"'.
442 ($this->disabled ?
'disabled="disabled"' :
'').
443 ' src="getbin.php?key='.$key.
'"'.
444 ' style="border:1px solid black;"'.
445 ' alt="'.htmlescape($this->getDescription()).
'"'.
446 ' title="'.
htmlescape($this->getDescription()).
'"'.
448 $display .= $this->renderInputField(
'file', $id);
449 $display .= $this->renderInputField(
450 'image', $id.
'_upload',
453 'src' =>
'geticon.php?context=actions&icon=upload&size=16',
454 'title' => _(
'Upload'),
458 if (!$this->isRequired()) {
459 $display .= $this->renderInputField(
460 'image', $id.
'_remove',
463 'src' =>
'geticon.php?context=actions&icon=remove&size=16',
464 'title' => _(
'Remove'),
469 if (($this->getValue() ==
'') && ($this->placeholder !=
'')) {
478 public function htmlIds (): array
480 $id = $this->getHtmlId();
481 return [$id.
'_img',$id,
'upload'.$id];
488 if ($this->isInLdap()) {
491 if ($this->isTemplate()) {
493 $value =
'%%'.$value;
495 $attrs[$this->getLdapName()] = $value;
497 $attrs[$this->getLdapName()] = [];
505 return preg_replace(
'/^%%/',
'', $value);
serializeValue($value=NULL)
Serialize value for RPC requests.
htmlescape(string $str)
Escape string for HTML output.
deserializeValue($value)
Apply value from RPC requests.
deserializeValue($value)
Apply value from RPC requests.
FileAttribue with a download button.
loadPostValue()
Update this attributes postValue depending of the $_POST values.
readFile($handle)
This function read the file from the given handle and then closes it.
Error returned by any method of SimplePlugin.
static set($name, $value)
Set a value in a session.
serializeAttribute(array &$attributes, bool $form=TRUE)
Serialize this attribute for RPC requests.
fixPostValue($value)
In case a treatment is needed on POSTÂ content.
static invalidValue(string $error)
Format error message for invalid value.
Attribute for storing an image.
fillLdapValue(array &$attrs)
Fill LDAP value in the attrs array.
renderAttribute(array &$attributes, bool $readOnly, bool $readable, bool $writable)
Render this attribute form input(s)
setPostValue($value)
Set the postValue.
renderAcl(string $display)
Add ACL information around display.
computeLdapValue()
Computes LDAP value.
A FileDownloadAttribute which displays a text area to edit the value.
inputValue($ldapValue)
Return the ldap value in the correct intern format value.
This class allow to handle easily an File LDAP attribute.
This class allow to handle easily any kind of LDAP attribute.
loadPostValue()
Update this attributes postValue depending of the $_POST values.
__construct(string $label, string $description, string $ldapName, bool $required=FALSE, $defaultValue='', string $acl='')
The constructor of Attribute.