/**
  * Implements the "typolink" property of stdWrap (and others)
  * Basically the input string, $linktext, is (typically) wrapped in a <a>-tag linking to some page, email address, file or URL based on a parameter defined by the configuration array $conf.
  * This function is best used from internal functions as is. There are some API functions defined after this function which is more suited for general usage in external applications.
  * Generally the concept "typolink" should be used in your own applications as an API for making links to pages with parameters and more. The reason for this is that you will then automatically make links compatible with all the centralized functions for URL simulation and manipulation of parameters into hashes and more.
  * For many more details on the parameters and how they are intepreted, please see the link to TSref below.
  *
  * @param string $linktxt The string (text) to link
  * @param array $conf TypoScript configuration (see link below)
  * @param tslib_cObj $cObj
  * @return	string		A link-wrapped string.
  * @see stdWrap(), tslib_pibase::pi_linkTP()
  * @link http://typo3.org/doc.0.html?&tx_extrepmgm_pi1[extUid]=270&tx_extrepmgm_pi1[tocEl]=321&cHash=59bd727a5e
  */
 function typoLink($linktxt, $conf, $cObj = NULL)
 {
     $finalTagParts = array();
     // If called from media link handler, use the reference of the passed cObj
     if (!is_object($this->cObj)) {
         $this->cObj = $cObj;
     }
     $link_param = trim($this->cObj->stdWrap($conf['parameter'], $conf['parameter.']));
     $initP = '?id=' . $GLOBALS['TSFE']->id . '&type=' . $GLOBALS['TSFE']->type;
     $this->cObj->lastTypoLinkUrl = '';
     $this->cObj->lastTypoLinkTarget = '';
     if ($link_param) {
         $link_paramA = t3lib_div::unQuoteFilenames($link_param, TRUE);
         $link_param = trim($link_paramA[0]);
         // Link parameter value
         $linkClass = trim($link_paramA[2]);
         // Link class
         if ($linkClass === '-') {
             $linkClass = '';
         }
         // The '-' character means 'no class'. Necessary in order to specify a title as fourth parameter without setting the target or class!
         $forceTarget = trim($link_paramA[1]);
         // Target value
         $forceTitle = trim($link_paramA[3]);
         // Title value
         if ($forceTarget === '-') {
             $forceTarget = '';
         }
         // The '-' character means 'no target'. Necessary in order to specify a class as third parameter without setting the target!
         // Check, if the target is coded as a JS open window link:
         $JSwindowParts = array();
         $JSwindowParams = '';
         $onClick = '';
         if ($forceTarget && preg_match('/^([0-9]+)x([0-9]+)(:(.*)|.*)$/', $forceTarget, $JSwindowParts)) {
             // Take all pre-configured and inserted parameters and compile parameter list, including width+height:
             $JSwindow_tempParamsArr = t3lib_div::trimExplode(',', strtolower($conf['JSwindow_params'] . ',' . $JSwindowParts[4]), TRUE);
             $JSwindow_paramsArr = array();
             foreach ($JSwindow_tempParamsArr as $JSv) {
                 list($JSp, $JSv) = explode('=', $JSv);
                 $JSwindow_paramsArr[$JSp] = $JSp . '=' . $JSv;
             }
             // Add width/height:
             $JSwindow_paramsArr['width'] = 'width=' . $JSwindowParts[1];
             $JSwindow_paramsArr['height'] = 'height=' . $JSwindowParts[2];
             // Imploding into string:
             $JSwindowParams = implode(',', $JSwindow_paramsArr);
             $forceTarget = '';
             // Resetting the target since we will use onClick.
         }
         // Internal target:
         $target = isset($conf['target']) ? $conf['target'] : $GLOBALS['TSFE']->intTarget;
         if ($conf['target.']) {
             $target = $this->cObj->stdWrap($target, $conf['target.']);
         }
         // Checking if the id-parameter is an alias.
         if (version_compare(TYPO3_version, '4.6.0', '>=')) {
             $isInteger = t3lib_utility_Math::canBeInterpretedAsInteger($link_param);
         } else {
             $isInteger = t3lib_div::testInt($link_param);
         }
         if (!$isInteger) {
             $GLOBALS['TT']->setTSlogMessage("tx_dam_tsfemediatag->typolink(): File id '" . $link_param . "' is not an integer, so '" . $linktxt . "' was not linked.", 1);
             return $linktxt;
         }
         if (!is_object($media = tx_dam::media_getByUid($link_param))) {
             $GLOBALS['TT']->setTSlogMessage("tx_dam_tsfemediatag->typolink(): File id '" . $link_param . "' was not found, so '" . $linktxt . "' was not linked.", 1);
             return $linktxt;
         }
         if (!$media->isAvailable) {
             $GLOBALS['TT']->setTSlogMessage("tx_dam_tsfemediatag->typolink(): File '" . $media->getPathForSite() . "' (" . $link_param . ") did not exist, so '" . $linktxt . "' was not linked.", 1);
             return $linktxt;
         }
         $meta = $media->getMetaArray();
         if (is_array($this->conf['procFields.'])) {
             foreach ($this->conf['procFields.'] as $field => $fieldConf) {
                 if (substr($field, -1, 1) === '.') {
                     $fN = substr($field, 0, -1);
                 } else {
                     $fN = $field;
                     $fieldConf = array();
                 }
                 $meta[$fN] = $media->getContent($fN, $fieldConf);
             }
         }
         $this->addMetaToData($meta);
         // Title tag
         $title = $conf['title'];
         if ($conf['title.']) {
             $title = $this->cObj->stdWrap($title, $conf['title.']);
         }
         // Setting title if blank value to link:
         if ($linktxt === '') {
             $linktxt = $media->getContent('title');
         }
         if ($GLOBALS['TSFE']->config['config']['jumpurl_enable']) {
             $this->cObj->lastTypoLinkUrl = $GLOBALS['TSFE']->absRefPrefix . $GLOBALS['TSFE']->config['mainScript'] . $initP . '&jumpurl=' . rawurlencode($media->getPathForSite()) . $GLOBALS['TSFE']->getMethodUrlIdToken;
         } else {
             $this->cObj->lastTypoLinkUrl = $media->getURL();
         }
         if ($forceTarget) {
             $target = $forceTarget;
         }
         $this->cObj->lastTypoLinkTarget = $target;
         $finalTagParts['url'] = $this->cObj->lastTypoLinkUrl;
         $finalTagParts['targetParams'] = $target ? ' target="' . $target . '"' : '';
         $finalTagParts['aTagParams'] = $this->cObj->getATagParams($conf);
         $finalTagParts['TYPE'] = 'file';
         if ($forceTitle) {
             $title = $forceTitle;
         }
         if ($JSwindowParams) {
             // Create TARGET-attribute only if the right doctype is used
             if (!t3lib_div::inList('xhtml_strict,xhtml_11,xhtml_2', $GLOBALS['TSFE']->xhtmlDoctype)) {
                 $target = ' target="FEopenLink"';
             } else {
                 $target = '';
             }
             $onClick = "vHWin=window.open('" . $GLOBALS['TSFE']->baseUrlWrap($finalTagParts['url']) . "','FEopenLink','" . $JSwindowParams . "');vHWin.focus();return false;";
             $res = '<a href="' . htmlspecialchars($finalTagParts['url']) . '"' . $target . ' onclick="' . htmlspecialchars($onClick) . '"' . ($title ? ' title="' . $title . '"' : '') . ($linkClass ? ' class="' . $linkClass . '"' : '') . $finalTagParts['aTagParams'] . '>';
         } else {
             $res = '<a href="' . htmlspecialchars($finalTagParts['url']) . '"' . ($title ? ' title="' . $title . '"' : '') . $finalTagParts['targetParams'] . ($linkClass ? ' class="' . $linkClass . '"' : '') . $finalTagParts['aTagParams'] . '>';
         }
         // Call userFunc
         if ($conf['userFunc']) {
             $finalTagParts['TAG'] = $res;
             $res = $this->cObj->callUserFunction($conf['userFunc'], $conf['userFunc.'], $finalTagParts);
         }
         // If flag "returnLastTypoLinkUrl" set, then just return the latest URL made:
         if ($conf['returnLast']) {
             switch ($conf['returnLast']) {
                 case 'url':
                     return $this->cObj->lastTypoLinkUrl;
                     break;
                 case 'target':
                     return $this->cObj->lastTypoLinkTarget;
                     break;
             }
         }
         if ($conf['postUserFunc']) {
             $linktxt = $this->cObj->callUserFunction($conf['postUserFunc'], $conf['postUserFunc.'], $linktxt);
         }
         if ($conf['ATagBeforeWrap']) {
             return $res . $this->cObj->wrap($linktxt, $conf['wrap']) . '</a>';
         } else {
             return $this->cObj->wrap($res . $linktxt . '</a>', $conf['wrap']);
         }
     } else {
         return $linktxt;
     }
 }
 /**
  * Fetches the current element
  *
  * @return	boolean
  */
 function _fetchCurrent()
 {
     if (isset($this->res[$this->currentPointer])) {
         $uid = intval($this->res[$this->currentPointer]);
         unset($this->media);
         $this->media = tx_dam::media_getByUid($uid);
         $this->currentData = $this->media->getMetaInfoArray();
         if ($this->media->isAvailable) {
             // TODO use tx_dam_media
             if (!is_null($this->currentData) and $this->table and $this->mode === 'FE') {
                 $this->currentData = tx_dam_db::getRecordOverlay($this->table, $this->currentData, array(), $this->mode);
             }
         }
         if ($this->conf['callbackFunc_currentData'] and is_callable($this->conf['callbackFunc_currentData'])) {
             call_user_func($this->conf['callbackFunc_currentData'], $this);
         }
     } else {
         unset($this->media);
         $this->currentData = NULL;
     }
 }
Пример #3
0
 public function formatValue($mValue)
 {
     if (t3lib_extmgm::isLoaded("dam")) {
         if (is_numeric($mValue)) {
             $oMedia = tx_dam::media_getByUid($mValue);
             return $oMedia->meta['file_name'];
         }
     }
     return $mValue;
 }
 /**
  * Rendering the "txdam" custom attribute on img tag, called from TypoScript
  *
  * @param	string		Content input. Not used, ignore.
  * @param	array		TypoScript configuration
  * @return	string		Unmodified content input
  * @access private
  */
 function renderTxdamAttribute($content, $conf)
 {
     global $TYPO3_CONF_VARS;
     $mediaId = isset($this->cObj->parameters['txdam']) ? $this->cObj->parameters['txdam'] : 0;
     if ($mediaId) {
         if (!is_object($media = tx_dam::media_getByUid($mediaId))) {
             $GLOBALS['TT']->setTSlogMessage("tx_dam_tsfeimgtag->renderTxdamAttribute(): File id '" . $mediaId . "' was not found, so '" . $content . "' was not updated.", 1);
             return $content;
         }
         $metaInfo = $media->getMetaArray();
         $magicPathPrefix = $TYPO3_CONF_VARS['BE']['RTE_imageStorageDir'] . 'RTEmagicC_';
         if (t3lib_div::isFirstPartOfStr($this->cObj->parameters['src'], $magicPathPrefix)) {
             // Process magic image
             $pI = pathinfo(substr($this->cObj->parameters['src'], strlen($magicPathPrefix)));
             $fileName = preg_replace('/_[0-9][0-9]' . preg_quote('.') . '/', '.', substr($pI['basename'], 0, -strlen('.' . $pI['extension'])));
             if ($fileName != $metaInfo['file_name']) {
                 // Substitute magic image
                 $imgObj = t3lib_div::makeInstance('t3lib_stdGraphic');
                 $imgObj->init();
                 $imgObj->mayScaleUp = 0;
                 $imgObj->tempPath = PATH_site . $imgObj->tempPath;
                 $imgInfo = $imgObj->getImageDimensions(PATH_site . $metaInfo['file_path'] . $metaInfo['file_name']);
                 if (is_array($imgInfo) && count($imgInfo) == 4 && $TYPO3_CONF_VARS['BE']['RTE_imageStorageDir']) {
                     // Create or update the reference and magic images
                     $fileInfo = pathinfo($imgInfo[3]);
                     $fileFunc = t3lib_div::makeInstance('t3lib_basicFileFunctions');
                     // Construct a name based on the mediaId and on the width and height of the magic image
                     $basename = $fileFunc->cleanFileName('RTEmagicP_' . $fileInfo['filename'] . '_txdam' . $this->cObj->parameters['txdam'] . '_' . substr(md5($this->cObj->parameters['width'] . 'x' . $this->cObj->parameters['height']), 0, $fileFunc->uniquePrecision) . '.' . $fileInfo['extension']);
                     $destPath = PATH_site . $TYPO3_CONF_VARS['BE']['RTE_imageStorageDir'];
                     if (@is_dir($destPath)) {
                         // Do not check file uniqueness in order to avoid creating a new one on every rendering
                         $destName = $fileFunc->getUniqueName($basename, $destPath, 1);
                         if (!@is_file($destName)) {
                             @copy($imgInfo[3], $destName);
                             t3lib_div::fixPermissions($destName);
                         }
                         $magicImageInfo = $imgObj->imageMagickConvert($destName, 'WEB', $this->cObj->parameters['width'] . 'm', $this->cObj->parameters['height'] . 'm');
                         if ($magicImageInfo[3]) {
                             $fileInfo = pathinfo($magicImageInfo[3]);
                             $mainBase = 'RTEmagicC_' . substr(basename($destName), 10) . '.' . $fileInfo['extension'];
                             $destName = $fileFunc->getUniqueName($mainBase, $destPath, 1);
                             if (!@is_file($destName)) {
                                 @copy($magicImageInfo[3], $destName);
                                 t3lib_div::fixPermissions($destName);
                             }
                             $destName = dirname($destName) . '/' . rawurlencode(basename($destName));
                             $this->cObj->parameters['src'] = substr($destName, strlen(PATH_site));
                         }
                     }
                 }
             }
         } else {
             // Substitute plain image, if needed
             if ($this->cObj->parameters['src'] != $metaInfo['file_path'] . $metaInfo['file_name']) {
                 $this->cObj->parameters['src'] = $metaInfo['file_path'] . $metaInfo['file_name'];
             }
         }
     }
     $parametersForAttributes = $this->cObj->parameters;
     unset($parametersForAttributes['txdam']);
     unset($parametersForAttributes['allParams']);
     $content = '<img ' . t3lib_div::implodeAttributes($parametersForAttributes, TRUE, TRUE) . ' />';
     return $content;
 }
 /**
  * tx_dam::media_getByUid()
  */
 public function test_media_getByUid()
 {
     $fixture = $this->getFixtureRandomIndexedFilename();
     $filename = $fixture['filename'];
     $meta = $fixture['meta'];
     $media = tx_dam::media_getByUid($meta['uid']);
     self::assertTrue(is_object($media), 'Object not created for ' . $filename);
     self::assertTrue($media->isIndexed);
 }
 /**
  *
  * @return mixed Is false when no indexed file available or: array('meta' => $row, 'filename' => $filename)
  */
 protected function getFixtureMedia()
 {
     if ($fixture = $this->getFixtureRandomIndexedFilename()) {
         $fixture['media'] = tx_dam::media_getByUid($fixture['meta']['uid']);
     }
     return $fixture;
 }
Пример #7
0
    /**
     * Main function of the module. Write the content to $this->content
     *
     * @return	void
     */
    function main()
    {
        global $BE_USER, $LANG, $BACK_PATH, $TYPO3_CONF_VARS, $HTTP_GET_VARS, $HTTP_POST_VARS;
        $access = false;
        $this->errorMessages = array();
        $this->media = NULL;
        $editorList = array();
        $this->actionTarget = $this->actionTarget ? $this->actionTarget : t3lib_div::linkThisScript(array('returnUrl' => $this->returnUrl, 'redirect' => $this->redirect));
        //
        // get media that should be edited
        //
        if ($this->file) {
            foreach ($this->file as $key => $filename) {
                if (!tx_dam::access_checkFile($filename)) {
                    $this->errorMessages['file'][] = tx_dam::file_normalizePath($filename);
                    unset($this->file[$key]);
                }
            }
            if ($this->file) {
                $this->media = tx_dam::media_getForFile($this->file[0]);
                if (!$this->media->isAvailable) {
                    $this->errorMessages['file'][] = $this->media->filename;
                    unset($this->media);
                }
            }
        } elseif ($this->record and $this->defaultPid) {
            foreach ($this->record as $table => $uidList) {
                $where = array();
                $where['enableFields'] = tx_dam_db::deleteClause($table);
                $where['pidList'] = $table . '.pid IN (' . $this->defaultPid . ')';
                $where['uid'] = $table . '.uid IN (' . implode(',', $uidList) . ')';
                $rows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('uid', $table, implode(' AND ', $where), '', '', '', 'uid');
                if ($rows) {
                    $this->record[$table] = array_keys($rows);
                } else {
                    $this->errorMessages['record'][$table] = $uidList;
                    unset($this->record[$table]);
                }
            }
            if ($this->record['tx_dam']) {
                // reduce passed files/records to just one item
                // it will be done here because later editors might want to get multiple resources (eg. blending images) so we keep the infrastructure
                reset($this->record['tx_dam']);
                // just one uid
                $uid = current($this->record['tx_dam']);
                $this->media = tx_dam::media_getByUid($uid);
                if (!$this->media->isAvailable) {
                    $this->errorMessages['file'][] = $this->media->filename;
                    unset($this->media);
                }
            }
        }
        $access = ($this->hasExtObjDefined() or is_object($this->media));
        //
        // Main
        //
        // a valid file is selected
        if ($access) {
            $success = false;
            // an editor is not already defined by CMD
            if (!$this->hasExtObjDefined() and is_object($this->media)) {
                if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['dam']['editorClasses'])) {
                    foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['dam']['editorClasses'] as $idName => $classRessource) {
                        if (is_object($editorList[$idName] = t3lib_div::getUserObj($classRessource))) {
                            if (!$editorList[$idName]->isValid($this->media)) {
                                unset($editorList[$idName]);
                            }
                        }
                    }
                }
                if (!count($editorList)) {
                    // error message no valid editor found for file
                    $this->errorMessages['error'][] = sprintf($LANG->getLL('messageNoEditorFound', 1), $this->media->filename);
                } elseif (count($editorList) == 1) {
                    // activate extObj
                    $this->errorMessages['error'][] = 'TODO: activate extObj';
                    if (!$this->CMD) {
                        $this->CMD = key($editorList);
                    }
                    $this->handleExternalFunctionValue('function', $this->CMD);
                }
                // selection of multiple editors is below
            }
            // an editor is selected
            if ($this->hasExtObjDefined()) {
                $this->checkExtObj();
                // Checking for first level external objects
                $this->checkSubExtObj();
                // Checking second level external objects
            }
            if (is_object($this->extObj)) {
                $this->extObjCmdInit();
                //
                // Initialize the template object
                //
                if (!is_object($this->doc)) {
                    $this->doc = t3lib_div::makeInstance('template');
                    $this->doc->backPath = $BACK_PATH;
                    $this->doc->setModuleTemplate(t3lib_extMgm::extRelPath('dam') . 'res/templates/mod_edit.html');
                    $this->doc->styleSheetFile2 = t3lib_extMgm::extRelPath('dam') . 'res/css/stylesheet.css';
                    $this->doc->docType = 'xhtml_trans';
                }
                //
                // check access
                //
                $this->actionAccess = $this->extObjAccess();
                if ($access and $this->actionAccess) {
                    $success = true;
                    //
                    // Output page header
                    //
                    $this->doc->form = '<form action="' . htmlspecialchars($this->actionTarget) . '" method="post" name="editform" enctype="' . $TYPO3_CONF_VARS['SYS']['form_enctype'] . '">';
                    $this->doc->form .= '<input type="hidden" name="CMD" value="' . $this->CMD . '" />';
                    // JavaScript
                    $this->doc->JScodeArray['jumpToUrl'] = '
						var script_ended = 0;
						var changed = 0;
		
						function jumpToUrl(URL)	{
							document.location.href = URL;
						}
		
						function jumpBack()	{
							document.location.href = "' . htmlspecialchars($this->redirect) . '";
						}
		
						function navFrameReload() {
							if (top.content && top.content.nav_frame && top.content.nav_frame.refresh_nav)	{
								// top.content.nav_frame.refresh_nav();
							}
						}
						';
                    $this->doc->postCode .= $this->doc->wrapScriptTags('
						script_ended = 1;');
                    $this->makePageHeader();
                    //
                    // Call submodule function
                    //
                    $this->extObjContent();
                    $this->markers['CONTENT'] = $this->content;
                } else {
                    $access = false;
                    $this->errorMessages['error'][] = sprintf($LANG->getLL('messageCmdDenied', true), $this->pageTitle);
                }
            }
        }
        if (!is_object($this->doc)) {
            $this->doc = t3lib_div::makeInstance('template');
            $this->doc->backPath = $BACK_PATH;
            $this->doc->setModuleTemplate(t3lib_extMgm::extRelPath('dam') . 'res/templates/mod_edit.html');
            $this->doc->styleSheetFile2 = t3lib_extMgm::extRelPath('dam') . 'res/css/stylesheet.css';
            $this->doc->docType = 'xhtml_trans';
        }
        // provide a selector when multiple editors are available
        if ($access and count($editorList) > 1) {
            $this->makePageHeader();
            $messages = array();
            $messages[] = '<div style="margin: 1em 3em 2em 3em;">' . sprintf($LANG->getLL('messageAvailableEditors', true), $this->media->filename) . '</div>';
            $messages[] = '<div style="padding-left:3em; display:table-cell">';
            foreach ($editorList as $idName => $editorObj) {
                $button = $this->button($editorObj->getIcon(), $editorObj->getLabel(), $editorObj->getDescription(), $this->actionTarget . '&CMD=' . $idName, '', ' style="display:block;"');
                $messages[] = '<div style="margin-bottom:0.8em">' . $button . '</div>';
            }
            $messages[] = '</div>';
            $this->content .= $GLOBALS['SOBE']->getMessageBox($this->pageTitle, $messages, $this->buttonBack(0), 2);
            $success = true;
        }
        if (!$access or !$success) {
            // If no access
            $this->makePageHeader();
            $messages = array();
            foreach ($this->errorMessages as $type => $items) {
                if ($items) {
                    if ($type !== 'error' and $headerText = $LANG->getLL($type, 1)) {
                        $messages[] = '<h4>' . $LANG->getLL($type, true) . '</h4>';
                    }
                    foreach ($items as $item) {
                        $messages[] = '<p>' . htmlspecialchars($item) . '</p>';
                    }
                }
            }
            // file do not exist ...
            if (!$access) {
                $this->content .= $this->accessDeniedMessageBox(implode('', $messages));
            } else {
                $this->content .= $this->errorMessageBox(implode('', $messages));
            }
        }
    }