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

Contents of /contributions/modules/adsense_injector/adsense_injector.module

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


Revision 1.5 - (show annotations) (download) (as text)
Fri Jan 2 03:01:24 2009 UTC (10 months, 3 weeks ago) by hswong3i
Branch: MAIN
CVS Tags: HEAD
Changes since 1.4: +3 -1 lines
File MIME type: text/x-php
- sync with 6.x-2.x-dev
1 <?php
2 // $Id: adsense_injector.module,v 1.1.2.6.2.3.2.6 2009/01/02 03:00:26 hswong3i Exp $
3
4 /**
5 * @file
6 * Inject adsense ads into node content automatically.
7 *
8 * @ingroup adsense_injector
9 */
10
11 /**
12 * Implementation of hook_nodeapi().
13 *
14 * If rendering a full page, and the node type one of the configured types,
15 * inject configured adsense content using simple string concatenation.
16 *
17 * @todo: Evaluate efficiency of string concat vs. sprintf, other methods.
18 */
19 function adsense_injector_nodeapi(&$node, $op, $teaser, $page) {
20 // We only consider content types which are enabled for inline adsense.
21 $node_types = variable_get('adsense_injector_nodes', array());
22 if (empty($node_types[$node->type])) {
23 return;
24 }
25
26 // insert an ad into the body.
27 if ($op == 'alter') {
28 if ($page && variable_get('adsense_injector_body_view', TRUE)) {
29 // Get the minimum node body wordcount for insertion.
30 $minwords = variable_get('adsense_injector_body_view_minwords', 75);
31 // Count words in a string.
32 // lifted from node.module node_validate() function.
33 $wordcount = count(explode(' ', $node->body, $minwords));
34 if ($wordcount >= $minwords) {
35 // Process adsense module tags in the template text, if enabled and possible.
36 $template = _adsense_process_tags(variable_get('adsense_injector_body_view_template', '<div style="float: right; margin: 0; padding: 0 1em .25em 0;">[adsense:250x250:0123456789]</div>%body<br class="clear"/>[adsense:728x90:0123456789]'));
37 $node->body = strtr($template, array('%body' => $node->body));
38 }
39 else {
40 $node->body .= "<!-- adsense_injector: node body word count ($wordcount) is insufficient ($minwords required), so we won't insert an ad. -->";
41 }
42 }
43 elseif ($teaser && variable_get('adsense_injector_list_view', FALSE)) {
44 // Process adsense module tags in the template text, if enabled and possible.
45 $template = _adsense_process_tags(variable_get('adsense_injector_list_view_template', '%teaser<br class="clear"/>[adsense:728x90:0123456789]'));
46 $node->teaser = strtr($template, array('%teaser' => $node->teaser));
47 }
48 }
49 }
50
51 /**
52 * Implementation of hook_menu().
53 */
54 function adsense_injector_menu() {
55 $items['admin/settings/adsense_injector'] = array(
56 'title' => 'AdSense Injector',
57 'description' => 'Insert Google AdSense ads into full node views automatically.',
58 'page callback' => 'drupal_get_form',
59 'page arguments' => array('adsense_injector_admin_settings'),
60 'access arguments' => array('administer site configuration'),
61 'file' => 'adsense_injector.admin.inc',
62 'type' => MENU_NORMAL_ITEM,
63 );
64 return $items;
65 }

  ViewVC Help
Powered by ViewVC 1.1.2