Builds the body MIME part of a multipart message.
public static buildMimeMessage ( Horde_View $view, string $template, Horde_Mime_Part $image ) : Horde_Mime_Part | ||
$view | Horde_View | A view to render the HTML and plain text templates for the messate. |
$template | string | The template base name for the view. |
$image | Horde_Mime_Part | The MIME part of a related image. |
return | Horde_Mime_Part | A multipart/alternative MIME part. |
/** * Returns an alarm hash of this event suitable for Horde_Alarm. * * @param Horde_Date $time Time of alarm. * @param string $user The user to return alarms for. * @param Prefs $prefs A Prefs instance. * * @return array Alarm hash or null. */ public function toAlarm($time, $user = null, $prefs = null) { if (!$this->alarm || $this->status == Kronolith::STATUS_CANCELLED) { return; } if ($this->recurs()) { $eventDate = $this->recurrence->nextRecurrence($time); if (!$eventDate || $eventDate && $this->recurrence->hasException($eventDate->year, $eventDate->month, $eventDate->mday)) { return; } $start = clone $eventDate; $diff = Date_Calc::dateDiff($this->start->mday, $this->start->month, $this->start->year, $this->end->mday, $this->end->month, $this->end->year); if ($diff == -1) { $diff = 0; } $end = new Horde_Date(array('year' => $start->year, 'month' => $start->month, 'mday' => $start->mday + $diff, 'hour' => $this->end->hour, 'min' => $this->end->min, 'sec' => $this->end->sec)); } else { $start = clone $this->start; $end = clone $this->end; } $serverName = $_SERVER['SERVER_NAME']; $serverConf = $GLOBALS['conf']['server']['name']; if (!empty($GLOBALS['conf']['reminder']['server_name'])) { $_SERVER['SERVER_NAME'] = $GLOBALS['conf']['server']['name'] = $GLOBALS['conf']['reminder']['server_name']; } if (empty($user)) { $user = $GLOBALS['registry']->getAuth(); } if (empty($prefs)) { $prefs = $GLOBALS['prefs']; } $methods = !empty($this->methods) ? $this->methods : @unserialize($prefs->getValue('event_alarms')); if (isset($methods['notify'])) { $methods['notify']['show'] = array('__app' => $GLOBALS['registry']->getApp(), 'event' => $this->id, 'calendar' => $this->calendar); $methods['notify']['ajax'] = 'event:' . $this->calendarType . '|' . $this->calendar . ':' . $this->id . ':' . $start->dateString(); if (!empty($methods['notify']['sound'])) { if ($methods['notify']['sound'] == 'on') { // Handle boolean sound preferences. $methods['notify']['sound'] = (string) Horde_Themes::sound('theetone.wav'); } else { // Else we know we have a sound name that can be // served from Horde. $methods['notify']['sound'] = (string) Horde_Themes::sound($methods['notify']['sound']); } } if ($this->isAllDay()) { if ($start->compareDate($end) == 0) { $methods['notify']['subtitle'] = sprintf(_("On %s"), '<strong>' . $start->strftime($prefs->getValue('date_format')) . '</strong>'); } else { $methods['notify']['subtitle'] = sprintf(_("From %s to %s"), '<strong>' . $start->strftime($prefs->getValue('date_format')) . '</strong>', '<strong>' . $end->strftime($prefs->getValue('date_format')) . '</strong>'); } } else { $methods['notify']['subtitle'] = sprintf(_("From %s at %s to %s at %s"), '<strong>' . $start->strftime($prefs->getValue('date_format')), $start->format($prefs->getValue('twentyFour') ? 'H:i' : 'h:ia') . '</strong>', '<strong>' . $end->strftime($prefs->getValue('date_format')), $this->end->format($prefs->getValue('twentyFour') ? 'H:i' : 'h:ia') . '</strong>'); } } if (isset($methods['mail'])) { $image = Kronolith::getImagePart('big_alarm.png'); $view = new Horde_View(array('templatePath' => KRONOLITH_TEMPLATES . '/alarm', 'encoding' => 'UTF-8')); new Horde_View_Helper_Text($view); $view->event = $this; $view->imageId = $image->getContentId(); $view->user = $user; $view->dateFormat = $prefs->getValue('date_format'); $view->timeFormat = $prefs->getValue('twentyFour') ? 'H:i' : 'h:ia'; $view->start = $start; if (!$prefs->isLocked('event_reminder')) { $view->prefsUrl = Horde::url($GLOBALS['registry']->getServiceLink('prefs', 'kronolith'), true)->remove(session_name()); } if ($this->attendees) { $view->attendees = Kronolith::getAttendeeEmailList($this->attendees)->addresses; } $methods['mail']['mimepart'] = Kronolith::buildMimeMessage($view, 'mail', $image); } if (isset($methods['desktop'])) { if ($this->isAllDay()) { if ($this->start->compareDate($this->end) == 0) { $methods['desktop']['subtitle'] = sprintf(_("On %s"), $start->strftime($prefs->getValue('date_format'))); } else { $methods['desktop']['subtitle'] = sprintf(_("From %s to %s"), $start->strftime($prefs->getValue('date_format')), $end->strftime($prefs->getValue('date_format'))); } } else { $methods['desktop']['subtitle'] = sprintf(_("From %s at %s to %s at %s"), $start->strftime($prefs->getValue('date_format')), $start->format($prefs->getValue('twentyFour') ? 'H:i' : 'h:ia'), $end->strftime($prefs->getValue('date_format')), $this->end->format($prefs->getValue('twentyFour') ? 'H:i' : 'h:ia')); } $methods['desktop']['url'] = strval($this->getViewUrl(array(), true, false)); } $alarmStart = clone $start; $alarmStart->min -= $this->alarm; $alarm = array('id' => $this->uid, 'user' => $user, 'start' => $alarmStart, 'end' => $end, 'methods' => array_keys($methods), 'params' => $methods, 'title' => $this->getTitle($user), 'text' => $this->description, 'instanceid' => $this->recurs() ? $eventDate->dateString() : null); $_SERVER['SERVER_NAME'] = $serverName; $GLOBALS['conf']['server']['name'] = $serverConf; return $alarm; }