summaryrefslogtreecommitdiff
path: root/views
diff options
context:
space:
mode:
authorAaron Parecki <aaron@parecki.com>2014-12-24 16:44:44 -0800
committerAaron Parecki <aaron@parecki.com>2014-12-24 16:44:44 -0800
commit2cd148c792a47fea18d760b723d23569ae52d390 (patch)
treecbd2d277d7c56be7042fc7765ea7a3c26c4cd1f8 /views
parent3f090eeb306dec5041d3c2c3b6baa3434f31802b (diff)
Support for "likes" and adding "settings" page
* Supports a bookmarklet to create "like" posts. * Beginning a "settings" page to connect silo profiles for POSSEing likes to twitter, facebook and instagram
Diffstat (limited to 'views')
-rw-r--r--views/layout.php8
-rw-r--r--views/liked-js.php22
-rw-r--r--views/partials/fb-script.php20
-rw-r--r--views/settings.php88
4 files changed, 137 insertions, 1 deletions
diff --git a/views/layout.php b/views/layout.php
index 531dec9..0c78aa7 100644
--- a/views/layout.php
+++ b/views/layout.php
@@ -31,6 +31,12 @@
</head>
<body role="document">
+<?php
+if(property_exists($this, 'include_facebook')) {
+ echo partial('partials/fb-script');
+}
+?>
+
<script type="text/javascript">
var _gaq = _gaq || [];
@@ -65,7 +71,7 @@
<ul class="nav navbar-nav navbar-right">
<? 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>
<? } else if(property_exists($this, 'authorizing')) { ?>
<li class="navbar-text"><?= $this->authorizing ?></li>
diff --git a/views/liked-js.php b/views/liked-js.php
new file mode 100644
index 0000000..80b62ac
--- /dev/null
+++ b/views/liked-js.php
@@ -0,0 +1,22 @@
+<?= $this->facebook_id ? partial('partials/fb-script') : '' ?>
+
+console.log("Favoriting URL: <?= $this->url ?>");
+
+var star = document.createElement('img');
+star.id="quill-star";
+star.src="http://quill.dev/images/<?= $this->like_url ? 'star' : 'red-x' ?>.svg";
+document.body.appendChild(star);
+
+var css = document.createElement('link');
+css.rel="stylesheet";
+css.type="text/css";
+css.href="http://quill.dev/css/favorite.css";
+document.body.appendChild(css);
+
+setTimeout(function(){
+
+ document.getElementById('quill-star').classList.add('hidden');
+ var el = document.getElementById('quill-star');
+ el.parentNode.removeChild(el);
+
+}, 1200);
diff --git a/views/partials/fb-script.php b/views/partials/fb-script.php
new file mode 100644
index 0000000..ce5b96a
--- /dev/null
+++ b/views/partials/fb-script.php
@@ -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> \ No newline at end of file
diff --git a/views/settings.php b/views/settings.php
new file mode 100644
index 0000000..61feefc
--- /dev/null
+++ b/views/settings.php
@@ -0,0 +1,88 @@
+<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>
+
+ -->
+
+</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(){
+ $.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;
+ });
+ }
+ });
+
+ $("#facebook-button").click(function(){
+ FB.login(window.quillHandleFbLogin, {scope:'publish_actions'});
+ });
+});
+</script>