예제 #1
0
 /**
  * Show the widget
  *
  * @return void
  */
 function show()
 {
     $this->out->elementStart('li', array('class' => 'h-entry notice', 'id' => 'message-' . $this->message->id));
     $profile = $this->getMessageProfile();
     $this->out->elementStart('a', array('href' => $profile->profileurl, 'class' => 'p-author'));
     $avatarUrl = $profile->avatarUrl(AVATAR_STREAM_SIZE);
     $this->out->element('img', array('src' => $avatarUrl, 'class' => 'avatar u-photo', 'width' => AVATAR_STREAM_SIZE, 'height' => AVATAR_STREAM_SIZE, 'alt' => $profile->getBestName()));
     $this->out->element('span', array('class' => 'nickname fn'), $profile->getNickname());
     $this->out->elementEnd('a');
     // FIXME: URL, image, video, audio
     $this->out->elementStart('div', array('class' => 'e-content'));
     $this->out->raw($this->message->rendered);
     $this->out->elementEnd('div');
     $messageurl = common_local_url('showmessage', array('message' => $this->message->id));
     // XXX: we need to figure this out better. Is this right?
     if (strcmp($this->message->uri, $messageurl) != 0 && preg_match('/^http/', $this->message->uri)) {
         $messageurl = $this->message->uri;
     }
     $this->out->elementStart('div', 'entry-metadata');
     $this->out->elementStart('a', array('rel' => 'bookmark', 'class' => 'timestamp', 'href' => $messageurl));
     $dt = common_date_iso8601($this->message->created);
     $this->out->element('time', array('class' => 'dt-published', 'datetime' => common_date_iso8601($this->message->created), 'title' => common_exact_date($this->message->created)), common_date_string($this->message->created));
     $this->out->elementEnd('a');
     if ($this->message->source) {
         $this->out->elementStart('span', 'source');
         // FIXME: bad i18n. Device should be a parameter (from %s).
         // TRANS: Followed by notice source (usually the client used to send the notice).
         $this->out->text(_('from'));
         $this->showSource($this->message->source);
         $this->out->elementEnd('span');
     }
     $this->out->elementEnd('div');
     $this->out->elementEnd('li');
 }
예제 #2
0
 function run()
 {
     if (!$this->start()) {
         return false;
     }
     $this->log(LOG_INFO, 'checking for queued notices');
     $transport = $this->transport();
     do {
         $qi = Queue_item::top($transport);
         if ($qi) {
             $this->log(LOG_INFO, 'Got item enqueued ' . common_exact_date($qi->created));
             $notice = Notice::staticGet($qi->notice_id);
             if ($notice) {
                 $this->log(LOG_INFO, 'broadcasting notice ID = ' . $notice->id);
                 # XXX: what to do if broadcast fails?
                 $result = $this->handle_notice($notice);
                 if (!$result) {
                     $this->log(LOG_WARNING, 'Failed broadcast for notice ID = ' . $notice->id);
                     $orig = $qi;
                     $qi->claimed = null;
                     $qi->update($orig);
                     $this->log(LOG_WARNING, 'Abandoned claim for notice ID = ' . $notice->id);
                     continue;
                 }
                 $this->log(LOG_INFO, 'finished broadcasting notice ID = ' . $notice->id);
                 $notice->free();
                 unset($notice);
                 $notice = null;
             } else {
                 $this->log(LOG_WARNING, 'queue item for notice that does not exist');
             }
             $qi->delete();
             $qi->free();
             unset($qi);
             $this->idle(0);
         } else {
             $this->clear_old_claims();
             $this->idle(5);
         }
     } while (true);
     if (!$this->finish()) {
         return false;
     }
     return true;
 }
 /**
  * Show the item
  *
  * @return void
  */
 function show()
 {
     $group = $this->gm->getGroup();
     $sender = $this->gm->getSender();
     $this->out->elementStart('li', array('class' => 'h-entry notice message group-message', 'id' => 'message-' . $this->gm->id));
     $this->out->elementStart('div', 'entry-title');
     $this->out->elementStart('span', 'vcard author');
     $this->out->elementStart('a', array('href' => $sender->profileurl, 'class' => 'url'));
     $avatarUrl = $sender->avatarUrl(AVATAR_STREAM_SIZE);
     $this->out->element('img', array('src' => $avatarUrl, 'width' => AVATAR_STREAM_SIZE, 'height' => AVATAR_STREAM_SIZE, 'class' => 'photo avatar', 'alt' => $sender->getBestName()));
     $this->out->element('span', array('class' => 'nickname fn'), $sender->nickname);
     $this->out->elementEnd('a');
     $this->out->elementEnd('span');
     $this->out->elementStart('p', array('class' => 'e-content message-content'));
     $this->out->raw($this->gm->rendered);
     $this->out->elementEnd('p');
     $this->out->elementEnd('div');
     $this->out->elementStart('div', 'e-content');
     $this->out->elementStart('a', array('rel' => 'bookmark', 'class' => 'timestamp', 'href' => $this->gm->url));
     $this->out->element('time', array('class' => 'dt-published', 'datetime' => common_date_iso8601($this->gm->created), 'title' => common_exact_date($this->gm->created)), common_date_string($this->gm->created));
     $this->out->elementEnd('a');
     $this->out->elementEnd('div');
     $this->out->elementEnd('li');
 }
예제 #4
0
 public function getTitle()
 {
     $title = null;
     if (Event::handle('GetNoticeTitle', array($this, &$title))) {
         // TRANS: Title of a notice posted without a title value.
         // TRANS: %1$s is a user name, %2$s is the notice creation date/time.
         $title = sprintf(_('%1$s\'s status on %2$s'), $this->getProfile()->getFancyName(), common_exact_date($this->created));
     }
     return $title;
 }
예제 #5
0
 /**
  * Title of the page
  *
  * @return string title of the page
  */
 function title()
 {
     if (!empty($this->profile->fullname)) {
         $base = $this->profile->fullname . ' (' . $this->profile->nickname . ')';
     } else {
         $base = $this->profile->nickname;
     }
     return sprintf(_('%1$s\'s status on %2$s'), $base, common_exact_date($this->notice->created));
 }
예제 #6
0
 /**
  * Title of the page
  */
 function title()
 {
     // TRANS: Title for private group message.
     // TRANS: %1$s is the sender name, %2$s is the group name, %3$s is a timestamp.
     return sprintf(_m('Message from %1$s to group %2$s on %3$s'), $this->sender->nickname, $this->group->nickname, common_exact_date($this->gm->created));
 }
예제 #7
0
파일: mail.php 프로젝트: Br3nda/laconica
/**
 * notify a user that one of their notices has been chosen as a 'fave'
 *
 * Doesn't check that the user has an email address nor if they
 * want to receive notification of faves. Maybe this happens higher
 * up the stack...?
 *
 * @param User   $other  The user whose notice was faved
 * @param User   $user   The user who faved the notice
 * @param Notice $notice The notice that was faved
 *
 * @return void
 */
function mail_notify_fave($other, $user, $notice)
{
    $profile = $user->getProfile();
    $bestname = $profile->getBestName();
    common_init_locale($other->language);
    $subject = sprintf(_('%s added your notice as a favorite'), $bestname);
    $body = sprintf(_("%1\$s just added your notice from %2\$s" . " as one of their favorites.\n\n" . "In case you forgot, you can see the text" . " of your notice here:\n\n" . "%3\$s\n\n" . "You can see the list of %1\$s's favorites here:\n\n" . "%4\$s\n\n" . "Faithfully yours,\n" . "%5\$s\n"), $bestname, common_exact_date($notice->created), common_local_url('shownotice', array('notice' => $notice->id)), common_local_url('showfavorites', array('nickname' => $user->nickname)), common_config('site', 'name'));
    common_init_locale();
    mail_to_user($other, $subject, $body);
}
예제 #8
0
/**
 * Notify a user that one of their notices has been chosen as a 'fave'
 *
 * @param User    $rcpt   The user whose notice was faved
 * @param Profile $sender The user who faved the notice
 * @param Notice  $notice The notice that was faved
 *
 * @return void
 */
function mail_notify_fave(User $rcpt, Profile $sender, Notice $notice)
{
    if (!$rcpt->receivesEmailNotifications() || !$rcpt->getConfigPref('email', 'notify_fave')) {
        return;
    }
    // This test is actually "if the sender is sandboxed"
    if (!$sender->hasRight(Right::EMAILONFAVE)) {
        return;
    }
    if ($rcpt->hasBlocked($sender)) {
        // If the author has blocked us, don't spam them with a notification.
        return;
    }
    // We need the global mail.php for various mail related functions below.
    require_once INSTALLDIR . '/lib/mail.php';
    $bestname = $sender->getBestName();
    common_switch_locale($rcpt->language);
    // TRANS: Subject for favorite notification e-mail.
    // TRANS: %1$s is the adding user's long name, %2$s is the adding user's nickname.
    $subject = sprintf(_('%1$s (@%2$s) added your notice as a favorite'), $bestname, $sender->getNickname());
    // TRANS: Body for favorite notification e-mail.
    // TRANS: %1$s is the adding user's long name, $2$s is the date the notice was created,
    // TRANS: %3$s is a URL to the faved notice, %4$s is the faved notice text,
    // TRANS: %5$s is a URL to all faves of the adding user, %6$s is the StatusNet sitename,
    // TRANS: %7$s is the adding user's nickname.
    $body = sprintf(_("%1\$s (@%7\$s) just added your notice from %2\$s" . " as one of their favorites.\n\n" . "The URL of your notice is:\n\n" . "%3\$s\n\n" . "The text of your notice is:\n\n" . "%4\$s\n\n" . "You can see the list of %1\$s's favorites here:\n\n" . "%5\$s"), $bestname, common_exact_date($notice->created), common_local_url('shownotice', array('notice' => $notice->id)), $notice->content, common_local_url('showfavorites', array('nickname' => $sender->getNickname())), common_config('site', 'name'), $sender->getNickname()) . mail_footer_block();
    $headers = _mail_prepare_headers('fave', $rcpt->getNickname(), $sender->getNickname());
    common_switch_locale();
    mail_to_user($rcpt, $subject, $body, $headers);
}
예제 #9
0
 function trackback($url, $endpoint)
 {
     $profile = $this->notice->getProfile();
     $args = array('title' => sprintf(_('%1$s\'s status on %2$s'), $profile->nickname, common_exact_date($this->notice->created)), 'excerpt' => $this->notice->content, 'url' => $this->notice->uri, 'blog_name' => $profile->nickname);
     $fetcher = Auth_Yadis_Yadis::getHTTPFetcher();
     $result = $fetcher->post($endpoint, http_build_query($args), array('User-Agent: ' . $this->userAgent()));
     if ($result->status != '200') {
         common_log(LOG_WARNING, "Trackback error for '{$url}' ({$endpoint}): " . "{$result->body}");
     } else {
         common_log(LOG_INFO, "Trackback success for '{$url}' ({$endpoint}): " . "'{$result->body}'");
     }
 }
예제 #10
0
 function showItem($notice)
 {
     $profile = Profile::staticGet($notice->profile_id);
     $nurl = common_local_url('shownotice', array('notice' => $notice->id));
     $creator_uri = common_profile_uri($profile);
     $this->elementStart('item', array('rdf:about' => $notice->uri));
     $title = $profile->nickname . ': ' . common_xml_safe_str(trim($notice->content));
     $this->element('title', null, $title);
     $this->element('link', null, $nurl);
     $this->element('description', null, $profile->nickname . "'s status on " . common_exact_date($notice->created));
     $this->element('dc:date', null, common_date_w3dtf($notice->created));
     $this->element('dc:creator', null, $profile->fullname ? $profile->fullname : $profile->nickname);
     $this->element('sioc:has_creator', array('rdf:resource' => $creator_uri));
     $this->element('laconica:postIcon', array('rdf:resource' => $profile->avatarUrl()));
     $this->element('cc:licence', array('rdf:resource' => common_config('license', 'url')));
     $this->elementEnd('item');
     $this->creators[$creator_uri] = $profile;
 }
예제 #11
0
 /**
  * Title of the page
  *
  * @return string title of the page
  */
 function title()
 {
     $base = $this->profile->getFancyName();
     return sprintf(_('%1$s\'s status on %2$s'), $base, common_exact_date($this->notice->created));
 }
예제 #12
0
 /**
  * Title of the page
  */
 function title()
 {
     return sprintf(_('Message from %1$s to group %2$s on %3$s'), $this->sender->nickname, $this->group->nickname, common_exact_date($this->gm->created));
 }
예제 #13
0
 /**
  * show the link to the main page for the notice
  *
  * Displays a local link to the rendered notice, with "relative" time.
  *
  * @return void
  */
 function showNoticeLink()
 {
     $this->out->elementStart('a', array('rel' => 'bookmark', 'class' => 'timestamp', 'href' => Conversation::getUrlFromNotice($this->notice)));
     $this->out->element('time', array('class' => 'dt-published', 'datetime' => common_date_iso8601($this->notice->created), 'title' => common_exact_date($this->notice->created)), common_date_string($this->notice->created));
     $this->out->elementEnd('a');
 }
예제 #14
0
 /**
  * Title of the page
  *
  * @return string title of the page
  */
 function title()
 {
     return sprintf(_('%1$s\'s status on %2$s'), $this->profile->nickname, common_exact_date($this->notice->created));
 }
예제 #15
0
 function title()
 {
     if ($this->user->id == $this->message->from_profile) {
         $to = $this->message->getTo();
         return sprintf(_("Message to %1\$s on %2\$s"), $to->nickname, common_exact_date($this->message->created));
     } else {
         if ($this->user->id == $this->message->to_profile) {
             $from = $this->message->getFrom();
             return sprintf(_("Message from %1\$s on %2\$s"), $from->nickname, common_exact_date($this->message->created));
         }
     }
 }
예제 #16
0
/**
 * notify a user that one of their notices has been chosen as a 'fave'
 *
 * Doesn't check that the user has an email address nor if they
 * want to receive notification of faves. Maybe this happens higher
 * up the stack...?
 *
 * @param User   $other  The user whose notice was faved
 * @param User   $user   The user who faved the notice
 * @param Notice $notice The notice that was faved
 *
 * @return void
 */
function mail_notify_fave($other, $user, $notice)
{
    if (!$user->hasRight(Right::EMAILONFAVE)) {
        return;
    }
    $profile = $user->getProfile();
    if ($other->hasBlocked($profile)) {
        // If the author has blocked us, don't spam them with a notification.
        return;
    }
    $bestname = $profile->getBestName();
    common_switch_locale($other->language);
    // TRANS: Subject for favorite notification e-mail.
    // TRANS: %1$s is the adding user's long name, %2$s is the adding user's nickname.
    $subject = sprintf(_('%1$s (@%2$s) added your notice as a favorite'), $bestname, $user->nickname);
    // TRANS: Body for favorite notification e-mail.
    // TRANS: %1$s is the adding user's long name, $2$s is the date the notice was created,
    // TRANS: %3$s is a URL to the faved notice, %4$s is the faved notice text,
    // TRANS: %5$s is a URL to all faves of the adding user, %6$s is the StatusNet sitename,
    // TRANS: %7$s is the adding user's nickname.
    $body = sprintf(_("%1\$s (@%7\$s) just added your notice from %2\$s" . " as one of their favorites.\n\n" . "The URL of your notice is:\n\n" . "%3\$s\n\n" . "The text of your notice is:\n\n" . "%4\$s\n\n" . "You can see the list of %1\$s's favorites here:\n\n" . "%5\$s\n\n" . "Faithfully yours,\n" . "%6\$s\n"), $bestname, common_exact_date($notice->created), common_local_url('shownotice', array('notice' => $notice->id)), $notice->content, common_local_url('showfavorites', array('nickname' => $user->nickname)), common_config('site', 'name'), $user->nickname);
    $headers = _mail_prepare_headers('fave', $other->nickname, $user->nickname);
    common_switch_locale();
    mail_to_user($other, $subject, $body, $headers);
}
예제 #17
0
파일: oembed.php 프로젝트: Grasia/bolotweet
 function handle($args)
 {
     common_debug("in oembed api action");
     $url = $args['url'];
     if (substr(strtolower($url), 0, strlen(common_root_url())) == strtolower(common_root_url())) {
         $path = substr($url, strlen(common_root_url()));
         $r = Router::get();
         $proxy_args = $r->map($path);
         if (!$proxy_args) {
             // TRANS: Server error displayed in oEmbed action when path not found.
             // TRANS: %s is a path.
             $this->serverError(sprintf(_('"%s" not found.'), $path), 404);
         }
         $oembed = array();
         $oembed['version'] = '1.0';
         $oembed['provider_name'] = common_config('site', 'name');
         $oembed['provider_url'] = common_root_url();
         switch ($proxy_args['action']) {
             case 'shownotice':
                 $oembed['type'] = 'link';
                 $id = $proxy_args['notice'];
                 $notice = Notice::staticGet($id);
                 if (empty($notice)) {
                     // TRANS: Server error displayed in oEmbed action when notice not found.
                     // TRANS: %s is a notice.
                     $this->serverError(sprintf(_("Notice %s not found."), $id), 404);
                 }
                 $profile = $notice->getProfile();
                 if (empty($profile)) {
                     // TRANS: Server error displayed in oEmbed action when notice has not profile.
                     $this->serverError(_('Notice has no profile.'), 500);
                 }
                 $authorname = $profile->getFancyName();
                 // TRANS: oEmbed title. %1$s is the author name, %2$s is the creation date.
                 $oembed['title'] = sprintf(_('%1$s\'s status on %2$s'), $authorname, common_exact_date($notice->created));
                 $oembed['author_name'] = $authorname;
                 $oembed['author_url'] = $profile->profileurl;
                 $oembed['url'] = $notice->url ? $notice->url : $notice->uri;
                 $oembed['html'] = $notice->rendered;
                 break;
             case 'attachment':
                 $id = $proxy_args['attachment'];
                 $attachment = File::staticGet($id);
                 if (empty($attachment)) {
                     // TRANS: Server error displayed in oEmbed action when attachment not found.
                     // TRANS: %d is an attachment ID.
                     $this->serverError(sprintf(_('Attachment %s not found.'), $id), 404);
                 }
                 if (empty($attachment->filename) && ($file_oembed = File_oembed::staticGet('file_id', $attachment->id))) {
                     // Proxy the existing oembed information
                     $oembed['type'] = $file_oembed->type;
                     $oembed['provider'] = $file_oembed->provider;
                     $oembed['provider_url'] = $file_oembed->provider_url;
                     $oembed['width'] = $file_oembed->width;
                     $oembed['height'] = $file_oembed->height;
                     $oembed['html'] = $file_oembed->html;
                     $oembed['title'] = $file_oembed->title;
                     $oembed['author_name'] = $file_oembed->author_name;
                     $oembed['author_url'] = $file_oembed->author_url;
                     $oembed['url'] = $file_oembed->url;
                 } else {
                     if (substr($attachment->mimetype, 0, strlen('image/')) == 'image/') {
                         $oembed['type'] = 'photo';
                         if ($attachment->filename) {
                             $filepath = File::path($attachment->filename);
                             $gis = @getimagesize($filepath);
                             if ($gis) {
                                 $oembed['width'] = $gis[0];
                                 $oembed['height'] = $gis[1];
                             } else {
                                 // TODO Either throw an error or find a fallback?
                             }
                         }
                         $oembed['url'] = $attachment->url;
                         $thumb = $attachment->getThumbnail();
                         if ($thumb) {
                             $oembed['thumbnail_url'] = $thumb->url;
                             $oembed['thumbnail_width'] = $thumb->width;
                             $oembed['thumbnail_height'] = $thumb->height;
                         }
                     } else {
                         $oembed['type'] = 'link';
                         $oembed['url'] = common_local_url('attachment', array('attachment' => $attachment->id));
                     }
                 }
                 if ($attachment->title) {
                     $oembed['title'] = $attachment->title;
                 }
                 break;
             default:
                 // TRANS: Server error displayed in oEmbed request when a path is not supported.
                 // TRANS: %s is a path.
                 $this->serverError(sprintf(_('"%s" not supported for oembed requests.'), $path), 501);
         }
         switch ($args['format']) {
             case 'xml':
                 $this->init_document('xml');
                 $this->elementStart('oembed');
                 $this->element('version', null, $oembed['version']);
                 $this->element('type', null, $oembed['type']);
                 if ($oembed['provider_name']) {
                     $this->element('provider_name', null, $oembed['provider_name']);
                 }
                 if ($oembed['provider_url']) {
                     $this->element('provider_url', null, $oembed['provider_url']);
                 }
                 if ($oembed['title']) {
                     $this->element('title', null, $oembed['title']);
                 }
                 if ($oembed['author_name']) {
                     $this->element('author_name', null, $oembed['author_name']);
                 }
                 if ($oembed['author_url']) {
                     $this->element('author_url', null, $oembed['author_url']);
                 }
                 if ($oembed['url']) {
                     $this->element('url', null, $oembed['url']);
                 }
                 if ($oembed['html']) {
                     $this->element('html', null, $oembed['html']);
                 }
                 if ($oembed['width']) {
                     $this->element('width', null, $oembed['width']);
                 }
                 if ($oembed['height']) {
                     $this->element('height', null, $oembed['height']);
                 }
                 if ($oembed['cache_age']) {
                     $this->element('cache_age', null, $oembed['cache_age']);
                 }
                 if ($oembed['thumbnail_url']) {
                     $this->element('thumbnail_url', null, $oembed['thumbnail_url']);
                 }
                 if ($oembed['thumbnail_width']) {
                     $this->element('thumbnail_width', null, $oembed['thumbnail_width']);
                 }
                 if ($oembed['thumbnail_height']) {
                     $this->element('thumbnail_height', null, $oembed['thumbnail_height']);
                 }
                 $this->elementEnd('oembed');
                 $this->end_document('xml');
                 break;
             case 'json':
             case '':
                 $this->init_document('json');
                 print json_encode($oembed);
                 $this->end_document('json');
                 break;
             default:
                 // TRANS: Error message displaying attachments. %s is a raw MIME type (eg 'image/png')
                 $this->serverError(sprintf(_('Content type %s not supported.'), $apidata['content-type']), 501);
         }
     } else {
         // TRANS: Error message displaying attachments. %s is the site's base URL.
         $this->serverError(sprintf(_('Only %s URLs over plain HTTP please.'), common_root_url()), 404);
     }
 }
예제 #18
0
 static function saveNew($profile, $start_time, $end_time, $title, $location, $description, $url, $options = array())
 {
     if (array_key_exists('uri', $options)) {
         $other = Happening::getKV('uri', $options['uri']);
         if (!empty($other)) {
             // TRANS: Client exception thrown when trying to create an event that already exists.
             throw new ClientException(_m('Event already exists.'));
         }
     }
     $ev = new Happening();
     $ev->id = UUID::gen();
     $ev->profile_id = $profile->id;
     $ev->start_time = common_sql_date($start_time);
     $ev->end_time = common_sql_date($end_time);
     $ev->title = $title;
     $ev->location = $location;
     $ev->description = $description;
     $ev->url = $url;
     if (array_key_exists('created', $options)) {
         $ev->created = $options['created'];
     } else {
         $ev->created = common_sql_now();
     }
     if (array_key_exists('uri', $options)) {
         $ev->uri = $options['uri'];
     } else {
         $ev->uri = common_local_url('showevent', array('id' => $ev->id));
     }
     $ev->insert();
     // XXX: does this get truncated?
     // TRANS: Event description. %1$s is a title, %2$s is start time, %3$s is end time,
     // TRANS: %4$s is location, %5$s is a description.
     $content = sprintf(_m('"%1$s" %2$s - %3$s (%4$s): %5$s'), $title, common_exact_date($ev->start_time), common_exact_date($ev->end_time), $location, $description);
     // TRANS: Rendered microformats2 tagged event description.
     // TRANS: %1$s is a title, %2$s is start time, %3$s is start time,
     // TRANS: %4$s is end time, %5$s is end time, %6$s is location, %7$s is description.
     // TRANS: Class names should not be translated.
     $rendered = sprintf(_m('<div class="h-event">' . '<p class="p-name p-summary">%1$s</p> ' . '<time class="dt-start" datetime="%2$s">%3$s</time> - ' . '<time class="dt-end" datetime="%4$s">%5$s</time> ' . '(<span class="p-location">%6$s</span>): ' . '<div class="p-description">%7$s</div> ' . '</div>'), htmlspecialchars($title), htmlspecialchars(common_date_iso8601($ev->start_time)), htmlspecialchars(common_exact_date($ev->start_time)), htmlspecialchars(common_date_iso8601($ev->end_time)), htmlspecialchars(common_exact_date($ev->end_time)), htmlspecialchars($location), htmlspecialchars($description));
     $options = array_merge(array('object_type' => Happening::OBJECT_TYPE), $options);
     if (!array_key_exists('uri', $options)) {
         $options['uri'] = $ev->uri;
     }
     if (!empty($url)) {
         $options['urls'] = array($url);
     }
     $saved = Notice::saveNew($profile->id, $content, array_key_exists('source', $options) ? $options['source'] : 'web', $options);
     return $saved;
 }
예제 #19
0
function common_date_string($dt)
{
    // XXX: do some sexy date formatting
    // return date(DATE_RFC822, $dt);
    $t = strtotime($dt);
    $now = time();
    $diff = $now - $t;
    if ($now < $t) {
        // that shouldn't happen!
        return common_exact_date($dt);
    } else {
        if ($diff < 60) {
            // TRANS: Used in notices to indicate when the notice was made compared to now.
            return _('a few seconds ago');
        } else {
            if ($diff < 92) {
                // TRANS: Used in notices to indicate when the notice was made compared to now.
                return _('about a minute ago');
            } else {
                if ($diff < 3300) {
                    $minutes = round($diff / 60);
                    // TRANS: Used in notices to indicate when the notice was made compared to now.
                    return sprintf(_m('about one minute ago', 'about %d minutes ago', $minutes), $minutes);
                } else {
                    if ($diff < 5400) {
                        // TRANS: Used in notices to indicate when the notice was made compared to now.
                        return _('about an hour ago');
                    } else {
                        if ($diff < 22 * 3600) {
                            $hours = round($diff / 3600);
                            // TRANS: Used in notices to indicate when the notice was made compared to now.
                            return sprintf(_m('about one hour ago', 'about %d hours ago', $hours), $hours);
                        } else {
                            if ($diff < 37 * 3600) {
                                // TRANS: Used in notices to indicate when the notice was made compared to now.
                                return _('about a day ago');
                            } else {
                                if ($diff < 24 * 24 * 3600) {
                                    $days = round($diff / (24 * 3600));
                                    // TRANS: Used in notices to indicate when the notice was made compared to now.
                                    return sprintf(_m('about one day ago', 'about %d days ago', $days), $days);
                                } else {
                                    if ($diff < 46 * 24 * 3600) {
                                        // TRANS: Used in notices to indicate when the notice was made compared to now.
                                        return _('about a month ago');
                                    } else {
                                        if ($diff < 330 * 24 * 3600) {
                                            $months = round($diff / (30 * 24 * 3600));
                                            // TRANS: Used in notices to indicate when the notice was made compared to now.
                                            return sprintf(_m('about one month ago', 'about %d months ago', $months), $months);
                                        } else {
                                            if ($diff < 480 * 24 * 3600) {
                                                // TRANS: Used in notices to indicate when the notice was made compared to now.
                                                return _('about a year ago');
                                            } else {
                                                return common_exact_date($dt);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
예제 #20
0
 function title()
 {
     if ($this->user->id == $this->message->from_profile) {
         $to = $this->message->getTo();
         // @todo FIXME: Might be nice if the timestamp could be localised.
         // TRANS: Page title for single direct message display when viewing user is the sender.
         // TRANS: %1$s is the addressed user's nickname, $2$s is a timestamp.
         return sprintf(_('Message to %1$s on %2$s'), $to->nickname, common_exact_date($this->message->created));
     } else {
         if ($this->user->id == $this->message->to_profile) {
             $from = $this->message->getFrom();
             // @todo FIXME: Might be nice if the timestamp could be localised.
             // TRANS: Page title for single message display.
             // TRANS: %1$s is the sending user's nickname, $2$s is a timestamp.
             return sprintf(_('Message from %1$s on %2$s'), $from->nickname, common_exact_date($this->message->created));
         }
     }
 }
예제 #21
0
파일: util.php 프로젝트: himmelex/NTW
function common_date_string($dt)
{
    // XXX: do some sexy date formatting
    // return date(DATE_RFC822, $dt);
    $t = strtotime($dt);
    $now = time();
    $diff = $now - $t;
    if ($now < $t) {
        // that shouldn't happen!
        return common_exact_date($dt);
    } else {
        if ($diff < 60) {
            return _('a few seconds ago');
        } else {
            if ($diff < 92) {
                return _('about a minute ago');
            } else {
                if ($diff < 3300) {
                    return sprintf(_('about %d minutes ago'), round($diff / 60));
                } else {
                    if ($diff < 5400) {
                        return _('about an hour ago');
                    } else {
                        if ($diff < 22 * 3600) {
                            return sprintf(_('about %d hours ago'), round($diff / 3600));
                        } else {
                            if ($diff < 37 * 3600) {
                                return _('about a day ago');
                            } else {
                                if ($diff < 24 * 24 * 3600) {
                                    return sprintf(_('about %d days ago'), round($diff / (24 * 3600)));
                                } else {
                                    if ($diff < 46 * 24 * 3600) {
                                        return _('about a month ago');
                                    } else {
                                        if ($diff < 330 * 24 * 3600) {
                                            return sprintf(_('about %d months ago'), round($diff / (30 * 24 * 3600)));
                                        } else {
                                            if ($diff < 480 * 24 * 3600) {
                                                return _('about a year ago');
                                            } else {
                                                return common_exact_date($dt);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
예제 #22
0
파일: mail.php 프로젝트: Br3nda/StatusNet
/**
 * notify a user that one of their notices has been chosen as a 'fave'
 *
 * Doesn't check that the user has an email address nor if they
 * want to receive notification of faves. Maybe this happens higher
 * up the stack...?
 *
 * @param User   $other  The user whose notice was faved
 * @param User   $user   The user who faved the notice
 * @param Notice $notice The notice that was faved
 *
 * @return void
 */
function mail_notify_fave($other, $user, $notice)
{
    if (!$user->hasRight(Right::EMAILONFAVE)) {
        return;
    }
    $profile = $user->getProfile();
    $bestname = $profile->getBestName();
    common_switch_locale($other->language);
    // TRANS: Subject for favorite notification email
    $subject = sprintf(_('%s (@%s) added your notice as a favorite'), $bestname, $user->nickname);
    // TRANS: Body for favorite notification email
    $body = sprintf(_("%1\$s (@%7\$s) just added your notice from %2\$s" . " as one of their favorites.\n\n" . "The URL of your notice is:\n\n" . "%3\$s\n\n" . "The text of your notice is:\n\n" . "%4\$s\n\n" . "You can see the list of %1\$s's favorites here:\n\n" . "%5\$s\n\n" . "Faithfully yours,\n" . "%6\$s\n"), $bestname, common_exact_date($notice->created), common_local_url('shownotice', array('notice' => $notice->id)), $notice->content, common_local_url('showfavorites', array('nickname' => $user->nickname)), common_config('site', 'name'), $user->nickname);
    $headers = _mail_prepare_headers('fave', $other->nickname, $user->nickname);
    common_switch_locale();
    mail_to_user($other, $subject, $body, $headers);
}
 function showItem($notice)
 {
     $profile = Profile::staticGet($notice->profile_id);
     $nurl = common_local_url('shownotice', array('notice' => $notice->id));
     $creator_uri = common_profile_uri($profile);
     $this->elementStart('item', array('rdf:about' => $notice->uri, 'rdf:type' => 'http://rdfs.org/sioc/types#MicroblogPost'));
     $title = $profile->nickname . ': ' . common_xml_safe_str(trim($notice->content));
     $this->element('title', null, $title);
     $this->element('link', null, $nurl);
     $this->element('description', null, $profile->nickname . "'s status on " . common_exact_date($notice->created));
     if ($notice->rendered) {
         $this->element('content:encoded', null, common_xml_safe_str($notice->rendered));
     }
     $this->element('dc:date', null, common_date_w3dtf($notice->created));
     $this->element('dc:creator', null, $profile->fullname ? $profile->fullname : $profile->nickname);
     $this->element('foaf:maker', array('rdf:resource' => $creator_uri));
     $this->element('sioc:has_creator', array('rdf:resource' => $creator_uri . '#acct'));
     $location = $notice->getLocation();
     if ($location && isset($location->lat) && isset($location->lon)) {
         $location_uri = $location->getRdfURL();
         $attrs = array('geo:lat' => $location->lat, 'geo:long' => $location->lon);
         if (strlen($location_uri)) {
             $attrs['rdf:resource'] = $location_uri;
         }
         $this->element('statusnet:origin', $attrs);
     }
     $this->element('statusnet:postIcon', array('rdf:resource' => $profile->avatarUrl()));
     $this->element('cc:licence', array('rdf:resource' => common_config('license', 'url')));
     if ($notice->reply_to) {
         $replyurl = common_local_url('shownotice', array('notice' => $notice->reply_to));
         $this->element('sioc:reply_of', array('rdf:resource' => $replyurl));
     }
     if (!empty($notice->conversation)) {
         $conversationurl = common_local_url('conversation', array('id' => $notice->conversation));
         $this->element('sioc:has_discussion', array('rdf:resource' => $conversationurl));
     }
     $attachments = $notice->attachments();
     if ($attachments) {
         foreach ($attachments as $attachment) {
             $enclosure = $attachment->getEnclosure();
             if ($enclosure) {
                 $attribs = array('rdf:resource' => $enclosure->url);
                 if ($enclosure->title) {
                     $attribs['dc:title'] = $enclosure->title;
                 }
                 if ($enclosure->modified) {
                     $attribs['dc:date'] = common_date_w3dtf($enclosure->modified);
                 }
                 if ($enclosure->size) {
                     $attribs['enc:length'] = $enclosure->size;
                 }
                 if ($enclosure->mimetype) {
                     $attribs['enc:type'] = $enclosure->mimetype;
                 }
                 $this->element('enc:enclosure', $attribs);
             }
             $this->element('sioc:links_to', array('rdf:resource' => $attachment->url));
         }
     }
     $tag = new Notice_tag();
     $tag->notice_id = $notice->id;
     if ($tag->find()) {
         $entry['tags'] = array();
         while ($tag->fetch()) {
             $tagpage = common_local_url('tag', array('tag' => $tag->tag));
             if (in_array($tag, $this->tags_already_output)) {
                 $this->element('ctag:tagged', array('rdf:resource' => $tagpage . '#concept'));
                 continue;
             }
             $tagrss = common_local_url('tagrss', array('tag' => $tag->tag));
             $this->elementStart('ctag:tagged');
             $this->elementStart('ctag:Tag', array('rdf:about' => $tagpage . '#concept', 'ctag:label' => $tag->tag));
             $this->element('foaf:page', array('rdf:resource' => $tagpage));
             $this->element('rdfs:seeAlso', array('rdf:resource' => $tagrss));
             $this->elementEnd('ctag:Tag');
             $this->elementEnd('ctag:tagged');
             $this->tags_already_output[] = $tag->tag;
         }
     }
     $this->elementEnd('item');
     $this->creators[$creator_uri] = $profile;
 }
예제 #24
0
 /**
  * Title of the page
  *
  * @return string title of the page
  */
 function title()
 {
     $base = $this->profile->getFancyName();
     // TRANS: Title of the page that shows a notice.
     // TRANS: %1$s is a user name, %2$s is the notice creation date/time.
     return sprintf(_('%1$s\'s status on %2$s'), $base, common_exact_date($this->notice->created));
 }