1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace GeminiLabs\SiteReviews\Integrations\Flatsome; |
4
|
|
|
|
5
|
|
|
use GeminiLabs\SiteReviews\Controllers\AbstractController; |
6
|
|
|
use GeminiLabs\SiteReviews\Database; |
7
|
|
|
|
8
|
|
|
class Controller extends AbstractController |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* @action ux_builder_enqueue_scripts |
12
|
|
|
*/ |
13
|
|
|
public function printInlineScripts(string $page = ''): void |
14
|
|
|
{ |
15
|
|
|
if ('editor' !== $page) { |
16
|
|
|
return; |
17
|
|
|
} |
18
|
|
|
$script = 'var glsr_ux_builder=t=>{if(t.tag.startsWith("ux_site_review")){var r=t.$scope.$ctrl.targets.$iframe().get(0);let e=r.contentWindow||r;e.GLSR.Event.trigger("site-reviews/init"),t.$element.find(":input,a").attr("tabindex",-1).css({"pointer-events":"none"})}};UxBuilder.on("shortcode-attached",glsr_ux_builder),UxBuilder.on("shortcode-content-change",glsr_ux_builder);'; |
19
|
|
|
wp_add_inline_script('ux-builder-core', $script); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @action ux_builder_enqueue_scripts |
24
|
|
|
*/ |
25
|
|
|
public function printInlineStyles(string $page = ''): void |
26
|
|
|
{ |
27
|
|
|
if ('editor' !== $page) { |
28
|
|
|
return; |
29
|
|
|
} |
30
|
|
|
$css = ''; |
31
|
|
|
$css .= '.add-shortcode-items ul .add-shortcode-box .add-shortcode-box-button:has(img[src*="site-reviews/assets/images/icons/flatsome"]){display:flex;flex-wrap:wrap;justify-content:center;}'; |
32
|
|
|
$css .= '.add-shortcode-items ul .add-shortcode-box img[src*="site-reviews/assets/images/icons/flatsome"]{height:36px;margin-top:13px;}'; |
33
|
|
|
wp_add_inline_style('ux-builder-core', $css); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @action init |
38
|
|
|
*/ |
39
|
|
|
public function registerShortcodes(): void |
40
|
|
|
{ |
41
|
|
|
glsr(FlatsomeSiteReview::class)->register(); |
42
|
|
|
glsr(FlatsomeSiteReviews::class)->register(); |
43
|
|
|
glsr(FlatsomeSiteReviewsForm::class)->register(); |
44
|
|
|
glsr(FlatsomeSiteReviewsSummary::class)->register(); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @action wp_ajax_ux_builder_search_posts:1 |
49
|
|
|
*/ |
50
|
|
|
public function searchAssignedPosts(): void |
51
|
|
|
{ |
52
|
|
|
if ('assigned_posts_query' !== filter_input(INPUT_GET, 'option')) { |
53
|
|
|
return; |
54
|
|
|
} |
55
|
|
|
$postId = (string) filter_input(INPUT_GET, 'id'); |
56
|
|
|
check_ajax_referer("ux-builder-{$postId}", 'security'); |
57
|
|
|
$query = sanitize_text_field((string) filter_input(INPUT_GET, 'query')); |
58
|
|
|
$posts = glsr(Database::class)->posts([ |
59
|
|
|
'numberposts' => 25, |
60
|
|
|
's' => $query, |
61
|
|
|
]); |
62
|
|
|
$callback = fn ($id, $title) => compact('id', 'title'); |
63
|
|
|
$items = array_map($callback, array_keys($posts), array_values($posts)); |
64
|
|
|
array_unshift($items, |
65
|
|
|
[ |
66
|
|
|
'id' => 'post_id', |
67
|
|
|
'title' => _x('The Current Page', 'admin-text', 'site-reviews'), |
68
|
|
|
], |
69
|
|
|
[ |
70
|
|
|
'id' => 'parent_id', |
71
|
|
|
'title' => _x('The Parent Page', 'admin-text', 'site-reviews'), |
72
|
|
|
] |
73
|
|
|
); |
74
|
|
|
wp_send_json_success($items); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @action wp_ajax_ux_builder_search_posts:2 |
79
|
|
|
*/ |
80
|
|
|
public function searchAssignedUsers(): void |
81
|
|
|
{ |
82
|
|
|
if ('assigned_users_query' !== filter_input(INPUT_GET, 'option')) { |
83
|
|
|
return; |
84
|
|
|
} |
85
|
|
|
$postId = (string) filter_input(INPUT_GET, 'id'); |
86
|
|
|
check_ajax_referer("ux-builder-{$postId}", 'security'); |
87
|
|
|
$query = sanitize_text_field((string) filter_input(INPUT_GET, 'query')); |
88
|
|
|
$users = glsr(Database::class)->users([ |
89
|
|
|
'number' => 25, |
90
|
|
|
'search' => $query, |
91
|
|
|
]); |
92
|
|
|
$callback = fn ($id, $title) => compact('id', 'title'); |
93
|
|
|
$items = array_map($callback, array_keys($users), array_values($users)); |
94
|
|
|
array_unshift($items, |
95
|
|
|
[ |
96
|
|
|
'id' => 'user_id', |
97
|
|
|
'title' => _x('The Logged-in user', 'admin-text', 'site-reviews'), |
98
|
|
|
], |
99
|
|
|
[ |
100
|
|
|
'id' => 'author_id', |
101
|
|
|
'title' => _x('The Page author', 'admin-text', 'site-reviews'), |
102
|
|
|
], |
103
|
|
|
[ |
104
|
|
|
'id' => 'profile_id', |
105
|
|
|
'title' => _x('The Profile user (BuddyPress/Ultimate Member)', 'admin-text', 'site-reviews'), |
106
|
|
|
] |
107
|
|
|
); |
108
|
|
|
wp_send_json_success($items); |
109
|
|
|
} |
110
|
|
|
} |
111
|
|
|
|