Updated scripts to the 1.1.8 code
Most recent code that I obtained from AYAH's website.
This commit is contained in:
parent
6e64ef7d9a
commit
60c0201bc6
3 changed files with 73 additions and 64 deletions
77
src/ayah.php
77
src/ayah.php
|
@ -3,7 +3,7 @@
|
||||||
* Are You A Human
|
* Are You A Human
|
||||||
* PHP Integration Library
|
* PHP Integration Library
|
||||||
*
|
*
|
||||||
* @version 1.1.6
|
* @version 1.1.8
|
||||||
*
|
*
|
||||||
* - Documentation and latest version
|
* - Documentation and latest version
|
||||||
* http://portal.areyouahuman.com/help
|
* http://portal.areyouahuman.com/help
|
||||||
|
@ -12,7 +12,7 @@
|
||||||
* - Discussion group
|
* - Discussion group
|
||||||
* http://getsatisfaction.com/areyouahuman
|
* http://getsatisfaction.com/areyouahuman
|
||||||
*
|
*
|
||||||
* Copyright (c) 2011 AYAH LLC -- http://www.areyouahuman.com
|
* Copyright (c) 2013 AYAH LLC -- http://www.areyouahuman.com
|
||||||
*
|
*
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
@ -33,12 +33,13 @@ class AYAH {
|
||||||
protected $ayah_scoring_key = '';
|
protected $ayah_scoring_key = '';
|
||||||
protected $ayah_web_service_host = 'ws.areyouahuman.com';
|
protected $ayah_web_service_host = 'ws.areyouahuman.com';
|
||||||
protected $ayah_debug_mode = FALSE;
|
protected $ayah_debug_mode = FALSE;
|
||||||
|
protected $ayah_use_curl = TRUE;
|
||||||
|
|
||||||
protected $session_secret;
|
protected $session_secret;
|
||||||
|
|
||||||
protected $__valid_construct_params = array('publisher_key', 'scoring_key', 'web_service_host', 'debug_mode');
|
protected $__valid_construct_params = array('publisher_key', 'scoring_key', 'web_service_host', 'debug_mode', 'use_curl');
|
||||||
protected $__message_buffer = array();
|
protected $__message_buffer = array();
|
||||||
protected $__version_number = '1.1.6';
|
protected $__version_number = '1.1.7';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
|
@ -54,39 +55,26 @@ class AYAH {
|
||||||
$this->__log("DEBUG", __FUNCTION__, "The ayah_config.php file is missing.");
|
$this->__log("DEBUG", __FUNCTION__, "The ayah_config.php file is missing.");
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the constants exist, override with those
|
// Get and use any valid parameters that were passed in via the $params array.
|
||||||
if (defined('AYAH_PUBLISHER_KEY'))
|
foreach ((array)$this->__valid_construct_params as $partial_variable_name)
|
||||||
{
|
{
|
||||||
$this->ayah_publisher_key = AYAH_PUBLISHER_KEY;
|
// Build the full variable name...and create an upper case version.
|
||||||
}
|
$variable_name = "ayah_" . $partial_variable_name;
|
||||||
if (defined('AYAH_SCORING_KEY'))
|
$uc_variable_name = strtoupper($variable_name);
|
||||||
{
|
|
||||||
$this->ayah_scoring_key = AYAH_SCORING_KEY;
|
|
||||||
}
|
|
||||||
if (defined('AYAH_WEB_SERVICE_HOST'))
|
|
||||||
{
|
|
||||||
$this->ayah_web_service_host = AYAH_WEB_SERVICE_HOST;
|
|
||||||
}
|
|
||||||
if (defined('AYAH_DEBUG_MODE'))
|
|
||||||
{
|
|
||||||
$this->ayah_debug_mode = AYAH_DEBUG_MODE;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Lastly, the params passed in can override the values set above.
|
// Check to see if it was passed in via $params.
|
||||||
foreach ((array)$params as $key => $value)
|
if (isset($params[$partial_variable_name]))
|
||||||
{
|
{
|
||||||
if (in_array($key, $this->__valid_construct_params))
|
$this->{$variable_name} = $params[$partial_variable_name];
|
||||||
{
|
|
||||||
$variable = "ayah_" . $key;
|
|
||||||
$this->$variable = $value;
|
|
||||||
}
|
}
|
||||||
else
|
// Check to see if it was defined in the ayah_config file.
|
||||||
|
elseif (defined($uc_variable_name))
|
||||||
{
|
{
|
||||||
$this->__log("ERROR", __FUNCTION__, "Unrecognized key for constructor param: '$key'");
|
$this->{$variable_name} = constant($uc_variable_name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generate some warnings/errors if any of the needed variables is not set.
|
// Generate some warnings/errors if needed variables are not set.
|
||||||
if ($this->ayah_publisher_key == "")
|
if ($this->ayah_publisher_key == "")
|
||||||
{
|
{
|
||||||
$this->__log("ERROR", __FUNCTION__, "Warning: Publisher key is not defined. This won't work.");
|
$this->__log("ERROR", __FUNCTION__, "Warning: Publisher key is not defined. This won't work.");
|
||||||
|
@ -101,7 +89,7 @@ class AYAH {
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$this->__log("DEBUG", __FUNCTION__, "Scoring key: '$this->ayah_scoring_key'");
|
// For security reasons, don't output the scoring key as part of the debug info.
|
||||||
}
|
}
|
||||||
if ($this->ayah_web_service_host == "")
|
if ($this->ayah_web_service_host == "")
|
||||||
{
|
{
|
||||||
|
@ -194,7 +182,7 @@ class AYAH {
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$this->__log("ERROR", __FUNCTION__, "Unable to score the result. Please check that your ayah_config.php file contains your correct publisher key and scoring key.");
|
$this->__log("DEBUG", __FUNCTION__, "Unable to score the result. Please check that your ayah_config.php file contains your correct publisher key and scoring key.");
|
||||||
}
|
}
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
|
@ -262,8 +250,8 @@ class AYAH {
|
||||||
}
|
}
|
||||||
rtrim($fields_string,'&');
|
rtrim($fields_string,'&');
|
||||||
|
|
||||||
// cURL or something else
|
// Use cURL?
|
||||||
if (function_exists('curl_init') and function_exists('curl_exec'))
|
if ($this->__use_curl())
|
||||||
{
|
{
|
||||||
// Build the cURL url.
|
// Build the cURL url.
|
||||||
$curl_url = "https://" . $hostname . $path;
|
$curl_url = "https://" . $hostname . $path;
|
||||||
|
@ -295,7 +283,8 @@ class AYAH {
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$this->__log("DEBUG", __FUNCTION__, "No cURL support....using fsockopen()");
|
// Log it.
|
||||||
|
$this->__log("DEBUG", __FUNCTION__, "Using fsockopen(): fields='$fields_string'");
|
||||||
|
|
||||||
// Build a header
|
// Build a header
|
||||||
$http_request = "POST $path HTTP/1.1\r\n";
|
$http_request = "POST $path HTTP/1.1\r\n";
|
||||||
|
@ -398,6 +387,24 @@ class AYAH {
|
||||||
return (isset($this->__version_number))? $this->__version_number : FALSE;
|
return (isset($this->__version_number))? $this->__version_number : FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine whether or not cURL is available to use.
|
||||||
|
*
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
private function __use_curl()
|
||||||
|
{
|
||||||
|
if (FALSE === $this->ayah_use_curl)
|
||||||
|
{
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
elseif (function_exists('curl_init') and function_exists('curl_exec'))
|
||||||
|
{
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load the config file.
|
* Load the config file.
|
||||||
*
|
*
|
||||||
|
@ -431,7 +438,7 @@ class AYAH {
|
||||||
*
|
*
|
||||||
* @return null
|
* @return null
|
||||||
*/
|
*/
|
||||||
private function __log($type, $function, $message)
|
protected function __log($type, $function, $message)
|
||||||
{
|
{
|
||||||
// Add a prefix to the message.
|
// Add a prefix to the message.
|
||||||
$message = __CLASS__ . "::$function: " . $message;
|
$message = __CLASS__ . "::$function: " . $message;
|
||||||
|
|
|
@ -5,8 +5,9 @@ define( 'AYAH_PUBLISHER_KEY', 'your_publisher_key_goes_here');
|
||||||
define( 'AYAH_SCORING_KEY', 'your_scoring_key_goes_here');
|
define( 'AYAH_SCORING_KEY', 'your_scoring_key_goes_here');
|
||||||
|
|
||||||
|
|
||||||
// Point to the default AYAH web service and set the timeout and debug_mode.
|
// Set defaults for values needed by the ayah.php file.
|
||||||
// (Note: you do not need to change these.)
|
// (Note: you do not need to change these.)
|
||||||
define( 'AYAH_WEB_SERVICE_HOST', 'ws.areyouahuman.com');
|
define( 'AYAH_WEB_SERVICE_HOST', 'ws.areyouahuman.com');
|
||||||
define( 'AYAH_TIMEOUT', 0);
|
define( 'AYAH_TIMEOUT', 0);
|
||||||
define( 'AYAH_DEBUG_MODE', FALSE);
|
define( 'AYAH_DEBUG_MODE', FALSE);
|
||||||
|
define( 'AYAH_USE_CURL', TRUE);
|
||||||
|
|
|
@ -20,44 +20,45 @@
|
||||||
*/
|
*/
|
||||||
//******************************************************************************
|
//******************************************************************************
|
||||||
|
|
||||||
// Instantiate the AYAH object.
|
// Instantiate the AYAH object. You need to instantiate the AYAH object
|
||||||
|
// on each page that is using PlayThru.
|
||||||
require_once("ayah.php");
|
require_once("ayah.php");
|
||||||
$ayah = new AYAH();
|
$ayah = new AYAH();
|
||||||
|
|
||||||
// If the PlayThru does not work correctly, enable debug mode.
|
// Check to see if the user has submitted the form. You will need to replace
|
||||||
//$ayah->debug_mode(TRUE);
|
// 'my_submit_button_name' with the name of your 'Submit' button.
|
||||||
|
|
||||||
// The form submits to itself, so see if the user has submitted the form.
|
|
||||||
if (array_key_exists('my_submit_button_name', $_POST))
|
if (array_key_exists('my_submit_button_name', $_POST))
|
||||||
{
|
{
|
||||||
// Use the AYAH object to get the score.
|
// Use the AYAH object to see if the user passed or failed the game.
|
||||||
$score = $ayah->scoreResult();
|
$score = $ayah->scoreResult();
|
||||||
|
|
||||||
// Check the score to determine what to do.
|
|
||||||
if ($score)
|
if ($score)
|
||||||
{
|
{
|
||||||
// Add code to process the form.
|
// This happens if the user passes the game. In this case,
|
||||||
echo "Hello ".$_POST['name'].", You are a human!";
|
// we're just displaying a congratulatory message.
|
||||||
|
echo "Congratulations: you are a human!";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
echo "You are NOT a human!";
|
// This happens if the user does not pass the game.
|
||||||
|
echo "Sorry, but we were not able to verify you as human. Please try again.";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
|
||||||
<!-- Build the form tag. -->
|
<!-- Now we're going to build the form that PlayThru is attached to.
|
||||||
<!-- (note: the blank action causes the form to submit to itself) -->
|
In this example, the form submits to itself. -->
|
||||||
<form method="post" action="">
|
<form method="post" action="">
|
||||||
<!-- Build a form field. -->
|
|
||||||
<p>Please enter your name: <input type="text" name="name"></p>
|
<p>Please enter your name: <input type="text" name="name" /></p>
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
// Use the AYAH object to get the HTML code needed to
|
// Use the AYAH object to get the HTML code needed to
|
||||||
// load and run the PlayThru.
|
// load and run PlayThru. You should place this code
|
||||||
|
// directly before your 'Submit' button.
|
||||||
echo $ayah->getPublisherHTML();
|
echo $ayah->getPublisherHTML();
|
||||||
?>
|
?>
|
||||||
|
|
||||||
<!-- Include a submit button. -->
|
<!-- Make sure the name of your 'Submit' matches the name you used on line 9. -->
|
||||||
<input type="Submit" name="my_submit_button_name" value=" GO ">
|
<input type="Submit" name="my_submit_button_name" value=" Submit ">
|
||||||
</form>
|
</form>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue