⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 plaintextlib.inc

📁 Typo3, 开源里边最强大的
💻 INC
📖 第 1 页 / 共 2 页
字号:
			}		}	}	/**	 * Function used to repeat a char pattern in head lines (like if you want "********" above/below a header)	 *	 * @param	array		Array of existing lines to which the new char-pattern should be added	 * @param	string		The character pattern to repeat. Default is "-"	 * @param	integer		The length of the line. $preLineChar will be repeated to fill in this length.	 * @return	array		The input array with a new line added.	 * @see renderHeader()	 */	function pad($lines,$preLineChar,$len)	{		$strPad = t3lib_div::intInRange($len,0,1000);		$strPadChar = $preLineChar?$preLineChar:'-';		if ($strPad)	{			$lines[]=str_pad('', $strPad, $strPadChar);		}		return $lines;	}	/**	 * Function used to wrap the bodytext field content (or image caption) into lines of a max length of	 *	 * @param	string		The content to break	 * @return	string		Processed value.	 * @see main_plaintext(), breakLines()	 */	function breakContent($str)	{		$cParts = explode(chr(10),$str);		reset($cParts);		$lines=array();		while(list(,$substrs)=each($cParts))	{			$lines[]=$this->breakLines($substrs);		}		return implode(chr(10),$lines);	}	/**	 * Breaks content lines into a bullet list	 *	 * @param	string		Content string to make into a bullet list	 * @return	string		Processed value	 */	function breakBulletlist($str)	{		$type = $this->cObj->data['layout'];		$type=t3lib_div::intInRange($type,0,3);		$tConf = $this->conf['bulletlist.'][$type.'.'];		$cParts = explode(chr(10),$str);		reset($cParts);		$lines=array();		$c=0;		while(list(,$substrs)=each($cParts))	{			$c++;			$bullet = $tConf['bullet'] ? $this->getString($tConf['bullet']) : ' - ';			$bLen=strlen($bullet);			$bullet = substr(str_replace('#',$c,$bullet),0,$bLen);			$secondRow = substr($tConf['secondRow']?$this->getString($tConf['secondRow']):str_pad('',strlen($bullet),' '),0,$bLen);			$lines[]=$bullet.$this->breakLines($substrs,chr(10).$secondRow,$this->charWidth-$bLen);			$blanks = t3lib_div::intInRange($tConf['blanks'],0,1000);			if ($blanks)	{$lines[]=str_pad('', $blanks-1, chr(10));}		}		return implode(chr(10),$lines);	}	/**	 * Formatting a table in plain text (based on the paradigm of lines being content rows and cells separated by "|")	 *	 * @param	string		Content string	 * @return	string		Processed value	 */	function breakTable($str)	{		$cParts = explode(chr(10),$str);		reset($cParts);		$lines=array();		$cols = intval($this->conf['cols']) ? intval($this->conf['cols']) : 0 ;		$c=0;		while(list(,$substrs)=each($cParts))	{			$c++;			if (trim($substrs))	{				$lineParts=explode('|',$substrs);				if (!$cols)	$cols=count($lineParts);				for ($a=0;$a<$cols;$a++)	{					$jdu = explode(chr(10),$this->breakLines($lineParts[$a],chr(10),ceil($this->charWidth/$cols)));					$lines[$c][$a]=$jdu;				}			}		}		$messure = $this->traverseTable($lines);		$divChar='-';		$joinChar='+';		$colChar='|';		// Make table:		$outLines = array();		$outLines[]=$this->addDiv($messure,'',$divChar,$joinChar,$cols);		reset($lines);		while(list($k,$v)=each($lines))	{			$top = intval($messure[1][$k]);			for ($aa=0;$aa<$top;$aa++)	{				$tempArr=array();				for ($bb=0;$bb<$cols;$bb++)	{					$tempArr[$bb]=str_pad($v[$bb][$aa],$messure[0][$bb],' ');				}				$outLines[]=$colChar.implode($colChar,$tempArr).$colChar;			}			$outLines[]=$this->addDiv($messure,'',$divChar,$joinChar,$cols);		}		return implode(chr(10),$outLines);	}	/**	 * Subfunction for breakTable(): Adds a divider line between table rows.	 *	 * @param	array		Some information about sizes	 * @param	string		Empty string.	 * @param	string		Character to use for the divider line, typically "-"	 * @param	string		Join character, typically "+"	 * @param	integer		Number of table columns	 * @return	string		Divider line for the table	 * @access private	 * @see breakTable()	 */	function addDiv($messure,$content,$divChar,$joinChar,$cols)	{		$tempArr=array();		for ($a=0;$a<$cols;$a++)	{			$tempArr[$a]=str_pad($content,$messure[0][$a],$divChar);		}		return $joinChar.implode($joinChar,$tempArr).$joinChar;	}	/**	 * Traverses the table lines/cells and creates arrays with statistics for line numbers and lengths	 *	 * @param	array		Array with [table rows] [table cells] [lines in cell]	 * @return	array		Statistics (max lines/lengths)	 * @access private	 * @see breakTable()	 */	function traverseTable($tableLines)	{		$maxLen=array();		$maxLines=array();		reset($tableLines);		while(list($k,$v)=each($tableLines))	{			reset($v);			while(list($kk,$vv)=each($v))	{				reset($vv);				while(list($lk,$lv)=each($vv))	{					if (strlen($lv)>intval($maxLen[$kk]))	$maxLen[$kk]=strlen($lv);				}				if (count($vv)>intval($maxLines[$k]))	$maxLines[$k]=count($vv);			}		}		return array($maxLen,$maxLines);	}	/**	 * Render block of images - which means creating lines with links to the images.	 *	 * @param	string		List of image filenames (from "image" field in tt_content records)	 * @param	string		Link value from the "image_link" field in tt_content records	 * @param	string		Caption text	 * @param	string		Alternative relative path for the files listed in $str	 * @return	string		Content	 * @see getImages()	 */	function renderImages($str,$links,$caption,$upload_path='uploads/pics/')	{		$images = explode(',',$str);		$linksArr = explode(',',$links);		reset($images);		$lines=array();		if ($this->conf['images.']['header'])	{$lines[]=$this->getString($this->conf['images.']['header']);}		while(list($k,$file)=each($images))	{			$lines[]=$this->siteUrl.$upload_path.$file;			if ($links && count($linksArr)>1)	{				if (isset($linksArr[$k]))	{					$ll=$linksArr[$k];				} else {					$ll=$linksArr[0];				}				$theLink = $this->getLink($ll);				if ($theLink)	{$lines[]=$this->getString($this->conf['images.']['linkPrefix']).$theLink;}			}		}		if ($links && count($linksArr)==1)	{			$theLink = $this->getLink($links);			if ($theLink)	{$lines[]=$this->getString($this->conf['images.']['linkPrefix']).$theLink;}		}		if ($caption)	{			$lines[]='';			$cHeader = trim($this->getString($this->conf['images.']['captionHeader']));			if ($cHeader)		$lines[]=$cHeader;			$lines[]=$this->breakContent($caption);		}		return implode(chr(10),$lines);	}	/**	 * Returns a typolink URL based on input.	 *	 * @param	string		Parameter to typolink	 * @return	string		The URL returned from $this->cObj->getTypoLink_URL(); - possibly it prefixed with the URL of the site if not present already	 */	function getLink($ll)	{		$theLink=$this->cObj->getTypoLink_URL($ll);		if (substr($theLink,0,4)!='http')	{			$theLink=$this->siteUrl.$theLink;		}		return $theLink;	}	/**	 * Breaking lines into fixed length lines, using t3lib_div::breakLinesForEmail()	 *	 * @param	string		The string to break	 * @param	string		Line break character	 * @param	integer		Length of lines, default is $this->charWidth	 * @return	string		Processed string	 * @see t3lib_div::breakLinesForEmail()	 */	function breakLines($str,$implChar="\n",$charWidth=0)	{		return t3lib_div::breakLinesForEmail($str,$implChar,$charWidth?$charWidth:$this->charWidth);	}	/**	 * Explodes a string with "|" and if the second part is found it will return this, otherwise the first part.	 * Used for many TypoScript properties used in this class since they need preceeding whitespace to be preserved.	 *	 * @param	string		Input string	 * @return	string		Output string	 * @access private	 */	function getString($str)	{		$parts = explode('|',$str);		return strcmp($parts[1],'')?$parts[1]:$parts[0];	}	/**	 * Calls a user function for processing of data	 *	 * @param	string		TypoScript property name, pointing to the definition of the user function to call (from the TypoScript array internally in this class). This array is passed to the user function. Notice that "parentObj" property is a reference to this class ($this)	 * @param	mixed		Variable to process	 * @return	mixed		The processed $passVar as returned by the function call	 */	function userProcess($mConfKey,$passVar)	{		if ($this->conf[$mConfKey])	{			$funcConf = $this->conf[$mConfKey.'.'];			$funcConf['parentObj']=&$this;			$passVar = $GLOBALS['TSFE']->cObj->callUserFunction($this->conf[$mConfKey], $funcConf, $passVar);		}		return $passVar;	}	/**	 * Function used by TypoScript "parseFunc" to process links in the bodytext.	 * Extracts the link and shows it in plain text in a parathesis next to the link text. If link was relative the site URL was prepended.	 *	 * @param	string		Empty, ignore.	 * @param	array		TypoScript parameters	 * @return	string		Processed output.	 * @see parseBody()	 */	function atag_to_http($content,$conf)	{		$this->conf = $conf;		$this->siteUrl=$conf['siteUrl'];		$theLink  = trim($this->cObj->parameters['href']);		if (strtolower(substr($theLink,0,7))=='mailto:')	{			$theLink=substr($theLink,7);		} elseif (substr($theLink,0,4)!='http')	{			$theLink=$this->siteUrl.$theLink;		}		return $this->cObj->getCurrentVal().' (Link: '.$theLink.' )';	}	/**	 * User function (called from TypoScript) for generating a bullet list (used in parsefunc)	 *	 * @param	string		Empty, ignore.	 * @param	array		TypoScript parameters	 * @return	string		Processed output.	 */	function typolist($content,$conf)	{		$this->conf = $this->cObj->mergeTSRef($conf,'bulletlist');		$this->siteUrl=$conf['siteUrl'];		$str = trim($this->cObj->getCurrentVal());		$this->cObj->data['layout'] = $this->cObj->parameters['type'];		return $this->breakBulletlist($str);	}	/**	 * User function (called from TypoScript) for generating a typo header tag (used in parsefunc)	 *	 * @param	string		Empty, ignore.	 * @param	array		TypoScript parameters	 * @return	string		Processed output.	 */	function typohead($content,$conf)	{		$this->conf = $this->cObj->mergeTSRef($conf,'header');		$this->siteUrl=$conf['siteUrl'];		$str = trim($this->cObj->getCurrentVal());		$this->cObj->data['header_layout'] = $this->cObj->parameters['type'];		$this->cObj->data['header_position'] = $this->cObj->parameters['align'];		$this->cObj->data['header']=$str;		return $this->getHeader();	}	/**	 * User function (called from TypoScript) for generating a code listing (used in parsefunc)	 *	 * @param	string		Empty, ignore.	 * @param	array		TypoScript parameters	 * @return	string		Processed output.	 */	function typocode($content,$conf)	{			// Nothing is really done here...		$this->conf = $conf;		$this->siteUrl=$conf['siteUrl'];		return $this->cObj->getCurrentVal();	}}if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['media/scripts/plaintextLib.inc'])	{	include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['media/scripts/plaintextLib.inc']);}?>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -