Hello multi language mode (remix for Andreas)
This commit is contained in:
parent
b771f51849
commit
00f6e45ed8
3 changed files with 79 additions and 38 deletions
|
@ -1,4 +1,4 @@
|
|||
Yellow 0.4.3
|
||||
Yellow 0.4.4
|
||||
============
|
||||
Yellow is for people who make websites. [Visit website](http://datenstrom.se/yellow).
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
// Web interface core plugin
|
||||
class YellowWebinterface
|
||||
{
|
||||
const Version = "0.4.1";
|
||||
const Version = "0.4.2";
|
||||
var $yellow; //access to API
|
||||
var $users; //web interface users
|
||||
var $active; //web interface is active? (boolean)
|
||||
|
@ -48,7 +48,7 @@ class YellowWebinterface
|
|||
$locationHeader = $this->yellow->toolbox->getLocationHeader(
|
||||
$this->yellow->config->get("webinterfaceServerScheme"),
|
||||
$this->yellow->config->get("webinterfaceServerName"), $base, $activeLocation);
|
||||
$this->yellow->sendStatus($statusCode, $locationHeader);
|
||||
$this->yellow->sendStatus($statusCode, false, $locationHeader);
|
||||
}
|
||||
}
|
||||
return $statusCode;
|
||||
|
@ -185,7 +185,7 @@ class YellowWebinterface
|
|||
if($statusCode == 0)
|
||||
{
|
||||
$statusCode = $this->userLoginFailed ? 401 : 0;
|
||||
$statusCode = $this->yellow->processRequest($serverScheme, $serverName, $base, $location, $fileName, false, $statusCode);
|
||||
$statusCode = $this->yellow->processRequest($serverScheme, $serverName, $base, $location, $fileName, $statusCode, false);
|
||||
}
|
||||
return $statusCode;
|
||||
}
|
||||
|
@ -196,16 +196,16 @@ class YellowWebinterface
|
|||
$statusCode = 0;
|
||||
if(is_readable($fileName))
|
||||
{
|
||||
$statusCode = $this->yellow->processRequest($serverScheme, $serverName, $base, $location, $fileName, false, 0);
|
||||
$statusCode = $this->yellow->processRequest($serverScheme, $serverName, $base, $location, $fileName, 0, false);
|
||||
} else {
|
||||
if($this->yellow->toolbox->isFileLocation($location) && $this->yellow->isContentDirectory("$location/"))
|
||||
{
|
||||
$statusCode = 301;
|
||||
$locationHeader = $this->yellow->toolbox->getLocationHeader($serverScheme, $serverName, $base, "$location/");
|
||||
$this->yellow->sendStatus($statusCode, $locationHeader);
|
||||
$this->yellow->sendStatus($statusCode, false, $locationHeader);
|
||||
} else {
|
||||
$statusCode = $this->userPermission ? 424 : 404;
|
||||
$this->yellow->processRequest($serverScheme, $serverName, $base, $location, $fileName, false, $statusCode);
|
||||
$this->yellow->processRequest($serverScheme, $serverName, $base, $location, $fileName, $statusCode, false);
|
||||
}
|
||||
}
|
||||
return $statusCode;
|
||||
|
@ -225,15 +225,15 @@ class YellowWebinterface
|
|||
{
|
||||
$statusCode = 303;
|
||||
$locationHeader = $this->yellow->toolbox->getLocationHeader($serverScheme, $serverName, $base, $page->location);
|
||||
$this->yellow->sendStatus($statusCode, $locationHeader);
|
||||
$this->yellow->sendStatus($statusCode, false, $locationHeader);
|
||||
} else {
|
||||
$statusCode = 500;
|
||||
$this->yellow->processRequest($serverScheme, $serverName, $base, $location, $fileName, false, $statusCode);
|
||||
$this->yellow->processRequest($serverScheme, $serverName, $base, $location, $fileName, $statusCode, false);
|
||||
$this->yellow->page->error($statusCode, "Can't write file '$page->fileName'!");
|
||||
}
|
||||
} else {
|
||||
$statusCode = 500;
|
||||
$this->yellow->processRequest($serverScheme, $serverName, $base, $location, $fileName, false, $statusCode);
|
||||
$this->yellow->processRequest($serverScheme, $serverName, $base, $location, $fileName, $statusCode, false);
|
||||
$this->yellow->page->error($statusCode, $page->get("pageError"));
|
||||
}
|
||||
}
|
||||
|
@ -256,15 +256,15 @@ class YellowWebinterface
|
|||
{
|
||||
$statusCode = 303;
|
||||
$locationHeader = $this->yellow->toolbox->getLocationHeader($serverScheme, $serverName, $base, $page->location);
|
||||
$this->yellow->sendStatus($statusCode, $locationHeader);
|
||||
$this->yellow->sendStatus($statusCode, false, $locationHeader);
|
||||
} else {
|
||||
$statusCode = 500;
|
||||
$this->yellow->processRequest($serverScheme, $serverName, $base, $location, $fileName, false, $statusCode);
|
||||
$this->yellow->processRequest($serverScheme, $serverName, $base, $location, $fileName, $statusCode, false);
|
||||
$this->yellow->page->error($statusCode, "Can't write file '$page->fileName'!");
|
||||
}
|
||||
} else {
|
||||
$statusCode = 500;
|
||||
$this->yellow->processRequest($serverScheme, $serverName, $base, $location, $fileName, false, $statusCode);
|
||||
$this->yellow->processRequest($serverScheme, $serverName, $base, $location, $fileName, $statusCode, false);
|
||||
$this->yellow->page->error($statusCode, $page->get("pageError"));
|
||||
}
|
||||
}
|
||||
|
@ -282,10 +282,10 @@ class YellowWebinterface
|
|||
{
|
||||
$statusCode = 303;
|
||||
$locationHeader = $this->yellow->toolbox->getLocationHeader($serverScheme, $serverName, $base, $location);
|
||||
$this->yellow->sendStatus($statusCode, $locationHeader);
|
||||
$this->yellow->sendStatus($statusCode, false, $locationHeader);
|
||||
} else {
|
||||
$statusCode = 500;
|
||||
$this->yellow->processRequest($serverScheme, $serverName, $base, $location, $fileName, false, $statusCode);
|
||||
$this->yellow->processRequest($serverScheme, $serverName, $base, $location, $fileName, $statusCode, false);
|
||||
$this->yellow->page->error($statusCode, "Can't delete file '$fileName'!");
|
||||
}
|
||||
}
|
||||
|
@ -301,11 +301,11 @@ class YellowWebinterface
|
|||
{
|
||||
$statusCode = 303;
|
||||
$locationHeader = $this->yellow->toolbox->getLocationHeader($serverScheme, $serverName, $base, $location);
|
||||
$this->yellow->sendStatus($statusCode, $locationHeader);
|
||||
$this->yellow->sendStatus($statusCode, false, $locationHeader);
|
||||
} else {
|
||||
$statusCode = 302;
|
||||
$locationHeader = $this->yellow->toolbox->getLocationHeader($serverScheme, $serverName, $base, $home);
|
||||
$this->yellow->sendStatus($statusCode, $locationHeader);
|
||||
$this->yellow->sendStatus($statusCode, false, $locationHeader);
|
||||
}
|
||||
return $statusCode;
|
||||
}
|
||||
|
@ -320,7 +320,7 @@ class YellowWebinterface
|
|||
$this->yellow->config->get("serverScheme"),
|
||||
$this->yellow->config->get("serverName"),
|
||||
$this->yellow->config->get("serverBase"), $location);
|
||||
$this->yellow->sendStatus($statusCode, $locationHeader);
|
||||
$this->yellow->sendStatus($statusCode, false, $locationHeader);
|
||||
return $statusCode;
|
||||
}
|
||||
|
||||
|
@ -431,7 +431,7 @@ class YellowWebinterface
|
|||
function getPageNew($serverScheme, $serverName, $base, $location, $fileName, $rawData)
|
||||
{
|
||||
$page = new YellowPage($this->yellow, $serverScheme, $serverName, $base, $location, $fileName);
|
||||
$page->parseData($rawData, false, 0);
|
||||
$page->parseData($rawData, 0, false);
|
||||
$page->fileName = $this->yellow->toolbox->findFileFromTitle(
|
||||
$page->get($this->yellow->config->get("webinterfaceFilePrefix")), $page->get("title"), $fileName,
|
||||
$this->yellow->config->get("contentDefaultFile"), $this->yellow->config->get("contentExtension"));
|
||||
|
@ -467,12 +467,12 @@ class YellowWebinterface
|
|||
function getPageUpdate($serverScheme, $serverName, $base, $location, $fileName, $rawDataSource, $rawDataEdit)
|
||||
{
|
||||
$page = new YellowPage($this->yellow, $serverScheme, $serverName, $base, $location, $fileName);
|
||||
$page->parseData($this->mergeText($location, $rawDataSource, $rawDataEdit, $fileName), false, 0);
|
||||
$page->parseData($this->mergeText($location, $rawDataSource, $rawDataEdit, $fileName), 0, false);
|
||||
if(empty($page->rawData)) $page->error(500, "Page has been modified by someone else!");
|
||||
if($this->yellow->toolbox->isFileLocation($location) && !$page->isError())
|
||||
{
|
||||
$pageSource = new YellowPage($this->yellow, $serverScheme, $serverName, $base, $location, $fileName);
|
||||
$pageSource->parseData($rawDataSource, false, 0);
|
||||
$pageSource->parseData($rawDataSource, 0, false);
|
||||
$prefix = $this->yellow->config->get("webinterfaceFilePrefix");
|
||||
if($pageSource->get($prefix)!=$page->get($prefix) || $pageSource->get("title")!=$page->get("title"))
|
||||
{
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
// Yellow main class
|
||||
class Yellow
|
||||
{
|
||||
const Version = "0.4.3";
|
||||
const Version = "0.4.4";
|
||||
var $page; //current page
|
||||
var $pages; //pages from file system
|
||||
var $config; //configuration
|
||||
|
@ -77,7 +77,7 @@ class Yellow
|
|||
if($statusCode == 0)
|
||||
{
|
||||
$this->pages->requestHandler = "core";
|
||||
$statusCode = $this->processRequest($serverScheme, $serverName, $base, $location, $fileName, true, $statusCode);
|
||||
$statusCode = $this->processRequest($serverScheme, $serverName, $base, $location, $fileName, $statusCode, true);
|
||||
}
|
||||
if($this->page->isError() || $statusCodeRequest>=400) $statusCode = $this->processRequestError($statusCodeRequest);
|
||||
ob_end_flush();
|
||||
|
@ -88,7 +88,7 @@ class Yellow
|
|||
}
|
||||
|
||||
// Process request
|
||||
function processRequest($serverScheme, $serverName, $base, $location, $fileName, $cacheable, $statusCode)
|
||||
function processRequest($serverScheme, $serverName, $base, $location, $fileName, $statusCode, $cacheable)
|
||||
{
|
||||
$handler = $this->getRequestHandler();
|
||||
if($statusCode == 0)
|
||||
|
@ -100,26 +100,26 @@ class Yellow
|
|||
$statusCode = 303;
|
||||
$locationArgs = $this->toolbox->getLocationArgsCleanUrl($this->config->get("contentPagination"));
|
||||
$locationHeader = $this->toolbox->getLocationHeader($serverScheme, $serverName, $base, $location.$locationArgs);
|
||||
$this->sendStatus($statusCode, $locationHeader);
|
||||
$this->sendStatus($statusCode, false, $locationHeader);
|
||||
} else {
|
||||
$statusCode = 200;
|
||||
$fileName = $this->readPage($serverScheme, $serverName, $base, $location, $fileName, $cacheable, $statusCode);
|
||||
$fileName = $this->readPage($serverScheme, $serverName, $base, $location, $fileName, $statusCode, $cacheable);
|
||||
}
|
||||
} else {
|
||||
if(($this->toolbox->isFileLocation($location) && $this->isContentDirectory("$location/")) ||
|
||||
($location=="/" && $this->config->get("multiLanguageMode")))
|
||||
{
|
||||
$statusCode = 301;
|
||||
$location = $this->toolbox->isFileLocation($location) ? "$location/" : "/".$this->config->get("language")."/";
|
||||
$location = $this->toolbox->isFileLocation($location) ? "$location/" : "/".$this->getRequestLanguage()."/";
|
||||
$locationHeader = $this->toolbox->getLocationHeader($serverScheme, $serverName, $base, $location);
|
||||
$this->sendStatus($statusCode, $locationHeader);
|
||||
$this->sendStatus($statusCode, false, $locationHeader);
|
||||
} else {
|
||||
$statusCode = 404;
|
||||
$fileName = $this->readPage($serverScheme, $serverName, $base, $location, $fileName, $cacheable, $statusCode);
|
||||
$fileName = $this->readPage($serverScheme, $serverName, $base, $location, $fileName, $statusCode, $cacheable);
|
||||
}
|
||||
}
|
||||
} else if($statusCode >= 400) {
|
||||
$fileName = $this->readPage($serverScheme, $serverName, $base, $location, $fileName, $cacheable, $statusCode);
|
||||
$fileName = $this->readPage($serverScheme, $serverName, $base, $location, $fileName, $statusCode, $cacheable);
|
||||
}
|
||||
if($this->page->statusCode != 0) $statusCode = $this->sendPage();
|
||||
if(defined("DEBUG") && DEBUG>=1) echo "Yellow::processRequest handler:$handler file:$fileName<br/>\n";
|
||||
|
@ -133,14 +133,14 @@ class Yellow
|
|||
$handler = $this->getRequestHandler();
|
||||
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"));
|
||||
$this->page->fileName, $this->page->statusCode, $this->page->cacheable, $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($serverScheme, $serverName, $base, $location, $fileName, $cacheable, $statusCode, $pageError = "")
|
||||
function readPage($serverScheme, $serverName, $base, $location, $fileName, $statusCode, $cacheable, $pageError = "")
|
||||
{
|
||||
if($statusCode >= 400)
|
||||
{
|
||||
|
@ -155,7 +155,7 @@ class Yellow
|
|||
fclose($fileHandle);
|
||||
}
|
||||
$this->page = new YellowPage($this, $serverScheme, $serverName, $base, $location, $fileName);
|
||||
$this->page->parseData($fileData, $cacheable, $statusCode, $pageError);
|
||||
$this->page->parseData($fileData, $statusCode, $cacheable, $pageError);
|
||||
$this->page->setHeader("Content-Type", "text/html; charset=UTF-8");
|
||||
$this->page->setHeader("Last-Modified", $this->page->getModified(true));
|
||||
if(!$this->page->isCacheable()) $this->page->setHeader("Cache-Control", "no-cache, must-revalidate");
|
||||
|
@ -219,11 +219,12 @@ class Yellow
|
|||
}
|
||||
|
||||
// Send status response
|
||||
function sendStatus($statusCode, $responseHeader = "")
|
||||
function sendStatus($statusCode, $cacheable, $responseHeader = "")
|
||||
{
|
||||
if(PHP_SAPI != "cli")
|
||||
{
|
||||
@header($this->toolbox->getHttpStatusFormatted($statusCode));
|
||||
if(!$cacheable) @header("Cache-Control: no-cache, must-revalidate");
|
||||
if(!empty($responseHeader)) @header($responseHeader);
|
||||
} else {
|
||||
if(!empty($responseHeader))
|
||||
|
@ -258,6 +259,13 @@ class Yellow
|
|||
return array($serverScheme, $serverName, $base, $location, $fileName);
|
||||
}
|
||||
|
||||
// Return request language
|
||||
function getRequestLanguage()
|
||||
{
|
||||
$languages = $this->toolbox->findRootLanguages($this->config->get("contentDir"), $this->config->get("contentRootDir"));
|
||||
return $this->toolbox->detectBrowserLanguage($languages, $this->config->get("language"));
|
||||
}
|
||||
|
||||
// Return request handler
|
||||
function getRequestHandler()
|
||||
{
|
||||
|
@ -366,7 +374,7 @@ class YellowPage
|
|||
}
|
||||
|
||||
// Parse page data
|
||||
function parseData($rawData, $cacheable, $statusCode, $pageError = "")
|
||||
function parseData($rawData, $statusCode, $cacheable, $pageError = "")
|
||||
{
|
||||
$this->rawData = $rawData;
|
||||
$this->parserSafeMode = $this->yellow->config->get("parserSafeMode");
|
||||
|
@ -994,7 +1002,7 @@ class YellowPages
|
|||
$page = new YellowPage($this->yellow,
|
||||
$this->yellow->page->serverScheme, $this->yellow->page->serverName, $this->yellow->page->base,
|
||||
$rootLocation, "");
|
||||
$page->parseData("", false, 0);
|
||||
$page->parseData("", 0, false);
|
||||
array_push($this->pages[$location], $page);
|
||||
}
|
||||
} else {
|
||||
|
@ -1019,7 +1027,7 @@ class YellowPages
|
|||
$this->yellow->config->get("contentRootDir"), $this->yellow->config->get("contentHomeDir"),
|
||||
$this->yellow->config->get("contentDefaultFile"), $this->yellow->config->get("contentExtension")),
|
||||
$fileName);
|
||||
$page->parseData($fileData, false, $statusCode);
|
||||
$page->parseData($fileData, $statusCode, false);
|
||||
array_push($this->pages[$location], $page);
|
||||
}
|
||||
}
|
||||
|
@ -1551,6 +1559,24 @@ class YellowToolbox
|
|||
return array($pathRoot, $pathHome);
|
||||
}
|
||||
|
||||
// Return root languages
|
||||
function findRootLanguages($pathBase, $pathRoot, $includeInvisible = false)
|
||||
{
|
||||
$languages = array();
|
||||
if(!empty($pathRoot))
|
||||
{
|
||||
foreach($this->getDirectoryEntries($pathBase, "/.*/", true, true, false) as $entry)
|
||||
{
|
||||
if($includeInvisible || preg_match("/^[\d\-\_\.]+(.*)$/", $entry))
|
||||
{
|
||||
$token = $this->normaliseName($entry);
|
||||
if(strlenu($token) == 2) array_push($languages, $token);
|
||||
}
|
||||
}
|
||||
}
|
||||
return $languages;
|
||||
}
|
||||
|
||||
// Return root locations
|
||||
function findRootLocations($pathBase, $pathRoot)
|
||||
{
|
||||
|
@ -1663,7 +1689,7 @@ class YellowToolbox
|
|||
}
|
||||
} else {
|
||||
$i = 1;
|
||||
$token = rtrim($pathHome, '/');
|
||||
$token = $tokens[0] = rtrim($pathHome, '/');
|
||||
if($this->normaliseName($token) != $token) $invalid = true;
|
||||
$regex = $invalid ? "//" : "/^[\d\-\_\.]*".strreplaceu('-', '.', $token)."$/";
|
||||
foreach($this->getDirectoryEntries($path, $regex, false, true, false) as $entry)
|
||||
|
@ -2147,6 +2173,21 @@ class YellowToolbox
|
|||
return $ok;
|
||||
}
|
||||
|
||||
// Detect web browser language
|
||||
function detectBrowserLanguage($languages, $languageDefault)
|
||||
{
|
||||
$language = $languageDefault;
|
||||
if(isset($_SERVER["HTTP_ACCEPT_LANGUAGE"]))
|
||||
{
|
||||
foreach(preg_split("/,\s*/", $_SERVER["HTTP_ACCEPT_LANGUAGE"]) as $string)
|
||||
{
|
||||
$tokens = explode(';', $string);
|
||||
if(in_array($tokens[0], $languages)) { $language = $tokens[0]; break; }
|
||||
}
|
||||
}
|
||||
return $language;
|
||||
}
|
||||
|
||||
// Detect image dimensions and type, png or jpg
|
||||
function detectImageInfo($fileName)
|
||||
{
|
||||
|
|
Loading…
Add table
Reference in a new issue