Esempio n. 1
0
	function testGenerateJSWritesPlugins() {
		$c = new HtmlEditorConfig();
		$c->enablePlugins(array('plugin1'));
		$c->enablePlugins(array('plugin2' => '/mypath/plugin2'));

		$this->assertContains('plugin1', $c->generateJS());
		$this->assertContains('tinymce.PluginManager.load("plugin2", "/mypath/plugin2");', $c->generateJS());
	}
 /**
  * Construct a sanitiser from a given HtmlEditorConfig
  *
  * Note that we build data structures from the current state of HtmlEditorConfig - later changes to
  * the passed instance won't cause this instance to update it's whitelist
  *
  * @param HtmlEditorConfig $config
  */
 public function __construct(HtmlEditorConfig $config)
 {
     $valid = $config->getOption('valid_elements');
     if ($valid) {
         $this->addValidElements($valid);
     }
     $valid = $config->getOption('extended_valid_elements');
     if ($valid) {
         $this->addValidElements($valid);
     }
 }
 function init()
 {
     HtmlEditorConfig::get('cms')->setOption('theme_advanced_blockformats', 'p,h1');
     HtmlEditorConfig::get('cms')->setButtonsForLine(1, 'undo, redo, separator, cut, copy, pastetext, separator, ssimage, sslink, unlink, separator, fullscreen, advcode, formatselect');
     HtmlEditorConfig::get('cms')->setButtonsForLine(2);
     HtmlEditorConfig::get('cms')->setButtonsForLine(3);
 }
 /**
  * Strips out not allowed tags, mainly this is to remove the kapost beacon script so it doesn't conflict with the cms
  * @param {string} $str String to be sanitized
  * @return {string} HTML to be used
  */
 public final function sanitizeHTML($str)
 {
     $htmlValue = Injector::inst()->create('HTMLValue', $str);
     $santiser = Injector::inst()->create('HtmlEditorSanitiser', HtmlEditorConfig::get_active());
     $santiser->sanitise($htmlValue);
     return $htmlValue->getContent();
 }
Esempio n. 5
0
 public function init()
 {
     parent::init();
     // Locale" attribute is either explicitly added by LeftAndMain Javascript logic,
     // or implied on a translated record (see {@link Translatable->updateCMSFields()}).
     // $Lang serves as a "context" which can be inspected by Translatable - hence it
     // has the same name as the database property on Translatable.
     if ($this->getRequest()->requestVar("Locale")) {
         $this->Locale = $this->getRequest()->requestVar("Locale");
     } elseif ($this->getRequest()->requestVar("locale")) {
         $this->Locale = $this->getRequest()->requestVar("locale");
     } else {
         $this->Locale = Translatable::default_locale();
     }
     Translatable::set_current_locale($this->Locale);
     // collect languages for TinyMCE spellchecker plugin.
     // see http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/spellchecker
     $langName = i18n::get_locale_name($this->Locale);
     HtmlEditorConfig::get('cms')->setOption('spellchecker_languages', "+{$langName}={$this->Locale}");
     Requirements::javascript(CMS_DIR . '/javascript/CMSMain.js');
     Requirements::javascript(CMS_DIR . '/javascript/CMSMain.Tree.js');
     Requirements::javascript(CMS_DIR . '/javascript/CMSMain.EditForm.js');
     Requirements::javascript(CMS_DIR . '/javascript/CMSMain.Translatable.js');
     Requirements::css(CMS_DIR . '/css/CMSMain.css');
     CMSBatchActionHandler::register('publish', 'CMSBatchAction_Publish');
     CMSBatchActionHandler::register('unpublish', 'CMSBatchAction_Unpublish');
     CMSBatchActionHandler::register('delete', 'CMSBatchAction_Delete');
     CMSBatchActionHandler::register('deletefromlive', 'CMSBatchAction_DeleteFromLive');
 }
 public function init()
 {
     // In LeftAndMain::init() the current theme is unset.
     // we need to restore the current theme here for make the dropdown of template list.
     $theme = SSViewer::current_theme();
     parent::init();
     if (isset($theme) && $theme) {
         SSViewer::set_theme($theme);
     }
     Requirements::javascript(MCE_ROOT . 'tiny_mce_src.js');
     Requirements::javascript(SAPPHIRE_DIR . '/javascript/tiny_mce_improvements.js');
     //TODO what is going on here? where did that hover.js go? can't find it.
     //TODO We need to reimplement a hover.js?
     Requirements::javascript(CMS_DIR . '/javascript/hover.js');
     Requirements::javascript(THIRDPARTY_DIR . '/scriptaculous/controls.js');
     Requirements::javascript(CMS_DIR . '/javascript/LeftAndMain_left.js');
     Requirements::javascript(CMS_DIR . '/javascript/LeftAndMain_right.js');
     Requirements::javascript(CMS_DIR . '/javascript/CMSMain_left.js');
     Requirements::javascript(CMS_DIR . '/javascript/SecurityAdmin.js');
     Requirements::javascript(NEWSLETTER_DIR . '/javascript/NewsletterAdmin_left.js');
     Requirements::javascript(NEWSLETTER_DIR . '/javascript/NewsletterAdmin_right.js');
     Requirements::javascript(NEWSLETTER_DIR . '/javascript/ProgressBar.js');
     // We don't want this showing up in every ajax-response, it should always be present in a CMS-environment
     if (!Director::is_ajax()) {
         Requirements::javascript(MCE_ROOT . 'tiny_mce_src.js');
         HtmlEditorConfig::get('cms')->setOption('ContentCSS', project() . '/css/editor.css');
         HtmlEditorConfig::get('cms')->setOption('Lang', i18n::get_tinymce_lang());
     }
     // Always block the HtmlEditorField.js otherwise it will be sent with an ajax request
     Requirements::block(SAPPHIRE_DIR . '/javascript/HtmlEditorField.js');
     Requirements::css(NEWSLETTER_DIR . '/css/NewsletterAdmin.css');
 }
 function init()
 {
     $req = $this->owner->getRequest();
     // Ignore being called on LeftAndMain base class,
     // which is the case when requests are first routed through AdminRootController
     // as an intermediary rather than the endpoint controller
     if (!$this->owner->stat('tree_class')) {
         return;
     }
     // Locale" attribute is either explicitly added by LeftAndMain Javascript logic,
     // or implied on a translated record (see {@link Translatable->updateCMSFields()}).
     // $Lang serves as a "context" which can be inspected by Translatable - hence it
     // has the same name as the database property on Translatable.
     $id = $req->param('ID');
     if ($req->requestVar("Locale")) {
         $this->owner->Locale = $req->requestVar("Locale");
     } else {
         if ($id && is_numeric($id)) {
             $record = DataObject::get_by_id($this->owner->stat('tree_class'), $id);
             if ($record && $record->Locale) {
                 $this->owner->Locale = $record->Locale;
             }
         } else {
             $this->owner->Locale = Translatable::default_locale();
             if ($this->owner->class == 'CMSPagesController') {
                 // the CMSPagesController always needs to have the locale set,
                 // otherwise page editing will cause an extra
                 // ajax request which looks weird due to multiple "loading"-flashes
                 $getVars = $req->getVars();
                 if (isset($getVars['url'])) {
                     unset($getVars['url']);
                 }
                 return $this->owner->redirect(Controller::join_links($this->owner->Link(), $req->param('Action'), $req->param('ID'), $req->param('OtherID'), ($query = http_build_query($getVars)) ? "?{$query}" : null));
             }
         }
     }
     Translatable::set_current_locale($this->owner->Locale);
     // If a locale is set, it needs to match to the current record
     $requestLocale = $req->requestVar("Locale");
     $page = $this->owner->currentPage();
     if ($req->httpMethod() == 'GET' && $requestLocale && $page && $page->hasExtension('Translatable') && $page->Locale != $requestLocale && $req->latestParam('Action') != 'EditorToolbar') {
         $transPage = $page->getTranslation($requestLocale);
         if ($transPage) {
             Translatable::set_current_locale($transPage->Locale);
             return $this->owner->redirect(Controller::join_links($this->owner->Link('show'), $transPage->ID));
         } else {
             if ($this->owner->class != 'CMSPagesController') {
                 // If the record is not translated, redirect to pages overview
                 return $this->owner->redirect(Controller::join_links(singleton('CMSPagesController')->Link(), '?Locale=' . $requestLocale));
             }
         }
     }
     // collect languages for TinyMCE spellchecker plugin.
     // see http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/spellchecker
     $langName = i18n::get_locale_name($this->owner->Locale);
     HtmlEditorConfig::get('cms')->setOption('spellchecker_languages', "+{$langName}={$this->owner->Locale}");
     Requirements::javascript('translatable/javascript/CMSMain.Translatable.js');
     Requirements::css('translatable/css/CMSMain.Translatable.css');
 }
    /**
     * This basically merges HtmlEditorField::include_js() and HTMLEditorConfig::generateJS() to output all
     * configuration sets to a customTinyMceConfigs javascript array.
     * This is output in addition to the standard ssTinyMceConfig because a) we can't stop the default output
     * with extensions; and b) the default setting is still used for any HTMLEditorField that doesn't specify
     * it's own config.
     *
     * Calls Requirements::javascript() to load the scripts.
     */
    public static function include_js()
    {
        require_once 'tinymce/tiny_mce_gzip.php';
        $availableConfigs = HtmlEditorConfig::get_available_configs_map();
        $pluginsForTag = array();
        $languages = array();
        //$allConfigs = array();
        $settingsJS = '';
        $externalPluginsForJS = array();
        $activeConfig = HtmlEditorConfig::get_active();
        foreach ($availableConfigs as $identifier => $friendlyName) {
            $configObj = CustomHtmlEditorConfig::get($identifier);
            $internalPluginsForJS = array();
            $configObj->getConfig()->setOption('language', i18n::get_tinymce_lang());
            if (!$configObj->getConfig()->getOption('content_css')) {
                $configObj->getConfig()->setOption('content_css', $activeConfig->getOption('content_css'));
            }
            $settings = $configObj->getSettings();
            foreach ($configObj->getPlugins() as $plugin => $path) {
                if (!$path) {
                    $pluginsForTag[$plugin] = $plugin;
                    $internalPluginsForJS[$plugin] = $plugin;
                } else {
                    $internalPluginsForJS[$plugin] = '-' . $plugin;
                    $externalPluginsForJS[$plugin] = sprintf('tinymce.PluginManager.load("%s", "%s");' . "\n", $plugin, $path);
                }
            }
            $language = $configObj->getConfig()->getOption('language');
            if ($language) {
                $languages[$language] = $language;
            }
            $settings['plugins'] = implode(',', $internalPluginsForJS);
            $buttons = $configObj->getButtons();
            foreach ($buttons as $i => $buttons) {
                $settings['theme_advanced_buttons' . $i] = implode(',', $buttons);
            }
            $settingsJS .= "customTinyMceConfigs['" . $identifier . "'] = " . Convert::raw2json($settings) . ";\n";
        }
        if (Config::inst()->get('HtmlEditorField', 'use_gzip')) {
            $tag = TinyMCE_Compressor::renderTag(array('url' => THIRDPARTY_DIR . '/tinymce/tiny_mce_gzip.php', 'plugins' => implode(',', $pluginsForTag), 'themes' => 'advanced', 'languages' => implode(',', $languages)), true);
            preg_match('/src="([^"]*)"/', $tag, $matches);
            Requirements::javascript($matches[1]);
        } else {
            Requirements::javascript(MCE_ROOT . 'tiny_mce_src.js');
        }
        $externalPluginsJS = implode('', $externalPluginsForJS);
        $script = <<<JS
\t\t\tif((typeof tinyMCE != 'undefined')) {
\t\t\t\t{$externalPluginsJS}

\t\t\t\tif (typeof customTinyMceConfigs == 'undefined') {
\t\t\t\t\tvar customTinyMceConfigs = [];
\t\t\t\t}
\t\t\t\t{$settingsJS}
\t\t\t}

JS;
        Requirements::customScript($script, 'htmlEditorConfigs');
    }
 /**
  * Returns the {@see HtmlEditorConfig} instance to use for sanitisation
  *
  * @return HtmlEditorConfig
  */
 protected function getEditorConfig()
 {
     $editorConfig = $this->config()->editor_config;
     if ($editorConfig) {
         return HtmlEditorConfig::get($editorConfig);
     }
     return HtmlEditorConfig::get_active();
 }
 public function __construct()
 {
     parent::__construct();
     // This may get called before the schema is created.
     if (!DB::getConn()->isSchemaUpdating()) {
         HtmlEditorConfig::get('cms')->setOption('viewtemplate', ViewTemplate::get()->map('Title')->toArray());
     }
 }
 public static function include_js($configName)
 {
     Requirements::javascript(MCE_ROOT . 'tiny_mce_src.js');
     $config = HtmlEditorConfig::get($configName);
     $config->setOption('mode', 'none');
     $config->setOption('editor_selector', "htmleditor{$configName}");
     Requirements::customScript("\n\t\tBehaviour.register({\n\t\t'textarea.htmleditor{$configName}' : {\n\t\tinitialize : function() {\n\t\tif(typeof tinyMCE != 'undefined'){\n\t\tvar oldsettings = tinyMCE.settings;\n\t\t" . $config->generateJS() . "\n\t\ttinyMCE.execCommand('mceAddControl', true, this.id);\n\t\ttinyMCE.settings = oldsettings;\n\t\tthis.isChanged = function() {\n\t\treturn tinyMCE.getInstanceById(this.id).isDirty();\n\t\t}\n\t\tthis.resetChanged = function() {\n\t\tinst = tinyMCE.getInstanceById(this.id);\n\t\tif (inst) inst.startContent = tinymce.trim(inst.getContent({format : 'raw', no_events : 1}));\n\t\t}\n\t\t}\n\t\t}\n\t\t}\n\t\t})\n\t\t", "htmlEditorConfig-{$configName}");
 }
 public function testRequireJSIncludesAllConfigs()
 {
     $a = HtmlEditorConfig::get('configA');
     $c = HtmlEditorConfig::get('configB');
     $aAttributes = $a->getAttributes();
     $cAttributes = $c->getAttributes();
     $this->assertNotEmpty($aAttributes['data-config']);
     $this->assertNotEmpty($cAttributes['data-config']);
 }
 public function testRequireJSIncludesAllConfigs()
 {
     $c = HtmlEditorConfig::get('configA');
     $c = HtmlEditorConfig::get('configB');
     HtmlEditorConfig::require_js();
     $js = Requirements::get_custom_scripts();
     $this->assertContains('"configA":{', $js);
     $this->assertContains('"configB":{', $js);
 }
Esempio n. 14
0
	public function init() {
	    parent::init();
	    // Remove all the junk that will break ModelAdmin
	    $config = HtmlEditorConfig::get_active();
	    $buttons = array('undo','redo','separator','cut','copy','paste','pastetext','pasteword','spellchecker','separator','sslink','unlink','anchor','separator','advcode','search','replace','selectall','visualaid','separator');
	    $config->setButtonsForLine(2,$buttons);
	    Requirements::javascript('remodeladmin/javascript/remodeladmin.js');
	    Requirements::css('remodeladmin/css/remodeladmin.css');

	}
 function alternateAccessCheck()
 {
     // html display simplification
     $lines = array('pastetext', 'ssmedia', 'separator', 'bold', 'italic', 'underline', 'strikethrough', 'hr', 'separator', 'styleselect', 'formatselect', 'separator', 'bullist', 'numlist', 'blockquote', 'sslink', 'unlink', 'anchor', 'separator', 'code');
     $config = HtmlEditorConfig::get('cms');
     $config->setButtonsForLine(1, $lines);
     $config->setButtonsForLine(2, null);
     $config->setButtonsForLine(3, null);
     HtmlEditorConfig::get('cms')->setOption('theme_advanced_blockformats', 'p,h1,h2,h3,h4');
 }
Esempio n. 16
0
 public function init()
 {
     parent::init();
     Requirements::css(CMS_DIR . '/css/ReportAdmin.css');
     // Set custom options for TinyMCE specific to ReportAdmin
     HtmlEditorConfig::get('cms')->setOption('ContentCSS', project() . '/css/editor.css');
     HtmlEditorConfig::get('cms')->setOption('Lang', i18n::get_tinymce_lang());
     // Always block the HtmlEditorField.js otherwise it will be sent with an ajax request
     Requirements::block(SAPPHIRE_DIR . '/javascript/HtmlEditorField.js');
 }
 /**
  * Implementation directly borrowed from HtmlEditorField
  * without the blocking or useless code.
  */
 public function saveInto(DataObjectInterface $record)
 {
     $htmlValue = Injector::inst()->create('HTMLValue', $this->value);
     // Sanitise if requested
     if ($this->config()->sanitise_server_side) {
         $santiser = Injector::inst()->create('HtmlEditorSanitiser', HtmlEditorConfig::get_active());
         $santiser->sanitise($htmlValue);
     }
     $this->extend('processHTML', $htmlValue);
     $record->{$this->name} = $htmlValue->getContent();
 }
 public function testSanitisation()
 {
     $tests = array(array('p,strong', '<p>Leave Alone</p><div>Strip parent<strong>But keep children</strong> in order</div>', '<p>Leave Alone</p>Strip parent<strong>But keep children</strong> in order', 'Non-whitelisted elements are stripped, but children are kept'), array('p,strong', '<div>A <strong>B <div>Nested elements are still filtered</div> C</strong> D</div>', 'A <strong>B Nested elements are still filtered C</strong> D', 'Non-whitelisted elements are stripped even when children of non-whitelisted elements'), array('p', '<p>Keep</p><script>Strip <strong>including children</strong></script>', '<p>Keep</p>', 'Non-whitelisted script elements are totally stripped, including any children'), array('p[id]', '<p id="keep" bad="strip">Test</p>', '<p id="keep">Test</p>', 'Non-whitelisted attributes are stripped'), array('p[default1=default1|default2=default2|force1:force1|force2:force2]', '<p default1="specific1" force1="specific1">Test</p>', '<p default1="specific1" force1="force1" default2="default2" force2="force2">Test</p>', 'Default attributes are set when not present in input, forced attributes are always set'));
     $config = HtmlEditorConfig::get('htmleditorsanitisertest');
     foreach ($tests as $test) {
         list($validElements, $input, $output, $desc) = $test;
         $config->setOptions(array('valid_elements' => $validElements));
         $sanitiser = new HtmlEditorSanitiser($config);
         $htmlValue = Injector::inst()->create('HTMLValue', $input);
         $sanitiser->sanitise($htmlValue);
         $this->assertEquals($output, $htmlValue->getContent(), $desc);
     }
 }
 public function init()
 {
     parent::init();
     //set the report we are currently viewing from the URL
     $this->reportClass = isset($this->urlParams['ReportClass']) && $this->urlParams['ReportClass'] !== 'index' ? $this->urlParams['ReportClass'] : null;
     $allReports = SS_Report::get_reports();
     $this->reportObject = isset($allReports[$this->reportClass]) ? $allReports[$this->reportClass] : null;
     // Set custom options for TinyMCE specific to ReportAdmin
     HtmlEditorConfig::get('cms')->setOption('content_css', project() . '/css/editor.css');
     HtmlEditorConfig::get('cms')->setOption('Lang', i18n::get_tinymce_lang());
     // Always block the HtmlEditorField.js otherwise it will be sent with an ajax request
     Requirements::block(FRAMEWORK_DIR . '/javascript/HtmlEditorField.js');
     Requirements::javascript(REPORTS_DIR . '/javascript/ReportAdmin.js');
 }
Esempio n. 20
0
 /**
  * Caution: Only call on instances, not through a singleton.
  *
  * @return FieldSet
  */
 public function getCMSFields()
 {
     $fields = new FieldSet(new TabSet("Root", new Tab(_t('SecurityAdmin.MEMBERS', 'Members'), new TextField("Title", $this->fieldLabel('Title')), $memberList = new MemberTableField($this, "Members", $this, null, false)), new Tab(_t('SecurityAdmin.PERMISSIONS', 'Permissions'), new LiteralField("", "<p>" . _t('SecurityAdmin.ADVANCEDONLY', "This section is for advanced users only.\n\t\t\t\t\t\t\tSee <a href=\"http://doc.silverstripe.com/doku.php?id=permissions:codes\" target=\"_blank\">this page</a>\n\t\t\t\t\t\t\tfor more information.") . "</p>"), new DropdownField('HtmlEditorConfig', 'HTML Editor Configuration', HtmlEditorConfig::get_available_configs_map()), new TableField("Permissions", "Permission", array("Code" => _t('SecurityAdmin.CODE', 'Code'), "Arg" => _t('SecurityAdmin.OPTIONALID', 'Optional ID')), array("Code" => "PermissionDropdownField", "Arg" => "TextField"), "GroupID", $this->ID)), new Tab(_t('Security.IPADDRESSES', 'IP Addresses'), new LiteralField("", _t('SecurityAdmin.IPADDRESSESHELP', "<p>You can restrict this group to a particular \n\t\t\t\t\t\tIP address range (one range per line). <br />Ranges can be in any of the following forms: <br />\n\t\t\t\t\t\t203.96.152.12<br />\n\t\t\t\t\t\t203.96.152/24<br />\n\t\t\t\t\t\t203.96/16<br />\n\t\t\t\t\t\t203/8<br /><br />If you enter one or more IP address ranges in this box, then members will only get\n\t\t\t\t\t\tthe rights of being in this group if they log on from one of the valid IP addresses.  It won't prevent\n\t\t\t\t\t\tpeople from logging in.  This is because the same user might have to log in to access parts of the\n\t\t\t\t\t\tsystem without IP address restrictions.")), new TextareaField("IPRestrictions", "IP Ranges", 10))));
     if (!Permission::check('EDIT_PERMISSIONS')) {
         $fields->removeFieldFromTab('Root', 'Permissions');
         $fields->removeFieldFromTab('Root', 'IP Addresses');
     }
     $memberList->setController($this);
     $memberList->setPermissions(array('show', 'edit', 'delete', 'export', 'add'));
     $memberList->setParentClass('Group');
     $memberList->setPopupCaption(_t('SecurityAdmin.VIEWUSER', 'View User'));
     $fields->push($idField = new HiddenField("ID"));
     $this->extend('updateCMSFields', $fields);
     return $fields;
 }
	function getCMSFields_forPopup() {
		$fields = new FieldSet();
		
	//	$tabset = new HorizontalTabSet('Root');
	//	$tabset->push(new Tab('Main'));
	//	$tabset->push(new Tab('Formats'));
	//	$fields->push($tabset);
		
		$fields->push(new TextField('Title', 'Video Title'));

		
		$fields->push($blurbField = new SimpleTinyMCEField('Blurb'));
		$config = HtmlEditorConfig::get_active();
		$contentCSS = $config->getOption('content_css');
		// hack!
		$contentCSS = '/'.str_replace(', ', ', /', $contentCSS);
		$blurbField->setContentCSS($contentCSS);
		$blurbField->setExtraOptions("body_class : 'typography'");
		
		$fields->push(new ImageField('Poster', 'Poster Image'));
		
		
		
		
		$videoManager = new FileDataobjectManager(
			$this, // Controller
			'VideoFormats', // Source name
			'MediaElementVideoFormat', // Source class
			'Attachment',
			array(
				'Type' => 'Type',
				'LinkifiedLink' => 'Link'
			), // Headings 
			'getCMSFields_forPopup' // Detail fields (function name or FieldSet object)
			// Filter clause
			// Sort clause
			// Join clause
		);
		$videoManager->setPluralTitle('Formats');
		$videoManager->setAddTitle('Format');
	//	$videoManager->setWideMode(true);
		$videoManager->setPopupWidth(600);
		$videoManager->setDefaultView('list');
		$fields->push($videoManager);
//		$fields->push($videoManager);
		
		return $fields;
	}
 /**
  * init (called from LeftAndMain extension hook)
  **/
 public function init()
 {
     // set the htmleditor "content_css" based on the active site
     $htmlEditorConfig = HtmlEditorConfig::get_active();
     $site = Multisites::inst()->getActiveSite();
     if ($site && ($theme = $site->getSiteTheme())) {
         $cssFile = THEMES_DIR . "/{$theme}/css/editor.css";
         if (file_exists(BASE_PATH . '/' . $cssFile)) {
             $htmlEditorConfig->setOption('content_css', $cssFile);
             if ($this->owner->getRequest()->isAjax() && $this->owner->class == 'CMSPageEditController') {
                 // Add editor css path to header so javascript can update ssTinyMceConfig.content_css
                 $this->owner->getResponse()->addHeader('X-HTMLEditor_content_css', $cssFile);
             }
         }
     }
 }
 public function preRequest(\SS_HTTPRequest $request, \Session $session, \DataModel $model)
 {
     // Check languages to set
     $languages = array();
     foreach (SpellController::get_locales() as $locale) {
         $languages[] = i18n::get_locale_name($locale) . '=' . $locale;
     }
     // Set settings
     $editor = Config::inst()->get(__CLASS__, 'editor');
     HtmlEditorConfig::get($editor)->enablePlugins('spellchecker');
     HtmlEditorConfig::get($editor)->addButtonsToLine(2, 'spellchecker');
     $token = SecurityToken::inst();
     HtmlEditorConfig::get($editor)->setOption('spellchecker_rpc_url', $token->addToUrl('spellcheck/'));
     HtmlEditorConfig::get($editor)->setOption('browser_spellcheck', false);
     HtmlEditorConfig::get($editor)->setOption('spellchecker_languages', '+' . implode(', ', $languages));
     return true;
 }
 function init()
 {
     // Locale" attribute is either explicitly added by LeftAndMain Javascript logic,
     // or implied on a translated record (see {@link Translatable->updateCMSFields()}).
     // $Lang serves as a "context" which can be inspected by Translatable - hence it
     // has the same name as the database property on Translatable.
     $req = $this->owner->getRequest();
     $id = $req->param('ID');
     if ($req->requestVar("Locale")) {
         $this->owner->Locale = $req->requestVar("Locale");
     } elseif ($req->requestVar("locale")) {
         $this->owner->Locale = $req->requestVar("locale");
     } else {
         if ($id && is_numeric($id)) {
             $record = DataObject::get_by_id($this->owner->stat('tree_class'), $id);
             if ($record && $record->Locale) {
                 $this->owner->Locale = $record->Locale;
             }
         } else {
             $this->owner->Locale = Translatable::default_locale();
         }
     }
     Translatable::set_current_locale($this->owner->Locale);
     // if a locale is set, it needs to match to the current record
     $requestLocale = $req->requestVar("Locale") ? $req->requestVar("Locale") : $req->requestVar("locale");
     $page = $this->owner->currentPage();
     if ($requestLocale && $page && $page->Locale != $requestLocale) {
         $transPage = $page->getTranslation($requestLocale);
         if ($transPage) {
             Translatable::set_current_locale($transPage->Locale);
             return $this->owner->redirect(Controller::join_links($this->owner->Link('show'), $transPage->ID));
         } else {
             // If the record is not translated, redirect to pages overview
             return $this->owner->redirect(Controller::join_links(singleton('CMSPagesController')->Link(), '?locale=' . $requestLocale));
         }
     }
     // collect languages for TinyMCE spellchecker plugin.
     // see http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/spellchecker
     $langName = i18n::get_locale_name($this->owner->Locale);
     HtmlEditorConfig::get('cms')->setOption('spellchecker_languages', "+{$langName}={$this->owner->Locale}");
     Requirements::javascript('translatable/javascript/CMSMain.Translatable.js');
     Requirements::css('translatable/css/CMSMain.Translatable.css');
 }
Esempio n. 25
0
 /**
  * Includes the JavaScript neccesary for this field to work using the {@link Requirements} system.
  */
 public static function include_js()
 {
     require_once 'tinymce/tiny_mce_gzip.php';
     $configObj = HtmlEditorConfig::get_active();
     if (self::$use_gzip) {
         $internalPlugins = array();
         foreach ($configObj->getPlugins() as $plugin => $path) {
             if (!$path) {
                 $internalPlugins[] = $plugin;
             }
         }
         $tag = TinyMCE_Compressor::renderTag(array('url' => THIRDPARTY_DIR . '/tinymce/tiny_mce_gzip.php', 'plugins' => implode(',', $internalPlugins), 'themes' => 'advanced', 'languages' => $configObj->getOption('language')), true);
         preg_match('/src="([^"]*)"/', $tag, $matches);
         Requirements::javascript($matches[1]);
     } else {
         Requirements::javascript(MCE_ROOT . 'tiny_mce_src.js');
     }
     Requirements::customScript($configObj->generateJS(), 'htmlEditorConfig');
 }
Esempio n. 26
0
 /**
  * Caution: Only call on instances, not through a singleton.
  *
  * @return FieldSet
  */
 public function getCMSFields()
 {
     $fields = new FieldSet(new TabSet("Root", new Tab(_t('SecurityAdmin.MEMBERS', 'Members'), new TextField("Title", $this->fieldLabel('Title')), $memberList = new MemberTableField($this, "Members", $this, null, false)), $permissionsTab = new Tab(_t('SecurityAdmin.PERMISSIONS', 'Permissions'), new PermissionCheckboxSetField('Permissions', false, 'Permission', 'GroupID', $this)), new Tab(_t('Security.IPADDRESSES', 'IP Addresses'), new LiteralField("", _t('SecurityAdmin.IPADDRESSESHELP', "<p>You can restrict this group to a particular \n\t\t\t\t\t\tIP address range (one range per line). <br />Ranges can be in any of the following forms: <br />\n\t\t\t\t\t\t203.96.152.12<br />\n\t\t\t\t\t\t203.96.152/24<br />\n\t\t\t\t\t\t203.96/16<br />\n\t\t\t\t\t\t203/8<br /><br />If you enter one or more IP address ranges in this box, then members will only get\n\t\t\t\t\t\tthe rights of being in this group if they log on from one of the valid IP addresses.  It won't prevent\n\t\t\t\t\t\tpeople from logging in.  This is because the same user might have to log in to access parts of the\n\t\t\t\t\t\tsystem without IP address restrictions.")), new TextareaField("IPRestrictions", "IP Ranges", 10))));
     // Only add a dropdown for HTML editor configurations if more than one is available.
     // Otherwise Member->getHtmlEditorConfigForCMS() will default to the 'cms' configuration.
     $editorConfigMap = HtmlEditorConfig::get_available_configs_map();
     if (count($editorConfigMap) > 1) {
         $fields->addFieldToTab('Root.Permissions', new DropdownField('HtmlEditorConfig', 'HTML Editor Configuration', $editorConfigMap), 'Permissions');
     }
     if (!Permission::check('EDIT_PERMISSIONS')) {
         $fields->removeFieldFromTab('Root', 'Permissions');
         $fields->removeFieldFromTab('Root', 'IP Addresses');
     }
     // Only show the "Roles" tab if permissions are granted to edit them,
     // and at least one role exists
     if (Permission::check('APPLY_ROLES') && DataObject::get('PermissionRole')) {
         $fields->findOrMakeTab('Root.Roles', _t('SecurityAdmin.ROLES', 'Roles'));
         $fields->addFieldToTab('Root.Roles', new LiteralField("", "<p>" . _t('SecurityAdmin.ROLESDESCRIPTION', "This section allows you to add roles to this group. Roles are logical groupings of permissions, which can be editied in the Roles tab") . "</p>"));
         // Add roles (and disable all checkboxes for inherited roles)
         $allRoles = Permission::check('ADMIN') ? DataObject::get('PermissionRole') : DataObject::get('PermissionRole', 'OnlyAdminCanApply = 0');
         $groupRoles = $this->Roles();
         $inheritedRoles = new DataObjectSet();
         $ancestors = $this->getAncestors();
         foreach ($ancestors as $ancestor) {
             $ancestorRoles = $ancestor->Roles();
             if ($ancestorRoles) {
                 $inheritedRoles->merge($ancestorRoles);
             }
         }
         $fields->findOrMakeTab('Root.Roles', 'Root.' . _t('SecurityAdmin.ROLES', 'Roles'));
         $fields->addFieldToTab('Root.Roles', $rolesField = new CheckboxSetField('Roles', 'Roles', $allRoles));
         $rolesField->setDefaultItems($inheritedRoles->column('ID'));
         $rolesField->setDisabledItems($inheritedRoles->column('ID'));
     }
     $memberList->setController($this);
     $memberList->setPermissions(array('edit', 'delete', 'export', 'add', 'inlineadd'));
     $memberList->setParentClass('Group');
     $memberList->setPopupCaption(_t('SecurityAdmin.VIEWUSER', 'View User'));
     $memberList->setRelationAutoSetting(false);
     $fields->push($idField = new HiddenField("ID"));
     $this->extend('updateCMSFields', $fields);
     return $fields;
 }
 public function saveInto(DataObjectInterface $record)
 {
     if ($record->hasField($this->name) && $record->escapeTypeForField($this->name) != 'xml') {
         throw new Exception('HtmlEditorField->saveInto(): This field should save into a HTMLText or HTMLVarchar field.');
     }
     $htmlValue = Injector::inst()->create('HTMLValue', $this->value);
     // Sanitise if requested
     if ($this->config()->sanitise_server_side) {
         $santiser = Injector::inst()->create('HtmlEditorSanitiser', HtmlEditorConfig::get_active());
         $santiser->sanitise($htmlValue);
     }
     // Resample images and add default attributes
     if ($images = $htmlValue->getElementsByTagName('img')) {
         foreach ($images as $img) {
             // strip any ?r=n data from the src attribute
             $img->setAttribute('src', preg_replace('/([^\\?]*)\\?r=[0-9]+$/i', '$1', $img->getAttribute('src')));
             // Resample the images if the width & height have changed.
             if ($image = File::find(urldecode(Director::makeRelative($img->getAttribute('src'))))) {
                 $width = (int) $img->getAttribute('width');
                 $height = (int) $img->getAttribute('height');
                 if ($width && $height && ($width != $image->getWidth() || $height != $image->getHeight())) {
                     //Make sure that the resized image actually returns an image:
                     $resized = $image->ResizedImage($width, $height);
                     if ($resized) {
                         $img->setAttribute('src', $resized->getRelativePath());
                     }
                 }
             }
             // Add default empty title & alt attributes.
             if (!$img->getAttribute('alt')) {
                 $img->setAttribute('alt', '');
             }
             if (!$img->getAttribute('title')) {
                 $img->setAttribute('title', '');
             }
         }
     }
     // Store into record
     $record->{$this->name} = $htmlValue->getContent();
 }
 private static function include_js_internal($configName)
 {
     require_once 'tinymce/tiny_mce_gzip.php';
     $configObj = HtmlEditorConfig::get_active();
     if (Config::inst()->get('HtmlEditorField', 'use_gzip')) {
         $internalPlugins = array();
         foreach ($configObj->getPlugins() as $plugin => $path) {
             if (!$path) {
                 $internalPlugins[] = $plugin;
             }
         }
         $tag = TinyMCE_Compressor::renderTag(array('url' => THIRDPARTY_DIR . '/tinymce/tiny_mce_gzip.php', 'plugins' => implode(',', $internalPlugins), 'themes' => 'advanced', 'languages' => $configObj->getOption('language')), true);
         preg_match('/src="([^"]*)"/', $tag, $matches);
         Requirements::javascript(html_entity_decode($matches[1]));
     } else {
         Requirements::javascript(MCE_ROOT . 'tiny_mce_src.js');
     }
     $config = HtmlEditorConfig::get($configName);
     $config->setOption('mode', 'none');
     $config->setOption('editor_selector', "htmleditor{$configName}");
     Requirements::customScript("\n\t\t\t" . str_replace("ssTinyMceConfig", "ssTinyMceConfig" . $configName, $config->generateJS()) . "\n\t\t\t", "htmlEditorConfig-{$configName}");
 }
 public function __construct($controller, $name)
 {
     parent::__construct();
     Requirements::javascript(FRAMEWORK_DIR . "/thirdparty/jquery/jquery.js");
     Requirements::javascript(THIRDPARTY_DIR . '/jquery-ui/jquery-ui.js');
     Requirements::javascript(THIRDPARTY_DIR . '/jquery-entwine/dist/jquery.entwine-dist.js');
     Requirements::javascript(FRAMEWORK_ADMIN_DIR . '/javascript/ssui.core.js');
     HtmlEditorConfig::require_js();
     Requirements::javascript(FRAMEWORK_DIR . "/javascript/HtmlEditorField.js");
     Requirements::css(THIRDPARTY_DIR . '/jquery-ui-themes/smoothness/jquery-ui.css');
     $this->controller = $controller;
     $this->name = $name;
 }
Esempio n. 30
0
 /**
  * Get the HtmlEditorConfig for this user to be used in the CMS.
  * This is set by the group. If multiple configurations are set,
  * the one with the highest priority wins.
  * 
  * @return string
  */
 function getHtmlEditorConfigForCMS()
 {
     $currentName = '';
     $currentPriority = 0;
     foreach ($this->Groups() as $group) {
         $configName = $group->HtmlEditorConfig;
         if ($configName) {
             $config = HtmlEditorConfig::get($group->HtmlEditorConfig);
             if ($config && $config->getOption('priority') > $currentPriority) {
                 $currentName = $configName;
             }
         }
     }
     // If can't find a suitable editor, just default to cms
     return $currentName ? $currentName : 'cms';
 }