Example #1
0
function sp_get_url_route()
{
    $apps = sp_scan_dir(SPAPP . "*", GLOB_ONLYDIR);
    $host = (is_ssl() ? 'https' : 'http') . "://" . $_SERVER['HTTP_HOST'];
    $routes = array();
    foreach ($apps as $a) {
        if (is_dir(SPAPP . $a)) {
            if (!(strpos($a, ".") === 0)) {
                $navfile = SPAPP . $a . "/nav.php";
                $app = $a;
                if (file_exists($navfile)) {
                    $navgeturls = (include $navfile);
                    foreach ($navgeturls as $url) {
                        //echo U("$app/$url");
                        $nav = file_get_contents($host . U("{$app}/{$url}"));
                        $nav = json_decode($nav, true);
                        if (!empty($nav) && isset($nav['urlrule'])) {
                            if (!is_array($nav['urlrule']['param'])) {
                                $params = $nav['urlrule']['param'];
                                $params = explode(",", $params);
                            }
                            sort($params);
                            $param = "";
                            foreach ($params as $p) {
                                $param .= ":{$p}/";
                            }
                            $routes[strtolower($nav['urlrule']['action']) . "/" . $param] = $nav['urlrule']['action'];
                        }
                    }
                }
            }
        }
    }
    return $routes;
}
Example #2
0
/**
 * 清空缓存
 */
function sp_clear_cache()
{
    $dirs = array();
    // runtime/
    $rootdirs = sp_scan_dir(RUNTIME_PATH . "*");
    //$noneed_clear=array(".","..","Data");
    $noneed_clear = array(".", "..");
    $rootdirs = array_diff($rootdirs, $noneed_clear);
    foreach ($rootdirs as $dir) {
        if ($dir != "." && $dir != "..") {
            $dir = RUNTIME_PATH . $dir;
            if (is_dir($dir)) {
                //array_push ( $dirs, $dir );
                $tmprootdirs = sp_scan_dir($dir . "/*");
                foreach ($tmprootdirs as $tdir) {
                    if ($tdir != "." && $tdir != "..") {
                        $tdir = $dir . '/' . $tdir;
                        if (is_dir($tdir)) {
                            array_push($dirs, $tdir);
                        } else {
                            @unlink($tdir);
                        }
                    }
                }
            } else {
                @unlink($dir);
            }
        }
    }
    $dirtool = new \Think\Dir("");
    foreach ($dirs as $dir) {
        $dirtool->delDir($dir);
    }
}
Example #3
0
 private function load_menu_lang()
 {
     $apps = sp_scan_dir(SPAPP . "*", GLOB_ONLYDIR);
     $error_menus = array();
     foreach ($apps as $app) {
         if (is_dir(SPAPP . $app)) {
             $admin_menu_lang_file = SPAPP . $app . "/Lang/" . LANG_SET . "/admin_menu.php";
             if (is_file($admin_menu_lang_file)) {
                 $lang = (include $admin_menu_lang_file);
                 L($lang);
             }
         }
     }
 }
 function site()
 {
     $option = $this->options_obj->where("option_name='site_options'")->find();
     $cmf_settings = $this->options_obj->where("option_name='cmf_settings'")->getField("option_value");
     $tpls = sp_scan_dir(C("SP_TMPL_PATH") . "*", GLOB_ONLYDIR);
     $noneed = array(".", "..", ".svn");
     $tpls = array_diff($tpls, $noneed);
     $this->assign("templates", $tpls);
     $adminstyles = sp_scan_dir(SPSTATIC . "simpleboot/themes/*", GLOB_ONLYDIR);
     $adminstyles = array_diff($adminstyles, $noneed);
     $this->assign("adminstyles", $adminstyles);
     if ($option) {
         $this->assign((array) json_decode($option['option_value']));
         $this->assign("option_id", $option['option_id']);
     }
     $this->assign("cmf_settings", json_decode($cmf_settings, true));
     $this->display();
 }
 /**
  * select nav
  */
 private function _select()
 {
     $apps = sp_scan_dir(SPAPP . "*");
     $navs = array();
     foreach ($apps as $a) {
         if (is_dir(SPAPP . $a)) {
             if (!(strpos($a, ".") === 0)) {
                 $navfile = SPAPP . $a . "/nav.php";
                 $app = $a;
                 if (file_exists($navfile)) {
                     $navgeturls = (include $navfile);
                     foreach ($navgeturls as $url) {
                         $nav = file_get_contents(U("{$app}/{$url}", array(), false, true));
                         $nav = json_decode($nav, true);
                         $navs[] = $nav;
                     }
                 }
             }
         }
     }
     return $navs;
 }
 public function spmy_getactions()
 {
     $apps_r = array("Comment");
     $groups = C("MODULE_ALLOW_LIST");
     $group_count = count($groups);
     $newmenus = array();
     $g = I("get.app");
     if (empty($g)) {
         $g = $groups[0];
     }
     if (in_array($g, $groups)) {
         if (is_dir(SPAPP . $g)) {
             if (!(strpos($g, ".") === 0)) {
                 $actiondir = SPAPP . $g . "/Controller";
                 $actions = sp_scan_dir($actiondir . "/*");
                 if (count($actions)) {
                     foreach ($actions as $mf) {
                         if (!(strpos($mf, ".") === 0)) {
                             if ($g == "Admin") {
                                 $m = str_replace("Controller.class.php", "", $mf);
                                 $noneed_models = array("Public", "Index", "Main");
                                 if (in_array($m, $noneed_models)) {
                                     continue;
                                 }
                             } else {
                                 if (strpos($mf, "adminController.class.php") || strpos($mf, "Admin") === 0) {
                                     $m = str_replace("Controller.class.php", "", $mf);
                                 } else {
                                     continue;
                                 }
                             }
                             $class = A($g . "/" . $m);
                             $adminbaseaction = new \Common\Controller\AdminbaseController();
                             $base_methods = get_class_methods($adminbaseaction);
                             $methods = get_class_methods($class);
                             $methods = array_diff($methods, $base_methods);
                             foreach ($methods as $a) {
                                 if (!(strpos($a, "_") === 0) && !(strpos($a, "spmy_") === 0)) {
                                     $where['app'] = $g;
                                     $where['model'] = $m;
                                     $where['action'] = $a;
                                     $count = $this->Menu->where($where)->count();
                                     if (!$count) {
                                         $data['parentid'] = 0;
                                         $data['app'] = $g;
                                         $data['model'] = $m;
                                         $data['action'] = $a;
                                         $data['type'] = "1";
                                         $data['status'] = "0";
                                         $data['name'] = "未知";
                                         $data['listorder'] = "0";
                                         $result = $this->Menu->add($data);
                                         if ($result !== false) {
                                             $newmenus[] = $g . "/" . $m . "/" . $a . "";
                                         }
                                     }
                                     $name = strtolower("{$g}/{$m}/{$a}");
                                     $mwhere = array("name" => $name);
                                     $find_rule = $this->auth_rule_model->where($mwhere)->find();
                                     if (!$find_rule) {
                                         $this->auth_rule_model->add(array("name" => $name, "module" => $app, "type" => "admin_url", "title" => $menu['name']));
                                         //type 1-admin rule;2-user rule
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
         $index = array_search($g, $groups);
         $nextindex = $index + 1;
         $nextindex = $nextindex >= $group_count ? 0 : $nextindex;
         if ($nextindex) {
             $this->assign("nextapp", $groups[$nextindex]);
         }
         $this->assign("app", $g);
     }
     $this->assign("newmenus", $newmenus);
     $this->display("getactions");
 }
Example #7
0
/**
 * 获取Portal应用当前模板下的模板列表
 * @return array
 */
function sp_admin_get_tpl_file_list()
{
    $template_path = C("SP_TMPL_PATH") . C("SP_DEFAULT_THEME") . "/Portal/";
    $files = sp_scan_dir($template_path . "*");
    $tpl_files = array();
    foreach ($files as $f) {
        if ($f != "." || $f != "..") {
            if (is_file($template_path . $f)) {
                $suffix = C("TMPL_TEMPLATE_SUFFIX");
                $result = preg_match("/{$suffix}\$/", $f);
                if ($result) {
                    $tpl = str_replace($suffix, "", $f);
                    $tpl_files[$tpl] = $tpl;
                } else {
                    if (preg_match("/\\.php\$/", $f)) {
                        $tpl = str_replace($suffix, "", $f);
                        $tpl_files[$tpl] = $tpl;
                    }
                }
            }
        }
    }
    return $tpl_files;
}
Example #8
0
/**
 * 获取所有钩子,包括系统,应用,模板
 */
function sp_get_hooks($refresh = false)
{
    if (!$refresh) {
        $return_hooks = F('all_hooks');
        if (!empty($return_hooks)) {
            return $return_hooks;
        }
    }
    $return_hooks = array();
    $system_hooks = array("url_dispatch", "app_init", "app_begin", "app_end", "action_begin", "action_end", "module_check", "path_info", "template_filter", "view_begin", "view_end", "view_parse", "view_filter", "body_start", "footer", "footer_end", "sider", "comment", 'admin_home');
    $app_hooks = array();
    $apps = sp_scan_dir(SPAPP . "*", GLOB_ONLYDIR);
    foreach ($apps as $app) {
        $hooks_file = SPAPP . $app . "/hooks.php";
        if (is_file($hooks_file)) {
            $hooks = (include $hooks_file);
            $app_hooks = is_array($hooks) ? array_merge($app_hooks, $hooks) : $app_hooks;
        }
    }
    $tpl_hooks = array();
    $tpls = sp_scan_dir("tpl/*", GLOB_ONLYDIR);
    foreach ($tpls as $tpl) {
        $hooks_file = "tpl/{$tpl}/hooks" . C("TMPL_TEMPLATE_SUFFIX");
        if (is_file($hooks_file)) {
            $hooks = file_get_contents($hooks_file);
            $hooks = preg_replace("/[^0-9A-Za-z_-]/u", ",", $hooks);
            $hooks = explode(",", $hooks);
            $hooks = array_filter($hooks);
            $tpl_hooks = is_array($hooks) ? array_merge($tpl_hooks, $hooks) : $tpl_hooks;
        }
    }
    $return_hooks = array_merge($system_hooks, $app_hooks, $tpl_hooks);
    $return_hooks = array_unique($return_hooks);
    F('all_hooks', $return_hooks);
    return $return_hooks;
}
 /**
  * select nav
  */
 private function _select()
 {
     $apps = sp_scan_dir(SPAPP . "*");
     $host = (is_ssl() ? 'https' : 'http') . "://" . $_SERVER['HTTP_HOST'] . ":" . $_SERVER['SERVER_PORT'];
     $navs = array();
     foreach ($apps as $a) {
         if (is_dir(SPAPP . $a)) {
             if (!(strpos($a, ".") === 0)) {
                 $navfile = SPAPP . $a . "/nav.php";
                 $app = $a;
                 if (file_exists($navfile)) {
                     $navgeturls = (include $navfile);
                     foreach ($navgeturls as $url) {
                         //echo U("$app/$url");
                         $nav = file_get_contents($host . U("{$app}/{$url}"));
                         $nav = json_decode($nav, true);
                         $navs[] = $nav;
                     }
                 }
             }
         }
     }
     return $navs;
 }