From b5f636ee56dd74007e1ee57d116ab4d384a2105b Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Mon, 11 Oct 2010 21:28:51 -0600 Subject: [PATCH] Convert Kronolith to using Horde_Session --- kronolith/attendees.php | 33 ++++++++----------- kronolith/lib/Ajax/Application.php | 2 +- kronolith/lib/Event.php | 26 +++------------ kronolith/lib/Kronolith.php | 49 ++++++++++++----------------- kronolith/lib/View/EditEvent.php | 4 +-- kronolith/new.php | 4 +-- kronolith/templates/attendees/attendees.inc | 6 ++-- kronolith/templates/panel.inc | 6 ++-- 8 files changed, 48 insertions(+), 82 deletions(-) diff --git a/kronolith/attendees.php b/kronolith/attendees.php index 6ee693bcf..e69597c2e 100644 --- a/kronolith/attendees.php +++ b/kronolith/attendees.php @@ -15,17 +15,10 @@ if (Kronolith::showAjaxView()) { } // Get the current attendees array from the session cache. -$attendees = (isset($_SESSION['kronolith']['attendees']) && - is_array($_SESSION['kronolith']['attendees'])) - ? $_SESSION['kronolith']['attendees'] - : array(); +$attendees = $session['kronolith:attendees;array']; +$resources = $session['kronolith:resources;array']; $editAttendee = null; -$resources = (isset($_SESSION['kronolith']['resources']) && - is_array($_SESSION['kronolith']['resources'])) - ? $_SESSION['kronolith']['resources'] - : array(); - // Get the action ID and value. This specifies what action the user initiated. $actionID = Horde_Util::getFormData('actionID'); if (Horde_Util::getFormData('clearAll')) { @@ -43,7 +36,7 @@ case 'add': $newAttendees = Kronolith::parseAttendees($newAttendees); if ($newAttendees) { - $_SESSION['kronolith']['attendees'] = $attendees + $newAttendees; + $session['kronolith:attendees'] = $attendees + $newAttendees; } // Any new resources? @@ -62,7 +55,7 @@ case 'add': 'name' => $resource->get('name'), ); - $_SESSION['kronolith']['resources'] = $resources; + $session['kronolith:resources'] = $resources; } if (Horde_Util::getFormData('addNewClose')) { @@ -85,7 +78,7 @@ case 'edit': : ' <' . $actionValue . '>')); } unset($attendees[$actionValue]); - $_SESSION['kronolith']['attendees'] = $attendees; + $session['kronolith:attendees'] = $attendees; } break; @@ -94,7 +87,7 @@ case 'remove': $actionValue = Horde_String::lower($actionValue); if (isset($attendees[$actionValue])) { unset($attendees[$actionValue]); - $_SESSION['kronolith']['attendees'] = $attendees; + $session['kronolith:attendees'] = $attendees; } break; @@ -102,7 +95,7 @@ case 'removeResource': // Remove the specified resource if (isset($resources[$actionValue])) { unset($resources[$actionValue]); - $_SESSION['kronolith']['resources'] = $resources; + $session['kronolith:resources'] = $resources; } break; @@ -111,7 +104,7 @@ case 'changeResourceResp': list($partval, $partname) = explode(' ', $actionValue, 2); if (isset($resources[$partname])) { $resources[$partname]['response'] = $partval; - $_SESSION['kronolith']['resources'] = $resources; + $session['kronolith:resources'] = $resources; } break; @@ -121,7 +114,7 @@ case 'changeatt': $partname = Horde_String::lower($partname); if (isset($attendees[$partname])) { $attendees[$partname]['attendance'] = $partval; - $_SESSION['kronolith']['attendees'] = $attendees; + $session['kronolith:attendees'] = $attendees; } break; @@ -131,7 +124,7 @@ case 'changeResourceAtt': $partname = Horde_String::lower($partname); if (isset($resources[$partname])) { $resources[$partname]['attendance'] = $partval; - $_SESSION['kronolith']['resources'] = $resources; + $session['kronolith:resources'] = $resources; } break; @@ -141,7 +134,7 @@ case 'changeresp': $partname = Horde_String::lower($partname); if (isset($attendees[$partname])) { $attendees[$partname]['response'] = $partval; - $_SESSION['kronolith']['attendees'] = $attendees; + $session['kronolith:attendees'] = $attendees; } break; @@ -166,7 +159,7 @@ case 'dismiss': case 'clear': // Remove all the attendees and resources. - $_SESSION['kronolith']['attendees'] = $_SESSION['kronolith']['resources'] = array(); + unset($session['kronolith:attendees'], $session['kronolith:resources']); break; } @@ -216,7 +209,7 @@ try { } // Add the Free/Busy information for each attendee. -foreach ($_SESSION['kronolith']['attendees'] as $email => $status) { +foreach ($session['kronolith:attendees;array'] as $email => $status) { if (strpos($email, '@') !== false && ($status['attendance'] == Kronolith::PART_REQUIRED || $status['attendance'] == Kronolith::PART_OPTIONAL)) { diff --git a/kronolith/lib/Ajax/Application.php b/kronolith/lib/Ajax/Application.php index 73fa82e54..263aa84c5 100644 --- a/kronolith/lib/Ajax/Application.php +++ b/kronolith/lib/Ajax/Application.php @@ -666,7 +666,7 @@ class Kronolith_Ajax_Application extends Horde_Core_Ajax_Application return $result; } $tasklist = $tasklists[$tasklistId]; - $_SESSION['all_external_calendars']['tasks/' . $tasklistId] = new Kronolith_Calendar_External(array('api' => 'tasks', 'name' => $tasklist->get('name'))); + //$GLOBALS['session']['kronolith:all_external_calendars']['tasks/' . $tasklistId] = new Kronolith_Calendar_External(array('api' => 'tasks', 'name' => $tasklist->get('name'))); $GLOBALS['display_external_calendars'][] = 'tasks/' . $tasklistId; $GLOBALS['prefs']->setValue('display_external_cals', serialize($GLOBALS['display_external_calendars'])); Kronolith::readPermsForm($tasklist); diff --git a/kronolith/lib/Event.php b/kronolith/lib/Event.php index e6e0a83c2..2247c56b2 100644 --- a/kronolith/lib/Event.php +++ b/kronolith/lib/Event.php @@ -2043,30 +2043,12 @@ abstract class Kronolith_Event $this->status = Horde_Util::getFormData('status', $this->status); // Attendees. - $attendees = Horde_Util::getFormData('attendees'); - if (isset($_SESSION['kronolith']['attendees']) && is_array($_SESSION['kronolith']['attendees'])) { - $this->attendees = $_SESSION['kronolith']['attendees']; - if ($attendees) { - if ($attendees = Kronolith::parseAttendees(trim($attendees))) { - $this->attendees = $attendees; - } - } - } else { - if ($attendees) { - if ($attendees = Kronolith::parseAttendees(trim($attendees))) { - $this->attendees = $attendees; - } - } else { - $attendees = array(); - } - - $this->attendees = $attendees; - } + $this->attendees = ($attendees = Horde_Util::getFormData('attendees')) + ? $attendees + : $session['kronolith:attendees;array']; // Resources - if (isset($_SESSION['kronolith']['resources']) && is_array($_SESSION['kronolith']['resources'])) { - $this->_resources = $_SESSION['kronolith']['resources']; - } + $this->_resources = $session['kronolith:resources;array']; // strptime() is locale dependent, i.e. %p is not always matching // AM/PM. Set the locale to C to workaround this, but grab the diff --git a/kronolith/lib/Kronolith.php b/kronolith/lib/Kronolith.php index 33699572d..de785d7d7 100644 --- a/kronolith/lib/Kronolith.php +++ b/kronolith/lib/Kronolith.php @@ -935,11 +935,6 @@ class Kronolith $_SERVER['REQUEST_TIME'] = time(); } - /* Initialize Kronolith session if we don't have one */ - if (!isset($_SESSION['kronolith'])) { - $_SESSION['kronolith'] = array(); - } - /* Fetch display preferences. */ $GLOBALS['display_calendars'] = @unserialize($GLOBALS['prefs']->getValue('display_cals')); $GLOBALS['display_remote_calendars'] = @unserialize($GLOBALS['prefs']->getValue('display_remote_cals')); @@ -965,9 +960,10 @@ class Kronolith * back to an available calendar. An empty string passed in this * parameter will clear any existing session value.*/ if (($calendarId = Horde_Util::getFormData('display_cal')) !== null) { - $_SESSION['kronolith']['display_cal'] = $calendarId; + $GLOBALS['session']['kronolith:display_cal'] = $calendarId; } - if (!empty($_SESSION['kronolith']['display_cal'])) { + + if (isset($GLOBALS['session']['kronolith:display_cal'])) { /* Specifying a value for display_cal is always to make sure * that only the specified calendars are shown. Use the * "toggle_calendar" argument to toggle the state of a single @@ -977,7 +973,7 @@ class Kronolith $GLOBALS['display_external_calendars'] = array(); $GLOBALS['display_resource_calendars'] = array(); $GLOBALS['display_holidays'] = array(); - $calendars = $_SESSION['kronolith']['display_cal']; + $calendars = $sessino['kronolith:display_cal']; if (!is_array($calendars)) { $calendars = array($calendars); } @@ -1102,12 +1098,14 @@ class Kronolith /* Get a list of external calendars. */ $GLOBALS['all_external_calendars'] = array(); - if (isset($_SESSION['all_external_calendars'])) { - foreach ($_SESSION['all_external_calendars'] as $calendar) { + if (isset($GLOBALS['session']['kronolith:all_external_calendars'])) { + foreach ($GLOBALS['session']['kronolith:all_external_calendars'] as $calendar) { $GLOBALS['all_external_calendars'][$calendar['a'] . '/' . $calendar['n']] = new Kronolith_Calendar_External(array('api' => $calendar['a'], 'name' => $calendar['d'])); } } else { $apis = array_unique($GLOBALS['registry']->listAPIs()); + $ext_cals = $GLOBALS['session']['kronolith:all_external_calendars;array']; + foreach ($apis as $api) { if (!$GLOBALS['registry']->hasMethod($api . '/listTimeObjects')) { continue; @@ -1121,11 +1119,15 @@ class Kronolith foreach ($categories as $name => $description) { $GLOBALS['all_external_calendars'][$api . '/' . $name] = new Kronolith_Calendar_External(array('api' => $api, 'name' => $description)); - $_SESSION['all_external_calendars'][] = array('a' => $api, - 'n' => $name, - 'd' => $description); + $ext_cals[] = array( + 'a' => $api, + 'n' => $name, + 'd' => $description + ); } } + + $GLOBALS['session']['kronolith:all_external_calendars'] = $ext_cals; } /* Make sure all the external calendars still exist. */ @@ -2199,26 +2201,15 @@ class Kronolith */ public static function attendeeList() { - $attendees = array(); - /* Attendees */ - if (isset($_SESSION['kronolith']['attendees']) && - is_array($_SESSION['kronolith']['attendees'])) { - - $attendees = array(); - foreach ($_SESSION['kronolith']['attendees'] as $email => $attendee) { - $attendees[] = empty($attendee['name']) ? $email : Horde_Mime_Address::trimAddress($attendee['name'] . (strpos($email, '@') === false ? '' : ' <' . $email . '>')); - } - + $attendees = array(); + foreach ($GLOBALS['session']['kronolith:attendees;array'] as $email => $attendee) { + $attendees[] = empty($attendee['name']) ? $email : Horde_Mime_Address::trimAddress($attendee['name'] . (strpos($email, '@') === false ? '' : ' <' . $email . '>')); } /* Resources */ - if (isset($_SESSION['kronolith']['resources']) && - is_array($_SESSION['kronolith']['resources'])) { - - foreach ($_SESSION['kronolith']['resources'] as $resource) { - $attendees[] = $resource['name']; - } + foreach ($GLOBALS['session']['kronolith:resources;array'] as $resource) { + $attendees[] = $resource['name']; } return implode(', ', $attendees); diff --git a/kronolith/lib/View/EditEvent.php b/kronolith/lib/View/EditEvent.php index ad2985dad..ca6b705d9 100644 --- a/kronolith/lib/View/EditEvent.php +++ b/kronolith/lib/View/EditEvent.php @@ -58,8 +58,8 @@ class Kronolith_View_EditEvent { } catch (Exception $e) { } } - $_SESSION['kronolith']['attendees'] = $this->event->attendees; - $_SESSION['kronolith']['resources'] = $this->event->getResources(); + $GLOBALS['session']['kronolith:attendees'] = $this->event->attendees; + $GLOBALS['session']['kronolith:resources'] = $this->event->getResources(); if ($datetime = Horde_Util::getFormData('datetime')) { $datetime = new Horde_Date($datetime); $month = $datetime->month; diff --git a/kronolith/new.php b/kronolith/new.php index dd21a8699..0ea766b14 100644 --- a/kronolith/new.php +++ b/kronolith/new.php @@ -38,8 +38,8 @@ if ($calendar_id == 'internal_') { } $event = Kronolith::getDriver()->getEvent(); -$_SESSION['kronolith']['attendees'] = $event->attendees; -$_SESSION['kronolith']['resources'] = $event->getResources(); +$session['kronolith:attendees'] = $event->attendees; +$session['kronolith:resources'] = $event->getResources(); $date = Horde_Util::getFormData('datetime'); if (!$date) { diff --git a/kronolith/templates/attendees/attendees.inc b/kronolith/templates/attendees/attendees.inc index c60ba3c2b..f3a7afce4 100644 --- a/kronolith/templates/attendees/attendees.inc +++ b/kronolith/templates/attendees/attendees.inc @@ -51,9 +51,9 @@ function switchDateView(view, date) - + - $status): ?> + $status): ?> link(array('title' => sprintf(_("Remove %s"), $name), 'onclick' => "performAction('remove', decodeURIComponent('" . rawurlencode($email) . "')); return false;")) . Horde::img('delete.png') . ' ' . Horde::url('#')->link(array('title' => sprintf(_("Edit %s"), $name), 'onclick' => "performAction('edit', decodeURIComponent('" . rawurlencode($email) . "')); return false;")) . Horde::img('edit.png') . '' ?> '))) ?> @@ -147,7 +147,7 @@ function switchDateView(view, date)
" /> " /> - " /> + " />

diff --git a/kronolith/templates/panel.inc b/kronolith/templates/panel.inc index 099ed7dd0..7f6f22a0c 100644 --- a/kronolith/templates/panel.inc +++ b/kronolith/templates/panel.inc @@ -43,11 +43,11 @@ $tagger = Kronolith::getTagger();
- + getAuth() ? _("Return to my calendars") : _("Return to calendars") ?> - +
- +

-- 2.11.0