/**
  * Update the media types table for browsing
  * Will be called when a meta data record was inserted.
  *
  * @param	array		$meta meta data. $meta['media_type'] and $meta['file_type'] have to be set
  * @return	void
  */
 function insertMetaTrigger($meta)
 {
     $TX_DAM = $GLOBALS['T3_VAR']['ext']['dam'];
     $mediaType = intval($meta['media_type']);
     // check if media type exists
     if ($typeStr = tx_dam::convert_mediaType($mediaType)) {
         // get the id of the media type record
         $media_id = false;
         $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid', 'tx_dam_metypes_avail', 'type=' . $GLOBALS['TYPO3_DB']->fullQuoteStr($mediaType, 'tx_dam_metypes_avail'));
         if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
             $media_id = $row['uid'];
         }
         // no record - then create one
         if (!$media_id) {
             $sorting = $TX_DAM['code2sorting'][$mediaType];
             $sorting = $sorting ? $sorting : 10000;
             $fields_values = array();
             $fields_values['pid'] = tx_dam_db::getPid();
             $fields_values['parent_id'] = 0;
             $fields_values['tstamp'] = time();
             $fields_values['title'] = $typeStr;
             $fields_values['type'] = $mediaType;
             $fields_values['sorting'] = $sorting;
             $res = $GLOBALS['TYPO3_DB']->exec_INSERTquery('tx_dam_metypes_avail', $fields_values);
             $media_id = $GLOBALS['TYPO3_DB']->sql_insert_id();
         }
         // get file type record
         $type_id = false;
         if ($media_id) {
             $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid', 'tx_dam_metypes_avail', 'title=' . $GLOBALS['TYPO3_DB']->fullQuoteStr($meta['file_type'], 'tx_dam_metypes_avail') . ' AND parent_id=' . $GLOBALS['TYPO3_DB']->fullQuoteStr($media_id, 'tx_dam_metypes_avail'));
             if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
                 $type_id = $row['uid'];
             }
         }
         // no record - then create one
         if (!$type_id) {
             $fields_values = array();
             $fields_values['pid'] = tx_dam_db::getPid();
             $fields_values['parent_id'] = $media_id;
             $fields_values['tstamp'] = time();
             $fields_values['title'] = $meta['file_type'] ? $meta['file_type'] : 'n/a';
             $fields_values['type'] = $mediaType;
             $res = $GLOBALS['TYPO3_DB']->exec_INSERTquery('tx_dam_metypes_avail', $fields_values);
         }
     }
 }
    /**
     * Do the file indexing
     * Read files from a directory index them and output a result table
     *
     * @return	string		HTML content
     */
    function checkUploads($indexSessionID)
    {
        global $LANG, $TYPO3_CONF_VARS;
        // makes sense? Was a hint on php.net
        ob_end_flush();
        // get session data - which might have left files stored
        $indexSession = $this->indexSessionFetch();
        $where = array();
        if ($age = intval($this->pObj->MOD_SETTINGS['tx_dam_tools_indexupdate.age'])) {
            $where['tstamp'] = 'tstamp<' . (time() - $age);
        }
        if ($indexSessionID == '' or !isset($indexSession['ID']) or !($indexSession['ID'] == $indexSessionID) or $indexSession['currentCount'] == 0) {
            $GLOBALS['TYPO3_DB']->exec_DELETEquery('tx_dam_file_tracking', '');
            $files = array();
            $files = $this->getFilesInDir(PATH_site . 'uploads/', true, $files);
            $countTotal = count($files);
            $indexSession = $this->indexSessionNew($countTotal, $files);
        }
        if (is_array($indexSession['data'])) {
            $damIndexing = t3lib_div::makeInstance('tx_dam_indexing');
            $damIndexing->init();
            $damIndexing->dryRun = TRUE;
            foreach ($indexSession['data'] as $key => $file) {
                // increase progress bar
                $indexSession['currentCount']++;
                $fileHash = tx_dam::file_calcHash($file);
                $fileInfo = tx_dam::file_compileInfo($file);
                $fields_values = array('tstamp' => time(), 'file_name' => $fileInfo['file_name'], 'file_path' => $fileInfo['file_path'], 'file_size' => $fileInfo['file_size'], 'file_ctime' => min($fileInfo['file_ctime'], $fileInfo['file_mtime']), 'file_hash' => $fileHash);
                $GLOBALS['TYPO3_DB']->exec_INSERTquery('tx_dam_file_tracking', $fields_values);
                $fileInfo = array_merge($fileInfo, $damIndexing->getFileMimeType($file));
                $fileInfo['media_type'] = tx_dam::convert_mediaType($fileInfo['file_mime_type']);
                $ctable = array();
                $ctable[] = '&nbsp;';
                $ctable[] = tx_dam::icon_getFileTypeImgTag($fileInfo, 'align="top"') . '&nbsp;' . htmlspecialchars(t3lib_div::fixed_lgd_cs($fileInfo['file_name'], 30));
                $ctable[] = htmlspecialchars(t3lib_div::fixed_lgd_cs($fileInfo['file_path'], -30));
                $this->indexing_addTableRow($ctable);
                $msg = $LANG->getLL('tx_dam_tools_indexupdate.updatedMessage', 1);
                $code = sprintf($msg, $indexSession['currentCount'], $indexSession['totalFilesCount']);
                $this->indexing_setMessage($code);
                $this->indexing_progressBar($indexSession['currentCount'], $indexSession['totalFilesCount']);
                $this->indexing_flushNow();
                $this->indexSessionWrite($indexSession);
                if ($this->indexEndtime < time() and $indexSession['currentCount'] < $indexSession['totalFilesCount']) {
                    $params = $this->pObj->addParams;
                    $params['indexSessionID'] = $indexSession['ID'];
                    echo '
						<script type="text/javascript">  window.location.href = unescape("' . t3lib_div::rawUrlEncodeJS(tx_dam_SCbase::linkThisScriptStraight($params)) . '"); </script>';
                    exit;
                }
            }
        } elseif ($indexSession['totalFilesCount'] == 0) {
            $code = $LANG->getLL('tx_dam_tools_indexupdate.no_files');
            $this->indexing_setMessage($code);
        }
        $this->indexing_finished();
        // finished - clear session
        $this->indexSessionClear();
    }
Esempio n. 3
0
 /**
  * Returns the icon file path for a file type icon for a given file.
  * $mimeType = tx_dam::file_getType($filename);
  *
  * @param	array		$mimeType Describes the type of a file. Can be meta record array or array from tx_dam::file_getType().
  * @param	boolean		$absolutePath If set the path to the icon is absolute. By default it's relative to typo3/ folder.
  * @param	string		$mode TYPO3_MODE to be used: 'FE', 'BE'. Constant TYPO3_MODE is default.
  * @return	string		Icon image file path
  * @see tx_dam::file_getType()
  */
 function icon_getFileType($mimeType, $absolutePath = false, $mode = TYPO3_MODE)
 {
     static $iconCache = array();
     static $iconCacheRel = array();
     $iconfile = false;
     // first see if the icon is in the icon cache
     if (is_array($mimeType)) {
         if (!$absolutePath && ($cached = $iconCacheRel[$mimeType['file_type']])) {
             return $cached;
         } elseif ($cached = $iconCache[$mimeType['file_type']]) {
             $iconfile = $cached;
         } else {
             foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['dam']['fileIconPaths_' . $mode] as $pathIcons) {
                 // Check defined icons
                 $fileType = tx_dam_db::getMediaExtension($mimeType['file_type']);
                 // See if the icon is a DAM reference
                 if (t3lib_div::testInt($fileType['icon'])) {
                     $fileType['icon'] = tx_dam::file_getPathByUid($fileType['icon']);
                 }
                 if (@file_exists($fileType['icon'])) {
                     $iconfile = $fileType['icon'];
                     $cacheKey = $mimeType['file_type'];
                     $iconCache[$cacheKey] = $iconfile;
                     break;
                 }
                 // then try default PNG
                 if (@file_exists($pathIcons . $mimeType['file_type'] . '.png')) {
                     $iconfile = $pathIcons . $mimeType['file_type'] . '.png';
                     $cacheKey = $mimeType['file_type'];
                     $iconCache[$cacheKey] = $iconfile;
                     break;
                 }
                 // then go for default GIF
                 if (@file_exists($pathIcons . $mimeType['file_type'] . '.gif')) {
                     $iconfile = $pathIcons . $mimeType['file_type'] . '.gif';
                     $cacheKey = $mimeType['file_type'];
                     $iconCache[$cacheKey] = $iconfile;
                     break;
                 }
             }
             if (!$iconfile && ($mediaType = tx_dam::convert_mediaType($mimeType['media_type']))) {
                 foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['dam']['fileIconPaths_' . $mode] as $pathIcons) {
                     // first try PNG
                     if (@file_exists($pathIcons . 'mtype_' . $mediaType . '.png')) {
                         $iconfile = $pathIcons . 'mtype_' . $mediaType . '.png';
                         $cacheKey = '_mtype_' . $mimeType['media_type'];
                         $iconCache[$cacheKey] = $iconfile;
                         break;
                     }
                     // then go for GIF
                     if (@file_exists($pathIcons . 'mtype_' . $mediaType . '.gif')) {
                         $iconfile = $pathIcons . 'mtype_' . $mediaType . '.gif';
                         $cacheKey = '_mtype_' . $mimeType['media_type'];
                         $iconCache[$cacheKey] = $iconfile;
                         break;
                     }
                 }
             }
             if (!$iconfile) {
                 $iconfile = PATH_txdam . 'i/18/' . 'mtype_undefined.gif';
                 $cacheKey = '__undefined';
             }
         }
     }
     if (!$absolutePath) {
         $iconfile = preg_replace('#^' . preg_quote(PATH_site) . '#', '', $iconfile);
         if (TYPO3_MODE === 'BE') {
             $iconfile = '../' . $iconfile;
             $iconCacheRel[$cacheKey] = $iconfile;
         }
     }
     return $iconfile;
 }
 /**
  * Returns the icon of an item
  *
  * @param	string		The select value/id
  * @param	string		The select value (true/false,...)
  * @return	string
  */
 function selection_getItemIcon($id, $value)
 {
     if (!intval($id)) {
         $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(implode(',', $this->fieldArray), $this->table, 'title=' . $GLOBALS['TYPO3_DB']->fullQuoteStr($id, $this->table));
         $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
         $id = $row['type'];
     }
     if (intval($id)) {
         $icon = '<img' . t3lib_iconWorks::skinImg($GLOBALS['BACK_PATH'], $this->iconPath . '18/mtype_' . tx_dam::convert_mediaType($id) . '.gif', 'width="18" height="16"') . ' class="typo3-icon" alt="" />';
     }
     return $icon;
 }
 /**
  * get meta information from a file using the metaExtract service
  *
  * @param	string		file with absolut path
  * @param	array		file meta information which should be extended
  * @return	array		file meta information
  * @todo what about using services in a chain?
  */
 function getFileMetaInfo($pathname, $meta)
 {
     global $TYPO3_CONF_VARS;
     $TX_DAM = $GLOBALS['T3_VAR']['ext']['dam'];
     $conf = array();
     $conf['wantedCharset'] = $this->getWantedCharset();
     if (is_file($pathname) && is_readable($pathname)) {
         $fileType = $meta['fields']['file_type'];
         if ($this->setup['useInternalMediaTypeList']) {
             // get media type from file type
             $meta['fields']['media_type'] = $TX_DAM['file2mediaCode'][$fileType];
             //  or from mime type
             $meta['fields']['media_type'] = $meta['fields']['media_type'] ? $meta['fields']['media_type'] : tx_dam::convert_mediaType($meta['fields']['file_mime_type']);
         } else {
             $meta['fields']['media_type'] = tx_dam::convert_mediaType($meta['fields']['file_mime_type']);
         }
         $mediaType = tx_dam::convert_mediaType($meta['fields']['media_type']);
         // find a service for that file type
         if (!is_object($serviceObj = t3lib_div::makeInstanceService('metaExtract', $fileType))) {
             // find a global service for that media type
             $serviceObj = t3lib_div::makeInstanceService('metaExtract', $mediaType . ':*');
         }
         if (is_object($serviceObj)) {
             $serviceObj->setInputFile($pathname, $fileType);
             $conf['meta'] = $meta;
             if ($serviceObj->process('', '', $conf) > 0 and is_array($svmeta = $serviceObj->getOutput())) {
                 $meta = t3lib_div::array_merge_recursive_overrule($meta, $svmeta);
             }
             $serviceObj->__destruct();
             unset($serviceObj);
         }
         // make simple image size detection if not yet done
         if ($meta['fields']['media_type'] == TXDAM_mtype_image and intval($meta['fields']['hpixels']) == 0) {
             $imgsize = $this->getImageDimensions($pathname, $meta);
             $meta = t3lib_div::array_merge_recursive_overrule($meta, $imgsize);
         }
         $metaExtractServices = array();
         $extraServiceTypes = array();
         if (!isset($meta['fields']['meta']['EXIF']) and !$meta['exif_done']) {
             $metaExtractServices[TXDAM_mtype_image][] = 'image:exif';
         }
         if (!isset($meta['fields']['meta']['IPTC']) and !$meta['iptc_done'] and (!isset($meta['fields']['meta']['XMP']) and !$meta['xmp_done'])) {
             $metaExtractServices[TXDAM_mtype_image][] = 'image:iptc';
         }
         if ($extraServiceTypes) {
             $metaExtractServices[TXDAM_mtype_image] = t3lib_div::array_merge($metaExtractServices[TXDAM_mtype_image], implode(', ', $extraServiceTypes));
         }
         // TODO should be possible to register other services too?!
         // read exif, iptc data
         if (is_array($metaExtractServices[$meta['fields']['media_type']])) {
             foreach ($metaExtractServices[$meta['fields']['media_type']] as $subType) {
                 if ($serviceObj = t3lib_div::makeInstanceService('metaExtract', $subType)) {
                     $serviceObj->setInputFile($pathname, $fileType);
                     $conf['meta'] = $meta;
                     if ($serviceObj->process('', '', $conf) > 0 and is_array($svmeta = $serviceObj->getOutput())) {
                         $meta = t3lib_div::array_merge_recursive_overrule($meta, $svmeta);
                     }
                     $serviceObj->__destruct();
                     unset($serviceObj);
                 }
             }
         }
         // convert extra meta data to xml
         if (is_array($meta['fields']['meta'])) {
             // content in array is expected as utf-8 because of xml functions
             $meta['fields']['meta'] = $this->array2xml($meta['fields']['meta']);
         }
         // If no title then the file-name is set as title. This will raise the hits considerably if the search matches the document name.
         if ($meta['fields']['title'] == '') {
             $meta['fields']['title'] = $this->makeTitleFromFilename($meta['fields']['file_name']);
         }
         $meta['fields']['keywords'] = $this->listBeautify($meta['fields']['keywords']);
     }
     if ($this->writeDevLog) {
         t3lib_div::devLog('getFileMetaInfo()', 'tx_dam_indexing', 0, $meta);
     }
     return $meta;
 }
 /**
  * Makes a DAM db query and collects data to be used in EB display
  *
  * @param	array		$allowedFileTypes Array list of allowed file types
  * @param	array		$disallowedFileTypes Array list of disallowed file types
  * @param	string		$mode EB mode: "db", "file", ...
  * @return	array		Array of file elements
  */
 function getFileListArr($allowedFileTypes, $disallowedFileTypes, $mode)
 {
     global $TCA;
     $filearray = array();
     //
     // Use the current selection to create a query and count selected records
     //
     $this->damSC->selection->addSelectionToQuery();
     $this->damSC->selection->qg->query['FROM']['tx_dam'] = tx_dam_db::getMetaInfoFieldList(true, array('hpixels', 'vpixels', 'caption'));
     #$this->damSC->selection->qg->addSelectFields(...
     //
     // set sorting
     //
     $allFields = tx_dam_db::getFieldListForUser('tx_dam');
     if ($this->damSC->MOD_SETTINGS['txdam_sortField']) {
         if (in_array($this->damSC->MOD_SETTINGS['txdam_sortField'], $allFields)) {
             $orderBy = 'tx_dam.' . $this->damSC->MOD_SETTINGS['txdam_sortField'];
         }
     } else {
         $orderBy = $TCA['tx_dam']['ctrl']['sortby'] ? $TCA['tx_dam']['ctrl']['sortby'] : $TCA['tx_dam']['ctrl']['default_sortby'];
         $orderBy = $GLOBALS['TYPO3_DB']->stripOrderBy($orderBy);
         $this->damSC->MOD_SETTINGS['txdam_sortField'] = $orderBy;
     }
     if ($this->damSC->MOD_SETTINGS['txdam_sortRev']) {
         $orderBy .= ' DESC';
     }
     $this->damSC->selection->qg->addOrderBy($orderBy);
     //
     // allowed media types
     //
     $allowedMediaTypes = array();
     $disallowedMediaTypes = array();
     foreach ($allowedFileTypes as $key => $type) {
         if ($mediaType = tx_dam::convert_mediaType($type)) {
             $allowedMediaTypes[] = $mediaType;
             unset($allowedFileTypes[$key]);
         }
     }
     foreach ($disallowedFileTypes as $key => $type) {
         if ($mediaType = tx_dam::convert_mediaType($type)) {
             $disallowedMediaTypes[] = $mediaType;
             unset($disallowedFileTypes[$key]);
         }
     }
     if ($allowedFileTypes) {
         $extList = implode(',', $GLOBALS['TYPO3_DB']->fullQuoteArray($allowedFileTypes, 'tx_dam'));
         $this->damSC->selection->qg->addWhere('AND tx_dam.file_type IN (' . $extList . ')', 'WHERE', 'tx_dam.file_type');
     }
     if ($disallowedFileTypes) {
         $extList = implode(',', $GLOBALS['TYPO3_DB']->fullQuoteArray($disallowedFileTypes, 'tx_dam'));
         $this->damSC->selection->qg->addWhere('AND tx_dam.file_type NOT IN (' . $extList . ')', 'WHERE', 'NOT tx_dam.file_type');
     }
     if ($allowedMediaTypes) {
         $extList = implode(',', $GLOBALS['TYPO3_DB']->fullQuoteArray($allowedMediaTypes, 'tx_dam'));
         $this->damSC->selection->qg->addWhere('AND tx_dam.media_type IN (' . $extList . ')', 'WHERE', 'tx_dam.media_type');
     }
     if ($disallowedMediaTypes) {
         $extList = implode(',', $GLOBALS['TYPO3_DB']->fullQuoteArray($disallowedMediaTypes, 'tx_dam'));
         $this->damSC->selection->qg->addWhere('AND tx_dam.media_type NOT IN (' . $extList . ')', 'WHERE', 'NOT tx_dam.media_type');
     }
     $this->damSC->selection->execSelectionQuery(TRUE);
     // any records found?
     if ($this->damSC->selection->pointer->countTotal) {
         // limit query for browsing
         $this->damSC->selection->addLimitToQuery();
         $this->damSC->selection->execSelectionQuery();
         if ($this->damSC->selection->res) {
             while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($this->damSC->selection->res)) {
                 $row = $this->enhanceItemArray($row, $mode);
                 $filearray[] = $row;
                 if (count($filearray) >= $this->damSC->selection->pointer->itemsPerPage) {
                     break;
                 }
             }
         }
     }
     return $filearray;
 }
 /**
  * Converts the media type code to a name.
  * In comparison to tx_dam::convert_mediaType() this function returns a localized name if possible.
  *
  * @param	mixed		$type Media type name or media type code to convert. Integer or 'text','image','audio','video','interactive', 'service','font','model','dataset','collection','software','application'
  * @return	mixed		Media type name or media type code
  */
 function convert_mediaType($type)
 {
     global $LANG;
     if (!strcmp($type, intval($type)) and is_object($LANG)) {
         $type = tx_dam_guifunc::getLabelFromItemlist('tx_dam', 'media_type', $type);
         $type = $LANG->sL($type);
     } else {
         // convert to code
         $type = tx_dam::convert_mediaType($type);
         // convert to localized name
         $type = tx_dam_guiFunc::convert_mediaType($type);
     }
     return $type;
 }