Skip to content

Commit

Permalink
Changes for version 1.1.5. New Aduity platform support
Browse files Browse the repository at this point in the history
  • Loading branch information
MattGeri committed Jul 16, 2010
1 parent b8fa2a1 commit 06ba8c2
Show file tree
Hide file tree
Showing 14 changed files with 95 additions and 1,642 deletions.
4 changes: 2 additions & 2 deletions mobilepress.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
182 changes: 13 additions & 169 deletions system/classes/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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("<p><strong>Options Saved</strong></p>");
}

$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('<p><strong>This domain has not been added to your Aduity account, please <a href="' . $data['url'] . '/sites/create_site">add it</a>.</strong></p>');
}

if ($data['debug_mode'])
{
// Display debug warning
mopr_display_notice('<p><strong>Warning! Debug mode is enabled, thus ads will be displayed but not counted and analytics will not be tracked</strong></p>');
}

// 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("<p><strong>Invalid account public key or account secret key, please check keys and try again.</strong></p>");

// 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);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions system/classes/core.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
}

/**
Expand Down
33 changes: 28 additions & 5 deletions system/classes/install.php
Original file line number Diff line number Diff line change
Expand Up @@ -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', '')
";

Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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);
}
}
}
?>
94 changes: 0 additions & 94 deletions system/helpers/ad_analytics_functions.php

This file was deleted.

Loading

0 comments on commit 06ba8c2

Please sign in to comment.