Change file name to match class name
This commit is contained in:
68
inc/Uploader.php
Normal file
68
inc/Uploader.php
Normal file
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
namespace Franzz\Spot;
|
||||
use Franzz\Objects\UploadHandler;
|
||||
use Franzz\Objects\Translator;
|
||||
|
||||
class Uploader extends UploadHandler
|
||||
{
|
||||
/**
|
||||
* Medias Management
|
||||
* @var Media
|
||||
*/
|
||||
private $oMedia;
|
||||
|
||||
/**
|
||||
* Languages
|
||||
* @var Translator
|
||||
*/
|
||||
private $oLang;
|
||||
|
||||
public $sBody;
|
||||
|
||||
function __construct(Media &$oMedia, Translator &$oLang)
|
||||
{
|
||||
$this->oMedia = &$oMedia;
|
||||
$this->oLang = &$oLang;
|
||||
$this->sBody = '';
|
||||
parent::__construct(array('image_versions'=>array(), 'accept_file_types'=>'/\.(gif|jpe?g|png|mov|mp4)$/i'));
|
||||
}
|
||||
|
||||
protected function validate($uploaded_file, $file, $error, $index, $content_range) {
|
||||
$bResult = parent::validate($uploaded_file, $file, $error, $index, $content_range);
|
||||
|
||||
//Check project mode
|
||||
if(!$this->oMedia->isProjectModeValid()) {
|
||||
$file->error = $this->get_error_message('upload_wrong_mode', array($this->oMedia->getProjectCodeName()));
|
||||
$bResult = false;
|
||||
}
|
||||
|
||||
return $bResult;
|
||||
}
|
||||
|
||||
protected function handle_file_upload($uploaded_file, $name, $size, $type, $error, $index = null, $content_range = null) {
|
||||
$file = parent::handle_file_upload($uploaded_file, $name, $size, $type, $error, $index, $content_range);
|
||||
|
||||
if(empty($file->error)) {
|
||||
$asResult = $this->oMedia->addMedia($file->name);
|
||||
if(!$asResult['result']) $file->error = $this->get_error_message($asResult['desc'], $asResult['data']);
|
||||
else {
|
||||
$file->id = $this->oMedia->getMediaId();
|
||||
$file->thumbnail = $asResult['data']['thumb_path'];
|
||||
}
|
||||
}
|
||||
|
||||
return $file;
|
||||
}
|
||||
|
||||
protected function body($sBodyPart) {
|
||||
$this->sBody .= $sBodyPart;
|
||||
}
|
||||
|
||||
protected function get_error_message($sError, $asParams=array()) {
|
||||
$sTranslatedError = $this->oLang->getTranslation($sError, $asParams);
|
||||
if($sTranslatedError) return $sTranslatedError;
|
||||
elseif(array_key_exists($sError, $this->error_messages)) return $this->error_messages[$sError];
|
||||
else return $sError;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user