Commit of first files
authorddavis
Fri, 30 Aug 2013 17:06:25 +0900
changeset 3 5a592cf58189
parent 2 5b1b286a68e8
child 4 be952543f121
Commit of first files
js/w3c_talks.js
php_temp/w3c_talks.php
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/js/w3c_talks.js	Fri Aug 30 17:06:25 2013 +0900
@@ -0,0 +1,90 @@
+(function() {
+    'use strict';
+    
+    // Global variables for tweet posting
+    var url = 'http://www.vodstock.com/w3c_talks/w3c_talks.php';
+    var hashtag = getHashtag();
+    
+    function getHashtag() {
+        var hashmeta = document.querySelector('[name=hashtag]');
+        
+        try {
+            var hashtag = hashmeta.content;
+            hashtag = (hashtag.indexOf('#') < 0) ? '#' + hashtag : hashtag;
+            return hashtag;
+        } catch(e) {
+            console.log('Unable to get hashtag');
+            return '';
+        }
+    }
+
+    // Use XHR to send data to specified URL
+    function doPost(url, data) {
+        var httpRequest;
+        
+        if (window.XMLHttpRequest) { // Modern browsers
+            httpRequest = new XMLHttpRequest();
+        } else if (window.ActiveXObject) { // Old IE
+            try {
+                httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
+            } catch (e) {
+                try {
+                    httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
+                } catch (e) {}
+            }
+        }
+
+        if (!httpRequest) {
+            console.log('Giving up :( Cannot create an XMLHTTP instance');
+            return false;
+        }
+        httpRequest.onreadystatechange = function() {
+            if (httpRequest.readyState === 4) {
+                if (httpRequest.status !== 200) {
+                    console.log('There was a problem with the XHR action.');
+                }
+            }
+        };
+        httpRequest.open('POST', url);
+        httpRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
+        httpRequest.send('data=' + encodeURIComponent(data));
+    }
+    
+    // The following is for Slidy:
+    if (window.w3c_slidy) {
+        // Store original "show_slide" method for later
+        w3c_slidy.__show_slide = w3c_slidy.show_slide;
+        
+        // Hijack "show_slide" method and add action to send note
+        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);
+            }
+        };
+    }
+    
+    // The following is for Shower:
+    if (window.shower) {
+        var slides = document.querySelectorAll('.slide');
+        
+        // Store original "go" method for later
+        shower.__go = shower.go;
+        
+        // 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);
+            }
+        };
+    }
+})();
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/php_temp/w3c_talks.php	Fri Aug 30 17:06:25 2013 +0900
@@ -0,0 +1,41 @@
+<?php
+header("Access-Control-Allow-Origin: *");
+session_start();
+require_once("twitteroauth/twitteroauth/twitteroauth.php"); //Path to twitteroauth library
+ 
+$twitteruser = "w3c_talks";
+$notweets = 30;
+$consumerkey = "hxg6thsXDcNByjBKwGtvdg";
+$consumersecret = "gJcfbddJPMydmvpaSP3qO283rI257ZtmlbghWjpmB28";
+$accesstoken = "1576718557-2MxPtS8fQsAiyvn1AvgLxY9hHM5ogTu6bhYE4vJ";
+$accesstokensecret = "kWNcGpnPfy0SFdMjhAchT0n3xP7EB3ieJCRvnaBpHwc";
+ 
+function getConnectionWithAccessToken($cons_key, $cons_secret, $oauth_token, $oauth_token_secret) {
+    $connection = new TwitterOAuth($cons_key, $cons_secret, $oauth_token, $oauth_token_secret);
+    return $connection;
+}
+ 
+$connection = getConnectionWithAccessToken($consumerkey, $consumersecret, $accesstoken, $accesstokensecret);
+
+//echo('<pre>');
+//print_r($_POST);
+//echo('</pre>');
+
+// Check login credentials
+//$account = $connection->get('account/verify_credentials');
+if (!empty($_POST['data'])) {
+    // Prepare tweet
+    $tweet = stripslashes(trim($_POST['data']));
+    
+    // Post a tweet
+    $status = $connection->post('statuses/update', array('status' => $tweet));
+
+    // Delete a tweet
+    //$status = $connection->delete('statuses/destroy/12345');
+
+    // Get the user's latest tweets
+    //$tweets = $connection->get("https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=".$twitteruser."&count=".$notweets);
+    //echo json_encode($tweets);
+}
+
+?>
\ No newline at end of file