|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
// ID: category.php 3-nov-2007 18:18:06 efqconsultancy |
|
4
|
|
|
// ------------------------------------------------------------------------ // |
|
5
|
|
|
// EFQ Directory // |
|
6
|
|
|
// Copyright (c) 2006 EFQ Consultancy // |
|
7
|
|
|
// <http://www.efqdirectory.com/> // |
|
8
|
|
|
// ------------------------------------------------------------------------ // |
|
9
|
|
|
// This program is free software; you can redistribute it and/or modify // |
|
10
|
|
|
// it under the terms of the GNU General Public License as published by // |
|
11
|
|
|
// the Free Software Foundation; either version 2 of the License, or // |
|
12
|
|
|
// (at your option) any later version. // |
|
13
|
|
|
// // |
|
14
|
|
|
// You may not change or alter any portion of this comment or credits // |
|
15
|
|
|
// of supporting developers from this source code or any supporting // |
|
16
|
|
|
// source code which is considered copyrighted (c) material of the // |
|
17
|
|
|
// original comment or credit authors. // |
|
18
|
|
|
// // |
|
19
|
|
|
// This program is distributed in the hope that it will be useful, // |
|
20
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of // |
|
21
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // |
|
22
|
|
|
// GNU General Public License for more details. // |
|
23
|
|
|
// // |
|
24
|
|
|
// You should have received a copy of the GNU General Public License // |
|
25
|
|
|
// along with this program; if not, write to the Free Software // |
|
26
|
|
|
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // |
|
27
|
|
|
// ------------------------------------------------------------------------ // |
|
28
|
|
|
// Part of the efqDirectory module provided by: wtravel // |
|
29
|
|
|
// e-mail: [email protected] // |
|
30
|
|
|
// Purpose: Create a business directory for xoops. // |
|
31
|
|
|
// Based upon the mylinks and the mxDirectory modules // |
|
32
|
|
|
// ------------------------------------------------------------------------- // |
|
33
|
|
|
*/ |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Class efqDirectory |
|
37
|
|
|
* Manages operations for directories |
|
38
|
|
|
* |
|
39
|
|
|
* @package efqDirectory |
|
40
|
|
|
* @author EFQ Consultancy <[email protected]> |
|
41
|
|
|
* @copyright EFQ Consultancy (c) 2007 |
|
42
|
|
|
* @version 1.1.0 |
|
43
|
|
|
*/ |
|
44
|
|
|
class efqDirectory extends XoopsObject |
|
|
|
|
|
|
45
|
|
|
{ |
|
46
|
|
|
/** |
|
47
|
|
|
* efqDirectory constructor. |
|
48
|
|
|
* @param bool $directory |
|
49
|
|
|
*/ |
|
50
|
|
|
public function __construct($directory = false) |
|
51
|
|
|
{ |
|
52
|
|
|
global $moddir; |
|
53
|
|
|
$this->db = XoopsDatabaseFactory::getDatabaseConnection(); |
|
|
|
|
|
|
54
|
|
|
$this->initVar('dirid', XOBJ_DTYPE_INT, null, false); |
|
|
|
|
|
|
55
|
|
|
$this->initVar('postfix', XOBJ_DTYPE_TXTBOX); |
|
|
|
|
|
|
56
|
|
|
$this->initVar('open', XOBJ_DTYPE_INT, 0, false); |
|
57
|
|
|
$this->initVar('name', XOBJ_DTYPE_TXTBOX); |
|
58
|
|
|
$this->initVar('description', XOBJ_DTYPE_TXTAREA); |
|
|
|
|
|
|
59
|
|
|
$this->initVar('img', XOBJ_DTYPE_TXTBOX); |
|
60
|
|
|
$this->initVar('allowreview', XOBJ_DTYPE_INT, 0, false); |
|
61
|
|
|
|
|
62
|
|
View Code Duplication |
if ($directory !== false) { |
|
|
|
|
|
|
63
|
|
|
if (is_array($directory)) { |
|
64
|
|
|
$this->assignVars($directory); |
|
65
|
|
|
} else { |
|
66
|
|
|
$directoryHandler = xoops_getModuleHandler('directory', $moddir); |
|
|
|
|
|
|
67
|
|
|
$objDirectory = $directoryHandler->get($directory); |
|
68
|
|
|
foreach ($objDirectory->vars as $k => $v) { |
|
69
|
|
|
$this->assignVar($k, $v['value']); |
|
70
|
|
|
} |
|
71
|
|
|
unset($objDirectory); |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* Class efqDirectoryHandler |
|
79
|
|
|
* Manages database operations for directories |
|
80
|
|
|
* |
|
81
|
|
|
* @package efqDirectory |
|
82
|
|
|
* @author EFQ Consultancy <[email protected]> |
|
83
|
|
|
* @copyright EFQ Consultancy (c) 2007 |
|
84
|
|
|
* @version 1.1.0 |
|
85
|
|
|
*/ |
|
86
|
|
|
class efqDirectoryHandler extends XoopsObjectHandler |
|
|
|
|
|
|
87
|
|
|
{ |
|
88
|
|
|
/** |
|
89
|
|
|
* efqDirectoryHandler constructor. |
|
90
|
|
|
*/ |
|
91
|
|
|
public function __construct() |
|
92
|
|
|
{ |
|
93
|
|
|
$this->db = XoopsDatabaseFactory::getDatabaseConnection(); |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
/** |
|
97
|
|
|
* create instance of directory class or reset the existing instance. |
|
98
|
|
|
* |
|
99
|
|
|
* @param bool $isNew |
|
100
|
|
|
* @return efqDirectory $directory |
|
101
|
|
|
*/ |
|
102
|
|
|
public function &create($isNew = true) |
|
103
|
|
|
{ |
|
104
|
|
|
$directory = new efqDirectory(); |
|
105
|
|
|
if ($isNew) { |
|
106
|
|
|
$directory->setNew(); |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
return $directory; |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
/** |
|
113
|
|
|
* retrieve a directory |
|
114
|
|
|
* |
|
115
|
|
|
* @param bool|int $dirid ID of the directory |
|
116
|
|
|
* @return mixed reference to the <a href='psi_element://efqDirectory'>efqDirectory</a> object, FALSE if failed |
|
117
|
|
|
* object, FALSE if failed |
|
118
|
|
|
*/ |
|
119
|
|
View Code Duplication |
public function &get($dirid = false) |
|
|
|
|
|
|
120
|
|
|
{ |
|
121
|
|
|
if ($dirid === false) { |
|
122
|
|
|
return false; |
|
123
|
|
|
} |
|
124
|
|
|
$dirid = (int)$dirid; |
|
125
|
|
|
if ($dirid > 0) { |
|
126
|
|
|
$sql = 'SELECT * FROM ' . $this->db->prefix('efqdiralpha1_dir') . ' WHERE dirid=' . $dirid; |
|
127
|
|
|
if (!$result = $this->db->query($sql)) { |
|
128
|
|
|
return false; |
|
129
|
|
|
} |
|
130
|
|
|
$directory =& $this->create(false); |
|
131
|
|
|
$directory->assignVars($this->db->fetchArray($result)); |
|
132
|
|
|
|
|
133
|
|
|
return $directory; |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
return false; |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
/** |
|
140
|
|
|
* retrieve all directories |
|
141
|
|
|
* |
|
142
|
|
|
* @return mixed reference to the {@link efqDirectory} object, FALSE if failed |
|
143
|
|
|
*/ |
|
144
|
|
|
public function &getAll() |
|
145
|
|
|
{ |
|
146
|
|
|
$sql = 'SELECT dirid,postfix,open,name,descr,img FROM ' . $this->db->prefix('efqdiralpha1_dir') . ''; |
|
147
|
|
|
if (!$result = $this->db->query($sql)) { |
|
148
|
|
|
return false; |
|
149
|
|
|
} |
|
150
|
|
|
while (list($dirid, $postfix, $open, $name, $descr, $img) = $this->db->fetchRow($result)) { |
|
151
|
|
|
$arr[] = array( |
|
152
|
|
|
'dirid' => $dirid, |
|
153
|
|
|
'postfix' => $postfix, |
|
154
|
|
|
'open' => $open, |
|
155
|
|
|
'name' => $name, |
|
156
|
|
|
'descr' => $descr, |
|
157
|
|
|
'img' => $img |
|
158
|
|
|
); |
|
159
|
|
|
} |
|
160
|
|
|
|
|
161
|
|
|
return $arr; |
|
|
|
|
|
|
162
|
|
|
} |
|
163
|
|
|
|
|
164
|
|
|
/** |
|
165
|
|
|
* retrieve all directory ID's |
|
166
|
|
|
* |
|
167
|
|
|
* @param array $idarray |
|
168
|
|
|
* @return array|bool |
|
169
|
|
|
*/ |
|
170
|
|
View Code Duplication |
public function &getAllDirectoryIds($idarray = array()) |
|
|
|
|
|
|
171
|
|
|
{ |
|
172
|
|
|
$sql = 'SELECT dirid FROM ' . $this->db->prefix('efqdiralpha1_dir') . ''; |
|
173
|
|
|
if (!$result = $this->db->query($sql)) { |
|
174
|
|
|
return false; |
|
175
|
|
|
} |
|
176
|
|
|
while (list($r_id) = $this->db->fetchRow($result)) { |
|
177
|
|
|
array_push($idarray, $r_id); |
|
178
|
|
|
} |
|
179
|
|
|
|
|
180
|
|
|
return $idarray; |
|
181
|
|
|
} |
|
182
|
|
|
|
|
183
|
|
|
/** |
|
184
|
|
|
* retrieve all directory ID's and titles as array |
|
185
|
|
|
* |
|
186
|
|
|
* @param array $arr |
|
187
|
|
|
* @return array|bool |
|
188
|
|
|
*/ |
|
189
|
|
View Code Duplication |
public function &getAllDirectoryTitles($arr = array()) |
|
|
|
|
|
|
190
|
|
|
{ |
|
191
|
|
|
$sql = 'SELECT dirid, name FROM ' . $this->db->prefix('efqdiralpha1_dir') . ''; |
|
192
|
|
|
if (!$result = $this->db->query($sql)) { |
|
193
|
|
|
return false; |
|
194
|
|
|
} |
|
195
|
|
|
while (list($r_id, $r_title) = $this->db->fetchRow($result)) { |
|
196
|
|
|
$result_arr[$r_id] = $r_title; |
|
197
|
|
|
//array_push($arr, $result_arr); |
|
|
|
|
|
|
198
|
|
|
} |
|
199
|
|
|
|
|
200
|
|
|
return $result_arr; |
|
|
|
|
|
|
201
|
|
|
} |
|
202
|
|
|
|
|
203
|
|
|
/** |
|
204
|
|
|
* count number of directories and if count == 1, set directory. |
|
205
|
|
|
* |
|
206
|
|
|
* @return mixed $result, FALSE if failed, 0 if count is 0. |
|
207
|
|
|
*/ |
|
208
|
|
|
public function countAll() |
|
209
|
|
|
{ |
|
210
|
|
|
global $xoopsDB; |
|
211
|
|
|
$block = array(); |
|
|
|
|
|
|
212
|
|
|
$myts = MyTextSanitizer::getInstance(); |
|
|
|
|
|
|
213
|
|
|
$dirid = 0; |
|
|
|
|
|
|
214
|
|
|
$result = $xoopsDB->query('SELECT dirid FROM ' . $xoopsDB->prefix('efqdiralpha1_dir') . ''); |
|
215
|
|
|
$num_results = $xoopsDB->getRowsNum($result); |
|
216
|
|
|
if (!$result) { |
|
217
|
|
|
return false; |
|
218
|
|
|
} elseif ($num_results == 0) { |
|
219
|
|
|
return 0; |
|
220
|
|
|
} elseif ($num_results == 1) { |
|
221
|
|
|
$row = $GLOBALS['xoopsDB']->fetchBoth($result); |
|
222
|
|
|
$dirid = $row['dirid']; |
|
223
|
|
|
|
|
224
|
|
|
return $dirid; |
|
225
|
|
|
} else { |
|
226
|
|
|
return false; |
|
227
|
|
|
} |
|
228
|
|
|
} |
|
229
|
|
|
|
|
230
|
|
|
/** |
|
231
|
|
|
* retrieve all directory ID's and names |
|
232
|
|
|
* |
|
233
|
|
|
* @param bool $dashes |
|
234
|
|
|
* @return array $array |
|
235
|
|
|
*/ |
|
236
|
|
|
public function directoryArray($dashes = false) |
|
237
|
|
|
{ |
|
238
|
|
|
$sql = 'SELECT dirid, name FROM ' . $this->db->prefix('efqdiralpha1_dir') . ' ORDER BY name ASC'; |
|
239
|
|
|
$result = $this->db->query($sql); |
|
240
|
|
|
$numrows = $this->db->getRowsNum($result); |
|
|
|
|
|
|
241
|
|
|
$result = $this->db->query($sql); |
|
242
|
|
|
if ($dashes !== false) { |
|
243
|
|
|
$arr = array('0' => '---'); |
|
244
|
|
|
} |
|
245
|
|
|
while (list($dirid, $dirname) = $this->db->fetchRow($result)) { |
|
246
|
|
|
$arr[$dirid] = $dirname; |
|
247
|
|
|
} |
|
248
|
|
|
|
|
249
|
|
|
return $arr; |
|
|
|
|
|
|
250
|
|
|
} |
|
251
|
|
|
|
|
252
|
|
|
/** |
|
253
|
|
|
* Function insertDirectory inserts new record into DB |
|
254
|
|
|
* @author EFQ Consultancy <[email protected]> |
|
255
|
|
|
* @copyright EFQ Consultancy (c) 2008 |
|
256
|
|
|
* @version 1.0.0 |
|
257
|
|
|
* |
|
258
|
|
|
* @param efqDirectory $obj object |
|
259
|
|
|
* |
|
260
|
|
|
* @param bool $forceQuery |
|
261
|
|
|
* @return bool true if insertion is succesful, false if unsuccesful |
|
262
|
|
|
*/ |
|
263
|
|
View Code Duplication |
public function insertDirectory($obj, $forceQuery = false) |
|
|
|
|
|
|
264
|
|
|
{ |
|
265
|
|
|
$tablename = 'efqdiralpha1_dir'; |
|
266
|
|
|
$keyName = 'dirid'; |
|
267
|
|
|
$excludedVars = array(); |
|
268
|
|
|
if ($obj instanceof efqDirectory) { |
|
269
|
|
|
// Variable part of this function ends. From this line you can copy |
|
270
|
|
|
// this function for similar object handling functions. |
|
271
|
|
|
$obj->cleanVars(); |
|
272
|
|
|
$cleanvars = $obj->cleanVars; |
|
273
|
|
|
} else { |
|
274
|
|
|
return false; |
|
275
|
|
|
} |
|
276
|
|
|
$countVars = count($cleanvars); |
|
277
|
|
|
$i = 1; |
|
278
|
|
|
$strFields = ''; |
|
279
|
|
|
$strValues = ''; |
|
280
|
|
|
foreach ($cleanvars as $k => $v) { |
|
281
|
|
|
if (!in_array($k, $excludedVars)) { |
|
282
|
|
|
$strFields .= $k; |
|
283
|
|
|
$strValues .= "'" . $v . "'"; |
|
284
|
|
|
if ($i < $countVars) { |
|
285
|
|
|
$strFields .= ', '; |
|
286
|
|
|
$strValues .= ', '; |
|
287
|
|
|
} |
|
288
|
|
|
$i++; |
|
289
|
|
|
} |
|
290
|
|
|
} |
|
291
|
|
|
$sql = sprintf('INSERT INTO %s (%s) VALUES (%s)', $this->db->prefix($tablename), $strFields, $strValues); |
|
292
|
|
|
if ($forceQuery) { |
|
293
|
|
|
if ($this->db->queryF($sql)) { |
|
294
|
|
|
$itemid = $this->db->getInsertId(); |
|
295
|
|
|
$obj->setVar($keyName, $itemid); |
|
296
|
|
|
|
|
297
|
|
|
return true; |
|
298
|
|
|
} |
|
299
|
|
|
} else { |
|
300
|
|
|
if ($this->db->query($sql)) { |
|
301
|
|
|
$itemid = $this->db->getInsertId(); |
|
302
|
|
|
$obj->setVar($keyName, $itemid); |
|
303
|
|
|
|
|
304
|
|
|
return true; |
|
305
|
|
|
} |
|
306
|
|
|
} |
|
307
|
|
|
|
|
308
|
|
|
return false; |
|
309
|
|
|
} |
|
310
|
|
|
} |
|
311
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths