Show
Ignore:
Timestamp:
01/24/2007 09:08:32 PM (23 months ago)
Author:
wei
Message:

upgrade tinyMCE to 2.0.9 to fix #482 and #459

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • branches/3.0/framework/Web/UI/WebControls/THtmlArea.php

    r1397 r1652  
    9999                        'is' => 'is', 
    100100                        'it' => 'it', 
    101                         'ja' => 'ja', 
     101                        'ja' => 'ja_utf-8', 
    102102                        'ko' => 'ko', 
    103103                        'nb' => 'nb', 
    104104                        'nl' => 'nl', 
     105                        'nn' => 'nn', 
    105106                        'pl' => 'pl', 
    106107                        'pt' => 'pt', 
    107108                        'pt_BR' => 'pt_br', 
    108                         'ru' => 'ru_UTF-8', 
     109                        'ro' => 'ro', 
     110                        'ru' => 'ru', 
    109111                        'si' => 'si', 
    110112                        'sk' => 'sk', 
    111                         'sv' => 'sv', 
     113                        'sq' => 'sq', 
     114                        'sr' => 'sr', 
     115                        'sv' => 'sv_utf8', 
    112116                        'th' => 'th', 
    113117                        'tr' => 'tr', 
     
    120124 
    121125        /** 
     126         * @var array list of default plugins to load, override using getAvailablePlugins(); 
     127         */ 
     128        private static $_plugins = array( 
     129                'style', 
     130                'layer', 
     131                'table', 
     132                'save', 
     133                'advhr', 
     134//              'advimage', 
     135//              'advlink', 
     136                'emotions', 
     137                'iespell', 
     138                'insertdatetime', 
     139                'preview', 
     140                'media', 
     141                'searchreplace', 
     142                'print', 
     143                'contextmenu', 
     144                'paste', 
     145                'directionality', 
     146                'fullscreen', 
     147                'noneditable', 
     148                'visualchars', 
     149                'nonbreaking', 
     150                'xhtmlxtras' 
     151        ); 
     152 
     153        /** 
     154         * @var array default themes to load 
     155         */ 
     156        private static $_themes = array( 
     157                'simple', 
     158                'advanced' 
     159        ); 
     160 
     161        /** 
    122162         * Constructor. 
    123163         * Sets default width and height. 
     
    125165        public function __construct() 
    126166        { 
    127                 $this->setWidth('450px'); 
     167                $this->setWidth('470px'); 
    128168                $this->setHeight('250px'); 
    129169        } 
     
    210250        { 
    211251                $this->setViewState('Options', $value, ''); 
     252        } 
     253 
     254        /** 
     255         * @param string path to custom plugins to be copied. 
     256         */ 
     257        public function setCustomPluginPath($value) 
     258        { 
     259                $this->setViewState('CustomPluginPath', $value); 
     260        } 
     261 
     262        /** 
     263         * @return string path to custom plugins to be copied. 
     264         */ 
     265        public function getCustomPluginPath() 
     266        { 
     267                return $this->getViewState('CustomPluginPath'); 
     268        } 
     269 
     270        public function onPreRender($param) 
     271        { 
     272                $this->preLoadCompressedScript(); 
    212273        } 
    213274 
     
    229290 
    230291        /** 
    231          * Registers the editor javascript file and code to initialize the editor. 
    232          */ 
    233         protected function registerEditorClientScript($writer) 
     292         * Returns a list of plugins to be loaded. 
     293         * Override this method to customize. 
     294         * @return array list of plugins to be loaded 
     295         */ 
     296        public function getAvailablePlugins() 
     297        { 
     298                return self::$_plugins; 
     299        } 
     300 
     301        /** 
     302         * @return array list of available themese 
     303         */ 
     304        public function getAvailableThemes() 
     305        { 
     306                return self::$_themes; 
     307        } 
     308 
     309        protected function preLoadCompressedScript() 
    234310        { 
    235311                $scripts = $this->getPage()->getClientScript(); 
    236312                if(!$scripts->isScriptFileRegistered('prado:THtmlArea')) 
    237313                        $scripts->registerScriptFile('prado:THtmlArea', $this->getScriptUrl()); 
     314                $key = 'prado:THtmlArea:compressed'; 
     315                if(!$scripts->isBeginScriptRegistered($key)) 
     316                { 
     317                        $options['plugins'] = implode(',', $this->getAvailablePlugins()); 
     318                        $options['themes'] = implode(',', $this->getAvailableThemes()); 
     319                        $options['languages'] = $this->getLanguageSuffix($this->getCulture()); 
     320                        $options['disk_cache'] = true; 
     321                        $options['debug'] = false; 
     322                        $js = TJavaScript::encode($options); 
     323                        $script = "if(typeof(tinyMCE_GZ)!='undefined'){ tinyMCE_GZ.init({$js}); }"; 
     324                        $scripts->registerBeginScript($key, $script); 
     325                } 
     326        } 
     327 
     328        /** 
     329         * Registers the editor javascript file and code to initialize the editor. 
     330         */ 
     331        protected function registerEditorClientScript($writer) 
     332        { 
     333                $scripts = $this->getPage()->getClientScript(); 
    238334                $options = TJavaScript::encode($this->getEditorOptions()); 
    239                 $script = "if(tinyMCE){ tinyMCE.init($options); }"; 
     335                $script = "if(typeof(tinyMCE)!='undefined'){ tinyMCE.init($options); }"; 
    240336                $scripts->registerEndScript('prado:THtmlArea'.$this->ClientID,$script); 
    241337        } 
     
    246342        protected function getScriptUrl() 
    247343        { 
    248                 return $this->getScriptDeploymentPath().'/tiny_mce/tiny_mce_gzip.php'; 
     344                return $this->getScriptDeploymentPath().'/tiny_mce/tiny_mce_gzip.js'; 
    249345        } 
    250346 
     
    259355                if($tarfile===null || $md5sum===null) 
    260356                        throw new TConfigurationException('htmlarea_tarfile_invalid'); 
    261                 return $this->getApplication()->getAssetManager()->publishTarFile($tarfile, $md5sum); 
     357                $url = $this->getApplication()->getAssetManager()->publishTarFile($tarfile, $md5sum); 
     358                $this->copyCustomPlugins($url); 
     359                return $url; 
     360        } 
     361 
     362        protected function copyCustomPlugins($url) 
     363        { 
     364                if($plugins = $this->getCustomPluginPath()) 
     365                { 
     366                        $assets = $this->getApplication()->getAssetManager(); 
     367                        $path = is_dir($plugins) ? $plugins : Prado::getPathOfNameSpace($plugins); 
     368                        $dest = $assets->getBasePath().'/'.basename($url).'/tiny_mce/plugins/'; 
     369                        if(!is_dir($dest) || $this->getApplication()->getMode()!==TApplicationMode::Performance) 
     370                                $assets->copyDirectory($path, $dest); 
     371                } 
    262372        } 
    263373 
     
    296406        { 
    297407                $options = array(); 
    298                 $substrings = preg_split('/\n|,\n/', trim($string)); 
     408                $substrings = preg_split('/,\s*\n|\n/', trim($string)); 
    299409                foreach($substrings as $bits) 
    300410                { 
    301                         $option = explode(":",$bits); 
     411                        $option = explode(":",$bits,2); 
     412 
    302413                        if(count($option) == 2) 
    303414                                $options[trim($option[0])] = trim(preg_replace('/\'|"/','',  $option[1])); 
     
    326437                return 'en'; 
    327438        } 
     439 
     440        /** 
     441         * Gets the name of the javascript class responsible for performing postback for this control. 
     442         * This method overrides the parent implementation. 
     443         * @return string the javascript class name 
     444         */ 
     445        protected function getClientClassName() 
     446        { 
     447                return 'Prado.WebUI.THtmlArea'; 
     448        } 
    328449} 
    329450