Merge branch 'testing' of gitorious.org:statusnet/mainline into testing

* 'testing' of gitorious.org:statusnet/mainline:
  OStatus discover fixes:
  Remove xpm support (no one really uses it, and IMAGETYPE_XPM is undefined, causing warnings)
  Fix notice warning about unused var -- was renamed during refactoring.
This commit is contained in:
Zach Copley 2010-03-18 17:11:06 -07:00
commit a6c9445f0d
6 changed files with 80 additions and 54 deletions

View File

@ -62,6 +62,14 @@ class Subscription extends Memcached_DataObject
static function start($subscriber, $other)
{
// @fixme should we enforce this as profiles in callers instead?
if ($subscriber instanceof User) {
$subscriber = $subscriber->getProfile();
}
if ($other instanceof User) {
$other = $other->getProfile();
}
if (!$subscriber->hasRight(Right::SUBSCRIBE)) {
throw new Exception(_('You have been banned from subscribing.'));
}

View File

@ -720,7 +720,7 @@ class ActivityObject
}
}
static function fromNotice($notice)
static function fromNotice(Notice $notice)
{
$object = new ActivityObject();
@ -734,7 +734,7 @@ class ActivityObject
return $object;
}
static function fromProfile($profile)
static function fromProfile(Profile $profile)
{
$object = new ActivityObject();

View File

@ -67,10 +67,8 @@ class ImageFile
$info[2] == IMAGETYPE_BMP ||
($info[2] == IMAGETYPE_WBMP && function_exists('imagecreatefromwbmp')) ||
($info[2] == IMAGETYPE_XBM && function_exists('imagecreatefromxbm')) ||
($info[2] == IMAGETYPE_XPM && function_exists('imagecreatefromxpm')) ||
($info[2] == IMAGETYPE_PNG && function_exists('imagecreatefrompng')))) {
@unlink($_FILES[$param]['tmp_name']);
throw new Exception(_('Unsupported image file format.'));
return;
}
@ -161,9 +159,6 @@ class ImageFile
case IMAGETYPE_XBM:
$image_src = imagecreatefromxbm($this->filepath);
break;
case IMAGETYPE_XPM:
$image_src = imagecreatefromxpm($this->filepath);
break;
default:
throw new Exception(_('Unknown file type'));
return;
@ -206,10 +201,6 @@ class ImageFile
//we don't want to save XBM... it's a rare format that we can't guarantee clients will support
//save png instead
$this->type = IMAGETYPE_PNG;
} else if($this->type == IMAGETYPE_XPM) {
//we don't want to save XPM... it's a rare format that we can't guarantee clients will support
//save png instead
$this->type = IMAGETYPE_PNG;
}
$outname = Avatar::filename($this->id,

View File

@ -1403,7 +1403,7 @@ class Ostatus_profile extends Memcached_DataObject
if (array_key_exists('feedurl', $hints)) {
try {
common_log(LOG_INFO, "Discovery on acct:$addr with feed URL $feedUrl");
common_log(LOG_INFO, "Discovery on acct:$addr with feed URL " . $hints['feedurl']);
$oprofile = self::ensureFeedURL($hints['feedurl'], $hints);
self::cacheSet(sprintf('ostatus_profile:webfinger:%s', $addr), $oprofile->uri);
return $oprofile;

View File

@ -65,17 +65,22 @@ class DiscoveryHints {
{
common_debug("starting tidy");
$body = self::_tidy($body);
$body = self::_tidy($body, $url);
common_debug("done with tidy");
set_include_path(get_include_path() . PATH_SEPARATOR . INSTALLDIR . '/plugins/OStatus/extlib/hkit/');
require_once('hkit.class.php');
$h = new hKit;
// hKit code is not clean for notices and warnings
$old = error_reporting();
error_reporting($old & ~E_NOTICE & ~E_WARNING);
$h = new hKit;
$hcards = $h->getByString('hcard', $body);
error_reporting($old);
if (empty($hcards)) {
return array();
}
@ -144,39 +149,61 @@ class DiscoveryHints {
return $hints;
}
private static function _tidy($body)
/**
* hKit needs well-formed XML for its parsing.
* We'll take the HTML body here and normalize it to XML.
*
* @param string $body HTML document source, possibly not-well-formed
* @param string $url source URL
* @return string well-formed XML document source
* @throws Exception if HTML parsing failed.
*/
private static function _tidy($body, $url)
{
if (function_exists('tidy_parse_string')) {
common_debug("Tidying with extension");
$text = tidy_parse_string($body);
$text = tidy_clean_repair($text);
return $body;
} else if ($fullpath = self::_findProgram('tidy')) {
common_debug("Tidying with program $fullpath");
$tempfile = tempnam('/tmp', 'snht'); // statusnet hcard tidy
file_put_contents($tempfile, $source);
exec("$fullpath -utf8 -indent -asxhtml -numeric -bare -quiet $tempfile", $tidy);
unlink($tempfile);
return implode("\n", $tidy);
} else {
common_debug("Not tidying.");
return $body;
if (empty($body)) {
throw new Exception("Empty HTML could not be parsed.");
}
}
$dom = new DOMDocument();
private static function _findProgram($name)
{
$path = $_ENV['PATH'];
// Some HTML errors will trigger warnings, but still work.
$old = error_reporting();
error_reporting($old & ~E_WARNING);
$ok = $dom->loadHTML($body);
$parts = explode(':', $path);
foreach ($parts as $part) {
$fullpath = $part . '/' . $name;
if (is_executable($fullpath)) {
return $fullpath;
error_reporting($old);
if ($ok) {
// hKit doesn't give us a chance to pass the source URL for
// resolving relative links, such as the avatar photo on a
// Google profile. We'll slip it into a <base> tag if there's
// not already one present.
$bases = $dom->getElementsByTagName('base');
if ($bases && $bases->length >= 1) {
$base = $bases->item(0);
if ($base->hasAttribute('href')) {
$base->setAttribute('href', $url);
}
} else {
$base = $dom->createElement('base');
$base->setAttribute('href', $url);
$heads = $dom->getElementsByTagName('head');
if ($heads || $heads->length) {
$head = $heads->item(0);
} else {
$head = $dom->createElement('head');
$root = $dom->documentRoot;
if ($root->firstChild) {
$root->insertBefore($head, $root->firstChild);
} else {
$root->appendChild($head);
}
}
$head->appendChild($base);
}
return $dom->saveXML();
} else {
throw new Exception("Invalid HTML could not be parsed.");
}
return null;
}
}

View File

@ -43,21 +43,21 @@ class LinkHeader
static function getLink($response, $rel=null, $type=null)
{
$headers = $response->getHeader('Link');
if ($headers) {
// Can get an array or string, so try to simplify the path
if (!is_array($headers)) {
$headers = array($headers);
}
// Can get an array or string, so try to simplify the path
if (!is_array($headers)) {
$headers = array($headers);
}
foreach ($headers as $header) {
$lh = new LinkHeader($header);
foreach ($headers as $header) {
$lh = new LinkHeader($header);
if ((is_null($rel) || $lh->rel == $rel) &&
(is_null($type) || $lh->type == $type)) {
return $lh->href;
if ((is_null($rel) || $lh->rel == $rel) &&
(is_null($type) || $lh->type == $type)) {
return $lh->href;
}
}
}
return null;
}
}
}