| 1 |
|
<?php |
| 2 |
|
// $Id$ |
| 3 |
|
|
| 4 |
|
/** |
| 5 |
|
* @file |
| 6 |
|
* Administrative page callbacks for the adsense_injector module. |
| 7 |
|
*/ |
| 8 |
|
|
| 9 |
|
/** |
| 10 |
|
* Implementation of hook_settings(). |
| 11 |
|
*/ |
| 12 |
|
function adsense_injector_admin_settings() { |
| 13 |
|
$form = array(); |
| 14 |
|
|
| 15 |
|
$form['node_ad_body_insertion'] = array( |
| 16 |
|
'#type' => 'fieldset', |
| 17 |
|
'#collapsible' => TRUE, |
| 18 |
|
'#collapsed' => FALSE, |
| 19 |
|
'#title' => t('Node body ad insertion'), |
| 20 |
|
'#description' => t('Requires adsense.module'), |
| 21 |
|
); |
| 22 |
|
|
| 23 |
|
if (module_exists('adsense')) { |
| 24 |
|
$form['node_ad_body_insertion']['adsense_injector_insert_body_ad'] = array( |
| 25 |
|
'#type' => 'checkbox', |
| 26 |
|
'#title' => t('Insert inline ad in node body on page views'), |
| 27 |
|
'#default_value' => variable_get('adsense_injector_insert_body_ad', ADSENSE_INJECTOR_INSERT_BODY_AD_DEFAULT), |
| 28 |
|
'#description' => t('Description'), |
| 29 |
|
'#required' => FALSE, |
| 30 |
|
); |
| 31 |
|
$form['node_ad_body_insertion']['adsense_injector_body_minwords'] = array( |
| 32 |
|
'#type' => 'textfield', |
| 33 |
|
'#title' => t('Minimum node body word count'), |
| 34 |
|
'#default_value' => variable_get('adsense_injector_body_minwords', ADSENSE_INJECTOR_BODY_MINWORDS_DEFAULT), |
| 35 |
|
'#description' => t('The minimum node body word count threshold - only inject if node body has at least this many words.'), |
| 36 |
|
); |
| 37 |
|
$form['node_ad_body_insertion']['adsense_injector_body_template'] = array( |
| 38 |
|
'#type' => 'textarea', |
| 39 |
|
'#title' => t('Node body ad insertion template'), |
| 40 |
|
'#rows' => 5, |
| 41 |
|
'#cols' => 40, |
| 42 |
|
'#default_value' => variable_get('adsense_injector_body_template', ADSENSE_INJECTOR_BODY_INSERTION_TEMPLATE_DEFAULT), |
| 43 |
|
'#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.'), |
| 44 |
|
'#required' => TRUE, |
| 45 |
|
); |
| 46 |
|
|
| 47 |
|
/** |
| 48 |
|
* 'list' insertion (frontpage, taxonomy, etc). |
| 49 |
|
*/ |
| 50 |
|
$form['node_ad_list_insertion'] = array( |
| 51 |
|
'#type' => 'fieldset', |
| 52 |
|
'#collapsible' => TRUE, |
| 53 |
|
'#collapsed' => FALSE, |
| 54 |
|
'#title' => t('Node list ad insertion'), |
| 55 |
|
'#description' => t('Ad insertion in node lists or other non-page view, like front page, taxonomy views.'), |
| 56 |
|
); |
| 57 |
|
$form['node_ad_list_insertion']['adsense_injector_append_in_listview'] = array( |
| 58 |
|
'#type' => 'checkbox', |
| 59 |
|
'#title' => t('Append an ad after teaser on frontpage and taxonomy lists'), |
| 60 |
|
'#default_value' => variable_get('adsense_injector_append_in_listview', ADSENSE_INJECTOR_APPEND_IN_LISTVIEW_DEFAULT), |
| 61 |
|
'#description' => t('Note: this does not currently support Views module based lists.'), |
| 62 |
|
'#required' => FALSE, |
| 63 |
|
); |
| 64 |
|
$form['node_ad_list_insertion']['adsense_injector_listview_insertion_template'] = array( |
| 65 |
|
'#type' => 'textarea', |
| 66 |
|
'#title' => t('List ad insertion template'), |
| 67 |
|
'#rows' => 3, |
| 68 |
|
'#cols' => 40, |
| 69 |
|
'#default_value' => variable_get('adsense_injector_listview_insertion_template', ADSENSE_INJECTOR_LISTVIEW_INSERTION_TEMPLATE_DEFAULT), |
| 70 |
|
'#description' => t('Template to use when inserting adsense ad. "%teaser" will be replaced with the node teaser. Insert adsense 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.'), |
| 71 |
|
'#required' => TRUE, |
| 72 |
|
); |
| 73 |
|
|
| 74 |
|
/** |
| 75 |
|
* What kinds of nodes do we want to insert on...? |
| 76 |
|
*/ |
| 77 |
|
$form['injection_control'] = array( |
| 78 |
|
'#type' => 'fieldset', |
| 79 |
|
'#collapsible' => TRUE, |
| 80 |
|
'#collapsed' => TRUE, |
| 81 |
|
'#title' => t('Select Node Types for Insertion'), |
| 82 |
|
'#description' => t('Nodes types to display inline ads - ads are inserted <strong>only</strong> in the selected node types.'), |
| 83 |
|
); |
| 84 |
|
|
| 85 |
|
/** |
| 86 |
|
* Enumerate node types, and set up form fields for each |
| 87 |
|
*/ |
| 88 |
|
$enabled_count = 0; |
| 89 |
|
$nodetypes = array(); |
| 90 |
|
foreach (node_get_types() as $type => $obj) { |
| 91 |
|
$nodetypes[$type] = $obj->name; |
| 92 |
|
$enabled = variable_get(ADSENSE_INJECTOR_INSERT_AD_NODETYPE . $type, FALSE); |
| 93 |
|
if ($enabled) $enabled_count++; |
| 94 |
|
$form['injection_control']['node_types'][ADSENSE_INJECTOR_INSERT_AD_NODETYPE . $type] = array('#type' => 'checkbox', |
| 95 |
|
'#title' => $obj->name, |
| 96 |
|
'#default_value' => $enabled, |
| 97 |
|
'#description' => t('Display inline ads on %nodetype nodes', array('%nodetype' => $obj->name)), |
| 98 |
|
'#required' => FALSE, |
| 99 |
|
); |
| 100 |
|
} |
| 101 |
|
|
| 102 |
|
// Do some sanity checking. |
| 103 |
|
if ($enabled_count == 0) { |
| 104 |
|
$msg = t('No node types selected (no ads will be inserted because you haven\'t selected any node types for automatic ad insertion.)'); |
| 105 |
|
$form['injection_control']['#collapsed'] = FALSE; |
| 106 |
|
$form['injection_control']['no_nodes_enabled'] = array( |
| 107 |
|
'#type' => 'markup', |
| 108 |
|
'#weight' => -1, |
| 109 |
|
'#value' => '<div id="message"><div class="messages error"><strong>'. $msg .'</strong></div></div>', |
| 110 |
|
); |
| 111 |
|
} |
| 112 |
|
} |
| 113 |
|
|
| 114 |
|
return system_settings_form($form); |
| 115 |
|
} |