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

This commit is contained in:
Zach Copley 2011-03-16 14:53:20 -07:00
commit 2d88e6d07e
4 changed files with 179 additions and 27 deletions

View File

@ -297,7 +297,7 @@ class EventPlugin extends MicroappPlugin
}
// @fixme we have to start the name/avatar and open this div
$out->elementStart('div', array('class' => 'event-info entry-content')); // EVENT-INFO.ENTRY-CONTENT IN
$out->elementStart('div', array('class' => 'event-info')); // EVENT-INFO.ENTRY-CONTENT IN
$profile = $notice->getProfile();
$avatar = $profile->getAvatar(AVATAR_MINI_SIZE);
@ -324,7 +324,11 @@ class EventPlugin extends MicroappPlugin
function showRSVPNotice($notice, $out)
{
$out->raw($notice->rendered);
$rsvp = RSVP::fromNotice($notice);
$out->elementStart('div', 'rsvp');
$out->raw($rsvp->asHTML());
$out->elementEnd('div');
return;
}
@ -336,7 +340,7 @@ class EventPlugin extends MicroappPlugin
assert(!empty($event));
assert(!empty($profile));
$out->elementStart('div', 'vevent'); // VEVENT IN
$out->elementStart('div', 'vevent event'); // VEVENT IN
$out->elementStart('h3'); // VEVENT/H3 IN
@ -351,39 +355,63 @@ class EventPlugin extends MicroappPlugin
$out->elementEnd('h3'); // VEVENT/H3 OUT
$startDate = strftime("%x", $event->start_time);
$startTime = strftime("%R", $event->start_time);
$endDate = strftime("%x", $event->end_time);
$endTime = strftime("%R", $event->end_time);
// FIXME: better dates
$out->elementStart('div', 'event-times'); // VEVENT/EVENT-TIMES IN
$out->element('strong', null, _('Time:'));
$out->element('abbr', array('class' => 'dtstart',
'title' => common_date_iso8601($event->start_time)),
common_exact_date($event->start_time));
'title' => common_date_iso8601()),
$startDate . ' ' . $startTime);
$out->text(' - ');
if ($startDate == $endDate) {
$out->element('span', array('class' => 'dtend',
'title' => common_date_iso8601($event->end_time)),
common_exact_date($event->end_time));
$out->elementEnd('div'); // VEVENT/EVENT-TIMES OUT
if (!empty($event->description)) {
$out->element('div', 'description', $event->description);
$endTime);
} else {
$out->element('span', array('class' => 'dtend',
'title' => common_date_iso8601($event->end_time)),
$endDate . ' ' . $endTime);
}
$out->elementEnd('div'); // VEVENT/EVENT-TIMES OUT
if (!empty($event->location)) {
$out->element('div', 'location', $event->location);
$out->elementStart('div', 'event-location');
$out->element('strong', null, _('Location: '));
$out->element('span', 'location', $event->location);
$out->elementEnd('div');
}
if (!empty($event->description)) {
$out->elementStart('div', 'event-description');
$out->element('strong', null, _('Description: '));
$out->element('span', 'description', $event->description);
$out->elementEnd('div');
}
$rsvps = $event->getRSVPs();
$out->element('div', 'event-rsvps',
$out->elementStart('div', 'event-rsvps');
$out->element('strong', null, _('Attending: '));
$out->element('span', 'event-rsvps',
sprintf(_('Yes: %d No: %d Maybe: %d'),
count($rsvps[RSVP::POSITIVE]),
count($rsvps[RSVP::NEGATIVE]),
count($rsvps[RSVP::POSSIBLE])));
$out->elementEnd('div');
$user = common_current_user();
if (!empty($user)) {
$rsvp = $event->getRSVP($user->getProfile());
common_log(LOG_DEBUG, "RSVP is: " . ($rsvp ? $rsvp->id : 'none'));
if (empty($rsvp)) {
$form = new RSVPForm($event, $out);
@ -440,4 +468,10 @@ class EventPlugin extends MicroappPlugin
{
$action->inlineScript('$(document).ready(function() { $("#startdate").datepicker(); $("#enddate").datepicker(); });');
}
function onEndShowStyles($action)
{
$action->cssLink($this->path('event.css'));
return true;
}
}

View File

@ -161,6 +161,8 @@ class RSVP extends Managed_DataObject
$rsvp->event_id = $event->id;
$rsvp->response = self::codeFor($verb);
common_debug("Got value {$rsvp->response} for verb {$verb}");
if (array_key_exists('created', $options)) {
$rsvp->created = $options['created'];
} else {
@ -178,12 +180,9 @@ class RSVP extends Managed_DataObject
// XXX: come up with something sexier
$content = sprintf(_('RSVPed %s for an event.'),
($verb == RSVP::POSITIVE) ? _('positively') :
($verb == RSVP::NEGATIVE) ? _('negatively') :
_('possibly'));
$content = $rsvp->asString();
$rendered = $content;
$rendered = $rsvp->asHTML();
$options = array_merge(array('object_type' => $verb),
$options);
@ -209,16 +208,36 @@ class RSVP extends Managed_DataObject
function codeFor($verb)
{
return ($verb == RSVP::POSITIVE) ? 'Y' :
($verb == RSVP::NEGATIVE) ? 'N' :
($verb == RSVP::POSSIBLE) ? '?' : null;
switch ($verb) {
case RSVP::POSITIVE:
return 'Y';
break;
case RSVP::NEGATIVE:
return 'N';
break;
case RSVP::POSSIBLE:
return '?';
break;
default:
throw new Exception("Unknown verb {$verb}");
}
}
static function verbFor($code)
{
return ($code == 'Y') ? RSVP::POSITIVE :
($code == 'N') ? RSVP::NEGATIVE :
($code == '?') ? RSVP::POSSIBLE : null;
switch ($code) {
case 'Y':
return RSVP::POSITIVE;
break;
case 'N':
return RSVP::NEGATIVE;
break;
case '?':
return RSVP::POSSIBLE;
break;
default:
throw new Exception("Unknown code {$code}");
}
}
function getNotice()
@ -254,4 +273,90 @@ class RSVP extends Managed_DataObject
return $rsvps;
}
function getProfile()
{
$profile = Profile::staticGet('id', $this->profile_id);
if (empty($profile)) {
throw new Exception("No profile with ID {$this->profile_id}");
}
return $profile;
}
function getEvent()
{
$event = Happening::staticGet('id', $this->event_id);
if (empty($event)) {
throw new Exception("No event with ID {$this->event_id}");
}
return $event;
}
function asHTML()
{
return self::toHTML($this->getProfile(),
$this->getEvent(),
$this->response);
}
function asString()
{
return self::toString($this->getProfile(),
$this->getEvent(),
$this->response);
}
static function toHTML($profile, $event, $response)
{
$fmt = null;
$notice = $event->getNotice();
switch ($response) {
case 'Y':
$fmt = _("<span class='automatic event-rsvp'><a href='%1s'>%2s</a> is attending <a href='%3s'>%4s</a>.</span>");
break;
case 'N':
$fmt = _("<span class='automatic event-rsvp'><a href='%1s'>%2s</a> is not attending <a href='%3s'>%4s</a>.</span>");
break;
case '?':
$fmt = _("<span class='automatic event-rsvp'><a href='%1s'>%2s</a> might attend <a href='%3s'>%4s</a>.</span>");
break;
default:
throw new Exception("Unknown response code {$response}");
break;
}
return sprintf($fmt,
htmlspecialchars($profile->profileurl),
htmlspecialchars($profile->getBestName()),
htmlspecialchars($notice->bestUrl()),
htmlspecialchars($event->title));
}
static function toString($profile, $event, $response)
{
$fmt = null;
$notice = $event->getNotice();
switch ($response) {
case 'Y':
$fmt = _("%1s is attending %2s.");
break;
case 'N':
$fmt = _("%1s is not attending %2s.");
break;
case '?':
$fmt = _("%1s might attend %2s.>");
break;
default:
throw new Exception("Unknown response code {$response}");
break;
}
return sprintf($fmt,
$profile->getBestName(),
$event->title);
}
}

9
plugins/Event/event.css Normal file
View File

@ -0,0 +1,9 @@
.event-tags li { display: inline; }
.event-mentions li { display: inline; }
.event-avatar { float: left; }
.event-notice-count { float: right; }
.event-info { float: left; }
.event-title { margin-left: 0px; }
#content .event .entry-title { margin-left: 0px; }
#content .event .entry-content { margin-left: 0px; }

View File

@ -451,6 +451,10 @@ address .poweredby {
overflow:visible;
}
.notice .automatic {
font-style:italic;
}
#showstream h1 {
display:none;
}