/[drupal]/contributions/modules/lat49ads/lat49ads.module
ViewVC logotype

Contents of /contributions/modules/lat49ads/lat49ads.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.1 - (show annotations) (download) (as text)
Sun Oct 19 02:12:22 2008 UTC (13 months, 1 week ago) by gman
Branch: MAIN
CVS Tags: HEAD
Branch point for: DRUPAL-5, DRUPAL-6--1
File MIME type: text/x-php
Initial commit of lat49ads module.
1 <?php
2 // $Id$
3
4 function lat49ads_help($section = 'admin/help#legal') {
5 $output = '';
6
7 switch ($section) {
8 case 'admin/help#lat49ads':
9 case 'admin/settings/lat49ads':
10 $output .= t('This module enables the use of the Lat49 advertising network to display ads inside of your Google maps.');
11 $output .= t('You must have an active publisher account with Lat49 to display ads. Go to the !link to create a new publisher account.', array('!link' => l('Lat49 Site', 'https://lat49.com/publisher/register.php?pubid=232', array('target' => '_blank'), NULL, NULL, TRUE, FALSE)));
12 $output .= '<br>'. t('Visit the !block page to configure your Lat49 ad blocks if you want to use them.', array('!block' => l('Block Admin', 'admin/build/block')));
13 break;
14 }
15 return $output;
16 }
17
18 function lat49ads_perm() {
19 return array('administer lat49ads');
20 }
21
22 function lat49ads_menu($may_cache) {
23
24 $items = array();
25
26 if ($may_cache) {
27
28 $items[] = array('path' => 'admin/settings/lat49ads',
29 'title' => t('Lat49Ads'),
30 'callback' => 'drupal_get_form',
31 'callback arguments' => array('lat49ads_administration'),
32 'access' => user_access('administer lat49ads'),
33 'description' => t('Administer Lat49 ads.')
34 );
35 }
36
37 return $items;
38 }
39
40
41 function lat49ads_administration() {
42
43
44 $form['lat49ads_pub_id'] = array(
45 '#type' => 'textfield',
46 '#title' => t('Publisher ID'),
47 '#default_value' => variable_get('lat49ads_pub_id', ''),
48 '#description' => t('Enter you Lat49 Publisher ID. If you dont\'t already have one, go !here', array('!here' => l('here', 'https://lat49.com/publisher/register.php', array('target' => '_blank'), NULL, NULL, TRUE, FALSE))),
49 '#required' => TRUE,
50 );
51
52
53 // overide display setting
54 $form['lat49ads_display'] = array(
55 '#type' => 'radios',
56 '#title' => t('Display Ads?'),
57 '#default_value' => variable_get('lat49ads_display', '0'),
58 '#options' => array(t('No'), t('Yes')),
59 '#description' => t('Global on/off switch for Lat49 ads.'),
60 '#required' => TRUE,
61 );
62
63 $form['lat49ads_display_map'] = array(
64 '#type' => 'radios',
65 '#title' => t('Display Ads on Maps?'),
66 '#default_value' => variable_get('lat49ads_display_map', '1'),
67 '#options' => array(t('No'), t('Yes')),
68 '#description' => t('Enable ads on your maps. If not turned on, ads will only be displayed in !blocks that are enabled and displayed with a map.', array('!blocks' => l('blocks', 'admin/build/block'))),
69 '#required' => TRUE,
70 );
71
72 $form['lat49ads_corner'] = array(
73 '#type' => 'radios',
74 '#title' => t('Display Corner'),
75 '#default_value' => variable_get('lat49ads_corner', '0'),
76 //Make dynamic depending on mapping module. For now basing off Google Maps
77 //'#options' => array(t('Lower Right'), t('Upper Right'), t('Upper Left'), t('Lower Left')),
78 '#options' => array(t('Lower Right'), t('Upper Right'), t('Upper Left')),
79 '#description' => t('Pick which corner the ads should appear. Note if you are using the zoom or display widgets, they may be blocked. Lower Left corner not allowed as it goes against the T&Cs of Google maps by blocking the branding.'),
80 '#required' => TRUE,
81 );
82 $form['lat49ads_map_it'] = array(
83 '#type' => 'radios',
84 '#title' => t('Add Map It functionality'),
85 '#default_value' => variable_get('lat49ads_map_it', '0'),
86 '#options' => array(t('Off'), t('On')),
87 '#description' => t('Certian ads have the ability to add a pin marking their business location. You may enable this feature if you want.'),
88 '#required' => TRUE,
89 );
90 $form['lat49ads_debug'] = array(
91 '#type' => 'radios',
92 '#title' => t('Debug mode'),
93 '#default_value' => variable_get('lat49ads_debug', '0'),
94 '#options' => array(t('Off'), t('On')),
95 '#description' => t('In debug mode, ads will not be counted as revenue, and displays text of a request that returns no ads.'),
96 '#required' => TRUE,
97 );
98
99
100 /*Other Options
101 * Alternate div tag to append ads to
102 * pushpin options
103 * referral link options
104 * docs for custom code if overridden theme_gmap
105 * CSS styles added if you want to overwrite the display of the ads.
106 */
107
108
109
110 return system_settings_form($form);
111 }
112
113 function lat49ads_block($op='list', $delta=0) {
114 switch ($op) {
115 case 'list':
116 $block[0]['info'] = t('Lat49 Ads: 234px x 60px');
117 $block[1]['info'] = t('Lat49 Ads: 125px x 125px');
118 $block[2]['info'] = t('Lat49 Ads: 728px x 90px');
119 $block[3]['info'] = t('Lat49 Ads: 468px x 60px');
120 $block[4]['info'] = t('Lat49 Ads: 300px x 250px');
121 break;
122 case 'view':
123 $settings = lat49ads_settings();
124 switch ($delta) {
125 case '0':
126 $id = "lat49ads_half_banner";
127 break;
128 case '1':
129 $id = "lat49ads_button";
130 break;
131 case '2':
132 $id = "lat49ads_leaderboard";
133 break;
134 case '3':
135 $id = "lat49ads_full_banner";
136 break;
137 case '4':
138 $id = "lat49ads_medium_rectangle";
139 break;
140 }
141
142 $block['content'] = '<div id="'. $id .'" '. $settings['debug'] .'>&nbsp;</div>';
143
144 $block['subject'] = '';
145 break;
146 }
147
148 return $block;
149 }
150
151 function lat49ads_corner_position() {
152
153 $values = array('lower-right', 'upper-right', 'upper-left', 'lower-left');
154 $corner = variable_get('lat49ads_corner', 0);
155
156 return $values[$corner];
157 }
158
159 function lat49ads_margins($map, $position = 'lower-right') {
160
161 $height = $map['height'];
162 $width = $map['width'];
163
164 if (strstr($width, '%')) {
165 //100% widths make the ad go off the map.
166 $width = str_replace('%', '', $width)*(0.92);
167 $width = $width .'%';
168 }
169
170 switch ($position) {
171 case 'lower-right':
172 $style = 'padding:0;margin-left:'. $width .';';
173 break;
174 case 'upper-right':
175 $style = 'margin-left:'. $width .'; margin-top:-'. $height .';';
176 break;
177 case 'upper-left':
178 $style = 'margin-left:0; margin-top:-'. $height .';';
179 break;
180 case 'lower-left':
181 $style = '';
182 break;
183
184 }
185
186 return $style;
187 }
188
189 function lat49ads_settings() {
190 $settings['position'] = lat49ads_corner_position();
191 $settings['debug'] = variable_get('lat49ads_debug', 0) ? 'lat49debug="1"' : '';
192 $settings['map_it'] = variable_get('lat49ads_map_it', 0) ? 'onlat49pushpin="AdPushpin.showPushPin" onlat49hidepushpin="AdPushpin.hidePushPin"' : '';
193
194 return $settings;
195 }
196
197 function _lat49ads_init($map = NULL) {
198 static $complete = FALSE;
199 //Make sure to only
200 if ($complete) return;
201
202 $path = drupal_get_path('module', 'lat49ads');
203 drupal_add_css($path .'/lat49ads.css');
204 drupal_add_js($path .'/lat49ads.js', 'module', 'footer');
205 drupal_set_html_head('<script type="text/javascript" src="http://adserver.lat49.com/lat49/lat49.php?ver=1.0"></script>');
206
207 $pub_ID = variable_get('lat49ads_pub_id', '');
208 $settings = lat49ads_settings();
209 $settings['placement'] = lat49ads_margins($map, $settings['position']);
210 if (variable_get('lat49ads_display_map', 1)) {
211 $append = '<div id="lat49ads_adcontainer" class="lat49ads '. $settings['position'] .'" lat49adposition="'. $settings['position'] .'" '. $settings['debug'] .' style="'. $settings['placement'] .';" '. $settings['map_it'] .'></div>';
212 $map_ad = '$(\'.gmap-map\').after(\''. $append .'\');';
213 }
214
215 drupal_add_js('
216 if( Drupal.jsEnabled ) {
217 $(document).ready(function() {
218 '.$map_ad.'
219 var publisherID = '. $pub_ID .';
220 try { //Wrap the Lat49 calls to avoid exceptions if the server is blocked
221 Lat49.initAds(publisherID);
222 } catch(e) {}
223 lat49adsGetAds('. $map ['latitude'] .','. $map['longitude'] .','. $map['zoom'] .');
224 });
225 }',
226 'inline');
227
228 $complete = TRUE;
229 }
230
231 function lat49ads_gmap($op, $map = NULL) {
232
233 if (variable_get('lat49ads_display', 0) AND !lat49ads_disallowed_pages()) {
234
235 switch ($op) {
236 case 'pre_theme_map':
237 _lat49ads_init($map);
238 break;
239 }
240 }
241 }
242
243 // Lat49.updateMultiAdsByLatLon(\'adcontainer\','.$map['latitude'].','.$map['longitude'].','.$map['zoom'].');
244
245 function lat49ads_disallowed_pages() {
246 $disallowed = false;
247 if (arg(0) == 'admin') $disallowed = true;
248 elseif (arg(0) == 'node' and arg(2) == 'edit') $disallowed = true;
249 elseif (arg(0) == 'node' and arg(1) == 'add') $disallowed = true;
250
251 return $disallowed;
252 }

  ViewVC Help
Powered by ViewVC 1.1.2