X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=plugins%2FWikiHowProfile%2FWikiHowProfilePlugin.php;h=6f45da6a707cbbbe8efbafad2736ed94f311c0ab;hb=3d019f91492396f4d27858a80894af74c34bb5b9;hp=b72bd55d6d259ee31f4f31a6d7edbb55b0cf2013;hpb=640e7e7c43fa8e9b1a8516b486e560df84bd9887;p=quix0rs-gnu-social.git diff --git a/plugins/WikiHowProfile/WikiHowProfilePlugin.php b/plugins/WikiHowProfile/WikiHowProfilePlugin.php index b72bd55d6d..6f45da6a70 100644 --- a/plugins/WikiHowProfile/WikiHowProfilePlugin.php +++ b/plugins/WikiHowProfile/WikiHowProfilePlugin.php @@ -47,17 +47,17 @@ if (!defined('STATUSNET')) { * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0 * @link http://status.net/ */ - class WikiHowProfilePlugin extends Plugin { function onPluginVersion(&$versions) { $versions[] = array('name' => 'WikiHow avatar fetcher', - 'version' => STATUSNET_VERSION, + 'version' => GNUSOCIAL_VERSION, 'author' => 'Brion Vibber', 'homepage' => 'http://status.net/wiki/Plugin:Sample', 'rawdescription' => - _m('Fetches avatar and other profile info for WikiHow users when setting up an account via OpenID.')); + // TRANS: Plugin description. + _m('Fetches avatar and other profile information for WikiHow users when setting up an account via OpenID.')); return true; } @@ -107,14 +107,14 @@ class WikiHowProfilePlugin extends Plugin /** * Given a user's WikiHow profile URL, find their avatar. - * + * * @param string $profileUrl user page on the wiki - * + * * @return array of data; possible members: * 'avatar' => full URL to avatar image - * + * * @throws Exception on various low-level failures - * + * * @todo pull location, web site, and about sections -- they aren't currently marked up cleanly. */ private function fetchProfile($profileUrl) @@ -122,7 +122,8 @@ class WikiHowProfilePlugin extends Plugin $client = HTTPClient::start(); $response = $client->get($profileUrl); if (!$response->isOk()) { - throw new Exception("WikiHow profile page fetch failed."); + // TRANS: Exception thrown when fetching a WikiHow profile page fails. + throw new Exception(_m('WikiHow profile page fetch failed.')); // HTTP error response already logged. return false; } @@ -138,7 +139,8 @@ class WikiHowProfilePlugin extends Plugin error_reporting($old); if (!$ok) { - throw new Exception("HTML parse failure during check for WikiHow avatar."); + // TRANS: Exception thrown when parsing a WikiHow profile page fails. + throw new Exception(_m('HTML parse failure during check for WikiHow avatar.')); return false; } @@ -169,28 +171,35 @@ class WikiHowProfilePlugin extends Plugin private function saveAvatar($user, $url) { if (!common_valid_http_url($url)) { - throw new ServerException(sprintf(_m("Invalid avatar URL %s"), $url)); + // TRANS: Server exception thrown when an avatar URL is invalid. + // TRANS: %s is the invalid avatar URL. + throw new ServerException(sprintf(_m('Invalid avatar URL %s.'), $url)); } - // @fixme this should be better encapsulated + // @todo FIXME: This should be better encapsulated // ripped from OStatus via oauthstore.php (for old OMB client) $temp_filename = tempnam(sys_get_temp_dir(), 'listener_avatar'); - if (!copy($url, $temp_filename)) { - throw new ServerException(sprintf(_m("Unable to fetch avatar from %s"), $url)); - } - - $profile = $user->getProfile(); - $id = $profile->id; - // @fixme should we be using different ids? + try { + if (!copy($url, $temp_filename)) { + // TRANS: Exception thrown when fetching an avatar from a URL fails. + // TRANS: %s is a URL. + throw new ServerException(sprintf(_m('Unable to fetch avatar from %s.'), $url)); + } - $imagefile = new ImageFile($id, $temp_filename); - $filename = Avatar::filename($id, - image_type_to_extension($imagefile->type), - null, - common_timestamp()); - rename($temp_filename, Avatar::path($filename)); + $profile = $user->getProfile(); + $id = $profile->id; + // @fixme should we be using different ids? + + $imagefile = new ImageFile($id, $temp_filename); + $filename = Avatar::filename($id, + image_type_to_extension($imagefile->type), + null, + common_timestamp()); + rename($temp_filename, Avatar::path($filename)); + } catch (Exception $e) { + unlink($temp_filename); + throw $e; + } $profile->setOriginal($filename); } - } -