/** * Fetches the meta data from the index by a given file path or file info array and a hash value. * This can be used to find the meta data for a "lost" file so the file and meta data can be reconnected. * Index entries which have a current valid file but have the same hash value will be removed from the result. * It will be searched in deleted records too to find a related index entry. * This function returns an array of meta data arrays because it's possible to match more than one index entry! * The returned records may be related to an existing file! In that case changing the index entry will create a lost file again! * * @param mixed $fileInfo Is a file path or an array containing a file info from tx_dam::file_compileInfo(). * @param string $hash The hash value will 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 string $fields A list of fields to be fetched. Default is a list of fields generated by tx_dam_db::getMetaInfoFieldList(). * @param string $mode TYPO3_MODE to be used: 'FE', 'BE'. Constant TYPO3_MODE is default. * @return array Array of Meta data arrays or false. */ function meta_findDataForFile($fileInfo, $hash = '', $fields = '', $mode = TYPO3_MODE) { $rows = false; if (!is_array($fileInfo)) { $fileInfo = tx_dam::file_compileInfo($fileInfo, true); } if (is_array($fileInfo)) { if (!$hash and @is_file(tx_dam::file_absolutePath($fileInfo))) { $hash = tx_dam::file_calcHash($fileInfo); } $fields = $fields ? $fields : tx_dam_db::getMetaInfoFieldList(); $where = array(); $where['enableFields'] = ''; $where['file_name'] = 'file_name=' . $GLOBALS['TYPO3_DB']->fullQuoteStr($fileInfo['file_name'], 'tx_dam'); $where['file_path'] = 'file_path=' . $GLOBALS['TYPO3_DB']->fullQuoteStr($fileInfo['file_path'], 'tx_dam'); if ($hash) { $where['hash'] = 'file_hash=' . $GLOBALS['TYPO3_DB']->fullQuoteStr($hash, 'tx_dam'); } // max 3 tries to find the record // 1: hash, name and path // 2: hash, name // 3: by hash only for ($index = 0; $index < 3; $index++) { $rowsResult = tx_dam_db::getDataWhere($fields, $where, '', '', '1'); if ($rowsResult) { $rows = array(); foreach ($rowsResult as $row) { // the file itself - we're done if ($row['file_name'] == $fileInfo['file_name'] and $row['file_path'] == $fileInfo['file_path']) { $rows[$row['uid']] = $row; break; } // a lost file if (!@is_file(tx_dam::file_absolutePath($row))) { $rows[$row['uid']] = $row; continue; } } break; } else { if (!$where['hash']) { // just leave the for-loop if there's no hash break; } switch ($index) { case 0: // search for filename AND hash unset($where['file_path']); break; case 1: // search for hash only unset($where['file_name']); break; default: break 2; } } } } return $rows; }
/** * Main function * * @return string HTML output */ function main() { global $BE_USER, $LANG, $BACK_PATH, $TCA, $TYPO3_CONF_VARS; $content = ''; $table = 'tx_dam'; // // get records by query depending on option 'Show deselected only' // $origSel = $this->pObj->selection->sl->sel; if ($this->pObj->MOD_SETTINGS['tx_dam_list_list_onlyDeselected']) { if (is_array($this->pObj->selection->sl->sel['NOT']['txdamRecords'])) { $excludeUidList = array_keys($this->pObj->selection->sl->sel['NOT']['txdamRecords']); } else { $excludeUidList = array(0); //dummy } unset($this->pObj->selection->sl->sel['NOT']['txdamRecords']); $this->pObj->selection->addSelectionToQuery(); if (is_array($excludeUidList)) { $this->pObj->selection->qg->query['WHERE']['WHERE']['NOT_txdamRecords'] = 'AND tx_dam.uid IN (' . $GLOBALS['TYPO3_DB']->cleanIntList(implode(',', $excludeUidList)) . ')'; } } else { // will display deselected unset($this->pObj->selection->sl->sel['NOT']['txdamRecords']); $this->pObj->selection->addSelectionToQuery(); } $this->pObj->selection->sl->sel = $origSel; // // set language query // $langRows = $this->pObj->getLanguages($this->pObj->defaultPid); $langCurrent = intval($this->pObj->MOD_SETTINGS['tx_dam_list_langSelector']); if (!isset($langRows[$langCurrent])) { $langCurrent = $this->pObj->MOD_SETTINGS['tx_dam_list_langSelector'] = key($langRows); } $langQuery = ''; $languageField = $TCA[$table]['ctrl']['languageField']; if ($langCurrent && $this->pObj->MOD_SETTINGS['tx_dam_list_langOverlay'] === 'exclusive') { // if ($langCurrent) { This works but create NULL columns for non-translated records so we need to use language overlay anyway $lgOvlFields = tx_dam_db::getLanguageOverlayFields($table, 'tx_dam_lgovl'); $languageField = $TCA[$table]['ctrl']['languageField']; $transOrigPointerField = $TCA[$table]['ctrl']['transOrigPointerField']; $this->pObj->selection->setSelectionLanguage($langCurrent); $this->pObj->selection->qg->query['SELECT']['tx_dam as tx_dam_lgovl'] = implode(', ', $lgOvlFields) . ', tx_dam.uid as _dlg_uid, tx_dam.title as _dlg_title'; $this->pObj->selection->qg->query['LEFT_JOIN']['tx_dam as tx_dam_lgovl'] = 'tx_dam.uid=tx_dam_lgovl.' . $transOrigPointerField; if ($this->pObj->MOD_SETTINGS['tx_dam_list_langOverlay'] === 'exclusive') { $this->pObj->selection->qg->query['WHERE']['WHERE']['tx_dam_lgovl.' . $languageField] = 'AND tx_dam_lgovl.' . $languageField . '=' . $langCurrent; $this->pObj->selection->qg->query['WHERE']['WHERE']['tx_dam_lgovl.deleted'] = 'AND tx_dam_lgovl.deleted=0'; } else { $this->pObj->selection->qg->query['WHERE']['WHERE']['tx_dam_lgovl.' . $languageField] = 'AND (tx_dam_lgovl.' . $languageField . ' IN (' . $langCurrent . ', 0, -1) )'; $this->pObj->selection->qg->query['WHERE']['WHERE']['tx_dam_lgovl.deleted'] = 'AND (tx_dam_lgovl.sys_language_uid=1 OR tx_dam.sys_language_uid=0 )'; } } else { $this->pObj->selection->qg->query['WHERE']['WHERE']['tx_dam.' . $languageField] = 'AND tx_dam.' . $languageField . ' IN (0,-1)'; } // // Add the current selection to the query // # $this->pObj->selection->addSelectionToQuery(); // // Use the current selection to create a query and count selected records // $this->pObj->selection->execSelectionQuery(TRUE); // // output header: info bar, result browser, .... // $content .= $this->pObj->guiItems->getOutput('header'); $content .= $this->pObj->doc->spacer(10); // any records found? if ($this->pObj->selection->pointer->countTotal) { // // init db list object // $dblist = t3lib_div::makeInstance('tx_dam_listrecords'); $dblist->setParameterName('form', $this->pObj->formName); $dblist->init($table); $dblist->setActionsEnv(array('currentLanguage' => $langCurrent, 'allowedLanguages' => $langRows)); // // process multi action if needed // if ($processAction = $dblist->getMultiActionCommand()) { if ($processAction['onItems'] === '_all') { $uidList = array(); $res = $this->pObj->selection->execSelectionQuery(); while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) { $uidList[] = $row['uid']; } $itemList = implode(',', $uidList); } else { $itemList = $processAction['onItems']; $uidList = t3lib_div::trimExplode(',', $itemList, true); } if ($uidList) { switch ($processAction['actionType']) { case 'url': $url = str_replace('###ITEMLIST###', $itemList, $processAction['action']); header('Location: ' . $url); exit; break; case 'tce-data': $params = ''; foreach ($uidList as $uid) { $params .= str_replace('###UID###', $uid, $processAction['action']); } $url = $GLOBALS['SOBE']->doc->issueCommand($params, -1); $url = $BACK_PATH . 'tce_db.php?&redirect=' . rawurlencode(t3lib_div::getIndpEnv('REQUEST_URI')) . '&vC=' . $BE_USER->veriCode() . '&prErr=1&uPT=1' . $params; header('Location: ' . $url); exit; break; } } } t3lib_div::loadTCA($table); // // set fields to display // $titleColumn = $TCA[$table]['ctrl']['label']; $allFields = tx_dam_db::getFieldListForUser($table); $selectedFields = t3lib_div::_GP('tx_dam_list_list_displayFields'); $selectedFields = is_array($selectedFields) ? $selectedFields : explode(',', $this->pObj->MOD_SETTINGS['tx_dam_list_list_displayFields']); // remove fields that can not be selected if (is_array($selectedFields)) { $selectedFields = array_intersect($allFields, $selectedFields); $selectedFields = array_merge(array($titleColumn), $selectedFields); } else { $selectedFields = array(); $selectedFields[] = $titleColumn; } // store field list $this->pObj->MOD_SETTINGS['tx_dam_list_list_displayFields'] = implode(',', $selectedFields); $GLOBALS['BE_USER']->pushModuleData($this->pObj->MCONF['name'], $this->pObj->MOD_SETTINGS); // // set query and sorting // $orderBy = $TCA[$table]['ctrl']['sortby'] ? 'tx_dam.' . $TCA[$table]['ctrl']['sortby'] : 'tx_dam.title'; if ($this->pObj->MOD_SETTINGS['tx_dam_list_list_sortField']) { if (in_array($this->pObj->MOD_SETTINGS['tx_dam_list_list_sortField'], $allFields)) { $orderBy = 'tx_dam.' . $this->pObj->MOD_SETTINGS['tx_dam_list_list_sortField']; if ($this->pObj->MOD_SETTINGS['tx_dam_list_list_sortRev']) { $orderBy .= ' DESC'; } } } $queryFieldList = tx_dam_db::getMetaInfoFieldList(false, $selectedFields); $this->pObj->selection->qg->addSelectFields($queryFieldList); $this->pObj->selection->qg->addOrderBy($orderBy); // // exec query // $this->pObj->selection->addLimitToQuery(); $res = $this->pObj->selection->execSelectionQuery(); // // init iterator for query // $conf = array('table' => 'tx_dam', 'countTotal' => $this->pObj->selection->pointer->countTotal); if ($langCurrent > 0 and $this->pObj->MOD_SETTINGS['tx_dam_list_langOverlay'] !== 'exclusive') { $dbIterator = new tx_dam_iterator_db_lang_ovl($res, $conf); $dbIterator->initLanguageOverlay($table, $this->pObj->MOD_SETTINGS['tx_dam_list_langSelector']); } else { $dbIterator = new tx_dam_iterator_db($res, $conf); } // // make db list // $dblist->setDataObject($dbIterator); // add columns to list $dblist->clearColumns(); $cc = 0; foreach ($selectedFields as $field) { $fieldLabel = is_array($TCA[$table]['columns'][$field]) ? preg_replace('#:$#', '', $LANG->sL($TCA[$table]['columns'][$field]['label'])) : '[' . $field . ']'; $dblist->addColumn($field, $fieldLabel); $cc++; if ($cc == 1) { // add control at second column $dblist->addColumn('_CONTROL_', ''); $cc++; } } // enable display of action column $dblist->showActions = true; // enable display of multi actions $dblist->showMultiActions = $this->pObj->MOD_SETTINGS['tx_dam_list_list_showMultiActions']; // enable context menus $dblist->enableContextMenus = $this->pObj->config_checkValueEnabled('contextMenuOnListItems', true); // Enable/disable display of thumbnails $dblist->showThumbs = $this->pObj->MOD_SETTINGS['tx_dam_list_list_showThumb']; // Enable/disable display of AlternateBgColors $dblist->showAlternateBgColors = $this->pObj->config_checkValueEnabled('alternateBgColors', true); $dblist->setPointer($this->pObj->selection->pointer); $dblist->setCurrentSorting($this->pObj->MOD_SETTINGS['tx_dam_list_list_sortField'], $this->pObj->MOD_SETTINGS['tx_dam_list_list_sortRev']); $dblist->setParameterName('sortField', 'SET[tx_dam_list_list_sortField]'); $dblist->setParameterName('sortRev', 'SET[tx_dam_list_list_sortRev]'); $this->pObj->doc->JScodeArray['dblist-JsCode'] = $dblist->getJsCode(); // todo Clipboard // It is set, if the clickmenu-layer is active AND the extended view is not enabled. # $dblist->dontShowClipControlPanels = $CLIENT['FORMSTYLE'] && !$BE_USER->uc['disableCMlayers']; #$content.= '<form action="'.htmlspecialchars(t3lib_div::linkThisScript()).'" method="post" name="'.$dblist->paramName['form'].'">'; // get all avalibale languages for the page if ($languageSwitch = $this->pObj->languageSwitch($langRows, intval($this->pObj->MOD_SETTINGS['tx_dam_list_langSelector']))) { $this->pObj->markers['LANGUAGE_SELECT'] = '<div class="languageSwitch">' . $languageSwitch . '</div>'; } else { $this->pObj->markers['LANGUAGE_SELECT'] = ''; } // wraps the list table with the form $content .= tx_dam_SCbase::getFormTag(); $content .= $dblist->getListTable(); $content .= '</form>'; $fieldSelectBoxContent = $this->fieldSelectBox($table, $allFields, $selectedFields); $content .= $this->pObj->buttonToggleDisplay('fieldselector', $LANG->getLL('field_selector'), $fieldSelectBoxContent); } else { // no search result: showing selection box if ($languageSwitch = $this->pObj->languageSwitch($langRows, intval($this->pObj->MOD_SETTINGS['tx_dam_list_langSelector']))) { $this->pObj->markers['LANGUAGE_SELECT'] = '<div class="languageSwitch">' . $languageSwitch . '</div>'; } else { $this->pObj->markers['LANGUAGE_SELECT'] = ''; } // is in footer now $content .= $this->pObj->getCurrentSelectionBox(); } return $content; }
/** * Set the Information of the images if mode = dam * * @param boolean $fromCategory * @return boolean */ protected function setDataDam($fromCategory = false, $table = 'tt_content', $uid = 0) { // clear the imageDir $this->imageDir = ''; // get all fields for captions $damCaptionFields = t3lib_div::trimExplode(',', $this->conf['damCaptionFields'], true); $damDescFields = t3lib_div::trimExplode(',', $this->conf['damDescFields'], true); $damHrefFields = t3lib_div::trimExplode(',', $this->conf['damHrefFields'], true); $fieldsArray = array_merge($damCaptionFields, $damDescFields, $damHrefFields); $fields = NULL; if (count($fieldsArray) > 0) { foreach ($fieldsArray as $field) { $fields .= ',tx_dam.' . $field; } } if ($fromCategory === true) { // Get the images from dam category $damcategories = $this->getDamcats($this->lConf['damcategories']); $res = $GLOBALS['TYPO3_DB']->exec_SELECT_mm_query(tx_dam_db::getMetaInfoFieldList() . $fields, 'tx_dam', 'tx_dam_mm_cat', 'tx_dam_cat', " AND tx_dam_cat.uid IN (" . implode(",", $damcategories) . ")", '', 'tx_dam.sorting', ''); while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) { $images['rows'][] = $row; } } else { // Get the images from dam $images = tx_dam_db::getReferencedFiles($table, $uid, 'imagecarousel', 'tx_dam_mm_ref', tx_dam_db::getMetaInfoFieldList() . $fields, '', '', 'tx_dam_mm_ref.sorting_foreign'); } if (count($images['rows']) > 0) { // overlay the translation $conf = array('sys_language_uid' => $this->sys_language_uid, 'lovl_mode' => ''); // add image foreach ($images['rows'] as $key => $row) { $row = tx_dam_db::getRecordOverlay('tx_dam', $row, $conf); $absFileName = t3lib_div::getFileAbsFileName($row['file_path'] . $row['file_name']); $size = @getimagesize($absFileName); if (preg_match("/^image\\//i", $size['mime'])) { // set the data $this->images[] = $row['file_path'] . $row['file_name']; ${$href} = ''; unset($href); if (count($damHrefFields) > 0) { foreach ($damHrefFields as $damHrefField) { if (!isset($href) && trim($row[$damHrefField])) { $href = $row[$damHrefField]; break; } } } $this->hrefs[] = $href; // set the caption $caption = ''; unset($caption); if (count($damCaptionFields) > 0) { if (isset($this->conf['damCaptionObject'])) { foreach ($damCaptionFields as $damCaptionField) { if (isset($row[$damCaptionField])) { $GLOBALS['TSFE']->register['dam_' . $damCaptionField] = $row[$damCaptionField]; } } $caption = trim($this->cObj->cObjGetSingle($this->conf['damCaptionObject'], $this->conf['damCaptionObject.'])); // Unset the registered values foreach ($damCaptionFields as $damCaptionField) { unset($GLOBALS['TSFE']->register['dam_' . $damCaptionField]); } } else { // the old way foreach ($damCaptionFields as $damCaptionField) { if (!isset($caption) && trim($row[$damCaptionField])) { $caption = $row[$damCaptionField]; break; } } } } $this->captions[] = $caption; // set the description $description = ''; unset($description); if (count($damDescFields) > 0) { if (isset($this->conf['damDescObject'])) { foreach ($damDescFields as $damDescField) { if (isset($row[$damDescField])) { $GLOBALS['TSFE']->register['dam_' . $damDescField] = $row[$damDescField]; } } $description = trim($this->cObj->cObjGetSingle($this->conf['damDescObject'], $this->conf['damDescObject.'])); // Unset the registered values foreach ($damDescFields as $damDescField) { unset($GLOBALS['TSFE']->register['dam_' . $damDescField]); } } else { // the old way foreach ($damDescFields as $damDescField) { if (!isset($description) && trim($row[$damDescField])) { $description = $row[$damDescField]; break; } } } } $this->description[] = $description; } } } return true; }
/** * Hat der DAM Eintrag noch Referenzen? * * @return bool */ public static function damRecordHasReferences($iLocalUid, $foreign_table = '', $foreign_uid = '', $MM_ident = '', $MM_table = 'tx_dam_mm_ref', $options = array()) { if (!self::isLoaded()) { return false; } require_once t3lib_extMgm::extPath('dam') . 'lib/class.tx_dam_db.php'; $fields = tx_dam_db::getMetaInfoFieldList(); $res = tx_dam_db::referencesQuery('tx_dam', $iLocalUid, $foreign_table, $foreign_uid, $MM_ident, $MM_table, $fields); if ($res && ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res))) { return true; } //else return false; }
/** * Creates a list of indexed files by uid * * @param string $uidList Comma list of uid's * @param mixed $res DB result pointer. If set will be used to fetch records instead of the $uidList. * @return array Data * @todo this could be less lowlevel (media objects?) */ function compileItemArray($uidList, $res = FALSE) { global $BACK_PATH, $LANG; $items = array(); if ($res) { $GLOBALS['TYPO3_DB']->sql_data_seek($res, 0); } else { $infoFields = tx_dam_db::getMetaInfoFieldList(); $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($infoFields, 'tx_dam', 'tx_dam.uid IN (' . $GLOBALS['TYPO3_DB']->cleanIntList($uidList) . ')'); } while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) { $items[$row['uid']] = array('uid' => $row['uid'], 'meta' => $row, 'meta_is_all' => 0, 'errors' => array()); } return $items; }
/** * "Finding" the files belonging to tx_dam records. * * @param string The uid of the record from $table * @param string The filename (usually found in field "file_name") * @param array Parameters set for the softref parser key in TCA/columns (currently unused) * @return array Result array on positive matches, containing one or null results */ function findRef_dam_file($uid, $fileName, $spParams) { $resultArray = array(); $fileInfo = tx_dam::meta_getDataByUid($uid, tx_dam_db::getMetaInfoFieldList() . ', description'); if ($fileInfo) { $file = $fileInfo['file_path'] . $fileInfo['file_name']; $tokenID = $this->makeTokenID(0); $resultArray = array('content' => '{softref:' . $tokenID . '}', 'elements' => array(0 => array('matchString' => $fileName, 'subst' => array('type' => 'file', 'tokenID' => $tokenID, 'tokenValue' => $fileName, 'relFileName' => $file, 'title' => $fileInfo['title'], 'description' => $fileInfo['description'])))); if (!@is_file(tx_dam::file_absolutePath($fileInfo))) { // Finally, notice if the file does not exist. $resultArray['elements'][0]['error'] = 'File does not exist!'; } } return $resultArray; }
/** * Make a list of files by a mm-relation to the tx_dam table which is used to get eg. the references tt_content<>tx_dam * * Returns: * array ( * 'files' => array( * record-uid => 'fileadmin/example.jpg', * ) * 'rows' => array( * record-uid => array(meta data array), * ) * ); * * @param string $foreign_table Table name to get references for. Eg tt_content * @param integer $foreign_uid The uid of the referenced record * @param mixed $MM_ident Array of field/value pairs that should match in MM table. If it is a string, it will be used as value for the field 'ident'. * @param string $MM_table The mm table to use. Default: tx_dam_mm_ref * @param string $fields The fields to select. Needs to be prepended with table name: tx_dam.uid, tx_dam.title * @param array $whereClauses WHERE clauses as array with associative keys (which can be used to overwrite 'enableFields') or a single one as string. * @param string $groupBy: ... * @param string $orderBy: ... * @param string $limit: Default: 1000 * @return array ... */ function getReferencedFiles($foreign_table = '', $foreign_uid = '', $MM_ident = '', $MM_table = 'tx_dam_mm_ref', $fields = '', $whereClauses = array(), $groupBy = '', $orderBy = '', $limit = 1000) { $fields = $fields ? $fields : tx_dam_db::getMetaInfoFieldList(); $local_table = 'tx_dam'; $files = array(); $rows = array(); $res = tx_dam_db::referencesQuery($local_table, '', $foreign_table, $foreign_uid, $MM_ident, $MM_table, $fields, $whereClauses, $groupBy, $orderBy, $limit); if ($res) { while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) { $files[$row['uid']] = $row['file_path'] . $row['file_name']; $rows[$row['uid']] = $row; } } return array('files' => $files, 'rows' => $rows); }
/** * Makes a DAM db query and collects data to be used in EB display * * @param string $allowedFileTypes Comma list of allowed file types * @param string $disallowedFileTypes Comma list of disallowed file types * @param string $mode EB mode: "db", "file", ... * @return array Array of file elements */ function getFileListArr($allowedFileTypes, $disallowedFileTypes, $mode) { global $TYPO3_CONF_VARS, $TYPO3_DB; $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', $this->imgTitleDAMColumn, 'alt_text')); #$this->damSC->selection->qg->addSelectFields(... if ($allowedFileTypes) { $extList = '"' . implode('","', explode(',', $allowedFileTypes)) . '"'; $this->damSC->selection->qg->addWhere('AND tx_dam.file_type IN (' . $extList . ')', 'WHERE', 'tx_dam.file_type'); } if ($disallowedFileTypes) { $extList = '"' . implode('","', explode(',', $disallowedFileTypes)) . '"'; $this->damSC->selection->qg->addWhere('AND NOT tx_dam.file_type IN (' . $extList . ')', 'WHERE', 'NOT tx_dam.file_type'); } if ($this->act == 'plain') { $this->damSC->selection->qg->addWhere('AND tx_dam.hpixels <= ' . intval($this->plainMaxWidth), 'WHERE', 'tx_dam.hpixels'); $this->damSC->selection->qg->addWhere('AND tx_dam.vpixels <= ' . intval($this->plainMaxHeight), 'WHERE', 'tx_dam.vpixels'); } $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 = $TYPO3_DB->sql_fetch_assoc($this->damSC->selection->res)) { $row['file_title'] = $row['title'] ? $row['title'] : $row['file_name']; $row['file_path_absolute'] = tx_dam::path_makeAbsolute($row['file_path']); $row['file_name_absolute'] = $row['file_path_absolute'] . $row['file_name']; $row['__exists'] = @is_file($row['file_name_absolute']); if ($mode == 'db') { $row['_ref_table'] = 'tx_dam'; $row['_ref_id'] = $row['uid']; $row['_ref_file_path'] = ''; } else { $row['_ref_table'] = ''; $row['_ref_id'] = t3lib_div::shortMD5($row['file_name_absolute']); $row['_ref_file_path'] = $row['file_name_absolute']; } $filearray[] = $row; if (count($filearray) >= $this->damSC->selection->pointer->itemsPerPage) { break; } } } } return $filearray; }
/** * Main function * * @return string HTML output */ function main() { global $BE_USER, $LANG, $BACK_PATH, $TCA, $TYPO3_CONF_VARS; $content = ''; $table = 'tx_dam'; // // get records by query depending on option 'Show deselected only' // $origSel = $this->pObj->selection->sl->sel; if ($this->pObj->MOD_SETTINGS['tx_dam_list_editsel_onlyDeselected']) { if (is_array($this->pObj->selection->sl->sel['NOT']['txdamRecords'])) { $ids = array_keys($this->pObj->selection->sl->sel['NOT']['txdamRecords']); } else { $ids = array(0); //dummy } unset($this->pObj->selection->sl->sel['NOT']['txdamRecords']); $this->pObj->selection->addSelectionToQuery(); if (is_array($ids)) { $this->pObj->selection->qg->query['WHERE']['WHERE']['NOT_txdamRecords'] = 'AND tx_dam.uid IN (' . $GLOBALS['TYPO3_DB']->cleanIntList(implode(',', $ids)) . ')'; } } else { unset($this->pObj->selection->sl->sel['NOT']['txdamRecords']); $this->pObj->selection->addSelectionToQuery(); } $this->pObj->selection->sl->sel = $origSel; // // Use the current selection to create a query and count selected records // $this->pObj->selection->execSelectionQuery(TRUE); // // output header: info bar, result browser, .... // $content .= $this->pObj->guiItems->getOutput('header'); $content .= $this->pObj->doc->spacer(10); // // current selection box // $content .= $this->pObj->getCurrentSelectionBox(); $content .= $this->pObj->doc->spacer(25); // any records found? if ($this->pObj->selection->pointer->countTotal) { t3lib_div::loadTCA($table); // // set fields to display // $titleColumn = $TCA[$table]['ctrl']['label']; $allFields = tx_dam_db::getFieldListForUser($table); $selectedFields = t3lib_div::_GP('tx_dam_list_list_displayFields'); $selectedFields = is_array($selectedFields) ? $selectedFields : explode(',', $this->pObj->MOD_SETTINGS['tx_dam_list_list_displayFields']); // remove fields that can not be selected if (is_array($selectedFields)) { $selectedFields = array_intersect($allFields, $selectedFields); $selectedFields = array_merge(array($titleColumn), $selectedFields); } else { $selectedFields = array(); $selectedFields[] = $titleColumn; } // store field list $this->pObj->MOD_SETTINGS['tx_dam_list_list_displayFields'] = implode(',', $selectedFields); $GLOBALS['BE_USER']->pushModuleData($this->pObj->MCONF['name'], $this->pObj->MOD_SETTINGS); // // set query and sorting // $orderBy = $TCA[$table]['ctrl']['sortby'] ? 'tx_dam.' . $TCA[$table]['ctrl']['sortby'] : 'tx_dam.title'; if ($this->pObj->MOD_SETTINGS['tx_dam_list_list_sortField']) { if (in_array($this->pObj->MOD_SETTINGS['tx_dam_list_list_sortField'], $allFields)) { $orderBy = 'tx_dam.' . $this->pObj->MOD_SETTINGS['tx_dam_list_list_sortField']; if ($this->pObj->MOD_SETTINGS['tx_dam_list_list_sortRev']) { $orderBy .= ' DESC'; } } } $queryFieldList = tx_dam_db::getMetaInfoFieldList(false, $selectedFields); $this->pObj->selection->qg->addSelectFields($queryFieldList); $this->pObj->selection->qg->addOrderBy($orderBy); // // exec query // $this->pObj->selection->addLimitToQuery(); $res = $this->pObj->selection->execSelectionQuery(); // // init iterator for query // $conf = array('table' => 'tx_dam', 'countTotal' => $this->pObj->selection->pointer->countTotal); $dbIterator = new tx_dam_iterator_db($res, $conf); // // make db list // $dblist = t3lib_div::makeInstance('tx_dam_listrecords'); $dblist->init($table, $dbIterator); $dblist->setDataObject($dbIterator); // add columns to list $dblist->clearColumns(); $cc = 0; foreach ($selectedFields as $field) { $fieldLabel = is_array($TCA[$table]['columns'][$field]) ? preg_replace('#:$#', '', $LANG->sL($TCA[$table]['columns'][$field]['label'])) : '[' . $field . ']'; $dblist->addColumn($field, $fieldLabel); $cc++; if ($cc == 1) { // add control at second column $dblist->addColumn('_CONTROL_', ''); $cc++; } } // enable display of action column $dblist->showActions = true; // enable context menus $dblist->enableContextMenus = true; // Enable/disable display of thumbnails $dblist->showThumbs = $this->pObj->MOD_SETTINGS['tx_dam_list_list_showThumb']; // Enable/disable display of AlternateBgColors $dblist->showAlternateBgColors = $this->pObj->config_checkValueEnabled('alternateBgColors', true); $dblist->setPointer($this->pObj->selection->pointer); $dblist->setCurrentSorting($this->pObj->MOD_SETTINGS['tx_dam_list_list_sortField'], $this->pObj->MOD_SETTINGS['tx_dam_list_list_sortRev']); $dblist->setParameterName('sortField', 'SET[tx_dam_list_list_sortField]'); $dblist->setParameterName('sortRev', 'SET[tx_dam_list_list_sortRev]'); #$content.= '<form action="'.htmlspecialchars(t3lib_div::linkThisScript()).'" method="post" name="dblistForm">'; $content .= $dblist->getListTable(); #$content.= '<input type="hidden" name="cmd_table"><input type="hidden" name="cmd"></form>'; $fieldSelectBoxContent = $this->fieldSelectBox($table, $allFields, $selectedFields); $content .= $this->pObj->buttonToggleDisplay('fieldselector', $LANG->getLL('field_selector'), $fieldSelectBoxContent); } return $content; }
/** * 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; }
/** * Returns an array with reference items + an array with the sorted items * * @param string $selection: reference to a selection object * @param array $columns: Array of column names required from the entries * @return void */ function read(&$selection, $columns) { $local_table = 'tx_dam'; $softRef_table = 'sys_refindex'; $tracking_table = 'tx_dam_file_tracking'; // Use the current selection to create a query and count selected records $selection->qg->query['DISTINCT'] = false; $selection->addSelectionToQuery(); $countTotal = 0; // Save selection where for softRef query $queryParts = $selection->qg->getQueryParts(); $softRefWhere = $queryParts['WHERE']; // Look for references in mm table $selection->qg->queryAddMM($mm_table = 'tx_dam_mm_ref', $foreign_table = '', $local_table); $selection->prepareSelectionQuery(TRUE); $queryArr = $selection->qg->getQueryParts(); $res = $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($queryArr); if ($res) { list($countTotal) = $GLOBALS['TYPO3_DB']->sql_fetch_row($res); } // If we have a selection... if ($selection->sl->hasSelection()) { // Look for references in refindex table $fields = ' COUNT(' . $local_table . '.uid) as count'; $res = tx_dam_db::softRefIndexQuery($local_table, '', '', '', '', '', $fields, array($softRefWhere)); if ($res) { list($softRefCountTotal) = $GLOBALS['TYPO3_DB']->sql_fetch_row($res); $countTotal += $softRefCountTotal; } // Look for references in file tracking table $where = array($softRefWhere); $where[] = $tracking_table . '.file_hash=' . $local_table . '.file_hash'; // use index to preselect records $where[] = $softRef_table . '.ref_string = CONCAT(' . $tracking_table . '.file_path,' . $tracking_table . '.file_name)'; $where[] = $softRef_table . '.ref_string LIKE CONCAT(' . $tracking_table . '.file_path,' . $tracking_table . '.file_name)'; $whereClause = implode(' AND ', $where); $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($fields, $local_table . ',' . $tracking_table . ',' . $softRef_table, $whereClause, '', '', 1000); if ($res) { list($fileTrackingCountTotal) = $GLOBALS['TYPO3_DB']->sql_fetch_row($res); $countTotal += $fileTrackingCountTotal; } } // If we have references.. if ($countTotal) { $rows = array(); // Get references from mm table $selection->qg->query['FROM'][$local_table] = tx_dam_db::getMetaInfoFieldList(); $selection->qg->query['FROM']['tx_dam_mm_ref'] = 'tx_dam_mm_ref.uid_foreign,tx_dam_mm_ref.tablenames,tx_dam_mm_ref.ident'; $selection->qg->addOrderBy('tablenames', 'tx_dam_mm_ref'); $selection->qg->addLimit($countTotal); $selection->prepareSelectionQuery(FALSE); $queryArr = $selection->qg->getQueryParts(); $res = $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($queryArr); if ($res) { while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) { $rows[] = $row; } } // Get soft references $queryParts = $selection->qg->getQueryParts(); $fields = tx_dam_db::getMetaInfoFieldList() . ', ' . $softRef_table . '.tablename AS tablenames, ' . $softRef_table . '.recuid AS uid_foreign, ' . $softRef_table . '.ref_uid AS uid_local, ' . $softRef_table . '.field, ' . $softRef_table . '.softref_key'; $res = tx_dam_db::softRefIndexQuery($local_table, '', '', '', '', '', $fields, array($softRefWhere), $queryParts['GROUPBY'], $queryParts['ORDERBY'], $queryParts['LIMIT']); if ($res) { while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) { $rows[] = $row; } } // Look for references in file tracking table $uids = array(); $fields = $local_table . '.uid'; $where = array($softRefWhere); $where[] = $tracking_table . '.file_hash=' . $local_table . '.file_hash'; // use index to preselect records $where[] = $softRef_table . '.ref_string = CONCAT(' . $tracking_table . '.file_path,' . $tracking_table . '.file_name)'; $where[] = $softRef_table . '.ref_string LIKE CONCAT(' . $tracking_table . '.file_path,' . $tracking_table . '.file_name)'; $whereClause = implode(' AND ', $where); $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($fields, $local_table . ',' . $tracking_table . ',' . $softRef_table, $whereClause, '', '', 1000); if ($res) { while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) { $uids[] = $row['uid']; } } // Get upload references $rows = array_merge($rows, tx_dam_db::getMediaUsageUploads(implode(',', array_unique($uids)), '', '')); // Post-process these rows to produce the reference entries array $this->processEntries($rows, $columns); } // Set the pointer $selection->pointer->setTotalCount(count($this->entries)); if (count($this->entries)) { $this->sort('page'); $this->rewind(); } }