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\Modules\Html\Builder; |
11
|
|
|
use GeminiLabs\SiteReviews\Modules\Schema; |
12
|
|
|
use GeminiLabs\SiteReviews\Modules\Style; |
13
|
|
|
use GeminiLabs\SiteReviews\Modules\Validator\ValidateReview; |
14
|
|
|
|
15
|
|
|
class PublicController extends Controller |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* @return void |
19
|
|
|
* @action wp_enqueue_scripts |
20
|
|
|
*/ |
21
|
|
|
public function enqueueAssets() |
22
|
|
|
{ |
23
|
|
|
(new EnqueuePublicAssets)->handle(); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @param string $tag |
28
|
|
|
* @param string $handle |
29
|
|
|
* @return string |
30
|
|
|
* @filter script_loader_tag |
31
|
|
|
*/ |
32
|
|
|
public function filterEnqueuedScripts( $tag, $handle ) |
33
|
|
|
{ |
34
|
|
|
$scripts = [Application::ID.'/google-recaptcha']; |
35
|
|
|
if( in_array( $handle, apply_filters( 'site-reviews/async-scripts', $scripts ))) { |
36
|
|
|
$tag = str_replace( ' src=', ' async src=', $tag ); |
37
|
|
|
} |
38
|
|
|
if( in_array( $handle, apply_filters( 'site-reviews/defer-scripts', $scripts ))) { |
39
|
|
|
$tag = str_replace( ' src=', ' defer src=', $tag ); |
40
|
|
|
} |
41
|
|
|
return $tag; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @return array |
46
|
|
|
* @filter query_vars |
47
|
|
|
*/ |
48
|
|
|
public function filterQueryVars( array $vars ) |
49
|
|
|
{ |
50
|
|
|
$vars[] = Application::PAGED_QUERY_VAR; |
51
|
|
|
return $vars; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @param string $view |
56
|
|
|
* @return string |
57
|
|
|
* @filter site-reviews/render/view |
58
|
|
|
*/ |
59
|
7 |
|
public function filterRenderView( $view ) |
60
|
|
|
{ |
61
|
7 |
|
return glsr( Style::class )->filterView( $view ); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @return void |
66
|
|
|
* @action site-reviews/builder |
67
|
|
|
*/ |
68
|
|
|
public function modifyBuilder( Builder $instance ) |
69
|
|
|
{ |
70
|
|
|
call_user_func_array( [glsr( Style::class ), 'modifyField'], [&$instance] ); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @return void |
75
|
|
|
* @action wp_footer |
76
|
|
|
*/ |
77
|
|
|
public function renderSchema() |
78
|
|
|
{ |
79
|
|
|
glsr( Schema::class )->render(); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @return mixed |
84
|
|
|
*/ |
85
|
1 |
|
public function routerSubmitReview( array $request ) |
86
|
|
|
{ |
87
|
1 |
|
$validated = glsr( ValidateReview::class )->validate( $request ); |
88
|
1 |
|
if( !empty( $validated->error ) || $validated->recaptchaIsUnset )return; |
89
|
1 |
|
$this->execute( new CreateReview( $validated->request )); |
90
|
1 |
|
} |
91
|
|
|
} |
92
|
|
|
|