Commit 525bcf22 authored by Donal McMullan's avatar Donal McMullan

Replace 'if(' with 'if (' in introduced code

parent 851bf10f
...@@ -90,7 +90,7 @@ function networkingform_submit(Pieform $form, $values) { ...@@ -90,7 +90,7 @@ function networkingform_submit(Pieform $form, $values) {
if (!set_config('enablenetworking', $values['enablenetworking'])) { if (!set_config('enablenetworking', $values['enablenetworking'])) {
networkingform_fail($form); networkingform_fail($form);
} else { } else {
if(empty($values['enablenetworking'])) { if (empty($values['enablenetworking'])) {
$reply .= get_string('networkingdisabled','admin'); $reply .= get_string('networkingdisabled','admin');
} else { } else {
$reply .= get_string('networkingenabled','admin'); $reply .= get_string('networkingenabled','admin');
...@@ -102,7 +102,7 @@ function networkingform_submit(Pieform $form, $values) { ...@@ -102,7 +102,7 @@ function networkingform_submit(Pieform $form, $values) {
if (!set_config('promiscuousmode', $values['promiscuousmode'])) { if (!set_config('promiscuousmode', $values['promiscuousmode'])) {
networkingform_fail($form); networkingform_fail($form);
} else { } else {
if(empty($values['promiscuousmode'])) { if (empty($values['promiscuousmode'])) {
$reply .= get_string('promiscuousmodedisabled','admin'); $reply .= get_string('promiscuousmodedisabled','admin');
} else { } else {
$reply .= get_string('promiscuousmodeenabled','admin'); $reply .= get_string('promiscuousmodeenabled','admin');
......
...@@ -126,7 +126,7 @@ function auth_config_submit(Pieform $form, $values) { ...@@ -126,7 +126,7 @@ function auth_config_submit(Pieform $form, $values) {
} }
if (false == $form->has_errors()) { if (false == $form->has_errors()) {
if(array_key_exists('create', $values) && $values['create']) { if (array_key_exists('create', $values) && $values['create']) {
execute_javascript_and_close('window.opener.addAuthority('.$values['instance'].', "'.addslashes($values['instancename']).'", "'.$values['authname'].'");'); execute_javascript_and_close('window.opener.addAuthority('.$values['instance'].', "'.addslashes($values['instancename']).'", "'.$values['authname'].'");');
} else { } else {
execute_javascript_and_close(); execute_javascript_and_close();
......
...@@ -252,16 +252,16 @@ function institution_submit(Pieform $form, $values) { ...@@ -252,16 +252,16 @@ function institution_submit(Pieform $form, $values) {
$allinstances = array_merge($values['authplugin']['instancearray'], $values['authplugin']['deletearray']); $allinstances = array_merge($values['authplugin']['instancearray'], $values['authplugin']['deletearray']);
if(array_diff($allinstances, $instancearray)) { if (array_diff($allinstances, $instancearray)) {
throw new Exception('Attempt to delete or update another institution\'s auth instance'); throw new Exception('Attempt to delete or update another institution\'s auth instance');
} }
if(array_diff($instancearray, $allinstances)) { if (array_diff($instancearray, $allinstances)) {
throw new Exception('One of your instances is unaccounted for in this transaction'); throw new Exception('One of your instances is unaccounted for in this transaction');
} }
foreach($values['authplugin']['instancearray'] as $priority => $instanceid) { foreach($values['authplugin']['instancearray'] as $priority => $instanceid) {
if(in_array($instanceid, $values['authplugin']['deletearray'])) { if (in_array($instanceid, $values['authplugin']['deletearray'])) {
// Should never happen: // Should never happen:
throw new Exception('Attempt to update AND delete an auth instance'); throw new Exception('Attempt to update AND delete an auth instance');
} }
......
...@@ -80,7 +80,7 @@ $ALLOWEDKEYS = array( ...@@ -80,7 +80,7 @@ $ALLOWEDKEYS = array(
function auth_get_auth_instances() { function auth_get_auth_instances() {
static $cache = array(); static $cache = array();
if(count($cache) > 0) { if (count($cache) > 0) {
return $cache; return $cache;
} }
...@@ -103,7 +103,7 @@ function auth_get_auth_instances() { ...@@ -103,7 +103,7 @@ function auth_get_auth_instances() {
$cache = get_records_sql_array($sql, array()); $cache = get_records_sql_array($sql, array());
if(empty($cache)) { if (empty($cache)) {
return array(); return array();
} }
......
...@@ -41,7 +41,7 @@ class Client { ...@@ -41,7 +41,7 @@ class Client {
} }
function set_method($method) { function set_method($method) {
if(is_string($method) && preg_match("@^[A-Za-z0-9]+/[A-Za-z0-9/_-]+(\.php/)?[A-Za-z0-9_-]+$@", $method)) { if (is_string($method) && preg_match("@^[A-Za-z0-9]+/[A-Za-z0-9/_-]+(\.php/)?[A-Za-z0-9_-]+$@", $method)) {
$this->method = $method; $this->method = $method;
} }
return $this; return $this;
...@@ -74,7 +74,7 @@ class Client { ...@@ -74,7 +74,7 @@ class Client {
if ('2' != $response_code_prefix) { if ('2' != $response_code_prefix) {
if ('4' == $response_code_prefix) { if ('4' == $response_code_prefix) {
throw new XmlrpcClientException('Client error code: ', $response_code); throw new XmlrpcClientException('Client error code: ', $response_code);
} elseif('5' == $response_code_prefix) { } elseif ('5' == $response_code_prefix) {
throw new XmlrpcClientException('An error occurred at the remote server. Code: ', $response_code); throw new XmlrpcClientException('An error occurred at the remote server. Code: ', $response_code);
} }
} }
...@@ -93,19 +93,19 @@ class Client { ...@@ -93,19 +93,19 @@ class Client {
throw new Exception('Payload is not a valid XML document', 6001); throw new Exception('Payload is not a valid XML document', 6001);
} }
if($xml->getName() == 'encryptedMessage') { if ($xml->getName() == 'encryptedMessage') {
$payload_encrypted = true; $payload_encrypted = true;
$wwwroot = (string)$xml->wwwroot; $wwwroot = (string)$xml->wwwroot;
$payload = xmlenc_envelope_strip($xml); $payload = xmlenc_envelope_strip($xml);
} }
if($xml->getName() == 'signedMessage') { if ($xml->getName() == 'signedMessage') {
$payload_signed = true; $payload_signed = true;
$remote_timestamp = $xml->timestamp; $remote_timestamp = $xml->timestamp;
$payload = xmldsig_envelope_strip($xml); $payload = xmldsig_envelope_strip($xml);
} }
if($xml->getName() == 'methodResponse') { if ($xml->getName() == 'methodResponse') {
$this->response = xmlrpc_decode($payload); $this->response = xmlrpc_decode($payload);
// Margin of error is the time it took the request to complete. // Margin of error is the time it took the request to complete.
...@@ -115,7 +115,7 @@ class Client { ...@@ -115,7 +115,7 @@ class Client {
// executing the time() function. Marginally better than nothing. // executing the time() function. Marginally better than nothing.
$hysteresis = ($margin_of_error) / 2; $hysteresis = ($margin_of_error) / 2;
if(!empty($remote_timestamp)) { if (!empty($remote_timestamp)) {
$remote_timestamp = $remote_timestamp - $hysteresis; $remote_timestamp = $remote_timestamp - $hysteresis;
$time_offset = $remote_timestamp - $timestamp_send; $time_offset = $remote_timestamp - $timestamp_send;
// We've set the maximum time drift between servers to 15 seconds // We've set the maximum time drift between servers to 15 seconds
......
...@@ -88,7 +88,7 @@ class Dispatcher { ...@@ -88,7 +88,7 @@ class Dispatcher {
// it might provide an opportunity for outsiders to scan the // it might provide an opportunity for outsiders to scan the
// server for random files. So just a single message/code for // server for random files. So just a single message/code for
// all failures here kthxbye. // all failures here kthxbye.
if(strpos($this->method, '/') !== false) { if (strpos($this->method, '/') !== false) {
$this->callstack = explode('/', $this->method); $this->callstack = explode('/', $this->method);
} else { } else {
throw new XmlrpcServerException('The function does not exist', 6011); throw new XmlrpcServerException('The function does not exist', 6011);
......
...@@ -223,7 +223,7 @@ function user_authorise($token, $useragent) { ...@@ -223,7 +223,7 @@ function user_authorise($token, $useragent) {
$profile_data = get_records_select_assoc('artefact', "owner=? AND artefacttype IN (" . join(",",array_map(create_function('$a','return db_quote($a);'),array_keys($element_list))) . ")", array($USER->get('id')), '','artefacttype, title'); $profile_data = get_records_select_assoc('artefact', "owner=? AND artefacttype IN (" . join(",",array_map(create_function('$a','return db_quote($a);'),array_keys($element_list))) . ")", array($USER->get('id')), '','artefacttype, title');
$email = get_field('artefact_internal_profile_email', 'email', 'owner', $sso_session->userid, 'principal', 1); $email = get_field('artefact_internal_profile_email', 'email', 'owner', $sso_session->userid, 'principal', 1);
if(false == $email) { if (false == $email) {
throw new XmlrpcServerException("No email adress for user"); throw new XmlrpcServerException("No email adress for user");
} }
...@@ -240,7 +240,7 @@ function user_authorise($token, $useragent) { ...@@ -240,7 +240,7 @@ function user_authorise($token, $useragent) {
if (is_numeric($user->profileicon)) { if (is_numeric($user->profileicon)) {
$filename = get_config('dataroot') . 'artefact/internal/profileicons/' . ($user->profileicon % 256) . '/'.$user->profileicon; $filename = get_config('dataroot') . 'artefact/internal/profileicons/' . ($user->profileicon % 256) . '/'.$user->profileicon;
if(file_exists($filename) && is_readable($filename)) { if (file_exists($filename) && is_readable($filename)) {
$userdata['imagehash'] = sha1_file($filename); $userdata['imagehash'] = sha1_file($filename);
} }
} }
...@@ -326,7 +326,7 @@ function get_public_key($uri, $application=null) { ...@@ -326,7 +326,7 @@ function get_public_key($uri, $application=null) {
$openssl = OpenSslRepo::singleton(); $openssl = OpenSslRepo::singleton();
if(empty($application)) { if (empty($application)) {
$application = 'moodle'; $application = 'moodle';
} }
...@@ -357,7 +357,7 @@ function get_public_key($uri, $application=null) { ...@@ -357,7 +357,7 @@ function get_public_key($uri, $application=null) {
if ('2' != $response_code_prefix) { if ('2' != $response_code_prefix) {
if ('4' == $response_code_prefix) { if ('4' == $response_code_prefix) {
throw new XmlrpcClientException('Client error code: ', $response_code); throw new XmlrpcClientException('Client error code: ', $response_code);
} elseif('5' == $response_code_prefix) { } elseif ('5' == $response_code_prefix) {
throw new XmlrpcClientException('An error occurred at the remote server. Code: ', $response_code); throw new XmlrpcClientException('An error occurred at the remote server. Code: ', $response_code);
} }
} }
...@@ -436,12 +436,12 @@ function get_peer($wwwroot) { ...@@ -436,12 +436,12 @@ function get_peer($wwwroot) {
$wwwroot = (string)$wwwroot; $wwwroot = (string)$wwwroot;
static $peers = array(); static $peers = array();
if(isset($peers[$wwwroot])) return $peers[$wwwroot]; if (isset($peers[$wwwroot])) return $peers[$wwwroot];
require_once(get_config('libroot') . 'peer.php'); require_once(get_config('libroot') . 'peer.php');
$peer = new Peer(); $peer = new Peer();
if(!$peer->findByWwwroot($wwwroot)) { if (!$peer->findByWwwroot($wwwroot)) {
// Bootstrap unknown hosts? // Bootstrap unknown hosts?
throw new MaharaException('We don\'t have a record for your webserver in our database', 6003); throw new MaharaException('We don\'t have a record for your webserver in our database', 6003);
} }
...@@ -684,7 +684,7 @@ class OpenSslRepo { ...@@ -684,7 +684,7 @@ class OpenSslRepo {
static $instance; static $instance;
//if we don't have the single instance, create one //if we don't have the single instance, create one
if(!isset($instance)) { if (!isset($instance)) {
$instance = new OpenSslRepo(); $instance = new OpenSslRepo();
} }
return($instance); return($instance);
...@@ -698,7 +698,7 @@ class OpenSslRepo { ...@@ -698,7 +698,7 @@ class OpenSslRepo {
* *
*/ */
private function __construct() { private function __construct() {
if(empty($this->keypair)) { if (empty($this->keypair)) {
$this->get_keypair(); $this->get_keypair();
$this->keypair['privatekey'] = openssl_pkey_get_private($this->keypair['keypair_PEM']); $this->keypair['privatekey'] = openssl_pkey_get_private($this->keypair['keypair_PEM']);
$this->keypair['publickey'] = openssl_pkey_get_public($this->keypair['certificate']); $this->keypair['publickey'] = openssl_pkey_get_public($this->keypair['certificate']);
...@@ -715,7 +715,7 @@ class OpenSslRepo { ...@@ -715,7 +715,7 @@ class OpenSslRepo {
*/ */
private function get_history() { private function get_history() {
$openssl_history = get_field('config', 'value', 'field', 'openssl_history'); $openssl_history = get_field('config', 'value', 'field', 'openssl_history');
if(empty($openssl_history)) { if (empty($openssl_history)) {
$openssl_history = array(); $openssl_history = array();
$record = new stdClass(); $record = new stdClass();
$record->field = 'openssl_history'; $record->field = 'openssl_history';
...@@ -737,11 +737,11 @@ class OpenSslRepo { ...@@ -737,11 +737,11 @@ class OpenSslRepo {
*/ */
private function save_history($openssl_history) { private function save_history($openssl_history) {
$openssl_generations = get_field('config', 'value', 'field', 'openssl_generations'); $openssl_generations = get_field('config', 'value', 'field', 'openssl_generations');
if(empty($openssl_generations)) { if (empty($openssl_generations)) {
set_config('openssl_generations', 6); set_config('openssl_generations', 6);
$openssl_generations = 6; $openssl_generations = 6;
} }
if(count($openssl_history) > $openssl_generations) { if (count($openssl_history) > $openssl_generations) {
$openssl_history = array_slice($openssl_history, 0, $openssl_generations); $openssl_history = array_slice($openssl_history, 0, $openssl_generations);
} }
return set_config('openssl_history', serialize($openssl_history)); return set_config('openssl_history', serialize($openssl_history));
...@@ -757,8 +757,8 @@ class OpenSslRepo { ...@@ -757,8 +757,8 @@ class OpenSslRepo {
* @access public * @access public
*/ */
public function __get($name) { public function __get($name) {
if('certificate' === $name) return $this->keypair['certificate']; if ('certificate' === $name) return $this->keypair['certificate'];
if('expires' === $name) return $this->keypair['expires']; if ('expires' === $name) return $this->keypair['expires'];
return null; return null;
} }
...@@ -774,9 +774,9 @@ class OpenSslRepo { ...@@ -774,9 +774,9 @@ class OpenSslRepo {
$this->keypair = array(); $this->keypair = array();
$records = null; $records = null;
if(empty($regenerate)) { if (empty($regenerate)) {
$records = get_records_select_menu('config', "field IN ('openssl_keypair', 'openssl_keypair_expires')", 'field', 'field, value'); $records = get_records_select_menu('config', "field IN ('openssl_keypair', 'openssl_keypair_expires')", 'field', 'field, value');
if(!empty($records)) { if (!empty($records)) {
list($this->keypair['certificate'], $this->keypair['keypair_PEM']) = explode('@@@@@@@@', $records['openssl_keypair']); list($this->keypair['certificate'], $this->keypair['keypair_PEM']) = explode('@@@@@@@@', $records['openssl_keypair']);
$this->keypair['expires'] = $records['openssl_keypair_expires']; $this->keypair['expires'] = $records['openssl_keypair_expires'];
if ($this->keypair['expires'] <= time()) { if ($this->keypair['expires'] <= time()) {
...@@ -804,12 +804,12 @@ class OpenSslRepo { ...@@ -804,12 +804,12 @@ class OpenSslRepo {
// Getting the expire timestamp is convoluted, but required: // Getting the expire timestamp is convoluted, but required:
$credentials = openssl_x509_parse($this->keypair['certificate']); $credentials = openssl_x509_parse($this->keypair['certificate']);
if(is_array($credentials) && isset($credentials['validTo_time_t'])) { if (is_array($credentials) && isset($credentials['validTo_time_t'])) {
$expiresrecord->value = $credentials['validTo_time_t']; $expiresrecord->value = $credentials['validTo_time_t'];
$this->keypair['expires'] = $credentials['validTo_time_t']; $this->keypair['expires'] = $credentials['validTo_time_t'];
} }
if(empty($records)) { if (empty($records)) {
$result = insert_record('config', $keyrecord); $result = insert_record('config', $keyrecord);
return $result & insert_record('config', $expiresrecord); return $result & insert_record('config', $expiresrecord);
} else { } else {
...@@ -841,9 +841,9 @@ class OpenSslRepo { ...@@ -841,9 +841,9 @@ class OpenSslRepo {
//TODO: Create additional fields on site setup and read those from //TODO: Create additional fields on site setup and read those from
// config. Then remove the next 3 linez // config. Then remove the next 3 linez
if(empty($country)) $country = 'NZ'; if (empty($country)) $country = 'NZ';
if(empty($province)) $province = 'Wellington'; if (empty($province)) $province = 'Wellington';
if(empty($locality)) $locality = 'Te Aro'; if (empty($locality)) $locality = 'Te Aro';
$dn = array( $dn = array(
"countryName" => $country, "countryName" => $country,
...@@ -901,7 +901,7 @@ class PublicKey { ...@@ -901,7 +901,7 @@ class PublicKey {
} }
function __get($name) { function __get($name) {
if('expires' == $name) return $this->credentials['validTo_time_t']; if ('expires' == $name) return $this->credentials['validTo_time_t'];
return $this->{$name}; return $this->{$name};
} }
} }
......
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