phpDocumentor lodel
[ class tree: lodel ] [ index: lodel ] [ all elements ]

Source for file filterfunc.php

Documentation is available at filterfunc.php

  1. <?
  2. /**
  3. * Fichier de gestion des filtres
  4. *
  5. * PHP versions 4 et 5
  6. *
  7. * LODEL - Logiciel d'Edition ELectronique.
  8. *
  9. * Copyright (c) 2001-2002, Ghislain Picard, Marin Dacos
  10. * Copyright (c) 2003, Ghislain Picard, Marin Dacos, Luc Santeramo, Nicolas Nutten, Anne Gentil-Beccot
  11. * Copyright (c) 2004, Ghislain Picard, Marin Dacos, Luc Santeramo, Anne Gentil-Beccot, Bruno Cénou
  12. * Copyright (c) 2005, Ghislain Picard, Marin Dacos, Luc Santeramo, Gautier Poupeau, Jean Lamy, Bruno Cénou
  13. * Copyright (c) 2006, Marin Dacos, Luc Santeramo, Bruno Cénou, Jean Lamy, Mikaël Cixous, Sophie Malafosse
  14. * Copyright (c) 2007, Marin Dacos, Bruno Cénou, Sophie Malafosse, Pierre-Alain Mignot
  15. *
  16. * Home page: http://www.lodel.org
  17. *
  18. * E-Mail: lodel@lodel.org
  19. *
  20. * All Rights Reserved
  21. *
  22. * This program is free software; you can redistribute it and/or modify
  23. * it under the terms of the GNU General Public License as published by
  24. * the Free Software Foundation; either version 2 of the License, or
  25. * (at your option) any later version.
  26. *
  27. * This program is distributed in the hope that it will be useful,
  28. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  29. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  30. * GNU General Public License for more details.
  31. *
  32. * You should have received a copy of the GNU General Public License
  33. * along with this program; if not, write to the Free Software
  34. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  35. *
  36. @author Ghislain Picard
  37. @author Jean Lamy
  38. @copyright 2005, Ghislain Picard, Marin Dacos, Luc Santeramo, Gautier Poupeau, Jean Lamy, Bruno Cénou
  39. @copyright 2006, Marin Dacos, Luc Santeramo, Bruno Cénou, Jean Lamy, Mikaël Cixous, Sophie Malafosse
  40. @copyright 2007, Marin Dacos, Bruno Cénou, Sophie Malafosse, Pierre-Alain Mignot
  41. @licence http://www.gnu.org/copyleft/gpl.html
  42. @version CVS:$Id:
  43. @package lodel
  44. */
  45.  
  46.  
  47.  
  48. require_once 'CACHE/filterfunc.php';
  49.  
  50. /**
  51. * Filtre les champs qu'il faut filtrer et converti les filtres en fonction
  52. *
  53. */
  54. function makefilterfunc()
  55. {
  56.     global $db;
  57.     require_once 'connect.php';
  58.     // cherche les champs a filtrer    
  59.     $result $db->execute(lq("SELECT class,name,filtering FROM #_TP_tablefields WHERE status > 0 AND filtering!=''")) or dberror();
  60.     while (!$result->EOF)    {
  61.         $row $result->fields;
  62.         // convert filter into a function
  63.         $filters preg_split("/\|/"$row['filtering']);
  64.         #$filters = explode('|',$row['filter']);
  65.         $filterfunc '$x';
  66.         foreach ($filters as $filter)    {
  67.             if (preg_match("/^([A-Za-z][A-Za-z_0-9]*)(?:\((.*?)\))?$/"$filter$result2)) {
  68.                 $funcname $result2[1]// name of the pipe function
  69.                 $arg $result2[2]// argument if any
  70.  
  71.                 // process the variable. The processing is simple here. Need more ? Sould be associated with parser variable processing.
  72.                 $arg preg_replace("/\[\#([A-Z][A-Z_0-9]*)\]/e"' "$"."context[".strtolower("\\1")."]" '$arg);
  73.  
  74.                 if ($arg{
  75.                     $arg ','$arg;
  76.                 }
  77.                 $filterfunc $funcname.'('.$filterfunc.$arg.')';
  78.             }    elseif ($filter)    {
  79.                 die("invalid filter function$filter");
  80.             // do nothing if $filter is empty
  81.         }
  82.         $filterfunc "return "$filterfunc";";
  83.         $filterstr .= "'"$row['class'].'.'$row['name']"' => '"addcslashes($filterfunc"'")."',";
  84.             #echo "filterstr=$filterstr";
  85.         $result->MoveNext();
  86.     }
  87.     // build the function with filtering
  88.     // to update with ADODB
  89.     $fp fopen("CACHE/filterfunc.php""w");
  90.     fputs($fp'<'.'?php function filtered_mysql_fetch_assoc($context, $result) {
  91.             $filters = array('.$filterstr.');
  92.         $count = mysql_num_fields($result);
  93.         $row = mysql_fetch_row($result);
  94.         if (!$row) return array();
  95.         for($i = 0; $i < $count; $i++) {
  96.             $fieldname[$i] = mysql_field_name($result, $i);
  97.             $fullfieldname[$i] = mysql_field_table($result,$i). ".". $fieldname[$i];
  98.             $ret[$fieldname[$i]] = $row[$i];
  99.         }
  100.         $localcontext=array_merge($context, $ret);
  101.         for($i = 0; $i < $count; $i++) {
  102.             if ($filters[$fullfieldname[$i]]) {
  103.                     $filter = create_function(\'$x, $context\', $filters[$fullfieldname[$i]]);
  104.                     $ret[$fieldname[$i]] = $filter($ret[$fieldname[$i]], $localcontext);
  105.     # echo $filters[$fullfieldname[$i]], " ", $fieldname[$i], " ", $ret[$fieldname[$i]]," ", $filter, "<br>";
  106.             }
  107.         }
  108.         return $ret;
  109.     }
  110.     
  111.     /**
  112.     * Function to filter field of a single class.
  113.     */
  114.     function merge_and_filter_fields(&$context, $class, &$assoc)
  115.     {
  116.         $filters = array('$filterstr');
  117.         $localcontext = array_merge($context, $assoc);
  118.         foreach($assoc as $k=>$v) {
  119.             if ($filters[$class. ".". $k]) {
  120.                 $filter = create_function(\'$x, $context\', $filters[$class. ".". $k]);
  121.                 $context[$k] = $filter($v, $localcontext);
  122.             } else {
  123.         $context[$k] = $v;
  124.             }
  125.         }
  126.     }
  127.     ?'.'>');
  128.     fclose($fp);
  129.  
  130. }
  131. ?>

Documentation generated on Thu, 10 Jul 2008 05:07:33 +0200 by phpDocumentor 1.4.0a2