コード例 #1
0
ファイル: aPController.php プロジェクト: SanneA/wodegongjubao
 public function __construct(Model $model, content $view, $plugins, $server)
 {
     parent::__construct($model, $view, $plugins, $server);
     $this->view->add_dict("plugin_" . get_class($this));
     $this->view->add_dict("admin");
     if (!empty($_SESSION["mwcabuild"])) {
         $this->configs = Configs::readCfg(get_class($this), $_SESSION["mwcabuild"]);
     }
     //подгружаем конфиги модуля сразу);
 }
コード例 #2
0
ファイル: router.php プロジェクト: SanneA/wodegongjubao
 private function __construct()
 {
     /**
      * если не установлен билд, то сначала грузим главный конфиг. в нем читаем билд,
      * устанавливаем и далее вычитываем конфиг конкретного билда.
      */
     $mainpath = "configs" . DIRECTORY_SEPARATOR . "configs.php";
     if (file_exists($mainpath)) {
         require_once $mainpath;
     } else {
         die("main cfg error!");
     }
     if (empty($_SESSION["mwcbuild"])) {
         $_SESSION["mwcbuild"] = $cfg["defaultbuild"];
     }
     define("tbuild", $_SESSION["mwcbuild"]);
     $globalcfg = Configs::readCfg("main", $_SESSION["mwcbuild"]);
     if (empty($_SESSION["mwcserver"])) {
         //сервер
         $_SESSION["mwcserver"] = 0;
     }
     if (empty($_SESSION["mwcbuild"])) {
         //сервер
         $_SESSION["mwcbuild"] = $globalcfg["tbuild"];
     }
     if (empty($_SESSION["mwclang"])) {
         //язык
         $_SESSION["mwclang"] = $globalcfg["dlang"];
     }
     if (empty($_SESSION["mwcpoints"])) {
         //группа
         $_SESSION["mwcpoints"] = $globalcfg["defgrp"];
     }
     $adres = $globalcfg["address"];
     try {
         $content = new content($adres, $globalcfg["theme"], $_SESSION["mwclang"]);
     } catch (Exception $e) {
         echo $e->getMessage();
         die;
     }
     $isBackground = isset($_GET["bg"]) ? 1 : NULL;
     //если идет обращение к серверу
     try {
         $db = connect::start();
         if (empty($_SESSION["mwcuid"])) {
             $uid = 0;
         } else {
             $uid = $_SESSION["mwcuid"];
         }
         $builder = new builder(tbuild, $_SESSION["mwclang"], $_SESSION["mwcserver"]);
         // проверяем наличие списка модулей и плагинов
         //region плагины
         $plugin = "";
         require_once "build" . DIRECTORY_SEPARATOR . tbuild . DIRECTORY_SEPARATOR . "_dat" . DIRECTORY_SEPARATOR . $_SESSION["mwcserver"] . "_" . $_SESSION["mwclang"] . "_plugins.php";
         if (is_array($plugin) && is_null($isBackground)) {
             foreach ($plugin as $name => $param) {
                 if ($param["pstate"] == 1) {
                     $contoller_path = "build" . DIRECTORY_SEPARATOR . tbuild . DIRECTORY_SEPARATOR . "plugins" . DIRECTORY_SEPARATOR . "controller" . DIRECTORY_SEPARATOR . $name . ".php";
                     //region проверка на пользователя (если есть)
                     $ccfg = Configs::readCfg("plugin_" . $name, $_SESSION["mwcbuild"]);
                     if (!empty($ccfg["allowedUsrs"])) {
                         $usrs = explode(",", $ccfg["allowedUsrs"]);
                         if (!in_array($uid, $usrs)) {
                             $err = 2;
                         } else {
                             $err = 0;
                         }
                     } else {
                         $err = 2;
                     }
                     //endregion
                     if (file_exists($contoller_path) && (!empty($param["groups"]) || $err == 0)) {
                         if (empty($param["groups"])) {
                             $paccess = array();
                         } else {
                             $paccess = explode(",", $param["groups"]);
                         }
                         try {
                             if (!empty($param["mname"])) {
                                 $model_path = "build" . DIRECTORY_SEPARATOR . tbuild . DIRECTORY_SEPARATOR . "plugins" . DIRECTORY_SEPARATOR . "model" . DIRECTORY_SEPARATOR . $param["mname"] . ".php";
                                 if (file_exists($model_path)) {
                                     require $model_path;
                                 }
                                 require $contoller_path;
                                 if ((in_array($_SESSION["mwcpoints"], $paccess) || in_array(4, $paccess) || $err == 0) && class_exists($param["mname"])) {
                                     $tmp = $param["mname"];
                                     $model = new $tmp();
                                     $pcontoller = new $name($model, $content, $plugin, $_SESSION["mwcserver"]);
                                     if (method_exists($name, "action_index")) {
                                         $pcontoller->init();
                                         $pcontoller->action_index();
                                         $pcontoller->parentOut();
                                     }
                                 }
                             } else {
                                 if (in_array($_SESSION["mwcpoints"], $paccess) || in_array(4, $paccess)) {
                                     $model = new $globalcfg["defModel"]();
                                     $pcontoller = new PController($model, $content, $plugin, $_SESSION["mwcserver"]);
                                     $pcontoller->genNonMVC($contoller_path);
                                     $pcontoller->parentOut($name);
                                 }
                             }
                         } catch (Exception $e) {
                             $content->error(1);
                             $content->setFContainer("plugin_{$name}", true);
                         }
                     }
                 }
             }
         }
         //endregion
         //region страницы
         //region получение контроллера и экшена
         $action_name = "action_index";
         if (!isset($_GET["p"])) {
             $controller = $globalcfg["defpage"];
         } else {
             $controller = htmlspecialchars($_GET["p"], ENT_QUOTES);
             if ($controller == "index") {
                 $controller = $globalcfg["defpage"];
             }
         }
         if (isset($_GET["a"])) {
             $action_name = "action_" . $_GET["a"];
         }
         //endregion
         require_once "build" . DIRECTORY_SEPARATOR . tbuild . DIRECTORY_SEPARATOR . "_dat" . DIRECTORY_SEPARATOR . $_SESSION["mwcserver"] . "_" . $_SESSION["mwclang"] . "_pages.php";
         if (isset($page[$controller])) {
             $path = "build" . DIRECTORY_SEPARATOR . tbuild . DIRECTORY_SEPARATOR . $page[$controller]["ppath"] . DIRECTORY_SEPARATOR . $controller . ".php";
             if (file_exists($path)) {
                 $access = explode(",", $page[$controller]["groups"]);
                 //region проверка на пользователя (если есть)
                 $ccfg = Configs::readCfg($controller, $_SESSION["mwcbuild"]);
                 if (!empty($ccfg["allowedUsrs"])) {
                     $usrs = explode(",", $ccfg["allowedUsrs"]);
                     if (!in_array($uid, $usrs)) {
                         $err = 2;
                     } else {
                         $err = 0;
                     }
                 } else {
                     $err = 2;
                 }
                 //endregion
                 try {
                     if (in_array($_SESSION["mwcpoints"], $access) || in_array(4, $access) || $err == 0) {
                         if (!empty($page[$controller]["mname"]) && !empty($page[$controller]["mpath"])) {
                             $modelpath = "build" . DIRECTORY_SEPARATOR . tbuild . DIRECTORY_SEPARATOR . $page[$controller]["mpath"] . DIRECTORY_SEPARATOR . $page[$controller]["mname"] . ".php";
                             require_once $path;
                             if (file_exists($modelpath)) {
                                 require_once $modelpath;
                                 $modelname = $page[$controller]["mname"];
                             } else {
                                 $modelname = "Model";
                                 $action_name = "showError";
                                 $db->SQLog("model {$modelpath} wasn't found", "router", 2);
                             }
                             $model = new $modelname($db);
                             $contolinst = new $controller($model, $content, $page, $_SESSION["mwcserver"]);
                             $contolinst->init();
                             if (method_exists($controller, $action_name)) {
                                 $contolinst->{$action_name}();
                             } else {
                                 $contolinst->action_index();
                                 $db->SQLog("{$controller} hasn't action {$action_name}", "router", 3);
                             }
                             $contolinst->parentOut($isBackground);
                         } else {
                             $model = new $globalcfg["defModel"]();
                             $contolinst = new $globalcfg["defController"]($model, $content, $page, $_SESSION["mwcserver"]);
                             $contolinst->genNonMVC($path);
                             $contolinst->parentOut($isBackground);
                         }
                     } else {
                         $model = new Model($db);
                         $contolinst = new Controller($model, $content, $page, $_SESSION["mwcserver"]);
                         $contolinst->init();
                         $contolinst->showError(2);
                         $contolinst->parentOut($isBackground);
                         if (!empty($_SESSION["mwcuid"])) {
                             $theGuy = $_SESSION["mwcuid"];
                         } else {
                             $theGuy = "?";
                         }
                         $db->SQLog("user({$theGuy}) try access to {$controller} but he hasn't access", "router", 6);
                     }
                 } catch (Exception $e) {
                     $model = new Model($db);
                     $contolinst = new Controller($model, $content, $page, $_SESSION["mwcserver"]);
                     $contolinst->init();
                     $contolinst->showErrorText($e->getMessage());
                     $contolinst->parentOut($isBackground);
                 }
             } else {
                 $model = new Model($db);
                 $contolinst = new Controller($model, $content, $page, $_SESSION["mwcserver"]);
                 $contolinst->init();
                 $contolinst->showError(3);
                 $contolinst->parentOut($isBackground);
                 $db->SQLog("controller {$path} ({$controller}) wasn't found", "router", 1, true);
             }
         } else {
             $model = new Model($db);
             $contolinst = new Controller($model, $content, $page, $_SESSION["mwcserver"]);
             $contolinst->init();
             $contolinst->showError(3);
             $contolinst->parentOut($isBackground);
             $db->SQLog("controller {$controller} wasn't register", "router", 1);
         }
         //endregion
     } catch (Exception $ex) {
         $stack = $ex->getTrace();
         $msg = $ex->getMessage() . " in file: " . basename($stack[3]["file"]) . " line: " . $stack[3]["line"];
         self::addlog(tbuild . "_error", $msg, "log");
         content::showError("Something went wrong", "please, check logs.");
     }
 }
コード例 #3
0
 public function __construct(Model $model, content $view, $plugins, $server)
 {
     parent::__construct($model, $view, $plugins, $server);
     $this->view->add_dict("plugin_" . get_class($this));
     $this->configs = Configs::readCfg("plugin_" . get_class($this), tbuild);
 }
コード例 #4
0
ファイル: arouter.php プロジェクト: SanneA/wodegongjubao
 private function __construct()
 {
     $mainpath = "configs" . DIRECTORY_SEPARATOR . "configs.php";
     if (file_exists($mainpath)) {
         require_once $mainpath;
     } else {
         die("main cfg error!");
     }
     $globalcfg = Configs::readCfg("main", $cfg["defaultabuild"]);
     if (empty($_SESSION["mwcabuild"])) {
         $_SESSION["mwcabuild"] = $cfg["defaultabuild"];
     }
     define("tbuild", $cfg["defaultabuild"]);
     //$baseDir = substr(dirname( __FILE__ ),0,-4);
     if (empty($_SESSION["mwcserver"])) {
         //сервер
         $_SESSION["mwcserver"] = 0;
     }
     if (empty($_SESSION["mwclang"])) {
         //язык
         $_SESSION["mwclang"] = $globalcfg["dlang"];
     }
     if (empty($_SESSION["mwcapoints"])) {
         //группа в админке
         $_SESSION["mwcapoints"] = $globalcfg["defgrp"];
     }
     $adres = $globalcfg["address"];
     //для редактирования билдов (подгрузка всего и вся (настроек)
     if (isset($_POST["whosconfig"])) {
         $builds = Tools::getAllBuilds();
         if (!empty($builds[$_POST["whosconfig"]])) {
             $_SESSION["mwccfgread"] = $_POST["whosconfig"];
         }
     } else {
         if (empty($_SESSION["whosconfig"])) {
             $_SESSION["whosconfig"] = "admin";
         }
     }
     $content = new content($adres, $globalcfg["theme"], $_SESSION["mwclang"]);
     $isBackground = isset($_GET["bg"]) ? 1 : NULL;
     //если идет обращение к серверу
     try {
         $db = connect::start();
         $builder = new builder(tbuild, $_SESSION["mwclang"], $_SESSION["mwcserver"]);
         // проверяем наличие списка модулей и плагинов
         $action_name = "action_index";
         //region плагины
         $plugin = "";
         require_once "build" . DIRECTORY_SEPARATOR . tbuild . DIRECTORY_SEPARATOR . "_dat" . DIRECTORY_SEPARATOR . $_SESSION["mwcserver"] . "_" . $_SESSION["mwclang"] . "_plugins.php";
         if (is_array($plugin) && is_null($isBackground)) {
             $aplugin = new ArrayIterator($plugin);
             foreach ($aplugin as $name => $param) {
                 if ($param["pstate"] == 2) {
                     $contoller_path = "build" . DIRECTORY_SEPARATOR . tbuild . DIRECTORY_SEPARATOR . "plugins" . DIRECTORY_SEPARATOR . "controller" . DIRECTORY_SEPARATOR . $name . ".php";
                     if (file_exists($contoller_path) && !empty($param["groups"])) {
                         $paccess = explode(",", $param["groups"]);
                         if (!empty($param["mname"])) {
                             $model_path = "build" . DIRECTORY_SEPARATOR . tbuild . DIRECTORY_SEPARATOR . "plugins" . DIRECTORY_SEPARATOR . "model" . DIRECTORY_SEPARATOR . $param["mname"] . ".php";
                             if (file_exists($model_path)) {
                                 require $model_path;
                             }
                             require $contoller_path;
                             if (in_array($_SESSION["mwcapoints"], $paccess) || in_array(4, $paccess) && class_exists($param["mname"])) {
                                 $tmp = $param["mname"];
                                 $model = new $tmp();
                                 $pcontoller = new $name($model, $content, $plugin, $_SESSION["mwcserver"]);
                                 if (method_exists($name, "action_index")) {
                                     $pcontoller->init();
                                     $pcontoller->action_index();
                                     $pcontoller->parentOut();
                                 }
                             }
                         } else {
                             if (in_array($_SESSION["mwcapoints"], $paccess) || in_array(4, $paccess)) {
                                 $model = new $globalcfg["defModel"]();
                                 $pcontoller = new PController($model, $content, $plugin, $_SESSION["mwcserver"]);
                                 $pcontoller->genNonMVC($contoller_path);
                                 $pcontoller->parentOut($name);
                             }
                         }
                     }
                 }
             }
         }
         //endregion
         //region страницы
         //region получение контроллера и экшена
         if (!isset($_GET["p"])) {
             $controller = $globalcfg["defpage"];
         } else {
             $controller = htmlspecialchars($_GET["p"], ENT_QUOTES);
             if ($controller == "index") {
                 $controller = $globalcfg["defpage"];
             }
         }
         if (isset($_GET["a"])) {
             $action_name = "action_" . $_GET["a"];
         }
         //endregion
         require_once "build" . DIRECTORY_SEPARATOR . tbuild . DIRECTORY_SEPARATOR . "_dat" . DIRECTORY_SEPARATOR . $_SESSION["mwcserver"] . "_" . $_SESSION["mwclang"] . "_pages.php";
         if (empty($page)) {
             $page = array();
         }
         if (isset($page[$controller])) {
             $path = "build" . DIRECTORY_SEPARATOR . tbuild . DIRECTORY_SEPARATOR . $page[$controller]["ppath"] . DIRECTORY_SEPARATOR . $controller . ".php";
             if (file_exists($path)) {
                 $access = explode(",", $page[$controller]["groups"]);
                 if (in_array($_SESSION["mwcapoints"], $access) || $_SESSION["mwcapoints"] == 1) {
                     if (!empty($page[$controller]["mname"]) && !empty($page[$controller]["mpath"])) {
                         $modelpath = "build" . DIRECTORY_SEPARATOR . tbuild . DIRECTORY_SEPARATOR . $page[$controller]["mpath"] . DIRECTORY_SEPARATOR . $page[$controller]["mname"] . ".php";
                         require_once $path;
                         if (file_exists($modelpath)) {
                             require_once $modelpath;
                             $modelname = $page[$controller]["mname"];
                         } else {
                             $modelname = "Model";
                             $action_name = "showError";
                             $db->SQLog("model {$modelpath} wasn't found", "arouter", 3);
                         }
                         $model = new $modelname($db);
                         $contolinst = new $controller($model, $content, $page, $_SESSION["mwcserver"]);
                         $contolinst->init();
                         if (method_exists($controller, $action_name)) {
                             $contolinst->{$action_name}();
                         } else {
                             $contolinst->action_index();
                             $db->SQLog("action {$action_name} wasn't found for {$controller}", "arouter", 3);
                         }
                         $contolinst->parentOut($isBackground);
                     } else {
                         $model = new $globalcfg["defModel"]();
                         $contolinst = new $globalcfg["defController"]($model, $content, $page, $_SESSION["mwcserver"]);
                         if (method_exists($contolinst, $action_name) && $action_name != "action_index" && (in_array($_SESSION["mwcapoints"], $access) || $_SESSION["mwcapoints"] == 1)) {
                             $contolinst->{$action_name}();
                         } else {
                             $contolinst->genNonMVC($path);
                         }
                         $contolinst->parentOut($isBackground);
                     }
                 } else {
                     $model = new Model($db);
                     $contolinst = new Controller($model, $content, $page, $_SESSION["mwcserver"]);
                     $contolinst->init();
                     $contolinst->showError(2);
                     $contolinst->parentOut($isBackground);
                     if (!empty($_SESSION["mwcuid"])) {
                         $theGuy = $_SESSION["mwcuid"];
                     } else {
                         $theGuy = "?";
                     }
                     if (!empty($_SESSION["mwcauid"])) {
                         $theGuy = $_SESSION["mwcauid"];
                     }
                     $db->SQLog("user ({$theGuy}) try access to {$controller} but he hasn't access", "arouter", 6);
                 }
             } else {
                 $model = new Model();
                 $contolinst = new Controller($model, $content, $page, $_SESSION["mwcserver"]);
                 $contolinst->init();
                 $contolinst->showError(3);
                 $contolinst->parentOut($isBackground);
                 $db->SQLog("controller '{$path}' wasn't found", "arouter", 1);
             }
         } else {
             $model = new Model();
             $contolinst = new Controller($model, $content, $page, $_SESSION["mwcserver"]);
             $contolinst->init();
             $contolinst->showError(3);
             $contolinst->parentOut($isBackground);
             $db->SQLog("controller '{$controller}' does't register in system", "arouter", 1);
         }
         //endregion
     } catch (Exception $ex) {
         $stack = $ex->getTrace();
         $msg = $ex->getMessage() . " in file: " . basename($stack[3]["file"]) . " line: " . $stack[3]["line"];
         self::addlog(tbuild . "_error", $msg, "log");
         content::showError("Something went wrong", "please, check logs.");
     }
 }