From 66fab8cdb2b7160a34ed7d8074c7e8f413f21e91 Mon Sep 17 00:00:00 2001 From: Aleksander Machniak Date: Sat, 5 Oct 2019 19:44:39 +0200 Subject: [PATCH] CS fixes, Avoid usused variables, fixed minor bugs --- plugins/archive/archive.php | 40 +- plugins/debug_logger/runlog/runlog.php | 10 +- plugins/enigma/lib/enigma_driver_gnupg.php | 6 +- plugins/enigma/lib/enigma_engine.php | 2 +- plugins/enigma/lib/enigma_key.php | 32 +- plugins/enigma/lib/enigma_ui.php | 1 - .../filesystem_attachments.php | 5 +- plugins/help/help.php | 2 +- .../lib/Roundcube/rcube_sieve_engine.php | 2 +- .../lib/Roundcube/rcube_sieve_forward.php | 26 +- .../lib/Roundcube/rcube_sieve_vacation.php | 15 +- plugins/password/drivers/directadmin.php | 768 ++++++++---------- plugins/password/drivers/domainfactory.php | 2 - plugins/password/drivers/gearman.php | 2 +- plugins/password/drivers/ldap_simple.php | 2 +- plugins/password/drivers/virtualmin.php | 1 - plugins/password/drivers/zxcvbn.php | 1 - plugins/password/password.php | 1 - plugins/zipdownload/zipdownload.php | 1 - program/include/rcmail_install.php | 7 +- program/include/rcmail_output_html.php | 17 +- program/include/rcmail_sendmail.php | 8 +- program/lib/Roundcube/rcube_addressbook.php | 5 +- program/lib/Roundcube/rcube_contacts.php | 6 +- program/lib/Roundcube/rcube_html2text.php | 8 +- program/lib/Roundcube/rcube_imap.php | 10 +- program/lib/Roundcube/rcube_imap_generic.php | 37 +- program/lib/Roundcube/rcube_ldap.php | 30 +- program/lib/Roundcube/rcube_message.php | 12 +- program/lib/Roundcube/rcube_mime_decode.php | 2 - program/lib/Roundcube/rcube_result_index.php | 1 + .../Roundcube/rcube_result_multifolder.php | 8 +- program/lib/Roundcube/rcube_user.php | 4 +- program/steps/addressbook/print.inc | 2 - program/steps/addressbook/show.inc | 1 - program/steps/mail/func.inc | 1 - program/steps/mail/import.inc | 7 +- program/steps/mail/move_del.inc | 1 - 38 files changed, 512 insertions(+), 574 deletions(-) diff --git a/plugins/archive/archive.php b/plugins/archive/archive.php index 3218b6e25..ecd88f713 100644 --- a/plugins/archive/archive.php +++ b/plugins/archive/archive.php @@ -14,7 +14,13 @@ class archive extends rcube_plugin { public $task = 'settings|mail|login'; + private $archive_folder; + private $folders; + + /** + * Plugin initialization. + */ function init() { $rcmail = rcmail::get_instance(); @@ -22,9 +28,9 @@ class archive extends rcube_plugin // register special folder type rcube_storage::$folder_types[] = 'archive'; - $archive_folder = $rcmail->config->get('archive_mbox'); + $this->archive_folder = $rcmail->config->get('archive_mbox'); - if ($rcmail->task == 'mail' && ($rcmail->action == '' || $rcmail->action == 'show') && $archive_folder) { + if ($rcmail->task == 'mail' && ($rcmail->action == '' || $rcmail->action == 'show') && $this->archive_folder) { $this->include_stylesheet($this->local_skin_path() . '/archive.css'); $this->include_script('archive.js'); $this->add_texts('localization', true); @@ -47,7 +53,7 @@ class archive extends rcube_plugin $this->add_hook('render_mailboxlist', array($this, 'render_mailboxlist')); // set env variables for client - $rcmail->output->set_env('archive_folder', $archive_folder); + $rcmail->output->set_env('archive_folder', $this->archive_folder); $rcmail->output->set_env('archive_type', $rcmail->config->get('archive_type','')); } else if ($rcmail->task == 'mail') { @@ -58,11 +64,11 @@ class archive extends rcube_plugin $this->add_hook('preferences_list', array($this, 'prefs_table')); $this->add_hook('preferences_save', array($this, 'save_prefs')); - if ($rcmail->action == 'folders' && $archive_folder) { + if ($rcmail->action == 'folders' && $this->archive_folder) { $this->include_stylesheet($this->local_skin_path() . '/archive.css'); $this->include_script('archive.js'); // set env variables for client - $rcmail->output->set_env('archive_folder', $archive_folder); + $rcmail->output->set_env('archive_folder', $this->archive_folder); } } } @@ -72,18 +78,14 @@ class archive extends rcube_plugin */ function render_mailboxlist($p) { - $rcmail = rcmail::get_instance(); - $archive_folder = $rcmail->config->get('archive_mbox'); - $show_real_name = $rcmail->config->get('show_real_foldernames'); - // set localized name for the configured archive folder - if ($archive_folder && !$show_real_name) { - if (isset($p['list'][$archive_folder])) { - $p['list'][$archive_folder]['name'] = $this->gettext('archivefolder'); + if ($this->archive_folder && !rcmail::get_instance()->config->get('show_real_foldernames')) { + if (isset($p['list'][$this->archive_folder])) { + $p['list'][$this->archive_folder]['name'] = $this->gettext('archivefolder'); } else { // search in subfolders - $this->_mod_folder_name($p['list'], $archive_folder, $this->gettext('archivefolder')); + $this->_mod_folder_name($p['list'], $this->archive_folder, $this->gettext('archivefolder')); } } @@ -129,15 +131,13 @@ class archive extends rcube_plugin $delimiter = $storage->get_hierarchy_delimiter(); $read_on_move = (bool) $rcmail->config->get('read_on_archive'); $archive_type = $rcmail->config->get('archive_type', ''); - $archive_folder = $rcmail->config->get('archive_mbox'); - $archive_prefix = $archive_folder . $delimiter; + $archive_prefix = $this->archive_folder . $delimiter; $search_request = rcube_utils::get_input_value('_search', rcube_utils::INPUT_GPC); // count messages before changing anything if ($_POST['_from'] != 'show') { $threading = (bool) $storage->get_threading(); $old_count = $storage->count(null, $threading ? 'THREADS' : 'ALL'); - $old_pages = ceil($old_count / $storage->get_pagesize()); } $count = 0; @@ -152,12 +152,12 @@ class archive extends rcube_plugin ); foreach (rcmail::get_uids(null, null, $multifolder, rcube_utils::INPUT_POST) as $mbox => $uids) { - if (!$archive_folder || $mbox === $archive_folder || strpos($mbox, $archive_prefix) === 0) { + if (!$this->archive_folder || $mbox === $this->archive_folder || strpos($mbox, $archive_prefix) === 0) { $count = count($uids); continue; } else if (!$archive_type || $archive_type == 'folder') { - $folder = $archive_folder; + $folder = $this->archive_folder; if ($archive_type == 'folder') { // compose full folder path @@ -202,7 +202,7 @@ class archive extends rcube_plugin } // compose full folder path - $folder = $archive_folder . ($subfolder ? $delimiter . $subfolder : ''); + $folder = $this->archive_folder . ($subfolder ? $delimiter . $subfolder : ''); $execute[$folder][] = $message->uid; } @@ -348,7 +348,7 @@ class archive extends rcube_plugin $delimiter = $storage->get_hierarchy_delimiter(); if ($this->folders === null) { - $this->folders = $storage->list_folders('', $archive_folder . '*', 'mail', null, true); + $this->folders = $storage->list_folders('', $this->archive_folder . '*', 'mail', null, true); } if (!in_array($folder, $this->folders)) { diff --git a/plugins/debug_logger/runlog/runlog.php b/plugins/debug_logger/runlog/runlog.php index 6291a2fb7..460242f54 100644 --- a/plugins/debug_logger/runlog/runlog.php +++ b/plugins/debug_logger/runlog/runlog.php @@ -38,8 +38,8 @@ class runlog { $this->parent_stack[] = $name; - $this->print_to_console("start: ".$name, $tag, 'start'); - $this->print_to_file("start: ".$name, $tag, 'start'); + $this->print_to_console("start: ".$name, $tag); + $this->print_to_file("start: ".$name, $tag); $this->indent++; } @@ -72,8 +72,8 @@ class runlog { $tag_report .= "$tag: $count, "; } $end_txt = sprintf("end: $name - %0.4f seconds $tag_report", $this->run_log[$lastk]['duration']); - $this->print_to_console($end_txt, $this->run_log[$lastk]['tag'], 'end'); - $this->print_to_file($end_txt, $this->run_log[$lastk]['tag'], 'end'); + $this->print_to_console($end_txt, $this->run_log[$lastk]['tag']); + $this->print_to_file($end_txt, $this->run_log[$lastk]['tag']); } } @@ -137,7 +137,7 @@ class runlog { $this->print_to_console($msg, $tag); } - public function print_to_file($msg, $tag = false, $type = false) + public function print_to_file($msg, $tag = false) { if (!$tag) { $file_handle_tag = 'master'; diff --git a/plugins/enigma/lib/enigma_driver_gnupg.php b/plugins/enigma/lib/enigma_driver_gnupg.php index 80753f2ec..5af339836 100644 --- a/plugins/enigma/lib/enigma_driver_gnupg.php +++ b/plugins/enigma/lib/enigma_driver_gnupg.php @@ -574,8 +574,8 @@ class enigma_driver_gnupg extends enigma_driver $data_result = $db->query("SELECT `data`, `mtime` FROM $table" . " WHERE `file_id` = ?", $record['file_id']); - $data = $db->fetch_assoc($data_result); - $data = $data ? base64_decode($data['data']) : null; + $record = $db->fetch_assoc($data_result); + $data = $record ? base64_decode($record['data']) : null; if ($data === null || $data === false) { rcube::raise_error(array( @@ -590,7 +590,7 @@ class enigma_driver_gnupg extends enigma_driver if (file_put_contents($tmpfile, $data, LOCK_EX) === strlen($data)) { rename($tmpfile, $file); - touch($file, $data_record['mtime']); + touch($file, $record['mtime']); if ($this->debug) { $this->debug("SYNC: Fetched file: $file"); diff --git a/plugins/enigma/lib/enigma_engine.php b/plugins/enigma/lib/enigma_engine.php index 521c614d3..0f420bbe8 100644 --- a/plugins/enigma/lib/enigma_engine.php +++ b/plugins/enigma/lib/enigma_engine.php @@ -682,7 +682,7 @@ class enigma_engine $sig = $this->pgp_verify($msg_body, $sig_body); // Store signature data for display - $this->signatures[$struct->mime_id] = $sig; + $this->signatures[$struct->mime_id] = $sig; $this->signatures[$msg_part->mime_id] = $sig; } } diff --git a/plugins/enigma/lib/enigma_key.php b/plugins/enigma/lib/enigma_key.php index a4470da24..75ccf4fca 100644 --- a/plugins/enigma/lib/enigma_key.php +++ b/plugins/enigma/lib/enigma_key.php @@ -46,10 +46,12 @@ class enigma_key */ function get_type() { - if ($this->subkeys[0]->has_private) + if ($this->subkeys[0]->has_private) { return enigma_key::TYPE_KEYPAIR; - else if (!empty($this->subkeys[0])) + } + else if (!empty($this->subkeys[0])) { return enigma_key::TYPE_PUBLIC; + } return enigma_key::TYPE_UNKNOWN; } @@ -59,9 +61,11 @@ class enigma_key */ function is_revoked() { - foreach ($this->subkeys as $subkey) - if (!$subkey->revoked) + foreach ($this->subkeys as $subkey) { + if (!$subkey->revoked) { return false; + } + } return true; } @@ -71,9 +75,11 @@ class enigma_key */ function is_valid() { - foreach ($this->users as $user) - if ($user->valid) + foreach ($this->users as $user) { + if ($user->valid) { return true; + } + } return false; } @@ -85,9 +91,11 @@ class enigma_key { $now = time(); - foreach ($this->subkeys as $subkey) - if (!$subkey->expires || $subkey->expires > $now) + foreach ($this->subkeys as $subkey) { + if (!$subkey->expires || $subkey->expires > $now) { return true; + } + } return false; } @@ -97,11 +105,11 @@ class enigma_key */ function is_private() { - $now = time(); - - foreach ($this->subkeys as $subkey) - if ($subkey->has_private) + foreach ($this->subkeys as $subkey) { + if ($subkey->has_private) { return true; + } + } return false; } diff --git a/plugins/enigma/lib/enigma_ui.php b/plugins/enigma/lib/enigma_ui.php index 781ad1034..e95aec29a 100644 --- a/plugins/enigma/lib/enigma_ui.php +++ b/plugins/enigma/lib/enigma_ui.php @@ -1253,7 +1253,6 @@ class enigma_ui $uid = rcube_utils::get_input_value('_uid', rcube_utils::INPUT_POST); $mbox = rcube_utils::get_input_value('_mbox', rcube_utils::INPUT_POST); $mime_id = rcube_utils::get_input_value('_part', rcube_utils::INPUT_POST); - $storage = $this->rc->get_storage(); $engine = $this->enigma->load_engine(); if ($uid && $mime_id) { diff --git a/plugins/filesystem_attachments/filesystem_attachments.php b/plugins/filesystem_attachments/filesystem_attachments.php index ec32e763c..c77f402b6 100644 --- a/plugins/filesystem_attachments/filesystem_attachments.php +++ b/plugins/filesystem_attachments/filesystem_attachments.php @@ -71,8 +71,7 @@ class filesystem_attachments extends rcube_plugin function upload($args) { $args['status'] = false; - $group = $args['group']; - $rcmail = rcube::get_instance(); + $group = $args['group']; // use common temp dir for file uploads $tmpfname = rcube_utils::temp_filename('attmnt'); @@ -199,7 +198,7 @@ class filesystem_attachments extends rcube_plugin private function find_file_by_id($id) { - foreach ((array) $_SESSION['plugins']['filesystem_attachments'] as $group => $files) { + foreach ((array) $_SESSION['plugins']['filesystem_attachments'] as $files) { if (isset($files[$id])) { return true; } diff --git a/plugins/help/help.php b/plugins/help/help.php index bd18ec8d4..194e3fefa 100644 --- a/plugins/help/help.php +++ b/plugins/help/help.php @@ -143,7 +143,7 @@ class help extends rcube_plugin // resolve task/action for deep linking $rel = $_REQUEST['_rel']; - list($task, $action) = explode('/', $rel); + list($task, ) = explode('/', $rel); if ($add = $index_map[$rel]) { $src .= $add; } diff --git a/plugins/managesieve/lib/Roundcube/rcube_sieve_engine.php b/plugins/managesieve/lib/Roundcube/rcube_sieve_engine.php index 8d74b17db..da39cebd1 100644 --- a/plugins/managesieve/lib/Roundcube/rcube_sieve_engine.php +++ b/plugins/managesieve/lib/Roundcube/rcube_sieve_engine.php @@ -1564,7 +1564,7 @@ class rcube_sieve_engine } if ($compact) { - $select = new html_select(array('name' => '_join', 'id' => '_join' . $id, + $select = new html_select(array('name' => '_join', 'id' => '_join', 'onchange' => 'rule_join_radio(this.value)')); foreach (array('allof', 'anyof', 'any') as $val) { diff --git a/plugins/managesieve/lib/Roundcube/rcube_sieve_forward.php b/plugins/managesieve/lib/Roundcube/rcube_sieve_forward.php index db1c1b653..b4fcd4ced 100644 --- a/plugins/managesieve/lib/Roundcube/rcube_sieve_forward.php +++ b/plugins/managesieve/lib/Roundcube/rcube_sieve_forward.php @@ -200,18 +200,12 @@ class rcube_sieve_forward extends rcube_sieve_engine return; } - $date_extension = in_array('date', $this->exts); - $regex_extension = in_array('regex', $this->exts); + $status = rcube_utils::get_input_value('forward_status', rcube_utils::INPUT_POST); + $action = rcube_utils::get_input_value('forward_action', rcube_utils::INPUT_POST); + $target = rcube_utils::get_input_value('action_target', rcube_utils::INPUT_POST, true); - $status = rcube_utils::get_input_value('forward_status', rcube_utils::INPUT_POST); - $action = rcube_utils::get_input_value('forward_action', rcube_utils::INPUT_POST); - $target = rcube_utils::get_input_value('action_target', rcube_utils::INPUT_POST, true); - - $forward_action['type'] = 'forward'; - $forward_action['reason'] = $this->strip_value(str_replace("\r\n", "\n", $reason)); - $forward_action['subject'] = trim($subject); - $forward_action['from'] = trim($from); - $forward_tests = (array) $this->forward['tests']; + $date_extension = in_array('date', $this->exts); + $forward_tests = (array) $this->forward['tests']; if ($action == 'redirect' || $action == 'copy') { if (empty($target) || !rcube_utils::check_email($target)) { @@ -230,7 +224,7 @@ class rcube_sieve_forward extends rcube_sieve_engine $rule['disabled'] = $status == 'off'; $rule['tests'] = $forward_tests; $rule['join'] = $date_extension ? count($forward_tests) > 1 : false; - $rule['actions'] = array($forward_action); + $rule['actions'] = array(); $rule['after'] = $after; if ($action && $action != 'keep') { @@ -269,8 +263,8 @@ class rcube_sieve_forward extends rcube_sieve_engine // form elements - $status = new html_select(array('name' => 'forward_status', 'id' => 'forward_status')); - $action = new html_select(array('name' => 'forward_action', 'id' => 'forward_action')); + $status = new html_select(array('name' => 'forward_status', 'id' => 'forward_status')); + $action = new html_select(array('name' => 'forward_action', 'id' => 'forward_action')); $status->add($this->plugin->gettext('forward.on'), 'on'); $status->add($this->plugin->gettext('forward.off'), 'off'); @@ -455,7 +449,7 @@ class rcube_sieve_forward extends rcube_sieve_engine $this->init_script(); $this->forward_rule(); - $forward['type'] = 'forward'; + $date_extension = in_array('date', $this->exts); if ($data['action'] == 'redirect' || $data['action'] == 'copy') { if (empty($data['target']) || !rcube_utils::check_email($data['target'])) { @@ -478,7 +472,7 @@ class rcube_sieve_forward extends rcube_sieve_engine $rule['disabled'] = isset($data['enabled']) && !$data['enabled']; $rule['tests'] = $forward_tests; $rule['join'] = $date_extension ? count($forward_tests) > 1 : false; - $rule['actions'] = array($forward); + $rule['actions'] = array(); if ($data['action'] && $data['action'] != 'keep') { $rule['actions'][] = array( diff --git a/plugins/managesieve/lib/Roundcube/rcube_sieve_vacation.php b/plugins/managesieve/lib/Roundcube/rcube_sieve_vacation.php index 0792f115b..931750110 100644 --- a/plugins/managesieve/lib/Roundcube/rcube_sieve_vacation.php +++ b/plugins/managesieve/lib/Roundcube/rcube_sieve_vacation.php @@ -591,6 +591,7 @@ class rcube_sieve_vacation extends rcube_sieve_engine public static function vacation_interval(&$vacation) { $rcube = rcube::get_instance(); + $seconds_extension = in_array('vacation-seconds', $this->exts); if (isset($vacation['seconds'])) { $interval = $vacation['seconds']; @@ -720,9 +721,8 @@ class rcube_sieve_vacation extends rcube_sieve_engine $this->vacation_rule(); // check supported extensions - $date_extension = in_array('date', $this->exts); - $regex_extension = in_array('regex', $this->exts); - $seconds_extension = in_array('vacation-seconds', $this->exts); + $date_extension = in_array('date', $this->exts); + $regex_extension = in_array('regex', $this->exts); // set user's timezone try { @@ -754,8 +754,8 @@ class rcube_sieve_vacation extends rcube_sieve_engine else if ($regex_extension) { // Sieve 'date' extension not available, read start/end from RegEx based rules instead if ($date_tests = self::parse_regexp_tests($this->vacation['tests'])) { - $from = new DateTime($date_tests['from'] . ' ' . '00:00:00', $timezone); - $to = new DateTime($date_tests['to'] . ' ' . '23:59:59', $timezone); + $start = new DateTime($date_tests['from'] . ' ' . '00:00:00', $timezone); + $end = new DateTime($date_tests['to'] . ' ' . '23:59:59', $timezone); } } @@ -799,9 +799,8 @@ class rcube_sieve_vacation extends rcube_sieve_engine $this->vacation_rule(); // check supported extensions - $date_extension = in_array('date', $this->exts); - $regex_extension = in_array('regex', $this->exts); - $seconds_extension = in_array('vacation-seconds', $this->exts); + $date_extension = in_array('date', $this->exts); + $regex_extension = in_array('regex', $this->exts); $vacation['type'] = 'vacation'; $vacation['reason'] = $this->strip_value(str_replace("\r\n", "\n", $data['message'])); diff --git a/plugins/password/drivers/directadmin.php b/plugins/password/drivers/directadmin.php index 7444e1407..1b8a31d61 100644 --- a/plugins/password/drivers/directadmin.php +++ b/plugins/password/drivers/directadmin.php @@ -84,419 +84,369 @@ class rcube_directadmin_password * @author Phi1 'l0rdphi1' Stier * @package HTTPSocket * @version 3.0.2 + */ +class HTTPSocket +{ + var $version = '3.0.2'; + + // all vars are private except $error, $query_cache, and $doFollowLocationHeader + + var $method = 'GET'; + + var $remote_host; + var $remote_port; + var $remote_uname; + var $remote_passwd; + + var $result; + var $result_header; + var $result_body; + var $result_status_code; + + var $lastTransferSpeed; + var $bind_host; + var $error = array(); + var $warn = array(); + var $query_cache = array(); + var $doFollowLocationHeader = true; + var $redirectURL; + var $max_redirects = 5; + var $ssl_setting_message = 'DirectAdmin appears to be using SSL. Change your script to connect to ssl://'; + var $extra_headers = array(); + + /** + * Create server "connection". + * + */ + function connect($host, $port = '') + { + if (!is_numeric($port)) { + $port = 2222; + } - * 3.0.2 - * added longer curl timeouts + $this->remote_host = $host; + $this->remote_port = $port; + } - * 3.0.1 - * support for tcp:// conversion to http:// + function bind($ip = '') + { + if ($ip == '') { + $ip = $_SERVER['SERVER_ADDR']; + } - * 3.0.0 - * swapped to use curl to address ssl certificate issues with php 5.6 + $this->bind_host = $ip; + } - * 2.7.2 - * added x-use-https header check - * added max number of location redirects - * added custom settable message if x-use-https is found, so users can be told where to set their scripts - * if a redirect host is https, add ssl:// to remote_host + /** + * Change the method being used to communicate. + * + * @param string|null request method. supports GET, POST, and HEAD. default is GET + */ + function set_method($method = 'GET') + { + $this->method = strtoupper($method); + } - * 2.7.1 - * added isset to headers['location'], line 306 + /** + * Specify a username and password. + * + * @param string|null username. default is null + * @param string|null password. default is null + */ + function set_login($uname = '', $passwd = '') + { + if (strlen($uname) > 0) { + $this->remote_uname = $uname; + } - */ -class HTTPSocket { - - var $version = '3.0.2'; - - /* all vars are private except $error, $query_cache, and $doFollowLocationHeader */ - - var $method = 'GET'; - - var $remote_host; - var $remote_port; - var $remote_uname; - var $remote_passwd; - - var $result; - var $result_header; - var $result_body; - var $result_status_code; - - var $lastTransferSpeed; - - var $bind_host; - - var $error = array(); - var $warn = array(); - var $query_cache = array(); - - var $doFollowLocationHeader = TRUE; - var $redirectURL; - var $max_redirects = 5; - var $ssl_setting_message = 'DirectAdmin appears to be using SSL. Change your script to connect to ssl://'; - - var $extra_headers = array(); - - /** - * Create server "connection". - * - */ - function connect($host, $port = '' ) - { - if (!is_numeric($port)) - { - $port = 2222; - } - - $this->remote_host = $host; - $this->remote_port = $port; - } - - function bind( $ip = '' ) - { - if ( $ip == '' ) - { - $ip = $_SERVER['SERVER_ADDR']; - } - - $this->bind_host = $ip; - } - - /** - * Change the method being used to communicate. - * - * @param string|null request method. supports GET, POST, and HEAD. default is GET - */ - function set_method( $method = 'GET' ) - { - $this->method = strtoupper($method); - } - - /** - * Specify a username and password. - * - * @param string|null username. default is null - * @param string|null password. default is null - */ - function set_login( $uname = '', $passwd = '' ) - { - if ( strlen($uname) > 0 ) - { - $this->remote_uname = $uname; - } - - if ( strlen($passwd) > 0 ) - { - $this->remote_passwd = $passwd; - } - - } - - /** - * Query the server - * - * @param string containing properly formatted server API. See DA API docs and examples. Http:// URLs O.K. too. - * @param string|array query to pass to url - * @param int if connection KB/s drops below value here, will drop connection - */ - function query( $request, $content = '', $doSpeedCheck = 0 ) - { - $this->error = $this->warn = array(); - $this->result_status_code = NULL; - - $is_ssl = FALSE; - - // is our request a http:// ... ? - if (preg_match('!^http://!i',$request) || preg_match('!^https://!i',$request)) - { - $location = parse_url($request); - if (preg_match('!^https://!i',$request)) - { - $this->connect('https://'.$location['host'],$location['port']); - } - else - $this->connect('http://'.$location['host'],$location['port']); - - $this->set_login($location['user'],$location['pass']); - - $request = $location['path']; - $content = $location['query']; - - if ( strlen($request) < 1 ) - { - $request = '/'; - } - - } - - if (preg_match('!^ssl://!i', $this->remote_host)) - $this->remote_host = 'https://'.substr($this->remote_host, 6); - - if (preg_match('!^tcp://!i', $this->remote_host)) - $this->remote_host = 'http://'.substr($this->remote_host, 6); - - if (preg_match('!^https://!i', $this->remote_host)) - $is_ssl = TRUE; - - $array_headers = array( - 'Host' => ( $this->remote_port == 80 ? $this->remote_host : "$this->remote_host:$this->remote_port" ), - 'Accept' => '*/*', - 'Connection' => 'Close' ); - - foreach ( $this->extra_headers as $key => $value ) - { - $array_headers[$key] = $value; - } - - $this->result = $this->result_header = $this->result_body = ''; - - // was content sent as an array? if so, turn it into a string - if (is_array($content)) - { - $pairs = array(); - - foreach ( $content as $key => $value ) - { - $pairs[] = "$key=".urlencode($value); - } - - $content = join('&',$pairs); - unset($pairs); - } - - $OK = TRUE; - - if ($this->method == 'GET') - $request .= '?'.$content; - - $ch = curl_init($this->remote_host.':'.$this->remote_port.$request); - - if ($is_ssl) - { - curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); //1 - curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); //2 - //curl_setopt($ch, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1_2); - } - - curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); - curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); - curl_setopt($ch, CURLOPT_USERAGENT, "HTTPSocket/$this->version"); - curl_setopt($ch, CURLOPT_FORBID_REUSE, 1); - curl_setopt($ch, CURLOPT_TIMEOUT, 100); - curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); - curl_setopt($ch, CURLOPT_HEADER, 1); - - curl_setopt($ch, CURLOPT_LOW_SPEED_LIMIT, 512); - curl_setopt($ch, CURLOPT_LOW_SPEED_TIME, 120); - - //if ($this->doFollowLocationHeader) - //{ - // curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE); - // curl_setopt($ch, CURLOPT_MAXREDIRS, $this->max_redirects); - //} - - // instance connection - if ($this->bind_host) - { - curl_setopt($ch, CURLOPT_INTERFACE, $this->bind_host); - } - - // if we have a username and password, add the header - if ( isset($this->remote_uname) && isset($this->remote_passwd) ) - { - curl_setopt($ch, CURLOPT_USERPWD, $this->remote_uname.':'.$this->remote_passwd); - } - - // for DA skins: if $this->remote_passwd is NULL, try to use the login key system - if ( isset($this->remote_uname) && $this->remote_passwd == NULL ) - { - $array_headers['Cookie'] = "session={$_SERVER['SESSION_ID']}; key={$_SERVER['SESSION_KEY']}"; - } - - // if method is POST, add content length & type headers - if ( $this->method == 'POST' ) - { - curl_setopt($ch, CURLOPT_POST, 1); - curl_setopt($ch, CURLOPT_POSTFIELDS, $content); - - //$array_headers['Content-type'] = 'application/x-www-form-urlencoded'; - $array_headers['Content-length'] = strlen($content); - } - - curl_setopt($ch, CURLOPT_HTTPHEADER, $array_headers); - - - if( !($this->result = curl_exec($ch)) ) - { - $this->error[] .= curl_error($ch); - $OK = FALSE; - } - - $header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE); - $this->result_header = substr($this->result, 0, $header_size); - $this->result_body = substr($this->result, $header_size); - $this->result_status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); - - $this->lastTransferSpeed = curl_getinfo($ch, CURLINFO_SPEED_DOWNLOAD) / 1024; - - curl_close($ch); - - $this->query_cache[] = $this->remote_host.':'.$this->remote_port.$request; - - $headers = $this->fetch_header(); - - // did we get the full file? - if ( !empty($headers['content-length']) && $headers['content-length'] != strlen($this->result_body) ) - { - $this->result_status_code = 206; - } - - // now, if we're being passed a location header, should we follow it? - if ($this->doFollowLocationHeader) - { - //dont bother if we didn't even setup the script correctly - if (isset($headers['x-use-https']) && $headers['x-use-https']=='yes') - die($this->ssl_setting_message); - - if (isset($headers['location'])) - { - if ($this->max_redirects <= 0) - die("Too many redirects on: ".$headers['location']); - - $this->max_redirects--; - $this->redirectURL = $headers['location']; - $this->query($headers['location']); - } - } - - } - - function getTransferSpeed() - { - return $this->lastTransferSpeed; - } - - /** - * The quick way to get a URL's content :) - * - * @param string URL - * @param boolean return as array? (like PHP's file() command) - * @return string result body - */ - function get($location, $asArray = FALSE ) - { - $this->query($location); - - if ( $this->get_status_code() == 200 ) - { - if ($asArray) - { - return preg_split("/\n/",$this->fetch_body()); - } - - return $this->fetch_body(); - } - - return FALSE; - } - - /** - * Returns the last status code. - * 200 = OK; - * 403 = FORBIDDEN; - * etc. - * - * @return int status code - */ - function get_status_code() - { - return $this->result_status_code; - } - - /** - * Adds a header, sent with the next query. - * - * @param string header name - * @param string header value - */ - function add_header($key,$value) - { - $this->extra_headers[$key] = $value; - } - - /** - * Clears any extra headers. - * - */ - function clear_headers() - { - $this->extra_headers = array(); - } - - /** - * Return the result of a query. - * - * @return string result - */ - function fetch_result() - { - return $this->result; - } - - /** - * Return the header of result (stuff before body). - * - * @param string (optional) header to return - * @return array result header - */ - function fetch_header( $header = '' ) - { - $array_headers = preg_split("/\r\n/",$this->result_header); - - $array_return = array( 0 => $array_headers[0] ); - unset($array_headers[0]); - - foreach ( $array_headers as $pair ) - { - if ($pair == '' || $pair == "\r\n") continue; - list($key,$value) = preg_split("/: /",$pair,2); - $array_return[strtolower($key)] = $value; - } - - if ( $header != '' ) - { - return $array_return[strtolower($header)]; - } - - return $array_return; - } - - /** - * Return the body of result (stuff after header). - * - * @return string result body - */ - function fetch_body() - { - return $this->result_body; - } - - /** - * Return parsed body in array format. - * - * @return array result parsed - */ - function fetch_parsed_body() - { - parse_str($this->result_body,$x); - return $x; - } - - /** - * Set a specifc message on how to change the SSL setting, in the event that it's not set correctly. - */ - function set_ssl_setting_message($str) - { - $this->ssl_setting_message = $str; - } + if (strlen($passwd) > 0) { + $this->remote_passwd = $passwd; + } + + } + + /** + * Query the server + * + * @param string containing properly formatted server API. See DA API docs and examples. Http:// URLs O.K. too. + * @param string|array query to pass to url + */ + function query($request, $content = '') + { + $this->error = $this->warn = array(); + $this->result_status_code = null; + + $is_ssl = false; + + // is our request a http:// ... ? + if (preg_match('!^http://!i',$request) || preg_match('!^https://!i',$request)) { + $location = parse_url($request); + if (preg_match('!^https://!i',$request)) { + $this->connect('https://'.$location['host'],$location['port']); + } + else { + $this->connect('http://'.$location['host'],$location['port']); + } + + $this->set_login($location['user'],$location['pass']); + + $request = $location['path']; + $content = $location['query']; + + if (strlen($request) < 1) { + $request = '/'; + } + } + + if (preg_match('!^ssl://!i', $this->remote_host)) { + $this->remote_host = 'https://'.substr($this->remote_host, 6); + } + + if (preg_match('!^tcp://!i', $this->remote_host)) { + $this->remote_host = 'http://'.substr($this->remote_host, 6); + } + + if (preg_match('!^https://!i', $this->remote_host)) { + $is_ssl = true; + } + + $array_headers = array( + 'Host' => $this->remote_port == 80 ? $this->remote_host : "$this->remote_host:$this->remote_port", + 'Accept' => '*/*', + 'Connection' => 'Close' ); + + foreach ($this->extra_headers as $key => $value) { + $array_headers[$key] = $value; + } + + $this->result = $this->result_header = $this->result_body = ''; + + // was content sent as an array? if so, turn it into a string + if (is_array($content)) { + $pairs = array(); + + foreach ($content as $key => $value) { + $pairs[] = "$key=".urlencode($value); + } + + $content = join('&',$pairs); + unset($pairs); + } + + $OK = true; + + if ($this->method == 'GET') { + $request .= '?'.$content; + } + + $ch = curl_init($this->remote_host.':'.$this->remote_port.$request); + + if ($is_ssl) { + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); //1 + curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); //2 + //curl_setopt($ch, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1_2); + } + + curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); + curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); + curl_setopt($ch, CURLOPT_USERAGENT, "HTTPSocket/$this->version"); + curl_setopt($ch, CURLOPT_FORBID_REUSE, 1); + curl_setopt($ch, CURLOPT_TIMEOUT, 100); + curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); + curl_setopt($ch, CURLOPT_HEADER, 1); + + curl_setopt($ch, CURLOPT_LOW_SPEED_LIMIT, 512); + curl_setopt($ch, CURLOPT_LOW_SPEED_TIME, 120); + + // instance connection + if ($this->bind_host) { + curl_setopt($ch, CURLOPT_INTERFACE, $this->bind_host); + } + + // if we have a username and password, add the header + if (isset($this->remote_uname) && isset($this->remote_passwd)) { + curl_setopt($ch, CURLOPT_USERPWD, $this->remote_uname.':'.$this->remote_passwd); + } + + // for DA skins: if $this->remote_passwd is NULL, try to use the login key system + if (isset($this->remote_uname) && $this->remote_passwd == NULL) { + $array_headers['Cookie'] = "session={$_SERVER['SESSION_ID']}; key={$_SERVER['SESSION_KEY']}"; + } + + // if method is POST, add content length & type headers + if ($this->method == 'POST') { + curl_setopt($ch, CURLOPT_POST, 1); + curl_setopt($ch, CURLOPT_POSTFIELDS, $content); + + //$array_headers['Content-type'] = 'application/x-www-form-urlencoded'; + $array_headers['Content-length'] = strlen($content); + } + + curl_setopt($ch, CURLOPT_HTTPHEADER, $array_headers); + + if(!($this->result = curl_exec($ch))) { + $this->error[] .= curl_error($ch); + $OK = false; + } + + $header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE); + $this->result_header = substr($this->result, 0, $header_size); + $this->result_body = substr($this->result, $header_size); + $this->result_status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); + $this->lastTransferSpeed = curl_getinfo($ch, CURLINFO_SPEED_DOWNLOAD) / 1024; + + curl_close($ch); + + $this->query_cache[] = $this->remote_host.':'.$this->remote_port.$request; + + $headers = $this->fetch_header(); + + // did we get the full file? + if (!empty($headers['content-length']) && $headers['content-length'] != strlen($this->result_body)) { + $this->result_status_code = 206; + } + + // now, if we're being passed a location header, should we follow it? + if ($this->doFollowLocationHeader) { + //dont bother if we didn't even setup the script correctly + if (isset($headers['x-use-https']) && $headers['x-use-https'] == 'yes') { + die($this->ssl_setting_message); + } + + if (isset($headers['location'])) { + if ($this->max_redirects <= 0) { + die("Too many redirects on: ".$headers['location']); + } + + $this->max_redirects--; + $this->redirectURL = $headers['location']; + $this->query($headers['location']); + } + } + } + + function getTransferSpeed() + { + return $this->lastTransferSpeed; + } + + /** + * The quick way to get a URL's content :) + * + * @param string URL + * @param boolean return as array? (like PHP's file() command) + * @return string result body + */ + function get($location, $asArray = false) + { + $this->query($location); + + if ($this->get_status_code() == 200) { + if ($asArray) { + return preg_split("/\n/",$this->fetch_body()); + } + + return $this->fetch_body(); + } + + return false; + } + + /** + * Returns the last status code. + * 200 = OK; + * 403 = FORBIDDEN; + * etc. + * + * @return int status code + */ + function get_status_code() + { + return $this->result_status_code; + } + + /** + * Adds a header, sent with the next query. + * + * @param string header name + * @param string header value + */ + function add_header($key,$value) + { + $this->extra_headers[$key] = $value; + } + + /** + * Clears any extra headers. + * + */ + function clear_headers() + { + $this->extra_headers = array(); + } + + /** + * Return the result of a query. + * + * @return string result + */ + function fetch_result() + { + return $this->result; + } + + /** + * Return the header of result (stuff before body). + * + * @param string (optional) header to return + * @return array result header + */ + function fetch_header($header = '') + { + $array_headers = preg_split("/\r\n/",$this->result_header); + + $array_return = array(0 => $array_headers[0]); + unset($array_headers[0]); + + foreach ($array_headers as $pair) { + if ($pair == '' || $pair == "\r\n") continue; + list($key,$value) = preg_split("/: /",$pair,2); + $array_return[strtolower($key)] = $value; + } + + if ($header != '') { + return $array_return[strtolower($header)]; + } + + return $array_return; + } + + /** + * Return the body of result (stuff after header). + * + * @return string result body + */ + function fetch_body() + { + return $this->result_body; + } + + /** + * Return parsed body in array format. + * + * @return array result parsed + */ + function fetch_parsed_body() + { + parse_str($this->result_body,$x); + return $x; + } + + /** + * Set a specifc message on how to change the SSL setting, in the event that it's not set correctly. + */ + function set_ssl_setting_message($str) + { + $this->ssl_setting_message = $str; + } } diff --git a/plugins/password/drivers/domainfactory.php b/plugins/password/drivers/domainfactory.php index 513e31e36..0183af02e 100644 --- a/plugins/password/drivers/domainfactory.php +++ b/plugins/password/drivers/domainfactory.php @@ -30,8 +30,6 @@ class rcube_domainfactory_password { function save($curpass, $passwd, $username) { - $rcmail = rcmail::get_instance(); - if ($ch = curl_init()) { // initial login curl_setopt_array($ch, array( diff --git a/plugins/password/drivers/gearman.php b/plugins/password/drivers/gearman.php index a05e09a7f..21113d501 100644 --- a/plugins/password/drivers/gearman.php +++ b/plugins/password/drivers/gearman.php @@ -51,7 +51,7 @@ class rcube_gearman_password 'code' => 600, 'type' => 'php', 'file' => __FILE__, 'line' => __LINE__, - 'message' => "Password plugin: Gearman authentication failed for user $username: $error" + 'message' => "Password plugin: Gearman authentication failed for user $username" ), true, false); } } diff --git a/plugins/password/drivers/ldap_simple.php b/plugins/password/drivers/ldap_simple.php index 33e939dad..cd5665005 100644 --- a/plugins/password/drivers/ldap_simple.php +++ b/plugins/password/drivers/ldap_simple.php @@ -85,7 +85,7 @@ class rcube_ldap_simple_password $entry[$smblchattr] = time(); } - $this->_debug("C: Modify $user_dn: " . print_r($entry, true)); + $this->_debug("C: Modify {$this->user}: " . print_r($entry, true)); if (!ldap_modify($this->conn, $this->user, $entry)) { $this->_debug("S: ".ldap_error($this->conn)); diff --git a/plugins/password/drivers/virtualmin.php b/plugins/password/drivers/virtualmin.php index da8a59840..934b49057 100644 --- a/plugins/password/drivers/virtualmin.php +++ b/plugins/password/drivers/virtualmin.php @@ -33,7 +33,6 @@ class rcube_virtualmin_password { function save($currpass, $newpass, $username) { - $rcmail = rcmail::get_instance(); $curdir = RCUBE_PLUGINS_DIR . 'password/helpers'; $username = escapeshellarg($username); diff --git a/plugins/password/drivers/zxcvbn.php b/plugins/password/drivers/zxcvbn.php index 992fdc57a..0c80d73fe 100644 --- a/plugins/password/drivers/zxcvbn.php +++ b/plugins/password/drivers/zxcvbn.php @@ -55,7 +55,6 @@ class rcube_zxcvbn_password return; } - $rcmail = rcmail::get_instance(); $zxcvbn = new ZxcvbnPhp\Zxcvbn(); $strength = $zxcvbn->passwordStrength($passwd); diff --git a/plugins/password/password.php b/plugins/password/password.php index 9be83ecec..42ba96c2f 100644 --- a/plugins/password/password.php +++ b/plugins/password/password.php @@ -132,7 +132,6 @@ class password extends rcube_plugin $this->rc->output->set_pagetitle($this->gettext('changepasswd')); - $form_disabled = $this->rc->config->get('password_disabled'); $confirm = $this->rc->config->get('password_confirm_current'); $required_length = intval($this->rc->config->get('password_minimum_length')); $force_save = $this->rc->config->get('password_force_save'); diff --git a/plugins/zipdownload/zipdownload.php b/plugins/zipdownload/zipdownload.php index 5a53ef6cf..4e5562133 100644 --- a/plugins/zipdownload/zipdownload.php +++ b/plugins/zipdownload/zipdownload.php @@ -133,7 +133,6 @@ class zipdownload extends rcube_plugin // require CSRF protected request $rcmail->request_security_check(rcube_utils::INPUT_GET); - $imap = $rcmail->get_storage(); $tmpfname = rcube_utils::temp_filename('zipdownload'); $tempfiles = array($tmpfname); $message = new rcube_message(rcube_utils::get_input_value('_uid', rcube_utils::INPUT_GET)); diff --git a/program/include/rcmail_install.php b/program/include/rcmail_install.php index a7ef637c5..3166b90a5 100644 --- a/program/include/rcmail_install.php +++ b/program/include/rcmail_install.php @@ -474,10 +474,9 @@ class rcmail_install */ private function db_read_schema($schemafile) { - $lines = file($schemafile); - $table_block = false; - $schema = array(); - $keywords = array('PRIMARY','KEY','INDEX','UNIQUE','CONSTRAINT','REFERENCES','FOREIGN'); + $lines = file($schemafile); + $schema = array(); + $keywords = array('PRIMARY','KEY','INDEX','UNIQUE','CONSTRAINT','REFERENCES','FOREIGN'); foreach ($lines as $line) { if (preg_match('/^\s*create table ([\S]+)/i', $line, $m)) { diff --git a/program/include/rcmail_output_html.php b/program/include/rcmail_output_html.php index 429b9b6d0..a2c6f682f 100644 --- a/program/include/rcmail_output_html.php +++ b/program/include/rcmail_output_html.php @@ -653,7 +653,7 @@ EOF; $this->page_headers(); // call super method - $this->_write($template, $this->config->get('skin_path')); + $this->_write($template); } /** @@ -856,15 +856,15 @@ EOF; /** * Make URLs starting with a slash point to skin directory * - * @param string $str Input string - * @param bool $search_path True if URL should be resolved using the current skin path stack + * @param string $str Input string + * @param bool $search_path True if URL should be resolved using the current skin path stack * * @return string URL */ public function abs_url($str, $search_path = false) { if ($str[0] == '/') { - if ($search_path && ($file_url = $this->get_skin_file($str, $skin_path))) { + if ($search_path && ($file_url = $this->get_skin_file($str))) { return $file_url; } @@ -967,7 +967,7 @@ EOF; } // add file modification timestamp - if (preg_match('/\.(js|css|less|ico|png|svg|jpeg)$/', $file, $m)) { + if (preg_match('/\.(js|css|less|ico|png|svg|jpeg)$/', $file)) { $file = $this->file_mod($file); } @@ -1578,7 +1578,7 @@ EOF; // try to find out the button type if ($attrib['type']) { $attrib['type'] = strtolower($attrib['type']); - if ($pos = strpos($attrib['type'], '-menuitem')) { + if (strpos($attrib['type'], '-menuitem')) { $attrib['type'] = substr($attrib['type'], 0, -9); $menuitem = true; } @@ -1831,10 +1831,9 @@ EOF; /** * Process template and write to stdOut * - * @param string $output HTML output - * @param string $base_path Base for absolute paths + * @param string $output HTML output */ - protected function _write($output = '', $base_path = '') + protected function _write($output = '') { $output = trim($output); diff --git a/program/include/rcmail_sendmail.php b/program/include/rcmail_sendmail.php index d6730bb4c..b90c23912 100644 --- a/program/include/rcmail_sendmail.php +++ b/program/include/rcmail_sendmail.php @@ -233,7 +233,7 @@ class rcmail_sendmail * Set charset and transfer encoding on the message * * @param Mail_mime $message Message object - * @param bool $flowed Enable format=flowed + * @param bool $flowed Enable format=flowed */ public function set_message_encoding($message, $flowed = false) { @@ -248,7 +248,7 @@ class rcmail_sendmail else if (preg_match('/[^\x00-\x7F]/', $message->getTXTBody())) { $transfer_encoding = $this->rcmail->config->get('force_7bit') ? 'quoted-printable' : '8bit'; } - else if ($message_charset == 'UTF-8') { + else if ($this->options['charset'] == 'UTF-8') { $text_charset = 'US-ASCII'; } @@ -287,9 +287,9 @@ class rcmail_sendmail // Check if we have enough memory to handle the message in it // It's faster than using files, so we'll do this if we only can - if (is_array($attachments) && ($mem_limit = parse_bytes(ini_get('memory_limit')))) { + if (is_array($attachments)) { $memory = 0; - foreach ($attachments as $id => $attachment) { + foreach ($attachments as $attachment) { $memory += $attachment['size']; } diff --git a/program/lib/Roundcube/rcube_addressbook.php b/program/lib/Roundcube/rcube_addressbook.php index 137bf624d..bba633197 100644 --- a/program/lib/Roundcube/rcube_addressbook.php +++ b/program/lib/Roundcube/rcube_addressbook.php @@ -260,7 +260,7 @@ abstract class rcube_addressbook * * @return mixed The created record ID on success, False on error */ - function insert($save_data, $check=false) + function insert($save_data, $check = false) { /* empty for read-only address books */ } @@ -273,7 +273,7 @@ abstract class rcube_addressbook * * @return array List of created record IDs */ - function insertMultiple($recset, $check=false) + function insertMultiple($recset, $check = false) { $ids = array(); if (is_object($recset) && is_a($recset, rcube_result_set)) { @@ -282,6 +282,7 @@ abstract class rcube_addressbook $ids[] = $insert; } } + return $ids; } diff --git a/program/lib/Roundcube/rcube_contacts.php b/program/lib/Roundcube/rcube_contacts.php index dde613d57..8691cd80e 100644 --- a/program/lib/Roundcube/rcube_contacts.php +++ b/program/lib/Roundcube/rcube_contacts.php @@ -294,10 +294,8 @@ class rcube_contacts extends rcube_addressbook $required = array($required); } - $where = $and_where = $post_search = array(); + $where = $post_search = array(); $mode = intval($mode); - $WS = ' '; - $AS = self::SEPARATOR; // direct ID search if ($fields == 'ID' || $fields == $this->primary_key) { @@ -390,7 +388,7 @@ class rcube_contacts extends rcube_addressbook if (!empty($required)) { foreach ($required as $req) { $hit = false; - foreach ($row as $c => $values) { + foreach (array_keys($row) as $c) { if ($c === $req || strpos($c, $req.':') === 0) { if ((is_string($row[$c]) && strlen($row[$c])) || !empty($row[$c])) { $hit = true; diff --git a/program/lib/Roundcube/rcube_html2text.php b/program/lib/Roundcube/rcube_html2text.php index 0459917a1..080accb9a 100644 --- a/program/lib/Roundcube/rcube_html2text.php +++ b/program/lib/Roundcube/rcube_html2text.php @@ -666,7 +666,8 @@ class rcube_html2text * Callback function for preg_replace_callback use. * * @param array $matches PREG matches - * @return string + * + * @return string Element content */ public function tags_preg_callback($matches) { @@ -686,7 +687,8 @@ class rcube_html2text * Callback function for preg_replace_callback use in PRE content handler. * * @param array $matches PREG matches - * @return string + * + * @return string PRE content */ public function pre_preg_callback($matches) { @@ -697,6 +699,7 @@ class rcube_html2text * Strtoupper function with HTML tags and entities handling. * * @param string $str Text to convert + * * @return string Converted text */ private function _toupper($str) @@ -718,6 +721,7 @@ class rcube_html2text * Strtoupper multibyte wrapper function with HTML entities handling. * * @param string $str Text to convert + * * @return string Converted text */ private function _strtoupper($str) diff --git a/program/lib/Roundcube/rcube_imap.php b/program/lib/Roundcube/rcube_imap.php index 8b5d3e065..6e36b69af 100644 --- a/program/lib/Roundcube/rcube_imap.php +++ b/program/lib/Roundcube/rcube_imap.php @@ -2706,13 +2706,13 @@ class rcube_imap extends rcube_storage * * @return boolean True on success, False on error */ - public function copy_message($uids, $to_mbox, $from_mbox='') + public function copy_message($uids, $to_mbox, $from_mbox = '') { if (!strlen($from_mbox)) { $from_mbox = $this->folder; } - list($uids, $all_mode) = $this->parse_uids($uids); + list($uids, ) = $this->parse_uids($uids); // exit if no message uids are specified if (empty($uids)) { @@ -2736,12 +2736,12 @@ class rcube_imap extends rcube_storage /** * Mark messages as deleted and expunge them * - * @param mixed $uids Message UIDs as array or comma-separated string, or '*' - * @param string $folder Source folder + * @param mixed $uids Message UIDs as array or comma-separated string, or '*' + * @param string $folder Source folder * * @return boolean True on success, False on error */ - public function delete_message($uids, $folder='') + public function delete_message($uids, $folder = '') { if (!strlen($folder)) { $folder = $this->folder; diff --git a/program/lib/Roundcube/rcube_imap_generic.php b/program/lib/Roundcube/rcube_imap_generic.php index 09d582670..507fc09b9 100644 --- a/program/lib/Roundcube/rcube_imap_generic.php +++ b/program/lib/Roundcube/rcube_imap_generic.php @@ -2653,22 +2653,18 @@ class rcube_imap_generic */ public static function sortHeaders($messages, $field, $flag) { - // Strategy: First, we'll create an "index" array. - // Then, we'll use sort() on that array, and use that to sort the main array. - - $field = empty($field) ? 'uid' : strtolower($field); - $flag = empty($flag) ? 'ASC' : strtoupper($flag); - $index = array(); - $result = array(); + $field = empty($field) ? 'uid' : strtolower($field); + $order = empty($flag) ? 'ASC' : strtoupper($flag); + $index = array(); reset($messages); + // Create an index foreach ($messages as $key => $headers) { - $value = null; - switch ($field) { case 'arrival': $field = 'internaldate'; + // no-break case 'date': case 'internaldate': case 'timestamp': @@ -2684,33 +2680,26 @@ class rcube_imap_generic $value = $headers->$field; if (is_string($value)) { $value = str_replace('"', '', $value); + if ($field == 'subject') { $value = preg_replace('/^(Re:\s*|Fwd:\s*|Fw:\s*)+/i', '', $value); } - - $data = strtoupper($value); } } $index[$key] = $value; } - if (!empty($index)) { - // sort index - if ($flag == 'ASC') { - asort($index); - } - else { - arsort($index); - } + $sort_order = $flag == 'ASC' ? SORT_ASC : SORT_DESC; + $sort_flags = SORT_STRING | SORT_FLAG_CASE; - // form new array based on index - foreach ($index as $key => $val) { - $result[$key] = $messages[$key]; - } + if (in_array($field, array('arrival', 'date', 'internaldate', 'timestamp'))) { + $sort_flags = SORT_NUMERIC; } - return $result; + array_multisort($index, $sort_order, $sort_flags, $messages); + + return $messages; } /** diff --git a/program/lib/Roundcube/rcube_ldap.php b/program/lib/Roundcube/rcube_ldap.php index e222aab27..1c653d680 100644 --- a/program/lib/Roundcube/rcube_ldap.php +++ b/program/lib/Roundcube/rcube_ldap.php @@ -655,10 +655,11 @@ class rcube_ldap extends rcube_addressbook /** * Fetch members of the given group entry from server * - * @param string Group DN - * @param array Group entry - * @param string Member attribute to use - * @param boolean Count only + * @param string $dn Group DN + * @param array $entry Group entry + * @param string $attr Member attribute to use + * @param bool $count Count only + * * @return array Accumulated group members */ private function _list_group_members($dn, $entry, $attr, $count) @@ -699,16 +700,17 @@ class rcube_ldap extends rcube_addressbook /** * List members of group class groupOfUrls * - * @param string Group DN - * @param array Group entry - * @param boolean True if only used for counting + * @param string $dn Group DN + * @param array $entry Group entry + * @param boo $count True if only used for counting + * * @return array Accumulated group members */ private function _list_group_memberurl($dn, $entry, $count) { $group_members = array(); - for ($i=0; $i < $entry['memberurl']['count']; $i++) { + for ($i = 0; $i < $entry['memberurl']['count']; $i++) { // extract components from url if (!preg_match('!ldap://[^/]*/([^\?]+)\?\?(\w+)\?(.*)$!', $entry['memberurl'][$i], $m)) { continue; @@ -716,14 +718,17 @@ class rcube_ldap extends rcube_addressbook // add search filter if any $filter = $this->filter ? '(&(' . $m[3] . ')(' . $this->filter . '))' : $m[3]; - $attrs = $count ? array('dn','objectClass') : $this->prop['list_attributes']; + $attrs = $count ? array('dn','objectClass') : $this->prop['list_attributes']; + if ($result = $this->ldap->search($m[1], $filter, $m[2], $attrs, $this->group_data)) { $entries = $result->entries(); for ($j = 0; $j < $entries['count']; $j++) { - if ($this->is_group_entry($entries[$j]) && ($nested_group_members = $this->list_group_members($entries[$j]['dn'], $count))) + if ($this->is_group_entry($entries[$j]) && ($nested_group_members = $this->list_group_members($entries[$j]['dn'], $count))) { $group_members = array_merge($group_members, $nested_group_members); - else + } + else { $group_members[] = $entries[$j]; + } } } } @@ -751,7 +756,7 @@ class rcube_ldap extends rcube_addressbook * * @return rcube_result_set List of contact records */ - function search($fields, $value, $mode=0, $select=true, $nocount=false, $required=array()) + function search($fields, $value, $mode = 0, $select = true, $nocount = false, $required = array()) { $mode = intval($mode); @@ -925,7 +930,6 @@ class rcube_ldap extends rcube_addressbook $prop = $this->group_id ? $this->group_data : $this->prop; $base_dn = $this->group_id ? $prop['base_dn'] : $this->base_dn; $attrs = $count ? array('dn') : $this->prop['attributes']; - $entries = array(); // Use global search filter if ($filter = $this->filter) { diff --git a/program/lib/Roundcube/rcube_message.php b/program/lib/Roundcube/rcube_message.php index c6ef83709..e46adf01a 100644 --- a/program/lib/Roundcube/rcube_message.php +++ b/program/lib/Roundcube/rcube_message.php @@ -209,11 +209,11 @@ class rcube_message /** * Get content of a specific part of this message * - * @param string $mime_id Part ID - * @param boolean $formatted Enables formatting of text/* parts bodies - * @param int $max_bytes Only return/read this number of bytes - * @param mixed $mode NULL to return a string, -1 to print body - * or file pointer to save the body into + * @param string $mime_id Part ID + * @param bool $formatted Enables formatting of text/* parts bodies + * @param int $max_bytes Only return/read this number of bytes + * @param mixed $mode NULL to return a string, -1 to print body + * or file pointer to save the body into * * @return string|bool Part content or operation status */ @@ -1099,7 +1099,7 @@ class rcube_message // check parents' charset $items = explode('.', $part->mime_id); for ($i = count($items)-1; $i > 0; $i--) { - $last = array_pop($items); + array_pop($items); $parent = $this->mime_parts[implode('.', $items)]; if ($parent && $parent->charset) { diff --git a/program/lib/Roundcube/rcube_mime_decode.php b/program/lib/Roundcube/rcube_mime_decode.php index 94c6ec4c8..3ebc94576 100644 --- a/program/lib/Roundcube/rcube_mime_decode.php +++ b/program/lib/Roundcube/rcube_mime_decode.php @@ -375,8 +375,6 @@ class rcube_mime_decode $struct->charset = $part->ctype_parameters['charset']; } - $part_charset = $struct->charset ?: $this->params['default_charset']; - // determine filename if (($filename = $part->d_parameters['filename']) || ($filename = $part->ctype_parameters['name'])) { if (!$this->params['decode_headers']) { diff --git a/program/lib/Roundcube/rcube_result_index.php b/program/lib/Roundcube/rcube_result_index.php index d18b63b2e..45f542930 100644 --- a/program/lib/Roundcube/rcube_result_index.php +++ b/program/lib/Roundcube/rcube_result_index.php @@ -290,6 +290,7 @@ class rcube_result_index return $idx; } + return true; } diff --git a/program/lib/Roundcube/rcube_result_multifolder.php b/program/lib/Roundcube/rcube_result_multifolder.php index 974cd76d3..f538d47ca 100644 --- a/program/lib/Roundcube/rcube_result_multifolder.php +++ b/program/lib/Roundcube/rcube_result_multifolder.php @@ -166,7 +166,13 @@ class rcube_result_multifolder $msgid .= '-' . $this->folder; } - return array_search($msgid, $this->index); + $idx = array_search($msgid, $this->index); + + if ($get_index) { + return $idx; + } + + return $idx !== false; } /** diff --git a/program/lib/Roundcube/rcube_user.php b/program/lib/Roundcube/rcube_user.php index 7c38ac099..d907021af 100644 --- a/program/lib/Roundcube/rcube_user.php +++ b/program/lib/Roundcube/rcube_user.php @@ -503,7 +503,9 @@ class rcube_user */ function failed_login() { - if ($this->ID && ($rate = (int) $this->rc->config->get('login_rate_limit', 3))) { + if ($this->ID && $this->rc->config->get('login_rate_limit', 3)) { + $counter = 0; + if (empty($this->data['failed_login'])) { $failed_login = new DateTime('now'); $counter = 1; diff --git a/program/steps/addressbook/print.inc b/program/steps/addressbook/print.inc index a14517b2e..4a2e4fd08 100644 --- a/program/steps/addressbook/print.inc +++ b/program/steps/addressbook/print.inc @@ -81,8 +81,6 @@ function rcmail_contact_details($attrib) return false; } - $i_size = $attrib['size'] ?: 40; - $form = array( 'contact' => array( 'name' => $RCMAIL->gettext('properties'), diff --git a/program/steps/addressbook/show.inc b/program/steps/addressbook/show.inc index ee5c58802..c539e9b87 100644 --- a/program/steps/addressbook/show.inc +++ b/program/steps/addressbook/show.inc @@ -184,7 +184,6 @@ function rcmail_contact_record_groups($contact_id) 'noclose' => true, ); - $list = array(); $members = $CONTACTS->get_record_groups($contact_id); $table = new html_table(array('tagname' => 'ul', 'cols' => 1, 'class' => 'proplist simplelist')); $checkbox = new html_checkbox(array('name' => '_gid[]', diff --git a/program/steps/mail/func.inc b/program/steps/mail/func.inc index 60fd84146..9c3598132 100644 --- a/program/steps/mail/func.inc +++ b/program/steps/mail/func.inc @@ -1205,7 +1205,6 @@ function rcmail_washtml_link_callback($tag, $attribs, $content, $washtml) 'c' => $washtml->get_config('container_id'), 'p' => $washtml->get_config('css_prefix'), )); - $end = ' />'; $content = null; } else if (preg_match('/^mailto:(.+)/i', $attrib['href'], $mailto)) { diff --git a/program/steps/mail/import.inc b/program/steps/mail/import.inc index 995c12f75..678ccef34 100644 --- a/program/steps/mail/import.inc +++ b/program/steps/mail/import.inc @@ -125,9 +125,8 @@ function rcmail_zip_extract($path) return; } - $rcmail = rcmail::get_instance(); - $zip = new ZipArchive; - $files = array(); + $zip = new ZipArchive; + $files = array(); if ($zip->open($path)) { for ($i = 0; $i < $zip->numFiles; $i++) { @@ -136,7 +135,7 @@ function rcmail_zip_extract($path) if (copy("zip://$path#$entry", $tmpfname)) { $ctype = rcube_mime::file_content_type($tmpfname, $entry); - list($mtype_primary, $mtype_secondary) = explode('/', $ctype); + list($mtype_primary, ) = explode('/', $ctype); if (in_array($mtype_primary, array('text', 'message'))) { $files[] = $tmpfname; diff --git a/program/steps/mail/move_del.inc b/program/steps/mail/move_del.inc index a3cfd5f57..4aedfbfb7 100644 --- a/program/steps/mail/move_del.inc +++ b/program/steps/mail/move_del.inc @@ -29,7 +29,6 @@ $sources = array(); if ($_POST['_from'] != 'show') { $old_count = $RCMAIL->storage->count(NULL, $threading ? 'THREADS' : 'ALL'); - $old_pages = ceil($old_count / $RCMAIL->storage->get_pagesize()); } // move messages