Skip to content

Commit

Permalink
"HTML galleys rendering"
Browse files Browse the repository at this point in the history
  • Loading branch information
Vitaliy-1 committed May 10, 2018
1 parent c982317 commit 69949bb
Show file tree
Hide file tree
Showing 7 changed files with 252 additions and 27 deletions.
41 changes: 41 additions & 0 deletions HealthSciencesThemePlugin.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ public function init() {

// Get extra data for templates
HookRegistry::register ('TemplateManager::display', array($this, 'loadTemplateData'));

// Check if CSS embedded to the HTML galley
HookRegistry::register('TemplateManager::display', array($this, 'hasEmbeddedCSS'));
}

/**
Expand Down Expand Up @@ -142,4 +145,42 @@ public function loadTemplateData($hookName, $args) {
));
}
}

public function hasEmbeddedCSS($hookName, $args) {
$templateMgr = $args[0];
$template = $args[1];
$request = $this->getRequest();

// Retun false if not a galley page
if ($template != 'plugins/plugins/generic/htmlArticleGalley/generic/htmlArticleGalley:display.tpl') return false;

$articleArrays = $templateMgr->get_template_vars('article');

$boolEmbeddedCss = false;

foreach ($articleArrays->getGalleys() as $galley) {
if ($galley->getFileType() === 'text/html') {
$submissionFile = $galley->getFile();

$submissionFileDao = DAORegistry::getDAO('SubmissionFileDAO');
import('lib.pkp.classes.submission.SubmissionFile'); // Constants
$embeddableFiles = array_merge(
$submissionFileDao->getLatestRevisions($submissionFile->getSubmissionId(), SUBMISSION_FILE_PROOF),
$submissionFileDao->getLatestRevisionsByAssocId(ASSOC_TYPE_SUBMISSION_FILE, $submissionFile->getFileId(), $submissionFile->getSubmissionId(), SUBMISSION_FILE_DEPENDENT)
);

foreach ($embeddableFiles as $embeddableFile) {
if ($embeddableFile->getFileType() == 'text/css') {
$boolEmbeddedCss = true;
}
}
}

}

$templateMgr->assign(array(
'boolEmbeddedCss' => $boolEmbeddedCss,
'themePath' => $request->getBaseUrl() . "/" . $this->getPluginPath(),
));
}
}
1 change: 1 addition & 0 deletions styles/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
@import "pages/page-search";
@import "pages/page-section";
@import "pages/page-view-pdf";
@import "pages/page-view-html";

@import "components/sidebar";
@import "components/footer";
2 changes: 1 addition & 1 deletion styles/pages/page-issue.less
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
}

.page-issue-cover {
margin-top: 0;
box-shadow: 0 10px 20px rgba(0,0,0,0.1);
margin: auto;
}

.page-issue-date,
Expand Down
81 changes: 81 additions & 0 deletions styles/pages/page-view-html.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/**
* @file styles/pages/page-view-html.less
*
* Copyright (c) 2014-2018 Simon Fraser University
* Copyright (c) 2003-2018 John Willinsky
* Distributed under the GNU GPL v2. For full terms see the file docs/COPYING.
*
* @brief Styles applying to the page for viewing HTML galley
*/


// container

.galley_view {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
overflow-y: hidden;

& iframe {
width: 100%;
height: 100%;
border: none;
padding-top: 30px;
}
}

.header_view {
background-color: @light-grey;
position: relative;
z-index: 2;
}

.header_view .return {
position: absolute;
top: 0;
left: 0;
height: 30px;
width: 30px;
line-height: 30px;
text-align: center;
background-color: #10beca;

&:before {
content: "\f060";
display: inline-block;
font: normal normal normal 14px/1 FontAwesome;
color: white;
}
}

.header_view .title {
margin-left: 30px;
padding-left: 10px;
display: block;
text-overflow: ellipsis;
color: @black;
height: 30px;
line-height: 30px;
max-width: 100%;
overflow: hidden;
white-space: nowrap;
}

.pkp_screen_reader {
position: absolute !important;
left: -5000px;
}



// inner HTML

@media (min-width: 1200px) {
.without_own_css body {
padding-left: 15%;
padding-right: 15%;
}
}
54 changes: 28 additions & 26 deletions templates/frontend/pages/indexJournal.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -45,35 +45,37 @@
</a>
</div>
{/if}
<div class="col-lg-9">
<div class="homepage-issue-description-wrapper">
{if $issue->hasDescription()}
<div class="homepage-issue-description">
<div class="h2">
{if $issue->getLocalizedTitle()}
{$issue->getLocalizedTitle()}
{else}
{translate key="plugins.themes.healthSciences.issueDescription"}
{/if}
{if $issue->hasDescription() || $issueGalleys}
<div class="col-lg-9">
<div class="homepage-issue-description-wrapper">
{if $issue->hasDescription()}
<div class="homepage-issue-description">
<div class="h2">
{if $issue->getLocalizedTitle()}
{$issue->getLocalizedTitle()}
{else}
{translate key="plugins.themes.healthSciences.issueDescription"}
{/if}
</div>
{$issue->getLocalizedDescription()|strip_unsafe_html}
<div class="homepage-issue-description-more">
<a href="{url op="view" page="issue" path=$issue->getBestIssueId()}">{translate key="common.more"}</a>
</div>
</div>
{$issue->getLocalizedDescription()|strip_unsafe_html}
<div class="homepage-issue-description-more">
<a href="{url op="view" page="issue" path=$issue->getBestIssueId()}">{translate key="common.more"}</a>
{/if}
{if $issueGalleys}
<div class="homepage-issue-galleys">
<div class="h3">
{translate key="issue.fullIssue"}
</div>
{foreach from=$issueGalleys item=galley}
{include file="frontend/objects/galley_link.tpl" parent=$issue purchaseFee=$currentJournal->getSetting('purchaseIssueFee') purchaseCurrency=$currentJournal->getSetting('currency')}
{/foreach}
</div>
</div>
{/if}
{if $issueGalleys}
<div class="homepage-issue-galleys">
<div class="h3">
{translate key="issue.fullIssue"}
</div>
{foreach from=$issueGalleys item=galley}
{include file="frontend/objects/galley_link.tpl" parent=$issue purchaseFee=$currentJournal->getSetting('purchaseIssueFee') purchaseCurrency=$currentJournal->getSetting('currency')}
{/foreach}
</div>
{/if}
{/if}
</div>
</div>
</div>
{/if}
</div>

<div class="row justify-content-center">
Expand Down
36 changes: 36 additions & 0 deletions templates/plugins/generic/htmlArticleGalley/css/default.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
p, h1, h2, h3, h4, h5, h6 {
font-family: 'PT Serif', serif;
line-height: 1.6;
}

p {
font-size: 18px;
}

@media (min-width: 1200px) {
body {
padding-left: 20%;
padding-right: 20%;
}
}

@media (min-width: 992px) and (max-width: 1199px) {
body {
padding-left: 12%;
padding-right: 12%;
}
}

@media (min-width: 768px) and (max-width: 991px) {
body {
padding-left: 7%;
padding-right: 7%;
}
}

@media (max-width: 767px) and (max-width: 767px) {
body {
padding-left: 5px;
padding-right: 5px;
}
}
64 changes: 64 additions & 0 deletions templates/plugins/generic/htmlArticleGalley/display.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
{**
* plugins/generic/htmlArticleGalley/display.tpl
*
* Copyright (c) 2014-2018 Simon Fraser University
* Copyright (c) 2003-2018 John Willinsky
* Distributed under the GNU GPL v2. For full terms see the file docs/COPYING.
*
* Embedded viewing of a HTML galley.
* @uses $boolEmbeddedCss bool is true if HTML galley has attached CSS file
*}
<!DOCTYPE html>
<html lang="{$currentLocale|replace:"_":"-"}" xml:lang="{$currentLocale|replace:"_":"-"}">
{translate|assign:"pageTitleTranslated" key="article.pageTitle" title=$article->getLocalizedTitle()}
{include file="frontend/components/headerHead.tpl"}
<body class="pkp_page_{$requestedPage|escape} pkp_op_{$requestedOp|escape}">

{* Header wrapper *}
<header class="header_view">

<a href="{url page="article" op="view" path=$article->getBestArticleId()}" class="return">
<span class="pkp_screen_reader">
{translate key="article.return"}
</span>
</a>

<a href="{url page="article" op="view" path=$article->getBestArticleId()}" class="title">
{$article->getLocalizedTitle()|escape}
</a>
</header>

<div id="htmlContainer" class="galley_view">
<iframe id="htmlGalleyFrame" name="htmlFrame" src="{url page="article" op="download" path=$article->getBestArticleId()|to_array:$galley->getBestGalleyId() inline=true}" allowfullscreen webkitallowfullscreen></iframe>
</div>
{call_hook name="Templates::Common::Footer::PageFooter"}

{* Default style if CSS isn't attached to the HTML Galley *}
{if $boolEmbeddedCss === false}
<script type="text/javascript">{literal}
window.onload = function() {
var iframe = document.getElementById('htmlGalleyFrame');
var insideFrame = iframe.contentDocument || iframe.contentWindow.document;
var headNode = insideFrame.getElementsByTagName('head')[0];
// Loading CSS stylesheet
var linkElement = document.createElement('link');
linkElement.type = 'text/css';
linkElement.rel = 'stylesheet';
linkElement.href = "{/literal}{$themePath|escape:"javascript"}{literal}/templates/plugins/generic/htmlArticleGalley/css/default.css";
headNode.appendChild(linkElement);
// Google Fonts
var linkFont= document.createElement('link');
linkFont.rel = 'stylesheet';
linkFont.href = "https://fonts.googleapis.com/css?family=PT+Serif";
headNode.appendChild(linkFont);
};
{/literal}</script>
{/if}
</body>
</html>

0 comments on commit 69949bb

Please sign in to comment.