- // @fixme there should be a common func for this
- if (common_config('db', 'type') == 'pgsql') {
- if (!empty($this->out->tag)) {
- $tag = pg_escape_string($this->out->tag);
- }
- } else {
- if (!empty($this->out->tag)) {
- $tag = mysql_escape_string($this->out->tag);
- }
- }
- $weightexpr = common_sql_weight('fave.modified', common_config('popular', 'dropoff'));
- $cutoff = sprintf("fave.modified > '%s'",
- common_sql_date(time() - common_config('popular', 'cutoff')));
- $qry = "SELECT notice.*, $weightexpr as weight ";
- if(isset($tag)) {
- $qry .= 'FROM notice_tag, notice JOIN fave ON notice.id = fave.notice_id ' .
- "WHERE $cutoff and notice.id = notice_tag.notice_id and '$tag' = notice_tag.tag";
- } else {
- $qry .= 'FROM notice JOIN fave ON notice.id = fave.notice_id ' .
- "WHERE $cutoff";
+ $pop = new Popularity();
+ if (!empty($this->out->tag)) {
+ $pop->tag = $this->out->tag;