

This is the source code for the Newest Browser Drupal module. Plug this Drupal module in your Drupal CMS to promote your browser of choice to visitors. The lastest numerical version will be shown to visitors, for example Upgrade to "Version 1.1.1". Data is pulled from NewestBrowser.com.
Make suggestions for new features in upcoming versions in the comments below.
name = Newest Browser description = Encourage upgrading to the lastest in technology and security by displaying updates for major browsers your visitor is using, or promote a browser your of choice. Updated are extracted from NewestBrowser.com. package = CW Web Solutions LLC version = 1.0 core = 6.x ; Information added by drupal.org packaging script on 2009-12-16 version = "1.0" core = "6.x" project = "newestbrowser" datestamp = "1260996916"
<?php
/*
This module is released under GPL: http://www.opensource.org/licenses/gpl-license.php
Newest Browser Wordpress Plugin - shows updated version to user's browser or site owner's promoted browser of choice
Copyright (C) 2010 CW Web Solutions LLC
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
*/
/* HELP - hook_help() */
function newestbrowser_help($path, $arg) {
switch ($path) {
case 'admin/settings/newestbrowser':
return t('<p style="text-align:center;"><a href="http://www.chriswashington.net/" alt="CW Web Solutions LLC" title="CW Web Solutions LLC" target="_blank"><img src="' . drupal_get_path('module', 'newestbrowser') .'/images/logo-black.jpg" border="0"></a></p><p>Encourage visitors to upgrade to the newest in browser technology/security by displaying updates for major browsers your visitor is using, or promote a browser of your choice.</p><p>Updated numeric versions are extracted remotely from <a href="http://www.newestbrowser.com/" alt="Updates for your browser" title="Updates for your browser" target="_blank">NewestBrowser.com</a> once a day, then stored in your database to be extracted for optimization.</p><p>This is an early verion, but future versions will give you more control of how promoted content is displayed.</p><p>A <a href="http://www.chriswashington.net/projects/newest-browser-for-wordpress" title="Newest Browser Plugin for Wordpress" target="_blank">Wordpress plugin</a> and <a href="http://www.chriswashington.net/projects/newest-browser-for-joomla" title="Newest Browser Extension for Joomla" target="_blank">Joombla extension</a> of Newest Browser are also avalialble for download.</p><p><a href="http://www.chriswashington.net/" alt="CW Web Solutions LLC" title="CW Web Solutions LLC" target="_blank">CW Web Solutions LLC</a></p>');
case 'admin/help#newestbrowser':
return t('<p style="text-align:center;"><a href="http://www.chriswashington.net/" alt="CW Web Solutions LLC" title="CW Web Solutions LLC" target="_blank"><img src="' . drupal_get_path('module', 'newestbrowser') .'/images/logo-black.jpg" border="0"></a></p><p>Encourage visitors to upgrade to the newest in browser technology/security by displaying updates for major browsers your visitor is using, or promote a browser of your choice.</p><p>Updated numeric versions are extracted remotely from <a href="http://www.newestbrowser.com/" alt="Updates for your browser" title="Updates for your browser" target="_blank">NewestBrowser.com</a> once a day, then stored in your database to be extracted for optimization.</p><p>This is an early verion, but future versions will give you more control of how promoted content is displayed.</p><p>A <a href="http://www.chriswashington.net/projects/newest-browser-for-wordpress" title="Newest Browser Plugin for Wordpress" target="_blank">Wordpress plugin</a> and <a href="http://www.chriswashington.net/projects/newest-browser-for-joomla" title="Newest Browser Extension for Joomla" target="_blank">Joombla extension</a> of Newest Browser are also avalialble for download.</p><p><a href="http://www.chriswashington.net/" alt="CW Web Solutions LLC" title="CW Web Solutions LLC" target="_blank">CW Web Solutions LLC</a></p>');
default:
return '';
}
}
/* PERMISSIONS - hook_perm() */
function newestbrowser_perm() {
return array('view block', 'administer settings');
}
/* ADMIN MENU - hook_menu() */
function newestbrowser_menu() {
$items = array();
$items['admin/settings/newestbrowser'] = array(
'title' => t('Newest Browser'),
'description' => t('Show visitors the latest upgrade version of their browser.'),
'page callback' => 'drupal_get_form',
'page arguments' => array('newestbrowser_admin_settings'),
'access arguments' => array('administer'),
'type' => MENU_NORMAL_ITEM,
);
return $items;
}
/* LOAD CSS - hook_init() */
function newestbrowser_init() {
drupal_set_html_head('<link type="text/css" rel="stylesheet" media="all" href="' . drupal_get_path('module', 'newestbrowser') .'/newestbrowser.css' . '" />');
}
/* ADMIN PAGE - newestbrowser_admin_settings() */
function newestbrowser_admin_settings() {
$PromoteValues = array(
'default' => 'Visitor\'s Browser',
'Internet Explorer' => 'Internet Explorer',
'Opera' => 'Opera',
'Safari' => 'Safari',
'Firefox' => 'Firefox',
'Chrome' => 'Chrome');
$form['fieldset_options'] = array(
'#type' => 'fieldset',
'#title' => t('Settings'),
'#description' => t('<br />Steps:<br /><br />1. Choose a browser to promote<br /><br />2. Choose the block the module will appear in<br /><br />3. Setup module permissions for anonymous users to access view block<br /><br />'),
'#collapsible' => TRUE,
'#collapsed' => FALSE
);
$form['fieldset_options']['promote'] = array(
'#type' => 'select',
'#title' => t('Which browser do you want to promote the newest version of'),
'#default_value' => variable_get('promote','default'),
'#options' => $PromoteValues
);
return system_settings_form($form);
}
/* BLOCK - newestbrowser_hook_block() */
function newestbrowser_block($op = 'list', $delta = 0) {
// ADMIN BLOCK LIST, CAN MOVE TO ANY BLOCK
if ($op == 'list') {
$blocks[0]['info'] = t('Newest Browser');
return $blocks;
}
// CONTENT VISITORS SEE
else if ($op == 'view' && user_access('view block')) {
$block['subject'] = t('Newest Browser');
// FIRST SEE IF YOU HAVE TODAY'S VERION FROM REMOTE XML FILE, IF NOT GO GET IT ONLY ONCE A DAY
$custom_module_path = drupal_get_path('module', 'newestbrowser');
if(variable_get('lastupdated','') == "" || variable_get('lastupdated','') != date('m/d/Y')) {
$strPass = 'HTTP/1.1 200 OK';
$strVersion = "http://www.newestbrowser.com/versions.xml";
$arrayResults = get_headers($strVersion);
$strXML = simplexml_load_file($strVersion);
if ($arrayResults[0] == $strPass && $strXML != "") {
// LOOP THROUGH XML TO GET ALL DATA THEN SAVE INTO DATABASE
foreach($strXML->children() as $child) {
foreach($child->children() as $grandchild) {
switch($grandchild->getName()) {
case "OS":
$strOS = trim($grandchild);
break;
case "Browser":
$strBrowser = trim($grandchild);
break;
case "Version":
$strVersion = trim($grandchild);
break;
};
}
// WHATEVER READ, STORE IN DATABASE
if($strOS == "Windows" && $strBrowser == "Internet Explorer") variable_set('win-ie', $strVersion);
if($strOS == "Windows" && $strBrowser == "Opera") variable_set('win-opera', $strVersion);
if($strOS == "Windows" && $strBrowser == "Safari") variable_set('win-safari', $strVersion);
if($strOS == "Windows" && $strBrowser == "Firefox") variable_set('win-ff', $strVersion);
if($strOS == "Windows" && $strBrowser == "Chrome") variable_set('win-chrome', $strVersion);
if($strOS == "Macintosh" && $strBrowser == "Safari") variable_set('mac-safari', $strVersion);
if($strOS == "Macintosh" && $strBrowser == "Firefox") variable_set('mac-ff', $strVersion);
if($strOS == "Macintosh" && $strBrowser == "Chrome") variable_set('mac-chrome', $strVersion);
if($strOS == "Macintosh" && $strBrowser == "Opera") variable_set('mac-opera', $strVersion);
}
// SAVE TODAYS DATE IN DATABASE FOR PLUGIN
variable_set('lastupdated', date('m/d/Y'));
}
}
// CHOOSE WHICH OPTION IS SELECTED FROM PLUGIN SETTINGS, THEN DISPLAY THE BROWSER AND VERSION TO UPGRADE TO
$strUserAgent = $_SERVER['HTTP_USER_AGENT'];
switch(variable_get('promote','')) {
case "Internet Explorer":
$block['content'] .= "<div id=\"cssNewestBrowser\"><a href=\"http://www.microsoft.com/windows/internet-explorer/worldwide-sites.aspx\" target=\"_blank\" rel=\"nofollow\"><img src=\"" . $custom_module_path . "/images/icon-internet-explorer.png" . "\" /> Upgrade to version " . variable_get('win-ie','') . "</a><br /><a href=\"http://www.chriswashington.net/projects/newest-browser-for-drupal\" title=\"Newest Browser module powered by CW Web Solutions LLC\" target=\"_blank\"><img src=\"" . $custom_module_path . "/images/icon.png" . "\" style=\"float:right;\" /></a></div>";
break;
case "Opera":
$block['content'] .= "<div id=\"cssNewestBrowser\"><a href=\"http://www.opera.com/browser/download/\" target=\"_blank\" rel=\"nofollow\"><img src=\"" . $custom_module_path . "/images/icon-opera.png" . "\" /> Upgrade to version ";
if(strlen(strstr(strtolower($strUserAgent),"windows")) > 0)
$block['content'] .= variable_get('win-opera','') . "</a><br /><a href=\"http://www.chriswashington.net/projects/newest-browser-for-drupal\" title=\"Newest Browser module powered by CW Web Solutions LLC\" target=\"_blank\"><img src=\"" . $custom_module_path . "/images/icon.png" . "\" style=\"float:right;\" /></a></div>";
else
$block['content'] .= variable_get('mac-opera','') . "</a><br /><a href=\"http://www.chriswashington.net/projects/newest-browser-for-drupal\" title=\"Newest Browser module powered by CW Web Solutions LLC\" target=\"_blank\"><img src=\"" . $custom_module_path . "/images/icon.png" . "\" style=\"float:right;\" /></a></div>";
break;
case "Safari":
$block['content'] .= "<div id=\"cssNewestBrowser\"><a href=\"http://www.apple.com/safari/download/\" target=\"_blank\" rel=\"nofollow\"><img src=\"" . $custom_module_path . "/images/icon-safari.png" . "\" /> Upgrade to version ";
if(strlen(strstr(strtolower($strUserAgent),"windows")) > 0)
$block['content'] .= variable_get('win-safari','') . "</a><br /><a href=\"http://www.chriswashington.net/projects/newest-browser-for-drupal\" title=\"Newest Browser module powered by CW Web Solutions LLC\" target=\"_blank\"><img src=\"" . $custom_module_path . "/images/icon.png" . "\" style=\"float:right;\" /></a></div>";
else
$block['content'] .= variable_get('mac-safari','') . "</a><br /><a href=\"http://www.chriswashington.net/projects/newest-browser-for-drupal\" title=\"Newest Browser module powered by CW Web Solutions LLC\" target=\"_blank\"><img src=\"" . $custom_module_path . "/images/icon.png" . "\" style=\"float:right;\" /></a></div>";
break;
case "Firefox":
$block['content'] .= "<div id=\"cssNewestBrowser\"><a href=\"http://www.mozilla.com/en-US/firefox/all.html\" target=\"_blank\" rel=\"nofollow\"><img src=\"" . $custom_module_path . "/images/icon-firefox.png" . "\" /> Upgrade to version ";
if(strlen(strstr(strtolower($strUserAgent),"windows")) > 0)
$block['content'] .= variable_get('win-ff','') . "</a><br /><a href=\"http://www.chriswashington.net/projects/newest-browser-for-drupal\" title=\"Newest Browser module powered by CW Web Solutions LLC\" target=\"_blank\"><img src=\"" . $custom_module_path . "/images/icon.png" . "\" style=\"float:right;\" /></a></div>";
else
$block['content'] .= variable_get('mac-ff','') . "</a><br /><a href=\"http://www.chriswashington.net/projects/newest-browser-for-drupal\" title=\"Newest Browser module powered by CW Web Solutions LLC\" target=\"_blank\"><img src=\"" . $custom_module_path . "/images/icon.png" . "\" style=\"float:right;\" /></a></div>";
break;
case "Chrome":
$block['content'] .= "<div id=\"cssNewestBrowser\"><a href=\"http://www.google.com/chrome\" target=\"_blank\" rel=\"nofollow\"><img src=\"" . $custom_module_path . "/images/icon-chrome.png" . "\" /> Upgrade to version ";
if(strlen(strstr(strtolower($strUserAgent),"windows")) > 0)
$block['content'] .= variable_get('win-chrome','') . "</a><br /><a href=\"http://www.chriswashington.net/projects/newest-browser-for-drupal\" title=\"Newest Browser module powered by CW Web Solutions LLC\" target=\"_blank\"><img src=\"" . $custom_module_path . "/images/icon.png" . "\" style=\"float:right;\" /></a></div>";
else
$block['content'] .= variable_get('mac-chrome','') . "</a><br /><a href=\"http://www.chriswashington.net/projects/newest-browser-for-drupal\" title=\"Newest Browser module powered by CW Web Solutions LLC\" target=\"_blank\"><img src=\"" . $custom_module_path . "/images/icon.png" . "\" style=\"float:right;\" /></a></div>";
break;
default:
// SHOW LASTEST BROWSER THAT VISITOR IS CURRENTLY USING
if(strlen(strstr(strtolower($strUserAgent),"firefox")) > 0 && strlen(strstr(strtolower($strUserAgent),"macintosh")) > 0 || strlen(strstr(strtolower($strUserAgent),"firefox")) > 0 && strlen(strstr(strtolower($strUserAgent),"windows")) > 0) {
// IF USERAGENT CONTAINS FIREFOX
$strText = "<a href=\"http://www.mozilla.com/en-US/firefox/all.html\" target=\"_blank\" rel=\"nofollow\"><img src=\"" . $custom_module_path . "/images/icon-firefox.png" . "\" /> Upgrade to version ";
if(strlen(strstr(strtolower($strUserAgent),"macintosh")) > 0)
$strText = $strText . variable_get('mac-ff','') . "</a>";
else
$strText = $strText . variable_get('win-ff','') . "</a>";
} else if(strlen(strstr(strtolower($strUserAgent),"msie")) > 0) {
// IF USERAGENT CONTAINS INTERNET EXPLORER
$strText = "<a href=\"http://www.microsoft.com/windows/internet-explorer/worldwide-sites.aspx\" target=\"_blank\" rel=\"nofollow\"><img src=\"" . $custom_module_path . "/images/icon-internet-explorer.png" . "\" /> Upgrade to version " . variable_get('win-ie','') . "</a>";
} else if(strlen(strstr(strtolower($strUserAgent),"opera")) > 0 && strlen(strstr(strtolower($strUserAgent),"macintosh")) > 0 || strlen(strstr(strtolower($strUserAgent),"opera")) > 0 && strlen(strstr(strtolower($strUserAgent),"windows")) > 0) {
// IF USERAGENT CONTAINS OPERA
$strText = "<a href=\"http://www.opera.com/browser/download/\" target=\"_blank\" rel=\"nofollow\"><img src=\"" . $custom_module_path . "/images/icon-opera.png" . "\" /> Upgrade to version ";
if(strlen(strstr(strtolower($strUserAgent),"macintosh")) > 0)
$strText = $strText . variable_get('mac-opera','') . "</a>";
else
$strText = $strText . variable_get('win-opera','') . "</a>";
} else if(strlen(strstr(strtolower($strUserAgent),"chrome")) > 0 && strlen(strstr(strtolower($strUserAgent),"macintosh")) > 0 || strlen(strstr(strtolower($strUserAgent),"chrome")) > 0 && strlen(strstr(strtolower($strUserAgent),"windows")) > 0) {
// IF USERAGENT CONTAINS CHROME
$strText = "<a href=\"http://www.google.com/chrome\" target=\"_blank\" rel=\"nofollow\"><img src=\"" . $custom_module_path . "/images/icon-chrome.png" . "\" /> Upgrade to version ";
if(strlen(strstr(strtolower($strUserAgent),"macintosh")) > 0)
$strText = $strText . variable_get('mac-chrome','') . "</a>";
else
$strText = $strText . variable_get('win-chrome','') . "</a>";
} else if(strlen(strstr(strtolower($strUserAgent),"safari")) > 0 && strlen(strstr(strtolower($strUserAgent),"iphone")) < 1 && strlen(strstr(strtolower($strUserAgent),"macintosh")) > 0 || strlen(strstr(strtolower($strUserAgent),"safari")) > 0 && strlen(strstr(strtolower($strUserAgent),"iphone")) < 1 && strlen(strstr(strtolower($strUserAgent),"windows")) > 0) {
// IF USERAGENT CONTAINS SAFARI, BUT NOT IPHONE
// IPHONE USERS CANNOT UPGRADE OUTSIDE ITUNES, SO THIS PLUGIN IS POINTLESS FOR THEM
// SAFARI CONDITION IS CALLED AFTER CROME BECAUE CHROME HAS SAFARI IN USERAGENT STRING
$strText = "<a href=\"http://www.apple.com/safari/download/\" target=\"_blank\" rel=\"nofollow\"><img src=\"" . $custom_module_path . "/images/icon-safari.png" . "\" /> Upgrade to version ";
if(strlen(strstr(strtolower($strUserAgent),"macintosh")) > 0)
$strText = $strText . variable_get('mac-safari','') . "</a>";
else
$strText = $strText . variable_get('win-safari','') . "</a>";
} // ELSE MUST BE LINUX OR A MINOR BROWSER
$block['content'] .= "<div id=\"cssNewestBrowser\">" . $strText . "<br /><a href=\"http://www.chriswashington.net/projects/newest-browser-for-drupal\" title=\"Newest Browser module powered by CW Web Solutions LLC\" target=\"_blank\"><img src=\"" . $custom_module_path . "/images/icon.png" . "\" style=\"float:right;\" /></a></div></div>";
break;
};
$block['content'] .= "<div id=\"cssCWWSClear\" />";
$block['content'] = $block['content'];
return $block;
}
}
/* DELETE VARIABLES - hook_uninstall */
function newestbrowser_uninstall() {
variable_del('promote');
variable_del('lastupdated');
variable_del('win-ie');
variable_del('mac-ff');
variable_del('win-ff');
variable_del('mac-opera');
variable_del('win-opera');
variable_del('mac-chrome');
variable_del('win-chrome');
variable_del('mac-safari');
variable_del('win-safari');
}
?>
#cssNewestBrowser {
/* CHANGE FONT SIZE STYLING HERE */
}
#cssNewestBrowser img {
border:none;
padding:0px;
margin:0px;
vertical-align:middle;
}
#cssCWWSClear {
clear:both;
}