Jeremy I apologize for posting that on the other issue.

I checked and the list check box is in fact checked, shows:

"Unable to mark ad as active as you have not uploaded any valid images. Setting ad as pending."

Comments

jeremy’s picture

That message will only be displayed if $node->fid is set to 0. I'm not sure why it would ever be 0 if you have an image uploaded.

I assume you've tried uploading another image?

Perhaps you can edit the ad_image.module and add the following block of code at line 394 (my snippet includes lines 392 and 393 to show you where this goes):

    case 'insert':
    case 'update':
echo '<pre>';
print_r($node);
echo '</pre>';

Now submit the ad again and you'll get a data dump of your node structure. Please paste that here.

Gentoo7’s picture


stdClass Object
(
    [nid] => 10
    [vid] => 10
    [uid] => 1
    [created] => 1178117425
    [type] => ad
    [changed] => 1178117425
    [aid] => 
    [title] => 43
    [body] => 34
    [format] => 1
    [url] => http://motusgear.com
    [tooltip] => yr
    [adtype] => image
    [gid] => 1
    [adstatus] => active
    [autoactivate] => 
    [autoexpire] => 
    [maxviews] => 
    [maxclicks] => 
    [log] => 
    [name] => ph7labs
    [date] => 
    [status] => 1
    [promote] => 1
    [sticky] => 0
    [revision] => 0
    [preview] => Preview
    [op] => Submit
    [submit] => Submit
    [form_token] => b04199439aad50316fe1f798eb329742
    [form_id] => ad_node_form
    [comment] => 2
    [menu] => Array
        (
            [title] => 
            [description] => 
            [pid] => 1
            [path] => 
            [weight] => 0
            [mid] => 0
            [type] => 86
        )

    [path] => 
    [files] => Array
        (
            [upload_0] => Array
                (
                    [description] => phlabs.jpg
                    [remove] => 0
                    [list] => 1
                    [filename] => phlabs.jpg
                    [filepath] => tmp/tmp_gOG4Qj
                    [filemime] => image/jpeg
                    [filesize] => 45728
                    [fid] => upload_0
                )

        )

    [upload] => 
    [attach] => Attach
    [attach-url] => http://forexdistrict.com/upload/js
    [teaser] => 34
    [validated] => 1
    [is_new] => 1
)
Anonymous’s picture

I do notice the same problem.
Could it be related to private images option? That is the setting I currently use.

jeremy’s picture

Title: Unable to mark ad as active » Unable to mark ad as active when using private download method
Assigned: Unassigned » jeremy

Yes, you are correct, the issue is with the private download method. Now that I can duplicate this I will look into a proper fix. Thanks for the bug report.

Gentoo7’s picture

np,
so no ads for me till bug is fixed

jeremy’s picture

A workaround until I am able to look into this: you can temporarily disable private download, upload all your ad images, then re-enable private downloads. In my brief testing, this seems to work.

Of course, I do plan to ultimately implement a proper fix.

Gentoo7’s picture

thanks jeremy, you the man!

appds’s picture

Hello, please, where I should go to "disable private download" ?

jeremy’s picture

administer >> settings >> File system settings >> Download method

j_norwood_young’s picture

Hi there

This is my first Drupal posting - I'm pretty new to all of this.

I found a problem with the Advertising module in version 5 in the ad_image_load_image function. The $node->files data is being accessed as an object, although it's actually an array. The function should actually be as follows:

function ad_image_load_image($node) {
  if (is_array($node->files)) {
    foreach ($node->files as $file) {
      if ($file["list"] && file_exists($file["filepath"])) {
        $image = ad_image_validate_size($file, $node->gid);
        if ($image !== FALSE) {
          $image->fid = $file["fid"];
          return $image;
        }
      }
    }
  }
  return FALSE;
}

After I made that change, I had no hassle with it claiming that I didn't have an image.

dru5sher’s picture

Sorry I am not sure how I can set it up here to be notified about developments about this issue, so I just post a message here and hope that I will then be notified.

Thx.

jeremy’s picture

Status: Active » Fixed

I have applied a fix for the private download issue to the 4.7.x and 5.x development trees. The fix will also be part of -beta9 which I hope to release within an hour.

dru5sher’s picture

Wow what a quick response, thanks a lot Jeremy!!!

j_norwood_young’s picture

Down the rabbit-hole we go. Once I'd done the change above, adverts were getting set as width=0, height=0 when I viewed them through the adserver. I eventually figured out that for some reason, when editing a node, the $node->files is type array, but at other times (like viewing the advert) it is type object. I guess it's a Drupal bug or something. Here's new code that checks which type it is and sets the size correctly:

function ad_image_validate_size($file, $gid) {
  $size = NULL;
  $error = FALSE;
  if (is_array($file)) {
  	$filepath=$file["filepath"];
  	$filename=$file["filename"];
  } elseif (is_object($file)) {
    $filepath=$file->filepath;
    $filename=$file->filename;
  }
    $format = ad_image_format_load($gid);
    list($size->width, $size->height) = getimagesize($filepath);
    if ($size->width < $format->min_width) {
      drupal_set_message(t('The image %name is only %current pixels wide, which is less than the minimum of %minimum pixels allowed in the selected ad group.', array('%name' => $filename, '%current' => $size->width, '%minimum' => $format->min_width)), 'error');
      $error = TRUE;
    }
    else if ($format->max_width && ($size->width > $format->max_width)) {
      drupal_set_message(t('The image %name is %current pixels wide, which is more than the maximum of %maximum pixels allowed in the selected ad group.', array('%name' => $filename, '%current' => $size->width, '%maximum' => $format->max_width)), 'error');
      $error = TRUE;
    }
    if ($size->height < $format->min_height) {
      drupal_set_message(t('The image %name is only %current pixels high, which is less than the minimum of %minimum pixels allowed in the selected ad group.', array('%name' => $filename, '%current' => $size->height, '%minimum' => $format->min_height)), 'error');
      $error = TRUE;
    }
    else if ($format->max_height && $size->height > $format->max_height) {
      drupal_set_message(t('The image %name is %current pixels high, which is more than the maximum of %maximum pixels allowed in the selected ad group.', array('%name' => $filename, '%current' => $size->height, '%maximum' => $format->max_height)), 'error');
      $error = TRUE;
    }
  
  if ($error) {
    return FALSE;
  }
  else {
    return $size;
  }
}
function ad_image_load_image($node) {
  if (is_array($node->files)) {
    foreach ($node->files as $file) {
      if (is_array($file)) {
        if ($file["list"] && file_exists($file["filepath"])) {
          $image = ad_image_validate_size($file, $node->gid);
          if ($image !== FALSE) {
            $image->fid = $file["fid"];
            return $image;
          }
        }
      } elseif (is_object($file)) {
        if ($file->list && file_exists($file->filepath)) {
          $image = ad_image_validate_size($file, $node->gid);
          if ($image !== FALSE) {
            $image->fid = $file->fid;
            return $image;
          }
        }
      }
    }
  }
  return FALSE;
}
jeremy’s picture

j_norwood_young, please do not clutter existing bug reports with new bug reports, open new issues instead. Appending additional issues to existing issues just confuses things.

In any case, the bug you are reporting is already fixed and will be part of -beta9. If you still have problems with -beta9, open a new issue.

j_norwood_young’s picture

Sorry Jeremy - like I said I'm new to all this. I thought it might be the cause of the bug because it was responsible for the "Unable to mark ad as active as you have not uploaded any valid images. Setting ad as pending" error. Also I thought it would be best to have the working code near my previous post, which caused its own bugs. In future I'll open new bug posts. Any other tips for a Drupal newbie?

Thanks
Jason

appds’s picture

Thank you so much Jeremy!
Problem fixed! ;-)

Gentoo7’s picture

hey jason, take it easy on my man Jeremy, he's helping everyone fast as hell, so take a chill pill.

Anonymous’s picture

Well done!
Thanks for your quick solution!

Joep

Anonymous’s picture

Status: Fixed » Closed (fixed)