| 1 |
<?php |
<?php |
| 2 |
// $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.6.2.3 2008/12/16 09:28:12 hswong3i Exp $ |
| 3 |
|
|
| 4 |
/** |
/** |
| 5 |
|
* @file |
| 6 |
* Inject adsense ads into node content automatically. |
* 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. |
|
| 7 |
*/ |
*/ |
| 8 |
|
|
|
define('ADSENSE_INJECTOR_MODULE_VERSION', '$Id: adsense_injector.module,v 1.1.2.6 2007/04/06 16:05:55 inactivist Exp $'); |
|
| 9 |
define('ADSENSE_INJECTOR_INSERT_BODY_AD_DEFAULT', TRUE); |
define('ADSENSE_INJECTOR_INSERT_BODY_AD_DEFAULT', TRUE); |
|
|
|
| 10 |
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]'); |
| 11 |
define('ADSENSE_INJECTOR_BODY_MINWORDS_DEFAULT', 75); |
define('ADSENSE_INJECTOR_BODY_MINWORDS_DEFAULT', 75); |
|
|
|
| 12 |
define('ADSENSE_INJECTOR_APPEND_IN_LISTVIEW_DEFAULT', FALSE); |
define('ADSENSE_INJECTOR_APPEND_IN_LISTVIEW_DEFAULT', FALSE); |
| 13 |
define('ADSENSE_INJECTOR_LISTVIEW_INSERTION_TEMPLATE_DEFAULT', '%teaser<div class="adsense-injector-list-ad">[adsense:468x60:1:1]</div>'); |
define('ADSENSE_INJECTOR_LISTVIEW_INSERTION_TEMPLATE_DEFAULT', '%teaser<div class="adsense-injector-list-ad">[adsense:468x60:1:1]</div>'); |
| 14 |
|
|
| 28 |
* this. |
* this. |
| 29 |
* @return |
* @return |
| 30 |
* The count of words, where delimiter is one or more spaces. |
* The count of words, where delimiter is one or more spaces. |
| 31 |
* @todo Efficiency, find better way to do this |
* @todo Efficiency, find better way to do this. |
| 32 |
*/ |
*/ |
| 33 |
function _adsense_injector_count_words($str, $max) { |
function _adsense_injector_count_words($str, $max) { |
| 34 |
// lifted from node.module node_validate() function. |
// lifted from node.module node_validate() function. |
| 66 |
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)) { |
| 67 |
if ($page) { |
if ($page) { |
| 68 |
if (variable_get('adsense_injector_insert_body_ad', ADSENSE_INJECTOR_INSERT_BODY_AD_DEFAULT)) { |
if (variable_get('adsense_injector_insert_body_ad', ADSENSE_INJECTOR_INSERT_BODY_AD_DEFAULT)) { |
| 69 |
$_body = $node->body; |
$body = $node->body; |
| 70 |
$minwords = _adsense_injector_minwords_cfg($node->type); |
$minwords = _adsense_injector_minwords_cfg($node->type); |
| 71 |
$wordcount = _adsense_injector_count_words($_body, $minwords); |
$wordcount = _adsense_injector_count_words($body, $minwords); |
| 72 |
if ($wordcount >= $minwords) { |
if ($wordcount >= $minwords) { |
| 73 |
$template = variable_get('adsense_injector_body_template', ADSENSE_INJECTOR_BODY_INSERTION_TEMPLATE_DEFAULT); |
$template = variable_get('adsense_injector_body_template', ADSENSE_INJECTOR_BODY_INSERTION_TEMPLATE_DEFAULT); |
| 74 |
// Process adsense module tags in the template text, if enabled and possible. |
// Process adsense module tags in the template text, if enabled and possible. |
| 78 |
else { |
else { |
| 79 |
watchdog('adsense_injector', 'adsense module function _adsense_process_tags() not found', WATCHDOG_ERROR); |
watchdog('adsense_injector', 'adsense module function _adsense_process_tags() not found', WATCHDOG_ERROR); |
| 80 |
} |
} |
| 81 |
$node->body = strtr($template, array('%body' => $_body)); |
$node->body = strtr($template, array('%body' => $body)); |
| 82 |
} |
} |
| 83 |
else { |
else { |
| 84 |
$node->body = "<!-- adsense_injector: node body word count ($wordcount) is insufficient ($minwords required), so we won't insert an ad. -->" . $_body; |
$node->body = "<!-- adsense_injector: node body word count ($wordcount) is insufficient ($minwords required), so we won't insert an ad. -->". $body; |
| 85 |
} |
} |
| 86 |
} |
} |
| 87 |
} |
} |