| 1 |
<?php |
<?php |
| 2 |
// $Id: customfilter.module,v 1.3.2.1.2.16.2.18 2009/07/01 01:36:22 kiam Exp $ |
// $Id: customfilter.module,v 1.3.2.1.2.16.2.19 2009/07/01 02:32:38 kiam Exp $ |
| 3 |
|
|
| 4 |
/** |
/** |
| 5 |
* @file |
* @file |
| 345 |
* An array that describes the filter identified by $fid. |
* An array that describes the filter identified by $fid. |
| 346 |
*/ |
*/ |
| 347 |
function customfilter_get_filter($fid) { |
function customfilter_get_filter($fid) { |
| 348 |
$filter = db_fetch_array(db_query("SELECT * FROM {customfilter_filters} WHERE fid = %d", $fid)); |
$filters = customfilter_get_filters(FALSE); |
| 349 |
|
|
| 350 |
return $filter; |
return isset($filters[$fid]) ? $filters[$fid] : 0; |
| 351 |
} |
} |
| 352 |
|
|
| 353 |
/** |
/** |
| 354 |
* Get the list of filters from database. |
* Get the list of filters. |
| 355 |
* |
* |
| 356 |
* @param $fields |
* @param $all |
| 357 |
* The fields to retrieve. |
* If TRUE, the function will return the list of filters as modified by |
| 358 |
* @param $cond |
* third-party modules. |
|
* 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. |
|
| 359 |
* |
* |
| 360 |
* @return |
* @return |
| 361 |
* An array of filters. |
* An array of filters. |
| 362 |
*/ |
*/ |
| 363 |
function customfilter_get_filters($all = TRUE) { |
function customfilter_get_filters($all = TRUE) { |
| 364 |
$filters = array(); |
static $db_filters; |
|
$query = "SELECT * FROM {customfilter_filters} ORDER BY name"; |
|
| 365 |
|
|
| 366 |
$result = db_query($query); |
if (!isset($db_filters)) { |
| 367 |
while ($filter = db_fetch_array($result)) { |
$db_filters = array(); |
| 368 |
$filters[] = $filter; |
$query = "SELECT * FROM {customfilter_filters} ORDER BY name"; |
| 369 |
|
|
| 370 |
|
$result = db_query($query); |
| 371 |
|
while ($filter = db_fetch_array($result)) { |
| 372 |
|
$db_filters[] = $filter; |
| 373 |
|
} |
| 374 |
} |
} |
| 375 |
|
|
| 376 |
|
$filters = $db_filters; |
| 377 |
|
|
| 378 |
if ($all) { |
if ($all) { |
| 379 |
drupal_alter('customfilter_filters', $filters); |
drupal_alter('customfilter_filters', $filters); |
| 380 |
} |
} |
| 383 |
} |
} |
| 384 |
|
|
| 385 |
/** |
/** |
| 386 |
* Retrieve the replacement rules from the database table. |
* Retrieve the replacement rules for a specific filter. |
| 387 |
* |
* |
| 388 |
* @param $fid |
* @param $fid |
| 389 |
* The filter ID. |
* The filter ID. |
| 390 |
* @param $root |
* @param $root |
| 391 |
* The root rule. |
* The root rule. |
| 392 |
* @param $sortby |
* @param $all |
| 393 |
* The database field used to sort the result; the default field used is the |
* If TRUE, the function will return the list of filters as modified by |
| 394 |
* weight field. |
* third-party modules. |
|
* @param $fields |
|
|
* The fields to retrieve. |
|
| 395 |
* |
* |
| 396 |
* @return |
* @return |
| 397 |
* An array of rules, which include any subrules. |
* An array of rules, which include any subrules. |
| 398 |
*/ |
*/ |
| 399 |
function customfilter_get_rules($fid, $root = 0, $all = TRUE) { |
function customfilter_get_rules($fid, $root = 0, $all = TRUE) { |
| 400 |
|
static $db_rules = array(); |
| 401 |
|
|
| 402 |
|
$cid = $fid . $root; |
| 403 |
|
|
| 404 |
|
if (!isset($db_rules[$cid])) { |
| 405 |
|
$db_rules[$cid] = _customfilter_get_rules($fid, $root); |
| 406 |
|
} |
| 407 |
|
|
| 408 |
|
$rules = $db_rules[$cid]; |
| 409 |
|
|
| 410 |
|
if ($all) { |
| 411 |
|
drupal_alter('customfilter_rules', $rules, $fid, $root); |
| 412 |
|
} |
| 413 |
|
|
| 414 |
|
return $rules; |
| 415 |
|
} |
| 416 |
|
|
| 417 |
|
/***************************************************************************** |
| 418 |
|
* Private functions. |
| 419 |
|
****************************************************************************/ |
| 420 |
|
|
| 421 |
|
/** |
| 422 |
|
* Retrieve the replacement rules for a specific filter. |
| 423 |
|
* |
| 424 |
|
* @param $fid |
| 425 |
|
* The filter ID. |
| 426 |
|
* @param $root |
| 427 |
|
* The root rule. |
| 428 |
|
* |
| 429 |
|
* @return |
| 430 |
|
* An array of rules, which include any subrules. |
| 431 |
|
*/ |
| 432 |
|
function _customfilter_get_rules($fid, $root) { |
| 433 |
$rules = array(); |
$rules = array(); |
| 434 |
|
|
| 435 |
$result = db_query("SELECT * FROM {customfilter_rules} WHERE fid = %d and prid = %d ORDER BY weight", $fid, $root); |
$result = db_query("SELECT * FROM {customfilter_rules} WHERE fid = %d and prid = %d ORDER BY weight", $fid, $root); |
| 436 |
|
|
| 437 |
while ($rule = db_fetch_array($result)) { |
while ($rule = db_fetch_array($result)) { |
| 438 |
$rule['sub'] = customfilter_get_rules($fid, $rule['rid']); |
$rule['sub'] = _customfilter_get_rules($fid, $rule['rid']); |
| 439 |
|
|
| 440 |
// Create an anonymous function if the replacement string is PHP code. |
// Create an anonymous function if the replacement string is PHP code. |
| 441 |
if ($rule['code']) { |
if ($rule['code']) { |
| 445 |
$rules[$rule['rid']] = $rule; |
$rules[$rule['rid']] = $rule; |
| 446 |
} |
} |
| 447 |
|
|
|
if ($all) { |
|
|
drupal_alter('customfilter_rules', $rules); |
|
|
} |
|
|
|
|
| 448 |
return $rules; |
return $rules; |
| 449 |
} |
} |
| 450 |
|
|
|
/***************************************************************************** |
|
|
* Private functions. |
|
|
****************************************************************************/ |
|
|
|
|
| 451 |
/** |
/** |
| 452 |
* Return an object that contains the global variables used during the |
* Return an object that contains the global variables used during the |
| 453 |
* execution of a rule. |
* execution of a rule. |