Browse Source

remove facebook

main
Aaron Parecki 6 months ago
parent
commit
44f91f443a
7 changed files with 0 additions and 140 deletions
  1. +0
    -1
      README.md
  2. +0
    -1
      controllers/Parse.php
  3. +0
    -25
      lib/XRay/Fetcher.php
  4. +0
    -107
      lib/XRay/Formats/Facebook.php
  5. +0
    -4
      lib/XRay/Parser.php
  6. +0
    -1
      tests/data/graph.facebook.com/1596554663924436.json
  7. +0
    -1
      tests/data/graph.facebook.com/446197069049722.json

+ 0
- 1
README.md View File

@ -13,7 +13,6 @@ XRay will parse content in the following formats. First the URL is checked again
* GitHub
* XKCD
* Hackernews
* ~~Facebook (public events)~~ <REMOVED>
If the contents of the URL is XML or JSON, then XRay will parse the Atom, RSS or JSONFeed formats.

+ 0
- 1
controllers/Parse.php View File

@ -95,7 +95,6 @@ class Parse {
$fields = [
'twitter_api_key','twitter_api_secret','twitter_access_token','twitter_access_token_secret',
'facebook_app_id', 'facebook_app_secret',
'github_access_token',
'token'
];

+ 0
- 25
lib/XRay/Fetcher.php View File

@ -43,11 +43,6 @@ class Fetcher {
return $this->_fetch_tweet($url, $opts);
}
// Check if this is a Facebook URL and use the API
if(Formats\Facebook::matches_host($url)) {
return $this->_fetch_facebook($url, $opts);
}
// Transform the HTML GitHub URL into an GitHub API request and fetch the API response
if(Formats\GitHub::matches_host($url)) {
return $this->_fetch_github($url, $opts);
@ -181,26 +176,6 @@ class Fetcher {
return Formats\Twitter::fetch($url, $creds);
}
private function _fetch_facebook($url, $opts) {
$fields = ['facebook_app_id','facebook_app_secret'];
$creds = [];
foreach($fields as $f) {
if(isset($opts[$f]))
$creds[$f] = $opts[$f];
}
if(count($creds) < 2) {
return [
'error_code' => 400,
'error' => 'missing_parameters',
'error_description' => 'Both Facebook credentials must be included in the request'
];
}
// TODO: Question, should I do this like Twitter or like Github?
return Formats\Facebook::fetch($url, $creds);
}
private function _fetch_github($url, $opts) {
$fields = ['github_access_token'];
$creds = [];

+ 0
- 107
lib/XRay/Formats/Facebook.php View File

@ -1,107 +0,0 @@
<?php
namespace p3k\XRay\Formats;
use DOMDocument, DOMXPath;
use DateTime, DateTimeZone;
class Facebook extends Format {
public static function matches_host($url) {
$host = parse_url($url, PHP_URL_HOST);
// TODO: match hosts like 'm.facebook.com' and 'mbasic.facebook.com'
return in_array($host, ['www.facebook.com','facebook.com']);
}
public static function matches($url) {
return self::matches_host($url);
}
public static function parse($http_response) {
$fbObject = $http_response['body'];
$url = $http_response['url'];
if(is_string($fbObject)) $fbObject = json_decode($fbObject, true);
$parts = self::extract_url_parts($url);
if($parts['type'] == 'event') {
$event = array(
'type' => 'event',
'url' => $url,
'name' => $fbObject['name'],
'start' => $fbObject['start_time']
);
if(isset($fbObject['end_time'])) $event['end'] = $fbObject['end_time'];
if(isset($fbObject['description'])) $event['summary'] = $fbObject['description'];
// Is the event linked to a Page?
if(isset($fbObject['place']['id'])) {
$card = array(
'type' => 'card',
'url' => 'https://facebook.com/'.$fbObject['place']['id'],
'name' => $fbObject['place']['name']
);
if(isset($fbObject['place']['location'])) {
$location = $fbObject['place']['location'];
if(isset($location['zip'])) $card['postal-code'] = $location['zip'];
if(isset($location['city'])) $card['locality'] = $location['city'];
if(isset($location['state'])) $card['region'] = $location['state'];
if(isset($location['street'])) $card['street-address'] = $location['street'];
if(isset($location['country'])) $card['country'] = $location['country'];
if(isset($location['latitude'])) $card['latitude'] = (string)$location['latitude'];
if(isset($location['longitude'])) $card['longitude'] = (string)$location['longitude'];
}
$event['location'] = $card['url'];
$event['refs'] = array($card);
// If we only have a name, use that
} elseif(isset($fbObject['place']['name'])) {
$event['location'] = $fbObject['place']['name'];
}
$event['post-type'] = \p3k\XRay\PostType::discover($event);
return [
'data' => $event,
'original' => $fbObject,
'source-format' => 'facebook',
];
}
}
public static function fetch($url, $creds) {
//Disabled Function for now
//TODO: Search all references to this class and remove it.
return [
'code' => 200,
'body' => '',
'url' => $url
];
}
private static function extract_url_parts($url) {
$response = false;
if(preg_match('~https://(.*?).?facebook.com/([^/]+)/posts/(\d+)/?$~', $url, $match)) {
// TODO: how do we get these?
// $response['type'] = 'entry';
// $response['api_uri'] = false;
} elseif(preg_match('~https://(.*?).?facebook.com/events/(\d+)/?$~', $url, $match)) {
$response['type'] = 'event';
$response['api_uri'] = '/'.$match[2];
}
return $response;
}
}

+ 0
- 4
lib/XRay/Parser.php View File

@ -91,10 +91,6 @@ class Parser {
return Formats\Twitter::parse($http_response);
}
if(Formats\Facebook::matches($url)) {
return Formats\Facebook::parse($http_response);
}
if(Formats\XKCD::matches($url)) {
return Formats\XKCD::parse($http_response);
}

+ 0
- 1
tests/data/graph.facebook.com/1596554663924436.json View File

@ -1 +0,0 @@
{"description":"Are you building your own website? Indie reader? Personal publishing web app? Or some other digital magic-cloud proxy? If so, come on by and join a gathering of people with like-minded interests. Bring your friends that want to start a personal web site. Exchange information, swap ideas, talk shop, help work on a project. \n\n Contact (914) 414-1775 when you arrive to be admitted. \n\n\nMore information: \u0040[NjQyMTgzOTU5MjA4MTA3Omh0dHBzXGEvL2luZGlld2ViY2FtcC5jb20vZXZlbnRzLzIwMTUtMDQtMjItaG9tZWJyZXctd2Vic2l0ZS1jbHViOjo=:\u0040[NjQyMTgzOTU5MjA4MTA3Omh0dHBzXGEvL2luZGlld2ViY2FtcC5jb20vZXZlbnRzLzIwMTUtMDQtMjItaG9tZWJyZXctd2Vic2l0ZS1jbHViOjo=:https:\/\/indiewebcamp.com\/events\/2015-04-22-homebrew-website-club]]","name":"Homebrew Website Club","place":{"name":"Charging Bull - WeeWork - 25 Broadway, New York, NY 10004"},"start_time":"2015-04-22T19:00:00-0400","id":"1596554663924436"}

+ 0
- 1
tests/data/graph.facebook.com/446197069049722.json View File

@ -1 +0,0 @@
{"description":"The seventh annual gathering for independent web creators of all kinds, from graphic artists, to designers, UX engineers, coders, hackers, to share ideas, actively work on creating for their own personal websites, and build upon each others creations.\n\nIMPORTANT: Please register for a ticket from https:\/\/2017.indieweb.org\/ to attend! RSVPing on Facebook is not enough. Your registration will ensure that we get enough food for everyone!\n\nOriginally posted at https:\/\/aaronparecki.com\/2017\/06\/24\/1\/indieweb-summit","end_time":"2017-06-25T18:00:00-0700","name":"IndieWeb Summit","place":{"name":"Mozilla PDX","location":{"city":"Portland","country":"United States","latitude":45.5233192,"longitude":-122.6824722,"state":"OR","street":"1120 NW Couch St, Ste 320","zip":"97209"},"id":"332204056925945"},"start_time":"2017-06-24T09:00:00-0700","id":"446197069049722"}

Loading…
Cancel
Save