Exemplo n.º 1
0
 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;
     }
 }
Exemplo n.º 2
0
 /**
  * @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);
         }
     }
 }
Exemplo n.º 3
0
 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';
 }
Exemplo n.º 4
0
    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');
    }
Exemplo n.º 5
0
 public function mysql_value($value)
 {
     return get::fn($value);
 }