| 1 |
<?php
|
| 2 |
/**
|
| 3 |
* $Id: auctionads.module,v 1.4 2007/05/25 07:47:21 yaph Exp $
|
| 4 |
*
|
| 5 |
* @file
|
| 6 |
* Author: Ramiro Gómez - http://www.ramiro.org
|
| 7 |
* A Drupal module that adds AuctionsAds.com advertising on your website.
|
| 8 |
*
|
| 9 |
* TODO restrict to selected vocabulary, input filter, ad preview (AJAX), blocks, color picker?
|
| 10 |
*/
|
| 11 |
/**
|
| 12 |
* Implementation of hook_menu().
|
| 13 |
*/
|
| 14 |
function auctionads_menu($may_cache) {
|
| 15 |
$items = array();
|
| 16 |
$items[] = array(
|
| 17 |
'path' => 'admin/settings/auctionads',
|
| 18 |
'title' => t('auctionads'),
|
| 19 |
'description' => t('Enable the node types and set the properties for the AuctionAds.com advertising.'),
|
| 20 |
'callback' => 'drupal_get_form',
|
| 21 |
'callback arguments' => array('auctionads_admin_settings'),
|
| 22 |
'access' => user_access('administer site configuration'),
|
| 23 |
'type' => MENU_NORMAL_ITEM
|
| 24 |
);
|
| 25 |
return $items;
|
| 26 |
}
|
| 27 |
|
| 28 |
/**
|
| 29 |
* admin settings for the auctionads module
|
| 30 |
*/
|
| 31 |
function auctionads_admin_settings() {
|
| 32 |
$form = array();
|
| 33 |
$form['auctionads'] = array(
|
| 34 |
'#type' => 'fieldset',
|
| 35 |
'#title' => 'auctionads ' . t('settings'),
|
| 36 |
'#collapsible' => TRUE,
|
| 37 |
'#collapsed' => FALSE
|
| 38 |
);
|
| 39 |
|
| 40 |
$form['auctionads']['auctionads_publisher_id'] = array(
|
| 41 |
'#type' => 'textfield',
|
| 42 |
'#title' => t('Publisher ID'),
|
| 43 |
'#default_value' => variable_get('auctionads_publisher_id', ''),
|
| 44 |
'#size' => 30,
|
| 45 |
'#maxlength' => 30,
|
| 46 |
'#required' => TRUE,
|
| 47 |
'#description' => t('Enter your AuctionAds.com publisher ID.')
|
| 48 |
);
|
| 49 |
|
| 50 |
$form['auctionads']['auctionads_ad_campaign'] = array(
|
| 51 |
'#type' => 'textfield',
|
| 52 |
'#title' => t('Campaign ID'),
|
| 53 |
'#default_value' => variable_get('auctionads_ad_campaign', ''),
|
| 54 |
'#size' => 40,
|
| 55 |
'#maxlength' => 40,
|
| 56 |
'#description' => t('Enter an AuctionAds.com campaign ID (optional).')
|
| 57 |
);
|
| 58 |
|
| 59 |
$form['auctionads']['auctionads_ad_format'] = array(
|
| 60 |
'#type' => 'select',
|
| 61 |
'#title' => t('Ad Format'),
|
| 62 |
'#default_value' => variable_get('auctionads_ad_format', ''),
|
| 63 |
'#options' => auctionads_ad_formats(),
|
| 64 |
'#required' => TRUE,
|
| 65 |
'#description' => t('The Ad format you want to use in your nodes.')
|
| 66 |
);
|
| 67 |
|
| 68 |
$form['auctionads']['auctionads_weight'] = array(
|
| 69 |
'#type' => 'select',
|
| 70 |
'#title' => t('Weight'),
|
| 71 |
'#default_value' => variable_get('auctionads_weight', 0),
|
| 72 |
'#options' => drupal_map_assoc(range(-20,20)),
|
| 73 |
'#description' => t('Specifies the position of the ad. A low weight, e.g. <strong>-20</strong> will display the ad above the content and a high weight, e.g. <strong>20</strong> below the content.')
|
| 74 |
);
|
| 75 |
|
| 76 |
$form['auctionads']['auctionads_new_window'] = array(
|
| 77 |
'#type' => 'checkbox',
|
| 78 |
'#title' => t('New window'),
|
| 79 |
'#default_value' => variable_get('auctionads_new_window', ''),
|
| 80 |
'#description' => t('Check this to open ad links in a new window.')
|
| 81 |
);
|
| 82 |
|
| 83 |
$form['auctionads']['auctionads_teaser_full_view'] = array(
|
| 84 |
'#type' => 'select',
|
| 85 |
'#title' => t('Display in teaser and/or full view'),
|
| 86 |
'#default_value' => variable_get('auctionads_teaser_full_view', 0),
|
| 87 |
'#options' => array(0 => t('Full view'), 1 => t('Teaser'), 2 => t('Teasers and full view')),
|
| 88 |
'#description' => t('When to display AuctionAds.'),
|
| 89 |
);
|
| 90 |
|
| 91 |
$form['auctionads']['auctionads_node_types'] = array(
|
| 92 |
'#type' => 'checkboxes',
|
| 93 |
'#title' => t('Node Types'),
|
| 94 |
'#default_value' => variable_get('auctionads_node_types', array()),
|
| 95 |
'#options' => node_get_types('names'),
|
| 96 |
'#description' => t('Activate the node types where AuctionAds.com advertising shall be displayed.')
|
| 97 |
);
|
| 98 |
|
| 99 |
// Ad keywords
|
| 100 |
$form['auctionads_kw'] = array(
|
| 101 |
'#type' => 'fieldset',
|
| 102 |
'#title' => t('Ad Keywords'),
|
| 103 |
'#collapsible' => TRUE,
|
| 104 |
'#collapsed' => FALSE
|
| 105 |
);
|
| 106 |
|
| 107 |
$form['auctionads_kw']['auctionads_keywords'] = array(
|
| 108 |
'#type' => 'textfield',
|
| 109 |
'#title' => t('Ad Keywords'),
|
| 110 |
'#default_value' => variable_get('auctionads_keywords', ''),
|
| 111 |
'#size' => 60,
|
| 112 |
'#maxlength' => 128,
|
| 113 |
'#required' => TRUE,
|
| 114 |
'#description' => t('Enter up to 15 keywords separated by semicolons ";". The keywords determine what kind of ads are displayed is as few as possible.')
|
| 115 |
);
|
| 116 |
|
| 117 |
$form['auctionads_kw']['auctionads_use_terms_as_keywords'] = array(
|
| 118 |
'#type' => 'checkbox',
|
| 119 |
'#title' => t('Use terms as keywords'),
|
| 120 |
'#default_value' => variable_get('auctionads_use_terms_as_keywords', ''),
|
| 121 |
'#description' => t('By activating this option the terms/tags associated with the node will be used as keywords. If no terms are associated with the displayed node the keywords entered above will be used. For this feature the taxonomy module must be enabled.')
|
| 122 |
);
|
| 123 |
|
| 124 |
$v_options = auctionads_get_vocabularies_options();
|
| 125 |
$v_options = array_merge (array(0 => 'Select vocabulary'), $v_options);
|
| 126 |
$form['auctionads_kw']['auctionads_restrict_vocabulary'] = array(
|
| 127 |
'#type' => 'select',
|
| 128 |
'#title' => t('Restrict to vocabulary'),
|
| 129 |
'#options' => $v_options,
|
| 130 |
'#default_value' => variable_get('auctionads_restrict_vocabulary', 0),
|
| 131 |
'#description' => t('If you activated the <strong>Use terms as keywords</strong> option you can restrict the terms used as Ad search words to one vocabulary.')
|
| 132 |
);
|
| 133 |
|
| 134 |
$form['auctionads_kw']['auctionads_term_limit'] = array(
|
| 135 |
'#type' => 'select',
|
| 136 |
'#title' => t('Number of terms'),
|
| 137 |
'#default_value' => variable_get('auctionads_term_limit', 2),
|
| 138 |
'#options' => drupal_map_assoc(range(1,15)),
|
| 139 |
'#description' => t('If you activated the <strong>Use terms as keywords</strong> option you can limit the number of terms to be used as search ad words here. 15 is the maximum number currently supported by AuctionAds.')
|
| 140 |
);
|
| 141 |
|
| 142 |
// Ad colors
|
| 143 |
$form['auctionads_colors'] = array(
|
| 144 |
'#type' => 'fieldset',
|
| 145 |
'#title' => t('Ad Colors'),
|
| 146 |
'#collapsible' => TRUE,
|
| 147 |
'#collapsed' => FALSE
|
| 148 |
);
|
| 149 |
foreach(auctionads_ad_colors() as $area => $color) {
|
| 150 |
$title = ucwords(str_replace('_',' ', $area));
|
| 151 |
$form['auctionads_colors'][$area] = array(
|
| 152 |
'#type' => 'textfield',
|
| 153 |
'#title' => $title,
|
| 154 |
'#default_value' => variable_get($area, $color),
|
| 155 |
'#size' => 6,
|
| 156 |
'#maxlength' => 6,
|
| 157 |
'#description' => t('Enter a hexadecimal color value here, e.g. <code>ff9900</code>.')
|
| 158 |
);
|
| 159 |
}
|
| 160 |
return system_settings_form($form);
|
| 161 |
}
|
| 162 |
/**
|
| 163 |
* Implementation of hook_nodeapi().
|
| 164 |
*/
|
| 165 |
function auctionads_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
|
| 166 |
if ($op == 'view') {
|
| 167 |
//Check our node is one of the checked types
|
| 168 |
if(in_array($node->type, variable_get('auctionads_node_types', array()), TRUE)) {
|
| 169 |
$display_ad = FALSE;
|
| 170 |
switch (variable_get('auctionads_teaser_full_view', 0)) {
|
| 171 |
// display in full view only
|
| 172 |
case 0:
|
| 173 |
if (!$a3) {
|
| 174 |
$display_ad = TRUE;
|
| 175 |
}
|
| 176 |
break;
|
| 177 |
// display in teaser only
|
| 178 |
case 1:
|
| 179 |
if ($a3) {
|
| 180 |
$display_ad = TRUE;
|
| 181 |
}
|
| 182 |
break;
|
| 183 |
// display in full view and teaser
|
| 184 |
case 2:
|
| 185 |
$display_ad = TRUE;
|
| 186 |
break;
|
| 187 |
}
|
| 188 |
if($display_ad) {
|
| 189 |
$node->content['auctionads_ad'] = array(
|
| 190 |
'#value' => theme('auctionads_ad'),
|
| 191 |
'#weight' => variable_get('auctionads_weight', 0)
|
| 192 |
);
|
| 193 |
}
|
| 194 |
}
|
| 195 |
}
|
| 196 |
}
|
| 197 |
|
| 198 |
function auctionads_generate_ad_code() {
|
| 199 |
// get color values
|
| 200 |
$ad_colors = auctionads_ad_colors();
|
| 201 |
$auctionads_color_border = variable_get('outer_border_color', $ad_colors['outer_border_color']);
|
| 202 |
$auctionads_color_bg = variable_get('background_color', $ad_colors['background_color']);
|
| 203 |
$auctionads_color_heading = variable_get('heading_color', $ad_colors['heading_color']);
|
| 204 |
$auctionads_color_text = variable_get('description_color', $ad_colors['description_color']);
|
| 205 |
$auctionads_color_link = variable_get('link_color', $ad_colors['link_color']);
|
| 206 |
|
| 207 |
// get keywords
|
| 208 |
$ad_kw = variable_get('auctionads_keywords', '');
|
| 209 |
if (variable_get('auctionads_use_terms_as_keywords','')) {
|
| 210 |
if(is_numeric(arg(1))) {
|
| 211 |
$nid = arg(1);
|
| 212 |
$terms = array();
|
| 213 |
$vid = variable_get('auctionads_restrict_vocabulary', 0);
|
| 214 |
if ($vid != 0) {
|
| 215 |
$terms = module_invoke('taxonomy','node_get_terms_by_vocabulary', $nid, $vid, 'tid');
|
| 216 |
} else {
|
| 217 |
$terms = module_invoke('taxonomy','node_get_terms', $nid);
|
| 218 |
}
|
| 219 |
$keywords = array();
|
| 220 |
$count = 0;
|
| 221 |
$term_limit = variable_get('auctionads_term_limit', 2);
|
| 222 |
foreach ($terms as $t) {
|
| 223 |
// 15 is the maximum number of keywords supported by AuctionAds
|
| 224 |
if ($count < $term_limit) {
|
| 225 |
array_push($keywords, $t->name);
|
| 226 |
}
|
| 227 |
$count++;
|
| 228 |
}
|
| 229 |
if ($count > 0) {
|
| 230 |
$ad_kw = implode(';',$keywords);
|
| 231 |
}
|
| 232 |
}
|
| 233 |
}
|
| 234 |
|
| 235 |
$ad_client = variable_get('auctionads_publisher_id', '');
|
| 236 |
$ad_format = variable_get('auctionads_ad_format', '');
|
| 237 |
$ad_campaign = variable_get('auctionads_ad_campaign', '');
|
| 238 |
list($width, $height) = explode('x',$ad_format,2);
|
| 239 |
|
| 240 |
// new window
|
| 241 |
if (variable_get('auctionads_new_window', '')) {
|
| 242 |
$new_window = 'auctionads_options = "n";';
|
| 243 |
}
|
| 244 |
|
| 245 |
$auctionads_code =<<<EOF
|
| 246 |
<script type="text/javascript"><!--
|
| 247 |
auctionads_ad_client = "$ad_client";
|
| 248 |
auctionads_ad_campaign = "$ad_campaign";
|
| 249 |
auctionads_ad_width = "$width";
|
| 250 |
auctionads_ad_height = "$height";
|
| 251 |
auctionads_ad_kw = "$ad_kw";
|
| 252 |
auctionads_color_border = "$auctionads_color_border";
|
| 253 |
auctionads_color_bg = "$auctionads_color_bg";
|
| 254 |
auctionads_color_heading = "$auctionads_color_heading";
|
| 255 |
auctionads_color_text = "$auctionads_color_text";
|
| 256 |
auctionads_color_link = "$auctionads_color_link";
|
| 257 |
$new_window
|
| 258 |
--></script>
|
| 259 |
<script type="text/javascript" src="http://ads.auctionads.com/pagead/show_ads.js">
|
| 260 |
</script>
|
| 261 |
EOF;
|
| 262 |
|
| 263 |
return $auctionads_code;
|
| 264 |
}
|
| 265 |
|
| 266 |
/**
|
| 267 |
* theme function for ad display
|
| 268 |
*/
|
| 269 |
function theme_auctionads_ad() {
|
| 270 |
$ad_code = auctionads_generate_ad_code();
|
| 271 |
return '<div class="auctionads-ad-code">'. $ad_code .'</div>';
|
| 272 |
}
|
| 273 |
|
| 274 |
function auctionads_ad_formats() {
|
| 275 |
$ad_formats = array(
|
| 276 |
'728x90' => ('728 x 90 Leaderboard'),
|
| 277 |
'468x60' => ('468 x 60 Banner'),
|
| 278 |
'336x280' => ('336 x 280 Large Rectangle'),
|
| 279 |
'300x250' => ('300 x 250 Medium rectangle'),
|
| 280 |
'250x250' => ('250 x 250 Square'),
|
| 281 |
'234x60' => ('234 x 60 Half Banner'),
|
| 282 |
'180x150' => ('180 x 150 Small Rectangle'),
|
| 283 |
'160x600' => ('160 x 600 Wide Skyscraper'),
|
| 284 |
'125x125' => ('125 x 125 Button'),
|
| 285 |
'120x600' => ('120 x 600 Skyscraper'),
|
| 286 |
'120x240' => ('120 x 240 Vertical Banner')
|
| 287 |
);
|
| 288 |
return $ad_formats;
|
| 289 |
}
|
| 290 |
|
| 291 |
function auctionads_ad_colors() {
|
| 292 |
// array of colors with default values
|
| 293 |
$ad_colors = array(
|
| 294 |
'outer_border_color' => 'CFF8A3',
|
| 295 |
'background_color' => 'FFFFFF',
|
| 296 |
'heading_color' => '00A0E2',
|
| 297 |
'description_color' => '000000',
|
| 298 |
'link_color' => '008000'
|
| 299 |
);
|
| 300 |
return $ad_colors;
|
| 301 |
}
|
| 302 |
|
| 303 |
function auctionads_get_vocabularies_options() {
|
| 304 |
$vocabularies = module_invoke('taxonomy','get_vocabularies');
|
| 305 |
foreach ($vocabularies as $v) {
|
| 306 |
$options[$v->vid] = $v->name;
|
| 307 |
}
|
| 308 |
return $options;
|
| 309 |
}
|
| 310 |
|
| 311 |
?>
|