page = new YellowPage($this);
$this->pages = new YellowPages($this);
$this->files = new YellowFiles($this);
$this->plugins = new YellowPlugins($this);
$this->config = new YellowConfig($this);
$this->text = new YellowText($this);
$this->lookup = new YellowLookup($this);
$this->toolbox = new YellowToolbox();
$this->config->setDefault("sitename", "Yellow");
$this->config->setDefault("author", "Yellow");
$this->config->setDefault("language", "en");
$this->config->setDefault("theme", "default");
$this->config->setDefault("serverScheme", $this->toolbox->getServerScheme());
$this->config->setDefault("serverName", $this->toolbox->getServerName());
$this->config->setDefault("serverBase", $this->toolbox->getServerBase());
$this->config->setDefault("serverTime", $this->toolbox->getServerTime());
$this->config->setDefault("imageLocation", "/media/images/");
$this->config->setDefault("pluginLocation", "/media/plugins/");
$this->config->setDefault("themeLocation", "/media/themes/");
$this->config->setDefault("systemDir", "system/");
$this->config->setDefault("configDir", "system/config/");
$this->config->setDefault("pluginDir", "system/plugins/");
$this->config->setDefault("themeDir", "system/themes/");
$this->config->setDefault("snippetDir", "system/themes/snippets/");
$this->config->setDefault("templateDir", "system/themes/templates/");
$this->config->setDefault("mediaDir", "media/");
$this->config->setDefault("imageDir", "media/images/");
$this->config->setDefault("staticDir", "cache/");
$this->config->setDefault("staticDefaultFile", "index.html");
$this->config->setDefault("staticErrorFile", "404.html");
$this->config->setDefault("contentDir", "content/");
$this->config->setDefault("contentRootDir", "default/");
$this->config->setDefault("contentHomeDir", "home/");
$this->config->setDefault("contentDefaultFile", "page.txt");
$this->config->setDefault("contentPagination", "page");
$this->config->setDefault("contentExtension", ".txt");
$this->config->setDefault("configExtension", ".ini");
$this->config->setDefault("configFile", "config.ini");
$this->config->setDefault("textFile", "language-(.*).ini");
$this->config->setDefault("errorFile", "page-error-(.*).txt");
$this->config->setDefault("robotsFile", "robots.txt");
$this->config->setDefault("iconFile", "icon.png");
$this->config->setDefault("template", "default");
$this->config->setDefault("navigation", "navigation");
$this->config->setDefault("sidebar", "sidebar");
$this->config->setDefault("parser", "markdown");
$this->config->setDefault("parserSafeMode", "0");
$this->config->setDefault("multiLanguageMode", "0");
$this->load();
}
// Initialise configuration
function load()
{
if(defined("DEBUG") && DEBUG>=3)
{
$serverSoftware = $this->toolbox->getServerSoftware();
echo "Yellow ".YellowCore::Version.", PHP ".PHP_VERSION.", $serverSoftware
\n";
}
$this->config->load($this->config->get("configDir").$this->config->get("configFile"));
$this->text->load($this->config->get("configDir").$this->config->get("textFile"));
date_default_timezone_set($this->config->get("serverTime"));
list($pathRoot, $pathHome) = $this->lookup->getContentInformation();
$this->config->set("contentRootDir", $pathRoot);
$this->config->set("contentHomeDir", $pathHome);
}
// Handle command
function command($name, $args = NULL)
{
$statusCode = 0;
if($this->plugins->isExisting($name))
{
$plugin = $this->plugins->plugins[$name];
if(method_exists($plugin["obj"], "onCommand")) $statusCode = $plugin["obj"]->onCommand(func_get_args());
} else {
$statusCode = 500;
$this->page->error($statusCode, "Plugin '$name' does not exist!");
}
return $statusCode;
}
// Handle request
function request()
{
ob_start();
$statusCode = 0;
$this->toolbox->timerStart($time);
$this->toolbox->normaliseRequest();
list($serverScheme, $serverName, $base, $location, $fileName) = $this->getRequestInformation();
$this->page->setRequestInformation($serverScheme, $serverName, $base, $location, $fileName);
foreach($this->plugins->plugins as $key=>$value)
{
if(method_exists($value["obj"], "onRequest"))
{
$this->pages->requestHandler = $key;
$statusCode = $value["obj"]->onRequest($serverScheme, $serverName, $base, $location, $fileName);
if($statusCode != 0) break;
}
}
if($statusCode == 0)
{
$this->pages->requestHandler = "core";
$statusCode = $this->processRequest($serverScheme, $serverName, $base, $location, $fileName, true);
}
if($this->page->isError()) $statusCode = $this->processRequestError();
$this->toolbox->timerStop($time);
ob_end_flush();
if(defined("DEBUG") && DEBUG>=1) echo "YellowCore::request status:$statusCode location:$location
\n";
if(defined("DEBUG") && DEBUG>=1) echo "YellowCore::request time:$time ms
\n";
return $statusCode;
}
// Process request
function processRequest($serverScheme, $serverName, $base, $location, $fileName, $cacheable)
{
$statusCode = 0;
if(is_readable($fileName))
{
if($this->toolbox->isRequestCleanUrl($location))
{
$statusCode = 303;
$location = $location.$this->getRequestLocationArgsClean();
$location = $this->lookup->normaliseUrl($serverScheme, $serverName, $base, $location);
$this->sendStatus($statusCode, $location);
}
} else {
if($this->isRequestContentDirectory($location))
{
$statusCode = 301;
$location = $this->lookup->isFileLocation($location) ? "$location/" : "/".$this->getRequestLanguage()."/";
$location = $this->lookup->normaliseUrl($serverScheme, $serverName, $base, $location);
$this->sendStatus($statusCode, $location);
}
}
if($statusCode == 0)
{
$statusCode = is_readable($fileName) ? 200 : 404;
$fileName = $this->getStaticFileFromCache($location, $fileName, $cacheable, $statusCode);
if($this->isStaticFile($fileName))
{
$statusCode = $this->sendFile($statusCode, $fileName, $cacheable);
} else {
$fileName = $this->readPage($serverScheme, $serverName, $base, $location, $fileName, $cacheable, $statusCode);
$statusCode = $this->sendPage();
}
}
if(defined("DEBUG") && DEBUG>=1)
{
$handler = $this->getRequestHandler();
echo "YellowCore::processRequest file:$fileName handler:$handler
\n";
}
return $statusCode;
}
// Process request with error
function processRequestError()
{
ob_clean();
$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"));
$statusCode = $this->sendPage();
if(defined("DEBUG") && DEBUG>=1)
{
$handler = $this->getRequestHandler();
echo "YellowCore::processRequestError file:$fileName handler:$handler
\n";
}
return $statusCode;
}
// Read page
function readPage($serverScheme, $serverName, $base, $location, $fileName, $cacheable, $statusCode, $pageError = "")
{
if($statusCode >= 400)
{
$fileName = $this->config->get("configDir").$this->config->get("errorFile");
$fileName = strreplaceu("(.*)", $statusCode, $fileName);
$cacheable = false;
}
$this->page = new YellowPage($this);
$this->page->setRequestInformation($serverScheme, $serverName, $base, $location, $fileName);
$this->page->parseData($this->toolbox->readFile($fileName), $cacheable, $statusCode, $pageError);
$this->text->setLanguage($this->page->get("language"));
$this->page->parseContent();
return $fileName;
}
// Send page response
function sendPage()
{
$this->page->parsePage();
$statusCode = $this->page->statusCode;
$lastModifiedFormatted = $this->page->getHeader("Last-Modified");
if($statusCode==200 && $this->page->isCacheable() && $this->toolbox->isRequestNotModified($lastModifiedFormatted))
{
$statusCode = 304;
@header($this->toolbox->getHttpStatusFormatted($statusCode));
} else {
@header($this->toolbox->getHttpStatusFormatted($statusCode));
foreach($this->page->headerData as $key=>$value) @header("$key: $value");
if(!is_null($this->page->outputData)) echo $this->page->outputData;
}
if(defined("DEBUG") && DEBUG>=1)
{
foreach($this->page->headerData as $key=>$value) echo "YellowCore::sendPage $key: $value
\n";
$fileNameTheme = $this->config->get("themeDir").$this->page->get("theme").".css";
$templateName = $this->page->get("template");
$parserName = $this->page->get("parser");
echo "YellowCore::sendPage theme:$fileNameTheme template:$templateName parser:$parserName
\n";
}
return $statusCode;
}
// Send file response
function sendFile($statusCode, $fileName, $cacheable)
{
$lastModifiedFormatted = $this->toolbox->getHttpDateFormatted(filemtime($fileName));
if($statusCode==200 && $cacheable && $this->toolbox->isRequestNotModified($lastModifiedFormatted))
{
$statusCode = 304;
@header($this->toolbox->getHttpStatusFormatted($statusCode));
} else {
@header($this->toolbox->getHttpStatusFormatted($statusCode));
if(!$cacheable) @header("Cache-Control: no-cache, must-revalidate");
@header("Content-Type: ".$this->toolbox->getMimeContentType($fileName));
@header("Last-Modified: ".$lastModifiedFormatted);
echo $this->toolbox->readFile($fileName);
}
return $statusCode;
}
// Send status response
function sendStatus($statusCode, $location = "")
{
if(!empty($location)) $this->page->clean($statusCode, $location);
@header($this->toolbox->getHttpStatusFormatted($statusCode));
foreach($this->page->headerData as $key=>$value) @header("$key: $value");
if(defined("DEBUG") && DEBUG>=1)
{
foreach($this->page->headerData as $key=>$value) echo "YellowCore::sendStatus $key: $value
\n";
}
}
// Parse snippet
function snippet($name, $args = NULL)
{
$this->pages->snippetArgs = func_get_args();
$this->page->parseSnippet($name);
}
// Return request information
function getRequestInformation($serverScheme = "", $serverName = "", $base = "")
{
$serverScheme = empty($serverScheme) ? $this->config->get("serverScheme") : $serverScheme;
$serverName = empty($serverName) ? $this->config->get("serverName") : $serverName;
$base = empty($base) ? $this->config->get("serverBase") : $base;
$location = $this->toolbox->getLocation();
$location = substru($location, strlenu($base));
if(preg_match("/\.(css|js|jpg|png|txt|woff)$/", $location))
{
$pluginLocationLength = strlenu($this->config->get("pluginLocation"));
$themeLocationLength = strlenu($this->config->get("themeLocation"));
if(substru($location, 0, $pluginLocationLength) == $this->config->get("pluginLocation")) {
$fileName = $this->config->get("pluginDir").substru($location, $pluginLocationLength);
} else if(substru($location, 0, $themeLocationLength) == $this->config->get("themeLocation")) {
$fileName = $this->config->get("themeDir").substru($location, $themeLocationLength);
} else if($location == "/".$this->config->get("robotsFile")) {
$fileName = $this->config->get("configDir").$this->config->get("robotsFile");
}
}
if(empty($fileName)) $fileName = $this->lookup->findFileFromLocation($location);
return array($serverScheme, $serverName, $base, $location, $fileName);
}
// Return request location
function getRequestLocationArgsClean()
{
return $this->toolbox->getLocationArgsClean($this->config->get("contentPagination"));
}
// Return request language
function getRequestLanguage()
{
return $this->toolbox->detectBrowserLanguage($this->pages->getLanguages(), $this->config->get("language"));
}
// Return request handler
function getRequestHandler()
{
return $this->pages->requestHandler;
}
// Return snippet arguments
function getSnippetArgs()
{
return $this->pages->snippetArgs;
}
// Return static file from cache if available
function getStaticFileFromCache($location, $fileName, $cacheable, $statusCode)
{
if(PHP_SAPI!="cli" && $cacheable)
{
if($statusCode == 200)
{
$location .= $this->toolbox->getLocationArgs();
$fileNameStatic = rtrim($this->config->get("staticDir"), '/').$location;
if(!$this->lookup->isFileLocation($location)) $fileNameStatic .= $this->config->get("staticDefaultFile");
} else if($statusCode == 404) {
$fileNameStatic = $this->config->get("staticDir").$this->config->get("staticErrorFile");
}
if(is_readable($fileNameStatic)) $fileName = $fileNameStatic;
}
return $fileName;
}
// Check if static file
function isStaticFile($fileName)
{
$staticDirLength = strlenu($this->config->get("staticDir"));
$systemDirLength = strlenu($this->config->get("systemDir"));
return substru($fileName, 0, $staticDirLength) == $this->config->get("staticDir") ||
substru($fileName, 0, $systemDirLength) == $this->config->get("systemDir");
}
// Check if request can be redirected into content directory
function isRequestContentDirectory($location)
{
$ok = false;
if($this->lookup->isFileLocation($location))
{
$path = $this->lookup->findFileFromLocation("$location/", true);
$ok = is_dir($path);
} else if($location=="/") {
$ok = $this->config->get("multiLanguageMode");
}
return $ok;
}
}
// Yellow page
class YellowPage
{
var $yellow; //access to API
var $serverScheme; //server scheme
var $serverName; //server name
var $base; //base location
var $location; //page location
var $fileName; //content file name
var $lastModified; //last modification date
var $rawData; //raw data of page
var $metaDataOffsetBytes; //meta data offset
var $metaData; //meta data
var $headerData; //response header
var $outputData; //response output
var $pages; //page collection
var $pageRelations; //page relations
var $parser; //content parser
var $parserData; //content data of page
var $parserSafeMode; //page is parsed in safe mode? (boolean)
var $available; //page is available? (boolean)
var $visible; //page is visible location? (boolean)
var $active; //page is active location? (boolean)
var $cacheable; //page is cacheable? (boolean)
var $statusCode; //status code
function __construct($yellow)
{
$this->yellow = $yellow;
$this->metaData = array();
$this->headerData = array();
$this->pages = new YellowPageCollection($yellow);
$this->pageRelations = array();
}
// Set request information
function setRequestInformation($serverScheme, $serverName, $base, $location, $fileName)
{
$this->serverScheme = $serverScheme;
$this->serverName = $serverName;
$this->base = $base;
$this->location = $location;
$this->fileName = $fileName;
}
// Parse page data
function parseData($rawData, $cacheable, $statusCode, $pageError = "")
{
$this->lastModified = 0;
$this->rawData = $rawData;
$this->parser = NULL;
$this->parserData = "";
$this->parserSafeMode = intval($this->yellow->config->get("parserSafeMode"));
$this->available = true;
$this->visible = $this->yellow->lookup->isVisibleLocation($this->location, $this->fileName);
$this->active = $this->yellow->lookup->isActiveLocation($this->location, $this->yellow->page->location);
$this->cacheable = $cacheable;
$this->statusCode = $statusCode;
$this->parseMeta($pageError);
}
// Parse page data update
function parseDataUpdate()
{
if($this->statusCode == 0)
{
$this->rawData = $this->yellow->toolbox->readFile($this->fileName);
$this->statusCode = 200;
$this->parseMeta();
}
}
// Parse page meta data
function parseMeta($pageError = "")
{
$this->metaData = array();
if(!is_null($this->rawData))
{
$this->set("title", $this->yellow->toolbox->createTextTitle($this->location));
$this->set("sitename", $this->yellow->config->get("sitename"));
$this->set("author", $this->yellow->config->get("author"));
$this->set("language", $this->yellow->lookup->findLanguageFromFile($this->fileName,
$this->yellow->config->get("language")));
$this->set("theme", $this->yellow->lookup->findNameFromFile($this->fileName,
$this->yellow->config->get("themeDir"), $this->yellow->config->get("theme"), ".css"));
$this->set("template", $this->yellow->lookup->findNameFromFile($this->fileName,
$this->yellow->config->get("templateDir"), $this->yellow->config->get("template"), ".html"));
$this->set("modified", date("Y-m-d H:i:s", $this->yellow->toolbox->getFileModified($this->fileName)));
$this->set("navigation", $this->yellow->config->get("navigation"));
$this->set("sidebar", $this->yellow->config->get("sidebar"));
$this->set("parser", $this->yellow->config->get("parser"));
if(preg_match("/^(\xEF\xBB\xBF)?\-\-\-[\r\n]+(.+?)[\r\n]+\-\-\-[\r\n]+/s", $this->rawData, $parts))
{
$this->metaDataOffsetBytes = strlenb($parts[0]);
foreach(preg_split("/[\r\n]+/", $parts[2]) as $line)
{
preg_match("/^\s*(.*?)\s*:\s*(.*?)\s*$/", $line, $matches);
if(!empty($matches[1]) && !strempty($matches[2])) $this->set(lcfirst($matches[1]), $matches[2]);
}
} else if(preg_match("/^(\xEF\xBB\xBF)?([^\r\n]+)[\r\n]+=+[\r\n]+/", $this->rawData, $parts)) {
$this->metaDataOffsetBytes = strlenb($parts[0]);
$this->set("title", $parts[2]);
}
$titleHeader = ($this->location == $this->yellow->pages->getHomeLocation($this->location)) ?
$this->get("sitename") : $this->get("title")." - ".$this->get("sitename");
if(!$this->isExisting("titleContent")) $this->set("titleContent", $this->get("title"));
if(!$this->isExisting("titleHeader")) $this->set("titleHeader", $titleHeader);
if(!$this->isExisting("titleNavigation")) $this->set("titleNavigation", $this->get("title"));
if($this->get("titleContent") == "-") $this->set("titleContent", "");
$this->set("pageRead", $this->yellow->lookup->normaliseUrl(
$this->yellow->config->get("serverScheme"),
$this->yellow->config->get("serverName"),
$this->yellow->config->get("serverBase"), $this->location));
$this->set("pageEdit", $this->yellow->lookup->normaliseUrl(
$this->yellow->config->get("webinterfaceServerScheme"),
$this->yellow->config->get("webinterfaceServerName"),
$this->yellow->config->get("serverBase"),
rtrim($this->yellow->config->get("webinterfaceLocation"), '/').$this->location));
$this->set("pageFile", $this->yellow->lookup->normaliseFile($this->fileName));
if($this->get("status") == "hidden") $this->available = false;
} else {
$this->set("type", $this->yellow->toolbox->getFileExtension($this->fileName));
$this->set("modified", date("Y-m-d H:i:s", $this->yellow->toolbox->getFileModified($this->fileName)));
$this->set("pageFile", $this->yellow->lookup->normaliseFile($this->fileName, true));
}
if(!empty($pageError)) $this->set("pageError", $pageError);
foreach($this->yellow->plugins->plugins as $key=>$value)
{
if(method_exists($value["obj"], "onParseMeta")) $value["obj"]->onParseMeta($this);
}
}
// Parse page content on demand
function parseContent()
{
if(!is_object($this->parser))
{
if($this->yellow->plugins->isExisting($this->get("parser")))
{
$plugin = $this->yellow->plugins->plugins[$this->get("parser")];
if(method_exists($plugin["obj"], "onParseContentRaw"))
{
$this->parser = $plugin["obj"];
$this->parserData = $this->getContent(true);
$this->parserData = preg_replace("/@pageRead/i", $this->get("pageRead"), $this->parserData);
$this->parserData = preg_replace("/@pageEdit/i", $this->get("pageEdit"), $this->parserData);
$this->parserData = preg_replace("/@pageError/i", $this->get("pageError"), $this->parserData);
$this->parserData = $this->parser->onParseContentRaw($this, $this->parserData);
foreach($this->yellow->plugins->plugins as $key=>$value)
{
if(method_exists($value["obj"], "onParseContentText"))
{
$output = $value["obj"]->onParseContentText($this, $this->parserData);
if(!is_null($output)) $this->parserData = $output;
}
}
}
} else {
$this->parserData = $this->getContent(true);
$this->parserData = preg_replace("/@pageError/i", $this->get("pageError"), $this->parserData);
}
if(!$this->isExisting("description"))
{
$this->set("description", $this->yellow->toolbox->createTextDescription($this->parserData, 150));
}
if(!$this->isExisting("keywords"))
{
$this->set("keywords", $this->yellow->toolbox->createTextKeywords($this->get("title"), 10));
}
if(defined("DEBUG") && DEBUG>=3) echo "YellowPage::parseContent location:".$this->location."
\n";
}
}
// Parse page content block
function parseContentBlock($name, $text, $shortcut)
{
$output = NULL;
foreach($this->yellow->plugins->plugins as $key=>$value)
{
if(method_exists($value["obj"], "onParseContentBlock"))
{
$output = $value["obj"]->onParseContentBlock($this, $name, $text, $shortcut);
if(!is_null($output)) break;
}
}
if(is_null($output))
{
if($name=="yellow" && $shortcut)
{
$output = "\n";
if(empty($text))
{
$serverSoftware = $this->yellow->toolbox->getServerSoftware();
$output .= "Yellow ".YellowCore::Version.", PHP ".PHP_VERSION.", $serverSoftware
\n";
foreach($this->yellow->plugins->getData() as $key=>$value)
{
$output .= htmlspecialchars("$key: $value")."
\n";
}
} else {
foreach($this->yellow->config->getData($text) as $key=>$value)
{
$output .= htmlspecialchars(ucfirst($key).": ".$value)."
\n";
}
}
if($this->parserSafeMode) $this->error(500, "Yellow information are not available in safe mode!");
$output .= "\n";
}
}
if(defined("DEBUG") && DEBUG>=3 && !empty($name)) echo "YellowPage::parseContentBlock name:$name shortcut:$shortcut
\n";
return $output;
}
// Parse page
function parsePage()
{
$this->outputData = NULL;
if(!$this->isError())
{
foreach($this->yellow->plugins->plugins as $key=>$value)
{
if(method_exists($value["obj"], "onParsePage")) $value["obj"]->onParsePage();
}
}
if(is_null($this->outputData))
{
ob_start();
$this->parseTemplate($this->get("template"));
$this->outputData = ob_get_contents();
ob_end_clean();
}
if(!$this->isCacheable()) $this->setHeader("Cache-Control", "no-cache, must-revalidate");
if(!$this->isHeader("Content-Type")) $this->setHeader("Content-Type", "text/html; charset=utf-8");
if(!$this->isHeader("Content-Modified")) $this->setHeader("Content-Modified", $this->getModified(true));
if(!$this->isHeader("Last-Modified")) $this->setHeader("Last-Modified", $this->getLastModified(true));
if(!$this->yellow->text->isLanguage($this->get("language")))
{
$this->error(500, "Language '".$this->get("language")."' does not exist!");
}
if(!is_file($this->yellow->config->get("themeDir").$this->get("theme").".css"))
{
$this->error(500, "Theme '".$this->get("theme")."' does not exist!");
}
if(!is_object($this->parser))
{
$this->error(500, "Parser '".$this->get("parser")."' does not exist!");
}
if($this->yellow->toolbox->isRequestSelf()) $this->error(500, "Rewrite module not enabled on this server!");
if($this->yellow->getRequestHandler()=="core" && $this->isExisting("redirect") && $this->statusCode==200)
{
$location = $this->yellow->lookup->normaliseLocation($this->get("redirect"), $this->base, $this->location);
$location = $this->yellow->lookup->normaliseUrl($this->serverScheme, $this->serverName, "", $location);
$this->clean(301, $location);
}
if($this->yellow->getRequestHandler()=="core" && !$this->isAvailable() && $this->statusCode==200)
{
$this->error(404);
}
if($this->isExisting("pageClean")) $this->outputData = NULL;
}
// Parse template
function parseTemplate($name)
{
$fileNameTemplate = $this->yellow->config->get("templateDir").$this->yellow->lookup->normaliseName($name).".html";
if(is_file($fileNameTemplate))
{
$this->setLastModified(filemtime($fileNameTemplate));
global $yellow;
require($fileNameTemplate);
} else {
$this->error(500, "Template '$name' does not exist!");
echo "Template error
\n";
}
}
// Parse snippet
function parseSnippet($name)
{
$fileNameSnippet = $this->yellow->config->get("snippetDir").$this->yellow->lookup->normaliseName($name).".php";
if(is_file($fileNameSnippet))
{
$this->setLastModified(filemtime($fileNameSnippet));
global $yellow;
require($fileNameSnippet);
} else {
$this->error(500, "Snippet '$name' does not exist!");
echo "Snippet error
\n";
}
}
// Set page meta data
function set($key, $value)
{
$this->metaData[$key] = $value;
}
// Return page meta data
function get($key)
{
return $this->isExisting($key) ? $this->metaData[$key] : "";
}
// Return page meta data, HTML encoded
function getHtml($key)
{
return htmlspecialchars($this->get($key));
}
// Return page meta data as language specific date
function getDate($key, $dateFormat = "")
{
if(!empty($dateFormat))
{
$format = $this->yellow->text->get($dateFormat);
} else {
$format = $this->yellow->text->get("dateFormatMedium");
}
return $this->yellow->text->getDateFormatted(strtotime($this->get($key)), $format);
}
// Return page content, HTML encoded or raw format
function getContent($rawFormat = false)
{
if($rawFormat)
{
$this->parseDataUpdate();
$text = substrb($this->rawData, $this->metaDataOffsetBytes);
} else {
$this->parseContent();
$text = $this->parserData;
}
return $text;
}
// Return parent page relative to current page, NULL if none
function getParent()
{
$parentLocation = $this->yellow->pages->getParentLocation($this->location);
return $this->yellow->pages->find($parentLocation);
}
// Return top-level page for current page, NULL if none
function getParentTop($homeFailback = true)
{
$parentTopLocation = $this->yellow->pages->getParentTopLocation($this->location);
if(!$this->yellow->pages->find($parentTopLocation) && $homeFailback)
{
$parentTopLocation = $this->yellow->pages->getHomeLocation($this->location);
}
return $this->yellow->pages->find($parentTopLocation);
}
// Return page collection with pages on the same level as current page
function getSiblings($showInvisible = false)
{
$parentLocation = $this->yellow->pages->getParentLocation($this->location);
return $this->yellow->pages->getChildren($parentLocation, $showInvisible);
}
// Return page collection with child pages relative to current page
function getChildren($showInvisible = false)
{
return $this->yellow->pages->getChildren($this->location, $showInvisible);
}
// Return page collection with media files for current page
function getFiles($showInvisible = false)
{
return $this->yellow->files->index($showInvisible, true)->filter("pageFile", $this->get("pageFile"));
}
// Set page collection with additional pages for current page
function setPages($pages)
{
$this->pages = $pages;
}
// Return page collection with additional pages for current page
function getPages()
{
return $this->pages;
}
// Set related page
function setPage($key, $page)
{
$this->pageRelations[$key] = $page;
}
// Return related page
function getPage($key)
{
return !is_null($this->pageRelations[$key]) ? $this->pageRelations[$key] : $this;
}
// Return absolute page location
function getLocation()
{
return $this->base.$this->location;
}
// Return page URL with server scheme and server name
function getUrl()
{
return $this->yellow->lookup->normaliseUrl($this->serverScheme, $this->serverName, $this->base, $this->location);
}
// Return page extra HTML data
function getExtra($name)
{
$output = "";
foreach($this->yellow->plugins->plugins as $key=>$value)
{
if(method_exists($value["obj"], "onExtra"))
{
$outputPlugin = $value["obj"]->onExtra($name);
if(!is_null($outputPlugin)) $output .= $outputPlugin;
}
}
if($name == "header")
{
if(is_file($this->yellow->config->get("themeDir").$this->get("theme").".css"))
{
$location = $this->yellow->config->get("serverBase").
$this->yellow->config->get("themeLocation").$this->get("theme").".css";
$output .= "\n";
}
if(is_file($this->yellow->config->get("themeDir").$this->get("theme").".js"))
{
$location = $this->yellow->config->get("serverBase").
$this->yellow->config->get("themeLocation").$this->get("theme").".js";
$output .= "\n";
}
if(is_file($this->yellow->config->get("imageDir").$this->yellow->config->get("iconFile")))
{
$location = $this->yellow->config->get("serverBase").
$this->yellow->config->get("imageLocation").$this->yellow->config->get("iconFile");
$contentType = $this->yellow->toolbox->getMimeContentType($this->yellow->config->get("iconFile"));
$output .= "\n";
}
}
return $this->normaliseExtra($output);
}
// Normalise page extra HTML data
function normaliseExtra($text)
{
$outputScript = $outputStylesheet = $outputOther = $locations = array();
foreach($this->yellow->toolbox->getTextLines($text) as $line)
{
if(preg_match("/^