/** * Prepares the list data */ public function prepareVars() { $value = $this->getLoadValue(); $this->vars['value'] = $value; $this->vars['imageUrl'] = $value ? MediaLibrary::url($value) : ''; $this->vars['field'] = $this->formField; $this->vars['prompt'] = str_replace('%s', '<i class="icon-folder"></i>', trans($this->prompt)); $this->vars['mode'] = $this->mode; }
/** * Converts supplied file to a URL relative to the media library. * @param string $file Specifies the media-relative file * @return string */ public function mediaUrl($file = null) { return MediaLibrary::url($file); }
protected function checkUploadPostback() { $fileName = null; $quickMode = false; if ((!($uniqueId = Request::header('X-OCTOBER-FILEUPLOAD')) || $uniqueId != $this->getId()) && !($quickMode = post('X_OCTOBER_MEDIA_MANAGER_QUICK_UPLOAD'))) { return; } try { if (!Input::hasFile('file_data')) { throw new ApplicationException('File missing from request'); } $uploadedFile = Input::file('file_data'); $fileName = $uploadedFile->getClientOriginalName(); /* * Convert uppcare case file extensions to lower case */ $extension = strtolower($uploadedFile->getClientOriginalExtension()); $fileName = File::name($fileName) . '.' . $extension; /* * File name contains non-latin characters, attempt to slug the value */ if (!$this->validateFileName($fileName)) { $fileNameClean = $this->cleanFileName(File::name($fileName)); $fileName = $fileNameClean . '.' . $extension; } /* * Check for unsafe file extensions */ if (!$this->validateFileType($fileName)) { throw new ApplicationException(Lang::get('cms::lang.media.type_blocked')); } // See mime type handling in the asset manager if (!$uploadedFile->isValid()) { throw new ApplicationException($uploadedFile->getErrorMessage()); } $path = $quickMode ? '/uploaded-files' : Input::get('path'); $path = MediaLibrary::validatePath($path); $filePath = $path . '/' . $fileName; MediaLibrary::instance()->put($filePath, File::get($uploadedFile->getRealPath())); Response::json(['link' => MediaLibrary::url($filePath), 'result' => 'success'])->send(); } catch (Exception $ex) { Response::json($ex->getMessage(), 400)->send(); } exit; }