This commit was manufactured by cvs2svn to create branch 'Kasper'.
[Packages/TYPO3.CMS.git] / typo3 / rte_user.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2003 Kasper Skårhøj (kasper@typo3.com)
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 * A copy is found in the textfile GPL.txt and important notices to the license
17 * from the author is found in LICENSE.txt distributed with these scripts.
18 *
19 *
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27 /**
28 * User defined content for the RTE
29 *
30 * Belongs to the "rte" extension
31 *
32 * @author Kasper Skårhøj <kasper@typo3.com>
33 * @package TYPO3
34 * @subpackage core
35 *
36 */
37
38
39
40 $BACK_PATH="";
41 require ("init.php");
42 require ("template.php");
43 include ("sysext/lang/locallang_rte_user.php");
44
45
46 // ***************************
47 // Script Classes
48 // ***************************
49 class SC_rte_user {
50 var $content;
51 var $modData;
52 var $siteUrl;
53 var $doc;
54
55 function init() {
56 global $BE_USER,$LANG,$BACK_PATH,$TCA_DESCR,$TCA,$HTTP_GET_VARS,$HTTP_POST_VARS,$CLIENT,$TYPO3_CONF_VARS;
57
58 /* $PRE_CODED["clear_gifs"] = Array (
59 "100" => "Clear-gif, 100x20",
60 "100." => Array (
61 "content" => '<img src=clear.gif width=100 height=20><BR>'
62 ),
63 "110" => "Clear-gif, 200x50",
64 "110." => Array (
65 "content" => '<img src=clear.gif width=200 height=50><BR>'
66 )
67 );
68 */
69
70
71 // Current site url:
72 $this->siteUrl = t3lib_div::getIndpEnv("TYPO3_SITE_URL");
73
74 $this->doc = t3lib_div::makeInstance("template");
75 $this->doc->backPath = $BACK_PATH;
76 $this->doc->form = '<form action="" name="process" method="POST">
77 <input type="hidden" name="processContent" value="">
78 <input type="hidden" name="returnUrl" value="'.htmlspecialchars(t3lib_div::getIndpEnv("REQUEST_URI")).'">
79 ';
80 $this->doc->JScode='
81 <script language="javascript" type="text/javascript">
82 var RTEobj = self.parent.parent;
83
84 function getSelectedTextContent() {
85 var oSel = RTEobj.GLOBAL_SEL;
86 var sType = oSel.type;
87 // alert(sType);
88 // RTEobj.debugObj(oSel);
89 if (sType=="Text") {
90 return oSel.htmlText;
91 }
92 return "";
93 }
94 function insertHTML(content,noHide) {
95 // alert(content);
96 RTEobj.insertHTML(content);
97 if (!noHide) RTEobj.edHidePopup();
98 }
99 function wrapHTML(wrap1,wrap2,noHide) {
100 var contentToWrap = getSelectedTextContent();
101 if (contentToWrap) {
102 contentToWrap = ""+wrap1+contentToWrap+wrap2;
103 setSelectedTextContent(contentToWrap);
104 } else {
105 alert('.$GLOBALS['LANG']->JScharCode($LANG->getLL("noTextSelection")).');
106 }
107 if (!noHide) RTEobj.edHidePopup();
108 }
109 function processSelection(script) {
110 document.process.action = script;
111 document.process.processContent.value = getSelectedTextContent();
112 document.process.submit();
113 }
114 function setSelectedTextContent(content) {
115 var oSel = RTEobj.GLOBAL_SEL;
116 var sType = oSel.type;
117 if (sType=="Text") {
118 oSel.pasteHTML(content);
119 }
120 }
121 // alert(RTEobj.getHTML());
122 // RTEobj.setHTML("Hej <b>Kasper</b>-dreng!",1);
123 </script>
124 ';
125
126
127 $this->modData = $BE_USER->getModuleData("rte_user.php","ses");
128 if (t3lib_div::GPvar("OC_key")) {
129 $parts = explode("|",t3lib_div::GPvar("OC_key"));
130 $this->modData["openKeys"][$parts[1]] = $parts[0]=="O" ? 1 : 0;
131 $BE_USER->pushModuleData("rte_user.php",$this->modData);
132 }
133 }
134 function main() {
135 global $BE_USER,$LANG,$BACK_PATH,$TCA_DESCR,$TCA,$HTTP_GET_VARS,$HTTP_POST_VARS,$CLIENT,$TYPO3_CONF_VARS;
136
137 $this->content="";
138 $this->content.=$this->main_user($this->modData["openKeys"]);
139 }
140 function printContent() {
141 echo $this->content;
142 }
143
144 // ***************************
145 // OTHER FUNCTIONS:
146 // ***************************
147 function calcWH($imgInfo,$maxW=380,$maxH=500) {
148 $IW = $imgInfo[0];
149 $IH = $imgInfo[1];
150 if ($IW>$maxW) {
151 $IH=ceil($IH/$IW*$maxW);
152 $IW=$maxW;
153 }
154 if ($IH>$maxH) {
155 $IW=ceil($IW/$IH*$maxH);
156 $IH=$maxH;
157 }
158
159 $imgInfo[3]='width="'.$IW.'" height="'.$IH.'"';
160 return $imgInfo;
161 }
162
163 // ******************************************************************
164 // Rich Text Editor (RTE) link selector (MAIN function)
165 // ******************************************************************
166 function main_user($openKeys) {
167 global $SOBE,$LANG;
168 // Starting content:
169 $content.=$this->doc->startPage("RTE user");
170
171 $RTEtsConfigParts = explode(":",t3lib_div::GPvar("RTEtsConfigParams"));
172 $RTEsetup = $GLOBALS["BE_USER"]->getTSConfig("RTE",t3lib_BEfunc::getPagesTSconfig($RTEtsConfigParts[5]));
173 $thisConfig = t3lib_BEfunc::RTEsetup($RTEsetup["properties"],$RTEtsConfigParts[0],$RTEtsConfigParts[2],$RTEtsConfigParts[4]);
174
175 //debug($RTEtsConfigParts);
176 //debug($thisConfig);
177 if (is_array($thisConfig["userElements."])) {
178
179 $categories=array();
180 reset($thisConfig["userElements."]);
181 while(list($k)=each($thisConfig["userElements."])) {
182 $ki=intval($k);
183 $v = $thisConfig["userElements."][$ki."."];
184 if (substr($k,-1)=="." && is_array($v)) {
185 $subcats=array();
186 $openK = $ki;
187 if ($openKeys[$openK]) {
188
189 $mArray = "";
190 switch ((string)$v["load"]) {
191 case "images_from_folder":
192 $mArray=array();
193 if ($v["path"] && @is_dir(PATH_site.$v["path"])) {
194 $files = t3lib_div::getFilesInDir(PATH_site.$v["path"],"gif,jpg,jpeg,png",0,"");
195 if (is_array($files)) {
196 reset($files);
197 $c=0;
198 while(list(,$filename)=each($files)) {
199 $iInfo = @getimagesize(PATH_site.$v["path"].$filename);
200 $iInfo = $this->calcWH($iInfo,50,100);
201
202 $ks=(string)(100+$c);
203 $mArray[$ks]=$filename;
204 $mArray[$ks."."]=array(
205 "content" => '<img src="'.$this->siteUrl.$v["path"].$filename.'">',
206 "_icon" => '<img src="'.$this->siteUrl.$v["path"].$filename.'" '.$iInfo[3].' border=0>',
207 "description" => $LANG->getLL("filesize").': '.str_replace("&nbsp;"," ",t3lib_div::formatSize(@filesize(PATH_site.$v["path"].$filename))).', '.$LANG->getLL("pixels").': '.$iInfo[0].'x'.$iInfo[1]
208 );
209 $c++;
210 }
211 }
212 }
213 break;
214 /* case "clear_gifs":
215 $mArray=$GLOBALS["PRE_CODED"]["clear_gifs"];
216 break;*/
217 }
218 if (is_array($mArray)) {
219 if ($v["merge"]) {
220 $v=t3lib_div::array_merge_recursive_overrule($mArray,$v);
221 } else {
222 $v=$mArray;
223 }
224 }
225
226 // debug($v);
227 reset($v);
228 while(list($k2)=each($v)) {
229 $k2i = intval($k2);
230 if (substr($k2,-1)=="." && is_array($v[$k2i."."])) {
231 $title = trim($v[$k2i]);
232 if (!$title) {
233 $title="[".$LANG->getLL("noTitle")."]";
234 } else {
235 $title=$LANG->sL($title,1);
236 }
237 $description=$LANG->sL($v[$k2i."."]["description"],1)."<BR>";
238 if (!$v[$k2i."."]["dontInsertSiteUrl"]) $v[$k2i."."]["content"] = str_replace("###_URL###",$this->siteUrl,$v[$k2i."."]["content"]);
239
240 $logo = $v[$k2i."."]["_icon"] ? $v[$k2i."."]["_icon"] : '';
241
242 $onClickEvent='';
243 switch((string)$v[$k2i."."]["mode"]) {
244 case "wrap":
245 $wrap = explode("|",$v[$k2i."."]["content"]);
246 $onClickEvent="wrapHTML(unescape('".str_replace("%20"," ",rawurlencode($wrap[0]))."'),unescape('".str_replace("%20"," ",rawurlencode($wrap[1]))."'));";
247 break;
248 case "processor":
249 $script = trim($v[$k2i."."]["submitToScript"]);
250 if (substr($script,0,4)!="http") $script = $this->siteUrl.$script;
251 //debug($script);
252 if ($script) {
253 $onClickEvent="processSelection(unescape('".rawurlencode($script)."'));";
254 }
255 break;
256 case "insert":
257 default:
258 $onClickEvent="insertHTML(unescape('".str_replace("%20"," ",rawurlencode($v[$k2i."."]["content"]))."'));";
259 break;
260 }
261 $A=array('<a href="#" onClick="'.$onClickEvent.'return false;">','</a>');
262 // debug($v[$k2i."."]);
263
264 $subcats[$k2i]='<tr>
265 <td><img src="clear.gif" width="18" height="1"></td>
266 <td bgColor="'.$this->doc->bgColor4.'" valign=top>'.$A[0].$logo.$A[1].'</td>
267 <td bgColor="'.$this->doc->bgColor4.'" valign=top>'.$A[0].'<strong>'.$title.'</strong><BR>'.$description.$A[1].'</td>
268 </tr>';
269 }
270 }
271 ksort($subcats);
272 }
273 $categories[$ki]=implode("",$subcats);
274 }
275 }
276 ksort($categories);
277
278 # Render menu of the items:
279 $lines=array();
280 reset($categories);
281 while(list($k,$v)=each($categories)) {
282 $title = trim($thisConfig["userElements."][$k]);
283 $openK = $k;
284 if (!$title) {
285 $title="[".$LANG->getLL("noTitle")."]";
286 } else {
287 $title=$LANG->sL($title,1);
288 }
289 $lines[]='<tr><td colspan=3 bgColor="'.$this->doc->bgColor5.'"><a href="'.t3lib_div::linkThisScript(array("OC_key"=>($openKeys[$openK]?"C|":"O|").$openK)).'"'.t3lib_BEfunc::titleAttrib($LANG->getLL("expand")).'><img src="gfx/ol/'.($openKeys[$openK]?"minus":"plus").'bullet.gif" width="18" height="16" border="0" align=top'.t3lib_BEfunc::titleAttrib($LANG->getLL("expand")).'><strong>'.$title.'</strong></a></td></tr>';
290 $lines[]=$v;
291 }
292
293 $content.='<table border=0 cellpadding=1 cellspacing=1>'.implode("",$lines).'</table>';
294 }
295
296 $content.= $this->doc->endPage();
297 return $content;
298 }
299 }
300
301 // Include extension?
302 if (defined("TYPO3_MODE") && $TYPO3_CONF_VARS[TYPO3_MODE]["XCLASS"]["typo3/rte_user.php"]) {
303 include_once($TYPO3_CONF_VARS[TYPO3_MODE]["XCLASS"]["typo3/rte_user.php"]);
304 }
305
306
307
308
309
310
311
312
313
314
315
316
317 // Make instance:
318 $SOBE = t3lib_div::makeInstance("SC_rte_user");
319 $SOBE->init();
320 $SOBE->main();
321 $SOBE->printContent();
322 ?>