PSR2-format

This commit is contained in:
brunoccast 2019-06-02 13:46:39 +01:00 committed by Diogo Cordeiro
parent ab24f59660
commit 691df04103
4 changed files with 203 additions and 215 deletions

View File

@ -28,7 +28,9 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
if (!defined('GNUSOCIAL')) { exit(1); }
if (!defined('GNUSOCIAL')) {
exit(1);
}
/**
* Conversation tree in the browser
@ -45,9 +47,9 @@ if (!defined('GNUSOCIAL')) { exit(1); }
*/
class ConversationAction extends ManagedAction
{
var $conv = null;
var $page = null;
var $notices = null;
public $conv = null;
public $page = null;
public $notices = null;
protected function doPreparation()
{
@ -59,7 +61,7 @@ class ConversationAction extends ManagedAction
*
* @return string page title
*/
function title()
public function title()
{
// TRANS: Title for page with a conversion (multiple notices in context).
return _('Conversation');
@ -72,48 +74,48 @@ class ConversationAction extends ManagedAction
*
* @return void
*/
function showContent()
public function showContent()
{
if (Event::handle('StartShowConversation', array($this, $this->conv, $this->scoped))) {
if (Event::handle('StartShowConversation', [$this, $this->conv, $this->scoped])) {
$notices = $this->conv->getNotices($this->scoped);
$nl = new FullThreadedNoticeList($notices, $this, $this->scoped);
$cnt = $nl->show();
}
Event::handle('EndShowConversation', array($this, $this->conv, $this->scoped));
Event::handle('EndShowConversation', [$this, $this->conv, $this->scoped]);
}
function isReadOnly($args)
public function isReadOnly($args)
{
return true;
}
function getFeeds()
public function getFeeds()
{
return array(new Feed(Feed::JSON,
common_local_url('apiconversation',
array(
'id' => $this->conv->getID(),
'format' => 'as')),
// TRANS: Title for link to notice feed.
// TRANS: %s is a user nickname.
_('Conversation feed (Activity Streams JSON)')),
new Feed(Feed::RSS2,
common_local_url('apiconversation',
array(
'id' => $this->conv->getID(),
'format' => 'rss')),
// TRANS: Title for link to notice feed.
// TRANS: %s is a user nickname.
_('Conversation feed (RSS 2.0)')),
new Feed(Feed::ATOM,
common_local_url('apiconversation',
array(
'id' => $this->conv->getID(),
'format' => 'atom')),
// TRANS: Title for link to notice feed.
// TRANS: %s is a user nickname.
_('Conversation feed (Atom)')));
return [
new Feed(Feed::JSON,
common_local_url('apiconversation',
['id' => $this->conv->getID(),
'format' => 'as']),
// TRANS: Title for link to notice feed.
// TRANS: %s is a user nickname.
_('Conversation feed (Activity Streams JSON)')
),
new Feed(Feed::RSS2,
common_local_url('apiconversation',
['id' => $this->conv->getID(),
'format' => 'rss']),
// TRANS: Title for link to notice feed.
// TRANS: %s is a user nickname.
_('Conversation feed (RSS 2.0)')
),
new Feed(Feed::ATOM,
common_local_url('apiconversation',
['id' => $this->conv->getID(),
'format' => 'atom']),
// TRANS: Title for link to notice feed.
// TRANS: %s is a user nickname.
_('Conversation feed (Atom)')
)
];
}
}

View File

@ -27,7 +27,9 @@
* @link http://status.net/
*/
if (!defined('GNUSOCIAL')) { exit(1); }
if (!defined('GNUSOCIAL')) {
exit(1);
}
require_once INSTALLDIR.'/lib/noticelist.php';
@ -45,17 +47,17 @@ class ShownoticeAction extends ManagedAction
/**
* Notice object to show
*/
var $notice = null;
public $notice = null;
/**
* Profile of the notice object
*/
var $profile = null;
public $profile = null;
/**
* Avatar of the profile of the notice object
*/
var $avatar = null;
public $avatar = null;
/**
* Load attributes based on database arguments
@ -66,7 +68,7 @@ class ShownoticeAction extends ManagedAction
*
* @return success flag
*/
protected function prepare(array $args=array())
protected function prepare(array $args=[])
{
parent::prepare($args);
if ($this->boolean('ajax')) {
@ -122,7 +124,7 @@ class ShownoticeAction extends ManagedAction
} catch (NoResultException $e) {
// Hm, not found.
$deleted = null;
Event::handle('IsNoticeDeleted', array($id, &$deleted));
Event::handle('IsNoticeDeleted', [$id, &$deleted]);
if ($deleted === true) {
// TRANS: Client error displayed trying to show a deleted notice.
throw new ClientException(_('Notice deleted.'), 410);
@ -137,7 +139,7 @@ class ShownoticeAction extends ManagedAction
*
* @return boolean true
*/
function isReadOnly($args)
public function isReadOnly($args)
{
return true;
}
@ -150,7 +152,7 @@ class ShownoticeAction extends ManagedAction
*
* @return int last-modified date as unix timestamp
*/
function lastModified()
public function lastModified()
{
return max(strtotime($this->notice->modified),
strtotime($this->profile->modified),
@ -166,18 +168,18 @@ class ShownoticeAction extends ManagedAction
*
* @return string etag
*/
function etag()
public function etag()
{
$avtime = ($this->avatar) ?
strtotime($this->avatar->modified) : 0;
return 'W/"' . implode(':', array($this->arg('action'),
common_user_cache_hash(),
common_language(),
$this->notice->id,
strtotime($this->notice->created),
strtotime($this->profile->modified),
$avtime)) . '"';
return 'W/"' . implode(':', [$this->arg('action'),
common_user_cache_hash(),
common_language(),
$this->notice->id,
strtotime($this->notice->created),
strtotime($this->profile->modified),
$avtime]) . '"';
}
/**
@ -185,7 +187,7 @@ class ShownoticeAction extends ManagedAction
*
* @return string title of the page
*/
function title()
public function title()
{
return $this->notice->getTitle();
}
@ -197,9 +199,9 @@ class ShownoticeAction extends ManagedAction
*
* @return void
*/
function showContent()
public function showContent()
{
$this->elementStart('ol', array('class' => 'notices xoxo'));
$this->elementStart('ol', ['class' => 'notices xoxo']);
$nli = new NoticeListItem($this->notice, $this);
$nli->show();
$this->elementEnd('ol');
@ -210,28 +212,30 @@ class ShownoticeAction extends ManagedAction
*
* @return void
*/
function showPageNoticeBlock()
public function showPageNoticeBlock()
{
}
function getFeeds()
public function getFeeds()
{
return array(new Feed(Feed::JSON,
common_local_url('ApiStatusesShow',
array(
'id' => $this->target->getID(),
'format' => 'json')),
// TRANS: Title for link to single notice representation.
// TRANS: %s is a user nickname.
sprintf(_('Single notice (JSON)'))),
new Feed(Feed::ATOM,
common_local_url('ApiStatusesShow',
array(
'id' => $this->target->getID(),
'format' => 'atom')),
// TRANS: Title for link to notice feed.
// TRANS: %s is a user nickname.
sprintf(_('Single notice (Atom)'))));
return [
new Feed(Feed::JSON,
common_local_url('ApiStatusesShow',
['id' => $this->target->getID(),
'format' => 'json']),
// TRANS: Title for link to single notice representation.
// TRANS: %s is a user nickname.
sprintf(_('Single notice (JSON)'))
),
new Feed(Feed::ATOM,
common_local_url('ApiStatusesShow',
['id' => $this->target->getID(),
'format' => 'atom']),
// TRANS: Title for link to notice feed.
// TRANS: %s is a user nickname.
sprintf(_('Single notice (Atom)'))
)
];
}
/**
@ -241,13 +245,13 @@ class ShownoticeAction extends ManagedAction
*
* @return void
*/
function extraHead()
public function extraHead()
{
// Extras to aid in sharing notices to Facebook
$avatarUrl = $this->profile->avatarUrl(AVATAR_PROFILE_SIZE);
$this->element('meta', array('property' => 'og:image',
'content' => $avatarUrl));
$this->element('meta', array('property' => 'og:description',
'content' => $this->notice->content));
$this->element('meta', ['property' => 'og:image',
'content' => $avatarUrl]);
$this->element('meta', ['property' => 'og:description',
'content' => $this->notice->content]);
}
}

View File

@ -27,7 +27,9 @@
* @link http://status.net/
*/
if (!defined('GNUSOCIAL')) { exit(1); }
if (!defined('GNUSOCIAL')) {
exit(1);
}
/**
* Group directory
@ -81,7 +83,7 @@ class GroupdirectoryAction extends ManagedAction
*
* @return string Title of the page
*/
function title()
public function title()
{
// @fixme: This looks kinda gross
@ -92,7 +94,7 @@ class GroupdirectoryAction extends ManagedAction
}
// TRANS: Title for group directory page.
return _m('Group directory');
} else if ($this->page == 1) {
} elseif ($this->page == 1) {
return sprintf(
// TRANS: Title for group directory page when it is filtered.
// TRANS: %s is the filter string.
@ -115,7 +117,7 @@ class GroupdirectoryAction extends ManagedAction
*
* @return instructions for use
*/
function getInstructions()
public function getInstructions()
{
// TRANS: Page instructions.
return _m("After you join a group you can send messages to all other members\n".
@ -129,7 +131,7 @@ class GroupdirectoryAction extends ManagedAction
*
* @return boolean true
*/
function isReadOnly($args)
public function isReadOnly($args)
{
return true;
}
@ -152,7 +154,7 @@ class GroupdirectoryAction extends ManagedAction
*
* @return void
*/
function showPageNotice()
public function showPageNotice()
{
$instr = $this->getInstructions();
$output = common_markup_to_html($instr);
@ -170,32 +172,25 @@ class GroupdirectoryAction extends ManagedAction
*
* @return void
*/
function showContent()
public function showContent()
{
if (common_logged_in()) {
$this->elementStart(
'p',
array(
'id' => 'new_group'
)
);
$this->element(
'a',
array(
'href' => common_local_url('newgroup'),
'class' => 'more'),
// TRANS: Link to create a new group on the group list page.
_m('Create a new group')
);
$this->elementStart('p',
['id' => 'new_group']);
$this->element('a',
['href' => common_local_url('newgroup'),
'class' => 'more'],
// TRANS: Link to create a new group on the group list page.
_m('Create a new group'));
$this->elementEnd('p');
}
$this->showForm();
$this->elementStart('div', array('id' => 'profile_directory'));
$this->elementStart('div', ['id' => 'profile_directory']);
// @todo FIXME: Does "All" need i18n here?
$alphaNav = new AlphaNav($this, false, false, array('0-9', 'All'));
$alphaNav = new AlphaNav($this, false, false, ['0-9', 'All']);
$alphaNav->show();
$group = null;
@ -217,7 +212,7 @@ class GroupdirectoryAction extends ManagedAction
}
}
$args = array();
$args = [];
if (isset($this->q)) {
$args['q'] = $this->q;
} else {
@ -235,17 +230,13 @@ class GroupdirectoryAction extends ManagedAction
$this->elementEnd('div');
}
function showForm($error=null)
public function showForm($error=null)
{
$this->elementStart(
'form',
array(
'method' => 'get',
'id' => 'form_search',
'class' => 'form_settings',
'action' => common_local_url('groupdirectory')
)
);
$this->elementStart('form',
['method' => 'get',
'id' => 'form_search',
'class' => 'form_settings',
'action' => common_local_url('groupdirectory')]);
$this->elementStart('fieldset');
@ -258,7 +249,7 @@ class GroupdirectoryAction extends ManagedAction
$this->input('q', _m('Keyword(s)'), $this->q);
// TRANS: Button text for searching group directory.
$this->submit('search', _m('BUTTON','Search'));
$this->submit('search', _m('BUTTON', 'Search'));
$this->elementEnd('li');
$this->elementEnd('ul');
$this->elementEnd('fieldset');
@ -269,55 +260,56 @@ class GroupdirectoryAction extends ManagedAction
* Get groups filtered by the current filter, sort key,
* sort order, and page
*/
function getGroups()
public function getGroups()
{
$group = new User_group();
// Disable this to get global group searches
$group->joinAdd(array('id', 'local_group:group_id'));
$group->joinAdd(['id', 'local_group:group_id']);
$order = false;
if (!empty($this->q)) {
$wheres = array('nickname', 'fullname', 'homepage', 'description', 'location');
$wheres = ['nickname', 'fullname', 'homepage', 'description', 'location'];
foreach ($wheres as $where) {
// Double % because of sprintf
$group->whereAdd(sprintf('LOWER(%1$s.%2$s) LIKE LOWER("%%%3$s%%")',
$group->escapedTableName(), $where,
$group->escape($this->q)),
'OR');
$group->escapedTableName(),
$where,
$group->escape($this->q)),
'OR');
}
$order = sprintf('%1$s.%2$s %3$s',
$group->escapedTableName(),
$this->getSortKey('created'),
$this->reverse ? 'DESC' : 'ASC');
$group->escapedTableName(),
$this->getSortKey('created'),
$this->reverse ? 'DESC' : 'ASC');
} else {
// User is browsing via AlphaNav
switch($this->filter) {
switch ($this->filter) {
case 'all':
// NOOP
break;
case '0-9':
$group->whereAdd(sprintf('LEFT(%1$s.%2$s, 1) BETWEEN %3$s AND %4$s',
$group->escapedTableName(),
'nickname',
$group->_quote("0"),
$group->_quote("9")));
$group->escapedTableName(),
'nickname',
$group->_quote("0"),
$group->_quote("9")));
break;
default:
$group->whereAdd(sprintf('LEFT(LOWER(%1$s.%2$s), 1) = %3$s',
$group->escapedTableName(),
'nickname',
$group->_quote($this->filter)));
$group->escapedTableName(),
'nickname',
$group->_quote($this->filter)));
}
$order = sprintf('%1$s.%2$s %3$s, %1$s.%4$s ASC',
$group->escapedTableName(),
$this->getSortKey('nickname'),
$this->reverse ? 'DESC' : 'ASC',
'nickname');
$group->escapedTableName(),
$this->getSortKey('nickname'),
$this->reverse ? 'DESC' : 'ASC',
'nickname');
}
$offset = ($this->page-1) * PROFILES_PER_PAGE;
@ -338,7 +330,7 @@ class GroupdirectoryAction extends ManagedAction
*
* @return string a column name for sorting
*/
function getSortKey($def='created')
public function getSortKey($def='created')
{
switch ($this->sort) {
case 'nickname':
@ -352,19 +344,16 @@ class GroupdirectoryAction extends ManagedAction
/**
* Show a nice message when there's no search results
*/
function showEmptyListMessage()
public function showEmptyListMessage()
{
if (!empty($this->filter) && ($this->filter != 'all')) {
$this->element(
'p',
'error',
sprintf(
// TRANS: Empty list message for searching group directory.
// TRANS: %s is the search string.
_m('No groups starting with %s.'),
$this->filter
)
);
$this->element('p',
'error',
sprintf(
// TRANS: Empty list message for searching group directory.
// TRANS: %s is the search string.
_m('No groups starting with %s.'),
$this->filter));
} else {
// TRANS: Empty list message for searching group directory.
$this->element('p', 'error', _m('No results.'));
@ -379,7 +368,7 @@ class GroupdirectoryAction extends ManagedAction
}
}
function showSections()
public function showSections()
{
$gbp = new GroupsByPostsSection($this);
$gbp->show();

View File

@ -27,7 +27,9 @@
* @link http://status.net/
*/
if (!defined('GNUSOCIAL')) { exit(1); }
if (!defined('GNUSOCIAL')) {
exit(1);
}
/**
* User directory
@ -80,7 +82,7 @@ class UserdirectoryAction extends ManagedAction
*
* @return string Title of the page
*/
function title()
public function title()
{
// @todo fixme: This looks kinda gross
@ -91,7 +93,7 @@ class UserdirectoryAction extends ManagedAction
}
// TRANS: Page title for user directory.
return _m('User directory');
} else if ($this->page == 1) {
} elseif ($this->page == 1) {
return sprintf(
// TRANS: Page title for user directory. %s is the applied filter.
_m('User directory - %s'),
@ -113,13 +115,12 @@ class UserdirectoryAction extends ManagedAction
*
* @return instructions for use
*/
function getInstructions()
public function getInstructions()
{
// TRANS: %%site.name%% is the name of the StatusNet site.
return _m('Search for people on %%site.name%% by their name, '
. 'location, or interests. Separate the terms by spaces; '
. ' they must be 3 characters or more.'
);
. 'location, or interests. Separate the terms by spaces; '
. ' they must be 3 characters or more.');
}
/**
@ -127,7 +128,7 @@ class UserdirectoryAction extends ManagedAction
*
* @return boolean true
*/
function isReadOnly($args)
public function isReadOnly($args)
{
return true;
}
@ -150,7 +151,7 @@ class UserdirectoryAction extends ManagedAction
*
* @return void
*/
function showPageNotice()
public function showPageNotice()
{
$instr = $this->getInstructions();
$output = common_markup_to_html($instr);
@ -168,13 +169,13 @@ class UserdirectoryAction extends ManagedAction
*
* @return void
*/
function showContent()
public function showContent()
{
$this->showForm();
$this->elementStart('div', array('id' => 'profile_directory'));
$this->elementStart('div', ['id' => 'profile_directory']);
$alphaNav = new AlphaNav($this, false, false, array('0-9', 'All'));
$alphaNav = new AlphaNav($this, false, false, ['0-9', 'All']);
$alphaNav->show();
$profile = null;
@ -196,7 +197,7 @@ class UserdirectoryAction extends ManagedAction
}
}
$args = array();
$args = [];
if (isset($this->q)) {
$args['q'] = $this->q;
} elseif (isset($this->filter) && $this->filter != 'all') {
@ -205,7 +206,7 @@ class UserdirectoryAction extends ManagedAction
if (isset($this->sort)) {
$args['sort'] = $this->sort;
}
}
if (!empty($this->reverse)) {
$args['reverse'] = $this->reverse;
}
@ -219,20 +220,15 @@ class UserdirectoryAction extends ManagedAction
);
$this->elementEnd('div');
}
function showForm($error=null)
public function showForm($error=null)
{
$this->elementStart(
'form',
array(
'method' => 'get',
'id' => 'form_search',
'class' => 'form_settings',
'action' => common_local_url('userdirectory')
)
);
$this->elementStart('form',
['method' => 'get',
'id' => 'form_search',
'class' => 'form_settings',
'action' => common_local_url('userdirectory')]);
$this->elementStart('fieldset');
@ -245,7 +241,7 @@ class UserdirectoryAction extends ManagedAction
$this->input('q', _m('Keyword(s)'), $this->q);
// TRANS: Button text.
$this->submit('search', _m('BUTTON','Search'));
$this->submit('search', _m('BUTTON', 'Search'));
$this->elementEnd('li');
$this->elementEnd('ul');
$this->elementEnd('fieldset');
@ -256,39 +252,39 @@ class UserdirectoryAction extends ManagedAction
* Get users filtered by the current filter, sort key,
* sort order, and page
*/
function getUsers()
public function getUsers()
{
$profile = new Profile();
// Comment this out or disable to get global profile searches
$profile->joinAdd(array('id', 'user:id'));
$profile->joinAdd(['id', 'user:id']);
$offset = ($this->page - 1) * PROFILES_PER_PAGE;
$limit = PROFILES_PER_PAGE + 1;
if (!empty($this->q)) {
// User is searching via query
$search_engine = $profile->getSearchEngine('profile');
// User is searching via query
$search_engine = $profile->getSearchEngine('profile');
$mode = 'reverse_chron';
$mode = 'reverse_chron';
if ($this->sort == 'nickname') {
if ($this->reverse) {
$mode = 'nickname_desc';
} else {
$mode = 'nickname_asc';
}
} else {
if ($this->reverse) {
$mode = 'chron';
}
}
if ($this->sort == 'nickname') {
if ($this->reverse) {
$mode = 'nickname_desc';
} else {
$mode = 'nickname_asc';
}
} else {
if ($this->reverse) {
$mode = 'chron';
}
}
$search_engine->set_sort_mode($mode);
$search_engine->limit($offset, $limit);
$search_engine->query($this->q);
$search_engine->set_sort_mode($mode);
$search_engine->limit($offset, $limit);
$search_engine->query($this->q);
$profile->find();
$profile->find();
} else {
// User is browsing via AlphaNav
@ -298,23 +294,23 @@ class UserdirectoryAction extends ManagedAction
break;
case '0-9':
$profile->whereAdd(sprintf('LEFT(%1$s.%2$s, 1) BETWEEN %3$s AND %4$s',
$profile->escapedTableName(),
'nickname',
$profile->_quote("0"),
$profile->_quote("9")));
$profile->escapedTableName(),
'nickname',
$profile->_quote("0"),
$profile->_quote("9")));
break;
default:
$profile->whereAdd(sprintf('LEFT(LOWER(%1$s.%2$s), 1) = %3$s',
$profile->escapedTableName(),
'nickname',
$profile->_quote($this->filter)));
$profile->escapedTableName(),
'nickname',
$profile->_quote($this->filter)));
}
$order = sprintf('%1$s.%2$s %3$s, %1$s.%4$s ASC',
$profile->escapedTableName(),
$this->getSortKey('nickname'),
$this->reverse ? 'DESC' : 'ASC',
'nickname');
$profile->escapedTableName(),
$this->getSortKey('nickname'),
$this->reverse ? 'DESC' : 'ASC',
'nickname');
$profile->orderBy($order);
$profile->limit($offset, $limit);
@ -329,7 +325,7 @@ class UserdirectoryAction extends ManagedAction
*
* @return string a column name for sorting
*/
function getSortKey($def='nickname')
public function getSortKey($def='nickname')
{
switch ($this->sort) {
case 'nickname':
@ -343,18 +339,15 @@ class UserdirectoryAction extends ManagedAction
/**
* Show a nice message when there's no search results
*/
function showEmptyListMessage()
public function showEmptyListMessage()
{
if (!empty($this->filter) && ($this->filter != 'all')) {
$this->element(
'p',
'error',
sprintf(
// TRANS: Empty list message for user directory.
_m('No users starting with %s'),
$this->filter
)
);
$this->element('p',
'error',
sprintf(
// TRANS: Empty list message for user directory.
_m('No users starting with %s'),
$this->filter));
} else {
// TRANS: Empty list message for user directory.
$this->element('p', 'error', _m('No results.'));