[dev] Weather block; need advice/help

Rick Emery rick at emery.homelinux.net
Fri Jan 16 11:09:42 PST 2004


Quoting Chuck Hagenbuch <chuck at horde.org>:

> Quoting Rick Emery <rick at emery.homelinux.net>:
>
> > I *really* hate bothering you guys, and I know I'm missing something
> basic.
>
> It's really not a problem, but I think at this point we need to see the
> code. :)
>
> -chuck
>
> --
> Charles Hagenbuch, <chuck at horde.org>
> "Here, I brought some cole slaw. It's made from peeeooople! Just kidding."

OK, here's what I have. For the block to be fully functional, there are a bunch
of graphics that are needed. I've zipped them up, but the file is still 192k,
and I didn't want to pollute the list. Let me know if you want them (private
email, maybe?).

Note that as it currently stands, you can't enter a location; so it will
default to Sanford, FL (until we can figure this out).

Thanks in advance!
Rick

--
Rick Emery

"When once you have tasted flight, you will forever walk the Earth
 with your eyes turned skyward, for there you have been, and there
 you will always long to return"
                                              -- Leonardo Da Vinci
-------------- next part --------------
Index: Form.php
===================================================================
RCS file: /repository/horde/lib/Attic/Form.php,v
retrieving revision 1.213
diff -u -r1.213 Form.php
--- Form.php	11 Jan 2004 16:48:37 -0000	1.213
+++ Form.php	16 Jan 2004 18:50:19 -0000
@@ -896,6 +896,91 @@
 
 }
 
+class Horde_Form_Type_weather extends Horde_Form_Type {
+
+    var $_regex;
+    var $_size;
+    var $_maxlength;
+
+    /**
+     * The initialisation function for the text variable type.
+     *
+     * @access private
+     *
+     * @param optional string $regex   Any valid PHP PCRE pattern syntax that
+     *                                 needs to be matched for the field to be
+     *                                 considered valid. If left empty validity
+     *                                 will be checked only for required fields
+     *                                 whether they are empty or not.
+     *                                 If using this regex test it is advisable
+     *                                 to enter a description for this field to
+     *                                 warn the user what is expected, as the
+     *                                 generated error message is quite generic
+     *                                 and will not give any indication where
+     *                                 the regex failed.
+     * @param optional int $size       The size of the input field.
+     * @param optional int $maxlength  The max number of characters.
+     */
+    function init($regex = '', $size = 40, $maxlength = null)
+    {
+        $this->_regex     = $regex;
+        $this->_size      = $size;
+        $this->_maxlength = $maxlength;
+    }
+
+    function isValid(&$var, &$vars, $value, &$message)
+    {
+        require_once "Services/Weather.php";
+        $weatherDotCom = &Services_Weather::service("WeatherDotCom");
+        $weatherDotCom->setAccountData("<PartnerID>", "<LicenseKey>");
+        $search = $weatherDotCom->searchLocation($value);
+
+        if (is_array($search)) {
+            $message = "Valid locations found include: ";
+            foreach ($search as $loc) {
+                $message = $message . $loc;
+            }
+            return false;
+            } elseif (is_a($search, 'PEAR_Error') {
+                $message = PEAR::raiseError(_('PEAR Error'));
+                return false;
+            } else {
+                return true;
+            }
+        }
+    }
+
+
+    function getSize()
+    {
+        return $this->_size;
+    }
+
+    function getMaxLength()
+    {
+        return $this->_maxlength;
+    }
+
+    /**
+     * Return info about field type.
+     */
+    function about()
+    {
+        $about = array();
+        $about['name'] = _("Text");
+        $about['params'] = array(
+            'regex'     => array('label' => _("Regex"),
+                                 'type'  => 'text'),
+            'size'      => array('label' => _("Size"),
+                                 'type'  => 'int'),
+            'maxlength' => array('label' => _("Maximum length"),
+                                 'type'  => 'int'),
+        );
+        return $about;
+    }
+
+}
+
 class Horde_Form_Type_header extends Horde_Form_Type {
 
     function isValid(&$var, &$vars, $value, &$message)
@@ -963,7 +1048,6 @@
         } elseif (empty($value)) {
             return true;
         }
-
         /* If matched this is a correct numeric value. */
         if (preg_match($this->_getValidationPattern(), $value)) {
             return true;
-------------- next part --------------
Index: Renderer.php
===================================================================
RCS file: /repository/horde/lib/Form/Attic/Renderer.php,v
retrieving revision 1.146
diff -u -r1.146 Renderer.php
--- Renderer.php	7 Jan 2004 15:29:08 -0000	1.146
+++ Renderer.php	16 Jan 2004 18:43:41 -0000
@@ -213,6 +213,10 @@
                     $this->_renderSpacer();
                     break;
 
+                case 'weather':
+                    $this->_renderWeather();
+                    break;
+
                 default:
                     $isInput = ($active && !$var->isReadonly());
                     $format = $isInput ? 'Input' : 'Display';
@@ -294,6 +298,11 @@
     {
 ?><tr><td colspan="<?php echo $this->_cols; ?>">&nbsp;</td></tr>
 <?php
+    }
+
+    function _renderWeather()
+    {
+?><tr><td><input type="text" size="20"></td></tr><?php
     }
 
     function _renderSubmit($submit, $reset)
-------------- next part --------------
Index: registry.php.dist
===================================================================
RCS file: /repository/horde/config/registry.php.dist,v
retrieving revision 1.199
diff -u -r1.199 registry.php.dist
--- registry.php.dist	7 Jan 2004 14:31:24 -0000	1.199
+++ registry.php.dist	16 Jan 2004 18:56:46 -0000
@@ -637,3 +637,7 @@
 $this->applets['metar'] = array(
     'name' => _("Metar Weather"),
 );
+
+$this->applets['weatherdotcom'] = array(
+    'name' => _("weather.com"),
+);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: weatherdotcom.php
Type: application/x-httpd-php
Size: 8252 bytes
Desc: not available
Url : http://lists.horde.org/archives/dev/attachments/20040116/af1c1fa4/weatherdotcom.bin


More information about the dev mailing list