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-07 07:09:28 +02:00
|
|
|
/**
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
private static $extensions = array(
|
2014-09-15 11:47:45 +02:00
|
|
|
'DocumentationViewerVersionWarning',
|
|
|
|
'DocumentationSearchExtension'
|
2014-09-07 07:09:28 +02:00
|
|
|
);
|
2014-09-07 10:35:08 +02: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
|
|
|
|
2014-09-15 11:47:45 +02:00
|
|
|
/**
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
private static $allowed_actions = array(
|
|
|
|
'all',
|
|
|
|
'results',
|
|
|
|
'handleAction'
|
|
|
|
);
|
|
|
|
|
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
|
|
|
|
2014-09-27 00:12:54 +02:00
|
|
|
/**
|
|
|
|
* @var DocumentationManifest
|
|
|
|
*/
|
|
|
|
protected $manifest;
|
|
|
|
|
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-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);
|
|
|
|
}
|
2014-11-03 01:03:05 +01:00
|
|
|
Requirements::javascript('//use.typekit.net/emt4dhq.js');
|
|
|
|
Requirements::customScript('try{Typekit.load();}catch(e){}');
|
2010-10-28 23:27:30 +02:00
|
|
|
|
2012-04-08 11:23:49 +02:00
|
|
|
Requirements::javascript(THIRDPARTY_DIR .'/jquery/jquery.js');
|
2014-11-03 01:03:05 +01:00
|
|
|
Requirements::javascript('https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js');
|
2011-01-10 11:59:31 +01:00
|
|
|
|
2012-04-08 11:36:16 +02:00
|
|
|
Requirements::javascript(DOCSVIEWER_DIR .'/javascript/DocumentationViewer.js');
|
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() ||
|
2014-09-28 06:10:55 +02:00
|
|
|
!$this->config()->get('check_permission') ||
|
|
|
|
Permission::check($this->config()->get('check_permission'))
|
2012-04-08 11:23:49 +02:00
|
|
|
);
|
2011-02-11 02:29:25 +01:00
|
|
|
}
|
2010-08-01 06:46:41 +02:00
|
|
|
|
2014-09-15 11:47:45 +02:00
|
|
|
public function hasAction($action) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function checkAccessAction($action) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
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) {
|
2014-09-15 11:47:45 +02:00
|
|
|
// if we submitted a form, let that pass
|
|
|
|
if(!$request->isGET()) {
|
|
|
|
return parent::handleAction($request, $action);
|
|
|
|
}
|
2014-09-07 10:35:08 +02:00
|
|
|
|
2014-09-15 11:47:45 +02:00
|
|
|
$url = $request->getURL();
|
|
|
|
|
|
|
|
//
|
|
|
|
// If the current request has an extension attached to it, strip that
|
|
|
|
// off and redirect the user to the page without an extension.
|
|
|
|
//
|
|
|
|
if(DocumentationHelper::get_extension($url)) {
|
|
|
|
$this->response = new SS_HTTPResponse();
|
|
|
|
$this->response->redirect(
|
|
|
|
DocumentationHelper::trim_extension_off($url) .'/',
|
|
|
|
301
|
|
|
|
);
|
|
|
|
|
|
|
|
$request->shift();
|
|
|
|
$request->shift();
|
|
|
|
|
|
|
|
return $this->response;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Strip off the base url
|
|
|
|
//
|
|
|
|
$base = ltrim(
|
|
|
|
Config::inst()->get('DocumentationViewer', 'link_base'), '/'
|
|
|
|
);
|
|
|
|
|
|
|
|
if($base && strpos($url, $base) !== false) {
|
|
|
|
$url = substr(
|
|
|
|
ltrim($url, '/'),
|
|
|
|
strlen($base)
|
|
|
|
);
|
|
|
|
} else {
|
2014-01-14 09:16:39 +01:00
|
|
|
|
2010-08-01 06:46:41 +02:00
|
|
|
}
|
|
|
|
|
2014-09-15 11:47:45 +02:00
|
|
|
//
|
|
|
|
// Handle any permanent redirections that the developer has defined.
|
|
|
|
//
|
|
|
|
if($link = DocumentationPermalinks::map($url)) {
|
|
|
|
// the first param is a shortcode for a page so redirect the user to
|
|
|
|
// the short code.
|
|
|
|
$this->response = new SS_HTTPResponse();
|
|
|
|
$this->response->redirect($link, 301);
|
|
|
|
|
|
|
|
$request->shift();
|
|
|
|
$request->shift();
|
2014-09-07 01:26:12 +02:00
|
|
|
|
2014-09-15 11:47:45 +02:00
|
|
|
return $this->response;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Validate the language provided. Language is a required URL parameter.
|
|
|
|
// as we use it for generic interfaces and language selection. If
|
|
|
|
// language is not set, redirects to 'en'
|
|
|
|
//
|
|
|
|
$languages = i18n::get_common_languages();
|
|
|
|
|
2014-09-21 01:19:17 +02:00
|
|
|
if(!$lang = $request->param('Lang')) {
|
|
|
|
$lang = $request->param('Action');
|
|
|
|
$action = $request->param('ID');
|
|
|
|
} else {
|
|
|
|
$action = $request->param('Action');
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!$lang) {
|
2014-09-15 11:47:45 +02:00
|
|
|
return $this->redirect($this->Link('en'));
|
2014-09-21 01:19:17 +02:00
|
|
|
} else if(!isset($languages[$lang])) {
|
2014-09-15 11:47:45 +02:00
|
|
|
return $this->httpError(404);
|
2011-07-01 08:49:31 +02:00
|
|
|
}
|
2011-07-01 04:37:55 +02:00
|
|
|
|
2014-09-21 01:19:17 +02:00
|
|
|
$request->shift(10);
|
2014-09-07 12:14:10 +02:00
|
|
|
|
2014-09-21 01:19:17 +02:00
|
|
|
$allowed = $this->config()->allowed_actions;
|
2014-09-15 11:47:45 +02:00
|
|
|
|
|
|
|
if(in_array($action, $allowed)) {
|
|
|
|
//
|
|
|
|
// if it's one of the allowed actions such as search or all then the
|
|
|
|
// URL must be prefixed with one of the allowed languages.
|
|
|
|
//
|
|
|
|
return parent::handleAction($request, $action);
|
|
|
|
} else {
|
|
|
|
//
|
2014-09-07 10:35:08 +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.
|
2014-09-15 11:47:45 +02:00
|
|
|
|
|
|
|
// strip off any extensions.
|
|
|
|
|
|
|
|
|
|
|
|
// if($cleaned !== $url) {
|
|
|
|
// $redirect = new SS_HTTPResponse();
|
|
|
|
|
|
|
|
// return $redirect->redirect($cleaned, 302);
|
|
|
|
// }
|
|
|
|
if($record = $this->getManifest()->getPage($url)) {
|
2014-09-07 10:35:08 +02:00
|
|
|
$this->record = $record;
|
2014-09-15 11:47:45 +02:00
|
|
|
$this->init();
|
2014-09-07 10:35:08 +02:00
|
|
|
|
|
|
|
$type = get_class($this->record);
|
|
|
|
$body = $this->renderWith(array(
|
|
|
|
"DocumentationViewer_{$type}",
|
|
|
|
"DocumentationViewer"
|
|
|
|
));
|
2014-09-21 01:19:17 +02:00
|
|
|
|
2014-09-07 10:35:08 +02:00
|
|
|
return new SS_HTTPResponse($body, 200);
|
2014-09-21 01:19:17 +02:00
|
|
|
} else if(!$url || $url == $lang) {
|
2014-09-15 11:47:45 +02:00
|
|
|
$body = $this->renderWith(array(
|
|
|
|
"DocumentationViewer_DocumentationFolder",
|
|
|
|
"DocumentationViewer"
|
|
|
|
));
|
2014-09-07 10:35:08 +02:00
|
|
|
|
2014-09-15 11:47:45 +02:00
|
|
|
return new SS_HTTPResponse($body, 200);
|
2014-09-07 10:35:08 +02:00
|
|
|
}
|
2011-01-17 07:00:16 +01:00
|
|
|
}
|
2014-09-21 01:19:17 +02:00
|
|
|
|
2014-09-15 11:47:45 +02:00
|
|
|
return $this->httpError(404);
|
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-15 11:47:45 +02:00
|
|
|
* @param int $status
|
|
|
|
* @param string $message
|
2011-07-01 04:37:55 +02:00
|
|
|
*
|
2014-09-15 11:47:45 +02:00
|
|
|
* @return SS_HTTPResponse
|
2010-10-22 03:10:04 +02:00
|
|
|
*/
|
2014-09-15 11:47:45 +02:00
|
|
|
public function httpError($status, $message = null) {
|
|
|
|
$this->init();
|
|
|
|
|
|
|
|
$class = get_class($this);
|
|
|
|
$body = $this->customise(new ArrayData(array(
|
|
|
|
'Message' => $message
|
|
|
|
)))->renderWith(array("{$class}_error", $class));
|
|
|
|
|
|
|
|
return new SS_HTTPResponse($body, $status);
|
2010-10-22 03:10:04 +02:00
|
|
|
}
|
2014-09-15 11:47:45 +02:00
|
|
|
|
2010-10-22 03:10:04 +02:00
|
|
|
/**
|
2014-09-07 11:28:21 +02:00
|
|
|
* @return DocumentationManifest
|
2010-10-22 03:10:04 +02:00
|
|
|
*/
|
2014-09-07 01:26:12 +02:00
|
|
|
public function getManifest() {
|
2014-09-27 00:12:54 +02:00
|
|
|
if(!$this->manifest) {
|
|
|
|
$flush = SapphireTest::is_running_test() || (isset($_GET['flush']));
|
2014-09-15 11:47:45 +02:00
|
|
|
|
2014-09-27 00:12:54 +02:00
|
|
|
$this->manifest = new DocumentationManifest($flush);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->manifest;
|
2010-10-22 03:10:04 +02:00
|
|
|
}
|
2014-09-07 01:26:12 +02:00
|
|
|
|
2010-03-04 05:39:02 +01:00
|
|
|
/**
|
2014-09-15 11:47:45 +02:00
|
|
|
* @return string
|
2010-03-04 05:39:02 +01:00
|
|
|
*/
|
2014-09-15 11:47:45 +02:00
|
|
|
public function getLanguage() {
|
2014-09-21 01:19:17 +02:00
|
|
|
if(!$lang = $this->request->param('Lang')) {
|
|
|
|
$lang = $this->request->param('Action');
|
|
|
|
}
|
|
|
|
|
|
|
|
return $lang;
|
2010-03-04 05:39:02 +01:00
|
|
|
}
|
2010-06-24 16:22:41 +02:00
|
|
|
|
2014-09-15 11:47:45 +02:00
|
|
|
|
2014-09-07 10:35:08 +02:00
|
|
|
|
|
|
|
/**
|
2014-09-15 11:47:45 +02:00
|
|
|
* Generate a list of {@link Documentation } which have been registered and which can
|
2011-07-01 08:49:31 +02:00
|
|
|
* be documented.
|
2010-04-11 09:25:26 +02:00
|
|
|
*
|
2010-06-24 16:22:41 +02:00
|
|
|
* @return DataObject
|
|
|
|
*/
|
2014-09-15 11:47:45 +02:00
|
|
|
public function getMenu() {
|
2014-09-07 07:09:28 +02:00
|
|
|
$entities = $this->getManifest()->getEntities();
|
2012-04-14 07:00:22 +02:00
|
|
|
$output = new ArrayList();
|
2014-09-15 11:47:45 +02:00
|
|
|
$record = $this->getPage();
|
|
|
|
$current = $this->getEntity();
|
2010-06-26 06:49:20 +02:00
|
|
|
|
2014-09-15 11:47:45 +02:00
|
|
|
foreach($entities as $entity) {
|
2014-12-16 11:18:54 +01:00
|
|
|
$checkLang = $entity->getLanguage();
|
|
|
|
$checkVers = $entity->getVersion();
|
2014-09-21 01:19:17 +02:00
|
|
|
|
2014-12-16 11:18:54 +01:00
|
|
|
// only show entities with the same language or any entity that
|
|
|
|
// isn't registered under any particular language (auto detected)
|
|
|
|
if($checkLang && $checkLang !== $this->getLanguage()) {
|
2014-09-15 11:47:45 +02:00
|
|
|
continue;
|
|
|
|
}
|
2014-12-16 11:18:54 +01:00
|
|
|
|
|
|
|
if($current && $checkVers) {
|
|
|
|
if($entity->getVersion() !== $current->getVersion()) {
|
|
|
|
continue;
|
|
|
|
}
|
2014-11-14 23:41:01 +01:00
|
|
|
}
|
|
|
|
|
2014-09-15 11:47:45 +02:00
|
|
|
$mode = 'link';
|
|
|
|
$children = new ArrayList();
|
2014-09-20 03:43:22 +02:00
|
|
|
|
2014-09-15 11:47:45 +02:00
|
|
|
if($entity->hasRecord($record) || $entity->getIsDefaultEntity()) {
|
|
|
|
$mode = 'current';
|
2014-09-07 11:28:21 +02:00
|
|
|
|
2014-11-03 01:03:05 +01:00
|
|
|
// add children
|
2014-09-15 11:47:45 +02:00
|
|
|
$children = $this->getManifest()->getChildrenFor(
|
2014-09-20 03:43:22 +02:00
|
|
|
$entity->getPath(), ($record) ? $record->getPath() : $entity->getPath()
|
2014-09-15 11:47:45 +02:00
|
|
|
);
|
|
|
|
} else {
|
|
|
|
if($current && $current->getKey() == $entity->getKey()) {
|
|
|
|
continue;
|
2014-09-07 07:09:28 +02:00
|
|
|
}
|
2010-06-24 16:22:41 +02:00
|
|
|
}
|
2014-09-15 11:47:45 +02:00
|
|
|
|
|
|
|
$link = $entity->Link();
|
|
|
|
|
|
|
|
$output->push(new ArrayData(array(
|
|
|
|
'Title' => $entity->getTitle(),
|
|
|
|
'Link' => $link,
|
|
|
|
'LinkingMode' => $mode,
|
|
|
|
'DefaultEntity' => $entity->getIsDefaultEntity(),
|
|
|
|
'Children' => $children
|
|
|
|
)));
|
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-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();
|
2014-09-19 13:29:22 +02:00
|
|
|
$html = $page->getHTML();
|
|
|
|
$html = $this->replaceChildrenCalls($html);
|
2014-09-07 12:14:10 +02:00
|
|
|
|
2014-09-26 10:15:40 +02:00
|
|
|
return $html;
|
2014-09-19 13:29:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function replaceChildrenCalls($html) {
|
|
|
|
$codes = new ShortcodeParser();
|
|
|
|
$codes->register('CHILDREN', array($this, 'includeChildren'));
|
|
|
|
|
|
|
|
return $codes->parse($html);
|
|
|
|
}
|
|
|
|
|
2014-09-20 03:43:22 +02:00
|
|
|
/**
|
|
|
|
* Short code parser
|
|
|
|
*/
|
2014-09-19 13:29:22 +02:00
|
|
|
public function includeChildren($args) {
|
|
|
|
if(isset($args['Folder'])) {
|
|
|
|
$children = $this->getManifest()->getChildrenFor(
|
2014-10-13 10:55:16 +02:00
|
|
|
Controller::join_links(dirname($this->record->getPath()), $args['Folder'])
|
2014-09-19 13:29:22 +02:00
|
|
|
);
|
|
|
|
} else {
|
|
|
|
$children = $this->getManifest()->getChildrenFor(
|
|
|
|
dirname($this->record->getPath())
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2014-10-13 10:55:16 +02:00
|
|
|
if(isset($args['Exclude'])) {
|
|
|
|
$exclude = explode(',', $args['Exclude']);
|
|
|
|
|
|
|
|
foreach($children as $k => $child) {
|
|
|
|
foreach($exclude as $e) {
|
|
|
|
if($child->Link == Controller::join_links($this->record->Link(), strtolower($e), '/')) {
|
|
|
|
unset($children[$k]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-19 13:29:22 +02:00
|
|
|
return $this->customise(new ArrayData(array(
|
|
|
|
'Children' => $children
|
|
|
|
)))->renderWith('Includes/DocumentationPages');
|
2010-03-04 05:39:02 +01:00
|
|
|
}
|
2014-09-20 03:43:22 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return ArrayList
|
|
|
|
*/
|
|
|
|
public function getChildren() {
|
|
|
|
if($this->record instanceof DocumentationFolder) {
|
|
|
|
return $this->getManifest()->getChildrenFor(
|
|
|
|
$this->record->getPath()
|
|
|
|
);
|
2014-09-21 01:19:17 +02:00
|
|
|
} else if($this->record) {
|
2014-09-20 03:43:22 +02:00
|
|
|
return $this->getManifest()->getChildrenFor(
|
|
|
|
dirname($this->record->getPath())
|
|
|
|
);
|
|
|
|
}
|
2014-09-21 01:19:17 +02:00
|
|
|
|
|
|
|
return new ArrayList();
|
2014-09-20 03:43:22 +02:00
|
|
|
}
|
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) {
|
2014-09-07 12:14:10 +02:00
|
|
|
return $this->getManifest()->generateBreadcrumbs(
|
|
|
|
$this->record,
|
|
|
|
$this->record->getEntity()
|
|
|
|
);
|
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;
|
|
|
|
}
|
2014-09-15 11:47:45 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return DocumentationEntity
|
|
|
|
*/
|
|
|
|
public function getEntity() {
|
|
|
|
return ($this->record) ? $this->record->getEntity() : null;
|
|
|
|
}
|
|
|
|
|
2014-09-20 03:43:22 +02:00
|
|
|
/**
|
|
|
|
* @return ArrayList
|
|
|
|
*/
|
2014-09-15 11:47:45 +02:00
|
|
|
public function getVersions() {
|
2014-12-16 11:18:54 +01:00
|
|
|
return $this->getManifest()->getVersions($this->getEntity());
|
2014-09-15 11:47:45 +02:00
|
|
|
}
|
|
|
|
|
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
|
|
|
*/
|
2014-09-07 12:14:10 +02:00
|
|
|
public function getTitle() {
|
|
|
|
return ($this->record) ? $this->record->getTitle() : null;
|
2011-01-13 21:34:55 +01:00
|
|
|
}
|
|
|
|
|
2014-09-15 11:47:45 +02:00
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function AbsoluteLink($action) {
|
|
|
|
return Controller::join_links(
|
|
|
|
Director::absoluteBaseUrl(),
|
|
|
|
$this->Link($action)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
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 10:35:08 +02:00
|
|
|
public function Link($action = '') {
|
2011-08-04 00:04:53 +02:00
|
|
|
$link = Controller::join_links(
|
2014-09-07 10:35:08 +02:00
|
|
|
Config::inst()->get('DocumentationViewer', 'link_base'),
|
2014-09-15 11:47:45 +02:00
|
|
|
$this->getLanguage(),
|
|
|
|
$action,
|
|
|
|
'/'
|
2011-08-04 00:04:53 +02:00
|
|
|
);
|
2010-12-22 09:21:49 +01:00
|
|
|
|
|
|
|
return $link;
|
2014-09-07 10:35:08 +02:00
|
|
|
}
|
|
|
|
|
2014-09-15 11:47:45 +02:00
|
|
|
/**
|
|
|
|
* Generate a list of all the pages in the documentation grouped by the
|
|
|
|
* first letter of the page.
|
|
|
|
*
|
|
|
|
* @return GroupedList
|
|
|
|
*/
|
2014-09-07 10:35:08 +02:00
|
|
|
public function AllPages() {
|
|
|
|
$pages = $this->getManifest()->getPages();
|
|
|
|
$output = new ArrayList();
|
|
|
|
|
|
|
|
foreach($pages as $url => $page) {
|
2014-09-15 11:47:45 +02:00
|
|
|
$first = strtoupper(trim(substr($page['title'], 0, 1)));
|
|
|
|
|
|
|
|
if($first) {
|
|
|
|
$output->push(new ArrayData(array(
|
|
|
|
'Link' => $url,
|
|
|
|
'Title' => $page['title'],
|
|
|
|
'FirstLetter' => $first
|
|
|
|
)));
|
|
|
|
}
|
2014-09-07 10:35:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return GroupedList::create($output->sort('Title', 'ASC'));
|
|
|
|
}
|
2010-06-24 16:22: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() {
|
2014-09-15 11:47:45 +02:00
|
|
|
if(!Config::inst()->get('DocumentationSearch','enabled')) {
|
2014-01-14 09:16:39 +01:00
|
|
|
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
|
|
|
}
|
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() {
|
2014-11-14 23:39:19 +01:00
|
|
|
|
2012-09-03 12:02:42 +02:00
|
|
|
$page = $this->getPage();
|
|
|
|
|
|
|
|
if($page) {
|
2014-11-14 23:39:19 +01:00
|
|
|
|
2012-09-03 12:02:42 +02:00
|
|
|
$entity = $page->getEntity();
|
|
|
|
|
2014-11-14 23:39:19 +01:00
|
|
|
|
|
|
|
|
|
|
|
if($entity && isset(self::$edit_links[strtolower($entity->title)])) {
|
|
|
|
|
2012-09-03 12:02:42 +02:00
|
|
|
// build the edit link, using the version defined
|
2014-11-14 23:39:19 +01:00
|
|
|
$url = self::$edit_links[strtolower($entity->title)];
|
|
|
|
$version = $entity->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-11-14 23:39:19 +01:00
|
|
|
$entity->title,
|
2014-09-07 01:26:12 +02:00
|
|
|
$this->getLanguage(),
|
2012-09-03 12:02:42 +02:00
|
|
|
$version,
|
2014-11-14 23:39:19 +01:00
|
|
|
ltrim($page->getRelativePath(), '/')
|
2012-09-03 12:02:42 +02:00
|
|
|
),
|
|
|
|
|
|
|
|
$url['url']
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2014-09-07 01:26:12 +02:00
|
|
|
|
|
|
|
|
2014-09-15 11:47:45 +02:00
|
|
|
|
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() {
|
2014-09-15 11:47:45 +02:00
|
|
|
return ($this->record)
|
2014-09-21 01:19:17 +02:00
|
|
|
? $this->getManifest()->getNextPage(
|
|
|
|
$this->record->getPath(), $this->getEntity()->getPath())
|
2014-09-15 11:47:45 +02:00
|
|
|
: null;
|
2014-09-07 01:26:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the previous page. Either returns the previous sibling or the
|
|
|
|
* parent of this page
|
|
|
|
*
|
|
|
|
* @return DocumentationPage
|
|
|
|
*/
|
|
|
|
public function getPreviousPage() {
|
2014-09-15 11:47:45 +02:00
|
|
|
return ($this->record)
|
2014-09-21 01:19:17 +02:00
|
|
|
? $this->getManifest()->getPreviousPage(
|
|
|
|
$this->record->getPath(), $this->getEntity()->getPath())
|
2014-09-15 11:47:45 +02:00
|
|
|
: null;
|
2014-09-07 01:26:12 +02:00
|
|
|
}
|
2011-08-04 00:04:53 +02:00
|
|
|
|
2014-09-06 01:13:12 +02:00
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getGoogleAnalyticsCode() {
|
2014-09-15 11:47:45 +02:00
|
|
|
$code = $this->config()->get('google_analytics_code');
|
2014-09-06 01:13:12 +02:00
|
|
|
|
|
|
|
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() {
|
2014-09-15 11:47:45 +02:00
|
|
|
return $this->config()->get('documentation_title');
|
2014-09-06 01:22:05 +02:00
|
|
|
}
|
2014-09-27 00:12:54 +02:00
|
|
|
|
|
|
|
public function getDocumentationBaseHref() {
|
|
|
|
return Config::inst()->get('DocumentationViewer', 'link_base');
|
|
|
|
}
|
2013-01-11 11:02:49 +01:00
|
|
|
}
|