function getProfiles()
 {
     $featured_nicks = common_config('nickname', 'featured');
     if (!$featured_nicks) {
         return null;
     }
     $quoted = array();
     foreach ($featured_nicks as $nick) {
         $quoted[] = "'{$nick}'";
     }
     $table = "user";
     if (common_config('db', 'quote_identifiers')) {
         $table = '"' . $table . '"';
     }
     $qry = 'SELECT profile.* ' . 'FROM profile JOIN ' . $table . ' on profile.id = ' . $table . '.id ' . 'WHERE ' . $table . '.nickname in (' . implode(',', $quoted) . ') ' . 'ORDER BY profile.created DESC ';
     $limit = PROFILES_PER_SECTION + 1;
     $offset = 0;
     if (common_config('db', 'type') == 'pgsql') {
         $qry .= ' LIMIT ' . $limit . ' OFFSET ' . $offset;
     } else {
         $qry .= ' LIMIT ' . $offset . ', ' . $limit;
     }
     $profile = Memcached_DataObject::cachedQuery('Profile', $qry, 6 * 3600);
     return $profile;
 }
Ejemplo n.º 2
0
 function getNotices()
 {
     // @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}";
     }
     $qry .= ' GROUP BY notice.id,notice.profile_id,notice.content,notice.uri,' . 'notice.rendered,notice.url,notice.created,notice.modified,' . 'notice.reply_to,notice.is_local,notice.source,notice.conversation, ' . 'notice.lat,notice.lon,location_id,location_ns,notice.repeat_of' . ' ORDER BY weight DESC';
     $offset = 0;
     $limit = NOTICES_PER_SECTION + 1;
     $qry .= ' LIMIT ' . $limit . ' OFFSET ' . $offset;
     $notice = Memcached_DataObject::cachedQuery('Notice', $qry, 1200);
     return $notice;
 }
Ejemplo n.º 3
0
 /**
  * Get the attachments for a particlar notice.
  *
  * @param int $post_id
  * @return array of File objects
  */
 static function getAttachments($post_id)
 {
     $file = new File();
     $query = "select file.* from file join file_to_post on (file_id = file.id) where post_id = " . $file->escape($post_id);
     $file = Memcached_DataObject::cachedQuery('File', $query);
     $att = array();
     while ($file->fetch()) {
         $att[] = clone $file;
     }
     return $att;
 }
 function getGroups()
 {
     $qry = 'SELECT user_group.*, count(*) as value ' . 'FROM user_group JOIN group_member ' . 'ON user_group.id = group_member.group_id ' . 'GROUP BY user_group.id,user_group.nickname,user_group.fullname,user_group.homepage,user_group.description,user_group.location,user_group.original_logo,user_group.homepage_logo,user_group.stream_logo,user_group.mini_logo,user_group.created,user_group.modified ' . 'ORDER BY value DESC ';
     $limit = GROUPS_PER_SECTION;
     $offset = 0;
     if (common_config('db', 'type') == 'pgsql') {
         $qry .= ' LIMIT ' . $limit . ' OFFSET ' . $offset;
     } else {
         $qry .= ' LIMIT ' . $offset . ', ' . $limit;
     }
     $group = Memcached_DataObject::cachedQuery('User_group', $qry, 3600);
     return $group;
 }
Ejemplo n.º 5
0
 function getProfiles()
 {
     $qry = 'SELECT profile.*, count(*) as value ' . 'FROM profile JOIN notice ON profile.id = notice.profile_id ' . (common_config('public', 'localonly') ? 'WHERE is_local = 1 ' : '') . 'GROUP BY profile.id,nickname,fullname,profileurl,homepage,bio,location,profile.created,profile.modified,textsearch ' . 'ORDER BY value DESC ';
     $limit = PROFILES_PER_SECTION;
     $offset = 0;
     if (common_config('db', 'type') == 'pgsql') {
         $qry .= ' LIMIT ' . $limit . ' OFFSET ' . $offset;
     } else {
         $qry .= ' LIMIT ' . $offset . ', ' . $limit;
     }
     $profile = Memcached_DataObject::cachedQuery('Profile', $qry, 6 * 3600);
     return $profile;
 }
Ejemplo n.º 6
0
 function getTags()
 {
     $qry = $this->query();
     $limit = TAGS_PER_SECTION;
     $offset = 0;
     if (common_config('db', 'type') == 'pgsql') {
         $qry .= ' LIMIT ' . $limit . ' OFFSET ' . $offset;
     } else {
         $qry .= ' LIMIT ' . $offset . ', ' . $limit;
     }
     $profile_tag = Memcached_DataObject::cachedQuery('Profile_tag', sprintf($qry, $this->out->user->id));
     return $profile_tag;
 }
 function getPeopletags()
 {
     $qry = 'SELECT profile_list.*, subscriber_count as value ' . 'FROM profile_list WHERE profile_list.private = false ' . 'ORDER BY value DESC ';
     $limit = PEOPLETAGS_PER_SECTION;
     $offset = 0;
     if (common_config('db', 'type') == 'pgsql') {
         $qry .= ' LIMIT ' . $limit . ' OFFSET ' . $offset;
     } else {
         $qry .= ' LIMIT ' . $offset . ', ' . $limit;
     }
     $peopletag = Memcached_DataObject::cachedQuery('Profile_list', $qry, 3600);
     return $peopletag;
 }
 function getTags()
 {
     $weightexpr = common_sql_weight('notice_tag.created', common_config('tag', 'dropoff'));
     // @fixme should we use the cutoff too? Doesn't help with indexing per-user.
     $qry = 'SELECT notice_tag.tag, ' . $weightexpr . ' as weight ' . 'FROM notice_tag JOIN notice ' . 'ON notice_tag.notice_id = notice.id ' . 'WHERE notice.profile_id = %d ' . 'GROUP BY notice_tag.tag ' . 'ORDER BY weight DESC ';
     $limit = TAGS_PER_SECTION;
     $offset = 0;
     if (common_config('db', 'type') == 'pgsql') {
         $qry .= ' LIMIT ' . $limit . ' OFFSET ' . $offset;
     } else {
         $qry .= ' LIMIT ' . $offset . ', ' . $limit;
     }
     $tag = Memcached_DataObject::cachedQuery('Notice_tag', sprintf($qry, $this->user->id), 3600);
     return $tag;
 }
Ejemplo n.º 9
0
 function getNotices()
 {
     if (common_config('db', 'type') == 'pgsql') {
         $weightexpr = 'sum(exp(-extract(epoch from (now() - fave.modified)) / %s))';
     } else {
         $weightexpr = 'sum(exp(-(now() - fave.modified) / %s))';
     }
     $qry = 'SELECT notice.*, ' . $weightexpr . ' as weight ' . 'FROM notice JOIN fave ON notice.id = fave.notice_id ' . 'GROUP BY notice.id,notice.profile_id,notice.content,notice.uri,' . 'notice.rendered,notice.url,notice.created,notice.modified,' . 'notice.reply_to,notice.is_local,notice.source ' . 'ORDER BY weight DESC';
     $offset = 0;
     $limit = NOTICES_PER_SECTION + 1;
     if (common_config('db', 'type') == 'pgsql') {
         $qry .= ' LIMIT ' . $limit . ' OFFSET ' . $offset;
     } else {
         $qry .= ' LIMIT ' . $offset . ', ' . $limit;
     }
     $notice = Memcached_DataObject::cachedQuery('Notice', sprintf($qry, common_config('popular', 'dropoff')), 1200);
     return $notice;
 }
Ejemplo n.º 10
0
 function getTags()
 {
     if (common_config('db', 'type') == 'pgsql') {
         $weightexpr = 'sum(exp(-extract(epoch from (now() - notice_tag.created)) / %s))';
     } else {
         $weightexpr = 'sum(exp(-(now() - notice_tag.created) / %s))';
     }
     $qry = 'SELECT notice_tag.tag, ' . $weightexpr . ' as weight ' . 'FROM notice_tag JOIN notice ' . 'ON notice_tag.notice_id = notice.id ' . 'JOIN group_inbox on group_inbox.notice_id = notice.id ' . 'WHERE group_inbox.group_id = %d ' . 'GROUP BY notice_tag.tag ' . 'ORDER BY weight DESC ';
     $limit = TAGS_PER_SECTION;
     $offset = 0;
     if (common_config('db', 'type') == 'pgsql') {
         $qry .= ' LIMIT ' . $limit . ' OFFSET ' . $offset;
     } else {
         $qry .= ' LIMIT ' . $offset . ', ' . $limit;
     }
     $tag = Memcached_DataObject::cachedQuery('Notice_tag', sprintf($qry, common_config('tag', 'dropoff'), $this->group->id), 3600);
     return $tag;
 }
Ejemplo n.º 11
0
 /**
  * Content area
  *
  * Shows the list of popular notices
  *
  * @return void
  */
 function showContent()
 {
     $groupId = intval($this->group->id);
     $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 ' . 'FROM notice ' . "JOIN group_inbox ON notice.id = group_inbox.notice_id " . 'JOIN fave ON notice.id = fave.notice_id ' . "WHERE {$cutoff} AND group_id = {$groupId} " . 'GROUP BY id,profile_id,uri,content,rendered,url,created,notice.modified,reply_to,is_local,source,notice.conversation ' . 'ORDER BY weight DESC';
     $offset = ($this->page - 1) * NOTICES_PER_PAGE;
     $limit = NOTICES_PER_PAGE + 1;
     if (common_config('db', 'type') == 'pgsql') {
         $qry .= ' LIMIT ' . $limit . ' OFFSET ' . $offset;
     } else {
         $qry .= ' LIMIT ' . $offset . ', ' . $limit;
     }
     $notice = Memcached_DataObject::cachedQuery('Notice', $qry, 600);
     $nl = new NoticeList($notice, $this);
     $cnt = $nl->show();
     if ($cnt == 0) {
         //$this->showEmptyList();
     }
     $this->pagination($this->page > 1, $cnt > NOTICES_PER_PAGE, $this->page, 'groupfavorited', array('nickname' => $this->group->nickname));
 }
 function getTags()
 {
     $weightexpr = common_sql_weight('notice_tag.created', common_config('tag', 'dropoff'));
     // @fixme should we use the cutoff too? Doesn't help with indexing per-group.
     $names = $this->group->getAliases();
     $names = array_merge(array($this->group->nickname), $names);
     // XXX This is dumb.
     $quoted = array();
     foreach ($names as $name) {
         $quoted[] = "'{$name}'";
     }
     $namestring = implode(',', $quoted);
     $qry = 'SELECT notice_tag.tag, ' . $weightexpr . ' as weight ' . 'FROM notice_tag JOIN notice ' . 'ON notice_tag.notice_id = notice.id ' . 'JOIN group_inbox on group_inbox.notice_id = notice.id ' . 'WHERE group_inbox.group_id = %d ' . 'AND notice_tag.tag not in (%s) ' . 'GROUP BY notice_tag.tag ' . 'ORDER BY weight DESC ';
     $limit = TAGS_PER_SECTION;
     $offset = 0;
     if (common_config('db', 'type') == 'pgsql') {
         $qry .= ' LIMIT ' . $limit . ' OFFSET ' . $offset;
     } else {
         $qry .= ' LIMIT ' . $offset . ', ' . $limit;
     }
     $tag = Memcached_DataObject::cachedQuery('Notice_tag', sprintf($qry, $this->group->id, $namestring), 3600);
     return $tag;
 }
Ejemplo n.º 13
0
 /**
  * Content area
  *
  * Shows the list of popular notices
  *
  * @return void
  */
 function showContent()
 {
     if (common_config('db', 'type') == 'pgsql') {
         $weightexpr = 'sum(exp(-extract(epoch from (now() - fave.modified)) / %s))';
     } else {
         $weightexpr = 'sum(exp(-(now() - fave.modified) / %s))';
     }
     $qry = 'SELECT notice.*, ' . $weightexpr . ' as weight ' . 'FROM notice JOIN fave ON notice.id = fave.notice_id ' . 'GROUP BY id,profile_id,uri,content,rendered,url,created,notice.modified,reply_to,is_local,source ' . 'ORDER BY weight DESC';
     $offset = ($this->page - 1) * NOTICES_PER_PAGE;
     $limit = NOTICES_PER_PAGE + 1;
     if (common_config('db', 'type') == 'pgsql') {
         $qry .= ' LIMIT ' . $limit . ' OFFSET ' . $offset;
     } else {
         $qry .= ' LIMIT ' . $offset . ', ' . $limit;
     }
     $notice = Memcached_DataObject::cachedQuery('Notice', sprintf($qry, common_config('popular', 'dropoff')), 600);
     $nl = new NoticeList($notice, $this);
     $cnt = $nl->show();
     $this->pagination($this->page > 1, $cnt > NOTICES_PER_PAGE, $this->page, 'favorited');
 }