PluginProbe
Depicter — Popup & Slider Builder / 1.9.2
Depicter — Popup & Slider Builder v1.9.2
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
← All changes | app/src/Controllers/Ajax/CuratedAPIAjaxController.php +33 -12 1.3.8 → 1.9.2 View file →
@@ -1,8 +1,9 @@
1 1 <?php
2 2 namespace Depicter\Controllers\Ajax;
3 3
4 4 use Averta\WordPress\Utility\JSON;
5 +use Depicter\Document\Mapper;
5 6 use Depicter\GuzzleHttp\Exception\GuzzleException;
6 7 use Depicter\Services\AssetsAPIService;
7 8 use Depicter\Utility\Http;
8 9 use Depicter\Utility\Sanitize;
@@ -63,14 +64,20 @@
63 64 $page = !empty( $request->query('page') ) ? Sanitize::int( $request->query('page') ) : 1;
64 65 $perpage = !empty( $request->query('perpage') ) ? Sanitize::int( $request->query('perpage') ) : 20;
65 66 $category = !empty( $request->query('category') ) ? Sanitize::textfield( $request->query('category') ) : '';
66 67 $search = !empty( $request->query('s') ) ? Sanitize::textfield( $request->query('s') ) : '';
68 + $version = !empty( $request->query('v') ) ? Sanitize::textfield( $request->query('v') ) : '1';
69 + $from = !empty( $request->query('from') ) ? Sanitize::textfield( $request->query('from') ) : 'website';
70 + $directory= !empty( $request->query('directory') ) ? Sanitize::textfield( $request->query('directory') ) : 2;
67 71
68 72 $options = [
69 73 'page' => $page,
70 74 'perpage' => $perpage,
71 75 'category' => $category,
72 - 's' => $search
76 + 's' => $search,
77 + 'v' => $version,
78 + 'from' => $from,
79 + 'directory' => $directory
73 80 ];
74 81
75 82 try {
76 83 return \Depicter::json( AssetsAPIService::searchDocumentTemplates( $options ) );
@@ -86,11 +93,15 @@
86 93 }
87 94
88 95 public function getDocumentTemplateCategories( RequestInterface $request, $view )
89 96 {
90 - $category = !empty( $request->query('category') ) ? Sanitize::textfield( $request->query('category') ) : '';
97 + $category = !empty( $request->query('category') ) ? Sanitize::textfield( $request->query('category') ) : '';
98 + $directory = !empty( $request->query('directory') ) ? Sanitize::textfield( $request->query('directory') ) : 2;
91 99
92 - $options = [ 'category' => $category ];
100 + $options = [
101 + 'category' => $category,
102 + 'directory' => $directory
103 + ];
93 104
94 105 try {
95 106 return \Depicter::json( AssetsAPIService::getDocumentTemplateCategories( $options ) );
96 107 } catch ( \Exception $exception ) {
@@ -112,11 +123,18 @@
112 123 * @throws GuzzleException
113 124 */
114 125 public function importDocumentTemplate( RequestInterface $request, $view ) {
115 126 $templateID = !empty( $request->query('ID') ) ? Sanitize::textfield( $request->query('ID') ) : '';
127 + $endpointVersion = !empty( $request->query('v') ) ? Sanitize::int( $request->query('v') ) : 1;
128 + $directory = !empty( $request->query('directory') ) ? Sanitize::textfield( $request->query('directory') ) : 2;
129 +
116 130 try {
117 - $result = AssetsAPIService::getDocumentTemplateData( $templateID );
118 - if ( !empty( $result->hits ) ) {
131 + $result = AssetsAPIService::getDocumentTemplateData( $templateID, [ 'v' => $endpointVersion, 'directory' => $directory ] );
132 +
133 + if ( !empty( $result->errors ) ) {
134 + return Http::getErrorJson( $result->errors );
135 +
136 + } elseif ( !empty( $result->hits ) ) {
119 137 $editorData = JSON::encode( $result->hits );
120 138 $editorData = preg_replace( '/"activeBreakpoint":".+?"/', '"activeBreakpoint":"default"', $editorData );
121 139 $document = \Depicter::documentRepository()->create();
122 140
@@ -146,13 +164,8 @@
146 164 } catch ( \Exception $exception ) {
147 165
148 166 $error = Http::getErrorExceptionResponse( $exception );
149 167
150 - if( $error['group'] == 'RequestException' ){
151 - $error['message'] = __( 'Cannot reach the server for downloading images.', 'depicter' );
152 - $error['statusCode'] = 421;
153 - }
154 -
155 168 return \Depicter::json([
156 169 'errors' => $error
157 170 ])->withStatus( $error['statusCode'] );
158 171 }
@@ -166,10 +179,12 @@
166 179 * @throws GuzzleException
167 180 */
168 181 public function previewDocumentTemplate( RequestInterface $request, $view ) {
169 182 $templateID = !empty( $request->query('ID') ) ? Sanitize::textfield( $request->query('ID') ) : '';
183 + $directory = !empty( $request->query('directory') ) ? Sanitize::textfield( $request->query('directory') ) : 2;
184 +
170 185 try {
171 - $result = AssetsAPIService::previewDocumentTemplate( $templateID );
186 + $result = AssetsAPIService::previewDocumentTemplate( $templateID, $directory );
172 187 return \Depicter::output( $result );
173 188 } catch ( \Exception $exception ) {
174 189 $error = Http::getErrorExceptionResponse( $exception );
175 190
@@ -237,9 +252,15 @@
237 252 $options['elementType'] = Sanitize::textfield( $request->query('elementType') );
238 253 }
239 254
240 255 try {
241 - return \Depicter::json( AssetsAPIService::getAnimationsCategories( $options ) );
256 + $result = AssetsAPIService::getAnimationsCategories( $options );
257 +
258 + if ( !empty( $result['errors'] ) ) {
259 + return Http::getErrorJson( $result['errors'] );
260 + } else {
261 + return \Depicter::json( $result );
262 + }
242 263
243 264 } catch ( \Exception $exception ) {
244 265 $error = Http::getErrorExceptionResponse( $exception );
245 266