forked from GNUsocial/gnu-social
allow html content in summary and clean it out of title
This commit is contained in:
parent
25cb917523
commit
2fc0f0433e
@ -434,6 +434,17 @@ class ActivityUtils
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static function childHtmlContent(DOMNode $element, $tag, $namespace=self::ATOM)
|
||||||
|
{
|
||||||
|
$el = self::child($element, $tag, $namespace);
|
||||||
|
|
||||||
|
if (empty($el)) {
|
||||||
|
return null;
|
||||||
|
} else {
|
||||||
|
return self::textConstruct($el);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the content of an atom:entry-like object
|
* Get the content of an atom:entry-like object
|
||||||
*
|
*
|
||||||
@ -448,27 +459,28 @@ class ActivityUtils
|
|||||||
|
|
||||||
static function getContent($element)
|
static function getContent($element)
|
||||||
{
|
{
|
||||||
$contentEl = ActivityUtils::child($element, self::CONTENT);
|
return self::childHtmlContent($element, self::CONTENT, self::ATOM);
|
||||||
|
}
|
||||||
|
|
||||||
if (!empty($contentEl)) {
|
static function textConstruct($el)
|
||||||
|
{
|
||||||
$src = $contentEl->getAttribute(self::SRC);
|
$src = $el->getAttribute(self::SRC);
|
||||||
|
|
||||||
if (!empty($src)) {
|
if (!empty($src)) {
|
||||||
throw new ClientException(_("Can't handle remote content yet."));
|
throw new ClientException(_("Can't handle remote content yet."));
|
||||||
}
|
}
|
||||||
|
|
||||||
$type = $contentEl->getAttribute(self::TYPE);
|
$type = $el->getAttribute(self::TYPE);
|
||||||
|
|
||||||
// slavishly following http://atompub.org/rfc4287.html#rfc.section.4.1.3.3
|
// slavishly following http://atompub.org/rfc4287.html#rfc.section.4.1.3.3
|
||||||
|
|
||||||
if (empty($type) || $type == 'text') {
|
if (empty($type) || $type == 'text') {
|
||||||
return $contentEl->textContent;
|
return $el->textContent;
|
||||||
} else if ($type == 'html') {
|
} else if ($type == 'html') {
|
||||||
$text = $contentEl->textContent;
|
$text = $el->textContent;
|
||||||
return htmlspecialchars_decode($text, ENT_QUOTES);
|
return htmlspecialchars_decode($text, ENT_QUOTES);
|
||||||
} else if ($type == 'xhtml') {
|
} else if ($type == 'xhtml') {
|
||||||
$divEl = ActivityUtils::child($contentEl, 'div', 'http://www.w3.org/1999/xhtml');
|
$divEl = ActivityUtils::child($el, 'div', 'http://www.w3.org/1999/xhtml');
|
||||||
if (empty($divEl)) {
|
if (empty($divEl)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -485,12 +497,11 @@ class ActivityUtils
|
|||||||
preg_match('#(+|/)xml$#', $type)) {
|
preg_match('#(+|/)xml$#', $type)) {
|
||||||
throw new ClientException(_("Can't handle embedded XML content yet."));
|
throw new ClientException(_("Can't handle embedded XML content yet."));
|
||||||
} else if (strncasecmp($type, 'text/', 5)) {
|
} else if (strncasecmp($type, 'text/', 5)) {
|
||||||
return $contentEl->textContent;
|
return $el->textContent;
|
||||||
} else {
|
} else {
|
||||||
throw new ClientException(_("Can't handle embedded Base64 content yet."));
|
throw new ClientException(_("Can't handle embedded Base64 content yet."));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// XXX: Arg! This wouldn't be necessary if we used Avatars conistently
|
// XXX: Arg! This wouldn't be necessary if we used Avatars conistently
|
||||||
@ -700,13 +711,17 @@ class ActivityObject
|
|||||||
}
|
}
|
||||||
|
|
||||||
$this->id = $this->_childContent($element, self::ID);
|
$this->id = $this->_childContent($element, self::ID);
|
||||||
$this->title = $this->_childContent($element, self::TITLE);
|
$this->summary = ActivityUtils::childHtmlContent($element, self::SUMMARY);
|
||||||
$this->summary = $this->_childContent($element, self::SUMMARY);
|
$this->content = ActivityUtils::getContent($element);
|
||||||
|
|
||||||
|
// We don't like HTML in our titles, although it's technically allowed
|
||||||
|
|
||||||
|
$title = ActivityUtils::childHtmlContent($element, self::TITLE);
|
||||||
|
|
||||||
|
$this->title = html_entity_decode(strip_tags($title));
|
||||||
|
|
||||||
$this->source = $this->_getSource($element);
|
$this->source = $this->_getSource($element);
|
||||||
|
|
||||||
$this->content = ActivityUtils::getContent($element);
|
|
||||||
|
|
||||||
$this->link = ActivityUtils::getPermalink($element);
|
$this->link = ActivityUtils::getPermalink($element);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user