Skip to content

Commit

Permalink
Merge pull request cypht-org#938 from josaphatim/fixed-prod-files-for…
Browse files Browse the repository at this point in the history
…-themes

Fixed production paths for themes files
  • Loading branch information
kroky authored Apr 8, 2024
2 parents 638ea46 + 5a8824e commit 0ae9f8f
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 16 deletions.
14 changes: 7 additions & 7 deletions modules/2fa/modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,11 @@ protected function output() {
'<i class="bi bi-unlock-fill fs-5 me-2"></i>'.$this->trans('2 Factor Authentication').'</td></tr>';

$res .= '<tr class="tfa_setting"><td><label class="form-check-label">'.$this->trans('Enable 2 factor authentication').'</label>'.
'</td><td><input class="form-check-input" value="1" type="checkbox" name="2fa_enable"';
'<input class="form-check-input ms-3" value="1" type="checkbox" name="2fa_enable"';
if ($enabled) {
$res .= ' checked="checked"';
}
$res .= '></td></tr>';
$res .= '>';
$svg = $this->get('2fa_svg');

if ($svg) {
Expand All @@ -174,9 +174,9 @@ protected function output() {
else {
$qr_code = '<div class="tfa_mt_1">'.$this->trans('Unable to generate 2 factor authentication QR code').'</div>';
}
$res .= $qr_code . '</td>';
$res .= $qr_code;

$res .= '<td><div class="tfa_mb_1">'.$this->trans('The following backup codes can be used to access your account if you lose your device'). '</div>';
$res .= '<div class="tfa_mb_1">'.$this->trans('The following backup codes can be used to access your account if you lose your device'). '</div>';

foreach ($backup_codes as $val) {
$res .= ' '.$val.'<input type="hidden" name="2fa_backup_codes[]" value="'.$val.'" /></br >';
Expand Down Expand Up @@ -238,12 +238,12 @@ protected function output() {
<meta charset="utf-8" />
<link href="site.css" media="all" rel="stylesheet" type="text/css" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
<link href="vendor/twbs/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
<link href="modules/themes/assets/default/css/default.css?v=' . CACHE_ID . '" media="all" rel="stylesheet" type="text/css" />
<link href="vendor/twbs/bootstrap-icons/font/bootstrap-icons.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div class="container bg-light">
<div class="row align-items-center justify-content-center vh-100 p-3">
<div class="bg-light">
<div class="d-flex align-items-center justify-content-center vh-100 p-3">
<div class="card col-12 col-md-6 col-lg-4 p-3">
<div class="card-body">
<form class="mt-5" method="POST">
Expand Down
4 changes: 2 additions & 2 deletions modules/2fa/site.css
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@
}
.tfa_confirmation_input_digit {
display: block;
width: 2rem;
height: 2rem;
width: 3rem;
height: 3rem;
padding: 0.625rem;
border: 1px solid var(--tfa-border-color);
border-radius: var(--tfa-border-radius);
Expand Down
6 changes: 3 additions & 3 deletions modules/core/output_modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -501,10 +501,10 @@ class Hm_Output_header_css extends Hm_Output_Module {
protected function output() {
$res = '';
$mods = $this->get('router_module_list');
if (! $this->get('theme')) {
$res .= '<link href="' . WEB_ROOT . 'modules/themes/assets/default/css/default.css?v=' . CACHE_ID . '" media="all" rel="stylesheet" type="text/css" />';
}
if (DEBUG_MODE) {
if ($this->get('theme') == '') {
$res .= '<link href="' . WEB_ROOT . 'modules/themes/assets/default/css/default.css?v=' . CACHE_ID . '" media="all" rel="stylesheet" type="text/css" />';
}
$res .= '<link href="vendor/twbs/bootstrap-icons/font/bootstrap-icons.css" rel="stylesheet" type="text/css" />';
foreach (glob(APP_PATH.'modules'.DIRECTORY_SEPARATOR.'**', GLOB_ONLYDIR | GLOB_MARK) as $name) {
$rel_name = str_replace(APP_PATH, '', $name);
Expand Down
32 changes: 30 additions & 2 deletions scripts/config_gen.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ function build_config() {

/* create the production version */
create_production_site($assets, $settings, $hashes);

process_bootswatch_files();
}
else {
printf("\nNo settings found in ini file\n");
Expand Down Expand Up @@ -235,8 +237,7 @@ function combine_includes($js, $js_compress, $css, $css_compress, $settings) {
$js_hash = '';
$css_hash = '';
if ($css) {
$css_out = file_get_contents(VENDOR_PATH . "twbs/bootstrap/dist/css/bootstrap.min.css");
$css_out .= file_get_contents(VENDOR_PATH . "twbs/bootstrap-icons/font/bootstrap-icons.css");
$css_out = file_get_contents(VENDOR_PATH . "twbs/bootstrap-icons/font/bootstrap-icons.css");
$css_out .= compress($css, $css_compress);
$css_hash = build_integrity_hash($css_out);
file_put_contents('site.css', $css_out);
Expand Down Expand Up @@ -314,6 +315,33 @@ function append_bootstrap_icons_files() {
}
}

function process_bootswatch_files() {
$src = 'site/modules/themes/assets';
if (! is_dir($src)) {
return;
}
$dir = opendir($src);
while(false !== ($folder = readdir($dir))) {
if (($folder != '.' ) && ($folder != '..' )) {
if (is_dir($src . '/' . $folder)) {
$target = $src . '/' . $folder . '/css/' . $folder . '.css';
if ($folder == 'default') {
$content = file_get_contents('vendor/twbs/bootstrap/dist/css/bootstrap.min.css');
// Append customization done to the default theme
$custom = file_get_contents($target);
$custom = preg_replace('/^@import.+/m', '', $custom);
$custom = preg_replace('/^@charset.+/m', '', $custom);
$content .= "\n" . $custom;
} else {
$content = file_get_contents('vendor/thomaspark/bootswatch/dist/' . $folder . '/bootstrap.min.css');
}
file_put_contents($target, $content);
}
}
}
closedir($dir);
}

/**
* Copies the site.js and site.css files to the site/ directory, and creates
* a production version of the index.php file.
Expand Down
4 changes: 2 additions & 2 deletions tests/phpunit/modules/core/modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -948,7 +948,7 @@ public function test_header_content() {
public function test_header_css() {
$test = new Output_Test('header_css', 'core');
$res = $test->run();
$this->assertEquals(array('<link href="site.css?v=asdf" media="all" rel="stylesheet" type="text/css" /><style type="text/css">@font-face {font-family:"Behdad";src:url("modules/core/assets/fonts/Behdad/Behdad-Regular.woff2") format("woff2"),url("modules/core/assets/fonts/Behdad/Behdad-Regular.woff") format("woff");</style>'), $res->output_response);
$this->assertEquals(array('<link href="modules/themes/assets/default/css/default.css?v=asdf" media="all" rel="stylesheet" type="text/css" /><link href="site.css?v=asdf" media="all" rel="stylesheet" type="text/css" /><style type="text/css">@font-face {font-family:"Behdad";src:url("modules/core/assets/fonts/Behdad/Behdad-Regular.woff2") format("woff2"),url("modules/core/assets/fonts/Behdad/Behdad-Regular.woff") format("woff");</style>'), $res->output_response);
}
/**
* @preserveGlobalState disabled
Expand All @@ -959,7 +959,7 @@ public function test_header_css_integrity() {
$test = new Output_Test('header_css', 'core');
$test->handler_response = array('router_module_list', array('core'));
$res = $test->run();
$this->assertEquals(array('<link href="site.css?v=asdf" integrity="foo" media="all" rel="stylesheet" type="text/css" /><style type="text/css">@font-face {font-family:"Behdad";src:url("modules/core/assets/fonts/Behdad/Behdad-Regular.woff2") format("woff2"),url("modules/core/assets/fonts/Behdad/Behdad-Regular.woff") format("woff");</style>'), $res->output_response);
$this->assertEquals(array('<link href="modules/themes/assets/default/css/default.css?v=asdf" media="all" rel="stylesheet" type="text/css" /><link href="site.css?v=asdf" integrity="foo" media="all" rel="stylesheet" type="text/css" /><style type="text/css">@font-face {font-family:"Behdad";src:url("modules/core/assets/fonts/Behdad/Behdad-Regular.woff2") format("woff2"),url("modules/core/assets/fonts/Behdad/Behdad-Regular.woff") format("woff");</style>'), $res->output_response);
}
/**
* @preserveGlobalState disabled
Expand Down

0 comments on commit 0ae9f8f

Please sign in to comment.