From a13add55de95c3145bf2fb626d322a0ffaae6b73 Mon Sep 17 00:00:00 2001 From: "Michael J. Rubinsky" Date: Mon, 8 Jun 2009 10:37:22 -0400 Subject: [PATCH] Check for existence of contacts API, check for PEAR_Error being returned --- timeobjects/lib/Driver/Weatherdotcom.php | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/timeobjects/lib/Driver/Weatherdotcom.php b/timeobjects/lib/Driver/Weatherdotcom.php index e2ae2ae55..13b20bf99 100644 --- a/timeobjects/lib/Driver/Weatherdotcom.php +++ b/timeobjects/lib/Driver/Weatherdotcom.php @@ -19,21 +19,26 @@ class TimeObjects_Driver_Weatherdotcom extends TimeObjects_Driver public function __construct($params) { + global $registry; + if (empty($params['location'])) { // Try to get a good location string from Turba's "own" contact - $contact = $GLOBALS['registry']->contacts->ownContact(); - $params['location'] = !empty($contact['homeCity']) - ? $contact['homeCity'] - . (!empty($contact['homeProvince']) ? ', ' . $contact['homeProvince'] : '') - . (!empty($contact['homeCountry']) ? ', ' . $contact['homeCountry'] : '') - : $contact['workCity'] - . (!empty($contact['workProvince']) ? ', ' . $contact['workProvince'] : '') - . (!empty($contact['workCountry']) ? ', ' . $contact['workCountry'] : ''); + if ($registry->hasInterface('contacts')) { + $contact = $GLOBALS['registry']->contacts->ownContact(); + if (!is_a($contact, 'PEAR_Error')) { + $params['location'] = !empty($contact['homeCity']) + ? $contact['homeCity'] + . (!empty($contact['homeProvince']) ? ', ' . $contact['homeProvince'] : '') + . (!empty($contact['homeCountry']) ? ', ' . $contact['homeCountry'] : '') + : $contact['workCity'] + . (!empty($contact['workProvince']) ? ', ' . $contact['workProvince'] : '') + . (!empty($contact['workCountry']) ? ', ' . $contact['workCountry'] : ''); + } + } + // TODO: Try some other way, maybe a hook or a new preference in Horde + // to set your current location, maybe with a google map? } - // TODO: Try some other way, maybe a hook or a new preference in Horde - // to set your current location, maybe with a google map? - parent::__construct($params); } -- 2.11.0