|
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
|
|
|
use blitze\sitemaker\services\blocks\action\action_interface; |
|
14
|
|
|
|
|
15
|
|
|
abstract class base_action implements action_interface |
|
16
|
|
|
{ |
|
17
|
|
|
/** @var \phpbb\config\config */ |
|
18
|
|
|
protected $config; |
|
19
|
|
|
|
|
20
|
|
|
/** @var ContainerInterface */ |
|
21
|
|
|
protected $phpbb_container; |
|
22
|
|
|
|
|
23
|
|
|
/** @var \phpbb\request\request_interface */ |
|
24
|
|
|
protected $request; |
|
25
|
|
|
|
|
26
|
|
|
/** @var \phpbb\user */ |
|
27
|
|
|
protected $user; |
|
28
|
|
|
|
|
29
|
|
|
/** @var \blitze\sitemaker\services\blocks\blocks */ |
|
30
|
|
|
protected $blocks; |
|
31
|
|
|
|
|
32
|
|
|
/** @var \blitze\sitemaker\services\blocks\factory */ |
|
33
|
|
|
protected $block_factory; |
|
34
|
|
|
|
|
35
|
|
|
/** @var \blitze\sitemaker\model\mapper_factory */ |
|
36
|
|
|
protected $mapper_factory; |
|
37
|
|
|
|
|
38
|
|
|
protected static $default_prefs = array( |
|
39
|
|
|
'hide_blocks' => false, |
|
40
|
|
|
'ex_positions' => array(), |
|
41
|
|
|
); |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* Constructor |
|
45
|
|
|
* |
|
46
|
|
|
* @param \phpbb\config\config $config Config object |
|
47
|
|
|
* @param ContainerInterface $phpbb_container Service container |
|
48
|
|
|
* @param \phpbb\request\request_interface $request Request object |
|
49
|
|
|
* @param \phpbb\user $user User object |
|
50
|
|
|
* @param \blitze\sitemaker\services\blocks\blocks $blocks Blocks object |
|
51
|
|
|
* @param \blitze\sitemaker\services\blocks\factory $block_factory Blocks factory object |
|
52
|
|
|
* @param \blitze\sitemaker\model\mapper_factory $mapper_factory Mapper factory object |
|
53
|
|
|
*/ |
|
54
|
42 |
|
public function __construct(\phpbb\config\config $config, ContainerInterface $phpbb_container, \phpbb\request\request_interface $request, \phpbb\user $user, \blitze\sitemaker\services\blocks\blocks $blocks, \blitze\sitemaker\services\blocks\factory $block_factory, \blitze\sitemaker\model\mapper_factory $mapper_factory) |
|
55
|
|
|
{ |
|
56
|
42 |
|
$this->config = $config; |
|
57
|
42 |
|
$this->phpbb_container = $phpbb_container; |
|
58
|
42 |
|
$this->request = $request; |
|
59
|
42 |
|
$this->user = $user; |
|
60
|
42 |
|
$this->blocks = $blocks; |
|
61
|
42 |
|
$this->block_factory = $block_factory; |
|
62
|
42 |
|
$this->mapper_factory = $mapper_factory; |
|
63
|
42 |
|
} |
|
64
|
|
|
|
|
65
|
8 |
|
protected function _force_get_route($route_data, $has_blocks = false) |
|
66
|
|
|
{ |
|
67
|
8 |
|
$route_mapper = $this->mapper_factory->create('blocks', 'routes'); |
|
68
|
|
|
|
|
69
|
8 |
|
if (($route = $route_mapper->load($this->get_condition($route_data))) === null) |
|
70
|
8 |
|
{ |
|
71
|
2 |
|
$route_data['ext_name'] = $this->request->variable('ext', ''); |
|
72
|
2 |
|
$route_data['has_blocks'] = $has_blocks; |
|
73
|
|
|
|
|
74
|
2 |
|
$entity = $route_mapper->create_entity($route_data); |
|
75
|
2 |
|
$route = $route_mapper->save($entity); |
|
76
|
2 |
|
} |
|
77
|
|
|
|
|
78
|
8 |
|
return $route; |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
11 |
|
protected function get_condition(array $info) |
|
82
|
|
|
{ |
|
83
|
|
|
return array( |
|
84
|
11 |
|
array('route', '=', $info['route']), |
|
85
|
11 |
|
array('style', '=', $info['style']), |
|
86
|
11 |
|
); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
14 |
|
protected function render_block(\blitze\sitemaker\model\blocks\entity\block $entity) |
|
90
|
|
|
{ |
|
91
|
14 |
|
$block_name = $entity->get_name(); |
|
92
|
14 |
|
if ($block_instance = $this->block_factory->get_block($block_name)) |
|
93
|
14 |
|
{ |
|
94
|
14 |
|
$default_settings = $block_instance->get_config(array()); |
|
95
|
14 |
|
$settings = $this->blocks->sync_settings($default_settings, $entity->get_settings()); |
|
96
|
14 |
|
$entity->set_settings($settings); |
|
97
|
|
|
|
|
98
|
14 |
|
$block_data = $entity->to_array(); |
|
99
|
14 |
|
$disp_data = $block_instance->display($block_data, true); |
|
100
|
|
|
|
|
101
|
14 |
|
return array_merge($block_data, array( |
|
102
|
14 |
|
'id' => $block_data['bid'], |
|
103
|
14 |
|
'title' => (!empty($block_data['title'])) ? $block_data['title'] : $this->user->lang($disp_data['title']), |
|
104
|
14 |
|
'content' => (!empty($disp_data['content'])) ? $disp_data['content'] : $this->user->lang('BLOCK_NO_DATA'), |
|
105
|
14 |
|
)); |
|
106
|
|
|
} |
|
107
|
1 |
|
} |
|
108
|
|
|
|
|
109
|
7 |
|
protected function _route_is_customized(array $route_prefs) |
|
110
|
|
|
{ |
|
111
|
7 |
|
$route_prefs = array_intersect_key($route_prefs, self::$default_prefs); |
|
112
|
7 |
|
return (self::$default_prefs !== $route_prefs) ? true : false; |
|
113
|
|
|
} |
|
114
|
|
|
} |
|
115
|
|
|
|