|
TYPO3 API
SVNRelease
|
00001 <?php 00002 /*************************************************************** 00003 * Copyright notice 00004 * 00005 * (c) 1999-2011 Kasper Skårhøj (kasper@typo3.com) 00006 * (c) 2005-2011 Stanislas Rolland <typo3(arobas)sjbr.ca> 00007 * All rights reserved 00008 * 00009 * This script is part of the TYPO3 project. The TYPO3 project is 00010 * free software; you can redistribute it and/or modify 00011 * it under the terms of the GNU General Public License as published by 00012 * the Free Software Foundation; either version 2 of the License, or 00013 * (at your option) any later version. 00014 * 00015 * The GNU General Public License can be found at 00016 * http://www.gnu.org/copyleft/gpl.html. 00017 * A copy is found in the textfile GPL.txt and important notices to the license 00018 * from the author is found in LICENSE.txt distributed with these scripts. 00019 * 00020 * 00021 * This script is distributed in the hope that it will be useful, 00022 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00023 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00024 * GNU General Public License for more details. 00025 * 00026 * This copyright notice MUST APPEAR in all copies of the script! 00027 ***************************************************************/ 00028 /** 00029 * User defined content for htmlArea RTE 00030 * 00031 * @author Kasper Skårhøj <kasper@typo3.com> 00032 * @author Stanislas Rolland <typo3(arobas)sjbr.ca> 00033 * 00034 * $Id: class.tx_rtehtmlarea_user.php 10120 2011-01-18 20:03:36Z ohader $ * 00035 */ 00036 00037 class tx_rtehtmlarea_user { 00038 var $content; 00039 var $modData; 00040 var $siteUrl; 00041 00042 /** 00043 * document template object 00044 * 00045 * @var template 00046 */ 00047 var $doc; 00048 var $editorNo; 00049 00050 /** 00051 * @return [type] ... 00052 */ 00053 function init() { 00054 global $BE_USER, $LANG, $BACK_PATH; 00055 00056 $this->editorNo = t3lib_div::_GP('editorNo'); 00057 00058 $this->siteUrl = t3lib_div::getIndpEnv('TYPO3_SITE_URL'); 00059 $this->doc = t3lib_div::makeInstance('template'); 00060 $this->doc->backPath = $BACK_PATH; 00061 00062 $this->doc->bodyTagAdditions = 'onload="Init();"'; 00063 $this->doc->form = ' 00064 <form action="" id="process" name="process" method="post"> 00065 <input type="hidden" name="processContent" value="" /> 00066 <input type="hidden" name="returnUrl" value="'.htmlspecialchars(t3lib_div::getIndpEnv('REQUEST_URI')).'" /> 00067 '; 00068 00069 $JScode = ' 00070 var plugin = window.parent.RTEarea["' . $this->editorNo . '"].editor.getPlugin("UserElements"); 00071 var HTMLArea = window.parent.HTMLArea; 00072 var editor = plugin.editor; 00073 00074 function Init() { 00075 }; 00076 function insertHTML(content,noHide) { 00077 plugin.restoreSelection(); 00078 editor.insertHTML(content); 00079 if(!noHide) plugin.close(); 00080 }; 00081 function wrapHTML(wrap1,wrap2,noHide) { 00082 plugin.restoreSelection(); 00083 if(editor.hasSelectedText()) { 00084 editor.surroundHTML(wrap1,wrap2); 00085 } else { 00086 alert('.$LANG->JScharCode($LANG->getLL('noTextSelection')).'); 00087 } 00088 if(!noHide) plugin.close(); 00089 }; 00090 function processSelection(script) { 00091 plugin.restoreSelection(); 00092 document.process.action = script; 00093 document.process.processContent.value = editor.getSelectedHTML(); 00094 document.process.submit(); 00095 }; 00096 function jumpToUrl(URL) { 00097 var RTEtsConfigParams = "&RTEtsConfigParams='.rawurlencode(t3lib_div::_GP('RTEtsConfigParams')).'"; 00098 var editorNo = "&editorNo=' . rawurlencode($this->editorNo) . '"; 00099 theLocation = "'.t3lib_div::getIndpEnv('SCRIPT_NAME').'"+URL+RTEtsConfigParams+editorNo; 00100 window.location.href = theLocation; 00101 } 00102 '; 00103 00104 $this->doc->JScode = $this->doc->wrapScriptTags($JScode); 00105 00106 $this->modData = $BE_USER->getModuleData('user.php','ses'); 00107 if (t3lib_div::_GP('OC_key')) { 00108 $parts = explode('|',t3lib_div::_GP('OC_key')); 00109 $this->modData['openKeys'][$parts[1]] = $parts[0]=='O' ? 1 : 0; 00110 $BE_USER->pushModuleData('user.php',$this->modData); 00111 } 00112 } 00113 00114 /** 00115 * [Describe function...] 00116 * 00117 * @return [type] ... 00118 */ 00119 function main() { 00120 00121 $this->content=''; 00122 $this->content.=$this->main_user($this->modData['openKeys']); 00123 } 00124 00125 /** 00126 * [Describe function...] 00127 * 00128 * @return [type] ... 00129 */ 00130 function printContent() { 00131 echo $this->content; 00132 } 00133 00134 00135 00136 /******************************** 00137 * 00138 * Other functions 00139 * 00140 *********************************/ 00141 00142 /** 00143 * @param [type] $imgInfo: ... 00144 * @param [type] $maxW: ... 00145 * @param [type] $maxH: ... 00146 * @return [type] ... 00147 */ 00148 function calcWH($imgInfo,$maxW=380,$maxH=500) { 00149 $IW = $imgInfo[0]; 00150 $IH = $imgInfo[1]; 00151 if ($IW>$maxW) { 00152 $IH=ceil($IH/$IW*$maxW); 00153 $IW=$maxW; 00154 } 00155 if ($IH>$maxH) { 00156 $IW=ceil($IW/$IH*$maxH); 00157 $IH=$maxH; 00158 } 00159 00160 $imgInfo[3]='width="'.$IW.'" height="'.$IH.'"'; 00161 return $imgInfo; 00162 } 00163 00164 /** 00165 * Rich Text Editor (RTE) user element selector 00166 * 00167 * @param [type] $openKeys: ... 00168 * @return [type] ... 00169 */ 00170 function main_user($openKeys) { 00171 global $LANG, $BACK_PATH, $BE_USER; 00172 // Starting content: 00173 $content.=$this->doc->startPage($LANG->getLL('Insert Custom Element',1)); 00174 00175 $RTEtsConfigParts = explode(':',t3lib_div::_GP('RTEtsConfigParams')); 00176 $RTEsetup = $BE_USER->getTSConfig('RTE',t3lib_BEfunc::getPagesTSconfig($RTEtsConfigParts[5])); 00177 $thisConfig = t3lib_BEfunc::RTEsetup($RTEsetup['properties'],$RTEtsConfigParts[0],$RTEtsConfigParts[2],$RTEtsConfigParts[4]); 00178 00179 if (is_array($thisConfig['userElements.'])) { 00180 00181 $categories=array(); 00182 foreach ($thisConfig['userElements.'] as $k => $value) { 00183 $ki=intval($k); 00184 $v = $thisConfig['userElements.'][$ki.'.']; 00185 if (substr($k,-1)=="." && is_array($v)) { 00186 $subcats=array(); 00187 $openK = $ki; 00188 if ($openKeys[$openK]) { 00189 00190 $mArray = ''; 00191 switch ((string)$v['load']) { 00192 case 'images_from_folder': 00193 $mArray=array(); 00194 if ($v['path'] && @is_dir(PATH_site.$v['path'])) { 00195 $files = t3lib_div::getFilesInDir(PATH_site.$v['path'],'gif,jpg,jpeg,png',0,''); 00196 if (is_array($files)) { 00197 $c=0; 00198 foreach ($files as $filename) { 00199 $iInfo = @getimagesize(PATH_site.$v['path'].$filename); 00200 $iInfo = $this->calcWH($iInfo,50,100); 00201 00202 $ks=(string)(100+$c); 00203 $mArray[$ks]=$filename; 00204 $mArray[$ks."."]=array( 00205 'content' => '<img src="'.$this->siteUrl.$v['path'].$filename.'" />', 00206 '_icon' => '<img src="'.$this->siteUrl.$v['path'].$filename.'" '.$iInfo[3].' />', 00207 'description' => $LANG->getLL('filesize').': '.str_replace(' ',' ',t3lib_div::formatSize(@filesize(PATH_site.$v['path'].$filename))).', '.$LANG->getLL('pixels',1).': '.$iInfo[0].'x'.$iInfo[1] 00208 ); 00209 $c++; 00210 } 00211 } 00212 } 00213 break; 00214 } 00215 if (is_array($mArray)) { 00216 if ($v['merge']) { 00217 $v=t3lib_div::array_merge_recursive_overrule($mArray,$v); 00218 } else { 00219 $v=$mArray; 00220 } 00221 } 00222 foreach ($v as $k2 => $dummyValue) { 00223 $k2i = intval($k2); 00224 if (substr($k2,-1)=='.' && is_array($v[$k2i.'.'])) { 00225 $title = trim($v[$k2i]); 00226 if (!$title) { 00227 $title='['.$LANG->getLL('noTitle',1).']'; 00228 } else { 00229 $title=$LANG->sL($title,1); 00230 } 00231 $description = $LANG->sL($v[$k2i.'.']['description'],1).'<br />'; 00232 if (!$v[$k2i.'.']['dontInsertSiteUrl']) $v[$k2i.'.']['content'] = str_replace('###_URL###',$this->siteUrl,$v[$k2i.'.']['content']); 00233 00234 $logo = $v[$k2i.'.']['_icon'] ? $v[$k2i.'.']['_icon'] : ''; 00235 00236 $onClickEvent=''; 00237 switch((string)$v[$k2i.'.']['mode']) { 00238 case 'wrap': 00239 $wrap = explode('|',$v[$k2i.'.']['content']); 00240 $onClickEvent='wrapHTML(' . $LANG->JScharCode($wrap[0]) . ',' . $LANG->JScharCode($wrap[1]) . ',false);'; 00241 break; 00242 case 'processor': 00243 $script = trim($v[$k2i.'.']['submitToScript']); 00244 if (substr($script,0,4)!='http') $script = $this->siteUrl.$script; 00245 if ($script) { 00246 $onClickEvent='processSelection(' . $LANG->JScharCode($script) . ');'; 00247 } 00248 break; 00249 case 'insert': 00250 default: 00251 $onClickEvent='insertHTML(' . $LANG->JScharCode($v[$k2i . '.']['content']) . ');'; 00252 break; 00253 } 00254 $A=array('<a href="#" onClick="'.$onClickEvent.'return false;">','</a>'); 00255 $subcats[$k2i]='<tr> 00256 <td><img src="clear.gif" width="18" height="1" /></td> 00257 <td class="bgColor4" valign="top">'.$A[0].$logo.$A[1].'</td> 00258 <td class="bgColor4" valign="top">'.$A[0].'<strong>'.$title.'</strong><br />'.$description.$A[1].'</td> 00259 </tr>'; 00260 } 00261 } 00262 ksort($subcats); 00263 } 00264 $categories[$ki]=implode('',$subcats); 00265 } 00266 } 00267 ksort($categories); 00268 00269 # Render menu of the items: 00270 $lines=array(); 00271 foreach ($categories as $k => $v) { 00272 $title = trim($thisConfig['userElements.'][$k]); 00273 $openK = $k; 00274 if (!$title) { 00275 $title='['.$LANG->getLL('noTitle',1).']'; 00276 } else { 00277 $title=$LANG->sL($title,1); 00278 } 00279 //$lines[]='<tr><td colspan="3" class="bgColor5"><a href="'.t3lib_div::linkThisScript(array('OC_key' => ($openKeys[$openK]?'C|':'O|').$openK, 'editorNo' => $this->editorNo)).'" title="'.$LANG->getLL('expand',1).'"><img' . t3lib_iconWorks::skinImg($BACK_PATH,'gfx/ol/'.($openKeys[$openK]?'minus':'plus').'bullet.gif','width="18" height="16"').' title="'.$LANG->getLL('expand',1).'" /><strong>'.$title.'</strong></a></td></tr>'; 00280 $lines[]='<tr><td colspan="3" class="bgColor5"><a href="#" title="'.$LANG->getLL('expand',1).'" onClick="jumpToUrl(\'?OC_key=' .($openKeys[$openK]?'C|':'O|').$openK. '\');return false;"><img' . t3lib_iconWorks::skinImg($BACK_PATH,'gfx/ol/'.($openKeys[$openK]?'minus':'plus').'bullet.gif','width="18" height="16"').' title="'.$LANG->getLL('expand',1).'" /><strong>'.$title.'</strong></a></td></tr>'; 00281 $lines[]=$v; 00282 } 00283 00284 $content.='<table border="0" cellpadding="1" cellspacing="1">'.implode('',$lines).'</table>'; 00285 } 00286 00287 $content.= $this->doc->endPage(); 00288 return $content; 00289 } 00290 } 00291 00292 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/rtehtmlarea/mod5/class.tx_rtehtmlarea_user.php'])) { 00293 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/rtehtmlarea/mod5/class.tx_rtehtmlarea_user.php']); 00294 } 00295 00296 ?>
1.8.0