public function Picture($UserReference = '') { $this->Permission('Garden.SignIn.Allow'); $Session = Gdn::Session(); if (!$Session->IsValid()) { $this->Form->AddError('You must be authenticated in order to use this form.'); } $this->GetUserInfo($UserReference); $this->Form->SetModel($this->UserModel); $this->Form->AddHidden('UserID', $this->User->UserID); if ($this->Form->AuthenticatedPostBack() === TRUE) { $UploadImage = new Gdn_UploadImage(); try { // Validate the upload $TmpImage = $UploadImage->ValidateUpload('Picture'); // Generate the target image name $TargetImage = $UploadImage->GenerateTargetName(PATH_ROOT . DS . 'uploads'); $ImageBaseName = pathinfo($TargetImage, PATHINFO_BASENAME); // Delete any previously uploaded images @unlink(PATH_ROOT . DS . 'uploads' . DS . 'p' . $this->User->Photo); // Don't delete this one because it hangs around in activity streams: // @unlink(PATH_ROOT . DS . 'uploads' . DS . 't' . $this->User->Photo); @unlink(PATH_ROOT . DS . 'uploads' . DS . 'n' . $this->User->Photo); // Save the uploaded image in profile size $UploadImage->SaveImageAs($TmpImage, PATH_ROOT . DS . 'uploads' . DS . 'p' . $ImageBaseName, Gdn::Config('Garden.Profile.MaxHeight', 1000), Gdn::Config('Garden.Profile.MaxWidth', 250)); // Save the uploaded image in preview size $UploadImage->SaveImageAs($TmpImage, PATH_ROOT . DS . 'uploads' . DS . 't' . $ImageBaseName, Gdn::Config('Garden.Preview.MaxHeight', 100), Gdn::Config('Garden.Preview.MaxWidth', 75)); // Save the uploaded image in thumbnail size $ThumbSize = Gdn::Config('Garden.Thumbnail.Size', 50); $UploadImage->SaveImageAs($TmpImage, PATH_ROOT . DS . 'uploads' . DS . 'n' . $ImageBaseName, $ThumbSize, $ThumbSize, TRUE); } catch (Exception $ex) { $this->Form->AddError($ex->getMessage()); } // If there were no errors, associate the image with the user if ($this->Form->ErrorCount() == 0) { $PhotoModel = new Gdn_Model('Photo'); $PhotoID = $PhotoModel->Insert(array('Name' => $ImageBaseName)); if (!$this->UserModel->Save(array('UserID' => $this->User->UserID, 'PhotoID' => $PhotoID, 'Photo' => $ImageBaseName))) { $this->Form->SetValidationResults($this->UserModel->ValidationResults()); } } // If there were no problems, redirect back to the user account if ($this->Form->ErrorCount() == 0) { Redirect('garden/profile/' . $UserReference); } } $this->Render(); }
public function Picture($UserReference = '', $Username = '') { $this->Permission('Garden.SignIn.Allow'); $Session = Gdn::Session(); if (!$Session->IsValid()) { $this->Form->AddError('You must be authenticated in order to use this form.'); } $ImageManipOk = FALSE; if (function_exists('gd_info')) { $GdInfo = gd_info(); $GdVersion = preg_replace('/[a-z ()]+/i', '', $GdInfo['GD Version']); if ($GdVersion < 2) { throw new Exception(sprintf(T("This installation of GD is too old (v%s). Vanilla requires at least version 2 or compatible."), $GdVersion)); } } else { throw new Exception(sprintf(T("Unable to detect PHP GD installed on this system. Vanilla requires GD version 2 or better."))); } $this->GetUserInfo($UserReference, $Username); $this->Form->SetModel($this->UserModel); $this->Form->AddHidden('UserID', $this->User->UserID); if ($this->Form->AuthenticatedPostBack() === TRUE) { $UploadImage = new Gdn_UploadImage(); try { // Validate the upload $TmpImage = $UploadImage->ValidateUpload('Picture'); // Generate the target image name $TargetImage = $UploadImage->GenerateTargetName(PATH_ROOT . DS . 'uploads'); $ImageBaseName = pathinfo($TargetImage, PATHINFO_BASENAME); // Delete any previously uploaded images @unlink(PATH_ROOT . DS . 'uploads' . DS . 'p' . $this->User->Photo); // Don't delete this one because it hangs around in activity streams: // @unlink(PATH_ROOT . DS . 'uploads' . DS . 't' . $this->User->Photo); @unlink(PATH_ROOT . DS . 'uploads' . DS . 'n' . $this->User->Photo); // Save the uploaded image in profile size $UploadImage->SaveImageAs($TmpImage, PATH_ROOT . DS . 'uploads' . DS . 'p' . $ImageBaseName, Gdn::Config('Garden.Profile.MaxHeight', 1000), Gdn::Config('Garden.Profile.MaxWidth', 250)); // Save the uploaded image in preview size $UploadImage->SaveImageAs($TmpImage, PATH_ROOT . DS . 'uploads' . DS . 't' . $ImageBaseName, Gdn::Config('Garden.Preview.MaxHeight', 100), Gdn::Config('Garden.Preview.MaxWidth', 75)); // Save the uploaded image in thumbnail size $ThumbSize = Gdn::Config('Garden.Thumbnail.Size', 50); $UploadImage->SaveImageAs($TmpImage, PATH_ROOT . DS . 'uploads' . DS . 'n' . $ImageBaseName, $ThumbSize, $ThumbSize, TRUE); } catch (Exception $ex) { $this->Form->AddError($ex->getMessage()); } // If there were no errors, associate the image with the user if ($this->Form->ErrorCount() == 0) { $PhotoModel = new Gdn_Model('Photo'); $PhotoID = $PhotoModel->Insert(array('Name' => $ImageBaseName)); if (!$this->UserModel->Save(array('UserID' => $this->User->UserID, 'PhotoID' => $PhotoID, 'Photo' => $ImageBaseName))) { $this->Form->SetValidationResults($this->UserModel->ValidationResults()); } } // If there were no problems, redirect back to the user account if ($this->Form->ErrorCount() == 0) { Redirect('dashboard/profile/' . $UserReference); } } $this->Render(); }