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()); }
public function __controller(array $path) { if (isset($path[1])) { $this->view = 'flight'; $this->current = new flight(); $this->current->do_retrieve(flight::$default_fields, ['where_equals' => ['fid' => $path[1]], 'join' => flight::$default_joins]); if (!$this->current->fid) { get::header_redirect('/flight_info'); } } parent::__controller($path); }
public static function unique_fn($table, $field, $str) { $base_fn = _get::fn($str); if (db::select($table)->add_field_to_retrieve($field)->filter($field . '=:fn', ['fn' => $base_fn])->execute()->rowCount()) { $cnt = 0; do { $fn = $base_fn . '_' . ++$cnt; } while (db::select($table)->add_field_to_retrieve($field)->filter($field . '=:fn', ['fn' => $fn])->execute()->rowCount()); return $fn; } else { return $base_fn; } }
/** * @return string */ public function get_url() { if ($this->pid == \module\pages\controller::$homepage_id) { return '/'; } if (isset($this->direct_link) && $this->direct_link) { return $this->direct_link; } else { if (!empty($this->module_name)) { return '/' . $this->module_name; } else { return '/' . $this->pid . '/' . get::fn($this->title); } } }
public function get_title_tag() { $parts = [parent::get_title_tag(), 'CMS', ucwords(str_replace('_', ' ', \classes\get::__class_name($this)))]; if (isset($this->module->current)) { $parts[] = ucwords(str_replace('_', ' ', get::__class_name($this->module->current))); if ($this->module->current->get_primary_key()) { if ($title = $this->module->current->get_title()) { $parts[] = $title; } else { $parts[] = $this->module->current->get_primary_key(); } } } return implode(' | ', $parts); }
public function get_push_state() { $push_state = new push_state(); $push_state->url = isset($this->current) ? $this->current->get_url() : '/' . _get::__namespace($this, 0) . ($this->view != '_default' ? '/' . $this->view : ''); if ($this->page > 1) { $push_state->url .= 'page/' . $this->page; } $push_state->title = $this->page_object->title; $push_state->data->url = $push_state->url; $push_state->data->module = get_class($this); $push_state->data->act = isset($_REQUEST['ajax_act']) ? $_REQUEST['ajax_act'] : 'ajax_load'; $push_state->data->request = $_REQUEST; $push_state->data->id = '#' . $this->view_object->get_page_selector(); $push_state->push = !isset($_REQUEST['is_popped']) ? true : !$_REQUEST['is_popped']; return $push_state; }
public function __controller(array $path) { if (!isset($path[0])) { $this->current->do_retrieve_from_id([], static::$homepage_id); $this->view = 'home'; } else { $this->current->do_retrieve_from_id([], $path[0]); } if (!$this->current->pid) { $this->current->do_retrieve([], ['order' => 'position']); } else { if (uri != trim($this->current->get_url(), '/')) { get::header_redirect($this->current->get_url()); } } parent::__controller($path); }
public function filter() { $res = $this->getIterator(); if (!isset($this->filters)) { $this->set_filters(); } foreach ($this->filters->fields as $field) { if ($field->field_name != 'identifier' && isset($this->filters->{$field->field_name}) && $this->filters->{$field->field_name}) { $key = $field->field_name; if ($field->original_field instanceof field_link) { $key = get::__class_name($field->original_field->get_link_module()); } $res = new collection_filter($res, $key, $this->filters->{$field->field_name}); } } $result_set = []; foreach ($res as $object) { $result_set[] = $object; } $this->exchangeArray($result_set); }
public function do_submit() { $module = new _cms_module([], $this->mid); $field = new field_type([], $this->type); $old_field = new _cms_field([], $this->fid); $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 . ' MODIFY `' . $old_field->field_name . '` `' . $this->field_name . '` ' . $field_type->get_database_create_query(), [], 1); } if ($field->title == 'mlink' && $old_field->type !== 'mlink') { $source_module = new _cms_module(['table_name', 'primary_key'], $this->link_module); db::create_table_join(\classes\get::__class_name($this), $source_module->table_name); } $insert = db::update('_cms_field')->add_value('title', $this->title)->add_value('type', $field->title)->add_value('field_name', $this->field_name)->add_value('link_module', $this->link_module)->add_value('link_field', $this->link_field)->filter_field('fid', $this->fid); $insert->execute(); table::rebuild_modules(); table::reset_module_fields($module->mid); ajax::update($module->get_fields_list()->get()); ajax::update($this->get_html()->get()); }
function write_table_header($flights, $type = 'pid') { $inner_html = ''; foreach (range(1, $flights) as $pos) { $inner_html .= node::create('th', [], get::ordinal($pos)); } $html = node::create('thead', [], node::create('tr', [], node::create('th.pos', [], 'Pos') . node::create('th.name', [], 'Name') . node::create('th.club', [], $type == 'pid' ? 'Club / Glider' : 'Manufacturer') . $inner_html . node::create('th.tot', [], 'Total'))); return $html; }
/** * @param table_array $elements * @param string $class * * @return node */ public function get_table_rows($elements, $class = '') { $nodes = node::create('tbody'); $keys = $this->allowed_keys; /** * @var \classes\table $obj * @return string */ return $elements->iterate_return(function (table $obj) use($nodes, $keys, $class) { if ($obj->_has_child && in_array($obj->get_primary_key(), $keys)) { $obj->_is_expanded = true; $children = $this->get_elements($obj->get_primary_key()); } else { $obj->_is_expanded = false; $children = false; } return node::create('tr#' . get::__class_name($obj) . $obj->get_primary_key() . ($obj->deleted ? '.danger.deleted' : '') . $class . '.vertical-align', [], $obj->get_cms_list()) . ($children ? $this->get_table_rows($children, '.active') : ''); }); }
public function mysql_value($value) { return get::fn($value); }
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); $new_path = str_replace(root . '/.core', 'core', $new_path); $file_mappings[$new_path] = $file; } $files = \classes\get::recursive_glob(root . '/inc', '*.php'); foreach ($files as $file) { $new_path = str_replace(root . '/inc/', '', $file); $file_mappings[$new_path] = $file; } $dependencies = []; foreach ($classes as $class) { $dependencies[$class] = find_dependencies($file_mappings[$class]); } $met_dependencies = ['Serializable.php']; $iterations = 0; while ($classes && $iterations < 10) { foreach ($classes as $index => $class) { foreach ($dependencies[$class] as $dependant) { if (!in_array($dependant, $met_dependencies)) { continue 2;
private function get_choose_track_html(igc_parser $track) { $parts = []; foreach ($track->get_split_parts() as $key => $part) { $parts[] = node::create('tr', ['style' => 'color:#' . get::kml_colour($key)], [node::create('td', [], 'Part: ' . $key), node::create('td', [], $part->duration . 's'), node::create('td', [], $part->points), node::create('td a.choose.button', ['data-ajax-click' => get_class($this) . ':do_choose_track', 'data-ajax-post' => '{"track":' . $track->id . ', "section": ' . $key . '}', 'data-ajax-shroud' => '#igc_upload_form_wrapper'], 'Choose')]); } $html = node::create('table', [], [node::create('thead tr', [], [node::create('th', [], 'Part'), node::create('th', [], 'Duration'), node::create('th', [], 'Points'), node::create('th', [], '')]), node::create('tbody', [], $parts)]); return $html; }
/** * */ public function do_reorder() { if (isset($_REQUEST['id'])) { /** @var table $object */ static::$retrieve_unlive = true; static::$retrieve_deleted = true; $object = new static(['position'], $_REQUEST['id']); if (isset($_REQUEST['dir']) && $_REQUEST['dir'] == 'down') { _db::update(_get::__class_name($object))->add_value('position', $object->position)->filter_field('position', $object->position + 1)->execute(); _db::update(_get::__class_name($object))->add_value('position', $object->position + 1)->filter_field($object->get_primary_key_name(), $object->get_primary_key())->execute(); } else { _db::update(_get::__class_name($object))->add_value('position', $object->position)->filter_field('position', $object->position - 1)->execute(); _db::update(_get::__class_name($object))->add_value('position', $object->position - 1)->filter_field($object->get_primary_key_name(), $object->get_primary_key())->execute(); } $list = new _cms_table_list(self::$cms_modules[get_called_class()], 1); _ajax::update($list->get_table()); } }
public function manage() { set_time_limit(0); if (!db::table_exists('_cms_module')) { $this->build(); } if (!db::table_exists('_cms_setting')) { $this->build_settings(); } $var = (int) get::setting('cms_version'); if ($var < self::$current_version) { for ($i = (int) $var + 1; $i <= self::$current_version; $i++) { $this->run_patch($i); } } }
public function get_cms_admin_edit() { $cols = []; $cols[] = node::create('td span.btn.btn-default.live' . ($this->live ? '' : '.not_live'), [], icon::get($this->live ? 'ok' : 'remove')); $cols[] = node::create('td span.btn.btn-default.edit', ['href' => '/' . $this->fid . '/?module=\\module\\cms\\object\\_cms_module&act=get_edit_field_form&fid=' . $this->fid, 'data-target' => '#modal', 'data-toggle' => 'modal'], icon::get('pencil')); $cols[] = node::create('td', [], $this->fid); $cols[] = node::create('td', [], node::create('a.up.reorder.btn.btn-default', ['data-ajax-click' => 'cms:do_reorder_fields', 'data-ajax-post' => '{"mid":' . $this->parent_form->get_module_id() . ',"fid":' . $this->fid . ',"dir":"up"}'], icon::get('arrow-up')) . node::create('a.down.reorder.btn.btn-default', ['data-ajax-click' => 'cms:do_reorder_fields', 'data-ajax-post' => '{"mid":' . $this->parent_form->get_module_id() . ',"fid":' . $this->fid . ',"dir":"down"}'], icon::get('arrow-down'))); $cols[] = node::create('td', [], $this->title); $cols[] = node::create('td', [], $this->field_name); $cols[] = node::create('td', [], get::__class_name($this)); $fields = ['list', 'required', 'filter']; foreach ($fields as $field) { $list_options = ['data-ajax-change' => 'form\\field_boolean:update_cms_setting', 'data-ajax-post' => '{"fid":' . $this->fid . ', "field":"' . $field . '"}', 'value' => 1, 'type' => 'checkbox']; if ($this->{$field}) { $list_options['checked'] = 'checked'; } $cols[] = node::create('td input#' . $this->fid . '_list', $list_options); } $cols[] = node::create('td', [], $this instanceof field_image ? $this->get_image_edit_link() : ''); return $cols; }
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 get_id() { return str_replace('\\', '_', _get::__class_name($this)); }
public function get_view() { $html = node::create('div', [], node::create('h2.page-header.container-fluid', [], 'View all ' . ucwords(get::__class_name($this->module->current)) . 's') . $this->module->get_inner()); return $html; }
public function get_page_selector() { return get::__namespace($this->module, 0) . '-igc'; }
/** * @param $object * @param array $fields_to_retrieve * @param $options * @return \db\select */ public static function get_query($object, array $fields_to_retrieve, $options) { $query = db::select(_get::__class_name($object)); $base_object = _get::__class_name($object); if (!empty($fields_to_retrieve)) { foreach ($fields_to_retrieve as $field) { if (strstr($field, '.') && !strstr($field, '.*') && !strstr($field, ' AS ')) { $query->add_field_to_retrieve($field . ' AS `' . str_replace('.', '@', $field) . '`'); } else { if (strstr($field, '(') === false && strstr($field, '.*') === false && strstr($field, '.') === false) { $query->add_field_to_retrieve($base_object . '.' . $field); } else { $query->add_field_to_retrieve($field); } } } } else { $query->add_field_to_retrieve($base_object . '.*'); } if (isset($options['parameters'])) { $query->filter('1', $options['parameters']); } if (isset($options['join'])) { foreach ($options['join'] as $key => $val) { $query->add_join($key, $val); } } if (isset($options['where'])) { $query->filter($options['where']); } if (isset($options['where_equals']) && $options['where_equals']) { foreach ($options['where_equals'] as $key => $val) { $query->filter_field($key, $val); } } if (isset($options['order'])) { $query->set_order($options['order']); } if (isset($options['limit'])) { $query->set_limit($options['limit']); } if (isset($options['group'])) { $query->add_grouping($options['group']); } return $query; }
public function do_submit() { db::query('CREATE TABLE IF NOT EXISTS `' . $this->table_name . '` ( `' . $this->primary_key . '` int(4) NOT NULL AUTO_INCREMENT, `parent_' . $this->primary_key . '` int(4) NOT NULL DEFAULT "0", `ts` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `cms_created` timestamp NOT NULL DEFAULT "0000-00-00 00:00:00", `live` tinyint(1) NOT NULL DEFAULT "0", `deleted` tinyint(1) NOT NULL DEFAULT "0", `position` int(6) NOT NULL DEFAULT "0", `' . get::fn($this->title_label) . '` varchar(255) NOT NULL, PRIMARY KEY (`' . $this->primary_key . '`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=0;'); $mid = db::insert('_cms_module')->add_value('gid', $this->gid)->add_value('primary_key', $this->primary_key)->add_value('title', $this->title)->add_value('table_name', $this->table_name)->add_value('namespace', $this->namespace)->execute(); $id_field = db::insert('_cms_field')->add_value('field_name', $this->primary_key)->add_value('title', 'ID')->add_value('type', 'int')->add_value('mid', $mid)->add_value('required', false)->add_value('list', false)->add_value('editable', false)->add_value('filter', false)->execute(); db::insert('_cms_field')->add_value('field_name', 'parent_' . $this->primary_key)->add_value('title', 'Parent ID')->add_value('type', 'link')->add_value('mid', $mid)->add_value('link_module', $mid)->add_value('link_field', (int) $id_field + 2)->add_value('required', false)->add_value('list', false)->execute(); db::insert('_cms_field')->add_value('field_name', get::fn($this->title_label))->add_value('title', $this->title_label)->add_value('type', 'string')->add_value('mid', $mid)->execute(); $file = null; if (!$this->namespace) { if (!is_dir(root . '/inc/object/')) { mkdir(root . '/inc/object/'); } if (!file_exists(root . '/inc/object/' . $this->table_name)) { $file = root . '/inc/object/' . $this->table_name; } } else { if (!is_dir(root . '/inc/module/')) { mkdir(root . '/inc/module/'); } if (!is_dir(root . '/inc/module/' . $this->namespace)) { mkdir(root . '/inc/module/' . $this->namespace); } if (!is_dir(root . '/inc/module/' . $this->namespace . '/object/')) { mkdir(root . '/inc/module/' . $this->namespace . '/object'); } if (!file_exists(root . '/inc/module/' . $this->namespace . '/object/' . $this->table_name)) { $file = root . '/inc/module/' . $this->namespace . '/object/' . $this->table_name; } } if ($file) { $class_name = ($this->namespace ? 'module\\' . $this->namespace . '\\' : '') . 'object\\' . $this->table_name; file_put_contents($file . '.php', '<?php namespace ' . ($this->namespace ? 'module\\' . $this->namespace . '\\' : '') . 'object; use classes\\table; use traits\\table_trait; class ' . $this->table_name . ' extends ' . (class_exists('\\core\\' . $class_name) ? '\\core\\' . $class_name : 'table') . ' { use table_trait; /** @var string */ public $' . get::fn($this->title_label) . '; /** @var int */ public $' . get::fn($this->primary_key) . '; }'); } \classes\table::rebuild_modules(); ajax::add_script('window.location = window.location'); }
define('core_dir', root . '/.core'); define('ajax', isset($_REQUEST['module'])); define('host', isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : 'Unknown_Host'); define('uri', isset($_SERVER['REQUEST_URI']) ? trim($_SERVER['REQUEST_URI'], '/') : 'Unknown_URI'); define('ip', isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : 'Unknown_IP'); if (!class_exists('\\classes\\autoloader', false)) { require_once root . '/.core/classes/auto_loader.php'; require_once root . '/.core/dependent/classes/auto_loader.php'; } $auto_loader = new \classes\auto_loader(); set_error_handler(['\\classes\\error_handler', 'handle_error']); register_shutdown_function(['\\classes\\error_handler', 'fatal_handler']); define('dev', in_array(host, \classes\ini::get('domain', 'development', []))); define('local', in_array(host, \classes\ini::get('domain', 'local', ['localhost']))); define('debug', in_array(ip, \classes\ini::get('developers', 'ip', []))); date_default_timezone_set(\classes\get::ini('zone', 'time', 'Europe/London')); if (debug || dev) { error_reporting(-1); ini_set('display_errors', '1'); } if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false) { define('ie', true); define('ie_ver', 0); } else { define('ie', false); define('ie_ver', 0); } if (!defined('load_core') || load_core) { $core = new core(); } function pretty_print($var, $return = false)
public function do_submit() { $table = new _object\league_table(); $table->use_preset($this->type, $this->year); if ($this->type == 10) { $table->options->pilot_id = $this->pilot; } $table->set_year($this->year); if ($this->no_min) { $table->options->minimum_score = 0; } if ($this->glider_mode) { $table->options->glider_mode = true; } if ($this->split_classes) { $table->options->split_classes = true; } get::header_redirect($table->get_url() . '?module=core&act=load_page&form=' . $_REQUEST['ajax_origin']); }
public function get_table_class() { return get::__class_name($this->get_table_object()); }
public function do_delete() { $module = new _cms_module([], $_REQUEST['mid']); $object = $module->get_class(); $class = $module->get_class_name(); $class::$retrieve_deleted = true; $object->do_retrieve_from_id(['deleted'], $_REQUEST['id']); if ($object->get_primary_key()) { if ($object->deleted) { db::delete(get::__class_name($class))->filter($object->get_primary_key_name() . '=' . $_REQUEST['id'])->execute(); } else { $object->deleted = true; $object->do_save(); } } $list = new object\_cms_table_list($module, 1); ajax::update($list->get_table()); }
public function do_submit() { $table = new _object\league_table(); $table->set_from_request(); get::header_redirect($table->get_url() . '?module=core&act=load_page&form=' . $_REQUEST['ajax_origin']); }
public function get_page_selector() { return get::__namespace($this->module, 0) . (isset($this->module->current) && $this->module->current->get_primary_key() ? '-' . $this->module->current->get_primary_key() : ''); }