$value) { if(substr($key, 0, 10) == "_51d_cond_") $conditions[str_replace("_51d_cond_", "", $key)] = $value; } $updatedFilter['conditions'] = $conditions; $filters = get_option('51DFilterStore'); if($filters == false) $filters = array(); if($_POST['_51D_FilterName'] != $_POST['_51D_SubmitFilter']) { // renaming filter $newFilters = array(); foreach($filters as $key => $filter) { if($key == $_POST['_51D_SubmitFilter']) $newFilters[$_POST['_51D_FilterName']] = $updatedFilter; else $newFilters[$key] = $filter; } $filters = $newFilters; } else $filters[$_POST['_51D_FilterName']] = $updatedFilter; update_option('51DFilterStore', $filters); header('Location: '.add_query_arg( 'filter', $_POST['_51D_FilterName'] )); } function _51d_print_admin_panel() { if(file_exists(dirname(__FILE__).'/51Degrees/51Degrees.mobi.php')) { _51d_print_javascript(); ?>

51Degrees.mobi Device Detection

'; echo '
'; _51d_print_documentation(); echo '
'; _51d_print_settings(); echo '
'; _51d_print_license_section(); ?>

51Degrees.mobi Device Detection

51Degrees.mobi Device Detection cannot run as the plugin is unable to write files. This is necessary to create the data files needed for detection and to install mobile friendly themes. Please enable file writing, or unzip the 51Degrees data file at '' to '' manually.

Options saved.

Failed to save options. Error: get_message(); ?>

"IsMobile", "Small Screen Phone" => "IsSmallScreen", "SmartPhone" => "IsSmartPhone", "Tablet" => "IsTablet", "Console" => "IsConsole", "EReader" => "IsEReader"); $propertyDescriptions = array( "IsMobile" => "Indicates that the device's primary data connection is wireless and is designed to operate mostly from battery power (ie a mobile phone, smart phone or tablet etc)", "IsSmallScreen" => "Is a mobile device with a screen size smaller than 2 1/2 inches.", "IsSmartPhone" => "Is a mobile device with a screen size larger then 2 1/2 inches running a modern smart phone operating system including Android, iOS, BlackBerry or Windows Phone.", "IsTablet" => "The manufacturer of the device sells the device primarily as a tablet.", "IsConsole" => "Indicates if the device is neither a phone or a computer/tablet (ie a games console or television).", "IsEReader" => "Indicates if the device is an e-reader."); // this array will contain default properties that are not in the current data set $absentProp = array(); foreach($properties as $name => $property) { if(isset($_51d_meta_data[$property])) { echo ' '.$name.'

'.$propertyDescriptions[$property].'

'; } else $absentProp[$name] = $property; } if(count($absentProp) > 0) { ?>

Enable these Options

$property) { echo ' '.$name; echo '

'.$propertyDescriptions[$property].'

'; } } } function _51d_print_license_section() { global $_51d_meta_data; ?>

Upgrade Device Data (BETA)

If you have purchased a licence key for device data paste it into the text box below and select Update. This process requires your PHP environment to support file updates and outbound web connectivity.

Licence key: " />
Download Upgraded Plugin"; ?>

You can also copy the licence key into the 51Degrees.mobi Downloads page and download an upgraded plugin preloaded with current device data. You must delete the currently installed version of this plugin before uploading the upgraded one. Learn More

Data type: Published:

'; $filters = get_option('51DFilterStore'); if ($filters == false || count($filters) == 0) echo 'No rules have been created. Click the button above to create your first redirection rule.'; else { $keys = array_keys($filters); $GLOBALS['keys'] = &$keys; if(isset($_GET["filter"]) && isset($filters[$_GET["filter"]])) $selectedTab = $_GET["filter"]; else $selectedTab = $keys[0]; ?>

Use this screen to create rules that control if devices are sent to another page or served a different theme based on what kind of devices they are. Multiple rules can be created to do different things with different devices.

';//end of tabs _51d_print_filter_tab($keyIndex, $filters); } echo '
'; } function _51d_print_settings() { if(get_option('enable_51DUDP')) $udp_enabled = 'checked="checked"'; ?>

Global Settings

These settings control 51Degrees.mobi Device Detection on all pages in the site.

/> Share usage data with 51Degrees.mobi. Learn More

Documentation

For assistance, refer to help tab at the top of this page. You can also use the tooltips, or see our user guide and support forum.

$filter) { if($key == $insertedFilterKey) continue; if($key == $shiftedFilterKey) $newFilters[$insertedFilterKey] = $filters[$insertedFilterKey]; $newFilters[$key] = $filters[$key]; } if($shiftedFilterKey == '_LAST') $newFilters[$insertedFilterKey] = $filters[$insertedFilterKey]; update_option('51DFilterStore', $newFilters); header('Location: '.remove_query_arg('ShiftFilter')); } } if(isset($_GET['DeleteFilter'])) { $filters = get_option('51DFilterStore'); if($filters != false) { if(isset($filters[$_GET['DeleteFilter']])) { unset($filters[$_GET['DeleteFilter']]); update_option('51DFilterStore', $filters); } } $newUrl = remove_query_arg('DeleteFilter'); header('Location: '.remove_query_arg('filter', $newUrl)); exit; } // help section only supported in 3.3+ global $wp_version; $version = (float)substr($wp_version, 0, 3); if($version >= 3.3) { // The POSTS have been dealt with, add help to options screen $screen = get_current_screen(); // Add as many tabs as necessary $screen->add_help_tab( array( 'id' => 'property_help_overview', 'title' => __('Overview'), 'content' => '

' . __('Detection') . ' - ' . __('This plugin contains a small database capable of determining the requesting device\'s properties ' . 'extremely quickly using the finger prints (technically called useragents) sent by web browsers.') . '

' . '

' . __('Optimisation') . ' - ' . __('Knowledge of the requesting device\'s capabilities enables the theme to be tailored to the device, or ' . 'the request redirected to another web site. For example; rules can be defined to treat small screen ' . 'mobile devices, smartphones and tablets differently from each other. Adverts could be optimised for the ' . 'smaller screens, or content limited to the essential parts of a page.') . '

' ) ); $screen->add_help_tab( array( 'id' => 'property_help_rules', 'title' => __('Rules'), 'content' => '

' . __( 'At the top of the settings page are the rules tabs. Select Create Rule to add the first rule. Select ' . 'the tab name to change it to something more meaningful to you.' ) . '

' . '

' . __( 'Select the + symbol to add additional rules.' ) . '

' . '

' . __( 'Rules are evaluated in order from left to right. The first one which matches the requesting device ' . 'is used to control the response.' ) . '

' ) ); $screen->add_help_tab( array( 'id' => 'property_help_device_type', 'title' => __('Device Type'), 'content' => '

' . __( 'Below the Rules tabs are tick boxes for basic properties that can be used to adjust which types of ' . 'devices will be affected by the rule. Selecting one or more of these property tick boxes associates ' . 'the rule to the device type. For example; to apply a rule to Tablet devices only you would select the ' . 'Tablet tick box and none of the others.' ) . '

' . '

' . __( 'Within the Advanced Properties section it is possible to customise the rule using more ' . 'properties. For example; if you would like your rule to apply to devices with a screen resolution ' . 'of 800x480 pixels then you would select the IsMobile, ScreenPixelsHeight and ScreenPixelsHeight ' . 'tickboxes and set their Value boxes to True, 800 and 480 respectively.' ) . '

' ) ); $screen->add_help_tab( array( 'id' => 'property_help_action', 'title' => __('Action'), 'content' => '

' . __( 'The action controls how the site responds to requests from matching devices.' . 'Two possible actions are available:' ) . '

' . '
    ' . '
  1. ' . __( 'Change the theme to one more suited to the requesting devices capabilities. For example; on a small ' . 'screen devices removes less important content, or displays mobile optimised adverts.' ) . '
  2. ' . '
  3. ' . __( 'Redirect the request to another web site more suited to the device.' ) . '
  4. ' . '
' . '

' . __( 'A drop down list in the Action area contains a list of all the installed themes. One of these can be ' . 'chosen for use with the rule. Alternatively the [Redirect to url] option can be selected and a text ' . 'box will appear to the right of the drop down list. This is where a new Url can be placed to redirect ' . 'all requests from devices matching the rule.' ) . '

' ) ); $screen->set_help_sidebar( __('For more information:

Overview

Documentation

Upgrade Device Data

') ); } } function _51d_unzip_data() { // set_time_limit(0); // $dir = dirname(__FILE__); // WP_Filesystem(); // unzip_file($dir.'/51Degrees.mobi.php.zip', $dir); } function _51d_set_options() { // install themes $dir = dirname(__FILE__); $theme_directory = "$dir/themes/"; if(WP_Filesystem()) { $themes = glob($theme_directory . "*.zip"); foreach($themes as $theme) { $targetdir = get_theme_root().'/'; unzip_file($theme, $targetdir); } } add_option('51d_enable_udp', false); } function _51d_unset_options() { delete_option('51d_enable_udp'); delete_option('51DFilterStore'); delete_option('_51d_license_text'); } function _51d_admin_init() { // $dir = dirname(__FILE__); // if(file_exists($dir.'/51Degrees/51Degrees.mobi.php') == false) { // // check if a premium key is available // _51d_unzip_data(); // $license = get_option("_51d_license_text"); // } } function _51d_loadTemplateFilters($current) { return _51d_loadFilters($current, 'Template'); } function _51d_loadStylesheetFilters($current) { return _51d_loadFilters($current, 'Stylesheet'); } function _51d_loadFilters($currentTheme, $tag) { // only load themes on non admin pages if(!is_admin()) { //echo $currentTheme; //echo "Checking $tag"; $theme = _51d_checkFilters(); if(empty($theme)) return $currentTheme; return $theme[$tag]; } return $currentTheme; } function _51d_checkFilters() { // confirm that session is enabled for every request @session_start(); // check if user has requested not to be switched if(isset($_SESSION['NO_SWITCH']) && $_SESSION['NO_SWITCH'] == true) return false; // check if the browser has been detected already if(isset($_SESSION['_51d_themeName'])) return $_SESSION['_51d_themeName']; if(!isset($GLOBALS['_51d_themeName'])) { // get 51d data from global scope global $_51d; //checking device filters $filters = get_option('51DFilterStore'); if($filters != false) { foreach($filters as $filter) { if(isset($filter['conditions'])) { $validConditions = true; // check all conditions foreach($filter['conditions'] as $key => $condition) { if($condition == 'True' && $_51d[$key] != $condition) { $validConditions = false; break; } } if($validConditions == true && isset($filter['action'])) { if($filter['action'] == 'theme') { //change theme $theme = @get_theme($filter['theme']['Title']); if(!empty($theme)) { $GLOBALS['_51d_themeName'] = $theme; $_SESSION['_51d_theme_name'] = $theme; return $theme; } } else if($filter['action'] == 'redirect' && isset($filter['url'])) { header('Location: '.$filter['url']); exit; } break; } } } } // no filters, stored, carry on $GLOBALS['_51d_themeName'] = false; $_SESSION['_51d_theme_name'] = false; return false; } else return $GLOBALS['_51d_themeName']; } // add_action('admin_init', '_51d_admin_init'); add_action('admin_menu', '_51d_add_admin_menu'); add_filter('template', '_51d_loadTemplateFilters'); add_filter('stylesheet', '_51d_loadStylesheetFilters'); register_activation_hook(__FILE__,'_51d_set_options'); register_deactivation_hook(__FILE__,'_51d_unset_options'); ?>