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

Contents of /contributions/modules/adbard/adbard.module

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


Revision 1.1 - (show annotations) (download) (as text)
Fri Apr 4 18:44:16 2008 UTC (19 months, 3 weeks ago) by jeremy
Branch: MAIN
CVS Tags: DRUPAL-5--1-0, HEAD
Branch point for: DRUPAL-6--1, DRUPAL-5
File MIME type: text/x-php
A simple module for integrating a Drupal powered website with the Ad
Bard Network, an open source advertising network offering 80% of the
price per clicks to FOSS websites.
1 <?php
2 // $Id: $
3
4 /**
5 * @file
6 * Display Ad Bard Network ads on your Drupal website.
7 *
8 * Visit http://adbard.net/ for for more information on the Ad Bard Network.
9 *
10 * Copyright (c) 2008.
11 * Jeremy Andrews <jeremy@tag1consulting.com>. All rights reserved.
12 */
13
14 /**
15 * Implementation of hook_menu().
16 */
17 function adbard_menu($may_cache) {
18 $items = array();
19
20 if ($may_cache) {
21 $items[] = array(
22 'path' => 'admin/settings/adbard',
23 'title' => 'Ad Bard Network',
24 'callback' => 'drupal_get_form',
25 'callback arguments' => array('adbard_settings'),
26 );
27 }
28
29 return $items;
30 }
31
32 function adbard_settings() {
33 $form = array();
34
35 $form['adbard_instructions'] = array(
36 '#type' => 'fieldset',
37 '#title' => t('Instructions'),
38 '#collapsible' => TRUE,
39 '#collapsed' => variable_get('adbard_key', '') ? TRUE : FALSE,
40 );
41 $form['adbard_instructions']['text'] = array(
42 '#value' => t('<p>The Ad Bard Network is dedicated to fostering a friendly and useful advertising community, built from and focused on Free and Open Source Software. In order to display ads from the Ad Bard Network on your website, you first have to <a href="http://adbard.net/user/">create an Ad Bard user account</a>. Your website must be somehow related to Free and Open Source Software to join the Ad Bard Network.</p><p>Once you have logged in to your Ad Bard account, you can find your Ad Bard key by clicking "Status" in your Website Controls. On the resulting screen, click "Instructions" at the top of the page. You will now find a screen offering you HTML snippets that are supposed to be installed on your website. This module makes it so you don\'t have to manually install the snippets. Instead, from within a provided snippet, find a line that reads something like:<pre> var adbard_key="a0b1c2d3e4f5a6b7c8d9e0f1a2b3c4e"</pre></p><p>Copy the lower-case letters and numbers that appear in quotes after adbard_key, and paste them into the Ad Bard key textfield below. They key is the same in all snippets, so it does not matter from which snippet you copy it.'),
43 '#prefix' => '<div>',
44 '#suffix' => '</div>',
45 );
46
47 $form['adbard_key'] = array(
48 '#type' => 'textfield',
49 '#title' => t('Ad Bard key'),
50 '#size' => 33,
51 '#maxlength' => 34,
52 '#default_value' => variable_get('adbard_key', ''),
53 '#description' => t('Enter the 32-character adbard_key assigned to you by the Ad Bard Network. If you don\'t know what this is, refer to the instructions at the top of this screen.'),
54 '#required' => TRUE,
55 );
56
57 $form['save'] = array(
58 '#type' => 'submit',
59 '#value' => t('Save'),
60 );
61
62 return $form;
63 }
64
65 /**
66 * Perform some sanity tests on the entered adbard_key.
67 */
68 function adbard_settings_validate($form_id, $form_values) {
69 $adbard_key = preg_replace('/["]/', '', $form_values['adbard_key']);
70 $adbard_key_validate = preg_replace('/[^a-f0-9]/', '', $adbard_key);
71 if ($adbard_key == 'a0b1c2d3e4f5a6b7c8d9e0f1a2b3c4e') {
72 form_set_error('adbard_key', t('You must use the adbard_key provided by <a href="http://adbard.net/user">logging in to your account on the Ad Bard Network</a>, not the example provided in the instructions on this page.'));
73 }
74 else if ($adbard_key != $adbard_key_validate) {
75 form_set_error('adbard_key', t('There are invalid characters in the key you have entered. Please double check the key provided by the Ad Bard Network and try again.'));
76 }
77 else if (strlen($adbard_key) != 32) {
78 form_set_error('adbard_key', t('Please be sure to include the entire key, it must be exactly 32 characters long.'));
79 }
80 }
81
82 /**
83 * Save the validate adbard_key.
84 */
85 function adbard_settings_submit($form_id, $form_values) {
86 $adbard_key = preg_replace('/"/', '', $form_values['adbard_key']);
87 variable_set('adbard_key', $adbard_key);
88 drupal_set_message(t('Please visit the <a href="@url">blocks administration page</a> to enable Ad Bard Network blocks.', array('@url' => url('admin/build/block'))));
89 }
90
91 /**
92 * Implementation of hook_block().
93 */
94 function adbard_block($op = 'list', $delta = 0, $edit = array()) {
95 if ($adbard_key = variable_get('adbard_key', '')) {
96 // An array of all ad types support by the Ad Bard Network.
97 $adbard_types = array(
98 '20' => t('175x125 Ad Image Blocks'),
99 );
100 $adbard_paths = array(
101 '20' => t('http://cdn1.adbard.net/ab3.js'),
102 );
103 if ($op == 'list') {
104 // Create a block for all ad types support by the Ad Bard Network.
105 foreach ($adbard_types as $type => $description) {
106 $blocks[$type]['info'] = "Ad Bard Network: $description";
107 }
108 return $blocks;
109 }
110 else if ($op == 'view') {
111 if (isset($adbard_types[$delta])) {
112 $description = $adbard_types[$delta];
113 $src = $adbard_paths[$delta];
114 $block['content'] = "<!--Ad Bard Image, $description, begin -->\n<script type=\"text/javascript\">\n var adbard_key=\"$adbard_key\";\n var adbard_type=\"$delta\";\n</script>\n<script type=\"text/javascript\" src=\"$src\"></script>\n<!--Ad Bard, end-->";
115 }
116 return $block;
117 }
118 }
119 }
120
121 ?>

  ViewVC Help
Powered by ViewVC 1.1.2