Skip to content

Commit

Permalink
Fixed Analytics & Formatted Code
Browse files Browse the repository at this point in the history
  • Loading branch information
EC2 Default User committed Jun 19, 2014
1 parent 9483d1b commit e98d999
Show file tree
Hide file tree
Showing 10 changed files with 153 additions and 137 deletions.
99 changes: 53 additions & 46 deletions account.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
$whack = new Whack();
$user_id = $whack->getProfileID();
if (!$user_id) {
header("Location: /register");
die("You need to login to access your account.");
header("Location: /register");
die("You need to login to access your account.");
}
$profile = $whack->getProfile($user_id);
?>
Expand Down Expand Up @@ -38,14 +38,14 @@
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
(function() {
var u=(("https:" == document.location.protocol) ? "https" : "http") + "://localhost/analytics/";
var u=(("https:" == document.location.protocol) ? "https" : "http") + "://homeworkhunt.com/analytics/";
_paq.push(['setTrackerUrl', u+'piwik.php']);
_paq.push(['setSiteId', 1]);
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0]; g.type='text/javascript';
g.defer=true; g.async=true; g.src=u+'piwik.js'; s.parentNode.insertBefore(g,s);
})();
</script><noscript>
<p><img src="http://localhost/analytics/piwik.php?idsite=1" style="border:0;" alt=""></p></noscript><!-- End Piwik Code -->
<p><img src="http://homeworkhunt.com/analytics/piwik.php?idsite=1" style="border:0;" alt=""></p></noscript><!-- End Piwik Code -->
</head>

<body>
Expand All @@ -68,54 +68,61 @@
</div>

<div class="col-xs-6 text-right">
<a href="mailto:[email protected]" class="btn btn-primary text-center" style="width:95%; margin-bottom: 10px;" >Email Us</a>
<a href="mailto:[email protected]" class="btn btn-primary text-center" style="width:95%; margin-bottom: 10px;">Email Us</a>
</div>
</div>Not <?php echo(htmlspecialchars($profile['username'])); ?>? <a href="/api/logout">Logout</a>.
</div>
</div>
</div><?php if(count($profile['posts']) == 0) {
?>


<?php if(count($profile['posts']) == 0) {
?>
<div class="col-lg-7 col-lg-push-1 col-md-9">
<div class="text-center"><h3>Woah there! You haven't shared any homework yet!</h3><h4>Why is sharing homework important?</h4>
<ol class="text-left">
<li>Earn upvotes which translate directly into credits allowing you to download more homework!</li>
<li>Fuel the community! Remember, sharing is caring!</li>
<li>Become a Trusted member so you can download unlimited homework for free! <a href="/faq#trusted">Learn more</a></li>
</ol>
<a href="/share" class="btn btn-lg btn-primary">Share Homework</a>
</div><?php
} else { ?><div class="col-md-9">
<div class="table-responsive">
<table class="table table-hover">
<thead>
<tr>
<th>Rating</th>

<th>Downloads</th>

<th>Title</th>
</tr>
</thead>

<tbody>
<?php

foreach ($profile['posts'] as $post) {
echo("<tr onclick='location.href=\"/hw/".$post['id']."\"'><td>".$post['rating']."</td>");
echo("<td>".$post['downloads']."</td>");
echo("<td>".htmlspecialchars($post['title'])."</td></tr>");
}
?>
</tbody>
</table>
</div> <?php } ?>
<div class="col-lg-7 col-lg-push-1 col-md-9">
<div class="text-center">
<h3>Woah there! You haven't shared any homework yet!</h3>

<h4>Why is sharing homework important?</h4>

<ol class="text-left">
<li>Earn upvotes which translate directly into credits allowing you to download more homework!</li>

<li>Fuel the community! Remember, sharing is caring!</li>

<li>Become a Trusted member so you can download unlimited homework for free! <a href="/faq#trusted">Learn more</a>
</li>
</ol><a href="/share" class="btn btn-lg btn-primary">Share Homework</a>
</div><?php
} else { ?>

<div class="col-md-9">
<div class="table-responsive">
<table class="table table-hover">
<thead>
<tr>
<th>Rating</th>

<th>Downloads</th>

<th>Title</th>
</tr>
</thead>

<tbody>
<?php

foreach ($profile['posts'] as $post) {
echo("<tr onclick='location.href=\"/hw/".$post['id']."\"'><td>".$post['rating']."</td>");
echo("<td>".$post['downloads']."</td>");
echo("<td>".htmlspecialchars($post['title'])."</td></tr>");
}
?>
</tbody>
</table>
</div><?php } ?>
</div>
</div>
</div>
</div>

<div id="push"></div>
</div><?php include("includes/footer.php"); ?>
<div id="push"></div>
</div><?php include("includes/footer.php"); ?>
</div>
</body>
</html>
12 changes: 6 additions & 6 deletions functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ function share($user, $title, $description, $file) {
$this->proccessContent($post, $fileContent);
return true;
}

$apikey = CLOUDCONVERT_KEY;
$process = CloudConvert::createProcess(pathinfo($file['name'], PATHINFO_EXTENSION), "txt", $apikey);
$fileURL = $s3->getObjectUrl(
Expand All @@ -86,7 +86,7 @@ function share($user, $title, $description, $file) {
'ResponseContentDisposition' => 'attachment; filename="'.$fileName.'"'
)
);

$process -> setOption("callback", SERVER_PROTOCOL."://".SERVER_HOSTNAME."/services/CloudConvert/callback?callback=true&secret=".CLOUDCONVERT_KEY."&hw=".$post);
$process -> uploadByUrl($fileURL, $fileName, "txt");
return true;
Expand Down Expand Up @@ -177,7 +177,7 @@ function homework($id, $user = 0) {
$hw["rating"] = $row_3['rating'];

$result_4 = mysqli_query($mysqli, "SELECT `isUpvote` FROM `votes` WHERE `user` = '$user' AND `post` = '$id_safe'") or die("Error " . mysqli_error($mysqli));

$row_4 = mysqli_fetch_assoc($result_4);
if($user == 0 || empty($row_4['isUpvote']) ) {
$hw["voteStatus"] = "never";
Expand All @@ -200,7 +200,7 @@ function getUser($user) {
$row = mysqli_fetch_assoc($result);
return $row;
}

// Returns search results for the query string.
function search($q) {
$mysqli = mysqli_connect(DB_HOSTNAME, DB_USERNAME, DB_PASSWORD, DB_NAME) or die("Error " . mysqli_error($mysqli));
Expand Down Expand Up @@ -257,7 +257,7 @@ function sitemapePages() {
$totalCount = $row['total'];
return ceil($totalCount/50000);
}
// Returns HW ID's for each of the
// Returns HW ID's for each of the
function sitemapPage($page) {
$mysqli = mysqli_connect(DB_HOSTNAME, DB_USERNAME, DB_PASSWORD, DB_NAME) or die("Error " . mysqli_error($mysqli));
$skip = ($page-1)*50000;
Expand All @@ -270,7 +270,7 @@ function sitemapPage($page) {
}
return $posts;
}

function creditsRemaining($user) {
return 5;
}
Expand Down
113 changes: 56 additions & 57 deletions hw.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@
$hasPurchased = $whack->hasPurchased($user_id, $hwID);
if ($hw == false) die("Homework not found");
function formatBytes($bytes, $precision = 2) {
$units = array('B', 'KB', 'MB', 'GB', 'TB');
$units = array('B', 'KB', 'MB', 'GB', 'TB');

$bytes = max($bytes, 0);
$pow = floor(($bytes ? log($bytes) : 0) / log(1024));
$pow = min($pow, count($units) - 1);
$bytes = max($bytes, 0);
$pow = floor(($bytes ? log($bytes) : 0) / log(1024));
$pow = min($pow, count($units) - 1);

// Uncomment one of the following alternatives
// $bytes /= pow(1024, $pow);
// $bytes /= (1 << (10 * $pow));
// Uncomment one of the following alternatives
// $bytes /= pow(1024, $pow);
// $bytes /= (1 << (10 * $pow));

return round($bytes, $precision) . ' ' . $units[$pow];
return round($bytes, $precision) . ' ' . $units[$pow];
}
header ('Content-type: text/html; charset=utf-8');

Expand Down Expand Up @@ -61,7 +61,7 @@ function formatBytes($bytes, $precision = 2) {
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
(function() {
var u=(("https:" == document.location.protocol) ? "https" : "http") + "://localhost/analytics/";
var u=(("https:" == document.location.protocol) ? "https" : "http") + "://homeworkhunt.com/analytics/";
_paq.push(['setTrackerUrl', u+'piwik.php']);
_paq.push(['setSiteId', 1]);
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0]; g.type='text/javascript';
Expand All @@ -70,64 +70,63 @@ function formatBytes($bytes, $precision = 2) {
</script>
</head>

<body><div id="wrapper">

<noscript>
<p><img src="http://localhost/analytics/piwik.php?idsite=1" style="border:0;" alt=""></p></noscript><!-- End Piwik Code -->
<?php include("includes/header.php"); ?>
<div class="container">
<div class="col-lg-8 col-lg-push-2 col-md-10 col-md-push-1">
<h2><?php echo(htmlspecialchars($hw['title'])); ?></h2>
<br>
<p><?php echo(htmlspecialchars($hw['description'])); ?></p>
<br>
<div class="row">
<div class="col-sm-3 col-xs-6">
<?php echo(htmlspecialchars(strtoupper(pathinfo($hw['file'], PATHINFO_EXTENSION)))); ?> File
</div>
<body>
<div id="wrapper">
<noscript>
<p><img src="http://homeworkhunt.com/analytics/piwik.php?idsite=1" style="border:0;" alt=""></p></noscript><!-- End Piwik Code -->
<?php include("includes/header.php"); ?>

<div class="col-sm-3 col-xs-6">
<?php
echo(formatBytes($hw['size'], 2));
?>
</div>
<div class="container">
<div class="col-lg-8 col-lg-push-2 col-md-10 col-md-push-1">
<h2><?php echo(htmlspecialchars($hw['title'])); ?></h2><br>

<div class="col-sm-3 col-xs-6">
<?php echo($hw['cost']); ?> Credit(s)
</div>
<p><?php echo(htmlspecialchars($hw['description'])); ?></p><br>

<div class="col-sm-3 col-xs-6">
By <?php echo(htmlspecialchars($hw['by'])); ?> <?php if ($hw['trusted']) { ?><a href="#" rel="tooltip" class="no-pointer" title="Trusted User"><i class="fa fa-bullseye"><?php ?></i></a><?php } ?>
</div>
</div>
<hr>
<?php if (!$user_id) { ?>
<div class="row">
<div class="col-sm-3 col-xs-6">
<?php echo(htmlspecialchars(strtoupper(pathinfo($hw['file'], PATHINFO_EXTENSION)))); ?>File
</div>

<div class="row col-lg-12">
To download this entire homework assignment for 1 credit, you will need an account. Both accounts and credits are <strong>free</strong> and more credits may be earned by sharing quality homework.
</div><?php } ?>
<div class="col-sm-3 col-xs-6">
<?php
echo(formatBytes($hw['size'], 2));
?>
</div>

<div class="row">
<div class="col-xs-6">
<?php if ($hasPurchased) { ?><a id="upvote" class="btn btn-sm btn-default<?php if ($hw['voteStatus'] == "upvoted") echo " btn-primary"; ?>"><i class="fa fa-thumbs-up"><?php ?></i></a>&nbsp;&nbsp;<?php } else { echo("Quality Rating:"); } ?><span id="rating"><?php echo($hw['rating']); ?></span><?php if ($hasPurchased) { ?>&nbsp;&nbsp;<a id="downvote" class="btn btn-sm btn-default<?php if ($hw['voteStatus'] == "downvoted") echo " btn-primary";?>"><i class="fa fa-thumbs-down"><?php ?></i></a><?php } ?>
<div class="col-sm-3 col-xs-6">
<?php echo($hw['cost']); ?>Credit(s)
</div>

<div class="col-sm-3 col-xs-6">
By <?php echo(htmlspecialchars($hw['by'])); ?> <?php if ($hw['trusted']) { ?><a href="#" rel="tooltip" class="no-pointer" title="Trusted User"><i class="fa fa-bullseye"><?php ?></i></a><?php } ?>
</div>
</div>
<hr>
<?php if (!$user_id) { ?>

<div class="row col-lg-12">
To download this entire homework assignment for 1 credit, you will need an account. Both accounts and credits are <strong>free</strong> and more credits may be earned by sharing quality homework.
</div><?php } ?>

<div class="row">
<div class="col-xs-6">
<?php if ($hasPurchased) { ?><a id="upvote" class="btn btn-sm btn-default&lt;?php if ($hw['voteStatus'] == " echo="btn-primary&quot;;">"&gt;<i class="fa fa-thumbs-up"><?php ?></i></a>&nbsp;&nbsp;<?php } else { echo("Quality Rating:"); } ?><span id="rating"><?php echo($hw['rating']); ?></span><?php if ($hasPurchased) { ?>&nbsp;&nbsp;<a id="downvote" class="btn btn-sm btn-default&lt;?php if ($hw['voteStatus'] == " echo="btn-primary&quot;;?">"&gt;<i class="fa fa-thumbs-down"><?php ?></i></a><?php } ?>
</div>

<div class="col-xs-6 text-right">
<input type="hidden" id="postid" name="id" value="<?php echo($hw['id']); ?>"> <a class="btn btn-primary" style="width:140px; margin-bottom: 10px;" id="download">Download</a>
</form>
</form>
<div class="col-xs-6 text-right">
<input type="hidden" id="postid" name="id" value="<?php echo($hw['id']); ?>"> <a class="btn btn-primary" style="width:140px; margin-bottom: 10px;" id="download">Download</a>
</div>
</div>
</div>

<p class="text-center" style="margin-top:15px;">Comments feature coming soon.</p>
<ul id="comments">
<li class="comment"><img src="https://d13yacurqjgara.cloudfront.net/users/31398/avatars/original/juliakhusainova-gravatar-copy.png?1333395342"></li>
</ul>
<p class="text-center" style="margin-top:15px;">Comments feature coming soon.</p>

<ul id="comments">
<li class="comment"><img src="https://d13yacurqjgara.cloudfront.net/users/31398/avatars/original/juliakhusainova-gravatar-copy.png?1333395342"></li>
</ul>
</div>
</div>
</div>
<div id="push"></div>

</div>
<?php include("includes/footer.php"); ?>
<div id="push"></div>
</div><?php include("includes/footer.php"); ?>
</body>
</html>
6 changes: 4 additions & 2 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,11 @@
<div class="main dark fullHeight">
<div class="container text-center">
<div class="row">
<div class="col-md-6 col-md-push-3 col-xs-8 col-xs-push-2 text-center"><img src="img/logo-light.png" width="80%" style="display:inline;margin-left:10%; margin-bottom:15px;" class="img-responsive"><span style="position: absolute;
<div class="col-md-6 col-md-push-3 col-xs-8 col-xs-push-2 text-center">
<img src="img/logo-light.png" width="80%" style="display:inline;margin-left:10%; margin-bottom:15px;" class="img-responsive"><span style="position: absolute;
right: -20px;
font-size: 22px;">beta</span></div>
font-size: 22px;">beta</span>
</div>

<div class="row text-center">
<form method="get" action="/search">
Expand Down
13 changes: 13 additions & 0 deletions legal.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,19 @@
</script>
<script src="/js/bootstrap.js" type="text/javascript">
</script>
<script type="text/javascript">
var _paq = _paq || [];
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
(function() {
var u=(("https:" == document.location.protocol) ? "https" : "http") + "://homeworkhunt.com/analytics/";
_paq.push(['setTrackerUrl', u+'piwik.php']);
_paq.push(['setSiteId', 1]);
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0]; g.type='text/javascript';
g.defer=true; g.async=true; g.src=u+'piwik.js'; s.parentNode.insertBefore(g,s);
})();
</script><noscript>
<p><img src="http://homeworkhunt.com/analytics/piwik.php?idsite=1" style="border:0;" alt=""></p></noscript><!-- End Piwik Code -->
</head>

<body>
Expand Down
4 changes: 2 additions & 2 deletions login.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
(function() {
var u=(("https:" == document.location.protocol) ? "https" : "http") + "://localhost/analytics/";
var u=(("https:" == document.location.protocol) ? "https" : "http") + "://homeworkhunt.com/analytics/";
_paq.push(['setTrackerUrl', u+'piwik.php']);
_paq.push(['setSiteId', 1]);
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0]; g.type='text/javascript';
g.defer=true; g.async=true; g.src=u+'piwik.js'; s.parentNode.insertBefore(g,s);
})();
</script><noscript>
<p><img src="http://localhost/analytics/piwik.php?idsite=1" style="border:0;" alt=""></p></noscript><!-- End Piwik Code -->
<p><img src="http://homeworkhunt.com/analytics/piwik.php?idsite=1" style="border:0;" alt=""></p></noscript><!-- End Piwik Code -->
</head>

<body>
Expand Down
Loading

0 comments on commit e98d999

Please sign in to comment.