/[drupal]/contributions/modules/adsense/adsense.admin.inc
ViewVC logotype

Contents of /contributions/modules/adsense/adsense.admin.inc

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


Revision 1.8 - (show annotations) (download) (as text)
Tue Mar 31 14:41:18 2009 UTC (7 months, 4 weeks ago) by jcnventura
Branch: MAIN
CVS Tags: HEAD
Changes since 1.7: +32 -2 lines
File MIME type: text/x-php
Restore the old test mode
Add options to use AdSense undocumented features
Coder fixes
1 <?php
2 // $Id: adsense.admin.inc,v 1.7 2008/12/17 14:11:02 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 require_once(drupal_get_path('module', 'adsense') .'/includes/adsense.search_options.inc');
20
21 $form['help'] = array(
22 '#type' => 'fieldset',
23 '#collapsible' => TRUE,
24 '#collapsed' => TRUE,
25 '#title' => t('Help and instructions'),
26 );
27
28 $form['help']['help'] = array(
29 '#type' => 'markup',
30 '#value' => adsense_help_text(),
31 );
32
33 $form['visibility'] = array(
34 '#type' => 'fieldset',
35 '#collapsible' => TRUE,
36 '#collapsed' => FALSE,
37 '#title' => t('Visibility'),
38 );
39
40 $form['visibility']['adsense_visibility'] = array(
41 '#type' => 'radios',
42 '#title' => t('Show AdSense on specific pages'),
43 '#default_value' => variable_get('adsense_visibility', ADSENSE_VISIBILITY_DEFAULT),
44 '#options' => array(t('Show on every page except the listed pages.'), t('Show on only the listed pages.')),
45 );
46
47 $form['visibility']['adsense_access_pages'] = array(
48 '#type' => 'textarea',
49 '#default_value' => variable_get('adsense_access_pages', ADSENSE_ACCESS_PAGES_DEFAULT),
50 '#rows' => 3,
51 '#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>')),
52 );
53
54 $access = user_access('use PHP for ad visibility');
55
56 if ($form['visibility']['adsense_visibility']['#default_value'] == 2 && !$access) {
57 $form['visibility']['adsense_visibility'] = array('#type' => 'value', '#value' => 2);
58 $form['visibility']['adsense_access_pages'] = array('#type' => 'value', '#value' => $form['visibility']['adsense_access_pages']['#default_value']);
59 }
60 elseif ($access) {
61 $form['visibility']['adsense_visibility']['#options'][] = t('Show if the following PHP code returns <code>TRUE</code> (PHP-mode, experts only).');
62 $form['visibility']['adsense_access_pages']['#description'] .= ' '. t('If the PHP-mode is chosen, enter PHP code between %php. Note that executing incorrect PHP-code can break your Drupal site.', array('%php' => '<?php ?>'));
63 }
64
65 $form['advanced'] = array(
66 '#type' => 'fieldset',
67 '#collapsible' => TRUE,
68 '#collapsed' => FALSE,
69 '#title' => t('Advanced options'),
70 );
71
72 $form['advanced']['adsense_test_mode'] = array(
73 '#type' => 'checkbox',
74 '#title' => t('Enable test mode?'),
75 '#default_value' => variable_get('adsense_test_mode', ADSENSE_TEST_MODE_DEFAULT),
76 '#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.'),
77 );
78
79 $form['advanced']['adsense_disable'] = array(
80 '#type' => 'checkbox',
81 '#title' => t('Disable Google AdSense ads?'),
82 '#default_value' => variable_get('adsense_disable', ADSENSE_DISABLE_DEFAULT),
83 '#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.'),
84 );
85
86 $form['advanced']['adsense_placeholder'] = array(
87 '#type' => 'checkbox',
88 '#title' => t('Placeholder when ads are disabled?'),
89 '#default_value' => variable_get('adsense_placeholder', ADSENSE_PLACEHOLDER_DEFAULT),
90 '#description' => t('This causes an empty box to be displayed in place of the ads when they are disabled.'),
91 );
92
93 $form['advanced']['adsense_placeholder_text'] = array(
94 '#type' => 'textarea',
95 '#title' => t('Placeholder text to display'),
96 '#default_value' => variable_get('adsense_placeholder_text', ADSENSE_PLACEHOLDER_TEXT_DEFAULT),
97 '#rows' => 3,
98 '#description' => t('Enter any text to display as a placeholder when ads are disabled.'),
99 );
100
101 $form['advanced']['adsense_section_targeting'] = array(
102 '#type' => 'checkbox',
103 '#title' => t('Enable AdSense section targeting?'),
104 '#default_value' => variable_get('adsense_section_targeting', ADSENSE_SECTION_TARGETING_DEFAULT),
105 '#description' => t('This better targets Google ads to the teaser and body of nodes.'),
106 );
107
108 $form['secret'] = array(
109 '#type' => 'fieldset',
110 '#collapsible' => TRUE,
111 '#collapsed' => TRUE,
112 '#title' => t('Undocumented options'),
113 '#description' => t("Warning: Use of these options is AT YOUR OWN RISK. Google will never generate an ad with any of these options, so using one of them is a violation of Google AdSense's Terms and Conditions. USE OF THESE OPTIONS MAY RESULT IN GETTING BANNED FROM THE PROGRAM. You may lose all the revenue accumulated in your account. FULL RESPONSABILITY FOR THE USE OF THESE OPTIONS IS YOURS. In other words, don't complain to the authors about getting banned, even if using one of these options was provided as a solution to a reported problem."),
114 );
115
116 $form['secret']['agreed'] = array(
117 '#type' => 'fieldset',
118 '#collapsible' => TRUE,
119 '#collapsed' => TRUE,
120 '#title' => t('I agree'),
121 );
122
123 $form['secret']['agreed']['adsense_secret_adtest'] = array(
124 '#type' => 'checkbox',
125 '#title' => t("Use Google's AdSense test option?"),
126 '#default_value' => variable_get('adsense_secret_adtest', ADSENSE_SECRET_ADTEST_DEFAULT),
127 '#description' => t('With this option set, Google will not count any clicks or page impressions. Revenue is not generated. Make sure that you disable this option in production servers. [!statement]', array('!statement' => l(t('Unofficial statement'), 'http://adsense-es.blogspot.com/2007/01/impresiones-de-mis-propios-anuncios-en.html'))),
128 );
129
130 $form['secret']['agreed']['adsense_secret_language'] = array(
131 '#type' => 'select',
132 '#title' => t('Language to display ads'),
133 '#default_value' => variable_get('adsense_secret_language', ADSENSE_SECRET_LANGUAGE_DEFAULT),
134 '#options' => array_merge(array(ADSENSE_SECRET_LANGUAGE_DEFAULT => 'Set by Google'), _adsense_search_options_language()),
135 );
136
137 return system_settings_form($form);
138 }
139
140 /**
141 * Menu callback for the adsense publisher ID settings form.
142 *
143 * @ingroup forms
144 */
145 function adsense_id_settings() {
146 include_once(drupal_get_path('module', 'adsense') .'/help/adsense_id_help.inc');
147
148 $form['help'] = array(
149 '#type' => 'fieldset',
150 '#collapsible' => TRUE,
151 '#collapsed' => TRUE,
152 '#title' => t('Help and instructions'),
153 );
154
155 $form['help']['help'] = array(
156 '#type' => 'markup',
157 '#value' => adsense_id_help_text(),
158 );
159
160 $form['adsense_basic_id'] = array(
161 '#type' => 'textfield',
162 '#title' => t('Site Google AdSense Publisher ID'),
163 '#required' => TRUE,
164 '#default_value' => variable_get('adsense_basic_id', ADSENSE_BASIC_ID_DEFAULT),
165 '#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')),
166 );
167
168 $options = _adsense_id_settings_client_id_mods();
169 if (count($options) > 1) {
170 $form['adsense_id_module'] = array(
171 '#type' => 'radios',
172 '#title' => t('Publisher ID module'),
173 '#default_value' => variable_get('adsense_id_module', ADSENSE_ID_MODULE_DEFAULT),
174 '#options' => $options,
175 );
176 }
177 else {
178 $form['adsense_id_module'] = array(
179 '#type' => 'hidden',
180 '#value' => $options[0],
181 );
182 }
183
184 $form['#validate'][] = '_adsense_id_settings_validate';
185
186 return system_settings_form($form);
187 }
188
189 /**
190 * Validate adsense_id_settings form.
191 */
192 function _adsense_id_settings_validate($form, &$form_state) {
193 $form_state['values']['adsense_basic_id'] = trim($form_state['values']['adsense_basic_id']);
194 }
195
196 /**
197 * Search for the available Publisher ID modules
198 *
199 * @return
200 * array of selectable Publisher ID functions
201 */
202 function _adsense_id_settings_client_id_mods() {
203 $ret['adsense_basic'] = 'Use the site Publisher ID always';
204
205 $funcs = get_defined_functions();
206 foreach ($funcs['user'] as $func) {
207 if (preg_match('!_adsense$!', $func)) {
208 $settings = $func('settings');
209 $ret[$func] = $settings['name'];
210 if (!empty($settings['desc'])) {
211 $ret[$func] .= "<div style='margin-left: 2.5em;' class='description'>{$settings['desc']}</div>";
212 }
213 }
214 }
215 return $ret;
216 }

  ViewVC Help
Powered by ViewVC 1.1.2