/** * Transformation handler: 'ts_links' / direction: "db" * Processing linked images inserted in the RTE. * This is used when content goes from the RTE to the database. * Images inserted in the RTE has an absolute URL applied to the src attribute. This URL is converted to a media uid * * @param string The content from RTE going to Database * @return string Processed content */ function transform_db($value, &$pObj) { // Split content into <a> tag blocks and process: $blockSplit = $pObj->splitIntoBlock('A', $value); foreach ($blockSplit as $k => $v) { if ($k % 2) { // If an A-tag was found: $attribArray = $pObj->get_tag_attributes_classic($pObj->getFirstTag($v), 1); $info = $pObj->urlInfoForLinkTags($attribArray['href']); $uid = false; if (isset($attribArray['txdam'])) { $uid = intval($attribArray['txdam']); } if (!$uid and $info['relUrl']) { $info['relUrl'] = rawurldecode($info['relUrl']); $uid = tx_dam::file_isIndexed($info['relUrl']); } // found an id, so convert the a tag to a media tag if ($uid) { if ($attribArray['usedamcolumn'] == 'true') { unset($attribArray['title']); } unset($attribArray['usedamcolumn']); if (is_array($pObj->procOptions['HTMLparser_db.']['tags.']['media.'])) { $tags = array(); $tags['a'] = $pObj->procOptions['HTMLparser_db.']['tags.']['media.']; $blockSplit[$k] = $pObj->HTMLcleaner($blockSplit[$k], $tags, true); } $bTag = '<media ' . $uid . ($attribArray['target'] ? ' ' . $attribArray['target'] : ($attribArray['class'] || $attribArray['title'] ? ' -' : '')) . ($attribArray['class'] ? ' ' . $attribArray['class'] : ($attribArray['title'] ? ' -' : '')) . ($attribArray['title'] ? ' "' . $attribArray['title'] . '"' : '') . '>'; $eTag = '</media>'; $blockSplit[$k] = $bTag . $this->transform_db($pObj->removeFirstAndLastTag($blockSplit[$k]), $pObj) . $eTag; } else { // just rebuild the tag so it can be processed by t3lib_parsehtml_proc::TS_links_db unset($attribArray['usedamcolumn']); $bTag = '<a ' . t3lib_div::implodeAttributes($attribArray, 1) . '>'; $eTag = '</a>'; $blockSplit[$k] = $bTag . $this->transform_db($pObj->removeFirstAndLastTag($blockSplit[$k]), $pObj) . $eTag; } } } $value = implode('', $blockSplit); $value = $pObj->TS_links_db($value); 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(); }
/** * Indiziert eine Datei mit DAM. * * ACHTUNG: wenn die Feld Collation der DB-Felder file_name und file_path * in der tx_dam Tabelle auf *_ci (utf8_general_ci) stehen, * wird bei der Prüfung Gruß-/Kleinschreibung ignoriert, * was bei unix-Systemen zu Fehlern führt! * Die einfache Lösung ist, die Collation der beiden Felder * auf *_bin (utf8_bin) zu setzen! * * @param string $file * @param int $beUserId * @return uid */ public static function indexProcess($file, $beUserId) { if (!tx_rnbase_util_Extensions::isLoaded('dam')) { return 0; } require_once tx_rnbase_util_Extensions::extPath('dam', 'lib/class.tx_dam.php'); $mediaUid = tx_dam::file_isIndexed($file); if (!$mediaUid) { // process file indexing self::initBE4DAM($beUserId); $damData = tx_dam::index_process($file); $mediaUid = $damData[0]['uid']; } return $mediaUid; }
/** * Process auto indexing for the given file. * This should be used to index files easily. * When auto indexing is disabled the indexing will not be processed. * * @param string $filename Filename with path * @param boolean $reindex If set already indexed files will be reindexed * @return array Meta data array. $meta['fields'] has the record data. Returns false when nothing was indexed but file might be in index already. */ function index_autoProcess($filename, $reindex = false) { global $TYPO3_CONF_VARS; // disable auto indexing by setup if (!tx_dam::config_getValue('setup.indexing.auto')) { return false; } $filename = tx_dam::file_absolutePath($filename); if (!@is_file($filename)) { return false; } // we don't index indexing setup files if (basename($filename) == '.indexing.setup.xml') { return false; } if (!$reindex and tx_dam::file_isIndexed($filename)) { return false; } require_once PATH_txdam . 'lib/class.tx_dam_indexing.php'; $index = t3lib_div::makeInstance('tx_dam_indexing'); $index->init(); $index->setDefaultSetup(tx_dam::file_dirname($filename)); $index->initEnabledRules(); $index->enableReindexing($reindex); // overrule some parameter from setup $index->setPath($filename); $index->setPID(tx_dam_db::getPid()); $index->setRunType('auto'); $index->enableMetaCollect(); // indexing ... $index->indexUsingCurrentSetup(); return current($index->meta); }
/** * Processes auto indexing if the file is not yet indexed * * @param array $item */ function autoIndex(&$item) { static $indexed = 0; if ($this->maxAutoIndexingItems and $indexed >= $this->maxAutoIndexingItems) { return; } // we don't index indexing setup files if ($item['file_name'] === '.indexing.setup.xml') { } elseif (!($uid = tx_dam::file_isIndexed($item))) { if ($metaRow = tx_dam::index_autoProcess($item)) { $item = $metaRow['fields']; $item['__isIndexed'] = true; $indexed++; } } }
/** * Renders the item icon * * @param array $item item array * @return string */ function getItemIcon($item) { static $titleNotIndexed; static $iconNotIndexed; if (!$iconNotIndexed) { $titleNotIndexed = 'title="' . $GLOBALS['LANG']->getLL('fileNotIndexed') . '"'; $iconNotIndexed = '<img' . t3lib_iconWorks::skinImg($GLOBALS['BACK_PATH'], 'gfx/required_h.gif', 'width="10" height="10"') . ' ' . $titleNotIndexed . ' alt="" />'; } $type = $item['__type']; if ($type == 'file') { $titleAttr = ''; $attachToIcon = ''; if (!$item['__isIndexed'] and !($uid = tx_dam::file_isIndexed($item))) { $attachToIcon = $iconNotIndexed; $titleAttr = $titleNotIndexed; } $iconTag = tx_dam::icon_getFileTypeImgTag($item, $titleAttr); if ($this->enableContextMenus) { $iconTag = $GLOBALS['SOBE']->doc->wrapClickMenuOnIcon($iconTag, tx_dam::file_absolutePath($item)); } $iconTag .= $attachToIcon; } else { $titleAttr = 'title="' . htmlspecialchars($item[$type . '_title']) . '"'; $iconTag = tx_dam::icon_getFileTypeImgTag($item, $titleAttr); if ($this->enableContextMenus) { $iconTag = $GLOBALS['SOBE']->doc->wrapClickMenuOnIcon($iconTag, tx_dam::path_makeAbsolute($item)); } } return $iconTag; }
/** * Recompile a TypoLink value from the array of properties made with getTypoLinkParts() into an elements array * * @param array TypoLink properties * @param array Array of elements to be modified with substitution / information entries. * @param string The content to process. * @param integer Index value of the found element - user to make unique but stable tokenID * @return string The input content, possibly containing tokens now according to the added substitution entries in $elements * @see getTypoLinkParts() */ function setTypoLinkPartsElement($tLP, &$elements, $content, $idx) { // Based on link type, maybe do more: switch ((string) $tLP['LINK_TYPE']) { case 'file': // Initialize, set basic values. In any case a link will be shown $tokenID = $this->makeTokenID('setTypoLinkPartsElement:' . $idx); $elements[$tokenID . ':' . $idx] = array(); $elements[$tokenID . ':' . $idx]['matchString'] = $content; // Process files found in fileadmin directory: if (!$tLP['query']) { // We will not process files which has a query added to it. That will look like a script we don't want to move. if (t3lib_div::isFirstPartOfStr($tLP['filepath'], $this->fileAdminDir . '/')) { // File must be inside fileadmin/ // Let see if the file is indexded by DAM $mediaId = tx_dam::file_isIndexed(rawurldecode($tLP['filepath'])); // If file is indexed by DAM continue. Otherwise ignore this link. if ($mediaId) { // Set up the basic token and token value for the relative file: $elements[$tokenID . ':' . $idx]['subst'] = array('type' => 'db', 'recordRef' => 'tx_dam:' . $mediaId, 'tokenID' => $tokenID, 'tokenValue' => $mediaId); } else { // Set up the basic token and token value for the relative file: $elements[$tokenID . ':' . $idx]['subst'] = array('type' => 'file', 'relFileName' => $tLP['filepath'], 'tokenID' => $tokenID, 'tokenValue' => $tLP['filepath']); } // Depending on whether the file exists or not we will set the $absPath = t3lib_div::getFileAbsFileName(PATH_site . $tLP['filepath']); if (!@is_file($absPath)) { $elements[$tokenID . ':' . $idx]['error'] = 'File does not exist!'; } // Output content will be the token instead $content = '{softref:' . $tokenID . '}'; } else { return $content; } } else { return $content; } break; default: return parent::setTypoLinkPartsElement($tLP, $elements, $content, $idx); break; } // Finally, for all entries that was rebuild with tokens, add target and class in the end: if (strlen($content) && strlen($tLP['target'])) { $content .= ' ' . $tLP['target']; if (strlen($tLP['class'])) { $content .= ' ' . $tLP['class']; } } // Return rebuilt typolink value: return $content; }
/** * 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(); }