예제 #1
0
 /**
  * Initialise from a database row
  * @param object $row The row from the DB.
  */
 function FromRow($row)
 {
     global $c;
     if ($row == null) {
         return;
     }
     $this->exists = true;
     $this->dav_name = $row->dav_name;
     $this->bound_from = isset($row->bound_from) ? $row->bound_from : $row->dav_name;
     $this->_is_collection = preg_match('{/$}', $this->dav_name);
     if ($this->_is_collection) {
         $this->contenttype = 'httpd/unix-directory';
         $this->collection = (object) array();
         $this->resource_id = $row->collection_id;
         $this->_is_principal = preg_match('{^/[^/]+/$}', $this->dav_name);
         if (preg_match('#^(/principals/[^/]+/[^/]+)/?$#', $this->dav_name, $matches)) {
             $this->collection->dav_name = $matches[1] . '/';
             $this->collection->type = 'principal_link';
             $this->_is_principal = true;
         }
     } else {
         $this->resource = (object) array();
         if (isset($row->dav_id)) {
             $this->resource_id = $row->dav_id;
         }
     }
     dbg_error_log('DAVResource', ':FromRow: Named "%s" is%s a collection.', $this->dav_name, $this->_is_collection ? '' : ' not');
     foreach ($row as $k => $v) {
         if ($this->_is_collection) {
             $this->collection->{$k} = $v;
         } else {
             $this->resource->{$k} = $v;
         }
         switch ($k) {
             case 'created':
             case 'modified':
                 $this->{$k} = $v;
                 break;
             case 'resourcetypes':
                 if ($this->_is_collection) {
                     $this->{$k} = $v;
                 }
                 break;
             case 'dav_etag':
                 $this->unique_tag = '"' . $v . '"';
                 break;
         }
     }
     if ($this->_is_collection) {
         if (!isset($this->collection->type) || $this->collection->type == 'collection') {
             if ($this->_is_principal) {
                 $this->collection->type = 'principal';
             } else {
                 if ($row->is_calendar == 't') {
                     $this->collection->type = 'calendar';
                 } else {
                     if ($row->is_addressbook == 't') {
                         $this->collection->type = 'addressbook';
                     } else {
                         if (isset($row->is_proxy) && $row->is_proxy == 't') {
                             $this->collection->type = 'proxy';
                         } else {
                             if (preg_match('#^((/[^/]+/)\\.(in|out)/)[^/]*$#', $this->dav_name, $matches)) {
                                 $this->collection->type = 'schedule-' . $matches[3] . 'box';
                             } else {
                                 if ($this->dav_name == '/') {
                                     $this->collection->type = 'root';
                                 } else {
                                     $this->collection->type = 'collection';
                                 }
                             }
                         }
                     }
                 }
             }
         }
         $this->_is_calendar = $this->collection->is_calendar == 't';
         $this->_is_addressbook = $this->collection->is_addressbook == 't';
         $this->_is_proxy_request = $this->collection->type == 'proxy';
         if ($this->_is_principal && !isset($this->resourcetypes)) {
             $this->resourcetypes = '<DAV::collection/><DAV::principal/>';
         } else {
             if ($this->_is_proxy_request) {
                 $this->resourcetypes = $this->collection->resourcetypes;
             }
         }
         if (isset($this->collection->dav_displayname)) {
             $this->collection->displayname = $this->collection->dav_displayname;
         }
     } else {
         $this->resourcetypes = '';
         if (isset($this->resource->caldav_data)) {
             if (isset($this->resource->summary)) {
                 $this->resource->displayname = $this->resource->summary;
             }
             if (strtoupper(substr($this->resource->caldav_data, 0, 15)) == 'BEGIN:VCALENDAR') {
                 $this->contenttype = 'text/calendar';
                 if (!$this->HavePrivilegeTo('read') && $this->HavePrivilegeTo('read-free-busy')) {
                     $vcal = new iCalComponent($this->resource->caldav_data);
                     $confidential = $vcal->CloneConfidential();
                     $this->resource->caldav_data = $confidential->Render();
                     $this->resource->displayname = $this->resource->summary = translate('Busy');
                     $this->resource->description = null;
                     $this->resource->location = null;
                     $this->resource->url = null;
                 } else {
                     if (isset($c->hide_alarm) && $c->hide_alarm && !$this->HavePrivilegeTo('write')) {
                         $vcal1 = new iCalComponent($this->resource->caldav_data);
                         $comps = $vcal1->GetComponents();
                         $vcal2 = new iCalComponent();
                         $vcal2->VCalendar();
                         foreach ($comps as $comp) {
                             $comp->ClearComponents('VALARM');
                             $vcal2->AddComponent($comp);
                         }
                         $this->resource->displayname = $this->resource->summary = $vcal2->GetPValue('SUMMARY');
                         $this->resource->caldav_data = $vcal2->Render();
                     }
                 }
             } else {
                 if (strtoupper(substr($this->resource->caldav_data, 0, 11)) == 'BEGIN:VCARD') {
                     $this->contenttype = 'text/vcard';
                 } else {
                     if (strtoupper(substr($this->resource->caldav_data, 0, 11)) == 'BEGIN:VLIST') {
                         $this->contenttype = 'text/x-vlist';
                     }
                 }
             }
         }
     }
 }