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

update advertisement
author pierre
date Thu, 02 Apr 2009 15:28:21 +0000
parents d8a3998dac8e
children 32c1a7d9e1fa
comparison
equal deleted inserted replaced
0:d8a3998dac8e 1:948362c2a207
1 <?php 1 <?php
2 // $Id: ad_remote.module,v 1.1.4.5.2.5 2009/02/16 23:12:29 jeremy Exp $ 2 // $Id: ad_remote.module,v 1.1.4.5.2.5.2.5 2009/03/05 00:35:56 jeremy Exp $
3 3
4 /** 4 /**
5 * @file 5 * @file
6 * Enhances the ad module to providing cut-and-paste source snippets allowing 6 * Enhances the ad module to providing cut-and-paste source snippets allowing
7 * ads to be easily displayed on remote websites. 7 * ads to be easily displayed on remote websites.
33 ); 33 );
34 return $items; 34 return $items;
35 } 35 }
36 36
37 /** 37 /**
38 * A simple page providing source snippets for displaying ads on remote 38 * A simple page providing source snippets for displaying ads on remote
39 * websites. When form is being submitted, it rebuilds with needed code snippet. 39 * websites. When form is being submitted, it rebuilds with needed code snippet.
40 */ 40 */
41 function ad_remote_form($form_state) { 41 function ad_remote_form($form_state) {
42 global $user; 42 global $user;
43 43
52 52
53 $form['settings']['group'] = taxonomy_form(_ad_get_vid(), 0, t('Select one or more groups to display ads from.')); 53 $form['settings']['group'] = taxonomy_form(_ad_get_vid(), 0, t('Select one or more groups to display ads from.'));
54 $form['settings']['group']['#default_value'] = isset($form_state['values']['group']) ? $form_state['values']['group'] : ''; 54 $form['settings']['group']['#default_value'] = isset($form_state['values']['group']) ? $form_state['values']['group'] : '';
55 55
56 if (isset($form_state['values']['quantity'])) { 56 if (isset($form_state['values']['quantity'])) {
57 // Sanity check, be sure quantity is an integer. 57 // sanity check, be sure quantity is an integer
58 $quantity = (int)$form_state['values']['quantity']; 58 $quantity = (int)$form_state['values']['quantity'];
59 } 59 }
60 if (!isset($quantity)) { 60 if (!isset($quantity)) {
61 // Must display at least one advertisement. 61 // must display at least one advertisement
62 $quantity = 1; 62 $quantity = 1;
63 } 63 }
64 64
65 $form['settings']['quantity'] = array( 65 $form['settings']['quantity'] = array(
66 '#type' => 'select', 66 '#type' => 'select',
67 '#title' => t('Quantity'), 67 '#title' => t('Quantity'),
68 '#options' => drupal_map_assoc(array(1,2,3,4,5,6,7,8,9,10,15,20,25,50)), 68 '#options' => drupal_map_assoc(array(1,2,3,4,5,6,7,8,9,10,15,20,25,50)),
69 '#default_value' => $quantity, 69 '#default_value' => $quantity,
70 '#description' => t('Select the maximum number of unique ads that should be displayed together.'), 70 '#description' => t('Select the maximum number of unique ads that should be displayed together.'),
71 ); 71 );
72 72
73 if (isset($form_state['values']['group'])) { 73 if (isset($form_state['values']['group'])) {
74 $form['code'] = array( 74 $form['code'] = array(
75 '#type' => 'fieldset', 75 '#type' => 'fieldset',
76 '#title' => t('Code snippet'), 76 '#title' => t('Code snippet'),
77 '#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.'), 77 '#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.'),
78 ); 78 );
79 79
80 $hostid = ad_host_id_create($user->uid); 80 // the hostid allows the tracking of multiple remote sites displaying ads
81 $hostid = ad_owners_create_hostid($user->uid);
81 $group = NULL; 82 $group = NULL;
82 if (is_array($form_state['values']['group']) && !empty($form_state['values']['group'])) { 83 if (is_array($form_state['values']['group']) && !empty($form_state['values']['group'])) {
83 if (isset($form_state['values']['group'][0]) && $form_state['values']['group'][0] == 0) { 84 if (isset($form_state['values']['group'][0]) && $form_state['values']['group'][0] == 0) {
84 unset($form_state['values']['group'][0]); 85 unset($form_state['values']['group'][0]);
85 } 86 }
86 $group = implode(',', $form_state['values']['group']); 87 $group = implode(',', $form_state['values']['group']);
87 // Sanity check, be sure group is only numbers and commas. 88 // sanity check, be sure group is only numbers and commas
88 $group = preg_replace('/[^0-9,]/', '', $group); 89 $group = preg_replace('/[^0-9,]/', '', $group);
89 } 90 }
90 if (!$group) { 91 if (!$group) {
91 $group = 0; 92 $group = 0;
92 } 93 }
93 94
94 $output = '<!--'. t('start') .'-->'. ad($group, $quantity, array('raw' => 1, 'hostid' => $hostid)) .'<!--'. t('end') .'-->'; 95 // build a snippet to display on the remote web page
96 $output = '<!--'. t('start') .'-->';
97 // build a wrapper script which collects the url the ad is displayed on
98 $output .= "\n<script language='JavaScript' type='text/javascript'>\n var adurl = window.location.href;\n";
99 $url = ad($group, $quantity, array('hostid' => $hostid, 'div' => FALSE));
100 // break up the inner script so the browser doesn't parse it
101 $url = str_replace(array('<script', '</script>', 'u=admin/content/ad/ad_remote'), array('"<scr" + "ipt', '"+"</scr" + "ipt>"', 'u="+adurl+"'), $url);
102 $output .= "document.write($url)\n</script>\n";
103 $output .= '<!--'. t('end') .'-->';
104
95 $form['code']['snippet'] = array( 105 $form['code']['snippet'] = array(
96 '#type' => 'textarea', 106 '#type' => 'textarea',
97 '#value' => $output, 107 '#value' => $output,
98 '#attributes' => array( 108 '#attributes' => array(
99 'onclick' => 'this.select();', 109 'onclick' => 'this.select();',