|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace GeminiLabs\SiteReviews\Controllers; |
|
4
|
|
|
|
|
5
|
|
|
use GeminiLabs\SiteReviews\Application; |
|
6
|
|
|
use GeminiLabs\SiteReviews\Commands\CreateReview; |
|
7
|
|
|
use GeminiLabs\SiteReviews\Controllers\Controller; |
|
8
|
|
|
use GeminiLabs\SiteReviews\Database\OptionManager; |
|
9
|
|
|
use GeminiLabs\SiteReviews\Handlers\EnqueuePublicAssets; |
|
10
|
|
|
use GeminiLabs\SiteReviews\Helper; |
|
11
|
|
|
use GeminiLabs\SiteReviews\Modules\Html\Builder; |
|
12
|
|
|
use GeminiLabs\SiteReviews\Modules\Schema; |
|
13
|
|
|
use GeminiLabs\SiteReviews\Modules\Style; |
|
14
|
|
|
use GeminiLabs\SiteReviews\Modules\Validator\ValidateReview; |
|
15
|
|
|
|
|
16
|
|
|
class PublicController extends Controller |
|
17
|
|
|
{ |
|
18
|
|
|
/** |
|
19
|
|
|
* @return void |
|
20
|
|
|
* @action wp_enqueue_scripts |
|
21
|
|
|
*/ |
|
22
|
|
|
public function enqueueAssets() |
|
23
|
|
|
{ |
|
24
|
|
|
(new EnqueuePublicAssets)->handle(); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @param string $tag |
|
29
|
|
|
* @param string $handle |
|
30
|
|
|
* @return string |
|
31
|
|
|
* @filter script_loader_tag |
|
32
|
|
|
*/ |
|
33
|
|
|
public function filterEnqueuedScripts( $tag, $handle ) |
|
34
|
|
|
{ |
|
35
|
|
|
$scripts = [Application::ID.'/google-recaptcha']; |
|
36
|
|
|
if( in_array( $handle, apply_filters( 'site-reviews/async-scripts', $scripts ))) { |
|
37
|
|
|
$tag = str_replace( ' src=', ' async src=', $tag ); |
|
38
|
|
|
} |
|
39
|
|
|
if( in_array( $handle, apply_filters( 'site-reviews/defer-scripts', $scripts ))) { |
|
40
|
|
|
$tag = str_replace( ' src=', ' defer src=', $tag ); |
|
41
|
|
|
} |
|
42
|
|
|
return $tag; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @return array |
|
48
|
|
|
* @filter site-reviews/config/forms/submission-form |
|
49
|
|
|
*/ |
|
50
|
|
|
public function filterFieldOrder( array $config ) |
|
51
|
|
|
{ |
|
52
|
|
|
$order = (array)apply_filters( 'site-reviews/submission-form/order', array_keys( $config )); |
|
53
|
|
|
return array_intersect_key( array_merge( array_flip( $order ), $config ), $config ); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* @param array $vars |
|
58
|
|
|
* @return array |
|
59
|
|
|
* @filter query_vars |
|
60
|
|
|
*/ |
|
61
|
|
|
public function filterQueryVars( $vars ) |
|
62
|
|
|
{ |
|
63
|
|
|
$vars = glsr( Helper::class )->consolidateArray( $vars ); |
|
64
|
|
|
$vars[] = glsr()->constant( 'PAGED_QUERY_VAR' ); |
|
65
|
|
|
return $vars; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* @param string $view |
|
70
|
|
|
* @return string |
|
71
|
|
|
* @filter site-reviews/render/view |
|
72
|
|
|
*/ |
|
73
|
7 |
|
public function filterRenderView( $view ) |
|
74
|
|
|
{ |
|
75
|
7 |
|
return glsr( Style::class )->filterView( $view ); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* @return void |
|
80
|
|
|
* @action site-reviews/builder |
|
81
|
|
|
*/ |
|
82
|
|
|
public function modifyBuilder( Builder $instance ) |
|
83
|
|
|
{ |
|
84
|
|
|
call_user_func_array( [glsr( Style::class ), 'modifyField'], [&$instance] ); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* @return void |
|
89
|
|
|
* @action wp_footer |
|
90
|
|
|
*/ |
|
91
|
|
|
public function renderSchema() |
|
92
|
|
|
{ |
|
93
|
|
|
glsr( Schema::class )->render(); |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
/** |
|
97
|
|
|
* @return CreateReview |
|
98
|
|
|
*/ |
|
99
|
1 |
|
public function routerSubmitReview( array $request ) |
|
100
|
|
|
{ |
|
101
|
1 |
|
$validated = glsr( ValidateReview::class )->validate( $request ); |
|
102
|
1 |
|
$command = new CreateReview( $validated->request ); |
|
103
|
1 |
|
if( empty( $validated->error ) && !$validated->recaptchaIsUnset ) { |
|
104
|
1 |
|
$this->execute( $command ); |
|
105
|
|
|
} |
|
106
|
1 |
|
return $command; |
|
107
|
|
|
} |
|
108
|
|
|
} |
|
109
|
|
|
|