Skip to content

Commit

Permalink
redundant boolean values
Browse files Browse the repository at this point in the history
  • Loading branch information
bbannon committed Oct 17, 2024
1 parent bd476d2 commit 1cd1b14
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 45 deletions.
2 changes: 1 addition & 1 deletion docs/WebCalendar-DeveloperGuide.html
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ <h2>Coding Standards</h2>

<b>the ternary operator</b>
If $foo is not undefined.
$a = ( $foo === 1 ? true : false );
$a = ( $foo === 1 );
<b>or, since 'true' is the default here:</b>
$a = ( $foo === 1 );

Expand Down
6 changes: 3 additions & 3 deletions includes/classes/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,7 @@ function getEndDateTimeTS() {
* @access public
*/
function isAllDay() {
$this->_allDay = ( $this->_time == 0 && $this->_duration == 1440? true : false);
$this->_allDay = ( $this->_time === 0 && $this->_duration === 1440 );
return $this->_allDay;
}

Expand All @@ -657,7 +657,7 @@ function isAllDay() {
*/
function isTimed() {
$this->_timed = ( $this->_time > 0 || ( $this->_time == 0
&& $this->_duration != 1440 )? true : false);
&& $this->_duration !== 1440 ) );
return $this->_timed;
}

Expand All @@ -669,7 +669,7 @@ function isTimed() {
* @access public
*/
function isUntimed() {
$this->_untimed = ( $this->_time == -1 && $this->_duration == 0? true : false);
$this->_untimed = ( $this->_time === -1 && $this->_duration === 0 );
return $this->_untimed;
}

Expand Down
6 changes: 2 additions & 4 deletions includes/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -251,12 +251,10 @@ function do_config($callingFromInstall=false)
$db_password = $settings['db_password'] ?? '';
$db_persistent = (preg_match(
'/(1|yes|true|on)/i',
$settings['db_persistent']
) ? true : false );
$settings['db_persistent'] ) );
$db_debug = (preg_match(
'/(1|yes|true|on)/i',
$settings['db_debug']
) ? true : false);
$settings['db_debug'] ) );
$db_type = $settings['db_type'] ?? '';

// If no db settings, then user has likely started install but not yet
Expand Down
6 changes: 2 additions & 4 deletions includes/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -6078,8 +6078,7 @@ function weekday_name ( $w, $format = 'l' ) {
*/
function boss_must_approve_event ( $assistant, $boss ) {
if ( user_is_assistant ( $assistant, $boss ) )
return ( get_pref_setting ( $boss, 'APPROVE_ASSISTANT_EVENT' ) == 'Y'
? true : false );
return ( get_pref_setting ( $boss, 'APPROVE_ASSISTANT_EVENT' ) === 'Y' );

return true;
}
Expand All @@ -6095,8 +6094,7 @@ function boss_must_approve_event ( $assistant, $boss ) {
*/
function boss_must_be_notified ( $assistant, $boss ) {
if ( user_is_assistant ( $assistant, $boss ) )
return ( get_pref_setting ( $boss, 'EMAIL_ASSISTANT_EVENTS' ) == 'Y'
? true : false );
return ( get_pref_setting ( $boss, 'EMAIL_ASSISTANT_EVENTS' ) === 'Y' );

return true;
}
Expand Down
2 changes: 1 addition & 1 deletion includes/user.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ function user_valid_login ( $login, $password, $silent=false ) {
$sql = 'UPDATE webcal_user SET cal_passwd = ? WHERE cal_login = ?';
dbi_execute ( $sql, [$new_hash, $login] );
}
$enabled = ( $row[1] == 'Y' ? true : false );
$enabled = ( $row[1] === 'Y' );
// MySQL seems to do case insensitive matching, so double-check the login.
if ( $okay && $row[0] == $login )
$ret = true; // found login/password
Expand Down
7 changes: 4 additions & 3 deletions install/install_ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,12 @@ function testDbConnection($host, $login, $password, $database)
}


$response = array();
$response = [];
ini_set('session.cookie_lifetime', 3600); // 3600 seconds = 1 hour
session_name('WebCalendar-Install-' . __DIR__);
session_start();

$errorResponse = array();
$errorResponse = [];
$errorResponse['status'] = "error";
$errorResponse['error'] = translate('Invalid test connection request');

Expand All @@ -103,7 +103,8 @@ function testDbConnection($host, $login, $password, $database)
echo json_encode($errorResponse);
exit;
}
$validUser = (isset($_SESSION['validUser']) && !empty($_SESSION['validUser'])) ? true : false;
$validUser = ( isset ( $_SESSION['validUser'] ) && ! empty ( $_SESSION['validUser'] ) );

if (!$validUser) { // User must be logged in to install pages
$errorResponse['error'] .= "\n" . 'Not logged in';
echo json_encode($errorResponse);
Expand Down
34 changes: 14 additions & 20 deletions purge.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,38 +14,32 @@
*/
require_once 'includes/init.php';

// Set this to true do show the SQL at the bottom of the page
$purgeDebug = false;

$sqlLog = '';

if ( ! $is_admin ) {
// must be admin...
do_redirect ( 'index.php' );
exit;
}

$ALL = 0;
// Set this to true do show the SQL at the bottom of the page
$purgeDebug = false;
$sqlLog = '';

$previewStr = translate ( 'Preview' );
$allStr = translate ( 'All' );
$purgingStr = translate ( 'Purging events for' );
$deleteStr = translate ( 'Delete' );

$delete = getPostValue ( 'delete' );
$do_purge = false;
if ( ! empty ( $delete ) ) {
$do_purge = true;
}
$do_purge = ( ! empty ( $delete ) );

$purge_all = getPostValue ( 'purge_all' );
$purge_deleted = getPostValue ( 'purge_deleted' );
$end_year = getPostValue ( 'end_year' );
$end_month = getPostValue ( 'end_month' );
$end_day = getPostValue ( 'end_day' );
$username = getPostValue ( 'username' );
$preview = getPostValue ( 'preview' );
$preview = ( empty ( $preview ) ? false : true );
$preview = ( ! empty ( getPostValue ( 'preview' ) ) );

$INC = ['js/visible.php'];

Expand Down Expand Up @@ -110,18 +104,18 @@
echo '<h2>...' . translate ( 'Finished' ) . ".</h2>\n";
?>
<form><button class="btn btn-primary" type="button" onclick="history.back()">
<?php etranslate ( 'Back' )?></button></form><?php
<?php etranslate ( 'Back' )?></button></form><?php
if ( $purgeDebug ) {
echo '<div style="border: 1px solid #000;background-color: #FFF;"><span class="tt">'
. "$sqlLog</span></div>\n";
}
} else {
?>
<form id="purgeform" action="purge.php" method="post" name="purgeform">
<?php echo csrf_form_key(); ?>
<?php echo csrf_form_key(); ?>
<table>
<tr><td><label for="user" class="colon">
<?php echo translate ( 'User' );?></label></td>
<?php echo translate ( 'User' );?></label></td>
<td><select class="form-control" name="username">
<?php
$userlist = get_my_users();
Expand All @@ -140,21 +134,21 @@
</select>
</td></tr>
<tr><td><label for="purge_all" class="colon">
<?php etranslate ( 'Check box to delete ALL events for a user' )?></label></td>
<?php etranslate ( 'Check box to delete ALL events for a user' )?></label></td>
<td class="alignbottom">
<input class="form-control-sm" type="checkbox" name="purge_all" value="Y" id="purge_all" onclick="toggle_datefields( 'dateArea', this );">
</td></tr>
<tr id="dateArea"><td><label class="colon">
<?php etranslate ( 'Delete all events before' );?></label></td><td>
<?php echo date_selection ( 'end_', date ( 'Ymd' ) ) ?>
<?php etranslate ( 'Delete all events before' );?></label></td><td>
<?php echo date_selection ( 'end_', date ( 'Ymd' ) ) ?>
</td></tr>
<tr><td><label for="purge_deleted" class="colon">
<?php etranslate ( 'Purge deleted only' )?></label></td>
<?php etranslate ( 'Purge deleted only' )?></label></td>
<td class="alignbottom">
<input class="form-control-sm" type="checkbox" name="purge_deleted" value="Y">
</td></tr>
<tr><td><label for="preview" class="colon">
<?php etranslate ( 'Preview delete' )?></label></td>
<?php etranslate ( 'Preview delete' )?></label></td>
<td class="alignbottom">
<input class="form-control-sm" type="checkbox" name="preview" value="Y" checked>
</td></tr>
Expand Down Expand Up @@ -195,7 +189,7 @@ function purge_events ( $ids ) {
//var_dump($tables);exit;
$cnt = count ( $tables );
$num = array_fill ( 0, $cnt, 0 );

foreach ( $ids as $cal_id ) {
for ( $i = 0; $i < $cnt; $i++ ) {
$clause = ( $cal_id == 'ALL' ? '' :
Expand Down
2 changes: 1 addition & 1 deletion rss.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
$date_in_title = false; //Can override with "rss.php?showdate=1|true".
$showdate = getValue ( 'showdate' );
if ( ! empty ( $showdate ) )
$date_in_title = ( $showdate == 'true' || $showdate == 1 ? true : false );
$date_in_title = ( $showdate == 'true' || $showdate == 1 );

$date_format = 'M jS'; //Aug 10th, 8/10
$time_format = 'g:ia'; //4:30pm, 16:30
Expand Down
16 changes: 8 additions & 8 deletions upcoming.php
Original file line number Diff line number Diff line change
Expand Up @@ -271,11 +271,11 @@ function print_upcoming_event ( $e, $date ) {
$numDays = getIntValue ( 'numDays' );
if (empty ($numDays)) $numDays = 30;
$showTitle = ( getGetValue ( 'showTitle', "[01]", true ) == '1' );
$showTitle = ( ! empty ( $showTitle ) && $showTitle !== false ? true : false );
$showTitle = ( ! empty ( $showTitle ) && $showTitle !== false );
$showMore = getGetValue ( 'showMore', "[01]", true );
$showMore = ( ! empty ( $showMore ) && $showMore !== false ? true : false );
$showMore = ( ! empty ( $showMore ) && $showMore !== false );
$showTime = getGetValue ( 'showTime', "[01]", true );
$showTime = ( ! empty ( $showTime ) && $showTime !== false ? true : false );
$showTime = ( ! empty ( $showTime ) && $showTime !== false );

//sets the URL used in the (optional) page title and
//(optional) "...more" tag at the end. If you want them to
Expand Down Expand Up @@ -393,7 +393,7 @@ function print_upcoming_event ( $e, $date ) {

$x = getGetValue ( 'showTitle', true );
if ( strlen( $x ) > 0 ) {
$showTitle = $x;
$showTitle = $x;
}

if ( $load_layers ) {
Expand Down Expand Up @@ -534,13 +534,13 @@ function print_upcoming_event ( $e, $date ) {
.rrule {
visibility: hidden;
}
</style> <?php
</style><?php
if ( ! empty ( $showPopups ) && empty ( $error ) ) {
echo '<script src="includes/js/util.js"></script>
<script src="includes/js/popups.js"></script>';
}
?> </head>
<body> <?php } //end test for direct call
<body><?php } //end test for direct call

if ( ! empty ( $error ) ) {
echo print_error ( $error );
Expand All @@ -553,7 +553,7 @@ function print_upcoming_event ( $e, $date ) {
}

if ($showTitle) echo '<h3 class="cal_upcoming_title">'. translate ($upcoming_title) . '</h3>';
?> <div class="vcalendar"> <?php
?> <div class="vcalendar"><?php
echo "<dl>\n";

echo "<!-- \nstartTime: $startDate (" . date('Ymd H:i:s', $startDate ) . ")\n" .
Expand Down Expand Up @@ -597,7 +597,7 @@ function print_upcoming_event ( $e, $date ) {

if ( $showMore ) echo '<center><i><a href="'. $title_more_url . '"> . . . ' .
translate ( 'more' ) . '</a></i></center>';
?> </div> <?php
?> </div><?php
echo $eventinfo;
if ( ! empty ( $PHP_SELF ) && preg_match ( $name_of_this_file, $PHP_SELF ) ) {
echo "</body>\n</html>";
Expand Down

0 comments on commit 1cd1b14

Please sign in to comment.