+ if (isset($urls)) {
+ $notice->saveKnownUrls($urls);
+ } else {
+ $notice->saveUrls();
+ }
+
+ if ($distribute) {
+ // Prepare inbox delivery, may be queued to background.
+ $notice->distribute();
+ }
+
+ return $notice;
+ }
+
+ static function saveActivity(Activity $act, Profile $actor, array $options=array())
+ {
+ // First check if we're going to let this Activity through from the specific actor
+ if (!$actor->hasRight(Right::NEWNOTICE)) {
+ common_log(LOG_WARNING, "Attempted post from user disallowed to post: " . $actor->getNickname());
+
+ // TRANS: Client exception thrown when a user tries to post while being banned.
+ throw new ClientException(_m('You are banned from posting notices on this site.'), 403);
+ }
+ if (common_config('throttle', 'enabled') && !self::checkEditThrottle($actor->id)) {
+ common_log(LOG_WARNING, 'Excessive posting by profile #' . $actor->id . '; throttled.');
+ // TRANS: Client exception thrown when a user tries to post too many notices in a given time frame.
+ throw new ClientException(_m('Too many notices too fast; take a breather '.
+ 'and post again in a few minutes.'));
+ }
+
+/* This interferes with stuff like Favorites from old StatusNet installations (first object in objects is the favored notice)
+ // Get ActivityObject properties
+ $actobj = count($act->objects)==1 ? $act->objects[0] : null;
+ if (!is_null($actobj) && $actobj->id) {
+ $options['uri'] = $actobj->id;
+ if ($actobj->link) {
+ $options['url'] = $actobj->link;
+ } elseif ($act->link) {
+ $options['url'] = $act->link;
+ } elseif (preg_match('!^https?://!', $actobj->id)) {
+ $options['url'] = $actobj->id;
+ }
+ } else {
+ // implied object
+ $options['uri'] = $act->id;
+ $options['url'] = $act->link;
+ }
+*/
+
+ $defaults = array(
+ 'groups' => array(),
+ 'is_local' => self::LOCAL_PUBLIC,
+ 'mentions' => array(),
+ 'reply_to' => null,
+ 'repeat_of' => null,
+ 'scope' => null,
+ 'source' => 'unknown',
+ 'tags' => array(),
+ 'uri' => null,
+ 'url' => null,
+ 'urls' => array(),
+ 'distribute' => true);
+
+ // options will have default values when nothing has been supplied
+ $options = array_merge($defaults, $options);
+ foreach (array_keys($defaults) as $key) {
+ // Only convert the keynames we specify ourselves from 'defaults' array into variables
+ $$key = $options[$key];
+ }
+ extract($options, EXTR_SKIP);
+
+ $stored = new Notice();
+ if (!empty($uri)) {
+ $stored->uri = $uri;
+ if ($stored->find()) {
+ common_debug('cannot create duplicate Notice URI: '.$stored->uri);
+ throw new Exception('Notice URI already exists');