NewnoticeAction now uses Notice::saveActivity(...)
This commit is contained in:
parent
26a6eca94e
commit
0dfafe2567
|
@ -96,7 +96,7 @@ class NewnoticeAction extends FormAction
|
||||||
assert($this->scoped instanceof Profile); // XXX: maybe an error instead...
|
assert($this->scoped instanceof Profile); // XXX: maybe an error instead...
|
||||||
$user = $this->scoped->getUser();
|
$user = $this->scoped->getUser();
|
||||||
$content = $this->trimmed('status_textarea');
|
$content = $this->trimmed('status_textarea');
|
||||||
$options = array();
|
$options = array('source' => 'web');
|
||||||
Event::handle('StartSaveNewNoticeWeb', array($this, $user, &$content, &$options));
|
Event::handle('StartSaveNewNoticeWeb', array($this, $user, &$content, &$options));
|
||||||
|
|
||||||
if (empty($content)) {
|
if (empty($content)) {
|
||||||
|
@ -117,31 +117,30 @@ class NewnoticeAction extends FormAction
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$content_shortened = $user->shortenLinks($content);
|
if ($this->int('inreplyto')) {
|
||||||
if (Notice::contentTooLong($content_shortened)) {
|
// Throws exception if the inreplyto Notice is given but not found.
|
||||||
// TRANS: Client error displayed when the parameter "status" is missing.
|
$parent = Notice::getByID($this->int('inreplyto'));
|
||||||
// TRANS: %d is the maximum number of character for a notice.
|
} else {
|
||||||
$this->clientError(sprintf(_m('That\'s too long. Maximum notice size is %d character.',
|
$parent = null;
|
||||||
'That\'s too long. Maximum notice size is %d characters.',
|
|
||||||
Notice::maxContent()),
|
|
||||||
Notice::maxContent()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$replyto = $this->int('inreplyto');
|
$act = new Activity();
|
||||||
if ($replyto) {
|
$act->verb = ActivityVerb::POST;
|
||||||
$options['reply_to'] = $replyto;
|
$act->time = time();
|
||||||
}
|
$act->actor = $this->scoped->asActivityObject();
|
||||||
|
|
||||||
|
$content = $this->scoped->shortenLinks($content);
|
||||||
|
|
||||||
$upload = null;
|
$upload = null;
|
||||||
try {
|
try {
|
||||||
// throws exception on failure
|
// throws exception on failure
|
||||||
$upload = MediaFile::fromUpload('attach', $this->scoped);
|
$upload = MediaFile::fromUpload('attach', $this->scoped);
|
||||||
if (Event::handle('StartSaveNewNoticeAppendAttachment', array($this, $upload, &$content_shortened, &$options))) {
|
if (Event::handle('StartSaveNewNoticeAppendAttachment', array($this, $upload, &$content, &$options))) {
|
||||||
$content_shortened .= ' ' . $upload->shortUrl();
|
$content .= ' ' . $upload->shortUrl();
|
||||||
}
|
}
|
||||||
Event::handle('EndSaveNewNoticeAppendAttachment', array($this, $upload, &$content_shortened, &$options));
|
Event::handle('EndSaveNewNoticeAppendAttachment', array($this, $upload, &$content, &$options));
|
||||||
|
|
||||||
if (Notice::contentTooLong($content_shortened)) {
|
if (Notice::contentTooLong($content)) {
|
||||||
$upload->delete();
|
$upload->delete();
|
||||||
// TRANS: Client error displayed exceeding the maximum notice length.
|
// TRANS: Client error displayed exceeding the maximum notice length.
|
||||||
// TRANS: %d is the maximum length for a notice.
|
// TRANS: %d is the maximum length for a notice.
|
||||||
|
@ -150,10 +149,25 @@ class NewnoticeAction extends FormAction
|
||||||
Notice::maxContent()),
|
Notice::maxContent()),
|
||||||
Notice::maxContent()));
|
Notice::maxContent()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$act->enclosures[] = $upload->getEnclosure();
|
||||||
} catch (NoUploadedMediaException $e) {
|
} catch (NoUploadedMediaException $e) {
|
||||||
// simply no attached media to the new notice
|
// simply no attached media to the new notice
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$actobj = new ActivityObject();
|
||||||
|
$actobj->type = ActivityObject::NOTE;
|
||||||
|
$actobj->content = common_render_content($content, $this->scoped, $parent);
|
||||||
|
|
||||||
|
$act->objects[] = $actobj;
|
||||||
|
|
||||||
|
|
||||||
|
$act->context = new ActivityContext();
|
||||||
|
|
||||||
|
if ($parent instanceof Notice) {
|
||||||
|
$act->context->replyToID = $parent->getUri();
|
||||||
|
$act->context->replyToUrl = $parent->getUrl(true); // maybe we don't have to send true here to force a URL?
|
||||||
|
}
|
||||||
|
|
||||||
if ($this->scoped->shareLocation()) {
|
if ($this->scoped->shareLocation()) {
|
||||||
// use browser data if checked; otherwise profile data
|
// use browser data if checked; otherwise profile data
|
||||||
|
@ -171,19 +185,20 @@ class NewnoticeAction extends FormAction
|
||||||
$this->scoped);
|
$this->scoped);
|
||||||
}
|
}
|
||||||
|
|
||||||
$options = array_merge($options, $locOptions);
|
$act->context->location = Location::fromOptions($locOptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
$author_id = $this->scoped->id;
|
$author_id = $this->scoped->id;
|
||||||
$text = $content_shortened;
|
$text = $content;
|
||||||
|
|
||||||
// Does the heavy-lifting for getting "To:" information
|
// Does the heavy-lifting for getting "To:" information
|
||||||
|
|
||||||
ToSelector::fillOptions($this, $options);
|
ToSelector::fillOptions($this, $options);
|
||||||
|
|
||||||
|
// FIXME: Make sure NoticeTitle plugin gets a change to add the title to our activityobject!
|
||||||
if (Event::handle('StartNoticeSaveWeb', array($this, &$author_id, &$text, &$options))) {
|
if (Event::handle('StartNoticeSaveWeb', array($this, &$author_id, &$text, &$options))) {
|
||||||
|
|
||||||
$this->stored = Notice::saveNew($this->scoped->id, $content_shortened, 'web', $options);
|
$this->stored = Notice::saveActivity($act, $this->scoped, $options);
|
||||||
|
|
||||||
if ($upload instanceof MediaFile) {
|
if ($upload instanceof MediaFile) {
|
||||||
$upload->attachToNotice($this->stored);
|
$upload->attachToNotice($this->stored);
|
||||||
|
@ -192,7 +207,7 @@ class NewnoticeAction extends FormAction
|
||||||
Event::handle('EndNoticeSaveWeb', array($this, $this->stored));
|
Event::handle('EndNoticeSaveWeb', array($this, $this->stored));
|
||||||
}
|
}
|
||||||
|
|
||||||
Event::handle('EndSaveNewNoticeWeb', array($this, $user, &$content_shortened, &$options));
|
Event::handle('EndSaveNewNoticeWeb', array($this, $user, &$content, &$options));
|
||||||
|
|
||||||
if (!GNUsocial::isAjax()) {
|
if (!GNUsocial::isAjax()) {
|
||||||
$url = common_local_url('shownotice', array('notice' => $this->stored->id));
|
$url = common_local_url('shownotice', array('notice' => $this->stored->id));
|
||||||
|
|
|
@ -738,6 +738,7 @@ class Notice extends Managed_DataObject
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get ActivityObject properties
|
// Get ActivityObject properties
|
||||||
|
$actobj = null;
|
||||||
if (!empty($act->id)) {
|
if (!empty($act->id)) {
|
||||||
// implied object
|
// implied object
|
||||||
$options['uri'] = $act->id;
|
$options['uri'] = $act->id;
|
||||||
|
@ -815,12 +816,26 @@ class Notice extends Managed_DataObject
|
||||||
$stored->url = $url;
|
$stored->url = $url;
|
||||||
$stored->verb = $act->verb;
|
$stored->verb = $act->verb;
|
||||||
|
|
||||||
// Use the local user's shortening preferences, if applicable.
|
// Notice content. We trust local users to provide HTML we like, but of course not remote users.
|
||||||
$stored->rendered = $actor->isLocal()
|
// FIXME: What about local users importing feeds? Mirror functions must filter out bad HTML first...
|
||||||
? $actor->shortenLinks($act->content)
|
$content = $act->content ?: $act->summary;
|
||||||
: common_purify($act->content);
|
if (is_null($content) && !is_null($actobj)) {
|
||||||
|
$content = $actobj->content ?: $actobj->summary;
|
||||||
|
}
|
||||||
|
$stored->rendered = $actor->isLocal() ? $content : common_purify($content);
|
||||||
$stored->content = common_strip_html($stored->rendered);
|
$stored->content = common_strip_html($stored->rendered);
|
||||||
|
|
||||||
|
// Reject notice if it is too long (without the HTML)
|
||||||
|
// FIXME: Reject if too short (empty) too? But we have to pass the
|
||||||
|
if ($actor->isLocal() && Notice::contentTooLong($stored->content)) {
|
||||||
|
// TRANS: Client error displayed when the parameter "status" is missing.
|
||||||
|
// TRANS: %d is the maximum number of character for a notice.
|
||||||
|
throw new ClientException(sprintf(_m('That\'s too long. Maximum notice size is %d character.',
|
||||||
|
'That\'s too long. Maximum notice size is %d characters.',
|
||||||
|
Notice::maxContent()),
|
||||||
|
Notice::maxContent()));
|
||||||
|
}
|
||||||
|
|
||||||
// Maybe a missing act-time should be fatal if the actor is not local?
|
// Maybe a missing act-time should be fatal if the actor is not local?
|
||||||
if (!empty($act->time)) {
|
if (!empty($act->time)) {
|
||||||
$stored->created = common_sql_date($act->time);
|
$stored->created = common_sql_date($act->time);
|
||||||
|
|
|
@ -74,6 +74,11 @@ class MediaFile
|
||||||
return $this->short_fileurl;
|
return $this->short_fileurl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getEnclosure()
|
||||||
|
{
|
||||||
|
return $this->getFile()->getEnclosure();
|
||||||
|
}
|
||||||
|
|
||||||
function delete()
|
function delete()
|
||||||
{
|
{
|
||||||
$filepath = File::path($this->filename);
|
$filepath = File::path($this->filename);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user