コード例 #1
0
ファイル: photos.php プロジェクト: joshjim27/jobsglobal
 /**
  *
  * @param type $type
  * @param type $id
  * @param type $sourceX
  * @param type $sourceY
  * @param type $width
  * @param type $height
  */
 public static function updateAvatar($type, $id, $sourceX, $sourceY, $width, $height)
 {
     $filter = JFilterInput::getInstance();
     /* Filter input values */
     $type = $filter->clean($type, 'string');
     $id = $filter->clean($id, 'integer');
     $sourceX = $filter->clean($sourceX, 'float');
     $sourceY = $filter->clean($sourceY, 'float');
     $width = $filter->clean($width, 'float');
     $height = $filter->clean($height, 'float');
     $cTable = JTable::getInstance(ucfirst($type), 'CTable');
     $cTable->load($id);
     $cTable->storage = 'file';
     $cTable->store();
     $srcPath = JPATH_ROOT . '/' . $cTable->avatar;
     $destPath = JPATH_ROOT . '/' . $cTable->thumb;
     /* */
     $config = CFactory::getConfig();
     $avatarFolder = $type != 'profile' && $type != '' ? $type . '/' : '';
     /* Get original image */
     $originalPath = JPATH_ROOT . '/' . $config->getString('imagefolder') . '/avatar' . '/' . $avatarFolder . '/' . $type . '-' . JFile::getName($cTable->avatar);
     /**
      * If original image does not exists than we use source image
      * @todo we should get from facebook original avatar file
      */
     if (!JFile::exists($originalPath)) {
         $originalPath = $srcPath;
     }
     $srcPath = str_replace('/', '/', $srcPath);
     $destPath = str_replace('/', '/', $destPath);
     $info = getimagesize($srcPath);
     $destType = $info['mime'];
     $destWidth = COMMUNITY_SMALL_AVATAR_WIDTH;
     $destHeight = COMMUNITY_SMALL_AVATAR_WIDTH;
     /* thumb size */
     $currentWidth = $width;
     $currentHeight = $height;
     /* avatar size */
     $imageMaxWidth = 160;
     $imageMaxHeight = 160;
     /**
      * @todo Should we generate new filename and update into database ?
      */
     /* do avatar resize */
     CImageHelper::resize($originalPath, $srcPath, $destType, $imageMaxWidth, $imageMaxHeight, $sourceX, $sourceY, $currentWidth, $currentHeight);
     /* do thumb resize */
     CImageHelper::resize($originalPath, $destPath, $destType, $destWidth, $destHeight, $sourceX, $sourceY, $currentWidth, $currentHeight);
     /**
      * Now we do check and process watermark
      */
     /* Check multiprofile to reapply watermark for thumbnail */
     $my = CFactory::getUser();
     $profileType = $my->getProfileType();
     $multiprofile = JTable::getInstance('MultiProfile', 'CTable');
     $multiprofile->load($profileType);
     $useWatermark = $profileType != COMMUNITY_DEFAULT_PROFILE && $config->get('profile_multiprofile') && !empty($multiprofile->watermark) ? true : false;
     if ($useWatermark && $type == 'profile') {
         $watermarkPath = JPATH_ROOT . '/' . CString::str_ireplace('/', '/', $multiprofile->watermark);
         list($watermarkWidth, $watermarkHeight) = getimagesize($watermarkPath);
         list($thumbWidth, $thumbHeight) = getimagesize($destPath);
         list($avatarWidth, $avatarHeight) = getimagesize($srcPath);
         // Avatar Properties
         $avatarPosition = CImageHelper::getPositions($multiprofile->watermark_location, $avatarWidth, $avatarHeight, $watermarkWidth, $watermarkHeight);
         // The original image file will be removed from the system once it generates a new watermark image.
         CImageHelper::addWatermark($srcPath, $srcPath, $destType, $watermarkPath, $avatarPosition->x, $avatarPosition->y);
         $thumbPosition = CImageHelper::getPositions($multiprofile->watermark_location, $thumbWidth, $thumbHeight, $watermarkWidth, $watermarkHeight);
         /* addWatermark into thumbnail */
         CImageHelper::addWatermark($destPath, $destPath, $destType, $watermarkPath, $thumbPosition->x, $thumbPosition->y);
     }
     // we need to update the activity stream of group if applicable, so the cropped image will be updated as well
     if ($type == 'group') {
         $groupParams = new JRegistry($cTable->params);
         $actId = $groupParams->get('avatar_activity_id');
         if ($actId) {
             $act = JTable::getInstance('Activity', 'CTable');
             $act->load($actId);
             $actParams = new JRegistry($act->params);
             $actParams->set('avatar_cropped_thumb', $cTable->avatar);
             $act->params = $actParams->toString();
             $act->store();
         }
     }
     $connectModel = CFactory::getModel('connect');
     // For facebook user, we need to add the watermark back on
     if ($connectModel->isAssociated($my->id) && $config->get('fbwatermark') && $type == 'profile') {
         list($watermarkWidth, $watermarkHeight) = getimagesize(FACEBOOK_FAVICON);
         CImageHelper::addWatermark($destPath, $destPath, $destType, FACEBOOK_FAVICON, $destWidth - $watermarkWidth, $destHeight - $watermarkHeight);
     }
 }
コード例 #2
0
ファイル: photos.php プロジェクト: Jougito/DynWeb
 /**
  * Called when the user uploaded a new photo and process avatar upload & resize
  * @return type
  */
 public function changeAvatar()
 {
     $mainframe = JFactory::getApplication();
     $jinput = $mainframe->input;
     /* get variables */
     $type = $jinput->get('type', null, 'NONE');
     $id = $jinput->get('id', null, 'INT');
     $saveAction = $jinput->get('repeattype', null, 'STRING');
     $filter = JFilterInput::getInstance();
     $type = $filter->clean($type, 'string');
     $id = $filter->clean($id, 'integer');
     $params = new JRegistry();
     $cTable = JTable::getInstance(ucfirst($type), 'CTable');
     $cTable->load($id);
     if ($type == "profile") {
         $my = CFactory::getUser($id);
     } else {
         $my = CFactory::getUser();
     }
     $config = CFactory::getConfig();
     $userid = $my->id;
     $fileFilter = new JInput($_FILES);
     $file = $fileFilter->get('filedata', '', 'array');
     if (!CImageHelper::checkImageSize(filesize($file['tmp_name']))) {
         $this->_showUploadError(true, JText::sprintf('COM_COMMUNITY_VIDEOS_IMAGE_FILE_SIZE_EXCEEDED_MB', CFactory::getConfig()->get('maxuploadsize')));
         return;
     }
     //check if file is allwoed
     if (!CImageHelper::isValidType($file['type'])) {
         $this->_showUploadError(true, JText::_('COM_COMMUNITY_IMAGE_FILE_NOT_SUPPORTED'));
         return;
     }
     CImageHelper::autoRotate($file['tmp_name']);
     $album = JTable::getInstance('Album', 'CTable');
     //create the avatar default album if it does not exists
     if (!($albumId = $album->isAvatarAlbumExists($id, $type))) {
         $albumId = $album->addAvatarAlbum($id, $type);
     }
     //start image processing
     // Get a hash for the file name.
     $fileName = JApplication::getHash($file['tmp_name'] . time());
     $hashFileName = JString::substr($fileName, 0, 24);
     $avatarFolder = $type != 'profile' && $type != '' ? $type . '/' : '';
     //avatar store path
     $storage = JPATH_ROOT . '/' . $config->getString('imagefolder') . '/avatar' . '/' . $avatarFolder;
     if (!JFolder::exists($storage)) {
         JFolder::create($storage);
     }
     $storageImage = $storage . '/' . $hashFileName . CImageHelper::getExtension($file['type']);
     $image = $config->getString('imagefolder') . '/avatar/' . $avatarFolder . $hashFileName . CImageHelper::getExtension($file['type']);
     /**
      * reverse image use for cropping feature
      * @uses <type>-<hashFileName>.<ext>
      */
     $storageReserve = $storage . '/' . $type . '-' . $hashFileName . CImageHelper::getExtension($file['type']);
     // filename for stream attachment
     $imageAttachment = $config->getString('imagefolder') . '/avatar/' . $hashFileName . '_stream_' . CImageHelper::getExtension($file['type']);
     //avatar thumbnail path
     $storageThumbnail = $storage . '/thumb_' . $hashFileName . CImageHelper::getExtension($file['type']);
     $thumbnail = $config->getString('imagefolder') . '/avatar/' . $avatarFolder . 'thumb_' . $hashFileName . CImageHelper::getExtension($file['type']);
     //Minimum height/width checking for Avatar uploads
     list($currentWidth, $currentHeight) = getimagesize($file['tmp_name']);
     if ($currentWidth < COMMUNITY_AVATAR_PROFILE_WIDTH || $currentHeight < COMMUNITY_AVATAR_PROFILE_HEIGHT) {
         $this->_showUploadError(true, JText::sprintf('COM_COMMUNITY_ERROR_MINIMUM_AVATAR_DIMENSION', COMMUNITY_AVATAR_PROFILE_WIDTH, COMMUNITY_AVATAR_PROFILE_HEIGHT));
         return;
     }
     /**
      * Generate square avatar
      */
     if (!CImageHelper::createThumb($file['tmp_name'], $storageImage, $file['type'], COMMUNITY_AVATAR_PROFILE_WIDTH, COMMUNITY_AVATAR_PROFILE_HEIGHT)) {
         $this->_showUploadError(true, JText::sprintf('COM_COMMUNITY_ERROR_MOVING_UPLOADED_FILE', $storageImage));
         return;
     }
     // Generate thumbnail
     if (!CImageHelper::createThumb($file['tmp_name'], $storageThumbnail, $file['type'])) {
         $this->_showUploadError(true, JText::sprintf('COM_COMMUNITY_ERROR_MOVING_UPLOADED_FILE', $storageImage));
         return;
     }
     /**
      * Generate large image use for avatar thumb cropping
      * It must be larget than profile avatar size because we'll use it for profile avatar recrop also
      */
     $newWidth = 0;
     $newHeight = 0;
     if ($currentWidth >= $currentHeight) {
         if ($this->testResize($currentWidth, $currentHeight, COMMUNITY_AVATAR_RESERVE_WIDTH, 0, COMMUNITY_AVATAR_PROFILE_WIDTH, COMMUNITY_AVATAR_RESERVE_WIDTH)) {
             $newWidth = COMMUNITY_AVATAR_RESERVE_WIDTH;
             $newHeight = 0;
         } else {
             $newWidth = 0;
             $newHeight = COMMUNITY_AVATAR_RESERVE_HEIGHT;
         }
     } else {
         if ($this->testResize($currentWidth, $currentHeight, 0, COMMUNITY_AVATAR_RESERVE_HEIGHT, COMMUNITY_AVATAR_PROFILE_HEIGHT, COMMUNITY_AVATAR_RESERVE_HEIGHT)) {
             $newWidth = 0;
             $newHeight = COMMUNITY_AVATAR_RESERVE_HEIGHT;
         } else {
             $newWidth = COMMUNITY_AVATAR_RESERVE_WIDTH;
             $newHeight = 0;
         }
     }
     if (!CImageHelper::resizeProportional($file['tmp_name'], $storageReserve, $file['type'], $newWidth, $newHeight)) {
         $this->_showUploadError(true, JText::sprintf('COM_COMMUNITY_ERROR_MOVING_UPLOADED_FILE', $storageReserve));
         return;
     }
     /*
      * Generate photo to be stored in default avatar album
      * notes: just in case this need to be used in registration, just get the code below.
      */
     $originalPath = $storage . 'original_' . md5($my->id . '_avatar' . time()) . CImageHelper::getExtension($file['type']);
     $fullImagePath = $storage . md5($my->id . '_avatar' . time()) . CImageHelper::getExtension($file['type']);
     $thumbPath = $storage . 'thumb_' . md5($my->id . '_avatar' . time()) . CImageHelper::getExtension($file['type']);
     // Generate full image
     if (!CImageHelper::resizeProportional($file['tmp_name'], $fullImagePath, $file['type'], 1024)) {
         $msg['error'] = JText::sprintf('COM_COMMUNITY_ERROR_MOVING_UPLOADED_FILE', $file['tmp_name']);
         echo json_encode($msg);
         exit;
     }
     CPhotos::generateThumbnail($file['tmp_name'], $thumbPath, $file['type']);
     if (!JFile::copy($file['tmp_name'], $originalPath)) {
         exit;
     }
     //store this picture into default avatar album
     $now = new JDate();
     $photo = JTable::getInstance('Photo', 'CTable');
     $photo->albumid = $albumId;
     $photo->image = str_replace(JPATH_ROOT . '/', '', $fullImagePath);
     $photo->caption = $file['name'];
     $photo->filesize = $file['size'];
     $photo->creator = $my->id;
     $photo->created = $now->toSql();
     $photo->published = 1;
     $photo->thumbnail = str_replace(JPATH_ROOT . '/', '', $thumbPath);
     $photo->original = str_replace(JPATH_ROOT . '/', '', $originalPath);
     if ($photo->store()) {
         $album->load($albumId);
         $album->photoid = $photo->id;
         $album->setParam('thumbnail', $photo->thumbnail);
         $album->store();
     }
     //end storing user avatar in avatar album
     if ($type == 'profile') {
         $profileType = $my->getProfileType();
         $multiprofile = JTable::getInstance('MultiProfile', 'CTable');
         $multiprofile->load($profileType);
         $useWatermark = $profileType != COMMUNITY_DEFAULT_PROFILE && $config->get('profile_multiprofile') && !empty($multiprofile->watermark) ? true : false;
         if ($useWatermark && $multiprofile->watermark) {
             JFile::copy($storageImage, JPATH_ROOT . '/images/watermarks/original' . '/' . md5($my->id . '_avatar') . CImageHelper::getExtension($file['type']));
             JFile::copy($storageThumbnail, JPATH_ROOT . '/images/watermarks/original' . '/' . md5($my->id . '_thumb') . CImageHelper::getExtension($file['type']));
             $watermarkPath = JPATH_ROOT . '/' . CString::str_ireplace('/', '/', $multiprofile->watermark);
             list($watermarkWidth, $watermarkHeight) = getimagesize($watermarkPath);
             list($avatarWidth, $avatarHeight) = getimagesize($storageImage);
             list($thumbWidth, $thumbHeight) = getimagesize($storageThumbnail);
             $watermarkImage = $storageImage;
             $watermarkThumbnail = $storageThumbnail;
             // Avatar Properties
             $avatarPosition = CImageHelper::getPositions($multiprofile->watermark_location, $avatarWidth, $avatarHeight, $watermarkWidth, $watermarkHeight);
             // The original image file will be removed from the system once it generates a new watermark image.
             CImageHelper::addWatermark($storageImage, $watermarkImage, $file['type'], $watermarkPath, $avatarPosition->x, $avatarPosition->y);
             //Thumbnail Properties
             $thumbPosition = CImageHelper::getPositions($multiprofile->watermark_location, $thumbWidth, $thumbHeight, $watermarkWidth, $watermarkHeight);
             // The original thumbnail file will be removed from the system once it generates a new watermark image.
             CImageHelper::addWatermark($storageThumbnail, $watermarkThumbnail, $file['type'], $watermarkPath, $thumbPosition->x, $thumbPosition->y);
             $my->set('_watermark_hash', $multiprofile->watermark_hash);
         }
         // We need to make a copy of current avatar and set it as stream 'attachement'
         // which will only gets deleted once teh stream is deleted
         $my->_cparams->set('avatar_photo_id', $photo->id);
         //we also set the id of the avatar photo
         $my->save();
         JFile::copy($image, $imageAttachment);
         $params->set('attachment', $imageAttachment);
     }
     //end of storing this picture into default avatar album
     if (empty($saveAction)) {
         $cTable->setImage($image, 'avatar');
         $cTable->setImage($thumbnail, 'thumb');
     } else {
         // This is for event recurring save option ( current / future event )
         $cTable->setImage($image, 'avatar', $saveAction);
         $cTable->setImage($thumbnail, 'thumb', $saveAction);
     }
     // add points & activity stream
     switch ($type) {
         case 'profile':
             /**
              * Generate activity stream
              * @todo Should we use CApiActivities::add
              */
             // do not have to generate a stream if the user is not the user itself (eg admin change user avatar)
             if (CUserPoints::assignPoint('profile.avatar.upload') && $my->id == CFactory::getUser()->id) {
                 $act = new stdClass();
                 $act->cmd = 'profile.avatar.upload';
                 $act->actor = $userid;
                 $act->target = 0;
                 $act->title = '';
                 $act->content = '';
                 $act->access = $my->_cparams->get("privacyPhotoView", 0);
                 $act->app = 'profile.avatar.upload';
                 /* Profile app */
                 $act->cid = isset($photo->id) && $photo->id ? $photo->id : 0;
                 $act->verb = 'upload';
                 /* We uploaded new avatar - NOT change avatar */
                 $act->params = $params;
                 $params->set('photo_id', $photo->id);
                 $params->set('album_id', $photo->albumid);
                 $act->comment_id = CActivities::COMMENT_SELF;
                 $act->comment_type = 'profile.avatar.upload';
                 $act->like_id = CActivities::LIKE_SELF;
                 $act->like_type = 'profile.avatar.upload';
             }
             break;
         case 'group':
             CUserPoints::assignPoint('group.avatar.upload');
             /**
              * Generate activity stream
              * @todo Should we use CApiActivities::add
              */
             $act = new stdClass();
             $act->cmd = 'groups.avatar.upload';
             $act->actor = $userid;
             $act->target = 0;
             $act->title = '';
             $act->content = '';
             $act->app = 'groups.avatar.upload';
             /* Groups app */
             $act->cid = $id;
             $act->groupid = $id;
             $act->verb = 'update';
             /* We do update */
             $params->set('photo_id', $photo->id);
             $params->set('album_id', $photo->albumid);
             $act->comment_id = CActivities::COMMENT_SELF;
             $act->comment_type = 'groups.avatar.upload';
             $act->like_id = CActivities::LIKE_SELF;
             $act->like_type = 'groups.avatar.upload';
             break;
         case 'event':
             //CUserPoints::assignPoint('events.avatar.upload'); @disabled since 4.0
             /**
              * Generate activity stream
              * @todo Should we use CApiActivities::add
              */
             $act = new stdClass();
             $act->cmd = 'events.avatar.upload';
             $act->actor = $userid;
             $act->target = 0;
             $act->title = '';
             $act->content = '';
             $act->app = 'events.avatar.upload';
             /* Events app */
             $act->cid = $id;
             $act->eventid = $id;
             $act->verb = 'update';
             /* We do update */
             $act->comment_id = CActivities::COMMENT_SELF;
             $act->comment_type = 'events.avatar.upload';
             $act->like_id = CActivities::LIKE_SELF;
             $act->like_type = 'events.avatar.upload';
             break;
     }
     //we only generate stream if the uploader is the user himself, not admin or anyone else
     if (isset($act) && $my->id == $id || $type != 'profile') {
         // $return = CApiActivities::add($act);
         /**
          * use internal Stream instead use for 3rd part API
          */
         $return = CActivityStream::add($act, $params->toString());
         //add the reference to the activity so that we can do something when someone update the avatar
         if ($type == 'profile') {
             // overwrite the params because some of the param might be updated through $my object above
             $cTableParams = $my->_cparams;
         } else {
             $cTableParams = new JRegistry($cTable->params);
         }
         $cTableParams->set('avatar_activity_id', $return->id);
         $cTable->params = $cTableParams->toString();
         $cTable->store();
     }
     if (method_exists($cTable, 'getLargeAvatar')) {
         $this->_showUploadError(false, $cTable->getLargeAvatar(), CUrlHelper::avatarURI($thumbnail, 'user_thumb.png'));
     } else {
         $this->_showUploadError(false, $cTable->getAvatar(), CUrlHelper::avatarURI($thumbnail, 'user_thumb.png'));
     }
 }
コード例 #3
0
ファイル: multiprofile.php プロジェクト: Jougito/DynWeb
 private function _updateUserWatermark($user, $type, $hashName)
 {
     $config = CFactory::getConfig();
     $oldAvatar = $user->_avatar;
     // @rule: This is the original avatar path
     //CFactory::load( 'helpers' , 'image' );
     $userImageType = '_' . $type;
     $data = @getimagesize(JPATH_ROOT . '/' . CString::str_ireplace('/', '/', $user->{$userImageType}));
     $original = JPATH_ROOT . '/images/watermarks/original' . '/' . md5($user->id . '_' . $type) . CImageHelper::getExtension($data['mime']);
     if (!$config->get('profile_multiprofile') || !JFile::exists($original)) {
         return false;
     }
     static $types = array();
     if (empty($types)) {
         $model = CFactory::getModel('Profile');
         $rows = $model->getProfileTypes();
         if ($rows) {
             foreach ($rows as $row) {
                 $types[$row->id] = $row;
             }
         }
     }
     $model = CFactory::getModel('User');
     if (isset($types[$user->_profile_id])) {
         // Bind the data to the current object so we can access it here.
         $this->bind($types[$user->_profile_id]);
         // Path to the watermark image.
         $watermarkPath = JPATH_ROOT . '/' . CString::str_ireplace('/', '/', $this->watermark);
         // Retrieve original image info
         $originalData = getimagesize($original);
         // Generate image file name.
         $fileName = $type == 'thumb' ? 'thumb_' : '';
         $fileName .= $hashName;
         $fileName .= CImageHelper::getExtension($originalData['mime']);
         // Absolute path to the image (local)
         $newImagePath = JPATH_ROOT . '/' . $config->getString('imagefolder') . '/avatar' . '/' . $fileName;
         // Relative path to the image (uri)
         $newImageUri = $config->getString('imagefolder') . '/avatar/' . $fileName;
         // Retrieve the height and width for watermark and original image.
         list($watermarkWidth, $watermarkHeight) = getimagesize($watermarkPath);
         list($originalWidth, $originalHeight) = getimagesize($original);
         // Retrieve the proper coordinates to the watermark location
         $position = CImageHelper::getPositions($this->watermark_location, $originalWidth, $originalHeight, $watermarkWidth, $watermarkHeight);
         // Create the new image with the watermarks.
         CImageHelper::addWatermark($original, $newImagePath, $originalData['mime'], $watermarkPath, $position->x, $position->y, false);
         $model->setImage($user->id, $newImageUri, $type);
         // Remove the user's old image
         $oldFile = JPATH_ROOT . '/' . CString::str_ireplace('/', '/', $user->{$userImageType});
         if (JFile::exists($oldFile)) {
             JFile::delete($oldFile);
         }
         if ($type == 'avatar') {
             $oldImg = explode('avatar/', $oldAvatar);
             $oldImg = explode('.', $oldImg[1]);
             $oldImg = $config->getString('imagefolder') . '/avatar/' . $oldImg[0] . '_stream_.' . $oldImg[1];
             JFile::copy($newImageUri, $oldImg);
         }
         // We need to update the property in CUser as well otherwise when we save the hash, it'll
         // use the old user avatar.
         $user->set($userImageType, $newImageUri);
         // We need to restore the storage method.
         $user->set('_storage', 'file');
         // Update the watermark hash with the latest hash
         $user->set('_watermark_hash', $this->watermark_hash);
         $user->save();
     }
     return true;
 }
コード例 #4
0
ファイル: facebook.php プロジェクト: Simarpreet05/joomla
 public function mapAvatar($avatarUrl = '', $joomlaUserId, $addWaterMark)
 {
     $image = '';
     if (!empty($avatarUrl)) {
         // Make sure user is properly added into the database table first
         $user = CFactory::getUser($joomlaUserId);
         $fbUser = $this->getUser();
         // Load image helper library as it is needed.
         CFactory::load('helpers', 'image');
         // Store image on a temporary folder.
         $tmpPath = JPATH_ROOT . DS . 'images' . DS . 'originalphotos' . DS . 'facebook_connect_' . $fbUser;
         /*
         			print_r($avatarUrl); exit;	
         			$url	= parse_url( $avatarUrl );
         			$host	= $url[ 'host' ];
         			$fp = fsockopen("profile.ak.fbcdn.net", 80, $errno, $errstr, 30);
         $path	= CString::str_ireplace( $url['scheme'] . '://' . $host , '' , $avatarUrl );
         			$source	= '';
         if( $fp )
         			{
         				$out = "GET $path HTTP/1.1\r\n";
         				$out .= "Host: " . $host . "\r\n";
         				$out .= "Connection: Close\r\n\r\n";
         	fwrite($fp, $out);
         				
         				$body		= false;
         								
         				while( !feof( $fp ) )
         				{
         					$return	= fgets( $fp , 1024 );
         					
         					if( $body )
         					{
         						$source	.= $return;
         					}
         					
         					if( $return == "\r\n" )
         					{
         						$body	= true;
         					}
         				}
         				fclose($fp);
         }
         */
         // Need to extract the non-https version since it will cause
         // certificate issue
         $avatarUrl = str_replace('https://', 'http://', $avatarUrl);
         CFactory::load('helpers', 'remote');
         $source = CRemoteHelper::getContent($avatarUrl, true);
         list($headers, $source) = explode("\r\n\r\n", $source, 2);
         JFile::write($tmpPath, $source);
         // @todo: configurable width?
         $imageMaxWidth = 160;
         // Get a hash for the file name.
         $fileName = JUtility::getHash($fbUser . time());
         $hashFileName = JString::substr($fileName, 0, 24);
         $extension = JString::substr($avatarUrl, JString::strrpos($avatarUrl, '.'));
         $type = 'image/jpg';
         if ($extension == '.png') {
             $type = 'image/png';
         }
         if ($extension == '.gif') {
             $type = 'image/gif';
         }
         //@todo: configurable path for avatar storage?
         $config = CFactory::getConfig();
         $storage = JPATH_ROOT . DS . $config->getString('imagefolder') . DS . 'avatar';
         $storageImage = $storage . DS . $hashFileName . $extension;
         $storageThumbnail = $storage . DS . 'thumb_' . $hashFileName . $extension;
         $image = $config->getString('imagefolder') . '/avatar/' . $hashFileName . $extension;
         $thumbnail = $config->getString('imagefolder') . '/avatar/' . 'thumb_' . $hashFileName . $extension;
         $userModel = CFactory::getModel('user');
         // Only resize when the width exceeds the max.
         CImageHelper::resizeProportional($tmpPath, $storageImage, $type, $imageMaxWidth);
         CImageHelper::createThumb($tmpPath, $storageThumbnail, $type);
         if ($addWaterMark) {
             // Get the width and height so we can calculate where to place the watermark.
             list($watermarkWidth, $watermarkHeight) = getimagesize(FACEBOOK_FAVICON);
             list($imageWidth, $imageHeight) = getimagesize($storageImage);
             list($thumbWidth, $thumbHeight) = getimagesize($storageThumbnail);
             CImageHelper::addWatermark($storageImage, $storageImage, $type, FACEBOOK_FAVICON, $imageWidth - $watermarkWidth, $imageHeight - $watermarkHeight);
             CImageHelper::addWatermark($storageThumbnail, $storageThumbnail, $type, FACEBOOK_FAVICON, $thumbWidth - $watermarkWidth, $thumbHeight - $watermarkHeight);
         }
         // Update the CUser object with the correct avatar.
         $user->set('_thumb', $thumbnail);
         $user->set('_avatar', $image);
         // @rule: once user changes their profile picture, storage method should always be file.
         $user->set('_storage', 'file');
         $userModel->setImage($joomlaUserId, $image, 'avatar');
         $userModel->setImage($joomlaUserId, $thumbnail, 'thumb');
         $user->save();
     }
 }
コード例 #5
0
ファイル: image.php プロジェクト: bizanto/Hooked
/**
 * Deprecated since 1.8
 * Use CImageHelper::addWatermark instead. 
 */
function cImageAddWatermark($backgroundImagePath, $destinationPath, $destinationType, $watermarkImagePath, $positionX = 0, $positionY = 0)
{
    return CImageHelper::addWatermark($backgroundImagePath, $destinationPath, $destinationType, $watermarkImagePath, $positionX, $positionY);
}
コード例 #6
0
ファイル: register.php プロジェクト: joshjim27/jobsglobal
 /**
  * Step 5
  * Upload a new user avatar
  */
 public function registerAvatar()
 {
     $mainframe = JFactory::getApplication();
     $jinput = $mainframe->input;
     jimport('joomla.filesystem.file');
     jimport('joomla.utilities.utility');
     $mySess = JFactory::getSession();
     $user = $mySess->get('tmpUser', '');
     /* Just for incase this's incomplete object */
     if (!is_object($user) && gettype($user) == 'object') {
         $user = unserialize(serialize($user));
     }
     if (empty($user)) {
         //throw error.
         JError::raiseError(500, JText::_('COM_COMMUNITY_REGISTRATION_MISSING_USER_OBJ'));
         return;
     }
     $view = $this->getView('register');
     $profileType = JRequest::getInt('profileType', 0);
     // If uplaod is detected, we process the uploaded avatar
     if ($jinput->post->get('action', '')) {
         $my = CFactory::getUser($user->id);
         $fileFilter = new JInput($_FILES);
         $file = $fileFilter->get('Filedata', '', 'array');
         if ($my->id == 0) {
             return $this->blockUnregister();
         }
         if (!CImageHelper::isValidType($file['type'])) {
             $mainframe->enqueueMessage(JText::_('COM_COMMUNITY_IMAGE_FILE_NOT_SUPPORTED'), 'error');
             $url = $profileType !== 0 ? CRoute::_('index.php?option=com_community&view=register&task=registerAvatar&profileType=' . $profileType, false) : CRoute::_('index.php?option=com_community&view=register&task=registerAvatar', false);
             $mainframe->redirect($url);
             return;
         }
         if (!isset($file['tmp_name']) || empty($file['tmp_name'])) {
             $mainframe->enqueueMessage(JText::_('COM_COMMUNITY_NO_POST_DATA'), 'error');
         } else {
             $config = CFactory::getConfig();
             $uploadLimit = (double) $config->get('maxuploadsize');
             $uploadLimit = $uploadLimit * 1024 * 1024;
             if (filesize($file['tmp_name']) > $uploadLimit && $uploadLimit != 0) {
                 $mainframe->enqueueMessage(JText::sprintf('COM_COMMUNITY_VIDEOS_IMAGE_FILE_SIZE_EXCEEDED_MB', CFactory::getConfig()->get('maxuploadsize')), 'error');
                 $mainframe->redirect(CRoute::_('index.php?option=com_community&view=register&task=registerAvatar&profileType=' . $profileType, false));
             }
             if (!CImageHelper::isValid($file['tmp_name'])) {
                 $mainframe->enqueueMessage(JText::_('COM_COMMUNITY_IMAGE_FILE_NOT_SUPPORTED'), 'error');
             } else {
                 $config = CFactory::getConfig();
                 $useWatermark = $profileType != COMMUNITY_DEFAULT_PROFILE && $config->get('profile_multiprofile') ? true : false;
                 // @todo: configurable width?
                 $imageMaxWidth = 160;
                 // Get a hash for the file name.
                 $fileName = JApplication::getHash($file['tmp_name'] . time());
                 $hashFileName = JString::substr($fileName, 0, 24);
                 //@todo: configurable path for avatar storage?
                 $config = CFactory::getConfig();
                 $storage = JPATH_ROOT . '/' . $config->getString('imagefolder') . '/avatar';
                 $storageImage = $storage . '/' . $hashFileName . CImageHelper::getExtension($file['type']);
                 $storageThumbnail = $storage . '/thumb_' . $hashFileName . CImageHelper::getExtension($file['type']);
                 $image = $config->getString('imagefolder') . '/avatar/' . $hashFileName . CImageHelper::getExtension($file['type']);
                 $thumbnail = $config->getString('imagefolder') . '/avatar/' . 'thumb_' . $hashFileName . CImageHelper::getExtension($file['type']);
                 $userModel = CFactory::getModel('user');
                 // Generate full image
                 if (!CImageHelper::resizeProportional($file['tmp_name'], $storageImage, $file['type'], $imageMaxWidth)) {
                     $mainframe->enqueueMessage(JText::sprintf('COM_COMMUNITY_ERROR_MOVING_UPLOADED_FILE', $storageImage), 'error');
                 }
                 // Generate thumbnail
                 if (!CImageHelper::createThumb($file['tmp_name'], $storageThumbnail, $file['type'])) {
                     $mainframe->enqueueMessage(JText::sprintf('COM_COMMUNITY_ERROR_MOVING_UPLOADED_FILE', $storageThumbnail), 'error');
                 }
                 if ($useWatermark) {
                     if (!JFolder::exists(JPATH_ROOT . '/images/watermarks/original')) {
                         JFolder::create(JPATH_ROOT . '/images/watermarks/original');
                     }
                     // @rule: Before adding the watermark, we should copy the user's original image so that when the admin tries to reset the avatar,
                     // it will be able to grab the original picture.
                     JFile::copy($storageImage, JPATH_ROOT . '/images/watermarks/original/' . md5($my->id . '_avatar') . CImageHelper::getExtension($file['type']));
                     JFile::copy($storageThumbnail, JPATH_ROOT . '/images/watermarks/original/' . md5($my->id . '_thumb') . CImageHelper::getExtension($file['type']));
                     $multiprofile = JTable::getInstance('MultiProfile', 'CTable');
                     $multiprofile->load($profileType);
                     if ($multiprofile->watermark) {
                         $watermarkPath = JPATH_ROOT . '/' . CString::str_ireplace('/', '/', $multiprofile->watermark);
                         list($watermarkWidth, $watermarkHeight) = getimagesize($watermarkPath);
                         list($avatarWidth, $avatarHeight) = getimagesize($storageImage);
                         list($thumbWidth, $thumbHeight) = getimagesize($storageThumbnail);
                         $watermarkImage = $storageImage;
                         $watermarkThumbnail = $storageThumbnail;
                         // Avatar Properties
                         $avatarPosition = CImageHelper::getPositions($multiprofile->watermark_location, $avatarWidth, $avatarHeight, $watermarkWidth, $watermarkHeight);
                         // The original image file will be removed from the system once it generates a new watermark image.
                         CImageHelper::addWatermark($storageImage, $watermarkImage, $file['type'], $watermarkPath, $avatarPosition->x, $avatarPosition->y);
                         //Thumbnail Properties
                         $thumbPosition = CImageHelper::getPositions($multiprofile->watermark_location, $thumbWidth, $thumbHeight, $watermarkWidth, $watermarkHeight);
                         // The original thumbnail file will be removed from the system once it generates a new watermark image.
                         CImageHelper::addWatermark($storageThumbnail, $watermarkThumbnail, $file['type'], $watermarkPath, $thumbPosition->x, $thumbPosition->y);
                         $my->set('_watermark_hash', $multiprofile->watermark_hash);
                         $my->save();
                     }
                 }
                 // Since this is a new registration, we definitely do not want to remove the old image.
                 $removeOldImage = false;
                 $userModel->setImage($my->id, $image, 'avatar', $removeOldImage);
                 $userModel->setImage($my->id, $thumbnail, 'thumb', $removeOldImage);
                 // Update the user object so that the profile picture gets updated.
                 $my->set('_avatar', $image);
                 $my->set('_thumb', $thumbnail);
             }
         }
     }
     echo $view->get(__FUNCTION__);
 }
コード例 #7
0
ファイル: multiprofile.php プロジェクト: Jougito/DynWeb
 public function save()
 {
     jimport('joomla.filesystem.folder');
     jimport('joomla.filesystem.file');
     $mainframe = JFactory::getApplication();
     $jinput = $mainframe->input;
     $id = JRequest::getInt('id', 0, 'POST');
     $post = JRequest::get('POST');
     $fields = $jinput->get('fields', '', 'NONE');
     $name = $jinput->get('name', '', 'STRING');
     $tmpParents = $jinput->get('parents', '', 'NONE');
     $mainframe = JFactory::getApplication();
     $task = JRequest::getCmd('task');
     $isNew = $id == 0 ? true : false;
     $validated = true;
     $multiprofile = JTable::getInstance('MultiProfile', 'CTable');
     $multiprofile->load($id);
     // Skip watermarking if it's the same location
     $skipWatermark = isset($multiprofile->watermark_location) && isset($post['watermark_location']) && $post['watermark_location'] == $multiprofile->watermark_location ? true : false;
     // Bind with form post
     $multiprofile->bind($post);
     // Can't have an empty name now can we?
     if (empty($name)) {
         $validated = false;
         $mainframe->enqueueMessage(JText::_('COM_COMMUNITY_MULTIPROFILE_NAME_EMPTY'), 'error');
     }
     $date = JFactory::getDate();
     $isNew = $multiprofile->id == 0 ? true : false;
     if ($isNew) {
         $multiprofile->created = $date->toSql();
     }
     // Store watermarks for profile types.
     $watermark = $jinput->files->get('watermark', '', 'NONE');
     //JRequest::getVar( 'watermark' , '' , 'FILES');
     if (!empty($watermark['tmp_name'])) {
         // Do not allow image size to exceed maximum width and height
         if (isset($watermark['name']) && !empty($watermark['name'])) {
             list($width, $height) = getimagesize($watermark['tmp_name']);
             /**
              * watermark can't large than 16px
              * @todo use define for min width & height instead fixed number here
              */
             if ($width > 16 || $height > 16) {
                 $validated = false;
                 $mainframe->enqueueMessage(JText::_('COM_COMMUNITY_MULTIPROFILE_WATERMARK_IMAGE_EXCEEDS_SIZE'), 'error');
             }
         }
     }
     if ($validated) {
         $multiprofile->store();
         // If image file is specified, we need to store the thumbnail.
         if (!empty($watermark['tmp_name'])) {
             if (isset($watermark['name']) && !empty($watermark['name'])) {
                 if (!JFolder::exists(JPATH_ROOT . '/' . COMMUNITY_WATERMARKS_PATH)) {
                     JFolder::create(JPATH_ROOT . '/' . COMMUNITY_WATERMARKS_PATH);
                 }
                 $watermarkFile = 'watermark_' . $multiprofile->id . CImageHelper::getExtension($watermark['type']);
                 JFile::copy($watermark['tmp_name'], JPATH_ROOT . '/' . COMMUNITY_WATERMARKS_PATH . '/' . $watermarkFile);
                 $multiprofile->watermark = CString::str_ireplace('/', '/', COMMUNITY_WATERMARKS_PATH) . '/' . $watermarkFile;
                 $multiprofile->store();
             }
         }
         // @rule: Create the watermarks folder if doesn't exists.
         if (!JFolder::exists(JPATH_ROOT . '/' . COMMUNITY_WATERMARKS_PATH)) {
             if (!JFolder::create(JPATH_ROOT . '/' . COMMUNITY_WATERMARKS_PATH)) {
                 $mainframe->enqueueMessage(JText::_('COM_COMMUNITY_MULTIPROFILE_UNABLE_TO_CREATE_WATERMARKS_FOLDER'));
             }
         }
         // @rule: Create original folder within watermarks to store original user photos.
         if (!JFolder::exists(JPATH_ROOT . '/' . COMMUNITY_WATERMARKS_PATH . '/original')) {
             if (!JFolder::create(JPATH_ROOT . '/' . COMMUNITY_WATERMARKS_PATH . '/original')) {
                 $mainframe->enqueueMessage(JText::_('COM_COMMUNITY_MULTIPROFILE_UNABLE_TO_CREATE_WATERMARKS_FOLDER'));
             }
         }
         if (!empty($watermark['tmp_name']) || !$isNew && !$skipWatermark) {
             if (isset($watermark['name']) && !empty($watermark['name'])) {
                 $watermarkPath = $watermark['tmp_name'];
                 $watermark_hash = md5($watermark['name'] . time());
             } else {
                 $watermarkPath = JPATH_ROOT . '/' . $multiprofile->watermark;
                 $watermark_hash = $multiprofile->watermark_hash;
             }
             // Create default watermarks for avatar and thumbnails.
             // Generate filename
             $fileName = CImageHelper::getHashName($multiprofile->id . time()) . '.jpg';
             $thumbFileName = 'thumb_' . $fileName;
             // Paths where the thumbnail and avatar should be saved.
             $thumbPath = JPATH_ROOT . '/' . COMMUNITY_WATERMARKS_PATH . '/' . $thumbFileName;
             $avatarPath = JPATH_ROOT . '/' . COMMUNITY_WATERMARKS_PATH . '/' . $fileName;
             // Copy existing default thumbnails into the path first.
             JFile::copy(JPATH_ROOT . '/' . DEFAULT_USER_THUMB, $thumbPath);
             JFile::copy(JPATH_ROOT . '/' . DEFAULT_USER_AVATAR, $avatarPath);
             $watermarkPath = $watermarkPath;
             list($watermarkWidth, $watermarkHeight) = getimagesize($watermarkPath);
             $oldDefaultAvatar = $multiprofile->avatar;
             $oldDefaultThumb = $multiprofile->thumb;
             // Avatar Properties
             $avatarInfo = getimagesize($avatarPath);
             $avatarWidth = $avatarInfo[0];
             $avatarHeight = $avatarInfo[1];
             $avatarMime = $avatarInfo['mime'];
             $avatarPosition = $this->_getPositions($multiprofile->watermark_location, $avatarWidth, $avatarHeight, $watermarkWidth, $watermarkHeight);
             CImageHelper::addWatermark($avatarPath, $avatarPath, $avatarMime, $watermarkPath, $avatarPosition->x, $avatarPosition->y);
             $multiprofile->avatar = CString::str_ireplace('/', '/', COMMUNITY_WATERMARKS_PATH) . '/' . $fileName;
             // Thumbnail properties.
             $thumbInfo = getimagesize($thumbPath);
             $thumbWidth = $thumbInfo[0];
             $thumbHeight = $thumbInfo[1];
             $thumbMime = $thumbInfo['mime'];
             $thumbPosition = $this->_getPositions($multiprofile->watermark_location, $thumbWidth, $thumbHeight, $watermarkWidth, $watermarkHeight);
             CImageHelper::addWatermark($thumbPath, $thumbPath, $thumbMime, $watermarkPath, $thumbPosition->x, $thumbPosition->y);
             $multiprofile->thumb = CString::str_ireplace('/', '/', COMMUNITY_WATERMARKS_PATH) . '/' . $thumbFileName;
             // Since the default thumbnail is used by current users, we need to update their existing values.
             $multiprofile->updateUserDefaultImage('avatar', $oldDefaultAvatar);
             $multiprofile->updateUserDefaultImage('thumb', $oldDefaultThumb);
             $multiprofile->watermark_hash = $watermark_hash;
             $multiprofile->store();
         }
         // Since it would be very tedious to check if previous fields were enabled or disabled.
         // We delete all existing mapping and remap it again to ensure data integrity.
         if (!$isNew && empty($fields)) {
             $multiprofile->deleteChilds();
         }
         if (!empty($fields)) {
             $parents = array();
             // We need to unique the parents first.
             foreach ($fields as $id) {
                 $customProfile = JTable::getInstance('Profiles', 'CommunityTable');
                 $customProfile->load($id);
                 // Need to only
                 $parent = $customProfile->getCurrentParentId();
                 if (in_array($parent, $tmpParents)) {
                     $parents[] = $parent;
                 }
             }
             $parents = array_unique($parents);
             $fields = array_merge($fields, $parents);
             $fieldTable = JTable::getInstance('MultiProfileFields', 'CTable');
             $fieldTable->cleanField($multiprofile->id);
             foreach ($fields as $id) {
                 $field = JTable::getInstance('MultiProfileFields', 'CTable');
                 $field->parent = $multiprofile->id;
                 $field->field_id = $id;
                 $field->store();
             }
         }
         if ($isNew) {
             $message = JText::_('COM_COMMUNITY_MULTIPROFILE_CREATED_SUCCESSFULLY');
         } else {
             $message = JText::_('COM_COMMUNITY_MULTIPROFILE_UPDATED_SUCCESSFULLY');
         }
         switch ($task) {
             case 'apply':
                 $link = 'index.php?option=com_community&view=multiprofile&layout=edit&id=' . $multiprofile->id;
                 break;
             case 'save':
             default:
                 $link = 'index.php?option=com_community&view=multiprofile';
                 break;
         }
         $mainframe->redirect($link, $message, 'message');
         return;
     }
     $document = JFactory::getDocument();
     $viewName = JRequest::getCmd('view', 'community');
     // Get the view type
     $viewType = $document->getType();
     // Get the view
     $view = $this->getView($viewName, $viewType);
     $view->setLayout('edit');
     $model = $this->getModel('Profiles');
     if ($model) {
         $view->setModel($model, $viewName);
     }
     $view->display();
 }
コード例 #8
0
ファイル: profile.php プロジェクト: joshjim27/jobsglobal
 /**
  * Upload a new user avatar, called from the profile/change avatar page
  */
 public function uploadAvatar()
 {
     CFactory::setActiveProfile();
     jimport('joomla.filesystem.file');
     jimport('joomla.utilities.utility');
     $view = $this->getView('profile');
     $mainframe = JFactory::getApplication();
     $jinput = $mainframe->input;
     $my = CFactory::getUser();
     if ($my->id == 0) {
         return $this->blockUnregister();
     }
     // If uplaod is detected, we process the uploaded avatar
     if ($jinput->post->get('action', '')) {
         $mainframe = JFactory::getApplication();
         $fileFilter = new JInput($_FILES);
         $file = $fileFilter->get('Filedata', '', 'array');
         $userid = $my->id;
         if ($jinput->post->get('userid', '', 'INT') != '') {
             $userid = JRequest::getInt('userid', '', 'POST');
             $url = CRoute::_('index.php?option=com_community&view=profile&userid=' . $userid);
             $my = CFactory::getUser($userid);
         }
         if (!isset($file['tmp_name']) || empty($file['tmp_name'])) {
             $mainframe->enqueueMessage(JText::_('COM_COMMUNITY_NO_POST_DATA'), 'error');
             if (isset($url)) {
                 $mainframe->redirect($url);
             }
         } else {
             $config = CFactory::getConfig();
             $uploadLimit = (double) $config->get('maxuploadsize');
             $uploadLimit = $uploadLimit * 1024 * 1024;
             // @rule: Limit image size based on the maximum upload allowed.
             if (filesize($file['tmp_name']) > $uploadLimit && $uploadLimit != 0) {
                 $mainframe->enqueueMessage(JText::sprintf('COM_COMMUNITY_VIDEOS_IMAGE_FILE_SIZE_EXCEEDED_MB', CFactory::getConfig()->get('maxuploadsize')), 'error');
                 if (isset($url)) {
                     $mainframe->redirect($url);
                 }
                 $mainframe->redirect(CRoute::_('index.php?option=com_community&view=profile&userid=' . $userid . '&task=uploadAvatar', false));
             }
             if (!CImageHelper::isValidType($file['type'])) {
                 $mainframe->enqueueMessage(JText::_('COM_COMMUNITY_IMAGE_FILE_NOT_SUPPORTED'), 'error');
                 if (isset($url)) {
                     $mainframe->redirect($url);
                 }
                 $mainframe->redirect(CRoute::_('index.php?option=com_community&view=profile&userid=' . $userid . '&task=uploadAvatar', false));
             }
             if (!CImageHelper::isValid($file['tmp_name'])) {
                 $mainframe->enqueueMessage(JText::_('COM_COMMUNITY_IMAGE_FILE_NOT_SUPPORTED'), 'error');
                 if (isset($url)) {
                     $mainframe->redirect($url);
                 }
             } else {
                 // @todo: configurable width?
                 //$imageMaxWidth    = 160;
                 //$imageMaxHeight   = 240;
                 // Get a hash for the file name.
                 $profileType = $my->getProfileType();
                 $fileName = JApplication::getHash($file['tmp_name'] . time());
                 $hashFileName = JString::substr($fileName, 0, 24);
                 $multiprofile = JTable::getInstance('MultiProfile', 'CTable');
                 $multiprofile->load($profileType);
                 $useWatermark = $profileType != COMMUNITY_DEFAULT_PROFILE && $config->get('profile_multiprofile') && !empty($multiprofile->watermark) ? true : false;
                 //@todo: configurable path for avatar storage?
                 $storage = JPATH_ROOT . '/' . $config->getString('imagefolder') . '/avatar';
                 /* physical path */
                 $storageImage = $storage . '/' . $hashFileName . CImageHelper::getExtension($file['type']);
                 $storageThumbnail = $storage . '/thumb_' . $hashFileName . CImageHelper::getExtension($file['type']);
                 /**
                  * reverse image use for cropping feature
                  * @uses <type>-<hashFileName>.<ext>
                  */
                 $storageReserve = $storage . '/profile-' . $hashFileName . CImageHelper::getExtension($file['type']);
                 /* relative path to save in database */
                 $image = $config->getString('imagefolder') . '/avatar/' . $hashFileName . CImageHelper::getExtension($file['type']);
                 $thumbnail = $config->getString('imagefolder') . '/avatar/' . 'thumb_' . $hashFileName . CImageHelper::getExtension($file['type']);
                 // filename for stream attachment
                 $imageAttachment = $config->getString('imagefolder') . '/avatar/' . $hashFileName . '_stream_' . CImageHelper::getExtension($file['type']);
                 $userModel = CFactory::getModel('user');
                 //Minimum height/width checking for Avatar uploads
                 list($currentWidth, $currentHeight) = getimagesize($file['tmp_name']);
                 /**
                  * Do square avatar 160x160
                  * @since 3.0
                  */
                 if ($currentWidth < COMMUNITY_AVATAR_PROFILE_WIDTH || $currentHeight < COMMUNITY_AVATAR_PROFILE_HEIGHT) {
                     $mainframe->enqueueMessage(JText::sprintf('COM_COMMUNITY_ERROR_MINIMUM_AVATAR_DIMENSION', COMMUNITY_AVATAR_PROFILE_WIDTH, COMMUNITY_AVATAR_PROFILE_HEIGHT), 'error');
                     $mainframe->redirect(CRoute::_('index.php?option=com_community&view=profile&task=uploadAvatar', false));
                 }
                 //					// Only resize when the width exceeds the max.
                 //					if ( ! CImageHelper::resizeProportional($file['tmp_name'], $storageImage, $file['type'], $imageMaxWidth, $imageMaxHeight))
                 //					{
                 //						$mainframe->enqueueMessage(JText::sprintf('COM_COMMUNITY_ERROR_MOVING_UPLOADED_FILE', $storageImage), 'error');
                 //
                 //						if (isset($url))
                 //						{
                 //							$mainframe->redirect($url);
                 //						}
                 //					}
                 /**
                  * Generate square avatar
                  */
                 if (!CImageHelper::createThumb($file['tmp_name'], $storageImage, $file['type'], COMMUNITY_AVATAR_PROFILE_WIDTH, COMMUNITY_AVATAR_PROFILE_HEIGHT)) {
                     $mainframe->enqueueMessage(JText::sprintf('COM_COMMUNITY_ERROR_MOVING_UPLOADED_FILE', $storageImage), 'error');
                     if (isset($url)) {
                         $mainframe->redirect($url);
                     }
                 }
                 // Generate thumbnail
                 if (!CImageHelper::createThumb($file['tmp_name'], $storageThumbnail, $file['type'])) {
                     $mainframe->enqueueMessage(JText::sprintf('COM_COMMUNITY_ERROR_MOVING_UPLOADED_FILE', $storageThumbnail), 'error');
                     if (isset($url)) {
                         $mainframe->redirect($url);
                     }
                 }
                 /**
                  * Generate large image use for avatar thumb cropping
                  * It must be larget than profile avatar size because we'll use it for profile avatar recrop also
                  */
                 if ($currentWidth >= $currentHeight) {
                     if (!CImageHelper::resizeProportional($file['tmp_name'], $storageReserve, $file['type'], 0, COMMUNITY_AVATAR_RESERVE_HEIGHT)) {
                         $this->_showUploadError(true, JText::sprintf('COM_COMMUNITY_ERROR_MOVING_UPLOADED_FILE', $storageReserve));
                         return;
                     }
                 } else {
                     if (!CImageHelper::resizeProportional($file['tmp_name'], $storageReserve, $file['type'], COMMUNITY_AVATAR_RESERVE_WIDTH, 0)) {
                         $this->_showUploadError(true, JText::sprintf('COM_COMMUNITY_ERROR_MOVING_UPLOADED_FILE', $storageReserve));
                         return;
                     }
                 }
                 if ($useWatermark) {
                     // @rule: Before adding the watermark, we should copy the user's original image so that when the admin tries to reset the avatar,
                     // it will be able to grab the original picture.
                     if (!JFolder::exists(JPATH_ROOT . '/images/watermarks/original/')) {
                         JFolder::create(JPATH_ROOT . '/images/watermarks/original/');
                     }
                     JFile::copy($storageImage, JPATH_ROOT . '/images/watermarks/original/' . md5($my->id . '_avatar') . CImageHelper::getExtension($file['type']));
                     JFile::copy($storageThumbnail, JPATH_ROOT . '/images/watermarks/original/' . md5($my->id . '_thumb') . CImageHelper::getExtension($file['type']));
                     $watermarkPath = JPATH_ROOT . '/' . CString::str_ireplace('/', '/', $multiprofile->watermark);
                     list($watermarkWidth, $watermarkHeight) = getimagesize($watermarkPath);
                     list($avatarWidth, $avatarHeight) = getimagesize($storageImage);
                     list($thumbWidth, $thumbHeight) = getimagesize($storageThumbnail);
                     $watermarkImage = $storageImage;
                     $watermarkThumbnail = $storageThumbnail;
                     // Avatar Properties
                     $avatarPosition = CImageHelper::getPositions($multiprofile->watermark_location, $avatarWidth, $avatarHeight, $watermarkWidth, $watermarkHeight);
                     // The original image file will be removed from the system once it generates a new watermark image.
                     CImageHelper::addWatermark($storageImage, $watermarkImage, $file['type'], $watermarkPath, $avatarPosition->x, $avatarPosition->y);
                     //Thumbnail Properties
                     $thumbPosition = CImageHelper::getPositions($multiprofile->watermark_location, $thumbWidth, $thumbHeight, $watermarkWidth, $watermarkHeight);
                     // The original thumbnail file will be removed from the system once it generates a new watermark image.
                     CImageHelper::addWatermark($storageThumbnail, $watermarkThumbnail, $file['type'], $watermarkPath, $thumbPosition->x, $thumbPosition->y);
                     $my->set('_watermark_hash', $multiprofile->watermark_hash);
                     $my->save();
                 }
                 // Autorotate avatar based on EXIF orientation value
                 if ($file['type'] == 'image/jpeg') {
                     $orientation = CImageHelper::getOrientation($file['tmp_name']);
                     CImageHelper::autoRotate($storageImage, $orientation);
                     CImageHelper::autoRotate($storageThumbnail, $orientation);
                     CImageHelper::autoRotate($storageReserve, $orientation);
                 }
                 // @todo: Change to use table code and get rid of model code
                 $userModel->setImage($userid, $image, 'avatar');
                 $userModel->setImage($userid, $thumbnail, 'thumb');
                 // Update the user object so that the profile picture gets updated.
                 $my->set('_avatar', $image);
                 $my->set('_thumb', $thumbnail);
                 // @rule: once user changes their profile picture, storage method should always be file.
                 $my->set('_storage', 'file');
                 if (isset($url)) {
                     $mainframe->redirect($url);
                 }
                 // Generate activity stream.
                 $this->_addAvatarUploadActivity($userid, $thumbnail);
                 $this->cacheClean(array(COMMUNITY_CACHE_TAG_ACTIVITIES, COMMUNITY_CACHE_TAG_FRONTPAGE));
             }
         }
     }
     echo $view->get(__FUNCTION__);
 }
コード例 #9
0
ファイル: facebook.php プロジェクト: Jougito/DynWeb
 public function mapAvatar($avatarUrl = '', $joomlaUserId, $addWaterMark)
 {
     $image = '';
     if (!empty($avatarUrl)) {
         // Make sure user is properly added into the database table first
         $user = CFactory::getUser($joomlaUserId);
         $fbUser = $this->getUser();
         // Store image on a temporary folder.
         $tmpPath = JPATH_ROOT . '/images/originalphotos/facebook_connect_' . $fbUser;
         // Need to extract the non-https version since it will cause
         // certificate issue
         $avatarUrl = str_replace('https://', 'http://', $avatarUrl);
         $source = CRemoteHelper::getContent($avatarUrl, true);
         list($headers, $source) = explode("\r\n\r\n", $source, 2);
         JFile::write($tmpPath, $source);
         // @todo: configurable width?
         $imageMaxWidth = 160;
         // Get a hash for the file name.
         $fileName = JApplication::getHash($fbUser . time());
         $hashFileName = JString::substr($fileName, 0, 24);
         $uri_parts = explode('?', $avatarUrl, 2);
         $extension = JString::substr($uri_parts[0], JString::strrpos($uri_parts[0], '.'));
         $type = 'image/jpg';
         if ($extension == '.png') {
             $type = 'image/png';
         }
         if ($extension == '.gif') {
             $type = 'image/gif';
         }
         //@todo: configurable path for avatar storage?
         $config = CFactory::getConfig();
         $storage = JPATH_ROOT . '/' . $config->getString('imagefolder') . '/avatar';
         $storageImage = $storage . '/' . $hashFileName . $extension;
         $storageThumbnail = $storage . '/thumb_' . $hashFileName . $extension;
         $image = $config->getString('imagefolder') . '/avatar/' . $hashFileName . $extension;
         $thumbnail = $config->getString('imagefolder') . '/avatar/' . 'thumb_' . $hashFileName . $extension;
         $userModel = CFactory::getModel('user');
         // Only resize when the width exceeds the max.
         CImageHelper::resizeProportional($tmpPath, $storageImage, $type, $imageMaxWidth);
         CImageHelper::createThumb($tmpPath, $storageThumbnail, $type);
         if ($addWaterMark) {
             // Get the width and height so we can calculate where to place the watermark.
             list($watermarkWidth, $watermarkHeight) = getimagesize(FACEBOOK_FAVICON);
             list($imageWidth, $imageHeight) = getimagesize($storageImage);
             list($thumbWidth, $thumbHeight) = getimagesize($storageThumbnail);
             CImageHelper::addWatermark($storageImage, $storageImage, $type, FACEBOOK_FAVICON, $imageWidth - $watermarkWidth, $imageHeight - $watermarkHeight);
             CImageHelper::addWatermark($storageThumbnail, $storageThumbnail, $type, FACEBOOK_FAVICON, $thumbWidth - $watermarkWidth, $thumbHeight - $watermarkHeight);
         }
         // Update the CUser object with the correct avatar.
         $user->set('_thumb', $thumbnail);
         $user->set('_avatar', $image);
         // @rule: once user changes their profile picture, storage method should always be file.
         $user->set('_storage', 'file');
         $userModel->setImage($joomlaUserId, $image, 'avatar');
         $userModel->setImage($joomlaUserId, $thumbnail, 'thumb');
         $user->save();
     }
 }
コード例 #10
0
ファイル: register.php プロジェクト: bizanto/Hooked
 /**
  * Upload a new user avatar
  */
 public function registerAvatar()
 {
     $mainframe =& JFactory::getApplication();
     jimport('joomla.filesystem.file');
     jimport('joomla.utilities.utility');
     $mySess =& JFactory::getSession();
     $user = $mySess->get('tmpUser', '');
     if (empty($user)) {
         //throw error.
         JError::raiseError(500, JText::_('CC REGISTRATION MISSING USER OBJ'));
         return;
     }
     //CFactory::setActiveProfile($user->id);
     $view =& $this->getView('register');
     CFactory::load('helpers', 'image');
     $profileType = JRequest::getInt('profileType', 0);
     // If uplaod is detected, we process the uploaded avatar
     if (JRequest::getVar('action', '', 'POST')) {
         // Load avatar library
         CFactory::load('libraries', 'avatar');
         $my = CFactory::getUser($user->id);
         $file = JRequest::getVar('Filedata', '', 'FILES', 'array');
         if ($my->id == 0) {
             return $this->blockUnregister();
         }
         if (!isset($file['tmp_name']) || empty($file['tmp_name'])) {
             $mainframe->enqueueMessage(JText::_('CC NO POST DATA'), 'error');
         } else {
             if (!CImageHelper::isValid($file['tmp_name'])) {
                 $mainframe->enqueueMessage(JText::_('CC IMAGE FILE NOT SUPPORTED'), 'error');
             } else {
                 $config = CFactory::getConfig();
                 $useWatermark = $profileType != COMMUNITY_DEFAULT_PROFILE && $config->get('profile_multiprofile') ? true : false;
                 // @todo: configurable width?
                 $imageMaxWidth = 160;
                 // Get a hash for the file name.
                 $fileName = JUtility::getHash($file['tmp_name'] . time());
                 $hashFileName = JString::substr($fileName, 0, 24);
                 //@todo: configurable path for avatar storage?
                 $config = CFactory::getConfig();
                 $storage = JPATH_ROOT . DS . $config->getString('imagefolder') . DS . 'avatar';
                 $storageImage = $storage . DS . $hashFileName . CImageHelper::getExtension($file['type']);
                 $storageThumbnail = $storage . DS . 'thumb_' . $hashFileName . CImageHelper::getExtension($file['type']);
                 $image = $config->getString('imagefolder') . '/avatar/' . $hashFileName . CImageHelper::getExtension($file['type']);
                 $thumbnail = $config->getString('imagefolder') . '/avatar/' . 'thumb_' . $hashFileName . CImageHelper::getExtension($file['type']);
                 $userModel = CFactory::getModel('user');
                 // Generate full image
                 if (!CImageHelper::resizeProportional($file['tmp_name'], $storageImage, $file['type'], $imageMaxWidth)) {
                     $mainframe->enqueueMessage(JText::sprintf('CC ERROR MOVING UPLOADED FILE', $storageImage), 'error');
                 }
                 // Generate thumbnail
                 if (!CImageHelper::createThumb($file['tmp_name'], $storageThumbnail, $file['type'])) {
                     $mainframe->enqueueMessage(JText::sprintf('CC ERROR MOVING UPLOADED FILE', $storageThumbnail), 'error');
                 }
                 if ($useWatermark) {
                     // @rule: Before adding the watermark, we should copy the user's original image so that when the admin tries to reset the avatar,
                     // it will be able to grab the original picture.
                     JFile::copy($storageImage, JPATH_ROOT . DS . 'images' . DS . 'watermarks' . DS . 'original' . DS . md5($my->id . '_avatar') . CImageHelper::getExtension($file['type']));
                     JFile::copy($storageThumbnail, JPATH_ROOT . DS . 'images' . DS . 'watermarks' . DS . 'original' . DS . md5($my->id . '_thumb') . CImageHelper::getExtension($file['type']));
                     $multiprofile =& JTable::getInstance('MultiProfile', 'CTable');
                     $multiprofile->load($profileType);
                     $watermarkPath = JPATH_ROOT . DS . JString::str_ireplace('/', DS, $multiprofile->watermark);
                     list($watermarkWidth, $watermarkHeight) = getimagesize($watermarkPath);
                     list($avatarWidth, $avatarHeight) = getimagesize($storageImage);
                     list($thumbWidth, $thumbHeight) = getimagesize($storageThumbnail);
                     $watermarkImage = $storageImage;
                     $watermarkThumbnail = $storageThumbnail;
                     // Avatar Properties
                     $avatarPosition = CImageHelper::getPositions($multiprofile->watermark_location, $avatarWidth, $avatarHeight, $watermarkWidth, $watermarkHeight);
                     // The original image file will be removed from the system once it generates a new watermark image.
                     CImageHelper::addWatermark($storageImage, $watermarkImage, 'image/jpg', $watermarkPath, $avatarPosition->x, $avatarPosition->y);
                     //Thumbnail Properties
                     $thumbPosition = CImageHelper::getPositions($multiprofile->watermark_location, $thumbWidth, $thumbHeight, $watermarkWidth, $watermarkHeight);
                     // The original thumbnail file will be removed from the system once it generates a new watermark image.
                     CImageHelper::addWatermark($storageThumbnail, $watermarkThumbnail, 'image/jpg', $watermarkPath, $thumbPosition->x, $thumbPosition->y);
                     $my->set('_watermark_hash', $multiprofile->watermark_hash);
                     $my->save();
                 }
                 // Since this is a new registration, we definitely do not want to remove the old image.
                 $removeOldImage = false;
                 $userModel->setImage($my->id, $image, 'avatar', $removeOldImage);
                 $userModel->setImage($my->id, $thumbnail, 'thumb', $removeOldImage);
                 // Update the user object so that the profile picture gets updated.
                 $my->set('_avatar', $image);
                 $my->set('_thumb', $thumbnail);
             }
         }
         //redirect to successful page
         $mainframe->redirect(CRoute::_('index.php?option=com_community&view=register&task=registerSucess&profileType=' . $profileType, false));
     }
     echo $view->get(__FUNCTION__);
 }
コード例 #11
0
ファイル: profile.php プロジェクト: bizanto/Hooked
 /**
  * Upload a new user avatar
  */
 public function uploadAvatar()
 {
     CFactory::setActiveProfile();
     jimport('joomla.filesystem.file');
     jimport('joomla.utilities.utility');
     $view =& $this->getView('profile');
     CFactory::load('helpers', 'image');
     $my = CFactory::getUser();
     if ($my->id == 0) {
         return $this->blockUnregister();
     }
     // If uplaod is detected, we process the uploaded avatar
     if (JRequest::getVar('action', '', 'POST')) {
         $mainframe =& JFactory::getApplication();
         $file = JRequest::getVar('Filedata', '', 'FILES', 'array');
         $userid = $my->id;
         if (JRequest::getVar('userid', '', 'POST') != '') {
             $userid = JRequest::getInt('userid', '', 'POST');
             $url = CRoute::_('index.php?option=com_community&view=profile&userid=' . $userid);
         }
         if (!isset($file['tmp_name']) || empty($file['tmp_name'])) {
             $mainframe->enqueueMessage(JText::_('CC NO POST DATA'), 'error');
             if (isset($url)) {
                 $mainframe->redirect($url);
             }
         } else {
             $config = CFactory::getConfig();
             $uploadLimit = (double) $config->get('maxuploadsize');
             $uploadLimit = $uploadLimit * 1024 * 1024;
             // @rule: Limit image size based on the maximum upload allowed.
             if (filesize($file['tmp_name']) > $uploadLimit && $uploadLimit != 0) {
                 $mainframe->enqueueMessage(JText::_('CC IMAGE FILE SIZE EXCEEDED'), 'error');
                 if (isset($url)) {
                     $mainframe->redirect($url);
                 }
                 $mainframe->redirect(CRoute::_('index.php?option=com_community&view=profile&userid=' . $userid . '&task=uploadAvatar', false));
             }
             if (!CImageHelper::isValidType($file['type'])) {
                 $mainframe->enqueueMessage(JText::_('CC IMAGE FILE NOT SUPPORTED'), 'error');
                 if (isset($url)) {
                     $mainframe->redirect($url);
                 }
                 $mainframe->redirect(CRoute::_('index.php?option=com_community&view=profile&userid=' . $userid . '&task=uploadAvatar', false));
             }
             if (!CImageHelper::isValid($file['tmp_name'])) {
                 $mainframe->enqueueMessage(JText::_('CC IMAGE FILE NOT SUPPORTED'), 'error');
                 if (isset($url)) {
                     $mainframe->redirect($url);
                 }
             } else {
                 // @todo: configurable width?
                 $imageMaxWidth = 160;
                 // Get a hash for the file name.
                 $profileType = $my->getProfileType();
                 $fileName = JUtility::getHash($file['tmp_name'] . time());
                 $hashFileName = JString::substr($fileName, 0, 24);
                 $multiprofile =& JTable::getInstance('MultiProfile', 'CTable');
                 $multiprofile->load($profileType);
                 $useWatermark = $profileType != COMMUNITY_DEFAULT_PROFILE && $config->get('profile_multiprofile') && !empty($multiprofile->watermark) ? true : false;
                 //@todo: configurable path for avatar storage?
                 $storage = JPATH_ROOT . DS . $config->getString('imagefolder') . DS . 'avatar';
                 $storageImage = $storage . DS . $hashFileName . CImageHelper::getExtension($file['type']);
                 $storageThumbnail = $storage . DS . 'thumb_' . $hashFileName . CImageHelper::getExtension($file['type']);
                 $image = $config->getString('imagefolder') . '/avatar/' . $hashFileName . CImageHelper::getExtension($file['type']);
                 $thumbnail = $config->getString('imagefolder') . '/avatar/' . 'thumb_' . $hashFileName . CImageHelper::getExtension($file['type']);
                 $userModel = CFactory::getModel('user');
                 // Only resize when the width exceeds the max.
                 if (!CImageHelper::resizeProportional($file['tmp_name'], $storageImage, $file['type'], $imageMaxWidth)) {
                     $mainframe->enqueueMessage(JText::sprintf('CC ERROR MOVING UPLOADED FILE', $storageImage), 'error');
                     if (isset($url)) {
                         $mainframe->redirect($url);
                     }
                 }
                 // Generate thumbnail
                 if (!CImageHelper::createThumb($file['tmp_name'], $storageThumbnail, $file['type'])) {
                     $mainframe->enqueueMessage(JText::sprintf('CC ERROR MOVING UPLOADED FILE', $storageThumbnail), 'error');
                     if (isset($url)) {
                         $mainframe->redirect($url);
                     }
                 }
                 if ($useWatermark) {
                     // @rule: Before adding the watermark, we should copy the user's original image so that when the admin tries to reset the avatar,
                     // it will be able to grab the original picture.
                     JFile::copy($storageImage, JPATH_ROOT . DS . 'images' . DS . 'watermarks' . DS . 'original' . DS . md5($my->id . '_avatar') . CImageHelper::getExtension($file['type']));
                     JFile::copy($storageThumbnail, JPATH_ROOT . DS . 'images' . DS . 'watermarks' . DS . 'original' . DS . md5($my->id . '_thumb') . CImageHelper::getExtension($file['type']));
                     $watermarkPath = JPATH_ROOT . DS . JString::str_ireplace('/', DS, $multiprofile->watermark);
                     list($watermarkWidth, $watermarkHeight) = getimagesize($watermarkPath);
                     list($avatarWidth, $avatarHeight) = getimagesize($storageImage);
                     list($thumbWidth, $thumbHeight) = getimagesize($storageThumbnail);
                     $watermarkImage = $storageImage;
                     $watermarkThumbnail = $storageThumbnail;
                     // Avatar Properties
                     $avatarPosition = CImageHelper::getPositions($multiprofile->watermark_location, $avatarWidth, $avatarHeight, $watermarkWidth, $watermarkHeight);
                     // The original image file will be removed from the system once it generates a new watermark image.
                     CImageHelper::addWatermark($storageImage, $watermarkImage, 'image/jpg', $watermarkPath, $avatarPosition->x, $avatarPosition->y);
                     //Thumbnail Properties
                     $thumbPosition = CImageHelper::getPositions($multiprofile->watermark_location, $thumbWidth, $thumbHeight, $watermarkWidth, $watermarkHeight);
                     // The original thumbnail file will be removed from the system once it generates a new watermark image.
                     CImageHelper::addWatermark($storageThumbnail, $watermarkThumbnail, 'image/jpg', $watermarkPath, $thumbPosition->x, $thumbPosition->y);
                     $my->set('_watermark_hash', $multiprofile->watermark_hash);
                     $my->save();
                 }
                 $userModel->setImage($userid, $image, 'avatar');
                 $userModel->setImage($userid, $thumbnail, 'thumb');
                 // Update the user object so that the profile picture gets updated.
                 $my->set('_avatar', $image);
                 $my->set('_thumb', $thumbnail);
                 // @rule: once user changes their profile picture, storage method should always be file.
                 $my->set('_storage', 'file');
                 if (isset($url)) {
                     $mainframe->redirect($url);
                 }
                 //add user points
                 CFactory::load('libraries', 'userpoints');
                 CFactory::load('libraries', 'activities');
                 $act = new stdClass();
                 $act->cmd = 'profile.avatar.upload';
                 $act->actor = $userid;
                 $act->target = 0;
                 $act->title = JText::_('CC ACTIVITIES NEW AVATAR');
                 $act->content = '';
                 $act->app = 'profile';
                 $act->cid = 0;
                 // Add activity logging
                 CFactory::load('libraries', 'activities');
                 CActivityStream::add($act);
                 CUserPoints::assignPoint('profile.avatar.upload');
             }
         }
     }
     echo $view->get(__FUNCTION__);
 }
コード例 #12
0
ファイル: photo.php プロジェクト: joshjim27/jobsglobal
 /**
  * Overrides parent store function as we need to clean up some variables
  * */
 public function store($updateNulls = false)
 {
     if (!$this->check()) {
         return false;
     }
     $this->image = CString::str_ireplace('\\', '/', $this->image);
     $this->thumbnail = CString::str_ireplace('\\', '/', $this->thumbnail);
     $this->original = CString::str_ireplace('\\', '/', $this->original);
     // Store params
     $this->params = $this->_params->toString();
     //lets add watermark if there is any and only for new photos
     if (CPhotosHelper::photoWatermarkEnabled() && !$this->id) {
         $config = CFactory::getConfig();
         $watermark = JPATH_ROOT . '/' . COMMUNITY_WATERMARKS_PATH . '/' . WATERMARK_DEFAULT_NAME . '.png';
         list($watermarkWidth, $watermarkHeight) = getimagesize($watermark);
         //original photo
         $thumbPath = JPATH_ROOT . '/' . $this->original;
         if (file_exists($thumbPath)) {
             $thumbInfo = getimagesize($thumbPath);
             $thumbWidth = $thumbInfo[0];
             $thumbHeight = $thumbInfo[1];
             $thumbMime = $thumbInfo['mime'];
             if ($config->get('min_width_img_watermark') <= $thumbWidth && $config->get('min_height_img_watermark') <= $thumbHeight && $thumbHeight >= $watermarkHeight && $thumbWidth >= $watermarkWidth) {
                 $thumbPosition = $this->_getPositions($config->get('watermark_position'), $thumbWidth, $thumbHeight, $watermarkWidth, $watermarkHeight);
                 CImageHelper::addWatermark($thumbPath, $thumbPath, $thumbMime, $watermark, $thumbPosition->x, $thumbPosition->y);
             }
         }
     }
     //do not use the photo name as the caption for the first time when uploaded
     if (!$this->id) {
         $this->caption = '';
     }
     $result = parent::store();
     if ($this->status != 'temp' && $result) {
         // Changes in photos will affect the album. Do a store on album
         $album = JTable::getInstance('Album', 'CTable');
         $album->load($this->albumid);
         $album->store();
     }
     return $result;
 }
コード例 #13
0
ファイル: multiprofile.php プロジェクト: Simarpreet05/joomla
 public function save()
 {
     jimport('joomla.filesystem.folder');
     jimport('joomla.filesystem.file');
     CFactory::load('helpers', 'image');
     $id = JRequest::getInt('id', 0, 'POST');
     $post = JRequest::get('POST');
     $fields = JRequest::getVar('fields', '');
     $name = JRequest::getVar('name', '');
     $tmpParents = JRequest::getVar('parents', '');
     $mainframe =& JFactory::getApplication();
     $isNew = $id == 0 ? true : false;
     $multiprofile =& JTable::getInstance('MultiProfile', 'CTable');
     $multiprofile->load($id);
     $multiprofile->bind($post);
     // Can't have an empty name now can we?
     if (empty($name)) {
         $mainframe->enqueueMessage(JText::_('COM_COMMUNITY_MULTIPROFILE_NAME_EMPTY'), 'error');
         $mainframe->redirect('index.php?option=com_community&view=multiprofile&layout=edit');
         return;
     }
     $date =& JFactory::getDate();
     $isNew = $multiprofile->id == 0;
     if ($isNew) {
         $multiprofile->created = $date->toMySQL();
     }
     // Store watermarks for profile types.
     $watermark = JRequest::getVar('watermark', '', 'FILES');
     // Do not allow image size to exceed maximum width and height
     if (isset($watermark['name']) && !empty($watermark['name'])) {
         list($width, $height) = getimagesize($watermark['tmp_name']);
         if ($width > 64 || $height > 64) {
             $mainframe->redirect('index.php?option=com_community&view=multiprofile&layout=edit', JText::_('COM_COMMUNITY_MULTIPROFILE_WATERMARK_IMAGE_EXCEEDS_SIZE'), 'error');
             exit;
         }
     }
     $multiprofile->store();
     // If image file is specified, we need to store the thumbnail.
     if (isset($watermark['name']) && !empty($watermark['name'])) {
         $watermarkFile = 'watermark_' . $multiprofile->id . CImageHelper::getExtension($watermark['type']);
         JFile::copy($watermark['tmp_name'], JPATH_ROOT . DS . COMMUNITY_WATERMARKS_PATH . DS . $watermarkFile);
         $multiprofile->watermark = CString::str_ireplace(DS, '/', COMMUNITY_WATERMARKS_PATH) . '/' . $watermarkFile;
         $multiprofile->store();
     }
     // @rule: Create the watermarks folder if doesn't exists.
     if (!JFolder::exists(COMMUNITY_WATERMARKS_PATH)) {
         if (!JFolder::create(COMMUNITY_WATERMARKS_PATH)) {
             $mainframe->enqueueMessage(JText::_('COM_COMMUNITY_MULTIPROFILE_UNABLE_TO_CREATE_WATERMARKS_FOLDER'));
         }
     }
     // @rule: Create original folder within watermarks to store original user photos.
     if (!JFolder::exists(COMMUNITY_WATERMARKS_PATH . DS . 'original')) {
         if (!JFolder::create(COMMUNITY_WATERMARKS_PATH . DS . 'original')) {
             $mainframe->enqueueMessage(JText::_('COM_COMMUNITY_MULTIPROFILE_UNABLE_TO_CREATE_WATERMARKS_FOLDER'));
         }
     }
     // Create default watermarks for avatar and thumbnails.
     if (isset($watermark['name']) && !empty($watermark['name']) || !empty($multiprofile->watermark)) {
         CFactory::load('helpers', 'image');
         // Generate filename
         $fileName = CImageHelper::getHashName($multiprofile->id . time()) . '.jpg';
         $thumbFileName = 'thumb_' . $fileName;
         // Paths where the thumbnail and avatar should be saved.
         $thumbPath = JPATH_ROOT . DS . COMMUNITY_WATERMARKS_PATH . DS . $thumbFileName;
         $avatarPath = JPATH_ROOT . DS . COMMUNITY_WATERMARKS_PATH . DS . $fileName;
         // Copy existing default thumbnails into the path first.
         JFile::copy(JPATH_ROOT . DS . DEFAULT_USER_THUMB, $thumbPath);
         JFile::copy(JPATH_ROOT . DS . DEFAULT_USER_AVATAR, $avatarPath);
         $watermarkPath = $watermark['tmp_name'];
         list($watermarkWidth, $watermarkHeight) = getimagesize($watermarkPath);
         $oldDefaultAvatar = $multiprofile->avatar;
         $oldDefaultThumb = $multiprofile->thumb;
         // Avatar Properties
         $avatarInfo = getimagesize($avatarPath);
         $avatarWidth = $avatarInfo[0];
         $avatarHeight = $avatarInfo[1];
         $avatarMime = $avatarInfo['mime'];
         $avatarPosition = $this->_getPositions($multiprofile->watermark_location, $avatarWidth, $avatarHeight, $watermarkWidth, $watermarkHeight);
         CImageHelper::addWatermark($avatarPath, $avatarPath, 'image/jpg', $watermarkPath, $avatarPosition->x, $avatarPosition->y);
         $multiprofile->avatar = CString::str_ireplace(DS, '/', COMMUNITY_WATERMARKS_PATH) . '/' . $fileName;
         // Thumbnail properties.
         $thumbInfo = getimagesize($thumbPath);
         $thumbWidth = $thumbInfo[0];
         $thumbHeight = $thumbInfo[1];
         $thumbMime = $thumbInfo['mime'];
         $thumbPosition = $this->_getPositions($multiprofile->watermark_location, $thumbWidth, $thumbHeight, $watermarkWidth, $watermarkHeight);
         CImageHelper::addWatermark($thumbPath, $thumbPath, $thumbMime, $watermarkPath, $thumbPosition->x, $thumbPosition->y);
         $multiprofile->thumb = CString::str_ireplace(DS, '/', COMMUNITY_WATERMARKS_PATH) . '/' . $thumbFileName;
         // Since the default thumbnail is used by current users, we need to update their existing values.
         $multiprofile->updateUserDefaultImage('avatar', $oldDefaultAvatar);
         $multiprofile->updateUserDefaultImage('thumb', $oldDefaultThumb);
         $multiprofile->watermark_hash = md5($watermark['name'] . time());
         $multiprofile->store();
     }
     // Since it would be very tedious to check if previous fields were enabled or disabled.
     // We delete all existing mapping and remap it again to ensure data integrity.
     if (!$isNew && !empty($fields)) {
         $multiprofile->deleteChilds();
     }
     if (!empty($fields)) {
         $parents = array();
         // We need to unique the parents first.
         foreach ($fields as $id) {
             $customProfile =& JTable::getInstance('Profiles', 'CommunityTable');
             $customProfile->load($id);
             // Need to only
             $parent = $customProfile->getCurrentParentId();
             if (in_array($parent, $tmpParents)) {
                 $parents[] = $parent;
             }
         }
         $parents = array_unique($parents);
         $fields = array_merge($fields, $parents);
         foreach ($fields as $id) {
             $field =& JTable::getInstance('MultiProfileFields', 'CTable');
             $field->parent = $multiprofile->id;
             $field->field_id = $id;
             $field->store();
         }
     }
     $message = JText::_('COM_COMMUNITY_MULTIPROFILE_UPDATED_SUCCESSFULLY');
     if ($isNew) {
         $message = JText::_('COM_COMMUNITY_MULTIPROFILE_CREATED_SUCCESSFULLY');
     }
     $mainframe->redirect('index.php?option=com_community&view=multiprofile', $message);
 }