/** * Constructor. */ function PaperHTMLGalley() { parent::PaperGalley(); }
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; }
/** * Import papers (including metadata and files). */ function importPapers() { if ($this->hasOption('verbose')) { printf("Importing papers\n"); } import('classes.file.PaperFileManager'); import('classes.search.PaperSearchIndex'); $userDao =& DAORegistry::getDAO('UserDAO'); $roleDao =& DAORegistry::getDAO('RoleDAO'); $trackDao =& DAORegistry::getDAO('TrackDAO'); $paperDao =& DAORegistry::getDAO('PaperDAO'); $publishedPaperDao =& DAORegistry::getDAO('PublishedPaperDAO'); $galleyDao =& DAORegistry::getDAO('PaperGalleyDAO'); $unassignedTrackId = null; $result =& $this->importDao->retrieve('SELECT * FROM papers ORDER by id'); while (!$result->EOF) { $row =& $result->fields; $schedConf =& $this->schedConfMap[$row['cf']]; $schedConfId = $schedConf->getId(); // Bring in the primary user for this paper. $user = $userDao->getUserByUsername(Core::cleanVar($row['login'])); if (!$user) { unset($user); $user = new User(); $user->setUsername(Core::cleanVar($row['login'])); $user->setFirstName(Core::cleanVar($row['first_name'])); $user->setLastName(Core::cleanVar($row['surname'])); $user->setAffiliation(Core::cleanVar($row['affiliation']), Locale::getLocale()); $user->setEmail(Core::cleanVar($row['email'])); $user->setUrl(Core::cleanVar($row['url'])); $user->setBiography(Core::cleanVar($row['bio']), Locale::getLocale()); $user->setLocales(array()); $user->setDateRegistered($row['created']); $user->setDateLastLogin($row['created']); $user->setMustChangePassword(1); $password = Validation::generatePassword(); $user->setPassword(Validation::encryptCredentials($user->getUsername(), $password)); if ($this->hasOption('emailUsers')) { import('classes.mail.MailTemplate'); $mail = new MailTemplate('USER_REGISTER'); $mail->setFrom($schedConf->getSetting('contactEmail'), $schedConf->getSetting('contactName')); $mail->assignParams(array('username' => $user->getUsername(), 'password' => $password, 'conferenceName' => $schedConf->getFullTitle())); $mail->addRecipient($user->getEmail(), $user->getFullName()); $mail->send(); } $user->setDisabled(0); $otherUser =& $userDao->getUserByEmail(Core::cleanVar($row['email'])); if ($otherUser !== null) { // User exists with this email -- munge it to make unique $user->setEmail('ocs-' . Core::cleanVar($row['login']) . '+' . Core::cleanVar($row['email'])); $this->conflicts[] = array(&$otherUser, &$user); } unset($otherUser); $userDao->insertUser($user); // Make this user a author $role = new Role(); $role->setSchedConfId($schedConf->getId()); $role->setConferenceId($schedConf->getConferenceId()); $role->setUserId($user->getId()); $role->setRoleId(ROLE_ID_AUTHOR); $roleDao->insertRole($role); unset($role); } $userId = $user->getId(); // Bring in the basic entry for the paper $paper = new Paper(); $paper->setUserId($userId); $paper->setLocale(Locale::getPrimaryLocale()); $paper->setSchedConfId($schedConfId); $oldTrackId = $row['primary_track_id']; if (!$oldTrackId || !isset($this->trackMap[$oldTrackId])) { $oldTrackId = $row['secondary_track_id']; } if (!$oldTrackId || !isset($this->trackMap[$oldTrackId])) { if (!$unassignedTrackId) { // Create an "Unassigned" track to use for submissions // that didn't have a track in OCS 1.x. $track = new Track(); $track->setSchedConfId($schedConf->getId()); $track->setTitle('UNASSIGNED', Locale::getLocale()); $track->setSequence(REALLY_BIG_NUMBER); $track->setDirectorRestricted(1); $track->setMetaReviewed(1); $unassignedTrackId = $trackDao->insertTrack($track); } $newTrackId = $unassignedTrackId; } else { $newTrackId = $this->trackMap[$oldTrackId]; } $paper->setTrackId($newTrackId); $paper->setTitle(Core::cleanVar($row['title']), Locale::getLocale()); $paper->setAbstract(Core::cleanVar($row['abstract']), Locale::getLocale()); $paper->setDiscipline(Core::cleanVar($row['discipline']), Locale::getLocale()); $paper->setSponsor(Core::cleanVar($row['sponsor']), Locale::getLocale()); $paper->setSubject(Core::cleanVar($row['topic']), Locale::getLocale()); $paper->setLanguage(Core::cleanVar($row['language'])); $paper->setDateSubmitted($row['created']); $paper->setDateStatusModified($row['timestamp']); // $paper->setTypeConst($row['present_format'] == 'multiple' ? SUBMISSION_TYPE_PANEL : SUBMISSION_TYPE_SINGLE); FIXME $paper->setCurrentRound(REVIEW_ROUND_ABSTRACT); $paper->setSubmissionProgress(0); $paper->setPages(''); // Bring in authors $firstNames = split("\n", Core::cleanVar($row['first_name'] . "\n" . $row['add_first_names'])); $lastNames = split("\n", Core::cleanVar($row['surname'] . "\n" . $row['add_surnames'])); $emails = split("\n", Core::cleanVar($row['email'] . "\n" . $row['add_emails'])); $affiliations = split("\n", Core::cleanVar($row['affiliation'] . "\n" . $row['add_affiliations'])); $urls = split("\n", Core::cleanVar($row['url'] . "\n" . $row['add_urls'])); foreach ($emails as $key => $email) { if (empty($email)) { continue; } $author = new Author(); $author->setEmail($email); $author->setFirstName($firstNames[$key]); $author->setLastName($lastNames[$key]); $author->setAffiliation($affiliations[$key], Locale::getLocale()); @$author->setUrl($urls[$key]); // Suppress warnings from inconsistent OCS 1.x data $author->setPrimaryContact($key == 0 ? 1 : 0); $paper->addAuthor($author); unset($author); } switch ($row['accepted']) { case 'true': $paper->setStatus(STATUS_PUBLISHED); $paperId = $paperDao->insertPaper($paper); $publishedPaper = new PublishedPaper(); $publishedPaper->setPaperId($paperId); $publishedPaper->setSchedConfId($schedConfId); $publishedPaper->setDatePublished(Core::getCurrentDate()); $publishedPaper->setSeq(REALLY_BIG_NUMBER); $publishedPaper->setViews(0); $publishedPaperDao->insertPublishedPaper($publishedPaper); $publishedPaperDao->resequencePublishedPapers($paper->getTrackId(), $schedConfId); break; case 'reject': $paper->setStatus(STATUS_DECLINED); $paperId = $paperDao->insertPaper($paper); break; default: $paper->setStatus(STATUS_QUEUED); $paperId = $paperDao->insertPaper($paper); } $this->paperMap[$row['id']] =& $paper; $paperFileManager = new PaperFileManager($paperId); if (!empty($row['paper']) && $row['paper'] != 'PDF') { $format = 'text/html'; $extension = $paperFileManager->getDocumentExtension($format); $fileId = $paperFileManager->writeSubmissionFile('migratedFile' . $extension, $row['paper'], $format); $paper->setSubmissionFileId($fileId); $paperDao->updatePaper($paper); $fileId = $paperFileManager->writePublicFile('migratedGalley' . $extension, $row['paper'], $format); PaperSearchIndex::updateFileIndex($paperId, PAPER_SEARCH_GALLEY_FILE, $fileId); if (strstr($format, 'html')) { $galley = new PaperHTMLGalley(); $galley->setLabel('HTML'); } else { $galley = new PaperGalley(); switch ($format) { case 'application/pdf': $galley->setLabel('PDF'); break; case 'application/postscript': $galley->setLabel('PostScript'); break; case 'application/msword': $galley->setLabel('Word'); break; case 'text/xml': $galley->setLabel('XML'); break; case 'application/powerpoint': $galley->setLabel('Slideshow'); break; default: $galley->setLabel('Untitled'); break; } } $galley->setLocale(Locale::getLocale()); $galley->setPaperId($paperId); $galley->setFileId($fileId); $galleyDao->insertGalley($galley); unset($galley); } elseif ($row['paper'] == 'PDF') { $fileId = $paperFileManager->copySubmissionFile($this->importPath . '/papers/' . $row['pdf'], 'application/pdf'); $paper->setSubmissionFileId($fileId); $paperDao->updatePaper($paper); $fileId = $paperFileManager->copyPublicFile($this->importPath . '/papers/' . $row['pdf'], 'application/pdf'); PaperSearchIndex::updateFileIndex($paperId, PAPER_SEARCH_GALLEY_FILE, $fileId); $galley = new PaperGalley(); $galley->setLabel('PDF'); $galley->setLocale(Locale::getLocale()); $galley->setPaperId($paperId); $galley->setFileId($fileId); $galleyDao->insertGalley($galley); unset($galley); } // FIXME: The following fields from OCS 1.x are UNUSED: // program_insert approach coverage format relation appendix_names appendix_dates // appendix appendix_pdf secondary_track_id multiple_* restrict_access paper_email // delete_paper comment_email unset($user); unset($paper); unset($schedConf); unset($paperFileManager); $result->MoveNext(); } $result->Close(); }
/** * 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; }
/** * Set the file to use as the default editing file. * @param $trackDirectorSubmission object * @param $fileId int * @param $revision int * @param $createGalley boolean * TODO: SECURITY! */ function setEditingFile($trackDirectorSubmission, $fileId, $revision, $createGalley = false) { import('file.PaperFileManager'); $paperFileManager = new PaperFileManager($trackDirectorSubmission->getPaperId()); $trackDirectorSubmissionDao =& DAORegistry::getDAO('TrackDirectorSubmissionDAO'); $paperFileDao =& DAORegistry::getDAO('PaperFileDAO'); $user =& Request::getUser(); if (!HookRegistry::call('TrackDirectorAction::setEditingFile', array(&$trackDirectorSubmission, &$fileId, &$revision))) { // Copy the file from the director decision file folder to the layout folder $newFileId = $paperFileManager->copyToLayoutFile($fileId, $revision); $trackDirectorSubmission->setLayoutFileId($newFileId); $trackDirectorSubmissionDao->updateTrackDirectorSubmission($trackDirectorSubmission); if ($createGalley) { $paperGalleyDao =& DAORegistry::getDAO('PaperGalleyDAO'); $galleys =& $paperGalleyDao->getGalleysByPaper($trackDirectorSubmission->getPaperId()); if (empty($galleys)) { $layoutFile =& $paperFileDao->getPaperFile($newFileId, $revision); $fileType = $layoutFile->getFileType(); $fileId = $paperFileManager->copyPublicFile($layoutFile->getFilePath(), $fileType); if (strstr($fileType, 'html')) { $galley = new PaperHTMLGalley(); } else { $galley = new PaperGalley(); } $galley->setPaperId($trackDirectorSubmission->getPaperId()); $galley->setLocale(Locale::getLocale()); $galley->setFileId($fileId); if ($galley->isHTMLGalley()) { $galley->setLabel('HTML'); } elseif (strstr($fileType, 'pdf')) { $galley->setLabel('PDF'); } else { if (strstr($fileType, 'postscript')) { $galley->setLabel('Postscript'); } else { if (strstr($fileType, 'xml')) { $galley->setLabel('XML'); } else { $galley->setLabel(Locale::translate('common.untitled')); } } } $paperGalleyDao->insertGalley($galley); } } // Add log import('paper.log.PaperLog'); import('paper.log.PaperEventLogEntry'); PaperLog::logEvent($trackDirectorSubmission->getPaperId(), PAPER_LOG_LAYOUT_SET_FILE, LOG_TYPE_FILE, $trackDirectorSubmission->getLayoutFileId(), 'log.layout.layoutFileSet', array('directorName' => $user->getFullName(), 'paperId' => $trackDirectorSubmission->getPaperId())); } }
/** * Save changes to the galley. * @return int the galley ID */ function execute($fileName = null) { import('classes.file.PaperFileManager'); $paperFileManager = new PaperFileManager($this->paperId); $galleyDao =& DAORegistry::getDAO('PaperGalleyDAO'); $fileName = isset($fileName) ? $fileName : 'galleyFile'; if (isset($this->galley)) { $galley =& $this->galley; // Upload galley file if ($paperFileManager->uploadedFileExists($fileName)) { if ($galley->getFileId()) { $paperFileManager->uploadPublicFile($fileName, $galley->getFileId()); } else { $fileId = $paperFileManager->uploadPublicFile($fileName); $galley->setFileId($fileId); } // Update file search index import('classes.search.PaperSearchIndex'); PaperSearchIndex::updateFileIndex($this->paperId, PAPER_SEARCH_GALLEY_FILE, $galley->getFileId()); } if ($paperFileManager->uploadedFileExists('styleFile')) { // Upload stylesheet file $styleFileId = $paperFileManager->uploadPublicFile('styleFile', $galley->getStyleFileId()); $galley->setStyleFileId($styleFileId); } else { if ($this->getData('deleteStyleFile')) { // Delete stylesheet file $styleFile =& $galley->getStyleFile(); if (isset($styleFile)) { $paperFileManager->deleteFile($styleFile->getFileId()); } } } // Update existing galley $galley->setLabel($this->getData('label')); $galley->setLocale($this->getData('galleyLocale')); $galleyDao->updateGalley($galley); } else { // Upload galley file if ($paperFileManager->uploadedFileExists($fileName)) { $fileType = $paperFileManager->getUploadedFileType($fileName); $fileId = $paperFileManager->uploadPublicFile($fileName); // Update file search index import('classes.search.PaperSearchIndex'); PaperSearchIndex::updateFileIndex($this->paperId, PAPER_SEARCH_GALLEY_FILE, $fileId); } else { $fileId = 0; } if (isset($fileType) && strstr($fileType, 'html')) { // Assume HTML galley $galley = new PaperHTMLGalley(); } else { $galley = new PaperGalley(); } $galley->setPaperId($this->paperId); $galley->setFileId($fileId); if ($this->getData('label') == null) { // Generate initial label based on file type if ($galley->isHTMLGalley()) { $galley->setLabel('HTML'); } else { if (isset($fileType)) { if (strstr($fileType, 'pdf')) { $galley->setLabel('PDF'); } else { if (strstr($fileType, 'postscript')) { $galley->setLabel('PostScript'); } else { if (strstr($fileType, 'xml')) { $galley->setLabel('XML'); } else { if (strstr($fileType, 'audio')) { $galley->setLabel('Audio'); } else { if (strstr($fileType, 'powerpoint')) { $galley->setLabel('Slideshow'); } } } } } } } if ($galley->getLabel() == null) { $galley->setLabel(Locale::translate('common.untitled')); } } else { $galley->setLabel($this->getData('label')); } $galley->setLocale($this->getData('galleyLocale')); // Insert new galley $galleyDao->insertGalley($galley); $this->galleyId = $galley->getId(); } return $this->galleyId; }