Merge branch 'master' of gitorious.org:statusnet/mainline into 0.9.x

This commit is contained in:
Brion Vibber 2010-11-15 17:36:48 -08:00
commit e4eb3b3dfd
7 changed files with 292 additions and 18 deletions

View File

@ -494,6 +494,29 @@ class Profile extends Memcached_DataObject
return $cnt;
}
/**
* Is this profile subscribed to another profile?
*
* @param Profile $other
* @return boolean
*/
function isSubscribed($other)
{
return Subscription::exists($this, $other);
}
/**
* Are these two profiles subscribed to each other?
*
* @param Profile $other
* @return boolean
*/
function mutuallySubscribed($other)
{
return $this->isSubscribed($other) &&
$other->isSubscribed($this);
}
function hasFave($notice)
{
$cache = common_memcache();

View File

@ -84,7 +84,8 @@ class User extends Memcached_DataObject
function isSubscribed($other)
{
return Subscription::exists($this->getProfile(), $other);
$profile = $this->getProfile();
return $profile->isSubscribed($other);
}
// 'update' won't write key columns, so we have to do it ourselves.
@ -418,8 +419,8 @@ class User extends Memcached_DataObject
function mutuallySubscribed($other)
{
return $this->isSubscribed($other) &&
$other->isSubscribed($this);
$profile = $this->getProfile();
return $profile->mutuallySubscribed($other);
}
function mutuallySubscribedUsers()

View File

@ -101,7 +101,7 @@ class ProfileAction extends OwnerDesignAction
function showSubscriptions()
{
$profile = $this->user->getSubscriptions(0, PROFILES_PER_MINILIST + 1);
$profile = $this->profile->getSubscriptions(0, PROFILES_PER_MINILIST + 1);
$this->elementStart('div', array('id' => 'entity_subscriptions',
'class' => 'section'));
@ -134,7 +134,7 @@ class ProfileAction extends OwnerDesignAction
function showSubscribers()
{
$profile = $this->user->getSubscribers(0, PROFILES_PER_MINILIST + 1);
$profile = $this->profile->getSubscribers(0, PROFILES_PER_MINILIST + 1);
$this->elementStart('div', array('id' => 'entity_subscribers',
'class' => 'section'));
@ -173,7 +173,7 @@ class ProfileAction extends OwnerDesignAction
$subs_count = $this->profile->subscriptionCount();
$subbed_count = $this->profile->subscriberCount();
$notice_count = $this->profile->noticeCount();
$group_count = $this->user->getGroups()->N;
$group_count = $this->profile->getGroups()->N;
$age_days = (time() - strtotime($this->profile->created)) / 86400;
if ($age_days < 1) {
// Rather than extrapolating out to a bajillion...
@ -241,7 +241,7 @@ class ProfileAction extends OwnerDesignAction
function showGroups()
{
$groups = $this->user->getGroups(0, GROUPS_PER_MINILIST + 1);
$groups = $this->profile->getGroups(0, GROUPS_PER_MINILIST + 1);
$this->elementStart('div', array('id' => 'entity_groups',
'class' => 'section'));
@ -249,7 +249,7 @@ class ProfileAction extends OwnerDesignAction
$this->element('h2', null, _('Groups'));
if ($groups) {
$gml = new GroupMiniList($groups, $this->user, $this);
$gml = new GroupMiniList($groups, $this->profile, $this);
$cnt = $gml->show();
if ($cnt == 0) {
$this->element('p', null, _('(None)'));

View File

@ -98,6 +98,10 @@ class UserProfile extends Widget
if (Event::handle('StartProfilePageAvatar', array($this->out, $this->profile))) {
$avatar = $this->profile->getAvatar(AVATAR_PROFILE_SIZE);
if (!$avatar) {
// hack for remote Twitter users: no 96px, but large Twitter size is 73px
$avatar = $this->profile->getAvatar(73);
}
$this->out->elementStart('dl', 'entity_depiction');
$this->out->element('dt', null, _('Photo'));
@ -109,10 +113,8 @@ class UserProfile extends Widget
'alt' => $this->profile->nickname));
$this->out->elementEnd('dd');
$user = User::staticGet('id', $this->profile->id);
$cur = common_current_user();
if ($cur && $cur->id == $user->id) {
if ($cur && $cur->id == $this->profile->id) {
$this->out->elementStart('dd');
$this->out->element('a', array('href' => common_local_url('avatarsettings')), _('Edit Avatar'));
$this->out->elementEnd('dd');
@ -278,7 +280,7 @@ class UserProfile extends Widget
}
$this->out->elementEnd('li');
if ($cur->mutuallySubscribed($this->user)) {
if ($cur->mutuallySubscribed($this->profile)) {
// message
@ -290,7 +292,7 @@ class UserProfile extends Widget
// nudge
if ($this->user->email && $this->user->emailnotifynudge) {
if ($this->user && $this->user->email && $this->user->emailnotifynudge) {
$this->out->elementStart('li', 'entity_nudge');
$nf = new NudgeForm($this->out, $this->user);
$nf->show();
@ -319,6 +321,9 @@ class UserProfile extends Widget
}
$this->out->elementEnd('li');
// Some actions won't be applicable to non-local users.
$isLocal = !empty($this->user);
if ($cur->hasRight(Right::SANDBOXUSER) ||
$cur->hasRight(Right::SILENCEUSER) ||
$cur->hasRight(Right::DELETEUSER)) {
@ -327,7 +332,7 @@ class UserProfile extends Widget
$this->out->elementStart('ul');
if ($cur->hasRight(Right::SANDBOXUSER)) {
$this->out->elementStart('li', 'entity_sandbox');
if ($this->user->isSandboxed()) {
if ($this->profile->isSandboxed()) {
$usf = new UnSandboxForm($this->out, $this->profile, $r2args);
$usf->show();
} else {
@ -339,7 +344,7 @@ class UserProfile extends Widget
if ($cur->hasRight(Right::SILENCEUSER)) {
$this->out->elementStart('li', 'entity_silence');
if ($this->user->isSilenced()) {
if ($this->profile->isSilenced()) {
$usf = new UnSilenceForm($this->out, $this->profile, $r2args);
$usf->show();
} else {
@ -349,7 +354,7 @@ class UserProfile extends Widget
$this->out->elementEnd('li');
}
if ($cur->hasRight(Right::DELETEUSER)) {
if ($isLocal && $cur->hasRight(Right::DELETEUSER)) {
$this->out->elementStart('li', 'entity_delete');
$df = new DeleteUserForm($this->out, $this->profile, $r2args);
$df->show();
@ -359,7 +364,7 @@ class UserProfile extends Widget
$this->out->elementEnd('li');
}
if ($cur->hasRight(Right::GRANTROLE)) {
if ($isLocal && $cur->hasRight(Right::GRANTROLE)) {
$this->out->elementStart('li', 'entity_role');
$this->out->element('p', null, _('User role'));
$this->out->elementStart('ul');
@ -387,7 +392,7 @@ class UserProfile extends Widget
$r2args['action'] = $action;
$this->out->elementStart('li', "entity_role_$role");
if ($this->user->hasRole($role)) {
if ($this->profile->hasRole($role)) {
$rf = new RevokeRoleForm($role, $label, $this->out, $this->profile, $r2args);
$rf->show();
} else {

View File

@ -0,0 +1,116 @@
<?php
/*
* StatusNet - the distributed open-source microblogging tool
* Copyright (C) 2010, StatusNet, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
if (!defined('STATUSNET')) {
exit(1);
}
/**
* Some UI extras for now...
*
* @package ModPlusPlugin
* @maintainer Brion Vibber <brion@status.net>
*/
class ModPlusPlugin extends Plugin
{
function onPluginVersion(&$versions)
{
$versions[] = array('name' => 'ModPlus',
'version' => STATUSNET_VERSION,
'author' => 'Brion Vibber',
'homepage' => 'http://status.net/wiki/Plugin:ModPlus',
'rawdescription' =>
_m('UI extensions for profile moderation actions.'));
return true;
}
/**
* Load JS at runtime if we're logged in.
*
* @param Action $action
* @return boolean hook result
*/
function onEndShowScripts($action)
{
$user = common_current_user();
if ($user) {
$action->script('plugins/ModPlus/modplus.js');
}
return true;
}
function onEndShowStatusNetStyles($action) {
$action->cssLink('plugins/ModPlus/modplus.css');
return true;
}
/**
* Autoloader
*
* Loads our classes if they're requested.
*
* @param string $cls Class requested
*
* @return boolean hook return
*/
function onAutoload($cls)
{
switch ($cls)
{
case 'RemoteprofileAction':
case 'RemoteProfileAction':
require_once dirname(__FILE__) . '/remoteprofileaction.php';
return false;
default:
return true;
}
}
/**
* Add OpenID-related paths to the router table
*
* Hook for RouterInitialized event.
*
* @param Net_URL_Mapper $m URL mapper
*
* @return boolean hook return
*/
function onStartInitializeRouter($m)
{
$m->connect('user/remote/:id',
array('action' => 'remoteprofile'),
array('id' => '[\d]+'));
return true;
}
function onStartShowNoticeItem($item)
{
$profile = $item->profile;
$isRemote = !(User::staticGet('id', $profile->id));
if ($isRemote) {
$target = common_local_url('remoteprofile', array('id' => $profile->id));
$label = _m('Remote profile options...');
$item->out->elementStart('div', 'remote-profile-options');
$item->out->element('a', array('href' => $target), $label);
$item->out->elementEnd('div');
}
}
}

View File

@ -0,0 +1,23 @@
.remote-profile-options {
position: absolute;
z-index: 999;
background: url(../../theme/base/images/icons/twotone/green/admin.gif) no-repeat 8px 8px white;
border: solid 1px #c0c0c0;
margin-top: 56px;
padding: 6px 16px;
padding-left: 32px;
-moz-border-radius: 8px;
-webkit-border-radius: 8px;
-msie-border-radius: 8px;
border-radius: 8px;
box-shadow:3px 3px 7px rgba(194, 194, 194, 0.3);
-moz-box-shadow:3px 3px 7px rgba(194, 194, 194, 0.3);
-webkit-box-shadow:3px 3px 7px rgba(194, 194, 194, 0.3);
display: none;
}

View File

@ -0,0 +1,106 @@
<?php
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
class RemoteProfileAction extends ShowstreamAction
{
function prepare($args)
{
OwnerDesignAction::prepare($args); // skip the ProfileAction code and replace it...
$id = $this->arg('id');
$this->user = false;
$this->profile = Profile::staticGet('id', $id);
if (!$this->profile) {
$this->serverError(_('User has no profile.'));
return false;
}
$user = User::staticGet('id', $this->profile->id);
if ($user) {
// This is a local user -- send to their regular profile.
$url = common_local_url('showstream', array('nickname' => $user->nickname));
common_redirect($url);
return false;
}
$this->tag = $this->trimmed('tag');
$this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
common_set_returnto($this->selfUrl());
return true;
}
function handle($args)
{
// skip yadis thingy
$this->showPage();
}
function title()
{
// maybe fixed in 0.9.x
if (!empty($this->profile->fullname)) {
$base = $this->profile->fullname . ' (' . $this->profile->nickname . ') ';
} else {
$base = $this->profile->nickname;
}
$host = parse_url($this->profile->profileurl, PHP_URL_HOST);
return sprintf(_m('%s on %s'), $base, $host);
}
/**
* Instead of showing notices, link to the original offsite profile.
*/
function showNotices()
{
$url = $this->profile->profileurl;
$host = parse_url($url, PHP_URL_HOST);
$markdown = sprintf(
_m('This remote profile is registered on another site; see [%s\'s original profile page on %s](%s).'),
$this->profile->nickname,
$host,
$url);
$html = common_markup_to_html($markdown);
$this->raw($html);
if ($this->profile->hasRole(Profile_role::SILENCED)) {
$markdown = _m('Site moderators have silenced this profile, which prevents delivery of new messages to any users on this site.');
$this->raw(common_markup_to_html($markdown));
}
}
function getFeeds()
{
// none
}
/**
* Don't do various extra stuff, and also trim some things to avoid crawlers.
*/
function extraHead()
{
$this->element('meta', array('name' => 'robots',
'content' => 'noindex,nofollow'));
}
function showLocalNav()
{
$nav = new PublicGroupNav($this);
$nav->show();
}
function showSections()
{
ProfileAction::showSections();
// skip tag cloud
}
function showStatistics()
{
// skip
}
}