/** * Configuration of registration settings. */ public function Registration($RedirectUrl = '') { $this->Permission('Garden.Registration.Manage'); if (!C('Garden.Registration.Manage', TRUE)) { return Gdn::Dispatcher()->Dispatch('Default404'); } $this->AddSideMenu('dashboard/settings/registration'); $this->AddJsFile('registration.js'); $this->Title(T('Registration')); // Create a model to save configuration settings $Validation = new Gdn_Validation(); $ConfigurationModel = new Gdn_ConfigurationModel($Validation); $ConfigurationModel->SetField(array('Garden.Registration.Method' => 'Captcha', 'Garden.Registration.CaptchaPrivateKey', 'Garden.Registration.CaptchaPublicKey', 'Garden.Registration.InviteExpiration')); // Set the model on the forms. $this->Form->SetModel($ConfigurationModel); // Load roles with sign-in permission $RoleModel = new RoleModel(); $this->RoleData = $RoleModel->GetByPermission('Garden.SignIn.Allow'); // Get the currently selected default roles // $this->ExistingRoleData = Gdn::Config('Garden.Registration.DefaultRoles'); // if (is_array($this->ExistingRoleData) === FALSE) // $this->ExistingRoleData = array(); // Get currently selected InvitationOptions $this->ExistingRoleInvitations = Gdn::Config('Garden.Registration.InviteRoles'); if (is_array($this->ExistingRoleInvitations) === FALSE) { $this->ExistingRoleInvitations = array(); } // Get the currently selected Expiration Length $this->InviteExpiration = Gdn::Config('Garden.Registration.InviteExpiration', ''); // Registration methods. $this->RegistrationMethods = array('Captcha' => "New users fill out a simple form and are granted access immediately.", 'Approval' => "New users are reviewed and approved by an administrator (that's you!).", 'Invitation' => "Existing members send invitations to new members."); // Options for how many invitations a role can send out per month. $this->InvitationOptions = array('0' => T('None'), '1' => '1', '2' => '2', '5' => '5', '-1' => T('Unlimited')); // Options for when invitations should expire. $this->InviteExpirationOptions = array('-1 week' => T('1 week after being sent'), '-2 weeks' => T('2 weeks after being sent'), '-1 month' => T('1 month after being sent'), 'FALSE' => T('never')); if ($this->Form->AuthenticatedPostBack() === FALSE) { $this->Form->SetData($ConfigurationModel->Data); } else { // Define some validation rules for the fields being saved $ConfigurationModel->Validation->ApplyRule('Garden.Registration.Method', 'Required'); // if($this->Form->GetValue('Garden.Registration.Method') != 'Closed') // $ConfigurationModel->Validation->ApplyRule('Garden.Registration.DefaultRoles', 'RequiredArray'); // Define the Garden.Registration.RoleInvitations setting based on the postback values $InvitationRoleIDs = $this->Form->GetValue('InvitationRoleID'); $InvitationCounts = $this->Form->GetValue('InvitationCount'); $this->ExistingRoleInvitations = ArrayCombine($InvitationRoleIDs, $InvitationCounts); $ConfigurationModel->ForceSetting('Garden.Registration.InviteRoles', $this->ExistingRoleInvitations); // Save! if ($this->Form->Save() !== FALSE) { $this->StatusMessage = T("Your settings have been saved."); if ($RedirectUrl != '') { $this->RedirectUrl = $RedirectUrl; } } } $this->Render(); }
/** * Enabling and disabling categories from list. * * @since 2.0.0 * @access public */ public function ManageCategories() { // Check permission $this->Permission('Garden.Settings.Manage'); $this->AddSideMenu('vanilla/settings/managecategories'); $this->AddJsFile('categories.js'); $this->AddJsFile('js/library/jquery.alphanumeric.js'); // This now works on latest jQuery version 1.10.2 // // Jan29, 2014, upgraded jQuery UI to 1.10.3 from 1.8.11 $this->AddJsFile('js/library/nestedSortable/jquery-ui.min.js'); // Newer nestedSortable, but does not work. //$this->AddJsFile('js/library/nestedSortable/jquery.mjs.nestedSortable.js'); // old jquery-ui //$this->AddJsFile('js/library/nestedSortable.1.3.4/jquery-ui-1.8.11.custom.min.js'); $this->AddJsFile('js/library/nestedSortable.1.3.4/jquery.ui.nestedSortable.js'); $this->Title(T('Categories')); // Get category data $this->SetData('CategoryData', $this->CategoryModel->GetAll('TreeLeft'), TRUE); // Enable/Disable Categories if (Gdn::Session()->ValidateTransientKey(GetValue(1, $this->RequestArgs))) { $Toggle = GetValue(0, $this->RequestArgs, ''); if ($Toggle == 'enable') { SaveToConfig('Vanilla.Categories.Use', TRUE); } else { if ($Toggle == 'disable') { SaveToConfig('Vanilla.Categories.Use', FALSE); } } Redirect('vanilla/settings/managecategories'); } // Setup & save forms $Validation = new Gdn_Validation(); $ConfigurationModel = new Gdn_ConfigurationModel($Validation); $ConfigurationModel->SetField(array('Vanilla.Categories.MaxDisplayDepth', 'Vanilla.Categories.DoHeadings', 'Vanilla.Categories.HideModule')); // Set the model on the form. $this->Form->SetModel($ConfigurationModel); // Define MaxDepthOptions $DepthData = array(); $DepthData['2'] = sprintf(T('more than %s deep'), Plural(1, '%s level', '%s levels')); $DepthData['3'] = sprintf(T('more than %s deep'), Plural(2, '%s level', '%s levels')); $DepthData['4'] = sprintf(T('more than %s deep'), Plural(3, '%s level', '%s levels')); $DepthData['0'] = T('never'); $this->SetData('MaxDepthData', $DepthData); // If seeing the form for the first time... if ($this->Form->AuthenticatedPostBack() === FALSE) { // Apply the config settings to the form. $this->Form->SetData($ConfigurationModel->Data); } else { if ($this->Form->Save() !== FALSE) { $this->InformMessage(T("Your settings have been saved.")); } } // Render default view $this->Render(); }
/** * Edit a comment (wrapper for PostController::Comment). * * Will throw an error if both params are blank. * * @since 2.0.0 * @access public * * @param int $CommentID Unique ID of the comment to edit. * @param int $DraftID Unique ID of the draft to edit. */ public function EditComment($CommentID = '', $DraftID = '') { if (is_numeric($CommentID) && $CommentID > 0) { $this->Form->SetModel($this->CommentModel); $this->Comment = $this->CommentModel->GetID($CommentID); } else { $this->Form->SetModel($this->DraftModel); $this->Comment = $this->DraftModel->GetID($DraftID); } $this->View = 'Comment'; $this->Comment($this->Comment->DiscussionID); }
/** * Edit a comment (wrapper for PostController::Comment). * * Will throw an error if both params are blank. * * @since 2.0.0 * @access public * * @param int $CommentID Unique ID of the comment to edit. * @param int $DraftID Unique ID of the draft to edit. */ public function EditComment($CommentID = '', $DraftID = '') { if (is_numeric($CommentID) && $CommentID > 0) { $this->Form->SetModel($this->CommentModel); $this->Comment = $this->CommentModel->GetID($CommentID); } else { $this->Form->SetModel($this->DraftModel); $this->Comment = $this->DraftModel->GetID($DraftID); } if (C('Garden.ForceInputFormatter')) { $this->Form->RemoveFormValue('Format'); } $this->View = 'editcomment'; $this->Comment($this->Comment->DiscussionID); }
/** * Calls the appropriate registration method based on the configuration setting. * * Events: Register * * @access public * @since 2.0.0 * * @param string $InvitationCode Unique code given to invited user. */ public function Register($InvitationCode = '') { $this->FireEvent("Register"); $this->Form->SetModel($this->UserModel); // Define gender dropdown options $this->GenderOptions = array('m' => T('Male'), 'f' => T('Female')); // Make sure that the hour offset for new users gets defined when their account is created $this->AddJsFile('entry.js'); $this->Form->AddHidden('ClientHour', date('Y-m-d H:00')); // Use the server's current hour as a default $this->Form->AddHidden('Target', $this->Target()); $RegistrationMethod = $this->_RegistrationView(); $this->View = $RegistrationMethod; $this->{$RegistrationMethod}($InvitationCode); }
/** * Edit a user account. * * @since 2.0.0 * @access public * @param int $UserID Unique ID. */ public function Edit($UserID) { $this->Permission('Garden.Users.Edit'); // Page setup $this->AddJsFile('user.js'); $this->Title(T('Edit User')); $this->AddSideMenu('dashboard/user'); // Only admins can reassign roles $RoleModel = new RoleModel(); $AllRoles = $RoleModel->GetArray(); $RoleData = CheckPermission('Garden.Settings.Manage') ? $AllRoles : array(); $UserModel = new UserModel(); $User = $UserModel->GetID($UserID, DATASET_TYPE_ARRAY); // Determine if username can be edited $CanEditUsername = (bool) C("Garden.Profile.EditUsernames") || Gdn::Session()->CheckPermission('Garden.Users.Edit'); $this->SetData('_CanEditUsername', $CanEditUsername); // Determine if emails can be edited $CanEditEmail = Gdn::Session()->CheckPermission('Garden.Users.Edit'); $this->SetData('_CanEditEmail', $CanEditEmail); // Decide if they have ability to confirm users $Confirmed = (bool) GetValueR('Confirmed', $User); $CanConfirmEmail = UserModel::RequireConfirmEmail() && Gdn::Session()->CheckPermission('Garden.Users.Edit'); $this->SetData('_CanConfirmEmail', $CanConfirmEmail); $this->SetData('_EmailConfirmed', $Confirmed); $User['ConfirmEmail'] = (int) $Confirmed; // Determine whether user being edited is privileged (can escalate permissions) $UserModel = new UserModel(); $EditingPrivilegedUser = $UserModel->CheckPermission($User, 'Garden.Settings.Manage'); // Determine our password reset options // Anyone with user editing my force reset over email $this->ResetOptions = array(0 => T('Keep current password.'), 'Auto' => T('Force user to reset their password and send email notification.')); // Only admins may manually reset passwords for other admins if (CheckPermission('Garden.Settings.Manage') || !$EditingPrivilegedUser) { $this->ResetOptions['Manual'] = T('Manually set user password. No email notification.'); } // Set the model on the form. $this->Form->SetModel($UserModel); // Make sure the form knows which item we are editing. $this->Form->AddHidden('UserID', $UserID); try { $AllowEditing = TRUE; $this->EventArguments['AllowEditing'] =& $AllowEditing; $this->EventArguments['TargetUser'] =& $User; // These are all the 'effective' roles for this edit action. This list can // be trimmed down from the real list to allow subsets of roles to be // edited. $this->EventArguments['RoleData'] =& $RoleData; $UserRoleData = $UserModel->GetRoles($UserID)->ResultArray(); $RoleIDs = ConsolidateArrayValuesByKey($UserRoleData, 'RoleID'); $RoleNames = ConsolidateArrayValuesByKey($UserRoleData, 'Name'); $UserRoleData = ArrayCombine($RoleIDs, $RoleNames); $this->EventArguments['UserRoleData'] =& $UserRoleData; $this->FireEvent("BeforeUserEdit"); $this->SetData('AllowEditing', $AllowEditing); $this->Form->SetData($User); if ($this->Form->AuthenticatedPostBack()) { if (!$CanEditUsername) { $this->Form->SetFormValue("Name", $User['Name']); } // Allow mods to confirm/unconfirm emails $this->Form->RemoveFormValue('Confirmed'); $Confirmation = $this->Form->GetFormValue('ConfirmEmail', null); $Confirmation = !is_null($Confirmation) ? (bool) $Confirmation : null; if ($CanConfirmEmail && is_bool($Confirmation)) { $this->Form->SetFormValue('Confirmed', (int) $Confirmation); } $ResetPassword = $this->Form->GetValue('ResetPassword', FALSE); // If we're an admin or this isn't a privileged user, allow manual setting of password $AllowManualReset = CheckPermission('Garden.Settings.Manage') || !$EditingPrivilegedUser; if ($ResetPassword == 'Manual' && $AllowManualReset) { // If a new password was specified, add it to the form's collection $NewPassword = $this->Form->GetValue('NewPassword', ''); $this->Form->SetFormValue('Password', $NewPassword); } // Role changes // These are the new roles the editing user wishes to apply to the target // user, adjusted for his ability to affect those roles $RequestedRoles = $this->Form->GetFormValue('RoleID'); if (!is_array($RequestedRoles)) { $RequestedRoles = array(); } $RequestedRoles = array_flip($RequestedRoles); $UserNewRoles = array_intersect_key($RoleData, $RequestedRoles); // These roles will stay turned on regardless of the form submission contents // because the editing user does not have permission to modify them $ImmutableRoles = array_diff_key($AllRoles, $RoleData); $UserImmutableRoles = array_intersect_key($ImmutableRoles, $UserRoleData); // Apply immutable roles foreach ($UserImmutableRoles as $IMRoleID => $IMRoleName) { $UserNewRoles[$IMRoleID] = $IMRoleName; } // Put the data back into the forum object as if the user had submitted // this themselves $this->Form->SetFormValue('RoleID', array_keys($UserNewRoles)); if ($this->Form->Save(array('SaveRoles' => TRUE)) !== FALSE) { if ($this->Form->GetValue('ResetPassword', '') == 'Auto') { $UserModel->PasswordRequest($User['Email']); $UserModel->SetField($UserID, 'HashMethod', 'Reset'); } $this->InformMessage(T('Your changes have been saved.')); } $UserRoleData = $UserNewRoles; } } catch (Exception $Ex) { $this->Form->AddError($Ex); } $this->SetData('User', $User); $this->SetData('Roles', $RoleData); $this->SetData('UserRoles', $UserRoleData); $this->Render(); }
/** * Invitation-only registration. Requires code. * * @param int $InvitationCode * @since 2.0.0 */ public function RegisterInvitation($InvitationCode = 0) { $this->Form->SetModel($this->UserModel); // Define gender dropdown options $this->GenderOptions = array('u' => T('Unspecified'), 'm' => T('Male'), 'f' => T('Female')); if (!$this->Form->IsPostBack()) { $this->Form->SetValue('InvitationCode', $InvitationCode); } $InvitationModel = new InvitationModel(); // Look for the invitation. $Invitation = $InvitationModel->GetWhere(array('Code' => $this->Form->GetValue('InvitationCode')))->FirstRow(DATASET_TYPE_ARRAY); if (!$Invitation) { $this->Form->AddError('Invitation not found.', 'Code'); } else { if ($Expires = GetValue('DateExpires', $Invitation)) { $Expires = Gdn_Format::ToTimestamp($Expires); if ($Expires <= time()) { } } } $this->Form->AddHidden('ClientHour', date('Y-m-d H:00')); // Use the server's current hour as a default $this->Form->AddHidden('Target', $this->Target()); Gdn::UserModel()->AddPasswordStrength($this); if ($this->Form->IsPostBack() === TRUE) { $this->InvitationCode = $this->Form->GetValue('InvitationCode'); // Add validation rules that are not enforced by the model $this->UserModel->DefineSchema(); $this->UserModel->Validation->ApplyRule('Name', 'Username', $this->UsernameError); $this->UserModel->Validation->ApplyRule('TermsOfService', 'Required', T('You must agree to the terms of service.')); $this->UserModel->Validation->ApplyRule('Password', 'Required'); $this->UserModel->Validation->ApplyRule('Password', 'Strength'); $this->UserModel->Validation->ApplyRule('Password', 'Match'); // $this->UserModel->Validation->ApplyRule('DateOfBirth', 'MinimumAge'); $this->FireEvent('RegisterValidation'); try { $Values = $this->Form->FormValues(); unset($Values['Roles']); $AuthUserID = $this->UserModel->Register($Values, array('Method' => 'Invitation')); if (!$AuthUserID) { $this->Form->SetValidationResults($this->UserModel->ValidationResults()); } else { // The user has been created successfully, so sign in now. Gdn::Session()->Start($AuthUserID); if ($this->Form->GetFormValue('RememberMe')) { Gdn::Authenticator()->SetIdentity($AuthUserID, TRUE); } $this->FireEvent('RegistrationSuccessful'); // ... and redirect them appropriately $Route = $this->RedirectTo(); if ($this->_DeliveryType != DELIVERY_TYPE_ALL) { $this->RedirectUrl = Url($Route); } else { if ($Route !== FALSE) { Redirect($Route); } } } } catch (Exception $Ex) { $this->Form->AddError($Ex); } } else { // Set some form defaults. if ($Name = GetValue('Name', $Invitation)) { $this->Form->SetValue('Name', $Name); } $this->InvitationCode = $InvitationCode; } // Make sure that the hour offset for new users gets defined when their account is created $this->AddJsFile('entry.js'); $this->Render(); }
protected function _AddEdit($Sender, $PocketID = FALSE) { $Form = new Gdn_Form(); $PocketModel = new Gdn_Model('Pocket'); $Form->SetModel($PocketModel); $Sender->ConditionModule = new ConditionModule($Sender); $Sender->Form = $Form; if ($Form->AuthenticatedPostBack()) { // Save the pocket. if ($PocketID !== FALSE) { $Form->SetFormValue('PocketID', $PocketID); } // Convert the form data into a format digestable by the database. $Repeat = $Form->GetFormValue('RepeatType'); switch ($Repeat) { case Pocket::REPEAT_EVERY: $PocketModel->Validation->ApplyRule('EveryFrequency', 'Integer'); $PocketModel->Validation->ApplyRule('EveryBegin', 'Integer'); $Frequency = $Form->GetFormValue('EveryFrequency', 1); if (!$Frequency || !ValidateInteger($Frequency) || $Frequency < 1) { $Frequency = 1; } $Repeat .= ' ' . $Frequency; if ($Form->GetFormValue('EveryBegin', 1) > 1) { $Repeat .= ',' . $Form->GetFormValue('EveryBegin'); } break; case Pocket::REPEAT_INDEX: $PocketModel->Validation->AddRule('IntegerArray', 'function:ValidateIntegerArray'); $PocketModel->Validation->ApplyRule('Indexes', 'IntegerArray'); $Indexes = explode(',', $Form->GetFormValue('Indexes', '')); $Indexes = array_map('trim', $Indexes); $Repeat .= ' ' . implode(',', $Indexes); break; default: break; } $Form->SetFormValue('Repeat', $Repeat); $Form->SetFormValue('Sort', 0); $Form->SetFormValue('Format', 'Raw'); $Condition = Gdn_Condition::ToString($Sender->ConditionModule->Conditions(TRUE)); $Form->SetFormValue('Condition', $Condition); if ($Form->GetFormValue('Ad', 0)) { $Form->SetFormValue('Type', Pocket::TYPE_AD); } else { $Form->SetFormValue('Type', Pocket::TYPE_DEFAULT); } $Saved = $Form->Save(); if ($Saved) { $Sender->StatusMessage = T('Your changes have been saved.'); $Sender->RedirectUrl = Url('settings/pockets'); } } else { if ($PocketID !== FALSE) { // Load the pocket. $Pocket = $PocketModel->GetWhere(array('PocketID' => $PocketID))->FirstRow(DATASET_TYPE_ARRAY); if (!$Pocket) { return Gdn::Dispatcher()->Dispatch('Default404'); } // Convert some of the pocket data into a format digestable by the form. list($RepeatType, $RepeatFrequency) = Pocket::ParseRepeat($Pocket['Repeat']); $Pocket['RepeatType'] = $RepeatType; $Pocket['EveryFrequency'] = GetValue(0, $RepeatFrequency, 1); $Pocket['EveryBegin'] = GetValue(1, $RepeatFrequency, 1); $Pocket['Indexes'] = implode(',', $RepeatFrequency); $Pocket['Ad'] = $Pocket['Type'] == Pocket::TYPE_AD; $Sender->ConditionModule->Conditions(Gdn_Condition::FromString($Pocket['Condition'])); $Form->SetData($Pocket); } else { // Default the repeat. $Form->SetFormValue('RepeatType', Pocket::REPEAT_ONCE); } } $Sender->Form = $Form; $Sender->SetData('Locations', $this->Locations); $Sender->SetData('LocationsArray', $this->GetLocationsArray()); $Sender->SetData('Pages', array('' => '(' . T('All') . ')', 'activity' => 'activity', 'comments' => 'comments', 'dashboard' => 'dashboard', 'discussions' => 'discussions', 'inbox' => 'inbox', 'profile' => 'profile')); return $Sender->Render('AddEdit', '', 'plugins/Pockets'); }
/** * Edit a user account. * * @since 2.0.0 * @access public * @param int $UserID Unique ID. */ public function Edit($UserID) { $this->Permission('Garden.Users.Edit'); // Page setup $this->AddJsFile('user.js'); $this->Title(T('Edit User')); $this->AddSideMenu('dashboard/user'); // Determine if username can be edited $this->CanEditUsername = TRUE; $this->CanEditUsername = $this->CanEditUsername & Gdn::Config("Garden.Profile.EditUsernames"); $this->CanEditUsername = $this->CanEditUsername | Gdn::Session()->CheckPermission('Garden.Users.Edit'); $RoleModel = new RoleModel(); $AllRoles = $RoleModel->GetArray(); // By default, people with access here can freely assign all roles $this->RoleData = $AllRoles; $UserModel = new UserModel(); $this->User = $UserModel->GetID($UserID); // Set the model on the form. $this->Form->SetModel($UserModel); // Make sure the form knows which item we are editing. $this->Form->AddHidden('UserID', $UserID); try { $AllowEditing = TRUE; $this->EventArguments['AllowEditing'] =& $AllowEditing; $this->EventArguments['TargetUser'] =& $this->User; // These are all the 'effective' roles for this edit action. This list can // be trimmed down from the real list to allow subsets of roles to be // edited. $this->EventArguments['RoleData'] =& $this->RoleData; $UserRoleData = $UserModel->GetRoles($UserID)->ResultArray(); $RoleIDs = ConsolidateArrayValuesByKey($UserRoleData, 'RoleID'); $RoleNames = ConsolidateArrayValuesByKey($UserRoleData, 'Name'); $this->UserRoleData = ArrayCombine($RoleIDs, $RoleNames); $this->EventArguments['UserRoleData'] =& $this->UserRoleData; $this->FireEvent("BeforeUserEdit"); $this->SetData('AllowEditing', $AllowEditing); if (!$this->Form->AuthenticatedPostBack()) { $this->Form->SetData($this->User); } else { if (!$this->CanEditUsername) { $this->Form->SetFormValue("Name", $this->User->Name); } // If a new password was specified, add it to the form's collection $ResetPassword = $this->Form->GetValue('ResetPassword', FALSE); $NewPassword = $this->Form->GetValue('NewPassword', ''); if ($ResetPassword == 'Manual') { $this->Form->SetFormValue('Password', $NewPassword); } // Role changes // These are the new roles the editing user wishes to apply to the target // user, adjusted for his ability to affect those roles $RequestedRoles = $this->Form->GetFormValue('RoleID'); if (!is_array($RequestedRoles)) { $RequestedRoles = array(); } $RequestedRoles = array_flip($RequestedRoles); $UserNewRoles = array_intersect_key($this->RoleData, $RequestedRoles); // These roles will stay turned on regardless of the form submission contents // because the editing user does not have permission to modify them $ImmutableRoles = array_diff_key($AllRoles, $this->RoleData); $UserImmutableRoles = array_intersect_key($ImmutableRoles, $this->UserRoleData); // Apply immutable roles foreach ($UserImmutableRoles as $IMRoleID => $IMRoleName) { $UserNewRoles[$IMRoleID] = $IMRoleName; } // Put the data back into the forum object as if the user had submitted // this themselves $this->Form->SetFormValue('RoleID', array_keys($UserNewRoles)); if ($this->Form->Save(array('SaveRoles' => TRUE)) !== FALSE) { if ($this->Form->GetValue('ResetPassword', '') == 'Auto') { $UserModel->PasswordRequest($this->User->Email); $UserModel->SetField($UserID, 'HashMethod', 'Reset'); } $this->InformMessage(T('Your changes have been saved.')); } $this->UserRoleData = $UserNewRoles; } } catch (Exception $Ex) { $this->Form->AddError($Ex); } $this->Render(); }
/** * Set user's thumbnail (crop & center photo). * * @since 2.0.0 * @access public * @param mixed $UserReference Unique identifier, possible username or ID. * @param string $Username. */ public function Thumbnail($UserReference = '', $Username = '') { if (!C('Garden.Profile.EditPhotos', TRUE)) { throw ForbiddenException('@Editing user photos has been disabled.'); } // Initial permission checks (valid user) $this->Permission('Garden.SignIn.Allow'); $Session = Gdn::Session(); if (!$Session->IsValid()) { $this->Form->AddError('You must be authenticated in order to use this form.'); } // Need some extra JS // jcrop update jan28, 2014 as jQuery upgrade to 1.10.2 no longer // supported browser() $this->AddJsFile('jquery.jcrop.min.js'); $this->AddJsFile('profile.js'); $this->GetUserInfo($UserReference, $Username, '', TRUE); // Permission check (correct user) if ($this->User->UserID != $Session->UserID && !CheckPermission('Garden.Users.Edit') && !CheckPermission('Moderation.Profiles.Edit')) { throw new Exception(T('You cannot edit the thumbnail of another member.')); } // Form prep $this->Form->SetModel($this->UserModel); $this->Form->AddHidden('UserID', $this->User->UserID); // Confirm we have a photo to manipulate if (!$this->User->Photo) { $this->Form->AddError('You must first upload a picture before you can create a thumbnail.'); } // Define the thumbnail size $this->ThumbSize = Gdn::Config('Garden.Thumbnail.Size', 40); // Define the source (profile sized) picture & dimensions. $Basename = ChangeBasename($this->User->Photo, 'p%s'); $Upload = new Gdn_UploadImage(); $PhotoParsed = Gdn_Upload::Parse($Basename); $Source = $Upload->CopyLocal($Basename); if (!$Source) { $this->Form->AddError('You cannot edit the thumbnail of an externally linked profile picture.'); } else { $this->SourceSize = getimagesize($Source); } // We actually need to upload a new file to help with cdb ttls. $NewPhoto = $Upload->GenerateTargetName('userpics', trim(pathinfo($this->User->Photo, PATHINFO_EXTENSION), '.'), TRUE); // Add some more hidden form fields for jcrop $this->Form->AddHidden('x', '0'); $this->Form->AddHidden('y', '0'); $this->Form->AddHidden('w', $this->ThumbSize); $this->Form->AddHidden('h', $this->ThumbSize); $this->Form->AddHidden('HeightSource', $this->SourceSize[1]); $this->Form->AddHidden('WidthSource', $this->SourceSize[0]); $this->Form->AddHidden('ThumbSize', $this->ThumbSize); if ($this->Form->AuthenticatedPostBack() === TRUE) { try { // Get the dimensions from the form. Gdn_UploadImage::SaveImageAs($Source, ChangeBasename($NewPhoto, 'n%s'), $this->ThumbSize, $this->ThumbSize, array('Crop' => TRUE, 'SourceX' => $this->Form->GetValue('x'), 'SourceY' => $this->Form->GetValue('y'), 'SourceWidth' => $this->Form->GetValue('w'), 'SourceHeight' => $this->Form->GetValue('h'))); // Save new profile picture. $Parsed = $Upload->SaveAs($Source, ChangeBasename($NewPhoto, 'p%s')); $UserPhoto = sprintf($Parsed['SaveFormat'], $NewPhoto); // Save the new photo info. Gdn::UserModel()->SetField($this->User->UserID, 'Photo', $UserPhoto); // Remove the old profile picture. @$Upload->Delete($Basename); } catch (Exception $Ex) { $this->Form->AddError($Ex); } // If there were no problems, redirect back to the user account if ($this->Form->ErrorCount() == 0) { Redirect(UserUrl($this->User, '', 'picture')); $this->InformMessage(Sprite('Check', 'InformSprite') . T('Your changes have been saved.'), 'Dismissable AutoDismiss HasSprite'); } } // Delete the source image if it is externally hosted. if ($PhotoParsed['Type']) { @unlink($Source); } $this->Title(T('Edit My Thumbnail')); $this->_SetBreadcrumbs(T('Edit My Thumbnail'), '/profile/thumbnail'); $this->Render(); }