Updated scripts to the 1.1.8 code

Most recent code that I obtained from AYAH's website.
This commit is contained in:
Joshua Sherman 2014-01-29 11:38:28 -05:00
parent 6e64ef7d9a
commit 60c0201bc6
3 changed files with 73 additions and 64 deletions

View file

@ -3,7 +3,7 @@
* Are You A Human
* PHP Integration Library
*
* @version 1.1.6
* @version 1.1.8
*
* - Documentation and latest version
* http://portal.areyouahuman.com/help
@ -12,7 +12,7 @@
* - Discussion group
* 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
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
@ -33,12 +33,13 @@ class AYAH {
protected $ayah_scoring_key = '';
protected $ayah_web_service_host = 'ws.areyouahuman.com';
protected $ayah_debug_mode = FALSE;
protected $ayah_use_curl = TRUE;
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 $__version_number = '1.1.6';
protected $__version_number = '1.1.7';
/**
* Constructor
@ -54,39 +55,26 @@ class AYAH {
$this->__log("DEBUG", __FUNCTION__, "The ayah_config.php file is missing.");
}
// If the constants exist, override with those
if (defined('AYAH_PUBLISHER_KEY'))
// Get and use any valid parameters that were passed in via the $params array.
foreach ((array)$this->__valid_construct_params as $partial_variable_name)
{
$this->ayah_publisher_key = AYAH_PUBLISHER_KEY;
}
if (defined('AYAH_SCORING_KEY'))
{
$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;
}
// Build the full variable name...and create an upper case version.
$variable_name = "ayah_" . $partial_variable_name;
$uc_variable_name = strtoupper($variable_name);
// Lastly, the params passed in can override the values set above.
foreach ((array)$params as $key => $value)
{
if (in_array($key, $this->__valid_construct_params))
// Check to see if it was passed in via $params.
if (isset($params[$partial_variable_name]))
{
$variable = "ayah_" . $key;
$this->$variable = $value;
$this->{$variable_name} = $params[$partial_variable_name];
}
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 == "")
{
$this->__log("ERROR", __FUNCTION__, "Warning: Publisher key is not defined. This won't work.");
@ -101,7 +89,7 @@ class AYAH {
}
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 == "")
{
@ -194,7 +182,7 @@ class AYAH {
}
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;
@ -262,8 +250,8 @@ class AYAH {
}
rtrim($fields_string,'&');
// cURL or something else
if (function_exists('curl_init') and function_exists('curl_exec'))
// Use cURL?
if ($this->__use_curl())
{
// Build the cURL url.
$curl_url = "https://" . $hostname . $path;
@ -295,7 +283,8 @@ class AYAH {
}
else
{
$this->__log("DEBUG", __FUNCTION__, "No cURL support....using fsockopen()");
// Log it.
$this->__log("DEBUG", __FUNCTION__, "Using fsockopen(): fields='$fields_string'");
// Build a header
$http_request = "POST $path HTTP/1.1\r\n";
@ -398,6 +387,24 @@ class AYAH {
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.
*
@ -431,7 +438,7 @@ class AYAH {
*
* @return null
*/
private function __log($type, $function, $message)
protected function __log($type, $function, $message)
{
// Add a prefix to the message.
$message = __CLASS__ . "::$function: " . $message;

View file

@ -5,8 +5,9 @@ define( 'AYAH_PUBLISHER_KEY', 'your_publisher_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.)
define( 'AYAH_WEB_SERVICE_HOST', 'ws.areyouahuman.com');
define( 'AYAH_TIMEOUT', 0);
define( 'AYAH_DEBUG_MODE', FALSE);
define( 'AYAH_USE_CURL', TRUE);

View file

@ -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");
$ayah = new AYAH();
// If the PlayThru does not work correctly, enable debug mode.
//$ayah->debug_mode(TRUE);
// The form submits to itself, so see if the user has submitted the form.
// Check to see if the user has submitted the form. You will need to replace
// 'my_submit_button_name' with the name of your 'Submit' button.
if (array_key_exists('my_submit_button_name', $_POST))
{
// Use the AYAH object to get the score.
$score = $ayah->scoreResult();
// Use the AYAH object to see if the user passed or failed the game.
$score = $ayah->scoreResult();
// Check the score to determine what to do.
if ($score)
{
// Add code to process the form.
echo "Hello ".$_POST['name'].", You are a human!";
}
else
{
echo "You are NOT a human!";
}
if ($score)
{
// This happens if the user passes the game. In this case,
// we're just displaying a congratulatory message.
echo "Congratulations: you are a human!";
}
else
{
// 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. -->
<!-- (note: the blank action causes the form to submit to itself) -->
<!-- Now we're going to build the form that PlayThru is attached to.
In this example, the form submits to itself. -->
<form method="post" action="">
<!-- Build a form field. -->
<p>Please enter your name: <input type="text" name="name"></p>
<?php
// Use the AYAH object to get the HTML code needed to
// load and run the PlayThru.
echo $ayah->getPublisherHTML();
?>
<p>Please enter your name: <input type="text" name="name" /></p>
<!-- Include a submit button. -->
<input type="Submit" name="my_submit_button_name" value=" GO ">
<?php
// Use the AYAH object to get the HTML code needed to
// load and run PlayThru. You should place this code
// directly before your 'Submit' button.
echo $ayah->getPublisherHTML();
?>
<!-- Make sure the name of your 'Submit' matches the name you used on line 9. -->
<input type="Submit" name="my_submit_button_name" value=" Submit ">
</form>