--- ad_image-o.module	2008-04-19 03:07:23.000000000 +0530
+++ ad_image.module	2008-05-08 16:03:41.000000000 +0530
@@ -1,11 +1,11 @@
 <?php
-// $Id: ad_image.module,v 1.2.2.13.2.37 2008/04/18 21:37:23 jeremy Exp $
+// $Id: ad_image.module,v 1.2.2.13.2.31 2008/01/11 18:52:09 jeremy Exp $
 
 /**
  * @file
  * Enhances the ad module to support banner ads.
  *
- * Copyright (c) 2005-2008.
+ * Copyright (c) 2005-2007.
  *   Jeremy Andrews <jeremy@kerneltrap.org>.  All rights reserved.
  */
 
@@ -13,15 +13,10 @@
  * Function used to display the selected ad.
  */
 function ad_image_display_ad($ad) {
-  $image = db_fetch_object(db_query('SELECT a.fid, a.url, a.tooltip, a.width, a.height, f.filepath FROM {ad_image} a INNER JOIN {files} f ON a.fid = f.fid WHERE a.aid = %d AND f.nid = %d', $ad->aid, $ad->aid));
+  $image = db_fetch_object(db_query('SELECT a.fid, a.url, a.tooltip, a.width, a.height, f.filepath FROM {ad_image} a INNER JOIN {files} f ON a.fid = f.fid INNER JOIN {upload} u ON f.fid = u.fid WHERE a.aid = %d AND u.nid = %d', $ad->aid, $ad->aid));
   // Strip module path from image path if serving images from adserve.php.
   $image_path = preg_replace('&'. drupal_get_path('module', 'ad') .'/&', '', file_create_url($image->filepath));
-  if ($image->url) {
-    return ("<div class=\"image-advertisement\" id=\"ad-$ad->aid\"><a href=\"$ad->redirect/@HOSTID___\" title=\"". htmlentities($image->tooltip, ENT_QUOTES, 'UTF-8') .'"'. ad_link_attributes() ."><img src=\"$image_path\" width=\"$image->width\" height=\"$image->height\" alt=\"". htmlentities($image->tooltip, ENT_QUOTES, 'UTF-8') ."\" /></a></div>");
-  }
-  else {
-    return ("<div class=\"image-advertisement\" id=\"ad-$ad->aid\"><img src=\"$image_path\" width=\"$image->width\" height=\"$image->height\" alt=\"". htmlentities($image->tooltip, ENT_QUOTES, 'UTF-8') ."\" /></div>");
-  }
+  return ("<div class=\"image-advertisement\" id=\"ad-$ad->aid\"><a href=\"$ad->redirect/@HOSTID___\" title=\"". htmlentities($image->tooltip, ENT_QUOTES) .'"'. ad_link_attributes() ."><img src=\"$image_path\" width=\"$image->width\" height=\"$image->height\" /></a></div>");
 }
 
 /*****/
@@ -53,20 +48,15 @@ function ad_image_help($path) {
 /**
  * Implementation of hook_menu().
  */
-function ad_image_menu($may_cache) {
+function ad_image_menu() {
   $items = array();
-
-  if ($may_cache) {
-    $items[] = array(
-      'path' => 'admin/content/ad/configure/ad_image',
-      'title' => t('Image ads'),
-      'callback' => 'drupal_get_form',
-      'callback arguments' => array('ad_image_group_settings'),
-      'type' => MENU_LOCAL_TASK,
-      'weight' => 3,
-    );
-  }
-
+  $items['admin/content/ad/configure/ad_image'] = array(
+    'title' => t('Image ads'),
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('ad_image_group_settings'),
+    'type' => MENU_LOCAL_TASK,
+    'weight' => 3,
+  );
   return $items;
 }
 
@@ -158,7 +148,7 @@ function ad_image_adapi($op, &$node) {
 
     case 'load':
       $return = db_fetch_array(db_query("SELECT a.*, f.filepath FROM {ad_image} a LEFT JOIN {files} f ON a.fid = f.fid WHERE aid = %d", $node['aid']));
-      $return['ad'] = '<img src="'. file_create_url($return['filepath']) .'" width="'. $return['width'] .'" height="'. $return['height'] .'" alt="'. htmlentities($return['tooltip'], ENT_QUOTES, 'UTF-8') .'" />';
+      $return['ad'] = '<img src="'. file_create_url($return['filepath']) .'" width="'. $return['width'] .'" height="'. $return['height'] .'" />';
       return $return;
 
     case 'insert':
@@ -192,7 +182,7 @@ function ad_image_adapi($op, &$node) {
         }  	         
       }
       if ($op == 'insert') {
-        db_query("INSERT INTO {ad_image} (aid, fid, url, tooltip, width, height) VALUES(%d, %d, '%s', '%s', %d, %d)", $node->nid, $node->fid, $node->url, $node->tooltip, $node->width, $node->height);
+        db_query("INSERT INTO {ad_image} (aid, fid, url, tooltip, width, height) VALUES(%d, %d, '%s', '%s', %d, %d)", $node->nid, $fid, $node->url, $node->tooltip, $node->width, $node->height);
       }
       else {
         db_query("UPDATE {ad_image} SET fid = %d, url = '%s', tooltip = '%s', width = %d, height = %d WHERE aid = %d", $fid, $node->url, $node->tooltip, $node->width, $node->height, $node->nid);
@@ -213,12 +203,9 @@ function ad_image_adapi($op, &$node) {
       break;
 
     case 'validate':
-      if ($node->url && variable_get('ad_validate_url', 1) && (!valid_url($node->url, TRUE))) {
+      if (variable_get('ad_validate_url', 1) && (!valid_url($node->url, TRUE))) {
         form_set_error('url', t('You must specify a valid %field.', array('%field' => t('Destination URL'))));
       }
-      if (!ad_image_active_file($node->files)) {
-        form_set_error('upload', t('It is required that you upload an image for your image advertisement.'));
-      }
       break;
 
     case 'delete':
@@ -266,19 +253,16 @@ function ad_image_adapi($op, &$node) {
  * Determine the currently active ad.
  */
 function ad_image_active_file($files = array()) {
-  if (is_array($files)) {
-    foreach ($files as $fid => $data) {
-      if (is_array($data)) {
-        if ($data['list'] && !$data['remove']) {
-          return $fid;
-        }
-      }
-      else if ($data->list && !$data->remove) {
+  foreach ($files as $fid => $data) {
+    if (is_array($data)) {
+      if ($data['list'] && !$data['remove']) {
         return $fid;
       }
     }
+    else if ($data->list && !$data->remove) {
+      return $fid;
+    }
   }
-  return 0;
 }
 
 function ad_image_format_load($gid) {
@@ -342,6 +326,12 @@ function ad_image_validate_size($file, $
 /**
  *
  */
+function ad_image_update_node(&$data) {
+}
+
+/**
+ *
+ */
 function ad_image_load_image($node) {
   if (is_array($node->files)) {
     foreach ($node->files as $file) {
@@ -395,7 +385,7 @@ function ad_image_node_form(&$node) {
   if ($num) {
     foreach ($files as $file) {
       if ($file->list && file_exists($file->filepath)) {
-        $path .= '<img src="'. file_create_url($file->filepath) .'" alt="'. htmlentities($file->filename, ENT_QUOTES, 'UTF-8') .'" /> ';
+        $path .= '<img src="'. file_create_url($file->filepath) .'" /> ';
         $image = ad_image_validate_size($file, $node->nid);
         if ($image === FALSE) {
           $path .= t('(invalid image)'). '<br />';
@@ -433,9 +423,9 @@ function ad_image_node_form(&$node) {
   $form['ad_image']['url'] = array(
     '#type' => 'textfield',
     '#title' => t('Destination URL'),
-    '#required' => FALSE,
+    '#required' => TRUE,
     '#default_value' => $node->url,
-    '#description' => t('Enter the complete URL if you want people to be redirected when they click on this advertisement.  The URL must begin with http:// or https://.  For example, %url.  If you do not enter a URL, the advertisement will not be clickable.', array('%url' => t('http://www.sample.org/'))),
+    '#description' => t('Enter the complete URL where you want people to be redirected when they click on this advertisement.  The URL must begin with http:// or https://.  For example, %url.', array('%url' => t('http://www.sample.org/'))),
   );
 
   $form['ad_image']['tooltip'] = array(
@@ -456,11 +446,10 @@ function ad_image_node_view(&$node) {
     '#weight' => -1,
   );
   // TODO: Move this into another function so it doesn't have to be displayed.
-  if ($node->url) {
-    $node->content['ad-link'] = array(
-      '#value' => '<div class="links-to">'. t('Links to %url.', array('%url' => $node->url)) .'</div>',
-      '#weight' => 1,
-    );
-  }
+  $node->content['ad-link'] = array(
+    '#value' => '<div class="links-to">'. t('Links to %url.', array('%url' => $node->url)) .'</div>',
+    '#weight' => 1,
+  );
 }
 
+
