Code cleanup (gingerbread remix)

This commit is contained in:
markseu 2013-12-11 15:13:38 +01:00
parent f0b35969fa
commit 115839bcf1
4 changed files with 42 additions and 30 deletions

View file

@ -1,4 +1,4 @@
---
Title: Page does not exist
---
You can [create this page](javascript:yellow.onShow('yellow-paneedit');).
You can [create this page](javascript:yellow.onShow('yellow-pane-edit');).

View file

@ -5,7 +5,7 @@
// Markdown extra parser core plugin
class YellowMarkdownExtra
{
const Version = "0.2.1";
const Version = "0.2.2";
var $yellow; //access to API
var $textHtml; //generated text (HTML format)
@ -92,9 +92,12 @@ class YellowMarkdownExtraParser extends MarkdownExtra_Parser
// Handle inline images
function _doImages_inline_callback($matches)
{
$path = $matches[3]=="" ? $matches[4] : $matches[3];
$src = $this->yellow->config->get("serverBase").$this->yellow->config->get("imageLocation").$path;
list($width, $height) = $this->yellow->toolbox->detectImageDimensions($this->yellow->config->get("imageDir").$path);
$src = $matches[3]=="" ? $matches[4] : $matches[3];
if(!preg_match("/^\w+:/", $src))
{
list($width, $height) = $this->yellow->toolbox->detectImageDimensions($this->yellow->config->get("imageDir").$src);
$src = $this->yellow->config->get("serverBase").$this->yellow->config->get("imageLocation").$src;
}
$alt = $matches[2];
$title = $matches[7];
$attr = $this->doExtraAttributes("img", $dummy =& $matches[8]);

View file

@ -5,7 +5,7 @@
// Web interface core plugin
class YellowWebinterface
{
const Version = "0.2.2";
const Version = "0.2.3";
var $yellow; //access to API
var $users; //web interface users
var $activeLocation; //web interface location? (boolean)
@ -58,15 +58,15 @@ class YellowWebinterface
"<a$1href=\"$serverBase/$webinterfaceLocation/$2\"$3>", $text);
if($page == $this->yellow->page)
{
if(empty($this->rawDataOriginal)) $this->rawDataOriginal = $page->rawData;
switch($page->statusCode)
{
case 200: $this->rawDataOriginal = $page->rawData; break;
case 424: $language = $this->isUser() ? $this->users->getLanguage($this->activeUserEmail) : $page->get("language");
$page->rawData = "---\r\n";
$page->rawData .= "Title: ".$this->yellow->text->getLanguageText($language, "webinterface424Title")."\r\n";
$page->rawData .= "Title: ".$this->yellow->text->getText("webinterface424Title", $language)."\r\n";
$page->rawData .= "Author: ".$this->users->getName($this->activeUserEmail)."\r\n";
$page->rawData .= "---\r\n";
$page->rawData .= $this->yellow->text->getLanguageText($language, "webinterface424Text");
$page->rawData .= $this->yellow->text->getText("webinterface424Text", $language);
break;
case 500: $page->rawData = $this->rawDataOriginal; break;
}
@ -93,7 +93,7 @@ class YellowWebinterface
$header .= "yellow.pages = ".json_encode($this->getPagesData()).";\n";
$header .= "yellow.config = ".json_encode($this->getConfigData($this->activeUserEmail)).";\n";
}
$header .= "yellow.text = ".json_encode($this->yellow->text->getData($language, "webinterface")).";\n";
$header .= "yellow.text = ".json_encode($this->yellow->text->getData("webinterface", $language)).";\n";
if(defined("DEBUG")) $header .= "yellow.debug = ".json_encode(DEBUG).";\n";
$header .= "// ]]>\n";
$header .= "</script>\n";

View file

@ -5,7 +5,7 @@
// Yellow main class
class Yellow
{
const Version = "0.2.1";
const Version = "0.2.2";
var $page; //current page data
var $pages; //current page tree from file system
var $config; //configuration
@ -154,11 +154,11 @@ class Yellow
$this->pages->serverBase = $serverBase;
$this->page = new YellowPage($this, $location);
$this->page->parseData($fileName, $fileData, $cacheable, $statusCode, $pageError);
$this->page->parseContent();
$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");
$this->text->setLanguage($this->page->get("language"));
$this->page->parseContent();
return $fileName;
}
@ -240,7 +240,7 @@ class Yellow
return $this->page->isExisting("pageError");
}
// Execute a template
// Execute template
function template($name)
{
$fileNameTemplate = $this->config->get("templateDir")."$name.php";
@ -253,7 +253,7 @@ class Yellow
}
}
// Execute a template snippet
// Execute code snippet
function snippet($name, $args = NULL)
{
$this->pages->snippetArgs = func_get_args();
@ -267,7 +267,7 @@ class Yellow
}
}
// Return template snippet arguments
// Return snippet arguments
function getSnippetArgs()
{
return $this->pages->snippetArgs;
@ -307,7 +307,7 @@ class Yellow
$this->config->get("contentDir"), $this->config->get("contentHomeDir"), "", "");
}
// Execute a plugin command
// Execute plugin command
function plugin($name, $args = NULL)
{
$statusCode = 0;
@ -328,11 +328,10 @@ class Yellow
$this->plugins->register($name, $class, $version);
}
// Set a response header
// Add page response header, OBSOLETE DON'T USE
function header($responseHeader)
{
$tokens = explode(':', $responseHeader, 2);
$this->page->setHeader(trim($tokens[0]), trim($tokens[1]));
$this->page->header($responseHeader);
}
}
@ -406,9 +405,10 @@ class YellowPage
$titleHeader = $this->location!="/" ? $this->get("title")." - ".$this->get("sitename") : $this->get("sitename");
if(!$this->isExisting("titleHeader")) $this->set("titleHeader", $titleHeader);
if(!$this->isExisting("titleNavigation")) $this->set("titleNavigation", $this->get("title"));
$this->set("pageRead", $this->yellow->config->get("serverBase").$this->location);
$this->set("pageEdit", $this->yellow->config->get("serverBase").
rtrim($this->yellow->config->get("webinterfaceLocation"), '/').$this->location);
$this->set("pageRead", $this->yellow->toolbox->getHttpUrl($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->yellow->config->get("serverBase"), rtrim($this->yellow->config->get("webinterfaceLocation"), '/').$this->location));
foreach($this->yellow->plugins->plugins as $key=>$value)
{
if(method_exists($value["obj"], "onParseMeta"))
@ -483,6 +483,7 @@ class YellowPage
if(!is_null($output)) break;
}
}
if(defined("DEBUG") && DEBUG>=2 && !empty($name)) echo "YellowPage::parseType name:$name shortcut:$typeShortcut<br/>\n";
return $output;
}
@ -503,11 +504,18 @@ class YellowPage
{
$this->statusCode = $statusCode;
$this->headerData = array();
if(!empty($responseHeader)) $this->yellow->header($responseHeader);
if(!empty($responseHeader)) $this->header($responseHeader);
$this->set("pageClean", (string)$statusCode);
}
}
// Add page response header, HTTP format
function header($responseHeader)
{
$tokens = explode(':', $responseHeader, 2);
$this->setHeader(trim($tokens[0]), trim($tokens[1]));
}
// Set page response header
function setHeader($key, $value)
{
@ -1098,7 +1106,7 @@ class YellowText
preg_match("/^\s*(.*?)\s*=\s*(.*?)\s*$/", $line, $matches);
if(!empty($language) && !empty($matches[1]) && !strempty($matches[2]))
{
$this->setLanguageText($language, $matches[1], $matches[2]);
$this->setText($matches[1], $matches[2], $language);
if(defined("DEBUG") && DEBUG>=3) echo "YellowText::load key:$matches[1] $matches[2]<br/>\n";
}
}
@ -1113,16 +1121,16 @@ class YellowText
}
// Set text string for specific language
function setLanguageText($language, $key, $value)
function setText($key, $value, $language)
{
if(is_null($this->text[$language])) $this->text[$language] = array();
$this->text[$language][$key] = $value;
}
// Return text string for specific language
function getLanguageText($language, $key)
function getText($key, $language)
{
return ($this->isLanguageText($language, $key)) ? $this->text[$language][$key] : "[$key]";
return ($this->isText($key, $language)) ? $this->text[$language][$key] : "[$key]";
}
// Return text string
@ -1137,10 +1145,11 @@ class YellowText
return htmlspecialchars($this->get($key));
}
// Return text strings for specific language
function getData($language, $filterStart = "")
// Return text strings
function getData($filterStart = "", $language = "")
{
$text = array();
if(empty($language)) $language = $this->language;
if(!is_null($this->text[$language]))
{
if(empty($filterStart))
@ -1164,7 +1173,7 @@ class YellowText
}
// Check if text string for specific language exists
function isLanguageText($language, $key)
function isText($key, $language)
{
return !is_null($this->text[$language]) && !is_null($this->text[$language][$key]);
}