diff remote/ad_remote.module @ 1:948362c2a207 ad

update advertisement
author pierre
date Thu, 02 Apr 2009 15:28:21 +0000
parents d8a3998dac8e
children 32c1a7d9e1fa
line wrap: on
line diff
--- a/remote/ad_remote.module	Fri Feb 20 14:04:09 2009 +0000
+++ b/remote/ad_remote.module	Thu Apr 02 15:28:21 2009 +0000
@@ -1,5 +1,5 @@
 <?php
-// $Id: ad_remote.module,v 1.1.4.5.2.5 2009/02/16 23:12:29 jeremy Exp $
+// $Id: ad_remote.module,v 1.1.4.5.2.5.2.5 2009/03/05 00:35:56 jeremy Exp $
 
 /**
 * @file
@@ -35,7 +35,7 @@
 }
 
 /**
- * A simple page providing source snippets for displaying ads on remote 
+ * 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) {
@@ -54,11 +54,11 @@
   $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.
+    // sanity check, be sure quantity is an integer
     $quantity = (int)$form_state['values']['quantity'];
   }
   if (!isset($quantity)) {
-    // Must display at least one advertisement.
+    // must display at least one advertisement
     $quantity = 1;
   }
 
@@ -69,29 +69,39 @@
     '#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 your web page to display ads hosted on this web site.  Include the entire snippet, and do not modify it in any way.'),
+      '#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.'),
     );
 
-    $hostid = ad_host_id_create($user->uid);
+    // 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.
+      // sanity check, be sure group is only numbers and commas
       $group = preg_replace('/[^0-9,]/', '', $group);
     }
     if (!$group) {
       $group = 0;
     }
 
-    $output = '<!--'. t('start') .'-->'. ad($group, $quantity, array('raw' => 1, 'hostid' => $hostid)) .'<!--'. t('end') .'-->';
+    // 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, 'div' => FALSE));
+    // 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+"'), $url);
+    $output .= "document.write($url)\n</script>\n";
+    $output .= '<!--'. t('end') .'-->';
+
     $form['code']['snippet'] = array(
       '#type' => 'textarea',
       '#value' => $output,