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

Contents of /contributions/modules/shoppingads/shoppingads.module

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


Revision 1.3 - (show annotations) (download) (as text)
Thu Sep 4 19:32:38 2008 UTC (14 months, 2 weeks ago) by yaph
Branch: MAIN
CVS Tags: DRUPAL-6--1-1-DEV, HEAD
Branch point for: DRUPAL-6--1
Changes since 1.2: +13 -160 lines
File MIME type: text/x-php
Added hook_uninstall and moved admin settings to include file
1 <?php
2 /**
3 * $Id: shoppingads.module,v 1.2 2008/02/17 17:04:38 yaph Exp $
4 *
5 * @file
6 * Author: Ramiro Gómez - http://www.ramiro.org
7 * A Drupal module that adds ShoppingAds.com advertising on your website.
8 *
9 * TODO input filter, ad preview, blocks, color picker?
10 */
11
12 /**
13 * Implementation of hook_menu().
14 */
15 function shoppingads_menu() {
16 $items = array();
17 $items['admin/settings/shoppingads'] = array(
18 'title' => 'Shoppingads',
19 'description' => 'Enable the node types and set the properties for the shoppingads.com advertising.',
20 'page callback' => 'drupal_get_form',
21 'page arguments' => array('shoppingads_admin_settings'),
22 'access arguments' => array('administer site configuration'),
23 'type' => MENU_NORMAL_ITEM,
24 'file' => 'shoppingads.admin.inc'
25 );
26 return $items;
27 }
28
29 function shoppingads_theme() {
30 return array(
31 'shoppingads_ad' => array()
32 );
33 }
34
35 /**
36 * Implementation of hook_nodeapi().
37 */
38 function shoppingads_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
39 if ($op == 'view') {
40 //Check our node is one of the checked types
41 if (in_array($node->type, variable_get('shoppingads_node_types', array()), TRUE)) {
42 $display_ad = FALSE;
43 switch (variable_get('shoppingads_teaser_full_view', 0)) {
44 // display in full view only
45 case 0:
46 if (!$a3) {
47 $display_ad = TRUE;
48 }
49 break;
50 // display in teaser only
51 case 1:
52 if ($a3) {
53 $display_ad = TRUE;
54 }
55 break;
56 // display in full view and teaser
57 case 2:
58 $display_ad = TRUE;
59 break;
60 }
61 if ($display_ad) {
62 $node->content['shoppingads_ad'] = array(
63 '#value' => theme('shoppingads_ad'),
64 '#weight' => variable_get('shoppingads_weight', 0)
65 );
66 }
67 }
68 }
69 }
70
71 function shoppingads_generate_ad_code() {
72 // get color values
73 $ad_colors = shoppingads_ad_colors();
74 $shoppingads_color_border = variable_get('shoppingads_outer_border_color', $ad_colors['outer_border_color']);
75 $shoppingads_color_bg = variable_get('shoppingads_background_color', $ad_colors['background_color']);
76 $shoppingads_color_heading = variable_get('shoppingads_heading_color', $ad_colors['heading_color']);
77 $shoppingads_color_text = variable_get('shoppingads_description_color', $ad_colors['description_color']);
78 $shoppingads_color_link = variable_get('shoppingads_link_color', $ad_colors['link_color']);
79
80 // get keywords
81 $ad_kw = variable_get('shoppingads_keywords', '');
82 if (variable_get('shoppingads_use_terms_as_keywords', '')) {
83 if (is_numeric(arg(1))) {
84 $nid = arg(1);
85 $terms = array();
86 $vid = variable_get('shoppingads_restrict_vocabulary', 0);
87 if ($vid != 0) {
88 $terms = module_invoke('taxonomy', 'node_get_terms_by_vocabulary', $nid, $vid, 'tid');
89 }
90 else {
91 $terms = module_invoke('taxonomy', 'node_get_terms', $nid);
92 }
93 $keywords = array();
94 $count = 0;
95 $term_limit = variable_get('shoppingads_term_limit', 2);
96 foreach ($terms as $t) {
97 // 15 is the maximum number of keywords supported by shoppingads
98 if ($count < $term_limit) {
99 array_push($keywords, $t->name);
100 }
101 $count++;
102 }
103 if ($count > 0) {
104 $ad_kw = implode(';', $keywords);
105 }
106 }
107 }
108
109 $ad_client = variable_get('shoppingads_publisher_id', '');
110 $ad_format = variable_get('shoppingads_ad_format', '');
111 $ad_campaign = variable_get('shoppingads_ad_campaign', 'default');
112 $attitude = variable_get('shoppingads_ad_attitude', '');
113 $attitude = 'shoppingads_attitude = "'. $attitude .'";';
114 list($width, $height) = explode('x', $ad_format, 2);
115 if (!$width) $width = 768;
116 if (!$height) $height = 90;
117
118 // new window
119 if (variable_get('shoppingads_new_window', '')) {
120 $new_window = 'shoppingads_options = "n";';
121 }
122
123 $shoppingads_code =<<<EOF
124 <script type="text/javascript"><!--
125 shoppingads_ad_client = "$ad_client";
126 shoppingads_ad_campaign = "$ad_campaign";
127 shoppingads_ad_width = "$width";
128 shoppingads_ad_height = "$height";
129 shoppingads_ad_kw = "$ad_kw";
130 shoppingads_color_border = "$shoppingads_color_border";
131 shoppingads_color_bg = "$shoppingads_color_bg";
132 shoppingads_color_heading = "$shoppingads_color_heading";
133 shoppingads_color_text = "$shoppingads_color_text";
134 shoppingads_color_link = "$shoppingads_color_link";
135 $attitude
136 $new_window
137 --></script>
138 <script type="text/javascript" src="http://ads.shoppingads.com/pagead/show_sa_ads.js">
139 </script>
140 EOF;
141 return $shoppingads_code;
142 }
143
144 /**
145 * theme function for ad display
146 */
147 function theme_shoppingads_ad() {
148 $ad_code = shoppingads_generate_ad_code();
149 return '<div class="shoppingads-ad-code">'. $ad_code .'</div>';
150 }
151
152 function shoppingads_ad_formats() {
153 $ad_formats = array(
154 '728x90' => ('728 x 90 Leaderboard'),
155 '468x60' => ('468 x 60 Banner'),
156 '336x280' => ('336 x 280 Large Rectangle'),
157 '300x250' => ('300 x 250 Medium rectangle'),
158 '250x250' => ('250 x 250 Square'),
159 '234x60' => ('234 x 60 Half Banner'),
160 '180x150' => ('180 x 150 Small Rectangle'),
161 '160x600' => ('160 x 600 Wide Skyscraper'),
162 '125x125' => ('125 x 125 Button'),
163 '120x600' => ('120 x 600 Skyscraper'),
164 '120x240' => ('120 x 240 Vertical Banner')
165 );
166 return $ad_formats;
167 }
168
169 function shoppingads_ad_colors() {
170 // array of colors with default values
171 $ad_colors = array(
172 'shoppingads_outer_border_color' => 'CFF8A3',
173 'shoppingads_background_color' => 'FFFFFF',
174 'shoppingads_heading_color' => '00A0E2',
175 'shoppingads_description_color' => '000000',
176 'shoppingads_link_color' => '008000'
177 );
178 return $ad_colors;
179 }
180
181 function shoppingads_get_vocabularies_options() {
182 $vocabularies = module_invoke('taxonomy', 'get_vocabularies');
183 $options[0] = 'Select vocabulary';
184 foreach ($vocabularies as $v) {
185 $options[$v->vid] = $v->name;
186 }
187 return $options;
188 }

  ViewVC Help
Powered by ViewVC 1.1.2