*/ require_once dirname(__FILE__) . '/config.php'; //API Key and Access Keys Settings. $eCommerce_api_Key = get_option('apptivo_ecommerce_apikey'); $eCommerce_access_key = get_option('apptivo_ecommerce_accesskey'); $business_site_key = get_option('apptivo_sitekey'); if(!empty($eCommerce_api_Key) ) { update_option('apptivo_apikey',$eCommerce_api_Key); update_option('apptivo_accesskey',$eCommerce_access_key); }else if(!empty($business_site_key)) { update_option('apptivo_apikey',$business_site_key); delete_option('apptivo_sitekey'); } $apptivo_api_key = get_option('apptivo_apikey'); $apptivo_accesskey = get_option('apptivo_accesskey'); define('APPTIVO_BUSINESS_API_KEY',trim($apptivo_api_key)); define('APPTIVO_BUSINESS_ACCESS_KEY',trim($apptivo_accesskey)); /** * Loads plugins * * @return void */ function awp_load_plugins() { ob_start(); //include Plugin Files. $plugin_dir = @opendir(AWP_PLUGINS_DIR); if ($plugin_dir) { while (($entry = @readdir($plugin_dir)) !== false) { if (strrchr($entry, '.') === '.php') { require_once AWP_PLUGINS_DIR . '/' . $entry; } } @closedir($plugin_dir); } } /** * Load Widgets * */ function awp_load_widgets() { //include widget files $widget_dir = @opendir(AWP_WIDGETS_DIR); if ($widget_dir) { while (($entry = @readdir($widget_dir)) !== false) { if (strrchr($entry, '.') === '.php') { require_once AWP_WIDGETS_DIR . '/' . $entry; } } @closedir($widget_dir); } } /** * Recursive strips slahes from the var * * @param mixed $var * @return mixed */ function awp_stripslashes($var) { if (is_string($var)) { return stripslashes($var); } elseif (is_array($var)) { $var = array_map('awp_stripslashes', $var); } return $var; } /** * Sort customformfields by order */ function awp_sort_by_order($a, $b) { if(is_array($a) && is_array($b)) { return $a["order"] - $b["order"]; } else { return; } } /** * Search for value using key in multi-dimensional array * returns index if value found * returns false if no value is found */ function awp_recursive_array_search($haystack, $needle, $index = null) { $aIt = new RecursiveArrayIterator($haystack); $it = new RecursiveIteratorIterator($aIt); while($it->valid()) { if (((isset($index) AND ($it->key() == $index)) OR (!isset($index))) AND ($it->current() == $needle)) { return $aIt->key(); } $it->next(); } return false; } /** * Add contact form scripts and styles, only when short code is present in page/posts */ function awp_check_for_shortcode($posts,$shortcode) { if ( empty($posts) ) return $posts; // false because we have to search through the posts first $found = false; // search through each post foreach ($posts as $post) { // check the post content for the short code if ((stripos($post->post_content, $shortcode))!==false) { // we have found a post with the short code $found = true; } // stop the search break; } return $found; } /** * Converts value to boolean * * @param mixed $value * @return boolean */ function awp_to_boolean($value) { if (is_string($value)) { switch (strtolower($value)) { case '+': case '1': case 'y': case 'on': case 'yes': case 'true': case 'enabled': return true; case '-': case '0': case 'n': case 'no': case 'off': case 'false': case 'disabled': return false; } } return (boolean) $value; } function awp_date_compare($a, $b) { $t1 = strtotime($a['datetime']); $t2 = strtotime($b['datetime']); return $t1 - $t2; } function awp_creation_date_compare($a, $b) { $t1 = $a->creationDate; $t2 = $b->creationDate; return $t1 - $t2; } function awp_sort_by_sequence($a, $b) { return $a->sequenceNumber - $b->sequenceNumber; } /** * Pagination * * @param unknown_type $reload * @param unknown_type $page * @param unknown_type $tpages * @return unknown */ function awp_paginate($reload, $page, $tpages,$totalitems) { $firstlabel = "<<"; $prevlabel = "<"; $nextlabel = ">"; $lastlabel = ">>"; $out = '
';
return $apptivo_logo;
}
/*
* To Get Case Status, Case Type and Case Priority
*
*/
function getAllCasesConfigData()
{
$params = array (
"a" => "getCasesConfigData",
"apiKey" => APPTIVO_BUSINESS_API_KEY,
"accessKey" => APPTIVO_BUSINESS_ACCESS_KEY
);
$response=getRestAPICall("POST",APPTIVO_CASES_API,$params);
return $response;
}
/*
* To Get Case Status, Case Type and Case Priority V6 API
*
*/
function getCasesConfigData()
{
$params = array (
"a" => "getConfigData",
"apiKey" => APPTIVO_BUSINESS_API_KEY,
"accessKey" => APPTIVO_BUSINESS_ACCESS_KEY
);
$response=getRestAPICall("POST",APPTIVO_CASE_V6_API,$params);
return $response;
}
/*
* To Get Case Status, Case Type and Case Priority V6 API
*
*/
function getAllEmployeesAndTeams()
{
$params = array (
"a" => "getAllEmployeesAndTeams",
"apiKey" => APPTIVO_BUSINESS_API_KEY,
"accessKey" => APPTIVO_BUSINESS_ACCESS_KEY
);
$response=getRestAPICall("POST",APPTIVO_EMPLOYEES_V6_API,$params);
return $response;
}
/*
* To Get Case Auto Generation Number, Case Assignee and Employee
*
*/
function getCaseConfigureData()
{
$params = array (
"a" => "getCaseConfigureData",
"apiKey" => APPTIVO_BUSINESS_API_KEY,
"accessKey" => APPTIVO_BUSINESS_ACCESS_KEY
);
$response=getRestAPICall("POST",APPTIVO_CASES_API,$params);
return $response;
}
/*
* To Get Contact Status, Contact Type and Contact Priority
*
*/
function getAllContactConfigData()
{
$params = array (
"a" => "getLeadConfigData",
"apiKey" => APPTIVO_BUSINESS_API_KEY,
"accessKey" => APPTIVO_BUSINESS_ACCESS_KEY
);
$response=getRestAPICall("POST",APPTIVO_LEAD_API,$params);
return $response;
}
/*
* To Get Contact Status, Contact Type and Contact Priority - V6 API
*
*/
function getContactConfigData()
{
$params = array (
"a" => "getConfigData",
"apiKey" => APPTIVO_BUSINESS_API_KEY,
"accessKey" => APPTIVO_BUSINESS_ACCESS_KEY
);
$response=getRestAPICall("POST",APPTIVO_LEAD_V6_API,$params);
return $response;
}
/* Generate Captcha */
function awp_reCaptcha()
{
if(get_option ('apptivo_business_recaptcha_mode')=="yes")
{
$option=get_option('apptivo_business_recaptcha_settings');
$option=json_decode($option);
if($option->recaptcha_publickey!= "" && $option->recaptcha_privatekey!="")
{
echo "
";
require_once AWP_ASSETS_DIR.'/captcha/recaptchalib.php';
echo "SOAP extension required to run Apptivo Business Site CRM plugin- ' . $currentOption . '.
";print_r($result);exit;
return $result;
}
}
function getRestAPICallCurl($method, $url, $data = false) {
$proxysettings = array();
$proxysettings = get_option('awp_proxy_settings');
if (!_isCurl()) {
echo 'CURL disabled in your server. please enable through php.ini';
exit;
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, Array("Content-Type: application/x-www-form-urlencoded;charset=utf-8"));
if ($method == "POST") {
curl_setopt($ch, CURLOPT_POST, 1);
if ($data) {
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
}
} else {
if ($data)
$url = sprintf("%s?%s", $url, http_build_query($data));
}
curl_setopt($ch, CURLOPT_URL, $url);
if (isset($proxysettings['proxy_enable'])) {
if (isset($proxysettings['proxy_hostname_portno'])) {
curl_setopt($ch, CURLOPT_PROXY, $proxysettings['proxy_hostname_portno']);
}
if (isset($proxysettings['proxy_loginuser_pwd'])) {
curl_setopt($ch, CURLOPT_PROXYUSERPWD, $proxysettings['proxy_loginuser_pwd']);
}
}
if(TLSV2_SUPPORT){
curl_setopt($ch, CURLOPT_SSLVERSION,'CURL_SSLVERSION_TLSv1_2');
}
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
$response = curl_exec($ch);
curl_close($ch);
$result = json_decode($response);
return $result;
}
/*
* To alert the user running under curl
*/
if(TLSV2_SUPPORT == false){
if (!function_exists('Apptivo_plugin_notice_error')) {
function Apptivo_plugin_notice_error() {
$version = curl_version();
$class = 'notice notice-error';
$message = __( 'Apptivo Notification: We found that you are running older version of CURL (Older version: '.$version[version].') which does not support TLS 1.2. Apptivo stops supporting API calls older than TLS 1.2. Read http://www.apptivo.com/blog/disabling-ssl-3-0-and-tls-1-1/ for more details', 'sample-text-domain' );
printf( '%2$s
', $class, $message );
}
}
add_action( 'admin_notices', 'Apptivo_plugin_notice_error' );
}