2010-03-04 05:39:02 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
2010-04-11 09:25:26 +02:00
|
|
|
* Documentation Viewer.
|
2010-03-04 05:39:02 +01:00
|
|
|
*
|
2010-06-24 16:22:41 +02:00
|
|
|
* Reads the bundled markdown files from documentation folders and displays the output (either
|
|
|
|
* via markdown or plain text)
|
|
|
|
*
|
|
|
|
* For more documentation on how to use this class see the documentation in /sapphiredocs/docs folder
|
|
|
|
*
|
|
|
|
* To view the documentation in the browser use:
|
|
|
|
*
|
|
|
|
* http://yoursite.com/dev/docs/ Which is locked to ADMIN only
|
|
|
|
*
|
|
|
|
* @todo - Add ability to have docs on the front end as the main site.
|
|
|
|
* - Fix Language Selector (enabling it troubles the handleRequest when submitting)
|
|
|
|
* - SS_HTTPRequest when we ask for 10 params it gives us 10. Could be 10 blank ones.
|
|
|
|
* It would mean I could save alot of code if it only gave back an array of size X
|
|
|
|
* up to a maximum of 10...
|
2010-03-04 05:39:02 +01:00
|
|
|
*
|
|
|
|
* @package sapphiredocs
|
|
|
|
*/
|
|
|
|
|
|
|
|
class DocumentationViewer extends Controller {
|
2010-06-24 16:22:41 +02:00
|
|
|
|
|
|
|
static $allowed_actions = array(
|
|
|
|
'LanguageForm',
|
|
|
|
'doLanguageForm',
|
|
|
|
'handleRequest',
|
|
|
|
'fr', // better way of handling this?
|
|
|
|
'en'
|
|
|
|
);
|
2010-03-04 05:39:02 +01:00
|
|
|
|
2010-06-24 16:22:41 +02:00
|
|
|
static $casting = array(
|
|
|
|
'Version' => 'Text',
|
|
|
|
'Lang' => 'Text',
|
|
|
|
'Module' => 'Text',
|
|
|
|
'LanguageTitle' => 'Text'
|
2010-08-01 06:46:32 +02:00
|
|
|
);
|
2010-03-04 05:39:02 +01:00
|
|
|
|
2010-06-24 16:22:41 +02:00
|
|
|
function init() {
|
|
|
|
parent::init();
|
|
|
|
|
|
|
|
$canAccess = (Director::isDev() || Director::is_cli() || Permission::check("ADMIN"));
|
2010-04-11 09:25:26 +02:00
|
|
|
|
2010-06-24 16:22:41 +02:00
|
|
|
if(!$canAccess) return Security::permissionFailure($this);
|
2010-04-11 09:25:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-06-24 16:22:41 +02:00
|
|
|
* Handle the url parsing for the documentation. In order to make this
|
|
|
|
* user friendly this does some tricky things..
|
2010-04-11 09:25:26 +02:00
|
|
|
*
|
2010-06-24 16:22:41 +02:00
|
|
|
* The urls which should work
|
|
|
|
* / - index page
|
|
|
|
* /en/sapphire - the index page of sapphire (shows versions)
|
|
|
|
* /2.4/en/sapphire - the docs for 2.4 sapphire.
|
|
|
|
* /2.4/en/sapphire/installation/
|
|
|
|
*
|
|
|
|
* @return SS_HTTPResponse
|
2010-04-11 09:25:26 +02:00
|
|
|
*/
|
2010-06-24 16:22:41 +02:00
|
|
|
public function handleRequest(SS_HTTPRequest $request) {
|
|
|
|
|
2010-08-01 06:46:32 +02:00
|
|
|
$this->Version = $request->shift();
|
|
|
|
$this->Lang = $request->shift();
|
|
|
|
$this->ModuleName = $request->shift();
|
2010-06-24 16:22:41 +02:00
|
|
|
$this->Remaining = $request->shift(10);
|
|
|
|
|
|
|
|
DocumentationService::load_automatic_registration();
|
|
|
|
|
|
|
|
if(isset($this->Version)) {
|
|
|
|
// check to see if its a valid version. If its not a float then its not actually a version
|
|
|
|
// its actually a language and it needs to change. So this means we support 2 structures
|
|
|
|
// /2.4/en/sapphire/page and
|
|
|
|
// /en/sapphire/page which is a link to the latest one
|
2010-03-04 05:39:02 +01:00
|
|
|
|
2010-06-24 16:22:41 +02:00
|
|
|
if(!is_numeric($this->Version)) {
|
2010-08-01 06:46:32 +02:00
|
|
|
array_unshift($this->Remaining, $this->ModuleName);
|
|
|
|
|
2010-06-24 16:22:41 +02:00
|
|
|
// not numeric so /en/sapphire/folder/page
|
|
|
|
if(isset($this->Lang) && $this->Lang)
|
2010-08-01 06:46:32 +02:00
|
|
|
$this->ModuleName = $this->Lang;
|
2010-06-24 16:22:41 +02:00
|
|
|
|
|
|
|
$this->Lang = $this->Version;
|
|
|
|
$this->Version = null;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// if(!DocumentationService::is_registered_version($this->Version)) {
|
|
|
|
// $this->httpError(404, 'The requested version could not be found.');
|
|
|
|
// }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(isset($this->Lang)) {
|
|
|
|
// check to see if its a valid language
|
|
|
|
// if(!DocumentationService::is_registered_language($this->Lang)) {
|
|
|
|
// $this->httpError(404, 'The requested language could not be found.');
|
|
|
|
// }
|
2010-04-11 09:25:26 +02:00
|
|
|
}
|
|
|
|
else {
|
2010-06-24 16:22:41 +02:00
|
|
|
$this->Lang = 'en';
|
2010-04-11 09:25:26 +02:00
|
|
|
}
|
2010-03-04 05:39:02 +01:00
|
|
|
|
2010-06-24 16:22:41 +02:00
|
|
|
return parent::handleRequest($request);
|
2010-04-11 09:25:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-06-24 16:22:41 +02:00
|
|
|
* Custom templates for each of the sections.
|
2010-04-11 09:25:26 +02:00
|
|
|
*/
|
2010-06-24 16:22:41 +02:00
|
|
|
function getViewer($action) {
|
|
|
|
// count the number of parameters after the language, version are taken
|
|
|
|
// into account. This automatically includes ' ' so all the counts
|
|
|
|
// are 1 more than what you would expect
|
2010-08-01 06:46:32 +02:00
|
|
|
if($this->ModuleName || $this->Remaining) {
|
2010-06-24 16:22:41 +02:00
|
|
|
|
2010-06-26 06:49:20 +02:00
|
|
|
$paramCount = count($this->Remaining);
|
|
|
|
|
2010-08-01 06:46:32 +02:00
|
|
|
if($paramCount == 0) {
|
2010-06-26 06:49:20 +02:00
|
|
|
return parent::getViewer('folder');
|
|
|
|
}
|
|
|
|
else if($module = $this->getModule()) {
|
|
|
|
$params = $this->Remaining;
|
|
|
|
|
|
|
|
$path = implode('/', array_unique($params));
|
|
|
|
|
|
|
|
if(is_dir($module->getPath() . $path)) return parent::getViewer('folder');
|
2010-03-04 05:39:02 +01:00
|
|
|
}
|
|
|
|
}
|
2010-06-26 06:49:20 +02:00
|
|
|
else {
|
|
|
|
return parent::getViewer('home');
|
|
|
|
}
|
2010-06-24 16:22:41 +02:00
|
|
|
|
|
|
|
return parent::getViewer($action);
|
2010-03-04 05:39:02 +01:00
|
|
|
}
|
2010-03-04 05:59:00 +01:00
|
|
|
|
2010-03-04 05:39:02 +01:00
|
|
|
/**
|
2010-06-24 16:22:41 +02:00
|
|
|
* Return all the available languages. Optionally the languages which are
|
|
|
|
* available for a given module
|
2010-03-04 05:39:02 +01:00
|
|
|
*
|
2010-06-24 16:22:41 +02:00
|
|
|
* @param String - The name of the module
|
2010-04-11 09:25:26 +02:00
|
|
|
* @return DataObjectSet
|
2010-03-04 05:39:02 +01:00
|
|
|
*/
|
2010-06-24 16:22:41 +02:00
|
|
|
function getLanguages($module = false) {
|
|
|
|
$output = new DataObjectSet();
|
2010-03-04 05:39:02 +01:00
|
|
|
|
2010-06-24 16:22:41 +02:00
|
|
|
if($module) {
|
|
|
|
// lookup the module for the available languages
|
|
|
|
|
|
|
|
// @todo
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$languages = DocumentationService::get_registered_languages();
|
|
|
|
|
|
|
|
if($languages) {
|
|
|
|
foreach($languages as $key => $lang) {
|
|
|
|
|
|
|
|
if(stripos($_SERVER['REQUEST_URI'], '/'. $this->Lang .'/') === false) {
|
|
|
|
// no language is in the URL currently. It needs to insert the language
|
|
|
|
// into the url like /sapphire/install to /en/sapphire/install
|
|
|
|
//
|
|
|
|
// @todo
|
|
|
|
}
|
|
|
|
|
|
|
|
$link = str_ireplace('/'.$this->Lang .'/', '/'. $lang .'/', $_SERVER['REQUEST_URI']);
|
|
|
|
|
|
|
|
$output->push(new ArrayData(array(
|
|
|
|
'Title' => $lang,
|
|
|
|
'Link' => $link
|
|
|
|
)));
|
|
|
|
}
|
2010-04-11 09:25:26 +02:00
|
|
|
}
|
2010-03-04 05:39:02 +01:00
|
|
|
}
|
2010-06-24 16:22:41 +02:00
|
|
|
|
|
|
|
return $output;
|
2010-03-04 05:39:02 +01:00
|
|
|
}
|
2010-06-24 16:22:41 +02:00
|
|
|
|
2010-03-04 11:18:02 +01:00
|
|
|
/**
|
2010-06-24 16:22:41 +02:00
|
|
|
* Get all the versions loaded into the module. If the project is only displaying from
|
|
|
|
* the filesystem then they are loaded under the 'Current' namespace.
|
|
|
|
*
|
|
|
|
* @todo Only show 'core' versions (2.3, 2.4) versions of the modules are going
|
|
|
|
* to spam this
|
2010-04-11 09:25:26 +02:00
|
|
|
*
|
2010-06-24 16:22:41 +02:00
|
|
|
* @param String $module name of module to limit it to eg sapphire
|
2010-04-11 09:25:26 +02:00
|
|
|
* @return DataObjectSet
|
2010-03-04 11:18:02 +01:00
|
|
|
*/
|
2010-06-24 16:22:41 +02:00
|
|
|
function getVersions($module = false) {
|
|
|
|
$versions = DocumentationService::get_registered_versions($module);
|
|
|
|
$output = new DataObjectSet();
|
2010-03-04 11:18:02 +01:00
|
|
|
|
2010-06-24 16:22:41 +02:00
|
|
|
foreach($versions as $key => $version) {
|
|
|
|
// work out the link to this version of the documentation.
|
|
|
|
//
|
|
|
|
// @todo Keep the user on their given page rather than redirecting to module.
|
|
|
|
// @todo Get links working
|
|
|
|
$linkingMode = ($this->Version == $version) ? 'current' : 'link';
|
|
|
|
|
|
|
|
if(!$version) $version = 'Current';
|
|
|
|
$major = (in_array($version, DocumentationService::get_major_versions())) ? true : false;
|
|
|
|
|
|
|
|
$output->push(new ArrayData(array(
|
|
|
|
'Title' => $version,
|
|
|
|
'Link' => $_SERVER['REQUEST_URI'],
|
|
|
|
'LinkingMode' => $linkingMode,
|
|
|
|
'MajorRelease' => $major
|
|
|
|
)));
|
2010-03-04 11:18:02 +01:00
|
|
|
}
|
2010-04-11 09:25:26 +02:00
|
|
|
|
2010-06-24 16:22:41 +02:00
|
|
|
return $output;
|
2010-03-04 11:18:02 +01:00
|
|
|
}
|
|
|
|
|
2010-04-11 09:25:26 +02:00
|
|
|
/**
|
2010-06-24 16:22:41 +02:00
|
|
|
* Generate the module which are to be documented. It filters
|
|
|
|
* the list based on the current head version. It displays the contents
|
|
|
|
* from the index.md file on the page to use.
|
2010-04-11 09:25:26 +02:00
|
|
|
*
|
2010-06-24 16:22:41 +02:00
|
|
|
* @return DataObject
|
|
|
|
*/
|
|
|
|
function getModules($version = false, $lang = false) {
|
|
|
|
if(!$version) $version = $this->Version;
|
|
|
|
if(!$lang) $lang = $this->Lang;
|
|
|
|
|
|
|
|
$modules = DocumentationService::get_registered_modules($version, $lang);
|
|
|
|
$output = new DataObjectSet();
|
2010-06-26 06:49:20 +02:00
|
|
|
|
2010-06-24 16:22:41 +02:00
|
|
|
if($modules) {
|
|
|
|
foreach($modules as $module) {
|
2010-08-01 06:46:32 +02:00
|
|
|
$filepath = $module->getPath() . '/index.md';
|
|
|
|
if(file_exists($filepath)) {
|
|
|
|
$page = new DocumentationPage(
|
|
|
|
$filepath,
|
|
|
|
$module,
|
|
|
|
$this->Lang,
|
|
|
|
$this->Version
|
|
|
|
);
|
|
|
|
$content = DocumentationParser::parse($page, $this->Link(array_slice($this->Remaining, -1, -1)));
|
|
|
|
} else {
|
|
|
|
$content = '';
|
|
|
|
}
|
|
|
|
|
2010-06-24 16:22:41 +02:00
|
|
|
// build the dataset. Load the $Content from an index.md
|
|
|
|
$output->push(new ArrayData(array(
|
|
|
|
'Title' => $module->getTitle(),
|
|
|
|
'Code' => $module,
|
2010-08-01 06:46:32 +02:00
|
|
|
'Content' => $content
|
2010-06-24 16:22:41 +02:00
|
|
|
)));
|
|
|
|
}
|
|
|
|
}
|
2010-06-26 06:49:20 +02:00
|
|
|
|
2010-06-24 16:22:41 +02:00
|
|
|
return $output;
|
2010-03-04 11:18:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-06-24 16:22:41 +02:00
|
|
|
* Get the currently accessed entity from the site.
|
2010-03-04 11:18:02 +01:00
|
|
|
*
|
2010-06-24 16:22:41 +02:00
|
|
|
* @return false|DocumentationEntity
|
2010-03-04 11:18:02 +01:00
|
|
|
*/
|
2010-06-24 16:22:41 +02:00
|
|
|
function getModule() {
|
2010-08-01 06:46:32 +02:00
|
|
|
if($this->ModuleName) {
|
|
|
|
return DocumentationService::is_registered_module($this->ModuleName, $this->Version, $this->Lang);
|
2010-03-04 11:18:02 +01:00
|
|
|
}
|
2010-06-24 16:22:41 +02:00
|
|
|
|
2010-03-04 11:18:02 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-08-01 06:46:32 +02:00
|
|
|
/**
|
|
|
|
* @return DocumentationPage
|
|
|
|
*/
|
|
|
|
function getPage() {
|
|
|
|
$module = $this->getModule();
|
|
|
|
if(!$module) return false;
|
|
|
|
|
|
|
|
$absFilepath = DocumentationParser::find_page($module->getPath(), $this->Remaining);
|
|
|
|
if($absFilepath) {
|
|
|
|
$relativeFilePath = str_replace($module->getPath(), '', $absFilepath);
|
|
|
|
return new DocumentationPage(
|
|
|
|
$relativeFilePath,
|
|
|
|
$module,
|
|
|
|
$this->Lang,
|
|
|
|
$this->Version
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-04 05:39:02 +01:00
|
|
|
/**
|
2010-06-24 16:22:41 +02:00
|
|
|
* Get the related pages to this module and the children to those pages
|
2010-03-04 05:39:02 +01:00
|
|
|
*
|
2010-06-24 16:22:41 +02:00
|
|
|
* @todo this only handles 2 levels. Could make it recursive
|
2010-03-04 05:39:02 +01:00
|
|
|
*
|
2010-06-24 16:22:41 +02:00
|
|
|
* @return false|DataObjectSet
|
2010-03-04 05:39:02 +01:00
|
|
|
*/
|
2010-06-24 16:22:41 +02:00
|
|
|
function getModulePages() {
|
|
|
|
if($module = $this->getModule()) {
|
|
|
|
$pages = DocumentationParser::get_pages_from_folder($module->getPath());
|
|
|
|
|
|
|
|
if($pages) {
|
|
|
|
foreach($pages as $page) {
|
2010-08-01 06:46:32 +02:00
|
|
|
$linkParts = array();
|
2010-06-24 16:22:41 +02:00
|
|
|
|
|
|
|
// don't include the 'index in the url
|
|
|
|
if($page->Title != "Index") $linkParts[] = $page->Filename;
|
2010-03-26 03:50:30 +01:00
|
|
|
|
2010-06-24 16:22:41 +02:00
|
|
|
$page->Link = $this->Link($linkParts);
|
|
|
|
|
|
|
|
$page->LinkingMode = 'link';
|
|
|
|
$page->Children = false;
|
|
|
|
|
2010-08-01 06:46:32 +02:00
|
|
|
if(isset($this->Remaining[0])) {
|
|
|
|
if(strtolower($this->Remaining[0]) == $page->Filename) {
|
2010-06-24 16:22:41 +02:00
|
|
|
$page->LinkingMode = 'current';
|
|
|
|
|
|
|
|
if(is_dir($page->Path)) {
|
|
|
|
$children = DocumentationParser::get_pages_from_folder($page->Path);
|
2010-08-01 06:46:32 +02:00
|
|
|
foreach($children as $child) {
|
|
|
|
$child->Link = $this->Link(array($this->Remaining[0], $child->Filename));
|
2010-06-24 16:22:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$page->Children = $children;
|
|
|
|
}
|
|
|
|
}
|
2010-03-04 05:39:02 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-06-24 16:22:41 +02:00
|
|
|
|
|
|
|
return $pages;
|
2010-03-04 05:39:02 +01:00
|
|
|
}
|
2010-06-24 16:22:41 +02:00
|
|
|
|
2010-03-04 05:39:02 +01:00
|
|
|
return false;
|
|
|
|
}
|
2010-08-01 06:46:32 +02:00
|
|
|
|
2010-03-04 05:39:02 +01:00
|
|
|
/**
|
2010-06-24 16:22:41 +02:00
|
|
|
* Return the content for the page. If its an actual documentation page then
|
|
|
|
* display the content from the page, otherwise display the contents from
|
|
|
|
* the index.md file if its a folder
|
2010-03-04 05:39:02 +01:00
|
|
|
*
|
2010-06-24 16:22:41 +02:00
|
|
|
* @return HTMLText
|
2010-03-04 05:39:02 +01:00
|
|
|
*/
|
2010-06-24 16:22:41 +02:00
|
|
|
function getContent() {
|
2010-08-01 06:46:32 +02:00
|
|
|
if($page = $this->getPage()) {
|
|
|
|
// Remove last portion of path (filename), we want a link to the folder base
|
|
|
|
return DocumentationParser::parse($page, $this->Link(array_slice($this->Remaining, -1, -1)));
|
2010-06-24 16:22:41 +02:00
|
|
|
}
|
2010-04-11 09:25:26 +02:00
|
|
|
|
2010-06-24 16:22:41 +02:00
|
|
|
return false;
|
2010-03-04 05:39:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-06-24 16:22:41 +02:00
|
|
|
* Generate a list of breadcrumbs for the user. Based off the remaining params
|
|
|
|
* in the url
|
2010-03-04 05:39:02 +01:00
|
|
|
*
|
2010-06-24 16:22:41 +02:00
|
|
|
* @return DataObjectSet
|
2010-03-04 05:39:02 +01:00
|
|
|
*/
|
2010-06-24 16:22:41 +02:00
|
|
|
function getBreadcrumbs() {
|
2010-08-01 06:46:32 +02:00
|
|
|
$pages = array_merge(array($this->ModuleName), $this->Remaining);;
|
2010-03-04 05:39:02 +01:00
|
|
|
|
2010-06-24 16:22:41 +02:00
|
|
|
$output = new DataObjectSet();
|
2010-08-01 06:46:32 +02:00
|
|
|
|
|
|
|
// $output->push(new ArrayData(array(
|
|
|
|
// 'Title' => ($this->Version) ? $this->Version : _t('DocumentationViewer.DOCUMENTATION', 'Documentation'),
|
|
|
|
// 'Link' => $this->Link()
|
|
|
|
// )));
|
2010-06-24 16:22:41 +02:00
|
|
|
|
|
|
|
if($pages) {
|
|
|
|
$path = array();
|
|
|
|
|
2010-08-01 06:46:32 +02:00
|
|
|
foreach($pages as $i => $title) {
|
2010-06-24 16:22:41 +02:00
|
|
|
if($title) {
|
2010-08-01 06:46:32 +02:00
|
|
|
// Don't add module name, already present in Link()
|
|
|
|
if($i > 0) $path[] = $title;
|
|
|
|
|
2010-06-24 16:22:41 +02:00
|
|
|
$output->push(new ArrayData(array(
|
|
|
|
'Title' => DocumentationParser::clean_page_name($title),
|
|
|
|
'Link' => $this->Link($path)
|
|
|
|
)));
|
2010-03-04 05:39:02 +01:00
|
|
|
}
|
2010-06-24 16:22:41 +02:00
|
|
|
}
|
2010-03-04 05:39:02 +01:00
|
|
|
}
|
2010-06-24 16:22:41 +02:00
|
|
|
|
2010-04-11 09:25:26 +02:00
|
|
|
return $output;
|
2010-03-04 05:39:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-06-24 16:22:41 +02:00
|
|
|
* Return the base link to this documentation location
|
2010-03-04 05:39:02 +01:00
|
|
|
*
|
2010-06-24 16:22:41 +02:00
|
|
|
* @todo Make this work on non /dev/
|
|
|
|
* @return String
|
|
|
|
*/
|
|
|
|
public function Link($path = false) {
|
|
|
|
$base = Director::absoluteBaseURL();
|
|
|
|
|
|
|
|
// @todo
|
|
|
|
$loc = 'dev/docs/';
|
|
|
|
|
|
|
|
$version = ($this->Version) ? $this->Version . '/' : false;
|
|
|
|
$lang = ($this->Lang) ? $this->Lang .'/' : false;
|
2010-08-01 06:46:32 +02:00
|
|
|
$module = ($this->ModuleName) ? $this->ModuleName .'/' : false;
|
2010-06-24 16:22:41 +02:00
|
|
|
|
|
|
|
$action = '';
|
|
|
|
if(is_string($path)) $action = $path . '/';
|
|
|
|
|
|
|
|
if(is_array($path)) {
|
|
|
|
foreach($path as $key => $value) {
|
|
|
|
if($value) {
|
|
|
|
$action .= $value .'/';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-01 06:46:32 +02:00
|
|
|
return $base . $loc . $version . $lang . $module . $action;
|
2010-06-24 16:22:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Build the language dropdown.
|
2010-03-04 05:39:02 +01:00
|
|
|
*
|
2010-06-24 16:22:41 +02:00
|
|
|
* @todo do this on a page by page rather than global
|
|
|
|
*
|
|
|
|
* @return Form
|
2010-03-04 05:39:02 +01:00
|
|
|
*/
|
2010-06-24 16:22:41 +02:00
|
|
|
function LanguageForm() {
|
|
|
|
if($module = $this->getModule()) {
|
|
|
|
$langs = DocumentationService::get_registered_languages($module->getModuleFolder());
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$langs = DocumentationService::get_registered_languages();
|
|
|
|
}
|
|
|
|
|
|
|
|
$fields = new FieldSet(
|
|
|
|
$dropdown = new DropdownField(
|
|
|
|
'LangCode',
|
|
|
|
_t('DocumentationViewer.LANGUAGE', 'Language'),
|
|
|
|
$langs,
|
|
|
|
$this->Lang
|
|
|
|
)
|
|
|
|
);
|
2010-03-04 05:39:02 +01:00
|
|
|
|
2010-06-24 16:22:41 +02:00
|
|
|
$actions = new FieldSet(
|
|
|
|
new FormAction('doLanguageForm', _t('DocumentationViewer.CHANGE', 'Change'))
|
|
|
|
);
|
2010-03-04 05:39:02 +01:00
|
|
|
|
2010-06-24 16:22:41 +02:00
|
|
|
$dropdown->setDisabled(true);
|
2010-03-04 11:18:02 +01:00
|
|
|
|
2010-06-24 16:22:41 +02:00
|
|
|
return new Form($this, 'LanguageForm', $fields, $actions);
|
2010-03-04 05:39:02 +01:00
|
|
|
}
|
2010-04-11 09:25:26 +02:00
|
|
|
|
2010-06-24 16:22:41 +02:00
|
|
|
/**
|
|
|
|
* Process the language change
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
function doLanguageForm($data, $form) {
|
|
|
|
$this->Lang = (isset($data['LangCode'])) ? $data['LangCode'] : 'en';
|
|
|
|
|
|
|
|
return $this->redirect($this->Link());
|
|
|
|
}
|
2010-03-04 05:39:02 +01:00
|
|
|
}
|