Hello,
I’m confused with obtaining download URL for paper pdf. Now, I use following code, but it don’t produce correct one
foreach ($articleFileDao->getBySubmissionId($article->getId())->toArray() as $files) {
$url = 'http://' . $_SERVER['HTTP_HOST'] . pathinfo($_SERVER['SCRIPT_NAME'], PATHINFO_DIRNAME);
$url .= "/index.php/$jpath/article/view/" . $article->getId() . '/' . $files->getSubmissionId();
XMLCustomWriter::createChildWithText($doc, $lang_version, 'pdfFileUrl', $url, true);
}
for more details, please look at github
$sectionDao =& DAORegistry::getDAO('SectionDAO');
$publishedArticleDao =& DAORegistry::getDAO('PublishedArticleDAO');
$articleFileDao =& DAORegistry::getDAO('ArticleGalleyDAO');
$submissionKeywordDao = DAORegistry::getDAO('SubmissionKeywordDAO');
$num_articles = 0;
foreach ($sectionDao->getByIssueId($issue->getId()) as $section) {
foreach ($publishedArticleDao->getPublishedArticlesBySectionId($section->getId(), $issue->getId()) as $article) {
if (!$article->getStartingPage()) continue;
$locales = array_keys($article->_data['title']);
$article_elem = XMLCustomWriter::createChildWithText($doc, $issue_elem, 'article', '', true);
XMLCustomWriter::createChildWithText($doc, $article_elem, 'type', 'ORIGINAL_ARTICLE');
foreach ($locales as $loc) {
$lc = explode('_', $loc);
$lang_version = XMLCustomWriter::createChildWithText($doc, $article_elem, 'languageVersion', '', true);
XMLCustomWriter::setAttribute($lang_version, 'language', $lc[0]);
XMLCustomWriter::createChildWithText($doc, $lang_version, 'title', $article->getLocalizedTitle($loc), true);
XMLCustomWriter::createChildWithText($doc, $lang_version, 'abstract', strip_tags($article->getLocalizedData('abstract', $loc)), true);
Hi @a-vodka ,
Because OJS needs to operate with disable_path_info
set to either On
or Off
, which results in URLs being generated differently, it’s best to use the built-in URL generation tools. To do this, you can call e.g.:
$url = $request->url(null, 'article', 'view', $article->getBestArticleId());
Regards,
Alec Smecher
Public Knowledge Project Team
a-vodka
January 7, 2019, 10:39pm
#3
Dear @asmecher
Thank you for your reply.
This code gives url to paper page, not for pdf file. Is it possible to get link to pdf file?
Hi @a-vodka ,
There may be none, one, or many PDF files uploaded, so you’ll need to try to find one and identify the best candidate. See e.g. this snippet:
$i=0;
$dao = DAORegistry::getDAO('SubmissionKeywordDAO');
$keywords = $dao->getKeywords($article->getId(), array(AppLocale::getLocale()));
foreach ($keywords as $locale => $localeKeywords) {
foreach ($localeKeywords as $keyword) {
$templateMgr->addHeader('googleScholarKeyword' . $i++, '<meta name="citation_keywords" xml:lang="' . htmlspecialchars(substr($locale, 0, 2)) . '" content="' . htmlspecialchars($keyword) . '"/>');
}
}
$i=$j=0;
if (is_a($article, 'PublishedArticle')) foreach ($article->getGalleys() as $galley) {
if (is_a($galley->getFile(), 'SupplementaryFile')) continue;
if ($galley->getFileType()=='application/pdf') {
$templateMgr->addHeader('googleScholarPdfUrl' . $i++, '<meta name="citation_pdf_url" content="' . $request->url(null, 'article', 'download', array($article->getBestArticleId(), $galley->getBestGalleyId())) . '"/>');
} elseif ($galley->getFileType()=='text/html') {
$templateMgr->addHeader('googleScholarHtmlUrl' . $i++, '<meta name="citation_fulltext_html_url" content="' . $request->url(null, 'article', 'view', array($article->getBestArticleId(), $galley->getBestGalleyId())) . '"/>');
}
}
return false;
Regards,
Alec Smecher
Public Knowledge Project Team