Use ternary operator where aplicable

pull/310/head
Aleksander Machniak 9 years ago
parent a15d877ba8
commit 7e3298753a

@ -505,7 +505,7 @@ class rcube
}
ini_set('session.cookie_secure', $is_secure);
ini_set('session.name', $sess_name ? $sess_name : 'roundcube_sessid');
ini_set('session.name', $sess_name ?: 'roundcube_sessid');
ini_set('session.use_cookies', 1);
ini_set('session.use_only_cookies', 1);
ini_set('session.cookie_httponly', 1);
@ -601,7 +601,7 @@ class rcube
$attrib = array('name' => $attrib);
}
$name = $attrib['name'] ? $attrib['name'] : '';
$name = (string) $attrib['name'];
// attrib contain text values: use them from now
if (($setval = $attrib[strtolower($_SESSION['language'])]) || ($setval = $attrib['en_us'])) {
@ -619,7 +619,7 @@ class rcube
// replace vars in text
if (is_array($attrib['vars'])) {
foreach ($attrib['vars'] as $var_key => $var_value) {
$text = str_replace($var_key[0]!='$' ? '$'.$var_key : $var_key, $var_value, $text);
$text = str_replace($var_key[0] != '$' ? '$'.$var_key : $var_key, $var_value, $text);
}
}
@ -685,7 +685,7 @@ class rcube
*/
public function load_language($lang = null, $add = array(), $merge = array())
{
$lang = $this->language_prop(($lang ? $lang : $_SESSION['language']));
$lang = $this->language_prop($lang ?: $_SESSION['language']);
// load localized texts
if (empty($this->texts) || $lang != $_SESSION['language']) {
@ -1267,7 +1267,7 @@ class rcube
*/
public static function log_bug($arg_arr)
{
$program = strtoupper(!empty($arg_arr['type']) ? $arg_arr['type'] : 'php');
$program = strtoupper($arg_arr['type'] ?: 'php');
$level = self::get_instance()->config->get('debug_level');
// disable errors for ajax requests, write to log instead (#1487831)

@ -539,7 +539,7 @@ abstract class rcube_addressbook
else if ($compose_mode == 1)
$fn = join(' ', array($contact['firstname'], $contact['middlename'], $contact['surname']));
else if ($compose_mode == 0)
$fn = !empty($contact['name']) ? $contact['name'] : join(' ', array($contact['prefix'], $contact['firstname'], $contact['middlename'], $contact['surname'], $contact['suffix']));
$fn = $contact['name'] ?: join(' ', array($contact['prefix'], $contact['firstname'], $contact['middlename'], $contact['surname'], $contact['suffix']));
else {
$plugin = rcube::get_instance()->plugins->exec_hook('contact_listname', array('contact' => $contact));
$fn = $plugin['fn'];

@ -119,7 +119,7 @@ class rcube_charset
}
// ISO-8859
else if (preg_match('/ISO8859([0-9]{0,2})/', $str, $m)) {
$iso = 'ISO-8859-' . ($m[1] ? $m[1] : 1);
$iso = 'ISO-8859-' . ($m[1] ?: 1);
// some clients sends windows-1252 text as latin1,
// it is safe to use windows-1252 for all latin1
$result = $iso == 'ISO-8859-1' ? 'WINDOWS-1252' : $iso;
@ -238,8 +238,8 @@ class rcube_charset
$aliases['US-ASCII'] = 'ASCII';
}
$mb_from = $aliases[$from] ? $aliases[$from] : $from;
$mb_to = $aliases[$to] ? $aliases[$to] : $to;
$mb_from = $aliases[$from] ?: $from;
$mb_to = $aliases[$to] ?: $to;
// return if encoding found, string matches encoding and convert succeeded
if (in_array($mb_from, $mbstring_list) && in_array($mb_to, $mbstring_list)) {

@ -741,7 +741,7 @@ class rcube_contacts extends rcube_addressbook
$words = '';
// copy values into vcard object
$vcard = new rcube_vcard($record['vcard'] ? $record['vcard'] : $save_data['vcard'], RCUBE_CHARSET, false, $this->vcard_fieldmap);
$vcard = new rcube_vcard($record['vcard'] ?: $save_data['vcard'], RCUBE_CHARSET, false, $this->vcard_fieldmap);
$vcard->reset();
// don't store groups in vCard (#1490277)

@ -1183,7 +1183,7 @@ class rcube_db
}
// process the different protocol options
$parsed['protocol'] = (!empty($proto)) ? $proto : 'tcp';
$parsed['protocol'] = $proto ?: 'tcp';
$proto_opts = rawurldecode($proto_opts);
if (strpos($proto_opts, ':') !== false) {
list($proto_opts, $parsed['port']) = explode(':', $proto_opts);

@ -194,7 +194,7 @@ class rcube_imap_generic
do {
if ($this->eof()) {
return $line ? $line : null;
return $line ?: null;
}
$buffer = fgets($this->fp, $size);
@ -462,7 +462,7 @@ class rcube_imap_generic
}
}
return !empty($result) ? $result : false;
return $result ?: false;
}
/**

@ -285,8 +285,7 @@ class rcube_ldap extends rcube_addressbook
$bind_dn = $this->prop['bind_dn'];
$this->base_dn = $this->prop['base_dn'];
$this->groups_base_dn = ($this->prop['groups']['base_dn']) ?
$this->prop['groups']['base_dn'] : $this->base_dn;
$this->groups_base_dn = $this->prop['groups']['base_dn'] ?: $this->base_dn;
// User specific access, generate the proper values to use.
if ($this->prop['user_specific']) {
@ -677,7 +676,7 @@ class rcube_ldap extends rcube_addressbook
$attrib = array_merge($attrib, array_values($this->group_types));
$attrib[] = 'memberURL';
$filter = $this->prop['groups']['member_filter'] ? $this->prop['groups']['member_filter'] : '(objectclass=*)';
$filter = $this->prop['groups']['member_filter'] ?: '(objectclass=*)';
for ($i=0; $i < $entry[$attr]['count']; $i++) {
if (empty($entry[$attr][$i]))
@ -1312,7 +1311,7 @@ class rcube_ldap extends rcube_addressbook
}
}
return $newdn ? $newdn : true;
return $newdn ?: true;
}
/**
@ -1372,7 +1371,7 @@ class rcube_ldap extends rcube_addressbook
function delete_all($with_groups = false)
{
// searching for contact entries
$dn_list = $this->ldap->list_entries($this->base_dn, $this->prop['filter'] ? $this->prop['filter'] : '(objectclass=*)');
$dn_list = $this->ldap->list_entries($this->base_dn, $this->prop['filter'] ?: '(objectclass=*)');
if (!empty($dn_list)) {
foreach ($dn_list as $idx => $entry) {
@ -1447,7 +1446,7 @@ class rcube_ldap extends rcube_addressbook
if ($this->is_group_entry($rec)) {
$out['_type'] = 'group';
$out['readonly'] = true;
$fieldmap['name'] = $this->group_data['name_attr'] ? $this->group_data['name_attr'] : $this->prop['groups']['name_attr'];
$fieldmap['name'] = $this->group_data['name_attr'] ?: $this->prop['groups']['name_attr'];
}
// assign object type from object class mapping
@ -1472,7 +1471,7 @@ class rcube_ldap extends rcube_addressbook
if ($col == 'email' && $this->mail_domain && !strpos($value, '@'))
$out[$rf][] = sprintf('%s@%s', $value, $this->mail_domain);
else if (in_array($col, array('street','zipcode','locality','country','region')))
$out['address'.($subtype?':':'').$subtype][$i][$col] = $value;
$out['address' . ($subtype ? ':' : '') . $subtype][$i][$col] = $value;
else if ($col == 'address' && strpos($value, '$') !== false) // address data is represented as string separated with $
list($out[$rf][$i]['street'], $out[$rf][$i]['locality'], $out[$rf][$i]['zipcode'], $out[$rf][$i]['country']) = explode('$', $value);
else if ($rec[$lf]['count'] > 1)
@ -1701,7 +1700,7 @@ class rcube_ldap extends rcube_addressbook
$filter = $this->prop['groups']['filter'];
$scope = $this->prop['groups']['scope'];
$name_attr = $this->prop['groups']['name_attr'];
$email_attr = $this->prop['groups']['email_attr'] ? $this->prop['groups']['email_attr'] : 'mail';
$email_attr = $this->prop['groups']['email_attr'] ?: 'mail';
$sort_attrs = $this->prop['groups']['sort'] ? (array)$this->prop['groups']['sort'] : array($name_attr);
$sort_attr = $sort_attrs[0];
@ -1849,11 +1848,11 @@ class rcube_ldap extends rcube_addressbook
$new_dn = 'cn=' . rcube_ldap_generic::quote_string($group_name, true) . ',' . $this->groups_base_dn;
$new_gid = self::dn_encode($new_dn);
$member_attr = $this->get_group_member_attr();
$name_attr = $this->prop['groups']['name_attr'] ? $this->prop['groups']['name_attr'] : 'cn';
$name_attr = $this->prop['groups']['name_attr'] ?: 'cn';
$new_entry = array(
'objectClass' => $this->prop['groups']['object_classes'],
$name_attr => $group_name,
$member_attr => '',
$name_attr => $group_name,
$member_attr => '',
);
if (!$this->ldap->add_entry($new_dn, $new_entry)) {
@ -2005,7 +2004,7 @@ class rcube_ldap extends rcube_addressbook
$base_dn = $this->groups_base_dn;
$contact_dn = self::dn_decode($contact_id);
$name_attr = $this->prop['groups']['name_attr'] ? $this->prop['groups']['name_attr'] : 'cn';
$name_attr = $this->prop['groups']['name_attr'] ?: 'cn';
$member_attr = $this->get_group_member_attr();
$add_filter = '';

@ -155,7 +155,7 @@ class rcube_mime
*/
public static function decode_mime_string($input, $fallback = null)
{
$default_charset = !empty($fallback) ? $fallback : self::get_charset();
$default_charset = $fallback ?: self::get_charset();
// rfc: all line breaks or other characters not found
// in the Base64 Alphabet must be ignored by decoding software

@ -325,8 +325,8 @@ class rcube_plugin_api
// load additional information from local composer.lock file
if ($lock = $composer_lock['installed'][$json['name']]) {
$info['version'] = $lock['version'];
$info['uri'] = $lock['homepage'] ? $lock['homepage'] : $lock['source']['uri'];
$info['src_uri'] = $lock['dist']['uri'] ? $lock['dist']['uri'] : $lock['source']['uri'];
$info['uri'] = $lock['homepage'] ?: $lock['source']['uri'];
$info['src_uri'] = $lock['dist']['uri'] ?: $lock['source']['uri'];
}
}

@ -59,10 +59,10 @@ class rcube_smtp
// let plugins alter smtp connection config
$CONFIG = $rcube->plugins->exec_hook('smtp_connect', array(
'smtp_server' => $host ? $host : $rcube->config->get('smtp_server'),
'smtp_port' => $port ? $port : $rcube->config->get('smtp_port', 25),
'smtp_user' => $user ? $user : $rcube->config->get('smtp_user'),
'smtp_pass' => $pass ? $pass : $rcube->config->get('smtp_pass'),
'smtp_server' => $host ?: $rcube->config->get('smtp_server'),
'smtp_port' => $port ?: $rcube->config->get('smtp_port', 25),
'smtp_user' => $user ?: $rcube->config->get('smtp_user'),
'smtp_pass' => $pass ?: $rcube->config->get('smtp_pass'),
'smtp_auth_cid' => $rcube->config->get('smtp_auth_cid'),
'smtp_auth_pw' => $rcube->config->get('smtp_auth_pw'),
'smtp_auth_type' => $rcube->config->get('smtp_auth_type'),
@ -145,7 +145,7 @@ class rcube_smtp
$smtp_user = str_replace('%u', $rcube->get_user_name(), $CONFIG['smtp_user']);
$smtp_pass = str_replace('%p', $rcube->get_user_password(), $CONFIG['smtp_pass']);
$smtp_auth_type = empty($CONFIG['smtp_auth_type']) ? NULL : $CONFIG['smtp_auth_type'];
$smtp_auth_type = $CONFIG['smtp_auth_type'] ?: null;
if (!empty($CONFIG['smtp_auth_cid'])) {
$smtp_authz = $smtp_user;

@ -67,7 +67,7 @@ class rcube_spellcheck_atd extends rcube_spellcheck_engine
if ($url) {
$a_uri = parse_url($url);
$ssl = ($a_uri['scheme'] == 'https' || $a_uri['scheme'] == 'ssl');
$port = $a_uri['port'] ? $a_uri['port'] : ($ssl ? 443 : 80);
$port = $a_uri['port'] ?: ($ssl ? 443 : 80);
$host = ($ssl ? 'ssl://' : '') . $a_uri['host'];
$path = $a_uri['path'] . ($a_uri['query'] ? '?'.$a_uri['query'] : '') . $this->lang;
}

@ -46,7 +46,7 @@ class rcube_spellchecker
{
$this->rc = rcube::get_instance();
$this->engine = $this->rc->config->get('spellcheck_engine', 'googie');
$this->lang = $lang ? $lang : 'en';
$this->lang = $lang ?: 'en';
$this->options = array(
'ignore_syms' => $this->rc->config->get('spellcheck_ignore_syms'),
@ -245,7 +245,7 @@ class rcube_spellchecker
*/
function error()
{
return $this->error ? $this->error : ($this->backend ? $this->backend->error() : false);
return $this->error ?: ($this->backend ? $this->backend->error() : false);
}
private function html2text($text)

@ -454,7 +454,7 @@ abstract class rcube_storage
{
$headers = $this->get_message_headers($uid);
return rcube_charset::convert($this->get_message_part($uid, $part, null),
$headers->charset ? $headers->charset : $this->default_charset);
$headers->charset ?: $this->default_charset);
}
/**

@ -234,7 +234,7 @@ class rcube_tnef_decoder
case self::MAPI_UNICODE_STRING:
case self::MAPI_BINARY:
case self::MAPI_OBJECT:
$num_vals = ($have_mval) ? $num_mval : $this->_geti($data, 32);
$num_vals = $have_mval ? $num_mval : $this->_geti($data, 32);
for ($i = 0; $i < $num_vals; $i++) {
$length = $this->_geti($data, 32);

@ -469,7 +469,7 @@ class rcube_utils
list($primary, $secondary) = explode('/', $mimetype);
$classes = array($primary ? $primary : 'unknown');
$classes = array($primary ?: 'unknown');
if ($secondary) {
$classes[] = $secondary;
@ -579,7 +579,7 @@ class rcube_utils
// %d - domain name without first part
$d = preg_replace('/^[^\.]+\./', '', $_SERVER['HTTP_HOST']);
// %h - IMAP host
$h = $_SESSION['storage_host'] ? $_SESSION['storage_host'] : $host;
$h = $_SESSION['storage_host'] ?: $host;
// %z - IMAP domain without first part, e.g. %h=imap.domain.tld, %z=domain.tld
$z = preg_replace('/^[^\.]+\./', '', $h);
// %s - domain name after the '@' from e-mail address provided at login screen.

@ -196,7 +196,7 @@ class rcube_vcard
}
while ($k < count($raw['type']) && ($subtype == 'internet' || $subtype == 'pref')) {
$subtype = $typemap[$raw['type'][++$k]] ? $typemap[$raw['type'][$k]] : strtolower($raw['type'][$k]);
$subtype = $typemap[$raw['type'][++$k]] ?: strtolower($raw['type'][$k]);
}
}
@ -207,7 +207,7 @@ class rcube_vcard
&& !in_array($k, array('pref','internet','voice','base64'))
) {
$k_uc = strtoupper($k);
$subtype = $typemap[$k_uc] ? $typemap[$k_uc] : $k;
$subtype = $typemap[$k_uc] ?: $k;
break;
}
}
@ -385,7 +385,7 @@ class rcube_vcard
$this->raw[$tag][$index] = (array)$value;
if ($type) {
$typemap = array_flip($this->typemap);
$this->raw[$tag][$index]['type'] = explode(',', ($typemap[$type_uc] ? $typemap[$type_uc] : $type));
$this->raw[$tag][$index]['type'] = explode(',', $typemap[$type_uc] ?: $type);
}
}
else {
@ -658,7 +658,7 @@ class rcube_vcard
// $entry['base64'] = true;
}
$data = self::decode_value($data, $enc ? $enc : 'base64');
$data = self::decode_value($data, $enc ?: 'base64');
}
else if ($field == 'PHOTO') {
// vCard 4.0 data URI, "PHOTO:data:image/jpeg;base64,..."

Loading…
Cancel
Save