Removing whitespace and creating an early-return in inScope
This commit is contained in:
parent
325e784ccd
commit
060dbe1b56
@ -1067,13 +1067,9 @@ class Notice extends Managed_DataObject
|
||||
}
|
||||
|
||||
$args = func_get_args();
|
||||
|
||||
$format = array_shift($args);
|
||||
|
||||
$keyPart = vsprintf($format, $args);
|
||||
|
||||
$cacheKey = Cache::key($keyPart);
|
||||
|
||||
$c->delete($cacheKey);
|
||||
|
||||
// delete the "last" stream, too, if this notice is
|
||||
@ -1194,17 +1190,13 @@ class Notice extends Managed_DataObject
|
||||
}
|
||||
|
||||
$f2ps = File_to_post::listGet('post_id', array($this->id));
|
||||
|
||||
$ids = array();
|
||||
|
||||
foreach ($f2ps[$this->id] as $f2p) {
|
||||
$ids[] = $f2p->file_id;
|
||||
}
|
||||
|
||||
$files = File::multiGet('id', $ids);
|
||||
|
||||
$this->_attachments[$this->id] = $files->fetchAll();
|
||||
|
||||
return $this->_attachments[$this->id];
|
||||
}
|
||||
|
||||
@ -1766,15 +1758,12 @@ class Notice extends Managed_DataObject
|
||||
|
||||
$ids = array();
|
||||
|
||||
foreach ($gis[$this->id] as $gi)
|
||||
{
|
||||
foreach ($gis[$this->id] as $gi) {
|
||||
$ids[] = $gi->group_id;
|
||||
}
|
||||
|
||||
$groups = User_group::multiGet('id', $ids);
|
||||
|
||||
$this->_groups[$this->id] = $groups->fetchAll();
|
||||
|
||||
return $this->_groups[$this->id];
|
||||
}
|
||||
|
||||
@ -2687,85 +2676,74 @@ class Notice extends Managed_DataObject
|
||||
$scope = self::defaultScope();
|
||||
}
|
||||
|
||||
// If there's no scope, anyone (even anon) is in scope.
|
||||
|
||||
if ($scope == 0) { // Not private
|
||||
|
||||
return !$this->isHiddenSpam($profile);
|
||||
|
||||
} else { // Private, somehow
|
||||
|
||||
// If there's scope, anon cannot be in scope
|
||||
|
||||
if (empty($profile)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Author is always in scope
|
||||
|
||||
if ($this->profile_id == $profile->id) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Only for users on this site
|
||||
|
||||
if (($scope & Notice::SITE_SCOPE) && !$profile->isLocal()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Only for users mentioned in the notice
|
||||
|
||||
if ($scope & Notice::ADDRESSEE_SCOPE) {
|
||||
|
||||
$reply = Reply::pkeyGet(array('notice_id' => $this->id,
|
||||
'profile_id' => $profile->id));
|
||||
|
||||
if (!$reply instanceof Reply) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Only for members of the given group
|
||||
|
||||
if ($scope & Notice::GROUP_SCOPE) {
|
||||
|
||||
// XXX: just query for the single membership
|
||||
|
||||
$groups = $this->getGroups();
|
||||
|
||||
$foundOne = false;
|
||||
|
||||
foreach ($groups as $group) {
|
||||
if ($profile->isMember($group)) {
|
||||
$foundOne = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$foundOne) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Only for followers of the author
|
||||
|
||||
$author = null;
|
||||
|
||||
if ($scope & Notice::FOLLOWER_SCOPE) {
|
||||
|
||||
try {
|
||||
$author = $this->getProfile();
|
||||
} catch (Exception $e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!Subscription::exists($profile, $author)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if ($scope == 0) { // Not scoping, so it is public.
|
||||
return !$this->isHiddenSpam($profile);
|
||||
}
|
||||
|
||||
// If there's scope, anon cannot be in scope
|
||||
if (empty($profile)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Author is always in scope
|
||||
if ($this->profile_id == $profile->id) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Only for users on this site
|
||||
if (($scope & Notice::SITE_SCOPE) && !$profile->isLocal()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Only for users mentioned in the notice
|
||||
if ($scope & Notice::ADDRESSEE_SCOPE) {
|
||||
|
||||
$reply = Reply::pkeyGet(array('notice_id' => $this->id,
|
||||
'profile_id' => $profile->id));
|
||||
|
||||
if (!$reply instanceof Reply) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Only for members of the given group
|
||||
if ($scope & Notice::GROUP_SCOPE) {
|
||||
|
||||
// XXX: just query for the single membership
|
||||
|
||||
$groups = $this->getGroups();
|
||||
|
||||
$foundOne = false;
|
||||
|
||||
foreach ($groups as $group) {
|
||||
if ($profile->isMember($group)) {
|
||||
$foundOne = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$foundOne) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Only for followers of the author
|
||||
$author = null;
|
||||
|
||||
if ($scope & Notice::FOLLOWER_SCOPE) {
|
||||
|
||||
try {
|
||||
$author = $this->getProfile();
|
||||
} catch (Exception $e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!Subscription::exists($profile, $author)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return !$this->isHiddenSpam($profile);
|
||||
}
|
||||
|
||||
function isHiddenSpam($profile) {
|
||||
@ -2836,7 +2814,6 @@ class Notice extends Managed_DataObject
|
||||
static function fillProfiles($notices)
|
||||
{
|
||||
$map = self::getProfiles($notices);
|
||||
|
||||
foreach ($notices as $entry=>$notice) {
|
||||
try {
|
||||
if (array_key_exists($notice->profile_id, $map)) {
|
||||
@ -2857,22 +2834,17 @@ class Notice extends Managed_DataObject
|
||||
foreach ($notices as $notice) {
|
||||
$ids[] = $notice->profile_id;
|
||||
}
|
||||
|
||||
$ids = array_unique($ids);
|
||||
|
||||
return Profile::pivotGet('id', $ids);
|
||||
}
|
||||
|
||||
static function fillGroups(&$notices)
|
||||
{
|
||||
$ids = self::_idsOf($notices);
|
||||
|
||||
$gis = Group_inbox::listGet('notice_id', $ids);
|
||||
|
||||
$gids = array();
|
||||
|
||||
foreach ($gis as $id => $gi)
|
||||
{
|
||||
foreach ($gis as $id => $gi) {
|
||||
foreach ($gi as $g)
|
||||
{
|
||||
$gids[] = $g->group_id;
|
||||
@ -2880,9 +2852,7 @@ class Notice extends Managed_DataObject
|
||||
}
|
||||
|
||||
$gids = array_unique($gids);
|
||||
|
||||
$group = User_group::pivotGet('id', $gids);
|
||||
|
||||
foreach ($notices as $notice)
|
||||
{
|
||||
$grps = array();
|
||||
@ -2906,11 +2876,8 @@ class Notice extends Managed_DataObject
|
||||
static function fillAttachments(&$notices)
|
||||
{
|
||||
$ids = self::_idsOf($notices);
|
||||
|
||||
$f2pMap = File_to_post::listGet('post_id', $ids);
|
||||
|
||||
$fileIds = array();
|
||||
|
||||
foreach ($f2pMap as $noticeId => $f2ps) {
|
||||
foreach ($f2ps as $f2p) {
|
||||
$fileIds[] = $f2p->file_id;
|
||||
@ -2918,9 +2885,7 @@ class Notice extends Managed_DataObject
|
||||
}
|
||||
|
||||
$fileIds = array_unique($fileIds);
|
||||
|
||||
$fileMap = File::pivotGet('id', $fileIds);
|
||||
|
||||
foreach ($notices as $notice)
|
||||
{
|
||||
$files = array();
|
||||
|
Loading…
Reference in New Issue
Block a user