|
1
|
|
|
<?php |
|
|
|
|
|
|
2
|
|
|
// $Id: comment.php 506 2006-05-26 23:10:37Z skalpa $ |
|
3
|
|
|
// ------------------------------------------------------------------------ // |
|
4
|
|
|
// XOOPS - PHP Content Management System // |
|
5
|
|
|
// Copyright (c) 2000 XOOPS.org // |
|
6
|
|
|
// <http://www.xoops.org/> // |
|
7
|
|
|
// ------------------------------------------------------------------------ // |
|
8
|
|
|
// This program is free software; you can redistribute it and/or modify // |
|
9
|
|
|
// it under the terms of the GNU General Public License as published by // |
|
10
|
|
|
// the Free Software Foundation; either version 2 of the License, or // |
|
11
|
|
|
// (at your option) any later version. // |
|
12
|
|
|
// // |
|
13
|
|
|
// You may not change or alter any portion of this comment or credits // |
|
14
|
|
|
// of supporting developers from this source code or any supporting // |
|
15
|
|
|
// source code which is considered copyrighted (c) material of the // |
|
16
|
|
|
// original comment or credit authors. // |
|
17
|
|
|
// // |
|
18
|
|
|
// This program is distributed in the hope that it will be useful, // |
|
19
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of // |
|
20
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // |
|
21
|
|
|
// GNU General Public License for more details. // |
|
22
|
|
|
// // |
|
23
|
|
|
// You should have received a copy of the GNU General Public License // |
|
24
|
|
|
// along with this program; if not, write to the Free Software // |
|
25
|
|
|
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // |
|
26
|
|
|
// ------------------------------------------------------------------------ // |
|
27
|
|
|
/** |
|
28
|
|
|
* XOOPS - PHP Content Management System |
|
29
|
|
|
* Copyright (c) 2001 - 2006 <http://www.xoops.org/> |
|
30
|
|
|
* |
|
31
|
|
|
* Module: class.mimetypes 1.0 |
|
32
|
|
|
* Licence : GPL |
|
33
|
|
|
* Authors : |
|
34
|
|
|
* - DuGris (http://www.dugris.info) |
|
35
|
|
|
*/ |
|
36
|
|
|
|
|
37
|
|
|
if (!defined('XOOPS_ROOT_PATH')) { die('XOOPS root path not defined'); } |
|
38
|
|
|
|
|
39
|
|
|
include_once( XOOPS_ROOT_PATH . '/class/xoopsobject.php' ); |
|
40
|
|
|
|
|
41
|
|
|
|
|
42
|
|
|
class XoopsMimetypes extends XoopsObject { |
|
|
|
|
|
|
43
|
|
|
var $db; |
|
|
|
|
|
|
44
|
|
|
|
|
45
|
|
|
// constructor |
|
46
|
|
|
function xoopsmimetypes ($mime_id=null) { |
|
|
|
|
|
|
47
|
|
|
$this->db = Database::getInstance(); |
|
48
|
|
|
$this->initVar('mime_id',XOBJ_DTYPE_INT,0,true,11); |
|
49
|
|
|
$this->initVar('mime_ext',XOBJ_DTYPE_TXTBOX,'',true,10); |
|
50
|
|
|
$this->initVar('mime_types',XOBJ_DTYPE_TXTAREA,'',true,0); |
|
51
|
|
|
$this->initVar('mime_name',XOBJ_DTYPE_TXTBOX,'',true,255); |
|
52
|
|
|
$this->initVar('mime_status',XOBJ_DTYPE_INT,0,true,1); |
|
53
|
|
|
|
|
54
|
|
|
if ( !empty($mime_id) ) { |
|
55
|
|
|
if ( is_array($mime_id) ) { |
|
56
|
|
|
$this->assignVars($mime_id); |
|
57
|
|
|
} else { |
|
58
|
|
|
$this->load($mime_id); |
|
59
|
|
|
} |
|
60
|
|
|
} else { |
|
61
|
|
|
$this->setNew(); |
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
View Code Duplication |
function load($mime_id) { |
|
|
|
|
|
|
66
|
|
|
$sql = 'SELECT * FROM '.$this->db->prefix('mimetypes').' WHERE mime_id='.$mime_id; |
|
67
|
|
|
$myrow = $this->db->fetchArray($this->db->query($sql)); |
|
68
|
|
|
$this->assignVars($myrow); |
|
69
|
|
|
if (!$myrow) { |
|
70
|
|
|
$this->setNew(); |
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
View Code Duplication |
function load_byExt($mime_ext) { |
|
|
|
|
|
|
75
|
|
|
$sql = 'SELECT * FROM '.$this->db->prefix('mimetypes').' WHERE mime_ext=' . $this->db->quoteString($mime_ext); |
|
76
|
|
|
$myrow = $this->db->fetchArray($this->db->query($sql)); |
|
77
|
|
|
$this->assignVars($myrow); |
|
78
|
|
|
if (!$myrow) { |
|
79
|
|
|
$this->setNew(); |
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
function mime_id() { |
|
|
|
|
|
|
84
|
|
|
return $this->getVar('mime_id'); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
View Code Duplication |
function mime_ext($format='S') { |
|
|
|
|
|
|
88
|
|
|
$ret = $this->getVar('mime_ext', $format); |
|
89
|
|
|
if (($format=='s') || ($format=='S') || ($format=='show')) { |
|
90
|
|
|
$myts = &MyTextSanitizer::getInstance(); |
|
91
|
|
|
$ret = $myts->displayTarea($ret); |
|
92
|
|
|
} |
|
93
|
|
|
return $ret; |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
View Code Duplication |
function mime_types($format='S') { |
|
|
|
|
|
|
97
|
|
|
$ret = $this->getVar('mime_types', $format); |
|
98
|
|
|
if (($format=='s') || ($format=='S') || ($format=='show')) { |
|
99
|
|
|
$myts = &MyTextSanitizer::getInstance(); |
|
100
|
|
|
$ret = $myts->displayTarea($ret); |
|
101
|
|
|
} |
|
102
|
|
|
return $ret; |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
View Code Duplication |
function mime_name($format='S') { |
|
|
|
|
|
|
106
|
|
|
$ret = $this->getVar('mime_name', $format); |
|
107
|
|
|
if (($format=='s') || ($format=='S') || ($format=='show')) { |
|
108
|
|
|
$myts = &MyTextSanitizer::getInstance(); |
|
109
|
|
|
$ret = $myts->displayTarea($ret); |
|
110
|
|
|
} |
|
111
|
|
|
return $ret; |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
function mime_status() { |
|
|
|
|
|
|
115
|
|
|
return $this->getVar('mime_status'); |
|
116
|
|
|
} |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
class XoopsMimetypesHandler extends XoopsObjectHandler { |
|
|
|
|
|
|
120
|
|
|
|
|
121
|
|
|
function &create($isNew = true) { |
|
122
|
|
|
$tplfile = new XoopsTplfile(); |
|
123
|
|
|
if ($isNew) { |
|
124
|
|
|
$tplfile->setNew(); |
|
125
|
|
|
} |
|
126
|
|
|
return $tplfile; |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
View Code Duplication |
function get_byExt( $mime_ext, $asobject=true ) { |
|
|
|
|
|
|
130
|
|
|
$ret = array(); |
|
131
|
|
|
$sql = 'SELECT * FROM ' . $this->db->prefix('mimetypes') . ' WHERE mime_ext = ' . $this->db->quoteString($mime_ext); |
|
132
|
|
|
|
|
133
|
|
|
$result = $this->db->query($sql); |
|
134
|
|
|
if (!$result) { |
|
135
|
|
|
return $ret; |
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
|
|
while ( $myrow = $this->db->fetchArray($result) ) { |
|
139
|
|
|
if ( !$asobject ) { |
|
140
|
|
|
$ret[$myrow['mime_id']] = $myrow; |
|
141
|
|
|
} else { |
|
142
|
|
|
$ret[] = new xoopsmimetypes( $myrow ); |
|
143
|
|
|
} |
|
144
|
|
|
} |
|
145
|
|
|
return $ret; |
|
146
|
|
|
} |
|
147
|
|
|
|
|
148
|
|
|
function get_mimetypes($limit=20, $start=0, $status=-1, $OtherCriteria=null, $sort='mime_ext', $order='ASC', $asobject=true) { |
|
|
|
|
|
|
149
|
|
|
$ret = array(); |
|
150
|
|
|
$criteria = new CriteriaCompo(); |
|
151
|
|
|
|
|
152
|
|
|
if ( is_object($OtherCriteria) ) { |
|
153
|
|
|
$criteria->add($OtherCriteria, 'AND'); |
|
154
|
|
|
} |
|
155
|
|
|
|
|
156
|
|
View Code Duplication |
if ( isset($status) && (is_array($status)) ) { |
|
|
|
|
|
|
157
|
|
|
foreach ($status as $v) { |
|
158
|
|
|
$criteria->add(new Criteria('mime_status', $v), 'AND'); |
|
159
|
|
|
} |
|
160
|
|
|
} elseif ( isset($status) && ($status != -1) ) { |
|
161
|
|
|
$criteria->add(new Criteria('mime_status', $status), 'AND'); |
|
162
|
|
|
} |
|
163
|
|
|
|
|
164
|
|
|
$criteria->setLimit($limit); |
|
165
|
|
|
$criteria->setStart($start); |
|
166
|
|
|
$criteria->setSort($sort); |
|
167
|
|
|
$criteria->setOrder($order); |
|
168
|
|
|
|
|
169
|
|
|
$sql = 'SELECT * FROM '.$this->db->prefix('mimetypes'); |
|
170
|
|
View Code Duplication |
if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
|
|
|
|
|
|
171
|
|
|
$sql .= ' '.$criteria->renderWhere(); |
|
172
|
|
|
if ($criteria->getSort() != '') { |
|
173
|
|
|
$sql .= ' ORDER BY '.$criteria->getSort().' '.$criteria->getOrder(); |
|
174
|
|
|
} |
|
175
|
|
|
|
|
176
|
|
|
$limit = $criteria->getLimit(); |
|
177
|
|
|
$start = $criteria->getStart(); |
|
178
|
|
|
} |
|
179
|
|
|
|
|
180
|
|
|
$result = $this->db->query($sql, $limit, $start); |
|
181
|
|
|
if (!$result) { |
|
182
|
|
|
return $ret; |
|
183
|
|
|
} |
|
184
|
|
|
|
|
185
|
|
|
while ( $myrow = $this->db->fetchArray($result) ) { |
|
186
|
|
|
if ( !$asobject ) { |
|
187
|
|
|
$ret[$myrow['mime_id']] = $myrow; |
|
188
|
|
|
} else { |
|
189
|
|
|
$ret[] = new xoopsmimetypes( $myrow ); |
|
190
|
|
|
} |
|
191
|
|
|
} |
|
192
|
|
|
return $ret; |
|
193
|
|
|
} |
|
194
|
|
|
|
|
195
|
|
|
function getCount($criteria = null, $notNullFields='') { |
|
|
|
|
|
|
196
|
|
|
$sql = 'SELECT COUNT(*) FROM '.$this->db->prefix('mimetypes'); |
|
197
|
|
View Code Duplication |
if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
|
|
|
|
|
|
198
|
|
|
$whereClause = $criteria->renderWhere(); |
|
199
|
|
|
if ($whereClause != 'WHERE ()') { |
|
200
|
|
|
$sql .= ' '.$criteria->renderWhere(); |
|
201
|
|
|
} |
|
202
|
|
|
} |
|
203
|
|
|
$result = $this->db->query($sql); |
|
204
|
|
|
if (!$result) { |
|
205
|
|
|
return 0; |
|
206
|
|
|
} |
|
207
|
|
|
list($count) = $this->db->fetchRow($result); |
|
208
|
|
|
return $count; |
|
209
|
|
|
} |
|
210
|
|
|
|
|
211
|
|
|
function insert(&$mimetype_object, $force = false) { |
|
|
|
|
|
|
212
|
|
|
if (strtolower(get_class($mimetype_object)) != 'xoopsmimetypes') { |
|
213
|
|
|
return false; |
|
214
|
|
|
} |
|
215
|
|
|
if (!$mimetype_object->isDirty()) { |
|
216
|
|
|
return true; |
|
217
|
|
|
} |
|
218
|
|
|
if (!$mimetype_object->cleanVars()) { |
|
219
|
|
|
return false; |
|
220
|
|
|
} |
|
221
|
|
|
foreach ($mimetype_object->cleanVars as $k => $v) { |
|
222
|
|
|
${$k} = $v; |
|
223
|
|
|
} |
|
224
|
|
|
if ($mimetype_object->isNew()) { |
|
225
|
|
|
$mimetype_object = new xoopsmimetypes(); |
|
226
|
|
|
$format = "INSERT INTO %s (mime_id, mime_ext, mime_types, mime_name, mime_status)"; |
|
227
|
|
|
$format .= "VALUES (%u, %s, %s, %s, %u)"; |
|
228
|
|
|
$sql = sprintf($format , |
|
229
|
|
|
$this->db->prefix('mimetypes'), |
|
230
|
|
|
$mime_id, |
|
|
|
|
|
|
231
|
|
|
$this->db->quoteString($mime_ext), |
|
|
|
|
|
|
232
|
|
|
$this->db->quoteString($mime_types), |
|
|
|
|
|
|
233
|
|
|
$this->db->quoteString($mime_name), |
|
|
|
|
|
|
234
|
|
|
$mime_status); |
|
|
|
|
|
|
235
|
|
|
$force = true; |
|
236
|
|
|
} else { |
|
237
|
|
|
$format = "UPDATE %s SET "; |
|
238
|
|
|
$format .="mime_ext=%s, mime_types=%s, mime_name=%s, mime_status=%u"; |
|
239
|
|
|
$format .=" WHERE mime_id = %u"; |
|
240
|
|
|
$sql = sprintf($format, $this->db->prefix('mimetypes'), |
|
241
|
|
|
|
|
242
|
|
|
$this->db->quoteString($mime_ext), |
|
243
|
|
|
$this->db->quoteString($mime_types), |
|
244
|
|
|
$this->db->quoteString($mime_name), |
|
245
|
|
|
$mime_status, |
|
246
|
|
|
$mime_id); |
|
247
|
|
|
} |
|
248
|
|
|
|
|
249
|
|
|
if (false != $force) { |
|
|
|
|
|
|
250
|
|
|
$result = $this->db->queryF($sql); |
|
251
|
|
|
} else { |
|
252
|
|
|
$result = $this->db->query($sql); |
|
253
|
|
|
} |
|
254
|
|
|
|
|
255
|
|
|
if (!$result) { |
|
256
|
|
|
$this->setErrors($this->db->error() ); |
|
257
|
|
|
return false; |
|
258
|
|
|
} |
|
259
|
|
|
|
|
260
|
|
|
if ($mimetype_object->isNew()) { |
|
261
|
|
|
$mimetype_object->assignVar('mime_id', $this->db->getInsertId() ); |
|
262
|
|
|
} |
|
263
|
|
|
return true; |
|
264
|
|
|
} |
|
265
|
|
|
|
|
266
|
|
|
function delete(&$mimetype_object, $force = false) { |
|
|
|
|
|
|
267
|
|
|
if (strtolower(get_class($mimetype_object)) != 'xoopsmimetypes') { |
|
268
|
|
|
return false; |
|
269
|
|
|
} |
|
270
|
|
|
|
|
271
|
|
|
$sql = sprintf("DELETE FROM %s WHERE mime_id = %u", $this->db->prefix("mimetypes"), $mimetype_object->getVar('mime_id')); |
|
272
|
|
|
if (false != $force) { |
|
|
|
|
|
|
273
|
|
|
$result = $this->db->queryF($sql); |
|
274
|
|
|
} else { |
|
275
|
|
|
$result = $this->db->query($sql); |
|
276
|
|
|
} |
|
277
|
|
|
|
|
278
|
|
|
if (!$result) { |
|
279
|
|
|
$this->setErrors($this->db->error() ); |
|
280
|
|
|
return false; |
|
281
|
|
|
} |
|
282
|
|
|
|
|
283
|
|
|
$sql = sprintf("DELETE FROM %s WHERE mperm_mime = %u", $this->db->prefix("mimetypes_perms"), $mimetype_object->getVar('mime_id')); |
|
284
|
|
|
if (false != $force) { |
|
|
|
|
|
|
285
|
|
|
$result = $this->db->queryF($sql); |
|
286
|
|
|
} else { |
|
287
|
|
|
$result = $this->db->query($sql); |
|
288
|
|
|
} |
|
289
|
|
|
if (!$result) { |
|
290
|
|
|
$this->setErrors($this->db->error() ); |
|
291
|
|
|
return false; |
|
292
|
|
|
} |
|
293
|
|
|
return true; |
|
294
|
|
|
} |
|
295
|
|
|
|
|
296
|
|
|
function &GetSelectList($criteria = null) { |
|
297
|
|
|
$ret = array(); |
|
298
|
|
|
$limit = $start = 0; |
|
299
|
|
|
$sql = 'SELECT * FROM '.$this->db->prefix('mimetypes'); |
|
300
|
|
View Code Duplication |
if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
|
|
|
|
|
|
301
|
|
|
$sql .= ' '.$criteria->renderWhere(); |
|
302
|
|
|
if ($criteria->getSort() != '') { |
|
303
|
|
|
$sql .= ' ORDER BY '.$criteria->getSort().' '.$criteria->getOrder(); |
|
304
|
|
|
} |
|
305
|
|
|
$limit = $criteria->getLimit(); |
|
306
|
|
|
$start = $criteria->getStart(); |
|
307
|
|
|
} |
|
308
|
|
|
$result = $this->db->query($sql, $limit, $start); |
|
309
|
|
|
if (!$result) { |
|
310
|
|
|
return $ret; |
|
311
|
|
|
} |
|
312
|
|
|
while ($myrow = $this->db->fetchArray($result)) { |
|
313
|
|
|
$ret[$myrow['mime_id']] = $myrow['mime_ext'] . ' - ' . $myrow['mime_name']; |
|
314
|
|
|
} |
|
315
|
|
|
return $ret; |
|
316
|
|
|
} |
|
317
|
|
|
|
|
318
|
|
|
function XoopsFormSelectMime( $caption, $name, $value=null, $size=1, $multiple=false ) { |
|
|
|
|
|
|
319
|
|
|
$ret = new XoopsFormSelect($caption, $name, $value, $size, $multiple); |
|
320
|
|
|
$criteria = new CriteriaCompo(); |
|
321
|
|
|
$criteria->setSort('mime_ext'); |
|
322
|
|
|
$ret->addOptionArray( $this->GetSelectList($criteria) ); |
|
323
|
|
|
return $ret; |
|
324
|
|
|
} |
|
325
|
|
|
|
|
326
|
|
|
function XoopsFormSelectType( $caption, $name, $value=null, $size=1, $multiple=false ) { |
|
|
|
|
|
|
327
|
|
|
$ret = new XoopsFormSelect($caption, $name, $value, $size, $multiple); |
|
328
|
|
|
$ret->addOptionArray( $this->Get_TypeList() ); |
|
329
|
|
|
return $ret; |
|
330
|
|
|
} |
|
331
|
|
|
|
|
332
|
|
|
function Get_TypeList() { |
|
|
|
|
|
|
333
|
|
|
$ret = array(); |
|
334
|
|
|
$sql = 'SELECT * FROM ' . $this->db->prefix("mimetypes") ; |
|
335
|
|
|
|
|
336
|
|
|
$result = $this->db->query($sql); |
|
337
|
|
|
while ( $myrow = $this->db->fetchArray($result) ) { |
|
338
|
|
|
$mime_types = explode('|',$myrow['mime_types']); |
|
339
|
|
|
foreach ( $mime_types as $mime_type ) { |
|
340
|
|
|
if ( $type = substr( $mime_type, 0, strpos($mime_type, '/') ) ) { |
|
341
|
|
|
if ( !in_array ($type, $ret) ) { |
|
342
|
|
|
$ret[$type] = $type; |
|
343
|
|
|
} |
|
344
|
|
|
} |
|
345
|
|
|
} |
|
346
|
|
|
} |
|
347
|
|
|
return $ret; |
|
348
|
|
|
} |
|
349
|
|
|
|
|
350
|
|
|
function setErrors($err_str) { |
|
|
|
|
|
|
351
|
|
|
$this->_errors[] = trim($err_str); |
|
352
|
|
|
} |
|
353
|
|
|
|
|
354
|
|
View Code Duplication |
function getHtmlErrors() { |
|
|
|
|
|
|
355
|
|
|
$ret = '<h4>Errors</h4>'; |
|
356
|
|
|
if (!empty($this->_errors)) { |
|
357
|
|
|
foreach ($this->_errors as $error) { |
|
358
|
|
|
$ret .= $error.'<br />'; |
|
359
|
|
|
} |
|
360
|
|
|
} else { |
|
361
|
|
|
$ret .= 'None<br />'; |
|
362
|
|
|
} |
|
363
|
|
|
return $ret; |
|
364
|
|
|
} |
|
365
|
|
|
} |
|
366
|
|
|
|
|
367
|
|
|
|
|
368
|
|
|
class XoopsMimetypes_perms extends XoopsObject { |
|
|
|
|
|
|
369
|
|
|
var $db; |
|
|
|
|
|
|
370
|
|
|
|
|
371
|
|
|
// constructor |
|
372
|
|
|
function xoopsmimetypes_perms ($mperm_id=null) { |
|
|
|
|
|
|
373
|
|
|
$this->db = Database::getInstance(); |
|
374
|
|
|
$this->initVar('mperm_id',XOBJ_DTYPE_INT,0,true,10); |
|
375
|
|
|
$this->initVar('mperm_mime',XOBJ_DTYPE_INT,0,true,11); |
|
376
|
|
|
$this->initVar('mperm_module' ,XOBJ_DTYPE_INT,0,true,5); |
|
377
|
|
|
$this->initVar('mperm_groups' ,XOBJ_DTYPE_TXTAREA,'',false,0); |
|
378
|
|
|
$this->initVar('mperm_status' ,XOBJ_DTYPE_INT,0,true,1); |
|
379
|
|
|
$this->initVar('mperm_maxwidth' ,XOBJ_DTYPE_INT,0,true,4); |
|
380
|
|
|
$this->initVar('mperm_maxheight',XOBJ_DTYPE_INT,0,true,4); |
|
381
|
|
|
$this->initVar('mperm_maxsize' ,XOBJ_DTYPE_INT,0,true,8); |
|
382
|
|
|
$this->initVar('mime_ext',XOBJ_DTYPE_TXTBOX,'',true,10); |
|
383
|
|
|
$this->initVar('mime_name',XOBJ_DTYPE_TXTBOX,'',true,255); |
|
384
|
|
|
$this->initVar('mod_name',XOBJ_DTYPE_TXTBOX,'',true,255); |
|
385
|
|
|
|
|
386
|
|
|
if ( !empty($mperm_id) ) { |
|
387
|
|
|
if ( is_array($mperm_id) ) { |
|
388
|
|
|
$this->assignVars($mperm_id); |
|
389
|
|
|
} else { |
|
390
|
|
|
$this->load($mperm_id); |
|
391
|
|
|
} |
|
392
|
|
|
} else { |
|
393
|
|
|
$this->setNew(); |
|
394
|
|
|
} |
|
395
|
|
|
} |
|
396
|
|
|
|
|
397
|
|
|
function load($module_id) { |
|
|
|
|
|
|
398
|
|
|
$sql = 'SELECT p.*, t.mime_ext, t.mime_name, m.name FROM ' . $this->db->prefix('mimetypes_perms') . ' p LEFT JOIN ' . |
|
399
|
|
|
$this->db->prefix("mimetypes") . ' t on p.mperm_mime = t.mime_id LEFT JOIN ' . |
|
400
|
|
|
$this->db->prefix("modules") . ' m on p.mperm_module = m.mid' . ' WHERE mperm_id=' . $this->db->quoteString($module_id); |
|
401
|
|
|
|
|
402
|
|
|
$myrow = $this->db->fetchArray($this->db->query($sql)); |
|
403
|
|
|
$this->assignVars($myrow); |
|
404
|
|
|
if (!$myrow) { |
|
405
|
|
|
$this->setNew(); |
|
406
|
|
|
} |
|
407
|
|
|
} |
|
408
|
|
|
|
|
409
|
|
|
function mime_id() { |
|
|
|
|
|
|
410
|
|
|
return $this->getVar('mperm_id'); |
|
411
|
|
|
} |
|
412
|
|
|
|
|
413
|
|
|
function mperm_mime() { |
|
|
|
|
|
|
414
|
|
|
return $this->getVar('mperm_mime'); |
|
415
|
|
|
} |
|
416
|
|
|
|
|
417
|
|
|
function mperm_module() { |
|
|
|
|
|
|
418
|
|
|
return $this->getVar('mperm_module'); |
|
419
|
|
|
} |
|
420
|
|
|
|
|
421
|
|
View Code Duplication |
function mime_ext($format='S') { |
|
|
|
|
|
|
422
|
|
|
$ret = $this->getVar('mime_ext', $format); |
|
423
|
|
|
if (($format=='s') || ($format=='S') || ($format=='show')) { |
|
424
|
|
|
$myts = &MyTextSanitizer::getInstance(); |
|
425
|
|
|
$ret = $myts->displayTarea($ret); |
|
426
|
|
|
} |
|
427
|
|
|
return $ret; |
|
428
|
|
|
} |
|
429
|
|
|
|
|
430
|
|
View Code Duplication |
function mime_module($format='S') { |
|
|
|
|
|
|
431
|
|
|
$ret = $this->getVar('name', $format); |
|
432
|
|
|
if (($format=='s') || ($format=='S') || ($format=='show')) { |
|
433
|
|
|
$myts = &MyTextSanitizer::getInstance(); |
|
434
|
|
|
$ret = $myts->displayTarea($ret); |
|
435
|
|
|
} |
|
436
|
|
|
return $ret; |
|
437
|
|
|
} |
|
438
|
|
|
|
|
439
|
|
View Code Duplication |
function mime_name($format='S') { |
|
|
|
|
|
|
440
|
|
|
$ret = $this->getVar('mime_name', $format); |
|
441
|
|
|
if (($format=='s') || ($format=='S') || ($format=='show')) { |
|
442
|
|
|
$myts = &MyTextSanitizer::getInstance(); |
|
443
|
|
|
$ret = $myts->displayTarea($ret); |
|
444
|
|
|
} |
|
445
|
|
|
return $ret; |
|
446
|
|
|
} |
|
447
|
|
|
|
|
448
|
|
|
function mime_groups() { |
|
|
|
|
|
|
449
|
|
|
return $this->getVar('mperm_groups'); |
|
450
|
|
|
} |
|
451
|
|
|
|
|
452
|
|
|
function mperm_maxwidth() { |
|
|
|
|
|
|
453
|
|
|
return $this->getVar('mperm_maxwidth'); |
|
454
|
|
|
} |
|
455
|
|
|
|
|
456
|
|
|
function mperm_maxheight() { |
|
|
|
|
|
|
457
|
|
|
return $this->getVar('mperm_maxheight'); |
|
458
|
|
|
} |
|
459
|
|
|
|
|
460
|
|
|
function mperm_maxsize() { |
|
|
|
|
|
|
461
|
|
|
return $this->getVar('mperm_maxsize'); |
|
462
|
|
|
} |
|
463
|
|
|
|
|
464
|
|
|
function mperm_status() { |
|
|
|
|
|
|
465
|
|
|
return $this->getVar('mperm_status'); |
|
466
|
|
|
} |
|
467
|
|
|
|
|
468
|
|
|
function GetGroups() { |
|
|
|
|
|
|
469
|
|
|
$groups = array(); |
|
470
|
|
|
$sql = 'SELECT p.mperm_groups FROM ' . $this->db->prefix('mimetypes_perms') . ' p LEFT JOIN ' . |
|
471
|
|
|
$this->db->prefix("mimetypes") . ' t on p.mperm_mime = t.mime_id ' . ' WHERE mperm_module=' . $this->mperm_module() . ' AND mperm_mime=' . $this->mperm_mime(); |
|
472
|
|
|
$result = $this->db->query($sql); |
|
473
|
|
|
|
|
474
|
|
|
while ( $myrow = $this->db->fetchArray($result) ) { |
|
475
|
|
|
$groups[] = $myrow['mperm_groups']; |
|
476
|
|
|
} |
|
477
|
|
|
|
|
478
|
|
|
return $groups; |
|
479
|
|
|
} |
|
480
|
|
|
} |
|
481
|
|
|
|
|
482
|
|
|
class XoopsMimetypes_permsHandler extends XoopsObjectHandler { |
|
|
|
|
|
|
483
|
|
|
var $_errors = array(); |
|
|
|
|
|
|
484
|
|
|
|
|
485
|
|
|
function get_mimetypes($limit=20, $start=0, $module=-1, $OtherCriteria=null, $asobject=true) { |
|
|
|
|
|
|
486
|
|
|
$ret = array(); |
|
487
|
|
|
$criteria = new CriteriaCompo(); |
|
488
|
|
|
if ( is_object($OtherCriteria) ) { |
|
489
|
|
|
$criteria->add($OtherCriteria, 'AND'); |
|
490
|
|
|
} |
|
491
|
|
|
|
|
492
|
|
View Code Duplication |
if ( isset($module) && (is_array($module)) ) { |
|
|
|
|
|
|
493
|
|
|
foreach ($module as $v) { |
|
494
|
|
|
$criteria->add(new Criteria('p.mperm_module', $v), 'AND'); |
|
495
|
|
|
} |
|
496
|
|
|
} elseif ( isset($module) && ($module != -1) ) { |
|
497
|
|
|
$criteria->add(new Criteria('p.mperm_module', $module), 'AND'); |
|
498
|
|
|
} |
|
499
|
|
|
|
|
500
|
|
|
$criteria->setLimit($limit); |
|
501
|
|
|
$criteria->setStart($start); |
|
502
|
|
|
$criteria->setSort('t.mime_ext'); |
|
503
|
|
|
$criteria->setOrder('ASC'); |
|
504
|
|
|
$criteria->setGroupby('p.mperm_mime'); |
|
505
|
|
|
|
|
506
|
|
|
$sql = 'SELECT p.*, t.mime_ext, t.mime_name, m.name FROM ' . $this->db->prefix('mimetypes_perms') . ' p LEFT JOIN ' . |
|
507
|
|
|
$this->db->prefix("mimetypes") . ' t on p.mperm_mime = t.mime_id LEFT JOIN ' . |
|
508
|
|
|
$this->db->prefix("modules") . ' m on p.mperm_module = m.mid'; |
|
509
|
|
|
|
|
510
|
|
View Code Duplication |
if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
|
|
|
|
|
|
511
|
|
|
$sql .= ' '.$criteria->renderWhere() . $criteria->getGroupby(); |
|
512
|
|
|
if ($criteria->getSort() != '') { |
|
513
|
|
|
$sql .= ' ORDER BY '.$criteria->getSort().' '.$criteria->getOrder(); |
|
514
|
|
|
} |
|
515
|
|
|
$limit = $criteria->getLimit(); |
|
516
|
|
|
$start = $criteria->getStart(); |
|
517
|
|
|
} |
|
518
|
|
|
|
|
519
|
|
|
$result = $this->db->query($sql, $limit, $start); |
|
520
|
|
|
if (!$result) { |
|
521
|
|
|
return $ret; |
|
522
|
|
|
} |
|
523
|
|
|
|
|
524
|
|
|
while ( $myrow = $this->db->fetchArray($result) ) { |
|
525
|
|
|
if ( !$asobject ) { |
|
526
|
|
|
$ret[$myrow['mime_id']] = $myrow; |
|
527
|
|
|
} else { |
|
528
|
|
|
$ret[] = new xoopsmimetypes_perms( $myrow ); |
|
529
|
|
|
} |
|
530
|
|
|
} |
|
531
|
|
|
return $ret; |
|
532
|
|
|
} |
|
533
|
|
|
|
|
534
|
|
View Code Duplication |
function get_byMimeModule( $mime_id, $mid, $asobject=true) { |
|
|
|
|
|
|
535
|
|
|
$ret = array(); |
|
536
|
|
|
$sql = 'SELECT * FROM ' . $this->db->prefix('mimetypes_perms') . ' WHERE mperm_mime = ' . $mime_id . ' AND mperm_module = ' . $mid; |
|
537
|
|
|
$result = $this->db->query($sql); |
|
538
|
|
|
if (!$result) { |
|
539
|
|
|
return $ret; |
|
540
|
|
|
} |
|
541
|
|
|
|
|
542
|
|
|
while ( $myrow = $this->db->fetchArray($result) ) { |
|
543
|
|
|
if ( !$asobject ) { |
|
544
|
|
|
$ret[$myrow['mime_id']] = $myrow; |
|
545
|
|
|
} else { |
|
546
|
|
|
$ret[] = new xoopsmimetypes_perms( $myrow ); |
|
547
|
|
|
} |
|
548
|
|
|
} |
|
549
|
|
|
return $ret; |
|
550
|
|
|
} |
|
551
|
|
|
|
|
552
|
|
|
function getCount($criteria = null, $notNullFields='') { |
|
|
|
|
|
|
553
|
|
|
$sql = 'SELECT COUNT(*) FROM ' . $this->db->prefix('mimetypes_perms') . ' p LEFT JOIN ' . |
|
554
|
|
|
$this->db->prefix("mimetypes") . ' t on p.mperm_mime = t.mime_id LEFT JOIN ' . |
|
555
|
|
|
$this->db->prefix("modules") . ' m on p.mperm_module = m.mid'; |
|
556
|
|
|
|
|
557
|
|
View Code Duplication |
if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
|
|
|
|
|
|
558
|
|
|
$whereClause = $criteria->renderWhere(); |
|
559
|
|
|
if ($whereClause != 'WHERE ()') { |
|
560
|
|
|
$sql .= ' '.$criteria->renderWhere(); |
|
561
|
|
|
} |
|
562
|
|
|
} |
|
563
|
|
|
|
|
564
|
|
|
$result = $this->db->query($sql); |
|
565
|
|
|
|
|
566
|
|
|
if (!$result) { |
|
567
|
|
|
return 0; |
|
568
|
|
|
} |
|
569
|
|
|
|
|
570
|
|
|
list($count) = $this->db->fetchRow($result); |
|
571
|
|
|
return $count; |
|
572
|
|
|
} |
|
573
|
|
|
|
|
574
|
|
|
function mime_module( $mid ) { |
|
|
|
|
|
|
575
|
|
|
$module_handler =& xoops_gethandler('module'); |
|
576
|
|
|
$module = $module_handler->get( $mid ); |
|
577
|
|
|
return $module->name(); |
|
578
|
|
|
} |
|
579
|
|
|
|
|
580
|
|
|
function insert(&$mimetype_object, $force = false) { |
|
|
|
|
|
|
581
|
|
|
if (strtolower(get_class($mimetype_object)) != 'xoopsmimetypes_perms') { |
|
582
|
|
|
return false; |
|
583
|
|
|
} |
|
584
|
|
|
if (!$mimetype_object->isDirty()) { |
|
585
|
|
|
return true; |
|
586
|
|
|
} |
|
587
|
|
|
if (!$mimetype_object->cleanVars()) { |
|
588
|
|
|
return false; |
|
589
|
|
|
} |
|
590
|
|
|
foreach ($mimetype_object->cleanVars as $k => $v) { |
|
591
|
|
|
${$k} = $v; |
|
592
|
|
|
} |
|
593
|
|
|
|
|
594
|
|
|
if ($mimetype_object->isNew()) { |
|
595
|
|
|
$mimetype_object = new xoopsmimetypes(); |
|
596
|
|
|
$format = "INSERT INTO %s (mperm_id, mperm_mime, mperm_module, mperm_groups, mperm_status, mperm_maxwidth, mperm_maxheight, mperm_maxsize)"; |
|
597
|
|
|
$format .= "VALUES (%u, %u, %u, %s, %u, %u, %u, %u)"; |
|
598
|
|
|
$sql = sprintf($format , |
|
599
|
|
|
$this->db->prefix('mimetypes_perms'), |
|
600
|
|
|
$mperm_id, |
|
|
|
|
|
|
601
|
|
|
$mperm_mime, |
|
|
|
|
|
|
602
|
|
|
$mperm_module, |
|
|
|
|
|
|
603
|
|
|
$mperm_groups, |
|
|
|
|
|
|
604
|
|
|
$mperm_status, |
|
|
|
|
|
|
605
|
|
|
$mperm_maxwidth, |
|
|
|
|
|
|
606
|
|
|
$mperm_maxheight, |
|
|
|
|
|
|
607
|
|
|
$mperm_maxsize ); |
|
|
|
|
|
|
608
|
|
|
$force = true; |
|
609
|
|
|
} else { |
|
610
|
|
|
$format = "UPDATE %s SET "; |
|
611
|
|
|
$format .="mperm_mime=%u, mperm_module=%u, mperm_groups=%s, mperm_status=%u, mperm_maxwidth=%u, mperm_maxheight=%u, mperm_maxsize=%u"; |
|
612
|
|
|
$format .=" WHERE mperm_id = %u"; |
|
613
|
|
|
$sql = sprintf($format, $this->db->prefix('mimetypes_perms'), |
|
614
|
|
|
$mperm_mime, |
|
615
|
|
|
$mperm_module, |
|
616
|
|
|
$this->db->quoteString($mperm_groups), |
|
617
|
|
|
$mperm_status, |
|
618
|
|
|
$mperm_maxwidth, |
|
619
|
|
|
$mperm_maxheight, |
|
620
|
|
|
$mperm_maxsize, |
|
621
|
|
|
$mperm_id); |
|
622
|
|
|
} |
|
623
|
|
|
|
|
624
|
|
|
if (false != $force) { |
|
|
|
|
|
|
625
|
|
|
$result = $this->db->queryF($sql); |
|
626
|
|
|
} else { |
|
627
|
|
|
$result = $this->db->query($sql); |
|
628
|
|
|
} |
|
629
|
|
|
if (!$result) { |
|
630
|
|
|
$this->setErrors($this->db->error() ); |
|
631
|
|
|
return false; |
|
632
|
|
|
} |
|
633
|
|
|
|
|
634
|
|
|
if ($mimetype_object->isNew()) { |
|
635
|
|
|
$mimetype_object->assignVar('mime_id', $this->db->getInsertId() ); |
|
636
|
|
|
} |
|
637
|
|
|
|
|
638
|
|
|
return true; |
|
639
|
|
|
} |
|
640
|
|
|
|
|
641
|
|
View Code Duplication |
function delete(&$mimetype_object, $force = false) { |
|
|
|
|
|
|
642
|
|
|
if (strtolower(get_class($mimetype_object)) != 'xoopsmimetypes_perms') { |
|
643
|
|
|
return false; |
|
644
|
|
|
} |
|
645
|
|
|
$sql = sprintf("DELETE FROM %s WHERE mperm_id = %u", $this->db->prefix("mimetypes_perms"), $mimetype_object->getVar('mperm_id')); |
|
646
|
|
|
if (false != $force) { |
|
|
|
|
|
|
647
|
|
|
$result = $this->db->queryF($sql); |
|
648
|
|
|
} else { |
|
649
|
|
|
$result = $this->db->query($sql); |
|
650
|
|
|
} |
|
651
|
|
|
if (!$result) { |
|
652
|
|
|
$this->setErrors($this->db->error() ); |
|
653
|
|
|
return false; |
|
654
|
|
|
} |
|
655
|
|
|
return true; |
|
656
|
|
|
} |
|
657
|
|
|
|
|
658
|
|
View Code Duplication |
function deletebyMimeModule(&$mimetype_object, $force = false) { |
|
|
|
|
|
|
659
|
|
|
if (strtolower(get_class($mimetype_object)) != 'xoopsmimetypes_perms') { |
|
660
|
|
|
return false; |
|
661
|
|
|
} |
|
662
|
|
|
$sql = sprintf("DELETE FROM %s WHERE mperm_mime = %u AND mperm_module = %u", $this->db->prefix("mimetypes_perms"), $mimetype_object->getVar('mperm_mime'), $mimetype_object->getVar('mperm_module')); |
|
663
|
|
|
if (false != $force) { |
|
|
|
|
|
|
664
|
|
|
$result = $this->db->queryF($sql); |
|
665
|
|
|
} else { |
|
666
|
|
|
$result = $this->db->query($sql); |
|
667
|
|
|
} |
|
668
|
|
|
|
|
669
|
|
|
if (!$result) { |
|
670
|
|
|
$this->setErrors($this->db->error() ); |
|
671
|
|
|
return false; |
|
672
|
|
|
} |
|
673
|
|
|
return true; |
|
674
|
|
|
} |
|
675
|
|
|
|
|
676
|
|
View Code Duplication |
function deletebyMime(&$mimetype_object, $force = false) { |
|
|
|
|
|
|
677
|
|
|
if (strtolower(get_class($mimetype_object)) != 'xoopsmimetypes_perms') { |
|
678
|
|
|
return false; |
|
679
|
|
|
} |
|
680
|
|
|
$sql = sprintf("DELETE FROM %s WHERE mperm_mime = %u", $this->db->prefix("mimetypes_perms"), $mimetype_object->getVar('mperm_mime')); |
|
681
|
|
|
if (false != $force) { |
|
|
|
|
|
|
682
|
|
|
$result = $this->db->queryF($sql); |
|
683
|
|
|
} else { |
|
684
|
|
|
$result = $this->db->query($sql); |
|
685
|
|
|
} |
|
686
|
|
|
|
|
687
|
|
|
if (!$result) { |
|
688
|
|
|
$this->setErrors($this->db->error() ); |
|
689
|
|
|
return false; |
|
690
|
|
|
} |
|
691
|
|
|
|
|
692
|
|
|
return true; |
|
693
|
|
|
} |
|
694
|
|
|
|
|
695
|
|
View Code Duplication |
function deletebyModule(&$mimetype_object, $force = false) { |
|
|
|
|
|
|
696
|
|
|
if (strtolower(get_class($mimetype_object)) != 'xoopsmimetypes_perms') { |
|
697
|
|
|
return false; |
|
698
|
|
|
} |
|
699
|
|
|
|
|
700
|
|
|
$sql = sprintf("DELETE FROM %s WHERE mperm_module = %u AND mperm_mime = %u", $this->db->prefix("mimetypes_perms"), $mimetype_object->getVar('mperm_module'), $mimetype_object->getVar('mperm_mime')); |
|
701
|
|
|
if (false != $force) { |
|
|
|
|
|
|
702
|
|
|
$result = $this->db->queryF($sql); |
|
703
|
|
|
} else { |
|
704
|
|
|
$result = $this->db->query($sql); |
|
705
|
|
|
} |
|
706
|
|
|
|
|
707
|
|
|
if (!$result) { |
|
708
|
|
|
$this->setErrors($this->db->error() ); |
|
709
|
|
|
return false; |
|
710
|
|
|
} |
|
711
|
|
|
return true; |
|
712
|
|
|
} |
|
713
|
|
|
|
|
714
|
|
|
function allowedMimeTypes( $mid, $groups, $allowedMimeTypes ) { |
|
|
|
|
|
|
715
|
|
|
$ret = array(); |
|
716
|
|
|
$sql = 'SELECT p.mperm_groups, t.mime_ext, t.mime_types FROM ' . $this->db->prefix('mimetypes_perms') . ' p LEFT JOIN ' . |
|
717
|
|
|
$this->db->prefix("mimetypes") . ' t on p.mperm_mime = t.mime_id WHERE mperm_module=' . $mid; |
|
718
|
|
|
|
|
719
|
|
|
$result = $this->db->query($sql); |
|
720
|
|
|
|
|
721
|
|
|
while ( $myrow = $this->db->fetchArray($result) ) { |
|
722
|
|
|
$mperm_groups = explode('|',$myrow['mperm_groups']); |
|
723
|
|
|
if (count(array_intersect($groups,$mperm_groups)) > 0) { |
|
724
|
|
|
$mime_types = explode('|',$myrow['mime_types']); |
|
725
|
|
|
$tmp = array_intersect($allowedMimeTypes,$mime_types); |
|
726
|
|
|
if (count($tmp) > 0) { |
|
727
|
|
|
$ret = array_merge ($ret, $tmp); |
|
728
|
|
|
} |
|
729
|
|
|
} |
|
730
|
|
|
} |
|
731
|
|
|
|
|
732
|
|
|
if ( count($ret) == 0 ) { |
|
733
|
|
|
@$ret = include( XOOPS_ROOT_PATH . '/class/mimetypes.inc.php' ); |
|
|
|
|
|
|
734
|
|
|
return $ret; |
|
735
|
|
|
} |
|
736
|
|
|
return $ret; |
|
737
|
|
|
} |
|
738
|
|
|
|
|
739
|
|
|
function setErrors($err_str) { |
|
|
|
|
|
|
740
|
|
|
$this->_errors[] = trim($err_str); |
|
741
|
|
|
} |
|
742
|
|
|
|
|
743
|
|
View Code Duplication |
function getHtmlErrors() { |
|
|
|
|
|
|
744
|
|
|
$ret = '<h4>Errors</h4>'; |
|
745
|
|
|
if (!empty($this->_errors)) { |
|
746
|
|
|
foreach ($this->_errors as $error) { |
|
747
|
|
|
$ret .= $error.'<br />'; |
|
748
|
|
|
} |
|
749
|
|
|
} else { |
|
750
|
|
|
$ret .= 'None<br />'; |
|
751
|
|
|
} |
|
752
|
|
|
return $ret; |
|
753
|
|
|
} |
|
754
|
|
|
} |
|
755
|
|
|
?> |
|
|
|
|
|
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.