Replace ereg() function call by preg_match()

This commit is contained in:
Benjamin Renard 2018-01-08 19:08:39 +01:00
parent 593a4c5e96
commit 7c45bfe833
9 changed files with 22 additions and 24 deletions

View file

@ -43,7 +43,7 @@
<varlistentry> <varlistentry>
<term>remoteRootPathRegex</term> <term>remoteRootPathRegex</term>
<listitem> <listitem>
<simpara>Expression régulière facultative dont le but est de <simpara>Expression régulière (compatible Perl) facultative dont le but est de
<emphasis>matcher</emphasis> dans la valeur complète du chemin distant de la <emphasis>matcher</emphasis> dans la valeur complète du chemin distant de la
<emphasis>maildir</emphasis>, le chemin de la <emphasis>maildir</emphasis> <emphasis>maildir</emphasis>, le chemin de la <emphasis>maildir</emphasis>
à créer une fois connecté sur le serveur.</simpara> à créer une fois connecté sur le serveur.</simpara>
@ -52,7 +52,7 @@
se connecte arrive directement dans <emphasis>/home/vmail</emphasis>, et faut se connecte arrive directement dans <emphasis>/home/vmail</emphasis>, et faut
définir le paramètre <parameter>remoteRootPathRegex</parameter> de la manière définir le paramètre <parameter>remoteRootPathRegex</parameter> de la manière
suivante : suivante :
<programlisting linenumbering="unnumbered">^\/home\/vmail\/([^\/]*)\/+$</programlisting> <programlisting linenumbering="unnumbered">/^\/home\/vmail\/([^\/]*)\/+$/</programlisting>
</para> </para>
</listitem> </listitem>
</varlistentry> </varlistentry>

View file

@ -41,10 +41,8 @@ define('LS_MAILDIR_FTP_PWD','password');
// Serveur FTP - Maildir Path // Serveur FTP - Maildir Path
define('LS_MAILDIR_FTP_MAILDIR_PATH','%{mailbox}'); define('LS_MAILDIR_FTP_MAILDIR_PATH','%{mailbox}');
// Serveur FTP - Maildir Path Regex // Serveur FTP - Maildir Path Regex (Perl compatible)
define('LS_MAILDIR_FTP_MAILDIR_PATH_REGEX','^\/home\/vmail\/([^\/]+)\/$'); define('LS_MAILDIR_FTP_MAILDIR_PATH_REGEX','/^\/home\/vmail\/([^\/]+)\/$/');
// Serveur FTP - Maildir CHMOD // Serveur FTP - Maildir CHMOD
define('LS_MAILDIR_FTP_MAILDIR_CHMOD','700'); define('LS_MAILDIR_FTP_MAILDIR_CHMOD','700');
?>

View file

@ -146,7 +146,7 @@ $retval=true;
$dir = getFData(LS_MAILDIR_FTP_MAILDIR_PATH,$ldapObject,'getValue'); $dir = getFData(LS_MAILDIR_FTP_MAILDIR_PATH,$ldapObject,'getValue');
if (LS_MAILDIR_FTP_MAILDIR_PATH_REGEX != "") { if (LS_MAILDIR_FTP_MAILDIR_PATH_REGEX != "") {
if (ereg(LS_MAILDIR_FTP_MAILDIR_PATH_REGEX,$dir,$regs)) { if (preg_match(LS_MAILDIR_FTP_MAILDIR_PATH_REGEX,$dir,$regs)) {
$dir = $regs[1]; $dir = $regs[1];
} }
else { else {

View file

@ -114,7 +114,7 @@ class LSattr_html_maildir extends LSattr_html {
} }
if ($this -> config['html_options']['remoteRootPathRegex']) { if ($this -> config['html_options']['remoteRootPathRegex']) {
if ( if (
ereg($this -> config['html_options']['remoteRootPathRegex'],$val,$r) preg_match($this -> config['html_options']['remoteRootPathRegex'],$val,$r)
|| ||
empty($val) empty($val)
) )

View file

@ -54,7 +54,7 @@ class LSformElement_mailQuota extends LSformElement {
$quotas=array(); $quotas=array();
foreach ($this -> values as $value) { foreach ($this -> values as $value) {
if (ereg('([0-9]*)'.$this -> getSuffix(),$value,$regs)) { if (preg_match('/([0-9]*)/'.$this -> getSuffix(),$value,$regs)) {
$infos = array( $infos = array(
'size' => $regs[1] 'size' => $regs[1]
); );

View file

@ -54,7 +54,7 @@ class LSformElement_quota extends LSformElement {
$quotas=array(); $quotas=array();
foreach ($this -> values as $value) { foreach ($this -> values as $value) {
if (ereg('^([0-9]*)$',$value,$regs)) { if (preg_match('/^([0-9]*)$/',$value,$regs)) {
$infos = array( $infos = array(
'size' => ceil($regs[1]/$this -> getFactor()) 'size' => ceil($regs[1]/$this -> getFactor())
); );

View file

@ -87,7 +87,7 @@ class LSformElement_valueWithUnit extends LSformElement {
if ($units) { if ($units) {
foreach ($this -> values as $value) { foreach ($this -> values as $value) {
if (ereg('^([0-9]*)$',$value,$regs)) { if (preg_match('/^([0-9]*)$/',$value,$regs)) {
$infos = array( $infos = array(
'value' => $regs[1] 'value' => $regs[1]
); );

View file

@ -394,15 +394,15 @@ class LSsession {
public static function getLangList() { public static function getLangList() {
$list=array('en_US'); $list=array('en_US');
if (self :: $encoding) { if (self :: $encoding) {
$regex = '^([a-zA-Z_]*)\.'.self :: $encoding.'$'; $regex = '/^([a-zA-Z_]*)\.'.self :: $encoding.'$/';
} }
else { else {
$regex = '^([a-zA-Z_]*)$'; $regex = '/^([a-zA-Z_]*)$/';
} }
if ($handle = opendir(LS_I18N_DIR)) { if ($handle = opendir(LS_I18N_DIR)) {
while (false !== ($file = readdir($handle))) { while (false !== ($file = readdir($handle))) {
if(is_dir(LS_I18N_DIR.'/'.$file)) { if(is_dir(LS_I18N_DIR.'/'.$file)) {
if (ereg($regex,$file,$regs)) { if (preg_match($regex,$file,$regs)) {
if (!in_array($regs[1],$list)) { if (!in_array($regs[1],$list)) {
$list[]=$regs[1]; $list[]=$regs[1];
} }

View file

@ -52,7 +52,7 @@ function getFData($format,$data,$meth=NULL) {
* - 7 : ! or _ * - 7 : ! or _
* - 8 : ~ * - 8 : ~
*/ */
$expr="%[{(]([A-Za-z0-9]+)(\:(-?[0-9])+)?(\:(-?[0-9]+))?(-)?(\!|\_)?(~)?[})]"; $expr="/%[{(]([A-Za-z0-9]+)(\:(-?[0-9])+)?(\:(-?[0-9]+))?(-)?(\!|\_)?(~)?[})]/";
if(!is_array($format)) { if(!is_array($format)) {
$format=array($format); $format=array($format);
$unique=true; $unique=true;
@ -60,7 +60,7 @@ function getFData($format,$data,$meth=NULL) {
for($i=0;$i<count($format);$i++) { for($i=0;$i<count($format);$i++) {
if(is_array($data)) { if(is_array($data)) {
if ($meth==NULL) { if ($meth==NULL) {
while (ereg($expr,$format[$i],$ch)) { while (preg_match($expr,$format[$i],$ch)) {
if (is_array($data[$ch[1]])) { if (is_array($data[$ch[1]])) {
$val = $data[$ch[1]][0]; $val = $data[$ch[1]][0];
} }
@ -72,7 +72,7 @@ function getFData($format,$data,$meth=NULL) {
} }
} }
else { else {
while (ereg($expr,$format[$i],$ch)) { while (preg_match($expr,$format[$i],$ch)) {
if (method_exists($data[$ch[1]],$meth)) { if (method_exists($data[$ch[1]],$meth)) {
$value = $data[$ch[1]] -> $meth(); $value = $data[$ch[1]] -> $meth();
if (is_array($value)) { if (is_array($value)) {
@ -90,7 +90,7 @@ function getFData($format,$data,$meth=NULL) {
} }
elseif (is_object($data)) { elseif (is_object($data)) {
if ($meth==NULL) { if ($meth==NULL) {
while (ereg($expr,$format[$i],$ch)) { while (preg_match($expr,$format[$i],$ch)) {
$value = $data -> $ch[1]; $value = $data -> $ch[1];
if (is_array($value)) { if (is_array($value)) {
$value = $value[0]; $value = $value[0];
@ -100,7 +100,7 @@ function getFData($format,$data,$meth=NULL) {
} }
} }
else { else {
while (ereg($expr,$format[$i],$ch)) { while (preg_match($expr,$format[$i],$ch)) {
if (method_exists($data,$meth)) { if (method_exists($data,$meth)) {
$value = $data -> $meth($ch[1]); $value = $data -> $meth($ch[1]);
if (is_array($value)) { if (is_array($value)) {
@ -117,7 +117,7 @@ function getFData($format,$data,$meth=NULL) {
} }
} }
else { else {
while (ereg($expr,$format[$i],$ch)) { while (preg_match($expr,$format[$i],$ch)) {
$val=_getFData_extractAndModify($data,$ch); $val=_getFData_extractAndModify($data,$ch);
$format[$i]=str_replace($ch[0],$val,$format[$i]); $format[$i]=str_replace($ch[0],$val,$format[$i]);
} }
@ -194,18 +194,18 @@ function _getFData_extractAndModify($data,$ch) {
function getFieldInFormat($format) { function getFieldInFormat($format) {
$fields=array(); $fields=array();
$expr="%[{(]([A-Za-z0-9]+)(\:(-?[0-9])+)?(\:(-?[0-9]+))?(-)?(\!|\_)?(~)?[})]"; $expr='/%[{(]([A-Za-z0-9]+)(\:(-?[0-9])+)?(\:(-?[0-9]+))?(-)?(\!|\_)?(~)?[})]/';
while (ereg($expr,$format,$ch)) { while (preg_match($expr,$format,$ch)) {
$fields[]=$ch[1]; $fields[]=$ch[1];
$format=str_replace($ch[0],'',$format); $format=str_replace($ch[0],'',$format);
} }
return $fields; return $fields;
} }
function loadDir($dir,$regexpr='^.*\.php$') { function loadDir($dir,$regexpr='/^.*\.php$/') {
if ($handle = opendir($dir)) { if ($handle = opendir($dir)) {
while (false !== ($file = readdir($handle))) { while (false !== ($file = readdir($handle))) {
if (ereg($regexpr,$file)) { if (preg_match($regexpr,$file)) {
require_once($dir.'/'.$file); require_once($dir.'/'.$file);
} }
} }