Example #1
0
 /**
  * Fetch the free/busy data.
  *
  * @params array   $params   Additional options.
  *
  * @return array The free/busy data.
  */
 public function fetch($params = array())
 {
     $this->logger->debug(sprintf("Free/busy data of owner %s requested by user %s (remote: %s).", $this->callee, $this->user, $this->remote));
     if (!empty($this->remote)) {
         /* Try to fetch the data if it is stored on a remote server */
         //@todo: How to determine which hook/processor to run?
         return $this->fetchRemote($params);
         // if (is_a($result, 'PEAR_Error')) {
         //    $error = array('type' => FREEBUSY_ERROR_UNAUTHORIZED, 'error' => $result);
     }
     global $conf;
     /* Which files will we access? */
     if (!empty($conf['fb']['use_acls'])) {
         $aclcache =& Horde_Kolab_FreeBusy_Cache_DB_acl::singleton('acl', $this->_cache_dir);
         $files = $aclcache->get($access->owner);
         if (is_a($files, 'PEAR_Error')) {
             return $files;
         }
     } else {
         $file_uid = str_replace("", '', str_replace(".", "^", $access->owner));
         $files = array();
         $this->findAll_readdir($file_uid, $conf['fb']['cache_dir'] . '/' . $file_uid, $files);
     }
     $owner = $access->owner;
     if (ereg('(.*)@(.*)', $owner, $regs)) {
         $owner = $regs[2] . '/' . $regs[1];
     }
     $user = $access->user;
     if (ereg('(.*)@(.*)', $user, $regs)) {
         $user = $regs[2] . '/' . $regs[1];
     }
     $c_file = str_replace("", '', str_replace('.', '^', $user . '/' . $owner));
     $c_vcal = new Horde_Kolab_FreeBusy_Cache_File_vcal($this->_cache_dir, $c_file, $extended);
     /* If the current vCal cache did not expire, we can deliver it */
     if (!$this->cache->expired($files)) {
         return $this->cache->loadVcal();
     }
     // Create the new iCalendar.
     $vCal = new Horde_Icalendar();
     $vCal->setAttribute('PRODID', '-//kolab.org//NONSGML Kolab Server 2//EN');
     $vCal->setAttribute('METHOD', 'PUBLISH');
     // Create new vFreebusy.
     $vFb = Horde_Icalendar::newComponent('vfreebusy', $vCal);
     $params = array();
     $cn = $access->owner_object->get(Horde_Kolab_Server_Object_Kolab_User::ATTRIBUTE_CN);
     if (!empty($cn) || is_a($cn, 'PEAR_Error')) {
         $params['cn'] = $access->owner_object->get(Horde_Kolab_Server_Object_Kolab_User::ATTRIBUTE_CN);
     }
     $vFb->setAttribute('ORGANIZER', 'MAILTO:' . $access->owner, $params);
     $vFb->setAttribute('DTSTAMP', time());
     if (isset($_SERVER['SERVER_NAME'])) {
         $host = $_SERVER['SERVER_NAME'];
     } else {
         $host = 'localhost';
     }
     if (isset($_SERVER['REQUEST_URI'])) {
         $uri = $_SERVER['REQUEST_URI'];
     } else {
         $uri = '/';
     }
     $vFb->setAttribute('URL', 'http://' . $host . $uri);
     $mtimes = array();
     foreach ($files as $file) {
         if ($extended && !empty($conf['fb']['use_acls'])) {
             $extended_pvc = $this->_allowExtended($file, $access);
         } else {
             $extended_pvc = $extended;
         }
         $c_pvcal = new Horde_Kolab_FreeBusy_Cache_File_pvcal($this->_cache_dir, $file);
         $pvCal = $c_pvcal->loadPVcal($extended_pvc);
         if (is_a($pvCal, 'PEAR_Error')) {
             Horde::log(sprintf("Ignoring partial free/busy file %s: %s)", $file, $pvCal->getMessage()), 'INFO');
             continue;
         }
         $pvFb =& $pvCal->findComponent('vfreebusy');
         if (!$pvFb) {
             Horde::log(sprintf("Could not find free/busy info in file %s.)", $file), 'INFO');
             continue;
         }
         if ($ets = $pvFb->getAttributeDefault('DTEND', false) !== false) {
             // PENDING(steffen): Make value configurable
             if ($ets < time()) {
                 Horde::log(sprintf("Free/busy info in file %s is too old.)", $file), 'INFO');
                 $c_pvcal->purge();
                 continue;
             }
         }
         $vFb->merge($pvFb);
         /* Store last modification time */
         $mtimes[$file] = array($c_pvcal->getFile(), $c_pvcal->getMtime());
     }
     if (!empty($conf['fb']['remote_servers'])) {
         $remote_vfb = $this->_fetchRemote($conf['fb']['remote_servers'], $access);
         if (is_a($remote_vfb, 'PEAR_Error')) {
             Horde::log(sprintf("Ignoring remote free/busy files: %s)", $remote_vfb->getMessage()), 'INFO');
         } else {
             $vFb->merge($remote_vfb);
         }
     }
     if (!(bool) $vFb->getBusyPeriods()) {
         /* No busy periods in fb list. We have to add a
          * dummy one to be standards compliant
          */
         $vFb->setAttribute('COMMENT', 'This is a dummy vfreebusy that indicates an empty calendar');
         $vFb->addBusyPeriod('BUSY', 0, 0, null);
     }
     $vCal->addComponent($vFb);
     $c_vcal->storeVcal($vCal, $mtimes);
     return $vCal;
     $result = $this->app->getCache->load($access, $extended);
     // if (is_a($result, 'PEAR_Error')) {
     //    $error = array('type' => FREEBUSY_ERROR_NOTFOUND, 'error' => $result);
     //$data = array('fb' => $result, 'name' => $access->owner . '.vfb');
     //$view = &new Horde_Kolab_FreeBusy_View_vfb($data);
 }
Example #2
0
 /**
  * Update the cache information for a calendar.
  *
  * @param Horde_Kolab_FreeBusy_Access $access The object holding the
  *                                      relevant access
  *                                      parameters.
  *
  * @return boolean|PEAR_Error True if successful.
  */
 function store($access)
 {
     global $conf;
     /* Now we really need the free/busy library */
     require_once 'Horde/Kolab/FreeBusy/Imap.php';
     $fb = new Horde_Kolab_FreeBusy_Imap();
     $result = $fb->connect($access->imap_folder);
     if (is_a($result, 'PEAR_Error')) {
         return $result;
     }
     $fbpast = $fbfuture = null;
     try {
         if (!empty($access->server_object)) {
             $result = $access->server_object->get(Horde_Kolab_Server_Object_Kolab_Server::ATTRIBUTE_FBPAST);
             if (!is_a($result, 'PEAR_Error')) {
                 $fbpast = $result;
             }
         }
     } catch (Horde_Kolab_Server_Exception $e) {
         Horde::log(sprintf("Failed fetching the k=kolab configuration object. Error was: %s", $e->getMessage()), 'ERR');
         if (isset($conf['kolab']['freebusy']['past'])) {
             $fbpast = $conf['kolab']['freebusy']['past'];
         } else {
             $fbpast = 10;
         }
     }
     if (!empty($access->owner_object)) {
         $result = $access->owner_object->get(Horde_Kolab_Server_Object_Kolab_User::ATTRIBUTE_FBFUTURE);
         if (!is_a($result, 'PEAR_Error')) {
             $fbfuture = $result;
         }
     }
     $vCal = $fb->generate(null, null, !empty($fbpast) ? $fbpast : 0, !empty($fbfuture) ? $fbfuture : 60, $access->owner, $access->owner_object->get(Horde_Kolab_Server_Object_Kolab_User::ATTRIBUTE_CN));
     if (is_a($vCal, 'PEAR_Error')) {
         $vCal;
     }
     $fbfilename = $this->_getFilename($access->folder, $access->owner);
     $c_pvcal = new Horde_Kolab_FreeBusy_Cache_File_pvcal($this->_cache_dir, $fbfilename);
     if (!empty($conf['fb']['use_acls'])) {
         $c_acl = new Horde_Kolab_FreeBusy_Cache_File_acl($this->_cache_dir, $fbfilename);
         $c_xacl = new Horde_Kolab_FreeBusy_Cache_File_xacl($this->_cache_dir, $fbfilename);
     }
     /* missing data means delete the cache files */
     if (empty($vCal)) {
         Horde::log(sprintf("No events. Purging cache %s.", $fbfilename), 'DEBUG');
         $result = $c_pvcal->purge();
         if (is_a($result, 'PEAR_Error')) {
             return $result;
         }
         if (!empty($conf['fb']['use_acls'])) {
             $result = $c_acl->purge();
             if (is_a($result, 'PEAR_Error')) {
                 return $result;
             }
             $result = $c_xacl->purge();
             if (is_a($result, 'PEAR_Error')) {
                 return $result;
             }
         }
     } else {
         $result = $c_pvcal->storePVcal($vCal);
         if (is_a($result, 'PEAR_Error')) {
             return $result;
         }
         $relevance = $fb->getRelevance();
         if (is_a($relevance, 'PEAR_Error')) {
             return $relevance;
         }
         if (!empty($conf['fb']['use_acls'])) {
             $acl = $fb->getACL();
             if (is_a($acl, 'PEAR_Error')) {
                 return $acl;
             }
             /**
              * Only store the acl information if the current user
              * has admin rights on the folder and can actually
              * retrieve the full ACL information.
              *
              * A folder that does not have admin rights for a user
              * will not be considered relvant for that user unless
              * it has been triggered by the folder owner before.
              */
             $append = false;
             if (isset($acl[$access->user])) {
                 $myacl = $acl[$access->user];
                 if (strpos($myacl, 'a') !== false) {
                     $append = true;
                 }
             }
             $result = $c_acl->storeACL($acl, $relevance, $append);
             if (is_a($result, 'PEAR_Error')) {
                 return $result;
             }
             $xacl = $fb->getExtendedACL();
             if (is_a($xacl, 'PEAR_Error')) {
                 return $xacl;
             }
             $result = $c_xacl->storeXACL($xacl, $acl);
             if (is_a($result, 'PEAR_Error')) {
                 return $result;
             }
         } else {
             $acl = null;
         }
         Horde::log(sprintf("Horde_Kolab_FreeBusy_Cache::store(file=%s, relevance=%s, acl=%s, xacl=%s)", $fbfilename, $relevance, $acl, $xacl), 'DEBUG');
     }
     return true;
 }