Skip to content

Commit

Permalink
pkp#3691 default style for HTML galley
Browse files Browse the repository at this point in the history
  • Loading branch information
Vitaliy-1 committed Dec 17, 2018
1 parent e7c7f5f commit b3c2af0
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions classes/plugins/ThemePlugin.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ function register($category, $path, $mainContextId = null) {
HookRegistry::register('appearanceform::readuservars', array($this, 'readOptionsFormUserVars'));
HookRegistry::register('sitesetupform::execute', array($this, 'saveOptionsForm'));
HookRegistry::register('sitesetupform::readuservars', array($this, 'readOptionsFormUserVars'));

// Add default styles to the HTML galley file
HookRegistry::register('HtmlArticleGalleyPlugin::htmlGalleyContent', array($this, 'addHmtlGalleyStyle'));

return true;
}
Expand Down Expand Up @@ -821,6 +824,57 @@ function isColourDark( $colour, $limit = 130 ) {
);
return $contrast < $limit;
}

/**
* Add default stylesheets to the HTML galley
*
* Passes styles to the galley through HTML Galley Plugin hook
*
* @param $hookName string
* @param $args array [
* $args[0] ArticleGalley
* $args[1] string HTML
* ]
*
* @return bool
*/
function addHmtlGalleyStyle($hookName, $args) {
$galley =& $args[0];
$contents =& $args[1];

if (empty($contents)) return false;

$submissionFile = $galley->getFile();

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

$attachedStyles = false;

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

if ($attachedStyles) return false;

// Upload styles to the HTML galley
$output = '';

foreach ($this->styles as $styleData) {
if ($styleData['contexts'] === 'htmlGalley') {
$output .= '<link rel="stylesheet" href="' . $styleData['style'] . '" type="text/css" />' . "\n";
}
}

$contents = str_replace('<head>', '<head>' . "\n" . $output, $contents);

return true;
}
}


0 comments on commit b3c2af0

Please sign in to comment.