X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=classes%2FNotice.php;h=dd9438f1604e52c5a49bdc7f23640aa2a2824153;hb=37994e3ff124fa2456c7dcf59970ca97d8db83ff;hp=13b322828bade789c9c45a3c083d0123b1a8d439;hpb=521daf5562051d0cc319c35a0dceaae3e0fd49b7;p=quix0rs-gnu-social.git diff --git a/classes/Notice.php b/classes/Notice.php index 13b322828b..dd9438f160 100644 --- a/classes/Notice.php +++ b/classes/Notice.php @@ -476,7 +476,9 @@ class Notice extends Memcached_DataObject * @return void */ function saveUrls() { - common_replace_urls_callback($this->content, array($this, 'saveUrl'), $this->id); + if (common_config('attachments', 'process_links')) { + common_replace_urls_callback($this->content, array($this, 'saveUrl'), $this->id); + } } /** @@ -489,9 +491,11 @@ class Notice extends Memcached_DataObject */ function saveKnownUrls($urls) { - // @fixme validation? - foreach (array_unique($urls) as $url) { - File::processNew($url, $this->id); + if (common_config('attachments', 'process_links')) { + // @fixme validation? + foreach (array_unique($urls) as $url) { + File::processNew($url, $this->id); + } } } @@ -524,10 +528,8 @@ class Notice extends Memcached_DataObject $notice = new Notice(); $notice->profile_id = $profile_id; $notice->content = $content; - if (common_config('db','type') == 'pgsql') - $notice->whereAdd('extract(epoch from now() - created) < ' . common_config('site', 'dupelimit')); - else - $notice->whereAdd('now() - created < ' . common_config('site', 'dupelimit')); + $threshold = common_sql_date(time() - common_config('site', 'dupelimit')); + $notice->whereAdd(sprintf("created > '%s'", $notice->escape($threshold))); $cnt = $notice->count(); return ($cnt == 0); @@ -745,6 +747,7 @@ class Notice extends Memcached_DataObject 1, 1 ); + if ($conversation->N > 0) { return true; } @@ -903,7 +906,7 @@ class Notice extends Memcached_DataObject { if (!is_array($group_ids)) { // TRANS: Server exception thrown when no array is provided to the method saveKnownGroups(). - throw new ServerException(_("Bad type provided to saveKnownGroups")); + throw new ServerException(_('Bad type provided to saveKnownGroups.')); } $groups = array(); @@ -1116,7 +1119,7 @@ class Notice extends Memcached_DataObject common_log_db_error($reply, 'INSERT', __FILE__); // TRANS: Server exception thrown when a reply cannot be saved. // TRANS: %1$d is a notice ID, %2$d is the ID of the mentioned user. - throw new ServerException(sprintf(_("Could not save reply for %1$d, %2$d."), $this->id, $mentioned->id)); + throw new ServerException(sprintf(_('Could not save reply for %1$d, %2$d.'), $this->id, $mentioned->id)); } else { $replied[$mentioned->id] = 1; self::blow('reply:stream:%d', $mentioned->id); @@ -1219,6 +1222,64 @@ class Notice extends Memcached_DataObject return $groups; } + function asActivity() + { + $profile = $this->getProfile(); + + $act = new Activity(); + + $act->actor = ActivityObject::fromProfile($profile); + $act->verb = ActivityVerb::POST; + $act->objects[] = ActivityObject::fromNotice($this); + + $act->time = strtotime($this->created); + $act->link = $this->bestUrl(); + + $act->content = common_xml_safe_str($this->rendered); + $act->id = $this->uri; + $act->title = common_xml_safe_str($this->content); + + $ctx = new ActivityContext(); + + if (!empty($this->reply_to)) { + $reply = Notice::staticGet('id', $this->reply_to); + if (!empty($reply)) { + $ctx->replyToID = $reply->uri; + $ctx->replyToUrl = $reply->bestUrl(); + } + } + + $ctx->location = $this->getLocation(); + + $conv = null; + + if (!empty($this->conversation)) { + $conv = Conversation::staticGet('id', $this->conversation); + if (!empty($conv)) { + $ctx->conversation = $conv->uri; + } + } + + $reply_ids = $this->getReplies(); + + foreach ($reply_ids as $id) { + $profile = Profile::staticGet('id', $id); + if (!empty($profile)) { + $ctx->attention[] = $profile->getUri(); + } + } + + $groups = $this->getGroups(); + + foreach ($groups as $group) { + $ctx->attention[] = $group->uri; + } + + $act->context = $ctx; + + return $act; + } + // This has gotten way too long. Needs to be sliced up into functional bits // or ideally exported to a utility class. @@ -1247,13 +1308,10 @@ class Notice extends Memcached_DataObject } if (Event::handle('StartActivitySource', array(&$this, &$xs))) { - if ($source) { - $atom_feed = $profile->getAtomFeed(); if (!empty($atom_feed)) { - $xs->elementStart('source'); // XXX: we should store the actual feed ID @@ -1557,6 +1615,35 @@ class Notice extends Memcached_DataObject Event::handle('EndActivityGeo', array(&$this, &$xs, $lat, $lon)); } + // @fixme check this logic + + if ($this->isLocal()) { + + $selfUrl = common_local_url('ApiStatusesShow', array('id' => $this->id, + 'format' => 'atom')); + + if (Event::handle('StartActivityRelSelf', array(&$this, &$xs, &$selfUrl))) { + $xs->element('link', array('rel' => 'self', + 'type' => 'application/atom+xml', + 'href' => $selfUrl)); + Event::handle('EndActivityRelSelf', array(&$this, &$xs, $selfUrl)); + } + + if (!empty($cur) && $cur->id == $this->profile_id) { + + // note: $selfUrl may have been changed by a plugin + $relEditUrl = common_local_url('ApiStatusesShow', array('id' => $this->id, + 'format' => 'atom')); + + if (Event::handle('StartActivityRelEdit', array(&$this, &$xs, &$relEditUrl))) { + $xs->element('link', array('rel' => 'edit', + 'type' => 'application/atom+xml', + 'href' => $relEditUrl)); + Event::handle('EndActivityRelEdit', array(&$this, &$xs, $relEditUrl)); + } + } + } + if (Event::handle('StartActivityEnd', array(&$this, &$xs))) { $xs->elementEnd('entry'); Event::handle('EndActivityEnd', array(&$this, &$xs)); @@ -1841,7 +1928,6 @@ class Notice extends Memcached_DataObject $options = array(); if (!empty($location_id) && !empty($location_ns)) { - $options['location_id'] = $location_id; $options['location_ns'] = $location_ns; @@ -1853,7 +1939,6 @@ class Notice extends Memcached_DataObject } } else if (!empty($lat) && !empty($lon)) { - $options['lat'] = $lat; $options['lon'] = $lon; @@ -1864,7 +1949,6 @@ class Notice extends Memcached_DataObject $options['location_ns'] = $location->location_ns; } } else if (!empty($profile)) { - if (isset($profile->lat) && isset($profile->lon)) { $options['lat'] = $profile->lat; $options['lon'] = $profile->lon; @@ -1981,6 +2065,7 @@ class Notice extends Memcached_DataObject { // We always insert for the author so they don't // have to wait + Event::handle('StartNoticeDistribute', array($this)); $user = User::staticGet('id', $this->profile_id); if (!empty($user)) {