| 1 |
|
<?php |
| 2 |
|
// $Id: adsense.admin.inc,v 1.5 2008/08/18 15:46:11 jcnventura Exp $ |
| 3 |
|
|
| 4 |
|
/** |
| 5 |
|
* @file |
| 6 |
|
* Contains the administrative functions of the adsense module. |
| 7 |
|
* |
| 8 |
|
* This file is included by the core adsense module, and includes the |
| 9 |
|
* settings form. |
| 10 |
|
*/ |
| 11 |
|
|
| 12 |
|
/** |
| 13 |
|
* Menu callback for the adsense module settings form. |
| 14 |
|
* |
| 15 |
|
* @ingroup forms |
| 16 |
|
*/ |
| 17 |
|
function adsense_main_settings() { |
| 18 |
|
include_once(drupal_get_path('module', 'adsense') .'/help/adsense.help.inc'); |
| 19 |
|
|
| 20 |
|
$form['help'] = array( |
| 21 |
|
'#type' => 'fieldset', |
| 22 |
|
'#collapsible' => TRUE, |
| 23 |
|
'#collapsed' => TRUE, |
| 24 |
|
'#title' => t('Help and instructions'), |
| 25 |
|
); |
| 26 |
|
|
| 27 |
|
$form['help']['help'] = array( |
| 28 |
|
'#type' => 'markup', |
| 29 |
|
'#value' => adsense_help_text(), |
| 30 |
|
); |
| 31 |
|
|
| 32 |
|
$form['visibility'] = array( |
| 33 |
|
'#type' => 'fieldset', |
| 34 |
|
'#collapsible' => TRUE, |
| 35 |
|
'#collapsed' => FALSE, |
| 36 |
|
'#title' => t('Visibility'), |
| 37 |
|
); |
| 38 |
|
|
| 39 |
|
$form['visibility']['adsense_visibility'] = array( |
| 40 |
|
'#type' => 'radios', |
| 41 |
|
'#title' => t('Show AdSense on specific pages'), |
| 42 |
|
'#default_value' => variable_get('adsense_visibility', 0), |
| 43 |
|
'#options' => array(t('Show on every page except the listed pages.'), t('Show on only the listed pages.')), |
| 44 |
|
); |
| 45 |
|
|
| 46 |
|
$form['visibility']['adsense_access_pages'] = array( |
| 47 |
|
'#type' => 'textarea', |
| 48 |
|
'#default_value' => variable_get('adsense_access_pages', ''), |
| 49 |
|
'#rows' => 3, |
| 50 |
|
'#description' => t("Enter one page per line as Drupal paths. The '*' character is a wildcard. Example paths are %blog for the blog page and %blog-wildcard for every personal blog. %front is the front page.", array('%blog' => 'blog', '%blog-wildcard' => 'blog/*', '%front' => '<front>')), |
| 51 |
|
); |
| 52 |
|
|
| 53 |
|
$form['advanced'] = array( |
| 54 |
|
'#type' => 'fieldset', |
| 55 |
|
'#collapsible' => TRUE, |
| 56 |
|
'#collapsed' => TRUE, |
| 57 |
|
'#title' => t('Advanced options'), |
| 58 |
|
); |
| 59 |
|
|
| 60 |
|
$form['advanced']['adsense_test_mode'] = array( |
| 61 |
|
'#type' => 'checkbox', |
| 62 |
|
'#title' => t('Enable test mode?'), |
| 63 |
|
'#default_value' => variable_get('adsense_test_mode', 0), |
| 64 |
|
'#description' => t('This enables you to test the AdSense module settings. This can be useful in some situations: for example, testing whether revenue sharing is working properly or not without having to display real ads on your site. It is best to test this after you log out.'), |
| 65 |
|
); |
| 66 |
|
|
| 67 |
|
$form['advanced']['adsense_disable'] = array( |
| 68 |
|
'#type' => 'checkbox', |
| 69 |
|
'#title' => t('Disable Google AdSense ads?'), |
| 70 |
|
'#default_value' => variable_get('adsense_disable', 0), |
| 71 |
|
'#description' => t('This disables all display of Google AdSense ads from your web site. This is useful in certain situations, such as site upgrades, or if you make a copy of the site for development and test purposes.'), |
| 72 |
|
); |
| 73 |
|
|
| 74 |
|
$form['advanced']['adsense_placeholder'] = array( |
| 75 |
|
'#type' => 'checkbox', |
| 76 |
|
'#title' => t('Placeholder when ads are disabled?'), |
| 77 |
|
'#default_value' => variable_get('adsense_placeholder', 1), |
| 78 |
|
'#description' => t('This causes an empty box to be displayed in place of the ads when they are disabled.'), |
| 79 |
|
); |
| 80 |
|
|
| 81 |
|
$form['advanced']['adsense_placeholder_text'] = array( |
| 82 |
|
'#type' => 'textarea', |
| 83 |
|
'#title' => t('Placeholder text to display'), |
| 84 |
|
'#default_value' => variable_get('adsense_placeholder_text', t('Google AdSense')), |
| 85 |
|
'#rows' => 3, |
| 86 |
|
'#description' => t('Enter any text to display as a placeholder when ads are disabled.'), |
| 87 |
|
); |
| 88 |
|
|
| 89 |
|
$form['advanced']['adsense_section_targeting'] = array( |
| 90 |
|
'#type' => 'checkbox', |
| 91 |
|
'#title' => t('Enable AdSense section targeting?'), |
| 92 |
|
'#default_value' => variable_get('adsense_section_targeting', 1), |
| 93 |
|
'#description' => t('This better targets Google ads to the teaser and body of nodes.'), |
| 94 |
|
); |
| 95 |
|
|
| 96 |
|
return system_settings_form($form); |
| 97 |
|
} |
| 98 |
|
|
| 99 |
|
/** |
| 100 |
|
* Menu callback for the adsense publisher ID settings form. |
| 101 |
|
* |
| 102 |
|
* @ingroup forms |
| 103 |
|
*/ |
| 104 |
|
function adsense_id_settings() { |
| 105 |
|
include_once(drupal_get_path('module', 'adsense') .'/help/adsense_id_help.inc'); |
| 106 |
|
|
| 107 |
|
$form['help'] = array( |
| 108 |
|
'#type' => 'fieldset', |
| 109 |
|
'#collapsible' => TRUE, |
| 110 |
|
'#collapsed' => TRUE, |
| 111 |
|
'#title' => t('Help and instructions'), |
| 112 |
|
); |
| 113 |
|
|
| 114 |
|
$form['help']['help'] = array( |
| 115 |
|
'#type' => 'markup', |
| 116 |
|
'#value' => adsense_id_help_text(), |
| 117 |
|
); |
| 118 |
|
|
| 119 |
|
$form['adsense_basic_id'] = array( |
| 120 |
|
'#type' => 'textfield', |
| 121 |
|
'#title' => t('Site Google AdSense Publisher ID'), |
| 122 |
|
'#required' => TRUE, |
| 123 |
|
'#default_value' => variable_get('adsense_basic_id', ''), |
| 124 |
|
'#description' => t('This is the Google AdSense Publisher ID for the site owner. It is used if no other ID is suitable. Get this in your Google Adsense account. It should be similar to %id.', array('%id' => 'pub-9999999999999')), |
| 125 |
|
); |
| 126 |
|
|
| 127 |
|
$options = _adsense_id_settings_client_id_mods(); |
| 128 |
|
if (count($options) > 1) { |
| 129 |
|
$form['adsense_id_module'] = array( |
| 130 |
|
'#type' => 'radios', |
| 131 |
|
'#title' => t('Publisher ID module'), |
| 132 |
|
'#default_value' => variable_get('adsense_id_module', 'adsense_basic'), |
| 133 |
|
'#options' => $options, |
| 134 |
|
); |
| 135 |
|
} |
| 136 |
|
else { |
| 137 |
|
$form['adsense_id_module'] = array( |
| 138 |
|
'#type' => 'hidden', |
| 139 |
|
'#value' => $options[0], |
| 140 |
|
); |
| 141 |
|
} |
| 142 |
|
|
| 143 |
|
$form['#validate']['_adsense_id_settings_validate'] = array(); |
| 144 |
|
|
| 145 |
|
return system_settings_form($form); |
| 146 |
|
} |
| 147 |
|
|
| 148 |
|
/** |
| 149 |
|
* Validate adsense_id_settings form. |
| 150 |
|
*/ |
| 151 |
|
function _adsense_id_settings_validate($form_id, $form_values, $form) { |
| 152 |
|
form_set_value($form['adsense_basic_id'], trim($form_values['adsense_basic_id'])); |
| 153 |
|
} |
| 154 |
|
|
| 155 |
|
/** |
| 156 |
|
* Search for the available Publisher ID modules |
| 157 |
|
* |
| 158 |
|
* @return |
| 159 |
|
* array of selectable Publisher ID functions |
| 160 |
|
*/ |
| 161 |
|
function _adsense_id_settings_client_id_mods() { |
| 162 |
|
$ret['adsense_basic'] = 'Use the site Publisher ID always'; |
| 163 |
|
|
| 164 |
|
$funcs = get_defined_functions(); |
| 165 |
|
foreach ($funcs['user'] as $func) { |
| 166 |
|
if (preg_match('!_adsense$!', $func)) { |
| 167 |
|
$settings = $func('settings'); |
| 168 |
|
$ret[$func] = $settings['name']; |
| 169 |
|
if (!empty($settings['desc'])) { |
| 170 |
|
$ret[$func] .= "<div style='margin-left: 2.5em;' class='description'>{$settings['desc']}</div>"; |
| 171 |
|
} |
| 172 |
|
} |
| 173 |
|
} |
| 174 |
|
return $ret; |
| 175 |
|
} |