public function updateGlobalRSS() { echo '[' . date('H:m:s') . "] Updating global RSS channel...\n"; $filename = PATH_PUBLIC . 'rss-global.xml'; $sites = Database::sites(); $st = array(); $cursor = Database::jobs()->find(); $cursor->sort(array('stamp' => -1)); $cursor->limit(25); date_default_timezone_set('GMT'); // generating global rss feed $rss = RSS::create($filename); while ($item = $cursor->getNext()) { if (!isset($st[$item['site']])) { $st[$item['site']] = $sites->findOne(array('code' => $item['site'])); } $s = $st[$item['site']]; $desc = <<<EOF {$item['desc']}<br /><p style="padding: 0.2em; background-color: silver; border: 1px dotted black; align: center;" align="center"><a href="{$item['url']}">{$item['title']}</a></p> EOF; $rss->addItem($s['name'] . ': ' . $item['title'], 'http://workbreeze.com/jobs/' . $s['folder'] . '/' . $item['id'], $desc, 'http://workbreeze.com/jobs/' . $s['folder'] . '/' . $item['id'], $item['stamp']); } $rss->save(); // compressing for nginx static gzip $out = system('gzip -c9 ' . escapeshellarg($filename) . ' > ' . escapeshellarg($filename . '.gz')); }
public function insert() { $arr = array('stamp' => $this->getStamp(), 'site' => $this->getSite(), 'id' => (string) $this->getId(), 'url' => $this->getUrl(), 'title' => $this->getTitle(), 'cats' => $this->getCategories(), 'desc' => $this->getDescription()); if ($this->getShortDescription()) { $arr['short'] = $this->getShortDescription(); } if (count($this->money)) { $arr['money'] = $this->getMoney(); } if (count($this->stem)) { $arr['stem'] = $this->stem; } Database::jobs()->insert($arr); return true; }
protected function prepare($query) { $this->preview = isset($_GET['preview']); $site = array_shift($query); $id = array_shift($query); if (!$site || !$id || isset(self::$sites[$site]) && !self::$sites[$site]) { return Module::NotFound(); } if (!isset(self::$sites[$site])) { self::$sites[$site] = Database::sites()->findOne(array('folder' => $site)); } $this->site = self::$sites[$site]; if (!$this->site) { return false; } $this->job = Database::jobs()->findOne(array('site' => (int) $this->site['code'], 'id' => (string) $id)); if (!$this->job) { return false; } return true; }
private function checkOffers() { $now = time(); // have to wait at least 5 seconds after previous check if ($now - $this->lastcheck < 5) { return; } $this->lastcheck = time(); if (0 !== sizeof($this->cache)) { // lets clean a cache foreach ($this->cache as $stamp => $item) { // 30 seconds for spare if ($now - $stamp > 30) { unset($this->cache[$stamp]); } } } // checking new offers $cursor = Database::jobs()->find(array('stamp' => array('$gt' => $this->laststamp)))->sort(array('stamp' => 1)); while ($item = $cursor->getNext()) { $this->laststamp = $item['stamp']; $this->cache[$this->laststamp] = $item; } }
protected function getScript() { $sites = Database::sites()->find()->sort(array('code' => 1)); $content = <<<EOF var data = new google.visualization.DataTable(); data.addColumn('string', 'date'); EOF; while ($site = $sites->getNext()) { $content .= <<<EOF data.addColumn('number', '{$site['name']}'); EOF; } $content .= <<<EOF data.addRows(7); EOF; $sites->reset(); $now = getdate(); $dt = mktime(0, 0, 0, $now['mon'], $now['mday'], $now['year']); $i = 6; // week for stats while ($i > -1) { $dth = date('d.m', $dt); $content .= <<<EOF data.setValue({$i}, 0, '{$dth}'); EOF; $n = 1; while ($site = $sites->getNext()) { $c = Database::jobs()->find(array('site' => $site['code'], 'stamp' => array('$gte' => $dt, '$lt' => $dt + 60 * 60 * 24)))->count(); $content .= <<<EOF data.setValue({$i}, {$n}, {$c}); EOF; ++$n; } $sites->reset(); --$i; $dt -= 60 * 60 * 24; } $content .= <<<EOF new google.visualization.LineChart( \tdocument.getElementById('weekjobs') ).draw(data, { \theight: 350, \twidth: 800, \tbackgroundColor: { \t\tstroke: '#858585', \t\tstrokeWidth: 1, \t\tfill: '#2e3436' \t}, \tlegendTextStyle: { \t\tcolor: 'white' \t}, \tvAxis: { \t\tbaselineColor: '#858585', \t\ttextStyle: { \t\t\tcolor: 'white' \t\t} \t}, \thAxis: { \t\tbaselineColor: '#858585', \t\ttextStyle: { \t\t\tcolor: 'white' \t\t} \t}, \tcurveType: 'function', \tchartArea: { \t\tleft: 60, \t\ttop: 55, \t\twidth: 550 \t}, \tpointSize: 3, \tfontName: 'Tahoma', \tmin: 0, \tlegend: 'right' }); EOF; return array('google.load(\'visualization\', \'1\', {packages: [\'corechart\']});', $content); }
/** * The main method to return jobs array */ private function getJobs($stamp) { $c = Database::jobs(); $jobs = array(); if ($stamp < 0) { $mod = -1; $st = array('$lt' => -$stamp); } else { $mod = 1; $st = array('$gt' => $stamp); } $filter = array('stamp' => $st); if (isset($_POST['filter_sites'])) { $sites = explode(',', $_POST['filter_sites']); foreach ($sites as $key => &$val) { $val = intval($val); if ($val < 0 || $val > 20) { unset($sites[$key]); } } if (count($sites)) { $filter['site'] = array('$in' => $sites); } } if (isset($_POST['filter_cats'])) { $cats = explode(',', $_POST['filter_cats']); foreach ($cats as $key => &$val) { $val = intval($val); if ($val < 0 || $val > 30) { unset($cats[$key]); } } if (count($cats)) { $filter['cats'] = array('$in' => $cats); } } if (isset($_POST['filter_keys'])) { $val = Stemmer::ExtractWords($_POST['filter_keys']); $val = Stemmer::Stem($val); if (count($val)) { $filter['stem'] = array('$in' => $val); } } if (1 == count($filter)) { // only stamp $res = Cache::get('j' . $stamp); if ($res) { return $res; } } $cursor = $c->find($filter, array('site', 'id', 'stamp', 'title', 'cats', 'short', 'desc', 'money')); $cursor->sort(array('stamp' => -1)); $cursor->limit(25); while ($job = $cursor->getNext()) { $item = Job::prepareJSON($job, $mod); $jobs[] = $item; } if (0 == count($jobs)) { return false; } if ($stamp < 0) { $jobs = array_reverse($jobs); } if (1 == count($filter)) { Cache::set('j' . $stamp, $jobs, 30); } return $jobs; }
protected function queueJobLink($jobId, $link) { $info = array('site' => $this->getSiteCode(), 'id' => (string) $jobId); $tmp = Database::jobs()->findOne($info); if (null != $tmp) { return false; } $info['type'] = 'job'; $tmp = Database::queue()->findOne($info); if (null != $tmp) { return false; } echo '[' . date('H:m:s') . '] Queueing job [' . $link . "]\n"; $info['url'] = $link; $info['rnd'] = rand(1, 10000); Database::queue()->insert($info); $this->queuedCount++; return true; }