/**
  * 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) {
             t3lib_div::devLog('[tx_dlf_collection->main(' . $content . ', [data])] Incomplete plugin configuration', $this->extKey, SYSLOG_SEVERITY_WARNING, $conf);
         }
         return $content;
     }
     // 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/collection/template.tmpl'), '###TEMPLATE###');
     }
     // Get hook objects.
     $this->hookObjects = tx_dlf_helper::getHookObjects($this->scriptRelPath);
     if (!empty($this->piVars['collection'])) {
         $this->showSingleCollection(intval($this->piVars['collection']));
     } else {
         $content .= $this->showCollectionList();
     }
     return $this->pi_wrapInBaseClass($content);
 }
 /**
  * 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);
         }
     }
 }
 /**
  * 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);
     // Load current document.
     $this->loadDocument();
     if ($this->doc === NULL) {
         // Quit without doing anything if required variables are not set.
         return $content;
     } else {
         // Set default values if not set.
         if (!isset($this->conf['rootline'])) {
             $this->conf['rootline'] = 0;
         }
     }
     $metadata = array();
     if ($this->conf['rootline'] < 2) {
         // Get current structure's @ID.
         $ids = array();
         if (!empty($this->doc->physicalPages[$this->piVars['page']]) && !empty($this->doc->smLinks['p2l'][$this->doc->physicalPages[$this->piVars['page']]])) {
             foreach ($this->doc->smLinks['p2l'][$this->doc->physicalPages[$this->piVars['page']]] as $logId) {
                 $count = count($this->doc->mets->xpath('./mets:structMap[@TYPE="LOGICAL"]//mets:div[@ID="' . $logId . '"]/ancestor::*'));
                 $ids[$count][] = $logId;
             }
         }
         ksort($ids);
         reset($ids);
         // Check if we should display all metadata up to the root.
         if ($this->conf['rootline'] == 1) {
             foreach ($ids as $id) {
                 foreach ($id as $sid) {
                     $data = $this->doc->getMetadata($sid, $this->conf['pages']);
                     if (!empty($data)) {
                         $data['_id'] = $sid;
                         $metadata[] = $data;
                     }
                 }
             }
         } else {
             $id = array_pop($ids);
             if (is_array($id)) {
                 foreach ($id as $sid) {
                     $data = $this->doc->getMetadata($sid, $this->conf['pages']);
                     if (!empty($data)) {
                         $data['_id'] = $sid;
                         $metadata[] = $data;
                     }
                 }
             }
         }
     }
     // Get titledata?
     if (empty($metadata) || $this->conf['rootline'] == 1 && $metadata[0]['_id'] != $this->doc->toplevelId) {
         $data = $this->doc->getTitleData($this->conf['pages']);
         $data['_id'] = $this->doc->toplevelId;
         array_unshift($metadata, $data);
     }
     if (empty($metadata)) {
         if (TYPO3_DLOG) {
             \TYPO3\CMS\Core\Utility\GeneralUtility::devLog('[tx_dlf_metadata->main(' . $content . ', [data])] No metadata found for document with UID "' . $this->doc->uid . '"', $this->extKey, SYSLOG_SEVERITY_WARNING, $conf);
         }
         return $content;
     }
     ksort($metadata);
     // Get hook objects.
     $this->hookObjects = tx_dlf_helper::getHookObjects($this->scriptRelPath);
     // Hook for getting a customized title bar (requested by SBB).
     foreach ($this->hookObjects as $hookObj) {
         if (method_exists($hookObj, 'main_customizeTitleBarGetCustomTemplate')) {
             $hookObj->main_customizeTitleBarGetCustomTemplate($this, $metadata);
         }
     }
     $content .= $this->printMetadata($metadata);
     return $this->pi_wrapInBaseClass($content);
 }