Permalink
Browse files

Initial Commit

  • Loading branch information...
0 parents commit e969ec3da2128783af9b1ffaad54e3609ac0ae5b @tarnfeld committed Jun 8, 2010
@@ -0,0 +1,106 @@
+<?php
+
+/*
+ Pusher PHP Library
+ /////////////////////////////////
+ This was a very simple PHP library to the Pusher API.
+
+ $pusher = new Pusher(APIKEY, SECRET, APP_ID, CHANNEL, [Debug: true/false, HOST, PORT]);
+ $pusher->trigger('my_event', 'test_channel', [Debug: true/false]);
+ $pusher->socket_auth('socket_id');
+
+ Copyright 2010, Squeeks. Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php
+
+*/
+
+class Pusher
+{
+ private $settings = array();
+
+ public function __construct($auth_key, $secret, $app_id, $channel, $debug = false, $host = 'http://api.pusherapp.com', $port = '80')
+ {
+ // Check for dependent PHP extensions (JSON, cURL)
+ if(!extension_loaded('curl') || !extension_loaded('json'))
+ {
+ die("There is missing dependant extensions - please ensure both cURL and JSON modules are installed");
+ }
+
+ // Check to see if we do support MD5 and SHA256 - older PHP5 setups and locked down hosts may not support the latter.
+ foreach(hash_algos() as $algo)
+ {
+ if($algo == 'sha256') { $has_sha256 = true; }
+ if($algo == 'md5') { $has_md5 = true; }
+ }
+
+ if(!isset($has_sha256) || !isset($has_md5))
+ {
+ die("Either MD5 and SHA256 appears to be unsupported - make sure you have support for it, or upgrade your version of PHP.");
+ }
+
+ // Setup defaults
+ $this->settings['server'] = $host;
+ $this->settings['port'] = $port;
+ $this->settings['auth_key'] = $auth_key;
+ $this->settings['secret'] = $secret;
+ $this->settings['app_id'] = $app_id;
+ $this->settings['channel'] = $channel;
+ $this->settings['url'] = '/apps/'.$this->settings['app_id'].'/channels/'.$this->settings['channel'].'/events';
+ $this->settings['debug'] = $debug;
+
+ }
+
+
+ public function trigger($event, $payload, $debug = false)
+ {
+ if($ch = curl_init())
+ {
+ $time = time();
+ $signature = "POST\n".$this->settings['url']."\n";
+ $query = "auth_key=".$this->settings['auth_key']. "&auth_timestamp=".$time."&auth_version=1.0&body_md5=".md5(json_encode($payload))."&name=".$event;
+ $auth_signature = hash_hmac('sha256', $signature.$query, $this->settings['secret'], false);
+ $signed_query = $query."&auth_signature=".$auth_signature;
+ $full_url = $this->settings['server'].':'.$this->settings['port'].$this->settings['url'].'?'.$signed_query;
+
+ curl_setopt($ch, CURLOPT_URL, $full_url);
+ curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json"));
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
+ curl_setopt($ch, CURLOPT_POST, 1);
+ curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($payload));
+
+ $response = curl_exec($ch);
+
+ curl_close($ch);
+
+ if($response == "202 ACCEPTED\n" && $debug == false)
+ {
+ return true;
+ }
+ elseif($debug == true || $this->settings['debug'] == true)
+ {
+ return $response;
+ }
+ else
+ {
+ return false;
+ }
+
+ }
+ else
+ {
+ die("Could not initialise cURL!");
+ }
+
+ }
+
+
+ public function socket_auth($socket_id)
+ {
+ $signature = hash_hmac('sha256', $this->settings['channel'].':'.$socket_id, $this->settings['secret'], false);
+ $signature = array('auth' => $this->settings['auth_key'].':'.$signature);
+ return json_encode($signature);
+ }
+
+
+}
+
+?>
@@ -0,0 +1,18 @@
+<?php
+
+ require_once('../config.php');
+ require('Pusher.php');
+
+ $message = $_POST['message'];
+ $nickname = $_POST['nickname'];
+ $channel = $_POST['chatChannel'];
+
+ $content = array(
+ "content"=>$message,
+ "nickname"=>$nickname
+ );
+
+ $pusher = new Pusher(PUSHER_API_KEY, PUSHER_API_SECRET, PUSHER_APP_ID, $channel);
+ $pusher->trigger('message', $content);
+
+?>
@@ -0,0 +1,28 @@
+<?php
+
+ session_start();
+ if(isset($_SESSION['chatCode']))
+ {
+ echo("pusherchat-".$_SESSION['chatCode']);
+ unset($_SESSION['chatCode']);
+ }
+ else
+ {
+ $password = "";
+ $possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
+ $length = 15;
+ $i = 0;
+ while ($i < $length) {
+ $char = substr($possible, mt_rand(0, strlen($possible)-1), 1);
+ if (!strstr($password, $char)) {
+ $password .= $char;
+ $i++;
+ }
+
+ }
+ echo("pusherchat-".$password);
+ }
+
+ sleep(1);
+
+?>
@@ -0,0 +1,37 @@
+<?php
+
+ session_start();
+ if($_GET['code']!='')
+ {
+ $_SESSION['chatCode'] = $_GET['code'];
+ }
+
+?>
+<!DOCTYPE html>
+<html>
+ <head>
+ <title>Pusher Chat</title>
+ <link rel="stylesheet" href="css/chat.css">
+ <script type="text/javascript" src="js/jquery-1.4.2.min.js"></script>
+ <script type="text/javascript" src="js/placeholder.js"></script>
+ <script src="http://js.pusherapp.com/1.4/pusher.min.js"></script>
+ <script type="text/javascript" src="js/chat.js"></script>
+ </head>
+ <body>
+ <div id="chatBox">
+ <div id="extras">
+ <input type="text" value="Person" id="nickname" />
+ <a href="#" id="saveNickname">Save</a>
+ <a href="#" id="editNickname"><p>Edit Nickname</p></a>
+ </div>
+ <div id="loading"></div>
+ <ul id="messages">
+ </ul>
+ <textarea disabled="disabled" id="message" placeholder="Type your message here..."></textarea>
+ <div id="shareChatLink">Unique Chat Code: <b id="shareChatLinkID"></b></div>
+ </div>
+ <script src="http://static.getclicky.com/js" type="text/javascript"></script>
+ <script type="text/javascript">clicky.init(119288);</script>
+ <noscript><p><img alt="Clicky" width="1" height="1" src="http://static.getclicky.com/119288ns.gif" /></p></noscript>
+ </body>
+</html>
@@ -0,0 +1,7 @@
+<?php
+
+ // These need to be changed to suit your PusherApp app configuration
+
+ define('PUSHER_API_KEY','KEY HERE');
+ define('PUSHER_API_SECRET','SECRET HERE');
+ define('PUSHER_APP_ID','ID HERE');
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -0,0 +1,118 @@
+body
+{
+ background: #e4e4e4;
+ font-family: "Helvetica Neue";
+ margin: 0;
+ padding: 0;
+}
+*
+{
+ outline: none;
+}
+a
+{
+ text-decoration: none;
+ border: 0;
+}
+a:hover, a:visited:hover
+{
+ color: #cd0606;
+}
+a:visited
+{
+ color: blue;
+}
+#chatBox
+{
+ width: 500px;
+ background: #fff;
+ padding: 0;
+ height: 400px;
+ box-shadow: 0 0 20px #414141;
+ -webkit-box-shadow: 0 0 20px #414141;
+ top: 50%;
+ left: 50%;
+ margin: -200px 0 0 -250px;
+ position: absolute;
+}
+#chatBox #loading
+{
+ width: 16px;
+ height: 16px;
+ background: url(spinner.gif) no-repeat center center;
+ top: 50%;
+ left: 50%;
+ margin: -8px 0 0 -8px;
+ position: absolute;
+}
+#chatBox #extras
+{
+ margin: -50px 0 10px 0;
+ width: 490px;
+ height: 20px;
+}
+#chatBox #extras input
+{
+ display: none;
+ padding: 5px;
+ margin: 10px 0 0 0;
+}
+#chatBox #extras #saveNickname
+{
+ display: none;
+ margin-left: 10px;
+}
+#chatBox #extras #editNickname p
+{
+ margin: 20px 0 0 0;
+ padding: 0;
+}
+#chatBox #messages
+{
+ width: 500px;
+ height: 329px;
+ margin: 0;
+ padding: 0;
+ overflow-y: auto;
+ overflow-x: hidden;
+}
+#chatBox #message
+{
+ margin: 0;
+ padding: 10px;
+ height: 50px;
+ border: none;
+ border-top: 1px #e4e4e4 solid;
+ max-height: 50px;
+ max-width: 479px;
+ min-height: 50px;
+ min-width: 479px;
+ width: 479px;
+}
+#chatBox #message:disabled
+{
+ color: #414141;
+}
+#chatBox #messages li
+{
+ padding: 10px;
+ width: 480px;
+ background: #a7c9ff;
+ border-bottom: 1px #ecebe8 solid;
+ border-top: 1px #bdcae0 solid;
+ font-size: 14px;
+ line-height: 20px;
+}
+#chatBox #messages li.alt
+{
+ background: #f2f5ff;
+ border-top: none;
+}
+#chatBox #shareChatLink
+{
+ margin-top: 10px;
+ font-size: 12px;
+ text-align: center;
+ display: none;
+ color: #414141;
+}
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -0,0 +1,68 @@
+body
+{
+ background: #e4e4e4;
+ font-family: "Helvetica Neue";
+}
+#centerBox
+{
+ box-shadow: 0 0 20px #414141;
+ -webkit-box-shadow: 0 0 20px #414141;
+ width: 400px;
+ height: 210px;
+ background: #fff;
+ top: 50%;
+ left: 50%;
+ margin: -170px 0 0 -220px;
+ position: absolute;
+ padding: 20px;
+}
+#centerBox h2
+{
+ margin: 0 0 10px 0;
+ padding: 0;
+ font-size: 20px;
+}
+#centerBox p
+{
+ margin: 0;
+ padding: 0;
+ font-size: 14px;
+}
+#centerBox a
+{
+ text-decoration: none;
+ border: 0;
+}
+#centerBox a:hover, #centerBox a:visited:hover
+{
+ color: #cd0606;
+}
+#centerBox a:visited
+{
+ color: blue;
+}
+button, input[type=submit], input[type=button] {
+ background: url(button_bg.png) no-repeat top left;
+ border: none;
+ height: 24px;
+ padding: 0 0 2px 0;
+ width: 75px;
+ text-shadow: #264d7d 0px 1px 1px;
+ color: #ffffff;
+ cursor: pointer;
+ margin: 0;
+}
+button:disbled {
+ cursor: default;
+ opacity: 0.5;
+}
+button:hover {background-position-y: -24px; }
+button:active { background-position-y: -48px; }
+button:focus { background-position-y: -48px; }
+input[type=text]
+{
+ padding: 5px;
+ font-weight: bold;
+ width: 200px;
+ margin-right: 10px;
+}
Oops, something went wrong.

0 comments on commit e969ec3

Please sign in to comment.