Commit a1a2be51 authored by Jérôme Chauveau's avatar Jérôme Chauveau
Browse files

transfo spécifique pour les métadonnées + injection dans le template. #23

parent b9f4a839
Loading
Loading
Loading
Loading
+41 −10
Changes for XML2HTMLPlugin.php: 41 added lines, 10 removed lines.
Original line number Diff line number Diff line
@@ -11,6 +11,8 @@ import('lib.pkp.classes.file.PrivateFileManager');

class XML2HTMLPlugin extends GenericPlugin
{
    static $META_XSL_SUFFIX = "-metas2html.xsl";

    public function register($category, $path, $mainContextId = NULL)
    {

@@ -61,7 +63,7 @@ class XML2HTMLPlugin extends GenericPlugin
    private function archiveView(string $filePath, int $submissionId, int $galleyId, string $op)
    {
        $htmlFile = XML2HTMLPlugin::getHTMLPathFromZipPath($filePath);
        $html = file_get_contents($htmlFile);
        $html = FALSE;//file_get_contents($htmlFile);
        //make transfo only if html does not exist
        if (!$html) {
            //get sources format from settings
@@ -84,13 +86,20 @@ class XML2HTMLPlugin extends GenericPlugin
                $galleyId,
                $xmlFilePath, $this->getRequest(),
                $op);
            //store transfo result
            file_put_contents($htmlFile, $html, LOCK_EX);
        }

            //metas transfo
            $dcMetas = XML2HTMLPlugin::transformMetas($xmlFilePath, $format);

            //store render result
            $templateMgr = TemplateManager::getManager($this->getRequest());
            $templateMgr->assign('assetsPath', $this->getPluginAssetsPath($this->getRequest()));
            $templateMgr->assign('dcMetas', $dcMetas);
            $templateMgr->assign('text', $html);
        $templateMgr->display($this->getTemplateResource('HTMLGalleyView.tpl'));
            $html = $templateMgr->display($this->getTemplateResource('HTMLGalleyView.tpl'));
            file_put_contents($htmlFile, $html, LOCK_EX);
        }
        return $html;

    }

    /**
@@ -213,13 +222,13 @@ class XML2HTMLPlugin extends GenericPlugin

        $result = NULL;
        foreach (glob($xsltDir . "*.xsl") as $xsltPath) {

            if(basename($xsltPath) ==  strtolower($format) . XML2HTMLPlugin::$META_XSL_SUFFIX)
                continue;//do not apply metas xsl
            $xml = new DOMDocument;
            if ($result == NULL) {
                // Load the XML source
                $xml->load($xmlFilePath);
            }
            else {
            } else {
                //Load previous xsl result
                $xml->loadXML($result);
            }
@@ -237,8 +246,7 @@ class XML2HTMLPlugin extends GenericPlugin

            try {
                $result = $proc->transformToXML($xml);
            }
            catch(Exception $e) {
            } catch (Exception $e) {
                $result = NULL;
                var_dump($e);
            }
@@ -249,6 +257,29 @@ class XML2HTMLPlugin extends GenericPlugin
    }


    static function transformMetas(
        string $xmlFilePath,
        string $format
    )
    {
        $xslt = dirname(__FILE__)
        . DIRECTORY_SEPARATOR
            . 'xsl'
            . DIRECTORY_SEPARATOR
            . strtolower($format)
            . DIRECTORY_SEPARATOR
            . strtolower($format)
            . XML2HTMLPlugin::$META_XSL_SUFFIX;
        $xml = new DOMDocument;
        $xml->load($xmlFilePath);
        $xsl = new DOMDocument;
        $xsl->load($xslt, LIBXML_DTDATTR);
        $proc = new XSLTProcessor;
        $proc->importStyleSheet($xsl);
        return $proc->transformToXML($xml);
    }


    /**
     * @param string $path
     * @return string|void|null
+1 −6
Changes for templates/HTMLGalleyView.tpl: 1 added line, 6 removed lines.
Original line number Diff line number Diff line
{*{include file="frontend/components/header.tpl"}*}
{*<div class="page">*}
{*	{$text}*}
{*</div>*}
{*{include file="frontend/components/footer.tpl"}*}
<!DOCTYPE html>
<html lang="{$currentLocale|replace:"_":"-"}" xml:lang="{$currentLocale|replace:"_":"-"}">
    <head>
@@ -17,6 +12,7 @@
            let lang = "{$currentLocale}"
        </script>
        <script src="{$assetsPath}javascript/xml_2_html.js"></script>
        {$dcMetas}
    </head>
    <body>
    <div class="page">
@@ -25,5 +21,4 @@
</body>
</html>

{*<script src="{$pluginLensPath}/lens.js"></script>*}
+29 −0
Changes for xsl/jats/jats-metas2html.xsl: 29 added lines, 0 removed lines.
Original line number Diff line number Diff line
<?xml version="1.0"?>

<xsl:stylesheet version="1.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:xlink="http://www.w3.org/1999/xlink"
                xmlns:mml="http://www.w3.org/1998/Math/MathML"
                xmlns:xs="http://www.w3.org/1999/XSL/Transform"
                xmlns:xsl-="http://www.w3.org/1999/XSL/Transform"
                exclude-result-prefixes="xlink mml">


    <xsl:output method="html" encoding="UTF-8" indent="no"/>

    <xsl:strip-space elements="*"/>


    <xsl:template match="/">
        <meta name="DC.title" content="{//article-title}"/>
        <meta name="DC.creator" content="{//contrib[@contrib-type='aut']//surname}"/>
        <meta name="DC.date" content="{//pub-date/year}"/>
        <meta name="DC.type" content="Text"/>
        <meta name="DC.format" content="text/html"/>
        <meta name="DC.language" content="{article/@xml:lang}"/>
        <meta name="DC.type" content="{article/@article-type}"/>
        <meta name="DC.rights" content="{//permissions/license/license-p}"/>
    </xsl:template>


</xsl:stylesheet>
+101 −62
Changes for xsl/tei/03-tei2html.xsl: 101 added lines, 62 removed lines.
Original line number Diff line number Diff line
@@ -34,32 +34,11 @@


    <xsl:template match="/">
        <!-- start : to delete -->
        <html lang="{//tei:language/@ident}">
            <head>
                <meta charset="utf-8"/>
                <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
                <title><xsl:value-of select="//tei:title[@type='main']"/></title>
                <link rel="stylesheet" type="text/css" href="../ressources/styles/xml_2_html.css"/>
                <script src="../ressources/javascript/xml_2_html.js"/>
                <script>let lang = "fr"</script>
                <xsl:if test="descendant::tei:formula">
                    <script src="https://polyfill.io/v3/polyfill.min.js?features=es6"></script>
                    <script id="MathJax-script" src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>
                </xsl:if>
                <meta name="DC.title" content="{//tei:title[@type='main']}"/>
                <meta name="DC.creator" content="{//tei:author[@role='aut']//tei:surname}"/>
                <meta name="DC.date" content="{//tei:ab[@subtype='HTML' and descendant::tei:name[@type='CMS']='OMP' or 'OJS']}"/>
                <meta name="DC.type" content="Text"/>
                <meta name="DC.format" content="text/html"/>
                <meta name="DC.language" content="{//tei:language/@ident}"/>
                <meta name="DC.type" content="{//tei:text/@type}"/>
                <meta name="DC.rights" content="{//tei:ab[@subtype='HTML' and descendant::tei:name[@type='CMS']='OMP' or 'OJS']//tei:availability}"/>
            </head>
            <body>
        <!-- end : to delete -->

        <div class="wrap">
            <a role="button" onclick="translatePage('fr')">FR</a> | <a role="button" onclick="translatePage('en')">EN</a>
            <a role="button" onclick="translatePage('fr')">FR</a>
            |
            <a role="button" onclick="translatePage('en')">EN</a>
            <div id="mode-color-btns">
                <button id="sun" onclick="darkMode(true)">
                    <svg style="" class="icon" focusable="false" viewBox="0 0 32 32">
@@ -88,10 +67,7 @@

            <xsl:apply-templates/>
        </div>
        <!-- start : to delete -->
        </body>
        </html>
        <!-- end : to delete -->

    </xsl:template>

    <xsl:template match="tei:TEI">
@@ -108,7 +84,8 @@
                                    <xsl:value-of select="@xml:lang"/>
                                </xsl:attribute>
                            </xsl:if>
                            <xsl:apply-templates/></p>
                            <xsl:apply-templates/>
                        </p>
                    </xsl:for-each>
                    <xsl:apply-templates select=".//tei:body"/>
                </div>
@@ -140,7 +117,8 @@

            <div class="button-tabs">
                <xsl:if test="//tei:div[starts-with(@type,'section')]">
                    <button id="tabtn-toc" class="tab-btn focus-tab trans" data-key='toc' onclick="openTab('toc')"></button>
                    <button id="tabtn-toc" class="tab-btn focus-tab trans" data-key='toc'
                            onclick="openTab('toc')"></button>
                </xsl:if>
                <xsl:if test="//tei:figure[not(child::tei:table)]">
                    <button id="tabtn-figures" class="tab-btn" onclick="openTab('figures')">Figures</button>
@@ -161,7 +139,8 @@
                <div id="toc-contents">

                    <ol>
                        <xsl:for-each select="../tei:body//tei:div|../tei:back//tei:div[@type='bibliography']|../tei:back//tei:listBibl|../tei:back//tei:div[@type='appendix']">
                        <xsl:for-each
                                select="../tei:body//tei:div|../tei:back//tei:div[@type='bibliography']|../tei:back//tei:listBibl|../tei:back//tei:div[@type='appendix']">
                            <xsl:call-template name="sec-toc-item">
                                <xsl:with-param name="item" select="."/>
                            </xsl:call-template>
@@ -172,7 +151,8 @@
            </div>

            <div id="figures" class="content-tab" style="display:none">
                <xsl:for-each select="..//tei:figure[not(child::tei:table) and not(child::tei:formula) and not(ancestor::tei:figure)]">
                <xsl:for-each
                        select="..//tei:figure[not(child::tei:table) and not(child::tei:formula) and not(ancestor::tei:figure)]">
                    <xsl:apply-templates select="." mode="panel"/>
                </xsl:for-each>
            </div>
@@ -228,7 +208,9 @@
            <xsl:attribute name="id">
                <xsl:value-of select="@xml:id"/>
            </xsl:attribute>
            <span class="label" title="voir"><xsl:value-of select="@n"/></span>
            <span class="label" title="voir">
                <xsl:value-of select="@n"/>
            </span>
            <xsl:apply-templates/>
        </li>
    </xsl:template>
@@ -244,7 +226,9 @@
        <xsl:choose>
            <xsl:when test="@type='index'">
                <span class="index-link">
                    <a href="{@target}"><xsl:number/></a>
                    <a href="{@target}">
                        <xsl:number/>
                    </a>
                </span>
            </xsl:when>
            <xsl:otherwise>
@@ -255,7 +239,8 @@
        </xsl:choose>
    </xsl:template>

    <xsl:template match="tei:anchor"><span id="{@xml:id}">
    <xsl:template match="tei:anchor">
        <span id="{@xml:id}">
            <xsl:attribute name="class">
                <xsl:choose>
                    <xsl:when test="starts-with(@n,'index')">index-anchor</xsl:when>
@@ -335,7 +320,8 @@
    </xsl:template>

    <!--generic meta template (block) <=> teiHeader -->
    <xsl:template match="tei:teiHeader|tei:fileDesc|tei:titleStmt|tei:publicationStmt|tei:persName|tei:surname|tei:ab|tei:bibl|tei:publisher|tei:availability|tei:licence|tei:distributor|tei:date|tei:dim">
    <xsl:template
            match="tei:teiHeader|tei:fileDesc|tei:titleStmt|tei:publicationStmt|tei:persName|tei:surname|tei:ab|tei:bibl|tei:publisher|tei:availability|tei:licence|tei:distributor|tei:date|tei:dim">
        <xsl:apply-templates/>
    </xsl:template>

@@ -357,7 +343,8 @@
    </xsl:template>

    <xsl:template match="tei:forename">
        <xsl:apply-templates/><xsl:text> </xsl:text>
        <xsl:apply-templates/>
        <xsl:text> </xsl:text>
    </xsl:template>

    <xsl:template match="tei:ab[@type='book']">
@@ -371,7 +358,8 @@
    </xsl:template>

    <!-- ignored teiHeader elements -->
    <xsl:template match="tei:sourceDesc|tei:encodingDesc|tei:profileDesc|tei:revisionDesc|tei:ab[@type='digital_download']"/>
    <xsl:template
            match="tei:sourceDesc|tei:encodingDesc|tei:profileDesc|tei:revisionDesc|tei:ab[@type='digital_download']"/>


    <!--generic inline template -->
@@ -422,16 +410,32 @@
                </s>
            </xsl:when>
            <xsl:when test="@rend='bold italic'">
                <b><i><xsl:apply-templates/></i></b>
                <b>
                    <i>
                        <xsl:apply-templates/>
                    </i>
                </b>
            </xsl:when>
            <xsl:when test="@rend='small-caps italic'">
                <i><span style="font-variant:small-caps;"><xsl:apply-templates/></span></i>
                <i>
                    <span style="font-variant:small-caps;">
                        <xsl:apply-templates/>
                    </span>
                </i>
            </xsl:when>
            <xsl:when test="@rend='sup italic'">
                <sup><i><xsl:apply-templates/></i></sup>
                <sup>
                    <i>
                        <xsl:apply-templates/>
                    </i>
                </sup>
            </xsl:when>
            <xsl:when test="@rend='sub italic'">
                <sub><i><xsl:apply-templates/></i></sub>
                <sub>
                    <i>
                        <xsl:apply-templates/>
                    </i>
                </sub>
            </xsl:when>
        </xsl:choose>
    </xsl:template>
@@ -517,14 +521,18 @@
        </p>
    </xsl:template>

    <xsl:template match="tei:lb"><br/></xsl:template>
    <xsl:template match="tei:lb">
        <br/>
    </xsl:template>

    <xsl:template match="tei:figure">
        <figure id="{concat('main-',@xml:id)}">
            <xsl:attribute name="class">
                <xsl:choose>
                    <xsl:when test="child::tei:table">fig-table</xsl:when>
                    <xsl:when test="child::tei:formula">fig-formula <xsl:value-of select="@rend"/></xsl:when>
                    <xsl:when test="child::tei:formula">fig-formula
                        <xsl:value-of select="@rend"/>
                    </xsl:when>
                    <xsl:otherwise>fig-ill</xsl:otherwise>
                </xsl:choose>
            </xsl:attribute>
@@ -546,11 +554,14 @@

    <xsl:template match="tei:figure[not(child::tei:table)]//tei:head">
        <label>
            <span class="fig-call" data-target="{parent::tei:figure/@xml:id}"><xsl:apply-templates/></span>
            <span class="fig-call" data-target="{parent::tei:figure/@xml:id}">
                <xsl:apply-templates/>
            </span>
            <span class="fig-call-window">
                <a href="#" id="openFigureLink">
                    <xsl:attribute name="onclick">
                    <xsl:value-of select='concat("openFigureWindow&#40;&apos;",parent::tei:figure/@xml:id,"&apos;&#41;")'/>
                        <xsl:value-of
                                select='concat("openFigureWindow&#40;&apos;",parent::tei:figure/@xml:id,"&apos;&#41;")'/>
                    </xsl:attribute>
                    <xsl:text>     ↗ </xsl:text>
                </a>
@@ -574,7 +585,8 @@
            <span class="fig-call-window">
                <a href="#" id="openFigureLink">
                    <xsl:attribute name="onclick">
                    <xsl:value-of select='concat("openFigureWindow&#40;&apos;",parent::tei:figure/@xml:id,"&apos;&#41;")'/>
                        <xsl:value-of
                                select='concat("openFigureWindow&#40;&apos;",parent::tei:figure/@xml:id,"&apos;&#41;")'/>
                    </xsl:attribute>
                    <xsl:text>     ↗ </xsl:text>
                </a>
@@ -598,19 +610,37 @@

    <xsl:template match="tei:table">
        <xsl:if test="parent::tei:figure/tei:head">
            <span class="expand"><xsl:text>▸ </xsl:text></span>
            <label><!--span class="table-call"><xsl:text> ↓ </xsl:text></span--><xs:apply-templates select="parent::tei:figure/tei:head" mode="titleUp"/><!--span class="table-call"><xsl:text> ↓ </xsl:text></span--></label>
            <span class="table-call-window"><a href="#" id="openFigureLink">
                <xsl:attribute name="onclick"><xsl:value-of select='concat("openFigureWindow&#40;&apos;main-",parent::tei:figure/@xml:id,"&apos;&#41;")'/></xsl:attribute>
                <xsl:text> ↗ </xsl:text></a></span>
            <span class="expand">
                <xsl:text>▸ </xsl:text>
            </span>
            <label><!--span class="table-call"><xsl:text> ↓ </xsl:text></span-->
                <xs:apply-templates select="parent::tei:figure/tei:head"
                                    mode="titleUp"/><!--span class="table-call"><xsl:text> ↓ </xsl:text></span-->
            </label>
            <span class="table-call-window">
                <a href="#" id="openFigureLink">
                    <xsl:attribute name="onclick">
                        <xsl:value-of
                                select='concat("openFigureWindow&#40;&apos;main-",parent::tei:figure/@xml:id,"&apos;&#41;")'/>
                    </xsl:attribute>
                    <xsl:text> ↗ </xsl:text>
                </a>
            </span>
        </xsl:if>
        <xsl:if test="parent::tei:figure[not(child::tei:head)]">
            <span class="expand empty"><xsl:text>▸ </xsl:text>
            <span class="expand empty">
                <xsl:text>▸ </xsl:text>
            </span>
            <label class="generated"/>
            <span class="table-call-window"><a href="#" id="openFigureLink">
                <xsl:attribute name="onclick"><xsl:value-of select='concat("openFigureWindow&#40;&apos;main-",parent::tei:figure/@xml:id,"&apos;&#41;")'/></xsl:attribute>
                <xsl:text> ↗ </xsl:text></a></span>
            <span class="table-call-window">
                <a href="#" id="openFigureLink">
                    <xsl:attribute name="onclick">
                        <xsl:value-of
                                select='concat("openFigureWindow&#40;&apos;main-",parent::tei:figure/@xml:id,"&apos;&#41;")'/>
                    </xsl:attribute>
                    <xsl:text> ↗ </xsl:text>
                </a>
            </span>
        </xsl:if>
        <table>
            <xsl:choose>
@@ -630,7 +660,9 @@
    </xsl:template>

    <xsl:template match="tei:row">
        <tr><xsl:apply-templates/></tr>
        <tr>
            <xsl:apply-templates/>
        </tr>
    </xsl:template>

    <xsl:template match="tei:cell">
@@ -664,7 +696,9 @@
            <xsl:when test="parent::tei:div[@type='index'] and text()='Index'"/>
            <xsl:otherwise>
                <xsl:element name="h{$ancestors + 1}">
                    <xsl:attribute name="id"><xsl-:value-of select="concat('title-',$n)"/></xsl:attribute>
                    <xsl:attribute name="id">
                        <xsl-:value-of select="concat('title-',$n)"/>
                    </xsl:attribute>
                    <xsl:apply-templates/>
                </xsl:element>
            </xsl:otherwise>
@@ -719,11 +753,15 @@

    <!-- citations -->
    <xsl:template match="tei:cit[not(@type='linguistic')]">
        <blockquote><xsl:apply-templates/></blockquote>
        <blockquote>
            <xsl:apply-templates/>
        </blockquote>
    </xsl:template>

    <xsl:template match="tei:quote">
        <p><xsl:apply-templates/></p>
        <p>
            <xsl:apply-templates/>
        </p>
    </xsl:template>

    <!-- maths -->
@@ -781,7 +819,8 @@

    <xsl:template match="tei:seg">
        <xsl:choose>
            <xsl:when test="not(preceding-sibling::tei:seg or following-sibling::tei:seg) and parent::tei:quote[@type='example']">
            <xsl:when
                    test="not(preceding-sibling::tei:seg or following-sibling::tei:seg) and parent::tei:quote[@type='example']">
                <xsl:apply-templates/>
            </xsl:when>
            <xsl:otherwise>
+31 −0
Changes for xsl/tei/tei-metas2html.xsl: 31 added lines, 0 removed lines.
Original line number Diff line number Diff line
<?xml version="1.0"?>

<xsl:stylesheet version="1.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:xlink="http://www.w3.org/1999/xlink"
                xmlns:mml="http://www.w3.org/1998/Math/MathML"
                xmlns:xs="http://www.w3.org/1999/XSL/Transform"
                xmlns:xsl-="http://www.w3.org/1999/XSL/Transform"
                xmlns:tei="http://www.tei-c.org/ns/1.0"
                exclude-result-prefixes="xlink mml tei">

    <xsl:output method="html" encoding="UTF-8" indent="no"/>

    <xsl:strip-space elements="*"/>


    <xsl:template match="/">
        <meta name="DC.title" content="{//tei:title[@type='main']}"/>
        <meta name="DC.creator" content="{//tei:author[@role='aut']//tei:surname}"/>
        <meta name="DC.date"
              content="{//tei:ab[@subtype='HTML' and descendant::tei:name[@type='CMS']='OMP' or 'OJS']}"/>
        <meta name="DC.type" content="Text"/>
        <meta name="DC.format" content="text/html"/>
        <meta name="DC.language" content="{//tei:language/@ident}"/>
        <meta name="DC.type" content="{//tei:text/@type}"/>
        <meta name="DC.rights"
              content="{//tei:ab[@subtype='HTML' and descendant::tei:name[@type='CMS']='OMP' or 'OJS']//tei:availability}"/>
    </xsl:template>


</xsl:stylesheet>