This includes common methods for handling language data, timezones, and hostname->country lookups.
Author: Jon Parise (jon@horde.org)
Author: Chuck Hagenbuch (chuck@horde.org)
Author: Jan Schneider (jan@horde.org)
Author: Michael Slusarz (slusarz@horde.org)
Example #1
0
 /**
  */
 protected function _getValidationPattern()
 {
     static $pattern = '';
     if (!empty($pattern)) {
         return $pattern;
     }
     /* Get current locale information. */
     $linfo = Horde_Nls::getLocaleInfo();
     /* Build the pattern. */
     $pattern = '(-)?';
     /* Only check thousands separators if locale has any. */
     if (!empty($linfo['mon_thousands_sep'])) {
         /* Regex to check for correct thousands separators (if any). */
         $pattern .= '((\\d+)|((\\d{0,3}?)([' . $linfo['mon_thousands_sep'] . ']\\d{3})*?))';
     } else {
         /* No locale thousands separator, check for only digits. */
         $pattern .= '(\\d+)';
     }
     /* If no decimal point specified default to dot. */
     if (empty($linfo['mon_decimal_point'])) {
         $linfo['mon_decimal_point'] = '.';
     }
     /* Regex to check for correct decimals (if any). */
     if (empty($this->_fraction)) {
         $fraction = '*';
     } else {
         $fraction = '{0,' . $this->_fraction . '}';
     }
     $pattern .= '([' . $linfo['mon_decimal_point'] . '](\\d' . $fraction . '))?';
     /* Put together the whole regex pattern. */
     $pattern = '/^' . $pattern . '$/';
     return $pattern;
 }
Example #2
0
 /**
  * Add base javascript variables to the page.
  */
 protected function _addBaseVars()
 {
     global $conf, $injector, $prefs, $registry;
     $auth_name = $registry->getAuth();
     $has_tasks = Kronolith::hasApiPermission('tasks');
     $identity = $injector->getInstance('Horde_Core_Factory_Identity')->create();
     $app_urls = $js_vars = array();
     if (isset($conf['menu']['apps']) && is_array($conf['menu']['apps'])) {
         foreach ($conf['menu']['apps'] as $app) {
             $app_urls[$app] = strval(Horde::url($registry->getInitialPage($app), true));
         }
     }
     /* Variables used in core javascript files. */
     $js_vars['conf'] = array_filter(array('URI_CALENDAR_EXPORT' => str_replace(array('%23', '%2523', '%7B', '%257B', '%7D', '%257D'), array('#', '#', '{', '{', '}', '}'), strval($registry->downloadUrl('#{calendar}.ics', array('actionID' => 'export', 'all_events' => 1, 'exportID' => Horde_Data::EXPORT_ICALENDAR, 'exportCal' => 'internal_#{calendar}'))->setRaw(true))), 'URI_RESOURCE_EXPORT' => str_replace(array('%23', '%2523', '%7B', '%257B', '%7D', '%257D'), array('#', '#', '{', '{', '}', '}'), strval($registry->downloadUrl('#{calendar}.ics', array('actionID' => 'export', 'all_events' => 1, 'exportID' => Horde_Data::EXPORT_ICALENDAR, 'exportCal' => 'resource_#{calendar}'))->setRaw(true))), 'URI_EVENT_EXPORT' => str_replace(array('%23', '%7B', '%7D'), array('#', '{', '}'), Horde::url('event.php', true)->add(array('view' => 'ExportEvent', 'eventID' => '#{id}', 'calendar' => '#{calendar}', 'type' => '#{type}'))), 'images' => array('alarm' => strval(Horde_Themes::img('alarm-fff.png')), 'attendees' => strval(Horde_Themes::img('attendees-fff.png')), 'exception' => strval(Horde_Themes::img('exception-fff.png')), 'new_event' => strval(Horde_Themes::img('new.png')), 'new_task' => strval(Horde_Themes::img('new_task.png')), 'recur' => strval(Horde_Themes::img('recur-fff.png'))), 'new_event' => $injector->getInstance('Kronolith_View_Sidebar')->newLink . $injector->getInstance('Kronolith_View_Sidebar')->newText . '</a>', 'new_task' => $injector->getInstance('Kronolith_View_SidebarTasks')->newLink . $injector->getInstance('Kronolith_View_SidebarTasks')->newText . '</a>', 'user' => $registry->convertUsername($auth_name, false), 'name' => $identity->getName(), 'email' => strval($identity->getDefaultFromAddress()), 'prefs_url' => strval($registry->getServiceLink('prefs', 'kronolith')->setRaw(true)), 'app_urls' => $app_urls, 'name' => $registry->get('name'), 'has_tasks' => intval($has_tasks), 'has_resources' => intval(!empty($conf['resource']['driver'])), 'login_view' => $prefs->getValue('defaultview') == 'workweek' ? 'week' : $prefs->getValue('defaultview'), 'default_calendar' => 'internal|' . Kronolith::getDefaultCalendar(Horde_Perms::EDIT), 'max_events' => intval($prefs->getValue('max_events')), 'date_format' => Horde_Core_Script_Package_Datejs::translateFormat(Horde_Nls::getLangInfo(D_FMT)), 'time_format' => $prefs->getValue('twentyFour') ? 'HH:mm' : 'hh:mm tt', 'import_file' => Horde_Data::IMPORT_FILE, 'import_url' => Horde_Data::IMPORT_URL, 'show_time' => Kronolith::viewShowTime(), 'default_alarm' => intval($prefs->getValue('default_alarm')), 'status' => array('cancelled' => Kronolith::STATUS_CANCELLED, 'confirmed' => Kronolith::STATUS_CONFIRMED, 'free' => Kronolith::STATUS_FREE, 'tentative' => Kronolith::STATUS_TENTATIVE), 'recur' => array(Horde_Date_Recurrence::RECUR_NONE => 'None', Horde_Date_Recurrence::RECUR_DAILY => 'Daily', Horde_Date_Recurrence::RECUR_WEEKLY => 'Weekly', Horde_Date_Recurrence::RECUR_MONTHLY_DATE => 'Monthly', Horde_Date_Recurrence::RECUR_MONTHLY_WEEKDAY => 'Monthly', Horde_Date_Recurrence::RECUR_YEARLY_DATE => 'Yearly', Horde_Date_Recurrence::RECUR_YEARLY_DAY => 'Yearly', Horde_Date_Recurrence::RECUR_YEARLY_WEEKDAY => 'Yearly'), 'perms' => array('all' => Horde_Perms::ALL, 'show' => Horde_Perms::SHOW, 'read' => Horde_Perms::READ, 'edit' => Horde_Perms::EDIT, 'delete' => Horde_Perms::DELETE, 'delegate' => Kronolith::PERMS_DELEGATE), 'tasks' => $has_tasks ? $registry->tasks->ajaxDefaults() : null));
     /* Make sure this value is not optimized out by array_filter(). */
     $js_vars['conf']['week_start'] = intval($prefs->getValue('week_start_monday'));
     /* Gettext strings. */
     $js_vars['text'] = array('alarm' => _("Alarm:"), 'alerts' => _("Notifications"), 'allday' => _("All day"), 'delete_calendar' => _("Are you sure you want to delete this calendar and all the events in it?"), 'delete_tasklist' => _("Are you sure you want to delete this task list and all the tasks in it?"), 'external_category' => _("Other events"), 'fix_form_values' => _("Please enter correct values in the form first."), 'geocode_error' => _("Unable to locate requested address"), 'hidelog' => _("Hide Notifications"), 'import_warning' => _("Importing calendar data. This may take a while..."), 'more' => _("more..."), 'no_assignee' => _("None"), 'no_calendar_title' => _("The calendar title must not be empty."), 'no_parent' => _("No parent task"), 'no_tasklist_title' => _("The task list title must not be empty."), 'no_url' => _("You must specify a URL."), 'prefs' => _("Preferences"), 'searching' => sprintf(_("Events matching \"%s\""), '#{term}'), 'shared' => _("Shared"), 'tasks' => _("Tasks"), 'unknown_resource' => _("Unknown resource."), 'wrong_auth' => _("The authentication information you specified wasn't accepted."), 'wrong_date_format' => sprintf(_("You used an unknown date format \"%s\". Please try something like \"%s\"."), '#{wrong}', '#{right}'), 'wrong_time_format' => sprintf(_("You used an unknown time format \"%s\". Please try something like \"%s\"."), '#{wrong}', '#{right}'));
     for ($i = 1; $i <= 12; ++$i) {
         $js_vars['text']['month'][$i - 1] = Horde_Nls::getLangInfo(constant('MON_' . $i));
     }
     for ($i = 1; $i <= 7; ++$i) {
         $js_vars['text']['weekday'][$i] = Horde_Nls::getLangInfo(constant('DAY_' . $i));
     }
     foreach (array_diff(array_keys($js_vars['conf']['recur']), array(Horde_Date_Recurrence::RECUR_NONE)) as $recurType) {
         $js_vars['text']['recur'][$recurType] = Kronolith::recurToString($recurType);
     }
     $js_vars['text']['recur']['exception'] = _("Exception");
     // Maps
     $js_vars['conf']['maps'] = $conf['maps'];
     return $js_vars;
 }
Example #3
0
 /**
  * Constructor.
  *
  * @param array $config  Configuration key-value pairs.
  */
 public function __construct($config = array())
 {
     global $prefs, $registry;
     parent::__construct($config);
     $blank = new Horde_Url();
     $this->addNewButton(_("_New Event"), $blank, array('id' => 'kronolithNewEvent'));
     $this->newExtra = $blank->link(array_merge(array('id' => 'kronolithQuickEvent'), Horde::getAccessKeyAndTitle(_("Quick _insert"), false, true)));
     $sidebar = $GLOBALS['injector']->createInstance('Horde_View');
     /* Minical. */
     $today = new Horde_Date($_SERVER['REQUEST_TIME']);
     $sidebar->today = $today->format('F Y');
     $sidebar->weekdays = array();
     for ($i = $prefs->getValue('week_start_monday'), $c = $i + 7; $i < $c; $i++) {
         $weekday = Horde_Nls::getLangInfo(constant('DAY_' . ($i % 7 + 1)));
         $sidebar->weekdays[$weekday] = Horde_String::substr($weekday, 0, 2);
     }
     /* Calendars. */
     $sidebar->newShares = $registry->getAuth() && !$prefs->isLocked('default_share');
     $sidebar->admin = $registry->isAdmin();
     $sidebar->resourceAdmin = $registry->isAdmin() || $GLOBALS['injector']->getInstance('Horde_Core_Perms')->hasAppPermission('resource_management');
     $sidebar->resources = $GLOBALS['conf']['resources']['enabled'];
     $sidebar->addRemote = !$prefs->isLocked('remote_cals');
     $remotes = unserialize($prefs->getValue('remote_cals'));
     $sidebar->showRemote = !($prefs->isLocked('remote_cals') && empty($remotes));
     $this->content = $sidebar->render('dynamic/sidebar');
 }
Example #4
0
 /**
  * Returns avaiable countries
  */
 static function getCountries()
 {
     try {
         return Horde::loadConfiguration('countries.php', 'countries', 'folks');
     } catch (Horde_Exception $e) {
         return Horde_Nls::getCountryISO();
     }
 }
Example #5
0
 /**
  * Generate flag image object.
  *
  * @since 2.10.0
  *
  * @param string $host  The hostname.
  *
  * @return array  False if not found, or an array with these keys:
  * <pre>
  *   - name: (string) Country name.
  *   - ob: (Horde_Themes_Image) Image object.
  * </pre>
  */
 public static function getFlagImageObByHost($host)
 {
     global $conf;
     $data = Horde_Nls::getCountryByHost($host, empty($conf['geoip']['datafile']) ? null : $conf['geoip']['datafile']);
     if ($data === false) {
         return false;
     }
     return array('name' => $data['name'], 'ob' => Horde_Themes::img('flags/' . $data['code'] . '.png'));
 }
Example #6
0
 /**
  * Translates date format strings from strftime to datejs.
  *
  * @param string $format  A date format string in strftime syntax.
  *
  * @return string  The date format string in datejs format.
  */
 public static function translateFormat($format)
 {
     $from = array('%e', '%-d', '%d', '%a', '%A', '%-m', '%m', '%h', '%b', '%B', '%y', '%Y');
     $to = array(' d', 'd', 'dd', 'ddd', 'dddd', 'M', 'MM', 'MMM', 'MMM', 'MMMM', 'yy', 'yyyy');
     if (defined('D_FMT')) {
         $from[] = '%x';
         $to[] = str_replace($from, $to, Horde_Nls::getLangInfo(D_FMT));
     }
     return str_replace($from, $to, $format);
 }
Example #7
0
 /**
  * Generate flag image object.
  *
  * @since 2.10.0
  *
  * @param string $host  The hostname.
  *
  * @return array  False if not found, or an array with these keys:
  * <pre>
  *   - name: (string) Country name.
  *   - ob: (Horde_Themes_Image) Image object.
  * </pre>
  */
 public static function getFlagImageObByHost($host)
 {
     global $conf, $injector;
     if (!Horde_Nls::$dnsResolver) {
         Horde_Nls::$dnsResolver = $injector->getInstance('Net_DNS2_Resolver');
     }
     $data = Horde_Nls::getCountryByHost($host, empty($conf['geoip']['datafile']) ? null : $conf['geoip']['datafile']);
     if ($data === false) {
         return false;
     }
     return array('name' => $data['name'], 'ob' => Horde_Themes::img('flags/' . $data['code'] . '.png'));
 }
Example #8
0
 function _renderVarInput_number($form, $var, $vars)
 {
     $value = $var->getValue($vars);
     if ($var->type->fraction) {
         $value = sprintf('%01.' . $var->type->fraction . 'f', $value);
     }
     $linfo = Horde_Nls::getLocaleInfo();
     /* Only if there is a mon_decimal_point do the
      * substitution. */
     if (!empty($linfo['mon_decimal_point'])) {
         $value = str_replace('.', $linfo['mon_decimal_point'], $value);
     }
     return sprintf('    <input type="text" class="form-input-number" name="%1$s" id="%1$s" value="%2$s"%3$s />', $var->getVarName(), $value, $this->_getActionScripts($form, $var));
 }
Example #9
0
 /**
  * Display form
  *
  * @param integer $form_id      Form id dispaly
  * @param string $target_url    Target url to link form to
  */
 public function display($form_id, $target_url = null)
 {
     /* Get the stored form information from the backend. */
     try {
         $form_info = $GLOBALS['injector']->getInstance('Ulaform_Factory_Driver')->create()->getForm($form_id, Horde_Perms::READ);
     } catch (Horde_Exception $e) {
         throw new Ulaform_Exception($e->getMessage());
     }
     if (!empty($form_info['form_params']['language'])) {
         Horde_Nls::setLanguageEnvironment($form_info['form_params']['language']);
     }
     $vars = Horde_Variables::getDefaultVariables();
     $vars->set('form_id', $form_id);
     $form = new Horde_Form($vars);
     $form->addHidden('', 'form_id', 'int', false);
     $form->addHidden('', 'user_uid', 'text', false);
     $form->addHidden('', 'email', 'email', false);
     $vars->set('user_uid', $GLOBALS['registry']->getAuth());
     $vars->set('email', $GLOBALS['prefs']->getValue('from_addr'));
     try {
         $fields = $GLOBALS['injector']->getInstance('Ulaform_Factory_Driver')->create()->getFields($form_id);
     } catch (Ulaform_Exception $e) {
         throw new Ulaform_Exception($e->getMessage());
     }
     foreach ($fields as $field) {
         /* In case of these types get array from stringlist. */
         if ($field['field_type'] == 'link' || $field['field_type'] == 'enum' || $field['field_type'] == 'multienum' || $field['field_type'] == 'mlenum' || $field['field_type'] == 'radio' || $field['field_type'] == 'set' || $field['field_type'] == 'sorter') {
             $field['field_params']['values'] = Ulaform::getStringlistArray($field['field_params']['values']);
         }
         /* Setup the field with all the parameters. */
         $form->addVariable($field['field_label'], $field['field_name'], $field['field_type'], $field['field_required'], $field['field_readonly'], $field['field_desc'], $field['field_params']);
     }
     /* Check if submitted and validate. */
     $result = array('title' => $form_info['form_name']);
     if ($form->validate()) {
         $form->getInfo(null, $info);
         try {
             $GLOBALS['ulaform_driver']->submitForm($info);
             return true;
         } catch (Horde_Exception $e) {
             throw new Ulaform_Exception(sprintf(_("Error submitting form. %s."), $e->getMessage()));
         }
     }
     if (is_null($target_url)) {
         $target_url = Horde::selfUrl(true);
     }
     Horde::startBuffer();
     $form->renderActive(null, null, $target_url, 'post', 'multipart/form-data');
     return array('title' => $form_info['form_name'], 'form' => Horde::endBuffer());
 }
Example #10
0
 protected function _renderVarInput_number($form, &$var, &$vars)
 {
     $value = $var->getValue($vars);
     if ($var->type->getProperty('fraction')) {
         $value = sprintf('%01.' . $var->type->getProperty('fraction') . 'f', $value);
     }
     $linfo = Horde_Nls::getLocaleInfo();
     /* Only if there is a mon_decimal_point do the
      * substitution. */
     if (!empty($linfo['mon_decimal_point'])) {
         $value = str_replace('.', $linfo['mon_decimal_point'], $value);
     }
     return sprintf('<input type="text" size="5" name="%s" id="%s" value="%s"%s />', htmlspecialchars($var->getVarName()), $this->_genID($var->getVarName(), false), $value, $this->_getActionScripts($form, $var));
 }
Example #11
0
 /**
  * Add all kinds of variables and captions dependent on prefs, locale, state...
  * TODO: This could be stripped further and still serve demonstrational purposes
  */
 protected function _addBaseVars()
 {
     global $prefs, $injector, $conf, $registry;
     $app_urls = $js_vars = array();
     if (isset($conf['menu']['apps']) && is_array($conf['menu']['apps'])) {
         foreach ($conf['menu']['apps'] as $app) {
             $app_urls[$app] = strval(Horde::url($registry->getInitialPage($app), true));
         }
     }
     $identity = $injector->getInstance('Horde_Core_Factory_Identity')->create();
     $format_date = str_replace(array('%x', '%X'), array(Horde_Nls::getLangInfo(D_FMT, Horde_Nls::getLangInfo(D_T_FMT))), $prefs->getValue('date_format_mini'));
     /* Variables used in core javascript files. */
     $js_vars['conf'] = array('images' => array('timerlog' => (string) Horde_Themes::img('log.png')), 'user' => $registry->convertUsername($registry->getAuth(), false), 'prefs_url' => strval($registry->getServiceLink('prefs', 'hermes')->setRaw(true)), 'app_urls' => $app_urls, 'name' => $identity->getName(), 'login_view' => 'example1', 'date_format' => str_replace(array('%e', '%d', '%a', '%A', '%m', '%h', '%b', '%B', '%y', '%Y'), array('d', 'dd', 'ddd', 'dddd', 'MM', 'MMM', 'MMM', 'MMMM', 'yy', 'yyyy'), $format_date));
     /* Gettext strings used in core javascript files. */
     $js_vars['text'] = array('noalerts' => _("No Notifications"), 'alerts' => sprintf(_("%s notifications"), '#{count}'), 'hidelog' => _("Hide Notifications"), 'more' => _("more..."), 'prefs' => _("Preferences"));
     return $js_vars;
 }
Example #12
0
File: Ajax.php Project: horde/horde
 /**
  */
 protected function _addBaseVars()
 {
     global $prefs, $injector, $conf, $registry;
     $app_urls = $js_vars = array();
     if (isset($conf['menu']['apps']) && is_array($conf['menu']['apps'])) {
         foreach ($conf['menu']['apps'] as $app) {
             $app_urls[$app] = strval(Horde::url($registry->getInitialPage($app), true));
         }
     }
     $identity = $injector->getInstance('Horde_Core_Factory_Identity')->create();
     $format_date = str_replace(array('%x', '%X'), array(Horde_Nls::getLangInfo(D_FMT, Horde_Nls::getLangInfo(D_T_FMT))), $prefs->getValue('date_format_mini'));
     /* Variables used in core javascript files. */
     $js_vars['conf'] = array('URI_EXPORT' => (string) $registry->downloadUrl('time.csv', array('actionID' => 'export'))->setRaw(true), 'images' => array('timerlog' => (string) Horde_Themes::img('log.png'), 'timerplay' => (string) Horde_Themes::img('play.png'), 'timerpause' => (string) Horde_Themes::img('pause.png')), 'user' => $registry->convertUsername($registry->getAuth(), false), 'prefs_url' => strval($registry->getServiceLink('prefs', 'hermes')->setRaw(true)), 'app_urls' => $app_urls, 'name' => $identity->getName(), 'login_view' => 'time', 'date_format' => str_replace(array('%e', '%d', '%a', '%A', '%m', '%h', '%b', '%B', '%y', '%Y'), array('d', 'dd', 'ddd', 'dddd', 'MM', 'MMM', 'MMM', 'MMMM', 'yy', 'yyyy'), $format_date), 'client_name_field' => $conf['client']['field'], 'has_review_edit' => $injector->getInstance('Horde_Perms')->hasPermission('hermes:review', $GLOBALS['registry']->getAuth(), Horde_Perms::EDIT), 'has_review' => $registry->isAdmin(array('permission' => 'hermes:review')), 'has_timeadmin' => $registry->isAdmin(array('permission' => 'hermes:timeadmin')), 'has_deliverableadmin' => $registry->isAdmin(array('permission' => 'hermes:deliverables')));
     /* Gettext strings used in core javascript files. */
     $js_vars['text'] = array('noalerts' => _("No Notifications"), 'alerts' => sprintf(_("%s notifications"), '#{count}'), 'hidelog' => _("Hide Notifications"), 'more' => _("more..."), 'prefs' => _("Preferences"), 'fix_form_values' => _("Please enter correct values in the form first."), 'wrong_date_format' => sprintf(_("You used an unknown date format \"%s\". Please try something like \"%s\"."), '#{wrong}', '#{right}'), 'timeentry' => _("Time Entry"), 'edittime' => _("Editing Time Entry"), 'select_jobtype' => _("Select a Job Type"), 'missing_client' => _("You must select a client first."), 'billable' => _("Billable"), 'nonbillable' => _("Non billable"), 'hours' => _("Hours"), 'type' => _("Job Type"), 'budget' => _("Budget hours"));
     return $js_vars;
 }
Example #13
0
 /**
  */
 protected function _params()
 {
     // @todo Find a way to allow not loading the entire metar location
     // database in memory. I.e., allow entering free-form text like
     // the other weather block.
     try {
         $rows = $this->_weather->getLocations();
     } catch (Horde_Exception $e) {
         // No data available.
         return;
     }
     $locations = array();
     foreach ($rows as $row) {
         $locations[Horde_Nls_Translation::t(Horde_Nls::getCountryISO($row['country']))][$row['icao']] = sprintf('%s (%s, %s, %s)', $row['name'], !empty($row['municipality']) ? $row['municipality'] : '', $row['state'], $row['country']);
     }
     uksort($locations, 'strcoll');
     return array('location' => array('type' => 'mlenum', 'name' => _("Location"), 'default' => 'KSFB', 'values' => $locations), 'units' => array('type' => 'enum', 'name' => _("Units"), 'default' => Horde_Service_Weather::UNITS_STANDARD, 'values' => array(Horde_Service_Weather::UNITS_STANDARD => _("Standard"), Horde_Service_Weather::UNITS_METRIC => _("Metric"))), 'knots' => array('type' => 'checkbox', 'name' => _("Wind speed in knots"), 'default' => 0), 'taf' => array('type' => 'checkbox', 'name' => _("Display forecast (TAF)"), 'default' => 0));
 }
Example #14
0
$_prefs['compose_html'] = array('value' => 0, 'type' => 'enum', 'enum' => array(0 => _("Plain Text"), 1 => _("Rich Text (HTML)")), 'desc' => _("Default method to compose messages:"));
// For the HTML editor, this is the default font family.
// This needs to be in CSS-parseable format.
$_prefs['compose_html_font_family'] = array('value' => 'Arial', 'advanced' => true, 'locked' => true, 'type' => 'string', 'desc' => _("The default font family to use in the HTML editor."), 'requires' => array('compose_html'));
$_prefs['compose_html_font_size'] = array('value' => 14, 'advanced' => true, 'locked' => true, 'type' => 'number', 'desc' => _("The default font size to use in the HTML editor (in pixels)."), 'requires' => array('compose_html'));
$_prefs['compose_cursor'] = array('value' => 'top', 'type' => 'enum', 'enum' => array('top' => _("Top"), 'bottom' => _("Bottom")), 'desc' => _("Where should the cursor be located in the compose text area by default?"));
// Select widget for the 'default_encrypt' preference
$_prefs['encryptselect'] = array('type' => 'special', 'handler' => 'IMP_Prefs_Special_Encrypt', 'requires_nolock' => array('default_encrypt'));
// The default encryption method to use when sending messages
$_prefs['default_encrypt'] = array('value' => IMP::ENCRYPT_NONE);
$_prefs['delete_attachments_monthly_keep'] = array('value' => 6, 'advanced' => true, 'type' => 'number', 'zero' => true, 'desc' => _("Delete linked attachments after this many months (0 to never delete):"), 'help' => 'prefs-delete_attachments_monthly_keep', 'suppress' => function () {
    return empty($GLOBALS['conf']['compose']['link_attachments']);
});
$_prefs['request_mdn'] = array('value' => 'never', 'advanced' => true, 'type' => 'enum', 'enum' => array('never' => _("No"), 'always' => _("Yes")), 'desc' => _("Request read receipts?"), 'help' => 'prefs-request_mdn');
$_prefs['reply_lang'] = array('value' => 'a:0:{}', 'advanced' => true, 'type' => 'multienum', 'enum' => array(), 'desc' => _("What language(s) do you prefer replies to your messages to be in? (Hold down the CTRL key when clicking to add multiple languages)"), 'on_init' => function ($ui) {
    $enum = Horde_Nls::getLanguageISO();
    asort($enum);
    $ui->prefs['reply_lang']['enum'] = $enum;
});
// The list of buttons to show in CKeditor
// See http://docs.cksource.com/CKEditor_3.x/Developers_Guide/Toolbar for
// details on configuration
$_prefs['ckeditor_buttons'] = array('value' => "[['Bold','Italic','Underline'],['Font','FontSize'],['TextColor','BGColor'],['Cut','Copy','Paste'],['Undo','Redo'],['NumberedList','BulletedList'],['Link','Unlink'],['Image','Table','Smiley','SpecialChar']]");
$_prefs['signature_expanded'] = array('value' => 0, 'type' => 'implicit');
// *** Compose Templates Preferences ***
$prefGroups['composetemplates'] = array('column' => _("Compose"), 'label' => _("Compose Templates"), 'desc' => _("Edit compose templates."), 'members' => array('composetemplates_management', 'composetemplates_new'), 'suppress' => function () {
    return !$GLOBALS['injector']->getInstance('IMP_Factory_Imap')->create()->isImap();
});
// Compose templates configuration widget
$_prefs['composetemplates_management'] = array('type' => 'special', 'handler' => 'IMP_Prefs_Special_ComposeTemplates');
// Link to compose templates mailbox.
Example #15
0
 /**
  * Parses a complete date-time string into a Horde_Date object.
  *
  * @param string $date       The date-time string to parse.
  * @param boolean $withtime  Whether time is included in the string.
  *
  * @return Horde_Date  The parsed date.
  * @throws Horde_Date_Exception
  */
 public static function parseDate($date, $withtime = true)
 {
     // strptime() is not available on Windows.
     if (!function_exists('strptime')) {
         return new Horde_Date($date);
     }
     // strptime() is locale dependent, i.e. %p is not always matching
     // AM/PM. Set the locale to C to workaround this, but grab the
     // locale's D_FMT before that.
     $format = Horde_Nls::getLangInfo(D_FMT);
     if ($withtime) {
         $format .= ' ' . ($GLOBALS['prefs']->getValue('twentyFour') ? '%H:%M' : '%I:%M %p');
     }
     $old_locale = setlocale(LC_TIME, 0);
     setlocale(LC_TIME, 'C');
     // Try exact format match first.
     $date_arr = strptime($date, $format);
     setlocale(LC_TIME, $old_locale);
     if (!$date_arr) {
         // Try with locale dependent parsing next.
         $date_arr = strptime($date, $format);
         if (!$date_arr) {
             // Try throwing at Horde_Date finally.
             return new Horde_Date($date);
         }
     }
     return new Horde_Date(array('year' => $date_arr['tm_year'] + 1900, 'month' => $date_arr['tm_mon'] + 1, 'mday' => $date_arr['tm_mday'], 'hour' => $date_arr['tm_hour'], 'min' => $date_arr['tm_min'], 'sec' => $date_arr['tm_sec']));
 }
Example #16
0
<?php

/* Variables used in core javascript files. */
$code['conf'] = array('URI_AJAX' => (string) $GLOBALS['registry']->getServiceLink('ajax', 'nag'), 'date_format' => str_replace(array('%e', '%d', '%a', '%A', '%m', '%h', '%b', '%B', '%y', '%Y'), array('d', 'dd', 'ddd', 'dddd', 'MM', 'MMM', 'MMM', 'MMMM', 'yy', 'yyyy'), Horde_Nls::getLangInfo(D_FMT)), 'tasklist_info_url' => (string) Horde::url('tasklists/info.php'), 'time_format' => $GLOBALS['prefs']->getValue('twentyFour') ? 'HH:mm' : 'hh:mm tt');
/* Gettext strings used in core javascript files. */
$code['text'] = array('close' => _("Close"));
$GLOBALS['page_output']->addInlineJsVars(array('var Nag' => $code), array('top' => true));
Example #17
0
 /**
  * Given a 2-letter country code, returns a country string.
  *
  * @param string $code  The country code.
  *
  * @return string  The country string.
  */
 protected function _getName($code)
 {
     $code = Horde_String::upper($code);
     $geoip_codes = array('AP' => Horde_Nls_Translation::t("Asia/Pacific Region"), 'EU' => Horde_Nls_Translation::t("Europe"), 'A1' => Horde_Nls_Translation::t("Anonymous Proxy"), 'A2' => Horde_Nls_Translation::t("Satellite Provider"), 'O1' => Horde_Nls_Translation::t("Other"));
     return isset($geoip_codes[$code]) ? $geoip_codes[$code] : strval(Horde_Nls::getCountryISO($code));
 }
Example #18
0
 /**
  * Output the size of this MIME part in KB.
  *
  * @todo Remove $approx parameter.
  *
  * @param boolean $approx  If true, determines an approximate size for
  *                         parts consisting of base64 encoded data.
  *
  * @return string  Size of the part in KB.
  */
 public function getSize($approx = false)
 {
     if (!($bytes = $this->getBytes($approx))) {
         return 0;
     }
     $localeinfo = Horde_Nls::getLocaleInfo();
     // TODO: Workaround broken number_format() prior to PHP 5.4.0.
     return str_replace(array('X', 'Y'), array($localeinfo['decimal_point'], $localeinfo['thousands_sep']), number_format(ceil($bytes / 1024), 0, 'X', 'Y'));
 }
Example #19
0
$_prefs['language'] = array('value' => '', 'type' => 'enum', 'enum' => array(), 'escaped' => true, 'desc' => _("Select your preferred language:"), 'on_init' => function ($ui) {
    $enum = $GLOBALS['registry']->nlsconfig->languages;
    array_unshift($enum, _("Default"));
    $ui->prefs['language']['enum'] = $enum;
}, 'on_change' => function () {
    global $prefs, $registry;
    $registry->setLanguageEnvironment($prefs->getValue('language'));
    foreach ($registry->listApps() as $app) {
        if ($registry->isAuthenticated(array('app' => $app, 'notransparent' => true))) {
            $registry->callAppMethod($app, 'changeLanguage');
        }
    }
});
$_prefs['sending_charset'] = array('value' => 'UTF-8', 'advanced' => true, 'locked' => true, 'type' => 'enum', 'enum' => array_merge(array('' => _("Default")), $GLOBALS['registry']->nlsconfig->encodings_sort), 'desc' => _("Default charset for sending e-mail messages:"));
$_prefs['timezone'] = array('value' => '', 'type' => 'enum', 'enum' => array(), 'desc' => _("Your current time zone:"), 'on_init' => function ($ui) {
    $enum = Horde_Nls::getTimezones();
    array_unshift($enum, _("Default"));
    $ui->prefs['timezone']['enum'] = $enum;
});
$_prefs['twentyFour'] = array('value' => false, 'type' => 'checkbox', 'desc' => _("Display 24-hour times?"));
$_prefs['date_format'] = array('value' => '%x', 'type' => 'enum', 'enum' => array('%x' => strftime('%x'), '%Y-%m-%d' => strftime('%Y-%m-%d'), '%d/%m/%Y' => strftime('%d/%m/%Y'), '%A, %B %d, %Y' => strftime('%A, %B %d, %Y'), '%A, %d. %B %Y' => strftime('%A, %d. %B %Y'), '%A, %d %B %Y' => strftime('%A, %d %B %Y'), '%a, %b %e, %Y' => strftime('%a, %b %e, %Y'), '%a, %b %e, %y' => strftime('%a, %b %e, %y'), '%a, %b %e' => strftime('%a, %b %e'), '%a, %e %b %Y' => strftime('%a, %e %b %Y'), '%a, %e %b %y' => strftime('%a, %e %b %y'), '%a %d %b %Y' => strftime('%a %d %b %Y'), '%a %x' => strftime('%a %x'), '%a %Y-%m-%d' => strftime('%a %Y-%m-%d'), '%e %b %Y' => strftime('%e %b %Y'), '%e. %b %Y' => strftime('%e. %b %Y'), '%e. %m %Y' => strftime('%e %m %Y'), '%e. %m.' => strftime('%e. %m.'), '%e. %B' => strftime('%e. %B'), '%e. %B %Y' => strftime('%e. %B %Y'), '%e. %B %y' => strftime('%e. %B %y'), '%B %e, %Y' => strftime('%B %e, %Y')), 'desc' => _("Choose how to display dates (full format):"));
$_prefs['date_format_mini'] = array('value' => '%x', 'type' => 'enum', 'enum' => array('%x' => strftime('%x'), '%Y-%m-%d' => strftime('%Y-%m-%d'), '%d/%m/%Y' => strftime('%d/%m/%Y'), '%a, %b %e, %Y' => strftime('%a, %b %e, %Y'), '%a, %b %e, %y' => strftime('%a, %b %e, %y'), '%a, %b %e' => strftime('%a, %b %e'), '%a, %e %b %Y' => strftime('%a, %e %b %Y'), '%a, %e %b %y' => strftime('%a, %e %b %y'), '%a %d %b %Y' => strftime('%a %d %b %Y'), '%a %x' => strftime('%a %x'), '%a %Y-%m-%d' => strftime('%a %Y-%m-%d'), '%e %b %Y' => strftime('%e %b %Y'), '%e. %b %Y' => strftime('%e. %b %Y'), '%e. %m %Y' => strftime('%e %m %Y'), '%e. %m.' => strftime('%e. %m.'), '%b %e, %Y' => strftime('%b %e, %Y')), 'desc' => _("Choose how to display dates (abbreviated format):"));
$_prefs['time_format'] = array('value' => '%X', 'type' => 'enum', 'enum' => array('%X' => strftime('%X') . ' (' . _("Default") . ')', '%H:%M:%S' => strftime('%H:%M:%S') . ' (' . _("24-hour format") . ')', '%l:%M:%S %p' => strftime('%l:%M:%S %p')), 'desc' => _("Choose how to display times (full format):"));
$_prefs['time_format_mini'] = array('value' => '%X', 'type' => 'enum', 'enum' => array('%X' => strftime('%X') . ' (' . _("Default") . ')', '%H:%M' => strftime('%H:%M') . ' (' . _("24-hour format") . ')', '%l:%M %p' => strftime('%l:%M %p')), 'desc' => _("Choose how to display times (abbreviated format):"));
$_prefs['first_week_day'] = array('value' => '0', 'type' => 'enum', 'enum' => array('0' => _("Sunday"), '1' => _("Monday")), 'desc' => _("Which day would you like to be displayed as the first day of the week?"));
// *** Categories/Labels Preferences ***
$prefGroups['categories'] = array('column' => _("Your Information"), 'label' => _("Categories and Labels"), 'desc' => _("Manage the list of categories you have to label items with, and colors associated with those categories."), 'members' => array('categorymanagement'));
// UI for category management.
$_prefs['categorymanagement'] = array('type' => 'special', 'handler' => 'Horde_Prefs_Special_Category');
$_prefs['categories'] = array('value' => '');
$_prefs['category_colors'] = array('value' => '');
Example #20
0
 /**
  * Determines the reply text and headers for a message.
  *
  * @param integer $type           The reply type (self::REPLY* constant).
  * @param IMP_Contents $contents  An IMP_Contents object.
  * @param array $opts             Additional options:
  *   - format: (string) Force to this format.
  *             DEFAULT: Auto-determine.
  *   - to: (string) The recipient of the reply. Overrides the
  *         automatically determined value.
  *
  * @return array  An array with the following keys:
  *   - addr: (array) Address lists (to, cc, bcc; Horde_Mail_Rfc822_List
  *           objects).
  *   - body: (string) The text of the body part.
  *   - format: (string) The format of the body message (html, text).
  *   - identity: (integer) The identity to use for the reply based on the
  *               original message's addresses.
  *   - lang: (array) Language code (keys)/language name (values) of the
  *           original sender's preferred language(s).
  *   - reply_list_id: (string) List ID label.
  *   - reply_recip: (integer) Number of recipients in reply list.
  *   - subject: (string) Formatted subject.
  *   - type: (integer) The reply type used (either self::REPLY_ALL,
  *           self::REPLY_LIST, or self::REPLY_SENDER).
  * @throws IMP_Exception
  */
 public function replyMessage($type, $contents, array $opts = array())
 {
     global $injector, $language, $prefs;
     if (!$contents instanceof IMP_Contents) {
         throw new IMP_Exception(_("Could not retrieve message data from the mail server."));
     }
     $alist = new Horde_Mail_Rfc822_List();
     $addr = array('to' => clone $alist, 'cc' => clone $alist, 'bcc' => clone $alist);
     $h = $contents->getHeader();
     $match_identity = $this->_getMatchingIdentity($h);
     $reply_type = self::REPLY_SENDER;
     if (!$this->_replytype) {
         $this->_setMetadata('indices', $contents->getIndicesOb());
         /* Set the Message-ID related headers (RFC 5322 [3.6.4]). */
         if ($tmp = $h['Message-ID']) {
             $msg_id = $tmp->getIdentificationOb();
             $msg_id = reset($msg_id->ids);
             if (strlen($msg_id)) {
                 $this->_setMetadata('in_reply_to', $msg_id);
             }
         } else {
             $msg_id = null;
         }
         if ($tmp = $h['References']) {
             $ref_ob = $tmp->getIdentificationOb();
             if (!count($ref_ob->ids) && ($tmp = $h['In-Reply-To'])) {
                 $ref_ob = $tmp->getIdentificationOb();
                 if (count($ref_ob->ids) > 1) {
                     $ref_ob->ids = array();
                 }
             }
             if (count($ref_ob->ids)) {
                 $this->_setMetadata('references', array_merge($ref_ob->ids, array_filter(array($msg_id))));
             }
         }
     }
     $subject = strlen($s = $h['Subject']) ? 'Re: ' . strval(new Horde_Imap_Client_Data_BaseSubject($s, array('keepblob' => true))) : 'Re: ';
     $force = false;
     if (in_array($type, array(self::REPLY_AUTO, self::REPLY_SENDER))) {
         if (isset($opts['to'])) {
             $addr['to']->add($opts['to']);
             $force = true;
         } elseif ($tmp = $h['reply-to']) {
             $addr['to']->add($tmp->getAddressList());
             $force = true;
         } elseif ($tmp = $h['from']) {
             $addr['to']->add($tmp->getAddressList());
         }
     } elseif ($type === self::REPLY_ALL) {
         $force = isset($h['reply-to']);
     }
     /* We might need $list_info in the reply_all section. */
     $list_info = in_array($type, array(self::REPLY_AUTO, self::REPLY_LIST)) ? $contents->getListInformation() : null;
     if (!is_null($list_info) && !empty($list_info['reply_list'])) {
         /* If To/Reply-To and List-Reply address are the same, no need
          * to handle these address separately. */
         $rlist = new Horde_Mail_Rfc822_Address($list_info['reply_list']);
         if (!$rlist->match($addr['to'])) {
             $addr['to'] = clone $alist;
             $addr['to']->add($rlist);
             $reply_type = self::REPLY_LIST;
         }
     } elseif (in_array($type, array(self::REPLY_ALL, self::REPLY_AUTO))) {
         /* Clear the To field if we are auto-determining addresses. */
         if ($type == self::REPLY_AUTO) {
             $addr['to'] = clone $alist;
         }
         /* Filter out our own address from the addresses we reply to. */
         $identity = $injector->getInstance('IMP_Identity');
         $all_addrs = $identity->getAllFromAddresses();
         /* Build the To: header. It is either:
          * 1) the Reply-To address (if not a personal address)
          * 2) the From address(es) (if it doesn't contain a personal
          * address)
          * 3) all remaining Cc addresses. */
         $to_fields = array('from', 'reply-to');
         foreach (array('reply-to', 'from', 'to', 'cc') as $val) {
             /* If either a reply-to or $to is present, we use this address
              * INSTEAD of the from address. */
             if ($force && $val == 'from' || !($tmp = $h[$val])) {
                 continue;
             }
             $ob = $tmp->getAddressList(true);
             /* For From: need to check if at least one of the addresses is
              * personal. */
             if ($val == 'from') {
                 foreach ($ob->raw_addresses as $addr_ob) {
                     if ($all_addrs->contains($addr_ob)) {
                         /* The from field contained a personal address.
                          * Use the 'To' header as the primary reply-to
                          * address instead. */
                         $to_fields[] = 'to';
                         /* Add other non-personal from addresses to the
                          * list of CC addresses. */
                         $ob->setIteratorFilter($ob::BASE_ELEMENTS, $all_addrs);
                         $addr['cc']->add($ob);
                         $all_addrs->add($ob);
                         continue 2;
                     }
                 }
             }
             $ob->setIteratorFilter($ob::BASE_ELEMENTS, $all_addrs);
             foreach ($ob as $hdr_ob) {
                 if ($hdr_ob instanceof Horde_Mail_Rfc822_Group) {
                     $addr['cc']->add($hdr_ob);
                     $all_addrs->add($hdr_ob->addresses);
                 } elseif ($val != 'to' || is_null($list_info) || !$force || empty($list_info['exists'])) {
                     /* Don't add as To address if this is a list that
                      * doesn't have a post address but does have a
                      * reply-to address. */
                     if (in_array($val, $to_fields)) {
                         /* If from/reply-to doesn't have personal
                          * information, check from address. */
                         if (is_null($hdr_ob->personal) && ($tmp = $h['from']) && ($to_ob = $tmp->getAddressList(true)->first()) && !is_null($to_ob->personal) && $hdr_ob->match($to_ob)) {
                             $addr['to']->add($to_ob);
                         } else {
                             $addr['to']->add($hdr_ob);
                         }
                     } else {
                         $addr['cc']->add($hdr_ob);
                     }
                     $all_addrs->add($hdr_ob);
                 }
             }
         }
         /* Build the Cc: (or possibly the To:) header. If this is a
          * reply to a message that was already replied to by the user,
          * this reply will go to the original recipients (Request
          * #8485).  */
         if (count($addr['cc'])) {
             $reply_type = self::REPLY_ALL;
         }
         if (!count($addr['to'])) {
             $addr['to'] = $addr['cc'];
             $addr['cc'] = clone $alist;
         }
         /* Build the Bcc: header. */
         if ($tmp = $h['bcc']) {
             $bcc = $tmp->getAddressList(true);
             $bcc->add($identity->getBccAddresses());
             $bcc->setIteratorFilter(0, $all_addrs);
             foreach ($bcc as $val) {
                 $addr['bcc']->add($val);
             }
         }
     }
     if (!$this->_replytype || $reply_type != $this->_replytype) {
         $this->_replytype = $reply_type;
         $this->changed = 'changed';
     }
     $ret = $this->replyMessageText($contents, array('format' => isset($opts['format']) ? $opts['format'] : null));
     if ($prefs->getValue('reply_charset') && $ret['charset'] != $this->charset) {
         $this->charset = $ret['charset'];
         $this->changed = 'changed';
     }
     unset($ret['charset']);
     if ($type == self::REPLY_AUTO) {
         switch ($reply_type) {
             case self::REPLY_ALL:
                 try {
                     $recip_list = $this->recipientList($addr);
                     $ret['reply_recip'] = count($recip_list['list']);
                 } catch (IMP_Compose_Exception $e) {
                     $ret['reply_recip'] = 0;
                 }
                 break;
             case self::REPLY_LIST:
                 if (($list_parse = $injector->getInstance('Horde_ListHeaders')->parse('list-id', strval($h['List-Id']))) && !is_null($list_parse->label)) {
                     $ret['reply_list_id'] = $list_parse->label;
                 }
                 break;
         }
     }
     if (($lang = $h['Accept-Language']) || ($lang = $h['X-Accept-Language'])) {
         $langs = array();
         foreach (explode(',', $lang->value_single) as $val) {
             if (($name = Horde_Nls::getLanguageISO($val)) !== null) {
                 $langs[trim($val)] = $name;
             }
         }
         $ret['lang'] = array_unique($langs);
         /* Don't show display if original recipient is asking for reply in
          * the user's native language. */
         if (count($ret['lang']) == 1 && reset($ret['lang']) && substr(key($ret['lang']), 0, 2) == substr($language, 0, 2)) {
             unset($ret['lang']);
         }
     }
     return array_merge(array('addr' => $addr, 'identity' => $match_identity, 'subject' => $subject, 'type' => $reply_type), $ret);
 }
Example #21
0
 function init($prompt = null)
 {
     parent::init(Horde_Nls::getCountryISO(), $prompt);
 }
Example #22
0
 /**
  * Callback used to replace a strtime pattern
  *
  * @param array $matches  preg_replace_callback() matches.
  *
  * @return string Replacement string.
  */
 protected function _regexCallback($reg)
 {
     switch ($reg[0]) {
         case '%b':
             return $this->strftime(Horde_Nls::getLangInfo(constant('ABMON_' . (int) $this->_month)));
         case '%B':
             return $this->strftime(Horde_Nls::getLangInfo(constant('MON_' . (int) $this->_month)));
         case '%C':
             return (int) ($this->_year / 100);
         case '%-d':
         case '%#d':
             return sprintf('%d', $this->_mday);
         case '%d':
             return sprintf('%02d', $this->_mday);
         case '%D':
             return $this->strftime('%m/%d/%y');
         case '%e':
             return sprintf('%2d', $this->_mday);
         case '%-H':
         case '%#H':
             return sprintf('%d', $this->_hour);
         case '%H':
             return sprintf('%02d', $this->_hour);
         case '%-I':
         case '%#I':
             return sprintf('%d', $this->_hour == 0 ? 12 : ($this->_hour > 12 ? $this->_hour - 12 : $this->_hour));
         case '%I':
             return sprintf('%02d', $this->_hour == 0 ? 12 : ($this->_hour > 12 ? $this->_hour - 12 : $this->_hour));
         case '%-m':
         case '%#m':
             return sprintf('%d', $this->_month);
         case '%m':
             return sprintf('%02d', $this->_month);
         case '%-M':
         case '%#M':
             return sprintf('%d', $this->_min);
         case '%M':
             return sprintf('%02d', $this->_min);
         case '%n':
             return "\n";
         case '%p':
             return $this->strftime(Horde_Nls::getLangInfo($this->_hour < 12 ? AM_STR : PM_STR));
         case '%R':
             return $this->strftime('%H:%M');
         case '%-S':
         case '%#S':
             return sprintf('%d', $this->_sec);
         case '%S':
             return sprintf('%02d', $this->_sec);
         case '%t':
             return "\t";
         case '%T':
             return $this->strftime('%H:%M:%S');
         case '%x':
             return $this->strftime(Horde_Nls::getLangInfo(D_FMT));
         case '%X':
             return $this->strftime(Horde_Nls::getLangInfo(T_FMT));
         case '%y':
             return substr(sprintf('%04d', $this->_year), -2);
         case '%Y':
             return (int) $this->_year;
         case '%%':
             return '%';
     }
     return $reg[0];
 }
Example #23
0
 /**
  * Workaround broken number_format() prior to PHP 5.4.0.
  *
  * @param integer $number    Number to format.
  * @param integer $decimals  Number of decimals to display.
  *
  * @return string  See number_format().
  */
 public static function numberFormat($number, $decimals)
 {
     $localeinfo = Horde_Nls::getLocaleInfo();
     return str_replace(array('X', 'Y'), array($localeinfo['decimal_point'], $localeinfo['thousands_sep']), number_format($decimals ? $number : ceil($number), $decimals, 'X', 'Y'));
 }
Example #24
0
 /**
  * Output the size of this MIME part in KB.
  *
  * @param boolean $approx  If true, determines an approximate size for
  *                         parts consisting of base64 encoded data.
  *
  * @return string  Size of the part in KB.
  */
 public function getSize($approx = false)
 {
     if (!($bytes = $this->getBytes($approx))) {
         return 0;
     }
     $kb = $bytes / 1024;
     $localeinfo = Horde_Nls::getLocaleInfo();
     /* Reduce need for decimals as part size gets larger. */
     if ($kb > 100) {
         $decimals = 0;
     } elseif ($kb > 10) {
         $decimals = 1;
     } else {
         $decimals = 2;
     }
     // TODO: Workaround broken number_format() prior to PHP 5.4.0.
     return str_replace(array('X', 'Y'), array($localeinfo['decimal_point'], $localeinfo['thousands_sep']), number_format($kb, $decimals, 'X', 'Y'));
 }
Example #25
0
        }
    }
}
// Timeobjects
foreach ($GLOBALS['calendar_manager']->get(Kronolith::ALL_EXTERNAL_CALENDARS) as $id => $calendar) {
    if ($calendar->api() == 'tasks') {
        continue;
    }
    if (!$calendar->display()) {
        continue;
    }
    $code['conf']['calendars']['external'][$id] = array('name' => $calendar->name(), 'fg' => $calendar->foreground(), 'bg' => $calendar->background(), 'api' => $registry->get('name', $registry->hasInterface($calendar->api())), 'show' => in_array($id, $GLOBALS['calendar_manager']->get(Kronolith::DISPLAY_EXTERNAL_CALENDARS)));
}
// Remote calendars
foreach ($GLOBALS['calendar_manager']->get(Kronolith::ALL_REMOTE_CALENDARS) as $url => $calendar) {
    $code['conf']['calendars']['remote'][$url] = array_merge(array('name' => $calendar->name(), 'desc' => $calendar->description(), 'owner' => true, 'fg' => $calendar->foreground(), 'bg' => $calendar->background(), 'show' => in_array($url, $GLOBALS['calendar_manager']->get(Kronolith::DISPLAY_REMOTE_CALENDARS))), $calendar->credentials());
}
// Holidays
foreach ($GLOBALS['calendar_manager']->get(Kronolith::ALL_HOLIDAYS) as $id => $calendar) {
    $code['conf']['calendars']['holiday'][$id] = array('name' => $calendar->name(), 'fg' => $calendar->foreground(), 'bg' => $calendar->background(), 'show' => in_array($id, $GLOBALS['calendar_manager']->get(Kronolith::DISPLAY_HOLIDAYS)));
}
/* Gettext strings used in core javascript files. */
$code['text'] = array('ajax_error' => _("Error when communicating with the server."), 'allday' => _("All day"), 'noevents' => _("No events to display"), 'yesterday' => _("Yesterday"), 'today' => _("Today"), 'tomorrow' => _("Tomorrow"));
/* Map day masks to localized day names for recursion */
$masks = array(Horde_Date::MASK_SUNDAY => Horde_Nls::getLangInfo(DAY_1), Horde_Date::MASK_MONDAY => Horde_Nls::getLangInfo(DAY_2), Horde_Date::MASK_TUESDAY => Horde_Nls::getLangInfo(DAY_3), Horde_Date::MASK_WEDNESDAY => Horde_Nls::getLangInfo(DAY_4), Horde_Date::MASK_THURSDAY => Horde_Nls::getLangInfo(DAY_5), Horde_Date::MASK_FRIDAY => Horde_Nls::getLangInfo(DAY_6), Horde_Date::MASK_SATURDAY => Horde_Nls::getLangInfo(DAY_7));
foreach ($masks as $i => $text) {
    $code['text']['weekday'][$i] = $text;
}
$code['text']['recur']['desc'] = array(Horde_Date_Recurrence::RECUR_DAILY => array(_("Recurs daily"), sprintf(_("Recurs every %s days"), "#{interval}")), Horde_Date_Recurrence::RECUR_WEEKLY => array(sprintf(_("Recurs weekly on every %s"), "#{weekday}"), sprintf(_("Recurs every %s weeks on %s"), "#{interval}", "#{weekday}")), Horde_Date_Recurrence::RECUR_MONTHLY_DATE => array(sprintf(_("Recurs on the %s of every month"), "#{date}"), sprintf(_("Recurs every %s months on the %s"), "#{interval}", "#{date}")), Horde_Date_Recurrence::RECUR_MONTHLY_WEEKDAY => array(_("Recurs every month on the same weekday"), sprintf(_("Recurs every %s months on the same weekday"), "#{interval}")), Horde_Date_Recurrence::RECUR_MONTHLY_LAST_WEEKDAY => array(_("Recurs every month on the same last weekday"), sprintf(_("Recurs every %s months on the same last weekday"), "#{interval}")), Horde_Date_Recurrence::RECUR_YEARLY_DATE => array(sprintf(_("Recurs once a year, on %s"), '#{date}'), sprintf(_("Recurs every %s years on %s"), '#{interval}', '#{date}')), Horde_Date_Recurrence::RECUR_YEARLY_DAY => array(_("Recurs once a year, on the same day"), sprintf(_("Recurs every %s years on the same day"), '#{interval}')), Horde_Date_Recurrence::RECUR_YEARLY_WEEKDAY => array(_("Recurs every year on the same weekday"), sprintf(_("Recurs every %s years on the same weekday"), "#{interval}")));
$code['text']['recur']['exception'] = _("Exception");
echo $GLOBALS['page_output']->addInlineJsVars(array('var Kronolith' => $code), array('top' => true));
Example #26
0
$attributes['workPOBox'] = array('label' => _("Work Post Office Box"), 'type' => 'text', 'required' => false, 'params' => array('regex' => '', 'size' => 10, 'maxlength' => 10));
$attributes['workCity'] = array('label' => _("Work City"), 'type' => 'text', 'required' => false, 'params' => array('regex' => '', 'size' => 40, 'maxlength' => 255));
$attributes['workProvince'] = array('label' => _("Work State/Province"), 'type' => 'text', 'required' => false, 'params' => array('regex' => '', 'size' => 40, 'maxlength' => 255));
$attributes['workPostalCode'] = array('label' => _("Work Postal Code"), 'type' => 'text', 'required' => false, 'params' => array('regex' => '', 'size' => 10, 'maxlength' => 10));
$attributes['workCountry'] = array('label' => _("Work Country"), 'type' => 'country', 'required' => false, 'params' => array('prompt' => true));
$attributes['workCountryFree'] = array('label' => _("Work Country"), 'type' => 'text', 'required' => false, 'params' => array('regex' => '', 'size' => 40, 'maxlength' => 255));
$attributes['companyAddress'] = array('label' => _("Company Address"), 'type' => 'address', 'required' => false, 'params' => array('rows' => 3, 'cols' => 40));
$attributes['otherAddress'] = array('label' => _("Other Address"), 'type' => 'address', 'required' => false, 'params' => array('rows' => 3, 'cols' => 40));
$attributes['otherStreet'] = array('label' => _("Other Street Address"), 'type' => 'text', 'required' => false, 'params' => array('regex' => '', 'size' => 40, 'maxlength' => 255));
$attributes['otherCity'] = array('label' => _("Other City"), 'type' => 'text', 'required' => false, 'params' => array('regex' => '', 'size' => 40, 'maxlength' => 255));
$attributes['otherProvince'] = array('label' => _("Other State/Province"), 'type' => 'text', 'required' => false, 'params' => array('regex' => '', 'size' => 40, 'maxlength' => 255));
$attributes['otherPostalCode'] = array('label' => _("Other Postal Code"), 'type' => 'text', 'required' => false, 'params' => array('regex' => '', 'size' => 10, 'maxlength' => 10));
$attributes['otherCountry'] = array('label' => _("Other Country"), 'type' => 'country', 'required' => false, 'params' => array('prompt' => true));
$attributes['otherCountryFree'] = array('label' => _("Other Country"), 'type' => 'text', 'required' => false, 'params' => array('regex' => '', 'size' => 40, 'maxlength' => 255));
$attributes['otherPOBox'] = array('label' => _("Other Post Office Box"), 'type' => 'text', 'required' => false, 'params' => array('regex' => '', 'size' => 10, 'maxlength' => 10));
$attributes['timezone'] = array('label' => _("Time Zone"), 'type' => 'enum', 'params' => array('values' => Horde_Nls::getTimezones(), 'prompt' => true), 'required' => false);
/* Communication. */
$attributes['email'] = array('label' => _("Email"), 'type' => 'email', 'required' => false, 'params' => array('allow_multi' => false, 'strip_domain' => false, 'link_compose' => true, 'link_name' => null, 'delimiters' => ',', 'size' => null));
$attributes['emails'] = array('label' => _("Emails"), 'type' => 'email', 'required' => false, 'params' => array('allow_multi' => true, 'strip_domain' => false, 'link_compose' => true, 'link_name' => null, 'delimiters' => ',', 'size' => null));
$attributes['homePhone'] = array('label' => _("Home Phone"), 'type' => 'phone', 'required' => false, 'params' => array('size' => 15));
$attributes['homePhone2'] = array('label' => _("Home Phone"), 'type' => 'phone', 'required' => false, 'params' => array('size' => 15));
$attributes['workPhone'] = array('label' => _("Work Phone"), 'type' => 'phone', 'required' => false, 'params' => array('size' => 15));
$attributes['workPhone2'] = array('label' => _("Work Phone"), 'type' => 'phone', 'required' => false, 'params' => array('size' => 15));
$attributes['assistPhone'] = array('label' => _("Assistant Phone"), 'type' => 'phone', 'required' => false, 'params' => array('size' => 15));
$attributes['companyPhone'] = array('label' => _("Company Phone"), 'type' => 'phone', 'required' => false, 'params' => array('size' => 15));
$attributes['cellPhone'] = array('label' => _("Mobile Phone"), 'type' => 'cellphone', 'required' => false);
$attributes['carPhone'] = array('label' => _("Car Phone"), 'type' => 'phone', 'required' => false, 'params' => array('size' => 15));
$attributes['radioPhone'] = array('label' => _("Radio Phone"), 'type' => 'phone', 'required' => false, 'params' => array('size' => 15));
$attributes['fax'] = array('label' => _("Fax"), 'type' => 'phone', 'required' => false, 'params' => array('size' => 15));
$attributes['homeFax'] = array('label' => _("Home Fax"), 'type' => 'phone', 'required' => false, 'params' => array('size' => 15));
$attributes['pager'] = array('label' => _("Pager"), 'type' => 'phone', 'required' => false, 'params' => array('size' => 15));
Example #27
0
 /**
  * Convert the contact to an ActiveSync contact message
  *
  * @param Turba_Object $object  The turba object to convert
  * @param array $options        Options:
  *   - protocolversion: (float)  The EAS version to support
  *                      DEFAULT: 2.5
  *   - bodyprefs: (array)  A BODYPREFERENCE array.
  *                DEFAULT: none (No body prefs enforced).
  *   - truncation: (integer)  Truncate event body to this length
  *                 DEFAULT: none (No truncation).
  *   - device: (Horde_ActiveSync_Device) The device object.
  *
  * @return Horde_ActiveSync_Message_Contact
  */
 public function toASContact(Turba_Object $object, array $options = array())
 {
     global $injector;
     $message = new Horde_ActiveSync_Message_Contact(array('logger' => $injector->getInstance('Horde_Log_Logger'), 'protocolversion' => $options['protocolversion'], 'device' => !empty($options['device']) ? $options['device'] : null));
     $hash = $object->getAttributes();
     if (!isset($hash['lastname']) && isset($hash['name'])) {
         $this->_guessName($hash);
     }
     // Ensure we have at least a good guess as to separate address fields.
     // Not ideal, but EAS does not have a single "address" field so we must
     // map "common" to either home or work. I choose home since
     // work/non-personal installs will be more likely to have separated
     // address fields.
     if (!empty($hash['commonAddress'])) {
         if (!isset($hash['commonStreet'])) {
             $hash['commonStreet'] = $hash['commonHome'];
         }
         foreach (array('Address', 'Street', 'POBox', 'Extended', 'City', 'Province', 'PostalCode', 'Country') as $field) {
             $hash['home' . $field] = $hash['common' . $field];
         }
     } else {
         if (isset($hash['homeAddress']) && !isset($hash['homeStreet'])) {
             $hash['homeStreet'] = $hash['homeAddress'];
         }
         if (isset($hash['workAddress']) && !isset($hash['workStreet'])) {
             $hash['workStreet'] = $hash['workAddress'];
         }
     }
     $hooks = $injector->getInstance('Horde_Core_Hooks');
     $decode_hook = $hooks->hookExists('decode_attribute', 'turba');
     foreach ($hash as $field => $value) {
         if ($decode_hook) {
             try {
                 $value = $hooks->callHook('decode_attribute', 'turba', array($field, $value, $object));
             } catch (Turba_Exception $e) {
                 Horde::log($e);
             }
         }
         if (isset(self::$_asMap[$field])) {
             try {
                 $message->{self::$_asMap[$field]} = $value;
             } catch (InvalidArgumentException $e) {
             }
             continue;
         }
         switch ($field) {
             case 'photo':
                 $message->picture = base64_encode($value);
                 break;
             case 'homeCountry':
                 $message->homecountry = !empty($hash['homeCountryFree']) ? $hash['homeCountryFree'] : !empty($hash['homeCountry']) ? Horde_Nls::getCountryISO($hash['homeCountry']) : null;
                 break;
             case 'otherCountry':
                 $message->othercountry = !empty($hash['otherCountryFree']) ? $hash['otherCountryFree'] : !empty($hash['otherCountry']) ? Horde_Nls::getCountryISO($hash['otherCountry']) : null;
                 break;
             case 'workCountry':
                 $message->businesscountry = !empty($hash['workCountryFree']) ? $hash['workCountryFree'] : !empty($hash['workCountry']) ? Horde_Nls::getCountryISO($hash['workCountry']) : null;
                 break;
             case 'email':
                 $message->email1address = $value;
                 break;
             case 'homeEmail':
                 $message->email2address = $value;
                 break;
             case 'workEmail':
                 $message->email3address = $value;
                 break;
             case 'emails':
                 $address = 1;
                 foreach (explode(',', $value) as $email) {
                     while ($address <= 3 && $message->{'email' . $address . 'address'}) {
                         $address++;
                     }
                     if ($address > 3) {
                         break;
                     }
                     $message->{'email' . $address . 'address'} = $email;
                     $address++;
                 }
                 break;
             case 'children':
                 // Children FROM horde are a simple string value. Even though EAS
                 // uses an array stucture to pass them, we pass as a single
                 // string since we can't assure what delimter the user will
                 // use and (at least in some languages) a comma can be used
                 // within a full name.
                 $message->children = array($value);
                 break;
             case 'notes':
                 if ($options['protocolversion'] > Horde_ActiveSync::VERSION_TWOFIVE) {
                     $bp = $options['bodyprefs'];
                     $note = new Horde_ActiveSync_Message_AirSyncBaseBody();
                     // No HTML supported in Turba's notes. Always use plaintext.
                     $note->type = Horde_ActiveSync::BODYPREF_TYPE_PLAIN;
                     if (isset($bp[Horde_ActiveSync::BODYPREF_TYPE_PLAIN]['truncationsize'])) {
                         if (Horde_String::length($value) > $bp[Horde_ActiveSync::BODYPREF_TYPE_PLAIN]['truncationsize']) {
                             $note->data = Horde_String::substr($value, 0, $bp[Horde_ActiveSync::BODYPREF_TYPE_PLAIN]['truncationsize']);
                             $note->truncated = 1;
                         } else {
                             $note->data = $value;
                         }
                         $note->estimateddatasize = Horde_String::length($value);
                     }
                     $message->airsyncbasebody = $note;
                 } else {
                     // EAS 2.5
                     $message->body = $value;
                     $message->bodysize = strlen($message->body);
                     $message->bodytruncated = 0;
                 }
                 break;
             case 'birthday':
             case 'anniversary':
                 if (!empty($value) && $value != '0000-00-00') {
                     try {
                         $date = new Horde_Date($value);
                     } catch (Horde_Date_Exception $e) {
                         $message->{$field} = null;
                     }
                     // Some sanity checking to make sure the date was
                     // successfully parsed.
                     if ($date->month != 0) {
                         $message->{$field} = $date;
                     } else {
                         $message->{$field} = null;
                     }
                 } else {
                     $message->{$field} = null;
                 }
                 break;
         }
     }
     /* Get tags. */
     $message->categories = explode(',', $object->getValue('__tags'));
     if (empty($this->fileas)) {
         $message->fileas = Turba::formatName($object);
     }
     return $message;
 }
Example #28
0
 /**
  * TODO
  */
 public static function callback()
 {
     Horde_Nls::$dnsResolver = $GLOBALS['injector']->getInstance('Net_DNS2_Resolver');
 }
Example #29
0
 /**
  * Initialize the configuration.
  *
  * @return NULL
  */
 public function init()
 {
     $values = $this->_cli->getOptions();
     $this->_sender = strtolower($values['sender']);
     $this->_recipients = array_map('strtolower', $values['recipient']);
     $this->_client_address = $values['client'];
     $this->_fqhostname = strtolower($values['host']);
     $this->_sasl_username = strtolower($values['user']);
     global $conf;
     if (!empty($values['config']) && file_exists($values['config'])) {
         require_once $values['config'];
     }
     if (!empty($conf['kolab']['filter']['locale_path']) && !empty($conf['kolab']['filter']['locale'])) {
         Horde_Nls::setTextdomain('Kolab_Filter', $conf['kolab']['filter']['locale_path']);
         setlocale(LC_ALL, $conf['kolab']['filter']['locale']);
     }
     /* This is used as the default domain for unqualified adresses */
     /* @todo: What do we need this for? Which libraries grab these infos from global scope? MIME? */
     if (isset($conf['kolab']['imap']['server'])) {
         if (!array_key_exists('SERVER_NAME', $_SERVER)) {
             $_SERVER['SERVER_NAME'] = $conf['kolab']['imap']['server'];
         }
         if (!array_key_exists('REMOTE_ADDR', $_SERVER)) {
             $_SERVER['REMOTE_ADDR'] = $conf['kolab']['imap']['server'];
         }
         if (!array_key_exists('REMOTE_HOST', $_SERVER)) {
             $_SERVER['REMOTE_HOST'] = $conf['kolab']['imap']['server'];
         }
     }
     /* Always display all possible problems */
     ini_set('error_reporting', E_ERROR);
     ini_set('track_errors', '1');
     /* Setup error logging */
     if (isset($conf['kolab']['filter']['error_log'])) {
         ini_set('log_errors', '1');
         ini_set('error_log', $conf['kolab']['filter']['error_log']);
     }
     /* Print PHP messages to StdOut if we are debugging */
     if (isset($conf['kolab']['filter']['debug']) && $conf['kolab']['filter']['debug']) {
         ini_set('display_errors', '1');
     }
     /* Provide basic syslog debugging if nothing has been
      * specified
      */
     if (!isset($conf['log'])) {
         $conf['log']['enabled'] = true;
         $conf['log']['priority'] = 'DEBUG';
         $conf['log']['type'] = 'syslog';
         $conf['log']['name'] = LOG_MAIL;
         $conf['log']['ident'] = 'kolabfilter';
         $conf['log']['params'] = array();
     }
     $this->_conf = $conf;
 }
Example #30
0
?>
</a>
 </div>

 <div data-role="content" id="kronolith-minical" class="kronolith-minical">
  <table>
   <thead>
    <tr>
<?php 
for ($i = $GLOBALS['prefs']->getValue('week_start_monday'), $c = $i + 7; $i < $c; $i++) {
    ?>
     <th title="<?php 
    echo Horde_Nls::getLangInfo(constant('DAY_' . ($i % 7 + 1)));
    ?>
"><?php 
    echo Horde_String::substr(Horde_Nls::getLangInfo(constant('DAY_' . ($i % 7 + 1))), 0, 1);
    ?>
</th>
<?php 
}
?>
    </tr>
   </thead>
   <tbody><tr><td></td></tr></tbody>
  </table>
 </div>

 <div id="kronolithDayDetailHeader" data-role="header">
   <h3></h3>
 </div>