diff --git a/system/core/core.php b/system/core/core.php index 7740d2a..b6214cb 100755 --- a/system/core/core.php +++ b/system/core/core.php @@ -5,7 +5,7 @@ // Yellow main class class Yellow { - const Version = "0.1.10"; + const Version = "0.1.11"; var $page; //current page data var $pages; //current page tree from file system var $toolbox; //toolbox with helpers @@ -26,7 +26,6 @@ class Yellow $this->config->setDefault("template", "default"); $this->config->setDefault("style", "default"); $this->config->setDefault("parser", "markdown"); - $this->config->setDefault("yellowVersion", Yellow::Version); $this->config->setDefault("serverName", $this->toolbox->getServerName()); $this->config->setDefault("serverBase", $this->toolbox->getServerBase()); $this->config->setDefault("styleLocation", "/media/styles/"); @@ -57,21 +56,26 @@ class Yellow { $this->toolbox->timerStart($time); ob_start(); + $statusCode = 0; $serverName = $this->config->get("serverName"); $serverBase = $this->config->get("serverBase"); $location = $this->getRelativeLocation($serverBase); $fileName = $this->getContentFileName($location); - $statusCode = 0; $this->page = new Yellow_Page($this, $location); foreach($this->plugins->plugins as $key=>$value) { if(method_exists($value["obj"], "onRequest")) { + $this->pages->requestHandler = $key; $statusCode = $value["obj"]->onRequest($serverName, $serverBase, $location, $fileName); - if($statusCode) break; + if($statusCode != 0) break; } } - if($statusCode == 0) $statusCode = $this->processRequest($serverName, $serverBase, $location, $fileName, true, $statusCode); + if($statusCode == 0) + { + $this->pages->requestHandler = "core"; + $statusCode = $this->processRequest($serverName, $serverBase, $location, $fileName, true, $statusCode); + } if($statusCodeRequest > 200) $this->page->error($statusCodeRequest, "Request error"); if($this->isRequestError()) { @@ -88,13 +92,14 @@ class Yellow // Process request function processRequest($serverName, $serverBase, $location, $fileName, $cacheable, $statusCode) { + $handler = $this->getRequestHandler(); if($statusCode == 0) { if(is_readable($fileName)) { $statusCode = 200; $fileName = $this->readPage($serverBase, $location, $fileName, $cacheable, $statusCode); - if($this->page->isExisting("redirect") && $cacheable) + if($this->page->isExisting("redirect") && $handler=="core") { $statusCode = 301; $locationHeader = $this->toolbox->getHttpLocationHeader($serverName, $serverBase, $this->page->get("redirect")); @@ -116,18 +121,19 @@ class Yellow $fileName = $this->readPage($serverBase, $location, $fileName, $cacheable, $statusCode); } if($this->page->statusCode != 0) $statusCode = $this->sendPage(); - if(defined("DEBUG") && DEBUG>=1) echo "Yellow::processRequest base:$serverBase file:$fileName
\n"; + if(defined("DEBUG") && DEBUG>=1) echo "Yellow::processRequest handler:$handler base:$serverBase file:$fileName
\n"; return $statusCode; } // Process request with error function processRequestError() { + $handler = $this->getRequestHandler(); $serverBase = $this->pages->serverBase; $fileName = $this->readPage($serverBase, $this->page->location, $this->page->fileName, $this->page->cacheable, $this->page->statusCode, $this->page->get("pageError")); $statusCode = $this->sendPage(); - if(defined("DEBUG") && DEBUG>=1) echo "Yellow::processRequestError base:$serverBase file:$fileName
\n"; + if(defined("DEBUG") && DEBUG>=1) echo "Yellow::processRequestError handler:$handler base:$serverBase file:$fileName
\n"; return $statusCode; } @@ -199,6 +205,12 @@ class Yellow } } + // Return name of request handler + function getRequestHandler() + { + return $this->pages->requestHandler; + } + // Check for request error function isRequestError() { @@ -391,7 +403,7 @@ class Yellow_Page { if(method_exists($value["obj"], "onParseContent")) $text = $value["obj"]->onParseContent($text, $this->statusCode); } - $this->setContent($text); + $this->parser->textHtml = $text; if(!$this->isExisting("description")) { $this->set("description", $this->yellow->toolbox->createTextDescription($this->getContent(), 150)); @@ -449,18 +461,12 @@ class Yellow_Page { return $this->getHtml("title"); } - - // Set page content, HTML encoded - function setContent($html) - { - $this->parser->html = $html; - } - + // Return page content, HTML encoded function getContent() { $this->parseContent(); - return $this->parser->html; + return $this->parser->textHtml; } // Return absolute page location @@ -662,10 +668,11 @@ class Yellow_PageCollection extends ArrayObject // Yellow page tree from file system class Yellow_Pages { - var $yellow; //access to API - var $pages; //scanned pages - var $serverBase; //requested server base - var $snippetArgs; //requested snippet arguments + var $yellow; //access to API + var $pages; //scanned pages + var $requestHandler; //request handler + var $serverBase; //requested server base + var $snippetArgs; //requested snippet arguments function __construct($yellow) { @@ -923,14 +930,14 @@ class Yellow_Toolbox { for($i=1; $itoolbox->getDirectoryEntries($yellow->config->get("pluginDir"), "/.*\.php/", true, false) as $entry) diff --git a/system/core/core_commandline.php b/system/core/core_commandline.php index b9359cc..b781afc 100755 --- a/system/core/core_commandline.php +++ b/system/core/core_commandline.php @@ -5,7 +5,7 @@ // Command line core plugin class Yellow_Commandline { - const Version = "0.1.3"; + const Version = "0.1.4"; var $yellow; //access to API // Initialise plugin @@ -141,31 +141,34 @@ class Yellow_Commandline $statusCode = $this->yellow->request(); if($statusCode != 404) { - $ok = false; + $fileOk = true; $modified = strtotime($this->yellow->page->getHeader("Last-Modified")); - if(preg_match("/^(\w+)\/(\w+)/", $this->yellow->page->getHeader("Content-Type"), $matches)) - { - $contentType = "$matches[1]/$matches[2]"; - $locationExtension = $this->getStaticLocation($location, ".$matches[2]"); - } - if(empty($contentType) || $contentType=="text/html") + list($contentType, $contentEncoding) = explode(';', $this->yellow->page->getHeader("Content-Type"), 2); + $staticLocation = $this->getStaticLocation($location, $contentType); + if($location == $staticLocation) { $fileName = $this->getStaticFileName($location, $path); $fileData = ob_get_contents(); if($statusCode == 301) $fileData = $this->getStaticRedirect($this->yellow->page->getHeader("Location")); - $ok = $this->makeStaticFile($fileName, $fileData, $modified); + $fileOk = $this->makeStaticFile($fileName, $fileData, $modified); } else { - $fileName = $this->getStaticFileName($location, $path); - $fileData = $this->getStaticRedirect("http://$serverName$serverBase$locationExtension"); - $ok = $this->makeStaticFile($fileName, $fileData, $modified); - if($ok) + if(!$this->yellow->toolbox->isFileLocation($location)) { - $fileName = $this->getStaticFileName($locationExtension, $path); - $fileData = ob_get_contents(); - $ok = $this->makeStaticFile($fileName, $fileData, $modified); + $fileName = $this->getStaticFileName($location, $path); + $fileData = $this->getStaticRedirect("http://$serverName$serverBase$staticLocation"); + $fileOk = $this->makeStaticFile($fileName, $fileData, $modified); + if($fileOk) + { + $fileName = $this->getStaticFileName($staticLocation, $path); + $fileData = ob_get_contents(); + $fileOk = $this->makeStaticFile($fileName, $fileData, $modified); + } + } else { + $statusCode = 500; + $this->yellow->page->error($statusCode, "Invalid file name for type '$contentType'!"); } } - if(!$ok) + if(!$fileOk) { $statusCode = 500; $this->yellow->page->error($statusCode, "Can't write file '$fileName'!"); @@ -186,10 +189,8 @@ class Yellow_Commandline $statusCode = $this->yellow->request($statusCodeRequest); if($statusCode == $statusCodeRequest) { - $fileData = ob_get_contents(); $modified = strtotime($this->yellow->page->getHeader("Last-Modified")); - $ok = $this->makeStaticFile($fileName, $fileData, $modified); - if(!$ok) + if(!$this->makeStaticFile($fileName, ob_get_contents(), $modified)) { $statusCode = 500; $this->yellow->page->error($statusCode, "Can't write file '$fileName'!"); @@ -213,6 +214,28 @@ class Yellow_Commandline $this->yellow->toolbox->modifyFile($fileNameDest, filemtime($fileNameSource)); } + // Return static location corresponding to content type + function getStaticLocation($location, $contentType) + { + $extension = ($pos = strrposu($location, '.')) ? substru($location, $pos) : ""; + if($contentType == "text/html") + { + if($this->yellow->toolbox->isFileLocation($location)) + { + if(!empty($extension) && $extension!=".html") $location .= ".html"; + } + } else { + if($this->yellow->toolbox->isFileLocation($location)) + { + if(empty($extension)) $location .= ".unknown"; + } else { + if(preg_match("/^(\w+)\/(\w+)/", $contentType, $matches)) $extension = ".$matches[2]"; + $location .= "index$extension"; + } + } + return $location; + } + // Return static file name from location function getStaticFileName($location, $path) { @@ -224,13 +247,6 @@ class Yellow_Commandline return $fileName; } - // Return static location with file extension - function getStaticLocation($location, $extension) - { - if(!$this->yellow->toolbox->isFileLocation($location)) $location .= "index"; - return $location.$extension; - } - // Return static redirect data function getStaticRedirect($url) { diff --git a/system/core/core_markdown.php b/system/core/core_markdown.php index 6b78901..15713e7 100755 --- a/system/core/core_markdown.php +++ b/system/core/core_markdown.php @@ -7,7 +7,7 @@ class Yellow_Markdown { const Version = "0.1.5"; var $markdown; //markdown parser - var $html; //generated HTML + var $textHtml; //generated text (HTML format) // Initialise plugin function initPlugin($yellow) @@ -18,7 +18,7 @@ class Yellow_Markdown // Parse text function parse($text) { - return $this->html = $this->markdown->transform($text); + return $this->textHtml = $this->markdown->transform($text); } } diff --git a/system/core/core_plaintext.php b/system/core/core_plaintext.php new file mode 100755 index 0000000..6128964 --- /dev/null +++ b/system/core/core_plaintext.php @@ -0,0 +1,21 @@ +text = $text; + return $textHtml; + } +} + +$yellow->registerPlugin("plaintext", "Yellow_Plaintext", Yellow_Plaintext::Version); +?> \ No newline at end of file diff --git a/system/core/core_rawhtml.php b/system/core/core_rawhtml.php deleted file mode 100755 index b47d248..0000000 --- a/system/core/core_rawhtml.php +++ /dev/null @@ -1,19 +0,0 @@ -html = $text; - } -} - -$yellow->registerPlugin("rawhtml", "Yellow_RawHtml", Yellow_RawHtml::Version); -?> \ No newline at end of file diff --git a/system/core/core_webinterface.php b/system/core/core_webinterface.php index 692209e..b42dda1 100755 --- a/system/core/core_webinterface.php +++ b/system/core/core_webinterface.php @@ -5,7 +5,7 @@ // Web interface core plugin class Yellow_Webinterface { - const Version = "0.1.6"; + const Version = "0.1.7"; var $yellow; //access to API var $users; //web interface users var $activeLocation; //web interface location? (boolean) @@ -182,7 +182,7 @@ class Yellow_Webinterface function checkUserPermissions($location, $fileName) { $path = dirname($fileName); - return is_dir($path); + return is_dir($path) && strlenu(basename($fileName))<128; } // Check if web interface location diff --git a/system/snippets/content.php b/system/snippets/content.php new file mode 100755 index 0000000..3b4f688 --- /dev/null +++ b/system/snippets/content.php @@ -0,0 +1,5 @@ +getSnippetArgs(); ?> +
+

+ +
diff --git a/system/templates/default.php b/system/templates/default.php index 13f962c..61703f0 100755 --- a/system/templates/default.php +++ b/system/templates/default.php @@ -1,7 +1,4 @@ snippet("header") ?> snippet("navigation") ?> -
-

page->getTitle() ?>

-page->getContent() ?> -
+snippet("content", $yellow->page->getTitle(), $yellow->page->getContent()) ?> snippet("footer") ?> \ No newline at end of file