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
|
|
|
*
|
2012-04-08 11:23:49 +02:00
|
|
|
* Reads the bundled markdown files from documentation folders and displays the
|
2014-09-06 01:13:12 +02:00
|
|
|
* output (either via markdown or plain text).
|
2010-06-24 16:22:41 +02:00
|
|
|
*
|
2012-04-08 11:23:49 +02:00
|
|
|
* For more documentation on how to use this class see the documentation in the
|
2014-09-06 01:13:12 +02:00
|
|
|
* docs folder.
|
2010-06-24 16:22:41 +02:00
|
|
|
*
|
2012-04-08 11:36:16 +02:00
|
|
|
* @package docsviewer
|
2010-03-04 05:39:02 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
class DocumentationViewer extends Controller {
|
2010-06-24 16:22:41 +02:00
|
|
|
|
2014-09-05 23:20:05 +02:00
|
|
|
/**
|
|
|
|
* @var array
|
|
|
|
*/
|
2013-03-26 11:08:44 +01:00
|
|
|
private static $allowed_actions = array(
|
2010-12-21 10:42:44 +01:00
|
|
|
'home',
|
2010-06-24 16:22:41 +02:00
|
|
|
'LanguageForm',
|
|
|
|
'doLanguageForm',
|
|
|
|
'handleRequest',
|
2010-12-21 10:42:44 +01:00
|
|
|
'DocumentationSearchForm',
|
|
|
|
'results'
|
2010-06-24 16:22:41 +02:00
|
|
|
);
|
2010-03-04 05:39:02 +01:00
|
|
|
|
2014-09-06 01:13:12 +02:00
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
private static $google_analytics_code = '';
|
|
|
|
|
2014-09-06 01:22:05 +02:00
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
private static $documentation_title = 'SilverStripe Documentation';
|
2010-10-22 03:10:04 +02:00
|
|
|
|
|
|
|
/**
|
2011-07-01 08:49:31 +02:00
|
|
|
* The string name of the currently accessed {@link DocumentationEntity}
|
2012-04-08 11:23:49 +02:00
|
|
|
* object. To access the entire object use {@link getEntity()}
|
|
|
|
*
|
2010-10-22 03:10:04 +02:00
|
|
|
* @var string
|
|
|
|
*/
|
2014-09-07 01:26:12 +02:00
|
|
|
protected $entity = '';
|
|
|
|
|
2012-11-12 15:48:15 +01:00
|
|
|
/**
|
|
|
|
* @var DocumentationPage
|
|
|
|
*/
|
2014-09-07 01:26:12 +02:00
|
|
|
protected $record;
|
2012-11-12 15:48:15 +01:00
|
|
|
|
2010-08-01 06:46:41 +02:00
|
|
|
/**
|
2014-09-07 01:26:12 +02:00
|
|
|
* @config
|
|
|
|
*
|
|
|
|
* @var string same as the routing pattern set through Director::addRules().
|
2010-08-01 06:46:41 +02:00
|
|
|
*/
|
2014-09-07 01:26:12 +02:00
|
|
|
private static $link_base = 'dev/docs/';
|
2010-08-01 06:46:41 +02:00
|
|
|
|
2010-08-01 07:04:36 +02:00
|
|
|
/**
|
2014-09-07 01:26:12 +02:00
|
|
|
* @config
|
|
|
|
*
|
|
|
|
* @var string|array Optional permission check
|
2010-08-01 07:04:36 +02:00
|
|
|
*/
|
2014-09-07 01:26:12 +02:00
|
|
|
private static $check_permission = 'ADMIN';
|
2012-09-03 12:02:42 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var array map of modules to edit links.
|
|
|
|
* @see {@link getEditLink()}
|
|
|
|
*/
|
|
|
|
private static $edit_links = array();
|
2012-11-12 15:48:15 +01:00
|
|
|
|
2014-09-07 01:26:12 +02:00
|
|
|
/**
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
private static $url_handlers = array(
|
|
|
|
'$Action' => 'handleAction'
|
|
|
|
);
|
|
|
|
|
2014-01-14 09:16:39 +01:00
|
|
|
/**
|
2014-09-06 01:13:12 +02:00
|
|
|
*
|
2014-01-14 09:16:39 +01:00
|
|
|
*/
|
|
|
|
public function init() {
|
2010-06-24 16:22:41 +02:00
|
|
|
parent::init();
|
2010-04-11 09:25:26 +02:00
|
|
|
|
2014-09-06 01:13:12 +02:00
|
|
|
if(!$this->canView()) {
|
|
|
|
return Security::permissionFailure($this);
|
|
|
|
}
|
2010-10-28 23:27:30 +02:00
|
|
|
|
2012-04-08 11:23:49 +02:00
|
|
|
Requirements::javascript(THIRDPARTY_DIR .'/jquery/jquery.js');
|
2011-01-10 11:59:31 +01:00
|
|
|
Requirements::combine_files(
|
|
|
|
'syntaxhighlighter.js',
|
|
|
|
array(
|
2012-04-08 11:36:16 +02:00
|
|
|
DOCSVIEWER_DIR .'/thirdparty/syntaxhighlighter/scripts/shCore.js',
|
|
|
|
DOCSVIEWER_DIR . '/thirdparty/syntaxhighlighter/scripts/shBrushJScript.js',
|
|
|
|
DOCSVIEWER_DIR . '/thirdparty/syntaxhighlighter/scripts/shBrushPhp.js',
|
|
|
|
DOCSVIEWER_DIR . '/thirdparty/syntaxhighlighter/scripts/shBrushXml.js',
|
|
|
|
DOCSVIEWER_DIR . '/thirdparty/syntaxhighlighter/scripts/shBrushCss.js',
|
2012-09-25 09:35:49 +02:00
|
|
|
DOCSVIEWER_DIR . '/thirdparty/syntaxhighlighter/scripts/shBrushYaml.js',
|
2014-09-05 23:20:05 +02:00
|
|
|
DOCSVIEWER_DIR . '/thirdparty/syntaxhighlighter/scripts/shBrushBash.js',
|
2012-04-08 11:36:16 +02:00
|
|
|
DOCSVIEWER_DIR . '/javascript/shBrushSS.js'
|
2011-01-10 11:59:31 +01:00
|
|
|
)
|
|
|
|
);
|
|
|
|
|
2012-04-08 11:36:16 +02:00
|
|
|
Requirements::javascript(DOCSVIEWER_DIR .'/javascript/DocumentationViewer.js');
|
|
|
|
Requirements::css(DOCSVIEWER_DIR .'/css/shSilverStripeDocs.css');
|
2014-09-06 01:13:12 +02:00
|
|
|
Requirements::combine_files('docs.css', array(
|
|
|
|
DOCSVIEWER_DIR .'/css/normalize.css',
|
|
|
|
DOCSVIEWER_DIR .'/css/utilities.css',
|
|
|
|
DOCSVIEWER_DIR .'/css/typography.css',
|
|
|
|
DOCSVIEWER_DIR .'/css/forms.css',
|
|
|
|
DOCSVIEWER_DIR .'/css/layout.css',
|
|
|
|
DOCSVIEWER_DIR .'/css/small.css'
|
|
|
|
));
|
2010-04-11 09:25:26 +02:00
|
|
|
}
|
2011-02-11 02:29:25 +01:00
|
|
|
|
|
|
|
/**
|
2014-09-06 01:13:12 +02:00
|
|
|
* Can the user view this documentation. Hides all functionality for private
|
|
|
|
* wikis.
|
2011-02-11 02:29:25 +01:00
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function canView() {
|
2012-04-08 11:23:49 +02:00
|
|
|
return (Director::isDev() || Director::is_cli() ||
|
|
|
|
!self::$check_permission ||
|
|
|
|
Permission::check(self::$check_permission)
|
|
|
|
);
|
2011-02-11 02:29:25 +01:00
|
|
|
}
|
2010-08-01 06:46:41 +02:00
|
|
|
|
|
|
|
/**
|
2012-04-08 11:23:49 +02:00
|
|
|
* Overloaded to avoid "action doesn't exist" errors - all URL parts in
|
|
|
|
* this controller are virtual and handled through handleRequest(), not
|
|
|
|
* controller methods.
|
|
|
|
*
|
2013-02-19 22:05:05 +01:00
|
|
|
* @param $request
|
|
|
|
* @param $action
|
2014-01-14 09:16:39 +01:00
|
|
|
*
|
2012-04-08 11:23:49 +02:00
|
|
|
* @return SS_HTTPResponse
|
2010-08-01 06:46:41 +02:00
|
|
|
*/
|
2013-02-19 22:05:05 +01:00
|
|
|
public function handleAction($request, $action) {
|
2011-07-01 04:37:55 +02:00
|
|
|
try {
|
2014-01-14 09:16:39 +01:00
|
|
|
if(preg_match('/DocumentationSearchForm/', $request->getURL())) {
|
|
|
|
$action = 'results';
|
|
|
|
}
|
|
|
|
|
2013-02-19 22:05:05 +01:00
|
|
|
$response = parent::handleAction($request, $action);
|
2010-08-01 06:46:41 +02:00
|
|
|
} catch(SS_HTTPResponse_Exception $e) {
|
|
|
|
if(strpos($e->getMessage(), 'does not exist') !== FALSE) {
|
|
|
|
return $this;
|
|
|
|
} else {
|
|
|
|
throw $e;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $response;
|
|
|
|
}
|
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
|
|
|
* @return SS_HTTPResponse
|
2010-04-11 09:25:26 +02:00
|
|
|
*/
|
2012-04-14 08:02:53 +02:00
|
|
|
public function handleRequest(SS_HTTPRequest $request, DataModel $model) {
|
2014-09-07 01:26:12 +02:00
|
|
|
$response = parent::handleRequest($request, $model);
|
|
|
|
|
2010-10-21 22:27:23 +02:00
|
|
|
// if we submitted a form, let that pass
|
2012-09-09 08:05:06 +02:00
|
|
|
if(!$request->isGET() || isset($_GET['action_results'])) {
|
2014-09-07 01:26:12 +02:00
|
|
|
return $response;
|
2011-07-01 08:49:31 +02:00
|
|
|
}
|
|
|
|
|
2014-09-07 01:26:12 +02:00
|
|
|
// look up the manifest to see find the nearest match against the
|
|
|
|
// list of the URL. If the URL exists then set that as the current
|
|
|
|
// page to match against.
|
|
|
|
if($record = $this->getManifest()->getPage($this->request->getURL())) {
|
|
|
|
$this->record = $record;
|
2011-01-14 02:03:46 +01:00
|
|
|
|
2014-09-07 01:26:12 +02:00
|
|
|
$type = get_class($this->record);
|
|
|
|
$body = $this->renderWith(array(
|
|
|
|
"DocumentationViewer_{$type}",
|
|
|
|
"DocumentationViewer"
|
|
|
|
));
|
|
|
|
|
|
|
|
return new SS_HTTPResponse($body, 200);
|
2010-06-24 16:22:41 +02:00
|
|
|
}
|
2014-09-07 01:26:12 +02:00
|
|
|
else {
|
|
|
|
$this->init();
|
2010-10-22 03:52:35 +02:00
|
|
|
|
2014-09-07 01:26:12 +02:00
|
|
|
$class = get_class($this);
|
|
|
|
$body = $this->renderWith(array("{$class}_error", $class));
|
2011-07-01 04:37:55 +02:00
|
|
|
|
2014-09-07 01:26:12 +02:00
|
|
|
return new SS_HTTPResponse($body, 404);
|
2011-01-17 07:00:16 +01:00
|
|
|
}
|
2010-04-11 09:25:26 +02:00
|
|
|
}
|
2014-09-07 01:26:12 +02:00
|
|
|
|
2011-07-01 04:37:55 +02:00
|
|
|
/**
|
2014-09-07 01:26:12 +02:00
|
|
|
* Returns the current version. If no version is set then it is the current
|
|
|
|
* set version so need to pull that from the {@link Entity}.
|
2011-07-01 04:37:55 +02:00
|
|
|
*
|
2014-09-07 01:26:12 +02:00
|
|
|
* @return string
|
2010-04-11 09:25:26 +02:00
|
|
|
*/
|
2014-09-07 01:26:12 +02:00
|
|
|
public function getVersion() {
|
|
|
|
return ($this->record) ? $this->record->getEntity()->getVersion() : null;
|
2010-03-04 05:39:02 +01:00
|
|
|
}
|
2010-03-04 05:59:00 +01:00
|
|
|
|
2010-10-22 03:10:04 +02:00
|
|
|
/**
|
2014-09-07 01:26:12 +02:00
|
|
|
* Returns the current language.
|
2010-10-22 03:10:04 +02:00
|
|
|
*
|
2014-09-07 01:26:12 +02:00
|
|
|
* @return string
|
2010-10-22 03:10:04 +02:00
|
|
|
*/
|
2014-09-07 01:26:12 +02:00
|
|
|
public function getLanguage() {
|
|
|
|
return ($this->record) ? $this->record->getEntity()->getLanguage() : null;
|
2010-10-22 03:10:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
2014-09-07 01:26:12 +02:00
|
|
|
public function getManifest() {
|
|
|
|
return new DocumentationManifest((isset($_GET['flush'])));
|
2010-10-22 03:10:04 +02:00
|
|
|
}
|
2014-09-07 01:26:12 +02:00
|
|
|
|
2010-03-04 05:39:02 +01:00
|
|
|
/**
|
2011-08-04 00:04:53 +02:00
|
|
|
* Return all the available languages for the {@link Entity}.
|
2010-03-04 05:39:02 +01:00
|
|
|
*
|
2011-08-04 00:04:53 +02:00
|
|
|
* @return array
|
2010-03-04 05:39:02 +01:00
|
|
|
*/
|
2014-09-07 01:26:12 +02:00
|
|
|
public function getLanguages() {
|
|
|
|
return ($this->record) ? $this->record->getEntity()->getSupportedLanguages() : null;
|
2010-03-04 05:39:02 +01:00
|
|
|
}
|
2010-06-24 16:22:41 +02:00
|
|
|
|
2010-03-04 11:18:02 +01:00
|
|
|
/**
|
2011-07-01 08:49:31 +02:00
|
|
|
* Get all the versions loaded for the current {@link DocumentationEntity}.
|
2014-09-07 01:26:12 +02:00
|
|
|
* the file system then they are loaded under the 'Current' name space.
|
2010-06-24 16:22:41 +02:00
|
|
|
*
|
2011-08-04 00:04:53 +02:00
|
|
|
* @param String $entity name of {@link Entity} to limit it to eg sapphire
|
2012-04-14 07:00:22 +02:00
|
|
|
* @return ArrayList
|
2010-03-04 11:18:02 +01:00
|
|
|
*/
|
2014-09-07 01:26:12 +02:00
|
|
|
public function getVersions() {
|
|
|
|
return ($this->record) ? $this->record->getEntity()->getVersions() : null;
|
2010-03-04 11:18:02 +01:00
|
|
|
}
|
|
|
|
|
2010-04-11 09:25:26 +02:00
|
|
|
/**
|
2011-07-01 08:49:31 +02:00
|
|
|
* Generate a list of entities which have been registered and which can
|
|
|
|
* be documented.
|
2010-04-11 09:25:26 +02:00
|
|
|
*
|
2010-06-24 16:22:41 +02:00
|
|
|
* @return DataObject
|
|
|
|
*/
|
2014-09-07 01:26:12 +02:00
|
|
|
public function getEntities() {
|
|
|
|
$entities = DocumentationService::get_registered_entities();
|
2012-04-14 07:00:22 +02:00
|
|
|
$output = new ArrayList();
|
2011-07-01 08:49:31 +02:00
|
|
|
|
|
|
|
$currentEntity = $this->getEntity();
|
2010-06-26 06:49:20 +02:00
|
|
|
|
2011-07-01 08:49:31 +02:00
|
|
|
if($entities) {
|
|
|
|
foreach($entities as $entity) {
|
|
|
|
$mode = ($entity === $currentEntity) ? 'current' : 'link';
|
|
|
|
$folder = $entity->getFolder();
|
|
|
|
|
2014-09-07 01:26:12 +02:00
|
|
|
$link = $entity->Link();
|
2011-07-01 08:49:31 +02:00
|
|
|
|
|
|
|
$content = false;
|
2014-09-07 01:26:12 +02:00
|
|
|
|
|
|
|
// if($page = $entity->getIndexPage()) {
|
|
|
|
// $content = DBField::create_field('HTMLText', DocumentationParser::parse($page, $link));
|
|
|
|
// }
|
2010-08-01 06:46:32 +02:00
|
|
|
|
2010-06-24 16:22:41 +02:00
|
|
|
$output->push(new ArrayData(array(
|
2011-07-01 08:49:31 +02:00
|
|
|
'Title' => $entity->getTitle(),
|
|
|
|
'Link' => $link,
|
|
|
|
'LinkingMode' => $mode,
|
2014-09-06 01:13:12 +02:00
|
|
|
'Content' => $content,
|
2014-09-06 01:22:05 +02:00
|
|
|
|
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
|
|
|
*
|
2014-09-07 01:26:12 +02:00
|
|
|
* @return DocumentationEntity
|
2010-03-04 11:18:02 +01:00
|
|
|
*/
|
2012-11-09 21:27:10 +01:00
|
|
|
public function getEntity() {
|
2011-07-01 08:49:31 +02:00
|
|
|
if($this->entity) {
|
|
|
|
return DocumentationService::is_registered_entity(
|
|
|
|
$this->entity,
|
2011-07-01 03:19:35 +02:00
|
|
|
$this->version,
|
|
|
|
$this->language
|
|
|
|
);
|
2010-03-04 11:18:02 +01:00
|
|
|
}
|
2010-06-24 16:22:41 +02:00
|
|
|
|
2014-09-07 01:26:12 +02:00
|
|
|
return null;
|
2010-10-22 05:46:44 +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
|
|
|
*/
|
2014-09-06 01:13:12 +02:00
|
|
|
public function getContent() {
|
2011-07-01 03:19:35 +02:00
|
|
|
$page = $this->getPage();
|
2011-01-14 03:16:03 +01:00
|
|
|
|
2011-07-01 03:19:35 +02:00
|
|
|
if($page) {
|
2014-09-07 01:26:12 +02:00
|
|
|
return DBField::create_field("HTMLText", $page->getHTML(
|
|
|
|
$this->getVersion(), $this->getLanguage()
|
|
|
|
));
|
2010-06-24 16:22:41 +02:00
|
|
|
}
|
2011-07-01 04:37:55 +02:00
|
|
|
|
|
|
|
// If no page found then we may want to get the listing of the folder.
|
|
|
|
// In case no folder exists, show a "not found" page.
|
2011-07-01 08:49:31 +02:00
|
|
|
$entity = $this->getEntity();
|
2011-07-01 04:37:55 +02:00
|
|
|
$url = $this->Remaining;
|
|
|
|
|
2011-07-01 08:49:31 +02:00
|
|
|
if($url && $entity) {
|
2014-09-07 01:26:12 +02:00
|
|
|
// @todo manifest
|
2011-03-12 05:14:37 +01:00
|
|
|
|
2011-07-01 04:37:55 +02:00
|
|
|
return $this->customise(array(
|
|
|
|
'Content' => false,
|
|
|
|
'Title' => DocumentationService::clean_page_name(array_pop($url)),
|
|
|
|
'Pages' => $pages
|
2014-09-06 01:13:12 +02:00
|
|
|
))->renderWith('DocumentationFolderListing');
|
2011-01-14 03:16:03 +01:00
|
|
|
}
|
2011-07-01 04:37:55 +02:00
|
|
|
else {
|
|
|
|
return $this->customise(array(
|
|
|
|
'Content' => false,
|
|
|
|
'Title' => _t('DocumentationViewer.MODULES', 'Modules'),
|
2011-07-01 08:49:31 +02:00
|
|
|
'Pages' => $this->getEntities()
|
2014-09-06 01:13:12 +02:00
|
|
|
))->renderWith('DocumentationFolderListing');
|
2011-07-01 04:37:55 +02:00
|
|
|
}
|
|
|
|
|
2010-06-24 16:22:41 +02:00
|
|
|
return false;
|
2010-03-04 05:39:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-09-07 01:26:12 +02:00
|
|
|
* Generate a list of breadcrumbs for the user.
|
2010-03-04 05:39:02 +01:00
|
|
|
*
|
2012-04-14 07:00:22 +02:00
|
|
|
* @return ArrayList
|
2010-03-04 05:39:02 +01:00
|
|
|
*/
|
2012-11-09 22:52:11 +01:00
|
|
|
public function getBreadcrumbs() {
|
2014-09-07 01:26:12 +02:00
|
|
|
if($this->record) {
|
|
|
|
return $this->getManifest()->generateBreadcrumbs($this->record);
|
2014-09-06 01:13:12 +02:00
|
|
|
}
|
2010-03-04 05:39:02 +01:00
|
|
|
}
|
2014-09-07 01:26:12 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return DocumentationPage
|
|
|
|
*/
|
|
|
|
public function getPage() {
|
|
|
|
return $this->record;
|
|
|
|
}
|
2011-01-13 21:34:55 +01:00
|
|
|
/**
|
|
|
|
* Generate a string for the title tag in the URL.
|
|
|
|
*
|
2012-11-09 22:52:11 +01:00
|
|
|
* @return string
|
2011-01-13 21:34:55 +01:00
|
|
|
*/
|
2012-11-09 22:52:11 +01:00
|
|
|
public function getPageTitle() {
|
2014-09-07 01:26:12 +02:00
|
|
|
return ($this->record) ? $this->record->getBreadcrumbTitle() : null;
|
2011-01-13 21:34:55 +01:00
|
|
|
}
|
|
|
|
|
2010-03-04 05:39:02 +01:00
|
|
|
/**
|
2014-09-07 01:26:12 +02:00
|
|
|
* Return the base link to this documentation location.
|
2011-07-01 08:49:31 +02:00
|
|
|
*
|
2014-09-07 01:26:12 +02:00
|
|
|
* @return string
|
2010-06-24 16:22:41 +02:00
|
|
|
*/
|
2014-09-07 01:26:12 +02:00
|
|
|
public function Link() {
|
2011-08-04 00:04:53 +02:00
|
|
|
$link = Controller::join_links(
|
|
|
|
Director::absoluteBaseURL(),
|
2014-09-07 01:26:12 +02:00
|
|
|
Config::inst()->get('DocumentationViewer', 'link_base')
|
2011-08-04 00:04:53 +02:00
|
|
|
);
|
2010-12-22 09:21:49 +01:00
|
|
|
|
|
|
|
return $link;
|
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
|
|
|
*/
|
2014-01-14 09:16:39 +01:00
|
|
|
public function LanguageForm() {
|
2011-08-02 05:30:58 +02:00
|
|
|
$langs = $this->getLanguages();
|
2014-09-07 01:26:12 +02:00
|
|
|
|
2012-04-14 07:00:22 +02:00
|
|
|
$fields = new FieldList(
|
2010-06-24 16:22:41 +02:00
|
|
|
$dropdown = new DropdownField(
|
|
|
|
'LangCode',
|
|
|
|
_t('DocumentationViewer.LANGUAGE', 'Language'),
|
|
|
|
$langs,
|
|
|
|
$this->Lang
|
|
|
|
)
|
|
|
|
);
|
2010-03-04 05:39:02 +01:00
|
|
|
|
2012-04-14 07:00:22 +02:00
|
|
|
$actions = new FieldList(
|
2010-06-24 16:22:41 +02:00
|
|
|
new FormAction('doLanguageForm', _t('DocumentationViewer.CHANGE', 'Change'))
|
|
|
|
);
|
2014-09-07 01:26:12 +02: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
|
|
|
|
*
|
|
|
|
*/
|
2014-01-14 09:16:39 +01:00
|
|
|
public function doLanguageForm($data, $form) {
|
2010-06-24 16:22:41 +02:00
|
|
|
$this->Lang = (isset($data['LangCode'])) ? $data['LangCode'] : 'en';
|
|
|
|
|
|
|
|
return $this->redirect($this->Link());
|
|
|
|
}
|
2010-08-01 06:46:41 +02:00
|
|
|
|
2010-10-21 22:27:23 +02:00
|
|
|
/**
|
2011-08-04 00:04:53 +02:00
|
|
|
* Documentation Search Form. Allows filtering of the results by many entities
|
|
|
|
* and multiple versions.
|
2010-10-21 22:27:23 +02:00
|
|
|
*
|
|
|
|
* @return Form
|
|
|
|
*/
|
2014-01-14 09:16:39 +01:00
|
|
|
public function DocumentationSearchForm() {
|
|
|
|
if(!DocumentationSearch::enabled()) {
|
|
|
|
return false;
|
|
|
|
}
|
2010-12-21 10:42:44 +01:00
|
|
|
|
2014-09-07 01:26:12 +02:00
|
|
|
return new DocumentationSearchForm($this);
|
2010-10-21 22:27:23 +02:00
|
|
|
}
|
2011-07-08 04:42:52 +02:00
|
|
|
|
2011-08-04 00:04:53 +02:00
|
|
|
|
2011-07-08 04:42:52 +02:00
|
|
|
/**
|
|
|
|
* Check to see if the currently accessed version is out of date or
|
|
|
|
* perhaps a future version rather than the stable edition
|
|
|
|
*
|
|
|
|
* @return false|ArrayData
|
|
|
|
*/
|
2014-01-14 09:16:39 +01:00
|
|
|
public function VersionWarning() {
|
2011-07-08 04:42:52 +02:00
|
|
|
$version = $this->getVersion();
|
|
|
|
$entity = $this->getEntity();
|
|
|
|
|
|
|
|
if($entity) {
|
|
|
|
$compare = $entity->compare($version);
|
|
|
|
$stable = $entity->getStableVersion();
|
|
|
|
|
|
|
|
// same
|
|
|
|
if($version == $stable) return false;
|
|
|
|
|
|
|
|
// check for trunk, if trunk and not the same then it's future
|
|
|
|
// also run through compare
|
|
|
|
if($version == "trunk" || $compare > 0) {
|
|
|
|
return $this->customise(new ArrayData(array(
|
|
|
|
'FutureRelease' => true,
|
2012-04-14 07:00:22 +02:00
|
|
|
'StableVersion' => DBField::create_field('HTMLText', $stable)
|
2011-07-08 04:42:52 +02:00
|
|
|
)));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return $this->customise(new ArrayData(array(
|
|
|
|
'OutdatedRelease' => true,
|
2012-04-14 07:00:22 +02:00
|
|
|
'StableVersion' => DBField::create_field('HTMLText', $stable)
|
2011-07-08 04:42:52 +02:00
|
|
|
)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2012-09-03 12:02:42 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the mapping between a entity name and the link for the end user
|
|
|
|
* to jump into editing the documentation.
|
|
|
|
*
|
|
|
|
* Some variables are replaced:
|
|
|
|
* - %version%
|
|
|
|
* - %entity%
|
|
|
|
* - %path%
|
|
|
|
* - %lang%
|
|
|
|
*
|
|
|
|
* For example to provide an edit link to the framework module in github:
|
|
|
|
*
|
|
|
|
* <code>
|
|
|
|
* DocumentationViewer::set_edit_link(
|
|
|
|
* 'framework',
|
|
|
|
* 'https://github.com/silverstripe/%entity%/edit/%version%/docs/%lang%/%path%',
|
|
|
|
* $opts
|
|
|
|
* ));
|
|
|
|
* </code>
|
|
|
|
*
|
|
|
|
* @param string module name
|
|
|
|
* @param string link
|
|
|
|
* @param array options ('rewritetrunktomaster')
|
|
|
|
*/
|
|
|
|
public static function set_edit_link($module, $link, $options = array()) {
|
|
|
|
self::$edit_links[$module] = array(
|
|
|
|
'url' => $link,
|
|
|
|
'options' => $options
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns an edit link to the current page (optional).
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getEditLink() {
|
|
|
|
$page = $this->getPage();
|
|
|
|
|
|
|
|
if($page) {
|
|
|
|
$entity = $page->getEntity();
|
|
|
|
|
|
|
|
if($entity && isset(self::$edit_links[$entity->title])) {
|
|
|
|
// build the edit link, using the version defined
|
|
|
|
$url = self::$edit_links[$entity->title];
|
2014-09-07 01:26:12 +02:00
|
|
|
$version = $this->getVersion();
|
2012-09-03 12:02:42 +02:00
|
|
|
|
|
|
|
if($version == "trunk" && (isset($url['options']['rewritetrunktomaster']))) {
|
|
|
|
if($url['options']['rewritetrunktomaster']) {
|
|
|
|
$version = "master";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return str_replace(
|
|
|
|
array('%entity%', '%lang%', '%version%', '%path%'),
|
|
|
|
array(
|
2014-09-07 01:26:12 +02:00
|
|
|
$entity->getBaseFolder(),
|
|
|
|
$this->getLanguage(),
|
2012-09-03 12:02:42 +02:00
|
|
|
$version,
|
2014-09-07 01:26:12 +02:00
|
|
|
ltrim($page->getPath(), '/')
|
2012-09-03 12:02:42 +02:00
|
|
|
),
|
|
|
|
|
|
|
|
$url['url']
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2014-09-07 01:26:12 +02:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the next page. Either retrieves the sibling of the current page
|
|
|
|
* or return the next sibling of the parent page.
|
|
|
|
*
|
|
|
|
* @return DocumentationPage
|
|
|
|
*/
|
|
|
|
public function getNextPage() {
|
|
|
|
return ($this->record) ? $this->getManifest()->getNextPage($this->record->getPath()) : null;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the previous page. Either returns the previous sibling or the
|
|
|
|
* parent of this page
|
|
|
|
*
|
|
|
|
* @return DocumentationPage
|
|
|
|
*/
|
|
|
|
public function getPreviousPage() {
|
|
|
|
return ($this->record) ? $this->getManifest()->getPreviousPage($this->record->getPath()) : null;
|
|
|
|
}
|
2011-08-04 00:04:53 +02:00
|
|
|
|
2014-09-06 01:13:12 +02:00
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getGoogleAnalyticsCode() {
|
|
|
|
$code = Config::inst()->get('DocumentationViewer', 'google_analytics_code');
|
|
|
|
|
|
|
|
if($code) {
|
|
|
|
return $code;
|
2011-08-04 00:04:53 +02:00
|
|
|
}
|
|
|
|
}
|
2014-09-06 01:22:05 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getDocumentationTitle() {
|
|
|
|
return Config::inst()->get('DocumentationViewer', 'documentation_title');
|
|
|
|
}
|
2013-01-11 11:02:49 +01:00
|
|
|
}
|