示例#1
0
 function getPhoto(Card $node)
 {
     // TODO: this is kind of expensive - load carddav data from database and parse it
     //       we might want to build up a cache one day
     try {
         $vObject = $this->readCard($node->get());
         if (!$vObject->PHOTO) {
             return false;
         }
         $photo = $vObject->PHOTO;
         $type = $this->getType($photo);
         $val = $photo->getValue();
         if ($photo->getValueType() === 'URI') {
             $parsed = \Sabre\URI\parse($val);
             //only allow data://
             if ($parsed['scheme'] !== 'data') {
                 return false;
             }
             if (substr_count($parsed['path'], ';') === 1) {
                 list($type, ) = explode(';', $parsed['path']);
             }
             $val = file_get_contents($val);
         }
         return ['Content-Type' => $type, 'body' => $val];
     } catch (\Exception $ex) {
         $this->logger->logException($ex);
     }
     return false;
 }