public function do_submit() { db::connect_root(); db::query('CREATE DATABASE IF NOT EXISTS `' . get::fn($this->username) . '`'); db::query('USE mysql'); if (db::select('user')->retrieve(['user'])->filter(['`user`=:user AND `host`=:host'], ['user' => $this->username, 'host' => '127.0.0.1'])->execute()->rowCount()) { db::query('CREATE USER \'' . get::fn($this->username) . '\'@\'127.0.0.1\' IDENTIFIED BY \'' . $this->password . '\'', [], true); } if (db::select('user')->retrieve(['user'])->filter(['`user`=:user AND `host`=:host'], ['user' => $this->username, 'host' => 'localhost'])->execute()->rowCount()) { db::query('CREATE USER \'' . get::fn($this->username) . '\'@\'localhost\' IDENTIFIED BY \'' . $this->password . '\'', [], true); } db::query('GRANT ALL PRIVILEGES ON `' . get::fn($this->username) . '`.* TO \'' . get::fn($this->username) . '\'@\'127.0.0.1\'', [], true); db::query('GRANT ALL PRIVILEGES ON `' . get::fn($this->username) . '`.* TO \'' . get::fn($this->username) . '\'@\'localhost\'', [], true); if (!is_dir(root . '/.conf')) { mkdir(root . '/.conf'); } ini::save(root . '/.conf/config.ini', ['mysql' => ['server' => '127.0.0.1', 'username' => get::fn($this->username), 'password' => $this->password, 'database' => get::fn($this->username)], 'site' => ['title_tag' => $this->site_name]]); ini::reload(); db::default_connection(); $cms_builder = new \module\cms\object\cms_builder(); $cms_builder->manage(); $i = 0; do { if ($this->{'user_' . $i} && $this->{'password_' . $i}) { $user = new _cms_user(); $user->title = $this->{'user_' . $i}; $user->password = $this->{'password_' . $i}; $user->ulid = $this->{'user_level_' . $i} ?: 1; } $i++; } while (isset($this->{'user_' . $i})); ajax::current()->redirect = '/cms/login'; }
public function do_submit() { $module = new _cms_module([], $this->mid); $field = new field_type([], $this->type); $type = '\\form\\field_' . $field->title; /** @var \form\field $field_type */ $field_type = new $type(''); if ($inner = $field_type->get_database_create_query()) { db::query('ALTER TABLE ' . $module->table_name . ' ADD `' . $this->field_name . '` ' . $field_type->get_database_create_query(), [], 1); } if ($field->title == 'mlink') { $source_module = new _cms_module(['table_name', 'primary_key'], $this->link_module); db::create_table_join(get::__class_name($this), $source_module->table_name); } $res = db::select('_cms_field')->retrieve('MAX(position) AS pos')->filter_field('mid', $this->mid)->execute()->fetchObject(); $insert = db::insert('_cms_field')->add_value('title', $this->title)->add_value('type', $field->title)->add_value('field_name', $this->field_name)->add_value('mid', $this->mid)->add_value('position', $res->pos + 1); if ($field->title == 'link' || $field->title == 'mlink') { $insert->add_value('link_module', $this->link_module)->add_value('link_field', $this->link_field); } $insert->execute(); table::rebuild_modules(); table::reset_module_fields($module->mid); ajax::update($module->get_fields_list()->get()); ajax::update($this->get_html()->get()); }
protected function set_default_fields($module) { try { $json = module::create($module); $_module = $_field = db::select('_cms_module')->retrieve(['mid'])->filter(['table_name=:table_name'], ['table_name' => $json->tablename])->execute()->fetchObject(); if ($json && $_module) { $fields = $json->fieldset; $previous_key = false; foreach ($fields as $key => $row) { $format = db::get_column_type_json($row); if ($format) { if (!db::column_exists($json->tablename, $key)) { db::add_column($json->tablename, $key, $format, $previous_key ? ' AFTER `' . $previous_key . '`' : ' FIRST'); } else { db::move_column($json->tablename, $key, $format, $previous_key ? ' AFTER `' . $previous_key . '`' : ' FIRST'); } } if (!$row->is_default) { $_field = db::select('_cms_field')->retrieve(['fid'])->filter(['mid=:mid', 'field_name=:key'], ['mid' => $_module->mid, 'key' => $key])->execute(); if (!$_field->rowCount()) { $this->create_field_base($_module, $key, $row); } } $previous_key = $key; } } } catch (\Exception $e) { } }
$time = time(); define('load_core', false); require $_SERVER['DOCUMENT_ROOT'] . '/.core/config.php'; set_time_limit(0); if (!is_dir(root . '/bin')) { mkdir(root . '/bin'); } if (!is_dir(root . '/bin/' . $time)) { mkdir(root . '/bin/' . $time); } else { die('A build already exists with the timestamp ' . $time); } $index_contents = '<?php'; $classes = []; $res = \classes\db::select('_autoloader_log')->retrieve(['classes'])->execute(); if ($res->rowCount()) { $row = $res->fetchObject(); $classes = explode(',', $row->classes); while ($row = $res->fetchObject()) { $classes = array_intersect($classes, explode(',', $row->classes)); } foreach ($classes as &$class) { $class = str_replace('\\', '/', $class) . '.php'; } } unset($class); $file_mappings = []; $files = \classes\get::recursive_glob(root . '/.core/', '*.php'); foreach ($files as $file) { $new_path = str_replace(root . '/.core/dependent/', '', $file);
/** * @return string */ public function do_save() { $class = _get::__class_name($this); if ($this->get_primary_key()) { $query = new update($class); } else { $query = new insert($class); $top_pos = _db::select($class)->add_field_to_retrieve('max(position) as pos')->execute()->fetchObject()->pos; $query->add_value('position', $top_pos ?: 1); } /** @var field $field */ $this->get_fields()->iterate(function ($field) use($query) { $field->parent_form = $this; if ($field->field_name != $this->get_primary_key_name()) { if (isset($this->{$field->field_name}) && !$field instanceof field_file && !$field instanceof field_mlink) { if (!$this->{$field->field_name} && $field instanceof field_fn && isset($this->title)) { $this->{$field->field_name} = _get::unique_fn(_get::__class_name($this), $field->field_name, $this->title); } try { $data = $field->get_save_sql(); $query->add_value($field->field_name, $data); } catch (\RuntimeException $e) { } } } }); $query->add_value('live', isset($this->live) ? $this->live : true); $query->add_value('deleted', isset($this->deleted) ? $this->deleted : false); $query->add_value('ts', date('Y-m-d H:i:s')); if ($this->get_primary_key()) { $query->filter_field($this->get_primary_key_name(), $this->get_primary_key()); } $key = $query->execute(); if (!$this->get_primary_key()) { $this->set_primary_key($key); } $this->get_fields()->iterate(function ($field) { if ($field->field_name != $this->get_primary_key_name()) { if (isset($this->{$field->field_name}) && $field instanceof field_mlink) { $source_module = new _cms_module(['table_name', 'primary_key'], $field->get_link_mid()); $module = new _cms_module(['table_name', 'primary_key'], static::get_module_id()); _db::delete($module->table_name . '_link_' . $source_module->table_name)->filter_field($module->primary_key, $this->get_primary_key())->execute(); if ($this->{$field->field_name}) { foreach ($this->{$field->field_name} as $value) { _db::insert($module->table_name . '_link_' . $source_module->table_name)->add_value($module->primary_key, $this->get_primary_key())->add_value('link_' . $source_module->primary_key, $value)->add_value('fid', $field->fid)->execute(); } } } } }); if ($this->get_primary_key()) { $this->get_fields()->iterate(function ($field) { if ($field instanceof field_file) { $this->do_upload_file($field); } }); } return $this->get_primary_key(); }