Exemple #1
0
 protected function detectCase($msg)
 {
     if ($msg == String::lower($msg)) {
         return 'lower';
     }
     if ($msg == String::upper($msg)) {
         return 'upper';
     }
     if ($msg == String::capitalize($msg)) {
         return 'capitalize';
     }
     return 'default';
 }
Exemple #2
0
    $help_file = $fileroot . "/admin/locale/{$language}/help.xml";
    $help_file_fallback = $fileroot . '/admin/locale/en_US/help.xml';
} else {
    $fileroot = $registry->getParam('fileroot', $module);
    $help_file = $fileroot . "/locale/{$language}/help.xml";
    $help_file_fallback = $fileroot . '/locale/en_US/help.xml';
}
if ($show == 'index') {
    require HORDE_TEMPLATES . '/help/index.inc';
} else {
    require HORDE_TEMPLATES . '/common-header.inc';
    if ($show == 'menu') {
        require HORDE_TEMPLATES . '/help/menu.inc';
    } elseif ($show == 'about') {
        require $fileroot . '/lib/version.php';
        eval('$version = "' . ucfirst($module) . ' " . ' . String::upper($module) . '_VERSION;');
        $credits = Util::bufferOutput('include', $fileroot . '/docs/CREDITS');
        $credits = String::convertCharset($credits, 'iso-8859-1', NLS::getCharset());
        require HORDE_TEMPLATES . '/help/about.inc';
    } else {
        require HORDE_TEMPLATES . '/help/header.inc';
        $help = new Help(HELP_SOURCE_FILE, array($help_file, $help_file_fallback));
        if ($show == 'entry' && !empty($topic)) {
            $help->lookup($topic);
            $help->display();
        } else {
            $topics = $help->topics();
            foreach ($topics as $id => $title) {
                $link = Horde::url($registry->getParam('webroot', 'horde') . '/services/help/');
                $link = Util::addParameter($link, array('show' => 'entry', 'module' => $module, 'topic' => $id));
                echo Horde::link($link, '', 'helpitem');
Exemple #3
0
 /**
  * Set the value of an attribute.
  *
  * @param string $name
  *        	The name of the attribute.
  * @param string $value
  *        	The value of the attribute.
  * @param array $params
  *        	Array containing any addition parameters for
  *        	this attribute.
  * @param boolean $append
  *        	True to append the attribute, False to replace
  *        	the first matching attribute found.
  * @param array $values
  *        	Array representation of $value. For
  *        	comma/semicolon seperated lists of values. If
  *        	not set use $value as single array element.
  */
 function setAttribute($name, $value, $params = array(), $append = true, $values = false)
 {
     // Make sure we update the internal format version if
     // setAttribute('VERSION', ...) is called.
     if ($name == 'VERSION') {
         $this->_version = $value;
         if ($this->_container !== false) {
             $this->_container->_version = $value;
         }
     }
     if (!$values) {
         $values = array($value);
     }
     $found = false;
     if (!$append) {
         $keys = array_keys($this->_attributes);
         foreach ($keys as $key) {
             if ($this->_attributes[$key]['name'] == String::upper($name)) {
                 $this->_attributes[$key]['params'] = $params;
                 $this->_attributes[$key]['value'] = $value;
                 $this->_attributes[$key]['values'] = $values;
                 $found = true;
                 break;
             }
         }
     }
     if ($append || !$found) {
         $this->_attributes[] = array('name' => strtoupper($name), 'params' => $params, 'value' => $value, 'values' => $values);
     }
 }
Exemple #4
0
 /**
  * Sort the array on its keys
  *
  * @param Array $array  The haystack
  * @param string $way   ASC or DESC
  *
  * @return Array  	the result array
  */
 public static function sort($array, $way = 'ASC')
 {
     $way = String::upper($way);
     asort($array);
     if ($way == 'DESC') {
         $array = static::reverse($array);
     }
     return $array;
 }
Exemple #5
0
 /**
  * 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']) . '&deg;' . String::upper($units['temp']));
     }
     if (isset($weather['dewPoint'])) {
         $html .= $this->_row(_("Dew Point"), round($weather['dewPoint']) . '&deg;' . String::upper($units['temp']));
     }
     if (isset($weather['feltTemperature'])) {
         $html .= $this->_row(_("Feels Like"), round($weather['feltTemperature']) . '&deg;' . 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) . '&deg;' . String::upper($units['temp']);
                     break;
                 case '1hdew':
                     $remarks .= '<br />' . _("Dew Point for last hour: ") . round($value) . '&deg;' . String::upper($units['temp']);
                     break;
                 case '6hmaxtemp':
                     $remarks .= '<br />' . _("Max temp last 6 hours: ") . round($value) . '&deg;' . String::upper($units['temp']);
                     break;
                 case '6hmintemp':
                     $remarks .= '<br />' . _("Min temp last 6 hours: ") . round($value) . '&deg;' . String::upper($units['temp']);
                     break;
                 case '24hmaxtemp':
                     $remarks .= '<br />' . _("Max temp last 24 hours: ") . round($value) . '&deg;' . String::upper($units['temp']);
                     break;
                 case '24hmintemp':
                     $remarks .= '<br />' . _("Min temp last 24 hours: ") . round($value) . '&deg;' . 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;
 }
Exemple #6
0
 public function __toString()
 {
     $label = $this->getText('title', $this->filename);
     if (($pos = strrpos($this->filename, '.')) && $pos !== false) {
         $label = substr($label, 0, $pos) . ' (' . String::upper(substr($this->filename, $pos + 1)) . ')';
     }
     return $label;
 }
Exemple #7
0
function init()
{
    global $cmd_options, $apps, $dirs, $debug, $test, $c, $silence;
    foreach ($cmd_options[0] as $option) {
        switch ($option[0]) {
            case 'h':
                usage();
                footer();
            case 'l':
            case '--locale':
                $lang = $option[1];
                break;
            case 'm':
            case '--module':
                $module = $option[1];
                break;
        }
    }
    if (empty($lang)) {
        $lang = getenv('LANG');
    }
    for ($i = 0; $i < count($dirs); $i++) {
        if (!empty($module) && $module != $apps[$i]) {
            continue;
        }
        $package = ucfirst($apps[$i]);
        $package_u = String::upper($apps[$i]);
        @(include $dirs[$i] . '/lib/version.php');
        $version = eval('return(defined("' . $package_u . '_VERSION") ? ' . $package_u . '_VERSION : "???");');
        echo sprintf(_("Initializing module %s... "), $apps[$i]);
        if (!@file_exists($dirs[$i] . '/po/' . $apps[$i] . '.pot')) {
            $c->writeln($c->red(_("failed")));
            $c->writeln(sprintf(_("%s not found. Run 'translation extract' first."), $dirs[$i] . DS . 'po' . DS . $apps[$i] . '.pot'));
            continue;
        }
        $dir = $dirs[$i] . DS . 'po' . DS;
        $sh = $GLOBALS['msginit'] . ' --no-translator -i ' . $dir . $apps[$i] . '.pot ' . (!empty($lang) ? ' -o ' . $dir . $lang . '.po --locale=' . $lang : '') . ($debug ? '' : $silence);
        if (!empty($lang) && !OS_WINDOWS) {
            $pofile = $dirs[$i] . '/po/' . $lang . '.po';
            $sh .= "; sed 's/PACKAGE package/{$package} package/' {$pofile} " . "| sed 's/PACKAGE VERSION/{$package} {$version}/' " . "| sed 's/messages for PACKAGE/messages for {$package}/' " . "| sed 's/Language-Team: none/Language-Team: i18n@lists.horde.org/' " . "> {$pofile}.tmp";
        }
        if ($debug || $test) {
            $c->writeln(_("Executing:"));
            $c->writeln($sh);
        }
        if ($test) {
            $ret = 0;
        } else {
            exec($sh, $out, $ret);
        }
        rename($pofile . '.tmp', $pofile);
        if ($ret == 0) {
            $c->writeln($c->green(_("done")));
        } else {
            $c->writeln($c->red(_("failed")));
        }
    }
}
Exemple #8
0
 /**
  * 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'] . '&deg;' . String::upper($units['temp']);
     // Dew point.
     $html .= ' <b>' . _("Dew point: ") . '</b>';
     $html .= $weather['dewPoint'] . '&deg;' . String::upper($units['temp']);
     // Feels like temperature.
     $html .= ' <b>' . _("Feels like: ") . '</b>';
     $html .= $weather['feltTemperature'] . '&deg;' . 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'] . '&deg;' . String::upper($units['temp']) . '</span>/';
         }
         $html .= '<span style="color:blue">' . $day['temperatureLow'] . '&deg;' . 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 .= '&nbsp;';
         }
         $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>&reg; ';
     $html .= Horde::img('block/weatherdotcom/32x32/TWClogo_32px.png', 'weather.com logo');
     $html .= '</a></td></tr></table>';
     return $html;
 }
<?php

if (empty($MediaFile)) {
    return false;
}
?>
<div class="thumb">
	<?php 
if ($MediaFile->file()) {
    if ($MediaFile instanceof MediaImage) {
        $icon = $HTML->image($MediaFile->src(coalesce(@$width, 160), coalesce(@$height, 120), coalesce(@$method, 'resize')));
    } else {
        $extension = $MediaFile->file()->extension();
        $icon = $HTML->tag('span', String::upper($extension), array('class' => array($extension, 'filetype')));
    }
} else {
    $icon = $HTML->tag('span', __('?'), array('class' => 'filetype'));
}
if (!isset($link)) {
    $link = $MediaFile->adminDetailPageUri(array('action' => 'edit'));
}
if (!empty($link)) {
    echo $HTML->link($link, $icon);
} else {
    echo $icon;
}
?>
</div>