Пример #1
0
 /**
  * Returns an array which describes the type of a file.
  *
  * example:
  * $mimeType = array();
  * $mimeType['file_mime_type'] = 'audio';
  * $mimeType['file_mime_subtype'] = 'x-mpeg';
  * $mimeType['file_type'] = 'mp3';
  *
  * @param	mixed		$fileInfo Is a file path or an array containing a file info from tx_dam::file_compileInfo().
  * @return	array		Describes the type of a file
  */
 function file_getType($fileInfo)
 {
     global $TYPO3_CONF_VARS;
     $mimeType = array();
     if (is_array($fileInfo) and $fileInfo['file_mime_type']) {
         $mimeType = array();
         $mimeType['file_mime_type'] = $fileInfo['file_mime_type'];
         $mimeType['file_mime_subtype'] = $fileInfo['file_mime_subtype'];
         $mimeType['file_type'] = $fileInfo['file_type'];
     } elseif ($uid = tx_dam::file_isIndexed($fileInfo)) {
         $mimeType = tx_dam::meta_getDataByUid($uid, 'file_mime_type,file_mime_subtype,file_type,media_type');
     } else {
         require_once PATH_txdam . 'lib/class.tx_dam_indexing.php';
         $mimeType = tx_dam_indexing::getFileMimeType($fileInfo);
     }
     return $mimeType;
 }
    /**
     * Generates the module content
     *
     * @return	string		HTML content
     */
    function moduleContent()
    {
        global $BE_USER, $LANG, $BACK_PATH, $TYPO3_CONF_VARS;
        $content = '';
        $func = $this->pObj->MOD_SETTINGS['tx_dam_tools_indexupdate.func'];
        if (t3lib_div::_GP('start')) {
            $func .= '.start';
        }
        if (t3lib_div::_GP('process')) {
            $func .= '.process';
        }
        // reload at this time
        $max_execution_time = ini_get('max_execution_time');
        $max_execution_time = intval($max_execution_time / 3 * 2);
        $this->indexEndtime = time() + $max_execution_time;
        switch ($func) {
            case 'lost_records':
                $content .= $this->pObj->doc->section($LANG->getLL('tx_dam_tools_indexupdate.lost_records_check'), $LANG->getLL('tx_dam_tools_indexupdate.lost_records_description', 1), 0, 1);
                $content .= $this->pObj->doc->spacer(10);
                if (t3lib_div::_GP('collect_lost_records')) {
                    $values = array('pid' => $this->pObj->defaultPid);
                    $mediaTables = tx_dam::register_getEntries('mediaTable');
                    foreach ($mediaTables as $table) {
                        $res = $GLOBALS['TYPO3_DB']->exec_UPDATEquery($table, $table . '.pid NOT IN (' . tx_dam_db::getPidList() . ')', $values);
                    }
                }
                list($lostRecordsFound, $statisticsLostRecords) = $this->statisticsLostRecords();
                if ($lostRecordsFound) {
                    $content .= $statisticsLostRecords;
                    $content .= $this->pObj->doc->spacer(10);
                    $content .= '<p><input type="submit" name="collect_lost_records" value="' . $LANG->getLL('tx_dam_tools_indexupdate.lost_records_collect') . '" /></p>';
                } else {
                    $content .= '<p><strong>' . $LANG->getLL('tx_dam_tools_indexupdate.lost_records_all_fine') . '</strong></p>';
                    $content .= $statisticsLostRecords;
                    $content .= $this->pObj->doc->spacer(10);
                    $content .= '<p><input type="submit" name="" value="' . $LANG->getLL('tx_dam_tools_indexupdate.lost_records_check_again') . '" /></p>';
                }
                break;
            case 'cleanup_meta':
                $content .= $this->pObj->doc->section($LANG->getLL('tx_dam_tools_indexupdate.cleanup_meta'), $LANG->getLL('tx_dam_tools_indexupdate.cleanup_meta_description', 1), 0, 1);
                $content .= $this->pObj->doc->spacer(10);
                if (t3lib_div::_GP('cleanup_meta')) {
                    $countTotal = 0;
                    $res = $GLOBALS['TYPO3_DB']->exec_UPDATEquery('tx_dam', 'color_space=' . $GLOBALS['TYPO3_DB']->fullQuoteStr('sRGB', 'tx_dam'), array('color_space' => 'RGB'));
                    $countTotal += $GLOBALS['TYPO3_DB']->sql_affected_rows();
                    $rows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('uid,title,file_name', 'tx_dam', 'title=\'\'');
                    foreach ($rows as $row) {
                        $title = tx_dam_indexing::makeTitleFromFilename($row['file_name']);
                        $values = array('title' => $title);
                        $res = $GLOBALS['TYPO3_DB']->exec_UPDATEquery('tx_dam', 'uid=' . $row['uid'], $values);
                        $countTotal++;
                    }
                    $content .= '<h4>Processing: ' . $countTotal . ' changes made</h4>';
                }
                $content .= '<h4>Available functions:</h4>';
                $content .= '<ul>';
                $content .= '<li>Create title for empty titles</li>';
                $content .= '<li>Change unused color space \'sRGB\' to \'RGB\'</li>';
                $content .= '</ul>';
                $content .= $this->pObj->doc->spacer(10);
                $content .= '<p><input type="submit" name="cleanup_meta" value="' . $LANG->getLL('tx_dam_tools_indexupdate.cleanup_meta') . '" /></p>';
                break;
            case 'statistics':
                $content .= $this->pObj->doc->section($LANG->getLL('tx_dam_tools_indexupdate.statistics'), $LANG->getLL('tx_dam_tools_indexupdate.statistics_description', 1), 0, 1);
                $content .= $this->pObj->doc->spacer(10);
                $content .= $this->statisticsMediaType();
                $content .= $this->pObj->doc->spacer(10);
                $content .= '<p><input type="submit" name="update" value="' . $LANG->getLL('tx_dam_tools_indexupdate.update') . '" /></p>';
                break;
            case 'index':
                $content .= $this->pObj->doc->section($LANG->getLL('tx_dam_tools_indexupdate.index_check'), $LANG->getLL('tx_dam_tools_indexupdate.index_description', 1), 0, 1);
                $content .= $this->pObj->doc->spacer(10);
                $code = '';
                $ageMenu = t3lib_BEfunc::getFuncMenu('', 'SET[tx_dam_tools_indexupdate.age]', $this->pObj->MOD_SETTINGS['tx_dam_tools_indexupdate.age'], $this->pObj->MOD_MENU['tx_dam_tools_indexupdate.age']);
                $ageMenu = preg_replace('#onchange="[^"]*"#', '', $ageMenu);
                $code .= '<p>' . $LANG->getLL('tx_dam_tools_indexupdate.age') . ': ' . $ageMenu . '<br /><span class="typo3-dimmed">' . $LANG->getLL('tx_dam_tools_indexupdate.age_descr') . '</span></p>';
                $code .= '<p><br /></p>';
                $code .= '<p>';
                $code .= '<input type="hidden" name="SET[tx_dam_tools_indexupdate.deleteMissing]" value="0">';
                $code .= '<input type="checkbox" ' . ($this->pObj->MOD_SETTINGS['tx_dam_tools_indexupdate.deleteMissing'] ? 'checked="checked"' : '') . ' name="SET[tx_dam_tools_indexupdate.deleteMissing]" id="SET.tx_dam_tools_indexupdate.deleteMissing" value="1"> ' . '<label for="SET.tx_dam_tools_indexupdate.deleteMissing">' . $LANG->getLL('tx_dam_tools_indexupdate.deleteMissing', 1) . '</label>';
                $code .= '<br /><span class="typo3-dimmed">' . $LANG->getLL('tx_dam_tools_indexupdate.deleteMissing_descr') . '</span></p>';
                $code .= '</p>';
                $code .= '<p><br /></p>';
                $code .= '<p><input type="submit" name="start" /></p>';
                $content .= $code;
                $code = '';
                $rows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('COUNT(uid) as count', 'tx_dam', $where_clause = '');
                reset($rows);
                $row = current($rows);
                $countTotal = $row['count'];
                $code = sprintf($LANG->getLL('tx_dam_tools_indexupdate.count_elements', 1), $countTotal);
                $content .= $this->pObj->doc->spacer(10);
                $content .= $this->pObj->doc->section($LANG->getLL('tx_dam_tools_indexupdate.statistics'), $code, 0, 1);
                break;
            case 'index.start':
                $code = '';
                $this->pObj->addParams['process'] = 1;
                $content .= $this->pObj->doc->section($LANG->getLL('tx_dam_tools_indexupdate.updatedFiles'), '', 0, 1);
                $content .= $this->pObj->doc->spacer(10);
                $code .= $this->indexing_getProgessTable();
                $content .= $this->pObj->doc->section('', $code, 0, 1);
                break;
            case 'index.process':
                $this->pObj->addParams['process'] = 1;
                echo '<head>
					<title>indexing</title>
					<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
					</head>
					<body>';
                $this->checkIndex(t3lib_div::_GP('indexSessionID'));
                echo '</body>
					</html>';
                exit;
                break;
            case 'uploads':
                $content .= $this->pObj->doc->spacer(10);
                $content .= $LANG->getLL('tx_dam_tools_indexupdate.description', 1);
                $code = '';
                $code .= $LANG->getLL('tx_dam_tools_indexupdate.uploads_description', 1);
                $code .= $this->pObj->doc->spacer(10);
                $code .= '<p><input type="submit" name="start" /></p>';
                $content .= $this->pObj->doc->section($LANG->getLL('tx_dam_tools_indexupdate.uploads_check'), $code, 0, 1);
                $code = '';
                $rows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('COUNT(uid) as count', 'tx_dam_file_tracking', $where_clause = '');
                reset($rows);
                $row = current($rows);
                $countTotal = $row['count'];
                $code .= sprintf($LANG->getLL('tx_dam_tools_indexupdate.count_elements', 1), $countTotal);
                $content .= $this->pObj->doc->spacer(10);
                $content .= $this->pObj->doc->section($LANG->getLL('tx_dam_tools_indexupdate.statistics'), $code, 0, 1);
                break;
            case 'uploads.start':
                $code = '';
                $this->pObj->addParams['process'] = 1;
                $content .= $this->pObj->doc->section($LANG->getLL('tx_dam_tools_indexupdate.updatedFiles'), '', 0, 1);
                $content .= $this->pObj->doc->spacer(10);
                $code .= $this->indexing_getProgessTable();
                $content .= $this->pObj->doc->section('', $code, 0, 1);
                break;
            case 'uploads.process':
                $this->pObj->addParams['process'] = 1;
                echo '<head>
					<title>indexing</title>
					<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
					</head>
					<body>';
                $this->checkUploads(t3lib_div::_GP('indexSessionID'));
                echo '</body>
					</html>';
                exit;
                break;
        }
        return $content;
    }
 function processMeta($meta)
 {
     $meta['fields']['title'] = tx_dam_indexing::makeTitleFromFilename($meta['fields']['file_name']);
     return $meta;
 }