Commit 9a92b580 authored by mmn's avatar mmn

ShowstreamAction tidying up

Lots of these changes mean that we're requiring certain values to
either by typed properly or return the expected value. If it doesn't
there should be a fatal exception thrown which we can followup in the
logs and won't go silently suppressed.
parent f8877e01
......@@ -563,14 +563,12 @@ abstract class ImPlugin extends Plugin
return true;
}
function onEndShowHeadElements($action)
function onEndShowHeadElements(Action $action)
{
$aname = $action->trimmed('action');
if ($aname == 'shownotice') {
if ($action instanceof ShownoticeAction) {
$user_im_prefs = new User_im_prefs();
$user_im_prefs->user_id = $action->profile->id;
$user_im_prefs->user_id = $action->notice->getProfile()->getID();
$user_im_prefs->transport = $this->transport;
if ($user_im_prefs->find() && $user_im_prefs->fetch() && $user_im_prefs->microid && $action->notice->uri) {
......@@ -580,13 +578,13 @@ abstract class ImPlugin extends Plugin
'content' => $id->toString()));
}
} else if ($aname == 'showstream') {
} elseif ($action instanceof ShowstreamAction) {
$user_im_prefs = new User_im_prefs();
$user_im_prefs->user_id = $action->user->id;
$user_im_prefs->user_id = $action->getTarget()->getID();
$user_im_prefs->transport = $this->transport;
if ($user_im_prefs->find() && $user_im_prefs->fetch() && $user_im_prefs->microid && $action->profile->profileurl) {
if ($user_im_prefs->find() && $user_im_prefs->fetch() && $user_im_prefs->microid && $action->getTarget()->getUrl()) {
$id = new Microid($this->microiduri($user_im_prefs->screenname),
$action->selfUrl());
$action->element('meta', array('name' => 'microid',
......
......@@ -72,6 +72,9 @@ abstract class ProfileAction extends ManagedAction
public function getTarget()
{
if (!$this->target instanceof Profile) {
throw new ServerException('No target profile in ProfileAction class');
}
return $this->target;
}
......
......@@ -32,18 +32,25 @@ if (!defined('GNUSOCIAL')) { exit(1); }
class ProfileListItem extends Widget
{
/** Current profile. */
protected $target = null;
var $profile = null;
/** Action object using us. */
var $action = null;
function __construct($profile, $action)
function __construct(Profile $target, HTMLOutputter $action)
{
parent::__construct($action);
$this->profile = $profile;
$this->target = $target;
$this->profile = $this->target;
$this->action = $action;
}
function getTarget()
{
return $this->target;
}
function show()
{
if (Event::handle('StartProfileListItem', array($this))) {
......
......@@ -57,25 +57,27 @@ class GeoURLPlugin extends Plugin
*
* @return boolean event handler flag
*/
function onEndShowHeadElements($action)
function onEndShowHeadElements(Action $action)
{
$name = $action->trimmed('action');
$location = null;
if ($name == 'showstream') {
$profile = $action->profile;
if (!empty($profile) && !empty($profile->lat) && !empty($profile->lon)) {
if ($action instanceof ShowstreamAction) {
$profile = $action->getTarget();
if (!empty($profile->lat) && !empty($profile->lon)) {
$location = $profile->lat . ', ' . $profile->lon;
}
} else if ($name == 'shownotice') {
$notice = $action->profile;
if (!empty($notice) && !empty($notice->lat) && !empty($notice->lon)) {
} elseif ($action instanceof ShownoticeAction) {
// FIXME: getNotice in ShownoticeAction will do a new lookup, we should fix those classes
// so they can reliably just get a pre-stored notice object which was fetched in Shownotice prepare()...
$notice = $action->notice;
if ($notice instanceof Notice && !empty($notice->lat) && !empty($notice->lon)) {
$location = $notice->lat . ', ' . $notice->lon;
}
}
if (!empty($location)) {
if (!is_null($location)) {
$action->element('meta', array('name' => 'ICBM',
'content' => $location));
$action->element('meta', array('name' => 'DC.title',
......
......@@ -101,10 +101,10 @@ class ModLogPlugin extends Plugin
$modlog->profile_id = $profile->id;
$cur = common_current_user();
$scoped = Profile::current();
if (!empty($cur)) {
$modlog->moderator_id = $cur->id;
if ($scoped instanceof Profile) {
$modlog->moderator_id = $scoped->getID();
}
$modlog->role = $role;
......@@ -118,21 +118,22 @@ class ModLogPlugin extends Plugin
function onEndShowSections(Action $action)
{
if ($action->arg('action') != 'showstream') {
if (!$action instanceof ShowstreamAction) {
// early return for actions we're not interested in
return true;
}
$cur = common_current_user();
if (empty($cur) || !$cur->hasRight(self::VIEWMODLOG)) {
$scoped = $action->getScoped();
if (!$scoped instanceof Profile || !$scoped->hasRight(self::VIEWMODLOG)) {
// only continue if we are allowed to VIEWMODLOG
return true;
}
$profile = $action->profile;
$profile = $action->getTarget();
$ml = new ModLog();
$ml->profile_id = $profile->id;
$ml->profile_id = $profile->getID();
$ml->orderBy("created");
$cnt = $ml->find();
......@@ -152,13 +153,13 @@ class ModLogPlugin extends Plugin
$action->element('td', null, sprintf(($ml->is_grant) ? _('+%s') : _('-%s'), $ml->role));
$action->elementStart('td');
if ($ml->moderator_id) {
$mod = Profile::getKV('id', $ml->moderator_id);
$mod = Profile::getByID($ml->moderator_id);
if (empty($mod)) {
$action->text(_('[unknown]'));
} else {
$action->element('a', array('href' => $mod->profileurl,
'title' => $mod->fullname),
$mod->nickname);
$action->element('a', array('href' => $mod->getUrl(),
'title' => $mod->getFullname()),
$mod->getNickname());
}
} else {
$action->text(_('[unknown]'));
......
......@@ -1063,12 +1063,16 @@ class OStatusPlugin extends Plugin
function showEntityRemoteSubscribe($action, $target='ostatussub')
{
$user = common_current_user();
if ($user && ($user->id == $action->profile->id)) {
if (!$action->getScoped() instanceof Profile) {
// early return if we're not logged in
return true;
}
if ($action->getScoped()->sameAs($action->getTarget())) {
$action->elementStart('div', 'entity_actions');
$action->elementStart('p', array('id' => 'entity_remote_subscribe',
'class' => 'entity_subscribe'));
$action->element('a', array('href' => common_local_url($target),
$action->element('a', array('href' => common_local_url($action->getTarget()),
'class' => 'entity_remote_subscribe'),
// TRANS: Link text for link to remote subscribe.
_m('Remote'));
......@@ -1127,42 +1131,45 @@ class OStatusPlugin extends Plugin
return true;
}
function onStartProfileListItemActionElements($item, $profile=null)
// FIXME: This one can accept both an Action and a Widget. Confusing! Refactor to (HTMLOutputter $out, Profile $target)!
function onStartProfileListItemActionElements($item)
{
if (!common_logged_in()) {
$profileUser = User::getKV('id', $item->profile->id);
if (!empty($profileUser)) {
if ($item instanceof Action) {
$output = $item;
$profile = $item->profile;
} else {
$output = $item->out;
}
if (common_logged_in()) {
// only non-logged in users get to see the "remote subscribe" form
return true;
} elseif (!$item->getTarget()->isLocal()) {
// we can (for now) only provide remote subscribe forms for local users
return true;
}
// Add an OStatus subscribe
$output->elementStart('li', 'entity_subscribe');
$url = common_local_url('ostatusinit',
array('nickname' => $profileUser->nickname));
$output->element('a', array('href' => $url,
'class' => 'entity_remote_subscribe'),
// TRANS: Link text for a user to subscribe to an OStatus user.
_m('Subscribe'));
$output->elementEnd('li');
$output->elementStart('li', 'entity_tag');
$url = common_local_url('ostatustag',
array('nickname' => $profileUser->nickname));
$output->element('a', array('href' => $url,
'class' => 'entity_remote_tag'),
// TRANS: Link text for a user to list an OStatus user.
_m('List'));
$output->elementEnd('li');
}
if ($item instanceof ProfileAction) {
$output = $item;
} elseif ($item instanceof Widget) {
$output = $item->out;
} else {
// Bad $item class, don't know how to use this for outputting!
throw new ServerException('Bad item type for onStartProfileListItemActionElements');
}
// Add an OStatus subscribe
$output->elementStart('li', 'entity_subscribe');
$url = common_local_url('ostatusinit',
array('nickname' => $item->getTarget()->getNickname()));
$output->element('a', array('href' => $url,
'class' => 'entity_remote_subscribe'),
// TRANS: Link text for a user to subscribe to an OStatus user.
_m('Subscribe'));
$output->elementEnd('li');
$output->elementStart('li', 'entity_tag');
$url = common_local_url('ostatustag',
array('nickname' => $item->getTarget()->getNickname()));
$output->element('a', array('href' => $url,
'class' => 'entity_remote_tag'),
// TRANS: Link text for a user to list an OStatus user.
_m('List'));
$output->elementEnd('li');
return true;
}
......
......@@ -390,11 +390,11 @@ class OpenIDPlugin extends Plugin
$action->element('link', array('rel' => 'openid2.provider',
'href' => common_local_url('openidserver')));
$action->element('link', array('rel' => 'openid2.local_id',
'href' => $action->profile->profileurl));
'href' => $action->getTarget()->getUrl()));
$action->element('link', array('rel' => 'openid.server',
'href' => common_local_url('openidserver')));
$action->element('link', array('rel' => 'openid.delegate',
'href' => $action->profile->profileurl));
'href' => $action->getTarget()->getUrl()));
}
if ($action instanceof SitestreamAction) {
......
......@@ -144,7 +144,7 @@ class WebFingerPlugin extends Plugin
public function onStartShowHTML($action)
{
if ($action instanceof ShowstreamAction) {
$acct = 'acct:'. $action->profile->nickname .'@'. common_config('site', 'server');
$acct = 'acct:'. $action->getTarget()->getNickname() .'@'. common_config('site', 'server');
$url = common_local_url('webfinger') . '?resource='.$acct;
foreach (array(Discovery::JRD_MIMETYPE, Discovery::XRD_MIMETYPE) as $type) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment