From: Evan Prodromou Date: Wed, 9 Mar 2011 15:07:30 +0000 (-0500) Subject: add url to events X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=f00f5f20b8b373fc8631071e8be6522a937a7690;p=quix0rs-gnu-social.git add url to events --- diff --git a/plugins/Event/EventPlugin.php b/plugins/Event/EventPlugin.php index f33de09d78..896ecaf5c8 100644 --- a/plugins/Event/EventPlugin.php +++ b/plugins/Event/EventPlugin.php @@ -300,8 +300,69 @@ class EventPlugin extends MicroappPlugin function showEventNotice($notice, $out) { - $out->raw($notice->rendered); - return; + $profile = $notice->getProfile(); + $event = Happening::fromNotice($notice); + + assert(!empty($event)); + assert(!empty($profile)); + + $out->elementStart('div', 'vevent'); + + $out->elementStart('h3'); + + if (!empty($event->url)) { + $out->element('a', + array('href' => $att->url, + 'class' => 'event-title entry-title summary'), + $event->title); + } else { + $out->text($event->title); + } + + $out->elementEnd('h3'); + + $out->elementStart('div', 'event-times'); + $out->element('abbr', array('class' => 'dtstart', + 'title' => common_date_iso8601($event->start_time)), + common_exact_date($event->start_time)); + $out->text(' - '); + $out->element('span', array('class' => 'dtend', + 'title' => common_date_iso8601($event->end_time)), + common_exact_date($event->end_time)); + $out->elementEnd('div'); + + if (!empty($event->description)) { + $out->element('div', 'description', $event->description); + } + + if (!empty($event->location)) { + $out->element('div', 'location', $event->location); + } + + $out->elementStart('div', array('class' => 'event-info entry-content')); + + $avatar = $profile->getAvatar(AVATAR_MINI_SIZE); + + $out->element('img', + array('src' => ($avatar) ? + $avatar->displayUrl() : + Avatar::defaultImage(AVATAR_MINI_SIZE), + 'class' => 'avatar photo bookmark-avatar', + 'width' => AVATAR_MINI_SIZE, + 'height' => AVATAR_MINI_SIZE, + 'alt' => $profile->getBestName())); + + $out->raw(' '); // avoid   for AJAX XML compatibility + + $out->elementStart('span', 'vcard author'); // hack for belongsOnTimeline; JS needs to be able to find the author + $out->element('a', + array('class' => 'url', + 'href' => $profile->profileurl, + 'title' => $profile->getBestName()), + $profile->nickname); + $out->elementEnd('span'); + + $out->elementEnd('div'); } /** diff --git a/plugins/Event/Happening.php b/plugins/Event/Happening.php index 5ede26706b..503cd8af14 100644 --- a/plugins/Event/Happening.php +++ b/plugins/Event/Happening.php @@ -60,6 +60,7 @@ class Happening extends Managed_DataObject public $end_time; // datetime public $title; // varchar(255) public $location; // varchar(255) + public $url; // varchar(255) public $description; // text public $created; // datetime @@ -92,15 +93,16 @@ class Happening extends Managed_DataObject 'uri' => array('type' => 'varchar', 'length' => 255, 'not null' => true), - 'profile_id' => array('type' => 'int'), - 'start_time' => array('type' => 'datetime'), - 'end_time' => array('type' => 'datetime'), + 'profile_id' => array('type' => 'int', 'not null' => true), + 'start_time' => array('type' => 'datetime', 'not null' => true), + 'end_time' => array('type' => 'datetime', 'not null' => true), 'title' => array('type' => 'varchar', 'length' => 255, 'not null' => true), 'location' => array('type' => 'varchar', - 'length' => 255, - 'not null' => true), + 'length' => 255), + 'url' => array('type' => 'varchar', + 'length' => 255), 'description' => array('type' => 'text'), 'created' => array('type' => 'datetime', 'not null' => true), @@ -109,10 +111,13 @@ class Happening extends Managed_DataObject 'unique keys' => array( 'happening_uri_key' => array('uri'), ), + 'foreign keys' => array('happening_profile_id__key' => array('profile', array('profile_id' => 'id'))), + 'indexes' => array('happening_created_idx' => array('created'), + 'happening_start_end_idx' => array('start_time', 'end_time')), ); } - function saveNew($profile, $start_time, $end_time, $title, $location, $description, $options=array()) + function saveNew($profile, $start_time, $end_time, $title, $location, $description, $url, $options=array()) { if (array_key_exists('uri', $options)) { $other = Happening::staticGet('uri', $options['uri']); @@ -130,6 +135,7 @@ class Happening extends Managed_DataObject $ev->title = $title; $ev->location = $location; $ev->description = $description; + $ev->url = $url; if (array_key_exists('created', $options)) { $ev->created = $options['created']; @@ -177,6 +183,10 @@ class Happening extends Managed_DataObject $options['uri'] = $ev->uri; } + if (!empty($url)) { + $options['urls'] = array($url); + } + $saved = Notice::saveNew($profile->id, $content, array_key_exists('source', $options) ? @@ -191,7 +201,7 @@ class Happening extends Managed_DataObject return Notice::staticGet('uri', $this->uri); } - static function fromNotice() + static function fromNotice($notice) { return Happening::staticGet('uri', $notice->uri); } diff --git a/plugins/Event/RSVP.php b/plugins/Event/RSVP.php index 69cae4b7dc..851978e819 100644 --- a/plugins/Event/RSVP.php +++ b/plugins/Event/RSVP.php @@ -192,7 +192,7 @@ class RSVP extends Managed_DataObject return Notice::staticGet('uri', $this->uri); } - static function fromNotice() + static function fromNotice($notice) { return RSVP::staticGet('uri', $notice->uri); } diff --git a/plugins/Event/eventform.php b/plugins/Event/eventform.php index 8d108020a6..e6bc1e7016 100644 --- a/plugins/Event/eventform.php +++ b/plugins/Event/eventform.php @@ -133,6 +133,13 @@ class EventForm extends Form _('Event location')); $this->unli(); + $this->li(); + $this->out->input('url', + _('URL'), + null, + _('URL for more information')); + $this->unli(); + $this->li(); $this->out->input('description', _('Description'), diff --git a/plugins/Event/newevent.php b/plugins/Event/newevent.php index 365e9c1434..7c0fd0177f 100644 --- a/plugins/Event/newevent.php +++ b/plugins/Event/newevent.php @@ -91,6 +91,7 @@ class NeweventAction extends Action $this->title = $this->trimmed('title'); $this->location = $this->trimmed('location'); + $this->url = $this->trimmed('url'); $this->description = $this->trimmed('description'); $start_date = $this->trimmed('start_date'); @@ -146,12 +147,15 @@ class NeweventAction extends Action throw new ClientException(_('Event must have an end time.')); } - $saved = Happening::saveNew($this->user->getProfile(), + $profile = $this->user->getProfile(); + + $saved = Happening::saveNew($profile, $this->start_time, $this->end_time, $this->title, $this->location, - $this->description); + $this->description, + $this->url); } catch (ClientException $ce) { $this->error = $ce->getMessage();