public function __construct() { parent::__construct(); /** * This can cause minor errors (eg if a user sent a file that is not a video). * So we hide the errors if we are not in development mode. */ if (!isDebug()) { error_reporting(0); } // Resizing and saving the video album thumbnail $oPicture = new Image($_FILES['album']['tmp_name']); if (!$oPicture->validate()) { \PFBC\Form::setError('form_video_album', Form::wrongImgFileTypeMsg()); } else { $iApproved = DbConfig::getSetting('videoManualApproval') == 0 ? '1' : '0'; $sFileName = Various::genRnd($oPicture->getFileName(), 1) . '-thumb.' . $oPicture->getExt(); (new VideoModel())->addAlbum($this->session->get('member_id'), $this->httpRequest->post('name'), $this->httpRequest->post('description'), $sFileName, $this->dateTime->get()->dateTime('Y-m-d H:i:s'), $iApproved); $iLastAlbumId = (int) Db::getInstance()->lastInsertId(); $oPicture->square(200); /* Set watermark text on thumbnail */ $sWatermarkText = DbConfig::getSetting('watermarkTextImage'); $iSizeWatermarkText = DbConfig::getSetting('sizeWatermarkTextImage'); $oPicture->watermarkText($sWatermarkText, $iSizeWatermarkText); $sPath = PH7_PATH_PUBLIC_DATA_SYS_MOD . 'video/file/' . $this->session->get('member_username') . PH7_DS . $iLastAlbumId . PH7_DS; $this->file->createDir($sPath); $oPicture->save($sPath . $sFileName); /* Clean VideoModel Cache */ (new Framework\Cache\Cache())->start(VideoModel::CACHE_GROUP, null, null)->clear(); HeaderUrl::redirect(Uri::get('video', 'main', 'addvideo', $iLastAlbumId)); } }
public function __construct() { parent::__construct(); /** * @desc This can cause minor errors (eg if a user sent a file that is not a photo). * So we hide the errors if we are not in development mode. */ if (!isDebug()) { error_reporting(0); } /** * @desc * Check if the photo album ID is valid. The value must be numeric. * This test is necessary because when the selection exists but that no option is available (this can when a user wants to add photos but he has no album) * the return value is of type "string" and the value is "1". */ if (!is_numeric($this->httpRequest->post('album_id'))) { \PFBC\Form::setError('form_picture', t('Please add a category before you add some photos.')); return; // Stop execution of the method. } /** * @desc Resizing and saving some photos */ $aPhotos = $_FILES['photos']['tmp_name']; for ($i = 0, $iNumPhotos = count($aPhotos); $i < $iNumPhotos; $i++) { $oPicture1 = new Image($aPhotos[$i], 2500, 2500); if (!$oPicture1->validate()) { \PFBC\Form::setError('form_picture', Form::wrongImgFileTypeMsg()); return; // Stop execution of the method. } $sAlbumTitle = $this->httpRequest->post('album_title'); $iAlbumId = (int) $this->httpRequest->post('album_id'); $oPicture2 = clone $oPicture1; $oPicture3 = clone $oPicture1; $oPicture4 = clone $oPicture1; $oPicture5 = clone $oPicture1; $oPicture6 = clone $oPicture1; $oPicture2->square(400); $oPicture3->square(600); $oPicture4->square(800); $oPicture5->square(1000); $oPicture6->square(1200); /* Set watermark text on images */ $sWatermarkText = DbConfig::getSetting('watermarkTextImage'); $iSizeWatermarkText = DbConfig::getSetting('sizeWatermarkTextImage'); $oPicture1->watermarkText($sWatermarkText, $iSizeWatermarkText); $oPicture2->watermarkText($sWatermarkText, $iSizeWatermarkText); $oPicture3->watermarkText($sWatermarkText, $iSizeWatermarkText); $oPicture4->watermarkText($sWatermarkText, $iSizeWatermarkText); $oPicture5->watermarkText($sWatermarkText, $iSizeWatermarkText); $oPicture6->watermarkText($sWatermarkText, $iSizeWatermarkText); $sPath = PH7_PATH_PUBLIC_DATA_SYS_MOD . 'picture/img/' . $this->session->get('member_username') . PH7_DS . $iAlbumId . PH7_DS; $sFileName = Various::genRnd($oPicture1->getFileName(), 20); $sFile1 = $sFileName . '-original.' . $oPicture1->getExt(); // Original $sFile2 = $sFileName . '-400.' . $oPicture2->getExt(); $sFile3 = $sFileName . '-600.' . $oPicture3->getExt(); $sFile4 = $sFileName . '-800.' . $oPicture4->getExt(); $sFile5 = $sFileName . '-1000.' . $oPicture5->getExt(); $sFile6 = $sFileName . '-1200.' . $oPicture6->getExt(); $oPicture1->save($sPath . $sFile1); $oPicture2->save($sPath . $sFile2); $oPicture3->save($sPath . $sFile3); $oPicture4->save($sPath . $sFile4); $oPicture5->save($sPath . $sFile5); $oPicture6->save($sPath . $sFile6); $iApproved = DbConfig::getSetting('pictureManualApproval') == 0 ? '1' : '0'; // It creates a nice title if no title is specified. $sTitle = $this->httpRequest->postExists('title') && $this->str->length($this->str->trim($this->httpRequest->post('title'))) > 2 ? $this->httpRequest->post('title') : $this->str->upperFirst(str_replace(array('-', '_'), ' ', str_ireplace(PH7_DOT . $oPicture1->getExt(), '', escape($_FILES['photos']['name'][$i], true)))); (new PictureModel())->addPhoto($this->session->get('member_id'), $iAlbumId, $sTitle, $this->httpRequest->post('description'), $sFile1, $this->dateTime->get()->dateTime('Y-m-d H:i:s'), $iApproved); } /* Clean PictureModel Cache */ (new Framework\Cache\Cache())->start(PictureModel::CACHE_GROUP, null, null)->clear(); $sModerationText = t('Your photo(s) has been received! But it will be visible once approved by our moderators. Please do not send a new photo(s) because this is useless!'); $sText = t('Your photo(s) has been added successfully!'); $sMsg = $iApproved == '0' ? $sModerationText : $sText; Header::redirect(Uri::get('picture', 'main', 'album', $this->session->get('member_username') . ',' . $sAlbumTitle . ',' . $iAlbumId), $sMsg); }