So this may be an amateur issue, but I am not quite sure how this code is intended to work. I have tried embedding the following code on several different sites/platforms with no luck:

<!--start-->
<script language='JavaScript' type='text/javascript'>
 var adurl = window.location.href;
document.write(
<div class="advertisement group-tids-1" id="group-id-tids-1">"<scr" + "ipt type='text/javascript' src='http://mysite.com/sites/all/modules/ad/serve.php?q=1&amp;k=2d6924dd26cd7084f3496da73d7787ac&amp;t=1&amp;u="+adurl+"'>"+"</scr" + "ipt>"</div>
)
</script>
<!--end-->

Here is my firebug error:
invalid XML tag syntax
[Break on this error]

Any ideas what is wrong with the generated code snippet just by looking at it? Thanks in advance for your help.

CommentFileSizeAuthor
#18 ad.zip196.64 KBlawrence
#11 adremote.diff1.37 KBreikiman

Comments

bevinlorenzo’s picture

So I played with the code snippet a bit and change it to this:

<!--start-->
<script language='JavaScript' type='text/javascript'>
 var adurl = window.location.href;
document.write(
'<div class="advertisement group-tids-1" id="group-id-tids-1"><scr' + 'ipt type="text/javascript" src="http://mysite.com/sites/all/modules/ad/serve.php?q=1&amp;k=2d6924dd26cd7084f3496da73d7787ac&amp;t=1&amp;u='+adurl+'">'+'</scr' + 'ipt></div>')
</script>
<!--end-->

This code works fine, but the Snippet generated in my last post is wrong. It looks like there are some confused double and single quotes...Anyway to update the syntax output of the remote_ad snippets? Or am I just doing something wrong here?

jeremy’s picture

I tried a quick test locally last night, and agree it currently seems broken. Your changes were adding new single quotes around the snippet, and converting a pair of the double quotes to single quotes? Is that correct.

Ideally it would be great if you can submit a patch. Either way, I'll try and retest with these changes soon. Thanks for the feedback.

bevinlorenzo’s picture

Ok, so the previous code works in my local environment perfectly, but not on blogger using the custom JS/HTML Widget... Any idea why?

bevinlorenzo’s picture

I finally got this embed code to work on blogger:

<!--start-->
<script language='JavaScript' type='text/javascript'>
 var adurl = window.location.href;
document.write(
'<div class="advertisement group-tids-1" id="group-id-tids-1"><script type="text/javascript" src="http://mysite.com/sites/all/modules/ad/serve.php?q=1&amp;k=2d6924dd26cd7084f3496da73d7787ac&amp;t=1&amp;u='+adurl+'">'+'<\/scr' + 'ipt></div>')
</script>
<!--end-->

You'll notice I added a "\" before the forward slash in the closing "script" tag. It also had a hard time interpreting the broken scr'+'ipt so I removed the '+'. I am getting closer, but it still wont work on a drupal page using Full HTML. I want to nail this down before diving into the module code and creating a patch.

jeremy’s picture

Any luck with this?

btrump’s picture

Following the wisdom in Post #4 by bevinlorenzo 'solved' the problem for me, in that the javascript can be massaged to work properly. However, in the event that someone other than a programmer is generating and distributing the tags, it would be absolutely lovely if the module could output the correct code properly without human intervention.

inteldesk’s picture

Is anyone working on this output issue??

dallen’s picture

Is anyone else getting a bum value for u?
I don't think 'admin%2Fcontent%2Fad%2Fad_remote' is correct.

<!--start-->
<script language='JavaScript' type='text/javascript'>
 var adurl = window.location.href;
document.write(
<div class="advertisement group-tids-291" id="group-id-tids-291">"<scr" + "ipt type='text/javascript' src='http://registermedia.sanduskyregister.com/sites/registermedia.sanduskyregister.com/modules/contrib/ad/serve.php?q=1&amp;k=a3dfca42b9b52c87e9aefbaa166b48d6&amp;c=file&amp;f=5&amp;p=files%2Fregistermedia&amp;t=291&amp;u=admin%2Fcontent%2Fad%2Fad_remote'>"+"</scr" + "ipt>"</div>
)
</script>
<!--end-->
makotec’s picture

Here is the code that I was able to get functional:

document.write('<div class="advertisement group-tids-3" id="group-id-tids-3"><script type="text/javascript" src="http://XXXXXX/sites/all/modules/ad/serve.php?q=1&amp;k=XXXXXXXX&amp;t=3&amp;u=admin%2Fcontent%2Fad%2Fad_remote"><\/script></div>')
Daryljames’s picture

I am willing to pay $50 USD to anyone that can provide a working patch to make this work correctly...

reikiman’s picture

StatusFileSize
new1.37 KB

I have a patch which works for me. An additional thing I had to do was to add the img tag to the allowed tags in filtered HTML so that images in HTML ads would be shown.

I wanted to keep the changes inside the ad_remote module. Some of the change could be done in the ad() function rather than here.

I'm unsure in this code what the u= parameter is supposed to be doing. The substitution for 'u="+adurl+"' doesn't appear to be happening.

reikiman’s picture

Version: 6.x-2.1 » 6.x-2.2
Status: Active » Needs review

Updated status - the above patch needs review

JurgN’s picture

I've just tried to use remote ads with the changes in #11 adremote.diff and it seems to work fine! :)

drjonez’s picture

Priority: Normal » Critical

Application of above patch solved the problem. (!)

Anonymous’s picture

-

drpl’s picture

this work fine, and to solve 'u="+adurl+"' I change this line to

	$url = trim(str_replace(array('<script', '</script>', 'u=admin%2Fcontent%2Fad%2Fad_remote&amp;l=admin%2Fcontent%2Fad%2Fad_remote', "type='text/javascript'", "src='", "'>"), array('<scr\' + \'ipt', '\'+\'</scr\'+ \'ipt>', 'u=\'+adurl+\'', 'type="text/javascript"', 'src="', '">'), $url));
Anonymous’s picture

-

lawrence’s picture

StatusFileSize
new196.64 KB

Although this may be redundant, this is a great module and not everyone has patching access or knows how to use them at all. I find this module extremely useful for keeping ads hosted on one domain, and having snippets on your other websites.

To those that don't know how to patch, do the following.

1. Download the following file. - HERE
2. Go to sites/all/modules/ad/remote/ and replace the file you've just downloaded. The file name is ad_remote.module.
3. Always safe to run update.php.

To those code hackers who would rather modify code from the file, do the following.

1. Navigate to sites/all/modules/ad/remote/
2. Open ad_remote.module.
3. Delete everything in there, and replace with the following code.
4. Run update.php, as that should be common practice with every module update.


<?php
// $Id: ad_remote.module,v 1.1.4.5.2.5.2.6 2009/08/05 00:13:37 jeremy Exp $

/**
* @file
 * Enhances the ad module to providing cut-and-paste source snippets allowing
 * ads to be easily displayed on remote websites.
 *
 * Copyright (c) 2005-2009.
 *   Jeremy Andrews <jeremy@tag1consulting.com>.
 */

/**
 * Implementation of hook_perm().
 */
function ad_remote_perm() {
  return array('host remote advertisements');
}

/**
 * Implementation of hook_menu().
 */
function ad_remote_menu() {
  $items = array();

  $items['admin/content/ad/ad_remote'] = array(
    'title' => 'Remote ads',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('ad_remote_form'),
    'access arguments' => array('host remote advertisements'),
    'type' => MENU_LOCAL_TASK,
    'weight' => 1,
  );
  return $items;
}

/**
 * A simple page providing source snippets for displaying ads on remote
 * websites. When form is being submitted, it rebuilds with needed code snippet.
 */
function ad_remote_form($form_state) {
  global $user;

  $form['settings'] = array(
    '#type' => 'fieldset',
    '#title' => t('Settings'),
    '#description' => t('Use the following options to build a source snippet for displaying ads on your website.'),
    '#collapsible' => TRUE,
    '#collapsed' => isset($form_state['values']['group']),
    '#weight' => -1,
  );

  $form['settings']['group'] = taxonomy_form(_ad_get_vid(), 0, t('Select one or more groups to display ads from.'));
  $form['settings']['group']['#default_value'] = isset($form_state['values']['group']) ? $form_state['values']['group'] : '';

  if (isset($form_state['values']['quantity'])) {
    // sanity check, be sure quantity is an integer
    $quantity = (int)$form_state['values']['quantity'];
  }
  if (!isset($quantity)) {
    // must display at least one advertisement
    $quantity = 1;
  }

  $form['settings']['quantity'] = array(
    '#type' => 'select',
    '#title' => t('Quantity'),
    '#options' => drupal_map_assoc(array(1,2,3,4,5,6,7,8,9,10,15,20,25,50)),
    '#default_value' => $quantity,
    '#description' => t('Select the maximum number of unique ads that should be displayed together.'),
  );

  if (isset($form_state['values']['group'])) {
    $form['code'] = array(
      '#type' => 'fieldset',
      '#title' => t('Code snippet'),
      '#description' => t('Insert the following source snippet into the source code of your remote web page. The remote website will then display advertisements from this website. It is necessary to include the entire snippet, and to not modify it in any way.'),
    );

    // the hostid allows the tracking of multiple remote sites displaying ads
    $hostid = ad_owners_create_hostid($user->uid);
    $group = NULL;
    if (is_array($form_state['values']['group']) && !empty($form_state['values']['group'])) {
      if (isset($form_state['values']['group'][0]) && $form_state['values']['group'][0] == 0) {
        unset($form_state['values']['group'][0]);
      }
      $group = implode(',', $form_state['values']['group']);
      // sanity check, be sure group is only numbers and commas
      $group = preg_replace('/[^0-9,]/', '', $group);
    }
    if (!$group) {
      $group = 0;
    }

    // build a snippet to display on the remote web page
    $output = '<!--'. t('start') .'-->';
    // build a wrapper script which collects the url the ad is displayed on
    $output .= "\n<script language='JavaScript' type=\"text/javascript\">\n var adurl = window.location.href;\n";
    $url = ad($group, $quantity, array('hostid' => $hostid, 'ad_display' => 'javascript'));
    // break up the inner script so the browser doesn't parse it
    $url = trim(str_replace(array('<script', '</script>', 'u=admin/content/ad/ad_remote', "type='text/javascript'", "src='", "'>"), array('<scr\' + \'ipt', '\'+\'</scr\'+ \'ipt>', 'u="+adurl+"',  'type="text/javascript"', 'src="', '">'), $url));
    $output .= "document.write('$url')\n</script>\n";


    $output .= '<!--'. t('end') .'-->';

    $form['code']['snippet'] = array(
      '#type' => 'textarea',
      '#value' => $output,
      '#attributes' => array(
        'onclick' => 'this.select();',
        'onfocus' => 'this.select();',
      ),
    );
  }

  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Generate code snippet'),
  );

  return $form;
}

/**
 * Form validator.
 */
function ad_remote_form_validate($form, &$form_state) {
  if (empty($form_state['values']['group'])) {
    form_set_error('group', t('At least one group should be selected'));
  }
}
/**
 * Tell the form to rebuild.
 */
function ad_remote_form_submit($form, &$form_state) {
  $form_state['rebuild'] = TRUE;
}

After you're done, you should be able to run ads from one central domain or heck, start your own ad service if you want. I've attacked the entire module for convenience to those that would rather start from scratch, or just starting.

Jeremy, you've created a powerful module. Thanks for everything. The patch works like a charm by the way. Tested and no errors.

anonymous07’s picture

Subscribe

anonymous07’s picture

@Lawrence: Thank you for the patch!! I tried to test your method but I am still not seeing the "remote" ads.

(I copy/pasted the code you provided directly into the ad_remote.module file).

Any troubleshooting recommendations? Thanks

UPDATE: Resolved! Had to create an Input Filter on the "remote" site (the one displaying the ads) that had NOTHING checked ... I mean nothing -- no HTML Corrector, no Smileys, no Recaptcha etc.

@Jeremy: This module is looking better and better ... if only I could use Node_Import to bring the Ads in to the "repository" site containing the Ads (and set the Publish/Unpublish Dates and Ad Status during the import without a lot of programming) ... I would deploy this on a bunch of sites. I had to "roll my own" to do this type of thing, but not even close to as feature-rich as this module is.

Keep up the fabulous work because I know this wasn't easy. Cheers!

eric.chenchao’s picture

@Lawrence thanks for your patch and hope it can be committed soon

anonymous07’s picture

@John Franklin or Jeremy: Could you please consider committing Lawrence's patch in #18 above?

I had to reapply it to get new remote ad groups to show after upgrading to the March 25, 2011 6.x-2.x-dev build.

I can confirm that it works (tested across multiple sites). It appears that "CityReader" above has also used it.

salientknight’s picture

The Patch for this error works.

jonathan_hunt’s picture

I found that the code snippet offered by ad_remote didn't work. It caused a js error on my site apparently caused by quoting issues. Also, u=admin/content/ad/ad_remote wasn't being substituted because it had already be urlencoded.

diff --git a/modules/ad/remote/ad_remote.module b/modules/ad/remote/ad_remote.module
index b23a88d..aa130ce 100644
--- a/modules/ad/remote/ad_remote.module
+++ b/modules/ad/remote/ad_remote.module
@@ -98,8 +98,8 @@ function ad_remote_form($form_state) {
     $output .= "\n<script language='JavaScript' type='text/javascript'>\n var adurl = window.location.href;\n";
     $url = ad($group, $quantity, array('hostid' => $hostid, 'ad_display' => 'javascript'));
     // break up the inner script so the browser doesn't parse it
-    $url = str_replace(array('<script', '</script>', 'u=admin/content/ad/ad_remote'), array('"<scr" + "ipt', '"+"</scr" + "ipt>"', 'u="+adurl+"')
-    $output .= "document.write($url)\n</script>\n";
+    $url = trim(str_replace(array('<script', '</script>', 'u=admin%2Fcontent%2Fad%2Fad_remote'), array('<scr\' + "ipt', '"+"</scr" + \'ipt>', 'u=
+    $output .= "document.write('". $url ."')\n</script>\n";
     $output .= '<!--'. t('end') .'-->';
 
     $form['code']['snippet'] = array(

The above works for me, but I notice that impressions aren't being recorded, only clicks.

lrwebks’s picture

Issue summary: View changes
Status: Needs review » Closed (outdated)

Drupal 6 is EOL and no longer supported. Closing this as outdated for that reason. Thanks for your contribution!