commit ee86a6fcb40a48453a6a1be4994f477706ff3b9c
parent 6282d1574156f2395d3f51f63c53ebb5ffe8c1ad
Author: markseu <mark2011@mayberg.se>
Date: Wed, 13 Aug 2014 16:36:13 +0200
Hello web interface (rename a page if you want)
Diffstat:
5 files changed, 83 insertions(+), 41 deletions(-)
diff --git a/system/config/config.ini b/system/config/config.ini
@@ -36,6 +36,7 @@ webinterfaceUserHashAlgorithm = bcrypt
webinterfaceUserHashCost = 10
webinterfaceUserFile = user.ini
webinterfaceNewPage = default
+webinterfaceFilePrefix = published
commandlineDefaultFile = index.html
commandlineErrorFile = error404.html
commandlineSystemFile = .htaccess, system/config/robots.txt
diff --git a/system/core/core-markdownextra.php b/system/core/core-markdownextra.php
@@ -5,7 +5,7 @@
// Markdown extra core plugin
class YellowMarkdownExtra
{
- const Version = "0.3.6";
+ const Version = "0.3.7";
var $yellow; //access to API
// Handle plugin initialisation
@@ -54,7 +54,7 @@ class YellowMarkdownExtraParser extends MarkdownExtraParser
// Return unique id attribute
function getIdAttribute($text)
{
- $text = $this->yellow->toolbox->normaliseName($text, false, true);
+ $text = $this->yellow->toolbox->normaliseName($text, true, false, true);
$text = trim(preg_replace("/-+/", "-", $text), "-");
if(is_null($this->idAttributes[$text]))
{
diff --git a/system/core/core-webinterface.js b/system/core/core-webinterface.js
@@ -4,7 +4,7 @@
// Yellow main API
var yellow =
{
- version: "0.3.3",
+ version: "0.3.4",
action: function(text) { yellow.webinterface.action(text); },
onClick: function(e) { yellow.webinterface.hidePanesOnClick(yellow.toolbox.getEventElement(e)); },
onKeydown: function(e) { yellow.webinterface.hidePanesOnKeydown(yellow.toolbox.getEventKeycode(e)); },
@@ -57,7 +57,6 @@ yellow.webinterface =
// Execute action
action: function(text)
{
- // edit and new should be like two panes
switch(text)
{
case "edit": this.togglePane("yellow-pane-edit", "edit"); break;
diff --git a/system/core/core-webinterface.php b/system/core/core-webinterface.php
@@ -5,7 +5,7 @@
// Web interface core plugin
class YellowWebinterface
{
- const Version = "0.3.3";
+ const Version = "0.3.4";
var $yellow; //access to API
var $users; //web interface users
var $active; //web interface is active? (boolean)
@@ -25,6 +25,7 @@ class YellowWebinterface
$this->yellow->config->setDefault("webinterfaceUserHashCost", "10");
$this->yellow->config->setDefault("webinterfaceUserFile", "user.ini");
$this->yellow->config->setDefault("webinterfaceNewPage", "default");
+ $this->yellow->config->setDefault("webinterfaceFilePrefix", "published");
$this->users = new YellowWebinterfaceUsers($yellow);
$this->users->load($this->yellow->config->get("configDir").$this->yellow->config->get("webinterfaceUserFile"));
}
@@ -211,19 +212,26 @@ class YellowWebinterface
function processRequestCreate($serverScheme, $serverName, $base, $location, $fileName)
{
$statusCode = 0;
- $page = $this->getPageNew($serverScheme, $serverName, $base, $location, $fileName, stripcslashes($_POST["rawdataedit"]));
- if($this->userPermission && $this->getUserPermission($page->location, $page->fileName) && !empty($page->rawData))
+ if($this->userPermission && !empty($_POST["rawdataedit"]))
{
$this->rawDataSource = $this->rawDataEdit = stripcslashes($_POST["rawdatasource"]);
- if(is_file($page->fileName) || $this->yellow->toolbox->createFile($page->fileName, $page->rawData))
+ $page = $this->getPageNew($serverScheme, $serverName, $base, $location, $fileName, stripcslashes($_POST["rawdataedit"]));
+ if(!$page->isError())
{
- $statusCode = 303;
- $locationHeader = $this->yellow->toolbox->getLocationHeader($serverScheme, $serverName, $base, $page->location);
- $this->yellow->sendStatus($statusCode, $locationHeader);
+ if($this->yellow->toolbox->createFile($page->fileName, $page->rawData))
+ {
+ $statusCode = 303;
+ $locationHeader = $this->yellow->toolbox->getLocationHeader($serverScheme, $serverName, $base, $page->location);
+ $this->yellow->sendStatus($statusCode, $locationHeader);
+ } else {
+ $statusCode = 500;
+ $this->yellow->processRequest($serverScheme, $serverName, $base, $location, $fileName, false, $statusCode);
+ $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->page->error($statusCode, "Can't write file '$page->fileName'!");
+ $this->yellow->page->error($statusCode, $page->get("pageError"));
}
}
return $statusCode;
@@ -237,23 +245,24 @@ class YellowWebinterface
{
$this->rawDataSource = stripcslashes($_POST["rawdatasource"]);
$this->rawDataEdit = stripcslashes($_POST["rawdataedit"]);
- $fileData = $this->mergeText($location, $this->rawDataSource, $this->rawDataEdit, $fileName);
- if(!empty($fileData))
+ $page = $this->getPageUpdate($serverScheme, $serverName, $base, $location, $fileName, $this->rawDataSource, $this->rawDataEdit);
+ if(!$page->isError())
{
- if($this->yellow->toolbox->createFile($fileName, $fileData))
+ if($this->yellow->toolbox->renameFile($fileName, $page->fileName) &&
+ $this->yellow->toolbox->createFile($page->fileName, $page->rawData))
{
$statusCode = 303;
- $locationHeader = $this->yellow->toolbox->getLocationHeader($serverScheme, $serverName, $base, $location);
+ $locationHeader = $this->yellow->toolbox->getLocationHeader($serverScheme, $serverName, $base, $page->location);
$this->yellow->sendStatus($statusCode, $locationHeader);
} else {
$statusCode = 500;
$this->yellow->processRequest($serverScheme, $serverName, $base, $location, $fileName, false, $statusCode);
- $this->yellow->page->error($statusCode, "Can't write file '$fileName'!");
+ $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->page->error($statusCode, "Page has been modified by someone else!");
+ $this->yellow->page->error($statusCode, $page->get("pageError"));
}
}
return $statusCode;
@@ -420,32 +429,61 @@ class YellowWebinterface
{
$page = new YellowPage($this->yellow, $serverScheme, $serverName, $base, $location, $fileName);
$page->parseData($rawData, false, 0);
- $page->fileName = $this->yellow->toolbox->findFileFromTitle($page->get("title"), $fileName,
+ $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"));
$page->location = $this->yellow->toolbox->findLocationFromFile($page->fileName,
$this->yellow->config->get("contentDir"), $this->yellow->config->get("contentHomeDir"),
$this->yellow->config->get("contentDefaultFile"), $this->yellow->config->get("contentExtension"));
if($this->yellow->pages->find($page->location))
{
- if(preg_match("/^(.*?)(\d+)$/", $page->get("title"), $matches))
+ preg_match("/^(.*?)(\d*)$/", $page->get("title"), $matches);
+ $titleText = $matches[1];
+ $titleNumber = $matches[2];
+ if(strempty($titleNumber)) { $titleNumber = 2; $titleText = $titleText.' '; }
+ for(; $titleNumber<=999; ++$titleNumber)
{
- $pageTitle = $matches[1];
- $pageNumber = max(2, $matches[2]);
- } else {
- $pageTitle = $page->get("title").' ';
- $pageNumber = 2;
+ $page->rawData = $this->updateDataTitle($rawData, $titleText.$titleNumber);
+ $page->fileName = $this->yellow->toolbox->findFileFromTitle(
+ $page->get($this->yellow->config->get("webinterfaceFilePrefix")), $titleText.$titleNumber, $fileName,
+ $this->yellow->config->get("contentDefaultFile"), $this->yellow->config->get("contentExtension"));
+ $page->location = $this->yellow->toolbox->findLocationFromFile($page->fileName,
+ $this->yellow->config->get("contentDir"), $this->yellow->config->get("contentHomeDir"),
+ $this->yellow->config->get("contentDefaultFile"), $this->yellow->config->get("contentExtension"));
+ if(!$this->yellow->pages->find($page->location)) { $ok = true; break; }
}
- for(; $pageNumber<=999; ++$pageNumber)
+ if(!$ok) $page->error(500, "Page '".$page->get("title")."' can not be created!");
+ }
+ if(!$this->getUserPermission($page->location, $page->fileName)) $page->error(500, "Page '".$page->get("title")."' is not allowed!");
+ return $page;
+ }
+
+ // Return modified page
+ 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);
+ 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);
+ $prefix = $this->yellow->config->get("webinterfaceFilePrefix");
+ if($pageSource->get($prefix)!=$page->get($prefix) || $pageSource->get("title")!=$page->get("title"))
{
- $page->rawData = $this->updateDataTitle($rawData, $pageTitle.$pageNumber);
- $page->fileName = $this->yellow->toolbox->findFileFromTitle($pageTitle.$pageNumber, $fileName,
+ $page->fileName = $this->yellow->toolbox->findFileFromTitle(
+ $page->get($prefix), $page->get("title"), $fileName,
$this->yellow->config->get("contentDefaultFile"), $this->yellow->config->get("contentExtension"));
$page->location = $this->yellow->toolbox->findLocationFromFile($page->fileName,
- $this->yellow->config->get("contentDir"), $this->yellow->config->get("contentHomeDir"),
- $this->yellow->config->get("contentDefaultFile"), $this->yellow->config->get("contentExtension"));
- if(!$this->yellow->pages->find($page->location)) break;
+ $this->yellow->config->get("contentDir"), $this->yellow->config->get("contentHomeDir"),
+ $this->yellow->config->get("contentDefaultFile"), $this->yellow->config->get("contentExtension"));
+ if($pageSource->location!=$page->location && $this->yellow->pages->find($page->location))
+ {
+ $page->error(500, "Page '".$page->get("title")."' already exists!");
+ }
}
}
+ if(!$this->getUserPermission($page->location, $page->fileName)) $page->error(500, "Page '".$page->get("title")."' is not allowed!");
return $page;
}
diff --git a/system/core/core.php b/system/core/core.php
@@ -5,7 +5,7 @@
// Yellow main class
class Yellow
{
- const Version = "0.3.11";
+ const Version = "0.3.12";
var $page; //current page
var $pages; //pages from file system
var $config; //configuration
@@ -193,7 +193,7 @@ class Yellow
if($statusCode==200 && !$this->toolbox->isValidContentType($contentType, $this->page->getLocation()))
{
$statusCode = 500;
- $this->page->error($statusCode, "Type '$contentType' does not match name!");
+ $this->page->error($statusCode, "Type '$contentType' does not match file name!");
}
if($this->page->isExisting("pageClean")) ob_clean();
if(PHP_SAPI != "cli")
@@ -1417,7 +1417,7 @@ class YellowToolbox
}
$token = $this->normaliseName($tokens[$i]);
$fileFolder = $this->normaliseName($tokens[$i-1]).$fileExtension;
- if($token!=$fileDefault && $token!=$fileFolder) $location .= $this->normaliseName($tokens[$i], true);
+ if($token!=$fileDefault && $token!=$fileFolder) $location .= $this->normaliseName($tokens[$i], true, true);
return $location;
}
@@ -1512,7 +1512,7 @@ class YellowToolbox
{
if($this->normaliseName($entry) == $fileDefault) continue;
if($this->normaliseName($entry) == $fileFolder) continue;
- if($this->normaliseName($entry, true) == "") continue;
+ if($this->normaliseName($entry, true, true) == "") continue;
array_push($fileNames, $path.$entry);
}
}
@@ -1530,11 +1530,15 @@ class YellowToolbox
}
// Return file path from title
- function findFileFromTitle($title, $fileName, $fileDefault, $fileExtension)
+ function findFileFromTitle($titlePrefix, $titleText, $fileName, $fileDefault, $fileExtension)
{
- $token = $this->normaliseName($title, false, true);
- $path = dirname($fileName)."/".(empty($token) ? $fileDefault : $token.$fileExtension);
- return $path;
+ preg_match("/^([\d\-\_\.]*)(.*)$/", $titlePrefix, $matches);
+ if(preg_match("/\d$/", $matches[1])) $matches[1] .= '-';
+ $titleText = $this->normaliseName($titleText, false, false, true);
+ preg_match("/^([\d\-\_\.]*)(.*)$/", $matches[1].$titleText, $matches);
+ $fileNamePrefix = $matches[1];
+ $fileNameText = empty($matches[2]) ? $fileDefault : $matches[2].$fileExtension;
+ return dirname($fileName)."/".$fileNamePrefix.$fileNameText;
}
// Normalise location arguments
@@ -1563,10 +1567,10 @@ class YellowToolbox
}
// Normalise file/directory/other name
- function normaliseName($text, $removeExtension = false, $filterStrict = false)
+ function normaliseName($text, $removePrefix = true, $removeExtension = false, $filterStrict = false)
{
if($removeExtension) $text = ($pos = strrposu($text, '.')) ? substru($text, 0, $pos) : $text;
- if(preg_match("/^[\d\-\_\.]+(.*)$/", $text, $matches)) $text = $matches[1];
+ if($removePrefix) if(preg_match("/^[\d\-\_\.]+(.*)$/", $text, $matches)) $text = $matches[1];
if($filterStrict) $text = strreplaceu('.', '-', strtoloweru($text));
return preg_replace("/[^\pL\d\-\_\.]/u", "-", $text);
}