/**
  * Modify user preferences
  *
  * @param string Option name
  * @param string Option value
  * @param int    Optional user identifier
  * @param string Optional value type (bool, int, string)
  */
 public static function mod_pref($name, $value, $userid = null, $type = 'string')
 {
     $db = self::db();
     if ($userid) {
         $query = '`user_id` = ' . intval($userid);
     } else {
         $query = '1=1';
     }
     $type = strtolower($type);
     if ($type == 'bool' || $type == 'boolean') {
         $value = rcube_utils::get_boolean($value);
     } else {
         if ($type == 'int' || $type == 'integer') {
             $value = (int) $value;
         }
     }
     // iterate over all users
     $sql_result = $db->query("SELECT * FROM " . $db->table_name('users', true) . " WHERE {$query}");
     while ($sql_result && ($sql_arr = $db->fetch_assoc($sql_result))) {
         echo "Updating prefs for user " . $sql_arr['user_id'] . "...";
         $user = new rcube_user($sql_arr['user_id'], $sql_arr);
         $prefs = $old_prefs = $user->get_prefs();
         $prefs[$name] = $value;
         if ($prefs != $old_prefs) {
             $user->save_prefs($prefs, true);
             echo "saved.\n";
         } else {
             echo "nothing changed.\n";
         }
     }
 }
 /**
  * GUI object 'loginform'
  * Returns code for the webmail login form
  *
  * @param array Named parameters
  * @return string HTML code for the gui object
  */
 protected function login_form($attrib)
 {
     $default_host = $this->config->get('default_host');
     $autocomplete = (int) $this->config->get('login_autocomplete');
     $_SESSION['temp'] = true;
     // save original url
     $url = rcube_utils::get_input_value('_url', rcube_utils::INPUT_POST);
     if (empty($url) && !preg_match('/_(task|action)=logout/', $_SERVER['QUERY_STRING'])) {
         $url = $_SERVER['QUERY_STRING'];
     }
     // Disable autocapitalization on iPad/iPhone (#1488609)
     $attrib['autocapitalize'] = 'off';
     // set atocomplete attribute
     $user_attrib = $autocomplete > 0 ? array() : array('autocomplete' => 'off');
     $host_attrib = $autocomplete > 0 ? array() : array('autocomplete' => 'off');
     $pass_attrib = $autocomplete > 1 ? array() : array('autocomplete' => 'off');
     $input_task = new html_hiddenfield(array('name' => '_task', 'value' => 'login'));
     $input_action = new html_hiddenfield(array('name' => '_action', 'value' => 'login'));
     $input_tzone = new html_hiddenfield(array('name' => '_timezone', 'id' => 'rcmlogintz', 'value' => '_default_'));
     $input_url = new html_hiddenfield(array('name' => '_url', 'id' => 'rcmloginurl', 'value' => $url));
     $input_user = new html_inputfield(array('name' => '_user', 'id' => 'rcmloginuser', 'required' => 'required') + $attrib + $user_attrib);
     $input_pass = new html_passwordfield(array('name' => '_pass', 'id' => 'rcmloginpwd', 'required' => 'required') + $attrib + $pass_attrib);
     $input_host = null;
     if (is_array($default_host) && count($default_host) > 1) {
         $input_host = new html_select(array('name' => '_host', 'id' => 'rcmloginhost'));
         foreach ($default_host as $key => $value) {
             if (!is_array($value)) {
                 $input_host->add($value, is_numeric($key) ? $value : $key);
             } else {
                 $input_host = null;
                 break;
             }
         }
     } else {
         if (is_array($default_host) && ($host = key($default_host)) !== null) {
             $hide_host = true;
             $input_host = new html_hiddenfield(array('name' => '_host', 'id' => 'rcmloginhost', 'value' => is_numeric($host) ? $default_host[$host] : $host) + $attrib);
         } else {
             if (empty($default_host)) {
                 $input_host = new html_inputfield(array('name' => '_host', 'id' => 'rcmloginhost') + $attrib + $host_attrib);
             }
         }
     }
     $form_name = !empty($attrib['form']) ? $attrib['form'] : 'form';
     $this->add_gui_object('loginform', $form_name);
     // create HTML table with two cols
     $table = new html_table(array('cols' => 2));
     $table->add('title', html::label('rcmloginuser', html::quote($this->app->gettext('username'))));
     $table->add('input', $input_user->show('mail@box'));
     $table->add('title', html::label('rcmloginpwd', html::quote($this->app->gettext('password'))));
     $table->add('input', $input_pass->show());
     // add host selection row
     if (is_object($input_host) && !$hide_host) {
         $table->add('title', html::label('rcmloginhost', html::quote($this->app->gettext('server'))));
         $table->add('input', $input_host->show(rcube_utils::get_input_value('_host', rcube_utils::INPUT_GPC)));
     }
     $out = $input_task->show();
     $out .= $input_action->show();
     $out .= $input_tzone->show();
     $out .= $input_url->show();
     $out .= $table->show();
     if ($hide_host) {
         $out .= $input_host->show();
     }
     if (rcube_utils::get_boolean($attrib['submit'])) {
         $submit = new html_inputfield(array('type' => 'submit', 'id' => 'rcmloginsubmit', 'class' => 'button mainaction', 'value' => $this->app->gettext('login')));
         $out .= html::p('formbuttons', $submit->show());
     }
     // surround html output with a form tag
     if (empty($attrib['form'])) {
         $out = $this->form_tag(array('name' => $form_name, 'method' => 'post'), $out);
     }
     // include script for timezone detection
     $this->include_script('jstz.min.js');
     return $out;
 }
示例#3
0
 /**
  * rcube_utils::get_boolean()
  */
 function test_get_boolean()
 {
     $input = array(false, 'false', '0', 'no', 'off', 'nein', 'FALSE', '', null);
     foreach ($input as $idx => $value) {
         $this->assertFalse(rcube_utils::get_boolean($value), "Invalid result for {$idx} test item");
     }
     $input = array(true, 'true', '1', 1, 'yes', 'anything', 1000);
     foreach ($input as $idx => $value) {
         $this->assertTrue(rcube_utils::get_boolean($value), "Invalid result for {$idx} test item");
     }
 }
示例#4
0
function get_boolean($str)
{
    return rcube_utils::get_boolean($str);
}
 /**
  * Callback function for parsing an xml command tag
  * and turn it into real html content
  *
  * @param  array Matches array of preg_replace_callback
  * @return string Tag/Object content
  */
 protected function xml_command($matches)
 {
     $command = strtolower($matches[1]);
     $attrib = html::parse_attrib_string($matches[2]);
     // empty output if required condition is not met
     if (!empty($attrib['condition']) && !$this->check_condition($attrib['condition'])) {
         return '';
     }
     // execute command
     switch ($command) {
         // return a button
         case 'button':
             if ($attrib['name'] || $attrib['command']) {
                 return $this->button($attrib);
             }
             break;
             // frame
         // frame
         case 'frame':
             return $this->frame($attrib);
             break;
             // show a label
         // show a label
         case 'label':
             if ($attrib['expression']) {
                 $attrib['name'] = $this->eval_expression($attrib['expression']);
             }
             if ($attrib['name'] || $attrib['command']) {
                 // @FIXME: 'noshow' is useless, remove?
                 if ($attrib['noshow']) {
                     return '';
                 }
                 $vars = $attrib + array('product' => $this->config->get('product_name'));
                 unset($vars['name'], $vars['command']);
                 $label = $this->app->gettext($attrib + array('vars' => $vars));
                 $quoting = !empty($attrib['quoting']) ? strtolower($attrib['quoting']) : (rcube_utils::get_boolean((string) $attrib['html']) ? 'no' : '');
                 switch ($quoting) {
                     case 'no':
                     case 'raw':
                         break;
                     case 'javascript':
                     case 'js':
                         $label = rcube::JQ($label);
                         break;
                     default:
                         $label = html::quote($label);
                         break;
                 }
                 return $label;
             }
             break;
             // include a file
         // include a file
         case 'include':
             $old_base_path = $this->base_path;
             if (!empty($attrib['skin_path'])) {
                 $attrib['skinpath'] = $attrib['skin_path'];
             }
             if ($path = $this->get_skin_file($attrib['file'], $skin_path, $attrib['skinpath'])) {
                 $this->base_path = preg_replace('!plugins/\\w+/!', '', $skin_path);
                 // set base_path to core skin directory (not plugin's skin)
                 $path = realpath($path);
             }
             if (is_readable($path)) {
                 if ($this->config->get('skin_include_php')) {
                     $incl = $this->include_php($path);
                 } else {
                     $incl = file_get_contents($path);
                 }
                 $incl = $this->parse_conditions($incl);
                 $incl = $this->parse_xml($incl);
                 $incl = $this->fix_paths($incl);
                 $this->base_path = $old_base_path;
                 return $incl;
             }
             break;
         case 'plugin.include':
             $hook = $this->app->plugins->exec_hook("template_plugin_include", $attrib);
             return $hook['content'];
             // define a container block
         // define a container block
         case 'container':
             if ($attrib['name'] && $attrib['id']) {
                 $this->command('gui_container', $attrib['name'], $attrib['id']);
                 // let plugins insert some content here
                 $hook = $this->app->plugins->exec_hook("template_container", $attrib);
                 return $hook['content'];
             }
             break;
             // return code for a specific application object
         // return code for a specific application object
         case 'object':
             $object = strtolower($attrib['name']);
             $content = '';
             // we are calling a class/method
             if (($handler = $this->object_handlers[$object]) && is_array($handler)) {
                 if (is_object($handler[0]) && method_exists($handler[0], $handler[1]) || is_string($handler[0]) && class_exists($handler[0])) {
                     $content = call_user_func($handler, $attrib);
                 }
             } else {
                 if (function_exists($handler)) {
                     $content = call_user_func($handler, $attrib);
                 } else {
                     if ($object == 'doctype') {
                         $content = html::doctype($attrib['value']);
                     } else {
                         if ($object == 'logo') {
                             $attrib += array('alt' => $this->xml_command(array('', 'object', 'name="productname"')));
                             if ($logo = $this->config->get('skin_logo')) {
                                 if (is_array($logo)) {
                                     if ($template_logo = $logo[$this->template_name]) {
                                         $attrib['src'] = $template_logo;
                                     } elseif ($template_logo = $logo['*']) {
                                         $attrib['src'] = $template_logo;
                                     }
                                 } else {
                                     $attrib['src'] = $logo;
                                 }
                             }
                             $content = html::img($attrib);
                         } else {
                             if ($object == 'productname') {
                                 $name = $this->config->get('product_name', 'Roundcube Webmail');
                                 $content = html::quote($name);
                             } else {
                                 if ($object == 'version') {
                                     $ver = (string) RCMAIL_VERSION;
                                     if (is_file(RCUBE_INSTALL_PATH . '.svn/entries')) {
                                         if (preg_match('/Revision:\\s(\\d+)/', @shell_exec('svn info'), $regs)) {
                                             $ver .= ' [SVN r' . $regs[1] . ']';
                                         }
                                     } else {
                                         if (is_file(RCUBE_INSTALL_PATH . '.git/index')) {
                                             if (preg_match('/Date:\\s+([^\\n]+)/', @shell_exec('git log -1'), $regs)) {
                                                 if ($date = date('Ymd.Hi', strtotime($regs[1]))) {
                                                     $ver .= ' [GIT ' . $date . ']';
                                                 }
                                             }
                                         }
                                     }
                                     $content = html::quote($ver);
                                 } else {
                                     if ($object == 'steptitle') {
                                         $content = html::quote($this->get_pagetitle());
                                     } else {
                                         if ($object == 'pagetitle') {
                                             if ($this->config->get('devel_mode') && !empty($_SESSION['username'])) {
                                                 $title = $_SESSION['username'] . ' :: ';
                                             } else {
                                                 if ($prod_name = $this->config->get('product_name')) {
                                                     $title = $prod_name . ' :: ';
                                                 } else {
                                                     $title = '';
                                                 }
                                             }
                                             $title .= $this->get_pagetitle();
                                             $content = html::quote($title);
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
             // exec plugin hooks for this template object
             $hook = $this->app->plugins->exec_hook("template_object_{$object}", $attrib + array('content' => $content));
             return $hook['content'];
             // return code for a specified eval expression
         // return code for a specified eval expression
         case 'exp':
             return html::quote($this->eval_expression($attrib['expression']));
             // return variable
         // return variable
         case 'var':
             $var = explode(':', $attrib['name']);
             $name = $var[1];
             $value = '';
             switch ($var[0]) {
                 case 'env':
                     $value = $this->env[$name];
                     break;
                 case 'config':
                     $value = $this->config->get($name);
                     if (is_array($value) && $value[$_SESSION['storage_host']]) {
                         $value = $value[$_SESSION['storage_host']];
                     }
                     break;
                 case 'request':
                     $value = rcube_utils::get_input_value($name, rcube_utils::INPUT_GPC);
                     break;
                 case 'session':
                     $value = $_SESSION[$name];
                     break;
                 case 'cookie':
                     $value = htmlspecialchars($_COOKIE[$name]);
                     break;
                 case 'browser':
                     $value = $this->browser->{$name};
                     break;
             }
             if (is_array($value)) {
                 $value = implode(', ', $value);
             }
             return html::quote($value);
         case 'form':
             return $this->form_tag($attrib);
     }
     return '';
 }
示例#6
0
function get_boolean($str)
{
    _deprecation_warning(__FUNCTION__);
    return rcube_utils::get_boolean($str);
}
示例#7
0
 /**
  * Upload form object
  *
  * @param array  $attrib     Object attributes
  * @param string $name       Form object name
  * @param string $action     Form action name
  * @param array  $input_attr File input attributes
  *
  * @return string HTML output
  */
 public function upload_form($attrib, $name, $action, $input_attr = array())
 {
     // Get filesize, enable upload progress bar
     $max_filesize = $this->upload_init();
     $hint = html::div('hint', $this->gettext(array('name' => 'maxuploadsize', 'vars' => array('size' => $max_filesize))));
     if ($attrib['mode'] == 'hint') {
         return $hint;
     }
     // set defaults
     $attrib += array('id' => 'rcmUploadbox', 'buttons' => 'yes');
     $event = rcmail_output::JS_OBJECT_NAME . ".command('{$action}', this.form)";
     $form_id = $attrib['id'] . 'Frm';
     // Default attributes of file input and form
     $input_attr += array('id' => $attrib['id'] . 'Input', 'type' => 'file', 'name' => '_attachments[]');
     $form_attr = array('id' => $form_id, 'name' => $name, 'method' => 'post', 'enctype' => 'multipart/form-data');
     if ($attrib['mode'] == 'smart') {
         unset($attrib['buttons']);
         $form_attr['class'] = 'smart-upload';
         $input_attr = array_merge($input_attr, array('onchange' => "if ((this.files && this.files.length) || (!this.files && this.value)) {$event}", 'class' => 'smart-upload', 'tabindex' => '-1'));
     }
     $input = new html_inputfield($input_attr);
     $content = $attrib['prefix'] . $input->show();
     if ($attrib['mode'] != 'smart') {
         $content = html::div(null, $content);
         $content .= $hint;
     }
     if (rcube_utils::get_boolean($attrib['buttons'])) {
         $button = new html_inputfield(array('type' => 'button'));
         $content .= html::div('buttons', $button->show($this->gettext('close'), array('class' => 'button', 'onclick' => "\$('#{$attrib['id']}').hide()")) . ' ' . $button->show($this->gettext('upload'), array('class' => 'button mainaction', 'onclick' => $event)));
     }
     $this->output->add_gui_object($name, $form_id);
     return html::div($attrib, $this->output->form_tag($form_attr, $content));
 }