Selaa lähdekoodia

adding listing controls to file backend

tokul 20 vuotta sitten
vanhempi
commit
dcac815ab4
2 muutettua tiedostoa jossa 24 lisäystä ja 5 poistoa
  1. 14 0
      functions/abook_local_file.php
  2. 10 5
      functions/addressbook.php

+ 14 - 0
functions/abook_local_file.php

@@ -26,6 +26,7 @@
  *                checking file permissions.
  *                checking file permissions.
  * ? writeable => allow writing into address book. Used only when
  * ? writeable => allow writing into address book. Used only when
  *                detect_writeable is set to false.
  *                detect_writeable is set to false.
+ * ? listing   => enable/disable listing
  *</pre>
  *</pre>
  * NOTE. This class should not be used directly. Use the
  * NOTE. This class should not be used directly. Use the
  *       "AddressBook" class instead.
  *       "AddressBook" class instead.
@@ -70,6 +71,11 @@ class abook_local_file extends addressbook_backend {
      * @var bool
      * @var bool
      */
      */
     var $writeable = false;
     var $writeable = false;
+    /**
+     * controls listing of address book
+     * @var bool
+     */
+    var $listing = true;
     /**
     /**
      * Umask of the file
      * Umask of the file
      * @var string
      * @var string
@@ -113,6 +119,9 @@ class abook_local_file extends addressbook_backend {
             if(!empty($param['writeable'])) {
             if(!empty($param['writeable'])) {
                 $this->writeable = $param['writeable'];
                 $this->writeable = $param['writeable'];
             }
             }
+            if(isset($param['listing'])) {
+                $this->listing = $param['listing'];
+            }
 
 
             $this->open(true);
             $this->open(true);
         } else {
         } else {
@@ -315,6 +324,11 @@ class abook_local_file extends addressbook_backend {
      */
      */
     function list_addr() {
     function list_addr() {
         $res = array();
         $res = array();
+
+        if(isset($this->listing) && !$this->listing) {
+            return array();
+        }
+
         $this->open();
         $this->open();
         @rewind($this->filehandle);
         @rewind($this->filehandle);
 
 

+ 10 - 5
functions/addressbook.php

@@ -35,7 +35,7 @@ global $addrbook_dsn, $addrbook_global_dsn;
 function addressbook_init($showerr = true, $onlylocal = false) {
 function addressbook_init($showerr = true, $onlylocal = false) {
     global $data_dir, $username, $color, $ldap_server, $address_book_global_filename;
     global $data_dir, $username, $color, $ldap_server, $address_book_global_filename;
     global $addrbook_dsn, $addrbook_table;
     global $addrbook_dsn, $addrbook_table;
-    global $abook_global_file, $abook_global_file_writeable;
+    global $abook_global_file, $abook_global_file_writeable, $abook_global_file_listing;
     global $addrbook_global_dsn, $addrbook_global_table, $addrbook_global_writeable, $addrbook_global_listing;
     global $addrbook_global_dsn, $addrbook_global_table, $addrbook_global_writeable, $addrbook_global_listing;
 
 
     /* Create a new addressbook object */
     /* Create a new addressbook object */
@@ -72,9 +72,12 @@ function addressbook_init($showerr = true, $onlylocal = false) {
 
 
     }
     }
 
 
-    /* This would be for the global addressbook */
-    if (isset($abook_global_file) && isset($abook_global_file_writeable)
-        && trim($abook_global_file)!=''){
+    /* Global file based addressbook */
+    if (isset($abook_global_file) && 
+        isset($abook_global_file_writeable) &&
+        isset($abook_global_file_listing) &&
+        trim($abook_global_file)!=''){
+
         // Detect place of address book
         // Detect place of address book
         if (! preg_match("/[\/\\\]/",$abook_global_file)) {
         if (! preg_match("/[\/\\\]/",$abook_global_file)) {
             /* no path chars, address book stored in data directory
             /* no path chars, address book stored in data directory
@@ -90,10 +93,12 @@ function addressbook_init($showerr = true, $onlylocal = false) {
         } else {
         } else {
             $abook_global_filename=SM_PATH . $abook_global_file;
             $abook_global_filename=SM_PATH . $abook_global_file;
         }
         }
+
         $r = $abook->add_backend('local_file',array('filename'=>$abook_global_filename,
         $r = $abook->add_backend('local_file',array('filename'=>$abook_global_filename,
                                                     'name' => _("Global address book"),
                                                     'name' => _("Global address book"),
                                                     'detect_writeable' => false,
                                                     'detect_writeable' => false,
-                                                    'writeable'=> $abook_global_file_writeable));
+                                                    'writeable'=> $abook_global_file_writeable,
+                                                    'listing' => $abook_global_file_listing));
 
 
         /* global abook init error is not fatal. add error message and continue */
         /* global abook init error is not fatal. add error message and continue */
         if (!$r && $showerr) {
         if (!$r && $showerr) {