Skip to content

Commit

Permalink
PHP 8 fixes, export bug fix, upgrade PHP Unit version
Browse files Browse the repository at this point in the history
- Upgraded PHP Unit to 9.6.15
- Fixed the "Export All" checkbox on the export page
- Various PHP 8 fixes to avoid warnings
- Changes to how event UID is generated for iCal exports
- Added button in installer to view PHP details (version, modules, etc.)
- Improvements to how server base URL is determined
  • Loading branch information
craigk5n committed Dec 7, 2023
1 parent 1ad524c commit b8575e9
Show file tree
Hide file tree
Showing 14 changed files with 144 additions and 85 deletions.
24 changes: 12 additions & 12 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions export.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@
function updateDateFields () {
var displayAll = $('#exportall')[0].checked;
if (displayAll) {
$('#dateArea').show();
} else {
$('#dateArea').hide();
} else {
$('#dateArea').show();
}
}

Expand Down
12 changes: 7 additions & 5 deletions export_handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,19 +217,19 @@ function transmit_header( $mime, $file ) {
die_miserable_death ( 'Invalid format "' . htmlspecialchars($format) . '"' );
$id = getValue ( 'id', '-?[0-9]+', true );

$use_all_dates = getPostValue ( 'use_all_dates' );
$use_all_dates = getPostValue ( 'use_all_dates', '' );
if ( strtolower ( $use_all_dates ) != 'y' )
$use_all_dates = '';

$include_layers = getPostValue ( 'include_layers' );
$include_layers = getPostValue ( 'include_layers', '' );
if ( strtolower ( $include_layers ) != 'y' )
$include_layers = '';

$include_deleted = getPostValue ( 'include_deleted' );
$include_deleted = getPostValue ( 'include_deleted', '' );
if ( strtolower ( $include_deleted ) != 'y' )
$include_deleted = '';

$cat_filter = getPostValue ( 'cat_filter' );
$cat_filter = getPostValue ( 'cat_filter', '' );
if ( $cat_filter == 0 )
$cat_filter = '';

Expand All @@ -247,11 +247,13 @@ function transmit_header( $mime, $file ) {
$enddate = sprintf ( "%04d%02d%02d", $endyear, $endmonth, $endday );
$moddate = sprintf ( "%04d%02d%02d", $modyear, $modmonth, $modday );

mt_srand ( ( float ) microtime() * 1000000 );
mt_srand(time());

if ( empty ( $id ) )
$id = 'all';

load_global_settings(); // Need server URL

$outputName = 'webcalendar-' . "$login-$id";
if ( substr ( $format, 0, 4 ) == 'ical' ) {
transmit_header ( 'text/calendar', $outputName . '.ics' );
Expand Down
31 changes: 31 additions & 0 deletions includes/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -3951,6 +3951,37 @@ function isLeapYear(int $year = null): bool {
return ($year % 4 == 0 && $year % 100 != 0) || $year % 400 == 0;
}


function getServerUrl($checkDatabase = true): string
{
global $SERVER_URL, $HTTP_HOST, $REQUEST_URI;
$ret = null;

if (false&&$checkDatabase) {
$rows = dbi_get_cached_rows('SELECT cal_value FROM webcal_config WHERE cal_setting = ?', ['SERVER_URL']);
if (!empty($rows) && !empty($rows[0]) && !empty($rows[0][0])) {
$ret = $rows[0][0];
}
}
// Calculate it.
if (empty($ret))
$ret = determineServerUrl();
$ret = rtrim($ret, '/');
return $ret . '/';
}

function determineServerUrl(): string
{
$protocol = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on') ? 'https' : 'http';
$host = $_SERVER['HTTP_HOST'];
$port = $_SERVER['SERVER_PORT'];
$folder = dirname($_SERVER['SCRIPT_NAME']);
$url = $protocol . '://'. $host . '/';
if ($folder != '/')
$url .= $folder;
return $url;
}

/**
* Loads default system settings (which can be updated via admin.php).
*
Expand Down
3 changes: 1 addition & 2 deletions includes/user-app-joomla.php
Original file line number Diff line number Diff line change
Expand Up @@ -349,8 +349,7 @@ function user_logged_in () {

// Redirect the user to the login-app.php page
function app_login_screen( $return ) {
global $SERVER_URL;
header ( "Location: {$SERVER_URL}login-app.php?return_path={$return}");
header ( "Location: " . getServerUrl() . "login-app.php?return_path={$return}");
exit;
}

Expand Down
36 changes: 23 additions & 13 deletions includes/xcal.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ function wc_export_fold_lines ( $string, $encoding = 'none', $limit = 76 ) {
if ( strcmp( $encoding, 'quotedprintable' ) == 0 )
$enc = export_quoted_printable_encode( $string[$i] );
else if ( strcmp( $encoding, 'utf8' ) == 0 )
$enc = utf8_encode ( $string[$i] );
$enc = mb_convert_encoding($string[$i], 'UTF-8', mb_detect_encoding($string[$i]));
}
if ( $string[$i] == ':' )
$start_encode = 1;
Expand Down Expand Up @@ -219,12 +219,15 @@ function export_get_attendee( $id, $export ) {
// Use "Full Name <email>" if we have it,
// Just "login" if that's all we have.
$attendee[$count] .= ';CN="'
. ( empty( $user['cal_firstname'] ) && empty( $user['cal_lastname'] )
? $user['cal_login']
: utf8_encode( $user['cal_firstname'] ) . ' '
. utf8_encode( $user['cal_lastname'] ) ) . '"'
. ':MAILTO:' . ( empty( $user['cal_email'] )
? $EMAIL_FALLBACK_FROM : $user['cal_email'] );
. (empty($user['cal_firstname']) && empty($user['cal_lastname'])
? $user['cal_login']
: mb_convert_encoding($user['cal_firstname'], 'UTF-8', mb_detect_encoding($user['cal_firstname'])) . ' '
. mb_convert_encoding($user['cal_lastname'], 'UTF-8', mb_detect_encoding($user['cal_lastname']))) . '"';
if (!empty($user['cal_email'])) {
$attendee[$count] .= ':MAILTO:' . $user['cal_email'];
} else if (strpos('@', $EMAIL_FALLBACK_FROM) > 0) {
$attendee[$count] .= ':MAILTO:' . $EMAIL_FALLBACK_FROM;
}
}
$count++;
} //end if ( count ( $user ) > 0 )
Expand Down Expand Up @@ -739,15 +742,18 @@ function export_get_event_entry( $id = 'all', $attachment = false ) {
return $res;
} //end function export_get_event_entry($id)
function generate_uid ( $id = '' ) {
global $login, $SERVER_URL;
global $login;

$uid = $SERVER_URL;
$uid = getServerUrl();
if ( empty ( $uid ) )
$uid = 'UNCONFIGURED-WEBCALENDAR';
$uid = str_replace ( 'http://', ' ', $uid );
$uid = str_replace ( 'http://', '', $uid );
$uid = str_replace ( 'https://', '', $uid );
$uid = str_replace ( ':', '-', $uid );
$uid .= sprintf ( "-%s-%010d", $login, $id );
$uid = preg_replace ( "/[\s\/\.-]+/", '-', $uid );
$uid = preg_replace ( "/[\/-]+/", '-', $uid );
$uid = strtoupper ( $uid );

return $uid;
}
// Add entries in the webcal_import and webcal_import_data tables.
Expand Down Expand Up @@ -944,8 +950,12 @@ function export_ical ( $id = 'all', $attachment = false ) {
// Always output something, even if no records come back
// This prevents errors on the iCal client
$ret = "BEGIN:VCALENDAR\r\n";
$title = utf8_encode ( 'X-WR-CALNAME;VALUE=TEXT:' .
( empty ( $publish_fullname ) ? $login : translate ( $publish_fullname ) ) );
$title = mb_convert_encoding(
'X-WR-CALNAME;VALUE=TEXT:' .
(empty($publish_fullname) ? $login : translate($publish_fullname)),
'UTF-8',
mb_detect_encoding(empty($publish_fullname) ? $login : $publish_fullname)
);
$title = str_replace ( ',', "\\,", $title );
$ret .= "$title\r\n";
$ret .= generate_prodid ( 'ics' );
Expand Down
4 changes: 4 additions & 0 deletions install/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,10 @@ function_exists('gd_info'),
$connectError = dbi_error();
}
}
if (!empty($_GET['action']) && $_GET['action'] == "phpinfo") {
phpinfo ();
exit;
}
$emptyDatabase = $canConnectDb ? isEmptyDatabase() : true;
$unsavedDbSettings = !empty($_SESSION['unsavedDbSettings']); // Keep track if Db settings were modified by not yet saved
$reportedDbVersion = 'Unknown';
Expand Down
37 changes: 32 additions & 5 deletions install/install_phpsettings.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<table class="table table-striped table-bordered">
<thead>
<tr>
<th><?php etranslate('Setting Description');?></th>
<th><?php etranslate('Required Setting');?></th>
<th><?php etranslate('Current Setting');?></th>
<th><?php etranslate('Status');?></th>
<th><?php etranslate('Setting Description'); ?></th>
<th><?php etranslate('Required Setting'); ?></th>
<th><?php etranslate('Current Setting'); ?></th>
<th><?php etranslate('Status'); ?></th>
</tr>
</thead>
<tbody>
Expand All @@ -27,6 +27,12 @@
</tbody>
</table>

<script>
function testPHPInfo() {
$('#wcTestPHPInfo').modal('show');
}
</script>
<input name="action" type="button" class="btn btn-secondary" value="<?php etranslate('Detailed PHP Info') ?>..." onClick="testPHPInfo()" />
<?php
$html = '';
$buttonLabel = translate('Next');
Expand All @@ -36,4 +42,25 @@
$buttonLabel = translate('Acknowledge');
}
printSubmitButton($action, $html, $buttonLabel);
?>
?>

<!-- Bootstrap Modal -->
<div class="modal fade" id="wcTestPHPInfo" tabindex="-1" role="dialog" aria-labelledby="wcTestPHPInfoLabel" aria-hidden="true">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="wcTestPHPInfoLabel"><?php etranslate('PHP Info'); ?></h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<!-- Iframe with full width and height -->
<iframe src="index.php?action=phpinfo" style="width: 100%; height: 500px;" frameborder="0"></iframe>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal"><?php etranslate('Close'); ?></button>
</div>
</div>
</div>
</div>
22 changes: 8 additions & 14 deletions pref.php
Original file line number Diff line number Diff line change
Expand Up @@ -762,35 +762,32 @@ function save_pref( $prefs, $src) {
<label for="USER_PUBLISH_ENABLED"><?php etranslate ( 'Allow remote subscriptions' )?>:</label></td><td class="form-inline mt-1">
<?php echo print_radio ( 'USER_PUBLISH_ENABLED' ) ?>
</td></tr>
<?php if ( ! empty ( $SERVER_URL ) ) { ?>
<tr><td data-toggle="tooltip" data-placement="top" title="<?php etooltip ("remote-subscriptions-url-help");?>">&nbsp;&nbsp;&nbsp;&nbsp;
<label><?php etranslate ( 'URL' )?>:</label></td>
<td>
<?php
echo htmlspecialchars ( $SERVER_URL ) .
echo htmlspecialchars ( getServerUrl() ) .
'publish.php/' . ( $updating_public ? '__public__' : $user ) . '.ics';
echo "<br>\n";
echo htmlspecialchars ( $SERVER_URL ) .
echo htmlspecialchars ( getServerUrl() ) .
'publish.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 } /* $SERVER_URL */ ?>

<tr><td data-toggle="tooltip" data-placement="top" title="<?php etooltip ("allow-remote-publishing-help");?>">
<label for="pref_USER_PUBLISH_RW_ENABLED"><?php etranslate ( 'Allow remote publishing' )?>:</label></td>
<td class="form-inline mt-1">
<?php echo print_radio ( 'USER_PUBLISH_RW_ENABLED' ) ?>
</td></tr>
<?php if ( ! empty ( $SERVER_URL ) ) { ?>
<tr><td data-toggle="tooltip" data-placement="top" title="<?php etooltip ("remote-publishing-url-help");?>">
&nbsp;&nbsp;&nbsp;&nbsp;<label><?php etranslate ( 'URL' )?>:</label></td>
<td>
<?php
echo htmlspecialchars ( $SERVER_URL ) .
echo htmlspecialchars ( getServerUrl() ) .
'icalclient.php';
?></td></tr>
<tr><td height="0.5 em"><!-- small vertical spacing--><span style="font-size: 25%">&nbsp;</span> </td></tr>
<?php } /* $SERVER_URL */
<?php

} /* $PUBLISH_ENABLED */

Expand All @@ -800,36 +797,33 @@ function save_pref( $prefs, $src) {
<td class="form-inline mt-1">
<?php echo print_radio ( 'USER_RSS_ENABLED' ) ?>
</td></tr>
<?php if ( ! empty ( $SERVER_URL ) ) { ?>
<tr><td data-toggle="tooltip" data-placement="top" title="<?php etooltip ("rss-feed-url-help");?>">
&nbsp;&nbsp;&nbsp;&nbsp;<label><?php etranslate ( 'URL' )?>:</label></td>
<td>
<?php
echo htmlspecialchars ( $SERVER_URL ) .
echo htmlspecialchars ( getServerUrl() ) .
'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 } /* $SERVER_URL */
<?php
} /* $RSS_ENABLED */ ?>

<tr><td data-toggle="tooltip" data-placement="top" title="<?php etooltip ("freebusy-enabled-help");?>">
<label for="pref_FREEBUSY_ENABLED"><?php etranslate ( 'Enable FreeBusy publishing' )?>:</label></td>
<td class="form-inline mt-1">
<?php echo print_radio ( 'FREEBUSY_ENABLED' ) ?>
</td></tr>
<?php if ( ! empty ( $SERVER_URL ) ) { ?>
<tr><td data-toggle="tooltip" data-placement="top" title="<?php etooltip ("freebusy-url-help");?>">
&nbsp;&nbsp;&nbsp;&nbsp;<label><?php etranslate ( 'URL' )?>:</label></td>
<td>
<?php
echo htmlspecialchars ( $SERVER_URL ) .
echo htmlspecialchars ( getServerUrl() ) .
'freebusy.php/' . ( $updating_public ? '__public__' : $user ) . '.ifb';
echo "<br>\n";
echo htmlspecialchars ( $SERVER_URL ) .
echo htmlspecialchars ( getServerUrl() ) .
'freebusy.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 } /* $SERVER_URL */ ?>
</table>
</div></div>
<!-- END SUBSCRIBE -->
Expand Down
Loading

0 comments on commit b8575e9

Please sign in to comment.