Skip to content

Commit

Permalink
Merge pull request #4630 from Vitaliy-1/ojs-stable-3_1_1-i3691
Browse files Browse the repository at this point in the history
#3691 default CSS for HTML galleys for stable-3.1.1
  • Loading branch information
NateWr authored Mar 26, 2019
2 parents e8a1241 + 3d4e852 commit b978c8c
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 b978c8c

Please sign in to comment.