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 / PostsAjaxController.php

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

117 lines 3.9 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 Averta\Core\Utility\Data;
5 use Averta\WordPress\Utility\JSON;
6 use Depicter\Utility\Sanitize;
7 use Psr\Http\Message\ResponseInterface;
8 use WPEmerge\Requests\RequestInterface;
9
10 class PostsAjaxController
11 {
12 /**
13 * list available post types with their taxonomies
14 * @param RequestInterface $request
15 * @param $view
16 *
17 * @return ResponseInterface
18 */
19 public function getPostTypes( RequestInterface $request, $view ) {
20 $postType = !empty( $request->query('postType') ) ? Sanitize::textfield( $request->query('postType') ) : 'all';
21 $result = \Depicter::dataSource()->posts()->getTypes( $postType );
22
23 return \Depicter::json([
24 'hits' => $result
25 ])->withStatus(200);
26 }
27
28 /**
29 * List available posts for custom post type
30 * @param RequestInterface $request
31 * @param $view
32 *
33 * @return ResponseInterface
34 */
35 public function getPosts( RequestInterface $request, $view ) {
36 $args = [];
37
38 if( !Data::isNullOrEmptyStr( $request->body('postType') ) ){
39 $args['postType'] = Sanitize::textfield( $request->body('postType') );
40 }
41 if( !Data::isNullOrEmptyStr( $request->body('perpage') ) ){
42 $args['perpage'] = Sanitize::int( $request->body('perpage') );
43 }
44 if( !Data::isNullOrEmptyStr( $request->body('excerptLength') ) ){
45 $args['excerptLength'] = Sanitize::int( $request->body('excerptLength') );
46 }
47 if( !Data::isNullOrEmptyStr( $request->body('offset') ) ){
48 $args['offset'] = Sanitize::int( $request->body('offset') );
49 }
50 if( !Data::isNullOrEmptyStr( $request->body('linkSlides') ) ){
51 $args['linkSlides'] = Sanitize::textfield( $request->body('linkSlides') );
52 }
53 if( !Data::isNullOrEmptyStr( $request->body('orderBy') ) ){
54 $args['orderBy'] = Sanitize::textfield( $request->body('orderBy') );
55 }
56 if( !Data::isNullOrEmptyStr( $request->body('order') ) ){
57 $args['order'] = Sanitize::textfield( $request->body('order') );
58 }
59 if( !Data::isNullOrEmptyStr( $request->body('imageSource') ) ){
60 $args['imageSource'] = Sanitize::textfield( $request->body('imageSource') );
61 }
62 if( !Data::isNullOrEmptyStr( $request->body('excludedIds') ) ){
63 $args['excludedIds'] = JSON::decode( $request->body('excludedIds') );
64 ; }
65 if( !Data::isNullOrEmptyStr( $request->body('includedIds') ) ){
66 $args['includedIds'] = JSON::decode( $request->body('includedIds') );
67 }
68 if( !Data::isNullOrEmptyStr( $request->body('excludeNonThumbnail') ) ){
69 $args['excludeNonThumbnail'] = Sanitize::textfield( $request->body('excludeNonThumbnail') );
70 }
71 if( !Data::isNullOrEmptyStr( $request->body('taxonomies') ) ){
72 $args['taxonomies'] = Sanitize::textfield( $request->body('taxonomies') );
73 }
74
75 $posts = \Depicter::dataSource()->posts()->previewRecords( $args );
76
77 return \Depicter::json([
78 'hits' => $posts
79 ])->withStatus(200);
80 }
81
82 /**
83 * Search posts
84 * @param RequestInterface $request
85 * @param $view
86 *
87 * @return ResponseInterface
88 */
89 public function searchPosts( RequestInterface $request, $view ) {
90 $args = [];
91
92 if( !Data::isNullOrEmptyStr( $request->body('postType') ) ){
93 $args['postType'] = Sanitize::textfield( $request->body('postType') );
94 }
95 if( !Data::isNullOrEmptyStr( $request->body('perpage') ) ){
96 $args['perpage'] = Sanitize::int( $request->body('perpage') );
97 } else {
98 $args['perpage'] = 20;
99 }
100 if( !Data::isNullOrEmptyStr( $request->body('page') ) ){
101 $args['page'] = Sanitize::int( $request->body('page') );
102 }
103 if( !Data::isNullOrEmptyStr( $request->body('s') ) ){
104 $args['s'] = Sanitize::textfield( $request->body('s') );
105 }
106 if( !Data::isNullOrEmptyStr( $request->body('excludedIds') ) ){
107 $args['excludedIds'] = JSON::decode( $request->body('excludedIds') );
108 }
109
110 $posts = \Depicter::dataSource()->posts()->searchRecordsByTitle( $args );
111
112 return \Depicter::json([
113 'hits' => $posts
114 ])->withStatus(200);
115 }
116 }
117