Skip to content

Commit

Permalink
Merge pull request #4146 from jyhein/f699
Browse files Browse the repository at this point in the history
pkp/pkp-lib#699 Show locale in url in multilingual contexts
  • Loading branch information
bozana authored Apr 25, 2024
2 parents 42d6fcc + d8d2f1f commit 072fea3
Show file tree
Hide file tree
Showing 23 changed files with 52 additions and 35 deletions.
2 changes: 1 addition & 1 deletion cypress/tests/integration/Pubmed.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe('Pubmed tests', function () {
.then((win) => {
const csrfToken = win.pkp.currentUser.csrfToken;
cy.request({
url: '/index.php/publicknowledge/management/importexport/plugin/PubMedExportPlugin/exportSubmissions',
url: '/index.php/publicknowledge/en/management/importexport/plugin/PubMedExportPlugin/exportSubmissions',
method: 'POST',
headers: {
'X-Csrf-Token': csrfToken
Expand Down
4 changes: 2 additions & 2 deletions cypress/tests/integration/Z_ArticleViewDCMetadata.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ describe('Article View Metadata - DC Plugin', function() {
return cy.submitSubmissionWithApi(submission.id, this.csrfToken);
})
.then(xhr => {
cy.visit('/index.php/publicknowledge/workflow/index/' + submission.id + '/1');
cy.visit('/index.php/publicknowledge/en/workflow/index/' + submission.id + '/1');
});


Expand Down Expand Up @@ -481,7 +481,7 @@ describe('Article View Metadata - DC Plugin', function() {
});

it('Tests if Header DC Metadata are present and consistent', function() {
cy.visit('/index.php/publicknowledge/article/view/' + submission.urlPath);
cy.visit('/index.php/publicknowledge/en/article/view/' + submission.urlPath);

cy.get('meta[name^="DC."]').each((item, index, list) => {
cy.wrap(item)
Expand Down
1 change: 0 additions & 1 deletion pages/user/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
//
case 'index':
case 'subscriptions':
case 'setLocale':
case 'authorizationDenied':
case 'purchaseSubscription':
case 'payPurchaseSubscription':
Expand Down
6 changes: 2 additions & 4 deletions plugins/blocks/languageToggle/LanguageToggleBlockPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,8 @@ public function getContents($templateMgr, $request = null)
$templateMgr->assign('languageToggleNoUser', true);
}

if (!empty($locales)) {
$templateMgr->assign('enableLanguageToggle', true);
$templateMgr->assign('languageToggleLocales', $locales);
}
$templateMgr->assign('enableLanguageToggle', count($locales) > 1);
$templateMgr->assign('languageToggleLocales', $locales);

return parent::getContents($templateMgr, $request);
}
Expand Down
2 changes: 1 addition & 1 deletion plugins/blocks/languageToggle/templates/block.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<ul>
{foreach from=$languageToggleLocales item=localeName key=localeKey}
<li class="locale_{$localeKey|escape}{if $localeKey == $currentLocale} current{/if}" lang="{$localeKey|replace:"_":"-"}">
<a href="{url router=\PKP\core\PKPApplication::ROUTE_PAGE page="user" op="setLocale" path=$localeKey source=$smarty.server.REQUEST_URI}">
<a href="{url router=\PKP\core\PKPApplication::ROUTE_PAGE page="user" op="setLocale" path=$localeKey}">
{$localeName}
</a>
</li>
Expand Down
2 changes: 1 addition & 1 deletion plugins/generic/citationStyleLanguage
2 changes: 1 addition & 1 deletion plugins/generic/crossref
6 changes: 3 additions & 3 deletions plugins/generic/datacite/DataciteExportPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -410,13 +410,13 @@ public function _getObjectUrl($request, $context, $object)
$url = null;
switch (true) {
case $object instanceof Issue:
$url = $dispatcher->url($request, PKPApplication::ROUTE_PAGE, $context->getPath(), 'issue', 'view', $object->getBestIssueId(), null, null, true);
$url = $dispatcher->url($request, PKPApplication::ROUTE_PAGE, $context->getPath(), 'issue', 'view', $object->getBestIssueId(), null, null, true, '');
break;
case $object instanceof Submission:
$url = $dispatcher->url($request, PKPApplication::ROUTE_PAGE, $context->getPath(), 'article', 'view', $object->getBestId(), null, null, true);
$url = $dispatcher->url($request, PKPApplication::ROUTE_PAGE, $context->getPath(), 'article', 'view', $object->getBestId(), null, null, true, '');
break;
case $object instanceof Galley:
$url = $dispatcher->url($request, PKPApplication::ROUTE_PAGE, $context->getPath(), 'article', 'view', [$article->getBestId(), $object->getBestGalleyId()], null, null, true);
$url = $dispatcher->url($request, PKPApplication::ROUTE_PAGE, $context->getPath(), 'article', 'view', [$article->getBestId(), $object->getBestGalleyId()], null, null, true, '');
break;
}
if ($this->isTestMode($context)) {
Expand Down
3 changes: 2 additions & 1 deletion plugins/generic/datacite/filter/DataciteXmlFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -821,7 +821,8 @@ public function createRelatedItemsNode($doc, $issue, $article, $publication, $pu
$contextUrl = $request->getDispatcher()->url(
$request,
Application::ROUTE_PAGE,
$context->getPath()
$context->getPath(),
urlLocaleForPage: ''
);
$relatedItemIdentifierNode = $doc->createElementNS($deployment->getNamespace(), 'relatedItemIdentifier', $contextUrl);
$relatedItemIdentifierNode->setAttribute('relatedItemIdentifierType', DATACITE_IDTYPE_URL);
Expand Down
5 changes: 3 additions & 2 deletions plugins/generic/dublinCoreMeta/DublinCoreMetaPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

use APP\facades\Repo;
use APP\template\TemplateManager;
use PKP\core\PKPApplication;
use PKP\plugins\GenericPlugin;
use PKP\plugins\Hook;

Expand Down Expand Up @@ -143,7 +144,7 @@ public function articleView($hookName, $args)
}
}

$templateMgr->addHeader('dublinCoreUri', '<meta name="DC.Identifier.URI" content="' . $request->url(null, 'article', 'view', [$articleBestId]) . '"/>');
$templateMgr->addHeader('dublinCoreUri', '<meta name="DC.Identifier.URI" content="' . $request->getDispatcher()->url($request, PKPApplication::ROUTE_PAGE, null, 'article', 'view', [$articleBestId], urlLocaleForPage: '') . '"/>');

$templateMgr->addHeader('dublinCoreLanguage', '<meta name="DC.Language" scheme="ISO639-1" content="' . substr($publicationLocale, 0, 2) . '"/>');

Expand All @@ -166,7 +167,7 @@ public function articleView($hookName, $args)
$templateMgr->addHeader('dublinCoreVolume', '<meta name="DC.Source.Volume" content="' . htmlspecialchars($issue->getVolume()) . '"/>');
}
}
$templateMgr->addHeader('dublinCoreSourceUri', '<meta name="DC.Source.URI" content="' . $request->url($journal->getPath()) . '"/>');
$templateMgr->addHeader('dublinCoreSourceUri', '<meta name="DC.Source.URI" content="' . $request->getDispatcher()->url($request, PKPApplication::ROUTE_PAGE, null, $journal->getPath(), urlLocaleForPage: '') . '"/>');

if ($subjects = $publication->getData('subjects')) {
foreach ($subjects as $locale => $localeSubjects) {
Expand Down
2 changes: 1 addition & 1 deletion plugins/generic/googleScholar
5 changes: 2 additions & 3 deletions plugins/generic/recommendByAuthor/templates/articleFooter.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,10 @@
{foreach from=$article->getCurrentPublication()->getData('authors') item=author}
{$author->getFullName()|escape},
{/foreach}
<a href="{url journal=$journal->getPath() page="article" op="view" path=$submission->g
etBestId()}">
<a href="{url router=\PKP\core\PKPApplication::ROUTE_PAGE journal=$journal->getPath() page="article" op="view" path=$submission->getBestId() urlLocaleForPage=""}">
{$publication->getLocalizedFullTitle(null, 'html')|strip_unsafe_html}
</a>,
<a href="{url journal=$journal->getPath() page="issue" op="view" path=$issue->getBestIssueId()}">
<a href="{url router=\PKP\core\PKPApplication::ROUTE_PAGE journal=$journal->getPath() page="issue" op="view" path=$issue->getBestIssueId() urlLocaleForPage=""}">
{$journal->getLocalizedName()|escape}: {$issue->getIssueIdentification()|escape}
</a>
</li>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use APP\submission\Collector;
use APP\submission\Submission;
use APP\template\TemplateManager;
use PKP\core\PKPApplication;
use PKP\plugins\GenericPlugin;
use PKP\plugins\Hook;

Expand Down Expand Up @@ -100,10 +101,10 @@ private function buildTemplate(): ?string
->getMany();

$nextPage = $rangeInfo->getPage() * $rangeInfo->getCount() < $submissionCount
? $request->url(path: $submissionId, params: ['articlesBySimilarityPage' => $rangeInfo->getPage() + 1])
? $request->getDispatcher()->url($request, PKPApplication::ROUTE_PAGE, path: $submissionId, params: ['articlesBySimilarityPage' => $rangeInfo->getPage() + 1], urlLocaleForPage: '')
: null;
$previousPage = $rangeInfo->getPage() > 1
? $request->url(path: $submissionId, params: ['articlesBySimilarityPage' => $rangeInfo->getPage() - 1])
? $request->getDispatcher()->url($request, PKPApplication::ROUTE_PAGE, path: $submissionId, params: ['articlesBySimilarityPage' => $rangeInfo->getPage() - 1], urlLocaleForPage: '')
: null;

$templateManager->assign('articlesBySimilarity', (object) [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
{foreach from=$publication->getData('authors') item=author}
{$author->getFullName()|escape},
{/foreach}
<a href="{url journal=$currentContext->getPath() page="article" op="view" path=$submission->getBestId()}">
<a href="{url router=\PKP\core\PKPApplication::ROUTE_PAGE journal=$currentContext->getPath() page="article" op="view" path=$submission->getBestId() urlLocaleForPage=""}">
{$publication->getLocalizedFullTitle(null, 'html')|strip_unsafe_html}
</a>
{if $issue},
<a href="{url journal=$currentContext->getPath() page="issue" op="view" path=$issue->getBestIssueId()}">
<a href="{url router=\PKP\core\PKPApplication::ROUTE_PAGE journal=$currentContext->getPath() page="issue" op="view" path=$issue->getBestIssueId() urlLocaleForPage=""}">
{$currentContext->getLocalizedName()|escape}: {$issue->getIssueIdentification()|escape}
</a>
{/if}
Expand Down
2 changes: 1 addition & 1 deletion plugins/importexport/doaj/filter/DOAJJsonFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public function &process(&$pubObject)
$request = Application::get()->getRequest();
$article['bibjson']['link'] = [];
$article['bibjson']['link'][] = [
'url' => $request->url($context->getPath(), 'article', 'view', $pubObject->getId()),
'url' => $request->getDispatcher()->url($request, Application::ROUTE_PAGE, $context->getPath(), 'article', 'view', $pubObject->getId(), urlLocaleForPage: ''),
'type' => 'fulltext',
'content_type' => 'html'
];
Expand Down
2 changes: 1 addition & 1 deletion plugins/importexport/doaj/filter/DOAJXmlFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ public function &process(&$pubObjects)
}
// FullText URL
$request = Application::get()->getRequest();
$recordNode->appendChild($node = $doc->createElement('fullTextUrl', htmlspecialchars($request->url(null, 'article', 'view', $pubObject->getId()), ENT_COMPAT, 'UTF-8')));
$recordNode->appendChild($node = $doc->createElement('fullTextUrl', htmlspecialchars($request->getDispatcher()->url($request, Application::ROUTE_PAGE, null, 'article', 'view', $pubObject->getId(), urlLocaleForPage: ''), ENT_COMPAT, 'UTF-8')));
$node->setAttribute('format', 'html');
// Keywords
$supportedLocales = $context->getSupportedFormLocales();
Expand Down
6 changes: 5 additions & 1 deletion plugins/importexport/pubmed/PubMedExportPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,11 @@ public function exportSubmissions($submissionIds, $context, $user)
return $a->level == LIBXML_ERR_ERROR || $a->level == LIBXML_ERR_FATAL;
});
if (!empty($errors)) {
$this->displayXMLValidationErrors($errors, $xml);
try {
$this->displayXMLValidationErrors($errors, $xml);
} catch (Exception $e) {
error_log($e->getMessage());
}
}
return $xml;
}
Expand Down
5 changes: 3 additions & 2 deletions plugins/metadata/dc11/filter/Dc11SchemaArticleAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
use APP\oai\ojs\OAIDAO;
use APP\plugins\PubIdPlugin;
use APP\submission\Submission;
use PKP\core\PKPApplication;
use PKP\db\DAORegistry;
use PKP\facades\Locale;
use PKP\metadata\MetadataDataObjectAdapter;
Expand Down Expand Up @@ -151,7 +152,7 @@ public function &extractMetadataFromDataObject(&$article)
$request = Application::get()->getRequest();
$includeUrls = $journal->getSetting('publishingMode') != Journal::PUBLISHING_MODE_NONE || $issueAction->subscribedUser($request->getUser(), $journal, null, $article->getId());
if ($includeUrls) {
$dc11Description->addStatement('dc:identifier', $request->url($journal->getPath(), 'article', 'view', [$article->getBestId()]));
$dc11Description->addStatement('dc:identifier', $request->getDispatcher()->url($request, PKPApplication::ROUTE_PAGE, null, 'article', 'view', [$article->getBestId()], urlLocaleForPage: ''));
}

// Source (journal title, issue id and pages)
Expand Down Expand Up @@ -184,7 +185,7 @@ public function &extractMetadataFromDataObject(&$article)
// full text URLs
if ($includeUrls) {
foreach ($galleys as $galley) {
$relation = $request->url($journal->getPath(), 'article', 'view', [$article->getBestId(), $galley->getBestGalleyId()]);
$relation = $request->getDispatcher()->url($request, PKPApplication::ROUTE_PAGE, null, 'article', 'view', [$article->getBestId(), $galley->getBestGalleyId()], urlLocaleForPage: '');
$dc11Description->addStatement('dc:relation', $relation);
}
}
Expand Down
15 changes: 14 additions & 1 deletion plugins/oaiMetadataFormats/dc/tests/OAIMetadataFormat_DCTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
use Illuminate\Support\LazyCollection;
use PHPUnit\Framework\MockObject\MockObject;
use PKP\author\Repository as AuthorRepository;
use PKP\core\Dispatcher;
use PKP\core\Registry;
use PKP\db\DAORegistry;
use PKP\doi\Doi;
Expand Down Expand Up @@ -213,13 +214,25 @@ public function testToXml()
->method('url')
->will($this->returnCallback(fn ($request, $newContext = null, $handler = null, $op = null, $path = null) => $handler . '-' . $op . '-' . implode('-', $path)));

// Dispatcher
/** @var Dispatcher|MockObject */
$dispatcher = $this->getMockBuilder(Dispatcher::class)
->onlyMethods(['url'])
->getMock();
$dispatcher->expects($this->any())
->method('url')
->will($this->returnCallback(fn ($request, $shortcut, $newContext = null, $handler = null, $op = null, $path = null) => $handler . '-' . $op . '-' . implode('-', $path)));

// Request
$requestMock = $this->getMockBuilder(Request::class)
->onlyMethods(['getRouter'])
->onlyMethods(['getRouter', 'getDispatcher'])
->getMock();
$requestMock->expects($this->any())
->method('getRouter')
->will($this->returnValue($router));
$requestMock->expects($this->any())
->method('getDispatcher')
->will($this->returnValue($dispatcher));
Registry::set('request', $requestMock);

//
Expand Down
2 changes: 1 addition & 1 deletion plugins/oaiMetadataFormats/marc/templates/record.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
</varfield>
{/foreach}
<varfield id="856" i1="4" i2="0">
<subfield label="u">{url journal=$journal->getPath() page="article" op="view" path=$article->getBestId()|escape}</subfield>
<subfield label="u">{url router=\PKP\core\PKPApplication::ROUTE_PAGE journal=$journal->getPath() page="article" op="view" path=$article->getBestId()|escape urlLocaleForPage=""}</subfield>
</varfield>

<varfield id="786" i1="0" i2=" ">
Expand Down
2 changes: 1 addition & 1 deletion plugins/oaiMetadataFormats/marcxml/templates/record.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
</datafield>
{/foreach}
<datafield tag="856" ind1="4" ind2="0">
<subfield code="u">{url journal=$journal->getPath() page="article" op="view" path=$article->getBestId()|escape}</subfield>
<subfield code="u">{url router=\PKP\core\PKPApplication::ROUTE_PAGE journal=$journal->getPath() page="article" op="view" path=$article->getBestId()|escape urlLocaleForPage=""}</subfield>
</datafield>

<datafield tag="786" ind1="0" ind2=" ">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public function toXml($record, $format = null)

$issueAction = new IssueAction();
$request = Application::get()->getRequest();
$url = $request->url($journal->getPath(), 'article', 'view', [$article->getBestId()]);
$url = $request->getDispatcher()->url($request, Application::ROUTE_PAGE, $journal->getPath(), 'article', 'view', [$article->getBestId()], urlLocaleForPage: '');
$includeUrls = $journal->getSetting('publishingMode') != \APP\journal\Journal::PUBLISHING_MODE_NONE || $issueAction->subscribedUser($request->getUser(), $journal, null, $article->getId());
$response = "<rfc1807\n" .
"\txmlns=\"http://info.internet.isi.edu:80/in-notes/rfc/files/rfc1807.txt\"\n" .
Expand Down

0 comments on commit 072fea3

Please sign in to comment.