X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=functions%2Fabook_local_file.php;h=274e19dad0b4c3c88bbace443271cdbb5331b776;hb=7fc4b14fdb798a7b1c1d003163afa5865cce01f4;hp=cf91099862f1d7c9851b915ee1b0235c18ac20dc;hpb=91e0dccca7b2452d8b450791cae3aa4125e8889e;p=squirrelmail.git diff --git a/functions/abook_local_file.php b/functions/abook_local_file.php index cf910998..274e19da 100644 --- a/functions/abook_local_file.php +++ b/functions/abook_local_file.php @@ -1,10 +1,10 @@ allow writing into address book. Used only when * detect_writeable is set to false. + * ? listing => enable/disable listing * * NOTE. This class should not be used directly. Use the * "AddressBook" class instead. @@ -70,6 +71,11 @@ class abook_local_file extends addressbook_backend { * @var bool */ var $writeable = false; + /** + * controls listing of address book + * @var bool + */ + var $listing = true; /** * Umask of the file * @var string @@ -113,6 +119,9 @@ class abook_local_file extends addressbook_backend { if(!empty($param['writeable'])) { $this->writeable = $param['writeable']; } + if(isset($param['listing'])) { + $this->listing = $param['listing']; + } $this->open(true); } else { @@ -132,7 +141,7 @@ class abook_local_file extends addressbook_backend { $this->error = ''; $file = $this->filename; $create = $this->create; - $fopenmode = ($this->writeable ? 'a+' : 'r'); + $fopenmode = (($this->writeable && is_writable($file)) ? 'a+' : 'r'); /* Return true is file is open and $new is unset */ if($this->filehandle && !$new) { @@ -250,6 +259,10 @@ class abook_local_file extends addressbook_backend { /* To be replaced by advanded search expression parsing */ if(is_array($expr)) { return; } + // don't allow wide search when listing is disabled. + if ($expr=='*' && ! $this->listing) + return array(); + /* Make regexp from glob'ed expression * May want to quote other special characters like (, ), -, [, ], etc. */ $expr = str_replace('?', '.', $expr); @@ -263,7 +276,12 @@ class abook_local_file extends addressbook_backend { while ($row = @fgetcsv($this->filehandle, 2048, '|')) { $line = join(' ', $row); - if(eregi($expr, $line)) { + /** + * TODO: regexp search is supported only in local_file backend. + * Do we check format of regexp or ignore errors? + */ + // errors on eregi call are suppressed in order to prevent display of regexp compilation errors + if(@eregi($expr, $line)) { array_push($res, array('nickname' => $row[0], 'name' => $row[1] . ' ' . $row[2], 'firstname' => $row[1], @@ -315,6 +333,11 @@ class abook_local_file extends addressbook_backend { */ function list_addr() { $res = array(); + + if(isset($this->listing) && !$this->listing) { + return array(); + } + $this->open(); @rewind($this->filehandle); @@ -343,16 +366,16 @@ class abook_local_file extends addressbook_backend { /* See if user exists already */ $ret = $this->lookup($userdata['nickname']); if(!empty($ret)) { - return $this->set_error(sprintf(_("User '%s' already exist"), - $ret['nickname'])); + // i18n: don't use html formating in translation + return $this->set_error(sprintf(_("User \"%s\" already exists"),$ret['nickname'])); } /* Here is the data to write */ $data = $this->quotevalue($userdata['nickname']) . '|' . $this->quotevalue($userdata['firstname']) . '|' . - $this->quotevalue($userdata['lastname']) . '|' . + $this->quotevalue((!empty($userdata['lastname'])?$userdata['lastname']:'')) . '|' . $this->quotevalue($userdata['email']) . '|' . - $this->quotevalue($userdata['label']); + $this->quotevalue((!empty($userdata['label'])?$userdata['label']:'')); /* Strip linefeeds */ $data = ereg_replace("[\r\n]", ' ', $data); @@ -436,8 +459,8 @@ class abook_local_file extends addressbook_backend { /* See if user exists */ $ret = $this->lookup($alias); if(empty($ret)) { - return $this->set_error(sprintf(_("User '%s' does not exist"), - $alias)); + // i18n: don't use html formating in translation + return $this->set_error(sprintf(_("User \"%s\" does not exist"),$alias)); } /* Lock the file to make sure we're the only process working @@ -458,9 +481,9 @@ class abook_local_file extends addressbook_backend { } else { $rows[$i++] = array(0 => $userdata['nickname'], 1 => $userdata['firstname'], - 2 => $userdata['lastname'], + 2 => (!empty($userdata['lastname'])?$userdata['lastname']:''), 3 => $userdata['email'], - 4 => $userdata['label']); + 4 => (!empty($userdata['label'])?$userdata['label']:'')); } } @@ -489,4 +512,4 @@ class abook_local_file extends addressbook_backend { } } /* End of class abook_local_file */ -?> \ No newline at end of file +?>