X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=classes%2FUser_group.php;h=27b444705d93823a67b8b519226f099e931fd939;hb=65ef1cb72a7d93dc2d031e0d9766ed1fb5c27edc;hp=98ad77cc0174a0191eabd58ba5b12952ec03e429;hpb=7aa496cd8a939960eeaf79f3397f6fe94097e047;p=quix0rs-gnu-social.git diff --git a/classes/User_group.php b/classes/User_group.php old mode 100755 new mode 100644 index 98ad77cc01..27b444705d --- a/classes/User_group.php +++ b/classes/User_group.php @@ -19,6 +19,7 @@ class User_group extends Memcached_DataObject public $homepage_logo; // varchar(255) public $stream_logo; // varchar(255) public $mini_logo; // varchar(255) + public $design_id; // int(4) public $created; // datetime() not_null public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP @@ -50,13 +51,50 @@ class User_group extends Memcached_DataObject function getNotices($offset, $limit) { - $qry = - 'SELECT notice.* ' . - 'FROM notice JOIN group_inbox ON notice.id = group_inbox.notice_id ' . - 'WHERE group_inbox.group_id = %d '; - return Notice::getStream(sprintf($qry, $this->id), - 'group:notices:'.$this->id, - $offset, $limit); + $ids = Notice::stream(array($this, '_streamDirect'), + array(), + 'user_group:notice_ids:' . $this->id, + $offset, $limit); + + return Notice::getStreamByIds($ids); + } + + function _streamDirect($offset, $limit, $since_id, $max_id, $since) + { + $inbox = new Group_inbox(); + + $inbox->group_id = $this->id; + + $inbox->selectAdd(); + $inbox->selectAdd('notice_id'); + + if ($since_id != 0) { + $inbox->whereAdd('notice_id > ' . $since_id); + } + + if ($max_id != 0) { + $inbox->whereAdd('notice_id <= ' . $max_id); + } + + if (!is_null($since)) { + $inbox->whereAdd('created > \'' . date('Y-m-d H:i:s', $since) . '\''); + } + + $inbox->orderBy('notice_id DESC'); + + if (!is_null($offset)) { + $inbox->limit($offset, $limit); + } + + $ids = array(); + + if ($inbox->find()) { + while ($inbox->fetch()) { + $ids[] = $inbox->notice_id; + } + } + + return $ids; } function allowedNickname($nickname) @@ -74,94 +112,186 @@ class User_group extends Memcached_DataObject 'WHERE group_member.group_id = %d ' . 'ORDER BY group_member.created DESC '; - if (common_config('db','type') == 'pgsql') { - $qry .= ' LIMIT ' . $limit . ' OFFSET ' . $offset; - } else { - $qry .= ' LIMIT ' . $offset . ', ' . $limit; + if ($limit != null) { + if (common_config('db','type') == 'pgsql') { + $qry .= ' LIMIT ' . $limit . ' OFFSET ' . $offset; + } else { + $qry .= ' LIMIT ' . $offset . ', ' . $limit; + } } $members = new Profile(); - $cnt = $members->query(sprintf($qry, $this->id)); - + $members->query(sprintf($qry, $this->id)); return $members; } - function setOriginal($filename, $type) + function getAdmins($offset=0, $limit=null) { + $qry = + 'SELECT profile.* ' . + 'FROM profile JOIN group_member '. + 'ON profile.id = group_member.profile_id ' . + 'WHERE group_member.group_id = %d ' . + 'AND group_member.is_admin = 1 ' . + 'ORDER BY group_member.modified ASC '; + + if ($limit != null) { + if (common_config('db','type') == 'pgsql') { + $qry .= ' LIMIT ' . $limit . ' OFFSET ' . $offset; + } else { + $qry .= ' LIMIT ' . $offset . ', ' . $limit; + } + } + + $admins = new Profile(); + + $admins->query(sprintf($qry, $this->id)); + return $admins; + } + + function getBlocked($offset=0, $limit=null) + { + $qry = + 'SELECT profile.* ' . + 'FROM profile JOIN group_block '. + 'ON profile.id = group_block.blocked ' . + 'WHERE group_block.group_id = %d ' . + 'ORDER BY group_block.modified DESC '; + + if ($limit != null) { + if (common_config('db','type') == 'pgsql') { + $qry .= ' LIMIT ' . $limit . ' OFFSET ' . $offset; + } else { + $qry .= ' LIMIT ' . $offset . ', ' . $limit; + } + } + + $blocked = new Profile(); + + $blocked->query(sprintf($qry, $this->id)); + return $blocked; + } + + function setOriginal($filename) + { + $imagefile = new ImageFile($this->id, Avatar::path($filename)); + $orig = clone($this); - $this->original_logo = common_avatar_url($filename); - $this->homepage_logo = common_avatar_url($this->scale($filename, - AVATAR_PROFILE_SIZE, - $type)); - $this->stream_logo = common_avatar_url($this->scale($filename, - AVATAR_STREAM_SIZE, - $type)); - $this->mini_logo = common_avatar_url($this->scale($filename, - AVATAR_MINI_SIZE, - $type)); + $this->original_logo = Avatar::url($filename); + $this->homepage_logo = Avatar::url($imagefile->resize(AVATAR_PROFILE_SIZE)); + $this->stream_logo = Avatar::url($imagefile->resize(AVATAR_STREAM_SIZE)); + $this->mini_logo = Avatar::url($imagefile->resize(AVATAR_MINI_SIZE)); common_debug(common_log_objstring($this)); return $this->update($orig); } - function scale($filename, $size, $type) + function getBestName() { - $filepath = common_avatar_path($filename); + return ($this->fullname) ? $this->fullname : $this->nickname; + } + + function getAliases() + { + $aliases = array(); + + // XXX: cache this + + $alias = new Group_alias(); - if (!file_exists($filepath)) { - $this->serverError(_('Lost our file.')); - return; + $alias->group_id = $this->id; + + if ($alias->find()) { + while ($alias->fetch()) { + $aliases[] = $alias->alias; + } } - $info = @getimagesize($filepath); - - switch ($type) { - case IMAGETYPE_GIF: - $image_src = imagecreatefromgif($filepath); - break; - case IMAGETYPE_JPEG: - $image_src = imagecreatefromjpeg($filepath); - break; - case IMAGETYPE_PNG: - $image_src = imagecreatefrompng($filepath); - break; - default: - $this->serverError(_('Unknown file type')); - return; + $alias->free(); + + return $aliases; + } + + function setAliases($newaliases) { + + $newaliases = array_unique($newaliases); + + $oldaliases = $this->getAliases(); + + # Delete stuff that's old that not in new + + $to_delete = array_diff($oldaliases, $newaliases); + + # Insert stuff that's in new and not in old + + $to_insert = array_diff($newaliases, $oldaliases); + + $alias = new Group_alias(); + + $alias->group_id = $this->id; + + foreach ($to_delete as $delalias) { + $alias->alias = $delalias; + $result = $alias->delete(); + if (!$result) { + common_log_db_error($alias, 'DELETE', __FILE__); + return false; + } + } + + foreach ($to_insert as $insalias) { + $alias->alias = $insalias; + $result = $alias->insert(); + if (!$result) { + common_log_db_error($alias, 'INSERT', __FILE__); + return false; + } + } + + return true; + } + + static function getForNickname($nickname) + { + $nickname = common_canonical_nickname($nickname); + $group = User_group::staticGet('nickname', $nickname); + if (!empty($group)) { + return $group; + } + $alias = Group_alias::staticGet('alias', $nickname); + if (!empty($alias)) { + return User_group::staticGet('id', $alias->group_id); } + return null; + } - $image_dest = imagecreatetruecolor($size, $size); + function getDesign() + { + return Design::staticGet('id', $this->design_id); + } - $background = imagecolorallocate($image_dest, 0, 0, 0); - ImageColorTransparent($image_dest, $background); - imagealphablending($image_dest, false); + function getUserMembers() + { + // XXX: cache this - imagecopyresized($image_dest, $image_src, 0, 0, $x, $y, $size, $size, $info[0], $info[1]); + $user = new User(); - $cur = common_current_user(); + $qry = + 'SELECT id ' . + 'FROM user JOIN group_member '. + 'ON user.id = group_member.profile_id ' . + 'WHERE group_member.group_id = %d '; - $outname = common_avatar_filename($cur->id, - image_type_to_extension($type), - null, - common_timestamp()); + $user->query(sprintf($qry, $this->id)); - $outpath = common_avatar_path($outname); + $ids = array(); - switch ($type) { - case IMAGETYPE_GIF: - imagegif($image_dest, $outpath); - break; - case IMAGETYPE_JPEG: - imagejpeg($image_dest, $outpath); - break; - case IMAGETYPE_PNG: - imagepng($image_dest, $outpath); - break; - default: - $this->serverError(_('Unknown file type')); - return; + while ($user->fetch()) { + $ids[] = $user->id; } - return $outname; + $user->free(); + + return $ids; } }