/** * tx_dam::meta_getDataByUid() */ public function test_meta_getDataByUid() { $fixture = $this->getFixtureRandomIndexedFilename(); $filename = $fixture['filename']; $meta = $fixture['meta']; $data = tx_dam::meta_getDataByUid($meta['uid']); self::assertEquals($data['file_name'], $meta['file_name'], 'Wrong index for ' . $filename); }
/** * Transformation handler: 'txdam_media' / direction: "rte" * Processing linked images from database content going into the RTE. * Processing includes converting the src attribute to an absolute URL. * * @param string Content input * @return string Content output */ function transform_rte($value, &$pObj) { // Split content by the TYPO3 pseudo tag "<media>": $blockSplit = $pObj->splitIntoBlock('media', $value, 1); foreach ($blockSplit as $k => $v) { $error = ''; if ($k % 2) { // block: $tagCode = t3lib_div::unQuoteFilenames(trim(substr($pObj->getFirstTag($v), 0, -1)), true); $link_param = $tagCode[1]; $href = ''; $useDAMColumn = FALSE; // Checking if the id-parameter is int and get meta data if (t3lib_div::testInt($link_param)) { $meta = tx_dam::meta_getDataByUid($link_param); } if (is_array($meta)) { $href = tx_dam::file_url($meta); if (!$tagCode[4]) { require_once PATH_txdam . 'lib/class.tx_dam_guifunc.php'; $displayItems = ''; if (t3lib_div::inList($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['rtehtmlarea']['plugins']['TYPO3Link']['additionalAttributes'], 'usedamcolumn') && $pObj->thisConfig['buttons.']['link.']['media.']['properties.']['title.']['useDAMColumn']) { $displayItems = $pObj->thisConfig['buttons.']['link.']['media.']['properties.']['title.']['useDAMColumn.']['displayItems'] ? $pObj->thisConfig['buttons.']['link.']['media.']['properties.']['title.']['useDAMColumn.']['displayItems'] : ''; $useDAMColumn = TRUE; } $tagCode[4] = tx_dam_guiFunc::meta_compileHoverText($meta, $displayItems, ', '); } } else { $href = $link_param; $error = 'No media file found: ' . $link_param; } // Setting the A-tag: $bTag = '<a href="' . htmlspecialchars($href) . '" txdam="' . htmlspecialchars($link_param) . '"' . ($tagCode[2] && $tagCode[2] != '-' ? ' target="' . htmlspecialchars($tagCode[2]) . '"' : '') . ($tagCode[3] && $tagCode[3] != '-' ? ' class="' . htmlspecialchars($tagCode[3]) . '"' : '') . ($tagCode[4] ? ' title="' . htmlspecialchars($tagCode[4]) . '"' : '') . ($useDAMColumn ? ' usedamcolumn="true"' : '') . ($error ? ' rteerror="' . htmlspecialchars($error) . '" style="background-color: yellow; border:2px red solid; color: black;"' : '') . '>'; $eTag = '</a>'; $blockSplit[$k] = $bTag . $this->transform_rte($pObj->removeFirstAndLastTag($blockSplit[$k]), $pObj) . $eTag; } } $value = implode('', $blockSplit); return $value; }
/** * tx_dam::index_process() */ public function test_index_process() { $this->removeIndexSetup(); $this->removeFixturesFromIndex(); $this->addFixturePathToFilemount(); $filepath = $this->getFixtureFilename('iptc'); $uid = tx_dam::file_isIndexed($filepath); self::assertFalse($uid, 'File index found, but shouldn\'t'); $indexed = tx_dam::index_process($filepath); $indexed = current($indexed); self::assertTrue(isset($indexed['uid']), 'File not indexed'); $meta = tx_dam::meta_getDataByUid($indexed['uid'], '*'); $date = date('d.m.Y', $meta['date_cr']); self::assertEquals($date, '04.07.2006', 'Wrong date: ' . $date); self::assertEquals($meta['title'], 'Hummelflug', 'Wrong title: ' . $meta['title']); self::assertEquals($meta['file_hash'], '184e454250f6f606a1dba14b5c7b38c5', 'Wrong file_hash: ' . $meta['file_hash']); self::assertEquals(intval($meta['media_type']), TXDAM_mtype_image, 'Wrong media_type: ' . $meta['media_type']); self::assertEquals($meta['file_type'], 'jpg', 'Wrong file_type: ' . $meta['file_type']); self::assertEquals($meta['file_mime_type'], 'image', 'Wrong file_mime_type: ' . $meta['file_mime_type']); self::assertEquals($meta['file_mime_subtype'], 'jpeg', 'Wrong file_mime_subtype: ' . $meta['file_mime_subtype']); self::assertTrue((bool) $meta['hpixels'], 'Missing value'); self::assertTrue((bool) $meta['vpixels'], 'Missing value'); self::assertTrue((bool) $meta['hres'], 'Missing value'); self::assertTrue((bool) $meta['vres'], 'Missing value'); self::assertTrue((bool) $meta['width'], 'Missing value'); self::assertTrue((bool) $meta['height'], 'Missing value'); self::assertTrue((bool) $meta['height_unit'], 'Missing value'); $this->removeFixturePathFromFilemount(); $this->removeFixturesFromIndex(); }
/** * Tries to find a lost index entry for a lost file and reconnect these items * * @param mixed $fileInfo Is a file path or an array containing a file info from tx_dam::file_compileInfo(). * @param string $hash The hash value will be used to identify the file if the file name was not found. That can happen if the file was renamed or moved without index update. * @return array status: array('__status' => TXDAM_file_notfound,'meta' => array(...)); */ function index_reconnect($fileInfo, $hash = '') { if (!is_array($fileInfo)) { $fileInfo = tx_dam::file_compileInfo($fileInfo, true); } $status = array('__status' => TXDAM_file_unknown, 'meta' => array()); $metaArr = tx_dam::meta_findDataForFile($fileInfo, $hash, 'uid,file_name,file_path,deleted'); foreach ($metaArr as $meta) { $srcInfo = tx_dam::file_compileInfo($meta, true); if (!$srcInfo['__exists']) { if ($meta['deleted']) { // setting the record undeleted right away ... $GLOBALS['TYPO3_DB']->exec_UPDATEquery('tx_dam', 'tx_dam.uid=' . $meta['uid'], array('deleted' => 0)); } tx_dam::notify_fileMoved(tx_dam::file_absolutePath($srcInfo), tx_dam::file_absolutePath($fileInfo)); $meta = tx_dam::meta_getDataByUid($meta['uid']); $status['meta'] = $meta; $status['__status'] = TXDAM_file_changed; break; } } return $status; }
/** * Main function, rendering the content of the rename form * * @return void */ function main() { global $LANG; $content = ''; // Cleaning and checking target if ($this->pObj->file[0]) { $this->file = tx_dam::file_compileInfo($this->pObj->file[0]); $this->meta = tx_dam::meta_getDataForFile($this->file); } elseif ($id = intval($this->pObj->record['tx_dam'][0])) { $this->meta = tx_dam::meta_getDataByUid($id); $this->file = tx_dam::file_compileInfo($this->meta); } if (!is_array($this->meta)) { $fileType = tx_dam::file_getType($this->file); $this->meta = array_merge($this->file, $fileType); $this->meta['uid'] = 0; } if ($this->file['file_accessable']) { if (is_array($this->pObj->data) and $this->pObj->data['upload']) { $error = tx_dam::process_replaceFile($this->meta, $this->pObj->data); if ($error) { $content .= $GLOBALS['SOBE']->getMessageBox($LANG->getLL('error'), htmlspecialchars($error), $this->pObj->buttonBack(0), 2); } else { $this->pObj->redirect(); } } else { $content .= $this->renderForm(); } } else { // this should have happen in index.php already $content .= $this->pObj->accessDeniedMessageBox($this->file['file_name']); } return $content; }
/** * "Finding" the files belonging to tx_dam records. * * @param string The uid of the record from $table * @param string The filename (usually found in field "file_name") * @param array Parameters set for the softref parser key in TCA/columns (currently unused) * @return array Result array on positive matches, containing one or null results */ function findRef_dam_file($uid, $fileName, $spParams) { $resultArray = array(); $fileInfo = tx_dam::meta_getDataByUid($uid, tx_dam_db::getMetaInfoFieldList() . ', description'); if ($fileInfo) { $file = $fileInfo['file_path'] . $fileInfo['file_name']; $tokenID = $this->makeTokenID(0); $resultArray = array('content' => '{softref:' . $tokenID . '}', 'elements' => array(0 => array('matchString' => $fileName, 'subst' => array('type' => 'file', 'tokenID' => $tokenID, 'tokenValue' => $fileName, 'relFileName' => $file, 'title' => $fileInfo['title'], 'description' => $fileInfo['description'])))); if (!@is_file(tx_dam::file_absolutePath($fileInfo))) { // Finally, notice if the file does not exist. $resultArray['elements'][0]['error'] = 'File does not exist!'; } } return $resultArray; }
/** * Compiles meta/fielInfo data for file and record items * * @return array Item array. Key is uid or md5 of filepath */ function compileFilesAndRecordsData() { $items = array(); if (count($this->file)) { foreach ($this->file as $filepath) { $fileInfo = tx_dam::file_compileInfo($filepath, true); $meta = tx_dam::meta_getDataForFile($fileInfo, '*'); if (!is_array($meta)) { $fileType = tx_dam::file_getType($filepath); $meta = array_merge($fileInfo, $fileType); $meta['uid'] = 0; } $id = $meta['uid'] ? $meta['uid'] : md5(tx_dam::file_absolutePath($fileInfo)); $items[$id] = array_merge($meta, $fileInfo); } } elseif (count($this->record['tx_dam'])) { foreach ($this->record['tx_dam'] as $uid) { if ($meta = tx_dam::meta_getDataByUid($uid, '*')) { $fileInfo = tx_dam::file_compileInfo($meta, true); $items[$meta['uid']] = array_merge($meta, $fileInfo); } } } return $items; }
/** * Reads all data from the index. * Only the limited amount of fields called "info fields" might be fetched from the index. * * @param integer $uid Optional UID of the wanted meta data record. Default: $this->meta['uid'] * @return void */ function fetchFullMetaData($uid = NULL) { if (!$this->isFullMetaData) { $uid = $uid ? $uid : $this->meta['uid']; if ($uid) { if ($row = tx_dam::meta_getDataByUid($this->meta['uid'], '*', $this->mode)) { $this->setMetaData($row); $this->fetchVariant(); $this->isFullMetaData = true; } } } }
/** * Set the link title that may be derived from the DAM meta data * * @return void */ protected function setDAMTitle() { if (t3lib_div::inList($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['rtehtmlarea']['plugins']['TYPO3Link']['additionalAttributes'], 'usedamcolumn') && $this->invokingObject->buttonConfig[$this->act . '.']['properties.']['title.']['useDAMColumn']) { $mediaId = $this->invokingObject->curUrlArray['txdam']; if ($mediaId) { // Checking if the id-parameter is int and get meta data if (t3lib_div::testInt($mediaId)) { $meta = tx_dam::meta_getDataByUid($mediaId); } // Generating configured title from meta data if (is_array($meta)) { require_once PATH_txdam . 'lib/class.tx_dam_guifunc.php'; $displayItems = $this->invokingObject->buttonConfig[$this->act . '.']['properties.']['title.']['useDAMColumn.']['displayItems'] ? $this->invokingObject->buttonConfig[$this->act . '.']['properties.']['title.']['useDAMColumn.']['displayItems'] : ''; $this->damTitle = tx_dam_guiFunc::meta_compileHoverText($meta, $displayItems, ', '); } else { $this->damTitle = 'No media record found: ' . $mediaId; } } } }
/** * tx_dam::process_renameFile() */ public function test_process_renameFile() { $this->removeFixtureTempFiles(); $this->removeIndexSetup(); $this->removeFixturesFromIndex(); $this->addFixturePathToFilemount(); $filepath = $this->getFixtureTempFilename(); $uid = tx_dam::file_isIndexed($filepath); self::assertNoUID($uid, 'File index found, but shouldn\'t'); tx_dam::config_setValue('setup.indexing.auto', true); $indexed = tx_dam::index_autoProcess($filepath, $reindex = false); self::assertTrue(isset($indexed['isIndexed']), 'File not indexed'); $uid = $indexed['fields']['uid']; $filepathNew = $filepath . '.doc'; $error = tx_dam::process_renameFile($filepath, tx_dam::file_basename($filepathNew)); if ($error) { debug($error); } self::assertTrue(is_file($filepathNew), 'File not renamed'); $uid2 = tx_dam::file_isIndexed($filepathNew); self::assertUID($uid2, 'File index not found'); self::assertEquals(intval($uid), intval($uid2), 'Wrong uid: ' . $uid . ' - ' . $uid2); $data = tx_dam::meta_getDataByUid($uid); self::assertEquals($data['file_name'], tx_dam::file_basename($filepathNew), 'Wrong file name ' . $indexed['fields']['file_name'] . ' != ' . tx_dam::file_basename($filepathNew)); $this->removeFixturePathFromFilemount(); $this->removeFixturesFromIndex(); $this->removeIndexSetup(); $this->removeFixtureTempFiles(); }