/** * 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; }
/** * 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; }
/** * 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); } } }
/** * This translates an internal "index_name" * * @access public * * @param string $index_name: The internal "index_name" to translate * @param string $table: Get the translation from this table * @param string $pid: Get the translation from this page * * @return string Localized label for $index_name */ public static function translate($index_name, $table, $pid) { // Save parameters for logging purposes. $_index_name = $index_name; $_pid = $pid; // Load labels into static variable for future use. static $labels = array(); // Sanitize input. $pid = max(intval($pid), 0); if (!$pid) { if (TYPO3_DLOG) { t3lib_div::devLog('[tx_dlf_helper->translate(' . $_index_name . ', ' . $table . ', ' . $_pid . ')] Invalid PID "' . $pid . '" for translation', self::$extKey, SYSLOG_SEVERITY_WARNING); } return $index_name; } // Check if "index_name" is an UID. if (tx_dlf_helper::testInt($index_name)) { $index_name = self::getIndexName($index_name, $table, $pid); } /* The $labels already contain the translated content element, but with the index_name of the translated content element itself * and not with the $index_name of the original that we receive here. So we have to determine the index_name of the * associated translated content element. E.g. $labels['title0'] != $index_name = title. */ // First fetch the uid of the received index_name $result = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid', $table, 'pid=' . $pid . ' AND index_name="' . $index_name . '"' . self::whereClause($table), '', '', ''); if ($GLOBALS['TYPO3_DB']->sql_num_rows($result) > 0) { // Now we use the uid of the l18_parent to fetch the index_name of the translated content element. $resArray = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($result); $result = $GLOBALS['TYPO3_DB']->exec_SELECTquery('index_name', $table, 'pid=' . $pid . ' AND l18n_parent=' . $resArray['uid'] . ' AND sys_language_uid=' . intval($GLOBALS['TSFE']->sys_language_content) . self::whereClause($table), '', '', ''); if ($GLOBALS['TYPO3_DB']->sql_num_rows($result) > 0) { // If there is an translated content element, overwrite the received $index_name. $resArray = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($result); $index_name = $resArray['index_name']; } } // Check if we already got a translation. if (empty($labels[$table][$pid][$GLOBALS['TSFE']->sys_language_content][$index_name])) { // Check if this table is allowed for translation. if (in_array($table, array('tx_dlf_collections', 'tx_dlf_libraries', 'tx_dlf_metadata', 'tx_dlf_structures'))) { $additionalWhere = ' AND sys_language_uid IN (-1,0)'; if ($GLOBALS['TSFE']->sys_language_content > 0) { $additionalWhere = ' AND (sys_language_uid IN (-1,0) OR (sys_language_uid=' . intval($GLOBALS['TSFE']->sys_language_content) . ' AND l18n_parent=0))'; } // Get labels from database. $result = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', $table, 'pid=' . $pid . $additionalWhere . self::whereClause($table), '', '', ''); if ($GLOBALS['TYPO3_DB']->sql_num_rows($result) > 0) { while ($resArray = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($result)) { // Overlay localized labels if available. if ($GLOBALS['TSFE']->sys_language_content > 0) { $resArray = $GLOBALS['TSFE']->sys_page->getRecordOverlay($table, $resArray, $GLOBALS['TSFE']->sys_language_content, $GLOBALS['TSFE']->sys_language_mode == 'strict' ? 'hideNonTranslated' : ''); } if ($resArray) { $labels[$table][$pid][$GLOBALS['TSFE']->sys_language_content][$resArray['index_name']] = $resArray['label']; } } } else { if (TYPO3_DLOG) { t3lib_div::devLog('[tx_dlf_helper->translate(' . $_index_name . ', ' . $table . ', ' . $_pid . ')] No translation with PID "' . $pid . '" available in table "' . $table . '" or translation not accessible', self::extKey, SYSLOG_SEVERITY_NOTICE); } } } else { if (TYPO3_DLOG) { t3lib_div::devLog('[tx_dlf_helper->translate(' . $_index_name . ', ' . $table . ', ' . $_pid . ')] No translations available for table "' . $table . '"', self::$extKey, SYSLOG_SEVERITY_WARNING); } } } if (!empty($labels[$table][$pid][$GLOBALS['TSFE']->sys_language_content][$index_name])) { return $labels[$table][$pid][$GLOBALS['TSFE']->sys_language_content][$index_name]; } else { return $index_name; } }
/** * This sets the element at the given offset * @see ArrayAccess::offsetSet() * * @access public * * @param mixed $offset: The offset to set (non-integer offsets will be appended) * @param mixed $value: The value to set * * @return void */ public function offsetSet($offset, $value) { if (tx_dlf_helper::testInt($offset)) { $this->elements[$offset] = $value; } else { $this->elements[] = $value; } // Re-number the elements. $this->elements = array_values($this->elements); $this->count = count($this->elements); }
/** * 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); // Disable caching for this plugin. $this->setCache(FALSE); // Quit without doing anything if required variables are not set. if (empty($this->conf['solrcore'])) { if (TYPO3_DLOG) { t3lib_div::devLog('[tx_dlf_search->main(' . $content . ', [data])] Incomplete plugin configuration', $this->extKey, SYSLOG_SEVERITY_WARNING, $conf); } return $content; } if (!isset($this->piVars['query']) && empty($this->piVars['extQuery'])) { // Add javascript for search suggestions if enabled and jQuery autocompletion is available. if (!empty($this->conf['suggest'])) { $this->addAutocompleteJS(); } // 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/search/template.tmpl'), '###TEMPLATE###'); } // Set last query if applicable. $lastQuery = ''; $list = t3lib_div::makeInstance('tx_dlf_list'); if (!empty($list->metadata['options']['source']) && $list->metadata['options']['source'] == 'search') { $lastQuery = $list->metadata['options']['select']; } // Configure @action URL for form. $linkConf = array('parameter' => $GLOBALS['TSFE']->id, 'forceAbsoluteUrl' => 1); // Fill markers. $markerArray = array('###ACTION_URL###' => $this->cObj->typoLink_URL($linkConf), '###LABEL_QUERY###' => $this->pi_getLL('label.query'), '###LABEL_SUBMIT###' => $this->pi_getLL('label.submit'), '###FIELD_QUERY###' => $this->prefixId . '[query]', '###QUERY###' => htmlspecialchars($lastQuery), '###FIELD_DOC###' => $this->addCurrentDocument(), '###FIELD_COLL###' => $this->addCurrentCollection(), '###ADDITIONAL_INPUTS###' => $this->addEncryptedCoreName(), '###FACETS_MENU###' => $this->addFacetsMenu()); // Get additional fields for extended search. $extendedSearch = $this->addExtendedSearch(); // Display search form. $content .= $this->cObj->substituteSubpart($this->cObj->substituteMarkerArray($this->template, $markerArray), '###EXT_SEARCH_ENTRY###', $extendedSearch); return $this->pi_wrapInBaseClass($content); } else { // Instantiate search object. $solr = tx_dlf_solr::getInstance($this->conf['solrcore']); if (!$solr->ready) { if (TYPO3_DLOG) { t3lib_div::devLog('[tx_dlf_search->main(' . $content . ', [data])] Apache Solr not available', $this->extKey, SYSLOG_SEVERITY_ERROR, $conf); } return $content; } // Build label for result list. $label = $this->pi_getLL('search', '', TRUE); if (!empty($this->piVars['query'])) { $label .= htmlspecialchars(sprintf($this->pi_getLL('for', ''), $this->piVars['query'])); } // Set search parameters. $solr->limit = max(intval($this->conf['limit']), 1); $solr->cPid = $this->conf['pages']; // Set search query. $query = $this->piVars['query']; // Add extended search query. if (!empty($this->piVars['extQuery']) && is_array($this->piVars['extQuery'])) { if (!empty($query)) { $query = tx_dlf_solr::escapeQuery($query); } $allowedOperators = array('AND', 'OR', 'NOT'); $allowedFields = t3lib_div::trimExplode(',', $this->conf['extendedFields'], TRUE); for ($i = 0; $i < count($this->piVars['extQuery']); $i++) { if (!empty($this->piVars['extQuery'][$i])) { if (in_array($this->piVars['extOperator'][$i], $allowedOperators) && in_array($this->piVars['extField'][$i], $allowedFields)) { if (!empty($query)) { $query .= ' ' . $this->piVars['extOperator'][$i] . ' '; } $query .= tx_dlf_indexing::getIndexFieldName($this->piVars['extField'][$i], $this->conf['pages']) . ':(' . tx_dlf_solr::escapeQuery($this->piVars['extQuery'][$i]) . ')'; } } } } else { if (empty($this->piVars['fq']) && $query != "*") { $query = tx_dlf_solr::escapeQuery($query); } } // Set query parameters. $params = array(); // Add filter query for faceting. if (!empty($this->piVars['fq'])) { $params = array('fq' => $this->piVars['fq']); } // Add filter query for in-document searching. if ($this->conf['searchIn'] == 'document' || $this->conf['searchIn'] == 'all') { if (!empty($this->piVars['id']) && tx_dlf_helper::testInt($this->piVars['id'])) { $params['fq'][] = 'uid:' . $this->piVars['id'] . ' OR partof:' . $this->piVars['id']; $label .= htmlspecialchars(sprintf($this->pi_getLL('in', ''), tx_dlf_document::getTitle($this->piVars['id']))); } } // Add filter query for in-collection searching. if ($this->conf['searchIn'] == 'collection' || $this->conf['searchIn'] == 'all') { if (!empty($this->piVars['collection']) && tx_dlf_helper::testInt($this->piVars['collection'])) { $index_name = tx_dlf_helper::getIndexName($this->piVars['collection'], 'tx_dlf_collections', $this->conf['pages']); $params['fq'][] = 'collection_faceting:("' . tx_dlf_solr::escapeQuery($index_name) . '")'; $label .= sprintf($this->pi_getLL('in', '', TRUE), tx_dlf_helper::translate($index_name, 'tx_dlf_collections', $this->conf['pages'])); } } $solr->params = $params; // Perform search. $results = $solr->search($query); $results->metadata = array('label' => $label, 'description' => '<p class="tx-dlf-search-numHits">' . htmlspecialchars(sprintf($this->pi_getLL('hits', ''), $solr->numberOfHits, count($results))) . '</p>', 'thumbnail' => '', 'options' => $results->metadata['options']); $results->save(); // Clean output buffer. t3lib_div::cleanOutputBuffers(); // Keep some plugin variables. $linkConf['parameter'] = $this->conf['targetPid']; if (!empty($this->piVars['order'])) { $linkConf['additionalParams'] = t3lib_div::implodeArrayForUrl($this->prefixId, array('order' => $this->piVars['order'], 'asc' => !empty($this->piVars['asc']) ? '1' : '0'), '', TRUE, FALSE); } // Send headers. header('Location: ' . t3lib_div::locationHeaderUrl($this->cObj->typoLink_URL($linkConf))); // 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'] = tx_dlf_helper::intInRange($this->piVars['page'], 1, $this->doc->numPages, 1); $this->piVars['double'] = tx_dlf_helper::intInRange($this->piVars['double'], 0, 1, 0); } $menuArray = array(); // Does the document have physical pages or is it an external file? if ($this->doc->physicalPages || !tx_dlf_helper::testInt($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; }
/** * Processes a logical unit (and its children) for the Solr index * * @access protected * * @param tx_dlf_document &$doc: The METS document * @param array $logicalUnit: Array of the logical unit to process * * @return integer 0 on success or 1 on failure */ protected static function process(tx_dlf_document &$doc, array $logicalUnit) { $errors = 0; // Get metadata for logical unit. $metadata = $doc->metadataArray[$logicalUnit['id']]; if (!empty($metadata)) { // Load class. if (!class_exists('Apache_Solr_Document')) { require_once t3lib_div::getFileAbsFileName('EXT:' . self::$extKey . '/lib/SolrPhpClient/Apache/Solr/Document.php'); } // Create new Solr document. $solrDoc = new Apache_Solr_Document(); // Create unique identifier from document's UID and unit's XML ID. $solrDoc->setField('id', $doc->uid . $logicalUnit['id']); $solrDoc->setField('uid', $doc->uid); $solrDoc->setField('pid', $doc->pid); if (tx_dlf_helper::testInt($logicalUnit['points'])) { $solrDoc->setField('page', $logicalUnit['points']); } if ($logicalUnit['id'] == $doc->toplevelId) { $solrDoc->setField('thumbnail', $doc->thumbnail); } elseif (!empty($logicalUnit['thumbnailId'])) { $solrDoc->setField('thumbnail', $doc->getFileLocation($logicalUnit['thumbnailId'])); } $solrDoc->setField('partof', $doc->parentId); $solrDoc->setField('sid', $logicalUnit['id']); $solrDoc->setField('toplevel', in_array($logicalUnit['type'], self::$toplevel)); $solrDoc->setField('type', $logicalUnit['type'], self::$fields['fieldboost']['type']); $solrDoc->setField('title', $metadata['title'][0], self::$fields['fieldboost']['title']); $solrDoc->setField('volume', $metadata['volume'][0], self::$fields['fieldboost']['volume']); $autocomplete = array(); foreach ($metadata as $index_name => $data) { if (!empty($data) && substr($index_name, -8) !== '_sorting') { $solrDoc->setField(self::getIndexFieldName($index_name, $doc->pid), $data, self::$fields['fieldboost'][$index_name]); if (in_array($index_name, self::$fields['sortables'])) { // Add sortable fields to index. $solrDoc->setField($index_name . '_sorting', $metadata[$index_name . '_sorting'][0]); } if (in_array($index_name, self::$fields['facets'])) { // Add facets to index. $solrDoc->setField($index_name . '_faceting', $data); } if (in_array($index_name, self::$fields['autocompleted'])) { $autocomplete = array_merge($autocomplete, $data); } } } // Add autocomplete values to index. if (!empty($autocomplete)) { $solrDoc->setField('autocomplete', $autocomplete); } try { self::$solr->service->addDocument($solrDoc); } catch (Exception $e) { if (!defined('TYPO3_cliMode')) { $message = t3lib_div::makeInstance('t3lib_FlashMessage', tx_dlf_helper::getLL('flash.solrException', TRUE) . '<br />' . htmlspecialchars($e->getMessage()), tx_dlf_helper::getLL('flash.error', TRUE), t3lib_FlashMessage::ERROR, TRUE); t3lib_FlashMessageQueue::addMessage($message); } return 1; } } // Check for child elements... if (!empty($logicalUnit['children'])) { foreach ($logicalUnit['children'] as $child) { if (!$errors) { // ...and process them, too. $errors = self::process($doc, $child); } else { break; } } } return $errors; }