92 lines
2.7 KiB
PHP
92 lines
2.7 KiB
PHP
<?php
|
|
|
|
class Image {
|
|
public string $name;
|
|
public array $params;
|
|
public $content = "";
|
|
|
|
public function __construct($params = array())
|
|
{
|
|
$this->params = $params;
|
|
}
|
|
|
|
public function set_content($content)
|
|
{
|
|
$this->content = $content;
|
|
}
|
|
|
|
public function set_name($name)
|
|
{
|
|
$this->name = $name;
|
|
}
|
|
|
|
public function render_edit()
|
|
{
|
|
global $b;
|
|
|
|
if($this->content) {
|
|
$box_dom = new DOM("div");
|
|
$box_dom->setAttribute("class", "image-field__preview");
|
|
|
|
$preview_link_dom = new DOM("a");
|
|
$preview_link_dom->setAttribute("href", $b->file_get_link($this->content));
|
|
$preview_link_dom->setAttribute("target", "_blank");
|
|
|
|
$preview_dom = new DOM("img");
|
|
$preview_dom->setAttribute("src", $b->file_get_link($this->content));
|
|
$preview_dom->setAttribute("class", "image-field__preview-image");
|
|
$preview_link_dom->append($preview_dom);
|
|
$box_dom->append($preview_link_dom);
|
|
|
|
$hidden_dom = new DOM("input");
|
|
$hidden_dom->setAttribute("type", "hidden");
|
|
$hidden_dom->setAttribute("name", $this->name . "[file_id]");
|
|
$hidden_dom->setAttribute("value", $this->content);
|
|
$box_dom->append($hidden_dom);
|
|
|
|
$label_dom = new DOM("label");
|
|
$label_dom->setAttribute("class", "image-field__delete-label");
|
|
|
|
$p_dom = new DOM("p");
|
|
$p_dom->setAttribute("class", "image-field__delete-text");
|
|
$p_dom->append("Удалить");
|
|
|
|
$label_dom->append($p_dom);
|
|
|
|
$checkbox_dom = new DOM("input");
|
|
$checkbox_dom->setAttribute("type", "checkbox");
|
|
$checkbox_dom->setAttribute("class", "image-field__delete-checkbox");
|
|
$checkbox_dom->setAttribute("name", $this->name . "[delete]");
|
|
$label_dom->prepend($checkbox_dom);
|
|
|
|
$box_dom->append($label_dom);
|
|
$box_dom->view();
|
|
} else {
|
|
$input_dom = new DOM("input");
|
|
$input_dom->setAttribute("type", "file");
|
|
$input_dom->setAttribute("name", $this->name);
|
|
$input_dom->view();
|
|
}
|
|
}
|
|
|
|
public function render_value()
|
|
{
|
|
global $b;
|
|
return $b->file_get_link($this->content);
|
|
}
|
|
|
|
public function render_db_value()
|
|
{
|
|
global $b;
|
|
|
|
if (is_array($this->content)) {
|
|
if($this->content["delete"])
|
|
return "";
|
|
if($this->content["file_id"])
|
|
return $this->content["file_id"];
|
|
return $b->files_save($this->content);
|
|
} else {
|
|
return $this->content;
|
|
}
|
|
}
|
|
} |