| 1 |
<?php
|
| 2 |
/**
|
| 3 |
* @file
|
| 4 |
* Display a banner and/or block to convert Internet Explorer users to Firefox
|
| 5 |
*
|
| 6 |
* @author David Kent Norman
|
| 7 |
* @link http://drupal.org/node/66987
|
| 8 |
* @link http://deekayen.net/iedestroyer
|
| 9 |
*/
|
| 10 |
|
| 11 |
// DEFAULTS
|
| 12 |
define('IEDESTROYER_ENABLED', 0);
|
| 13 |
define('IEDESTROYER_VISIBILITY', 0);
|
| 14 |
|
| 15 |
/**
|
| 16 |
* Implementation of hook_help().
|
| 17 |
*
|
| 18 |
* @return string
|
| 19 |
*/
|
| 20 |
function iedestroyer_help($section) {
|
| 21 |
switch ($section) {
|
| 22 |
case 'admin/block/configure/iedestroyer/0':
|
| 23 |
return t('This block only displays when visitors are using Internet Explorer.');
|
| 24 |
break;
|
| 25 |
}
|
| 26 |
}
|
| 27 |
|
| 28 |
function iedestroyer_init() {
|
| 29 |
// common.inc doesn't load till a full bootstrap, whereas init is before that
|
| 30 |
require_once 'includes/common.inc';
|
| 31 |
|
| 32 |
$path = drupal_get_path('module', 'iedestroyer');
|
| 33 |
|
| 34 |
if (variable_get('iedestroyer_enabled', IEDESTROYER_ENABLED) && _iedestroyer_should_display_page()) {
|
| 35 |
if (file_exists("$path/iedestroyer.js")) {
|
| 36 |
drupal_add_js("$path/iedestroyer.js");
|
| 37 |
}
|
| 38 |
}
|
| 39 |
}
|
| 40 |
|
| 41 |
function iedestroyer_menu($maycache) {
|
| 42 |
$items = array();
|
| 43 |
$items[] = array(
|
| 44 |
'path' => 'admin/settings/iedestroyer',
|
| 45 |
'title' => t('IE Destroyer'),
|
| 46 |
'description' => t('Change what type of banner displays.'),
|
| 47 |
'callback' => 'drupal_get_form',
|
| 48 |
'callback arguments' => 'iedestroyer_admin_settings',
|
| 49 |
'access' => user_access('administer site configuration'),
|
| 50 |
'type' => MENU_NORMAL_ITEM
|
| 51 |
);
|
| 52 |
return $items;
|
| 53 |
}
|
| 54 |
/**
|
| 55 |
* Implementation of hook_block().
|
| 56 |
*/
|
| 57 |
function iedestroyer_block($op = 'list', $delta = 0, $edit = array()) {
|
| 58 |
$edit = $_POST['edit'];
|
| 59 |
switch($op) {
|
| 60 |
case 'list':
|
| 61 |
$blocks[0]['info'] = 'IE Destroyer';
|
| 62 |
return $blocks;
|
| 63 |
break;
|
| 64 |
|
| 65 |
case 'configure':
|
| 66 |
$form['iedestroyer_block_firefoxbutton'] = array(
|
| 67 |
'#type' => 'textarea',
|
| 68 |
'#title' => t('Block content'),
|
| 69 |
'#default_value' => variable_get('iedestroyer_block_firefoxbutton', _iedestroyer_default_firefoxbutton()),
|
| 70 |
'#cols' => 70, '#rows' => 9,
|
| 71 |
'#required' => true,
|
| 72 |
'#default_value' => variable_get('iedestroyer_firefoxbutton', _iedestroyer_default_firefoxbutton()),
|
| 73 |
'#description' => t('Insert your Firefox referral HTML. You can earn referral income from Google through AdSense:<br />').
|
| 74 |
'<script type="text/javascript"><!--
|
| 75 |
google_ad_client = "pub-1105343943158891";
|
| 76 |
google_ad_output = "textlink";
|
| 77 |
google_ad_format = "ref_text";
|
| 78 |
google_cpa_choice = "CAAQidTQgAIaCDFyD7PiBqtPKN2uuIEB";
|
| 79 |
google_ad_channel = "7588513660";
|
| 80 |
//--></script>
|
| 81 |
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
|
| 82 |
</script>');
|
| 83 |
return $form;
|
| 84 |
break;
|
| 85 |
|
| 86 |
case 'save':
|
| 87 |
variable_set('iedestroyer_block_firefoxbutton', $edit['iedestroyer_block_firefoxbutton']);
|
| 88 |
|
| 89 |
case 'view':
|
| 90 |
if (strpos(strtolower($_SERVER['HTTP_USER_AGENT']), 'msie') !== FALSE) {
|
| 91 |
$block['subject'] = t('Download Firefox');
|
| 92 |
$block['content'] = variable_get('iedestroyer_block_firefoxbutton', _iedestroyer_default_firefoxbutton());
|
| 93 |
return $block;
|
| 94 |
}
|
| 95 |
break;
|
| 96 |
}
|
| 97 |
}
|
| 98 |
|
| 99 |
function iedestroyer_admin_settings() {
|
| 100 |
$form = array();
|
| 101 |
|
| 102 |
$form['iedestroyer_settings'] = array(
|
| 103 |
'#type' => 'fieldset',
|
| 104 |
'#title' => t('IE Destroyer settings')
|
| 105 |
);
|
| 106 |
$form['iedestroyer_settings']['iedestroyer_enabled'] = array(
|
| 107 |
'#type' => 'checkbox',
|
| 108 |
'#title' => t('Enable IE Destroyer banner'),
|
| 109 |
'#default_value' => variable_get('iedestroyer_enabled', IEDESTROYER_ENABLED)
|
| 110 |
);
|
| 111 |
$form['iedestroyer_settings']['iedestroyer_die'] = array(
|
| 112 |
'#type' => 'checkbox',
|
| 113 |
'#title' => t('Stop output after Firefox banner'),
|
| 114 |
'#description' => t('Shows only the banner - normal output will not be shown'),
|
| 115 |
'#default_value' => variable_get('iedestroyer_die', 0)
|
| 116 |
);
|
| 117 |
|
| 118 |
$form['iedestroyer_adsense_settings'] = array(
|
| 119 |
'#type' => 'fieldset',
|
| 120 |
'#title' => t('Firefox referral link'),
|
| 121 |
'#collapsible' => true,
|
| 122 |
'#collapsed' => true
|
| 123 |
);
|
| 124 |
$form['iedestroyer_adsense_settings']['iedestroyer_firefoxbutton'] = array(
|
| 125 |
'#type' => 'textarea',
|
| 126 |
'#title' => t('Your Firefox referral button'),
|
| 127 |
'#cols' => 70, '#rows' => 9,
|
| 128 |
'#required' => true,
|
| 129 |
'#default_value' => variable_get('iedestroyer_firefoxbutton', _iedestroyer_default_firefoxbutton()),
|
| 130 |
'#description' => t('Insert your Firefox referral code. You can earn referral income from Google through AdSense:<br />').
|
| 131 |
'<script type="text/javascript"><!--
|
| 132 |
google_ad_client = "pub-1105343943158891";
|
| 133 |
google_ad_output = "textlink";
|
| 134 |
google_ad_format = "ref_text";
|
| 135 |
google_cpa_choice = "CAAQidTQgAIaCDFyD7PiBqtPKN2uuIEB";
|
| 136 |
google_ad_channel = "7588513660";
|
| 137 |
//--></script>
|
| 138 |
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
|
| 139 |
</script>');
|
| 140 |
|
| 141 |
$form['iedestroyer_page'] = array(
|
| 142 |
'#type' => 'fieldset',
|
| 143 |
'#title' => t('Specific page configuration'),
|
| 144 |
'#collapsible' => true,
|
| 145 |
'#collapsed' => true
|
| 146 |
);
|
| 147 |
$form['iedestroyer_page']['iedestroyer_visibility'] = array(
|
| 148 |
'#type' => 'radios',
|
| 149 |
'#title' => t('Show on specific pages'),
|
| 150 |
'#default_value' => variable_get('iedestroyer_visibility', IEDESTROYER_VISIBILITY),
|
| 151 |
'#options' => array(t('Show on every page except the listed pages.'),
|
| 152 |
t('Show on only the listed pages.'),
|
| 153 |
t('Show if the following PHP code returns TRUE (PHP-mode, experts only).'))
|
| 154 |
);
|
| 155 |
$form['iedestroyer_page']['iedestroyer_access_pages'] = array(
|
| 156 |
'#type' => 'textarea',
|
| 157 |
'#title' => t('Pages'),
|
| 158 |
'#cols' => 70, '#rows' => 5,
|
| 159 |
'#default_value' => variable_get('iedestroyer_access_pages', ''),
|
| 160 |
'#description' => t('Enter one page per line as Drupal paths. The "*" character is a wildcard. Example paths are <em>blog</em> for every personal blog. "<em><front></em>" is the front page.')
|
| 161 |
);
|
| 162 |
|
| 163 |
$form['iedestroyer_output'] = array(
|
| 164 |
'#type' => 'textarea',
|
| 165 |
'#title' => t('Output HTML'),
|
| 166 |
'#cols' => 70, '#rows' => 20,
|
| 167 |
'#default_value' => variable_get('iedestroyer_output', _iedestroyer_default()),
|
| 168 |
'#description' => t('Only configure this script if you want to make changes to the displayed banner. Any occurence of [adsense_button] will be replaced with the referral button code from the Google AdSense settings section of this page.')
|
| 169 |
);
|
| 170 |
return system_settings_form($form);
|
| 171 |
}
|
| 172 |
|
| 173 |
function iedestroyer_banner() {
|
| 174 |
if (strpos(strtolower($_SERVER['HTTP_USER_AGENT']), 'msie') === FALSE) {
|
| 175 |
return;
|
| 176 |
}
|
| 177 |
if (_iedestroyer_should_display_page()) {
|
| 178 |
$output = variable_get('iedestroyer_output', _iedestroyer_default());
|
| 179 |
|
| 180 |
echo str_replace('[adsense_button]', variable_get('iedestroyer_firefoxbutton', _iedestroyer_default_firefoxbutton()), $output);
|
| 181 |
if (variable_get('iedestroyer_die', 0)) {
|
| 182 |
exit('</body></html>');
|
| 183 |
}
|
| 184 |
|
| 185 |
}
|
| 186 |
}
|
| 187 |
|
| 188 |
/**
|
| 189 |
* This theme hook is here to provide some compatibility
|
| 190 |
* with nonphptemplate themes. Just in theory, though.
|
| 191 |
*/
|
| 192 |
function theme_iedestroyer() {
|
| 193 |
iedestroyer_banner();
|
| 194 |
}
|
| 195 |
|
| 196 |
function _iedestroyer_should_display_page() {
|
| 197 |
$page_match = FALSE;
|
| 198 |
$visibility = (int)variable_get('iedestroyer_visibility', IEDESTROYER_VISIBILITY);
|
| 199 |
$pages = variable_get('iedestroyer_access_pages', '');
|
| 200 |
|
| 201 |
if (variable_get('iedestroyer_enabled', IEDESTROYER_ENABLED) == 0) {
|
| 202 |
return $page_match;
|
| 203 |
}
|
| 204 |
|
| 205 |
if ($pages) {
|
| 206 |
if ($visibility < 2) {
|
| 207 |
$path = drupal_get_path_alias($_GET['q']);
|
| 208 |
$regexp = '/^('. preg_replace(array('/(\r\n?|\n)/', '/\\\\\*/', '/(^|\|)\\\\<front\\\\>($|\|)/'), array('|', '.*', '\1'. preg_quote(variable_get('site_frontpage', 'node'), '/') .'\2'), preg_quote($pages, '/')) .')$/';
|
| 209 |
$page_match = !($visibility xor preg_match($regexp, $path));
|
| 210 |
}
|
| 211 |
else {
|
| 212 |
$page_match = drupal_eval($block->pages);
|
| 213 |
}
|
| 214 |
}
|
| 215 |
else {
|
| 216 |
if ($visibility === 0) {
|
| 217 |
$page_match = TRUE;
|
| 218 |
}
|
| 219 |
}
|
| 220 |
|
| 221 |
return $page_match;
|
| 222 |
}
|
| 223 |
|
| 224 |
function _iedestroyer_default() {
|
| 225 |
|
| 226 |
return <<<EOT
|
| 227 |
<div id="iedestroyer" style="display: block;">
|
| 228 |
|
| 229 |
<br /><br />
|
| 230 |
|
| 231 |
<div style="padding: 20px; background-color: #ffffbb; font-family: arial; font-size: 15px; font-weight: normal; color: #111111; line-height: 17px;">
|
| 232 |
|
| 233 |
<div style="width: 630px; margin: 0 auto 0 auto; text-align: left">
|
| 234 |
|
| 235 |
<div style="padding-left: 10px; padding-top: 0px; float: right;">
|
| 236 |
|
| 237 |
[adsense_button]
|
| 238 |
|
| 239 |
</div>
|
| 240 |
|
| 241 |
<strong>We see you're using Internet Explorer, which is not compatible with this site. We strongly suggest downloading Firefox. We think you'll like it better:</strong>
|
| 242 |
<ul>
|
| 243 |
<li>Firefox protects you from viruses, spyware, and pop-ups.</li>
|
| 244 |
<li>Enjoy improvements to performance, ease of use, and privacy.</li>
|
| 245 |
<li>Features like tabbed browsing make reading webpages easier.</li>
|
| 246 |
<li>Use Live Bookmarks that update themselves automatically with the latest content from the Web.</li>
|
| 247 |
<li>Automatic updates and faster browsing.</li>
|
| 248 |
<li>It's easy to import your favorites and settings.</li>
|
| 249 |
</ul>
|
| 250 |
|
| 251 |
Click the button on the right to download Firefox. <strong>It's free.</strong>
|
| 252 |
<br /><br />
|
| 253 |
<input type="button" onclick="hideIEdestroyer_banner()" value="Continue without Firefox >>" />
|
| 254 |
|
| 255 |
<br /><br />
|
| 256 |
|
| 257 |
</div></div></div>
|
| 258 |
EOT;
|
| 259 |
}
|
| 260 |
|
| 261 |
function _iedestroyer_default_firefoxbutton() {
|
| 262 |
|
| 263 |
return '<script type="text/javascript"><!--
|
| 264 |
google_ad_client = "pub-1105343943158891";
|
| 265 |
google_ad_width = 125;
|
| 266 |
google_ad_height = 125;
|
| 267 |
google_ad_format = "125x125_as_rimg";
|
| 268 |
google_cpa_choice = "CAAQ_f-XhAIaCDgvi727fxoIKK2293M";
|
| 269 |
google_ad_channel = "7588513660";
|
| 270 |
//--></script>
|
| 271 |
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
|
| 272 |
</script>';
|
| 273 |
}
|