|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* |
|
4
|
|
|
* phpBB Directory extension for the phpBB Forum Software package. |
|
5
|
|
|
* |
|
6
|
|
|
* @copyright (c) 2014 ErnadoO <http://www.phpbb-services.com> |
|
7
|
|
|
* @license GNU General Public License, version 2 (GPL-2.0) |
|
8
|
|
|
* |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace ernadoo\phpbbdirectory\core; |
|
12
|
|
|
|
|
13
|
|
|
abstract class helper |
|
14
|
|
|
{ |
|
15
|
|
|
/** @var \phpbb\extension\manager */ |
|
16
|
|
|
private $extension_manager; |
|
17
|
|
|
|
|
18
|
|
|
/** @var \phpbb\path_helper */ |
|
19
|
|
|
private $path_helper; |
|
20
|
|
|
|
|
21
|
|
|
/** @var string */ |
|
22
|
|
|
public $categories_table; |
|
23
|
|
|
|
|
24
|
|
|
/** @var string */ |
|
25
|
|
|
public $comments_table; |
|
26
|
|
|
|
|
27
|
|
|
/** @var string */ |
|
28
|
|
|
public $links_table; |
|
29
|
|
|
|
|
30
|
|
|
/** @var string */ |
|
31
|
|
|
public $votes_table; |
|
32
|
|
|
|
|
33
|
|
|
/** @var string */ |
|
34
|
|
|
public $watch_table; |
|
35
|
|
|
|
|
36
|
|
|
/** @var string */ |
|
37
|
|
|
private $ext_name = 'ernadoo/phpbbdirectory'; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* Set the extension manager |
|
41
|
|
|
* |
|
42
|
|
|
* @param \phpbb\extension\manager $phpbb_extension_manager |
|
43
|
|
|
* @return null |
|
44
|
|
|
*/ |
|
45
|
|
|
public function set_extension_manager(\phpbb\extension\manager $phpbb_extension_manager) |
|
46
|
|
|
{ |
|
47
|
|
|
$this->extension_manager = $phpbb_extension_manager; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* Set the path helper |
|
52
|
|
|
* |
|
53
|
|
|
* @param \phpbb\path_helper $path_helper |
|
54
|
|
|
* @return null |
|
55
|
|
|
*/ |
|
56
|
|
|
public function set_path_helper(\phpbb\path_helper $path_helper) |
|
57
|
|
|
{ |
|
58
|
|
|
$this->path_helper = $path_helper; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* Set the tables names |
|
63
|
|
|
* |
|
64
|
|
|
* @param string $categories_table |
|
65
|
|
|
* @param string $comments_table |
|
66
|
|
|
* @param string $links_table |
|
67
|
|
|
* @param string $votes_table |
|
68
|
|
|
* @param string $watch_table |
|
69
|
|
|
* @return null |
|
70
|
|
|
*/ |
|
71
|
|
|
public function set_tables($categories_table, $comments_table, $links_table, $votes_table, $watch_table) |
|
72
|
|
|
{ |
|
73
|
|
|
$this->comments_table = $comments_table; |
|
74
|
|
|
$this->links_table = $links_table; |
|
75
|
|
|
$this->votes_table = $votes_table; |
|
76
|
|
|
$this->watch_table = $watch_table; |
|
77
|
|
|
$this->categories_table = $categories_table; |
|
78
|
|
|
} |
|
79
|
|
|
/** |
|
80
|
|
|
* Return ext name |
|
81
|
|
|
* |
|
82
|
|
|
* @param bool $web_root_path Whether the path should be relative to web root |
|
83
|
|
|
* @return string Path to an extension |
|
84
|
|
|
*/ |
|
85
|
|
|
public function get_ext_name($web_root_path = false) |
|
86
|
|
|
{ |
|
87
|
|
|
return (($web_root_path) ? $this->path_helper->get_web_root_path() : '') . $this->extension_manager->get_extension_path($this->ext_name); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* Return path to resource image |
|
92
|
|
|
* |
|
93
|
|
|
* @param string $type is ressource type (flags|icons) |
|
94
|
|
|
* @param string $image is the resource to display |
|
95
|
|
|
* @return string The relative path to ressource |
|
96
|
|
|
*/ |
|
97
|
|
|
public function get_img_path($type, $image = '') |
|
98
|
|
|
{ |
|
99
|
|
|
return $this->get_ext_name(true) . 'images/' . $type . '/' . $image; |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
/** |
|
103
|
|
|
* Return path to banner |
|
104
|
|
|
* |
|
105
|
|
|
* @param string $banner is the physical name |
|
106
|
|
|
* @return string The relative path to banner |
|
107
|
|
|
*/ |
|
108
|
|
|
public function get_banner_path($banner = '') |
|
109
|
|
|
{ |
|
110
|
|
|
return 'files/' . $this->get_ext_name() . 'banners/' . $banner; |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
/** |
|
114
|
|
|
* Return array entries that match the pattern |
|
115
|
|
|
* |
|
116
|
|
|
* @link http://php.net/manual/fr/function.preg-grep.php#95787 |
|
117
|
|
|
* |
|
118
|
|
|
* @param string $pattern The pattern to search for |
|
119
|
|
|
* @param array $input The input array |
|
120
|
|
|
* @return array $vals Returns an array indexed using the keys from the input array |
|
121
|
|
|
*/ |
|
122
|
|
|
public function preg_grep_keys($pattern, $input) |
|
123
|
|
|
{ |
|
124
|
|
|
$keys = preg_grep($pattern, array_keys($input)); |
|
125
|
|
|
$vals = array(); |
|
126
|
|
|
foreach ($keys as $key) |
|
127
|
|
|
{ |
|
128
|
|
|
$vals[$key] = $input[$key]; |
|
129
|
|
|
} |
|
130
|
|
|
return $vals; |
|
131
|
|
|
} |
|
132
|
|
|
} |
|
133
|
|
|
|