forked from GNUsocial/gnu-social
Merge branch 'testing' of git@gitorious.org:statusnet/mainline into testing
This commit is contained in:
commit
2c9887bce5
@ -253,69 +253,69 @@ class OStatusPlugin extends Plugin
|
|||||||
|
|
||||||
function onEndFindMentions($sender, $text, &$mentions)
|
function onEndFindMentions($sender, $text, &$mentions)
|
||||||
{
|
{
|
||||||
preg_match_all('!(?:^|\s+)
|
$matches = array();
|
||||||
@( # Webfinger:
|
|
||||||
(?:\w+\.)*\w+ # user
|
// Webfinger matches: @user@example.com
|
||||||
@ # @
|
if (preg_match_all('!(?:^|\s+)@((?:\w+\.)*\w+@(?:\w+\.)*\w+(?:\w+\-\w+)*\.\w+)!',
|
||||||
(?:\w+\.)*\w+(?:\w+\-\w+)*\.\w+ # domain
|
|
||||||
| # Profile:
|
|
||||||
(?:\w+\.)*\w+(?:\w+\-\w+)*\.\w+ # domain
|
|
||||||
(?:/\w+)+ # /path1(/path2...)
|
|
||||||
)!x',
|
|
||||||
$text,
|
$text,
|
||||||
$wmatches,
|
$wmatches,
|
||||||
PREG_OFFSET_CAPTURE);
|
PREG_OFFSET_CAPTURE)) {
|
||||||
|
|
||||||
foreach ($wmatches[1] as $wmatch) {
|
foreach ($wmatches[1] as $wmatch) {
|
||||||
$target = $wmatch[0];
|
list($target, $pos) = $wmatch;
|
||||||
$oprofile = null;
|
$this->log(LOG_INFO, "Checking webfinger '$target'");
|
||||||
|
|
||||||
if (strpos($target, '/') === false) {
|
|
||||||
$this->log(LOG_INFO, "Checking Webfinger for address '$target'");
|
|
||||||
try {
|
try {
|
||||||
$oprofile = Ostatus_profile::ensureWebfinger($target);
|
$oprofile = Ostatus_profile::ensureWebfinger($target);
|
||||||
|
if ($oprofile && !$oprofile->isGroup()) {
|
||||||
|
$profile = $oprofile->localProfile();
|
||||||
|
$matches[$pos] = array('mentioned' => array($profile),
|
||||||
|
'text' => $target,
|
||||||
|
'position' => $pos,
|
||||||
|
'url' => $profile->profileurl);
|
||||||
|
}
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
$this->log(LOG_ERR, "Webfinger check failed: " . $e->getMessage());
|
$this->log(LOG_ERR, "Webfinger check failed: " . $e->getMessage());
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
$schemes = array('https', 'http');
|
}
|
||||||
|
|
||||||
|
// Profile matches: @example.com/mublog/user
|
||||||
|
if (preg_match_all('!(?:^|\s+)@((?:\w+\.)*\w+(?:\w+\-\w+)*\.\w+(?:/\w+)+)!',
|
||||||
|
$text,
|
||||||
|
$wmatches,
|
||||||
|
PREG_OFFSET_CAPTURE)) {
|
||||||
|
foreach ($wmatches[1] as $wmatch) {
|
||||||
|
list($target, $pos) = $wmatch;
|
||||||
|
$schemes = array('http', 'https');
|
||||||
foreach ($schemes as $scheme) {
|
foreach ($schemes as $scheme) {
|
||||||
$url = "$scheme://$target";
|
$url = "$scheme://$target";
|
||||||
$this->log(LOG_INFO, "Checking profile address '$url'");
|
$this->log(LOG_INFO, "Checking profile address '$url'");
|
||||||
try {
|
try {
|
||||||
$oprofile = Ostatus_profile::ensureProfile($url);
|
$oprofile = Ostatus_profile::ensureProfile($url);
|
||||||
if ($oprofile) {
|
if ($oprofile && !$oprofile->isGroup()) {
|
||||||
continue;
|
$profile = $oprofile->localProfile();
|
||||||
|
$matches[$pos] = array('mentioned' => array($profile),
|
||||||
|
'text' => $target,
|
||||||
|
'position' => $pos,
|
||||||
|
'url' => $profile->profileurl);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
$this->log(LOG_ERR, "Profile check failed: " . $e->getMessage());
|
$this->log(LOG_ERR, "Profile check failed: " . $e->getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (empty($oprofile)) {
|
|
||||||
$this->log(LOG_INFO, "No Ostatus_profile found for address '$target'");
|
|
||||||
} else {
|
|
||||||
|
|
||||||
$this->log(LOG_INFO, "Ostatus_profile found for address '$target'");
|
|
||||||
|
|
||||||
if ($oprofile->isGroup()) {
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
$profile = $oprofile->localProfile();
|
|
||||||
|
|
||||||
$pos = $wmatch[1];
|
|
||||||
foreach ($mentions as $i => $other) {
|
foreach ($mentions as $i => $other) {
|
||||||
// If we share a common prefix with a local user, override it!
|
// If we share a common prefix with a local user, override it!
|
||||||
if ($other['position'] == $pos) {
|
$pos = $other['position'];
|
||||||
unset($mentions[$i]);
|
if (isset($matches[$pos])) {
|
||||||
|
$mentions[$i] = $matches[$pos];
|
||||||
|
unset($matches[$pos]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$mentions[] = array('mentioned' => array($profile),
|
foreach ($matches as $mention) {
|
||||||
'text' => $target,
|
$mentions[] = $mention;
|
||||||
'position' => $pos,
|
|
||||||
'url' => $profile->profileurl);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -1500,7 +1500,7 @@ class Ostatus_profile extends Memcached_DataObject
|
|||||||
if (array_key_exists('url', $hcard)) {
|
if (array_key_exists('url', $hcard)) {
|
||||||
if (is_string($hcard['url'])) {
|
if (is_string($hcard['url'])) {
|
||||||
$hints['homepage'] = $hcard['url'];
|
$hints['homepage'] = $hcard['url'];
|
||||||
} else if (is_array($hcard['adr'])) {
|
} else if (is_array($hcard['url'])) {
|
||||||
// HACK get the last one; that's how our hcards look
|
// HACK get the last one; that's how our hcards look
|
||||||
$hints['homepage'] = $hcard['url'][count($hcard['url'])-1];
|
$hints['homepage'] = $hcard['url'][count($hcard['url'])-1];
|
||||||
}
|
}
|
||||||
|
@ -149,11 +149,13 @@ class XRD
|
|||||||
$link['href'] = $element->getAttribute('href');
|
$link['href'] = $element->getAttribute('href');
|
||||||
$link['template'] = $element->getAttribute('template');
|
$link['template'] = $element->getAttribute('template');
|
||||||
foreach ($element->childNodes as $node) {
|
foreach ($element->childNodes as $node) {
|
||||||
|
if ($node instanceof DOMElement) {
|
||||||
switch($node->tagName) {
|
switch($node->tagName) {
|
||||||
case 'Title':
|
case 'Title':
|
||||||
$link['title'][] = $node->nodeValue;
|
$link['title'][] = $node->nodeValue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return $link;
|
return $link;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user