Changeset 4205 in subversion
- Timestamp:
- Nov 9, 2010 4:04:28 PM (3 years ago)
- Location:
- trunk/plugins/kolab_addressbook
- Files:
-
- 3 edited
-
kolab_addressbook.php (modified) (4 diffs)
-
lib/rcube_kolab.php (modified) (3 diffs)
-
rcube_kolab_contacts.php (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/plugins/kolab_addressbook/kolab_addressbook.php
r4201 r4205 17 17 class kolab_addressbook extends rcube_plugin 18 18 { 19 private $kolab;20 19 private $folders; 21 20 private $sources; … … 31 30 $this->add_hook('addressbooks_list', array($this, 'address_sources')); 32 31 $this->add_hook('addressbook_get', array($this, 'get_address_book')); 33 $this->add_hook('imap_init', array($this, 'imap_init'));34 32 35 33 // extend include path to load bundled Horde classes 36 34 $include_path = $this->home . '/lib' . PATH_SEPARATOR . ini_get('include_path'); 37 35 set_include_path($include_path); 36 37 // extend list of address sources to be used for autocompletion 38 $rcmail = rcmail::get_instance(); 39 if ($rcmail->action == 'autocomplete' || $rcmail->action == 'group-expand') { 40 $sources = (array) $rcmail->config->get('autocomplete_addressbooks', array()); 41 foreach ($this->_list_sources() as $abook_id => $abook) { 42 if (!in_array($abook_id, $sources)) 43 $sources[] = $abook_id; 44 } 45 $rcmail->config->set('autocomplete_addressbooks', $sources); 46 } 38 47 } 39 48 … … 49 58 public function address_sources($p) 50 59 { 51 // setup Kolab backend 52 rcube_kolab::setup(); 60 foreach ($this->_list_sources() as $abook_id => $abook) { 61 // register this address source 62 $p['sources'][$abook_id] = array( 63 'id' => $abook_id, 64 'name' => $abook->get_name(), 65 'readonly' => $abook->readonly, 66 'groups' => $abook->groups, 67 ); 68 } 69 70 return $p; 71 } 72 73 74 /** 75 * Getter for the rcube_addressbook instance 76 */ 77 public function get_address_book($p) 78 { 79 if ($this->sources[$p['id']]) { 80 $p['instance'] = $this->sources[$p['id']]; 81 } 82 83 return $p; 84 } 85 86 87 private function _list_sources() 88 { 89 // already read sources 90 if (isset($this->sources)) 91 return $this->sources; 53 92 54 93 // get all folders that have "contact" type 55 $this-> kolab = Kolab_List::singleton();56 $this-> folders = $this->kolab->getByType('contact');94 $this->folders = rcube_kolab::get_folders('contact'); 95 $this->sources = array(); 57 96 58 97 if (PEAR::isError($this->folders)) { … … 69 108 $abook = new rcube_kolab_contacts($c_folder->name); 70 109 $this->sources[$abook_id] = $abook; 71 72 // register this address source73 $p['sources'][$abook_id] = array(74 'id' => $abook_id,75 'name' => $c_folder->name,76 'readonly' => $abook->readonly,77 'groups' => $abook->groups,78 );79 110 } 80 111 } 112 113 return $this->sources; 114 } 81 115 82 return $p;83 }84 85 86 /**87 * Getter for the rcube_addressbook instance88 */89 public function get_address_book($p)90 {91 if ($this->sources[$p['id']]) {92 $p['instance'] = $this->sources[$p['id']];93 }94 95 return $p;96 }97 98 99 /**100 * Make sure the X-Kolab-Type headers are also fetched when listing messages101 */102 function imap_init($p)103 {104 $p['fetch_headers'] = strtoupper('X-Kolab-Type');105 return $p;106 }107 116 } -
trunk/plugins/kolab_addressbook/lib/rcube_kolab.php
r4134 r4205 1 1 <?php 2 2 3 require_once 'Horde/Kolab/Format/XML.php';4 3 require_once 'Horde/Kolab/Storage/List.php'; 5 4 require_once 'Horde/Auth.php'; … … 16 15 { 17 16 private static $horde_auth; 17 18 18 19 19 /** … … 50 50 } 51 51 52 /** 53 * Get a list of storage folders for the given data type 54 * 55 * @param string Data type to list folders for (contact,event,task,note) 56 * @return array List of Kolab_Folder objects 57 */ 58 public static function get_folders($type) 59 { 60 self::setup(); 61 $kolab = Kolab_List::singleton(); 62 return $kolab->getByType($type); 63 } 52 64 65 /** 66 * Get storage object for read/write access to the Kolab backend 67 * 68 * @param string IMAP folder to access 69 * @param string Object type to deal with (leave empty for auto-detection using annotations) 70 * @return object Kolab_Data The data storage object 71 */ 72 public static function get_storage($folder, $data_type = null) 73 { 74 self::setup(); 75 $kolab = Kolab_List::singleton(); 76 return $kolab->getFolder($folder)->getData($data_type); 77 } 78 79 /** 80 * Cleanup session data when done 81 */ 82 public static function shutdown() 83 { 84 if (isset($_SESSION['__auth'])) { 85 // unset auth data from session. no need to store it persistantly 86 unset($_SESSION['__auth']); 87 88 // FIXME: remove strange numeric entries 89 foreach ($_SESSION as $key => $val) { 90 if (!$val && is_numeric($key)) 91 unset($_SESSION[$key]); 92 } 93 } 94 } 53 95 } -
trunk/plugins/kolab_addressbook/rcube_kolab_contacts.php
r4204 r4205 17 17 public $groups = true; 18 18 19 private static $instance;20 21 19 private $gid; 22 20 private $imap; … … 39 37 40 38 // fetch objects from the given IMAP folder 41 $this->kolab = Kolab_List::singleton(); 42 $this->folder = $this->kolab->getFolder($this->imap_folder); 43 $this->contactstorage = $this->folder->getData(); 44 $this->liststorage = $this->folder->getData('distributionlist'); 39 $this->contactstorage = rcube_kolab::get_storage($this->imap_folder); 40 $this->liststorage = rcube_kolab::get_storage($this->imap_folder, 'distributionlist'); 45 41 46 42 $this->ready = !PEAR::isError($this->contactstorage) && !PEAR::isError($this->liststorage); … … 49 45 50 46 /** 47 * Getter for the address book name to be displayed 48 * 49 * @return string Name of this address book 50 */ 51 public function get_name() 52 { 53 return strtr(preg_replace('!^(INBOX|user)/!i', '', $this->imap_folder), '/', ':'); 54 } 55 56 57 /** 51 58 * Setter for the current group 52 59 */ 53 function set_group($gid)60 public function set_group($gid) 54 61 { 55 62 $this->gid = $gid; … … 133 140 return $this->result; 134 141 } 142 143 144 /** 145 * Search records 146 * 147 * @param array List of fields to search in 148 * @param string Search value 149 * @param boolean True if results are requested, False if count only 150 * @return Indexed list of contact records and 'count' value 151 */ 152 public function search($fields, $value, $strict=false, $select=true) 153 { 154 // TODO: currently not implemented, just list all records 155 return $this->list_records(); 156 } 157 158 159 /** 160 * Count number of available contacts in database 161 * 162 * @return rcube_result_set Result set with values for 'count' and 'first' 163 */ 164 public function count() 165 { 166 $this->_fetch_data(); 167 $count = $this->gid ? count($this->distlists[$this->gid]['member']) : count($this->contacts); 168 return new rcube_result_set($count, ($this->list_page-1) * $this->page_size); 169 } 170 171 172 /** 173 * Return the last result set 174 * 175 * @return rcube_result_set Current result set or NULL if nothing selected yet 176 */ 177 public function get_result() 178 { 179 return $this->result; 180 } 181 182 /** 183 * Get a specific contact record 184 * 185 * @param mixed record identifier(s) 186 * @param boolean True to return record as associative array, otherwise a result set is returned 187 * @return mixed Result object with all record fields or False if not found 188 */ 189 public function get_record($id, $assoc=false) 190 { 191 $this->_fetch_data(); 192 if ($this->contacts[$id] && $assoc) { 193 return $this->contacts[$id]; 194 } 195 else if ($this->contacts[$id]) { 196 $this->result = new rcube_result_set(1); 197 $this->result->add($this->contacts[$id]); 198 return $this->result; 199 } 200 201 return false; 202 } 203 204 205 /** 206 * Get group assignments of a specific contact record 207 * 208 * @param mixed Record identifier 209 * @return array List of assigned groups as ID=>Name pairs 210 */ 211 function get_record_groups($id) 212 { 213 $out = array(); 214 215 foreach ($this->distlists as $gid => $group) { 216 foreach ($group['member'] as $member) { 217 if ($member['ID'] == $id) 218 $out[$gid] = $group['last-name']; 219 } 220 } 221 222 return $out; 223 } 135 224 136 225 226 /** 227 * Close connection to source 228 * Called on script shutdown 229 */ 230 function close() 231 { 232 rcube_kolab::shutdown(); 233 } 234 235 236 function create_group($name) 237 { 238 return false; 239 } 240 241 function delete_group($gid) 242 { 243 return false; 244 } 245 246 function rename_group($gid, $newname) 247 { 248 return $newname; 249 } 250 251 function add_to_group($group_id, $ids) 252 { 253 return false; 254 } 255 256 function remove_from_group($group_id, $ids) 257 { 258 return false; 259 } 260 261 137 262 /** 138 263 * Simply fetch all records and store them in private member vars … … 153 278 $this->distlists = array(); 154 279 foreach ((array)$this->liststorage->getObjects() as $record) { 280 // FIXME: folders without any distribution-list objects return contacts instead ?! 281 if ($record['__type'] != 'Group') 282 continue; 155 283 $record['ID'] = md5($record['uid']); 156 284 foreach ($record['member'] as $i => $member) … … 183 311 } 184 312 185 186 /**187 * Search records188 *189 * @param array List of fields to search in190 * @param string Search value191 * @param boolean True if results are requested, False if count only192 * @return Indexed list of contact records and 'count' value193 */194 public function search($fields, $value, $strict=false, $select=true)195 {196 // no search implemented, just list all records197 return $this->list_records();198 }199 200 201 /**202 * Count number of available contacts in database203 *204 * @return rcube_result_set Result set with values for 'count' and 'first'205 */206 public function count()207 {208 $this->_fetch_data();209 $count = $this->gid ? count($this->distlists[$this->gid]['member']) : count($this->contacts);210 return new rcube_result_set($count, ($this->list_page-1) * $this->page_size);211 }212 213 214 /**215 * Return the last result set216 *217 * @return rcube_result_set Current result set or NULL if nothing selected yet218 */219 public function get_result()220 {221 return $this->result;222 }223 224 /**225 * Get a specific contact record226 *227 * @param mixed record identifier(s)228 * @param boolean True to return record as associative array, otherwise a result set is returned229 * @return mixed Result object with all record fields or False if not found230 */231 public function get_record($id, $assoc=false)232 {233 $this->_fetch_data();234 if ($this->contacts[$id]) {235 $this->result = new rcube_result_set(1);236 $this->result->add($this->contacts[$id]);237 return $assoc ? $rec : $this->result;238 }239 240 return false;241 }242 243 244 /**245 * Get group assignments of a specific contact record246 *247 * @param mixed Record identifier248 * @return array List of assigned groups as ID=>Name pairs249 */250 function get_record_groups($id)251 {252 $out = array();253 254 foreach ($this->distlists as $gid => $group) {255 foreach ($group['member'] as $member) {256 if ($member['ID'] == $id)257 $out[$gid] = $group['last-name'];258 }259 }260 261 return $out;262 }263 264 265 /**266 * Close connection to source267 * Called on script shutdown268 */269 function close()270 {271 272 }273 274 275 function create_group($name)276 {277 return false;278 }279 280 function delete_group($gid)281 {282 return false;283 }284 285 function rename_group($gid, $newname)286 {287 return $newname;288 }289 290 function add_to_group($group_id, $ids)291 {292 return false;293 }294 295 function remove_from_group($group_id, $ids)296 {297 return false;298 }299 300 313 }
Note: See TracChangeset
for help on using the changeset viewer.
