}
}
+ public function getSelfLink()
+ {
+ if ($this->isLocal()) {
+ return common_local_url('ApiStatusesShow', array('id' => $this->getID(), 'format' => 'atom'));
+ }
+
+ $selfLink = $this->getPref('ostatus', 'self');
+
+ if (!common_valid_http_url($selfLink)) {
+ throw new InvalidUrlException($selfLink);
+ }
+
+ return $selfLink;
+ }
+
public function getObjectType($canonical=false) {
if (is_null($this->object_type) || $this->object_type==='') {
throw new NoObjectTypeException($this);
static function saveNew($profile_id, $content, $source, array $options=null) {
$defaults = array('uri' => null,
'url' => null,
+ 'self' => null,
'conversation' => null, // URI of conversation
'reply_to' => null, // This will override convo URI if the parent is known
'repeat_of' => null, // This will override convo URI if the repeated notice is known
} else {
// Conversation entry with specified URI was not found, so we must create it.
common_debug('Conversation URI not found, so we will create it with the URI given in the options to Notice::saveNew: '.$options['conversation']);
+ $convctx = new ActivityContext();
+ $convctx->conversation = $options['conversation'];
+ if (array_key_exists('conversation_url', $options)) {
+ $convctx->conversation_url = $options['conversation_url'];
+ }
// The insert in Conversation::create throws exception on failure
- $conv = Conversation::create($options['conversation'], $notice->created);
+ $conv = Conversation::create($convctx, $notice->created);
}
$notice->conversation = $conv->getID();
unset($conv);
}
}
+ if ($self && common_valid_http_url($self)) {
+ $notice->setPref('ostatus', 'self', $self);
+ }
+
// Only save 'attention' and metadata stuff (URLs, tags...) stuff if
// the activityverb is a POST (since stuff like repeat, favorite etc.
// reasonably handle notifications themselves.
// implied object
$options['uri'] = $act->id;
$options['url'] = $act->link;
+ if ($act->selfLink) {
+ $options['self'] = $act->selfLink;
+ }
} else {
$actobj = count($act->objects)===1 ? $act->objects[0] : null;
if (!is_null($actobj) && !empty($actobj->id)) {
$options['url'] = $actobj->id;
}
}
+ if ($actobj->selfLink) {
+ $options['self'] = $actobj->selfLink;
+ }
}
$defaults = array(
'reply_to' => null,
'repeat_of' => null,
'scope' => null,
+ 'self' => null,
'source' => 'unknown',
'tags' => array(),
'uri' => null,
// Conversation entry with specified URI was not found, so we must create it.
common_debug('Conversation URI not found, so we will create it with the URI given in the context of the activity: '.$act->context->conversation);
// The insert in Conversation::create throws exception on failure
- $conv = Conversation::create($act->context->conversation, $stored->created);
+ $conv = Conversation::create($act->context, $stored->created);
}
$stored->conversation = $conv->getID();
unset($conv);
throw new ServerException('Supposedly saved Notice has no ID.');
}
+ if ($self && common_valid_http_url($self)) {
+ $stored->setPref('ostatus', 'self', $self);
+ }
+
// Only save 'attention' and metadata stuff (URLs, tags...) stuff if
// the activityverb is a POST (since stuff like repeat, favorite etc.
// reasonably handle notifications themselves.
if (common_config('group', 'addtag')) {
// we automatically add a tag for every group name, too
-
- $tag = Notice_tag::pkeyGet(array('tag' => common_canonical_tag($group->nickname),
- 'notice_id' => $this->id));
+ common_debug('Adding hashtag matching group nickname: '._ve($group->getNickname()));
+ $tag = Notice_tag::pkeyGet(array('tag' => common_canonical_tag($group->getNickname()),
+ 'notice_id' => $this->getID()));
if (is_null($tag)) {
- $this->saveTag($group->nickname);
+ $this->saveTag($group->getNickname());
}
}
$conv = Conversation::getKV('id', $this->conversation);
if ($conv instanceof Conversation) {
$ctx->conversation = $conv->uri;
+ $ctx->conversation_url = $conv->url;
}
}
}
}
+ try {
+ $act->selfLink = $this->getSelfLink();
+ } catch (InvalidUrlException $e) {
+ $act->selfLink = null;
+ }
if ($this->isLocal()) {
- $act->selfLink = common_local_url('ApiStatusesShow', array('id' => $this->id,
- 'format' => 'atom'));
$act->editLink = $act->selfLink;
}
if (!empty($ns->url)) {
$noticeInfoAttr['source_link'] = $ns->url;
if (!empty($ns->name)) {
- $noticeInfoAttr['source'] = '<a href="'
- . htmlspecialchars($ns->url)
- . '" rel="nofollow">'
- . htmlspecialchars($ns->name)
- . '</a>';
+ $noticeInfoAttr['source'] = $ns->name;
}
}
}
$object->title = sprintf('New %1$s by %2$s', ActivityObject::canonicalType($object->type), $this->getProfile()->getNickname());
$object->content = $this->getRendered();
$object->link = $this->getUrl();
+ try {
+ $object->selfLink = $this->getSelfLink();
+ } catch (InvalidUrlException $e) {
+ $object->selfLink = null;
+ }
$object->extra[] = array('status_net', array('notice_id' => $this->id));
return !empty($this->repeat_of);
}
+ public function isRepeated()
+ {
+ $n = new Notice();
+ $n->repeat_of = $this->getID();
+ return $n->find() && $n->N > 0;
+ }
+
/**
* Get the list of hash tags saved with this notice.
*
$schema = Schema::get();
$schemadef = $schema->getTableDef($table);
+ // 2015-09-04 We move Notice location data to Notice_location
+ // First we see if we have to do this at all
+ if (isset($schemadef['fields']['lat'])
+ && isset($schemadef['fields']['lon'])
+ && isset($schemadef['fields']['location_id'])
+ && isset($schemadef['fields']['location_ns'])) {
+ // Then we make sure the Notice_location table is created!
+ $schema->ensureTable('notice_location', Notice_location::schemaDef());
+
+ // Then we continue on our road to migration!
+ echo "\nFound old $table table, moving location data to 'notice_location' table... (this will probably take a LONG time, but can be aborted and continued)";
+
+ $notice = new Notice();
+ $notice->query(sprintf('SELECT id, lat, lon, location_id, location_ns FROM %1$s ' .
+ 'WHERE lat IS NOT NULL ' .
+ 'OR lon IS NOT NULL ' .
+ 'OR location_id IS NOT NULL ' .
+ 'OR location_ns IS NOT NULL',
+ $schema->quoteIdentifier($table)));
+ print "\nFound {$notice->N} notices with location data, inserting";
+ while ($notice->fetch()) {
+ $notloc = Notice_location::getKV('notice_id', $notice->id);
+ if ($notloc instanceof Notice_location) {
+ print "-";
+ continue;
+ }
+ $notloc = new Notice_location();
+ $notloc->notice_id = $notice->id;
+ $notloc->lat= $notice->lat;
+ $notloc->lon= $notice->lon;
+ $notloc->location_id= $notice->location_id;
+ $notloc->location_ns= $notice->location_ns;
+ $notloc->insert();
+ print ".";
+ }
+ print "\n";
+ }
+
/**
* Make sure constraints are met before upgrading, if foreign keys
* are not already in use.
unset($notice);
}
}
+ }
- // 2015-09-04 We move Notice location data to Notice_location
- // First we see if we have to do this at all
- if (!isset($schemadef['fields']['lat'])
- && !isset($schemadef['fields']['lon'])
- && !isset($schemadef['fields']['location_id'])
- && !isset($schemadef['fields']['location_ns'])) {
- // We have already removed the location fields, so no need to migrate.
- return;
+ public function delPref($namespace, $topic) {
+ return Notice_prefs::setData($this, $namespace, $topic, null);
+ }
+
+ public function getPref($namespace, $topic, $default=null) {
+ // If you want an exception to be thrown, call Notice_prefs::getData directly
+ try {
+ return Notice_prefs::getData($this, $namespace, $topic, $default);
+ } catch (NoResultException $e) {
+ return null;
}
- // Then we make sure the Notice_location table is created!
- $schema->ensureTable('notice_location', Notice_location::schemaDef());
+ }
- // Then we continue on our road to migration!
- echo "\nFound old $table table, moving location data to 'notice_location' table... (this will probably take a LONG time, but can be aborted and continued)";
+ // The same as getPref but will fall back to common_config value for the same namespace/topic
+ public function getConfigPref($namespace, $topic)
+ {
+ return Notice_prefs::getConfigData($this, $namespace, $topic);
+ }
- $notice = new Notice();
- $notice->query(sprintf('SELECT id, lat, lon, location_id, location_ns FROM %1$s ' .
- 'WHERE lat IS NOT NULL ' .
- 'OR lon IS NOT NULL ' .
- 'OR location_id IS NOT NULL ' .
- 'OR location_ns IS NOT NULL',
- $schema->quoteIdentifier($table)));
- print "\nFound {$notice->N} notices with location data, inserting";
- while ($notice->fetch()) {
- $notloc = Notice_location::getKV('notice_id', $notice->id);
- if ($notloc instanceof Notice_location) {
- print "-";
- continue;
- }
- $notloc = new Notice_location();
- $notloc->notice_id = $notice->id;
- $notloc->lat= $notice->lat;
- $notloc->lon= $notice->lon;
- $notloc->location_id= $notice->location_id;
- $notloc->location_ns= $notice->location_ns;
- $notloc->insert();
- print ".";
- }
- print "\n";
+ public function setPref($namespace, $topic, $data) {
+ return Notice_prefs::setData($this, $namespace, $topic, $data);
}
}