*/ 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 = '
'; $out .= ''.$totalitems.' items'; // first if($page>1) { $out.= "" . $firstlabel . "\n"; } else { $out.= "" . $firstlabel . "\n"; } // previous if($page==1) { $out.= "" . $prevlabel . "\n"; } elseif($page==2) { $out.= "" . $prevlabel . "\n"; } else { $out.= "" . $prevlabel . "\n"; } // current $out .=' of '.$tpages.'  '; // next if($page<$tpages) { $out.= "" . $nextlabel . "\n"; } else { $out.= "" . $nextlabel . "\n"; } // last if($page<$tpages) { $out.= "" . $lastlabel . "\n"; } else { $out.= "" . $lastlabel . "\n"; } $out.= "
"; return $out; } /** * To Make Soap Call * * @param unknown_type $wsdl * @param unknown_type $function * @param unknown_type $params * @return unknown */ function getsoapCall($wsdl,$function,$params) { $client = new SoapClient($wsdl); try { $response = $client->__soapCall($function, array($params)); }catch(Exception $e){ return 'E_100'; } return $response; } /** * LoadMemCache Methods. * * @param unknown_type $wsdl * @param unknown_type $key_publishdate * @param unknown_type $plugincall_key * @param unknown_type $method_publishdate * @param unknown_type $plugincall_function * @param unknown_type $publishdate_params * @param unknown_type $plugincall_params * @return unknown */ /** * get ApptiovWordPress(awp) Templates * * @param unknown_type $dir * @param unknown_type $type == 'widget' => "Widget Templates" , $type == 'plugin' => "Plugin templates" * @return Template Array Lists. */ function get_awpTemplates($dir,$type) { $default_headers = array( 'Template Name' => 'Template Name', 'Template Type' => 'Template Type' ); $templates = array(); $dir_news = $dir; // Open a known directory, and proceed to read its contents if (is_dir($dir_news)) { if ($dh = opendir($dir_news)) { while (($file = readdir($dh)) !== false) { if ( substr( $file, -4 ) == '.php' ) { $plugin_data = get_file_data( $dir_news."/".$file, $default_headers, '' ); if(strlen(trim($plugin_data['Template Name'])) != 0 ) { if(strtolower(trim($plugin_data['Template Type'])) == 'widget' && strtolower($type) == 'widget' ) { $templates[$plugin_data['Template Name']] = $file; }else if(strtolower(trim($plugin_data['Template Type'])) == 'shortcode' && strtolower($type) == 'plugin') { $templates[$plugin_data['Template Name']] = $file; }else if(strtolower(trim($plugin_data['Template Type'])) == 'inline' && strtolower($type) == 'inline') { $templates[$plugin_data['Template Name']] = $file; } } } } closedir($dh); } } return $templates; } /** * Remove html tags from string * * @param string $str * @return string */ function html_remove($str){ return $str; return preg_replace("/<[^>]*>/","",$str); } /** * Convert Object to array. * * @param unknown_type $objectValue * @return unknown */ function awp_convertObjToArray($objectValue) { if(!empty($objectValue)){ if(is_array($objectValue)) { $arrayValue = $objectValue; } else { $arrayValue = array(); array_push($arrayValue,$objectValue); } return $arrayValue; } } /** * * @param $wsdl * @param string $publishdate_key * @param string $plugincall_key * @param $publishdate_function * @param $plugincall_function * @param $publishdate_params * @param $plugincall_params * @return */ function get_data($wsdl,$publishdate_key,$plugincall_key,$publishdate_function,$plugincall_function,$publishdate_params,$plugincall_params) { $cache_obj = new AWP_Cache_Util(); //Create Object in AWP_DataCache class $response = $cache_obj->get_data($wsdl, $publishdate_key, $plugincall_key, $publishdate_function, $plugincall_function, $publishdate_params, $plugincall_params); return $response; } /** * Recursive creates directory * * @param string $path * @param integer $mask * @param string * @return boolean */ function awp_mkdir($path, $mask = 0755, $curr_path = '') { $path = awp_realpath($path); $path = trim($path, '/'); $dirs = explode('/', $path); foreach ($dirs as $dir) { if ($dir == '') { return false; } $curr_path .= ($curr_path == '' ? '' : '/') . $dir; if (!@is_dir($curr_path)) { if (@mkdir($curr_path, $mask)) { @chmod($curr_path, $mask); } else { return false; } } } return true; } /** * Recursive remove dir * * @param string $path * @param array $exclude * @return void */ function awp_rmdir($path, $exclude = array(), $remove = true) { $dir = @opendir($path); if ($dir) { while (($entry = @readdir($dir)) !== false) { $full_path = $path . '/' . $entry; if ($entry != '.' && $entry != '..' && !in_array($full_path, $exclude)) { if (@is_dir($full_path)) { awp_rmdir($full_path, $exclude); } else { @unlink($full_path); } } } @closedir($dir); if ($remove) { @rmdir($path); } } } /** * Recursive empty dir * * @param string $path * @param array $exclude * @return void */ function awp_emptydir($path, $exclude = array()) { awp_rmdir($path, $exclude, false); } /** * Returns realpath of given path * * @param string $path */ function awp_realpath($path) { $path = awp_path($path); $parts = explode('/', $path); $absolutes = array(); foreach ($parts as $part) { if ('.' == $part) { continue; } if ('..' == $part) { array_pop($absolutes); } else { $absolutes[] = $part; } } return implode('/', $absolutes); } /** * Converts win path to unix * * @param string $path * @return string */ function awp_path($path) { $path = preg_replace('~[/\\\]+~', '/', $path); $path = rtrim($path, '/'); return $path; } //Label Field function awp_labelfield($field='',$class='contactform_field_label',$before='',$after='') { $fieldid=$field['fieldid']; $showtext=$field['showtext']; return $before.''.$after; } function awp_jobsearch_textfield ($field='',$class='',$before='',$after='') { $fieldid = $field['fieldid']; $showtext = $field['showtext']; $required = $field['required']; $fieldtype = $field['type']; $options = $field['options']; switch( $fieldid ) { case "keywords" : $html = ''; break; case "customfield1" : if($fieldtype == 'select') : $html .= ''; endif; break; case "customfield2" : if($fieldtype == 'checkbox') : foreach($options as $opt_val) { $opt_value = strtoupper(trim($opt_val)); $opt_value = str_replace(" ","_",$opt_value); $html .= '   
'; } endif; if($fieldtype == 'select') : $html .= ''; endif; break; } return $html; } /** * Enter description here... * * @param unknown_type $forms * @param unknown_type $field * @param unknown_type $countries * @param Bollean $value_present * @param unknown_type $before * @param unknown_type $after * @return unknown */ function awp_textfield($forms='',$field='',$countries='',$value_present='',$before='',$after='',$placeholder=false, $tabindex='') { $fieldid=$field['fieldid']; $showtext=$field['showtext']; $validation=$field['validation']; $required=$field['required']; $fieldtype=$field['type']; $options=$field['options']; $optionvalues=array(); $place_text = ''; if($placeholder) { $place_text = 'placeholder="'.$showtext.'"'; } if($fieldtype=="select" || $fieldtype=="radio" || $fieldtype=="checkbox" ){ if(trim($fieldid) == 'industry') { $optionvalues=$options; $fieldtype = 'select'; } else if(trim($options)!=""){ $optionvalues=preg_split("[\n]",trim($options));//Split the String line by line. } } if ($value_present) : $postValue = $_REQUEST[$fieldid]; else : $postValue=""; endif; //Required Class if($required){ $mandate_property='"mandatory="true"'; $validateclass=" required"; } else{ $mandate_property=""; $validateclass=""; } //Field Validation Class switch($validation) { case "email": $validateclass .=" email"; break; case "url": $validateclass .=" url"; break; case "number": $validateclass .=" number"; break; } //Captcha Class if($fieldid=='captcha') { $captcha_class = 'captcha'; } else{ $captcha_class = ''; } switch($fieldtype) { case "text": $html = ''; break; case "textarea": $html = ''; break; case "select": if($fieldid == 'country'){ $html = ''; } else if($fieldid == 'industry') { if(!empty($optionvalues)) { $html .= ''; }else { $html .= ''; } } else{ $html = ''; } break; case "radio": $i=0;$opt=0; foreach( $optionvalues as $optionvalue ) { if(trim($postValue) == trim($optionvalue)){ $selected='checked="checked"'; } else{ $selected = ""; } if(!empty($optionvalue) && strlen(trim($optionvalue)) != 0) { if($i>0) $html .=' '; $html .=''; } $opt++; } break; case "checkbox": $i=0;$opt=0; foreach( $optionvalues as $optionvalue ) { $selected =""; foreach($postValue as $value){ if(trim($value) == trim($optionvalue)){ $selected='checked="checked"'; } } if(!empty($optionvalue) && strlen(trim($optionvalue)) != 0) { if($i>0) $html .=' '; $html.=''; $i++;$opt++; } } break; case "captcha": $html ='
'; break; case "file": $html =''; $html.= ''; break; } return $before.$html.$after; } /** * SubMit Button Type * * @param array $contactform * @return html field(form submit type) */ function awp_submit_type($forms='',$form_submitname='',$class='',$before='',$after='', $tabindex) { if(strlen(trim($form_submitname)) != 0 ) : $html =''; endif; if($forms[submit_button_type] == "submit" ){ if(strlen(trim($forms[submit_button_val])) != 0) { $value = $forms[submit_button_val]; }else { $value = 'Submit'; } $button_value = 'value="'.$value.'"'; } else{ if(strlen(trim($forms[submit_button_val])) == 0) { $imgSrc = awp_image('submit_button'); }else { $imgSrc = $forms[submit_button_val]; } $button_value = 'src="'.$imgSrc.'"'; } $html .= ''; return $before.$html.$after; } /** * Enter description here... * * @param unknown_type $forms * @param unknown_type $field * @param unknown_type $countries * @param Bollean $value_present * @param unknown_type $before * @param unknown_type $after * @return unknown */ function cases_textfield($forms='',$field='',$countries='',$value_present='',$before='',$after='',$placeholder=false, $tabindex='',$dafaultselect=false,$plugin='',$postValue,$caseForm) { echo $before; $getConfig=get_option('awp_casesforms'); for($i=0;$i'; break; case "textarea": echo ''; break; case "select": if(_isCurl()) { if($fieldid=="priority" || $fieldid=="type" || $fieldid=="status") { if($fieldid=="priority") { $configValues= $selectedCValues["awp_casePriority_selected"]; $input_text=''; } elseif($fieldid=="type") { $input_text=""; $configValues= $selectedCValues["awp_caseType_selected"]; $input_text=''; } elseif($fieldid=="status") { $input_text=""; $configValues= $selectedCValues["awp_caseStatus_selected"]; $input_text=''; } echo ''; echo $input_text; } else { echo ''; } } else { echo ''; } break; case "radio": $i=0;$opt=0; foreach( $optionvalues as $optionvalue ) { if(trim($postValue[$fieldid]) == trim($optionvalue)){ $selected='checked="checked"'; } else{ $selected = ""; } if(!empty($optionvalue) && strlen(trim($optionvalue)) != 0) { echo '
'; } $opt++; } break; case "checkbox": $i=0;$opt=0; foreach( $optionvalues as $optionvalue ) { $selected =""; if(isset($postValue)!="" && count($postValue) >1) { if(isset($postValue[$fieldid])){ foreach($postValue[$fieldid] as $value){ if(trim($value) == trim($optionvalue)){ $selected='checked="checked"'; } } } } if(!empty($optionvalue) && strlen(trim($optionvalue)) != 0) { echo '
'; $i++; } $opt++; } break; case "captcha": awp_captcha($fieldid,$postValue,$validateclass); break; case "file": echo ''; echo ''; break; } } echo $after; } function cases_submit_type($forms='',$form_submitname='',$class='',$before='',$after='', $tabindex) { $html=""; if($forms['submit_button_type'] == "submit" ){ if(strlen(trim($forms['submit_button_val'])) != 0) { $value = $forms['submit_button_val']; }else { $value = 'Submit'; } $button_value = 'value="'.$value.'"'; } else{ if(strlen(trim($forms['submit_button_val'])) == 0) { $imgSrc = awp_image('submit_button'); }else { $imgSrc = $forms['submit_button_val']; } $button_value = 'src="'.$imgSrc.'"'; } $html .= ''; return $before.$html.$after; } /** * Create Label Fields * * @param unknown_type $showtext * @param unknown_type $customtext * @param unknown_type $class * @param unknown_type $before * @param unknown_type $after * @return unknown */ function awp_create_labelfield($showtext='',$customtext='',$class='',$before='',$after='',$fieldid='') { if($showtext == '' || strlen(trim($showtext)) == 0) : $showtext = $customtext; endif; return $before.''.$showtext.''.$after; } function awp_create_textfiled($type='',$fieldid='',$class='',$before='',$after='') { switch(strtolower($type)) { case "checkbox" : $html = $before.''.$after; break; } return $html; } //Mandatory Field. function awp_mandatoryfield($field='',$before='',$after='',$mandatory_symbol = '*') { if(isset($field['required'])){ $required=$field['required']; if($required): return $before.$mandatory_symbol.$after; endif; } } //Powered By Apptivo. function poweredby_apptivo() { $apptivo_logo = ' Apptivo.com is the best free way to run your business. Apptivo.com powers ecommerce websites, provides free CMS, free CRM, free ERP, free Project Management and free Invoicing to small businesses. '; 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 "
"; echo recaptcha_get_html($option->recaptcha_publickey); echo "
"; return; } } else { echo '
Please Enable reCaptcha in Plugin Settings.
'; return; } } /* Get Captcha Response */ function captchaValidation($privatekey,$response_field) { require_once(AWP_ASSETS_DIR.'/captcha/recaptchalib.php'); $resp = recaptcha_check_answers ($privatekey, $_SERVER["REMOTE_ADDR"], $response_field); if (!$resp->is_valid) { $response= $resp->error; } else{ $response =$resp->is_valid; } return $response; } /* Check's Captcha if enabled or disabled */ function checkCaptchaOption() { if(get_option ('apptivo_business_recaptcha_mode')!="yes") { echo ''; } else if(get_option ('apptivo_business_recaptcha_mode')=="yes") { echo ''; } } /* Create Lead Source */ function CreateContactFormLeads($sourceName,$leadSources) { /* checking the leadsource from configData */ $checkLead = "notpresent"; $response= new stdClass(); foreach($leadSources as $leadSource){ if( trim(strtoupper($sourceName)) == trim(strtoupper($leadSource->name))){ $checkLead = "present"; } } if($checkLead=="present") { $leadSource = "present"; return $leadSource; } if($checkLead=="notpresent" && $checkLead!='') { $details='{"name":"'.$sourceName.'","emailId":"","description":"'.$sourceName.'"}'; $params = array ( "a" =>"createLeadSource", "leadSource"=>$details, "apiKey"=> APPTIVO_BUSINESS_API_KEY, "accessKey"=> APPTIVO_BUSINESS_ACCESS_KEY ); $respone=getRestAPICall("POST",APPTIVO_APPSETTINGS_V5_API,$params); return $respone; } } function checkSoapextension($currentOption) { if (!extension_loaded('soap')) { echo '

SOAP extension required to run Apptivo Business Site CRM plugin- ' . $currentOption . '.

' ; exit; // echo ''; } } function getDomain($url){ $pieces = parse_url($url); $domain = isset($pieces['host']) ? $pieces['host'] : ''; if(preg_match('/(?P[a-z0-9][a-z0-9\-]{1,63}\.[a-z\.]{2,6})$/i', $domain, $regs)){ return $regs['domain']; } return FALSE; } function sendRegisterationEmailToUser($fname,$phoneNumber,$lname,$email){ $adminEmail = get_option('admin_email'); $mailsubject = "Apptivo Newsletter form signup"; $to = $email; $protocol=strpos(strtolower($_SERVER['SERVER_PROTOCOL']),'https') === FALSE ? 'http' : 'https'; $url = $protocol .'://' . $_SERVER['SERVER_NAME']; $domain = getDomain($url); $msg = '

Hi There,

Newsletter subscribed sucessfully

 

Thanks,

'.$domain.'

'; $headers = "MIME-Version: 1.0" . "\r\n"; $headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n"; $headers .= 'From: <'.$adminEmail . ">\r\n"; $headers .='Reply-To: no-reply@'.$domain. "\r\n" ; mail($to, $mailsubject, $msg, $headers); } function sendRegisterationEmailToAdmin($fname,$phoneNumber,$lname,$email){ $adminEmail = get_option('admin_email'); $protocol=strpos(strtolower($_SERVER['SERVER_PROTOCOL']),'https') === FALSE ? 'http' : 'https'; $url = $protocol .'://' . $_SERVER['SERVER_NAME']; $domain = getDomain($url); $From = 'noreply@'.$domain; $mailsubject = "Newsletter signup notification ".$fname.' '.$lname; //$to = $adminEmail; $to = trim($adminEmail); $msg = '

Hi There,

'.$email.' is subscribed for Newsletter

 

Thanks,

'.$domain.'

'; $headers = "MIME-Version: 1.0" . "\r\n"; $headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n"; $headers .= 'From: <'.$adminEmail . ">\r\n"; $headers .='Reply-To: no-reply@'.$domain. "\r\n" ; mail($adminEmail, $mailsubject, $msg, $headers); } /** * Create TargetLists. * * @param unknown_type $category * @param unknown_type $fname * @param unknown_type $lname * @param unknown_type $email * @param unknown_type $userId * @return unknown */ function createTargetList($category,$fname,$lname,$email,$phoneNumber,$comments,$notesLabel,$userId=null) { $target_category = target_lists_category(trim($category)); if(trim($category) != $target_category ) { return $target_category; } $verification = check_blockip(); if($verification){ return $verification; } $targetParams='{"firstName":"'.$fname.'","phoneNumbers": [{"id": "contact_phone_input","phoneType": "Business","phoneTypeCode": "PHONE_BUSINESS","phoneNumber": "'.$phoneNumber.'"}],"lastName":"'.$lname.'","jobTitle":"","emailAddresses": [{"id": "cont_email_input","emailType": "Business","emailTypeCode": "BUSINESS","emailAddress": "'.$email.'"}]}'; $params = array ( "a" => "createTarget", "idxTarget" => $targetParams, "targetListId" => $category, "apiKey"=> APPTIVO_BUSINESS_API_KEY, "accessKey"=> APPTIVO_BUSINESS_ACCESS_KEY ); $response=getRestAPICall("POST", APPTIVO_TARGETS_V6_API,$params); if(isset($response) && $response->responseObject->id !=''){ sendRegisterationEmailToAdmin($fname,$phoneNumber,$lname,$email); sendRegisterationEmailToUser($fname,$phoneNumber,$lname,$email); $targetId=$response->responseObject->id; if($comments !=''){ $awpServiceObj=new AWPAPIServices(); $objectId = APPTIVO_TARGET_OBJECT_ID; $objRefId = $targetId; $objectRefName = $response->responseObject->firstName .' '.$response->responseObject->lastName; $awpServiceObj->createTargetListNotes($comments,$notesLabel,$targetId,$objectId,$objRefId,$objectRefName); } } return $response; } function getAllTargetList(){ $params = array ( "a" => "getAllTargetLists", "startIndex" => 0, "numRecords" => 50, "sortColumn"=>'name', "sortDir"=>'asc', "iDisplayStart"=>0, "iDisplayLength"=>50, "sSortDir_0"=>'asc', "selectedLetter"=>'All', "type"=> 'by-directory', "typeId"=>'All', "objectId"=>APPTIVO_TARGET_OBJECT_ID, "apiKey"=> APPTIVO_BUSINESS_API_KEY, "accessKey"=> APPTIVO_BUSINESS_ACCESS_KEY ); $response=getRestAPICall("POST", APPTIVO_TARGETS_V6_API,$params); return $response; } /* * * To get Current Browser */ function get_current_browser() { if(isset($_SERVER['HTTP_USER_AGENT'])){ $agent = $_SERVER['HTTP_USER_AGENT']; } if(strlen(strstr($agent,"Firefox")) > 0 ){ $browser = 'firefox'; } else if(strlen(strstr($agent,"Chrome")) > 0 ){ $browser = 'chrome'; } else { $browser = 'other'; } return $browser; } /* Simple Captcha Integration */ function awp_simple_captcha($fieldid,$postValue,$validateclass,$fg_color,$bg_color) { $captcha_instance = new AWPSimpleCaptcha(); list($r, $g, $b) = sscanf($fg_color, "#%02x%02x%02x"); $captcha_instance->fg = array($r,$g,$b); list($bg_r, $bg_g, $bg_b) = sscanf($bg_color, "#%02x%02x%02x"); $captcha_instance->bg = array( $bg_r,$bg_g,$bg_b ); $word = $captcha_instance->generate_random_word(); $prefix = mt_rand(); $image=$captcha_instance->generate_image($prefix, $word ); $awp_upload_url=wp_upload_dir(); $awp_url=path_join( $awp_upload_url['baseurl'], 'awp_captcha' ); echo '   '; } /* CleanUp All unwanted Captcha Images */ add_action( 'template_redirect', 'awp_captcha_cleanup' ); function awp_captcha_cleanup(){ $captcha_instance = new AWPSimpleCaptcha(); $captcha_instance->cleanup(60); } function awp_captcha($fieldid, $postValue, $validateclass) { $option = get_option('apptivo_business_recaptcha_settings'); $option = json_decode($option); $fg_color = $option->awp_fg_color; $bg_color = $option->awp_bg_color; if ($option->awp_captcha_type == 'recaptcha') { awp_reCaptcha(); } elseif ($option->awp_captcha_type == 'simplecaptcha') { awp_simple_captcha($fieldid, $postValue, $validateclass, $fg_color, $bg_color); } } /* * Call occur when fatal error occurs in site. * */ register_shutdown_function( "absp_fatal_error_handler" ); function absp_fatal_error_handler() { $errfile = "unknown file"; $errstr = "shutdown"; $errno = E_CORE_ERROR; $errline = 0; $error = error_get_last(); if( $error !== NULL) { $errno = $error["type"]; $errfile = $error["file"]; $errline = $error["line"]; $errstr = $error["message"]; } absp_show_error_log($errno, $errfile, $errline, $errstr); } function absp_show_error_log($errorno,$file,$line,$message) { absp_currentError($message); } function absp_currentError($message) { if(strpos($message, "SOAP-ERROR: Parsing WSDL: Couldn't load")!=false || strpos($message, "Maximum execution time of 30 seconds exceeded")!=false || strpos($message, "SoapClient::SoapClient()")!=false) { echo awp_messagelist("fatal_error").' ' ; echo ''; } } /* * Check the option and add or update option. */ function check_option($option_name,$option_value) { $get= get_option($option_name); if($get=="") { add_option($option_name,$option_value); } else { update_option($option_name, $option_value); } } /* * Apptivo REST API CALL */ if (!function_exists('_isCurl')) { function _isCurl() { return function_exists('curl_version'); } } if (!function_exists('getRestAPICall')) { function getRestAPICall($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' ); }