示例#1
0
 public function init()
 {
     self::$helper = new carddav_common('BACKEND: ');
     $this->add_hook('addressbooks_list', array($this, 'address_sources'));
     $this->add_hook('addressbook_get', array($this, 'get_address_book'));
     $this->add_hook('preferences_list', array($this, 'cd_preferences'));
     $this->add_hook('preferences_save', array($this, 'cd_save'));
     $this->add_hook('preferences_sections_list', array($this, 'cd_preferences_section'));
     $this->add_hook('login_after', array($this, 'init_presets'));
     if (!array_key_exists('user_id', $_SESSION)) {
         return;
     }
     // use this address book for autocompletion queries
     // (maybe this should be configurable by the user?)
     $config = rcmail::get_instance()->config;
     $sources = (array) $config->get('autocomplete_addressbooks', array('sql'));
     $dbh = rcmail::get_instance()->db;
     $sql_result = $dbh->query('SELECT id FROM ' . get_table_name('carddav_addressbooks') . ' WHERE user_id=? AND active=1', $_SESSION['user_id']);
     while ($abookrow = $dbh->fetch_assoc($sql_result)) {
         $abookname = "carddav_" . $abookrow['id'];
         if (!in_array($abookname, $sources)) {
             $sources[] = $abookname;
         }
     }
     $config->set('autocomplete_addressbooks', $sources);
 }
示例#2
0
    /**
     * Retrieves the Card URIs from the CardDAV server
     *
     * @return int  number of cards in collection, -1 on error
     */
    private function list_records_sync_collection()
    {
        $sync_token = $this->config['sync_token'];
        while (true) {
            $opts = array('method' => "REPORT", 'header' => array("Depth: 0", 'Content-Type: application/xml; charset="utf-8"'), 'content' => <<<EOF
<?xml version="1.0" encoding="utf-8" ?>
<D:sync-collection xmlns:D="DAV:" xmlns:C="urn:ietf:params:xml:ns:carddav">
    <D:sync-token>{$sync_token}</D:sync-token>
    <D:sync-level>1</D:sync-level>
    <D:prop>
        <D:getcontenttype/>
        <D:getetag/>
    </D:prop>
</D:sync-collection>
EOF
);
            $reply = self::$helper->cdfopen($this->config['url'], $opts, $this->config);
            $xml = self::$helper->checkAndParseXML($reply);
            if ($xml === false) {
                // a server may invalidate old sync-tokens, in which case we need to do a full resync
                if (strlen($sync_token) > 0 && $reply == 412) {
                    self::$helper->warn("Server reported invalid sync-token in sync of addressbook " . $this->config['abookid'] . ". Resorting to full resync.");
                    $sync_token = '';
                    continue;
                } else {
                    return -1;
                }
            }
            list($new_sync_token) = $xml->xpath('//RCMCD:sync-token');
            $records = $this->addvcards($xml);
            if (strlen($sync_token) == 0) {
                if ($records >= 0) {
                    $this->delete_unseen();
                }
            } else {
                $this->delete_synccoll($xml);
            }
            if ($records >= 0) {
                carddav::update_abook($this->config['abookid'], array('sync_token' => "{$new_sync_token}"));
                // if we got a truncated result set continue sync
                $xpresult = $xml->xpath('//RCMCD:response[contains(child::RCMCD:status, " 507 Insufficient Storage")]');
                if (count($xpresult) > 0) {
                    $sync_token = "{$new_sync_token}";
                    continue;
                }
            }
            break;
        }
        return $records;
    }
 /**
  * Extended write log with pre defined logfile name and add version before the message content
  *
  * @param  string $message Log message
  * @return void
  */
 function write_log($message)
 {
     carddav::write_log(' carddav_server_id: ' . $this->carddav_server_id . ' | ' . $message);
 }
示例#4
0
 public function init()
 {
     $this->rc = rcmail::get_instance();
     $tasks = explode('|', $this->task);
     // Since other plugins may also use the Sabre library
     // In order to avoid version conflicts between Sabre libraries
     // which might be used by other plugins
     // It is better to restrict the loading of Sabre library
     // under necessary tasks
     if (!in_array($this->rc->task, $tasks)) {
         return;
     } else {
         require_once 'carddav_backend.php';
         require_once 'carddav_discovery.php';
         require_once 'carddav_common.php';
     }
     self::$helper = new carddav_common('BACKEND: ');
     $this->add_hook('addressbooks_list', array($this, 'address_sources'));
     $this->add_hook('addressbook_get', array($this, 'get_address_book'));
     $this->add_hook('preferences_list', array($this, 'cd_preferences'));
     $this->add_hook('preferences_save', array($this, 'cd_save'));
     $this->add_hook('preferences_sections_list', array($this, 'cd_preferences_section'));
     $this->add_hook('login_after', array($this, 'checkMigrations'));
     $this->add_hook('login_after', array($this, 'init_presets'));
     if (!array_key_exists('user_id', $_SESSION)) {
         return;
     }
     // use this address book for autocompletion queries
     // (maybe this should be configurable by the user?)
     $config = rcmail::get_instance()->config;
     $sources = (array) $config->get('autocomplete_addressbooks', array('sql'));
     $dbh = rcmail::get_instance()->db;
     $sql_result = $dbh->query('SELECT id FROM ' . get_table_name('carddav_addressbooks') . ' WHERE user_id=? AND active=1', $_SESSION['user_id']);
     while ($abookrow = $dbh->fetch_assoc($sql_result)) {
         $abookname = "carddav_" . $abookrow['id'];
         if (!in_array($abookname, $sources)) {
             $sources[] = $abookname;
         }
     }
     $config->set('autocomplete_addressbooks', $sources);
 }
 /**
  * Constructor
  * Sets the CardDAV server url
  *
  * @param	string	$url	CardDAV server url
  * @param string  $ext  vCard file extension
  * @param boolean $wait 
  * @return	void
  */
 public function __construct($url = null, $ext = 'vcf')
 {
     if ($url !== null) {
         $this->set_url($url);
         $this->ext = class_exists('carddav') ? carddav::carddav_ext($url, $ext) : $ext;
     }
 }