1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* |
4
|
|
|
* @package sitemaker |
5
|
|
|
* @copyright (c) 2013 Daniel A. (blitze) |
6
|
|
|
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 |
7
|
|
|
* |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace blitze\sitemaker\services\blocks\action; |
11
|
|
|
|
12
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
13
|
|
|
|
14
|
|
|
abstract class base_action implements action_interface |
15
|
|
|
{ |
16
|
|
|
/** @var \phpbb\config\config */ |
17
|
|
|
protected $config; |
18
|
|
|
|
19
|
|
|
/** @var ContainerInterface */ |
20
|
|
|
protected $phpbb_container; |
21
|
|
|
|
22
|
|
|
/** @var \phpbb\request\request_interface */ |
23
|
|
|
protected $request; |
24
|
|
|
|
25
|
|
|
/** @var \phpbb\language\language */ |
26
|
|
|
protected $translator; |
27
|
|
|
|
28
|
|
|
/** @var \blitze\sitemaker\services\blocks\blocks */ |
29
|
|
|
protected $blocks; |
30
|
|
|
|
31
|
|
|
/** @var \blitze\sitemaker\services\blocks\factory */ |
32
|
|
|
protected $block_factory; |
33
|
|
|
|
34
|
|
|
/** @var \blitze\sitemaker\model\mapper_factory */ |
35
|
|
|
protected $mapper_factory; |
36
|
|
|
|
37
|
|
|
protected static $default_prefs = array( |
38
|
|
|
'hide_blocks' => false, |
39
|
|
|
'ex_positions' => array(), |
40
|
|
|
); |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Constructor |
44
|
|
|
* |
45
|
|
|
* @param \phpbb\config\config $config Config object |
46
|
|
|
* @param ContainerInterface $phpbb_container Service container |
47
|
|
|
* @param \phpbb\request\request_interface $request Request object |
48
|
|
|
* @param \phpbb\language\language $translator Langua object |
49
|
|
|
* @param \blitze\sitemaker\services\blocks\blocks $blocks Blocks object |
50
|
|
|
* @param \blitze\sitemaker\services\blocks\factory $block_factory Blocks factory object |
51
|
|
|
* @param \blitze\sitemaker\model\mapper_factory $mapper_factory Mapper factory object |
52
|
|
|
*/ |
53
|
46 |
|
public function __construct(\phpbb\config\config $config, ContainerInterface $phpbb_container, \phpbb\request\request_interface $request, \phpbb\language\language $translator, \blitze\sitemaker\services\blocks\blocks $blocks, \blitze\sitemaker\services\blocks\factory $block_factory, \blitze\sitemaker\model\mapper_factory $mapper_factory) |
54
|
|
|
{ |
55
|
46 |
|
$this->config = $config; |
56
|
46 |
|
$this->phpbb_container = $phpbb_container; |
57
|
46 |
|
$this->request = $request; |
58
|
46 |
|
$this->translator = $translator; |
59
|
46 |
|
$this->blocks = $blocks; |
60
|
46 |
|
$this->block_factory = $block_factory; |
61
|
46 |
|
$this->mapper_factory = $mapper_factory; |
62
|
46 |
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* This is guaranteed to return a route entity. If the route does not exist, it create it |
66
|
|
|
* |
67
|
|
|
* @param array $route_data |
68
|
|
|
* @param bool $has_blocks |
69
|
|
|
* @return \blitze\sitemaker\model\entity_interface |
70
|
|
|
*/ |
71
|
9 |
|
protected function force_get_route(array $route_data, $has_blocks = false) |
72
|
|
|
{ |
73
|
9 |
|
$route_mapper = $this->mapper_factory->create('routes'); |
74
|
|
|
|
75
|
9 |
|
if (($route = $route_mapper->load($this->get_condition($route_data))) === null) |
76
|
9 |
|
{ |
77
|
3 |
|
$route_data['ext_name'] = $this->request->variable('ext', ''); |
78
|
3 |
|
$route_data['has_blocks'] = $has_blocks; |
79
|
|
|
|
80
|
3 |
|
$entity = $route_mapper->create_entity($route_data); |
81
|
3 |
|
$route = $route_mapper->save($entity); |
82
|
3 |
|
} |
83
|
|
|
|
84
|
9 |
|
return $route; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @param array $info |
89
|
|
|
* @return array |
90
|
|
|
*/ |
91
|
12 |
|
protected function get_condition(array $info) |
92
|
|
|
{ |
93
|
|
|
return array( |
94
|
12 |
|
array('route', '=', $info['route']), |
95
|
12 |
|
array('style', '=', $info['style']), |
96
|
12 |
|
); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @param \blitze\sitemaker\model\entity_interface $entity |
101
|
|
|
* @return array |
102
|
|
|
*/ |
103
|
16 |
|
protected function render_block(\blitze\sitemaker\model\entity_interface $entity) |
104
|
|
|
{ |
105
|
16 |
|
$block = array(); |
106
|
|
|
/** @type \blitze\sitemaker\model\entity\block $entity */ |
107
|
16 |
|
if ($block_instance = $this->block_factory->get_block($entity->get_name())) |
108
|
16 |
|
{ |
109
|
15 |
|
$default_settings = $block_instance->get_config(array()); |
110
|
15 |
|
$settings = $this->blocks->sync_settings($default_settings, $entity->get_settings()); |
111
|
15 |
|
$entity->set_settings($settings); |
112
|
|
|
|
113
|
15 |
|
$db_data = $entity->to_array(); |
114
|
15 |
|
$returned_data = $block_instance->display($db_data, true); |
115
|
|
|
|
116
|
15 |
|
$returned_data['id'] = $db_data['bid']; |
117
|
15 |
|
$returned_data['title'] = $this->get_block_title($db_data['title'], $returned_data['title']); |
118
|
15 |
|
$returned_data['content'] = $this->get_block_content($returned_data); |
119
|
|
|
|
120
|
15 |
|
$block = array_merge($db_data, $returned_data); |
121
|
15 |
|
$block['class'] .= (!$block['status']) ? ' sm-inactive' : ''; |
122
|
15 |
|
} |
123
|
|
|
|
124
|
16 |
|
return $block; |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* @param string $custom_title |
129
|
|
|
* @param string $default_title |
130
|
|
|
* @return string |
131
|
|
|
*/ |
132
|
15 |
|
protected function get_block_title($custom_title, $default_title) |
133
|
|
|
{ |
134
|
15 |
|
return ($custom_title) ? $custom_title : $this->translator->lang($default_title); |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* @param array $returned_data |
139
|
|
|
* @return string |
140
|
|
|
*/ |
141
|
15 |
|
protected function get_block_content(array &$returned_data) |
142
|
|
|
{ |
143
|
15 |
|
if (empty($returned_data['content'])) |
144
|
15 |
|
{ |
145
|
2 |
|
$content = $this->translator->lang('BLOCK_NO_DATA'); |
146
|
2 |
|
$returned_data['status'] = 0; |
147
|
2 |
|
} |
148
|
|
|
else |
149
|
|
|
{ |
150
|
14 |
|
$content = $returned_data['content']; |
151
|
|
|
} |
152
|
15 |
|
return $content; |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
/** |
156
|
|
|
* @param array $route_prefs |
157
|
|
|
* @return bool |
158
|
|
|
*/ |
159
|
7 |
|
protected function route_is_customized(array $route_prefs) |
160
|
|
|
{ |
161
|
7 |
|
$route_prefs = array_intersect_key($route_prefs, self::$default_prefs); |
162
|
7 |
|
return (self::$default_prefs !== $route_prefs) ? true : false; |
163
|
|
|
} |
164
|
|
|
} |
165
|
|
|
|