2011-03-23 10:51:00 +01:00
|
|
|
<?php
|
2015-08-24 06:15:38 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @package framework
|
|
|
|
* @subpackage admin
|
|
|
|
*/
|
|
|
|
|
2016-02-22 02:13:35 +01:00
|
|
|
use SilverStripe\Forms\Schema\FormSchema;
|
|
|
|
|
2011-03-23 10:51:00 +01:00
|
|
|
/**
|
|
|
|
* LeftAndMain is the parent class of all the two-pane views in the CMS.
|
|
|
|
* If you are wanting to add more areas to the CMS, you can do it by subclassing LeftAndMain.
|
2014-08-15 08:53:05 +02:00
|
|
|
*
|
2011-03-23 10:51:00 +01:00
|
|
|
* This is essentially an abstract class which should be subclassed.
|
|
|
|
* See {@link CMSMain} for a good example.
|
2016-03-01 04:15:15 +01:00
|
|
|
*
|
|
|
|
* @property FormSchema $schema
|
2011-03-23 10:51:00 +01:00
|
|
|
*/
|
2012-03-05 16:07:20 +01:00
|
|
|
class LeftAndMain extends Controller implements PermissionProvider {
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2011-03-23 10:51:00 +01:00
|
|
|
/**
|
|
|
|
* The 'base' url for CMS administration areas.
|
|
|
|
* Note that if this is changed, many javascript
|
|
|
|
* behaviours need to be updated with the correct url
|
|
|
|
*
|
2013-03-21 19:48:54 +01:00
|
|
|
* @config
|
2011-03-23 10:51:00 +01:00
|
|
|
* @var string $url_base
|
|
|
|
*/
|
2013-03-21 19:48:54 +01:00
|
|
|
private static $url_base = "admin";
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2011-05-20 01:29:40 +02:00
|
|
|
/**
|
|
|
|
* The current url segment attached to the LeftAndMain instance
|
|
|
|
*
|
2013-03-21 19:48:54 +01:00
|
|
|
* @config
|
2011-05-20 01:29:40 +02:00
|
|
|
* @var string
|
|
|
|
*/
|
2013-03-21 19:48:54 +01:00
|
|
|
private static $url_segment;
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2011-05-20 01:29:40 +02:00
|
|
|
/**
|
2013-03-21 19:48:54 +01:00
|
|
|
* @config
|
2011-05-20 01:29:40 +02:00
|
|
|
* @var string
|
|
|
|
*/
|
2013-03-21 19:48:54 +01:00
|
|
|
private static $url_rule = '/$Action/$ID/$OtherID';
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2011-05-20 01:29:40 +02:00
|
|
|
/**
|
2013-03-21 19:48:54 +01:00
|
|
|
* @config
|
2011-05-20 01:29:40 +02:00
|
|
|
* @var string
|
|
|
|
*/
|
2013-03-21 19:48:54 +01:00
|
|
|
private static $menu_title;
|
2012-08-19 14:14:41 +02:00
|
|
|
|
|
|
|
/**
|
2013-03-21 19:48:54 +01:00
|
|
|
* @config
|
2012-08-19 14:14:41 +02:00
|
|
|
* @var string
|
|
|
|
*/
|
2013-03-21 19:48:54 +01:00
|
|
|
private static $menu_icon;
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2011-05-20 01:29:40 +02:00
|
|
|
/**
|
2013-03-21 19:48:54 +01:00
|
|
|
* @config
|
2011-05-20 01:29:40 +02:00
|
|
|
* @var int
|
|
|
|
*/
|
2013-03-21 19:48:54 +01:00
|
|
|
private static $menu_priority = 0;
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2011-05-20 01:29:40 +02:00
|
|
|
/**
|
2013-03-21 19:48:54 +01:00
|
|
|
* @config
|
2011-05-20 01:29:40 +02:00
|
|
|
* @var int
|
|
|
|
*/
|
2013-03-21 19:48:54 +01:00
|
|
|
private static $url_priority = 50;
|
2011-03-23 10:51:00 +01:00
|
|
|
|
|
|
|
/**
|
2014-08-15 08:53:05 +02:00
|
|
|
* A subclass of {@link DataObject}.
|
|
|
|
*
|
|
|
|
* Determines what is managed in this interface, through
|
2011-05-20 01:29:40 +02:00
|
|
|
* {@link getEditForm()} and other logic.
|
|
|
|
*
|
2013-03-21 19:48:54 +01:00
|
|
|
* @config
|
2014-08-15 08:53:05 +02:00
|
|
|
* @var string
|
2011-03-23 10:51:00 +01:00
|
|
|
*/
|
2013-03-21 19:48:54 +01:00
|
|
|
private static $tree_class = null;
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2011-03-23 10:51:00 +01:00
|
|
|
/**
|
2011-05-20 01:29:40 +02:00
|
|
|
* The url used for the link in the Help tab in the backend
|
2013-03-21 19:48:54 +01:00
|
|
|
*
|
|
|
|
* @config
|
2011-05-20 01:29:40 +02:00
|
|
|
* @var string
|
|
|
|
*/
|
2015-07-31 01:38:18 +02:00
|
|
|
private static $help_link = '//userhelp.silverstripe.org/framework/en/3.2';
|
2011-03-23 10:51:00 +01:00
|
|
|
|
2011-05-20 01:29:40 +02:00
|
|
|
/**
|
|
|
|
* @var array
|
|
|
|
*/
|
2016-02-22 02:13:35 +01:00
|
|
|
private static $allowed_actions = [
|
2011-03-23 10:51:00 +01:00
|
|
|
'index',
|
2011-06-09 03:49:52 +02:00
|
|
|
'save',
|
2011-03-23 10:51:00 +01:00
|
|
|
'savetreenode',
|
|
|
|
'getsubtree',
|
2012-07-17 15:04:27 +02:00
|
|
|
'updatetreenodes',
|
2011-03-23 10:51:00 +01:00
|
|
|
'printable',
|
|
|
|
'show',
|
|
|
|
'EditorToolbar',
|
|
|
|
'EditForm',
|
|
|
|
'AddForm',
|
|
|
|
'batchactions',
|
|
|
|
'BatchActionsForm',
|
2016-02-22 02:13:35 +01:00
|
|
|
'schema',
|
|
|
|
];
|
|
|
|
|
|
|
|
private static $dependencies = [
|
|
|
|
'schema' => '%$FormSchema'
|
|
|
|
];
|
2012-03-05 16:07:20 +01:00
|
|
|
|
|
|
|
/**
|
2013-03-21 19:48:54 +01:00
|
|
|
* @config
|
2012-03-05 16:07:20 +01:00
|
|
|
* @var Array Codes which are required from the current user to view this controller.
|
|
|
|
* If multiple codes are provided, all of them are required.
|
|
|
|
* All CMS controllers require "CMS_ACCESS_LeftAndMain" as a baseline check,
|
|
|
|
* and fall back to "CMS_ACCESS_<class>" if no permissions are defined here.
|
|
|
|
* See {@link canView()} for more details on permission checks.
|
|
|
|
*/
|
2013-03-21 19:48:54 +01:00
|
|
|
private static $required_permission_codes;
|
2012-08-28 00:25:58 +02:00
|
|
|
|
|
|
|
/**
|
2013-03-21 19:48:54 +01:00
|
|
|
* @config
|
2012-08-28 00:25:58 +02:00
|
|
|
* @var String Namespace for session info, e.g. current record.
|
|
|
|
* Defaults to the current class name, but can be amended to share a namespace in case
|
|
|
|
* controllers are logically bundled together, and mainly separated
|
|
|
|
* to achieve more flexible templating.
|
|
|
|
*/
|
2013-03-21 19:48:54 +01:00
|
|
|
private static $session_namespace;
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2011-03-23 10:51:00 +01:00
|
|
|
/**
|
2011-05-20 01:29:40 +02:00
|
|
|
* Register additional requirements through the {@link Requirements} class.
|
2011-03-23 10:51:00 +01:00
|
|
|
* Used mainly to work around the missing "lazy loading" functionality
|
|
|
|
* for getting css/javascript required after an ajax-call (e.g. loading the editform).
|
|
|
|
*
|
2013-04-05 15:34:29 +02:00
|
|
|
* YAML configuration example:
|
|
|
|
* <code>
|
|
|
|
* LeftAndMain:
|
|
|
|
* extra_requirements_javascript:
|
|
|
|
* mysite/javascript/myscript.js:
|
|
|
|
* </code>
|
|
|
|
*
|
2013-03-21 19:48:54 +01:00
|
|
|
* @config
|
|
|
|
* @var array
|
2011-03-23 10:51:00 +01:00
|
|
|
*/
|
2013-03-21 19:48:54 +01:00
|
|
|
private static $extra_requirements_javascript = array();
|
|
|
|
|
|
|
|
/**
|
2013-04-05 15:34:29 +02:00
|
|
|
* YAML configuration example:
|
|
|
|
* <code>
|
|
|
|
* LeftAndMain:
|
|
|
|
* extra_requirements_css:
|
|
|
|
* mysite/css/mystyle.css:
|
|
|
|
* media: screen
|
|
|
|
* </code>
|
2014-08-15 08:53:05 +02:00
|
|
|
*
|
2013-03-21 19:48:54 +01:00
|
|
|
* @config
|
|
|
|
* @var array See {@link extra_requirements_javascript}
|
|
|
|
*/
|
|
|
|
private static $extra_requirements_css = array();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @config
|
|
|
|
* @var array See {@link extra_requirements_javascript}
|
|
|
|
*/
|
|
|
|
private static $extra_requirements_themedCss = array();
|
2012-03-24 03:19:02 +01:00
|
|
|
|
2013-05-31 06:27:30 +02:00
|
|
|
/**
|
|
|
|
* If true, call a keepalive ping every 5 minutes from the CMS interface,
|
|
|
|
* to ensure that the session never dies.
|
2014-08-15 08:53:05 +02:00
|
|
|
*
|
2013-05-31 06:27:30 +02:00
|
|
|
* @config
|
|
|
|
* @var boolean
|
|
|
|
*/
|
|
|
|
private static $session_keepalive_ping = true;
|
|
|
|
|
2012-03-24 03:19:02 +01:00
|
|
|
/**
|
2012-05-18 07:36:06 +02:00
|
|
|
* @var PjaxResponseNegotiator
|
2012-03-24 03:19:02 +01:00
|
|
|
*/
|
|
|
|
protected $responseNegotiator;
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2016-02-22 02:13:35 +01:00
|
|
|
/**
|
|
|
|
* Gets a JSON schema representing the current edit form.
|
|
|
|
*
|
2016-03-03 00:03:38 +01:00
|
|
|
* WARNING: Experimental API.
|
|
|
|
*
|
2016-02-22 02:13:35 +01:00
|
|
|
* @return SS_HTTPResponse
|
|
|
|
*/
|
2016-03-03 00:03:38 +01:00
|
|
|
public function schema($request) {
|
|
|
|
$response = $this->getResponse();
|
|
|
|
$formName = $request->param('ID');
|
|
|
|
|
|
|
|
if(!$this->hasMethod("get{$formName}")) {
|
|
|
|
throw new SS_HTTPResponse_Exception(
|
|
|
|
'Form not found',
|
|
|
|
400
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!$this->hasAction($formName)) {
|
|
|
|
throw new SS_HTTPResponse_Exception(
|
|
|
|
'Form not accessible',
|
|
|
|
401
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
$form = $this->{"get{$formName}"}();
|
|
|
|
$response->addHeader('Content-Type', 'application/json');
|
|
|
|
$response->setBody(Convert::raw2json($this->getSchemaForForm($form)));
|
|
|
|
|
|
|
|
return $response;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a representation of the provided {@link Form} as structured data,
|
|
|
|
* based on the request data.
|
|
|
|
*
|
|
|
|
* @param Form $form
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
protected function getSchemaForForm(Form $form) {
|
|
|
|
$request = $this->getRequest();
|
2016-02-29 01:50:59 +01:00
|
|
|
$schemaParts = [];
|
2016-03-03 00:03:38 +01:00
|
|
|
$return = null;
|
2016-02-29 01:50:59 +01:00
|
|
|
|
|
|
|
// Valid values for the "X-Formschema-Request" header are "schema" and "state".
|
|
|
|
// If either of these values are set they will be stored in the $schemaParst array
|
|
|
|
// and used to construct the response body.
|
2016-03-03 00:03:38 +01:00
|
|
|
if ($schemaHeader = $request->getHeader('X-Formschema-Request')) {
|
2016-02-29 01:50:59 +01:00
|
|
|
$schemaParts = array_filter(explode(',', $schemaHeader), function($value) {
|
|
|
|
$validHeaderValues = ['schema', 'state'];
|
|
|
|
return in_array(trim($value), $validHeaderValues);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-03-03 00:03:38 +01:00
|
|
|
if (!count($schemaParts)) {
|
2016-02-29 01:50:59 +01:00
|
|
|
throw new SS_HTTPResponse_Exception(
|
|
|
|
'Invalid request. Check you\'ve set a "X-Formschema-Request" header with "schema" or "state" values.',
|
|
|
|
400
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-03-03 00:03:38 +01:00
|
|
|
$return = ['id' => $form->getName()];
|
2016-02-29 01:50:59 +01:00
|
|
|
|
|
|
|
if (in_array('schema', $schemaParts)) {
|
2016-03-03 00:03:38 +01:00
|
|
|
$return['schema'] = $this->schema->getSchema($form);
|
2016-02-29 01:50:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (in_array('state', $schemaParts)) {
|
2016-03-03 00:03:38 +01:00
|
|
|
$return['state'] = $this->schema->getState($form);
|
2016-02-29 01:50:59 +01:00
|
|
|
}
|
|
|
|
|
2016-03-03 00:03:38 +01:00
|
|
|
return $return;
|
2016-02-22 02:13:35 +01:00
|
|
|
}
|
|
|
|
|
2011-03-23 10:51:00 +01:00
|
|
|
/**
|
|
|
|
* @param Member $member
|
|
|
|
* @return boolean
|
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public function canView($member = null) {
|
2012-03-05 16:07:20 +01:00
|
|
|
if(!$member && $member !== FALSE) $member = Member::currentUser();
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2011-03-23 10:51:00 +01:00
|
|
|
// cms menus only for logged-in members
|
|
|
|
if(!$member) return false;
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2011-04-15 11:35:30 +02:00
|
|
|
// alternative extended checks
|
2011-03-23 10:51:00 +01:00
|
|
|
if($this->hasMethod('alternateAccessCheck')) {
|
|
|
|
$alternateAllowed = $this->alternateAccessCheck();
|
|
|
|
if($alternateAllowed === FALSE) return false;
|
|
|
|
}
|
2012-03-05 16:07:20 +01:00
|
|
|
|
|
|
|
// Check for "CMS admin" permission
|
|
|
|
if(Permission::checkMember($member, "CMS_ACCESS_LeftAndMain")) return true;
|
|
|
|
|
2014-08-15 08:53:05 +02:00
|
|
|
// Check for LeftAndMain sub-class permissions
|
2012-03-05 16:07:20 +01:00
|
|
|
$codes = array();
|
|
|
|
$extraCodes = $this->stat('required_permission_codes');
|
|
|
|
if($extraCodes !== false) { // allow explicit FALSE to disable subclass check
|
|
|
|
if($extraCodes) $codes = array_merge($codes, (array)$extraCodes);
|
2014-08-15 08:53:05 +02:00
|
|
|
else $codes[] = "CMS_ACCESS_$this->class";
|
2011-03-23 10:51:00 +01:00
|
|
|
}
|
2012-03-05 16:07:20 +01:00
|
|
|
foreach($codes as $code) if(!Permission::checkMember($member, $code)) return false;
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2011-03-23 10:51:00 +01:00
|
|
|
return true;
|
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2011-03-23 10:51:00 +01:00
|
|
|
/**
|
2011-04-15 11:35:30 +02:00
|
|
|
* @uses LeftAndMainExtension->init()
|
|
|
|
* @uses LeftAndMainExtension->accessedCMS()
|
2011-03-23 10:51:00 +01:00
|
|
|
* @uses CMSMenu
|
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public function init() {
|
2011-03-23 10:51:00 +01:00
|
|
|
parent::init();
|
|
|
|
|
2014-08-15 08:53:05 +02:00
|
|
|
Config::inst()->update('SSViewer', 'rewrite_hash_links', false);
|
2013-05-08 23:45:42 +02:00
|
|
|
Config::inst()->update('ContentNegotiator', 'enabled', false);
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2011-03-23 10:51:00 +01:00
|
|
|
// set language
|
|
|
|
$member = Member::currentUser();
|
|
|
|
if(!empty($member->Locale)) i18n::set_locale($member->Locale);
|
2013-03-21 19:48:54 +01:00
|
|
|
if(!empty($member->DateFormat)) i18n::config()->date_format = $member->DateFormat;
|
|
|
|
if(!empty($member->TimeFormat)) i18n::config()->time_format = $member->TimeFormat;
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2011-03-23 10:51:00 +01:00
|
|
|
// can't be done in cms/_config.php as locale is not set yet
|
|
|
|
CMSMenu::add_link(
|
2014-08-15 08:53:05 +02:00
|
|
|
'Help',
|
|
|
|
_t('LeftAndMain.HELP', 'Help', 'Menu title'),
|
2013-04-09 12:20:20 +02:00
|
|
|
$this->config()->help_link,
|
2013-10-02 08:06:54 +02:00
|
|
|
-2,
|
|
|
|
array(
|
|
|
|
'target' => '_blank'
|
|
|
|
)
|
2011-03-23 10:51:00 +01:00
|
|
|
);
|
|
|
|
|
2011-04-15 11:35:30 +02:00
|
|
|
// Allow customisation of the access check by a extension
|
2012-05-23 11:50:02 +02:00
|
|
|
// Also all the canView() check to execute Controller::redirect()
|
2015-08-14 02:39:33 +02:00
|
|
|
if(!$this->canView() && !$this->getResponse()->isFinished()) {
|
2011-03-23 10:51:00 +01:00
|
|
|
// When access /admin/, we should try a redirect to another part of the admin rather than be locked out
|
|
|
|
$menu = $this->MainMenu();
|
|
|
|
foreach($menu as $candidate) {
|
|
|
|
if(
|
2014-08-15 08:53:05 +02:00
|
|
|
$candidate->Link &&
|
|
|
|
$candidate->Link != $this->Link()
|
|
|
|
&& $candidate->MenuItem->controller
|
2011-03-23 10:51:00 +01:00
|
|
|
&& singleton($candidate->MenuItem->controller)->canView()
|
|
|
|
) {
|
2012-05-23 11:50:02 +02:00
|
|
|
return $this->redirect($candidate->Link);
|
2011-03-23 10:51:00 +01:00
|
|
|
}
|
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2011-03-23 10:51:00 +01:00
|
|
|
if(Member::currentUser()) {
|
|
|
|
Session::set("BackURL", null);
|
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2011-03-23 10:51:00 +01:00
|
|
|
// if no alternate menu items have matched, return a permission error
|
|
|
|
$messageSet = array(
|
2015-08-17 12:43:28 +02:00
|
|
|
'default' => _t(
|
|
|
|
'LeftAndMain.PERMDEFAULT',
|
|
|
|
"You must be logged in to access the administration area; please enter your credentials below."
|
|
|
|
),
|
|
|
|
'alreadyLoggedIn' => _t(
|
|
|
|
'LeftAndMain.PERMALREADY',
|
2012-09-26 23:34:00 +02:00
|
|
|
"I'm sorry, but you can't access that part of the CMS. If you want to log in as someone else, do"
|
2015-08-17 12:43:28 +02:00
|
|
|
. " so below."
|
|
|
|
),
|
|
|
|
'logInAgain' => _t(
|
|
|
|
'LeftAndMain.PERMAGAIN',
|
2012-09-26 23:34:00 +02:00
|
|
|
"You have been logged out of the CMS. If you would like to log in again, enter a username and"
|
2015-08-17 12:43:28 +02:00
|
|
|
. " password below."
|
|
|
|
),
|
2011-03-23 10:51:00 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
return Security::permissionFailure($this, $messageSet);
|
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2011-03-23 10:51:00 +01:00
|
|
|
// Don't continue if there's already been a redirection request.
|
2012-05-23 11:50:02 +02:00
|
|
|
if($this->redirectedTo()) return;
|
2011-03-23 10:51:00 +01:00
|
|
|
|
|
|
|
// Audit logging hook
|
2015-04-30 01:04:08 +02:00
|
|
|
if(empty($_REQUEST['executeForm']) && !$this->getRequest()->isAjax()) $this->extend('accessedCMS');
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2011-12-12 23:41:49 +01:00
|
|
|
// Set the members html editor config
|
2014-07-17 04:45:22 +02:00
|
|
|
if(Member::currentUser()) {
|
2016-02-12 04:00:15 +01:00
|
|
|
HtmlEditorConfig::set_active_identifier(Member::currentUser()->getHtmlEditorConfigForCMS());
|
2014-07-17 04:45:22 +02:00
|
|
|
}
|
|
|
|
|
2011-12-13 14:56:35 +01:00
|
|
|
// Set default values in the config if missing. These things can't be defined in the config
|
|
|
|
// file because insufficient information exists when that is being processed
|
|
|
|
$htmlEditorConfig = HtmlEditorConfig::get_active();
|
|
|
|
$htmlEditorConfig->setOption('language', i18n::get_tinymce_lang());
|
|
|
|
if(!$htmlEditorConfig->getOption('content_css')) {
|
|
|
|
$cssFiles = array();
|
2012-03-24 04:38:57 +01:00
|
|
|
$cssFiles[] = FRAMEWORK_ADMIN_DIR . '/css/editor.css';
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2011-12-13 14:56:35 +01:00
|
|
|
// Use theme from the site config
|
|
|
|
if(class_exists('SiteConfig') && ($config = SiteConfig::current_site_config()) && $config->Theme) {
|
|
|
|
$theme = $config->Theme;
|
2013-03-27 10:13:24 +01:00
|
|
|
} elseif(Config::inst()->get('SSViewer', 'theme_enabled') && Config::inst()->get('SSViewer', 'theme')) {
|
2013-03-21 19:48:54 +01:00
|
|
|
$theme = Config::inst()->get('SSViewer', 'theme');
|
2011-12-13 14:56:35 +01:00
|
|
|
} else {
|
|
|
|
$theme = false;
|
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2011-12-13 14:56:35 +01:00
|
|
|
if($theme) $cssFiles[] = THEMES_DIR . "/{$theme}/css/editor.css";
|
|
|
|
else if(project()) $cssFiles[] = project() . '/css/editor.css';
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2011-12-13 14:56:35 +01:00
|
|
|
// Remove files that don't exist
|
|
|
|
foreach($cssFiles as $k => $cssFile) {
|
|
|
|
if(!file_exists(BASE_PATH . '/' . $cssFile)) unset($cssFiles[$k]);
|
|
|
|
}
|
|
|
|
|
|
|
|
$htmlEditorConfig->setOption('content_css', implode(',', $cssFiles));
|
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2016-01-11 02:25:30 +01:00
|
|
|
Requirements::javascript(FRAMEWORK_ADMIN_DIR . '/javascript/dist/bundle-lib.js', [
|
|
|
|
'provides' => [
|
2011-04-25 11:24:55 +02:00
|
|
|
THIRDPARTY_DIR . '/jquery/jquery.js',
|
|
|
|
THIRDPARTY_DIR . '/jquery-ui/jquery-ui.js',
|
|
|
|
THIRDPARTY_DIR . '/json-js/json2.js',
|
|
|
|
THIRDPARTY_DIR . '/jquery-entwine/dist/jquery.entwine-dist.js',
|
|
|
|
THIRDPARTY_DIR . '/jquery-cookie/jquery.cookie.js',
|
2011-07-15 10:35:41 +02:00
|
|
|
THIRDPARTY_DIR . '/jquery-query/jquery.query.js',
|
2012-03-02 13:42:15 +01:00
|
|
|
THIRDPARTY_DIR . '/jquery-form/jquery.form.js',
|
2016-01-11 02:25:30 +01:00
|
|
|
THIRDPARTY_DIR . '/jquery-ondemand/jquery.ondemand.js',
|
|
|
|
THIRDPARTY_DIR . '/jquery-changetracker/lib/jquery.changetracker.js',
|
|
|
|
THIRDPARTY_DIR . '/jstree/jquery.jstree.js',
|
2012-03-24 04:38:57 +01:00
|
|
|
FRAMEWORK_ADMIN_DIR . '/thirdparty/jquery-notice/jquery.notice.js',
|
|
|
|
FRAMEWORK_ADMIN_DIR . '/thirdparty/jsizes/lib/jquery.sizes.js',
|
|
|
|
FRAMEWORK_ADMIN_DIR . '/thirdparty/jlayout/lib/jlayout.border.js',
|
|
|
|
FRAMEWORK_ADMIN_DIR . '/thirdparty/jlayout/lib/jquery.jlayout.js',
|
|
|
|
FRAMEWORK_ADMIN_DIR . '/thirdparty/history-js/scripts/uncompressed/history.js',
|
|
|
|
FRAMEWORK_ADMIN_DIR . '/thirdparty/history-js/scripts/uncompressed/history.adapter.jquery.js',
|
|
|
|
FRAMEWORK_ADMIN_DIR . '/thirdparty/history-js/scripts/uncompressed/history.html4.js',
|
|
|
|
FRAMEWORK_ADMIN_DIR . '/thirdparty/chosen/chosen/chosen.jquery.js',
|
|
|
|
FRAMEWORK_ADMIN_DIR . '/thirdparty/jquery-hoverIntent/jquery.hoverIntent.js',
|
2016-01-11 02:25:30 +01:00
|
|
|
FRAMEWORK_DIR . '/javascript/dist/TreeDropdownField.js',
|
|
|
|
FRAMEWORK_DIR . '/javascript/dist/DateField.js',
|
|
|
|
FRAMEWORK_DIR . '/javascript/dist/HtmlEditorField.js',
|
|
|
|
FRAMEWORK_DIR . '/javascript/dist/TabSet.js',
|
|
|
|
FRAMEWORK_DIR . '/javascript/dist/GridField.js',
|
|
|
|
FRAMEWORK_DIR . '/javascript/dist/i18n.js',
|
|
|
|
FRAMEWORK_ADMIN_DIR . '/javascript/dist/sspath.js',
|
|
|
|
FRAMEWORK_ADMIN_DIR . '/javascript/dist/ssui.core.js',
|
|
|
|
]
|
|
|
|
]);
|
|
|
|
|
|
|
|
Requirements::javascript(FRAMEWORK_ADMIN_DIR . '/javascript/dist/bundle-leftandmain.js', [
|
|
|
|
'provides' => [
|
|
|
|
FRAMEWORK_ADMIN_DIR . '/javascript/dist/LeftAndMain.Layout.js',
|
|
|
|
FRAMEWORK_ADMIN_DIR . '/javascript/dist/LeftAndMain.js',
|
|
|
|
FRAMEWORK_ADMIN_DIR . '/javascript/dist/LeftAndMain.ActionTabSet.js',
|
|
|
|
FRAMEWORK_ADMIN_DIR . '/javascript/dist/LeftAndMain.Panel.js',
|
|
|
|
FRAMEWORK_ADMIN_DIR . '/javascript/dist/LeftAndMain.Tree.js',
|
|
|
|
FRAMEWORK_ADMIN_DIR . '/javascript/dist/LeftAndMain.Content.js',
|
|
|
|
FRAMEWORK_ADMIN_DIR . '/javascript/dist/LeftAndMain.EditForm.js',
|
|
|
|
FRAMEWORK_ADMIN_DIR . '/javascript/dist/LeftAndMain.Menu.js',
|
|
|
|
FRAMEWORK_ADMIN_DIR . '/javascript/dist/LeftAndMain.Preview.js',
|
|
|
|
FRAMEWORK_ADMIN_DIR . '/javascript/dist/LeftAndMain.BatchActions.js',
|
|
|
|
FRAMEWORK_ADMIN_DIR . '/javascript/dist/LeftAndMain.FieldHelp.js',
|
|
|
|
FRAMEWORK_ADMIN_DIR . '/javascript/dist/LeftAndMain.FieldDescriptionToggle.js',
|
|
|
|
FRAMEWORK_ADMIN_DIR . '/javascript/dist/LeftAndMain.TreeDropdownField.js'
|
|
|
|
]
|
|
|
|
]);
|
|
|
|
|
2016-02-12 04:00:15 +01:00
|
|
|
Requirements::add_i18n_javascript(FRAMEWORK_DIR . '/javascript/lang', false, true);
|
|
|
|
Requirements::add_i18n_javascript(FRAMEWORK_ADMIN_DIR . '/javascript/lang', false, true);
|
2016-01-11 02:25:30 +01:00
|
|
|
|
|
|
|
if ($this->config()->session_keepalive_ping) {
|
|
|
|
Requirements::javascript(FRAMEWORK_ADMIN_DIR . '/javascript/dist/LeftAndMain.Ping.js');
|
2013-05-31 06:27:30 +02:00
|
|
|
}
|
|
|
|
|
2012-08-16 01:55:44 +02:00
|
|
|
if (Director::isDev()) {
|
2016-01-11 02:25:30 +01:00
|
|
|
// TODO Confuses jQuery.ondemand through document.write()
|
2012-08-16 01:55:44 +02:00
|
|
|
Requirements::javascript(THIRDPARTY_DIR . '/jquery-entwine/src/jquery.entwine.inspector.js');
|
2016-01-11 02:25:30 +01:00
|
|
|
Requirements::javascript(FRAMEWORK_ADMIN_DIR . '/javascript/dist/leaktools.js');
|
2012-08-16 01:55:44 +02:00
|
|
|
}
|
2012-05-14 06:00:42 +02:00
|
|
|
|
2012-03-24 04:38:57 +01:00
|
|
|
Requirements::css(FRAMEWORK_ADMIN_DIR . '/thirdparty/jquery-notice/jquery.notice.css');
|
2012-01-06 10:46:27 +01:00
|
|
|
Requirements::css(THIRDPARTY_DIR . '/jquery-ui-themes/smoothness/jquery-ui.css');
|
2012-03-24 04:38:57 +01:00
|
|
|
Requirements::css(FRAMEWORK_ADMIN_DIR .'/thirdparty/chosen/chosen/chosen.css');
|
2012-01-06 10:46:27 +01:00
|
|
|
Requirements::css(THIRDPARTY_DIR . '/jstree/themes/apple/style.css');
|
2012-03-24 04:38:57 +01:00
|
|
|
Requirements::css(FRAMEWORK_DIR . '/css/TreeDropdownField.css');
|
|
|
|
Requirements::css(FRAMEWORK_ADMIN_DIR . '/css/screen.css');
|
|
|
|
Requirements::css(FRAMEWORK_DIR . '/css/GridField.css');
|
2012-01-03 14:49:35 +01:00
|
|
|
|
|
|
|
// Browser-specific requirements
|
|
|
|
$ie = isset($_SERVER['HTTP_USER_AGENT']) ? strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') : false;
|
|
|
|
if($ie) {
|
|
|
|
$version = substr($_SERVER['HTTP_USER_AGENT'], $ie + 5, 3);
|
2013-06-02 03:37:34 +02:00
|
|
|
|
|
|
|
if($version == 7) {
|
|
|
|
Requirements::css(FRAMEWORK_ADMIN_DIR . '/css/ie7.css');
|
|
|
|
} else if($version == 8) {
|
|
|
|
Requirements::css(FRAMEWORK_ADMIN_DIR . '/css/ie8.css');
|
|
|
|
}
|
2012-01-03 14:49:35 +01:00
|
|
|
}
|
|
|
|
|
2012-05-23 07:15:17 +02:00
|
|
|
// Custom requirements
|
2013-03-21 19:48:54 +01:00
|
|
|
$extraJs = $this->stat('extra_requirements_javascript');
|
|
|
|
|
2013-06-02 03:37:34 +02:00
|
|
|
if($extraJs) {
|
|
|
|
foreach($extraJs as $file => $config) {
|
|
|
|
if(is_numeric($file)) {
|
|
|
|
$file = $config;
|
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2013-06-02 03:37:34 +02:00
|
|
|
Requirements::javascript($file);
|
|
|
|
}
|
2011-10-11 09:55:58 +02:00
|
|
|
}
|
2013-06-02 03:37:34 +02:00
|
|
|
|
2013-03-21 19:48:54 +01:00
|
|
|
$extraCss = $this->stat('extra_requirements_css');
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2013-06-02 03:37:34 +02:00
|
|
|
if($extraCss) {
|
|
|
|
foreach($extraCss as $file => $config) {
|
|
|
|
if(is_numeric($file)) {
|
|
|
|
$file = $config;
|
|
|
|
$config = array();
|
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2013-06-02 03:37:34 +02:00
|
|
|
Requirements::css($file, isset($config['media']) ? $config['media'] : null);
|
|
|
|
}
|
2011-10-11 09:55:58 +02:00
|
|
|
}
|
2013-06-02 03:37:34 +02:00
|
|
|
|
2013-05-28 16:48:23 +02:00
|
|
|
$extraThemedCss = $this->stat('extra_requirements_themedCss');
|
2013-06-02 03:37:34 +02:00
|
|
|
|
|
|
|
if($extraThemedCss) {
|
|
|
|
foreach ($extraThemedCss as $file => $config) {
|
|
|
|
if(is_numeric($file)) {
|
|
|
|
$file = $config;
|
|
|
|
$config = array();
|
|
|
|
}
|
|
|
|
|
|
|
|
Requirements::themedCSS($file, isset($config['media']) ? $config['media'] : null);
|
|
|
|
}
|
2011-10-11 09:55:58 +02:00
|
|
|
}
|
2011-03-23 10:51:00 +01:00
|
|
|
|
|
|
|
$dummy = null;
|
|
|
|
$this->extend('init', $dummy);
|
|
|
|
|
2014-08-15 08:53:05 +02:00
|
|
|
// The user's theme shouldn't affect the CMS, if, for example, they have
|
2013-06-02 03:37:34 +02:00
|
|
|
// replaced TableListField.ss or Form.ss.
|
2013-03-27 10:13:24 +01:00
|
|
|
Config::inst()->update('SSViewer', 'theme_enabled', false);
|
2014-08-26 12:09:03 +02:00
|
|
|
|
|
|
|
//set the reading mode for the admin to stage
|
2014-08-26 12:09:03 +02:00
|
|
|
Versioned::reading_stage('Stage');
|
2011-03-23 10:51:00 +01:00
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function handleRequest(SS_HTTPRequest $request, DataModel $model = null) {
|
2013-03-08 12:50:27 +01:00
|
|
|
try {
|
|
|
|
$response = parent::handleRequest($request, $model);
|
|
|
|
} catch(ValidationException $e) {
|
|
|
|
// Nicer presentation of model-level validation errors
|
2014-08-15 08:53:05 +02:00
|
|
|
$msgs = _t('LeftAndMain.ValidationError', 'Validation error') . ': '
|
2013-03-19 14:02:28 +01:00
|
|
|
. $e->getMessage();
|
2013-03-08 12:50:27 +01:00
|
|
|
$e = new SS_HTTPResponse_Exception($msgs, 403);
|
2015-08-14 02:39:33 +02:00
|
|
|
$errorResponse = $e->getResponse();
|
|
|
|
$errorResponse->addHeader('Content-Type', 'text/plain');
|
|
|
|
$errorResponse->addHeader('X-Status', rawurlencode($msgs));
|
|
|
|
$e->setResponse($errorResponse);
|
2013-03-08 12:50:27 +01:00
|
|
|
throw $e;
|
|
|
|
}
|
|
|
|
|
2012-08-26 23:13:42 +02:00
|
|
|
$title = $this->Title();
|
2011-12-20 17:06:11 +01:00
|
|
|
if(!$response->getHeader('X-Controller')) $response->addHeader('X-Controller', $this->class);
|
2012-12-17 10:41:07 +01:00
|
|
|
if(!$response->getHeader('X-Title')) $response->addHeader('X-Title', urlencode($title));
|
2013-07-11 10:29:21 +02:00
|
|
|
|
|
|
|
// Prevent clickjacking, see https://developer.mozilla.org/en-US/docs/HTTP/X-Frame-Options
|
2015-08-14 02:39:33 +02:00
|
|
|
$originalResponse = $this->getResponse();
|
|
|
|
$originalResponse->addHeader('X-Frame-Options', 'SAMEORIGIN');
|
|
|
|
$originalResponse->addHeader('Vary', 'X-Requested-With');
|
|
|
|
|
2011-06-09 03:49:52 +02:00
|
|
|
return $response;
|
|
|
|
}
|
|
|
|
|
2012-03-24 03:19:02 +01:00
|
|
|
/**
|
|
|
|
* Overloaded redirection logic to trigger a fake redirect on ajax requests.
|
|
|
|
* While this violates HTTP principles, its the only way to work around the
|
|
|
|
* fact that browsers handle HTTP redirects opaquely, no intervention via JS is possible.
|
|
|
|
* In isolation, that's not a problem - but combined with history.pushState()
|
|
|
|
* it means we would request the same redirection URL twice if we want to update the URL as well.
|
|
|
|
* See LeftAndMain.js for the required jQuery ajaxComplete handlers.
|
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public function redirect($url, $code=302) {
|
2015-04-30 01:04:08 +02:00
|
|
|
if($this->getRequest()->isAjax()) {
|
2015-08-14 02:39:33 +02:00
|
|
|
$response = $this->getResponse();
|
|
|
|
$response->addHeader('X-ControllerURL', $url);
|
|
|
|
if($this->getRequest()->getHeader('X-Pjax') && !$response->getHeader('X-Pjax')) {
|
|
|
|
$response->addHeader('X-Pjax', $this->getRequest()->getHeader('X-Pjax'));
|
2012-06-14 20:20:29 +02:00
|
|
|
}
|
2012-07-16 23:30:59 +02:00
|
|
|
$newResponse = new LeftAndMain_HTTPResponse(
|
2015-08-14 02:39:33 +02:00
|
|
|
$response->getBody(),
|
|
|
|
$response->getStatusCode(),
|
|
|
|
$response->getStatusDescription()
|
2012-07-16 23:30:59 +02:00
|
|
|
);
|
2015-08-14 02:39:33 +02:00
|
|
|
foreach($response->getHeaders() as $k => $v) {
|
2012-07-16 23:30:59 +02:00
|
|
|
$newResponse->addHeader($k, $v);
|
|
|
|
}
|
|
|
|
$newResponse->setIsFinished(true);
|
2015-08-14 02:39:33 +02:00
|
|
|
$this->setResponse($newResponse);
|
2012-03-24 03:19:02 +01:00
|
|
|
return ''; // Actual response will be re-requested by client
|
|
|
|
} else {
|
|
|
|
parent::redirect($url, $code);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function index($request) {
|
2012-03-24 03:19:02 +01:00
|
|
|
return $this->getResponseNegotiator()->respond($request);
|
2011-06-09 03:49:52 +02:00
|
|
|
}
|
2011-03-23 10:51:00 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* If this is set to true, the "switchView" context in the
|
|
|
|
* template is shown, with links to the staging and publish site.
|
|
|
|
*
|
|
|
|
* @return boolean
|
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public function ShowSwitchView() {
|
2011-03-23 10:51:00 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2011-03-23 10:51:00 +01:00
|
|
|
//------------------------------------------------------------------------------------------//
|
|
|
|
// Main controllers
|
|
|
|
|
|
|
|
/**
|
|
|
|
* You should implement a Link() function in your subclass of LeftAndMain,
|
|
|
|
* to point to the URL of that particular controller.
|
2014-08-15 08:53:05 +02:00
|
|
|
*
|
2011-03-23 10:51:00 +01:00
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function Link($action = null) {
|
|
|
|
// Handle missing url_segments
|
2013-03-21 19:48:54 +01:00
|
|
|
if($this->config()->url_segment) {
|
|
|
|
$segment = $this->config()->get('url_segment', Config::FIRST_SET);
|
|
|
|
} else {
|
|
|
|
$segment = $this->class;
|
|
|
|
};
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2012-05-15 21:27:32 +02:00
|
|
|
$link = Controller::join_links(
|
2011-03-23 10:51:00 +01:00
|
|
|
$this->stat('url_base', true),
|
2013-03-21 19:48:54 +01:00
|
|
|
$segment,
|
2011-03-23 10:51:00 +01:00
|
|
|
'/', // trailing slash needed if $action is null!
|
|
|
|
"$action"
|
|
|
|
);
|
2012-05-15 21:27:32 +02:00
|
|
|
$this->extend('updateLink', $link);
|
|
|
|
return $link;
|
2011-03-23 10:51:00 +01:00
|
|
|
}
|
2012-03-12 13:41:22 +01:00
|
|
|
|
2011-03-23 10:51:00 +01:00
|
|
|
/**
|
|
|
|
* Returns the menu title for the given LeftAndMain subclass.
|
|
|
|
* Implemented static so that we can get this value without instantiating an object.
|
|
|
|
* Menu title is *not* internationalised.
|
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public static function menu_title_for_class($class) {
|
2012-04-16 01:04:55 +02:00
|
|
|
$title = Config::inst()->get($class, 'menu_title', Config::FIRST_SET);
|
2011-03-23 10:51:00 +01:00
|
|
|
if(!$title) $title = preg_replace('/Admin$/', '', $class);
|
|
|
|
return $title;
|
|
|
|
}
|
2012-08-19 14:14:41 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return styling for the menu icon, if a custom icon is set for this class
|
|
|
|
*
|
|
|
|
* Example: static $menu-icon = '/path/to/image/';
|
2013-06-21 00:32:08 +02:00
|
|
|
* @param string $class
|
2012-08-19 14:14:41 +02:00
|
|
|
* @return string
|
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public static function menu_icon_for_class($class) {
|
2012-08-19 14:14:41 +02:00
|
|
|
$icon = Config::inst()->get($class, 'menu_icon', Config::FIRST_SET);
|
|
|
|
if (!empty($icon)) {
|
2015-07-15 16:33:00 +02:00
|
|
|
$class = strtolower(Convert::raw2htmlname(str_replace('\\', '-', $class)));
|
2015-08-07 03:22:57 +02:00
|
|
|
return ".icon.icon-16.icon-{$class} { background-image: url('{$icon}'); } ";
|
2012-08-19 14:14:41 +02:00
|
|
|
}
|
|
|
|
return '';
|
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2011-03-23 10:51:00 +01:00
|
|
|
public function show($request) {
|
|
|
|
// TODO Necessary for TableListField URLs to work properly
|
|
|
|
if($request->param('ID')) $this->setCurrentPageID($request->param('ID'));
|
2012-03-24 03:19:02 +01:00
|
|
|
return $this->getResponseNegotiator()->respond($request);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Caution: Volatile API.
|
2014-08-15 08:53:05 +02:00
|
|
|
*
|
2012-05-18 07:36:06 +02:00
|
|
|
* @return PjaxResponseNegotiator
|
2012-03-24 03:19:02 +01:00
|
|
|
*/
|
2012-05-08 07:40:05 +02:00
|
|
|
public function getResponseNegotiator() {
|
2012-03-24 03:19:02 +01:00
|
|
|
if(!$this->responseNegotiator) {
|
|
|
|
$controller = $this;
|
2012-06-13 00:27:03 +02:00
|
|
|
$this->responseNegotiator = new PjaxResponseNegotiator(
|
|
|
|
array(
|
|
|
|
'CurrentForm' => function() use(&$controller) {
|
|
|
|
return $controller->getEditForm()->forTemplate();
|
|
|
|
},
|
|
|
|
'Content' => function() use(&$controller) {
|
|
|
|
return $controller->renderWith($controller->getTemplatesWithSuffix('_Content'));
|
|
|
|
},
|
|
|
|
'Breadcrumbs' => function() use (&$controller) {
|
|
|
|
return $controller->renderWith('CMSBreadcrumbs');
|
|
|
|
},
|
|
|
|
'default' => function() use(&$controller) {
|
|
|
|
return $controller->renderWith($controller->getViewer('show'));
|
|
|
|
}
|
|
|
|
),
|
2015-08-14 02:39:33 +02:00
|
|
|
$this->getResponse()
|
2012-06-13 00:27:03 +02:00
|
|
|
);
|
2011-03-23 10:51:00 +01:00
|
|
|
}
|
2012-03-24 03:19:02 +01:00
|
|
|
return $this->responseNegotiator;
|
2011-03-23 10:51:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------------------//
|
|
|
|
// Main UI components
|
|
|
|
|
|
|
|
/**
|
2014-08-15 08:53:05 +02:00
|
|
|
* Returns the main menu of the CMS. This is also used by init()
|
2011-03-23 10:51:00 +01:00
|
|
|
* to work out which sections the user has access to.
|
2014-08-15 08:53:05 +02:00
|
|
|
*
|
2012-05-03 13:49:19 +02:00
|
|
|
* @param Boolean
|
2011-10-26 08:09:04 +02:00
|
|
|
* @return SS_List
|
2011-03-23 10:51:00 +01:00
|
|
|
*/
|
2012-05-03 13:49:19 +02:00
|
|
|
public function MainMenu($cached = true) {
|
|
|
|
if(!isset($this->_cache_MainMenu) || !$cached) {
|
|
|
|
// Don't accidentally return a menu if you're not logged in - it's used to determine access.
|
|
|
|
if(!Member::currentUser()) return new ArrayList();
|
|
|
|
|
|
|
|
// Encode into DO set
|
|
|
|
$menu = new ArrayList();
|
|
|
|
$menuItems = CMSMenu::get_viewable_menu_items();
|
2012-08-19 14:14:41 +02:00
|
|
|
|
|
|
|
// extra styling for custom menu-icons
|
|
|
|
$menuIconStyling = '';
|
|
|
|
|
2012-05-03 13:49:19 +02:00
|
|
|
if($menuItems) {
|
|
|
|
foreach($menuItems as $code => $menuItem) {
|
|
|
|
// alternate permission checks (in addition to LeftAndMain->canView())
|
2013-10-02 08:06:54 +02:00
|
|
|
|
2012-05-03 13:49:19 +02:00
|
|
|
if(
|
2014-08-15 08:53:05 +02:00
|
|
|
isset($menuItem->controller)
|
2012-05-03 13:49:19 +02:00
|
|
|
&& $this->hasMethod('alternateMenuDisplayCheck')
|
|
|
|
&& !$this->alternateMenuDisplayCheck($menuItem->controller)
|
|
|
|
) {
|
|
|
|
continue;
|
|
|
|
}
|
2011-03-23 10:51:00 +01:00
|
|
|
|
2012-05-03 13:49:19 +02:00
|
|
|
$linkingmode = "link";
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2012-05-03 13:49:19 +02:00
|
|
|
if($menuItem->controller && get_class($this) == $menuItem->controller) {
|
2011-07-28 06:57:41 +02:00
|
|
|
$linkingmode = "current";
|
2012-05-03 13:49:19 +02:00
|
|
|
} else if(strpos($this->Link(), $menuItem->url) !== false) {
|
|
|
|
if($this->Link() == $menuItem->url) {
|
|
|
|
$linkingmode = "current";
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2012-05-03 13:49:19 +02:00
|
|
|
// default menu is the one with a blank {@link url_segment}
|
|
|
|
} else if(singleton($menuItem->controller)->stat('url_segment') == '') {
|
|
|
|
if($this->Link() == $this->stat('url_base').'/') {
|
|
|
|
$linkingmode = "current";
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
2011-07-28 06:57:41 +02:00
|
|
|
$linkingmode = "current";
|
|
|
|
}
|
2012-05-03 13:49:19 +02:00
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2012-05-03 13:49:19 +02:00
|
|
|
// already set in CMSMenu::populate_menu(), but from a static pre-controller
|
|
|
|
// context, so doesn't respect the current user locale in _t() calls - as a workaround,
|
2014-08-15 08:53:05 +02:00
|
|
|
// we simply call LeftAndMain::menu_title_for_class() again
|
2012-05-03 13:49:19 +02:00
|
|
|
// if we're dealing with a controller
|
|
|
|
if($menuItem->controller) {
|
|
|
|
$defaultTitle = LeftAndMain::menu_title_for_class($menuItem->controller);
|
|
|
|
$title = _t("{$menuItem->controller}.MENUTITLE", $defaultTitle);
|
2011-07-28 06:57:41 +02:00
|
|
|
} else {
|
2012-05-03 13:49:19 +02:00
|
|
|
$title = $menuItem->title;
|
2011-07-28 06:57:41 +02:00
|
|
|
}
|
2012-08-19 14:14:41 +02:00
|
|
|
|
|
|
|
// Provide styling for custom $menu-icon. Done here instead of in
|
|
|
|
// CMSMenu::populate_menu(), because the icon is part of
|
|
|
|
// the CMS right pane for the specified class as well...
|
|
|
|
if($menuItem->controller) {
|
|
|
|
$menuIcon = LeftAndMain::menu_icon_for_class($menuItem->controller);
|
|
|
|
if (!empty($menuIcon)) $menuIconStyling .= $menuIcon;
|
|
|
|
}
|
2013-10-02 08:06:54 +02:00
|
|
|
|
2012-05-03 13:49:19 +02:00
|
|
|
$menu->push(new ArrayData(array(
|
|
|
|
"MenuItem" => $menuItem,
|
2013-10-02 08:06:54 +02:00
|
|
|
"AttributesHTML" => $menuItem->getAttributesHTML(),
|
2012-05-03 13:49:19 +02:00
|
|
|
"Title" => Convert::raw2xml($title),
|
|
|
|
"Code" => DBField::create_field('Text', $code),
|
|
|
|
"Link" => $menuItem->url,
|
|
|
|
"LinkingMode" => $linkingmode
|
|
|
|
)));
|
2011-03-23 10:51:00 +01:00
|
|
|
}
|
|
|
|
}
|
2012-08-19 14:14:41 +02:00
|
|
|
if ($menuIconStyling) Requirements::customCSS($menuIconStyling);
|
2012-05-03 13:49:19 +02:00
|
|
|
|
|
|
|
$this->_cache_MainMenu = $menu;
|
2011-03-23 10:51:00 +01:00
|
|
|
}
|
2011-07-28 06:57:41 +02:00
|
|
|
|
2012-05-03 13:49:19 +02:00
|
|
|
return $this->_cache_MainMenu;
|
2011-03-23 10:51:00 +01:00
|
|
|
}
|
|
|
|
|
2011-04-15 04:12:57 +02:00
|
|
|
public function Menu() {
|
|
|
|
return $this->renderWith($this->getTemplatesWithSuffix('_Menu'));
|
2011-03-23 10:51:00 +01:00
|
|
|
}
|
|
|
|
|
2012-05-03 13:49:19 +02:00
|
|
|
/**
|
|
|
|
* @todo Wrap in CMSMenu instance accessor
|
|
|
|
* @return ArrayData A single menu entry (see {@link MainMenu})
|
|
|
|
*/
|
|
|
|
public function MenuCurrentItem() {
|
|
|
|
$items = $this->MainMenu();
|
|
|
|
return $items->find('LinkingMode', 'current');
|
|
|
|
}
|
|
|
|
|
2011-03-23 10:51:00 +01:00
|
|
|
/**
|
2014-08-15 08:53:05 +02:00
|
|
|
* Return a list of appropriate templates for this class, with the given suffix using
|
2013-11-21 20:44:54 +01:00
|
|
|
* {@link SSViewer::get_templates_by_class()}
|
|
|
|
*
|
|
|
|
* @return array
|
2011-03-23 10:51:00 +01:00
|
|
|
*/
|
2012-02-27 17:43:32 +01:00
|
|
|
public function getTemplatesWithSuffix($suffix) {
|
2013-11-21 20:44:54 +01:00
|
|
|
return SSViewer::get_templates_by_class(get_class($this), $suffix, 'LeftAndMain');
|
2011-03-23 10:51:00 +01:00
|
|
|
}
|
|
|
|
|
2011-04-15 04:12:57 +02:00
|
|
|
public function Content() {
|
|
|
|
return $this->renderWith($this->getTemplatesWithSuffix('_Content'));
|
2011-03-23 10:51:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getRecord($id) {
|
|
|
|
$className = $this->stat('tree_class');
|
2011-04-19 08:44:46 +02:00
|
|
|
if($className && $id instanceof $className) {
|
2011-03-23 10:51:00 +01:00
|
|
|
return $id;
|
2014-05-05 09:26:05 +02:00
|
|
|
} else if($className && $id == 'root') {
|
2011-05-02 02:36:16 +02:00
|
|
|
return singleton($className);
|
2014-05-05 09:26:05 +02:00
|
|
|
} else if($className && is_numeric($id)) {
|
2011-03-23 10:51:00 +01:00
|
|
|
return DataObject::get_by_id($className, $id);
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2012-02-14 16:01:26 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return ArrayList
|
|
|
|
*/
|
|
|
|
public function Breadcrumbs($unlinked = false) {
|
2012-07-18 13:51:12 +02:00
|
|
|
$defaultTitle = LeftAndMain::menu_title_for_class($this->class);
|
|
|
|
$title = _t("{$this->class}.MENUTITLE", $defaultTitle);
|
2012-02-14 16:01:26 +01:00
|
|
|
$items = new ArrayList(array(
|
|
|
|
new ArrayData(array(
|
|
|
|
'Title' => $title,
|
|
|
|
'Link' => ($unlinked) ? false : $this->Link()
|
|
|
|
))
|
|
|
|
));
|
|
|
|
$record = $this->currentPage();
|
2012-03-01 00:15:56 +01:00
|
|
|
if($record && $record->exists()) {
|
2012-02-14 16:01:26 +01:00
|
|
|
if($record->hasExtension('Hierarchy')) {
|
|
|
|
$ancestors = $record->getAncestors();
|
2012-02-28 18:48:20 +01:00
|
|
|
$ancestors = new ArrayList(array_reverse($ancestors->toArray()));
|
2012-02-14 16:01:26 +01:00
|
|
|
$ancestors->push($record);
|
|
|
|
foreach($ancestors as $ancestor) {
|
|
|
|
$items->push(new ArrayData(array(
|
2012-12-13 15:25:56 +01:00
|
|
|
'Title' => ($ancestor->MenuTitle) ? $ancestor->MenuTitle : $ancestor->Title,
|
2012-02-14 16:01:26 +01:00
|
|
|
'Link' => ($unlinked) ? false : Controller::join_links($this->Link('show'), $ancestor->ID)
|
2014-08-15 08:53:05 +02:00
|
|
|
)));
|
2012-02-14 16:01:26 +01:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$items->push(new ArrayData(array(
|
2012-12-13 15:25:56 +01:00
|
|
|
'Title' => ($record->MenuTitle) ? $record->MenuTitle : $record->Title,
|
2012-02-14 16:01:26 +01:00
|
|
|
'Link' => ($unlinked) ? false : Controller::join_links($this->Link('show'), $record->ID)
|
2014-08-15 08:53:05 +02:00
|
|
|
)));
|
2012-02-14 16:01:26 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $items;
|
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2011-03-23 10:51:00 +01:00
|
|
|
/**
|
|
|
|
* @return String HTML
|
|
|
|
*/
|
|
|
|
public function SiteTreeAsUL() {
|
2012-05-15 21:28:38 +02:00
|
|
|
$html = $this->getSiteTreeFor($this->stat('tree_class'));
|
|
|
|
$this->extend('updateSiteTreeAsUL', $html);
|
|
|
|
return $html;
|
2011-03-23 10:51:00 +01:00
|
|
|
}
|
|
|
|
|
2015-04-30 07:12:53 +02:00
|
|
|
/**
|
|
|
|
* Gets the current search filter for this request, if available
|
|
|
|
*
|
|
|
|
* @throws InvalidArgumentException
|
|
|
|
* @return LeftAndMain_SearchFilter
|
|
|
|
*/
|
|
|
|
protected function getSearchFilter() {
|
|
|
|
// Check for given FilterClass
|
|
|
|
$params = $this->getRequest()->getVar('q');
|
|
|
|
if(empty($params['FilterClass'])) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Validate classname
|
|
|
|
$filterClass = $params['FilterClass'];
|
|
|
|
$filterInfo = new ReflectionClass($filterClass);
|
|
|
|
if(!$filterInfo->implementsInterface('LeftAndMain_SearchFilter')) {
|
|
|
|
throw new InvalidArgumentException(sprintf('Invalid filter class passed: %s', $filterClass));
|
|
|
|
}
|
2015-08-14 02:39:33 +02:00
|
|
|
|
2015-04-30 07:12:53 +02:00
|
|
|
return Injector::inst()->createWithArgs($filterClass, array($params));
|
|
|
|
}
|
|
|
|
|
2011-03-23 10:51:00 +01:00
|
|
|
/**
|
|
|
|
* Get a site tree HTML listing which displays the nodes under the given criteria.
|
2014-08-15 08:53:05 +02:00
|
|
|
*
|
2011-03-23 10:51:00 +01:00
|
|
|
* @param $className The class of the root object
|
|
|
|
* @param $rootID The ID of the root object. If this is null then a complete tree will be
|
|
|
|
* shown
|
|
|
|
* @param $childrenMethod The method to call to get the children of the tree. For example,
|
|
|
|
* Children, AllChildrenIncludingDeleted, or AllHistoricalChildren
|
|
|
|
* @return String Nested unordered list with links to each page
|
|
|
|
*/
|
2012-09-26 23:34:00 +02:00
|
|
|
public function getSiteTreeFor($className, $rootID = null, $childrenMethod = null, $numChildrenMethod = null,
|
2013-03-12 23:01:43 +01:00
|
|
|
$filterFunction = null, $nodeCountThreshold = 30) {
|
2012-09-26 23:34:00 +02:00
|
|
|
|
2012-04-16 22:05:50 +02:00
|
|
|
// Filter criteria
|
2015-04-30 07:12:53 +02:00
|
|
|
$filter = $this->getSearchFilter();
|
2012-04-16 22:05:50 +02:00
|
|
|
|
2011-03-23 10:51:00 +01:00
|
|
|
// Default childrenMethod and numChildrenMethod
|
2012-09-26 23:34:00 +02:00
|
|
|
if(!$childrenMethod) $childrenMethod = ($filter && $filter->getChildrenMethod())
|
2014-08-15 08:53:05 +02:00
|
|
|
? $filter->getChildrenMethod()
|
2012-09-26 23:34:00 +02:00
|
|
|
: 'AllChildrenIncludingDeleted';
|
|
|
|
|
2014-07-20 01:49:17 +02:00
|
|
|
if(!$numChildrenMethod) {
|
|
|
|
$numChildrenMethod = 'numChildren';
|
|
|
|
if($filter && $filter->getNumChildrenMethod()) {
|
|
|
|
$numChildrenMethod = $filter->getNumChildrenMethod();
|
|
|
|
}
|
|
|
|
}
|
2015-04-30 07:12:53 +02:00
|
|
|
if(!$filterFunction && $filter) {
|
|
|
|
$filterFunction = function($node) use($filter) {
|
|
|
|
return $filter->isPageIncluded($node);
|
|
|
|
};
|
|
|
|
}
|
2012-04-16 22:05:50 +02:00
|
|
|
|
2011-03-23 10:51:00 +01:00
|
|
|
// Get the tree root
|
2011-04-22 07:42:40 +02:00
|
|
|
$record = ($rootID) ? $this->getRecord($rootID) : null;
|
|
|
|
$obj = $record ? $record : singleton($className);
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2015-05-07 17:01:24 +02:00
|
|
|
// Get the current page
|
|
|
|
// NOTE: This *must* be fetched before markPartialTree() is called, as this
|
|
|
|
// causes the Hierarchy::$marked cache to be flushed (@see CMSMain::getRecord)
|
|
|
|
// which means that deleted pages stored in the marked tree would be removed
|
|
|
|
$currentPage = $this->currentPage();
|
2015-08-14 02:39:33 +02:00
|
|
|
|
2011-03-23 10:51:00 +01:00
|
|
|
// Mark the nodes of the tree to return
|
|
|
|
if ($filterFunction) $obj->setMarkingFilterFunction($filterFunction);
|
|
|
|
|
2013-03-12 23:01:43 +01:00
|
|
|
$obj->markPartialTree($nodeCountThreshold, $this, $childrenMethod, $numChildrenMethod);
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2011-03-23 10:51:00 +01:00
|
|
|
// Ensure current page is exposed
|
2015-05-07 17:01:24 +02:00
|
|
|
if($currentPage) $obj->markToExpose($currentPage);
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2011-03-23 10:51:00 +01:00
|
|
|
// NOTE: SiteTree/CMSMain coupling :-(
|
2011-03-29 06:54:58 +02:00
|
|
|
if(class_exists('SiteTree')) {
|
2012-09-26 23:34:00 +02:00
|
|
|
SiteTree::prepopulate_permission_cache('CanEditType', $obj->markedNodeIDs(),
|
|
|
|
'SiteTree::can_edit_multiple');
|
2011-03-29 06:54:58 +02:00
|
|
|
}
|
2011-03-23 10:51:00 +01:00
|
|
|
|
|
|
|
// getChildrenAsUL is a flexible and complex way of traversing the tree
|
2012-04-17 22:29:45 +02:00
|
|
|
$controller = $this;
|
|
|
|
$recordController = ($this->stat('tree_class') == 'SiteTree') ? singleton('CMSPageEditController') : $this;
|
2015-04-30 07:12:53 +02:00
|
|
|
$titleFn = function(&$child, $numChildrenMethod) use(&$controller, &$recordController, $filter) {
|
2012-07-17 15:04:27 +02:00
|
|
|
$link = Controller::join_links($recordController->Link("show"), $child->ID);
|
2015-04-30 07:12:53 +02:00
|
|
|
$node = LeftAndMain_TreeNode::create($child, $link, $controller->isCurrentPage($child), $numChildrenMethod, $filter);
|
2014-07-20 01:49:17 +02:00
|
|
|
return $node->forTemplate();
|
2012-04-17 22:29:45 +02:00
|
|
|
};
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2013-03-19 22:26:48 +01:00
|
|
|
// Limit the amount of nodes shown for performance reasons.
|
|
|
|
// Skip the check if we're filtering the tree, since its not clear how many children will
|
|
|
|
// match the filter criteria until they're queried (and matched up with previously marked nodes).
|
|
|
|
$nodeThresholdLeaf = Config::inst()->get('Hierarchy', 'node_threshold_leaf');
|
|
|
|
if($nodeThresholdLeaf && !$filterFunction) {
|
2013-07-31 04:12:08 +02:00
|
|
|
$nodeCountCallback = function($parent, $numChildren) use(&$controller, $className, $nodeThresholdLeaf) {
|
2013-03-19 22:26:48 +01:00
|
|
|
if($className == 'SiteTree' && $parent->ID && $numChildren > $nodeThresholdLeaf) {
|
|
|
|
return sprintf(
|
|
|
|
'<ul><li class="readonly"><span class="item">'
|
|
|
|
. '%s (<a href="%s" class="cms-panel-link" data-pjax-target="Content">%s</a>)'
|
|
|
|
. '</span></li></ul>',
|
|
|
|
_t('LeftAndMain.TooManyPages', 'Too many pages'),
|
|
|
|
Controller::join_links(
|
|
|
|
$controller->LinkWithSearch($controller->Link()), '
|
|
|
|
?view=list&ParentID=' . $parent->ID
|
2014-08-15 08:53:05 +02:00
|
|
|
),
|
2013-03-19 22:26:48 +01:00
|
|
|
_t(
|
2014-08-15 08:53:05 +02:00
|
|
|
'LeftAndMain.ShowAsList',
|
|
|
|
'show as list',
|
2013-03-19 22:26:48 +01:00
|
|
|
'Show large amount of pages in list instead of tree view'
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
};
|
2013-03-19 22:26:48 +01:00
|
|
|
} else {
|
|
|
|
$nodeCountCallback = null;
|
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2013-03-19 22:26:48 +01:00
|
|
|
// If the amount of pages exceeds the node thresholds set, use the callback
|
2013-04-09 01:42:30 +02:00
|
|
|
$html = null;
|
2013-03-19 22:26:48 +01:00
|
|
|
if($obj->ParentID && $nodeCountCallback) {
|
|
|
|
$html = $nodeCountCallback($obj, $obj->$numChildrenMethod());
|
2014-08-15 08:53:05 +02:00
|
|
|
}
|
2013-03-19 22:26:48 +01:00
|
|
|
|
|
|
|
// Otherwise return the actual tree (which might still filter leaf thresholds on children)
|
|
|
|
if(!$html) {
|
|
|
|
$html = $obj->getChildrenAsUL(
|
|
|
|
"",
|
|
|
|
$titleFn,
|
|
|
|
singleton('CMSPagesController'),
|
2014-08-15 08:53:05 +02:00
|
|
|
true,
|
2013-03-19 22:26:48 +01:00
|
|
|
$childrenMethod,
|
|
|
|
$numChildrenMethod,
|
|
|
|
$nodeCountThreshold,
|
|
|
|
$nodeCountCallback
|
|
|
|
);
|
|
|
|
}
|
2011-03-23 10:51:00 +01:00
|
|
|
|
|
|
|
// Wrap the root if needs be.
|
|
|
|
if(!$rootID) {
|
|
|
|
$rootLink = $this->Link('show') . '/root';
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2011-03-23 10:51:00 +01:00
|
|
|
// This lets us override the tree title with an extension
|
|
|
|
if($this->hasMethod('getCMSTreeTitle') && $customTreeTitle = $this->getCMSTreeTitle()) {
|
|
|
|
$treeTitle = $customTreeTitle;
|
2011-03-24 09:39:47 +01:00
|
|
|
} elseif(class_exists('SiteConfig')) {
|
2011-03-23 10:51:00 +01:00
|
|
|
$siteConfig = SiteConfig::current_site_config();
|
2012-11-05 01:19:02 +01:00
|
|
|
$treeTitle = Convert::raw2xml($siteConfig->Title);
|
2011-03-24 09:39:47 +01:00
|
|
|
} else {
|
|
|
|
$treeTitle = '...';
|
2011-03-23 10:51:00 +01:00
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2012-03-12 10:42:07 +01:00
|
|
|
$html = "<ul><li id=\"record-0\" data-id=\"0\" class=\"Root nodelete\"><strong>$treeTitle</strong>"
|
2011-03-23 10:51:00 +01:00
|
|
|
. $html . "</li></ul>";
|
|
|
|
}
|
|
|
|
|
|
|
|
return $html;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a subtree underneath the request param 'ID'.
|
|
|
|
* If ID = 0, then get the whole tree.
|
|
|
|
*/
|
|
|
|
public function getsubtree($request) {
|
|
|
|
$html = $this->getSiteTreeFor(
|
2014-08-15 08:53:05 +02:00
|
|
|
$this->stat('tree_class'),
|
|
|
|
$request->getVar('ID'),
|
|
|
|
null,
|
|
|
|
null,
|
2011-03-23 10:51:00 +01:00
|
|
|
null,
|
|
|
|
$request->getVar('minNodeCount')
|
|
|
|
);
|
|
|
|
|
|
|
|
// Trim off the outer tag
|
|
|
|
$html = preg_replace('/^[\s\t\r\n]*<ul[^>]*>/','', $html);
|
|
|
|
$html = preg_replace('/<\/ul[^>]*>[\s\t\r\n]*$/','', $html);
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2011-03-23 10:51:00 +01:00
|
|
|
return $html;
|
|
|
|
}
|
2012-07-17 15:04:27 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Allows requesting a view update on specific tree nodes.
|
|
|
|
* Similar to {@link getsubtree()}, but doesn't enforce loading
|
|
|
|
* all children with the node. Useful to refresh views after
|
|
|
|
* state modifications, e.g. saving a form.
|
2014-08-15 08:53:05 +02:00
|
|
|
*
|
2012-07-17 15:04:27 +02:00
|
|
|
* @return String JSON
|
|
|
|
*/
|
|
|
|
public function updatetreenodes($request) {
|
|
|
|
$data = array();
|
|
|
|
$ids = explode(',', $request->getVar('ids'));
|
|
|
|
foreach($ids as $id) {
|
2014-01-13 05:47:33 +01:00
|
|
|
if($id === "") continue; // $id may be a blank string, which is invalid and should be skipped over
|
|
|
|
|
2012-07-17 15:04:27 +02:00
|
|
|
$record = $this->getRecord($id);
|
2014-08-08 04:37:57 +02:00
|
|
|
if(!$record) continue; // In case a page is no longer available
|
2014-08-15 08:53:05 +02:00
|
|
|
$recordController = ($this->stat('tree_class') == 'SiteTree')
|
|
|
|
? singleton('CMSPageEditController')
|
2012-09-26 23:34:00 +02:00
|
|
|
: $this;
|
2012-07-23 12:15:11 +02:00
|
|
|
|
|
|
|
// Find the next & previous nodes, for proper positioning (Sort isn't good enough - it's not a raw offset)
|
|
|
|
// TODO: These methods should really be in hierarchy - for a start it assumes Sort exists
|
|
|
|
$next = $prev = null;
|
|
|
|
|
|
|
|
$className = $this->stat('tree_class');
|
2012-09-26 23:34:00 +02:00
|
|
|
$next = DataObject::get($className)
|
|
|
|
->filter('ParentID', $record->ParentID)
|
|
|
|
->filter('Sort:GreaterThan', $record->Sort)
|
|
|
|
->first();
|
|
|
|
|
2012-07-23 12:15:11 +02:00
|
|
|
if (!$next) {
|
2012-09-26 23:34:00 +02:00
|
|
|
$prev = DataObject::get($className)
|
|
|
|
->filter('ParentID', $record->ParentID)
|
|
|
|
->filter('Sort:LessThan', $record->Sort)
|
|
|
|
->reverse()
|
|
|
|
->first();
|
2012-07-23 12:15:11 +02:00
|
|
|
}
|
|
|
|
|
2012-07-17 15:04:27 +02:00
|
|
|
$link = Controller::join_links($recordController->Link("show"), $record->ID);
|
2012-09-26 23:34:00 +02:00
|
|
|
$html = LeftAndMain_TreeNode::create($record, $link, $this->isCurrentPage($record))
|
|
|
|
->forTemplate() . '</li>';
|
2012-07-23 12:15:11 +02:00
|
|
|
|
2012-07-17 15:04:27 +02:00
|
|
|
$data[$id] = array(
|
2014-08-15 08:53:05 +02:00
|
|
|
'html' => $html,
|
2012-07-17 15:04:27 +02:00
|
|
|
'ParentID' => $record->ParentID,
|
2012-07-23 12:15:11 +02:00
|
|
|
'NextID' => $next ? $next->ID : null,
|
|
|
|
'PrevID' => $prev ? $prev->ID : null
|
2012-07-17 15:04:27 +02:00
|
|
|
);
|
|
|
|
}
|
2015-08-14 02:39:33 +02:00
|
|
|
$this->getResponse()->addHeader('Content-Type', 'text/json');
|
2012-07-17 15:04:27 +02:00
|
|
|
return Convert::raw2json($data);
|
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2011-03-23 10:51:00 +01:00
|
|
|
/**
|
|
|
|
* Save handler
|
|
|
|
*/
|
|
|
|
public function save($data, $form) {
|
2016-03-03 00:03:38 +01:00
|
|
|
$request = $this->getRequest();
|
2011-03-23 10:51:00 +01:00
|
|
|
$className = $this->stat('tree_class');
|
|
|
|
|
|
|
|
// Existing or new record?
|
2013-06-21 00:32:08 +02:00
|
|
|
$id = $data['ID'];
|
|
|
|
if(substr($id,0,3) != 'new') {
|
|
|
|
$record = DataObject::get_by_id($className, $id);
|
2011-03-23 10:51:00 +01:00
|
|
|
if($record && !$record->canEdit()) return Security::permissionFailure($this);
|
2013-06-21 00:32:08 +02:00
|
|
|
if(!$record || !$record->ID) $this->httpError(404, "Bad record ID #" . (int)$id);
|
2011-03-23 10:51:00 +01:00
|
|
|
} else {
|
|
|
|
if(!singleton($this->stat('tree_class'))->canCreate()) return Security::permissionFailure($this);
|
2013-06-21 00:32:08 +02:00
|
|
|
$record = $this->getNewItem($id, false);
|
2011-03-23 10:51:00 +01:00
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2011-03-23 10:51:00 +01:00
|
|
|
// save form data into record
|
|
|
|
$form->saveInto($record, true);
|
|
|
|
$record->write();
|
|
|
|
$this->extend('onAfterSave', $record);
|
2012-03-24 03:19:02 +01:00
|
|
|
$this->setCurrentPageID($record->ID);
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2015-08-14 02:39:33 +02:00
|
|
|
$this->getResponse()->addHeader('X-Status', rawurlencode(_t('LeftAndMain.SAVEDUP', 'Saved.')));
|
2016-03-03 00:03:38 +01:00
|
|
|
|
|
|
|
if($request->getHeader('X-Formschema-Request')) {
|
|
|
|
$data = $this->getSchemaForForm($form);
|
|
|
|
$response = new SS_HTTPResponse(Convert::raw2json($data));
|
|
|
|
$response->addHeader('Content-Type', 'application/json');
|
|
|
|
} else {
|
|
|
|
$response = $this->getResponseNegotiator()->respond($request);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $response;
|
2011-03-23 10:51:00 +01:00
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2011-04-19 11:16:56 +02:00
|
|
|
public function delete($data, $form) {
|
|
|
|
$className = $this->stat('tree_class');
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2013-06-21 00:32:08 +02:00
|
|
|
$id = $data['ID'];
|
|
|
|
$record = DataObject::get_by_id($className, $id);
|
2011-04-19 11:16:56 +02:00
|
|
|
if($record && !$record->canDelete()) return Security::permissionFailure();
|
2013-06-21 00:32:08 +02:00
|
|
|
if(!$record || !$record->ID) $this->httpError(404, "Bad record ID #" . (int)$id);
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2011-04-19 11:16:56 +02:00
|
|
|
$record->delete();
|
2012-03-24 03:19:02 +01:00
|
|
|
|
2015-08-14 02:39:33 +02:00
|
|
|
$this->getResponse()->addHeader('X-Status', rawurlencode(_t('LeftAndMain.DELETED', 'Deleted.')));
|
2012-03-24 03:19:02 +01:00
|
|
|
return $this->getResponseNegotiator()->respond(
|
2015-04-30 01:04:08 +02:00
|
|
|
$this->getRequest(),
|
2012-03-24 03:19:02 +01:00
|
|
|
array('currentform' => array($this, 'EmptyForm'))
|
|
|
|
);
|
2011-04-19 11:16:56 +02:00
|
|
|
}
|
2011-03-23 10:51:00 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Update the position and parent of a tree node.
|
|
|
|
* Only saves the node if changes were made.
|
2014-08-15 08:53:05 +02:00
|
|
|
*
|
|
|
|
* Required data:
|
2011-03-23 10:51:00 +01:00
|
|
|
* - 'ID': The moved node
|
|
|
|
* - 'ParentID': New parent relation of the moved node (0 for root)
|
|
|
|
* - 'SiblingIDs': Array of all sibling nodes to the moved node (incl. the node itself).
|
|
|
|
* In case of a 'ParentID' change, relates to the new siblings under the new parent.
|
2014-08-15 08:53:05 +02:00
|
|
|
*
|
|
|
|
* @return SS_HTTPResponse JSON string with a
|
2011-03-23 10:51:00 +01:00
|
|
|
*/
|
|
|
|
public function savetreenode($request) {
|
|
|
|
if (!Permission::check('SITETREE_REORGANISE') && !Permission::check('ADMIN')) {
|
2015-08-14 02:39:33 +02:00
|
|
|
$this->getResponse()->setStatusCode(
|
2011-03-23 10:51:00 +01:00
|
|
|
403,
|
2012-09-26 23:34:00 +02:00
|
|
|
_t('LeftAndMain.CANT_REORGANISE',
|
|
|
|
"You do not have permission to rearange the site tree. Your change was not saved.")
|
2011-03-23 10:51:00 +01:00
|
|
|
);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-08-15 08:53:05 +02:00
|
|
|
$className = $this->stat('tree_class');
|
2011-03-23 10:51:00 +01:00
|
|
|
$statusUpdates = array('modified'=>array());
|
|
|
|
$id = $request->requestVar('ID');
|
|
|
|
$parentID = $request->requestVar('ParentID');
|
2012-06-14 07:17:27 +02:00
|
|
|
|
|
|
|
if($className == 'SiteTree' && $page = DataObject::get_by_id('Page', $id)){
|
|
|
|
$root = $page->getParentType();
|
|
|
|
if(($parentID == '0' || $root == 'root') && !SiteConfig::current_site_config()->canCreateTopLevel()){
|
2015-08-14 02:39:33 +02:00
|
|
|
$this->getResponse()->setStatusCode(
|
2012-06-14 07:17:27 +02:00
|
|
|
403,
|
2012-09-26 23:34:00 +02:00
|
|
|
_t('LeftAndMain.CANT_REORGANISE',
|
|
|
|
"You do not have permission to alter Top level pages. Your change was not saved.")
|
2012-06-14 07:17:27 +02:00
|
|
|
);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-23 10:51:00 +01:00
|
|
|
$siblingIDs = $request->requestVar('SiblingIDs');
|
|
|
|
$statusUpdates = array('modified'=>array());
|
|
|
|
if(!is_numeric($id) || !is_numeric($parentID)) throw new InvalidArgumentException();
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2011-03-23 10:51:00 +01:00
|
|
|
$node = DataObject::get_by_id($className, $id);
|
|
|
|
if($node && !$node->canEdit()) return Security::permissionFailure($this);
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2011-03-23 10:51:00 +01:00
|
|
|
if(!$node) {
|
2015-08-14 02:39:33 +02:00
|
|
|
$this->getResponse()->setStatusCode(
|
2011-03-23 10:51:00 +01:00
|
|
|
500,
|
2012-09-26 23:34:00 +02:00
|
|
|
_t('LeftAndMain.PLEASESAVE',
|
2014-03-21 02:30:17 +01:00
|
|
|
"Please Save Page: This page could not be updated because it hasn't been saved yet."
|
2011-03-23 10:51:00 +01:00
|
|
|
)
|
|
|
|
);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update hierarchy (only if ParentID changed)
|
|
|
|
if($node->ParentID != $parentID) {
|
|
|
|
$node->ParentID = (int)$parentID;
|
|
|
|
$node->write();
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2011-03-23 10:51:00 +01:00
|
|
|
$statusUpdates['modified'][$node->ID] = array(
|
|
|
|
'TreeTitle'=>$node->TreeTitle
|
|
|
|
);
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2011-03-23 10:51:00 +01:00
|
|
|
// Update all dependent pages
|
2011-03-29 06:54:58 +02:00
|
|
|
if(class_exists('VirtualPage')) {
|
2013-06-21 00:32:08 +02:00
|
|
|
$virtualPages = VirtualPage::get()->filter("CopyContentFromID", $node->ID);
|
|
|
|
foreach($virtualPages as $virtualPage) {
|
|
|
|
$statusUpdates['modified'][$virtualPage->ID] = array(
|
|
|
|
'TreeTitle' => $virtualPage->TreeTitle()
|
|
|
|
);
|
2011-03-23 10:51:00 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-14 02:39:33 +02:00
|
|
|
$this->getResponse()->addHeader('X-Status',
|
2012-09-26 23:34:00 +02:00
|
|
|
rawurlencode(_t('LeftAndMain.REORGANISATIONSUCCESSFUL', 'Reorganised the site tree successfully.')));
|
2011-03-23 10:51:00 +01:00
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2011-03-23 10:51:00 +01:00
|
|
|
// Update sorting
|
|
|
|
if(is_array($siblingIDs)) {
|
|
|
|
$counter = 0;
|
|
|
|
foreach($siblingIDs as $id) {
|
|
|
|
if($id == $node->ID) {
|
|
|
|
$node->Sort = ++$counter;
|
|
|
|
$node->write();
|
|
|
|
$statusUpdates['modified'][$node->ID] = array(
|
|
|
|
'TreeTitle' => $node->TreeTitle
|
|
|
|
);
|
|
|
|
} else if(is_numeric($id)) {
|
2014-08-15 08:53:05 +02:00
|
|
|
// Nodes that weren't "actually moved" shouldn't be registered as
|
2011-03-23 10:51:00 +01:00
|
|
|
// having been edited; do a direct SQL update instead
|
|
|
|
++$counter;
|
2013-06-21 00:32:08 +02:00
|
|
|
DB::prepared_query(
|
|
|
|
"UPDATE \"$className\" SET \"Sort\" = ? WHERE \"ID\" = ?",
|
|
|
|
array($counter, $id)
|
|
|
|
);
|
2011-03-23 10:51:00 +01:00
|
|
|
}
|
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2015-08-14 02:39:33 +02:00
|
|
|
$this->getResponse()->addHeader('X-Status',
|
2012-09-26 23:34:00 +02:00
|
|
|
rawurlencode(_t('LeftAndMain.REORGANISATIONSUCCESSFUL', 'Reorganised the site tree successfully.')));
|
2011-03-23 10:51:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return Convert::raw2json($statusUpdates);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function CanOrganiseSitetree() {
|
|
|
|
return !Permission::check('SITETREE_REORGANISE') && !Permission::check('ADMIN') ? false : true;
|
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2011-03-23 10:51:00 +01:00
|
|
|
/**
|
|
|
|
* Retrieves an edit form, either for display, or to process submitted data.
|
|
|
|
* Also used in the template rendered through {@link Right()} in the $EditForm placeholder.
|
2014-08-15 08:53:05 +02:00
|
|
|
*
|
2011-03-23 10:51:00 +01:00
|
|
|
* This is a "pseudo-abstract" methoed, usually connected to a {@link getEditForm()}
|
|
|
|
* method in an entwine subclass. This method can accept a record identifier,
|
2014-08-15 08:53:05 +02:00
|
|
|
* selected either in custom logic, or through {@link currentPageID()}.
|
|
|
|
* The form usually construct itself from {@link DataObject->getCMSFields()}
|
2011-03-23 10:51:00 +01:00
|
|
|
* for the specific managed subclass defined in {@link LeftAndMain::$tree_class}.
|
2014-08-15 08:53:05 +02:00
|
|
|
*
|
2011-03-23 10:51:00 +01:00
|
|
|
* @param HTTPRequest $request Optionally contains an identifier for the
|
|
|
|
* record to load into the form.
|
|
|
|
* @return Form Should return a form regardless wether a record has been found.
|
|
|
|
* Form might be readonly if the current user doesn't have the permission to edit
|
|
|
|
* the record.
|
|
|
|
*/
|
|
|
|
/**
|
|
|
|
* @return Form
|
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public function EditForm($request = null) {
|
2011-03-23 10:51:00 +01:00
|
|
|
return $this->getEditForm();
|
|
|
|
}
|
|
|
|
|
2011-04-15 05:32:43 +02:00
|
|
|
/**
|
|
|
|
* Calls {@link SiteTree->getCMSFields()}
|
2014-08-15 08:53:05 +02:00
|
|
|
*
|
2011-04-15 05:32:43 +02:00
|
|
|
* @param Int $id
|
2011-05-11 09:51:54 +02:00
|
|
|
* @param FieldList $fields
|
2011-04-15 05:32:43 +02:00
|
|
|
* @return Form
|
|
|
|
*/
|
|
|
|
public function getEditForm($id = null, $fields = null) {
|
2011-03-23 10:51:00 +01:00
|
|
|
if(!$id) $id = $this->currentPageID();
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2011-03-23 10:51:00 +01:00
|
|
|
if(is_object($id)) {
|
|
|
|
$record = $id;
|
|
|
|
} else {
|
2011-05-02 02:36:16 +02:00
|
|
|
$record = $this->getRecord($id);
|
2011-03-23 10:51:00 +01:00
|
|
|
if($record && !$record->canView()) return Security::permissionFailure($this);
|
|
|
|
}
|
|
|
|
|
|
|
|
if($record) {
|
2011-04-15 05:32:43 +02:00
|
|
|
$fields = ($fields) ? $fields : $record->getCMSFields();
|
2011-03-23 10:51:00 +01:00
|
|
|
if ($fields == null) {
|
|
|
|
user_error(
|
2014-08-15 08:53:05 +02:00
|
|
|
"getCMSFields() returned null - it should return a FieldList object.
|
|
|
|
Perhaps you forgot to put a return statement at the end of your method?",
|
2011-03-23 10:51:00 +01:00
|
|
|
E_USER_ERROR
|
|
|
|
);
|
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2011-03-23 10:51:00 +01:00
|
|
|
// Add hidden fields which are required for saving the record
|
|
|
|
// and loading the UI state
|
|
|
|
if(!$fields->dataFieldByName('ClassName')) {
|
|
|
|
$fields->push(new HiddenField('ClassName'));
|
|
|
|
}
|
2012-10-09 23:59:23 +02:00
|
|
|
|
|
|
|
$tree_class = $this->stat('tree_class');
|
2011-03-23 10:51:00 +01:00
|
|
|
if(
|
2014-08-15 08:53:05 +02:00
|
|
|
$tree_class::has_extension('Hierarchy')
|
2011-03-23 10:51:00 +01:00
|
|
|
&& !$fields->dataFieldByName('ParentID')
|
|
|
|
) {
|
|
|
|
$fields->push(new HiddenField('ParentID'));
|
|
|
|
}
|
2011-07-21 20:14:33 +02:00
|
|
|
|
2012-11-29 05:41:48 +01:00
|
|
|
// Added in-line to the form, but plucked into different view by frontend scripts.
|
2011-07-21 20:14:33 +02:00
|
|
|
if(in_array('CMSPreviewable', class_implements($record))) {
|
|
|
|
$navField = new LiteralField('SilverStripeNavigator', $this->getSilverStripeNavigator());
|
|
|
|
$navField->setAllowHTML(true);
|
|
|
|
$fields->push($navField);
|
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2011-03-23 10:51:00 +01:00
|
|
|
if($record->hasMethod('getAllCMSActions')) {
|
|
|
|
$actions = $record->getAllCMSActions();
|
|
|
|
} else {
|
|
|
|
$actions = $record->getCMSActions();
|
|
|
|
// add default actions if none are defined
|
|
|
|
if(!$actions || !$actions->Count()) {
|
2011-04-19 08:44:46 +02:00
|
|
|
if($record->hasMethod('canEdit') && $record->canEdit()) {
|
2012-02-17 00:35:10 +01:00
|
|
|
$actions->push(
|
|
|
|
FormAction::create('save',_t('CMSMain.SAVE','Save'))
|
|
|
|
->addExtraClass('ss-ui-action-constructive')->setAttribute('data-icon', 'accept')
|
|
|
|
);
|
2011-03-23 10:51:00 +01:00
|
|
|
}
|
2012-03-07 00:36:47 +01:00
|
|
|
if($record->hasMethod('canDelete') && $record->canDelete()) {
|
|
|
|
$actions->push(
|
|
|
|
FormAction::create('delete',_t('ModelAdmin.DELETE','Delete'))
|
|
|
|
->addExtraClass('ss-ui-action-destructive')
|
|
|
|
);
|
|
|
|
}
|
2011-03-23 10:51:00 +01:00
|
|
|
}
|
|
|
|
}
|
2012-02-17 00:35:10 +01:00
|
|
|
|
|
|
|
// Use <button> to allow full jQuery UI styling
|
|
|
|
$actionsFlattened = $actions->dataFields();
|
|
|
|
if($actionsFlattened) foreach($actionsFlattened as $action) $action->setUseButtonTag(true);
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2016-03-01 04:15:15 +01:00
|
|
|
$negotiator = $this->getResponseNegotiator();
|
|
|
|
$form = Form::create(
|
2013-05-10 15:00:13 +02:00
|
|
|
$this, "EditForm", $fields, $actions
|
|
|
|
)->setHTMLID('Form_EditForm');
|
2011-03-31 10:52:29 +02:00
|
|
|
$form->addExtraClass('cms-edit-form');
|
2011-03-23 10:51:00 +01:00
|
|
|
$form->loadDataFrom($record);
|
2011-10-29 21:56:33 +02:00
|
|
|
$form->setTemplate($this->getTemplatesWithSuffix('_EditForm'));
|
2012-04-18 22:11:40 +02:00
|
|
|
$form->setAttribute('data-pjax-fragment', 'CurrentForm');
|
2016-03-01 04:15:15 +01:00
|
|
|
$form->setValidationResponseCallback(function() use ($negotiator, $form) {
|
|
|
|
$request = $this->getRequest();
|
|
|
|
if($request->isAjax() && $negotiator) {
|
|
|
|
$form->setupFormErrors();
|
|
|
|
$result = $form->forTemplate();
|
|
|
|
|
|
|
|
return $negotiator->respond($request, array(
|
|
|
|
'CurrentForm' => function() use($result) {
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
));
|
|
|
|
}
|
|
|
|
});
|
2012-12-03 22:16:58 +01:00
|
|
|
|
|
|
|
// Announce the capability so the frontend can decide whether to allow preview or not.
|
|
|
|
if(in_array('CMSPreviewable', class_implements($record))) {
|
|
|
|
$form->addExtraClass('cms-previewable');
|
|
|
|
}
|
|
|
|
|
2011-10-29 21:59:21 +02:00
|
|
|
// Set this if you want to split up tabs into a separate header row
|
2012-10-31 15:57:48 +01:00
|
|
|
// if($form->Fields()->hasTabset()) {
|
|
|
|
// $form->Fields()->findOrMakeTab('Root')->setTemplate('CMSTabSet');
|
|
|
|
// }
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2011-03-23 10:51:00 +01:00
|
|
|
// Add a default or custom validator.
|
|
|
|
// @todo Currently the default Validator.js implementation
|
|
|
|
// adds javascript to the document body, meaning it won't
|
|
|
|
// be included properly if the associated fields are loaded
|
|
|
|
// through ajax. This means only serverside validation
|
|
|
|
// will kick in for pages+validation loaded through ajax.
|
|
|
|
// This will be solved by using less obtrusive javascript validation
|
|
|
|
// in the future, see http://open.silverstripe.com/ticket/2915 and
|
|
|
|
// http://open.silverstripe.com/ticket/3386
|
|
|
|
if($record->hasMethod('getCMSValidator')) {
|
|
|
|
$validator = $record->getCMSValidator();
|
|
|
|
// The clientside (mainly LeftAndMain*.js) rely on ajax responses
|
|
|
|
// which can be evaluated as javascript, hence we need
|
|
|
|
// to override any global changes to the validation handler.
|
2016-02-24 03:13:00 +01:00
|
|
|
if($validator != NULL){
|
|
|
|
$form->setValidator($validator);
|
|
|
|
}
|
2011-03-23 10:51:00 +01:00
|
|
|
} else {
|
|
|
|
$form->unsetValidator();
|
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2011-04-19 08:44:46 +02:00
|
|
|
if($record->hasMethod('canEdit') && !$record->canEdit()) {
|
2011-03-23 10:51:00 +01:00
|
|
|
$readonlyFields = $form->Fields()->makeReadonly();
|
|
|
|
$form->setFields($readonlyFields);
|
|
|
|
}
|
|
|
|
} else {
|
2012-03-08 18:20:11 +01:00
|
|
|
$form = $this->EmptyForm();
|
2011-03-23 10:51:00 +01:00
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2011-03-23 10:51:00 +01:00
|
|
|
return $form;
|
2014-08-15 08:53:05 +02:00
|
|
|
}
|
|
|
|
|
2011-03-23 10:51:00 +01:00
|
|
|
/**
|
|
|
|
* Returns a placeholder form, used by {@link getEditForm()} if no record is selected.
|
|
|
|
* Our javascript logic always requires a form to be present in the CMS interface.
|
2014-08-15 08:53:05 +02:00
|
|
|
*
|
2011-03-23 10:51:00 +01:00
|
|
|
* @return Form
|
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public function EmptyForm() {
|
2016-03-01 04:15:15 +01:00
|
|
|
$form = Form::create(
|
2014-08-15 08:53:05 +02:00
|
|
|
$this,
|
|
|
|
"EditForm",
|
2011-05-11 09:51:54 +02:00
|
|
|
new FieldList(
|
2011-04-24 01:30:28 +02:00
|
|
|
// new HeaderField(
|
|
|
|
// 'WelcomeHeader',
|
|
|
|
// $this->getApplicationName()
|
|
|
|
// ),
|
|
|
|
// new LiteralField(
|
|
|
|
// 'WelcomeText',
|
|
|
|
// sprintf('<p id="WelcomeMessage">%s %s. %s</p>',
|
2013-08-03 20:18:06 +02:00
|
|
|
// _t('LeftAndMain_right_ss.WELCOMETO','Welcome to'),
|
2011-04-24 01:30:28 +02:00
|
|
|
// $this->getApplicationName(),
|
|
|
|
// _t('CHOOSEPAGE','Please choose an item from the left.')
|
|
|
|
// )
|
|
|
|
// )
|
2014-08-15 08:53:05 +02:00
|
|
|
),
|
2011-05-11 09:51:54 +02:00
|
|
|
new FieldList()
|
2013-05-10 15:00:13 +02:00
|
|
|
)->setHTMLID('Form_EditForm');
|
2011-03-23 10:51:00 +01:00
|
|
|
$form->unsetValidator();
|
2011-03-31 10:52:29 +02:00
|
|
|
$form->addExtraClass('cms-edit-form');
|
|
|
|
$form->addExtraClass('root-form');
|
2011-04-15 05:32:43 +02:00
|
|
|
$form->setTemplate($this->getTemplatesWithSuffix('_EditForm'));
|
2012-04-18 22:11:40 +02:00
|
|
|
$form->setAttribute('data-pjax-fragment', 'CurrentForm');
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2011-03-23 10:51:00 +01:00
|
|
|
return $form;
|
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2012-01-03 18:09:40 +01:00
|
|
|
/**
|
|
|
|
* Return the CMS's HTML-editor toolbar
|
|
|
|
*/
|
|
|
|
public function EditorToolbar() {
|
2012-04-04 16:59:30 +02:00
|
|
|
return HtmlEditorField_Toolbar::create($this, "EditorToolbar");
|
2012-01-03 18:09:40 +01:00
|
|
|
}
|
2012-02-15 13:39:45 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Renders a panel containing tools which apply to all displayed
|
|
|
|
* "content" (mostly through {@link EditForm()}), for example a tree navigation or a filter panel.
|
|
|
|
* Auto-detects applicable templates by naming convention: "<controller classname>_Tools.ss",
|
|
|
|
* and takes the most specific template (see {@link getTemplatesWithSuffix()}).
|
|
|
|
* To explicitly disable the panel in the subclass, simply create a more specific, empty template.
|
2014-08-15 08:53:05 +02:00
|
|
|
*
|
2012-02-15 13:39:45 +01:00
|
|
|
* @return String HTML
|
|
|
|
*/
|
|
|
|
public function Tools() {
|
|
|
|
$templates = $this->getTemplatesWithSuffix('_Tools');
|
|
|
|
if($templates) {
|
|
|
|
$viewer = new SSViewer($templates);
|
2014-08-15 08:53:05 +02:00
|
|
|
return $viewer->process($this);
|
2012-02-15 13:39:45 +01:00
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Renders a panel containing tools which apply to the currently displayed edit form.
|
|
|
|
* The main difference to {@link Tools()} is that the panel is displayed within
|
|
|
|
* the element structure of the form panel (rendered through {@link EditForm}).
|
|
|
|
* This means the panel will be loaded alongside new forms, and refreshed upon save,
|
|
|
|
* which can mean a performance hit, depending on how complex your panel logic gets.
|
|
|
|
* Any form fields contained in the returned markup will also be submitted with the main form,
|
|
|
|
* which might be desired depending on the implementation details.
|
2014-08-15 08:53:05 +02:00
|
|
|
*
|
2012-02-15 13:39:45 +01:00
|
|
|
* @return String HTML
|
|
|
|
*/
|
|
|
|
public function EditFormTools() {
|
|
|
|
$templates = $this->getTemplatesWithSuffix('_EditFormTools');
|
|
|
|
if($templates) {
|
|
|
|
$viewer = new SSViewer($templates);
|
2014-08-15 08:53:05 +02:00
|
|
|
return $viewer->process($this);
|
2012-02-15 13:39:45 +01:00
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2011-03-23 10:51:00 +01:00
|
|
|
/**
|
|
|
|
* Batch Actions Handler
|
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public function batchactions() {
|
2011-03-23 10:51:00 +01:00
|
|
|
return new CMSBatchActionHandler($this, 'batchactions', $this->stat('tree_class'));
|
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2011-03-23 10:51:00 +01:00
|
|
|
/**
|
|
|
|
* @return Form
|
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public function BatchActionsForm() {
|
2011-03-23 10:51:00 +01:00
|
|
|
$actions = $this->batchactions()->batchActionList();
|
2016-01-22 04:02:27 +01:00
|
|
|
$actionsMap = array('-1' => _t('LeftAndMain.DropdownBatchActionsDefault', 'Choose an action...')); // Placeholder action
|
2015-06-16 00:52:42 +02:00
|
|
|
foreach($actions as $action) {
|
|
|
|
$actionsMap[$action->Link] = $action->Title;
|
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2011-03-23 10:51:00 +01:00
|
|
|
$form = new Form(
|
|
|
|
$this,
|
|
|
|
'BatchActionsForm',
|
2011-05-11 09:51:54 +02:00
|
|
|
new FieldList(
|
2011-03-23 10:51:00 +01:00
|
|
|
new HiddenField('csvIDs'),
|
2012-04-04 16:59:30 +02:00
|
|
|
DropdownField::create(
|
2011-03-23 10:51:00 +01:00
|
|
|
'Action',
|
|
|
|
false,
|
|
|
|
$actionsMap
|
2015-06-16 00:52:42 +02:00
|
|
|
)
|
|
|
|
->setAttribute('autocomplete', 'off')
|
2016-01-22 04:02:27 +01:00
|
|
|
->setAttribute('data-placeholder', _t('LeftAndMain.DropdownBatchActionsDefault', 'Choose an action...'))
|
2011-03-23 10:51:00 +01:00
|
|
|
),
|
2011-05-11 09:51:54 +02:00
|
|
|
new FieldList(
|
2011-03-23 10:51:00 +01:00
|
|
|
// TODO i18n
|
2012-08-09 23:55:30 +02:00
|
|
|
new FormAction('submit', _t('Form.SubmitBtnLabel', "Go"))
|
2011-03-23 10:51:00 +01:00
|
|
|
)
|
|
|
|
);
|
2011-04-24 01:05:59 +02:00
|
|
|
$form->addExtraClass('cms-batch-actions nostyle');
|
2011-03-23 10:51:00 +01:00
|
|
|
$form->unsetValidator();
|
2013-09-27 07:46:01 +02:00
|
|
|
|
|
|
|
$this->extend('updateBatchActionsForm', $form);
|
2011-03-23 10:51:00 +01:00
|
|
|
return $form;
|
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2011-03-23 10:51:00 +01:00
|
|
|
public function printable() {
|
|
|
|
$form = $this->getEditForm($this->currentPageID());
|
|
|
|
if(!$form) return false;
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2011-03-23 10:51:00 +01:00
|
|
|
$form->transform(new PrintableTransformation());
|
|
|
|
$form->setActions(null);
|
|
|
|
|
|
|
|
Requirements::clear();
|
2012-03-24 04:38:57 +01:00
|
|
|
Requirements::css(FRAMEWORK_ADMIN_DIR . '/css/LeftAndMain_printable.css');
|
2011-03-23 10:51:00 +01:00
|
|
|
return array(
|
|
|
|
"PrintForm" => $form
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2011-07-21 20:14:33 +02:00
|
|
|
/**
|
|
|
|
* Used for preview controls, mainly links which switch between different states of the page.
|
2014-08-15 08:53:05 +02:00
|
|
|
*
|
2011-07-21 20:14:33 +02:00
|
|
|
* @return ArrayData
|
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public function getSilverStripeNavigator() {
|
2011-07-21 20:14:33 +02:00
|
|
|
$page = $this->currentPage();
|
|
|
|
if($page) {
|
|
|
|
$navigator = new SilverStripeNavigator($page);
|
|
|
|
return $navigator->renderWith($this->getTemplatesWithSuffix('_SilverStripeNavigator'));
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-23 10:51:00 +01:00
|
|
|
/**
|
|
|
|
* Identifier for the currently shown record,
|
|
|
|
* in most cases a database ID. Inspects the following
|
|
|
|
* sources (in this order):
|
|
|
|
* - GET/POST parameter named 'ID'
|
|
|
|
* - URL parameter named 'ID'
|
|
|
|
* - Session value namespaced by classname, e.g. "CMSMain.currentPage"
|
2014-08-15 08:53:05 +02:00
|
|
|
*
|
|
|
|
* @return int
|
2011-03-23 10:51:00 +01:00
|
|
|
*/
|
|
|
|
public function currentPageID() {
|
2015-04-30 01:04:08 +02:00
|
|
|
if($this->getRequest()->requestVar('ID') && is_numeric($this->getRequest()->requestVar('ID'))) {
|
|
|
|
return $this->getRequest()->requestVar('ID');
|
2012-02-28 18:48:02 +01:00
|
|
|
} elseif (isset($this->urlParams['ID']) && is_numeric($this->urlParams['ID'])) {
|
|
|
|
return $this->urlParams['ID'];
|
2012-08-28 00:25:58 +02:00
|
|
|
} elseif(Session::get($this->sessionNamespace() . ".currentPage")) {
|
|
|
|
return Session::get($this->sessionNamespace() . ".currentPage");
|
2011-03-23 10:51:00 +01:00
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Forces the current page to be set in session,
|
|
|
|
* which can be retrieved later through {@link currentPageID()}.
|
|
|
|
* Keep in mind that setting an ID through GET/POST or
|
|
|
|
* as a URL parameter will overrule this value.
|
2014-08-15 08:53:05 +02:00
|
|
|
*
|
2011-03-23 10:51:00 +01:00
|
|
|
* @param int $id
|
|
|
|
*/
|
|
|
|
public function setCurrentPageID($id) {
|
2012-08-28 00:25:58 +02:00
|
|
|
Session::set($this->sessionNamespace() . ".currentPage", $id);
|
2011-03-23 10:51:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Uses {@link getRecord()} and {@link currentPageID()}
|
|
|
|
* to get the currently selected record.
|
2014-08-15 08:53:05 +02:00
|
|
|
*
|
2011-03-23 10:51:00 +01:00
|
|
|
* @return DataObject
|
|
|
|
*/
|
|
|
|
public function currentPage() {
|
|
|
|
return $this->getRecord($this->currentPageID());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Compares a given record to the currently selected one (if any).
|
|
|
|
* Used for marking the current tree node.
|
2014-08-15 08:53:05 +02:00
|
|
|
*
|
2011-03-23 10:51:00 +01:00
|
|
|
* @return boolean
|
|
|
|
*/
|
|
|
|
public function isCurrentPage(DataObject $record) {
|
|
|
|
return ($record->ID == $this->currentPageID());
|
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2012-08-28 00:25:58 +02:00
|
|
|
/**
|
|
|
|
* @return String
|
|
|
|
*/
|
|
|
|
protected function sessionNamespace() {
|
|
|
|
$override = $this->stat('session_namespace');
|
|
|
|
return $override ? $override : $this->class;
|
|
|
|
}
|
|
|
|
|
2011-03-23 10:51:00 +01:00
|
|
|
/**
|
2011-05-15 05:43:21 +02:00
|
|
|
* URL to a previewable record which is shown through this controller.
|
2014-08-15 08:53:05 +02:00
|
|
|
* The controller might not have any previewable content, in which case
|
2011-05-15 05:43:21 +02:00
|
|
|
* this method returns FALSE.
|
2014-08-15 08:53:05 +02:00
|
|
|
*
|
2011-05-15 05:43:21 +02:00
|
|
|
* @return String|boolean
|
2011-03-23 10:51:00 +01:00
|
|
|
*/
|
2012-04-18 22:59:18 +02:00
|
|
|
public function LinkPreview() {
|
2011-10-29 19:12:33 +02:00
|
|
|
return false;
|
2011-05-15 05:43:21 +02:00
|
|
|
}
|
2011-03-23 10:51:00 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the version number of this application.
|
2013-02-28 13:38:19 +01:00
|
|
|
* Uses the number in <mymodule>/silverstripe_version
|
|
|
|
* (automatically replaced by build scripts).
|
|
|
|
* If silverstripe_version is empty,
|
|
|
|
* then attempts to get it from composer.lock
|
|
|
|
*
|
2011-03-23 10:51:00 +01:00
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function CMSVersion() {
|
2013-02-28 13:38:19 +01:00
|
|
|
$versions = array();
|
|
|
|
$modules = array(
|
|
|
|
'silverstripe/framework' => array(
|
|
|
|
'title' => 'Framework',
|
|
|
|
'versionFile' => FRAMEWORK_PATH . '/silverstripe_version',
|
|
|
|
)
|
2012-02-01 18:30:34 +01:00
|
|
|
);
|
2013-02-28 13:38:19 +01:00
|
|
|
if(defined('CMS_PATH')) {
|
|
|
|
$modules['silverstripe/cms'] = array(
|
|
|
|
'title' => 'CMS',
|
|
|
|
'versionFile' => CMS_PATH . '/silverstripe_version',
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Tries to obtain version number from composer.lock if it exists
|
|
|
|
$composerLockPath = BASE_PATH . '/composer.lock';
|
|
|
|
if (file_exists($composerLockPath)) {
|
|
|
|
$cache = SS_Cache::factory('LeftAndMain_CMSVersion');
|
|
|
|
$cacheKey = filemtime($composerLockPath);
|
|
|
|
$versions = $cache->load($cacheKey);
|
2013-03-28 14:45:23 +01:00
|
|
|
if($versions) {
|
|
|
|
$versions = json_decode($versions, true);
|
|
|
|
} else {
|
|
|
|
$versions = array();
|
|
|
|
}
|
2013-02-28 13:38:19 +01:00
|
|
|
if(!$versions && $jsonData = file_get_contents($composerLockPath)) {
|
|
|
|
$lockData = json_decode($jsonData);
|
|
|
|
if($lockData && isset($lockData->packages)) {
|
|
|
|
foreach ($lockData->packages as $package) {
|
|
|
|
if(
|
|
|
|
array_key_exists($package->name, $modules)
|
|
|
|
&& isset($package->version)
|
|
|
|
) {
|
|
|
|
$versions[$package->name] = $package->version;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$cache->save(json_encode($versions), $cacheKey);
|
|
|
|
}
|
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
}
|
|
|
|
|
2013-02-28 13:38:19 +01:00
|
|
|
// Fall back to static version file
|
|
|
|
foreach($modules as $moduleName => $moduleSpec) {
|
|
|
|
if(!isset($versions[$moduleName])) {
|
|
|
|
if($staticVersion = file_get_contents($moduleSpec['versionFile'])) {
|
2014-08-15 08:53:05 +02:00
|
|
|
$versions[$moduleName] = $staticVersion;
|
2013-02-28 13:38:19 +01:00
|
|
|
} else {
|
2014-08-15 08:53:05 +02:00
|
|
|
$versions[$moduleName] = _t('LeftAndMain.VersionUnknown', 'Unknown');
|
2013-02-28 13:38:19 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$out = array();
|
|
|
|
foreach($modules as $moduleName => $moduleSpec) {
|
|
|
|
$out[] = $modules[$moduleName]['title'] . ': ' . $versions[$moduleName];
|
|
|
|
}
|
|
|
|
return implode(', ', $out);
|
2011-03-23 10:51:00 +01:00
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2011-03-23 10:51:00 +01:00
|
|
|
/**
|
|
|
|
* @return array
|
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public function SwitchView() {
|
2014-08-15 08:53:05 +02:00
|
|
|
if($page = $this->currentPage()) {
|
|
|
|
$nav = SilverStripeNavigator::get_for_record($page);
|
|
|
|
return $nav['items'];
|
|
|
|
}
|
2011-03-23 10:51:00 +01:00
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2011-04-15 04:12:57 +02:00
|
|
|
/**
|
|
|
|
* @return SiteConfig
|
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public function SiteConfig() {
|
2011-05-01 12:20:30 +02:00
|
|
|
return (class_exists('SiteConfig')) ? SiteConfig::current_site_config() : null;
|
2011-04-15 04:12:57 +02:00
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2012-10-24 15:42:48 +02:00
|
|
|
/**
|
|
|
|
* The href for the anchor on the Silverstripe logo.
|
|
|
|
* Set by calling LeftAndMain::set_application_link()
|
|
|
|
*
|
2013-03-21 19:48:54 +01:00
|
|
|
* @config
|
2012-10-24 15:42:48 +02:00
|
|
|
* @var String
|
|
|
|
*/
|
2015-03-26 03:20:21 +01:00
|
|
|
private static $application_link = '//www.silverstripe.org/';
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2012-10-24 15:42:48 +02:00
|
|
|
/**
|
|
|
|
* Sets the href for the anchor on the Silverstripe logo in the menu
|
2015-08-14 02:39:33 +02:00
|
|
|
*
|
2015-06-19 01:59:27 +02:00
|
|
|
* @deprecated since version 4.0
|
2012-10-24 15:42:48 +02:00
|
|
|
*
|
|
|
|
* @param String $link
|
|
|
|
*/
|
2014-08-15 08:53:05 +02:00
|
|
|
public static function set_application_link($link) {
|
2015-06-19 01:59:27 +02:00
|
|
|
Deprecation::notice('4.0', 'Use the "LeftAndMain.application_link" config setting instead');
|
2013-03-21 19:48:54 +01:00
|
|
|
Config::inst()->update('LeftAndMain', 'application_link', $link);
|
2012-10-24 15:42:48 +02:00
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2012-10-24 15:42:48 +02:00
|
|
|
/**
|
|
|
|
* @return String
|
|
|
|
*/
|
|
|
|
public function ApplicationLink() {
|
2013-03-21 19:48:54 +01:00
|
|
|
return $this->stat('application_link');
|
2012-10-24 15:42:48 +02:00
|
|
|
}
|
2011-03-23 10:51:00 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The application name. Customisable by calling
|
|
|
|
* LeftAndMain::setApplicationName() - the first parameter.
|
2013-03-21 19:48:54 +01:00
|
|
|
*
|
|
|
|
* @config
|
2011-03-23 10:51:00 +01:00
|
|
|
* @var String
|
|
|
|
*/
|
2013-03-21 19:48:54 +01:00
|
|
|
private static $application_name = 'SilverStripe';
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2011-03-23 10:51:00 +01:00
|
|
|
/**
|
|
|
|
* @param String $name
|
2015-06-19 01:59:27 +02:00
|
|
|
* @deprecated since version 4.0
|
2011-03-23 10:51:00 +01:00
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public static function setApplicationName($name) {
|
2015-06-19 01:59:27 +02:00
|
|
|
Deprecation::notice('4.0', 'Use the "LeftAndMain.application_name" config setting instead');
|
2013-03-21 19:48:54 +01:00
|
|
|
Config::inst()->update('LeftAndMain', 'application_name', $name);
|
2011-03-23 10:51:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the application name.
|
2011-08-22 06:44:41 +02:00
|
|
|
*
|
|
|
|
* @return string
|
2011-03-23 10:51:00 +01:00
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public function getApplicationName() {
|
2013-03-21 19:48:54 +01:00
|
|
|
return $this->stat('application_name');
|
2011-03-23 10:51:00 +01:00
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2011-06-09 05:47:59 +02:00
|
|
|
/**
|
2011-08-22 06:44:41 +02:00
|
|
|
* @return string
|
2011-06-09 05:47:59 +02:00
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public function Title() {
|
2011-08-22 06:44:41 +02:00
|
|
|
$app = $this->getApplicationName();
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2011-08-22 06:44:41 +02:00
|
|
|
return ($section = $this->SectionTitle()) ? sprintf('%s - %s', $app, $section) : $app;
|
2011-06-09 05:47:59 +02:00
|
|
|
}
|
2011-03-23 10:51:00 +01:00
|
|
|
|
|
|
|
/**
|
2011-08-22 06:44:41 +02:00
|
|
|
* Return the title of the current section. Either this is pulled from
|
|
|
|
* the current panel's menu_title or from the first active menu
|
|
|
|
*
|
|
|
|
* @return string
|
2011-03-23 10:51:00 +01:00
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public function SectionTitle() {
|
2012-08-26 23:13:42 +02:00
|
|
|
$class = get_class($this);
|
|
|
|
$defaultTitle = LeftAndMain::menu_title_for_class($class);
|
|
|
|
if($title = _t("{$class}.MENUTITLE", $defaultTitle)) return $title;
|
|
|
|
|
2012-05-03 13:49:19 +02:00
|
|
|
foreach($this->MainMenu() as $menuItem) {
|
2011-08-22 06:44:41 +02:00
|
|
|
if($menuItem->LinkingMode != 'link') return $menuItem->Title;
|
2011-03-23 10:51:00 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-04 16:36:24 +02:00
|
|
|
/**
|
|
|
|
* Same as {@link ViewableData->CSSClasses()}, but with a changed name
|
|
|
|
* to avoid problems when using {@link ViewableData->customise()}
|
|
|
|
* (which always returns "ArrayData" from the $original object).
|
2014-08-15 08:53:05 +02:00
|
|
|
*
|
2011-07-04 16:36:24 +02:00
|
|
|
* @return String
|
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public function BaseCSSClasses() {
|
2012-03-12 14:05:54 +01:00
|
|
|
return $this->CSSClasses('Controller');
|
2011-07-04 16:36:24 +02:00
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2011-12-18 16:57:26 +01:00
|
|
|
/**
|
|
|
|
* @return String
|
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public function Locale() {
|
2012-03-27 06:57:42 +02:00
|
|
|
return DBField::create_field('DBLocale', i18n::get_locale());
|
2011-12-18 16:57:26 +01:00
|
|
|
}
|
2012-03-05 16:07:20 +01:00
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function providePermissions() {
|
2012-03-05 16:07:20 +01:00
|
|
|
$perms = array(
|
|
|
|
"CMS_ACCESS_LeftAndMain" => array(
|
|
|
|
'name' => _t('CMSMain.ACCESSALLINTERFACES', 'Access to all CMS sections'),
|
|
|
|
'category' => _t('Permission.CMS_ACCESS_CATEGORY', 'CMS Access'),
|
|
|
|
'help' => _t('CMSMain.ACCESSALLINTERFACESHELP', 'Overrules more specific access settings.'),
|
|
|
|
'sort' => -100
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
// Add any custom ModelAdmin subclasses. Can't put this on ModelAdmin itself
|
|
|
|
// since its marked abstract, and needs to be singleton instanciated.
|
|
|
|
foreach(ClassInfo::subclassesFor('ModelAdmin') as $i => $class) {
|
|
|
|
if($class == 'ModelAdmin') continue;
|
|
|
|
if(ClassInfo::classImplements($class, 'TestOnly')) continue;
|
|
|
|
|
|
|
|
$title = _t("{$class}.MENUTITLE", LeftAndMain::menu_title_for_class($class));
|
|
|
|
$perms["CMS_ACCESS_" . $class] = array(
|
2012-05-01 21:44:54 +02:00
|
|
|
'name' => _t(
|
2014-08-15 08:53:05 +02:00
|
|
|
'CMSMain.ACCESS',
|
2012-05-01 21:44:54 +02:00
|
|
|
"Access to '{title}' section",
|
|
|
|
"Item in permission selection identifying the admin section. Example: Access to 'Files & Images'",
|
|
|
|
array('title' => $title)
|
|
|
|
),
|
2012-03-05 16:07:20 +01:00
|
|
|
'category' => _t('Permission.CMS_ACCESS_CATEGORY', 'CMS Access')
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $perms;
|
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2011-03-23 10:51:00 +01:00
|
|
|
/**
|
|
|
|
* Register the given javascript file as required in the CMS.
|
2016-01-11 02:25:30 +01:00
|
|
|
* Filenames should be relative to the base, eg, FRAMEWORK_DIR . '/javascript/dist/loader.js'
|
2015-08-14 02:39:33 +02:00
|
|
|
*
|
2015-06-19 01:59:27 +02:00
|
|
|
* @deprecated since version 4.0
|
2011-03-23 10:51:00 +01:00
|
|
|
*/
|
|
|
|
public static function require_javascript($file) {
|
2015-06-19 01:59:27 +02:00
|
|
|
Deprecation::notice('4.0', 'Use "LeftAndMain.extra_requirements_javascript" config setting instead');
|
2013-03-21 19:48:54 +01:00
|
|
|
Config::inst()->update('LeftAndMain', 'extra_requirements_javascript', array($file => array()));
|
2011-03-23 10:51:00 +01:00
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2011-03-23 10:51:00 +01:00
|
|
|
/**
|
|
|
|
* Register the given stylesheet file as required.
|
2015-06-19 01:59:27 +02:00
|
|
|
* @deprecated since version 4.0
|
2014-08-15 08:53:05 +02:00
|
|
|
*
|
2011-03-23 10:51:00 +01:00
|
|
|
* @param $file String Filenames should be relative to the base, eg, THIRDPARTY_DIR . '/tree/tree.css'
|
2014-08-15 08:53:05 +02:00
|
|
|
* @param $media String Comma-separated list of media-types (e.g. "screen,projector")
|
2011-03-23 10:51:00 +01:00
|
|
|
* @see http://www.w3.org/TR/REC-CSS2/media.html
|
|
|
|
*/
|
|
|
|
public static function require_css($file, $media = null) {
|
2015-06-19 01:59:27 +02:00
|
|
|
Deprecation::notice('4.0', 'Use "LeftAndMain.extra_requirements_css" config setting instead');
|
2013-03-21 19:48:54 +01:00
|
|
|
Config::inst()->update('LeftAndMain', 'extra_requirements_css', array($file => array('media' => $media)));
|
2011-03-23 10:51:00 +01:00
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2011-03-23 10:51:00 +01:00
|
|
|
/**
|
|
|
|
* Register the given "themeable stylesheet" as required.
|
|
|
|
* Themeable stylesheets have globally unique names, just like templates and PHP files.
|
|
|
|
* Because of this, they can be replaced by similarly named CSS files in the theme directory.
|
2015-08-14 02:39:33 +02:00
|
|
|
*
|
2015-06-19 01:59:27 +02:00
|
|
|
* @deprecated since version 4.0
|
2014-08-15 08:53:05 +02:00
|
|
|
*
|
2011-03-23 10:51:00 +01:00
|
|
|
* @param $name String The identifier of the file. For example, css/MyFile.css would have the identifier "MyFile"
|
2014-08-15 08:53:05 +02:00
|
|
|
* @param $media String Comma-separated list of media-types (e.g. "screen,projector")
|
2011-03-23 10:51:00 +01:00
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public static function require_themed_css($name, $media = null) {
|
2015-06-19 01:59:27 +02:00
|
|
|
Deprecation::notice('4.0', 'Use "LeftAndMain.extra_requirements_themedCss" config setting instead');
|
2013-05-28 16:48:23 +02:00
|
|
|
Config::inst()->update('LeftAndMain', 'extra_requirements_themedCss', array($name => array('media' => $media)));
|
2011-03-23 10:51:00 +01:00
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2011-03-23 10:51:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @package cms
|
|
|
|
* @subpackage core
|
|
|
|
*/
|
|
|
|
class LeftAndMainMarkingFilter {
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2011-03-23 10:51:00 +01:00
|
|
|
/**
|
|
|
|
* @var array Request params (unsanitized)
|
|
|
|
*/
|
|
|
|
protected $params = array();
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2011-03-23 10:51:00 +01:00
|
|
|
/**
|
|
|
|
* @param array $params Request params (unsanitized)
|
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public function __construct($params = null) {
|
2011-03-23 10:51:00 +01:00
|
|
|
$this->ids = array();
|
|
|
|
$this->expanded = array();
|
|
|
|
$parents = array();
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2011-03-23 10:51:00 +01:00
|
|
|
$q = $this->getQuery($params);
|
|
|
|
$res = $q->execute();
|
|
|
|
if (!$res) return;
|
2014-08-15 08:53:05 +02:00
|
|
|
|
|
|
|
// And keep a record of parents we don't need to get parents
|
2011-03-23 10:51:00 +01:00
|
|
|
// of themselves, as well as IDs to mark
|
|
|
|
foreach($res as $row) {
|
|
|
|
if ($row['ParentID']) $parents[$row['ParentID']] = true;
|
|
|
|
$this->ids[$row['ID']] = true;
|
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
|
|
|
// We need to recurse up the tree,
|
2011-03-23 10:51:00 +01:00
|
|
|
// finding ParentIDs for each ID until we run out of parents
|
|
|
|
while (!empty($parents)) {
|
2013-06-21 00:32:08 +02:00
|
|
|
$parentsClause = DB::placeholders($parents);
|
|
|
|
$res = DB::prepared_query(
|
|
|
|
"SELECT \"ParentID\", \"ID\" FROM \"SiteTree\" WHERE \"ID\" in ($parentsClause)",
|
|
|
|
array_keys($parents)
|
|
|
|
);
|
2011-03-23 10:51:00 +01:00
|
|
|
$parents = array();
|
|
|
|
|
|
|
|
foreach($res as $row) {
|
|
|
|
if ($row['ParentID']) $parents[$row['ParentID']] = true;
|
|
|
|
$this->ids[$row['ID']] = true;
|
|
|
|
$this->expanded[$row['ID']] = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2011-03-23 10:51:00 +01:00
|
|
|
protected function getQuery($params) {
|
|
|
|
$where = array();
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2013-06-21 00:32:08 +02:00
|
|
|
if(isset($params['ID'])) unset($params['ID']);
|
|
|
|
if($treeClass = static::config()->tree_class) foreach($params as $name => $val) {
|
|
|
|
// Partial string match against a variety of fields
|
|
|
|
if(!empty($val) && singleton($treeClass)->hasDatabaseField($name)) {
|
|
|
|
$predicate = sprintf('"%s" LIKE ?', $name);
|
|
|
|
$where[$predicate] = "%$val%";
|
2011-03-23 10:51:00 +01:00
|
|
|
}
|
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2013-06-21 00:32:08 +02:00
|
|
|
return new SQLSelect(
|
2011-03-23 10:51:00 +01:00
|
|
|
array("ParentID", "ID"),
|
|
|
|
'SiteTree',
|
|
|
|
$where
|
|
|
|
);
|
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function mark($node) {
|
2011-03-23 10:51:00 +01:00
|
|
|
$id = $node->ID;
|
|
|
|
if(array_key_exists((int) $id, $this->expanded)) $node->markOpened();
|
|
|
|
return array_key_exists((int) $id, $this->ids) ? $this->ids[$id] : false;
|
|
|
|
}
|
|
|
|
}
|
2012-02-12 21:22:11 +01:00
|
|
|
|
2012-07-16 23:30:59 +02:00
|
|
|
/**
|
|
|
|
* Allow overriding finished state for faux redirects.
|
2013-05-20 12:18:07 +02:00
|
|
|
*
|
|
|
|
* @package framework
|
|
|
|
* @subpackage admin
|
2012-07-16 23:30:59 +02:00
|
|
|
*/
|
|
|
|
class LeftAndMain_HTTPResponse extends SS_HTTPResponse {
|
|
|
|
|
|
|
|
protected $isFinished = false;
|
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function isFinished() {
|
2012-07-16 23:30:59 +02:00
|
|
|
return (parent::isFinished() || $this->isFinished);
|
|
|
|
}
|
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function setIsFinished($bool) {
|
2012-07-16 23:30:59 +02:00
|
|
|
$this->isFinished = $bool;
|
|
|
|
}
|
|
|
|
|
2012-07-18 13:51:12 +02:00
|
|
|
}
|
2012-07-17 15:04:27 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Wrapper around objects being displayed in a tree.
|
|
|
|
* Caution: Volatile API.
|
|
|
|
*
|
2013-05-20 12:18:07 +02:00
|
|
|
* @todo Implement recursive tree node rendering.
|
|
|
|
*
|
|
|
|
* @package framework
|
|
|
|
* @subpackage admin
|
2012-07-17 15:04:27 +02:00
|
|
|
*/
|
|
|
|
class LeftAndMain_TreeNode extends ViewableData {
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2012-07-17 15:04:27 +02:00
|
|
|
/**
|
2015-04-30 07:12:53 +02:00
|
|
|
* Object represented by this node
|
|
|
|
*
|
|
|
|
* @var Object
|
2012-07-17 15:04:27 +02:00
|
|
|
*/
|
|
|
|
protected $obj;
|
|
|
|
|
|
|
|
/**
|
2015-04-30 07:12:53 +02:00
|
|
|
* Edit link to the current record in the CMS
|
|
|
|
*
|
|
|
|
* @var string
|
2012-07-17 15:04:27 +02:00
|
|
|
*/
|
|
|
|
protected $link;
|
|
|
|
|
|
|
|
/**
|
2015-04-30 07:12:53 +02:00
|
|
|
* True if this is the currently selected node in the tree
|
|
|
|
*
|
|
|
|
* @var bool
|
2012-07-17 15:04:27 +02:00
|
|
|
*/
|
|
|
|
protected $isCurrent;
|
|
|
|
|
2014-07-20 01:49:17 +02:00
|
|
|
/**
|
2015-04-30 07:12:53 +02:00
|
|
|
* Name of method to count the number of children
|
2015-08-14 02:39:33 +02:00
|
|
|
*
|
2014-07-20 01:49:17 +02:00
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $numChildrenMethod;
|
|
|
|
|
2015-04-30 07:12:53 +02:00
|
|
|
|
2014-07-20 01:49:17 +02:00
|
|
|
/**
|
2015-04-30 07:12:53 +02:00
|
|
|
*
|
|
|
|
* @var LeftAndMain_SearchFilter
|
|
|
|
*/
|
|
|
|
protected $filter;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param Object $obj
|
|
|
|
* @param string $link
|
2014-07-20 01:49:17 +02:00
|
|
|
* @param bool $isCurrent
|
2015-04-30 07:12:53 +02:00
|
|
|
* @param string $numChildrenMethod
|
|
|
|
* @param LeftAndMain_SearchFilter $filter
|
2014-07-20 01:49:17 +02:00
|
|
|
*/
|
2015-04-30 07:12:53 +02:00
|
|
|
public function __construct($obj, $link = null, $isCurrent = false,
|
|
|
|
$numChildrenMethod = 'numChildren', $filter = null
|
|
|
|
) {
|
|
|
|
parent::__construct();
|
2012-07-17 15:04:27 +02:00
|
|
|
$this->obj = $obj;
|
|
|
|
$this->link = $link;
|
|
|
|
$this->isCurrent = $isCurrent;
|
2014-07-20 01:49:17 +02:00
|
|
|
$this->numChildrenMethod = $numChildrenMethod;
|
2015-04-30 07:12:53 +02:00
|
|
|
$this->filter = $filter;
|
2012-07-17 15:04:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns template, for further processing by {@link Hierarchy->getChildrenAsUL()}.
|
|
|
|
* Does not include closing tag to allow this method to inject its own children.
|
|
|
|
*
|
|
|
|
* @todo Remove hardcoded assumptions around returning an <li>, by implementing recursive tree node rendering
|
2014-08-15 08:53:05 +02:00
|
|
|
*
|
2012-07-17 15:04:27 +02:00
|
|
|
* @return String
|
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public function forTemplate() {
|
2012-07-17 15:04:27 +02:00
|
|
|
$obj = $this->obj;
|
2012-09-26 23:34:00 +02:00
|
|
|
return "<li id=\"record-$obj->ID\" data-id=\"$obj->ID\" data-pagetype=\"$obj->ClassName\" class=\""
|
|
|
|
. $this->getClasses() . "\">" . "<ins class=\"jstree-icon\"> </ins>"
|
2015-07-16 17:49:43 +02:00
|
|
|
. "<a href=\"" . $this->getLink() . "\" title=\"("
|
|
|
|
. trim(_t('LeftAndMain.PAGETYPE','Page type'), " :") // account for inconsistencies in translations
|
|
|
|
. ": " . $obj->i18n_singular_name() . ") $obj->Title\" ><ins class=\"jstree-icon\"> </ins><span class=\"text\">" . ($obj->TreeTitle)
|
2012-09-26 23:34:00 +02:00
|
|
|
. "</span></a>";
|
2012-07-17 15:04:27 +02:00
|
|
|
}
|
|
|
|
|
2015-04-30 07:12:53 +02:00
|
|
|
/**
|
|
|
|
* Determine the CSS classes to apply to this node
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public function getClasses() {
|
2015-04-30 07:12:53 +02:00
|
|
|
// Get classes from object
|
2014-07-20 01:49:17 +02:00
|
|
|
$classes = $this->obj->CMSTreeClasses($this->numChildrenMethod);
|
2015-04-30 07:12:53 +02:00
|
|
|
if($this->isCurrent) {
|
|
|
|
$classes .= ' current';
|
|
|
|
}
|
|
|
|
// Get status flag classes
|
|
|
|
$flags = $this->obj->hasMethod('getStatusFlags')
|
|
|
|
? $this->obj->getStatusFlags()
|
|
|
|
: false;
|
2013-05-28 16:25:25 +02:00
|
|
|
if ($flags) {
|
|
|
|
$statuses = array_keys($flags);
|
|
|
|
foreach ($statuses as $s) {
|
|
|
|
$classes .= ' status-' . $s;
|
|
|
|
}
|
|
|
|
}
|
2015-04-30 07:12:53 +02:00
|
|
|
// Get additional filter classes
|
|
|
|
if($this->filter && ($filterClasses = $this->filter->getPageClasses($this->obj))) {
|
|
|
|
if(is_array($filterClasses)) {
|
|
|
|
$filterClasses = implode(' ' . $filterClasses);
|
|
|
|
}
|
|
|
|
$classes .= ' ' . $filterClasses;
|
|
|
|
}
|
2012-07-17 15:04:27 +02:00
|
|
|
return $classes;
|
|
|
|
}
|
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function getObj() {
|
2012-07-17 15:04:27 +02:00
|
|
|
return $this->obj;
|
|
|
|
}
|
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function setObj($obj) {
|
2012-07-17 15:04:27 +02:00
|
|
|
$this->obj = $obj;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function getLink() {
|
2012-07-17 15:04:27 +02:00
|
|
|
return $this->link;
|
|
|
|
}
|
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function setLink($link) {
|
2012-07-17 15:04:27 +02:00
|
|
|
$this->link = $link;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function getIsCurrent() {
|
2012-07-17 15:04:27 +02:00
|
|
|
return $this->isCurrent;
|
|
|
|
}
|
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function setIsCurrent($bool) {
|
2012-07-17 15:04:27 +02:00
|
|
|
$this->isCurrent = $bool;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2012-08-27 04:41:07 +02:00
|
|
|
}
|
2015-04-30 07:12:53 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Abstract interface for a class which may be used to filter the results displayed
|
|
|
|
* in a nested tree
|
|
|
|
*/
|
|
|
|
interface LeftAndMain_SearchFilter {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Method on {@link Hierarchy} objects which is used to traverse into children relationships.
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getChildrenMethod();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Method on {@link Hierarchy} objects which is used find the number of children for a parent page
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getNumChildrenMethod();
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns TRUE if the given page should be included in the tree.
|
|
|
|
* Caution: Does NOT check view permissions on the page.
|
|
|
|
*
|
|
|
|
* @param DataObject $page
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function isPageIncluded($page);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Given a page, determine any additional CSS classes to apply to the tree node
|
|
|
|
*
|
|
|
|
* @param DataObject $page
|
|
|
|
* @return array|string
|
|
|
|
*/
|
|
|
|
public function getPageClasses($page);
|
|
|
|
}
|