/** * 生成单个静态页面 * @param Feiurl FeiUrl的参数 * @param alias_url 生成HTML文件的名称,如果不设置alias_url,将使用年月日生成目录及随机数为文件名的形式生成HTML文件。 * @param update_mode 更新模式,默认2为同时更新列表及文件 * 0是仅更新列表 * 1是仅更新文件 */ public function make($Feiurl, $alias_url = NULL, $update_mode = 2) { if (1 == FeiAccess('r', 'Fei_html_making')) { $this->Feiurls[] = array($Feiurl, $alias_url); return; } @(list($controller, $action, $args, $anchor) = $Feiurl); if ($url_item = FeiHtml::getUrl($controller, $action, $args, $anchor, TRUE)) { @(list($baseuri, $realfile) = $url_item); $update_mode = 1; } else { $file_root_name = '' == $GLOBALS['G_Fei']['html']['file_root_name'] ? '' : $GLOBALS['G_Fei']['html']['file_root_name'] . '/'; if (NULL == $alias_url) { $filedir = $file_root_name . date('Y/n/d') . '/'; $filename = substr(time(), 3, 10) . substr(mt_rand(100000, substr(time(), 3, 10)), 4) . ".html"; } else { $filedir = $file_root_name . dirname($alias_url) . '/'; $filename = basename($alias_url); } $baseuri = rtrim(dirname($GLOBALS['G_Fei']['url']["url_path_base"]), '/\\') . "/" . $filedir . $filename; $realfile = APP_PATH . "/" . $filedir . $filename; } if (0 == $update_mode or 2 == $update_mode) { FeiHtml::setUrl($Feiurl, $baseuri, $realfile); } if (1 == $update_mode or 2 == $update_mode) { $remoteurl = 'http://' . $_SERVER["SERVER_NAME"] . ':' . $_SERVER['SERVER_PORT'] . '/' . ltrim(FeiUrl($controller, $action, $args, $anchor, TRUE), '/\\'); $cachedata = file_get_contents($remoteurl); if (FALSE === $cachedata) { $cachedata = $this->curl_get_file_contents($remoteurl); if (FALSE === $cachedata) { FeiError("无法从网络获取页面数据,请检查:<br />1. FeiUrl生成地址是否正确!<a href='{$remoteurl}' target='_blank'>点击这里测试</a>。<br />2. 设置php.ini的allow_url_fopen为On。<br />3. 检查是否防火墙阻止了APACHE/PHP访问网络。<br />4. 建议安装CURL函数库。"); } } __mkdirs(dirname($realfile)); file_put_contents($realfile, $cachedata); } }
/** * FeiUrl * URL模式的构建函数 * @param controller 控制器名称,默认为配置'default_controller' * @param action 动作名称,默认为配置'default_action' * @param args 传递的参数,数组形式 * @param anchor 跳转锚点 * @param no_Feihtml 是否应用FeiHtml设置,在FALSE时效果与不启用FeiHtml相同。 */ function FeiUrl($controller = NULL, $action = NULL, $args = NULL, $anchor = NULL, $no_Feihtml = FALSE) { if (TRUE == $GLOBALS['G_Fei']['html']["enabled"] && TRUE != $no_Feihtml) { // 当开启HTML生成时,将查找HTML列表获取静态文件名称。 $realhtml = FeiHtml::getUrl($controller, $action, $args, $anchor); if (isset($realhtml[0])) { return $realhtml[0]; } } $controller = NULL != $controller ? $controller : $GLOBALS['G_Fei']["default_controller"]; $action = NULL != $action ? $action : $GLOBALS['G_Fei']["default_action"]; // 使用扩展点 if ($launch = FeiLaunch("function_url", array('controller' => $controller, 'action' => $action, 'args' => $args, 'anchor' => $anchor, 'no_Feihtml' => $no_Feihtml), TRUE)) { return $launch; } if (TRUE == $GLOBALS['G_Fei']['url']["url_path_info"]) { // 使用path_info方式 $url = $GLOBALS['G_Fei']['url']["url_path_base"] . "/{$controller}/{$action}"; if (NULL != $args) { foreach ($args as $key => $arg) { $url .= "/{$key}/{$arg}"; } } } else { $url = $GLOBALS['G_Fei']['url']["url_path_base"] . "?" . $GLOBALS['G_Fei']["url_controller"] . "={$controller}&"; $url .= $GLOBALS['G_Fei']["url_action"] . "={$action}"; if (NULL != $args) { foreach ($args as $key => $arg) { $url .= "&{$key}={$arg}"; } } } if (NULL != $anchor) { $url .= "#" . $anchor; } return $url; }