Пример #1
0
 function getContent()
 {
     $this->createGatekeeper();
     $user = \Idno\Core\site()->session()->currentUser();
     $u = $this->getInput('u');
     if ($content = \Idno\Core\Webservice::get($u)['content']) {
         $parser = new \Mf2\Parser($content, $u);
         if ($return = $parser->parse()) {
             if (isset($return['items'])) {
                 $t = \Idno\Core\site()->template();
                 $body = '';
                 $hcard = [];
                 $this->findHcard($return['items'], $hcard);
                 $hcard = $this->removeDuplicateProfiles($hcard);
                 if (!count($hcard)) {
                     throw new \Exception("Sorry, could not find any users on that page, perhaps they need to mark up their profile in <a href=\"http://microformats.org/wiki/microformats-2\">Microformats</a>?");
                 }
                 // TODO: Add a manual way to add the user
                 foreach ($hcard as $card) {
                     $body .= $t->__(['mf2' => $card])->draw('account/settings/following/mf2user');
                 }
                 // List user
                 $t->body = $body;
                 $t->title = 'Found users';
                 $t->drawPage();
             }
         } else {
             throw new \Exception("Sorry, there was a problem parsing the page!");
         }
     } else {
         throw new \Exception("Sorry, {$u} could not be retrieved!");
     }
     // forward back
     $this->forward($_SERVER['HTTP_REFERER']);
 }
Пример #2
0
 /**
  * Parses a given set of HTML for Microformats 2 content
  * @param $content HTML to parse
  * @param $url Optionally, the source URL of the content, so relative URLs can be parsed into absolute ones
  * @return array
  */
 static function parseContent($content, $url = null)
 {
     $parser = new \Mf2\Parser($content, $url);
     try {
         $return = $parser->parse();
     } catch (\Exception $e) {
         $return = false;
     }
     return $return;
 }
Пример #3
0
 /**
  * Given the content of a page and its URL, returns an array of FeedItem objects (or false on failure)
  * @param $content
  * @param $url
  * @return array|bool
  */
 function parseFeed($content, $url)
 {
     // Check for microformats
     if ($html = @\DOMDocument::loadHTML($content)) {
         try {
             $parser = new \Mf2\Parser($html, $url);
             $parsed_content = $parser->parse();
             return $this->mf2FeedToFeedItems($parsed_content, $url);
         } catch (\Exception $e) {
             return false;
         }
     }
     // Try XML (RSS or Atom)
     $xml_parser = new \SimplePie();
     $xml_parser->set_raw_data($content);
     $xml_parser->init();
     if (!$xml_parser->error()) {
         return $this->xmlFeedToFeedItems($xml_parser->get_items(), $url);
     }
     return false;
 }
Пример #4
0
 function getContent()
 {
     $this->createGatekeeper();
     $user = \Idno\Core\site()->session()->currentUser();
     $u = $this->getInput('u');
     if ($content = \Idno\Core\Webservice::get($u)['content']) {
         $parser = new \Mf2\Parser($content, $u);
         if ($return = $parser->parse()) {
             if (isset($return['items'])) {
                 $t = \Idno\Core\site()->template();
                 $body = '';
                 $hcard = array();
                 $this->findHcard($return['items'], $hcard);
                 $hcard = $this->removeDuplicateProfiles($hcard);
                 if (!count($hcard)) {
                     //throw new \Exception("Sorry, could not find any users on that page, perhaps they need to mark up their profile in <a href=\"http://microformats.org/wiki/microformats-2\">Microformats</a>?"); // TODO: Add a manual way to add the user
                     // No entry could be found, so lets fake one and allow manual entry
                     $hcard[] = ['properties' => ['name' => [$this->findPageTitle($content)], 'photo' => [], 'email' => [], 'nickname' => [], 'url' => [$u]]];
                     // Display a warning
                     \Idno\Core\site()->session()->addErrorMessage('Page did not contain any <a href=\\"http://microformats.org/wiki/microformats-2\\">Microformats</a> markup... doing my best with what I have!');
                 }
                 foreach ($hcard as $card) {
                     $body .= $t->__(array('mf2' => $card))->draw('account/settings/following/mf2user');
                 }
                 // List user
                 $t->body = $body;
                 $t->title = 'Found users';
                 $t->drawPage();
             }
         } else {
             throw new \Exception("Sorry, there was a problem parsing the page!");
         }
     } else {
         throw new \Exception("Sorry, {$u} could not be retrieved!");
     }
     // forward back
     $this->forward($_SERVER['HTTP_REFERER']);
 }
Пример #5
0
 protected function _parseBody($target, $html)
 {
     if (class_exists('\\Mf2\\Parser') && $this->usemf2) {
         $parser = new \Mf2\Parser($html, $target);
         list($rels, $alternates) = $parser->parseRelsAndAlternates();
         $this->c('rels', $target, $rels);
     }
 }