1
|
|
|
<?php namespace Arcanesoft\Seo\Models\Presenters; |
2
|
|
|
|
3
|
|
|
use Arcanesoft\Seo\Entities\Locales; |
4
|
|
|
use Arcanesoft\Seo\Helpers\TextReplacer; |
5
|
|
|
|
6
|
|
|
/** |
7
|
|
|
* Class PagePresenter |
8
|
|
|
* |
9
|
|
|
* @package Arcanesoft\Seo\Models\Presenters |
10
|
|
|
* @author ARCANEDEV <[email protected]> |
11
|
|
|
* |
12
|
|
|
* @property string locale |
13
|
|
|
* @property string locale_name |
14
|
|
|
* @property string content |
15
|
|
|
* @property string content_preview |
16
|
|
|
*/ |
17
|
|
|
trait PagePresenter |
18
|
|
|
{ |
19
|
|
|
/* ----------------------------------------------------------------- |
20
|
|
|
| Accessors |
21
|
|
|
| ----------------------------------------------------------------- |
22
|
|
|
*/ |
23
|
|
|
/** |
24
|
|
|
* Get the `locale_name` attribute. |
25
|
|
|
* |
26
|
|
|
* @return string|null |
27
|
|
|
*/ |
28
|
|
|
public function getLocaleNameAttribute() |
29
|
|
|
{ |
30
|
|
|
return Locales::get($this->locale); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Get the `content_preview` attribute. |
35
|
|
|
* |
36
|
|
|
* @return string |
37
|
|
|
*/ |
38
|
|
|
public function getContentPreviewAttribute() |
39
|
|
|
{ |
40
|
|
|
return $this->getContentReplacer()->highlight($this->content); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/* ----------------------------------------------------------------- |
44
|
|
|
| Other Methods |
45
|
|
|
| ----------------------------------------------------------------- |
46
|
|
|
*/ |
47
|
|
|
/** |
48
|
|
|
* Render the content. |
49
|
|
|
* |
50
|
|
|
* @param array $replacements |
51
|
|
|
* |
52
|
|
|
* @return string |
53
|
|
|
*/ |
54
|
|
|
public function renderContent(array $replacements) |
55
|
|
|
{ |
56
|
|
|
return $this->getContentReplacer()->replace($this->content, array_merge([ |
57
|
|
|
'app_name' => config('app.name'), |
58
|
|
|
'app_url' => link_to(config('app.url'), config('app.name')), |
59
|
|
|
'mobile' => config('cms.company.mobile'), |
60
|
|
|
'phone' => config('cms.company.phone'), |
61
|
|
|
'email' => html()->mailto(config('cms.company.email')), |
62
|
|
|
], $replacements)); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Get the content replacer. |
67
|
|
|
* |
68
|
|
|
* @return \Arcanesoft\Seo\Helpers\TextReplacer |
69
|
|
|
*/ |
70
|
|
|
public static function getContentReplacer() |
71
|
|
|
{ |
72
|
|
|
return TextReplacer::make( |
73
|
|
|
config('arcanesoft.seo.pages.replacer', []) |
74
|
|
|
); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Get the content replacer pattern. |
79
|
|
|
* |
80
|
|
|
* @return string |
81
|
|
|
*/ |
82
|
|
|
protected function getReplacerPattern() |
83
|
|
|
{ |
84
|
|
|
$replacer = config('arcanesoft.seo.pages.replacer', []); |
85
|
|
|
|
86
|
|
|
return empty($replacer) ? '' : '/\[('.implode('|', $replacer).')\]/'; |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|