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
depicter / app / src / Controllers / Ajax / PostsAjaxController.php

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

122 lines 4.0 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 // check if request is for handpicked data or not
76 if ( !Data::isNullOrEmptyStr( $request->body('handpicked') ) ) {
77 $args['orderBy'] = 'post__in';
78 }
79
80 $posts = \Depicter::dataSource()->posts()->previewRecords( $args );
81
82 return \Depicter::json([
83 'hits' => $posts
84 ])->withStatus(200);
85 }
86
87 /**
88 * Search posts
89 * @param RequestInterface $request
90 * @param $view
91 *
92 * @return ResponseInterface
93 */
94 public function searchPosts( RequestInterface $request, $view ) {
95 $args = [];
96
97 if( !Data::isNullOrEmptyStr( $request->body('postType') ) ){
98 $args['postType'] = Sanitize::textfield( $request->body('postType') );
99 }
100 if( !Data::isNullOrEmptyStr( $request->body('perpage') ) ){
101 $args['perpage'] = Sanitize::int( $request->body('perpage') );
102 } else {
103 $args['perpage'] = 20;
104 }
105 if( !Data::isNullOrEmptyStr( $request->body('page') ) ){
106 $args['page'] = Sanitize::int( $request->body('page') );
107 }
108 if( !Data::isNullOrEmptyStr( $request->body('s') ) ){
109 $args['s'] = Sanitize::textfield( $request->body('s') );
110 }
111 if( !Data::isNullOrEmptyStr( $request->body('excludedIds') ) ){
112 $args['excludedIds'] = JSON::decode( $request->body('excludedIds') );
113 }
114
115 $posts = \Depicter::dataSource()->posts()->searchRecordsByTitle( $args );
116
117 return \Depicter::json([
118 'hits' => $posts
119 ])->withStatus(200);
120 }
121 }
122