Exemplo n.º 1
0
     if ($description) {
         $error['error_description'] = $description;
     }
     $res->body(json_encode($error));
 };
 $source = parse_url($sourceURL);
 # Verify $source is valid
 if ($source == FALSE || !array_key_exists('scheme', $source) || !in_array($source['scheme'], array('http', 'https')) || !array_key_exists('host', $source) || $source['host'] == gethostbyname($source['host'])) {
     $error($res, 'source_not_found');
     return;
 }
 $ch = curl_init();
 curl_setopt($ch, CURLOPT_URL, $sourceURL);
 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
 $html = curl_exec($ch);
 $parser = new ParserPlus($html);
 $output = $parser->parse();
 $page = new MF2Page($output);
 $data = array('name' => null, 'content' => null, 'published' => null, 'published_ts' => null, 'author' => array('name' => null, 'url' => null, 'photo' => null));
 if ($page->hentry) {
     $data['mf2'] = $output;
     if ($page->hentry->property('name')) {
         $data['name'] = trim($page->hentry->property('name', true));
     }
     if ($page->hentry->author) {
         if ($page->hentry->author->url) {
             $data['author']['url'] = $page->hentry->author->url;
         }
         if ($page->hentry->author->name) {
             $data['author']['name'] = $page->hentry->author->name;
         }
Exemplo n.º 2
0
 if ($target == FALSE || !array_key_exists('scheme', $target) || !in_array($target['scheme'], array('http', 'https')) || !array_key_exists('host', $target) || $target['host'] != Config::$hostname) {
     $error($res, 'target_not_supported');
     return;
 }
 if (!preg_match('/^https?:\\/\\/' . Config::$hostname . '\\/?/', $targetURL, $match)) {
     $error($res, 'target_not_supported', 'The target you specified does not appear to be a URL on this site.');
     return;
 }
 $data = array('post_author' => $source['scheme'] . '://' . $source['host'], 'title' => false, 'body' => false, 'date' => false);
 $notices = array();
 # Now fetch and parse the page looking for Microformats
 $ch = curl_init();
 curl_setopt($ch, CURLOPT_URL, $sourceURL);
 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
 $html = curl_exec($ch);
 $parser = new ParserPlus($html);
 $output = $parser->parse();
 $page = new MF2Page($output);
 if ($page->hentry) {
     if ($page->hentry->property('name')) {
         $data['title'] = trim($page->hentry->property('name', true));
     } else {
         $notices[] = 'No "name" property found on the h-entry. Using the page title instead.';
     }
     if ($page->hentry->author && $page->hentry->author->url) {
         $authorURL = parse_url($page->hentry->author->url);
         if ($authorURL && array_key_exists('host', $authorURL)) {
             $data['post_author'] = $page->hentry->author->url;
         } else {
             $notices[] = 'No host was found on the author URL (' . $page->hentry->author->url . ')';
         }