/usr/bin/kronolith-agenda is in php-horde-kronolith 4.2.23-1ubuntu1.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 | #!/usr/bin/php
<?php
/**
* Copyright 2003-2017 Horde LLC (http://www.horde.org/)
*
* See the enclosed file COPYING for license information (GPL). If you
* did not receive this file, see http://www.horde.org/licenses/gpl.
*
* @author Chuck Hagenbuch <chuck@horde.org>
*/
if (file_exists(__DIR__ . '/../../kronolith/lib/Application.php')) {
$baseDir = __DIR__ . '/../';
} else {
require_once 'PEAR/Config.php';
$baseDir = PEAR_Config::singleton()
->get('horde_dir', null, 'pear.horde.org') . '/kronolith/';
}
require_once $baseDir . 'lib/Application.php';
Horde_Registry::appInit('kronolith', array('cli' => true));
send_agendas();
/**
*/
function send_agendas()
{
if (isset($_SERVER['REQUEST_TIME'])) {
$runtime = $_SERVER['REQUEST_TIME'];
} else {
$runtime = time();
}
$kronolith_shares = $GLOBALS['injector']->getInstance('Kronolith_Shares');
$calendars = $kronolith_shares->listAllShares();
// If there are no calendars to check, we're done.
if (!count($calendars)) {
return;
}
if (empty($GLOBALS['conf']['reminder']['server_name']) ||
empty($GLOBALS['conf']['reminder']['from_addr'])) {
die('You must configure the server_name and from_addr settings for reminders in the calendar configuration.');
}
$_SERVER['SERVER_NAME'] = $GLOBALS['conf']['server']['name'] = $GLOBALS['conf']['reminder']['server_name'];
// Retrieve a list of users associated with each calendar, and
// thus a list of users who have used kronolith and
// potentially have an agenda preference set.
$users = array();
foreach (array_keys($calendars) as $calendarId) {
try {
$calendar = $kronolith_shares->getShare($calendarId);
} catch (Exception $e) {
continue;
}
$users = array_merge($users, $calendar->listUsers(Horde_Perms::READ));
}
// Remove duplicates.
$users = array_unique($users);
// Generate image mime part first and only once, because we need
// the Content-ID.
$image = Kronolith::getImagePart('big_agenda.png');
$runtime = new Horde_Date($runtime);
$default_timezone = date_default_timezone_get();
$kronolith_driver = Kronolith::getDriver();
$view = new Horde_View(array('templatePath' => KRONOLITH_TEMPLATES . '/agenda', 'encoding' => 'UTF-8'));
new Horde_View_Helper_Text($view);
$view->imageId = $image->getContentId();
$view->date = $runtime;
if (!$GLOBALS['prefs']->isLocked('daily_agenda')) {
$view->prefsUrl = Horde::url($GLOBALS['registry']->getServiceLink('prefs', 'kronolith'), true)->remove(session_name());
}
// Loop through the users and generate an agenda for them
foreach ($users as $user) {
$prefs = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Prefs')->create('kronolith', array(
'user' => $user
));
$agenda_calendars = $prefs->getValue('daily_agenda');
if (!$agenda_calendars) {
continue;
}
// Initialize the CalendarsManager for this user.
$GLOBALS['calendar_manager'] = new Kronolith_CalendarsManager($user);
// Try to find an email address for the user.
$identity = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Identity')->create($user);
$email = $identity->getDefaultFromAddress(true);
// Check if user has a timezone pref, and set it. Otherwise, make
// sure to use the server's default timezone.
$tz = $prefs->getValue('timezone');
date_default_timezone_set(empty($tz) ? $default_timezone : $tz);
// If we found an email address, generate the agenda.
switch ($agenda_calendars) {
case 'owner':
$calendars = $kronolith_shares->listShares(
$user,
array('perm' => Horde_Perms::SHOW,
'attributes' => $user));
$calendars = array_keys($calendars);
break;
case 'read':
$calendars = $kronolith_shares->listShares(
$user,
array('perm' => Horde_Perms::READ));
$calendars = array_keys($calendars);
break;
case 'show':
default:
$calendars = array();
$shown_calendars = unserialize($prefs->getValue('display_cals'));
$cals = $kronolith_shares->listShares(
$user,
array('perm' => Horde_Perms::SHOW));
foreach (array_keys($cals) as $calId) {
if (in_array($calId, $shown_calendars)) {
$calendars[] = $calId;
}
}
}
// Get a list of events for today
$eventlist = array();
foreach ($calendars as $calId) {
$kronolith_driver->open($calId);
$events = $kronolith_driver->listEvents(
$runtime, $runtime, array('show_recurrence' => true));
foreach ($events as $dayevents) {
foreach ($dayevents as $event) {
// The event list contains events starting at 12am.
if ($event->start->compareDate($runtime) || $event->isPrivate($user)) {
continue;
}
$eventlist[] = $event;
}
}
}
if (!count($eventlist)) {
continue;
}
// If there are any events, generate and send the email.
usort($eventlist, 'sort_events');
$GLOBALS['registry']->setLanguageEnvironment($prefs->getValue('language'));
$twentyFour = $prefs->getValue('twentyFour');
$view->pad = max(Horde_String::length(_("All day")) + 2, $twentyFour ? 6 : 8);
$view->dateFormat = $prefs->getValue('date_format');
$view->timeformat = $twentyFour ? 'H:i' : 'h:ia';
$view->user = $user;
$view->events = $eventlist;
$mime_mail = new Horde_Mime_Mail(array(
'Subject' => sprintf(_("Your daily agenda for %s"), $runtime->strftime($view->dateFormat)),
'To' => $email,
'From' => $GLOBALS['conf']['reminder']['from_addr'],
'User-Agent' => 'Kronolith ' . $GLOBALS['registry']->getVersion(),
'Auto-Submitted' => 'auto-generated'));
try {
$mime_mail->addRecipients($email);
} catch (Horde_Mime_Exception $e) {}
$mime_mail->setBasePart(Kronolith::buildMimeMessage($view, 'notification', $image));
Horde::log(sprintf('Sending daily agenda to %s', $email), 'DEBUG');
try {
$mime_mail->send($GLOBALS['injector']->getInstance('Horde_Mail'));
} catch (Horde_Mime_Exception $e) {
Horde::log(sprintf('Error sending daily agenda to %s: %s', $email, $e->getMessage()), 'WARN');
}
}
}
function sort_events($a, $b)
{
if ($a->allday && $b->allday) {
return 0;
}
if ($a->allday || $b->allday) {
return ($a->allday) ? -1 : 1;
}
if ($a->start == $b->start) {
return 0;
}
return ($a->start < $b->start) ? -1 : 1;
}
|