1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
class Ajde_Cms extends Ajde_Object_Singleton implements Ajde_BootstrapInterface |
4
|
|
|
{ |
5
|
|
|
private $_homepageSet = false; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* @var NodeModel|bool |
9
|
|
|
*/ |
10
|
|
|
private $_detectedNode = false; |
11
|
|
|
|
12
|
|
|
public static function getInstance() |
13
|
|
|
{ |
14
|
|
|
static $instance; |
15
|
|
|
|
16
|
|
|
return $instance === null ? $instance = new self() : $instance; |
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
protected function __construct() |
20
|
|
|
{ |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
public function __bootstrap() |
24
|
|
|
{ |
25
|
|
|
Ajde_Event::register('Ajde_Core_Route', 'onAfterLangSet', [$this, 'setHomepage']); |
26
|
|
|
Ajde_Event::register('Ajde_Core_Route', 'onAfterRouteSet', [$this, 'detectNodeSlug']); |
27
|
|
|
Ajde_Event::register('Ajde_Core_Route', 'onAfterRouteSet', [$this, 'detectShopSlug']); |
28
|
|
|
|
29
|
|
|
return true; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
public function setHomepage(Ajde_Core_Route $route) |
|
|
|
|
33
|
|
|
{ |
34
|
|
|
if ($this->_homepageSet) { |
35
|
|
|
return; |
36
|
|
|
} |
37
|
|
|
$this->_homepageSet = true; |
38
|
|
|
|
39
|
|
|
$homepageNodeId = (int) SettingModel::byName('homepage'); |
40
|
|
|
|
41
|
|
|
if ($homepageNodeId) { |
42
|
|
|
$node = NodeModel::fromPk($homepageNodeId); |
43
|
|
|
if ($node) { |
44
|
|
|
Config::set('routes.homepage', $node->getUrl()); |
45
|
|
|
} |
46
|
|
|
} |
47
|
|
|
} |
48
|
|
|
|
49
|
|
View Code Duplication |
public function detectNodeSlug(Ajde_Core_Route $route) |
|
|
|
|
50
|
|
|
{ |
51
|
|
|
$slug = $route->getRoute(); |
52
|
|
|
|
53
|
|
|
$slug = trim($slug, '/'); |
54
|
|
|
$lastSlash = strrpos($slug, '/'); |
55
|
|
|
if ($lastSlash !== false) { |
56
|
|
|
$slug = substr($slug, $lastSlash + 1); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
$node = NodeModel::fromSlug($slug); |
60
|
|
|
if ($node) { |
61
|
|
|
$this->_detectedNode = $node; |
62
|
|
|
$route->setRoute($slug); |
63
|
|
|
$routes = config('routes.list'); |
64
|
|
|
array_unshift($routes, ['%^('.preg_quote($slug).')$%' => ['slug']]); |
65
|
|
|
Config::set('routes.list', $routes); |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|
69
|
|
View Code Duplication |
public function detectShopSlug(Ajde_Core_Route $route) |
|
|
|
|
70
|
|
|
{ |
71
|
|
|
$slug = $route->getRoute(); |
72
|
|
|
|
73
|
|
|
$slug = trim($slug, '/'); |
74
|
|
|
$lastSlash = strrpos($slug, '/'); |
75
|
|
|
if ($lastSlash !== false) { |
76
|
|
|
$lastSlugPart = substr($slug, $lastSlash + 1); |
77
|
|
|
|
78
|
|
|
$product = ProductModel::fromSlug($lastSlugPart); |
79
|
|
|
if ($product) { |
80
|
|
|
$route->setRoute($slug); |
81
|
|
|
$routes = config('routes.list'); |
82
|
|
|
array_unshift($routes, ['%^(shop)/('.preg_quote($lastSlugPart).')$%' => ['module', 'slug']]); |
83
|
|
|
Config::set('routes.list', $routes); |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* @return NodeModel|bool |
90
|
|
|
*/ |
91
|
|
|
public function getRoutedNode() |
92
|
|
|
{ |
93
|
|
|
return $this->_detectedNode; |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.