[TYPO3] TinyRTE and links button [trying to solve]

Cyprian Kowalczyk cyprian at pi2.pl
Sat May 27 16:19:52 CEST 2006


Here is my patch for TinyRTE and browse_links.php:

browse_links.php (around line 790, I moved the first snipet (//Determine  
nature of current url) - it was after //CurentURL - the current link...)  
and changed some lines:

		// Determine nature of current url:
		$this->act=t3lib_div::_GP('act');
		if (!$this->act)	{
			$this->act=$this->curUrlInfo['act'];
		}

		// CurrentUrl - the current link url must be passed around if it exists
		if ($this->mode=='wizard')	{
			if ($this->act == 'page') {
				$currentLinkParts = t3lib_div::trimExplode('  
',$this->P['currentValue']);
				$this->curUrlArray = array(
				'href' =>  $currentLinkParts[0],
				'target' => $currentLinkParts[1]
				);
				if (sizeof($currentLinkParts) > 2) {
					$i =2;
					while ($i < sizeof($currentLinkParts)) {
						$this->curUrlArray['title'] .= $currentLinkParts[$i++] . ' ';
					}
					$this->curUrlArray['title'] = trim($this->curUrlArray['title']);
				}
				$this->curUrlInfo=$this->parseCurUrl($this->siteURL.'?id='.$currentLinkParts[0],$this->siteURL);
			} else {
				$this->curUrlArray = t3lib_div::_GP('curUrl');
				if ($this->curUrlArray['all'])	{
					$this->curUrlArray=t3lib_div::get_tag_attributes($this->curUrlArray['all']);
				}
				$this->curUrlInfo=$this->parseCurUrl($this->curUrlArray['href'],$this->siteURL);
			}
		} else {
			$this->curUrlArray = t3lib_div::_GP('curUrl');
			if ($this->curUrlArray['all'])	{
				$this->curUrlArray=t3lib_div::get_tag_attributes($this->curUrlArray['all']);
			}
			$this->curUrlInfo=$this->parseCurUrl($this->curUrlArray['href'],$this->siteURL);
		}


/////////////////////
class.tx_tinyrte.php:
around line 217 ->
			function fileBrowserCallBack(field_name, url, type, win) {
				var template = new Array();
				template["width"] = 500;
				template["height"] = 300;
				var editor_id="RTEarea'.$pObj->RTEcounter.'";
				switch(type){
					case "link":
						var curr="";
						var act="page";
						var selURL="";
						var current="";
						node=tinyMCE.selectedElement;
						do {
							if (node.nodeName.toLowerCase() == "a" && tinyMCE.getAttrib(node,  
"href") != "") {
								curr=tinyMCE.getAttrib(node, "href");
								if(curr.indexOf("?id=")<0) {
									if(curr.indexOf("@")>-1) {
										act="mail";
									}
									else if(curr.indexOf("http://")>-1 || curr.indexOf("www.")>-1) {
										act="url";
									}
									current="&curUrl[href]="+tinyMCE.getAttrib(node,  
"href")+"&curUrl[target]="+tinyMCE.getAttrib(node,  
"target")+"&curUrl[title]="+tinyMCE.getAttrib(node, "title");
								}
								else {
									var fz=curr.indexOf("?")+4;
									selURL=curr.substr(fz,curr.length);
									current="&P[currentValue]="+selURL+" "+tinyMCE.getAttrib(node,  
"target")+" "+tinyMCE.getAttrib(node, "title")+" ";
								}
								break;
							}
						} while ((node = node.parentNode));
						template["file"] =  
"'.$this->httpTypo3Path.'typo3/browse_links.php?act="+act+"&mode=wizard&P[ext]=../'.t3lib_extMgm::siteRelPath("tinyrte").'&P[init]=tinyrte&P[formName]=editform"+current+"&P[itemName]=data%5B'.$table.'%5D%5B'.$row["uid"].'%5D%5B'.$field.'%5D_hr&P[fieldChangeFunc][setTheValue]=setTheValue%28\'link\',input,document.location.search%29%3B&P[fieldChangeFunc][TBE_EDITOR_fieldChanged]=TBE_EDITOR_fieldChanged%28%27'.$table.'%27%2C%27'.$row["uid"].'%27%2C%27'.$field.'%27%2C%27data%5B'.$table.'%5D%5B'.$row["uid"].'%5D%5B'.$field.'%5D%27%29%3B";
						tinyMCE.openWindow(template, {editor_id : editor_id, scrollbars :  
"yes", inline : "yes"});
						return false;

					case "image":
						template["file"] =  
"'.$this->Path.'rte_select_image.php?&RTEtsConfigParams='.$table.'%3A136%3A'.$field.'%3A29%3Atext%3A'.$row["pid"].'%3A";
						tinyMCE.openWindow(template, {editor_id : editor_id, scrollbars :  
"yes", inline : "yes"});
						return false;
				}
			}

around line 269 ->
			function setTheValue(type,value,act) {
				switch(type){
					case "link":
						var prefixURL=getActivePagefromFilebrowser(act);
						var linkValue=value.split(" ");
						var linkURL=linkValue[0];
						var target=linkValue[1];
						var title = "";
						alert (linkValue);
						var _i = 2;
						while (_i < linkValue.length) {
							title += linkValue[_i++] + " ";
						}
						if(target.indexOf("x")!=-1) { // Opens the link in a window with  
window.open....
							var winProp=target.split("x");
							var  
klick="window.open(\'"+prefixURL+linkURL+"\',\'popup\',\'height="+winProp[0]+",width="+winProp[1]+"\')";
							linkURL="#_";
							tinyMCE.themes["advanced"]._insertLink(linkURL, "", title, klick);
						}
						else {
							tinyMCE.themes["advanced"]._insertLink(prefixURL+linkURL, target,  
title);
						}
						break;
					case "image":
						var imageProp=value.split("|");
						tinyMCE.themes["advanced"]._insertImage(imageProp[0], "", "", "",  
"", imageProp[1], imageProp[2], "", "", "", "");
						TBE_EDITOR_fieldChanged(\''.$table.'\',\''.$row["uid"].'\',\''.$field.'\',\'data['.$table.']['.$row["uid"].']['.$field.']\');
						break;
				}
			}

I'm sorry, I've changed too many lines. It works for me.
The last thing to do is to fix file links detection - it detects them as  
external links, but when you switch to file link they are displayed  
correctly.

regards, cyprian



More information about the TYPO3-english mailing list