Skip to content

Commit

Permalink
Allow users to choose the font family
Browse files Browse the repository at this point in the history
Fixes #23758
  • Loading branch information
syncguru authored and vboctor committed Jan 14, 2018
1 parent 98c2b8f commit 1906e4d
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 1 deletion.
10 changes: 10 additions & 0 deletions account_prefs_inc.php
Expand Up @@ -383,6 +383,16 @@ function edit_account_prefs( $p_user_id = null, $p_error_if_protected = true, $p
</select>
</td>
</tr>
<tr>
<td class="category">
<?php echo lang_get( 'font_family' ) ?>
</td>
<td>
<select id="font_family" name="font_family" class="input-sm">
<?php print_font_option_list( config_get( 'font_family' ) ) ?>
</select>
</td>
</tr>
<?php event_signal( 'EVENT_ACCOUNT_PREF_UPDATE_FORM', array( $p_user_id ) ); ?>
</table>
</div>
Expand Down
3 changes: 3 additions & 0 deletions account_prefs_update.php
Expand Up @@ -84,6 +84,9 @@
$t_prefs->language = $t_lang;
}

$t_font = gpc_get_string( 'font_family' );
config_set ( 'font_family', $t_font, $f_user_id );

$t_prefs->email_on_new = gpc_get_bool( 'email_on_new' );
$t_prefs->email_on_assigned = gpc_get_bool( 'email_on_assigned' );
$t_prefs->email_on_feedback = gpc_get_bool( 'email_on_feedback' );
Expand Down
42 changes: 42 additions & 0 deletions config_defaults_inc.php
Expand Up @@ -942,6 +942,48 @@
*/
$g_fallback_language = 'english';

##########################
# MantisBT Font Settings #
##########################

/**
* Name of one of google fonts available at https://fonts.google.com/
* 'Open Sans' font files are part of MantisBT code. Selecting any other font will work if download from CDN
* option is enabled.
* @global string $g_font_family
*/
$g_font_family = 'Open Sans';

/**
* List the google fonts that the users are allowed to choose from.
* Google offers over 800 fonts. The list below is limited to the ones tested on MantisBT UI
* @global array $g_font_choices_arr
*/
$g_font_choices_arr = array(
'Architects Daughter',
'Archivo Narrow',
'Arvo',
'Bitter',
'Cabin',
'Cinzel',
'Comfortaa',
'Courgette',
'Droid Sans',
'Gloria Hallelujah',
'Inconsolata',
'Josefin Sans',
'Karla',
'Kaushan Script',
'Lato',
'Montserrat',
'Open Sans',
'Orbitron',
'Poppins',
'Raleway',
'Ubuntu',
'Vollkorn'
);

#############################
# MantisBT Display Settings #
#############################
Expand Down
19 changes: 18 additions & 1 deletion core/layout_api.php
Expand Up @@ -131,6 +131,9 @@ function layout_page_header_end( $p_page_id = null) {
echo '<body ' . $t_body_id . 'class="skin-3">', "\n";
}

# Set user font preference
layout_user_font_preference();

event_signal( 'EVENT_LAYOUT_BODY_BEGIN' );

$g_error_send_page_header = false;
Expand Down Expand Up @@ -256,7 +259,7 @@ function layout_head_css() {
html_css_cdn_link( 'https://maxcdn.bootstrapcdn.com/font-awesome/' . FONT_AWESOME_VERSION . '/css/font-awesome.min.css' );

# theme text fonts
html_css_cdn_link( 'https://fonts.googleapis.com/css?family=Open+Sans:300,400' );
html_css_cdn_link( 'https://fonts.googleapis.com/css?family=' . urlencode( config_get( 'font_family' ) ) . ':300,400' );

# datetimepicker
html_css_cdn_link( 'https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/' . DATETIME_PICKER_VERSION . '/css/bootstrap-datetimepicker.min.css' );
Expand Down Expand Up @@ -285,6 +288,16 @@ function layout_head_css() {
echo "\n";
}

/**
* Print user font preference
* @return void
*/
function layout_user_font_preference() {
echo '<style>', "\n";
echo '* { font-family: "' , config_get( 'font_family' ) , '"; } ', "\n";
echo 'h1, h2, h3, h4, h5 { font-family: "' , config_get( 'font_family' ) , '"; } ', "\n";
echo '</style>', "\n";
}

/**
* Print javascript directives before the closing of the page body element
Expand Down Expand Up @@ -359,6 +372,10 @@ function layout_login_page_begin() {
html_head_end();

echo '<body class="login-layout light-login">';

# Set font preference
layout_user_font_preference();

layout_main_container_begin();
layout_main_content_begin();
echo '<div class="row">';
Expand Down
16 changes: 16 additions & 0 deletions core/print_api.php
Expand Up @@ -1107,6 +1107,22 @@ function print_language_option_list( $p_language ) {
}
}

/**
* Print option list of available font choices
* @param string $p_font The current font.
* @return void
*/
function print_font_option_list( $p_font ) {
$t_arr = config_get( 'font_choices_arr' );
$t_enum_count = count( $t_arr );
for( $i = 0;$i < $t_enum_count;$i++ ) {
$t_font = string_attribute( $t_arr[$i] );
echo '<option value="' . $t_font . '"';
check_selected( $t_font, $p_font );
echo '>' . $t_font . '</option>';
}
}

/**
* Print a dropdown list of all bug actions available to a user for a specified
* set of projects.
Expand Down
10 changes: 10 additions & 0 deletions docbook/Admin_Guide/en-US/config/display.xml
Expand Up @@ -6,6 +6,16 @@
<title>Display</title>

<variablelist>
<varlistentry>
<term>$g_font_family</term>
<listitem>
<para>Name of the google font family for the browser to use. For all available fonts, see:
<ulink url="https://fonts.google.com/">
fonts.google.com
</ulink>.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>$g_window_title</term>
<listitem>
Expand Down
1 change: 1 addition & 0 deletions lang/strings_english.txt
Expand Up @@ -407,6 +407,7 @@ $s_email_on_priority_change = 'E-mail on Priority Change';
$s_email_bugnote_limit = 'E-mail Notes Limit';
$s_email_full_issue_details = 'E-mail Full Issue Details';
$s_language = 'Language';
$s_font_family = 'Font Family';
$s_update_prefs_button = 'Update Prefs';
$s_reset_prefs_button = 'Reset Prefs';
$s_timezone = 'Time Zone';
Expand Down

0 comments on commit 1906e4d

Please sign in to comment.