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']); } } }
protected function createFolder($folderName, $pathTo) { $folder = Fx::io()->path(root, Fx::service_context()->config['folder']['file_manager'], $folderName); if (strlen($pathTo) > 1) { $folder = Fx::io()->path(root, Fx::service_context()->config['folder']['file_manager'], $pathTo, $folderName); } Fx::io()->create_dir($folder); }
/** * @param string $prefix * @return array */ public function getScript($prefix = '') { $result = array(); foreach ($this->paths as $v) { $mime = Fx::io()->mime($v); if (in_array($mime, array('js'))) { $result[] = '<script src="' . $prefix . $v . '" type="text/javascript"></script>'; } } return $result; }
public function compile() { $folderExtension = root . '/' . Fx::service_context()->config['folder']['extension'] . '/'; $fileExtensionSave = $folderExtension . 'extension.php'; if (!is_dir($folderExtension)) { Fx::io()->create_dir($folderExtension); } if (!file_exists($fileExtensionSave)) { Fx::io()->create_file($fileExtensionSave); } $listExtension = Fx::io()->read_dir($folderExtension, 'dir'); $ext = array(); if (file_exists($fileExtensionSave)) { ob_start(); $ext = (include $fileExtensionSave); ob_clean(); } $Extensions = array('list' => array()); if (count($listExtension)) { foreach ($listExtension as $k => $v) { if ($k === 'list') { continue; } $fileInit = $v . 'init.php'; if (file_exists($fileInit)) { $sha = sha1_file($fileInit); if (isset($ext[$v]) && $ext[$v]['sha'] === $sha) { $Extensions[$v] = $ext[$v]; } else { $Extensions[$v] = array('sha' => $sha, 'ext' => $this->compileExtension($v)); } foreach ($Extensions[$v]['ext'] as $event) { if (!isset($Extensions['list'][$event['use']])) { $Extensions['list'][$event['use']] = array(); } $event['url'] = $v; $Extensions['list'][$event['use']][] = $event; } } } } if (file_exists($fileExtensionSave)) { Fx::io()->del($fileExtensionSave); } Fx::io()->create_file($fileExtensionSave); Fx::io()->write($fileExtensionSave, '<? return $Extension = ' . Fx::io()->arrayToString($Extensions) . '; ?>'); $this->extensions = $Extensions; return $Extensions; }
/** * @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; }
/** Добавляем манифест в контекст приложения */ Fx::service_context()->manifest = $manifest; /** Алиасы имен бд */ Fx::service_context()->namespace = array(); foreach ($manifest['baseCollection'] as $k => $v) { Fx::service_context()->namespace[$k] = Fx::service_context()->config['db']['sys_namespace'] . $k; } Fx::service_context()->dict = $lang; if (system_static) { Fx::cStatic()->set('template/js/jq.js'); Fx::cStatic()->set('template/js/underscore.js'); Fx::cStatic()->set('plugin/ckeditor/ckeditor.js'); Fx::cStatic()->set('plugin/ckeditor/config.js'); Fx::cStatic()->set('plugin/ckeditor/adapters/jquery.js'); Fx::cStatic()->set('template/js/lib.js'); Fx::cStatic()->set('template/js/datepicker.js'); Fx::cStatic()->set('template/js/main.js'); Fx::cStatic()->set('template/js/struct.js'); Fx::cStatic()->set('template/tpl/blocks/table/table.js'); Fx::cStatic()->set('template/tpl/blocks/project/project.js'); Fx::cStatic()->set('template/tpl/blocks/object/object.js'); Fx::cStatic()->set('template/js/setting.js'); Fx::cStatic()->set('template/css/reset.css'); Fx::cStatic()->set('template/font/fontello.css'); Fx::cStatic()->set('template/font/animation.css'); Fx::cStatic()->set('template/css/responsive-style.css'); Fx::cStatic()->set('template/css/style.css'); Fx::cStatic()->set('template/css/sys.css'); Fx::cStatic()->set('template/tpl/blocks/struct/struct.css'); Fx::cStatic()->set('template/tpl/blocks/object/object.css'); }
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); } } foreach ($dir['file'] as $v) { $file = explode('/', $v); $file = str_replace($folderFrom, '', $v); if (!file_exists($folderTo . $file)) { Fx::io()->copy($v, $folderTo . $file); } } load_url(); } else { load_url(); } } require_once 'main.html';
$twig->addExtension(new Twig_Extension_Debug()); require_once Fx::service_context()->config['folder']['template'] . '/main.php'; $render = ''; foreach (Fx::context()->template as $v) { $filePHP = Fx::service_context()->config['folder']['template'] . '/php/' . $v . '.php'; $fileHTML = 'twig/' . $v . '.twig'; if (file_exists($filePHP)) { require_once $filePHP; $render .= $twig->render($fileHTML, (array) Fx::context()); } else { throw new Exception("Error Processing Request", 404); } } if (isset($_GET['show']) && $_GET['show'] == 'glob') { header('Content-Type: text/html'); debug(Fx::context()); } else { echo $render; } break; } } catch (Exception $e) { switch ($e->getCode()) { case 404: header("HTTP/1.0 404 Not Found"); header("Status: 404 Not Found"); $errorPage = '404.html'; if (file_exists($errorPage)) { require_once $errorPage; } else { echo '<h1>404</h1><p>Not found</p>';
<?php //TODO robots.txt //TODO sitemap.xml //TODO rewrite_url //TODO chpu_list //TODO page_status Fx::context()->menu = array('robots' => 'robots.txt', 'sitemap' => 'sitemap.xml', 'rewrite' => 'Редиректы', 'history_link' => 'Страници'); Fx::context()->page = isset($_GET['page']) ? $_GET['page'] : false;
/** * @return Action */ public static function action() { if (null == self::$_action) { self::$_action = new Action(); } return self::$_action; }
<?php access(0); // Root Fx::context()->users = Fx::db()->find(Fx::service_context()->namespace['user']);
} } } } } if (isset($_GET['extension']) && $_GET['extension'] !== '' && $extView !== '') { $php = $extController; $tpl = $extView; } /** Рендерим страници */ try { if (file_exists($php)) { require_once $php; } ob_start(); require_once $tpl; Fx::context()->content = ob_get_contents(); ob_end_clean(); require_once 'template/main.html'; } catch (Exception $e) { Fx::context()->leftMenu = ''; $param = array('code' => $e->getCode(), 'message' => $e->getMessage(), 'file' => $e->getFile(), 'line' => $e->getLine()); if ($e->getCode() === 403) { $param['text'] = 'Доступ запрещен'; } if ($e->getCode() === 404) { $param['text'] = 'Такая страница не существует'; } Fx::context()->content = Fx::io()->buffer(sys . '/template/error.html', $param); require_once 'template/main.html'; }
break; case 'deleteCurso': $crs->deleteCurso(intval($dataObj->id)); break; case 'loadPlanesCurso': $planes = $crs->getPlanesCurso(intval($dataObj->id)); $planes = json_encode($planes); echo $planes; break; case 'loadProfesCursos': $profesores = $crs->getProfesCurso(intval($dataObj->id)); $profesores = json_encode($profesores); echo $profesores; break; case 'getProfes': $fetch = Fx::flattenArray($prf->getProfesores()); $result = array(); if (isset($fetch) && is_array($fetch)) { foreach ($fetch as $val) { $prfFetch = $prf->getProfesor($val); $prfFetch['horasLaborales'] = intval($prfFetch['horasLaborales']); array_push($result, $prfFetch); } } $return = json_encode($result); echo $return; break; case 'addProfe': $return = $prf->addProfe($dataObj->nombre, $dataObj->apellido, intval($dataObj->horasLaborales)); $return = json_encode($return); echo $return;
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();
} $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';
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; } } }
<?php $GLOB['menu'] = array('project' => $lang['menu.project'], 'seo&page=robots' => $lang['menu.seo'], 'struct' => $lang['menu.struct'], 'setting' => $lang['menu.setting']); Fx::context()->url = array('home' => '/' . $config['folder']['sys'] . '/index.php'); //-> leftMenu Fx::context()->leftMenu = ''; $script_config = implode('', array('<script>', 'window.CONFIG_CKEDITOR = ' . json_encode($config['ckeditor_config']), '</script>'));
<?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); } }
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 access(0, 1); // Root / Admin $markerList = Fx::db()->find(Fx::service_context()->namespace['marker']); $templateList = Fx::db()->find(Fx::service_context()->namespace['template']);
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'])); } }