nystudio107 /
craft-disqus
| 1 | <?php |
||
| 2 | /** |
||
| 3 | * Disqus plugin for Craft CMS 3.x |
||
| 4 | * |
||
| 5 | * Integrates the Disqus commenting system into Craft 3 websites, including |
||
| 6 | * Single Sign On (SSO) and custom login/logout URLs |
||
| 7 | * |
||
| 8 | * @link https://nystudio107.com |
||
|
0 ignored issues
–
show
Coding Style
introduced
by
Loading history...
|
|||
| 9 | * @copyright Copyright (c) 2017 nystudio107 |
||
|
0 ignored issues
–
show
|
|||
| 10 | */ |
||
|
0 ignored issues
–
show
|
|||
| 11 | |||
| 12 | namespace nystudio107\disqus\models; |
||
| 13 | |||
| 14 | use craft\base\Model; |
||
| 15 | use craft\behaviors\EnvAttributeParserBehavior; |
||
| 16 | use craft\helpers\App; |
||
| 17 | use yii\behaviors\AttributeTypecastBehavior; |
||
| 18 | |||
| 19 | /** |
||
|
0 ignored issues
–
show
|
|||
| 20 | * @author nystudio107 |
||
|
0 ignored issues
–
show
Content of the @author tag must be in the form "Display Name <[email protected]>"
Loading history...
|
|||
| 21 | * @package Disqus |
||
|
0 ignored issues
–
show
|
|||
| 22 | * @since 1.0.0 |
||
|
0 ignored issues
–
show
|
|||
| 23 | */ |
||
|
0 ignored issues
–
show
|
|||
| 24 | class Settings extends Model |
||
| 25 | { |
||
| 26 | // Public Properties |
||
| 27 | // ========================================================================= |
||
| 28 | |||
| 29 | /** |
||
|
0 ignored issues
–
show
|
|||
| 30 | * @var bool |
||
| 31 | */ |
||
| 32 | public bool $lazyLoadDisqus = true; |
||
| 33 | |||
| 34 | /** |
||
|
0 ignored issues
–
show
|
|||
| 35 | * @var string |
||
| 36 | */ |
||
| 37 | public string $disqusShortname = ''; |
||
| 38 | |||
| 39 | /** |
||
|
0 ignored issues
–
show
|
|||
| 40 | * @var bool |
||
| 41 | */ |
||
| 42 | public bool $useSSO = false; |
||
| 43 | |||
| 44 | /** |
||
|
0 ignored issues
–
show
|
|||
| 45 | * @var string |
||
| 46 | */ |
||
| 47 | public string $disqusPublicKey = ''; |
||
| 48 | |||
| 49 | /** |
||
|
0 ignored issues
–
show
|
|||
| 50 | * @var string |
||
| 51 | */ |
||
| 52 | public string $disqusSecretKey = ''; |
||
| 53 | |||
| 54 | /** |
||
|
0 ignored issues
–
show
|
|||
| 55 | * @var bool |
||
| 56 | */ |
||
| 57 | public bool $customLogin = false; |
||
| 58 | |||
| 59 | /** |
||
|
0 ignored issues
–
show
|
|||
| 60 | * @var string |
||
| 61 | */ |
||
| 62 | public string $loginName = ''; |
||
| 63 | |||
| 64 | /** |
||
|
0 ignored issues
–
show
|
|||
| 65 | * @var string |
||
| 66 | */ |
||
| 67 | public string $loginButton = ''; |
||
| 68 | |||
| 69 | /** |
||
|
0 ignored issues
–
show
|
|||
| 70 | * @var string |
||
| 71 | */ |
||
| 72 | public string $loginIcon = ''; |
||
| 73 | |||
| 74 | /** |
||
|
0 ignored issues
–
show
|
|||
| 75 | * @var string |
||
| 76 | */ |
||
| 77 | public string $loginUrl = ''; |
||
| 78 | |||
| 79 | /** |
||
|
0 ignored issues
–
show
|
|||
| 80 | * @var string |
||
| 81 | */ |
||
| 82 | public string $loginLogoutUrl = ''; |
||
| 83 | |||
| 84 | /** |
||
|
0 ignored issues
–
show
|
|||
| 85 | * @var int |
||
| 86 | */ |
||
| 87 | public int $loginWidth = 800; |
||
| 88 | |||
| 89 | /** |
||
|
0 ignored issues
–
show
|
|||
| 90 | * @var int |
||
| 91 | */ |
||
| 92 | public int $loginHeight = 400; |
||
| 93 | |||
| 94 | // Public Methods |
||
| 95 | // ========================================================================= |
||
| 96 | |||
| 97 | /** |
||
|
0 ignored issues
–
show
|
|||
| 98 | * @return string the parsed secret key (e.g. 'XXXXXXXXXXX') |
||
| 99 | */ |
||
| 100 | public function getDisqusSecretKey(): string |
||
| 101 | { |
||
| 102 | return App::parseEnv($this->disqusSecretKey); |
||
|
0 ignored issues
–
show
|
|||
| 103 | } |
||
| 104 | |||
| 105 | /** |
||
|
0 ignored issues
–
show
|
|||
| 106 | * @return string the parsed public key (e.g. 'XXXXXXXXXXX') |
||
| 107 | */ |
||
| 108 | public function getDisqusPublicKey(): string |
||
| 109 | { |
||
| 110 | return App::parseEnv($this->disqusPublicKey); |
||
|
0 ignored issues
–
show
|
|||
| 111 | } |
||
| 112 | |||
| 113 | /** |
||
|
0 ignored issues
–
show
|
|||
| 114 | * @return string |
||
| 115 | */ |
||
| 116 | public function getDisqusShortname(): string |
||
| 117 | { |
||
| 118 | return $this->disqusShortname; |
||
| 119 | } |
||
| 120 | |||
| 121 | /** |
||
|
0 ignored issues
–
show
|
|||
| 122 | * @return bool |
||
| 123 | */ |
||
| 124 | public function getUseSSO(): bool |
||
| 125 | { |
||
| 126 | return $this->useSSO; |
||
| 127 | } |
||
| 128 | |||
| 129 | /** |
||
|
0 ignored issues
–
show
|
|||
| 130 | * @return bool |
||
| 131 | */ |
||
| 132 | public function getCustomLogin(): bool |
||
| 133 | { |
||
| 134 | return $this->customLogin; |
||
| 135 | } |
||
| 136 | |||
| 137 | /** |
||
|
0 ignored issues
–
show
|
|||
| 138 | * @return string |
||
| 139 | */ |
||
| 140 | public function getLoginName(): string |
||
| 141 | { |
||
| 142 | return App::parseEnv($this->loginName); |
||
|
0 ignored issues
–
show
|
|||
| 143 | } |
||
| 144 | |||
| 145 | /** |
||
|
0 ignored issues
–
show
|
|||
| 146 | * @return string |
||
| 147 | */ |
||
| 148 | public function getLoginButton(): string |
||
| 149 | { |
||
| 150 | return App::parseEnv($this->loginButton); |
||
|
0 ignored issues
–
show
|
|||
| 151 | } |
||
| 152 | |||
| 153 | /** |
||
|
0 ignored issues
–
show
|
|||
| 154 | * @return string |
||
| 155 | */ |
||
| 156 | public function getLoginIcon(): string |
||
| 157 | { |
||
| 158 | return App::parseEnv($this->loginIcon); |
||
|
0 ignored issues
–
show
|
|||
| 159 | } |
||
| 160 | |||
| 161 | /** |
||
|
0 ignored issues
–
show
|
|||
| 162 | * @return string |
||
| 163 | */ |
||
| 164 | public function getLoginUrl(): string |
||
| 165 | { |
||
| 166 | return App::parseEnv($this->loginUrl); |
||
|
0 ignored issues
–
show
|
|||
| 167 | } |
||
| 168 | |||
| 169 | /** |
||
|
0 ignored issues
–
show
|
|||
| 170 | * @return string |
||
| 171 | */ |
||
| 172 | public function getLoginLogoutUrl(): string |
||
| 173 | { |
||
| 174 | return App::parseEnv($this->loginLogoutUrl); |
||
|
0 ignored issues
–
show
|
|||
| 175 | } |
||
| 176 | |||
| 177 | /** |
||
|
0 ignored issues
–
show
|
|||
| 178 | * @return int |
||
| 179 | */ |
||
| 180 | public function getLoginWidth(): int |
||
| 181 | { |
||
| 182 | return $this->loginWidth; |
||
| 183 | } |
||
| 184 | |||
| 185 | /** |
||
|
0 ignored issues
–
show
|
|||
| 186 | * @return int |
||
| 187 | */ |
||
| 188 | public function getLoginHeight(): int |
||
| 189 | { |
||
| 190 | return $this->loginHeight; |
||
| 191 | } |
||
| 192 | |||
| 193 | /** |
||
|
0 ignored issues
–
show
|
|||
| 194 | * @inheritdoc |
||
| 195 | */ |
||
|
0 ignored issues
–
show
|
|||
| 196 | public function rules(): array |
||
| 197 | { |
||
| 198 | return [ |
||
| 199 | ['lazyLoadDisqus', 'boolean'], |
||
| 200 | ['lazyLoadDisqus', 'default', 'value' => false], |
||
| 201 | ['disqusShortname', 'string'], |
||
| 202 | ['disqusShortname', 'default', 'value' => ''], |
||
| 203 | ['useSSO', 'boolean'], |
||
| 204 | ['useSSO', 'default', 'value' => false], |
||
| 205 | ['disqusPublicKey', 'string'], |
||
| 206 | ['disqusPublicKey', 'default', 'value' => ''], |
||
| 207 | ['disqusSecretKey', 'string'], |
||
| 208 | ['disqusSecretKey', 'default', 'value' => ''], |
||
| 209 | ['customLogin', 'boolean'], |
||
| 210 | ['customLogin', 'default', 'value' => false], |
||
| 211 | ['loginName', 'string'], |
||
| 212 | ['loginName', 'default', 'value' => ''], |
||
| 213 | ['loginButton', 'string'], |
||
| 214 | ['loginButton', 'default', 'value' => ''], |
||
| 215 | ['loginIcon', 'string'], |
||
| 216 | ['loginIcon', 'default', 'value' => ''], |
||
| 217 | ['loginUrl', 'string'], |
||
| 218 | ['loginUrl', 'default', 'value' => ''], |
||
| 219 | ['loginLogoutUrl', 'string'], |
||
| 220 | ['loginLogoutUrl', 'default', 'value' => ''], |
||
| 221 | ['loginWidth', 'integer', 'min' => 400, 'max' => 2000], |
||
| 222 | ['loginWidth', 'default', 'value' => 800], |
||
| 223 | ['loginHeight', 'integer', 'min' => 200, 'max' => 1000], |
||
| 224 | ['loginHeight', 'default', 'value' => 400], |
||
| 225 | ]; |
||
| 226 | } |
||
| 227 | |||
| 228 | /** |
||
|
0 ignored issues
–
show
|
|||
| 229 | * @return array |
||
| 230 | */ |
||
| 231 | public function behaviors(): array |
||
| 232 | { |
||
| 233 | return [ |
||
| 234 | 'parser' => [ |
||
| 235 | 'class' => EnvAttributeParserBehavior::class, |
||
| 236 | 'attributes' => [ |
||
| 237 | 'loginName', |
||
| 238 | 'loginButton', |
||
| 239 | 'loginIcon', |
||
| 240 | 'loginUrl', |
||
| 241 | 'loginLogoutUrl', |
||
| 242 | 'disqusPublicKey', |
||
| 243 | 'disqusSecretKey', |
||
| 244 | ], |
||
| 245 | ], |
||
| 246 | 'typecast' => [ |
||
| 247 | 'class' => AttributeTypecastBehavior::class, |
||
| 248 | // 'attributeTypes' will be composed automatically according to `rules()` |
||
| 249 | ], |
||
| 250 | ]; |
||
| 251 | } |
||
| 252 | } |
||
| 253 |