|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* SEOmatic plugin for Craft CMS 3.x |
|
4
|
|
|
* |
|
5
|
|
|
* A turnkey SEO implementation for Craft CMS that is comprehensive, powerful, |
|
6
|
|
|
* and flexible |
|
7
|
|
|
* |
|
8
|
|
|
* @link https://nystudio107.com |
|
9
|
|
|
* @copyright Copyright (c) 2020 nystudio107 |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace nystudio107\seomatic\models\metalink; |
|
13
|
|
|
|
|
14
|
|
|
use nystudio107\seomatic\Seomatic; |
|
15
|
|
|
use nystudio107\seomatic\models\MetaLink; |
|
16
|
|
|
use nystudio107\seomatic\helpers\UrlHelper; |
|
17
|
|
|
|
|
18
|
|
|
use craft\helpers\StringHelper; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* @author nystudio107 |
|
|
|
|
|
|
22
|
|
|
* @package Seomatic |
|
23
|
|
|
* @since 3.3.14 |
|
24
|
|
|
*/ |
|
25
|
|
|
class HomeLink extends MetaLink |
|
26
|
|
|
{ |
|
27
|
|
|
// Constants |
|
28
|
|
|
// ========================================================================= |
|
29
|
|
|
|
|
30
|
|
|
const ITEM_TYPE = 'HomeLink'; |
|
31
|
|
|
|
|
32
|
|
|
// Static Methods |
|
33
|
|
|
// ========================================================================= |
|
34
|
|
|
|
|
35
|
|
|
// Public Properties |
|
36
|
|
|
// ========================================================================= |
|
37
|
|
|
|
|
38
|
|
|
// Public Methods |
|
39
|
|
|
// ========================================================================= |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @inheritdoc |
|
43
|
|
|
*/ |
|
44
|
|
|
public function init() |
|
45
|
|
|
{ |
|
46
|
|
|
parent::init(); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* @inheritdoc |
|
51
|
|
|
*/ |
|
52
|
|
|
public function rules() |
|
53
|
|
|
{ |
|
54
|
|
|
$rules = parent::rules(); |
|
55
|
|
|
$rules = array_merge($rules, [ |
|
56
|
|
|
]); |
|
57
|
|
|
|
|
58
|
|
|
return $rules; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
|
|
|
|
|
62
|
|
|
* @inheritdoc |
|
63
|
|
|
*/ |
|
64
|
|
|
public function prepForRender(&$data): bool |
|
65
|
|
|
{ |
|
66
|
|
|
$shouldRender = parent::prepForRender($data); |
|
67
|
|
|
if ($shouldRender) { |
|
68
|
|
|
// Ensure the href is a full url |
|
69
|
|
|
if (!empty($data['href'])) { |
|
70
|
|
|
if (Seomatic::$settings->lowercaseCanonicalUrl) { |
|
71
|
|
|
$data['href'] = StringHelper::toLowerCase($data['href']); |
|
72
|
|
|
} |
|
73
|
|
|
$url = UrlHelper::absoluteUrlWithProtocol($data['href']); |
|
74
|
|
|
// The URL should be stripped of its query string already, but because |
|
75
|
|
|
// Craft adds the `token` URL param back in via UrlHelper, strip it again |
|
76
|
|
|
$url = preg_replace('/\?.*/', '', $url); |
|
77
|
|
|
$data['href'] = $url; |
|
78
|
|
|
} |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
return $shouldRender; |
|
82
|
|
|
} |
|
83
|
|
|
} |
|
84
|
|
|
|