diff --git a/mobilepress.php b/mobilepress.php new file mode 100644 index 0000000..b3c54b0 --- /dev/null +++ b/mobilepress.php @@ -0,0 +1,87 @@ +create_admin(); + } + else + { + // Start a session if not started already + if ( ! session_id()) + { + @session_start(); + } + + // Load the ad/analytics helpers + require_once(dirname(__FILE__) . '/system/helpers/ad_analytics_functions.php'); + + // Initialize the MobilePress check logic and rendering + $mobilepress->load_site(); + } +} + +// Are we uninstalling the plugin? +if (function_exists('register_uninstall_hook')) +{ + register_uninstall_hook(__FILE__, 'mopr_load_uninstall'); +} + +if ( ! function_exists('mopr_load_uninstall')) +{ + function mopr_load_uninstall() + { + require_once(dirname(__FILE__) . '/system/classes/uninstall.php'); + $uninstall = new MobilePress_uninstall; + } +} +?> \ No newline at end of file diff --git a/readme.txt b/readme.txt new file mode 100644 index 0000000..9ec3f8e --- /dev/null +++ b/readme.txt @@ -0,0 +1,70 @@ +=== MobilePress === +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 + +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 +serve ads. + + +== Description == + +MobilePress is a WordPress plugin that will render your WordPress blog on mobile +handsets, with the ability to use customized themes. Built into MobilePress is the +ability to track your mobile sites analytics and serve ads with [Aduity.com](http://aduity.com). + +Integration with [Aduity.com](http://aduity.com) enables you to serve ads from some of the biggest +mobile ad networks such as Admob, Quattro Wireless, Buzzcity and InMobi. You can +also serve you own managed ads. You will also be able to track your visitors every +move with Aduity analytics. + +The plugin allows WordPress theme developers to create custom mobile themes for +MobilePress enabled blogs. Theme designers can create specific iPhone themes or +generic mobile themes for other mobile devices. + +MobilePress is SEO enabled and detects Google, Yahoo and MSN mobile search bots. +These mobile search engine bots will see the mobile version of your blog and get +your mobile site indexed in the mobile search results. + +For more information and a full set of docs, please visit the official MobilePress +website at [MobilePress.co.za](http://mobilepress.co.za) + + +== Installation == + +Installation instructions available at: [MobilePress.co.za](http://mobilepress.co.za/download/installation) + + +== Config & Settings == + +Once successfully installed, you will be presented with a few options. + += Blog Title = + +Changing this will replace the title of your blog when being viewed on a +mobile device. So, instead of "My cool blog", you could replace it with +something like "My mobile blog". This will not affect your site when being +viewed on a regular web browser. + += Blog Description = + +This is the same as changing your blog title, but will modify your blog's +description instead. + += Force Mobile Site = + +This option will force your site to be rendered as mobile, regardless of where +it is being viewed from. Regular web browsers will see the mobile version. + + +== Frequently Asked Questions == + +FAQ available at: [MobilePress.co.za](http://mobilepress.co.za/support) + + +== Screenshots == + +Screenshots are available at: [MobilePress.co.za](http://mobilepress.co.za) \ No newline at end of file diff --git a/system/classes/admin.php b/system/classes/admin.php new file mode 100644 index 0000000..c2ce0b2 --- /dev/null +++ b/system/classes/admin.php @@ -0,0 +1,645 @@ +
MobilePress table is empty!
'; + mopr_display_notice($message); + } + else + { + // Check if an upgrade is needed + if (MOPR_DBVERSION < MOPR_VERSION) + { + $message = ''; + mopr_display_notice($message); + } + } + } + else + { + // If the table doesnt exist throw message to create it + $message = ''; + mopr_display_notice($message); + } + } + + /** + * Renders the MobilePress ads and analytics page + * + * @package MobilePress + * @since 1.1 + */ + function render_ads_analytics() + { + if (isset($_POST['add'])) + { + global $wpdb; + + // Options to be added + $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) + ); + } + } + 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'); + + // 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); + } + } + + /** + * Renders the MobilePress options page + * + * @package MobilePress + * @since 1.0 + */ + function render_options() + { + if (isset($_POST['save'])) + { + global $wpdb; + + $themes_directory = trim($_POST['themes_directory'], '/'); + + // Options to be added + $updates = array( + 'title' => $_POST['title'], + 'description' => $_POST['description'], + 'force_mobile' => $_POST['force_mobile'], + 'themes_directory' => $themes_directory + ); + + // 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
"); + + $update_success = TRUE; + } + else if (isset($_POST['upgrade'])) + { + require_once(MOPR_PATH . 'classes/install.php'); + $upgrade = new MobilePress_install; + + mopr_display_notice("MobilePress Upgraded
"); + + $update_success = TRUE; + } + else if (isset($_POST['create'])) + { + require_once(MOPR_PATH . 'classes/install.php'); + $install = new MobilePress_install; + + mopr_display_notice("MobilePress table has been created
"); + + $update_success = TRUE; + } + else if (isset($_POST['add'])) + { + require_once(MOPR_PATH . 'classes/install.php'); + $install = new MobilePress_install; + $install->add_defaults(); + + mopr_display_notice("MobilePress options have been added to your table
"); + + $update_success = TRUE; + } + + // Options to send to view + $data['title'] = mopr_get_option('title', 1); + $data['description'] = mopr_get_option('description', 1); + $data['force_mobile'] = mopr_get_option('force_mobile', 1); + $data['themes_directory'] = mopr_get_option('themes_directory', 1); + + // Check if table exists and if version is out dated, display appropriate message + // Since we cannot redefine a constant (i.e. our version), we only run the checks if we have not just upgraded/updated + if ( ! isset($update_success)) + { + $this->initial_checks(); + } + + // Load options view + mopr_load_view('admin_options', $data); + } + + /** + * Renders the themes page + * + * @package MobilePress + * @since 1.0 + */ + function render_themes() + { + // What theme are we dealing with? + if (isset($_GET['section'])) + { + $section = $_GET['section']; + $current_theme = mopr_get_option($section, 2); + + if ($section == 'iphone_theme') + { + $data['browser'] = "iPhone Browser"; + } + else if ($section == 'default_theme') + { + $data['browser'] = "Default Browser"; + } + } + else + { + $section = "default_theme"; + $current_theme = mopr_get_option($section, 2); + $data['browser'] = "Default Browser"; + } + + // Do we need to activate a theme? + if (isset($_GET['action']) == "activate") + { + global $wpdb; + + $template = $_GET['template']; + $theme_name = $_GET['theme']; + + $wpdb->query( + $wpdb->prepare(" + UPDATE + " . MOPR_TABLE . " + SET + option_value = '%s', + option_value_2 = '%s' + WHERE + option_name = '%s' + ", $template, $theme_name, $section) + ); + + $message = "" . $theme_name . " has been activated for the " . $data['browser'] . "
"; + + // Update the current theme (we've just changed it) + $current_theme = $theme_name; + + mopr_display_notice($message); + } + + // Check if table exists and if version is out dated, display appropriate message + $this->initial_checks(); + + // Data to be passed to view + $data['section'] = $section; + $data['current_theme'] = $current_theme; + $data['themes'] = $this->select_themes($section); + + // Load the theme view + mopr_load_view('admin_themes', $data); + } + + /** + * Function to check if themes exist and if default theme exists, if so, returns the themes + * + * @package MobilePress + * @since 1.1.1 + */ + function select_themes($section) + { + // Get the defaul themes + $default_themes = $this->get_themes(MOPR_ROOT_PATH . "system/themes"); + + // Get any themes from the users local theme directory + $local_themes = $this->get_themes(rtrim(WP_CONTENT_DIR, '/') . '/' . mopr_get_option('themes_directory', 1)); + + if (is_array($default_themes) && is_array($local_themes)) + { + // Merge themes + $themes = array_merge($default_themes, $local_themes); + ksort($themes); + } + else if (is_array($default_themes)) + { + $themes = $default_themes; + ksort($themes); + } + else if (is_array($local_themes)) + { + $themes = $local_themes; + ksort($themes); + } + else + { + $themes = array(); + } + + if (empty($themes)) + { + $message = "Please upload a theme to your mobilepress themes directory!
"; + mopr_display_notice($message); + return false; + } + else + { + if (empty($themes['Default']['Title'])) + { + $message = "You need to upload the default theme!
"; + mopr_display_notice($message); + return false; + } + else + { + return $themes; + } + } + } + + // ---------------------------------------- + // CORE WORDPRESS FUNCTIONS FOR THEME VIEWS + // ---------------------------------------- + + /** + * Core WP function for getting themes (with a few modifications) - located at: wp-includes/theme.php + * + * @package MobilePress + * @since 1.0 + */ + function get_themes($directory) { + $themes = array(); + $theme_loc = $theme_root = $directory; + + // Files in wp-content/themes directory and one subdir down + $themes_dir = @ opendir($theme_root); + if ( !$themes_dir ) + return false; + + while ( ($theme_dir = readdir($themes_dir)) !== false ) { + if ( is_dir($theme_root . '/' . $theme_dir) && is_readable($theme_root . '/' . $theme_dir) ) { + if ( $theme_dir{0} == '.' || $theme_dir == '..' || $theme_dir == 'CVS' ) + continue; + $stylish_dir = @ opendir($theme_root . '/' . $theme_dir); + $found_stylesheet = false; + while ( ($theme_file = readdir($stylish_dir)) !== false ) { + if ( $theme_file == 'style.css' ) { + $theme_files[] = $theme_dir . '/' . $theme_file; + $found_stylesheet = true; + break; + } + } + @closedir($stylish_dir); + if ( !$found_stylesheet ) { // look for themes in that dir + $subdir = "$theme_root/$theme_dir"; + $subdir_name = $theme_dir; + $theme_subdir = @ opendir( $subdir ); + while ( ($theme_dir = readdir($theme_subdir)) !== false ) { + if ( is_dir( $subdir . '/' . $theme_dir) && is_readable($subdir . '/' . $theme_dir) ) { + if ( $theme_dir{0} == '.' || $theme_dir == '..' || $theme_dir == 'CVS' ) + continue; + $stylish_dir = @ opendir($subdir . '/' . $theme_dir); + $found_stylesheet = false; + while ( ($theme_file = readdir($stylish_dir)) !== false ) { + if ( $theme_file == 'style.css' ) { + $theme_files[] = $subdir_name . '/' . $theme_dir . '/' . $theme_file; + $found_stylesheet = true; + break; + } + } + @closedir($stylish_dir); + } + } + @closedir($theme_subdir); + $wp_broken_themes[$theme_dir] = array('Name' => $theme_dir, 'Title' => $theme_dir, 'Description' => __('Stylesheet is missing.')); + } + } + } + if ( is_dir( $theme_dir ) ) + @closedir( $theme_dir ); + + if ( !$themes_dir || !$theme_files ) + return $themes; + + sort($theme_files); + + foreach ( (array) $theme_files as $theme_file ) { + if ( !is_readable("$theme_root/$theme_file") ) { + $wp_broken_themes[$theme_file] = array('Name' => $theme_file, 'Title' => $theme_file, 'Description' => __('File not readable.')); + continue; + } + + $theme_data = get_theme_data("$theme_root/$theme_file"); + + $name = $theme_data['Name']; + $title = $theme_data['Title']; + $description = wptexturize($theme_data['Description']); + $version = $theme_data['Version']; + $author = $theme_data['Author']; + $template = $theme_data['Template']; + $stylesheet = dirname($theme_file); + + $screenshot = false; + foreach ( array('png', 'gif', 'jpg', 'jpeg') as $ext ) { + if (file_exists("$theme_root/$stylesheet/screenshot.$ext")) { + $screenshot = "screenshot.$ext"; + break; + } + } + + if ( empty($name) ) { + $name = dirname($theme_file); + $title = $name; + } + + if ( empty($template) ) { + if ( file_exists(dirname("$theme_root/$theme_file/index.php")) ) + $template = dirname($theme_file); + else + continue; + } + + $template = trim($template); + + if ( !file_exists("$theme_root/$template/index.php") ) { + $parent_dir = dirname(dirname($theme_file)); + if ( file_exists("$theme_root/$parent_dir/$template/index.php") ) { + $template = "$parent_dir/$template"; + } else { + $wp_broken_themes[$name] = array('Name' => $name, 'Title' => $title, 'Description' => __('Template is missing.')); + continue; + } + } + + $stylesheet_files = array(); + $stylesheet_dir = @ dir("$theme_root/$stylesheet"); + if ( $stylesheet_dir ) { + while ( ($file = $stylesheet_dir->read()) !== false ) { + if ( !preg_match('|^\.+$|', $file) && preg_match('|\.css$|', $file) ) + $stylesheet_files[] = "$theme_loc/$stylesheet/$file"; + } + } + + $template_files = array(); + $template_dir = @ dir("$theme_root/$template"); + if ( $template_dir ) { + while(($file = $template_dir->read()) !== false) { + if ( !preg_match('|^\.+$|', $file) && preg_match('|\.php$|', $file) ) + $template_files[] = "$theme_loc/$template/$file"; + } + } + + $template_dir = dirname($template_files[0]); + $stylesheet_dir = dirname($stylesheet_files[0]); + + if ( empty($template_dir) ) + $template_dir = '/'; + if ( empty($stylesheet_dir) ) + $stylesheet_dir = '/'; + + // Check for theme name collision. This occurs if a theme is copied to + // a new theme directory and the theme header is not updated. Whichever + // theme is first keeps the name. Subsequent themes get a suffix applied. + // The Default always trump their pretenders. + if ( isset($themes[$name]) ) { + if ( ('Default' == $name) && + ('default' == $stylesheet) ) { + // If another theme has claimed to be one of our default themes, move + // them aside. + $suffix = $themes[$name]['Stylesheet']; + $new_name = "$name/$suffix"; + $themes[$new_name] = $themes[$name]; + $themes[$new_name]['Name'] = $new_name; + } else { + $name = "$name/$stylesheet"; + } + } + + $themes[$name] = array('Name' => $name, 'Title' => $title, 'Description' => $description, 'Author' => $author, 'Version' => $version, 'Template' => $template, 'Stylesheet' => $stylesheet, 'Template Files' => $template_files, 'Stylesheet Files' => $stylesheet_files, 'Template Dir' => $template_dir, 'Stylesheet Dir' => $stylesheet_dir, 'Status' => $theme_data['Status'], 'Screenshot' => $screenshot, 'Tags' => $theme_data['Tags'], 'Theme Root' => $theme_root, 'Theme Root URI' => str_replace( WP_CONTENT_DIR, content_url(), $theme_root ) ); + } + + // Resolve theme dependencies. + $theme_names = array_keys($themes); + + foreach ( (array) $theme_names as $theme_name ) { + $themes[$theme_name]['Parent Theme'] = ''; + if ( $themes[$theme_name]['Stylesheet'] != $themes[$theme_name]['Template'] ) { + foreach ( (array) $theme_names as $parent_theme_name ) { + if ( ($themes[$parent_theme_name]['Stylesheet'] == $themes[$parent_theme_name]['Template']) && ($themes[$parent_theme_name]['Template'] == $themes[$theme_name]['Template']) ) { + $themes[$theme_name]['Parent Theme'] = $themes[$parent_theme_name]['Name']; + break; + } + } + } + } + + return $themes; + } + } +} +?> \ No newline at end of file diff --git a/system/classes/check.php b/system/classes/check.php new file mode 100644 index 0000000..c7cad3f --- /dev/null +++ b/system/classes/check.php @@ -0,0 +1,89 @@ +theme = mopr_get_option('default_theme', 1); + + // If viewing the mobile website + switch(TRUE) + { + // ?mobile accesses the mobile version of the website + case (isset($_GET['mobile'])): + $browser = "mobile"; + $activated = TRUE; + break; + + // If forcing iphone theme + case (isset($_GET['iphone'])): + $browser = "iphone"; + $activated = TRUE; + $theme = mopr_get_option('iphone_theme',1); + break; + + // ?nomobile renders the orignial website + case (isset($_GET['nomobile'])): + $activated = FALSE; + $theme = ''; + break; + + // Apple/iPhone browser renders as mobile + case (preg_match('/(apple|iphone|ipod)/i', $_SERVER['HTTP_USER_AGENT']) && preg_match('/mobile/i', $_SERVER['HTTP_USER_AGENT'])): + $browser = "iphone"; + $activated = TRUE; + $theme = mopr_get_option('iphone_theme',1); + break; + + // Other mobile browsers render as mobile + case (preg_match('/(blackberry|configuration\/cldc|hp |hp-|htc |htc_|htc-|iemobile|kindle|midp|mmp|motorola|mobile|nokia|opera mini|opera mobi|palm|palmos|pocket|portalmmm|ppc;|smartphone|sonyericsson|sqh|spv|symbian|treo|up.browser|up.link|vodafone|windows ce|xda |xda_)/i', $_SERVER['HTTP_USER_AGENT'])): + $browser = "mobile"; + $activated = TRUE; + break; + + // Wap browser + case (((strpos(strtolower($_SERVER['HTTP_ACCEPT']),'text/vnd.wap.wml') > 0) || (strpos(strtolower($_SERVER['HTTP_ACCEPT']),'application/vnd.wap.xhtml+xml')>0)) || ((isset($_SERVER['HTTP_X_WAP_PROFILE']) || isset($_SERVER['HTTP_PROFILE'])))): + $activated = TRUE; + break; + + // Shortend user agents + case (in_array(strtolower(substr($_SERVER['HTTP_USER_AGENT'],0,3)),array('lg '=>'lg ','lg-'=>'lg-','lg_'=>'lg_','lge'=>'lge'))); + $browser = "mobile"; + $activated = TRUE; + break; + + // More shortend user agents + case (in_array(strtolower(substr($_SERVER['HTTP_USER_AGENT'],0,4)),array('acs-'=>'acs-','amoi'=>'amoi','doco'=>'doco','eric'=>'eric','huaw'=>'huaw','lct_'=>'lct_','leno'=>'leno','mobi'=>'mobi','mot-'=>'mot-','moto'=>'moto','nec-'=>'nec-','phil'=>'phil','sams'=>'sams','sch-'=>'sch-','shar'=>'shar','sie-'=>'sie-','wap_'=>'wap_','zte-'=>'zte-'))); + $browser = "mobile"; + $activated = TRUE; + break; + + // Render mobile site for mobile search engines + case (preg_match('/Googlebot-Mobile/i', $_SERVER['HTTP_USER_AGENT']) || preg_match('/YahooSeeker\/M1A1-R2D2/i', $_SERVER['HTTP_USER_AGENT'])): + $browser = "mobile"; + $activated = TRUE; + break; + } + + $_SESSION['MOPR_MOBILE_BROWSER'] = $browser; + $_SESSION['MOPR_MOBILE_ACTIVE'] = $activated; + $_SESSION['MOPR_MOBILE_THEME'] = $theme; + } + + } +} +?> \ No newline at end of file diff --git a/system/classes/core.php b/system/classes/core.php new file mode 100644 index 0000000..8f4ecb1 --- /dev/null +++ b/system/classes/core.php @@ -0,0 +1,137 @@ +init(); + } + + // Set the browser variable + $browser = $_SESSION['MOPR_MOBILE_BROWSER']; + + // This is for testing mobile themes in a normal browser and mobile browsers, resets browser session if you are switching between mobile browsers + if ((isset($_GET['mobile']) && ($browser != "mobile")) || (isset($_GET['iphone']) && ($browser != "iphone"))) + { + require_once(MOPR_PATH . 'classes/check.php'); + $checkmobile = new MobilePress_check; + $checkmobile->init(); + + // Reset the browser variable + $browser = $_SESSION['MOPR_MOBILE_BROWSER']; + } + + if ($_SESSION['MOPR_MOBILE_ACTIVE'] === TRUE) + { + // Double check session var for theme, fall back on default if any problems + if ( ! isset($_SESSION['MOPR_MOBILE_THEME']) || (trim($_SESSION['MOPR_MOBILE_THEME']) == '')) + { + $_SESSION['MOPR_MOBILE_THEME'] = mopr_get_option('default_theme', 1); + } + + // Render time! + require_once(MOPR_PATH . 'classes/render.php'); + $render = new MobilePress_render(); + $render->init(); + } + else + { + // MOPR_MOBILE_ACTIVE has explicitly been set to false. Either by following nomobile link, or there were no matches in the detection script (We're using a web browser) + } + } + + } +} +?> \ No newline at end of file diff --git a/system/classes/install.php b/system/classes/install.php new file mode 100644 index 0000000..368f24f --- /dev/null +++ b/system/classes/install.php @@ -0,0 +1,274 @@ +upgrade(); + } + else + { + $this->setup_table(); + $this->add_defaults(); + } + } + + /** + * Inserts default values into the MobilePress database + * + * @package MobilePress + * @since 1.0 + */ + function add_defaults() + { + global $wpdb; + + // Add default options + $sql = "INSERT INTO " . MOPR_TABLE . " ( + option_name, + option_value, + option_value_2 + ) + VALUES + ('version', '" . MOPR_VERSION . "', ''), + ('title', '', ''), + ('description', '', ''), + ('themes_directory', 'mobile-themes', ''), + ('default_theme', 'default', 'Default'), + ('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', '') + "; + + $results = $wpdb->query($sql); + } + + /** + * Creates the MobilePress Table + * + * @package MobilePress + * @since 1.0 + */ + function setup_table() + { + $sql = " + CREATE TABLE " . MOPR_TABLE . " ( + id mediumint(9) NOT NULL AUTO_INCREMENT, + option_name VARCHAR(100) NOT NULL, + option_value VARCHAR(100) NOT NULL, + option_value_2 VARCHAR(100) NOT NULL, + UNIQUE KEY id (id)) + ENGINE = MYISAM + CHARACTER SET utf8 + COLLATE utf8_unicode_ci; + "; + + // Require upgrade.php from the CORE + require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); + dbDelta($sql); + } + + /** + * Upgrades the plugin database if it is outdated + * + * @package MobilePress + * @since 1.0.2 + */ + function upgrade() + { + global $wpdb; + + if (MOPR_DBVERSION < '1.0.2') + $this->upgrade_102(); + + if (MOPR_DBVERSION < '1.1') + $this->upgrade_110(); + + if (MOPR_DBVERSION < '1.1.1') + $this->upgrade_111(); + + // Change the version in the database to the latest version after upgrade + $wpdb->query( + $wpdb->prepare(" + UPDATE + " . MOPR_TABLE . " + SET + option_value = '%s' + WHERE + option_name = 'version' + ", MOPR_VERSION) + ); + } + + /** + * Critical upgrades for plugin version 1.0.2 and lower + * + * @package MobilePress + * @since 1.0.2 + */ + function upgrade_102() + { + global $wpdb; + + // First delete any duplicate DB entries that may have been caused by a bug prior to version 1.0.2 + $sql = "DELETE FROM " . MOPR_TABLE . " WHERE id > 11"; + $delete = $wpdb->query($sql); + + // Reset auto increment + $sql = "ALTER TABLE " . MOPR_TABLE . " AUTO_INCREMENT = 1"; + $reset = $wpdb->query($sql); + } + + /** + * Upgrades for plugin version 1.1 and lower + * + * @package MobilePress + * @since 1.1 + */ + function upgrade_110() + { + global $wpdb; + + // First we needa alter the option_value2 column name + $sql = "ALTER TABLE " . MOPR_TABLE . " CHANGE option_value2 option_value_2 VARCHAR(100) NOT NULL"; + $reset = $wpdb->query($sql); + + // Delete options we no longer need + $sql = "DELETE FROM " . MOPR_TABLE . " WHERE option_name = 'windowstheme'"; + $delete = $wpdb->query($sql); + + $sql = "DELETE FROM " . MOPR_TABLE . " WHERE option_name = 'operamtheme'"; + $delete = $wpdb->query($sql); + + $sql = "DELETE FROM " . MOPR_TABLE . " WHERE option_name = 'iswebbrowser_iphone'"; + $delete = $wpdb->query($sql); + + $sql = "DELETE FROM " . MOPR_TABLE . " WHERE option_name = 'iswebbrowser_windows'"; + $delete = $wpdb->query($sql); + + $sql = "DELETE FROM " . MOPR_TABLE . " WHERE option_name = 'iswebbrowser_operamini'"; + $delete = $wpdb->query($sql); + + // Update some changed options + $wpdb->query( + $wpdb->prepare(" + UPDATE + " . MOPR_TABLE . " + SET + option_name = '%s' + WHERE + option_name = 'defaulttheme' + ", "default_theme") + ); + + $wpdb->query( + $wpdb->prepare(" + UPDATE + " . MOPR_TABLE . " + SET + option_name = '%s' + WHERE + option_name = 'iphonetheme' + ", "iphone_theme") + ); + + $wpdb->query( + $wpdb->prepare(" + UPDATE + " . MOPR_TABLE . " + SET + option_name = '%s' + WHERE + option_name = 'forcemobile' + ", "force_mobile") + ); + + // Change option values from "true" to "1" and "false" to "0" + $wpdb->query( + $wpdb->prepare(" + UPDATE + " . MOPR_TABLE . " + SET + option_value = '%s' + WHERE + option_value = 'true' + ", "1") + ); + + $wpdb->query( + $wpdb->prepare(" + UPDATE + " . MOPR_TABLE . " + SET + option_value = '%s' + WHERE + option_value = 'false' + ", "0") + ); + + // Insert new options + $sql = "INSERT INTO " . MOPR_TABLE . " ( + option_name, + option_value, + option_value_2 + ) + VALUES + ('aduity_account_public_key', '', ''), + ('aduity_account_secret_key', '', ''), + ('aduity_site_public_key', '', ''), + ('aduity_ads_enabled', '0', ''), + ('aduity_analytics_enabled', '0', ''), + ('aduity_ads_type', '0', ''), + ('aduity_ads_campaign', '0', ''), + ('aduity_ads_ad', '0', ''), + ('aduity_ads_location', '0', '') + "; + + $results = $wpdb->query($sql); + } + + function upgrade_111() + { + global $wpdb; + + // Insert new options + $sql = "INSERT INTO " . MOPR_TABLE . " ( + option_name, + option_value, + option_value_2 + ) + VALUES + ('themes_directory', 'mobile-themes', ''), + ('aduity_debug_mode', '0', '') + "; + + $results = $wpdb->query($sql); + } + } +} +?> \ No newline at end of file diff --git a/system/classes/render.php b/system/classes/render.php new file mode 100644 index 0000000..5fdd6ff --- /dev/null +++ b/system/classes/render.php @@ -0,0 +1,189 @@ +default_theme = mopr_get_option('default_theme', 1); + $this->title = mopr_get_option('title', 1); + $this->description = mopr_get_option('description', 1); + } + + /** + * Initialize the rendering of the mobile website + * + * @package MobilePress + * @since 1.0 + */ + function init() + { + add_filter('stylesheet', array(&$this, 'set_stylesheet')); + add_filter('theme_root', array(&$this, 'set_theme_root')); + add_filter('theme_root_uri', array(&$this, 'set_theme_uri')); + add_filter('template', array(&$this, 'set_template')); + + if ($this->title != '') + { + add_filter('option_blogname', array(&$this, 'set_title')); + } + + if ($this->description != '') + { + add_filter('option_blogdescription', array(&$this, 'set_description')); + } + } + + /** + * Returns the mobile blogs description + * + * @package MobilePress + * @since 1.0 + * @return STRING The mobile blogs description + */ + function set_description() + { + return $this->description; + } + + /** + * Sets the stylesheet to the themes mobile stylesheet + * + * @package MobilePress + * @since 1.0 + * @return STRING Name of the theme where the stylesheet will be called + */ + function set_stylesheet() + { + if ( ! isset($_SESSION['MOPR_MOBILE_THEME']) || trim($_SESSION['MOPR_MOBILE_THEME']) == '') + { + $stylesheet = $this->default_theme; + } + else + { + $stylesheet = $_SESSION['MOPR_MOBILE_THEME']; + } + + return $stylesheet; + } + + /** + * Sets the blogs template to the MobilePress template + * + * @package MobilePress + * @since 1.0 + * @return STRING The name of the MobilePress template to be used for rendering + */ + function set_template() + { + if ( ! isset($_SESSION['MOPR_MOBILE_THEME']) || trim($_SESSION['MOPR_MOBILE_THEME']) == '') + { + $template = $this->default_theme; + } + else + { + $template = $_SESSION['MOPR_MOBILE_THEME']; + } + + return $template; + } + + /** + * Sets the theme root to the MobilePress theme directory + * + * @package MobilePress + * @since 1.0 + * @return STRING Root directory of the MobilePress theme directory + */ + function set_theme_root() + { + if ( ! isset($_SESSION['MOPR_MOBILE_THEME']) || trim($_SESSION['MOPR_MOBILE_THEME']) == '') + { + $template = $this->default_theme; + } + else + { + $template = $_SESSION['MOPR_MOBILE_THEME']; + } + + if ($template == 'default' || $template == 'iphone') + { + return MOPR_ROOT_PATH . "system/themes"; + } + else + { + return rtrim(WP_CONTENT_DIR, '/') . '/' . mopr_get_option('themes_directory', 1); + } + } + + /** + * Sets the path to the themes directory + * + * @package MobilePress + * @since 1.0 + * @return STRING The MobilePress theme directory + */ + function set_theme_uri() + { + if ( ! isset($_SESSION['MOPR_MOBILE_THEME']) || trim($_SESSION['MOPR_MOBILE_THEME']) == '') + { + $template = $this->default_theme; + } + else + { + $template = $_SESSION['MOPR_MOBILE_THEME']; + } + + if ($template == 'default' || $template == 'iphone') + { + return get_bloginfo('wpurl') . "/wp-content/plugins/mobilepress/system/themes"; + } + else + { + return get_bloginfo('wpurl') . "/wp-content/" . mopr_get_option('themes_directory', 1); + } + } + + /** + * Returns the mobile blogs title + * + * @package MobilePress + * @since 1.0 + * @return STRING The mobile blogs title + */ + function set_title() + { + return $this->title; + } + + } +} +?> \ No newline at end of file diff --git a/system/classes/uninstall.php b/system/classes/uninstall.php new file mode 100644 index 0000000..a71ebbd --- /dev/null +++ b/system/classes/uninstall.php @@ -0,0 +1,38 @@ +delete_table(); + } + + /** + * Deletes the MobilePress table + * + * @package MobilePress + * @since 1.0.2 + */ + function delete_table() + { + global $wpdb; + $sql = "DROP TABLE IF EXISTS " . MOPR_TABLE; + $wpdb->query($sql); + } + + } +} +?> \ No newline at end of file diff --git a/system/config/config.php b/system/config/config.php new file mode 100644 index 0000000..dbe12b1 --- /dev/null +++ b/system/config/config.php @@ -0,0 +1,11 @@ +prefix . 'mobilepress'); + +// For WP versions < 2.6 +if ( ! defined( 'WP_CONTENT_DIR' ) ) + define( 'WP_CONTENT_DIR', ABSPATH . 'wp-content' ); +?> \ No newline at end of file diff --git a/system/config/versions.php b/system/config/versions.php new file mode 100644 index 0000000..4abd213 --- /dev/null +++ b/system/config/versions.php @@ -0,0 +1,5 @@ + diff --git a/system/helpers/ad_analytics_functions.php b/system/helpers/ad_analytics_functions.php new file mode 100644 index 0000000..e657f0b --- /dev/null +++ b/system/helpers/ad_analytics_functions.php @@ -0,0 +1,94 @@ + $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 new file mode 100644 index 0000000..beb465b --- /dev/null +++ b/system/helpers/functions.php @@ -0,0 +1,186 @@ +get_var("SELECT COUNT(*) FROM " . MOPR_TABLE) == 0) + { + return TRUE; + } + else + { + return FALSE; + } + } +} + +if ( ! function_exists('mopr_check_table_exists')) +{ + /** + * Checks if the MobilePress table exists in the WordPress database + * + * @package MobilePress + * @since 1.0 + * @return BOOL True or false + */ + function mopr_check_table_exists() + { + global $wpdb; + + if ($wpdb->get_var("SHOW TABLES LIKE '" . MOPR_TABLE . "'") == MOPR_TABLE) + { + return TRUE; + } + else + { + return FALSE; + } + + } +} + +if ( ! function_exists('mopr_display_notice')) +{ + /** + * Displays an admin area notice + * + * @package MobilePress + * @since 1.0 + * @param STRING $notice The message you want to be displayed + */ + function mopr_display_notice($notice) + { + echo '
+ * // 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/archive.php b/system/themes/default/archive.php
new file mode 100644
index 0000000..5ea7b1b
--- /dev/null
+++ b/system/themes/default/archive.php
@@ -0,0 +1,43 @@
+
+
+ Sorry, The page you are looking for cannot be found!
+ + + + + +This post is password protected. Enter the password to view comments.
+says:
+ + comment_approved == '0') : ?> +Your comment is awaiting moderation.
+ +Posted on
+Be the first to leave a comment.
+Sorry, comments are closed on this post.
+
Post A Comment.
+