Esempio n. 1
0
 public function initialize()
 {
     $file = new File('media');
     $this->add($file);
     // CSRF
     $csrf = new Hidden('csrf');
     $csrf->addValidator(new Identical(['value' => $this->security->getSessionToken(), 'message' => $this->constants->csrfError()]));
     // Display for type of media. Such as images, videos, audios, etc
     $totalMedia = MediaType::sum(["column" => "amount"]);
     $mediaType = new Select("mediaType", MediaType::find(['columns' => array('id', " CONCAT(name, ' (', amount, ')') as type_amount")]), ['using' => ['id', 'type_amount'], 'name' => 'mediaType', 'class' => 'form-control col-md-3 btn-mini', 'useEmpty' => true, 'emptyText' => "All (" . $totalMedia . ")", 'emptyValue' => "all"]);
     $this->add($mediaType);
     // Search some thing
     $search = new Text('search', ['placeholder' => $this->constants->searchPlaceHolder(), 'class' => 'form-control btn-mini', 'required' => false]);
     $this->add($search);
 }
Esempio n. 2
0
 public function initialize()
 {
     $file = new File('media');
     $this->add($file);
     // CSRF
     $csrf = new Hidden('csrf');
     $csrf->addValidator(new Identical(['value' => $this->security->getSessionToken(), 'message' => CSRF_ERROR]));
     $userName = $this->getDI()->getAuth()->getUsername();
     // Display for type of media. Such as images, videos, audios, etc
     // Get user media config file for total media file
     $mediaFiles = new MediaFiles();
     $userConfig = $mediaFiles->getConfigFile($userName);
     $totalMedia = 0;
     $displayData = [];
     foreach ($userConfig as $key => $value) {
         $totalMedia += $value;
         $displayData[MediaType::getTypeFromName($key)->getId()] = $key . "({$value})";
     }
     $mediaType = new Select("mediaType", $displayData, ['using' => ['id', 'type_amount'], 'name' => 'mediaType', 'class' => 'form-control col-md-3 btn-mini', 'useEmpty' => true, 'emptyText' => "All (" . $totalMedia . ")", 'emptyValue' => "all"]);
     $this->add($mediaType);
     // Search some thing
     $search = new Text('search', ['placeholder' => SEARCH_PLACE_HOLDER, 'class' => 'form-control btn-mini', 'required' => false]);
     $this->add($search);
 }
Esempio n. 3
0
 public function uploadAction()
 {
     if ($this->request->hasFiles()) {
         $uploads = $this->request->getUploadedFiles();
         $this->view->disable();
         $uploaded = true;
         foreach ($uploads as $fileObj) {
             if (!$this->mediaModel->initFile($fileObj)) {
                 $uploaded = false;
             }
         }
         if (!$uploaded) {
             $error = implode("\n", $this->mediaModel->getError());
             $this->response->setStatusCode(406, $error);
             $this->response->setContent($error);
         } else {
             $this->response->setStatusCode(200, SUCCESS_MESSAGE);
         }
         return $this->response->send();
     }
     $this->assets->addCss('/core/assets/css/dropzone.css', false);
     $this->assets->addJs('/core/assets/js/dropzone.js', false);
     $this->view->acceptExt = implode(",", MediaType::getExtensionAllowed());
 }
Esempio n. 4
0
 /**
  * Input file for media, using for upload file
  * @param File Object $fileObj File upload by user
  * @return boolean           true if all ok. Otherwise, false
  */
 public function initFile($fileObj)
 {
     $fileExt = $fileObj->getExtension();
     $filesAccept = MediaType::getExtensionAllowed();
     // Check if file extension's allowed
     if (!in_array($fileExt, $filesAccept)) {
         return $this->setError(MEDIA_FILE_NOT_ACCEPT . ": " . $fileExt);
     }
     // determine directory for this file. <username>/<file type>/<year>/<month>/<filename>
     $userName = $this->getDI()->getAuth()->getUsername();
     $year = date("Y");
     $month = date("M");
     $fileName = $fileObj->getName();
     $fileType = MediaType::getTypeFromExt($fileExt);
     // generate path of file
     $serverPath = $userName . DS . $fileType->getName() . DS . $year . DS . $month . DS . $fileName;
     $localPath = $fileObj->getTempName();
     if (!file_exists($localPath)) {
         return $this->setError(MEDIA_TEMP_NOT_FOUND);
     }
     if ($this->fileSystem->checkFileExists($serverPath)) {
         return $this->setError(MEDIA_ALREADY_EXISTS);
     }
     if (!$this->fileSystem->uploadFile($localPath, $serverPath)) {
         return $this->setError(MEDIA_TEMP_NOT_FOUND);
     }
     $uploadStatus = $this->saveToDB($userName, $fileType->getId(), time(), $fileName);
     if (!$uploadStatus) {
         return $this->setError(MEDIA_UPLOAD_ERROR);
     }
     // Update analytic file
     $config = $this->fileSystem->getConfigFile($userName);
     $defaultConfig = MediaType::getConfig();
     $config = array_merge($defaultConfig, $config);
     $config[$fileType->getName()]++;
     $this->fileSystem->saveConfigFile($userName, $config);
     if ($fileType->getName() == "Images") {
         $this->generateThumb($localPath, $serverPath);
     }
     return true;
 }
Esempio n. 5
0
 /**
  * Get default media type
  * @return mixed
  */
 public static function getConfig()
 {
     $names = MediaType::find();
     $config = [];
     foreach ($names as $key) {
         $config[$key->getName()] = 0;
     }
     return $config;
 }