diff options
author | Ludovic Pouzenc <lpouzenc@gmail.com> | 2013-10-29 18:42:08 +0100 |
---|---|---|
committer | Ludovic Pouzenc <lpouzenc@gmail.com> | 2013-10-29 18:42:08 +0100 |
commit | c98515883097467896a3f46b755c8cb892fe8961 (patch) | |
tree | be2e4f5450e9bc9cf692e8dfac7c9780eaa7019b /code/admin/render.php | |
download | editablesite-c98515883097467896a3f46b755c8cb892fe8961.tar.gz editablesite-c98515883097467896a3f46b755c8cb892fe8961.tar.bz2 editablesite-c98515883097467896a3f46b755c8cb892fe8961.zip |
Import initial avec une arbrescence éclatée
Diffstat (limited to 'code/admin/render.php')
-rw-r--r-- | code/admin/render.php | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/code/admin/render.php b/code/admin/render.php new file mode 100644 index 0000000..9d4175e --- /dev/null +++ b/code/admin/render.php @@ -0,0 +1,59 @@ +<?php + require_once('utils.php'); + need_auth(); + + // Config loading + $site_conf = load_ini_site_conf("content/site_conf.ini"); + if ( ! is_array($site_conf) ) trigger_error("Error parsing site_conf.ini", E_USER_ERROR); + + // URL params clean-up + $action=sanitize($_GET, 'action', '/[^a-z_]+/', 'preview'); /* Could be : preview, edit, publish */ + $page=sanitize($_GET, 'page', '/[^a-z0-9\/]+/', $site_conf['site_default_page']); // Never put \. in this regex + + // Template vars init ($page, $page_path, $page_props, $page_tpl_url) + $page_path = "content/$page"; + if ( ! is_dir($page_path) ) trigger_error("Error : page does not exists ($page)", E_USER_ERROR); + $page_props = load_ini_page_props($page); + if ( ! is_array($page_props) ) trigger_error("Error parsing page properties ($page/props.ini)", E_USER_ERROR); + $page_tpl_url = str_repeat('../', substr_count($page, '/')) . "admin/templates/" . $page_props['page_template'] . '/'; + + if ($action === 'publish') ob_start(); /* Buffering for redirecting to file instead of browser */ + + // Basic HTML5 skeleton + page props insertion + template call +?> +<!DOCTYPE html> +<html> +<head> +<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> +<title><?=$page_props['page_title']?></title> +<meta name="description" content="<?=$page_props['page_description']?>"> +<meta name="keywords" content="<?=$page_props['page_keywords']?>"> +<link rel="stylesheet" href="<?="$page_tpl_url" /*FIXME*/?>screen.css"> +</head> +<body> +<?php + require("templates/" . $page_props['page_template'] . '/layout-' . $page_props['page_layout'] . '.php'); + if ( $action === 'edit') require('editor-bind-code.html'); +?> +</body> +</html> +<?php + // If publishing, write resulting HTML page on a .html file + if ($action === 'publish') { + $out=ob_get_contents(); + ob_end_clean(); + $dest="../$page.html"; + $destfold=dirname($dest); + if ( ! is_dir($destfold) ) { + if ( ! mkdir($destfold,0777,true) ) { + trigger_error("Error : Can't create '$destfold'", E_USER_ERROR); + } + } + $size=file_put_contents($dest, $out); + if ( $size === FALSE ) { + trigger_error("Error : Can't write " . strlen($out) . " bytes to '$dest'", E_USER_ERROR); + } else { + echo json_encode(array('result'=>'ok', 'size' => $size)); + } + } +?> |