X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=classes%2FNotice.php;h=c56d68578debef875a7d38bd1579c101bdc571a5;hb=4d17d9533552ea620b83109c550e250a5c236291;hp=020df0c4589ece6e5d8b7b2e8b3f1a8cfd3070af;hpb=45dd3431262846893f958efea9fdfd55ca5f6aed;p=quix0rs-gnu-social.git diff --git a/classes/Notice.php b/classes/Notice.php index 020df0c458..c56d68578d 100644 --- a/classes/Notice.php +++ b/classes/Notice.php @@ -88,7 +88,7 @@ class Notice extends Managed_DataObject 'reply_to' => array('type' => 'int', 'description' => 'notice replied to (usually a guess)'), 'is_local' => array('type' => 'int', 'size' => 'tiny', 'default' => 0, 'description' => 'notice was generated by a user'), 'source' => array('type' => 'varchar', 'length' => 32, 'description' => 'source of comment, like "web", "im", or "clientname"'), - 'conversation' => array('type' => 'int', 'description' => 'id of root notice in this conversation'), + 'conversation' => array('type' => 'int', 'description' => 'the local numerical conversation id'), 'repeat_of' => array('type' => 'int', 'description' => 'notice this is a repeat of'), 'object_type' => array('type' => 'varchar', 'length' => 191, 'description' => 'URI representing activity streams object type', 'default' => null), 'verb' => array('type' => 'varchar', 'length' => 191, 'description' => 'URI representing activity streams verb', 'default' => 'http://activitystrea.ms/schema/1.0/post'), @@ -260,7 +260,8 @@ class Notice extends Managed_DataObject public function getRendered() { - if (is_null($this->rendered) || $this->rendered === '') { + // we test $this->id because if it's not inserted yet, we can't update the field + if (!empty($this->id) && (is_null($this->rendered) || $this->rendered === '')) { // update to include rendered content on-the-fly, so we don't have to have a fix-up script in upgrade.php common_debug('Rendering notice '.$this->getID().' as it had no rendered HTML content.'); $orig = clone($this); @@ -272,6 +273,21 @@ class Notice extends Managed_DataObject return $this->rendered; } + public function getCreated() + { + return $this->created; + } + + public function getVerb($make_relative=false) + { + return ActivityUtils::resolveUri($this->verb, $make_relative); + } + + public function isVerb(array $verbs) + { + return ActivityUtils::compareVerbs($this->getVerb(), $verbs); + } + /* * Get the original representation URL of this notice. * @@ -298,9 +314,21 @@ class Notice extends Managed_DataObject } public function getObjectType($canonical=false) { + if (is_null($this->object_type) || $this->object_type==='') { + throw new NoObjectTypeException($this); + } return ActivityUtils::resolveUri($this->object_type, $canonical); } + public function isObjectType(array $types) + { + try { + return ActivityUtils::compareTypes($this->getObjectType(), $types); + } catch (NoObjectTypeException $e) { + return false; + } + } + public static function getByUri($uri) { $notice = new Notice(); @@ -749,7 +777,7 @@ class Notice extends Managed_DataObject $options['uri'] = $act->id; $options['url'] = $act->link; } else { - $actobj = count($act->objects)==1 ? $act->objects[0] : null; + $actobj = count($act->objects)===1 ? $act->objects[0] : null; if (!is_null($actobj) && !empty($actobj->id)) { $options['uri'] = $actobj->id; if ($actobj->link) { @@ -821,15 +849,17 @@ class Notice extends Managed_DataObject $stored->url = $url; $stored->verb = $act->verb; - // Notice content. We trust local users to provide HTML we like, but of course not remote users. - // FIXME: What about local users importing feeds? Mirror functions must filter out bad HTML first... $content = $act->content ?: $act->summary; if (is_null($content) && !is_null($actobj)) { $content = $actobj->content ?: $actobj->summary; } - $stored->rendered = $actor->isLocal() ? $content : common_purify($content); - // yeah, just don't use getRendered() here since it's not inserted yet ;) - $stored->content = common_strip_html($stored->rendered); + // Strip out any bad HTML + $stored->rendered = common_purify($content); + $stored->content = common_strip_html($stored->getRendered(), true, true); + if (trim($stored->content) === '') { + // TRANS: Error message when the plain text content of a notice has zero length. + throw new ClientException(_('Empty notice content, will not save this.')); + } // Maybe a missing act-time should be fatal if the actor is not local? if (!empty($act->time)) { @@ -950,7 +980,7 @@ class Notice extends Managed_DataObject $object = null; Event::handle('StoreActivityObject', array($act, $stored, $options, &$object)); if (empty($object)) { - throw new ServerException('Unsuccessful call to StoreActivityObject '.$stored->getUri() . ': '.$act->asString()); + throw new NoticeSaveException('Unsuccessful call to StoreActivityObject '._ve($stored->getUri()) . ': '._ve($act->asString())); } // If something changed in the Notice during StoreActivityObject @@ -2128,6 +2158,11 @@ class Notice extends Managed_DataObject Event::handle('EndActivityObjectFromNotice', array($this, &$object)); } + if (!$object instanceof ActivityObject) { + common_log(LOG_ERR, 'Notice asActivityObject created something else for uri=='._ve($this->getUri()).': '._ve($object)); + throw new ServerException('Notice asActivityObject created something else.'); + } + return $object; }