<?php include dirname(__FILE__) . '/../index.php'; $current = !empty($_REQUEST['current']) ? trim(filter_path($_REQUEST['current'], true)) : ''; if ($current == '') { die('error:ID is empty'); } // get current path $currentPath = $_SERVER['DOCUMENT_ROOT'] . $current . '/_data'; if ($_SERVER['REQUEST_METHOD'] == 'POST') { if (!empty($_POST['new']) && is_dir($currentPath)) { die('error:Page exists'); } } $currentData = file_get_config('attribs', $siteExtension, $currentPath); $parent = !empty($currentData['parent']) || !empty($_POST['parent']); // get section path $tmp = trim($current, '/'); $sectionPath = $_SERVER['DOCUMENT_ROOT'] . '/' . substr($tmp, 0, strpos($tmp, '/')) . '/_data'; if ($parent) { $sectionData = file_get_config('attribs', $siteExtension, $sectionPath); } else { $sectionData = file_get_config('attribs.item', $siteExtension, $sectionPath); if (empty($sectionData)) { $sectionData = file_get_config('attribs.item', $siteExtension, $_SERVER['DOCUMENT_ROOT'] . '/_data'); } } if (empty($sectionData)) { $sectionData = array(); } if (empty($currentData)) {
$ticket = isset($_COOKIE["ticket"]) ? $_COOKIE["ticket"] : null; $resobj = new response(); if ($ticket && !auth::check_ticket($ticket)) { $resobj->set(array('code' => 403, 'body' => "ticket invalid!")); goto RES_CLIENT; } /*extract a clean and standard path like /rest/xxx/xxx/xxx*/ function filter_path() { $path = preg_replace('/\\|\\\\|\\/\\//', '/', $_SERVER["REQUEST_URI"]); $path = preg_replace('/\\?[^\\/]*$/', '', $path); $path = preg_replace('/\\/$/', '', $path); return $path; } /*find the api handler method*/ $handler = find_handler(filter_path()); if ($handler) { $params = check_method_params($handler['method'], extract_params()); if (!$params && !is_array($params)) { $resobj->set(array('code' => 500, 'body' => "params invalid!")); goto RES_CLIENT; } try { $resobj = $handler['method']->invokeArgs($handler['class'], $params); } catch (ForbiddenException $e) { $resobj->set(array('code' => 403, 'body' => $e->getMessage())); } catch (Exception $e) { // Will be caught $resobj->set(array('code' => 500, 'body' => $e->getMessage())); } } else {
init_params_from_cli(); // init template path if (!empty($_GET['template'])) { $app->template_url = '/templates/' . path_filter($_GET['template']); } else { $app->template_url = '/templates/default'; } $app->template = _APP_ROOT . $app->template_url; // init current paths $app->current_url = current_url(); $app->current_section_url = current_section_url(); $app->current_path = _APP_ROOT . $app->current_url; $app->current_section_path = _APP_ROOT . $app->current_section_url; // init current data if (file_exists($app->current_path . '/_data/attribs.php')) { $app->page = (include $app->current_path . '/_data/attribs.php'); } if (!empty($_GET['tmpl'])) { $app->page['layout'] = filter_path($_GET['tmpl']); } // init current config if (file_exists($app->current_path . '/_data/config.php')) { $app->page_config = (include $app->current_path . '/_data/config.php'); } else { $app->page_config = (include $app->current_section_path . '/_data/config.php'); } // init for page type if (file_exists($app->current_section_path . '/_data/init.php')) { include $app->current_section_path . '/_data/init.php'; } return $app;
<?php include dirname(__FILE__) . '/../index.php'; $current = !empty($_POST['current']) ? trim(filter_path($_POST['current'], true)) : ''; $id = !empty($_POST['id']) ? trim(filter_path($_POST['id'], true)) : ''; $template = !empty($_POST['template']) ? trim(filter_path($_POST['template'], true)) : ''; if ($id == '' || $current == '') { die('error:ID is empty'); } // TODO filter scripts and styles $content = $_POST['content']; if (substr($id, 0, 1) == '/') { if ($template == '') { die('error:Template is empty'); } // save as partial block content $fname = $_SERVER['DOCUMENT_ROOT'] . $template . $id . $siteExtension; } else { // save as field content $fname = $_SERVER['DOCUMENT_ROOT'] . $current . '/_data/' . $id . $siteExtension; } if ($_SERVER['REQUEST_METHOD'] == 'POST') { print_r(array($current, $id, $fname)); file_put_contents($fname, $content); // TODO lock }
} } if (is_related($source_dir, $target_dir)) { echo '源文件夹和目标文件夹不可为从属关系!'; exit; } $source_list = array($source_dir); $dir = null; $encode_count = 0; $copy_count = 0; clearstatcache(); while (count($source_list) > 0) { $dir = array_pop($source_list); $files = glob($dir . '/*'); foreach ($files as $file) { $file = filter_path($file); if (is_file($file)) { $target_path = str_replace($source_dir, $target_dir, $file); $target_dir = dirname($target_path); make_dir($target_dir); if (is_encode($file)) { $code = php_strip_whitespace($file); $code = enclose($code); $code = zoeey_encode($code); $code = output($code); file_put_contents($target_path, $code); $encode_count++; } else { if (is_copy($file)) { copy($file, $target_path); $copy_count++;