public function parseUrl($url)
 {
     $essence = new \Essence\Essence();
     $options = EmbeddedAssetsPlugin::getParameters();
     $result = $essence->extract($url, $options);
     if ($result && $result->html) {
         $properties = array();
         foreach ($result as $property => $value) {
             if (empty($value) && isset($this->_ogProperties[$property])) {
                 $properties[] = $property;
             }
         }
         if (!empty($properties)) {
             try {
                 $data = $this->_readExternalFile($url);
                 $reader = new \Opengraph\Reader();
                 $reader->parse($data);
                 foreach ($properties as $property) {
                     $ogProperty = $this->_ogProperties[$property];
                     $result->{$property} = $reader->getMeta($ogProperty);
                 }
             } catch (\Exception $e) {
             }
         }
     }
     return $result;
 }
 public function parseUrl($url)
 {
     $essence = new \Essence\Essence();
     $options = EmbeddedAssetsPlugin::getParameters();
     EmbeddedAssetsPlugin::log("Requesting URL \"{$url}\"");
     $result = $essence->extract($url, $options);
     if ($result && $result->html) {
         EmbeddedAssetsPlugin::log("Embed data found");
         $properties = array();
         foreach ($result as $property => $value) {
             if (empty($value) && isset($this->_ogProperties[$property])) {
                 $properties[] = $property;
             }
         }
         if (!empty($properties)) {
             EmbeddedAssetsPlugin::log("Some data missing - looking for related Open Graph metadata");
             try {
                 $data = $this->_readExternalFile($url);
                 if (!$data) {
                     throw new \Exception("Could not read data");
                 }
                 $reader = new \Opengraph\Reader();
                 $reader->parse($data);
                 foreach ($properties as $property) {
                     $ogProperty = $this->_ogProperties[$property];
                     $result->{$property} = $reader->getMeta($ogProperty);
                 }
             } catch (\Exception $e) {
                 EmbeddedAssetsPlugin::log("Error requesting/parsing Open Graph metadata (\"{$e->getMessage()}\")", LogLevel::Warning);
             }
         }
     }
     return $result;
 }
예제 #3
0
 public function after_parse_content(&$content)
 {
     $Cache = new FileCacheEngine($this->cacheDir, $this->cacheLife);
     $Essence = Essence\Essence::instance(array('Cache' => function () use($Cache) {
         return $Cache;
     }));
     $content = $Essence->replace($content);
 }
예제 #4
0
/**
 *
 */
function main($method, $url)
{
    $Essence = Essence\Essence::instance();
    switch ($method) {
        case 'embed':
            dumpMedia($Essence->embed($url));
            break;
        case 'extract':
            dumpArray($Essence->extract($url));
            break;
    }
}