Skip to content
This repository has been archived by the owner on Apr 24, 2019. It is now read-only.

Commit

Permalink
Did some major refactoring to pull out license logic into "Engine" fi…
Browse files Browse the repository at this point in the history
…les. This allows you to easily write your own serial number logic. Simply create your own subclass of class.engine.php and set your application to use that new class. The file class.enginemd5.php is a simple, working example.

Also, this new refactoring removes the old AquaticPrime ap.inc.php include file and moves all of that logic into the new AquaticPrime Engine file: class.engineaquaticprime.php
  • Loading branch information
Tyler Hall committed May 3, 2011
1 parent a8d6041 commit 5275a04
Show file tree
Hide file tree
Showing 9 changed files with 348 additions and 383 deletions.
157 changes: 84 additions & 73 deletions application.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,85 +12,98 @@

if($Error->ok())
{
$app = new Application($_GET['id']);
$app->name = $_POST['name'];
$app->link = $_POST['link'];
$app->bundle_name = $_POST['bundle_name'];
$app->i_use_this_key = $_POST['i_use_this_key'];
$app->s3key = $_POST['s3key'];
$app->s3pkey = $_POST['s3pkey'];
$app->s3bucket = $_POST['s3bucket'];
$app->s3path = $_POST['s3path'];
$app->sparkle_key = $_POST['sparkle_key'];
$app->sparkle_pkey = $_POST['sparkle_pkey'];
$app->ap_key = $_POST['ap_key'];
$app->ap_pkey = $_POST['ap_pkey'];
$app->custom_salt = $_POST['custom_salt'];
$app->license_type = $_POST['license_type'];
$app->from_email = $_POST['from_email'];
$app->email_subject = $_POST['email_subject'];
$app->email_body = $_POST['email_body'];
$app->license_filename = $_POST['license_filename'];
$app->return_url = $_POST['return_url'];
$app->fs_security_key = $_POST['fs_security_key'];
$app->tweet_terms = $_POST['tweet_terms'];
$app->upgrade_app_id = $_POST['upgrade_app_id'];
$app = new Application($_GET['id']);
$app->name = $_POST['name'];
$app->link = $_POST['link'];
$app->bundle_name = $_POST['bundle_name'];
$app->i_use_this_key = $_POST['i_use_this_key'];
$app->s3key = $_POST['s3key'];
$app->s3pkey = $_POST['s3pkey'];
$app->s3bucket = $_POST['s3bucket'];
$app->s3path = $_POST['s3path'];
$app->sparkle_key = $_POST['sparkle_key'];
$app->sparkle_pkey = $_POST['sparkle_pkey'];
$app->ap_key = $_POST['ap_key'];
$app->ap_pkey = $_POST['ap_pkey'];
$app->custom_salt = $_POST['custom_salt'];
$app->from_email = $_POST['from_email'];
$app->email_subject = $_POST['email_subject'];
$app->email_body = $_POST['email_body'];
$app->license_filename = $_POST['license_filename'];
$app->return_url = $_POST['return_url'];
$app->fs_security_key = $_POST['fs_security_key'];
$app->tweet_terms = $_POST['tweet_terms'];
$app->upgrade_app_id = $_POST['upgrade_app_id'];
$app->engine_class_name = $_POST['engine_class_name'];
$app->update();
redirect('application.php?id=' . $app->id);
}
else
{
$name = $_POST['name'];
$link = $_POST['link'];
$bundle_name = $_POST['bundle_name'];
$i_use_this_key = $_POST['i_use_this_key'];
$s3key = $_POST['s3key'];
$s3pkey = $_POST['s3pkey'];
$s3bucket = $_POST['s3bucket'];
$s3path = $_POST['s3path'];
$sparkle_key = $_POST['sparkle_key'];
$sparkle_pkey = $_POST['sparkle_pkey'];
$ap_key = $_POST['ap_key'];
$ap_pkey = $_POST['ap_pkey'];
$custom_salt = $_POST['custom_salt'];
$license_type = $_POST['license_type'];
$from_email = $_POST['from_email'];
$email_subject = $_POST['email_subject'];
$email_body = $_POST['email_body'];
$license_filename = $_POST['license_filename'];
$return_url = $_POST['return_url'];
$fs_security_key = $_POST['fs_security_key'];
$tweet_terms = $_POST['tweet_terms'];
$upgrade_app_id = $_POST['upgrade_app_id'];
$name = $_POST['name'];
$link = $_POST['link'];
$bundle_name = $_POST['bundle_name'];
$i_use_this_key = $_POST['i_use_this_key'];
$s3key = $_POST['s3key'];
$s3pkey = $_POST['s3pkey'];
$s3bucket = $_POST['s3bucket'];
$s3path = $_POST['s3path'];
$sparkle_key = $_POST['sparkle_key'];
$sparkle_pkey = $_POST['sparkle_pkey'];
$ap_key = $_POST['ap_key'];
$ap_pkey = $_POST['ap_pkey'];
$custom_salt = $_POST['custom_salt'];
$from_email = $_POST['from_email'];
$email_subject = $_POST['email_subject'];
$email_body = $_POST['email_body'];
$license_filename = $_POST['license_filename'];
$return_url = $_POST['return_url'];
$fs_security_key = $_POST['fs_security_key'];
$tweet_terms = $_POST['tweet_terms'];
$upgrade_app_id = $_POST['upgrade_app_id'];
$engine_class_name = $_POST['engine_class_name'];
}
}
else
{
$name = $app->name;
$link = $app->link;
$bundle_name = $app->bundle_name;
$i_use_this_key = $app->i_use_this_key;
$s3key = $app->s3key;
$s3pkey = $app->s3pkey;
$s3bucket = $app->s3bucket;
$s3path = $app->s3path;
$sparkle_key = $app->sparkle_key;
$sparkle_pkey = $app->sparkle_pkey;
$ap_key = $app->ap_key;
$ap_pkey = $app->ap_pkey;
$custom_salt = $app->custom_salt;
$license_type = $app->license_type;
$from_email = $app->from_email;
$email_subject = $app->email_subject;
$email_body = $app->email_body;
$license_filename = $app->license_filename;
$return_url = $app->return_url;
$fs_security_key = $app->fs_security_key;
$tweet_terms = $app->tweet_terms;
$upgrade_app_id = $app->upgrade_app_id;
$name = $app->name;
$link = $app->link;
$bundle_name = $app->bundle_name;
$i_use_this_key = $app->i_use_this_key;
$s3key = $app->s3key;
$s3pkey = $app->s3pkey;
$s3bucket = $app->s3bucket;
$s3path = $app->s3path;
$sparkle_key = $app->sparkle_key;
$sparkle_pkey = $app->sparkle_pkey;
$ap_key = $app->ap_key;
$ap_pkey = $app->ap_pkey;
$custom_salt = $app->custom_salt;
$from_email = $app->from_email;
$email_subject = $app->email_subject;
$email_body = $app->email_body;
$license_filename = $app->license_filename;
$return_url = $app->return_url;
$fs_security_key = $app->fs_security_key;
$tweet_terms = $app->tweet_terms;
$upgrade_app_id = $app->upgrade_app_id;
$engine_class_name = $app->engine_class_name;
}

$upgrade_apps = DBObject::glob('Application', "SELECT * FROM shine_applications WHERE id <> '{$app->id}' ORDER BY name");

$includes_path = DOC_ROOT . '/includes/';
$files = scandir($includes_path);
$available_engines = array();
foreach($files as $fn)
{
$engine_name = match('/^class\.engine(..*?)\.php/', $fn, 1);
if($engine_name !== false)
{
$available_engines[] = $engine_name;
}
}
$available_engines = implode(', ', $available_engines);
?>
<?PHP include('inc/header.inc.php'); ?>

Expand Down Expand Up @@ -183,13 +196,11 @@

<hr>

<h3>Licensing</h3>
<h3>Licensing Engine</h3>
<p>
<label for="license_type">License Type</label><br>
<select name="license_type" id="license_type">
<option <?PHP if($license_type == 'ap') echo 'selected="selected"'; ?> value="ap">Aquatic Prime</option>
<option <?PHP if($license_type == 'custom') echo 'selected="selected"'; ?> value="custom">Custom</option>
</select>
<label for="engine_class_name">License Engine Class Name</label><br>
<input type="text" class="text" name="engine_class_name" id="engine_class_name" value="<?PHP echo $engine_class_name; ?>">
<span class="info">The PHP class name of your licensing engine. Available engines are: <?PHP echo $available_engines; ?></span>
</p>

<p>
Expand Down
141 changes: 0 additions & 141 deletions includes/ap.inc.php

This file was deleted.

44 changes: 44 additions & 0 deletions includes/class.engine.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?PHP
abstract class Engine
{
public $order;
public $application;

// Should do whatever steps are required to generate a license and store
// into the database - typically by updating the $order property.
abstract public function generateLicense();

// Should force a download of the user's license file or do nothing if
// the license is not downloadable i.e., it's simply a serial number.
abstract public function downloadLicense();

public function emailLicense()
{
Mail_Postmark::compose()
->addTo($this->order->payer_email)
->subject($this->application->email_subject)
->messagePlain($this->application->getBody($this->order))
->send();
}

public function upgradeLicense()
{
$upgrade_app = new Application($this->application->upgrade_app_id);
if($upgrade_app->ok())
{
$o = new Order();
$o->app_id = $upgrade_app->id;
$o->dt = dater();
$o->first_name = $this->order->first_name;
$o->last_name = $this->order->last_name;
$o->payer_email = $this->order->payer_email;
$o->notes = "Upgrade via Shine";
$o->type = 'Upgrade';
$o->insert();
$o->generateLicense();
return $o;
}

return null;
}
}
Loading

0 comments on commit 5275a04

Please sign in to comment.