function handleGalleyNode(&$conference, &$schedConf, &$galleyNode, &$track, &$paper, &$errors, $isCommandLine, $isHtml, $galleyCount, &$paperFileManager) { $errors = array(); $conferenceSupportedLocales = array_keys($conference->getSupportedLocaleNames()); // => locales must be set up before $conferencePrimaryLocale = $conference->getPrimaryLocale(); $galleyDao =& DAORegistry::getDAO('PaperGalleyDAO'); if ($isHtml) { $galley = new PaperHtmlGalley(); } else { $galley = new PaperGalley(); } $galley->setPaperId($paper->getId()); $galley->setSequence($galleyCount); // just conference supported locales? $locale = $galleyNode->getAttribute('locale'); if ($locale == '') { $locale = $conferencePrimaryLocale; } elseif (!in_array($locale, $conferenceSupportedLocales)) { $errors[] = array('plugins.importexport.native.import.error.galleyLocaleUnsupported', array('paperTitle' => $paper->getLocalizedTitle(), 'locale' => $locale)); return false; } $galley->setLocale($locale); /* --- Galley Label --- */ if (!($node = $galleyNode->getChildByName('label'))) { $errors[] = array('plugins.importexport.native.import.error.galleyLabelMissing', array('paperTitle' => $paper->getLocalizedTitle(), 'trackTitle' => $track->getLocalizedTitle())); return false; } $galley->setLabel($node->getValue()); /* --- Galley File --- */ if (!($node = $galleyNode->getChildByName('file'))) { $errors[] = array('plugins.importexport.native.import.error.galleyFileMissing', array('paperTitle' => $paper->getLocalizedTitle(), 'trackTitle' => $track->getLocalizedTitle())); return false; } if ($href = $node->getChildByName('href')) { $url = $href->getAttribute('src'); if ($isCommandLine || NativeImportDom::isAllowedMethod($url)) { if ($isCommandLine && NativeImportDom::isRelativePath($url)) { // The command-line tool does a chdir; we need to prepend the original pathname to relative paths so we're not looking in the wrong place. $url = PWD . '/' . $url; } if (($fileId = $paperFileManager->copyPublicFile($url, $href->getAttribute('mime_type'))) === false) { $errors[] = array('plugins.importexport.native.import.error.couldNotCopy', array('url' => $url)); return false; } } } if ($embed = $node->getChildByName('embed')) { if (($type = $embed->getAttribute('encoding')) !== 'base64') { $errors[] = array('plugins.importexport.native.import.error.unknownEncoding', array('type' => $type)); return false; } $originalName = $embed->getAttribute('filename'); if (($fileId = $paperFileManager->writePublicFile($originalName, base64_decode($embed->getValue()), $embed->getAttribute('mime_type'))) === false) { $errors[] = array('plugins.importexport.native.import.error.couldNotWriteFile', array('originalName' => $originalName)); return false; } } if (!isset($fileId)) { $errors[] = array('plugins.importexport.native.import.error.galleyFileMissing', array('paperTitle' => $paper->getLocalizedTitle(), 'trackTitle' => $track->getLocalizedTitle())); return false; } $galley->setFileId($fileId); $galleyDao->insertGalley($galley); if ($isHtml) { $result = NativeImportDom::handleHtmlGalleyNodes($galleyNode, $paperFileManager, $galley, $errors, $isCommandLine); if (!$result) { return false; } } return true; }
/** * Internal function to return an PaperGalley object from a row. * @param $row array * @return PaperGalley */ function &_returnGalleyFromRow(&$row) { if ($row['html_galley']) { $galley = new PaperHTMLGalley(); // HTML-specific settings $galley->setStyleFileId($row['style_file_id']); if ($row['style_file_id']) { $galley->setStyleFile($this->paperFileDao->getPaperFile($row['style_file_id'])); } // Retrieve images $images =& $this->getGalleyImages($row['galley_id']); $galley->setImageFiles($images); } else { $galley = new PaperGalley(); } $galley->setId($row['galley_id']); $galley->setPaperId($row['paper_id']); $galley->setLocale($row['locale']); $galley->setFileId($row['file_id']); $galley->setLabel($row['label']); $galley->setSequence($row['seq']); $galley->setViews($row['views']); // PaperFile set methods $galley->setFileName($row['file_name']); $galley->setOriginalFileName($row['original_file_name']); $galley->setFileType($row['file_type']); $galley->setFileSize($row['file_size']); $galley->setDateModified($this->datetimeFromDB($row['date_modified'])); $galley->setDateUploaded($this->datetimeFromDB($row['date_uploaded'])); HookRegistry::call('PaperGalleyDAO::_returnGalleyFromRow', array(&$galley, &$row)); return $galley; }