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\model\menus\entity; |
11
|
|
|
|
12
|
|
|
use blitze\sitemaker\model\base_entity; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* @method integer get_item_id() |
16
|
|
|
* @method object set_menu_id($menu_id) |
17
|
|
|
* @method integer get_menu_id() |
18
|
|
|
* @method object set_parent_id($parent_id) |
19
|
|
|
* @method integer get_parent_id() |
20
|
|
|
* @method string get_item_title() |
21
|
|
|
* @method string get_item_url() |
22
|
|
|
* @method string get_item_icon() |
23
|
|
|
* @method object set_item_target($item_target) |
24
|
|
|
* @method integer get_item_target() |
25
|
|
|
* @method object set_left_id($left_id) |
26
|
|
|
* @method integer get_left_id() |
27
|
|
|
* @method object set_right_id($right_id) |
28
|
|
|
* @method integer get_right_id() |
29
|
|
|
* @method object item_parents($item_parents) |
30
|
|
|
* @method integer get_item_parents() |
31
|
|
|
* @method object set_depth($depth) |
32
|
|
|
* @method integer get_depth() |
33
|
|
|
*/ |
34
|
|
|
final class item extends base_entity |
35
|
|
|
{ |
36
|
|
|
/** @var integer */ |
37
|
|
|
protected $item_id; |
38
|
|
|
|
39
|
|
|
/** @var integer */ |
40
|
|
|
protected $menu_id = 0; |
41
|
|
|
|
42
|
|
|
/** @var integer */ |
43
|
|
|
protected $parent_id = 0; |
44
|
|
|
|
45
|
|
|
/** @var string */ |
46
|
|
|
protected $item_title = ''; |
47
|
|
|
|
48
|
|
|
/** @var string */ |
49
|
|
|
protected $item_url = ''; |
50
|
|
|
|
51
|
|
|
/** @var string */ |
52
|
|
|
protected $item_icon = ''; |
53
|
|
|
|
54
|
|
|
/** @var integer */ |
55
|
|
|
protected $item_target = 0; |
56
|
|
|
|
57
|
|
|
/** @var integer */ |
58
|
|
|
protected $left_id = 0; |
59
|
|
|
|
60
|
|
|
/** @var integer */ |
61
|
|
|
protected $right_id = 0; |
62
|
|
|
|
63
|
|
|
/** @var string */ |
64
|
|
|
protected $item_parents = ''; |
65
|
|
|
|
66
|
|
|
/** @var integer */ |
67
|
|
|
protected $depth = 0; |
68
|
|
|
|
69
|
|
|
/** @var string */ |
70
|
|
|
protected $full_url = ''; |
71
|
|
|
|
72
|
|
|
/** @var string */ |
73
|
|
|
protected $board_url; |
74
|
|
|
|
75
|
|
|
/** @var boolean */ |
76
|
|
|
protected $mod_rewrite_enabled; |
77
|
|
|
|
78
|
|
|
/** @var array */ |
79
|
|
|
protected $required_fields = array('menu_id', 'item_title'); |
80
|
|
|
|
81
|
|
|
/** @var array */ |
82
|
|
|
protected $db_fields = array( |
83
|
|
|
'item_id', |
84
|
|
|
'menu_id', |
85
|
|
|
'parent_id', |
86
|
|
|
'item_title', |
87
|
|
|
'item_url', |
88
|
|
|
'item_icon', |
89
|
|
|
'item_target', |
90
|
|
|
'left_id', |
91
|
|
|
'right_id', |
92
|
|
|
'item_parents', |
93
|
|
|
'depth', |
94
|
|
|
); |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* Class constructor |
98
|
|
|
* @param array $data |
99
|
|
|
* @param bool $mod_rewrite_enabled |
100
|
|
|
*/ |
101
|
70 |
|
public function __construct(array $data, $mod_rewrite_enabled = false) |
102
|
|
|
{ |
103
|
70 |
|
$this->board_url = generate_board_url(); |
104
|
70 |
|
$this->mod_rewrite_enabled = $mod_rewrite_enabled; |
105
|
|
|
|
106
|
70 |
|
parent::__construct($data); |
107
|
70 |
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* Set block ID |
111
|
|
|
* @param int $item_id |
112
|
|
|
* @return $this |
113
|
|
|
*/ |
114
|
47 |
|
public function set_item_id($item_id) |
115
|
|
|
{ |
116
|
47 |
|
if (!$this->item_id) |
117
|
47 |
|
{ |
118
|
47 |
|
$this->item_id = (int) $item_id; |
119
|
47 |
|
} |
120
|
47 |
|
return $this; |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* @param string $item_title |
125
|
|
|
* @return $this |
126
|
|
|
*/ |
127
|
47 |
|
public function set_item_title($item_title) |
128
|
|
|
{ |
129
|
47 |
|
$this->item_title = utf8_ucfirst(trim($item_title)); |
130
|
47 |
|
return $this; |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* @param string $icon |
135
|
|
|
* @return $this |
136
|
|
|
*/ |
137
|
45 |
|
public function set_item_icon($icon) |
138
|
|
|
{ |
139
|
45 |
|
$this->item_icon = ($icon) ? trim($icon) . ' ' : ''; |
140
|
45 |
|
return $this; |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* @param string $item_url |
145
|
|
|
* @return $this |
146
|
|
|
*/ |
147
|
57 |
|
public function set_item_url($item_url) |
148
|
|
|
{ |
149
|
57 |
|
$search = array('&', $this->board_url); |
150
|
57 |
|
$replace = array('&', ''); |
151
|
57 |
|
$this->item_url = ltrim(str_replace($search, $replace, $item_url), './'); |
152
|
|
|
|
153
|
|
|
// add leading / for local paths, except leading hashtags |
154
|
57 |
|
if ($this->item_url && $this->item_url[0] !== '#' && $this->is_local_path($this->item_url)) |
155
|
57 |
|
{ |
156
|
30 |
|
$this->item_url = '/' . $this->item_url; |
157
|
30 |
|
} |
158
|
|
|
|
159
|
57 |
|
return $this; |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
/** |
163
|
|
|
* @return string |
164
|
|
|
*/ |
165
|
40 |
|
public function get_full_url() |
166
|
|
|
{ |
167
|
40 |
|
$item_url = $this->item_url; |
168
|
|
|
|
169
|
40 |
|
if ($item_url && $item_url[0] === '/') |
170
|
40 |
|
{ |
171
|
29 |
|
$item_url = $this->board_url . $item_url; |
172
|
29 |
|
if ($this->mod_rewrite_enabled) |
173
|
29 |
|
{ |
174
|
4 |
|
$item_url = str_replace('app.php/', '', $item_url); |
175
|
4 |
|
} |
176
|
29 |
|
} |
177
|
|
|
|
178
|
40 |
|
return $item_url; |
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
/** |
182
|
|
|
* Checks if a url is in local path |
183
|
|
|
* We already stripped out the board url so if it has a host, it is a remote url |
184
|
|
|
* |
185
|
|
|
* @param string $item_url |
186
|
|
|
* @return true|false |
187
|
|
|
*/ |
188
|
32 |
|
private function is_local_path($item_url) |
189
|
|
|
{ |
190
|
32 |
|
$host = parse_url($item_url, PHP_URL_HOST); |
191
|
|
|
|
192
|
32 |
|
return ($host) ? false : true; |
193
|
|
|
} |
194
|
|
|
} |
195
|
|
|
|