| 1 |
<?php |
<?php |
| 2 |
// $Id: adsense_injector.admin.inc,v 1.1.2.3 2008/12/16 09:25:58 hswong3i Exp $ |
// $Id: adsense_injector.admin.inc,v 1.1.2.3.2.3 2008/12/17 09:56:09 hswong3i Exp $ |
| 3 |
|
|
| 4 |
/** |
/** |
| 5 |
* @file |
* @file |
| 10 |
* Implementation of hook_settings(). |
* Implementation of hook_settings(). |
| 11 |
*/ |
*/ |
| 12 |
function adsense_injector_admin_settings() { |
function adsense_injector_admin_settings() { |
| 13 |
$form = array(); |
// 'body view' insertion (i.e. show with node complete view). |
| 14 |
|
$form['body_view'] = array( |
|
$form['node_ad_body_insertion'] = array( |
|
| 15 |
'#type' => 'fieldset', |
'#type' => 'fieldset', |
| 16 |
'#collapsible' => TRUE, |
'#collapsible' => TRUE, |
| 17 |
'#collapsed' => FALSE, |
'#collapsed' => FALSE, |
| 18 |
'#title' => t('Node body ad insertion'), |
'#title' => t('Node body ad insertion'), |
| 19 |
'#description' => t('Requires adsense.module'), |
'#description' => t('Requires adsense.module'), |
| 20 |
); |
); |
| 21 |
|
$form['body_view']['adsense_injector_body_view'] = array( |
| 22 |
|
'#type' => 'checkbox', |
| 23 |
|
'#title' => t('Insert inline ad in node body on page views'), |
| 24 |
|
'#default_value' => variable_get('adsense_injector_body_view', TRUE), |
| 25 |
|
'#description' => t('Description'), |
| 26 |
|
'#required' => FALSE, |
| 27 |
|
); |
| 28 |
|
$form['body_view']['adsense_injector_body_view_minwords'] = array( |
| 29 |
|
'#type' => 'textfield', |
| 30 |
|
'#title' => t('Minimum node body word count'), |
| 31 |
|
'#default_value' => variable_get('adsense_injector_body_view_minwords', 75), |
| 32 |
|
'#description' => t('The minimum node body word count threshold - only inject if node body has at least this many words.'), |
| 33 |
|
); |
| 34 |
|
$form['body_view']['adsense_injector_body_view_template'] = array( |
| 35 |
|
'#type' => 'textarea', |
| 36 |
|
'#title' => t('Node body ad insertion template'), |
| 37 |
|
'#rows' => 5, |
| 38 |
|
'#cols' => 40, |
| 39 |
|
'#default_value' => 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]'), |
| 40 |
|
'#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.'), |
| 41 |
|
'#required' => TRUE, |
| 42 |
|
); |
| 43 |
|
|
| 44 |
if (module_exists('adsense')) { |
// 'list view' insertion (frontpage, taxonomy, etc). |
| 45 |
$form['node_ad_body_insertion']['adsense_injector_insert_body_ad'] = array( |
$form['list_view'] = array( |
| 46 |
'#type' => 'checkbox', |
'#type' => 'fieldset', |
| 47 |
'#title' => t('Insert inline ad in node body on page views'), |
'#collapsible' => TRUE, |
| 48 |
'#default_value' => variable_get('adsense_injector_insert_body_ad', ADSENSE_INJECTOR_INSERT_BODY_AD_DEFAULT), |
'#collapsed' => FALSE, |
| 49 |
'#description' => t('Description'), |
'#title' => t('Node list ad insertion'), |
| 50 |
'#required' => FALSE, |
'#description' => t('Ad insertion in node lists or other non-page view, like front page, taxonomy views.'), |
| 51 |
); |
); |
| 52 |
$form['node_ad_body_insertion']['adsense_injector_body_minwords'] = array( |
$form['list_view']['adsense_injector_list_view'] = array( |
| 53 |
'#type' => 'textfield', |
'#type' => 'checkbox', |
| 54 |
'#title' => t('Minimum node body word count'), |
'#title' => t('Append an ad after teaser on frontpage and taxonomy lists'), |
| 55 |
'#default_value' => variable_get('adsense_injector_body_minwords', ADSENSE_INJECTOR_BODY_MINWORDS_DEFAULT), |
'#default_value' => variable_get('adsense_injector_list_view', FALSE), |
| 56 |
'#description' => t('The minimum node body word count threshold - only inject if node body has at least this many words.'), |
'#description' => t('Note: this does not currently support Views module based lists.'), |
| 57 |
); |
'#required' => FALSE, |
| 58 |
$form['node_ad_body_insertion']['adsense_injector_body_template'] = array( |
); |
| 59 |
'#type' => 'textarea', |
$form['list_view']['adsense_injector_list_view_template'] = array( |
| 60 |
'#title' => t('Node body ad insertion template'), |
'#type' => 'textarea', |
| 61 |
'#rows' => 5, |
'#title' => t('List ad insertion template'), |
| 62 |
'#cols' => 40, |
'#rows' => 3, |
| 63 |
'#default_value' => variable_get('adsense_injector_body_template', ADSENSE_INJECTOR_BODY_INSERTION_TEMPLATE_DEFAULT), |
'#cols' => 40, |
| 64 |
'#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.'), |
'#default_value' => variable_get('adsense_injector_list_view_template', '%teaser<br class="clear"/>[adsense:728x90:0123456789]'), |
| 65 |
'#required' => TRUE, |
'#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.'), |
| 66 |
); |
'#required' => TRUE, |
| 67 |
|
); |
|
/** |
|
|
* '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 <a href="/admin/settings/adsense">adsense.module settings page</a> 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' => FALSE, |
|
|
'#title' => t('Select Node Types for Insertion'), |
|
|
'#description' => t('Nodes types to display inline ads - ads are inserted <strong>only</strong> 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, |
|
|
); |
|
|
} |
|
| 68 |
|
|
| 69 |
// Do some sanity checking. |
// What kinds of nodes do we want to insert on...? |
| 70 |
if ($enabled_count == 0) { |
$form['content_types'] = array( |
| 71 |
$msg = t('No node types selected (no ads will be inserted because you haven\'t selected any node types for automatic ad insertion.)'); |
'#type' => 'fieldset', |
| 72 |
$form['injection_control']['#collapsed'] = FALSE; |
'#collapsible' => TRUE, |
| 73 |
$form['injection_control']['no_nodes_enabled'] = array( |
'#collapsed' => FALSE, |
| 74 |
'#type' => 'markup', |
'#title' => t('Content types'), |
| 75 |
'#weight' => -1, |
); |
| 76 |
'#value' => '<div id="message"><div class="messages error"><strong>'. $msg .'</strong></div></div>', |
$form['content_types']['adsense_injector_nodes'] = array( |
| 77 |
); |
'#type' => 'checkboxes', |
| 78 |
} |
'#title' => t('Content types'), |
| 79 |
} |
'#default_value' => variable_get('adsense_injector_nodes', array()), |
| 80 |
|
'#options' => array_map('check_plain', node_get_types('names')), |
| 81 |
|
'#description' => t('Select content types to display inline ads.'), |
| 82 |
|
); |
| 83 |
|
|
| 84 |
return system_settings_form($form); |
return system_settings_form($form); |
| 85 |
} |
} |