mikuli.cz

:)
git clone https://git.sr.ht/~ashymad/mikuli.cz
Log | Files | Refs

commit 5561965291932f3574410b348001fc1685390374
parent f30d5ceec53b28739cb8729c2424e31145113abb
Author: markseu <mark2011@mayberg.se>
Date:   Sun, 19 Oct 2014 21:22:47 +0200

Core update (time for refactoring)

Diffstat:
MREADME.md | 2+-
Msystem/config/config.ini | 2--
Msystem/core/core-webinterface.js | 6+++---
Msystem/core/core-webinterface.php | 8+++-----
Msystem/core/core.php | 125+++++++++++++++++++++++++++++++------------------------------------------------
5 files changed, 56 insertions(+), 87 deletions(-)

diff --git a/README.md b/README.md @@ -1,4 +1,4 @@ -Yellow 0.4.5 +Yellow 0.4.6 ============ Yellow is for people who make websites. [Visit website](http://datenstrom.se/yellow). diff --git a/system/config/config.ini b/system/config/config.ini @@ -38,8 +38,6 @@ webinterfaceServerScheme = http webinterfaceUserHashAlgorithm = bcrypt webinterfaceUserHashCost = 10 webinterfaceUserFile = user.ini -webinterfaceEmail = -webinterfacePassword = webinterfaceNewPage = default webinterfaceFilePrefix = published commandlineDefaultFile = index.html 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.4.1", + version: "0.4.2", 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)); }, @@ -112,8 +112,8 @@ yellow.webinterface = "<h1>"+this.getText("LoginText")+"</h1>"+ "<form method=\"post\">"+ "<input type=\"hidden\" name=\"action\" value=\"login\" />"+ - "<p><label for=\"email\">"+this.getText("LoginEmail")+"</label> <input name=\"email\" id=\"email\" maxlength=\"64\" value=\""+yellow.config.webinterfaceEmail+"\" /></p>"+ - "<p><label for=\"password\">"+this.getText("LoginPassword")+"</label> <input type=\"password\" name=\"password\" id=\"password\" maxlength=\"64\" value=\""+yellow.config.webinterfacePassword+"\" /></p>"+ + "<p><label for=\"email\">"+this.getText("LoginEmail")+"</label> <input name=\"email\" id=\"email\" maxlength=\"64\" value=\""+yellow.config.loginEmail+"\" /></p>"+ + "<p><label for=\"password\">"+this.getText("LoginPassword")+"</label> <input type=\"password\" name=\"password\" id=\"password\" maxlength=\"64\" value=\""+yellow.config.loginPassword+"\" /></p>"+ "<p><input class=\"yellow-btn\" type=\"submit\" value=\""+this.getText("LoginButton")+"\" /></p>"+ "</form>"; } else if(paneId == "yellow-pane-edit") { 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.4.2"; + const Version = "0.4.3"; var $yellow; //access to API var $users; //web interface users var $active; //web interface is active? (boolean) @@ -24,8 +24,6 @@ class YellowWebinterface $this->yellow->config->setDefault("webinterfaceUserHashAlgorithm", "bcrypt"); $this->yellow->config->setDefault("webinterfaceUserHashCost", "10"); $this->yellow->config->setDefault("webinterfaceUserFile", "user.ini"); - $this->yellow->config->setDefault("webinterfaceEmail", ""); - $this->yellow->config->setDefault("webinterfacePassword", ""); $this->yellow->config->setDefault("webinterfaceNewPage", "default"); $this->yellow->config->setDefault("webinterfaceFilePrefix", "published"); $this->users = new YellowWebinterfaceUsers($yellow); @@ -527,8 +525,8 @@ class YellowWebinterface $data["serverName"] = $this->yellow->config->get("serverName"); $data["serverBase"] = $this->yellow->config->get("serverBase"); } else { - $data["webinterfaceEmail"] = $this->yellow->config->get("webinterfaceEmail"); - $data["webinterfacePassword"] = $this->yellow->config->get("webinterfacePassword"); + $data["loginEmail"] = $this->yellow->config->get("loginEmail"); + $data["loginPassword"] = $this->yellow->config->get("loginPassword"); } return $data; } diff --git a/system/core/core.php b/system/core/core.php @@ -5,7 +5,7 @@ // Yellow main class class Yellow { - const Version = "0.4.5"; + const Version = "0.4.6"; var $page; //current page var $pages; //pages from file system var $config; //configuration @@ -1632,99 +1632,49 @@ class YellowToolbox function findFileFromLocation($location, $pathBase, $pathRoot, $pathHome, $fileDefault, $fileExtension) { $path = $pathBase; + $tokens = explode('/', $location); if($this->isRootLocation($location)) { if(!empty($pathRoot)) { - $token = rtrim(substru($location, 5), '/'); - if(empty($token)) $token = rtrim($pathRoot, '/'); - if($this->normaliseName($token) != $token) $invalid = true; - $regex = $invalid ? "//" : "/^[\d\-\_\.]*".strreplaceu('-', '.', $token)."$/"; - foreach($this->getDirectoryEntries($path, $regex, false, true, false) as $entry) - { - if($this->normaliseName($entry) == $token) { $token = $entry; break; } - } - $path .= "$token/"; + $token = (count($tokens) > 2) ? $tokens[1] : rtrim($pathRoot, '/'); + $path .= $this->findFileDirectory($path, $token, true, true, $found, $invalid); } } else { - $tokens = explode('/', $location); if(!empty($pathRoot)) { if(count($tokens) > 2) { - $root = $tokens[1]; - if($this->normaliseName($root) == $this->normaliseName($pathRoot)) $invalid = true; - if($this->normaliseName($root) != $root) $invalid = true; - $regex = $invalid ? "//" : "/^[\d\-\_\.]*".strreplaceu('-', '.', $root)."$/"; - foreach($this->getDirectoryEntries($path, $regex, false, true, false) as $entry) - { - if($this->normaliseName($entry) == $root) { $token = $entry; array_shift($tokens); break; } - } - } - if(empty($token)) - { - $token = rtrim($pathRoot, '/'); - if($this->normaliseName($token) != $token) $invalid = true; - $regex = $invalid ? "//" : "/^[\d\-\_\.]*".strreplaceu('-', '.', $token)."$/"; - foreach($this->getDirectoryEntries($path, $regex, false, true, false) as $entry) - { - if($this->normaliseName($entry) == $token) { $token = $entry; break; } - } + if($this->normaliseName($tokens[1]) == $this->normaliseName($pathRoot)) $invalid = true; + $path .= $this->findFileDirectory($path, $tokens[1], false, true, $found, $invalid); + if($found) array_shift($tokens); } - $path .= "$token/"; + if(!$found) $path .= $this->findFileDirectory($path, rtrim($pathRoot, '/'), true, true, $found, $invalid); + } if(count($tokens) > 2) { if($this->normaliseName($tokens[1]) == $this->normaliseName($pathHome)) $invalid = true; for($i=1; $i<count($tokens)-1; ++$i) { - $token = $tokens[$i]; - if($this->normaliseName($token) != $token) $invalid = true; - $regex = $invalid ? "//" : "/^[\d\-\_\.]*".strreplaceu('-', '.', $token)."$/"; - foreach($this->getDirectoryEntries($path, $regex, false, true, false) as $entry) - { - if($this->normaliseName($entry) == $token) { $token = $entry; break; } - } - $path .= "$token/"; + $path .= $this->findFileDirectory($path, $tokens[$i], true, true, $found, $invalid); } } else { $i = 1; - $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) - { - if($this->normaliseName($entry) == $token) { $token = $entry; break; } - } - $path .= "$token/"; + $tokens[0] = rtrim($pathHome, '/'); + $path .= $this->findFileDirectory($path, $tokens[0], true, true, $found, $invalid); } if(!empty($fileDefault) && !empty($fileExtension)) { + $fileFolder = $tokens[$i-1].$fileExtension; if(!empty($tokens[$i])) { $token = $tokens[$i].$fileExtension; - $fileFolder = $tokens[$i-1].$fileExtension; if($token==$fileDefault || $token==$fileFolder) $invalid = true; - if($this->normaliseName($token) != $token) $invalid = true; - $regex = $invalid ? "//" : "/^[\d\-\_\.]*".strreplaceu('-', '.', $token)."$/"; - foreach($this->getDirectoryEntries($path, $regex, false, false, false) as $entry) - { - if($this->normaliseName($entry) == $token) { $token = $entry; break; } - } + $path .= $this->findFileDirectory($path, $token, true, false, $found, $invalid); } else { - $token = $fileDefault; - if(!is_file($path."/".$fileDefault)) - { - $fileFolder = $tokens[$i-1].$fileExtension; - $regex = "/^[\d\-\_\.]*($fileDefault|$fileFolder)$/"; - foreach($this->getDirectoryEntries($path, $regex, true, false, false) as $entry) - { - if($this->normaliseName($entry) == $fileDefault) { $token = $entry; break; } - if($this->normaliseName($entry) == $fileFolder) { $token = $entry; break; } - } - } + $path .= $this->findFileDefault($path, $fileDefault, $fileFolder); } - $path .= $token; if(defined("DEBUG") && DEBUG>=2) { $debug = "$location -> ".($invalid ? "INVALID" : $path); @@ -1734,6 +1684,38 @@ class YellowToolbox } return $invalid ? "" : $path; } + + // Return file or directory that matches token + function findFileDirectory($path, $token, $tokenFailback, $directory, &$found, &$invalid) + { + if($this->normaliseName($token) != $token) $invalid = true; + if(!$invalid) + { + $regex = "/^[\d\-\_\.]*".strreplaceu('-', '.', $token)."$/"; + foreach($this->getDirectoryEntries($path, $regex, false, $directory, false) as $entry) + { + if($this->normaliseName($entry) == $token) { $token = $entry; $found = true; break; } + } + } + if($directory) $token .= '/'; + return ($tokenFailback || $found) ? $token : ""; + } + + // Return default file in directory + function findFileDefault($path, $fileDefault, $fileFolder) + { + $token = $fileDefault; + if(!is_file($path."/".$fileDefault)) + { + $regex = "/^[\d\-\_\.]*($fileDefault|$fileFolder)$/"; + foreach($this->getDirectoryEntries($path, $regex, true, false, false) as $entry) + { + if($this->normaliseName($entry) == $fileDefault) { $token = $entry; break; } + if($this->normaliseName($entry) == $fileFolder) { $token = $entry; break; } + } + } + return $token; + } // Return children from location function findChildrenFromLocation($location, $pathBase, $pathRoot, $pathHome, $fileDefault, $fileExtension) @@ -1744,17 +1726,8 @@ class YellowToolbox $path = $this->findFileFromLocation($location, $pathBase, $pathRoot, $pathHome, "", ""); foreach($this->getDirectoryEntries($path, "/.*/", true, true, false) as $entry) { - $token = $fileDefault; - if(!is_file($path.$entry."/".$fileDefault)) - { - $fileFolder = $this->normaliseName($entry).$fileExtension; - $regex = "/^[\d\-\_\.]*($fileDefault|$fileFolder)$/"; - foreach($this->getDirectoryEntries($path.$entry, $regex, true, false, false) as $entry2) - { - if($this->normaliseName($entry2) == $fileDefault) { $token = $entry2; break; } - if($this->normaliseName($entry2) == $fileFolder) { $token = $entry2; break; } - } - } + $fileFolder = $this->normaliseName($entry).$fileExtension; + $token = $this->findFileDefault($path.$entry, $fileDefault, $fileFolder); array_push($fileNames, $path.$entry."/".$token); } if(!$this->isRootLocation($location))