| 1 |
<?php |
<?php |
| 2 |
// $Id: customfilter.module,v 1.3.2.1.2.27 2009/06/30 00:40:14 kiam Exp $ |
// $Id: customfilter.module,v 1.3.2.1.2.28 2009/07/01 02:33:53 kiam Exp $ |
| 3 |
|
|
| 4 |
/** |
/** |
| 5 |
* @file |
* @file |
| 305 |
* |
* |
| 306 |
* @param $fid |
* @param $fid |
| 307 |
* The filter ID. |
* The filter ID. |
|
* @param $fields |
|
|
* The fields to retrieve. |
|
| 308 |
* |
* |
| 309 |
* @return |
* @return |
| 310 |
* An array that describes the filter identified by $fid. |
* An array that describes the filter identified by $fid. |
| 311 |
*/ |
*/ |
| 312 |
function customfilter_get_filter($fid, $fields) { |
function customfilter_get_filter($fid) { |
| 313 |
$filter = db_fetch_array(db_query("SELECT * FROM {customfilter_filters} WHERE fid = %d", $fid)); |
$filters = customfilter_get_filters(); |
| 314 |
|
|
| 315 |
return $filter; |
return isset($filters[$fid]) ? $filters[$fid] : 0; |
| 316 |
} |
} |
| 317 |
|
|
| 318 |
/** |
/** |
| 319 |
* Get the list of filters from database. |
* Get the list of filters. |
|
* |
|
|
* @param $fields |
|
|
* The fields to retrieve. |
|
|
* @param $cond |
|
|
* The SQL condition that must be verified; by default, all results are |
|
|
* returned. |
|
|
* @param $args |
|
|
* The array of arguments to pass to the query function. |
|
| 320 |
* |
* |
| 321 |
* @return |
* @return |
| 322 |
* An array of filters. |
* An array of filters. |
| 323 |
*/ |
*/ |
| 324 |
function customfilter_get_filters() { |
function customfilter_get_filters() { |
| 325 |
$filters = array(); |
static $db_filters; |
|
|
|
|
$query = "SELECT * FROM {customfilter_filters} ORDER BY name"; |
|
|
$result = db_query($query); |
|
| 326 |
|
|
| 327 |
while ($filter = db_fetch_array($result)) { |
if (!isset($db_filters)) { |
| 328 |
$filters[] = $filter; |
$db_filters = array(); |
| 329 |
|
$query = "SELECT * FROM {customfilter_filters} ORDER BY name"; |
| 330 |
|
|
| 331 |
|
$result = db_query($query); |
| 332 |
|
while ($filter = db_fetch_array($result)) { |
| 333 |
|
$db_filters[] = $filter; |
| 334 |
|
} |
| 335 |
} |
} |
| 336 |
|
|
| 337 |
return $filters; |
return $db_filters; |
| 338 |
} |
} |
| 339 |
|
|
| 340 |
/** |
/** |
| 341 |
* Retrieve the replacement rules from the database table. |
* Retrieve the replacement rules for a specific filter. |
| 342 |
* |
* |
| 343 |
* @param $fid |
* @param $fid |
| 344 |
* The filter ID. |
* The filter ID. |
| 345 |
* @param $root |
* @param $root |
| 346 |
* The root rule. |
* The root rule. |
|
* @param $sortby |
|
|
* The database field used to sort the result; the default field used is the |
|
|
* weight field. |
|
|
* @param $fields |
|
|
* The fields to retrieve. |
|
| 347 |
* |
* |
| 348 |
* @return |
* @return |
| 349 |
* An array of rules, which include any subrules. |
* An array of rules, which include any subrules. |
| 350 |
*/ |
*/ |
| 351 |
function customfilter_get_rules($fid, $root = 0) { |
function customfilter_get_rules($fid, $root = 0) { |
| 352 |
|
static $db_rules = array(); |
| 353 |
|
|
| 354 |
|
$cid = $fid . $root; |
| 355 |
|
|
| 356 |
|
if (!isset($db_rules[$cid])) { |
| 357 |
|
$db_rules[$cid] = _customfilter_get_rules($fid, $root); |
| 358 |
|
} |
| 359 |
|
|
| 360 |
|
return $db_rules[$cid]; |
| 361 |
|
} |
| 362 |
|
|
| 363 |
|
/***************************************************************************** |
| 364 |
|
* Private functions. |
| 365 |
|
****************************************************************************/ |
| 366 |
|
|
| 367 |
|
/** |
| 368 |
|
* Retrieve the replacement rules for a specific filter. |
| 369 |
|
* |
| 370 |
|
* @param $fid |
| 371 |
|
* The filter ID. |
| 372 |
|
* @param $root |
| 373 |
|
* The root rule. |
| 374 |
|
* |
| 375 |
|
* @return |
| 376 |
|
* An array of rules, which include any subrules. |
| 377 |
|
*/ |
| 378 |
|
function _customfilter_get_rules($fid, $root) { |
| 379 |
$rules = array(); |
$rules = array(); |
| 380 |
$result = db_query("SELECT * FROM {customfilter_rules} WHERE fid = %d and prid = %d ORDER BY weight", $fid, $prid); |
|
| 381 |
|
$result = db_query("SELECT * FROM {customfilter_rules} WHERE fid = %d and prid = %d ORDER BY weight", $fid, $root); |
| 382 |
|
|
| 383 |
while ($rule = db_fetch_array($result)) { |
while ($rule = db_fetch_array($result)) { |
| 384 |
$rule['sub'] = customfilter_get_rules($fid, $rule['rid']); |
$rule['sub'] = _customfilter_get_rules($fid, $rule['rid']); |
| 385 |
|
|
| 386 |
// Create an anonymous function if the replacement string is PHP code. |
// Create an anonymous function if the replacement string is PHP code. |
| 387 |
if ($rule['code']) { |
if ($rule['code']) { |
| 388 |
$rule['function'] = create_function('$matches', '$vars =& _customfilter_code_vars(); '. $rule['replacement']); |
$rule['function'] = create_function('$matches', '$customfilter = CustomFilter::singleton(); '. $rule['replacement']); |
| 389 |
} |
} |
| 390 |
|
|
| 391 |
$rules[$rule['rid']] = $rule; |
$rules[$rule['rid']] = $rule; |
| 394 |
return $rules; |
return $rules; |
| 395 |
} |
} |
| 396 |
|
|
|
/***************************************************************************** |
|
|
* Private functions. |
|
|
****************************************************************************/ |
|
|
|
|
| 397 |
/** |
/** |
| 398 |
* Return the global object containing the global properties used in the |
* Return the global object containing the global properties used in the |
| 399 |
* replacement PHP code. |
* replacement PHP code. |