Index: webcams.module
===================================================================
RCS file: /cvs/drupal/contributions/modules/webcams/webcams.module,v
retrieving revision 1.2
diff -u -r1.2 webcams.module
--- webcams.module	1 Mar 2007 18:39:10 -0000	1.2
+++ webcams.module	20 Jul 2007 08:00:20 -0000
@@ -219,6 +219,55 @@
 }
 
 /**
+ * Implementation of hook_validate().
+ */
+function webcams_validate($node) {
+  for ($i = 0; $i < count($node->webcams); $i++) {
+    if ($url = $node->webcams[$i][url]){
+      //Open a curl resource to fetch the header. 
+      $ch = curl_init();
+      curl_setopt($ch, CURLOPT_URL, $url);
+      curl_setopt($ch, CURLOPT_HEADER, true);
+      curl_setopt($ch, CURLOPT_NOBODY, true);
+      curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
+      curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 3);//3 sec should be enough to get the header
+      $data = curl_exec($ch);
+      $getinfo = curl_getinfo($ch);
+      curl_close($ch);
+      //Checking url
+      if (!$data) {
+        drupal_set_message("error");
+        form_set_error("webcams][$i][url", t("Domain not found. Webcam " . ($i+1)));        
+      } elseif ($getinfo[http_code] != 200 ) {
+        form_set_error("webcams][$i][url", t("Page not found. Webcam " . ($i+1)));  
+      //} elseif ($getinfo[content_type] != 'image/jpeg'){  //We can do this in the future
+      //  form_set_error("webcams][$i][url", t("We currently only support jpeg sources. Webcam " . ($i+1))); 
+      } elseif ($getinfo[download_content_length] > 100000) {
+        form_set_error("webcams][$i][url", t("Source image too big. Webcam " . ($i+1)));
+      } else {
+        //Open a curl resource to fetch the image.
+        $ch = curl_init();
+        curl_setopt($ch, CURLOPT_URL, $url);
+        curl_setopt($ch, CURLOPT_HEADER, false);
+        curl_setopt($ch, CURLOPT_NOBODY, false);
+        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
+        curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 5);//5 sec should be enough to get the image
+        $data = curl_exec($ch);
+        curl_close($ch);
+        //Checking and setting image dimensions        
+        $img = imagecreatefromstring($data);
+        drupal_set_message("imagesize " . imagesx($img));
+        dprint_r($node->webcams);
+        $node->webcams[$i]['width'] = imagesx($img); //Does not work. I think we need to use set_form_values or something
+        drupal_set_message("imagesize " . imagesy($img));
+        $node->webcams[$i]['height'] = imagesy($img); //Does not work. 
+        imagedestroy($img);
+      }
+    }
+  }   
+} 
+
+/**
  * Implementation of hook_insert().
  */
 function webcams_insert(&$node) {
