Exemplo n.º 1
0
 /**
  * Handler for attendee group expansion requests
  */
 public function expand_attendee_group()
 {
     $id = rcube_utils::get_input_value('id', rcube_utils::INPUT_POST);
     $data = rcube_utils::get_input_value('data', rcube_utils::INPUT_POST, true);
     $result = array('id' => $id, 'members' => array());
     $maxnum = 500;
     // iterate over all autocomplete address books (we don't know the source of the group)
     foreach ((array) $this->rc->config->get('autocomplete_addressbooks', 'sql') as $abook_id) {
         if (($abook = $this->rc->get_address_book($abook_id)) && $abook->groups) {
             foreach ($abook->list_groups($data['name'], 1) as $group) {
                 // this is the matching group to expand
                 if (in_array($data['email'], (array) $group['email'])) {
                     $abook->set_pagesize($maxnum);
                     $abook->set_group($group['ID']);
                     // get all members
                     $res = $abook->list_records($this->rc->config->get('contactlist_fields'));
                     // handle errors (e.g. sizelimit, timelimit)
                     if ($abook->get_error()) {
                         $result['error'] = $this->rc->gettext('expandattendeegrouperror', 'libcalendaring');
                         $res = false;
                     } else {
                         if ($res->count > $maxnum) {
                             $result['error'] = $this->rc->gettext('expandattendeegroupsizelimit', 'libcalendaring');
                             $res = false;
                         }
                     }
                     while ($res && ($member = $res->iterate())) {
                         $emails = (array) $abook->get_col_values('email', $member, true);
                         if (!empty($emails) && ($email = array_shift($emails))) {
                             $result['members'][] = array('email' => $email, 'name' => rcube_addressbook::compose_list_name($member));
                         }
                     }
                     break 2;
                 }
             }
         }
     }
     $this->rc->output->command('plugin.expand_attendee_callback', $result);
 }
Exemplo n.º 2
0
 /**
  * Get vcard data for specified contact
  */
 private function get_contact_vcard($source, $cid, &$filename = null)
 {
     $rcmail = rcmail::get_instance();
     $source = $rcmail->get_address_book($source);
     $contact = $source->get_record($cid, true);
     if ($contact) {
         $fieldmap = $source ? $source->vcard_map : null;
         if (empty($contact['vcard'])) {
             $vcard = new rcube_vcard('', RCUBE_CHARSET, false, $fieldmap);
             $vcard->reset();
             foreach ($contact as $key => $values) {
                 list($field, $section) = explode(':', $key);
                 // avoid unwanted casting of DateTime objects to an array
                 // (same as in rcube_contacts::convert_save_data())
                 if (is_object($values) && is_a($values, 'DateTime')) {
                     $values = array($values);
                 }
                 foreach ((array) $values as $value) {
                     if (is_array($value) || is_a($value, 'DateTime') || @strlen($value)) {
                         $vcard->set($field, $value, strtoupper($section));
                     }
                 }
             }
             $contact['vcard'] = $vcard->export();
         }
         $name = rcube_addressbook::compose_list_name($contact);
         $filename = (self::parse_filename($name) ?: 'contact') . '.vcf';
         // fix folding and end-of-line chars
         $vcard = preg_replace('/\\r|\\n\\s+/', '', $contact['vcard']);
         $vcard = preg_replace('/\\n/', rcube_vcard::$eol, $vcard);
         return rcube_vcard::rfc2425_fold($vcard) . rcube_vcard::$eol;
     }
 }