GoogleKS_getSuggestion

Ajax call to determine suggestions.

Description

GoogleKS_getSuggestion(); 

Usage

  1. if ( !function_exists( 'GoogleKS_getSuggestion' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'google-keyword-suggest/ajax.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = GoogleKS_getSuggestion(); 
  7.  

Defined (1)

The function is defined in the following location(s).

/ajax.php  
  1. function GoogleKS_getSuggestion() { 
  2. // collect data from AJAX request via POST 
  3. $l_str_Language = array_key_exists("lang", $_POST) ? $_POST["lang"] : ""; 
  4. $l_str_Country = array_key_exists("cr", $_POST) ? $_POST["cr"] : ""; 
  5. $l_str_Keyword = array_key_exists("keyword", $_POST) ? utf8_encode(urlencode(trim($_POST['keyword']))) : ""; 
  6.  
  7. // abort if a requested value is empty, return an empty string to clear the current list 
  8. if (empty($l_str_Language) || empty($l_str_Country) || empty($l_str_Keyword)) { 
  9. echo '<li>' . __("Bad request. Please fill in all input fields.", GOOGLE_KS_INTERNAL_PLUGIN_NAME) . '</li>'; 
  10. exit; 
  11. // get response utf8 encoded 
  12. $l_str_Response = getSuggestions($l_str_Keyword, $l_str_Language, $l_str_Country); 
  13.  
  14. // convert response to XML 
  15. /** @var SimpleXMLElement $l_obj_xml */ 
  16. $l_obj_xml = simplexml_load_string($l_str_Response); 
  17.  
  18. if (empty($l_obj_xml)) { 
  19. returnSuggestions('<li>' . sprintf(__("Error reading response from API.", GOOGLE_KS_INTERNAL_PLUGIN_NAME)) . '</li>'); 
  20.  
  21. // iterate through each suggestion 
  22. $l_str_Result = ""; 
  23. foreach($l_obj_xml->CompleteSuggestion as $l_obj_Value) { 
  24. // append suggestion to output list 
  25. $l_str_Result .= '<li>'.$l_obj_Value->suggestion['data'].'</li>'; 
  26. // alert suggestions 
  27. returnSuggestions($l_str_Result);