Index: adsense_injector.admin.inc =================================================================== RCS file: adsense_injector.admin.inc diff -N adsense_injector.admin.inc --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ adsense_injector.admin.inc 16 Dec 2008 03:34:49 -0000 @@ -0,0 +1,133 @@ + 'fieldset', + '#collapsible' => TRUE, + '#collapsed' => FALSE, + '#title' => t('Node body ad insertion'), + '#description' => t('Requires adsense.module'), + ); + + if (module_exists('adsense')) { + $form['node_ad_body_insertion']['adsense_injector_insert_body_ad'] = array( + '#type' => 'checkbox', + '#title' => t('Insert inline ad in node body on page views'), + '#default_value' => variable_get('adsense_injector_insert_body_ad', ADSENSE_INJECTOR_INSERT_BODY_AD_DEFAULT), + '#description' => t('Description'), + '#required' => FALSE, + ); + $form['node_ad_body_insertion']['adsense_injector_body_minwords'] = array( + '#type' => 'textfield', + '#title' => t('Minimum node body word count'), + '#default_value' => variable_get('adsense_injector_body_minwords', ADSENSE_INJECTOR_BODY_MINWORDS_DEFAULT), + '#description' => t('The minimum node body word count threshold - only inject if node body has at least this many words.'), + ); + $form['node_ad_body_insertion']['adsense_injector_body_template'] = array( + '#type' => 'textarea', + '#title' => t('Node body ad insertion template'), + '#rows' => 5, + '#cols' => 40, + '#default_value' => variable_get('adsense_injector_body_template', ADSENSE_INJECTOR_BODY_INSERTION_TEMPLATE_DEFAULT), + '#description' => t('Ad insertion template. Substitution variables: %body = full node body text. Insert adsense module filter tags. See the adsense.module settings page for a list of supported formats and help with filter tags.'), + '#required' => TRUE, + ); + + /** + * 'list' insertion (frontpage, taxonomy, etc). + */ + $form['node_ad_list_insertion'] = array( + '#type' => 'fieldset', + '#collapsible' => TRUE, + '#collapsed' => FALSE, + '#title' => t('Node list ad insertion'), + '#description' => t('Ad insertion in node lists or other non-page view, like front page, taxonomy views.'), + ); + $form['node_ad_list_insertion']['adsense_injector_append_in_listview'] = array( + '#type' => 'checkbox', + '#title' => t('Append an ad after teaser on frontpage and taxonomy lists'), + '#default_value' => variable_get('adsense_injector_append_in_listview', ADSENSE_INJECTOR_APPEND_IN_LISTVIEW_DEFAULT), + '#description' => t('Note: this does not currently support Views module based lists.'), + '#required' => FALSE, + ); + $form['node_ad_list_insertion']['adsense_injector_listview_insertion_template'] = array( + '#type' => 'textarea', + '#title' => t('List ad insertion template'), + '#rows' => 3, + '#cols' => 40, + '#default_value' => variable_get('adsense_injector_listview_insertion_template', ADSENSE_INJECTOR_LISTVIEW_INSERTION_TEMPLATE_DEFAULT), + '#description' => t('Template to use when inserting adsense ad. "%teaser" will be replaced with the node teaser. Insert adsense filter tags. See the adsense.module settings page for a list of supported formats and help with filter tags.'), + '#required' => TRUE, + ); + + /** + * What kinds of nodes do we want to insert on...? + */ + $form['injection_control'] = array( + '#type' => 'fieldset', + '#collapsible' => TRUE, + '#collapsed' => TRUE, + '#title' => t('Select Node Types for Insertion'), + '#description' => t('Nodes types to display inline ads - ads are inserted only in the selected node types.'), + ); + + /** + * Enumerate node types, and set up form fields for each + */ + $enabled_count = 0; + $nodetypes = array(); + foreach (node_get_types() as $type => $obj) { + $nodetypes[$type] = $obj->name; + $enabled = variable_get(ADSENSE_INJECTOR_INSERT_AD_NODETYPE . $type, FALSE); + if ($enabled) $enabled_count++; + $form['injection_control']['node_types'][ADSENSE_INJECTOR_INSERT_AD_NODETYPE . $type] = array('#type' => 'checkbox', + '#title' => $obj->name, + '#default_value' => $enabled, + '#description' => t('Display inline ads on %nodetype nodes', array('%nodetype' => $obj->name)), + '#required' => FALSE, + ); + } + + // Do some sanity checking. + if ($enabled_count == 0) { + $msg = t('No node types selected (no ads will be inserted because you haven\'t selected any node types for automatic ad insertion.)'); + $form['injection_control']['#collapsed'] = FALSE; + $form['injection_control']['no_nodes_enabled'] = array( + '#type' => 'markup', + '#weight' => -1, + '#value' => '
'. $msg .'
', + ); + } + } + + return system_settings_form($form); +} + +/** + * Get settings 'banner'. + */ +function _adsense_injector_get_banner(&$form) { + $name = 'adsense_injector-d5'; + $banner = 'Your donations support ongoing development'; + + $form['module_banner'] = array( + '#type' => 'markup', + '#value' => '
'. $banner .'
Module development sponsored by Exodus Development
', + ); + $form['module_id'] = array( + '#type' => 'markup', + '#value' => ADSENSE_INJECTOR_MODULE_VERSION .'
', + ); +} Index: adsense_injector.info =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/adsense_injector/Attic/adsense_injector.info,v retrieving revision 1.1.2.2 diff -u -p -r1.1.2.2 adsense_injector.info --- adsense_injector.info 9 Feb 2007 05:38:19 -0000 1.1.2.2 +++ adsense_injector.info 16 Dec 2008 03:34:49 -0000 @@ -1,10 +1,7 @@ ; $Id: adsense_injector.info,v 1.1.2.2 2007/02/09 05:38:19 inactivist Exp $ name = AdSense Injector description = Insert adsense ads into full-page node view, and front page or other list views automatically. -dependencies = adsense -package = "Site Advertising" - -; Information added by drupal.org packaging script on 2006-12-14 -version = "5.0" -project = "adsense_injector" - +dependencies[] = adsense +package = Adsense +version = 6.x-1.x-dev +core = 6.x Index: adsense_injector.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/adsense_injector/adsense_injector.module,v retrieving revision 1.1.2.6 diff -u -p -r1.1.2.6 adsense_injector.module --- adsense_injector.module 6 Apr 2007 16:05:55 -0000 1.1.2.6 +++ adsense_injector.module 16 Dec 2008 03:34:49 -0000 @@ -1,32 +1,31 @@ body field. + * + * It uses a very simple scheme at present (just string concatenation) + * and could be enhanced greatly by using regular expressions, templates, + * or other techniques in a later revision. + */ - /** - * Inject adsense ads into node content automatically. - * - * Copyright (c) 2006, 2007 Exodus Development, Inc. All Rights Reserved. - * Licensed under the terms of the GNU Public License (GPL) version 2. Please see LICENSE.txt for - * license terms. Posession and use of this code signifies acceptance of license - * terms. - * - * Visit Exodus Development at - * http://exodusdev.com exodusdev@gmail.com - * - * Project homepage: - * http://exodusdev.com/drupal/4.7/modules/adsense_injector.module - * - * The purpose of this module is to provide a simple method of automatically placing 'inline' - * adsense module content into a full-page view of selected node types. - * It does this by intercepting node rendering using hook_nodeapi during 'page' rendering, - * and injecting selected text into the $node->body field. - * - * It uses a very simple scheme at present (just string concatenation) - * and could be enhanced greatly by using regular expressions, templates, - * or other techniques in a later revision. - */ - -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.6 2007/04/06 16:05:55 inactivist Exp $'); define('ADSENSE_INJECTOR_INSERT_BODY_AD_DEFAULT', TRUE); define('ADSENSE_INJECTOR_BODY_INSERTION_TEMPLATE_DEFAULT', '
[adsense:120x240:1:1]
%body
[adsense:468x60:1:1]'); @@ -37,217 +36,104 @@ define('ADSENSE_INJECTOR_LISTVIEW_INSERT /** * Prefix for variable table entries - append node type name, store as boolean - * value, nonzero means insert ad content + * value, nonzero means insert ad content. */ - define('ADSENSE_INJECTOR_INSERT_AD_NODETYPE', 'adsense_injector_nodetype_'); /** * Count words in a string. - * @param $str ref to a string (ref so no copy) - * @param $max max # of words we care about. Return value will never exceed this. - * @return the count of words, where delimiter is one or more spaces + * + * @param $str + * Target string. + * @param $max + * Maximum number of words we care about. Return value will never exceed + * this. + * @return + * The count of words, where delimiter is one or more spaces. * @todo Efficiency, find better way to do this */ -function _adsense_injector_count_words(&$str, $max) { - return count(explode(' ', $str, $max)); // lifted from node.module node_validate() function. +function _adsense_injector_count_words($str, $max) { + // lifted from node.module node_validate() function. + return count(explode(' ', $str, $max)); } /** - * Get the minimum node body wordcount for insertion. - * May be content-type specific, but at present, it's - * global to all node types. - * @param $nodetype the node type - * @param $defval the default value - * @return The minimum insertion wordcount + * Get the minimum node body wordcount for insertion. + * + * May be content-type specific, but at present, it's global to all node + * types. + * + * @param $nodetype + * The node type. + * @param $defval + * The default value. + * @return + * The minimum insertion wordcount. */ -function _adsense_injector_minwords_cfg($nodetype, $defval=75) { +function _adsense_injector_minwords_cfg($nodetype, $defval = 75) { return variable_get('adsense_injector_body_minwords', $defval); } /** - * Implementation of hook_nodeapi. + * Implementation of hook_nodeapi(). + * * If rendering a full page, and the node type one of the configured types, * inject configured adsense content using simple string concatenation. + * * @todo: Evaluate efficiency of string concat vs. sprintf, other methods. - */ + */ function adsense_injector_nodeapi(&$node, $op, $teaser, $page) { // insert an ad into the body. - if (module_exists('adsense') && _adsense_page_match() && variable_get(ADSENSE_INJECTOR_INSERT_AD_NODETYPE . $node->type, FALSE)) { - if ($op == 'view') { + if ($op == 'alter') { + if (module_exists('adsense') && _adsense_page_match() && variable_get(ADSENSE_INJECTOR_INSERT_AD_NODETYPE . $node->type, FALSE)) { if ($page) { if (variable_get('adsense_injector_insert_body_ad', ADSENSE_INJECTOR_INSERT_BODY_AD_DEFAULT)) { + $_body = $node->body; $minwords = _adsense_injector_minwords_cfg($node->type); - $oldBody = $node->content['body']['#value']; - $wordcount = _adsense_injector_count_words($oldBody, $minwords); + $wordcount = _adsense_injector_count_words($_body, $minwords); if ($wordcount >= $minwords) { $template = variable_get('adsense_injector_body_template', ADSENSE_INJECTOR_BODY_INSERTION_TEMPLATE_DEFAULT); - // Process adsense module tags in the template text, if enabled and possible + // Process adsense module tags in the template text, if enabled and possible. if (function_exists('_adsense_process_tags')) { $template = _adsense_process_tags($template); } else { - watchdog('adsense_injector', t('adsense module function _adsense_process_tags() not found'), WATCHDOG_ERROR); + watchdog('adsense_injector', 'adsense module function _adsense_process_tags() not found', WATCHDOG_ERROR); } - $node->body = - $node->content['body']['#value'] = strtr($template, array('%body' => $oldBody)); - } else { - $node->content['body']['#value'] = "" . $oldBody; + $node->body = strtr($template, array('%body' => $_body)); + } + else { + $node->body = "" . $_body; } } } - else if ($teaser - && variable_get('adsense_injector_append_in_listview', ADSENSE_INJECTOR_APPEND_IN_LISTVIEW_DEFAULT)) { + elseif ($teaser && variable_get('adsense_injector_append_in_listview', ADSENSE_INJECTOR_APPEND_IN_LISTVIEW_DEFAULT)) { $template = variable_get('adsense_injector_listview_insertion_template', ADSENSE_INJECTOR_LISTVIEW_INSERTION_TEMPLATE_DEFAULT); - // Process adsense module tags in the template text, if enabled and possible + // Process adsense module tags in the template text, if enabled and possible. if (function_exists('_adsense_process_tags')) { $template = _adsense_process_tags($template); } else { - watchdog('adsense_injector', t('adsense module function _adsense_process_tags() not found'), WATCHDOG_ERROR); + watchdog('adsense_injector', 'adsense module function _adsense_process_tags() not found', WATCHDOG_ERROR); } - $node->content['body']['#value'] = strtr($template, array('%teaser' => $node->teaser)); + $node->body = strtr($template, array('%teaser' => $node->teaser)); } } } } /** - * Implementation of hook_menu + * Implementation of hook_menu(). */ function adsense_injector_menu() { - $items[] = array( - 'path' => 'admin/settings/adsense_injector', - 'title' => t('Google AdSense Injector'), - 'description' => t('Insert Google AdSense ads into full node views automatically.'), - 'callback' => 'drupal_get_form', - 'callback arguments' => array('adsense_injector_admin_settings'), - 'access' => user_access('administer site configuration'), - 'type' => MENU_NORMAL_ITEM, - ); - return $items; -} - - -/** - * Implementation of hook_settings - */ -function adsense_injector_admin_settings() { - $form=array(); - _adsense_injector_get_banner($form); - - $form['node_ad_body_insertion'] = array( - '#type' => 'fieldset', - '#collapsible' => TRUE, - '#collapsed' => FALSE, - '#title' => t('Node body ad insertion'), - '#description' => t('Requires adsense.module'), + $items['admin/settings/adsense_injector'] = array( + 'title' => 'AdSense Injector', + 'description' => 'Insert Google AdSense ads into full node views automatically.', + 'page callback' => 'drupal_get_form', + 'page arguments' => array('adsense_injector_admin_settings'), + 'access arguments' => array('administer site configuration'), + 'file' => 'adsense_injector.admin.inc', + 'type' => MENU_NORMAL_ITEM, ); - - if (module_exists('adsense')) { - $form['node_ad_body_insertion']['adsense_injector_insert_body_ad'] = - array('#type' => 'checkbox', - '#title'=> t('Insert inline ad in node body on page views'), - '#default_value' => variable_get('adsense_injector_insert_body_ad', ADSENSE_INJECTOR_INSERT_BODY_AD_DEFAULT), - '#description' => t('Description'), - '#required'=>FALSE); - - - - $form['node_ad_body_insertion']['adsense_injector_body_minwords'] = - array('#type' => 'textfield', - '#title'=> t('Minimum node body word count'), - '#default_value' => variable_get('adsense_injector_body_minwords', ADSENSE_INJECTOR_BODY_MINWORDS_DEFAULT), - '#description' => t('The minimum node body word count threshold - only inject if node body has at least this many words.')); - - $form['node_ad_body_insertion']['adsense_injector_body_template'] = - array('#type' => 'textarea', - '#title'=> t('Node body ad insertion template'), - '#rows' => 5, - '#cols' => 40, - '#default_value' => variable_get('adsense_injector_body_template', ADSENSE_INJECTOR_BODY_INSERTION_TEMPLATE_DEFAULT), - '#description' => t('Ad insertion template. Substitution variables: %body = full node body text. Insert adsense module filter tags. See the adsense.module settings page for a list of supported formats and help with filter tags.'), - '#required' => TRUE); - - /** - * 'list' insertion (frontpage, taxonomy, etc. - */ - $form['node_ad_list_insertion'] = - array('#type' => 'fieldset', - '#collapsible' => TRUE, - '#collapsed' => FALSE, - '#title' => t('Node list ad insertion'), - '#description' => t('Ad insertion in node lists or other non-page view, like front page, taxonomy views.'), - ); - - $form['node_ad_list_insertion']['adsense_injector_append_in_listview'] = - array('#type' => 'checkbox', - '#title'=> t('Append an ad after teaser on frontpage and taxonomy lists'), - '#default_value' => variable_get('adsense_injector_append_in_listview', ADSENSE_INJECTOR_APPEND_IN_LISTVIEW_DEFAULT), - '#description' => t('Note: this does not currently support Views module based lists.'), - '#required'=>FALSE); - - $form['node_ad_list_insertion']['adsense_injector_listview_insertion_template'] = - array('#type' => 'textarea', - '#title'=> t('List ad insertion template'), - '#rows' => 3, - '#cols' => 40, - '#default_value' => variable_get('adsense_injector_listview_insertion_template', ADSENSE_INJECTOR_LISTVIEW_INSERTION_TEMPLATE_DEFAULT), - '#description' => t('Template to use when inserting adsense ad. "%teaser" will be replaced with the node teaser. Insert adsense filter tags. See the adsense.module settings page for a list of supported formats and help with filter tags.'), - '#required' => TRUE); - - /** - * What kinds of nodes do we want to insert on...? - */ - - $form['injection_control'] = - array('#type' => 'fieldset', - '#collapsible' => TRUE, - '#collapsed' => TRUE, - '#title' => t('Select Node Types for Insertion'), - '#description' => t('Nodes types to display inline ads - ads are inserted only in the selected node types.'), - ); - - /** - * Enumerate node types, and set up form fields for each - */ - $enabled_count = 0; - $nodetypes = array(); - foreach (node_get_types() as $type => $typeObj) { - $nodetypes[$type] = $typeObj->name; - $enabled = variable_get(ADSENSE_INJECTOR_INSERT_AD_NODETYPE . $type, FALSE); - if ($enabled) $enabled_count++; - $form['injection_control']['node_types'][ADSENSE_INJECTOR_INSERT_AD_NODETYPE . $type] = - array('#type' => 'checkbox', - '#title'=> $typeObj->name, - '#default_value' => $enabled, - '#description' => t('Display inline ads on %nodetype nodes', array('%nodetype' => $typeObj->name)), - '#required'=>FALSE); - - } - - // do some sanity checking - if ($enabled_count == 0) { - $msg = t('No node types selected (no ads will be inserted because you haven\'t selected any node types for automatic ad insertion.)'); - // form_set_error('injection_control][node_types', $msg); - $form['injection_control']['#collapsed'] = FALSE; - $form['injection_control']['no_nodes_enabled'] - = array('#type' => 'markup', - '#weight' => -1, - '#value' => '
' . $msg . '
'); - } - - } - return system_settings_form($form); -} - -/** - * Get settings 'banner' - */ -function _adsense_injector_get_banner(&$form) { - $name = 'adsense_injector-d5'; - $d = 'Your donations support ongoing development'; - $form['module_banner'] = array('#type' => 'markup', - '#value' => '
' . $d . '
Module development sponsored by Exodus Development
'); - $form['module_id'] = array('#type' => 'markup', '#value' => ADSENSE_INJECTOR_MODULE_VERSION . '
'); + return $items; }