Skip to content

Commit

Permalink
rework / standardize function print_header a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
bbannon committed Jun 18, 2024
1 parent d1eca7b commit 3c39b14
Show file tree
Hide file tree
Showing 33 changed files with 74 additions and 101 deletions.
6 changes: 3 additions & 3 deletions about.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
$replacements[] = '';
$data = preg_replace ( $patterns, $replacements, $data );
}
print_header ( [], '<link href="includes/css/about.css" rel="stylesheet">',
'', true, false, true );
echo ' <div id="creds">'
print_header ( ['css/about.css'], '', '', true, false, true );
echo '
<div id="creds">'
. ( empty ( $credits ) ? '
<a href="' . $PROGRAM_URL
. '" target="_blank" title="' . $PROGRAM_NAME . '">
Expand Down
7 changes: 2 additions & 5 deletions access.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,8 @@
}
}
}
print_header( '',
'<script src="includes/js/access.js?'
. filemtime( 'includes/js/access.js' ) . '"></script>
<link href="includes/css/access.css?'
. filemtime( 'includes/css/access.css' ) . '" rel="stylesheet">',

print_header ( ['css/access.css', 'js/access.js'], '',
( ! empty( $op['time'] ) && $op['time'] == 'Y'
? 'onload="enableAll( true );"' : '' ) );

Expand Down
13 changes: 1 addition & 12 deletions adminhome.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,18 +149,7 @@

$_SESSION['webcal_tmp_login'] = 'SheIsA1Fine!';

print_header( '',
/*
'<style>
#adminhome table,
#adminhome td a {
background:' . $CELLBG . '
}
</style>
If this is the proper way to call css_cacher.php from here?
*/
'<link href="css_cacher.php" rel="stylesheet">
<link href="includes/css/styles.css" rel="stylesheet">' );
print_header();

echo '
<h2>' . translate( 'Administrative Tools' ) . '</h2>
Expand Down
3 changes: 1 addition & 2 deletions assistant_edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
if ( $user != $login )
$user = ( ( $is_admin || $is_nonuser_admin ) && $user ) ? $user : $login;

print_header( '', ! $GROUPS_ENABLED == 'Y' ? '' :
'<script src="includes/js/assistant_edit.js"></script>' );
print_header ( $GROUPS_ENABLED !== 'Y' ? [] : ['js/assistant_edit.js'] );
echo '
<form action="assistant_edit_handler.php" method="post" '
. 'name="assistanteditform">' . csrf_form_key() . ( $user ? '
Expand Down
5 changes: 2 additions & 3 deletions catsel.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@
if ( strlen ( $entryCatStr ) < 30 )
$entryCatStr = $entryCatFiller . $entryCatStr . $entryCatFiller;

print_header ( ['js/catsel.php/false/' . $form],
'<script type=text/javascript" src="includes/js/catsel.js"></script>',
'', true, false, true );
print_header ( ['js/catsel.php/false/' . $form, 'js/catsel.js'],
'', '', true, false, true );
echo '
<table class="aligncenter" width="90%">
<tr>
Expand Down
2 changes: 1 addition & 1 deletion day.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
$eventinfo = ( empty ( $eventinfo ) ? '' : $eventinfo );
$trailerStr = print_trailer();
print_header ( ['js/popups.js/true', 'js/dblclick_add.js/true'],
generate_refresh_meta(), '', false, false, false, false );
generate_refresh_meta() );

echo <<<EOT
Expand Down
2 changes: 1 addition & 1 deletion edit_entry.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ function time_selection($prefix, $time = '', $trigger = false)
$real_user = ((!empty($user) && strlen($user)) &&
($is_assistant || $is_admin)) ? $user : $login;

print_header($INC, $HEAD, $BodyX);
print_header ( $INC, $HEAD, $BodyX );

if ($readonly == 'Y' || $is_nonuser)
$can_edit = false;
Expand Down
2 changes: 1 addition & 1 deletion edit_remotes_handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ function_exists ( 'simplexml_load_string' ) ) {
$errorStr = '<br><br>
<b>' . translate ( 'Error' ) . ':</b> ';

print_header ( '', '', '', true, false, true );
print_header ( [], '', '', true, false, true );
if ( count ( $data ) && empty ( $errormsg ) ) {
// Delete existing events.
delete_events ( $nid );
Expand Down
2 changes: 1 addition & 1 deletion edit_template.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
}
}

print_header ( '', '', '', true );
print_header ( [], '', '', true );
/*
echo 'report_id: ' . $report_id . '<br>
report_name: ' . $report_name . '<br>
Expand Down
2 changes: 1 addition & 1 deletion export.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
$dateYearAgo = date('Ymd', $yearAgo);
$selected = ' selected ';

print_header('', '', 'onload="updateDateFields();"' );
print_header ( [], '', 'onload="updateDateFields();"' );
echo '<h2>' . translate ( 'Export' ) . '</h2>
<form action="export_handler.php" method="post" name="exportform" id="exportform">';
echo csrf_form_key();
Expand Down
8 changes: 2 additions & 6 deletions groups.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,7 @@
$noNameError = translate('Group Name cannot be blank.');
$noUsersSelectedError = translate('You must selected one or more users.');

print_header(
'',
'',
'onload="load_groups();"'
);
print_header ( [], '', 'onload="load_groups();"' );

?>
<h2><?php etranslate('Groups'); ?></h2>
Expand Down Expand Up @@ -282,7 +278,7 @@ function save_handler() {

var selectedUsers = $('#editUsers').val();
if (! selectedUsers || selectedUsers.length == 0) {
$('#errorMessage').html('<?php echo $noUsersSelectedError; ?>');
$('#errorMessage').html('<?php echo $noUsersSelectedError; ?>');
$('#edit-group-dialog-alert').show();
return;
}
Expand Down
2 changes: 1 addition & 1 deletion help_admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
require_once 'includes/init.php';
require_once 'includes/help_list.php';

print_header ( '', '', '', true );
print_header ( [], '', '', true );
echo $helpListStr . '
<h2>' . translate ( 'Help' ) . ': ' . translate ( 'System Settings' )
. '</h2>
Expand Down
2 changes: 1 addition & 1 deletion help_bug.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
if ( empty ( $HTTP_USER_AGENT ) )
$HTTP_USER_AGENT = $_SERVER['HTTP_USER_AGENT'];

print_header ( '', '', '', true );
print_header ( [], '', '', true );
echo $helpListStr . '
<h2>' . translate ( 'Report Bug' ) . '</h2>
<p>' .
Expand Down
2 changes: 1 addition & 1 deletion help_docs.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
if ( empty ( $HTTP_USER_AGENT ) )
$HTTP_USER_AGENT = $_SERVER['HTTP_USER_AGENT'];

print_header ( '', '', '', true );
print_header ( [], '', '', true );

echo $helpListStr . '
<h2>' . translate ( 'WebCalendar Documentation' ) . '</h2>
Expand Down
2 changes: 1 addition & 1 deletion help_edit_entry.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
require_once 'includes/init.php';
require_once 'includes/help_list.php';

print_header ( '', '', '', true );
print_header ( [], '', '', true );
echo $helpListStr . '
<h2>' . translate ( 'Help' ) . ': '
. translate ( 'Adding/Editing Calendar Entries' ) . '</h2>';
Expand Down
2 changes: 1 addition & 1 deletion help_import.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
require_once 'includes/init.php';
require_once 'includes/help_list.php';

print_header ( '', '', '', true );
print_header ( [], '', '', true );
echo $helpListStr . '
<h2>' . translate ( 'Help' ) . ': ' . translate ( 'Import' ) . '</h2>
<h3>' . translate ( 'Palm Desktop' ) . '</h3>
Expand Down
2 changes: 1 addition & 1 deletion help_index.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
require_once 'includes/init.php';
require_once 'includes/help_list.php';
print_header ( '', '', '', true );
print_header ( [], '', '', true );
echo '
<h2>' . translate ( 'Help Index' ) . '</h2>
<ul>';
Expand Down
2 changes: 1 addition & 1 deletion help_layers.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
require_once 'includes/init.php';
require_once 'includes/help_list.php';
print_header ( '', '', '', true );
print_header ( [], '', '', true );
echo $helpListStr . '
<h2>' . translate ( 'Help' ) . ': ' . translate ( 'Layers' ) . '</h2>
<p>' .
Expand Down
2 changes: 1 addition & 1 deletion help_pref.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
require_once 'includes/init.php';
require_once 'includes/help_list.php';

print_header ( '', '', '', true );
print_header ( [], '', '', true );
echo $helpListStr . '
<h2>' . translate ( 'Help' ) . ': ' . translate ( 'Preferences' ) . '</h2>
<h3>' . translate ( 'Settings' ) . '</h3>
Expand Down
2 changes: 1 addition & 1 deletion help_uac.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
$descStr =
translate ( 'Allows for fine control of user access and permissions. Users can also grant default and per individual permission if authorized by the administrator.' );

print_header ( '', '', '', true, false, true );
print_header ( [], '', '', true, false, true );
echo $helpListStr . '
<div class="helpbody">
<h2>' . translate ( 'Help' ) . ': '
Expand Down
8 changes: 4 additions & 4 deletions includes/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -1758,7 +1758,7 @@ function error_check ( $nextURL, $redirect = true ) {

$ret = '';
if ( ! empty ( $error ) ) {
print_header ( '', '', '', true );
print_header ( [], '', '', true );
$ret .= '
<h2>' . print_error ( $error ) . '</h2>';
} else {
Expand Down Expand Up @@ -2581,9 +2581,9 @@ function get_groups($user, $includeUserlist=false)
$res = dbi_execute($sql, [$groups[$i]['cal_group_id']]);
while ($row = dbi_fetch_row($res)) {
if (isset($users_by_name[$row[0]])){
// It is possible some users assigned to this group may not exist,
// so we skip those that don't. For example, if users are fetched
// from an external source via user-app-*.php, and one of those
// It is possible some users assigned to this group may not exist,
// so we skip those that don't. For example, if users are fetched
// from an external source via user-app-*.php, and one of those
// users is deleted externally.
$users[] = $users_by_name[$row[0]];
}
Expand Down
43 changes: 25 additions & 18 deletions includes/init.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ function send_http_headers () {
* @param bool $IGNORED Parameter not used (ignored)
* @param bool $disableUTIL Do not include the util.js link
*/
function print_header( $includes = '', $HeadX = '', $BodyX = '',
function print_header ( $includes = '', $HeadX = '', $BodyX = '',
$disableCustom = false, $disableStyle = false, $disableRSS = false,
$IGNORED = false, $disableUTIL = false ) {
global $BGCOLOR, $browser, $charset, $CSP, $CUSTOM_HEADER, $CUSTOM_SCRIPT,
Expand All @@ -165,6 +165,8 @@ function print_header( $includes = '', $HeadX = '', $BodyX = '',
$self, $TABLECELLFG, $TEXTCOLOR, $THBG, $THFG, $TODAYCELLBG, $WEEKENDBG,
$ASSETS;

$id = '';

ob_start ();

if ( is_dir ( 'includes' ) ) {
Expand Down Expand Up @@ -218,9 +220,8 @@ function print_header( $includes = '', $HeadX = '', $BodyX = '',

if( ! empty( $js_ar ) )
foreach( $js_ar as $j ) {
$i = 'includes/' . $j;
$ret .= '
<script src="' . $i . '"></script>';
<script src="includes/' . $j . '" defer></script>';
}

// Any other includes?
Expand All @@ -231,11 +232,10 @@ function print_header( $includes = '', $HeadX = '', $BodyX = '',
// Ignore since we handled it above
//$cs_ret .= '<!-- JQUERY INCLUDED -->' . "\n";
} if( stristr( $inc, '.css' ) ) {
$i = 'includes/' . $inc;
// Not added to $cs_ar because I think we want these,
// even if $disableStyle.
$cs_ret .= '
<link href="' . $i . '" rel="stylesheet">';
<link href="includes/' . $inc . '" rel="stylesheet">';
} elseif( substr( $inc, 0, 12 ) == 'js/popups.js'
&& ! empty( $DISABLE_POPUPS ) && $DISABLE_POPUPS == 'Y' ) {
// Don't load popups.js if DISABLE_POPUPS.
Expand All @@ -256,7 +256,7 @@ function print_header( $includes = '', $HeadX = '', $BodyX = '',
} else {
$ret .= 'js_cacher.php?inc=' . $inc;
}
$ret .= '"></script>';
$ret .= '" defer></script>';
}
}
}
Expand Down Expand Up @@ -325,21 +325,28 @@ function print_header( $includes = '', $HeadX = '', $BodyX = '',
. '" rel="alternate" title="' . $appStr . ' [RSS 2.0]">' : '' )
// Do we need anything else inside the header tag?
// $HeadX moved here because linked CSS may override standard styles.
. ( $HeadX ? '
' . $HeadX : '' ) . '
. "
$HeadX" . '
<link type="image/x-icon" href="favicon.ico?'
. filemtime( 'favicon.ico' ) . '" rel="shortcut icon">
</head>
<body'
// Determine the page direction (left-to-right or right-to-left).
. ( translate( 'direction' ) == 'rtl' ? ' dir="rtl"' : '' )
/* Add <body> id. */ . ' id="' . preg_replace( '/(_|.php)/', '',
substr( $self, strrpos( $self, '/' ) + 1 ) ) . '"'
// Add any extra parts to the <body> tag.
. ( empty( $BodyX ) ? '' : " $BodyX" ) . '>' . "\n"
// Add custom header if enabled.
. ( $CUSTOM_HEADER == 'Y' && ! $disableCustom
? load_template( $login, 'H' ) : '' );
<body id="';

$id = preg_replace ( '/.php/', '',
substr ( $self, strrpos ( $self, '/' ) + 1 ) );
$id_ar = explode ( '_', $id );

// classes and ids are supposed to be UpperCamelCase, per Developer Guide
$id = array_map ( 'ucfirst', $id_ar );

echo implode ( '', $id ) .
( translate ( 'direction' ) === 'rtl' ? '" dir="rtl"' : '"' )
// Add any extra parts to the <body> tag.
. " $BodyX>\n"
// Add custom header if enabled.
. ( $CUSTOM_HEADER === 'Y' && ! $disableCustom
? load_template ( $login, 'H' ) : '' );

// HTML includes needed for the top menu.
if( $MENU_ENABLED == 'Y' ) {
require_once 'menu.php';
Expand Down
2 changes: 1 addition & 1 deletion minical.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
$enddate = mktime ( 23, 59, 59, $thismonth + 1, 0, $thisyear );

// Don't display custom header.
print_header ( '', generate_refresh_meta(), '', true );
print_header ( [], generate_refresh_meta(), '', true );

/* Pre-Load the repeated events for quicker access. */
$repeated_events = read_repeated_events ( $user, $startdate, $enddate, $cat_id );
Expand Down
6 changes: 3 additions & 3 deletions pref.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ function save_pref( $prefs, $src) {
$openStr ="\"window.open( 'edit_template.php?type=%s&user=%s','cal_template','dependent,menubar,scrollbars,height=500,width=500,outerHeight=520,outerWidth=520' );\"";

$INC = [];
print_header($INC, '', '');
print_header();
?>

<h2><?php
Expand Down Expand Up @@ -400,7 +400,7 @@ function save_pref( $prefs, $src) {
$prefarray['DEFAULT_VISIBILITY'] == 'R') {
echo " selected ";
}
echo ">" . translate('Private');
echo ">" . translate('Private');
?> </option>
<option value="C"
<?php if (isset($prefarray['DEFAULT_VISIBILITY']) &&
Expand Down Expand Up @@ -805,7 +805,7 @@ function save_pref( $prefs, $src) {
'rss.php?user=' . ( $updating_public ? '__public__' : $user );
?></td></tr>
<tr><td height="0.5 em"><!-- small vertical spacing--><span style="font-size: 25%">&nbsp;</span> </td></tr>
<?php
<?php
} /* $RSS_ENABLED */ ?>

<tr><td data-toggle="tooltip" data-placement="top" title="<?php etooltip ("freebusy-enabled-help");?>">
Expand Down
10 changes: 3 additions & 7 deletions remotecal_mgmt.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,7 @@
$duplicatesStr = translate('Duplicates');


print_header(
'',
'',
'onload="load_users();"'
);
print_header ( [], '', 'onload="load_users();"' );

?>

Expand Down Expand Up @@ -503,7 +499,7 @@ function save_handler() {
var add = $('#editUserAdd').val();
if (add == "1") {
if (login.length == 0) {
$('#errorMessage').html('<?php echo $noLoginError; ?>');
$('#errorMessage').html('<?php echo $noLoginError; ?>');
$('#edit-user-dialog-alert').show();
return;
}
Expand Down Expand Up @@ -534,7 +530,7 @@ function save_handler() {

var url = $('#editURL').val();
if (url.length == 0) {
//$('#errorMessage').html('<?php echo $noUrlError; ?>');
//$('#errorMessage').html('<?php echo $noUrlError; ?>');
$('#invalid-url-error').show();
//$('#edit-user-dialog-alert').show();
foundError = true;
Expand Down
Loading

0 comments on commit 3c39b14

Please sign in to comment.