Ejemplo n.º 1
0
 /**
  * Remove the mobile logo from config & delete it.
  *
  * @since 2.0.0
  * @access public
  * @param string $TransientKey Security token.
  */
 public function removeMobileLogo($TransientKey = '')
 {
     $Session = Gdn::session();
     if ($Session->validateTransientKey($TransientKey) && $Session->checkPermission('Garden.Community.Manage')) {
         $MobileLogo = c('Garden.MobileLogo', '');
         RemoveFromConfig('Garden.MobileLogo');
         safeUnlink(PATH_ROOT . "/{$MobileLogo}");
     }
     redirect('/settings/banner');
 }
Ejemplo n.º 2
0
 /**
  *
  *
  * @param bool $Save
  * @return bool|mixed|string
  * @throws Exception
  */
 public function loadTableType($Save = true)
 {
     $Result = val('LoadTableType', $this->Data, false);
     if (is_string($Result)) {
         return $Result;
     }
     // Create a table to test loading.
     $St = Gdn::structure();
     $St->table(self::TABLE_PREFIX . 'Test')->column('ID', 'int')->set(true, true);
     // Create a test file to load.
     if (!file_exists(PATH_UPLOADS . '/import')) {
         mkdir(PATH_UPLOADS . '/import');
     }
     $TestPath = PATH_UPLOADS . '/import/test.txt';
     $TestValue = 123;
     $TestContents = 'ID' . self::NEWLINE . $TestValue . self::NEWLINE;
     file_put_contents($TestPath, $TestContents, LOCK_EX);
     // Try LoadTableOnSameServer.
     try {
         $this->_LoadTableOnSameServer('Test', $TestPath);
         $Value = $this->SQL->get(self::TABLE_PREFIX . 'Test')->value('ID');
         if ($Value == $TestValue) {
             $Result = 'LoadTableOnSameServer';
         }
     } catch (Exception $Ex) {
         $Result = false;
     }
     // Try LoadTableLocalInfile.
     if (!$Result) {
         try {
             $this->_LoadTableLocalInfile('Test', $TestPath);
             $Value = $this->SQL->get(self::TABLE_PREFIX . 'Test')->value('ID');
             if ($Value == $TestValue) {
                 $Result = 'LoadTableLocalInfile';
             }
         } catch (Exception $Ex) {
             $Result = false;
         }
     }
     // If those two didn't work then default to LoadTableWithInsert.
     if (!$Result) {
         $Result = 'LoadTableWithInsert';
     }
     // Cleanup.
     safeUnlink($TestPath);
     $St->table(self::TABLE_PREFIX . 'Test')->Drop();
     if ($Save) {
         $this->Data['LoadTableType'] = $Result;
     }
     return $Result;
 }
Ejemplo n.º 3
0
 /**
  * Remove the mobile logo from config & delete it.
  *
  * @since 2.0.0
  * @access public
  */
 public function removeMobileLogo()
 {
     if (Gdn::request()->isAuthenticatedPostBack(true) && Gdn::session()->checkPermission('Garden.Community.Manage')) {
         $MobileLogo = c('Garden.MobileLogo', '');
         RemoveFromConfig('Garden.MobileLogo');
         safeUnlink(PATH_ROOT . "/{$MobileLogo}");
         $this->informMessage(sprintf(t('%s deleted.'), t('Mobile logo')));
     }
     $this->render('blank', 'utility', 'dashboard');
 }
Ejemplo n.º 4
0
 /**
  * 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 (!$this->CanEditPhotos) {
         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']) {
         safeUnlink($Source);
     }
     $this->title(t('Edit My Thumbnail'));
     $this->_setBreadcrumbs(t('Edit My Thumbnail'), '/profile/thumbnail');
     $this->render();
 }
Ejemplo n.º 5
0
 /**
  * Determine whether or not a path is writable.
  *
  * PHP's native is_writable() function fails to correctly determine write
  * capabilities on some systems (Windows), and in our tests it returned true
  * despite not being able to create subfolders within the folder being
  * checked. Our version truly verifies permissions by performing file-write
  * tests.
  *
  * @param string $Path The past to test.
  * @return bool Returns true if {@link $Path} is writable or false otherwise.
  */
 function isWritable($Path)
 {
     if ($Path[strlen($Path) - 1] == DS) {
         // Recursively return a temporary file path
         return IsWritable($Path . uniqid(mt_rand()) . '.tmp');
     } elseif (is_dir($Path)) {
         return IsWritable($Path . '/' . uniqid(mt_rand()) . '.tmp');
     }
     // Check tmp file for read/write capabilities
     $KeepPath = file_exists($Path);
     $File = @fopen($Path, 'a');
     if ($File === false) {
         return false;
     }
     fclose($File);
     if (!$KeepPath) {
         safeUnlink($Path);
     }
     return true;
 }
Ejemplo n.º 6
0
 /**
  * Delete an uploaded file.
  *
  * @param string $Name The name of the upload as saved in the database.
  * @return bool
  */
 public function delete($Name)
 {
     $Parsed = $this->parse($Name);
     // Throw an event so that plugins that have stored the file somewhere else can delete it.
     $this->EventArguments['Parsed'] =& $Parsed;
     $Handled = false;
     $this->EventArguments['Handled'] =& $Handled;
     $this->fireAs('Gdn_Upload')->fireEvent('Delete');
     if (!$Handled) {
         $Path = PATH_UPLOADS . '/' . ltrim($Name, '/');
         if ($Path === realpath($Path) && file_exists($Path)) {
             return safeUnlink($Path);
         }
     }
     return true;
 }