Initial commit
This commit is contained in:
32
playarea/plugins/bive-admin-panel/scripts/admin.php
Normal file
32
playarea/plugins/bive-admin-panel/scripts/admin.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
defined( 'ROOT_DIR' ) || exit;
|
||||
|
||||
require_once $plugin_path . "scripts/fields.php";
|
||||
require_once $plugin_path . "scripts/datatypes.php";
|
||||
require_once $plugin_path . "scripts/auth.php";
|
||||
require_once $plugin_path . "scripts/settings.php";
|
||||
require_once $plugin_path . "scripts/wingman.php";
|
||||
require_once $plugin_path . "scripts/links.php";
|
||||
|
||||
// ROUTERS
|
||||
$b->router_add("/" . ADMIN_PAGE . "/%", "bive-admin-panel/template/index.php", array("get", "post"));
|
||||
$b->event_add(base64_encode("/" . ADMIN_PAGE . "/%"), "admin_page");
|
||||
|
||||
function admin_page()
|
||||
{
|
||||
global $b;
|
||||
$b->title_set("Bive - Admin Panel");
|
||||
$b->meta_add("viewport", "width=device-width, initial-scale=1.0");
|
||||
$b->meta_add("description", "Bive Engine is an effective solution for creating websites.");
|
||||
$b->link_add(array("rel" => "preconnect", "href" => "https://fonts.googleapis.com"));
|
||||
$b->link_add(array("rel" => "preconnect", "href" => "https://fonts.gstatic.com"));
|
||||
$b->link_add(array("rel" => "stylesheet", "href" => "https://fonts.googleapis.com/css2?family=Inter:wght@100;200;300;400;500;600;700;800;900&display=swap"));
|
||||
$b->script_add(array("src" => "https://cdn.ckeditor.com/4.22.1/standard/ckeditor.js", "referrerpolicy" => "origin"));
|
||||
$b->link_add(array("rel" => "stylesheet", "href" => "/playarea/plugins/bive-admin-panel/assets/styles/b-styles.css"));
|
||||
$b->link_add(array("rel" => "stylesheet", "href" => "/playarea/plugins/bive-admin-panel/assets/styles/styles.css"));
|
||||
$b->link_add(array("rel" => "stylesheet", "href" => "/playarea/plugins/bive-admin-panel/assets/styles/visor.css"));
|
||||
}
|
||||
|
||||
$admin_page = $_GET["page"] ?? "dashboard";
|
||||
$b->ls_set_key("admin_page", $admin_page);
|
||||
37
playarea/plugins/bive-admin-panel/scripts/auth.php
Normal file
37
playarea/plugins/bive-admin-panel/scripts/auth.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
defined( 'ROOT_DIR' ) || exit;
|
||||
|
||||
// EVENTS
|
||||
|
||||
$b->event_add("login", "form_event");
|
||||
|
||||
function form_event($args)
|
||||
{
|
||||
global $b;
|
||||
|
||||
$login = $args["login"];
|
||||
$password = $args["password"];
|
||||
|
||||
$search = new Search(array(
|
||||
"class" => "User",
|
||||
"props" => array(
|
||||
"username" => $login
|
||||
),
|
||||
"limit" => 1,
|
||||
"offset" => 0
|
||||
));
|
||||
|
||||
$result = $search->collect();
|
||||
$user = $result[0];
|
||||
|
||||
if(!$user || !$user->check_password($password)) {
|
||||
$b->alerts_add("Неверный логин или пароль. Попробуйте снова.", "error", "login");
|
||||
return false;
|
||||
};
|
||||
|
||||
$b->session_set("user_id", $user->item_id);
|
||||
}
|
||||
|
||||
$b->router_add("/" . ADMIN_PAGE . "/login/", "bive-admin-panel/template/login.php", array("get", "post"));
|
||||
$b->event_add(base64_encode("/" . ADMIN_PAGE . "/login/"), "admin_page");
|
||||
160
playarea/plugins/bive-admin-panel/scripts/datatypes.php
Normal file
160
playarea/plugins/bive-admin-panel/scripts/datatypes.php
Normal file
@@ -0,0 +1,160 @@
|
||||
<?php
|
||||
|
||||
defined( 'ROOT_DIR' ) || exit;
|
||||
|
||||
$b->event_add("engine_loaded", "add_admin_datatypes");
|
||||
|
||||
function add_admin_datatypes()
|
||||
{
|
||||
global $b;
|
||||
$datatypes = $b->datatypes;
|
||||
|
||||
foreach ($datatypes as $key => $value) {
|
||||
$item = new $value(0);
|
||||
$title = $item->title;
|
||||
if(!$item->admin_menu) continue;
|
||||
|
||||
$parent_slug = "datatype_" . $value;
|
||||
|
||||
$b->admin_page_set("content", $parent_slug, $title, array("datatype" => $value), "page_datatype", false, $item->icon);
|
||||
$b->admin_page_set($parent_slug, "item_" . $value, "Изменение", array(), "page_datatype_edit", true);
|
||||
$b->admin_page_set($parent_slug, "item_add_" . $value, "Добавить", array("datatype" => $value), "page_datatype_new", false, "add");
|
||||
}
|
||||
}
|
||||
|
||||
$b->router_add("/" . ADMIN_PAGE . "/trashItem/", function () { trashItem(); }, array("get", "post"));
|
||||
|
||||
function trashItem()
|
||||
{
|
||||
global $b;
|
||||
$item_id = $_GET["item_id"];
|
||||
$item = $b->get_item_by_id($item_id);
|
||||
$class_name = $item->get_class_name();
|
||||
$item->delete();
|
||||
$get_params = $b->router_format_get_params(array("datatype" => $class_name, "page" => "datatype_" . $class_name));
|
||||
$b->router_redirect("/admin/$get_params");
|
||||
exit();
|
||||
}
|
||||
|
||||
function page_datatype()
|
||||
{
|
||||
global $b;
|
||||
$b->template_load("bive-admin-panel/template/datatype/datatypes.php");
|
||||
};
|
||||
|
||||
function page_datatype_edit()
|
||||
{
|
||||
global $b;
|
||||
admin_page_title();
|
||||
$b->template_load("bive-admin-panel/template/datatype/datatype_edit.php");
|
||||
};
|
||||
|
||||
function page_datatype_new()
|
||||
{
|
||||
global $b;
|
||||
admin_page_title();
|
||||
$b->template_load("bive-admin-panel/template/datatype/datatype_new.php");
|
||||
};
|
||||
|
||||
function admin_page_title()
|
||||
{
|
||||
global $b;
|
||||
|
||||
$pages = $b->admin_pages_list;
|
||||
$admin_page = $_GET["page"];
|
||||
$title = $pages[$admin_page]["title"];
|
||||
|
||||
$h1_dom = new DOM("h1");
|
||||
$h1_dom->setAttribute("class", "page_name");
|
||||
$h1_dom->append($title);
|
||||
|
||||
$div_dom = new DOM("div");
|
||||
$div_dom->setAttribute("class", "page_wrapper");
|
||||
$div_dom->prepend($h1_dom);
|
||||
$div_dom->view();
|
||||
}
|
||||
|
||||
$b->event_add("datatype_save", "datatype_save");
|
||||
|
||||
function datatype_save($args)
|
||||
{
|
||||
global $b;
|
||||
$item_id = $args["item_id"];
|
||||
|
||||
$search = new Search(array(
|
||||
"limit" => 1,
|
||||
"terms" => array("item_id" => $item_id)
|
||||
));
|
||||
|
||||
list($item) = $search->collect();
|
||||
|
||||
$item->set_field("item_name", $args["item_name"]);
|
||||
$item->set_field("item_content", $args["item_content"]);
|
||||
$item->set_field("item_slug", $args["item_slug"]);
|
||||
|
||||
if(isset($args["item_parents"])){
|
||||
$item->clear_parents($item->parent_class);
|
||||
foreach ($args["item_parents"] as $key => $parent_id)
|
||||
$item->set_parent($parent_id);
|
||||
if(isset($args["item_parent"]))
|
||||
$item->set_parent($args["item_parent"], true);
|
||||
}
|
||||
|
||||
foreach ($args as $arg => $value) {
|
||||
$item->set_prop($arg, $value);
|
||||
}
|
||||
|
||||
$b->alerts_add("Данные успешно сохранены.", "info", "admin_item");
|
||||
|
||||
if($args["b_wingman"]) {
|
||||
$b->template_load("bive-admin-panel/template/datatype/datatype_edit.php");
|
||||
exit();
|
||||
}
|
||||
|
||||
$b->router_refresh();
|
||||
exit();
|
||||
}
|
||||
|
||||
$b->event_add("datatype_new", "datatype_new");
|
||||
|
||||
function datatype_new($args)
|
||||
{
|
||||
global $b;
|
||||
$datatype = $args["datatype"];
|
||||
|
||||
$item = new $datatype(0);
|
||||
$item->create($args["item_name"], $args["item_content"], 0);
|
||||
$item->set_field("item_slug", $args["item_slug"]);
|
||||
$item_id = $item->item_id;
|
||||
|
||||
foreach ($args as $arg => $value)
|
||||
$item->set_prop($arg, $value);
|
||||
|
||||
if($args["b_wingman"]) {
|
||||
exit(json_encode(array("redirect" => "/admin/" . $b->router_format_get_params(array("page" => "item_" . $datatype, "item_id" => $item_id)) )));
|
||||
}
|
||||
|
||||
$b->router_redirect("/admin/" . $b->router_format_get_params(array("page" => "item_" . $datatype, "item_id" => $item_id)));
|
||||
exit();
|
||||
}
|
||||
|
||||
// Link Fields
|
||||
|
||||
$redirect_field = new Text();
|
||||
$short_code_field = new Text();
|
||||
$clicks_field = new Text();
|
||||
|
||||
$b->field_register("redirect", $redirect_field);
|
||||
$b->field_register("short_code", $short_code_field);
|
||||
$b->field_register("clicks", $clicks_field);
|
||||
|
||||
// User Fields
|
||||
|
||||
$username_field = new Text();
|
||||
$reg_time_field = new Date();
|
||||
$password_field = new Password();
|
||||
|
||||
$b->field_register("username", $username_field);
|
||||
$b->field_register("reg_time", $reg_time_field);
|
||||
$b->field_register("password", $password_field);
|
||||
|
||||
41
playarea/plugins/bive-admin-panel/scripts/fields.php
Normal file
41
playarea/plugins/bive-admin-panel/scripts/fields.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
defined( 'ROOT_DIR' ) || exit;
|
||||
|
||||
require_once $plugin_path . "scripts/fields/field.separator.php";
|
||||
$plain_separator_field = new Separator();
|
||||
$b->field_register("plain_separator", $plain_separator_field);
|
||||
|
||||
require_once $plugin_path . "scripts/fields/field.text.php";
|
||||
$plain_text_field = new Text();
|
||||
$b->field_register("plain_text", $plain_text_field);
|
||||
|
||||
require_once $plugin_path . "scripts/fields/field.link.php";
|
||||
$plain_link_field = new Link();
|
||||
$b->field_register("plain_link", $plain_link_field);
|
||||
|
||||
require_once $plugin_path . "scripts/fields/field.text_readonly.php";
|
||||
$plain_text_readonly_field = new Text_Readonly();
|
||||
$b->field_register("plain_text_readonly", $plain_text_readonly_field);
|
||||
|
||||
require_once $plugin_path . "scripts/fields/field.date.php";
|
||||
$plain_date_field = new Date();
|
||||
$b->field_register("plain_date", $plain_date_field);
|
||||
|
||||
require_once $plugin_path . "scripts/fields/field.image.php";
|
||||
$plain_image_field = new Image();
|
||||
$b->field_register("plain_image", $plain_image_field);
|
||||
|
||||
require_once $plugin_path . "scripts/fields/field.password.php";
|
||||
$plain_password_field = new Password();
|
||||
$b->field_register("plain_password", $plain_password_field);
|
||||
|
||||
require_once $plugin_path . "scripts/fields/field.bigtext.php";
|
||||
$plain_bigtext_field = new Bigtext();
|
||||
$b->field_register("plain_bigtext", $plain_bigtext_field);
|
||||
|
||||
require_once $plugin_path . "scripts/fields/field.multifield.php";
|
||||
$plain_multifield_field = new Multifield(array("fields" => array("title" => array("plain_text", "Заголовок"), "link" => array("plain_link", "Ссылка"))));
|
||||
$b->field_register("plain_links", $plain_multifield_field);
|
||||
|
||||
require_once $plugin_path . "scripts/fields/field.attribute.php";
|
||||
@@ -0,0 +1,153 @@
|
||||
<?php
|
||||
|
||||
class AttributeField {
|
||||
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;
|
||||
$item_id = $_GET["item_id"];
|
||||
if(!isset($item_id)) {
|
||||
echo "Редактировать атрибуты можно только после создания объекта.";
|
||||
return;
|
||||
}
|
||||
$item = $b->get_item_by_id($item_id);
|
||||
|
||||
$search = new Search(array(
|
||||
"class" => "Attribute",
|
||||
));
|
||||
|
||||
$items = $search->collect();
|
||||
$attributes = $item->get_parent_items("Attribute");
|
||||
$ai = $item->get_child_items("Attribute_Item");
|
||||
?>
|
||||
|
||||
<?php if(count($attributes)) { ?>
|
||||
<div class="bive-attributes">
|
||||
<?php foreach ($attributes as $arg => $attribute) { ?>
|
||||
<div class="bive-attributes_row">
|
||||
<div class="bive-attributes__wrapper">
|
||||
<div class="bive-attributes__title">
|
||||
<?= $attribute->get_item_name(); ?>
|
||||
</div>
|
||||
<div class="bive-attributes__items">
|
||||
<?php foreach ($ai as $key => $a) { ?>
|
||||
<?php if($a->parent_id != $attribute->get_item_id()) continue; ?>
|
||||
<div class="bive-attributes__item">
|
||||
<div class="bive-attributes__item-text"><?= $a->get_item_name(); ?></div>
|
||||
<button type="submit" class="bive-attributes__item-remove" name="<?= $this->name . "[" . $attribute->get_item_id() . "][remove]"; ?>" value="<?= $a->get_item_id(); ?>">x</button>
|
||||
</div>
|
||||
<?php } ?>
|
||||
<div class="bive-attributes__item-new">
|
||||
<input class="bive-attributes__item-input" type="text" name="<?= $this->name . "[" . $attribute->get_item_id() . "][new]"; ?>" placeholder="Новый атрибут">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<button type="submit" class="bive-attributes__remove" name="<?= $this->name . "[remove]"; ?>" value="<?= $attribute->get_item_id(); ?>">X</button>
|
||||
</div>
|
||||
<?php } ?>
|
||||
</div>
|
||||
<?php } ?>
|
||||
|
||||
<div>
|
||||
<select class="bive-select" name="<?= $this->name . "[new][attribute]"; ?>">
|
||||
<?php foreach ($items as $arg => $item) { ?>
|
||||
<option value="<?= $item->get_item_id(); ?>"><?= $item->get_item_name(); ?></option>
|
||||
<?php } ?>
|
||||
</select>
|
||||
<button type="submit" class="btn btn-primary mb-1 ml-1 mt-1" name="<?= $this->name . "[new][button]"; ?>" value="1">Добавить</button>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
}
|
||||
|
||||
public function render_value()
|
||||
{
|
||||
return $this->content;
|
||||
}
|
||||
|
||||
public function render_db_value()
|
||||
{
|
||||
global $b;
|
||||
$item_id = $_GET["item_id"];
|
||||
if(!isset($item_id)) return "";
|
||||
$item = $b->get_item_by_id($item_id);
|
||||
if (is_array($this->content)) {
|
||||
foreach ($this->content as $key => $data) {
|
||||
if ((string) $key == "new" && isset($data["button"])) {
|
||||
$item->set_parent($data["attribute"], false);
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((string) $key == "remove") {
|
||||
$item->clear_parent($data);
|
||||
continue;
|
||||
}
|
||||
|
||||
if((string) $data["new"] !== "") {
|
||||
$parent_id = $key;
|
||||
$slug = $this->translit_sef($data["new"]);
|
||||
$search = new Search(array(
|
||||
"class" => "Attribute_Item",
|
||||
"terms" => array("item_slug" => $slug),
|
||||
"parent_id" => $parent_id
|
||||
));
|
||||
$items = $search->collect();
|
||||
if(!$items) {
|
||||
$ai = new Attribute_Item(0);
|
||||
$ai->create($data["new"], "");
|
||||
$ai->set_field("item_slug", $slug);
|
||||
$ai->set_parent($parent_id, true);
|
||||
$ai->set_parent($item_id);
|
||||
} else {
|
||||
$items[0]->set_parent($item_id);
|
||||
}
|
||||
}
|
||||
|
||||
if((string) $data["remove"] !== "") {
|
||||
$parent = $b->get_item_by_id($data["remove"]);
|
||||
$parent->clear_parent($item_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
private function translit_sef($value)
|
||||
{
|
||||
$converter = array(
|
||||
'а' => 'a', 'б' => 'b', 'в' => 'v', 'г' => 'g', 'д' => 'd',
|
||||
'е' => 'e', 'ё' => 'e', 'ж' => 'zh', 'з' => 'z', 'и' => 'i',
|
||||
'й' => 'y', 'к' => 'k', 'л' => 'l', 'м' => 'm', 'н' => 'n',
|
||||
'о' => 'o', 'п' => 'p', 'р' => 'r', 'с' => 's', 'т' => 't',
|
||||
'у' => 'u', 'ф' => 'f', 'х' => 'h', 'ц' => 'c', 'ч' => 'ch',
|
||||
'ш' => 'sh', 'щ' => 'sch', 'ь' => '', 'ы' => 'y', 'ъ' => '',
|
||||
'э' => 'e', 'ю' => 'yu', 'я' => 'ya',
|
||||
);
|
||||
|
||||
$value = mb_strtolower($value);
|
||||
$value = strtr($value, $converter);
|
||||
$value = mb_ereg_replace('[^-0-9a-z]', '-', $value);
|
||||
$value = mb_ereg_replace('[-]+', '-', $value);
|
||||
$value = trim($value, '-');
|
||||
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
class Bigtext {
|
||||
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()
|
||||
{
|
||||
$bive_textarea_dom = new DOM("div");
|
||||
$bive_textarea_dom->setAttribute("class", "bive-textarea mb-1");
|
||||
|
||||
$bive_textarea_content_dom = new DOM("textarea", true);
|
||||
$bive_textarea_content_dom->setAttribute("type", "text");
|
||||
$bive_textarea_content_dom->setAttribute("class", "bive-textarea__content");
|
||||
$bive_textarea_content_dom->setAttribute("id", $this->name);
|
||||
$bive_textarea_content_dom->setAttribute("name", $this->name);
|
||||
$bive_textarea_content_dom->append($this->content);
|
||||
|
||||
$bive_textarea_dom->append($bive_textarea_content_dom);
|
||||
$bive_textarea_dom->view();
|
||||
}
|
||||
|
||||
public function render_value()
|
||||
{
|
||||
return $this->content;
|
||||
}
|
||||
|
||||
public function render_db_value()
|
||||
{
|
||||
if(!$this->content) return "";
|
||||
return $this->content;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
class Date {
|
||||
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()
|
||||
{
|
||||
$input_dom = new DOM("input");
|
||||
$input_dom->setAttribute("type", "text");
|
||||
$input_dom->setAttribute("name", $this->name);
|
||||
$input_dom->setAttribute("value", $this->content);
|
||||
$input_dom->view();
|
||||
}
|
||||
|
||||
public function render_value()
|
||||
{
|
||||
return date("H:m:s d.m.Y", $this->content);
|
||||
}
|
||||
|
||||
public function render_db_value()
|
||||
{
|
||||
if(!$this->content) return time();
|
||||
return $this->content;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
class Link {
|
||||
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;
|
||||
$input_dom = new DOM("input", false);
|
||||
$input_dom->setAttribute("type", "text");
|
||||
$input_dom->setAttribute("name", $this->name);
|
||||
$input_dom->setAttribute("placeholder", "Укажите абсолютную или относительную ссылку");
|
||||
$input_dom->setAttribute("value", $b->get_view($this->content));
|
||||
$input_dom->view();
|
||||
}
|
||||
|
||||
public function render_value()
|
||||
{
|
||||
return $this->content;
|
||||
}
|
||||
|
||||
public function render_db_value()
|
||||
{
|
||||
return $this->content;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
<?php
|
||||
|
||||
class Multifield {
|
||||
public string $name;
|
||||
public array $params;
|
||||
public $content = "";
|
||||
|
||||
public function __construct($params = array())
|
||||
{
|
||||
$this->params = $params;
|
||||
}
|
||||
|
||||
public function set_content($content)
|
||||
{
|
||||
if(is_array($content)) {
|
||||
$this->content = $content;
|
||||
return;
|
||||
}
|
||||
if(!$content) $content = "[]";
|
||||
$this->content = json_decode(trim($content), true);
|
||||
}
|
||||
|
||||
public function set_name($name)
|
||||
{
|
||||
$this->name = $name;
|
||||
}
|
||||
|
||||
public function render_edit()
|
||||
{
|
||||
global $b;
|
||||
|
||||
?><div class="bive-multifield"><?php
|
||||
|
||||
?><div class="bive-multifield__wrapper" data-level="<?= $this->name; ?>"><?php
|
||||
foreach ($this->content as $key => $data)
|
||||
{
|
||||
?><div class="bive-multifield__row"><?php
|
||||
?><div class="input-number"><?= $key; ?></div><?php
|
||||
|
||||
?><div class="input-row"><?php
|
||||
foreach ($this->params["fields"] as $arg => $field)
|
||||
{
|
||||
?><div class="input-group"><?php
|
||||
?><div class="input-label">
|
||||
<p class="input-label__inner"><?= $field[1]; ?></p>
|
||||
<p class="input-label__background"><?= $arg;?></p>
|
||||
</div><?php
|
||||
|
||||
?><div class="input-edit"><?php
|
||||
$b->field_render_edit($field[0], $this->name . "[$key][$arg]", $data[$arg]);
|
||||
?></div><?php
|
||||
?></div><?php
|
||||
}
|
||||
?></div><?php
|
||||
|
||||
?><button type="submit" class="btn-remove" name="<?= $this->name . "[$key]"; ?>" value="remove">X</button>
|
||||
</div><?php
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="bive-multifield__buttons">
|
||||
<button type="submit" class="btn btn-primary mb-1 ml-1 mt-1" name="<?= $this->name . "[new]"; ?>" value="1">Добавить ещё</button>
|
||||
<span class="bive-multifield__hide">Скрыть</span>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
|
||||
?></div><?php
|
||||
}
|
||||
|
||||
public function render_value()
|
||||
{
|
||||
global $b;
|
||||
$array = array();
|
||||
foreach ($this->content as $key => $data) {
|
||||
foreach ($this->params["fields"] as $arg => $field) {
|
||||
$array[$key][$arg] = $b->field_render_value($field[0], $this->name . "[$key][$arg]", $data[$arg]);
|
||||
}
|
||||
}
|
||||
return $array;
|
||||
}
|
||||
|
||||
public function render_db_value()
|
||||
{
|
||||
global $b;
|
||||
|
||||
foreach ($this->content as $key => $data) {
|
||||
if ((string) $data == "remove") {
|
||||
unset($this->content[$key]);
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((string) $key == "new") {
|
||||
unset($this->content[$key]);
|
||||
$array = array();
|
||||
foreach ($this->params["fields"] as $arg => $field)
|
||||
$array[$arg] = $b->field_render_db_value($field[0], $this->name . "[$key][$arg]", "");
|
||||
$this->content[] = $array;
|
||||
}
|
||||
}
|
||||
foreach ($this->content as $key => $data) {
|
||||
foreach ($this->params["fields"] as $arg => $field)
|
||||
$this->content[$key][$arg] = $b->field_render_db_value($field[0], $this->name . "[$key][$arg]", $data[$arg]);
|
||||
}
|
||||
return json_encode(array_values($this->content));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
class Password {
|
||||
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;
|
||||
$input_dom = new DOM("input");
|
||||
$input_dom->setAttribute("type", "password");
|
||||
$input_dom->setAttribute("name", $this->name);
|
||||
$input_dom->setAttribute("placeholder", "Оставьте пустым чтобы не вносить изменения");
|
||||
$input_dom->setAttribute("value", $b->get_view($this->content));
|
||||
$input_dom->view();
|
||||
}
|
||||
|
||||
public function render_value()
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
public function render_db_value($old_value)
|
||||
{
|
||||
if($this->content == "ЗАШИФРОВАНО") return $old_value;
|
||||
return password_hash($this->content, PASSWORD_DEFAULT);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
class Separator {
|
||||
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;
|
||||
$input_dom = new DOM("div");
|
||||
$input_dom->setAttribute("type", "text");
|
||||
$input_dom->setAttribute("class", "bive-separator");
|
||||
$input_dom->setAttribute("value", $b->get_view($this->content));
|
||||
$input_dom->view();
|
||||
}
|
||||
|
||||
public function render_value()
|
||||
{
|
||||
return $this->content;
|
||||
}
|
||||
|
||||
public function render_db_value()
|
||||
{
|
||||
return $this->content;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
class Text {
|
||||
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;
|
||||
$input_dom = new DOM("input");
|
||||
$input_dom->setAttribute("type", "text");
|
||||
$input_dom->setAttribute("name", $this->name);
|
||||
$input_dom->setAttribute("value", $b->get_view($this->content));
|
||||
$input_dom->view();
|
||||
}
|
||||
|
||||
public function render_value()
|
||||
{
|
||||
return $this->content;
|
||||
}
|
||||
|
||||
public function render_db_value()
|
||||
{
|
||||
return $this->content;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
class Text_Readonly {
|
||||
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;
|
||||
$input_dom = new DOM("input");
|
||||
$input_dom->setAttribute("type", "text");
|
||||
$input_dom->setAttribute("class", "bive-readonly");
|
||||
$input_dom->setAttribute("value", $b->get_view($this->content));
|
||||
$input_dom->setAttribute("readonly", "readonly");
|
||||
$input_dom->view();
|
||||
}
|
||||
|
||||
public function render_value()
|
||||
{
|
||||
return $this->content;
|
||||
}
|
||||
|
||||
public function render_db_value()
|
||||
{
|
||||
return $this->content;
|
||||
}
|
||||
}
|
||||
25
playarea/plugins/bive-admin-panel/scripts/links.php
Normal file
25
playarea/plugins/bive-admin-panel/scripts/links.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
defined( 'ROOT_DIR' ) || exit;
|
||||
|
||||
$b->admin_page_set("system", "links", "Ссылки", array(), "bive_links_page", false, "link");
|
||||
|
||||
function bive_links_page()
|
||||
{
|
||||
global $b;
|
||||
$b->template_load("bive-admin-panel/template/links/links.php");
|
||||
}
|
||||
|
||||
$b->event_add("bive_edit_links", "bive_edit_links");
|
||||
|
||||
function bive_edit_links($args)
|
||||
{
|
||||
global $b;
|
||||
$bive_fragment_replacement = $args["bive_fragment_replacement"];
|
||||
$bive_fragment_filling = $args["bive_fragment_filling"];
|
||||
$b->db_query("UPDATE bive_settings SET value = REPLACE(value, ?, ?) WHERE INSTR(value, ?) > 0;", array($bive_fragment_replacement, $bive_fragment_filling, $bive_fragment_replacement));
|
||||
$b->db_query("UPDATE bive_items_props SET prop_value = REPLACE(prop_value, ?, ?) WHERE INSTR(prop_value, ?) > 0;", array($bive_fragment_replacement, $bive_fragment_filling, $bive_fragment_replacement));
|
||||
$b->alerts_add("Ссылки на сайте обновлены!", "notice", "b_link_update");
|
||||
$b->router_refresh();
|
||||
exit();
|
||||
}
|
||||
80
playarea/plugins/bive-admin-panel/scripts/settings.php
Normal file
80
playarea/plugins/bive-admin-panel/scripts/settings.php
Normal file
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
defined( 'ROOT_DIR' ) || exit;
|
||||
|
||||
// Страницы настройки движка
|
||||
|
||||
$b->admin_page_set("content", "settings", "Настройки", array(), "bive_settings_page", false, "settings");
|
||||
$b->admin_page_set("settings", "main_settings","Основные", array(), "bive_settings_page");
|
||||
|
||||
function bive_get_settings_template_path(): string
|
||||
{
|
||||
return "bive-admin-panel/template/settings/settings.php";
|
||||
}
|
||||
|
||||
function bive_settings_page()
|
||||
{
|
||||
global $b;
|
||||
$b->template_load(bive_get_settings_template_path(), array("settings_list" => array("bive_site_name")));
|
||||
}
|
||||
|
||||
// Сохранение настроек
|
||||
|
||||
$b->event_add("settings_save", "bive_settings_save");
|
||||
|
||||
function bive_settings_save($args)
|
||||
{
|
||||
global $b;
|
||||
foreach ($args as $arg => $value) $b->setting_set($arg, $value);
|
||||
$b->alerts_add("Данные успешно сохранены.", "info", "admin_item");
|
||||
|
||||
if($args["b_wingman"]) {
|
||||
$admin_page = $b->ls_get_key("admin_page");
|
||||
$b->admin_page_render($admin_page, true);
|
||||
exit();
|
||||
}
|
||||
|
||||
$b->router_refresh();
|
||||
exit();
|
||||
}
|
||||
|
||||
// Поля для настроек
|
||||
|
||||
$b->setting_register("bive_site_name", "Название сайта", "plain_text");
|
||||
|
||||
class SettingPage {
|
||||
public array $settings_list = array();
|
||||
public string $parent_slug;
|
||||
public string $page_slug;
|
||||
public string $page_title;
|
||||
public array $params = array();
|
||||
public bool $hide = false;
|
||||
public bool $icon = false;
|
||||
|
||||
public function __construct($parent_slug, $page_slug, $page_title, $params = array(), $hide = false, $icon = false)
|
||||
{
|
||||
$this->parent_slug = $parent_slug;
|
||||
$this->page_slug = $page_slug;
|
||||
$this->page_title = $page_title;
|
||||
$this->params = $params;
|
||||
$this->hide = $hide;
|
||||
$this->icon = $icon;
|
||||
}
|
||||
|
||||
public function func(): Closure {
|
||||
$settings_list = $this->settings_list;
|
||||
return function () use ($settings_list) {
|
||||
global $b;
|
||||
$b->template_load(bive_get_settings_template_path(), array("settings_list" => $settings_list));
|
||||
};
|
||||
}
|
||||
|
||||
public function add(string $setting_id){
|
||||
$this->settings_list[] = $setting_id;
|
||||
}
|
||||
|
||||
public function create(){
|
||||
global $b;
|
||||
$b->admin_page_set($this->parent_slug, $this->page_slug, $this->page_title, $this->params, $this->func(), $this->hide, $this->icon);
|
||||
}
|
||||
}
|
||||
73
playarea/plugins/bive-admin-panel/scripts/wingman.php
Normal file
73
playarea/plugins/bive-admin-panel/scripts/wingman.php
Normal file
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
$b->router_add("/wingman/load_submenu_search/", "wingman_load_submenu_search", array("post"));
|
||||
|
||||
function wingman_load_submenu_search()
|
||||
{
|
||||
global $b;
|
||||
$search = $_POST["search"];
|
||||
$admin_page = $_POST["page"];
|
||||
|
||||
$pages = $b->admin_pages;
|
||||
$active_submenu = false;
|
||||
|
||||
foreach ($pages as $key => $value) {
|
||||
if($value["hide"]) continue;
|
||||
if($b->admin_page_has_child($key, $admin_page))
|
||||
$active_submenu = $value;
|
||||
}
|
||||
|
||||
if($active_submenu !== false) {
|
||||
$b->template_load("bive-admin-panel/template/menu/nav_subpage.php", array(
|
||||
"active_submenu" => $active_submenu,
|
||||
"open_child"=> true,
|
||||
"admin_page" => $admin_page,
|
||||
"search" => $search
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
$b->router_add("/wingman/favorite_add_page/", "wingman_favorite_add_page", array("post"));
|
||||
|
||||
function wingman_favorite_add_page()
|
||||
{
|
||||
global $b;
|
||||
$user_id = $b->session_get("user_id");
|
||||
if(!$user_id) exit(json_encode(array("ok" => false)));
|
||||
|
||||
$link_url = $_POST["link"];
|
||||
$link_name = $_POST["name"];
|
||||
|
||||
$favorite = new Favorite(0);
|
||||
$favorite->create($link_name, "");
|
||||
$favorite->set_prop("user_id", $user_id);
|
||||
$favorite->set_prop("link", $link_url);
|
||||
|
||||
exit(json_encode(array("ok" => true)));
|
||||
}
|
||||
|
||||
$b->router_add("/wingman/favorite_remove_page/", "wingman_favorite_remove_page", array("post"));
|
||||
|
||||
function wingman_favorite_remove_page()
|
||||
{
|
||||
global $b;
|
||||
$user_id = $b->session_get("user_id");
|
||||
if(!$user_id) exit(json_encode(array("ok" => false)));
|
||||
|
||||
$link_url = $_POST["link"];
|
||||
$search = new Search(array(
|
||||
"class" => "Favorite",
|
||||
"props" => array(
|
||||
"user_id" => $user_id,
|
||||
"link" => $link_url
|
||||
)
|
||||
));
|
||||
|
||||
$favorites = $search->collect();
|
||||
|
||||
foreach ($favorites as $key => $item) {
|
||||
$item->delete();
|
||||
}
|
||||
|
||||
exit(json_encode(array("ok" => true)));
|
||||
}
|
||||
Reference in New Issue
Block a user