/** * Output an error if no CID was specified or the data wasn't in the * cache. */ function _cacheError($cid = null) { if (!is_null($cid)) { Horde::logMessage('CID ' . $cid . ' not found in the cache, unable to display.', __FILE__, __LINE__, PEAR_LOG_ERR); } exit; }
if ($auth->authenticate(Util::getPost('horde_user'), array('password' => Util::getPost('horde_pass')))) { $entry = sprintf('Login success for %s [%s] to Horde', Auth::getAuth(), $_SERVER['REMOTE_ADDR']); Horde::logMessage($entry, __FILE__, __LINE__, PEAR_LOG_INFO); if ($url_param) { $url = Horde::url(Util::removeParameter($url_param, session_name()), true); $horde_url = Horde::applicationUrl($registry->getParam('webroot', 'horde') . '/index.php', true); $horde_url = Util::addParameter($horde_url, 'url', $url); } else { $horde_url = Horde::applicationUrl('index.php', true); } $horde_url = Util::addParameter($horde_url, 'frameset', Util::getFormData('frameset') ? 1 : 0); header('Location: ' . $horde_url); exit; } else { $entry = sprintf('FAILED LOGIN for %s [%s] to Horde', Util::getFormData('horde_user'), $_SERVER['REMOTE_ADDR']); Horde::logMessage($entry, __FILE__, __LINE__, PEAR_LOG_ERR); if ($conf['menu']['always'] && !Util::getFormData('framed')) { $main_page = Util::addParameter(Horde::selfUrl(), 'framed', $auth->getLogoutReasonString()); if ($browser->hasQuirk('scrollbar_in_way')) { $scrollbar = 'yes'; } else { $scrollbar = 'auto'; } require HORDE_TEMPLATES . '/index/frames_index.inc'; exit; } } } if (Auth::isAuthenticated()) { if ($browser->isMobile()) { require HORDE_BASE . '/services/portal/mobile.php';
/** * Provides a standardised function to call a Horde hook, checking whether * a hook config file exists and whether the function itself exists. If * these two conditions are not satisfied it will return the specified * value (by default a PEAR error). * * @param string $hook The function to call. * @param array $args An array of any arguments to pass to the hook * function. * @param string $app If specified look for hooks in the config directory * of this app. * @param mixed $error What to return if $app/config/hooks.php or $hook * does not exist. If this is the string 'PEAR_Error' * a PEAR error object is returned instead, detailing * the failure. * * @return mixed Either the results of the hook or PEAR error on failure. */ function callHook($hook, $args = array(), $app = 'horde', $error = 'PEAR_Error') { global $registry; static $hooks_loaded = array(); if (!isset($hooks_loaded[$app])) { $success = Horde::loadConfiguration('hooks.php', null, $app); if (is_a($success, 'PEAR_Error')) { Horde::logMessage($success, __FILE__, __LINE__, PEAR_LOG_DEBUG); $hooks_loaded[$app] = false; } else { $hooks_loaded[$app] = true; } } if (function_exists($hook)) { $result = call_user_func_array($hook, $args); if (is_a($result, 'PEAR_Error')) { Horde::logMessage($result, __FILE__, __LINE__, PEAR_LOG_ERR); } return $result; } if (is_string($error) && strcmp($error, 'PEAR_Error') == 0) { $error = PEAR::raiseError(sprintf('Hook %s in application %s not called.', $hook, $app)); Horde::logMessage($error, __FILE__, __LINE__, PEAR_LOG_DEBUG); } return $error; }
/** * Say if a user is a member of a group or not. * * @param string $user The name of the user. * @param integer $gid The ID of the group. * @param boolean $subgroups Return true if the user is in any subgroups * of $group, also. * * @return boolean */ function userIsInGroup($user, $gid, $subgroups = true) { Horde::logMessage('userIsInGroup', __FILE__, __LINE__, PEAR_LOG_DEBUG); $groups = $this->getGroupMemberships($user, false); return in_array($gid, $groups) || parent::userIsInGroup($user, $gid, $subgroups); }
public function handleError($error, $sql, $values, $line) { $msg = 'SQL statement: ' . $sql . "\n"; $msg .= print_r($values, true); $msg .= 'Error reported: ' . !empty($error) && is_a($error, 'PEAR_Error') ? $error->getMessage() . "\nDebug info: " . $error->getDebugInfo() : $error; Horde::logMessage($msg, __FILE__, $line, PEAR_LOG_ERR); }
/** * The content to go in this block. * * @return string The content */ function _content() { if (!@(include_once 'Services/Weather.php')) { Horde::logMessage('The metar block will not work without Services_Weather from PEAR. Run pear install Services_Weather.', __FILE__, __LINE__, PEAR_LOG_ERR); return _("Metar block not available. Details have been logged for the administrator."); } global $conf; static $metarLocs; if (!isset($conf['sql'])) { return _("A database backend is required for this block."); } if (empty($this->_params['location'])) { return _("No location is set."); } if (!is_array($metarLocs)) { $metarLocs = $this->getParams(); } require_once 'Services/Weather.php'; $metar =& Services_Weather::service('METAR', array('debug' => 0)); $dbString = $conf['sql']['phptype'] . '://'; $dbString .= $conf['sql']['username'] . ':'; $dbString .= $conf['sql']['password'] . '@'; $dbString .= $conf['sql']['hostspec'] . '/'; $dbString .= $conf['sql']['database']; $metar->setMetarDB($dbString); $metar->setUnitsFormat($this->_params['units']); $metar->setDateTimeFormat('M j, Y', 'H:i'); $metar->setMetarSource('http'); $units = $metar->getUnits(0, $this->_params['units']); $weather = $metar->getWeather($this->_params['location']); $html = '<table width="100%" border="0" cellpadding="0" cellspacing="0">' . '<tr><td class="control"><b>' . sprintf('%s, %s (%s)', $metarLocs['location']['values'][$this->_params['__location']][$this->_params['location']], $this->_params['__location'], $this->_params['location']) . '</td></tr></table><b>' . _("Last Updated:") . '</b> ' . $weather['update'] . '<br /><br />'; // Wind. if (isset($weather['wind'])) { $html .= '<b>' . _("Wind:") . '</b> '; if ($weather['windDirection'] == 'Variable') { if (!empty($this->_params['knots'])) { $html .= sprintf(_('%s at %s %s'), $weather['windDirection'], round($metar->convertSpeed($weather['wind'], $units['wind'], 'kt')), 'kt'); } else { $html .= sprintf(_('%s at %s %s'), $weather['windDirection'], round($weather['wind']), $units['wind']); } } elseif ($weather['windDegrees'] == '000' && $weather['wind'] == '0') { $html .= sprintf(_("calm")); } else { $html .= sprintf(_("from the %s (%s) at %s %s"), $weather['windDirection'], $weather['windDegrees'], empty($this->_params['knots']) ? round($weather['wind']) : round($metar->convertSpeed($weather['wind'], $units['wind'], 'kt')), empty($this->_params['knots']) ? $units['wind'] : 'kt'); } } if (isset($weather['windGust'])) { if ($weather['windGust']) { if (!empty($this->_params['knots'])) { $html .= sprintf(_(", gusting %s %s"), round($metar->convertSpeed($weather['windGust'], $units['wind'], 'kt')), 'kt'); } else { $html .= sprintf(_(", gusting %s %s"), round($weather['windGust']), $units['wind']); } } } if (isset($weather['windVariability'])) { if ($weather['windVariability']['from']) { $html .= sprintf(_(", variable from %s to %s"), $weather['windVariability']['from'], $weather['windVariability']['to']); } } // Visibility. if (isset($weather['visibility'])) { $html .= $this->_row(_("Visibility"), $weather['visibility'] . ' ' . $units['vis']); } // Temperature/DewPoint. if (isset($weather['temperature'])) { $html .= $this->_row(_("Temperature"), round($weather['temperature']) . '°' . String::upper($units['temp'])); } if (isset($weather['dewPoint'])) { $html .= $this->_row(_("Dew Point"), round($weather['dewPoint']) . '°' . String::upper($units['temp'])); } if (isset($weather['feltTemperature'])) { $html .= $this->_row(_("Feels Like"), round($weather['feltTemperature']) . '°' . String::upper($units['temp'])); } // Pressure. if (isset($weather['pressure'])) { $html .= $this->_row(_("Pressure"), $weather['pressure'] . ' ' . $units['pres']); } // Humidity. if (isset($weather['humidity'])) { $html .= $this->_row(_("Humidity"), round($weather['humidity']) . '%'); } // Clouds. if (isset($weather['clouds'])) { $clouds = ''; foreach ($weather['clouds'] as $cloud) { $clouds .= '<br />'; if (isset($cloud['height'])) { $clouds .= sprintf(_("%s at %s ft"), $cloud['amount'], $cloud['height']); } else { $clouds .= $cloud['amount']; } } $html .= $this->_row(_("Clouds"), $clouds); } // Conditions. if (isset($weather['condition'])) { $html .= $this->_row(_("Conditions"), $weather['condition']); } // Remarks. if (isset($weather['remark'])) { $remarks = ''; $other = ''; foreach ($weather['remark'] as $remark => $value) { switch ($remark) { case 'seapressure': $remarks .= '<br />' . _("Pressure at sea level: ") . $value . ' ' . $units['pres']; break; case 'precipitation': foreach ($value as $precip) { if (is_numeric($precip['amount'])) { $remarks .= '<br />' . sprintf(_("Precipitation for last %s hour(s): "), $precip['hours']) . $precip['amount'] . ' ' . $units['rain']; } else { $remarks .= '<br />' . sprintf(_("Precipitation for last %s hour(s): "), $precip['hours']) . $precip['amount']; } } break; case 'snowdepth': $remarks .= '<br />' . _("Snow depth: ") . $value . ' ' . $units['rain']; break; case 'snowequiv': $remarks .= '<br />' . _("Snow equivalent in water: ") . $value . ' ' . $units['rain']; break; case 'sunduration': $remarks .= '<br />' . sprintf(_("%s minutes"), $value); break; case '1htemp': $remarks .= '<br />' . _("Temp for last hour: ") . round($value) . '°' . String::upper($units['temp']); break; case '1hdew': $remarks .= '<br />' . _("Dew Point for last hour: ") . round($value) . '°' . String::upper($units['temp']); break; case '6hmaxtemp': $remarks .= '<br />' . _("Max temp last 6 hours: ") . round($value) . '°' . String::upper($units['temp']); break; case '6hmintemp': $remarks .= '<br />' . _("Min temp last 6 hours: ") . round($value) . '°' . String::upper($units['temp']); break; case '24hmaxtemp': $remarks .= '<br />' . _("Max temp last 24 hours: ") . round($value) . '°' . String::upper($units['temp']); break; case '24hmintemp': $remarks .= '<br />' . _("Min temp last 24 hours: ") . round($value) . '°' . String::upper($units['temp']); break; case 'sensors': foreach ($value as $sensor) { $remarks .= '<br />' . _("Sensor: ") . $sensor; } break; default: $other .= '<br />' . $value; break; } } $html .= $this->_row(_("Remarks"), $remarks . $other); } return $html; }
/** * Creates an instance of the appropriate action class * then invokes the "execute" method on the instance. An optional * framework parameter may be delegated to the action. If * the Action implements a method matching the given task, it * will be invoked rather than the "execute" method. * * The return value from the Action will be passed to a * corresponding Page instance (created in the same manner) via * its "render" method. The given task may override the target * method as described above. * * If the Dispatcher instance is visible in global scope, the Action * implementation may dynamically override the task method for the * subsequent Page invocation as follows: * <pre> * global $dispatcher; * $dispatcher->setTask('pageTask'); * </pre> * * @param String $scope A key for finding the action/page prefix * @param String $task An optional target method to invoke */ public function dispatch($scope, $task = null) { $timer = Horde_Timer::singleton(); $timer->push(); // overall timer for action+page $this->setTask($task); $this->setRedirect(null); $action = $this->getAction($scope); if (!is_subclass_of($action, 'BaseAction')) { trigger_error("Invalid Action class: get_class({$action})", E_USER_ERROR); return; } $bean = null; $method = $this->getTask(); $timer->push(); // timer for action if (!empty($method) && in_array($method, get_class_methods($action))) { $bean = $action->{$method}($this->param); } else { $bean = $action->execute($this->param); } $this->timers[$scope . ':action'] = $timer->pop(); if ($this->getRedirect() == null || $scope == $this->getRedirect() && $task == $this->getTask()) { $page = $this->getPage($scope); if (!is_subclass_of($page, 'BasePage')) { trigger_error("Invalid Page class: get_class({$action})", E_USER_ERROR); return; } $method = $this->getTask(); $timer->push(); // timer for page if (!empty($method) && in_array($method, get_class_methods($page))) { $page->{$method}($bean); } else { $page->render($bean); } $this->timers[$scope . ':page'] = $timer->pop(); } else { $this->dispatch($this->getRedirect(), $this->getTask()); } $this->timers[$scope . ':overall'] = $timer->pop(); Horde::logMessage("Dispatcher timing (ms) for {$scope} [{$this->task}]: " . print_r($this->timers, true), __FILE__, __LINE__, PEAR_LOG_DEBUG); }
$perm->removeGroupPermission($group, PERMS_DELETE, false); } } $share->setPermission($perm); $share->save(); $notification->push(sprintf(_("Updated '%s'."), $share->get('name')), 'horde.success'); $form = 'edit.inc'; } break; } if (is_a($share, 'PEAR_Error')) { $title = _("Edit Permissions"); } else { $title = sprintf(_("Edit Permissions for %s"), $share->get('name')); } $userList = $auth->listUsers(); if (is_a($userList, 'PEAR_Error')) { Horde::logMessage($userList, __FILE__, __LINE__, PEAR_LOG_NOTICE); $userList = array(); } $groupList = $groups->listGroups(); if (is_a($groupList, 'PEAR_Error')) { Horde::logMessage($groupList, __FILE__, __LINE__, PEAR_LOG_NOTICE); $groupList = array(); } require HORDE_TEMPLATES . '/common-header.inc'; $notification->notify(array('listeners' => 'status')); if (!empty($form)) { require HORDE_TEMPLATES . '/shares/' . $form; } require HORDE_TEMPLATES . '/common-footer.inc';
/** * The content to go in this block. * * @return string The content */ function _content() { if (!@(include_once 'Services/Weather.php')) { Horde::logMessage('The weather.com block will not work without Services_Weather from PEAR. Run pear install Services_Weather.', __FILE__, __LINE__, PEAR_LOG_ERR); return _("The weather.com block is not available."); } global $conf; $cacheDir = Horde::getTempDir(); $html = ''; if (empty($this->_params['location'])) { return _("No location is set."); } $weatherDotCom =& Services_Weather::service("WeatherDotCom"); $weatherDotCom->setAccountData(isset($conf['weatherdotcom']['partner_id']) ? $conf['weatherdotcom']['partner_id'] : '', isset($conf['weatherdotcom']['license_key']) ? $conf['weatherdotcom']['license_key'] : ''); if (!$cacheDir) { return PEAR::raiseError(_("No temporary directory available for cache."), 'horde.error'); } else { $weatherDotCom->setCache("file", array("cache_dir" => $cacheDir . '/')); } $weatherDotCom->setDateTimeFormat("m.d.Y", "H:i"); $weatherDotCom->setUnitsFormat($this->_params['units']); $units = $weatherDotCom->getUnitsFormat(); // If the user entered a zip code for the location, no need to // search (weather.com accepts zip codes as location IDs). // The location ID should already have been validated in // getParams. $search = preg_match('/\\b(?:\\d{5}(-\\d{5})?)|(?:[A-Z]{4}\\d{4})\\b/', $this->_params['location'], $matches) ? $matches[0] : $weatherDotCom->searchLocation($this->_params['location']); if (is_a($search, 'PEAR_Error')) { return $search->getmessage(); } if (is_array($search)) { // Several locations returned due to imprecise location parameter $html = _("Several locations possible with the parameter: "); $html .= $this->_params['location']; $html .= "<br/><ul>"; foreach ($search as $id_weather => $real_location) { $html .= "<li>{$real_location} ({$id_weather})</li>\n"; } $html .= "</ul>"; return $html; } $location = $weatherDotCom->getLocation($search); if (is_a($location, 'PEAR_Error')) { return $location->getmessage(); } $weather = $weatherDotCom->getWeather($search); if (is_a($weather, 'PEAR_Error')) { return $weather->getmessage(); } $forecast = $weatherDotCom->getForecast($search, $this->_params['days']); if (is_a($forecast, 'PEAR_Error')) { return $forecast->getmessage(); } // Location and local time. $html .= "<table width=100%><tr><td class=control>"; $html .= '<b>' . $location['name'] . '</b>' . ' local time ' . $location['time']; $html .= "</b></td></tr></table>"; // Sunrise/sunset. $html .= '<b>' . _("Sunrise: ") . '</b>' . Horde::img('block/sunrise/sunrise.gif', _("Sunrise")) . $location['sunrise']; $html .= ' <b>' . _("Sunset: ") . '</b>' . Horde::img('block/sunrise/sunset.gif', _("Sunset")) . $location['sunset']; // Temperature. $html .= '<br /><b>' . _("Temperature: ") . '</b>'; $html .= $weather['temperature'] . '°' . String::upper($units['temp']); // Dew point. $html .= ' <b>' . _("Dew point: ") . '</b>'; $html .= $weather['dewPoint'] . '°' . String::upper($units['temp']); // Feels like temperature. $html .= ' <b>' . _("Feels like: ") . '</b>'; $html .= $weather['feltTemperature'] . '°' . String::upper($units['temp']); // Pressure and trend. $html .= '<br /><b>' . _("Pressure: ") . '</b>'; $html .= number_format($weather['pressure'], 2) . ' ' . $units['pres']; $html .= _(" and ") . $weather['pressureTrend']; // Wind. $html .= '<br /><b>' . _("Wind: ") . '</b>'; if ($weather['windDirection'] == 'VAR') { $html .= _("Variable"); } elseif ($weather['windDirection'] == 'CALM') { $html .= _("Calm"); } else { $html .= _("From the ") . $weather['windDirection']; $html .= ' (' . $weather['windDegrees'] . ')'; } $html .= _(" at ") . $weather['wind'] . ' ' . $units['wind']; // Humidity. $html .= '<br /><b>' . _("Humidity: ") . '</b>'; $html .= $weather['humidity'] . '%'; // Visibility. $html .= ' <b>' . _("Visibility: ") . '</b>'; $html .= $weather['visibility'] . (is_numeric($weather['visibility']) ? ' ' . $units['vis'] : ''); // UV index. $html .= ' <b>' . _("U.V. index: ") . '</b>'; $html .= $weather['uvIndex'] . ' - ' . $weather['uvText']; // Current condition. $html .= '<br /><b>' . _("Current condition: ") . '</b>' . Horde::img('block/weatherdotcom/32x32/' . $weather['conditionIcon'] . '.png', _(String::lower($weather['condition'])), 'align="middle"'); $html .= ' ' . $weather['condition']; // Do the forecast now. $html .= '<table border="0" width="100%" align="center"><tr>'; $html .= '<tr><td class="control" colspan="' . $this->_params['days'] * 2 . '"><center><b>' . $this->_params['days'] . '-day forecast</b></center></td></tr><tr>'; $futureDays = 0; foreach ($forecast['days'] as $which => $day) { $html .= '<td colspan="2" align="center">'; // Day name. $html .= '<b>'; if ($which == 0) { $html .= _("Today"); } elseif ($which == 1) { $html .= _("Tomorrow"); } else { $html .= strftime('%A', mktime(0, 0, 0, date('m'), date('d') + $futureDays, date('Y'))); } $html .= '</b><br />'; $futureDays++; // High/low temp. If after 2 p.m. local time, the "day" // forecast is no longer valid. if ($which > 0 || $which == 0 && strtotime($location['time']) < strtotime('14:00')) { $html .= '<span style="color:red">' . $day['tempertureHigh'] . '°' . String::upper($units['temp']) . '</span>/'; } $html .= '<span style="color:blue">' . $day['temperatureLow'] . '°' . String::upper($units['temp']) . '</span>'; $html .= '</td>'; } $html .= '</tr><tr>'; $elementWidth = 100 / ($this->_params['days'] * 2); foreach ($forecast['days'] as $which => $day) { // Day forecast. $html .= '<td align="center" valign="top" width="' . $elementWidth . '%">'; if ($which > 0 || $which == 0 && strtotime($location['time']) < strtotime('14:00')) { $html .= '<b><i>Day</i></b><br />'; $html .= Horde::img('block/weatherdotcom/23x23/' . $day['day']['conditionIcon'] . '.png', $day['day']['condition']); $html .= '<br />' . $day['day']['condition']; } else { $html .= ' '; } $html .= '</td>'; // Night forecast. $html .= '<td align="center" valign="top" width="' . $elementWidth . '%">'; $html .= '<b><i>Night</i></b><br />'; $html .= Horde::img('block/weatherdotcom/23x23/' . $day['night']['conditionIcon'] . '.png', $day['night']['condition']); $html .= '<br />' . $day['night']['condition']; $html .= '</td>'; } $html .= '</tr></table>'; // Display a bar at the bottom of the block with the required // attribution to weather.com and the logo, both linked to // weather.com with the partner ID. $html .= '<table width=100%><tr>'; $html .= '<td align=right class=control>'; $html .= 'Weather data provided by '; $html .= Horde::link('http://www.weather.com/?prod=xoap&par=' . $weatherDotCom->_partnerID, 'weather.com', '', '_blank', '', 'weather.com'); $html .= '<i>weather.com</i>® '; $html .= Horde::img('block/weatherdotcom/32x32/TWClogo_32px.png', 'weather.com logo'); $html .= '</a></td></tr></table>'; return $html; }
} break; case 'tmp': /* Getting a file from Horde's temp dir. */ $tmpdir = Horde::getTempDir(); if (empty($action) || $action == 'resize') { /* Use original if no action or if resizing. */ $file_name = $tmpdir . '/' . $file; } else { $file_name = $tmpdir . '/mod_' . $file; if (!file_exists($file_name)) { copy($tmpdir . '/' . $file, $file_name); } } if (!file_exists($file_name)) { Horde::logMessage(sprintf('Image not found [%s]', $file_name), __FILE__, __LINE__, PEAR_LOG_ERR); exit; } $size = filesize($file_name); $fp = @fopen($file_name, 'r'); $file_data = fread($fp, $size); fclose($fp); break; } /* Load the image object. */ require_once HORDE_LIBS . 'Horde/Image.php'; $image =& Horde_Image::singleton('gd'); $image->loadString($file, $file_data); /* Check if no editing action required and send the image to browser. */ if (empty($action)) { $image->display();