/** * @return string */ public function getRename() { $old_name = Input::get('file'); $new_name = Input::get('new_name'); $file_path = parent::getPath('directory'); $thumb_path = parent::getPath('thumb'); $old_file = $file_path . $old_name; if (!File::isDirectory($old_file)) { $extension = File::extension($old_file); $new_name = str_replace('.' . $extension, '', $new_name) . '.' . $extension; } $new_file = $file_path . $new_name; if (File::exists($new_file)) { return Lang::get('laravel-filemanager::lfm.error-rename'); } if (File::isDirectory($old_file)) { File::move($old_file, $new_file); return 'OK'; } File::move($old_file, $new_file); if ('Images' === $this->file_type) { File::move($thumb_path . $old_name, $thumb_path . $new_name); } return 'OK'; }
/** * @return string */ public function getRename() { $old_name = Input::get('file'); $new_name = trim(Input::get('new_name')); $file_path = parent::getPath('directory'); $thumb_path = parent::getPath('thumb'); $old_file = $file_path . $old_name; if (!File::isDirectory($old_file)) { $extension = File::extension($old_file); $new_name = str_replace('.' . $extension, '', $new_name) . '.' . $extension; } $new_file = $file_path . $new_name; if (Config::get('lfm.alphanumeric_directory') && preg_match('/[^\\w-]/i', $new_name)) { return Lang::get('laravel-filemanager::lfm.error-folder-alnum'); } elseif (File::exists($new_file)) { return Lang::get('laravel-filemanager::lfm.error-rename'); } if (File::isDirectory($old_file)) { File::move($old_file, $new_file); Event::fire(new FolderWasRenamed($old_file, $new_file)); return 'OK'; } File::move($old_file, $new_file); if ('Images' === $this->file_type) { File::move($thumb_path . $old_name, $thumb_path . $new_name); } Event::fire(new ImageWasRenamed($old_file, $new_file)); return 'OK'; }
/** * Store a newly created resource in storage. * * @param TemplateRequest $request * @return Response */ public function store(TemplateRequest $request) { ini_set('max_execution_time', 0); File::delete(base_path('resources/views/Template.php')); File::delete(storage_path('tmp/Template.php')); File::deleteDirectory(storage_path('tmp/')); $file_path = storage_path('tmp/'); $orginal_name = $request->file('file')->getClientOriginalName(); if ($request->file('file')->move($file_path, $orginal_name)) { Zipper::make($file_path . $orginal_name)->extractTo(storage_path('tmp')); $template = (require_once storage_path('tmp/Template.php')); $assets = File::move(storage_path('tmp/assets/' . $template['folder']), public_path('assets/' . $template['folder'])); $template_file = File::move(storage_path('tmp/' . $template['folder']), base_path('resources/views/' . $template['folder'])); if (!$assets || !$template_file) { File::delete(base_path('resources/views/Template.php')); File::delete(storage_path('tmp/Template.php')); File::deleteDirectory(storage_path('tmp/')); Flash::error('Tema Dosyası Yüklendi ama Dizinler Tasinamadi! Tüm İşlemleriniz İptal Edildi.'); return redirect()->route('admin.template.index'); } $message = $this->template->create($template) ? ['success', 'Başarıyla Kaydedildi'] : ['error', 'Bir Hata Meydana Geldi ve Kaydedilemedi']; File::delete(base_path('resources/views/Template.php')); File::delete(storage_path('tmp/Template.php')); File::deleteDirectory(storage_path('tmp/')); Flash::$message[0]($message[1]); if ($message[0] == "success") { Logs::add('process', "Şablon Eklendi\n{$template['name']}"); } else { Logs::add('errors', "Şablon Eklenemedi!"); } return redirect()->route('admin.template.index'); } }
/** * Execute the console command. */ public function fire() { $this->line(''); $this->info('Routes file: app/routes.php'); $message = 'This will rebuild routes.php with all of the packages that' . ' subscribe to the `toolbox.routes` event.'; $this->comment($message); $this->line(''); if ($this->confirm('Proceed with the rebuild? [Yes|no]')) { $this->line(''); $this->info('Backing up routes.php ...'); // Remove the last backup if it exists if (File::exists('app/routes.bak.php')) { File::delete('app/routes.bak.php'); } // Back up the existing file if (File::exists('app/routes.php')) { File::move('app/routes.php', 'app/routes.bak.php'); } // Generate new routes $this->info('Generating routes...'); $routes = Event::fire('toolbox.routes'); // Save new file $this->info('Saving new routes.php...'); if ($routes && !empty($routes)) { $routes = $this->getHeader() . implode("\n", $routes); File::put('app/routes.php', $routes); $this->info('Process completed!'); } else { $this->error('Nothing to save!'); } // Done! $this->line(''); } }
protected function setupLangDir() { $langDir = realpath(app_path() . '/../resources/lang'); if (File::exists("{$langDir}/en")) { File::move("{$langDir}/en", "{$langDir}/en_GB"); } }
/** * Store a newly created resource in storage. * * @param TemplateRequest $request * @return Response */ public function store(TemplateRequest $request) { ini_set('max_execution_time', 0); File::delete(base_path('resources/views/Template.php')); File::delete(storage_path('tmp/Template.php')); File::deleteDirectory(storage_path('tmp/')); $file_path = storage_path('tmp/'); $orginal_name = $request->file('file')->getClientOriginalName(); if ($request->file('file')->move($file_path, $orginal_name)) { Zipper::make($file_path . $orginal_name)->extractTo(storage_path('tmp')); $template = (require_once storage_path('tmp/Template.php')); $assets = File::move(storage_path('tmp/assets/' . $template['folder']), public_path('assets/' . $template['folder'])); $template_file = File::move(storage_path('tmp/' . $template['folder']), base_path('resources/views/' . $template['folder'])); if (!$assets || !$template_file) { File::delete(base_path('resources/views/Template.php')); File::delete(storage_path('tmp/Template.php')); File::deleteDirectory(storage_path('tmp/')); Flash::error(trans('whole::http/controllers.templates_flash_1')); return redirect()->route('admin.template.index'); } $message = $this->template->create($template) ? ['success', trans('whole::http/controllers.templates_flash_2')] : ['error', trans('whole::http/controllers.templates_flash_3')]; File::delete(base_path('resources/views/Template.php')); File::delete(storage_path('tmp/Template.php')); File::deleteDirectory(storage_path('tmp/')); Flash::$message[0]($message[1]); if ($message[0] == "success") { Logs::add('process', trans('whole::http/controllers.templates_log_1', ['name' => $template['name']])); } else { Logs::add('errors', trans('whole::http/controllers.templates_log_2')); } return redirect()->route('admin.template.index'); } }
public function storeAttachment() { $parameters = $this->request->route()->parameters(); $attachments = $this->request->input('attachments'); $attachmentsResponse = []; foreach ($attachments as $attachment) { $idAttachment = Attachment::max('id_016'); $idAttachment++; // move file from temp file to attachment folder File::move(public_path() . config($this->request->input('routesConfigFile') . '.tmpFolder') . '/' . $attachment['tmpFileName'], public_path() . config($this->request->input('routesConfigFile') . '.attachmentFolder') . '/' . $parameters['object'] . '/' . $parameters['lang'] . '/' . $attachment['fileName']); $attachmentsResponse[] = Attachment::create(['id_016' => $idAttachment, 'lang_id_016' => $parameters['lang'], 'resource_id_016' => $this->request->input('resource'), 'object_id_016' => $parameters['object'], 'family_id_016' => null, 'library_id_016' => $attachment['library'], 'library_file_name_016' => $attachment['libraryFileName'], 'sorting_016' => null, 'name_016' => null, 'file_name_016' => $attachment['fileName'], 'mime_016' => $attachment['mime'], 'size_016' => filesize(public_path() . config($this->request->input('routesConfigFile') . '.attachmentFolder') . '/' . $parameters['object'] . '/' . $parameters['lang'] . '/' . $attachment['fileName']), 'type_id_016' => $attachment['type']['id'], 'type_text_016' => $attachment['type']['name'], 'width_016' => empty($attachment['width']) ? null : $attachment['width'], 'height_016' => empty($attachment['height']) ? null : $attachment['height'], 'data_016' => json_encode(['icon' => $attachment['type']['icon']])]); } $response = ['success' => true, 'attachments' => $attachmentsResponse]; return response()->json($response); }
/** * Function to store attachment elements * * @access public * @param \Illuminate\Support\Facades\Request $attachments * @param string $lang * @param string $routesConfigFile * @param integer $objectId * @param string $resource * @return boolean */ public static function storeAttachments($attachments, $routesConfigFile, $resource, $objectId, $lang) { if (!File::exists(public_path() . config($routesConfigFile . '.attachmentFolder') . '/' . $objectId . '/' . $lang)) { File::makeDirectory(public_path() . config($routesConfigFile . '.attachmentFolder') . '/' . $objectId . '/' . $lang, 0755, true); } foreach ($attachments as $attachment) { $idAttachment = Attachment::max('id_016'); $idAttachment++; $width = null; $height = null; if ($attachment->type->id == 1) { list($width, $height) = getimagesize(public_path() . $attachment->folder . '/' . $attachment->tmpFileName); } // move file fom temp file to attachment folder File::move(public_path() . $attachment->folder . '/' . $attachment->tmpFileName, public_path() . config($routesConfigFile . '.attachmentFolder') . '/' . $objectId . '/' . $lang . '/' . $attachment->fileName); Attachment::create(['id_016' => $idAttachment, 'lang_id_016' => $lang, 'resource_id_016' => $resource, 'object_id_016' => $objectId, 'family_id_016' => empty($attachment->family) ? null : $attachment->family, 'library_id_016' => $attachment->library, 'library_file_name_016' => empty($attachment->libraryFileName) ? null : $attachment->libraryFileName, 'sorting_016' => $attachment->sorting, 'name_016' => empty($attachment->name) ? null : $attachment->name, 'file_name_016' => empty($attachment->fileName) ? null : $attachment->fileName, 'mime_016' => $attachment->mime, 'size_016' => filesize(public_path() . config($routesConfigFile . '.attachmentFolder') . '/' . $objectId . '/' . $lang . '/' . $attachment->fileName), 'type_id_016' => $attachment->type->id, 'type_text_016' => $attachment->type->name, 'width_016' => $width, 'height_016' => $height, 'data_016' => json_encode(['icon' => $attachment->type->icon])]); } }
/** * @return string */ public function getRename() { $file_to_rename = Input::get('file'); $dir = Input::get('dir'); $new_name = Str::slug(Input::get('new_name')); if ($dir == "/") { if (File::exists(base_path() . "/" . $this->file_location . $new_name)) { return "File name already in use!"; } else { if (File::isDirectory(base_path() . "/" . $this->file_location . $file_to_rename)) { File::move(base_path() . "/" . $this->file_location . $file_to_rename, base_path() . "/" . $this->file_location . $new_name); return "OK"; } else { $extension = File::extension(base_path() . "/" . $this->file_location . $file_to_rename); $new_name = Str::slug(str_replace($extension, '', $new_name)) . "." . $extension; File::move(base_path() . "/" . $this->file_location . $file_to_rename, base_path() . "/" . $this->file_location . $new_name); if (Session::get('lfm_type') == "Images") { // rename thumbnail File::move(base_path() . "/" . $this->file_location . "thumbs/" . $file_to_rename, base_path() . "/" . $this->file_location . "thumbs/" . $new_name); } return "OK"; } } } else { if (File::exists(base_path() . "/" . $this->file_location . $dir . "/" . $new_name)) { return "File name already in use!"; } else { if (File::isDirectory(base_path() . "/" . $this->file_location . $dir . "/" . $file_to_rename)) { File::move(base_path() . "/" . $this->file_location . $dir . "/" . $file_to_rename, base_path() . "/" . $this->file_location . $dir . "/" . $new_name); } else { $extension = File::extension(base_path() . "/" . $this->file_location . $dir . "/" . $file_to_rename); $new_name = Str::slug(str_replace($extension, '', $new_name)) . "." . $extension; File::move(base_path() . "/" . $this->file_location . $dir . "/" . $file_to_rename, base_path() . "/" . $this->file_location . $dir . "/" . $new_name); if (Session::get('lfm_type') == "Images") { File::move(base_path() . "/" . $this->file_location . $dir . "/thumbs/" . $file_to_rename, base_path() . "/" . $this->file_location . $dir . "/thumbs/" . $new_name); } return "OK"; } } } return true; }
/** * @param string $sourceFile * @param string $targetFile * @param string $namespace */ private function copyJumpstartAsset($sourceFile, $targetFile, $namespace = 'App\\') { $fileName = basename($targetFile); if ($this->shouldBackup && File::exists($targetFile)) { $fileNameParts = explode('.', $fileName); $newFileName = array_shift($fileNameParts) . '-original-' . Carbon::now('UTC')->format('Y-m-d_h:i:s') . '.' . implode('.', $fileNameParts); File::move($targetFile, dirname($targetFile) . '/' . $newFileName); $this->info("File '{$fileName}' already exists - renamed to '{$newFileName}'."); } elseif (!File::exists(dirname($targetFile))) { File::makeDirectory(dirname($targetFile), 0755, true, true); } if ($namespace == 'App\\') { File::copy($sourceFile, $targetFile); } else { $sourceFileContent = File::get($sourceFile); $targetFileContent = str_replace('namespace App\\', 'namespace ' . $namespace, $sourceFileContent); File::put($targetFile, $targetFileContent); } $this->info("File '{$fileName}' copied."); }
/** * @return string */ function getRename() { $file_to_rename = Input::get('file'); $dir = Input::get('dir'); $new_name = Str::slug(Input::get('new_name')); if ($dir == "/") { if (File::exists(base_path() . "/" . Config::get('sfm.dir') . $new_name)) { return Lang::get('filemanager::sfm.file_exists'); } else { if (File::isDirectory(base_path() . "/" . Config::get('sfm.dir') . $file_to_rename)) { File::move(base_path() . "/" . Config::get('sfm.dir') . $file_to_rename, base_path() . "/" . Config::get('sfm.dir') . $new_name); return "OK"; } else { $extension = File::extension(base_path() . "/" . Config::get('sfm.dir') . $file_to_rename); $new_name = Str::slug(str_replace($extension, '', $new_name)) . "." . $extension; if (@getimagesize(base_path() . "/" . Config::get('sfm.dir') . $file_to_rename)) { // rename thumbnail File::move(base_path() . "/" . Config::get('sfm.dir') . "/.thumbs/" . $file_to_rename, base_path() . "/" . Config::get('sfm.dir') . "/.thumbs/" . $new_name); } File::move(base_path() . "/" . Config::get('sfm.dir') . $file_to_rename, base_path() . "/" . Config::get('sfm.dir') . $new_name); return "OK"; } } } else { if (File::exists(base_path() . "/" . Config::get('sfm.dir') . $dir . "/" . $new_name)) { return Lang::get('filemanager::sfm.file_exists'); } else { if (File::isDirectory(base_path() . "/" . Config::get('sfm.dir') . $dir . "/" . $file_to_rename)) { File::move(base_path() . "/" . Config::get('sfm.dir') . $dir . "/" . $file_to_rename, base_path() . "/" . Config::get('sfm.dir') . $dir . "/" . $new_name); } else { $extension = File::extension(base_path() . "/" . Config::get('sfm.dir') . $dir . "/" . $file_to_rename); $new_name = Str::slug(str_replace($extension, '', $new_name)) . "." . $extension; if (@getimagesize(base_path() . "/" . Config::get('sfm.dir') . $dir . "/" . $file_to_rename)) { File::move(base_path() . "/" . Config::get('sfm.dir') . $dir . "/.thumbs/" . $file_to_rename, base_path() . "/" . Config::get('sfm.dir') . $dir . "/.thumbs/" . $new_name); } File::move(base_path() . "/" . Config::get('sfm.dir') . $dir . "/" . $file_to_rename, base_path() . "/" . Config::get('sfm.dir') . $dir . "/" . $new_name); return "OK"; } } } }
/** * Execute the command. */ public function handle() { $name = $this->argument('name'); $domain = $this->argument('domain'); $webExecution = $this->option('webExecution'); try { $workingPath = base_path('../'); $outputFolder = strtolower(str_replace(' ', '-', $name . '-api')); $this->writeStatus('Installing lumen and dependencies ...', $webExecution); // Create project (new Composer($workingPath))->createProject('laravel/lumen', '5.1.*', $outputFolder)->setWorkingPath($workingPath . $outputFolder)->requirePackage('dingo/api', '1.0.x@dev'); $this->writeStatus('Setting up lumen ...', $webExecution); // Rename .env file File::move($workingPath . $outputFolder . '/.env.example', $workingPath . $outputFolder . '/.env'); // Dingo config File::append($workingPath . $outputFolder . '/.env', 'API_DOMAIN=' . $domain . PHP_EOL . 'API_STANDARDS_TREE=vnd' . PHP_EOL . 'API_SUBTYPE=' . strtolower(str_replace(' ', '', $name)) . PHP_EOL . 'API_VERSION=v1' . PHP_EOL . 'API_NAME="' . $name . '"' . PHP_EOL . 'API_CONDITIONAL_REQUEST=false' . PHP_EOL . 'API_STRICT=false' . PHP_EOL . 'API_DEFAULT_FORMAT=json' . PHP_EOL . 'API_DEBUG=true'); // Get lumen app file $lumenAppFile = File::get($workingPath . $outputFolder . '/bootstrap/app.php'); // Get .env file $lumenEnvFile = File::get($workingPath . $outputFolder . '/.env'); // Enable Dotenv $lumenAppFile = str_replace('// Dotenv::load(__DIR__.\'/../\');', 'Dotenv::load(__DIR__.\'/../\');', $lumenAppFile); // Enable Eloquent $lumenAppFile = str_replace('// $app->withEloquent();', '$app->withEloquent();', $lumenAppFile); // Add Dingo service provider $registerServiceProviderPosition = strpos($lumenAppFile, 'Register Service Providers'); $lumenAppFile = substr($lumenAppFile, 0, $registerServiceProviderPosition + 322) . '$app->register(Dingo\\Api\\Provider\\LumenServiceProvider::class);' . substr($lumenAppFile, $registerServiceProviderPosition + 320); // Database config $lumenEnvFile = str_replace('DB_DATABASE=homestead', 'DB_DATABASE=' . env('DB_DATABASE', 'homestead'), $lumenEnvFile); $lumenEnvFile = str_replace('DB_USERNAME=homestead', 'DB_USERNAME='******'DB_USERNAME', 'homestead'), $lumenEnvFile); $lumenEnvFile = str_replace('DB_PASSWORD=secret', 'DB_PASSWORD='******'DB_PASSWORD', 'secret'), $lumenEnvFile); File::put($workingPath . $outputFolder . '/.env', $lumenEnvFile); File::put($workingPath . $outputFolder . '/bootstrap/app.php', $lumenAppFile); } catch (\Exception $exception) { $this->writeStatus('Error', $webExecution); Log::error($exception->getMessage()); } }
public function generate() { /*GENERATE BASE CONTROLLER FOR NAMESPACE */ if (!FileSystem::exists($this->path . $this->pathname . '/BaseController.php')) { $baseDistPath = realpath(__DIR__ . '/../Controllers/BaseController.php.dist'); $basePath = realpath(__DIR__ . '/../Controllers/') . '/BaseController.php'; $copy = FileSystem::copy($baseDistPath, $basePath); $base = realpath(__DIR__ . '/../Controllers/BaseController.php'); $find = 'use App\\Http\\Controllers\\Controller;'; $replace = 'use ' . $this->getAppNamespace() . 'Http\\Controllers\\Controller;'; $find2 = 'namespace AppNamespace\\Http\\Controllers\\API;'; $replace2 = 'namespace ' . $this->getAppNamespace() . 'Http\\Controllers\\' . $this->pathname . ';'; FileSystem::put($base, str_replace($find2, $replace2, str_replace($find, $replace, file_get_contents($base)))); if (!FileSystem::isDirectory($this->path . $this->pathname)) { FileSystem::makeDirectory($this->path . $this->pathname); } FileSystem::move($base, $this->path . $this->pathname . '/BaseController.php'); } $prefix = $this->prefix ? $this->prefix . '/' : ''; $repository = File::make($this->filename)->setLicensePhpdoc(new LicensePhpdoc(self::PROJECT_NAME, self::AUTHOR_NAME, self::AUTHOR_EMAIL))->addFullyQualifiedName(new FullyQualifiedName(\Illuminate\Http\Request::class))->addFullyQualifiedName(new FullyQualifiedName($this->namespace . "BaseController"))->addFullyQualifiedName(new FullyQualifiedName($this->appNamespace . "Repositories\\" . $this->entity . "Repository as Repository"))->addFullyQualifiedName(new FullyQualifiedName($this->appNamespace . "Managers\\" . $this->entity . "Manager as Manager"))->setStructure(Object::make($this->namespace . $this->entity . $this->layer)->extend(new Object(BaseController::class))->addMethod(Method::make('__construct')->addArgument(new Argument('Repository', 'Repository'))->addArgument(new Argument('Manager', 'Manager'))->setBody(' return parent::__construct($Repository , $Manager);'))->addMethod(Method::make('index')->setPhpdoc(MethodPhpdoc::make()->setDescription(Description::make('@api {get} /' . $prefix . snake_case(str_plural($this->entity)) . ' 1 Request all ' . snake_case(str_plural($this->entity)))->addLine('@apiVersion 1.0.0')->addLine('@apiName All' . str_plural($this->entity))->addLine('@apiGroup ' . str_plural($this->entity))->addEmptyLine()->addLine('@apiSuccess {Object[]} 0 ' . $this->entity . ' Object.')->addLine('@apiSuccess {Number} 0.id Id.')->addLine('@apiSuccess {DateTime} 0.created_at Created date.')->addLine('@apiSuccess {DateTime} 0.updated_at Last modification date.')->addEmptyLine()->addLine("@apiSuccessExample Success 200 Example")->addLine(" HTTP/1.1 200 OK")->addLine("[")->addLine(" {")->addLine(' id: 1,')->addLine(' created_at: ' . date('Y-m-d h:i:s') . ',')->addLine(' updated_at: ' . date('Y-m-d h:i:s'))->addLine(" },")->addLine(" {")->addLine(' id: 2,')->addLine(' created_at: ' . date('Y-m-d h:i:s') . ',')->addLine(' updated_at: ' . date('Y-m-d h:i:s'))->addLine(" }")->addLine("]")->addEmptyLine()->addLine("@apiError (ServerError 500) {string} error Server error.")->addEmptyLine()->addLine("@apiErrorExample {json} ServerError 500 Example")->addLine(" HTTP/1.1 404 Not Found")->addLine("{")->addLine(' error: Server error. Try again.')->addLine("}")))->addArgument(new Argument('Request', 'Request'))->setBody(' return parent::index($Request);'))->addMethod(Method::make('show')->setPhpdoc(MethodPhpdoc::make()->setDescription(Description::make('@api {get} /' . $prefix . snake_case(str_plural($this->entity)) . '/:id 2 Request a specific ' . snake_case($this->entity))->addLine('@apiVersion 1.0.0')->addLine('@apiName Get' . $this->entity)->addLine('@apiGroup ' . str_plural($this->entity))->addEmptyLine()->addLine('@apiParam (Url params) {Number} id ' . $this->entity . ' unique id.')->addEmptyLine()->addLine('@apiSuccess {Number} id Id.')->addLine('@apiSuccess {DateTime} created_at Created date.')->addLine('@apiSuccess {DateTime} updated_at Last modification date.')->addEmptyLine()->addLine("@apiSuccessExample {json} Success 200 Example")->addLine(" HTTP/1.1 200 OK")->addLine("{")->addLine(' id: 1,')->addLine(' created_at: ' . date('Y-m-d h:i:s') . ',')->addLine(' updated_at: ' . date('Y-m-d h:i:s'))->addLine("}")->addEmptyLine()->addLine("@apiError (EntityNotFound 404) {string} error The id of the " . snake_case($this->entity) . " was not found.")->addEmptyLine()->addLine("@apiErrorExample {json} EntityNotFound 404 Example")->addLine(" HTTP/1.1 404 Not Found")->addLine("{")->addLine(' error: Entity not found')->addLine("}")->addEmptyLine()->addLine("@apiError (ServerError 500) {string} error Server error.")->addEmptyLine()->addLine("@apiErrorExample {json} ServerError 500 Example")->addLine(" HTTP/1.1 404 Not Found")->addLine("{")->addLine(' error: Server error. Try again.')->addLine("}")))->addArgument(new Argument('Request', 'Request'))->addArgument(new Argument('integer', 'id'))->setBody(' return parent::show($Request , $id);'))->addMethod(Method::make('store')->setPhpdoc(MethodPhpdoc::make()->setDescription(Description::make('@api {post} /' . $prefix . snake_case(str_plural($this->entity)) . ' 3 Store a ' . snake_case($this->entity))->addLine('@apiVersion 1.0.0')->addLine('@apiName Store' . $this->entity)->addLine('@apiGroup ' . str_plural($this->entity))->addEmptyLine()->addLine('@apiParam (FormData) {String} name ' . $this->entity . ' name.')->addEmptyLine()->addLine('@apiSuccess (Success 201) {Number} id Id.')->addLine('@apiSuccess (Success 201) {DateTime} created_at Created date.')->addLine('@apiSuccess (Success 201) {DateTime} updated_at Last modification date.')->addEmptyLine()->addLine("@apiSuccessExample {json} Success 201 Example")->addLine(" HTTP/1.1 201 OK")->addLine("{")->addLine(' id: 1,')->addLine(' created_at: ' . date('Y-m-d h:i:s') . ',')->addLine(' updated_at: ' . date('Y-m-d h:i:s'))->addLine("}")->addEmptyLine()->addLine("@apiError (ValidationErrors 400) {array[]} name List of errors for name field.")->addLine("@apiError (ValidationErrors 400) {string} name.0 First error for name.")->addLine("@apiError (ValidationErrors 400) {string} name.1 Second error for name.")->addEmptyLine()->addLine("@apiErrorExample {json} ValidationErrors 400 Example")->addLine(" HTTP/1.1 400 Bad Request")->addLine("{")->addLine(' name: [')->addLine(' The name field is required')->addLine(" ]")->addLine("}")->addEmptyLine()->addLine("@apiError (ServerError 500) {string} error Server error.")->addEmptyLine()->addLine("@apiErrorExample {json} ServerError 500 Example")->addLine(" HTTP/1.1 404 Not Found")->addLine("{")->addLine(' error: Server error. Try again.')->addLine("}")))->addArgument(new Argument('Request', 'Request'))->setBody(' return parent::store($Request);'))->addMethod(Method::make('update')->setPhpdoc(MethodPhpdoc::make()->setDescription(Description::make('@api {put} /' . $prefix . snake_case(str_plural($this->entity)) . '/:id 4 Update a specific ' . snake_case($this->entity))->addLine('@apiVersion 1.0.0')->addLine('@apiName Update' . $this->entity)->addLine('@apiGroup ' . str_plural($this->entity))->addEmptyLine()->addLine('@apiParam (Url params) {Number} id ' . $this->entity . ' unique id.')->addLine('@apiParam (FormData) {String} name ' . $this->entity . ' name.')->addEmptyLine()->addLine('@apiSuccess {Number} id Id.')->addLine('@apiSuccess {DateTime} created_at Created date.')->addLine('@apiSuccess {DateTime} updated_at Last modification date.')->addEmptyLine()->addLine("@apiSuccessExample {json} Success 200 Example")->addLine(" HTTP/1.1 200 OK")->addLine("{")->addLine(' id: 1,')->addLine(' created_at: ' . date('Y-m-d h:i:s') . ',')->addLine(' updated_at: ' . date('Y-m-d h:i:s'))->addLine("}")->addEmptyLine()->addLine("@apiError (EntityNotFound 404) {string} error The id of the " . snake_case($this->entity) . " was not found.")->addEmptyLine()->addLine("@apiErrorExample {json} EntityNotFound 404 Example")->addLine(" HTTP/1.1 404 Not Found")->addLine("{")->addLine(' error: Entity not found')->addLine("}")->addEmptyLine()->addLine("@apiError (ValidationErrors 400) {array[]} name List of errors for name field.")->addLine("@apiError (ValidationErrors 400) {string} name.0 First error for name.")->addLine("@apiError (ValidationErrors 400) {string} name.1 Second error for name.")->addEmptyLine()->addLine("@apiErrorExample {json} ValidationErrors 400 Example")->addLine(" HTTP/1.1 400 Bad Request")->addLine("{")->addLine(' name: [')->addLine(' The name field is required')->addLine(" ]")->addLine("}")->addEmptyLine()->addLine("@apiError (ServerError 500) {string} error Server error.")->addEmptyLine()->addLine("@apiErrorExample {json} ServerError 500 Example")->addLine(" HTTP/1.1 404 Not Found")->addLine("{")->addLine(' error: Server error. Try again.')->addLine("}")))->addArgument(new Argument('Request', 'Request'))->addArgument(new Argument('integer', 'id'))->setBody(' return parent::update($Request , $id);'))->addMethod(Method::make('destroy')->setPhpdoc(MethodPhpdoc::make()->setDescription(Description::make('@api {delete} /' . $prefix . snake_case(str_plural($this->entity)) . '/:id 5 Delete a specific ' . snake_case($this->entity))->addLine('@apiVersion 1.0.0')->addLine('@apiName Delete' . $this->entity)->addLine('@apiGroup ' . str_plural($this->entity))->addEmptyLine()->addLine('@apiParam (Url params) {Number} id ' . $this->entity . ' unique id.')->addEmptyLine()->addLine("@apiSuccessExample Success 204 Example")->addLine(" HTTP/1.1 204 OK")->addEmptyLine()->addLine("@apiError (EntityNotFound 404) {string} error The id of the " . snake_case($this->entity) . " was not found.")->addEmptyLine()->addLine("@apiErrorExample {json} EntityNotFound 404 Example")->addLine(" HTTP/1.1 404 Not Found")->addLine("{")->addLine(' error: Entity not found')->addLine("}")->addEmptyLine()->addLine("@apiError (ServerError 500) {string} error Server error.")->addEmptyLine()->addLine("@apiErrorExample {json} ServerError 500 Example")->addLine(" HTTP/1.1 404 Not Found")->addLine("{")->addLine(' error: Server error. Try again.')->addLine("}")))->addArgument(new Argument('Request', 'Request'))->addArgument(new Argument('integer', 'id'))->setBody(' return parent::destroy($Request , $id);'))); $prettyPrinter = Build::prettyPrinter(); $generatedCode = $prettyPrinter->generateCode($repository); return $this->generateFile($generatedCode); }
/** * Update the specified resource in storage. * * @param \App\Http\Requests\DepartmentRequest $request * @param \App\Department $department * @return \Illuminate\Http\Response */ public function update(Requests\DepartmentRequest $request, Department $department) { DB::transaction(function () use($department, $request) { $oldKeyword = $department->keyword; $data = ['keyword' => $request->get('keyword'), 'url' => $request->get('url'), 'theme_background_color' => $request->get('theme_background_color'), 'theme_color' => $request->get('theme_color'), 'sort' => $request->get('sort'), 'active' => $request->get('active')]; if ($request->file('image')) { $data['image'] = $request->file('image')->getClientOriginalName(); File::delete('images/' . $department->image); $request->file('image')->move('images/', $request->file('image')->getClientOriginalName()); } $department->update($data); $department->langs()->delete(); $this->addDepartmentLangs($request, $department); if ($department->keyword != $oldKeyword) { File::move('papers/' . $oldKeyword, 'papers/' . $department->keyword); } Cache::forget('departments'); }); return redirect(action('Admin\\DepartmentController@index'))->with('success', 'updated'); }
/** * Update the specified resource in storage. * * @param Requests\PaperRequest $request * @param Paper $paper * @return \Illuminate\Http\Response */ public function update(Requests\PaperRequest $request, Paper $paper) { $this->paper->setPaper($paper); $status = $request->get('status_id'); $reviewer = $request->get('reviewer_id') ?: null; if (!$paper->reviewer_id && $reviewer) { if ($request->get('status_id') < 2) { $status = 2; } } $department = Department::find($request->get('department_id')); $this->paper->setUrl($department->keyword); if (!in_array($request->get('category_id'), $department->categories->lists('id')->toArray())) { return redirect()->back()->with('error', 'department-category'); } if ($paper->department_id != $request->get('department_id')) { #if department is changed files must be moved $url = $this->paper->prefix(); $oldPath = $url . '/' . $paper->department->keyword . '/'; $newPath = $url . '/' . $department->keyword . '/'; File::move($oldPath . $paper->source, $newPath . $paper->source); if ($paper->payment_source) { File::move($oldPath . $paper->payment_source, $newPath . $paper->payment_source); } } $paperData = ['department_id' => $department->id, 'category_id' => $request->get('category_id'), 'status_id' => $status, 'title' => $request->get('title'), 'description' => $request->get('description'), 'authors' => $request->get('authors'), 'user_id' => $request->get('user_id'), 'reviewer_id' => $reviewer, 'updated_at' => Carbon::now(), 'payment_description' => $request->get('payment_description')]; if ($request->file('paper')) { $paperData['source'] = $this->paper->buildFileName(); $this->paper->deleteFile(); } if ($request->file('payment_source')) { $paperData['payment_source'] = $this->paper->buildInvoiceName(); $this->paper->deleteInvoice(); } $this->paper->upload(); $oldReviewer = $paper->reviewer_id; $paper->update($paperData); if ($oldReviewer != $paper->reviewer_id) { #reviewer changed event(new ReviewerPaperSet($paper)); } return redirect()->action('Admin\\PaperController@index')->with('success', 'updated'); }
/** * Save * * Boilerplate method to save file and backup existing one. * @param string $path File path * @param string $contents Contents to save to the file * @return bool True on sucess, false otherwise */ protected function save($path, $contents) { $success = false; // Remove the old backup if (File::exists($path . '.bak.php')) { File::delete($path . '.bak.php'); } // Back up the existing file if (File::exists($path . '.php')) { File::move($path . '.php', $path . '.bak.php'); } // Save the new file if (File::put($path . '.php', $contents)) { $success = true; } return $success; }
/** * Update the user's settings. * * @param \Tricks\User $user * @param array $data * @return \Tricks\User */ public function updateSettings(User $user, array $data) { $user->username = $data['username']; $user->companyname = $data['companyname']; $user->phonenumber = $data['phonenumber']; $user->Address = $data['Address']; $user->flag_name = $data['flag_name']; /*if ($data['flag_name'] = ''){ $user->flag_name = 0;#$data['flag_name']; } else { $user->flag_name = 1; } */ $user->password = $data['password'] != '' ? $data['password'] : $user->password; //Hash::make($data['password']) : $user->password; if ($data['avatar'] != '') { File::move(public_path() . '/img/avatar/temp/' . $data['avatar'], 'img/avatar/' . $data['avatar']); if ($user->photo) { File::delete(public_path() . '/img/avatar/' . $user->photo); } $user->photo = $data['avatar']; } return $user->save(); }
/** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param int $id * @return \Illuminate\Http\Response */ public function update(Request $request) { // $contestDefault = Contest::where('default', '=', 'Yes')->get()->first(); $contestant = Contestant::find($request->id); $contestant->full_name = $request->full_name; $contestant->email = $request->email; $contestant->phone = $request->phone; $contestant->region_id = $request->region; $contestant->district_id = $request->district; $contestant->city = $request->city; $contestant->zone = $request->zone; $contestant->registration_date = date("Y-m-d"); $contestant->profile_note = $request->profile_note; $contestant->status = "Active"; $contestant->dob = $request->dob; $contestant->contest_year = date("Y"); if (count($contestDefault) > 0 && $contestDefault != null && $contestDefault != "") { $contestant->contest_id = $contestDefault->id; } $contestant->save(); if ($request->uploadedFileName != "") { $newfile = config('app.contestant_image_profile') . $request->uploadedFileName; $oldfile = config('app.contestant_image_profile_tmp') . $request->uploadedFileName; if (!File::exists($newfile)) { File::move($oldfile, $newfile); $contestant->profile_image = $request->uploadedFileName; $contestant->save(); /// //Copy to front folder $file_namenw = config('app.contestant_front_image_profile') . $request->uploadedFileName; File::copy($newfile, $file_namenw); } else { $contestant->profile_image = $request->uploadedFileName; $contestant->save(); //Copy to front folder $file_namenw = config('app.contestant_front_image_profile') . $request->uploadedFileName; File::copy($newfile, $file_namenw); } } return redirect('contestant/manage'); }
/** * Upload an image to the public storage * @param File $file * @return string */ public function upload($file, $dir = null, $createDimensions = false) { if ($file) { // Generate random dir if (!$dir) { $dir = str_random(8); } // Get file info and try to move $destination = Config::get('redminportal::image.upload_path') . $dir; $filename = $file->getClientOriginalName(); $path = RHelper::joinPaths(Config::get('redminportal::image.upload_dir'), $dir, $filename); $uploaded = $file->move($destination, $filename); if ($uploaded) { if ($createDimensions) { $this->createDimensions($path); } return $path; } } }
/** * Run the settings table seeder * @param string $master */ public function settingsSeeder($master = 'master') { $cli_path = 'config/ticketit.php'; // if seeder run from cli, use the cli path $provider_path = '../config/ticketit.php'; // if seeder run from provider, use the provider path $config_settings = []; $settings_file_path = false; if (File::isFile($cli_path)) { $settings_file_path = $cli_path; } elseif (File::isFile($provider_path)) { $settings_file_path = $provider_path; } if ($settings_file_path) { $config_settings = (include $settings_file_path); File::move($settings_file_path, $settings_file_path . '.backup'); } $seeder = new SettingsTableSeeder(); $config_settings['master_template'] = $master; $seeder->config = $config_settings; $seeder->run(); }
/** * Función para mover ficheros * * @access public * @param $path * @param $target * @param $fileName * @param bool $encryption * @param bool $newFilename * @return bool */ public static function move($path, $target, $fileName, $encryption = false, $newFilename = false) { $fileNameOld = $fileName; $extension = File::extension($fileName); $baseName = basename($fileName, '.' . $extension); if ($encryption) { mt_srand(); $fileName = md5(uniqid(mt_rand())) . "." . $extension; } elseif ($newFilename) { $fileName = $newFilename . "." . $extension; } $i = 0; while (File::exists($target . '/' . $fileName)) { $i++; $fileName = $baseName . '-' . $i . '.' . $extension; } File::move($path . '/' . $fileNameOld, $target . '/' . $fileName); return $fileName; }
public static function makeThumb($extension, $filename) { switch ($extension) { case 'pdf': case 'PDF': $name = pathinfo($filename, PATHINFO_FILENAME); $pdf = new Spatie\PdfToImage\Pdf(storage_path('app/' . $filename)); $old_path = storage_path() . '/app/' . $name . '.jpg'; $pdf->saveImage($old_path); MaterialFile::resize($name . '.jpg'); $new_path = storage_path() . '/app/thumbs/' . $name . '.jpg'; if (File::move($old_path, $new_path)) { $pathToPicture = '/thumbs'; break; } else { $pathToPicture = "failed to copy {$filename}...\n"; break; } break; case 'doc': case 'DOC': case 'docx': case 'DOCX': case 'ppt': case 'PPT': case 'pptx': case 'PPTX': $path = storage_path() . '/app/'; chdir($path); exec("export HOME=/tmp && libreoffice --headless --convert-to pdf {$filename}"); $name = pathinfo($filename, PATHINFO_FILENAME); $pdf = new Spatie\PdfToImage\Pdf(storage_path('app/' . $name . '.pdf')); $old_path = $name . '.jpg'; $pdf->saveImage($old_path); MaterialFile::resize($old_path); $new_path = storage_path() . '/app/thumbs/' . $name . '.jpg'; if (File::move($old_path, $new_path)) { $pathToPicture = '/thumbs'; $pdf = $name . '.pdf'; MaterialFileController::destroyFile($pdf); break; } else { $pathToPicture = "failed to copy {$filename}...\n"; break; } break; case 'jpg': case 'JPG': case 'png': case 'PNG': case 'bmp': MaterialFile::resize($filename); $new_path = storage_path() . '/app/thumbs/' . $filename; if (File::move($filename, $new_path)) { $pathToPicture = '/thumbs'; break; } else { $pathToPicture = "failed to copy {$filename}...\n"; break; } break; case 'mp3': case 'MP3': $name = pathinfo($filename, PATHINFO_FILENAME); $old_path = 'img/audio.png'; $new_path = storage_path() . '/app/thumbs/' . $name . '.jpg'; if (File::move($old_path, $new_path)) { $pathToPicture = '/thumbs'; break; } else { $pathToPicture = "failed to copy {$filename}...\n"; break; } break; case 'WMV': case 'wmv': case 'mp4': case 'MP4': case 'avi': case 'AVI': case 'mov': case 'MOV': $path = storage_path() . '/app/'; chdir($path); $name = pathinfo($filename, PATHINFO_FILENAME); exec("ffmpeg -i {$filename} -ss 1 -vframes 1 {$name}.jpg"); $old_path = $name . '.jpg'; MaterialFile::resize($old_path); $new_path = storage_path() . '/app/thumbs/' . $name . '.jpg'; if (File::move($old_path, $new_path)) { $pathToPicture = '/thumbs'; break; } else { $pathToPicture = "failed to copy {$filename}...\n"; break; } break; default: $pathToPicture = 'img/file-icon.png'; break; } return $pathToPicture; }
/** * Execute the console command. * * @return mixed */ public function handle() { $config = Config::get('mail'); switch ($config['encryption']) { case 'ssl': $connection_string = '{' . $config['host'] . ':993/imap/ssl}INBOX'; break; case 'tls': $connection_string = '{' . $config['host'] . ':143/imap/tls}INBOX'; break; case null: default: $connection_string = '{' . $config['host'] . ':143/imap}INBOX'; break; } $this->info($connection_string); $tmp_attachment_path = storage_path() . '/attachments/tmp'; $mailbox = new Mailbox($connection_string, $config['username'], $config['password'], $tmp_attachment_path); if (!$mailbox) { $this->error('Unable to connect to the IMAP server'); } $mailIds = $mailbox->searchMailbox('UNSEEN'); $this->info('Found ' . count($mailIds) . ' new emails to check'); if (!empty($mailIds)) { foreach ($mailIds as $mailId) { $msg = $mailbox->getMail($mailId); $subject = str_replace(array('Re: ', 'RE: '), '', $msg->subject); $email = $msg->fromAddress; if ($msg->textHtml == '') { $response = $msg->textPlain; $response = str_replace("\n\r", '<br>', $response); $response = str_replace("\n", '<br>', $response); $response = '<p>' . $response . '</p>'; } else { $response = $msg->textHtml; } $_subjectParts = explode(' - ', $subject); if (count($_subjectParts) > 1) { $_subjectParts = explode('[', $_subjectParts[1]); $this->info('Email details:'); $this->info('Subject: ' . $subject); $this->info('Email : ' . $email); $this->info('TrackID : ' . $_subjectParts[0]); // Find the ticket $ticket = Ticket::where('track_id', $_subjectParts[0])->first(); // Find the user $user = User::where('email', $email)->first(); if (count($ticket) > 0 || count($user) > 0) { $this->info('Email associated with ticket ' . $ticket->id); $this->info('Email associated with user ' . $user->first_name . ' ' . $user->last_name); $uploadPath = storage_path() . '/attachments/' . $ticket->id; $response = TicketResponse::create(['user_id' => $user->id, 'response' => $response, 'source' => 'email', 'ticket_id' => $ticket->id]); $attachments = $msg->getAttachments(); if (count($attachments) > 0) { $fs = new Filesystem(); if (!$fs->isDirectory($uploadPath)) { $fs->makeDirectory($uploadPath); } } foreach ($attachments as $attachment) { $tmpPath = $attachment->filePath; $fileName = $attachment->name; $this->info('Trying to move file from ' . $tmpPath . ' to ' . $uploadPath . '/' . $fileName); File::move($tmpPath, $uploadPath . '/' . $fileName); Attachment::create(['user_id' => $user->id, 'name' => $fileName, 'ticket_response_id' => $response->id]); } $this->dispatch(new EmailUpdatedTicket($ticket, $response)); } else { $this->info('Ticket or User not found'); } } else { $this->info('Not an email for us'); } } } }
/** * Update the user's settings. * * @param \Tricks\User $user * @param array $data * * @return \Tricks\User */ public function updateSettings(User $user, array $data) { $user->username = $data['username']; if ($data['password'] != '') { $user->password = Hash::make($data['password']); } if ($data['avatar'] != '') { File::move(public_path() . '/img/avatar/temp/' . $data['avatar'], 'img/avatar/' . $data['avatar']); if ($user->photo) { File::delete(public_path() . '/img/avatar/' . $user->photo); } $user->photo = $data['avatar']; } return $user->save(); }
/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { $rules = ['name' => ['required', 'unique:archive,name', 'regex:' . config('app.expressions.dir')]]; if ($this->systemAdmin) { $rules['department_id'] = 'required'; } $validator = Validator::make($request->all(), $rules); if ($validator->fails()) { return redirect()->back()->withErrors($validator)->withInput(); } DB::transaction(function () use($request) { #add all papers from department to archive $archive = Archive::create($request->all()); $department = Department::findOrFail($request->get('department_id')); $paperObj = new PaperClass(); $archivePath = 'archive/'; if (!File::exists($archivePath . $archive->name)) { File::makeDirectory($archivePath . $archive->name); } $newPath = $archivePath . $archive->name . '/'; $oldPath = $paperObj->prefix() . '/' . $department->keyword . '/'; foreach ($department->papers()->archived()->get() as $paper) { $paper->archive()->associate($archive); $paper->save(); File::move($oldPath . $paper->source, $newPath . $paper->source); if ($paper->payment_source) { File::move($oldPath . $paper->payment_source, $newPath . $paper->payment_source); } } }); return redirect()->action('Admin\\ArchiveController@index')->with('success', 'updated'); }
/** * @param $findResults * @param $directory * @param $fileNameWithoutExt * @param $imagePattern * @param $row * @param $createdProductCategories */ private function createProductCategory($findResults, $directory, $fileNameWithoutExt, $imagePattern, $row, $createdProductCategories) { $imageOriginalPath = $findResults[0]; $imageExt = File::extension($imageOriginalPath); $imagePath = $directory . $fileNameWithoutExt . $imagePattern . '.' . $imageExt; $newImagePath = 'img/uploads/' . str_random(32) . '.' . $imageExt; File::move($imagePath, public_path() . '/' . $newImagePath); $createdProductCategories[$row['nomer']] = ProductCategory::create(['title' => $row['nazvanie'], 'image' => $newImagePath, 'description' => $row['opisanie']]); }
/** * Renommage des images de l'objet : on renomme non seulement l'image principale mais aussi toutes les vignettes * Le nouveau nom de l'image doit avoir été enregistré dans $this. L'ancien nom se trouve dans getOriginal() * */ public function resetImagesNames() { $imagesDirectoryPath = $this->imagesDirectoryPath(true); $originalImageName = $this->getOriginal('image'); // On renomme l'image originale... $originalImagePath = $imagesDirectoryPath . DIRECTORY_SEPARATOR . $originalImageName; $newImagePath = $this->imagePath(null, true); File::move($originalImagePath, $newImagePath); // ... puis les vignettes foreach (self::$thumbnail_size as $alias => $sizeArray) { $subdirectory = $sizeArray['width'] . 'x' . $sizeArray['height']; $originalThumbnailPath = $imagesDirectoryPath . DIRECTORY_SEPARATOR . $subdirectory . DIRECTORY_SEPARATOR . $originalImageName; $newThumbnailPath = $imagesDirectoryPath . DIRECTORY_SEPARATOR . $subdirectory . DIRECTORY_SEPARATOR . $this->image; File::move($originalThumbnailPath, $newThumbnailPath); } }