private function rec($id) { $find = $this->perform(Fx::service_context()->namespace['construct_db'], array('parent' => $id)); foreach ($find as $v) { $active = isset($this->path[0]) && $this->path[0]['id'] == $v['id'] ? ' class="active"' : ''; if ($active == '' && Fx::context()->struct_db[$v['object']]['show_wood'] < 1) { continue; } $elem = Fx::db()->find($v['object'], array('id' => $v['id'])); if (!isset($elem[0])) { continue; } $elem = $elem[0]; $name = isset($elem['name']) && $elem['name'] !== '' ? $elem['name'] : 'undefiend-' . $v['id']; $this->result[] = '<li>'; $this->result[] = '<a' . $active . ' href="?mode=project&id=' . $v['id'] . '">' . $name . '</a>'; if ($active != '') { $item = array_shift($this->path); if (Fx::context()->struct_db[$item['object']]['show_wood'] > 0) { $this->result[] = '<ul>'; $this->rec($item['id']); $this->result[] = '</ul>'; } } $this->result[] = '</li>'; } }
public function find($param) { $val = $param['value']; $result = array(); if (is_numeric($val)) { Fx::db()->search(Fx::service_context()->namespace['construct_db'], array('id' => (int) $val, 'chpu' => $val)); } foreach (Fx::db()->find(Fx::service_context()->namespace['struct_db']) as $v) { $table = $v['code']; $row = Fx::db()->extract(Fx::db()->go(array('event' => 'find', 'from' => $table, 'limit' => 1))); if (!isset($row[0])) { continue; } $rows = $row[0]; $where = array(); foreach (array_keys($rows) as $row) { $where[$row] = $val; } $find = Fx::db()->search($table, $where); if (count($find) > 0) { $result[] = array('name' => $v['name'], 'code' => $v['code'], 'find' => $find); } } return $result; }
public function removeCell($post) { foreach ($post['cell'] as $v) { if (isset($v['find'])) { Fx::db()->remove($v['table'], $v['find']); } } }
/** * @param array $ctx * @param $param * @return array */ public function run($ctx = array(), $param) { if (isset($param['controllerAction']) && $param['controllerAction'] === 'saveList') { Fx::db()->remove(Fx::service_context()->namespace['rewrite']); foreach ($param['option'] as $v) { if ($v['from'] !== '') { $v['from'] = $this->normalizeString($v['from']); if ($v['to']) { $v['to'] = $this->normalizeString($v['to']); } Fx::db()->insert(Fx::service_context()->namespace['rewrite'], $v); } } } else { $ctx = array_merge($ctx, array('dict' => Fx::service_context()->dict, 'list' => Fx::db()->find(Fx::service_context()->namespace['rewrite']))); } return $ctx; }
<?php access(0, 1); // Root / Admin $markerList = Fx::db()->find(Fx::service_context()->namespace['marker']); $templateList = Fx::db()->find(Fx::service_context()->namespace['template']);
public function migrate($post) { $tables = Fx::db()->tables_info(); $tables = array_keys($tables['table']); $prefix = Fx::service_context()->config['db']['sys_namespace']; $collections = array_keys(Fx::service_context()->manifest['baseCollection']); $isTrue = 0; $isFalse = 0; foreach ($collections as $v) { if (!in_array($prefix . $v, $tables)) { if (Fx::db()->createCollection(array('name' => $prefix . $v, 'row' => Fx::service_context()->manifest['baseCollection'][$v]))) { $isTrue++; } else { $isFalse++; } } } echo 'Создано таблиц ' . $isTrue . ', не смогли создать таблиц ' . $isFalse; }
<?php $lastChange = Fx::db()->extract(Fx::db()->go(array('event' => 'find', 'from' => Fx::service_context()->namespace['construct_db'], 'order' => '`date` DESC', 'limit' => 15)), function ($item, $db) { $data = $db->findOne($item['object'], array('id' => $item['id'])); return array('date' => date('d.m.Y G:i', $item['date']), 'id' => $item['id'], 'name' => isset($data['name']) && $data['name'] !== '' ? $data['name'] : 'undefiend-' . $item['id'], 'url' => '?mode=elem&id=' . $item['id']); }); $dbInfo = Fx::db()->tables_info();
die; } if (isset($_POST['saveConfig'])) { $dbConfig = array('db' => $_SESSION['dbConfig'], 'project_name' => $_POST['project_name'], 'templating' => $_POST['templating']); Fx::service_context()->config = array_merge(Fx::service_context()->config, array('db' => array_merge(Fx::service_context()->config['db'], $_SESSION['dbConfig']), 'project_name' => $_POST['project_name'], 'templating' => $_POST['templating'])); if (Fx::db()->isConnect()) { $login = trim($_POST['user']['login']); $pass = hashGenerate(strtolower(trim($_POST['user']['pass']))); foreach ($manifest['baseCollection'] as $k => $v) { Fx::db()->createCollection(array('name' => Fx::service_context()->namespace[$k], 'row' => $v)); } $find = Fx::db()->find(Fx::service_context()->namespace['user'], array('login' => $login, 'pass' => $pass)); if (count($find)) { Fx::db()->update(Fx::service_context()->namespace['user'], array('access' => 0), array('id' => $find[0]['id'])); } else { Fx::db()->insert(Fx::service_context()->namespace['user'], array('login' => $login, 'pass' => $pass, 'access' => 0)); } Fx::io()->create_file(root . '/config.php'); Fx::io()->write(root . '/config.php', '<? return $config = ' . Fx::io()->arrayToString(Fx::service_context()->config) . '; ?>'); $folderFrom = root . '/install/templating/' . Fx::service_context()->config['templating'] . '/'; $folderTo = root . '/' . Fx::service_context()->config['folder']['template'] . '/'; if (!is_dir($folderTo)) { Fx::io()->create_dir($folderTo); } $dir = Fx::io()->tree($folderFrom); foreach ($dir['dir'] as $v) { $folder = str_replace($folderFrom, '', $v); if (!is_dir($folderTo . $folder)) { Fx::io()->create_dir($folderTo . $folder); } }
require_once 'config.php'; define('sys', root . '/' . $config['folder']['sys']); require_once sys . '/requerid.php'; Fx::lib()->rewrite(); Fx::context()->path = Fx::db()->path($_SERVER['REQUEST_URI']); if (Fx::context()->path === false) { throw new Exception('Not found', 404); } Fx::context()->template = array(); if (count(Fx::context()->path) > 0) { Fx::context()->self_object = end(Fx::context()->path); if ((int) Fx::context()->self_object['marker'] !== 0) { $marker = Fx::db()->find(Fx::service_context()->namespace['marker'], array('id' => Fx::context()->self_object['marker'])); $marker = explode(',', $marker[0]['template_id']); foreach ($marker as $v) { $template = Fx::db()->find(Fx::service_context()->namespace['template'], array('id' => $v)); Fx::context()->template[] = $template[0]['name']; } } else { throw new Exception('not found', 404); } } else { Fx::context()->template[] = 'home'; } switch (trim(strtolower(Fx::service_context()->config['templating']))) { case 'twig': require_once Fx::service_context()->config['folder']['sys'] . '/templating/Twig/Autoloader.php'; Twig_Autoloader::register(); $loader = new Twig_Loader_Filesystem(root . '/template/'); $twig = new Twig_Environment($loader, array('debug' => true)); $twig->addExtension(new Twig_Extension_Debug());
<?php access(0); // Root Fx::context()->users = Fx::db()->find(Fx::service_context()->namespace['user']);
throw new Exception('not found', 404); } // Левое меню require_once sys . '/template/php/project-menu.php'; $tables = Fx::db()->find(Fx::service_context()->namespace['struct_db']); $rowslist = Fx::db()->find(Fx::service_context()->namespace['struct_td']); $selfItem = Fx::db()->extract(Fx::db()->go(array('event' => 'find', 'from' => Fx::service_context()->namespace['construct_db'], 'where' => array('parent' => Fx::context()->selfId), 'order' => 'num'))); $rows = array(); foreach ($rowslist as $k => $v) { if (!isset($rows[$v['parent']])) { $rows[$v['parent']] = array(); } $rows[$v['parent']][$v['code']] = $v; } $tabl = array(); foreach ($tables as $v) { if (isset($rows[$v['id']])) { $v['rows'] = $rows[$v['id']]; } $tabl[$v['code']] = $v; } $selfList = array(); $selfList[] = '<ul class="js-sortable-list">'; foreach ($selfItem as $k => $j) { $id = $j['ref'] > 0 ? $j['ref'] : $j['id']; $item = Fx::db()->findOne($j['object'], array('id' => $id)); if (is_array($item)) { $selfList[] = Fx::io()->buffer(sys . '/template/tpl/blocks/project-list-item.html', array('index' => $k + 1, 'id' => $id, 'ref' => $j['ref'], 'num' => $j['num'], 'object' => $j, 'date' => date('d.m.Y G:i (s)', $j['date']), 'data' => $item, 'name' => isset($item['name']) && $item['name'] != '' ? $item['name'] : 'undefiend-' . $j['id'], 'hide-icon' => $j['hide'] == 1 ? 'icon-eye-off' : 'icon-eye', 'icon' => $tabl[$j['object']]['icon'], 'data-list' => $tabl[$j['object']]['rows'])); } } $selfList[] = '</ul>';
<?php $leftMenu = Fx::db()->find(Fx::service_context()->namespace['struct_db']); $text = array('<h3>Объекты</h3><ul>'); foreach ($leftMenu as $v) { $active = isset($_GET['id']) && $_GET['id'] == $v['id'] ? ' class="active"' : ''; $text[] = '<li' . $active . '><a href="?mode=object&id=' . $v['id'] . '">' . $v['name'] . '</a></li>'; } Fx::context()->leftMenu .= implode("\n", $text) . '</ul>'; Fx::context()->leftMenu .= '<a href="?mode=object" class="btn mt_mini"><span class="btn-in">Создать объект</span></a>'; // Текущий объект $paramObject = ''; if (isset($_GET['id']) && is_numeric($_GET['id'])) { $id = $_GET['id']; $objectParam = Fx::db()->find(Fx::service_context()->namespace['struct_db'], array('id' => $id)); $td = Fx::db()->find(Fx::service_context()->namespace['struct_td'], array('parent' => $id)); if (is_array($objectParam) && is_array($td) && count($objectParam) && count($td)) { $len = count($td); $paramObject = array(); foreach ($td as $k => $v) { $paramObject[] = Fx::io()->buffer(sys . '/template/tpl/template/object_item.html', array('key' => $k, 'value' => $v, 'zIndex' => $len - $k, 'manifest' => $manifest)); } $paramObject = implode("\n", $paramObject); } else { throw new Exception('not found', 404); } }
function removeElem($id, $object = '') { while (true) { if ($object == '') { $object = Fx::db()->find(Fx::service_context()->namespace['construct_db'], array('$or' => array('id' => $id, 'ref' => $id))); } Fx::db()->remove($object[0]['object'], array('id' => $id)); Fx::db()->remove(Fx::service_context()->namespace['construct_db'], array('id' => $id)); $path = root . '/' . Fx::service_context()->config['folder']['files'] . '/' . $id . '/'; Fx::io()->del($path); $find = Fx::db()->find(Fx::service_context()->namespace['construct_db'], array('parent' => $id)); if (count($find)) { foreach ($find as $v) { removeElem($v['id'], array($v)); } } else { break; } } }
Fx::context()->selfId = Fx::context()->parent_object; } $pathGist = sys . '/template/tpl/gist-elem/'; $tablParam = array(); $tableName = isset($_GET['name']) ? $_GET['name'] : ''; $objectValue = array(); if (isset($_GET['id']) && (int) $_GET['id'] > 0) { $selfObject = Fx::db()->find(Fx::service_context()->namespace['construct_db'], array('id' => (int) $_GET['id'])); if (count($selfObject)) { $tableName = $selfObject[0]['object']; $objectValue = Fx::db()->find($tableName, array('id' => $selfObject[0]['id'])); $objectValue = $objectValue[0]; } } if ($tableName != '') { $tabl = Fx::db()->find(Fx::service_context()->namespace['struct_db'], array('code' => $tableName)); $tablParam = $tabl[0]; } else { setSystemMessage('error', 'Не заданы параметры для редактирования'); load_url(); } $row = Fx::db()->find(Fx::service_context()->namespace['struct_td'], array('parent' => $tablParam['id'])); $result = array(); foreach ($row as $key => $v) { $result[] = loadParam($key, array('row' => $v, 'value' => isset($objectValue[$v['code']]) ? $objectValue[$v['code']] : ''), $manifest, $pathGist . $v['type'] . '.html'); } // Шаблоны $template = Fx::db()->find(Fx::service_context()->namespace['marker']); // Левое меню require_once sys . '/template/php/project-menu.php'; $isShowSystem = Fx::context()->struct_db[$tableName]['show_sistem'] == '1';
private function saveHistoryLink() { $history_link = Fx::db()->find(Fx::service_context()->namespace['history-link'], array('link' => $_SERVER['REQUEST_URI'])); if (!count($history_link)) { Fx::db()->insert(Fx::service_context()->namespace['history-link'], array('link' => $_SERVER['REQUEST_URI'])); } }