summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--controllers/auth.php61
-rw-r--r--controllers/controllers.php70
-rw-r--r--lib/config.template.php4
-rw-r--r--views/favorite-js.php33
-rw-r--r--views/favorite-popup.php50
-rw-r--r--views/layout.php6
-rw-r--r--views/partials/fb-script.php20
-rw-r--r--views/privacy.php4
-rw-r--r--views/settings.php79
9 files changed, 11 insertions, 316 deletions
diff --git a/controllers/auth.php b/controllers/auth.php
index f339ed4..c4efb1d 100644
--- a/controllers/auth.php
+++ b/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) {
if($user=require_login($app, false)) {
$params = $app->request()->params();
@@ -360,45 +341,3 @@ $app->get('/auth/twitter/callback', function() use($app) {
$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');
- }
-});
diff --git a/controllers/controllers.php b/controllers/controllers.php
index d6cad4f..1b832b9 100644
--- a/controllers/controllers.php
+++ b/controllers/controllers.php
@@ -314,7 +314,11 @@ $app->get('/email', function() use($app) {
$app->get('/settings', function() use($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);
}
});
@@ -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) {
$micropub_request = array(
'like-of' => $url
);
$r = micropub_post_for_user($user, $micropub_request);
- $facebook_id = false;
- $instagram_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)) {
$tweet_id = $match[1];
$twitter = new \TwitterOAuth\Api(Config::$twitterClientID, Config::$twitterClientSecret,
@@ -417,29 +382,6 @@ function create_repost(&$user, $url) {
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) {
if($user=require_login($app)) {
$params = $app->request()->params();
diff --git a/lib/config.template.php b/lib/config.template.php
index 87ce75b..50d3b12 100644
--- a/lib/config.template.php
+++ b/lib/config.template.php
@@ -17,11 +17,7 @@ class Config {
public static $jwtSecret = 'xxx';
- public static $fbClientID = '';
- public static $fbClientSecret = '';
public static $twitterClientID = '';
public static $twitterClientSecret = '';
- public static $instagramClientID = '';
- public static $instagramClientSecret = '';
}
diff --git a/views/favorite-js.php b/views/favorite-js.php
deleted file mode 100644
index 4ce6dba..0000000
--- a/views/favorite-js.php
+++ /dev/null
@@ -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();
diff --git a/views/favorite-popup.php b/views/favorite-popup.php
deleted file mode 100644
index fecc780..0000000
--- a/views/favorite-popup.php
+++ /dev/null
@@ -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> \ No newline at end of file
diff --git a/views/layout.php b/views/layout.php
index f953dc2..9fad319 100644
--- a/views/layout.php
+++ b/views/layout.php
@@ -40,12 +40,6 @@
</head>
<body role="document">
-<?php
-if(property_exists($this, 'include_facebook')) {
- # echo partial('partials/fb-script');
-}
-?>
-
<script type="text/javascript">
var _gaq = _gaq || [];
diff --git a/views/partials/fb-script.php b/views/partials/fb-script.php
deleted file mode 100644
index ce5b96a..0000000
--- a/views/partials/fb-script.php
+++ /dev/null
@@ -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> \ No newline at end of file
diff --git a/views/privacy.php b/views/privacy.php
index acdf235..40ce393 100644
--- a/views/privacy.php
+++ b/views/privacy.php
@@ -3,10 +3,10 @@
<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>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>
diff --git a/views/settings.php b/views/settings.php
index 831528d..46df0bf 100644
--- a/views/settings.php
+++ b/views/settings.php
@@ -4,68 +4,16 @@
<h2>Signed In As</h2>
<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>
+ <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">
- <h3>Instagram</h3>
- <input type="button" id="instagram-button" value="Checking" class="btn">
-
</div>
<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(){
- /*
- $("#facebook-button").click(function(){
- FB.login(window.quillHandleFbLogin, {scope:'publish_actions,user_likes'});
- });
- */
$.getJSON("/auth/twitter", function(data){
// 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>