Browse Source

remove facebook/instagram stuff

pull/64/head
Aaron Parecki 8 years ago
parent
commit
7d19f61b10
No known key found for this signature in database GPG Key ID: 276C2817346D6056
  1. 61
      controllers/auth.php
  2. 70
      controllers/controllers.php
  3. 4
      lib/config.template.php
  4. 33
      views/favorite-js.php
  5. 50
      views/favorite-popup.php
  6. 6
      views/layout.php
  7. 20
      views/partials/fb-script.php
  8. 4
      views/privacy.php
  9. 79
      views/settings.php

61
controllers/auth.php

@ -256,25 +256,6 @@ $app->get('/signout', function() use($app) {
}); });
/*
$app->post('/auth/facebook', function() use($app) {
if($user=require_login($app, false)) {
$params = $app->request()->params();
// User just auth'd with facebook, store the access token
$user->facebook_access_token = $params['fb_token'];
$user->save();
$app->response()->body(json_encode(array(
'result' => 'ok'
)));
} else {
$app->response()->body(json_encode(array(
'result' => 'error'
)));
}
});
*/
$app->post('/auth/twitter', function() use($app) { $app->post('/auth/twitter', function() use($app) {
if($user=require_login($app, false)) { if($user=require_login($app, false)) {
$params = $app->request()->params(); $params = $app->request()->params();
@ -360,45 +341,3 @@ $app->get('/auth/twitter/callback', function() use($app) {
$app->redirect('/settings'); $app->redirect('/settings');
} }
}); });
$app->get('/auth/instagram', function() use($app) {
if($user=require_login($app, false)) {
$instagram = instagram_client();
// If there is an existing Instagram auth token, check if it's valid
if($user->instagram_access_token) {
$instagram->setAccessToken($user->instagram_access_token);
$igUser = $instagram->getUser();
if($igUser && $igUser->meta->code == 200) {
$app->response()['Content-type'] = 'application/json';
$app->response()->body(json_encode(array(
'result' => 'ok',
'username' => $igUser->data->username,
'url' => $instagram->getLoginUrl(array('basic','likes'))
)));
return;
}
}
$app->response()['Content-type'] = 'application/json';
$app->response()->body(json_encode(array(
'result' => 'error',
'url' => $instagram->getLoginUrl(array('basic','likes'))
)));
}
});
$app->get('/auth/instagram/callback', function() use($app) {
if($user=require_login($app)) {
$params = $app->request()->params();
$instagram = instagram_client();
$data = $instagram->getOAuthToken($params['code']);
$user->instagram_access_token = $data->access_token;
$user->save();
$app->redirect('/settings');
}
});

70
controllers/controllers.php

@ -314,7 +314,11 @@ $app->get('/email', function() use($app) {
$app->get('/settings', function() use($app) { $app->get('/settings', function() use($app) {
if($user=require_login($app)) { if($user=require_login($app)) {
$html = render('settings', array('title' => 'Settings', 'include_facebook' => true, 'authorizing' => false));
$html = render('settings', [
'title' => 'Settings',
'user' => $user,
'authorizing' => false
]);
$app->response()->body($html); $app->response()->body($html);
} }
}); });
@ -339,54 +343,15 @@ $app->get('/settings/html-content', function() use($app) {
} }
}); });
$app->get('/favorite-popup', function() use($app) {
if($user=require_login($app)) {
$params = $app->request()->params();
$html = $app->render('favorite-popup.php', array(
'url' => $params['url'],
'token' => $params['token']
));
$app->response()->body($html);
}
});
function create_favorite(&$user, $url) { function create_favorite(&$user, $url) {
$micropub_request = array( $micropub_request = array(
'like-of' => $url 'like-of' => $url
); );
$r = micropub_post_for_user($user, $micropub_request); $r = micropub_post_for_user($user, $micropub_request);
$facebook_id = false;
$instagram_id = false;
$tweet_id = false; $tweet_id = false;
/*
// Facebook likes are posted via Javascript, so pass the FB ID to the javascript code
if(preg_match('/https?:\/\/(?:www\.)?facebook\.com\/(?:[^\/]+)\/posts\/(\d+)/', $url, $match)) {
$facebook_id = $match[1];
}
if(preg_match('/https?:\/\/(?:www\.)?facebook\.com\/photo\.php\?fbid=(\d+)/', $url, $match)) {
$facebook_id = $match[1];
}
*/
if(preg_match('/https?:\/\/(?:www\.)?instagram\.com\/p\/([^\/]+)/', $url, $match)) {
$instagram_id = $match[1];
if($user->instagram_access_token) {
$instagram = instagram_client();
$instagram->setAccessToken($user->instagram_access_token);
$ch = curl_init('https://api.instagram.com/v1/media/shortcode/' . $instagram_id . '?access_token=' . $user->instagram_access_token);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = json_decode(curl_exec($ch));
$result = $instagram->likeMedia($result->data->id);
} else {
// TODO: indicate that the instagram post couldn't be liked because no access token was available
}
}
// POSSE favorites to Twitter
if($user->twitter_access_token && preg_match('/https?:\/\/(?:www\.)?twitter\.com\/[^\/]+\/status(?:es)?\/(\d+)/', $url, $match)) { if($user->twitter_access_token && preg_match('/https?:\/\/(?:www\.)?twitter\.com\/[^\/]+\/status(?:es)?\/(\d+)/', $url, $match)) {
$tweet_id = $match[1]; $tweet_id = $match[1];
$twitter = new \TwitterOAuth\Api(Config::$twitterClientID, Config::$twitterClientSecret, $twitter = new \TwitterOAuth\Api(Config::$twitterClientID, Config::$twitterClientSecret,
@ -417,29 +382,6 @@ function create_repost(&$user, $url) {
return $r; return $r;
} }
$app->get('/favorite.js', function() use($app) {
$app->response()->header("Content-type", "text/javascript");
if($user=require_login($app, false)) {
$params = $app->request()->params();
if(array_key_exists('url', $params)) {
$r = create_favorite($user, $params['url']);
$app->response()->body($app->render('favorite-js.php', array(
'url' => $params['url'],
'like_url' => $r['location'],
'error' => $r['error'],
// 'facebook_id' => $facebook_id
)));
} else {
$app->response()->body('alert("no url");');
}
} else {
$app->response()->body('alert("invalid token");');
}
});
$app->post('/favorite', function() use($app) { $app->post('/favorite', function() use($app) {
if($user=require_login($app)) { if($user=require_login($app)) {
$params = $app->request()->params(); $params = $app->request()->params();

4
lib/config.template.php

@ -17,11 +17,7 @@ class Config {
public static $jwtSecret = 'xxx'; public static $jwtSecret = 'xxx';
public static $fbClientID = '';
public static $fbClientSecret = '';
public static $twitterClientID = ''; public static $twitterClientID = '';
public static $twitterClientSecret = ''; public static $twitterClientSecret = '';
public static $instagramClientID = '';
public static $instagramClientSecret = '';
} }

33
views/favorite-js.php

@ -1,33 +0,0 @@
console.log("Favoriting URL: <?= $this->url ?>");
var css = document.createElement('link');
css.rel="stylesheet";
css.type="text/css";
css.href="<?= Config::$base_url ?>css/favorite.css";
document.body.appendChild(css);
function show_star() {
var star = document.createElement('img');
star.id="quill-star";
star.src="<?= Config::$base_url ?>images/<?= $this->like_url ? 'star' : 'red-x' ?>.svg";
star.onload=function() {
setTimeout(function(){
document.getElementById('quill-star').classList.add('hidden');
var el = document.getElementById('quill-star');
el.parentNode.removeChild(el);
if(typeof favorite_finished == "function") {
favorite_finished();
} else {
// For now, redirect the user to the URL of their favorite so they can see it posted.
// Might want to change this later.
window.location = "<?= $this->like_url ?>";
}
}, 1200);
}
document.body.appendChild(star);
}
show_star();

50
views/favorite-popup.php

@ -1,50 +0,0 @@
<!doctype html>
<html lang="en">
<head>
<title>Favoriting</title>
</head>
<body>
<script>
function favorite_finished() {
self.close();
}
</script>
<script src="/favorite.js?url=<?= urlencode($this->url) ?>&amp;token=<?= $this->token ?>"></script>
<?php /*
<script>
window.quillFbInit = function() {
FB.getLoginStatus(function(response) {
if (response.status === 'connected') {
// the user is logged in and has authenticated your
// app, and response.authResponse supplies
// the user's ID, a valid access token, a signed
// request, and the time the access token
// and signed request each expire
var uid = response.authResponse.userID;
var accessToken = response.authResponse.accessToken;
console.log(accessToken);
FB.api("/<?= $this->facebook_id ?>/likes", "post", function(response){
console.log(response);
show_star();
});
} else if (response.status === 'not_authorized') {
// the user is logged in to Facebook,
// but has not authenticated your app
console.log("Logged in but not authorized");
} else {
// the user isn't logged in to Facebook.
console.log("User isn't logged in");
}
});
};
</script>
<?= partial('partials/fb-script') ?>
*/ ?>
</body>
</html>

6
views/layout.php

@ -40,12 +40,6 @@
</head> </head>
<body role="document"> <body role="document">
<?php
if(property_exists($this, 'include_facebook')) {
# echo partial('partials/fb-script');
}
?>
<script type="text/javascript"> <script type="text/javascript">
var _gaq = _gaq || []; var _gaq = _gaq || [];

20
views/partials/fb-script.php

@ -1,20 +0,0 @@
<script>
window.fbAsyncInit = function() {
FB.init({
appId : '<?= Config::$fbClientID ?>',
xfbml : true,
version : 'v2.2'
});
if(window.quillFbInit) {
window.quillFbInit();
}
};
(function(d, s, id){
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) {return;}
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/sdk.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
</script>

4
views/privacy.php

@ -3,10 +3,10 @@
<h2>Privacy Policy</h2> <h2>Privacy Policy</h2>
<p>Quill enables you to post text, bookmarks and likes to your own wbesite</p>
<p>Quill enables you to post text, bookmarks, likes, and other kinds of posts to your own wbesite</p>
<p>Quill does not store your posts itself, but does cache the last response from your website and provides it to you for debugging purposes.</p> <p>Quill does not store your posts itself, but does cache the last response from your website and provides it to you for debugging purposes.</p>
<p>If you connect Quill to your Facebook or Twitter account, Quill can post to those sites on your behalf. Quill will never post anything to your accounts without an explicit action on your part.</p>
<p>If you connect Quill to your Twitter account, Quill can favorite tweets on your behalf when you favorite a Twitter URL. Quill will never post anything to your accounts without an explicit action on your part.</p>
</div> </div>

79
views/settings.php

@ -4,68 +4,16 @@
<h2>Signed In As</h2> <h2>Signed In As</h2>
<code><?= session('me') ?></code> <code><?= session('me') ?></code>
<!--
<h3>Facebook</h3>
<input type="button" id="facebook-button" value="Checking" class="btn">
-->
<h3>Access Token</h3>
<input type="text" class="form-control" readonly="readonly" value="<?= $this->user->micropub_access_token ?>">
<h3>Twitter</h3> <h3>Twitter</h3>
<p>Connecting a Twitter account will automatically "favorite" tweets on Twitter when you favorite a Twitter URL in Quill.</p>
<input type="button" id="twitter-button" value="Checking" class="btn"> <input type="button" id="twitter-button" value="Checking" class="btn">
<h3>Instagram</h3>
<input type="button" id="instagram-button" value="Checking" class="btn">
</div> </div>
<script> <script>
/*
window.quillFbInit = function() {
FB.getLoginStatus(function(response) {
if (response.status === 'connected') {
// the user is logged in and has authenticated your
// app, and response.authResponse supplies
// the user's ID, a valid access token, a signed
// request, and the time the access token
// and signed request each expire
var uid = response.authResponse.userID;
var accessToken = response.authResponse.accessToken;
save_facebook_token(response.authResponse.accessToken);
} else if (response.status === 'not_authorized') {
// the user is logged in to Facebook,
// but has not authenticated your app
console.log("Logged in but not authorized");
$("#facebook-button").val("Sign In").addClass("btn-warning");
} else {
// the user isn't logged in to Facebook.
console.log("User isn't logged in");
$("#facebook-button").val("Sign In").addClass("btn-warning");
}
});
};
window.quillHandleFbLogin = function(response) {
save_facebook_token(response.authResponse.accessToken);
};
function save_facebook_token(token) {
console.log("Authed with token: " + token);
$.post('/auth/facebook', {
fb_token: token
}, function(data){
$("#facebook-button").val("Connected").addClass("btn-success");
});
}
*/
$(function(){ $(function(){
/*
$("#facebook-button").click(function(){
FB.login(window.quillHandleFbLogin, {scope:'publish_actions,user_likes'});
});
*/
$.getJSON("/auth/twitter", function(data){ $.getJSON("/auth/twitter", function(data){
// Check if we're already authorized with twitter // Check if we're already authorized with twitter
@ -88,26 +36,5 @@ $(function(){
} }
}); });
$.getJSON("/auth/instagram", function(data){
// Check if we're already authorized with Instagram
if(data && data.result == 'ok') {
$("#instagram-button").val("Connected").addClass("btn-success");
} else if(data && data.url) {
$("#instagram-button").val("Sign In").data("url", data.url).addClass("btn-warning");
} else {
$("#instagram-button").val("Error").addClass("btn-danger");
}
});
$("#instagram-button").click(function(){
if($(this).data('url')) {
window.location = $(this).data('url');
} else {
$.getJSON("/auth/instagram", {login: 1}, function(data){
window.location = data.url;
});
}
});
}); });
</script> </script>
Loading…
Cancel
Save