<?php
// Load configuration
require_once('config.php');
$config = Config::instance();
$webRoot = $config->webRoot();
$docRoot = $config->documentRoot();
// Import classes
ClassFactory::importClass('PageServer');
ClassFactory::importClass('Redirect');
ClassFactory::importClass('FileBrowser');
try {
// Must be before session_start() !!!
FileBrowser::handleRequest();
}
catch (Exception $e) {
// Bad URL?
// Redirect to parrent level
header('Content-type: text/html', true, 404);
$page = PageServer::isPageValid(@$_GET['page'])?$_GET[page]:'';
Redirect::redirect($webRoot.'/'.$page, LangSelect::singleton()->getLang());
}
// Select page language
LangSelect::singleton()->handleLangSelect();
$page='index';
$bNotFound=false;
try {
if (isset($_GET['page']))
$page = ereg_replace('/$', '', $_GET['page']);
$nestedPage = ereg_replace('/$', '', @$_GET['nestedPage']);
$pageServer = new PageServer($page, $nestedPage);
}
catch (ExceptionRedirect $e) {
// Nested page requested by user not found.
header('Content-type: text/html', true, 404);
Redirect::redirect($webRoot.'/'.$page, LangSelect::singleton()->getLang());
}
catch (ExceptionNotFound $e) {
header('Content-type: text/html', true, 404);
$bNotFound = true;
}
// Localization (common for all pages)
$l10n = new L10n;
$l10n->setTranslation('cz', 'Documentation', 'Dokumentace');
$l10n->setTranslation('cz', 'Download', 'Stáhnout');
$l10n->setTranslation('cz', 'Gallery', 'Galerie');
$l10n->setTranslation('cz', 'Preview', 'Ukázka');
$l10n->setTranslation('cz', 'Source code', 'Zdrojový kód');
$l10n->setTranslation('cz', 'Source files', 'Zdrojové soubory');
$l10n->setTranslation('cz', 'templates', 'šablony');
$l10n->setTranslation('cz', 'Tested browsers', 'Testované prohlížeče');
$l10n->setTranslation('cz', 'Tutorial', 'Tutoriál');
$l10n->setTranslation('cz', 'View', 'Zobrazit');
$pageTitle = '';
if ($bNotFound) {
$page = 'index';
$pageTitle = ('cz'==LangSelect::singleton()->getLang())?
'Stránka nenalezena':
'Page not found';
} else {
require($pageServer->titleInitScript());
}
// Import classes
ClassFactory::importClass('SmartyFactory');
ClassFactory::importClass('QuickMenu');
ClassFactory::importClass('PageTransform');
// Send page head
$smarty = SmartyFactory::createSmarty();
if ($page!='index' || $bNotFound) {
$smarty->assign('page', $page);
$smarty->assign('pageTitle', $pageTitle.FileBrowser::titlePostfix());
}
$smarty->assign('lang', LangSelect::singleton()->getLang());
$smarty->display('pageInit.tpl'); echo "\n";
// EXPERIMENTAL
$pageTitle = ereg_replace('(\([^\)]+\))', '<em>\1</em>', $pageTitle);
$smarty->assign('pageTitle', $pageTitle);
// Initialize QuickMenu class
$qm = new QuickMenu();
// $qm->setVisibleDepth(2);
$qm->genHead();
// Load file browser JavaScript
FileBrowser::genHeadIfNeeded();
// Move to page body
JSOnloadList::instance()->generate();
$smarty->display('pageBodyInit.tpl'); echo "\n";
// Generate QuickMenu template
$menuCache = $docRoot.$config->cacheDir().'/QmTemplate.xml';
PageTransform::buildIfNeeded($menuCache, 'QmTemplateBuilder.xsl');
$qm->loadXmlTemplate($menuCache);
// Render QuickMenu
Indentor::singleton()->enter();
$qm->setActiveItemHREF($page);
$qm->genMenu();
if ($bNotFound)
$smarty->display('pageNotFound.tpl');
else if (FileBrowser::requested())
FileBrowser::showContent($page, $pageTitle);
else
mainPage($pageServer, $nestedPage, $pageTitle, $l10n);
// Send page end
$smarty->display('pageEnd.tpl'); echo "\n";
/**
* Display MainPage of selected page
* @param pageServer Instace of initialized PageServer object.
* @param pageTitle Desired page title.
*/
function mainPage($pageServer, $nestedPage, $pageTitle, $l10n) {
// Load configuration
$config = Config::instance();
// ...
// Execute page-content script
require($pageServer->pageContentScript());
}
/**
* Generate image thumbnail as external link to full size of the same image.
* Puts nothing to output, just return XHTML code as string.
* @param name Image name - @b ralative @b path
* @param size Thumbnail (maximum) size. Size must be supported by FileBrowser component.
* @return Return generated XHTML code as string.
*/
function imageThumbnail($name, $size=320) {
$link = Config::instance()->webRoot().'/'.$name;
$title = ('cz'== LangSelect::singleton()->getLang())?
'Kliknutím zvětšíte obrázek':
'Click to enlarge image';
return '<a href="javascript:void window.open(\''.$link.'?action=fullImage\');" title="'.$title.'"><img src="'.$link.'?action=thumbnail'.$size.'" alt="'.$name.'"/></a>';
}
/**
* Generate XHTML code for local image. Just image, no links.
* Puts nothing to output, just return XHTML code as string.
* @param name Image name - @b ralative @b path
* @param alt XHTML img element's alt attribute. Default is image's name.
* @return Return generated XHTML code as string.
*/
function image($name, $alt=null) {
if (!isset($alt))
$alt = $name;
$link = Config::instance()->webRoot().'/'.$name;
return '<img src="'.$link.'?action=fullImage" alt="'.$alt.'"/>';
}
/**
* Generate XHTML code for internal link.
* Puts nothing to output, just return XHTML code as string.
* @param relHref HREF relative to web root.
* @param text Link's visible text. This string can also contain XHTML elements.
* @param title Link's title. Voluntary parameter.
* @return Return generated XHTML code as string.
*/
function intLink($relHref, $text, $title=null) {
$webRoot = Config::instance()->webRoot();
$szTitle = '';
if (isset($title))
$szTitle = " title='$title'";
return "<a href='$webRoot/$relHref'$szTitle>$text</a>";
}
/**
* Generate XHTML code for external link. Link will be opened in @b new @b window.
* Puts nothing to output, just return XHTML code as string.
* @param absHref Absolute HREF. Should be valid in global scope.
* @param text Link's visible text. This string can also contain XHTML elements.
* @param title Link's title. Voluntary parameter.
* @return Return generated XHTML code as string.
*/
function extLink($absHref, $text, $title=null) {
$szTitle = '';
if (isset($title))
$szTitle = " title='$title'";
return "<a href=\"javascript:void window.open('$absHref');\"$szTitle>$text</a>";
}
/**
* Generate XHTML code for 32x32 image link.
* @remarks
* - \<div|span class='imgLink32'\>
* - \<a href="..."\>
* - \<img src="..." .../\>
* - text
* Puts nothing to output, just return XHTML code as string.
* @param absHref Absolute HREF. Should be valid in global scope.
* @param text Link's visible text. This string can also contain XHTML elements.
* @param img Image file name. Image must be in imgDir directory.
* @param bInline If true, inline element (span) will be generated.
* If false, block element (div) will be generated (default).
* @return Return generated XHTML code as string.
*/
function imgLink32($absHref, $text, $img, $bInline=false) {
$element = ($bInline)?
'span':
'div';
$config = Config::instance();
$webRoot = $config->webRoot();
$imgSrc = $webRoot.$config->imgDir().'/'.$img;
$imgAlt = ereg_replace('\..*$', '', $img);
return
"<$element class=\"imgLink32\">".
"<a href=\"$absHref\"><img src=\"$imgSrc\" alt=\"$imgAlt\"/>$text</a>".
"</$element>";
}
/**
* Convert relative href to absolute. (Just add webRoot as prefix)
* @param relHref HREF relative to web root.
* @return Return absolute HREF.
*/
function relToAbsHref($relHref) {
return Config::instance()->webRoot()."/$relHref";
}
/**
* Convert internal link to external. External link will be opened in new window.
* @param absHref Absolute HREF. Should be valid in global scope.
* @return Return generated external link.
*/
function absToExtHref($absHref) {
return "javascript: void window.open('$absHref');";
}
function highlightCode($code, $lang) {
// Import GeSHi
require_once(
Config::instance()->documentRoot().
Config::instance()->geshiDir().
'/geshi.php');
$geshi = new GeSHi($code, $lang);
return '<div class="SourceCodeNoScroll">'.$geshi->parse_code()."</div>\n";
}
?>