예제 #1
0
 public function testFileTrait()
 {
     $image = new ImageFile();
     $image->createDirectory('image');
     $image->chmod('image');
     $this->assertFileExists('image');
     @rmdir('image');
 }
예제 #2
0
파일: _info.php 프로젝트: pmvc-plugin/image
 function get(ImageFile $file)
 {
     $path = $file->getPath();
     if (empty($this->_images_info[$path])) {
         $this->_images_info[$path] = getimagesize($path);
     }
     return $this->_images_info[$path];
 }
예제 #3
0
 function setOriginal($filename)
 {
     $imagefile = new ImageFile($this->id, Avatar::path($filename));
     $orig = clone $this;
     $this->original_logo = Avatar::url($filename);
     $this->homepage_logo = Avatar::url($imagefile->resize(AVATAR_PROFILE_SIZE));
     $this->stream_logo = Avatar::url($imagefile->resize(AVATAR_STREAM_SIZE));
     $this->mini_logo = Avatar::url($imagefile->resize(AVATAR_MINI_SIZE));
     common_debug(common_log_objstring($this));
     return $this->update($orig);
 }
예제 #4
0
 public function imageResize($value)
 {
     $resize = new ImageFile($value['tmp_name']);
     if (isset($this->options['params']['type'])) {
         switch ($this->options['params']['type']) {
             case 'getCenter':
                 $resize->centerResize($this->options['params']['save_path'] . $this->options['params']['prefix'] . $value['name'], $this->options['params']['width'], $this->options['params']['height']);
                 break;
         }
     }
     return $value;
 }
 /**
  * @param string $file путь к файлу
  * @return bool|ImageFile
  */
 static function isImage($filename, array $supportedImageTypes = array(IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_JPEG2000, IMAGETYPE_PNG))
 {
     try {
         $image = new ImageFile($filename);
     } catch (Exception $e) {
         return false;
     }
     if (empty($supportedImageTypes) || in_array($image->getType(), $supportedImageTypes)) {
         return $image;
     }
     return false;
 }
예제 #6
0
파일: image.php 프로젝트: hidetobara/voices
 function handle()
 {
     $path = $this->imageInfo->getFilePath($this->size);
     if (!file_exists($path)) {
         throw new VoiceException(CommonMessages::get()->msg('NO_FILE'));
     }
     $ct = ImageFile::type2ContentType($this->imageInfo->type);
     if ($ct) {
         header("Content-type: {$ct}");
     }
     header('Content-Length: ' . filesize($path));
     readfile($path);
 }
예제 #7
0
 function getUpload()
 {
     $imagefile = ImageFile::fromUpload('photo_upload');
     if ($imagefile === null) {
         throw new Exception(_('No file uploaded'));
     }
     $title = $this->trimmed('title');
     $description = $this->trimmed('description');
     $new_filename = UUID::gen() . image_type_to_extension($imagefile->type);
     move_uploaded_file($imagefile->filepath, INSTALLDIR . '/file/' . $new_filename);
     // XXX: we should be using https where we can. TODO: detect whether the server
     // supports this.
     $photo_uri = 'http://' . common_config('site', 'server') . '/file/' . $new_filename;
     $thumb_uri = $photo_uri;
     $photo = Photo::saveNew($profile, $photo_uri, $thumb_uri, $title, $description, $options);
 }
 private function scaleEnlarge($maxwidth, $maxheight)
 {
     $inputWidth = $this->input->getWidth();
     $inputHeight = $this->input->getHeight();
     if ($this->allowEnlargement && $inputWidth < $maxwidth && $inputHeight < $maxheight) {
         // allow enlargements
         if ($maxwidth - $inputWidth > $maxheight - $inputHeight) {
             //enlarge according to height
             $new_height = $maxheight;
             $new_width = $new_height * $inputWidth / $inputHeight;
         } else {
             //enlarge accoring to width
             $new_width = $maxwidth;
             $new_height = $new_width * $inputHeight / $inputWidth;
         }
         return array(round($new_width), round($new_height));
     } else {
         return array($inputWidth, $this->input->getHeight());
     }
 }
예제 #9
0
파일: Profile.php 프로젝트: himmelex/NTW
 function setOriginal($filename)
 {
     $imagefile = new ImageFile($this->id, Avatar::path($filename));
     $avatar = new Avatar();
     $avatar->profile_id = $this->id;
     $avatar->width = $imagefile->width;
     $avatar->height = $imagefile->height;
     $avatar->mediatype = image_type_to_mime_type($imagefile->type);
     $avatar->filename = $filename;
     $avatar->original = true;
     $avatar->url = Avatar::url($filename);
     $avatar->created = DB_DataObject_Cast::dateTime();
     # current time
     # XXX: start a transaction here
     if (!$this->delete_avatars() || !$avatar->insert()) {
         @unlink(Avatar::path($filename));
         return null;
     }
     foreach (array(AVATAR_PROFILE_SIZE, AVATAR_STREAM_SIZE, AVATAR_MINI_SIZE) as $size) {
         # We don't do a scaled one if original is our scaled size
         if (!($avatar->width == $size && $avatar->height == $size)) {
             $scaled_filename = $imagefile->resize($size);
             //$scaled = DB_DataObject::factory('avatar');
             $scaled = new Avatar();
             $scaled->profile_id = $this->id;
             $scaled->width = $size;
             $scaled->height = $size;
             $scaled->original = false;
             $scaled->mediatype = image_type_to_mime_type($imagefile->type);
             $scaled->filename = $scaled_filename;
             $scaled->url = Avatar::url($scaled_filename);
             $scaled->created = DB_DataObject_Cast::dateTime();
             # current time
             if (!$scaled->insert()) {
                 return null;
             }
         }
     }
     return $avatar;
 }
 /**
  * Handle the request
  *
  * Check whether the credentials are valid and output the result
  *
  * @return void
  */
 protected function handle()
 {
     parent::handle();
     // Workaround for PHP returning empty $_POST and $_FILES when POST
     // length > post_max_size in php.ini
     if (empty($_FILES) && empty($_POST) && $_SERVER['CONTENT_LENGTH'] > 0) {
         // TRANS: Client error displayed when the number of bytes in a POST request exceeds a limit.
         // TRANS: %s is the number of bytes of the CONTENT_LENGTH.
         $msg = _m('The server was unable to handle that much POST data (%s byte) due to its current configuration.', 'The server was unable to handle that much POST data (%s bytes) due to its current configuration.', intval($_SERVER['CONTENT_LENGTH']));
         $this->clientError(sprintf($msg, $_SERVER['CONTENT_LENGTH']));
     }
     if (empty($this->user)) {
         // TRANS: Client error displayed updating profile image without having a user object.
         $this->clientError(_('No such user.'), 404);
     }
     try {
         $imagefile = ImageFile::fromUpload('image');
     } catch (Exception $e) {
         $this->clientError($e->getMessage());
     }
     $type = $imagefile->preferredType();
     $filename = Avatar::filename($user->id, image_type_to_extension($type), null, 'tmp' . common_timestamp());
     $filepath = Avatar::path($filename);
     $imagefile->copyTo($filepath);
     $profile = $this->user->getProfile();
     $profile->setOriginal($filename);
     $twitter_user = $this->twitterUserArray($profile, true);
     if ($this->format == 'xml') {
         $this->initDocument('xml');
         $this->showTwitterXmlUser($twitter_user, 'user', true);
         $this->endDocument('xml');
     } elseif ($this->format == 'json') {
         $this->initDocument('json');
         $this->showJsonObjects($twitter_user);
         $this->endDocument('json');
     }
 }
예제 #11
0
 function setAvatar($user)
 {
     try {
         $picUrl = sprintf('http://graph.facebook.com/%d/picture?type=large', $this->fbuser->id);
         // fetch the picture from Facebook
         $client = new HTTPClient();
         // fetch the actual picture
         $response = $client->get($picUrl);
         if ($response->isOk()) {
             // seems to always be jpeg, but not sure
             $tmpname = "facebook-avatar-tmp-" . common_good_rand(4);
             $ok = file_put_contents(Avatar::path($tmpname), $response->getBody());
             if (!$ok) {
                 common_log(LOG_WARNING, 'Couldn\'t save tmp Facebook avatar: ' . $tmpname, __FILE__);
             } else {
                 // save it as an avatar
                 $file = new ImageFile($user->id, Avatar::path($tmpname));
                 $filename = $file->resize(180);
                 // size of the biggest img we get from Facebook
                 $profile = $user->getProfile();
                 if ($profile->setOriginal($filename)) {
                     common_log(LOG_INFO, sprintf('Saved avatar for %s (%d) from Facebook picture for ' . '%s (fbuid %d), filename = %s', $user->nickname, $user->id, $this->fbuser->name, $this->fbuid, $filename), __FILE__);
                     // clean up tmp file
                     @unlink(Avatar::path($tmpname));
                 }
             }
         }
     } catch (Exception $e) {
         common_log(LOG_WARNING, 'Couldn\'t save Facebook avatar: ' . $e->getMessage(), __FILE__);
         // error isn't fatal, continue
     }
 }
예제 #12
0
 /**
  * Add stuff to notices in API responses
  *
  * @param Action $action action being executed
  *
  * @return boolean hook return
  */
 function onNoticeSimpleStatusArray($notice, &$twitter_status, $scoped)
 {
     // groups
     $notice_groups = $notice->getGroups();
     $group_addressees = false;
     foreach ($notice_groups as $g) {
         $group_addressees[] = array('nickname' => $g->nickname, 'url' => $g->mainpage);
     }
     $twitter_status['statusnet_in_groups'] = $group_addressees;
     // for older verions of gnu social: include the repeat-id, which we need when unrepeating later
     if (array_key_exists('repeated', $twitter_status) && $twitter_status['repeated'] === true) {
         $repeated = Notice::pkeyGet(array('profile_id' => $scoped->id, 'repeat_of' => $notice->id, 'verb' => 'http://activitystrea.ms/schema/1.0/share'));
         $twitter_status['repeated_id'] = $repeated->id;
     }
     // more metadata about attachments
     // get all attachments first, and put all the extra meta data in an array
     $attachments = $notice->attachments();
     $attachment_url_to_id = array();
     if (!empty($attachments)) {
         foreach ($attachments as $attachment) {
             if (is_object($attachment)) {
                 try {
                     $enclosure_o = $attachment->getEnclosure();
                     // add id to all attachments
                     $attachment_url_to_id[$enclosure_o->url]['id'] = $attachment->id;
                     // add data about thumbnails
                     $thumb = $attachment->getThumbnail();
                     $large_thumb = $attachment->getThumbnail(1000, 3000, false);
                     if (method_exists('File_thumbnail', 'url')) {
                         $thumb_url = File_thumbnail::url($thumb->filename);
                         $large_thumb_url = File_thumbnail::url($large_thumb->filename);
                     } else {
                         $thumb_url = $thumb->getUrl();
                         $large_thumb_url = $large_thumb->getUrl();
                     }
                     $attachment_url_to_id[$enclosure_o->url]['thumb_url'] = $thumb_url;
                     $attachment_url_to_id[$enclosure_o->url]['large_thumb_url'] = $large_thumb_url;
                     $attachment_url_to_id[$enclosure_o->url]['width'] = $attachment->width;
                     $attachment_url_to_id[$enclosure_o->url]['height'] = $attachment->height;
                     // animated gif?
                     if ($attachment->mimetype == 'image/gif') {
                         $image = ImageFile::fromFileObject($attachment);
                         if ($image->animated == 1) {
                             $attachment_url_to_id[$enclosure_o->url]['animated'] = true;
                         } else {
                             $attachment_url_to_id[$enclosure_o->url]['animated'] = false;
                         }
                     }
                     // this applies to older versions of gnu social, i think
                 } catch (ServerException $e) {
                     $thumb = File_thumbnail::getKV('file_id', $attachment->id);
                     if ($thumb instanceof File_thumbnail) {
                         $thumb_url = $thumb->getUrl();
                         $attachment_url_to_id[$enclosure_o->url]['id'] = $attachment->id;
                         $attachment_url_to_id[$enclosure_o->url]['thumb_url'] = $thumb_url;
                         $attachment_url_to_id[$enclosure_o->url]['large_thumb_url'] = $thumb_url;
                         $attachment_url_to_id[$enclosure_o->url]['width'] = $attachment->width;
                         $attachment_url_to_id[$enclosure_o->url]['height'] = $attachment->height;
                         // animated gif?
                         if ($attachment->mimetype == 'image/gif') {
                             $image = ImageFile::fromFileObject($attachment);
                             if ($image->animated == 1) {
                                 $attachment_url_to_id[$enclosure_o->url]['animated'] = true;
                             } else {
                                 $attachment_url_to_id[$enclosure_o->url]['animated'] = false;
                             }
                         }
                     }
                 }
             }
         }
     }
     // add the extra meta data to $twitter_status
     if (!empty($twitter_status['attachments'])) {
         foreach ($twitter_status['attachments'] as &$attachment) {
             if (!empty($attachment_url_to_id[$attachment['url']])) {
                 $attachment = array_merge($attachment, $attachment_url_to_id[$attachment['url']]);
             }
         }
     }
     // quoted notices
     if (!empty($twitter_status['attachments'])) {
         foreach ($twitter_status['attachments'] as &$attachment) {
             $quoted_notice = false;
             // if this attachment has an url this might be a notice url
             if (isset($attachment['url'])) {
                 $noticeurl = common_path('notice/', StatusNet::isHTTPS());
                 $instanceurl = common_path('', StatusNet::isHTTPS());
                 // remove protocol for the comparison below
                 $noticeurl_wo_protocol = preg_replace('(^https?://)', '', $noticeurl);
                 $instanceurl_wo_protocol = preg_replace('(^https?://)', '', $instanceurl);
                 $attachment_url_wo_protocol = preg_replace('(^https?://)', '', $attachment['url']);
                 // local notice urls
                 if (strpos($attachment_url_wo_protocol, $noticeurl_wo_protocol) === 0) {
                     $possible_notice_id = str_replace($noticeurl_wo_protocol, '', $attachment_url_wo_protocol);
                     if (ctype_digit($possible_notice_id)) {
                         $quoted_notice = Notice::getKV('id', $possible_notice_id);
                     }
                 } elseif (strpos($attachment_url_wo_protocol, $instanceurl_wo_protocol) !== 0 && stristr($attachment_url_wo_protocol, '/notice/')) {
                     $quoted_notice = Notice::getKV('url', $attachment['url']);
                     // try with http<->https if no match. applies to quitter.se notices mostly
                     if (!$quoted_notice instanceof Notice) {
                         if (strpos($attachment['url'], 'https://') === 0) {
                             $quoted_notice = Notice::getKV('url', str_replace('https://', 'http://', $attachment['url']));
                         } else {
                             $quoted_notice = Notice::getKV('url', str_replace('http://', 'https://', $attachment['url']));
                         }
                     }
                 }
                 // include the quoted notice in the attachment
                 if ($quoted_notice instanceof Notice) {
                     $quoted_notice_author = Profile::getKV('id', $quoted_notice->profile_id);
                     if ($quoted_notice_author instanceof Profile) {
                         $attachment['quoted_notice']['id'] = $quoted_notice->id;
                         $attachment['quoted_notice']['content'] = $quoted_notice->content;
                         $attachment['quoted_notice']['nickname'] = $quoted_notice_author->nickname;
                         $attachment['quoted_notice']['fullname'] = $quoted_notice_author->fullname;
                         $quoted_notice_attachments = $quoted_notice->attachments();
                         foreach ($quoted_notice_attachments as $q_attach) {
                             if (is_object($q_attach)) {
                                 try {
                                     $qthumb = $q_attach->getThumbnail();
                                     if (method_exists('File_thumbnail', 'url')) {
                                         $thumb_url = File_thumbnail::url($qthumb->filename);
                                     } else {
                                         $thumb_url = $qthumb->getUrl();
                                     }
                                     $attachment['quoted_notice']['attachments'][] = array('thumb_url' => $thumb_url, 'attachment_id' => $q_attach->id);
                                 } catch (Exception $e) {
                                     common_debug('Qvitter: could not get thumbnail for attachment id=' . $q_attach->id . ' in quoted notice id=' . $quoted_notice->id);
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     try {
         $twitter_status['external_url'] = $notice->getUrl(true);
     } catch (InvalidUrlException $e) {
         common_debug('Qvitter: No URL available for external notice: id=' . $notice->id);
     }
     // reply-to profile url
     try {
         $reply = $notice->getParent();
         $twitter_status['in_reply_to_profileurl'] = $reply->getProfile()->getUrl();
     } catch (ServerException $e) {
         $twitter_status['in_reply_to_profileurl'] = null;
     }
     // fave number
     $faves = Fave::byNotice($notice);
     $favenum = count($faves);
     $twitter_status['fave_num'] = $favenum;
     // repeat number
     $repeats = $notice->repeatStream();
     $repeatnum = 0;
     while ($repeats->fetch()) {
         if ($repeats->verb == ActivityVerb::SHARE) {
             // i.e. not deleted repeats
             $repeatnum++;
         }
     }
     $twitter_status['repeat_num'] = $repeatnum;
     // is this a post? (previously is_activity)
     if (method_exists('ActivityUtils', 'compareVerbs')) {
         $twitter_status['is_post_verb'] = ActivityUtils::compareVerbs($notice->verb, array(ActivityVerb::POST));
     } else {
         $twitter_status['is_post_verb'] = $notice->verb == ActivityVerb::POST ? true : false;
     }
     // some more metadata about notice
     if ($notice->is_local == '1') {
         $twitter_status['is_local'] = true;
     } else {
         $twitter_status['is_local'] = false;
         if ($twitter_status['is_post_verb'] === true) {
             try {
                 $twitter_status['external_url'] = $notice->getUrl(true);
             } catch (InvalidUrlException $e) {
                 common_debug('Qvitter: No URL available for external notice: id=' . $notice->id);
             }
         }
     }
     if (ActivityUtils::compareTypes($notice->verb, array('qvitter-delete-notice', 'delete'))) {
         $twitter_status['qvitter_delete_notice'] = true;
     }
     return true;
 }
예제 #13
0
 public function testGetITXtChunkFromKeyMatch()
 {
     $png = new ImageFile(__DIR__ . self::TEST_ITXT_IMAGE_PATH);
     $matches = $png->getITXtChunksFromKey('openbadges');
     $this->assertCount(1, $matches);
 }
 /**
  * Handle an image upload
  *
  * Does all the magic for handling an image upload, and crops the
  * image by default.
  *
  * @return void
  */
 function uploadLogo()
 {
     if ($_FILES['app_icon']['error'] == UPLOAD_ERR_OK) {
         try {
             $imagefile = ImageFile::fromUpload('app_icon');
         } catch (Exception $e) {
             common_debug("damn that sucks");
             $this->showForm($e->getMessage());
             return;
         }
         $filename = Avatar::filename($this->id, image_type_to_extension($imagefile->type), null, 'oauth-app-icon-' . common_timestamp());
         $filepath = Avatar::path($filename);
         move_uploaded_file($imagefile->filepath, $filepath);
         $this->setOriginal($filename);
     }
 }
예제 #15
0
 /**
  * Handle the results of jcrop.
  *
  * @return void
  */
 function cropAvatar()
 {
     $filedata = $_SESSION['FILEDATA'];
     if (!$filedata) {
         $this->serverError(_('Lost our file data.'));
         return;
     }
     $file_d = $filedata['width'] > $filedata['height'] ? $filedata['height'] : $filedata['width'];
     $dest_x = $this->arg('avatar_crop_x') ? $this->arg('avatar_crop_x') : 0;
     $dest_y = $this->arg('avatar_crop_y') ? $this->arg('avatar_crop_y') : 0;
     $dest_w = $this->arg('avatar_crop_w') ? $this->arg('avatar_crop_w') : $file_d;
     $dest_h = $this->arg('avatar_crop_h') ? $this->arg('avatar_crop_h') : $file_d;
     $size = min($dest_w, $dest_h, MAX_ORIGINAL);
     $user = common_current_user();
     $profile = $user->getProfile();
     $imagefile = new ImageFile($user->id, $filedata['filepath']);
     $filename = $imagefile->resize($size, $dest_x, $dest_y, $dest_w, $dest_h);
     if ($profile->setOriginal($filename)) {
         @unlink($filedata['filepath']);
         unset($_SESSION['FILEDATA']);
         $this->mode = 'upload';
         $this->showForm(_('Avatar updated.'), true);
         common_broadcast_profile($profile);
     } else {
         $this->showForm(_('Failed updating avatar.'));
     }
 }
예제 #16
0
 /**
  * Generate and store a thumbnail image for the uploaded file, if applicable.
  *
  * @return File_thumbnail or null
  */
 function storeThumbnail()
 {
     if (substr($this->mimetype, 0, strlen('image/')) != 'image/') {
         // @fixme video thumbs would be nice!
         return null;
     }
     try {
         $image = new ImageFile($this->fileRecord->id, File::path($this->filename));
     } catch (Exception $e) {
         // Unsupported image type.
         return null;
     }
     $outname = File::filename($this->user->getProfile(), 'thumb-' . $this->filename, $this->mimetype);
     $outpath = File::path($outname);
     $maxWidth = common_config('attachments', 'thumb_width');
     $maxHeight = common_config('attachments', 'thumb_height');
     list($width, $height) = $this->scaleToFit($image->width, $image->height, $maxWidth, $maxHeight);
     $image->resizeTo($outpath, $width, $height);
     File_thumbnail::saveThumbnail($this->fileRecord->id, File::url($outname), $width, $height);
 }
예제 #17
0
 static function maxFileSizeInt()
 {
     return min(ImageFile::strToInt(ini_get('post_max_size')), ImageFile::strToInt(ini_get('upload_max_filesize')), ImageFile::strToInt(ini_get('memory_limit')));
 }
예제 #18
0
 /**
  * Handle the results of jcrop.
  *
  * @return void
  */
 function cropAvatar()
 {
     $filedata = $_SESSION['FILEDATA'];
     if (!$filedata) {
         // TRANS: Server error displayed if an avatar upload went wrong somehow server side.
         $this->serverError(_('Lost our file data.'));
         return;
     }
     $file_d = $filedata['width'] > $filedata['height'] ? $filedata['height'] : $filedata['width'];
     $dest_x = $this->arg('avatar_crop_x') ? $this->arg('avatar_crop_x') : 0;
     $dest_y = $this->arg('avatar_crop_y') ? $this->arg('avatar_crop_y') : 0;
     $dest_w = $this->arg('avatar_crop_w') ? $this->arg('avatar_crop_w') : $file_d;
     $dest_h = $this->arg('avatar_crop_h') ? $this->arg('avatar_crop_h') : $file_d;
     $size = min($dest_w, $dest_h, MAX_ORIGINAL);
     $user = common_current_user();
     $profile = $user->getProfile();
     $imagefile = new ImageFile($user->id, $filedata['filepath']);
     $filename = $imagefile->resize($size, $dest_x, $dest_y, $dest_w, $dest_h);
     if ($profile->setOriginal($filename)) {
         @unlink($filedata['filepath']);
         unset($_SESSION['FILEDATA']);
         $this->mode = 'upload';
         // TRANS: Success message for having updated a user avatar.
         $this->showForm(_('Avatar updated.'), true);
         common_broadcast_profile($profile);
     } else {
         // TRANS: Error displayed on the avatar upload page if the avatar could not be updated for an unknown reason.
         $this->showForm(_('Failed updating avatar.'));
     }
 }
예제 #19
0
 /**
  * Handle the results of jcrop.
  *
  * @return void
  */
 function cropLogo()
 {
     $filedata = $_SESSION['FILEDATA'];
     if (!$filedata) {
         // TRANS: Server error displayed trying to crop an uploaded group logo that is no longer present.
         $this->serverError(_('Lost our file data.'));
         return;
     }
     // If image is not being cropped assume pos & dimentions of original
     $dest_x = $this->arg('avatar_crop_x') ? $this->arg('avatar_crop_x') : 0;
     $dest_y = $this->arg('avatar_crop_y') ? $this->arg('avatar_crop_y') : 0;
     $dest_w = $this->arg('avatar_crop_w') ? $this->arg('avatar_crop_w') : $filedata['width'];
     $dest_h = $this->arg('avatar_crop_h') ? $this->arg('avatar_crop_h') : $filedata['height'];
     $size = min($dest_w, $dest_h);
     $size = $size > MAX_ORIGINAL ? MAX_ORIGINAL : $size;
     $imagefile = new ImageFile($this->group->id, $filedata['filepath']);
     $filename = $imagefile->resize($size, $dest_x, $dest_y, $dest_w, $dest_h);
     if ($this->group->setOriginal($filename)) {
         @unlink($filedata['filepath']);
         unset($_SESSION['FILEDATA']);
         $this->mode = 'upload';
         // TRANS: Form success message after updating a group logo.
         $this->showForm(_('Logo updated.'), true);
     } else {
         // TRANS: Form failure message after failing to update a group logo.
         $this->showForm(_('Failed updating logo.'));
     }
 }
 /**
  * Add stuff to notices in API responses
  *
  * @param Action $action action being executed
  *
  * @return boolean hook return
  */
 function onNoticeSimpleStatusArray($notice, &$twitter_status, $scoped)
 {
     // groups
     $notice_groups = $notice->getGroups();
     $group_addressees = false;
     foreach ($notice_groups as $g) {
         $group_addressees[] = array('nickname' => $g->nickname, 'url' => $g->mainpage);
     }
     $twitter_status['statusnet_in_groups'] = $group_addressees;
     // for older verions of gnu social: include the repeat-id, which we need when unrepeating later
     if (array_key_exists('repeated', $twitter_status) && $twitter_status['repeated'] === true) {
         $repeated = Notice::pkeyGet(array('profile_id' => $scoped->id, 'repeat_of' => $notice->id, 'verb' => 'http://activitystrea.ms/schema/1.0/share'));
         $twitter_status['repeated_id'] = $repeated->id;
     }
     // more metadata about attachments
     // get all attachments first, and put all the extra meta data in an array
     $attachments = $notice->attachments();
     $attachment_url_to_id = array();
     if (!empty($attachments)) {
         foreach ($attachments as $attachment) {
             if (is_object($attachment)) {
                 try {
                     $enclosure_o = $attachment->getEnclosure();
                     // Oembed
                     if (array_key_exists('Oembed', StatusNet::getActivePlugins())) {
                         $oembed = File_oembed::getKV('file_id', $attachment->id);
                         if ($oembed instanceof File_oembed) {
                             $oembed_html = str_replace('&lt;!--//--&gt;', '', $oembed->html);
                             // trash left of wordpress' javascript after htmLawed removed the tags
                             if ($oembed->provider == 'Twitter' && strstr($oembed_html, '>&mdash; ' . $oembed->author_name)) {
                                 $oembed_html = substr($oembed_html, 0, strpos($oembed_html, '>&mdash; ' . $oembed->author_name) + 1);
                                 // remove user data from twitter oembed html (we have it in )
                                 $twitter_username = substr($oembed->html, strpos($oembed->html, '>&mdash; ' . $oembed->author_name) + strlen('>&mdash; ' . $oembed->author_name));
                                 $twitter_username = substr($twitter_username, strpos($twitter_username, '(@') + 1);
                                 $twitter_username = substr($twitter_username, 0, strpos($twitter_username, ')'));
                                 $oembed->title = $twitter_username;
                             }
                             $oembed_html = str_replace('&#8230;', '...', $oembed_html);
                             // ellipsis is sometimes stored as html in db, for some reason
                             $oembed_html = mb_substr(trim(strip_tags(html_entity_decode($oembed_html, ENT_QUOTES))), 0, 250);
                             // sometimes we have html charachters that we want to decode and then strip
                             $oembed_title = trim(strip_tags(html_entity_decode($oembed->title, ENT_QUOTES)));
                             $oembed_provider = trim(strip_tags(html_entity_decode($oembed->provider, ENT_QUOTES)));
                             $oembed_author_name = trim(strip_tags(html_entity_decode($oembed->author_name, ENT_QUOTES)));
                             $attachment_url_to_id[$enclosure_o->url]['oembed'] = array('type' => $oembed->type, 'provider' => $oembed_provider, 'provider_url' => $oembed->provider_url, 'oembedHTML' => $oembed_html, 'title' => $oembed_title, 'author_name' => $oembed_author_name, 'author_url' => $oembed->author_url);
                         } else {
                             $attachment_url_to_id[$enclosure_o->url]['oembed'] = false;
                         }
                     }
                     // add id to all attachments
                     $attachment_url_to_id[$enclosure_o->url]['id'] = $attachment->id;
                     // add an attachment version to all attachments
                     // this means we can force all cached attachments to update, if we change this
                     $attachment_url_to_id[$enclosure_o->url]['version'] = '1.2';
                     // add data about thumbnails
                     $thumb = $attachment->getThumbnail();
                     $large_thumb = $attachment->getThumbnail(1000, 3000, false);
                     if (method_exists('File_thumbnail', 'url')) {
                         $thumb_url = File_thumbnail::url($thumb->filename);
                         $large_thumb_url = File_thumbnail::url($large_thumb->filename);
                     } else {
                         $thumb_url = $thumb->getUrl();
                         $large_thumb_url = $large_thumb->getUrl();
                     }
                     $attachment_url_to_id[$enclosure_o->url]['thumb_url'] = $thumb_url;
                     $attachment_url_to_id[$enclosure_o->url]['large_thumb_url'] = $large_thumb_url;
                     $attachment_url_to_id[$enclosure_o->url]['width'] = $attachment->width;
                     $attachment_url_to_id[$enclosure_o->url]['height'] = $attachment->height;
                     // animated gif?
                     if ($attachment->mimetype == 'image/gif') {
                         $image = ImageFile::fromFileObject($attachment);
                         if ($image->animated == 1) {
                             $attachment_url_to_id[$enclosure_o->url]['animated'] = true;
                         } else {
                             $attachment_url_to_id[$enclosure_o->url]['animated'] = false;
                         }
                     }
                     // this applies to older versions of gnu social, i think
                 } catch (Exception $e) {
                     $thumb = File_thumbnail::getKV('file_id', $attachment->id);
                     if ($thumb instanceof File_thumbnail) {
                         $thumb_url = $thumb->getUrl();
                         $attachment_url_to_id[$enclosure_o->url]['id'] = $attachment->id;
                         $attachment_url_to_id[$enclosure_o->url]['thumb_url'] = $thumb_url;
                         $attachment_url_to_id[$enclosure_o->url]['large_thumb_url'] = $thumb_url;
                         $attachment_url_to_id[$enclosure_o->url]['width'] = $attachment->width;
                         $attachment_url_to_id[$enclosure_o->url]['height'] = $attachment->height;
                         // animated gif?
                         if ($attachment->mimetype == 'image/gif') {
                             $image = ImageFile::fromFileObject($attachment);
                             if ($image->animated == 1) {
                                 $attachment_url_to_id[$enclosure_o->url]['animated'] = true;
                             } else {
                                 $attachment_url_to_id[$enclosure_o->url]['animated'] = false;
                             }
                         }
                     }
                 }
             }
         }
     }
     // add the extra meta data to $twitter_status
     if (!empty($twitter_status['attachments'])) {
         foreach ($twitter_status['attachments'] as &$attachment) {
             if (!empty($attachment_url_to_id[$attachment['url']])) {
                 $attachment = array_merge($attachment, $attachment_url_to_id[$attachment['url']]);
             }
         }
     }
     // quoted notices
     if (!empty($twitter_status['attachments'])) {
         foreach ($twitter_status['attachments'] as &$attachment) {
             $quoted_notice = false;
             // if this attachment has an url this might be a notice url
             if (isset($attachment['url'])) {
                 $noticeurl = common_path('notice/', StatusNet::isHTTPS());
                 $instanceurl = common_path('', StatusNet::isHTTPS());
                 // remove protocol for the comparison below
                 $noticeurl_wo_protocol = preg_replace('(^https?://)', '', $noticeurl);
                 $instanceurl_wo_protocol = preg_replace('(^https?://)', '', $instanceurl);
                 $attachment_url_wo_protocol = preg_replace('(^https?://)', '', $attachment['url']);
                 // local notice urls
                 if (strpos($attachment_url_wo_protocol, $noticeurl_wo_protocol) === 0) {
                     $possible_notice_id = str_replace($noticeurl_wo_protocol, '', $attachment_url_wo_protocol);
                     if (ctype_digit($possible_notice_id)) {
                         $quoted_notice = Notice::getKV('id', $possible_notice_id);
                     }
                 } elseif (strpos($attachment_url_wo_protocol, $instanceurl_wo_protocol) !== 0 && stristr($attachment_url_wo_protocol, '/notice/')) {
                     $quoted_notice = Notice::getKV('url', $attachment['url']);
                     // try with http<->https if no match. applies to quitter.se notices mostly
                     if (!$quoted_notice instanceof Notice) {
                         if (strpos($attachment['url'], 'https://') === 0) {
                             $quoted_notice = Notice::getKV('url', str_replace('https://', 'http://', $attachment['url']));
                         } else {
                             $quoted_notice = Notice::getKV('url', str_replace('http://', 'https://', $attachment['url']));
                         }
                     }
                 }
                 // include the quoted notice in the attachment
                 if ($quoted_notice instanceof Notice) {
                     $quoted_notice_author = Profile::getKV('id', $quoted_notice->profile_id);
                     if ($quoted_notice_author instanceof Profile) {
                         $attachment['quoted_notice']['id'] = $quoted_notice->id;
                         $attachment['quoted_notice']['content'] = $quoted_notice->content;
                         $attachment['quoted_notice']['nickname'] = $quoted_notice_author->nickname;
                         $attachment['quoted_notice']['fullname'] = $quoted_notice_author->fullname;
                         $attachment['quoted_notice']['is_local'] = $quoted_notice_author->isLocal();
                         $quoted_notice_attachments = $quoted_notice->attachments();
                         foreach ($quoted_notice_attachments as $q_attach) {
                             if (is_object($q_attach)) {
                                 try {
                                     $qthumb = $q_attach->getThumbnail();
                                     if (method_exists('File_thumbnail', 'url')) {
                                         $thumb_url = File_thumbnail::url($qthumb->filename);
                                     } else {
                                         $thumb_url = $qthumb->getUrl();
                                     }
                                     $attachment['quoted_notice']['attachments'][] = array('thumb_url' => $thumb_url, 'attachment_id' => $q_attach->id);
                                 } catch (Exception $e) {
                                     common_debug('Qvitter: could not get thumbnail for attachment id=' . $q_attach->id . ' in quoted notice id=' . $quoted_notice->id);
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     try {
         $twitter_status['external_url'] = $notice->getUrl(true);
     } catch (InvalidUrlException $e) {
         common_debug('Qvitter: No URL available for external notice: id=' . $notice->id);
     }
     // reply-to profile url
     try {
         $reply = $notice->getParent();
         $twitter_status['in_reply_to_profileurl'] = $reply->getProfile()->getUrl();
     } catch (ServerException $e) {
         $twitter_status['in_reply_to_profileurl'] = null;
     }
     // fave number
     $faves = Fave::byNotice($notice);
     $favenum = count($faves);
     $twitter_status['fave_num'] = $favenum;
     // repeat number
     $repeats = $notice->repeatStream();
     $repeatnum = 0;
     while ($repeats->fetch()) {
         if ($repeats->verb == ActivityVerb::SHARE) {
             // i.e. not deleted repeats
             $repeatnum++;
         }
     }
     $twitter_status['repeat_num'] = $repeatnum;
     // is this a post? (previously is_activity)
     if (method_exists('ActivityUtils', 'compareVerbs')) {
         $twitter_status['is_post_verb'] = ActivityUtils::compareVerbs($notice->verb, array(ActivityVerb::POST));
     } else {
         $twitter_status['is_post_verb'] = $notice->verb == ActivityVerb::POST ? true : false;
     }
     // some more metadata about notice
     if ($notice->is_local == '1') {
         $twitter_status['is_local'] = true;
     } else {
         $twitter_status['is_local'] = false;
         if ($twitter_status['is_post_verb'] === true) {
             try {
                 $twitter_status['external_url'] = $notice->getUrl(true);
             } catch (InvalidUrlException $e) {
                 common_debug('Qvitter: No URL available for external notice: id=' . $notice->id);
             }
         }
     }
     if (ActivityUtils::compareTypes($notice->verb, array('qvitter-delete-notice', 'delete'))) {
         $twitter_status['qvitter_delete_notice'] = true;
     }
     return true;
 }
예제 #21
0
 function setting($section, $key)
 {
     $result = common_config($section, $key);
     if ($key == 'file_quota') {
         // hack: adjust for the live upload limit
         if (common_config($section, 'uploads')) {
             $max = ImageFile::maxFileSizeInt();
         } else {
             $max = 0;
         }
         return min($result, $max);
     }
     return $result;
 }
 /**
  * Handle the request
  *
  * @return void
  */
 protected function handle()
 {
     parent::handle();
     $profile = $this->user->getProfile();
     $base64img = $this->img;
     if (stristr($base64img, 'image/jpeg')) {
         $base64img_mime = 'image/jpeg';
     } elseif (stristr($base64img, 'image/png')) {
         // should convert to jpg here!!
         $base64img_mime = 'image/png';
     }
     $base64img = str_replace('data:image/jpeg;base64,', '', $base64img);
     $base64img = str_replace('data:image/png;base64,', '', $base64img);
     $base64img = str_replace(' ', '+', $base64img);
     $base64img_hash = md5($base64img);
     $base64img = base64_decode($base64img);
     $base64img_basename = basename('bg');
     $base64img_filename = File::filename($profile, $base64img_basename, $base64img_mime);
     $base64img_path = File::path($base64img_filename);
     $base64img_success = file_put_contents($base64img_path, $base64img);
     $base64img_mimetype = MediaFile::getUploadedMimeType($base64img_path, $base64img_filename);
     $mediafile = new MediaFile($profile, $base64img_filename, $base64img_mimetype);
     $imagefile = new ImageFile($mediafile->fileRecord->id, File::path($mediafile->filename));
     $imagefile->resizeTo(File::path($mediafile->filename), array('width' => 1280, 'height' => 1280, 'x' => $this->cropX, 'y' => $this->cropY, 'w' => $this->cropW, 'h' => $this->cropH));
     $result['url'] = File::url($mediafile->filename);
     Profile_prefs::setData($profile, 'qvitter', 'background_image', $result['url']);
     $this->initDocument('json');
     $this->showJsonObjects($result);
     $this->endDocument('json');
 }
예제 #23
0
 public function testGetRectanglesToResize_correctScaleWithoutCrop()
 {
     list($srcRectangle, $trgRectangle) = ImageFile::getRectanglesToResize(array(400, 400), array(200, 100), false, true, array(0, 0));
     self::assertEquals($srcRectangle->width, 400);
     self::assertEquals($srcRectangle->height, 400);
     self::assertEquals($srcRectangle->x, 0);
     self::assertEquals($srcRectangle->y, 0);
     self::assertEquals($trgRectangle->width, 100);
     self::assertEquals($trgRectangle->height, 100);
     self::assertEquals($trgRectangle->x, 0);
     self::assertEquals($trgRectangle->y, 0);
 }
 /**
  * Handle the request
  *
  * @return void
  */
 protected function handle()
 {
     parent::handle();
     $profile = $this->user->getProfile();
     $base64img = $this->img;
     if (stristr($base64img, 'image/jpeg')) {
         $base64img_mime = 'image/jpeg';
     } elseif (stristr($base64img, 'image/png')) {
         // should convert to jpg here!!
         $base64img_mime = 'image/png';
     }
     $base64img = str_replace('data:image/jpeg;base64,', '', $base64img);
     $base64img = str_replace('data:image/png;base64,', '', $base64img);
     $base64img = str_replace(' ', '+', $base64img);
     $base64img_hash = md5($base64img);
     $base64img = base64_decode($base64img);
     $base64img_basename = basename('avatar');
     $base64img_filename = File::filename($profile, $base64img_basename, $base64img_mime);
     $base64img_path = File::path($base64img_filename);
     $base64img_success = file_put_contents($base64img_path, $base64img);
     $base64img_mimetype = MediaFile::getUploadedMimeType($base64img_path, $base64img_filename);
     $mediafile = new MediaFile($profile, $base64img_filename, $base64img_mimetype);
     $imagefile = new ImageFile($mediafile->fileRecord->id, File::path($mediafile->filename));
     $imagefile->resizeTo(File::path($mediafile->filename), array('width' => $this->cropW, 'height' => $this->cropH, 'x' => $this->cropX, 'y' => $this->cropY, 'w' => $this->cropW, 'h' => $this->cropH));
     $type = $imagefile->preferredType();
     $filename = Avatar::filename($profile->id, image_type_to_extension($type), null, common_timestamp());
     $filepath = Avatar::path($filename);
     $imagefile->copyTo($filepath);
     $profile = $this->user->getProfile();
     $profile->setOriginal($filename);
     $mediafile->delete();
     $twitter_user = $this->twitterUserArray($profile, true);
     $this->initDocument('json');
     $this->showJsonObjects($twitter_user);
     $this->endDocument('json');
 }
예제 #25
0
 /**
  * Add stuff to notices in API responses
  *
  * @param Action $action action being executed
  *
  * @return boolean hook return
  */
 function onNoticeSimpleStatusArray($notice, &$twitter_status, $scoped)
 {
     // groups
     $notice_groups = $notice->getGroups();
     $group_addressees = false;
     foreach ($notice_groups as $g) {
         $group_addressees[] = array('nickname' => $g->nickname, 'url' => $g->mainpage);
     }
     $twitter_status['statusnet_in_groups'] = $group_addressees;
     // for older verions of gnu social: include the repeat-id, which we need when unrepeating later
     if (array_key_exists('repeated', $twitter_status) && $twitter_status['repeated'] === true) {
         $repeated = Notice::pkeyGet(array('profile_id' => $scoped->id, 'repeat_of' => $notice->id, 'verb' => 'http://activitystrea.ms/schema/1.0/share'));
         $twitter_status['repeated_id'] = $repeated->id;
     }
     // more metadata about attachments
     // get all attachments first, and put all the extra meta data in an array
     $attachments = $notice->attachments();
     $attachment_url_to_id = array();
     if (!empty($attachments)) {
         foreach ($attachments as $attachment) {
             if (is_object($attachment)) {
                 try {
                     $enclosure_o = $attachment->getEnclosure();
                     // add id to all attachments
                     $attachment_url_to_id[$enclosure_o->url]['id'] = $attachment->id;
                     // add data about thumbnails
                     $thumb = $attachment->getThumbnail();
                     $large_thumb = $attachment->getThumbnail(1000, 3000, false);
                     if (method_exists('File_thumbnail', 'url')) {
                         $thumb_url = File_thumbnail::url($thumb->filename);
                         $large_thumb_url = File_thumbnail::url($large_thumb->filename);
                     } else {
                         $thumb_url = $thumb->getUrl();
                         $large_thumb_url = $large_thumb->getUrl();
                     }
                     $attachment_url_to_id[$enclosure_o->url]['thumb_url'] = $thumb_url;
                     $attachment_url_to_id[$enclosure_o->url]['large_thumb_url'] = $large_thumb_url;
                     $attachment_url_to_id[$enclosure_o->url]['width'] = $attachment->width;
                     $attachment_url_to_id[$enclosure_o->url]['height'] = $attachment->height;
                     // animated gif?
                     if ($attachment->mimetype == 'image/gif') {
                         $image = ImageFile::fromFileObject($attachment);
                         if ($image->animated == 1) {
                             $attachment_url_to_id[$enclosure_o->url]['animated'] = true;
                         } else {
                             $attachment_url_to_id[$enclosure_o->url]['animated'] = false;
                         }
                     }
                     // this applies to older versions of gnu social, i think
                 } catch (ServerException $e) {
                     $thumb = File_thumbnail::getKV('file_id', $attachment->id);
                     if ($thumb instanceof File_thumbnail) {
                         $thumb_url = $thumb->getUrl();
                         $attachment_url_to_id[$enclosure_o->url]['id'] = $attachment->id;
                         $attachment_url_to_id[$enclosure_o->url]['thumb_url'] = $thumb_url;
                         $attachment_url_to_id[$enclosure_o->url]['large_thumb_url'] = $thumb_url;
                         $attachment_url_to_id[$enclosure_o->url]['width'] = $attachment->width;
                         $attachment_url_to_id[$enclosure_o->url]['height'] = $attachment->height;
                         // animated gif?
                         if ($attachment->mimetype == 'image/gif') {
                             $image = ImageFile::fromFileObject($attachment);
                             if ($image->animated == 1) {
                                 $attachment_url_to_id[$enclosure_o->url]['animated'] = true;
                             } else {
                                 $attachment_url_to_id[$enclosure_o->url]['animated'] = false;
                             }
                         }
                     }
                 }
             }
         }
     }
     // add the extra meta data to $twitter_status
     if (!empty($twitter_status['attachments'])) {
         foreach ($twitter_status['attachments'] as &$attachment) {
             if (!empty($attachment_url_to_id[$attachment['url']])) {
                 $attachment = array_merge($attachment, $attachment_url_to_id[$attachment['url']]);
             }
         }
     }
     // reply-to profile url
     try {
         $reply = $notice->getParent();
         $twitter_status['in_reply_to_profileurl'] = $reply->getProfile()->getUrl();
     } catch (ServerException $e) {
         $twitter_status['in_reply_to_profileurl'] = null;
     }
     // fave number
     $faves = Fave::byNotice($notice);
     $favenum = count($faves);
     $twitter_status['fave_num'] = $favenum;
     // repeat number
     $repeats = $notice->repeatStream();
     $repeatnum = 0;
     while ($repeats->fetch()) {
         if ($repeats->verb == ActivityVerb::SHARE) {
             // i.e. not deleted repeats
             $repeatnum++;
         }
     }
     $twitter_status['repeat_num'] = $repeatnum;
     // some more metadata about notice
     if ($notice->is_local == '1') {
         $twitter_status['is_local'] = true;
     } else {
         $twitter_status['is_local'] = false;
         if ($notice->object_type != 'activity') {
             try {
                 $twitter_status['external_url'] = $notice->getUrl(true);
             } catch (InvalidUrlException $e) {
                 common_debug('Qvitter: No URL available for external notice: id=' . $notice->id);
             }
         }
     }
     if ($notice->source == 'activity' || $notice->object_type == 'activity' || $notice->object_type == 'http://activitystrea.ms/schema/1.0/activity' || $notice->verb == 'delete') {
         $twitter_status['is_activity'] = true;
     } else {
         $twitter_status['is_activity'] = false;
     }
     if (ActivityUtils::compareTypes($notice->verb, array('qvitter-delete-notice', 'delete'))) {
         $twitter_status['qvitter_delete_notice'] = true;
     }
     return true;
 }
 function setAvatar($user)
 {
     try {
         $picUrl = sprintf('http://graph.facebook.com/%d/picture?type=large', $this->fbuser->id);
         // fetch the picture from Facebook
         $client = new HTTPClient();
         // fetch the actual picture
         $response = $client->get($picUrl);
         if ($response->isOk()) {
             // seems to always be jpeg, but not sure
             $tmpname = "facebook-avatar-tmp-" . common_random_hexstr(4);
             $ok = file_put_contents(Avatar::path($tmpname), $response->getBody());
             if (!$ok) {
                 common_log(LOG_WARNING, 'Couldn\'t save tmp Facebook avatar: ' . $tmpname, __FILE__);
             } else {
                 // save it as an avatar
                 $imagefile = new ImageFile(null, Avatar::path($tmpname));
                 $filename = Avatar::filename($user->id, image_type_to_extension($imagefile->preferredType()), 180, common_timestamp());
                 // Previous docs said 180 is the "biggest img we get from Facebook"
                 $imagefile->resizeTo(Avatar::path($filename, array('width' => 180, 'height' => 180)));
                 // No need to keep the temporary file around...
                 @unlink(Avatar::path($tmpname));
                 $profile = $user->getProfile();
                 if ($profile->setOriginal($filename)) {
                     common_log(LOG_INFO, sprintf('Saved avatar for %s (%d) from Facebook picture for ' . '%s (fbuid %d), filename = %s', $user->nickname, $user->id, $this->fbuser->name, $this->fbuid, $filename), __FILE__);
                     // clean up tmp file
                 }
             }
         }
     } catch (Exception $e) {
         common_log(LOG_WARNING, 'Couldn\'t save Facebook avatar: ' . $e->getMessage(), __FILE__);
         // error isn't fatal, continue
     }
 }
예제 #27
0
 /**
  * Handle the results of jcrop.
  *
  * @return void
  */
 function cropLogo()
 {
     $filedata = $_SESSION['FILEDATA'];
     if (!$filedata) {
         $this->serverError(_('Lost our file data.'));
         return;
     }
     // If image is not being cropped assume pos & dimentions of original
     $dest_x = $this->arg('avatar_crop_x') ? $this->arg('avatar_crop_x') : 0;
     $dest_y = $this->arg('avatar_crop_y') ? $this->arg('avatar_crop_y') : 0;
     $dest_w = $this->arg('avatar_crop_w') ? $this->arg('avatar_crop_w') : $filedata['width'];
     $dest_h = $this->arg('avatar_crop_h') ? $this->arg('avatar_crop_h') : $filedata['height'];
     $size = min($dest_w, $dest_h);
     $size = $size > MAX_ORIGINAL ? MAX_ORIGINAL : $size;
     $imagefile = new ImageFile($this->group->id, $filedata['filepath']);
     $filename = $imagefile->resize($size, $dest_x, $dest_y, $dest_w, $dest_h);
     if ($this->group->setOriginal($filename)) {
         @unlink($filedata['filepath']);
         unset($_SESSION['FILEDATA']);
         $this->mode = 'upload';
         $this->showForm(_('Logo updated.'), true);
     } else {
         $this->showForm(_('Failed updating logo.'));
     }
 }
예제 #28
0
 /**
  * Save the background image, if any, and set its disposition
  *
  * @param Design $design a working design to attach the img to
  *
  * @return nothing
  */
 function saveBackgroundImage($design)
 {
     // Now that we have a Design ID we can add a file to the design.
     // XXX: This is an additional DB hit, but figured having the image
     // associated with the Design rather than the User was worth
     // it. -- Zach
     if ($_FILES['design_background-image_file']['error'] == UPLOAD_ERR_OK) {
         $filepath = null;
         try {
             $imagefile = ImageFile::fromUpload('design_background-image_file');
         } catch (Exception $e) {
             $this->showForm($e->getMessage());
             return;
         }
         $filename = Design::filename($design->id, image_type_to_extension($imagefile->type), common_timestamp());
         $filepath = Design::path($filename);
         move_uploaded_file($imagefile->filepath, $filepath);
         // delete any old backround img laying around
         if (isset($design->backgroundimage)) {
             @unlink(Design::path($design->backgroundimage));
         }
         $original = clone $design;
         $design->backgroundimage = $filename;
         // default to on, no tile
         $design->setDisposition(true, false, false);
         $result = $design->update($original);
         if ($result === false) {
             common_log_db_error($design, 'UPDATE', __FILE__);
             // TRANS: Error message displayed if design settings could not be saved.
             $this->showForm(_('Couldn\'t update your design.'));
             return;
         }
     }
 }
 /**
  * Data elements of the form
  *
  * @return void
  */
 function formData()
 {
     if ($this->application) {
         $id = $this->application->id;
         $icon = $this->application->icon;
         $name = $this->application->name;
         $description = $this->application->description;
         $source_url = $this->application->source_url;
         $organization = $this->application->organization;
         $homepage = $this->application->homepage;
         $callback_url = $this->application->callback_url;
         $this->type = $this->application->type;
         $this->access_type = $this->application->access_type;
     } else {
         $id = '';
         $icon = '';
         $name = '';
         $description = '';
         $source_url = '';
         $organization = '';
         $homepage = '';
         $callback_url = '';
         $this->type = '';
         $this->access_type = '';
     }
     $this->out->elementStart('ul', 'form_data');
     $this->out->elementStart('li', array('id' => 'application_icon'));
     if (!empty($icon)) {
         $this->out->element('img', array('src' => $icon));
     }
     $this->out->element('input', array('name' => 'MAX_FILE_SIZE', 'type' => 'hidden', 'id' => 'MAX_FILE_SIZE', 'value' => ImageFile::maxFileSizeInt()));
     $this->out->element('label', array('for' => 'app_icon'), _('Icon'));
     $this->out->element('input', array('name' => 'app_icon', 'type' => 'file', 'id' => 'app_icon'));
     // TRANS: Form guide.
     $this->out->element('p', 'form_guide', _('Icon for this application'));
     $this->out->elementEnd('li');
     $this->out->elementStart('li');
     $this->out->hidden('application_id', $id);
     // TRANS: Form input field label for application name.
     $this->out->input('name', _('Name'), $this->out->arg('name') ? $this->out->arg('name') : $name);
     $this->out->elementEnd('li');
     $this->out->elementStart('li');
     $maxDesc = Oauth_application::maxDesc();
     if ($maxDesc > 0) {
         // TRANS: Form input field instructions.
         // TRANS: %d is the number of available characters for the description.
         $descInstr = sprintf(_m('Describe your application in %d character', 'Describe your application in %d characters', $maxDesc), $maxDesc);
     } else {
         // TRANS: Form input field instructions.
         $descInstr = _('Describe your application');
     }
     // TRANS: Form input field label.
     $this->out->textarea('description', _('Description'), $this->out->arg('description') ? $this->out->arg('description') : $description, $descInstr);
     $this->out->elementEnd('li');
     $this->out->elementStart('li');
     // TRANS: Form input field instructions.
     $instruction = _('URL of the homepage of this application');
     // TRANS: Form input field label.
     $this->out->input('source_url', _('Source URL'), $this->out->arg('source_url') ? $this->out->arg('source_url') : $source_url, $instruction);
     $this->out->elementEnd('li');
     $this->out->elementStart('li');
     // TRANS: Form input field instructions.
     $instruction = _('Organization responsible for this application');
     // TRANS: Form input field label.
     $this->out->input('organization', _('Organization'), $this->out->arg('organization') ? $this->out->arg('organization') : $organization, $instruction);
     $this->out->elementEnd('li');
     $this->out->elementStart('li');
     // TRANS: Form input field instructions.
     $instruction = _('URL for the homepage of the organization');
     // TRANS: Form input field label.
     $this->out->input('homepage', _('Homepage'), $this->out->arg('homepage') ? $this->out->arg('homepage') : $homepage, $instruction);
     $this->out->elementEnd('li');
     $this->out->elementStart('li');
     // TRANS: Form input field instructions.
     $instruction = _('URL to redirect to after authentication');
     // TRANS: Form input field label.
     $this->out->input('callback_url', 'Callback URL', $this->out->arg('callback_url') ? $this->out->arg('callback_url') : $callback_url, $instruction);
     $this->out->elementEnd('li');
     $this->out->elementStart('li', array('id' => 'application_types'));
     $attrs = array('name' => 'app_type', 'type' => 'radio', 'id' => 'app_type-browser', 'class' => 'radio', 'value' => Oauth_application::$browser);
     // Default to Browser
     if (empty($this->application) || empty($this->application->type) || $this->application->type == Oauth_application::$browser) {
         $attrs['checked'] = 'checked';
     }
     $this->out->element('input', $attrs);
     $this->out->element('label', array('for' => 'app_type-browser', 'class' => 'radio'), _('Browser'));
     $attrs = array('name' => 'app_type', 'type' => 'radio', 'id' => 'app_type-dekstop', 'class' => 'radio', 'value' => Oauth_application::$desktop);
     if (!empty($this->application) && $this->application->type == Oauth_application::$desktop) {
         $attrs['checked'] = 'checked';
     }
     $this->out->element('input', $attrs);
     $this->out->element('label', array('for' => 'app_type-desktop', 'class' => 'radio'), _('Desktop'));
     // TRANS: Form guide.
     $this->out->element('p', 'form_guide', _('Type of application, browser or desktop'));
     $this->out->elementEnd('li');
     $this->out->elementStart('li', array('id' => 'default_access_types'));
     $attrs = array('name' => 'default_access_type', 'type' => 'radio', 'id' => 'default_access_type-r', 'class' => 'radio', 'value' => 'r');
     // default to read-only access
     if (empty($this->application) || empty($this->application->access_type) || $this->application->access_type & Oauth_application::$readAccess) {
         $attrs['checked'] = 'checked';
     }
     $this->out->element('input', $attrs);
     $this->out->element('label', array('for' => 'default_access_type-ro', 'class' => 'radio'), _('Read-only'));
     $attrs = array('name' => 'default_access_type', 'type' => 'radio', 'id' => 'default_access_type-rw', 'class' => 'radio', 'value' => 'rw');
     if (!empty($this->application) && $this->application->access_type & Oauth_application::$readAccess && $this->application->access_type & Oauth_application::$writeAccess) {
         $attrs['checked'] = 'checked';
     }
     $this->out->element('input', $attrs);
     $this->out->element('label', array('for' => 'default_access_type-rw', 'class' => 'radio'), _('Read-write'));
     // TRANS: Form guide.
     $this->out->element('p', 'form_guide', _('Default access for this application: read-only, or read-write'));
     $this->out->elementEnd('li');
     $this->out->elementEnd('ul');
 }
예제 #30
0
 function uploadPhoto()
 {
     $cur = common_current_user();
     if (empty($cur)) {
         return;
     }
     try {
         $imagefile = ImageFile::fromUpload('photofile');
     } catch (Exception $e) {
         $this->showForm($e->getMessage());
         return;
     }
     if ($imagefile === null) {
         $this->showForm(_('No file uploaded.'));
         return;
     }
     $title = $this->trimmed('phototitle');
     $photo_description = $this->trimmed('photo_description');
     common_log(LOG_INFO, 'upload path : ' . $imagefile->filepath);
     $filename = $cur->nickname . '-' . common_timestamp() . sha1_file($imagefile->filepath) . image_type_to_extension($imagefile->type);
     move_uploaded_file($imagefile->filepath, INSTALLDIR . '/file/' . $filename);
     photo_make_thumbnail($filename);
     $uri = 'http://' . common_config('site', 'server') . '/file/' . $filename;
     $thumb_uri = 'http://' . common_config('site', 'server') . '/file/thumb.' . $filename;
     $profile_id = $cur->id;
     $album = GNUsocialPhotoAlbum::getKV('album_id', $this->trimmed('album'));
     if ($album->profile_id != $profile_id) {
         $this->showForm(_('Error: This is not your album!'));
         return;
     }
     GNUsocialPhoto::saveNew($profile_id, $album->album_id, $thumb_uri, $uri, 'web', false, $title, $photo_description);
 }