This commit is contained in:
Stéphane Goetz 2015-04-23 21:04:00 +02:00
parent d817875755
commit f3d472363d
7 changed files with 47 additions and 53 deletions

View File

@ -152,10 +152,10 @@ class Daux
} }
$params['theme'] = DauxHelper::getTheme( $params['theme'] = DauxHelper::getTheme(
$this->local_base . DS . 'resources' . DS . 'themes' . DS . $this->options['theme-name'], $this->options['theme-name'],
$params['base_url'], $params['base_url'],
$this->local_base, $this->local_base,
$params['base_url'] . "resources/themes/" . $this->options['theme-name'] . '/' $params['base_url']
); );
return $params; return $params;

View File

@ -26,9 +26,10 @@ class DauxHelper
return $request; return $request;
} }
public static function getTheme($theme_folder, $base_url, $local_base, $theme_url) public static function getTheme($theme_name, $base_url, $local_base, $current_url)
{ {
$name = static::pathinfo($theme_folder); $theme_folder = $local_base . DS . 'resources' . DS . 'themes' . DS . $theme_name;
$theme_url = $base_url . "resources/themes/" . $theme_name . '/';
$theme = array(); $theme = array();
if (is_file($theme_folder . DS . "config.json")) { if (is_file($theme_folder . DS . "config.json")) {
@ -37,10 +38,10 @@ class DauxHelper
$theme = array(); $theme = array();
} }
} }
$theme['name'] = $name['filename'];
//Default parameters for theme //Default parameters for theme
$theme += [ $theme += [
'name' => $theme_name,
'css' => [], 'css' => [],
'js' => [], 'js' => [],
'fonts' => [], 'fonts' => [],
@ -50,7 +51,7 @@ class DauxHelper
'templates' => $theme_folder . DS . 'templates', 'templates' => $theme_folder . DS . 'templates',
]; ];
$substitutions = ['<local_base>' => $local_base, '<base_url>' => $base_url, '<theme_url>' => $theme_url]; $substitutions = ['<local_base>' => $local_base, '<base_url>' => $current_url, '<theme_url>' => $theme_url];
// Substitute some placeholders // Substitute some placeholders
$theme['templates'] = strtr($theme['templates'], $substitutions); $theme['templates'] = strtr($theme['templates'], $substitutions);

View File

@ -32,10 +32,10 @@ class Generator
// Rebase Theme // Rebase Theme
$params['theme'] = DauxHelper::getTheme( $params['theme'] = DauxHelper::getTheme(
$params['local_base'] . DS . 'resources' . DS . 'themes' . DS . $params['theme-name'], $params['theme-name'],
$base_url, $params['base_url'],
$params['local_base'], $params['local_base'],
$params['base_url'] . "resources/themes/" . $params['theme-name'] . '/' $base_url
); );
$params['image'] = str_replace('<base_url>', $base_url, $params['image']); $params['image'] = str_replace('<base_url>', $base_url, $params['image']);

View File

@ -1,38 +0,0 @@
<?php namespace Todaymade\Daux\Server;
class Helper
{
public static function getRequest()
{
if (isset($_SERVER['PATH_INFO'])) {
$uri = $_SERVER['PATH_INFO'];
} elseif (isset($_SERVER['REQUEST_URI'])) {
$uri = $_SERVER['REQUEST_URI'];
if (strpos($uri, $_SERVER['SCRIPT_NAME']) === 0) {
$uri = substr($uri, strlen($_SERVER['SCRIPT_NAME']));
} elseif (strpos($uri, dirname($_SERVER['SCRIPT_NAME'])) === 0) {
$uri = substr($uri, strlen(dirname($_SERVER['SCRIPT_NAME'])));
}
if (strncmp($uri, '?/', 2) === 0) {
$uri = substr($uri, 2);
}
$parts = preg_split('#\?#i', $uri, 2);
$uri = $parts[0];
if (isset($parts[1])) {
$_SERVER['QUERY_STRING'] = $parts[1];
parse_str($_SERVER['QUERY_STRING'], $_GET);
} else {
$_SERVER['QUERY_STRING'] = '';
$_GET = array();
}
$uri = parse_url($uri, PHP_URL_PATH);
} else {
return false;
}
$uri = str_replace(array('//', '../'), '/', trim($uri, '/'));
if ($uri == "") {
$uri = "first_page";
}
return $uri;
}
}

View File

@ -37,7 +37,7 @@ class Server
{ {
$this->params = $this->daux->getParams(); $this->params = $this->daux->getParams();
$request = Helper::getRequest(); $request = $this->getRequest();
$request = urldecode($request); $request = urldecode($request);
$request_type = isset($query['method']) ? $query['method'] : ''; $request_type = isset($query['method']) ? $query['method'] : '';
if ($request == 'first_page') { if ($request == 'first_page') {
@ -128,4 +128,38 @@ class Server
} }
return MarkdownPage::fromFile($file, $params); return MarkdownPage::fromFile($file, $params);
} }
public function getRequest()
{
if (isset($_SERVER['PATH_INFO'])) {
$uri = $_SERVER['PATH_INFO'];
} elseif (isset($_SERVER['REQUEST_URI'])) {
$uri = $_SERVER['REQUEST_URI'];
if (strpos($uri, $_SERVER['SCRIPT_NAME']) === 0) {
$uri = substr($uri, strlen($_SERVER['SCRIPT_NAME']));
} elseif (strpos($uri, dirname($_SERVER['SCRIPT_NAME'])) === 0) {
$uri = substr($uri, strlen(dirname($_SERVER['SCRIPT_NAME'])));
}
if (strncmp($uri, '?/', 2) === 0) {
$uri = substr($uri, 2);
}
$parts = preg_split('#\?#i', $uri, 2);
$uri = $parts[0];
if (isset($parts[1])) {
$_SERVER['QUERY_STRING'] = $parts[1];
parse_str($_SERVER['QUERY_STRING'], $_GET);
} else {
$_SERVER['QUERY_STRING'] = '';
$_GET = array();
}
$uri = parse_url($uri, PHP_URL_PATH);
} else {
return false;
}
$uri = str_replace(array('//', '../'), '/', trim($uri, '/'));
if ($uri == "") {
$uri = "first_page";
}
return $uri;
}
} }

View File

@ -34,12 +34,10 @@ class Builder
continue; continue;
} }
$file_details = DauxHelper::pathinfo($path);
$entry = null; $entry = null;
if (is_dir($path)) { if (is_dir($path)) {
$entry = static::build($path, $ignore, $params, $new_parents); $entry = static::build($path, $ignore, $params, $new_parents);
} elseif (in_array($file_details['extension'], Daux::$VALID_MARKDOWN_EXTENSIONS)) { } elseif (in_array(pathinfo($path, PATHINFO_EXTENSION), Daux::$VALID_MARKDOWN_EXTENSIONS)) {
$entry = new Content($path, $new_parents); $entry = new Content($path, $new_parents);
if ($params['mode'] === Daux::STATIC_MODE) { if ($params['mode'] === Daux::STATIC_MODE) {

View File

@ -15,7 +15,6 @@ class Content extends Entry
protected function getFilename($file) protected function getFilename($file)
{ {
$file = DauxHelper::pathinfo($file); return DauxHelper::pathinfo($file)['filename'];
return $file['filename'];
} }
} }