From: Roland Haeder Date: Fri, 12 Sep 2014 16:52:26 +0000 (+0200) Subject: Some cleanups: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=9c4e6bfe4692436e3b84534d3ecc876022558d09;p=quix0rs-gnu-social.git Some cleanups: - Used instanceof to compare object instance with class (not the best, interfaces would be better) - Improved some SQL queries by addding backticks - Converted some double-quotes to single Signed-off-by: Roland Haeder --- diff --git a/actions/addpeopletag.php b/actions/addpeopletag.php index b501ce0fd9..551e968859 100644 --- a/actions/addpeopletag.php +++ b/actions/addpeopletag.php @@ -127,7 +127,8 @@ class AddpeopletagAction extends Action if (!$ptag) { $user = User::getKV('id', $id); - if ($user) { + + if ($user instanceof User) { $this->clientError( // TRANS: Client error displayed when an unknown error occurs when adding a user to a list. // TRANS: %s is a username. diff --git a/actions/block.php b/actions/block.php index 53d8ae7ae0..71d009b788 100644 --- a/actions/block.php +++ b/actions/block.php @@ -220,7 +220,8 @@ class BlockAction extends ProfileFormAction function defaultReturnTo() { $user = common_current_user(); - if ($user) { + + if ($user instanceof User) { return common_local_url('subscribers', array('nickname' => $user->nickname)); } else { diff --git a/actions/removepeopletag.php b/actions/removepeopletag.php index 8192e86b44..3d9cfe5332 100644 --- a/actions/removepeopletag.php +++ b/actions/removepeopletag.php @@ -129,7 +129,7 @@ class RemovepeopletagAction extends Action if (!$ptag) { $user = User::getKV('id', $this->tagged->id); - if ($user) { + if ($user instanceof User) { $this->clientError( // TRANS: Client error displayed when an unknown error occurs while delisting a user. // TRANS: %s is a username. diff --git a/classes/Message.php b/classes/Message.php index cc605ab54f..2f5938adcb 100644 --- a/classes/Message.php +++ b/classes/Message.php @@ -81,12 +81,14 @@ class Message extends Managed_DataObject $msg->from_profile = $from; $msg->to_profile = $to; - if ($user) { + + if ($user instanceof User) { // Use the sender's URL shortening options. $msg->content = $user->shortenLinks($content); } else { $msg->content = common_shorten_links($content); } + $msg->rendered = common_render_text($msg->content); $msg->created = common_sql_now(); $msg->source = $source; diff --git a/lib/grouplist.php b/lib/grouplist.php index 39e904222a..d29a149573 100644 --- a/lib/grouplist.php +++ b/lib/grouplist.php @@ -136,7 +136,7 @@ class GroupList extends Widget $this->out->elementEnd('div'); - if ($user) { + if ($user instanceof User) { $this->out->elementStart('div', 'entity_actions'); $this->out->elementStart('ul'); $this->out->elementStart('li', 'entity_subscribe'); diff --git a/lib/noticelistitem.php b/lib/noticelistitem.php index 57207339a9..d0b5bed068 100644 --- a/lib/noticelistitem.php +++ b/lib/noticelistitem.php @@ -150,7 +150,8 @@ class NoticeListItem extends Widget { if (Event::handle('StartShowNoticeOptions', array($this))) { $user = common_current_user(); - if ($user) { + + if ($user instanceof User) { $this->out->elementStart('div', 'notice-options'); if (Event::handle('StartShowNoticeOptionItems', array($this))) { $this->showReplyLink(); @@ -160,6 +161,7 @@ class NoticeListItem extends Widget } $this->out->elementEnd('div'); } + Event::handle('EndShowNoticeOptions', array($this)); } } diff --git a/lib/util.php b/lib/util.php index 08a0cdea2f..b0a7eeb740 100644 --- a/lib/util.php +++ b/lib/util.php @@ -322,7 +322,7 @@ function common_set_user($user) return false; } - if ($user) { + if ($user instanceof User) { if (Event::handle('StartSetUser', array(&$user))) { if (!empty($user)) { if (!$user->hasRight(Right::WEBLOGIN)) { @@ -538,7 +538,7 @@ function common_user_cache_hash($user=false) if ($user === false) { $user = common_current_user(); } - if ($user) { + if ($user instanceof User) { return crc32($user->id . ':' . $user->nickname); } else { return '0'; diff --git a/plugins/Directory/lib/sortablegrouplist.php b/plugins/Directory/lib/sortablegrouplist.php index 2849e75eba..03a83438a0 100644 --- a/plugins/Directory/lib/sortablegrouplist.php +++ b/plugins/Directory/lib/sortablegrouplist.php @@ -234,8 +234,8 @@ class SortableGroupListItem extends SortableSubscriptionListItem function showJoinButton() { $user = $this->owner; - if ($user) { + if ($user instanceof User) { $this->out->elementStart('li', 'entity_subscribe'); // XXX: special-case for user looking at own // subscriptions page diff --git a/plugins/ExtendedProfile/ExtendedProfilePlugin.php b/plugins/ExtendedProfile/ExtendedProfilePlugin.php index aa456c2f9b..13aa476d82 100644 --- a/plugins/ExtendedProfile/ExtendedProfilePlugin.php +++ b/plugins/ExtendedProfile/ExtendedProfilePlugin.php @@ -81,7 +81,8 @@ class ExtendedProfilePlugin extends Plugin function onEndShowAccountProfileBlock(HTMLOutputter $out, Profile $profile) { $user = User::getKV('id', $profile->id); - if ($user) { + + if ($user instanceof User) { $url = common_local_url('profiledetail', array('nickname' => $user->nickname)); // TRANS: Link text on user profile page leading to extended profile page. $out->element('a', array('href' => $url, 'class' => 'profiledetail'), _m('More details...')); diff --git a/plugins/OStatus/actions/ostatusinit.php b/plugins/OStatus/actions/ostatusinit.php index 5666c898af..85ba31c2d8 100644 --- a/plugins/OStatus/actions/ostatusinit.php +++ b/plugins/OStatus/actions/ostatusinit.php @@ -210,7 +210,8 @@ class OStatusInitAction extends Action { if ($this->nickname) { $user = User::getKV('nickname', $this->nickname); - if ($user) { + + if ($user instanceof User) { return common_local_url('userbyid', array('id' => $user->id)); } else { // TRANS: Client error. diff --git a/plugins/OStatus/scripts/fixup-shadow.php b/plugins/OStatus/scripts/fixup-shadow.php index 2f6a6ffa04..817ef4eb16 100644 --- a/plugins/OStatus/scripts/fixup-shadow.php +++ b/plugins/OStatus/scripts/fixup-shadow.php @@ -156,7 +156,7 @@ while ($oprofile->fetch()) { if (preg_match('!/group/(\d+)/id!', $oprofile->getUri(), $matches)) { $id = intval($matches[1]); $group = Local_group::getKV('group_id', $id); - if ($group) { + if ($group instanceof Local_group) { $nick = $group->nickname; } else { $nick = ''; @@ -165,11 +165,13 @@ while ($oprofile->fetch()) { } else if (preg_match('!/user/(\d+)!', $uri, $matches)) { $id = intval($matches[1]); $user = User::getKV('id', $id); - if ($user) { + + if ($user instanceof User) { $nick = $user->nickname; } else { $nick = ''; } + echo "user $id ($nick) hidden by $uri"; } else { echo "$uri matched query, but we don't recognize it.\n"; diff --git a/plugins/OpenID/actions/finishopenidlogin.php b/plugins/OpenID/actions/finishopenidlogin.php index 3a99988fb5..23f12a9e85 100644 --- a/plugins/OpenID/actions/finishopenidlogin.php +++ b/plugins/OpenID/actions/finishopenidlogin.php @@ -271,16 +271,18 @@ class FinishopenidloginAction extends Action $user = oid_get_user($canonical); - if ($user) { + if ($user instanceof User) { oid_set_last($display); // XXX: commented out at @edd's request until better // control over how data flows from OpenID provider. // oid_update_user($user, $sreg); common_set_user($user); common_real_login(true); + if (isset($_SESSION['openid_rememberme']) && $_SESSION['openid_rememberme']) { common_rememberme($user); } + unset($_SESSION['openid_rememberme']); $this->goHome($user->nickname); } else { diff --git a/plugins/Poll/lib/polllistitem.php b/plugins/Poll/lib/polllistitem.php index 875fa9c7d9..29889d6320 100644 --- a/plugins/Poll/lib/polllistitem.php +++ b/plugins/Poll/lib/polllistitem.php @@ -76,7 +76,7 @@ class PollListItem extends NoticeListItemAdapter $out->elementStart('div', array('class' => 'e-content poll-content')); $poll = Poll::getByNotice($notice); if ($poll) { - if ($user) { + if ($user instanceof User) { $profile = $user->getProfile(); $response = $poll->getResponse($profile); if ($response) { diff --git a/plugins/SearchSub/SearchSubPlugin.php b/plugins/SearchSub/SearchSubPlugin.php index ba25bf1b2b..bca04f9dce 100644 --- a/plugins/SearchSub/SearchSubPlugin.php +++ b/plugins/SearchSub/SearchSubPlugin.php @@ -165,7 +165,8 @@ class SearchSubPlugin extends Plugin function onStartNoticeSearchShowResults($action, $q, $notice) { $user = common_current_user(); - if ($user) { + + if ($user instanceof User) { $search = $q; $searchsub = SearchSub::pkeyGet(array('search' => $search, 'profile_id' => $user->id)); @@ -174,6 +175,7 @@ class SearchSubPlugin extends Plugin } else { $form = new SearchSubForm($action, $search); } + $action->elementStart('div', 'entity_actions'); $action->elementStart('ul'); $action->elementStart('li', 'entity_subscribe'); @@ -182,6 +184,7 @@ class SearchSubPlugin extends Plugin $action->elementEnd('ul'); $action->elementEnd('div'); } + return true; } diff --git a/plugins/SlicedFavorites/actions/favoritedslice.php b/plugins/SlicedFavorites/actions/favoritedslice.php index 5c9fb31f8f..bf4242d096 100644 --- a/plugins/SlicedFavorites/actions/favoritedslice.php +++ b/plugins/SlicedFavorites/actions/favoritedslice.php @@ -121,13 +121,13 @@ class FavoritedSliceAction extends FavoritedAction $exclude = $this->nicknamesToIds($this->excludeUsers); if (count($include) == 1) { - return "profile_id = " . intval($include[0]); + return '`profile_id` = ' . intval($include[0]); } else if (count($include) > 1) { - return "profile_id IN (" . implode(',', $include) . ")"; + return '`profile_id` IN (' . implode(',', $include) . ')'; } else if (count($exclude) == 1) { - return "profile_id != " . intval($exclude[0]); + return '`profile_id` != ' . intval($exclude[0]); } else if (count($exclude) > 1) { - return "profile_id NOT IN (" . implode(',', $exclude) . ")"; + return '`profile_id` NOT IN (' . implode(',', $exclude) . ')'; } else { return false; } @@ -144,7 +144,8 @@ class FavoritedSliceAction extends FavoritedAction foreach ($nicks as $nick) { // not the most efficient way for a big list! $user = User::getKV('nickname', $nick); - if ($user) { + + if ($user instanceof User) { $ids[] = intval($user->id); } } diff --git a/plugins/SubMirror/actions/mirrorsettings.php b/plugins/SubMirror/actions/mirrorsettings.php index b5a49fe4fa..44a1fba457 100644 --- a/plugins/SubMirror/actions/mirrorsettings.php +++ b/plugins/SubMirror/actions/mirrorsettings.php @@ -90,7 +90,8 @@ class MirrorSettingsAction extends SettingsAction function showFeedForm($mirror) { $profile = Profile::getKV('id', $mirror->subscribed); - if ($profile) { + + if ($profile instanceof Profile) { $form = new EditMirrorForm($this, $profile); $form->show(); } diff --git a/plugins/TagSub/TagSubPlugin.php b/plugins/TagSub/TagSubPlugin.php index 1c493de0cd..db142e608a 100644 --- a/plugins/TagSub/TagSubPlugin.php +++ b/plugins/TagSub/TagSubPlugin.php @@ -136,7 +136,8 @@ class TagSubPlugin extends Plugin function onStartTagShowContent(TagAction $action) { $user = common_current_user(); - if ($user) { + + if ($user instanceof User) { $tag = $action->trimmed('tag'); $tagsub = TagSub::pkeyGet(array('tag' => $tag, 'profile_id' => $user->id)); @@ -153,6 +154,7 @@ class TagSubPlugin extends Plugin $action->elementEnd('ul'); $action->elementEnd('div'); } + return true; } diff --git a/plugins/YammerImport/lib/yammerimporter.php b/plugins/YammerImport/lib/yammerimporter.php index 54b273a8a1..6af0302f77 100644 --- a/plugins/YammerImport/lib/yammerimporter.php +++ b/plugins/YammerImport/lib/yammerimporter.php @@ -50,7 +50,8 @@ class YammerImporter return Profile::getKV('id', $profileId); } else { $user = User::getKV('nickname', $nickname); - if ($user) { + + if ($user instanceof User) { common_log(LOG_WARNING, "Copying Yammer profile info onto existing user $nickname"); $profile = $user->getProfile(); $this->savePropertiesOn($profile, $data['options'], @@ -59,6 +60,7 @@ class YammerImporter $user = User::register($data['options']); $profile = $user->getProfile(); } + if ($data['avatar']) { try { $this->saveAvatar($data['avatar'], $profile); @@ -159,7 +161,8 @@ class YammerImporter // Save "likes" as favorites... foreach ($data['faves'] as $nickname) { $user = User::getKV('nickname', $nickname); - if ($user) { + + if ($user instanceof User) { Fave::addNew($user->getProfile(), $notice); } } @@ -334,7 +337,7 @@ class YammerImporter // @fixme if we see a group link inline, don't add this? $group = User_group::getKV('id', $groupId); - if ($group) { + if ($group instanceof User_group) { $content .= ' !' . $group->nickname; } } diff --git a/tests/UserRightsTest.php b/tests/UserRightsTest.php index bd9124a91d..031be0cc44 100644 --- a/tests/UserRightsTest.php +++ b/tests/UserRightsTest.php @@ -18,13 +18,16 @@ class UserRightsTest extends PHPUnit_Framework_TestCase function setUp() { $user = User::getKV('nickname', 'userrightstestuser'); - if ($user) { + + if ($user instanceof User) { // Leftover from a broken test run? $profile = $user->getProfile(); $user->delete(); $profile->delete(); } + $this->user = User::register(array('nickname' => 'userrightstestuser')); + if (!$this->user) { throw new Exception("Couldn't register userrightstestuser"); }