diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/apiaction.php | 9 | ||||
-rw-r--r-- | lib/authenticationplugin.php | 66 | ||||
-rw-r--r-- | lib/authorizationplugin.php | 2 | ||||
-rw-r--r-- | lib/command.php | 29 | ||||
-rw-r--r-- | lib/commandinterpreter.php | 11 | ||||
-rw-r--r-- | lib/default.php | 1 | ||||
-rw-r--r-- | lib/htmloutputter.php | 55 | ||||
-rw-r--r-- | lib/imagefile.php | 135 | ||||
-rw-r--r-- | lib/iomaster.php | 2 | ||||
-rw-r--r-- | lib/queuemanager.php | 6 | ||||
-rw-r--r-- | lib/subs.php | 45 | ||||
-rw-r--r-- | lib/util.php | 17 |
12 files changed, 316 insertions, 62 deletions
diff --git a/lib/apiaction.php b/lib/apiaction.php index 2af150ab9..9bfca3b66 100644 --- a/lib/apiaction.php +++ b/lib/apiaction.php @@ -289,11 +289,12 @@ class ApiAction extends Action $twitter_status['attachments'] = array(); foreach ($attachments as $attachment) { - if ($attachment->isEnclosure()) { + $enclosure_o=$attachment->getEnclosure(); + if ($enclosure_o) { $enclosure = array(); - $enclosure['url'] = $attachment->url; - $enclosure['mimetype'] = $attachment->mimetype; - $enclosure['size'] = $attachment->size; + $enclosure['url'] = $enclosure_o->url; + $enclosure['mimetype'] = $enclosure_o->mimetype; + $enclosure['size'] = $enclosure_o->size; $twitter_status['attachments'][] = $enclosure; } } diff --git a/lib/authenticationplugin.php b/lib/authenticationplugin.php index de479a576..97e9d52de 100644 --- a/lib/authenticationplugin.php +++ b/lib/authenticationplugin.php @@ -69,13 +69,17 @@ abstract class AuthenticationPlugin extends Plugin /** * Automatically register a user when they attempt to login with valid credentials. * User::register($data) is a very useful method for this implementation - * @param username + * @param username username (that is used to login and find the user in the authentication provider) of the user to be registered + * @param nickname nickname of the user in the SN system. If nickname is null, then set nickname = username * @return mixed instance of User, or false (if user couldn't be created) */ - function autoRegister($username) + function autoRegister($username, $nickname = null) { + if(is_null($nickname)){ + $nickname = $username; + } $registration_data = array(); - $registration_data['nickname'] = $username ; + $registration_data['nickname'] = common_nicknamize($nickname); return User::register($registration_data); } @@ -92,6 +96,19 @@ abstract class AuthenticationPlugin extends Plugin return false; } + /** + * Given a username, suggest what the nickname should be + * Used during autoregistration + * Useful if your usernames are ugly, and you want to suggest + * nice looking nicknames when users initially sign on + * @param username + * @return string nickname + */ + function suggestNicknameForUsername($username) + { + return $username; + } + //------------Below are the methods that connect StatusNet to the implementing Auth plugin------------\\ function onInitializePlugin(){ if(!isset($this->provider_name)){ @@ -108,10 +125,22 @@ abstract class AuthenticationPlugin extends Plugin function onAutoRegister($nickname, $provider_name, &$user) { if($provider_name == $this->provider_name && $this->autoregistration){ - $user = $this->autoregister($nickname); - if($user){ - User_username::register($user,$nickname,$this->provider_name); - return false; + $suggested_nickname = $this->suggestNicknameForUsername($nickname); + $test_user = User::staticGet('nickname', $suggested_nickname); + if($test_user) { + //someone already exists with the suggested nickname, so used the passed nickname + $suggested_nickname = $nickname; + } + $test_user = User::staticGet('nickname', $suggested_nickname); + if($test_user) { + //someone already exists with the suggested nickname + //not much else we can do + }else{ + $user = $this->autoRegister($nickname, $suggested_nickname); + if($user){ + User_username::register($user,$nickname,$this->provider_name); + return false; + } } } } @@ -122,23 +151,30 @@ abstract class AuthenticationPlugin extends Plugin $user_username->username=$nickname; $user_username->provider_name=$this->provider_name; if($user_username->find() && $user_username->fetch()){ - $username = $user_username->username; - $authenticated = $this->checkPassword($username, $password); + $authenticated = $this->checkPassword($user_username->username, $password); if($authenticated){ $authenticatedUser = User::staticGet('id', $user_username->user_id); return false; } }else{ - $user = User::staticGet('nickname', $nickname); + //$nickname is the username used to login + //$suggested_nickname is the nickname the auth provider suggests for that username + $suggested_nickname = $this->suggestNicknameForUsername($nickname); + $user = User::staticGet('nickname', $suggested_nickname); if($user){ - //make sure a different provider isn't handling this nickname + //make sure this user isn't claimed $user_username = new User_username(); - $user_username->username=$nickname; - if(!$user_username->find()){ - //no other provider claims this username, so it's safe for us to handle it + $user_username->user_id=$user->id; + $we_can_handle = false; + if($user_username->find()){ + //either this provider, or another one, has already claimed this user + //so we cannot. Let another plugin try. + return; + }else{ + //no other provider claims this user, so it's safe for us to handle it $authenticated = $this->checkPassword($nickname, $password); if($authenticated){ - $authenticatedUser = User::staticGet('nickname', $nickname); + $authenticatedUser = $user; User_username::register($authenticatedUser,$nickname,$this->provider_name); return false; } diff --git a/lib/authorizationplugin.php b/lib/authorizationplugin.php index 733b0c065..07da9b2d1 100644 --- a/lib/authorizationplugin.php +++ b/lib/authorizationplugin.php @@ -85,7 +85,7 @@ abstract class AuthorizationPlugin extends Plugin } function onStartSetApiUser(&$user) { - return $this->onStartSetUser(&$user); + return $this->onStartSetUser($user); } function onStartHasRole($profile, $name, &$has_role) { diff --git a/lib/command.php b/lib/command.php index ea7b60372..db8e80030 100644 --- a/lib/command.php +++ b/lib/command.php @@ -668,6 +668,34 @@ class LoginCommand extends Command } } +class LoseCommand extends Command +{ + + var $other = null; + + function __construct($user, $other) + { + parent::__construct($user); + $this->other = $other; + } + + function execute($channel) + { + if(!$this->other) { + $channel->error($this->user, _('Specify the name of the user to unsubscribe from')); + return; + } + + $result=subs_unsubscribe_from($this->user, $this->other); + + if ($result) { + $channel->output($this->user, sprintf(_('Unsubscribed %s'), $this->other)); + } else { + $channel->error($this->user, $result); + } + } +} + class SubscriptionsCommand extends Command { function execute($channel) @@ -750,6 +778,7 @@ class HelpCommand extends Command "d <nickname> <text> - direct message to user\n". "get <nickname> - get last notice from user\n". "whois <nickname> - get profile info on user\n". + "lose <nickname> - force user to stop following you\n". "fav <nickname> - add user's last notice as a 'fave'\n". "fav #<notice_id> - add notice with the given id as a 'fave'\n". "repeat #<notice_id> - repeat a notice with a given id\n". diff --git a/lib/commandinterpreter.php b/lib/commandinterpreter.php index c2add7299..fbc6174bb 100644 --- a/lib/commandinterpreter.php +++ b/lib/commandinterpreter.php @@ -47,6 +47,17 @@ class CommandInterpreter } else { return new LoginCommand($user); } + case 'lose': + if ($arg) { + list($other, $extra) = $this->split_arg($arg); + if ($extra) { + return null; + } else { + return new LoseCommand($user, $other); + } + } else { + return null; + } case 'subscribers': if ($arg) { return null; diff --git a/lib/default.php b/lib/default.php index d849055c2..b06b96157 100644 --- a/lib/default.php +++ b/lib/default.php @@ -279,6 +279,7 @@ $default = 'Geonames' => null, 'Mapstraction' => null, 'WikiHashtags' => null, + 'RSSCloud' => null, 'OpenID' => null), ), 'admin' => diff --git a/lib/htmloutputter.php b/lib/htmloutputter.php index 7315fe2ad..7786b5941 100644 --- a/lib/htmloutputter.php +++ b/lib/htmloutputter.php @@ -356,40 +356,47 @@ class HTMLOutputter extends XMLOutputter if( empty($url['scheme']) && empty($url['host']) && empty($url['query']) && empty($url['fragment'])) { - $path = common_config('javascript', 'path'); + if (strpos($src, 'plugins/') === 0 || strpos($src, 'local/') === 0) { - if (empty($path)) { - $path = common_config('site', 'path') . '/js/'; - } + $src = common_path($src) . '?version=' . STATUSNET_VERSION; - if ($path[strlen($path)-1] != '/') { - $path .= '/'; - } + }else{ - if ($path[0] != '/') { - $path = '/'.$path; - } + $path = common_config('javascript', 'path'); - $server = common_config('javascript', 'server'); + if (empty($path)) { + $path = common_config('site', 'path') . '/js/'; + } - if (empty($server)) { - $server = common_config('site', 'server'); - } + if ($path[strlen($path)-1] != '/') { + $path .= '/'; + } - $ssl = common_config('javascript', 'ssl'); + if ($path[0] != '/') { + $path = '/'.$path; + } + + $server = common_config('javascript', 'server'); - if (is_null($ssl)) { // null -> guess - if (common_config('site', 'ssl') == 'always' && - !common_config('javascript', 'server')) { - $ssl = true; - } else { - $ssl = false; + if (empty($server)) { + $server = common_config('site', 'server'); } - } - $protocol = ($ssl) ? 'https' : 'http'; + $ssl = common_config('javascript', 'ssl'); - $src = $protocol.'://'.$server.$path.$src . '?version=' . STATUSNET_VERSION; + if (is_null($ssl)) { // null -> guess + if (common_config('site', 'ssl') == 'always' && + !common_config('javascript', 'server')) { + $ssl = true; + } else { + $ssl = false; + } + } + + $protocol = ($ssl) ? 'https' : 'http'; + + $src = $protocol.'://'.$server.$path.$src . '?version=' . STATUSNET_VERSION; + } } $this->element('script', array('type' => $type, diff --git a/lib/imagefile.php b/lib/imagefile.php index 6bc8e599b..7b0479455 100644 --- a/lib/imagefile.php +++ b/lib/imagefile.php @@ -99,6 +99,10 @@ class ImageFile if ($info[2] !== IMAGETYPE_GIF && $info[2] !== IMAGETYPE_JPEG && + $info[2] !== IMAGETYPE_BMP && + $info[2] !== IMAGETYPE_WBMP && + $info[2] !== IMAGETYPE_XBM && + $info[2] !== IMAGETYPE_XPM && $info[2] !== IMAGETYPE_PNG) { @unlink($_FILES[$param]['tmp_name']); @@ -146,6 +150,18 @@ class ImageFile case IMAGETYPE_PNG: $image_src = imagecreatefrompng($this->filepath); break; + case IMAGETYPE_BMP: + $image_src = imagecreatefrombmp($this->filepath); + break; + case IMAGETYPE_WBMP: + $image_src = imagecreatefromwbmp($this->filepath); + break; + 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; @@ -153,7 +169,7 @@ class ImageFile $image_dest = imagecreatetruecolor($size, $size); - if ($this->type == IMAGETYPE_GIF || $this->type == IMAGETYPE_PNG) { + if ($this->type == IMAGETYPE_GIF || $this->type == IMAGETYPE_PNG || $this->type == IMAGETYPE_BMP) { $transparent_idx = imagecolortransparent($image_src); @@ -176,6 +192,24 @@ class ImageFile imagecopyresampled($image_dest, $image_src, 0, 0, $x, $y, $size, $size, $w, $h); + if($this->type == IMAGETYPE_BMP) { + //we don't want to save BMP... it's an inefficient, rare, antiquated format + //save png instead + $this->type = IMAGETYPE_PNG; + } else if($this->type == IMAGETYPE_WBMP) { + //we don't want to save WBMP... 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_XBM) { + //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, image_type_to_extension($this->type), $size, @@ -245,4 +279,101 @@ class ImageFile return $num; } -}
\ No newline at end of file +} + +//PHP doesn't (as of 2/24/2010) have an imagecreatefrombmp so conditionally define one +if(!function_exists('imagecreatefrombmp')){ + //taken shamelessly from http://www.php.net/manual/en/function.imagecreatefromwbmp.php#86214 + function imagecreatefrombmp($p_sFile) + { + // Load the image into a string + $file = fopen($p_sFile,"rb"); + $read = fread($file,10); + while(!feof($file)&&($read<>"")) + $read .= fread($file,1024); + + $temp = unpack("H*",$read); + $hex = $temp[1]; + $header = substr($hex,0,108); + + // Process the header + // Structure: http://www.fastgraph.com/help/bmp_header_format.html + if (substr($header,0,4)=="424d") + { + // Cut it in parts of 2 bytes + $header_parts = str_split($header,2); + + // Get the width 4 bytes + $width = hexdec($header_parts[19].$header_parts[18]); + + // Get the height 4 bytes + $height = hexdec($header_parts[23].$header_parts[22]); + + // Unset the header params + unset($header_parts); + } + + // Define starting X and Y + $x = 0; + $y = 1; + + // Create newimage + $image = imagecreatetruecolor($width,$height); + + // Grab the body from the image + $body = substr($hex,108); + + // Calculate if padding at the end-line is needed + // Divided by two to keep overview. + // 1 byte = 2 HEX-chars + $body_size = (strlen($body)/2); + $header_size = ($width*$height); + + // Use end-line padding? Only when needed + $usePadding = ($body_size>($header_size*3)+4); + + // Using a for-loop with index-calculation instaid of str_split to avoid large memory consumption + // Calculate the next DWORD-position in the body + for ($i=0;$i<$body_size;$i+=3) + { + // Calculate line-ending and padding + if ($x>=$width) + { + // If padding needed, ignore image-padding + // Shift i to the ending of the current 32-bit-block + if ($usePadding) + $i += $width%4; + + // Reset horizontal position + $x = 0; + + // Raise the height-position (bottom-up) + $y++; + + // Reached the image-height? Break the for-loop + if ($y>$height) + break; + } + + // Calculation of the RGB-pixel (defined as BGR in image-data) + // Define $i_pos as absolute position in the body + $i_pos = $i*2; + $r = hexdec($body[$i_pos+4].$body[$i_pos+5]); + $g = hexdec($body[$i_pos+2].$body[$i_pos+3]); + $b = hexdec($body[$i_pos].$body[$i_pos+1]); + + // Calculate and draw the pixel + $color = imagecolorallocate($image,$r,$g,$b); + imagesetpixel($image,$x,$height-$y,$color); + + // Raise the horizontal position + $x++; + } + + // Unset the body / free the memory + unset($body); + + // Return image-object + return $image; + } +} diff --git a/lib/iomaster.php b/lib/iomaster.php index d20837ba5..7cfb2c9a0 100644 --- a/lib/iomaster.php +++ b/lib/iomaster.php @@ -330,7 +330,7 @@ abstract class IoMaster * for per-queue and per-site records. * * @param string $key counter name - * @param array $owners list of owner keys like 'queue:jabber' or 'site:stat01' + * @param array $owners list of owner keys like 'queue:xmpp' or 'site:stat01' */ public function stats($key, $owners=array()) { diff --git a/lib/queuemanager.php b/lib/queuemanager.php index 9fdc80110..87bd356aa 100644 --- a/lib/queuemanager.php +++ b/lib/queuemanager.php @@ -213,7 +213,9 @@ abstract class QueueManager extends IoManager { if (isset($this->handlers[$queue])) { $class = $this->handlers[$queue]; - if (class_exists($class)) { + if(is_object($class)) { + return $class; + } else if (class_exists($class)) { return new $class(); } else { $this->_log(LOG_ERR, "Nonexistent handler class '$class' for queue '$queue'"); @@ -286,7 +288,7 @@ abstract class QueueManager extends IoManager * Only registered transports will be reliably picked up! * * @param string $transport - * @param string $class + * @param string $class class name or object instance * @param string $group */ public function connect($transport, $class, $group='main') diff --git a/lib/subs.php b/lib/subs.php index 1c240c475..e2ce0667e 100644 --- a/lib/subs.php +++ b/lib/subs.php @@ -42,4 +42,47 @@ function subs_unsubscribe_to($user, $other) } catch (Exception $e) { return $e->getMessage(); } -}
\ No newline at end of file +} + +function subs_unsubscribe_from($user, $other){ + $local = User::staticGet("nickname",$other); + if($local){ + return subs_unsubscribe_to($local,$user); + } else { + try { + $remote = Profile::staticGet("nickname",$other); + if(is_string($remote)){ + return $remote; + } + if (Event::handle('StartUnsubscribe', array($remote,$user))) { + + $sub = DB_DataObject::factory('subscription'); + + $sub->subscriber = $remote->id; + $sub->subscribed = $user->id; + + $sub->find(true); + + // note we checked for existence above + + if (!$sub->delete()) + return _('Couldn\'t delete subscription.'); + + $cache = common_memcache(); + + if ($cache) { + $cache->delete(common_cache_key('user:notices_with_friends:' . $remote->id)); + } + + + $user->blowSubscribersCount(); + $remote->blowSubscribersCount(); + + Event::handle('EndUnsubscribe', array($remote, $user)); + } + } catch (Exception $e) { + return $e->getMessage(); + } + } +} + diff --git a/lib/util.php b/lib/util.php index d12a7920d..c7cb4f313 100644 --- a/lib/util.php +++ b/lib/util.php @@ -770,20 +770,13 @@ function common_linkify($url) { } if (!empty($f)) { - if ($f->isEnclosure()) { + if ($f->getEnclosure()) { $is_attachment = true; $attachment_id = $f->id; - } else { - $foe = File_oembed::staticGet('file_id', $f->id); - if (!empty($foe)) { - // if it has OEmbed info, it's an attachment, too - $is_attachment = true; - $attachment_id = $f->id; - - $thumb = File_thumbnail::staticGet('file_id', $f->id); - if (!empty($thumb)) { - $has_thumb = true; - } + + $thumb = File_thumbnail::staticGet('file_id', $f->id); + if (!empty($thumb)) { + $has_thumb = true; } } } |