1
|
|
|
<?php |
2
|
|
|
namespace samsoncms\cms; |
3
|
|
|
|
4
|
|
|
use samson\activerecord\dbQuery; |
5
|
|
|
use samson\core\CompressableExternalModule; |
6
|
|
|
use samson\pager\Pager; |
7
|
|
|
use samsonphp\event\Event; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* SamsonCMS external compressible application for integrating |
11
|
|
|
* @author Vitaly Iegorov <[email protected]> |
12
|
|
|
*/ |
13
|
|
|
class Application extends CompressableExternalModule { |
14
|
|
|
/** @var string Module identifier */ |
15
|
|
|
protected $id = 'cms'; |
16
|
|
|
|
17
|
|
|
protected $isCMS = false; |
18
|
|
|
|
19
|
|
|
public function isCMS() |
20
|
|
|
{ |
21
|
|
|
return $this->isCMS; |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
public function init( array $params = array() ) { |
25
|
|
|
Event::subscribe('core.security', array($this, 'updateTemplate')); |
26
|
|
|
// Old applications main page rendering |
27
|
|
|
Event::subscribe('template.main.rendered', array($this, 'oldMainRenderer')); |
28
|
|
|
// Old applications menu rendering |
29
|
|
|
Event::subscribe('template.menu.rendered', array($this, 'oldMenuRenderer')); |
30
|
|
|
|
31
|
|
|
Event::subscribe('samson.url.build', array($this, 'buildUrl')); |
32
|
|
|
// Call parent initialization |
33
|
|
|
return parent::init( $params ); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
public function buildUrl(& $urlObj, & $httpHost, & $urlParams) |
37
|
|
|
{ |
38
|
|
|
$index = 0; |
39
|
|
|
if (isset($urlParams[$index]) && (\samson\core\SamsonLocale::current() == $urlParams[$index])) { |
40
|
|
|
$index = 1; |
41
|
|
|
} |
42
|
|
|
if ( isset( $urlParams[$index] ) && ( strpos($urlParams[$index], 'cms-') === 0 ) ) { |
43
|
|
|
$urlParams[$index] = str_replace('cms-', '', $urlParams[$index]); |
44
|
|
|
array_unshift($urlParams, 'cms'); |
45
|
|
|
} |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function updateTemplate($core, $securityResult) { |
|
|
|
|
49
|
|
|
if ($this->isCMS) { |
50
|
|
|
$core->template($this->path().'app/view/index.php', true); |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function initUrl( & $urlObj, & $urlArgs ) { |
|
|
|
|
55
|
|
|
if($urlArgs[0] == 'cms') { |
56
|
|
|
$this->isCMS = true; |
57
|
|
|
if (isset($urlArgs[1])) { |
58
|
|
|
if (strpos($urlArgs[1], 'samsoncms_') !== 0){ |
59
|
|
|
$urlArgs[1] = 'cms-'.$urlArgs[1]; |
60
|
|
|
} |
61
|
|
|
unset($urlArgs[0]); |
62
|
|
|
$urlArgs = array_values($urlArgs); |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
public function initResources(& $resourceRouter, $moduleId, & $approve) |
|
|
|
|
68
|
|
|
{ |
69
|
|
|
if ($moduleId == 'core') return true; |
70
|
|
|
if ($this->isCMS) { |
71
|
|
|
$approve = false; |
72
|
|
|
if (isset(m($moduleId)->composerParameters['composerName'])&& |
73
|
|
|
isset(m('cms')->composerParameters['required'])&& |
74
|
|
|
in_array(m($moduleId)->composerParameters['composerName'], m('cms')->composerParameters['required'])){ |
75
|
|
|
$approve = true; |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
public function __base() |
82
|
|
|
{ |
83
|
|
|
$this->active(m('template')); |
|
|
|
|
84
|
|
|
|
85
|
|
|
m('template')->__handler(); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
public function oldMainRenderer(&$html) |
89
|
|
|
{ |
90
|
|
|
// Render application main page block |
91
|
|
|
foreach (\samsoncms\Application::loaded() as $app) { |
|
|
|
|
92
|
|
|
// Show only visible apps |
93
|
|
|
if ($app->hide == false && $app->findView('sub_menu')) { |
94
|
|
|
$html .= $app->main(); |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @deprecated All application should draw menu block via events |
101
|
|
|
*/ |
102
|
|
|
public function oldMenuRenderer(&$html, &$subMenu) |
103
|
|
|
{ |
104
|
|
|
// Iterate loaded samson\cms\application |
105
|
|
|
foreach (\samsoncms\Application::loaded() as $app) { |
|
|
|
|
106
|
|
|
// Show only visible apps |
107
|
|
|
if ($app->hide == false) { |
108
|
|
|
// Render application menu item |
109
|
|
|
$html .= m('template') |
110
|
|
|
->view('menu/item') |
111
|
|
|
->active(url()->module == $app->id() ? 'active' : '') |
112
|
|
|
->app($app) |
113
|
|
|
->icon($app->icon) |
114
|
|
|
->name(isset($app->name{0}) ? $app->name : '') |
115
|
|
|
->output(); |
116
|
|
|
} |
117
|
|
|
} |
118
|
|
|
$subMenu = ''; |
119
|
|
|
// Find current SamsonCMS application |
120
|
|
|
if (\samsoncms\Application::find(url()->module, $app/*@var $app App*/)) { |
121
|
|
|
// If module has sub_menu view - render it |
122
|
|
|
if ($app->findView('sub_menu')) { |
123
|
|
|
$subMenu .= $app->view('sub_menu')->output(); |
124
|
|
|
} |
125
|
|
|
} |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* @deprecated |
130
|
|
|
* @return string Page title |
131
|
|
|
*/ |
132
|
|
|
public function oldGetTitle() |
133
|
|
|
{ |
134
|
|
|
$local = m('local'); |
135
|
|
|
$current = m(); |
136
|
|
|
return isset($current['title']) ? $current['title'] : |
137
|
|
|
(isset($local['title']) ? $local['title'] : ''); |
138
|
|
|
} |
139
|
|
|
} |
140
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.