|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Chuckbe\Chuckcms\Models; |
|
4
|
|
|
|
|
5
|
|
|
use Chuckbe\Chuckcms\Models\PageBlock; |
|
6
|
|
|
use ChuckSite; |
|
|
|
|
|
|
7
|
|
|
|
|
8
|
|
|
use \Illuminate\Database\Eloquent\Model as Eloquent; |
|
9
|
|
|
|
|
10
|
|
|
use Spatie\EloquentSortable\Sortable; |
|
11
|
|
|
use Spatie\EloquentSortable\SortableTrait; |
|
12
|
|
|
use Spatie\Translatable\HasTranslations; |
|
13
|
|
|
|
|
14
|
|
|
class Page extends Eloquent implements Sortable |
|
15
|
|
|
{ |
|
16
|
|
|
use SortableTrait; |
|
17
|
|
|
use HasTranslations; |
|
18
|
|
|
|
|
19
|
|
|
public $sortable = [ |
|
20
|
|
|
'order_column_name' => 'order', |
|
21
|
|
|
'sort_when_creating' => true, |
|
22
|
|
|
]; |
|
23
|
|
|
|
|
24
|
|
|
public function template(){ |
|
25
|
|
|
return $this->belongsTo('Chuckbe\Chuckcms\Models\Template'); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
public function page_blocks(){ |
|
29
|
|
|
return $this->hasMany('Chuckbe\Chuckcms\Models\PageBlock')->orderBy('order'); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
public function getById($id) |
|
33
|
|
|
{ |
|
34
|
|
|
return $this->where('id', $id)->first(); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
public function getByIdWithBlocks($id) |
|
38
|
|
|
{ |
|
39
|
|
|
return $this->where('id', $id)->with('page_blocks')->first(); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
public static function getUrl($id) |
|
43
|
|
|
{ |
|
44
|
|
|
return ChuckSite::getSetting('domain') . '/' . self::where('id', $id)->first()->slug; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
public function create($values) |
|
48
|
|
|
{ |
|
49
|
|
|
$page = new Page(); |
|
50
|
|
|
|
|
51
|
|
|
$meta = []; |
|
52
|
|
|
foreach (ChuckSite::getSupportedLocales() as $langKey => $langValue) { |
|
53
|
|
|
$page->setTranslation('title', $langKey, $values->get('page_title')[$langKey]); |
|
54
|
|
|
$page->setTranslation('slug', $langKey, $values->get('page_slug')[$langKey]); |
|
55
|
|
|
|
|
56
|
|
|
$meta[$langKey]['title'] = $values->get('meta_title')[$langKey]; |
|
57
|
|
|
$meta[$langKey]['description'] = $values->get('meta_description')[$langKey]; |
|
58
|
|
|
$meta[$langKey]['keywords'] = $values->get('meta_keywords')[$langKey]; |
|
59
|
|
|
$meta[$langKey]['og-url'] = $values->get('page_slug')[$langKey]; |
|
60
|
|
|
$meta[$langKey]['og-type'] = 'website'; |
|
61
|
|
|
$meta[$langKey]['og-title'] = $values->get('meta_title')[$langKey]; |
|
62
|
|
|
$meta[$langKey]['og-description'] = $values->get('meta_description')[$langKey]; |
|
63
|
|
|
$meta[$langKey]['og-site_name'] = $values->get('meta_title')[$langKey]; |
|
64
|
|
|
if ($values->get('meta_robots_index')[$langKey] == '1') { |
|
65
|
|
|
$index = 'index, '; |
|
66
|
|
|
} else { |
|
67
|
|
|
$index = 'noindex, '; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
if ($values->get('meta_robots_follow')[$langKey] == '1') { |
|
71
|
|
|
$follow = 'follow'; |
|
72
|
|
|
} else { |
|
73
|
|
|
$follow = 'nofollow'; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
$meta[$langKey]['robots'] = $index . $follow; |
|
77
|
|
|
$meta[$langKey]['googlebots'] = $index . $follow; |
|
78
|
|
|
$count = count($values->get('meta_key')[$langKey]); |
|
79
|
|
|
for ($i=0; $i < $count; $i++) { |
|
80
|
|
|
$meta[$langKey][$values->get('meta_key')[$langKey][$i]] = $values->get('meta_value')[$langKey][$i]; |
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
$page->meta = $meta; |
|
84
|
|
|
|
|
85
|
|
|
$page->template_id = $values['template_id']; |
|
86
|
|
|
$page->page = $values['page']; |
|
87
|
|
|
$page->active = $values['active']; |
|
88
|
|
|
$page->isHp = $values['isHp']; |
|
89
|
|
|
$page->order_column = ($this->max('order_column') ?? 0) + 1; |
|
|
|
|
|
|
90
|
|
|
$page->save(); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
public function updatePage($values) |
|
94
|
|
|
{ |
|
95
|
|
|
$page = $this->getById($values['page_id']); |
|
96
|
|
|
|
|
97
|
|
|
$meta = []; |
|
98
|
|
|
foreach (ChuckSite::getSupportedLocales() as $langKey => $langValue) { |
|
99
|
|
|
$page->setTranslation('title', $langKey, $values->get('page_title')[$langKey]); |
|
100
|
|
|
$page->setTranslation('slug', $langKey, $values->get('page_slug')[$langKey]); |
|
101
|
|
|
$count = count($values->get('meta_key')[$langKey]); |
|
102
|
|
|
for ($i=0; $i < $count; $i++) { |
|
103
|
|
|
$meta[$langKey][$values->get('meta_key')[$langKey][$i]] = $values->get('meta_value')[$langKey][$i]; |
|
104
|
|
|
} |
|
105
|
|
|
} |
|
106
|
|
|
$page->meta = $meta; |
|
107
|
|
|
|
|
108
|
|
|
$page->template_id = $values['template_id']; |
|
109
|
|
|
$page->page = $values['page']; |
|
110
|
|
|
$page->active = $values['active']; |
|
111
|
|
|
$page->isHp = $values['isHp']; |
|
112
|
|
|
|
|
113
|
|
|
$page->save(); |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
public function deleteById($id) |
|
117
|
|
|
{ |
|
118
|
|
|
$page = $this->where('id', $id)->first(); |
|
119
|
|
|
if ($page) { |
|
120
|
|
|
PageBlock::where('page_id', $page->id)->delete(); |
|
121
|
|
|
if ($page->delete()) { |
|
122
|
|
|
return 'success'; |
|
123
|
|
|
} else { |
|
124
|
|
|
return 'error'; |
|
125
|
|
|
} |
|
126
|
|
|
} else { |
|
127
|
|
|
return 'false'; |
|
128
|
|
|
} |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
public $translatable = ['title', 'slug']; |
|
132
|
|
|
|
|
133
|
|
|
protected $casts = [ |
|
134
|
|
|
'meta' => 'array', |
|
135
|
|
|
]; |
|
136
|
|
|
|
|
137
|
|
|
/** |
|
138
|
|
|
* The attributes that are mass assignable. |
|
139
|
|
|
* |
|
140
|
|
|
* @var array |
|
141
|
|
|
*/ |
|
142
|
|
|
protected $fillable = [ |
|
143
|
|
|
'order_column', |
|
144
|
|
|
]; |
|
145
|
|
|
} |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths