/** * The main method of the PlugIn * * @access public * * @param string $content: The PlugIn content * @param array $conf: The PlugIn configuration * * @return string The content that is displayed on the website */ public function main($content, $conf) { $this->init($conf); // Turn cache on. $this->setCache(TRUE); // Quit without doing anything if required configuration variables are not set. if (empty($this->conf['pages'])) { if (TYPO3_DLOG) { \TYPO3\CMS\Core\Utility\GeneralUtility::devLog('[tx_dlf_statistics->main(' . $content . ', [data])] Incomplete plugin configuration', $this->extKey, SYSLOG_SEVERITY_WARNING, $conf); } return $content; } // Get description. $content .= $this->pi_RTEcssText($this->conf['description']); // Check for selected collections. if ($this->conf['collections']) { // Include only selected collections. $resultTitles = $GLOBALS['TYPO3_DB']->exec_SELECT_mm_query('tx_dlf_documents.uid AS uid', 'tx_dlf_documents', 'tx_dlf_relations', 'tx_dlf_collections', 'AND tx_dlf_documents.pid=' . intval($this->conf['pages']) . ' AND tx_dlf_collections.pid=' . intval($this->conf['pages']) . ' AND tx_dlf_documents.partof=0 AND tx_dlf_collections.uid IN (' . $GLOBALS['TYPO3_DB']->cleanIntList($this->conf['collections']) . ') AND tx_dlf_relations.ident=' . $GLOBALS['TYPO3_DB']->fullQuoteStr('docs_colls', 'tx_dlf_relations') . tx_dlf_helper::whereClause('tx_dlf_documents') . tx_dlf_helper::whereClause('tx_dlf_collections'), 'tx_dlf_documents.uid', '', ''); $resultVolumes = $GLOBALS['TYPO3_DB']->exec_SELECT_mm_query('tx_dlf_documents.uid AS uid', 'tx_dlf_documents', 'tx_dlf_relations', 'tx_dlf_collections', 'AND tx_dlf_documents.pid=' . intval($this->conf['pages']) . ' AND tx_dlf_collections.pid=' . intval($this->conf['pages']) . ' AND NOT tx_dlf_documents.uid IN (SELECT DISTINCT tx_dlf_documents.partof FROM tx_dlf_documents WHERE NOT tx_dlf_documents.partof=0' . tx_dlf_helper::whereClause('tx_dlf_documents') . ') AND tx_dlf_collections.uid IN (' . $GLOBALS['TYPO3_DB']->cleanIntList($this->conf['collections']) . ') AND tx_dlf_relations.ident=' . $GLOBALS['TYPO3_DB']->fullQuoteStr('docs_colls', 'tx_dlf_relations') . tx_dlf_helper::whereClause('tx_dlf_documents') . tx_dlf_helper::whereClause('tx_dlf_collections'), 'tx_dlf_documents.uid', '', ''); } else { // Include all collections. $resultTitles = $GLOBALS['TYPO3_DB']->exec_SELECTquery('tx_dlf_documents.uid AS uid', 'tx_dlf_documents', 'tx_dlf_documents.pid=' . intval($this->conf['pages']) . ' AND tx_dlf_documents.partof=0' . tx_dlf_helper::whereClause('tx_dlf_documents'), '', '', ''); $resultVolumes = $GLOBALS['TYPO3_DB']->exec_SELECTquery('tx_dlf_documents.uid AS uid', 'tx_dlf_documents', 'tx_dlf_documents.pid=' . intval($this->conf['pages']) . ' AND NOT tx_dlf_documents.uid IN (SELECT DISTINCT tx_dlf_documents.partof FROM tx_dlf_documents WHERE NOT tx_dlf_documents.partof=0' . tx_dlf_helper::whereClause('tx_dlf_documents') . ')' . tx_dlf_helper::whereClause('tx_dlf_documents'), '', '', ''); } $countTitles = $GLOBALS['TYPO3_DB']->sql_num_rows($resultTitles); $countVolumes = $GLOBALS['TYPO3_DB']->sql_num_rows($resultVolumes); // Set replacements. $replace = array('key' => array('###TITLES###', '###VOLUMES###'), 'value' => array($countTitles . ($countTitles > 1 ? $this->pi_getLL('titles', '', TRUE) : $this->pi_getLL('title', '', TRUE)), $countVolumes . ($countVolumes > 1 ? $this->pi_getLL('volumes', '', TRUE) : $this->pi_getLL('volume', '', TRUE)))); // Apply replacements. $content = str_replace($replace['key'], $replace['value'], $content); return $this->pi_wrapInBaseClass($content); }
/** * Main function of the script. * * @access public * * @return void */ public function main() { switch ((string) $this->cli_args['_DEFAULT'][1]) { // (Re-)Index a single document. case 'index': // Add command line arguments. $this->cli_options[] = array('-doc UID/URL', 'UID or URL of the document.'); $this->cli_options[] = array('-pid UID', 'UID of the page the document should be added to.'); $this->cli_options[] = array('-core UID', 'UID of the Solr core the document should be added to.'); // Check the command line arguments. $this->cli_validateArgs(); // Get the document... $doc =& tx_dlf_document::getInstance($this->cli_args['-doc'][0], $this->cli_args['-pid'][0], TRUE); if ($doc->ready) { // ...and save it to the database... if (!$doc->save(intval($this->cli_args['-pid'][0]), intval($this->cli_args['-core'][0]))) { $this->cli_echo('ERROR: Document ' . $this->cli_args['-doc'][0] . ' not saved and indexed.' . LF, TRUE); exit(1); } } else { $this->cli_echo('ERROR: Document ' . $this->cli_args['-doc'][0] . ' could not be loaded.' . LF, TRUE); exit(1); } break; // Re-index all documents of a collection. // Re-index all documents of a collection. case 'reindex': // Add command line arguments. $this->cli_options[] = array('-coll UID', 'UID of the collection.'); $this->cli_options[] = array('-pid UID', 'UID of the page the document should be added to.'); $this->cli_options[] = array('-core UID', 'UID of the Solr core the document should be added to.'); // Check the command line arguments. $this->cli_validateArgs(); // Get the collection. $result = $GLOBALS['TYPO3_DB']->exec_SELECT_mm_query('tx_dlf_documents.uid AS uid', 'tx_dlf_documents', 'tx_dlf_relations', 'tx_dlf_collections', 'AND tx_dlf_collections.uid=' . intval($this->cli_args['-coll'][0]) . ' AND tx_dlf_collections.pid=' . intval($this->cli_args['-pid'][0]) . ' AND tx_dlf_relations.ident=' . $GLOBALS['TYPO3_DB']->fullQuoteStr('docs_colls', 'tx_dlf_relations') . tx_dlf_helper::whereClause('tx_dlf_documents') . tx_dlf_helper::whereClause('tx_dlf_collections'), '', '', ''); while ($resArray = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($result)) { // Get the document... $doc =& tx_dlf_document::getInstance($resArray['uid'], $this->cli_args['-pid'][0], TRUE); if ($doc->ready) { // ...and save it to the database... if (!$doc->save(intval($this->cli_args['-pid'][0]), intval($this->cli_args['-core'][0]))) { $this->cli_echo('ERROR: Document ' . $resArray['uid'] . ' not saved and indexed.' . LF, TRUE); exit(1); } } else { $this->cli_echo('ERROR: Document ' . $resArray['uid'] . ' could not be loaded.' . LF, TRUE); exit(1); } } break; default: $this->cli_help(); break; } exit(0); }
/** * Adds the JS files necessary for search suggestions * * @access protected * * @return void */ protected function addAutocompleteJS() { // Check if there are any metadata to suggest. $result = $GLOBALS['TYPO3_DB']->exec_SELECTquery('tx_dlf_metadata.*', 'tx_dlf_metadata', 'tx_dlf_metadata.autocomplete=1 AND tx_dlf_metadata.pid=' . intval($this->conf['pages']) . tx_dlf_helper::whereClause('tx_dlf_metadata'), '', '', '1'); if ($GLOBALS['TYPO3_DB']->sql_num_rows($result)) { // Add javascript to page header. if (tx_dlf_helper::loadJQuery()) { $GLOBALS['TSFE']->additionalHeaderData[$this->prefixId . '_search_suggest'] = '<script type="text/javascript" src="' . \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::siteRelPath($this->extKey) . 'plugins/search/tx_dlf_search_suggest.js"></script>'; } } else { if (TYPO3_DLOG) { \TYPO3\CMS\Core\Utility\GeneralUtility::devLog('[tx_dlf_search->addAutocompleteJS()] No metadata fields configured for search suggestions', $this->extKey, SYSLOG_SEVERITY_WARNING); } } }
/** * This is a singleton class, thus the constructor should be private/protected * * @access protected * * @param integer $uid: The UID of the document to parse or URL to XML file * @param integer $pid: If > 0, then only document with this PID gets loaded * * @return void */ protected function __construct($uid, $pid) { // Prepare to check database for the requested document. if (tx_dlf_helper::testInt($uid)) { $whereClause = 'tx_dlf_documents.uid=' . intval($uid) . tx_dlf_helper::whereClause('tx_dlf_documents'); } else { // Cast to string for safety reasons. $location = (string) $uid; // Try to load METS file. if ($this->load($location)) { // Initialize core METS object. $this->init(); if ($this->mets !== NULL) { // Check for METS object @ID. if (!empty($this->mets['OBJID'])) { $this->recordId = (string) $this->mets['OBJID']; } // Get hook objects. $hookObjects = tx_dlf_helper::getHookObjects('common/class.tx_dlf_document.php'); // Apply hooks. foreach ($hookObjects as $hookObj) { if (method_exists($hookObj, 'construct_postProcessRecordId')) { $hookObj->construct_postProcessRecordId($this->xml, $this->recordId); } } } else { // No METS part found. return; } } else { // Loading failed. return; } if (!empty($this->recordId)) { $whereClause = 'tx_dlf_documents.record_id=' . $GLOBALS['TYPO3_DB']->fullQuoteStr($this->recordId, 'tx_dlf_documents') . tx_dlf_helper::whereClause('tx_dlf_documents'); } else { // There is no record identifier and there should be no hit in the database. $whereClause = '1=-1'; } } // Check for PID if needed. if ($pid) { $whereClause .= ' AND tx_dlf_documents.pid=' . intval($pid); } // Get document PID and location from database. $result = $GLOBALS['TYPO3_DB']->exec_SELECTquery('tx_dlf_documents.uid AS uid,tx_dlf_documents.pid AS pid,tx_dlf_documents.record_id AS record_id,tx_dlf_documents.partof AS partof,tx_dlf_documents.thumbnail AS thumbnail,tx_dlf_documents.location AS location', 'tx_dlf_documents', $whereClause, '', '', '1'); if ($GLOBALS['TYPO3_DB']->sql_num_rows($result) > 0) { list($this->uid, $this->pid, $this->recordId, $this->parentId, $this->thumbnail, $this->location) = $GLOBALS['TYPO3_DB']->sql_fetch_row($result); $this->thumbnailLoaded = TRUE; // Load XML file if necessary... if ($this->mets === NULL && $this->load($this->location)) { // ...and set some basic properties. $this->init(); } // Do we have a METS object now? if ($this->mets !== NULL) { // Set new location if necessary. if (!empty($location)) { $this->location = $location; } // Document ready! $this->ready = TRUE; } } elseif ($this->mets !== NULL) { // Set location as UID for documents not in database. $this->uid = $location; $this->location = $location; // Document ready! $this->ready = TRUE; } else { if (TYPO3_DLOG) { t3lib_div::devLog('[tx_dlf_document->__construct(' . $uid . ', ' . $pid . ')] No document with UID "' . $uid . '" found or document not accessible', self::$extKey, SYSLOG_SEVERITY_ERROR); } } }
/** * Main function of the module * * @access public * * @return void */ public function main() { // Is the user allowed to access this page? $access = is_array($this->pageInfo) || $GLOBALS['BE_USER']->isAdmin(); if ($this->id && $access) { // Increase max_execution_time and max_input_time for large documents. if (!ini_get('safe_mode')) { ini_set('max_execution_time', '0'); ini_set('max_input_time', '-1'); } switch ($this->CMD) { case 'indexFile': if (!empty($this->data['id']) && isset($this->data['core'])) { // Save document to database and index. $doc =& tx_dlf_document::getInstance($this->data['id'], $this->id, TRUE); if ($doc->ready) { $doc->save($this->id, $this->data['core']); } else { $_message = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage', htmlspecialchars(sprintf(tx_dlf_helper::getLL('flash.fileNotLoaded'), $this->data['id'])), tx_dlf_helper::getLL('flash.error', TRUE), \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR, TRUE); tx_dlf_helper::addMessage($_message); } } break; case 'reindexDocs': if (isset($this->data['core'])) { if (!empty($this->data['collection'])) { // Get all documents in this collection. $_result = $GLOBALS['TYPO3_DB']->exec_SELECT_mm_query('tx_dlf_documents.title AS title,tx_dlf_documents.uid AS uid', 'tx_dlf_documents', 'tx_dlf_relations', 'tx_dlf_collections', 'AND tx_dlf_documents.pid=' . intval($this->id) . ' AND tx_dlf_collections.uid=' . intval($this->data['collection']) . ' AND tx_dlf_relations.ident=' . $GLOBALS['TYPO3_DB']->fullQuoteStr('docs_colls', 'tx_dlf_relations') . tx_dlf_helper::whereClause('tx_dlf_documents') . tx_dlf_helper::whereClause('tx_dlf_collections'), 'tx_dlf_documents.uid', '', ''); } else { // Get all documents. $_result = $GLOBALS['TYPO3_DB']->exec_SELECTquery('tx_dlf_documents.title AS title,tx_dlf_documents.uid AS uid', 'tx_dlf_documents', 'tx_dlf_documents.pid=' . intval($this->id) . tx_dlf_helper::whereClause('tx_dlf_documents'), '', '', ''); } // Save them as a list object in user's session. $elements = array(); while ($resArray = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($_result)) { $elements[] = array($resArray['uid'], $resArray['title']); } $this->list = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('tx_dlf_list', $elements); // Start index looping. if (count($this->list) > 0) { $this->indexLoop(); } } break; case 'indexLoop': // Refresh user's session to prevent session timeout. $GLOBALS['BE_USER']->fetchUserSession(); // Get document list from user's session. $this->list = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('tx_dlf_list'); // Continue index looping. if (count($this->list) > 0 && isset($this->data['core'])) { $this->indexLoop(); } else { $_message = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage', tx_dlf_helper::getLL('flash.seeLog', TRUE), tx_dlf_helper::getLL('flash.done', TRUE), \TYPO3\CMS\Core\Messaging\FlashMessage::OK, TRUE); tx_dlf_helper::addMessage($_message); } break; } $this->markerArray['CONTENT'] .= tx_dlf_helper::renderFlashMessages(); switch ($this->MOD_SETTINGS['function']) { case 'indexFile': $this->markerArray['CONTENT'] .= $this->getFileForm(); break; case 'reindexDoc': $this->markerArray['CONTENT'] .= $this->getDocList(); break; case 'reindexDocs': $this->markerArray['CONTENT'] .= $this->getCollList(); break; } } else { // TODO: Ändern! $this->markerArray['CONTENT'] .= 'You are not allowed to access this page or have not selected a page, yet.'; } $this->printContent(); }
/** * Connects to Solr server. * * @access protected * * @return boolean TRUE on success or FALSE on failure */ protected function solrConnect() { // Get Solr instance. if (!$this->solr) { // Connect to Solr server. if ($this->solr = tx_dlf_solr::getInstance($this->metadata['options']['core'])) { // Load index configuration. $result = $GLOBALS['TYPO3_DB']->exec_SELECTquery('tx_dlf_metadata.index_name AS index_name,tx_dlf_metadata.tokenized AS tokenized,tx_dlf_metadata.indexed AS indexed', 'tx_dlf_metadata', 'tx_dlf_metadata.is_listed=1 AND tx_dlf_metadata.pid=' . intval($this->metadata['options']['pid']) . tx_dlf_helper::whereClause('tx_dlf_metadata'), '', 'tx_dlf_metadata.sorting ASC', ''); while ($resArray = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($result)) { $this->solrConfig[$resArray['index_name']] = $resArray['index_name'] . '_' . ($resArray['tokenized'] ? 't' : 'u') . 's' . ($resArray['indexed'] ? 'i' : 'u'); } // Add static fields. $this->solrConfig['type'] = 'type'; } else { return FALSE; } } return TRUE; }
/** * Main function of the module * * @access public * * @return void */ public function main() { // Is the user allowed to access this page? $access = is_array($this->pageInfo) && $GLOBALS['BE_USER']->isAdmin(); if ($this->id && $access) { // Check if page is sysfolder. if ($this->pageInfo['doktype'] != 254) { $_message = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage', $GLOBALS['LANG']->getLL('flash.wrongPageTypeMsg'), $GLOBALS['LANG']->getLL('flash.wrongPageType', TRUE), \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR, FALSE); tx_dlf_helper::addMessage($_message); $this->markerArray['CONTENT'] .= tx_dlf_helper::renderFlashMessages(); $this->printContent(); return; } // Should we do something? if (!empty($this->CMD)) { // Sanitize input... $_method = 'cmd' . ucfirst($this->CMD); // ...and unset to prevent infinite looping. unset($this->CMD); if (method_exists($this, $_method)) { $this->{$_method}(); } } // Check for existing structure configuration. $result = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid', 'tx_dlf_structures', 'pid=' . intval($this->id) . tx_dlf_helper::whereClause('tx_dlf_structures')); if ($GLOBALS['TYPO3_DB']->sql_num_rows($result)) { // Fine. $_message = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage', $GLOBALS['LANG']->getLL('flash.structureOkayMsg'), $GLOBALS['LANG']->getLL('flash.structureOkay', TRUE), \TYPO3\CMS\Core\Messaging\FlashMessage::OK, FALSE); } else { // Configuration missing. $_url = \TYPO3\CMS\Core\Utility\GeneralUtility::locationHeaderUrl(\TYPO3\CMS\Core\Utility\GeneralUtility::linkThisScript(array('id' => $this->id, 'CMD' => 'addStructure'))); $_message = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage', sprintf($GLOBALS['LANG']->getLL('flash.structureNotOkayMsg'), $_url), $GLOBALS['LANG']->getLL('flash.structureNotOkay', TRUE), \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR, FALSE); } tx_dlf_helper::addMessage($_message); // Check for existing metadata configuration. $result = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid', 'tx_dlf_metadata', 'pid=' . intval($this->id) . tx_dlf_helper::whereClause('tx_dlf_metadata')); if ($GLOBALS['TYPO3_DB']->sql_num_rows($result)) { // Fine. $_message = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage', $GLOBALS['LANG']->getLL('flash.metadataOkayMsg'), $GLOBALS['LANG']->getLL('flash.metadataOkay', TRUE), \TYPO3\CMS\Core\Messaging\FlashMessage::OK, FALSE); } else { // Configuration missing. $_url = \TYPO3\CMS\Core\Utility\GeneralUtility::locationHeaderUrl(\TYPO3\CMS\Core\Utility\GeneralUtility::linkThisScript(array('id' => $this->id, 'CMD' => 'addMetadata'))); $_message = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage', sprintf($GLOBALS['LANG']->getLL('flash.metadataNotOkayMsg'), $_url), $GLOBALS['LANG']->getLL('flash.metadataNotOkay', TRUE), \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR, FALSE); } tx_dlf_helper::addMessage($_message); $this->markerArray['CONTENT'] .= tx_dlf_helper::renderFlashMessages(); } else { // TODO: Ändern! $this->markerArray['CONTENT'] .= 'You are not allowed to access this page or have not selected a page, yet.'; } $this->printContent(); }
/** * Processes a search request. * * @access public * * @param string $query: The search query * * @return tx_dlf_list The result list */ public function search($query = '') { // Perform search. $results = $this->service->search((string) $query, 0, $this->limit, $this->params); $this->numberOfHits = count($results->response->docs); $toplevel = array(); $checks = array(); // Get metadata configuration. if ($this->numberOfHits > 0) { $result = $GLOBALS['TYPO3_DB']->exec_SELECTquery('tx_dlf_metadata.index_name AS index_name', 'tx_dlf_metadata', 'tx_dlf_metadata.is_sortable=1 AND tx_dlf_metadata.pid=' . intval($this->cPid) . tx_dlf_helper::whereClause('tx_dlf_metadata'), '', '', ''); $sorting = array(); while ($resArray = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($result)) { $sorting[$resArray['index_name']] = $resArray['index_name'] . '_sorting'; } } // Keep track of relevance. $i = 0; // Process results. foreach ($results->response->docs as $doc) { // Split toplevel documents from subparts. if ($doc->toplevel == 1) { // Prepare document's metadata for sorting. $docSorting = array(); foreach ($sorting as $index_name => $solr_name) { if (!empty($doc->{$solr_name})) { $docSorting[$index_name] = is_array($doc->{$solr_name}) ? $doc->{$solr_name}[0] : $doc->{$solr_name}; } } // Preserve relevance ranking. if (!empty($toplevel[$doc->uid]['s']['relevance'])) { $docSorting['relevance'] = $toplevel[$doc->uid]['s']['relevance']; } $toplevel[$doc->uid] = array('u' => $doc->uid, 's' => $docSorting, 'p' => !empty($toplevel[$doc->uid]['p']) ? $toplevel[$doc->uid]['p'] : array()); } else { $toplevel[$doc->uid]['p'][] = $doc->id; if (!in_array($doc->uid, $checks)) { $checks[] = $doc->uid; } } // Add relevance to sorting values. if (empty($toplevel[$doc->uid]['s']['relevance'])) { $toplevel[$doc->uid]['s']['relevance'] = str_pad($i, 6, '0', STR_PAD_LEFT); } $i++; } // Check if the toplevel documents have metadata. foreach ($checks as $check) { if (empty($toplevel[$check]['u'])) { // Get information for toplevel document. $result = $GLOBALS['TYPO3_DB']->exec_SELECTquery('tx_dlf_documents.uid AS uid,tx_dlf_documents.metadata_sorting AS metadata_sorting', 'tx_dlf_documents', 'tx_dlf_documents.uid=' . intval($check) . tx_dlf_helper::whereClause('tx_dlf_documents'), '', '', '1'); // Process results. if ($GLOBALS['TYPO3_DB']->sql_num_rows($result)) { $resArray = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($result); // Prepare document's metadata for sorting. $sorting = unserialize($resArray['metadata_sorting']); if (!empty($sorting['type']) && tx_dlf_helper::testInt($sorting['type'])) { $sorting['type'] = tx_dlf_helper::getIndexName($sorting['type'], 'tx_dlf_structures', $this->cPid); } if (!empty($sorting['owner']) && tx_dlf_helper::testInt($sorting['owner'])) { $sorting['owner'] = tx_dlf_helper::getIndexName($sorting['owner'], 'tx_dlf_libraries', $this->cPid); } if (!empty($sorting['collection']) && tx_dlf_helper::testInt($sorting['collection'])) { $sorting['collection'] = tx_dlf_helper::getIndexName($sorting['collection'], 'tx_dlf_collections', $this->cPid); } // Preserve relevance ranking. if (!empty($toplevel[$check]['s']['relevance'])) { $sorting['relevance'] = $toplevel[$check]['s']['relevance']; } $toplevel[$check] = array('u' => $resArray['uid'], 's' => $sorting, 'p' => $toplevel[$check]['p']); } else { // Clear entry if there is no (accessible) toplevel document. unset($toplevel[$check]); } } } // Save list of documents. $list = t3lib_div::makeInstance('tx_dlf_list'); $list->reset(); $list->add(array_values($toplevel)); // Set metadata for search. $list->metadata = array('label' => '', 'description' => '', 'options' => array('source' => 'search', 'select' => $query, 'userid' => 0, 'params' => $this->params, 'core' => $this->core, 'pid' => $this->cPid, 'order' => 'relevance', 'order.asc' => TRUE)); return $list; }
/** * Load indexing configuration * * @access protected * * @param integer $pid: The configuration page's UID * * @return void */ protected static function loadIndexConf($pid) { if (!self::$fieldsLoaded) { // Get the list of toplevel structures. $result = $GLOBALS['TYPO3_DB']->exec_SELECTquery('tx_dlf_structures.index_name AS index_name', 'tx_dlf_structures', 'tx_dlf_structures.toplevel=1 AND tx_dlf_structures.pid=' . intval($pid) . tx_dlf_helper::whereClause('tx_dlf_structures'), '', '', ''); while ($toplevel = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($result)) { self::$toplevel[] = $toplevel['index_name']; } // Get the metadata indexing options. $result = $GLOBALS['TYPO3_DB']->exec_SELECTquery('tx_dlf_metadata.index_name AS index_name,tx_dlf_metadata.tokenized AS tokenized,tx_dlf_metadata.stored AS stored,tx_dlf_metadata.indexed AS indexed,tx_dlf_metadata.is_sortable AS is_sortable,tx_dlf_metadata.is_facet AS is_facet,tx_dlf_metadata.is_listed AS is_listed,tx_dlf_metadata.autocomplete AS autocomplete,tx_dlf_metadata.boost AS boost', 'tx_dlf_metadata', 'tx_dlf_metadata.pid=' . intval($pid) . tx_dlf_helper::whereClause('tx_dlf_metadata'), '', '', ''); while ($indexing = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($result)) { if ($indexing['tokenized']) { self::$fields['tokenized'][] = $indexing['index_name']; } if ($indexing['stored'] || $indexing['is_listed']) { self::$fields['stored'][] = $indexing['index_name']; } if ($indexing['indexed'] || $indexing['autocomplete']) { self::$fields['indexed'][] = $indexing['index_name']; } if ($indexing['is_sortable']) { self::$fields['sortables'][] = $indexing['index_name']; } if ($indexing['is_facet']) { self::$fields['facets'][] = $indexing['index_name']; } if ($indexing['autocomplete']) { self::$fields['autocompleted'][] = $indexing['index_name']; } if ($indexing['boost'] > 0.0) { self::$fields['fieldboost'][$indexing['index_name']] = floatval($indexing['boost']); } else { self::$fields['fieldboost'][$indexing['index_name']] = FALSE; } } self::$fieldsLoaded = TRUE; } }
/** * The main method of the PlugIn * * @access public * * @param string $content: The PlugIn content * @param array $conf: The PlugIn configuration * * @return void */ public function main($content, $conf) { $this->init($conf); // Don't cache the output. $this->setCache(FALSE); // Create XML document. $rss = new DOMDocument('1.0', 'utf-8'); // Add mandatory root element. $root = $rss->createElement('rss'); $root->setAttribute('version', '2.0'); // Add channel element. $channel = $rss->createElement('channel'); $channel->appendChild($rss->createElement('title', htmlspecialchars($this->conf['title'], ENT_NOQUOTES, 'UTF-8'))); $channel->appendChild($rss->createElement('link', htmlspecialchars(t3lib_div::locationHeaderUrl($this->pi_linkTP_keepPIvars_url()), ENT_NOQUOTES, 'UTF-8'))); if (!empty($this->conf['description'])) { $channel->appendChild($rss->createElement('description', htmlspecialchars($this->conf['description'], ENT_QUOTES, 'UTF-8'))); } $result = $GLOBALS['TYPO3_DB']->exec_SELECTquery('tx_dlf_libraries.label AS label', 'tx_dlf_libraries', 'tx_dlf_libraries.pid=' . intval($this->conf['pages']) . ' AND tx_dlf_libraries.uid=' . intval($this->conf['library']) . tx_dlf_helper::whereClause('tx_dlf_libraries'), '', '', '1'); if ($GLOBALS['TYPO3_DB']->sql_num_rows($result)) { $resArray = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($result); $channel->appendChild($rss->createElement('copyright', htmlspecialchars($resArray['label'], ENT_NOQUOTES, 'UTF-8'))); } $channel->appendChild($rss->createElement('pubDate', date('r', $GLOBALS['EXEC_TIME']))); $channel->appendChild($rss->createElement('generator', htmlspecialchars($this->conf['useragent'], ENT_NOQUOTES, 'UTF-8'))); // Add item elements. if (!$this->conf['excludeOther'] || empty($this->piVars['collection']) || t3lib_div::inList($this->conf['collections'], $this->piVars['collection'])) { $additionalWhere = ''; // Check for pre-selected collections. if (!empty($this->piVars['collection'])) { $additionalWhere = ' AND tx_dlf_collections.uid=' . intval($this->piVars['collection']); } elseif (!empty($this->conf['collections'])) { $additionalWhere = ' AND tx_dlf_collections.uid IN (' . $GLOBALS['TYPO3_DB']->cleanIntList($this->conf['collections']) . ')'; } $result = $GLOBALS['TYPO3_DB']->exec_SELECT_mm_query('tx_dlf_documents.uid AS uid,tx_dlf_documents.partof AS partof,tx_dlf_documents.title AS title,tx_dlf_documents.volume AS volume,tx_dlf_documents.author AS author,tx_dlf_documents.record_id AS guid,tx_dlf_documents.tstamp AS tstamp,tx_dlf_documents.crdate AS crdate', 'tx_dlf_documents', 'tx_dlf_relations', 'tx_dlf_collections', 'AND tx_dlf_documents.pid=' . intval($this->conf['pages']) . ' AND tx_dlf_relations.ident=' . $GLOBALS['TYPO3_DB']->fullQuoteStr('docs_colls', 'tx_dlf_relations') . ' AND tx_dlf_collections.pid=' . intval($this->conf['pages']) . $additionalWhere . tx_dlf_helper::whereClause('tx_dlf_documents') . tx_dlf_helper::whereClause('tx_dlf_collections'), 'tx_dlf_documents.uid', 'tx_dlf_documents.tstamp DESC', intval($this->conf['limit'])); if ($GLOBALS['TYPO3_DB']->sql_num_rows($result)) { // Add each record as item element. while ($resArray = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($result)) { $item = $rss->createElement('item'); $title = ''; // Get title of superior document. if ((empty($resArray['title']) || !empty($this->conf['prependSuperiorTitle'])) && !empty($resArray['partof'])) { $superiorTitle = tx_dlf_document::getTitle($resArray['partof'], TRUE); if (!empty($superiorTitle)) { $title .= '[' . $superiorTitle . ']'; } } // Get title of document. if (!empty($resArray['title'])) { $title .= ' ' . $resArray['title']; } // Set default title if empty. if (empty($title)) { $title = $this->pi_getLL('noTitle'); } // Append volume information. if (!empty($resArray['volume'])) { $title .= ', ' . $this->pi_getLL('volume') . ' ' . $resArray['volume']; } // Is this document new or updated? if ($resArray['crdate'] == $resArray['tstamp']) { $title = $this->pi_getLL('new') . ' ' . trim($title); } else { $title = $this->pi_getLL('update') . ' ' . trim($title); } $item->appendChild($rss->createElement('title', htmlspecialchars($title, ENT_NOQUOTES, 'UTF-8'))); // Add link. $linkConf = array('parameter' => $this->conf['targetPid'], 'forceAbsoluteUrl' => 1, 'additionalParams' => t3lib_div::implodeArrayForUrl($this->prefixId, array('id' => $resArray['uid']), '', TRUE, FALSE)); $item->appendChild($rss->createElement('link', htmlspecialchars($this->cObj->typoLink_URL($linkConf), ENT_NOQUOTES, 'UTF-8'))); // Add author if applicable. if (!empty($resArray['author'])) { $item->appendChild($rss->createElement('author', htmlspecialchars($resArray['author'], ENT_NOQUOTES, 'UTF-8'))); } // Add online publication date. $item->appendChild($rss->createElement('pubDate', date('r', $resArray['crdate']))); // Add internal record identifier. $item->appendChild($rss->createElement('guid', htmlspecialchars($resArray['guid'], ENT_NOQUOTES, 'UTF-8'))); $channel->appendChild($item); } } } $root->appendChild($channel); // Build XML output. $rss->appendChild($root); $content = $rss->saveXML(); // Clean output buffer. t3lib_div::cleanOutputBuffers(); // Send headers. header('HTTP/1.1 200 OK'); header('Cache-Control: no-cache'); header('Content-Length: ' . strlen($content)); header('Content-Type: application/rss+xml; charset=utf-8'); header('Date: ' . date('r', $GLOBALS['EXEC_TIME'])); header('Expires: ' . date('r', $GLOBALS['EXEC_TIME'])); echo $content; // Flush output buffer and end script processing. ob_end_flush(); exit; }
/** * Helper to get flexform's items array for plugin "tx_dlf_search" * * @access public * * @param array &$params: An array with parameters * @param t3lib_TCEforms &$pObj: The parent object * * @return void */ public function itemsProcFunc_solrList(&$params, &$pObj) { if ($params['row']['pi_flexform']) { $pi_flexform = t3lib_div::xml2array($params['row']['pi_flexform']); $pages = $pi_flexform['data']['sDEF']['lDEF']['pages']['vDEF']; // There is a strange behavior where the uid from the flexform is prepended by the table's name and appended by its title. // i.e. instead of "18" it reads "pages_18|Title" if (!tx_dlf_helper::testInt($pages)) { $parts = explode('|', $pages); $pages = array_pop(explode('_', $parts[0])); } if ($pages > 0) { $result = $GLOBALS['TYPO3_DB']->exec_SELECTquery('label,uid', 'tx_dlf_solrcores', 'pid IN (' . intval($pages) . ',0)' . tx_dlf_helper::whereClause('tx_dlf_solrcores'), '', 'label', ''); if ($GLOBALS['TYPO3_DB']->sql_num_rows($result) > 0) { while ($resArray = $GLOBALS['TYPO3_DB']->sql_fetch_row($result)) { $params['items'][] = $resArray; } } } } }
/** * This builds a menu array for HMENU * * @access public * * @param string $content: The PlugIn content * @param array $conf: The PlugIn configuration * * @return array HMENU array */ public function makeMenuArray($content, $conf) { $this->init($conf); // Load current document. $this->loadDocument(); if ($this->doc === NULL) { // Quit without doing anything if required variables are not set. return array(); } else { // Set default values for page if not set. $this->piVars['page'] = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($this->piVars['page'], 1, $this->doc->numPages, 1); $this->piVars['double'] = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($this->piVars['double'], 0, 1, 0); } $menuArray = array(); // Does the document have physical pages or is it an external file? if ($this->doc->physicalPages || !\TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($this->doc->uid)) { // Get all logical units the current page is a part of. if (!empty($this->piVars['page']) && $this->doc->physicalPages) { $this->activeEntries = array_merge((array) $this->doc->smLinks['p2l'][$this->doc->physicalPages[0]], (array) $this->doc->smLinks['p2l'][$this->doc->physicalPages[$this->piVars['page']]]); if (!empty($this->piVars['double']) && $this->piVars['page'] < $this->doc->numPages) { $this->activeEntries = array_merge($this->activeEntries, (array) $this->doc->smLinks['p2l'][$this->doc->physicalPages[$this->piVars['page'] + 1]]); } } // Go through table of contents and create all menu entries. foreach ($this->doc->tableOfContents as $entry) { $menuArray[] = $this->getMenuEntry($entry, TRUE); } } else { // Go through table of contents and create top-level menu entries. foreach ($this->doc->tableOfContents as $entry) { $menuArray[] = $this->getMenuEntry($entry, FALSE); } // Get all child documents from database. $whereClause = 'tx_dlf_documents.partof=' . intval($this->doc->uid) . ' AND tx_dlf_documents.structure=tx_dlf_structures.uid AND tx_dlf_structures.pid=' . $this->doc->pid . tx_dlf_helper::whereClause('tx_dlf_documents') . tx_dlf_helper::whereClause('tx_dlf_structures'); if ($this->conf['excludeOther']) { $whereClause .= ' AND tx_dlf_documents.pid=' . intval($this->conf['pages']); } // Build table of contents from database. $result = $GLOBALS['TYPO3_DB']->exec_SELECTquery('tx_dlf_documents.uid AS uid,tx_dlf_documents.title AS title,tx_dlf_documents.volume AS volume,tx_dlf_structures.index_name AS type', 'tx_dlf_documents,tx_dlf_structures', $whereClause, '', 'tx_dlf_documents.volume_sorting', ''); if ($GLOBALS['TYPO3_DB']->sql_num_rows($result)) { $menuArray[0]['ITEM_STATE'] = 'CURIFSUB'; $menuArray[0]['_SUB_MENU'] = array(); while ($resArray = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($result)) { $entry = array('label' => $resArray['title'], 'type' => $resArray['type'], 'volume' => $resArray['volume'], 'pagination' => '', 'targetUid' => $resArray['uid']); $menuArray[0]['_SUB_MENU'][] = $this->getMenuEntry($entry, FALSE); } } } return $menuArray; }
/** * Prepares the metadata array for output * * @access protected * * @param array $metadataArray: The metadata array * * @return string The metadata array ready for output */ protected function printMetadata(array $metadataArray) { // Load template file. if (!empty($this->conf['templateFile'])) { $this->template = $this->cObj->getSubpart($this->cObj->fileResource($this->conf['templateFile']), '###TEMPLATE###'); } else { $this->template = $this->cObj->getSubpart($this->cObj->fileResource('EXT:dlf/plugins/metadata/template.tmpl'), '###TEMPLATE###'); } $output = ''; $subpart['block'] = $this->cObj->getSubpart($this->template, '###BLOCK###'); // Get list of metadata to show. $metaList = array(); $result = $GLOBALS['TYPO3_DB']->exec_SELECTquery('tx_dlf_metadata.index_name AS index_name,tx_dlf_metadata.is_listed AS is_listed,tx_dlf_metadata.wrap AS wrap', 'tx_dlf_metadata', 'tx_dlf_metadata.pid=' . intval($this->conf['pages']) . tx_dlf_helper::whereClause('tx_dlf_metadata'), '', 'tx_dlf_metadata.sorting', ''); while ($resArray = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($result)) { if ($this->conf['showFull'] || $resArray['is_listed']) { $metaList[$resArray['index_name']] = array('wrap' => $resArray['wrap'], 'label' => tx_dlf_helper::translate($resArray['index_name'], 'tx_dlf_metadata', $this->conf['pages'])); } } // Save original data array. $cObjData = $this->cObj->data; // Parse the metadata arrays. foreach ($metadataArray as $metadata) { $markerArray['###METADATA###'] = ''; // Reset content object's data array. $this->cObj->data = $cObjData; // Load all the metadata values into the content object's data array. foreach ($metadata as $index_name => $value) { if (is_array($value)) { $this->cObj->data[$index_name] = implode($this->conf['separator'], $value); } else { $this->cObj->data[$index_name] = $value; } } // Process each metadate. foreach ($metaList as $index_name => $metaConf) { $parsedValue = ''; $fieldwrap = $this->parseTS($metaConf['wrap']); do { $value = @array_shift($metadata[$index_name]); if ($index_name == 'title') { // Get title of parent document if needed. if (empty($value) && $this->conf['getTitle'] && $this->doc->parentId) { $superiorTitle = tx_dlf_document::getTitle($this->doc->parentId, TRUE); if (!empty($superiorTitle)) { $value = '[' . $superiorTitle . ']'; } } if (!empty($value)) { $value = htmlspecialchars($value); // Link title to pageview. if ($this->conf['linkTitle'] && $metadata['_id']) { $details = $this->doc->getLogicalStructure($metadata['_id']); $value = $this->pi_linkTP($value, array($this->prefixId => array('id' => $this->doc->uid, 'page' => !empty($details['points']) ? intval($details['points']) : 1)), TRUE, $this->conf['targetPid']); } } } elseif ($index_name == 'owner' && !empty($value)) { // Translate name of holding library. $value = htmlspecialchars(tx_dlf_helper::translate($value, 'tx_dlf_libraries', $this->conf['pages'])); } elseif ($index_name == 'type' && !empty($value)) { // Translate document type. $value = htmlspecialchars(tx_dlf_helper::translate($value, 'tx_dlf_structures', $this->conf['pages'])); } elseif ($index_name == 'collection' && !empty($value)) { // Translate collection. $value = htmlspecialchars(tx_dlf_helper::translate($value, 'tx_dlf_collections', $this->conf['pages'])); } elseif ($index_name == 'language' && !empty($value)) { // Translate ISO 639 language code. $value = htmlspecialchars(tx_dlf_helper::getLanguageName($value)); } elseif (!empty($value)) { // Sanitize value for output. $value = htmlspecialchars($value); } // Hook for getting a customized value (requested by SBB). foreach ($this->hookObjects as $hookObj) { if (method_exists($hookObj, 'printMetadata_customizeMetadata')) { $hookObj->printMetadata_customizeMetadata($value); } } $value = $this->cObj->stdWrap($value, $fieldwrap['value.']); if (!empty($value)) { $parsedValue .= $value; } } while (count($metadata[$index_name])); if (!empty($parsedValue)) { $field = $this->cObj->stdWrap(htmlspecialchars($metaConf['label']), $fieldwrap['key.']); $field .= $parsedValue; $markerArray['###METADATA###'] .= $this->cObj->stdWrap($field, $fieldwrap['all.']); } } $output .= $this->cObj->substituteMarkerArray($subpart['block'], $markerArray); } return $this->cObj->substituteSubpart($this->template, '###BLOCK###', $output, TRUE); }
/** * Make sure the essential namespaces are defined. * * @access public * * @param array &$params: An array with parameters * @param t3lib_tsStyleConfig &$pObj: The parent object * * @return string Message informing the user of success or failure */ public function checkMetadataFormats(&$params, &$pObj) { $nsDefined = array('MODS' => FALSE, 'TEIHDR' => FALSE); // Check if formats "MODS" and "TEIHDR" exist. $result = $GLOBALS['TYPO3_DB']->exec_SELECTquery('type', 'tx_dlf_formats', '(type=' . $GLOBALS['TYPO3_DB']->fullQuoteStr('MODS', 'tx_dlf_formats') . ' OR type=' . $GLOBALS['TYPO3_DB']->fullQuoteStr('TEIHDR', 'tx_dlf_formats') . ')' . tx_dlf_helper::whereClause('tx_dlf_formats')); while ($resArray = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($result)) { $nsDefined[$resArray['type']] = TRUE; } // Build data array. $data = array(); // Add MODS namespace. if (!$nsDefined['MODS']) { $data['tx_dlf_formats'][uniqid('NEW')] = array('pid' => 0, 'type' => 'MODS', 'root' => 'mods', 'namespace' => 'http://www.loc.gov/mods/v3', 'class' => 'tx_dlf_mods'); } // Add TEIHDR namespace. if (!$nsDefined['TEIHDR']) { $data['tx_dlf_formats'][uniqid('NEW')] = array('pid' => 0, 'type' => 'TEIHDR', 'root' => 'teiHeader', 'namespace' => 'http://www.tei-c.org/ns/1.0', 'class' => 'tx_dlf_teihdr'); } if (!empty($data)) { // Process changes. $substUid = tx_dlf_helper::processDBasAdmin($data); if (!empty($substUid)) { $message = t3lib_div::makeInstance('t3lib_FlashMessage', $GLOBALS['LANG']->getLL('metadataFormats.nsCreatedMsg'), $GLOBALS['LANG']->getLL('metadataFormats.nsCreated'), t3lib_FlashMessage::INFO, FALSE); } else { $message = t3lib_div::makeInstance('t3lib_FlashMessage', $GLOBALS['LANG']->getLL('metadataFormats.nsNotCreatedMsg'), $GLOBALS['LANG']->getLL('metadataFormats.nsNotCreated'), t3lib_FlashMessage::ERROR, FALSE); } } else { $message = t3lib_div::makeInstance('t3lib_FlashMessage', $GLOBALS['LANG']->getLL('metadataFormats.nsOkayMsg'), $GLOBALS['LANG']->getLL('metadataFormats.nsOkay'), t3lib_FlashMessage::OK, FALSE); } $this->content .= $message->render(); return $this->content; }
/** * Main function of the module * * @access public * * @return void */ public function main() { // Is the user allowed to access this page? $access = is_array($this->pageInfo) && $GLOBALS['BE_USER']->isAdmin(); if ($this->id && $access) { // Check if page is sysfolder. if ($this->pageInfo['doktype'] != 254) { $_message = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage', tx_dlf_helper::getLL('flash.wrongPageTypeMsg'), tx_dlf_helper::getLL('flash.wrongPageType', TRUE), \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR, FALSE); tx_dlf_helper::addMessage($_message); $this->markerArray['CONTENT'] .= tx_dlf_helper::renderFlashMessages(); $this->printContent(); return; } // Should we do something? if (!empty($this->CMD)) { // Sanitize input... $_method = 'cmd' . ucfirst($this->CMD); // ...and unset to prevent infinite looping. unset($this->CMD); if (method_exists($this, $_method)) { $this->{$_method}(); } } // Check for existing structure configuration. $result = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid', 'tx_dlf_structures', 'pid=' . intval($this->id) . tx_dlf_helper::whereClause('tx_dlf_structures')); if ($GLOBALS['TYPO3_DB']->sql_num_rows($result)) { // Fine. $_message = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage', tx_dlf_helper::getLL('flash.structureOkayMsg'), tx_dlf_helper::getLL('flash.structureOkay', TRUE), \TYPO3\CMS\Core\Messaging\FlashMessage::OK, FALSE); } else { // Configuration missing. $_url = \TYPO3\CMS\Core\Utility\GeneralUtility::locationHeaderUrl(\TYPO3\CMS\Core\Utility\GeneralUtility::linkThisScript(array('id' => $this->id, 'CMD' => 'addStructure'))); $_message = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage', sprintf(tx_dlf_helper::getLL('flash.structureNotOkayMsg'), $_url), tx_dlf_helper::getLL('flash.structureNotOkay', TRUE), \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR, FALSE); } tx_dlf_helper::addMessage($_message); // Check for existing metadata configuration. $result = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid', 'tx_dlf_metadata', 'pid=' . intval($this->id) . tx_dlf_helper::whereClause('tx_dlf_metadata')); if ($GLOBALS['TYPO3_DB']->sql_num_rows($result)) { // Fine. $_message = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage', tx_dlf_helper::getLL('flash.metadataOkayMsg'), tx_dlf_helper::getLL('flash.metadataOkay', TRUE), \TYPO3\CMS\Core\Messaging\FlashMessage::OK, FALSE); } else { // Configuration missing. $_url = \TYPO3\CMS\Core\Utility\GeneralUtility::locationHeaderUrl(\TYPO3\CMS\Core\Utility\GeneralUtility::linkThisScript(array('id' => $this->id, 'CMD' => 'addMetadata'))); $_message = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage', sprintf(tx_dlf_helper::getLL('flash.metadataNotOkayMsg'), $_url), tx_dlf_helper::getLL('flash.metadataNotOkay', TRUE), \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR, FALSE); } tx_dlf_helper::addMessage($_message); // Check the access conditions for the command line indexer's user. $result = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid,db_mountpoints', 'be_groups', 'title=' . $GLOBALS['TYPO3_DB']->fullQuoteStr('_cli_dlf', 'be_groups') . ' AND ' . $GLOBALS['TCA']['be_groups']['ctrl']['enablecolumns']['disabled'] . '=0' . \TYPO3\CMS\Backend\Utility\BackendUtility::deleteClause('be_groups')); if ($GLOBALS['TYPO3_DB']->sql_num_rows($result)) { $resArray = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($result); if (\TYPO3\CMS\Core\Utility\GeneralUtility::inList($resArray['db_mountpoints'], $this->id)) { // Fine. $_message = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage', tx_dlf_helper::getLL('flash.usergroupOkayMsg'), tx_dlf_helper::getLL('flash.usergroupOkay', TRUE), \TYPO3\CMS\Core\Messaging\FlashMessage::OK, FALSE); } else { // Configuration missing. $_url = \TYPO3\CMS\Core\Utility\GeneralUtility::locationHeaderUrl(\TYPO3\CMS\Core\Utility\GeneralUtility::linkThisScript(array('id' => $this->id, 'CMD' => 'addAccessRights'))); $_message = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage', sprintf(tx_dlf_helper::getLL('flash.usergroupNotOkayMsg'), $_url), tx_dlf_helper::getLL('flash.usergroupNotOkay', TRUE), \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR, FALSE); } } else { // Usergoup missing. $_message = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage', tx_dlf_helper::getLL('flash.usergroupMissingMsg'), tx_dlf_helper::getLL('flash.usergroupMissing', TRUE), \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR, FALSE); } tx_dlf_helper::addMessage($_message); // Check for existing Solr core. $result = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid,pid', 'tx_dlf_solrcores', 'pid IN (' . intval($this->id) . ',0)' . tx_dlf_helper::whereClause('tx_dlf_solrcores')); if ($GLOBALS['TYPO3_DB']->sql_num_rows($result)) { $resArray = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($result); if ($resArray['pid']) { // Fine. $_message = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage', tx_dlf_helper::getLL('flash.solrcoreOkayMsg'), tx_dlf_helper::getLL('flash.solrcoreOkay', TRUE), \TYPO3\CMS\Core\Messaging\FlashMessage::OK, FALSE); } else { // Default core available, but this is deprecated. $_url = \TYPO3\CMS\Core\Utility\GeneralUtility::locationHeaderUrl(\TYPO3\CMS\Core\Utility\GeneralUtility::linkThisScript(array('id' => $this->id, 'CMD' => 'addSolrcore'))); $_message = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage', sprintf(tx_dlf_helper::getLL('flash.solrcoreDeprecatedMsg'), $_url), tx_dlf_helper::getLL('flash.solrcoreDeprecatedOkay', TRUE), \TYPO3\CMS\Core\Messaging\FlashMessage::NOTICE, FALSE); } } else { // Solr core missing. $_url = \TYPO3\CMS\Core\Utility\GeneralUtility::locationHeaderUrl(\TYPO3\CMS\Core\Utility\GeneralUtility::linkThisScript(array('id' => $this->id, 'CMD' => 'addSolrcore'))); $_message = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage', sprintf(tx_dlf_helper::getLL('flash.solrcoreMissingMsg'), $_url), tx_dlf_helper::getLL('flash.solrcoreMissing', TRUE), \TYPO3\CMS\Core\Messaging\FlashMessage::WARNING, FALSE); } tx_dlf_helper::addMessage($_message); $this->markerArray['CONTENT'] .= tx_dlf_helper::renderFlashMessages(); } else { // TODO: Ändern! $this->markerArray['CONTENT'] .= 'You are not allowed to access this page or have not selected a page, yet.'; } $this->printContent(); }
/** * Get metadata configuration from database * * @access protected * * @return void */ protected function loadConfig() { $result = $GLOBALS['TYPO3_DB']->exec_SELECTquery('tx_dlf_metadata.index_name AS index_name,tx_dlf_metadata.wrap AS wrap,tx_dlf_metadata.is_listed AS is_listed,tx_dlf_metadata.is_sortable AS is_sortable', 'tx_dlf_metadata', '(tx_dlf_metadata.is_listed=1 OR tx_dlf_metadata.is_sortable=1) AND tx_dlf_metadata.pid=' . intval($this->conf['pages']) . tx_dlf_helper::whereClause('tx_dlf_metadata'), '', 'tx_dlf_metadata.sorting ASC', ''); while ($resArray = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($result)) { if ($resArray['is_listed']) { $this->metadata[$resArray['index_name']] = array('wrap' => $resArray['wrap'], 'label' => tx_dlf_helper::translate($resArray['index_name'], 'tx_dlf_metadata', $this->conf['pages'])); } if ($resArray['is_sortable']) { $this->sortables[$resArray['index_name']] = tx_dlf_helper::translate($resArray['index_name'], 'tx_dlf_metadata', $this->conf['pages']); } } }
/** * Post-processing hook for the process_cmdmap() method. * * @access public * * @param string $command: 'move', 'copy', 'localize', 'inlineLocalizeSynchronize', 'delete' or 'undelete' * @param string $table: The destination table * @param integer $id: The uid of the record * @param mixed $value: The value for the command * @param \TYPO3\CMS\Core\DataHandling\DataHandler $pObj: The parent object * * @return void */ public function processCmdmap_postProcess($command, $table, $id, $value, $pObj) { if (in_array($command, array('move', 'delete', 'undelete')) && $table == 'tx_dlf_documents') { // Get Solr core. $result = $GLOBALS['TYPO3_DB']->exec_SELECTquery('tx_dlf_solrcores.uid', 'tx_dlf_solrcores,tx_dlf_documents', 'tx_dlf_solrcores.uid=tx_dlf_documents.solrcore AND tx_dlf_documents.uid=' . intval($id) . tx_dlf_helper::whereClause('tx_dlf_solrcores'), '', '', '1'); if ($GLOBALS['TYPO3_DB']->sql_num_rows($result)) { list($core) = $GLOBALS['TYPO3_DB']->sql_fetch_row($result); switch ($command) { case 'move': case 'delete': // Establish Solr connection. if ($solr = tx_dlf_solr::getInstance($core)) { // Delete Solr document. $solr->service->deleteByQuery('uid:' . $id); $solr->service->commit(); if ($command == 'delete') { break; } } case 'undelete': // Reindex document. $doc =& tx_dlf_document::getInstance($id); if ($doc->ready) { $doc->save($doc->pid, $core); } else { if (TYPO3_DLOG) { \TYPO3\CMS\Core\Utility\GeneralUtility::devLog('[tx_dlf_tcemain->processCmdmap_postProcess(' . $command . ', ' . $table . ', ' . $id . ', ' . $value . ', [' . get_class($pObj) . '])] Failed to re-index document with UID "' . $id . '"', $this->extKey, SYSLOG_SEVERITY_ERROR); } } break; } } } }
/** * Process verb "ListSets" * * @access protected * * @return string Substitution for subpart "###RESPONSE###" */ protected function verbListSets() { // Check for invalid arguments. if (count($this->piVars) > 1) { if (!empty($this->piVars['resumptionToken'])) { return $this->error('badResumptionToken'); } else { return $this->error('badArgument'); } } // Get set information. $additionalWhere = ''; if (!$this->conf['show_userdefined']) { $additionalWhere = ' AND tx_dlf_collections.fe_cruser_id=0'; } $result = $GLOBALS['TYPO3_DB']->exec_SELECTquery('tx_dlf_collections.oai_name AS oai_name,tx_dlf_collections.label AS label', 'tx_dlf_collections', 'tx_dlf_collections.sys_language_uid IN (-1,0) AND NOT tx_dlf_collections.oai_name=\'\' AND tx_dlf_collections.pid=' . intval($this->conf['pages']) . $additionalWhere . tx_dlf_helper::whereClause('tx_dlf_collections'), 'tx_dlf_collections.oai_name', 'tx_dlf_collections.oai_name', ''); if (!$GLOBALS['TYPO3_DB']->sql_num_rows($result)) { return $this->error('noSetHierarchy'); } // Add set list node. $ListSets = $this->oai->createElementNS('http://www.openarchives.org/OAI/2.0/', 'ListSets'); while ($resArray = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($result)) { // Add set node. $set = $this->oai->createElementNS('http://www.openarchives.org/OAI/2.0/', 'set'); $set->appendChild($this->oai->createElementNS('http://www.openarchives.org/OAI/2.0/', 'setSpec', htmlspecialchars($resArray['oai_name'], ENT_NOQUOTES, 'UTF-8'))); $set->appendChild($this->oai->createElementNS('http://www.openarchives.org/OAI/2.0/', 'setName', htmlspecialchars($resArray['label'], ENT_NOQUOTES, 'UTF-8'))); $ListSets->appendChild($set); } return $ListSets; }
/** * Builds a collection's list * * @access protected * * @param integer $id: The collection's UID * * @return void */ protected function showSingleCollection($id) { // Should user-defined collections be shown? if (empty($this->conf['show_userdefined'])) { $additionalWhere = ' AND tx_dlf_collections.fe_cruser_id=0'; } elseif ($this->conf['show_userdefined'] > 0) { $additionalWhere = ' AND NOT tx_dlf_collections.fe_cruser_id=0'; } // Get all documents in collection. $result = $GLOBALS['TYPO3_DB']->exec_SELECT_mm_query('tx_dlf_collections.index_name AS index_name,tx_dlf_collections.label AS collLabel,tx_dlf_collections.description AS collDesc,tx_dlf_collections.thumbnail AS collThumb,tx_dlf_collections.fe_cruser_id AS userid,tx_dlf_documents.uid AS uid,tx_dlf_documents.metadata_sorting AS metadata_sorting,tx_dlf_documents.volume_sorting AS volume_sorting,tx_dlf_documents.partof AS partof', 'tx_dlf_documents', 'tx_dlf_relations', 'tx_dlf_collections', 'AND tx_dlf_collections.uid=' . intval($id) . ' AND tx_dlf_collections.pid=' . intval($this->conf['pages']) . ' AND tx_dlf_relations.ident=' . $GLOBALS['TYPO3_DB']->fullQuoteStr('docs_colls', 'tx_dlf_relations') . $additionalWhere . tx_dlf_helper::whereClause('tx_dlf_documents') . tx_dlf_helper::whereClause('tx_dlf_collections'), '', 'tx_dlf_documents.title_sorting ASC', ''); $toplevel = array(); $subparts = array(); $listMetadata = array(); // Process results. while ($resArray = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($result)) { if (empty($listMetadata)) { $listMetadata = array('label' => htmlspecialchars($resArray['collLabel']), 'description' => $this->pi_RTEcssText($resArray['collDesc']), 'thumbnail' => htmlspecialchars($resArray['collThumb']), 'options' => array('source' => 'collection', 'select' => $id, 'userid' => $resArray['userid'], 'params' => array('fq' => array('collection_faceting:"' . $resArray['index_name'] . '"')), 'core' => '', 'pid' => $this->conf['pages'], 'order' => 'title', 'order.asc' => TRUE)); } // Split toplevel documents from volumes. if ($resArray['partof'] == 0) { // Prepare document's metadata for sorting. $sorting = unserialize($resArray['metadata_sorting']); if (!empty($sorting['type']) && tx_dlf_helper::testInt($sorting['type'])) { $sorting['type'] = tx_dlf_helper::getIndexName($sorting['type'], 'tx_dlf_structures', $this->conf['pages']); } if (!empty($sorting['owner']) && tx_dlf_helper::testInt($sorting['owner'])) { $sorting['owner'] = tx_dlf_helper::getIndexName($sorting['owner'], 'tx_dlf_libraries', $this->conf['pages']); } if (!empty($sorting['collection']) && tx_dlf_helper::testInt($sorting['collection'])) { $sorting['collection'] = tx_dlf_helper::getIndexName($sorting['collection'], 'tx_dlf_collections', $this->conf['pages']); } $toplevel[$resArray['uid']] = array('u' => $resArray['uid'], 's' => $sorting, 'p' => array()); } else { $subparts[$resArray['partof']][$resArray['volume_sorting']] = $resArray['uid']; } } // Add volumes to the corresponding toplevel documents. foreach ($subparts as $partof => $parts) { if (!empty($toplevel[$partof])) { ksort($parts); $toplevel[$partof]['p'] = array_values($parts); } } // Save list of documents. $list = t3lib_div::makeInstance('tx_dlf_list'); $list->reset(); $list->add(array_values($toplevel)); $list->metadata = $listMetadata; $list->save(); // Clean output buffer. t3lib_div::cleanOutputBuffers(); // Send headers. header('Location: ' . t3lib_div::locationHeaderUrl($this->cObj->typoLink_URL(array('parameter' => $this->conf['targetPid'])))); // Flush output buffer and end script processing. ob_end_flush(); exit; }
/** * Update all outdated metadata configuration records * * @access protected * * @return void */ protected function updateMetadataConfig() { $metadataUids = $this->getMetadataConfig(); if (!empty($metadataUids)) { $data = array(); // Get all old metadata configuration records. $result = $GLOBALS['TYPO3_DB']->exec_SELECTquery('tx_dlf_metadata.uid AS uid,tx_dlf_metadata.pid AS pid,tx_dlf_metadata.cruser_id AS cruser_id,tx_dlf_metadata.encoded AS encoded,tx_dlf_metadata.xpath AS xpath,tx_dlf_metadata.xpath_sorting AS xpath_sorting', 'tx_dlf_metadata', 'tx_dlf_metadata.uid IN (' . implode(',', $metadataUids) . ')' . tx_dlf_helper::whereClause('tx_dlf_metadata'), '', '', ''); while ($resArray = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($result)) { $newId = uniqid('NEW'); // Copy record to new table. $data['tx_dlf_metadataformat'][$newId] = array('pid' => $resArray['pid'], 'cruser_id' => $resArray['cruser_id'], 'parent_id' => $resArray['uid'], 'encoded' => $resArray['encoded'], 'xpath' => $resArray['xpath'], 'xpath_sorting' => $resArray['xpath_sorting']); // Add reference to old table. $data['tx_dlf_metadata'][$resArray['uid']]['format'] = $newId; } if (!empty($data)) { // Process datamap. $substUids = tx_dlf_helper::processDBasAdmin($data); unset($data); if (!empty($substUids)) { $message = t3lib_div::makeInstance('t3lib_FlashMessage', $GLOBALS['LANG']->getLL('update.metadataConfigOkay', TRUE), $GLOBALS['LANG']->getLL('update.metadataConfig', TRUE), t3lib_FlashMessage::OK, FALSE); } else { $message = t3lib_div::makeInstance('t3lib_FlashMessage', $GLOBALS['LANG']->getLL('update.metadataConfigNotOkay', TRUE), $GLOBALS['LANG']->getLL('update.metadataConfig', TRUE), t3lib_FlashMessage::WARNING, FALSE); } $this->content .= $message->render(); } } }
/** * Loads the current document into $this->doc * * @access protected * * @return void */ protected function loadDocument() { // Check for required variable. if (!empty($this->piVars['id']) && !empty($this->conf['pages'])) { // Should we exclude documents from other pages than $this->conf['pages']? $pid = !empty($this->conf['excludeOther']) ? intval($this->conf['pages']) : 0; // Get instance of tx_dlf_document. $this->doc =& tx_dlf_document::getInstance($this->piVars['id'], $pid); if (!$this->doc->ready) { // Destroy the incomplete object. if (TYPO3_DLOG) { t3lib_div::devLog('[tx_dlf_plugin->loadDocument()] Failed to load document with UID "' . $this->piVars['id'] . '"', $this->extKey, SYSLOG_SEVERITY_ERROR); } $this->doc = NULL; } else { // Set configuration PID. $this->doc->cPid = $this->conf['pages']; } } elseif (!empty($this->piVars['recordId'])) { // Get UID of document with given record identifier. $result = $GLOBALS['TYPO3_DB']->exec_SELECTquery('tx_dlf_documents.uid', 'tx_dlf_documents', 'tx_dlf_documents.record_id=' . $GLOBALS['TYPO3_DB']->fullQuoteStr($this->piVars['recordId'], 'tx_dlf_documents') . tx_dlf_helper::whereClause('tx_dlf_documents'), '', '', '1'); if ($GLOBALS['TYPO3_DB']->sql_num_rows($result) == 1) { list($this->piVars['id']) = $GLOBALS['TYPO3_DB']->sql_fetch_row($result); // Set superglobal $_GET array. $_GET[$this->prefixId]['id'] = $this->piVars['id']; // Unset variable to avoid infinite looping. unset($this->piVars['recordId'], $_GET[$this->prefixId]['recordId']); // Try to load document. $this->loadDocument(); } else { if (TYPO3_DLOG) { t3lib_div::devLog('[tx_dlf_plugin->loadDocument()] Failed to load document with record ID "' . $this->piVars['recordId'] . '"', $this->extKey, SYSLOG_SEVERITY_ERROR); } } } else { if (TYPO3_DLOG) { t3lib_div::devLog('[tx_dlf_plugin->loadDocument()] Invalid UID "' . $this->piVars['id'] . '" or PID "' . $this->conf['pages'] . '" for document loading', $this->extKey, SYSLOG_SEVERITY_ERROR); } } }
/** * Loads the current document into $this->doc * * @access protected * * @return void */ protected function loadDocument() { // Check for required variable. if (!empty($this->piVars['id'])) { // Get instance of tx_dlf_document. $this->doc =& tx_dlf_document::getInstance($this->piVars['id']); if (!$this->doc->ready) { // Destroy the incomplete object. $this->doc = NULL; if (TYPO3_DLOG) { \TYPO3\CMS\Core\Utility\GeneralUtility::devLog('[tx_dlf_doctype->loadDocument()] Failed to load document with UID "' . $this->piVars['id'] . '"', $this->extKey, SYSLOG_SEVERITY_WARNING); } } } elseif (!empty($this->piVars['recordId'])) { // Get UID of document with given record identifier. $result = $GLOBALS['TYPO3_DB']->exec_SELECTquery('tx_dlf_documents.uid', 'tx_dlf_documents', 'tx_dlf_documents.record_id=' . $GLOBALS['TYPO3_DB']->fullQuoteStr($this->piVars['recordId'], 'tx_dlf_documents') . tx_dlf_helper::whereClause('tx_dlf_documents'), '', '', '1'); if ($GLOBALS['TYPO3_DB']->sql_num_rows($result) == 1) { list($this->piVars['id']) = $GLOBALS['TYPO3_DB']->sql_fetch_row($result); // Set superglobal $_GET array. $_GET[$this->prefixId]['id'] = $this->piVars['id']; // Unset variable to avoid infinite looping. unset($this->piVars['recordId'], $_GET[$this->prefixId]['recordId']); // Try to load document. $this->loadDocument(); } else { if (TYPO3_DLOG) { \TYPO3\CMS\Core\Utility\GeneralUtility::devLog('[tx_dlf_doctype->loadDocument()] Failed to load document with record ID "' . $this->piVars['recordId'] . '"', $this->extKey, SYSLOG_SEVERITY_WARNING); } } } }