Core update (configuration summer remix)

This commit is contained in:
markseu 2014-05-31 23:48:59 +02:00
parent 836c75f31e
commit 352d232b8f
4 changed files with 38 additions and 19 deletions

View file

@ -0,0 +1,4 @@
---
Title: New page
---
Write text here

View file

@ -13,7 +13,5 @@ webinterfaceSaveButton = Save
webinterfaceCancelButton = Cancel
webinterfaceEdit = Edit
webinterfaceUserLogout = Logout
webinterface424Title = New page
webinterface424Text = Write text here
paginationPrevious = ← Previous
paginationNext = Next →

View file

@ -5,7 +5,7 @@
// Web interface core plugin
class YellowWebinterface
{
const Version = "0.2.10";
const Version = "0.2.11";
var $yellow; //access to API
var $users; //web interface users
var $active; //web interface is active? (boolean)
@ -16,6 +16,7 @@ class YellowWebinterface
function onLoad($yellow)
{
$this->yellow = $yellow;
$this->yellow->config->setDefault("webinterfacePage", "default");
$this->yellow->config->setDefault("webinterfaceLocation", "/edit/");
$this->yellow->config->setDefault("webinterfaceUserFile", "user.ini");
$this->yellow->config->setDefault("webinterfaceUserHome", "/");
@ -74,13 +75,7 @@ class YellowWebinterface
{
switch($page->statusCode)
{
case 424: $language = $this->isUser() ? $this->users->getLanguage() : $page->get("language");
$page->rawData = "---\r\n";
$page->rawData .= "Title: ".$this->yellow->text->getText("webinterface424Title", $language)."\r\n";
$page->rawData .= "Author: ".$this->users->getName()."\r\n";
$page->rawData .= "---\r\n";
$page->rawData .= $this->yellow->text->getText("webinterface424Text", $language);
break;
case 424: $page->rawData = $this->getPageData(); break;
case 500: $page->rawData = $this->rawDataOriginal; break;
}
}
@ -296,6 +291,25 @@ class YellowWebinterface
return $this->yellow->getRequestInformation($serverScheme, $serverName, $base);
}
// Return content data for new page
function getPageData()
{
$fileData = "";
$fileName = $this->yellow->toolbox->findFileFromLocation($this->yellow->page->location,
$this->yellow->config->get("contentDir"), $this->yellow->config->get("contentHomeDir"),
$this->yellow->config->get("contentDefaultFile"), $this->yellow->config->get("contentExtension"));
$fileName = $this->yellow->toolbox->findNameFromFile($fileName,
$this->yellow->config->get("configDir"), $this->yellow->config->get("webinterfacePage"),
$this->yellow->config->get("contentExtension"), true);
$fileHandle = @fopen($fileName, "r");
if($fileHandle)
{
$fileData = fread($fileHandle, filesize($fileName));
fclose($fileHandle);
}
return $fileData;
}
// Return configuration data including information of current user
function getConfigData()
{

View file

@ -5,7 +5,7 @@
// Yellow main class
class Yellow
{
const Version = "0.2.21";
const Version = "0.2.22";
var $page; //current page
var $pages; //pages from file system
var $config; //configuration
@ -384,9 +384,10 @@ class YellowPage
$this->set("sitename", $this->yellow->config->get("sitename"));
$this->set("author", $this->yellow->config->get("author"));
$this->set("language", $this->yellow->config->get("language"));
$this->set("template", $this->yellow->toolbox->findTemplateFromFile($this->fileName,
$this->yellow->config->get("templateDir"), $this->yellow->config->get("template")));
$this->set("style", $this->yellow->config->get("style"));
$this->set("template", $this->yellow->toolbox->findNameFromFile($this->fileName,
$this->yellow->config->get("templateDir"), $this->yellow->config->get("template"), ".php"));
$this->set("style", $this->yellow->toolbox->findNameFromFile($this->fileName,
$this->yellow->config->get("styleDir"), $this->yellow->config->get("style"), ".css"));
$this->set("parser", $this->yellow->config->get("parser"));
if(preg_match("/^(\-\-\-[\r\n]+)(.+?)([\r\n]+\-\-\-[\r\n]+)/s", $this->rawData, $parsed))
@ -1521,14 +1522,16 @@ class YellowToolbox
return $fileNames;
}
// Return template from file path
function findTemplateFromFile($fileName, $templateDir, $templateDefault)
// Return file/template/style name from file path
function findNameFromFile($fileName, $pathBase, $nameDefault, $fileExtension, $includeFileName = false)
{
if(preg_match("/^.*\/(.+?)$/", dirname($fileName), $matches)) $templateFolder = $this->normaliseName($matches[1]);
return is_file("$templateDir$templateFolder.php") ? $templateFolder : $templateDefault;
$name = "";
if(preg_match("/^.*\/(.+?)$/", dirname($fileName), $matches)) $name = $this->normaliseName($matches[1]);
if(!is_file("$pathBase$name$fileExtension")) $name = $this->normaliseName($nameDefault);
return $includeFileName ? "$pathBase$name$fileExtension" : $name;
}
// Normalise directory/file/attribute name
// Normalise file/directory/attribute name
function normaliseName($text, $removeExtension = false, $filterStrict = false)
{
if(preg_match("/^[\d\-\_\.]+(.*)$/", $text, $matches)) $text = $matches[1];