PluginProbe
Depicter — Popup & Slider Builder / 1.3.3
Depicter — Popup & Slider Builder v1.3.3
4.8.1 trunk 1.0.0 1.1.0 1.1.2 1.1.4 1.1.6 1.1.7 1.1.8 1.1.9 1.2.0 1.3.0 1.3.1 1.3.2 1.3.3 1.3.5 1.3.8 1.5.0 1.5.1 1.5.2 1.5.5 1.6.0 1.6.1 1.6.2 1.7.0 All 76 releases
depicter / app / src / Controllers / Ajax / ImportAjaxController.php

ImportAjaxController.php in Depicter — Popup & Slider Builder 1.3.3, at app/src/Controllers/Ajax/ImportAjaxController.php

54 lines 1.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Depicter\Controllers\Ajax;
3
4 use GuzzleHttp\Psr7\UploadedFile;
5 use WPEmerge\Requests\RequestInterface;
6
7 class ImportAjaxController
8 {
9
10 /**
11 * @param RequestInterface $request
12 * @param $view
13 *
14 * @return \Psr\Http\Message\ResponseInterface
15 */
16 public function unpack( RequestInterface $request, $view ) {
17 $zipFile = $request->files('file');
18
19 if ( empty( $zipFile ) || ! $zipFile instanceof UploadedFile ) {
20 return \Depicter::json([
21 'errors' => [ 'No file provided to upload']
22 ])->withStatus(400 );
23 }
24
25 if ( $zipFile->getError() ) {
26 return \Depicter::json([
27 'errors' => [
28 sprintf( __( 'Cannot upload the file, because max permitted file upload size is %s.', 'depicter' ), ini_get('upload_max_filesize') )
29 ]
30 ]);
31 }
32
33 $zipMediaTypes = [
34 'application/zip',
35 'application/x-zip-compressed'
36 ];
37 if( !in_array( $zipFile->getClientMediaType(), $zipMediaTypes ) ){
38 return \Depicter::json([
39 'errors' => [ 'Provided file must be zip file.']
40 ])->withStatus(400 );
41 }
42
43 if ( \Depicter::importService()->unpack($zipFile) ) {
44 return \Depicter::json([
45 'success' => [ 'Slider imported successfully']
46 ])->withStatus(200 );
47 } else {
48 return \Depicter::json([
49 'errors' => [ 'Error occurred during import process.']
50 ])->withStatus(400 );
51 }
52 }
53 }
54