Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
X
xml2html-pkp-plugin
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
FNSO
FAIREST
xml2html-pkp-plugin
Commits
01b34d48
Commit
01b34d48
authored
Jul 3, 2023
by
Jerome Chauveau
Browse files
Options
Downloads
Patches
Plain Diff
ajustements divers pour fonctionnement du plugin sur les galleys / publications
parent
6f4e9be9
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
ArticleImageDataHandler.inc.php
+10
-58
10 additions, 58 deletions
ArticleImageDataHandler.inc.php
BookImageDataHandler.inc.php
+51
-54
51 additions, 54 deletions
BookImageDataHandler.inc.php
XML2HTMLPlugin.php
+9
-54
9 additions, 54 deletions
XML2HTMLPlugin.php
with
70 additions
and
166 deletions
ArticleImageDataHandler.inc.php
+
10
−
58
View file @
01b34d48
...
...
@@ -8,70 +8,22 @@ class ArticleImageDataHandler extends ArticleHandler
/**
* @param array $args
* @param Request $request
* @return mixed
*/
public
function
image
(
array
$args
,
Request
$request
)
{
$fileId
=
$args
[
1
];
import
(
'lib.pkp.classes.submission.SubmissionFile'
);
$dependentFilesIterator
=
Services
::
get
(
'submissionFile'
)
->
getMany
([
'assocTypes'
=>
[
ASSOC_TYPE_SUBMISSION_FILE
],
'submissionIds'
=>
[
$this
->
article
->
getId
()],
'fileStages'
=>
[
SUBMISSION_FILE_DEPENDENT
],
'includeDependentFiles'
=>
true
,
]);
$submissionFile
=
null
;
foreach
(
$dependentFilesIterator
as
$dependentFile
)
{
if
(
$fileId
==
$dependentFile
->
getData
(
'fileId'
))
{
$submissionFile
=
$dependentFile
;
break
;
}
}
// Download file if exists
if
(
!
Services
::
get
(
'file'
)
->
fs
->
has
(
$submissionFile
->
getData
(
'path'
)))
{
$request
->
getDispatcher
()
->
handle404
();
}
$filename
=
Services
::
get
(
'file'
)
->
formatFilename
(
$submissionFile
->
getData
(
'path'
),
$submissionFile
->
getLocalizedData
(
'name'
));
return
Services
::
get
(
'file'
)
->
download
(
$submissionFile
->
getData
(
'path'
),
$filename
);
}
/**
* Image from zip archive submission file
* Image from zip archive galley file
* @param array $args
* @param Request $request
* @return mixed
*/
public
function
zimage
(
array
$args
,
Request
$request
)
{
import
(
'lib.pkp.classes.submission.SubmissionFile'
);
$imgName
=
$args
[
1
];
$dependentFilesIterator
=
Services
::
get
(
'submissionFile'
)
->
getMany
([
'submissionIds'
=>
[
$this
->
article
->
getId
()],
'fileStages'
=>
[
SUBMISSION_FILE_SUBMISSION
],
]);
$submissionFile
=
null
;
$result
=
iterator_to_array
(
$dependentFilesIterator
);
if
(
sizeof
(
$result
)
!=
1
)
{
$request
->
getDispatcher
()
->
handle404
();
}
else
{
$submissionFile
=
$result
[
0
];
$galleyId
=
$args
[
1
];
$imgName
=
$args
[
2
];
$galley
=
Services
::
get
(
'galley'
)
->
get
(
$galleyId
);
$file
=
$galley
->
getFile
();
$filename
=
Services
::
get
(
'file'
)
->
formatFilename
(
$
submissionF
ile
->
getData
(
'path'
),
$
submissionF
ile
->
getLocalizedData
(
'path'
));
->
formatFilename
(
$
f
ile
->
getData
(
'path'
),
$
f
ile
->
getLocalizedData
(
'path'
));
$pathInfo
=
pathinfo
(
$filename
);
$imagePath
=
$pathInfo
[
'dirname'
]
.
DIRECTORY_SEPARATOR
.
$pathInfo
[
'filename'
]
.
DIRECTORY_SEPARATOR
.
$imgName
;
return
Services
::
get
(
'file'
)
->
download
(
$imagePath
,
$imgName
);
}
}
...
...
This diff is collapsed.
Click to expand it.
BookImageDataHandler.inc.php
+
51
−
54
View file @
01b34d48
...
...
@@ -7,41 +7,41 @@ class BookImageDataHandler extends CatalogBookHandler
{
/**
* @param array $args
* @param Request $request
* @return mixed
*/
public
function
image
(
array
$args
,
Request
$request
)
{
$fileId
=
$args
[
1
];
$submission
=
$this
->
getAuthorizedContextObject
(
ASSOC_TYPE_SUBMISSION
);
import
(
'lib.pkp.classes.submission.SubmissionFile'
);
$dependentFilesIterator
=
Services
::
get
(
'submissionFile'
)
->
getMany
([
'assocTypes'
=>
[
ASSOC_TYPE_SUBMISSION_FILE
],
'submissionIds'
=>
[
$submission
->
getId
()],
'fileStages'
=>
[
SUBMISSION_FILE_DEPENDENT
],
'includeDependentFiles'
=>
true
,
]);
$submissionFile
=
null
;
foreach
(
$dependentFilesIterator
as
$dependentFile
)
{
if
(
$fileId
==
$dependentFile
->
getData
(
'fileId'
))
{
$submissionFile
=
$dependentFile
;
break
;
}
}
// Download file if exists
if
(
!
Services
::
get
(
'file'
)
->
fs
->
has
(
$submissionFile
->
getData
(
'path'
)))
{
$request
->
getDispatcher
()
->
handle404
();
}
$filename
=
Services
::
get
(
'file'
)
->
formatFilename
(
$submissionFile
->
getData
(
'path'
),
$submissionFile
->
getLocalizedData
(
'name'
));
return
Services
::
get
(
'file'
)
->
download
(
$submissionFile
->
getData
(
'path'
),
$filename
);
}
//
/**
//
* @param array $args
//
* @param Request $request
//
* @return mixed
//
*/
//
public function image(array $args, Request $request)
//
{
//
$fileId = $args[1];
//
$submission = $this->getAuthorizedContextObject(ASSOC_TYPE_SUBMISSION);
//
import('lib.pkp.classes.submission.SubmissionFile');
//
$dependentFilesIterator = Services::get('submissionFile')->getMany([
//
'assocTypes' => [ASSOC_TYPE_SUBMISSION_FILE],
//
'submissionIds' => [$submission->getId()],
//
'fileStages' => [SUBMISSION_FILE_DEPENDENT],
//
'includeDependentFiles' => true,
//
]);
//
//
$submissionFile = null;
//
foreach ($dependentFilesIterator as $dependentFile) {
//
if ($fileId == $dependentFile->getData('fileId')) {
//
$submissionFile = $dependentFile;
//
break;
//
}
//
}
//
//
// Download file if exists
//
if (!Services::get('file')->fs->has($submissionFile->getData('path'))) {
//
$request->getDispatcher()->handle404();
//
}
//
//
$filename = Services::get('file')
//
->formatFilename($submissionFile->getData('path'), $submissionFile->getLocalizedData('name'));
//
//
return Services::get('file')->download($submissionFile->getData('path'), $filename);
//
}
/**
* Image from zip archive submission file
...
...
@@ -51,31 +51,28 @@ class BookImageDataHandler extends CatalogBookHandler
*/
public
function
zimage
(
array
$args
,
Request
$request
)
{
import
(
'lib.pkp.classes.submission.SubmissionFile'
);
$imgName
=
$args
[
1
];
$pubId
=
$args
[
1
];
$imgName
=
$args
[
2
];
$submission
=
$this
->
getAuthorizedContextObject
(
ASSOC_TYPE_SUBMISSION
);
$dependentFilesIterator
=
Services
::
get
(
'submissionFile'
)
->
getMany
([
$pubFormatFiles
=
Services
::
get
(
'submissionFile'
)
->
getMany
([
'submissionIds'
=>
[
$submission
->
getId
()],
'fileStages'
=>
[
SUBMISSION_FIL
E_
S
UB
MISSION
],
'assocTypes'
=>
[
ASSOC_TYP
E_
P
UB
LICATION_FORMAT
],
]);
$submissionFile
=
null
;
$result
=
iterator_to_array
(
$dependentFilesIterator
);
if
(
sizeof
(
$result
)
!=
1
)
{
$request
->
getDispatcher
()
->
handle404
();
$publicationFile
=
NULL
;
foreach
(
$pubFormatFiles
as
$file
){
if
(
$file
->
getData
(
'assocId'
)
==
$pubId
)
{
$publicationFile
=
$file
;
}
}
else
{
$submissionFile
=
$result
[
0
];
$filename
=
Services
::
get
(
'file'
)
->
formatFilename
(
$
s
ub
miss
ionFile
->
getData
(
'path'
),
$
s
ub
miss
ionFile
->
getLocalizedData
(
'path'
));
->
formatFilename
(
$
p
ub
licat
ionFile
->
getData
(
'path'
),
$
p
ub
licat
ionFile
->
getLocalizedData
(
'path'
));
$pathInfo
=
pathinfo
(
$filename
);
$imagePath
=
$pathInfo
[
'dirname'
]
.
DIRECTORY_SEPARATOR
.
$pathInfo
[
'filename'
]
.
DIRECTORY_SEPARATOR
.
$imgName
;
return
Services
::
get
(
'file'
)
->
download
(
$imagePath
,
$imgName
);
}
}
}
This diff is collapsed.
Click to expand it.
XML2HTMLPlugin.php
+
9
−
54
View file @
01b34d48
...
...
@@ -43,7 +43,7 @@ class XML2HTMLPlugin extends GenericPlugin
//handle only on zip galleys - supposed to be an xml archive (source + images)
$zipMode
=
$galley
&&
$galley
->
getFileType
()
===
'application/zip'
;
if
(
$zipMode
)
{
$this
->
archiveView
(
$galley
->
getFile
()
->
getData
(
'path'
),
$submission
->
getId
(),
'article'
);
$this
->
archiveView
(
$galley
->
getFile
()
->
getData
(
'path'
),
$submission
->
getId
(),
$galley
->
getId
(),
'article'
);
return
true
;
}
else
return
false
;
}
...
...
@@ -52,23 +52,25 @@ class XML2HTMLPlugin extends GenericPlugin
{
$submission
=
&
$params
[
1
];
$galley
=&
$params
[
2
];
$submissionFile
=&
$params
[
3
];
$zipMode
=
$submissionFile
->
getData
(
'mimetype'
)
===
"application/zip"
;
if
(
$zipMode
)
{
$this
->
archiveView
(
$submissionFile
->
getData
(
'path'
),
$submission
->
getId
(),
'catalog'
);
$this
->
archiveView
(
$submissionFile
->
getData
(
'path'
),
$submission
->
getId
(),
$galley
->
getId
(),
'catalog'
);
return
true
;
}
else
return
false
;
}
private
function
archiveView
(
string
$filePath
,
int
$submissionId
,
string
$op
)
private
function
archiveView
(
string
$filePath
,
int
$submissionId
,
int
$galleyId
,
string
$op
)
{
$templateMgr
=
TemplateManager
::
getManager
(
$this
->
getRequest
());
$xmlFilePath
=
XML2HTMLPlugin
::
unzipXMLArchive
(
$filePath
);
$html
=
$this
->
resolveZipImagePaths
(
XML2HTMLPlugin
::
transform
(
$xmlFilePath
),
$submissionId
,
$galleyId
,
$xmlFilePath
,
$this
->
getRequest
(),
$op
);
$baseUrl
=
$this
->
getRequest
()
->
getBaseUrl
()
.
'/'
.
$this
->
getPluginPath
();
...
...
@@ -185,68 +187,20 @@ class XML2HTMLPlugin extends GenericPlugin
$page
=
$args
[
0
];
$op
=
$args
[
1
];
if
(
$page
==
'article'
&&
(
$op
==
'image'
||
$op
==
'zimage'
))
{
if
(
$page
==
'article'
&&
(
/*
$op == 'image' ||
*/
$op
==
'zimage'
))
{
define
(
'HANDLER_CLASS'
,
'ArticleImageDataHandler'
);
import
(
'plugins.generic.xml2html.ArticleImageDataHandler'
);
}
else
if
((
$page
==
'catalog'
)
&&
(
$op
==
'image'
||
$op
==
'zimage'
))
{
}
else
if
((
$page
==
'catalog'
)
&&
(
/*
$op == 'image' ||
*/
$op
==
'zimage'
))
{
define
(
'HANDLER_CLASS'
,
'BookImageDataHandler'
);
import
(
'plugins.generic.xml2html.BookImageDataHandler'
);
}
}
/**
* @param string $htmlString
* @param SubmissionFile $submissionFile
* @return string
* @brief Substitute path to attached images in html source
*/
static
function
resolveImagePaths
(
string
$htmlString
,
SubmissionFile
$submissionFile
,
Request
$request
)
{
$dependentFilesIterator
=
Services
::
get
(
'submissionFile'
)
->
getMany
([
'assocTypes'
=>
[
ASSOC_TYPE_SUBMISSION_FILE
],
'assocIds'
=>
[
$submissionFile
->
getId
()],
'submissionIds'
=>
[
$submissionFile
->
getData
(
'submissionId'
)],
'fileStages'
=>
[
SUBMISSION_FILE_DEPENDENT
],
'includeDependentFiles'
=>
true
,
]);
foreach
(
$dependentFilesIterator
as
$dependentFile
)
{
$filePath
=
$request
->
url
(
null
,
'article'
,
'image'
,
array
(
$submissionFile
->
getData
(
'submissionId'
),
$dependentFile
->
getData
(
'fileId'
)
)
);
// Solution from HtmlArticleGalleyPlugin::_getHTMLContents
$imageFiles
=
[];
$imageFileNames
=
array_values
(
$dependentFile
->
getData
(
'name'
));
// localized
foreach
(
$imageFileNames
as
$imageFileName
)
{
if
(
empty
(
$imageFileName
))
continue
;
if
(
array_key_exists
(
$imageFileName
,
$imageFiles
))
continue
;
$imageFiles
[
$imageFileName
]
=
$filePath
;
$pattern
=
preg_quote
(
rawurlencode
(
$imageFileName
));
$htmlString
=
preg_replace
(
'/([Ss][Rr][Cc]|[Hh][Rr][Ee][Ff]|[Dd][Aa][Tt][Aa])\s*=\s*"([^"]*'
.
$pattern
.
')"/'
,
'\1="'
.
$filePath
.
'"'
,
$htmlString
);
}
}
return
$htmlString
;
}
static
function
resolveZipImagePaths
(
string
$htmlString
,
int
$submissionId
,
int
$galleyId
,
string
$xmlFilePath
,
Request
$request
,
string
$op
=
'article'
)
...
...
@@ -265,6 +219,7 @@ class XML2HTMLPlugin extends GenericPlugin
'zimage'
,
array
(
$submissionId
,
$galleyId
,
$file
)
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment