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
*/
2008-11-20 00:26:07 +01:00
static $url_base = " admin " ;
2008-11-02 22:27:55 +01:00
static $url_segment ;
2008-11-26 01:58:41 +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 ;
static $tree_class = null ;
2008-04-05 05:43:58 +02:00
2007-07-19 12:40:05 +02:00
static $ForceReload ;
2007-09-14 21:26:56 +02:00
2008-02-25 03:10:37 +01:00
static $allowed_actions = array (
'ajaxupdateparent' ,
'ajaxupdatesort' ,
'callPageMethod' ,
'deleteitems' ,
'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' ,
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 (),
);
2008-12-11 23:25:42 +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
if ( ! Permission :: checkMember ( $member , " CMS_ACCESS_ $this->class " )) {
return false ;
}
return true ;
}
2008-11-07 13:21:10 +01:00
/**
* @ uses LeftAndMainDecorator -> init ()
* @ uses LeftAndMainDecorator -> accessedCMS ()
2008-12-11 23:25:42 +01:00
* @ uses CMSMenu
* @ uses Director :: set_site_mode ()
2008-11-07 13:21:10 +01:00
*/
2007-07-19 12:40:05 +02:00
function init () {
2008-12-11 23:25:42 +01:00
parent :: init ();
2007-07-19 12:40:05 +02:00
Director :: set_site_mode ( 'cms' );
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
2008-12-10 10:07:46 +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' ),
'http://userhelp.silverstripe.com'
);
2007-11-13 01:14:15 +01:00
// set reading lang
2008-06-25 06:11:36 +02:00
if ( Translatable :: is_enabled () && ! Director :: is_ajax ()) {
Merging refactored Translatable from trunk, and related changes to CMSMain
------------------------------------------------------------------------
r69959 | ischommer | 2009-01-11 01:15:30 +1300 (Sun, 11 Jan 2009) | 18 lines
Merged, debugged and enhanced Translatable patches from branches/translatable at r64523, r64523, 64523, thanks wakeless!
API CHANGE Changed Translatable schema from auxilliary tables (SiteTree_lang, SiteTree_lang_Live) to automatically filtered records on the original table (SiteTree, SiteTree_Live), using $Lang and $OriginalID properties. Incompatible update to old schema, migration script is in the works.
API CHANGE Removed Translatable::get_one(), Translatable::write()
ENHANCEMENT Simplified Translatable tree generation by using getSiteTreeFor() in CMSMain->createtranslation()
ENHANCEMENT Added AllChildrenIncludingDeleted(), augmentNumChildrenCountQuery(), augmentAllChildrenIncludingDeleted(), augmentStageChildren() to Translatable class to allow for more stable tree generation.
ENHANCEMENT Moved definition of Translatable schema from augmentDatabase() to Translatable->extraStatics()
ENHANCEMENT Changes to the CMS language selection refresh the whole admin interface instead of the tree only. This way we can add a URL parameter ?lang=<lang> to /admin, which makes the specific language bookmarkable and reloadable. Changes to LangSelector.js
ENHANCEMENT Added fallback to ModelAsController->getNestedController() to fetch page with matching URLSegment but different language in case no page is found in the current language.
ENHANCEMENT Added helper methods to Translatable: getTranslation(), hasTranslation(), isTranslation(), findOriginalIDs()
ENHANCEMENT Getters and setters for Translatable->getOriginalPage() etc.
ENHANCEMENT Hooking Translatable into ModelAsController and ContentController initialization in order to call choose_site_lang()
ENHANCEMENT Simplified Translatable->augmentSQL(), augmentWrite() by not using auxilliary tables
ENHANCEMENT Showing clickable links for Translations in Translatable->updateCMSFields()
BUGFIX Modifying Hierarchy/SiteTree Children getters to accept optional "context" which can be used to set a language explicitly through the $Lang property, rather than implicitly reyling on the static Translatable::current_lang()
BUGFIX Fixed TranslatableTest to work with new datamodel
BUGFIX Temporarily disabled cookie/session selection in Translatable::choose_site_lang() until we have a good test suite for the side effects.
MINOR Added "untranslated" CSS styles to tree nodes and marking them as inactive/grey
------------------------------------------------------------------------
r70307 | ischommer | 2009-01-16 17:16:19 +1300 (Fri, 16 Jan 2009) | 2 lines
ENHANCEMENT Simplifying creation logic of new languages in CMS by reloading complete interface, rather than refreshing partial interface, language dropdown etc.
API CHANGE Removed CMSMain->switchlanguage()
------------------------------------------------------------------------
r70308 | ischommer | 2009-01-16 17:17:37 +1300 (Fri, 16 Jan 2009) | 2 lines
ENHANCEMENT Moved language selector in CMS above tree for better visibility, added padding and adjusted dropdown width
ENHANCEMENT Removed "Translating mode" status message above edit form - should be clear by the language dropdown above the CMS tree now
------------------------------------------------------------------------
r70322 | ischommer | 2009-01-19 13:09:55 +1300 (Mon, 19 Jan 2009) | 1 line
BUGFIX Ensuring that new pages can't be created when in translation mode by disabling the "create..." tree action
------------------------------------------------------------------------
r70323 | ischommer | 2009-01-19 13:11:08 +1300 (Mon, 19 Jan 2009) | 1 line
BUGFIX Fixed expanded/unexpanded flags on new tree items - was showing expanded styling (plus icon) with newly created pages
------------------------------------------------------------------------
r70324 | ischommer | 2009-01-19 13:26:02 +1300 (Mon, 19 Jan 2009) | 1 line
BUGFIX Making sure that LeftAndMain->CurrentPage() respects language settings - was returning pages in different language from session after switching between languages in cms
------------------------------------------------------------------------
r71297 | sharvey | 2009-02-03 18:12:42 +1300 (Tue, 03 Feb 2009) | 1 line
BUGFIX Only show the LangSelector dropdown if there's multiple languages available on the site
------------------------------------------------------------------------
r73343 | ischommer | 2009-03-19 06:14:02 +1300 (Thu, 19 Mar 2009) | 1 line
BUGFIX Changed CSS selector for TranslationTab javascript behaviour to be less specific
------------------------------------------------------------------------
r73344 | ischommer | 2009-03-19 06:14:59 +1300 (Thu, 19 Mar 2009) | 1 line
BUGFIX Checking for existence of original before trying to get translation in LeftAndMain->currentPage()
------------------------------------------------------------------------
r73345 | ischommer | 2009-03-19 06:18:52 +1300 (Thu, 19 Mar 2009) | 3 lines
ENHANCEMENT Showing all available languages in language selector above sitetree in CMS - you can now create new pages in completely new languages without any relation to an "original"
ENHANCEMENT Added CMSMain->IsTranslatableEnabled
API CHANGE Removed CMSMain->switchlanguage() - createTranslation() is sufficient for new, ajax refreshing of CMS state got way too complicated for switching languages, we now just reload the entire CMS with a different ?lang GET parameter
------------------------------------------------------------------------
r73469 | ischommer | 2009-03-20 21:49:27 +1300 (Fri, 20 Mar 2009) | 1 line
ENHANCEMENT Adjusted CMSMain and LeftAndMain to use locales instead of short lang codes when reading and writing translations. See r73468 for details on the underlying Translatable datamodel change
------------------------------------------------------------------------
r74071 | ischommer | 2009-04-04 10:24:59 +1300 (Sat, 04 Apr 2009) | 1 line
BUGFIX Fixed Form_EditForm_Locale reference in LeftAndMain_right.js (used to be Form_EditForm_Lang)
------------------------------------------------------------------------
r74072 | ischommer | 2009-04-04 10:26:51 +1300 (Sat, 04 Apr 2009) | 1 line
MINOR Using Translatable::choose_site_locale() instead of choose_site_lang() in LeftAndMain->init()
------------------------------------------------------------------------
r74951 | ischommer | 2009-04-22 16:23:56 +1200 (Wed, 22 Apr 2009) | 1 line
BUGFIX Fixed CMSMainTest->testThatGetCMSFieldsWorksOnEveryPageType() - was comparing a string $class with instanceof() instead of comparing the actually created instance
------------------------------------------------------------------------
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/branches/2.3@74988 467b73ca-7a2a-4603-9d3b-597d59a354a9
2009-04-23 03:46:49 +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
2008-12-11 23:25:42 +01:00
if ( ! $this -> canView ()) {
// 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
}
}
2008-12-11 23:25:42 +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
);
2008-12-11 23:25:42 +01:00
return Security :: permissionFailure ( $this , $messageSet );
2007-07-19 12:40:05 +02:00
}
2008-12-11 23:25:42 +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 07:25:38 +02:00
// Override HtmlEditorField's config with our own
HtmlEditorconfig :: set_active ( 'cms' );
2008-08-13 02:14:31 +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)
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 . '/firebug/firebug-lite-compressed.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
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 . '/firebug/firebugx.js' );
2008-09-16 23:46:08 +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 . '/prototype.js' );
2008-11-26 05:45:43 +01:00
Requirements :: javascript ( THIRDPARTY_DIR . '/jquery/jquery.js' );
2008-11-21 01:54:17 +01:00
Requirements :: javascript ( THIRDPARTY_DIR . '/jquery/jquery_improvements.js' );
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 . '/behaviour.js' );
2008-11-12 23:28:24 +01:00
Requirements :: javascript ( THIRDPARTY_DIR . '/jquery/plugins/livequery/jquery.livequery.js' );
2008-11-12 05:31:53 +01:00
Requirements :: javascript ( SAPPHIRE_DIR . '/javascript/core/jquery.ondemand.js' );
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 . '/prototype_improvements.js' );
Requirements :: javascript ( THIRDPARTY_DIR . '/loader.js' );
Requirements :: javascript ( THIRDPARTY_DIR . '/hover.js' );
Requirements :: javascript ( THIRDPARTY_DIR . '/layout_helpers.js' );
2009-03-06 04:10:41 +01:00
Requirements :: add_i18n_javascript ( SAPPHIRE_DIR . '/javascript/lang' );
2009-03-16 03:59:52 +01:00
Requirements :: add_i18n_javascript ( CMS_DIR . '/javascript/lang' );
2008-09-16 23:46:08 +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 . '/scriptaculous/effects.js' );
Requirements :: javascript ( THIRDPARTY_DIR . '/scriptaculous/dragdrop.js' );
Requirements :: javascript ( THIRDPARTY_DIR . '/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 :: css ( THIRDPARTY_DIR . '/greybox/greybox.css' );
Requirements :: javascript ( THIRDPARTY_DIR . '/greybox/AmiJS.js' );
Requirements :: javascript ( THIRDPARTY_DIR . '/greybox/greybox.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' );
Requirements :: javascript ( CMS_DIR . '/javascript/LeftAndMain_left.js' );
Requirements :: javascript ( CMS_DIR . '/javascript/LeftAndMain_right.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 ( CMS_DIR . '/javascript/SideTabs.js' );
Requirements :: javascript ( CMS_DIR . '/javascript/SideReports.js' );
Requirements :: javascript ( CMS_DIR . '/javascript/LangSelector.js' );
Requirements :: javascript ( CMS_DIR . '/javascript/TranslationTab.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
Requirements :: customScript ( 'Behaviour.addLoader(hideLoading);' );
2008-12-04 02:47:41 +01:00
// Javascript combined files
Requirements :: combine_files (
'assets/base.js' ,
array (
'jsparty/prototype.js' ,
'jsparty/behaviour.js' ,
'jsparty/prototype_improvements.js' ,
'jsparty/jquery/jquery.js' ,
'jsparty/jquery/plugins/livequery/jquery.livequery.js' ,
'jsparty/jquery/plugins/effen/jquery.fn.js' ,
'sapphire/javascript/core/jquery.ondemand.js' ,
'jsparty/jquery/jquery_improvements.js' ,
'jsparty/firebug/firebugx.js' ,
'sapphire/javascript/i18n.js' ,
)
);
Requirements :: combine_files (
'assets/leftandmain.js' ,
array (
'jsparty/loader.js' ,
'jsparty/hover.js' ,
'jsparty/layout_helpers.js' ,
'jsparty/scriptaculous/effects.js' ,
'jsparty/scriptaculous/dragdrop.js' ,
'jsparty/scriptaculous/controls.js' ,
'jsparty/greybox/AmiJS.js' ,
'jsparty/greybox/greybox.js' ,
'cms/javascript/LeftAndMain.js' ,
'cms/javascript/LeftAndMain_left.js' ,
'cms/javascript/LeftAndMain_right.js' ,
//'jsparty/tiny_mce2/tiny_mce_src.js',
'jsparty/tree/tree.js' ,
'jsparty/tabstrip/tabstrip.js' ,
'cms/javascript/TinyMCEImageEnhancement.js' ,
'jsparty/SWFUpload/SWFUpload.js' ,
'cms/javascript/Upload.js' ,
'sapphire/javascript/TreeSelectorField.js' ,
'cms/javascript/ThumbnailStripField.js' ,
)
);
Requirements :: combine_files (
'assets/cmsmain.js' ,
array (
'cms/javascript/CMSMain.js' ,
'cms/javascript/CMSMain_left.js' ,
'cms/javascript/CMSMain_right.js' ,
'cms/javascript/SideTabs.js' ,
'cms/javascript/SideReports.js' ,
'cms/javascript/LangSelector.js' ,
'cms/javascript/TranslationTab.js' ,
'jsparty/calendar/calendar.js' ,
'jsparty/calendar/lang/calendar-en.js' ,
'jsparty/calendar/calendar-setup.js' ,
)
);
2007-09-16 04:21:47 +02:00
2008-11-07 13:21:10 +01:00
// DEPRECATED 2.3: Use init()
2007-08-16 08:25:17 +02:00
$dummy = null ;
$this -> extend ( 'augmentInit' , $dummy );
2008-11-07 13:21:10 +01:00
$dummy = null ;
$this -> extend ( 'init' , $dummy );
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-17 22:45:01 +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 "
);
}
/**
2008-11-20 00:26:07 +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 .
2008-11-02 22:27:55 +01:00
*/
2008-11-20 00:26:07 +01:00
static function menu_title_for_class ( $class ) {
$title = eval ( " return $class :: \$ menu_title; " );
if ( ! $title ) $title = preg_replace ( '/Admin$/' , '' , $class );
return $title ;
2008-04-05 05:43:58 +02:00
}
2007-09-14 21:26:56 +02:00
2007-07-19 12:40:05 +02:00
public function show ( $params ) {
if ( $params [ 'ID' ]) $this -> setCurrentPageID ( $params [ 'ID' ]);
2007-09-15 02:56:26 +02:00
if ( isset ( $params [ 'OtherID' ]))
2007-07-19 12:40:05 +02:00
Session :: set ( 'currentMember' , $params [ 'OtherID' ]);
if ( Director :: is_ajax ()) {
SSViewer :: setOption ( 'rewriteHashlinks' , false );
return $this -> EditForm () -> formHtmlContent ();
2007-09-14 21:26:56 +02:00
2007-07-19 12:40:05 +02:00
} else {
return array ();
}
}
2007-09-14 21:26:56 +02:00
2007-07-19 12:40:05 +02:00
public function getitem () {
$this -> setCurrentPageID ( $_REQUEST [ 'ID' ]);
SSViewer :: setOption ( 'rewriteHashlinks' , false );
2008-11-03 15:56:36 +01:00
2008-11-04 14:53:11 +01:00
if ( isset ( $_REQUEST [ 'ID' ]) && is_numeric ( $_REQUEST [ 'ID' ])) {
2008-11-03 15:56:36 +01:00
$record = DataObject :: get_by_id ( $this -> stat ( 'tree_class' ), $_REQUEST [ 'ID' ]);
if ( $record && ! $record -> canView ()) return Security :: permissionFailure ( $this );
}
2007-09-14 21:26:56 +02:00
2007-07-19 12:40:05 +02:00
$form = $this -> EditForm ();
if ( $form ) return $form -> formHtmlContent ();
else return " " ;
}
public function getLastFormIn ( $html ) {
$parts = split ( '</?form[^>]*>' , $html );
return $parts [ sizeof ( $parts ) - 2 ];
}
2008-11-05 03:28:11 +01:00
/**
* @ deprecated Use CMSMenu :: add_menu_item ();
*/
static function add_menu_item ( $code , $menuTitle , $url , $controllerClass = null , $priority = - 1 ) {
user_error ( " LeftAndMain::add_menu_item is deprecated; use CMSMenu::add_menu_item " , E_USER_NOTICE );
return CMSMenu :: add_menu_item ( $code , $menuTitle , $url , $controllerClass , $priority );
}
2007-07-19 12:40:05 +02:00
//------------------------------------------------------------------------------------------//
// Main UI components
2007-09-14 21:26:56 +02:00
2007-07-19 12:40:05 +02: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-11-26 01:58:41 +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 ();
2008-12-11 23:25:42 +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-17 22:45:01 +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-17 22:45:01 +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,
2008-11-20 00:26:07 +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 ) {
2008-12-10 09:57:40 +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 (
2008-12-11 23:25:42 +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
}
2008-09-23 04:24:23 +02:00
2008-11-20 00:26:07 +01:00
public function CMSTopMenu () {
return $this -> renderWith ( array ( 'CMSTopMenu_alternative' , 'CMSTopMenu' ));
}
2007-07-19 12:40:05 +02:00
/**
* Return a list of appropriate templates for this class , with the given suffix
2007-09-14 21:26:56 +02:00
*/
2007-07-19 12:40:05 +02:00
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-11-21 05:38:27 +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-04-29 04:49:29 +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-04-30 07:39:12 +02:00
/**
* Get a site tree displaying the nodes under the given objects
* @ 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
*/
2009-05-14 05:36:11 +02:00
function getSiteTreeFor ( $className , $rootID = null , $childrenMethod = null , $filterFunction = null ) {
// Default childrenMethod
if ( ! $childrenMethod ) $childrenMethod = 'AllChildrenIncludingDeleted' ;
// Get the tree root
2007-07-19 12:40:05 +02:00
$obj = $rootID ? $this -> getRecord ( $rootID ) : singleton ( $className );
2009-05-14 05:36:11 +02:00
// Mark the nodes of the tree to return
if ( $filterFunction ) $obj -> setMarkingFilterFunction ( $filterFunction );
2009-04-30 07:39:12 +02:00
$obj -> markPartialTree ( 30 , $this , $childrenMethod );
2009-05-14 05:36:11 +02:00
// Ensure current page is exposed
2007-07-19 12:40:05 +02:00
if ( $p = $this -> currentPage ()) $obj -> markToExpose ( $p );
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
$siteTree = $obj -> getChildrenAsUL ( " " , '
" <li id= \" record- $child->ID\ " class = \ " " . $child -> CMSTreeClasses ( $extraArg ) . " \" > " .
2008-02-25 03:10:37 +01:00
" <a href= \" " . Director :: link ( substr ( $extraArg -> Link (), 0 , - 1 ), " show " , $child -> ID ) . " \" class= \" " . $child -> CMSTreeClasses ( $extraArg ) . " \" title= \" ' . _t('LeftAndMain.PAGETYPE','Page type: ') . ' " . $child -> class . " \" > " .
( $child -> TreeTitle ()) .
2007-07-19 12:40:05 +02:00
" </a> "
'
2009-04-30 07:39:12 +02:00
, $this , true , $childrenMethod );
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 ) {
$rootLink = $this -> Link () . '0' ;
2007-08-16 08:25:17 +02:00
// This lets us override the tree title with an extension
if ( $this -> hasMethod ( 'getCMSTreeTitle' )) $treeTitle = $this -> getCMSTreeTitle ();
2007-11-07 00:44:20 +01:00
else $treeTitle = _t ( 'LeftAndMain.SITECONTENTLEFT' , " Site Content " , PR_HIGH , 'Root node on left' );
2007-08-16 08:25:17 +02:00
2007-10-29 02:45:36 +01:00
$siteTree = " <ul id= \" sitetree \" class= \" tree unformatted \" ><li id= \" record-0 \" class= \" Root nodelete \" ><a href= \" $rootLink\ " >< strong > $treeTitle </ strong ></ a > "
2007-07-19 12:40:05 +02:00
. $siteTree . " </li></ul> " ;
}
2007-09-14 21:26:56 +02:00
2007-07-19 12:40:05 +02:00
return $siteTree ;
}
2007-09-14 21:26:56 +02:00
2009-04-30 07:39:12 +02:00
/**
* Get a subtree underneath the request param 'ID' .
* If ID = 0 , then get the whole tree .
*/
2007-07-19 12:40:05 +02:00
public function getsubtree () {
2009-04-30 07:39:12 +02:00
// Get the tree
$tree = $this -> getSiteTreeFor ( $this -> stat ( 'tree_class' ), $_REQUEST [ 'ID' ]);
// Trim off the outer tag
$tree = ereg_replace ( '^[ \t\r\n]*<ul[^>]*>' , '' , $tree );
$tree = ereg_replace ( '</ul[^>]*>[ \t\r\n]*$' , '' , $tree );
return $tree ;
2007-07-19 12:40:05 +02:00
}
2007-09-14 21:26:56 +02:00
2007-07-19 12:40:05 +02:00
/**
2007-09-14 21:26:56 +02:00
* Allows you to returns a new data object to the tree ( subclass of sitetree )
* and updates the tree via javascript .
2007-07-19 12:40:05 +02:00
*/
public function returnItemToUser ( $p ) {
if ( Director :: is_ajax ()) {
// Prepare the object for insertion.
2009-04-22 12:18:16 +02:00
$parentID = ( int ) $p -> ParentID ;
2007-09-14 21:26:56 +02:00
$id = $p -> ID ? $p -> ID : " new- $p->class - $p->ParentID " ;
2007-07-19 12:40:05 +02:00
$treeTitle = Convert :: raw2js ( $p -> TreeTitle ());
2009-01-23 02:52:11 +01:00
$hasChildren = ( is_numeric ( $id ) && $p -> AllChildren () && $p -> AllChildren () -> Count ()) ? ' unexpanded' : '' ;
2007-09-14 21:26:56 +02:00
2007-07-19 12:40:05 +02:00
// Ensure there is definitly a node avaliable. if not, append to the home tree.
$response = <<< JS
var tree = $ ( 'sitetree' );
var newNode = tree . createTreeNode ( " $id " , " $treeTitle " , " { $p -> class } { $hasChildren } " );
node = tree . getTreeNodeByIdx ( $parentID );
2009-04-22 12:18:16 +02:00
if ( ! node ) {
node = tree . getTreeNodeByIdx ( 0 );
}
2007-07-19 12:40:05 +02:00
node . open ();
node . appendTreeNode ( newNode );
newNode . selectTreeNode ();
JS ;
FormResponse :: add ( $response );
2008-11-14 02:15:05 +01:00
return FormResponse :: respond ();
} else {
2009-04-22 12:18:16 +02:00
Director :: redirect ( 'admin/' . self :: $url_segment . '/show/' . $p -> ID );
2007-07-19 12:40:05 +02:00
}
}
/**
2007-09-15 03:00:03 +02:00
* Save and Publish page handler
2007-07-19 12:40:05 +02:00
*/
public function save ( $urlParams , $form ) {
$className = $this -> stat ( 'tree_class' );
$result = '' ;
2007-09-14 21:26:56 +02:00
2007-09-25 23:58:42 +02:00
$SQL_id = Convert :: raw2sql ( $_REQUEST [ 'ID' ]);
if ( substr ( $SQL_id , 0 , 3 ) != 'new' ) {
$record = DataObject :: get_one ( $className , " ` $className `.ID = { $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
}
2007-09-14 21:26:56 +02:00
// We don't want to save a new version if there are no changes
2007-07-19 12:40:05 +02:00
$dataFields_new = $form -> Fields () -> dataFields ();
$dataFields_old = $record -> getAllFields ();
$changed = false ;
$hasNonRecordFields = false ;
foreach ( $dataFields_new as $datafield ) {
// if the form has fields not belonging to the record
if ( ! isset ( $dataFields_old [ $datafield -> Name ()])) {
2007-09-14 21:26:56 +02:00
$hasNonRecordFields = true ;
2007-07-19 12:40:05 +02:00
}
// if field-values have changed
if ( ! isset ( $dataFields_old [ $datafield -> Name ()]) || $dataFields_old [ $datafield -> Name ()] != $datafield -> dataValue ()) {
$changed = true ;
}
}
if ( ! $changed && ! $hasNonRecordFields ) {
// Tell the user we have saved even though we haven't, as not to confuse them
if ( is_a ( $record , " Page " )) {
$record -> Status = " Saved (update) " ;
}
2007-09-15 22:21:13 +02:00
FormResponse :: status_message ( _t ( 'LeftAndMain.SAVEDUP' , " Saved " ), " good " );
2007-07-19 12:40:05 +02:00
FormResponse :: update_status ( $record -> Status );
return FormResponse :: respond ();
}
2007-09-14 21:26:56 +02:00
2007-07-19 12:40:05 +02:00
$form -> dataFieldByName ( 'ID' ) -> Value = 0 ;
if ( isset ( $urlParams [ 'Sort' ]) && is_numeric ( $urlParams [ 'Sort' ])) {
$record -> Sort = $urlParams [ 'Sort' ];
}
// HACK: This should be turned into something more general
$originalClass = $record -> ClassName ;
$originalStatus = $record -> Status ;
2009-05-01 05:02:48 +02:00
$originalParentID = $record -> ParentID ;
2007-07-19 12:40:05 +02:00
$record -> HasBrokenLink = 0 ;
$record -> HasBrokenFile = 0 ;
$record -> writeWithoutVersion ();
// HACK: This should be turned into something more general
$originalURLSegment = $record -> URLSegment ;
$form -> saveInto ( $record , true );
2007-09-14 21:26:56 +02:00
2007-07-19 12:40:05 +02:00
if ( is_a ( $record , " Page " )) {
$record -> Status = ( $record -> Status == " New page " || $record -> Status == " Saved (new) " ) ? " Saved (new) " : " Saved (update) " ;
}
2007-09-14 21:26:56 +02:00
2007-07-19 12:40:05 +02:00
if ( Director :: is_ajax ()) {
2007-09-25 23:58:42 +02:00
if ( $SQL_id != $record -> ID ) {
FormResponse :: add ( " $ ('sitetree').setNodeIdx( \" { $SQL_id } \" , \" $record->ID\ " ); " );
2007-07-19 12:40:05 +02:00
FormResponse :: add ( " $ ('Form_EditForm').elements.ID.value = \" $record->ID\ " ; " );
}
if ( $added = DataObjectLog :: getAdded ( 'SiteTree' )) {
foreach ( $added as $page ) {
if ( $page -> ID != $record -> ID ) $result .= $this -> addTreeNodeJS ( $page );
}
}
if ( $deleted = DataObjectLog :: getDeleted ( 'SiteTree' )) {
foreach ( $deleted as $page ) {
if ( $page -> ID != $record -> ID ) $result .= $this -> deleteTreeNodeJS ( $page );
}
}
if ( $changed = DataObjectLog :: getChanged ( 'SiteTree' )) {
foreach ( $changed as $page ) {
if ( $page -> ID != $record -> ID ) {
$title = Convert :: raw2js ( $page -> TreeTitle ());
2008-07-18 05:40:32 +02:00
FormResponse :: add ( " $ ('sitetree').setNodeTitle( $page->ID , \" $title\ " ); " );
2007-07-19 12:40:05 +02:00
}
}
}
2007-09-14 21:26:56 +02:00
2007-09-15 22:21:13 +02:00
$message = _t ( 'LeftAndMain.SAVEDUP' );
2007-07-19 12:40:05 +02:00
2009-04-30 01:33:56 +02:00
// Update the class instance if necessary
2007-07-19 12:40:05 +02:00
if ( $originalClass != $record -> ClassName ) {
2009-04-30 01:33:56 +02:00
$newClassName = $record -> ClassName ;
// The records originally saved attribute was overwritten by $form->saveInto($record) before.
// This is necessary for newClassInstance() to work as expected, and trigger change detection
// on the ClassName attribute
$record -> setClassName ( $originalClass );
// Replace $record with a new instance
$record = $record -> newClassInstance ( $newClassName );
// update the tree icon
2007-07-19 12:40:05 +02:00
FormResponse :: add ( " if( \$ ('sitetree').setNodeIcon) \$ ('sitetree').setNodeIcon( $record->ID , ' $originalClass ', ' $record->ClassName '); " );
}
// HACK: This should be turned into somethign more general
2007-09-14 21:26:56 +02:00
if ( ( $record -> class == 'VirtualPage' && $originalURLSegment != $record -> URLSegment ) ||
2007-07-19 12:40:05 +02:00
( $originalClass != $record -> ClassName ) || self :: $ForceReload == true ) {
FormResponse :: add ( " $ ('Form_EditForm').getPageFromServer( $record->ID ); " );
}
2007-09-14 21:26:56 +02:00
2007-07-19 12:40:05 +02:00
// After reloading action
if ( $originalStatus != $record -> Status ) {
2007-09-15 22:21:13 +02:00
$message .= sprintf ( _t ( 'LeftAndMain.STATUSTO' , " Status changed to '%s' " ), $record -> Status );
2007-07-19 12:40:05 +02:00
}
2009-05-01 05:02:48 +02:00
if ( $originalParentID != $record -> ParentID ) {
FormResponse :: add ( " if( \$ ('sitetree').setNodeParentID) \$ ('sitetree').setNodeParentID( $record->ID , $record->ParentID ); " );
}
2007-09-14 21:26:56 +02:00
$record -> write ();
2008-02-25 03:10:37 +01:00
if ( ( $record -> class != 'VirtualPage' ) && $originalURLSegment != $record -> URLSegment ) {
$message .= sprintf ( _t ( 'LeftAndMain.CHANGEDURL' , " Changed URL to '%s' " ), $record -> URLSegment );
FormResponse :: add ( " \$ ('Form_EditForm').elements.URLSegment.value = \" $record->URLSegment\ " ; " );
FormResponse :: add ( " \$ ('Form_EditForm_StageURLSegment').value = \" { $record -> URLSegment } \" ; " );
}
2007-09-16 17:02:57 +02:00
// If the 'Save & Publish' button was clicked, also publish the page
if ( isset ( $urlParams [ 'publish' ]) && $urlParams [ 'publish' ] == 1 ) {
2008-08-12 04:59:27 +02:00
$record -> doPublish ();
2007-09-25 23:58:42 +02:00
2009-04-30 01:33:56 +02:00
// Update classname with original and get new instance (see above for explanation)
$record -> setClassName ( $originalClass );
$publishedRecord = $record -> newClassInstance ( $record -> ClassName );
2007-09-25 23:58:42 +02:00
2009-01-04 23:40:52 +01:00
return $this -> tellBrowserAboutPublicationChange (
$publishedRecord ,
sprintf (
_t (
'LeftAndMain.STATUSPUBLISHEDSUCCESS' ,
" Published '%s' successfully " ,
PR_MEDIUM ,
'Status message after publishing a page, showing the page title'
),
$record -> Title
)
);
2007-09-16 17:02:57 +02:00
} else {
// BUGFIX: Changed icon only shows after Save button is clicked twice http://support.silverstripe.com/gsoc/ticket/76
$title = Convert :: raw2js ( $record -> TreeTitle ());
FormResponse :: add ( " $ ('sitetree').setNodeTitle( \" $record->ID\ " , \ " $title\ " ); " );
$result .= $this -> getActionUpdateJS ( $record );
FormResponse :: status_message ( $message , " good " );
FormResponse :: update_status ( $record -> Status );
return FormResponse :: respond ();
}
2007-09-15 03:00:03 +02:00
}
2007-07-19 12:40:05 +02:00
}
2007-09-14 21:26:56 +02:00
2007-07-19 12:40:05 +02:00
/**
* Return a piece of javascript that will update the actions of the main form
*/
public function getActionUpdateJS ( $record ) {
// Get the new action buttons
2008-10-03 02:48:34 +02:00
2007-07-19 12:40:05 +02:00
$tempForm = $this -> getEditForm ( $record -> ID );
$actionList = '' ;
foreach ( $tempForm -> Actions () as $action ) {
$actionList .= $action -> Field () . ' ' ;
}
2007-09-14 21:26:56 +02:00
2007-07-19 12:40:05 +02:00
FormResponse :: add ( " $ ('Form_EditForm').loadActionsFromString(' " . Convert :: raw2js ( $actionList ) . " '); " );
2007-09-14 21:26:56 +02:00
2007-07-19 12:40:05 +02:00
return FormResponse :: respond ();
}
2007-09-14 21:26:56 +02:00
2007-07-19 12:40:05 +02:00
/**
* Return JavaScript code to generate a tree node for the given page , if visible
*/
2007-10-01 07:23:04 +02:00
public function addTreeNodeJS ( $page , $select = false ) {
2007-07-19 12:40:05 +02:00
$parentID = ( int ) $page -> ParentID ;
$title = Convert :: raw2js ( $page -> TreeTitle ());
$response = <<< JS
2007-10-01 07:23:04 +02:00
var newNode = $ ( 'sitetree' ) . createTreeNode ( $page -> ID , " $title " , " $page->class " );
var parentNode = $ ( 'sitetree' ) . getTreeNodeByIdx ( $parentID );
if ( parentNode ) parentNode . appendTreeNode ( newNode );
2007-07-19 12:40:05 +02:00
JS ;
2007-10-01 07:23:04 +02:00
$response .= ( $select ? " newNode.selectTreeNode(); \n " : " " ) ;
2007-07-19 12:40:05 +02:00
FormResponse :: add ( $response );
return FormResponse :: respond ();
}
/**
* Return JavaScript code to remove a tree node for the given page , if it exists .
*/
public function deleteTreeNodeJS ( $page ) {
2007-09-14 21:26:56 +02:00
$id = $page -> ID ? $page -> ID : $page -> OldID ;
2007-07-19 12:40:05 +02:00
$response = <<< JS
2007-09-14 21:26:56 +02:00
var node = $ ( 'sitetree' ) . getTreeNodeByIdx ( $id );
if ( node && node . parentTreeNode ) node . parentTreeNode . removeTreeNode ( node );
2007-07-19 12:40:05 +02:00
$ ( 'Form_EditForm' ) . closeIfSetTo ( $id );
JS ;
FormResponse :: add ( $response );
return FormResponse :: respond ();
}
2007-09-14 21:26:56 +02:00
/**
2007-07-19 12:40:05 +02:00
* Sets a static variable on this class which means the panel will be reloaded .
*/
static function ForceReload (){
self :: $ForceReload = true ;
}
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
*/
public function ajaxupdateparent () {
$id = $_REQUEST [ 'ID' ];
$parentID = $_REQUEST [ 'ParentID' ];
if ( $parentID == 'root' ){
2007-09-14 21:26:56 +02:00
$parentID = 0 ;
2007-07-19 12:40:05 +02:00
}
$_REQUEST [ 'ajax' ] = 1 ;
2007-09-14 21:26:56 +02:00
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 );
2007-07-19 12:40:05 +02:00
$node -> ParentID = $parentID ;
$node -> Status = " Saved (update) " ;
$node -> write ();
2007-09-14 21:26:56 +02:00
2007-07-19 12:40:05 +02:00
if ( is_numeric ( $_REQUEST [ 'CurrentlyOpenPageID' ])) {
$currentPage = DataObject :: get_by_id ( $this -> stat ( 'tree_class' ), $_REQUEST [ 'CurrentlyOpenPageID' ]);
if ( $currentPage ) {
$cleanupJS = $currentPage -> cmsCleanup_parentChanged ();
}
}
2007-09-14 21:26:56 +02:00
2007-09-15 22:21:13 +02:00
FormResponse :: status_message ( _t ( 'LeftAndMain.SAVED' , 'saved' ), 'good' );
2008-11-05 05:20:35 +01:00
if ( $cleanupJS ) FormResponse :: add ( $cleanupJS );
2007-09-14 21:26:56 +02:00
2007-07-19 12:40:05 +02:00
} else {
2007-09-15 22:21:13 +02:00
FormResponse :: status_message ( _t ( 'LeftAndMain.PLEASESAVE' , " Please Save Page: This page could not be upated because it hasn't been saved yet. " ), " good " );
2007-07-19 12:40:05 +02:00
}
2007-09-14 21:26:56 +02:00
2007-07-19 12:40:05 +02:00
return FormResponse :: respond ();
} else {
user_error ( " Error in ajaxupdateparent request; id= $id , parentID= $parentID " , E_USER_ERROR );
}
}
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
*/
public function ajaxupdatesort () {
$className = $this -> stat ( 'tree_class' );
$counter = 0 ;
$js = '' ;
$_REQUEST [ 'ajax' ] = 1 ;
2007-09-14 21:26:56 +02:00
2007-07-19 12:40:05 +02:00
if ( is_array ( $_REQUEST [ 'ID' ])) {
2007-10-02 07:10:35 +02:00
if ( $_REQUEST [ 'MovedNodeID' ] == 0 ){ //Sorting root
$movedNode = DataObject :: get ( $className , " `ParentID`=0 " );
} else {
$movedNode = DataObject :: get_by_id ( $className , $_REQUEST [ 'MovedNodeID' ]);
}
2007-07-19 12:40:05 +02:00
foreach ( $_REQUEST [ 'ID' ] as $id ) {
if ( $id == $movedNode -> ID ) {
$movedNode -> Sort = ++ $counter ;
$movedNode -> Status = " Saved (update) " ;
$movedNode -> write ();
2007-09-14 21:26:56 +02:00
2007-07-19 12:40:05 +02:00
$title = Convert :: raw2js ( $movedNode -> TreeTitle ());
2008-07-18 05:40:32 +02:00
$js .= " $ ('sitetree').setNodeTitle( $movedNode->ID , \" $title\ " ); \n " ;
2007-09-14 21:26:56 +02:00
2007-07-19 12:40:05 +02:00
// Nodes that weren't "actually moved" shouldn't be registered as having been edited; do a direct SQL update instead
} else if ( is_numeric ( $id )) {
++ $counter ;
DB :: query ( " UPDATE ` $className ` SET `Sort` = $counter WHERE `ID` = ' $id ' " );
}
}
// Virtual pages require selected to be null if the page is the same.
FormResponse :: add (
" if( $ ('sitetree').selected && $ ('sitetree').selected[0]) {
var idx = $ ( 'sitetree' ) . selected [ 0 ] . getIdx ();
if ( idx ){
$ ( 'Form_EditForm' ) . getPageFromServer ( idx );
}
} \n " . $js
);
2007-09-15 22:21:13 +02:00
FormResponse :: status_message ( _t ( 'LeftAndMain.SAVED' ), 'good' );
2007-07-19 12:40:05 +02:00
} else {
2007-09-15 22:21:13 +02:00
FormResponse :: error ( _t ( 'LeftAndMain.REQUESTERROR' , " Error in request " ));
2007-07-19 12:40:05 +02:00
}
2007-09-14 21:26:56 +02:00
2007-07-19 12:40:05 +02:00
return FormResponse :: respond ();
}
/**
* Delete a number of items
*/
public function deleteitems () {
$ids = split ( ' *, *' , $_REQUEST [ 'csvIDs' ]);
2007-09-14 21:26:56 +02:00
2007-07-19 12:40:05 +02:00
$script = " st = \$ ('sitetree'); \n " ;
foreach ( $ids as $id ) {
if ( is_numeric ( $id )) {
2008-11-16 09:04:00 +01:00
$record = DataObject :: get_by_id ( $this -> stat ( 'tree_class' ), $id );
2008-11-03 15:56:36 +01:00
if ( $record && ! $record -> canDelete ()) return Security :: permissionFailure ( $this );
2007-07-19 12:40:05 +02:00
DataObject :: delete_by_id ( $this -> stat ( 'tree_class' ), $id );
$script .= " node = st.getTreeNodeByIdx( $id ); if(node) node.parentTreeNode.removeTreeNode(node); $ ('Form_EditForm').closeIfSetTo( $id ); \n " ;
}
}
FormResponse :: add ( $script );
2007-09-14 21:26:56 +02:00
2007-07-19 12:40:05 +02:00
return FormResponse :: respond ();
}
2007-09-14 21:26:56 +02:00
2007-07-19 12:40:05 +02:00
public function EditForm () {
2009-04-29 04:45:19 +02:00
$record = $this -> currentPage ();
Merging refactored Translatable from trunk, and related changes to CMSMain
------------------------------------------------------------------------
r69959 | ischommer | 2009-01-11 01:15:30 +1300 (Sun, 11 Jan 2009) | 18 lines
Merged, debugged and enhanced Translatable patches from branches/translatable at r64523, r64523, 64523, thanks wakeless!
API CHANGE Changed Translatable schema from auxilliary tables (SiteTree_lang, SiteTree_lang_Live) to automatically filtered records on the original table (SiteTree, SiteTree_Live), using $Lang and $OriginalID properties. Incompatible update to old schema, migration script is in the works.
API CHANGE Removed Translatable::get_one(), Translatable::write()
ENHANCEMENT Simplified Translatable tree generation by using getSiteTreeFor() in CMSMain->createtranslation()
ENHANCEMENT Added AllChildrenIncludingDeleted(), augmentNumChildrenCountQuery(), augmentAllChildrenIncludingDeleted(), augmentStageChildren() to Translatable class to allow for more stable tree generation.
ENHANCEMENT Moved definition of Translatable schema from augmentDatabase() to Translatable->extraStatics()
ENHANCEMENT Changes to the CMS language selection refresh the whole admin interface instead of the tree only. This way we can add a URL parameter ?lang=<lang> to /admin, which makes the specific language bookmarkable and reloadable. Changes to LangSelector.js
ENHANCEMENT Added fallback to ModelAsController->getNestedController() to fetch page with matching URLSegment but different language in case no page is found in the current language.
ENHANCEMENT Added helper methods to Translatable: getTranslation(), hasTranslation(), isTranslation(), findOriginalIDs()
ENHANCEMENT Getters and setters for Translatable->getOriginalPage() etc.
ENHANCEMENT Hooking Translatable into ModelAsController and ContentController initialization in order to call choose_site_lang()
ENHANCEMENT Simplified Translatable->augmentSQL(), augmentWrite() by not using auxilliary tables
ENHANCEMENT Showing clickable links for Translations in Translatable->updateCMSFields()
BUGFIX Modifying Hierarchy/SiteTree Children getters to accept optional "context" which can be used to set a language explicitly through the $Lang property, rather than implicitly reyling on the static Translatable::current_lang()
BUGFIX Fixed TranslatableTest to work with new datamodel
BUGFIX Temporarily disabled cookie/session selection in Translatable::choose_site_lang() until we have a good test suite for the side effects.
MINOR Added "untranslated" CSS styles to tree nodes and marking them as inactive/grey
------------------------------------------------------------------------
r70307 | ischommer | 2009-01-16 17:16:19 +1300 (Fri, 16 Jan 2009) | 2 lines
ENHANCEMENT Simplifying creation logic of new languages in CMS by reloading complete interface, rather than refreshing partial interface, language dropdown etc.
API CHANGE Removed CMSMain->switchlanguage()
------------------------------------------------------------------------
r70308 | ischommer | 2009-01-16 17:17:37 +1300 (Fri, 16 Jan 2009) | 2 lines
ENHANCEMENT Moved language selector in CMS above tree for better visibility, added padding and adjusted dropdown width
ENHANCEMENT Removed "Translating mode" status message above edit form - should be clear by the language dropdown above the CMS tree now
------------------------------------------------------------------------
r70322 | ischommer | 2009-01-19 13:09:55 +1300 (Mon, 19 Jan 2009) | 1 line
BUGFIX Ensuring that new pages can't be created when in translation mode by disabling the "create..." tree action
------------------------------------------------------------------------
r70323 | ischommer | 2009-01-19 13:11:08 +1300 (Mon, 19 Jan 2009) | 1 line
BUGFIX Fixed expanded/unexpanded flags on new tree items - was showing expanded styling (plus icon) with newly created pages
------------------------------------------------------------------------
r70324 | ischommer | 2009-01-19 13:26:02 +1300 (Mon, 19 Jan 2009) | 1 line
BUGFIX Making sure that LeftAndMain->CurrentPage() respects language settings - was returning pages in different language from session after switching between languages in cms
------------------------------------------------------------------------
r71297 | sharvey | 2009-02-03 18:12:42 +1300 (Tue, 03 Feb 2009) | 1 line
BUGFIX Only show the LangSelector dropdown if there's multiple languages available on the site
------------------------------------------------------------------------
r73343 | ischommer | 2009-03-19 06:14:02 +1300 (Thu, 19 Mar 2009) | 1 line
BUGFIX Changed CSS selector for TranslationTab javascript behaviour to be less specific
------------------------------------------------------------------------
r73344 | ischommer | 2009-03-19 06:14:59 +1300 (Thu, 19 Mar 2009) | 1 line
BUGFIX Checking for existence of original before trying to get translation in LeftAndMain->currentPage()
------------------------------------------------------------------------
r73345 | ischommer | 2009-03-19 06:18:52 +1300 (Thu, 19 Mar 2009) | 3 lines
ENHANCEMENT Showing all available languages in language selector above sitetree in CMS - you can now create new pages in completely new languages without any relation to an "original"
ENHANCEMENT Added CMSMain->IsTranslatableEnabled
API CHANGE Removed CMSMain->switchlanguage() - createTranslation() is sufficient for new, ajax refreshing of CMS state got way too complicated for switching languages, we now just reload the entire CMS with a different ?lang GET parameter
------------------------------------------------------------------------
r73469 | ischommer | 2009-03-20 21:49:27 +1300 (Fri, 20 Mar 2009) | 1 line
ENHANCEMENT Adjusted CMSMain and LeftAndMain to use locales instead of short lang codes when reading and writing translations. See r73468 for details on the underlying Translatable datamodel change
------------------------------------------------------------------------
r74071 | ischommer | 2009-04-04 10:24:59 +1300 (Sat, 04 Apr 2009) | 1 line
BUGFIX Fixed Form_EditForm_Locale reference in LeftAndMain_right.js (used to be Form_EditForm_Lang)
------------------------------------------------------------------------
r74072 | ischommer | 2009-04-04 10:26:51 +1300 (Sat, 04 Apr 2009) | 1 line
MINOR Using Translatable::choose_site_locale() instead of choose_site_lang() in LeftAndMain->init()
------------------------------------------------------------------------
r74951 | ischommer | 2009-04-22 16:23:56 +1200 (Wed, 22 Apr 2009) | 1 line
BUGFIX Fixed CMSMainTest->testThatGetCMSFieldsWorksOnEveryPageType() - was comparing a string $class with instanceof() instead of comparing the actually created instance
------------------------------------------------------------------------
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/branches/2.3@74988 467b73ca-7a2a-4603-9d3b-597d59a354a9
2009-04-23 03:46:49 +02:00
if ( ! $record ) return false ;
2008-11-04 14:53:11 +01:00
Merging refactored Translatable from trunk, and related changes to CMSMain
------------------------------------------------------------------------
r69959 | ischommer | 2009-01-11 01:15:30 +1300 (Sun, 11 Jan 2009) | 18 lines
Merged, debugged and enhanced Translatable patches from branches/translatable at r64523, r64523, 64523, thanks wakeless!
API CHANGE Changed Translatable schema from auxilliary tables (SiteTree_lang, SiteTree_lang_Live) to automatically filtered records on the original table (SiteTree, SiteTree_Live), using $Lang and $OriginalID properties. Incompatible update to old schema, migration script is in the works.
API CHANGE Removed Translatable::get_one(), Translatable::write()
ENHANCEMENT Simplified Translatable tree generation by using getSiteTreeFor() in CMSMain->createtranslation()
ENHANCEMENT Added AllChildrenIncludingDeleted(), augmentNumChildrenCountQuery(), augmentAllChildrenIncludingDeleted(), augmentStageChildren() to Translatable class to allow for more stable tree generation.
ENHANCEMENT Moved definition of Translatable schema from augmentDatabase() to Translatable->extraStatics()
ENHANCEMENT Changes to the CMS language selection refresh the whole admin interface instead of the tree only. This way we can add a URL parameter ?lang=<lang> to /admin, which makes the specific language bookmarkable and reloadable. Changes to LangSelector.js
ENHANCEMENT Added fallback to ModelAsController->getNestedController() to fetch page with matching URLSegment but different language in case no page is found in the current language.
ENHANCEMENT Added helper methods to Translatable: getTranslation(), hasTranslation(), isTranslation(), findOriginalIDs()
ENHANCEMENT Getters and setters for Translatable->getOriginalPage() etc.
ENHANCEMENT Hooking Translatable into ModelAsController and ContentController initialization in order to call choose_site_lang()
ENHANCEMENT Simplified Translatable->augmentSQL(), augmentWrite() by not using auxilliary tables
ENHANCEMENT Showing clickable links for Translations in Translatable->updateCMSFields()
BUGFIX Modifying Hierarchy/SiteTree Children getters to accept optional "context" which can be used to set a language explicitly through the $Lang property, rather than implicitly reyling on the static Translatable::current_lang()
BUGFIX Fixed TranslatableTest to work with new datamodel
BUGFIX Temporarily disabled cookie/session selection in Translatable::choose_site_lang() until we have a good test suite for the side effects.
MINOR Added "untranslated" CSS styles to tree nodes and marking them as inactive/grey
------------------------------------------------------------------------
r70307 | ischommer | 2009-01-16 17:16:19 +1300 (Fri, 16 Jan 2009) | 2 lines
ENHANCEMENT Simplifying creation logic of new languages in CMS by reloading complete interface, rather than refreshing partial interface, language dropdown etc.
API CHANGE Removed CMSMain->switchlanguage()
------------------------------------------------------------------------
r70308 | ischommer | 2009-01-16 17:17:37 +1300 (Fri, 16 Jan 2009) | 2 lines
ENHANCEMENT Moved language selector in CMS above tree for better visibility, added padding and adjusted dropdown width
ENHANCEMENT Removed "Translating mode" status message above edit form - should be clear by the language dropdown above the CMS tree now
------------------------------------------------------------------------
r70322 | ischommer | 2009-01-19 13:09:55 +1300 (Mon, 19 Jan 2009) | 1 line
BUGFIX Ensuring that new pages can't be created when in translation mode by disabling the "create..." tree action
------------------------------------------------------------------------
r70323 | ischommer | 2009-01-19 13:11:08 +1300 (Mon, 19 Jan 2009) | 1 line
BUGFIX Fixed expanded/unexpanded flags on new tree items - was showing expanded styling (plus icon) with newly created pages
------------------------------------------------------------------------
r70324 | ischommer | 2009-01-19 13:26:02 +1300 (Mon, 19 Jan 2009) | 1 line
BUGFIX Making sure that LeftAndMain->CurrentPage() respects language settings - was returning pages in different language from session after switching between languages in cms
------------------------------------------------------------------------
r71297 | sharvey | 2009-02-03 18:12:42 +1300 (Tue, 03 Feb 2009) | 1 line
BUGFIX Only show the LangSelector dropdown if there's multiple languages available on the site
------------------------------------------------------------------------
r73343 | ischommer | 2009-03-19 06:14:02 +1300 (Thu, 19 Mar 2009) | 1 line
BUGFIX Changed CSS selector for TranslationTab javascript behaviour to be less specific
------------------------------------------------------------------------
r73344 | ischommer | 2009-03-19 06:14:59 +1300 (Thu, 19 Mar 2009) | 1 line
BUGFIX Checking for existence of original before trying to get translation in LeftAndMain->currentPage()
------------------------------------------------------------------------
r73345 | ischommer | 2009-03-19 06:18:52 +1300 (Thu, 19 Mar 2009) | 3 lines
ENHANCEMENT Showing all available languages in language selector above sitetree in CMS - you can now create new pages in completely new languages without any relation to an "original"
ENHANCEMENT Added CMSMain->IsTranslatableEnabled
API CHANGE Removed CMSMain->switchlanguage() - createTranslation() is sufficient for new, ajax refreshing of CMS state got way too complicated for switching languages, we now just reload the entire CMS with a different ?lang GET parameter
------------------------------------------------------------------------
r73469 | ischommer | 2009-03-20 21:49:27 +1300 (Fri, 20 Mar 2009) | 1 line
ENHANCEMENT Adjusted CMSMain and LeftAndMain to use locales instead of short lang codes when reading and writing translations. See r73468 for details on the underlying Translatable datamodel change
------------------------------------------------------------------------
r74071 | ischommer | 2009-04-04 10:24:59 +1300 (Sat, 04 Apr 2009) | 1 line
BUGFIX Fixed Form_EditForm_Locale reference in LeftAndMain_right.js (used to be Form_EditForm_Lang)
------------------------------------------------------------------------
r74072 | ischommer | 2009-04-04 10:26:51 +1300 (Sat, 04 Apr 2009) | 1 line
MINOR Using Translatable::choose_site_locale() instead of choose_site_lang() in LeftAndMain->init()
------------------------------------------------------------------------
r74951 | ischommer | 2009-04-22 16:23:56 +1200 (Wed, 22 Apr 2009) | 1 line
BUGFIX Fixed CMSMainTest->testThatGetCMSFieldsWorksOnEveryPageType() - was comparing a string $class with instanceof() instead of comparing the actually created instance
------------------------------------------------------------------------
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/branches/2.3@74988 467b73ca-7a2a-4603-9d3b-597d59a354a9
2009-04-23 03:46:49 +02:00
if ( $record && ! $record -> canView ()) return Security :: permissionFailure ( $this );
2008-11-03 15:56:36 +01:00
Merging refactored Translatable from trunk, and related changes to CMSMain
------------------------------------------------------------------------
r69959 | ischommer | 2009-01-11 01:15:30 +1300 (Sun, 11 Jan 2009) | 18 lines
Merged, debugged and enhanced Translatable patches from branches/translatable at r64523, r64523, 64523, thanks wakeless!
API CHANGE Changed Translatable schema from auxilliary tables (SiteTree_lang, SiteTree_lang_Live) to automatically filtered records on the original table (SiteTree, SiteTree_Live), using $Lang and $OriginalID properties. Incompatible update to old schema, migration script is in the works.
API CHANGE Removed Translatable::get_one(), Translatable::write()
ENHANCEMENT Simplified Translatable tree generation by using getSiteTreeFor() in CMSMain->createtranslation()
ENHANCEMENT Added AllChildrenIncludingDeleted(), augmentNumChildrenCountQuery(), augmentAllChildrenIncludingDeleted(), augmentStageChildren() to Translatable class to allow for more stable tree generation.
ENHANCEMENT Moved definition of Translatable schema from augmentDatabase() to Translatable->extraStatics()
ENHANCEMENT Changes to the CMS language selection refresh the whole admin interface instead of the tree only. This way we can add a URL parameter ?lang=<lang> to /admin, which makes the specific language bookmarkable and reloadable. Changes to LangSelector.js
ENHANCEMENT Added fallback to ModelAsController->getNestedController() to fetch page with matching URLSegment but different language in case no page is found in the current language.
ENHANCEMENT Added helper methods to Translatable: getTranslation(), hasTranslation(), isTranslation(), findOriginalIDs()
ENHANCEMENT Getters and setters for Translatable->getOriginalPage() etc.
ENHANCEMENT Hooking Translatable into ModelAsController and ContentController initialization in order to call choose_site_lang()
ENHANCEMENT Simplified Translatable->augmentSQL(), augmentWrite() by not using auxilliary tables
ENHANCEMENT Showing clickable links for Translations in Translatable->updateCMSFields()
BUGFIX Modifying Hierarchy/SiteTree Children getters to accept optional "context" which can be used to set a language explicitly through the $Lang property, rather than implicitly reyling on the static Translatable::current_lang()
BUGFIX Fixed TranslatableTest to work with new datamodel
BUGFIX Temporarily disabled cookie/session selection in Translatable::choose_site_lang() until we have a good test suite for the side effects.
MINOR Added "untranslated" CSS styles to tree nodes and marking them as inactive/grey
------------------------------------------------------------------------
r70307 | ischommer | 2009-01-16 17:16:19 +1300 (Fri, 16 Jan 2009) | 2 lines
ENHANCEMENT Simplifying creation logic of new languages in CMS by reloading complete interface, rather than refreshing partial interface, language dropdown etc.
API CHANGE Removed CMSMain->switchlanguage()
------------------------------------------------------------------------
r70308 | ischommer | 2009-01-16 17:17:37 +1300 (Fri, 16 Jan 2009) | 2 lines
ENHANCEMENT Moved language selector in CMS above tree for better visibility, added padding and adjusted dropdown width
ENHANCEMENT Removed "Translating mode" status message above edit form - should be clear by the language dropdown above the CMS tree now
------------------------------------------------------------------------
r70322 | ischommer | 2009-01-19 13:09:55 +1300 (Mon, 19 Jan 2009) | 1 line
BUGFIX Ensuring that new pages can't be created when in translation mode by disabling the "create..." tree action
------------------------------------------------------------------------
r70323 | ischommer | 2009-01-19 13:11:08 +1300 (Mon, 19 Jan 2009) | 1 line
BUGFIX Fixed expanded/unexpanded flags on new tree items - was showing expanded styling (plus icon) with newly created pages
------------------------------------------------------------------------
r70324 | ischommer | 2009-01-19 13:26:02 +1300 (Mon, 19 Jan 2009) | 1 line
BUGFIX Making sure that LeftAndMain->CurrentPage() respects language settings - was returning pages in different language from session after switching between languages in cms
------------------------------------------------------------------------
r71297 | sharvey | 2009-02-03 18:12:42 +1300 (Tue, 03 Feb 2009) | 1 line
BUGFIX Only show the LangSelector dropdown if there's multiple languages available on the site
------------------------------------------------------------------------
r73343 | ischommer | 2009-03-19 06:14:02 +1300 (Thu, 19 Mar 2009) | 1 line
BUGFIX Changed CSS selector for TranslationTab javascript behaviour to be less specific
------------------------------------------------------------------------
r73344 | ischommer | 2009-03-19 06:14:59 +1300 (Thu, 19 Mar 2009) | 1 line
BUGFIX Checking for existence of original before trying to get translation in LeftAndMain->currentPage()
------------------------------------------------------------------------
r73345 | ischommer | 2009-03-19 06:18:52 +1300 (Thu, 19 Mar 2009) | 3 lines
ENHANCEMENT Showing all available languages in language selector above sitetree in CMS - you can now create new pages in completely new languages without any relation to an "original"
ENHANCEMENT Added CMSMain->IsTranslatableEnabled
API CHANGE Removed CMSMain->switchlanguage() - createTranslation() is sufficient for new, ajax refreshing of CMS state got way too complicated for switching languages, we now just reload the entire CMS with a different ?lang GET parameter
------------------------------------------------------------------------
r73469 | ischommer | 2009-03-20 21:49:27 +1300 (Fri, 20 Mar 2009) | 1 line
ENHANCEMENT Adjusted CMSMain and LeftAndMain to use locales instead of short lang codes when reading and writing translations. See r73468 for details on the underlying Translatable datamodel change
------------------------------------------------------------------------
r74071 | ischommer | 2009-04-04 10:24:59 +1300 (Sat, 04 Apr 2009) | 1 line
BUGFIX Fixed Form_EditForm_Locale reference in LeftAndMain_right.js (used to be Form_EditForm_Lang)
------------------------------------------------------------------------
r74072 | ischommer | 2009-04-04 10:26:51 +1300 (Sat, 04 Apr 2009) | 1 line
MINOR Using Translatable::choose_site_locale() instead of choose_site_lang() in LeftAndMain->init()
------------------------------------------------------------------------
r74951 | ischommer | 2009-04-22 16:23:56 +1200 (Wed, 22 Apr 2009) | 1 line
BUGFIX Fixed CMSMainTest->testThatGetCMSFieldsWorksOnEveryPageType() - was comparing a string $class with instanceof() instead of comparing the actually created instance
------------------------------------------------------------------------
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/branches/2.3@74988 467b73ca-7a2a-4603-9d3b-597d59a354a9
2009-04-23 03:46:49 +02:00
return $this -> getEditForm ( $record -> ID );
2007-07-19 12:40:05 +02:00
}
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 () {
$id = $_REQUEST [ 'ID' ] ? $_REQUEST [ 'ID' ] : $this -> currentPageID ();
2007-09-14 21:26:56 +02:00
2007-07-19 12:40:05 +02:00
if ( $id ) $form = $this -> getEditForm ( $id );
$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
2007-07-19 12:40:05 +02:00
public function currentPageID () {
if ( isset ( $_REQUEST [ 'ID' ]) && is_numeric ( $_REQUEST [ 'ID' ])) {
return $_REQUEST [ 'ID' ];
2007-08-08 03:16:02 +02:00
} elseif ( isset ( $this -> urlParams [ 'ID' ]) && is_numeric ( $this -> urlParams [ 'ID' ])) {
2007-07-19 12:40:05 +02:00
return $this -> urlParams [ 'ID' ];
} elseif ( Session :: get ( " { $this -> class } .currentPage " )) {
return Session :: get ( " { $this -> class } .currentPage " );
} else {
return null ;
}
}
2007-09-14 21:26:56 +02:00
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
2007-07-19 12:40:05 +02:00
public function currentPage () {
2009-04-29 04:45:19 +02:00
return $this -> getRecord ( $this -> currentPageID ());
2007-07-19 12:40:05 +02:00
}
2007-09-14 21:26:56 +02:00
2007-07-19 12:40:05 +02:00
public function isCurrentPage ( DataObject $page ) {
return $page -> ID == Session :: get ( " { $this -> class } .currentPage " );
}
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
/**
2008-11-20 02:39:31 +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 () {
$sapphireVersionFile = file_get_contents ( '../sapphire/silverstripe_version' );
$jspartyVersionFile = file_get_contents ( '../jsparty/silverstripe_version' );
$cmsVersionFile = file_get_contents ( '../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 );
2008-11-20 02:39:31 +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 ( $jspartyVersionFile , " /jsparty/trunk " )) {
$jspartyVersion = " trunk " ;
} else {
preg_match ( " /jsparty \ /(?:(?:branches)|(?:tags))(?: \ /rc)? \ /([A-Za-z0-9._-]+) \ /silverstripe_version/ " , $jspartyVersionFile , $matches );
2008-11-20 02:39:31 +01:00
$jspartyVersion = ( $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 );
2008-11-20 02:39:31 +01:00
$cmsVersion = ( $matches ) ? $matches [ 1 ] : null ;
2007-09-14 21:26:56 +02:00
}
2007-07-19 12:40:05 +02:00
if ( $sapphireVersion == $jspartyVersion && $jspartyVersion == $cmsVersion ) {
return $sapphireVersion ;
} else {
return " cms: $cmsVersion , sapphire: $sapphireVersion , jsparty: $jspartyVersion " ;
}
}
/**
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:23:55 +01:00
static $application_link = " http://www.silverstripe.org/ " ;
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 ;
}
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 ;
}
2007-08-27 07:06:57 +02:00
/**
* Use this as an action handler for custom CMS buttons .
*/
function callPageMethod ( $data , $form ) {
$methodName = $form -> buttonClicked () -> extraData ();
$record = $this -> CurrentPage ();
return $record -> $methodName ( $data , $form );
}
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
}
2009-03-10 22:23:55 +01:00
?>