Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

moving repo

  • Loading branch information...
commit ebc561a2fc02d181d8759304f65dd2ed84d2daaf 1 parent cafcb2d
geremy authored
Showing with 2 additions and 3,592 deletions.
  1. +0 −239 php/3.1/Pubnub.php
  2. +0 −8 php/3.1/examples/README
  3. +0 −52 php/3.1/examples/benchmark.php
  4. +0 −68 php/3.1/examples/chat-command-line.php
  5. +0 −38 php/3.1/examples/chat-subscribe-helper.php
  6. +0 −38 php/3.1/examples/history-example.php
  7. +0 −51 php/3.1/examples/performance-test.php
  8. +0 −4 php/3.1/examples/php-push-api-walkthrough-javascript-publish.js
  9. +0 −7 php/3.1/examples/php-push-api-walkthrough-javascript-subscribe.js
  10. +0 −9 php/3.1/examples/php-push-api-walkthrough-php-publish.php
  11. +0 −12 php/3.1/examples/php-push-api-walkthrough-php-subscribe.php
  12. +0 −45 php/3.1/examples/publish-example.php
  13. +0 −47 php/3.1/examples/socket.io-example.php
  14. +0 −44 php/3.1/examples/subscribe-example.php
  15. +0 −157 php/3.1/unit-test.php
  16. +0 −563 php/3.3/Pubnub.php
  17. +0 −94 php/3.3/PubnubAES.php
  18. +0 −211 php/3.3/PubnubTest.php
  19. +0 −32 php/3.3/exitSubOnFalse.php
  20. +0 −13 php/3.3/here_now_example.php
  21. +0 −14 php/3.3/presenceTest.php
  22. +0 −32 php/3.3/pubnub.com.pem
  23. +0 −176 php/3.3/pubnubCipherTextTests.php
  24. +0 −130 php/3.3/pubnubPlaintextTests.php
  25. +0 −13 php/3.3/subscribeTest.php
  26. +0 −563 php/3.4/Pubnub.php
  27. +0 −94 php/3.4/PubnubAES.php
  28. +0 −211 php/3.4/PubnubTest.php
  29. +0 −32 php/3.4/exitSubOnFalse.php
  30. +0 −13 php/3.4/here_now_example.php
  31. +0 −68 php/3.4/noise.php
  32. +0 −51 php/3.4/ping.php
  33. +0 −14 php/3.4/presenceTest.php
  34. +0 −32 php/3.4/pubnub.com.pem
  35. +0 −176 php/3.4/pubnubCipherTextTests.php
  36. +0 −130 php/3.4/pubnubPlaintextTests.php
  37. +0 −13 php/3.4/subscribeTest.php
  38. +2 −98 php/README.md
View
239 php/3.1/Pubnub.php
@@ -1,239 +0,0 @@
-<?php
-
-/**
- * PubNub 3.0 Real-time Push Cloud API
- *
- * @author Stephen Blum
- * @package Pubnub
- */
-class Pubnub {
- private $ORIGIN = 'pubsub.pubnub.com';
- private $PUBLISH_KEY = 'demo';
- private $SUBSCRIBE_KEY = 'demo';
- private $SECRET_KEY = false;
- private $SSL = false;
-
- /**
- * Pubnub
- *
- * Init the Pubnub Client API
- *
- * @param string $publish_key required key to send messages.
- * @param string $subscribe_key required key to receive messages.
- * @param string $secret_key optional key to sign messages.
- * @param string $origin optional setting for cloud origin.
- * @param boolean $ssl required for 2048 bit encrypted messages.
- */
- function Pubnub(
- $publish_key = 'demo',
- $subscribe_key = 'demo',
- $secret_key = false,
- $ssl = false,
- $origin = false
- ) {
- $this->PUBLISH_KEY = $publish_key;
- $this->SUBSCRIBE_KEY = $subscribe_key;
- $this->SECRET_KEY = $secret_key;
- $this->SSL = $ssl;
-
- if ($origin) $this->ORIGIN = $origin;
-
- if ($ssl) $this->ORIGIN = 'https://' . $this->ORIGIN;
- else $this->ORIGIN = 'http://' . $this->ORIGIN;
- }
-
- /**
- * Publish
- *
- * Send a message to a channel.
- *
- * @param array $args with channel and message.
- * @return array success information.
- */
- function publish($args) {
- ## Fail if bad input.
- if (!($args['channel'] && $args['message'])) {
- echo('Missing Channel or Message');
- return false;
- }
-
- ## Capture User Input
- $channel = $args['channel'];
- $message = json_encode($args['message']);
-
- ## Generate String to Sign
- $string_to_sign = implode( '/', array(
- $this->PUBLISH_KEY,
- $this->SUBSCRIBE_KEY,
- $this->SECRET_KEY,
- $channel,
- $message
- ) );
-
- ## Sign Message
- $signature = $this->SECRET_KEY ? md5($string_to_sign) : '0';
-
- ## Send Message
- return $this->_request(array(
- 'publish',
- $this->PUBLISH_KEY,
- $this->SUBSCRIBE_KEY,
- $signature,
- $channel,
- '0',
- $message
- ));
- }
-
- /**
- * Subscribe
- *
- * This is BLOCKING.
- * Listen for a message on a channel.
- *
- * @param array $args with channel and message.
- * @return mixed false on fail, array on success.
- */
- function subscribe($args) {
- ## Capture User Input
- $channel = $args['channel'];
- $callback = $args['callback'];
- $timetoken = isset($args['timetoken']) ? $args['timetoken'] : '0';
-
- ## Fail if missing channel
- if (!$channel) {
- echo("Missing Channel.\n");
- return false;
- }
-
- ## Fail if missing callback
- if (!$callback) {
- echo("Missing Callback.\n");
- return false;
- }
-
- ## Begin Recusive Subscribe
- try {
- ## Wait for Message
- $response = $this->_request(array(
- 'subscribe',
- $this->SUBSCRIBE_KEY,
- $channel,
- '0',
- $timetoken
- ));
-
- $messages = $response[0];
- $args['timetoken'] = $response[1];
-
- ## If it was a timeout
- if (!count($messages)) {
- return $this->subscribe($args);
- }
-
- ## Run user Callback and Reconnect if user permits.
- foreach ($messages as $message) {
- if (!$callback($message)) return;
- }
-
- ## Keep Listening.
- return $this->subscribe($args);
- }
- catch (Exception $error) {
- sleep(1);
- return $this->subscribe($args);
- }
- }
-
- /**
- * History
- *
- * Load history from a channel.
- *
- * @param array $args with 'channel' and 'limit'.
- * @return mixed false on fail, array on success.
- */
- function history($args) {
- ## Capture User Input
- $limit = +$args['limit'] ? +$args['limit'] : 10;
- $channel = $args['channel'];
-
- ## Fail if bad input.
- if (!$channel) {
- echo('Missing Channel');
- return false;
- }
-
- ## Get History
- return $this->_request(array(
- 'history',
- $this->SUBSCRIBE_KEY,
- $channel,
- '0',
- $limit
- ));
- }
-
- /**
- * Time
- *
- * Timestamp from PubNub Cloud.
- *
- * @return int timestamp.
- */
- function time() {
- ## Get History
- $response = $this->_request(array(
- 'time',
- '0'
- ));
-
- return $response[0];
- }
-
- /**
- * Request URL
- *
- * @param array $request of url directories.
- * @return array from JSON response.
- */
- private function _request($request) {
- $request = array_map( 'Pubnub::_encode', $request );
- array_unshift( $request, $this->ORIGIN );
-
- $ctx = stream_context_create(array(
- 'http' => array( 'timeout' => 200 )
- ));
-
- return json_decode( @file_get_contents(
- implode( '/', $request ), 0, $ctx
- ), true );
- }
-
- /**
- * Encode
- *
- * @param string $part of url directories.
- * @return string encoded string.
- */
- private static function _encode($part) {
- return implode( '', array_map(
- 'Pubnub::_encode_char', str_split($part)
- ) );
- }
-
- /**
- * Encode Char
- *
- * @param string $char val.
- * @return string encoded char.
- */
- private static function _encode_char($char) {
- if (strpos( ' ~`!@#$%^&*()+=[]\\{}|;\':",./<>?', $char ) === false)
- return $char;
- return rawurlencode($char);
- }
-}
-
-
-?>
View
8 php/3.1/examples/README
@@ -1,8 +0,0 @@
-www.pubnub.com - pubnub - realtime push service in the cloud
-
-To start the PHP Chat Client:
------------------------------
- php ./chat-command-line.php PUBLISH-KEY SUBSCRIBE-KEY
-
-Review code in each file to see examples of the PHP Pubnub Client API.
-Publish, Subscribe and History functions are available in the Pubnub PHP Class.
View
52 php/3.1/examples/benchmark.php
@@ -1,52 +0,0 @@
-<?php
-
- ## Capture Publish and Subscribe Keys from Command Line
- $publish_key = "demo";
- $subscribe_key = "demo";
- $channel_name = "while-loop-channel";
-
- ## Require Pubnub API
- echo("Loading Pubnub.php Class\n");
- require('../Pubnub.php');
-
- ## -----------------------------------------
- ## Create Pubnub Client API (INITIALIZATION)
- ## -----------------------------------------
- echo("Creating new Pubnub Client API\n");
- $pubnub = new Pubnub(
- $publish_key,
- $subscribe_key,
- '',
- false,
- 'pubsub.pubnub.com'
- );
-
- ## ----------------------
- ## Send Message (PUBLISH)
- ## ----------------------
- echo("Sending a message with Publish Function\n");
-
- $start = microtime(1);
- $tries = 100.0;
- $i = 0;
- $message = json_decode('{"id":"130051906964946945","type":"newtopic","created_at":"Fri Oct 28 22:42:45 +0000 2011","current_time":1319841837,"posted_at":1319841837,"reply_count":0,"from_user":"WeDemo","from_user_name":"Demo","profile_image_url":"http:\/\/a1.twimg.com\/profile_images\/1568426943\/Screen_shot_2011-10-01_at_1.40.42_PM_normal.png","tweettext":"#uynb5598 ggttrru <a href=\"http:\/\/t.co\/QkKBpjRS\" rel=\"nofollow\" target=\"_blank\">http:\/\/t.co\/QkKBpjRS<\/a>","bubble_color":"","product_shorturl":null,"product_longurl":null,"media_type":"YFrog","message_video_url":null,"message_image_id":"21067","message_o_image_url":"http:\/\/c797842.r42.cf2.rackcdn.com\/TIKZuz.jpg","message_l_image_url":"http:\/\/c797844.r44.cf2.rackcdn.com\/TIKZuz.jpg","message_t_image_url":"http:\/\/c797843.r43.cf2.rackcdn.com\/TIKZuz.jpg","message_f_image_url":null,"message_tvt_image_url":null,"message_tvl_image_url":null}');#array( 'text' => $message );
-
- while ($i++ < $tries) {
- $pubnub->publish(array(
- 'channel' => $channel_name,
- 'message' => $message
- ));
- }
-
- ## DONE
- $end = microtime(1);
- print_r(array(
- 'total publishes sent' => $tries,
- 'start' => $start,
- 'end' => $end,
- 'total test duration in seconds' => $end - $start,
- 'average delivery in seconds' => ($end - $start) / $tries,
- 'publishes per second' => $tries / ($end - $start)
- ));
-
-?>
View
68 php/3.1/examples/chat-command-line.php
@@ -1,68 +0,0 @@
-<?php
-
- ## Capture Publish and Subscribe Keys from Command Line
- $publish_key = isset($argv[1]) ? $argv[1] : false;
- $subscribe_key = isset($argv[2]) ? $argv[2] : false;
-
- # Print usage if missing info.
- if (!($publish_key && $subscribe_key)) {
-echo("
- ==============
- EXAMPLE USAGE:
- ==============
- php ./chat-command-line.php PUBLISH-KEY SUBSCRIBE-KEY
-
-");
- exit();
- }
-
- ## Require Pubnub API
- echo("Connecting...\n");
- echo("(Press ^C to exit)\n");
- require('../Pubnub.php');
-
- ## -----------------------------------------
- ## Create Pubnub Client API (INITIALIZATION)
- ## -----------------------------------------
- $pubnub = new Pubnub( $publish_key, $subscribe_key );
-
- ## ----------------------------------------
- ## Send/Recieve Message (PUBLISH/SUBSCRIBE)
- ## ----------------------------------------
- $pid = pcntl_fork();
-
- if ($pid == -1) {
-
- ## Fail :'(
- die('Could not fork. Get newer version of PHP!');
-
- } else if ($pid) {
-
- ## Get Username
- echo("ENTER USERNAME: ");
- $user = trim(fgets(STDIN));
- $user = $user ? $user : 'chad';
- echo("YOUR NAME IS $user\n\n");
-
- ## Listen for Messages From User
- while (true) {
- $text = trim(fgets(STDIN));
- $pubnub->publish(array(
- 'channel' => 'php_chat',
- 'message' => array(
- 'text' => $text,
- 'from' => $user
- )
- ));
- }
-
- ## Protect against Zombie children
- pcntl_wait($status);
-
- }
- else {
- ## Launch Subscriber
- system("php ./chat-subscribe-helper.php $publish_key $subscribe_key");
- }
-
-?>
View
38 php/3.1/examples/chat-subscribe-helper.php
@@ -1,38 +0,0 @@
-<?php
-
- ## Capture Publish and Subscribe Keys from Command Line
- $publish_key = isset($argv[1]) ? $argv[1] : false;
- $subscribe_key = isset($argv[2]) ? $argv[2] : false;
-
- ## Require Pubnub API
- require('../Pubnub.php');
-
- ## -----------------------------------------
- ## Create Pubnub Client API (INITIALIZATION)
- ## -----------------------------------------
- $pubnub = new Pubnub( $publish_key, $subscribe_key );
-
- ## ----------------------
- ## Send Message (PUBLISH)
- ## ----------------------
- $pubnub->subscribe(array(
- 'channel' => 'php_chat', ## REQUIRED Channel to Listen
- 'callback' => function($message) { ## REQUIRED Callback With Response
- ## Print Message
- echo(
- "[" .
- date('H:i:s') .
- "] <" .
- $message['from'] .
- "> " .
- $message['text'] .
- "\r\n"
- );
-
- ## Keep listening (return false to stop)
- return true;
- }
- ));
-
-?>
-
View
38 php/3.1/examples/history-example.php
@@ -1,38 +0,0 @@
-<?php
-
- ## Capture Publish and Subscribe Keys from Command Line
- $publish_key = isset($argv[1]) ? $argv[1] : false;
- $subscribe_key = isset($argv[2]) ? $argv[2] : false;
-
- # Print usage if missing info.
- if (!($publish_key && $subscribe_key)) {
-echo("
- ==============
- EXAMPLE USAGE:
- ==============
- php ./publish-example.php PUBLISH-KEY SUBSCRIBE-KEY
-
-");
- exit();
- }
-
- ## Require Pubnub API
- echo("Loading Pubnub.php Class\n");
- require('../Pubnub.php');
-
- ## -----------------------------------------
- ## Create Pubnub Client API (INITIALIZATION)
- ## -----------------------------------------
- echo("Creating new Pubnub Client API\n");
- $pubnub = new Pubnub( $publish_key, $subscribe_key );
-
- ## Get History
- echo("Requesting History...\n");
- $messages = $pubnub->history(array(
- 'channel' => 'hello_world', ## REQUIRED Channel to Send
- 'limit' => 100 ## OPTIONAL Limit Number of Messages
- ));
- var_dump($messages); ## Prints Published Messages.
-
-?>
-
View
51 php/3.1/examples/performance-test.php
@@ -1,51 +0,0 @@
-<?php
- ## Require Pubnub API
- echo("Loading Pubnub.php Class\n");
- require('../Pubnub.php');
-
- ## -----------------------------------------
- ## Create Pubnub Client API (INITIALIZATION)
- ## -----------------------------------------
- echo("Creating new Pubnub Client API\n");
- $pubnub = new Pubnub();
-
- ## ----------------------
- ## Send Message (PUBLISH)
- ## ----------------------
- echo("Sending a message with Publish Function\n");
-
- $start = microtime(1);
- $tries = 50.0;
- $success = 0;
- $failes = 0;
- $sent = 0;
-
- while ($sent++ < $tries) {
- $info = $pubnub->publish(array(
- 'channel' => 'performance-test',
- 'message' => 'hi'
- ));
-
- $info[0] && $success++;
- $info[0] || $failes++;
-
- $sent % (int)($tries/50) || print('.');
- }
-
- ## DONE
- $end = microtime(1);
- print("\n");
- print_r(array(
- 'total successful publishes' => $success,
- 'total failed publishes' => $failes,
- 'total sequential publishes sent' => $tries,
- 'successful delivery rate' => '%' . ($success / $tries * 100),
- 'failure delivery rate' => '%' . ($failes / $tries * 100),
- 'total test duration in seconds' => $end - $start,
- 'average delivery in seconds' => ($end - $start) / $tries,
- 'publishes per second' => $tries / ($end - $start),
- 'start' => $start,
- 'end' => $end
- ));
-
-?>
View
4 php/3.1/examples/php-push-api-walkthrough-javascript-publish.js
@@ -1,4 +0,0 @@
-PUBNUB.publish({
- channel : 'extra_cool_channel',
- message : { 'some_var' : 'what up?' }
-});
View
7 php/3.1/examples/php-push-api-walkthrough-javascript-subscribe.js
@@ -1,7 +0,0 @@
-PUBNUB.subscribe( { channel : 'my_test_channel' },
-function(message) {
- if ('some_text' in message) {
- alert(message.some_text);
- }
-} );
-
View
9 php/3.1/examples/php-push-api-walkthrough-php-publish.php
@@ -1,9 +0,0 @@
-<?php
- require('../Pubnub.php');
-
- $pubnub = new Pubnub( 'demo', 'demo' );
- $pubnub->publish(array(
- 'channel' => 'my_test_channel',
- 'message' => array( 'some_text' => 'hello!' )
- ));
-?>
View
12 php/3.1/examples/php-push-api-walkthrough-php-subscribe.php
@@ -1,12 +0,0 @@
-<?php
- require('../Pubnub.php');
-
- $pubnub = new Pubnub( 'demo', 'demo' );
- $pubnub->subscribe(array(
- 'channel' => 'extra_cool_channel',
- 'callback' => function($message) {
- var_dump($message);
- return true; ## continue listening
- }
- ));
-?>
View
45 php/3.1/examples/publish-example.php
@@ -1,45 +0,0 @@
-<?php
-
- ## Capture Publish and Subscribe Keys from Command Line
- $publish_key = isset($argv[1]) ? $argv[1] : false;
- $subscribe_key = isset($argv[2]) ? $argv[2] : false;
- $message = isset($argv[3]) ? $argv[3] : false;
- $channel_name = isset($argv[4]) ? $argv[4] : 'hello_world2';
-
- ## Print usage if missing info.
- if (!($publish_key && $subscribe_key && $message)) {
-echo("
- ==============
- EXAMPLE USAGE:
- ==============
- php ./publish-example.php PUBLISH-KEY SUBSCRIBE-KEY 'ANY MESSAGE HERE' 'CHANNEL_NAME'
- php ./publish-example.php demo demo 'Hey what is up?' 'hello_world_channel'
-
-");
- exit();
- }
-
- ## Require Pubnub API
- echo("Loading Pubnub.php Class\n");
- require('../Pubnub.php');
-
- ## -----------------------------------------
- ## Create Pubnub Client API (INITIALIZATION)
- ## -----------------------------------------
- echo("Creating new Pubnub Client API\n");
- $pubnub = new Pubnub( $publish_key, $subscribe_key );
-
- ## ----------------------
- ## Send Message (PUBLISH)
- ## ----------------------
- echo("Sending a message with Publish Function\n");
- $message = array( 'text' => $message );
- $info = $pubnub->publish(array(
- 'channel' => $channel_name,
- 'message' => $message
- ));
-
- echo("Response:\n");
- print_r(array( 'published' => $message/*, 'success' => $info*/ ));
-
-?>
View
47 php/3.1/examples/socket.io-example.php
@@ -1,47 +0,0 @@
-<?php
-
- //
- // Socket.IO JavaScript Example Code
- //
- /*
- var pubnub_setup = {
- channel : 'PUBNUB_CHANNEL_HERE',
- publish_key : 'demo',
- subscribe_key : 'demo',
- ssl : false
- };
-
- var socket = io.connect( 'http://pubsub.pubnub.com/THREAD_123', pubnub_setup );
-
- socket.on( 'EVENT', function(data) {
- console.log(data);
- } );
- */
-
- //
- // Send Data to Socket.IO from PHP
- //
- require('../Pubnub.php');
-
- ## -----------------------------------------
- ## Create Pubnub Client API (INITIALIZATION)
- ## -----------------------------------------
- $publish_key = 'demo';
- $subscribe_key = 'demo';
- $pubnub = new Pubnub( $publish_key, $subscribe_key );
-
- ## ----------------------
- ## Send Message (PUBLISH)
- ## ----------------------
- $info = $pubnub->publish(array(
- 'channel' => 'PUBNUB_CHANNEL_HERE',
- 'message' => array(
- 'name' => 'EVENT', ## emit( 'event-name', ... )
- 'ns' => 'THREAD_123', ## chat, news, feed, etc.
- 'data' => {'msg':'Hi'} ## object to be received.
- )
- ));
-
- print_r($info);
-
-?>
View
44 php/3.1/examples/subscribe-example.php
@@ -1,44 +0,0 @@
-<?php
-
- ## Capture Publish and Subscribe Keys from Command Line
- $publish_key = isset($argv[1]) ? $argv[1] : false;
- $subscribe_key = isset($argv[2]) ? $argv[2] : false;
- $channel_name = isset($argv[3]) ? $argv[3] : 'hello_world2';
-
- # Print usage if missing info.
- if (!($publish_key && $subscribe_key)) {
-echo("
- ==============
- EXAMPLE USAGE:
- ==============
- php ./subscribe-example.php PUBLISH-KEY SUBSCRIBE-KEY
-
-");
- exit();
- }
-
- ## Require Pubnub API
- echo("Loading Pubnub.php Class\n");
- require('../Pubnub.php');
-
- ## -----------------------------------------
- ## Create Pubnub Client API (INITIALIZATION)
- ## -----------------------------------------
- echo("Creating new Pubnub Client API\n");
- $pubnub = new Pubnub( $publish_key, $subscribe_key );
-
- ## ------------------------------
- ## Listen for Message (SUBSCRIBE)
- ## ------------------------------
- echo("Listening for Messages (Press ^C to stop)\n");
- $pubnub->subscribe(array(
- 'channel' => $channel_name, ## REQUIRED Channel to Listen
- 'callback' => function($message) { ## REQUIRED Callback With Response
- var_dump($message); ## Print Message
- usleep(100);
- return true; ## Keep listening (return false to stop)
- }
- ));
-
-?>
-
View
157 php/3.1/unit-test.php
@@ -1,157 +0,0 @@
-<?php
-
-require_once('Pubnub.php');
-
-## ---------------------------------------------------------------------------
-## USAGE:
-## ---------------------------------------------------------------------------
-#
-# php ./unit-test.php
-# php ./unit-test.php [PUB-KEY] [SUB-KEY] [SECRET-KEY] [USE SSL]
-#
-
-
-## Capture Publish and Subscribe Keys from Command Line
-$publish_key = isset($argv[1]) ? $argv[1] : 'demo';
-$subscribe_key = isset($argv[2]) ? $argv[2] : 'demo';
-$secret_key = isset($argv[3]) ? $argv[3] : false;
-$ssl_on = isset($argv[4]);
-
-## ---------------------------------------------------------------------------
-## Create Pubnub Object
-## ---------------------------------------------------------------------------
-$pubnub = new Pubnub( $publish_key, $subscribe_key, $secret_key, $ssl_on );
-
-## ---------------------------------------------------------------------------
-## Generate Random Channel Name
-## ---------------------------------------------------------------------------
-$channel = 'unit-test-' . rand( 0, 100000000 ) . rand( 0, 100000000 );
-
-
-## ---------------------------------------------------------------------------
-## Get History Part 1
-## ---------------------------------------------------------------------------
-$history = $pubnub->history(array(
- 'channel' => $channel,
- 'limit' => 1
-));
-test( count($history), 0, 'Initial Empty History' );
-
-
-## ---------------------------------------------------------------------------
-## PUBLISH
-## ---------------------------------------------------------------------------
-$pubish_success = $pubnub->publish(array(
- 'channel' => $channel,
- 'message' => 'Hi. (顶顅Ȓ)'
-));
-test( $pubish_success[0], 1, 'Publish First Message' );
-
-
-## ---------------------------------------------------------------------------
-## Get History Part 2
-## ---------------------------------------------------------------------------
-$history = $pubnub->history(array(
- 'channel' => $channel,
- 'limit' => 1
-));
-test( count($history), 1, 'History With 1 Item' );
-test( $history[0], 'Hi. (顶顅Ȓ)', 'History Message Text == "Hi. (顶顅Ȓ)"' );
-
-
-## ---------------------------------------------------------------------------
-## PUBLISH 2
-## ---------------------------------------------------------------------------
-$pubish_success = $pubnub->publish(array(
- 'channel' => $channel,
- 'message' => 'Hi Again.'
-));
-test( $pubish_success[0], 1, 'Publish Second Message' );
-
-
-## ---------------------------------------------------------------------------
-## Get History Part 3
-## ---------------------------------------------------------------------------
-$history = $pubnub->history(array(
- 'channel' => $channel,
- 'limit' => 1
-));
-test( count($history), 1, 'History With 2 Items Limit 1' );
-test( $history[0], 'Hi Again.', 'History Message is Text == "Hi Again."' );
-
-$history = $pubnub->history(array(
- 'channel' => $channel,
- 'limit' => 2
-));
-test( count($history), 2, 'History With 2 Item Limit 2' );
-test( $history[0], 'Hi. (顶顅Ȓ)', 'History Message Text == "Hi. (顶顅Ȓ)"' );
-test( $history[1], 'Hi Again.', 'History Message is Text == "Hi Again."' );
-
-## ---------------------------------------------------------------------------
-## Test Timestamp API
-## ---------------------------------------------------------------------------
-$timestamp = $pubnub->time();
-test( $timestamp, true, 'Timestamp API Test: ' . $timestamp );
-
-
-## ---------------------------------------------------------------------------
-## PUBLISH Special Characters
-## ---------------------------------------------------------------------------
-$craziness = 'crazy -> ~!@#$%^&*()_+`-=\\][{}\'";:,./<>?顶頴ģŃՃ';
-$pubish_success = $pubnub->publish(array(
- 'channel' => $craziness,
- 'message' => $craziness
-));
-test( $pubish_success[0], 1, 'Publish Crazy Channel/Message' );
-
-$history = $pubnub->history(array(
- 'channel' => $craziness,
- 'limit' => 1
-));
-test( count($history), 1, 'History With 3 Items Limit 1' );
-test( $history[0], $craziness, 'History Message is Crazy' );
-
-
-## ---------------------------------------------------------------------------
-## Test Subscribe
-## ---------------------------------------------------------------------------
-$message = 1234;
-
-## Generate String to Sign
-$string_to_sign = implode( '/', array(
- $publish_key,
- $subscribe_key,
- $secret_key,
- $channel,
- $message
-) );
-$signature = $secret_key ? md5($string_to_sign) : '0';
-$pubsub_url_test = "http://pubsub.pubnub.com/publish/" .
- $publish_key . "/" .
- $subscribe_key . "/" .
- $signature . "/" .
- $channel . "/0/" . $message;
-
-echo("\nHIT THIS URL to CONTINUE -> $pubsub_url_test");
-echo("\n\nHit CTRL+C to finish.");
-echo("\nYou may continue reloading the URL to keep testing.\n\n");
-$pubnub->subscribe(array(
- 'channel' => $channel,
- 'callback' => function($message) {
- test( $message, 1234, 'Subscribe: ' . $message );
- return true;
- }
-));
-
-
-
-## ---------------------------------------------------------------------------
-## Unit Test Function
-## ---------------------------------------------------------------------------
-function test( $val1, $val2, $name ) {
- if ($val1 == $val2) echo('PASS: ');
- else echo('FAIL: ');
- echo("$name\n");
-}
-?>
-
View
563 php/3.3/Pubnub.php
@@ -1,563 +0,0 @@
-<?php
-require_once('PubnubAES.php');
-
-/**
- * PubNub 3.4 Real-time Push Cloud API
- * @package Pubnub
- */
-class Pubnub
-{
- private $ORIGIN = 'PHP.pubnub.com'; // Change this to your custom origin, or IUNDERSTAND.pubnub.com
- private $PUBLISH_KEY = 'demo';
- private $SUBSCRIBE_KEY = 'demo';
- private $SECRET_KEY = false;
- private $CIPHER_KEY = '';
- private $SSL = false;
- private $SESSION_UUID = '';
-
- // New style response contains channel after timetoken
- // Old style response does not
-
- private $NEW_STYLE_RESPONSE = true;
- private $PEM_PATH = __DIR__;
-
- /**
- * Pubnub
- *
- * Init the Pubnub Client API
- *
- * @param string $publish_key required key to send messages.
- * @param string $subscribe_key required key to receive messages.
- * @param string $secret_key optional key to sign messages.
- * @param string $origin optional setting for cloud origin.
- * @param boolean $ssl required for 2048 bit encrypted messages.
- */
-
-
- function Pubnub(
- $publish_key = 'demo',
- $subscribe_key = 'demo',
- $secret_key = false,
- $cipher_key = false,
- $ssl = false,
- $origin = false,
- $pem_path = false
- )
- {
-
- $this->SESSION_UUID = $this->uuid();
-
- $this->PUBLISH_KEY = $publish_key;
- $this->SUBSCRIBE_KEY = $subscribe_key;
- $this->SECRET_KEY = $secret_key;
-
- if (!isBlank($cipher_key)) {
- $this->CIPHER_KEY = $cipher_key;
- }
-
- $this->SSL = $ssl;
-
- if ($pem_path != false)
- $this->PEM_PATH = $pem_path;
-
- if ($origin)
- $this->ORIGIN = $origin;
-
- if ($this->ORIGIN == "PHP.pubnub.com") {
- trigger_error("Before running in production, please contact support@pubnub.com for your custom origin.\nPlease set the origin from PHP.pubnub.com to IUNDERSTAND.pubnub.com to remove this warning.\n", E_USER_NOTICE);
- }
-
-
- if ($ssl)
- $this->ORIGIN = 'https://' . $this->ORIGIN;
- else
- $this->ORIGIN = 'http://' . $this->ORIGIN;
- }
-
-
- /**
- * Publish
- *
- * Send a message to a channel.
- *
- * @param array $args with channel and message.
- * @return array success information.
- */
-
- function publish($args)
- {
- ## Fail if bad input.
- if (!(isset($args['channel']) && isset($args['message']))) {
- echo('Missing Channel or Message');
- return false;
- }
-
- ## Capture User Input
- $channel = $args['channel'];
- $message_org = $args['message'];
-
- $message = $this->sendMessage($message_org);
-
-
- ## Sign Message
- $signature = "0";
- if ($this->SECRET_KEY) {
- ## Generate String to Sign
- $string_to_sign = implode('/', array(
- $this->PUBLISH_KEY,
- $this->SUBSCRIBE_KEY,
- $this->SECRET_KEY,
- $channel,
- $message
- ));
-
- $signature = md5($string_to_sign);
- }
-
- ## Send Message
- $publishResponse = $this->_request(array(
- 'publish',
- $this->PUBLISH_KEY,
- $this->SUBSCRIBE_KEY,
- $signature,
- $channel,
- '0',
- $message
- ));
-
- if ($publishResponse == null)
- return array(0, "Error during publish.");
- else
- return $publishResponse;
-
- }
-
- public function sendMessage($message_org)
-
- {
- if ($this->CIPHER_KEY != false) {
- $message = json_encode(encrypt(json_encode($message_org), $this->CIPHER_KEY));
- } else {
- $message = json_encode($message_org);
- }
- return $message;
- }
-
- function here_now($args)
- {
- if (!($args['channel'])) {
- echo('Missing Channel');
- return false;
- }
-
- ## Capture User Input
- $channel = $args['channel'];
-
- return $this->_request(array(
- 'v2',
- 'presence',
- 'sub_key',
- $this->SUBSCRIBE_KEY,
- 'channel',
- $channel
- ));
- }
-
- /**
- * Subscribe
- *
- * This is BLOCKING.
- * Listen for a message on a channel.
- *
- * @param array $args with channel and message.
- * @return mixed false on fail, array on success.
- */
- function subscribe($args, $presence = false)
- {
- ## Capture User Input
- $channel = $args['channel'];
- $callback = $args['callback'];
- $timetoken = isset($args['timetoken']) ? $args['timetoken'] : '0';
-
- ## Fail if missing channel
- if (!$channel) {
- echo("Missing Channel.\n");
- return false;
- }
-
- ## Fail if missing callback
- if (!$callback) {
- echo("Missing Callback.\n");
- return false;
- }
-
- if ($presence == true) {
- $mode = "presence";
- } else
- $mode = "default";
-
-
- while (1) {
-
- try {
- ## Wait for Message
- $response = $this->_request(array(
- 'subscribe',
- $this->SUBSCRIBE_KEY,
- $channel,
- '0',
- $timetoken
- ));
-
- if ($response == "_PUBNUB_TIMEOUT") {
- continue;
- } elseif ($response == "_PUBNUB_MESSAGE_TOO_LARGE") {
- $timetoken = $this->throwAndResetTimetoken($callback, "Message Too Large");
- continue;
- } elseif ($response == null || $timetoken == null) {
- $timetoken = $this->throwAndResetTimetoken($callback, "Bad server response.");
- continue;
- }
-
- $messages = $response[0];
- $timetoken = $response[1];
-
- // determine the channel
-
- if ((count($response) == 3)) {
- $derivedChannel = explode(",", $response[2]);
- } else {
- $channel_array = array();
- for ($a = 0; $a < sizeof($messages); $a++) {
- array_push($channel_array, $channel);
- }
- $derivedChannel = $channel_array;
- }
-
-
- if (!count($messages)) {
- continue;
- }
-
- $receivedMessages = $this->decodeAndDecrypt($messages, $mode);
-
-
- $returnArray = $this->NEW_STYLE_RESPONSE ? array($receivedMessages, $derivedChannel, $timetoken) : array($receivedMessages, $timetoken);
-
- # Call once for each message for each channel
-
- $exit_now = false;
- for ($i = 0; $i < sizeof($receivedMessages); $i++) {
-
- $cbReturn = $callback(array("message" => $returnArray[0][$i], "channel" => $returnArray[1][$i], "timetoken" => $returnArray[2]));
-
- if ($cbReturn == false) {
- $exit_now = true;
- }
-
- }
-
- if ($exit_now) {
- return;
- }
-
-
- } catch (Exception $error) {
- $this->handleError($error, $args);
- $timetoken = $this->throwAndResetTimetoken($callback, "Unknown error.");
- continue;
-
- }
- }
- }
-
- public function throwAndResetTimetoken($callback, $errorMessage)
- {
- $callback(array(0, $errorMessage));
- $timetoken = "0";
- return $timetoken;
- }
-
- public function decodeAndDecrypt($messages, $mode = "default")
- {
- $receivedMessages = array();
-
- if ($mode == "presence") {
- return $messages;
-
- } elseif ($mode == "default") {
- $messageArray = $messages;
- $receivedMessages = $this->decodeDecryptLoop($messageArray);
-
- } elseif ($mode == "detailedHistory") {
-
- $decodedMessages = $this->decodeDecryptLoop($messages);
- $receivedMessages = array($decodedMessages[0], $messages[1], $messages[2] );
- }
-
- return $receivedMessages;
- }
-
- public function decodeDecryptLoop($messageArray)
- {
- $receivedMessages = array();
- foreach ($messageArray as $message) {
-
- if ($this->CIPHER_KEY) {
- $decryptedMessage = decrypt($message, $this->CIPHER_KEY);
- $message = json_decode($decryptedMessage, true);
- }
-
- array_push($receivedMessages, $message);
- }
- return $receivedMessages;
- }
-
-
- public function handleError($error, $args)
- {
- $errorMsg = 'Error on line ' . $error->getLine() . ' in ' . $error->getFile() . $error->getMessage();
- trigger_error($errorMsg, E_COMPILE_WARNING);
-
-
- sleep(1);
- }
-
- /**
- * Presence
- *
- * This is BLOCKING.
- * Listen for a message on a channel.
- *
- * @param array $args with channel and message.
- * @return mixed false on fail, array on success.
- */
- function presence($args)
- {
- ## Capture User Input
- $args['channel'] = ($args['channel'] . "-pnpres");
- $this->subscribe($args, true);
- }
-
- /**
- * Detailed History
- *
- * Load history from a channel.
- *
- * @param array $args with 'channel' and 'limit'.
- * @return mixed false on fail, array on success.
- */
-
- function detailedHistory($args)
- {
- ## Capture User Input
-
- ## Fail if bad input.
- if (!$args['channel']) {
- echo('Missing Channel');
- return false;
- }
-
- $channel = $args['channel'];
- $urlParams = "";
-
- if ($args['count'] || $args['start'] || $args['end'] || $args['reverse']) {
-
- $urlParamSep = "?";
- if (isset($args['count'])) {
- $urlParams .= $urlParamSep . "count=" . $args['count'];
- $urlParamSep = "&";
- }
- if (isset($args['start'])) {
- $urlParams .= $urlParamSep . "start=" . $args['start'];
- $urlParamSep = "&";
- }
- if (isset($args['end'])) {
- $urlParams .= $urlParamSep . "end=" . $args['end'];
- $urlParamSep = "&";
- }
- if (isset($args['reverse'])) {
- $urlParams .= $urlParamSep . "reverse=" . $args['reverse'];
- }
-
- }
-
- $response = $this->_request(array(
- 'v2',
- 'history',
- "sub-key",
- $this->SUBSCRIBE_KEY,
- "channel",
- $channel
- ), $urlParams);
- ;
-
- $receivedMessages = $this->decodeAndDecrypt($response, "detailedHistory");
-
- return $receivedMessages;
-
- }
-
- /**
- * History
- *
- * Load history from a channel.
- *
- * @param array $args with 'channel' and 'limit'.
- * @return mixed false on fail, array on success.
- */
- function history($args)
- {
- ## Capture User Input
- $limit = +$args['limit'] ? +$args['limit'] : 10;
- $channel = $args['channel'];
-
- ## Fail if bad input.
- if (!$channel) {
- echo('Missing Channel');
- return false;
- }
-
- ## Get History
- $response = $this->_request(array(
- 'history',
- $this->SUBSCRIBE_KEY,
- $channel,
- '0',
- $limit
- ));
- ;
-
- $receivedMessages = $this->decodeAndDecrypt($response);
-
- return $receivedMessages;
-
- }
-
- /**
- * Time
- *
- * Timestamp from PubNub Cloud.
- *
- * @return int timestamp.
- */
- function time()
- {
- ## Get History
- $response = $this->_request(array(
- 'time',
- '0'
- ));
-
- return $response[0];
- }
-
- /**
- * UUID
- *
- * UUID generator
- *
- * @return UUID
- */
- function uuid()
- {
- if (function_exists('com_create_guid') === true) {
- return trim(com_create_guid(), '{}');
- }
-
- return sprintf('%04X%04X-%04X-%04X-%04X-%04X%04X%04X', mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(16384, 20479), mt_rand(32768, 49151), mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(0, 65535));
- }
-
- /**
- * Request URL
- *
- * @param array $request of url directories.
- * @return array from JSON response.
- */
- private function _request($request, $urlParams = false)
- {
- $request = array_map('Pubnub::_encode', $request);
-
- array_unshift($request, $this->ORIGIN);
-
- if (($request[1] === 'presence') || ($request[1] === 'subscribe')) {
- array_push($request, '?uuid=' . $this->SESSION_UUID);
- }
-
- $urlString = implode('/', $request);
-
- if ($urlParams) {
- $urlString .= $urlParams;
- }
-
- $ch = curl_init();
-
- $pubnubHeaders = array("V: 3.4", "Accept: */*");
- curl_setopt($ch, CURLOPT_HTTPHEADER, $pubnubHeaders);
- curl_setopt($ch, CURLOPT_USERAGENT, "PHP");
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_TIMEOUT, 310);
-
- curl_setopt($ch, CURLOPT_URL, $urlString);
-
- if ($this->SSL) {
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
-
-
- $pemPathAndFilename = $this->PEM_PATH . "/pubnub.com.pem";
- if (file_exists($pemPathAndFilename))
- curl_setopt($ch, CURLOPT_CAINFO, $pemPathAndFilename);
- else {
- trigger_error("Can't find PEM file. Please set pem_path in initializer.");
- exit;
- }
-
- }
-
-
- $output = curl_exec($ch);
- $curlError = curl_errno($ch);
- $curlResponseCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
-
- curl_close($ch);
-
- $JSONdecodedResponse = json_decode($output, true);
-
- if ($JSONdecodedResponse != null)
- return $JSONdecodedResponse;
- elseif ($curlError == 28)
- return "_PUBNUB_TIMEOUT";
- elseif ($curlResponseCode == 400 || $curlResponseCode == 404)
- return "_PUBNUB_MESSAGE_TOO_LARGE";
-
- }
-
- /**
- * Encode
- *
- * @param string $part of url directories.
- * @return string encoded string.
- */
- private static function _encode($part)
- {
- $pieces = array_map('Pubnub::_encode_char', str_split($part));
- return implode('', $pieces);
- }
-
- /**
- * Encode Char
- *
- * @param string $char val.
- * @return string encoded char.
- */
- private static function _encode_char($char)
- {
- if (strpos(' ~`!@#$%^&*()+=[]\\{}|;\':",./<>?', $char) === false)
- return $char;
- else
- return rawurlencode($char);
- }
-}
-
-?>
View
94 php/3.3/PubnubAES.php
@@ -1,94 +0,0 @@
-<?php
-
-#$plaintext = "this is my plaintext.";
-$cipher_key = "enigma";
-
-#printf("\ncipher key is %s\n", $cipher_key);
-
-#$cipher_text = "q/xJqqN6qbiZMXYmiQC1Fw==";
-#$decrypt = "RVOElAJIHskATgCCP+KlaQ==";
-#$key = "67a4f45f0d1d9bc606486fc42dc49416";
-#$iv = "0123456789012345";
-## Manual Run
-#$cipher_text = encrypt("hellohellohello!", $cipher_key, $iv);
-#$p_text = decrypt($cipher_text, $cipher_key, $iv);
-##
-
-function decrypt($cipher_text, $cipher_key) {
- $iv = "0123456789012345";
-
- if (gettype($cipher_text) != "string")
- return "DECRYPTION_ERROR";
-
- $decoded = base64_decode($cipher_text);
-
- $sha_cipher_key = hash("sha256", $cipher_key);
- $padded_cipher_key = substr($sha_cipher_key, 0, 32);
-
- $td = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_CBC, '');
- mcrypt_generic_init($td, $padded_cipher_key, $iv);
-
- $decrypted = mdecrypt_generic($td, $decoded); // TODO: handle non-encrypted unicode corner-case
- mcrypt_generic_deinit($td);
- mcrypt_module_close($td);
-
- $unpadded = unpadPKCS7($decrypted, 16);
- #printf("\ndecoded: %s", $unpadded);
- return $unpadded;
-}
-
-
-function encrypt($plain_text, $cipher_key) {
- $iv = "0123456789012345";
-
- $sha_cipher_key = hash("sha256", $cipher_key);
- $padded_cipher_key = substr($sha_cipher_key, 0, 32);
- $padded_plain_text = pkcs5_pad($plain_text, 16);
-
-// printf("sha256 key is %s\n", $sha_cipher_key);
-// printf("padded cipher key is %s\n\n", $padded_cipher_key);
-// printf("padded plain_text is %s\n\n", $padded_plain_text);
-
- # This is the way to do AES-256 using mcrypt PHP - its not AES-128 or anything other than that!
- $td = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_CBC, '');
- mcrypt_generic_init($td, $padded_cipher_key, $iv);
- $encrypted = mcrypt_generic($td, $padded_plain_text);
- $encode = base64_encode($encrypted);
- mcrypt_generic_deinit($td);
- mcrypt_module_close($td);
- #printf("\nencoded: %s", $encode);
- return $encode;
-}
-
-function pkcs5_pad ($text, $blocksize)
-{
- $pad = $blocksize - (strlen($text) % $blocksize);
- return $text . str_repeat(chr($pad), $pad);
-}
-
-function unpadPKCS7($data, $blockSize)
-{
- $length = strlen($data);
- if ($length > 0) {
- $first = substr($data, -1);
-
- if (ord($first) <= $blockSize) {
- for ($i = $length - 2; $i > 0; $i--)
- if (ord($data [$i] != $first))
- break;
-
- return substr($data, 0, $i+1);
- }
- }
- return $data;
-}
-
-function isBlank($word)
-{
- if (($word == null) || ($word == false))
- return true;
- else
- return false;
-}
-
-?>
View
211 php/3.3/PubnubTest.php
@@ -1,211 +0,0 @@
-<?php
-
-include('Pubnub.php');
-
-class PubnubTest extends PHPUnit_Framework_TestCase
-{
- protected $pubnub;
- public static $channel = 'testChannel';
- static $configs = array('default' => array('publish_key' => 'demo', 'subscribe_key' => 'demo', 'secret_key' => false, 'cipher_key' => false, 'ssl_on' => false),
- 'cipher' => array('publish_key' => 'demo', 'subscribe_key' => 'demo', 'secret_key' => false, 'cipher_key' => 'enigma', 'ssl_on' => false),
- 'ssl' => array('publish_key' => 'demo', 'subscribe_key' => 'demo', 'secret_key' => false, 'cipher_key' => false, 'ssl_on' => true),
- 'cipherSsl' => array('publish_key' => 'demo', 'subscribe_key' => 'demo', 'secret_key' => false, 'cipher_key' => 'enigma', 'ssl_on' => true));
-
-
- private function getObject($config)
- {
- return new Pubnub($config['publish_key'],$config['subscribe_key'],$config['secret_key'],$config['cipher_key'],$config['ssl_on']);
- }
-
-
- public static function setUpBeforeClass()
- {
- exec( 'php subscribeTest.php > /dev/null &', $Out );
- exec( 'php presenceTest.php > /dev/null &', $Out );
- }
-
-
-## ------------------ ENCRIPTION TEST ------------------ ##
- public function testEncryption(){
- $plain_text = "yay!";
- $cipher_text = "q/xJqqN6qbiZMXYmiQC1Fw==";
-
- $this->assertEquals( decrypt($cipher_text, self::$configs['cipher']['cipher_key']), $plain_text );
- $this->assertEquals( encrypt($plain_text, self::$configs['cipher']['cipher_key']), $cipher_text );
- }
-
-
-## ------------------ HERE NOW TEST ------------------ ##
- /**
- * @dataProvider configsProvider
- */
- public function testHereNow($config)
- {
- $pubnub = $this->getObject($config);
- $here_now = $pubnub->here_now( array(
- 'channel' => self::$channel
- ));
- $this->assertNotCount( 0, $here_now['uuids'] );
- }
-
-
-## ------------------ PUBLISH TEST ------------------ ##
- /**
- * @dataProvider publishProvider
- * @depends testHereNow
- */
- public function testPublish($config, $message, $statusResponse, $msgResponse, $channel = false)
- {
- $pubnub = $this->getObject($config);
- $publish_success = $pubnub->publish( array(
- 'channel' => $channel ? $channel : self::$channel,
- 'message' => $message
- ));
- $this->assertEquals( $publish_success[0], $statusResponse);
- $this->assertEquals( $publish_success[1], $msgResponse);
- }
-
- public function publishProvider()
- {
- return array(
- // NoCipher, NoSsl
- array(self::$configs['default'],'Hello from PHP!', 1, 'Sent'),
- array(self::$configs['default'],'漢語', 1, 'Sent'),
- array(self::$configs['default'],array( 'this stuff' => array( 'can get' => 'complicated!' )), 1, 'Sent'),
- array(self::$configs['default'],array(), 1, 'Sent'),
- array(self::$configs['default'],str_repeat('a', 2000), 0, 'Message Too Large'),
- // Cipher, NoSsl
- array(self::$configs['cipher'],'Pubnub Messaging API 1', 1, 'Sent'),
- array(self::$configs['cipher'],'漢語', 1, 'Sent'),
- array(self::$configs['cipher'],array( 'this stuff' => array( 'can get' => 'complicated!' )), 1, 'Sent'),
- array(self::$configs['cipher'],array(), 1, 'Sent'),
- array(self::$configs['cipher'],str_repeat('a', 2000), 0, 'Message Too Large'),
- // NoCipher, Ssl
- array(self::$configs['ssl'],'Pubnub Messaging API 1', 1, 'Sent'),
- array(self::$configs['ssl'],'漢語', 1, 'Sent'),
- array(self::$configs['ssl'],array( 'this stuff' => array( 'can get' => 'complicated!' )), 1, 'Sent'),
- array(self::$configs['ssl'],array(), 1, 'Sent'),
- array(self::$configs['ssl'],str_repeat('a', 2000), 0, 'Message Too Large'),
- // Cipher, Ssl
- array(self::$configs['cipherSsl'],'Pubnub Messaging API 1', 1, 'Sent'),
- array(self::$configs['cipherSsl'],'漢語', 1, 'Sent'),
- array(self::$configs['cipherSsl'],array( 'this stuff' => array( 'can get' => 'complicated!' )), 1, 'Sent'),
- array(self::$configs['cipherSsl'],array(), 1, 'Sent'),
- array(self::$configs['cipherSsl'],str_repeat('a', 2000), 0, 'Message Too Large'),
- // Message to presence
- array(self::$configs['default'],'Test Presence', 1, 'Sent', self::$channel.'-pnpres'),
- );
- }
-
-
-## ------------------ HISTORY TEST ------------------ ##
- /**
- * @dataProvider historyProvider
- */
- public function testHistory($config, $limit)
- {
- $pubnub = $this->getObject($config);
- $history = $pubnub->history( array(
- 'channel' => self::$channel,
- 'limit' => $limit
- ));
- $this->assertNotEmpty( $history );
- $this->assertGreaterThanOrEqual( count($history), $limit );
- }
-
- public function historyProvider()
- {
- return array(
- // NoCipher, NoSsl
- array(self::$configs['default'],1),
- array(self::$configs['default'],2),
- array(self::$configs['default'],3),
- array(self::$configs['default'],4),
- array(self::$configs['default'],5),
- // Cipher, NoSsl
- array(self::$configs['cipher'],1),
- array(self::$configs['cipher'],2),
- array(self::$configs['cipher'],3),
- array(self::$configs['cipher'],4),
- array(self::$configs['cipher'],5),
- // NoCipher, Ssl
- array(self::$configs['ssl'],1),
- array(self::$configs['ssl'],2),
- array(self::$configs['ssl'],3),
- array(self::$configs['ssl'],4),
- array(self::$configs['ssl'],5),
- // Cipher, Ssl
- array(self::$configs['cipherSsl'],1),
- array(self::$configs['cipherSsl'],2),
- array(self::$configs['cipherSsl'],3),
- array(self::$configs['cipherSsl'],4),
- array(self::$configs['cipherSsl'],5)
- );
- }
-
-
-## ------------------ DETAILED HISTORY TEST ------------------ ##
- /**
- * @dataProvider historyProvider
- */
- public function testDetailedHistory($config, $count)
- {
- $pubnub = $this->getObject($config);
- $history = $pubnub->detailedHistory( array(
- 'channel' => self::$channel,
- 'count' => $count,
- 'end' => '13466530169226760'
- ));
- $this->assertNotEmpty( $history );
- $this->assertGreaterThanOrEqual( count($history), $count );
- }
-
-
-## ------------------ TIME TEST ------------------ ##
- /**
- * @dataProvider configsProvider
- */
- public function testTime($config)
- {
- $pubnub = $this->getObject($config);
- $time = $pubnub->time();
- $this->assertTrue( is_integer($time) && $time );
- }
-
-
- public function configsProvider()
- {
- return array(
- // NoCipher, NoSsl
- array(self::$configs['default']),
- array(self::$configs['cipher']),
- array(self::$configs['ssl']),
- array(self::$configs['cipherSsl'])
- );
- }
-
-
-## ------------------ SUBSCRIBE TEST ------------------ ##
- /**
- * @depends testPublish
- */
- public function testSubscribe()
- {
- $this->assertTrue( is_array($subs = unserialize(file_get_contents('subscribeOut.txt'))) );
- $this->assertNotEmpty( $subs );
- unlink('subscribeOut.txt');
- }
-
-
-## ------------------ SUBSCRIBE TEST ------------------ ##
- /**
- * @depends testPublish
- */
- public function testPresenceO()
- {
- $this->assertTrue( is_array($subs = unserialize(file_get_contents('presenceOut.txt'))) );
- $this->assertNotEmpty( $subs );
- unlink('presenceOut.txt');
- }
-
-}
View
32 php/3.3/exitSubOnFalse.php
@@ -1,32 +0,0 @@
-<?php
-require_once('Pubnub.php');
-
-
-$publish_key = isset($argv[1]) ? $argv[1] : 'demo';
-$subscribe_key = isset($argv[2]) ? $argv[2] : 'demo';
-$secret_key = isset($argv[3]) ? $argv[3] : false;
-$cipher_key = isset($argv[4]) ? $argv[4] : false;
-$ssl_on = false;
-
-## Create Pubnub Object
-
-$pubnub = new Pubnub( $publish_key, $subscribe_key, $secret_key, $cipher_key, $ssl_on );
-
-## Define Messaging Channel
-
-$channel = "hello_world";
-
-## Subscribe Example
-
-echo("\nWaiting for Publish message... Hit CTRL+C to finish.\n");
-
-$pubnub->subscribe(array(
- 'channel' => $channel,
- 'callback' => function($message) {
- print_r($message);
- echo "\r\n";
- return false;
- }
-));
-
-?>
View
13 php/3.3/here_now_example.php
@@ -1,13 +0,0 @@
-<?php
-require_once('Pubnub.php');
-
-$pubnub = new Pubnub( 'demo', 'demo', false , false, false );
-$here = $pubnub->here_now(array( 'channel' => 'my_channel' ));
-$occupancy = $here['occupancy'];
-$user_ids = $here['uuids'];
-
-print("UUIDs (userIDs): ");
-print_r($user_ids);
-print("\n");
-print("OCCUPANTS: $occupancy\n\n");
-?>
View
14 php/3.3/presenceTest.php
@@ -1,14 +0,0 @@
-<?php
-require_once('Pubnub.php');
-
-$pubnub = new Pubnub( 'demo', 'demo', false , false, false );
-$pubnub->presence(array(
- 'channel' => 'testChannel',
- 'callback' => function($message) {
- $fp = fopen('presenceOut.txt', 'w');
- fwrite($fp, serialize($message));
- fclose($fp);
- exit;
- }
-));
-?>
View
32 php/3.3/pubnub.com.pem
@@ -1,32 +0,0 @@
------BEGIN CERTIFICATE-----
-MIIFgDCCBGigAwIBAgIHTpwnck1dVjANBgkqhkiG9w0BAQUFADCB3DELMAkGA1UE
-BhMCVVMxEDAOBgNVBAgTB0FyaXpvbmExEzARBgNVBAcTClNjb3R0c2RhbGUxJTAj
-BgNVBAoTHFN0YXJmaWVsZCBUZWNobm9sb2dpZXMsIEluYy4xOTA3BgNVBAsTMGh0
-dHA6Ly9jZXJ0aWZpY2F0ZXMuc3RhcmZpZWxkdGVjaC5jb20vcmVwb3NpdG9yeTEx
-MC8GA1UEAxMoU3RhcmZpZWxkIFNlY3VyZSBDZXJ0aWZpY2F0aW9uIEF1dGhvcml0
-eTERMA8GA1UEBRMIMTA2ODg0MzUwHhcNMTExMTAyMjAwMjMzWhcNMTIxMTAyMTgz
-MzM1WjBRMRUwEwYDVQQKFAwqLnB1Ym51Yi5jb20xITAfBgNVBAsTGERvbWFpbiBD
-b250cm9sIFZhbGlkYXRlZDEVMBMGA1UEAxQMKi5wdWJudWIuY29tMIIBIjANBgkq
-hkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAoUoh/H9N9ueaxGuGZaIPyhilMANSQCXC
-N4l1AW2KRM4c3iUfnbJgRe09byZ3mpZ9AVhqt5fDTkYYPJGnBp2aBVY+zcSaNSWA
-HwaEVPcbvhTSq7xqqnbSz7hYWfgvMf8XPI8oY4N9y/l6Gnx+mdPoZUvIZ55buQHe
-D7/qwnY5pb8cnO9ocV9UVVWUMh4zVD0Ya3VsR1aIjsCOdkRx/LHmPW2x3zYT8RvN
-1/ddUf9dsbDgGT4X7qbYxsF7sLgOGmtENvsEhC76phaaRNhsXNeucujRo373e3jU
-+wmbJ+3LzLzV9eEuYU3KVUvpayonZrLTugI+Bef8+3VjZhv9P8YEOwIDAQABo4IB
-zzCCAcswDwYDVR0TAQH/BAUwAwEBADAdBgNVHSUEFjAUBggrBgEFBQcDAQYIKwYB
-BQUHAwIwDgYDVR0PAQH/BAQDAgWgMDkGA1UdHwQyMDAwLqAsoCqGKGh0dHA6Ly9j
-cmwuc3RhcmZpZWxkdGVjaC5jb20vc2ZzMS0yMC5jcmwwWQYDVR0gBFIwUDBOBgtg
-hkgBhv1uAQcXATA/MD0GCCsGAQUFBwIBFjFodHRwOi8vY2VydGlmaWNhdGVzLnN0
-YXJmaWVsZHRlY2guY29tL3JlcG9zaXRvcnkvMIGNBggrBgEFBQcBAQSBgDB+MCoG
-CCsGAQUFBzABhh5odHRwOi8vb2NzcC5zdGFyZmllbGR0ZWNoLmNvbS8wUAYIKwYB
-BQUHMAKGRGh0dHA6Ly9jZXJ0aWZpY2F0ZXMuc3RhcmZpZWxkdGVjaC5jb20vcmVw
-b3NpdG9yeS9zZl9pbnRlcm1lZGlhdGUuY3J0MB8GA1UdIwQYMBaAFElLUifRG7zy
-oSFqYntRQnqK19VWMCMGA1UdEQQcMBqCDCoucHVibnViLmNvbYIKcHVibnViLmNv
-bTAdBgNVHQ4EFgQU1LjhCRlC4sKfFRaCg+uhNjOz3u8wDQYJKoZIhvcNAQEFBQAD
-ggEBAFZWrYmY4JqP+//8v/3/UztMpZWWlivZ44wpbxNIeQEnHVxpzjfG+eUZkZpV
-1e3DG3pxDdehwNE3YIbnkCku0SaqOT4sU6AjfaLV3tHvvqFwBGQQqdAkuC+C1O1D
-ynHq2vyPvsFu5jDDSOQ4IMgWSznay7b1bzp55NxPg16D3i9p+cy6nYUvHsjqjLn9
-8qiWwFWYaNju5CYr+fIl5sR3AP+8Qd+IYDpx+icMt42yOgN1mBauMj0bMV3p9D9B
-egQH1kN29mb65Q52t2wDooIqiTPrmMGwr+59SmCrchzMWFT/8wakPSo4aK2/Z5f1
-mslRKVjaP39pSqkEdD2S1VvR4x0=
------END CERTIFICATE-----
View
176 php/3.3/pubnubCipherTextTests.php
@@ -1,176 +0,0 @@
-<?php
-
-require_once('Pubnub.php');
-
-##
-# php ./pubnubPlaintextTests.php
-# php ./pubnubPlaintextTests.php [PUB-KEY] [SUB-KEY] [SECRET-KEY] [CIPHER-KEY] [USE SSL]
-
-## Capture Publish and Subscribe Keys from Command Line
-
-
-// TODO: Need SSL tests
-
-$publish_key = 'demo';
-$subscribe_key = 'demo';
-$secret_key = false;
-$cipher_key = "enigma";
-$ssl_on = false;
-
-$plain_text = "yay!";
-$cipher_text = "q/xJqqN6qbiZMXYmiQC1Fw==";
-$cipher_key = "enigma";
-
-## Encryption Test
-if (decrypt($cipher_text, $cipher_key) == $plain_text) {
- echo "Standard encryption test PASS.\n\n";
-} else
- echo "Standard encryption test FAIL.\n\n";
-
-## Decryption Test
-if (encrypt($plain_text, $cipher_key) == $cipher_text) {
- echo "Standard decryption test PASS.\n\n";
-} else
- echo "Standard decryption test FAIL.\n\n";
-
-
-## ---------------------------------------------------------------------------
-## Create Pubnub Object
-## ---------------------------------------------------------------------------
-$pubnub = new Pubnub( $publish_key, $subscribe_key, $secret_key, $cipher_key, $ssl_on );
-
-## ---------------------------------------------------------------------------
-## Define Messaging Channel
-## ---------------------------------------------------------------------------
-$channel = "hello_world";
-
-## ---------------------------------------------------------------------------
-## Publish Example
-## ---------------------------------------------------------------------------
-echo "Running publish\r\n";
-$publish_success = $pubnub->publish(array(
- 'channel' => $channel,
- 'message' => 'Pubnub Messaging API 1'
-));
-echo($publish_success[0] . $publish_success[1]);
-echo "\r\n";
-
-$publish_success = $pubnub->publish(array(
- 'channel' => $channel,
- 'message' => 'Pubnub Messaging API 2'
-));
-echo($publish_success[0] . $publish_success[1]);
-echo "\r\n";
-
-
-
-$publish_success = $pubnub->publish(array(
- 'channel' => $channel,
- 'message' => '漢語'
-));
-echo($publish_success[0] . $publish_success[1]);
-echo "\r\n";
-
-// Publish an associative array
-
-$big_array = array();
-$big_array["this stuff"]["can get"] = "complicated!";
-
-$publish_success = $pubnub->publish(array(
- 'channel' => $channel,
- 'message' => $big_array
-));
-
-echo($publish_success[0] . $publish_success[1]);
-echo "\r\n";
-
-// Publish an empty array
-$emptyArray = array();
-$publish_success = $pubnub->publish(array(
- 'channel' => $channel,
- 'message' => $emptyArray
-));
-
-echo($publish_success[0] . $publish_success[1]);
-echo "\r\n";
-
-// This should return a failure (0) JSON Array
-$publish_success = $pubnub->publish(array(
- 'channel' => $channel,
- 'message' => "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
-));
-echo($publish_success[0] . $publish_success[1]);
-echo "\r\n";
-
-
-## ---------------------------------------------------------------------------
-## detailedHistory Example
-## ---------------------------------------------------------------------------
-echo "Running detailedHistory\r\n";
-$history = $pubnub->detailedHistory(array(
- 'channel' => $channel,
- 'count' => 5,
- 'end' => "13466530169226760"
-));
-print_r($history);
-echo "\r\n";
-
-## ---------------------------------------------------------------------------
-## History Example
-## ---------------------------------------------------------------------------
-echo "Running history\r\n";
-$history = $pubnub->history(array(
- 'channel' => $channel,
- 'limit' => 2
-));
-echo($history);
-echo "\r\n";
-
-## ---------------------------------------------------------------------------
-## Here_Now Example
-## ---------------------------------------------------------------------------
-echo "Running here_now\r\n";
-$here_now = $pubnub->here_now(array(
- 'channel' => $channel
-));
-var_dump($here_now);
-echo "\r\n";
-
-## ---------------------------------------------------------------------------
-## Timestamp Example
-## ---------------------------------------------------------------------------
-echo "Running timestamp\r\n";
-$timestamp = $pubnub->time();
-echo('Timestamp: ' . $timestamp);
-echo "\r\n";
-
-## ---------------------------------------------------------------------------
-## Presence Example
-## ---------------------------------------------------------------------------
-//echo("\nWaiting for Presence message... Hit CTRL+C to finish.\n");
-//
-//$pubnub->presence(array(
-// 'channel' => $channel,
-// 'callback' => function($message) {
-// print_r($message);
-// echo "\r\n";
-// return false;
-// }
-//));
-
-## ---------------------------------------------------------------------------
-## Subscribe Example
-## ---------------------------------------------------------------------------
-echo("\nWaiting for Publish message... Hit CTRL+C to finish.\n");
-
-$pubnub->subscribe(array(
- 'channel' => $channel,
- 'callback' => function($message) {
- print_r($message);
- echo "\r\n";
- return true;
- }
-));
-
-?>
-
View
130 php/3.3/pubnubPlaintextTests.php
@@ -1,130 +0,0 @@
-<?php
-require_once('Pubnub.php');
-
-// TODO: Add SSL version of these tests
-## ---------------------------------------------------------------------------