|
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\Validator\ValidateReview; |
|
11
|
|
|
|
|
12
|
|
|
class PublicController extends Controller |
|
13
|
|
|
{ |
|
14
|
|
|
/** |
|
15
|
|
|
* @return void |
|
16
|
|
|
* @action wp_enqueue_scripts |
|
17
|
|
|
*/ |
|
18
|
|
|
public function enqueueAssets() |
|
19
|
|
|
{ |
|
20
|
|
|
(new EnqueuePublicAssets)->handle(); |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @return string |
|
25
|
|
|
* @filter script_loader_tag |
|
26
|
|
|
*/ |
|
27
|
|
|
public function filterEnqueuedScripts( $tag, $handle ) |
|
28
|
|
|
{ |
|
29
|
|
|
return $handle == Application::ID.'/google-recaptcha' |
|
30
|
|
|
&& glsr( OptionManager::class )->get( 'settings.submissions.recaptcha.integration' ) == 'custom' |
|
31
|
|
|
? str_replace( ' src=', ' async defer src=', $tag ) |
|
32
|
|
|
: $tag; |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Add a variable to query_vars for custom pagination |
|
37
|
|
|
* @param array $vars |
|
38
|
|
|
* @return array |
|
39
|
|
|
* @filter query_vars |
|
40
|
|
|
* @todo remove need for dirty hack |
|
41
|
|
|
*/ |
|
42
|
|
|
public function filterQueryVars( $vars ) |
|
43
|
|
|
{ |
|
44
|
|
|
$vars[] = Application::PAGED_QUERY_VAR; |
|
45
|
|
|
// dirty hack to fix a form submission with a field that has "name" as name |
|
46
|
|
|
if( filter_input( INPUT_POST, 'action' ) == 'submit-review' |
|
47
|
|
|
&& !is_null( filter_input( INPUT_POST, 'gotcha' ))) { |
|
48
|
|
|
$index = array_search( 'name', $vars, true ); |
|
49
|
|
|
if( false !== $index ) { |
|
50
|
|
|
unset( $vars[$index] ); |
|
51
|
|
|
} |
|
52
|
|
|
} |
|
53
|
|
|
return $vars; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* @return mixed |
|
58
|
|
|
*/ |
|
59
|
|
|
public function routerCreateReview( array $request ) |
|
60
|
|
|
{ |
|
61
|
|
|
$validated = glsr( ValidateReview::class )->validate( $request ); |
|
62
|
|
|
if( !empty( $validated->error )) { |
|
63
|
|
|
return $validated->request; |
|
64
|
|
|
} |
|
65
|
|
|
if( $validated->recaptchaIsUnset )return; |
|
66
|
|
|
return $this->execute( new CreateReview( $validated->request )); |
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
|