1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Materials app controller |
5
|
|
|
* |
6
|
|
|
* @author Alexey Krupskiy <[email protected]> |
7
|
|
|
* @link http://inji.ru/ |
8
|
|
|
* @copyright 2015 Alexey Krupskiy |
9
|
|
|
* @license https://github.com/injitools/cms-Inji/blob/master/LICENSE |
10
|
|
|
*/ |
11
|
|
|
class MaterialsController extends Controller { |
|
|
|
|
12
|
|
|
|
13
|
|
|
public function indexAction() { |
14
|
|
|
$args = func_get_args(); |
15
|
|
|
$category = null; |
16
|
|
|
$material = null; |
17
|
|
|
$path = trim(implode('/', $args)); |
18
|
|
|
if (is_numeric($path)) { |
19
|
|
|
$material = Materials\Material::get([['id', (int) $path], ['date_publish', null, 'IS NOT']]); |
20
|
|
|
} |
21
|
|
|
if (!$material && $args) { |
|
|
|
|
22
|
|
|
foreach ($args as $key => $alias) { |
23
|
|
|
$nextCategory = Materials\Category::get([['parent_id', $category ? $category->id : 0], ['alias', $alias]]); |
24
|
|
|
if (!$nextCategory) { |
25
|
|
|
break; |
26
|
|
|
} |
27
|
|
|
$category = $nextCategory; |
28
|
|
|
} |
29
|
|
|
} |
30
|
|
|
if (!$material && $path) { |
31
|
|
|
if ($category) { |
32
|
|
|
$where = [ |
33
|
|
|
['tree_path', $category->tree_path . $category->id . '/%', 'LIKE'], |
34
|
|
|
['alias', $args[count($args) - 1]], |
35
|
|
|
['date_publish', null, 'IS NOT'] |
36
|
|
|
]; |
37
|
|
|
} else { |
38
|
|
|
$where = [['alias', $path], ['date_publish', null, 'IS NOT']]; |
39
|
|
|
} |
40
|
|
|
$material = Materials\Material::get($where); |
41
|
|
|
if (!$material) { |
42
|
|
|
if ($category) { |
43
|
|
|
$where = [ |
44
|
|
|
['category_id', $category->id], |
45
|
|
|
['id', (int) $args[count($args) - 1]], |
46
|
|
|
['date_publish', null, 'IS NOT'] |
47
|
|
|
]; |
48
|
|
|
} else { |
49
|
|
|
$where = [['alias', $path], ['date_publish', null, 'IS NOT']]; |
50
|
|
|
} |
51
|
|
|
$material = Materials\Material::get($where); |
52
|
|
|
} |
53
|
|
|
if (!$material) { |
54
|
|
|
$category = Materials\Category::get($path, 'alias'); |
55
|
|
|
if ($category) { |
56
|
|
|
$this->categoryAction($category->id); |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
} elseif (!$material) { |
60
|
|
|
$material = Materials\Material::get(1, 'default'); |
61
|
|
|
} |
62
|
|
|
if ($material) { |
63
|
|
|
$this->viewAction($material->id); |
64
|
|
|
} elseif (!$category && !$material) { |
65
|
|
|
Tools::header('404'); |
|
|
|
|
66
|
|
|
$this->view->page([ |
67
|
|
|
'content' => '404', |
68
|
|
|
'data' => ['text' => 'Такой страницы не найдено'] |
69
|
|
|
]); |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
public function categoryAction() { |
74
|
|
|
$args = func_get_args(); |
75
|
|
|
$path = trim(implode('/', $args)); |
76
|
|
|
$category = null; |
77
|
|
|
if (is_numeric($path)) { |
78
|
|
|
$category = Materials\Category::get((int) $path); |
79
|
|
|
} |
80
|
|
|
if (!$category) { |
81
|
|
|
foreach ($args as $alias) { |
82
|
|
|
$category = Materials\Category::get([['parent_id', $category ? $category->id : 0], ['alias', $alias]]); |
83
|
|
|
if (!$category) { |
84
|
|
|
break; |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
if (!$category) { |
89
|
|
|
$category = Materials\Category::get($path, 'alias'); |
90
|
|
|
} |
91
|
|
|
if (!$category) { |
92
|
|
|
Tools::header('404'); |
93
|
|
|
$this->view->page([ |
94
|
|
|
'content' => '404', |
95
|
|
|
'data' => ['text' => 'Такой страницы не найдено'] |
96
|
|
|
]); |
97
|
|
|
} else { |
98
|
|
|
$this->view->setTitle($category->name); |
99
|
|
|
|
100
|
|
|
$pages = new Ui\Pages($_GET, ['count' => Materials\Material::getCount(['where' => [['tree_path', $category->tree_path . $category->id . '/%', 'LIKE'], ['date_publish', null, 'IS NOT']]]), 'limit' => 10]); |
101
|
|
|
$materials = Materials\Material::getList(['where' => [['tree_path', $category->tree_path . $category->id . '/%', 'LIKE'], ['date_publish', null, 'IS NOT']], 'order' => ['date_create', 'desc'], 'start' => $pages->params['start'], 'limit' => $pages->params['limit']]); |
102
|
|
|
|
103
|
|
|
$this->view->page(['page' => $category->resolveTemplate(), 'content' => $category->resolveViewer(), 'data' => compact('materials', 'pages', 'category')]); |
104
|
|
|
} |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
public function viewAction() { |
108
|
|
|
$args = func_get_args(); |
109
|
|
|
$alias = trim(implode('/', $args)); |
110
|
|
|
$material = false; |
111
|
|
|
if ($alias) { |
112
|
|
|
if (is_numeric($alias)) { |
113
|
|
|
$material = Materials\Material::get([['id', (int) $alias], ['date_publish', null, 'IS NOT']]); |
114
|
|
|
} |
115
|
|
|
if (!$material) { |
116
|
|
|
$material = Materials\Material::get([['alias', $alias], ['date_publish', null, 'IS NOT']]); |
117
|
|
|
if (!$material) { |
118
|
|
|
Tools::header('404'); |
119
|
|
|
$this->view->page([ |
120
|
|
|
'content' => '404', |
121
|
|
|
'data' => ['text' => 'Такой страницы не найдено'] |
122
|
|
|
]); |
123
|
|
|
} |
124
|
|
|
} |
125
|
|
|
} |
126
|
|
|
if ($material->keywords) { |
127
|
|
|
$this->view->addMetaTag(['name' => 'keywords', 'content' => $material->keywords]); |
128
|
|
|
} |
129
|
|
|
if ($material->description) { |
130
|
|
|
$this->view->addMetaTag(['name' => 'description', 'content' => $material->description]); |
131
|
|
|
} |
132
|
|
|
$this->view->addMetaTag(['property' => 'og:title', 'content' => $material->name]); |
133
|
|
|
$this->view->addMetaTag(['property' => 'og:url', 'content' => 'http://' . idn_to_utf8(INJI_DOMAIN_NAME) . '/' . $material->alias]); |
134
|
|
|
if ($material->description) { |
135
|
|
|
$this->view->addMetaTag(['property' => 'og:description', 'content' => 'http://' . idn_to_utf8(INJI_DOMAIN_NAME) . '/' . $material->description]); |
136
|
|
|
} |
137
|
|
|
if ($material->image) { |
138
|
|
|
$this->view->addMetaTag(['property' => 'og:image', 'content' => 'http://' . idn_to_utf8(INJI_DOMAIN_NAME) . $material->image->path]); |
139
|
|
|
} elseif ($logo = Files\File::get('site_logo', 'code')) { |
140
|
|
|
$this->view->addMetaTag(['property' => 'og:image', 'content' => 'http://' . idn_to_utf8(INJI_DOMAIN_NAME) . $logo->path]); |
141
|
|
|
} |
142
|
|
|
$this->view->setTitle($material->name); |
143
|
|
|
$bread = []; |
144
|
|
|
$bread[] = ['text' => $material->name, 'href' => '/' . $material->alias]; |
145
|
|
|
$this->view->page([ |
146
|
|
|
'page' => $material->resolveTemplate(), |
147
|
|
|
'content' => $material->resolveViewer(), |
148
|
|
|
'data' => compact('material', 'bread'), |
149
|
|
|
]); |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
function detailSearchAction() { |
|
|
|
|
153
|
|
|
$this->view->setTitle('Поиск материалов'); |
154
|
|
|
$result = []; |
155
|
|
|
if (!empty($_GET['search']) && is_string($_GET['search'])) { |
156
|
|
|
$result = $this->module->search($_GET['search']); |
157
|
|
|
} |
158
|
|
|
$this->view->page(['data' => ['result' => $result]]); |
159
|
|
|
} |
160
|
|
|
} |
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