| 1 | <?php
|
| 2 | /***************************************************************
|
| 3 | * Copyright notice
|
| 4 | *
|
| 5 | * (c) 2008 Marcus Schwemer (schwemer@netzwerkberatung.de)
|
| 6 | * All rights reserved
|
| 7 | *
|
| 8 | * This script is part of the TYPO3 project. The TYPO3 project is
|
| 9 | * free software; you can redistribute it and/or modify
|
| 10 | * it under the terms of the GNU General Public License as published by
|
| 11 | * the Free Software Foundation; either version 2 of the License, or
|
| 12 | * (at your option) any later version.
|
| 13 | *
|
| 14 | * The GNU General Public License can be found at
|
| 15 | * http://www.gnu.org/copyleft/gpl.html.
|
| 16 | *
|
| 17 | * This script is distributed in the hope that it will be useful,
|
| 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 20 | * GNU General Public License for more details.
|
| 21 | *
|
| 22 | * This copyright notice MUST APPEAR in all copies of the script!
|
| 23 | ***************************************************************/
|
| 24 |
|
| 25 | /**
|
| 26 | * class.tx_tinymcerte_pi1.php
|
| 27 | *
|
| 28 | * Provides tinymce_rte for use in frontend plugins
|
| 29 | *
|
| 30 | * @author Marcus Schwemer <schwemer@netzwerkberatung.de)
|
| 31 | *
|
| 32 | */
|
| 33 |
|
| 34 | /**
|
| 35 | * This class provides the tinymce_rte for usage in FE-plugins
|
| 36 | *
|
| 37 | * @author Marcus Schwemer <schwemer@netzwerkberatung.de>
|
| 38 | * @package Typo3
|
| 39 | * @subpackage tinymce_rte
|
| 40 | */
|
| 41 |
|
| 42 | require_once(t3lib_extMgm::extPath('tinymce_rte').'class.tx_tinymce_rte_base.php');
|
| 43 |
|
| 44 | class tx_tinymcerte_pi1 extends tx_tinymce_rte_base
|
| 45 | {
|
| 46 | var $pageTSConfig = array();
|
| 47 | var $rteSetup = array();
|
| 48 | var $httpTypo3Path;
|
| 49 | var $extHttpPath;
|
| 50 |
|
| 51 | /**
|
| 52 | * * Adds the tinymce_rte to a textarea
|
| 53 | *
|
| 54 | * @param object $parentObject Reference to parent object, which is an instance of the TCEforms.
|
| 55 | * @param string $table The table name
|
| 56 | * @param string $field The field name
|
| 57 | * @param array $row The current row from which field is being rendered
|
| 58 | * @param array $PA Array of standard content for rendering form fields from TCEforms. See TCEforms for details on this. Includes for instance the value and the form field name, java script actions and more.
|
| 59 | * @param array $specConf "special" configuration - what is found at position 4 in the types configuration of a field from record, parsed into an array.
|
| 60 | * @param array $thisConfig Configuration for RTEs; A mix between TSconfig and otherwise. Contains configuration for display, which buttons are enabled, additional transformation information etc.
|
| 61 | * @param string $RTEtypeVal Record "type" field value.
|
| 62 | * @param string $RTErelPath Relative path for images/links in RTE; this is used when the RTE edits content from static files where the path of such media has to be transformed forth and back!
|
| 63 | * @param integer $thePidValue PID value of record (true parent page id)
|
| 64 | * @return string HTML code for tinymce_rte
|
| 65 | */
|
| 66 |
|
| 67 | function drawRTE($parentObject,$table,$field,$row,$PA,$specConf,$thisConfig,$RTEtypeVal,$RTErelPath,$thePidValue) {
|
| 68 |
|
| 69 | // relativ paths to tinymce files
|
| 70 | $mceRelPath = 'res/tiny_mce/tiny_mce.js';
|
| 71 | $mceRelGzipPath = 'res/tiny_mce/tiny_mce_gzip.js';
|
| 72 |
|
| 73 | // html code for rte creation
|
| 74 | $code = '';
|
| 75 |
|
| 76 | //loads the current Value
|
| 77 | $value = $this->transformContent('rte',$PA['itemFormElValue'],$table,$field,$row,$specConf,$thisConfig, $RTErelPath ,$thePidValue);
|
| 78 |
|
| 79 | $this->initClassVars();
|
| 80 |
|
| 81 | $config = $this->getConfiguration($parentObject);
|
| 82 |
|
| 83 | $loaded = ( t3lib_extmgm::isLoaded( $this->rteSetup['languagesExtension'] ) ) ? 1 : 0;
|
| 84 |
|
| 85 | if ($this->rteSetup['gzip']) {
|
| 86 | $code .= '
|
| 87 | <script type="text/javascript" src="'. $this->extHttpPath . $mceRelGzipPath . '"></script>
|
| 88 | <script type="text/javascript">
|
| 89 | /* <![CDATA[ */
|
| 90 | tinyMCE_GZ.init({
|
| 91 | plugins : "' . $this->conf['init']['plugins'] . '",
|
| 92 | themes : "advanced",
|
| 93 | languages : "' . $this->conf['init']['language'] .'",
|
| 94 | disk_cache : ' . $this->rteSetup['gzipFileCache'] . ',
|
| 95 | langExt : "' . $this->rteSetup['languagesExtension'] . '",
|
| 96 | langExtLoaded : ' . $loaded . ',
|
| 97 | debug : false
|
| 98 | });
|
| 99 | /* ]]> */
|
| 100 | </script>
|
| 101 | ';
|
| 102 | } else {
|
| 103 | $code .= '<script type="text/javascript" src="'. $this->extHttpPath . $mceRelPath . '"></script>';
|
| 104 | if ( t3lib_extmgm::isLoaded($this->rteSetup['languagesExtension']) && ($this->conf['init']['language'] != 'en') && ($this->conf['init']['language'] != 'de') ) {
|
| 105 | $code .= '<script type="text/javascript"> /* <![CDATA[ */';
|
| 106 | $code .= $this->loadLanguageExtension($this->conf['init']['language'], $this->conf['init']['plugins'], t3lib_extMgm::siteRelPath($this->rteSetup['languagesExtension']) . '/tiny_mce' );
|
| 107 | $code .= '/* ]]> */</script>';
|
| 108 | }
|
| 109 | }
|
| 110 |
|
| 111 | $code .= '
|
| 112 | <script type="text/javascript">
|
| 113 | /* <![CDATA[ */
|
| 114 | tinyMCE.init(
|
| 115 | ' . $this->parseConfig($config) . '
|
| 116 | );
|
| 117 | /* ]]> */
|
| 118 | </script>
|
| 119 | ';
|
| 120 |
|
| 121 | $code .= $this->triggerField($PA['itemFormElName']);
|
| 122 | $code .= '<textarea id="RTEarea'.$pObj->RTEcounter.'" class="tinymce_rte" name="'.htmlspecialchars($PA['itemFormElName']).'" rows="15" cols="80">'.t3lib_div::formatForTextarea($value).'</textarea>';
|
| 123 |
|
| 124 | return $code;
|
| 125 |
|
| 126 |
|
| 127 | }
|
| 128 |
|
| 129 | /**
|
| 130 | * This function initializes the class viariables
|
| 131 | *
|
| 132 | * @param none
|
| 133 | * @return void
|
| 134 | */
|
| 135 |
|
| 136 | function initClassVars() {
|
| 137 |
|
| 138 | // first get the http-path to typo3:
|
| 139 | $this->httpTypo3Path = substr( substr( t3lib_div::getIndpEnv('TYPO3_SITE_URL'), strlen( t3lib_div::getIndpEnv('TYPO3_REQUEST_HOST') ) ), 0, -1 );
|
| 140 | if (strlen($this->httpTypo3Path) == 1) {
|
| 141 | $this->httpTypo3Path = '/';
|
| 142 | } else {
|
| 143 | $this->httpTypo3Path .= '/';
|
| 144 | }
|
| 145 |
|
| 146 | // Get the path to this extension:
|
| 147 | $this->extHttpPath = $this->httpTypo3Path.t3lib_extMgm::siteRelPath('tinymce_rte');
|
| 148 |
|
| 149 | $this->pageTSConfig = $GLOBALS['TSFE']->getPagesTSconfig();
|
| 150 |
|
| 151 | if (is_array($this->pageTSConfig) && is_array($this->pageTSConfig['RTE.']['default.'])) {
|
| 152 | $this->rteSetup = $this->pageTSConfig['RTE.']['default.'];
|
| 153 | }
|
| 154 | }
|
| 155 |
|
| 156 | /**
|
| 157 | * Reads the configuration from PageTS and TS-Setup and merges them into one array
|
| 158 | *
|
| 159 | * @param object $parentObject
|
| 160 | * @return array Array with all configuration parameters
|
| 161 | */
|
| 162 | function getConfiguration($parentObject) {
|
| 163 |
|
| 164 | if (is_array($this->rteSetup['init.'])) {
|
| 165 | $rteInit = $this->rteSetup['init.'];
|
| 166 | } else {
|
| 167 | $rteInit = array();
|
| 168 | }
|
| 169 |
|
| 170 | if (is_array($this->rteSetup) && is_array($this->rteSetup['FE.'])) {
|
| 171 | $feSetup = $this->rteSetup['FE.'];
|
| 172 | }
|
| 173 |
|
| 174 | if (is_array($feSetup['init.'])) {
|
| 175 | $feInit = $feSetup['init.'];
|
| 176 | } else {
|
| 177 | $feInit = array();
|
| 178 | }
|
| 179 |
|
| 180 | if (is_array($parentObject->conf['tinymce_rte.'])) {
|
| 181 | $tsSetup = $parentObject->conf['tinymce_rte.'];
|
| 182 | }
|
| 183 |
|
| 184 | if (is_array($tsSetup['init.'])) {
|
| 185 | $tsInit = $tsSetup['init.'];
|
| 186 | } else {
|
| 187 | $tsInit = array();
|
| 188 | }
|
| 189 |
|
| 190 | // get the language (also checks if lib is called from FE or BE, which might of use later.)
|
| 191 | $lang = (TYPO3_MODE == 'FE') ? $GLOBALS['TSFE'] : $GLOBALS['LANG'];
|
| 192 | $this->language = $lang->lang;
|
| 193 |
|
| 194 | // language conversion from TLD to iso631
|
| 195 | if ( array_key_exists($this->language, $lang->csConvObj->isoArray) )
|
| 196 | $this->language = $lang->csConvObj->isoArray[$this->language];
|
| 197 |
|
| 198 | // check if TinyMCE language file exists
|
| 199 | $langpath = (t3lib_extmgm::isLoaded($thisConfig['languagesExtension'])) ? t3lib_extMgm::siteRelPath($thisConfig['languagesExtension']) : t3lib_extMgm::siteRelPath('tinymce_rte') . 'res/';
|
| 200 |
|
| 201 | if(!is_file(PATH_site . $langpath . 'tiny_mce/langs/' . $this->language . '.js')) {
|
| 202 | $this->language = 'en';
|
| 203 | }
|
| 204 |
|
| 205 | $this->conf['init'] = array(
|
| 206 | 'language' => $this->language,
|
| 207 | 'document_base_url' => t3lib_div::getIndpEnv('TYPO3_SITE_URL')
|
| 208 | );
|
| 209 |
|
| 210 | $this->conf['init'] = array_merge($this->conf['init'], $rteInit, $feInit, $tsInit);
|
| 211 |
|
| 212 | return $this->conf['init'];
|
| 213 |
|
| 214 | }
|
| 215 |
|
| 216 | }
|
| 217 |
|
| 218 | // Default-Code for using XCLASS (dont touch)
|
| 219 | if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/tinymce_rte/pi1/class.tx_tinymcerte_pi1.php']) {
|
| 220 | include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/tinymce_rte/pi1/class.tx_tinymcerte_pi1.php']);
|
| 221 | }
|
| 222 |
|
| 223 | ?>
|