Skip to content

Commit

Permalink
Merge pull request #895 from josaphatim/fixed-duplicated-call-for-boo…
Browse files Browse the repository at this point in the history
…tstrap-files

Added bootstrap files to optimized css/js files
  • Loading branch information
kroky authored Feb 13, 2024
2 parents eea3c4c + a562026 commit 7748bce
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 24 deletions.
4 changes: 2 additions & 2 deletions modules/2fa/modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ protected function output() {
<body>
<div class="container bg-light">
<div class="row align-items-center justify-content-center vh-100 p-3">
<div class="card col-12 col-md-6 col-lg-4 py-3">
<div class="card col-12 col-md-6 col-lg-4 p-3">
<div class="card-body">
<form class="mt-5" method="POST">
<p class="text-center"><img class="w-50" src="modules/core/assets/images/logo_dark.svg"></p>
Expand All @@ -255,7 +255,7 @@ protected function output() {
<label for="2fa_code">'.$this->trans('Login code').'</label>
</div>
<div class="d-grid">
<input type="submit" class="btn btn-success" value="'.$this->trans('Submit').'">
<input type="submit" class="btn btn-success btn-lg" value="'.$this->trans('Submit').'">
</div>
<input type="hidden" name="hm_page_key" value="'.$this->get('2fa_key').'">
</form>
Expand Down
6 changes: 3 additions & 3 deletions modules/core/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -424,9 +424,9 @@ function setup_base_page($name, $source=false) {
add_handler($name, 'http_headers', true, $source);

add_output($name, 'header_start', false, $source);
add_output($name, 'header_css', true, $source);
add_output($name, 'header_css', false, $source);
add_output($name, 'header_content', false, $source);
add_output($name, 'js_data', true, $source);
add_output($name, 'js_data', false, $source);
add_output($name, 'js_search_data', true, $source);
add_output($name, 'header_end', false, $source);
add_output($name, 'content_start', false, $source);
Expand All @@ -441,7 +441,7 @@ function setup_base_page($name, $source=false) {
add_output($name, 'content_section_start', true, $source);
add_output($name, 'content_section_end', true, $source);
add_output($name, 'save_reminder', true, $source);
add_output($name, 'page_js', true, $source);
add_output($name, 'page_js', false, $source);
add_output($name, 'content_end', false, $source);
}}

Expand Down
18 changes: 8 additions & 10 deletions modules/core/output_modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ protected function output() {
$fancy_login = $this->get('fancy_login_allowed');
if(!$fancy_login){
return '<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 py-3">
<div class="card col-12 col-md-6 col-lg-4 p-3">
<div class="card-body">
<p class="text-center"><img class="w-50" src="'.WEB_ROOT. 'modules/core/assets/images/logo_dark.svg"></p>
<div class="mt-5">
Expand All @@ -248,9 +248,9 @@ protected function output() {
<input required type="password" id="password" placeholder="'.$this->trans('Password').'" name="password" class="form-control">
<label for="password" class="form-label screen-reader">'.$this->trans('Password').'</label>
</div>'.
'<div class="d-flex justify-content-between align-items-center">'.$stay_logged_in.
'<div class="d-grid">'.$stay_logged_in.
'<input type="hidden" name="hm_page_key" value="'.Hm_Request_Key::generate().'" />
<input type="submit" id="login" class="btn btn-success btn-block px-5" value="'.$this->trans('Login').'">
<input type="submit" id="login" class="btn btn-success btn-lg" value="'.$this->trans('Login').'">
</div>
</div>
</div>
Expand Down Expand Up @@ -401,10 +401,7 @@ protected function output() {
'<meta name="apple-mobile-web-app-capable" content="yes" />'.
'<meta name="mobile-web-app-capable" content="yes" />'.
'<meta name="apple-mobile-web-app-status-bar-style" content="black" />'.
'<meta name="theme-color" content="#888888" /><meta charset="utf-8" />'.
'<link href="vendor/twbs/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet" type="text/css" />'.
'<link href="vendor/twbs/bootstrap-icons/font/bootstrap-icons.css" rel="stylesheet" type="text/css" />'.
'<script src="vendor/twbs/bootstrap/dist/js/bootstrap.bundle.min.js"></script>';
'<meta name="theme-color" content="#888888" /><meta charset="utf-8" />';

if ($this->get('router_login_state')) {
$res .= '<meta name="referrer" content="no-referrer" />';
Expand Down Expand Up @@ -506,10 +503,10 @@ class Hm_Output_header_css extends Hm_Output_Module {
*/
protected function output() {
$res = '';
$res .= '<link href="vendor/twbs/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet" type="text/css" />';
$res .= '<link href="vendor/twbs/bootstrap-icons/font/bootstrap-icons.css" rel="stylesheet" type="text/css" />';
$mods = $this->get('router_module_list');
if (DEBUG_MODE) {
$res .= '<link href="vendor/twbs/bootstrap/dist/css/bootstrap.min.css" 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/**', GLOB_ONLYDIR | GLOB_MARK) as $name) {
$rel_name = str_replace(APP_PATH, '', $name);
$mod = str_replace(array('modules/', '/'), '', $rel_name);
Expand Down Expand Up @@ -544,7 +541,8 @@ class Hm_Output_page_js extends Hm_Output_Module {
protected function output() {
if (DEBUG_MODE) {
$res = '';
$js_lib = '<script type="text/javascript" src="vendor/twbs/bootstrap/dist/js/bootstrap.min.js"></script>';
$js_lib = '<script type="text/javascript" src="vendor/twbs/bootstrap/dist/js/bootstrap.bundle.min.js"></script>';
$js_lib .= '<script type="text/javascript" src="vendor/twbs/bootstrap/dist/js/bootstrap.min.js"></script>';
$js_lib .= '<script type="text/javascript" src="third_party/cash.min.js"></script>';
$js_lib .= '<script type="text/javascript" src="third_party/resumable.min.js"></script>';
$js_lib .= '<script type="text/javascript" src="third_party/tingle.min.js"></script>';
Expand Down
5 changes: 1 addition & 4 deletions modules/core/site.css
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,8 @@ td { vertical-align: top; }
.disabled_input, input:disabled { color: #aaa !important; background-color: #ddd; }
input, option, select, button { font-size: 100%; padding: 3px; }
textarea, select, input, button { border: solid 1px #ddd; background-color: #fff; color: #333; border-radius: 3px; }
.login_form { float: left; font-size: 90%; padding-top: 60px; height: 300px; border-radius: 0px 0px 10px 0px; margin: 0px; background-color: #f5f5f5; width: 300px; padding-left: 20px; }

.screen_reader { position:absolute; top:auto; width:1px; height:1px; overflow:hidden; }
.login_form input { clear: both; float: left; padding: 4px; margin-left: 20px; margin-top: 10px; margin-bottom: 10px; }
#username, #password { width: 200px; }
.err { color: red !important; }
.debug { color: teal; font-size: 75%; float: right; clear: both; margin: 20px; }
.inner_list a { padding-right: 5px; }
Expand Down Expand Up @@ -260,7 +258,6 @@ div.unseen, .unseen .subject { font-weight: 700; }
.mobile .checkbox_cell { width: 35px; }
.mobile .checkbox_cell label { width: 30px; height: 30px; }
.mobile .github_para { white-space: normal !important; }
.mobile .login_form { margin-top: 60px; display: block; float: none; width: 100%; background-color: #fff; font-size: 130%; height: auto; }
.mobile .account_icon { width: 20px; height: 20px; }
.mobile .imap_filter { display: none; }
.mobile .list_controls { color: #777; background: linear-gradient(180deg, #fff, #fff, #f7f2ef); height: 48px; padding-left: 5px; padding-right: 5px; }
Expand Down
28 changes: 26 additions & 2 deletions scripts/config_gen.php
Original file line number Diff line number Diff line change
Expand Up @@ -229,14 +229,18 @@ function combine_includes($js, $js_compress, $css, $css_compress, $settings) {
$js_hash = '';
$css_hash = '';
if ($css) {
$css_out = compress($css, $css_compress);
$css_out = file_get_contents("vendor/twbs/bootstrap/dist/css/bootstrap.min.css");
$css_out .= file_get_contents("vendor/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);
printf("site.css file created\n");
}
if ($js) {
$mods = get_modules($settings);
$js_lib = file_get_contents("third_party/cash.min.js");
$js_lib = file_get_contents("vendor/twbs/bootstrap/dist/js/bootstrap.bundle.min.js") . "\n\n";
$js_lib .= file_get_contents("vendor/twbs/bootstrap/dist/js/bootstrap.min.js") . "\n\n";
$js_lib .= file_get_contents("third_party/cash.min.js");
if (in_array('sievefilters', $mods, true)) {
$js_lib .= file_get_contents("third_party/tingle.min.js");
}
Expand Down Expand Up @@ -290,6 +294,24 @@ function write_config_file($settings, $filters) {
printf("dynamic.php file written\n");
}

/**
* Copies bootstrap icons fonts folder as it is
* referenced and needed by bootstrap icons css file
*
* @return void
*/
function append_bootstrap_icons_files() {
if (!is_dir("site/fonts")) {
mkdir('site/fonts', 0755);
}
$source_folder = 'vendor/twbs/bootstrap-icons/font/fonts/';
$files = glob("$source_folder*.*");
foreach($files as $file){
$dest_forlder = str_replace($source_folder, "site/fonts/", $file);
copy($file, $dest_forlder);
}
}

/**
* Copies the site.js and site.css files to the site/ directory, and creates
* a production version of the index.php file.
Expand All @@ -303,6 +325,8 @@ function create_production_site($assets, $settings, $hashes) {
printf("creating production site\n");
copy('site.css', 'site/site.css');
copy('site.js', 'site/site.js');
append_bootstrap_icons_files();

$index_file = file_get_contents('index.php');
$index_file = preg_replace("/APP_PATH', ''/", "APP_PATH', '".APP_PATH."'", $index_file);
$index_file = preg_replace("/CACHE_ID', ''/", "CACHE_ID', '".urlencode(Hm_Crypt::unique_id(32))."'", $index_file);
Expand Down
6 changes: 3 additions & 3 deletions tests/phpunit/modules/core/modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -774,7 +774,7 @@ public function test_msgs() {
public function test_header_start() {
$test = new Output_Test('header_start', 'core');
$res = $test->run();
$this->assertEquals(array('<!DOCTYPE html><html dir="ltr" class="ltr_page" lang=en><head><meta name="apple-mobile-web-app-capable" content="yes" /><meta name="mobile-web-app-capable" content="yes" /><meta name="apple-mobile-web-app-status-bar-style" content="black" /><meta name="theme-color" content="#888888" /><meta charset="utf-8" /><link href="vendor/twbs/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet" type="text/css" /><link href="vendor/twbs/bootstrap-icons/font/bootstrap-icons.css" rel="stylesheet" type="text/css" /><script src="vendor/twbs/bootstrap/dist/js/bootstrap.bundle.min.js"></script>'), $res->output_response);
$this->assertEquals(array('<!DOCTYPE html><html dir="ltr" class="ltr_page" lang=en><head><meta name="apple-mobile-web-app-capable" content="yes" /><meta name="mobile-web-app-capable" content="yes" /><meta name="apple-mobile-web-app-status-bar-style" content="black" /><meta name="theme-color" content="#888888" /><meta charset="utf-8" />'), $res->output_response);
}
/**
* @preserveGlobalState disabled
Expand Down Expand Up @@ -1530,10 +1530,10 @@ public function test_page_js_debug() {
$test = new Output_Test('page_js', 'core');
$test->handler_response = array('encrypt_ajax_requests' => true, 'router_module_list' => array('foo', 'core'));
$res = $test->run();
$this->assertEquals(array('<script type="text/javascript" src="vendor/twbs/bootstrap/dist/js/bootstrap.min.js"></script><script type="text/javascript" src="third_party/cash.min.js"></script><script type="text/javascript" src="third_party/resumable.min.js"></script><script type="text/javascript" src="third_party/tingle.min.js"></script><script type="text/javascript" src="third_party/ays-beforeunload-shim.js"></script><script type="text/javascript" src="third_party/jquery.are-you-sure.js"></script><script type="text/javascript" src="third_party/sortable.min.js"></script><script type="text/javascript" src="third_party/forge.min.js"></script><script type="text/javascript" src="modules/core/site.js"></script>'), $res->output_response);
$this->assertEquals(array('<script type="text/javascript" src="vendor/twbs/bootstrap/dist/js/bootstrap.bundle.min.js"></script><script type="text/javascript" src="vendor/twbs/bootstrap/dist/js/bootstrap.min.js"></script><script type="text/javascript" src="third_party/cash.min.js"></script><script type="text/javascript" src="third_party/resumable.min.js"></script><script type="text/javascript" src="third_party/tingle.min.js"></script><script type="text/javascript" src="third_party/ays-beforeunload-shim.js"></script><script type="text/javascript" src="third_party/jquery.are-you-sure.js"></script><script type="text/javascript" src="third_party/sortable.min.js"></script><script type="text/javascript" src="third_party/forge.min.js"></script><script type="text/javascript" src="modules/core/site.js"></script>'), $res->output_response);
$test->handler_response = array('encrypt_ajax_requests' => true, 'router_module_list' => array('imap'));
$res = $test->run();
$this->assertEquals(array('<script type="text/javascript" src="vendor/twbs/bootstrap/dist/js/bootstrap.min.js"></script><script type="text/javascript" src="third_party/cash.min.js"></script><script type="text/javascript" src="third_party/resumable.min.js"></script><script type="text/javascript" src="third_party/tingle.min.js"></script><script type="text/javascript" src="third_party/ays-beforeunload-shim.js"></script><script type="text/javascript" src="third_party/jquery.are-you-sure.js"></script><script type="text/javascript" src="third_party/sortable.min.js"></script><script type="text/javascript" src="third_party/forge.min.js"></script><script type="text/javascript" src="modules/core/site.js"></script><script type="text/javascript" src="modules/imap/site.js"></script>'), $res->output_response);
$this->assertEquals(array('<script type="text/javascript" src="vendor/twbs/bootstrap/dist/js/bootstrap.bundle.min.js"></script><script type="text/javascript" src="vendor/twbs/bootstrap/dist/js/bootstrap.min.js"></script><script type="text/javascript" src="third_party/cash.min.js"></script><script type="text/javascript" src="third_party/resumable.min.js"></script><script type="text/javascript" src="third_party/tingle.min.js"></script><script type="text/javascript" src="third_party/ays-beforeunload-shim.js"></script><script type="text/javascript" src="third_party/jquery.are-you-sure.js"></script><script type="text/javascript" src="third_party/sortable.min.js"></script><script type="text/javascript" src="third_party/forge.min.js"></script><script type="text/javascript" src="modules/core/site.js"></script><script type="text/javascript" src="modules/imap/site.js"></script>'), $res->output_response);
}
/**
* @preserveGlobalState disabled
Expand Down

0 comments on commit 7748bce

Please sign in to comment.