/** * Outputs the html for a DateGallery tile. * * @param Ansel_Gallery_Decorator_Date $dgallery The Ansel_Gallery_Date we are * displaying. * @param Ansel_Style $style A style object. * @param boolean $mini Force the use of a mini thumbail? * @param array $params An array containing additional parameters. * Currently, gallery_view_url and image_view_url * are used to override the respective urls. * %g and %i are replaced with image id and * gallery id, respectively. * * @return string The HTML for the tile. */ public function getTile(Ansel_Gallery_Decorator_Date $dgallery, Ansel_Style $style = null, $mini = false, array $params = array()) { $view = $GLOBALS['injector']->createInstance('Horde_View'); $view->addTemplatePath(ANSEL_TEMPLATES . '/tile'); // User's preferred date format $date_format = $GLOBALS['prefs']->getValue('date_format'); $date_array = $dgallery->getDate(); if (empty($date_array['month'])) { $date_array['month'] = 1; } if (empty($date_array['day'])) { $date_array['day'] = 1; } $full_date = new Horde_Date($date_array); // Need the unaltered date part array $date_array = $dgallery->getDate(); // Figure out the needed link for the next drill down level. We *must* // have at least a year since we are in a date tile. if (empty($date_array['month'])) { // unit == year $view->caption = $full_date->strftime('%Y'); $next_date = array('year' => (int) $view->caption); } elseif (empty($date_array['day'])) { // unit == month $view->caption = $full_date->strftime('%B %Y'); $next_date = array('year' => date('Y', $full_date->timestamp()), 'month' => date('n', $full_date->timestamp())); } else { // unit == day $view->caption = $full_date->strftime($date_format); $next_date = array('year' => date('Y', $full_date->timestamp()), 'month' => date('n', $full_date->timestamp()), 'day' => date('j', $full_date->timestamp())); } // Check permissions on the gallery and get appropriate tile image if ($dgallery->hasPermission($GLOBALS['registry']->getAuth(), Horde_Perms::READ)) { if (is_null($style)) { $style = $dgallery->getStyle(); } $thumbstyle = $mini ? 'mini' : 'thumb'; $view->gallery_image = Ansel::getImageUrl($dgallery->getKeyImage(), $thumbstyle, true, $style); } else { $view->gallery_image = Horde_Themes::img('thumb-error.png'); } /* Check for being called via the api and generate correct view links */ if (!isset($params['gallery_view_url'])) { if (empty($params['style'])) { $gstyle = $dgallery->getStyle(); } else { $gstyle = $params['style']; } $params = array('gallery' => $dgallery->id, 'view' => 'Gallery', 'slug' => $dgallery->get('slug')); $view->view_link = Ansel::getUrlFor('view', array_merge($params, $next_date)); } else { $view->view_link = new Horde_Url(str_replace(array('%g', '%s'), array($dgallery->id, $dgallery->get('slug')), urldecode($params['gallery_view_url']))); $view->view_link->add($next_date); } $view->gallery_count = $dgallery->countImages(true); return $view->render('dategallery'); }
/** */ public function display(Horde_Core_Prefs_Ui $ui) { global $browser, $injector, $page_output, $prefs; $page_output->addScriptPackage('IMP_Script_Package_Imp'); $p_css = new Horde_Themes_Element('prefs.css'); $page_output->addStylesheet($p_css->fs, $p_css->uri); $view = new Horde_View(array('templatePath' => IMP_TEMPLATES . '/prefs')); $view->addHelper('Horde_Core_View_Helper_Help'); if (!Horde::isConnectionSecure()) { $view->notsecure = true; return $view->render('smimeprivatekey'); } $smime_url = IMP_Basic_Smime::url(); $view->has_key = $prefs->getValue('smime_public_key') && $prefs->getValue('smime_private_key'); $view->has_sign_key = $prefs->getValue('smime_public_sign_key') && $prefs->getValue('smime_private_sign_key'); if ($browser->allowFileUploads()) { $view->import = true; $page_output->addInlineScript(array('$("import_smime_personal").observe("click", function(e) { ' . Horde::popupJs($smime_url, array('params' => array('actionID' => 'import_personal_certs', 'reload' => base64_encode($ui->selfUrl()->setRaw(true))), 'height' => 450, 'width' => 750, 'urlencode' => true)) . '; e.stop(); })'), true); } if (!$view->has_key) { return $view->render('smimeprivatekey'); } $smime = $injector->getInstance('IMP_Smime'); foreach (array('' => false, '_sign' => true) as $suffix => $secondary) { if ($secondary && !$view->has_sign_key) { continue; } $cert = $smime->parseCert($smime->getPersonalPublicKey($secondary)); if (!empty($cert['validity']['notafter'])) { $expired = new Horde_Date($cert['validity']['notafter']); if ($expired->before(time())) { $view->{'expiredate' . $suffix} = $expired->strftime($prefs->getValue('date_format')); $view->{'expiretime' . $suffix} = $expired->strftime($prefs->getValue('time_format')); } } $view->{'viewpublic' . $suffix} = $smime_url->copy()->add('actionID', 'view_personal_public' . $suffix . '_key')->link(array('title' => $secondary ? _("View Secondary Personal Public Certificate") : _("View Personal Public Certificate"), 'target' => 'view_key')) . _("View") . '</a>'; $view->{'infopublic' . $suffix} = $smime_url->copy()->add('actionID', 'info_personal_public' . $suffix . '_key')->link(array('title' => _("Information on Personal Public Certificate"), 'target' => 'info_key')) . _("Details") . '</a>'; if ($smime->getPassphrase($secondary)) { $view->{'passphrase' . $suffix} = $ui->selfUrl(array('special' => true, 'token' => true))->add('unset_smime' . $suffix . '_passphrase', 1)->link(array('title' => _("Unload Passphrase"))) . _("Unload Passphrase") . '</a>'; } else { $imple = $injector->getInstance('Horde_Core_Factory_Imple')->create('IMP_Ajax_Imple_PassphraseDialog', array('params' => array('reload' => $ui->selfUrl()->setRaw(true), 'secondary' => intval($secondary)), 'type' => 'smimePersonal')); $view->{'passphrase' . $suffix} = Horde::link('#', _("Enter Passphrase"), null, null, null, null, null, array('id' => $imple->getDomId())) . _("Enter Passphrase"); } $view->{'viewprivate' . $suffix} = $smime_url->copy()->add('actionID', 'view_personal_private' . $suffix . '_key')->link(array('title' => _("View Secondary Personal Private Key"), 'target' => 'view_key')) . _("View") . '</a>'; $page_output->addInlineScript(array('$("delete_smime_personal' . $suffix . '").observe("click", function(e) { if (!window.confirm(' . json_encode(_("Are you sure you want to delete your keypair? (This is NOT recommended!)")) . ')) { e.stop(); } })'), true); } return $view->render('smimeprivatekey'); }
/** * Get an array describing where this gallery is in a breadcrumb trail. * * @return array An array of 'title' and 'navdata' hashes with the [0] * element being the deepest part. */ public function getGalleryCrumbData() { $year = !empty($this->_date['year']) ? $this->_date['year'] : 0; $month = !empty($this->_date['month']) ? $this->_date['month'] : 0; $day = !empty($this->_date['day']) ? $this->_date['day'] : 0; $trail = array(); // Do we have any date parts? if (!empty($year)) { if (!empty($day)) { $date = new Horde_Date($this->_date); $text = $date->strftime('%e'); $navdata = array('view' => 'Gallery', 'gallery' => $this->_gallery->id, 'slug' => $this->_gallery->get('slug'), 'year' => $year, 'month' => $month, 'day' => $day); $trail[] = array('title' => $text, 'navdata' => $navdata); } if (!empty($month)) { $date = new Horde_Date(array('year' => $year, 'month' => $month, 'day' => 1)); $text = $date->strftime('%B'); $navdata = array('view' => 'Gallery', 'gallery' => $this->_gallery->id, 'slug' => $this->_gallery->get('slug'), 'year' => $year, 'month' => $month); $trail[] = array('title' => $text, 'navdata' => $navdata); } $navdata = array('view' => 'Gallery', 'gallery' => $this->_gallery->id, 'slug' => $this->_gallery->get('slug'), 'year' => $year); $trail[] = array('title' => $year, 'navdata' => $navdata); } else { // This is the first level of a date mode gallery. $navdata = array('view' => 'Gallery', 'gallery' => $this->_gallery->id, 'slug' => $this->_gallery->get('slug')); $trail[] = array('title' => _("All dates"), 'navdata' => $navdata); } $text = htmlspecialchars($this->_gallery->get('name')); $navdata = array('view' => 'Gallery', 'gallery' => $this->_gallery->id, 'slug' => $this->_gallery->get('slug')); $trail[] = array('title' => $text, 'navdata' => $navdata); return $trail; }
protected function _hours() { global $prefs; $hours_html = ''; $dayWidth = round(100 / $this->_days); $span = floor(($this->_endHour - $this->_startHour) / 3); if (($this->_endHour - $this->_startHour) % 3) { $span++; } $date_format = $prefs->getValue('date_format'); for ($i = 0; $i < $this->_days; $i++) { $t = new Horde_Date(array('month' => $this->_start->month, 'mday' => $this->_start->mday + $i, 'year' => $this->_start->year)); $day_label = Horde::url('#')->link(array('onclick' => 'return switchDateView(\'Day\',' . $t->dateString() . ');')) . $t->strftime($date_format) . '</a>'; $hours_html .= sprintf('<th colspan="%d" width="%s%%">%s</th>', $span, $dayWidth, $day_label); } $hours_html .= '</tr><tr><td width="100" class="label"> </td>'; $width = round(100 / ($span * $this->_days)); for ($i = 0; $i < $this->_days; $i++) { for ($h = $this->_startHour; $h < $this->_endHour; $h += 3) { $start = new Horde_Date(array('hour' => $h, 'month' => $this->_start->month, 'mday' => $this->_start->mday + $i, 'year' => $this->_start->year)); $end = new Horde_Date($start); $end->hour += 2; $end->min = 59; $this->_timeBlocks[] = array($start, $end); $hour = $start->strftime($prefs->getValue('twentyFour') ? '%H:00' : '%I:00'); $hours_html .= sprintf('<th width="%d%%">%s</th>', $width, $hour); } } return $hours_html; }
protected function _hours() { global $prefs; $hours_html = ''; $width = round(100 / ($this->_endHour - $this->_startHour + 1)); $start = new Horde_Date($this->_start); $end = new Horde_Date($this->_start); $end->min = 59; for ($i = $this->_startHour; $i < $this->_endHour; $i++) { $start->hour = $end->hour = $i; $this->_timeBlocks[] = array(clone $start, clone $end); $hours_html .= '<th width="' . $width . '%">' . $start->strftime($prefs->getValue('twentyFour') ? '%H:00' : '%I:00') . '</th>'; } return $hours_html; }
/** */ protected function _title() { $title = _("All Calendars"); $url = Horde::url($GLOBALS['registry']->getInitialPage(), true); if (isset($this->_params['calendar']) && $this->_params['calendar'] != '__all') { $calendars = Kronolith::listCalendars(); if (isset($calendars[$this->_params['calendar']])) { $title = htmlspecialchars($calendars[$this->_params['calendar']]->name()); } else { $title = _("Calendar not found"); } $url->add('display_cal', $this->_params['calendar']); } $date = new Horde_Date(time()); return $title . ', ' . $url->link() . $date->strftime('%B, %Y') . '</a>'; }
protected function _prepareWrite($attributes, $blob_fields, $date_fields) { $fields = $values = array(); foreach ($attributes as $field => $value) { $fields[] = $field; if (!empty($value) && isset($blob_fields[$field])) { $values[] = new Horde_Db_Value_Binary($value); } elseif (!empty($value) && isset($date_fields[$field])) { $d = new Horde_Date($value); $values[] = $d->strftime('%Y-%m-%d'); } else { $values[] = $this->_convertToDriver($value); } } return array($fields, $values); }
/** * Returns a simple object suitable for json transport representing this * task. * * @param boolean $full Whether to return all task details. * @param string $time_format The date() format to use for time formatting. * * @return object A simple object. */ public function toJson($full = false, $time_format = 'H:i') { $json = new stdClass(); $json->l = $this->tasklist; $json->p = $this->parent_id; $json->i = $this->indent; $json->n = $this->name; if ($this->desc) { //TODO: Get the proper amount of characters, and cut by last //whitespace $json->sd = Horde_String::substr($this->desc, 0, 80); } $json->cp = (bool) $this->completed; if ($this->due && ($due = $this->getNextDue())) { $json->du = $due->toJson(); } if ($this->start && ($start = $this->getNextStart())) { $json->s = $start->toJson(); } $json->pr = (int) $this->priority; if ($this->recurs()) { $json->r = $this->recurrence->getRecurType(); } $json->t = array_values($this->tags); if ($full) { // @todo: do we really need all this? $json->id = $this->id; $json->de = $this->desc; if ($this->due) { $date = new Horde_Date($this->due); $json->dd = $date->strftime('%x'); $json->dt = $date->format($time_format); } $json->as = $this->assignee; if ($this->estimate) { $json->e = $this->estimate; } /* $json->o = $this->owner; if ($this->completed_date) { $date = new Horde_Date($this->completed_date); $json->cd = $date->toJson(); } */ $json->a = (int) $this->alarm; $json->m = $this->methods; //$json->pv = (boolean)$this->private; if ($this->recurs()) { $json->r = $this->recurrence->toJson(); } if ($this->tasklist == '**EXTERNAL**') { $json->vl = (string) $this->view_link; $json->cl = (string) $this->complete_link; $json->pe = $json->pd = false; } else { try { $share = $GLOBALS['nag_shares']->getShare($this->tasklist); } catch (Horde_Share_Exception $e) { Horde::log($e->getMessage(), 'ERR'); throw new Nag_Exception($e); } $json->pe = $share->hasPermission($GLOBALS['registry']->getAuth(), Horde_Perms::EDIT); $json->pd = $share->hasPermission($GLOBALS['registry']->getAuth(), Horde_Perms::DELETE); } } return $json; }
/** * Return the rendered inline version of the Horde_Mime_Part object. * * @return array See parent::render(). */ protected function _renderInline() { $browser = $this->getConfigParam('browser'); $notification = $this->getConfigParam('notification'); $prefs = $this->getConfigParam('prefs'); $registry = $this->getConfigParam('registry'); $data = $this->_mimepart->getContents(); $html = ''; $title = Horde_Core_Translation::t("vCard"); $iCal = new Horde_Icalendar(); if (!$iCal->parsevCalendar($data, 'VCALENDAR', $this->_mimepart->getCharset())) { $notification->push(Horde_Core_Translation::t("There was an error reading the contact data."), 'horde.error'); } if (Horde_Util::getFormData('import') && Horde_Util::getFormData('source') && $registry->hasMethod('contacts/import')) { $source = Horde_Util::getFormData('source'); $count = 0; foreach ($iCal->getComponents() as $c) { if ($c->getType() == 'vcard') { try { $registry->call('contacts/import', array($c, null, $source)); ++$count; } catch (Horde_Exception $e) { $notification->push(Horde_Core_Translation::t("There was an error importing the contact data:") . ' ' . $e->getMessage(), 'horde.error'); } } } $notification->push(sprintf(Horde_Core_Translation::ngettext("%d contact was successfully added to your address book.", "%d contacts were successfully added to your address book.", $count), $count), 'horde.success'); } $html .= '<table class="horde-table" style="width:100%">'; foreach ($iCal->getComponents() as $i => $vc) { if ($i > 0) { $html .= '<tr><td colspan="2"> </td></tr>'; } $addresses = $vc->getAllAttributes('EMAIL'); $html .= '<tr><td colspan="2" class="header">'; if (($fullname = $vc->getAttributeDefault('FN', false)) === false) { $fullname = count($addresses) ? $addresses[0]['value'] : Horde_Core_Translation::t("[No Label]"); } $html .= htmlspecialchars($fullname) . '</td></tr>'; $n = $vc->printableName(); if (!empty($n)) { $html .= $this->_row(Horde_Core_Translation::t("Name"), $n); } try { $html .= $this->_row(Horde_Core_Translation::t("Alias"), implode("\n", $vc->getAttributeValues('ALIAS'))); } catch (Horde_Icalendar_Exception $e) { } try { $birthdays = $vc->getAttributeValues('BDAY'); $birthday = new Horde_Date($birthdays[0]); $html .= $this->_row(Horde_Core_Translation::t("Birthday"), $birthday->strftime($prefs->getValue('date_format'))); } catch (Horde_Icalendar_Exception $e) { } $photos = $vc->getAllAttributes('PHOTO'); foreach ($photos as $p => $photo) { if (isset($photo['params']['VALUE']) && Horde_String::upper($photo['params']['VALUE']) == 'URI') { $html .= $this->_row(Horde_Core_Translation::t("Photo"), '<img src="' . htmlspecialchars($photo['value']) . '" />', false); } elseif (isset($photo['params']['ENCODING']) && Horde_String::upper($photo['params']['ENCODING']) == 'B' && isset($photo['params']['TYPE'])) { if ($browser->hasFeature('datauri') === true || $browser->hasFeature('datauri') >= strlen($photo['value'])) { $html .= $this->_row(Horde_Core_Translation::t("Photo"), '<img src="' . Horde_Url_Data::create($photo['params']['TYPE'], base64_decode($photo['value'])) . '" />', false); } elseif ($this->_imageUrl) { $html .= $this->_row(Horde_Core_Translation::t("Photo"), '<img src="' . $this->_imageUrl->add(array('c' => $i, 'p' => $p)) . '" />', false); } } } $labels = $vc->getAllAttributes('LABEL'); foreach ($labels as $label) { if (isset($label['params']['TYPE'])) { if (!is_array($label['params']['TYPE'])) { $label['params']['TYPE'] = array($label['params']['TYPE']); } } else { $label['params']['TYPE'] = array_keys($label['params']); } $types = array(); foreach ($label['params']['TYPE'] as $type) { switch (Horde_String::upper($type)) { case 'HOME': $types[] = Horde_Core_Translation::t("Home Address"); break; case 'WORK': $types[] = Horde_Core_Translation::t("Work Address"); break; case 'DOM': $types[] = Horde_Core_Translation::t("Domestic Address"); break; case 'INTL': $types[] = Horde_Core_Translation::t("International Address"); break; case 'POSTAL': $types[] = Horde_Core_Translation::t("Postal Address"); break; case 'PARCEL': $types[] = Horde_Core_Translation::t("Parcel Address"); break; case 'PREF': $types[] = Horde_Core_Translation::t("Preferred Address"); break; } } if (!count($types)) { $types = array(Horde_Core_Translation::t("Address")); } $html .= $this->_row(implode('/', $types), $label['value']); } $adrs = $vc->getAllAttributes('ADR'); foreach ($adrs as $item) { if (isset($item['params']['TYPE'])) { if (!is_array($item['params']['TYPE'])) { $item['params']['TYPE'] = array($item['params']['TYPE']); } } else { $item['params']['TYPE'] = array_keys($item['params']); } $address = $item['values']; $a = array(); $a_list = array(Horde_Icalendar_Vcard::ADR_STREET, Horde_Icalendar_Vcard::ADR_LOCALITY, Horde_Icalendar_Vcard::ADR_REGION, Horde_Icalendar_Vcard::ADR_POSTCODE, Horde_Icalendar_Vcard::ADR_COUNTRY); foreach ($a_list as $val) { if (isset($address[$val])) { $a[] = $address[$val]; } } $types = array(); foreach ($item['params']['TYPE'] as $type) { switch (Horde_String::upper($type)) { case 'HOME': $types[] = Horde_Core_Translation::t("Home Address"); break; case 'WORK': $types[] = Horde_Core_Translation::t("Work Address"); break; case 'DOM': $types[] = Horde_Core_Translation::t("Domestic Address"); break; case 'INTL': $types[] = Horde_Core_Translation::t("International Address"); break; case 'POSTAL': $types[] = Horde_Core_Translation::t("Postal Address"); break; case 'PARCEL': $types[] = Horde_Core_Translation::t("Parcel Address"); break; case 'PREF': $types[] = Horde_Core_Translation::t("Preferred Address"); break; } } if (!count($types)) { $types = array(Horde_Core_Translation::t("Address")); } $html .= $this->_row(implode('/', $types), implode("\n", $a)); } $numbers = $vc->getAllAttributes('TEL'); foreach ($numbers as $number) { if (isset($number['params']['TYPE'])) { if (!is_array($number['params']['TYPE'])) { $number['params']['TYPE'] = array($number['params']['TYPE']); } foreach ($number['params']['TYPE'] as $type) { $number['params'][Horde_String::upper($type)] = true; } } if (isset($number['params']['FAX'])) { $html .= $this->_row(Horde_Core_Translation::t("Fax"), $number['value']); } else { if (isset($number['params']['HOME'])) { $html .= $this->_row(Horde_Core_Translation::t("Home Phone"), $number['value']); } elseif (isset($number['params']['WORK'])) { $html .= $this->_row(Horde_Core_Translation::t("Work Phone"), $number['value']); } elseif (isset($number['params']['CELL'])) { $html .= $this->_row(Horde_Core_Translation::t("Cell Phone"), $number['value']); } else { $html .= $this->_row(Horde_Core_Translation::t("Phone"), $number['value']); } } } $emails = array(); foreach ($addresses as $address) { if (isset($address['params']['TYPE'])) { if (!is_array($address['params']['TYPE'])) { $address['params']['TYPE'] = array($address['params']['TYPE']); } foreach ($address['params']['TYPE'] as $type) { $address['params'][Horde_String::upper($type)] = true; } } $email = '<a href="'; if ($registry->hasMethod('mail/compose')) { $email .= $registry->call('mail/compose', array(array('to' => $address['value']))); } else { $email .= 'mailto:' . htmlspecialchars($address['value']); } $email .= '">' . htmlspecialchars($address['value']) . '</a>'; if (isset($address['params']['PREF'])) { array_unshift($emails, $email); } else { $emails[] = $email; } } if (count($emails)) { $html .= $this->_row(Horde_Core_Translation::t("Email"), implode("\n", $emails), false); } try { $title = $vc->getAttributeValues('TITLE'); $html .= $this->_row(Horde_Core_Translation::t("Title"), $title[0]); } catch (Horde_Icalendar_Exception $e) { } try { $role = $vc->getAttributeValues('ROLE'); $html .= $this->_row(Horde_Core_Translation::t("Role"), $role[0]); } catch (Horde_Icalendar_Exception $e) { } try { $org = $vc->getAttributeValues('ORG'); $html .= $this->_row(Horde_Core_Translation::t("Company"), $org[0]); if (isset($org[1])) { $html .= $this->_row(Horde_Core_Translation::t("Department"), $org[1]); } } catch (Horde_Icalendar_Exception $e) { } try { $notes = $vc->getAttributeValues('NOTE'); $html .= $this->_row(Horde_Core_Translation::t("Notes"), $notes[0]); } catch (Horde_Icalendar_Exception $e) { } try { $url = $vc->getAttributeValues('URL'); $html .= $this->_row(Horde_Core_Translation::t("URL"), '<a href="' . htmlspecialchars($url[0]) . '" target="_blank">' . htmlspecialchars($url[0]) . '</a>', false); } catch (Horde_Icalendar_Exception $e) { } } $html .= '</table>'; if ($registry->hasMethod('contacts/import') && $registry->hasMethod('contacts/sources')) { $html .= '<div class="horde-form-buttons"><form action="' . Horde::selfUrl() . '" method="get" name="vcard_import" id="vcard_import">' . Horde_Util::formInput(); foreach ($_GET as $key => $val) { $html .= '<input type="hidden" name="' . htmlspecialchars($key) . '" value="' . htmlspecialchars($val) . '" />'; } $sources = $registry->call('contacts/sources', array(true)); if (count($sources) > 1) { $html .= '<input type="submit" class="horde-default" name="import" value="' . Horde_Core_Translation::t("Add to address book:") . '" />' . ' <label for="add_source" class="hidden">' . Horde_Core_Translation::t("Address Book") . '</label>' . '<select id="add_source" name="source">'; foreach ($sources as $key => $label) { $selected = $key == $prefs->getValue('add_source') ? ' selected="selected"' : ''; $html .= '<option value="' . htmlspecialchars($key) . '"' . $selected . '>' . htmlspecialchars($label) . '</option>'; } $html .= '</select>'; } else { reset($sources); $html .= '<input type="submit" class="horde-default" name="import" value="' . Horde_Core_Translation::t("Add to my address book") . '" />' . '<input type="hidden" name="source" value="' . htmlspecialchars(key($sources)) . '" />'; } $html .= '</form></div>'; } Horde::startBuffer(); $notification->notify(array('listeners' => 'status')); return $this->_renderReturn(Horde::endBuffer() . $html, 'text/html; charset=' . $this->getConfigParam('charset')); }
/** * Returns a relative, natural language representation of a timestamp * * @todo Wider range of values ... maybe future time as well? * @todo Support minimum resolution parameter. * * @param mixed $time The time. Any format accepted by Horde_Date. * @param string $date_format Format to display date if timestamp is * more then 1 day old. * @param string $time_format Format to display time if timestamp is 1 * day old. * * @return string The relative time (i.e. 2 minutes ago) */ public static function relativeDateTime($time, $date_format = '%x', $time_format = '%X') { $date = new Horde_Date($time); $delta = time() - $date->timestamp(); if ($delta < 60) { return sprintf(Horde_Date_Translation::ngettext("%d second ago", "%d seconds ago", $delta), $delta); } $delta = round($delta / 60); if ($delta < 60) { return sprintf(Horde_Date_Translation::ngettext("%d minute ago", "%d minutes ago", $delta), $delta); } $delta = round($delta / 60); if ($delta < 24) { return sprintf(Horde_Date_Translation::ngettext("%d hour ago", "%d hours ago", $delta), $delta); } if ($delta > 24 && $delta < 48) { $date = new Horde_Date($time); return sprintf(Horde_Date_Translation::t("yesterday at %s"), $date->strftime($time_format)); } $delta = round($delta / 24); if ($delta < 7) { return sprintf(Horde_Date_Translation::t("%d days ago"), $delta); } if (round($delta / 7) < 5) { $delta = round($delta / 7); return sprintf(Horde_Date_Translation::ngettext("%d week ago", "%d weeks ago", $delta), $delta); } // Default to the user specified date format. return $date->strftime($date_format); }
/** * Creates a new event that represents an exception to a recurring event. * * @param Kronolith_Event $event The original recurring event. * @param Kronolith_Event $copy If present, contains a copy of $event, but * with changes from edited event form. * @param stdClass $attributes The attributes passed from the client. * Expected to contain rstart and rend or * rday that represents the original * starting/ending date of the instance. * * @return Kronolith_Event The event representing the exception */ protected function _copyEvent(Kronolith_Event $event, Kronolith_Event $copy = null, $attributes = null) { if (empty($copy)) { $copy = clone $event; } if ($attributes->rstart) { $rstart = new Horde_Date($attributes->rstart); $rstart->setTimezone($event->start->timezone); $rend = new Horde_Date($attributes->rend); $rend->setTimezone($event->end->timezone); } else { $rstart = new Horde_Date($attributes->rday); $rstart->setTimezone($event->start->timezone); $rstart->hour = $event->start->hour; $rstart->min = $event->start->min; $rend = $rstart->add($event->getDuration); $rend->setTimezone($event->end->timezone); $rend->hour = $event->end->hour; $rend->min = $event->end->min; } $uid = $event->uid; $otime = $event->start->strftime('%T'); // Create new event for the exception $nevent = $event->getDriver()->getEvent(); $nevent->baseid = $uid; $nevent->exceptionoriginaldate = new Horde_Date($rstart->strftime('%Y-%m-%d') . 'T' . $otime); $nevent->exceptionoriginaldate->setTimezone($event->start->timezone); $nevent->creator = $event->creator; $nevent->title = $copy->title; $nevent->description = $copy->description; $nevent->location = $copy->location; $nevent->private = $copy->private; $nevent->url = $copy->url; $nevent->status = $copy->status; $nevent->attendees = $copy->attendees; $nevent->setResources($copy->getResources()); $nevent->start = $rstart; $nevent->end = $rend; $nevent->initialized = true; return $nevent; }
public function getTime($format, $offset = 0) { $date = new Horde_Date(array('month' => $this->month, 'mday' => $this->mday + $offset, 'year' => $this->year)); return $date->strftime($format); }
/** * Stop a timer. Expects the following in $this->vars: * - t: The timer id. * - restart: * * @return array An array describing the current timer state. Contains: * - h: The total number of hours elapsed so far. * - n: A note to apply to the description field of a time slice. * - t: The new timer title, if restarting. */ public function stopTimer() { global $prefs, $notification; try { $timer = Hermes::getTimer($this->vars->t); } catch (Horde_Exception_NotFound $e) { $notification->push(_("Invalid timer requested"), 'horde.error'); return false; } $results = $timer; $tname = $timer['name']; $elapsed = (!$timer['paused'] ? time() - $timer['time'] : 0) + $timer['elapsed']; $results['h'] = round((double) $elapsed / 3600, 2); $started = new Horde_Date($this->vars->t, 'UTC'); $started->setTimezone(date_default_timezone_get()); $now = new Horde_Date(time(), 'UTC'); $now->setTimezone(date_default_timezone_get()); if ($prefs->getValue('add_description')) { $results['n'] = sprintf(_("Using the \"%s\" stop watch from %s %s to %s %s"), $tname, $started->strftime($prefs->getValue('date_format_mini')), $started->strftime($prefs->getValue('time_format')), $now->strftime($prefs->getValue('date_format_mini')), $now->strftime($prefs->getValue('time_format'))); } else { $results['n'] = ''; } $notification->push(sprintf(_("The stop watch \"%s\" has been stopped."), $tname), 'horde.success'); Hermes::clearTimer($this->vars->t); if ($this->vars->restart == 'true') { $now = time(); $timer['elapsed'] = 0; $timer['paused'] = $results['paused'] = true; $timer['time'] = $now; Hermes::updateTimer($this->vars->t, $timer); } return $results; }
?> "><?php echo $this->h($tag); ?> </a></li> <?php } ?> </ul> </div> </td> <td class="trean-bookmarks-date"> <?php if ($bookmark->dt) { $dt = new Horde_Date($bookmark->dt); echo $dt->strftime($GLOBALS['prefs']->getValue('date_format')); } ?> </td> <td class="trean-bookmarks-clicks"> <?php echo $bookmark->clicks; ?> </td> <td class="trean-bookmarks-actions"> <a href="<?php echo Horde::url('edit.php')->add('bookmark', (int) $bookmark->id); ?> "><?php echo Horde::img('edit.png', _("Edit")); ?>
/** * Returns a correcty formatted exception date for recurring events. * * @param string $date Exception in the format Ymd. * @param string $format The format to display in. * * @return string The formatted date and delete link. * @since 2.1.0 */ protected function _formatExceptionDate($date, $format) { if (!preg_match('/(\\d{4})(\\d{2})(\\d{2})/', $date, $match)) { return ''; } $horde_date = new Horde_Date(array('year' => $match[1], 'month' => $match[2], 'mday' => $match[3])); return $horde_date->strftime($format); }
/** * @return string The time range of the event ("All Day", "1:00pm-3:00pm", * "08:00-22:00"). */ public function getTimeRange() { if ($this->isAllDay()) { return _("All day"); } elseif (($cmp = $this->start->compareDate($this->end)) > 0) { $df = $GLOBALS['prefs']->getValue('date_format'); if ($cmp > 0) { return $this->end->strftime($df) . '-' . $this->start->strftime($df); } else { return $this->start->strftime($df) . '-' . $this->end->strftime($df); } } else { $twentyFour = $GLOBALS['prefs']->getValue('twentyFour'); return $this->start->format($twentyFour ? 'G:i' : 'g:ia') . '-' . $this->end->format($twentyFour ? 'G:i' : 'g:ia'); } }
$notification->push(_("You do not have permission to edit this event."), 'horde.warning'); break; } $exception = new Horde_Date(Horde_Util::getFormData('recur_ex')); switch ($edit_recur) { case 'current': /* Add exception. */ $event->recurrence->addException($exception->year, $exception->month, $exception->mday); $event->save(); $uid = $event->uid; $originaltime = $event->start->strftime('%T'); /* Create one-time event. */ $event = $kronolith_driver->getEvent(); $event->readForm(); $event->baseid = $uid; $event->exceptionoriginaldate = new Horde_Date($exception->strftime('%Y-%m-%d') . 'T' . $originaltime); break; case 'future': /* Set recurrence end. */ $exception->mday--; if ($event->end->compareDate($exception) > 0 && $event->hasPermission(Horde_Perms::DELETE)) { try { $kronolith_driver->deleteEvent($event->id); } catch (Exception $e) { $notification->push($e, 'horde.error'); } } else { $event->recurrence->setRecurEnd($exception); $event->save(); } /* Create new event. */
public function testStrftimeUnsupported() { setlocale(LC_TIME, 'en_US.UTF-8'); $date = new Horde_Date('2001-02-03 16:05:06'); $this->assertEquals(strftime('%a', $date->timestamp()), $date->strftime('%a')); }
public function html() { global $prefs; $html = '<table id="kronolith-view-year" class="kronolith-minical"><tr>'; for ($month = 1; $month <= 12; ++$month) { $html .= '<td>'; // Heading for each month. $date = new Horde_Date(sprintf('%04d%02d01010101', $this->year, $month)); $html .= '<table><thead><tr class="kronolith-minical-nav"><th colspan="7">' . Horde::url('month.php')->add('date', $date->dateString())->link() . $date->strftime('%B') . '</a></th></tr><tr><th class="kronolith-minical-empty"> </th>'; if (!$prefs->getValue('week_start_monday')) { $html .= '<th>' . _("Su") . '</th>'; } $html .= '<th>' . _("Mo") . '</th>' . '<th>' . _("Tu") . '</th>' . '<th>' . _("We") . '</th>' . '<th>' . _("Th") . '</th>' . '<th>' . _("Fr") . '</th>' . '<th>' . _("Sa") . '</th>'; if ($prefs->getValue('week_start_monday')) { $html .= '<th>' . _("Su") . '</th>'; } $html .= '</tr></thead><tbody><tr><td class="kronolith-minical-week">'; $startday = new Horde_Date(array('mday' => 1, 'month' => $month, 'year' => $this->year)); $startday = $startday->dayOfWeek(); $daysInView = Date_Calc::weeksInMonth($month, $this->year) * 7; if (!$prefs->getValue('week_start_monday')) { $startOfView = 1 - $startday; // We may need to adjust the number of days in the // view if we're starting weeks on Sunday. if ($startday == Horde_Date::DATE_SUNDAY) { $daysInView -= 7; } $endday = new Horde_Date(array('mday' => Horde_Date_Utils::daysInMonth($month, $this->year), 'month' => $month, 'year' => $this->year)); $endday = $endday->dayOfWeek(); if ($endday == Horde_Date::DATE_SUNDAY) { $daysInView += 7; } } else { if ($startday == Horde_Date::DATE_SUNDAY) { $startOfView = -5; } else { $startOfView = 2 - $startday; } } $currentCalendars = array(true); foreach ($currentCalendars as $id => $cal) { $cell = 0; for ($day = $startOfView; $day < $startOfView + $daysInView; ++$day) { $date = new Kronolith_Day($month, $day, $this->year); $date->hour = $prefs->getValue('twentyFour') ? 12 : 6; $week = $date->weekOfYear(); if ($cell % 7 == 0) { if ($cell != 0) { $html .= "</tr>\n<tr><td class=\"kronolith-minical-week\">"; } $html .= (int) $date->weekOfYear() . '</td>'; } if ($date->month != $month) { $style = 'kronolith-other-month'; } else { $style = ''; } /* Set up the link to the day view. */ $url = Horde::url('day.php', true)->add('date', $date->dateString()); if ($date->month == $month && !empty($this->_events[$date->dateString()])) { /* There are events; create a cell with tooltip to list * them. */ $day_events = ''; foreach ($this->_events[$date->dateString()] as $event) { if ($event->status == Kronolith::STATUS_CONFIRMED) { /* Set the background color to distinguish the * day */ $style = 'year-event'; } if ($event->isAllDay()) { $day_events .= _("All day"); } else { $day_events .= $event->start->strftime($prefs->getValue('twentyFour') ? '%R' : '%I:%M%p') . '-' . $event->end->strftime($prefs->getValue('twentyFour') ? '%R' : '%I:%M%p'); } $day_events .= ':' . ($event->getLocation() ? ' (' . $event->getLocation() . ')' : '') . ' ' . $event->getTitle() . "\n"; } /* Bold the cell if there are events. */ $cellday = '<strong>' . Horde::linkTooltip($url, _("View Day"), '', '', '', $day_events) . $date->mday . '</a></strong>'; } else { /* No events, plain link to the day. */ $cellday = Horde::linkTooltip($url, _("View Day")) . $date->mday . '</a>'; } if ($date->isToday() && $date->month == $month) { $style .= ' kronolith-today'; } $html .= '<td align="center" class="' . $style . '" height="10" width="5%" valign="top">' . $cellday . '</td>'; ++$cell; } } $html .= '</tr></tbody></table></td>'; if ($month % 3 == 0 && $month != 12) { $html .= '</tr><tr>'; } } echo $html . '</tr></table>'; }