Get the language info returned by nl_langinfo(), but cache it, to
avoid repeated calls.
public static getLangInfo ( const $item ) : array | ||
$item | const | The langinfo item to return. |
Результат | array | The results of nl_langinfo(). |
/** * 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; }
/** * 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'); }
/** * 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); }
/** */ 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; }
/** * 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; }
/** * 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]; }
} } } // 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));
/** * 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'])); }
<?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));
?> </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>