public function setDescription($text = '') { $tmp = Beautifier::HTMLPrepare($text); $this->description = $tmp; // stemmer $tmp .= ' ' . $this->getTitle(); $words = Stemmer::ExtractWords($tmp); $this->stem = Stemmer::Stem($words); // /stemmer if (preg_match('/([^ \\n\\r]+[ \\n\\r]+){30}/s', $this->description, $match)) { $this->description_short = trim(str_replace("\n\n", "\n", $match[0])) . '...'; } return $this; }
public function init() { // getting last stamp from application instance $this->laststamp = $this->appInstance->getLastStamp(); // TODO refactor if (isset($this->attrs['filter_cats'])) { $this->fcats = explode(',', $this->attrs['filter_cats']); if (0 === sizeof($this->fcats)) { $this->fcats = false; } } if (isset($this->attrs['filter_sites'])) { $this->fsites = explode(',', $this->attrs['filter_sites']); if (0 === sizeof($this->fsites)) { $this->fsites = false; } } if (isset($this->attrs['filter_keys'])) { $this->fkeys = Stemmer::Stem(Stemmer::ExtractWords($this->attrs['filter_keys'])); if (0 === sizeof($this->fkeys)) { $this->fkeys = false; } } }
/** * 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; }