1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* |
5
|
|
|
* @package sitemaker |
6
|
|
|
* @copyright (c) 2013 Daniel A. (blitze) |
7
|
|
|
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 |
8
|
|
|
* |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace blitze\sitemaker\services; |
12
|
|
|
|
13
|
|
|
class util |
14
|
|
|
{ |
15
|
|
|
/** @var \phpbb\path_helper */ |
16
|
|
|
protected $path_helper; |
17
|
|
|
|
18
|
|
|
/** @var \phpbb\template\template */ |
19
|
|
|
protected $template; |
20
|
|
|
|
21
|
|
|
/** @var \phpbb\user */ |
22
|
|
|
protected $user; |
23
|
|
|
|
24
|
|
|
/** string */ |
25
|
|
|
protected $web_path; |
26
|
|
|
|
27
|
|
|
/** array */ |
28
|
|
|
protected $assets; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Constructor |
32
|
|
|
* |
33
|
|
|
* @param \phpbb\path_helper $path_helper Path helper object |
34
|
|
|
* @param \phpbb\template\template $template Template object |
35
|
|
|
* @param \phpbb\user $user User object |
36
|
101 |
|
*/ |
37
|
|
|
public function __construct(\phpbb\path_helper $path_helper, \phpbb\template\template $template, \phpbb\user $user) |
38
|
101 |
|
{ |
39
|
101 |
|
$this->path_helper = $path_helper; |
40
|
101 |
|
$this->template = $template; |
41
|
|
|
$this->user = $user; |
42
|
101 |
|
|
43
|
101 |
|
$this->reset(); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* include css/javascript |
48
|
|
|
* @param array $assets array of form array('js' => array('test.js', 'test2.js'), 'css' => array()) |
49
|
|
|
* @return void |
50
|
2 |
|
*/ |
51
|
|
|
public function add_assets(array $assets) |
52
|
2 |
|
{ |
53
|
|
|
foreach ($assets as $type => $scripts) |
54
|
1 |
|
{ |
55
|
|
|
foreach ($scripts as $order => $script) |
56
|
1 |
|
{ |
57
|
1 |
|
if (!isset($this->assets[$type][$script]) || $this->assets[$type][$script] < $order) |
58
|
1 |
|
{ |
59
|
1 |
|
$this->assets[$type][$script] = $order; |
60
|
1 |
|
} |
61
|
2 |
|
} |
62
|
2 |
|
} |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Pass assets to template |
67
|
2 |
|
*/ |
68
|
|
|
public function set_assets() |
69
|
2 |
|
{ |
70
|
2 |
|
uasort($this->assets['js'], array($this, 'sort_assets')); |
71
|
|
|
uasort($this->assets['css'], array($this, 'sort_assets')); |
72
|
2 |
|
|
73
|
2 |
|
$this->template->assign_var('assets', array( |
74
|
2 |
|
'css' => array_keys($this->assets['css']), |
75
|
2 |
|
'js' => array_keys($this->assets['js']), |
76
|
|
|
)); |
77
|
2 |
|
|
78
|
2 |
|
$this->reset(); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Add a secret token to the form |
83
|
|
|
* @param string $form_name The name of the form; has to match the name used in check_form_key, otherwise no restrictions apply |
84
|
1 |
|
* @param string $template_variable_suffix A string that is appended to the name of the template variable to which the form elements are assigned |
85
|
|
|
* @return string |
86
|
1 |
|
*/ |
87
|
|
|
public function get_form_key($form_name, $template_variable_suffix = '_BLITZE_SITEMAKER') |
88
|
1 |
|
{ |
89
|
|
|
add_form_key($form_name, $template_variable_suffix); |
90
|
|
|
|
91
|
|
|
return $this->template->retrieve_var('S_FORM_TOKEN' . $template_variable_suffix); |
92
|
|
|
} |
93
|
|
|
|
94
|
15 |
|
/** |
95
|
|
|
* @return string |
96
|
15 |
|
*/ |
97
|
|
|
public function get_default_avatar() |
98
|
|
|
{ |
99
|
|
|
return '<img src="' . $this->get_theme_path() . '/images/no_avatar.gif" alt="" />'; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
15 |
|
* Returns a corrected theme path depending on whether or not we are accessing a controller |
104
|
|
|
* @return string |
105
|
15 |
|
*/ |
106
|
15 |
|
public function get_theme_path() |
107
|
|
|
{ |
108
|
|
|
$web_path = $this->get_web_path(); |
109
|
|
|
return "{$web_path}styles/" . rawurlencode($this->user->style['style_path']) . '/theme'; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
15 |
|
* Returns a corrected root path depending on whether or not we are accessing a controller |
114
|
|
|
* @return string |
115
|
|
|
*/ |
116
|
15 |
|
public function get_web_path() |
117
|
|
|
{ |
118
|
15 |
|
// Determine board url - we may need it later |
119
|
15 |
|
$board_url = generate_board_url() . '/'; |
120
|
|
|
|
121
|
|
|
$corrected_path = $this->path_helper->get_web_root_path(); |
122
|
|
|
return (defined('PHPBB_USE_BOARD_URL_PATH') && PHPBB_USE_BOARD_URL_PATH) ? $board_url : $corrected_path; |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* @param int $a |
127
|
1 |
|
* @param int $b |
128
|
|
|
* @return int |
129
|
1 |
|
*/ |
130
|
1 |
|
protected function sort_assets($a, $b) |
131
|
|
|
{ |
132
|
|
|
return ($a < $b) ? -1 : 1; |
133
|
|
|
} |
134
|
1 |
|
|
135
|
|
|
/** |
136
|
|
|
* @return void |
137
|
|
|
*/ |
138
|
|
|
protected function reset() |
139
|
|
|
{ |
140
|
101 |
|
$this->assets = array( |
141
|
|
|
'js' => array(), |
142
|
101 |
|
'css' => array(), |
143
|
101 |
|
); |
144
|
101 |
|
} |
145
|
|
|
} |
146
|
|
|
|