--- a/js/w3c_talks.js Fri Aug 30 17:29:09 2013 +0900
+++ b/js/w3c_talks.js Fri Aug 30 17:58:48 2013 +0900
@@ -3,21 +3,24 @@
// Global variables for tweet posting
var url = 'http://www.vodstock.com/w3c_talks/w3c_talks.php';
- var hashtag = getHashtag();
+ var hashtag = getMetaTag('hashtag');
+ var author = getMetaTag('author');
+ var title = document.title;
+ var accesskey = getMetaTag('accesskey');
+ // TODO: Find proper way to handle accesskey
+ if (!accesskey) return false;
- function getHashtag() {
- var hashmeta = document.querySelector('[name=hashtag]');
+ function getMetaTag(name) {
+ var tag = document.querySelector('[name=' + name + ']');
try {
- var hashtag = hashmeta.content;
- hashtag = (hashtag.indexOf('#') < 0) ? '#' + hashtag : hashtag;
- return hashtag;
+ return tag.content;
} catch(e) {
console.log('Unable to get hashtag');
return '';
}
}
-
+
// Use XHR to send data to specified URL
function doPost(url, data) {
var httpRequest;
@@ -42,12 +45,30 @@
if (httpRequest.readyState === 4) {
if (httpRequest.status !== 200) {
console.log('There was a problem with the XHR action.');
+ } else {
+ alert('Success: ' + httpRequest.responseText);
}
}
};
httpRequest.open('POST', url);
httpRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
- httpRequest.send('data=' + encodeURIComponent(data));
+ httpRequest.send(data);
+ }
+
+ function sendNote(slide) {
+ try {
+ var note = slide.getAttribute('data-note');
+ if (note) {
+ var data = 'note=' + encodeURIComponent(note);
+ data += '&hashtag=' + encodeURIComponent(hashtag);
+ data += '&author=' + encodeURIComponent(author);
+ data += '&title=' + encodeURIComponent(title);
+ data += '&accesskey=' + accesskey;
+ doPost(url, data);
+ }
+ } catch(e) {
+ console.log('Unable to send note');
+ }
}
// The following is for Slidy:
@@ -59,12 +80,7 @@
w3c_slidy.show_slide = function(slide) {
this.__show_slide(slide);
- try {
- var note = slide.getAttribute('data-note');
- if (note) doPost(url, note + ' ' + hashtag);
- } catch(e) {
- console.log('Unable to send slide note: ' + note);
- }
+ sendNote(slide);
};
}
@@ -78,12 +94,9 @@
// Hijack "go" method and add action to send note
shower.go = function(slideNumber, callback) {
this.__go(slideNumber, callback);
-
- try {
- var note = slides[slideNumber].getAttribute('data-note');
- if (note) doPost(url, note + ' ' + hashtag);
- } catch(e) {
- console.log('Unable to send slide note: ' + note);
+
+ if (slides.length > slideNumber) {
+ sendNote(slides[slideNumber]);
}
};
}
--- a/php_temp/w3c_talks.php Fri Aug 30 17:29:09 2013 +0900
+++ b/php_temp/w3c_talks.php Fri Aug 30 17:58:48 2013 +0900
@@ -17,15 +17,24 @@
$connection = getConnectionWithAccessToken($consumerkey, $consumersecret, $accesstoken, $accesstokensecret);
-//echo('<pre>');
-//print_r($_POST);
-//echo('</pre>');
+echo('<pre>');
+print_r($_POST);
+echo('</pre>');
+
+/*
+ * POST data will be something like this:
+ [note] => Slidy lets you create accessible slide shows with ease
+ [hashtag] => #testevent
+ [author] => Bob Smith
+ [title] => HTML Slidy
+ [accesskey] => asdfasdfadsfas
+*/
// Check login credentials
//$account = $connection->get('account/verify_credentials');
-if (!empty($_POST['data'])) {
+if (!empty($_POST['note'])) {
// Prepare tweet
- $tweet = stripslashes(trim($_POST['data']));
+ $tweet = stripslashes(trim($_POST['note']).' '.$_POST['hashtag']);
// Post a tweet
$status = $connection->post('statuses/update', array('status' => $tweet));