Skip to content

Commit

Permalink
Fixed issue caused by UTF-8 characters in image URLs.
Browse files Browse the repository at this point in the history
Added some styling to the view page (still incomplete).
Fixed sorting order for history results.
Format prices to two decimal places.
Passing the site name to the view.
No longer handling exceptions silently (accident).  Now handling and throwing again.
  • Loading branch information
DarkstarDev committed Nov 4, 2011
1 parent 5ad2401 commit 2e16274
Show file tree
Hide file tree
Showing 13 changed files with 280 additions and 54 deletions.
5 changes: 5 additions & 0 deletions application/controllers/ItemController.php
Expand Up @@ -9,6 +9,11 @@ class ItemController
extends Zend_Controller_Action
{

public function init()
{
$this->view->site = $this->getRequest()->getParam('site');
}

public function indexAction()
{
$this->_forward('view');
Expand Down
15 changes: 11 additions & 4 deletions application/layouts/scripts/layout.phtml
Expand Up @@ -3,11 +3,18 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Darkstar's Woot-off Checker v3</title>
<?php //echo $this->headLink()->appendStylesheet('/css/style.css') ?>
<?php $this->headLink()->appendStylesheet('/css/common.css') ?>
<?php $this->headLink()->appendStylesheet('/css/'.$this->site.'.css') ?>
<?php echo $this->headLink(); ?>
</head>
<body>

<?php echo $this->layout()->content; ?>

<div id="main-wrapper">
<div id="logo">DSwoot/<?php echo ucfirst($this->site); ?></div>
<?php echo $this->layout()->content; ?>
<div class="clearfix"></div>
</div>
<div id="secondary-wrapper">
<?php echo $this->placeholder('secondary'); ?>
</div>
</body>
</html>
103 changes: 59 additions & 44 deletions application/views/scripts/item/view.phtml
@@ -1,45 +1,60 @@
<?php var_dump($this->productData); ?>
<div id="outer-container">
<?php //var_dump($this->productData); ?>
<div id="product-container">
<div id="image">
<img alt="<?php echo str_replace('"','&rdquo;',$this->productData['title']); ?>" src="/images/products/<?php echo $this->productData['id'] ?><?php echo $this->productData['file_extension']; ?>" />
</div>
<div id="title">
<?php echo $this->productData['title']; ?>
</div>
<div id="price">
$<?php echo $this->productData['price']; ?>
</div>
<div id="shipping">
+ $<?php echo $this->productData['shipping']; ?> shipping
</div>
<div id="condition">
Condition: <?php echo $this->productData['condition']; ?>
</div>
<div id="product">
Product:
<ul>
<?php foreach($this->productData['products'] as $product): ?>
<li><?php echo $product['quantity']; ?> <?php echo $product['name']; ?></li>
<?php endforeach; ?>
</ul>
</div>
<div id="buy-link">
<?php $current = end($this->productData['history']); ?>
<?php if(!$current['sold_out'] && $current['percent_sold'] < .9): ?>
<a href="<?php echo $this->productData['purchase_url']; ?>">I want one!</a>
<?php elseif(!$current['sold_out'] && $current['percent_sold'] >= .9): ?>
<a href="<?php echo $this->productData['purchase_url']; ?>">I want one! (they're almost gone!)</a>
<?php else: ?>
Sold out!
<?php endif; ?>
</div>
<div id="comment-container">
<?php echo $current['comments']; ?> comment(s)
</div>
<div id="subtitle">
<?php echo $this->productData['subtitle']; ?>
</div>
<div id="teaser">
<?php echo $this->productData['teaser']; ?>
</div>
</div>
<img alt="<?php echo str_replace('"','&quote;',$this->productData['title']); ?>" src="/images/products/<?php echo $this->productData['id'] ?><?php echo $this->productData['file_extension']; ?>" />
</div>
<div id="product-info">
<div id="title">
<?php echo $this->productData['title']; ?>
</div>
<div id="price">
$<?php echo $this->productData['price']; ?>
</div>
<div id="shipping">
+ $<?php echo $this->productData['shipping']; ?> shipping
</div>
<div id="condition">
<dl>
<dt>Condition:</dt>
<dd>
<?php echo $this->productData['condition']; ?>
</dd>
</dl>
</div>
<div id="product">
<dl>
<dt>Product:</dt>
<?php foreach($this->productData['products'] as $product): ?>
<dd>
<?php echo $product['quantity']; ?> <?php echo $product['name']; ?>
</dd>
<?php endforeach; ?>
</dl>
<div class="clearfix"></div>
</div>
<div id="buy-link">
<?php $current = end($this->productData['history']); ?>
<?php if(!$current['sold_out'] && $current['percent_sold'] < .9): ?>
<a href="<?php echo $this->productData['purchase_url']; ?>">I want one!</a>
<?php elseif(!$current['sold_out'] && $current['percent_sold'] >= .9): ?>
<a href="<?php echo $this->productData['purchase_url']; ?>">I want one! (they're almost gone!)</a>
<?php else: ?>
Sold out!
<?php endif; ?>
</div>
<div id="comment-container">
<?php echo $current['comments']; ?> comment(s)
</div>
</div>
<div class="clearfix">
<div class="triangle"></div>
</div>
</div>
<?php $this->placeholder('secondary')->set(
'<div id="subtitle">'.
str_replace("'",'&apos;',$this->productData["subtitle"]) .
'</div>
<div id="teaser">' .
str_replace("'", '&apos;', $this->productData["teaser"]) .
'</div>'
);
16 changes: 12 additions & 4 deletions library/Ds/Service/WootFeed.php
Expand Up @@ -88,6 +88,7 @@ public function getCurrentProduct($site)
//Unable to fetch data from woot or insert data.
$this->_db->rollBack();
$this->_dao->unlockApplicationUpdates();
throw new Exception($e->getMessage(), 500, $e);
}
}
return $data;
Expand Down Expand Up @@ -122,9 +123,9 @@ protected function _fetchWootRss($site)
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$xml = curl_exec($ch);

if (curl_errno($ch)) {
$error = curl_error($ch);
curl_close($ch);
throw new Exception($error);
}
curl_close($ch);
Expand Down Expand Up @@ -156,7 +157,6 @@ protected function _fetchProductImages($itemId, array &$data)
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$standard = curl_exec($ch);
if (curl_errno($ch)) {
curl_close($ch);
throw new Exception(curl_error($ch));
}
curl_close($ch);
Expand All @@ -167,7 +167,6 @@ protected function _fetchProductImages($itemId, array &$data)
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$detail = curl_exec($ch);
if (curl_errno($ch)) {
curl_close($ch);
throw new Exception(curl_error($ch));
}
curl_close($ch);
Expand All @@ -189,7 +188,7 @@ protected function _parseWootRss($xml)
$item['condition'] = (string)$wootNamespace->condition;
$item['thread'] = (string)$wootNamespace->discussionurl;
$item['purchase_url'] = (string)$wootNamespace->purchaseurl;
$item['price'] = (float)str_replace('$','',$wootNamespace->price);
$item['price'] = number_format((float)str_replace('$','',$wootNamespace->price),2);

preg_match('/\$([\d\.]*)/',$wootNamespace->shipping, $matches);

Expand All @@ -204,6 +203,15 @@ protected function _parseWootRss($xml)
$images['standard'] = (string)$wootNamespace->standardimage;
$images['detail'] = (string)$wootNamespace->detailimage;

//Woot tends to use UTF-8 characters in their filenames. cURL doesn't like this.
$standardUrl = parse_url($images['standard']);
$standardUrl['path'] = substr($standardUrl['path'], 1);
$images['standard'] = str_replace($standardUrl['path'], urlencode($standardUrl['path']), $images['standard']);

$detailUrl = parse_url($images['detail']);
$detailUrl['path'] = substr($detailUrl['path'], 1);
$images['detail'] = str_replace($detailUrl['path'], urlencode($detailUrl['path']), $images['detail']);

$products = array();

foreach($wootNamespace->products->product as $product) {
Expand Down
4 changes: 2 additions & 2 deletions library/Ds/Service/WootFeed/DbDao.php
Expand Up @@ -140,7 +140,7 @@ public function fetchItemListBySite($site, $page=1, $limit=10)
INNER JOIN history h
ON h.item_id = i.id
WHERE i.site = ?
ORDER BY h.updated ASC
ORDER BY h.updated DESC
LIMIT ?,?';

$dtos = null;
Expand Down Expand Up @@ -172,7 +172,7 @@ protected function _recordReduce($records)
'condition' => $record['condition'],
'thread' => $record['thread'],
'purchase_url' => $record['purchase_url'],
'price' => round($record['price'],2),
'price' => number_format($record['price'],2),
'shipping' => round($record['shipping'],2),
'wootoff' => (bool)$record['wootoff'],
'title' => $record['title'],
Expand Down
122 changes: 122 additions & 0 deletions public/css/common.css
@@ -0,0 +1,122 @@
.triangle {
height: 0;
width: 0;
border-width: 25px 37px;
border-color: #FFF transparent transparent transparent;
border-style: solid;
position: absolute;
left: 115px;
}

#logo {
width: 811px;
margin: 0 auto;
border-width: 0 0 5px 0;
border-color: #E2E2E2;
border-style: solid;
font-size: 30px;
font-weight: bold;
}

#main-wrapper {
background-color: #FFF;
}

#product-container {
margin: 0 auto;
width: 811px;
}

#secondary-wrapper {
background-color: rgba(255,255,255,.4);
border-radius: 5px;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
/* For IE 7*/
filter:progid:DXImageTransform.Microsoft.gradient(startColorstr=#66FFFFFF, endColorstr=#66FFFFFF);
/* For IE 8*/
-ms-filter: "progid:DXImageTransform.Microsoft.gradient(startColorstr=#66FFFFFF, endColorstr=#66FFFFFF)";
padding: 15px 15px 15px 15px;
margin: 17px auto;
width: 781px;
}

body {
font-family: "Trebuchet MS",Trebuchet,Calibri,Tahoma,Arial,sans-serif;
margin: 0;
padding: 0;
}

#image, #product-info {
float: left;
}

#image {
width: 456px;
}

#product-info {
width: 355px;
}

.clearfix {
clear: both;
width: 100%;
position: relative;
}

#subtitle {
font-size: 16px;
font-weight: bold;
text-transform: uppercase;
margin: 5px 0;
}

#teaser {
color: #FFF;
font-size: 22px;
margin-top: 10px;
}

#title {
font-size: 20px;
padding: 6px 5px 5px 0px;
}

#price {
font-weight: bold;
font-size: 22px;
float: left;
margin-bottom: 4px;
}

#shipping {
font-size: 11px;
margin: 8px 0 0 30px;
float: left;
}

#condition, #product {
clear: both;
font-size: 11px;
}

#condition dd, #product dd {
margin-left: 90px;
margin-bottom: 5px;
float: left;
width: 250px;
}

#condition dt, #product dt {
width: 80px;
float: left;
padding: 0 0 5px 0;
position: absolute;
}

#condition dt, #product dt {
color: #999;
text-transform: uppercase;
font-size: 12px;
}
15 changes: 15 additions & 0 deletions public/css/home.css
@@ -0,0 +1,15 @@
body {
background-color: #EFEAE6;
}

#secondary-wrapper {
background-color: #EFEAE6;
/* For IE 7*/
filter:progid:DXImageTransform.Microsoft.gradient(startColorstr=#FFEFEAE6, endColorstr=#FFEFEAE6);
/* For IE 8*/
-ms-filter: "progid:DXImageTransform.Microsoft.gradient(startColorstr=#FFEFEAE6, endColorstr=#FFEFEAE6)";
}

#logo, #teaser {
color: #D35500;
}
15 changes: 15 additions & 0 deletions public/css/kids.css
@@ -0,0 +1,15 @@
body {
background-color: #FFE086;
}

#secondary-wrapper {
background-color: #E19433;
/* For IE 7*/
filter:progid:DXImageTransform.Microsoft.gradient(startColorstr=#FFE19433, endColorstr=#FFE19433);
/* For IE 8*/
-ms-filter: "progid:DXImageTransform.Microsoft.gradient(startColorstr=#FFE19433F, endColorstr=#FFE19433)";
}

#logo {
color: #E19433;
}
7 changes: 7 additions & 0 deletions public/css/moofi.css
@@ -0,0 +1,7 @@
body {
background-color: #61861E;
}

#logo {
color: #61861E;
}
7 changes: 7 additions & 0 deletions public/css/sellout.css
@@ -0,0 +1,7 @@
body {
background-color: #4B437D;
}

#logo {
color: #4B437D;
}

0 comments on commit 2e16274

Please sign in to comment.