Example #1
0
 /**
  * Sets the Blog Thumbnail.
  *
  * @param object $oPost
  * @param \PH7\Framework\File\File $oFile
  * @return void
  */
 public function setThumb($oPost, Framework\File\File $oFile)
 {
     if (!empty($_FILES['thumb']['tmp_name'])) {
         $oImage = new Framework\Image\Image($_FILES['thumb']['tmp_name']);
         if (!$oImage->validate()) {
             \PFBC\Form::setError('form_blog', Form::wrongImgFileTypeMsg());
         } else {
             /**
              * The method deleteFile first test if the file exists, if so it delete the file.
              */
             $sPathName = PH7_PATH_PUBLIC_DATA_SYS_MOD . 'blog/' . PH7_IMG . $oPost->blogId;
             $oFile->deleteFile($sPathName);
             // It erases the old thumbnail
             $oFile->createDir($sPathName);
             $oImage->square(100);
             $oImage->save($sPathName . '/thumb.png');
         }
         unset($oImage);
     }
 }
Example #2
0
 /**
  * Sets the Note Thumbnail.
  *
  * @param object $oPost
  * @param \PH7\NoteModel $oNoteModel
  * @param \PH7\Framework\File\File $oFile
  * @return void
  */
 public function setThumb($oPost, NoteModel $oNoteModel, Framework\File\File $oFile)
 {
     if (!empty($_FILES['thumb']['tmp_name'])) {
         $oImage = new Framework\Image\Image($_FILES['thumb']['tmp_name']);
         if (!$oImage->validate()) {
             \PFBC\Form::setError('form_note', Form::wrongImgFileTypeMsg());
         } else {
             /**
              * The method deleteFile first test if the file exists, if so it delete the file.
              */
             $sPathName = PH7_PATH_PUBLIC_DATA_SYS_MOD . 'note/' . PH7_IMG . $oPost->username . PH7_SH;
             $oFile->deleteFile($sPathName);
             // It erases the old thumbnail
             $oFile->createDir($sPathName);
             $sFileName = Various::genRnd($oImage->getFileName(), 20) . PH7_DOT . $oImage->getExt();
             $oImage->square(100);
             $oImage->save($sPathName . $sFileName);
             $oNoteModel->updatePost('thumb', $sFileName, $oPost->noteId, $oPost->profileId);
         }
         unset($oImage);
     }
 }
Example #3
0
 /**
  * @param integer $iAlbumId
  * @param string $sUsername
  * @param string $sVideoLink (file with the extension)
  * @param string $sVideoExt Separate the different extensions with commas. (extension with the point. e.g., .ogg,.webm,.mp4) Default: .webm,.mp4
  * @param string $sThumbExt (extension of thumbnail with the point) Default: .jpg
  * @return void
  */
 public function deleteVideo($iAlbumId, $sUsername, $sVideoLink, $sVideoExt = '.webm,.mp4', $sThumbExt = '.jpg')
 {
     $sDir = PH7_PATH_PUBLIC_DATA_SYS_MOD . 'video/file/' . $sUsername . PH7_DS . $iAlbumId . PH7_DS;
     $oFile = new File();
     $sThumbName = $oFile->getFileWithoutExt($sVideoLink);
     // Delete video file
     $aVideoExt = explode(',', $sVideoExt);
     foreach ($aVideoExt as $sExt) {
         $oFile->deleteFile($sDir . $sVideoLink . $sExt);
     }
     // Delete thumbnail
     $oFile->deleteFile($sDir . $sThumbName . $sThumbExt);
     $oFile->deleteFile($sDir . $sThumbName . '-1' . $sThumbExt);
     $oFile->deleteFile($sDir . $sThumbName . '-2' . $sThumbExt);
     $oFile->deleteFile($sDir . $sThumbName . '-3' . $sThumbExt);
     $oFile->deleteFile($sDir . $sThumbName . '-4' . $sThumbExt);
     unset($oFile);
 }
 /**
  * Check and load the files if necessary.
  *
  * @param string $sFileNamePath A pH7Framework filename path.
  * @return void
  */
 private function _loadFile($sFileNamePath)
 {
     $oFile = new File();
     $sFullPath = PH7_PATH_FRAMEWORK . $sFileNamePath;
     $bIsExpiredFile = VDate::setTime('-2 months') > $oFile->getModifTime($sFullPath);
     $bFileExists = $oFile->existFile($sFullPath);
     $bIsTooSmallFile = $oFile->size($sFullPath) < 1000;
     if (!$bFileExists || $bIsTooSmallFile || $bIsExpiredFile) {
         if ($bFileExists) {
             // Delete the file if it already exists
             $oFile->deleteFile($sFullPath);
         }
         $this->_downloadFile($sFileNamePath, $oFile);
     }
     unset($oFile);
 }
 /**
  * Delete the avatar (image) and track database.
  *
  * @param integer $iProfileId
  * @param string $sUsername
  * @return void
  */
 public function deleteAvatar($iProfileId, $sUsername)
 {
     // We start to delete the file before the data in the database if we could not delete the file since we would have lost the link to the file found in the database.
     $sGetAvatar = (new UserCoreModel())->getAvatar($iProfileId, null);
     $sFile = $sGetAvatar->pic;
     $oFile = new File();
     $sExt = PH7_DOT . $oFile->getFileExt($sFile);
     $sPath = PH7_PATH_PUBLIC_DATA_SYS_MOD . 'user/avatar/img/' . $sUsername . PH7_SH;
     /** Array to the new format (>= PHP5.4) **/
     $aFiles = [$sPath . $sFile, $sPath . str_replace($sExt, '-32' . $sExt, $sFile), $sPath . str_replace($sExt, '-64' . $sExt, $sFile), $sPath . str_replace($sExt, '-100' . $sExt, $sFile), $sPath . str_replace($sExt, '-150' . $sExt, $sFile), $sPath . str_replace($sExt, '-200' . $sExt, $sFile), $sPath . str_replace($sExt, '-400' . $sExt, $sFile)];
     $oFile->deleteFile($aFiles);
     unset($oFile);
     (new UserCoreModel())->deleteAvatar($iProfileId);
     /* Clean User Avatar Cache */
     (new Framework\Cache\Cache())->start(Framework\Layout\Html\Design::CACHE_AVATAR_GROUP . $sUsername, null, null)->clear()->start(UserCoreModel::CACHE_GROUP, 'avatar' . $iProfileId, null)->clear();
 }
Example #6
0
 /**
  * Check and load the files if necessary.
  *
  * @return void
  */
 private function _loadFile()
 {
     $oFile = new File();
     $sFileNamePath = PH7_PATH_FRAMEWORK . 'Core/License.class.php';
     $bIsExpiredFile = $oFile->modificationTime($sFileNamePath) + VDate::setTime('+1 month') < VDate::getTime();
     if (!$oFile->existsFile($sFileNamePath) || $bIsExpiredFile) {
         if ($bIsExpiredFile) {
             $oFile->deleteFile($sFileNamePath);
         }
         $this->_downloadFile($sFileNamePath, $oFile);
     }
     unset($oFile);
 }