public function __construct($url = null) { $userId = OW::getUser()->getId(); $document = OW::getDocument(); $plugin = OW::getPluginManager()->getPlugin('base'); $document->addScript($plugin->getStaticJsUrl() . 'jQueryRotate.min.js'); $document->addScript($plugin->getStaticJsUrl() . 'codemirror.min.js'); $document->addScript($plugin->getStaticJsUrl() . 'upload.js'); $document->addScriptDeclarationBeforeIncludes(UTIL_JsGenerator::composeJsString(';window.ajaxFileUploadParams = {}; Object.defineProperties(ajaxFileUploadParams, { actionUrl: { value: {$url}, writable: false, enumerable: true }, maxFileSize: { value: {$size}, writable: false, enumerable: true }, deleteAction: { value: {$deleteAction}, writable: false, enumerable: true } });', array('url' => OW::getRouter()->urlForRoute('admin.ajax_upload'), 'size' => BOL_FileService::getInstance()->getUploadMaxFilesizeBytes(), 'deleteAction' => OW::getRouter()->urlForRoute('admin.ajax_upload_delete')))); $document->addOnloadScript(';window.ajaxFileUploader.init();'); BOL_FileTemporaryService::getInstance()->deleteUserTemporaryFiles($userId); $form = new BASE_CLASS_AjaxUploadForm('user', $userId, $url); $this->addForm($form); $language = OW::getLanguage(); $language->addKeyForJs('admin', 'not_all_photos_uploaded'); $language->addKeyForJs('admin', 'size_limit'); $language->addKeyForJs('admin', 'type_error'); $language->addKeyForJs('admin', 'dnd_support'); $language->addKeyForJs('admin', 'dnd_not_support'); $language->addKeyForJs('admin', 'drop_here'); $language->addKeyForJs('admin', 'please_wait'); $language->addKeyForJs('admin', 'describe_photo'); $language->addKeyForJs('admin', 'photo_upload_error'); }
public function moveTemporaryFile($tmpId, $title = '') { $tmp = BOL_FileTemporaryDao::getInstance()->findById($tmpId); $tmpPath = BOL_FileTemporaryService::getInstance()->getTemporaryFilePath($tmpId); if (!$tmp) { throw new LogicException(); } if (!UTIL_File::validateImage($tmp->filename)) { throw new LogicException(); } $image = new BOL_ThemeImage(); $image->addDatetime = time(); $image->title = $title; $dimensions = getimagesize($tmpPath); $image->dimensions = "{$dimensions[0]}x{$dimensions[1]}"; $image->filesize = UTIL_File::getFileSize($tmpPath); $this->themeImageDao->save($image); $ext = UTIL_File::getExtension($tmp->filename); $imageName = 'theme_image_' . $image->getId() . '.' . $ext; $newTempName = $tmp->filename . '.' . $ext; rename($tmp->filename, $newTempName); OW::getStorage()->copyFile($tmpPath, $this->userfileImagesDir . $imageName); if (file_exists($newTempName)) { unlink($newTempName); } BOL_FileTemporaryDao::getInstance()->deleteById($tmpId); $image->setFilename($imageName); $this->themeImageDao->save($image); return $image; }
public function upload() { if ($this->isAvailableFile($_FILES)) { $order = !empty($_POST['order']) ? (int) $_POST['order'] : 0; if ($id = BOL_FileTemporaryService::getInstance()->addTemporaryFile($_FILES['file']['tmp_name'], $_FILES['file']['name'], OW::getUser()->getId(), $order)) { $fileUrl = BOL_FileTemporaryService::getInstance()->getTemporaryFileUrl($id); $this->returnResponse(array('status' => self::STATUS_SUCCESS, 'fileUrl' => $fileUrl, 'id' => $id, 'filename' => $_FILES['file']['name'])); } else { $this->returnResponse(array('status' => self::STATUS_ERROR, 'msg' => OW::getLanguage()->text('admin', 'no_photo_uploaded'))); } } else { $msg = $this->getErrorMsg($_FILES); $this->returnResponse(array('status' => self::STATUS_ERROR, 'msg' => $msg)); } }