| Server IP : 68.183.124.220 / Your IP : 216.73.216.141 Web Server : Apache/2.4.18 (Ubuntu) System : Linux Sandbox-A 4.4.0-210-generic #242-Ubuntu SMP Fri Apr 16 09:57:56 UTC 2021 x86_64 User : gavin ( 1000) PHP Version : 7.0.33-0ubuntu0.16.04.16 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority, MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /var/www/html/wp-content/plugins/ajax-search-lite/includes/classes/suggest/ |
Upload File : |
<?php
/* Prevent direct access */
defined('ABSPATH') or die("You can't access this file directly.");
if (!class_exists('wpd_googleKeywordSuggest')) {
/**
* Google keyword suggestion class
*
* @class wpd_googleKeywordSuggest
* @version 1.2
* @package AjaxSearchLite/Classes
* @category Class
* @author Ernest Marcinko
*/
class wpd_googleKeywordSuggest extends wpd_keywordSuggestAbstract {
private $lang, $matchStart, $url;
function __construct( $args = array() ) {
$defaults = array(
'maxCount' => 10,
'maxCharsPerWord' => 25,
'lang' => "en",
'overrideUrl' => '',
'match_start' => false
);
$args = wp_parse_args( $args, $defaults );
$this->maxCount = $args['maxCount'];
$this->maxCharsPerWord = $args['maxCharsPerWord'];
$this->lang = $args['lang'];
$this->matchStart = $args['match_start'];
if ($args['overrideUrl'] != '') {
$this->url = $args['overrideUrl'];
} else {
$this->url = 'http://suggestqueries.google.com/complete/search?output=toolbar&oe=utf-8&client=toolbar&hl=' . $this->lang . '&q=';
}
}
function getKeywords($q) {
$qf = str_replace(' ', '+', $q);
$method = $this->can_get_file();
if ($method == false) {
return array('Error: The fopen url wrapper is not enabled on your server!');
}
$_content = $this->url_get_contents($this->url . rawurlencode($qf), $method);
if ($_content == null || $_content == "") return array();
if (function_exists('mb_convert_encoding'))
$_content = mb_convert_encoding($_content, "UTF-8");
try {
$xml = simplexml_load_string($_content);
if ($xml == null || $xml === '') return array();
$json = json_encode($xml);
$array = json_decode($json, TRUE);
$res = array();
$keywords = array();
if (isset($array['CompleteSuggestion'])) {
foreach ($array['CompleteSuggestion'] as $k => $v) {
if (isset($v['suggestion']))
$keywords[] = $v['suggestion']['@attributes']['data'];
elseif (isset($v[0]))
$keywords[] = $v[0]['@attributes']['data'];
}
}
foreach ($keywords as $keyword) {
$t = strtolower($keyword);
if (
$t != $q &&
('' != $str = wd_substr_at_word($t, $this->maxCharsPerWord))
) {
if ($this->matchStart && strpos($t, $q) === 0)
$res[] = $str;
elseif (!$this->matchStart)
$res[] = $str;
}
}
$res = array_slice($res, 0, $this->maxCount);
if (count($res) > 0)
return $res;
else
return array();
} catch(Exception $e) {
return array();
}
}
}
}