Skip to content

Instantly share code, notes, and snippets.

Created January 14, 2016 16:01
Show Gist options
  • Select an option

  • Save anonymous/df4483b4fa99858f49af to your computer and use it in GitHub Desktop.

Select an option

Save anonymous/df4483b4fa99858f49af to your computer and use it in GitHub Desktop.
<?php
/*
* Plugin Name: Ellipsis Human Presence Technology
* Plugin URI: http://www.humanpresence.net/wp-ellipsis-plugin/
* Description: Industry leading bot detection and analytics through the use of the Ellipsis Human Presence score proprietary technology. To get started: 1) Click the "Activate" link to the left of this description, 2) Go to the Ellipsis plugin <a href="../wp-admin/admin.php?page=wp-ellipsis">settings page</a> in the admin menu on the far left, and 3) Connect to Ellipsis with your company name and username.
* Version: 1.0
* Author: Ellipsis
* Author URI: http://www.humanpresence.net
* License: GPL2
*
*/
/*
* Assign global variables
*/
$plugin_url = plugins_url( '', __FILE__ );
$options = array();
$ellipsis_users = json_decode(file_get_contents('http://script.metricode.com/svc/users'), true);
$triggerLoginErr = false;
$triggerLoginErr2 = false;
$loggedIn = false;
$wp_ellipsis_api_key = null;
function wp_ellipsis_menu() {
add_menu_page(
// $page_title, $menu_title, $capability, $menu_slug, $function, $icon_url, $position
'Ellipsis Human Presence Technology',
'Ellipsis',
'manage_options',
'wp-ellipsis',
'wp_ellipsis_options_page',
'',
'100'
);
}
add_action( 'admin_menu', 'wp_ellipsis_menu' );
function wp_ellipsis_options_page() {
if( !current_user_can( 'manage_options' ) ) {
wp_die( 'You do not have sufficient permissions to access this page.' );
}
global $plugin_url;
global $options;
global $ellipsis_users;
global $triggerLoginErr;
global $triggerLoginErr2;
global $loggedIn;
global $wp_ellipsis_api_key;
//Login form submission
if( isset( $_POST['wp_ellipsis_form_submitted'] ) ) {
$hidden_field = esc_html( $_POST['wp_ellipsis_form_submitted'] );
if( $hidden_field == 'Y' && !$_POST['wp_ellipsis_company'] == '' && !$_POST['wp_ellipsis_username'] == '' ) {
$wp_ellipsis_company = esc_html( $_POST['wp_ellipsis_company'] );
$wp_ellipsis_username = esc_html( $_POST['wp_ellipsis_username'] );
foreach ($ellipsis_users[companyDict] as $i => $acct) {
//Make lowercase for case insensitive comparison
if ( strtolower($acct[Company]) == strtolower($wp_ellipsis_company) ) {
$acctIdx = $i;
foreach ($ellipsis_users[companyDict][$acctIdx][users] as $i => $user) {
//Make lowercase for case insensitive comparison
if ( strtolower($user[username]) == strtolower($wp_ellipsis_username) ) {
$wp_ellipsis_api_key = $ellipsis_users[companyDict][$acctIdx][api_key];
//Store username
$options['wp_ellipsis_company'] = $wp_ellipsis_company;
$options['wp_ellipsis_username'] = $wp_ellipsis_username;
$options['wp_ellipsis_api_key'] = $wp_ellipsis_api_key;
$options['last_updated'] = time();
update_option( 'wp-ellipsis', $options );
$loggedIn = true;
break;
} else {
$triggerLoginErr2 = true;
}
}
break;
} else {
$triggerLoginErr2 = true;
}
}
} else {
$triggerLoginErr = true;
}
}
//Logout
if( isset( $_POST['wp_ellipsis_logout_submitted'] ) ) {
delete_option( 'wp-ellipsis' );
}
//Check if already logged in and credentials are still valid
$options = get_option( 'wp-ellipsis' );
if ($options != '') {
$wp_ellipsis_company = $options['wp_ellipsis_company'];
$wp_ellipsis_username = $options['wp_ellipsis_username'];
$loggedIn = true;
}
require( 'inc/options-page-wrapper.php' );
}
//If logged in, add script to every page
/*\
*E* Activation Fatal Error Bug Fix
*D* @author: Brent Alexander
*I* @date: Jan 14, 2016 10:55 AM
*T* @since: 1.0.1
\*/
// get options
$options = get_option( 'wp-ellipsis' );
// check if api key exists
if ( array_key_exists('wp_ellipsis_api_key', $options ) ) {
$cachedApiKey = $options['wp_ellipsis_api_key'];
}
// if api key exists, enqueue scripts
if ( $cachedApiKey ) {
function wp_ellipsis_script() {
//Include ellipsis
wp_enqueue_script( 'wp_ellipsis_script', 'http://script.metricode.com/ellipsis.js?apikey=' . $cachedApiKey, array(), null );
//Include DOMReady
wp_enqueue_script( 'domready', plugins_url( '', __FILE__ ).'/domready.js', array(), null );
}
add_action( 'wp_enqueue_scripts', 'wp_ellipsis_script');
}
/*\ ////////////////////////////////////////////////////////
*E*
*D*
*I*
*T*
\*/
//Include Zero Clipboard and miscellaneous custom scripts & styles
function wp_misc_scripts() {
wp_enqueue_script( 'domready', plugins_url( '', __FILE__ ).'/domready.js', array(), null );
wp_enqueue_script( 'zeroclipboard', plugins_url( '', __FILE__ ).'/zero-clipboard/ZeroClipboard.js', array(), null );
wp_enqueue_script( 'func', plugins_url( '', __FILE__ ).'/func.js', array(), null );
wp_enqueue_style( 'styles', plugins_url( '', __FILE__ ).'/wp-ellipsis.css', array(), null );
}
add_action( 'admin_head', 'wp_misc_scripts' );
//Create Ellipsis Link Shortcode
function ellipsis_link_shortcode( $atts ) {
//Attributes
extract( shortcode_atts (array (
'css_class' => "",
'link_text' => "",
'human_traffic_url' => "",
'instance_number' => ""
), $atts));
if ($link_text) {
//Check human presence threshold and determine where to send the user.
$pluginUrl = plugins_url();
$options = get_option( 'wp-ellipsis' );
$checkKey = $options['wp_ellipsis_api_key'];
//Get human traffic url ID csv string
$humanUrlIdStr = $options['human_url_id'];
$humanUrlIds = explode(",", $humanUrlIdStr);
//Get last url index
$lastHumanUrlId = count($humanUrlIds);
$lastHumanUrlIdNum = intval($lastHumanUrlId);
//Set current url index
$currHumanUrlIdNum = $lastHumanUrlIdNum;
//Get human_traffic_url
$humanUrlStr = $options['human_url'];
$humanUrls = explode(",", $humanUrlStr);
$setIdx = null;
//If same url needs to be used multiple times on the same page, an instance_number should be provided for each.
$instance_num_value = $instance_number ? '-'.$instance_number : null;
//Check to see if Url has already been stored
$urlCached = strpos($humanUrlStr, $human_traffic_url);
if ($urlCached !== false) {
//Nothing to do here...
$urlCachedIdx = array_search($human_traffic_url, $humanUrls);
$setIdx = $urlCachedIdx;
} else {
if ($humanUrlStr === null) {
//Set human_url_id to 0 & no comma for first entry
$options['human_url_id'] = $currHumanUrlIdNum - 1;
$options['human_url'] = $human_traffic_url;
$setIdx = $currHumanUrlIdNum - 1;
} else {
//Set human_url_id to current if new but not first
$options['human_url_id'] .= ','.$currHumanUrlIdNum;
$options['human_url'] .= ','.$human_traffic_url;
$setIdx = $currHumanUrlIdNum;
}
update_option( 'wp-ellipsis', $options );
}
//Shortcode Output
$captchaUrl = plugins_url( '', __FILE__ ).'/captcha/index.php?ref='.$setIdx;
return "<div id='ellipsis-action-$setIdx$instance_num_value'></div><script>DomReady.ready(function() {var el = document.getElementById('ellipsis-action-$setIdx$instance_num_value');ellipsis.require(['ellipsis'],function(ell){ellResult = ell.checkHumanPresence('$checkKey');if((ellResult.signal != 'HUMAN') || (ellResult.confidence < 95)){el.innerHTML = '<a class=\'$css_class\' href=\'$captchaUrl\'>$link_text</a></div>';}else{el.innerHTML = '<a class=\'$css_class\' href=\'$human_traffic_url\'>$link_text</a>';}});});</script>";
}
}
add_shortcode( 'ellipsis_link', 'ellipsis_link_shortcode' );
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment