public function indexAction() { $this->view->headLink()->appendStylesheet('/css/index/index.css'); $this->view->featured = Yadda_Model_Deal::featured(3); // fetch report data $this->view->reportData = Yadda_Model_Report::pull(date('Y-m-d', strtotime('-14 day')), date('Y-m-d')); }
public function indexAction() { $this->view->headMeta()->setName('description', 'Yadda (yet another daily deal aggregator) gathers into one space the daily deals and specials offered by South Africa\'s popular group buying websites.'); $this->view->headLink()->appendStylesheet('/css/index/index.css'); $this->view->regions = Yadda_Model_Region::index(false); $this->view->sites = Yadda_Model_Site::all(); $this->view->featured = Yadda_Model_Deal::featured(3); }
public function viewAction() { $id = (int) $this->_getParam('id'); $this->view->deal = Yadda_Model_Deal::find($id); $this->view->headTitle('yadda. - ' . $this->view->deal['title'], 'SET'); $this->view->headMeta()->setName('description', $this->view->trim($this->view->deal['description'], 160)); $this->view->canonical = 'http://' . $this->view->config->domain->www . '/deal/' . $this->view->deal['id']; }
public function featureAction() { $id = $this->_getParam('id'); try { Yadda_Model_Deal::feature($id); $this->getHelper('FlashMessenger')->addMessage('Deal featured.'); } catch (Yadda_Model_Exception $e) { $this->getHelper('FlashMessenger')->addMessage('Error: ' . $e->getMessage()); } $this->_redirect($this->getHelper('ReturnUrl')->getUrl('/deal/list')); }
public function ajaxFindDealsByMapBoundsAction() { $bounds = isset($_GET['bounds']) ? explode(',', $_GET['bounds']) : null; $deals = Yadda_Model_Deal::allByMapBounds($bounds); $return = array(); foreach ($deals as $deal) { $return[] = array('lat' => $deal['lat'], 'long' => $deal['long'], 'html' => $this->view->partial('deal/_deal.phtml', array('config' => $this->view->config, 'deal' => $deal))); } $this->getResponse()->setHeader('Content-type', 'application/json'); $this->getResponse()->setBody(Zend_Json::encode($return)); $this->getResponse()->sendResponse(); die; }
public function ajaxSearchAction() { $params = array_merge(array('page' => 1), array_intersect_key($_GET, Yadda_Model_Deal::$allowedSearchParams), array('count' => 15)); $deals = Yadda_Model_Deal::search($params); $html = array(); if ($deals['page'] == $deals['params']['page']) { foreach ($deals['results'] as $deal) { $html[] = $this->view->partial('deal/_deal.phtml', array('config' => $this->view->config, 'deal' => $deal)); } } $this->getResponse()->setHeader('Content-Type', 'application/json; charset=utf-8'); $this->getResponse()->setBody(Zend_Json::encode($html)); $this->getResponse()->sendResponse(); die; }
public function subscribeAction() { $form = new Www_Form_Subscribe(); if ($this->getRequest()->isPost()) { $this->view->params = array_intersect_key($_POST, Yadda_Model_Deal::$allowedSearchParams); $this->view->result = Yadda_Model_Deal::search($this->view->params); if ($form->isValid($_POST)) { $values = $form->getValues(); try { Yadda_Model_Subscription::subscribe($values); $this->getHelper('FlashMessenger')->addMessage('Your subscription has been set up.'); $this->_redirect($this->view->url(array(), 'search') . '?from=subscribe&' . http_build_query($this->view->params)); } catch (Yadda_Model_Exception $e) { $this->view->flashMessages[] = $e->getMessage(); } } } else { $this->view->params = array_intersect_key($_GET, Yadda_Model_Deal::$allowedSearchParams); $this->view->result = Yadda_Model_Deal::search($this->view->params); $form->populate($this->view->params); } $this->view->form = $form; $this->view->headLink()->appendStylesheet('/css/subscription/subscribe.css'); }
$config = Zend_Registry::get('config'); $router = new Www_Controller_Router(); $mailerUrl = 'http://' . $config->domain->www . $router->assemble(array(), 'mailer'); $unsubscribeUrl = 'http://' . $config->domain->www . $router->assemble(array(), 'unsubscribe'); // determine which subscriptions need to be sent $hour = (int) gmdate('H'); $subscriptionDb = Yadda_Db_Table::getInstance('subscription'); $select = $subscriptionDb->select()->setIntegrityCheck(false)->from('subscription')->joinLeft('user', 'subscription.user_id = user.id', array('user_email' => 'email'))->where('subscription.status = ?', 'active')->where('user.status = ?', 'active')->where('subscription.hour = ?', $hour)->order('id'); $subscriptions = $subscriptionDb->fetchAll($select); $since = gmdate('Y-m-d\\TH:00:00\\Z', strtotime('-24 hour')); foreach ($subscriptions as $subscription) { $logger->log('Subscription #' . $subscription->id, Zend_Log::DEBUG); // run the search $params = array('query' => $subscription->query, 'region' => $subscription->region_id, 'price' => $subscription->price, 'since' => $since, 'count' => 10); try { $result = Yadda_Model_Deal::search($params); } catch (Yadda_Model_Exception $e) { $logger->log('Error while searching: ' . $e->getMessage(), Zend_Log::ERR); $logger->log('Skipping...', Zend_Log::ERR); continue; } $total = $result['total']; $logger->log('Found ' . $total . ' result(s)', Zend_Log::DEBUG); if ($total == 0) { continue; } $logger->log('Sending ' . $total . ' deal(s) to ' . $subscription->user_email, Zend_Log::INFO); // fetch HTML try { $client = new Zend_Http_Client($mailerUrl, array('timeout' => 10, 'useragent' => 'send_subscriptions.php')); foreach ($params as $key => $value) {
/** * Imports the deals from a feed. * * @param Zend_Db_Table_Row $feed * @throws Yadda_Model_Exception * @throws Yadda_Feed_Exception * @return void */ public static function import($feed) { if (!isset(self::$engines[$feed->engine])) { throw new Yadda_Model_Exception('Unknown feed type "' . $feed->engine . '"'); } $class = 'Yadda_Feed_Engine_' . ucfirst(strtolower($feed->engine)); $engine = new $class(); $stubs = $engine->import($feed); $logger = Yadda_Log::getInstance(); $dealDb = Yadda_Db_Table::getInstance('deal'); foreach ($stubs as $stub) { ob_start(); print_r($stub); $logger->log('Stub:' . "\n" . ob_get_clean(), Zend_Log::DEBUG); // make sure we have the bare minimum if ($stub->getGuid() === null || $stub->getTitle() === null) { $logger->log('Rejected: Stub doesn\'t have GUID or title.', Zend_Log::DEBUG); continue; } // do we already have this guid for this site? $deal = $dealDb->fetchRow(array('site_id = ?' => $feed->site_id, 'guid = ?' => $stub->getGuid())); if ($deal !== null) { continue; } // do we already have an item with this title for this site today? $deal = $dealDb->fetchRow(array('site_id = ?' => $feed->site_id, 'title = ?' => $stub->getTitle(), 'DATE_FORMAT(display_date, \'%Y%m%d\') = ?' => date('Ymd', strtotime($stub->getDate())))); if ($deal !== null) { continue; } $logger->log('New entry: ' . $stub->getGuid(), Zend_Log::INFO); // determine geo coords $geo = $stub->getGeo(); if ($geo === null && $feed->region_lat !== null && $feed->region_long !== null) { // get deal title $title = $stub->getTitle(); $title = utf8_decode($title); $matches = array(); preg_match_all('#(at|from)\\s+((([A-Z][\\w\']+)\\s*)+)#', $title, $matches); foreach ($matches[2] as $match) { $logger->log('Testing "' . $match . '" for coords', Zend_Log::DEBUG); $match = trim($match); // remove prices/stopwords/etc. if (preg_match('/^R\\d+$/', $match)) { continue; } if ($match == 'On') { continue; } // get coordinates $test = Yadda_Model_Deal::getGeoFromPlaceName(array((double) $feed->region_lat, (double) $feed->region_long), $match); if ($test !== null) { $logger->log('Found geo coords: ' . join(' ', $test), Zend_Log::INFO); $geo = $test; break; } } } // insert the new deal $dealDb->getAdapter()->beginTransaction(); try { $insert = array('site_id' => $feed->site_id, 'region_id' => $feed->region_id, 'guid' => $stub->getGuid(), 'title' => $stub->getTitle(), 'description' => $stub->getDescription(), 'link' => $stub->getLink(), 'display_date' => date('Y-m-d H:i:s', strtotime($stub->getDate())), 'price' => $stub->getPrice(), 'value' => $stub->getValue(), 'discount' => $stub->getDiscount(), 'lat' => $geo !== null ? $geo[0] : null, 'long' => $geo !== null ? $geo[1] : null, 'status' => 'active', 'created' => Yadda_Db::now()); $dealId = $dealDb->insert($insert); // check for images foreach ($stub->getImages() as $image) { $logger->log('New image: ' . $image, Zend_Log::INFO); $imageId = $dealDb->getAdapter()->insert('image', array('deal_id' => $dealId, 'source' => $image, 'created' => Yadda_Db::now())); } $dealDb->getAdapter()->commit(); } catch (Zend_Exception $e) { $dealDb->getAdapter()->rollBack(); throw new Yadda_Feed_Exception('Error importing deal: ' . $e->getMessage()); } } }