Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Elvis and other PHP short form operators #520

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 28 additions & 23 deletions access.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,22 @@
*/
require_once 'includes/init.php';

$allow_view_other =
( ! empty( $ALLOW_VIEW_OTHER ) && $ALLOW_VIEW_OTHER == 'Y' );
// We need to find where these things are being unset. :-(
global $ALLOW_VIEW_OTHER;

// This
$ALLOW_VIEW_OTHER ??= 'Y';
$ALLOW_VIEW_OTHER = ( ! $ALLOW_VIEW_OTHER || trim ( $ALLOW_VIEW_OTHER ) === 'Y' ? 'Y' : 'N' );

// is shorthand for:
// $ALLOW_VIEW_OTHER =
// ( ! isset ( $ALLOW_VIEW_OTHER ) || null === $ALLOW_VIEW_OTHER
// ? 'Y' : $ALLOW_VIEW_OTHER );
// $ALLOW_VIEW_OTHER =
// ( empty ( $ALLOW_VIEW_OTHER ) || trim ( $ALLOW_VIEW_OTHER ) === 'Y' )
// ? 'Y' : 'N' );

$allow_view_other = ( $ALLOW_VIEW_OTHER === 'Y' );

if( ! access_is_enabled() ) {
echo print_not_auth();
Expand Down Expand Up @@ -86,9 +100,6 @@
$i += $i;
}

$email = getPostValue( 'email' );
$invite = getPostValue( 'invite' );
$time = getPostValue( 'time' );

if( ! dbi_execute( 'INSERT INTO webcal_access_user ( cal_login,
cal_other_user, cal_can_view, cal_can_edit, cal_can_approve,
Expand All @@ -97,12 +108,13 @@
[
$puser,
$pouser,
( $view_total > 0 ? $view_total : 0 ),
( $view_total ?: 0 ),
( $edit_total > 0 && $puser != '__public__' ? $edit_total : 0 ),
( $approve_total > 0 && $puser != '__public__' ? $approve_total : 0 ),
( strlen( $invite ) ? $invite : 'N' ),
( strlen( $email ) ? $email : 'N' ),
( strlen( $time ) ? $time : 'N' )] ) )
( trim ( getPostValue ( 'invite' ) ) ?: 'N' ),
( trim ( getPostValue ( 'email' ) ) ?: 'N' ),
( trim ( getPostValue ( 'time' ) ) ?: 'N' )
] ) )
die_miserable_death( str_replace( 'XXX', dbi_error(), $dbErrStr ) );

$saved = true;
Expand Down Expand Up @@ -134,25 +146,18 @@
$allPermissions = access_load_user_permissions( false );

// Load default-default values if exist.
if( ! empty( $allPermissions['__default__.__default__'] ) )
$op = $allPermissions['__default__.__default__'];
$op = ( $allPermissions['__default__.__default__'] ?: '' );

if( $is_admin ) {
// Load user-default values if exist.
if( ! empty( $allPermissions[ $guser . '.__default__' ] ) )
$op = $allPermissions[ $guser . '.__default__' ];

// Load user-otheruser values if exist.
if( ! empty( $allPermissions[ $guser . '.' . $otheruser ] ) )
$op = $allPermissions[ $guser . '.' . $otheruser ];
$op = ( $allPermissions[$guser . '.' . $otheruser] ?:
// Load user-default values if exist.
$allPermissions[$guser . '.__default__'] );
} else {
// Load default-user values if exist.
if( ! empty( $allPermissions['__default__.' . $guser] ) )
$op = $allPermissions['__default__.' . $guser ];

// Load otheruser-user values if exist.
if( ! empty( $allPermissions[$otheruser . '.' . $guser] ) )
$op = $allPermissions[$otheruser . '.' . $guser];
$op = ( $allPermissions[$otheruser . '.' . $guser] ?:
// Load default-user values if exist.
$allPermissions['__default__.' . $guser] );
}
}
}
Expand Down