1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace GeminiLabs\SiteReviews\Modules; |
4
|
|
|
|
5
|
|
|
use GeminiLabs\SiteReviews\Contracts\MultilingualContract as Contract; |
6
|
|
|
use GeminiLabs\SiteReviews\Database\OptionManager; |
7
|
|
|
|
8
|
|
|
class Multilingual implements Contract |
9
|
|
|
{ |
10
|
|
|
protected $integration; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* @param string $integration |
14
|
|
|
* @return false|\GeminiLabs\SiteReviews\Modules\Multilingual\Polylang|\GeminiLabs\SiteReviews\Modules\Multilingual\Wpml |
15
|
|
|
*/ |
16
|
|
|
public function getIntegration($integration = '') |
17
|
|
|
{ |
18
|
|
|
if (empty($integration)) { |
19
|
|
|
$integration = ucfirst(glsr(OptionManager::class)->get('settings.general.multilingual')); |
20
|
|
|
} |
21
|
|
|
$integrationClass = 'GeminiLabs\SiteReviews\Modules\Multilingual\\'.$integration; |
22
|
|
|
if (class_exists($integrationClass)) { |
23
|
|
|
return glsr($integrationClass); |
|
|
|
|
24
|
|
|
} |
25
|
|
|
return false; |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* {@inheritdoc} |
30
|
|
|
*/ |
31
|
|
|
public function getPost($postId) |
32
|
|
|
{ |
33
|
|
|
return $this->isIntegrated() |
34
|
|
|
? $this->integration->getPostIds($postId) |
35
|
|
|
: $postId; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* {@inheritdoc} |
40
|
|
|
*/ |
41
|
|
|
public function getPostIds(array $postIds) |
42
|
|
|
{ |
43
|
|
|
return $this->isIntegrated() |
44
|
|
|
? $this->integration->getPostIds($postIds) |
45
|
|
|
: $postIds; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* {@inheritdoc} |
50
|
|
|
*/ |
51
|
|
|
public function isActive() |
52
|
|
|
{ |
53
|
|
|
return $this->isIntegrated() |
54
|
|
|
? $this->integration->isActive() |
55
|
|
|
: false; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* {@inheritdoc} |
60
|
|
|
*/ |
61
|
|
|
public function isEnabled() |
62
|
|
|
{ |
63
|
|
|
return $this->isIntegrated() |
64
|
|
|
? $this->integration->isEnabled() |
65
|
|
|
: false; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* {@inheritdoc} |
70
|
|
|
*/ |
71
|
|
|
public function isSupported() |
72
|
|
|
{ |
73
|
|
|
return $this->isIntegrated() |
74
|
|
|
? $this->integration->isSupported() |
75
|
|
|
: false; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* return bool |
80
|
|
|
*/ |
81
|
|
|
protected function isIntegrated() |
82
|
|
|
{ |
83
|
|
|
if (!empty($this->integration)) { |
84
|
|
|
return true; |
85
|
|
|
} |
86
|
|
|
if ($integration = $this->getIntegration()) { |
87
|
|
|
$this->integration = $integration; |
88
|
|
|
return true; |
89
|
|
|
} |
90
|
|
|
glsr_log()->error($integrationClass.' does not exist'); |
|
|
|
|
91
|
|
|
return false; |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|