steffen: server/kolab-horde-fbview/kolab-horde-fbview/fbview/lib/Block color.php, NONE, 1.1 fortune.php, NONE, 1.1 google.php, NONE, 1.1 iframe.php, NONE, 1.1 metar.php, NONE, 1.1 moon.php, NONE, 1.1 sunrise.php, NONE, 1.1 time.php, NONE, 1.1 weatherdotcom.php, NONE, 1.1

cvs at intevation.de cvs at intevation.de
Mon Oct 31 12:43:25 CET 2005


Author: steffen

Update of /kolabrepository/server/kolab-horde-fbview/kolab-horde-fbview/fbview/lib/Block
In directory doto:/tmp/cvs-serv18388/kolab-horde-fbview/kolab-horde-fbview/fbview/lib/Block

Added Files:
	color.php fortune.php google.php iframe.php metar.php moon.php 
	sunrise.php time.php weatherdotcom.php 
Log Message:
Fbview in separate package

--- NEW FILE: color.php ---
<?php
/**
 * $Horde: horde/lib/Block/color.php,v 1.9 2004/05/29 16:21:03 jan Exp $
 *
 * @package Horde_Block
 */
class Horde_Block_color extends Horde_Block {

    var $_app = 'horde';

    function getParams()
    {
        return array('type' => 'text',
                     'name' => _("Color"),
                     'default' => '#ff0000');
    }

    /**
     * The title to go in this block.
     *
     * @return string   The title text.
     */
    function _title()
    {
        return _("Color");
    }

    /**
     * The content to go in this block.
     *
     * @return string   The content
     */
    function _content()
    {
        $html  = '<table width="100" height="100" bgcolor="%s">';
        $html .= '<tr><td> </td></tr>';
        $html .= '</table>';

        return sprintf($html, $this->_params['color']);
    }

}

--- NEW FILE: fortune.php ---
<?php
/**
 * $Horde: horde/lib/Block/fortune.php,v 1.7 2004/05/29 16:21:03 jan Exp $
 *
 * @package Horde_Block
 */
class Horde_Block_fortune extends Horde_Block {

    var $_app = 'horde';

    /**
     * The title to go in this block.
     *
     * @return string   The title text.
     */
    function _title()
    {
        return _("Fortune");
    }

    /**
     * The content to go in this block.
     *
     * @return string   The content
     */
    function _content()
    {
        return nl2br(shell_exec($this->_params['fortune']));
    }

}

--- NEW FILE: google.php ---
<?php
/**
 * $Horde: horde/lib/Block/google.php,v 1.7 2004/05/29 16:21:03 jan Exp $
 *
 * @package Horde_Block
 */
class Horde_Block_google extends Horde_Block {

    var $_app = 'horde';

    /**
     * The title to go in this block.
     *
     * @return string   The title text.
     */
    function _title()
    {
        return _("Google Search");
    }

    /**
     * The content to go in this block.
     *
     * @return string   The content
     */
    function _content()
    {
        $html  = '<form name="google" onsubmit="open_google_win(); return false;">';
        $html .= '<table width="100%" height="100%">';
        $html .= '<tr><script language="JavaScript" type="text/javascript" src="' . $GLOBALS['registry']->getParam('webroot', 'horde') . '/services/javascript.php?file=open_google_win.js&app=horde"></script>';
        $html .= '<td>' . Horde::img('google.png', 'Google') . '</td></tr>';
        $html .= '<tr><td><input maxLength="256" size="40" name="q" width="100%" /></td></tr>';
        $html .= '<tr><td><table width="100%"><tr><td align="center"><input type="radio" name="area" value="web" width="20%" checked="checked" />' . _("Web") . '</td>';
        $html .= '<td align="center"><input type="radio" name="area" value="images" width="20%" />' . _("Images") . '</td>';
        $html .= '<td align="center"><input type="radio" name="area" value="groups" width="20%" />' . _("Groups") . '</td>';
        $html .= '<td align="center"><input type="radio" name="area" value="directory" width="20%" />' . _("Directory") . '</td>';
        $html .= '<td align="center"><input type="radio" name="area" value="news" width="20%" />' . _("News") . '</td></tr></table></td></tr>';
        $html .= '<tr><td><input type="submit" class="button" value="' . _("Google Search") . '" /></td></tr>';
        $html .= '</table>';
        $html .= '</form>';
        return $html;
    }

}

--- NEW FILE: iframe.php ---
<?php
/**
 * $Horde: horde/lib/Block/iframe.php,v 1.12 2004/05/29 16:21:03 jan Exp $
 *
 * @package Horde_Block
 */
class Horde_Block_iframe extends Horde_Block {

    var $_app = 'horde';

    function getParams()
    {
        return array('iframe' => array('type' => 'text',
                                       'name' => _("URL"),
                                       'default' => 'http://slashdot.org/'),
                     'title'  => array('type' => 'text',
                                       'name' => _("Title")));
    }

    /**
     * The title to go in this block.
     *
     * @return string   The title text.
     */
    function _title()
    {
        global $registry;

        $title = isset($this->_params['title']) ? $this->_params['title'] :$this->_params['iframe'];

        $html  = Horde::link($this->_params['iframe'], $title, 'header') . $title . '</a>';
        $html .= Horde::link($this->_params['iframe'], _("Open in a new window"), 'smallheader', '_new') . Horde::img('webserver.gif', _("Open in a new window"), 'hspace="5"', Horde::url($registry->getParam('graphics'), true, -1)) . _("Open in a new window") . '</a>';

        return $html;
    }

    /**
     * The content to go in this block.
     *
     * @return string   The content
     */
    function _content()
    {
        global $browser;

        if (!$browser->hasFeature('iframes')) {
            $html = _("Your browser does not support this feature.");
        } else {
            if ($browser->isBrowser('msie') || $browser->isBrowser('konqueror')) {
                $height = '';
            } else {
                $height = ' height="100%"';
            }
            $html = '<iframe src="' . htmlspecialchars($this->_params['iframe']) . '" width="100%"' . $height . ' marginheight="0" scrolling="yes" frameborder="0"></iframe>';
        }
        return $html;
    }

}

--- NEW FILE: metar.php ---
<?php
/**
 * The Horde_Block_metar class provides an applet for the portal
 * screen to display METAR weather data for a specified location
 * (currently airports).
 *
 * $Horde: horde/lib/Block/metar.php,v 1.17 2004/05/29 16:21:03 jan Exp $
 *
 * @package Horde_Block
 */
class Horde_Block_metar extends Horde_Block {

    var $_app = 'horde';

    /**
     * The title to go in this block.
     *
     * @return string   The title text.
     */
    function _title()
    {
        return _("Current Weather");
    }

    function getParams()
    {
        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 array(
                'error' => array(
                    'type' => 'error',
                    'name' => _("Error"),
                    'default' => _("Metar block not available.")
                )
            );
        } else {
            global $conf;

            // Get locations from the database.
            require_once 'DB.php';
            $db = &DB::connect($conf['sql']);
            if (is_a($db, 'PEAR_Error')) {
                return $db;
            }

            $result = $db->query('SELECT icao, name, country FROM metarAirports ORDER BY country');
            if (is_a($result, 'PEAR_Error')) {
                return $result;
            }

            $locations = array();
            while ($row = $result->fetchRow(DB_FETCHMODE_ASSOC)) {
                $locations[$row['country']][$row['icao']] = $row['name'];
            }

            return array(
                'location' => array(
                    'type' => 'mlenum',
                    'name' => _("Location"),
                    'default' => 'KSFB',
                    'values' => $locations,
                ),
                'units' => array(
                    'type' => 'enum',
                    'name' => _("Units"),
                    'default' => 's',
                    'values' => array(
                        's' => _("Standard"),
                        'm' => _("Metric")
                    )
                ),
                'knots' => array(
                    'type' => 'checkbox',
                    'name' => _("Wind speed in knots"),
                    'default' => 0
                )
            );
        }
    }

    function _row($label, $content)
    {
        return '<br /><b>' . $label . ':</b> ' . $content;
    }

    /**
     * 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;
    }

}

--- NEW FILE: moon.php ---
<?php
/**
 * $Horde: horde/lib/Block/moon.php,v 1.11 2004/05/29 16:21:03 jan Exp $
 *
 * @package Horde_Block
 */
class Horde_Block_moon extends Horde_Block {

    var $_app = 'horde';

    function _title()
    {
        return _("Moon Phases");
    }

    function getParams()
    {
        return $params = array(
                             'phase' => array(
                                 'name' => _("Which phases"),
                                 'type' => 'enum',
                                 'default' => 'current',
                                 'values' => array('current' => _("Current Phase"),
                                                   'next' => _("Next Phase"))),
                             'hemisphere' => array(
                                 'name' => _("Hemisphere"),
                                 'type' => 'enum',
                                 'default' => 'northern',
                                 'values' => array('northern' => _("Northern Hemisphere"),
                                                   'southern' => _("Southern Hemisphere"))),
                             );
    }

    function _content()
    {
        $phases = $this->_calculateMoonPhases(date('Y'));
        $now = time();

        $lastNew = 0;
        $lastNewStamp = 0;
        $offset = 0;
        foreach ($phases as $key => $val) {
            if ($key < $now && $key > $lastNewStamp && $val == _("New Moon")) {
                $lastNew = $offset;
                $lastNewStamp = $key;
            }
            $offset++;
        }

        if (isset($this->_params['phase']) && $this->_params['phase'] == 'next') {
            $dates = array_slice(array_keys($phases), $lastNew + 4, 4);
        } else {
            $dates = array_slice(array_keys($phases), $lastNew, 4);
        }

        if (isset($this->_params['hemisphere']) && $this->_params['hemisphere'] == 'northern') {
            $location = _("Northern Hemisphere");
        } else {
            $location = _("Southern Hemisphere");
        }

        $html  = '<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">';
        $html .= '<tr><td colspan="4" class="control"><b>' . $location . '</b></td></tr>';
        $html .= '<tr height="100%"><td width="25%" align="center">';
        $html .= Horde::img('block/moon/newmoon.gif', _("New Moon"));
        $html .= '<br/>' . strftime('%d %b', $dates[0]);
        $html .= '</td>';

        $html .= '<td width="25%" align="center">';
        if (isset($this->_params['hemisphere']) && $this->_params['hemisphere'] == 'northern') {
            $html .= Horde::img('block/moon/lastquarter.gif', _("First Quarter"));
        } else {
            $html .= Horde::img('block/moon/firstquarter.gif', _("First Quarter"));
        }
        $html .= '<br/>' . strftime('%d %b', $dates[1]);
        $html .= '</td>';

        $html .= '<td width="25%" align="center">';
        $html .= Horde::img('block/moon/fullmoon.gif', _("Full Moon"));
        $html .= '<br/>' . strftime('%d %b', $dates[2]);
        $html .= '</td>';

        $html .= '<td width="25%" align="center">';
        if (isset($this->_params['hemisphere']) && $this->_params['hemisphere'] == 'northern') {
            $html .= Horde::img('block/moon/firstquarter.gif', _("Last Quarter"));
        } else {
            $html .= Horde::img('block/moon/lastquarter.gif', _("Last Quarter"));
        }
        $html .= '<br/>' . strftime('%d %b', $dates[3]);
        $html .= '</td>';

        $html .= "</tr></table>";

        return $html;
    }

    /**
     * Returns an array with all the phases of the moon for a whole
     * year.
     *
     * Based on code from
     * http://www.zend.com/codex.php?id=830&single=1 by Are Pedersen.
     *
     * Converted from Basic by Roger W. Sinnot, Sky & Telescope, March 1985.
     * Converted from javascript by Are Pedersen 2002
     * Javascript found at http://www.stellafane.com/moon_phase/moon_phase.htm
     *
     * @param integer   $year   The four digit year to return the moon
     *                          phases for.
     *
     * @return array    The moon phases.
     */
    function _calculateMoonPhases($Y)
    {
        $R1 = 3.14159265 / 180;
        $U  = false;
        $K0 = intval(($Y - 1900) * 12.3685);
        $T  = ($Y - 1899.5) / 100;
        $T2 = $T * $T;
        $T3 = $T * $T * $T;
        $J0 = 2415020 + 29 * $K0;
        $F0 = 0.0001178 * $T2 - 0.000000155 * $T3;
        $F0 += (0.75933 + 0.53058868*$K0);
        $F0 -= (0.000837 * $T + 0.000335 * $T2);
        $M0  = $K0 * 0.08084821133;
        $M0  = 360 * ($M0 - intval($M0)) + 359.2242;
        $M0 -= 0.0000333 * $T2;
        $M0 -= 0.00000347 * $T3;
        $M1  = $K0 * 0.07171366128;
        $M1  = 360 * ($M1 - intval($M1)) + 306.0253;
        $M1 += 0.0107306 * $T2;
        $M1 += 0.00001236 * $T3;
        $B1  = $K0 * 0.08519585128;
        $B1  = 360 * ($B1 - intval($B1)) + 21.2964;
        $B1 -= 0.0016528 * $T2;
        $B1 -= 0.00000239 * $T3;
        for ($K9 = 0; $K9 <= 28; $K9 = $K9 + 0.5) {
            $J = $J0 + 14 * $K9;
            $F = $F0 + 0.765294 * $K9;
            $K = $K9 / 2;
            $M5 = ($M0 + $K * 29.10535608) * $R1;
            $M6 = ($M1 + $K * 385.81691806) * $R1;
            $B6 = ($B1 + $K * 390.67050646) * $R1;
            $F -= 0.4068 * sin($M6);
            $F += (0.1734 - 0.000393 * $T) * sin($M5);
            $F += 0.0161 * sin(2 * $M6);
            $F += 0.0104 * sin(2 * $B6);
            $F -= 0.0074 * sin($M5 - $M6);
            $F -= 0.0051 * sin($M5 + $M6);
            $F += 0.0021 * sin(2 * $M5);
            $F += 0.0010 * sin(2 * $B6 - $M6);

            /* Add 1/2 minute for proper rounding to minutes per Sky &
             * Tel article. */
            $F += 0.5 / 1440;
            $J += intval($F);
            $F -= intval($F);

            /* Convert from JD to Calendar Date. */
            $julian = $J + round($F);
            $parts  = explode('/', $this->_jdtogregorian($julian));
            $stamp  = gmmktime(0, 0, 0, $parts[0], $parts[1], $parts[2]);

            /* half K. */
            if (($K9 - floor($K9)) > 0) {
                if ($U) {
                    /* New half. */
                    $phases[$stamp] = _("First Half");
                } else {
                    /* Full half. */
                    $phases[$stamp] = _("Last Half");
                }
            } else {
                /* full K. */
                if (!$U) {
                    $phases[$stamp] = _("New Moon");
                } else {
                    $phases[$stamp] = _("Full Moon");
                }
                $U = !$U;
            }
        }

        return $phases;
    }

    /**
     * Checks if the jdtogregorian function exists, and if not
     * calculates the gregorian date manually.
     *
     * @param int $julian The julian date
     *
     * @access public
     * @return string m/d/Y
     */
    function _jdtogregorian($julian)
    {
        if (function_exists('jdtogregorian')) {
            return jdtogregorian($julian);
        } else {
            // From http://php.net/manual/en/function.jdtogregorian.php
            $julian = $julian - 1721119;
            $calc1 = 4 * $julian - 1;
            $year = floor($calc1 / 146097);
            $julian = floor($calc1 - 146097 * $year);
            $day = floor($julian / 4);
            $calc2 = 4 * $day + 3;
            $julian = floor($calc2 / 1461);
            $day = $calc2 - 1461 * $julian;
            $day = floor(($day + 4) / 4);
            $calc3 = 5 * $day - 3;
            $month = floor($calc3 / 153);
            $day = $calc3 - 153 * $month;
            $day = floor(($day + 5) / 5);
            $year = 100 * $year + $julian;

            if ($month < 10) {
                $month = $month + 3;
            } else {
                $month = $month - 9;
                $year = $year + 1;
            }
            return "$day/$month/$year";
        }
    }

}

--- NEW FILE: sunrise.php ---
<?php
/**
 * $Horde: horde/lib/Block/sunrise.php,v 1.10 2004/05/29 16:21:03 jan Exp $
 *
 * @package Horde_Block
 */
class Horde_Block_sunrise extends Horde_Block {

    var $_app = 'horde';

    function _title()
    {
        return _("Sunrise/Sunset");
    }

    function getParams()
    {
        $params = array('location' => array('type' => 'mlenum',
                                            'name' => _("Location"),
                                            'default' => '51.517:-0.117'));

        global $coordinates;
        if (!is_array($coordinates)) {
            @include 'Horde/NLS/coordinates.php';
            if (!is_array($coordinates)) {
                $coordinates = array();
            }
        }
        $params['location']['values'] = $coordinates;

        return $params;
    }

    function _content()
    {
        if (empty($this->_params['location'])) {
            return _("No location is set.");
        }

        // Set the timezone variable, if available.
        NLS::setTimeZone();

        list($lat, $long) = explode(':', $this->_params['location']);
        $rise = $this->_calculateSunset(time(), $lat, $long, false, floor(date('Z') / 3600));
        $set = $this->_calculateSunset(time(), $lat, $long, true, floor(date('Z') / 3600));

        $location = '';
        global $coordinates;
        if (!is_array($coordinates)) {
            require 'Horde/NLS/coordinates.php';
        }
        foreach ($coordinates as $country) {
            if (array_key_exists($this->_params['location'], $country)) {
                $location = $country[$this->_params['location']];
                break;
            }
        }

        $html  = '<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0"><tr>';
        $html .= '<td colspan="2" class="control"><b>' . $location . '</b></td></tr><tr height="100%">';

        $html .= '<td width="50%" align="center">';
        $html .= Horde::img('block/sunrise/sunrise.gif', _("Sun Rise"));
        $html .= '<br/>' . $rise;
        $html .= '</td>';

        $html .= '<td width="50%" align="center">';
        $html .= Horde::img('block/sunrise/sunset.gif', _("Sun Set"));
        $html .= '<br/>' . $set;
        $html .= '</td>';

        $html .= '</tr></table>';

        return $html;
    }

    /**
     * http://www.zend.com/codex.php?id=135&single=1
     */
    function _calculateSunset($date, $latitude, $longitude, $sunset = true, $timezone)
    {
        $yday = date('z', $date);
        $mon = date('n', $date);
        $mday = date('j', $date);
        $year = date('Y', $date);

        $DST = date('I', $date);
        // if ($DST == '1') {
        //     $timezone = ($timezone + 1);
        // }

        if ($timezone == '13') {
            $timezone = '-11';
            $mday++;
            $yday++;
        }

        $A = 1.5708;
        $B = 3.14159;
        $C = 4.71239;
        $D = 6.28319;
        $E = 0.0174533 * $latitude;
        $F = 0.0174533 * $longitude;
        $G = 0.261799  * $timezone;

        // For astronomical twilight, use R = -.309017
        // For nautical twilight, use R = -.207912
        // For civil twilight, use R = -.104528
        // For sunrise or sunset, use R = -.0145439
        $R = -.0145439;

        if ($sunset) {
            $J = $C;
        } else {
            $J = $A;
        }

        $K = $yday + (($J - $F) / $D);
        $L = ($K * .017202) - .0574039;              // Solar Mean Anomoly
        $M = $L + .0334405 * sin($L);                // Solar True Longitude
        $M += 4.93289 + (3.49066E-04) * sin(2 * $L); // Quadrant Determination
        while ($M < 0) {
            $M = ($M + $D);
        }
        while ($M >= $D) {
            $M = ($M - $D);
        }

        if (($M / $A) - intval($M / $A) == 0) {
            $M += 4.84814E-06;
        }

        $P = sin($M) / cos($M);                   // Solar Right Ascension
        $P = atan2(.91746 * $P, 1);

        // Quadrant Adjustment
        if ($M > $C) {
            $P += $D;
        } elseif ($M > $A) {
            $P += $B;
        }

        $Q = .39782 * sin($M);            // Solar Declination
        $Q = $Q / sqrt(-$Q * $Q + 1);     // This is how the original author wrote it!
        $Q = atan2($Q, 1);

        $S = $R - (sin($Q) * sin($E));
        $S = $S / (cos($Q) * cos($E));

        if (abs($S) > 1) {
            echo 'none';                // Null phenomenon
        }

        $S = $S / sqrt(-$S * $S + 1);
        $S = $A - atan2($S, 1);

        if (!$sunset) {
            $S = $D - $S ;
        }

        $T = $S + $P - 0.0172028 * $K - 1.73364; // Local apparent time
        $U = $T - $F;                            // Universal timer
        $V = $U + $G;                            // Wall clock time

        // Quadrant Determination
        while ($V < 0) {
            $V = ($V + $D);
        }
        while ($V >= $D) {
            $V = ($V - $D);
        }
        $V = $V * 3.81972;

        $hour = intval($V);
        $V   -= $hour;
        $min  = intval($V * 60);
        $V   -= $min / 60;
        $sec  = intval($V * 3600);

        return strftime('%X', mktime($hour, $min, $sec, $mon, $mday, $year));
    }

}

--- NEW FILE: time.php ---
<?php
/**
 * $Horde: horde/lib/Block/time.php,v 1.11 2004/05/29 16:21:03 jan Exp $
 *
 * @package Horde_Block
 */
class Horde_Block_time extends Horde_Block {

    var $_app = 'horde';

    function getParams()
    {
        return $params = array('time' => array('type' => 'enum',
                                               'name' => _("Time format"),
                                               'default' => '24-hour',
                                               'values' => array('24-hour' => '24 Hour Format',
                                                                 '12-hour' => '12 Hour Format')));
    }

    /**
     * The title to go in this block.
     *
     * @return string   The title text.
     */
    function _title()
    {
        return _("Current Time");
    }

    /**
     * The content to go in this block.
     *
     * @return string   The content
     */
    function _content()
    {
        if (empty($this->_params['time'])) {
            $this->_params['time'] = '24-hour';
        }

        // Set the timezone variable, if available.
        NLS::setTimeZone();

        $html = '<table width="100%" height="100%"><tr><td style="font-family:verdana;font-size:18px;" align="center" valign="center">';
        $html .= strftime('%A, %B %d, %Y ');
        if ($this->_params['time'] == '24-hour') {
            $html .= strftime('%H:%M');
        } else {
            $html .= strftime('%I:%M %p');
        }
        $html .= '</td></tr></table>';

        return $html;
    }

}

--- NEW FILE: weatherdotcom.php ---
<?php
/**
 * The Horde_Block_weatherdotcom class provides an applet for the portal screen
 * to display weather and forecast data from weather.com for a specified
 * location.
 *
 * $Horde: horde/lib/Block/weatherdotcom.php,v 1.16 2004/05/29 16:21:03 jan Exp $
 *
 * @package Horde_Block
 */
class Horde_Block_weatherdotcom extends Horde_Block {

    var $_app = 'horde';

    /**
     * The title to go in this block.
     *
     * @return string   The title text.
     */
    function _title()
    {
        return _("Weather Forecast");
    }

    /**
     * The parameters to go with this block.
     *
     * @return array  An array containing the parameters.
     */
    function getParams()
    {
        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);
            $params = array(
                'error' => array(
                    'type' => 'error',
                    'name' => _("Error"),
                    'default' => _("The weather.com block is not available.")
                )
            );
        } else {
            $params = array(
                'location' => array(
                    // 'type' => 'weatherdotcom',
                    'type' => 'text',
                    'name' => _("Location"),
                    'default' => 'Boston, MA'
                ),
                'units' => array(
                    'type' => 'enum',
                    'name' => _("Units"),
                    'default' => 's',
                    'values' => array(
                        'standard' => _("Standard"),
                        'metric' => _("Metric")
                    )
                ),
                'days' => array(
                    'type' => 'enum',
                    'name' => _("Forecast Days (note that the returned forecast returns both day and night; a large number here could result in a wide block)"),
                    'default' => '3',
                    'values' => array(
                        '1' => '1',
                        '2' => '2',
                        '3' => '3',
                        '4' => '4',
                        '5' => '5',
                        '6' => '6',
                        '7' => '7',
                        '8' => '8'
                    )
                ),
            );
        }

        return $params;
    }

    /**
     * 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 cellspacing="0" 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 .= round($weather['temperature']) . '°' . String::upper($units['temp']);

        // Dew point.
        $html .= ' <b>' . _("Dew point: ") . '</b>';
        $html .= round($weather['dewPoint']) . '°' . String::upper($units['temp']);

        // Feels like temperature.
        $html .= ' <b>' . _("Feels like: ") . '</b>';
        $html .= round($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 cellspacing="0" width="100%"><tr>';
        $html .= '<tr><td class="control" colspan="'
            . $this->_params['days'] * 2
            . '"><center><b>' . sprintf(_("%d-day forecast"), $this->_params['days'])
            . '</b></center></td></tr><tr>';
        $futureDays = 0;
        $item = 0;
        foreach ($forecast['days'] as $which => $day) {
            $item++;
            $html .= '<td colspan="2" align="center" class="item' . ($item % 2) . '">';

            // 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">' . round($day['temperatureHigh']) .
                    '°' . String::upper($units['temp']) . '</span>/';
            }
            $html .= '<span style="color:blue">' . round($day['temperatureLow']) .
                '°' . String::upper($units['temp']) . '</span>';
            $html .= '</td>';
        }
        $html .= '</tr><tr>';

        $elementWidth = 100 / ($this->_params['days'] * 2);

        $item = 0;
        foreach ($forecast['days'] as $which => $day) {
            $item++;
            // Day forecast.
            $html .= '<td align="center" valign="top" width="'
                . $elementWidth . '%" class="item' . ($item % 2) . '">';
            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 . '%" class="item' . ($item % 2) . '">';

            $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 cellspacing="0" 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;
    }

}





More information about the commits mailing list