1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Class: WflLists |
5
|
|
|
* |
6
|
|
|
* Module: WF-Links |
7
|
|
|
* Version: v1.0.3 |
8
|
|
|
* Release Date: 21 June 2005 |
9
|
|
|
* Developer: John N |
10
|
|
|
* Team: WF-Projects |
11
|
|
|
* Licence: GNU |
12
|
|
|
*/ |
13
|
|
|
class WflLists |
|
|
|
|
14
|
|
|
{ |
15
|
|
|
public $value; |
16
|
|
|
public $selected; |
17
|
|
|
public $path = 'uploads'; |
18
|
|
|
public $size; |
19
|
|
|
public $emptyselect; |
20
|
|
|
public $type; |
21
|
|
|
public $prefix; |
22
|
|
|
public $suffix; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @param string $path |
26
|
|
|
* @param null $value |
27
|
|
|
* @param string $selected |
28
|
|
|
* @param int $size |
29
|
|
|
* @param int $emptyselect |
30
|
|
|
* @param int $type |
31
|
|
|
* @param string $prefix |
32
|
|
|
* @param string $suffix |
33
|
|
|
*/ |
34
|
|
|
public function __construct( |
35
|
|
|
$path = 'uploads', |
36
|
|
|
$value = null, |
37
|
|
|
$selected = '', |
38
|
|
|
$size = 1, |
39
|
|
|
$emptyselect = 0, |
40
|
|
|
$type = 0, |
41
|
|
|
$prefix = '', |
|
|
|
|
42
|
|
|
$suffix = '') |
|
|
|
|
43
|
|
|
{ |
44
|
|
|
$this->value = $value; |
45
|
|
|
$this->selection = $selected; |
|
|
|
|
46
|
|
|
$this->path = $path; |
47
|
|
|
$this->size = (int)$size; |
48
|
|
|
$this->emptyselect = $emptyselect ? 0 : 1; |
49
|
|
|
$this->type = $type; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @param array $this_array |
54
|
|
|
* |
55
|
|
|
* @return string |
56
|
|
|
*/ |
57
|
|
|
public function getarray($this_array) |
58
|
|
|
{ |
59
|
|
|
$ret = "<select size='" . $this->getSize() . "' name='$this->getValue()'>"; |
|
|
|
|
60
|
|
|
if ($this->emptyselect) { |
61
|
|
|
$ret .= "<option value='" . $this->getValue() . "'>----------------------</option>"; |
62
|
|
|
} |
63
|
|
|
foreach ($this_array as $content) { |
64
|
|
|
$opt_selected = ''; |
65
|
|
|
|
66
|
|
|
if ($content[0] == $this->getSelected()) { |
67
|
|
|
$opt_selected = 'selected'; |
68
|
|
|
} |
69
|
|
|
$ret .= "<option value='" . $content . "' $opt_selected>" . $content . '</option>'; |
70
|
|
|
} |
71
|
|
|
$ret .= '</select>'; |
72
|
|
|
|
73
|
|
|
return $ret; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Private to be called by other parts of the class |
78
|
|
|
* @param $dirname |
79
|
|
|
* @return array |
80
|
|
|
*/ |
81
|
|
|
public function getDirListAsArray($dirname) |
82
|
|
|
{ |
83
|
|
|
$dirlist = array(); |
84
|
|
|
if (is_dir($dirname) && $handle = opendir($dirname)) { |
85
|
|
|
while (false !== ($file = readdir($handle))) { |
86
|
|
|
if (!preg_match('/^[.]{1,2}$/', $file)) { |
87
|
|
|
if (strtolower($file) !== 'cvs' && is_dir($dirname . $file)) { |
88
|
|
|
$dirlist[$file] = $file; |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
closedir($handle); |
93
|
|
|
|
94
|
|
|
reset($dirlist); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
return $dirlist; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* @param $dirname |
102
|
|
|
* @param string $type |
103
|
|
|
* @param string $prefix |
104
|
|
|
* @param int $noselection |
105
|
|
|
* |
106
|
|
|
* @return array |
107
|
|
|
*/ |
108
|
|
|
public static function getListTypeAsArray($dirname, $type = '', $prefix = '', $noselection = 1) |
109
|
|
|
{ |
110
|
|
|
$filelist = array(); |
111
|
|
|
switch (trim($type)) { |
112
|
|
|
case 'images': |
113
|
|
|
$types = '[.gif|.jpg|.png]'; |
114
|
|
|
if ($noselection) { |
115
|
|
|
$filelist[''] = _AM_WFL_SHOWNOIMAGE; |
116
|
|
|
} |
117
|
|
|
break; |
118
|
|
|
case 'html': |
119
|
|
|
$types = '[.htm|.html|.xhtml|.php|.php3|.phtml|.txt]'; |
120
|
|
|
if ($noselection) { |
121
|
|
|
$filelist[''] = 'No Selection'; |
122
|
|
|
} |
123
|
|
|
break; |
124
|
|
|
default: |
125
|
|
|
$types = ''; |
126
|
|
|
if ($noselection) { |
127
|
|
|
$filelist[''] = 'No Selected File'; |
128
|
|
|
} |
129
|
|
|
break; |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
if (substr($dirname, -1) === '/') { |
133
|
|
|
$dirname = substr($dirname, 0, -1); |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
if (is_dir($dirname) && $handle = opendir($dirname)) { |
137
|
|
|
while (false !== ($file = readdir($handle))) { |
138
|
|
|
if (!preg_match('/^[.]{1,2}$/', $file) && preg_match("/$types$/i", $file) |
139
|
|
|
&& is_file($dirname . '/' . $file)) { |
140
|
|
|
if (strtolower($file) === 'blank.gif') { |
141
|
|
|
continue; |
142
|
|
|
} |
143
|
|
|
$file = $prefix . $file; |
144
|
|
|
$filelist[$file] = $file; |
145
|
|
|
} |
146
|
|
|
} |
147
|
|
|
closedir($handle); |
148
|
|
|
asort($filelist); |
149
|
|
|
reset($filelist); |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
return $filelist; |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
/** |
156
|
|
|
* @param int $type |
157
|
|
|
* @param $selected |
158
|
|
|
* |
159
|
|
|
* @return mixed |
160
|
|
|
*/ |
161
|
|
|
public static function getForum($type = 1, $selected) |
162
|
|
|
{ |
163
|
|
|
global $xoopsDB; |
|
|
|
|
164
|
|
|
switch (xoops_trim($type)) { |
165
|
|
|
case 2: |
166
|
|
|
$sql = 'SELECT id, name FROM ' . $xoopsDB->prefix('ibf_forums') . ' ORDER BY id'; |
167
|
|
|
break; |
168
|
|
|
case 3: |
169
|
|
|
$sql = 'SELECT forum_id, forum_name FROM ' . $xoopsDB->prefix('pbb_forums') . ' ORDER BY forum_id'; |
170
|
|
|
break; |
171
|
|
|
case 4: |
172
|
|
|
$sql = 'SELECT forum_id, forum_name FROM ' . $xoopsDB->prefix('bbex_forums') . ' ORDER BY forum_id'; |
173
|
|
|
break; |
174
|
|
|
case 1: |
175
|
|
|
case 0: |
176
|
|
|
default: |
177
|
|
|
$sql = 'SELECT forum_id, forum_name FROM ' . $xoopsDB->prefix('newbb_forums') . ' ORDER BY forum_id'; |
178
|
|
|
break; |
179
|
|
|
} |
180
|
|
|
$result = $xoopsDB->query($sql); |
181
|
|
|
|
182
|
|
|
$noforum = defined('_WFL_NO_FORUM') ? _WFL_NO_FORUM : _AM_WFL_NO_FORUM; |
183
|
|
|
|
184
|
|
|
echo "<select size='1' name='forumid'>"; |
185
|
|
|
echo "<option value='0'>" . $noforum . '</option>'; |
186
|
|
View Code Duplication |
while (list($forum_id, $forum_name) = $xoopsDB->fetchRow($result)) { |
|
|
|
|
187
|
|
|
$opt_selected = ''; |
188
|
|
|
if ($forum_id == $selected) { |
189
|
|
|
$opt_selected = 'selected'; |
190
|
|
|
} |
191
|
|
|
echo "<option value='" . $forum_id . "' $opt_selected>" . $forum_name . '</option>'; |
192
|
|
|
} |
193
|
|
|
echo '</select>'; |
194
|
|
|
|
195
|
|
|
return $forum_array; |
|
|
|
|
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
/** |
199
|
|
|
* @return null |
200
|
|
|
*/ |
201
|
|
|
public function getValue() |
202
|
|
|
{ |
203
|
|
|
return $this->value; |
204
|
|
|
} |
205
|
|
|
|
206
|
|
|
public function getSelected() |
|
|
|
|
207
|
|
|
{ |
208
|
|
|
return $this->selected; |
209
|
|
|
} |
210
|
|
|
|
211
|
|
|
/** |
212
|
|
|
* @return string |
213
|
|
|
*/ |
214
|
|
|
public function getPath() |
215
|
|
|
{ |
216
|
|
|
return $this->path; |
217
|
|
|
} |
218
|
|
|
|
219
|
|
|
/** |
220
|
|
|
* @return int |
221
|
|
|
*/ |
222
|
|
|
public function getSize() |
223
|
|
|
{ |
224
|
|
|
return $this->size; |
225
|
|
|
} |
226
|
|
|
|
227
|
|
|
/** |
228
|
|
|
* @return int |
229
|
|
|
*/ |
230
|
|
|
public function getEmptySelect() |
231
|
|
|
{ |
232
|
|
|
return $this->emptyselect; |
233
|
|
|
} |
234
|
|
|
|
235
|
|
|
/** |
236
|
|
|
* @return int |
237
|
|
|
*/ |
238
|
|
|
public function getType() |
239
|
|
|
{ |
240
|
|
|
return $this->type; |
241
|
|
|
} |
242
|
|
|
|
243
|
|
|
public function getPrefix() |
|
|
|
|
244
|
|
|
{ |
245
|
|
|
return $this->prefix; |
246
|
|
|
} |
247
|
|
|
|
248
|
|
|
public function getSuffix() |
|
|
|
|
249
|
|
|
{ |
250
|
|
|
return $this->suffix; |
251
|
|
|
} |
252
|
|
|
} |
253
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.