Browse Source

Merge branch 'master' of github.com:aaronpk/IndiePost

pull/5/head
Aaron Parecki 9 years ago
parent
commit
87a76f495e
20 changed files with 779 additions and 47 deletions
  1. +3
    -1
      composer.json
  2. +91
    -19
      composer.lock
  3. +276
    -22
      controllers/controllers.php
  4. +7
    -0
      lib/config.template.php
  5. +31
    -0
      lib/helpers.php
  6. +17
    -0
      public/css/favorite.css
  7. BIN
      public/images/quill-logo-1024.png
  8. +8
    -0
      public/images/red-x.svg
  9. +8
    -0
      public/images/star.svg
  10. +23
    -0
      public/js/fav.js
  11. +33
    -0
      views/favorite-js.php
  12. +50
    -0
      views/favorite-popup.php
  13. +8
    -2
      views/layout.php
  14. +2
    -2
      views/new-bookmark.php
  15. +74
    -0
      views/new-favorite.php
  16. +4
    -0
      views/new-post.php
  17. +1
    -1
      views/partials/bookmark-bookmarklet.php
  18. +10
    -0
      views/partials/favorite-bookmarklet.php
  19. +20
    -0
      views/partials/fb-script.php
  20. +113
    -0
      views/settings.php

+ 3
- 1
composer.json View File

@ -8,7 +8,9 @@
"indieweb/date-formatter": "0.1.*", "indieweb/date-formatter": "0.1.*",
"indieauth/client": "0.1.3", "indieauth/client": "0.1.3",
"mpratt/relativetime": ">=1.0", "mpratt/relativetime": ">=1.0",
"firebase/php-jwt": "dev-master"
"firebase/php-jwt": "dev-master",
"ruudk/twitter-oauth": "dev-master",
"andreyco/instagram": "3.*"
}, },
"autoload": { "autoload": {
"files": [ "files": [

+ 91
- 19
composer.lock View File

@ -3,8 +3,51 @@
"This file locks the dependencies of your project to a known state", "This file locks the dependencies of your project to a known state",
"Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file" "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file"
], ],
"hash": "3e034e0a6a692d5bbfecfdc95ee69db2",
"hash": "f2f8fdb671b52ce22dc0a5e133f9a13d",
"packages": [ "packages": [
{
"name": "andreyco/instagram",
"version": "v3.2",
"source": {
"type": "git",
"url": "https://github.com/Andreyco/Instagram-for-PHP.git",
"reference": "726e724c51301410873d9bae9c659a0597ca47e4"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/Andreyco/Instagram-for-PHP/zipball/726e724c51301410873d9bae9c659a0597ca47e4",
"reference": "726e724c51301410873d9bae9c659a0597ca47e4",
"shasum": ""
},
"require": {
"ext-curl": "*",
"php": ">=5.3.0"
},
"type": "library",
"autoload": {
"psr-4": {
"Andreyco\\Instagram\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-4-Clause"
],
"authors": [
{
"name": "Andrej Badin",
"email": "contact@andrejbadin.com",
"homepage": "http://andrejbadin.com"
}
],
"description": "An easy-to-use PHP Class for accessing Instagram's API.",
"homepage": "https://github.com/Andreyco/Instagram",
"keywords": [
"api",
"instagram"
],
"time": "2014-07-14 19:53:19"
},
{ {
"name": "firebase/php-jwt", "name": "firebase/php-jwt",
"version": "dev-master", "version": "dev-master",
@ -12,12 +55,12 @@
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/firebase/php-jwt.git", "url": "https://github.com/firebase/php-jwt.git",
"reference": "53669d621149e49c2a428722a62acfef3342c260"
"reference": "83b8899cb73d85d648af93f37ec0ac89f4a5bbae"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/firebase/php-jwt/zipball/53669d621149e49c2a428722a62acfef3342c260",
"reference": "53669d621149e49c2a428722a62acfef3342c260",
"url": "https://api.github.com/repos/firebase/php-jwt/zipball/83b8899cb73d85d648af93f37ec0ac89f4a5bbae",
"reference": "83b8899cb73d85d648af93f37ec0ac89f4a5bbae",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -26,7 +69,8 @@
"type": "library", "type": "library",
"autoload": { "autoload": {
"classmap": [ "classmap": [
"Authentication/"
"Authentication/",
"Exceptions/"
] ]
}, },
"notification-url": "https://packagist.org/downloads/", "notification-url": "https://packagist.org/downloads/",
@ -47,7 +91,7 @@
], ],
"description": "A simple library to encode and decode JSON Web Tokens (JWT) in PHP. Should conform to the current spec.", "description": "A simple library to encode and decode JSON Web Tokens (JWT) in PHP. Should conform to the current spec.",
"homepage": "https://github.com/firebase/php-jwt", "homepage": "https://github.com/firebase/php-jwt",
"time": "2013-09-03 20:55:18"
"time": "2014-11-18 17:58:25"
}, },
{ {
"name": "indieauth/client", "name": "indieauth/client",
@ -367,6 +411,41 @@
], ],
"time": "2013-09-23 22:51:48" "time": "2013-09-23 22:51:48"
}, },
{
"name": "ruudk/twitter-oauth",
"version": "dev-master",
"source": {
"type": "git",
"url": "https://github.com/ruudk/twitteroauth.git",
"reference": "7f5a94eaa1572ddbc7f0a32ba3b865b8ac23712a"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/ruudk/twitteroauth/zipball/7f5a94eaa1572ddbc7f0a32ba3b865b8ac23712a",
"reference": "7f5a94eaa1572ddbc7f0a32ba3b865b8ac23712a",
"shasum": ""
},
"require": {
"php": ">=5.3.0"
},
"type": "library",
"autoload": {
"classmap": [
"src"
]
},
"notification-url": "https://packagist.org/downloads/",
"authors": [
{
"name": "Ruud Kamphuis",
"email": "ruud@1plus1media.nl",
"role": "Developer"
}
],
"description": "PHP 5.3 version of abraham/twitteroauth",
"homepage": "http://github.com/ruudk/twitteroauth",
"time": "2014-06-10 18:17:38"
},
{ {
"name": "saltybeagle/savant3", "name": "saltybeagle/savant3",
"version": "dev-master", "version": "dev-master",
@ -446,21 +525,14 @@
"time": "2012-12-13 02:15:50" "time": "2012-12-13 02:15:50"
} }
], ],
"packages-dev": [
],
"aliases": [
],
"packages-dev": [],
"aliases": [],
"minimum-stability": "stable", "minimum-stability": "stable",
"stability-flags": { "stability-flags": {
"saltybeagle/savant3": 20, "saltybeagle/savant3": 20,
"firebase/php-jwt": 20
"firebase/php-jwt": 20,
"ruudk/twitter-oauth": 20
}, },
"platform": [
],
"platform-dev": [
]
"platform": [],
"platform-dev": []
} }

+ 276
- 22
controllers/controllers.php View File

@ -1,6 +1,6 @@
<?php <?php
function require_login(&$app) {
function require_login(&$app, $redirect=true) {
$params = $app->request()->params(); $params = $app->request()->params();
if(array_key_exists('token', $params)) { if(array_key_exists('token', $params)) {
try { try {
@ -8,16 +8,25 @@ function require_login(&$app) {
$_SESSION['user_id'] = $data->user_id; $_SESSION['user_id'] = $data->user_id;
$_SESSION['me'] = $data->me; $_SESSION['me'] = $data->me;
} catch(DomainException $e) { } catch(DomainException $e) {
header('X-Error: DomainException');
$app->redirect('/', 301);
if($redirect) {
header('X-Error: DomainException');
$app->redirect('/', 301);
} else {
return false;
}
} catch(UnexpectedValueException $e) { } catch(UnexpectedValueException $e) {
header('X-Error: UnexpectedValueException');
$app->redirect('/', 301);
if($redirect) {
header('X-Error: UnexpectedValueException');
$app->redirect('/', 301);
} else {
return false;
}
} }
} }
if(!array_key_exists('user_id', $_SESSION)) { if(!array_key_exists('user_id', $_SESSION)) {
$app->redirect('/');
if($redirect)
$app->redirect('/');
return false; return false;
} else { } else {
return ORM::for_table('users')->find_one($_SESSION['user_id']); return ORM::for_table('users')->find_one($_SESSION['user_id']);
@ -95,6 +104,24 @@ $app->get('/bookmark', function() use($app) {
} }
}); });
$app->get('/favorite', function() use($app) {
if($user=require_login($app)) {
$params = $app->request()->params();
$url = '';
if(array_key_exists('url', $params))
$url = $params['url'];
$html = render('new-favorite', array(
'title' => 'New Favorite',
'url' => $url,
'token' => generate_login_token()
));
$app->response()->body($html);
}
});
$app->post('/prefs', function() use($app) { $app->post('/prefs', function() use($app) {
if($user=require_login($app)) { if($user=require_login($app)) {
$params = $app->request()->params(); $params = $app->request()->params();
@ -165,6 +192,109 @@ $app->get('/add-to-home', function() use($app) {
} }
}); });
$app->get('/settings', function() use($app) {
if($user=require_login($app)) {
$html = render('settings', array('title' => 'Settings', 'include_facebook' => true));
$app->response()->body($html);
}
});
$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
}
}
if(preg_match('/https?:\/\/(?:www\.)?twitter\.com\/[^\/]+\/status(?:es)?\/(\d+)/', $url, $match)) {
$tweet_id = $match[1];
$twitter = new \TwitterOAuth\Api(Config::$twitterClientID, Config::$twitterClientSecret,
$user->twitter_access_token, $user->twitter_token_secret);
$result = $twitter->post('favorites/create', array(
'id' => $tweet_id
));
}
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();
$r = create_favorite($user, $params['url']);
$app->response()->body(json_encode(array(
'location' => $r['location'],
'error' => $r['error']
)));
}
});
$app->get('/micropub/syndications', function() use($app) { $app->get('/micropub/syndications', function() use($app) {
if($user=require_login($app)) { if($user=require_login($app)) {
$data = get_syndication_targets($user); $data = get_syndication_targets($user);
@ -184,31 +314,155 @@ $app->post('/micropub/post', function() use($app) {
return $v !== ''; return $v !== '';
}); });
// Now send to the micropub endpoint
$r = micropub_post($user->micropub_endpoint, $params, $user->micropub_access_token);
$request = $r['request'];
$response = $r['response'];
$r = micropub_post_for_user($user, $params);
$user->last_micropub_response = json_encode($r);
$user->last_micropub_response_date = date('Y-m-d H:i:s');
$app->response()->body(json_encode(array(
'request' => htmlspecialchars($r['request']),
'response' => htmlspecialchars($r['response']),
'location' => $r['location'],
'error' => $r['error'],
'curlinfo' => $r['curlinfo']
)));
}
});
/*
$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();
// User just auth'd with twitter, store the access token
$user->twitter_access_token = $params['twitter_token'];
$user->twitter_token_secret = $params['twitter_secret'];
$user->save();
// Check the response and look for a "Location" header containing the URL
if($response && preg_match('/Location: (.+)/', $response, $match)) {
$location = $match[1];
$user->micropub_success = 1;
$app->response()->body(json_encode(array(
'result' => 'ok'
)));
} else {
$app->response()->body(json_encode(array(
'result' => 'error'
)));
}
});
function getTwitterLoginURL(&$twitter) {
$request_token = $twitter->getRequestToken(Config::$base_url . 'auth/twitter/callback');
$_SESSION['twitter_auth'] = $request_token;
return $twitter->getAuthorizeURL($request_token['oauth_token']);
}
$app->get('/auth/twitter', function() use($app) {
$params = $app->request()->params();
if($user=require_login($app, false)) {
// If there is an existing Twitter token, check if it is valid
// Otherwise, generate a Twitter login link
$twitter_login_url = false;
$twitter = new \TwitterOAuth\Api(Config::$twitterClientID, Config::$twitterClientSecret,
$user->twitter_access_token, $user->twitter_token_secret);
if(array_key_exists('login', $params)) {
$twitter = new \TwitterOAuth\Api(Config::$twitterClientID, Config::$twitterClientSecret);
$twitter_login_url = getTwitterLoginURL($twitter);
} else { } else {
$location = false;
if($user->twitter_access_token) {
if ($twitter->get('account/verify_credentials')) {
$app->response()->body(json_encode(array(
'result' => 'ok'
)));
return;
} else {
// If the existing twitter token is not valid, generate a login link
$twitter_login_url = getTwitterLoginURL($twitter);
}
} else {
$twitter_login_url = getTwitterLoginURL($twitter);
}
} }
$app->response()->body(json_encode(array(
'url' => $twitter_login_url
)));
} else {
$app->response()->body(json_encode(array(
'result' => 'error'
)));
}
});
$app->get('/auth/twitter/callback', function() use($app) {
if($user=require_login($app)) {
$params = $app->request()->params();
$twitter = new \TwitterOAuth\Api(Config::$twitterClientID, Config::$twitterClientSecret,
$_SESSION['twitter_auth']['oauth_token'], $_SESSION['twitter_auth']['oauth_token_secret']);
$credentials = $twitter->getAccessToken($params['oauth_verifier']);
$user->twitter_access_token = $credentials['oauth_token'];
$user->twitter_token_secret = $credentials['oauth_token_secret'];
$user->twitter_username = $credentials['screen_name'];
$user->save(); $user->save();
$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()->body(json_encode(array(
'result' => 'ok',
'username' => $igUser->data->username,
'url' => $instagram->getLoginUrl(array('basic','likes'))
)));
return;
}
}
$app->response()->body(json_encode(array( $app->response()->body(json_encode(array(
'request' => htmlspecialchars($request),
'response' => htmlspecialchars($response),
'location' => $location,
'error' => $r['error'],
'curlinfo' => $r['curlinfo']
'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');
}
});

+ 7
- 0
lib/config.template.php View File

@ -10,5 +10,12 @@ class Config {
public static $dbPassword = ''; public static $dbPassword = '';
public static $jwtSecret = 'xxx'; public static $jwtSecret = 'xxx';
public static $fbClientID = '';
public static $fbClientSecret = '';
public static $twitterClientID = '';
public static $twitterClientSecret = '';
public static $instagramClientID = '';
public static $instagramClientSecret = '';
} }

+ 31
- 0
lib/helpers.php View File

@ -70,6 +70,26 @@ function get_timezone($lat, $lng) {
return null; return null;
} }
function micropub_post_for_user(&$user, $params) {
// Now send to the micropub endpoint
$r = micropub_post($user->micropub_endpoint, $params, $user->micropub_access_token);
$user->last_micropub_response = json_encode($r);
$user->last_micropub_response_date = date('Y-m-d H:i:s');
// Check the response and look for a "Location" header containing the URL
if($r['response'] && preg_match('/Location: (.+)/', $r['response'], $match)) {
$r['location'] = trim($match[1]);
$user->micropub_success = 1;
} else {
$r['location'] = false;
}
$user->save();
return $r;
}
function micropub_post($endpoint, $params, $access_token) { function micropub_post($endpoint, $params, $access_token) {
$ch = curl_init(); $ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $endpoint); curl_setopt($ch, CURLOPT_URL, $endpoint);
@ -175,3 +195,14 @@ function relative_time($date) {
} }
return $rel->timeAgo($date); return $rel->timeAgo($date);
} }
function instagram_client() {
return new Andreyco\Instagram\Client(array(
'apiKey' => Config::$instagramClientID,
'apiSecret' => Config::$instagramClientSecret,
'apiCallback' => Config::$base_url . 'auth/instagram/callback',
'scope' => array('basic','likes'),
));
}

+ 17
- 0
public/css/favorite.css View File

@ -0,0 +1,17 @@
#quill-star {
position: fixed;
top: 50%;
left: 50%;
margin-top: -100px;
margin-left: -100px;
width: 200px;
height: 200px;
}
#quill-star.hidden {
display: none;
}

BIN
public/images/quill-logo-1024.png View File

Before After
Width: 1024  |  Height: 1024  |  Size: 38 KiB

+ 8
- 0
public/images/red-x.svg View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 16.0.4, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
width="108px" height="108px" viewBox="0 0 108 108" enable-background="new 0 0 108 108" xml:space="preserve">
<line fill="none" stroke="#972D2C" stroke-width="20" stroke-miterlimit="10" x1="8.788" y1="8.308" x2="99.81" y2="99.329"/>
<line fill="none" stroke="#972D2C" stroke-width="20" stroke-miterlimit="10" x1="99.81" y1="8.308" x2="8.788" y2="99.329"/>
</svg>

+ 8
- 0
public/images/star.svg View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 16.0.4, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
width="108px" height="108px" viewBox="0 0 108 108" enable-background="new 0 0 108 108" xml:space="preserve">
<polygon fill="#FCB117" points="54.306,4.549 70.476,37.312 106.633,42.566 80.47,68.069 86.646,104.079 54.306,87.077
21.967,104.079 28.143,68.069 1.98,42.566 38.136,37.312 "/>
</svg>

+ 23
- 0
public/js/fav.js View File

@ -0,0 +1,23 @@
console.log("Favoriting with token: " + quill_token);
var http = new XMLHttpRequest();
var params = "like-of=" + encodeURIComponent(window.location) + "&token=" + quill_token;
http.open("POST", "http://quill.dev/favorite", true);
http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
http.onreadystatechange = function() {//Call a function when the state changes.
console.log(http);
if(http.readyState == 4 && http.status == 200) {
alert(http.responseText);
}
}
http.send(params);
/*
(function(){var el=document.createElement('input'); el.type="hidden"; el.id="quill_token"; el.value="eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoiMjciLCJtZSI6Imh0dHA6XC9cL2Fhcm9ucGFyZWNraS5jb20iLCJjcmVhdGVkX2F0IjoxNDEwMTE3NTM5fQ.ifp1VIgCTz9NPtMTlTLPBXAGSxHwpGS5tLPhXGxrjNk"; document.body.appendChild(el); document.body.appendChild(document.createElement('script')).src='http://quill.dev/js/fav.js';})();
(function(){document.body.appendChild(document.createElement('script')).src='http://quill.dev/favorite.js?url='+encodeURIComponent(window.location)+'&token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoiMSIsIm1lIjoiaHR0cDpcL1wvcGsuZGV2XC8iLCJjcmVhdGVkX2F0IjoxNDE5MDM2NzAzfQ.AgJ5xyviiBzWOvQO0je0Bdi3BUpKJ4CLJnx8GIm-0OI';})();
*/

+ 33
- 0
views/favorite-js.php View File

@ -0,0 +1,33 @@
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
- 0
views/favorite-popup.php View File

@ -0,0 +1,50 @@
<!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>

+ 8
- 2
views/layout.php View File

@ -31,6 +31,12 @@
</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 || [];
@ -58,14 +64,14 @@
<? if(session('me')) { ?> <? if(session('me')) { ?>
<li><a href="/new">New Post</a></li> <li><a href="/new">New Post</a></li>
<li><a href="/bookmark">Bookmark</a></li> <li><a href="/bookmark">Bookmark</a></li>
<li><a href="/favorite">Favorite</a></li>
<? } ?> <? } ?>
<li><a href="/docs">Docs</a></li> <li><a href="/docs">Docs</a></li>
</ul> </ul>
<ul class="nav navbar-nav navbar-right"> <ul class="nav navbar-nav navbar-right">
<? if(session('me')) { ?> <? if(session('me')) { ?>
<li><a href="/add-to-home?start">Add to Home Screen</a></li>
<li><span class="navbar-text"><?= preg_replace('/https?:\/\//','',session('me')) ?></span></li>
<li><a href="/settings"><?= preg_replace(array('/https?:\/\//','/\/$/'),'',session('me')) ?></a></li>
<li><a href="/signout">Sign Out</a></li> <li><a href="/signout">Sign Out</a></li>
<? } else if(property_exists($this, 'authorizing')) { ?> <? } else if(property_exists($this, 'authorizing')) { ?>
<li class="navbar-text"><?= $this->authorizing ?></li> <li class="navbar-text"><?= $this->authorizing ?></li>

+ 2
- 2
views/new-bookmark.php View File

@ -87,9 +87,9 @@ $(function(){
if(response.location != false) { if(response.location != false) {
// $("#test_success").removeClass('hidden');
$("#test_success").removeClass('hidden');
$("#test_error").addClass('hidden'); $("#test_error").addClass('hidden');
// $("#post_href").attr("href", response.location);
$("#post_href").attr("href", response.location);
// $("#note_bookmark").val(""); // $("#note_bookmark").val("");
// $("#note_content").val(""); // $("#note_content").val("");

+ 74
- 0
views/new-favorite.php View File

@ -0,0 +1,74 @@
<div class="narrow">
<?= partial('partials/header') ?>
<div style="clear: both;">
<div class="alert alert-success hidden" id="test_success"><strong>Success! We found a Location header in the response!</strong><br>Your post should be on your website now!<br><a href="" id="post_href">View your post</a></div>
<div class="alert alert-danger hidden" id="test_error"><strong>Your endpoint did not return a Location header.</strong><br>See <a href="/creating-a-micropub-endpoint">Creating a Micropub Endpoint</a> for more information.</div>
</div>
<form role="form" style="margin-top: 20px;" id="note_form">
<div class="form-group">
<label for="note_url">URL to Favorite (<code>like-of</code>)</label>
<input type="text" id="note_url" value="<?= $this->url ?>" class="form-control">
</div>
<div style="float: right; margin-top: 6px;">
<button class="btn btn-success" id="btn_post">Post</button>
</div>
</form>
<div style="clear: both;"></div>
<hr>
<div style="text-align: right;">
Bookmarklet: <a href="javascript:<?= js_bookmarklet('partials/favorite-bookmarklet', $this) ?>" class="btn btn-default btn-xs">favorite</a>
</div>
</div>
<script>
$(function(){
// ctrl-s to save
$(window).on('keydown', function(e){
if(e.keyCode == 83 && e.ctrlKey){
$("#btn_post").click();
}
});
$("#btn_post").click(function(){
var syndications = [];
$("#syndication-container button.btn-info").each(function(i,btn){
syndications.push($(btn).data('syndication'));
});
$.post("/favorite", {
url: $("#note_url").val()
}, function(data){
var response = JSON.parse(data);
if(response.location != false) {
$("#test_success").removeClass('hidden');
$("#test_error").addClass('hidden');
$("#post_href").attr("href", response.location);
window.location = response.location;
} else {
$("#test_success").addClass('hidden');
$("#test_error").removeClass('hidden');
}
});
return false;
});
bind_syndication_buttons();
});
<?= partial('partials/syndication-js') ?>
</script>

+ 4
- 0
views/new-post.php View File

@ -97,6 +97,10 @@
</table> </table>
</div> </div>
<hr>
<div style="text-align: right;">
<a href="/add-to-home?start">Add to Home Screen</a>
</div>
</div> </div>
<script> <script>

+ 1
- 1
views/partials/bookmark-bookmarklet.php View File

@ -1,4 +1,4 @@
javascript:(function(){
(function(){
var t;try{t=((window.getSelection&&window.getSelection())||(document.getSelection&&document.getSelection())||(document.selection&&document.selection.createRange&&document.selection.createRange().text));}catch(e){t="";}; var t;try{t=((window.getSelection&&window.getSelection())||(document.getSelection&&document.getSelection())||(document.selection&&document.selection.createRange&&document.selection.createRange().text));}catch(e){t="";};
window.location="<?= Config::$base_url ?>bookmark?url="+encodeURIComponent(window.location.href)+"&content="+encodeURIComponent((t == '' ? '' : '"'+t+'"'))+"&name="+encodeURIComponent(document.title)+"&token=<?= $this->token ?>"; window.location="<?= Config::$base_url ?>bookmark?url="+encodeURIComponent(window.location.href)+"&content="+encodeURIComponent((t == '' ? '' : '"'+t+'"'))+"&name="+encodeURIComponent(document.title)+"&token=<?= $this->token ?>";
})(); })();

+ 10
- 0
views/partials/favorite-bookmarklet.php View File

@ -0,0 +1,10 @@
var quill_popup=function(){
window.open(document.getElementById('quill-script').src.replace('favorite.js?','favorite-popup?'),'quill-like', 'status=no,directories=no,location=no,resizable=no,menubar=no,width=300,height=200,toolbar=no');
};
(function(){
var quill=document.createElement('script');
quill.src='<?= Config::$base_url ?>favorite.js?url='+encodeURIComponent(window.location)+'&token=<?= $this->token ?>';
quill.setAttribute('id','quill-script');
quill.setAttribute('onerror', 'quill_popup()');
document.body.appendChild(quill);
})();

+ 20
- 0
views/partials/fb-script.php View File

@ -0,0 +1,20 @@
<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>

+ 113
- 0
views/settings.php View File

@ -0,0 +1,113 @@
<div class="narrow">
<?= partial('partials/header') ?>
<h2>Signed In As</h2>
<code><?= session('me') ?></code>
<!--
<h3>Facebook</h3>
<input type="button" id="facebook-button" value="Checking" class="btn">
-->
<h3>Twitter</h3>
<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
if(data && data.result == 'ok') {
$("#twitter-button").val("Connected").addClass("btn-success");
} else if(data && data.url) {
$("#twitter-button").val("Sign In").data("url", data.url).addClass("btn-warning");
} else {
$("#twitter-button").val("Error").addClass("btn-danger");
}
});
$("#twitter-button").click(function(){
if($(this).data('url')) {
window.location = $(this).data('url');
} else {
$.getJSON("/auth/twitter", {login: 1}, function(data){
window.location = data.url;
});
}
});
$.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>

Loading…
Cancel
Save