Skip to content

Commit

Permalink
pkp#3691 default CSS for HTML galleys for stable-3.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Vitaliy-1 committed Mar 22, 2019
1 parent e8a1241 commit 3d4e852
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions classes/template/PKPTemplateManager.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -1495,6 +1495,48 @@ function smartyLoadStylesheet($params, $smarty) {
return $output;
}

/**
* Inject default styles into a HTML galley
*
* Any styles assigned to the `htmlGalley` context will be injected into the
* galley unless the galley already has an embedded CSS file.
*
* @param $htmlContent string The HTML file content
* @param $embeddedFiles array Additional files embedded in this galley
*/
function loadHtmlGalleyStyles($htmlContent, $embeddedFiles) {

if (empty($htmlContent)) {
return $htmlContent;
}

$hasEmbeddedStyle = false;
foreach ($embeddedFiles as $embeddedFile) {
if ($embeddedFile->getFileType() === 'text/css') {
$hasEmbeddedStyle = true;
break;
}
}

if ($hasEmbeddedStyle) {
return $htmlContent;
}

$links = '';
$styles = $this->getResourcesByContext($this->_styleSheets, 'htmlGalley');

if (!empty($styles)) {
ksort($styles);
foreach ($styles as $priorityGroup) {
foreach ($priorityGroup as $htmlStyle) {
$links .= '<link rel="stylesheet" href="' . $htmlStyle['style'] . '" type="text/css">' . "\n";
}
}
}

return str_ireplace('<head>', '<head>' . "\n" . $links, $htmlContent);
}

/**
* Smarty usage: {load_script context="backend" scripts=$scripts}
*
Expand Down

0 comments on commit 3d4e852

Please sign in to comment.