Exemplo n.º 1
0
 /**
  * Returns a unique absolut path of a file or folder.
  *
  * @param string $path
  *        the path of a file or folder relative to the calling extension's
  *        upload directory, must not be empty
  *
  * @return string the unique absolut path of a file or folder
  *
  * @throws InvalidArgumentException
  */
 public function getUniqueFileOrFolderPath($path)
 {
     if (empty($path)) {
         throw new InvalidArgumentException('The first parameter $path must not be empty.', 1334439457);
     }
     if (!self::$fileNameProcessor) {
         self::$fileNameProcessor = t3lib_div::makeInstance('t3lib_basicFileFunctions');
     }
     return self::$fileNameProcessor->getUniqueName(basename($path), $this->uploadFolderPath . t3lib_div::dirname($path));
 }
 /**
  * Copies any "RTEmagic" image files found in record with table/id to new names.
  * Usage: After copying a record this function should be called to search for "RTEmagic"-images inside the record. If such are found they should be duplicated to new names so all records have a 1-1 relation to them.
  * Reason for copying RTEmagic files: a) if you remove an RTEmagic image from a record it will remove the file - any other record using it will have a lost reference! b) RTEmagic images keeps an original and a copy. The copy always is re-calculated to have the correct physical measures as the HTML tag inserting it defines. This is calculated from the original. Two records using the same image could have difference HTML-width/heights for the image and the copy could only comply with one of them. If you don't want a 1-1 relation you should NOT use RTEmagic files but just insert it as a normal file reference to a file inside fileadmin/ folder
  *
  * @param	string		Table name
  * @param	integer		Record UID
  * @return	void
  */
 function copyRecord_fixRTEmagicImages($table, $theNewSQLID)
 {
     global $TYPO3_DB;
     // Creating fileFunc object.
     if (!$this->fileFunc) {
         $this->fileFunc = t3lib_div::makeInstance('t3lib_basicFileFunctions');
         $this->include_filefunctions = 1;
     }
     // Select all RTEmagic files in the reference table from the table/ID
     /* @var $TYPO3_DB t3lib_DB */
     $recs = $TYPO3_DB->exec_SELECTgetRows('*', 'sys_refindex', 'ref_table=' . $TYPO3_DB->fullQuoteStr('_FILE', 'sys_refindex') . ' AND ref_string LIKE ' . $TYPO3_DB->fullQuoteStr('%/RTEmagic%', 'sys_refindex') . ' AND softref_key=' . $TYPO3_DB->fullQuoteStr('images', 'sys_refindex') . ' AND tablename=' . $TYPO3_DB->fullQuoteStr($table, 'sys_refindex') . ' AND recuid=' . intval($theNewSQLID), '', 'sorting DESC');
     // Traverse the files found and copy them:
     if (is_array($recs)) {
         foreach ($recs as $rec) {
             $filename = basename($rec['ref_string']);
             $fileInfo = array();
             if (t3lib_div::isFirstPartOfStr($filename, 'RTEmagicC_')) {
                 $fileInfo['exists'] = @is_file(PATH_site . $rec['ref_string']);
                 $fileInfo['original'] = substr($rec['ref_string'], 0, -strlen($filename)) . 'RTEmagicP_' . preg_replace('/\\.[[:alnum:]]+$/', '', substr($filename, 10));
                 $fileInfo['original_exists'] = @is_file(PATH_site . $fileInfo['original']);
                 // CODE from tx_impexp and class.rte_images.php adapted for use here:
                 if ($fileInfo['exists'] && $fileInfo['original_exists']) {
                     // Initialize; Get directory prefix for file and set the original name:
                     $dirPrefix = dirname($rec['ref_string']) . '/';
                     $rteOrigName = basename($fileInfo['original']);
                     // If filename looks like an RTE file, and the directory is in "uploads/", then process as a RTE file!
                     if ($rteOrigName && t3lib_div::isFirstPartOfStr($dirPrefix, 'uploads/') && @is_dir(PATH_site . $dirPrefix)) {
                         // RTE:
                         // From the "original" RTE filename, produce a new "original" destination filename which is unused.
                         $origDestName = $this->fileFunc->getUniqueName($rteOrigName, PATH_site . $dirPrefix);
                         // Create copy file name:
                         $pI = pathinfo($rec['ref_string']);
                         $copyDestName = dirname($origDestName) . '/RTEmagicC_' . substr(basename($origDestName), 10) . '.' . $pI['extension'];
                         if (!@is_file($copyDestName) && !@is_file($origDestName) && $origDestName === t3lib_div::getFileAbsFileName($origDestName) && $copyDestName === t3lib_div::getFileAbsFileName($copyDestName)) {
                             // Making copies:
                             t3lib_div::upload_copy_move(PATH_site . $fileInfo['original'], $origDestName);
                             t3lib_div::upload_copy_move(PATH_site . $rec['ref_string'], $copyDestName);
                             clearstatcache();
                             // Register this:
                             $this->RTEmagic_copyIndex[$rec['tablename']][$rec['recuid']][$rec['field']][$rec['ref_string']] = substr($copyDestName, strlen(PATH_site));
                             // Check and update the record using the t3lib_refindex class:
                             if (@is_file($copyDestName)) {
                                 $sysRefObj = t3lib_div::makeInstance('t3lib_refindex');
                                 $error = $sysRefObj->setReferenceValue($rec['hash'], substr($copyDestName, strlen(PATH_site)), FALSE, TRUE);
                                 if ($error) {
                                     echo $this->newlog('t3lib_refindex::setReferenceValue(): ' . $error, 1);
                                 }
                             } else {
                                 $this->newlog('File "' . $copyDestName . '" was not created!', 1);
                             }
                         } else {
                             $this->newlog('Could not construct new unique names for file!', 1);
                         }
                     } else {
                         $this->newlog('Maybe directory of file was not within "uploads/"?', 1);
                     }
                 } else {
                     $this->newlog('Trying to copy RTEmagic files (' . $rec['ref_string'] . ' / ' . $fileInfo['original'] . ') but one or both were missing', 1);
                 }
             }
         }
     }
 }