Browse Source

replace external XRay.p3k.io call with the XRay library

pull/96/head
Aaron Parecki 4 years ago
parent
commit
1395055d8a
No known key found for this signature in database GPG Key ID: 276C2817346D6056
3 changed files with 217 additions and 15 deletions
  1. +2
    -1
      composer.json
  2. +188
    -2
      composer.lock
  3. +27
    -12
      controllers/controllers.php

+ 2
- 1
composer.json View File

@ -14,7 +14,8 @@
"p3k/multipart": ">=0.2.0",
"tantek/cassis": "*",
"p3k/timezone": "*",
"gajus/dindent": "^2.0"
"gajus/dindent": "^2.0",
"p3k/xray": "^1.3"
},
"autoload": {
"files": [

+ 188
- 2
composer.lock View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
"content-hash": "349372b9e3a8017912dde4df82c46eb3",
"content-hash": "26d324e17ac5eeecdeaae4ff4e279213",
"packages": [
{
"name": "abraham/twitteroauth",
@ -143,6 +143,108 @@
"description": "Cleans up microformats2 array structures",
"time": "2014-10-06T23:11:15+00:00"
},
{
"name": "cebe/markdown",
"version": "1.1.2",
"source": {
"type": "git",
"url": "https://github.com/cebe/markdown.git",
"reference": "25b28bae8a6f185b5030673af77b32e1163d5c6e"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/cebe/markdown/zipball/25b28bae8a6f185b5030673af77b32e1163d5c6e",
"reference": "25b28bae8a6f185b5030673af77b32e1163d5c6e",
"shasum": ""
},
"require": {
"lib-pcre": "*",
"php": ">=5.4.0"
},
"require-dev": {
"cebe/indent": "*",
"facebook/xhprof": "*@dev",
"phpunit/phpunit": "4.1.*"
},
"bin": [
"bin/markdown"
],
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.1.x-dev"
}
},
"autoload": {
"psr-4": {
"cebe\\markdown\\": ""
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Carsten Brandt",
"email": "mail@cebe.cc",
"homepage": "http://cebe.cc/",
"role": "Creator"
}
],
"description": "A super fast, highly extensible markdown parser for PHP",
"homepage": "https://github.com/cebe/markdown#readme",
"keywords": [
"extensible",
"fast",
"gfm",
"markdown",
"markdown-extra"
],
"time": "2017-07-16T21:13:23+00:00"
},
{
"name": "dg/twitter-php",
"version": "v3.6",
"source": {
"type": "git",
"url": "https://github.com/dg/twitter-php.git",
"reference": "dd872ad12121ff919b358989e61f7f08ba6cc7a8"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/dg/twitter-php/zipball/dd872ad12121ff919b358989e61f7f08ba6cc7a8",
"reference": "dd872ad12121ff919b358989e61f7f08ba6cc7a8",
"shasum": ""
},
"require": {
"ext-curl": "*",
"php": ">=5.2.0"
},
"type": "library",
"autoload": {
"classmap": [
"src/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
"authors": [
{
"name": "David Grudl",
"homepage": "https://davidgrudl.com"
}
],
"description": "Small and easy Twitter library for PHP",
"homepage": "https://github.com/dg/twitter-php",
"keywords": [
"oauth",
"twitter"
],
"time": "2016-08-15T16:46:22+00:00"
},
{
"name": "ezyang/htmlpurifier",
"version": "v4.9.3",
@ -572,6 +674,44 @@
],
"time": "2015-12-24T12:43:04+00:00"
},
{
"name": "p3k/http",
"version": "0.1.5",
"source": {
"type": "git",
"url": "https://github.com/aaronpk/p3k-http.git",
"reference": "3740fe135e6d58457d7528e7c05a67b68e020a79"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/aaronpk/p3k-http/zipball/3740fe135e6d58457d7528e7c05a67b68e020a79",
"reference": "3740fe135e6d58457d7528e7c05a67b68e020a79",
"shasum": ""
},
"require": {
"indieweb/link-rel-parser": "0.1.*",
"mf2/mf2": "0.3.*"
},
"type": "library",
"autoload": {
"psr-4": {
"p3k\\": "src/p3k"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Aaron Parecki",
"homepage": "https://aaronparecki.com"
}
],
"description": "A simple wrapper API around the PHP curl functions",
"homepage": "https://github.com/aaronpk/p3k-http",
"time": "2017-04-29T17:43:29+00:00"
},
{
"name": "p3k/multipart",
"version": "0.2.0",
@ -650,6 +790,52 @@
],
"time": "2017-01-12T17:30:08+00:00"
},
{
"name": "p3k/xray",
"version": "v1.3.1",
"source": {
"type": "git",
"url": "https://github.com/aaronpk/XRay.git",
"reference": "a37ed3bbaeec5ddb51d6a6ae285c5ab608d31978"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/aaronpk/XRay/zipball/a37ed3bbaeec5ddb51d6a6ae285c5ab608d31978",
"reference": "a37ed3bbaeec5ddb51d6a6ae285c5ab608d31978",
"shasum": ""
},
"require": {
"cebe/markdown": "1.1.*",
"dg/twitter-php": "3.6.*",
"ezyang/htmlpurifier": "4.*",
"indieweb/link-rel-parser": "0.1.*",
"mf2/mf2": "^0.3.2",
"p3k/http": "0.1.*",
"p3k/timezone": "*"
},
"require-dev": {
"league/plates": "3.*",
"league/route": "1.*",
"phpunit/phpunit": "4.8.*"
},
"type": "library",
"autoload": {
"psr-4": {
"p3k\\XRay\\": "lib/XRay"
},
"files": [
"lib/helpers.php",
"lib/XRay.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"description": "X-Ray returns structured data from any URL",
"homepage": "https://github.com/aaronpk/XRay",
"time": "2017-09-22T19:35:08+00:00"
},
{
"name": "saltybeagle/savant3",
"version": "dev-master",
@ -683,7 +869,7 @@
}
],
"description": "Savant3 template engine",
"time": "2014-01-07 17:10:32"
"time": "2014-01-07T17:10:32+00:00"
},
{
"name": "slim/slim",

+ 27
- 12
controllers/controllers.php View File

@ -511,6 +511,25 @@ $app->get('/settings/html-content', function() use($app) {
}
});
$app->get('/view', function() use($app) {
if($user=require_login($app)) {
$params = $app->request()->params();
$xray = new p3k\XRay();
$result = $xray->parse($params['url']);
if(isset($result['data']))
$entry = $result['data'];
else
$entry = [];
render('view-post', array(
'title' => 'View',
'entry' => $entry,
'authorizing' => false
));
}
});
function create_favorite(&$user, $url) {
$tweet_id = false;
@ -678,25 +697,21 @@ $app->get('/reply/preview', function() use($app) {
$entry = false;
$xray = [
'url' => $reply_url
];
$xray_opts = [];
if(preg_match('/twitter\.com\/(?:[^\/]+)\/statuse?s?\/(.+)/', $reply_url, $match)) {
if($user->twitter_access_token) {
$xray['twitter_api_key'] = Config::$twitterClientID;
$xray['twitter_api_secret'] = Config::$twitterClientSecret;
$xray['twitter_access_token'] = $user->twitter_access_token;
$xray['twitter_access_token_secret'] = $user->twitter_token_secret;
$xray_opts['twitter_api_key'] = Config::$twitterClientID;
$xray_opts['twitter_api_secret'] = Config::$twitterClientSecret;
$xray_opts['twitter_access_token'] = $user->twitter_access_token;
$xray_opts['twitter_access_token_secret'] = $user->twitter_token_secret;
}
}
// Pass to X-Ray to see if it can expand the entry
$ch = curl_init('https://xray.p3k.io/parse');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($xray));
$response = curl_exec($ch);
$data = @json_decode($response, true);
$xray = new p3k\XRay();
$xray->http = new p3k\HTTP('Quill ('.Config::$base_url.')');
$data = $xray->parse($reply_url, $xray_opts);
if($data && isset($data['data'])) {
if($data['data']['type'] == 'entry') {
$entry = $data['data'];

Loading…
Cancel
Save