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
|
43 |
|
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
|
43 |
|
$this->config = $config; |
56
|
43 |
|
$this->phpbb_container = $phpbb_container; |
57
|
43 |
|
$this->request = $request; |
58
|
43 |
|
$this->translator = $translator; |
59
|
43 |
|
$this->blocks = $blocks; |
60
|
43 |
|
$this->block_factory = $block_factory; |
61
|
43 |
|
$this->mapper_factory = $mapper_factory; |
62
|
43 |
|
} |
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
|
8 |
|
protected function force_get_route(array $route_data, $has_blocks = false) |
72
|
|
|
{ |
73
|
8 |
|
$route_mapper = $this->mapper_factory->create('blocks', 'routes'); |
74
|
|
|
|
75
|
8 |
|
if (($route = $route_mapper->load($this->get_condition($route_data))) === null) |
76
|
8 |
|
{ |
77
|
2 |
|
$route_data['ext_name'] = $this->request->variable('ext', ''); |
78
|
2 |
|
$route_data['has_blocks'] = $has_blocks; |
79
|
|
|
|
80
|
2 |
|
$entity = $route_mapper->create_entity($route_data); |
81
|
2 |
|
$route = $route_mapper->save($entity); |
82
|
2 |
|
} |
83
|
|
|
|
84
|
8 |
|
return $route; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @param array $info |
89
|
|
|
* @return array |
90
|
|
|
*/ |
91
|
11 |
|
protected function get_condition(array $info) |
92
|
|
|
{ |
93
|
|
|
return array( |
94
|
11 |
|
array('route', '=', $info['route']), |
95
|
11 |
|
array('style', '=', $info['style']), |
96
|
11 |
|
); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @param \blitze\sitemaker\model\entity_interface $entity |
101
|
|
|
* @return array |
102
|
|
|
*/ |
103
|
15 |
|
protected function render_block(\blitze\sitemaker\model\entity_interface $entity) |
104
|
|
|
{ |
105
|
|
|
/** @type \blitze\sitemaker\model\blocks\entity\block $entity */ |
106
|
15 |
|
$block_name = $entity->get_name(); |
107
|
15 |
|
if ($block_instance = $this->block_factory->get_block($block_name)) |
108
|
15 |
|
{ |
109
|
14 |
|
$default_settings = $block_instance->get_config(array()); |
110
|
14 |
|
$settings = $this->blocks->sync_settings($default_settings, $entity->get_settings()); |
111
|
14 |
|
$entity->set_settings($settings); |
112
|
|
|
|
113
|
14 |
|
$block_data = $entity->to_array(); |
114
|
14 |
|
$disp_data = $block_instance->display($block_data, true); |
115
|
|
|
|
116
|
14 |
|
return array_merge($block_data, array( |
117
|
14 |
|
'id' => $block_data['bid'], |
118
|
14 |
|
'title' => (!empty($block_data['title'])) ? $block_data['title'] : $this->translator->lang($disp_data['title']), |
119
|
14 |
|
'content' => (!empty($disp_data['content'])) ? $disp_data['content'] : $this->translator->lang('BLOCK_NO_DATA'), |
120
|
14 |
|
)); |
121
|
|
|
} |
122
|
|
|
|
123
|
2 |
|
return array(); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* @param array $route_prefs |
128
|
|
|
* @return bool |
129
|
|
|
*/ |
130
|
7 |
|
protected function route_is_customized(array $route_prefs) |
131
|
|
|
{ |
132
|
7 |
|
$route_prefs = array_intersect_key($route_prefs, self::$default_prefs); |
133
|
7 |
|
return (self::$default_prefs !== $route_prefs) ? true : false; |
134
|
|
|
} |
135
|
|
|
} |
136
|
|
|
|