[ Index ] |
|
Code source de Horde 3.1.3 |
1 <?php 2 /** 3 * This is a utility class, every method is static. 4 * 5 * $Horde: framework/LDAP/LDAP.php,v 1.5.12.10 2006/01/01 21:28:23 jan Exp $ 6 * 7 * Copyright 1999-2006 Chuck Hagenbuch <chuck@horde.org> 8 * 9 * See the enclosed file COPYING for license information (LGPL). If you 10 * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. 11 * 12 * @author Chuck Hagenbuch <chuck@horde.org> 13 * @since Horde 2.2 14 * @package Horde_LDAP 15 */ 16 class Horde_LDAP { 17 18 /** 19 * Return a boolean expression using the specified operator. 20 * 21 * @static 22 * 23 * @param string $lhs The attribute to test. 24 * @param string $op The operator. 25 * @param string $rhs The comparison value. 26 * 27 * @return string The LDAP search fragment. 28 */ 29 function buildClause($lhs, $op, $rhs) 30 { 31 switch ($op) { 32 case 'LIKE': 33 return empty($rhs) ? 34 sprintf('(%s=*)', $lhs) : 35 sprintf('(%s=*%s*)', $lhs, Horde_LDAP::quote($rhs)); 36 37 default: 38 return sprintf('(%s%s%s)', $lhs, $op, Horde_LDAP::quote($rhs)); 39 } 40 } 41 42 /** 43 * Escape characters with special meaning in LDAP searches. 44 * 45 * @static 46 * 47 * @param string $clause The string to escape. 48 * 49 * @return string The escaped string. 50 */ 51 function quote($clause) 52 { 53 return str_replace(array('\\', '(', ')', '*', "\0"), 54 array('\\5c', '\(', '\)', '\*', "\\00"), 55 $clause); 56 } 57 58 /** 59 * Take an array of DN elements and properly quote it according to RFC 60 * 1485. 61 * 62 * @static 63 * 64 * @param array $parts An array of tuples containing the attribute 65 * name and that attribute's value which make 66 * up the DN. Example: 67 * 68 * $parts = array(0 => array('cn', 'John Smith'), 69 * 1 => array('dc', 'example'), 70 * 2 => array('dc', 'com')); 71 * 72 * @return string The properly quoted string DN. 73 */ 74 function quoteDN($parts) 75 { 76 $dn = ''; 77 $count = count($parts); 78 for ($i = 0; $i < $count; $i++) { 79 if ($i > 0) { 80 $dn .= ','; 81 } 82 $dn .= $parts[$i][0] . '='; 83 84 // See if we need to quote the value. 85 if (preg_match('/^\s|\s$|\s\s|[,+="\r\n<>#;]/', $parts[$i][1])) { 86 $dn .= '"' . str_replace('"', '\\"', $parts[$i][1]) . '"'; 87 } else { 88 $dn .= $parts[$i][1]; 89 } 90 } 91 92 return $dn; 93 } 94 95 }
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sun Feb 25 18:01:28 2007 | par Balluche grâce à PHPXref 0.7 |