/**
  * Check if this object should render
  *
  * @param	string		Type: "file"
  * @param	object		Parent object.
  * @return	boolean
  */
 function isValid($type, &$pObj)
 {
     $isValid = false;
     if ($type === 'file' && is_array($this->meta = tx_dam::meta_getDataForFile($pObj->file, '*'))) {
         $isValid = true;
     }
     return $isValid;
 }
 /**
  * tx_dam::meta_getDataForFile()
  */
 public function test_meta_getDataForFile()
 {
     $fixture = $this->getFixtureRandomIndexedFilename();
     $filename = $fixture['filename'];
     $meta = $fixture['meta'];
     $data = tx_dam::meta_getDataForFile($filename);
     self::assertEquals($data['uid'], $meta['uid'], 'Wrong index for ' . $filename);
 }
 /**
  * Insert the image in the editing area
  *
  * @return	void
  */
 protected function insertImage()
 {
     global $TCA;
     if (t3lib_div::_GP('insertImage')) {
         $filepath = t3lib_div::_GP('insertImage');
         $imgInfo = $this->RTESelectImageObj->getImageInfo($filepath);
         $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':
                 $this->RTESelectImageObj->insertMagicImage($filepath, $imgInfo, $imgMetaData['alt_text'], $imgMetaData[$this->imgTitleDAMColumn], 'txdam=' . $imgMetaData['uid']);
                 exit;
                 break;
             case 'plain':
                 $imgInfo[0] = $imgMetaData['hpixels'];
                 $imgInfo[1] = $imgMetaData['vpixels'];
                 $this->RTESelectImageObj->insertPlainImage($imgInfo, $imgMetaData['alt_text'], $imgMetaData[$this->imgTitleDAMColumn], 'txdam=' . $imgMetaData['uid']);
                 exit;
                 break;
         }
     }
 }
Пример #4
0
 /**
  * Notifies the DAM about a deleted file or folder.
  * This will remove the file(s) from the index.
  *
  * @param	string		$filename Filename with path or a folder which have to have a trailing slash.
  * @param	string		$recyclerPath New path when item is moved to recycler.
  * @return	void
  */
 function notify_fileDeleted($filename, $recyclerPath = '')
 {
     if (is_array($row = tx_dam::meta_getDataForFile($filename, 'uid', true))) {
         $uid = $row['uid'];
     }
     if ($uid) {
         $fields_values = array();
         $fields_values['uid'] = $uid;
         $fields_values['deleted'] = '1';
         // file was moved to recycler
         if ($recyclerPath) {
             $org_filename = tx_dam::file_basename($filename);
             $path_parts = t3lib_div::split_fileref($recyclerPath);
             $new_filename = $path_parts['file'];
             $new_path = $path_parts['path'];
             if ($org_filename != $new_filename) {
                 $fields_values['file_name'] = $new_filename;
             }
             if ($new_path) {
                 $fields_values['file_path'] = tx_dam::path_makeRelative($new_path);
             }
         } else {
             // delete MM relations
             $GLOBALS['TYPO3_DB']->exec_DELETEquery('tx_dam_mm_ref', 'tx_dam_mm_ref.uid_local=' . $uid);
         }
         tx_dam_db::insertUpdateData($fields_values);
         // set language overlays deleted
         $GLOBALS['TYPO3_DB']->exec_UPDATEquery('tx_dam', 'l18n_parent=' . $uid, array('deleted' => 1));
         # $GLOBALS['TYPO3_DB']->exec_DELETEquery('tx_dam', 'l18n_parent='.$uid);
         // todo: replace with full supported group concept --------------------
         // todo: delete child elements and their MM-relation
         // files stay at their physical storage position (usually uploads/tx_dam/storage/_uid_/)
         $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid', 'tx_dam', 'parent_id=' . intval($uid));
         while ($childRow = $GLOBALS['TYPO3_DB']->sql_fetch_row($res)) {
             $childUid = $childRow[0];
             $GLOBALS['TYPO3_DB']->exec_UPDATEquery('tx_dam', 'uid=' . $childUid, array('deleted' => 1));
             $GLOBALS['TYPO3_DB']->exec_DELETEquery('tx_dam_mm_ref', 'tx_dam_mm_ref.uid_local=' . $childUid);
         }
         // ------------------------------------
     } elseif (preg_match('#/$#', $filename)) {
         tx_dam_db::updateFilePathSetDeleted($filename);
     }
 }
 /**
  * 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;
 }
 /**
  * Returns an array with file/dir items + an array with the sorted items
  *
  * @param	string		Path (absolute) to read
  * @param	mixed		$allowTypes List or array of allow directory entry types: file, dir, link. Empty is all kinds of stuff.
  * @return	void
  */
 function read($path, $allowTypes = 'file')
 {
     $allowTypes = is_array($allowTypes) ? $allowTypes : t3lib_div::trimExplode(',', $allowTypes, true);
     if ($path) {
         $tempArray = array();
         $path = tx_dam::path_makeAbsolute($path);
         if (is_object($d = @dir($path))) {
             while ($entry = $d->read()) {
                 $filepath = $path . $entry;
                 // check for allow file types: eg. file, dir, link
                 if (@file_exists($filepath) && (!$allowTypes || in_array($type = filetype($filepath), $allowTypes))) {
                     // if filename matches exclude list this file is skipped
                     foreach ($this->excludeRegex as $expr) {
                         if (preg_match($expr, $entry)) {
                             continue 2;
                         }
                     }
                     // if filename don't matches allow list this file is skipped
                     foreach ($this->allowRegex as $expr) {
                         if (!preg_match($expr, $entry)) {
                             continue 2;
                         }
                     }
                     if ($type === 'file') {
                         $fileInfo = tx_dam::file_compileInfo($filepath);
                         if (is_array($meta = tx_dam::meta_getDataForFile($fileInfo))) {
                             // the newer stat data will be merged over the stored meta data
                             $fileInfo = array_merge($meta, $fileInfo);
                         } else {
                             $mimeType = tx_dam::file_getType($filepath);
                             $fileInfo = array_merge($fileInfo, $mimeType);
                         }
                         if (count($this->excludeFileTypes) and in_array($fileInfo['file_type'], $this->excludeFileTypes)) {
                             continue;
                         }
                         if (count($this->allowFileTypes) and !in_array($fileInfo['file_type'], $this->allowFileTypes)) {
                             continue;
                         }
                         if ($this->enableAutoIndexing) {
                             $this->autoIndex($fileInfo);
                         }
                     } elseif ($type === 'dir' or $type === 'link') {
                         $fileInfo = tx_dam::path_compileInfo($filepath);
                     }
                     // the file is valid so we add it to the list
                     $this->entries[] = $fileInfo;
                     $this->countBytes += $fileInfo['file_size'];
                 }
             }
             $d->close();
             $this->sort();
             $this->rewind();
         }
     }
 }
Пример #7
0
 /**
  * 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;
 }
 /**
  * Initialize the object by a given filename
  *
  * @param	string		$file Filepath to file. Should probably be absolute.
  * @param	string		$hash If set the hash value can 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.
  * @param	boolean		$autoIndex If set (default) the file will be indexed automatically.
  * @return	void
  */
 function fetchIndexFromFilename($file, $hash = false, $autoIndex = true)
 {
     $this->fetchFileInfo($file);
     if ($this->isAvailable) {
         if ($row = tx_dam::meta_getDataForFile($this->fileInfo, '*', true, $this->mode)) {
             $this->setMetaData($row);
             $this->fetchVariant();
             $this->isFullMetaData = true;
             $this->isIndexed = true;
         } elseif ($autoIndex) {
             // TODO search for hash
             $this->autoIndex();
         }
     }
 }
 /**
  * [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);
         $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);
                         t3lib_div::fixPermissions($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);
                             t3lib_div::fixPermissions($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;
         }
     }
 }
 /**
  * Inserts the element in the RTE editing area
  *
  * @param	string		$act: the action
  * @return	void
  */
 public function insertElement($act)
 {
     global $TCA;
     // Determine the DAM column from which to get the title
     $imgTitleDAMColumn = 'caption';
     t3lib_div::loadTCA('tx_dam');
     if (is_array($this->buttonConfig['title.']) && is_array($TCA['tx_dam']['columns'][$this->buttonConfig['title.']['useDAMColumn']])) {
         $imgTitleDAMColumn = $this->buttonConfig['title.']['useDAMColumn'];
     }
     // Get the image info from the DAM database
     $filepath = t3lib_div::_GP('insertImage');
     $imgInfo = $this->invokingObject->getImageInfo($filepath);
     $imgMetaData = tx_dam::meta_getDataForFile($filepath, 'uid,pid,alt_text,hpixels,vpixels,' . $imgTitleDAMColumn . ',' . $TCA['tx_dam']['ctrl']['languageField']);
     // Localize the record in the language of the content element
     $imgMetaData = $this->getRecordOverlay('tx_dam', $imgMetaData, $this->sys_language_content);
     switch ($act) {
         case 'media_magic':
             $this->invokingObject->insertMagicImage($filepath, $imgInfo, $imgMetaData['alt_text'], $imgMetaData[$imgTitleDAMColumn], 'txdam=' . $imgMetaData['uid']);
             break;
         case 'media_plain':
             $imgInfo[0] = $imgMetaData['hpixels'];
             $imgInfo[1] = $imgMetaData['vpixels'];
             $this->invokingObject->insertPlainImage($imgInfo, $imgMetaData['alt_text'], $imgMetaData[$imgTitleDAMColumn], 'txdam=' . $imgMetaData['uid']);
             break;
     }
 }