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

Diff of /contributions/modules/adsense_injector/adsense_injector.module

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

revision 1.1.2.7 by inactivist, Tue Mar 18 02:38:42 2008 UTC revision 1.1.2.8 by hswong3i, Tue Dec 16 08:20:55 2008 UTC
# Line 1  Line 1 
1  <?php  <?php
2    
3    /*  $Id: adsense_injector.module,v 1.1.2.6 2007/04/06 16:05:55 inactivist Exp $ */    /*  $Id: adsense_injector.module,v 1.1.2.7 2008/03/18 02:38:42 inactivist Exp $ */
4    
5    /**    /**
6     * Inject adsense ads into node content automatically.     * Inject adsense ads into node content automatically.
7     *     *
8     * Copyright (c) 2006, 2007 Exodus Development, Inc.  All Rights Reserved.     * Copyright (c) 2006, 2007 Exodus Development, Inc.  All Rights Reserved.
9     * Licensed under the terms of the GNU Public License (GPL) version 2.  Please see LICENSE.txt for     * Licensed under the terms of the GNU Public License (GPL) version 2.  Please see LICENSE.txt for
10     * license terms.  Posession and use of this code signifies acceptance of license     * license terms.  Posession and use of this code signifies acceptance of license
11     * terms.     * terms.
# Line 13  Line 13 
13     * Visit Exodus Development at     * Visit Exodus Development at
14     * http://exodusdev.com exodusdev@gmail.com     * http://exodusdev.com exodusdev@gmail.com
15     *     *
16     * Project homepage:     * Project homepage:
17     * http://exodusdev.com/drupal/4.7/modules/adsense_injector.module     * http://exodusdev.com/drupal/4.7/modules/adsense_injector.module
18     *     *
19     * The purpose of this module is to provide a simple method of automatically placing 'inline'     * The purpose of this module is to provide a simple method of automatically placing 'inline'
20     * adsense module content into a full-page view of selected node types.     * adsense module content into a full-page view of selected node types.
21     * It does this by intercepting node rendering using hook_nodeapi during 'page' rendering,     * It does this by intercepting node rendering using hook_nodeapi during 'page' rendering,
22     * and injecting selected text into the $node->body field.     * and injecting selected text into the $node->body field.
23     *     *
24     * It uses a very simple scheme at present (just string concatenation)     * It uses a very simple scheme at present (just string concatenation)
25     * and could be enhanced greatly by using regular expressions, templates,     * and could be enhanced greatly by using regular expressions, templates,
26     * or other techniques in a later revision.     * or other techniques in a later revision.
27     */     */
28    
29  define('ADSENSE_INJECTOR_MODULE_VERSION', '$Id: adsense_injector.module,v 1.1.2.6 2007/04/06 16:05:55 inactivist Exp $' );  define('ADSENSE_INJECTOR_MODULE_VERSION', '$Id: adsense_injector.module,v 1.1.2.7 2008/03/18 02:38:42 inactivist Exp $' );
30  define('ADSENSE_INJECTOR_INSERT_BODY_AD_DEFAULT', TRUE);  define('ADSENSE_INJECTOR_INSERT_BODY_AD_DEFAULT', TRUE);
31    
32  define('ADSENSE_INJECTOR_BODY_INSERTION_TEMPLATE_DEFAULT', '<div class="ad-auto-inserted" style="float:left; margin: 0 1em .25em 0;">[adsense:120x240:1:1]</div>%body<br class="clear"/>[adsense:468x60:1:1]');  define('ADSENSE_INJECTOR_BODY_INSERTION_TEMPLATE_DEFAULT', '<div class="ad-auto-inserted" style="float:left; margin: 0 1em .25em 0;">[adsense:120x240:1:1]</div>%body<br class="clear"/>[adsense:468x60:1:1]');
# Line 37  define('ADSENSE_INJECTOR_LISTVIEW_INSERT Line 37  define('ADSENSE_INJECTOR_LISTVIEW_INSERT
37    
38  /**  /**
39   * Prefix for variable table entries - append node type name, store as boolean   * Prefix for variable table entries - append node type name, store as boolean
40   * value, nonzero means insert ad content   * value, nonzero means insert ad content
41   */   */
42    
43  define('ADSENSE_INJECTOR_INSERT_AD_NODETYPE', 'adsense_injector_nodetype_');  define('ADSENSE_INJECTOR_INSERT_AD_NODETYPE', 'adsense_injector_nodetype_');
# Line 62  function _adsense_injector_count_words(& Line 62  function _adsense_injector_count_words(&
62  }  }
63    
64  /**  /**
65   * Get the minimum node body wordcount for insertion.   * Get the minimum node body wordcount for insertion.
66   * May be content-type specific, but at present, it's   * May be content-type specific, but at present, it's
67   * global to all node types.   * global to all node types.
68   * @param $nodetype the node type   * @param $nodetype the node type
# Line 120  function theme_adsense_injector_transfor Line 120  function theme_adsense_injector_transfor
120   * If rendering a full page, and the node type one of the configured types,   * If rendering a full page, and the node type one of the configured types,
121   * inject configured adsense content using simple string concatenation.   * inject configured adsense content using simple string concatenation.
122   * @todo: Evaluate efficiency of string concat vs. sprintf, other methods.   * @todo: Evaluate efficiency of string concat vs. sprintf, other methods.
123   */   */
124  function adsense_injector_nodeapi(&$node, $op, $teaser, $page) {  function adsense_injector_nodeapi(&$node, $op, $teaser, $page) {
125    // insert an ad into the body.    // insert an ad into the body.
126    if (module_exists('adsense') && _adsense_page_match() && variable_get(ADSENSE_INJECTOR_INSERT_AD_NODETYPE . $node->type, FALSE)) {    if (module_exists('adsense') && _adsense_page_match() && variable_get(ADSENSE_INJECTOR_INSERT_AD_NODETYPE . $node->type, FALSE)) {
# Line 134  function adsense_injector_nodeapi(&$node Line 134  function adsense_injector_nodeapi(&$node
134   * Implementation of hook_menu   * Implementation of hook_menu
135   */   */
136  function adsense_injector_menu() {  function adsense_injector_menu() {
137          $items[] = array(    $items[] = array(
138                  'path' => 'admin/settings/adsense_injector',      'path' => 'admin/settings/adsense_injector',
139                  'title' => t('Google AdSense Injector'),      'title' => t('Google AdSense Injector'),
140                  'description' => t('Insert Google AdSense ads into full node views automatically.'),      'description' => t('Insert Google AdSense ads into full node views automatically.'),
141                  'callback' => 'drupal_get_form',      'callback' => 'drupal_get_form',
142                  'callback arguments' => array('adsense_injector_admin_settings'),      'callback arguments' => array('adsense_injector_admin_settings'),
143                  'access' => user_access('administer site configuration'),      'access' => user_access('administer site configuration'),
144                  'type' => MENU_NORMAL_ITEM,      'type' => MENU_NORMAL_ITEM,
145                  );      );
146          return $items;    return $items;
147  }  }
148    
149    
# Line 153  function adsense_injector_menu() { Line 153  function adsense_injector_menu() {
153  function adsense_injector_admin_settings() {  function adsense_injector_admin_settings() {
154    $form=array();    $form=array();
155    _adsense_injector_get_banner($form);    _adsense_injector_get_banner($form);
156    
157    $form['node_ad_body_insertion'] = array(    $form['node_ad_body_insertion'] = array(
158      '#type' => 'fieldset',      '#type' => 'fieldset',
159      '#collapsible' => TRUE,      '#collapsible' => TRUE,
# Line 163  function adsense_injector_admin_settings Line 163  function adsense_injector_admin_settings
163    );    );
164    
165    if (module_exists('adsense')) {    if (module_exists('adsense')) {
166      $form['node_ad_body_insertion']['adsense_injector_insert_body_ad'] =      $form['node_ad_body_insertion']['adsense_injector_insert_body_ad'] =
167        array('#type' => 'checkbox',        array('#type' => 'checkbox',
168              '#title'=> t('Insert inline ad in node body on page views'),              '#title'=> t('Insert inline ad in node body on page views'),
169              '#default_value' => variable_get('adsense_injector_insert_body_ad', ADSENSE_INJECTOR_INSERT_BODY_AD_DEFAULT),              '#default_value' => variable_get('adsense_injector_insert_body_ad', ADSENSE_INJECTOR_INSERT_BODY_AD_DEFAULT),
170              '#description' => t('Description'),              '#description' => t('Description'),
171              '#required'=>FALSE);              '#required'=>FALSE);
172    
173    
174    
175      $form['node_ad_body_insertion']['adsense_injector_body_minwords'] =      $form['node_ad_body_insertion']['adsense_injector_body_minwords'] =
176        array('#type' => 'textfield',        array('#type' => 'textfield',
177              '#title'=> t('Minimum node body word count'),              '#title'=> t('Minimum node body word count'),
178              '#default_value' => variable_get('adsense_injector_body_minwords', ADSENSE_INJECTOR_BODY_MINWORDS_DEFAULT),              '#default_value' => variable_get('adsense_injector_body_minwords', ADSENSE_INJECTOR_BODY_MINWORDS_DEFAULT),
179              '#description' => t('The minimum node body word count threshold - only inject if node body has at least this many words.'));              '#description' => t('The minimum node body word count threshold - only inject if node body has at least this many words.'));
180    
181      $form['node_ad_body_insertion']['adsense_injector_body_template'] =      $form['node_ad_body_insertion']['adsense_injector_body_template'] =
182        array('#type' => 'textarea',        array('#type' => 'textarea',
183              '#title'=> t('Node body ad insertion template'),              '#title'=> t('Node body ad insertion template'),
184              '#rows' => 5,              '#rows' => 5,
185              '#cols' => 40,              '#cols' => 40,
186              '#default_value' =>   variable_get('adsense_injector_body_template', ADSENSE_INJECTOR_BODY_INSERTION_TEMPLATE_DEFAULT),              '#default_value' =>   variable_get('adsense_injector_body_template', ADSENSE_INJECTOR_BODY_INSERTION_TEMPLATE_DEFAULT),
187              '#description' => t('Ad insertion template.  Substitution variables: %body = full node body text.  Insert adsense module filter tags.  See the <a href="/admin/settings/adsense">adsense.module settings page</a> for a list of supported formats and help with filter tags.'),              '#description' => t('Ad insertion template.  Substitution variables: %body = full node body text.  Insert adsense module filter tags.  See the <a href="/admin/settings/adsense">adsense.module settings page</a> for a list of supported formats and help with filter tags.'),
188              '#required' => TRUE);              '#required' => TRUE);
189    
190      /**      /**
191       * 'list' insertion (frontpage, taxonomy, etc.       * 'list' insertion (frontpage, taxonomy, etc.
192       */       */
193      $form['node_ad_list_insertion'] =      $form['node_ad_list_insertion'] =
194        array('#type' => 'fieldset',        array('#type' => 'fieldset',
195              '#collapsible' => TRUE,              '#collapsible' => TRUE,
196              '#collapsed' => FALSE,              '#collapsed' => FALSE,
# Line 198  function adsense_injector_admin_settings Line 198  function adsense_injector_admin_settings
198              '#description' => t('Ad insertion in node lists or other non-page view, like front page, taxonomy views.'),              '#description' => t('Ad insertion in node lists or other non-page view, like front page, taxonomy views.'),
199              );              );
200    
201      $form['node_ad_list_insertion']['adsense_injector_append_in_listview'] =      $form['node_ad_list_insertion']['adsense_injector_append_in_listview'] =
202        array('#type' => 'checkbox',        array('#type' => 'checkbox',
203              '#title'=> t('Append an ad after teaser on frontpage and taxonomy lists'),              '#title'=> t('Append an ad after teaser on frontpage and taxonomy lists'),
204              '#default_value' => variable_get('adsense_injector_append_in_listview', ADSENSE_INJECTOR_APPEND_IN_LISTVIEW_DEFAULT),              '#default_value' => variable_get('adsense_injector_append_in_listview', ADSENSE_INJECTOR_APPEND_IN_LISTVIEW_DEFAULT),
205              '#description' => t('Note: this does not currently support Views module based lists.'),              '#description' => t('Note: this does not currently support Views module based lists.'),
206              '#required'=>FALSE);              '#required'=>FALSE);
207    
208      $form['node_ad_list_insertion']['adsense_injector_listview_insertion_template'] =      $form['node_ad_list_insertion']['adsense_injector_listview_insertion_template'] =
209        array('#type' => 'textarea',        array('#type' => 'textarea',
210              '#title'=> t('List ad insertion template'),              '#title'=> t('List ad insertion template'),
211              '#rows' => 3,              '#rows' => 3,
# Line 216  function adsense_injector_admin_settings Line 216  function adsense_injector_admin_settings
216    
217      /**      /**
218       *  What kinds of nodes do we want to insert on...?       *  What kinds of nodes do we want to insert on...?
219       */       */
220    
221      $form['injection_control'] =      $form['injection_control'] =
222        array('#type' => 'fieldset',        array('#type' => 'fieldset',
223              '#collapsible' => TRUE,              '#collapsible' => TRUE,
224              '#collapsed' => TRUE,              '#collapsed' => TRUE,
# Line 234  function adsense_injector_admin_settings Line 234  function adsense_injector_admin_settings
234      foreach (node_get_types() as $type => $typeObj) {      foreach (node_get_types() as $type => $typeObj) {
235        $nodetypes[$type] = $typeObj->name;        $nodetypes[$type] = $typeObj->name;
236        $enabled = variable_get(ADSENSE_INJECTOR_INSERT_AD_NODETYPE . $type, FALSE);        $enabled = variable_get(ADSENSE_INJECTOR_INSERT_AD_NODETYPE . $type, FALSE);
237        if ($enabled) $enabled_count++;        if ($enabled) $enabled_count++;
238        $form['injection_control']['node_types'][ADSENSE_INJECTOR_INSERT_AD_NODETYPE . $type] =        $form['injection_control']['node_types'][ADSENSE_INJECTOR_INSERT_AD_NODETYPE . $type] =
239          array('#type' => 'checkbox',          array('#type' => 'checkbox',
240                '#title'=> $typeObj->name,                '#title'=> $typeObj->name,
241                '#default_value' => $enabled,                '#default_value' => $enabled,
242                '#description' => t('Display inline ads on %nodetype nodes', array('%nodetype' => $typeObj->name)),                '#description' => t('Display inline ads on %nodetype nodes', array('%nodetype' => $typeObj->name)),
243                '#required'=>FALSE);                '#required'=>FALSE);
244    
245      }      }
246    
247      // do some sanity checking      // do some sanity checking
# Line 249  function adsense_injector_admin_settings Line 249  function adsense_injector_admin_settings
249        $msg = t('No node types selected (no ads will be inserted because you haven\'t selected any node types for automatic ad insertion.)');        $msg = t('No node types selected (no ads will be inserted because you haven\'t selected any node types for automatic ad insertion.)');
250        //      form_set_error('injection_control][node_types', $msg);        //      form_set_error('injection_control][node_types', $msg);
251        $form['injection_control']['#collapsed'] = FALSE;        $form['injection_control']['#collapsed'] = FALSE;
252        $form['injection_control']['no_nodes_enabled']        $form['injection_control']['no_nodes_enabled']
253          = array('#type' => 'markup',          = array('#type' => 'markup',
254                  '#weight' => -1,                  '#weight' => -1,
255                  '#value' => '<div id="message"><div class="messages error"><strong>' . $msg . '</strong></div></div>');                  '#value' => '<div id="message"><div class="messages error"><strong>' . $msg . '</strong></div></div>');
256      }      }
# Line 265  function adsense_injector_admin_settings Line 265  function adsense_injector_admin_settings
265  function _adsense_injector_get_banner(&$form) {  function _adsense_injector_get_banner(&$form) {
266    $name = 'adsense_injector-d5';    $name = 'adsense_injector-d5';
267    $d = '<a target="_blank" href="https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&business=exodus.paypal%40gmail.com&item_name=' . $name . '&item_number= ' . $name . '-donation&page_style=PayPal&no_shipping=1&return=http%3A%2F%2Fexodusdev.com%2Fproducts&cancel_return=http%3A%2F%2Fexodusdev.com%2Fproducts&no_note=1&tax=0&currency_code=USD&lc=US&bn=PP%2dDonationsBF&charset=UTF%2d8"><img src="http://www.paypal.com/en_US/i/btn/x-click-but7.gif" alt="Your donations support ongoing development" title="Your donations support ongoing development"></a>';    $d = '<a target="_blank" href="https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&business=exodus.paypal%40gmail.com&item_name=' . $name . '&item_number= ' . $name . '-donation&page_style=PayPal&no_shipping=1&return=http%3A%2F%2Fexodusdev.com%2Fproducts&cancel_return=http%3A%2F%2Fexodusdev.com%2Fproducts&no_note=1&tax=0&currency_code=USD&lc=US&bn=PP%2dDonationsBF&charset=UTF%2d8"><img src="http://www.paypal.com/en_US/i/btn/x-click-but7.gif" alt="Your donations support ongoing development" title="Your donations support ongoing development"></a>';
268    $form['module_banner'] = array('#type' => 'markup',    $form['module_banner'] = array('#type' => 'markup',
269                                   '#value' => '<div style="border: solid 1px #eee; margin: .5em; padding: .5em;"><div style="float:right;">' . $d . '</div><strong>Module development sponsored by <a href="http://exodusdev.com">Exodus Development</a></strong><br/>');                                   '#value' => '<div style="border: solid 1px #eee; margin: .5em; padding: .5em;"><div style="float:right;">' . $d . '</div><strong>Module development sponsored by <a href="http://exodusdev.com">Exodus Development</a></strong><br/>');
270    $form['module_id'] = array('#type' => 'markup', '#value' => ADSENSE_INJECTOR_MODULE_VERSION . '<br/></div>');    $form['module_id'] = array('#type' => 'markup', '#value' => ADSENSE_INJECTOR_MODULE_VERSION . '<br/></div>');
271  }  }

Legend:
Removed from v.1.1.2.7  
changed lines
  Added in v.1.1.2.8

  ViewVC Help
Powered by ViewVC 1.1.3