commit 125949bfc87ff4e918e4a7a2fa27aaa7f4a6cdfb
parent 3d4ca1421d8382e5f7c509429832a9ee7cb2dae4
Author: markseu <mark2011@mayberg.se>
Date: Thu, 15 May 2014 13:53:54 +0200
Core update (low security is verboten)
Diffstat:
6 files changed, 166 insertions(+), 104 deletions(-)
diff --git a/README.md b/README.md
@@ -11,12 +11,12 @@ How do I install this?
2. Copy all files to your web hosting.
3. Open your website in a browser.
-Installation requirements are Apache, mod_rewrite, mod_ssl and PHP 5.3.
+Installation requirements are Apache, mod_rewrite, mod_ssl, PHP 5.3+.
How do I get started?
---------------------
You already have everything you need. Start by editing your own website.
-There are [Yellow extensions](https://github.com/markseu/yellowcms-extensions). For more information see [Yellow documentation](https://github.com/markseu/yellowcms-extensions/blob/master/documentation/README.md)
+There are [Yellow extensions](https://github.com/markseu/yellowcms-extensions). For more information see [Yellow documentation](https://github.com/markseu/yellowcms-extensions/blob/master/documentation/README.md).
License and thanks
------------------
diff --git a/system/config/config.ini b/system/config/config.ini
@@ -8,6 +8,7 @@ template = default
style = default
parser = markdownextra
+// serverScheme = http
// serverName = your.domain.name
// serverBase =
diff --git a/system/core/core-commandline.php b/system/core/core-commandline.php
@@ -5,7 +5,7 @@
// Command line core plugin
class YellowCommandline
{
- const Version = "0.2.7";
+ const Version = "0.2.8";
var $yellow; //access to API
var $content; //number of content pages
var $media; //number of media files
@@ -77,7 +77,7 @@ class YellowCommandline
$statusCode = 500;
list($this->content, $this->media, $this->system, $this->error) = array(0, 0, 0, 1);
$fileName = $this->yellow->config->get("configDir").$this->yellow->config->get("configFile");
- echo "ERROR bulding pages: Please configure serverName and serverBase in file '$fileName'!\n";
+ echo "ERROR bulding pages: Please configure serverScheme, serverName and serverBase in file '$fileName'!\n";
}
echo "Yellow $command: $this->content content, $this->media media, $this->system system";
echo ", $this->error error".($this->error!=1 ? 's' : '');
@@ -108,7 +108,7 @@ class YellowCommandline
$this->yellow->config->get("commandlineServerFile"));
} else {
$pages = new YellowPageCollection($this->yellow);
- $pages->append(new YellowPage($this->yellow, $location));
+ $pages->append(new YellowPage($this->yellow, "", "", "", $location));
$fileNamesMedia = $fileNamesSystem = array();
}
foreach($pages as $page)
@@ -291,9 +291,10 @@ class YellowCommandline
// Check static configuration
function checkStaticConfig()
{
+ $serverScheme = $this->yellow->config->get("serverScheme");
$serverName = $this->yellow->config->get("serverName");
$serverBase = $this->yellow->config->get("serverBase");
- return !empty($serverName) && $this->yellow->toolbox->isValidLocation($serverBase) && $serverBase!="/";
+ return !empty($serverScheme) && !empty($serverName) && $this->yellow->toolbox->isValidLocation($serverBase) && $serverBase!="/";
}
// Return static file name from location
@@ -310,8 +311,9 @@ class YellowCommandline
// Return static redirect data
function getStaticRedirect($location)
{
- $url = $this->yellow->toolbox->getHttpUrl($this->yellow->config->get("serverName"),
- $this->yellow->config->get("serverBase"), $location);
+ $serverScheme = $this->yellow->config->get("serverScheme");
+ $serverName = $this->yellow->config->get("serverName");
+ $url = $this->yellow->toolbox->getUrl($serverScheme, $serverName, "", $location);
$text = "<!DOCTYPE html><html>\n";
$text .= "<head>\n";
$text .= "<meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\" />\n";
diff --git a/system/core/core-webinterface.php b/system/core/core-webinterface.php
@@ -8,7 +8,7 @@ class YellowWebinterface
const Version = "0.2.9";
var $yellow; //access to API
var $users; //web interface users
- var $active; //web interface is active location? (boolean)
+ var $active; //web interface is active? (boolean)
var $loginFailed; //web interface login failed? (boolean)
var $rawDataOriginal; //raw data of page in case of errors
@@ -21,25 +21,31 @@ class YellowWebinterface
$this->yellow->config->setDefault("webinterfaceUserHome", "/");
$this->yellow->config->setDefault("webinterfaceUserHashAlgorithm", "bcrypt");
$this->yellow->config->setDefault("webinterfaceUserHashCost", "10");
+ $this->yellow->config->setDefault("webinterfaceServerScheme", "https");
+ $this->yellow->config->setDefault("webinterfaceServerName", $this->yellow->config->get("serverName"));
$this->users = new YellowWebinterfaceUsers($yellow);
$this->users->load($this->yellow->config->get("configDir").$this->yellow->config->get("webinterfaceUserFile"));
}
// Handle web interface location
- function onRequest($serverName, $serverBase, $location, $fileName)
+ function onRequest($serverScheme, $serverName, $base, $location, $fileName)
{
$statusCode = 0;
- if($this->checkLocation($location))
+ if($this->checkRequest($location))
{
- list($serverName, $serverBase, $location, $fileName) = $this->yellow->getRequestInformation($this->yellow->config->get("webinterfaceLocation"));
- if($this->checkUser()) $statusCode = $this->processRequestAction($serverName, $serverBase, $location, $fileName);
- if($statusCode == 0) $statusCode = $this->yellow->processRequest($serverName, $serverBase, $location, $fileName,
+ list($serverScheme, $serverName, $base, $location, $fileName) = $this->getRequestInformation();
+ if($this->checkUser()) $statusCode = $this->processRequestAction($serverScheme, $serverName, $base, $location, $fileName);
+ if($statusCode == 0) $statusCode = $this->yellow->processRequest($serverScheme, $serverName, $base, $location, $fileName,
false, $this->loginFailed ? 401 : 0);
} else {
- if($this->yellow->config->get("webinterfaceLocation") == "$location/")
+ $activeLocation = $this->yellow->config->get("webinterfaceLocation");
+ if(rtrim($location, '/') == rtrim($activeLocation, '/'))
{
$statusCode = 301;
- $locationHeader = $this->yellow->toolbox->getHttpLocationHeader($serverName, $serverBase, "$location/");
+ $locationHeader = $this->yellow->toolbox->getLocationHeader(
+ $this->yellow->config->get("webinterfaceServerScheme"),
+ $this->yellow->config->get("webinterfaceServerName"),
+ $base, $activeLocation);
$this->yellow->sendStatus($statusCode, $locationHeader);
}
}
@@ -79,10 +85,10 @@ class YellowWebinterface
}
}
$serverBase = $this->yellow->config->get("serverBase");
- $location = trim($this->yellow->config->get("webinterfaceLocation"), '/');
- $callback = function($matches) use ($serverBase, $location)
+ $activePath = trim($this->yellow->config->get("webinterfaceLocation"), '/');
+ $callback = function($matches) use ($serverBase, $activePath)
{
- $matches[2] = preg_replace("#^$serverBase/(?!$location)(.*)$#", "$serverBase/$location/$1", $matches[2]);
+ $matches[2] = preg_replace("#^$serverBase/(?!$activePath)(.*)$#", "$serverBase/$activePath/$1", $matches[2]);
return "<a$matches[1]href=\"$matches[2]\"$matches[3]>";
};
$output = preg_replace_callback("/<a(.*?)href=\"([^\"]+)\"(.*?)>/i", $callback, $text);
@@ -97,7 +103,6 @@ class YellowWebinterface
if($this->isActive())
{
$location = $this->yellow->config->getHtml("serverBase").$this->yellow->config->getHtml("pluginLocation");
- $language = $this->isUser() ? $this->users->getLanguage() : $this->yellow->page->get("language");
$header .= "<link rel=\"styleSheet\" type=\"text/css\" media=\"all\" href=\"{$location}core-webinterface.css\" />\n";
$header .= "<script type=\"text/javascript\" src=\"{$location}core-webinterface.js\"></script>\n";
$header .= "<script type=\"text/javascript\">\n";
@@ -109,6 +114,7 @@ class YellowWebinterface
$header .= "yellow.page.permissions = " .json_encode($permissions).";\n";
$header .= "yellow.config = ".json_encode($this->getConfigData()).";\n";
}
+ $language = $this->isUser() ? $this->users->getLanguage() : $this->yellow->page->get("language");
$header .= "yellow.text = ".json_encode($this->yellow->text->getData("webinterface", $language)).";\n";
if(defined("DEBUG")) $header .= "yellow.debug = ".json_encode(DEBUG).";\n";
$header .= "// ]]>\n";
@@ -164,7 +170,7 @@ class YellowWebinterface
}
// Process request for an action
- function processRequestAction($serverName, $serverBase, $location, $fileName)
+ function processRequestAction($serverScheme, $serverName, $base, $location, $fileName)
{
$statusCode = 0;
switch($_POST["action"])
@@ -175,11 +181,13 @@ class YellowWebinterface
if($this->yellow->toolbox->createFile($fileName, $_POST["rawdata"]))
{
$statusCode = 303;
- $locationHeader = $this->yellow->toolbox->getHttpLocationHeader($serverName, $serverBase, $location);
+ $locationHeader = $this->yellow->toolbox->getLocationHeader(
+ $serverScheme, $serverName, $base, $location);
$this->yellow->sendStatus($statusCode, $locationHeader);
} else {
$statusCode = 500;
- $this->yellow->processRequest($serverName, $serverBase, $location, $fileName, false, $statusCode);
+ $this->yellow->processRequest(
+ $serverScheme, $serverName, $base, $location, $fileName, false, $statusCode);
$this->yellow->page->error($statusCode, "Can't write file '$fileName'!");
}
}
@@ -188,18 +196,23 @@ class YellowWebinterface
if(substru($location, 0, strlenu($home)) == $home)
{
$statusCode = 303;
- $locationHeader = $this->yellow->toolbox->getHttpLocationHeader($serverName, $serverBase, $location);
+ $locationHeader = $this->yellow->toolbox->getLocationHeader(
+ $serverScheme, $serverName, $base, $location);
$this->yellow->sendStatus($statusCode, $locationHeader);
} else {
$statusCode = 302;
- $locationHeader = $this->yellow->toolbox->getHttpLocationHeader($serverName, $serverBase, $home);
+ $locationHeader = $this->yellow->toolbox->getLocationHeader(
+ $serverScheme, $serverName, $base, $home);
$this->yellow->sendStatus($statusCode, $locationHeader);
}
break;
case "logout": $this->users->destroyCookie("login");
$this->users->email = "";
$statusCode = 302;
- $locationHeader = $this->yellow->toolbox->getHttpLocationHeader($serverName, $this->yellow->config->get("serverBase"), $location);
+ $locationHeader = $this->yellow->toolbox->getLocationHeader(
+ $this->yellow->config->get("serverScheme"),
+ $this->yellow->config->get("serverName"),
+ $this->yellow->config->get("serverBase"), $location);
$this->yellow->sendStatus($statusCode, $locationHeader);
break;
default: if(!is_readable($fileName))
@@ -207,22 +220,28 @@ class YellowWebinterface
if($this->yellow->toolbox->isFileLocation($location) && $this->yellow->isContentDirectory("$location/"))
{
$statusCode = 301;
- $locationHeader = $this->yellow->toolbox->getHttpLocationHeader($serverName, $serverBase, "$location/");
+ $locationHeader = $this->yellow->toolbox->getLocationHeader(
+ $serverScheme, $serverName, $base, "$location/");
$this->yellow->sendStatus($statusCode, $locationHeader);
} else {
$statusCode = $this->checkPermissions($location, $fileName) ? 424 : 404;
- $this->yellow->processRequest($serverName, $serverBase, $location, $fileName, false, $statusCode);
+ $this->yellow->processRequest(
+ $serverScheme, $serverName, $base, $location, $fileName, false, $statusCode);
}
}
}
return $statusCode;
}
- // Check web interface location
- function checkLocation($location)
+ // Check web interface request
+ function checkRequest($location)
{
- $locationLength = strlenu($this->yellow->config->get("webinterfaceLocation"));
- $this->active = substru($location, 0, $locationLength) == $this->yellow->config->get("webinterfaceLocation");
+ if($this->yellow->toolbox->getServerScheme()==$this->yellow->config->get("webinterfaceServerScheme") &&
+ $this->yellow->toolbox->getServerName()==$this->yellow->config->get("webinterfaceServerName"))
+ {
+ $locationLength = strlenu($this->yellow->config->get("webinterfaceLocation"));
+ $this->active = substru($location, 0, $locationLength) == $this->yellow->config->get("webinterfaceLocation");
+ }
return $this->isActive();
}
@@ -268,16 +287,13 @@ class YellowWebinterface
return $permissions;
}
- // Check if web interface location
- function isActive()
- {
- return $this->active;
- }
-
- // Check if user is logged in
- function isUser()
+ // Return request information
+ function getRequestInformation()
{
- return !empty($this->users->email);
+ $serverScheme = $this->yellow->config->get("webinterfaceServerScheme");
+ $serverName = $this->yellow->config->get("webinterfaceServerName");
+ $base = rtrim($this->yellow->config->get("serverBase").$this->yellow->config->get("webinterfaceLocation"), '/');
+ return $this->yellow->getRequestInformation($serverScheme, $serverName, $base);
}
// Return configuration data including information of current user
@@ -287,10 +303,23 @@ class YellowWebinterface
"userName" => $this->users->getName(),
"userLanguage" => $this->users->getLanguage(),
"userHome" => $this->users->getHome(),
+ "serverScheme" => $this->yellow->config->get("serverScheme"),
"serverName" => $this->yellow->config->get("serverName"),
"serverBase" => $this->yellow->config->get("serverBase"));
return array_merge($data, $this->yellow->config->getData("Location"));
}
+
+ // Check if web interface request
+ function isActive()
+ {
+ return $this->active;
+ }
+
+ // Check if user is logged in
+ function isUser()
+ {
+ return !empty($this->users->email);
+ }
}
// Yellow web interface users
@@ -388,7 +417,9 @@ class YellowWebinterfaceUsers
$location = $this->yellow->config->get("serverBase").$this->yellow->config->get("webinterfaceLocation");
$session = $this->yellow->toolbox->createHash($this->users[$email]["hash"], "sha256");
if(empty($session)) $session = "error-hash-algorithm-sha256";
- setcookie($cookieName, "$email,$session", time()+60*60*24*30*365, $location);
+ setcookie($cookieName, "$email,$session", time()+60*60*24*30*365, $location,
+ $this->yellow->config->get("webinterfaceServerName"),
+ $this->yellow->config->get("webinterfaceServerScheme")=="https");
}
}
@@ -396,7 +427,9 @@ class YellowWebinterfaceUsers
function destroyCookie($cookieName)
{
$location = $this->yellow->config->get("serverBase").$this->yellow->config->get("webinterfaceLocation");
- setcookie($cookieName, "", time()-3600, $location);
+ setcookie($cookieName, "", time()-3600,
+ $location, $this->yellow->config->get("webinterfaceServerName"),
+ $this->yellow->config->get("webinterfaceServerScheme")=="https");
}
// Return information from browser cookie
diff --git a/system/core/core.php b/system/core/core.php
@@ -5,7 +5,7 @@
// Yellow main class
class Yellow
{
- const Version = "0.2.18";
+ const Version = "0.2.19";
var $page; //current page
var $pages; //pages from file system
var $config; //configuration
@@ -26,6 +26,7 @@ class Yellow
$this->config->setDefault("template", "default");
$this->config->setDefault("style", "default");
$this->config->setDefault("parser", "markdownextra");
+ $this->config->setDefault("serverScheme", $this->toolbox->getServerScheme());
$this->config->setDefault("serverName", $this->toolbox->getServerName());
$this->config->setDefault("serverBase", $this->toolbox->getServerBase());
$this->config->setDefault("styleLocation", "/media/styles/");
@@ -53,29 +54,28 @@ class Yellow
}
// Handle request
- function request($statusCodeRequest = 200)
+ function request($statusCodeRequest = 0)
{
$this->toolbox->timerStart($time);
ob_start();
$statusCode = 0;
- list($serverName, $serverBase, $location, $fileName) = $this->getRequestInformation();
- $this->page = new YellowPage($this, $location);
+ list($serverScheme, $serverName, $base, $location, $fileName) = $this->getRequestInformation();
+ $this->page = new YellowPage($this, $serverScheme, $serverName, $base, $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);
+ $statusCode = $value["obj"]->onRequest($serverScheme, $serverName, $base, $location, $fileName);
if($statusCode != 0) break;
}
}
if($statusCode == 0)
{
$this->pages->requestHandler = "core";
- $statusCode = $this->processRequest($serverName, $serverBase, $location, $fileName, true, $statusCode);
+ $statusCode = $this->processRequest($serverScheme, $serverName, $base, $location, $fileName, true, $statusCode);
}
- if($statusCodeRequest > 200) $this->page->error($statusCodeRequest, "Request error");
- if($this->isRequestError()) $statusCode = $this->processRequestError();
+ if($this->isRequestError() || $statusCodeRequest>=400) $statusCode = $this->processRequestError($statusCodeRequest);
ob_end_flush();
$this->toolbox->timerStop($time);
if(defined("DEBUG") && DEBUG>=1) echo "Yellow::request status:$statusCode location:$location<br>\n";
@@ -84,34 +84,36 @@ class Yellow
}
// Process request
- function processRequest($serverName, $serverBase, $location, $fileName, $cacheable, $statusCode)
+ function processRequest($serverScheme, $serverName, $base, $location, $fileName, $cacheable, $statusCode)
{
$handler = $this->getRequestHandler();
if($statusCode == 0)
{
if(is_readable($fileName))
{
- if(!$this->isRequestCleanUrl())
+ if($this->isRequestCleanUrl())
{
- $statusCode = 200;
- $fileName = $this->readPage($serverBase, $location, $fileName, $cacheable, $statusCode);
- } else {
$statusCode = 303;
$locationArgs = $this->toolbox->getLocationArgsCleanUrl($location, $this->config->get("contentPagination"));
- $this->sendStatus($statusCode, $this->toolbox->getHttpLocationHeader($serverName, $serverBase, $location.$locationArgs));
+ $locationHeader = $this->toolbox->getLocationHeader($serverScheme, $serverName, $base, $location.$locationArgs);
+ $this->sendStatus($statusCode, $locationHeader);
+ } else {
+ $statusCode = 200;
+ $fileName = $this->readPage($serverScheme, $serverName, $base, $location, $fileName, $cacheable, $statusCode);
}
} else {
if($this->toolbox->isFileLocation($location) && $this->isContentDirectory("$location/"))
{
$statusCode = 301;
- $this->sendStatus($statusCode, $this->toolbox->getHttpLocationHeader($serverName, $serverBase, "$location/"));
+ $locationHeader = $this->toolbox->getLocationHeader($serverScheme, $serverName, $base, "$location/");
+ $this->sendStatus($statusCode, $locationHeader);
} else {
$statusCode = 404;
- $fileName = $this->readPage($serverBase, $location, $fileName, $cacheable, $statusCode);
+ $fileName = $this->readPage($serverScheme, $serverName, $base, $location, $fileName, $cacheable, $statusCode);
}
}
} else if($statusCode >= 400) {
- $fileName = $this->readPage($serverBase, $location, $fileName, $cacheable, $statusCode);
+ $fileName = $this->readPage($serverScheme, $serverName, $base, $location, $fileName, $cacheable, $statusCode);
}
if($this->page->statusCode != 0) $statusCode = $this->sendPage();
if(defined("DEBUG") && DEBUG>=1) echo "Yellow::processRequest handler:$handler file:$fileName<br>\n";
@@ -119,19 +121,20 @@ class Yellow
}
// Process request with error
- function processRequestError()
+ function processRequestError($statusCodeRequest)
{
ob_clean();
$handler = $this->getRequestHandler();
- $fileName = $this->readPage($this->pages->serverBase, $this->page->location, $this->page->fileName,
- $this->page->cacheable, $this->page->statusCode, $this->page->get("pageError"));
+ if($statusCodeRequest >= 400) $this->page->error($statusCodeRequest, "Request error");
+ $fileName = $this->readPage($this->page->serverScheme, $this->page->serverName, $this->page->base, $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 handler:$handler file:$fileName<br>\n";
return $statusCode;
}
// Read page from file
- function readPage($serverBase, $location, $fileName, $cacheable, $statusCode, $pageError = "")
+ function readPage($serverScheme, $serverName, $base, $location, $fileName, $cacheable, $statusCode, $pageError = "")
{
if($statusCode >= 400)
{
@@ -145,8 +148,7 @@ class Yellow
$fileData = fread($fileHandle, filesize($fileName));
fclose($fileHandle);
}
- $this->pages->serverBase = $serverBase;
- $this->page = new YellowPage($this, $location);
+ $this->page = new YellowPage($this, $serverScheme, $serverName, $base, $location);
$this->page->parseData($fileName, $fileData, $cacheable, $statusCode, $pageError);
$this->page->setHeader("Content-Type", "text/html; charset=UTF-8");
$this->page->setHeader("Last-Modified", $this->page->getModified(true));
@@ -174,8 +176,12 @@ class Yellow
{
$statusCode = 301;
$location = $this->page->get("redirect");
- if(preg_match("/^[^\/]+$/", $location)) $location = $this->toolbox->getDirectoryLocation($this->page->getLocation()).$location;
- $this->page->clean($statusCode, $this->toolbox->getHttpLocationHeader($this->config->get("serverName"), "", $location));
+ if(preg_match("/^[^\/]+$/", $location))
+ {
+ $location = $this->toolbox->getDirectoryLocation($this->page->getLocation()).$location;
+ }
+ $locationHeader = $this->toolbox->getLocationHeader($this->page->serverScheme, $this->page->serverName, "", $location);
+ $this->page->clean($statusCode, $locationHeader);
$this->page->setHeader("Last-Modified", $this->page->getModified(true));
$this->page->setHeader("Cache-Control", "no-cache, must-revalidate");
}
@@ -219,13 +225,13 @@ class Yellow
}
// Return request information
- function getRequestInformation($serverBaseLocation = "")
+ function getRequestInformation($serverScheme = "", $serverName = "", $base = "")
{
- $serverName = $this->config->get("serverName");
- $serverBase = $this->config->get("serverBase");
- if(!empty($serverBaseLocation)) $serverBase .= rtrim($serverBaseLocation, '/');
+ $serverScheme = empty($serverScheme) ? $this->config->get("serverScheme") : $serverScheme;
+ $serverName = empty($serverName) ? $this->config->get("serverName") : $serverName;
+ $base = empty($base) ? $this->config->get("serverBase") : $base;
$location = $this->toolbox->getLocationNormalised();
- $location = substru($location, strlenu($serverBase));
+ $location = substru($location, strlenu($base));
$fileName = $this->toolbox->findFileFromLocation($location,
$this->config->get("contentDir"), $this->config->get("contentHomeDir"),
$this->config->get("contentDefaultFile"), $this->config->get("contentExtension"));
@@ -236,7 +242,7 @@ class Yellow
$this->config->get("contentDir"), $this->config->get("contentHomeDir"),
$this->config->get("contentDefaultFile"), $this->config->get("contentExtension"));
}
- return array($serverName, $serverBase, $location, $fileName);
+ return array($serverScheme, $serverName, $base, $location, $fileName);
}
// Return request handler
@@ -260,7 +266,8 @@ class Yellow
// Check if content directory exists
function isContentDirectory($location)
{
- $path = $this->toolbox->findFileFromLocation($location, $this->config->get("contentDir"), $this->config->get("contentHomeDir"), "", "");
+ $path = $this->toolbox->findFileFromLocation($location,
+ $this->config->get("contentDir"), $this->config->get("contentHomeDir"), "", "");
return is_dir($path);
}
@@ -334,6 +341,9 @@ class Yellow
class YellowPage
{
var $yellow; //access to API
+ var $serverScheme; //server scheme
+ var $serverName; //server name
+ var $base; //base location
var $location; //page location
var $fileName; //content file name
var $rawData; //raw data of page
@@ -347,9 +357,12 @@ class YellowPage
var $cacheable; //page is cacheable? (boolean)
var $statusCode; //status code
- function __construct($yellow, $location)
+ function __construct($yellow, $serverScheme, $serverName, $base, $location)
{
$this->yellow = $yellow;
+ $this->serverScheme = $serverScheme;
+ $this->serverName = $serverName;
+ $this->base = $base;
$this->location = $location;
$this->metaData = array();
$this->headerData = array();
@@ -361,10 +374,9 @@ class YellowPage
{
$this->fileName = $fileName;
$this->rawData = $rawData;
- $this->active = $this->yellow->toolbox->isActiveLocation($this->yellow->pages->serverBase, $this->location,
- $this->yellow->page->location);
- $this->visible = $this->yellow->toolbox->isVisibleLocation($this->yellow->pages->serverBase, $this->location,
- $fileName, $this->yellow->config->get("contentDir"));
+ $this->active = $this->yellow->toolbox->isActiveLocation($this->location, $this->yellow->page->location);
+ $this->visible = $this->yellow->toolbox->isVisibleLocation($this->location, $fileName,
+ $this->yellow->config->get("contentDir"));
$this->cacheable = $cacheable;
$this->statusCode = $statusCode;
if(!empty($pageError)) $this->error($statusCode, $pageError);
@@ -403,9 +415,11 @@ class YellowPage
if(!$this->isExisting("titleHeader")) $this->set("titleHeader", $titleHeader);
if(!$this->isExisting("titleNavigation")) $this->set("titleNavigation", $this->get("title"));
if(!$this->isExisting("titleContent")) $this->set("titleContent", $this->get("title"));
- $this->set("pageRead", $this->yellow->toolbox->getHttpUrl($this->yellow->config->get("serverName"),
+ $this->set("pageRead", $this->yellow->toolbox->getUrl(
+ $this->yellow->config->get("serverScheme"), $this->yellow->config->get("serverName"),
$this->yellow->config->get("serverBase"), $this->location));
- $this->set("pageEdit", $this->yellow->toolbox->getHttpUrl($this->yellow->config->get("serverName"),
+ $this->set("pageEdit", $this->yellow->toolbox->getUrl(
+ $this->yellow->config->get("webinterfaceServerScheme"), $this->yellow->config->get("webinterfaceServerName"),
$this->yellow->config->get("serverBase"), rtrim($this->yellow->config->get("webinterfaceLocation"), '/').$this->location));
foreach($this->yellow->plugins->plugins as $key=>$value)
{
@@ -560,14 +574,13 @@ class YellowPage
// Return absolute page location
function getLocation()
{
- return $this->yellow->pages->serverBase.$this->location;
+ return $this->base.$this->location;
}
- // Return full page URL, with server name
+ // Return page URL, with server scheme and server name
function getUrl()
{
- return $this->yellow->toolbox->getHttpUrl($this->yellow->config->get("serverName"),
- $this->yellow->pages->serverBase, $this->location);
+ return $this->yellow->toolbox->getUrl($this->serverScheme, $this->serverName, $this->base, $this->location);
}
// Return page modification time, Unix time
@@ -839,7 +852,6 @@ class YellowPages
var $yellow; //access to API
var $pages; //scanned pages
var $requestHandler; //request handler name
- var $serverBase; //requested server base
var $snippetArgs; //requested snippet arguments
function __construct($yellow)
@@ -869,7 +881,7 @@ class YellowPages
// Return page collection with path ancestry
function path($location, $absoluteLocation = false)
{
- if($absoluteLocation) $location = substru($location, strlenu($this->serverBase));
+ if($absoluteLocation) $location = substru($location, strlenu($this->yellow->page->base));
$pages = $this->find($location, false);
for($page=$pages->first(); $page; $page=$parent)
{
@@ -882,7 +894,7 @@ class YellowPages
// Return page collection with one specific page
function find($location, $absoluteLocation = false)
{
- if($absoluteLocation) $location = substru($location, strlenu($this->serverBase));
+ if($absoluteLocation) $location = substru($location, strlenu($this->yellow->page->base));
$parentLocation = $this->getParentLocation($location);
$this->scanChildren($parentLocation);
$pages = new YellowPageCollection($this->yellow);
@@ -941,7 +953,9 @@ class YellowPages
$fileData = "";
$statusCode = 0;
}
- $page = new YellowPage($this->yellow, $this->yellow->toolbox->findLocationFromFile($fileName,
+ $page = new YellowPage($this->yellow,
+ $this->yellow->page->serverScheme, $this->yellow->page->serverName, $this->yellow->page->base,
+ $this->yellow->toolbox->findLocationFromFile($fileName,
$this->yellow->config->get("contentDir"), $this->yellow->config->get("contentHomeDir"),
$this->yellow->config->get("contentDefaultFile"), $this->yellow->config->get("contentExtension")));
$page->parseData($fileName, $fileData, false, $statusCode);
@@ -1181,6 +1195,18 @@ class YellowText
// Yellow toolbox with helpers
class YellowToolbox
{
+ // Return server scheme from current HTTP request
+ function getServerScheme()
+ {
+ $serverScheme = "";
+ if(preg_match("/^HTTP\//", $_SERVER["SERVER_PROTOCOL"]))
+ {
+ $secure = isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"]!="off";
+ $serverScheme = $secure ? "https" : "http";
+ }
+ return $serverScheme;
+ }
+
// Return server name from current HTTP request
function getServerName()
{
@@ -1295,6 +1321,12 @@ class YellowToolbox
return $locationArgs;
}
+ // Return location header with URL
+ function getLocationHeader($serverScheme, $serverName, $base, $location)
+ {
+ return "Location: ".$this->getUrl($serverScheme, $serverName, $base, $location);
+ }
+
// Check if location contains location arguments
function isLocationArgs($location)
{
@@ -1351,7 +1383,7 @@ class YellowToolbox
}
// Check if location is within current HTTP request
- function isActiveLocation($serverBase, $location, $currentLocation)
+ function isActiveLocation($location, $currentLocation)
{
if($location != "/")
{
@@ -1363,7 +1395,7 @@ class YellowToolbox
}
// Check if location is visible in navigation
- function isVisibleLocation($serverBase, $location, $fileName, $pathBase)
+ function isVisibleLocation($location, $fileName, $pathBase)
{
$visible = true;
if(substru($fileName, 0, strlenu($pathBase)) == $pathBase) $fileName = substru($fileName, strlenu($pathBase));
@@ -1549,24 +1581,18 @@ class YellowToolbox
return gmdate("D, d M Y H:i:s", $timestamp)." GMT";
}
- // Return HTTP URL
- function getHttpUrl($serverName, $serverBase, $location)
+ // Return URL
+ function getUrl($serverScheme, $serverName, $base, $location)
{
- if(preg_match("/^(http|https):\/\//", $location))
+ if(!preg_match("/^\w+:/", $location))
{
- $url = $location;
+ $url = "$serverScheme://$serverName$base$location";
} else {
- $url = "http://$serverName$serverBase$location";
+ $url = $location;
}
return $url;
}
- // Return HTTP location header
- function getHttpLocationHeader($serverName, $serverBase, $location)
- {
- return "Location: ".$this->getHttpUrl($serverName, $serverBase, $location);
- }
-
// Return directory location
function getDirectoryLocation($location)
{
diff --git a/system/snippets/header.php b/system/snippets/header.php
@@ -12,5 +12,5 @@
</head>
<body>
<div class="page">
-<div class="header"><h1><a href="<?php echo $yellow->pages->serverBase."/" ?>"><?php echo $yellow->page->getHtml("sitename") ?></a></h1></div>
+<div class="header"><h1><a href="<?php echo $yellow->page->base."/" ?>"><?php echo $yellow->page->getHtml("sitename") ?></a></h1></div>
<div class="header-banner"></div>