Commit b8ecc4e2 authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Remove use of bitwise assignments on boolean values



This patch removes some inapproprate uses of the |= and &= operators
on boolean values.  On view/edit.php, &= was also used on the integer
return value from strlen as if it were a boolean, resulting in the
clean url field being uneditable in some instances where it should
have been editable (see bug #1006634).

Change-Id: I96a72c407309ed82a45d3130cffa06418be05fe7
Signed-off-by: default avatarRichard Mansfield <richard.mansfield@catalyst.net.nz>
parent 1bf27bcf
......@@ -82,16 +82,16 @@ else {
}
// If the file is in the public directory, it's fine to serve
$fileispublic = (bool)get_field('artefact_parent_cache', 'artefact', 'artefact', $fileid, 'parent', ArtefactTypeFolder::admin_public_folder_id());
$fileispublic &= $file->get('institution') == 'mahara';
$fileispublic = $file->get('institution') == 'mahara';
$fileispublic = $fileispublic && (bool)get_field('artefact_parent_cache', 'artefact', 'artefact', $fileid, 'parent', ArtefactTypeFolder::admin_public_folder_id());
if (!$fileispublic) {
// If the file is in the logged in menu and the user is logged in then
// they can view it
$fileinloggedinmenu = $file->get('institution') == 'mahara';
$fileinloggedinmenu &= $file->get('parent') == null;
$fileinloggedinmenu &= record_exists('site_menu', 'file', $fileid, 'public', 0);
$fileinloggedinmenu &= $USER->is_logged_in();
$fileinloggedinmenu = $fileinloggedinmenu && $file->get('parent') == null;
$fileinloggedinmenu = $fileinloggedinmenu && $USER->is_logged_in();
$fileinloggedinmenu = $fileinloggedinmenu && record_exists('site_menu', 'file', $fileid, 'public', 0);
if (!$fileinloggedinmenu) {
// Alternatively, if you own the file or you are an admin, it should always work
......
......@@ -2028,6 +2028,7 @@ function get_views($users, $userlooking=null, $limit=5, $type=null) {
}
$data = array();
$done = false;
// public, logged in, or friends' views
if ($results = get_records_sql_assoc(
......@@ -2093,7 +2094,7 @@ function get_views($users, $userlooking=null, $limit=5, $type=null) {
$data = array_merge($data, $results);
// bail if we've filled all users to the limit
$done &= _get_views_trim_list($list, $users, $limit, $data);
$done = $done && _get_views_trim_list($list, $users, $limit, $data);
}
// check group access
......@@ -2122,7 +2123,7 @@ function get_views($users, $userlooking=null, $limit=5, $type=null) {
$data = array_merge($data, $results);
// bail if we've filled all users to the limit
$done &= _get_views_trim_list($list, $users, $limit, $data);
$done = $done && _get_views_trim_list($list, $users, $limit, $data);
}
require_once('view.php');
......
......@@ -272,7 +272,7 @@ function get_admin_user_search_results($search, $offset, $limit) {
// Remove email address when viewed by staff
if (!$hideemail = (empty($admininstitutions) || empty($result['institutions']))) {
$commoninstitutions = array_intersect($admininstitutions, $result['institutions']);
$hideemail |= empty($commoninstitutions);
$hideemail = $hideemail || empty($commoninstitutions);
}
if ($hideemail) {
unset($result['email']);
......
......@@ -886,8 +886,8 @@ function get_user_for_display($user=null) {
foreach ($fields as $f) {
$user->$f = $USER->get($f);
}
$user->admin |= $USER->is_institutional_admin();
$user->staff |= $USER->is_institutional_staff();
$user->admin = $user->admin || $USER->is_institutional_admin();
$user->staff = $user->staff || $USER->is_institutional_staff();
}
else if ($user instanceof User) {
$userObj = $user;
......
......@@ -3942,8 +3942,8 @@ class View {
}
if ($a->allowcomments) {
$allowcomments |= $a->allowcomments;
$approvecomments &= $a->approvecomments;
$allowcomments = $allowcomments || $a->allowcomments;
$approvecomments = $approvecomments && $a->approvecomments;
}
if (!$approvecomments) {
return true;
......
......@@ -90,12 +90,12 @@ if ($studentid !== '') {
if ($urlallowed = get_config('cleanurls') && $view->get('type') == 'portfolio' && !$institution) {
if ($group) {
$groupdata = get_record('group', 'id', $group);
$urlallowed &= strlen($groupdata->urlid);
$urlallowed = $urlallowed && strlen($groupdata->urlid);
$cleanurlbase = get_config('wwwroot') . get_config('cleanurlgroupdefault') . '/' . $groupdata->urlid . '/';
}
else {
$userurlid = $USER->get('urlid');
if ($urlallowed &= (!is_null($userurlid) && strlen($userurlid))) {
if ($urlallowed = ($urlallowed && !is_null($userurlid) && strlen($userurlid))) {
$cleanurlbase = get_config('wwwroot') . get_config('cleanurluserdefault') . '/' . $userurlid . '/';
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment