comparison ad.module @ 7:6aeff3329e01 ad

maj module ad 2.1rc1
author piotre
date Mon, 20 Jul 2009 13:54:40 +0000
parents 416ea999ed76
children 32c1a7d9e1fa
comparison
equal deleted inserted replaced
6:b7653861e0b4 7:6aeff3329e01
1 <?php 1 <?php
2 // $Id: ad.module,v 1.2.2.29.2.83.2.16.2.21 2009/04/16 14:24:53 jeremy Exp $ 2 // $Id: ad.module,v 1.2.2.29.2.83.2.16.2.23 2009/07/06 21:47:49 jeremy Exp $
3 3
4 /** 4 /**
5 * @file 5 * @file
6 * An advertising system for Drupal powered websites. 6 * An advertising system for Drupal powered websites.
7 * 7 *
155 $query['u'] = $options['url']; 155 $query['u'] = $options['url'];
156 } 156 }
157 else { 157 else {
158 $query['u'] = $_GET['q']; 158 $query['u'] = $_GET['q'];
159 } 159 }
160 $src = htmlentities(url($base_url .'/'. $adserve, array('query' => $query))); 160 $src = url($base_url .'/'. $adserve, array('query' => $query));
161 if ($options['ad_display'] == 'iframe') { 161 if ($options['ad_display'] == 'iframe') {
162 // TODO: We need to know the IFrame size before it is displayed. This 162 // TODO: We need to know the IFrame size before it is displayed. This
163 // limits the flexibility of what can be displayed in these frames. 163 // limits the flexibility of what can be displayed in these frames.
164 // For now we'll have a global value, later we'll add per-group 164 // For now we'll have a global value, later we'll add per-group
165 // over-rides. 165 // over-rides.
170 $append .= 'height="'. $height .'" '; 170 $append .= 'height="'. $height .'" ';
171 } 171 }
172 if ($width = variable_get('ad_iframe_width', '')) { 172 if ($width = variable_get('ad_iframe_width', '')) {
173 $append .= 'width="'. $width .'" '; 173 $append .= 'width="'. $width .'" ';
174 } 174 }
175 $output = '<iframe src="'. $src ."\" $append></iframe>"; 175 $output = '<iframe src="'. htmlentities($src) ."\" $append></iframe>";
176 } 176 }
177 else if ($options['ad_display'] == 'jquery') { 177 else if ($options['ad_display'] == 'jquery') {
178 // The theme function uses this to generate a CSS id for jQuery to use. 178 // The theme function uses this to generate a CSS id for jQuery to use.
179 $output = $src; 179 $output = $src;
180 } 180 }
181 else { 181 else {
182 $output = "<script type='text/javascript' src='$src'></script>"; 182 $output = "<script type='text/javascript' src='". htmlentities($src) ."'></script>";
183 } 183 }
184 break; 184 break;
185 } 185 }
186 186
187 if (user_access('show advertisements')) { 187 if (user_access('show advertisements')) {
209 209
210 // The naming convention for the id attribute doesn't allow commas. 210 // The naming convention for the id attribute doesn't allow commas.
211 $group = preg_replace('/[,]/', '+', $group); 211 $group = preg_replace('/[,]/', '+', $group);
212 212
213 if ($method == 'jquery') { 213 if ($method == 'jquery') {
214 drupal_add_js('misc/jquery.js', 'core');
215 return "\n<div class=\"advertisement group-$group\" id=\"group-id-$id\">\n <script type=\"text/javascript\">\n//<![CDATA[\n $(document).ready(function(){ jQuery(\"div#group-id-$id\").load(\"$display\"); });\n //]]>\n </script>\n</div>\n"; 214 return "\n<div class=\"advertisement group-$group\" id=\"group-id-$id\">\n <script type=\"text/javascript\">\n//<![CDATA[\n $(document).ready(function(){ jQuery(\"div#group-id-$id\").load(\"$display\"); });\n //]]>\n </script>\n</div>\n";
216 } 215 }
217 else if ($method == 'raw') { 216 else if ($method == 'raw') {
218 return $display; 217 return $display;
219 } 218 }
437 } 436 }
438 break; 437 break;
439 } 438 }
440 $output .= '</div>'; 439 $output .= '</div>';
441 return theme('box', t('Status'), $output); 440 return theme('box', t('Status'), $output);
441 }
442 }
443
444 /**
445 * Implementation of hook_init.
446 */
447 function ad_init() {
448 // We do this in the init hook so that it doesn't get skipped when block
449 // caching is enabled.
450 $method = variable_get('ad_display', 'javascript');
451 if ($method == 'jquery') {
452 drupal_add_js('misc/jquery.js', 'core');
442 } 453 }
443 } 454 }
444 455
445 /** 456 /**
446 * Implementation of hook_help(). 457 * Implementation of hook_help().
1197 return $form; 1208 return $form;
1198 case 'save': 1209 case 'save':
1199 variable_set('ad_block_quantity_'. $delta, $edit['ad_block_quantity_'. $delta]); 1210 variable_set('ad_block_quantity_'. $delta, $edit['ad_block_quantity_'. $delta]);
1200 break; 1211 break;
1201 case 'view': 1212 case 'view':
1202 $groups = ad_groups_list();
1203 $block['content'] = ad($delta, variable_get('ad_block_quantity_'. $delta, 1)); 1213 $block['content'] = ad($delta, variable_get('ad_block_quantity_'. $delta, 1));
1204 return $block; 1214 return $block;
1205 } 1215 }
1206 } 1216 }
1207 1217