Get the path to a journal's public files directory.
public getContextFilesPath ( $assocType, $contextId ) : string | ||
$assocType | int Assoc type for context | |
$contextId | int Press ID | |
return | string |
/** * Constructor. * Initialize template engine and assign basic template variables. * @param $request PKPRequest */ function TemplateManager($request) { parent::PKPTemplateManager($request); if (!defined('SESSION_DISABLE_INIT')) { /** * Kludge to make sure no code that tries to connect to * the database is executed (e.g., when loading * installer pages). */ $context = $request->getContext(); $site = $request->getSite(); $publicFileManager = new PublicFileManager(); $siteFilesDir = $request->getBaseUrl() . '/' . $publicFileManager->getSiteFilesPath(); $this->assign('sitePublicFilesDir', $siteFilesDir); $this->assign('publicFilesDir', $siteFilesDir); // May be overridden by press $siteStyleFilename = $publicFileManager->getSiteFilesPath() . '/' . $site->getSiteStyleFilename(); if (file_exists($siteStyleFilename)) { $this->addStyleSheet($request->getBaseUrl() . '/' . $siteStyleFilename, STYLE_SEQUENCE_LAST); } if (isset($context)) { $this->assign('currentPress', $context); $this->assign('siteTitle', $context->getLocalizedName()); $this->assign('publicFilesDir', $request->getBaseUrl() . '/' . $publicFileManager->getContextFilesPath($context->getAssocType(), $context->getId())); $this->assign('primaryLocale', $context->getPrimaryLocale()); $this->assign('alternateLocales', $context->getSetting('alternateLocales')); // Assign page header $this->assign('displayPageHeaderTitle', $context->getPageHeaderTitle()); $this->assign('displayPageHeaderLogo', $context->getPageHeaderLogo()); $this->assign('alternatePageHeader', $context->getLocalizedSetting('pageHeader')); $this->assign('metaSearchDescription', $context->getLocalizedSetting('searchDescription')); $this->assign('metaSearchKeywords', $context->getLocalizedSetting('searchKeywords')); $this->assign('metaCustomHeaders', $context->getLocalizedSetting('customHeaders')); $this->assign('numPageLinks', $context->getSetting('numPageLinks')); $this->assign('itemsPerPage', $context->getSetting('itemsPerPage')); $this->assign('enableAnnouncements', $context->getSetting('enableAnnouncements')); // Assign stylesheets and footer $contextStyleSheet = $context->getSetting('styleSheet'); if ($contextStyleSheet) { $this->addStyleSheet($request->getBaseUrl() . '/' . $publicFileManager->getContextFilesPath(ASSOC_TYPE_PRESS, $context->getId()) . '/' . $contextStyleSheet['uploadName'], STYLE_SEQUENCE_LAST); } // Include footer links if they have been defined. $footerCategoryDao = DAORegistry::getDAO('FooterCategoryDAO'); $footerCategories = $footerCategoryDao->getNotEmptyByContextId($context->getId()); $this->assign('footerCategories', $footerCategories->toArray()); $footerLinkDao = DAORegistry::getDAO('FooterLinkDAO'); $this->assign('maxLinks', $footerLinkDao->getLargestCategoryTotalbyContextId($context->getId())); $this->assign('pageFooter', $context->getLocalizedSetting('pageFooter')); } else { // Add the site-wide logo, if set for this locale or the primary locale $displayPageHeaderTitle = $site->getLocalizedPageHeaderTitle(); $this->assign('displayPageHeaderTitle', $displayPageHeaderTitle); if (isset($displayPageHeaderTitle['altText'])) { $this->assign('displayPageHeaderTitleAltText', $displayPageHeaderTitle['altText']); } $this->assign('siteTitle', $site->getLocalizedTitle()); } } }
/** * Parse out the issue style sheet and store it in an issue. * @param DOMElement $node * @param Issue $issue */ function parseIssueStyle($node, $issue) { for ($n = $node->firstChild; $n !== null; $n = $n->nextSibling) { if (is_a($n, 'DOMElement')) { switch ($n->tagName) { case 'style_file_name': $issue->setStyleFileName($n->textContent); break; case 'original_style_file_name': $issue->setOriginalStyleFileName($n->textContent); break; case 'embed': import('classes.file.PublicFileManager'); $publicFileManager = new PublicFileManager(); $filePath = $publicFileManager->getContextFilesPath(ASSOC_TYPE_JOURNAL, $issue->getJournalId()) . '/' . $issue->getStyleFileName(); file_put_contents($filePath, base64_decode($n->textContent)); break; } } } }
/** * Add the issue cover image to its DOM element. * @param $doc DOMDocument * @param $issueNode DOMElement * @param $issue Issue */ function addStyleFile($doc, $issueNode, $issue) { $originalStyleFileName = $issue->getOriginalStyleFileName(); if ($originalStyleFileName) { $deployment = $this->getDeployment(); $issueStyleNode = $doc->createElementNS($deployment->getNamespace(), 'issue_style'); $issueStyleNode->appendChild($node = $doc->createElementNS($deployment->getNamespace(), 'style_file_name', $issue->getStyleFileName())); $issueStyleNode->appendChild($node = $doc->createElementNS($deployment->getNamespace(), 'original_style_file_name', $issue->getOriginalStyleFileName())); import('classes.file.PublicFileManager'); $publicFileManager = new PublicFileManager(); $filePath = $publicFileManager->getContextFilesPath(ASSOC_TYPE_JOURNAL, $issue->getJournalId()) . '/' . $issue->getStyleFileName(); $embedNode = $doc->createElementNS($deployment->getNamespace(), 'embed', base64_encode(file_get_contents($filePath))); $embedNode->setAttribute('encoding', 'base64'); $issueStyleNode->appendChild($embedNode); $issueNode->appendChild($issueStyleNode); } }
/** * Save the new image file. * @param $request Request. */ function execute($request) { $temporaryFile = $this->fetchTemporaryFile($request); import('classes.file.PublicFileManager'); $publicFileManager = new PublicFileManager(); if (is_a($temporaryFile, 'TemporaryFile')) { $type = $temporaryFile->getFileType(); $extension = $publicFileManager->getImageExtension($type); if (!$extension) { return false; } $locale = AppLocale::getLocale(); $context = $request->getContext(); $uploadName = $this->getFileSettingName() . '_' . $locale . $extension; if ($publicFileManager->copyContextFile($context->getAssocType(), $context->getId(), $temporaryFile->getFilePath(), $uploadName)) { // Get image dimensions $filePath = $publicFileManager->getContextFilesPath($context->getAssocType(), $context->getId()); list($width, $height) = getimagesize($filePath . '/' . $uploadName); $value = $context->getSetting($this->getFileSettingName()); $imageAltText = $this->getData('imageAltText'); $value[$locale] = array('name' => $temporaryFile->getOriginalFileName(), 'uploadName' => $uploadName, 'width' => $width, 'height' => $height, 'dateUploaded' => Core::getCurrentDate(), 'altText' => $imageAltText[$locale]); $settingsDao = $context->getSettingsDAO(); $settingsDao->updateSetting($context->getId(), $this->getFileSettingName(), $value, 'object', true); // Clean up the temporary file. $this->removeTemporaryFile($request); return true; } } return false; }
/** * Add the issue cover image to its DOM element. * @param $doc DOMDocument * @param $issueNode DOMElement * @param $issue Issue */ function addCoverImage($doc, $issueNode, $issue) { $coverImage = $issue->getCoverImage(); if (!empty($coverImage)) { $deployment = $this->getDeployment(); $issueCoverNode = $doc->createElementNS($deployment->getNamespace(), 'issue_cover'); $issueCoverNode->appendChild($node = $doc->createElementNS($deployment->getNamespace(), 'cover_image', $issue->getCoverImage())); $issueCoverNode->appendChild($node = $doc->createElementNS($deployment->getNamespace(), 'cover_image_alt_text', $issue->getCoverImage())); import('classes.file.PublicFileManager'); $publicFileManager = new PublicFileManager(); $filePath = $publicFileManager->getContextFilesPath(ASSOC_TYPE_JOURNAL, $issue->getJournalId()) . '/' . $issue->getCoverImage(); $embedNode = $doc->createElementNS($deployment->getNamespace(), 'embed', base64_encode(file_get_contents($filePath))); $embedNode->setAttribute('encoding', 'base64'); $issueCoverNode->appendChild($embedNode); $issueNode->appendChild($issueCoverNode); } }
/** * Add the issue cover images to its DOM element. * @param $doc DOMDocument * @param $issueNode DOMElement * @param $issue Issue */ function addCoverImages($doc, $issueNode, $issue) { $coverImages = $issue->getCoverImage(null); if (!empty($coverImages)) { $deployment = $this->getDeployment(); $issueCoversNode = $doc->createElementNS($deployment->getNamespace(), 'issue_covers'); foreach ($coverImages as $locale => $coverImage) { $coverNode = $doc->createElementNS($deployment->getNamespace(), 'cover'); $coverNode->setAttribute('locale', $locale); $coverNode->appendChild($node = $doc->createElementNS($deployment->getNamespace(), 'cover_image', htmlspecialchars($coverImage, ENT_COMPAT, 'UTF-8'))); $coverNode->appendChild($node = $doc->createElementNS($deployment->getNamespace(), 'cover_image_alt_text', htmlspecialchars($issue->getCoverImageAltText($locale), ENT_COMPAT, 'UTF-8'))); import('classes.file.PublicFileManager'); $publicFileManager = new PublicFileManager(); $filePath = $publicFileManager->getContextFilesPath(ASSOC_TYPE_JOURNAL, $issue->getJournalId()) . '/' . $coverImage; $embedNode = $doc->createElementNS($deployment->getNamespace(), 'embed', base64_encode(file_get_contents($filePath))); $embedNode->setAttribute('encoding', 'base64'); $coverNode->appendChild($embedNode); $issueCoversNode->appendChild($coverNode); } $issueNode->appendChild($issueCoversNode); } }
/** * Constructor. * Initialize template engine and assign basic template variables. * @param $request PKPRequest */ function TemplateManager($request) { parent::PKPTemplateManager($request); AppLocale::requireComponents(LOCALE_COMPONENT_APP_COMMON); if (!defined('SESSION_DISABLE_INIT')) { /** * Kludge to make sure no code that tries to connect to * the database is executed (e.g., when loading * installer pages). */ $context = $request->getContext(); $site = $request->getSite(); $publicFileManager = new PublicFileManager(); $siteFilesDir = $request->getBaseUrl() . '/' . $publicFileManager->getSiteFilesPath(); $this->assign('sitePublicFilesDir', $siteFilesDir); $this->assign('publicFilesDir', $siteFilesDir); // May be overridden by press $siteStyleFilename = $publicFileManager->getSiteFilesPath() . '/' . $site->getSiteStyleFilename(); if (file_exists($siteStyleFilename)) { $this->addStyleSheet($request->getBaseUrl() . '/' . $siteStyleFilename, STYLE_SEQUENCE_LAST); } if (isset($context)) { $this->assign('currentPress', $context); $this->assign('siteTitle', $context->getLocalizedName()); $this->assign('publicFilesDir', $request->getBaseUrl() . '/' . $publicFileManager->getContextFilesPath($context->getAssocType(), $context->getId())); $this->assign('primaryLocale', $context->getPrimaryLocale()); $this->assign('alternateLocales', $context->getSetting('alternateLocales')); // Assign page header $this->assign('displayPageHeaderTitle', $context->getPageHeaderTitle()); $this->assign('displayPageHeaderLogo', $context->getPageHeaderLogo()); $this->assign('alternatePageHeader', $context->getLocalizedSetting('pageHeader')); $this->assign('metaSearchDescription', $context->getLocalizedSetting('searchDescription')); $this->assign('metaSearchKeywords', $context->getLocalizedSetting('searchKeywords')); $this->assign('metaCustomHeaders', $context->getLocalizedSetting('customHeaders')); $this->assign('numPageLinks', $context->getSetting('numPageLinks')); $this->assign('itemsPerPage', $context->getSetting('itemsPerPage')); $this->assign('enableAnnouncements', $context->getSetting('enableAnnouncements')); // Assign stylesheets and footer $contextStyleSheet = $context->getSetting('styleSheet'); if ($contextStyleSheet) { $this->addStyleSheet($request->getBaseUrl() . '/' . $publicFileManager->getContextFilesPath(ASSOC_TYPE_PRESS, $context->getId()) . '/' . $contextStyleSheet['uploadName'], STYLE_SEQUENCE_LAST); } // Get context info for use in primary navigation items import('pages.about.AboutContextHandler'); if (in_array('IAboutContextInfoProvider', class_implements('AboutContextHandler'))) { $this->assign('contextInfo', AboutContextHandler::getAboutInfo($context)); } // Get a link to the settings page for the current context. // This allows us to reduce template duplication by using this // variable in templates/common/header.tpl, instead of // reproducing a lot of OMP/OJS-specific logic there. $router = $request->getRouter(); $dispatcher = $request->getDispatcher(); $this->assign('contextSettingsUrl', $dispatcher->url($request, ROUTE_PAGE, null, 'management', 'settings', 'press')); // Include footer links if they have been defined. $footerCategoryDao = DAORegistry::getDAO('FooterCategoryDAO'); $footerCategories = $footerCategoryDao->getNotEmptyByContextId($context->getId()); $this->assign('footerCategories', $footerCategories->toArray()); $footerLinkDao = DAORegistry::getDAO('FooterLinkDAO'); $this->assign('maxLinks', $footerLinkDao->getLargestCategoryTotalbyContextId($context->getId())); $this->assign('pageFooter', $context->getLocalizedSetting('pageFooter')); } else { // Add the site-wide logo, if set for this locale or the primary locale $displayPageHeaderTitle = $site->getLocalizedPageHeaderTitle(); $this->assign('displayPageHeaderTitle', $displayPageHeaderTitle); if (isset($displayPageHeaderTitle['altText'])) { $this->assign('displayPageHeaderTitleAltText', $displayPageHeaderTitle['altText']); } $this->assign('siteTitle', $site->getLocalizedTitle()); } } }
/** * Localize article cover images. * @return boolean True indicates success. */ function localizeArticleCoverImages() { $articleDao = DAORegistry::getDAO('ArticleDAO'); $publicFileManager = new PublicFileManager(); // remove strange old cover images with array values in the DB - from 3.alpha or 3.beta? $articleDao->update('DELETE FROM submission_settings WHERE setting_name = \'coverImage\' AND setting_type = \'object\''); // remove empty 3.0 cover images $articleDao->update('DELETE FROM submission_settings WHERE setting_name = \'coverImage\' AND locale = \'\' AND setting_value = \'\''); $articleDao->update('DELETE FROM submission_settings WHERE setting_name = \'coverImageAltText\' AND locale = \'\' AND setting_value = \'\''); // get cover image duplicates, from 2.4.x and 3.0 $result = $articleDao->retrieve('SELECT DISTINCT ss1.submission_id, ss1.setting_value, s.context_id FROM submission_settings ss1 LEFT JOIN submissions s ON (s.submission_id = ss1.submission_id) JOIN submission_settings ss2 ON (ss2.submission_id = ss1.submission_id AND ss2.setting_name = \'coverImage\') WHERE ss1.setting_name = \'fileName\''); // remove the old 2.4.x cover images, for which a new cover image exists while (!$result->EOF) { $row = $result->GetRowAssoc(false); $submissionId = $row['submission_id']; $oldFileName = $row['setting_value']; if ($publicFileManager->fileExists($publicFileManager->getContextFilesPath(ASSOC_TYPE_JOURNAL, $row['context_id']) . '/' . $oldFileName)) { $publicFileManager->removeJournalFile($row['journal_id'], $oldFileName); } $articleDao->update('DELETE FROM submission_settings WHERE submission_id = ? AND setting_name = \'fileName\' AND setting_value = ?', array((int) $submissionId, $oldFileName)); $result->MoveNext(); } $result->Close(); // retrieve names for unlocalized article cover images $result = $articleDao->retrieve('SELECT ss.submission_id, ss.setting_value, j.journal_id, j.primary_locale FROM submission_settings ss, submissions s, journals j WHERE ss.setting_name = \'coverImage\' AND ss.locale = \'\' AND s.submission_id = ss.submission_id AND j.journal_id = s.context_id'); // for all unlocalized article cover images // rename (copy + remove) the cover images files in the public folder, // considereing the locale (using the journal primary locale) while (!$result->EOF) { $row = $result->GetRowAssoc(false); $oldFileName = $row['setting_value']; $newFileName = str_replace('.', '_' . $row['primary_locale'] . '.', $oldFileName); if ($publicFileManager->fileExists($publicFileManager->getContextFilesPath(ASSOC_TYPE_JOURNAL, $row['journal_id']) . '/' . $oldFileName)) { $publicFileManager->copyJournalFile($row['journal_id'], $publicFileManager->getContextFilesPath(ASSOC_TYPE_JOURNAL, $row['journal_id']) . '/' . $oldFileName, $newFileName); $publicFileManager->removeJournalFile($row['journal_id'], $oldFileName); } $result->MoveNext(); } $result->Close(); $driver = $articleDao->getDriver(); switch ($driver) { case 'mysql': case 'mysqli': // Update cover image names in the submission_settings table $articleDao->update('UPDATE submission_settings ss, submissions s, journals j SET ss.locale = j.primary_locale, ss.setting_value = CONCAT(LEFT( ss.setting_value, LOCATE(\'.\', ss.setting_value) - 1 ), \'_\', j.primary_locale, \'.\', SUBSTRING_INDEX(ss.setting_value,\'.\',-1)) WHERE ss.setting_name = \'coverImage\' AND ss.locale = \'\' AND s.submission_id = ss.submission_id AND j.journal_id = s.context_id'); // Update cover image alt texts in the submission_settings table $articleDao->update('UPDATE submission_settings ss, submissions s, journals j SET ss.locale = j.primary_locale WHERE ss.setting_name = \'coverImageAltText\' AND ss.locale = \'\' AND s.submission_id = ss.submission_id AND j.journal_id = s.context_id'); break; case 'postgres': // Update cover image names in the submission_settings table $articleDao->update('UPDATE submission_settings SET locale = j.primary_locale, setting_value = REGEXP_REPLACE(submission_settings.setting_value, \'[\\.]\', CONCAT(\'_\', j.primary_locale, \'.\')) FROM submissions s, journals j WHERE submission_settings.setting_name = \'coverImage\' AND submission_settings.locale = \'\' AND s.submission_id = submission_settings.submission_id AND j.journal_id = s.context_id'); // Update cover image alt texts in the submission_settings table $articleDao->update('UPDATE submission_settings SET locale = j.primary_locale FROM submissions s, journals j WHERE submission_settings.setting_name = \'coverImageAltText\' AND submission_settings.locale = \'\' AND s.submission_id = submission_settings.submission_id AND j.journal_id = s.context_id'); break; default: fatalError('Unknown database type!'); } $articleDao->flushCache(); return true; }
/** * Parse out the cover and store it in the object. * @param $node DOMElement * @param $object Issue */ function parseCover($node, $object) { $deployment = $this->getDeployment(); $context = $deployment->getContext(); $locale = $node->getAttribute('locale'); if (empty($locale)) { $locale = $context->getPrimaryLocale(); } for ($n = $node->firstChild; $n !== null; $n = $n->nextSibling) { if (is_a($n, 'DOMElement')) { switch ($n->tagName) { case 'cover_image': $object->setCoverImage($n->textContent, $locale); break; case 'cover_image_alt_text': $object->setCoverImageAltText($n->textContent, $locale); break; case 'embed': import('classes.file.PublicFileManager'); $publicFileManager = new PublicFileManager(); $filePath = $publicFileManager->getContextFilesPath(ASSOC_TYPE_JOURNAL, $context->getId()) . '/' . $object->getCoverImage($locale); file_put_contents($filePath, base64_decode($n->textContent)); break; } } } }
/** * Constructor. * Initialize template engine and assign basic template variables. * @param $request PKPRequest */ function __construct($request) { parent::__construct($request); AppLocale::requireComponents(LOCALE_COMPONENT_APP_COMMON); if (!defined('SESSION_DISABLE_INIT')) { /** * Kludge to make sure no code that tries to connect to * the database is executed (e.g., when loading * installer pages). */ $context = $request->getContext(); $site = $request->getSite(); $publicFileManager = new PublicFileManager(); $siteFilesDir = $request->getBaseUrl() . '/' . $publicFileManager->getSiteFilesPath(); $this->assign('sitePublicFilesDir', $siteFilesDir); $this->assign('publicFilesDir', $siteFilesDir); // May be overridden by press $siteStyleFilename = $publicFileManager->getSiteFilesPath() . '/' . $site->getSiteStyleFilename(); if (file_exists($siteStyleFilename)) { $this->addStyleSheet('siteStylesheet', $request->getBaseUrl() . '/' . $siteStyleFilename, array('priority' => STYLE_SEQUENCE_LAST)); } // Pass app-specific details to template $this->assign(array('brandImage' => 'templates/images/omp_brand.png', 'packageKey' => 'common.openMonographPress', 'pkpLink' => 'http://pkp.sfu.ca/omp')); // Get a count of unread tasks. if ($user = $request->getUser()) { $notificationDao = DAORegistry::getDAO('NotificationDAO'); // Exclude certain tasks, defined in the notifications grid handler import('lib.pkp.controllers.grid.notifications.TaskNotificationsGridHandler'); $this->assign('unreadNotificationCount', $notificationDao->getNotificationCount(false, $user->getId(), null, NOTIFICATION_LEVEL_TASK)); } if (isset($context)) { $this->assign('currentPress', $context); $this->assign('siteTitle', $context->getLocalizedName()); $this->assign('publicFilesDir', $request->getBaseUrl() . '/' . $publicFileManager->getContextFilesPath($context->getAssocType(), $context->getId())); $this->assign('primaryLocale', $context->getPrimaryLocale()); $this->assign('supportedLocales', $context->getSupportedLocaleNames()); // Assign page header $this->assign('displayPageHeaderTitle', $context->getPageHeaderTitle()); $this->assign('displayPageHeaderLogo', $context->getPageHeaderLogo()); $this->assign('numPageLinks', $context->getSetting('numPageLinks')); $this->assign('itemsPerPage', $context->getSetting('itemsPerPage')); $this->assign('enableAnnouncements', $context->getSetting('enableAnnouncements')); $this->assign('disableUserReg', $context->getSetting('disableUserReg')); // Assign stylesheets and footer $contextStyleSheet = $context->getSetting('styleSheet'); if ($contextStyleSheet) { $this->addStyleSheet('contextStylesheet', $request->getBaseUrl() . '/' . $publicFileManager->getContextFilesPath(ASSOC_TYPE_PRESS, $context->getId()) . '/' . $contextStyleSheet['uploadName'], array('priority' => STYLE_SEQUENCE_LAST)); } // Get a link to the settings page for the current context. // This allows us to reduce template duplication by using this // variable in templates/common/header.tpl, instead of // reproducing a lot of OMP/OJS-specific logic there. $dispatcher = $request->getDispatcher(); $this->assign('contextSettingsUrl', $dispatcher->url($request, ROUTE_PAGE, null, 'management', 'settings', 'press')); $this->assign('pageFooter', $context->getLocalizedSetting('pageFooter')); } else { // Add the site-wide logo, if set for this locale or the primary locale $this->assign('displayPageHeaderTitle', $site->getLocalizedPageHeaderTitle()); $this->assign('displayPageHeaderLogo', $site->getLocalizedSetting('pageHeaderTitleImage')); $this->assign('siteTitle', $site->getLocalizedTitle()); $this->assign('primaryLocale', $site->getPrimaryLocale()); $this->assign('supportedLocales', $site->getSupportedLocaleNames()); // Check if registration is open for any contexts $contextDao = Application::getContextDAO(); $contexts = $contextDao->getAll(true)->toArray(); $contextsForRegistration = array(); foreach ($contexts as $context) { if (!$context->getSetting('disableUserReg')) { $contextsForRegistration[] = $context; } } $this->assign('contexts', $contextsForRegistration); $this->assign('disableUserReg', empty($contextsForRegistration)); } } }