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
|
|
|
return $handle == Application::ID.'/google-recaptcha' |
35
|
|
|
&& glsr( OptionManager::class )->get( 'settings.submissions.recaptcha.integration' ) == 'custom' |
36
|
|
|
? str_replace( ' src=', ' async defer src=', $tag ) |
37
|
|
|
: $tag; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @return array |
42
|
|
|
* @filter query_vars |
43
|
|
|
*/ |
44
|
|
|
public function filterQueryVars( array $vars ) |
45
|
|
|
{ |
46
|
|
|
$vars[] = Application::PAGED_QUERY_VAR; |
47
|
|
|
return $vars; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @param string $view |
52
|
|
|
* @return string |
53
|
|
|
* @filter site-reviews/render/view |
54
|
|
|
*/ |
55
|
7 |
|
public function filterRenderView( $view ) |
56
|
|
|
{ |
57
|
7 |
|
return glsr( Style::class )->filterView( $view ); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @return void |
62
|
|
|
* @action site-reviews/builder |
63
|
|
|
*/ |
64
|
|
|
public function modifyBuilder( Builder $instance ) |
65
|
|
|
{ |
66
|
|
|
call_user_func_array( [glsr( Style::class ), 'modifyField'], [&$instance] ); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @return void |
71
|
|
|
* @action wp_footer |
72
|
|
|
*/ |
73
|
|
|
public function renderSchema() |
74
|
|
|
{ |
75
|
|
|
glsr( Schema::class )->render(); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @return mixed |
80
|
|
|
*/ |
81
|
1 |
|
public function routerSubmitReview( array $request ) |
82
|
|
|
{ |
83
|
1 |
|
$validated = glsr( ValidateReview::class )->validate( $request ); |
84
|
1 |
|
if( !empty( $validated->error ) || $validated->recaptchaIsUnset )return; |
85
|
1 |
|
$this->execute( new CreateReview( $validated->request )); |
86
|
1 |
|
} |
87
|
|
|
} |
88
|
|
|
|