/** * Initializes application's router on Drupal. * This creates a last hook for the requests before 404 errors. * It dynamically creates a route if the application can dispatch to the url. * * TODO: Document the _escaped_fragment_ logic here... * @return void */ protected function _initRouter($dispatcher, $options) { if (isset($_REQUEST["_escaped_fragment_"])) { $_fragment = $_REQUEST["_escaped_fragment_"]; //strip the first and trailing slashes... if (substr($_fragment, -1) === "/") { $_fragment = substr($_fragment, 0, strlen($_fragment) - 1); } //Add first slash if (substr($_fragment, 0, 1) === "/") { $_fragment = substr($_fragment, -1 * (strlen($_fragment) - 1)); } $_REQUEST["q"] = $_fragment; $_GET["q"] = $_fragment; } $item = menu_get_item(); if (!$item) { global $base_url; if (isset($_REQUEST["q"])) { $loc = $_REQUEST["q"]; } else { //try the clean urls... //FIXME: Look out for hard coded http... $loc = preg_replace("/" . preg_replace("/\\//", '\\/', $base_url) . "/", "", "http://" . $_SERVER["HTTP_HOST"] . $_SERVER['REQUEST_URI'], 1); list($loc) = explode("?", $loc); } //Strip of the last slash... if (substr($loc, -1) === "/") { $loc = substr($loc, 0, strlen($loc) - 1); } //Add first slash if (substr($loc, 0, 1) !== "/") { $loc = "/" . $loc; } if ($dispatcher->routeExists($loc)) { $menu_item = menu_get_item('krtc/dispatcher'); $menu_item['page_arguments'] = array($loc, $options); menu_set_item(preg_replace("/\\//", "", $loc, 1), $menu_item); } } }
function dida_setup() { global $base_path, $error, $setting_file, $conf_dir; if ($_POST) { if (empty($_POST['admin'])) { $error[] = '管理员帐号不能为空。'; } else { if (empty($_POST['mail'])) { $error[] = '邮箱不能为空。'; } else { if (empty($_POST['adminpass'])) { $error[] = '管理员帐号密码不能为空。'; } else { if ($_POST['adminpass'] != $_POST['adminpass2']) { $error[] = '两次输入的密码不一致。'; } else { if (empty($_POST['site_name'])) { $error[] = '网站名称不能为空。'; } else { if (empty($_POST['site_mail'])) { $error[] = '站长邮箱不能为空。'; } else { if (empty($_POST['status'])) { $error[] = '请设置网站访问状态。'; } else { if (db_connect('default')) { require_once DIDA_ROOT . '/modules/system/system.install'; require_once DIDA_ROOT . '/includes/module.inc'; require_once DIDA_ROOT . '/includes/menu.inc'; if (_system_install()) { if (module_set_list('theme') && module_set_list('module')) { db_exec('UPDATE {system} SET status = -1 WHERE filename = :name', array(':name' => 'default')); if ($messages = module_set_enabled('disabled', 'module', array('system', 'block', 'user', 'field'))) { _install_setting_chmod(); // 锁定安装文件,修改配置文件权限 _install_bootstrap(); // 载入模块 module_enabled_variable(); //写入模块、主题列表 menu_set_item(); // 写入menu $admin = check_plain($_POST['admin']); $pass = user_get_salt_pass($_POST['adminpass']); //写入第一个用户 db_query('INSERT INTO {users} (name, pass, salt, mail, created, status) VALUES(?, ?, ?, ?, ?, 1)', array($admin, $pass['pass'], $pass['salt'], $_POST['mail'], $_SERVER['REQUEST_TIME'])); //写入匿名用户 db_query('INSERT INTO {users} (name, created, status) VALUES(?, ?, 1)', array('匿名', $_SERVER['REQUEST_TIME'])); //调整 uid db_query('UPDATE {users} SET uid = 0 WHERE name = ?', array('匿名')); //测试简洁链接 $clean_url = 0; $goto = '?q=user/login'; block_cache_lists('default'); // 导入区块 $modules = array('system' => 'modules/system', 'user' => 'modules/user', 'block' => 'modules/block', 'category' => 'modules/category'); dd_set_lang($modules, array('zh-hans', 'zh-hant')); // 导入语言包 $var_timestamp = serialize($_SERVER['REQUEST_TIME']); $var_args = array('status', serialize($_POST['status']), 'site_global', serialize(array('logo' => $base_path . 'misc/images/logo.png', 'favicon' => $base_path . 'misc/images/favicon.ico', 'name' => trim($_POST['site_name']), 'mail' => $_POST['site_mail'])), 'clean_url', serialize($clean_url), 'cache_css_and_js_timestamp', $var_timestamp, 'site_created', $var_timestamp); db_query('INSERT INTO {variable} (name, value) VALUES (?, ?), (?, ?), (?, ?), (?, ?), (?, ?)', $var_args); require_once './includes/filter.inc'; /** * 输入格式缓存 */ filter_get_filters(); filter_set_cache(); var_init(); unset($_SESSION['messages']); foreach ($messages as $mmessage) { dd_set_message($message); } // 创建头像字段 $field = array('name' => t('field', '头像'), 'module' => 'user', 'type' => 'field', 'field_type' => 'file', 'field_key' => 'avatar', 'weight' => -20, 'data' => array('multi' => 1, 'filesize' => 4096, 'filename' => '[uid]', 'extension' => 'jpg', 'savepath' => 'avatar', 'thumbs' => array('thumb' => '85x85', 'medium' => '200x200'))); $data = (object) $field; field_save($data); /** * 基本安装完成后,可继续执行自定义安装 * 自定义安装文件名称为:install.custom.php * 入口函数:install_custom * 文件目录结构如下(按优先级): * $conf_dir/install/install.custom.php * install/install.custom.php */ if (is_file(DIDA_ROOI . '/' . $conf_dir . '/install/install.custom.php') && function_exists('install_custom')) { install_custom(); } else { if (is_file(DIDA_ROOT . '/install/install.custom.php') && function_exists('install_custom')) { install_custom(); } } // 登录超级用户 user_login(user_load(1)); dd_goto('user/login'); } } $error[] = dd_get_message(); } else { $error[] = '无法创建配置表'; } } else { $error[] = '连接数据库失败,请检查配置,或<a href="install.php?setup=1&clear=1">重新开始安装</a>'; } } } } } } } } } }