diff --git a/mobilepress.php b/mobilepress.php index b3c54b0..79826d6 100644 --- a/mobilepress.php +++ b/mobilepress.php @@ -3,7 +3,7 @@ Plugin Name: MobilePress Plugin URI: http://mobilepress.co.za Description: Turn your WordPress blog into a mobile website/blog. -Version: 1.1.4 +Version: 1.1.5 Author: Aduity Author URI: http://aduity.com @@ -63,7 +63,7 @@ } // Load the ad/analytics helpers - require_once(dirname(__FILE__) . '/system/helpers/ad_analytics_functions.php'); + require_once(dirname(__FILE__) . '/system/helpers/ad_functions.php'); // Initialize the MobilePress check logic and rendering $mobilepress->load_site(); diff --git a/readme.txt b/readme.txt index 9ec3f8e..bc20ec5 100644 --- a/readme.txt +++ b/readme.txt @@ -3,7 +3,7 @@ Contributors: mattgeri, tylerreed Tags: mobile, iphone, android, mobilepress, cell phone, cellphone, handset, nokia, motorola, att, sprint, verizon, blackberry, palm, windows ce, opera, operamini, opera mini, google, yahoo, plugin, comments, posts Requires at least: 2.3 Tested up to: 2.8.6 -Stable tag: 1.1.4 +Stable tag: 1.1.5 MobilePress is a WordPress plugin that will render your WordPress blog on mobile handsets, with the ability to use customized mobile themes, track analytics and diff --git a/system/classes/admin.php b/system/classes/admin.php index c2ce0b2..4f136c9 100644 --- a/system/classes/admin.php +++ b/system/classes/admin.php @@ -51,16 +51,18 @@ function initial_checks() * @package MobilePress * @since 1.1 */ - function render_ads_analytics() + function render_ads() { - if (isset($_POST['add'])) + if (isset($_POST['save'])) { global $wpdb; - // Options to be added $updates = array( 'aduity_account_public_key' => $_POST['apk'], - 'aduity_account_secret_key' => $_POST['ask'] + 'aduity_site_public_key' => $_POST['spk'], + 'aduity_ads_enabled' => $_POST['ads_enabled'], + 'aduity_debug_mode' => $_POST['debug_mode'], + 'aduity_ads_location' => $_POST['location'] ); // Update the options table @@ -77,176 +79,18 @@ function render_ads_analytics() ", $update) ); } - } - else if (isset($_POST['edit'])) - { - global $wpdb; - - if ( ! isset($_POST['error'])) - { - // Options to be edited - $updates = array( - 'aduity_account_public_key' => $_POST['apk'], - 'aduity_account_secret_key' => $_POST['ask'], - 'aduity_analytics_enabled' => $_POST['analytics_enabled'], - 'aduity_ads_enabled' => $_POST['ads_enabled'], - 'aduity_debug_mode' => $_POST['debug_mode'], - 'aduity_ads_type' => $_POST['type'], - 'aduity_ads_campaign' => $_POST['campaign'], - 'aduity_ads_ad' => $_POST['ad'], - 'aduity_ads_location' => $_POST['location'] - ); - } - else - { - // Options to be edited - $updates = array( - 'aduity_account_public_key' => $_POST['apk'], - 'aduity_account_secret_key' => $_POST['ask'] - ); - } - - // Update the options table - foreach ($updates as $name => $update) - { - $wpdb->query( - $wpdb->prepare(" - UPDATE - " . MOPR_TABLE . " - SET - option_value = '%s' - WHERE - option_name = '" . $name . "' - ", $update) - ); - } mopr_display_notice("
Options Saved
"); } - $apk = mopr_get_option('aduity_account_public_key'); - $ask = mopr_get_option('aduity_account_secret_key'); + $data['apk'] = mopr_get_option('aduity_account_public_key'); + $data['spk'] = mopr_get_option('aduity_site_public_key'); + $data['ads_enabled'] = mopr_get_option('aduity_ads_enabled'); + $data['debug_mode'] = mopr_get_option('aduity_debug_mode'); + $data['location'] = mopr_get_option('aduity_ads_location'); - // Check if they have setup their account yet - if ($apk == '' || $ask == '') - { - // Load ads and analytics setup view - mopr_load_view('admin_ads_analytics_setup'); - } - else - { - $data['apk'] = $apk; - $data['ask'] = $ask; - $data['analytics_enabled'] = mopr_get_option('aduity_analytics_enabled'); - $data['ads_enabled'] = mopr_get_option('aduity_ads_enabled'); - $data['debug_mode'] = mopr_get_option('aduity_debug_mode'); - $data['type'] = mopr_get_option('aduity_ads_type'); - $data['campaign'] = mopr_get_option('aduity_ads_campaign'); - $data['ad'] = mopr_get_option('aduity_ads_ad'); - $data['location'] = mopr_get_option('aduity_ads_location'); - - // Load libraries - $json = mopr_load_json_library(); - $aduity = mopr_load_aduity_api_library($apk, $ask); - - // Lets do some checks - $validate = $json->decode($aduity->request('validate')); - - if ($validate->response == 'ok') - { - // Lets get the url of their Aduity account - $data['url'] = $json->decode($aduity->request('get_account_url')); - $data['url'] = $data['url']->url; - - // Importantly, we need to make sure this blog matches a site added to their Aduity account - $sites = $json->decode($aduity->request('get_sites')); - $spk = mopr_get_option('aduity_site_public_key'); - - $domain = str_replace('http://', '', str_replace('https://', '', $_SERVER['HTTP_HOST'])); - $domain = str_replace('www.', '', $domain); - $domain = explode('/', $domain); - $domain = $domain[0]; - - if ($sites->response == 'ok') - { - foreach ($sites->sites as $site_data) - { - if ($domain == $site_data->site_domain) - { - if ($spk != $site_data->site_public_key) - { - global $wpdb; - - // Update site public key - $wpdb->query( - $wpdb->prepare(" - UPDATE - " . MOPR_TABLE . " - SET - option_value = '%s' - WHERE - option_name = 'aduity_site_public_key' - ", $site_data->site_public_key) - ); - - $updated = TRUE; - } - else if ($spk == $site_data->site_public_key) - { - $updated = TRUE; - } - } - } - } - - if ( ! isset($updated)) - { - // Display site error - mopr_display_notice('This domain has not been added to your Aduity account, please add it.
'); - } - - if ($data['debug_mode']) - { - // Display debug warning - mopr_display_notice('Warning! Debug mode is enabled, thus ads will be displayed but not counted and analytics will not be tracked
'); - } - - // Get campaigns - $data['campaigns'] = $json->decode($aduity->request('get_campaigns')); - - if ($data['campaigns']->response == 'ok') - { - $data['campaigns'] = $data['campaigns']->campaigns; - } - else - { - $data['campaigns'] = NULL; - } - - // Get ads - $data['ads'] = $json->decode($aduity->request('get_ads')); - - if ($data['ads']->response == 'ok') - { - $data['ads'] = $data['ads']->ads; - } - else - { - $data['ads'] = NULL; - } - } - else if ($validate->response == 'error') - { - // Deal with validation error here - mopr_display_notice("Invalid account public key or account secret key, please check keys and try again.
"); - - // Tell view we have a validation error - $data['validation_error'] = TRUE; - } - - // Load ads and analytics view - mopr_load_view('admin_ads_analytics', $data); - } + // Load ads and analytics view + mopr_load_view('admin_ads', $data); } /** diff --git a/system/classes/core.php b/system/classes/core.php index 8f4ecb1..f5bc858 100644 --- a/system/classes/core.php +++ b/system/classes/core.php @@ -54,8 +54,8 @@ function load_admin() //Add the 'Themes' submenu to the MobilePress menu and render the page add_submenu_page('mobilepress', 'MobilePress Themes', 'Themes', 10, 'mobilepress-themes', array(&$MobilePress_admin, 'render_themes')); - //Add the 'Ads and Analytics' submenu to the MobilePress menu and render the page - add_submenu_page('mobilepress', 'MobilePress Ads and Analytics', 'Ads & Analytics', 10, 'mobilepress-ads-analytics', array(&$MobilePress_admin, 'render_ads_analytics')); + //Add the 'Ads' submenu to the MobilePress menu and render the page + add_submenu_page('mobilepress', 'MobilePress Ads', 'Mobile Ads', 10, 'mobilepress-ads', array(&$MobilePress_admin, 'render_ads')); } /** diff --git a/system/classes/install.php b/system/classes/install.php index 368f24f..46a8cd2 100644 --- a/system/classes/install.php +++ b/system/classes/install.php @@ -54,14 +54,9 @@ function add_defaults() ('iphone_theme', 'iphone', 'iPhone'), ('force_mobile', '0', ''), ('aduity_account_public_key', '', ''), - ('aduity_account_secret_key', '', ''), ('aduity_site_public_key', '', ''), ('aduity_ads_enabled', '0', ''), - ('aduity_analytics_enabled', '0', ''), ('aduity_debug_mode', '0', ''), - ('aduity_ads_type', '0', ''), - ('aduity_ads_campaign', '0', ''), - ('aduity_ads_ad', '0', ''), ('aduity_ads_location', '0', '') "; @@ -111,6 +106,9 @@ function upgrade() if (MOPR_DBVERSION < '1.1.1') $this->upgrade_111(); + + if (MOPR_DBVERSION < '1.1.5') + $this->upgrade_115(); // Change the version in the database to the latest version after upgrade $wpdb->query( @@ -269,6 +267,31 @@ function upgrade_111() $results = $wpdb->query($sql); } + + function upgrade_115() + { + global $wpdb; + + // Delete options we no longer need + $sql = "DELETE FROM " . MOPR_TABLE . " WHERE option_name = 'aduity_account_secret_key'"; + $delete = $wpdb->query($sql); + + // Delete options we no longer need + $sql = "DELETE FROM " . MOPR_TABLE . " WHERE option_name = 'analytics_enabled'"; + $delete = $wpdb->query($sql); + + // Delete options we no longer need + $sql = "DELETE FROM " . MOPR_TABLE . " WHERE option_name = 'aduity_ads_type'"; + $delete = $wpdb->query($sql); + + // Delete options we no longer need + $sql = "DELETE FROM " . MOPR_TABLE . " WHERE option_name = 'aduity_ads_campaign'"; + $delete = $wpdb->query($sql); + + // Delete options we no longer need + $sql = "DELETE FROM " . MOPR_TABLE . " WHERE option_name = 'aduity_ads_ad'"; + $delete = $wpdb->query($sql); + } } } ?> \ No newline at end of file diff --git a/system/helpers/ad_analytics_functions.php b/system/helpers/ad_analytics_functions.php deleted file mode 100644 index e657f0b..0000000 --- a/system/helpers/ad_analytics_functions.php +++ /dev/null @@ -1,94 +0,0 @@ - $campaign, 'ad_public_key' => $ad)); - } - else - { - aduity_display_ad(array('campaign_public_key' => $campaign)); - } - } - else - { - aduity_display_ad(); - } - } - else if ($ads_type == '2') - { - aduity_display_ad(array('network_ads' => 1)); - } - - return; - } -} - -if ( ! function_exists('mopr_analytics')) -{ - function mopr_analytics() - { - if ( ! mopr_get_option('aduity_analytics_enabled')) - { - return; - } - - // Include the Aduity library - require_once(MOPR_PATH . 'libraries/aduity_core.php'); - - $title = wp_title('', FALSE); - - if (is_home()) - { - $title = get_bloginfo('name'); - } - - aduity_analytics(array('page_title' => $title)); - } -} -?> \ No newline at end of file diff --git a/system/helpers/functions.php b/system/helpers/functions.php index beb465b..df256c7 100644 --- a/system/helpers/functions.php +++ b/system/helpers/functions.php @@ -153,34 +153,4 @@ function mopr_load_view($view, $vars = NULL) } } } - -if ( ! function_exists('mopr_load_json_library')) -{ - /** - * Loads the JSON library - * - * @package MobilePress - * @since 1.1 - */ - function mopr_load_json_library() - { - require_once(MOPR_PATH . 'libraries/json.php'); - return new Services_JSON(); - } -} - -if ( ! function_exists('mopr_load_aduity_api_library')) -{ - /** - * Loads the Aduity Library - * - * @package MobilePress - * @since 1.1 - */ - function mopr_load_aduity_api_library($apk, $ask) - { - require_once(MOPR_PATH . 'libraries/aduity_api.php'); - return new Aduity_api_request($apk, $ask); - } -} ?> \ No newline at end of file diff --git a/system/libraries/aduity_api.php b/system/libraries/aduity_api.php deleted file mode 100644 index 71f288e..0000000 --- a/system/libraries/aduity_api.php +++ /dev/null @@ -1,89 +0,0 @@ -apk = $apk; - $this->ask = $ask; - } - - function make_request() - { - // Open a new connection to the ad server - $conn = @fsockopen($this->api_uri, 80, $errno, $errstr, 5); - - if ( ! $conn) - { - return NULL; - } - else - { - $header = "GET /" . $this->version . $this->request_uri . " HTTP/1.0\r\n"; - $header .= "Host: " . $this->api_uri . "\r\n"; - $header .= "Connection: close\r\n\r\n"; - - fputs($conn, $header, strlen($header)); - - // Lets grab the JSON data - while ( ! feof($conn)) - { - $data = fgets($conn); - - if (isset($start_copy)) - { - $content .= $data; - } - - if ($data == "\r\n" && ! isset($start_copy)) - { - $start_copy = TRUE; - } - } - } - - fclose($conn); - - return $content; - } - - function request($request_type, $request_params = NULL) - { - // First lets set initial request URI vars - $this->request_uri = '?apk=' . $this->apk . '&ask=' . $this->ask; - - // Now deal with the request type - $this->_set_request_type($request_type); - - // Now we deal with parameters - if ($request_params != NULL && is_array($request_params)) - { - foreach ($request_params as $param => $value) - { - $this->_set_request_params($param, $value); - } - } - - // Now lets make and return the request - return $this->make_request(); - } - - function _set_request_params($param, $value) - { - $this->request_uri .= '&' . $param . '=' . $value; - } - - function _set_request_type($request_type) - { - $this->request_uri .= "&request_type=" . $request_type; - } - } -} -?> \ No newline at end of file diff --git a/system/libraries/aduity_core.php b/system/libraries/aduity_core.php index 82a7a19..fed444f 100644 --- a/system/libraries/aduity_core.php +++ b/system/libraries/aduity_core.php @@ -1,61 +1,23 @@ 1 - ); - - if (is_array($request_params)) - { - // Merge the request type and parameters - $request_data = array_merge($request_type, $request_params); - } - else - { - $request_data = $request_type; - } - - $request = new Aduity_request($request_data); - } -} - +define('ACCOUNT_PUBLIC_KEY', mopr_get_option('aduity_account_public_key')); +define('SITE_PUBLIC_KEY', mopr_get_option('aduity_site_public_key')); +// NO NEED TO EDIT ANYTHING BELOW THIS LINE if ( ! function_exists('aduity_display_ad')) { - function aduity_display_ad($request_params = NULL) + function aduity_display_ad($request_data = NULL) { - // Set the request type - $request_type = array( - 'request_type' => 2 - ); - - if (is_array($request_params)) - { - // Merge the request type and parameters - $request_data = array_merge($request_type, $request_params); - } - else - { - $request_data = $request_type; - } - // Make the request $request = new Aduity_request($request_data); } @@ -67,15 +29,10 @@ class Aduity_request { var $account_public_key = NULL; var $site_public_key = NULL; - var $campaign_public_key = NULL; - var $ad_public_key = NULL; var $ad_type = NULL; - var $keywords = NULL; - var $network_ads_only = NULL; - var $page_title = NULL; + var $request_server = 'r.aduity.com'; + var $version = 'v1'; var $request_data; - var $request_type; - var $request_server = 'r.aduity.com'; function Aduity_request($request_data) { @@ -86,63 +43,23 @@ function Aduity_request($request_data) // Set site public key $this->site_public_key = SITE_PUBLIC_KEY; - - // Set the request type for use throughout the class - $this->request_type = $request_data['request_type']; - - // Set campaign public key if available - if (array_key_exists('campaign_public_key', $request_data)) - $this->campaign_public_key = $request_data['campaign_public_key']; - - // Set the ad public key if available - if (array_key_exists('ad_public_key', $request_data)) - $this->ad_public_key = $request_data['ad_public_key']; - // Set the ad type if available - if (array_key_exists('ad_type', $request_data)) - $this->ad_type = $request_data['ad_type']; - - // Are we only displaying network ads? - if (array_key_exists('network_ads', $request_data)) - $this->network_ads_only = $request_data['network_ads']; - - // Set up our keywords if we have any - if (array_key_exists('keywords', $request_data)) - $this->keywords = $request_data['keywords']; - - // Setup the page title for analytics - if (array_key_exists('page_title', $request_data)) - $this->page_title = $request_data['page_title']; + if (is_array($request_data)) + { + // Set the ad type if available + if (array_key_exists('ad_type', $request_data)) + $this->ad_type = $request_data['ad_type']; + } // Setup the data $this->_set_request_data(); - // Make the request - if ($this->request_type == 1) - { - $this->analytics_request(); - } - else if ($this->request_type == 2) - { - $this->ad_request(); - } + echo $this->make_request(); } return; } - function ad_request() - { - // Display the ad - echo $this->make_request(); - } - - function analytics_request() - { - // All we do for now is make the request - $this->make_request(); - } - function make_request() { // Open a new connection to the server @@ -154,7 +71,7 @@ function make_request() } else { - $header = "POST / HTTP/1.0\r\n"; + $header = "POST /" . $this->version . "/ HTTP/1.0\r\n"; $header .= "Host: " . $this->request_server . "\r\n"; $header .= "Content-Type: application/x-www-form-urlencoded\r\n"; $header .= "Content-Length: " . strlen($this->request_data) . "\r\n"; @@ -163,22 +80,20 @@ function make_request() fputs($conn, $header, strlen($header)); - if ($this->request_type == 2) + // Lets grab the ad code + while ( ! feof($conn)) { - // Lets grab the ad code - while ( ! feof($conn)) + $data = fgets($conn); + $content = ''; + + if (isset($start_copy)) + { + $content .= $data; + } + + if ($data == "\r\n" && ! isset($start_copy)) { - $data = fgets($conn); - - if (isset($start_copy)) - { - $content .= $data; - } - - if ($data == "\r\n" && ! isset($start_copy)) - { - $start_copy = TRUE; - } + $start_copy = TRUE; } } } @@ -196,45 +111,32 @@ function _set_request_data() // Create the data we need $this->request_data = '&apk=' . $this->account_public_key; - $this->request_data .= '&spk=' . $this->site_public_key; - - $this->request_data .= '&rt=' . $this->request_type; + $this->request_data .= '&ppk=' . $this->site_public_key; // We only need this data it is set and we are serving an ad - if (isset($this->campaign_public_key)) - $this->request_data .= '&cpk=' . $this->campaign_public_key; - - if (isset($this->ad_public_key)) - $this->request_data .= '&adpk=' . $this->ad_public_key; - if (isset($this->ad_type)) $this->request_data .= '&adt=' . $this->ad_type; - if (isset($this->keywords)) - $this->request_data .= '&kw=' . $this->keywords; - - if (isset($this->network_ads_only)) - $this->request_data .= '&na=' . $this->network_ads_only; + // some variables we can determine on our own + if (array_key_exists('HTTP_HOST', $_SERVER)) + $this->request_data .= '&sc=' . $_SERVER['HTTP_HOST']; - if (isset($this->page_title)) - $this->request_data .= '&pt=' . $this->page_title; + if (array_key_exists('REQUEST_URI', $_SERVER)) + $this->request_data .= '&sn=' . $_SERVER['REQUEST_URI']; - // some variables we can determine on our own - $this->request_data .= '&d=' . $_SERVER['HTTP_HOST']; - $this->request_data .= '&p=' . $_SERVER['REQUEST_URI']; - $this->request_data .= '&r=' . $_SERVER['HTTP_REFERER']; - $this->request_data .= '&t=' . time(); + if (array_key_exists('HTTP_REFERER', $_SERVER)) + $this->request_data .= '&rf=' . $_SERVER['HTTP_REFERER']; // is the user's brower Opera Mini? if (array_key_exists('HTTP_X_OPERAMINI_PHONE_UA', $_SERVER)) { $this->request_data .= '&ua=' . $_SERVER['HTTP_X_OPERAMINI_PHONE_UA']; - $this->request_data .= '&browser=1'; + $this->request_data .= '&br=1'; } else { $this->request_data .= '&ua=' . $_SERVER['HTTP_USER_AGENT']; - $this->request_data .= '&browser=0'; + $this->request_data .= '&br=0'; } if (array_key_exists('HTTP_X_FORWARDED_FOR', $_SERVER)) diff --git a/system/libraries/json.php b/system/libraries/json.php deleted file mode 100644 index b513791..0000000 --- a/system/libraries/json.php +++ /dev/null @@ -1,812 +0,0 @@ - - * @author Matt Knapp
- * // create a new instance of Services_JSON
- * $json = new Services_JSON();
- *
- * // convert a complexe value to JSON notation, and send it to the browser
- * $value = array('foo', 'bar', array(1, 2, 'baz'), array(3, array(4)));
- * $output = $json->encode($value);
- *
- * print($output);
- * // prints: ["foo","bar",[1,2,"baz"],[3,[4]]]
- *
- * // accept incoming POST data, assumed to be in JSON notation
- * $input = file_get_contents('php://input', 1000000);
- * $value = $json->decode($input);
- *
- */
-if ( ! class_exists('Services_JSON'))
-{
- class Services_JSON
- {
- /**
- * constructs a new JSON instance
- *
- * @param int $use object behavior flags; combine with boolean-OR
- *
- * possible values:
- * - SERVICES_JSON_LOOSE_TYPE: loose typing.
- * "{...}" syntax creates associative arrays
- * instead of objects in decode().
- * - SERVICES_JSON_SUPPRESS_ERRORS: error suppression.
- * Values which can't be encoded (e.g. resources)
- * appear as NULL instead of throwing errors.
- * By default, a deeply-nested resource will
- * bubble up with an error, so all return values
- * from encode() should be checked with isError()
- */
- function Services_JSON($use = 0)
- {
- $this->use = $use;
- }
-
- /**
- * convert a string from one UTF-16 char to one UTF-8 char
- *
- * Normally should be handled by mb_convert_encoding, but
- * provides a slower PHP-only method for installations
- * that lack the multibye string extension.
- *
- * @param string $utf16 UTF-16 character
- * @return string UTF-8 character
- * @access private
- */
- function utf162utf8($utf16)
- {
- // oh please oh please oh please oh please oh please
- if(function_exists('mb_convert_encoding')) {
- return mb_convert_encoding($utf16, 'UTF-8', 'UTF-16');
- }
-
- $bytes = (ord($utf16{0}) << 8) | ord($utf16{1});
-
- switch(true) {
- case ((0x7F & $bytes) == $bytes):
- // this case should never be reached, because we are in ASCII range
- // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
- return chr(0x7F & $bytes);
-
- case (0x07FF & $bytes) == $bytes:
- // return a 2-byte UTF-8 character
- // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
- return chr(0xC0 | (($bytes >> 6) & 0x1F))
- . chr(0x80 | ($bytes & 0x3F));
-
- case (0xFFFF & $bytes) == $bytes:
- // return a 3-byte UTF-8 character
- // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
- return chr(0xE0 | (($bytes >> 12) & 0x0F))
- . chr(0x80 | (($bytes >> 6) & 0x3F))
- . chr(0x80 | ($bytes & 0x3F));
- }
-
- // ignoring UTF-32 for now, sorry
- return '';
- }
-
- /**
- * convert a string from one UTF-8 char to one UTF-16 char
- *
- * Normally should be handled by mb_convert_encoding, but
- * provides a slower PHP-only method for installations
- * that lack the multibye string extension.
- *
- * @param string $utf8 UTF-8 character
- * @return string UTF-16 character
- * @access private
- */
- function utf82utf16($utf8)
- {
- // oh please oh please oh please oh please oh please
- if(function_exists('mb_convert_encoding')) {
- return mb_convert_encoding($utf8, 'UTF-16', 'UTF-8');
- }
-
- switch(strlen($utf8)) {
- case 1:
- // this case should never be reached, because we are in ASCII range
- // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
- return $utf8;
-
- case 2:
- // return a UTF-16 character from a 2-byte UTF-8 char
- // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
- return chr(0x07 & (ord($utf8{0}) >> 2))
- . chr((0xC0 & (ord($utf8{0}) << 6))
- | (0x3F & ord($utf8{1})));
-
- case 3:
- // return a UTF-16 character from a 3-byte UTF-8 char
- // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
- return chr((0xF0 & (ord($utf8{0}) << 4))
- | (0x0F & (ord($utf8{1}) >> 2)))
- . chr((0xC0 & (ord($utf8{1}) << 6))
- | (0x7F & ord($utf8{2})));
- }
-
- // ignoring UTF-32 for now, sorry
- return '';
- }
-
- /**
- * encodes an arbitrary variable into JSON format
- *
- * @param mixed $var any number, boolean, string, array, or object to be encoded.
- * see argument 1 to Services_JSON() above for array-parsing behavior.
- * if var is a strng, note that encode() always expects it
- * to be in ASCII or UTF-8 format!
- *
- * @return mixed JSON string representation of input var or an error if a problem occurs
- * @access public
- */
- function encode($var)
- {
- switch (gettype($var)) {
- case 'boolean':
- return $var ? 'true' : 'false';
-
- case 'NULL':
- return 'null';
-
- case 'integer':
- return (int) $var;
-
- case 'double':
- case 'float':
- return (float) $var;
-
- case 'string':
- // STRINGS ARE EXPECTED TO BE IN ASCII OR UTF-8 FORMAT
- $ascii = '';
- $strlen_var = strlen($var);
-
- /*
- * Iterate over every character in the string,
- * escaping with a slash or encoding to UTF-8 where necessary
- */
- for ($c = 0; $c < $strlen_var; ++$c) {
-
- $ord_var_c = ord($var{$c});
-
- switch (true) {
- case $ord_var_c == 0x08:
- $ascii .= '\b';
- break;
- case $ord_var_c == 0x09:
- $ascii .= '\t';
- break;
- case $ord_var_c == 0x0A:
- $ascii .= '\n';
- break;
- case $ord_var_c == 0x0C:
- $ascii .= '\f';
- break;
- case $ord_var_c == 0x0D:
- $ascii .= '\r';
- break;
-
- case $ord_var_c == 0x22:
- case $ord_var_c == 0x2F:
- case $ord_var_c == 0x5C:
- // double quote, slash, slosh
- $ascii .= '\\'.$var{$c};
- break;
-
- case (($ord_var_c >= 0x20) && ($ord_var_c <= 0x7F)):
- // characters U-00000000 - U-0000007F (same as ASCII)
- $ascii .= $var{$c};
- break;
-
- case (($ord_var_c & 0xE0) == 0xC0):
- // characters U-00000080 - U-000007FF, mask 110XXXXX
- // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
- $char = pack('C*', $ord_var_c, ord($var{$c + 1}));
- $c += 1;
- $utf16 = $this->utf82utf16($char);
- $ascii .= sprintf('\u%04s', bin2hex($utf16));
- break;
-
- case (($ord_var_c & 0xF0) == 0xE0):
- // characters U-00000800 - U-0000FFFF, mask 1110XXXX
- // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
- $char = pack('C*', $ord_var_c,
- ord($var{$c + 1}),
- ord($var{$c + 2}));
- $c += 2;
- $utf16 = $this->utf82utf16($char);
- $ascii .= sprintf('\u%04s', bin2hex($utf16));
- break;
-
- case (($ord_var_c & 0xF8) == 0xF0):
- // characters U-00010000 - U-001FFFFF, mask 11110XXX
- // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
- $char = pack('C*', $ord_var_c,
- ord($var{$c + 1}),
- ord($var{$c + 2}),
- ord($var{$c + 3}));
- $c += 3;
- $utf16 = $this->utf82utf16($char);
- $ascii .= sprintf('\u%04s', bin2hex($utf16));
- break;
-
- case (($ord_var_c & 0xFC) == 0xF8):
- // characters U-00200000 - U-03FFFFFF, mask 111110XX
- // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
- $char = pack('C*', $ord_var_c,
- ord($var{$c + 1}),
- ord($var{$c + 2}),
- ord($var{$c + 3}),
- ord($var{$c + 4}));
- $c += 4;
- $utf16 = $this->utf82utf16($char);
- $ascii .= sprintf('\u%04s', bin2hex($utf16));
- break;
-
- case (($ord_var_c & 0xFE) == 0xFC):
- // characters U-04000000 - U-7FFFFFFF, mask 1111110X
- // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
- $char = pack('C*', $ord_var_c,
- ord($var{$c + 1}),
- ord($var{$c + 2}),
- ord($var{$c + 3}),
- ord($var{$c + 4}),
- ord($var{$c + 5}));
- $c += 5;
- $utf16 = $this->utf82utf16($char);
- $ascii .= sprintf('\u%04s', bin2hex($utf16));
- break;
- }
- }
-
- return '"'.$ascii.'"';
-
- case 'array':
- /*
- * As per JSON spec if any array key is not an integer
- * we must treat the the whole array as an object. We
- * also try to catch a sparsely populated associative
- * array with numeric keys here because some JS engines
- * will create an array with empty indexes up to
- * max_index which can cause memory issues and because
- * the keys, which may be relevant, will be remapped
- * otherwise.
- *
- * As per the ECMA and JSON specification an object may
- * have any string as a property. Unfortunately due to
- * a hole in the ECMA specification if the key is a
- * ECMA reserved word or starts with a digit the
- * parameter is only accessible using ECMAScript's
- * bracket notation.
- */
-
- // treat as a JSON object
- if (is_array($var) && count($var) && (array_keys($var) !== range(0, sizeof($var) - 1))) {
- $properties = array_map(array($this, 'name_value'),
- array_keys($var),
- array_values($var));
-
- foreach($properties as $property) {
- if(Services_JSON::isError($property)) {
- return $property;
- }
- }
-
- return '{' . join(',', $properties) . '}';
- }
-
- // treat it like a regular array
- $elements = array_map(array($this, 'encode'), $var);
-
- foreach($elements as $element) {
- if(Services_JSON::isError($element)) {
- return $element;
- }
- }
-
- return '[' . join(',', $elements) . ']';
-
- case 'object':
- $vars = get_object_vars($var);
-
- $properties = array_map(array($this, 'name_value'),
- array_keys($vars),
- array_values($vars));
-
- foreach($properties as $property) {
- if(Services_JSON::isError($property)) {
- return $property;
- }
- }
-
- return '{' . join(',', $properties) . '}';
-
- default:
- return ($this->use & SERVICES_JSON_SUPPRESS_ERRORS)
- ? 'null'
- : new Services_JSON_Error(gettype($var)." can not be encoded as JSON string");
- }
- }
-
- /**
- * array-walking function for use in generating JSON-formatted name-value pairs
- *
- * @param string $name name of key to use
- * @param mixed $value reference to an array element to be encoded
- *
- * @return string JSON-formatted name-value pair, like '"name":value'
- * @access private
- */
- function name_value($name, $value)
- {
- $encoded_value = $this->encode($value);
-
- if(Services_JSON::isError($encoded_value)) {
- return $encoded_value;
- }
-
- return $this->encode(strval($name)) . ':' . $encoded_value;
- }
-
- /**
- * reduce a string by removing leading and trailing comments and whitespace
- *
- * @param $str string string value to strip of comments and whitespace
- *
- * @return string string value stripped of comments and whitespace
- * @access private
- */
- function reduce_string($str)
- {
- $str = preg_replace(array(
-
- // eliminate single line comments in '// ...' form
- '#^\s*//(.+)$#m',
-
- // eliminate multi-line comments in '/* ... */' form, at start of string
- '#^\s*/\*(.+)\*/#Us',
-
- // eliminate multi-line comments in '/* ... */' form, at end of string
- '#/\*(.+)\*/\s*$#Us'
-
- ), '', $str);
-
- // eliminate extraneous space
- return trim($str);
- }
-
- /**
- * decodes a JSON string into appropriate variable
- *
- * @param string $str JSON-formatted string
- *
- * @return mixed number, boolean, string, array, or object
- * corresponding to given JSON input string.
- * See argument 1 to Services_JSON() above for object-output behavior.
- * Note that decode() always returns strings
- * in ASCII or UTF-8 format!
- * @access public
- */
- function decode($str)
- {
- $str = $this->reduce_string($str);
-
- switch (strtolower($str)) {
- case 'true':
- return true;
-
- case 'false':
- return false;
-
- case 'null':
- return null;
-
- default:
- $m = array();
-
- if (is_numeric($str)) {
- // Lookie-loo, it's a number
-
- // This would work on its own, but I'm trying to be
- // good about returning integers where appropriate:
- // return (float)$str;
-
- // Return float or int, as appropriate
- return ((float)$str == (integer)$str)
- ? (integer)$str
- : (float)$str;
-
- } elseif (preg_match('/^("|\').*(\1)$/s', $str, $m) && $m[1] == $m[2]) {
- // STRINGS RETURNED IN UTF-8 FORMAT
- $delim = substr($str, 0, 1);
- $chrs = substr($str, 1, -1);
- $utf8 = '';
- $strlen_chrs = strlen($chrs);
-
- for ($c = 0; $c < $strlen_chrs; ++$c) {
-
- $substr_chrs_c_2 = substr($chrs, $c, 2);
- $ord_chrs_c = ord($chrs{$c});
-
- switch (true) {
- case $substr_chrs_c_2 == '\b':
- $utf8 .= chr(0x08);
- ++$c;
- break;
- case $substr_chrs_c_2 == '\t':
- $utf8 .= chr(0x09);
- ++$c;
- break;
- case $substr_chrs_c_2 == '\n':
- $utf8 .= chr(0x0A);
- ++$c;
- break;
- case $substr_chrs_c_2 == '\f':
- $utf8 .= chr(0x0C);
- ++$c;
- break;
- case $substr_chrs_c_2 == '\r':
- $utf8 .= chr(0x0D);
- ++$c;
- break;
-
- case $substr_chrs_c_2 == '\\"':
- case $substr_chrs_c_2 == '\\\'':
- case $substr_chrs_c_2 == '\\\\':
- case $substr_chrs_c_2 == '\\/':
- if (($delim == '"' && $substr_chrs_c_2 != '\\\'') ||
- ($delim == "'" && $substr_chrs_c_2 != '\\"')) {
- $utf8 .= $chrs{++$c};
- }
- break;
-
- case preg_match('/\\\u[0-9A-F]{4}/i', substr($chrs, $c, 6)):
- // single, escaped unicode character
- $utf16 = chr(hexdec(substr($chrs, ($c + 2), 2)))
- . chr(hexdec(substr($chrs, ($c + 4), 2)));
- $utf8 .= $this->utf162utf8($utf16);
- $c += 5;
- break;
-
- case ($ord_chrs_c >= 0x20) && ($ord_chrs_c <= 0x7F):
- $utf8 .= $chrs{$c};
- break;
-
- case ($ord_chrs_c & 0xE0) == 0xC0:
- // characters U-00000080 - U-000007FF, mask 110XXXXX
- //see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
- $utf8 .= substr($chrs, $c, 2);
- ++$c;
- break;
-
- case ($ord_chrs_c & 0xF0) == 0xE0:
- // characters U-00000800 - U-0000FFFF, mask 1110XXXX
- // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
- $utf8 .= substr($chrs, $c, 3);
- $c += 2;
- break;
-
- case ($ord_chrs_c & 0xF8) == 0xF0:
- // characters U-00010000 - U-001FFFFF, mask 11110XXX
- // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
- $utf8 .= substr($chrs, $c, 4);
- $c += 3;
- break;
-
- case ($ord_chrs_c & 0xFC) == 0xF8:
- // characters U-00200000 - U-03FFFFFF, mask 111110XX
- // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
- $utf8 .= substr($chrs, $c, 5);
- $c += 4;
- break;
-
- case ($ord_chrs_c & 0xFE) == 0xFC:
- // characters U-04000000 - U-7FFFFFFF, mask 1111110X
- // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
- $utf8 .= substr($chrs, $c, 6);
- $c += 5;
- break;
-
- }
-
- }
-
- return $utf8;
-
- } elseif (preg_match('/^\[.*\]$/s', $str) || preg_match('/^\{.*\}$/s', $str)) {
- // array, or object notation
-
- if ($str{0} == '[') {
- $stk = array(SERVICES_JSON_IN_ARR);
- $arr = array();
- } else {
- if ($this->use & SERVICES_JSON_LOOSE_TYPE) {
- $stk = array(SERVICES_JSON_IN_OBJ);
- $obj = array();
- } else {
- $stk = array(SERVICES_JSON_IN_OBJ);
- $obj = new stdClass();
- }
- }
-
- array_push($stk, array('what' => SERVICES_JSON_SLICE,
- 'where' => 0,
- 'delim' => false));
-
- $chrs = substr($str, 1, -1);
- $chrs = $this->reduce_string($chrs);
-
- if ($chrs == '') {
- if (reset($stk) == SERVICES_JSON_IN_ARR) {
- return $arr;
-
- } else {
- return $obj;
-
- }
- }
-
- //print("\nparsing {$chrs}\n");
-
- $strlen_chrs = strlen($chrs);
-
- for ($c = 0; $c <= $strlen_chrs; ++$c) {
-
- $top = end($stk);
- $substr_chrs_c_2 = substr($chrs, $c, 2);
-
- if (($c == $strlen_chrs) || (($chrs{$c} == ',') && ($top['what'] == SERVICES_JSON_SLICE))) {
- // found a comma that is not inside a string, array, etc.,
- // OR we've reached the end of the character list
- $slice = substr($chrs, $top['where'], ($c - $top['where']));
- array_push($stk, array('what' => SERVICES_JSON_SLICE, 'where' => ($c + 1), 'delim' => false));
- //print("Found split at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n");
-
- if (reset($stk) == SERVICES_JSON_IN_ARR) {
- // we are in an array, so just push an element onto the stack
- array_push($arr, $this->decode($slice));
-
- } elseif (reset($stk) == SERVICES_JSON_IN_OBJ) {
- // we are in an object, so figure
- // out the property name and set an
- // element in an associative array,
- // for now
- $parts = array();
-
- if (preg_match('/^\s*(["\'].*[^\\\]["\'])\s*:\s*(\S.*),?$/Uis', $slice, $parts)) {
- // "name":value pair
- $key = $this->decode($parts[1]);
- $val = $this->decode($parts[2]);
-
- if ($this->use & SERVICES_JSON_LOOSE_TYPE) {
- $obj[$key] = $val;
- } else {
- $obj->$key = $val;
- }
- } elseif (preg_match('/^\s*(\w+)\s*:\s*(\S.*),?$/Uis', $slice, $parts)) {
- // name:value pair, where name is unquoted
- $key = $parts[1];
- $val = $this->decode($parts[2]);
-
- if ($this->use & SERVICES_JSON_LOOSE_TYPE) {
- $obj[$key] = $val;
- } else {
- $obj->$key = $val;
- }
- }
-
- }
-
- } elseif ((($chrs{$c} == '"') || ($chrs{$c} == "'")) && ($top['what'] != SERVICES_JSON_IN_STR)) {
- // found a quote, and we are not inside a string
- array_push($stk, array('what' => SERVICES_JSON_IN_STR, 'where' => $c, 'delim' => $chrs{$c}));
- //print("Found start of string at {$c}\n");
-
- } elseif (($chrs{$c} == $top['delim']) &&
- ($top['what'] == SERVICES_JSON_IN_STR) &&
- ((strlen(substr($chrs, 0, $c)) - strlen(rtrim(substr($chrs, 0, $c), '\\'))) % 2 != 1)) {
- // found a quote, we're in a string, and it's not escaped
- // we know that it's not escaped becase there is _not_ an
- // odd number of backslashes at the end of the string so far
- array_pop($stk);
- //print("Found end of string at {$c}: ".substr($chrs, $top['where'], (1 + 1 + $c - $top['where']))."\n");
-
- } elseif (($chrs{$c} == '[') &&
- in_array($top['what'], array(SERVICES_JSON_SLICE, SERVICES_JSON_IN_ARR, SERVICES_JSON_IN_OBJ))) {
- // found a left-bracket, and we are in an array, object, or slice
- array_push($stk, array('what' => SERVICES_JSON_IN_ARR, 'where' => $c, 'delim' => false));
- //print("Found start of array at {$c}\n");
-
- } elseif (($chrs{$c} == ']') && ($top['what'] == SERVICES_JSON_IN_ARR)) {
- // found a right-bracket, and we're in an array
- array_pop($stk);
- //print("Found end of array at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n");
-
- } elseif (($chrs{$c} == '{') &&
- in_array($top['what'], array(SERVICES_JSON_SLICE, SERVICES_JSON_IN_ARR, SERVICES_JSON_IN_OBJ))) {
- // found a left-brace, and we are in an array, object, or slice
- array_push($stk, array('what' => SERVICES_JSON_IN_OBJ, 'where' => $c, 'delim' => false));
- //print("Found start of object at {$c}\n");
-
- } elseif (($chrs{$c} == '}') && ($top['what'] == SERVICES_JSON_IN_OBJ)) {
- // found a right-brace, and we're in an object
- array_pop($stk);
- //print("Found end of object at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n");
-
- } elseif (($substr_chrs_c_2 == '/*') &&
- in_array($top['what'], array(SERVICES_JSON_SLICE, SERVICES_JSON_IN_ARR, SERVICES_JSON_IN_OBJ))) {
- // found a comment start, and we are in an array, object, or slice
- array_push($stk, array('what' => SERVICES_JSON_IN_CMT, 'where' => $c, 'delim' => false));
- $c++;
- //print("Found start of comment at {$c}\n");
-
- } elseif (($substr_chrs_c_2 == '*/') && ($top['what'] == SERVICES_JSON_IN_CMT)) {
- // found a comment end, and we're in one now
- array_pop($stk);
- $c++;
-
- for ($i = $top['where']; $i <= $c; ++$i)
- $chrs = substr_replace($chrs, ' ', $i, 1);
-
- //print("Found end of comment at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n");
-
- }
-
- }
-
- if (reset($stk) == SERVICES_JSON_IN_ARR) {
- return $arr;
-
- } elseif (reset($stk) == SERVICES_JSON_IN_OBJ) {
- return $obj;
-
- }
-
- }
- }
- }
-
- /**
- * @todo Ultimately, this should just call PEAR::isError()
- */
- function isError($data, $code = null)
- {
- if (class_exists('pear')) {
- return PEAR::isError($data, $code);
- } elseif (is_object($data) && (get_class($data) == 'services_json_error' ||
- is_subclass_of($data, 'services_json_error'))) {
- return true;
- }
-
- return false;
- }
- }
-}
-
-if (class_exists('PEAR_Error')) {
-
- if ( ! class_exists('Services_JSON_Error'))
- {
- class Services_JSON_Error extends PEAR_Error
- {
- function Services_JSON_Error($message = 'unknown error', $code = null,
- $mode = null, $options = null, $userinfo = null)
- {
- parent::PEAR_Error($message, $code, $mode, $options, $userinfo);
- }
- }
- }
-
-} else {
-
- if ( ! class_exists('Services_JSON_Error'))
- {
- /**
- * @todo Ultimately, this class shall be descended from PEAR_Error
- */
- class Services_JSON_Error
- {
- function Services_JSON_Error($message = 'unknown error', $code = null,
- $mode = null, $options = null, $userinfo = null)
- {
-
- }
- }
- }
-
-}
-?>
\ No newline at end of file
diff --git a/system/themes/default/footer.php b/system/themes/default/footer.php
index 9f505d7..046f526 100644
--- a/system/themes/default/footer.php
+++ b/system/themes/default/footer.php
@@ -1,8 +1,8 @@