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
23783060
Commit
23783060
authored
Jul 4, 2024
by
Jerome Chauveau
Browse files
Options
Downloads
Patches
Plain Diff
Publication::publish hook
parent
e6db2d80
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
BookImageDataHandler.inc.php
+4
-20
4 additions, 20 deletions
BookImageDataHandler.inc.php
XML2HTMLPlugin.php
+38
-24
38 additions, 24 deletions
XML2HTMLPlugin.php
with
42 additions
and
44 deletions
BookImageDataHandler.inc.php
+
4
−
20
View file @
23783060
...
...
@@ -29,28 +29,12 @@ class BookImageDataHandler extends CatalogBookHandler
*/
public
function
zimage
(
array
$args
,
APP
\core\Request
$request
)
{
$pubId
=
$args
[
1
];
$imgName
=
$args
[
2
];
$submission
=
$this
->
getAuthorizedContextObject
(
Application
::
ASSOC_TYPE_SUBMISSION
);
$pubFormatFiles
=
Repo
::
submissionFile
()
->
getCollector
()
->
filterBySubmissionIds
([
$submission
->
getId
()])
->
filterByAssoc
(
Application
::
ASSOC_TYPE_PUBLICATION_FORMAT
)
->
getMany
();
$publicationFile
=
NULL
;
foreach
(
$pubFormatFiles
as
$file
){
if
(
$file
->
getData
(
'assocId'
)
==
$pubId
)
{
$publicationFile
=
$file
;
}
}
$pathInfo
=
pathinfo
(
$publicationFile
->
getData
(
'path'
));
$submissionFileId
=
(
int
)
$args
[
2
];
$imgName
=
$args
[
3
];
$submissionFile
=
Repo
::
submissionFile
()
->
get
(
$submissionFileId
);
$pathInfo
=
pathinfo
(
$submissionFile
->
getData
(
'path'
));
$imagePath
=
$pathInfo
[
'dirname'
]
.
DIRECTORY_SEPARATOR
.
$pathInfo
[
'filename'
]
.
DIRECTORY_SEPARATOR
.
$imgName
;
ImageUtils
::
downloadImage
(
$this
->
fs
,
$imagePath
,
$imgName
);
}
...
...
This diff is collapsed.
Click to expand it.
XML2HTMLPlugin.php
+
38
−
24
View file @
23783060
...
...
@@ -7,10 +7,13 @@
*/
use
APP\facades\Repo
;
use
PKP\core\JSONMessage
;
use
PKP\plugins\GenericPlugin
;
use
PKP\file\PrivateFileManager
;
use
PKP\facades\Locale
;
use
PKP\submissionFile\SubmissionFile
;
use
PKP\plugins\Hook
;
class
XML2HTMLPlugin
extends
GenericPlugin
{
...
...
@@ -22,48 +25,71 @@ class XML2HTMLPlugin extends GenericPlugin
if
(
$success
&&
$this
->
getEnabled
())
{
HookRegistry
::
register
(
'ArticleHandler::view::galley'
,
array
(
$this
,
'articleHandler'
));
//HookRegistry::register('ArticleHandler::download', array($this, 'articleDownloadCallback'), HOOK_SEQUENCE_LATE);
HookRegistry
::
register
(
'LoadHandler'
,
array
(
$this
,
'loadImageHandler'
));
HookRegistry
::
register
(
'CatalogBookHandler::view'
,
array
(
$this
,
'catalogHandler'
));
Hook
::
add
(
'Publication::publish'
,
array
(
$this
,
'publishHandler'
));
}
return
$success
;
}
/**
* when a publication is published : remove all html transformation file results
* @param $hookName
* @param $params
* @return void
*/
public
function
publishHandler
(
$hookName
,
$params
){
$publication
=
&
$params
[
1
];
$submissionId
=
$publication
->
getData
(
'submissionId'
);
$submissionFiles
=
Repo
::
submissionFile
()
->
getCollector
()
->
filterBySubmissionIds
([
$submissionId
])
->
getMany
();
foreach
(
$submissionFiles
as
$sf
){
$htmlFile
=
XML2HTMLPlugin
::
getHTMLPathFromZipPath
(
$sf
->
getData
(
'path'
));
if
(
file_exists
(
$htmlFile
)){
unlink
(
$htmlFile
);
}
}
}
/**
* @throws Exception
*/
public
function
articleHandler
(
$hookName
,
$params
):
bool
{
$galley
=&
$params
[
2
];
$submission
=
&
$params
[
3
];
//handle only on zip galleys - supposed to be an xml archive (source + images)
#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
(),
$galley
->
getId
(),
'article'
);
$this
->
archiveView
(
$galley
->
getFile
()
->
getData
(
'path'
),
[
$submission
->
getId
(),
$galley
->
getId
()
]
,
'article'
);
return
true
;
}
else
return
false
;
}
public
function
catalogHandler
(
$hookName
,
$params
):
bool
{
$submission
=
&
$params
[
1
];
$galley
=&
$params
[
2
];
$submissionFile
=&
$params
[
3
];
$zipMode
=
$submissionFile
->
getData
(
'mimetype'
)
===
"application/zip"
;
if
(
$zipMode
)
{
$this
->
archiveView
(
$submissionFile
->
getData
(
'path'
),
$submission
->
getId
(),
$galley
->
getId
(),
'catalog'
);
$this
->
archiveView
(
$submissionFile
->
getData
(
'path'
),
[
$submission
->
getId
(),
$galley
->
getId
(),
$submissionFile
->
getId
()],
'catalog'
);
return
true
;
}
else
return
false
;
}
private
function
archiveView
(
string
$filePath
,
int
$submissionId
,
int
$galleyId
,
string
$op
)
private
function
archiveView
(
string
$zipPath
,
array
$routeIds
,
string
$op
)
{
$htmlFile
=
XML2HTMLPlugin
::
getHTMLPathFromZipPath
(
$
file
Path
);
$htmlFile
=
XML2HTMLPlugin
::
getHTMLPathFromZipPath
(
$
zip
Path
);
$html
=
file_get_contents
(
$htmlFile
);
//make transfo only if html does not exist
if
(
!
$html
)
{
...
...
@@ -80,11 +106,10 @@ class XML2HTMLPlugin extends GenericPlugin
if
(
$format
==
NULL
||
$format
==
''
)
$format
=
'JATS'
;
//default value is JATS
$xmlFilePath
=
XML2HTMLPlugin
::
unzipXMLArchive
(
$
file
Path
);
$xmlFilePath
=
XML2HTMLPlugin
::
unzipXMLArchive
(
$
zip
Path
);
$html
=
$this
->
resolveZipImagePaths
(
XML2HTMLPlugin
::
transform
(
$xmlFilePath
,
$format
),
$submissionId
,
$galleyId
,
$routeIds
,
$xmlFilePath
,
$this
->
getRequest
(),
$op
);
//store transfo result
...
...
@@ -206,18 +231,14 @@ class XML2HTMLPlugin extends GenericPlugin
string
$format
)
{
$xslFileName
=
strtolower
(
$format
)
.
'2html.xsl'
;
////// xslt transfo
$xsltPath
=
dirname
(
__FILE__
)
.
DIRECTORY_SEPARATOR
.
$xslFileName
;
// Load the XML source
$xml
=
new
DOMDocument
;
$xml
->
load
(
$xmlFilePath
);
$xsl
=
new
DOMDocument
;
$xsl
->
load
(
$xsltPath
,
LIBXML_DTDATTR
);
// Configure the transformer
$proc
=
new
XSLTProcessor
;
$proc
->
importStyleSheet
(
$xsl
);
// attach the xsl rules
...
...
@@ -286,7 +307,6 @@ class XML2HTMLPlugin extends GenericPlugin
{
$page
=
$args
[
0
];
$op
=
$args
[
1
];
if
(
$page
==
'article'
&&
(
/*$op == 'image' || */
$op
==
'zimage'
))
{
define
(
'HANDLER_CLASS'
,
'ArticleImageDataHandler'
);
import
(
'plugins.generic.xml2html.ArticleImageDataHandler'
);
...
...
@@ -296,11 +316,9 @@ class XML2HTMLPlugin extends GenericPlugin
}
}
static
function
resolveZipImagePaths
(
string
$htmlString
,
int
$submissionId
,
int
$galleyId
,
array
$routesIds
,
string
$xmlFilePath
,
APP
\core\Request
$request
,
string
$op
=
'article'
)
...
...
@@ -317,11 +335,7 @@ class XML2HTMLPlugin extends GenericPlugin
$filePath
=
$request
->
url
(
null
,
$op
,
'zimage'
,
array
(
$submissionId
,
$galleyId
,
$file
)
array_merge
(
$routesIds
,
[
$file
])
);
$pattern
=
preg_quote
(
rawurlencode
(
$file
));
$htmlString
=
preg_replace
(
...
...
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