public function getNestedController()
 {
     if ($this->urlParams['URLSegment']) {
         $SQL_URLSegment = Convert::raw2sql($this->urlParams['URLSegment']);
         if (Translatable::is_enabled()) {
             $child = Translatable::get_one("SiteTree", "URLSegment = '{$SQL_URLSegment}'");
         } else {
             $child = DataObject::get_one("SiteTree", "URLSegment = '{$SQL_URLSegment}'");
         }
         if (!$child) {
             $child = $this->get404Page();
         }
         if ($child) {
             if (isset($_REQUEST['debug'])) {
                 Debug::message("Using record #{$child->ID} of type {$child->class} with URL {$this->urlParams['URLSegment']}");
             }
             $controllerClass = "{$child->class}_Controller";
             if ($this->urlParams['Action'] && ClassInfo::exists($controllerClass . '_' . $this->urlParams['Action'])) {
                 $controllerClass = $controllerClass . '_' . $this->urlParams['Action'];
             }
             if (ClassInfo::exists($controllerClass)) {
                 $controller = new $controllerClass($child);
             } else {
                 $controller = $child;
             }
             $controller->setURLParams($this->urlParams);
             return $controller;
         } else {
             die("The requested page couldn't be found.");
         }
     } else {
         user_error("ModelAsController not geting a URLSegment.  It looks like the site isn't redirecting to home", E_USER_ERROR);
     }
 }
	function setUp() {
		$this->origTranslatableSettings['enabled'] = Translatable::is_enabled();
		$this->origTranslatableSettings['default_lang'] = Translatable::default_lang();
		Translatable::enable();
		Translatable::set_default_lang("en");
		
		// needs to recreate the database schema with *_lang tables
		self::kill_temp_db();
		self::create_temp_db();
		
		parent::setUp();
	}
Beispiel #3
0
 /**
  * Get a list of languages with at least one element translated in (including the default language)
  *
  * @param string $className Look for languages in elements of this class
  * @return array Map of languages in the form langCode => langName
  */
 static function get_existing_content_languages($className = 'SiteTree', $where = '')
 {
     if (!Translatable::is_enabled()) {
         return false;
     }
     $query = new SQLQuery('Lang', $className . '_lang', $where, "", 'Lang');
     $dbLangs = $query->execute()->column();
     $langlist = array_merge((array) Translatable::default_lang(), (array) $dbLangs);
     $returnMap = array();
     $allCodes = array_merge(self::$all_locales, self::$common_languages);
     foreach ($langlist as $langCode) {
         $returnMap[$langCode] = is_array($allCodes[$langCode]) ? $allCodes[$langCode][0] : $allCodes[$langCode];
     }
     return $returnMap;
 }
	/**
	 * @uses LeftAndMainDecorator->init()
	 * @uses LeftAndMainDecorator->accessedCMS()
	 * @uses CMSMenu
	 * @uses Director::set_site_mode()
	 */
	function init() {
		parent::init();

		Director::set_site_mode('cms');
		
		// set language
		$member = Member::currentUser();
		if(!empty($member->Locale)) {
			i18n::set_locale($member->Locale);
		}
		
		// 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'
		);
		
		// set reading lang
		if(Translatable::is_enabled() && !Director::is_ajax()) {
			Translatable::choose_site_lang(array_keys(Translatable::get_existing_content_languages('SiteTree')));
		}

		// Allow customisation of the access check by a decorator
		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);
				}
			}
			
			if(Member::currentUser()) {
				Session::set("BackURL", null);
			}
			
			// if no alternate menu items have matched, return a permission error
			$messageSet = array(
				'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."),
			);

			return Security::permissionFailure($this, $messageSet);
		}

		// Don't continue if there's already been a redirection request.
		if(Director::redirected_to()) return;

		// Audit logging hook
		if(empty($_REQUEST['executeForm']) && !Director::is_ajax()) $this->extend('accessedCMS');
		
		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');
		Requirements::css(SAPPHIRE_DIR . '/css/Form.css');
		
		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)
			Requirements::javascript(THIRDPARTY_DIR . '/firebug/firebug-lite-compressed.js');
		} else {
			// By default, we include fake-objects for all firebug calls
			// to avoid javascript errors when referencing console.log() etc in javascript code
			Requirements::javascript(THIRDPARTY_DIR . '/firebug/firebugx.js');
		}
		
		Requirements::javascript(THIRDPARTY_DIR . '/prototype.js');
		Requirements::javascript(THIRDPARTY_DIR . '/jquery/jquery.js');
		Requirements::javascript(THIRDPARTY_DIR . '/jquery/jquery_improvements.js');
		Requirements::javascript(THIRDPARTY_DIR . '/behaviour.js');
		Requirements::javascript(THIRDPARTY_DIR . '/jquery/plugins/livequery/jquery.livequery.js');
		Requirements::javascript(SAPPHIRE_DIR . '/javascript/core/jquery.ondemand.js');
		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');
		Requirements::javascript(SAPPHIRE_DIR . "/javascript/i18n.js");
		
		Requirements::javascript(THIRDPARTY_DIR . '/scriptaculous/effects.js');
		Requirements::javascript(THIRDPARTY_DIR . '/scriptaculous/dragdrop.js');
		Requirements::javascript(THIRDPARTY_DIR . '/scriptaculous/controls.js');

		Requirements::css(THIRDPARTY_DIR . '/greybox/greybox.css');
		Requirements::javascript(THIRDPARTY_DIR . '/greybox/AmiJS.js');
		Requirements::javascript(THIRDPARTY_DIR . '/greybox/greybox.js');
		
		Requirements::javascript(THIRDPARTY_DIR . '/tree/tree.js');
		Requirements::css(THIRDPARTY_DIR . '/tree/tree.css');
		
		Requirements::javascript(CMS_DIR . '/javascript/LeftAndMain.js');
		Requirements::javascript(CMS_DIR . '/javascript/LeftAndMain_left.js');
		Requirements::javascript(CMS_DIR . '/javascript/LeftAndMain_right.js');
	
		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');
		
		Requirements::themedCSS('typography');

		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]);
		}
		
		Requirements::customScript('Behaviour.addLoader(hideLoading);');
		
		// 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',
			)
		);

		// DEPRECATED 2.3: Use init()
		$dummy = null;
		$this->extend('augmentInit', $dummy);
		
		$dummy = null;
		$this->extend('init', $dummy);
	}
Beispiel #5
0
	/**
	 * @uses LeftAndMainDecorator->augmentNewSiteTreeItem()
	 */
	public function getNewItem($id, $setID = true) {
		list($dummy, $className, $parentID, $suffix) = array_pad(explode('-',$id),4,null);
		
		if(Translatable::is_enabled()) {
			if (!Translatable::is_default_lang()) {
				$originalItem = Translatable::get_original($className,Session::get("{$id}_originalLangID"));
				if ($setID) $originalItem->ID = $id;
				else {
					$originalItem->ID = null;
					Translatable::creating_from(Session::get($id.'_originalLangID'));
				}
				return $originalItem;
			}
		}
		
		$newItem = new $className();

	    if( !$suffix ) {
			$sessionTag = "NewItems." . $parentID . "." . $className;
    		if(Session::get($sessionTag)) {
		    	$suffix = '-' . Session::get($sessionTag);
		    	Session::set($sessionTag, Session::get($sessionTag) + 1);
		    }
		    else
		    	Session::set($sessionTag, 1);

		    	$id = $id . $suffix;
	    }

		$newItem->Title = _t('CMSMain.NEW',"New ",PR_MEDIUM,'"New " followed by a className').$className;
		$newItem->URLSegment = "new-" . strtolower($className);
		$newItem->ClassName = $className;
		$newItem->ParentID = $parentID;

		// DataObject::fieldExists only checks the current class, not the hierarchy
		// This allows the CMS to set the correct sort value
		if($newItem->castingHelperPair('Sort')) {
			$newItem->Sort = DB::query("SELECT MAX(Sort)  FROM SiteTree WHERE ParentID = '" . Convert::raw2sql($parentID) . "'")->value() + 1;
		}

		if( Member::currentUser() )
			$newItem->OwnerID = Member::currentUser()->ID;

		if($setID) $newItem->ID = $id;

		# Some modules like subsites add extra fields that need to be set when the new item is created
		$this->extend('augmentNewSiteTreeItem', $newItem);
		
		return $newItem;
	}
Beispiel #6
0
 /**
  * Get a database record to be managed by the CMS
  */
 public function getRecord($id)
 {
     $treeClass = $this->stat('tree_class');
     if ($id && is_numeric($id)) {
         // First, try getting a record from the stage site
         $record = DataObject::get_one($treeClass, "`{$treeClass}`.ID = {$id}");
         // Then, try getting a record from the live site
         if (!$record) {
             // $record = Versioned::get_one_by_stage($treeClass, "Live", "`$treeClass`.ID = $id");
             Versioned::reading_stage('Live');
             singleton($treeClass)->flushCache();
             $record = DataObject::get_one($treeClass, "`{$treeClass}`.ID = {$id}");
             if ($record) {
                 Versioned::reading_stage(null);
             }
         }
         // Then, try getting a deleted record
         if (!$record) {
             $record = Versioned::get_latest_version($treeClass, $id);
         }
         // Don't open a page from a different locale
         if ($record && Translatable::is_enabled() && $record->Locale && $record->Locale != Translatable::get_current_locale()) {
             $record = null;
         }
         return $record;
     } else {
         if (substr($id, 0, 3) == 'new') {
             return $this->getNewItem($id);
         }
     }
 }
Beispiel #7
0
 function init()
 {
     Director::set_site_mode('cms');
     // set language
     $member = Member::currentUser();
     if (!empty($member->Locale)) {
         i18n::set_locale($member->Locale);
     }
     // set reading lang
     if (Translatable::is_enabled() && !Director::is_ajax()) {
         Translatable::choose_site_lang(array_keys(i18n::get_existing_content_languages('SiteTree')));
     }
     parent::init();
     // Allow customisation of the access check by a decorator
     if ($this->hasMethod('alternateAccessCheck')) {
         $isAllowed = $this->alternateAccessCheck();
         // Default security check for LeftAndMain sub-class permissions
     } else {
         $isAllowed = Permission::check("CMS_ACCESS_{$this->class}");
         if (!$isAllowed && $this->class == 'CMSMain') {
             // When access /admin/, we should try a redirect to another part of the admin rather than be locked out
             $menu = $this->MainMenu();
             if (($first = $menu->First()) && $first->Link) {
                 Director::redirect($first->Link);
             }
         }
     }
     // Don't continue if there's already been a redirection request.
     if (Director::redirected_to()) {
         return;
     }
     // Access failure!
     if (!$isAllowed) {
         $messageSet = array('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."));
         Security::permissionFailure($this, $messageSet);
         return;
     }
     Requirements::javascript('jsparty/prototype.js');
     Requirements::javascript('jsparty/behaviour.js');
     Requirements::javascript('jsparty/prototype_improvements.js');
     Requirements::javascript('jsparty/loader.js');
     Requirements::javascript('jsparty/hover.js');
     Requirements::javascript('jsparty/layout_helpers.js');
     Requirements::javascript(MCE_ROOT . 'tiny_mce_src.js');
     Requirements::javascript('cms/javascript/ImageEditor/Activator.js');
     Requirements::javascript('jsparty/tiny_mce_improvements.js');
     Requirements::javascript('jsparty/scriptaculous/effects.js');
     Requirements::javascript('jsparty/scriptaculous/dragdrop.js');
     Requirements::javascript('jsparty/scriptaculous/controls.js');
     Requirements::css('jsparty/greybox/greybox.css');
     Requirements::javascript('jsparty/greybox/AmiJS.js');
     Requirements::javascript('jsparty/greybox/greybox.js');
     Requirements::javascript('jsparty/tree/tree.js');
     Requirements::css('jsparty/tree/tree.css');
     Requirements::javascript('jsparty/tabstrip/tabstrip.js');
     Requirements::css('jsparty/tabstrip/tabstrip.css');
     Requirements::css('cms/css/TinyMCEImageEnhancement.css');
     Requirements::javascript('cms/javascript/TinyMCEImageEnhancement.js');
     Requirements::javascript('cms/javascript/LeftAndMain.js');
     Requirements::javascript('cms/javascript/LeftAndMain_left.js');
     Requirements::javascript('cms/javascript/LeftAndMain_right.js');
     Requirements::css('sapphire/css/Form.css');
     // Requirements::javascript('cms/javascript/MemberList.js');
     Requirements::javascript('cms/javascript/ForumAdmin.js');
     Requirements::javascript('cms/javascript/SideTabs.js');
     Requirements::javascript('cms/javascript/TaskList.js');
     Requirements::javascript('cms/javascript/CommentList.js');
     Requirements::javascript('cms/javascript/SideReports.js');
     Requirements::javascript('cms/javascript/LangSelector.js');
     Requirements::javascript('cms/javascript/TranslationTab.js');
     Requirements::javascript('sapphire/javascript/Validator.js');
     Requirements::javascript('sapphire/javascript/UniqueFields.js');
     Requirements::javascript('sapphire/javascript/RedirectorPage.js');
     Requirements::javascript('sapphire/javascript/DataReport.js');
     Requirements::javascript('sapphire/javascript/ToggleCompositeField.js');
     Requirements::css('sapphire/css/SubmittedFormReportField.css');
     Requirements::javascript('sapphire/javascript/FieldEditor.js');
     Requirements::css('sapphire/css/FieldEditor.css');
     Requirements::css('sapphire/css/TableListField.css');
     Requirements::css('sapphire/css/ComplexTableField.css');
     Requirements::javascript('sapphire/javascript/TableListField.js');
     Requirements::javascript('sapphire/javascript/TableField.js');
     Requirements::javascript('sapphire/javascript/ComplexTableField.js');
     Requirements::javascript('sapphire/javascript/RelationComplexTableField.js');
     Requirements::css('sapphire/css/TreeDropdownField.css');
     Requirements::css('sapphire/css/CheckboxSetField.css');
     Requirements::javascript('jsparty/calendar/calendar.js');
     Requirements::javascript('jsparty/calendar/lang/calendar-en.js');
     Requirements::javascript('jsparty/calendar/calendar-setup.js');
     Requirements::css('sapphire/css/CalendarDateField.css');
     Requirements::css('jsparty/calendar/calendar-win2k-1.css');
     Requirements::javascript('sapphire/javascript/DropdownTimeField.js');
     Requirements::css('sapphire/css/DropdownTimeField.css');
     Requirements::css('sapphire/css/PopupDateTimeField.css');
     Requirements::javascript('sapphire/javascript/SelectionGroup.js');
     Requirements::css('sapphire/css/SelectionGroup.css');
     Requirements::javascript('jsparty/SWFUpload/SWFUpload.js');
     Requirements::javascript('cms/javascript/Upload.js');
     Requirements::javascript('sapphire/javascript/HasManyFileField.js');
     Requirements::css('sapphire/css/HasManyFileField.css');
     Requirements::themedCSS('typography');
     // For Widgets
     Requirements::css('cms/css/WidgetAreaEditor.css');
     Requirements::javascript('cms/javascript/WidgetAreaEditor.js');
     // For Blog
     Requirements::javascript('blog/javascript/bbcodehelp.js');
     Requirements::javascript("sapphire/javascript/Security_login.js");
     $dummy = null;
     $this->extend('augmentInit', $dummy);
 }
Beispiel #8
0
 static function currentPage()
 {
     if (isset(Director::$urlParams['URLSegment'])) {
         $SQL_urlSegment = Convert::raw2sql(Director::$urlParams['URLSegment']);
         if (Translatable::is_enabled()) {
             return Translatable::get_one("SiteTree", "URLSegment = '{$SQL_urlSegment}'");
         } else {
             return DataObject::get_one("SiteTree", "URLSegment = '{$SQL_urlSegment}'");
         }
     } else {
         return Controller::curr();
     }
 }
Beispiel #9
0
	function init() {
		// set language
		$member = Member::currentUser();
		if(!empty($member->Locale)) {
			i18n::set_locale($member->Locale);
		}
		
		// set reading lang
		if(Translatable::is_enabled() && !Director::is_ajax()) {
			Translatable::choose_site_lang(array_keys(Translatable::get_existing_content_languages('SiteTree')));
		}
		
		parent::init();
	}