2007-07-19 12:40:05 +02:00
< ? php
/**
* 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 .
2008-04-05 05:43:58 +02:00
*
* This is essentially an abstract class which should be subclassed .
* See { @ link CMSMain } for a good example .
*
2008-02-25 03:10:37 +01:00
* @ package cms
* @ subpackage core
2007-07-19 12:40:05 +02:00
*/
2008-04-05 05:43:58 +02:00
class LeftAndMain extends Controller {
/**
2008-11-02 22:27:55 +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
2008-04-05 05:43:58 +02:00
*
2008-11-02 22:27:55 +01:00
* @ var string $url_base
2008-04-05 05:43:58 +02:00
*/
2009-01-05 07:17:59 +01:00
static $url_base = " admin " ;
2008-11-02 22:27:55 +01:00
static $url_segment ;
2008-12-04 23:38:58 +01:00
static $url_rule = '/$Action/$ID/$OtherID' ;
2008-11-02 22:27:55 +01:00
static $menu_title ;
static $menu_priority = 0 ;
static $url_priority = 50 ;
2009-11-21 04:20:36 +01:00
/**
* @ var string A subclass of { @ link DataObject } .
* Determines what is managed in this interface ,
* through { @ link getEditForm ()} and other logic .
*/
2008-11-02 22:27:55 +01:00
static $tree_class = null ;
2007-09-14 21:26:56 +02:00
2008-02-25 03:10:37 +01:00
static $allowed_actions = array (
2009-09-10 03:38:29 +02:00
'index' ,
2008-02-25 03:10:37 +01:00
'ajaxupdateparent' ,
'ajaxupdatesort' ,
'getitem' ,
'getsubtree' ,
'myprofile' ,
'printable' ,
'save' ,
'show' ,
2008-08-09 07:57:44 +02:00
'Member_ProfileForm' ,
'EditorToolbar' ,
2008-08-11 02:03:57 +02:00
'EditForm' ,
2009-11-21 04:20:21 +01:00
'BatchActionsForm' ,
'batchactions' ,
2009-11-21 04:20:41 +01:00
'AddForm' ,
'doAdd'
2008-02-25 03:10:37 +01:00
);
2008-07-17 23:08:35 +02:00
/**
* Register additional requirements through the { @ link Requirements class } .
* Used mainly to work around the missing " lazy loading " functionality
* for getting css / javascript required after an ajax - call ( e . g . loading the editform ) .
*
* @ var array $extra_requirements
*/
protected static $extra_requirements = array (
'javascript' => array (),
'css' => array (),
'themedcss' => array (),
);
2009-01-05 07:17:59 +01:00
/**
* @ param Member $member
* @ return boolean
*/
function canView ( $member = null ) {
if ( ! $member && $member !== FALSE ) {
$member = Member :: currentUser ();
}
// cms menus only for logged-in members
if ( ! $member ) return false ;
// alternative decorated checks
if ( $this -> hasMethod ( 'alternateAccessCheck' )) {
$alternateAllowed = $this -> alternateAccessCheck ();
if ( $alternateAllowed === FALSE ) return false ;
}
// Default security check for LeftAndMain sub-class permissions
2010-04-12 10:44:29 +02:00
if ( ! Permission :: checkMember ( $member , " CMS_ACCESS_ $this->class " ) &&
! Permission :: checkMember ( $member , " CMS_ACCESS_LeftAndMain " )) {
2009-01-05 07:17:59 +01:00
return false ;
}
return true ;
}
2008-11-07 13:21:10 +01:00
/**
* @ uses LeftAndMainDecorator -> init ()
* @ uses LeftAndMainDecorator -> accessedCMS ()
2009-01-05 07:17:59 +01:00
* @ uses CMSMenu
2008-11-07 13:21:10 +01:00
*/
2007-07-19 12:40:05 +02:00
function init () {
2009-01-05 07:17:59 +01:00
parent :: init ();
2007-09-27 22:56:55 +02:00
2009-11-21 03:36:02 +01:00
SSViewer :: setOption ( 'rewriteHashlinks' , false );
2007-09-27 22:56:55 +02:00
// set language
$member = Member :: currentUser ();
2007-10-21 21:53:57 +02:00
if ( ! empty ( $member -> Locale )) {
i18n :: set_locale ( $member -> Locale );
2007-09-27 22:56:55 +02:00
}
2007-11-13 01:14:15 +01:00
2009-01-05 07:17:59 +01:00
// can't be done in cms/_config.php as locale is not set yet
CMSMenu :: add_link (
'Help' ,
_t ( 'LeftAndMain.HELP' , 'Help' , PR_HIGH , 'Menu title' ),
2009-11-21 02:58:26 +01:00
'http://userhelp.silverstripe.org'
2009-01-05 07:17:59 +01:00
);
2007-11-13 01:14:15 +01:00
// set reading lang
2009-11-30 02:04:56 +01:00
if ( Object :: has_extension ( 'SiteTree' , 'Translatable' ) && ! Director :: is_ajax ()) {
2009-04-03 23:26:51 +02:00
Translatable :: choose_site_locale ( array_keys ( Translatable :: get_existing_content_languages ( 'SiteTree' )));
2007-11-13 01:14:15 +01:00
}
2007-09-14 21:26:56 +02:00
2007-08-31 02:31:49 +02:00
// Allow customisation of the access check by a decorator
2010-04-13 05:26:55 +02:00
// Also all the canView() check to execute Director::redirect()
if ( ! $this -> canView () && ! $this -> response -> isFinished ()) {
2009-01-05 07:17:59 +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 (
$candidate -> Link &&
$candidate -> Link != $this -> Link ()
&& $candidate -> MenuItem -> controller
&& singleton ( $candidate -> MenuItem -> controller ) -> canView ()
) {
return Director :: redirect ( $candidate -> Link );
2007-07-19 12:40:05 +02:00
}
}
2009-01-05 07:17:59 +01:00
if ( Member :: currentUser ()) {
Session :: set ( " BackURL " , null );
}
// if no alternate menu items have matched, return a permission error
2007-07-19 12:40:05 +02:00
$messageSet = array (
2007-09-15 22:21:13 +02:00
'default' => _t ( 'LeftAndMain.PERMDEFAULT' , " Please choose an authentication method and enter your credentials to access the CMS. " ),
'alreadyLoggedIn' => _t ( 'LeftAndMain.PERMALREADY' , " I'm sorry, but you can't access that part of the CMS. If you want to log in as someone else, do so below " ),
'logInAgain' => _t ( 'LeftAndMain.PERMAGAIN' , " You have been logged out of the CMS. If you would like to log in again, enter a username and password below. " ),
2007-07-19 12:40:05 +02:00
);
2009-01-05 07:17:59 +01:00
return Security :: permissionFailure ( $this , $messageSet );
2007-07-19 12:40:05 +02:00
}
2010-04-13 05:26:55 +02:00
2009-01-05 07:17:59 +01:00
// Don't continue if there's already been a redirection request.
if ( Director :: redirected_to ()) return ;
2008-08-13 02:14:31 +02:00
// Audit logging hook
if ( empty ( $_REQUEST [ 'executeForm' ]) && ! Director :: is_ajax ()) $this -> extend ( 'accessedCMS' );
2009-05-14 08:11:18 +02:00
2009-08-10 06:34:17 +02:00
// Set the members html editor config
HtmlEditorConfig :: set_active ( Member :: currentUser () -> getHtmlEditorConfigForCMS ());
2009-12-16 06:58:37 +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 ();
if ( ! $htmlEditorConfig -> getOption ( 'content_css' )) {
$cssFiles = 'cms/css/editor.css' ;
if ( SSViewer :: current_theme ()) $cssFiles .= ', ' . THEMES_DIR . " / " . SSViewer :: current_theme () . '/css/editor.css' ;
else if ( project ()) $cssFiles .= ', ' . project () . '/css/editor.css' ;
$htmlEditorConfig -> setOption ( 'content_css' , $cssFiles );
}
2009-08-10 06:34:17 +02:00
ENHANCEMENT Introduced constants for system paths like /sapphire in preparation for a more flexible directory reorganisation. Instead of hardcoding your path, please use the following constants: BASE_PATH, BASE_URL, SAPPHIRE_DIR, SAPPHIRE_PATH, CMS_DIR, CMS_PATH, THIRDPARTY_DIR, THIRDPARTY_PATH, ASSETS_DIR, ASSETS_PATH, THEMES_DIR, THEMES_PATH
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/trunk@63154 467b73ca-7a2a-4603-9d3b-597d59a354a9
2008-09-27 18:02:38 +02:00
Requirements :: css ( CMS_DIR . '/css/typography.css' );
Requirements :: css ( CMS_DIR . '/css/layout.css' );
Requirements :: css ( CMS_DIR . '/css/cms_left.css' );
Requirements :: css ( CMS_DIR . '/css/cms_right.css' );
2008-11-12 05:31:53 +01:00
Requirements :: css ( SAPPHIRE_DIR . '/css/Form.css' );
2008-08-11 07:29:12 +02:00
2008-09-16 23:46:08 +02:00
if ( isset ( $_REQUEST [ 'debug_firebug' ])) {
// Firebug is a useful console for debugging javascript
// Its available as a Firefox extension or a javascript library
// for easy inclusion in other browsers (just append ?debug_firebug=1 to the URL)
2009-11-21 03:36:38 +01:00
Requirements :: javascript ( SAPPHIRE_DIR . '/thirdparty/firebug-lite/firebug.js' );
2008-09-16 23:46:08 +02:00
} else {
// By default, we include fake-objects for all firebug calls
// to avoid javascript errors when referencing console.log() etc in javascript code
2009-11-21 03:36:38 +01:00
Requirements :: javascript ( SAPPHIRE_DIR . '/thirdparty/firebug-lite/firebugx.js' );
2008-09-16 23:46:08 +02:00
}
2009-11-21 04:17:01 +01:00
Requirements :: javascript ( SAPPHIRE_DIR . '/javascript/prototypefix/intro.js' );
2009-11-21 03:36:38 +01:00
Requirements :: javascript ( SAPPHIRE_DIR . '/thirdparty/prototype/prototype.js' );
2009-11-21 04:17:01 +01:00
Requirements :: javascript ( SAPPHIRE_DIR . '/javascript/prototypefix/outro.js' );
ENHANCEMENT Using jQuery layout manager plugin to size panels in main CMS interface. Removed custom javascript resizing and CSS rules.
API CHANGE Removed custom resizing javascript methods: window.ontabschanged, window.onresize, fixRightWidth(), fixHeight_left()
API CHANGE Removed DraggableSeparator, SideTabs, SideTabItem javascript classes
API CHANGE Removed Effect.ReSize and Highlighter javascript helper classes
API CHANGE Modified template structure in CMSMain_left.ss, CMSMain_right.ss and LeftAndMain.ss
API CHANGE Modified markup IDs in LeftAndMain/CMSMain templates, removed "left", "right", "contentPanel", "bottom"
ENHANCEMENT Using jquery-latest (currently 1.3) in CMSMain and LeftAndMain
ENHANCEMENT Added jQuery UI library and "smoothness" theme to default CMS interface
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/trunk@92581 467b73ca-7a2a-4603-9d3b-597d59a354a9
2009-11-21 03:35:20 +01:00
2009-11-21 03:36:38 +01:00
Requirements :: javascript ( SAPPHIRE_DIR . '/thirdparty/jquery/jquery.js' );
Requirements :: javascript ( SAPPHIRE_DIR . '/javascript/jquery_improvements.js' );
Requirements :: javascript ( SAPPHIRE_DIR . '/thirdparty/jquery-ui/ui.core.js' );
Requirements :: javascript ( SAPPHIRE_DIR . '/thirdparty/jquery-ui/ui.datepicker.js' );
2009-11-21 03:37:34 +01:00
Requirements :: javascript ( SAPPHIRE_DIR . '/thirdparty/jquery-ui/ui.dialog.js' );
2009-11-21 03:37:39 +01:00
Requirements :: javascript ( SAPPHIRE_DIR . '/thirdparty/jquery-ui/ui.tabs.js' );
2009-11-21 03:36:38 +01:00
Requirements :: javascript ( SAPPHIRE_DIR . '/thirdparty/jquery-ui/ui.draggable.js' );
Requirements :: javascript ( SAPPHIRE_DIR . '/thirdparty/jquery-ui/ui.droppable.js' );
Requirements :: javascript ( SAPPHIRE_DIR . '/thirdparty/jquery-ui/ui.accordion.js' );
Requirements :: javascript ( SAPPHIRE_DIR . '/thirdparty/jquery-ui/effects.core.js' );
Requirements :: javascript ( SAPPHIRE_DIR . '/thirdparty/jquery-ui/effects.slide.js' );
Requirements :: javascript ( SAPPHIRE_DIR . '/thirdparty/jquery-ui/effects.drop.js' );
Requirements :: javascript ( SAPPHIRE_DIR . '/thirdparty/jquery-ui/effects.scale.js' );
2009-11-21 03:37:21 +01:00
2009-11-21 03:37:39 +01:00
2009-11-21 03:36:54 +01:00
Requirements :: javascript ( CMS_DIR . '/thirdparty/jquery-layout/jquery.layout.js' );
2009-11-21 03:37:21 +01:00
Requirements :: javascript ( CMS_DIR . '/thirdparty/jquery-layout/jquery.layout.state.js' );
Requirements :: javascript ( SAPPHIRE_DIR . '/thirdparty/json-js/json2.js' );
2010-05-25 04:57:00 +02:00
Requirements :: javascript ( SAPPHIRE_DIR . '/thirdparty/jquery-metadata/jquery.metadata.js' );
2009-11-21 03:36:54 +01:00
Requirements :: javascript ( CMS_DIR . '/javascript/jquery-fitheighttoparent/jquery.fitheighttoparent.js' );
2009-11-21 03:37:21 +01:00
2009-11-21 03:36:26 +01:00
Requirements :: javascript ( CMS_DIR . '/javascript/ssui.core.js' );
ENHANCEMENT Using jQuery layout manager plugin to size panels in main CMS interface. Removed custom javascript resizing and CSS rules.
API CHANGE Removed custom resizing javascript methods: window.ontabschanged, window.onresize, fixRightWidth(), fixHeight_left()
API CHANGE Removed DraggableSeparator, SideTabs, SideTabItem javascript classes
API CHANGE Removed Effect.ReSize and Highlighter javascript helper classes
API CHANGE Modified template structure in CMSMain_left.ss, CMSMain_right.ss and LeftAndMain.ss
API CHANGE Modified markup IDs in LeftAndMain/CMSMain templates, removed "left", "right", "contentPanel", "bottom"
ENHANCEMENT Using jquery-latest (currently 1.3) in CMSMain and LeftAndMain
ENHANCEMENT Added jQuery UI library and "smoothness" theme to default CMS interface
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/trunk@92581 467b73ca-7a2a-4603-9d3b-597d59a354a9
2009-11-21 03:35:20 +01:00
// @todo Load separately so the CSS files can be inlined
2009-11-21 03:36:38 +01:00
Requirements :: css ( SAPPHIRE_DIR . '/thirdparty/jquery-ui-themes/smoothness/ui.all.css' );
ENHANCEMENT Using jQuery layout manager plugin to size panels in main CMS interface. Removed custom javascript resizing and CSS rules.
API CHANGE Removed custom resizing javascript methods: window.ontabschanged, window.onresize, fixRightWidth(), fixHeight_left()
API CHANGE Removed DraggableSeparator, SideTabs, SideTabItem javascript classes
API CHANGE Removed Effect.ReSize and Highlighter javascript helper classes
API CHANGE Modified template structure in CMSMain_left.ss, CMSMain_right.ss and LeftAndMain.ss
API CHANGE Modified markup IDs in LeftAndMain/CMSMain templates, removed "left", "right", "contentPanel", "bottom"
ENHANCEMENT Using jquery-latest (currently 1.3) in CMSMain and LeftAndMain
ENHANCEMENT Added jQuery UI library and "smoothness" theme to default CMS interface
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/trunk@92581 467b73ca-7a2a-4603-9d3b-597d59a354a9
2009-11-21 03:35:20 +01:00
2010-04-13 07:55:56 +02:00
// entwine
Requirements :: javascript ( SAPPHIRE_DIR . '/thirdparty/jquery-entwine/dist/jquery.entwine-dist.js' );
2009-11-21 03:35:33 +01:00
2009-11-21 03:37:39 +01:00
// Required for TreeTools panel above tree
Requirements :: javascript ( SAPPHIRE_DIR . '/javascript/TabSet.js' );
2009-11-21 03:36:38 +01:00
Requirements :: javascript ( SAPPHIRE_DIR . '/thirdparty/behaviour/behaviour.js' );
2009-11-21 03:36:59 +01:00
Requirements :: javascript ( SAPPHIRE_DIR . '/thirdparty/jquery-cookie/jquery.cookie.js' );
2009-11-21 04:14:36 +01:00
Requirements :: javascript ( CMS_DIR . '/thirdparty/jquery-notice/jquery.notice.js' );
2009-11-21 03:37:36 +01:00
Requirements :: javascript ( SAPPHIRE_DIR . '/javascript/jquery-ondemand/jquery.ondemand.js' );
2009-11-21 04:14:08 +01:00
Requirements :: javascript ( CMS_DIR . '/javascript/jquery-changetracker/lib/jquery.changetracker.js' );
2009-03-10 22:59:19 +01:00
Requirements :: add_i18n_javascript ( SAPPHIRE_DIR . '/javascript/lang' );
2009-04-29 03:44:28 +02:00
Requirements :: add_i18n_javascript ( CMS_DIR . '/javascript/lang' );
2008-09-16 23:46:08 +02:00
2009-11-21 03:36:38 +01:00
Requirements :: javascript ( SAPPHIRE_DIR . '/thirdparty/scriptaculous/effects.js' );
Requirements :: javascript ( SAPPHIRE_DIR . '/thirdparty/scriptaculous/dragdrop.js' );
Requirements :: javascript ( SAPPHIRE_DIR . '/thirdparty/scriptaculous/controls.js' );
2007-09-27 22:56:55 +02:00
ENHANCEMENT Introduced constants for system paths like /sapphire in preparation for a more flexible directory reorganisation. Instead of hardcoding your path, please use the following constants: BASE_PATH, BASE_URL, SAPPHIRE_DIR, SAPPHIRE_PATH, CMS_DIR, CMS_PATH, THIRDPARTY_DIR, THIRDPARTY_PATH, ASSETS_DIR, ASSETS_PATH, THEMES_DIR, THEMES_PATH
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/trunk@63154 467b73ca-7a2a-4603-9d3b-597d59a354a9
2008-09-27 18:02:38 +02:00
Requirements :: javascript ( THIRDPARTY_DIR . '/tree/tree.js' );
Requirements :: css ( THIRDPARTY_DIR . '/tree/tree.css' );
2007-11-15 23:31:22 +01:00
ENHANCEMENT Introduced constants for system paths like /sapphire in preparation for a more flexible directory reorganisation. Instead of hardcoding your path, please use the following constants: BASE_PATH, BASE_URL, SAPPHIRE_DIR, SAPPHIRE_PATH, CMS_DIR, CMS_PATH, THIRDPARTY_DIR, THIRDPARTY_PATH, ASSETS_DIR, ASSETS_PATH, THEMES_DIR, THEMES_PATH
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/trunk@63154 467b73ca-7a2a-4603-9d3b-597d59a354a9
2008-09-27 18:02:38 +02:00
Requirements :: javascript ( CMS_DIR . '/javascript/LeftAndMain.js' );
2009-11-21 04:15:51 +01:00
Requirements :: javascript ( CMS_DIR . '/javascript/LeftAndMain.Tree.js' );
2009-11-21 03:38:20 +01:00
Requirements :: javascript ( CMS_DIR . '/javascript/LeftAndMain.EditForm.js' );
2009-11-21 04:19:25 +01:00
Requirements :: javascript ( CMS_DIR . '/javascript/LeftAndMain.AddForm.js' );
2009-11-21 04:19:20 +01:00
Requirements :: javascript ( CMS_DIR . '/javascript/LeftAndMain.BatchActions.js' );
2008-02-25 03:10:37 +01:00
2007-09-27 22:56:55 +02:00
Requirements :: themedCSS ( 'typography' );
2008-11-12 05:31:53 +01:00
2008-07-17 23:08:35 +02:00
foreach ( self :: $extra_requirements [ 'javascript' ] as $file ) {
Requirements :: javascript ( $file [ 0 ]);
}
foreach ( self :: $extra_requirements [ 'css' ] as $file ) {
Requirements :: css ( $file [ 0 ], $file [ 1 ]);
}
foreach ( self :: $extra_requirements [ 'themedcss' ] as $file ) {
Requirements :: css ( $file [ 0 ], $file [ 1 ]);
}
2008-08-11 07:29:12 +02:00
2009-11-21 04:18:31 +01:00
Requirements :: css ( CMS_DIR . '/css/unjquery.css' );
2008-12-04 23:38:58 +01:00
// Javascript combined files
Requirements :: combine_files (
'assets/base.js' ,
array (
2009-11-21 04:20:45 +01:00
'sapphire/thirdparty/prototype/prototype.js' ,
'sapphire/thirdparty/behaviour/behaviour.js' ,
2009-11-21 03:36:38 +01:00
'sapphire/thirdparty/jquery/jquery.js' ,
'sapphire/thirdparty/jquery-livequery/jquery.livequery.js' ,
2009-11-21 03:37:36 +01:00
'sapphire/javascript/jquery-ondemand/jquery.ondemand.js' ,
2009-11-21 04:16:54 +01:00
'sapphire/thirdparty/firebug-lite/firebug.js' ,
'sapphire/thirdparty/firebug-lite/firebugx.js' ,
2008-12-04 23:38:58 +01:00
'sapphire/javascript/i18n.js' ,
)
);
Requirements :: combine_files (
'assets/leftandmain.js' ,
array (
2009-11-21 03:36:38 +01:00
'sapphire/thirdparty/scriptaculous/effects.js' ,
'sapphire/thirdparty/scriptaculous/dragdrop.js' ,
'sapphire/thirdparty/scriptaculous/controls.js' ,
2008-12-04 23:38:58 +01:00
'cms/javascript/LeftAndMain.js' ,
2009-11-21 04:16:54 +01:00
'sapphire/javascript/tree/tree.js' ,
2008-12-04 23:38:58 +01:00
'sapphire/javascript/TreeSelectorField.js' ,
'cms/javascript/ThumbnailStripField.js' ,
)
);
Requirements :: combine_files (
'assets/cmsmain.js' ,
array (
'cms/javascript/CMSMain_left.js' ,
'cms/javascript/CMSMain_right.js' ,
)
);
2008-11-07 13:21:10 +01:00
$dummy = null ;
$this -> extend ( 'init' , $dummy );
2010-05-28 04:37:30 +02:00
// The user's theme shouldn't affect the CMS, if, for example, they have replaced
// TableListField.ss or Form.ss.
SSViewer :: set_theme ( null );
2007-07-19 12:40:05 +02:00
}
2007-09-14 21:26:56 +02:00
2007-07-19 12:40:05 +02:00
//------------------------------------------------------------------------------------------//
// Main controllers
2007-09-14 21:26:56 +02:00
2007-07-19 12:40:05 +02:00
/**
* You should implement a Link () function in your subclass of LeftAndMain ,
* to point to the URL of that particular controller .
2008-04-05 05:43:58 +02:00
*
* @ return string
2007-07-19 12:40:05 +02:00
*/
2008-11-02 22:27:55 +01:00
public function Link ( $action = null ) {
2008-11-18 02:48:50 +01:00
// Handle missing url_segments
if ( ! $this -> stat ( 'url_segment' , true ))
self :: $url_segment = $this -> class ;
2008-11-02 22:27:55 +01:00
return Controller :: join_links (
$this -> stat ( 'url_base' , true ),
$this -> stat ( 'url_segment' , true ),
'/' , // trailing slash needed if $action is null!
" $action "
);
}
2009-01-05 07:17:59 +01:00
/**
2009-11-21 04:16:48 +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 .
*/
2009-01-05 07:17:59 +01:00
static function menu_title_for_class ( $class ) {
$title = eval ( " return $class :: \$ menu_title; " );
if ( ! $title ) $title = preg_replace ( '/Admin$/' , '' , $class );
return $title ;
}
2007-09-14 21:26:56 +02:00
2009-11-21 03:39:01 +01:00
public function show ( $request ) {
2009-11-21 04:19:37 +01:00
// TODO Necessary for TableListField URLs to work properly
if ( $request -> param ( 'ID' )) $this -> setCurrentPageID ( $request -> param ( 'ID' ));
2007-07-19 12:40:05 +02:00
if ( Director :: is_ajax ()) {
SSViewer :: setOption ( 'rewriteHashlinks' , false );
2009-11-21 04:20:56 +01:00
$form = $this -> getEditForm ( $request -> param ( 'ID' ));
2009-11-21 04:15:13 +01:00
return $form -> formHtmlContent ();
2007-07-19 12:40:05 +02:00
} else {
2009-11-21 03:39:12 +01:00
// Rendering is handled by template, which will call EditForm() eventually
2009-11-21 04:20:56 +01:00
return $this -> renderWith ( $this -> getViewer ( 'show' ));
2007-07-19 12:40:05 +02:00
}
}
2007-09-14 21:26:56 +02:00
2009-11-21 04:16:40 +01:00
/**
* @ deprecated 2.4 Please use show ()
*/
2009-11-21 04:20:47 +01:00
public function getitem ( $request ) {
$form = $this -> getEditForm ( $request -> getVar ( 'ID' ));
2009-11-21 04:15:13 +01:00
if ( $form ) return $form -> formHtmlContent ();
2007-07-19 12:40:05 +02:00
else return " " ;
}
//------------------------------------------------------------------------------------------//
// Main UI components
2007-09-14 21:26:56 +02:00
2007-07-19 12:40:05 +02:00
/**
2009-11-21 04:16:48 +01:00
* Returns the main menu of the CMS . This is also used by init ()
* to work out which sections the user has access to .
2008-04-05 05:43:58 +02:00
*
* @ return DataObjectSet
2007-07-19 12:40:05 +02:00
*/
public function MainMenu () {
// Don't accidentally return a menu if you're not logged in - it's used to determine access.
2008-12-04 23:38:58 +01:00
if ( ! Member :: currentUser ()) return new DataObjectSet ();
2007-07-19 12:40:05 +02:00
// Encode into DO set
2007-09-14 21:26:56 +02:00
$menu = new DataObjectSet ();
2009-01-05 07:17:59 +01:00
$menuItems = CMSMenu :: get_viewable_menu_items ();
if ( $menuItems ) foreach ( $menuItems as $code => $menuItem ) {
// alternate permission checks (in addition to LeftAndMain->canView())
if (
isset ( $menuItem -> controller )
&& $this -> hasMethod ( 'alternateMenuDisplayCheck' )
&& ! $this -> alternateMenuDisplayCheck ( $menuItem -> controller )
) {
continue ;
2007-08-31 02:31:49 +02:00
}
2008-04-05 05:43:58 +02:00
$linkingmode = " " ;
2008-11-02 22:27:55 +01:00
2008-11-18 02:48:50 +01:00
if ( strpos ( $this -> Link (), $menuItem -> url ) !== false ) {
if ( $this -> Link () == $menuItem -> url ) {
$linkingmode = " current " ;
2008-11-02 22:27:55 +01:00
// default menu is the one with a blank {@link url_segment}
2008-11-18 02:48:50 +01:00
} else if ( singleton ( $menuItem -> controller ) -> stat ( 'url_segment' ) == '' ) {
if ( $this -> Link () == $this -> stat ( 'url_base' ) . '/' ) $linkingmode = " current " ;
2008-04-05 05:43:58 +02:00
} else {
$linkingmode = " current " ;
2007-07-19 12:40:05 +02:00
}
}
2008-04-05 05:43:58 +02:00
2008-11-02 23:45:49 +01: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,
2009-11-21 04:16:48 +01:00
// we simply call LeftAndMain::menu_title_for_class() again
// if we're dealing with a controller
2008-11-02 23:45:49 +01:00
if ( $menuItem -> controller ) {
2009-01-05 07:17:59 +01:00
$defaultTitle = LeftAndMain :: menu_title_for_class ( $menuItem -> controller );
$title = _t ( " { $menuItem -> controller } .MENUTITLE " , $defaultTitle );
2008-11-02 23:45:49 +01:00
} else {
$title = $menuItem -> title ;
}
2008-04-05 05:43:58 +02:00
$menu -> push ( new ArrayData ( array (
2009-01-05 07:17:59 +01:00
" MenuItem " => $menuItem ,
2008-11-02 23:45:49 +01:00
" Title " => Convert :: raw2xml ( $title ),
2008-04-05 05:43:58 +02:00
" Code " => $code ,
2008-11-02 22:27:55 +01:00
" Link " => $menuItem -> url ,
2008-04-05 05:43:58 +02:00
" LinkingMode " => $linkingmode
)));
2007-07-19 12:40:05 +02:00
}
2008-04-05 05:43:58 +02:00
// if no current item is found, assume that first item is shown
//if(!isset($foundCurrent))
return $menu ;
2007-07-19 12:40:05 +02:00
}
2009-02-03 03:50:25 +01:00
public function CMSTopMenu () {
return $this -> renderWith ( array ( 'CMSTopMenu_alternative' , 'CMSTopMenu' ));
}
2009-11-21 04:16:48 +01:00
/**
* Return a list of appropriate templates for this class , with the given suffix
*/
protected function getTemplatesWithSuffix ( $suffix ) {
$classes = array_reverse ( ClassInfo :: ancestry ( $this -> class ));
foreach ( $classes as $class ) {
$templates [] = $class . $suffix ;
if ( $class == 'LeftAndMain' ) break ;
}
return $templates ;
}
2007-09-14 21:26:56 +02:00
2007-07-19 12:40:05 +02:00
public function Left () {
return $this -> renderWith ( $this -> getTemplatesWithSuffix ( '_left' ));
}
2008-12-04 23:38:58 +01:00
2007-07-19 12:40:05 +02:00
public function Right () {
return $this -> renderWith ( $this -> getTemplatesWithSuffix ( '_right' ));
}
2007-09-14 21:26:56 +02:00
2007-07-19 12:40:05 +02:00
public function getRecord ( $id , $className = null ) {
2009-05-01 00:47:28 +02:00
if ( $id && is_numeric ( $id )) {
if ( ! $className ) $className = $this -> stat ( 'tree_class' );
return DataObject :: get_by_id ( $className , $id );
}
2007-07-19 12:40:05 +02:00
}
2009-11-21 04:21:00 +01:00
2009-11-22 09:23:12 +01:00
/**
* @ return String HTML
*/
2009-11-21 04:21:00 +01:00
public function SiteTreeAsUL () {
return $this -> getSiteTreeFor ( $this -> stat ( 'tree_class' ));
}
2007-07-19 12:40:05 +02:00
2009-05-01 00:47:28 +02:00
/**
2009-11-22 09:23:12 +01:00
* Get a site tree HTML listing which displays the nodes under the given criteria .
2009-11-21 04:16:48 +01:00
*
2009-05-01 00:47:28 +02: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
2009-11-21 04:16:48 +01:00
* shown
* @ param $childrenMethod The method to call to get the children of the tree . For example ,
* Children , AllChildrenIncludingDeleted , or AllHistoricalChildren
2010-04-23 02:11:32 +02:00
* @ return String Nested unordered list with links to each page
2009-05-01 00:47:28 +02:00
*/
2010-04-12 11:22:43 +02:00
function getSiteTreeFor ( $className , $rootID = null , $childrenMethod = null , $numChildrenMethod = null , $filterFunction = null , $minNodeCount = 30 ) {
// Default childrenMethod and numChildrenMethod
2009-05-14 08:11:18 +02:00
if ( ! $childrenMethod ) $childrenMethod = 'AllChildrenIncludingDeleted' ;
2010-04-12 11:22:43 +02:00
if ( ! $numChildrenMethod ) $numChildrenMethod = 'numChildren' ;
2009-05-14 08:11:18 +02:00
// Get the tree root
2007-07-19 12:40:05 +02:00
$obj = $rootID ? $this -> getRecord ( $rootID ) : singleton ( $className );
2009-05-14 08:11:18 +02:00
// Mark the nodes of the tree to return
if ( $filterFunction ) $obj -> setMarkingFilterFunction ( $filterFunction );
2009-07-09 07:36:47 +02:00
2010-04-12 11:22:43 +02:00
$obj -> markPartialTree ( $minNodeCount , $this , $childrenMethod , $numChildrenMethod );
2009-05-14 08:11:18 +02:00
// Ensure current page is exposed
2007-07-19 12:40:05 +02:00
if ( $p = $this -> currentPage ()) $obj -> markToExpose ( $p );
2009-07-31 07:43:47 +02:00
// NOTE: SiteTree/CMSMain coupling :-(
SiteTree :: prepopuplate_permission_cache ( 'edit' , $obj -> markedNodeIDs ());
2007-09-14 21:26:56 +02:00
2007-07-19 12:40:05 +02:00
// getChildrenAsUL is a flexible and complex way of traversing the tree
2009-07-09 07:36:47 +02:00
$titleEval = '
2009-11-21 04:16:48 +01:00
" <li id= \" record- $child->ID\ " class = \ " " . $child -> CMSTreeClasses ( $extraArg ) . " \" > " .
2009-11-30 02:41:36 +01:00
" <a href= \" " . Controller :: join_links ( substr ( $extraArg -> Link (), 0 , - 1 ), " show " , $child -> ID ) . " \" class= \" " . $child -> CMSTreeClasses ( $extraArg ) . " \" title= \" '
2009-11-21 04:16:48 +01:00
. _t ( 'LeftAndMain.PAGETYPE' , 'Page type: ' )
. ' " . $child->class . " \ " > " . ( $child -> TreeTitle ) .
" </a> "
' ;
2009-11-21 04:21:03 +01:00
2009-11-22 09:23:14 +01:00
$html = $obj -> getChildrenAsUL (
2009-07-09 07:36:47 +02:00
" " ,
$titleEval ,
$this ,
true ,
$childrenMethod ,
2010-04-12 11:22:43 +02:00
$numChildrenMethod ,
2009-07-09 07:36:47 +02:00
$minNodeCount
);
2007-07-19 12:40:05 +02:00
2007-09-14 21:26:56 +02:00
// Wrap the root if needs be.
2007-07-19 12:40:05 +02:00
if ( ! $rootID ) {
2010-02-11 00:06:34 +01:00
$rootLink = $this -> Link ( 'show' ) . '/root' ;
2007-08-16 08:25:17 +02:00
// This lets us override the tree title with an extension
2010-04-14 00:19:49 +02:00
if ( $this -> hasMethod ( 'getCMSTreeTitle' ) && $customTreeTitle = $this -> getCMSTreeTitle ()) {
$treeTitle = $customTreeTitle ;
} else {
$siteConfig = SiteConfig :: current_site_config ();
$treeTitle = $siteConfig -> Title ;
}
2007-08-16 08:25:17 +02:00
2009-11-22 09:23:14 +01:00
$html = " <ul id= \" sitetree \" class= \" tree unformatted \" ><li id= \" record-0 \" class= \" Root nodelete \" ><a href= \" $rootLink\ " >< strong > $treeTitle </ strong ></ a > "
. $html . " </li></ul> " ;
2007-07-19 12:40:05 +02:00
}
2007-09-14 21:26:56 +02:00
2009-11-22 09:23:14 +01:00
return $html ;
2007-07-19 12:40:05 +02:00
}
2007-09-14 21:26:56 +02:00
2009-05-01 00:47:28 +02:00
/**
* Get a subtree underneath the request param 'ID' .
* If ID = 0 , then get the whole tree .
*/
2009-07-09 07:36:47 +02:00
public function getsubtree ( $request ) {
2009-11-22 09:23:12 +01:00
if ( $filterClass = $request -> requestVar ( 'FilterClass' )) {
if ( ! is_subclass_of ( $filterClass , 'CMSSiteTreeFilter' )) {
throw new Exception ( sprintf ( 'Invalid filter class passed: %s' , $filterClass ));
}
$filter = new $filterClass ( $request -> requestVars ());
} else {
$filter = null ;
}
$html = $this -> getSiteTreeFor (
2009-07-09 07:36:47 +02:00
$this -> stat ( 'tree_class' ),
$request -> getVar ( 'ID' ),
2010-04-12 11:22:43 +02:00
( $filter ) ? $filter -> getChildrenMethod () : null ,
null ,
2009-11-22 09:23:12 +01:00
( $filter ) ? array ( $filter , 'isPageIncluded' ) : null ,
2010-04-12 11:22:43 +02:00
$request -> getVar ( 'minNodeCount' )
2009-07-09 07:36:47 +02:00
);
2009-05-01 00:47:28 +02:00
// Trim off the outer tag
2009-11-22 09:23:12 +01:00
$html = ereg_replace ( '^[ \t\r\n]*<ul[^>]*>' , '' , $html );
$html = ereg_replace ( '</ul[^>]*>[ \t\r\n]*$' , '' , $html );
2009-05-01 00:47:28 +02:00
2009-11-22 09:23:12 +01:00
return $html ;
2009-11-21 04:21:00 +01:00
}
2007-07-19 12:40:05 +02:00
/**
2009-11-21 04:20:26 +01:00
* Save handler
2007-07-19 12:40:05 +02:00
*/
2009-11-21 03:39:12 +01:00
public function save ( $data , $form ) {
2007-07-19 12:40:05 +02:00
$className = $this -> stat ( 'tree_class' );
2007-09-14 21:26:56 +02:00
2009-11-21 03:39:12 +01:00
// Existing or new record?
$SQL_id = Convert :: raw2sql ( $data [ 'ID' ]);
2007-09-25 23:58:42 +02:00
if ( substr ( $SQL_id , 0 , 3 ) != 'new' ) {
2009-11-21 03:39:12 +01:00
$record = DataObject :: get_by_id ( $className , $SQL_id );
2008-11-03 15:56:36 +01:00
if ( $record && ! $record -> canEdit ()) return Security :: permissionFailure ( $this );
2007-07-19 12:40:05 +02:00
} else {
2008-11-03 15:56:36 +01:00
if ( ! singleton ( $this -> stat ( 'tree_class' )) -> canCreate ()) return Security :: permissionFailure ( $this );
2007-09-25 23:58:42 +02:00
$record = $this -> getNewItem ( $SQL_id , false );
2007-07-19 12:40:05 +02:00
}
2009-11-21 03:39:12 +01:00
// save form data into record
$form -> saveInto ( $record , true );
$record -> write ();
2009-11-21 04:20:26 +01:00
$this -> extend ( 'onAfterSave' , $record );
2007-09-14 21:26:56 +02:00
2009-11-21 04:20:26 +01:00
$this -> response -> addHeader ( 'X-Status' , _t ( 'LeftAndMain.SAVEDUP' ));
// write process might've changed the record, so we reload before returning
$form -> loadDataFrom ( $record );
2009-11-21 03:39:12 +01:00
return $form -> formHtmlContent ();
2007-07-19 12:40:05 +02:00
}
2007-09-14 21:26:56 +02:00
2007-07-19 12:40:05 +02:00
/**
* Ajax handler for updating the parent of a tree node
*/
2009-11-21 04:16:30 +01:00
public function ajaxupdateparent ( $request ) {
2009-08-10 00:29:45 +02:00
if ( ! Permission :: check ( 'SITETREE_REORGANISE' ) && ! Permission :: check ( 'ADMIN' )) {
2009-11-21 04:16:30 +01:00
$this -> response -> setStatusCode (
403 ,
_t ( 'LeftAndMain.CANT_REORGANISE' , " You do not have permission to rearange the site tree. Your change was not saved. " )
);
return ;
2009-08-10 00:29:45 +02:00
}
2007-09-14 21:26:56 +02:00
2009-11-21 04:16:30 +01:00
$id = $request -> requestVar ( 'ID' );
$parentID = $request -> requestVar ( 'ParentID' );
$statusUpdates = array ( 'modified' => array ());
2007-07-19 12:40:05 +02:00
if ( is_numeric ( $id ) && is_numeric ( $parentID ) && $id != $parentID ) {
$node = DataObject :: get_by_id ( $this -> stat ( 'tree_class' ), $id );
if ( $node ){
2008-11-03 15:56:36 +01:00
if ( $node && ! $node -> canEdit ()) return Security :: permissionFailure ( $this );
2009-11-21 04:20:50 +01:00
2007-07-19 12:40:05 +02:00
$node -> ParentID = $parentID ;
$node -> write ();
2009-11-21 04:16:30 +01:00
2009-11-21 04:20:50 +01:00
$statusUpdates [ 'modified' ][ $node -> ID ] = array (
'TreeTitle' => $node -> TreeTitle
);
2010-04-14 03:49:29 +02:00
// Update all dependent pages
2010-06-03 02:16:58 +02:00
if ( $virtualPages = DataObject :: get ( " VirtualPage " , " \" CopyContentFromID \" = $node->ID " )) {
2010-04-14 03:49:29 +02:00
foreach ( $virtualPages as $virtualPage ) {
$statusUpdates [ 'modified' ][ $virtualPage -> ID ] = array (
'TreeTitle' => $virtualPage -> TreeTitle ()
);
}
}
2007-09-14 21:26:56 +02:00
2009-11-21 04:20:50 +01:00
$this -> response -> addHeader (
'X-Status' ,
_t ( 'LeftAndMain.SAVED' , 'saved' )
);
} else {
$this -> response -> setStatusCode (
500 ,
_t (
'LeftAndMain.PLEASESAVE' ,
" Please Save Page: This page could not be upated because it hasn't been saved yet. "
)
);
}
2007-07-19 12:40:05 +02:00
}
2009-11-21 04:16:30 +01:00
return Convert :: raw2json ( $statusUpdates );
2007-07-19 12:40:05 +02:00
}
2007-09-14 21:26:56 +02:00
2007-07-19 12:40:05 +02:00
/**
* Ajax handler for updating the order of a number of tree nodes
* $_GET [ ID ] : An array of node ids in the correct order
* $_GET [ MovedNodeID ] : The node that actually got moved
*/
2009-11-21 04:16:30 +01:00
public function ajaxupdatesort ( $request ) {
if ( ! Permission :: check ( 'SITETREE_REORGANISE' ) && ! Permission :: check ( 'ADMIN' )) {
$this -> response -> setStatusCode (
403 ,
_t ( 'LeftAndMain.CANT_REORGANISE' , " You do not have permission to rearange the site tree. Your change was not saved. " )
);
return ;
}
2007-07-19 12:40:05 +02:00
$className = $this -> stat ( 'tree_class' );
$counter = 0 ;
2009-11-21 04:16:30 +01:00
$statusUpdates = array ( 'modified' => array ());
if ( ! is_array ( $request -> requestVar ( 'ID' ))) return false ;
2009-08-10 00:29:45 +02:00
2009-11-21 04:16:30 +01:00
//Sorting root
if ( $request -> requestVar ( 'MovedNodeID' ) == 0 ){
$movedNode = DataObject :: get ( $className , " \" ParentID \" =0 " );
} else {
$movedNode = DataObject :: get_by_id ( $className , $request -> requestVar ( 'MovedNodeID' ));
2009-08-10 00:29:45 +02:00
}
2009-11-21 04:16:30 +01:00
foreach ( $request -> requestVar ( 'ID' ) as $id ) {
if ( $id == $movedNode -> ID ) {
$movedNode -> Sort = ++ $counter ;
$movedNode -> write ();
$statusUpdates [ 'modified' ][ $movedNode -> ID ] = array (
'TreeTitle' => $movedNode -> TreeTitle
);
} else if ( is_numeric ( $id )) {
// Nodes that weren't "actually moved" shouldn't be registered as
// having been edited; do a direct SQL update instead
++ $counter ;
DB :: query ( " UPDATE \" $className\ " SET \ " Sort \" = $counter WHERE \" ID \" = ' $id ' " );
2007-07-19 12:40:05 +02:00
}
}
2007-09-14 21:26:56 +02:00
2009-11-21 04:16:30 +01:00
return Convert :: raw2json ( $statusUpdates );
2007-07-19 12:40:05 +02:00
}
2009-11-21 04:16:38 +01:00
2009-08-10 00:29:45 +02:00
public function CanOrganiseSitetree () {
return ! Permission :: check ( 'SITETREE_REORGANISE' ) && ! Permission :: check ( 'ADMIN' ) ? false : true ;
}
2009-11-21 04:15:13 +01:00
2009-11-21 04:15:18 +01:00
/**
2009-11-21 04:17:16 +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 .
2009-11-21 04:15:18 +01:00
*
2009-11-21 04:17:16 +01:00
* This is a " pseudo-abstract " methoed , usually connected to a { @ link getEditForm ()}
2010-04-13 07:55:56 +02:00
* method in an entwine subclass . This method can accept a record identifier ,
2009-11-21 04:17:16 +01:00
* selected either in custom logic , or through { @ link currentPageID ()} .
* The form usually construct itself from { @ link DataObject -> getCMSFields ()}
* for the specific managed subclass defined in { @ link LeftAndMain :: $tree_class } .
2009-11-21 04:15:13 +01:00
*
2009-11-21 04:17:16 +01:00
* @ param HTTPRequest $request Optionally contains an identifier for the
* record to load into the form .
2009-11-21 04:15:13 +01:00
* @ 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 .
*/
2009-11-21 04:20:26 +01:00
/**
* @ return Form
*/
2009-11-21 04:17:16 +01:00
function EditForm ( $request = null ) {
2009-11-21 04:20:26 +01:00
return $this -> getEditForm ();
2009-11-21 04:17:16 +01:00
}
2009-11-21 04:20:26 +01:00
public function getEditForm ( $id = null ) {
if ( ! $id ) $id = $this -> currentPageID ();
2009-11-21 04:20:47 +01:00
$record = ( $id && $id != " root " ) ? $this -> getRecord ( $id ) : null ;
2009-11-21 04:20:26 +01:00
if ( $record && ! $record -> canView ()) return Security :: permissionFailure ( $this );
2009-11-21 04:20:47 +01:00
2009-11-21 04:20:26 +01:00
if ( $record ) {
$fields = $record -> getCMSFields ();
if ( $fields == null ) {
user_error (
" getCMSFields() returned null - it should return a FieldSet object.
Perhaps you forgot to put a return statement at the end of your method ? " ,
E_USER_ERROR
);
}
2009-11-21 04:20:30 +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' ));
}
if (
Object :: has_extension ( $this -> stat ( 'tree_class' ), 'Hierarchy' )
&& ! $fields -> dataFieldByName ( 'ParentID' )
) {
$fields -> push ( new HiddenField ( 'ParentID' ));
}
2009-11-21 04:20:26 +01:00
if ( $record -> hasMethod ( 'getAllCMSActions' )) {
$actions = $record -> getAllCMSActions ();
} else {
$actions = $record -> getCMSActions ();
// add default actions if none are defined
if ( ! $actions || ! $actions -> Count ()) {
if ( $record -> canEdit ()) {
$actions -> push ( new FormAction ( 'save' , _t ( 'CMSMain.SAVE' , 'Save' )));
}
}
}
$form = new Form ( $this , " EditForm " , $fields , $actions );
$form -> loadDataFrom ( $record );
// 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.
$validator -> setJavascriptValidationHandler ( 'prototype' );
$form -> setValidator ( $validator );
} else {
$form -> unsetValidator ();
}
if ( ! $record -> canEdit ()) {
$readonlyFields = $form -> Fields () -> makeReadonly ();
$form -> setFields ( $readonlyFields );
}
} else {
2010-02-11 00:06:34 +01:00
$form = $this -> RootForm ();
2009-11-21 04:20:26 +01:00
}
return $form ;
}
2009-11-21 04:20:41 +01:00
2010-02-11 00:06:34 +01:00
function RootForm () {
return $this -> EmptyForm ();
}
2009-11-21 04:15:13 +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 .
*
* @ return Form
*/
function EmptyForm () {
2009-11-21 04:15:20 +01:00
$form = new Form (
2009-11-21 04:15:13 +01:00
$this ,
" EditForm " ,
new FieldSet (
new HeaderField (
'WelcomeHeader' ,
$this -> getApplicationName ()
),
new LiteralField (
'WelcomeText' ,
2009-11-21 04:18:38 +01:00
sprintf ( '<p id="WelcomeMessage">%s %s. %s</p>' ,
2009-11-21 04:15:13 +01:00
_t ( 'LeftAndMain_right.ss.WELCOMETO' , 'Welcome to' ),
$this -> getApplicationName (),
_t ( 'CHOOSEPAGE' , 'Please choose an item from the left.' )
)
)
),
new FieldSet ()
);
2009-11-21 04:15:20 +01:00
$form -> unsetValidator ();
return $form ;
2007-07-19 12:40:05 +02:00
}
2007-09-27 22:56:55 +02:00
2009-11-21 04:20:41 +01:00
/**
* @ return Form
*/
function AddForm () {
$class = $this -> stat ( 'tree_class' );
$typeMap = array ( $class => singleton ( $class ) -> i18n_singular_name ());
$typeField = new DropdownField ( 'Type' , false , $typeMap , $class );
$form = new Form (
$this ,
'AddForm' ,
new FieldSet (
new HiddenField ( 'ParentID' ),
$typeField -> performReadonlyTransformation ()
),
new FieldSet (
new FormAction ( 'doAdd' , _t ( 'AssetAdmin_left.ss.GO' , 'Go' ))
)
);
$form -> addExtraClass ( 'actionparams' );
return $form ;
}
/**
* Add a new group and return its details suitable for ajax .
*/
public function doAdd ( $data , $form ) {
$class = $this -> stat ( 'tree_class' );
// check create permissions
if ( ! singleton ( $class ) -> canCreate ()) return Security :: permissionFailure ( $this );
// check addchildren permissions
if (
singleton ( $class ) -> hasDatabaseField ( 'Hierarchy' )
&& isset ( $data [ 'ParentID' ])
&& is_numeric ( $data [ 'ParentID' ])
) {
$parentRecord = DataObject :: get_by_id ( $class , $data [ 'ParentID' ]);
if (
$parentRecord -> hasMethod ( 'canAddChildren' )
&& ! $parentRecord -> canAddChildren ()
) return Security :: permissionFailure ( $this );
}
$record = Object :: create ( $class );
$form -> saveInto ( $record );
$record -> write ();
// Used in TinyMCE inline folder creation
if ( isset ( $data [ 'returnID' ])) {
return $record -> ID ;
2010-04-14 05:06:22 +02:00
} else if ( Director :: is_ajax ()) {
2009-11-21 04:20:41 +01:00
$form = $this -> getEditForm ( $record -> ID );
return $form -> formHtmlContent ();
2010-04-14 05:06:22 +02:00
} else {
return $this -> redirect ( Controller :: join_links ( $this -> Link ( 'show' ), $record -> ID ));
2009-11-21 04:20:41 +01:00
}
}
2009-11-21 04:20:21 +01:00
/**
* Batch Actions Handler
*/
function batchactions () {
return new CMSBatchActionHandler ( $this , 'batchactions' , $this -> stat ( 'tree_class' ));
}
/**
* @ return Form
*/
function BatchActionsForm () {
$actions = $this -> batchactions () -> batchActionList ();
$actionsMap = array ();
foreach ( $actions as $action ) $actionsMap [ $action -> Link ] = $action -> Title ;
$form = new Form (
$this ,
'BatchActionsForm' ,
new FieldSet (
new LiteralField (
'Intro' ,
sprintf ( '<p><small>%s</small></p>' ,
_t (
'CMSMain_left.ss.SELECTPAGESACTIONS' ,
'Select the pages that you want to change & then click an action:'
)
)
),
new HiddenField ( 'csvIDs' ),
new DropdownField (
'Action' ,
false ,
$actionsMap
)
),
new FieldSet (
// TODO i18n
new FormAction ( 'submit' , " Go " )
)
);
$form -> addExtraClass ( 'actionparams' );
$form -> unsetValidator ();
return $form ;
}
2007-09-27 22:56:55 +02:00
public function myprofile () {
$form = $this -> Member_ProfileForm ();
return $this -> customise ( array (
'Form' => $form
)) -> renderWith ( 'BlankPage' );
}
public function Member_ProfileForm () {
return new Member_ProfileForm ( $this , 'Member_ProfileForm' , Member :: currentUser ());
}
2007-09-14 21:26:56 +02:00
2007-07-19 12:40:05 +02:00
public function printable () {
2009-11-21 04:17:16 +01:00
$form = $this -> getEditForm ( $this -> currentPageID ());
if ( ! $form ) return false ;
2007-07-19 12:40:05 +02:00
$form -> transform ( new PrintableTransformation ());
$form -> actions = null ;
2007-09-14 21:26:56 +02:00
2007-07-19 12:40:05 +02:00
Requirements :: clear ();
ENHANCEMENT Introduced constants for system paths like /sapphire in preparation for a more flexible directory reorganisation. Instead of hardcoding your path, please use the following constants: BASE_PATH, BASE_URL, SAPPHIRE_DIR, SAPPHIRE_PATH, CMS_DIR, CMS_PATH, THIRDPARTY_DIR, THIRDPARTY_PATH, ASSETS_DIR, ASSETS_PATH, THEMES_DIR, THEMES_PATH
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/trunk@63154 467b73ca-7a2a-4603-9d3b-597d59a354a9
2008-09-27 18:02:38 +02:00
Requirements :: css ( CMS_DIR . '/css/LeftAndMain_printable.css' );
2007-07-19 12:40:05 +02:00
return array (
" PrintForm " => $form
);
}
2007-09-14 21:26:56 +02:00
2009-11-21 04:17:19 +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 "
*
* @ return int
*/
2007-07-19 12:40:05 +02:00
public function currentPageID () {
2009-11-21 04:17:19 +01:00
if ( $this -> request -> getVar ( 'ID' )) {
return $this -> request -> getVar ( 'ID' );
2009-11-21 04:19:37 +01:00
} elseif ( $this -> request -> param ( 'ID' ) && is_numeric ( $this -> request -> param ( 'ID' ))) {
2009-11-21 04:17:19 +01:00
return $this -> request -> param ( 'ID' );
2007-07-19 12:40:05 +02:00
} elseif ( Session :: get ( " { $this -> class } .currentPage " )) {
return Session :: get ( " { $this -> class } .currentPage " );
} else {
return null ;
}
}
2007-09-14 21:26:56 +02:00
2009-11-21 04:17:19 +01:00
/**
* 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 .
*
* @ param int $id
*/
2007-07-19 12:40:05 +02:00
public function setCurrentPageID ( $id ) {
Session :: set ( " { $this -> class } .currentPage " , $id );
}
2007-09-14 21:26:56 +02:00
2009-11-21 04:17:19 +01:00
/**
* Uses { @ link getRecord ()} and { @ link currentPageID ()}
* to get the currently selected record .
*
* @ return DataObject
*/
2007-07-19 12:40:05 +02:00
public function currentPage () {
2009-05-01 00:47:28 +02:00
return $this -> getRecord ( $this -> currentPageID ());
2007-07-19 12:40:05 +02:00
}
2007-09-14 21:26:56 +02:00
2009-11-21 04:17:19 +01:00
/**
* Compares a given record to the currently selected one ( if any ) .
* Used for marking the current tree node .
*
* @ return boolean
*/
public function isCurrentPage ( DataObject $record ) {
return ( $record -> ID == $this -> currentPageID ());
2007-07-19 12:40:05 +02:00
}
2009-08-12 23:19:04 +02:00
/**
* Get the staus of a certain page and version .
*
* This function is used for concurrent editing , and providing alerts
* when multiple users are editing a single page . It echoes a json
* encoded string to the UA .
*/
2007-09-14 21:26:56 +02:00
2007-07-19 12:40:05 +02:00
/**
* Return the CMS ' s HTML - editor toolbar
*/
public function EditorToolbar () {
2008-04-26 08:23:41 +02:00
return Object :: create ( 'HtmlEditorField_Toolbar' , $this , " EditorToolbar " );
2007-07-19 12:40:05 +02:00
}
2007-09-14 21:26:56 +02:00
2007-07-19 12:40:05 +02:00
/**
2009-02-03 03:50:25 +01:00
* Return the version number of this application .
* Uses the subversion path information in < mymodule >/ silverstripe_version
* ( automacially replaced $URL $ placeholder ) .
*
* @ return string
2007-07-19 12:40:05 +02:00
*/
public function CMSVersion () {
2010-04-14 00:24:12 +02:00
$sapphireVersionFile = file_get_contents ( BASE_PATH . '/sapphire/silverstripe_version' );
$cmsVersionFile = file_get_contents ( BASE_PATH . '/cms/silverstripe_version' );
2007-09-14 21:26:56 +02:00
2007-07-19 12:40:05 +02:00
if ( strstr ( $sapphireVersionFile , " /sapphire/trunk " )) {
$sapphireVersion = " trunk " ;
} else {
preg_match ( " /sapphire \ /(?:(?:branches)|(?:tags))(?: \ /rc)? \ /([A-Za-z0-9._-]+) \ /silverstripe_version/ " , $sapphireVersionFile , $matches );
2009-02-03 03:50:25 +01:00
$sapphireVersion = ( $matches ) ? $matches [ 1 ] : null ;
2007-07-19 12:40:05 +02:00
}
2007-09-14 21:26:56 +02:00
2007-07-19 12:40:05 +02:00
if ( strstr ( $cmsVersionFile , " /cms/trunk " )) {
$cmsVersion = " trunk " ;
} else {
preg_match ( " /cms \ /(?:(?:branches)|(?:tags))(?: \ /rc)? \ /([A-Za-z0-9._-]+) \ /silverstripe_version/ " , $cmsVersionFile , $matches );
2009-02-03 03:50:25 +01:00
$cmsVersion = ( $matches ) ? $matches [ 1 ] : null ;
2007-09-14 21:26:56 +02:00
}
2009-11-21 04:16:54 +01:00
return " cms: $cmsVersion , sapphire: $sapphireVersion " ;
2007-07-19 12:40:05 +02:00
}
/**
2008-04-26 08:42:10 +02:00
* The application name . Customisable by calling
* LeftAndMain :: setApplicationName () - the first parameter .
*
* @ var String
*/
static $application_name = 'SilverStripe CMS' ;
/**
* The application logo text . Customisable by calling
* LeftAndMain :: setApplicationName () - the second parameter .
*
* @ var String
*/
static $application_logo_text = 'SilverStripe' ;
/**
* Set the application name , and the logo text .
*
* @ param String $name The application name
* @ param String $logoText The logo text
2007-09-14 21:26:56 +02:00
*/
2009-03-10 22:59:19 +01:00
static $application_link = " http://www.silverstripe.org/ " ;
2009-11-21 04:16:48 +01:00
/**
* @ param String $name
* @ param String $logoText
* @ param String $link ( Optional )
*/
2008-04-22 05:19:53 +02:00
static function setApplicationName ( $name , $logoText = null , $link = null ) {
2007-07-19 12:40:05 +02:00
self :: $application_name = $name ;
self :: $application_logo_text = $logoText ? $logoText : $name ;
2008-04-22 05:19:53 +02:00
if ( $link ) self :: $application_link = $link ;
2007-07-19 12:40:05 +02:00
}
2008-04-26 08:42:10 +02:00
/**
* Get the application name .
* @ return String
*/
function getApplicationName () {
2007-07-19 12:40:05 +02:00
return self :: $application_name ;
}
2008-04-26 08:42:10 +02:00
/**
* Get the application logo text .
* @ return String
*/
function getApplicationLogoText () {
2007-07-19 12:40:05 +02:00
return self :: $application_logo_text ;
}
2009-11-21 04:16:48 +01:00
/**
* @ return String
*/
2008-04-22 05:19:53 +02:00
function ApplicationLink () {
return self :: $application_link ;
}
2007-07-19 12:40:05 +02:00
2008-09-23 04:24:23 +02:00
/**
* Return the title of the current section , as shown on the main menu
*/
function SectionTitle () {
// Get menu - use obj() to cache it in the same place as the template engine
$menu = $this -> obj ( 'MainMenu' );
foreach ( $menu as $menuItem ) {
if ( $menuItem -> LinkingMode == 'current' ) return $menuItem -> Title ;
}
}
2008-04-26 08:42:10 +02:00
/**
* The application logo path . Customisable by calling
* LeftAndMain :: setLogo () - the first parameter .
*
* @ var unknown_type
*/
static $application_logo = 'cms/images/mainmenu/logo.gif' ;
2007-09-14 21:26:56 +02:00
2008-04-26 08:42:10 +02:00
/**
* The application logo style . Customisable by calling
* LeftAndMain :: setLogo () - the second parameter .
*
* @ var String
*/
static $application_logo_style = '' ;
/**
* Set the CMS application logo .
*
* @ param String $logo Relative path to the logo
* @ param String $logoStyle Custom CSS styles for the logo
* e . g . " border: 1px solid red; padding: 5px; "
*/
2007-07-19 12:40:05 +02:00
static function setLogo ( $logo , $logoStyle ) {
self :: $application_logo = $logo ;
self :: $application_logo_style = $logoStyle ;
2008-04-26 08:42:10 +02:00
self :: $application_logo_text = '' ;
2007-07-19 12:40:05 +02:00
}
2008-04-26 08:39:00 +02:00
protected static $loading_image = 'cms/images/loading.gif' ;
/**
* Set the image shown when the CMS is loading .
*/
static function set_loading_image ( $loadingImage ) {
self :: $loading_image = $loadingImage ;
}
function LoadingImage () {
return self :: $loading_image ;
}
2007-07-19 12:40:05 +02:00
function LogoStyle () {
2008-02-25 03:10:37 +01:00
return " background: url( " . self :: $application_logo . " ) no-repeat; " . self :: $application_logo_style ;
2007-07-19 12:40:05 +02:00
}
/**
* Return the base directory of the tiny_mce codebase
*/
function MceRoot () {
return MCE_ROOT ;
}
2008-04-05 03:40:36 +02:00
2008-07-17 23:08:35 +02:00
/**
* Register the given javascript file as required in the CMS .
ENHANCEMENT Introduced constants for system paths like /sapphire in preparation for a more flexible directory reorganisation. Instead of hardcoding your path, please use the following constants: BASE_PATH, BASE_URL, SAPPHIRE_DIR, SAPPHIRE_PATH, CMS_DIR, CMS_PATH, THIRDPARTY_DIR, THIRDPARTY_PATH, ASSETS_DIR, ASSETS_PATH, THEMES_DIR, THEMES_PATH
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/trunk@63154 467b73ca-7a2a-4603-9d3b-597d59a354a9
2008-09-27 18:02:38 +02:00
* Filenames should be relative to the base , eg , SAPPHIRE_DIR . '/javascript/loader.js'
2008-07-17 23:08:35 +02:00
*/
public static function require_javascript ( $file ) {
self :: $extra_requirements [ 'javascript' ][] = array ( $file );
}
/**
* Register the given stylesheet file as required .
*
ENHANCEMENT Introduced constants for system paths like /sapphire in preparation for a more flexible directory reorganisation. Instead of hardcoding your path, please use the following constants: BASE_PATH, BASE_URL, SAPPHIRE_DIR, SAPPHIRE_PATH, CMS_DIR, CMS_PATH, THIRDPARTY_DIR, THIRDPARTY_PATH, ASSETS_DIR, ASSETS_PATH, THEMES_DIR, THEMES_PATH
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/trunk@63154 467b73ca-7a2a-4603-9d3b-597d59a354a9
2008-09-27 18:02:38 +02:00
* @ param $file String Filenames should be relative to the base , eg , THIRDPARTY_DIR . '/tree/tree.css'
2008-07-17 23:08:35 +02:00
* @ param $media String Comma - separated list of media - types ( e . g . " screen,projector " )
* @ see http :// www . w3 . org / TR / REC - CSS2 / media . html
*/
public static function require_css ( $file , $media = null ) {
self :: $extra_requirements [ 'css' ][] = array ( $file , $media );
}
/**
* 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 .
*
* @ param $name String The identifier of the file . For example , css / MyFile . css would have the identifier " MyFile "
* @ param $media String Comma - separated list of media - types ( e . g . " screen,projector " )
*/
static function require_themed_css ( $name , $media = null ) {
self :: $extra_requirements [ 'themedcss' ][] = array ( $name , $media );
}
2007-07-19 12:40:05 +02:00
}
2010-04-23 02:11:32 +02:00
/**
* @ package cms
* @ subpackage core
*/
2009-11-21 04:21:00 +01:00
class LeftAndMainMarkingFilter {
/**
* @ var array Request params ( unsanitized )
*/
protected $params = array ();
/**
* @ param array $params Request params ( unsanitized )
*/
function __construct ( $params = null ) {
$this -> ids = array ();
$this -> expanded = array ();
$parents = array ();
$q = $this -> getQuery ( $params );
$res = $q -> execute ();
if ( ! $res ) return ;
// And keep a record of parents we don't need to get parents
// of themselves, as well as IDs to mark
foreach ( $res as $row ) {
if ( $row [ 'ParentID' ]) $parents [ $row [ 'ParentID' ]] = true ;
$this -> ids [ $row [ 'ID' ]] = true ;
}
// We need to recurse up the tree,
// finding ParentIDs for each ID until we run out of parents
while ( ! empty ( $parents )) {
$res = DB :: query ( 'SELECT "ParentID", "ID" FROM "SiteTree" WHERE "ID" in (' . implode ( ',' , array_keys ( $parents )) . ')' );
$parents = array ();
foreach ( $res as $row ) {
if ( $row [ 'ParentID' ]) $parents [ $row [ 'ParentID' ]] = true ;
$this -> ids [ $row [ 'ID' ]] = true ;
$this -> expanded [ $row [ 'ID' ]] = true ;
}
}
}
protected function getQuery ( $params ) {
$where = array ();
$SQL_params = Convert :: raw2sql ( $params );
if ( isset ( $SQL_params [ 'ID' ])) unset ( $SQL_params [ 'ID' ]);
foreach ( $SQL_params as $name => $val ) {
switch ( $name ) {
default :
// Partial string match against a variety of fields
if ( ! empty ( $val ) && singleton ( " SiteTree " ) -> hasDatabaseField ( $name )) {
$where [] = " \" $name\ " LIKE '%$val%' " ;
}
}
}
return new SQLQuery (
array ( " ParentID " , " ID " ),
'SiteTree' ,
$where
);
}
function mark ( $node ) {
$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 ;
}
}
2009-11-21 04:16:48 +01:00
?>