📄 class.tx_rtehtmlarea_dam_browse_media.php
字号:
<?php/**************************************************************** Copyright notice** (c) 1999-2004 Kasper Skaarhoj (kasper@typo3.com)* (c) 2004-2006 Stanislas Rolland <stanislas.rolland(arobas)fructifor.ca>* All rights reserved** This script is part of the TYPO3 project. The TYPO3 project is* free software; you can redistribute it and/or modify* it under the terms of the GNU General Public License as published by* the Free Software Foundation; either version 2 of the License, or* (at your option) any later version.** The GNU General Public License can be found at* http://www.gnu.org/copyleft/gpl.html.* A copy is found in the textfile GPL.txt and important notices to the license* from the author is found in LICENSE.txt distributed with these scripts.*** This script is distributed in the hope that it will be useful,* but WITHOUT ANY WARRANTY; without even the implied warranty of* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the* GNU General Public License for more details.** This copyright notice MUST APPEAR in all copies of the script!***************************************************************//** * Displays image selector for the RTE * * @author Kasper Skaarhoj <kasper@typo3.com> * @author Stanislas Rolland <stanislas.rolland(arobas)fructifor.ca> * * $Id: class.tx_rtehtmlarea_dam_browse_media.php 1462 2006-05-05 20:35:09Z stanrolland $ * */require_once(PATH_t3lib.'class.t3lib_stdgraphic.php');require_once(PATH_t3lib.'class.t3lib_basicfilefunc.php');require_once(t3lib_extMgm::extPath('dam').'class.tx_dam_browse_media.php');/** * Script Class * * @author Kasper Skaarhoj <kasper@typo3.com> * @package TYPO3 * @subpackage tx_rte */class tx_rtehtmlarea_dam_browse_media extends tx_dam_browse_media { var $extKey = 'rtehtmlarea'; var $content; var $act; var $allowedItems; var $plainMaxWidth; var $plainMaxHeight; var $magicMaxWidth; var $magicMaxHeight; var $imgPath; var $imgTitleDAMColumn = ''; var $classesImageJSOptions; var $editorNo; var $sys_language_content; var $buttonConfig = array(); /** * Check if this object should be rendered. * * @param string $type Type: "file", ... * @param object $pObj Parent object. * @return boolean * @see SC_browse_links::main() */ function isValid($type, &$pObj) { $isValid = false; $pArr = explode('|', t3lib_div::_GP('bparams')); if ($type=='rte' && $pObj->button == 'image') { $isValid = true; } return $isValid; } /** * Rendering * Called in SC_browse_links::main() when isValid() returns true; * * @param string $type Type: "file", ... * @param object $pObj Parent object. * @return string Rendered content * @see SC_browse_links::main() */ function render($type, &$pObj) { global $LANG, $BE_USER, $BACK_PATH; $this->pObj = &$pObj; // init class browse_links $this->init(); switch((string)$this->mode) { case 'rte': $content = $this->main_rte(); break;// case 'wizard':// $content = $this->main_rte(1);// break; default: $content = ''; break; } return $content; } /** * Initialisation * * @return [type] ... */ function init() { global $BE_USER,$BACK_PATH,$TYPO3_CONF_VARS; // Main GPvars: $this->siteUrl = t3lib_div::getIndpEnv('TYPO3_SITE_URL'); $this->act = t3lib_div::_GP('act'); $this->expandPage = t3lib_div::_GP('expandPage'); $this->expandFolder = t3lib_div::_GP('expandFolder'); // Find RTE parameters $this->bparams = t3lib_div::_GP('bparams'); $this->editorNo = t3lib_div::_GP('editorNo'); $this->sys_language_content = t3lib_div::_GP('sys_language_content'); $this->RTEtsConfigParams = t3lib_div::_GP('RTEtsConfigParams'); if (!$this->editorNo) { $pArr = explode('|', $this->bparams); $pRteArr = explode(':', $pArr[1]); $this->editorNo = $pRteArr[0]; $this->sys_language_content = $pRteArr[1]; $this->RTEtsConfigParams = $pArr[2]; } // Find "mode" $this->mode = t3lib_div::_GP('mode'); if (!$this->mode) { $this->mode='rte'; } // Site URL $this->siteURL = t3lib_div::getIndpEnv('TYPO3_SITE_URL'); // Current site url // the script to link to $this->thisScript = t3lib_div::getIndpEnv('SCRIPT_NAME'); if (!$this->act) { $this->act='magic'; } $RTEtsConfigParts = explode(':', $this->RTEtsConfigParams); $RTEsetup = $BE_USER->getTSConfig('RTE',t3lib_BEfunc::getPagesTSconfig($RTEtsConfigParts[5])); $this->thisConfig = t3lib_BEfunc::RTEsetup($RTEsetup['properties'],$RTEtsConfigParts[0],$RTEtsConfigParts[2],$RTEtsConfigParts[4]); $this->imgPath = $RTEtsConfigParts[6]; if (is_array($this->thisConfig['buttons.']) && is_array($this->thisConfig['buttons.']['image.'])) { $this->buttonConfig = $this->thisConfig['buttons.']['image.']; } $this->allowedItems = explode(',','magic,plain,dragdrop,image,upload'); if (is_array($this->buttonConfig['options.']) && $this->buttonConfig['options.']['removeItems']) { $this->allowedItems = array_diff($this->allowedItems,t3lib_div::trimExplode(',',$this->buttonConfig['options.']['removeItems'],1)); } else { $this->allowedItems = array_diff($this->allowedItems,t3lib_div::trimExplode(',',$this->thisConfig['blindImageOptions'],1)); } reset($this->allowedItems); if (!in_array($this->act,$this->allowedItems)) { $this->act = current($this->allowedItems); } if ($this->act == 'magic') { if (is_array($this->buttonConfig['options.']) && is_array($this->buttonConfig['options.']['magic.'])) { if ($this->buttonConfig['options.']['magic.']['maxWidth']) $this->magicMaxWidth = $this->buttonConfig['options.']['magic.']['maxWidth']; if ($this->buttonConfig['options.']['magic.']['maxHeight']) $this->magicMaxHeight = $this->buttonConfig['options.']['magic.']['maxHeight']; } // These defaults allow images to be based on their width - to a certain degree - by setting a high height. Then we're almost certain the image will be based on the width if (!$this->magicMaxWidth) $this->magicMaxWidth = 300; if (!$this->magicMaxHeight) $this->magicMaxHeight = 1000; } elseif ($this->act == 'plain') { if ($TYPO3_CONF_VARS['EXTCONF'][$this->extKey]['plainImageMaxWidth']) $this->plainMaxWidth = $TYPO3_CONF_VARS['EXTCONF'][$this->extKey]['plainImageMaxWidth']; if ($TYPO3_CONF_VARS['EXTCONF'][$this->extKey]['plainImageMaxHeight']) $this->plainMaxHeight = $TYPO3_CONF_VARS['EXTCONF'][$this->extKey]['plainImageMaxHeight']; if (is_array($this->buttonConfig['options.']) && is_array($this->buttonConfig['options.']['plain.'])) { if ($this->buttonConfig['options.']['plain.']['maxWidth']) $this->plainMaxWidth = $this->buttonConfig['options.']['plain.']['maxWidth']; if ($this->buttonConfig['options.']['plain.']['maxHeight']) $this->plainMaxHeight = $this->buttonConfig['options.']['plain.']['maxHeight']; } if (!$this->plainMaxWidth) $this->plainMaxWidth = 640; if (!$this->plainMaxHeight) $this->plainMaxHeight = 680; } if ($this->thisConfig['classesImage']) { $classesImageArray = t3lib_div::trimExplode(',',$this->thisConfig['classesImage'],1); $this->classesImageJSOptions = '<option value=""></option>'; reset($classesImageArray); while(list(,$class)=each($classesImageArray)) { $this->classesImageJSOptions .= '<option value="' .$class . '">' . $class . '</option>'; } } // init the DAM object $this->initDAM(); $this->getModSettings(); $this->processParams(); // Insert the image if we are done $this->imageInsert(); // Creating backend template object: $this->doc = t3lib_div::makeInstance('template'); $this->doc->docType= 'xhtml_trans'; $this->doc->backPath = $BACK_PATH; $this->getJSCode(); } /** * [Describe function...] * * @return [type] ... */ function rteImageStorageDir() { $dir = $this->imgPath ? $this->imgPath : $GLOBALS['TYPO3_CONF_VARS']['BE']['RTE_imageStorageDir'];; return $dir; } /** * [Describe function...] * * @return [type] ... */ function imageInsert() { global $TCA,$TYPO3_CONF_VARS; if (t3lib_div::_GP('insertImage')) { $filepath = t3lib_div::_GP('insertImage'); $imgObj = t3lib_div::makeInstance('t3lib_stdGraphic'); $imgObj->init(); $imgObj->mayScaleUp=0; $imgObj->tempPath=PATH_site.$imgObj->tempPath; $imgInfo = $imgObj->getImageDimensions($filepath); t3lib_div::loadTCA('tx_dam'); if (is_array($this->buttonConfig['title.']) && is_array($TCA['tx_dam']['columns'][$this->buttonConfig['title.']['useDAMColumn']])) { $this->imgTitleDAMColumn = $this->buttonConfig['title.']['useDAMColumn']; } if (!$this->imgTitleDAMColumn) $this->imgTitleDAMColumn = 'caption'; $imgMetaData = tx_dam::meta_getDataForFile($filepath,'uid,pid,alt_text,hpixels,vpixels,'.$this->imgTitleDAMColumn.','.$TCA['tx_dam']['ctrl']['languageField']); $imgMetaData = $this->getRecordOverlay('tx_dam',$imgMetaData,$this->sys_language_content); switch ($this->act) { case 'magic': if (is_array($imgInfo) && count($imgInfo)==4 && $this->rteImageStorageDir() && is_array($imgMetaData)) { $fI=pathinfo($imgInfo[3]); $fileFunc = t3lib_div::makeInstance('t3lib_basicFileFunctions'); $basename = $fileFunc->cleanFileName('RTEmagicP_'.$fI['basename']); $destPath =PATH_site.$this->rteImageStorageDir(); if (@is_dir($destPath)) { $destName = $fileFunc->getUniqueName($basename,$destPath); @copy($imgInfo[3],$destName); $cWidth = t3lib_div::intInRange(t3lib_div::_GP('cWidth'),0,$this->magicMaxWidth); $cHeight = t3lib_div::intInRange(t3lib_div::_GP('cHeight'),0,$this->magicMaxHeight); if (!$cWidth) $cWidth = $this->magicMaxWidth; if (!$cHeight) $cHeight = $this->magicMaxHeight; $imgI = $imgObj->imageMagickConvert($filepath,'WEB',$cWidth.'m',$cHeight.'m'); // ($imagefile,$newExt,$w,$h,$params,$frame,$options,$mustCreate=0) if ($imgI[3]) { $fI=pathinfo($imgI[3]); $mainBase='RTEmagicC_'.substr(basename($destName),10).'.'.$fI['extension']; $destName = $fileFunc->getUniqueName($mainBase,$destPath); @copy($imgI[3],$destName); $iurl = $this->siteUrl.substr($destName,strlen(PATH_site)); $this->imageInsertJS($iurl,$imgI[0],$imgI[1],$imgMetaData['alt_text'],$imgMetaData[$this->imgTitleDAMColumn],substr($imgInfo[3],strlen(PATH_site))); } } } exit; break; case 'plain': if (is_array($imgInfo) && count($imgInfo)==4 && is_array($imgMetaData)) { $iurl = $this->siteUrl.substr($imgInfo[3],strlen(PATH_site)); $this->imageInsertJS($iurl,$imgMetaData['hpixels'],$imgMetaData['vpixels'],$imgMetaData['alt_text'],$imgMetaData[$this->imgTitleDAMColumn],substr($imgInfo[3],strlen(PATH_site))); } exit; break; } } } function imageInsertJS($url,$width,$height,$altText,$titleText,$origFile) { global $TYPO3_CONF_VARS; echo'<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html><head> <title>Untitled</title></head><script language="javascript" type="text/javascript">/*<![CDATA[*/ var editor = window.opener.RTEarea[' . $this->editorNo . ']["editor"]; var HTMLArea = window.opener.HTMLArea; function insertImage(file,width,height,alt,title,origFile) { var styleWidth, styleHeight; styleWidth = parseInt(width); if (isNaN(styleWidth) || styleWidth == 0) { styleWidth = "auto"; } else { styleWidth += "px"; } styleHeight = parseInt(height); if (isNaN(styleHeight) || styleHeight == 0) { styleHeight = "auto"; } else { styleHeight += "px";
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -