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

Commit

Permalink
Adding more advanced download license handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyler Hall committed Jul 23, 2010
1 parent fcfb338 commit 521f3ed
Show file tree
Hide file tree
Showing 8 changed files with 100 additions and 166 deletions.
2 changes: 1 addition & 1 deletion application.php
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@
<p>
<label for="email_body">Email Body</label>
<textarea name="email_body" id="email_body" class="text"><?PHP echo $email_body ?></textarea><br>
<span class="info"><strong>Available Substitutions</strong>: {first_name}, {last_name}, {payer_email}, {license}. Add your own in includes/class.objects.php getBody().</span>
<span class="info"><strong>Available Substitutions</strong>: {first_name}, {last_name}, {payer_email}, {license}, {1daylink}, {3daylink}, {1weeklink}, {foreverlink}. Add your own in includes/class.objects.php getBody().</span>
</p>

<p>
Expand Down
23 changes: 22 additions & 1 deletion css/yuiapp.css
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,25 @@ textarea { height:13em; }
.text-right { text-align:right; }
.text-center { text-align:center; }
.inline { display:inline; }
.dim { opacity:0.3; }
.dim { opacity:0.3; }

/* Shine Specific Stuff */
a.big-button {
display:block; border:1px solid #999; color:#000; text-decoration:none; padding:0.5em 1em;
-moz-border-radius:7px; -webkit-border-radius:7px;
background-image:-webkit-gradient(linear,left top,left bottom,color-stop(0, rgb(250,250,250)),color-stop(0.5, rgb(220,220,220)));
background:-moz-linear-gradient(center top,rgb(250,250,250) 0%,rgb(220,220,220) 50%);
}
a.big-button:hover {
background-image:-webkit-gradient(linear,left top,left bottom,color-stop(0, rgb(230,230,230)),color-stop(0.5, rgb(200,200,200)));
background:-moz-linear-gradient(center top,rgb(230,230,230) 0%,rgb(200,200,200) 50%);
}

.bd div.ticket { background-color:#edd; margin:-1em; margin-bottom:1em; padding:1em; border-bottom:1px solid #ccc; }
.bd div.ticket img { float:left; margin:0 1em 1em 0; }
.bd div.ticket h3 { font-weight:bold; color:#000; margin-bottom:0; font-size:138.5%; }
.bd div.ticket .meta { color:#666; }
.bd div.ticket .float-box { float:right; text-align:center; background-color:#ccc; font-weight:bold; padding:0.5em; font-size:123.1%; -moz-border-radius:7px; -webkit-border-radius:7px; border:1px solid #aaa; }
.bd div.ticket .float-box span { font-size:77%; }
.bd div.ticket h4 { font-size:108%; font-weight:bold; }
.bd div.ticket .markdown { clear:both; }
69 changes: 56 additions & 13 deletions includes/class.objects.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class User extends DBObject
{
public function __construct($id = null)
{
parent::__construct('shine_users', array('username', 'password', 'level', 'email'), $id);
parent::__construct('shine_users', array('username', 'password', 'level', 'email', 'twitter'), $id);
}

public function setPassword($password)
Expand All @@ -17,6 +17,14 @@ public function setPassword($password)
else
$this->password = $password;
}

public function avatar()
{
if(strlen($this->twitter) > 0)
return "http://api.twitter.com/1/users/profile_image/{$this->twitter}.xml?size=normal";
else
return "http://l.yimg.com/us.yimg.com/i/identity/nopic_48.gif";
}
}

class Application extends DBObject
Expand Down Expand Up @@ -76,7 +84,8 @@ public function numFeatureRequests()

function getBody($order)
{
return str_replace(array('{first_name}', '{last_name}', '{payer_email}', '{license}'), array($order->first_name, $order->last_name, $order->payer_email, $order->license), $this->email_body);
return str_replace(array('{first_name}', '{last_name}', '{payer_email}', '{license}', '{1daylink}', '{3daylink}', '{1weeklink}', '{foreverlink}'),
array($order->first_name, $order->last_name, $order->payer_email, $order->license, $order->getDownloadLink(86400), $order->getDownloadLink(86400*3), $order->getDownloadLink(86400*7), $order->getDownloadLink(0)), $this->email_body);
}

function ordersPerMonth()
Expand Down Expand Up @@ -119,6 +128,40 @@ public function iUseThisHTML()
$result = "<div style=\"width: 160px;background: no-repeat url(http://osx.iusethis.com/static/badges/ucb2.png); height: 43px; cursor: pointer;\"><a href='http://osx.iusethis.com/app/{$this->i_use_this_key}'><div style=\"color: #383838; font: 14px Geneva, Arial, Helvetica, sans-serif; position: relative; top: 14px; left: 45px; font-weight: bold; text-align: left;\">$count<span style=\"color:#7a7a7a; font:12px;\">usethis</span></div></a></div>";
return $result;
}

public function numNewTickets()
{
$db = Database::getDatabase();
return $db->getValue("SELECT COUNT(*) FROM shine_tickets WHERE status = 'new' AND app_id = '{$this->id}'");
}

public function numOpenTickets()
{
$db = Database::getDatabase();
return $db->getValue("SELECT COUNT(*) FROM shine_tickets WHERE status = 'open' AND app_id = '{$this->id}'");
}

public function nextMilestone()
{
$db = Database::getDatabase();
$row = $db->getRow("SELECT * FROM shine_milestones WHERE status = 'open' AND app_id = '{$this->id}'ORDER BY dt_due ASC");
if($row !== false)
{
$m = new Milestone();
$m->load($row);
return $m;
}
return null;
}

public function strNextMilestone()
{
$m = $this->nextMilestone();
if(is_null($m))
return '';
else
return "<a href='tickets-milestone.php?id={$m->id}'>{$m->title}</a>";
}
}

class Order extends DBObject
Expand Down Expand Up @@ -297,6 +340,14 @@ public function downloadLicense()
exit;
}

public function getDownloadLink($expires = 0) // Number of seconds until link expires, 0 = never expires
{
if($expires > 0) $expires += time();
$hash = md5($this->id . $expires . Config::get('authSalt'));
$link = 'http://' . $_SERVER['HTTP_HOST'] . '/license.php?id=' . $this->id . '&x=' . $expires . '&h=' . $hash;
return $link;
}

public function intlAmount()
{
$currencies = array('USD' => '$', 'GBP' =>'£', 'EUR' => '', 'CAD' => '$', 'JPY' => '¥');
Expand Down Expand Up @@ -344,30 +395,22 @@ class Ticket extends DBObject
{
function __construct($id = null)
{
parent::__construct('shine_ticket', array('app_id', 'title', 'description', 'created_by', 'milestone_id', 'state_id', 'dt_created', 'dt_last_state'), $id);
parent::__construct('shine_tickets', array('app_id', 'title', 'description', 'created_by', 'assigned_to', 'milestone_id', 'status', 'dt_created', 'dt_last_state'), $id);
}
}

class Milestone extends DBObject
{
function __construct($id = null)
{
parent::__construct('shine_milestone', array('app_id', 'title', 'dt_due', 'description'), $id);
parent::__construct('shine_milestone', array('app_id', 'title', 'dt_due', 'description', 'status'), $id);
}
}

class TicketHistory extends DBObject
{
function __construct($id = null)
{
parent::__construct('shine_milestone', array('dt', 'ticket_id', 'app_id', 'user_id', 'state_from_id', 'state_to_id', 'milestone_from_id', 'milestone_to_id', 'comment'), $id);
}
}

class TicketStatus extends DBObject
{
function __construct($id = null)
{
parent::__construct('shine_ticket_statuses', array('title', 'is_open', 'css_class'), $id);
parent::__construct('shine_milestone', array('dt', 'ticket_id', 'app_id', 'user_id', 'status_from', 'status_to', 'milestone_from_id', 'milestone_to_id', 'comment'), $id);
}
}
1 change: 1 addition & 0 deletions includes/master.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
require DOC_ROOT . '/includes/class.dbobject.php';
require DOC_ROOT . '/includes/class.objects.php';
require DOC_ROOT . '/includes/ap.inc.php'; // AquaticPrime functions
require DOC_ROOT . '/includes/markdown.inc.php';

// Fix magic quotes
if(get_magic_quotes_gpc())
Expand Down
12 changes: 12 additions & 0 deletions license.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?PHP
require 'includes/master.inc.php';

$o = new Order($_GET['id']);
if(!$o->ok()) exit;

$computed_hash = md5($o->id . $_GET['x'] . Config::get('authSalt'));
if($computed_hash !== $_GET['h']) exit;

if((time() > $_GET['x']) && ($_GET['x'] > 0)) exit;

$o->downloadLicense();
5 changes: 4 additions & 1 deletion order.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,11 @@
</div>
<div class="bd">
<ul class="biglist">
<li><a href="order.php?id=<?PHP echo $o->id; ?>&amp;act=download">Download</a></li>
<li><a href="order.php?id=<?PHP echo $o->id; ?>&amp;act=email" id="email">Email to User</a></li>
<li><a href="<?PHP echo $o->getDownloadLink(); ?>">Download Link (does not expire)</a></li>
<li><a href="<?PHP echo $o->getDownloadLink(86400); ?>">Download Link (1 day)</a></li>
<li><a href="<?PHP echo $o->getDownloadLink(86400 * 3); ?>">Download Link (3 days)</a></li>
<li><a href="<?PHP echo $o->getDownloadLink(86400 * 7); ?>">Download Link (1 week)</a></li>
</ul>
</div>
</div>
Expand Down
150 changes: 0 additions & 150 deletions tickets.php

This file was deleted.

4 changes: 4 additions & 0 deletions user-edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
$u->username = $_POST['username'];
$u->email = $_POST['email'];
$u->level = $_POST['level'];
$u->twitter = trim($_POST['twitter']);

// Leave the password alone if it's not set
if(!empty($_POST['password']))
Expand All @@ -35,13 +36,15 @@
$username = $_POST['username'];
$email = $_POST['email'];
$level = $_POST['level'];
$twitter = $_POST['twitter'];
}
}
else
{
$username = $u->username;
$email = $u->email;
$level = $u->level;
$twitter = $u->twitter;
}
?>
<?PHP include('inc/header.inc.php'); ?>
Expand All @@ -63,6 +66,7 @@
<form action="user-edit.php?id=<?PHP echo $u->id; ?>" method="post">
<p><label for="username">Username</label> <input type="text" name="username" id="username" value="<?PHP echo $username; ?>" class="text"></p>
<p><label for="password">Password</label> <input type="password" name="password" id="password" value="" class="text"><span class="info">Leave the password blank if you do not wish to change it</span></p>
<p><label for="twitter">Twitter Username</label> <input type="text" name="twitter" id="twitter" value="<?PHP echo $twitter; ?>" class="text"><span class="info">We'll use your Twitter avatar throughout the site</span></p>
<p><label for="email">Email</label> <input type="text" name="email" id="email" value="<?PHP echo $email; ?>" class="text"></p>
<p><label for="level">Level</label>
<select name="level" id="level">
Expand Down

0 comments on commit 521f3ed

Please sign in to comment.