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
 /**
  * Load partial free/busy data.
  *
  * @param Horde_Kolab_FreeBusy_Access $access   The object holding the
  *                                        relevant access
  *                                        parameters.
  * @param boolean               $extended Should the data hold the extended
  *                                        free/busy information?
  *
  * @return Horde_Icalendar|PEAR_Error The free/busy data of a
  *                                    single calendar.
  */
 function &loadPartial(&$access, $extended)
 {
     global $conf;
     $file = $this->_getFilename($access->folder, $access->owner);
     if (!empty($conf['fb']['use_acls'])) {
         $aclcache =& Horde_Kolab_FreeBusy_Cache_DB_acl::singleton('acl', $this->_cache_dir);
         if ($extended) {
             $extended = $this->_allowExtended($file, $access);
         }
     }
     $c_pvcal = new Horde_Kolab_FreeBusy_Cache_File_pvcal($this->_cache_dir, $file);
     $pvCal = $c_pvcal->loadPVcal($extended);
     if (is_a($pvCal, 'PEAR_Error')) {
         return $pvCal;
     }
     return $pvCal;
 }