diff options
Diffstat (limited to 'views')
-rw-r--r-- | views/favorite-js.php | 33 | ||||
-rw-r--r-- | views/favorite-popup.php | 50 | ||||
-rw-r--r-- | views/layout.php | 10 | ||||
-rw-r--r-- | views/new-bookmark.php | 4 | ||||
-rw-r--r-- | views/new-favorite.php | 74 | ||||
-rw-r--r-- | views/new-post.php | 4 | ||||
-rw-r--r-- | views/partials/bookmark-bookmarklet.php | 2 | ||||
-rw-r--r-- | views/partials/favorite-bookmarklet.php | 10 | ||||
-rw-r--r-- | views/partials/fb-script.php | 20 | ||||
-rw-r--r-- | views/settings.php | 113 |
10 files changed, 315 insertions, 5 deletions
diff --git a/views/favorite-js.php b/views/favorite-js.php new file mode 100644 index 0000000..4ce6dba --- /dev/null +++ b/views/favorite-js.php @@ -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(); diff --git a/views/favorite-popup.php b/views/favorite-popup.php new file mode 100644 index 0000000..fecc780 --- /dev/null +++ b/views/favorite-popup.php @@ -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) ?>&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 531dec9..8d7607d 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 || []; @@ -58,14 +64,14 @@ <? if(session('me')) { ?> <li><a href="/new">New Post</a></li> <li><a href="/bookmark">Bookmark</a></li> + <li><a href="/favorite">Favorite</a></li> <? } ?> <li><a href="/docs">Docs</a></li> </ul> <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/new-bookmark.php b/views/new-bookmark.php index d4100ba..fac2c95 100644 --- a/views/new-bookmark.php +++ b/views/new-bookmark.php @@ -87,9 +87,9 @@ $(function(){ if(response.location != false) { - // $("#test_success").removeClass('hidden'); + $("#test_success").removeClass('hidden'); $("#test_error").addClass('hidden'); - // $("#post_href").attr("href", response.location); + $("#post_href").attr("href", response.location); // $("#note_bookmark").val(""); // $("#note_content").val(""); diff --git a/views/new-favorite.php b/views/new-favorite.php new file mode 100644 index 0000000..7b19350 --- /dev/null +++ b/views/new-favorite.php @@ -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> diff --git a/views/new-post.php b/views/new-post.php index fa7b9bc..12c01f9 100644 --- a/views/new-post.php +++ b/views/new-post.php @@ -97,6 +97,10 @@ </table> </div> + <hr> + <div style="text-align: right;"> + <a href="/add-to-home?start">Add to Home Screen</a> + </div> </div> <script> diff --git a/views/partials/bookmark-bookmarklet.php b/views/partials/bookmark-bookmarklet.php index d47a728..0dfd916 100644 --- a/views/partials/bookmark-bookmarklet.php +++ b/views/partials/bookmark-bookmarklet.php @@ -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="";}; window.location="<?= Config::$base_url ?>bookmark?url="+encodeURIComponent(window.location.href)+"&content="+encodeURIComponent((t == '' ? '' : '"'+t+'"'))+"&name="+encodeURIComponent(document.title)+"&token=<?= $this->token ?>"; })(); diff --git a/views/partials/favorite-bookmarklet.php b/views/partials/favorite-bookmarklet.php new file mode 100644 index 0000000..e4d27bd --- /dev/null +++ b/views/partials/favorite-bookmarklet.php @@ -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); +})();
\ No newline at end of file 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..831528d --- /dev/null +++ b/views/settings.php @@ -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> |