<?php
ob_start();
class SearchController extends NesoteController
{
	function redirAction()
	{
		if(isset($_POST['search2']))
		$search2=$_POST['search2'];
		else
		$search2=$_GET['search2'];
		if(isset($_POST['search3']))
		$search3=$_POST['search3'];
		else
		$search3=$_GET['search3'];
		if(isset($_POST['search3']))
		$search4=$_POST['search4'];
		else
		$search4=$_GET['search4'];
		if($search2=="Enter Country")
		{
			$search2="";
			$search3="";
			$search4="";
			$additional="";
		}
		else
		{
			if($search3=="Enter State")
			$search3="";
			if(($search4=="Enter City")||($search3==""))
			$search4="";
			$additional="";
			if($search2!="")
			$additional.="&search2=".$search2;
			if($search3!="")
			$additional.="&search3=".$search3;
			if($search4!="")
			$additional.="&search4=".$search4;
		}
		if(isset($_POST['type']))
		$type=$_POST['type'];
		else
		$type=$_GET['type'];
		if(isset($_POST['search']))
		$searchkeyword=trim($_POST['search']);
		else
		$searchkeyword=trim($_GET['search']);
		if($type=="")
		$type="web";
		if(isset($_POST['lucky']))
		{
			if($_POST['lucky']!="")
			$feelinglucky=1;
			else
			$feelinglucky=0;
		}
		else
		$feelinglucky=0;
		$quotestatus=get_magic_quotes_gpc();
		if($quotestatus==1)
		$keyword=stripslashes($searchkeyword);
		else
		$keyword=$searchkeyword;
		$db= new NesoteDALController();
		$db->select("nesote_inoutse_engines");
		$db->fields("id,search_type,special_status");
		$db->where("tab_name=?",$type);
		$result=$db->query();
		$row=$db->fetchRow($result);
		if(isset ($_POST['searchstatus']))
		{
			if($_POST['searchstatus']=="no")
			{
				if($mod_rewrite==true)
				header("Location:".$this->url("search/noresults?search=".urlencode($keyword)."&type=web"));
				else
				header("Location:".$this->url("search/noresults&search=".urlencode($keyword)."&type=web"));
				exit(0);
			}
		}
		if(trim($keyword)!="")
		{
			{
			    $db->insert("nesote_inoutse_logs");
				$db->fields("engine_id,keyword,time");
				$db->values(array($row[0],$keyword,time()));
				$db->query();
				$id=$db->lastInsertid("nesote_inoutse_logs");
			}
				$db->insert("nesote_inoutse_logs_region");
				$db->fields("log_id,region");
				$db->values(array($id,$region));
				$db->query();
		}
		include('script.inc.php');
		include($config_path.'system.config.php');
		$keyword=urlencode($keyword);
		if($mod_rewrite==true)
		{
			if($keyword=="")
			{
				header("Location:".$this->url("index/index?type=$type".$additional));
				exit(0);
			}
			else
			{
				header("Location:".$this->url("search/$row[1]?search=".$keyword."&type=$type&fl=$feelinglucky".$additional));
				exit(0);
			}
		}
		else
		{
			if($keyword=="")
			{
				header("Location:".$this->url("index/index&type=$type".$additional));
				exit(0);
			}
			else
			{
				header("Location:".$this->url("search/$row[1]&search=$keyword&type=$type&fl=$feelinglucky".$additional));
				exit(0);
			}
		}
		exit(0);
	}
	function getbingAutosuggestAction()
	{   
        if($_POST['keyword']){
			$keyword =trim($_POST['keyword']);
		}
		if(isset ($_COOKIE['region']))
		$region=$_COOKIE['region'];
		else
		// $region="us-en";
		$region=63;
		$db=new NesoteDALController();
		    $db->select("nesote_inoutse_countries");
			$db->fields("google_countrycode");
			$db->where("id=?",$region);
			$result=$db->query();
			$row=$db->fetchRow($result);
			$region=$row[0];
		 $mkt = $region;
		$this->loadLibrary('Settings');
		$settings=new Settings('nesote_inoutse_settings');
		$settings->loadValues();
		$bing_api_key=$settings->getValue("bing_auto_searchsuggestion_api");
		$host = "https://api.cognitive.microsoft.com";
		$path = "/bing/v5.0/Suggestions";
		 echo $result = $this->get_bing_suggestions ($host, $path, $bing_api_key, $mkt, $keyword) ;
		 $auto_suggestion = json_decode($result);
	     exit;
	 } 
	 function get_bing_suggestions ($host, $path, $bing_api_key, $mkt, $keyword) {
		$params = '?mkt=' . $mkt . '&q=' . $keyword;
		$headers = "Content-type: text/json\r\n" .
		  "Ocp-Apim-Subscription-Key: $bing_api_key\r\n";
		$options = array (
		  'http' => array (
			'header' => $headers,
			'method' => 'GET'
		  )
		);
		$context  = stream_context_create ($options);
		$result = file_get_contents ($host . $path . $params, false, $context);
		return $result;
	  }
	function getspellurl($keyword=false,$searchtype=false,$rest_api_status=false,$video_api_status=false)
	{
		if(isset ($_COOKIE['region']))
		$region=$_COOKIE['region'];
		else
		$region="us-en";
		$region=explode("-",$region);
		$this->loadLibrary('Settings');
		$settings=new Settings('nesote_inoutse_settings');
		$settings->loadValues();
		$apikey=$settings->getValue("yahoo_boss_api_key");
		$bing_api_key=$settings->getValue("bing_api_key");
		$source_id=$rowbing[2];
		if($rest_api_status==3)
		$rest_api_status=1;
		if(($searchtype!='videos')&&($rest_api_status==1))
		{
			$spellurl="http://yboss.yahooapis.com/ysearch/spelling";
			$args = array();
			$args["q"] = $keyword;
			$args["format"] = "xml";
			require_once("OAuth.php");
			$this->loadLibrary('Settings');
			$settings=new Settings('nesote_inoutse_settings');
			$settings->loadValues();
			$apikey=$settings->getValue("yahoo_boss_api_key");
			$api_secret=$settings->getValue("yahoo_boss_secret_key");
			$consumer = new OAuthConsumer($apikey, $api_secret);
			$request = OAuthRequest::from_consumer_and_token($consumer, NULL,"GET", $spellurl, $args);
			$request->sign_request(new OAuthSignatureMethod_HMAC_SHA1(), $consumer, NULL);
			$spellurl = sprintf("%s?%s", $spellurl, OAuthUtil::build_http_query($args));
		}
		elseif(($searchtype!='videos')&&($rest_api_status==2))
		{
			$spellurl='https://api.cognitive.microsoft.com/bing/v7.0/search?q='.urlencode($keyword).'&responseFilter=spellsuggestions&mkt='.$region[1].'-'.$region[0].'&count=50';
		}
		elseif(($searchtype=='videos')&&($videos_api_status==1))
		{
			$spellurl="http://yboss.yahooapis.com/ysearch/spelling";
			$args = array();
			$args["q"] = $keyword;
			$args["format"] = "xml";
			require_once("OAuth.php");
			$this->loadLibrary('Settings');
			$settings=new Settings('nesote_inoutse_settings');
			$settings->loadValues();
			$apikey=$settings->getValue("yahoo_boss_api_key");
			$api_secret=$settings->getValue("yahoo_boss_secret_key");
			$consumer = new OAuthConsumer($apikey, $api_secret);
			$request = OAuthRequest::from_consumer_and_token($consumer, NULL,"GET", $spellurl, $args);
			$request->sign_request(new OAuthSignatureMethod_HMAC_SHA1(), $consumer, NULL);
			$spellurl = sprintf("%s?%s", $spellurl, OAuthUtil::build_http_query($args));
		}
		elseif(($searchtype=='videos')&&($videos_api_status==2))
$spellurl='https://api.cognitive.microsoft.com/bing/v7.0/search?q='.urlencode($keyword).'&responseFilter=spellsuggestions&mkt='.$region[1].'-'.$region[0].'&count=50';
		return $spellurl;
	}
	public function queryTestAction()
	{  
		include_once('classes.inc');	
		$db= new NesoteDALController();
		    $content ='{\"item\":[{\"title\":\"The private life of Nita Ambani - Times of India\",\"titleurl\":\"https://timesofindia.indiatimes.com/life-style/spotlight/The-private-life-of-Nita-Ambani/articleshow/10288259.cms\",\"description\":\"QXByIDI0LCAyMDE3IC4uLiBHZXQgdG8ga25vdyBhIGZldyBpbnNpZ2h0cyBhYm91dCBOZWV0YSBBbWJhbmkncyBwZXJzb25hbCBsaWZlLg==\",\"displayurl\":\"timesofindia.indiatimes.com\"},{\"title\":\"The man with all the toys: Why Mukesh Ambani bought Hamleys\",\"titleurl\":\"https://m.economictimes.com/industry/services/retail/the-man-with-all-the-toys-why-mukesh-ambani-bought-hamleys/articleshow/69264824.cms\",\"description\":\"TWF5IDEyLCAyMDE5IC4uLiBXaXRoIDE2NyBzdG9yZXMgc3ByZWFkIGFjcm9zcyAxOCBjb3VudHJpZXMsIHRoZSAyNTkteWVhci1vbGQgQnJpdGlzaCB0b3kgc3RvcmUgCmNoYWluIEhhbWxleXMgZ2l2ZXMgUmVsaWFuY2UgUmV0YWlsIGEgbXVjaC1uZWVkZWQgZ2xvYmFswqAuLi4=\",\"displayurl\":\"m.economictimes.com\"},{\"title\":\"Nita Ambani\'s Hermès handbag with 240 studded diamonds costs ...\",\"titleurl\":\"https://www.hindustantimes.com/lifestyle/nita-ambani-s-hermes-handbag-with-240-studded-diamonds-costs-approx-2-6-crores/story-93WVsmePZHymmcKvVivs6K.html\",\"description\":\"TWF5IDI2LCAyMDIwIC4uLiBOaXRhIEFtYmFuaSdzIG92ZXIgMjAwLWRpYW1vbmQgZW5jcnVzdGVkIEhlcm3DqHMgSGltYWxheWEgQmlya2luIGJhZywgd29ydGggCm92ZXIgUnMgMi42IGNyb3JlLCBoYXMgZ29uZSB2aXJhbCBvbiB0aGUgc29jaWFsIG1lZGlhLg==\",\"displayurl\":\"www.hindustantimes.com\"},{\"title\":\"At 23, Nita Ambani was told that she could never conceive - Times of ...\",\"titleurl\":\"https://timesofindia.indiatimes.com/life-style/parenting/pregnancy/at-23-nita-ambani-was-told-that-she-could-never-conceive/articleshow/68864007.cms\",\"description\":\"QXByIDE4LCAyMDE5IC4uLiBPbmUgc3VjaCBwZXJzb24gaXMgcGhpbGFudGhyb3Bpc3QgTml0YSBBbWJhbmkuIEEgZGV2b3RlZCBidXNpbmVzc3dvbWFuIGFuZCAKYW4gYWZmZWN0aW9uYXRlIG1vdGhlciwgaGVyIGxvdmUgZm9yIGhlciB0aHJlZSBjaGlsZHJlbi1Jc2hhLMKgLi4u\",\"displayurl\":\"timesofindia.indiatimes.com\"},{\"title\":\"Nita Ambani | Family matters: Nita Ambani addresses RIL AGM for ...\",\"titleurl\":\"https://economictimes.indiatimes.com/magazines/panache/family-matters-nita-ambani-addresses-ril-agm-for-the-1st-time-promises-unconditional-support-in-covid-fight-isha-akash-share-jio-2-0-roadmap/articleshow/76980605.cms\",\"description\":\"SnVsIDE1LCAyMDIwIC4uLiBUaGUgUklMIEFHTSB3ZW50IHZpcnR1YWwgZm9yIHRoZSBmaXJzdCB0aW1lLiBBZ2VuY2llcyBUaGUgdmlydHVhbCBSSUwgQUdNIHNhdyAKTXVrZXNoLCBOaXRhLCBJc2hhIGFuZCBBa2FzaCBBbWJhbmkgZGVsaXZlciBzcGVlY2hlczsgdGhlcmUgd2FzwqAuLi4=\",\"displayurl\":\"economictimes.indiatimes.com\"},{\"title\":\"FAKE: Nita Ambani\'s \'Tweet\' Supporting PM Modi, Amit Shah\",\"titleurl\":\"https://www.boomlive.in/fake-news/fake-nita-ambanis-tweet-supporting-pm-modi-amit-shah-6366\",\"description\":\"RGVjIDIxLCAyMDE5IC4uLiBBIFJlbGlhbmNlIGdyb3VwIHNwb2tlc3BlcnNvbiBjb25maXJtZWQgdG8gQk9PTSB0aGF0IHRoZSBhY2NvdW50IHdhcyBmYWtlIAphbmQgaW1wZXJzb25hdGluZyBOaXRhIEFtYmFuaS4gVGhlIHNjcmVlbnNob3Qgb2YgdGhlIGZha2UgdHdlZXTCoC4uLg==\",\"displayurl\":\"www.boomlive.in\"},{\"title\":\"Mukesh and Nita Ambani had kids Isha and Akash via IVF after 7 ...\",\"titleurl\":\"https://www.indiatoday.in/lifestyle/celebrity/story/mukesh-and-nita-ambani-had-kids-isha-and-akash-via-ivf-after-7-years-of-marriage-1443614-2019-01-31\",\"description\":\"SmFuIDMxLCAyMDE5IC4uLiBJc2hhIEFtYmFuaSB3YXMgcmVjZW50bHkgZmVhdHVyZWQgb24gdGhlIGNvdmVyIG9mIGEgbWFnYXppbmUuIEluIHRoZSBpbnRlcnZpZXcgCnNoZSB0YWxrZWQgYWJvdXQgaGVyIGFuZCBBa2FzaCBiZWluZyBJVkYgYmFiaWVzLCBoZXLCoC4uLg==\",\"displayurl\":\"www.indiatoday.in\"},{\"title\":\"Nita Ambani. Is the necklace Bhagat? He has used red and green ...\",\"titleurl\":\"https://in.pinterest.com/pin/433964114092961545/\",\"description\":\"QXByIDIxLCAyMDE5IC0gQ2hlY2tvdXQgQmVhdXRpZnVsIE5pdGEgQW1iYW5pIEhvdCBJbWFnZXMgV2l0aCBCb2xseXdvb2QgCkNlbGVicml0aWVzLCBQaG90b3MgR2FsbGVyeSAmIEltYWdlcywgTml0YSBBbWJhbmkgTGF0ZXN0IEZ1bGwgSEQgVW5zZWVuIApQaWN0dXJlcyzCoC4uLg==\",\"displayurl\":\"in.pinterest.com\"},{\"title\":\"10 Gifts Bought By Celebrities That Are So Expensive Youd Hate ...\",\"titleurl\":\"https://www.mensxp.com/special-features/features/44981-10-gifts-bought-by-celebrities-that-are-so-expensive-you-d-hate-your-partner-for-being-so-poor.html\",\"description\":\"TWF5IDI4LCAyMDE4IC4uLiBNdWtlc2ggQW1iYW5pLCBjaGFpcm1hbiBvZiBSZWxpYW5jZSBJbmR1c3RyaWVzLCBnaWZ0ZWQgaGlzIHdpZmUgTml0YSBBbWJhbmkgYSAKbHV4dXJ5IGpldCBvbiBoZXIgNDR0aCBiaXJ0aGRheS4gVGhlIGpldCBob3VzZXMgYSBtYXN0ZXLCoC4uLg==\",\"displayurl\":\"www.mensxp.com\"},{\"title\":\"29 stunning pictures and videos that take you inside Antilia, Mukesh ...\",\"titleurl\":\"https://www.vogue.in/culture-and-living/content/mukesh-ambani-house-inside-antilia-pictures-isha-ambani-nita-ambani\",\"description\":\"Mjkgc3R1bm5pbmcgcGljdHVyZXMgYW5kIHZpZGVvcyB0aGF0IHRha2UgeW91IGluc2lkZSBBbnRpbGlhLCBNdWtlc2ggQW1iYW5pICYgCk5pdGEgQW1iYW5pJ3MgcmVzaWRlbmNlLiBCeSBOaXR5YSBDaGFibGFuaSAyMSBBcHJpbCAyMDIwLiBGcm9tIHRoZSBncmFuZMKgLi4u\",\"displayurl\":\"www.vogue.in\"}]}';
			$cacheindex=5; $i=41; 
			$source='1000.01d1090fdb663d4874f0af4c422600e5,1000.c01379cf5a0d10980a8f26dfce72484f,1000.3950908dde942b59ce18d5ba5a72a183,1000.4fcb063626475dd11c888a4303269468,1000.e43e39ebd4b1d9c2e9951346f91257df,1000.04a4c3e5790eb588bac72be694622aa3,1000.f685d18163ee01be106371f6022230f1,1000.aaeeb369317adcbe2280eba83a0ec2b1,1000.73881775c65e5f6cbabbc99b7711a79a,1000.c3f64523c9c83204c218950cfc24f0b5,';
			$cachestore = new cachestorage();
			$start = microtime(true);
			$cachestore->storemixcache($content, $cacheindex, $id, $source);
			$end = microtime(true);
			echo "------------------------------";
			echo $exec_time = ($end - $start); 
	}
	function webAction($alignment=0)
	{
		$valid=$this->uservalidation();
		$this->setValue("valid",$valid);
		$keyword=$_GET['search'];
		$exactphrase=trim($_GET['exactphrase']);
		$searchdomain=trim($_GET['searchdomain']);
		$excludedword=trim($_GET['excludedword']);
		$excludeddomain=trim($_GET['excludeddomain']);
		$setkeyword="";
		if($exactphrase!="")
		{
			$setkeyword.=" \"$exactphrase\"" ;
		}
		if($searchdomain!="")
		{
			$setkeyword.=" site:".$searchdomain;
		}
		if($excludedword!="")
		{
			$setkeyword.=" -".$excludedword;
		}
		if($excludeddomain!="")
		{
			$setkeyword.=" -site:".$excludeddomain;
		}
		$quotestatus=get_magic_quotes_gpc();
		if($quotestatus==1)
		$keyword=stripslashes($keyword);
		$tabname=$_GET['type'];
		$fl=$_GET['fl'];
		if((!isset($_GET['type']))||($_GET['type']==""))
		$tabname="web";
		if((!isset($_GET['search'])||($_GET['search']=="")))
		$keyword=str_replace("%2NNFF","/",$this->getParam(1));
		if(($setkeyword!="")&&($setkeyword!=" "))
		$keyword=$keyword.$setkeyword;
        $this->setValue("getkeyword",$keyword);
		$suggestion_keyword=$keyword;
		include('script.inc.php');
		include($config_path.'system.config.php');
		if($fl==1)
		$feelinglucky=1;
		$quotestatus=get_magic_quotes_gpc();
		if($quotestatus==1)
		$keyword=stripslashes($keyword);
		$keyword=str_replace('"',' " ',$keyword);
		$keyword=str_replace("'"," ' ",$keyword);
		$keyword=$this->familyfilter($keyword);
		$keyword=str_replace("' ","'",$keyword);
		$keyword=str_replace(" '","'",$keyword);
		$keyword=str_replace('" ','"',$keyword);
		$keyword=str_replace(' "','"',$keyword);
		$db= new NesoteDALController();
		$db->select("nesote_inoutse_engines");
		$db->fields("id,search_type");
		$db->where("tab_name=?",$tabname);
		$result=$db->query();
		$row=$db->fetchRow($result);
		$searchtype=$row[1];
		$engineid=$row[0];
		$tot=$db->total("nesote_inoutse_engines","tab_name=? and status=?",array($tabname,1));
		if(($keyword=="")||($tot==0))
		{
			if($mod_rewrite==true)
			header("Location:".$this->url("search/noresults?search=$keyword&type=$searchtype"));
			else
			header("Location:".$this->url("search/noresults&search=$keyword&type=$searchtype"));
			exit(0);
		}
		$page=1;
		if(isset($_GET['startpage']))
		$page=$_GET['startpage']; 
		if($page=="")
		$page=1;
		$tabkeyword=str_replace("/","%2NNFF",$keyword);
		$this->setValue("keyword",$tabkeyword);
		$this->setValue("tabname",$tabname);
		$this->loadLibrary('Settings');
		$settings=new Settings('nesote_inoutse_settings');
		$settings->loadValues();
		$count=$settings->getValue("result_count");
		$relatedtag_count=$settings->getValue("related_tags_count");
		$styleid=$settings->getValue("result");
		$openin_newwindow=$settings->getValue("new_window");
		$this->setValue("newwindow",$openin_newwindow);
		$emailafrnd=$settings->getValue("email_a_frnd");
		$this->setValue("emailafrnd",$emailafrnd);
		$quicklook=$settings->getValue("quicklook");
		$this->setValue("quicklook",$quicklook);
		$servicename=$settings->getValue("service_name");
		$this->setValue("servicename",$servicename);
		$member_status=$settings->getValue("member_status");
		$star_status=$settings->getValue("star_status");
		$this->setValue("star_status",$star_status);
		if($member_status==1)
		$comment_status=$settings->getValue("comment_status");
		else
		$comment_status=0;
		$this->setValue("comment_status",$comment_status);
			$seasonal_logo_status=$settings->getValue("seasonal_logo");
		if($seasonal_logo_status==1)
		{
			$time=time();
			$db->select("nesote_inoutse_seasonallogo");
			$db->fields("id,resultpage_logo");
			$db->where("startdate<=? and enddate>=? and status=1",$time);
			$result=$db->query();
			$row=$db->fetchRow($result);
			if($row[1]!="")
			{
				$logostatus=1;
				$userlogo=$row[1];
				$this->setValue("logoid",$row[0]);
			}
			elseif($row[1]=="")
			{
				$logostatus=0;
				$userlogo=$settings->getValue("result_logo"); 
			}
		}
		else
		{
			$logostatus=0;
			$userlogo=$settings->getValue("result_logo");
		}
		$this->setValue("logo",$userlogo);
		$this->setValue("logostatus",$logostatus);
		$moreimagearray=array("keyword"=>$keyword);
		$moreimage=$this->getmessagegrammer(26,$moreimagearray);
		$this->setValue("moreimage",$moreimage);
		$showimageresultsinweb=$settings->getValue("showimageresultsinweb");
		$thumbshot_user_override=$settings->getValue("thumbshot_user_override");
		$this->setValue("thumbshot_useroverride",$thumbshot_user_override);
		$quicklook_user_override=$settings->getValue("quicklook_user_override");
		$this->setValue("qlook_useroverride",$quicklook_user_override);
		$rest_api_status=$settings->getValue("rest_api_search");
		$this->setValue("yahooboss_status",$rest_api_status);
		$ad_codes=$settings->getValue("ad_codes");
		$this->setValue("ad_codes",$ad_codes);
		$message=array("servicename"=>$servicename);
		$home=$this->getmessagegrammer(47,$message,0);
		$this->setValue("home",$home);
		$unit_conversionstatus=$settings->getValue("unit_conversions");
		$priority_result_status=$settings->getValue("priority_result_status");
		if($unit_conversionstatus==1)
		{
			$coversion=$this->getconversions($keyword);
			$conversionkeyword=str_replace("=","",$keyword);
			$this->setValue("conversionkeyword",$conversionkeyword);
		}
		else
		$coversion="";
		if($coversion!="")
		$this->setValue("conversionstatus",1);
		else
		$this->setValue("conversionstatus",0);
		$this->setValue("conversion",$coversion);
		$operatorcount=0;
		$operatorcount=$operatorcount+substr_count($keyword,"+");
		$operatorcount=$operatorcount+substr_count($keyword,"-");
		$operatorcount=$operatorcount+substr_count($keyword,"*");
		$operatorcount=$operatorcount+substr_count($keyword,"/");
		$operatorcount=$operatorcount+substr_count(str_replace("%20"," ",$keyword),"%");
		$nocal=0;
		if(isset($_GET['nocal']))
		$nocal=$_GET['nocal'];
		if(($nocal!=1)&&($operatorcount!=0)&&($page==1))
		$arithmeticconversion=$this->getarithmeticconversion($keyword);
		$this->setValue("engineid",$engineid);
		$enginename=$this->getenginename($engineid);
		define('PAGETITLE',$servicename." - ".$enginename." - ".$keyword);
		define('HEADERKEYWORD',$servicename.",search,search engine,".$keyword.",".$searchtype);
		$typearray=array("type"=>$enginename)	;
		$typesearch=$this->getmessagegrammer(23,$typearray);
		$this->setValue("typesearch",$typesearch);
		$spellurl=$this->getspellurl($keyword,"web",2,0);
		$spellsuggestion=$this->getspellcontent($spellurl,$keyword,$tabname,2,0);
		if($spellsuggestion=="")
		{
			$spellurl=$this->getspellurl($keyword,"web",1,0);
			$spellsuggestion=$this->getspellcontent($spellurl,$keyword,$tabname,1,0);
		}
		if($spellsuggestion!="")
		{
			$spell=array("spell"=>$spellsuggestion);
			$style=array("keyword_in_spellsuggestion_class");
			$spellstr=$this->getmessagegrammer(24,$spell,$style);
			$spellstr=str_replace("<span class=\"keyword_in_spellsuggestion_class\">".$spellsuggestion."</span>","<a class=\"spelllink\" href=\"".$this->url("search/web&search=".$spellsuggestion."&type=$tabname")."\">".$spellsuggestion."</a>",$spellstr);
			$this->setValue("spell","<span class=\"spellsuggestiontext\">".$spellstr."</span>");
		}
		else
		$this->setValue("spell","");
		$db->select("nesote_inoutse_engines");
		$db->fields("id,search_type");
		$db->where("tab_name=?","images");
		$result=$db->query();
		$row=$db->fetchRow($result);
		$imagesearchtype=$row[1];  
		$imageengineid=$row[0]; 
		$showimageresultsinweb=0;//only for google theme
		if($showimageresultsinweb==1)
		{
			$images=$this->get_imagecontent($imageengineid,$imagesearchtype,$keyword,1);
			$this->setValue("imageurl",$this->url("search/images&search=$keyword&type=images"));
			$imagecount=count($images);
			if(($images!="")&&($page==1)&&($showimageresultsinweb==1)&&($imagecount>=5))
			$showimagestatus=1;
			else
			$showimagestatus=0;
		}
		else
		{
			$showimagestatus=0;
		}
		$this->setLoopValue("images",$images);
		$this->setValue("showimagestatus",$showimagestatus);
$xmldata=$this->getmixurlcontents($engineid,$searchtype,$page,$keyword,1);
		$cacheparts=explode("&@&",$xmldata);
		$cachepart1=$cacheparts[0];
		$cachepart2=$cacheparts[1];
		$source=$cacheparts[2];
		$cacheresult=json_decode($cachepart2);
		$source=$cacheparts[2];
		if($source!='')
		{
			$sourceresult=json_decode($source);
			foreach($sourceresult->source as $mydata)
		    {
		         $statusarray[1][].=$mydata->sourcestatus;
		    }
		}
		$cacheresultd = json_decode($cachepart1, true);
 		$start=$cacheresultd['start'];
 		$totalcount=$cacheresultd['totalcount'];
 		$backupcount=$cacheresultd['backupcount'];
 		$allstatus=$cacheresultd['allstatus'];
 		$onlygooglestatus=$cacheresultd['onlygooglestatus'];
		$style="";
		$this->setValue("style",$style);
		$resultflag=true;
		$xmldata=str_replace("\r\n","",$xmldata);
		$xmldata=str_replace("\n","",$xmldata);
		$xmldata=str_replace("\r","",$xmldata);
		if($xmldata=="expired")
		{
		$resultflag=false;
		}
		else 
		{
		$totalhits=$totalcount;
		if($allstatus==0)
		{
			$total=$backupcount;
			$total1=$totalhits;
		}
		else
		{
			$onlygoogle=$onlygooglestatus;
			if($onlygoogle==1)
			{
				$total=$totalhits;
				$google_maxcount=$settings->getValue("google_totalfetchingcount");
				if($total>$google_maxcount)
				{
				   $total=$google_maxcount;
				}
			}
			else
			{
				$total=$totalhits;
			}
			$total1=$totalhits;
		}
        $stnum=$start;
		$stnumber=$stnum;
		$this->setValue("totalhits",$total);
		$cacheresultcount=0;
		foreach($cacheresult->item as $mydata)
		{
			$cacheresultcount=$cacheresultcount+1;
		}
		if($cacheresultcount==0)
		{
		$resultflag=false;
		}
		else 
		{
		$pagecount=$page*10;
		$start=(10*($page-1))%$count;
		$startingnum=($page*10)-9;
		$endingnum=$page*10;
		if($total<$endingnum)
		$endingnum=$total;
		if($total<10)
		$startingnum=1;
		else
		$startingnum=($page*10)-9;
		$totalstring=number_format($total1);
		$message=array("startingnum"=>$startingnum,"endingnum"=>$endingnum,"total"=>$totalstring,"keyword"=>htmlentities($keyword,ENT_QUOTES,"UTF-8"));
		$style=array("resultcountstart","resultcountend","totalresults","keywordintotal");
		$totalstr=$this->getmessagegrammer(8,$message,$style);
		$this->setValue("total",$totalstr);
		$keyword1=urlencode($keyword);
		$keywordsuggestion_status=$db->total("nesote_inoutse_engines","id=? and keyword_suggestion_status=1",array($engineid));
		if($page==1 && $keywordsuggestion_status!=0 && trim($suggestion_keyword)==trim($keyword))
		{
			$tot1=$db->total("nesote_inoutse_keywordsuggestions","engine_id=? and keyword=?",array($engineid,$suggestion_keyword));
			if($tot1==0)
			{
				$db->insert("nesote_inoutse_keywordsuggestions");
				$db->fields("engine_id,keyword,total,searchcount,time");
				$db->values(array($engineid,$suggestion_keyword,$total1,1,time()));
				$db->query();
			}
			else
			{
				$db->update("nesote_inoutse_keywordsuggestions");
				$db->set("searchcount=searchcount+1,time=?,total=?",array(time(),$total1));
				$db->where("engine_id=? and keyword=?",array($engineid,$suggestion_keyword));
				$db->query();
			}
		}
		$previouspage=$page-1;
		if($page<=4)
		{
			$startpage=1;
			$endpage=5;
		}
		else
		{
			$startpage=$page-3;
			$endpage=$page+3;
		}
		$nextpage=$page+1;
		if($page!=1)
		{
		$footerlink.="<li class=\"pgntn-li float-left\"><a class=\"pgntn-a pgn-arw\" href=javascript:loadpage($previouspage)><i class=\"fas fa-chevron-left\"></i></a></li>";
		}
		for($i=$startpage;$i<=$endpage;$i++)
		{
			if($i*10<($total+10))
			{
				if($i!=$page)
				{
					$footerlink.="<li class=\"pgntn-li float-left\"><a class=\"pgntn-a pgn-cnt\" href=javascript:loadpage($i)>$i</a></li>";
				}
				else 
				{
					$footerlink.="<li class=\"pgntn-li float-left\"><a class=\"pgntn-a pgn-cnt pgn-actv\" href=javascript:loadpage($i)>$i</a></li>";
				}
			}
		}
		if($page*10<($total))
		{
		$footerlink.="<li class=\"pgntn-li float-left\"><a class=\"pgntn-a pgn-arw\" href=javascript:loadpage($nextpage)><i class=\"fas fa-chevron-right\"></i></a></li>";
		}
		$this->setValue("footerlink",$footerlink);
		$relatedkeywords=$this->getrelatedkeyword($keyword,$xmldata);
		$finalkeywordarray=[];
		for($i=0;$i<$relatedtag_count;$i++)
		{
			$finalkeywordarray[$i][0]=$relatedkeywords[$i];
		}
		if($finalkeywordarray[0][0]!="")
		$this->setValue("keywordstatus",1);
		else
		$this->setValue("keywordstatus",0);
		$this->setLoopValue("relatedkeywords",$finalkeywordarray);
		$j=0;
		if($stnumber==0)
		{
			$max_priority=$settings->getValue("max_priority_results");
			$count=$settings->getValue("result_count");
			$priority_result_status=$settings->getValue("priority_result_status");
			if($max_priority>10)
			$max_priority=10;
			$prioritykeyword=$keyword;
			if($stnumber==0)
			{
				$db->select(array("a"=>"nesote_inoutse_priority_results","b"=>"nesote_inoutse_priority_result_keywords"));
				$db->fields("a.id,a.description,a.displayurl,a.title,a.link");
				$db->where("a.id=b.rid and b.keyword=? and a.status=1",$prioritykeyword);
				$db->order("b.position asc");
				$db->limit(0,$max_priority);
				$result=$db->query();
				$priorityresults=$result->getresult();
				$priorityresultcount=count($priorityresults);
			}
			else
			{
				$priorityresultcount=0;
			}
			$j=0;
			for($i=0;$i<=$priorityresultcount;$i++)
			{
				if($priorityresults[$i][2]=="")
				break;
				$finalresultstemp[$j][1]=$priorityresults[$i][1];
				$finalresultstemp[$j][2]=$priorityresults[$i][2];
				$finalresultstemp[$j][3]=$priorityresults[$i][3];
				$finalresultstemp[$j][4]=$priorityresults[$i][4];
				$j++;
			}
		}
		$resultset=[];
foreach($cacheresult->item as $mydata)
    {
         $resultset[2][]=$mydata->titleurl;
    }
foreach($cacheresult->item as $mydata)
    {
         $resultset[1][]=base64_decode($mydata->title);
    }
foreach($cacheresult->item as $mydata)
    {
         $resultset[3][]=base64_decode($mydata->description);
    }
foreach($cacheresult->item as $mydata)
    {
         $resultset[4][]=$mydata->displayurl;
    }
		$finalresult2=$resultset;
		if($cacheresultcount==0)
		{
		$resultflag=false;
		}
		else 
		{
		$s=($page-1)*10-$stnumber; $u=0;
		$rescnt=$cacheresultcount;
		if($stnumber==0)
		{
			if($page<2)
			{
				if($priority_result_status==0)
				{
					$totcnt=10;
				}
				else if($priority_result_status==1)
				{
					$totcnt=10 + $priorityresultcount;
				}
			}
			else
			{
				if($priority_result_status==0)
				{
					$s=$s-$priorityresultcount;
				}
			}
		}
		if($page<2)
		{
			for($i=0;$i<$priorityresultcount;$i++)
			{
				$finalresult[$u][1]=$finalresultstemp[$i][1];
				$finalresult[$u][2]=$finalresultstemp[$i][2];
				$finalresult[$u][3]=$finalresultstemp[$i][3];
				$finalresult[$u][4]=$finalresultstemp[$i][4];
				$finalresult[$u][5]="0000";
				$finalresult[$u][6]=$this->getstar($finalresult[$u][4],$engineid);
				$u++;
			}
			for($i=$priorityresultcount;$i<$totcnt;$i++)
			{
				if($resultset[4][$s]!="")
				{
					$finalresult[$u][1]=$resultset[3][$s];                        
					if(strlen($finalresult[$u][1])>=150)
					{  $len=strlen($finalresult[$u][1]);
					$p=strpos($finalresult[$u][1]," ");
					if(($p=="")||($p>150))
					{   
						$fir=substr($finalresult[$u][1],0,150);
						$sec=substr($finalresult[$u][1],151,$len);
						$finalresult[$u][1]=$fir." ".$sec;
					}
					}
					$finalresult[$u][2]=$resultset[4][$s];
					if(strlen($finalresult[$u][2])>=60)                             
					$finalresult[$u][2]=substr($finalresult[$u][2],0,60)."...";
					$finalresult[$u][3]=$resultset[1][$s];                          
					if(strlen($finalresult[$u][3])>=100)
					$finalresult[$u][3]=substr($finalresult[$u][3],0,100)."...";
					$finalresult[$u][4]=$resultset[2][$s];                      
					$finalresult[$u][5]=$statusarray[1][$u];
					$finalresult[$u][6]=$this->getstar($finalresult[$u][4],$engineid);
					$u++;
				}
				$s=$s+1;
			}
		}
		else if($rescnt>=$s+10)
		{
			for($i=0;$i<10;$i++)
			{
				if($resultset[4][$s]!="")
				{
					$finalresult[$u][1]=$resultset[3][$s];                        
					if(strlen($finalresult[$u][1])>=150)
					{  $len=strlen($finalresult[$u][1]);
					$p=strpos($finalresult[$u][1]," ");
					if(($p=="")||($p>150))
					{  
						$fir=substr($finalresult[$u][1],0,150);
						$sec=substr($finalresult[$u][1],151,$len);
						$finalresult[$u][1]=$fir." ".$sec;
					}
					}
					$finalresult[$u][2]=$resultset[4][$s];
					if(strlen($finalresult[$u][2])>=60)                           
					$finalresult[$u][2]=substr($finalresult[$u][2],0,60)."...";
					$finalresult[$u][3]=$resultset[1][$s];                          
					if(strlen($finalresult[$u][3])>=100)
					$finalresult[$u][3]=substr($finalresult[$u][3],0,100)."...";
					$finalresult[$u][4]=$resultset[2][$s];                       
					$finalresult[$u][5]=$statusarray[1][$u];
					$finalresult[$u][6]=$this->getstar($finalresult[$u][4],$engineid);
					$u++;
				}
				$s=$s+1;
			}
		}
		else if($total-$startingnum+1>10)
		{
			$s= $rescnt-10;
			for($i=0;$i<10;$i++)
			{
				if($resultset[4][$s]!="")
				{
					$finalresult[$u][1]=$resultset[3][$s];
					if(strlen($finalresult[$u][1])>=150)
					{  $len=strlen($finalresult[$u][1]);
					$p=strpos($finalresult[$u][1]," ");
					if(($p=="")||($p>150))
					{   
						$fir=substr($finalresult[$u][1],0,150);
						$sec=substr($finalresult[$u][1],151,$len);
						$finalresult[$u][1]=$fir." ".$sec;
					}
					}
					$finalresult[$u][2]=$resultset[4][$s];
					if(strlen($finalresult[$u][2])>=60)                          
					$finalresult[$u][2]=substr($finalresult[$u][2],0,60)."...";
					$finalresult[$u][3]=$resultset[1][$s];                           
					if(strlen($finalresult[$u][3])>=100)
					$finalresult[$u][3]=substr($finalresult[$u][3],0,100)."...";
					$finalresult[$u][4]=$resultset[2][$s];
					$finalresult[$u][5]=$statusarray[1][$u];
					$finalresult[$u][6]=$this->getstar($finalresult[$u][4],$engineid);
					$u++;
				}
				$s=$s+1;
			}
		}
		else if($total-$startingnum+1>0)
		{
			$finish=$total-$startingnum+1;
			$statf=0;
			$s=0;
			for($i=0;$i<$finish;$i++)
			{
				if($resultset[4][$s]!="")
				{
					$finalresult[$u][1]=$resultset[3][$s];
					if(strlen($finalresult[$u][1])>=150)
					{  $len=strlen($finalresult[$u][1]);
					$p=strpos($finalresult[$u][1]," ");
					if(($p=="")||($p>150))
					{   
						$fir=substr($finalresult[$u][1],0,150);
						$sec=substr($finalresult[$u][1],151,$len);
						$finalresult[$u][1]=$fir." ".$sec;
					}
					}
					$finalresult[$u][2]=$resultset[4][$s];
					if(strlen($finalresult[$u][2])>=60)                            
					$finalresult[$u][2]=substr($finalresult[$u][2],0,40)."...";
					$finalresult[$u][3]=$resultset[1][$s];                          
					if(strlen($finalresult[$u][3])>=100)
					$finalresult[$u][3]=substr($finalresult[$u][3],0,80)."...";
					$finalresult[$u][4]=$resultset[2][$s];
					$finalresult[$u][5]=$statusarray[1][$statf];
					$finalresult[$u][6]=$this->getstar($finalresult[$u][4],$engineid);
					$u++; $statf++;
				}
				$s=$s+1;
			}
		}
		else
		{
		$resultflag=false;
		}
		if(($page==1)&&($feelinglucky==1))
		{
			header("Location:".strip_tags($finalresult[0][4]));
			exit(0);
		}
		if($resultflag==true)
		{
$finalcount=count($finalresult);
		for($i=0;$i<$finalcount;$i++)
		{
			$finalresult[$i][1]=$this->makebold($finalresult[$i][1],$keyword,1);
						$finalresult[$i][2]=$this->makebold($finalresult[$i][2],$keyword,0);
			$finalresult[$i][3]=$this->makebold($finalresult[$i][3],$keyword,0);
		}
		}
		if($finalcount==0)
		{
			$resultflag=false;
		}
		}
		}
		}
	    if($resultflag==false)
		{
			list($finalresult,$totals)=$this->getalturlcontentdata($searchtype, $page,$keyword);
			$total=$totals[0];
		$previouspage=$page-1;
		if($page<=4)
		{
			$startpage=1;
			$endpage=5;
		}
		else
		{
			$startpage=$page-3;
			$endpage=$page+3;
		}
		$nextpage=$page+1;
		if($page!=1)
		{
		$footerlink.="<li class=\"pgntn-li float-left\"><a class=pgntn-a pgn-arw href=javascript:loadpage($previouspage)><i class=\"fas fa-chevron-left\"></i></a></li>";
		}
		for($i=$startpage;$i<=$endpage;$i++)
		{
			if($i*10<($total+10))
			{
				if($i!=$page)
				{
					$footerlink.="<li class=\"pgntn-li float-left\"><a class=\"pgntn-a pgn-cnt\" href=javascript:loadpage($i)>$i</a></li>";
				}
				else 
				{
					$footerlink.="<li class=\"pgntn-li float-left\"><a class=\"pgntn-a pgn-cnt pgn-actv\" href=javascript:loadpage($i)>$i</a></li>";
				}
			}
		}
		if($page*10<($total))
		{
		$footerlink.="<li class=\"pgntn-li float-left\"><a class=pgntn-a pgn-arw href=javascript:loadpage($nextpage)><i class=\"fas fa-chevron-right\"></i></a></li>";
		}
		$message=array("startingnum"=>1,"endingnum"=>10,"total"=>100,"keyword"=>htmlentities($keyword,ENT_QUOTES,"UTF-8"));
		$style=array("resultcountstart","resultcountend","totalresults","keywordintotal");
		$totalstr=$this->getmessagegrammer(8,$message,$style);
		    $this->setValue("total",$totalstr);
			$this->setValue("totalhits","");
			$this->setValue("footerlink",$footerlink);
			$this->setValue("keywordstatus",0);
			$this->setLoopValue("relatedkeywords","");
			$this->setValue("comment_status",0);
		}
		//suraaj start
for($i=0;$i<$finalcount;$i++)
		{
		$urlarr.=urlencode($finalresult[$i][4]).'7ff4daa1068d1f82265991e6ccc6fa8c';	
		}
$this->setValue("resultsfinal",$urlarr);
//suraaj end
		$this->setLoopValue("results",$finalresult);
		$installurl=$settings->getValue("adserver_installurl");
		$authcode=$settings->getValue("adserver_authenticationcode");
		$displayurl=$settings->getValue("adserver_displayurl");
		$topadcount=$settings->getValue("adserver_topadcount");
		$rightadcount=$settings->getValue("adserver_rightadcount");
		$this->setValue("installurl",$installurl);
		$this->setValue("authcode",$authcode);
		$this->setValue("displayurl",$displayurl);
		$this->setValue("topadcount",$topadcount);
		$this->setValue("rightadcount",$rightadcount);
		 $webadtype=$settings->getValue("webadtype");
		$this->setValue("webadtype",$webadtype);
		$spnewsadtype=$settings->getValue("spnewsadtype");
		$this->setValue("spnewsadtype",$spnewsadtype);
		$publicadstatus=$settings->getValue("publicadstatus");
		$this->setValue("publicadstatus",$publicadstatus);
		$adserver_installurl=$settings->getValue("adserver_installurl");
		$this->setValue("adserver_installurl",$adserver_installurl);
		if(($installurl!="")&&($authcode!=""))
		{
			if($webadtype==2)
			{
				$sponsoredurl=$installurl."xml-ads.php?user_id=0&auth_code=".$authcode."&start_record=0&count=".$topadcount."&keywords=".urlencode($keyword)."&user_ip=".$_SERVER['REMOTE_ADDR'] ;
				$sponsoredlinks=$this->xmlsponsoredlinks($sponsoredurl);
				$sponsoredlinks=str_replace("\r\n","",$sponsoredlinks);
				$sponsoredlinks=str_replace("\n","",$sponsoredlinks);
				$sponsoredlinks=str_replace("\r","",$sponsoredlinks);
				preg_match_all("/<ad><title>(.+?)<\/title><description>(.+?)<\/description><displayurl>(.+?)<\/displayurl><targeturl>(.+?)<\/targeturl><clickbid>(.+?)<\/clickbid><\/ad>/i",$sponsoredlinks,$sponresults);
				if(count($sponresults[0])!=0)
				{
					$j=0;
					for($i=0;$i<count($sponresults[0]);$i++)
					{
						$var=str_replace("<![CDATA[","",$sponresults[1][$i]);
						$var=str_replace("]]>","",$var);
						$spresult[$j][0]=$this->makebold(strip_tags($var),$keyword,0);
						$var=str_replace("<![CDATA[","",$sponresults[2][$i]);
						$var=str_replace("]]>","",$var);
						$spresult[$j][1]=$this->makebold(strip_tags($var),$keyword,1);
						$var=str_replace("<![CDATA[","",$sponresults[3][$i]);
						$var=str_replace("]]>","",$var);
						$spresult[$j][2]=html_entity_decode($var);
						$var=str_replace("<![CDATA[","",$sponresults[4][$i]);
						$var=str_replace("]]>","",$var);
						$spresult[$j][3]=html_entity_decode($var);
						$j++;
					}
					$j=0;
					for($i=0; $i<$topadcount;$i++)
					{
						if($spresult[$i][0]!="")
						{
							$toparray[$j][0]=$spresult[$i][0];
							$toparray[$j][1]=$spresult[$i][1];
							$toparray[$j][2]=$spresult[$i][2];
							$toparray[$j][3]=$spresult[$i][3];
							$j++;
						}
					}
					if(count($toparray)!=0)
					{
						$this->setValue("tpc","1");
						shuffle($toparray);
						$this->setLoopValue("toparray",$toparray);
					}
					else
					$this->setValue("tpc","0");
				}
				$sponsoredurl2=$installurl."xml-ads.php?user_id=0&auth_code=".$authcode."&start_record=".$topadcount."&count=".$rightadcount."&keywords=".urlencode($keyword)."&user_ip=".$_SERVER['REMOTE_ADDR'] ;
				$sponlinks2=$this->xmlsponsoredlinks($sponsoredurl2);
				$sponlinks2=str_replace("\r\n","",$sponlinks2);
				$sponlinks2=str_replace("\n","",$sponlinks2);
				$sponlinks2=str_replace("\r","",$sponlinks2);
				preg_match_all("/<ad><title>(.+?)<\/title><description>(.+?)<\/description><displayurl>(.+?)<\/displayurl><targeturl>(.+?)<\/targeturl><clickbid>(.+?)<\/clickbid><\/ad>/i",$sponlinks2,$sponresults2);
				if(count($sponresults2[0])!=0)
				{
					$j=0;
					for($i=0;$i<count($sponresults2[0]);$i++)
					{
						$var=str_replace("<![CDATA[","",$sponresults2[1][$i]);
						$var=str_replace("]]>","",$var);
						$spresult2[$j][0]=$this->makebold(strip_tags($var),$keyword,0);
						$var=str_replace("<![CDATA[","",$sponresults2[2][$i]);
						$var=str_replace("]]>","",$var);
						$spresult2[$j][1]=$this->makebold(strip_tags($var),$keyword,1);
						$var=str_replace("<![CDATA[","",$sponresults2[3][$i]);
						$var=str_replace("]]>","",$var);
						$spresult2[$j][2]=html_entity_decode($var);
						$var=str_replace("<![CDATA[","",$sponresults2[4][$i]);
						$var=str_replace("]]>","",$var);
						$spresult2[$j][3]=html_entity_decode($var);
						$j++;
					}
					$j=0;
					for($i=0; $i<$rightadcount;$i++)
					{
						if($spresult2[0][0]!="")
						{
							$rightarray[$j][0]=$spresult2[$i][0];
							$rightarray[$j][1]=$spresult2[$i][1];
							$rightarray[$j][2]=$spresult2[$i][2];
							$rightarray[$j][3]=$spresult2[$i][3];
							$j++;
						}
					}
					if(count($rightarray)!=0)
					{
						$this->setValue("rpc","1");
						shuffle($rightarray);
						$this->setLoopValue("rightarray",$rightarray);
					}
					else
					$this->setValue("rpc","0");
				}
			}
			if((count($rightarray)==0)&&($publicadstatus==1)&&($webadtype==2))
			{
				$publicurl=$installurl."xml-ads.php?user_id=0&auth_code=".$authcode."&start_record=0&count=".$rightadcount."&user_ip=".$_SERVER['REMOTE_ADDR']."&ps=2" ;
				$publiclinks=$this->xmlsponsoredlinks($publicurl);
				$publiclinks=str_replace("\r\n","",$publiclinks);
				$publiclinks=str_replace("\n","",$publiclinks);
				$publiclinks=str_replace("\r","",$publiclinks);
				preg_match_all("/<ad><title>(.+?)<\/title><description>(.+?)<\/description><displayurl>(.+?)<\/displayurl><targeturl>(.+?)<\/targeturl><clickbid>(.+?)<\/clickbid><\/ad>/i",$publiclinks,$pubresults);
			}
			if(count($pubresults[0])!=0)
			{
				$j=0;
				for($i=0;$i<=count($pubresults[0]);$i++)
				{
					$var=str_replace("<![CDATA[","",$pubresults[1][$i]);
					$var=str_replace("]]>","",$var);
					$publicresult[$j][0]=$this->makebold(strip_tags($var),$keyword,0);
					$var=str_replace("<![CDATA[","",$pubresults[2][$i]);
					$var=str_replace("]]>","",$var);
					$publicresult[$j][1]=$this->makebold(strip_tags($var),$keyword,1);
					$var=str_replace("<![CDATA[","",$pubresults[3][$i]);
					$var=str_replace("]]>","",$var);
					$publicresult[$j][2]=html_entity_decode($var);
					$var=str_replace("<![CDATA[","",$pubresults[4][$i]);
					$var=str_replace("]]>","",$var);
					$publicresult[$j][3]=html_entity_decode($var);
					$var=str_replace("<![CDATA[","",$pubresults[5][$i]);
					$var=str_replace("]]>","",$var);
					$publicresult[$j][4]=html_entity_decode($var);
					$j++;
				}
				$rightadcount=$settings->getValue("adserver_rightadcount");
				$j=0;
				for($i=0; $i<$rightadcount;$i++)
				{
					if($publicresult[$i][0]!="")
					{
						$publicarray[$j][0]=$publicresult[$i][0];
						$publicarray[$j][1]=$publicresult[$i][1];
						$publicarray[$j][2]=$publicresult[$i][2];
						$publicarray[$j][3]=$publicresult[$i][3];
						$publicarray[$j][4]=$publicresult[$i][4];
						$j++;
					}
				}
				if(count($publicarray)!=0)
				{
					$this->setValue("rpc","1");
					$this->setLoopValue("rightarray",$publicarray);
				}
				else
				$this->setValue("rpc","0");
			}
		}
$this->setValue("viewmsgsett_639",$this->getmessage(639));
$this->setValue("viewmsgsett_641",$this->getmessage(641));
$this->setValue("viewmsgsett_640",$this->getmessage(640));
$this->setValue("viewmsgsett_27",$this->getmessage(27));
$this->setValue("viewmsgsett_39",$this->getmessage(39));
$this->setValue("viewmsgsett_41",$this->getmessage(41));
$this->setValue("viewmsgsett_40",$this->getmessage(40));
$this->setValue("viewmsgsett_43",$this->getmessage(43));
$this->setValue("viewmsgsett_42",$this->getmessage(42));
$this->setValue("viewmsgsett_579",$this->getmessage(579));
$this->setValue("viewmsgsett_608",$this->getmessage(608));
$this->setValue("viewmsgsett_581",$this->getmessage(581));
$this->setValue("viewmsgsett_587",$this->getmessage(587));
$this->setValue("viewmsgsett_15",$this->getmessage(15));
	}
	function getsortedfinalarray($resultset,$total,$feelinglucky,$keyword,$page)
	{
		$this->loadLibrary('Settings');
		$settings=new Settings('nesote_inoutse_settings');
		$settings->loadValues();
		$max_priority=$settings->getValue("max_priority_results");
		$count=$settings->getValue("result_count");
		$priority_result_status=$settings->getValue("priority_result_status");
		$rest_api_status=$settings->getValue("rest_api_search");
		if($max_priority>10)
		$max_priority=10;
		$prioritykeyword=$keyword;
		$db= new NesoteDALController();
		if($page<2)
		{
			$db->select(array("a"=>"nesote_inoutse_priority_results","b"=>"nesote_inoutse_priority_result_keywords"));
			$db->fields("a.id,a.description,a.displayurl,a.title,a.link");
			$db->where("a.id=b.rid and b.keyword=? and a.status=1",$prioritykeyword);
			$db->order("b.position asc");
			$db->limit(0,$max_priority);
			$result=$db->query();
			$priorityresults=$result->getresult();
			$priorityresultcount=count($priorityresults);
		}
		else
		{
			$priorityresultcount=0;
		}
		$j=0;
		for($i=0;$i<=$priorityresultcount;$i++)
		{
			if($priorityresults[$i][2]=="")
			break;
			if(($i==0)&&($feelinglucky==1))
			{
				header("Location:".strip_tags($priorityresults[$i][4]));
				exit(0);
			}
			$finalresultstemp[$j][1]=$priorityresults[$i][1];
			$finalresultstemp[$j][2]=$priorityresults[$i][2];
			$finalresultstemp[$j][3]=$priorityresults[$i][3];
			$finalresultstemp[$j][4]=$priorityresults[$i][4];
			$j++;
		}
		$j=($priorityresultcount);
		if($priority_result_status==0)
		{
			for($k=0;$k<=($count-$priorityresultcount-1);$k++)
			{
				if($resultset[2][$k]=="")
				break;
				if(($k==0)&&($feelinglucky==1))
				{
					header("Location:".strip_tags($resultset[6][$k]));
					exit(0);
				}
				$finalresultstemp[$j][1]="";
				$var=str_replace("<![CDATA[","",$resultset[2][$k]);
				$var=str_replace("]]>","",$var);
				$finalresultstemp[$j][2]=$this->makebold(strip_tags($var),$keyword,0);
				$var=str_replace("<![CDATA[","",$resultset[4][$k]);
				$var=str_replace("]]>","",$var);
				$finalresultstemp[$j][3]=$this->makebold(strip_tags($var),$keyword,1);
				$var=str_replace("<![CDATA[","",$resultset[6][$k]);
				$var=str_replace("]]>","",$var);
				$finalresultstemp[$j][4]=html_entity_decode($var);
				preg_match("/(.+?)<abstract>(.+?)<\/abstract>(.+?)/i",$resultset[1][$k],$abc);
				if(count($abc)!=0)
				{
					$var=str_replace("<![CDATA[","",$abc[2]);
					$var=str_replace("]]>","",$var);
					$finalresultstemp[$j][1]=$this->makebold(strip_tags($var),$keyword,1);
				}
				else
				{
					$var=str_replace("<![CDATA[","",$resultset[4][$k]);
					$var=str_replace("]]>","",$var);
					$finalresultstemp[$j][1]=$this->makebold(strip_tags($var),$keyword,1);
				}
				$j++;
			}
		}
		elseif($priority_result_status==1)
		{
			for($k=0;$k<=($count+$priorityresultcount);$k++)
			{
				if($resultset[2][$k]=="")
				break;
				if(($k==0)&&($feelinglucky==1))
				{
					header("Location:".strip_tags($resultset[6][$k]));
					exit(0);
				}
				$finalresultstemp[$j][1]="";
				$var=str_replace("<![CDATA[","",$resultset[2][$k]);
				$var=str_replace("]]>","",$var);
				$finalresultstemp[$j][2]=$this->makebold(strip_tags($var),$keyword,0);
				$var=str_replace("<![CDATA[","",$resultset[4][$k]);
				$var=str_replace("]]>","",$var);
				$finalresultstemp[$j][3]=$this->makebold(strip_tags($var),$keyword,1);
				$var=str_replace("<![CDATA[","",$resultset[6][$k]);
				$var=str_replace("]]>","",$var);
				$finalresultstemp[$j][4]=html_entity_decode($var);
				preg_match("/(.+?)<abstract>(.+?)<\/abstract>(.+?)/i",$resultset[1][$k],$abc);
				if(count($abc)!=0)
				{
					$var=str_replace("<![CDATA[","",$abc[2]);
					$var=str_replace("]]>","",$var);
					$finalresultstemp[$j][1]=$this->makebold(strip_tags($var),$keyword,1);
				}
				else
				{
					$var=str_replace("<![CDATA[","",$resultset[4][$k]);
					$var=str_replace("]]>","",$var);
					$finalresultstemp[$j][1]=$this->makebold(strip_tags($var),$keyword,1);
				}
				$j++;
			}
		}
		if($priority_result_status==0 && $rest_api_status==1)
		{
			for($k=0;$k<=($count-$priorityresultcount-1);$k++)
			{
				if($resultset[2][$k]=="")
				break;
				if(($k==0)&&($feelinglucky==1))
				{
					header("Location:".strip_tags($resultset[6][$k]));
					exit(0);
				}
				$finalresultstemp[$j][1]="";
				$var=str_replace("<![CDATA[","",$resultset[2][$k]);
				$var=str_replace("]]>","",$var);
				$finalresultstemp[$j][2]=$this->makebold(strip_tags($var),$keyword,0);
				$var=str_replace("<![CDATA[","",$resultset[4][$k]);
				$var=str_replace("]]>","",$var);
				$finalresultstemp[$j][3]=$this->makebold(strip_tags($var),$keyword,1);
				$var=str_replace("<![CDATA[","",$resultset[6][$k]);
				$var=str_replace("]]>","",$var);
				$finalresultstemp[$j][4]=html_entity_decode($var);
				preg_match("/(.+?)<abstract>(.+?)<\/abstract>(.+?)/i",$resultset[1][$k],$abc);
				if(count($abc)!=0)
				{
					$var=str_replace("<![CDATA[","",$abc[2]);
					$var=str_replace("]]>","",$var);
					$finalresultstemp[$j][1]=$this->makebold(strip_tags($var),$keyword,1);
				}
				else
				{
					$var=str_replace("<![CDATA[","",$resultset[4][$k]);
					$var=str_replace("]]>","",$var);
					$finalresultstemp[$j][1]=$this->makebold(strip_tags($var),$keyword,1);
				}
				$j++;
			}
		}
		elseif($priority_result_status==1 && $rest_api_status==1)
		{
			for($k=0;$k<=($count+$priorityresultcount);$k++)
			{
				if($resultset[2][$k]=="")
				break;
				if(($k==0)&&($feelinglucky==1))
				{
					header("Location:".strip_tags($resultset[6][$k]));
					exit(0);
				}
				$finalresultstemp[$j][1]="";
				$var=str_replace("<![CDATA[","",$resultset[2][$k]);
				$var=str_replace("]]>","",$var);
				$finalresultstemp[$j][2]=$this->makebold(strip_tags($var),$keyword,0);
				$var=str_replace("<![CDATA[","",$resultset[4][$k]);
				$var=str_replace("]]>","",$var);
				$finalresultstemp[$j][3]=$this->makebold(strip_tags($var),$keyword,1);
				$var=str_replace("<![CDATA[","",$resultset[6][$k]);
				$var=str_replace("]]>","",$var);
				$finalresultstemp[$j][4]=html_entity_decode($var);
				preg_match("/(.+?)<abstract>(.+?)<\/abstract>(.+?)/i",$resultset[1][$k],$abc);
				if(count($abc)!=0)
				{
					$var=str_replace("<![CDATA[","",$abc[2]);
					$var=str_replace("]]>","",$var);
					$finalresultstemp[$j][1]=$this->makebold(strip_tags($var),$keyword,1);
				}
				else
				{
					$var=str_replace("<![CDATA[","",$resultset[4][$k]);
					$var=str_replace("]]>","",$var);
					$finalresultstemp[$j][1]=$this->makebold(strip_tags($var),$keyword,1);
				}
				$j++;
			}
		}
		elseif($priority_result_status==0 && $rest_api_status==2)
		{
			for($k=0;$k<=($count-$priorityresultcount-1);$k++)
			{
				if($resultset[2][$k]=="")
				break;
				if(($k==0)&&($feelinglucky==1))
				{
					header("Location:".strip_tags($resultset[3][$k]));
					exit(0);
				}
				$finalresultstemp[$j][1]=$this->makebold(strip_tags($resultset[2][$k]),$keyword,1);
				$finalresultstemp[$j][2]=$this->makebold(strip_tags($resultset[5][$k]),$keyword,0);
				$finalresultstemp[$j][3]=$this->makebold(strip_tags($resultset[1][$k]),$keyword,1);
				$finalresultstemp[$j][4]=html_entity_decode($resultset[3][$k]);
				$j++;
			}
		}
		elseif($priority_result_status==1 && $rest_api_status==2)
		{
			for($k=0;$k<=($count+$priorityresultcount);$k++)
			{
				if($resultset[2][$k]=="")
				break;
				if(($k==0)&&($feelinglucky==1))
				{
					header("Location:".strip_tags($resultset[3][$k]));
					exit(0);
				}
				$finalresultstemp[$j][1]=$this->makebold(strip_tags($resultset[2][$k]),$keyword,1);
				$finalresultstemp[$j][2]=$this->makebold(strip_tags($resultset[5][$k]),$keyword,0);
				$finalresultstemp[$j][3]=$this->makebold(strip_tags($resultset[1][$k]),$keyword,1);
				$finalresultstemp[$j][4]=html_entity_decode($resultset[3][$k]);
				$j++;
			}
		}
		elseif($priority_result_status==0 && $rest_api_status==3)
		{
			for($k=0;$k<=($count-$priorityresultcount-1);$k++)
			{
				if($resultset[3][$k]=="")
				break;
				if(($k==0)&&($feelinglucky==1))
				{
					$var=str_replace("<![CDATA[","",$resultset[3][$k]);
					$var=str_replace("]]>","",$var);
					html_entity_decode($var);
					header("Location:".html_entity_decode($var));
					exit(0);
				}
				$var=str_replace("<![CDATA[","",$resultset[2][$k]);
				$var=str_replace("]]>","",$var);
				$finalresultstemp[$j][1]=$this->makebold(strip_tags($var),$keyword,1);
				$var=str_replace("<![CDATA[","",$resultset[3][$k]);
				$var=str_replace("]]>","",$var);
				$var=str_replace("http://","",$var);
				$finalresultstemp[$j][2]=$this->makebold(strip_tags($var),$keyword,0);
				$var=str_replace("<![CDATA[","",$resultset[1][$k]);
				$var=str_replace("]]>","",$var);
				$finalresultstemp[$j][3]=$this->makebold(strip_tags($var),$keyword,1);
				$var=str_replace("<![CDATA[","",$resultset[3][$k]);
				$var=str_replace("]]>","",$var);
				$finalresultstemp[$j][4]=html_entity_decode($var);
				$j++;
			}
		}
		elseif($priority_result_status==1 && $rest_api_status==3)
		{
			for($k=0;$k<=($count+$priorityresultcount);$k++)
			{
				if($resultset[2][$k]=="")
				break;
				if(($k==0)&&($feelinglucky==1))
				{
					$var=str_replace("<![CDATA[","",$resultset[3][$k]);
					$var=str_replace("]]>","",$var);
					html_entity_decode($var);
					header("Location:".html_entity_decode($var));
					exit(0);
				}
				$var=str_replace("<![CDATA[","",$resultset[2][$k]);
				$var=str_replace("]]>","",$var);
				$finalresultstemp[$j][1]=$this->makebold(strip_tags($var),$keyword,0);
				$var=str_replace("<![CDATA[","",$resultset[3][$k]);
				$var=str_replace("]]>","",$var);
				$var=str_replace("http://","",$var);
				$finalresultstemp[$j][2]=$this->makebold(strip_tags($var),$keyword,1);
				$var=str_replace("<![CDATA[","",$resultset[1][$k]);
				$var=str_replace("]]>","",$var);
				$finalresultstemp[$j][3]=$this->makebold(strip_tags($var),$keyword,1);
				$var=str_replace("<![CDATA[","",$resultset[3][$k]);
				$var=str_replace("]]>","",$var);
				$finalresultstemp[$j][4]=html_entity_decode($var);
				$j++;
			}
		}
		for($i=0;$i<count($finalresultstemp);$i++)
		{
			for($j=0;$j<count($finalresultstemp);$j++)
			{
				if($j!=4)
				$finalresultstemp[$i][$j]=$this->makebold($finalresultstemp[$i][$j],$keyword,0);
			}
		}
		return $finalresultstemp;
	}
	function imagesAction($alignment=0)
	{
		$valid=$this->uservalidation();
		$this->setValue("valid",$valid);
		$keyword=$_GET['search'];
		$quotestatus=get_magic_quotes_gpc();
		if($quotestatus==1)
		$keyword=stripslashes($keyword);
		$tabname=$_GET['type'];
		$fl=$_GET['fl'];
		if((!isset($_GET['type']))||($_GET['type']==""))
		$tabname="images";
		if((!isset($_GET['search'])||($_GET['search']=="")))
		$keyword=str_replace("%2NNFF","/",$this->getParam(1));
        $this->setValue("getkeyword",$keyword);
		$suggestion_keyword=$keyword;
		include('script.inc.php');
		include($config_path.'system.config.php');
		if($fl==1)
		$feelinglucky=1;
		$quotestatus=get_magic_quotes_gpc();
		if($quotestatus==1)
		$keyword=stripslashes($keyword);
		$keyword=str_replace('"',' " ',$keyword);
		$keyword=str_replace("'"," ' ",$keyword);
		$keyword=$this->familyfilter($keyword);
		$keyword=str_replace("' ","'",$keyword);
		$keyword=str_replace(" '","'",$keyword);
		$keyword=str_replace('" ','"',$keyword);
		$keyword=str_replace(' "','"',$keyword);
		$this->loadLibrary('Settings');
		$settings=new Settings('nesote_inoutse_settings');
		$settings->loadValues();
		$count=$settings->getValue("image_result_count");
		$lightbox=$settings->getValue("lightbox");
		$this->setValue("lightbox",$lightbox);
		$styleid=$settings->getValue("result");
		$servicename=$settings->getValue("service_name");
		$this->setValue("servicename",$servicename);
		$rest_api_status=$settings->getValue("rest_api_search");
		$this->setValue("yahooboss_status",$rest_api_status);
		$thumbshot_user_override=$settings->getValue("thumbshot_user_override");
	    $this->setValue("thumbshot_useroverride",$thumbshot_user_override);
		$quicklook_user_override=$settings->getValue("quicklook_user_override");
		$this->setValue("qlook_useroverride",$quicklook_user_override);
		$source_status=$settings->getValue("source_status");
		$this->setValue("source_status",$source_status);
        $auto_scroll_status=$settings->getValue("auto_scroll_status");
		$this->setValue("auto_scroll_status",$auto_scroll_status);
		$relatedtag_count=$settings->getValue("related_tags_count");
		$seasonal_logo_status=$settings->getValue("seasonal_logo");
		$star_status=$settings->getValue("star_status");
		$this->setValue("star_status",$star_status);
		$member_status=$settings->getValue("member_status");
		if($member_status==1)
		$comment_status=$settings->getValue("comment_status");
		else
		$comment_status=0;
		$this->setValue("comment_status",$comment_status);
		$db=new NesoteDALController();
		if($seasonal_logo_status==1)
		{
			$time=time();
			$db->select("nesote_inoutse_seasonallogo");
			$db->fields("id,resultpage_logo");
			$db->where("startdate<=? and enddate>=? and status=1",$time);
			$result=$db->query();
			$row=$db->fetchRow($result);
			if($row[1]!="")
			{
				$logostatus=1;
				$userlogo=$row[1];
				$this->setValue("logoid",$row[0]);
			}
			elseif($row[1]=="")
			{
				$logostatus=0;
				$userlogo=$settings->getValue("result_logo");  ////////////     seasonal logo status
			}
		}
		else
		{
			$logostatus=0;
			$userlogo=$settings->getValue("result_logo");
		}
		$this->setValue("logo",$userlogo);
		$this->setValue("logostatus",$logostatus);
		$message=array("servicename"=>$servicename);
		$home=$this->getmessagegrammer(47,$message,0);
		$this->setValue("home",$home);
		$db->select("nesote_inoutse_engines");
		$db->fields("id,search_type");
		$db->where("tab_name=?",$tabname);
		$result=$db->query();
		$row=$db->fetchRow($result);
		$searchtype=$row[1];  // reading search type
		$engineid=$row[0];  // reading engine id
		$this->setValue("engineid",$engineid);
		$enginename=$this->getenginename($engineid);
		define('PAGETITLE',$servicename." - ".$enginename." - ".$keyword);
		define('HEADERKEYWORD',$servicename.",search,search engine,".$keyword.",".$searchtype);
		$typearray=array("type"=>$enginename);
		$typesearch=$this->getmessagegrammer(23,$typearray);
		$this->setValue("typesearch",$typesearch);
		$db= new NesoteDALController();
		$tot=$db->total("nesote_inoutse_engines","tab_name=? and status=?",array($tabname,1));
		if(($keyword=="")||($tot==0))
		{
			if($mod_rewrite==true)
			header("Location:".$this->url("search/noresults?search=$keyword&type=$searchtype"));
			else
			header("Location:".$this->url("search/noresults&search=$keyword&type=$searchtype"));
			exit(0);
		}
		$page=1;
		if(isset($_GET['startpage']))
		$page=$_GET['startpage'];   // reading page value
		if ($page=="")
		$page=1;
		$tabkeyword=str_replace("/","%2NNFF",$keyword);
		$this->setValue("keyword",$tabkeyword);
		$this->setValue("tabname",$tabname);
		$spellurl=$this->getspellurl($keyword,"web",1,0);
		$spellsuggestion=$this->getspellcontent($spellurl,$keyword,$tabname,1,0);
		if($spellsuggestion=="")
		{
			$spellurl=$this->getspellurl($keyword,"web",2,0);
			$spellsuggestion=$this->getspellcontent($spellurl,$keyword,$tabname,2,0);
		}
		if($spellsuggestion!="")
		{
			$spell=array("spell"=>$spellsuggestion);
			$style=array("keyword_in_spellsuggestion_class");
			$spellstr=$this->getmessagegrammer(24,$spell,$style);
			$spellstr=str_replace("<span class=\"keyword_in_spellsuggestion_class\">".$spellsuggestion."</span>","<a class=\"spelllink\" href=\"".$this->url("search/images&search=".$spellsuggestion."&type=$tabname")."\">".$spellsuggestion."</a>",$spellstr);
			$this->setValue("spell","<span class=\"spellsuggestiontext\">".$spellstr."<span>");
		}
		else
		$this->setValue("spell","");
		$xmldata=$this->getmixurlcontents($engineid,$searchtype,$page,$keyword,1);
		$cacheparts=explode("&@&",$xmldata);
		$cachepart1=$cacheparts[0];
		$cachepart2=$cacheparts[1];
$cacheresult=json_decode($cachepart2);
$source=$cacheparts[2];
		if($source!='')
		{
			$sourceresult=json_decode($source);
			foreach($sourceresult->source as $mydata)
		    {
		         $statusarray[1][].=$mydata->sourcestatus;
		    }
		}
		$cacheresultd = json_decode($cachepart1, true);
 		$start=$cacheresultd['start'];
 		$totalcount=$cacheresultd['totalcount'];
 		$backupcount=$cacheresultd['backupcount'];
 		$allstatus=$cacheresultd['allstatus'];
 		$onlygooglestatus=$cacheresultd['onlygooglestatus'];
		$style="";
		$this->setValue("style",$style);
		$resultflag=true;
		$xmldata=str_replace("\r\n","",$xmldata);
		$xmldata=str_replace("\n","",$xmldata);
		$xmldata=str_replace("\r","",$xmldata);
		if($xmldata=="expired")
		{
		$resultflag=false;
		}
		else 
		{
		$totalhits=$totalcount;
		if($allstatus==0)
		{
			$total=$backupcount;
			$total1=$totalhits;
		}
		else
		{
			$onlygoogle=$onlygooglestatus;
			if($onlygoogle==1)
			{
				$total=$totalhits;
				$google_maxcount=$settings->getValue("google_totalfetchingcount");
				if($total>$google_maxcount)
				{
				   $total=$google_maxcount;
				}
			}
			else
			{
				$total=$totalhits;
			}
			$total1=$totalhits;
		}
        $stnum=$start;
		$stnumber=$stnum;
		$this->setValue("totalhits",$total);
		$cacheresultcount=0;
		foreach($cacheresult->item as $mydata)
		{
			$cacheresultcount=$cacheresultcount+1;
		}
		if($cacheresultcount==0)
		{
			$resultflag=false;
		}
		else 
		{
		$style="";
		$this->setValue("style",$style);
		$start=(25*($page-1))%$count;
		$startingnum=($page*25)-24;
		$endingnum=$page*25;
		if($total<$endingnum)
		$endingnum=$total;
		if($total<25)
		$startingnum=1;
		else
		$startingnum=($page*25)-24;
		$totalstring=number_format($total1);
		$message=array("startingnum"=>$startingnum,"endingnum"=>$endingnum,"total"=>$totalstring,"keyword"=>htmlentities($keyword,ENT_QUOTES,"UTF-8"));
		$style=array("resultcountstart","resultcountend","totalresults","keywordintotal");
		$totalstr=$this->getmessagegrammer(8,$message,$style);
		$this->setValue("total",$totalstr);
		$keyword1=urlencode($keyword);
		$keywordsuggestion_status=$db->total("nesote_inoutse_engines","id=? and keyword_suggestion_status=1",array($engineid));
		if($page==1 && $keywordsuggestion_status!=0 && trim($suggestion_keyword)==trim($keyword))
		{
			$tot1=$db->total("nesote_inoutse_keywordsuggestions","engine_id=? and keyword=?",array($engineid,$suggestion_keyword));
			if($tot1==0)
			{
				$db->insert("nesote_inoutse_keywordsuggestions");
				$db->fields("engine_id,keyword,total,searchcount,time");
				$db->values(array($engineid,$suggestion_keyword,$total1,1,time()));
				$db->query();
			}
			else
			{
				$db->update("nesote_inoutse_keywordsuggestions");
				$db->set("searchcount=searchcount+1,time=?,total=?",array(time(),$total1));
				$db->where("engine_id=? and keyword=?",array($engineid,$suggestion_keyword));
				$db->query();
			}
		}
	$previouspage=$page-1;
		if($page<=4)
		{
			$startpage=1;
			$endpage=5;
		}
		else
		{
			$startpage=$page-3;
			$endpage=$page+1;
		}
		$nextpage=$page+1;
		if($page!=1)
		{
		$footerlink.="<li class=\"pgntn-li float-left\"><a class=\"pgntn-a pgn-arw\" href=javascript:loadpage($previouspage)><i class=\"fas fa-chevron-left\"></i></a></li>";
		}
		for($i=$startpage;$i<=$endpage;$i++)
		{
			if($i*25<($total+25))
			{
				if($i!=$page)
				{
					$footerlink.="<li class=\"pgntn-li float-left\"><a class=\"pgntn-a pgn-cnt\" href=javascript:loadpage($i)>$i</a></li>";
				}
				else 
				{
					$footerlink.="<li class=\"pgntn-li float-left\"><a class=\"pgntn-a pgn-cnt pgn-actv\" href=javascript:loadpage($i)>$i</a></li>";
				}
			}
		}
		if($page*25<($total))
		{
		$footerlink.="<li class=\"pgntn-li float-left\"><a class=\"pgntn-a pgn-arw\" href=javascript:loadpage($nextpage)><i class=\"fas fa-chevron-right\"></i></a></li>";
		}
		$this->setValue("footerlink",$footerlink);
		$relatedkeywords=$this->getrelatedkeyword($keyword);
		$finalkeywordarray=[];
		for($i=0;$i<$relatedtag_count;$i++)
		{
			$finalkeywordarray[$i][0]=$relatedkeywords[$i];
		}
		if($finalkeywordarray[0][0]!="")
		$this->setValue("keywordstatus",1);
		else
		$this->setValue("keywordstatus",0);
		$this->setLoopValue("relatedkeywords",$finalkeywordarray);
		$j=0;
			$resultset=[];
foreach($cacheresult->item as $mydata)
    {
         $resultset[1][]=$mydata->type;
    }
foreach($cacheresult->item as $mydata)
    {
         $resultset[2][]=$mydata->width;
    }
foreach($cacheresult->item as $mydata)
    {
         $resultset[3][]=$mydata->imagelocation;
    }
    foreach($cacheresult->item as $mydata)
    {
         $resultset[4][]=$mydata->filesize;
    }
    foreach($cacheresult->item as $mydata)
    {
         $resultset[5][]=$mydata->thumburl;
    }
    foreach($cacheresult->item as $mydata)
    {
         $resultset[6][]=$mydata->title;
    }
    foreach($cacheresult->item as $mydata)
    {
         $resultset[7][]=$mydata->visibleurl;
    }
	foreach($cacheresult->item as $mydata)
    {
         $resultset[8][]=$mydata->height;
    }
	foreach($cacheresult->item as $mydata)
    {
         $resultset[9][]=$mydata->url;
    }
//print_r($resultset);
//exit;
		$finalresult2=$resultset;
		if($cacheresultcount==0)
		{
			$resultflag=false;
		}
		else //if no results 
		{
		$s=($page-1)*25-$stnumber; $u=0;
		$rescnt=count($resultset[1]);
//print_r($resultset); exit;
		if($rescnt>=$s+25)
		{
			for($i=0;$i<25;$i++)
			{
				if($resultset[4][$s]!="")
				{
					$finalresult[$u][1]=$resultset[1][$s];
					$finalresult[$u][2]=$resultset[2][$s];
					$finalresult[$u][3]=$resultset[3][$s];
					$finalresult[$u][4]=$resultset[4][$s];
					$finalresult[$u][5]=$resultset[5][$s];
					$finalresult[$u][6]=$resultset[6][$s];                        
					if(strlen($finalresult[$u][6])>=100)
					$finalresult[$u][6]=substr($finalresult[$u][6],0,100)."...";
					$finalresult[$u][7]=$resultset[7][$s];                          
					if(strlen($finalresult[$u][7])>=60)
					$finalresult[$u][7]=substr($finalresult[$u][7],0,60)."...";
					$finalresult[$u][8]=$resultset[8][$s];
					$finalresult[$u][9]=$resultset[9][$s];
					$finalresult[$u][10]=$statusarray[1][$u];
					$finalresult[$u][11]=$this->getstar($finalresult[$u][3],$engineid);
					$u++;
				}
				$s=$s+1;
			}
		}
		else if($total-$startingnum+1>15)
		{
			$s= $rescnt-25;
			for($i=0;$i<25;$i++)
			{
				if($resultset[4][$s]!="")
				{
					$finalresult[$u][1]=$resultset[1][$s];
					$finalresult[$u][2]=$resultset[2][$s];
					$finalresult[$u][3]=$resultset[3][$s];
					$finalresult[$u][4]=$resultset[4][$s];
					$finalresult[$u][5]=$resultset[5][$s];
					$finalresult[$u][6]=$resultset[6][$s];                           
					if(strlen($finalresult[$u][6])>=100)
					$finalresult[$u][6]=substr($finalresult[$u][6],0,100)."...";
					$finalresult[$u][7]=$resultset[7][$s];                          
					if(strlen($finalresult[$u][7])>=60)
					$finalresult[$u][7]=substr($finalresult[$u][7],0,60)."...";
					$finalresult[$u][8]=$resultset[8][$s];
					$finalresult[$u][9]=$resultset[9][$s];
					$finalresult[$u][10]=$statusarray[1][$u];
					$finalresult[$u][11]=$this->getstar($finalresult[$u][3],$engineid);
					$u++;
				}
				$s=$s+1;
			}
		}
		else if($total-$startingnum+1>0)
		{
			$finish=$total-$startingnum+1;
			$statf=0;
			$s=0;
			for($i=0;$i<$finish;$i++)
			{
				if($resultset[4][$s]!="")
				{
					$finalresult[$u][1]=$resultset[1][$s];
					$finalresult[$u][2]=$resultset[2][$s];
					$finalresult[$u][3]=$resultset[3][$s];
					$finalresult[$u][4]=$resultset[4][$s];
					$finalresult[$u][5]=$resultset[5][$s];
					$finalresult[$u][6]=$resultset[6][$s];                           
					if(strlen($finalresult[$u][6])>=100)
					$finalresult[$u][6]=substr($finalresult[$u][6],0,100)."...";
					$finalresult[$u][7]=$resultset[7][$s];                          
					if(strlen($finalresult[$u][7])>=60)
					$finalresult[$u][7]=substr($finalresult[$u][7],0,60)."...";
					$finalresult[$u][8]=$resultset[8][$s];
					$finalresult[$u][9]=$resultset[9][$s];
					$finalresult[$u][10]=$statusarray[1][$statf];
					$finalresult[$u][11]=$this->getstar($finalresult[$u][3],$engineid);
					$u++; $statf++;
				}
				$s=$s+1;
			}
		}
		else
		{
			$resultflag=false;
		}
		if(($page==1)&&($feelinglucky==1))
		{
			header("Location:".strip_tags($finalresult[0][3]));
			exit(0);
		}
$finalcount=count($finalresult);
		for($i=0;$i<$finalcount;$i++)
		{
			$finalresult[$i][7]=html_entity_decode($this->makebold($finalresult[$i][7],$keyword,0));
		}
		if($finalcount==0)
		{
			$resultflag=false;
		}
		}
		}
		}
		if($resultflag==false)
		{
			$this->setValue("keywordstatus",0);
         $typearray=array("type"=>$enginename);
		$typesearch=$this->getmessagegrammer(23,$typearray);
		$this->setValue("typesearch",$typesearch);
			$this->setValue("comment_status",0);
		list($finalresult,$total) = $this->testapiimagesdataAction($keyword, $page);
		$start=(25*($page-1))%$count;
		$startingnum=($page*25)-24;
		$endingnum=$page*25;
		if($total<$endingnum)
		$endingnum=$total;
		if($total<15)
		$startingnum=1;
		else
		$startingnum=($page*25)-24;
		$totalstring=number_format($total1);
		$message=array("startingnum"=>$startingnum,"endingnum"=>$endingnum,"total"=>$total,"keyword"=>htmlentities($keyword,ENT_QUOTES,"UTF-8"));
		$style=array("resultcountstart","resultcountend","totalresults","keywordintotal");
		$totalstr=$this->getmessagegrammer(8,$message,$style);
		$this->setValue("total",$totalstr);
			$previouspage=$page-1;
		if($page<=4)
		{
			$startpage=1;
			$endpage=5;
		}
		else
		{
			$startpage=$page-3;
			$endpage=$page+1;
		}
		$nextpage=$page+1;
		if($page!=1)
		{
		$footerlink.="<li class=\"pgntn-li float-left\"><a class=\"pgntn-a pgn-arw\" href=javascript:loadpage($previouspage)><i class=\"fas fa-chevron-left\"></i></a></li>";
		}
		for($i=$startpage;$i<=$endpage;$i++)
		{
			if($i*10<($total+10))
			{
				if($i!=$page)
				{
					$footerlink.="<li class=\"pgntn-li float-left\"><a class=\"pgntn-a pgn-cnt\" href=javascript:loadpage($i)>$i</a></li>";
				}
				else 
				{
					$footerlink.="<li class=\"pgntn-li float-left\"><a class=\"pgntn-a pgn-cnt pgn-actv\" href=javascript:loadpage($i)>$i</a></li>";
				}
			}
		}
		if($page*10<($total))
		{
		$footerlink.="<li class=\"pgntn-li float-left\"><a class=\"pgntn-a pgn-arw\" href=javascript:loadpage($nextpage)><i class=\"fas fa-chevron-right\"></i></a></li>";
		}
		$this->setValue("footerlink",$footerlink);
		}
		$this->setLoopValue("results",$finalresult);
	}
	function newsAction($alignment=0)
	{
		$valid=$this->uservalidation();
		$this->setValue("valid",$valid);
		$keyword=$_GET['search'];// reading search keyword
		$quotestatus=get_magic_quotes_gpc();
		if($quotestatus==1)
		$keyword=stripslashes($keyword);
		$tabname=$_GET['type'];//    reading tab name
		$fl=$_GET['fl'];
		if((!isset($_GET['type']))||($_GET['type']==""))
		$tabname="news";
		if((!isset($_GET['search'])||($_GET['search']=="")))
		$keyword=str_replace("%2NNFF","/",$this->getParam(1));
$this->setValue("getkeyword",$keyword);
		$suggestion_keyword=$keyword;
		include('script.inc.php');
		include($config_path.'system.config.php');
		if($fl==1)
		$feelinglucky=1;
		$quotestatus=get_magic_quotes_gpc();
		if($quotestatus==1)
		$keyword=stripslashes($keyword);
		$keyword=str_replace('"',' " ',$keyword);
		$keyword=str_replace("'"," ' ",$keyword);
		$keyword=$this->familyfilter($keyword);
		$keyword=str_replace("' ","'",$keyword);
		$keyword=str_replace(" '","'",$keyword);
		$keyword=str_replace('" ','"',$keyword);
		$keyword=str_replace(' "','"',$keyword);
		$db= new NesoteDALController();
		$db->select("nesote_inoutse_engines");
		$db->fields("id,search_type");
		$db->where("tab_name=?",$tabname);
		$result=$db->query();
		$row=$db->fetchRow($result);
		$searchtype=$row[1];  // reading search type
		$engineid=$row[0];  // reading engine id
		$db= new NesoteDALController();
		$tot=$db->total("nesote_inoutse_engines","tab_name=? and status=?",array($tabname,1));
		if(($keyword=="")||($tot==0))
		{
			if($mod_rewrite==true)
			header("Location:".$this->url("search/noresults?search=$keyword&type=$searchtype"));
			else
			header("Location:".$this->url("search/noresults&search=$keyword&type=$searchtype"));
			exit(0);
		}
		$page=1;
		if(isset($_GET['startpage']))
		$page=$_GET['startpage'];   // reading page value
		if ($page=="")
		$page=1;
		$tabkeyword=str_replace("/","%2NNFF",$keyword);
		$this->setValue("keyword",$tabkeyword);
		$this->setValue("tabname",$tabname);
		$this->setValue("engineid",$engineid);
		$spellurl=$this->getspellurl($keyword,"web",1,0);
		$spellsuggestion=$this->getspellcontent($spellurl,$keyword,$tabname,1,0);
		if($spellsuggestion=="")
		{
			$spellurl=$this->getspellurl($keyword,"web",2,0);
			$spellsuggestion=$this->getspellcontent($spellurl,$keyword,$tabname,2,0);
		}
		if($spellsuggestion!="")
		{
			$spell=array("spell"=>$spellsuggestion);
			$style=array("keyword_in_spellsuggestion_class");
			$spellstr=$this->getmessagegrammer(24,$spell,$style);
			$spellstr=str_replace("<span class=\"keyword_in_spellsuggestion_class\">".$spellsuggestion."</span>","<a class=\"spelllink\" href=\"".$this->url("search/news&search=".$spellsuggestion."&type=$tabname")."\">".$spellsuggestion."</a>",$spellstr);
			$this->setValue("spell","<span class=\"spellsuggestiontext\">".$spellstr."</span>");
		}
		else
		$this->setValue("spell","");
		$this->loadLibrary('Settings');
		$settings=new Settings('nesote_inoutse_settings');
		$settings->loadValues();
		$count=$settings->getValue("result_count");
		$styleid=$settings->getValue("result");
		$openin_newwindow=$settings->getValue("new_window");
		$this->setValue("newwindow",$openin_newwindow);
		$emailafrnd=$settings->getValue("email_a_frnd");
		$this->setValue("emailafrnd",$emailafrnd);
		$quicklook=$settings->getValue("quicklook");
		$this->setValue("quicklook",$quicklook);
		$servicename=$settings->getValue("service_name");
		$this->setValue("servicename",$servicename);
$auto_scroll_status=$settings->getValue("auto_scroll_status");
		$this->setValue("auto_scroll_status",$auto_scroll_status);
		$ad_codes=$settings->getValue("ad_codes");
		$this->setValue("ad_codes",$ad_codes);
		$relatedtag_count=$settings->getValue("related_tags_count");
		$seasonal_logo_status=$settings->getValue("seasonal_logo");
		$star_status=$settings->getValue("star_status");
		$this->setValue("star_status",$star_status);
		$member_status=$settings->getValue("member_status");
		if($member_status==1)
		$comment_status=$settings->getValue("comment_status");
		else
		$comment_status=0;
		$this->setValue("comment_status",$comment_status);
		if($seasonal_logo_status==1)
		{
			$time=time();
			$db= new NesoteDALController();
			$db->select("nesote_inoutse_seasonallogo");
			$db->fields("id,resultpage_logo");
			$db->where("startdate<=? and enddate>=? and status=1",$time);
			$result=$db->query();
			$row=$db->fetchRow($result);
			if($row[1]!="")
			{
				$logostatus=1;
				$userlogo=$row[1];
				$this->setValue("logoid",$row[0]);
			}
			elseif($row[1]=="")
			{
				$logostatus=0;
				$userlogo=$settings->getValue("result_logo");  ////////////     seasonal logo status
			}
		}
		else
		{
			$logostatus=0;
			$userlogo=$settings->getValue("result_logo");
		}
		$this->setValue("logo",$userlogo);
		$this->setValue("logostatus",$logostatus);
		$message=array("servicename"=>$servicename);
		$home=$this->getmessagegrammer(47,$message,0);
		$this->setValue("home",$home);
		$this->setValue("engineid",$engineid);
		$enginename=$this->getenginename($engineid);
		define('PAGETITLE',$servicename." - ".$enginename." - ".$keyword);
                 $this->setValue('pagetitle',$servicename." - ".$enginename." - ".$keyword);
		define('HEADERKEYWORD',$servicename.",search,search engine,".$keyword.",".$searchtype);
		$typearray=array("type"=>$enginename);
		$typesearch=$this->getmessagegrammer(23,$typearray);
		$this->setValue("typesearch",$typesearch);
		$rest_api_status=$settings->getValue("rest_api_search");
		$this->setValue("yahooboss_status",$rest_api_status);
		$resultflag=true;
		$xmldata=$this->getmixurlcontents($engineid,$searchtype,$page,$keyword,1);
		$cacheparts=explode("&@&",$xmldata);
		$cachepart1=$cacheparts[0];
		$cachepart2=$cacheparts[1];
		$source=$cacheparts[2];
		if($source!='')
		{
			$sourceresult=json_decode($source);
			foreach($sourceresult->source as $mydata)
		    {
		         $statusarray[1][].=$mydata->sourcestatus;
		    }
		}
$cacheresult=json_decode($cachepart2);
		$cacheresultd = json_decode($cachepart1, true);
 		$start=$cacheresultd['start'];
 		$totalcount=$cacheresultd['totalcount'];
 		$backupcount=$cacheresultd['backupcount'];
 		$allstatus=$cacheresultd['allstatus'];
 		$onlygooglestatus=$cacheresultd['onlygooglestatus'];
		$xmldata=str_replace("\r\n","",$xmldata);
		$xmldata=str_replace("\n","",$xmldata);
		$xmldata=str_replace("\r","",$xmldata);
		if($xmldata=="expired")
		{
			$resultflag=false;
		}
		else 
		{
		$totalhits=$totalcount;
		if($allstatus==0)
		{
			$total=$backupcount;
			$total1=$totalhits;
		}
		else
		{
			$onlygoogle=$onlygooglestatus;
			if($onlygoogle==1)
			{
				$total=$totalhits;
				$google_maxcount=$settings->getValue("google_totalfetchingcount");
				if($total>$google_maxcount)
				{
				   $total=$google_maxcount;
				}
			}
			else
			{
				$total=$totalhits;
			}
			$total1=$totalhits;
		}
        $stnum=$start;
		$stnumber=$stnum;
		$resultset=[];
foreach($cacheresult->item as $mydata)
    {
         $resultset[2][]=base64_decode($mydata->title);
    }
foreach($cacheresult->item as $mydata)
    {
         $resultset[1][]=$mydata->titleurl;
    }
foreach($cacheresult->item as $mydata)
    {
         $resultset[3][]=base64_decode($mydata->description);
    }
foreach($cacheresult->item as $mydata)
    {
         $resultset[4][]=$mydata->displayurl;
    }
		$this->setValue("totalhits",$total);
		$cacheresultcount=0;
		foreach($cacheresult->item as $mydata)
		{
			$cacheresultcount=$cacheresultcount+1;
		}
		$this->setValue("totalhits",$total);
		if($cacheresultcount==0)
		{
			$resultflag=false;
		}
		else 
		{
		$style="";
		$this->setValue("style",$style);
		$start=(10*($page-1))%$count;
		$startingnum=($page*10)-9;
		$endingnum=$page*10;
		if($total<$endingnum)
		$endingnum=$total;
		if($total<10)
		$startingnum=1;
		else
		$startingnum=($page*10)-9;
		$totalstring=number_format($total1);
		$message=array("startingnum"=>$startingnum,"endingnum"=>$endingnum,"total"=>$totalstring,"keyword"=>htmlentities($keyword,ENT_QUOTES,"UTF-8"));
		$style=array("resultcountstart","resultcountend","totalresults","keywordintotal");
		$totalstr=$this->getmessagegrammer(8,$message,$style);
		$this->setValue("total",$totalstr);
		$keyword1=urlencode($keyword);
		$keywordsuggestion_status=$db->total("nesote_inoutse_engines","id=? and keyword_suggestion_status=1",array($engineid));
		if($page==1 && $keywordsuggestion_status!=0 && trim($suggestion_keyword)==trim($keyword))
		{
			$tot1=$db->total("nesote_inoutse_keywordsuggestions","engine_id=? and keyword=?",array($engineid,$suggestion_keyword));
			if($tot1==0)
			{
				$db->insert("nesote_inoutse_keywordsuggestions");
				$db->fields("engine_id,keyword,total,searchcount,time");
				$db->values(array($engineid,$suggestion_keyword,$total1,1,time()));
				$db->query();
			}
			else
			{
				$db->update("nesote_inoutse_keywordsuggestions");
				$db->set("searchcount=searchcount+1,time=?,total=?",array(time(),$total1));
				$db->where("engine_id=? and keyword=?",array($engineid,$suggestion_keyword));
				$db->query();
			}
		}
		$previouspage=$page-1;
		if($page<=4)
		{
			$startpage=1;
		$endpage=5;
		}
		else
		{
			$startpage=$page-3;
			$endpage=$page+1;
		}
		$nextpage=$page+1;
		if($page!=1)
		{
		$footerlink.="<li class=\"pgntn-li float-left\"><a class=\"pgntn-a pgn-arw\" href=javascript:loadpage($previouspage)><i class=\"fas fa-chevron-left\"></i></a></li>";
		}
		for($i=$startpage;$i<=$endpage;$i++)
		{
			if($i*10<($total+10))
			{
				if($i!=$page)
				{
					$footerlink.="<li class=\"pgntn-li float-left\"><a class=\"pgntn-a pgn-cnt\" href=javascript:loadpage($i)>$i</a></li>";
				}
				else 
				{
					$footerlink.="<li class=\"pgntn-li float-left\"><a class=\"pgntn-a pgn-cnt pgn-actv\" href=javascript:loadpage($i)>$i</a></li>";
				}
			}
		}
		if($page*10<($total))
		{
		$footerlink.="<li class=\"pgntn-li float-left\"><a class=\"pgntn-a pgn-arw\" href=javascript:loadpage($nextpage)><i class=\"fas fa-chevron-right\"></i></a></li>";
		}
		$this->setValue("footerlink",$footerlink);
		$relatedkeywords=$this->getrelatedkeyword($keyword);
		$finalkeywordarray=[];
		for($i=0;$i<$relatedtag_count;$i++)
		{
			$finalkeywordarray[$i][0]=$relatedkeywords[$i];
		}
		if($finalkeywordarray[0][0]!="")
		$this->setValue("keywordstatus",1);
		else
		$this->setValue("keywordstatus",0);
		$this->setLoopValue("relatedkeywords",$finalkeywordarray);
		$s=($page-1)*10-$stnumber; $u=0;
		$rescnt=$cacheresultcount;
		if($rescnt>=$s+10)
		{
			for($i=0;$i<10;$i++)
			{
				if($resultset[4][$s]!="")
				{
					$finalresult[$u][1]=$resultset[3][$s];
					if(strlen($finalresult[$u][1])>=150)
					{  $len=strlen($finalresult[$u][1]);
					$p=strpos($finalresult[$u][1]," ");
					if(($p=="")||($p>150))
					{   
						$fir=substr($finalresult[$u][1],0,150);
						$sec=substr($finalresult[$u][1],151,$len);
						$finalresult[$u][1]=$fir." ".$sec;
					}
					}
					$finalresult[$u][2]=$resultset[4][$s];
					if(strlen($finalresult[$u][2])>=60)                             
					$finalresult[$u][2]=substr($finalresult[$u][2],0,60)."...";
					$finalresult[$u][3]=$resultset[1][$s];                           
					if(strlen($finalresult[$u][3])>=100)
					$finalresult[$u][3]=substr($finalresult[$u][3],0,100)."...";
					$finalresult[$u][4]=$resultset[2][$s];
					$finalresult[$u][5]=$statusarray[1][$u];
					$finalresult[$u][6]=$this->getstar($finalresult[$u][4],$engineid);
					$u++;
				}
				$s=$s+1;
			}
		}
		else if($total-$startingnum+1>10)
		{
			$s= $rescnt-10;
			for($i=0;$i<10;$i++)
			{
				if($resultset[4][$s]!="")
				{
					$finalresult[$u][1]=$resultset[3][$s];
					if(strlen($finalresult[$u][1])>=150)
					{  $len=strlen($finalresult[$u][1]);
					$p=strpos($finalresult[$u][1]," ");
					if(($p=="")||($p>150))
					{   
						$fir=substr($finalresult[$u][1],0,150);
						$sec=substr($finalresult[$u][1],151,$len);
						$finalresult[$u][1]=$fir." ".$sec;
					}
					}
					$finalresult[$u][2]=$resultset[4][$s];
					if(strlen($finalresult[$u][2])>=60)                             
					$finalresult[$u][2]=substr($finalresult[$u][2],0,60)."...";
					$finalresult[$u][3]=$resultset[1][$s];                          
					if(strlen($finalresult[$u][3])>=100)
					$finalresult[$u][3]=substr($finalresult[$u][3],0,100)."...";
					$finalresult[$u][4]=$resultset[2][$s];
					$finalresult[$u][5]=$statusarray[1][$u];
					$finalresult[$u][6]=$this->getstar($finalresult[$u][4],$engineid);
					$u++;
				}
				$s=$s+1;
			}
		}
		else if($total-$startingnum+1>0)
		{
			$finish=$total-$startingnum+1;
			//$statf=10-$finish;
			$statf=0;
			$s=0;
			for($i=0;$i<$finish;$i++)
			{
				if($resultset[4][$s]!="")
				{
					$finalresult[$u][1]=$resultset[3][$s];
					if(strlen($finalresult[$u][1])>=150)
					{  $len=strlen($finalresult[$u][1]);
					$p=strpos($finalresult[$u][1]," ");
					if(($p=="")||($p>150))
					{   
						$fir=substr($finalresult[$u][1],0,150);
						$sec=substr($finalresult[$u][1],151,$len);
						$finalresult[$u][1]=$fir." ".$sec;
					}
					}
					$finalresult[$u][2]=$resultset[4][$s];
					if(strlen($finalresult[$u][2])>=60)                            
					$finalresult[$u][2]=substr($finalresult[$u][2],0,60)."...";
					$finalresult[$u][3]=$resultset[1][$s];                          
					if(strlen($finalresult[$u][3])>=100)
					$finalresult[$u][3]=substr($finalresult[$u][3],0,100)."...";
					$finalresult[$u][4]=$resultset[2][$s];
					$finalresult[$u][5]=$statusarray[1][$statf];
					$finalresult[$u][6]=$this->getstar($finalresult[$u][4],$engineid);
					$u++; $statf++;
				}
				$s=$s+1;
			}
		}
		else
		{
$resultflag=false;
		}
		if(($page==1)&&($feelinglucky==1))
		{
			header("Location:".strip_tags($finalresult[0][4]));
			exit(0);
		}
		if($resultflag==true)
		{
$finalcount=count($finalresult);
		for($i=0;$i<$finalcount;$i++)
		{
			$finalresult[$i][1]=$this->makebold($finalresult[$i][1],$keyword,1);
			$finalresult[$i][2]=$this->makebold($finalresult[$i][2],$keyword,0);
			$finalresult[$i][3]=$this->makebold($finalresult[$i][3],$keyword,0);
		}
		}
		if($finalcount==0)
		{
			$resultflag=false;
		}
		}
		}// xmldata expired
	if($resultflag==false)
		{
			list($finalresult,$totals)=$this->getalturlcontentdata($searchtype, $page,$keyword);
			$total=$totals[0];
		$previouspage=$page-1;
		if($page<=4)
		{
			$startpage=1;
			$endpage=5;
		}
		else
		{
			$startpage=$page-3;
			$endpage=$page+1;
		}
		$nextpage=$page+1;
		if($page!=1)
		{
		$footerlink.="<li class=\"pgntn-li float-left\"><a class=\"pgntn-a pgn-arw\" href=javascript:loadpage($previouspage)><i class=\"fas fa-chevron-left\"></i></a></li>";
		}
		for($i=$startpage;$i<=$endpage;$i++)
		{
			if($i*10<($total+10))
			{
				if($i!=$page)
				{
					$footerlink.="<li class=\"pgntn-li float-left\"><a class=\"pgntn-a pgn-cnt\" href=javascript:loadpage($i)>$i</a></li>";
				}
				else 
				{
					$footerlink.="<li class=\"pgntn-li float-left\"><a class=\"pgntn-a pgn-cnt pgn-actv\" href=javascript:loadpage($i)>$i</a></li>";
				}
			}
		}
		if($page*10<($total))
		{
		$footerlink.="<li class=\"pgntn-li float-left\"><a class=\"pgntn-a pgn-arw\" href=javascript:loadpage($nextpage)><i class=\"fas fa-chevron-right\"></i></a></li>";
		}
		$message=array("startingnum"=>1,"endingnum"=>10,"total"=>100,"keyword"=>htmlentities($keyword,ENT_QUOTES,"UTF-8"));
		$style=array("resultcountstart","resultcountend","totalresults","keywordintotal");
		$totalstr=$this->getmessagegrammer(8,$message,$style);
		$this->setValue("total",$totalstr);
			$this->setValue("totalhits","");
			$this->setValue("footerlink",$footerlink);
			$this->setValue("keywordstatus",0);
			$this->setLoopValue("relatedkeywords","");
			$this->setValue("comment_status",0);
		}
		$this->setLoopValue("results",$finalresult);
		$installurl=$settings->getValue("adserver_installurl");
		$authcode=$settings->getValue("adserver_authenticationcode");
		$displayurl=$settings->getValue("adserver_displayurl");
		$topadcount=$settings->getValue("adserver_topadcount");
		$rightadcount=$settings->getValue("adserver_rightadcount");
		$this->setValue("installurl",$installurl);
		$this->setValue("authcode",$authcode);
		$this->setValue("displayurl",$displayurl);
		$this->setValue("topadcount",$topadcount);
		$this->setValue("rightadcount",$rightadcount);
		$webadtype=$settings->getValue("webadtype");
		$this->setValue("webadtype",$webadtype);
		$spnewsadtype=$settings->getValue("spnewsadtype");
		$this->setValue("spnewsadtype",$spnewsadtype);
		$publicadstatus=$settings->getValue("publicadstatus");
		$this->setValue("publicadstatus",$publicadstatus);
		$adserver_installurl=$settings->getValue("adserver_installurl");
		$this->setValue("adserver_installurl",$adserver_installurl);
		if(($installurl!="")&&($authcode!=""))
		{
			if($spnewsadtype==2)
			{
				$sponsoredurl=$installurl."xml-ads.php?user_id=0&auth_code=".$authcode."&start_record=0&count=".$topadcount."&keywords=".urlencode($keyword)."&user_ip=".$_SERVER['REMOTE_ADDR'] ;
				$sponsoredlinks=$this->xmlsponsoredlinks($sponsoredurl);
				$sponsoredlinks=str_replace("\r\n","",$sponsoredlinks);
				$sponsoredlinks=str_replace("\n","",$sponsoredlinks);
				$sponsoredlinks=str_replace("\r","",$sponsoredlinks);
				preg_match_all("/<ad><title>(.+?)<\/title><description>(.+?)<\/description><displayurl>(.+?)<\/displayurl><targeturl>(.+?)<\/targeturl><clickbid>(.+?)<\/clickbid><\/ad>/i",$sponsoredlinks,$sponresults);
				if(count($sponresults[0])!=0)//top array
				{
					$j=0;
					for($i=0;$i<count($sponresults[0]);$i++)
					{
						$var=str_replace("<![CDATA[","",$sponresults[1][$i]);
						$var=str_replace("]]>","",$var);
						$spresult[$j][0]=$this->makebold(strip_tags($var),$keyword,0);
						$var=str_replace("<![CDATA[","",$sponresults[2][$i]);
						$var=str_replace("]]>","",$var);
						$spresult[$j][1]=$this->makebold(strip_tags($var),$keyword,1);
						$var=str_replace("<![CDATA[","",$sponresults[3][$i]);
						$var=str_replace("]]>","",$var);
						$spresult[$j][2]=html_entity_decode($var);
						$var=str_replace("<![CDATA[","",$sponresults[4][$i]);
						$var=str_replace("]]>","",$var);
						$spresult[$j][3]=html_entity_decode($var);
						$j++;
					}
					$j=0;
					for($i=0; $i<$topadcount;$i++)
					{
						if($spresult[$i][0]!="")
						{
							$toparray[$j][0]=$spresult[$i][0];
							$toparray[$j][1]=$spresult[$i][1];
							$toparray[$j][2]=$spresult[$i][2];
							$toparray[$j][3]=$spresult[$i][3];
							$j++;
						}
					}
					if(count($toparray)!=0)
					{
						$this->setValue("tpc","1");
						shuffle($toparray);
						$this->setLoopValue("toparray",$toparray);
					}
					else
					$this->setValue("tpc","0");
				}
				$sponsoredurl2=$installurl."xml-ads.php?user_id=0&auth_code=".$authcode."&start_record=".$topadcount."&count=".$rightadcount."&keywords=".urlencode($keyword)."&user_ip=".$_SERVER['REMOTE_ADDR'] ;
				$sponlinks2=$this->xmlsponsoredlinks($sponsoredurl2);
				$sponlinks2=str_replace("\r\n","",$sponlinks2);
				$sponlinks2=str_replace("\n","",$sponlinks2);
				$sponlinks2=str_replace("\r","",$sponlinks2);
				preg_match_all("/<ad><title>(.+?)<\/title><description>(.+?)<\/description><displayurl>(.+?)<\/displayurl><targeturl>(.+?)<\/targeturl><clickbid>(.+?)<\/clickbid><\/ad>/i",$sponlinks2,$sponresults2);
				if(count($sponresults2[0])!=0)
				{
					$j=0;
					for($i=0;$i<count($sponresults2[0]);$i++)//right array
					{
						$var=str_replace("<![CDATA[","",$sponresults2[1][$i]);
						$var=str_replace("]]>","",$var);
						$spresult2[$j][0]=$this->makebold(strip_tags($var),$keyword,0);
						$var=str_replace("<![CDATA[","",$sponresults2[2][$i]);
						$var=str_replace("]]>","",$var);
						$spresult2[$j][1]=$this->makebold(strip_tags($var),$keyword,1);
						$var=str_replace("<![CDATA[","",$sponresults2[3][$i]);
						$var=str_replace("]]>","",$var);
						$spresult2[$j][2]=html_entity_decode($var);
						$var=str_replace("<![CDATA[","",$sponresults2[4][$i]);
						$var=str_replace("]]>","",$var);
						$spresult2[$j][3]=html_entity_decode($var);
						$j++;
					}
					$j=0;
					for($i=0; $i<$rightadcount;$i++)
					{
						if($spresult2[0][0]!="")
						{
							$rightarray[$j][0]=$spresult2[$i][0];
							$rightarray[$j][1]=$spresult2[$i][1];
							$rightarray[$j][2]=$spresult2[$i][2];
							$rightarray[$j][3]=$spresult2[$i][3];
							$j++;
						}
					}
					if(count($rightarray)!=0)
					{
						$this->setValue("rpc","1");
						shuffle($rightarray);
						$this->setLoopValue("rightarray",$rightarray);
					}
					else
					$this->setValue("rpc","0");
				}
			}
			if((count($rightarray)==0)&&($publicadstatus==1)&&($spnewsadtype==2))
			{
				$publicurl=$installurl."xml-ads.php?user_id=0&auth_code=".$authcode."&start_record=0&count=".$rightadcount."&user_ip=".$_SERVER['REMOTE_ADDR']."&ps=2" ;
				$publiclinks=$this->xmlsponsoredlinks($publicurl);
				$publiclinks=str_replace("\r\n","",$publiclinks);
				$publiclinks=str_replace("\n","",$publiclinks);
				$publiclinks=str_replace("\r","",$publiclinks);
				preg_match_all("/<ad><title>(.+?)<\/title><description>(.+?)<\/description><displayurl>(.+?)<\/displayurl><targeturl>(.+?)<\/targeturl><clickbid>(.+?)<\/clickbid><\/ad>/i",$publiclinks,$pubresults);
			}
			if(count($pubresults[0])!=0)
			{
				$j=0;
				for($i=0;$i<=count($pubresults[0]);$i++)
				{
					$var=str_replace("<![CDATA[","",$pubresults[1][$i]);
					$var=str_replace("]]>","",$var);
					$publicresult[$j][0]=$this->makebold(strip_tags($var),$keyword,0);
					$var=str_replace("<![CDATA[","",$pubresults[2][$i]);
					$var=str_replace("]]>","",$var);
					$publicresult[$j][1]=$this->makebold(strip_tags($var),$keyword,1);
					$var=str_replace("<![CDATA[","",$pubresults[3][$i]);
					$var=str_replace("]]>","",$var);
					$publicresult[$j][2]=html_entity_decode($var);
					$var=str_replace("<![CDATA[","",$pubresults[4][$i]);
					$var=str_replace("]]>","",$var);
					$publicresult[$j][3]=html_entity_decode($var);
					$j++;
				}
				$db= new NesoteDALController();
				$this->loadLibrary('Settings');
				$settings=new Settings('nesote_inoutse_settings');
				$settings->loadValues();
				$rightadcount=$settings->getValue("adserver_rightadcount");
				$j=0;
				for($i=0; $i<$rightadcount;$i++)
				{
					if($publicresult[$i][0]!="")
					{
						$publicarray[$j][0]=$publicresult[$i][0];
						$publicarray[$j][1]=$publicresult[$i][1];
						$publicarray[$j][2]=$publicresult[$i][2];
						$publicarray[$j][3]=$publicresult[$i][3];
						$publicarray[$j][4]=$publicresult[$i][4];
						$j++;
					}
				}
				if(count($publicarray)!=0)
				{
					$this->setValue("rpc","1");
					$this->setLoopValue("rightarray",$publicarray);
				}
				else
				$this->setValue("rpc","0");
			}
		}
	}
	function specialAction($alignment=0)
	{
		$valid=$this->uservalidation();
		$this->setValue("valid",$valid);
		$keyword=$_GET['search'];// reading search keyword
		$quotestatus=get_magic_quotes_gpc();
		if($quotestatus==1)
		$keyword=stripslashes($keyword);
		$tabname=$_GET['type'];//    reading tab name
		$fl=$_GET['fl'];
		if((!isset($_GET['type']))||($_GET['type']==""))
		$tabname=$this->getParam(1);
		if((!isset($_GET['search'])||($_GET['search']=="")))
		$keyword=str_replace("%2NNFF","/",$this->getParam(2));
        $this->setValue("getkeyword",$keyword);
		$suggestion_keyword=$keyword;
		include("script.inc.php");
		include("{$config_path}system.config.php");
		if($fl==1)
		$feelinglucky=1;
		$quotestatus=get_magic_quotes_gpc();
		if($quotestatus==1)
		$keyword=stripslashes($keyword);
		$keyword=str_replace('"',' " ',$keyword);
		$keyword=str_replace("'"," ' ",$keyword);
		$keyword=$this->familyfilter($keyword);
		$keyword=str_replace("' ","'",$keyword);
		$keyword=str_replace(" '","'",$keyword);
		$keyword=str_replace('" ','"',$keyword);
		$keyword=str_replace(' "','"',$keyword);
		$db= new NesoteDALController();
		$db->select("nesote_inoutse_engines");
		$db->fields("id,search_type,tab_name");
		$db->where("tab_name=?",$tabname);
		$result=$db->query();
		$row=$db->fetchRow($result);
		$searchtype=$row[1];  // reading search type
		$engineid=$row[0];  // reading engine id
		$enginename=$row[2];//reading tab name
		$this->setValue("engineid",$engineid);
		$tabkeyword=str_replace("/","%2NNFF",$keyword);
		$this->setValue("keyword",$tabkeyword);
		$this->setValue("tabname",$tabname);
		$db= new NesoteDALController();
		$tot=$db->total("nesote_inoutse_engines","tab_name=? and status=?",array($tabname,1));
		if(($keyword=="")||($tot==0))
		{
			if($mod_rewrite==true)
			header("Location:".$this->url("search/noresults?search=$keyword&type=$enginename"));  // modify path
			else
			header("Location:".$this->url("search/noresults&search=$keyword&type=$enginename")); // modify path
			exit(0);
		}
		$db->select("nesote_inoutse_engines");
		$db->fields("special_status");
		$db->where("tab_name=? and status=?",array($tabname,1));
		$tabstatus=$db->query();
		$statusrow=$db->fetchRow($tabstatus);
		$this->setValue("statusrow",$statusrow[0]);
		$page=1;
		if(isset($_GET['startpage']))
		$page=$_GET['startpage'];   // reading page value
		if ($page=="")
		$page=1;
		$spellurl=$this->getspellurl($keyword,"web",1,0);
		$spellsuggestion=$this->getspellcontent($spellurl,$keyword,$tabname,1,0);
		if($spellsuggestion=="")
		{
			$spellurl=$this->getspellurl($keyword,"web",2,0);
			$spellsuggestion=$this->getspellcontent($spellurl,$keyword,$tabname,2,0);
		}
		if($spellsuggestion!="")
		{
			$spell=array("spell"=>$spellsuggestion);
			$style=array("keyword_in_spellsuggestion_class");
			$spellstr=$this->getmessagegrammer(24,$spell,$style);
			$spellstr=str_replace("<span class=\"keyword_in_spellsuggestion_class\">".$spellsuggestion."</span>","<a class=\"spelllink\" href=\"".$this->url("search/special&search=".$spellsuggestion."&type=$tabname")."\">".$spellsuggestion."</a>",$spellstr);
			$this->setValue("spell","<span class=\"spellsuggestiontext\">".$spellstr."</span>");
		}
		else
		$this->setValue("spell","");
		$xmldata=$this->getmixurlcontents($engineid,$searchtype,$page,$keyword,1);
		$cacheparts=explode("&@&",$xmldata);
		$cachepart1=$cacheparts[0];
		$cachepart2=$cacheparts[1];
		$source=$cacheparts[2];
		if($source!='')
		{
			$sourceresult=json_decode($source);
			foreach($sourceresult->source as $mydata)
		    {
		         $statusarray[1][].=$mydata->sourcestatus;
		    }
		}
		$cacheresult=json_decode($cachepart2);
		$cacheresultd = json_decode($cachepart1, true);
		$start=$cacheresultd['start'];
		$totalcount=$cacheresultd['totalcount'];
		$backupcount=$cacheresultd['backupcount'];
		$allstatus=$cacheresultd['allstatus'];
		$onlygooglestatus=$cacheresultd['onlygooglestatus'];
		$this->loadLibrary('Settings');
		$settings=new Settings('nesote_inoutse_settings');
		$settings->loadValues();
		$count=$settings->getValue("result_count");
		$isbold=$settings->getValue("keyword_bold");
		$relatedtag_count=$settings->getValue("related_tags_count");
		$styleid=$settings->getValue("result");
        $auto_scroll_status=$settings->getValue("auto_scroll_status");
		$this->setValue("auto_scroll_status",$auto_scroll_status);
		$thumbshot=$settings->getValue("thumbshot");
		if($_COOKIE['thumbshot']=="off")
		$thumbshot=0;
		$this->setValue("thumbshotstatus",$thumbshot);
		$thumshot_api=$settings->getValue("thumshot_url");		
		$thumshot_url="http://images.thumbshots.com/image.aspx?cid=$thumshot_api&v=1&w=120px&url=";
		$this->setValue("thumshot_url",$thumshot_url);
		$openin_newwindow=$settings->getValue("new_window");
		$this->setValue("newwindow",$openin_newwindow);
		$emailafrnd=$settings->getValue("email_a_frnd");
		$this->setValue("emailafrnd",$emailafrnd);
		$quicklook=$settings->getValue("quicklook");
		$this->setValue("quicklook",$quicklook);
		$servicename=$settings->getValue("service_name");
		$this->setValue("servicename",$servicename);
		$ad_codes=$settings->getValue("ad_codes");
		$this->setValue("ad_codes",$ad_codes);
		$seasonal_logo_status=$settings->getValue("seasonal_logo");
		$star_status=$settings->getValue("star_status");
		$this->setValue("star_status",$star_status);
		$member_status=$settings->getValue("member_status");
		if($member_status==1)
		$comment_status=$settings->getValue("comment_status");
		else
		$comment_status=0;
		$this->setValue("comment_status",$comment_status);
		if($seasonal_logo_status==1)
		{
			$time=time();
			$db= new NesoteDALController();
			$db->select("nesote_inoutse_seasonallogo");
			$db->fields("id,resultpage_logo");
			$db->where("startdate<=? and enddate>=? and status=1",$time);
			$result=$db->query();
			$row=$db->fetchRow($result);
			if($row[1]!="")
			{
				$logostatus=1;
				$userlogo=$row[1];
				$this->setValue("logoid",$row[0]);
			}
			elseif($row[1]=="")
			{
				$logostatus=0;
				$userlogo=$settings->getValue("result_logo");  ////////////     seasonal logo status
			}
		}
		else
		{
			$logostatus=0;
			$userlogo=$settings->getValue("result_logo");
		}
		$this->setValue("logo",$userlogo);
		$this->setValue("logostatus",$logostatus);
		$rest_api_status=$settings->getValue("rest_api_search");
		$this->setValue("yahooboss_status",$rest_api_status);
		$specialstatus=$this->getspecialstatus($engineid);
		if($specialstatus==2)
		$thumbshot=0;
		else
		$thumbshot=$settings->getValue("thumbshot");
		if($_COOKIE['thumbshot']=="off")
		$thumbshot=0;
		$thumbshot_user_override=$settings->getValue("thumbshot_user_override");
		if(($thumbshot==1)&&($thumbshot_user_override==1))
		{
			$status=1;
			$this->setValue("thumbshotstatus",$status);
		}
		else
		$this->setValue("thumbshotstatus",$thumbshot);
		$message=array("servicename"=>$servicename);
		$home=$this->getmessagegrammer(47,$message,0);
		$this->setValue("home",$home);
		$enginename1=$this->getenginename($engineid);
		define('PAGETITLE',$servicename." - ".$enginename1." - ".$keyword);
		  $this->setValue('pagetitle',$servicename." - ".$enginename1." - ".$keyword);
		define('HEADERKEYWORD',$servicename.",search,search engine,".$keyword.",".$searchtype);
		$typearray=array("type"=>$enginename1)	;
		$typesearch=$this->getmessagegrammer(23,$typearray);
		$this->setValue("typesearch",$typesearch);
		$style="";
		$this->setValue("style",$style);
		$resultflag=true;
		$xmldata=str_replace("\r\n","",$xmldata);
		$xmldata=str_replace("\n","",$xmldata);
		$xmldata=str_replace("\r","",$xmldata);
		if($xmldata=="expired")
		{
			$resultflag=false;
		}
		else //if xmldata
		{
		$totalhits=$totalcount;
		if($allstatus==0)
		{
			$total=$backupcount;
			$total1=$totalhits;
		}
		else
		{
			$onlygoogle=$onlygooglestatus;
			if($onlygoogle==1)
			{
				$total=$totalhits;
				$google_maxcount=$settings->getValue("google_totalfetchingcount");
				if($total>$google_maxcount)
				{
				   $total=$google_maxcount;
				}
			}
			else
			{
				$total=$totalhits;
			}
			$total1=$totalhits;
		}
        $stnum=$start;
		$stnumber=$stnum;
		$this->setValue("totalhits",$total);
		$cacheresultcount=0;
		foreach($cacheresult->item as $mydata)
		{
			$cacheresultcount=$cacheresultcount+1;
		}
		if($cacheresultcount==0)
		{
		$resultflag=false;
		}
		else
		{
		$pagecount=$page*10;
		$start=(10*($page-1))%$count;
		$startingnum=($page*10)-9;
		$endingnum=$page*10;
		if($total<$endingnum)
		$endingnum=$total;
		if($total<10)
		$startingnum=1;
		else
		$startingnum=($page*10)-9;
		$totalstring=number_format($total1);
		$message=array("startingnum"=>$startingnum,"endingnum"=>$endingnum,"total"=>$totalstring,"keyword"=>htmlentities($keyword,ENT_QUOTES,"UTF-8"));
		$style=array("resultcountstart","resultcountend","totalresults","keywordintotal");
		$totalstr=$this->getmessagegrammer(8,$message,$style);
		$this->setValue("total",$totalstr);
		$keyword1=urlencode($keyword);
		$keywordsuggestion_status=$db->total("nesote_inoutse_engines","id=? and keyword_suggestion_status=1",array($engineid));
		if($page==1 && $keywordsuggestion_status!=0 && trim($suggestion_keyword)==trim($keyword))
		{
			$tot1=$db->total("nesote_inoutse_keywordsuggestions","engine_id=? and keyword=?",array($engineid,$suggestion_keyword));
			if($tot1==0)
			{
				$db->insert("nesote_inoutse_keywordsuggestions");
				$db->fields("engine_id,keyword,total,searchcount,time");
				$db->values(array($engineid,$suggestion_keyword,$total1,1,time()));
				$db->query();
			}
			else
			{
				$db->update("nesote_inoutse_keywordsuggestions");
				$db->set("searchcount=searchcount+1,time=?,total=?",array(time(),$total1));
				$db->where("engine_id=? and keyword=?",array($engineid,$suggestion_keyword));
				$db->query();
			}
		}
		$previouspage=$page-1;
		if($page<=4)
		{
			$startpage=1;
			$endpage=5;
		}
		else
		{
			$startpage=$page-3;
			$endpage=$page+1;
		}
		$nextpage=$page+1;
		if($page!=1)
		{
		$footerlink.="<li class=\"pgntn-li float-left\"><a class=\"pgntn-a pgn-arw\" href=javascript:loadpage($previouspage)><i class=\"fas fa-chevron-left\"></i></a></li>";
		}
		for($i=$startpage;$i<=$endpage;$i++)
		{
			if($i*10<($total+10))
			{
				if($i!=$page)
				{
					$footerlink.="<li class=\"pgntn-li float-left\"><a class=\"pgntn-a pgn-cnt\" href=javascript:loadpage($i)>$i</a></li>";
				}
				else 
				{
					$footerlink.="<li class=\"pgntn-li float-left\"><a class=\"pgntn-a pgn-cnt pgn-actv\" href=javascript:loadpage($i)>$i</a></li>";
				}
			}
		}
		if($page*10<($total))
		{
		$footerlink.="<li class=\"pgntn-li float-left\"><a class=\"pgntn-a pgn-arw\" href=javascript:loadpage($nextpage)><i class=\"fas fa-chevron-right\"></i></a></li>";
		}
		$this->setValue("footerlink",$footerlink);
		$relatedkeywords=$this->getrelatedkeyword($keyword);
		$finalkeywordarray=[];
		for($i=0;$i<$relatedtag_count;$i++)
		{
			$finalkeywordarray[$i][0]=$relatedkeywords[$i];
		}
		if($finalkeywordarray[0][0]!="")
		$this->setValue("keywordstatus",1);
		else
		$this->setValue("keywordstatus",0);
		$this->setLoopValue("relatedkeywords",$finalkeywordarray);
		$s=($page-1)*10-$stnumber; $u=0;
		$resultset=[];
foreach($cacheresult->item as $mydata)
    {
         $resultset[2][]=$mydata->titleurl;
    }
foreach($cacheresult->item as $mydata)
    {
         $resultset[1][]=base64_decode($mydata->title);
    }
foreach($cacheresult->item as $mydata)
    {
         $resultset[3][]=base64_decode($mydata->description);
    }
foreach($cacheresult->item as $mydata)
    {
         $resultset[4][]=$mydata->displayurl;
    }
		$rescnt=$cacheresultcount;
		if($rescnt>=$s+10)
		{
			for($i=0;$i<10;$i++)
			{
				if($resultset[4][$s]!="")
				{
					$finalresult[$u][1]=$resultset[3][$s];
					if(strlen($finalresult[$u][1])>=150)
					{  $len=strlen($finalresult[$u][1]);
					$p=strpos($finalresult[$u][1]," ");
					if(($p=="")||($p>150))
					{   
						$fir=substr($finalresult[$u][1],0,150);
						$sec=substr($finalresult[$u][1],151,$len);
						$finalresult[$u][1]=$fir." ".$sec;
					}
					}
					$finalresult[$u][2]=$resultset[4][$s];
					if(strlen($finalresult[$u][2])>=60)                            
					$finalresult[$u][2]=substr($finalresult[$u][2],0,60)."...";
					$finalresult[$u][3]=$resultset[1][$s];                           
					if(strlen($finalresult[$u][3])>=100)
					$finalresult[$u][3]=substr($finalresult[$u][3],0,100)."...";
					$finalresult[$u][4]=$resultset[2][$s];
					$finalresult[$u][5]=$statusarray[1][$u];
					$finalresult[$u][6]=$this->getstar($finalresult[$u][4],$engineid);
					$u++;
				}
				$s=$s+1;
			}
		}
		else if($total-$startingnum+1>10)
		{
			$s= $rescnt-10;
			for($i=0;$i<10;$i++)
			{
				if($resultset[4][$s]!="")
				{
					$finalresult[$u][1]=$resultset[3][$s];
					if(strlen($finalresult[$u][1])>=150)
					{  $len=strlen($finalresult[$u][1]);
					$p=strpos($finalresult[$u][1]," ");
					if(($p=="")||($p>150))
					{  
						$fir=substr($finalresult[$u][1],0,150);
						$sec=substr($finalresult[$u][1],151,$len);
						$finalresult[$u][1]=$fir." ".$sec;
					}
					}
					$finalresult[$u][2]=$resultset[4][$s];
					if(strlen($finalresult[$u][2])>=60)                           
					$finalresult[$u][2]=substr($finalresult[$u][2],0,60)."...";
					$finalresult[$u][3]=$resultset[1][$s];                           
					if(strlen($finalresult[$u][3])>=100)
					$finalresult[$u][3]=substr($finalresult[$u][3],0,100)."...";
					$finalresult[$u][4]=$resultset[2][$s];
					$finalresult[$u][5]=$statusarray[1][$u];
					$finalresult[$u][6]=$this->getstar($finalresult[$u][4],$engineid);
					$u++;
				}
				$s=$s+1;
			}
		}
		else if($total-$startingnum+1>0)
		{
			$finish=$total-$startingnum+1;
			$statf=0;
			$s=0;
			for($i=0;$i<$finish;$i++)
			{
				if($resultset[4][$s]!="")
				{
					$finalresult[$u][1]=$resultset[3][$s];
					if(strlen($finalresult[$u][1])>=150)
					{  $len=strlen($finalresult[$u][1]);
					$p=strpos($finalresult[$u][1]," ");
					if(($p=="")||($p>150))
					{   
						$fir=substr($finalresult[$u][1],0,150);
						$sec=substr($finalresult[$u][1],151,$len);
						$finalresult[$u][1]=$fir." ".$sec;
					}
					}
					$finalresult[$u][2]=$resultset[4][$s];
					if(strlen($finalresult[$u][2])>=60)                            
					$finalresult[$u][2]=substr($finalresult[$u][2],0,60)."...";
					$finalresult[$u][3]=$resultset[1][$s];                          
					if(strlen($finalresult[$u][3])>=100)
					$finalresult[$u][3]=substr($finalresult[$u][3],0,100)."...";
					$finalresult[$u][4]=$resultset[2][$s];
					$finalresult[$u][5]=$statusarray[1][$statf];
					$finalresult[$u][6]=$this->getstar($finalresult[$u][4],$engineid);
					$u++; $statf++;
				}
				$s=$s+1;
			}
		}
		else
		{
			$resultflag=false;
		}
		if(($page==1)&&($feelinglucky==1))
		{
			header("Location:".strip_tags($finalresult[0][4]));
			exit(0);
		}
		if($resultflag==true)
		{
$finalcount=count($finalresult);
		for($i=0;$i<$finalcount;$i++)
		{
			$finalresult[$i][1]=$this->makebold($finalresult[$i][1],$keyword,1);
			$finalresult[$i][2]=$this->makebold($finalresult[$i][2],$keyword,0);
			$finalresult[$i][3]=$this->makebold($finalresult[$i][3],$keyword,0);
		}
		}
		if($finalcount==0)
		{
			$resultflag=false;
		}
		}//if no results
		}//if xmldata
	if($resultflag==false)
		{
			list($finalresult,$totals)=$this->getalturlcontentdata($searchtype, $page,$keyword);
			$total=$totals[0];
			$previouspage=$page-1;
	if($page<=4)
		{
			$startpage=1;
			$endpage=5;
		}
		else
		{
			$startpage=$page-3;
			$endpage=$page+1;
		}
		$nextpage=$page+1;
		if($page!=1)
		{
		$footerlink.="<li class=\"pgntn-li float-left\"><a class=\"pgntn-a pgn-arw\" href=javascript:loadpage($previouspage)><i class=\"fas fa-chevron-left\"></i></a></li>";
		}
		for($i=$startpage;$i<=$endpage;$i++)
		{
			if($i*10<($total+10))
			{
				if($i!=$page)
				{
					$footerlink.="<li class=\"pgntn-li float-left\"><a class=\"pgntn-a pgn-cnt\" href=javascript:loadpage($i)>$i</a></li>";
				}
				else 
				{
					$footerlink.="<li class=\"pgntn-li float-left\"><a class=\"pgntn-a pgn-cnt pgn-actv\" href=javascript:loadpage($i)>$i</a></li>";
				}
			}
		}
		if($page*10<($total))
		{
		$footerlink.="<li class=\"pgntn-li float-left\"><a class=\"pgntn-a pgn-arw\" href=javascript:loadpage($nextpage)><i class=\"fas fa-chevron-right\"></i></a></li>";
		}
		$message=array("startingnum"=>1,"endingnum"=>10,"total"=>100,"keyword"=>htmlentities($keyword,ENT_QUOTES,"UTF-8"));
		$style=array("resultcountstart","resultcountend","totalresults","keywordintotal");
		$totalstr=$this->getmessagegrammer(8,$message,$style);
		$this->setValue("total",$totalstr);
			$this->setValue("totalhits","");
			$this->setValue("footerlink",$footerlink);
			$this->setValue("keywordstatus",0);
			$this->setLoopValue("relatedkeywords","");
			$this->setValue("comment_status",0);
					}
		$this->setLoopValue("results",$finalresult);
		$installurl=$settings->getValue("adserver_installurl");
		$authcode=$settings->getValue("adserver_authenticationcode");
		$displayurl=$settings->getValue("adserver_displayurl");
		$topadcount=$settings->getValue("adserver_topadcount");
		$rightadcount=$settings->getValue("adserver_rightadcount");
		$this->setValue("installurl",$installurl);
		$this->setValue("authcode",$authcode);
		$this->setValue("displayurl",$displayurl);
		$this->setValue("topadcount",$topadcount);
		$this->setValue("rightadcount",$rightadcount);
		$webadtype=$settings->getValue("webadtype");
		$this->setValue("webadtype",$webadtype);
		$spnewsadtype=$settings->getValue("spnewsadtype");
		$this->setValue("spnewsadtype",$spnewsadtype);
		$publicadstatus=$settings->getValue("publicadstatus");
		$this->setValue("publicadstatus",$publicadstatus);
		$adserver_installurl=$settings->getValue("adserver_installurl");
		$this->setValue("adserver_installurl",$adserver_installurl);
		if(($installurl!="")&&($authcode!=""))
		{
			if($spnewsadtype==2)
			{
				$sponsoredurl=$installurl."xml-ads.php?user_id=0&auth_code=".$authcode."&start_record=0&count=".$topadcount."&keywords=".urlencode($keyword)."&user_ip=".$_SERVER['REMOTE_ADDR'] ;
				$sponsoredlinks=$this->xmlsponsoredlinks($sponsoredurl);
				$sponsoredlinks=str_replace("\r\n","",$sponsoredlinks);
				$sponsoredlinks=str_replace("\n","",$sponsoredlinks);
				$sponsoredlinks=str_replace("\r","",$sponsoredlinks);
				preg_match_all("/<ad><title>(.+?)<\/title><description>(.+?)<\/description><displayurl>(.+?)<\/displayurl><targeturl>(.+?)<\/targeturl><clickbid>(.+?)<\/clickbid><\/ad>/i",$sponsoredlinks,$sponresults);
				if(count($sponresults[0])!=0)//top array
				{
					$j=0;
					for($i=0;$i<count($sponresults[0]);$i++)
					{
						$var=str_replace("<![CDATA[","",$sponresults[1][$i]);
						$var=str_replace("]]>","",$var);
						$spresult[$j][0]=$this->makebold(strip_tags($var),$keyword,0);
						$var=str_replace("<![CDATA[","",$sponresults[2][$i]);
						$var=str_replace("]]>","",$var);
						$spresult[$j][1]=$this->makebold(strip_tags($var),$keyword,1);
						$var=str_replace("<![CDATA[","",$sponresults[3][$i]);
						$var=str_replace("]]>","",$var);
						$spresult[$j][2]=html_entity_decode($var);
						$var=str_replace("<![CDATA[","",$sponresults[4][$i]);
						$var=str_replace("]]>","",$var);
						$spresult[$j][3]=html_entity_decode($var);
						$j++;
					}
					$j=0;
					for($i=0; $i<$topadcount;$i++)
					{
						if($spresult[$i][0]!="")
						{
							$toparray[$j][0]=$spresult[$i][0];
							$toparray[$j][1]=$spresult[$i][1];
							$toparray[$j][2]=$spresult[$i][2];
							$toparray[$j][3]=$spresult[$i][3];
							$j++;
						}
					}
					if(count($toparray)!=0)
					{
						$this->setValue("tpc","1");
						shuffle($toparray);
						$this->setLoopValue("toparray",$toparray);
					}
					else
					$this->setValue("tpc","0");
				}
				$sponsoredurl2=$installurl."xml-ads.php?user_id=0&auth_code=".$authcode."&start_record=".$topadcount."&count=".$rightadcount."&keywords=".urlencode($keyword)."&user_ip=".$_SERVER['REMOTE_ADDR'] ;
				$sponlinks2=$this->xmlsponsoredlinks($sponsoredurl2);
				$sponlinks2=str_replace("\r\n","",$sponlinks2);
				$sponlinks2=str_replace("\n","",$sponlinks2);
				$sponlinks2=str_replace("\r","",$sponlinks2);
				preg_match_all("/<ad><title>(.+?)<\/title><description>(.+?)<\/description><displayurl>(.+?)<\/displayurl><targeturl>(.+?)<\/targeturl><clickbid>(.+?)<\/clickbid><\/ad>/i",$sponlinks2,$sponresults2);
				if(count($sponresults2[0])!=0)
				{
					$j=0;
					for($i=0;$i<count($sponresults2[0]);$i++)//right array
					{
						$var=str_replace("<![CDATA[","",$sponresults2[1][$i]);
						$var=str_replace("]]>","",$var);
						$spresult2[$j][0]=$this->makebold(strip_tags($var),$keyword,0);
						$var=str_replace("<![CDATA[","",$sponresults2[2][$i]);
						$var=str_replace("]]>","",$var);
						$spresult2[$j][1]=$this->makebold(strip_tags($var),$keyword,1);
						$var=str_replace("<![CDATA[","",$sponresults2[3][$i]);
						$var=str_replace("]]>","",$var);
						$spresult2[$j][2]=html_entity_decode($var);
						$var=str_replace("<![CDATA[","",$sponresults2[4][$i]);
						$var=str_replace("]]>","",$var);
						$spresult2[$j][3]=html_entity_decode($var);
						$j++;
					}
					$j=0;
					for($i=0; $i<$rightadcount;$i++)
					{
						if($spresult2[0][0]!="")
						{
							$rightarray[$j][0]=$spresult2[$i][0];
							$rightarray[$j][1]=$spresult2[$i][1];
							$rightarray[$j][2]=$spresult2[$i][2];
							$rightarray[$j][3]=$spresult2[$i][3];
							$j++;
						}
					}
					if(count($rightarray)!=0)
					{
						$this->setValue("rpc","1");
						shuffle($rightarray);
						$this->setLoopValue("rightarray",$rightarray);
					}
					else
					$this->setValue("rpc","0");
				}
			}
			if((count($rightarray)==0)&&($publicadstatus==1)&&($spnewsadtype==2))
			{
				$publicurl=$installurl."xml-ads.php?user_id=0&auth_code=".$authcode."&start_record=0&count=".$rightadcount."&user_ip=".$_SERVER['REMOTE_ADDR']."&ps=2" ;
				$publiclinks=$this->xmlsponsoredlinks($publicurl);
				$publiclinks=str_replace("\r\n","",$publiclinks);
				$publiclinks=str_replace("\n","",$publiclinks);
				$publiclinks=str_replace("\r","",$publiclinks);
				preg_match_all("/<ad><title>(.+?)<\/title><description>(.+?)<\/description><displayurl>(.+?)<\/displayurl><targeturl>(.+?)<\/targeturl><clickbid>(.+?)<\/clickbid><\/ad>/i",$publiclinks,$pubresults);
			}
			if(count($pubresults[0])!=0)
			{
				$j=0;
				for($i=0;$i<=count($pubresults[0]);$i++)
				{
					$var=str_replace("<![CDATA[","",$pubresults[1][$i]);
					$var=str_replace("]]>","",$var);
					$publicresult[$j][0]=$this->makebold(strip_tags($var),$keyword,0);
					$var=str_replace("<![CDATA[","",$pubresults[2][$i]);
					$var=str_replace("]]>","",$var);
					$publicresult[$j][1]=$this->makebold(strip_tags($var),$keyword,1);
					$var=str_replace("<![CDATA[","",$pubresults[3][$i]);
					$var=str_replace("]]>","",$var);
					$publicresult[$j][2]=html_entity_decode($var);
					$var=str_replace("<![CDATA[","",$pubresults[4][$i]);
					$var=str_replace("]]>","",$var);
					$publicresult[$j][3]=html_entity_decode($var);
					$j++;
				}
				$db= new NesoteDALController();
				$this->loadLibrary('Settings');
				$settings=new Settings('nesote_inoutse_settings');
				$settings->loadValues();
				$rightadcount=$settings->getValue("adserver_rightadcount");
				$j=0;
				for($i=0; $i<$rightadcount;$i++)
				{
					if($publicresult[$i][0]!="")
					{
						$publicarray[$j][0]=$publicresult[$i][0];
						$publicarray[$j][1]=$publicresult[$i][1];
						$publicarray[$j][2]=$publicresult[$i][2];
						$publicarray[$j][3]=$publicresult[$i][3];
						$j++;
					}
				}
				if(count($publicarray)!=0)
				{
					$this->setValue("rpc","1");
					$this->setLoopValue("rightarray",$publicarray);
				}
				else
				$this->setValue("rpc","0");
			}
		}
	}
	function videosAction($alignment=0)
	{
		$valid=$this->uservalidation();
		$this->setValue("valid",$valid);
		$keyword=$_GET['search'];// reading search keyword
		$quotestatus=get_magic_quotes_gpc();
		if($quotestatus==1)
		$keyword=stripslashes($keyword);
		$tabname=$_GET['type'];//    reading tab name
		$fl=$_GET['fl'];
		if((!isset($_GET['type']))||($_GET['type']==""))
		$tabname="videos";
		if((!isset($_GET['search'])||($_GET['search']=="")))
		$keyword=str_replace("%2NNFF","/",$this->getParam(1));
		$this->setValue("getkeyword",$keyword);
		$suggestion_keyword=$keyword;
		include('script.inc.php');
		include($config_path.'system.config.php');
		if($fl==1)
		$feelinglucky=1;
		$quotestatus=get_magic_quotes_gpc();
		if($quotestatus==1)
		$keyword=stripslashes($keyword);
		$keyword=str_replace('"',' " ',$keyword);
		$keyword=str_replace("'"," ' ",$keyword);
		$keyword=$this->familyfilter($keyword);
		$keyword=str_replace("' ","'",$keyword);
		$keyword=str_replace(" '","'",$keyword);
		$keyword=str_replace('" ','"',$keyword);
		$keyword=str_replace(' "','"',$keyword);
		$db= new NesoteDALController();
		$db->select("nesote_inoutse_engines");
		$db->fields("id,search_type");
		$db->where("tab_name=?",$tabname);
		$result=$db->query();
		$row=$db->fetchRow($result);
		$searchtype=$row[1];  // reading search type
		$engineid=$row[0];  // reading engine id
		$this->loadLibrary('Settings');
		$settings=new Settings('nesote_inoutse_settings');
		$settings->loadValues();
		$mixing_video_status=$settings->getValue("mixing_video_status");
		$this->setValue("mix",$mixing_video_status);
		$mixing_video_sources=$settings->getValue("video_api_search");
		$this->setValue("bingonly",$mixing_video_sources);
		$db= new NesoteDALController();
		$tot=$db->total("nesote_inoutse_engines","tab_name=? and status=?",array($tabname,1));
		if(($keyword=="")||($tot==0))
		{
			if($mod_rewrite==true)
			header("Location:".$this->url("search/noresults?search=$keyword&type=$searchtype"));
			else
			header("Location:".$this->url("search/noresults&search=$keyword&type=$searchtype"));
			exit(0);
		}
		$page=1;
		if(isset($_GET['startpage']))
		$page=$_GET['startpage'];   // reading page value
		if ($page=="")
		$page=1;
		$tabkeyword=str_replace("/","%2NNFF",$keyword);
		$this->setValue("keyword",$tabkeyword);
		$this->setValue("tabname",$tabname);
		$spellurl=$this->getspellurl($keyword,"web",1,0);
		$spellsuggestion=$this->getspellcontent($spellurl,$keyword,$tabname,1,0);
		if($spellsuggestion=="")
		{
			$spellurl=$this->getspellurl($keyword,"web",2,0);
			$spellsuggestion=$this->getspellcontent($spellurl,$keyword,$tabname,2,0);
		}
		if($spellsuggestion!="")
		{
			$spell=array("spell"=>$spellsuggestion);
			$style=array("keyword_in_spellsuggestion_class");
			$spellstr=$this->getmessagegrammer(24,$spell,$style);
			$spellstr=str_replace("<span class=\"keyword_in_spellsuggestion_class\">".$spellsuggestion."</span>","<a class=\"spelllink\" href=\"".$this->url("search/videos&search=".$spellsuggestion."&type=$tabname")."\">".$spellsuggestion."</a>",$spellstr);
			$this->setValue("spell","<span class=\"spellsuggestiontext\">".$spellstr."</span>");
		}
		else
		$this->setValue("spell","");
		$this->loadLibrary('Settings');
		$settings=new Settings('nesote_inoutse_settings');
		$settings->loadValues();
		$count=$settings->getValue("image_result_count");
		$this->setValue("lightbox",$lightbox);
		$servicename=$settings->getValue("service_name");
		$this->setValue("servicename",$servicename);
		$source_status=$settings->getValue("source_status");
		$this->setValue("source_status",$source_status);
$auto_scroll_status=$settings->getValue("auto_scroll_status");
		$this->setValue("auto_scroll_status",$auto_scroll_status);
		$styleid=$settings->getValue("result");
		$relatedtag_count=$settings->getValue("related_tags_count");
		$seasonal_logo_status=$settings->getValue("seasonal_logo");
		$star_status=$settings->getValue("star_status");
		$this->setValue("star_status",$star_status);
		$member_status=$settings->getValue("member_status");
		if($member_status==1)
		$comment_status=$settings->getValue("comment_status");
		else
		$comment_status=0;
		$this->setValue("comment_status",$comment_status);
		if($seasonal_logo_status==1)
		{
			$time=time();
			$db= new NesoteDALController();
			$db->select("nesote_inoutse_seasonallogo");
			$db->fields("id,resultpage_logo");
			$db->where("startdate<=? and enddate>=? and status=1",$time);
			$result=$db->query();
			$row=$db->fetchRow($result);
			if($row[1]!="")
			{
				$logostatus=1;
				$userlogo=$row[1];
				$this->setValue("logoid",$row[0]);
			}
			elseif($row[1]=="")
			{
				$logostatus=0;
				$userlogo=$settings->getValue("result_logo");  ////////////     seasonal logo status
			}
		}
		else
		{
			$logostatus=0;
			$userlogo=$settings->getValue("result_logo");
		}
		$this->setValue("logo",$userlogo);
		$this->setValue("logostatus",$logostatus);
		$video_api_status=$settings->getValue("video_api_search");
		$this->setValue("yahooboss_status",$video_api_status);
		$xmldata=$this->getmixurlcontents($engineid,$searchtype,$page,$keyword,1);
		$cacheparts=explode("&@&",$xmldata);
		$cachepart1=$cacheparts[0];
		$cachepart2=$cacheparts[1];
		 $source=$cacheparts[2];
		if($source!='')
		{
			$sourceresult=json_decode($source);
			foreach($sourceresult->source as $mydata)
		    {
		         $statusarray[1][].=$mydata->sourcestatus;
		    }
		}
		$next=$cacheparts[3];
		$prev=$cacheparts[4];
		$cacheresult=json_decode($cachepart2);
		$cacheresultd = json_decode($cachepart1, true);
 		$start=$cacheresultd['start'];
 		$totalcount=$cacheresultd['totalcount'];
 		$backupcount=$cacheresultd['backupcount'];
 		$allstatus=$cacheresultd['allstatus'];
 		$onlygooglestatus=$cacheresultd['onlygooglestatus'];
 		$totalhits=$totalcount;
		$xmldata=str_replace("\r\n","",$xmldata);
		$xmldata=str_replace("\n","",$xmldata);
		$xmldata=str_replace("\r","",$xmldata);
		if($xmldata=="expired")
		{
			if($mod_rewrite==true)
			header("Location:".$this->url("search/noresults?search=$keyword&type=$searchtype&status=$xmldata"));
			else
			header("Location:".$this->url("search/noresults&search=$keyword&type=$searchtype&status=$xmldata"));
			exit(0);
		}
 $prev=$prev;
		$next=$next;
		if($allstatus==0)
		{
			$total=$totalhits;
			$total1=$totalhits;
		}
		else
		{
			$total=$totalhits;
			$total1=$totalhits;
		}
		$stnum=$start;
		$stnumber=$stnum;
		$this->setValue("totalhits",$total);
		$this->setValue("total",$total);
		$cacheresultcount=0;
		foreach($cacheresult->item as $mydata)
		{
		$cacheresultcount=$cacheresultcount+1;
		}
		if($cacheresultcount==0)
		{
		if($mod_rewrite==true)
		header("Location:".$this->url("search/noresults?search=$keyword&type=$searchtype"));
		else
		header("Location:".$this->url("search/noresults&search=$keyword&type=$searchtype"));
		exit(0);
		}
		$message=array("servicename"=>$servicename);
		$home=$this->getmessagegrammer(47,$message,0);
		$this->setValue("home",$home);
		$this->setValue("engineid",$engineid);
		$enginename=$this->getenginename($engineid);
		define('PAGETITLE',$servicename." - ".$enginename." - ".$keyword);
                $this->setValue('PAGETITLE',$servicename." - ".$enginename." - ".$keyword);
		define('HEADERKEYWORD',$servicename.",search,search engine,".$keyword.",".$searchtype);
		$typearray=array("type"=>$enginename);
		$typesearch=$this->getmessagegrammer(23,$typearray);
		$this->setValue("typesearch",$typesearch);
		$style="";
		$this->setValue("style",$style);
		$start=((15*($page-1))%$count);
		$startingnum=($page*15)-14;
		$endingnum=$page*15;
		if($total<$endingnum)
		$endingnum=$total;
		if($total<15)
		$startingnum=1;
		else
		$startingnum=($page*15)-14;
		$totalstring=number_format($total1);
		$message=array("startingnum"=>$startingnum,"endingnum"=>$endingnum,"total"=>$totalstring,"keyword"=>htmlentities($keyword,ENT_QUOTES,"UTF-8"));
		$style=array("resultcountstart","resultcountend","totalresults","keywordintotal");
		$totalstr=$this->getmessagegrammer(8,$message,$style);
		$this->setValue("total",$totalstr);
		$keyword1=urlencode($keyword);
		$keywordsuggestion_status=$db->total("nesote_inoutse_engines","id=? and keyword_suggestion_status=1",array($engineid));
		if($page==1 && $keywordsuggestion_status!=0 && trim($suggestion_keyword)==trim($keyword))
		{
			$tot1=$db->total("nesote_inoutse_keywordsuggestions","engine_id=? and keyword=?",array($engineid,$suggestion_keyword));
			if($tot1==0)
			{
				$db->insert("nesote_inoutse_keywordsuggestions");
				$db->fields("engine_id,keyword,total,searchcount,time");
				$db->values(array($engineid,$suggestion_keyword,$total1,1,time()));
				$db->query();
			}
			else
			{
				$db->update("nesote_inoutse_keywordsuggestions");
				$db->set("searchcount=searchcount+1,time=?,total=?",array(time(),$total1));
				$db->where("engine_id=? and keyword=?",array($engineid,$suggestion_keyword));
				$db->query();
			}
		}
		$previouspage=$page-1;
		if($page<=4)
		{
			$startpage=1;
			$endpage=7;
		}
		else
		{
			$startpage=$page-3;
			$endpage=$page+3;
		}
		$nextpage=$page+1;
			if($page!=1)
		{
		$footerlink.="<li class=\"pgntn-li float-left\"><a class=\"pgntn-a pgn-arw\" href=javascript:loadpage($previouspage,'$prev')><i class=\"fas fa-chevron-left\"></i></a></li>";
		}
		if($page*10<($total))
		{
		$footerlink.="<li class=\"pgntn-li float-left\"><a class=\"pgntn-a pgn-arw\" href=javascript:loadpage($nextpage,'$next')><i class=\"fas fa-chevron-right\"></i></a></li>";
		}
			$this->setValue("footerlink",$footerlink);
		$relatedkeywords=$this->getrelatedkeyword($keyword);
		$finalkeywordarray=[];
		for($i=0;$i<$relatedtag_count;$i++)
		{
			$finalkeywordarray[$i][0]=$relatedkeywords[$i];
		}
		if($finalkeywordarray[0][0]!="")
		$this->setValue("keywordstatus",1);
		else
		$this->setValue("keywordstatus",0);
		$this->setLoopValue("relatedkeywords",$finalkeywordarray);
		$j=0;
			$resultset=[];
foreach($cacheresult->item as $mydata)
    {
         $resultset[1][]=$mydata->title;
    }
foreach($cacheresult->item as $mydata)
    {
         $resultset[2][]=$mydata->titleurl;
    }
foreach($cacheresult->item as $mydata)
    {
         $resultset[3][]=$mydata->imageurl;
    }
    foreach($cacheresult->item as $mydata)
    {
         $resultset[4][]=$mydata->duration;
    }
		$finalresult2=$resultset;
		if($cacheresultcount==0)
		{
			$keyword=urlencode($keyword);
			include('script.inc.php');
			include($config_path.'system.config.php');
			if($mod_rewrite==true)
			header("Location:".$this->url("search/noresults?search=$keyword&type=$searchtype"));
			else
			header("Location:".$this->url("search/noresults&search=$keyword&type=$searchtype"));
			exit(0);
		}
		$s=($page-1)*15-$stnumber; $u=0;
		$rescnt=count($resultset[1]);
		if($rescnt>=$s+15)
		{
			for($i=0;$i<15;$i++)
			{
				if($resultset[4][$s]!="")
				{
					$finalresult[$u][1]=$resultset[3][$s];
					if(strlen($finalresult[$u][1])>=150)
					{  $len=strlen($finalresult[$u][1]);
					$p=strpos($finalresult[$u][1]," ");
					if(($p=="")||($p>150))
					{  
						$fir=substr($finalresult[$u][1],0,150);
						$sec=substr($finalresult[$u][1],151,$len);
						$finalresult[$u][1]=$fir." ".$sec;
					}
					}
					$finalresult[$u][2]=$resultset[4][$s];
					if(strlen($finalresult[$u][2])>=60)                             
					$finalresult[$u][2]=substr($finalresult[$u][2],0,60)."...";
					$finalresult[$u][3]=$resultset[1][$s];                          
					if(strlen($finalresult[$u][3])>=100)
					$finalresult[$u][3]=substr($finalresult[$u][3],0,100)."...";
					$finalresult[$u][4]=$resultset[2][$s];
					$finalresult[$u][5]=$statusarray[1][$u];
					$finalresult[$u][6]=$this->getstar($finalresult[$u][4],$engineid);
					$u++;
				}
				$s=$s+1;
			}
		}
		else if($total-$startingnum+1>15)
		{
			$s= $rescnt-15;
			for($i=0;$i<15;$i++)
			{
				if($resultset[4][$s]!="")
				{
					$finalresult[$u][1]=$resultset[3][$s];
					if(strlen($finalresult[$u][1])>=150)
					{  $len=strlen($finalresult[$u][1]);
					$p=strpos($finalresult[$u][1]," ");
					if(($p=="")||($p>150))
					{   
						$fir=substr($finalresult[$u][1],0,150);
						$sec=substr($finalresult[$u][1],151,$len);
						$finalresult[$u][1]=$fir." ".$sec;
					}
					}
					$finalresult[$u][2]=$resultset[4][$s];
					if(strlen($finalresult[$u][2])>=60)                            
					$finalresult[$u][2]=substr($finalresult[$u][2],0,60)."...";
					$finalresult[$u][3]=$resultset[1][$s];                           
					if(strlen($finalresult[$u][3])>=100)
					$finalresult[$u][3]=substr($finalresult[$u][3],0,100)."...";
					$finalresult[$u][4]=$resultset[2][$s];
					$finalresult[$u][5]=$statusarray[1][$u];
					$finalresult[$u][6]=$this->getstar($finalresult[$u][4],$engineid);
					$u++;
				}
				$s=$s+1;
			}
		}
		else if($total-$startingnum+1>0)
		{
			$finish=$total-$startingnum+1;
			$statf=0;
			$s=0;
			for($i=0;$i<$finish;$i++)
			{
				if($resultset[4][$s]!="")
				{
					$finalresult[$u][1]=$resultset[3][$s];
					if(strlen($finalresult[$u][1])>=150)
					{  $len=strlen($finalresult[$u][1]);
					$p=strpos($finalresult[$u][1]," ");
					if(($p=="")||($p>150))
					{   
						$fir=substr($finalresult[$u][1],0,150);
						$sec=substr($finalresult[$u][1],151,$len);
						$finalresult[$u][1]=$fir." ".$sec;
					}
					}
					$finalresult[$u][2]=$resultset[4][$s];
					if(strlen($finalresult[$u][2])>=60)                            
					$finalresult[$u][2]=substr($finalresult[$u][2],0,60)."...";
					$finalresult[$u][3]=$resultset[1][$s];                           
					if(strlen($finalresult[$u][3])>=100)
					$finalresult[$u][3]=substr($finalresult[$u][3],0,100)."...";
					$finalresult[$u][4]=$resultset[2][$s];
					$finalresult[$u][5]=$statusarray[1][$statf];
					$finalresult[$u][6]=$this->getstar($finalresult[$u][4],$engineid);
					$u++; $statf++;
				}
				$s=$s+1;
			}
		}
		else
		{
			$keyword=urlencode($keyword);
			include('script.inc.php');
			include($config_path.'system.config.php');
			if($mod_rewrite==true)
			header("Location:".$this->url("search/noresults?search=$keyword&type=$searchtype"));
			else
			header("Location:".$this->url("search/noresults&search=$keyword&type=$searchtype"));
			exit(0);
		}
		if(($page==1)&&($feelinglucky==1))
		{
			header("Location:".strip_tags($finalresult[0][4]));
			exit(0);
		}
$finalcount=count($finalresult);
		if($finalcount==0)
		{
			$keyword=urlencode($keyword);
			include('script.inc.php');
			include($config_path.'system.config.php');
			if($mod_rewrite==true)
			header("Location:".$this->url("search/noresults?search=$keyword&type=$searchtype"));
			else
			header("Location:".$this->url("search/noresults&search=$keyword&type=$searchtype"));
			exit(0);
		}
		$this->setLoopValue("results",$finalresult);
		$this->setValue("nexttoken",$next);
	}
	function datasourceAction($alignment=0)
	{
		$valid=$this->uservalidation();
		$this->setValue("valid",$valid);
		$keyword=$_GET['search'];// reading search keyword
		$quotestatus=get_magic_quotes_gpc();
		if($quotestatus==1)
		$keyword=stripslashes($keyword);
		$tabname=$_GET['type'];//    reading tab name
		$fl=$_GET['fl'];
		if((!isset($_GET['type']))||($_GET['type']==""))
		$tabname=$this->getParam(1);
		if((!isset($_GET['search'])||($_GET['search']=="")))
		$keyword=str_replace("%2NNFF","/",$this->getParam(2));
$this->setValue("getkeyword",$keyword);
		$suggestion_keyword=$keyword;
		include("script.inc.php");
		include("{$config_path}system.config.php");
		if($fl==1)
		$feelinglucky=1;
		$quotestatus=get_magic_quotes_gpc();
		if($quotestatus==1)
		$keyword=stripslashes($keyword);
		$keyword=str_replace('"',' " ',$keyword);
		$keyword=str_replace("'"," ' ",$keyword);
		$keyword=$this->familyfilter($keyword);
		$keyword=str_replace("' ","'",$keyword);
		$keyword=str_replace(" '","'",$keyword);
		$keyword=str_replace('" ','"',$keyword);
		$keyword=str_replace(' "','"',$keyword);
		$db= new NesoteDALController();
		$db->select("nesote_inoutse_engines");
		$db->fields("id,search_type,tab_name");
		$db->where("tab_name=?",$tabname);
		$result=$db->query();
		$row=$db->fetchRow($result);
		$searchtype=$row[1];  // reading search type
		$engineid=$row[0];  // reading engine id
		$enginename=$row[2];//reading tab name
		$this->setValue("engineid",$engineid);
		$tabkeyword=str_replace("/","%2NNFF",$keyword);
		$this->setValue("keyword",$tabkeyword);
		$this->setValue("tabname",$tabname);
		$this->loadLibrary('Settings');
		$settings=new Settings('nesote_inoutse_settings');
		$settings->loadValues();
		$count=$settings->getValue("result_count");
		$db= new NesoteDALController();
		$tot=$db->total("nesote_inoutse_engines","tab_name=? and status=?",array($tabname,1));
		if(($keyword=="")||($tot==0))
		{
			if($mod_rewrite==true)
			header("Location:".$this->url("search/noresults?search=$keyword&type=$enginename"));
			else
			header("Location:".$this->url("search/noresults&search=$keyword&type=$enginename"));
			exit(0);
		}
		$page=1;
		if(isset($_GET['startpage']))
		$page=$_GET['startpage'];   // reading page value
		if ($page=="")
		$page=1;
		$this->loadLibrary('Settings');
		$settings=new Settings('nesote_inoutse_settings');
		$settings->loadValues();
		$count=$settings->getValue("result_count");
		$isbold=$settings->getValue("keyword_bold");
		$relatedtag_count=$settings->getValue("related_tags_count");
		$styleid=$settings->getValue("result");
		$servicename=$settings->getValue("service_name");
		$this->setValue("servicename",$servicename);
		$relatedkeyword_status=$settings->getValue("db_related_keyword");
		$spell_status=$settings->getValue("db_spelling_suggestion");
		$this->setValue("spell_status",$spell_status);
		$star_status=$settings->getValue("star_status");
		$this->setValue("star_status",$star_status);
		$member_status=$settings->getValue("member_status");
		if($member_status==1)
		$comment_status=$settings->getValue("comment_status");
		else
		$comment_status=0;
		$this->setValue("comment_status",$comment_status);
		if($spell_status==1)
		{
			$spellurl=$this->getspellurl($keyword,$engineid);
			$spellsuggestion=$this->getspellcontent($spellurl,$keyword,$tabname);
			if($spellsuggestion!="")
			{
				$spell=array("spell"=>$spellsuggestion);
				$style=array("keyword_in_spellsuggestion_class");
				$spellstr=$this->getmessagegrammer(24,$spell,$style);
				$spellstr=str_replace("<span class=\"keyword_in_spellsuggestion_class\">".$spellsuggestion."</span>","<a class=\"spelllink\" href=\"".$this->url("search/special&search=".$spellsuggestion."&type=$tabname")."\">".$spellsuggestion."</a>",$spellstr);
				$this->setValue("spell","<span class=\"spellsuggestiontext\">".$spellstr."</span>");
			}
			else
			$this->setValue("spell","");
		}
		else
		{
			$this->setValue("spell","");
		}
		$ad_codes=$settings->getValue("ad_codes");
		$this->setValue("ad_codes",$ad_codes);
		$seasonal_logo_status=$settings->getValue("seasonal_logo");
		if($seasonal_logo_status==1)
		{
			$time=time();
			$db= new NesoteDALController();
			$db->select("nesote_inoutse_seasonallogo");
			$db->fields("id,resultpage_logo");
			$db->where("startdate<=? and enddate>=? and status=1",$time);
			$result=$db->query();
			$row=$db->fetchRow($result);
			if($row[1]!="")
			{
				$logostatus=1;
				$userlogo=$row[1];
				$this->setValue("logoid",$row[0]);
			}
			elseif($row[1]=="")
			{
				$logostatus=0;
				$userlogo=$settings->getValue("result_logo");  ////////////     seasonal logo status
			}
		}
		else
		{
			$logostatus=0;
			$userlogo=$settings->getValue("result_logo");
		}
		$this->setValue("logo",$userlogo);
		$this->setValue("logostatus",$logostatus);
		$message=array("servicename"=>$servicename);
		$home=$this->getmessagegrammer(47,$message,0);
		$this->setValue("home",$home);
		$enginename1=$this->getenginename($engineid);
		define('PAGETITLE',$servicename." - ".$enginename1." - ".$keyword);
$this->setValue('pagetitle',$servicename." - ".$enginename1." - ".$keyword);
		define('HEADERKEYWORD',$servicename.",search,search engine,".$keyword.",".$searchtype);
		$typearray=array("type"=>$enginename1)	;
		$typesearch=$this->getmessagegrammer(23,$typearray);
		$this->setValue("typesearch",$typesearch);
		$style="";
		$this->setValue("style",$style);
		$db->select("nesote_inoutse_engines");
		$db->fields("hidden_keyword");
		$db->where("id=?",$engineid);
		$rest=$db->query();
		$frow=$db->fetchRow($rest);
		$hiddenkeyword=$frow[0];   /////////// reading hidden keyword
		if($hiddenkeyword!="")
		$keyword.="+".$hiddenkeyword;
		$pagetmp=$page;
		if($page%($count/10)==0)
		$pagetmp=$pagetmp-1;
		$startpage=($pagetmp-($pagetmp%($count/10)))*10;
        $keyword=urlencode($keyword);
		require("script.inc.php");
		require($config_path."system.config.php");
		$urlreplaces=array();
		$var=$_SERVER['SCRIPT_NAME'];
		$var=substr($var,0,strrpos($var,"/"));
		$hostdir= "http://".$_SERVER['HTTP_HOST']."".$var."/";
		$url=$hostdir."admin/index.php?page=rss/result/$engineid&search=$keyword&start=$startpage&count=$count";
		$xmldata=$this->geturlcontent($url,$engineid,$keyword);
		$xmldata=str_replace("\r\n","",$xmldata);
		$xmldata=str_replace("\n","",$xmldata);
		$xmldata=str_replace("\r","",$xmldata);
		preg_match("/<total>(.+?)<\/total>/i",$xmldata,$totalcount);
		$total=$totalcount[1];
		$resultset=="";
		if($total>0)
		{
			preg_match_all("/<item><data>(.+?)<\/data>/i",$xmldata,$resultset);
		}
		if(count($resultset[0])==0)
		{
			if($mod_rewrite==true)
			header("Location:".$this->url("search/noresults?search=$keyword&type=$enginename"));
			else
			header("Location:".$this->url("search/noresults&search=$keyword&type=$enginename"));
			exit(0);
		}
		$pagecount=$page*10;
		$start=(10*($page-1))%$count;
		$startingnum=($page*10)-9;
		$endingnum=$page*10;
		if($total<$endingnum)
		$endingnum=$total;
		if($total<10)
		$startingnum=1;
		else
		$startingnum=($page*10)-9;
		$totalstring=number_format($total);
		$message=array("startingnum"=>$startingnum,"endingnum"=>$endingnum,"total"=>$totalstring,"keyword"=>htmlentities($keyword,ENT_QUOTES,"UTF-8"));
		$style=array("resultcountstart","resultcountend","totalresults","keywordintotal");
		$totalstr=$this->getmessagegrammer(8,$message,$style);
		$this->setValue("total",$totalstr);
		$keyword1=urlencode($keyword);
		$keywordsuggestion_status=$db->total("nesote_inoutse_engines","id=? and keyword_suggestion_status=1",array($engineid));
		if($page==1 && $keywordsuggestion_status!=0 && trim($suggestion_keyword)==trim($keyword))
		{
			$tot1=$db->total("nesote_inoutse_keywordsuggestions","engine_id=? and keyword=?",array($engineid,$suggestion_keyword));
			if($tot1==0)
			{
				$db->insert("nesote_inoutse_keywordsuggestions");
				$db->fields("engine_id,keyword,total,searchcount,time");
				$db->values(array($engineid,$suggestion_keyword,$total,1,time()));
				$db->query();
			}
			else
			{
				$db->update("nesote_inoutse_keywordsuggestions");
				$db->set("searchcount=searchcount+1,time=?,total=?",array(time(),$total));
				$db->where("engine_id=? and keyword=?",array($engineid,$suggestion_keyword));
				$db->query();
			}
		}
		$previouspage=$page-1;
		if($page!=1)
		{
			if($alignment==1)
			{
				if($mod_rewrite==true)
				$footerlink="<a href=\"".$this->url("search/datasource_rl?search=$keyword1&type=$tabname&startpage=$previouspage")."\"><span class=\"footerpagelink\">".$this->getmessage(6)."</span></a>&nbsp;";
				else
				$footerlink="<a href=\"".$this->url("search/datasource_rl&search=$keyword1&type=$tabname&startpage=$previouspage")."\"><span class=\"footerpagelink\">".$this->getmessage(6)."</span></a>&nbsp;";
			}
			else
			{
				if($mod_rewrite==true)
				$footerlink="<a href=\"".$this->url("search/datasource?search=$keyword1&type=$tabname&startpage=$previouspage")."\"><span class=\"footerpagelink\">".$this->getmessage(6)."</span></a>&nbsp;";
				else
				$footerlink="<a href=\"".$this->url("search/datasource&search=$keyword1&type=$tabname&startpage=$previouspage")."\"><span class=\"footerpagelink\">".$this->getmessage(6)."</span></a>&nbsp;";
			}
		}
		if($page<=4)
		{
			$startpage=1;
			$endpage=7;
		}
		else
		{
			$startpage=$page-3;
			$endpage=$page+3;
		}
		for($i=$startpage;$i<=$endpage;$i++)
		{
			if($i*10<($total+10))
			{
				if($i!=$page)
				{
					if($alignment==1)
					{
						if($mod_rewrite==true)
						$footerlink.="<a href=\"".$this->url("search/datasource_rl?search=$keyword1&type=$tabname&startpage=$i")."\"><span class=\"footerpagelink\">$i</span></a>&nbsp;";
						else
						$footerlink.="<a href=\"".$this->url("search/datasource_rl&search=$keyword1&type=$tabname&startpage=$i")."\"><span class=\"footerpagelink\">$i</span></a>&nbsp;";
					}
					else
					{
						if($mod_rewrite==true)
						$footerlink.="<a href=\"".$this->url("search/datasource?search=$keyword1&type=$tabname&startpage=$i")."\"><span class=\"footerpagelink\">$i</span></a>&nbsp;";
						else
						$footerlink.="<a href=\"".$this->url("search/datasource&search=$keyword1&type=$tabname&startpage=$i")."\"><span class=\"footerpagelink\">$i</span></a>&nbsp;";
					}
				}
				else
				if($total>10)
				$footerlink.="<span class=\"footerpagetext\">".$i."</span>&nbsp;";
			}
			else
			break;
		}
		$footerlink=substr($footerlink,0,-6);
		$nextpage=$page+1;
		if($page*10<($total))
		{
			if($alignment==1)
			{
				if($mod_rewrite==true)
				$footerlink.="&nbsp;<a href=\"".$this->url("search/datasource_rl?search=$keyword1&type=$tabname&startpage=$nextpage")."\"><span class=\"footerpagelink\">".$this->getmessage(5)."</span></a>";
				else
				$footerlink.="&nbsp;<a href=\"".$this->url("search/datasource_rl&search=$keyword1&type=$tabname&startpage=$nextpage")."\"><span class=\"footerpagelink\">".$this->getmessage(5)."</span></a>";
			}
			else
			{
				if($mod_rewrite==true)
				$footerlink.="&nbsp;<a href=\"".$this->url("search/datasource?search=$keyword1&type=$tabname&startpage=$nextpage")."\"><span class=\"footerpagelink\">".$this->getmessage(5)."</span></a>";
				else
				$footerlink.="&nbsp;<a href=\"".$this->url("search/datasource&search=$keyword1&type=$tabname&startpage=$nextpage")."\"><span class=\"footerpagelink\">".$this->getmessage(5)."</span></a>";
			}
		}
		$this->setValue("footerlink",$footerlink);
		if($relatedkeyword_status==1)
		{
			$relatedkeywords=$this->getrelatedkeyword($keyword);
			$finalkeywordarray=[];
			for($i=0;$i<$relatedtag_count;$i++)
			{
				$finalkeywordarray[$i][0]=$relatedkeywords[$i];
			}
			if($finalkeywordarray[0][0]!="")
			$this->setValue("keywordstatus",1);
			else
			$this->setValue("keywordstatus",0);
		}
		else
		{
			$this->setValue("keywordstatus",0);
		}
		$this->setLoopValue("relatedkeywords",$finalkeywordarray);
		$j=0;
		for($i=$start;$i<=($start+9) && $i<=$total;$i++)
		{
			if($resultset[1][$i]=="")
			break;
			$var=$this->makebold(strip_tags($resultset[1][$i]),$keyword,1);
			$finalresult[$j][1]=html_entity_decode($var);
			$finalresult[$j][2]=$this->getstar($finalresult[$j][1],$engineid);
			$j++;
		}
$finalcount=count($finalresult);
		if($finalcount==0)
		{
			$keyword=urlencode($keyword);
			include('script.inc.php');
			include($config_path.'system.config.php');
			if($mod_rewrite==true)
			header("Location:".$this->url("search/noresults?search=$keyword&type=$enginename"));
			else
			header("Location:".$this->url("search/noresults&search=$keyword&type=$enginename"));
			exit(0);
		}
		$this->setLoopValue("results",$finalresult);
	}
	function rsssourceAction($alignment=0)
	{
		$valid=$this->uservalidation();
		$this->setValue("valid",$valid);
		$keyword=$_GET['search'];// reading search keyword
		$quotestatus=get_magic_quotes_gpc();
		if($quotestatus==1)
		$keyword=stripslashes($keyword);
		$tabname=$_GET['type'];//    reading tab name
		$fl=$_GET['fl'];
		if((!isset($_GET['type']))||($_GET['type']==""))
		$tabname=$this->getParam(1);
		if((!isset($_GET['search'])||($_GET['search']=="")))
		$keyword=str_replace("%2NNFF","/",$this->getParam(2));
$this->setValue("getkeyword",$keyword);
		$suggestion_keyword=$keyword;
		include('script.inc.php');
		include($config_path.'system.config.php');
		if($fl==1)
		$feelinglucky=1;
		$quotestatus=get_magic_quotes_gpc();
		if($quotestatus==1)
		$keyword=stripslashes($keyword);
		$keyword=str_replace('"',' " ',$keyword);
		$keyword=str_replace("'"," ' ",$keyword);
		$keyword=$this->familyfilter($keyword);
		$keyword=str_replace("' ","'",$keyword);
		$keyword=str_replace(" '","'",$keyword);
		$keyword=str_replace('" ','"',$keyword);
		$keyword=str_replace(' "','"',$keyword);
		$db= new NesoteDALController();
		$db->select("nesote_inoutse_engines");
		$db->fields("id,search_type");
		$db->where("tab_name=?",$tabname);
		$result=$db->query();
		$row=$db->fetchRow($result);
		$searchtype=$row[1];  // reading search type
		$engineid=$row[0];  // reading engine id
		$db= new NesoteDALController();
		$tot=$db->total("nesote_inoutse_engines","tab_name=? and status=?",array($tabname,1));
		if(($keyword=="")||($tot==0))
		{
			if($mod_rewrite==true)
			header("Location:".$this->url("search/noresults?search=$keyword&type=$tabname"));
			else
			header("Location:".$this->url("search/noresults&search=$keyword&type=$tabname"));
			exit(0);
		}
		$page=1;
		if(isset($_GET['startpage']))
		$page=$_GET['startpage'];   // reading page value
		if ($page=="")
		$page=1;
		$tabkeyword=str_replace("/","%2NNFF",$keyword);
		$this->setValue("keyword",$tabkeyword);
		$this->setValue("tabname",$tabname);
		$this->setValue("engineid",$engineid);
		$spellurl=$this->getspellurl($keyword);
		if(($spellurl!="")&&($spellurl!=" "))
		{$spellsuggestion=$this->getspellcontent($spellurl,$keyword,$tabname);}
		if($spellsuggestion!="")
		{
			$spell=array("spell"=>$spellsuggestion);
			$style=array("keyword_in_spellsuggestion_class");
			$spellstr=$this->getmessagegrammer(24,$spell,$style);
			$spellstr=str_replace("<span class=\"keyword_in_spellsuggestion_class\">".$spellsuggestion."</span>","<a class=\"spelllink\" href=\"".$this->url("search/news&search=".$spellsuggestion."&type=$tabname")."\">".$spellsuggestion."</a>",$spellstr);
			$this->setValue("spell","<span class=\"spellsuggestiontext\">".$spellstr."</span>");
		}
		else
		$this->setValue("spell","");
		$this->loadLibrary('Settings');
		$settings=new Settings('nesote_inoutse_settings');
		$settings->loadValues();
		$count=$settings->getValue("rss_resultcount");
		$styleid=$settings->getValue("result");
		$thumbshot=$settings->getValue("thumbshot");
		if($_COOKIE['thumbshot']=="off")
		$thumbshot=0;
		$this->setValue("thumbshotstatus",$thumbshot);
		$openin_newwindow=$settings->getValue("new_window");
		$this->setValue("newwindow",$openin_newwindow);
		$emailafrnd=$settings->getValue("email_a_frnd");
		$this->setValue("emailafrnd",$emailafrnd);
		$quicklook=$settings->getValue("quicklook");
		$this->setValue("quicklook",$quicklook);
		$servicename=$settings->getValue("service_name");
		$this->setValue("servicename",$servicename);
$auto_scroll_status=$settings->getValue("auto_scroll_status");
		$this->setValue("auto_scroll_status",$auto_scroll_status);
		$ad_codes=$settings->getValue("ad_codes");
		$this->setValue("ad_codes",$ad_codes);
		$relatedtag_count=$settings->getValue("related_tags_count");
		$seasonal_logo_status=$settings->getValue("seasonal_logo");
		///////////////////////// Ultimate7 /////////////////////////////////////
		$star_status=$settings->getValue("star_status");
		$this->setValue("star_status",$star_status);
		$member_status=$settings->getValue("member_status");
		if($member_status==1)
		$comment_status=$settings->getValue("comment_status");
		else
		$comment_status=0;
		$this->setValue("comment_status",$comment_status);
        $this->setValue("thumshot_url",$thumshot_url);
		if($seasonal_logo_status==1)
		{
			$time=time();
			$db= new NesoteDALController();
			$db->select("nesote_inoutse_seasonallogo");
			$db->fields("id,resultpage_logo");
			$db->where("startdate<=? and enddate>=? and status=1",$time);
			$result=$db->query();
			$row=$db->fetchRow($result);
			if($row[1]!="")
			{
				$logostatus=1;
				$userlogo=$row[1];
				$this->setValue("logoid",$row[0]);
			}
			elseif($row[1]=="")
			{
				$logostatus=0;
				$userlogo=$settings->getValue("result_logo");  ////////////     seasonal logo status
			}
		}
		else
		{
			$logostatus=0;
			$userlogo=$settings->getValue("result_logo");
		}
		$this->setValue("logo",$userlogo);
		$this->setValue("logostatus",$logostatus);
		$message=array("servicename"=>$servicename);
		$home=$this->getmessagegrammer(47,$message,0);
		$this->setValue("home",$home);
		$this->setValue("engineid",$engineid);
		$enginename=$this->getenginename($engineid);
		define('PAGETITLE',$servicename." - ".$enginename." - ".$keyword);
		define('HEADERKEYWORD',$servicename.",search,search engine,".$keyword.",".$searchtype);
		$typearray=array("type"=>$enginename);
		$typesearch=$this->getmessagegrammer(23,$typearray);
		$this->setValue("typesearch",$typesearch);
		$style="";
		$this->setValue("style",$style);
		$db->select("nesote_inoutse_engines");
		$db->fields("hidden_keyword");
		$db->where("id=?",$engineid);
		$rest=$db->query();
		$frow=$db->fetchRow($rest);
		$hiddenkeyword=$frow[0];   /////////// reading hidden keyword
		if($hiddenkeyword!="")
		$keyword.=" ".$hiddenkeyword;
		$pagetmp=$page;
		if($page%($count/10)==0)
		$pagetmp=$pagetmp-1;
		$startpage=($pagetmp-($pagetmp%($count/10)))*10;
		require("script.inc.php");
		require($config_path."system.config.php");
		$urlreplaces=array();
		$var=$_SERVER['SCRIPT_NAME'];
		$var=substr($var,0,strrpos($var,"/"));
		$hostdir= "http://".$_SERVER['HTTP_HOST']."".$var."/";
		$url=$hostdir."admin/index.php?page=rss/rssresult/$engineid&search=".urlencode($keyword)."&start=$startpage&count=$count";
		$xmldata=$this->geturlcontent($url,$engineid,$keyword);
		$xmldata=str_replace("\r\n","",$xmldata);
		$xmldata=str_replace("\n","",$xmldata);
		$xmldata=str_replace("\r","",$xmldata);
		preg_match("/<total>(.+?)<\/total>/i",$xmldata,$totalcount);
		$total=$totalcount[1];
		$resultset=="";
		if($total>0)
		{
			preg_match_all("/<item><data><title>(.+?)<\/title><description>(.+?)<\/description><url>(.+?)<\/url>\<\/data><\/item>/i",$xmldata,$resultset);
		}
		if(count($resultset[0])==0)
		{
			if($mod_rewrite==true)
			header("Location:".$this->url("search/noresults?search=$keyword&type=$tabname"));
			else
			header("Location:".$this->url("search/noresults&search=$keyword&type=$tabname"));
			exit(0);
		}
		$start=(10*($page-1))%$count;
		$startingnum=($page*10)-9;
		$endingnum=$page*10;
		if($total<$endingnum)
		$endingnum=$total;
		if($total<10)
		$startingnum=1;
		else
		$startingnum=($page*10)-9;
		$totalstring=number_format($total);
		$message=array("startingnum"=>$startingnum,"endingnum"=>$endingnum,"total"=>$totalstring,"keyword"=>htmlentities($keyword,ENT_QUOTES,"UTF-8"));
		$style=array("resultcountstart","resultcountend","totalresults","keywordintotal");
		$totalstr=$this->getmessagegrammer(8,$message,$style);
		$this->setValue("total",$totalstr);
		$keyword1=urlencode($keyword);
		$keywordsuggestion_status=$db->total("nesote_inoutse_engines","id=? and keyword_suggestion_status=1",array($engineid));
		if($page==1 && $keywordsuggestion_status!=0 && trim($suggestion_keyword)==trim($keyword))
		{
			$tot1=$db->total("nesote_inoutse_keywordsuggestions","engine_id=? and keyword=?",array($engineid,$suggestion_keyword));
			if($tot1==0)
			{
				$db->insert("nesote_inoutse_keywordsuggestions");
				$db->fields("engine_id,keyword,total,searchcount,time");
				$db->values(array($engineid,$suggestion_keyword,$total,1,time()));
				$db->query();
			}
			else
			{
				$db->update("nesote_inoutse_keywordsuggestions");
				$db->set("searchcount=searchcount+1,time=?,total=?",array(time(),$total));
				$db->where("engine_id=? and keyword=?",array($engineid,$suggestion_keyword));
				$db->query();
			}
		}
		$previouspage=$page-1;
		if($page!=1)
		{
			if($alignment==1)
			{
				if($mod_rewrite==true)
				$footerlink="<a href=\"".$this->url("search/rsssource_rl?search=$keyword1&type=$tabname&startpage=$previouspage")."\"><span class=\"footerpagelink\">".$this->getmessage(6)."</span></a>&nbsp;";
				else
				$footerlink="<a href=\"".$this->url("search/rsssource_rl&search=$keyword1&type=$tabname&startpage=$previouspage")."\"><span class=\"footerpagelink\">".$this->getmessage(6)."</span></a>&nbsp;";
			}
			else
			{
				if($mod_rewrite==true)
				$footerlink="<a href=\"".$this->url("search/rsssource?search=$keyword1&type=$tabname&startpage=$previouspage")."\"><span class=\"footerpagelink\">".$this->getmessage(6)."</span></a>&nbsp;";
				else
				$footerlink="<a href=\"".$this->url("search/rsssource&search=$keyword1&type=$tabname&startpage=$previouspage")."\"><span class=\"footerpagelink\">".$this->getmessage(6)."</span></a>&nbsp;";
			}
		}
		if($page<=4)
		{
			$startpage=1;
			$endpage=7;
		}
		else
		{
			$startpage=$page-3;
			$endpage=$page+3;
		}
		for($i=$startpage;$i<=$endpage;$i++)
		{
			if($i*10<($total+10))
			{
				if($i!=$page)
				{
					if($alignment==1)
					{
						if($mod_rewrite==true)
						$footerlink.="<a href=\"".$this->url("search/rsssource_rl?search=$keyword1&type=$tabname&startpage=$i")."\"><span class=\"footerpagelink\">$i</span></a>&nbsp;";
						else
						$footerlink.="<a href=\"".$this->url("search/rsssource_rl&search=$keyword1&type=$tabname&startpage=$i")."\"><span class=\"footerpagelink\">$i</span></a>&nbsp;";
					}
					else
					{
						if($mod_rewrite==true)
						$footerlink.="<a href=\"".$this->url("search/rsssource?search=$keyword1&type=$tabname&startpage=$i")."\"><span class=\"footerpagelink\">$i</span></a>&nbsp;";
						else
						$footerlink.="<a href=\"".$this->url("search/rsssource&search=$keyword1&type=$tabname&startpage=$i")."\"><span class=\"footerpagelink\">$i</span></a>&nbsp;";
					}
				}
				else
				if($total>10)
				$footerlink.="<span class=\"footerpagetext\">".$i."</span>&nbsp;";
			}
			else
			break;
		}
		$footerlink=substr($footerlink,0,-6);
		$nextpage=$page+1;
		if($page*10<($total))//if($page*10<=($total+10))
		{
			if($alignment==1)
			{
				if($mod_rewrite==true)
				$footerlink.="&nbsp;<a href=\"".$this->url("search/rsssource_rl?search=$keyword1&type=$tabname&startpage=$nextpage")."\"><span class=\"footerpagelink\">".$this->getmessage(5)."</span></a>";
				else
				$footerlink.="&nbsp;<a href=\"".$this->url("search/rsssource_rl&search=$keyword1&type=$tabname&startpage=$nextpage")."\"><span class=\"footerpagelink\">".$this->getmessage(5)."</span></a>";
			}
			else
			{
				if($mod_rewrite==true)
				$footerlink.="&nbsp;<a href=\"".$this->url("search/rsssource?search=$keyword1&type=$tabname&startpage=$nextpage")."\"><span class=\"footerpagelink\">".$this->getmessage(5)."</span></a>";
				else
				$footerlink.="&nbsp;<a href=\"".$this->url("search/rsssource&search=$keyword1&type=$tabname&startpage=$nextpage")."\"><span class=\"footerpagelink\">".$this->getmessage(5)."</span></a>";
			}
		}
		$this->setValue("footerlink",$footerlink);
		$relatedkeywords=$this->getrelatedkeyword($keyword);
		$finalkeywordarray=[];
		for($i=0;$i<$relatedtag_count;$i++)
		{
			$finalkeywordarray[$i][0]=$relatedkeywords[$i];
		}
		if($finalkeywordarray[0][0]!="")
		$this->setValue("keywordstatus",1);
		else
		$this->setValue("keywordstatus",0);
		$this->setLoopValue("relatedkeywords",$finalkeywordarray);
		$db->select("nesote_inoutse_rssengines");
		$db->fields("source_description,thumbshots_status");
		$db->where("engineid=?",$engineid);
		$result=$db->query();
		$row=$db->fetchRow($result);
		$thumbshots_status=$row[1];
		if($thumbshots_status==1)
		$this->setValue("rssthumbstatus",1);
		else
		$this->setValue("rssthumbstatus",0);
		$j=0;
		for($i=$start;$i<=($start+9)&& $i<=$total;$i++)
		{
			if($resultset[1][$i]=="")
			break;
			if(($i==0)&&($feelinglucky==1))
			{
				header("Location:".strip_tags($resultset[3][$i]));
				exit(0);
			}
			$finalresult[$j][1]=$this->makebold($resultset[1][$i],$keyword,1);//title
			$finalresult[$j][2]=$this->makebold($resultset[2][$i],$keyword,1);//description
			$finalresult[$j][3]=html_entity_decode($resultset[3][$i]);//url
			$finalresult[$j][4]=$this->makebold(substr($resultset[3][$i],7),$keyword,0);//displayurl
			$finalresult[$j][5]=$this->getstar($finalresult[$j][3],$engineid);
			$j++;
		}
$finalcount=count($finalresult);
		if($finalcount==0)
		{
			$keyword=urlencode($keyword);
			include('script.inc.php');
			include($config_path.'system.config.php');
			if($mod_rewrite==true)
			header("Location:".$this->url("search/noresults?search=$keyword&type=$tabname"));
			else
			header("Location:".$this->url("search/noresults&search=$keyword&type=$tabname"));
			exit(0);
		}
		$this->setLoopValue("results",$finalresult);
	}
	function getcacheindex($url)
	{
		$number=27;
		$mdstring=md5($url);
		$mdstring=str_replace("a","",$mdstring);
		$mdstring=str_replace("b","",$mdstring);
		$mdstring=str_replace("c","",$mdstring);
		$mdstring=str_replace("d","",$mdstring);
		$mdstring=str_replace("e","",$mdstring);
		$mdstring=str_replace("f","",$mdstring);
		$digits=substr($mdstring,-6);
		$modlusnumber=$digits % $number;
		$modlusnumber=$modlusnumber+1;
		$numbers=[];
		$numbers[$modlusnumber]++;
		return $modlusnumber;
	}
	function getspellcontent($url=false,$keyword=false,$tabname=false,$rest_api_status=false, $video_api_status=false)
	{
		$this->loadLibrary('Settings');
		$settings=new Settings('nesote_inoutse_settings');
		$settings->loadValues();
		$keyword=$this->addslash($keyword);
		$accountKey=$settings->getValue("bing_api_key");
		$db= new NesoteDALController();
		$tot=$db->total("nesote_inoutse_spellingsuggestions","keyword=?",$keyword);
		if($tot!=0)
		{
			$db= new NesoteDALController();
			$db->select("nesote_inoutse_spellingsuggestions");
			$db->fields("spelling_suggestion");
			$db->where("keyword=?",$keyword);
			$result=$db->query();
			$row=$db->fetchRow($result);
			return $row[0];
			exit(0);
		}
		$spellingsuggestion="";
		if(($tabname!='videos')&&($rest_api_status==2))
		{
	$process = curl_init($url);
	  curl_setopt($process, CURLOPT_HTTPGET, 1);
	 curl_setopt($process,CURLOPT_HTTPHEADER,array('Ocp-Apim-Subscription-Key:'.$accountKey,'Content-Type: application/json'));
  curl_setopt($process, CURLOPT_TIMEOUT, 30);
  curl_setopt($process, CURLOPT_RETURNTRANSFER, TRUE);
    $spellingsuggestion_res = curl_exec($process);
$responseobject = json_decode($spellingsuggestion_res, true);
	$spellsuggestion=$responseobject[queryContext][alteredQuery];
		$db->insert("nesote_inoutse_spellingsuggestions");
		$db->fields("keyword,spelling_suggestion");
		$db->values(array($keyword,$spellsuggestion));
		$db->query();
		return $spellsuggestion ;
		}
		elseif(($tabname=='videos')&&($videos_api_status==2))
		{
	$process = curl_init($url);
	$bing_spell_check_Key='f730b5298346456db744b0b82b8168c7';
	  curl_setopt($process, CURLOPT_HTTPGET, 1);
  curl_setopt($process,CURLOPT_HTTPHEADER,array('Ocp-Apim-Subscription-Key:'.$bing_spell_check_Key,'Content-Type: application/json'));
  curl_setopt($process, CURLOPT_TIMEOUT, 30);
  curl_setopt($process, CURLOPT_RETURNTRANSFER, TRUE);
    $spellingsuggestion_res = curl_exec($process);
$responseobject = json_decode($spellingsuggestion_res, true);
	  foreach ($responseobject['flaggedTokens']  as $responseresult)
		{
			$spellingsuggestion_sugges = $responseobject['flaggedTokens'] ;
			     $spll_cnt=$spellingsuggestion_sugges[0][suggestions];      
		}
	$spellsuggestion=$spll_cnt[0][suggestion];
	return $spellsuggestion ;
		}
		if($rest_api_status==3)
		$rest_api_status=2;
		if(($tabname!='videos')&&($rest_api_status==1))
		preg_match("/<suggestion>(.+?)<\/suggestion>/i",$spellingsuggestion,$spelling);
		elseif(($tabname!='videos')&&($rest_api_status==2))
		preg_match("/<d:Value m:type=\"Edm.String\">(.+?)<\/d:Value>/i",$spellingsuggestion,$spelling);
		elseif(($tabname=='videos')&&($videos_api_status==1))
		preg_match("/<suggestion>(.+?)<\/suggestion>/i",$spellingsuggestion,$spelling);
		preg_match("/<d:Value m:type=\"Edm.String\">(.+?)<\/d:Value>/i",$spellingsuggestion,$spelling);
		$spellsuggestion=$spelling[1];
		$db->insert("nesote_inoutse_spellingsuggestions");
		$db->fields("keyword,spelling_suggestion");
		$db->values(array($keyword,$spellsuggestion));
		$db->query();
		return $spellsuggestion ;
	}
	function geturl($engineid,$searchtype,$keyword,$page,$mixsource="0",$next="",$advancedarray="")
	{
	    
		$db= new NesoteDALController();
		$bcpg=$page;
		$startspider=$page;
		$this->loadLibrary('Settings');
		$settings=new Settings('nesote_inoutse_settings');
		$settings->loadValues();
		$video_api_status=$settings->getValue("video_api_search");
		$rest_api_status=$settings->getValue("rest_api_search");
		$count=$settings->getValue("result_count");
		$image_resultcount=$settings->getValue("image_result_count");
		$db->select("nesote_inoutse_engines");
		$db->fields("hidden_keyword");
		$db->where("id=?",$engineid);
		$rest=$db->query();
		$frow=$db->fetchRow($rest);
		$hiddenkeyword=$frow[0];
		$ebay_resultcount=$settings->getValue("ebay_result_count");// set ebay result count
		if(isset($_COOKIE['region']))
		{
			$region=$_COOKIE['region'];
			if($_COOKIE['region']==0)
			$region=63;
		}
		elseif(!isset($_COOKIE['region']))
		{
			$region=$settings->getValue("default_country");
			if(($region=="")||($region==0))
			$region=63;
		}
		if($region==0)
		$region=63;
		if($region=="")
		$region=63;
		if($mixsource!="0")
		{
			$nul="";
			if(($searchtype!="news")||($mixsource!="G"))
			{
				if($mixsource=="G")
				{
					$db->select("nesote_inoutse_countries");
					$db->fields("google_countrycode");
					$db->where("id=? and google_countrycode!=?", array($region,$nul));
					$country=$db->query();
				}
				if($mixsource=="Y")
				{
					$db->select("nesote_inoutse_countries");
					$db->fields("yahoo_countrycode");
					$db->where("id=? and yahoo_countrycode!=?", array($region,$nul));
					$country=$db->query();
				}
				if($mixsource=="B")
				{
					$db->select("nesote_inoutse_countries");
					$db->fields("bing_countrycode");
					$db->where("id=? and bing_countrycode!=?", array($region,$nul));
					$country=$db->query();
				}
				if($mixsource=="T")
				{
					$db->select("nesote_inoutse_countries");
					$db->fields("bing_countrycode");
					$db->where("id=? and bing_countrycode!=?", array($region,$nul));
					$country=$db->query();
				}
				if($mixsource=="S")
				{
					$db->select("nesote_inoutse_countries");
					$db->fields("google_countrycode");
					$db->where("id=? and google_countrycode!=?", array($region,$nul));
					$country=$db->query();
				}
				$ned="";
			}
			else
			{
				if($mixsource=="G")
				{
					$db->select("nesote_inoutse_countries");
					$db->fields("googlenews_code");
					$db->where("id=? and google_countrycode!=?", array($region,$nul));
					$country=$db->query();
					$country1=$db->fetchRow($country);
					$ned= $country1[0];
				}
			}
			$country1=$db->fetchRow($country);
			$region= $country1[0];
			if(($region=="")&&($ned==""))
			{
				return "";
			}
		}
		$region=explode("_",$region);
		if($hiddenkeyword!="")
		$keyword.=" ".$hiddenkeyword;
		if($mixsource!="0")
		{
			if(($searchtype=="web")||($searchtype=="special"))
			{
				$count=$settings->getValue("result_fetchcount");
				$start=($page-1)*$count;
			}
			if($searchtype=="images")
			{
				$count=$settings->getValue("image_result_fetchcount");
				$start=($page-1)*$count;
			}
			if($searchtype=="videos")
			{
				$count=$settings->getValue("video_result_fetchcount");
				$start=($page-1)*$count;
			}
			if($searchtype=="news")
			{
				$count=$settings->getValue("news_result_fetchcount");
				$start=($page-1)*$count;
			}
			if($mixsource=="Y")
			{
				if(($searchtype=="web")||($searchtype=="special"))
				$maxcount=$settings->getValue("yahoo_result_maxcount");
				if($searchtype=="news")
				$maxcount=$settings->getValue("yahoo_news_result_maxcount");
				if($searchtype=="images")
				$maxcount=$settings->getValue("yahoo_image_result_maxcount");
				$totalfetchingcount=$settings->getValue("yahoo_totalfetchingcount");
				$yahoo_loopmode=$settings->getValue("yahoo_loopmode");
				if($yahoo_loopmode==0)
				{
					if($maxcount<$count)
					{$count=$maxcount;
					$start=($page-1)*$count;}
				}
			}
			else if($mixsource=="B")
			{
				if(($searchtype=="web")||($searchtype=="special"))
				$maxcount=$settings->getValue("bing_result_maxcount");
				if($searchtype=="news")
				$maxcount=$settings->getValue("bing_news_result_maxcount");
				if($searchtype=="images")
				$maxcount=$settings->getValue("bing_image_result_maxcount");
				if($searchtype=="videos")
				$maxcount=$settings->getValue("bing_video_result_maxcount");
				$totalfetchingcount=$settings->getValue("bing_totalfetchingcount");
				$bing_loopmode=$settings->getValue("bing_loopmode");
				if($bing_loopmode==0)
				{
					if($maxcount<$count)
					{$count=$maxcount;
					$start=($page-1)*$count;}
				}
			}
			else if($mixsource=="S")
			{
				if(($searchtype=="web")||($searchtype=="special"))
				$maxcount=$settings->getValue("spider_result_maxcount");
				if($searchtype=="news")
				$maxcount=$settings->getValue("spider_news_result_maxcount");
				if($searchtype=="images")
				$maxcount=$settings->getValue("spider_image_result_maxcount");
				$totalfetchingcount=$settings->getValue("spider_totalfetchingcount");
				$spider_loopmode=$settings->getValue("spider_loopmode");
				if($spider_loopmode==0)
				{
					if($maxcount<$count)
					{$count=$maxcount;
					$start=($page-1)*$count;}
				}
			}
			else if($mixsource=="G")
			{
				if(($searchtype=="web")||($searchtype=="special"))
				$maxcount=$settings->getValue("google_result_maxcount");
				if($searchtype=="news")
				$maxcount=$settings->getValue("google_news_result_maxcount");
				if($searchtype=="images")
				$maxcount=$settings->getValue("google_image_result_maxcount");
				$totalfetchingcount=$settings->getValue("google_totalfetchingcount");
				$google_loopmode=$settings->getValue("google_loopmode");
				if($google_loopmode==0)
				{
					if($maxcount<$count)
					{$count=$maxcount;
					$start=($page-1)*$count;}
				}
			}
			else if($mixsource=="T")
			{
				if($searchtype=="videos")
				$maxcount=$settings->getValue("youtube_video_result_maxcount");
				$totalfetchingcount=$settings->getValue("youtube_totalfetchingcount");
				$youtube_loopmode=$settings->getValue("youtube_loopmode");
				if($youtube_loopmode==0)
				{
					if($maxcount<$count)
					{$count=$maxcount;
					$start=($page-1)*$count;}
				}
			}
		}
		else
		{
			if($searchtype=="twitter")
			{
				$count=$settings->getValue("twitter_result_count");
			}
			$pagetmp=$page;
			$ebaypagetmp=$page;
			if($page%($count/10)==0)
			$pagetmp=$pagetmp-1;
			$start=($pagetmp-($pagetmp%($count/10)))*10;
			$twitpage= $start/$count + 1;
			if($searchtype=="ebay")
			{
				$page=1;
				while($ebaypagetmp*10>$page*$ebay_resultcount)
				{
					$page=$page+1;
				}
			}
		}
		if($searchtype=="twitter")
		{
			$nul="";
			$db->select("nesote_inoutse_countries");
			$db->fields("google_countrycode");
			$db->where("id=? and google_countrycode!=?", array($region[0],$nul));
			$country=$db->query();
			$region=$db->fetchRow($country);
			$region=explode("-",$region[0]);
			$lang=explode("_",$region[0]);
			$twitter_resultcount=$settings->getValue("twitter_result_count");
			$keyword=urlencode($keyword);
			$url='https://api.twitter.com/1.1/search/tweets.json?q='.$keyword.'&lang='.$lang[1].'&result_type=mixed&count='.$twitter_resultcount.'&max_id='.$twitpage.'';
		}
		if($searchtype=="videos")
		{
			if($mixsource=="T")
			{
				$youtube_api_key=$settings->getValue("google_youtube_developer_key");
				$ylimit=intval($count/$maxcount);
				$reminder=$count%$maxcount;
				$yrem= intval(($totalfetchingcount -($bcpg-1)*$count )/$maxcount);
				if($yrem<$ylimit)
				{
					$ylimit=$yrem;
					$reminder=($totalfetchingcount -($bcpg-1)*$count)%$maxcount;
				}
				$start1=($bcpg-1)*$count;
				for($i=0;$i<$ylimit;$i++)
				{
					$start=$start1 + $i*$maxcount+1;
					if($count>$maxcount)
					{
						$count=$maxcount;
					}
		$url='https://www.googleapis.com/youtube/v3/search?key='.$youtube_api_key.'&part=snippet&maxResults=15&order=relevance&type=video&q='.urlencode($keyword).'&pageToken='.$next;
					$urlstring.=$url." ||| ";
				}
				if($reminder!=0)
				{
					$start=$start1 + $i*$maxcount+1;
					if($reminder>$maxcount)
					{
						$reminder=$maxcount;
					}
					$count=$reminder;
			 $url='https://www.googleapis.com/youtube/v3/search?key='.$youtube_api_key.'&part=snippet&maxResults=15&order=relevance&type=video&q='.urlencode($keyword).'&pageToken='.$next;
					$urlstring.=$url." ||| ";
				}
				$url=$urlstring;
			}
			elseif($mixsource=="B")
			{
				$bing_api_key=$settings->getValue("bing_api_key");
				$blimit=intval($count/$maxcount);
				$reminder=$count%$maxcount;
				$brem= intval(($totalfetchingcount - ($bcpg-1)*$count )/$maxcount);
				if($brem<$blimit)
				{
					$blimit=$brem;
					$reminder=($totalfetchingcount-($bcpg-1)*$count)%$maxcount;
				}
				$start1=($bcpg-1)*$count;
				for($i=0;$i<$blimit;$i++)
				{
					$start=$start1 + $i*$maxcount;
					if($count>$maxcount)
					{
						$count=$maxcount;
					}
					$url='https://api.cognitive.microsoft.com/bing/v7.0/videos/search?q='.urlencode($keyword).'&count='.$count.'&offset='.$start.'&mkt='.$region[1].'-'.$region[0];
					$urlstring.=$url." ||| ";
				}
				if($reminder!=0)
				{
					$start=$start1 + $i*$maxcount;
					if($reminder>$maxcount)
					{
						$reminder=$maxcount;
					}
					$count=$reminder;
						$url='https://api.cognitive.microsoft.com/bing/v7.0/videos/search?q='.urlencode($keyword).'&count='.$count.'&offset='.$start.'&mkt='.$region[1].'-'.$region[0];
					$urlstring.=$url." ||| ";
				}
				$url=$urlstring;
			}
		}
		elseif($mixsource=="B")
		{
			$bing_api_key=$settings->getValue("bing_api_key");
			$blimit=intval($count/$maxcount);
			$reminder=$count%$maxcount;
			$brem= intval(($totalfetchingcount - ($bcpg-1)*$count )/$maxcount);
			if($brem<$blimit)
			{
				$blimit=$brem;
				$reminder=($totalfetchingcount-($bcpg-1)*$count)%$maxcount;
			}
			$start1=($bcpg-1)*$count;
			for($i=0;$i<$blimit;$i++)
			{
				$start=$start1 + $i*$maxcount;
				$pagelimit=$bcpg*10;
				if($count>$maxcount)
				{
					$count=$maxcount;
				}
				if($searchtype=="web")
				{
				$url ='https://api.cognitive.microsoft.com/bing/v7.0/search?q='.urlencode($keyword).'&count='.$count.'&offset='.$start.'&mkt='.$region[1].'-'.$region[0].'&safesearch=Moderate';	
				}
				if($searchtype=="images")
				{
				$url ='https://api.cognitive.microsoft.com/bing/v7.0/images/search?q='.urlencode($keyword).'&count='.$count.'&offset='.$start.'&mkt='.$region[1].'-'.$region[0].'&safesearch=Moderate';
				}
				if($searchtype=="news")
				{
				$url='https://api.cognitive.microsoft.com/bing/v7.0/news/search?q='.urlencode($keyword).'&count='.$count.'&offset='.$start.'&mkt='.$region[1].'-'.$region[0].'&safesearch=Moderate';
				}
				if($searchtype=="special")
				{
					$db->select("nesote_inoutse_engines");
					$db->fields("special_status,special_keyword,support_keyword");
					$db->where("id=?",$engineid);
					$result=$db->query();
					$row=$db->fetchRow($result); 
					if($row[0]==1)
					{
					$url ='https://api.cognitive.microsoft.com/bing/v7.0/search?q='.urlencode($keyword).'%20intitle'.$row[1].'&count='.$count.'&offset='.$start.'&mkt='.$region[1].'-'.$region[0].'&safesearch=Moderate';	
					}
					if($row[0]==2)
					{
							$site=explode(",",$row[1]);
						$sitecount=count($site);
							$sitestring.="site:(";
						for($i=0;$i<$sitecount;$i++)
						{
							if($i!=0)
							{
							$sitestring.="+".$site[$i] ;
							}
							else 
							{
								$sitestring.=$site[$i];
							}
						}
							$sitestring.=")";
		$url ='https://api.cognitive.microsoft.com/bing/v7.0/search?q='.urlencode($keyword).$sitestring.'&count='.$count.'&offset='.$start.'&mkt='.$region[1].'-'.$region[0].'&safesearch=Moderate';	
					}
					if($row[0]==3)
					{
						$url ='https://api.cognitive.microsoft.com/bing/v7.0/search?q='.urlencode($keyword).'%20filetype:'.$row[1].'&count='.$count.'&offset='.$start.'&mkt='.$region[1].'-'.$region[0].'&safesearch=Moderate';	
					}
					if($row[0]==4)
					{
						$site=explode(",",$row[1]);
						$sitecount=count($site);
						for($i=0;$i<$sitecount;$i++)
						{
							$sitestring.="site:".$site[$i]."%20OR%20";
						}
			$url ='https://api.cognitive.microsoft.com/bing/v7.0/search?q='.urlencode($keyword).$sitestring.'%20intitle:'.$row[2].'&count='.$count.'&offset='.$start.'&mkt='.$region[1].'-'.$region[0].'&safesearch=Moderate';	
					}
				}
				$urlstring.=$url." ||| ";
			}
			if($reminder!=0)
			{
				$start=$start1 + $i*$maxcount;
				if($reminder>$maxcount)
				{
					$reminder=$maxcount;
				}
				$count=$reminder;
				$pagelimit=$bcpg*10;
				if($searchtype=="web")
				{
			$url ='https://api.cognitive.microsoft.com/bing/v7.0/search?q='.urlencode($keyword).'&count='.$count.'&offset='.$start.'&mkt='.$region[1].'-'.$region[0].'&safesearch=Moderate';
				}
				if($searchtype=="images")
				{
				$url ='https://api.cognitive.microsoft.com/bing/v7.0/images/search?q='.urlencode($keyword).'&count='.$count.'&offset='.$start.'&mkt='.$region[1].'-'.$region[0].'&safesearch=Moderate';	
				}
				if($searchtype=="news")
				{
				$url='https://api.cognitive.microsoft.com/bing/v7.0/news/search?q='.urlencode($keyword).'&count='.$count.'&offset='.$start.'&mkt='.$region[1].'-'.$region[0].'&safesearch=Moderate';
				}
				if($searchtype=="special")
				{
					$db->select("nesote_inoutse_engines");
					$db->fields("special_status,special_keyword,support_keyword");
					$db->where("id=?",$engineid);
					$result=$db->query();
					$row=$db->fetchRow($result);
					if($row[0]==1)
					{
	$url ='https://api.cognitive.microsoft.com/bing/v7.0/search?q='.urlencode($keyword).'%20intitle:'.$row[1].'&count='.$count.'&offset='.$start.'&mkt='.$region[1].'-'.$region[0].'&safesearch=Moderate';				
					}
					if($row[0]==2)
					{
						$site=explode(",",$row[1]);
						$sitecount=count($site);
						for($i=0;$i<$sitecount;$i++)
						{
							$sitestring.="site:".$site[$i];
						}
$url ='https://api.cognitive.microsoft.com/bing/v7.0/search?q='.urlencode($keyword).$sitestring.'&count='.$count.'&offset='.$start.'&mkt='.$region[1].'-'.$region[0].'&safesearch=Moderate';				
					}
					if($row[0]==3)
					{
					$url ='https://api.cognitive.microsoft.com/bing/v7.0/search?q='.urlencode($keyword).'%20filetype:'.$row[1].'&count='.$count.'&offset='.$start.'&mkt='.$region[1].'-'.$region[0].'&safesearch=Moderate';	
					}
					if($row[0]==4)
					{
						$site=explode(",",$row[1]);
						$sitecount=count($site);
						for($i=0;$i<$sitecount;$i++)
						{
							$sitestring.="site:".$site[$i]."%20OR%20";
						}
						$url ='https://api.cognitive.microsoft.com/bing/v7.0/search?q='.urlencode($keyword).'%20'.$sitestring.'%20intitle:'.$row[1].'&count='.$count.'&offset='.$start.'&mkt='.$region[1].'-'.$region[0].'&safesearch=Moderate';	
					}
				}
				$urlstring.=$url." ||| ";
			}
			$url=$urlstring;
		}
		elseif($mixsource=="S")
		{
			$crawler_url=$settings->getValue("crawler_url");
			$apikey=$settings->getValue("spider_api_key");
			$slimit=intval($count/$maxcount);
			$reminder=$count%$maxcount;
			$srem= intval(( $totalfetchingcount - ($bcpg-1)*$count )/$maxcount);
			if($srem<$slimit)
			{
				$slimit=$srem;
				$reminder=($totalfetchingcount-($bcpg-1)*$count)%$maxcount;
			}
			$start1=($bcpg-1)*$count;
			for($i=0;$i<$slimit;$i++)
			{
				$start=$start1 + $i*$maxcount;
				if($count>$maxcount)
				{
					$count=$maxcount;
				}
				if($searchtype=="web")
				{
				
				//$url=$startspider;
				//$url=$crawler_url.'index.php?page=rss/web&apikey='.$apikey.'&keyword='.urlencode($keyword).'&startcount='.$start.'&count='.$count.'&region=www';
				
				$url=$crawler_url.'index.php/search/web?apikey='.$apikey.'&keyword='.urlencode($keyword).'&startcount='.$startspider.'&count='.$count.'&region=www';
				//echo $url; exit;
				}
				if($searchtype=="images")
				$url=$crawler_url.'index.php?page=rss/image&apikey='.$apikey.'&keyword='.urlencode($keyword).'&startcount='.$start.'&count='.$count.'&filter=moderate';
				if($searchtype=="news")
				$url=$crawler_url.'index.php?page=rss/news&apikey='.$apikey.'&keyword='.urlencode($keyword).'&startcount='.$start.'&count='.$count.'&region=www';
				if($searchtype=="special")
				{
					$db->select("nesote_inoutse_engines");
					$db->fields("special_status,special_keyword,support_keyword,spider_category_domain_id");
					$db->where("id=?",$engineid);
					$result=$db->query();
					$row=$db->fetchRow($result);
					$row[1]=trim($row[1]);
					$row[2]=trim($row[2]);
				if($row[0]==1)
					$url=$crawler_url.'index.php/search/web?apikey='.$apikey.'&keyword='.urlencode($keyword).'&startcount='.$startspider.'&count='.$count.'&category='.$row[3].'&region=www';
					if($row[0]==2){
						//if($row[2]!="")
						$url=$crawler_url.'index.php/search/web?apikey='.$apikey.'&keyword='.urlencode($keyword).'&startcount='.$startspider.'&count='.$count.'&domainset='.urlencode($row[3]).'&region=www';
						//else
						//$url=$crawler_url.'index.php/search/web?apikey='.$apikey.'&keyword='.urlencode($keyword).'+sites:'.$row[1].'&startcount='.$startspider.'&count='.$count.'&region=www';
					}
					if($row[0]==3)
					$url=$crawler_url.'index.php/search/web?apikey='.$apikey.'&keyword='.urlencode($keyword).'&startcount='.$startspider.'&count='.$count.'&filetype='.$row[1].'&region=www';
					if($row[0]==4)
					{
						$addon="";
						if($row[2]!="")
						$addon="&category=".urlencode($row[2]);
						$url=$crawler_url.'index.php/search/web?apikey='.$apikey.'&keyword='.urlencode($keyword).'&startcount='.$startspider.'&count='.$count.'&extension='.$row[1].$addon.'&region=www';
					}
				}
				$urlstring.=$url." ||| ";
			}
			if($reminder!=0)
			{
				$start=$start1 + $i*$maxcount;
				if($reminder>$maxcount)
				{
					$reminder=$maxcount;
				}
				$count=$reminder;
				if($searchtype=="web")
				//$url=$crawler_url.'index.php?page=rss/web&apikey='.$apikey.'&keyword='.urlencode($keyword).'&startcount='.$start.'&count='.$count.'&region=www';
				$url=$crawler_url.'index.php/search/web?apikey='.$apikey.'&keyword='.urlencode($keyword).'&startcount='.$startspider.'&count='.$count.'&region=www';
				if($searchtype=="images")
				$url=$crawler_url.'index.php?page=rss/image&apikey='.$apikey.'&keyword='.urlencode($keyword).'&startcount='.$start.'&count='.$count.'&filter=moderate';
				if($searchtype=="news")
				$url=$crawler_url.'index.php?page=rss/news&apikey='.$apikey.'&keyword='.urlencode($keyword).'&startcount='.$start.'&count='.$count.'&region=www';
				if($searchtype=="special")
				{
					$db->select("nesote_inoutse_engines");
					$db->fields("special_status,special_keyword,support_keyword,spider_category_domain_id");
					$db->where("id=?",$engineid);
					$result=$db->query();
					$row=$db->fetchRow($result);
					$row[1]=trim($row[1]);
					$row[2]=trim($row[2]);
					if($row[0]==1)
					$url=$crawler_url.'index.php/search/web?apikey='.$apikey.'&keyword='.urlencode($keyword).'&startcount='.$startspider.'&count='.$count.'&category='.$row[3].'&region=www';
					if($row[0]==2){
						//if($row[2]!="")
						$url=$crawler_url.'index.php/search/web?apikey='.$apikey.'&keyword='.urlencode($keyword).'&startcount='.$startspider.'&count='.$count.'&domainset='.urlencode($row[3]).'&region=www';
						//else
						//$url=$crawler_url.'index.php/search/web?apikey='.$apikey.'&keyword='.urlencode($keyword).'+sites:'.$row[1].'&startcount='.$startspider.'&count='.$count.'&region=www';
					}
					if($row[0]==3)
					$url=$crawler_url.'index.php/search/web?apikey='.$apikey.'&keyword='.urlencode($keyword).'&startcount='.$startspider.'&count='.$count.'&filetype='.$row[1].'&region=www';
					if($row[0]==4)
					{
						$addon="";
						if($row[2]!="")
						$addon="&category=".urlencode($row[2]);
						$url=$crawler_url.'index.php/search/web?apikey='.$apikey.'&keyword='.urlencode($keyword).'&startcount='.$startspider.'&count='.$count.'&extension='.$row[1].$addon.'&region=www';
					}
				}
				$urlstring.=$url." ||| ";
			}
			$url=$urlstring;
		}
		elseif($mixsource=="G")
		{
			$region[0]=strtoupper($region[0]);
			$google_api_key=$settings->getValue("google_api_key");
		$google_customsearch_id=$settings->getValue("customsearch");
			$glimit=intval($count/$maxcount);
			$reminder=$count%$maxcount;
			$grem= intval(( $totalfetchingcount - ($bcpg-1)*$count )/$maxcount);
			if($grem<$glimit)
			{
				$glimit=$grem;
				$reminder=($totalfetchingcount-($bcpg-1)*$count)%$maxcount;
			}
			$start1=($bcpg-1)*$count;
			$strindex=0;
			for($i=0;$i<$glimit;$i++)
			{
				$start=$start1 + $i*$maxcount;
				$strindex=($start+1);
				if($count>$maxcount)
				{
					$count=$maxcount;
				}
				if($searchtype=="web")
				$url='https://www.googleapis.com/customsearch/v1?key='.$google_api_key.'&cx='.$google_customsearch_id.'&q='.urlencode($keyword).'&cr=country'.$region[0].'&lr=lang_'.$region[1].'&safe=medium&filter=1&start='.$strindex;				
				if($searchtype=="images")
 $url='https://www.googleapis.com/customsearch/v1?key='.$google_api_key.'&cx='.$google_customsearch_id.'&q='.urlencode($keyword).'&alt=json&searchType=image&as_filetype=jpg&imgtype=photo&num=10&filter=0&start='.$strindex.'&count=10&imgSize=huge';
				if($searchtype=="news")
		$url='https://www.googleapis.com/customsearch/v1?key='.$google_api_key.'&cx='.$google_customsearch_id.'&q='.urlencode($keyword).'&orTerms=news&safe=medium&filter=1&start='.$strindex;				
				if($searchtype=="special")
				{
					$db->select("nesote_inoutse_engines");
					$db->fields("special_status,special_keyword,support_keyword");
					$db->where("id=?",$engineid);
					$result=$db->query();
					$row=$db->fetchRow($result);
					if($row[0]==1)
				$url='https://www.googleapis.com/customsearch/v1?key='.$google_api_key.'&cx='.$google_customsearch_id.'&q='.urlencode($keyword)."+".urlencode("inurl:$row[1]").'&cr=country'.$region[0].'&lr=lang_'.$region[1].'&safe=medium&filter=1&start='.$strindex;				
					if($row[0]==2)
					{
						$site=explode(",",$row[1]);
						$sitecount=count($site);
						$firstsite=$site[0];
				$url='https://www.googleapis.com/customsearch/v1?key='.$google_api_key.'&cx='.$google_customsearch_id.'&q='.urlencode($keyword)."+".urlencode("site:$firstsite").'&cr=country'.$region[0].'&lr=lang_'.$region[1].'&safe=medium&filter=1&start='.$strindex;				
					}
					if($row[0]==3)
				$url='https://www.googleapis.com/customsearch/v1?key='.$google_api_key.'&cx='.$google_customsearch_id.'&q='.urlencode($keyword)."+".urlencode("fileType:$row[1]").'&cr=country'.$region[0].'&lr=lang_'.$region[1].'&safe=medium&filter=1&start='.$strindex;				
					if($row[0]==4)
					{
						$site=explode(",",$row[1]);
						$sitecount=count($site);
						$firstsite=$site[0];
						if($row[2]!="")
					$url='https://www.googleapis.com/customsearch/v1?key='.$google_api_key.'&cx='.$google_customsearch_id.'&q='.urlencode($keyword)."+".urlencode("site:$firstsite")."+".urlencode("inurl:$row[2]").'&cr=country'.$region[0].'&lr=lang_'.$region[1].'&safe=medium&filter=1&start='.$strindex;				
						else
					$url='https://www.googleapis.com/customsearch/v1?key='.$google_api_key.'&cx='.$google_customsearch_id.'&q='.urlencode($keyword)."+".urlencode("site:$firstsite").'&cr=country'.$region[0].'&lr=lang_'.$region[1].'&safe=medium&filter=1&start='.$strindex;						
					}
				}
				$urlstring.=$url." ||| ";
			}
			if($reminder!=0)
			{
				$start=$start1 + $i*$maxcount;
					$strindex=($start+1);
				if($reminder>$maxcount)
				{
					$reminder=$maxcount;
				}
				$count=$reminder;
				if($searchtype=="web")
	$url='https://www.googleapis.com/customsearch/v1?key='.$google_api_key.'&cx='.$google_customsearch_id.'&q='.urlencode($keyword).'&cr=country'.$region[0].'&lr=lang_'.$region[1].'&safe=medium&rsz=2&filter=1&start='.$start;	
			if($searchtype=="images")
$url='https://www.googleapis.com/customsearch/v1?key='.$google_api_key.'&cx='.$google_customsearch_id.'&q='.urlencode($keyword).'&alt=json&searchType=image&as_filetype=jpg&imgtype=photo&num='.$reminder.'&filter=0&start='.$strindex.'&count='.$reminder.'&imgSize=huge';			
				if($searchtype=="news")
		$url='https://www.googleapis.com/customsearch/v1?key='.$google_api_key.'&cx='.$google_customsearch_id.'&q='.urlencode($keyword).'&orTerms=news&safe=medium&filter=1&start='.$strindex;				
				if($searchtype=="special")
				{
					$db->select("nesote_inoutse_engines");
					$db->fields("special_status,special_keyword,support_keyword");
					$db->where("id=?",$engineid);
					$result=$db->query();
					$row=$db->fetchRow($result);
					if($row[0]==1)
	$url='https://www.googleapis.com/customsearch/v1?key='.$google_api_key.'&cx='.$google_customsearch_id.'&q='.urlencode($keyword)."+".urlencode("inurl:$row[1]").'&cr=country'.$region[0].'&lr=lang_'.$region[1].'&safe=medium&filter=1&start='.$strindex;				
					if($row[0]==2)
					{
						$site=explode(",",$row[1]);
						$sitecount=count($site);
						$firstsite=$site[0];
							$url='https://www.googleapis.com/customsearch/v1?key='.$google_api_key.'&cx='.$google_customsearch_id.'&q='.urlencode($keyword)."+".urlencode("site:$firstsite").'&cr=country'.$region[0].'&lr=lang_'.$region[1].'&safe=medium&filter=1&start='.$strindex;				
					}
					if($row[0]==3)
				$url='https://www.googleapis.com/customsearch/v1?key='.$google_api_key.'&cx='.$google_customsearch_id.'&q='.urlencode($keyword)."+".urlencode("fileType:$row[1]").'&cr=country'.$region[0].'&lr=lang_'.$region[1].'&safe=medium&filter=1&start='.$strindex;				
					if($row[0]==4)
					{
						$site=explode(",",$row[1]);
						$sitecount=count($site);
						$firstsite=$site[0];
						if($row[2]!="")
					$url='https://www.googleapis.com/customsearch/v1?key='.$google_api_key.'&cx='.$google_customsearch_id.'&q='.urlencode($keyword)."+".urlencode("site:$firstsite")."+".urlencode("inurl:$row[2]").'&cr=country'.$region[0].'&lr=lang_'.$region[1].'&safe=medium&filter=1&start='.$strindex;				
						else
							$url='https://www.googleapis.com/customsearch/v1?key='.$google_api_key.'&cx='.$google_customsearch_id.'&q='.urlencode($keyword)."+".urlencode("site:$firstsite").'&cr=country'.$region[0].'&lr=lang_'.$region[1].'&safe=medium&filter=1&start='.$strindex;						
					}
				}
				$urlstring.=$url." ||| ";
			}
			$url=$urlstring;
		}
		if($mixsource!="0")
		{
			$url=substr($url,0,-5);
		}
		return $url;
	}
	function perform_google_search($response)
	{
		$result = array();
		$responseobject = json_decode($response, true);
		$nofresult=array();
		$nofresult=($responseobject['queries'] );
	foreach ($nofresult as $key => $val)
	 {
       }
	if (($val[0]['totalResults'])==0)
		{
			return $result;
		}
		$allresponseresults=array();
		for($i=0;$i<10;$i++)
		{
		$allresponseresults[]= $responseobject['items'][$i];
		}
		foreach ($allresponseresults as $responseresult)
		{
			$result[] = array(
              'url' => $responseresult['link'],
             'title' => $responseresult['title'],
             'content' => $responseresult['snippet'],
             'visibleUrl' => $responseresult['displayLink'],
			 'originalContextUrl' => $responseresult['formattedUrl']);
		}
		return $result;
	}
	function perform_google_search2($response)
	{
		$result = array();
		$responseobject = json_decode($response, true);
	$nofresult=array();
		$nofresult=($responseobject['queries'] );
	foreach ($nofresult as $key => $val)
	 {
       }
 $allresponsecursor= $val[0]['totalResults'];
		return $allresponsecursor;
	}
	function geturlcontent($url,$engineid,$keyword="",$amazonurl="")
	{
         include_once('classes.inc');	
		$db= new NesoteDALController();
		$db->select("nesote_inoutse_engines");
	    $db->fields("cacheable");
		$db->where("id=?",$engineid);
		$result=$db->query();
		$row=$db->fetchRow($result);
        $cacheable_status=$row[0];	
        $db->select("nesote_inoutse_engines");
	    $db->fields("search_type");
		$db->where("id=?",$engineid);
		$resulttwitter=$db->query();
		$row_twitter=$db->fetchRow($resulttwitter);
		if($cacheable_status==1)
		{
			if($amazonurl!="")
			{
				$cacheindex=$this->getcacheindex($amazonurl);
				$db->select("nesote_inoutse_cache".$cacheindex);
				$db->fields("id,time");
				$db->where("eid=? and url=?",array($engineid,$amazonurl));
				$db->limit(0,1);
				$result=$db->query();
				$row=$db->fetchRow($result);
			}
			else
			{
				$cacheindex=$this->getcacheindex($url);
				$db->select("nesote_inoutse_cache".$cacheindex);
				$db->fields("id,time");
				$db->where("eid=? and url=?",array($engineid,$url));
				$db->limit(0,1);
				$result=$db->query();
				$row=$db->fetchRow($result);
			}
			if($row[0]!="")
			{
				$time=getdate($row[1]);
				$year=$time['year'];
				$month=$time['mon'];
				$date=$time['mday'];
	            $cachestore = new cachestorage();
                $xmldata = $cachestore->getcache($cacheindex,$row[0]);
	            return $xmldata;
				exit(0);
			}
		}
		$currenttime=time();
		$time=getdate($currenttime);
		$year=$time['year'];
		$month=$time['mon'];
		$date=$time['mday'];
		$xmldata="";
		if($row_twitter[0]!="twitter")
		{
	    if($fp=fopen($url,"r"))//  && 1==0)
		{
			while(!feof($fp))
			{
				$xmldata.=fgetc($fp);
			}
			fclose($fp);
		}
		elseif(function_exists('curl_init'))
		{
			$ch = curl_init();
			curl_setopt($ch, CURLOPT_URL,$url);
			curl_setopt($ch, CURLOPT_HEADER, 0);
			curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
			$xmldata = curl_exec($ch);
			curl_close($ch);
		}
		else
		{
			$db->select("nesote_inoutse_engines");
			$db->fields("tab_name");
			$db->where("id=?",array($engineid));
			$result=$db->query();
			$row=$db->fetchRow($result);
			$type=$row[0];
			$keyword=urlencode($keyword);
			if($xmldata=="")
			{
				include('script.inc.php');
				include($config_path.'system.config.php');
				if($mod_rewrite==true)
				{
					header("Location:".$this->url("search/noresults?search=$keyword&type=$type"));
				}
				else
				{
					header("Location:".$this->url("search/noresults&search=$keyword&type=$type"));
				}
				exit(0);
			}
		}
		}
		else 
		{
		require_once("twitteroauth-master/twitteroauth/twitteroauth.php"); //Path to twitteroauth library
		$this->loadLibrary('Settings');
		$settings=new Settings('nesote_inoutse_settings');
		$settings->loadValues();
		$count=$settings->getValue("twitter_consumer");
$consumerkey = "LIZAyBhNN7oa2IealPnlC14SP";
$consumersecret = "d3iSr5lWjGJQHbTYO7ZT0dkZXNV3uhoA9MNuCIDChFcRYe7gsv";
$accesstoken = "2456080904-csLN1P9ImUBhzaPoqvE2pFFCf64eie1TBs4MNOI";
$accesstokensecret = "ho5kU79WoCpjUoI5RV5snNunZTSw9rj8fE3Rf16pQsMvj";
		function getConnectionWithAccessToken($cons_key, $cons_secret, $oauth_token, $oauth_token_secret) {
		$connection = new TwitterOAuth($cons_key, $cons_secret, $oauth_token, $oauth_token_secret);
		return $connection;
}
	$connection = getConnectionWithAccessToken($consumerkey, $consumersecret, $accesstoken, $accesstokensecret);
  	$tweets=array();
  	$xmldata = $connection->get($url);
		if($xmldata=="")
		{
			$db->select("nesote_inoutse_engines");
			$db->fields("tab_name");
			$db->where("id=?",array($engineid));
			$result=$db->query();
			$row=$db->fetchRow($result);
			$type=$row[0];
			$keyword=urlencode($keyword);
			if($xmldata=="")
			{
				include('script.inc.php');
				include($config_path.'system.config.php');
				if($mod_rewrite==true)
				{
					header("Location:".$this->url("search/noresults?search=$keyword&type=$type"));
				}
				else
				{
					header("Location:".$this->url("search/noresults&search=$keyword&type=$type"));
				}
				exit(0);
			}
		}
		}
		$tot1=$db->total("nesote_inoutse_engines","id=? and cacheable=?",array($engineid,1));
		if($tot1==1)
		{
			if($amazonurl!="")
			{
			                $db->insert("nesote_inoutse_cache".$cacheindex);
		                    $db->fields("eid,url,time");
		                    $db->values(array($engineid,$amazonurl,time()));
		                    $db->query();
                         $id= $db->lastInsertid("nesote_inoutse_cache".$cacheindex);
			}
			else
			{
			                $db->insert("nesote_inoutse_cache".$cacheindex);
		                    $db->fields("eid,url,time");
		                    $db->values(array($engineid,$url,time()));
		                    $db->query();
                         $id= $db->lastInsertid("nesote_inoutse_cache".$cacheindex);
			}
			$cachestore = new cachestorage();
			$source='';
			$name = $cachestore->storecache($xmldata,$cacheindex,$id,$source);
		}
		return $xmldata;
	}
	function getrelatedkeyword($keyword,$xmldata='',$rest_api_status=null)
	{
		$keyword=$this->addslash($keyword);
		$db= new NesoteDALController();
		$tot=$db->total("nesote_inoutse_relatedkeywords","keyword=?",$keyword);
		if($tot!=0)
		{
			$db->select("nesote_inoutse_relatedkeywords");
			$db->fields("related_keywords");
			$db->where("keyword=?",$keyword);
			$result=$db->query();
			$row=$db->fetchRow($result);
			$relatedkeywords= explode(",",$row[0]);
			return $relatedkeywords;
		}
		if($xmldata=="")
		{
			return "";
		}
		$this->loadLibrary('Settings');
		$settings=new Settings('nesote_inoutse_settings');
		$settings->loadValues();
		$xmldata=str_replace("\r\n","",$xmldata);
		$xmldata=str_replace("\r","",$xmldata);
		$xmldata=str_replace("\n","",$xmldata);
		if($rest_api_status==1)
		{
			$xmldata=str_replace("</term>","</term> ",$xmldata);
			preg_match_all('/<term>(.+?)<\/term>/i',$xmldata,$keywordarray);
		}
		elseif($rest_api_status==2)
		{
			$url='https://api.cognitive.microsoft.com/bing/v7.0/search?q='.urlencode($keyword).'&responseFilter=relatedsearches';
			$related_xml=$this->getbingrelatedkeywords($url);
			$related_xml_array=json_decode($related_xml,true);
			$related_xmls=$related_xml_array['relatedSearches']['value'];
			$cnt=count($related_xmls);
			$keywordarray=[];
			for($i=0;$i<$cnt;$i++)
			{
		$keywordarray[1][$i]=$related_xmls[$i]['displayText'];	
			}			
		}
		elseif($rest_api_status==3)
		{
			preg_match_all('/<keywords>(.+?)<\/keywords>/i',$xmldata,$relatedsubarray);
			$relatedsubarray_count=count($relatedsubarray[1]);
			$j=0;
			for($i=0;$i<$relatedsubarray_count;$i++)
			{
				$var=str_replace("<![CDATA[","",$relatedsubarray[1][$i]);
				$var=str_replace("]]>","",$var);
				$relatedarray=explode(",",$var);
				$relatedarray_count=count($relatedarray);
				{
					for($k=0;$k<$relatedarray_count;$k++)
					{
						if(trim($relatedarray[$k])!="")
						{
							$keywordarray[0][$j]=$relatedarray[$k];
							$keywordarray[1][$j]=$relatedarray[$k];
							$j++;
						}
					}
				}
			}
		}
    $keywordcountarray=[];
		$count=count($keywordarray[1]);
		for($i=0;$i<$count;$i++)
		{
			if($keywordcountarray[strtolower($keywordarray[1][$i])]=="")
			$keywordcountarray[strtolower($keywordarray[1][$i])]=1;
			else ;
			$keywordcountarray[strtolower($keywordarray[1][$i])]= $keywordcountarray[strtolower($keywordarray[1][$i])]+1;
		}
		arsort($keywordcountarray);
		$i=0;
		$this->loadLibrary('Settings');
		$settings=new Settings('nesote_inoutse_settings');
		$settings->loadValues();
		$keywordcount=25;
		foreach($keywordcountarray as $key=> $value)
		{
			if($key!=$keyword)
			{
				if($i<$keywordcount)
				{
					$relatedtags=$relatedtags.$key.",";
				}
				$i++;
			}
		}
		$relatedtags=substr($relatedtags,0,-1);
		$relatedtags=html_entity_decode($relatedtags);
		if($relatedtags!="")
		{
			$db->insert("nesote_inoutse_relatedkeywords");
    		$db->fields("keyword,related_keywords,time");
    		$db->values(array($keyword,$relatedtags,time()));
    		$db->query();
		}
		$finalarray=explode(",",$relatedtags);
		return $finalarray;
	}
function getbingrelatedkeywords($url)
{
$this->loadLibrary('Settings');
		$settings=new Settings('nesote_inoutse_settings');
		$settings->loadValues();
		$accountKey=$settings->getValue("bing_api_key");
	$process = curl_init($url);
	 curl_setopt($process, CURLOPT_HTTPGET, 1);
  curl_setopt($process,CURLOPT_HTTPHEADER,array('Ocp-Apim-Subscription-Key:'.$accountKey,'Content-Type: application/json'));
  curl_setopt($process, CURLOPT_TIMEOUT, 30);
  curl_setopt($process, CURLOPT_RETURNTRANSFER, TRUE);
    $response = curl_exec($process);
				return  $response	;
}
	function makebold($content,$keyword,$wordstatus=0)
	{
		$this->loadLibrary('Settings');
		$settings=new Settings('nesote_inoutse_settings');
		$settings->loadValues();
		$isbold=$settings->getValue("keyword_bold");
		if($isbold==0)
		return $content;
		else
		{
			$keyword=urlencode($keyword);
			$keyword=str_replace("+"," ",$keyword);
			$keyword=str_replace("%22","",$keyword);
			while(substr_count($keyword,"  ")!=0)
			{
				$keyword=str_replace("  "," ",$keyword);
			}
			$newkeyword=explode(" ",$keyword);
			$arraycount=count($newkeyword);
			$content=" ".$content." ";
			for($i=0;$i<=($arraycount-1);$i++)
			{
				if($wordstatus==1)
				{
					$content=preg_replace('/( '.$newkeyword[$i].' )/i',' <b>$1</b> ',$content);
				}
				else
				$content=preg_replace('/('.$newkeyword[$i].')/i','<b>$1</b>',$content);
			}
			return trim($content);
		}
	}
	function getmessage($msg_id)
	{
		$lang_id="";
        $db= new NesoteDALController();
		$this->loadLibrary("settings");
		$set=new settings("nesote_inoutse_settings");
		$set->loadValues();
		$defaultlang_id=$set->getValue("default_language");
		if(isset ($_COOKIE['language']))
		{
			$lang_id=$_COOKIE['language'];
			$db->select("nesote_inoutse_languages");
			$db->fields("id");
			$db->where("lang_code=?", array($lang_id));
			$result=$db->query();
			$row=$db->fetchRow($result);
			$lang_id=$row[0];
		}
		else
		{
			$lang_id=$defaultlang_id;
		}
		if($lang_id!="")
		{
			$tot=$db->total("nesote_inoutse_commonwordscripts","msg_id=? and lang_id=?",array($msg_id,$lang_id));
			if($tot!=0)
			{
				$db->select("nesote_inoutse_commonwordscripts");
				$db->fields("wordscript");
				$db->where("msg_id=? and lang_id=?", array($msg_id,$lang_id));
				$result=$db->query();
				$row=$db->fetchRow($result);
				return $row[0];
			}
			else
			{
				$tot=$db->total("nesote_inoutse_commonwordscripts","msg_id=? and lang_id=?",array($msg_id,$defaultlang_id));
				if($tot!=0)
				{
					$db->select("nesote_inoutse_commonwordscripts");
					$db->fields("wordscript");
					$db->where("msg_id=? and lang_id=?", array($msg_id,$defaultlang_id));
					$result=$db->query();
					$row=$db->fetchRow($result);
					return $row[0];
				}
				else
				{
					$db->select("nesote_inoutse_commonwordscripts");
					$db->fields("wordscript");
					$db->where("msg_id=? and lang_id=?", array($msg_id,1));
					$result=$db->query();
					$row=$db->fetchRow($result);
					return $row[0];
				}
			}
		}
		else
		{
			$db=new NesoteDALController();
			$db->select("nesote_inoutse_commonwordscripts");
			$db->fields("wordscript");
			$db->where("msg_id=? and lang_id=?", array($msg_id,1));
			$result=$db->query();
			$row=$db->fetchRow($result);
			return $row[0];
		}
	}
	function getalignment()
	{
		$lang_id="";
		$db=new NesoteDALController();
		if(isset ($_COOKIE['language']))
		{
			$lang_id=$_COOKIE['language'];
			$db->select("nesote_inoutse_languages");
			$db->fields("id");
			$db->where("lang_code=?", array($lang_id));
			$result=$db->query();
			$row=$db->fetchRow($result);
			$lang_id=$row[0];
		}
		else
		{
			$this->loadLibrary("settings");
			$set=new settings("nesote_inoutse_settings");
			$set->loadValues();
			$lang_id=$set->getValue("default_language");
		}
		if(is_numeric($lang_id)){
		if($lang_id==0)
		$lang_id=1;}
		else
		{
			exit;
		}
		$db->select("nesote_inoutse_languages");
		$db->fields("lang_alignment");
		$db->where("id=?",$lang_id);
		$result=$db->query();
		$row=$db->fetchRow($result);
		return $row[0];
	}
	function gettd($results)
	{
		if(($results==1)||($results==5)||($results==9)||($results==13))
		return "<td colspan=\"3\">&nbsp;</td>";
		if(($results==2)||($results==6)||($results==10)||($results==14))
		return "<td colspan=\"2\">&nbsp;</td>";
		if(($results==3)||($results==7)||($results==11)||($results==15))
		return "<td>&nbsp;</td>";
		if(($results==4)||($results==8)||($results==12)||($results==16))
		return "";
	}
	function gettitle($title,$keyword)
	{
		$titlestr=substr($title,0,15);
		for($i=15;$i<=50;$i++)
		{
			if(($title[$i]!="")&&($title[$i]!=" "))
			{
				$titlestr.=$title[$i];
			}
			else
			{
				if($title[$i]==" ")
				$status=1;
				break;
			}
		}
		if($status==1)
		$titlestr.="...";
		$subtitle=$this->makebold($titlestr,$keyword);
		return $subtitle;
	}
	function getsize($size)
	{
		$size=$size/1024;
		$size=round($size,2);
		return $size."K";
	}
	function getpreviewlink($url,$height,$width)
	{
		$this->loadLibrary('Settings');
		$settings=new Settings('nesote_inoutse_settings');
		$settings->loadValues();
		$lightbox=$settings->getValue("lightbox");
		if($lightbox==1)
		return "&nbsp;<a class=\"pop-link\"  rel=\"lightbox['result']\" title=\"Image Results\" href=\"$url\">".$this->getmessage(30)."</a>&nbsp;";
		elseif($lightbox==2)
		return "<a class=\"pop-link\" href=\"javascript:popUpimage('$url',$height,$width)\">".$this->getmessage(30)."</a>";
		elseif($lightbox==0)
		return "<a class=\"pop-link\"  style=\"background:rgba(73,73,73,1.00);\" href=\"$url\">".$this->getmessage(30)."</a>";
	}
	function getduration($duration)
	{
 preg_match_all('/(\d+)/',$duration,$parts);
            $hours = $parts[0][0];
            $minutes = $parts[0][1];
            $seconds = $parts[0][2];
            if($seconds != 0)
                return $hours.':'.$minutes.':'.$seconds;
            else
                return $hours.':'.$minutes;
	}
	function getyoutubeduration($videoid)
	{
		$db= new NesoteDALController();
		$this->loadLibrary('Settings');
		$settings=new Settings('nesote_inoutse_settings');
		$settings->loadValues();
		$youtube_api=$settings->getValue("google_youtube_developer_key");
			$url="https://www.googleapis.com/youtube/v3/videos?part=contentDetails&key=$youtube_api&id=$videoid";
			$ch = curl_init();
			curl_setopt($ch, CURLOPT_URL, $url);
			curl_setopt($ch, CURLOPT_TIMEOUT, 30);
			curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
			curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
			curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
			$xml = curl_exec($ch);
			if (curl_error($ch) || !$xml) $xml =curl_error($ch);
			curl_close($ch);
			$searchResponse=json_decode($xml,true);
			foreach ($searchResponse['items'] as $searchResult) {
				$videosrate= sprintf('%s',  $searchResult['contentDetails']['duration']);
			}
		try {
			$date = new DateTime('2000-01-01');
			$date->add(new DateInterval($videosrate));
			return $date->format('i:s') ; 
			}
	     catch(Exception $e) {
}
		}
	function getmessagegrammer($msgid=false,$message=false,$style="")
	{
		$lang_id="";
		$style=[];
		$this->loadLibrary("settings");
		$set=new settings("nesote_inoutse_settings");
		$set->loadValues();
		$defaultlang_id=$set->getValue("default_language");
		$db=new NesoteDALController();
		if(isset ($_COOKIE['language']))
		{
			$lang_id=$_COOKIE['language'];
			$db->select("nesote_inoutse_languages");
			$db->fields("id");
			$db->where("lang_code=?", array($lang_id));
			$result=$db->query();
			$row=$db->fetchRow($result);
			$lang_id=$row[0];
		}
		else
		{
			$lang_id=$defaultlang_id;
		}
		if($lang_id!="")
		{
			$db=new NesoteDALController();
			$tot=$db->total("nesote_inoutse_commonwordscripts","lang_id=? and msg_id=?",array($lang_id,$msgid));
			if($tot!=0)
			{
				$db->select("nesote_inoutse_commonwordscripts");
				$db->fields("wordscript");
				$db->where("msg_id=? and lang_id=?",array($msgid,$lang_id));
				$result=$db->query();
				$row=$db->fetchRow($result);
				$i=0;
				$msgstring=$row[0];
				foreach($message as $key=> $value)
				{
					if($style[$i]!="")
					{
						$msgstring=str_replace('{$'.$key.'}','<span class="'.$style[$i].'">'.$value.'</span>',$msgstring);
					}
					else
					{
						$msgstring=str_replace('{$'.$key.'}',$value,$msgstring);
					}
					$i++;
				}
				return  $msgstring;
			}
			else
			{
				$tot=$db->total("nesote_inoutse_commonwordscripts","lang_id=? and msg_id=?",array($defaultlang_id,$msgid));
				if($tot!=0)
				{
					$db->select("nesote_inoutse_commonwordscripts");
					$db->fields("wordscript");
					$db->where("msg_id=? and lang_id=?",array($msgid,$defaultlang_id));
					$result=$db->query();
					$row=$db->fetchRow($result);
					$i=0;
					$msgstring=$row[0];
					foreach($message as $key=> $value)
					{
						if($style[$i]!="")
						{
							$msgstring=str_replace('{$'.$key.'}','<span class="'.$style[$i].'">'.$value.'</span>',$msgstring);
						}
						else
						{
							$msgstring=str_replace('{$'.$key.'}',$value,$msgstring);
						}
						$i++;
					}
					return  $msgstring;
				}
				else
				{
					$db->select("nesote_inoutse_commonwordscripts");
					$db->fields("wordscript");
					$db->where("msg_id=? and lang_id=?",array($msgid,1));
					$result=$db->query();
					$row=$db->fetchRow($result);
					$i=0;
					$msgstring=$row[0];
					foreach($message as $key=> $value)
					{
						if($style[$i]!="")
						{
							$msgstring=str_replace('{$'.$key.'}','<span class="'.$style[$i].'">'.$value.'</span>',$msgstring);
						}
						else
						{
							$msgstring=str_replace('{$'.$key.'}',$value,$msgstring);
						}
						$i++;
					}
					return  $msgstring;
				}
			}
		}
		else
		{
			$db->select("nesote_inoutse_commonwordscripts");
			$db->fields("wordscript");
			$db->where("msg_id=? and lang_id=?",array($msgid,1));
			$result=$db->query();
			$row=$db->fetchRow($result);
			$i=0;
			$msgstring=$row[0];
			foreach($message as $key=> $value)
			{
				if($style[$i]!="")
				{
					$msgstring=str_replace('{$'.$key.'}','<span class="'.$style[$i].'">'.$value.'</span>',$msgstring);
				}
				else
				{
					$msgstring=str_replace('{$'.$key.'}',$value,$msgstring);
				}
				$i++;
			}
			return  $msgstring;  
		}
	}
	function getlinkstartforEmail()
	{
		$returnurl=$this->url("search/emailafriend");
		include('script.inc.php');
		include($config_path."system.config.php");
		if($mod_rewrite)
		$returnurl.="?";
		else
		$returnurl.="&";
		return $returnurl;
	}
	function createlink($url)
	{
		return urlencode($url);
	}
	function emailafriendAction($alignment=0)
	{
		$msg = "";
		$sendername="";
		$senderaddress="";
		$recepientname="";
		$recepientaddress="";
		$message="";
		$url="";
		$url=$_GET['url'];
		$url=urldecode($url);
		$this->setValue("url",$url);
		$status=$_GET['status'];
		$this->setValue("status",$status);
		$this->loadLibrary('Settings');
		$settings=new Settings('nesote_inoutse_settings');
		$settings->loadValues();
		$servicename=$settings->getValue("service_name");
		$message=array("servicename"=>$servicename);
		$emailtitle=$this->getmessagegrammer(17,$message);
		$this->setValue("emailtitle",$emailtitle);
		define('PAGETITLE',$servicename." - ".$this->getmessage(50));
		define('HEADERKEYWORD',$servicename.",search,search engine");
		$style="";
		$this->setValue("style",$style);
		if(isset($_POST['submit1']))
		{
			$sendername=$_POST['sendername'];
			$senderaddress=$_POST['senderaddress'];
			$recepientname=$_POST['recepientname'];
			$recepientaddress=$_POST['recepientaddress'];
			$message=$_POST['message'];
			$url=$_POST['url'];
			$rand =$_COOKIE["image_random_value"];
			$image=trim($_POST['image']);
			$vcode=md5($image);
			if($rand!=$vcode)
			{
				$msg=$this->getmessage(246);
			}
			if(($sendername=="")||($senderaddress=="")||($recepientname=="")||($recepientaddress==""))
			{
				$msg=$this->getmessage(51);
			}
			if($msg!="")
			{
				$this->setValue("errormsg",$msg);
			}
			else 
			{
				$this->sendemailfun($sendername, $senderaddress, $recepientname, $recepientaddress, $message, $url);
			}
		}
		$this->setValue("sendername",$sendername);
		$this->setValue("senderaddress",$senderaddress);
		$this->setValue("recepientname",$recepientname);
		$this->setValue("recepientaddress",$recepientaddress);
		$this->setValue("message",$message);
	}
	function sendemailAction()
	{
		$recepientaddress=$this->getParam(1);
		$this->loadLibrary('Settings');
		$settings=new Settings('nesote_inoutse_settings');
		$settings->loadValues();
		$servicename=$settings->getValue("service_name");
		$messagecontent=array("recepientemail"=>$recepientaddress);
		$successmsg=$this->getmessagegrammer(21,$messagecontent);
		$this->setValue("successmsg",$successmsg);
		$this->setValue("servicename",$servicename);
		define('PAGETITLE',$servicename." - ".$successmsg);
		define('HEADERKEYWORD',$servicename.",search,search engine");
		$style="";
		$this->setValue("style",$style);
	}
function sendemailfun($sendername,$senderaddress,$recepientname,$recepientaddress,$message,$url)
	{
		$this->loadLibrary('Settings');
		$settings=new Settings('nesote_inoutse_settings');
		$settings->loadValues();
		$servicename=$settings->getValue("service_name");
		if($message!="")
		{
			$privatemsg=
			$this->getmessage(19)."\r\n".
			$message;
		}
		else
		$privatemsg="";
		$messagecontent=array("recepientname"=>$recepientname,"sendername"=>$sendername,"url"=>$url);
		$msg=
		$this->getmessagegrammer(18,$messagecontent)."\r\n\r\n".
		$privatemsg.
"\r\n\r\n - ".
		$servicename;
		$messagecontent=array("sendername"=>$sendername,"senderaddress"=>$senderaddress);
		$sub=$this->getmessagegrammer(20,$messagecontent);
		$header='From: '.$sendername."<$senderaddress>"."\r\n" .'Reply-To: '.$senderaddress. "\r\n" .
    'X-Mailer: PHP/';
		mail($recepientaddress,$sub,$msg,$header);
		$messagecontent=array("recepientemail"=>$recepientaddress);
		$successmsg=$this->getmessagegrammer(21,$messagecontent);
		$this->setValue("successmsg",$successmsg);
		$this->setValue("servicename",$servicename);
		define('PAGETITLE',$servicename." - ".$successmsg);
		define('HEADERKEYWORD',$servicename.",search,search engine");
		$style="";
		$this->setValue("style",$style);
			header("Location:".$this->url("search/sendemail/$recepientaddress"));
		exit(0);
	}
	function familyfilter($keyword)
	{
		$this->loadLibrary('Settings');
		$settings=new Settings('nesote_inoutse_settings');
		$settings->loadValues();
		$filterstatus=$settings->getValue("family_filter");
		if($filterstatus==0)
		return $keyword;
        $keyword=strtolower($keyword);
		$keyword=" ".$keyword." ";
		$db=new NesoteDALController();
		$db->select("nesote_inoutse_familyfilter");
		$db->fields("keyword");
		$result=$db->query();
		while($row=$result->fetchRow())
		{
			if(substr_count($keyword," ".$row[0]." ")!=0)
			while(substr_count($keyword," ".$row[0]." ")!=0)
			{
				$keyword=str_replace(" ".$row[0]." "," ",$keyword);
			}
		}
		$keyword=trim($keyword);
		return $keyword;
	}
	function noresultsAction($alignment=0)
	{
		$db= new NesoteDALController();
		$keyword=$_GET['search'];
		$status=$_GET['status'];
		$this->setValue("stat",$status);
		$quotestatus=get_magic_quotes_gpc();
		if($quotestatus==1)
		$keyword=stripslashes($keyword);
		$tabname=$_GET['type'];
		include('script.inc.php');
		include($config_path.'system.config.php');
		$this->loadLibrary('Settings');
		$settings=new Settings('nesote_inoutse_settings');
		$settings->loadValues();
		$servicename=$settings->getValue("service_name");
		$seasonal_logo_status=$settings->getValue("seasonal_logo");
		if($seasonal_logo_status==1)
		{
			$time=time();
			$db->select("nesote_inoutse_seasonallogo");
			$db->fields("id,resultpage_logo");
			$db->where("startdate<=? and enddate>=? and status=1",$time);
			$result=$db->query();
			$row=$db->fetchRow($result);
			if($row[1]!="")
			{
				$logostatus=1;
				$userlogo=$row[1];
				$this->setValue("logoid",$row[0]);
			}
			elseif($row[1]=="")
			{
				$logostatus=0;
				$userlogo=$settings->getValue("result_logo");  ////////////     seasonal logo status
			}
		}
		else
		{
			$logostatus=0;
			$userlogo=$settings->getValue("result_logo");
		}
		$this->setValue("logo",$userlogo);
		$this->setValue("logostatus",$logostatus);
		$message=array("servicename"=>$servicename);
		$home=$this->getmessagegrammer(47,$message,0);
		$this->setValue("home",$home);
		$db->select("nesote_inoutse_engines");
		$db->fields("id,search_type");
		$db->where("tab_name=?",$tabname);
		$result=$db->query();
		$row=$db->fetchRow($result);
		$searchtype=$row[1];  // reading search type
		$engineid=$row[0];  // reading engine id
		$this->setValue("type",$searchtype);
		if($searchtype=="itunes")
		{
			$this->setValue("keyword",$keyword);
			$country=$_COOKIE["itune_country"];
			if($country=="")
			{
				$country="US";
			}
			$this->setValue("curcountry",$country);
			$db->select("nesote_inoutse_itune_countries");
			$db->fields("*");
			$db->order("country_name");
			$countrylist=$db->query();
			$this->setLoopValue("countrylist",$countrylist->getresult());
			$media=$_COOKIE["itune_media"];
			if($media=="")
			{
				$media="all";
			}
			$this->setValue("curmedia",$media);
			$this->setValue("tabname",$tabname);
			$this->setValue("fl","0");
			if($mod_rewrite==true)
			$this->setValue("mod","1");
			else
			$this->setValue("mod","0");
			$db->select("nesote_inoutse_itune_medias");
			$db->fields("id,media");
			$medialist=$db->query();
			$this->setLoopValue("medialist",$medialist->getresult());
		}
		
		$enginename=$this->getenginename($engineid);
		define('PAGETITLE',$servicename." - ".$enginename);
		define('HEADERKEYWORD',$servicename.",search,search engine,".$searchtype);
		$style="";
		$this->setValue("style",$style);
		$baseurl=$this->url();
		$this->setValue("baseurl",$baseurl);
	}
	function getconversions($keyword)
	{
		$keyword=str_replace(" ","",$keyword);
		$keyword=strtolower($keyword);
		$keyword=str_replace("=","",$keyword);
		$db= new NesoteDALController();
		$db->select("nesote_inoutse_conversions");
		$db->fields("source,target");
		$db->where("status=?",1);
		$result=$db->query();
		while($row=$result->fetchRow())
		{
			$source=str_replace(" ","",$row[0]);
			$source=strtolower($source);
			if($keyword==$source)
			{
				return $row[1];
			}
		}
		return "";
	}
	function getarithmeticconversion($keyword)
	{
		$this->loadLibrary('Settings');
		$settings=new Settings('nesote_inoutse_settings');
		$settings->loadValues();
		$arithmetic_conversionstatus=$settings->getValue("arithmetic_conversions");
		include("script.inc.php");
		include("{$config_path}system.config.php");
		if($arithmetic_conversionstatus==0)
		return "";
		$convertedstring=str_replace('+',"",$keyword);
		$convertedstring=str_replace('-',"",$convertedstring);
		$convertedstring=str_replace('*',"",$convertedstring);
		$convertedstring=str_replace('/',"",$convertedstring);
		$convertedstring=str_replace('%',"",$convertedstring);
		$convertedstring=str_replace('(',"",$convertedstring);
		$convertedstring=str_replace(')',"",$convertedstring);
		$convertedstring=str_replace('=',"",$convertedstring);
		$convertedstring=str_replace('.',"",$convertedstring);
		$convertedstring=preg_replace(' ',"",$convertedstring);
		$multipliedconvertedstring=$convertedstring*1;
		$keyword1=strchr($keyword,"=");
		$keyword1=str_replace("=","",$keyword1);
		if($keyword1!="")
		{
			return "";
		}
		elseif($convertedstring=="$multipliedconvertedstring")
		{
			if($mod_rewrite==true)
			$path="search/arithmeticconversion?search=".urlencode($keyword)."&type=web";
			else
			$path="search/arithmeticconversion&search=".urlencode($keyword)."&type=web";
			header("location:".$this->url($path));
		}
		else
		return "";
	}
	function arithmeticconversionAction($alignment=0)
	{
		$keyword=$_GET['search'];
		$keyword1=urlencode($keyword);
		$keyword1=str_replace("+","%2B",$keyword1);
		include("script.inc.php");
		include("{$config_path}system.config.php");
		$conversionkeyword=str_replace("=","",$keyword);
		eval("\$result = $conversionkeyword;");
		$this->setValue("conversionkeyword",$conversionkeyword);
		if($result=="")
		{
			if($alignment==0)
			{
				if($mod_rewrite==true)
				header("Location:".$this->url("search/web?search=".urlencode($keyword)."&type=web&nocal=1"));
				else
				header("Location:".$this->url("search/web&search=".urlencode($keyword)."&type=web&nocal=1"));
			}
			else
			{
				if($mod_rewrite==true)
				header("Location:".$this->url("search/web_rl?search=".urlencode($keyword)."&type=web&nocal=1"));
				else
				header("Location:".$this->url("search/web_rl&search=".urlencode($keyword)."&type=web&nocal=1"));
			}
		}
		$this->setValue("result",$result);
		$this->setValue("keyword",$keyword);
		$this->loadLibrary('Settings');
		$settings=new Settings('nesote_inoutse_settings');
		$settings->loadValues();
		$servicename=$settings->getValue("service_name");
		$this->setValue("servicename",$servicename);
		$seasonal_logo_status=$settings->getValue("seasonal_logo");
		if($seasonal_logo_status==1)
		{
			$time=time();
			$db= new NesoteDALController();
			$db->select("nesote_inoutse_seasonallogo");
			$db->fields("id,resultpage_logo");
			$db->where("startdate<=? and enddate>=? and status=1",$time);
			$result=$db->query();
			$row=$db->fetchRow($result);
			if($row[1]!="")
			{
				$logostatus=1;
				$userlogo=$row[1];
				$this->setValue("logoid",$row[0]);
			}
			elseif($row[1]=="")
			{
				$logostatus=0;
				$userlogo=$settings->getValue("result_logo");  ////////////     seasonal logo status
			}
		}
		else
		{
			$logostatus=0;
			$userlogo=$settings->getValue("result_logo");
		}
		$this->setValue("logo",$userlogo);
		$this->setValue("logostatus",$logostatus);
		$message=array("servicename"=>$servicename);
		$home=$this->getmessagegrammer(47,$message,0);
		$this->setValue("home",$home);
		$style="";
		$this->setValue("style",$style);
		define('PAGETITLE',$servicename." - ".$this->getmessage(56));
		define('HEADERKEYWORD',$servicename.",search,search engine");
		if($alignment==0)
		{
			if($mod_rewrite==true)
			$show=array("keyword"=>"<a dir=\"ltr\" href=\"".$this->url("search/web?search=".urlencode($keyword)."&type=web&nocal=1")."\">".$keyword."</a>");
			else
			$show=array("keyword"=>"<a dir=\"ltr\" href=\"".$this->url("search/web&search=".urlencode($keyword)."&type=web&nocal=1")."\">".$keyword."</a>");
		}
		else
		{
			if($mod_rewrite==true)
			$show=array("keyword"=>"<a dir=\"rtl\" href=\"".$this->url("search/web_rl?search=".urlencode($keyword)."&type=web&nocal=1")."\">".$keyword."</a>");
			else
			$show=array("keyword"=>"<a dir=\"rtl\" href=\"".$this->url("search/web_rl&search=".urlencode($keyword)."&type=web&nocal=1")."\">".$keyword."</a>");
		}
		$str=$this->getmessagegrammer(29,$show);
		$this->setValue("show",$str);
	}
	function getspecialstatus($engineid)
	{
		$db= new NesoteDALController();
		$db->select("nesote_inoutse_engines");
		$db->fields("special_status");
		$db->where("id=?",$engineid);
		$result=$db->query();
		$row=$db->fetchRow($result);
		return $row[0];
	}
	function getenginename($eng_id)
	{
		$lang_id="";
		$this->loadLibrary("settings");
		$set=new settings("nesote_inoutse_settings");
		$set->loadValues();
		$defaultlang_id=$set->getValue("default_language");
		$db=new NesoteDALController();
		if(isset ($_COOKIE['language']))
		{
			$lang_id=$_COOKIE['language'];
			$db->select("nesote_inoutse_languages");
			$db->fields("id");
			$db->where("lang_code=?", array($lang_id));
			$result=$db->query();
			$row=$db->fetchRow($result);
			$lang_id=$row[0];
		}
		else
		{
			$lang_id=$defaultlang_id;
		}
		if($lang_id!="")
		{
			$tot=$db->total("nesote_inoutse_enginenames","lang_id=? and engine_id=?",array($lang_id,$eng_id));
			if($tot!=0)
			{
				$db->select("nesote_inoutse_enginenames");
				$db->fields("namescript");
				$db->where("lang_id=? and engine_id=?", array($lang_id,$eng_id));
				$result=$db->query();
				$row=$db->fetchRow($result);
				return $row[0];
			}
			else
			{
				$tot=$db->total("nesote_inoutse_enginenames","lang_id=? and engine_id=?",array($defaultlang_id,$eng_id));
				if($tot!=0)
				{
					$db->select("nesote_inoutse_enginenames");
					$db->fields("namescript");
					$db->where("lang_id=? and engine_id=?", array($defaultlang_id,$eng_id));
					$result=$db->query();
					$row=$db->fetchRow($result);
					return $row[0];
				}
				else
				{
					$db->select("nesote_inoutse_engines");
					$db->fields("tab_name");
					$db->where("id=?", array($eng_id));
					$result=$db->query();
					$row=$db->fetchRow($result);
					return $row[0];
				}
			}
		}
		else
		{
			$db=new NesoteDALController();
			$db->select("nesote_inoutse_engines");
			$db->fields("tab_name");
			$db->where("id=?", array($eng_id));
			$result=$db->query();
			$row=$db->fetchRow($result);
			return $row[0];
		}
	}
	function web_rlAction()
	{
		$this->webAction(1);
		$this->loadLibrary("settings");
		$settings=new settings("nesote_inoutse_settings");
		$settings->loadValues();
		$adserver_installurl=$settings->getValue("adserver_installurl");
		$this->setValue("adserver_installurl",$adserver_installurl);
	}
	function images_rlAction()
	{
		$this->imagesAction(1);
	}
	function videos_rlAction()
	{
		$this->videosAction(1);
	}
	function news_rlAction()
	{
		$this->newsAction(1);
		$this->loadLibrary("settings");
		$settings=new settings("nesote_inoutse_settings");
		$settings->loadValues();
		$adserver_installurl=$settings->getValue("adserver_installurl");
		$this->setValue("adserver_installurl",$adserver_installurl);
			$thumshot_api=$settings->getValue("thumshot_url");		
		$thumshot_url="http://images.thumbshots.com/image.aspx?cid=$thumshot_api&v=1&w=120px&url=";
		$this->setValue("thumshot_url",$thumshot_url);
	}
	function special_rlAction()
	{
		$this->specialAction(1);
		$this->loadLibrary("settings");
		$settings=new settings("nesote_inoutse_settings");
		$settings->loadValues();
		$adserver_installurl=$settings->getValue("adserver_installurl");
		$this->setValue("adserver_installurl",$adserver_installurl);
				$thumshot_api=$settings->getValue("thumshot_url");		
		$thumshot_url="http://images.thumbshots.com/image.aspx?cid=$thumshot_api&v=1&w=120px&url=";
		$this->setValue("thumshot_url",$thumshot_url);
	}
	function datasource_rlAction()
	{
		$this->datasourceAction(1);
	}
	function emailafriend_rlAction()
	{
		$this->emailafriendAction(1);
	}
	function sendemail_rlAction()
	{
		$this->sendemailAction();
	}
	function noresults_rlAction()
	{
		$this->noresultsAction(1);
		$status=$_GET['status'];
		$this->setValue("stat",$status);
	}
	function arithmeticconversion_rlAction()
	{
		$this->arithmeticconversionAction(1);
	}
	function rsssource_rlAction()
	{
		$this->rsssourceAction(1);
	}
	function addslash($keyword)
	{
		return $keyword;
	}
	function getthumbshotdisplaystatus()
	{   
	   	$this->loadLibrary('Settings');
		$settings=new Settings('nesote_inoutse_settings');
		$settings->loadValues();
		$thumshot_api=$settings->getValue("thumshot_url");	
		if(!isset($thumshot_api) || $thumshot_api=="")
		return "display:none";
		elseif(!isset($_COOKIE['thumbshot']))
		return "";
		elseif($_COOKIE['thumbshot']=="on")
		return "";
		else
		return "display:none";
	}
	function getqlookdisplaystatus()
	{
		if(!isset($_COOKIE['qlook']))
		return "";
		if($_COOKIE['qlook']=="on")
		return "";
		else
		return "display:none";
	}
	function relatedkeywordlink($keyword,$type)
	{
		include('script.inc.php');
		include($config_path.'system.config.php');
		$keyword=html_entity_decode($keyword);
		$db=new NesoteDALController();
		$db->select("nesote_inoutse_engines");
		$db->fields("search_type");
		$db->where("tab_name=?", array($type));
		$result=$db->query();
		$row=$db->fetchRow($result);
		if($mod_rewrite==true)
		{
			return $this->url("search/".$row[0]."?search=".urlencode($keyword)."&type=$type");
		}
		else
		{
			return $this->url("search/".$row[0]."&search=".urlencode($keyword)."&type=$type");
		}
	}
	function getbreak($url)
	{
		$len=strlen($url);
		if($len>35)
		return "<br>";
		else
		return "";
	}
function twitterAction($alignment=0)
	{
		$valid=$this->uservalidation();
		$this->setValue("valid",$valid);
		$keyword=$_GET['search']; //reading search keyword
		$quotestatus=get_magic_quotes_gpc();
		if($quotestatus==1)
		$keyword=stripslashes($keyword);
		$tabname=$_GET['type']; //reading tab name
		$fl=$_GET['fl'];
		if((!isset($_GET['type']))||($_GET['type']==""))
		$tabname="twitter";
		if((!isset($_GET['search'])||($_GET['search']=="")))
		$keyword=str_replace("%2NNFF","/",$this->getParam(1));
		$suggestion_keyword=$keyword;
$this->setValue("getkeyword",$keyword);
		include('script.inc.php');
		include($config_path.'system.config.php');
		if($fl==1)
		$feelinglucky=1;
		$quotestatus=get_magic_quotes_gpc();
		if($quotestatus==1)
		$keyword=stripslashes($keyword);
		$keyword=str_replace('"',' " ',$keyword);
		$keyword=str_replace("'"," ' ",$keyword);
		$keyword=$this->familyfilter($keyword);
		$keyword=str_replace("' ","'",$keyword);
		$keyword=str_replace(" '","'",$keyword);
		$keyword=str_replace('" ','"',$keyword);
		$keyword=str_replace(' "','"',$keyword);
		$db= new NesoteDALController();
		$db->select("nesote_inoutse_engines");
		$db->fields("id,search_type");
		$db->where("tab_name=?",$tabname);
		$result=$db->query();
		$row=$db->fetchRow($result);
		$searchtype=$row[1]; //reading search type
		$engineid=$row[0];   //reading engine id
		$db= new NesoteDALController();
		$tot=$db->total("nesote_inoutse_engines","tab_name=? and status=?",array($tabname,1));
		if(($keyword=="")||($tot==0))
		{
			$keyword=urlencode($keyword);
			if($mod_rewrite==true)
			header("Location:".$this->url("search/noresults?search=$keyword&type=$searchtype"));
			else
			header("Location:".$this->url("search/noresults&search=$keyword&type=$searchtype"));
			exit(0);
		}
		$page=1;
		if(isset($_GET['startpage']))
		$page=$_GET['startpage'];   // reading page value
		if ($page=="")
		$page=1;
		$tabkeyword=str_replace("/","%2NNFF",$keyword);
		$this->setValue("keyword",$tabkeyword);
		$this->setValue("tabname",$tabname);
		$this->loadLibrary('Settings');
		$settings=new Settings('nesote_inoutse_settings');
		$settings->loadValues();
		$count=$settings->getValue("twitter_result_count");// read no of results to be fetched for ebay from settings
		$relatedtag_count=$settings->getValue("related_tags_count");
		$styleid=$settings->getValue("result");
		$openin_newwindow=$settings->getValue("new_window");
		$this->setValue("newwindow",$openin_newwindow);
		$emailafrnd=$settings->getValue("email_a_frnd");
		$this->setValue("emailafrnd",$emailafrnd);
		$quicklook=$settings->getValue("quicklook");
		$this->setValue("quicklook",$quicklook);
		$servicename=$settings->getValue("service_name");
		$this->setValue("servicename",$servicename);
		$seasonal_logo_status=$settings->getValue("seasonal_logo");
		if($seasonal_logo_status==1)
		{
			$time=time();
			$db->select("nesote_inoutse_seasonallogo");
			$db->fields("id,resultpage_logo");
			$db->where("startdate<=? and enddate>=? and status=1",$time);
			$result=$db->query();
			$row=$db->fetchRow($result);
			if($row[1]!="")
			{
				$logostatus=1;
				$userlogo=$row[1];
				$this->setValue("logoid",$row[0]);
			}
			elseif($row[1]=="")
			{
				$logostatus=0;
				$userlogo=$settings->getValue("result_logo");  ////////////     seasonal logo status
			}
		}
		else
		{
			$logostatus=0;
			$userlogo=$settings->getValue("result_logo");
		}
		$this->setValue("logo",$userlogo);
		$this->setValue("logostatus",$logostatus);
		$quicklook_user_override=$settings->getValue("quicklook_user_override");
		$this->setValue("qlook_useroverride",$quicklook_user_override);
		$ad_codes=$settings->getValue("ad_codes");
		$this->setValue("ad_codes",$ad_codes);
		$star_status=$settings->getValue("star_status");
		$this->setValue("star_status",$star_status);
		$member_status=$settings->getValue("member_status");
		if($member_status==1)
		$comment_status=$settings->getValue("comment_status");
		else
		$comment_status=0;
		$this->setValue("comment_status",$comment_status);
			$tab_status=$settings->getValue("tabstatus");
		$this->setValue("status",$tab_status);
		$message=array("servicename"=>$servicename);
		$home=$this->getmessagegrammer(47,$message,0);
		$this->setValue("home",$home);
		$this->setValue("engineid",$engineid);
		$enginename=$this->getenginename($engineid);
		define('PAGETITLE',$servicename." - ".$enginename." - ".$keyword);
$this->setValue('pagetitle',$servicename." - ".$enginename." - ".$keyword);
		define('HEADERKEYWORD',$servicename.",search,search engine,".$keyword.",".$searchtype);
		$typearray=array("type"=>$enginename)	;
		$typesearch=$this->getmessagegrammer(23,$typearray);
		$this->setValue("typesearch",$typesearch);
		$url=$this->geturl($engineid,$searchtype,$keyword,$page);
		$xmldata=$this->geturlcontent($url,$engineid,$keyword);
		$style="";
		$this->setValue("style",$style);
$result1=array();
foreach ($xmldata->statuses as $result)
{
    $result1[]=array('text'=>$result->text,
    		'desc'=>$result->user->description,
    		'imgurl'=>$result->user->profile_image_url,
    		'url'=>$result->user->url,
    		'auther'=>$result->user->name,
    		'autheurl'=>$result->user->profile_image_url);
}
for($i=0;$i<count($result1);$i++)
{
$resultset[1][$i]=strip_tags($result1[$i]['text']);
$resultset[2][$i]=strip_tags($result1[$i]['desc']);
$resultset[3][$i]=strip_tags($result1[$i]['imgurl']);
$resultset[4][$i]=strip_tags($result1[$i]['url']);
$resultset[5][$i]=strip_tags($result1[$i]['auther']);
$resultset[6][$i]=strip_tags($result1[$i]['autheurl']);
}
$total=100;
		if(count($resultset[1])==0)
		{
			$keyword=urlencode($keyword);
			if($mod_rewrite==true)
			header("Location:".$this->url("search/noresults?search=$keyword&type=$searchtype"));
			else
			header("Location:".$this->url("search/noresults&search=$keyword&type=$searchtype"));
			exit(0);
		}
		$this->setValue("total",$totalstr);
		$keyword1=urlencode($keyword);
		$keywordsuggestion_status=$db->total("nesote_inoutse_engines","id=? and keyword_suggestion_status=1",array($engineid));
		if($page==1 && $keywordsuggestion_status!=0 && trim($suggestion_keyword)==trim($keyword))
		{
			$tot1=$db->total("nesote_inoutse_keywordsuggestions","engine_id=? and keyword=?",array($engineid,$suggestion_keyword));
			if($tot1==0)
			{
				$db->insert("nesote_inoutse_keywordsuggestions");
				$db->fields("engine_id,keyword,total,searchcount,time");
				$db->values(array($engineid,$suggestion_keyword,$total1,1,time()));
				$db->query();
			}
			else
			{
				$db->update("nesote_inoutse_keywordsuggestions");
				$db->set("searchcount=searchcount+1,time=?,total=?",array(time(),$total1));
				$db->where("engine_id=? and keyword=?",array($engineid,$suggestion_keyword));
				$db->query();
			}
		}
		$nextpage=$page+1;
		if($page!=1)
		{
			$footerlink.="<li class=\"pgntn-li float-left\"><a class=\"pgntn-a pgn-arw\" href=javascript:loadpage($previouspage)>".$this->getmessage(6)."</a></li>";
		}
		if(($page*10<$total))
		{
			$footerlink.="<li class=\"pgntn-li float-left\"><a class=\"pgntn-a pgn-arw\" href=javascript:loadpage($nextpage)>".$this->getmessage(5)."</a></li>";
		}
		$this->setValue("footerlink",$footerlink);
		$finalkeywordarray=[];
		$j=0;
		$finalresult=[];
		$count=count($resultset[1]);
		for($i=0;$i<$count-1;$i++)
		{
			if(($i==0)&&($feelinglucky==1))
			{
				header("Location:".strip_tags($resultset[2][$i]));
				exit(0);
			}
			$finalresult[$j][1]=$this->makebold(strip_tags($resultset[1][$i]),$keyword,0);//title
			$var=html_entity_decode($resultset[2][$i]);//content
			$var=str_replace("<b>","",$var);
			$var=str_replace("</b>","",$var);
			$finalresult[$j][2]=$this->makebold($var,$keyword,0);
			$finalresult[$j][3]=html_entity_decode($resultset[3][$i]);//imageurl
			$finalresult[$j][4]=trim(html_entity_decode($resultset[4][$i]));//title url
			$finalresult[$j][5]=$this->makebold(strip_tags($resultset[5][$i]),$keyword,0);//author
			$finalresult[$j][6]=$resultset[6][$i];//author url
			$finalresult[$j][7]=$this->getstar($finalresult[$j][4],$engineid);
			$j++;
		}
$finalcount=count($finalresult);
		if($finalcount==0)
		{
			$keyword=urlencode($keyword);
			include('script.inc.php');
			include($config_path.'system.config.php');
			if($mod_rewrite==true)
			header("Location:".$this->url("search/noresults?search=$keyword&type=$searchtype"));
			else
			header("Location:".$this->url("search/noresults&search=$keyword&type=$searchtype"));
			exit(0);
		}
        $this->setValue("count",$count);
		$this->setLoopValue("results",$finalresult);
	}
	function snippet($snippet)
	{
		echo $snippet;
	}
	function itunecookiesAction()
	{
		$db= new NesoteDALController();
		$keyword=$_GET['search'];
		$tabname=$_GET['type']; //reading tab name
		$fl=$_GET['fl'];
		if((!isset($_GET['type']))||($_GET['type']==""))
		$tabname="itunes";
		if(isset($_GET['country']))
		{
			$itunecountry=$_GET['country'];
			setcookie("itune_country",$itunecountry,"0","/");
		}
		if(isset($_GET['media']))
		{
			$mediaid=$_GET['media'];
			$db->select("nesote_inoutse_itune_medias");
			$db->fields("id,media");
			$db->where("id=?", array($mediaid));
			$result=$db->query();
			$medialist=$db->fetchRow($result);
			$media=$medialist[1];
			setcookie("itune_media",$media,"0","/");
		}
		include('script.inc.php');
		include($config_path.'system.config.php');
		if($mod_rewrite==true)
		{
			header("Location:".$this->url("search/itunes?search=$keyword&type=$tabname&fl=$fl"));
		}
		else
		header("Location:".$this->url("search/itunes&search=$keyword&type=$tabname&fl=$fl"));
		exit(0);
	}
	function itunesAction($alignment=0)
	{
		$keyword=$_GET['search']; //reading search keyword
		$quotestatus=get_magic_quotes_gpc();
		if($quotestatus==1)
		$keyword=stripslashes($keyword);
		$tabname=$_GET['type']; //reading tab name
		$fl=$_GET['fl'];
		if((!isset($_GET['type']))||($_GET['type']==""))
		$tabname="itunes";
		if((!isset($_GET['search'])||($_GET['search']=="")))
		$keyword=str_replace("%2NNFF","/",$this->getParam(1));
		$suggestion_keyword=$keyword;
$this->setValue("getkeyword",$keyword);
		include('script.inc.php');
		include($config_path.'system.config.php');
		if($fl==1)
		$feelinglucky=1;
		$quotestatus=get_magic_quotes_gpc();
		if($quotestatus==1)
		$keyword=stripslashes($keyword);
		$keyword=str_replace('"',' " ',$keyword);
		$keyword=str_replace("'"," ' ",$keyword);
		$keyword=$this->familyfilter($keyword);
		$keyword=str_replace("' ","'",$keyword);
		$keyword=str_replace(" '","'",$keyword);
		$keyword=str_replace('" ','"',$keyword);
		$keyword=str_replace(' "','"',$keyword);
		$db= new NesoteDALController();
		$db->select("nesote_inoutse_engines");
		$db->fields("id,search_type");
		$db->where("tab_name=?",$tabname);
		$result=$db->query();
		$row=$db->fetchRow($result);
		$searchtype=$row[1]; //reading search type
		$engineid=$row[0];   //reading engine id
		$db= new NesoteDALController();
		$tot=$db->total("nesote_inoutse_engines","tab_name=? and status=?",array($tabname,1));
		if(($keyword=="")||($tot==0))
		{
			$keyword=urlencode($keyword);
			if($mod_rewrite==true)
			header("Location:".$this->url("search/noresults?search=$keyword&type=$searchtype"));
			else
			header("Location:".$this->url("search/noresults&search=$keyword&type=$searchtype"));
			exit(0);
		}
		$page=1;
		if(isset($_GET['startpage']))
		$page=$_GET['startpage'];   // reading page value
		if ($page=="")
		$page=1;
		$tabkeyword=str_replace("/","%2NNFF",$keyword);
		$this->setValue("keyword",$tabkeyword);
		$this->setValue("tabname",$tabname);
		$this->setValue("fl",$fl);
		if($mod_rewrite==true)
		$this->setValue("mod","1");
		else
		$this->setValue("mod","0");
		$this->loadLibrary('Settings');
		$settings=new Settings('nesote_inoutse_settings');
		$settings->loadValues();
		$count=$settings->getValue("itune_result_count");// read no of results to be fetched for itune from settings
		$relatedtag_count=$settings->getValue("related_tags_count");
		$styleid=$settings->getValue("result");
		$openin_newwindow=$settings->getValue("new_window");
		$this->setValue("newwindow",$openin_newwindow);
		$emailafrnd=$settings->getValue("email_a_frnd");
		$this->setValue("emailafrnd",$emailafrnd);
		$quicklook=$settings->getValue("quicklook");
		$this->setValue("quicklook",$quicklook);
		$servicename=$settings->getValue("service_name");
		$this->setValue("servicename",$servicename);
		$star_status=$settings->getValue("star_status");
		$this->setValue("star_status",$star_status);
		$member_status=$settings->getValue("member_status");
		if($member_status==1)
		$comment_status=$settings->getValue("comment_status");
		else
		$comment_status=0;
		$this->setValue("comment_status",$comment_status);
$auto_scroll_status=$settings->getValue("auto_scroll_status");
		$this->setValue("auto_scroll_status",$auto_scroll_status);
		$seasonal_logo_status=$settings->getValue("seasonal_logo");
		if($seasonal_logo_status==1)
		{
			$time=time();
			$db->select("nesote_inoutse_seasonallogo");
			$db->fields("id,resultpage_logo");
			$db->where("startdate<=? and enddate>=? and status=1",$time);
			$result=$db->query();
			$row=$db->fetchRow($result);
			if($row[1]!="")
			{
				$logostatus=1;
				$userlogo=$row[1];
				$this->setValue("logoid",$row[0]);
			}
			elseif($row[1]=="")
			{
				$logostatus=0;
				$userlogo=$settings->getValue("result_logo");  ////////////     seasonal logo status
			}
		}
		else
		{
			$logostatus=0;
			$userlogo=$settings->getValue("result_logo");
		}
		$this->setValue("logo",$userlogo);
		$this->setValue("logostatus",$logostatus);
		$quicklook_user_override=$settings->getValue("quicklook_user_override");
		$this->setValue("qlook_useroverride",$quicklook_user_override);
		$ad_codes=$settings->getValue("ad_codes");
		$this->setValue("ad_codes",$ad_codes);
		$message=array("servicename"=>$servicename);
		$home=$this->getmessagegrammer(47,$message,0);
		$this->setValue("home",$home);
		$this->setValue("engineid",$engineid);
		$enginename=$this->getenginename($engineid);
		define('PAGETITLE',$servicename." - ".$enginename." - ".$keyword);
                $this->setValue('pagetitle',$servicename." - ".$enginename." - ".$keyword);
		define('HEADERKEYWORD',$servicename.",search,search engine,".$keyword.",".$searchtype);
		$typearray=array("type"=>$enginename)	;
		$typesearch=$this->getmessagegrammer(23,$typearray);
		$this->setValue("typesearch",$typesearch);
		$db->select("nesote_inoutse_itune_countries");
		$db->fields("*");
		$db->order("country_name");
		$countrylist=$db->query();
		$this->setLoopValue("countrylist",$countrylist->getresult());
		$country=$_COOKIE["itune_country"];
		if($country=="")
		{
			$country="US";
		}
		$this->setValue("curcountry",$country);
		$db->select("nesote_inoutse_itune_medias");
		$db->fields("id,media");
		$medialist=$db->query();
		$this->setLoopValue("medialist",$medialist->getresult());
		$media=$_COOKIE["itune_media"];
		if($media=="")
		{
			$media="all";
		}
		$this->setValue("curmedia",$media);
		$url="http://ax.itunes.apple.com/WebObjects/MZStoreServices.woa/wa/wsSearch?term=$keyword&country=$country&media=$media&limit=$count";
		$xmldata=$this->geturlcontent($url,$engineid,$keyword);
		$xmldata=str_replace("\r\n","",$xmldata);
		$xmldata=str_replace("\n","",$xmldata);
		$xmldata=str_replace("\r","",$xmldata);
		$responseobject = json_decode($xmldata, true);
		$countitune=$responseobject['resultCount'];
		$allresponseresults=$responseobject['results'];
		foreach ($allresponseresults as $responseresult)
		{
			if($media!="software")
			$img=$responseresult['artworkUrl100'];
			else
			$img=$responseresult['artworkUrl60'];
			if($media=="ebook")
			{
				$description= substr( strip_tags( $responseresult['description']),0,100);
				$wrapper=$responseresult['wrapperType'];
				if($wrapper=="")
				{
					$wrapper="ebook";
				}
			}
			else
			{
				$description=$responseresult['primaryGenreName'];
				$wrapper=$responseresult['wrapperType'];
			}
			$resultitune[] = array(
						'0' => $wrapper,
		                '1' => $responseresult['kind'],		               
			            '2' => $responseresult['artistName'],
		            	'3' => $responseresult['trackName'],
			            '4' => $responseresult['collectionName'],
			            '5' => $img,
		                '6' => $responseresult['artistViewUrl'],
		            	'7' => $responseresult['trackViewUrl'],
			            '8' => $responseresult['collectionViewUrl'],
			            '9' => $responseresult['releaseDate'],
			 		   '10' => $description,
		               '11' => $responseresult['trackPrice'],
		               '12' => $responseresult['collectionPrice'],
			           '13' => $responseresult['price'],
			           '14' => $responseresult['currency']
			);
		}
		$style="";
		$this->setValue("style",$style);
		if(count($resultitune)==0) // or  if($countitune==0)
		{
			$keyword=urlencode($keyword);
			if($mod_rewrite==true)
			header("Location:".$this->url("search/noresults?search=$keyword&type=$searchtype"));
			else
			header("Location:".$this->url("search/noresults&search=$keyword&type=$searchtype"));
			exit(0);
		}
		$total=$countitune;
		$start=10*($page-1);
		$startingnum=($page*10)-9;
		$endingnum=$page*10;
		if($total<$endingnum)
		$endingnum=$total;
		if($total<10)
		$startingnum=1;
		else
		$startingnum=($page*10)-9;
		$baseurl=$this->url();
		$this->setValue("baseurl",$baseurl);
		$message=array("startingnum"=>$startingnum,"endingnum"=>$endingnum,"keyword"=>htmlentities($keyword,ENT_QUOTES,"UTF-8"));
		$style=array("resultcountstart","resultcountend","keywordintotal");
		$totalstr=$this->getmessagegrammer(419,$message,$style);
		$this->setValue("total",$totalstr);
		$keyword1=urlencode($keyword);
		$keywordsuggestion_status=$db->total("nesote_inoutse_engines","id=? and keyword_suggestion_status=1",array($engineid));
		if($page==1 && $keywordsuggestion_status!=0 && trim($suggestion_keyword)==trim($keyword))
		{
			$tot1=$db->total("nesote_inoutse_keywordsuggestions","engine_id=? and keyword=?",array($engineid,$suggestion_keyword));
			if($tot1==0)
			{
				$db->insert("nesote_inoutse_keywordsuggestions");
				$db->fields("engine_id,keyword,searchcount,time");
				$db->values(array($engineid,$suggestion_keyword,1,time()));
				$db->query();
			}
			else
			{
				$db->update("nesote_inoutse_keywordsuggestions");
				$db->set("searchcount=searchcount+1,time=?",array(time()));
				$db->where("engine_id=? and keyword=?",array($engineid,$suggestion_keyword));
				$db->query();
			}
		}
	$previouspage=$page-1;
		if($page<=4)
		{
			$startpage=1;
			$endpage=5;
		}
		else
		{
			$startpage=$page-3;
			$endpage=$page+1;
		}
		$nextpage=$page+1;
		if($page!=1)
		{
		$footerlink.="<li class=\"pgntn-li float-left\"><a class=\"pgntn-a pgn-arw\" href=javascript:loadpage($previouspage)><i class=\"fas fa-chevron-left\"></i></a></li>";
		}
		for($i=$startpage;$i<=$endpage;$i++)
		{
			if($i*10<($total+10))
			{
				if($i!=$page)
				{
					$footerlink.="<li class=\"pgntn-li float-left\"><a class=\"pgntn-a pgn-cnt\" href=javascript:loadpage($i)>$i</a></li>";
				}
				else 
				{
					$footerlink.="<li class=\"pgntn-li float-left\"><a class=\"pgntn-a pgn-cnt pgn-actv\" href=javascript:loadpage($i)>$i</a></li>";
				}
			}
		}
		if($page*10<($total))
		{
		$footerlink.="<li class=\"pgntn-li float-left\"><a class=\"pgntn-a pgn-arw\" href=javascript:loadpage($nextpage)><i class=\"fas fa-chevron-right\"></i></a></li>";
		}
		$this->setValue("footerlink",$footerlink);
		$relatedkeywords=$this->getrelatedkeyword($keyword,$xmldata);
		$finalkeywordarray=[];
		for($i=0;$i<$relatedtag_count;$i++)
		{
			$finalkeywordarray[$i][0]=$relatedkeywords[$i];
		}
		if($finalkeywordarray[0][0]!="")
		$this->setValue("keywordstatus",1);
		else
		$this->setValue("keywordstatus",0);
		$this->setLoopValue("relatedkeywords",$finalkeywordarray);
		$j=0;
		$finalresult=[];
		for($i=$start;$i<=($start+9)&& $i<=$total;$i++)
		{
			if(($resultitune[$i][0]=="")&&($resultitune[$i][6]=="")&&($resultitune[$i][5]==""))
			break;
			if(($i==0)&&($feelinglucky==1))
			{
				if($resultitune[$i][7]!="")
				{
					header("Location:".strip_tags($resultitune[$i][7]));
					exit(0);
				}
				else
				{
					header("Location:".strip_tags($resultitune[$i][6]));
					exit(0);
				}
			}
			$finalresult[$j][1]=$resultitune[$i][0]; //wrapper
			$finalresult[$j][2]=$resultitune[$i][1]; //kind
			$finalresult[$j][3]=$this->makebold(strip_tags($resultitune[$i][2]),$keyword,0); //artistname
			$finalresult[$j][4]=$this->makebold(strip_tags($resultitune[$i][3]),$keyword,0); //trackname
			$finalresult[$j][5]=$this->makebold(strip_tags($resultitune[$i][4]),$keyword,0); //collectionname
			$finalresult[$j][6]=html_entity_decode($resultitune[$i][5]); //imageurl
			$finalresult[$j][7]=html_entity_decode($resultitune[$i][6]); //artistViewUrl
			$finalresult[$j][8]=html_entity_decode($resultitune[$i][7]); //trackViewUrl
			$finalresult[$j][9]=html_entity_decode($resultitune[$i][8]); //collectionViewUrl
			$finalresult[$j][10]=$resultitune[$i][9]; //releaseDate
			$finalresult[$j][11]=$resultitune[$i][10]; //primaryGenreName
			$finalresult[$j][12]=$resultitune[$i][11]; //trackPrice
			$finalresult[$j][13]=$resultitune[$i][12]; //collectionPrice
			$finalresult[$j][14]=$resultitune[$i][13]; //price
			$finalresult[$j][15]=$resultitune[$i][14]; //currency
			$finalresult[$j][16]=$this->getstar($finalresult[$j][4],$engineid);
			$j++;
		}
$finalcount=count($finalresult);
		if($finalcount==0)
		{
			$keyword=urlencode($keyword);
			include('script.inc.php');
			include($config_path.'system.config.php');
			if($mod_rewrite==true)
			header("Location:".$this->url("search/noresults?search=$keyword&type=$searchtype"));
			else
			header("Location:".$this->url("search/noresults&search=$keyword&type=$searchtype"));
			exit(0);
		}
		$this->setLoopValue("results",$finalresult);
	}
	function twitter_rlAction()
	{
		$this->twitterAction(1);
	}
	function itunes_rlAction()
	{
		$this->itunesAction(1);
	}
	function getsearchindexAction()
	{
		$country=$this->getParam(1);
		if(isset($_COOKIE['searchindex']))
		{
			$amazon_searchindex=$_COOKIE['searchindex'];
		}
		else
		{
			$this->loadLibrary('Settings');
			$settings=new Settings('nesote_inoutse_settings');
			$settings->loadValues();
			$amazon_searchindex=$settings->getValue("amazon_searchindex");
		}
		$db= new NesoteDALController();
		$db->select("nesote_inoutse_searchindex");
		$db->fields("id,searchindex");
		$db->where("country=?",$country);
		$result=$db->query();
		$i=0;
		while($row=$result->fetchRow())
		{
			$resultset[$i][0]=$row[0];
			$resultset[$i][1]=$row[1];
			$i++;
		}
		$str.='<select name="search_index" id="seach_index"  tabindex="1">';
		for($i=0;$i<=count($resultset);$i++)
		{
			$str.='<option value="';
			$str.= $resultset[$i][0];
			if($resultset[$i][0]==$amazon_searchindex)
			$str.='" selected="selected">';
			else
			$str.='">';
			$str.=$resultset[$i][1];
			$str.='</option>';
		}
		$str.='</select>';
		echo  $str;
	}
	function storesearchindexAction()
	{
		$search_index=$_POST['search_index'];
		$pageurl=$_POST['pageurl'];
		$host=$_SERVER['HTTP_HOST'];
		setcookie("searchindex",$search_index,"0","/");
		if(substr_count($pageurl,"startpage")!=0)
		{
			$pageurlarray=explode("&startpage",$pageurl);
			$pageurl=$pageurlarray[0]."&startpage=1";
		}
		header("location:".$pageurl);
		exit(0);
	}
	function getreviewmessage($review)
	{
		$reviewarray=array("review"=>$review);
		$reviewmsg=$this->getmessagegrammer(68,$reviewarray);
		return $reviewmsg;
	}
	function averagerateAction()
	{
		$rate=$this->getParam(1);
		if ($rate==0)
		{
			$star=0;
		}
		if (($rate==1) or ($rate>1 and $rate<1.5))
		{
			$star=1;
		}
		if (($rate==1.5) or ($rate>1.5 and $rate<2))
		{
			$star=1.5;
		}
		if (($rate==2) or ($rate>2 and $rate<2.5))
		{
			$star=2;
		}
		if (($rate==2.5) or ($rate>2.5 and $rate<3))
		{
			$star=2.5;
		}
		if (($rate==3) or ($rate>3 and $rate<3.5))
		{
			$star=3;
		}
		if (($rate==3.5) or ($rate>3.5 and $rate<4))
		{
			$star=3.5;
		}
		if (($rate==4) or ($rate>4 and $rate<4.5))
		{
			$star=4;
		}
		if (($rate==4.5) or ($rate>4.5 and $rate<5))
		{
			$star=4.5;
		}
		if ($rate==5)
		{
			$star=5;
		}
		$this->setValue("star",$star);
	}
	function generatesearchboxcodeAction($alignment=0)
	{  
		$this->loadLibrary('Settings');
		$settings=new Settings('nesote_inoutse_settings');
		$settings->loadValues();
		$choose_engine_status=$settings->getValue("allowusers_choose_engines");
		$add_searchcode_status=$settings->getValue("webmaster_add_sitesearch");
		$webmaster_logo=$settings->getValue("webmaster_logo");
		$webmaster_style=$settings->getValue("webmaster_style");
		$servicename=$settings->getValue("service_name");
		$webmaster_logo_useroverride_status=$settings->getValue("allow_users_webmasterlogo");
		$this->setvalue("webmaster_logo_useroverride_status",$webmaster_logo_useroverride_status);
		$message=array("servicename"=>$servicename);
		$home=$this->getmessagegrammer(47,$message,0);
		$this->setValue("home",$home);
		if($add_searchcode_status!=1)
		{
			header("Location:".$this->url(""));
			exit(0);
		}
		if(isset($_POST['process_status']))
		$border_status=$_POST['borderstatus'];
		else
		$border_status=1;
		$this->setValue("borderstatus",$border_status);
		$weblogostatus=1;
		if(isset($_POST['searchbox_width']))
		{
			if(isset($_POST['weblogostatus']))
			$weblogostatus=$_POST['weblogostatus'];
			else
			$weblogostatus=0;
		}
		$this->setValue("weblogostatus",$weblogostatus);
		if(isset($_POST['colors']))
		$bordercolor=$_POST['colors'];
		else
		$bordercolor="#999999";
		$this->setValue("bordercolor",$bordercolor);
		if($border_status==1)
		{
			$borderstyle=" .outerborder { border-style: solid;border-color: {$bordercolor};border-width:1px; }";
		}
		else
		{
			$borderstyle=" .outerborder	{ border-width:0px;	}";
		}
		$webmaster_style.=$borderstyle;
		$webmaster_style=str_replace("\r\n","",$webmaster_style);
		$webmaster_style=str_replace("\n","",$webmaster_style);
		$webmaster_style=str_replace("\r","",$webmaster_style);
		$webmaster_style=str_replace("\t","",$webmaster_style);
		while(substr_count($webmaster_style,"  ")!=0)
		{
			$webmaster_style=str_replace("  "," ",$webmaster_style);
		}
		$this->setValue("webstyle",$webmaster_style);
		if($_POST['searchbox_width']=="")
		$searchbox_width=$settings->getValue("searchbox_width");
		else
		$searchbox_width=$_POST['searchbox_width'];
		$this->setValue("width",$searchbox_width);
		$seasonal_logo_status=$settings->getValue("seasonal_logo");
		$displaystyle=1;
		if(isset($_POST['display_style']))
		$displaystyle=$_POST['display_style'];
		define('PAGETITLE',$servicename." - ".$this->getmessage(88));
		define('HEADERKEYWORD',$servicename.",search,search engine");
		$this->setValue("displaystyle",$displaystyle);
		$this->setValue("choose_engine_status",$choose_engine_status);
		$db=new NesoteDALController();
		$style="";
		$this->setValue("style",$style);
        $protocol = isset($_SERVER["HTTPS"]) ? 'https://' : 'http://';
		$imagepath=$protocol.$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME'];
		$imagepath=str_replace("index.php","",$imagepath);
		$this->setValue("imagepath",$imagepath);
		$logopath=$protocol.$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME'];
		$logopath=str_replace("index.php","userdata/",$logopath);
		$logopath.=	$webmaster_logo;
		$this->setValue("logopath",$logopath);
		$this->setValue("homepath",$this->url());
		$this->setValue("processpath",$this->url("search/redir"));
		if($seasonal_logo_status==1)
		{
			$time=time();
			$db->select("nesote_inoutse_seasonallogo");
			$db->fields("id,homepage_logo");
			$db->where("startdate<=? and enddate>=? and status=1",$time);
			$result=$db->query();
			$row=$db->fetchRow($result);
			if($row[1]!="")
			{
				$logostatus=1;
				$userlogo=$row[1];
				$this->setValue("logoid",$row[0]);
			}
			else
			{
				$logostatus=0;
				$userlogo=$settings->getValue("user_logo");
			} 
		}
		else
		{
			$logostatus=0;
			$userlogo=$settings->getValue("user_logo");
		}
		$this->setValue("logo",$userlogo);
		$this->setValue("logostatus",$logostatus);
		$db->select("nesote_inoutse_engines");
		$db->fields("id,tab_name");
		$db->where("status=1");
		$db->order("position asc");
		$result=$db->query();
		$num=$db->numRows($result);
		$this->setLoopValue("engines",$result->getresult());
		$flag=0;
		$j=0;
		$finalenginearray=[];
		if(($choose_engine_status==1) && (isset($_POST['process_status']))) /// set var in tpl to show checkbox is checked or not
		{
			while($row=$result->fetchRow())
			{
				if(isset($_POST['engine'.$row[0]]))
				{
					$flag=1;
					$finalenginearray[$j][0]=$row[0];
					$finalenginearray[$j][1]=$row[1];
					$j++;
				}
			}
		}
		else
		{
			while($row=$result->fetchRow())
			{
				if($row[0]=="")
				break;
				$flag=1;
				$finalenginearray[$j][0]=$row[0];
				$finalenginearray[$j][1]=$row[1];
				$j++;
			}
		}
		if($flag==1)
		{
			$this->setLoopValue("finalenginearray",$finalenginearray);
			$this->setValue("defaultenginetype",$finalenginearray[0][1]);
			$this->setValue("enginecount",count($finalenginearray));
		}
		$this->setValue("flag",$flag);
	}
	function getchecked($eid)
	{
		if(isset($_POST['engine'.$eid]) || !isset($_POST['process_status']))
		return "checked=checked";
		else
		return "";
	}
	function xmlsponsoredlinks($url)
	{
		if (function_exists('curl_init'))
		{
			$ch = curl_init();
			curl_setopt($ch, CURLOPT_URL,$url);
			curl_setopt($ch, CURLOPT_HEADER, 0);
			curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
			$xmldata = curl_exec($ch);
			curl_close($ch);
		}
		elseif($fp=fopen($url,"r"))
		{
			while(!feof($fp))
			{
				$xmldata.=fgetc($fp);
			}
			fclose($fp);
		}
		return $xmldata;
	}
	function generatesearchboxcode_rlAction()
	{
		$this->generatesearchboxcodeAction(1);
	}
	function getpublished_date($time)
	{
		$time_diff=time()-$time;
		if($time_diff<60) // seconds
		{
			$final_time=$time_diff;
			$message=array("time"=>$final_time);
			$style="";
			$msgstring=$this->getmessagegrammer(96,$message,$style);
		}
		elseif($time_diff<3600)// minutes 60x60
		{
			$final_time=$time_diff/60;
			$final_time=floor($final_time);
			$message=array("time"=>$final_time);
			$style="";
			$msgstring=$this->getmessagegrammer(97,$message,$style);
		}
		elseif($time_diff<86400) // hours 60x60x24
		{
			$final_time=$time_diff/(60*60);
			$final_time=floor($final_time);
			$message=array("time"=>$final_time);
			$style="";
			$msgstring=$this->getmessagegrammer(98,$message,$style);
		}
		elseif($time_diff<604800) // days 60x60x24x7
		{
			$final_time=$time_diff/(60*60*24);
			$final_time=floor($final_time);
			$message=array("time"=>$final_time);
			$style="";
			$msgstring=$this->getmessagegrammer(99,$message,$style);
		}
		elseif($time_diff<2592000) // weeks 60x60x24x30
		{
			$final_time=$time_diff/(60*60*24*7);
			$final_time=floor($final_time);
			$message=array("time"=>$final_time);
			$style="";
			$msgstring=$this->getmessagegrammer(100,$message,$style);
		}
		elseif($time_diff<31536000) // months 60x60x24x365
		{
			$final_time=$time_diff/(60*60*24*30);
			$final_time=floor($final_time);
			$message=array("time"=>$final_time);
			$style="";
			$msgstring=$this->getmessagegrammer(101,$message,$style);
		}
		else //years
		{
			$final_time=$time_diff/(60*60*24*365);
			$final_time=floor($final_time);
			$message=array("time"=>$final_time);
			$style="";
			$msgstring=$this->getmessagegrammer(102,$message,$style);
		}
		return $msgstring;
	}
	function testAction()
	{
		for($l=1;$l<29;$l++)
		{
			for($m=2009;$m<2012;$m++)
			{
				for($i=1;$i<13;$i++)
				{
					for($j=1;$j<32;$j++)
					{
						for($k=1;$k<10000;$k++)
						{
							unlink("xmldata1/cache".$l."/".$m."/".$i."/".$j."/".$k.".data");
						}
					}
				}
			}
		}
		exit(0);
	}
function getcommentsnw_images($url=false,$id=false,$engine="",$engine_id="",$glb=false){
		$align=$this->getalignment();
		if($align==2)
		{
			$direction="left";
			$table="right";
		}
		else
		{
			$direction="right";
			$table="left";
		}
                $url=trim($url);
		if($engine=="datasource")
		{
			$titleurl=$url;
			$cacheindex=$this->getcacheindex($engine_id);
			$titleurl=md5($titleurl);
			$type="datasource";
			$db=new NesoteDALController();
			$db->select("nesote_inoutse_commentcache".$cacheindex);
			$db->fields("*");
			$db->where("title_url=? and type=? and status=?",array($titleurl,$type,0));
			$db->order("time desc");
			//$db->limit(0,3);
			$result=$db->query();
			$num=$db->numRows($result);
			if($num!=0)
			{
				$url=urlencode($url);
				$url=base64_encode($url);
				$response="";
				$response.='<ul class="old_cmntul">';
				while ($frow=$db->fetchRow($result))
				{
					$comid=$frow[0];
					$time=date("d-m-Y",$frow[5]);
					$commen=$frow[7];
					$len=strlen($commen);
					$uid=$frow[2];
					$db->select("nesote_inoutscripts_users");
					$db->fields("username");
					$db->where("id=? and status=?",array($uid,1));
					$res=$db->query();
					$fetch=$db->fetchRow($res);
					$username1=$fetch[0];
$response.=' <div class="fullwidth drp-cmnts img-cmnt">
 <h5 class="cmnt-name">'.$this->getmessage(584).'&nbsp'.$username1.'</h5>
<span class="cmnt-date-time">'.$this->getmessage(585).'&nbsp;'.$time.'</span>
<p class="cmnt-cnt">'.$this->echocom($commen).'</p>
</div>';
				}
				$total=$db->total("nesote_inoutse_commentcache".$cacheindex,"title_url=? and type=? and status=?",array($titleurl,$type,0));
				$db->query();
			}
			else
			$response="";
			return $response;
		}
		else
		{
			$titleurl=$url;
			$domainurl=str_replace("http://","",$url);
			$domainurl=str_replace("https://","",$domainurl);
			$urlpos=strpos($domainurl,"/");
			if($urlpos!="")
			$domain=substr($domainurl,0,$urlpos);
			else
			$domain=$domainurl;
			$len_title=strlen($titleurl);
			if(substr($titleurl,-1)=="/")
			{
				$titleurl=substr($titleurl,0,$len_title-1);
			}
			$cacheindex=$this->getcacheindex($domain);
			if($engine=="jobsearch")
			{
				$urlpos=strpos($titleurl,"&indpubnum");
				$titleurl=substr($titleurl,0,$urlpos);
			}
			$titleurl=md5($titleurl);
			$domainurl=md5($domain);
			$type="title";
			$db=new NesoteDALController();
			$db->select("nesote_inoutse_commentcache".$cacheindex);
			$db->fields("*");
			$db->where("title_url=? and type=? and status=?",array($titleurl,$type,0));
			$db->order("time desc");
			//$db->limit(0,3);
			$result=$db->query();
			$num=$db->numRows($result);
			$tot1=$db->total("nesote_inoutse_commentcache".$cacheindex,"title_url=? and type=? and status=?",array($titleurl,$type,0));
			$db->query();
			if(($num==0)&&($engine!=2))
			{
				$type="domain";
				$db->select("nesote_inoutse_commentcache".$cacheindex);
				$db->fields("*");
				$db->where("domain_url=? and type=? and status=?",array($domainurl,$type,0));
				$db->order("time desc");
				$result=$db->query();
				$total=$db->numRows($result);
			}
	if($engine=="jobsearch")
			{
				$urlpos=strpos($url,"&indpubnum");
				$url=substr($url,0,$urlpos);
			}
			$url= $titleurl;//md5($url);
			$domain=base64_encode($domain);
			$response="";
			while ($frow=$db->fetchRow($result))
			{
				$comid=$frow[0];
				$time=date("d-m-Y",$frow[5]);
				$commen=$frow[7];
				$len=strlen($commen);
				$uid=$frow[2];
				$db->select("nesote_inoutscripts_users");
				$db->fields("username");
				$db->where("id=? and status=?",array($uid,1));
				$res=$db->query();
				$fetch=$db->fetchRow($res);
				$username1=$fetch[0];
 $response.='<div class="fullwidth drp-cmnts img-cmnt">
			    <h5 class="cmnt-name img-c-name">'.$this->getmessage(584).'&nbsp'.$username1.'</h5>
				<span class="cmnt-date-time">'.$this->getmessage(585).'&nbsp;'.$time.'</span>
				<p class="cmnt-cnt">'.$this->echocom($commen).'</p>
			</div>';
			}
			if(($num!=0)&&($engine!=2))
			{
				$type="domain";
				$db->select("nesote_inoutse_commentcache".$cacheindex);
				$db->fields("*");
				$db->where("domain_url=? and type=? and status=?",array($domainurl,$type,0));
				$db->order("time desc");
				$domainresult=$db->query();
				while ($row=$db->fetchRow($domainresult))
				{
					$comid=$row[0];
					$time=date("d-m-Y",$row[5]);
					$commen=$row[7];
					$len=strlen($commen);
					$uid=$row[2];
					$db->select("nesote_inoutscripts_users");
					$db->fields("username");
					$db->where("id=? and status=?",array($uid,1));
					$res=$db->query();
					$fetch=$db->fetchRow($res);
					$username1=$fetch[0];
$response.='<div class="fullwidth drp-cmnts img-cmnt">
			    <h5 class="cmnt-name img-c-name">'.$this->getmessage(584).'&nbsp'.$username1.'</h5>
				<span class="cmnt-date-time">'.$this->getmessage(585).'&nbsp;'.$time.'</span>
				<p class="cmnt-cnt">'.$this->echocom($commen).'</p>
			</div>';
				}
			}
			$type="domain";
			$domcont=$db->total("nesote_inoutse_commentcache".$cacheindex,"domain_url=? and type=? and status=?",array($domainurl,$type,0));
			$db->query();
			if($engine!=2)
			$count=($tot1+$domcont);
			else
			$count=$tot1;
			if(($tot1==0)&&($domcont==0))
			$response="";
			return $response;
		}
	}
function getcommentsnw($url=false,$id=false,$engine="",$engine_id="",$glb=false)
	{
		$align=$this->getalignment();
		if($align==2)
		{
			$direction="left";
			$table="right";
		}
		else
		{
			$direction="right";
			$table="left";
		}
$url=trim($url);
		if($engine=="datasource")
		{
			$titleurl=$url;
			$cacheindex=$this->getcacheindex($engine_id);
			$titleurl=md5($titleurl);
			$type="datasource";
			$db=new NesoteDALController();
			$db->select("nesote_inoutse_commentcache".$cacheindex);
			$db->fields("*");
			$db->where("title_url=? and type=? and status=?",array($titleurl,$type,0));
			$db->order("time desc");
			$result=$db->query();
			$num=$db->numRows($result);
			if($num!=0)
			{
				$url=urlencode($url);
				$url=base64_encode($url);
				$response="";
				$response.='<ul class="old_cmntul">';
				while ($frow=$db->fetchRow($result))
				{
					$comid=$frow[0];
					$time=date("d-m-Y",$frow[5]);
					$commen=$frow[7];
					$len=strlen($commen);
					$uid=$frow[2];
					$db->select("nesote_inoutscripts_users");
					$db->fields("username");
					$db->where("id=? and status=?",array($uid,1));
					$res=$db->query();
					$fetch=$db->fetchRow($res);
					$username1=$fetch[0];
$response.=' <div class="fullwidth drp-cmnts">
 <h5 class="cmnt-name">'.$this->getmessage(584).'&nbsp'.$username1.'</h5>
<span class="cmnt-date-time">'.$this->getmessage(585).'&nbsp;'.$time.'</span>
<p class="cmnt-cnt">'.$this->echocom($commen).'</p>
</div>';
				}
				$total=$db->total("nesote_inoutse_commentcache".$cacheindex,"title_url=? and type=? and status=?",array($titleurl,$type,0));
				$db->query();
				if($total>3)
				$response.="<a class=\"sharegc initialism allcomment_open fadeandscale".$glb."_close viewmrecmnt btn-success\" href=\"#allcomment\"  onclick=\"showallcmnt('".$engine."','".$url."',$comid,'".$engine_id."')\" >".$this->getmessage(595)."</a>";
$response.=' </ul>';
			}
			else
			$response="";
			return $response;
		}
		else
		{
			$titleurl=$url;
			$domainurl=str_replace("http://","",$url);
			$domainurl=str_replace("https://","",$domainurl);
			$urlpos=strpos($domainurl,"/");
			if($urlpos!="")
			$domain=substr($domainurl,0,$urlpos);
			else
			$domain=$domainurl;
			$len_title=strlen($titleurl);
			if(substr($titleurl,-1)=="/")
			{
				$titleurl=substr($titleurl,0,$len_title-1);
			}
			$cacheindex=$this->getcacheindex($domain);
			if($engine=="jobsearch")
			{
				$urlpos=strpos($titleurl,"&indpubnum");
				$titleurl=substr($titleurl,0,$urlpos);
			}
			$titleurl=md5($titleurl);
			$domainurl=md5($domain);
			$type="title";
			$db=new NesoteDALController();
			$db->select("nesote_inoutse_commentcache".$cacheindex);
			$db->fields("*");
			$db->where("title_url=? and type=? and status=?",array($titleurl,$type,0));
			$db->order("time desc");
			$result=$db->query();
			$num=$db->numRows($result);
			$tot1=$db->total("nesote_inoutse_commentcache".$cacheindex,"title_url=? and type=? and status=?",array($titleurl,$type,0));
			$db->query();
			if(($num==0)&&($engine!=2))
			{
				$type="domain";
				$db->select("nesote_inoutse_commentcache".$cacheindex);
				$db->fields("*");
				$db->where("domain_url=? and type=? and status=?",array($domainurl,$type,0));
				$db->order("time desc");
				$result=$db->query();
				$total=$db->numRows($result);
			}
			if($engine=="jobsearch")
			{
				$urlpos=strpos($url,"&indpubnum");
				$url=substr($url,0,$urlpos);
			}
			$url= $titleurl;//md5($url);
			$domain=base64_encode($domain);
			$response="";
			while ($frow=$db->fetchRow($result))
			{
				$comid=$frow[0];
				$time=date("d-m-Y",$frow[5]);
				$commen=$frow[7];
				$len=strlen($commen);
				$uid=$frow[2];
				$db->select("nesote_inoutscripts_users");
				$db->fields("username");
				$db->where("id=? and status=?",array($uid,1));
				$res=$db->query();
				$fetch=$db->fetchRow($res);
				$username1=$fetch[0];
 $response.=' <div class="fullwidth drp-cmnts">
 <h5 class="cmnt-name">'.$this->getmessage(584).'&nbsp'.$username1.'</h5>
<span class="cmnt-date-time">'.$this->getmessage(585).'&nbsp;'.$time.'</span>
<p class="cmnt-cnt">'.$this->echocom($commen).'</p>
</div>';
			}
			if(($num!=0)&&($num<3)&&($engine!=2))
			{
				$limit=(3-$num);
				$type="domain";
				$db->select("nesote_inoutse_commentcache".$cacheindex);
				$db->fields("*");
				$db->where("domain_url=? and type=? and status=?",array($domainurl,$type,0));
				$db->order("time desc");
				$db->limit(0,$limit);
				$domainresult=$db->query();
				while ($row=$db->fetchRow($domainresult))
				{
					$comid=$row[0];
					$time=date("d-m-Y",$row[5]);
					$commen=$row[7];
					$len=strlen($commen);
					$uid=$row[2];
					$db->select("nesote_inoutscripts_users");
					$db->fields("username");
					$db->where("id=? and status=?",array($uid,1));
					$res=$db->query();
					$fetch=$db->fetchRow($res);
					$username1=$fetch[0];
               $response.=' <div class="fullwidth drp-cmnts">
 <h5 class="cmnt-name">'.$this->getmessage(584).'&nbsp'.$username1.'</h5>
<span class="cmnt-date-time">'.$this->getmessage(585).'&nbsp;'.$time.'</span>
<p class="cmnt-cnt">'.$this->echocom($commen).'</p>
</div>';	
				}
			}
			$type="domain";
			$domcont=$db->total("nesote_inoutse_commentcache".$cacheindex,"domain_url=? and type=? and status=?",array($domainurl,$type,0));
			$db->query();
			if($engine!=2)
			$count=($tot1+$domcont);
			else
			$count=$tot1;
			if(($tot1==0)&&($domcont==0))
			$response="";
			return $response;
		}
	}
function getcommentsnwAction()
	{
		$url=$_POST['url'];
		$align=$this->getalignment();
		if($align==2)
		{
			$direction="left";
			$table="right";
		}
		else
		{
			$direction="right";
			$table="left";
		}
		if($engine=="datasource")
		{
			$titleurl=$url;
			$cacheindex=$this->getcacheindex($engine_id);
			$titleurl=md5($titleurl);
			$type="datasource";
			$db=new NesoteDALController();
			$db->select("nesote_inoutse_commentcache".$cacheindex);
			$db->fields("*");
			$db->where("title_url=? and type=? and status=?",array($titleurl,$type,0));
			$db->order("time desc");
			$db->limit(0,3);
			$result=$db->query();
			$num=$db->numRows($result);
			if($num!=0)
			{
				$url=urlencode($url);
				$url=base64_encode($url);
				$response="";
					$response.='<ul class="old_cmntul">';
				while ($frow=$db->fetchRow($result))
				{
					$comid=$frow[0];
					$time=date("d-m-Y",$frow[5]);
					$commen=$frow[7];
					$len=strlen($commen);
					$uid=$frow[2];
					$db->select("nesote_inoutscripts_users");
					$db->fields("username");
					$db->where("id=? and status=?",array($uid,1));
					$res=$db->query();
					$fetch=$db->fetchRow($res);
					$username1=$fetch[0];
					$response.="<table class=\"commenttable\" border=\"0\"><tr><td class=\"comment\" width=\"600px\"><table><tr><td align=\"justify\">";
					if($len>200)
					$response.=$this->echocom($commen)."&nbsp; <span align=\"$direction\"><a href=\"".$this->url("user/viewcomments/$engine/$url/$comid/$engine_id")."\" onclick=\"$(this).modal({width:833, height:453}).open(); return false;\"><img title=\"".$this->getmessage(607)."\" src=\"images/readmore.ico\" border=\"0\"></a></span>";
					else
					$response.=$this->echocom($commen);
					$response.='	<li class="old_cmntsli">';
 $response.=' <div class="prf_details">
                <div class="details_cmtns">
                <a class="prfil_name">'.$this->getmessage(584).'&nbsp'.$username1.'</a>
                <span class="c_time c_span">'.$this->getmessage(585).'&nbsp;'.$time.'</span>
                <div class="right" style="float:right;">';
  $response.='	 </div>
                </div>
                <div class="clear"></div>
                <p class="prflecmnttxt">';
  if($len>200)
					$response.=$this->echocom($commen)."&nbsp; <span align=\"$direction\"><a href=\"".$this->url("user/viewcomments/$engine/$url/$comid/$engine_id")."\" onclick=\"$(this).modal({width:833, height:453}).open(); return false;\"><img title=\"".$this->getmessage(607)."\" src=\"images/readmore.ico\" border=\"0\"></a></span>";
					else
					$response.=$this->echocom($commen);
  $response.='</p>
                <div class="clear"></div>
            </div>
        </li>';
				}
				$total=$db->total("nesote_inoutse_commentcache".$cacheindex,"title_url=? and type=? and status=?",array($titleurl,$type,0));
				$db->query();
				if($total>3)
				$response.="<a class=\"sharegc initialism allcomment_open fadeandscale".$glb."_close viewmrecmnt btn-success\" href=\"#allcomment\"  onclick=\"showallcmnt('".$engine."','".$url."',$comid,'".$engine_id."')\" >".$this->getmessage(595)."</a>";
$response.=' </ul>';
			}
			else
			$response="";
			echo $response;
			exit;
		}
		else
		{
			$titleurl=$url;
			$domainurl=str_replace("http://","",$url);
			$domainurl=str_replace("https://","",$domainurl);
			$urlpos=strpos($domainurl,"/");
			if($urlpos!="")
			$domain=substr($domainurl,0,$urlpos);
			else
			$domain=$domainurl;
			$len_title=strlen($titleurl);
			if(substr($titleurl,-1)=="/")
			{
				$titleurl=substr($titleurl,0,$len_title-1);
			}
			$cacheindex=$this->getcacheindex($domain);
			if($engine=="jobsearch")
			{
				$urlpos=strpos($titleurl,"&indpubnum");
				$titleurl=substr($titleurl,0,$urlpos);
			}
			$titleurl=md5($titleurl);
			$domainurl=md5($domain);
			$type="title";
			$db=new NesoteDALController();
			$db->select("nesote_inoutse_commentcache".$cacheindex);
			$db->fields("*");
			$db->where("title_url=? and type=? and status=?",array($titleurl,$type,0));
			$db->order("time desc");
			$db->limit(0,3);
			$result=$db->query();
			$num=$db->numRows($result);
			$tot1=$db->total("nesote_inoutse_commentcache".$cacheindex,"title_url=? and type=? and status=?",array($titleurl,$type,0));
			$db->query();
			if(($num==0)&&($engine!=2))
			{
				$type="domain";
				$db->select("nesote_inoutse_commentcache".$cacheindex);
				$db->fields("*");
				$db->where("domain_url=? and type=? and status=?",array($domainurl,$type,0));
				$db->order("time desc");
				$db->limit(0,3);
				$result=$db->query();
				$total=$db->numRows($result);
			}
			if($engine=="jobsearch")
			{
				$urlpos=strpos($url,"&indpubnum");
				$url=substr($url,0,$urlpos);
			}
			$url= $titleurl;//md5($url);
			$domain=base64_encode($domain);
			$response="";
			$response.='<ul class="old_cmntul">';
			while ($frow=$db->fetchRow($result))
			{
				$comid=$frow[0];
				$time=date("d-m-Y",$frow[5]);
				$commen=$frow[7];
				$len=strlen($commen);
				$uid=$frow[2];
				$db->select("nesote_inoutscripts_users");
				$db->fields("username");
				$db->where("id=? and status=?",array($uid,1));
				$res=$db->query();
				$fetch=$db->fetchRow($res);
				$username1=$fetch[0];
    $response.='	<li class="old_cmntsli">';
               $response.=' <div class="prf_details">
            	 <div class="details_cmtns">
                <a class="prfil_name">'.$this->getmessage(584).'&nbsp'.$username1.'</a>
                <span class="c_time c_span">'.$this->getmessage(585).'&nbsp;'.$time.'</span>
                <div class="right" style="float:right;">';
                $response.='	 </div>
                </div>
                <div class="clear"></div>
                <p class="prflecmnttxt">';
    			if($len>200)
				$response.=$this->echocom($commen)."&nbsp; <span align=\"$direction\"><a href=\"".$this->url("user/viewcomments/$engine/$url/$domain/$comid")."\" onclick=\"$(this).modal({width:833, height:453}).open(); return false;\"><img title=\"".$this->getmessage(607)."\" src=\"images/readmore.ico\" border=\"0\"></a></span>";
				else
				$response.=$this->echocom($commen);
   	 $response.='</p>
                <div class="clear"></div>
            </div>
        </li>';
			}
			if(($num!=0)&&($num<3)&&($engine!=2))
			{
				$limit=(3-$num);
				$type="domain";
				$db->select("nesote_inoutse_commentcache".$cacheindex);
				$db->fields("*");
				$db->where("domain_url=? and type=? and status=?",array($domainurl,$type,0));
				$db->order("time desc");
				$db->limit(0,$limit);
				$domainresult=$db->query();
				while ($row=$db->fetchRow($domainresult))
				{
					$comid=$row[0];
					$time=date("d-m-Y",$row[5]);
					$commen=$row[7];
					$len=strlen($commen);
					$uid=$row[2];
					$db->select("nesote_inoutscripts_users");
					$db->fields("username");
					$db->where("id=? and status=?",array($uid,1));
					$res=$db->query();
					$fetch=$db->fetchRow($res);
					$username1=$fetch[0];
				 $response.='	<li class="old_cmntsli">';
               $response.=' <div class="prf_details">
                <div class="details_cmtns">
                <a class="prfil_name">'.$this->getmessage(584).'&nbsp'.$username1.'</a>
                <span class="c_time c_span">'.$this->getmessage(585).'&nbsp;'.$time.'</span>
                <div class="right" style="float:right;">';
                $response.='	 </div>
                </div>
                <div class="clear"></div>
                <p class="prflecmnttxt">';
    			if($len>200)
				$response.=$this->echocom($commen)."&nbsp; <span align=\"$direction\"><a href=\"".$this->url("user/viewcomments/$engine/$url/$domain/$comid")."\" onclick=\"$(this).modal({width:833, height:453}).open(); return false;\"><img title=\"".$this->getmessage(607)."\" src=\"images/readmore.ico\" border=\"0\"></a></span>";
				else
				$response.=$this->echocom($commen);
   	 $response.='</p>
                <div class="clear"></div>
            </div>
        </li>';
				}
			}
			$type="domain";
			$domcont=$db->total("nesote_inoutse_commentcache".$cacheindex,"domain_url=? and type=? and status=?",array($domainurl,$type,0));
			$db->query();
			if($engine!=2)
			$count=($tot1+$domcont);
			else
			$count=$tot1;
			if($count>3)
				$response.="<a class=\"sharegc initialism allcomment_open fadeandscale".$glb."_close viewmrecmnt btn-success\" href=\"#allcomment\"  onclick=\"showallcmnt('".$engine."','".$url."','".$domain."')\" >".$this->getmessage(595)."</a>";
$response.=' </ul>';
			if(($tot1==0)&&($domcont==0))
			$response="";
			echo $response;
			exit;
		}
	}
function getcommentsnw_imagAction(){
		$url=$_POST['url'];
		$align=$this->getalignment();
		if($align==2)
		{
			$direction="left";
			$table="right";
		}
		else
		{
			$direction="right";
			$table="left";
		}
		if($engine=="datasource")
		{
			$titleurl=$url;
			$cacheindex=$this->getcacheindex($engine_id);
			$titleurl=md5($titleurl);
			$type="datasource";
			$db=new NesoteDALController();
			$db->select("nesote_inoutse_commentcache".$cacheindex);
			$db->fields("*");
			$db->where("title_url=? and type=? and status=?",array($titleurl,$type,0));
			$db->order("time desc");
			$result=$db->query();
			$num=$db->numRows($result);
			if($num!=0)
			{
				$url=urlencode($url);
				$url=base64_encode($url);
				$response="";
				while ($frow=$db->fetchRow($result))
				{
					$comid=$frow[0];
					$time=date("d-m-Y",$frow[5]);
					$commen=$frow[7];
					$len=strlen($commen);
					$uid=$frow[2];
					$db->select("nesote_inoutscripts_users");
					$db->fields("username");
					$db->where("id=? and status=?",array($uid,1));
					$res=$db->query();
					$fetch=$db->fetchRow($res);
					$username1=$fetch[0];
					$response.="<table class=\"commenttable\" border=\"0\"><tr><td class=\"comment\" width=\"600px\"><table><tr><td align=\"justify\">";
					if($len>200)
					$response.=$this->echocom($commen)."&nbsp; <span align=\"$direction\"><a href=\"".$this->url("user/viewcomments/$engine/$url/$comid/$engine_id")."\" onclick=\"$(this).modal({width:833, height:453}).open(); return false;\"><img title=\"".$this->getmessage(607)."\" src=\"images/readmore.ico\" border=\"0\"></a></span>";
					else
					$response.=$this->echocom($commen);
					$response.='	<li class="old_cmntsli">';
 $response.=' <div class="prf_details">
                <div class="details_cmtns">
                <a class="prfil_name">'.$this->getmessage(584).'&nbsp'.$username1.'</a>
                <span class="c_time c_span">'.$this->getmessage(585).'&nbsp;'.$time.'</span>
                <div class="right" style="float:right;">';
  $response.='	 </div>
                </div>
                <div class="clear"></div>
                <p class="prflecmnttxt">';
  if($len>200)
					$response.=$this->echocom($commen)."&nbsp; <span align=\"$direction\"><a href=\"".$this->url("user/viewcomments/$engine/$url/$comid/$engine_id")."\" onclick=\"$(this).modal({width:833, height:453}).open(); return false;\"><img title=\"".$this->getmessage(607)."\" src=\"images/readmore.ico\" border=\"0\"></a></span>";
					else
					$response.=$this->echocom($commen);
  $response.='</p>
                <div class="clear"></div>
            </div>
        </li>';
				}
				$total=$db->total("nesote_inoutse_commentcache".$cacheindex,"title_url=? and type=? and status=?",array($titleurl,$type,0));
				$db->query();
				if($total>3)
				$response.="<a class=\"sharegc initialism allcomment_open fadeandscale".$glb."_close viewmrecmnt btn-success\" href=\"#allcomment\"  onclick=\"showallcmnt('".$engine."','".$url."',$comid,'".$engine_id."')\" >".$this->getmessage(595)."</a>";
$response.=' </ul>';
			}
			else
			$response="";
			echo $response;
			exit;
		}
		else
		{
			$titleurl=$url;
			$domainurl=str_replace("http://","",$url);
			$domainurl=str_replace("https://","",$domainurl);
			$urlpos=strpos($domainurl,"/");
			if($urlpos!="")
			$domain=substr($domainurl,0,$urlpos);
			else
			$domain=$domainurl;
			$len_title=strlen($titleurl);
			if(substr($titleurl,-1)=="/")
			{
				$titleurl=substr($titleurl,0,$len_title-1);
			}
			$cacheindex=$this->getcacheindex($domain);
			if($engine=="jobsearch")
			{
				$urlpos=strpos($titleurl,"&indpubnum");
				$titleurl=substr($titleurl,0,$urlpos);
			}
			$titleurl=md5($titleurl);
			$domainurl=md5($domain);
			$type="title";
			$db=new NesoteDALController();
			$db->select("nesote_inoutse_commentcache".$cacheindex);
			$db->fields("*");
			$db->where("title_url=? and type=? and status=?",array($titleurl,$type,0));
			$db->order("time desc");
			$result=$db->query();
			$num=$db->numRows($result);
			$tot1=$db->total("nesote_inoutse_commentcache".$cacheindex,"title_url=? and type=? and status=?",array($titleurl,$type,0));
			$db->query();
			if(($num==0)&&($engine!=2))
			{
				$type="domain";
				$db->select("nesote_inoutse_commentcache".$cacheindex);
				$db->fields("*");
				$db->where("domain_url=? and type=? and status=?",array($domainurl,$type,0));
				$db->order("time desc");
				$db->limit(0,3);
				$result=$db->query();
				$total=$db->numRows($result);
			}
			if($engine=="jobsearch")
			{
				$urlpos=strpos($url,"&indpubnum");
				$url=substr($url,0,$urlpos);
			}
			$url= $titleurl;//md5($url);
			$domain=base64_encode($domain);
			$response="";
			while ($frow=$db->fetchRow($result))
			{
				$comid=$frow[0];
				$time=date("d-m-Y",$frow[5]);
				$commen=$frow[7];
				$len=strlen($commen);
				$uid=$frow[2];
				$db->select("nesote_inoutscripts_users");
				$db->fields("username");
				$db->where("id=? and status=?",array($uid,1));
				$res=$db->query();
				$fetch=$db->fetchRow($res);
				$username1=$fetch[0];
       $response.=' <div class="fullwidth drp-cmnts img-cmnt">
 <h5 class="cmnt-name">'.$this->getmessage(584).'&nbsp'.$username1.'</h5>
<span class="cmnt-date-time">'.$this->getmessage(585).'&nbsp;'.$time.'</span>
<p class="cmnt-cnt">'.$this->echocom($commen).'</p>
</div>';
			}
			if(($num!=0)&&($engine!=2))
			{
				$type="domain";
				$db->select("nesote_inoutse_commentcache".$cacheindex);
				$db->fields("*");
				$db->where("domain_url=? and type=? and status=?",array($domainurl,$type,0));
				$db->order("time desc");
				$domainresult=$db->query();
				while ($row=$db->fetchRow($domainresult))
				{
					$comid=$row[0];
					$time=date("d-m-Y",$row[5]);
					$commen=$row[7];
					$len=strlen($commen);
					$uid=$row[2];
					$db->select("nesote_inoutscripts_users");
					$db->fields("username");
					$db->where("id=? and status=?",array($uid,1));
					$res=$db->query();
					$fetch=$db->fetchRow($res);
					$username1=$fetch[0];
$response.=' <div class="fullwidth drp-cmnts img-cmnt">
 <h5 class="cmnt-name">'.$this->getmessage(584).'&nbsp'.$username1.'</h5>
<span class="cmnt-date-time">'.$this->getmessage(585).'&nbsp;'.$time.'</span>
<p class="cmnt-cnt">'.$this->echocom($commen).'</p>
</div>';
				}
			}
			$type="domain";
			$domcont=$db->total("nesote_inoutse_commentcache".$cacheindex,"domain_url=? and type=? and status=?",array($domainurl,$type,0));
			$db->query();
			if($engine!=2)
			$count=($tot1+$domcont);
			else
			$count=$tot1;
			if(($tot1==0)&&($domcont==0))
			$response="";
			echo $response;
			exit;
		}
}
	function getcomments($url=false,$id=false,$engine="",$engine_id="")
	{
		$align=$this->getalignment();
		if($align==2)
		{
			$direction="left";
			$table="right";
		}
		else
		{
			$direction="right";
			$table="left";
		}
		if($engine=="datasource")
		{
			$titleurl=$url;
			$cacheindex=$this->getcacheindex($engine_id);
			$titleurl=md5($titleurl);
			$type="datasource";
			$db=new NesoteDALController();
			$db->select("nesote_inoutse_commentcache".$cacheindex);
			$db->fields("*");
			$db->where("title_url=? and type=? and status=?",array($titleurl,$type,0));
			$db->order("time desc");
			$db->limit(0,3);
			$result=$db->query();
			$num=$db->numRows($result);
			if($num!=0)
			{
				$url=urlencode($url);
				$url=base64_encode($url);
				$response="";
				$response.="<table border=\"0\" style=\"font-size: 12px;\"><tr><td>";
				while ($frow=$db->fetchRow($result))
				{
					$comid=$frow[0];
					$time=date("d-m-Y",$frow[5]);
					$commen=$frow[7];
					$len=strlen($commen);
					$uid=$frow[2];
					$db->select("nesote_inoutscripts_users");
					$db->fields("username");
					$db->where("id=? and status=?",array($uid,1));
					$res=$db->query();
					$fetch=$db->fetchRow($res);
					$username1=$fetch[0];
					$response.="<table class=\"commenttable\" border=\"0\"><tr><td class=\"comment\" width=\"600px\"><table><tr><td align=\"justify\">";
					if($len>200)
					$response.=$this->echocom($commen)."&nbsp; <span align=\"$direction\"><a href=\"".$this->url("user/viewcomments/$engine/$url/$comid/$engine_id")."\" onclick=\"$(this).modal({width:833, height:453}).open(); return false;\"><img title=\"".$this->getmessage(607)."\" src=\"images/readmore.ico\" border=\"0\"></a></span>";
					else
					$response.=$this->echocom($commen);
					$response.="</td></tr></table></td><td width=\"140px\"><table><tr><td align=\"$direction\" class=\"commentedby\">".$this->getmessage(584)."&nbsp;&nbsp;$username1</td></tr>
					<tr><td align=\"$direction\" class=\"commentedby\">".$this->getmessage(585)."&nbsp;$time</td></tr></table></td></tr></table>
					<table width=\"80%\" align=\"center\"><tr><td></td></tr></table>";
				}
				$total=$db->total("nesote_inoutse_commentcache".$cacheindex,"title_url=? and type=? and status=?",array($titleurl,$type,0));
				$db->query();
				if($total>3)
				$response.="</td></tr><tr><td align=\"$direction\"><a href=\"".$this->url("user/viewcomments/$engine/$url/comid/$engine_id")."\"  onclick=\"$(this).modal({width:833, height:453}).open(); return false;\">".$this->getmessage(595)."</a>";
				$response.="</td></tr></table>";
			}
			else
			$response="";
			return $response;
		}
		else
		{
			$titleurl=$url;
			$domainurl=str_replace("http://","",$url);
			$domainurl=str_replace("https://","",$domainurl);
			$urlpos=strpos($domainurl,"/");
			if($urlpos!="")
			$domain=substr($domainurl,0,$urlpos);
			else
			$domain=$domainurl;
			$len_title=strlen($titleurl);
			if(substr($titleurl,-1)=="/")
			{
				$titleurl=substr($titleurl,0,$len_title-1);
			}
			$cacheindex=$this->getcacheindex($domain);
			if($engine=="jobsearch")
			{
				$urlpos=strpos($titleurl,"&indpubnum");
				$titleurl=substr($titleurl,0,$urlpos);
			}
			$titleurl=md5($titleurl);
			$domainurl=md5($domain);
            $type="title";
			$db=new NesoteDALController();
			$db->select("nesote_inoutse_commentcache".$cacheindex);
			$db->fields("*");
			$db->where("title_url=? and type=? and status=?",array($titleurl,$type,0));
			$db->order("time desc");
			$db->limit(0,3);
			$result=$db->query();
			$num=$db->numRows($result);
			$tot1=$db->total("nesote_inoutse_commentcache".$cacheindex,"title_url=? and type=? and status=?",array($titleurl,$type,0));
			$db->query();
			if(($num==0)&&($engine!=2))
			{
				$type="domain";
				$db->select("nesote_inoutse_commentcache".$cacheindex);
				$db->fields("*");
				$db->where("domain_url=? and type=? and status=?",array($domainurl,$type,0));
				$db->order("time desc");
				$db->limit(0,3);
				$result=$db->query();
				$total=$db->numRows($result);
			}
			if($engine=="jobsearch")
			{
				$urlpos=strpos($url,"&indpubnum");
				$url=substr($url,0,$urlpos);
			}
			$url= $titleurl;//md5($url);
			$domain=base64_encode($domain);
			$response="";
			$response.="<table border=\"0\" style=\"font-size: 12px;\"><tr><td>";
			while ($frow=$db->fetchRow($result))
			{
				$comid=$frow[0];
				$time=date("d-m-Y",$frow[5]);
				$commen=$frow[7];
				$len=strlen($commen);
				$uid=$frow[2];
				$db->select("nesote_inoutscripts_users");
				$db->fields("username");
				$db->where("id=? and status=?",array($uid,1));
				$res=$db->query();
				$fetch=$db->fetchRow($res);
				$username1=$fetch[0];
				$response.="<table class=\"commenttable\" border=\"0\"><tr><td class=\"comment\" width=\"600px\"><table><tr><td align=\"justify\">";
				if($len>200)
				$response.=$this->echocom($commen)."&nbsp; <span align=\"$direction\"><a href=\"".$this->url("user/viewcomments/$engine/$url/$domain/$comid")."\" onclick=\"$(this).modal({width:833, height:453}).open(); return false;\"><img title=\"".$this->getmessage(607)."\" src=\"images/readmore.ico\" border=\"0\"></a></span>";
				else
				$response.=$this->echocom($commen);
				$response.="</td></tr></table></td><td width=\"140px\"><table><tr><td align=\"$direction\" class=\"commentedby\">".$this->getmessage(584)."&nbsp;&nbsp;$username1</td></tr>
				<tr><td align=\"$direction\" class=\"commentedby\">".$this->getmessage(585)."&nbsp;$time</td></tr></table></td></tr></table>
				<table width=\"80%\" align=\"center\"><tr><td></td></tr></table>";
			}
			if(($num!=0)&&($num<3)&&($engine!=2))
			{
				$limit=(3-$num);
				$type="domain";
				$db->select("nesote_inoutse_commentcache".$cacheindex);
				$db->fields("*");
				$db->where("domain_url=? and type=? and status=?",array($domainurl,$type,0));
				$db->order("time desc");
				$db->limit(0,$limit);
				$domainresult=$db->query();
				while ($row=$db->fetchRow($domainresult))
				{
					$comid=$row[0];
					$time=date("d-m-Y",$row[5]);
					$commen=$row[7];
					$len=strlen($commen);
					$uid=$row[2];
					$db->select("nesote_inoutscripts_users");
					$db->fields("username");
					$db->where("id=? and status=?",array($uid,1));
					$res=$db->query();
					$fetch=$db->fetchRow($res);
					$username1=$fetch[0];
					$response.="<table class=\"commenttable\" border=\"0\"><tr><td class=\"comment\" width=\"600px\"><table><tr><td align=\"justify\">";
					if($len>200)
					$response.=$this->echocom($commen)."&nbsp; <span align=\"$direction\"><a href=\"".$this->url("user/viewcomments/$engine/$url/$domain/$comid")."\" onclick=\"$(this).modal({width:833, height:453}).open(); return false;\"><img title=\"".$this->getmessage(607)."\" src=\"images/readmore.ico\" border=\"0\"></a></span>";
					else
					$response.=$this->echocom($commen);
					$response.="</td></tr></table></td><td width=\"140px\"><table><tr><td align=\"$direction\" class=\"commentedby\">".$this->getmessage(584)."&nbsp;&nbsp;$username1</td></tr>
					<tr><td align=\"$direction\" class=\"commentedby\">".$this->getmessage(585)."&nbsp;$time</td></tr></table></td></tr></table>
					<table width=\"80%\" align=\"center\"><tr><td></td></tr></table>";
				}
			}
			$type="domain";
			$domcont=$db->total("nesote_inoutse_commentcache".$cacheindex,"domain_url=? and type=? and status=?",array($domainurl,$type,0));
			$db->query();
            if($engine!=2)
			$count=($tot1+$domcont);
			else
			$count=$tot1;
			if($count>3)
			$response.="</td></tr><tr><td align=\"$direction\"><a href=\"".$this->url("user/viewcomments/$engine/$url/$domain")."\"  onclick=\"$(this).modal({width:833, height:453}).open(); return false;\">".$this->getmessage(595)."</a>";
			$response.="</td></tr></table>";
			if(($tot1==0)&&($domcont==0))
			$response="";
			return $response;
		}
	}
function getcommentsAction()
	{
		$align=$this->getalignment();
		if($align==2)
		{
			$direction="left";
			$table="right";
		}
		else
		{
			$direction="right";
			$table="left";
		}
		$url=$_POST['url'];
		if($engine=="datasource")
		{
			$titleurl=$url;
			$cacheindex=$this->getcacheindex($engine_id);
			$titleurl=md5($titleurl);
			$type="datasource";
			$db=new NesoteDALController();
			$db->select("nesote_inoutse_commentcache".$cacheindex);
			$db->fields("*");
			$db->where("title_url=? and type=? and status=?",array($titleurl,$type,0));
			$db->order("time desc");
			$db->limit(0,3);
			$result=$db->query();
			$num=$db->numRows($result);
			if($num!=0)
			{
				$url=urlencode($url);
				$url=base64_encode($url);
				$response="";
				$response.="<table border=\"0\" style=\"font-size: 12px;\"><tr><td>";
				while ($frow=$db->fetchRow($result))
				{
					$comid=$frow[0];
					$time=date("d-m-Y",$frow[5]);
					$commen=$frow[7];
					$len=strlen($commen);
					$uid=$frow[2];
					$db->select("nesote_inoutscripts_users");
					$db->fields("username");
					$db->where("id=? and status=?",array($uid,1));
					$res=$db->query();
					$fetch=$db->fetchRow($res);
					$username1=$fetch[0];
					$response.="<table class=\"commenttable\" border=\"0\"><tr><td class=\"comment\" width=\"600px\"><table><tr><td align=\"justify\">";
					if($len>200)
					$response.=$this->echocom($commen)."&nbsp; <span align=\"$direction\"><a href=\"".$this->url("user/viewcomments/$engine/$url/$comid/$engine_id")."\" onclick=\"$(this).modal({width:833, height:453}).open(); return false;\"><img title=\"".$this->getmessage(607)."\" src=\"images/readmore.ico\" border=\"0\"></a></span>";
					else
					$response.=$this->echocom($commen);
					$response.="</td></tr></table></td><td width=\"140px\"><table><tr><td align=\"$direction\" class=\"commentedby\">".$this->getmessage(584)."&nbsp;&nbsp;$username1</td></tr>
					<tr><td align=\"$direction\" class=\"commentedby\">".$this->getmessage(585)."&nbsp;$time</td></tr></table></td></tr></table>
					<table width=\"80%\" align=\"center\"><tr><td></td></tr></table>";
				}
				$total=$db->total("nesote_inoutse_commentcache".$cacheindex,"title_url=? and type=? and status=?",array($titleurl,$type,0));
				$db->query();
				if($total>3)
				$response.="</td></tr><tr><td align=\"$direction\"><a href=\"".$this->url("user/viewcomments/$engine/$url/comid/$engine_id")."\"  onclick=\"$(this).modal({width:833, height:453}).open(); return false;\">".$this->getmessage(595)."</a>";
				$response.="</td></tr></table>";
			}
			else
			$response="";
			echo $response;
			exit;
		}
		else
		{
			$titleurl=$url;
			$domainurl=str_replace("http://","",$url);
			$domainurl=str_replace("https://","",$domainurl);
			$urlpos=strpos($domainurl,"/");
			if($urlpos!="")
			$domain=substr($domainurl,0,$urlpos);
			else
			$domain=$domainurl;
			$len_title=strlen($titleurl);
			if(substr($titleurl,-1)=="/")
			{
				$titleurl=substr($titleurl,0,$len_title-1);
			}
			$cacheindex=$this->getcacheindex($domain);
			if($engine=="jobsearch")
			{
				$urlpos=strpos($titleurl,"&indpubnum");
				$titleurl=substr($titleurl,0,$urlpos);
			}
			$titleurl=md5($titleurl);
			$domainurl=md5($domain);
            $type="title";
			$db=new NesoteDALController();
			$db->select("nesote_inoutse_commentcache".$cacheindex);
			$db->fields("*");
			$db->where("title_url=? and type=? and status=?",array($titleurl,$type,0));
			$db->order("time desc");
			$db->limit(0,3);
			$result=$db->query();
			$num=$db->numRows($result);
			$tot1=$db->total("nesote_inoutse_commentcache".$cacheindex,"title_url=? and type=? and status=?",array($titleurl,$type,0));
			$db->query();
			if(($num==0)&&($engine!=2))
			{
				$type="domain";
				$db->select("nesote_inoutse_commentcache".$cacheindex);
				$db->fields("*");
				$db->where("domain_url=? and type=? and status=?",array($domainurl,$type,0));
				$db->order("time desc");
				$db->limit(0,3);
				$result=$db->query();
				$total=$db->numRows($result);
			}
			if($engine=="jobsearch")
			{
				$urlpos=strpos($url,"&indpubnum");
				$url=substr($url,0,$urlpos);
			}
			$url= $titleurl;//md5($url);
			$domain=base64_encode($domain);
			$response="";
			$response.="<table border=\"0\" style=\"font-size: 12px;\"><tr><td>";
			while ($frow=$db->fetchRow($result))
			{
				$comid=$frow[0];
				$time=date("d-m-Y",$frow[5]);
				$commen=$frow[7];
				$len=strlen($commen);
				$uid=$frow[2];
				$db->select("nesote_inoutscripts_users");
				$db->fields("username");
				$db->where("id=? and status=?",array($uid,1));
				$res=$db->query();
				$fetch=$db->fetchRow($res);
				$username1=$fetch[0];
				$response.="<table class=\"commenttable\" border=\"0\"><tr><td class=\"comment\" width=\"600px\"><table><tr><td align=\"justify\">";
				if($len>200)
				$response.=$this->echocom($commen)."&nbsp; <span align=\"$direction\"><a href=\"".$this->url("user/viewcomments/$engine/$url/$domain/$comid")."\" onclick=\"$(this).modal({width:833, height:453}).open(); return false;\"><img title=\"".$this->getmessage(607)."\" src=\"images/readmore.ico\" border=\"0\"></a></span>";
				else
				$response.=$this->echocom($commen);
				$response.="</td></tr></table></td><td width=\"140px\"><table><tr><td align=\"$direction\" class=\"commentedby\">".$this->getmessage(584)."&nbsp;&nbsp;$username1</td></tr>
				<tr><td align=\"$direction\" class=\"commentedby\">".$this->getmessage(585)."&nbsp;$time</td></tr></table></td></tr></table>
				<table width=\"80%\" align=\"center\"><tr><td></td></tr></table>";
			}
			if(($num!=0)&&($num<3)&&($engine!=2))
			{
				$limit=(3-$num);
				$type="domain";
				$db->select("nesote_inoutse_commentcache".$cacheindex);
				$db->fields("*");
				$db->where("domain_url=? and type=? and status=?",array($domainurl,$type,0));
				$db->order("time desc");
				$db->limit(0,$limit);
				$domainresult=$db->query();
				while ($row=$db->fetchRow($domainresult))
				{
					$comid=$row[0];
					$time=date("d-m-Y",$row[5]);
					$commen=$row[7];
					$len=strlen($commen);
					$uid=$row[2];
					$db->select("nesote_inoutscripts_users");
					$db->fields("username");
					$db->where("id=? and status=?",array($uid,1));
					$res=$db->query();
					$fetch=$db->fetchRow($res);
					$username1=$fetch[0];
					$response.="<table class=\"commenttable\" border=\"0\"><tr><td class=\"comment\" width=\"600px\"><table><tr><td align=\"justify\">";
					if($len>200)
					$response.=$this->echocom($commen)."&nbsp; <span align=\"$direction\"><a href=\"".$this->url("user/viewcomments/$engine/$url/$domain/$comid")."\" onclick=\"$(this).modal({width:833, height:453}).open(); return false;\"><img title=\"".$this->getmessage(607)."\" src=\"images/readmore.ico\" border=\"0\"></a></span>";
					else
					$response.=$this->echocom($commen);
					$response.="</td></tr></table></td><td width=\"140px\"><table><tr><td align=\"$direction\" class=\"commentedby\">".$this->getmessage(584)."&nbsp;&nbsp;$username1</td></tr>
					<tr><td align=\"$direction\" class=\"commentedby\">".$this->getmessage(585)."&nbsp;$time</td></tr></table></td></tr></table>
					<table width=\"80%\" align=\"center\"><tr><td></td></tr></table>";
				}
			}
			$type="domain";
			$domcont=$db->total("nesote_inoutse_commentcache".$cacheindex,"domain_url=? and type=? and status=?",array($domainurl,$type,0));
			$db->query();
            if($engine!=2)
			$count=($tot1+$domcont);
			else
			$count=$tot1;
			if($count>3)
			$response.="</td></tr><tr><td align=\"$direction\"><a href=\"".$this->url("user/viewcomments/$engine/$url/$domain")."\"  onclick=\"$(this).modal({width:833, height:453}).open(); return false;\">".$this->getmessage(595)."</a>";
			$response.="</td></tr></table>";
			if(($tot1==0)&&($domcont==0))
			$response="".$tot1;
			echo $response;
			exit;
		}
		exit;
	}
	function postcommentAction()
	{
		if($this->uservalidation1())
		{
			$type=$_POST['urltype'];
			$comment=trim($_POST['comment']);
			$url=$_POST['url'];
			$url=trim($url);
			//$newurl=$url;
			$id=$_POST['id'];
			$time=time();
			$engine=$_POST['engine'];
			$engine_id=$_POST['engine_id'];
			$titleurl=$url;
			$len_title=strlen($titleurl);
			if(substr($titleurl,-1)=="/")
			{
				$titleurl=substr($titleurl,0,$len_title-1);
			}
			$username=$_COOKIE['io_username'];
			$password=$_COOKIE['io_password'];
			$db=new NesoteDALController();
			$db->select("nesote_inoutscripts_users");
			$db->fields("id");
			$db->where("username=? and password=? and status=?",array($username,$password,1));
			$res=$db->query();
			$num=$db->numRows($res);
			if($num==1)
			{
				$fetch=$db->fetchRow($res);
				$uid=$fetch[0];
				if($type=="datasource")
				{
					$url=trim(stripslashes($_POST['url']));
					$titleurl=$url;
					$cacheindex=$this->getcacheindex($engine_id);
					$titleurl=md5($titleurl);
    			    $db->insert("nesote_inoutse_commentcache".$cacheindex);
            		$db->fields("type,uid,title_url,domain_url,time,status,comment");
            		$db->values(array($type,$uid,$titleurl,$titleurl,$time,'0',$comment));
            		$db->query();
					$engine="datasource";
					$result=$this->getcommentsnw($url,$id,$engine,$engine_id);
					$count=$this->getcmntcount($url,$engine,$engine_id);
				}
				else
				{
					$domainurl=str_replace("http://","",$url);
					$domainurl=str_replace("https://","",$domainurl);
					$urlpos=strpos($domainurl,"/");
					if($urlpos!="")
					$domain=substr($domainurl,0,$urlpos);
					else
					$domain=$domainurl;
					$cacheindex=$this->getcacheindex($domain);
					if($engine=="jobsearch")
					{
						$urlpos=strpos($titleurl,"&indpubnum");
						$titleurl=substr($titleurl,0,$urlpos);
					}
					$titleurl=md5($titleurl);
					$domainurl=md5($domain);
					 $db->insert("nesote_inoutse_commentcache".$cacheindex);
            		$db->fields("type,uid,title_url,domain_url,time,status,comment");
            		$db->values(array($type,$uid,$titleurl,$domainurl,$time,'0',$comment));
            		$db->query();
if($engine=="image"){
$result=$this->getcommentsnw_images($url,$id,$engine);
}else{
$result=$this->getcommentsnw($url,$id,$engine);
}
					$count=$this->getcmntcount($url,$engine);
				}
				echo $response=$id."[sp:lt]".$count."[sp:lt]".$result;
			}
			else
			echo "514";
			exit;
		}
		else
		{
			echo "514";
			exit;
		}
	}
	function echocom($comment)
	{
		$len=strlen($comment);
		if($len>200)
		{
			if(preg_match('/[^(\x20-\x7F)]*/', $comment))
			{
				$lang="";
			}
			else
			{
				$lang="ASCII";
			}
			if($lang=="ASCII")
			$comment=substr($comment,0,230);
			else
			$comment=substr($comment,0,480);
			$pos=strrpos($comment," ");
			if($pos!="")
			$comment=substr($comment,0,$pos)." .......";
			else
			$comment=$comment." .......";
		}
		else
		$comment=$comment;
		$length=strlen($comment);
		if($lang=="ASCII")
		{
			if($length>=110)
			{
				$p=strpos($comment," ");
				if(($p=="")||($p>110))
				{
					$fir=substr($comment,0,110);
					$sec=substr($comment,111,$length);
					$pn=strpos($sec," ");
					if(($pn=="")||($pn>110))
					{
						$sec1=substr($sec,0,110);
						$sec2=substr($sec,111);
						$sec= $sec1." ".$sec2;
					}
					$comment=$fir." ".$sec;
				}
			}
		}
		else
		{
			if($length>=300)
			{
				$p=strpos($comment," ");
				if(($p=="")||($p>300))
				{
					$fir=substr($comment,0,300);
					$sec=substr($comment,301,$length);
					$pn=strpos($sec," ");
					if(($pn=="")||($pn>300))
					{
						$sec1=substr($sec,0,300);
						$sec2=substr($sec,301);
						$sec= $sec1." ".$sec2;
					}
					$comment=$fir." ".$sec;
				}
			}
		}
		$comment= htmlentities($comment,ENT_QUOTES ,"utf-8");
		return $comment;
	}
	function getcmntcount($url,$engine="",$engine_id="")
	{
	$url=trim($url);
		if($engine=="datasource")
		{
			$titleurl=$url;
			$cacheindex=$this->getcacheindex($engine_id);
			$titleurl=md5($titleurl);
			$type="datasource";
			$db=new NesoteDALController();
			$total=$db->total("nesote_inoutse_commentcache".$cacheindex,"title_url=? and type=? and status=?",array($titleurl,$type,0));
			$db->query();
			return $total;
		}
		$titleurl=$url;
		$len_title=strlen($titleurl);
		if(substr($titleurl,-1)=="/")
		{
			$titleurl=substr($titleurl,0,$len_title-1);
		}
		$domainurl=str_replace("http://","",$url);
		$domainurl=str_replace("https://","",$domainurl);
		$urlpos=strpos($domainurl,"/");
		if($urlpos!="")
		$domain=substr($domainurl,0,$urlpos);
		else
		$domain=$domainurl;
		$cacheindex=$this->getcacheindex($domain);
		if($engine=="jobsearch")
		{
			$urlpos=strpos($titleurl,"&indpubnum");
			$titleurl=substr($titleurl,0,$urlpos);
		}
		$titleurl=md5($titleurl);
		$domainurl=md5($domain);
		$type="title";
		$db=new NesoteDALController();
		$tcont=$db->total("nesote_inoutse_commentcache".$cacheindex,"title_url=? and type=? and status=?",array($titleurl,$type,0));
		$db->query();
		$total=$tcont;
		if($engine!='2')
		{
			$type="domain";
			$dcont=$db->total("nesote_inoutse_commentcache".$cacheindex,"domain_url=? and type=? and status=?",array($domainurl,$type,0));
			$db->query();		
			$total+=$dcont;			
		}
		return $total;
	}
	function getstar($title_url,$engine_id,$engine_name="")
	{
		if($engine_name=="jobsearch")
		{
			$urlpos=strpos($title_url,"&indpubnum");
			$title_url=substr($title_url,0,$urlpos);
		}
		$title_url=base64_encode(htmlentities($title_url));
		$username=$_COOKIE['io_username'];
		$password=$_COOKIE['io_password'];
		$db=new NesoteDALController();
		$db->select("nesote_inoutscripts_users");
		$db->fields("id");
		$db->where("username=? and password=?",array($username,$password));
		$res=$db->query();
		$fetch=$db->fetchRow($res);
		$uid=$fetch[0];
		$cacheindex=$this->getcacheindex($uid);
		$check=$db->total("nesote_inoutse_starredcache$cacheindex","uid=? and engine_id=? and url=?",array($uid,$engine_id,$title_url));
		$db->query();
		if($check==0)
		{
$img=0;
		}
		else
		{
$img=1;
		}
		return $img;
	}
	function uservalidation()
	{
		$username=$_COOKIE['io_username'];
		$password=$_COOKIE['io_password'];
		$this->loadLibrary('Settings');
		$settings=new Settings('nesote_inoutse_settings');
		$settings->loadValues();
		$member_status=$settings->getValue("member_status");
		if($member_status==1)
		{
			$db=new NesoteDALController();
			$count=$db->total("nesote_inoutscripts_users","username=? and password=? and status=?",array($username,$password,1));
			$db->query();
			if($count==1)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		else
		{
			return false;
		}
	}
	function uservalidation1()
	{
		$username=$_COOKIE['io_username'];
		$password=$_COOKIE['io_password'];
		$db=new NesoteDALController();
		$count=$db->total("nesote_inoutscripts_users","username=? and password=? and status=?",array($username,$password,1));
		$db->query();
		if($count==1)
		{
			return true;
		}
		else
		{
			return false;
		}
	}
	function encode($content)
	{
		$content=base64_encode($content);
		return $content;
	}
	function encode_ae($content)
	{
		$content=htmlentities($content);
		$content=base64_encode($content);
		return $content;
	}
	function urlencode($content)
	{
		$content=md5($content);
		return $content;
	}
	function getdomain($content)
	{
		$domainurl=str_replace("http://","",$content);
		$domainurl=str_replace("https://","",$domainurl);
		$urlpos=strpos($domainurl,"/");
		$domain=substr($domainurl,0,$urlpos);
		$domain=base64_encode($domain);
		return $domain;
	}
	function getstarimage($src)
	{
		$pos=strrpos($src,"/");
		echo $domain=substr($src,$pos);exit;
	}
	function getmixcacheindex($newarray,$basevalue)
	{
		ksort($newarray);
		foreach ($newarray as $key => $val)
		{
			if($val!="")
			$url.=$val."/";
		}
		$url=trim($url);
		$md5_url=md5($url);
		$md5_url=str_replace("a","",$md5_url);
		$md5_url=str_replace("b","",$md5_url);
		$md5_url=str_replace("c","",$md5_url);
		$md5_url=str_replace("d","",$md5_url);
		$md5_url=str_replace("e","",$md5_url);
		$md5_url=str_replace("f","",$md5_url);
		$digits=substr($md5_url,-6);
		$modlusnumber=$digits % $basevalue;
		$modlusnumber=$modlusnumber+1;
		$numbers[$modlusnumber]++;
		return $modlusnumber;
	}
	function getsourcestatus($status,$type=0)
	{
		if($status=="faroo")
		{
			return " • Found on Faroo";
		}
		if($status=="0000")
		{
			return "";
		}
		else
		{
			$this->loadLibrary("settings");
			$settings=new settings("nesote_inoutse_settings");
			$settings->loadValues();
			$source_status=$settings->getValue("source_status");
			if($source_status==1)
			{
				if($type!=1)
				{
					$source=str_split($status);
					if($source[0]=="1")
					{
						$google=$this->getmessage(421).",";
					}
					else
					{
						$google="";
					}
					if($source[1]=="1")
					{
						$yahoo=$this->getmessage(422).",";
					}
					else
					{
						$yahoo="";
					}
					if($source[2]=="1")
					{
						$bing=$this->getmessage(423).",";
					}
					else
					{
						$bing="";
					}
					if($source[3]=="1")
					{
						$spider=$this->getmessage(424).",";
					}
					else
					{
						$spider="";
					}
					$message=array("google"=>$google,"yahoo"=>$yahoo,"bing"=>$bing,"spider"=>$spider);
					$sourcestatatus=$this->getmessagegrammer(402,$message);
					$p=strrpos($sourcestatatus,",");
					$part1=substr($sourcestatatus,0,$p);
					$part2=substr($sourcestatatus,$p+1);
					$sourcestatatus=$part1.$part2;
					if($type!=3)
					{
						$ter= "•";
						$resp=$ter." ".$sourcestatatus;
					}
					else
					$resp=$sourcestatatus;
					return $resp;
				}
				else
				{
					$source=str_split($status);
					if($source[0]=="1")
					{
						$youtube="Youtube,";
					}
					else
					{
						$youtube="";
					}
					if($source[1]=="1")
					{
						$bing="Bing,";
					}
					else
					{
						$bing="";
					}
					$message=array("youtube"=>$youtube,"bing"=>$bing);
					$sourcestatatus=$this->getmessagegrammer(403,$message);
					$p=strrpos($sourcestatatus,",");
					$sourcestatatus=substr($sourcestatatus,0,$p);
					$resp=$sourcestatatus;
					return $resp;
				}
			}
			else
			{
				return "";
			}
		}
	}
	function remotefsize($url) {
		$sch = parse_url($url, PHP_URL_SCHEME);
		if (($sch != "http") && ($sch != "https") && ($sch != "ftp") && ($sch != "ftps")) {
			return false;
		}
		if (($sch == "http") || ($sch == "https")) {
			$headers = get_headers($url, 1);
			if ((!array_key_exists("Content-Length", $headers))) { return false; }
			return $headers["Content-Length"];
		}
		if (($sch == "ftp") || ($sch == "ftps")) {
			$server = parse_url($url, PHP_URL_HOST);
			$port = parse_url($url, PHP_URL_PORT);
			$path = parse_url($url, PHP_URL_PATH);
			$user = parse_url($url, PHP_URL_USER);
			$pass = parse_url($url, PHP_URL_PASS);
			if ((!$server) || (!$path)) { return false; }
			if (!$port) { $port = 21; }
			if (!$user) { $user = "anonymous"; }
			if (!$pass) { $pass = "phpos@"; }
			switch ($sch) {
				case "ftp":
					$ftpid = ftp_connect($server, $port);
					break;
				case "ftps":
					$ftpid = ftp_ssl_connect($server, $port);
					break;
			}
			if (!$ftpid) { return false; }
			$login = ftp_login($ftpid, $user, $pass);
			if (!$login) { return false; }
			$ftpsize = ftp_size($ftpid, $path);
			ftp_close($ftpid);
			if ($ftpsize == -1) { return false; }
			return $ftpsize;
		}
	}
function get_imagecontent($engineid=false,$searchtype=false,$keyword=false,$page=1)
	{ 
		 include_once('classes.inc');
		$this->loadLibrary('Settings');
		$settings=new Settings('nesote_inoutse_settings');
		$settings->loadValues();
		$db= new NesoteDALController();
		if(isset($_COOKIE['region']))
		{
			$region=$_COOKIE['region'];
			if($_COOKIE['region']==0)
			$region=63;
		}
		elseif(!isset($_COOKIE['region']))
		{
			$region=$settings->getValue("default_country");
			if(($region=="")||($region==0))
			$region=63;
		}
		$newarray["keyword"]=$keyword;
		$newarray["engineid"]=$engineid;
		$newarray["region"]=$region;
		$resultcount=5;
		$cacheindex=$this->getmixcacheindex($newarray,27);
		$cacheindex1=$this->getmixcacheindex($newarray,100);
		$cacheindex2=$this->getmixcacheindex($newarray,137);
		ksort($newarray);
		foreach ($newarray as $key => $val)
		{
			$keyterm.=$val."/";
		}
		$keyterm=md5($keyterm);
		$crawlst= ($page-1)*$resultcount;
		$crawlst1 = $crawlst+$resultcount-1;
		$db->select("nesote_inoutse_mixcache".$cacheindex);
		$db->fields("id,time,startnumber,totalcount");
		$db->where("deletestatus=0 and startnumber<=? and endnumber>=? and keyterm=?",array($crawlst,$crawlst1,$keyterm));
		$result1=$db->query();
		$row1=$db->fetchRow($result1);
		if($row1[0]!="")
		{
			$cachestore = new cachestorage();
			$cache = $cachestore->getmixcache($cacheindex, $row1[0]);
			$cacheresult=json_decode($cache);
			$resultset=[];
			foreach($cacheresult->item as $mydata)
			{
			 $resultset[1][]=$mydata->type;
			}
			foreach($cacheresult->item as $mydata)
			{
			 $resultset[2][]=$mydata->width;
			}
			foreach($cacheresult->item as $mydata)
			{
			 $resultset[3][]=$mydata->imagelocation;
			}
			foreach($cacheresult->item as $mydata)
			{
			 $resultset[4][]=$mydata->filesize;
			}
			foreach($cacheresult->item as $mydata)
			{
			 $resultset[5][]=$mydata->thumburl;
			}
			foreach($cacheresult->item as $mydata)
			{
			 $resultset[6][]=$mydata->title;
			}
			foreach($cacheresult->item as $mydata)
			{
			 $resultset[7][]=$mydata->visibleurl;
			}
			foreach($cacheresult->item as $mydata)
			{
			 $resultset[8][]=$mydata->height;
			}
			foreach($cacheresult->item as $mydata)
			{
			 $resultset[9][]=$mydata->url;
			}
			$j=0;
				for($i=0;$i<=4;$i++)
				{
					if($resultset[2][$i]=="")
					break;
					$finalresult[$j][1]=$resultset[9][$i];
					$finalresult[$j][2]=$resultset[5][$i];
					$j++;
				}
				return $finalresult;
		}
		else
		{
			return "";
		}
	}
	function getmedianame($media_id)
	{
		$lang_id="";
		$this->loadLibrary("settings");
		$set=new settings("nesote_inoutse_settings");
		$set->loadValues();
		$defaultlang_id=$set->getValue("default_language");
		$db=new NesoteDALController();
		if(isset ($_COOKIE['language']))
		{
			$lang_id=$_COOKIE['language'];
			$db->select("nesote_inoutse_languages");
			$db->fields("id");
			$db->where("lang_code=?", array($lang_id));
			$result=$db->query();
			$row=$db->fetchRow($result);
			$lang_id=$row[0];
		}
		else
		{
			$lang_id=$defaultlang_id;
		}
		if($lang_id!="")
		{
			$tot=$db->total("nesote_inoutse_itune_medianames","langid=? and mediaid=?",array($lang_id,$media_id));
			if($tot!=0)
			{
				$db->select("nesote_inoutse_itune_medianames");
				$db->fields("medianame");
				$db->where("langid=? and mediaid=?", array($lang_id,$media_id));
				$result=$db->query();
				$row=$db->fetchRow($result);
				return $row[0];
			}
			else
			{
				$tot=$db->total("nesote_inoutse_itune_medianames","langid=? and mediaid=?",array($defaultlang_id,$media_id));
				if($tot!=0)
				{
					$db->select("nesote_inoutse_itune_medianames");
					$db->fields("medianame");
					$db->where("langid=? and mediaid=?", array($defaultlang_id,$media_id));
					$result=$db->query();
					$row=$db->fetchRow($result);
					return $row[0];
				}
				else
				{
					$db->select("nesote_inoutse_itune_medianames");
					$db->fields("medianame");
					$db->where("langid=? and mediaid=?", array(1,$media_id));
					$result=$db->query();
					$row=$db->fetchRow($result);
					return $row[0];
				}
			}
		}
		else
		{
			$db=new NesoteDALController();
			$db->select("nesote_inoutse_itune_medianames");
			$db->fields("medianame");
			$db->where("langid=? and mediaid=?", array(1,$media_id));
			$result=$db->query();
			$row=$db->fetchRow($result);
			return $row[0];
		}
	}
function getmixurlcontents($engineid, $searchtype, $page, $keyword = "", $mixstatus = 0, $nextpage = "", $advancedarray = "")
{
    include_once('classes.inc');
    $next_token = $nextpage;
    $this->loadLibrary('Settings');
    $settings = new Settings('nesote_inoutse_settings');
    $settings->loadValues();
    $db = new NesoteDALController();
    if (isset($_COOKIE['region']))
    {
        $region = $_COOKIE['region'];
        if ($_COOKIE['region'] == 0) $region = 63;
    }
    elseif (!isset($_COOKIE['region']))
    {
        $region = $settings->getValue("default_country");
        if (($region == "") || ($region == 0)) $region = 63;
    }
    $realkeyword = $keyword;
    if (($searchtype == "web") || ($searchtype == "news"))
    {
        $newarray["keyword"] = $keyword;
        $newarray["engineid"] = $engineid;
        $newarray["region"] = $region;
        $resultcount = $settings->getValue("result_count");
        $fetchcount = $settings->getValue("result_fetchcount");
    }
    if (($searchtype == "images") || ($searchtype == "videos"))
    {
        $newarray["keyword"] = $keyword;
        $newarray["engineid"] = $engineid;
        $newarray["region"] = $region;
        $resultcount = $settings->getValue("image_result_count");
        $fetchcount = $settings->getValue("image_result_fetchcount");
    }
    else if ($searchtype == "special")
    {
        $newarray["keyword"] = $keyword;
        $newarray["engineid"] = $engineid;
        $newarray["region"] = $region;
        $resultcount = $settings->getValue("result_count");
        $fetchcount = $settings->getValue("result_fetchcount");
        $db = new NesoteDALController();
        $db->select("nesote_inoutse_engines");
        $db->fields("special_status,special_keyword,support_keyword,cacheable");
        $db->where("id=?", $engineid);
        $result = $db->query();
        $row = $db->fetchRow($result);
        $newarray["special_status"] = $row[0];
        $newarray["special_keyword"] = $row[1];
        if (($row[2] != "") && ($row[2] != " "))
        {
            $newarray["support_keyword"] = $row[2];
        }
    }
    $mixing_normal_sources = $settings->getValue("rest_api_search");
    $mixing_normal_status = $settings->getValue("mixing_normal_status");
    $p = str_split($mixing_normal_sources, 1);
    if (($p[0] == "G") && ($mixing_normal_status == 0))
    {
        $googleonly = 1;
    }
    else
    {
        $googleonly = 0;
    }
    $db->select("nesote_inoutse_engines");
    $db->fields("cacheable");
    $db->where("id=?", $engineid);
    $result = $db->query();
    $row = $db->fetchRow($result);
    $cacheable_mixing = $row[0];
    $cacheindex = $this->getmixcacheindex($newarray, 27);
    $cacheindex1 = $this->getmixcacheindex($newarray, 100);
    $cacheindex2 = $this->getmixcacheindex($newarray, 137);
    ksort($newarray);
    foreach ($newarray as $key => $val)
    {
        $keyterm .= $val . "/";
    }
    $keyterm = md5($keyterm);
    if (($searchtype == "images") || ($searchtype == "videos"))
    {
        $perpagesize = 25;
    }
    else
    {
        $perpagesize = 10;
    }
    $crawlst = ($page - 1) * $perpagesize;
    $crawlst1 = $crawlst + $perpagesize - 1;
    $db->select("nesote_inoutse_mixcache" . $cacheindex);
    $db->fields("id,time");
    $db->where("deletestatus=0 and startnumber<=? and endnumber>=? and keyterm=?", array(
        $crawlst,
        $crawlst,
        $keyterm
    ));
    $result = $db->query();
    $row = $db->fetchRow($result);
    $db->select("nesote_inoutse_mixcache" . $cacheindex);
    $db->fields("id,time,startnumber,totalcount");
    $db->where("deletestatus=0 and startnumber<=? and endnumber>=? and keyterm=?", array(
        $crawlst,
        $crawlst1,
        $keyterm
    ));
    $result1 = $db->query();
    $row1 = $db->fetchRow($result1); 
    if (($row[0] != "") && ($row1[0] != ""))
    {
        $cachestore = new cachestorage();
        $csv = $cachestore->getsource($cacheindex, $row1[0]);
        $length = strlen($csv);
        $csv = substr_replace($csv, "", -1, $length);
        $i = 0;
        $csv = (explode(",", $csv));
        $h = count($csv);
        $p = 0; 
        $xmlappend .= "{\"source\":[";
        for ($i = 0;$i < $h;$i++)
        {
            $csv1[$i] = (explode(".", $csv[$i]));
            $statusarray[$i] = $csv1[$i][0];
            if (($i >= $crawlst) && ($i <= $crawlst1))
            {
                if ($i == $crawlst1)
                {
                    $xmlappend .= "{\"sourcestatus\":\"" . $statusarray[$i] . "\"}";
                }
                else
                {
                    $xmlappend .= "{\"sourcestatus\":\"" . $statusarray[$i] . "\"},";
                }
            }
        }
        $xmlappend .= "]}";
        $cachestore = new cachestorage();
        $xmldataprev = $cachestore->getmixcache($cacheindex, $row1[0]);
        $db->select("nesote_inoutse_mixcache" . $cacheindex);
        $db->fields("*");
        $db->where("deletestatus=0 and keyterm=?", array(
            $keyterm
        ));
        $db->order("time desc");
        $db->limit(0, 1);
        $res2 = $db->query();
        $r = $db->fetchRow($res2);
        if ($r[0] != "")
        {
            $s1 = $r[7];
            $s2 = $r[8];
            $s3 = $r[9];
            $s4 = $r[10];
            $start = $r[3];
            $end = $r[4];
        }
        if ($h > $end + 1)
        {
            $h = $end + 1;
        }
        if (($s1 == 0) && ($s2 == 0) && ($s3 == 0) && ($s4 == 0))
        {
            $allstatus = 0;
        }
        else
        {
            $allstatus = 1;
        }
        return "{\"start\":\"" . $row1[2] . "\",\"totalcount\":\"" . $row1[3] . "\",\"backupcount\":\"" . $h . "\",\"allstatus\":\"" . $allstatus . "\",\"onlygooglestatus\":\"" . $googleonly . "\"}" . '&@&' . $xmldataprev . '&@&' . $xmlappend;
        exit(0);
    }
    else if ($row[0] != "")
    {
        $db->select("nesote_inoutse_mixcache" . $cacheindex);
        $db->fields("*");
        $db->where("deletestatus=0 and startnumber<=? and endnumber>=? and keyterm=?", array(
            $crawlst,
            $crawlst,
            $keyterm
        ));
        $result2 = $db->query();
        $row2 = $db->fetchRow($result2);
        $time = getdate($row2[5]);
        $year = $time['year'];
        $month = $time['mon'];
        $date = $time['mday'];
        $s1 = $row2[7];
        $s2 = $row2[8];
        $s3 = $row2[9];
        $s4 = $row2[10];
        $lastid = $row2[0];
        $crawlindex = $row2[2];
        $start = $row2[3];
        $end = $row2[4];
        $lasttime = $row2[5];
        $totalcount = $row2[12];
        if (($start > $end) && ($start == 0))
        {
            return "";
        }
        $cachestore = new cachestorage();
        $xmldataprev = $cachestore->getmixcache($cacheindex, $row2[0]);
        $startprev = $row2[3];
        $cachestore = new cachestorage();
        $csv = $cachestore->getsource($cacheindex, $row2[0]);
        $length = strlen($csv);
        $csv = substr_replace($csv, "", -1, $length);
        $i = 0;
        $csv = (explode(",", $csv));
        $h = count($csv);
        for ($i = 0;$i < $h;$i++)
        {
            $csv1[$i] = (explode(".", $csv[$i]));
        }
        if ($h > $end + 1)
        {
            $h = $end + 1;
        }
    }
    else
    {
        $db->select("nesote_inoutse_mixcache" . $cacheindex);
        $db->fields("*");
        $db->where("deletestatus=0 and keyterm=?", array(
            $keyterm
        ));
        $db->order("time desc");
        $db->limit(0, 1);
        $result2 = $db->query();
        $row2 = $db->fetchRow($result2);
        if ($row2[0] != "")
        {
            $time = getdate($row2[5]);
            $year = $time['year'];
            $month = $time['mon'];
            $date = $time['mday'];
            $s1 = $row2[7];
            $s2 = $row2[8];
            $s3 = $row2[9];
            $s4 = $row2[10];
            $lastid = $row2[0];
            $newest = 0;
            $crawlindex = $row2[2];
            $start = $row2[3];
            $end = $row2[4];
            $lasttime = $row2[5];
            $totalcount = $row2[12];
            if (($start > $end) && ($start == 0))
            {
                return "";
            }
            $cachestore = new cachestorage();
            $csv = $cachestore->getsource($cacheindex, $row2[0]);
            $length = strlen($csv);
            $csv = substr_replace($csv, "", -1, $length);
            $i = 0;
            $csv = (explode(",", $csv));
            $h = count($csv);
            for ($i = 0;$i < $h;$i++)
            {
                $csv1[$i] = (explode(".", $csv[$i]));
            }
            if ($h > $end + 1)
            {
                $h = $end + 1;
            }
        }
        else
        {
            $s1 = 1;
            $s2 = 1;
            $s3 = 1;
            $s4 = 1;
            $crawlindex = 0;
            $start = 0;
            $lastid = 0;
            $newest = 1;
        }
    }
    $db->select("nesote_inoutse_mixcache" . $cacheindex);
    $db->fields("*");
    $db->where("deletestatus=0 and keyterm=?", array(
        $keyterm
    ));
    $db->order("time desc");
    $db->limit(0, 2);
    $result3 = $db->query();
    while ($row3 = $result3->fetchRow())
    {
        $time = getdate($row3[5]);
        $prevcrawlindex = $row3[2];
        $year = $time['year'];
        $month = $time['mon'];
        $date = $time['mday'];
        $cachestore = new cachestorage();
        $xmldataprev = $cachestore->getmixcache($cacheindex, $row3[0]);
        $startprev = $row3[3];
    }
    ++$crawlindex;
    if (($s1 == 0) && ($s2 == 0) && ($s3 == 0) && ($s4 == 0))
    {
        if ($newest == 1)
        return "";
        else
        {
            if (($crawlst == 0) && ($h < 1))
            {
                return "";
            }
            else
            {
                if ($crawlst1 >= $h)
                {
                    $erd = $h - 1;
                }
                else $erd = $crawlst1;
                $xmlappend .= "{\"source\":[";
                for ($i = $crawlst;$i <= $erd;$i++)
                {
                    $statusarray[$i] = $csv1[$i][0];
                    if ($i == $erd)
                    {
                        $xmlappend .= "{\"sourcestatus\":\"" . $statusarray[$i] . "\"}";
                    }
                    else
                    {
                        $xmlappend .= "{\"sourcestatus\":\"" . $statusarray[$i] . "\"},";
                    }
                }
                $xmlappend .= "]}";
                return "{\"start\":\"" . $startprev . "\",\"totalcount\":\"" . $totalcount . "\",\"backupcount\":\"" . $h . "\",\"allstatus\":\"" . $allstatus . "\",\"onlygooglestatus\":\"" . $googleonly . "\"}" . '&@&' . $xmldataprev . '&@&' . $xmlappend;
            }
        }
    }
    require_once ("OAuth.php");
    $mixing_normal_sources = $settings->getValue("rest_api_search");
    $mixing_normal_status = $settings->getValue("mixing_normal_status");
    $p = str_split($mixing_normal_sources, 1);
    $mixing_video_sources = $settings->getValue("video_api_search");
    $mixing_video_status = $settings->getValue("mixing_video_status");
    $q = str_split($mixing_video_sources, 1);
    $cc_secret = $settings->getValue("yahoo_boss_secret_key");
    $cc_key = $settings->getValue("yahoo_boss_api_key");
    $webtype = $settings->getValue("web_api_status");
    $source1 = 0;
    $source2 = 0;
    $source3 = 0;
    $source4 = 0;
    if ($searchtype != "videos")
    {
        if ($mixing_normal_status == 1)
        {
            $i = 0;
            $k = 0;
            if (($p[0] == "G") && ($s1 == 1))
            {
                $urlarray[$i] = $this->geturl($engineid, $searchtype, $keyword, $crawlindex, "G");
                if ($urlarray[$i] == "")
                {
                    $urlarray[$i] = "N";
                    $i++;
                }
                else
                {
                    $fullurl1 = $urlarray[$i];
                    $fullurl = explode(" ||| ", $fullurl1);
                    $source1 = count($fullurl);
                    for ($c = 0;$c < $source1;$c++)
                    {
                        $url[$k] = $fullurl[$c];
                        $k++;
                    }
                    $i++;
                }
            }
            else
            {
                $urlarray[$i] = "N";
                $i++;
            }
            if (($p[1] == "Y") && ($s2 == 1))
            {
                $urlarray[$i] = $this->geturl($engineid, $searchtype, $keyword, $crawlindex, "Y");
                if ($urlarray[$i] == "")
                {
                    $urlarray[$i] = "N";
                    $i++;
                }
                else
                {
                    $fullurl1 = $urlarray[$i];
                    $fullurl = explode(" ||| ", $fullurl1);
                    $source2 = count($fullurl);
                    for ($c = 0;$c < $source2;$c++)
                    {
                        $url[$k] = $fullurl[$c];
                        $k++;
                    }
                    $i++;
                }
            }
            else
            {
                $urlarray[$i] = "N";
                $i++;
            }
            if (($p[2] == "B") && ($s3 == 1))
            {
                if ($searchtype == 'images')
                {
                    $urlarray[$i] = $this->geturl($engineid, $searchtype, $keyword, $page, "B");
                }
                else
                {
                    $urlarray[$i] = $this->geturl($engineid, $searchtype, $keyword, $crawlindex, "B");
                }
                if ($urlarray[$i] == "")
                {
                    $urlarray[$i] = "N";
                    $i++;
                }
                else
                {
                    $fullurl1 = $urlarray[$i];
                    $fullurl = explode(" ||| ", $fullurl1);
                    $source3 = count($fullurl);
                    for ($c = 0;$c < $source3;$c++)
                    {
                        $url[$k] = $fullurl[$c];
                        $k++;
                    }
                    $i++;
                }
            }
            else
            {
                $urlarray[$i] = "N";
                $i++;
            }
            if (($p[3] == "S") && ($s4 == 1))
            {
                $urlarray[$i] = $this->geturl($engineid, $searchtype, $keyword, $crawlindex, "S");
                if ($urlarray[$i] == "")
                {
                    $urlarray[$i] = "N";
                    $i++;
                }
                else
                {
                    $fullurl1 = $urlarray[$i];
                    $fullurl = explode(" ||| ", $fullurl1);
                    $source4 = count($fullurl);
                    for ($c = 0;$c < $source4;$c++)
                    {
                        $url[$k] = $fullurl[$c];
                        $k++;
                    }
                    $i++;
                }
            }
            else
            {
                $urlarray[$i] = "N";
                $i++;
            }
        }
        else if ($mixing_normal_status == 0)
        {
            $i = 0;
            $k = 0;
            if ($mixing_normal_sources == "GNNN")
            {
                if ($cacheable_mixing == 0) $urlarray[0] = $this->geturl($engineid, $searchtype, $keyword, $page, "G");
                else $urlarray[0] = $this->geturl($engineid, $searchtype, $keyword, $crawlindex, "G");
                $urlarray[1] = "N";
                $urlarray[2] = "N";
                $urlarray[3] = "N";
                if ($urlarray[0] == "")
                {
                    $urlarray[0] = "N";
                }
                else
                {
                    $fullurl1 = $urlarray[0];
                    $fullurl = explode(" ||| ", $fullurl1);
                    $source1 = count($fullurl);
                    for ($c = 0;$c < $source1;$c++)
                    {
                        $url[$k] = $fullurl[$c];
                        $k++;
                    }
                }
            }
            else if ($mixing_normal_sources == "NYNN")
            {
                $urlarray[0] = "N";
                if ($cacheable_mixing == 0) $urlarray[1] = $this->geturl($engineid, $searchtype, $keyword, $page, "Y");
                else $urlarray[1] = $this->geturl($engineid, $searchtype, $keyword, $crawlindex, "Y");
                $urlarray[2] = "N";
                $urlarray[3] = "N";
                if ($urlarray[1] == "")
                {
                    $urlarray[1] = "N";
                }
                else
                {
                    $fullurl1 = $urlarray[1];
                    $fullurl = explode(" ||| ", $fullurl1);
                    $source2 = count($fullurl);
                    for ($c = 0;$c < $source2;$c++)
                    {
                        $url[$k] = $fullurl[$c];
                        $k++;
                    }
                }
            }
            else if ($mixing_normal_sources == "NNBN")
            {
                $urlarray[0] = "N";
                $urlarray[1] = "N";
                if ($cacheable_mixing == 0) $urlarray[2] = $this->geturl($engineid, $searchtype, $keyword, $page, "B");
                else
                $urlarray[2] = $this->geturl($engineid, $searchtype, $keyword, $page, "B");
                $urlarray[3] = "N";
                if ($urlarray[2] == "")
                {
                    $urlarray[2] = "N";
                }
                else
                {
                    $fullurl1 = $urlarray[2];
                    $fullurl = explode(" ||| ", $fullurl1);
                    $source3 = count($fullurl);
                    for ($c = 0;$c < $source3;$c++)
                    {
                        $url[$k] = $fullurl[$c];
                        $k++;
                    }
                }
            }
            else if ($mixing_normal_sources == "NNNS")
            {
                $urlarray[0] = "N";
                $urlarray[1] = "N";
                $urlarray[2] = "N";
                if ($cacheable_mixing == 0) $urlarray[3] = $this->geturl($engineid, $searchtype, $keyword, $page, "S");
                else $urlarray[3] = $this->geturl($engineid, $searchtype, $keyword, $crawlindex, "S");
                if ($urlarray[3] == "")
                {
                    $urlarray[3] = "N";
                }
                else
                {
                    $fullurl1 = $urlarray[3];
                    $fullurl = explode(" ||| ", $fullurl1);
                    $source4 = count($fullurl);
                    for ($c = 0;$c < $source4;$c++)
                    {
                        $url[$k] = $fullurl[$c];
                        $k++;
                    }
                }
            }
        }
    }
    else if ($searchtype == "videos")
    {
        if ($mixing_video_status == 1)
        {
            $i = 0;
            $k = 0;
            if (($q[0] == "T") && ($s1 == 1))
            {
                $urlarray[$i] = $this->geturl($engineid, $searchtype, $keyword, $crawlindex, "T", $next_token);
                if ($urlarray[$i] == "")
                {
                    $urlarray[$i] = "N";
                    $i++;
                }
                else
                {
                    $fullurl1 = $urlarray[$i];
                    $fullurl = explode(" ||| ", $fullurl1);
                    $source1 = count($fullurl);
                    $source5 = count($fullurl);
                    for ($c = 0;$c < $source1;$c++)
                    {
                        $url[$k] = $fullurl[$c];
                        $k++;
                    }
                    $i++;
                }
            }
            else
            {
                $urlarray[$i] = "N";
                $i++;
            }
            if (($q[1] == "B") && ($s2 == 1))
            {
                $urlarray[$i] = $this->geturl($engineid, $searchtype, $keyword, $crawlindex, "B");
                if ($urlarray[$i] == "")
                {
                    $urlarray[$i] = "N";
                    $i++;
                }
                else
                {
                    $fullurl1 = $urlarray[$i];
                    $fullurl = explode(" ||| ", $fullurl1);
                    $source2 = count($fullurl);
                    $source6 = count($fullurl);
                    for ($c = 0;$c < $source2;$c++)
                    {
                        $url[$k] = $fullurl[$c];
                        $k++;
                    }
                    $i++;
                }
            }
            else
            {
                $urlarray[$i] = "N";
                $i++;
            }
        }
        else if ($mixing_video_status == 0)
        {
            $i = 0;
            $k = 0;
            if ($mixing_video_sources == "TN")
            {
                if ($cacheable_mixing == 0) $urlarray[0] = $this->geturl($engineid, $searchtype, $keyword, $page, "T", $next_token);
                else $urlarray[0] = $this->geturl($engineid, $searchtype, $keyword, $crawlindex, "T", $next_token);
                $urlarray[1] = "N";
                if ($urlarray[0] == "")
                {
                    $urlarray[0] = "N";
                }
                else
                {
                    $fullurl1 = $urlarray[0];
                    $fullurl = explode(" ||| ", $fullurl1);
                    $source1 = count($fullurl);
                    $source5 = count($fullurl);
                    for ($c = 0;$c < $source1;$c++)
                    {
                        $url[$k] = $fullurl[$c];
                        $k++;
                    }
                }
            }
            else if ($mixing_video_sources == "NB")
            {
                $urlarray[0] = "N";
                if ($cacheable_mixing == 0) $urlarray[1] = $this->geturl($engineid, $searchtype, $keyword, $page, "B");
                else $urlarray[1] = $this->geturl($engineid, $searchtype, $keyword, $crawlindex, "B");
                if ($urlarray[1] == "")
                {
                    $urlarray[1] = "N";
                }
                else
                {
                    $fullurl1 = $urlarray[1];
                    $fullurl = explode(" ||| ", $fullurl1);
                    $source2 = count($fullurl);
                    $source6 = count($fullurl);
                    for ($c = 0;$c < $source2;$c++)
                    {
                        $url[$k] = $fullurl[$c];
                        $k++;
                    }
                }
            }
        }
    }
    $num = count($urlarray);
    $num1 = count($url);
    $process_status = 0;
    $this->loadLibrary('Settings');
    $settings = new Settings('nesote_inoutse_settings');
    $settings->loadValues();
    $accountKey = $settings->getValue("bing_api_key");
    if (function_exists('curl_init'))
    {
        $version = phpversion();
        $version = substr($version, 0, 1);
        if (($version != " ") && ($version != ""))
        {
            if ($version < 5) $process_status = 1;
            else if (curl_multi_init()) 
            {
                $process_status = 0; //parallel processing
            }
            else
            {
                $process_status = 1; //serial processing
            }
        }
        else
        {
            if (curl_multi_init()) //if($mhcheck==curl_multi_init())
            {
                $process_status = 0; //parallel processing
            }
            else
            {
                $process_status = 1; //serial processing
            }
        }
    }
    else
    {
        $process_status = 1; //serial processing
    }
    $process_status = 1;
    if ($process_status == 1)
    {
        $j = 0;
        $cl = 0;
        for ($i = 0;$i < $num;$i++) // outer loop for the url array if all sources are selected it will be 4
        {
            $row[1] = $urlarray[$i];
            if ($row[1] == "N")
            {
                $xmlarray[$j] = "null";
            }
            else
            {
                if ($i == 0) $source = $source1; //google url count // for videos it is youtube
                else if ($i == 1) $source = $source2; //yahoo url count // for videos it is bing
                else if ($i == 2) $source = $source3; //bing url count
                else if ($i == 3) $source = $source4; //spider url count
                if ($source != 1)
                {
                    $end = $cl + $source;
                    for ($c = $cl;$c < $end;$c++)
                    {
                        $xmlarray1 = [];
                        $row[1] = $url[$c];
                        if ($i == 1 && $source6 == "") //$i=1 means yahoo ,first time it is zero
                        {
                            $consumer = new OAuthConsumer($cc_key, $cc_secret);
                            $request = OAuthRequest::from_consumer_and_token($consumer, NULL, "GET", $row[1], NULL);
                            $request->sign_request(new OAuthSignatureMethod_HMAC_SHA1() , $consumer, NULL);
                            {
                                if (function_exists('curl_init'))
                                {
                                    $headers = array(
                                        $request->to_header()
                                    );
                                    $ch = curl_init();
                                    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
                                    curl_setopt($ch, CURLOPT_HEADER, 1);
                                    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
                                    curl_setopt($ch, CURLOPT_URL, $row[1]);
                                    $xmlarray1 = curl_exec($ch);
                                    curl_close($ch);
                                }
                            }
                        }
                        elseif ($i == 2) 
                        {
                            if (function_exists('curl_init'))
                            {
                                $ch = curl_init($row[1]);
                                curl_setopt($ch, CURLOPT_HTTPGET, 1);
                                curl_setopt($ch, CURLOPT_HTTPHEADER, array(
                                    'Ocp-Apim-Subscription-Key:' . $accountKey,
                                    'Content-Type: application/json'
                                ));
                                curl_setopt($ch, CURLOPT_TIMEOUT, 30);
                                curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
                                $xmlarray1 = curl_exec($ch);
                                curl_close($ch);
                            }
                        }
                        elseif ($i == 1 && $source6 != "") 
                        {
                            if (function_exists('curl_init'))
                            {
                                $process = curl_init($row[1]);
                                curl_setopt($ch, CURLOPT_HTTPGET, 1);
                                curl_setopt($ch, CURLOPT_HTTPHEADER, array(
                                    'Ocp-Apim-Subscription-Key:' . $accountKey,
                                    'Content-Type: application/json'
                                ));
                                curl_setopt($ch, CURLOPT_TIMEOUT, 30);
                                curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
                                $xmlarray1 = curl_exec($process);
                                curl_close($ch);
                            }
                        }
                        else if (function_exists('curl_init'))
                        {
                            $ch = curl_init();
                            $ch = curl_init();
                            curl_setopt($ch, CURLOPT_URL, $row[1]);
                            curl_setopt($ch, CURLOPT_HEADER, 0);
                            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
                            $xmlarray1 = curl_exec($ch);
                            curl_close($ch);
                        }
                        elseif ($fp = fopen($row[1], "r"))
                        {
                            while (!feof($fp))
                            {
                                $xmlarray1 .= fgetc($fp);
                            }
                            fclose($fp);
                        }
                        $xmlarray[$j] .= $xmlarray1 . " ||| ";
                        $cl++;
                    }
                }
                else
                {
                    if ($i == 1 && $source6 == "") //$i==1 means yahoo
                    {
                        $consumer = new OAuthConsumer($cc_key, $cc_secret);
                        $request = OAuthRequest::from_consumer_and_token($consumer, NULL, "GET", $row[1], NULL);
                        $request->sign_request(new OAuthSignatureMethod_HMAC_SHA1() , $consumer, NULL);
                        {
                            if (function_exists('curl_init'))
                            {
                                $headers = array(
                                    $request->to_header()
                                );
                                $ch = curl_init();
                                curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
                                curl_setopt($ch, CURLOPT_HEADER, 1);
                                curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
                                curl_setopt($ch, CURLOPT_URL, $row[1]);
                                $xmlarray[$j] = curl_exec($ch);
                                curl_close($ch);
                            }
                        }
                    }
                    elseif ($i == 2) //$i=1 means bing ,first time it is zero
                    {
                        if (function_exists('curl_init'))
                        {
                            $ch = curl_init($row[1]);
                            curl_setopt($ch, CURLOPT_HTTPGET, 1);
                            curl_setopt($ch, CURLOPT_HTTPHEADER, array(
                                'Ocp-Apim-Subscription-Key:' . $accountKey,
                                'Content-Type: application/json'
                            ));
                            curl_setopt($ch, CURLOPT_TIMEOUT, 30);
                            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
                            $xmlarray[$j] = curl_exec($ch);
                            curl_close($ch);
                        }
                    }
                    elseif ($i == 1 && $source6 != "") //$i=1 means bing videos ,first time it is zero
                    {
                        if (function_exists('curl_init'))
                        {
                            $process = curl_init($row[1]);
                            curl_setopt($ch, CURLOPT_HTTPGET, 1);
                            curl_setopt($process, CURLOPT_HTTPHEADER, array(
                                'Ocp-Apim-Subscription-Key:' . $accountKey,
                                'Content-Type: application/json'
                            ));
                            curl_setopt($process, CURLOPT_TIMEOUT, 30);
                            curl_setopt($process, CURLOPT_RETURNTRANSFER, true);
                            $xmlarray[$j] = curl_exec($process);
                            curl_close($process);
                        }
                    }
                    elseif (function_exists('curl_init'))
                    {
                        $ch = curl_init();
                        curl_setopt($ch, CURLOPT_URL, $row[1]);
                        curl_setopt($ch, CURLOPT_HEADER, 0);
                        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
                        $xmlarray[$j] = curl_exec($ch);
                        curl_close($ch);
                    }
                    elseif ($fp = fopen($row[1], "r"))
                    {
                        while (!feof($fp))
                        {
                            $xmlarray[$j] .= fgetc($fp);
                        }
                        fclose($fp);
                    }
                    $cl++;
                }
            }
            $j++;
        }
    }
    else
    {
        $j = 0;
        $cl = 0;
        $mh = curl_multi_init();
        $handles = array();
        for ($i = 0;$i < $num1;$i++)
        {
            if (($i >= $source1) && ($i < $source1 + $source2 && $source6 == "")) // pointing to yahoo only
            { 
                $consumer = new OAuthConsumer($cc_key, $cc_secret);
                $request = OAuthRequest::from_consumer_and_token($consumer, NULL, "GET", $url[$i], NULL);
                $request->sign_request(new OAuthSignatureMethod_HMAC_SHA1() , $consumer, NULL);
                $headers = array(
                    $request->to_header()
                );
            }
            $ch = curl_init();
            if (($i >= $source1) && ($i < $source1 + $source2 && $source6 == "")) // pointing to yahoo only
            { 
                curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
                curl_setopt($ch, CURLOPT_HEADER, 1);
            }
            if (($i >= $source1 + $source2) && ($i < $source1 + $source2 + $source3 && $source6 == "")) 
            { 
             curl_setopt($ch, CURLOPT_HTTPGET, 1);
                curl_setopt($ch, CURLOPT_HTTPHEADER, array(
                    'Ocp-Apim-Subscription-Key:' . $accountKey,
                    'Content-Type: application/json'
                ));
                curl_setopt($ch, CURLOPT_TIMEOUT, 30);
                curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
            }
            if (($i >= $source5) && ($i < $source5 + $source6 && $source6 != "")) // pointing to bing only.
            {
                curl_setopt($ch, CURLOPT_HTTPGET, 1);
                curl_setopt($ch, CURLOPT_HTTPHEADER, array(
                    'Ocp-Apim-Subscription-Key:' . $accountKey,
                    'Content-Type: application/json'
                ));
                curl_setopt($ch, CURLOPT_TIMEOUT, 30);
                curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
            }
            else
            { 
                curl_setopt($ch, CURLOPT_HEADER, 0);
            }
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
            curl_setopt($ch, CURLOPT_URL, $url[$i]);
            curl_setopt($ch, CURLOPT_TIMEOUT, 30);
            curl_multi_add_handle($mh, $ch);
            $handles[] = $ch;
        }
        $running = null;
        do
        {
            curl_multi_exec($mh, $running);
            usleep(100000);
        }
        while ($running > 0);
        for ($i = 0;$i < $num1;$i++)
        {
            $xmls[$i] = curl_multi_getcontent($handles[$i]);
            curl_multi_remove_handle($mh, $handles[$i]);
        }
        curl_multi_close($mh);
        $k = 0;
        for ($i = 0;$i < $num;$i++)
        {
            if ($urlarray[$i] == "N")
            {
                $xmlarray[$i] = "null";
            }
            else
            {
                if ($i == 0) $source = $source1;
                else if ($i == 1) $source = $source2;
                else if ($i == 2) $source = $source3;
                else if ($i == 3) $source = $source4;
                if ($source != 1)
                {
                    $end = $cl + $source;
                    for ($c = $cl;$c < $end;$c++)
                    {
                        $xmlarray[$i] .= $xmls[$k] . " ||| ";
                        $k++;
                        $cl++;
                    }
                }
                else
                {
                    $xmlarray[$i] = $xmls[$k];
                    $k++;
                    $cl++;
                }
            }
        }
    }
    if (($searchtype == "web") || ($searchtype == "special") || ($searchtype == "news") || ($searchtype == "images"))
    {
        if (($searchtype == "web") || ($searchtype == "special"))
        {
            if ($xmlarray[0] != "null")
            {
                $googlexml = explode(" ||| ", $xmlarray[0]);
                $j = 0;
                for ($c = 0;$c < $source1;$c++)
                {
                    $googlewebresult = $this->perform_google_search($googlexml[$c]);
                    $total[$c] = $this->perform_google_search2($googlexml[$c]);
                    $num = count($googlewebresult);
                    for ($i = 0;$i < $num;$i++)
                    {
                        $resultset1[$j][1] = strip_tags($googlewebresult[$i]['content']);
                        $resultset1[$j][2] = strip_tags($googlewebresult[$i]['visibleUrl']);
                        $resultset1[$j][3] = strip_tags($googlewebresult[$i]['title']);
                        $resultset1[$j][4] = $googlewebresult[$i]['url'];
                        $j++;
                    }
                }
                $cnt = $settings->getValue("result_fetchcount");
                $loopmode = $settings->getValue("google_loopmode");
                if ($loopmode == 0)
                {
                    $max = $settings->getValue("google_result_maxcount");
                    if ($max < $cnt) $cnt = $max;
                }
            }
            $total1 = $total[0];
            for ($i = 1;$i <= 3;$i++)
            {
                $xmlarray[$i] = str_replace("\r\n", "", $xmlarray[$i]);
                $xmlarray[$i] = str_replace("\n", "", $xmlarray[$i]);
                $xmlarray[$i] = str_replace("\r", "", $xmlarray[$i]);
                $xmlarray[$i] = str_replace("\t", "", $xmlarray[$i]);
            }
            if ($xmlarray[1] != "null")
            {
                preg_match_all("/<result>(.+?)<url>(.+?)<\/url><dispurl type=\"(.+?)\">(.+?)<\/dispurl><title type=\"default\">(.+?)<\/title>(.+?)<\/result>/i", $xmlarray[1], $yahooresult);
                if ($webtype == 1) preg_match("/<web start=\"(.+?)\" count=\"(.+?)\" totalresults=\"(.+?)\">/i", $xmlarray[1], $totalhits2);
                else preg_match("/<limitedweb start=\"(.+?)\" count=\"(.+?)\" totalresults=\"(.+?)\">/i", $xmlarray[1], $totalhits2);
                $total2 = $totalhits2[3];
                $yoffset = $totalhits2[1];
                $cnt = $settings->getValue("result_fetchcount"); //10
                $loopmode = $settings->getValue("yahoo_loopmode");
                if ($loopmode == 0)
                {
                    $max = $settings->getValue("yahoo_result_maxcount"); //50
                    if ($max < $cnt) $cnt = $max;
                }
                $j = 0;
                for ($k = 0;$k <= $cnt - 1;$k++)
                {
                    if ($yahooresult[4][$k] != "")
                    {
                        $var = str_replace("<![CDATA[", "", $yahooresult[6][$k]);
                        $var = str_replace("]]>", "", $var);
                        $resultset2[$j][1] = strip_tags(html_entity_decode($var)); //content
                        $var = str_replace("<![CDATA[", "", $yahooresult[4][$k]);
                        $var = str_replace("]]>", "", $var);
                        $resultset2[$j][2] = strip_tags(html_entity_decode($var));
                        $var = str_replace("<![CDATA[", "", $yahooresult[5][$k]);
                        $var = str_replace("]]>", "", $var); //displayurl
                        $resultset2[$j][3] = strip_tags(html_entity_decode($var));
                        $var = str_replace("<![CDATA[", "", $yahooresult[2][$k]);
                        $var = str_replace("]]>", "", $var); //title
                        $resultset2[$j][4] = html_entity_decode($var); //url
                        preg_match("/(.+?)<abstract type=\"(.+?)\">(.+?)<\/abstract>/i", $yahooresult[6][$k], $abc); //discription
                        if (count($abc) != 0)
                        {
                            $var = str_replace("<![CDATA[", "", $abc[3]);
                            $var = str_replace("]]>", "", $var);
                            $resultset2[$j][1] = strip_tags(html_entity_decode($var));
                        }
                        else
                        {
                            $var = str_replace("<![CDATA[", "", $yahooresult[6][$k]);
                            $var = str_replace("]]>", "", $var);
                            $resultset2[$j][1] = strip_tags(html_entity_decode($var));
                        }
                        $j++;
                    }
                }
            }
            if ($xmlarray[2] != "null") // bing xml pregmatch
            {
                $this->getrelatedkeyword($keyword, $xmlarray[2], 2);
                $response = json_decode($xmlarray[2], true);
                $someObject = '';
                $bing_count = ($response['webPages']['totalEstimatedMatches']);
                foreach (($response['webPages']) as $value)
                {
                    $sec_array = array();
                    $sec_array = $response['webPages']['value'];
                }
                $response_bng = array();
                $atc_res = array();
                foreach ($sec_array as $result)
                {
                    for ($i = 0;$i < sizeof($sec_array);$i++)
                    {
                        $bingresult[] = array(
                            'snippet' => $sec_array[$i]['snippet'],
                            'displayUrl' => $sec_array[$i]['displayUrl'],
                            'title' => $sec_array[$i]['name'],
                            'url' => $sec_array[$i]['url']
                        );
                    }
                }
                if (count($bingresult) > 0)
                {
                    $xx = $bing_count;
                    $count_bing = 1000;
                    $total3 = $count_bing;
                }
                else
                {
                    $total3 = 0;
                }
                $boffset = $page * 10;
                $cnt = $settings->getValue("result_fetchcount");
                $loopmode = $settings->getValue("bing_loopmode");
                if ($loopmode == 0)
                {
                    $max = $settings->getValue("bing_result_maxcount");
                    if ($max < $cnt) $cnt = $max;
                }
                $j = 0;
                for ($k = 0;$k <= $cnt - 1;$k++)
                {
                    if (($bingresult[$k]['url']) != "")
                    {
                        $resultset3[$j][1] = strip_tags($bingresult[$k]['snippet']);
                        $resultset3[$j][2] = strip_tags($bingresult[$k]['displayUrl']);
                        $resultset3[$j][3] = strip_tags($bingresult[$k]['title']);
                        $resultset3[$j][4] = html_entity_decode($bingresult[$k]['url']);
                        $j++;
                    }
                }
            }
            if ($xmlarray[3] != "null")
            {
                $this->getrelatedkeyword($keyword, $xmlarray[3], 3);
                preg_match_all("/<result><title>(.+?)<\/title><description>(.+?)<\/description><url>(.+?)<\/url><keywords>(.+?)<\/keywords><\/result>/i", $xmlarray[3], $spiderresult);
                preg_match("/<totalcount>(.+?)<\/totalcount>/i", $xmlarray[3], $totalhits4);
                $total4 = $totalhits4[1];
                $cnt = $settings->getValue("result_fetchcount");
                $loopmode = $settings->getValue("spider_loopmode");
                if ($loopmode == 0)
                {
                    $max = $settings->getValue("spider_result_maxcount");
                    if ($max < $cnt) $cnt = $max;
                }
                $j = 0;
                for ($k = 0;$k <= $cnt - 1;$k++)
                {
                    if ($spiderresult[4][$k] != "")
                    {
                        $var = str_replace("<![CDATA[", "", $spiderresult[2][$k]);
                        $var = str_replace("]]>", "", $var);
                        $resultset4[$j][1] = strip_tags($var);
                        $var = str_replace("<![CDATA[", "", $spiderresult[3][$k]);
                        $var = str_replace("]]>", "", $var);
                        $var = str_replace("http://", "", $var);
                        $resultset4[$j][2] = strip_tags($var);
                        $var = str_replace("<![CDATA[", "", $spiderresult[1][$k]);
                        $var = str_replace("]]>", "", $var);
                        $resultset4[$j][3] = strip_tags($var);
                        $var = str_replace("<![CDATA[", "", $spiderresult[3][$k]);
                        $var = str_replace("]]>", "", $var);
                        $resultset4[$j][4] = html_entity_decode($var);
                        $j++;
                    }
                }
            }
        }
        if ($searchtype == "news")
        {
            if ($xmlarray[0] != "null")
            {
                $googlexml = explode(" ||| ", $xmlarray[0]);
                $j = 0;
                for ($c = 0;$c < $source1;$c++)
                {
                    $googlewebresult = $this->perform_google_search($googlexml[$c]);
                    $total[$c] = $this->perform_google_search2($googlexml[$c]);
                    $num = count($googlewebresult);
                    for ($i = 0;$i < $num;$i++)
                    {
                        $resultset1[$j][1] = strip_tags($googlewebresult[$i]['content']);
                        $resultset1[$j][4] = urldecode($googlewebresult[$i]['url']);
                        $resultset1[$j][2] = strip_tags(urldecode(str_replace("http%3A%2F%2F", "", $googlewebresult[$i]['url'])));
                        $resultset1[$j][3] = strip_tags($googlewebresult[$i]['title']);
                        $j++;
                    }
                }
                $cnt = $settings->getValue("news_result_fetchcount");
                $loopmode = $settings->getValue("google_loopmode");
                if ($loopmode == 0)
                {
                    $max = $settings->getValue("google_result_maxcount");
                    if ($max < $cnt) $cnt = $max;
                }
            }
            $total1 = $total[0];
            for ($i = 1;$i <= 3;$i++)
            {
                $xmlarray[$i] = str_replace("\r\n", "", $xmlarray[$i]);
                $xmlarray[$i] = str_replace("\n", "", $xmlarray[$i]);
                $xmlarray[$i] = str_replace("\r", "", $xmlarray[$i]);
                $xmlarray[$i] = str_replace("\t", "", $xmlarray[$i]);
            }
            if ($xmlarray[1] != "null")
            {
                preg_match_all("/<result><abstract>(.+?)<\/abstract>(.+?)<title>(.+?)<\/title>(.+?)<date>(.+?)<\/date><source>(.+?)<\/source><sourceurl>(.+?)<\/sourceurl><url>(.+?)<\/url><\/result>/i", $xmlarray[1], $yahooresult);
                preg_match("/<news start=\"(.+?)\" count=\"(.+?)\" totalresults=\"(.+?)\">/i", $xmlarray[1], $totalhits2);
                $total2 = $totalhits2[3];
                $yoffset = $totalhits2[1];
                $cnt = $settings->getValue("news_result_fetchcount");
                $loopmode = $settings->getValue("yahoo_loopmode");
                if ($loopmode == 0)
                {
                    $max = $settings->getValue("yahoo_news_result_maxcount");
                    if ($max < $cnt) $cnt = $max;
                }
                $j = 0;
                for ($k = 0;$k <= $cnt - 1;$k++)
                {
                    if ($yahooresult[4][$k] != "")
                    {
                        $var = str_replace("<![CDATA[", "", $yahooresult[1][$k]);
                        $var = str_replace("]]>", "", $var);
                        $resultset2[$j][1] = strip_tags(html_entity_decode(substr($var, 7)));
                        $var = str_replace("<![CDATA[", "", $yahooresult[8][$k]);
                        $var = str_replace("]]>", "", $var);
                        $resultset2[$j][2] = strip_tags(html_entity_decode(substr($var, 7)));
                        $var = str_replace("<![CDATA[", "", $yahooresult[3][$k]);
                        $var = str_replace("]]>", "", $var);
                        $resultset2[$j][3] = strip_tags(html_entity_decode($var));
                        $var = str_replace("<![CDATA[", "", $yahooresult[8][$k]);
                        $var = str_replace("]]>", "", $var);
                        $resultset2[$j][4] = html_entity_decode($var);
                        $j++;
                    }
                }
            }
            if ($xmlarray[2] != "null") // bing news results
            {
                $this->getrelatedkeyword($keyword, $xmlarray[2], 2);
                $bingresult = json_decode($xmlarray[2], true);
                $count_bing = ($bingresult['totalEstimatedMatches']);
                if ($count_bing > 1)
                {
                    $xx = $count_bing;
                    $count_bing = 1000;
                    $total3 = $count_bing;
                }
                else
                {
                    $total3 = 0;
                }
                $sec_array = array();
                $sec_array = $bingresult['value'];
                foreach ($sec_array as $i)
                {
                    $bing_fresult[] = array(
                        'titile' => $i['name'],
                        'description' => $i['description'],
                        'url' => $i['url'],
                        'contentUrl' => $i['url']
                    );
                }
                $boffset = $page * 10;
                $cnt = $settings->getValue("news_result_fetchcount");
                $loopmode = $settings->getValue("bing_loopmode");
                if ($loopmode == 0)
                {
                    $max = $settings->getValue("bing_news_result_maxcount");
                    if ($max < $cnt) $cnt = $max;
                }
                $j = 0;
                for ($k = 0;$k <= $cnt - 1;$k++)
                {
                    if (($bing_fresult[$k]['contentUrl']) != "")
                    {
                        $resultset3[$j][1] = html_entity_decode($bing_fresult[$k]['description']);
                        $resultset3[$j][2] = html_entity_decode($bing_fresult[$k]['contentUrl']);
                        $resultset3[$j][3] = strip_tags($bing_fresult[$k]['titile']);
                        $resultset3[$j][4] = html_entity_decode($bing_fresult[$k]['contentUrl']);
                        $j++;
                    }
                }
            }
            if ($xmlarray[3] != "null")
            {
                $this->getrelatedkeyword($keyword, $xmlarray[3], 3);
                preg_match_all("/<result><title>(.+?)<\/title><description>(.+?)<\/description><url>(.+?)<\/url><keywords>(.+?)<\/keywords><pubDate>(.+?)<\/pubDate><\/result>/i", $xmlarray[3], $spiderresult);
                preg_match("/<totalcount>(.+?)<\/totalcount>/i", $xmlarray[3], $totalhits4);
                $total4 = $totalhits4[1];
                $cnt = $settings->getValue("news_result_fetchcount");
                $loopmode = $settings->getValue("spider_loopmode");
                if ($loopmode == 0)
                {
                    $max = $settings->getValue("spider_news_result_maxcount");
                    if ($max < $cnt) $cnt = $max;
                }
                $j = 0;
                for ($k = 0;$k <= $cnt - 1;$k++)
                {
                    if ($spiderresult[3][$k] != "")
                    {
                        $var = str_replace("<![CDATA[", "", $spiderresult[2][$k]);
                        $var = str_replace("]]>", "", $var);
                        $resultset4[$j][1] = strip_tags($var); //description
                        $var = str_replace("<![CDATA[", "", $spiderresult[3][$k]);
                        $var = str_replace("]]>", "", $var);
                        $var = str_replace("http://", "", $var);
                        $resultset4[$j][2] = strip_tags($var); //displayurl
                        $var = str_replace("<![CDATA[", "", $spiderresult[1][$k]);
                        $var = str_replace("]]>", "", $var);
                        $resultset4[$j][3] = strip_tags($var);
                        $var = str_replace("<![CDATA[", "", $spiderresult[3][$k]);
                        $var = str_replace("]]>", "", $var);
                        $resultset4[$j][4] = html_entity_decode($var);
                        $j++;
                    }
                }
            }
        }
        if ($searchtype == "images")
        {
            if ($xmlarray[0] != "null")
            {
                $googlexml = explode(" ||| ", $xmlarray[0]);
                $j = 0;
                for ($c = 0;$c < $source1;$c++)
                {
                    $googlewebresult = $this->googlecustomimage_search($googlexml[$c]);
                    $total[$c] = $this->googlecustomimage_search2($googlexml[$c]);
                    $num = count($googlewebresult);
                    for ($i = 0;$i < $num;$i++)
                    {
                        $resultset1[$j][1] = urldecode($googlewebresult[$i]['url']);
                        $resultset1[$j][2] = $googlewebresult[$i]['width'];
                        $resultset1[$j][3] = strip_tags(html_entity_decode($googlewebresult[$i]['contextlink']));
                        $resultset1[$j][9] = "0"; //$this->remotefsize($res);
                        $resultset1[$j][5] = $googlewebresult[$i]['thumbnailLink'];
                        $resultset1[$j][6] = strip_tags(html_entity_decode($googlewebresult[$i]['title']));
                        $resultset1[$j][4] = strip_tags(($googlewebresult[$i]['link']));
                        $resultset1[$j][8] = $googlewebresult[$i]['height'];
                        $resultset1[$j][7] = urldecode($googlewebresult[$i]['url']);
                        $j++;
                    }
                }
                $cnt = $settings->getValue("image_result_fetchcount");
                $loopmode = $settings->getValue("google_loopmode");
                if ($loopmode == 0)
                {
                    $max = $settings->getValue("google_result_maxcount");
                    if ($max < $cnt) $cnt = $max;
                }
            }
            $total1 = $total[0];
            for ($i = 1;$i <= 3;$i++)
            {
                $xmlarray[$i] = str_replace("\r\n", "", $xmlarray[$i]);
                $xmlarray[$i] = str_replace("\n", "", $xmlarray[$i]);
                $xmlarray[$i] = str_replace("\r", "", $xmlarray[$i]);
                $xmlarray[$i] = str_replace("\t", "", $xmlarray[$i]);
            }
            if ($xmlarray[1] != "null")
            {
                preg_match_all("/<result><clickurl>(.+?)<\/clickurl><size>(.+?)<\/size><format>(.+?)<\/format><height>(.+?)<\/height>(.+?)<refererurl>(.+?)<\/refererurl><title>(.+?)<\/title><url>(.+?)<\/url><width>(.+?)<\/width><thumbnailheight>(.+?)<\/thumbnailheight><thumbnailurl>(.+?)<\/thumbnailurl><thumbnailwidth>(.+?)<\/thumbnailwidth><\/result>/i", $xmlarray[1], $yahooresult);
                preg_match("/<images start=\"(.+?)\" count=\"(.+?)\" totalresults=\"(.+?)\">/i", $xmlarray[1], $totalhits2);
                $total2 = $totalhits2[3];
                $yoffset = $totalhits2[1];
                $cnt = $settings->getValue("image_result_fetchcount");
                $loopmode = $settings->getValue("yahoo_loopmode");
                if ($loopmode == 0)
                {
                    $max = $settings->getValue("yahoo_image_result_maxcount");
                    if ($max < $cnt) $cnt = $max;
                }
                $j = 0;
                for ($k = 0;$k <= $cnt - 1;$k++)
                {
                    if ($yahooresult[2][$k] != "")
                    {
                        $resultset2[$j][1] = $yahooresult[3][$k]; //type
                        $resultset2[$j][2] = $yahooresult[9][$k]; //width
                        $resultset2[$j][3] = strip_tags(html_entity_decode($yahooresult[6][$k])); //refererurl
                        $resultset2[$j][9] = $yahooresult[2][$k]; //size
                        $resultset2[$j][5] = html_entity_decode($yahooresult[11][$k]); //thumbnailurl
                        $resultset2[$j][6] = strip_tags(html_entity_decode($yahooresult[7][$k])); //title
                        $temp = explode("/", substr($yahooresult[8][$k], 7)); //domainurl
                        $resultset2[$j][7] = strip_tags(html_entity_decode($temp[0]));
                        $resultset2[$j][8] = $yahooresult[4][$k]; //height
                        $resultset2[$j][4] = $yahooresult[8][$k]; //url
                        $j++;
                    }
                }
            }
            if ($xmlarray[2] != "null")
            {
                $this->getrelatedkeyword($keyword, $xmlarray[2], 2);
                $response_img = json_decode($xmlarray[2], true);
                $response_bng = array();
                $atc_res = array();
                $allresponseresults = array();
                for ($i = 0;$i < 10;$i++)
                {
                    $allresponseresults[] = $response_img['value'][$i];
                }
                foreach ($allresponseresults as $i)
                {
                    $bingresult[] = array(
                        'title' => $i['name'],
                        'sourceUrl' => $i['hostPageUrl'],
                        'thumbnailUrl' => $i['thumbnailUrl'],
                        'DisplaylUrl' => $i['hostPageDisplayUrl'],
                        'width' => $i['width'],
                        'height' => $i['height'],
                        'filesize' => $i['contentSize'],
                        'filetype' => $i['encodingFormat'],
                        'originalUrl' => $i['contentUrl']
                    );
                }
                $bing_count = $response_img['totalEstimatedMatches'];
                if (count($bingresult) > 1)
                {
                    $xx = $bing_count;
                    $count_bing = 1000;
                    $total3 = $count_bing;
                }
                $boffset = $page * 15;
                $cnt = $settings->getValue("image_result_fetchcount");
                $loopmode = $settings->getValue("bing_loopmode");
                if ($loopmode == 0)
                {
                    $max = $settings->getValue("bing_image_result_maxcount");
                    if ($max < $cnt) $cnt = $max;
                }
                $j = 0;
                for ($k = 0;$k <= $cnt - 1;$k++)
                {
                    if (($bingresult[$k]['sourceUrl']) != "")
                    {
                        $resultset3[$j][1] = strip_tags($bingresult[$k]['filetype']);
                        $resultset3[$j][2] = strip_tags($bingresult[$k]['width']);
                        $resultset3[$j][3] = strip_tags($bingresult[$k]['sourceUrl']);
                        $resultset3[$j][4] = strip_tags($bingresult[$k]['originalUrl']);
                        $resultset3[$j][5] = strip_tags($bingresult[$k]['thumbnailUrl']);
                        $resultset3[$j][6] = strip_tags($bingresult[$k]['title']);
                        $resultset3[$j][7] = strip_tags($bingresult[$k]['DisplaylUrl']);
                        $resultset3[$j][8] = strip_tags($bingresult[$k]['height']);
                        $resultset3[$j][9] = strip_tags($bingresult[$k]['filesize']);
                        $j++;
                    }
                }
            }
            if ($xmlarray[3] != "null")
            {
                $this->getrelatedkeyword($keyword, $xmlarray[3], 3);
                preg_match_all("/<result><domain>(.+?)<\/domain><filename>(.+?)<\/filename><filesize>(.+?)<\/filesize><format>(.+?)<\/format><height>(.+?)<\/height><refererurl>(.+?)<\/refererurl><thumbnail_url>(.+?)<\/thumbnail_url><title>(.+?)<\/title><url>(.+?)<\/url><width>(.+?)<\/width><\/result>/i", $xmlarray[3], $spiderresult);
                preg_match("/<totalcount>(.+?)<\/totalcount>/i", $xmlarray[3], $totalhits4);
                $total4 = $totalhits4[1];
                $cnt = $settings->getValue("image_result_fetchcount");
                $loopmode = $settings->getValue("spider_loopmode");
                if ($loopmode == 0)
                {
                    $max = $settings->getValue("spider_image_result_maxcount");
                    if ($max < $cnt) $cnt = $max;
                }
                $j = 0;
                for ($k = 0;$k <= $cnt - 1;$k++)
                {
                    if ($spiderresult[2][$k] != "")
                    {
                        $resultset4[$j][1] = $spiderresult[4][$k]; //format
                        $resultset4[$j][2] = $spiderresult[10][$k]; //width
                        $var = str_replace("<![CDATA[", "", $spiderresult[6][$k]);
                        $var = str_replace("]]>", "", $var);
                        $resultset4[$j][3] = strip_tags(html_entity_decode($var)); //refererurl
                        $resultset4[$j][9] = $spiderresult[3][$k]; //filesize
                        $var = str_replace("<![CDATA[", "", $spiderresult[7][$k]);
                        $var = str_replace("]]>", "", $var);
                        $resultset4[$j][5] = html_entity_decode($var); //thumbnail url
                        $var = str_replace("<![CDATA[", "", $spiderresult[8][$k]);
                        $var = str_replace("]]>", "", $var);
                        $resultset4[$j][6] = strip_tags(html_entity_decode($var)); //title
                        $var = str_replace("<![CDATA[", "", $spiderresult[1][$k]);
                        $var = str_replace("]]>", "", $var);
                        $resultset4[$j][7] = strip_tags(html_entity_decode($var)); //domain
                        $resultset4[$j][8] = $spiderresult[5][$k]; //height
                        $var = str_replace("<![CDATA[", "", $spiderresult[9][$k]);
                        $var = str_replace("]]>", "", $var);
                        $resultset4[$j][4] = $var; //url
                        $j++;
                    }
                }
            }
        }
        $totalfetchingcount1 = $settings->getValue("google_totalfetchingcount");
        $totalfetchingcount2 = $settings->getValue("yahoo_totalfetchingcount");
        $totalfetchingcount3 = $settings->getValue("bing_totalfetchingcount");
        $totalfetchingcount4 = $settings->getValue("spider_totalfetchingcount");
        $google_loopmode = $settings->getValue("google_loopmode");
        $yahoo_loopmode = $settings->getValue("yahoo_loopmode");
        $bing_loopmode = $settings->getValue("bing_loopmode");
        $spider_loopmode = $settings->getValue("spider_loopmode");
        if (($searchtype == "web") || ($searchtype == "special"))
        {
            $count = $settings->getValue("result_fetchcount");
            $count1 = $settings->getValue("google_result_maxcount");
            if ($google_loopmode == 0)
            {
                if ($count1 > $count) $count1 = $count;
            }
            else if ($google_loopmode == 1)
            {
                $count1 = $count;
            }
            $count2 = $settings->getValue("yahoo_result_maxcount");
            if ($yahoo_loopmode == 0)
            {
                if ($count2 > $count) $count2 = $count;
            }
            else if ($yahoo_loopmode == 1)
            {
                $count2 = $count;
            }
            $count3 = $settings->getValue("bing_result_maxcount");
            if ($bing_loopmode == 0)
            {
                if ($count3 > $count) $count3 = $count;
            }
            else if ($bing_loopmode == 1)
            {
                $count3 = $count;
            }
            $count4 = $settings->getValue("spider_result_maxcount");
            if ($spider_loopmode == 0)
            {
                if ($count4 > $count) $count4 = $count;
            }
            else if ($spider_loopmode == 1)
            {
                $count4 = $count;
            }
        }
        if ($searchtype == "images")
        {
            $count = $settings->getValue("image_result_fetchcount");
            $count1 = $settings->getValue("google_image_result_maxcount");
            if ($google_loopmode == 0)
            {
                if ($count1 > $count) $count1 = $count;
            }
            else if ($google_loopmode == 1)
            {
                $count1 = $count;
            }
            $count2 = $settings->getValue("yahoo_image_result_maxcount");
            if ($yahoo_loopmode == 0)
            {
                if ($count2 > $count) $count2 = $count;
            }
            else if ($yahoo_loopmode == 1)
            {
                $count2 = $count;
            }
            $count3 = $settings->getValue("bing_image_result_maxcount");
            if ($bing_loopmode == 0)
            {
                if ($count3 > $count) $count3 = $count;
            }
            else if ($bing_loopmode == 1)
            {
                $count3 = $count;
            }
            $count4 = $settings->getValue("spider_image_result_maxcount");
            if ($spider_loopmode == 0)
            {
                if ($count4 > $count) $count4 = $count;
            }
            else if ($spider_loopmode == 1)
            {
                $count4 = $count;
            }
        }
        if ($searchtype == "news")
        {
            $count = $settings->getValue("news_result_fetchcount");
            $count1 = $settings->getValue("google_news_result_maxcount");
            if ($google_loopmode == 0)
            {
                if ($count1 > $count) $count1 = $count;
            }
            else if ($google_loopmode == 1)
            {
                $count1 = $count;
            }
            $count2 = $settings->getValue("yahoo_news_result_maxcount");
            if ($yahoo_loopmode == 0)
            {
                if ($count2 > $count) $count2 = $count;
            }
            else if ($yahoo_loopmode == 1)
            {
                $count2 = $count;
            }
            $count3 = $settings->getValue("bing_news_result_maxcount");
            if ($bing_loopmode == 0)
            {
                if ($count3 > $count) $count3 = $count;
            }
            else if ($bing_loopmode == 1)
            {
                $count3 = $count;
            }
            $count4 = $settings->getValue("spider_news_result_maxcount");
            if ($spider_loopmode == 0)
            {
                if ($count4 > $count) $count4 = $count;
            }
            else if ($spider_loopmode == 1)
            {
                $count4 = $count;
            }
        }
        if ($totalfetchingcount1 % $count1 == 0)
        {
            $limit1 = intval($totalfetchingcount1 / $count1);
        }
        else
        {
            $limit1 = intval($totalfetchingcount1 / $count1) + 1;
        }
        if ($totalfetchingcount2 % $count2 == 0)
        {
            $limit2 = intval($totalfetchingcount2 / $count2);
        }
        else
        {
            $limit2 = intval($totalfetchingcount2 / $count2) + 1;
        }
        if ($totalfetchingcount3 % $count3 == 0)
        {
            $limit3 = intval($totalfetchingcount3 / $count3);
        }
        else
        {
            $limit3 = intval($totalfetchingcount3 / $count3) + 1;
        }
        if ($totalfetchingcount4 % $count4 == 0)
        {
            $limit4 = intval($totalfetchingcount4 / $count4);
        }
        else
        {
            $limit4 = intval($totalfetchingcount4 / $count4) + 1;
        }
        $status1 = 1;
        $status2 = 1;
        $status3 = 1;
        $status4 = 1;
        if (($xmlarray[0] != "") && ($xmlarray[0] != " "))
        {
            if ($total1 == 0)
            {
                $status1 = 0;
            }
            else if ($crawlindex >= $limit1)
            {
                $status1 = 0;
            }
            else if ($total1 <= ($crawlindex - 1) * $count1)
            {
                $status1 = 0;
            }
        }
        if (($xmlarray[1] != "") && ($xmlarray[1] != " "))
        {
            if ($total2 == 0)
            {
                $status2 = 0;
            }
            else if ($crawlindex >= $limit2)
            {
                $status2 = 0;
            }
            else if ($yoffset < ($crawlindex - 1) * $count2)
            {
                $status2 = 0;
            }
        }
        if (($xmlarray[2] != "") && ($xmlarray[2] != " "))
        {
            if ($total3 == 0)
            {
                $status3 = 0;
            }
            else if ($crawlindex >= $limit3)
            {
                $status3 = 0;
            }
            else if ($boffset < ($crawlindex - 1) * $count3)
            {
                $status3 = 0;
            }
        }
        if (($xmlarray[3] != "") && ($xmlarray[3] != " "))
        {
            if ($total4 == 0)
            {
                $status4 = 0;
            }
            else if ($crawlindex >= $limit4)
            {
                $status4 = 0;
            }
            else if ($total4 <= ($crawlindex - 1) * $count4)
            {
                $status4 = 0;
            }
        }
        if ($crawlindex - $prevcrawlindex > 5)
        {
            $status1 = 0;
            $status2 = 0;
            $status3 = 0;
            $status4 = 0;
        }
        if (($total1 == 0) && ($total2 == 0) && ($total3 == 0) && ($total4 == 0))
        {
            if (($xmlarray[0] != "") && ($xmlarray[0] != " ") && ($xmlarray[1] != "") && ($xmlarray[1] != " ") && ($xmlarray[2] != "") && ($xmlarray[2] != " ") && ($xmlarray[3] != "") && ($xmlarray[3] != " ")) $allstatus = 0;
            else
            return "expired";
        }
        else if ((count($resultset1) == 0) && (count($resultset2) == 0) && (count($resultset3) == 0) && (count($resultset4) == 0))
        {
            if (($xmlarray[0] != "") && ($xmlarray[0] != " ") && ($xmlarray[1] != "") && ($xmlarray[1] != " ") && ($xmlarray[2] != "") && ($xmlarray[2] != " ") && ($xmlarray[3] != "") && ($xmlarray[3] != " ")) $allstatus = 0;
            else
            return "expired";
        }
        else
        {
            $allstatus = 1;
            $s = 0;
            $t = 1;
            if ($h == "")
            {
                $h = 0;
            }
            $u = $h;
            for ($e = 0;$e < $h;$e++)
            {
                $urlcollection[$e] = $csv1[$e][1];
                $finalmixresults[$e][5] = $csv1[$e][0];
            }
            if ($mixing_normal_status == 1)
            {
                $cnt = $count * 4;
                for ($i = 0;$i < $cnt;$i++)
                {
                    if ($t == 1)
                    {
                        $resultset = $resultset1;
                    } //google
                    if ($t == 2)
                    {
                        $resultset = $resultset2;
                    } //yahoo
                    if ($t == 3)
                    {
                        $resultset = $resultset3;
                    } //bing
                    if ($t == 4)
                    {
                        $resultset = $resultset4;
                    } //spider
                    $new = str_replace("www.", "", $resultset[$s][4]);
                    if ((!in_array(md5($new) , $urlcollection)) && ($new != ""))
                    {
                        $urlcollection[$u] = md5($new);
                        $finalmixresults[$u][1] = $resultset[$s][1]; //disc
                        $finalmixresults[$u][2] = $resultset[$s][2]; //dispaly url
                        $finalmixresults[$u][3] = $resultset[$s][3]; //title
                        $finalmixresults[$u][4] = trim($resultset[$s][4]); //title url
                        if ($searchtype == "images")
                        {
                            $finalmixresults[$u][6] = $resultset[$s][5];
                            $finalmixresults[$u][7] = $resultset[$s][6];
                            $finalmixresults[$u][8] = $resultset[$s][7];
                            $finalmixresults[$u][9] = $resultset[$s][8];
                            $finalmixresults[$u][10] = $resultset[$s][9];
                        }
                        if ($t == 1)
                        {
                            $finalmixresults[$u][5] = "1000";
                        }
                        if ($t == 2)
                        {
                            $finalmixresults[$u][5] = "0100";
                        }
                        if ($t == 3)
                        {
                            $finalmixresults[$u][5] = "0010";
                        }
                        if ($t == 4)
                        {
                            $finalmixresults[$u][5] = "0001";
                        }
                        $u++;
                    }
                    else if (in_array(md5($new) , $urlcollection))
                    {
                        $p = array_search(md5($new) , $urlcollection, 'strict');
                        if ($p >= $h)
                        {
                            if ($t == 1)
                            {
                                $finalmixresults[$p][5] = substr_replace($finalmixresults[$p][5], "1", 0, 1);
                            }
                            if ($t == 2)
                            {
                                $finalmixresults[$p][5] = substr_replace($finalmixresults[$p][5], "1", 1, 1);
                            }
                            if ($t == 3)
                            {
                                $finalmixresults[$p][5] = substr_replace($finalmixresults[$p][5], "1", 2, 1);
                            }
                            if ($t == 4)
                            {
                                $finalmixresults[$p][5] = substr_replace($finalmixresults[$p][5], "1", 3, 1);
                            }
                        }
                        else
                        {
                            if ($t == 1)
                            {
                                $finalmixresults[$p][5] = substr_replace($finalmixresults[$p][5], "1", 0, 1);
                            }
                            if ($t == 2)
                            {
                                $finalmixresults[$p][5] = substr_replace($finalmixresults[$p][5], "1", 1, 1);
                            }
                            if ($t == 3)
                            {
                                $finalmixresults[$p][5] = substr_replace($finalmixresults[$p][5], "1", 2, 1);
                            }
                            if ($t == 4)
                            {
                                $finalmixresults[$p][5] = substr_replace($finalmixresults[$p][5], "1", 3, 1);
                            }
                        }
                    }
                    ++$t;
                    if ($t >= 5)
                    {
                        $t = 1;
                        $s = $s + 1;
                    }
                }
                $onlygooglestatus = 0;
            }
            else
            {
                if (substr_count($mixing_normal_sources, "G") != 0)
                {
                    $resultset = $resultset1;
                    $show = "1000";
                    $onlygooglestatus = 1;
                }
                elseif (substr_count($mixing_normal_sources, "Y") != 0)
                {
                    $resultset = $resultset2;
                    $show = "0100";
                    $onlygooglestatus = 0;
                }
                elseif (substr_count($mixing_normal_sources, "B") != 0)
                {
                    $resultset = $resultset3;
                    $show = "0010";
                    $onlygooglestatus = 0;
                }
                elseif (substr_count($mixing_normal_sources, "S") != 0)
                {
                    $resultset = $resultset4;
                    $show = "0001";
                    $onlygooglestatus = 0;
                }
                for ($i = 0;$i < $cnt;$i++)
                {
                    $new = str_replace("www.", "", $resultset[$s][4]);
                    if ((!in_array(md5($new) , $urlcollection)) && ($new != ""))
                    {
                        $urlcollection[$u] = md5($new);
                        $finalmixresults[$u][1] = $resultset[$s][1];
                        $finalmixresults[$u][2] = $resultset[$s][2];
                        $finalmixresults[$u][3] = $resultset[$s][3];
                        $finalmixresults[$u][4] = trim($resultset[$s][4]);
                        $finalmixresults[$u][5] = $show;
                        if ($searchtype == "images")
                        {
                            $finalmixresults[$u][6] = $resultset[$s][5];
                            $finalmixresults[$u][7] = $resultset[$s][6];
                            $finalmixresults[$u][8] = $resultset[$s][7];
                            $finalmixresults[$u][9] = $resultset[$s][8];
                            $finalmixresults[$u][10] = $resultset[$s][9];
                        }
                        $u++;
                    }
                    $s = $s + 1;
                }
            }
            $totcnt = count($finalmixresults);
            $newcnt = $totcnt - $h;
            if ($lastid != 0)
            {
                $rem = $resultcount - $h % $resultcount;
                if ($rem != $resultcount)
                {
                    if ($newcnt < $rem)
                    {
                        $rem = $newcnt;
                        $h = $h + $rem;
                    }
                    else $h = $h + $rem;
                }
                else $rem = 0;
            }
            $xmldataprev .= "{\"item\":[";
            for ($i = $h - $rem;$i < $h;$i++)
            {
                $jk = $h - 1;
                if ($searchtype == "images")
                {
                    if ($jk == $i)
                    {
                        $xmldataprev .= "{\"type\":\"" . $finalmixresults[$i][1] . "\",\"width\":\"" . $finalmixresults[$i][2] . "\",\"imagelocation\":\"" . $finalmixresults[$i][3] . "\",\"filesize\":\"" . $finalmixresults[$i][10] . "\",\"thumburl\":\"" . $finalmixresults[$i][6] . "\",\"title\":\"" . $finalmixresults[$i][7] . "\",\"visibleurl\":\"" . $finalmixresults[$i][8] . "\",\" height\":\"" . $finalmixresults[$i][9] . "\",\"url\":\"" . $finalmixresults[$i][4] . "\" }";
                    }
                    else
                    {
                        $xmldataprev .= "{\"type\":\"" . $finalmixresults[$i][1] . "\",\"width\":\"" . $finalmixresults[$i][2] . "\",\"imagelocation\":\"" . $finalmixresults[$i][3] . "\",\"filesize\":\"" . $finalmixresults[$i][10] . "\",\"thumburl\":\"" . $finalmixresults[$i][6] . "\",\"title\":\"" . $finalmixresults[$i][7] . "\",\"visibleurl\":\"" . $finalmixresults[$i][8] . "\",\"height\":\"" . $finalmixresults[$i][9] . "\",\"url\":\"" . $finalmixresults[$i][4] . "\" },";
                    }
                }
                else
                {
                    $description = base64_encode($finalmixresults[$i][1]);
		    $title = base64_encode($finalmixresults[$i][3]);
                    if ($jk == $i)
                    {
                        $xmldataprev .= "{\"title\":\"" . $title . "\",\"titleurl\":\"" . $finalmixresults[$i][4] . "\",\"description\":\"" . $description . "\",\"displayurl\":\"" . $finalmixresults[$i][2] . "\"}";
                    }
                    else
                    {
                        $xmldataprev .= "{\"title\":\"" . $title . "\",\"titleurl\":\"" . $finalmixresults[$i][4] . "\",\"description\":\"" . $description . "\",\"displayurl\":\"" . $finalmixresults[$i][2] . "\"},";
                    }
                }
            }
            $xmldataprev .= "]}";
            if ($h == $totcnt)
            {
                $newcntstatus = 0;
            }
            else
            {
                $newcntstatus = 1;
            }
            $xmldata = "";
            $maxcnt = max($total1, $total2, $total3, $total4); //exit;
            $maxfetch = max($totalfetchingcount1, $totalfetchingcount2, $totalfetchingcount3, $totalfetchingcount4);
            if ($maxcnt < $maxfetch)
            {
                $maxcnt = $total1 + $total2 + $total3 + $total4;
            }
            if (($totalcount != "") && ($totalcount != 0) && ($totalcount >= $maxcnt))
            {
                $maxcnt = $totalcount;
            }
            $xmldata .= "{\"item\":[";
            for ($i = $h;$i < $totcnt;$i++)
            {
                $jk = $totcnt - 1;
                if ($searchtype == "images")
                {
                    if ($jk == $i)
                    {
                        $xmldata .= "{\"type\":\"" . $finalmixresults[$i][1] . "\",\"width\":\"" . $finalmixresults[$i][2] . "\",\"imagelocation\":\"" . $finalmixresults[$i][3] . "\",\"filesize\":\"" . $finalmixresults[$i][10] . "\",\"thumburl\":\"" . $finalmixresults[$i][6] . "\",\"title\":\"" . $finalmixresults[$i][7] . "\",\"visibleurl\":\"" . $finalmixresults[$i][8] . "\",\" cheight\":\"" . $finalmixresults[$i][9] . "\",\"url\":\"" . $finalmixresults[$i][4] . "\" }";
                    }
                    else
                    {
                        $xmldata .= "{\"type\":\"" . $finalmixresults[$i][1] . "\",\"width\":\"" . $finalmixresults[$i][2] . "\",\"imagelocation\":\"" . $finalmixresults[$i][3] . "\",\"filesize\":\"" . $finalmixresults[$i][10] . "\",\"thumburl\":\"" . $finalmixresults[$i][6] . "\",\"title\":\"" . $finalmixresults[$i][7] . "\",\"visibleurl\":\"" . $finalmixresults[$i][8] . "\",\"height\":\"" . $finalmixresults[$i][9] . "\",\"url\":\"" . $finalmixresults[$i][4] . "\" },";
                    }
                }
                else
                {
                    $description = base64_encode($finalmixresults[$i][1]);
$title = base64_encode($finalmixresults[$i][3]);
                    if ($jk == $i)
                    {
                        $xmldata .= "{\"title\":\"" . $title . "\",\"titleurl\":\"" . $finalmixresults[$i][4] . "\",\"description\":\"" . $description . "\",\"displayurl\":\"" . $finalmixresults[$i][2] . "\"}";
                    }
                    else
                    {
                        $xmldata .= "{\"title\":\"" . $title . "\",\"titleurl\":\"" . $finalmixresults[$i][4] . "\",\"description\":\"" . $description . "\",\"displayurl\":\"" . $finalmixresults[$i][2] . "\"},";
                    }
                }
            }
            $xmldata .= "]}";
            $toturl = count($urlcollection);
            $csvstring = "";
            for ($i = 0;$i < $toturl;$i++)
            {
                $csvstring .= $finalmixresults[$i][5] . "." . $urlcollection[$i] . ",";
            }
        }
    }
    if ($searchtype == "videos")
    {
        for ($i = 0;$i <= 1;$i++)
        {
            $xmlarray[$i] = str_replace("\r\n", "", $xmlarray[$i]);
            $xmlarray[$i] = str_replace("\n", "", $xmlarray[$i]);
            $xmlarray[$i] = str_replace("\r", "", $xmlarray[$i]);
        }
        $xmlarray_decode = json_decode($xmlarray[0], true);
        $youtuberesult = array();
        $tot = $xmlarray_decode['pageInfo']['totalResults'];
        $next = $xmlarray_decode['nextPageToken'];
        $prev = $xmlarray_decode['prevPageToken'];
        $responseresult = [];
        foreach ($xmlarray_decode['items'] as $responseresult)
        {
            $youtuberesult[] = array(
                '1' => $responseresult['snippet']['title'],
                '2' => $responseresult['id']['videoId'],
                '3' => $responseresult['snippet']['thumbnails']['high']['url'],
            );
        }
        if ($xmlarray[0] != "null")
        {
            $this->getrelatedkeyword($keyword, $xmlarray[0], 1);
            $total1 = $tot;
            $yoffset = $totalhits2[2];
            $cnt = $settings->getValue("video_result_fetchcount");
            $loopmode = $settings->getValue("youtube_loopmode");
            if ($loopmode == 0)
            {
                $max = $settings->getValue("youtube_video_result_maxcount");
                if ($max < $cnt) $cnt = $max;
            }
            $j = 0;
            for ($k = 0;$k <= $cnt - 1;$k++)
            {
                if ($youtuberesult[$k][2] != "")
                {
                    $resultset1[$j][1] = html_entity_decode('http://www.youtube.com/watch?v=' . $youtuberesult[$j][2]);
                    $resultset1[$j][2] = html_entity_decode($youtuberesult[$j][3]);
                    $resultset1[$j][3] = html_entity_decode($youtuberesult[$j][1]); //title
                    $resultset1[$j][4] = $youtuberesult[$j][2]; // video id
                    $j++;
                }
            }
        }
        if ($xmlarray[1] != "null") // bing video results
        {
            $this->getrelatedkeyword($keyword, $xmlarray[1], 2);
            $bingresult = json_decode($xmlarray[1], true);
            $bing_count = ($bingresult['totalEstimatedMatches']);
            $xx = $bing_count;
            $count_bing = 1000;
            $total2 = $bing_count;
            $response_bng = array();
            $atc_res = array();
            $sec_array = array();
            $sec_array = $bingresult['value'];
            foreach ($sec_array as $i)
            {
                $bing_fresult[] = array(
                    'name' => $i['name'],
                    'duration' => $i['duration'],
                    'thumbnailUrl' => $i['thumbnailUrl'],
                    'contentUrl' => $i['contentUrl']
                );
            }
            $boffset = $page * 10;
            $cnt = $settings->getValue("video_result_fetchcount");
            $loopmode = $settings->getValue("bing_loopmode");
            if ($loopmode == 0)
            {
                $max = $settings->getValue("bing_video_result_maxcount");
                if ($max < $cnt) $cnt = $max;
            }
            $j = 0;
            for ($k = 0;$k <= $cnt - 1;$k++)
            {
                if (($bing_fresult[$k]['contentUrl']) != "")
                {
                    $resultset2[$j][1] = html_entity_decode($bing_fresult[$k]['contentUrl']);
                    $resultset2[$j][2] = html_entity_decode($bing_fresult[$k]['thumbnailUrl']);
                    $resultset2[$j][3] = strip_tags($bing_fresult[$k]['name']);
                    $resultset2[$j][4] = $bing_fresult[$k]['duration'];
                    $j++;
                }
            }
        }
        $totalfetchingcount1 = $settings->getValue("youtube_totalfetchingcount");
        $totalfetchingcount2 = $settings->getValue("bing_totalfetchingcount");
        $youtube_loopmode = $settings->getValue("youtube_loopmode");
        $bing_loopmode = $settings->getValue("bing_loopmode");
        if ($searchtype == "videos")
        {
            $count = $settings->getValue("video_result_fetchcount");
            $count1 = $settings->getValue("youtube_video_result_maxcount");
            if ($youtube_loopmode == 0)
            {
                if ($count1 > $count) $count1 = $count;
            }
            else if ($youtube_loopmode == 1)
            {
                $count1 = $count;
            }
            $count2 = $settings->getValue("bing_video_result_maxcount");
            if ($bing_loopmode == 0)
            {
                if ($count2 > $count) $count2 = $count;
            }
            else if ($bing_loopmode == 1)
            {
                $count2 = $count;
            }
        }
        if ($totalfetchingcount1 % $count1 == 0)
        {
            $limit1 = intval($totalfetchingcount1 / $count1);
        }
        else
        {
            $limit1 = intval($totalfetchingcount1 / $count1) + 1;
        }
        if ($totalfetchingcount2 % $count2 == 0)
        {
            $limit2 = intval($totalfetchingcount2 / $count2);
        }
        else
        {
            $limit2 = intval($totalfetchingcount2 / $count2) + 1;
        }
        $status1 = 1;
        $status2 = 1;
        if (($xmlarray[0] != "") && ($xmlarray[0] != " "))
        {
            if ($total1 == 0)
            {
                $status1 = 0;
            }
            else if ($crawlindex >= $limit1)
            {
                $status1 = 0;
            }
            else if ($yoffset < ($crawlindex - 1) * $count1)
            {
                $status1 = 0;
            }
        }
        if (($xmlarray[1] != "") && ($xmlarray[1] != " "))
        {
            if ($total2 == 0)
            {
                $status2 = 0;
            }
            else if ($crawlindex >= $limit2)
            {
                $status2 = 0;
            }
            else if ($boffset < ($crawlindex - 1) * $count2)
            {
                $status2 = 0;
            }
        }
			if($crawlindex-$prevcrawlindex>5)
			{
				$status1=0;$status2=0;
			}
        if (($total1 == 0) && ($total2 == 0))
        {
            if (($xmlarray[0] != "") && ($xmlarray[0] != " ") && ($xmlarray[1] != "") && ($xmlarray[1] != " ")) $allstatus = 0;
            else return "expired";
        }
        else if ((count($resultset1) == 0) && (count($resultset2) == 0))
        {
            if (($xmlarray[0] != "") && ($xmlarray[0] != " ") && ($xmlarray[1] != "") && ($xmlarray[1] != " ")) $allstatus = 0;
            else return "expired";
        }
        else
        {
            $allstatus = 1;
            $s = 0;
            $t = 1;
            if ($h == "")
            {
                $h = 0;
            }
            $u = $h;
            for ($e = 0;$e < $h;$e++)
            {
                $urlcollection[$e] = $csv1[$e][1];
                $finalmixresults[$e][5] = $csv1[$e][0];
            }
            if ($mixing_video_status == 1)
            {
                $cnt = $count * 2;
                for ($i = 0;$i < $cnt;$i++)
                {
                    if ($t == 1)
                    {
                        $resultset = $resultset1;
                    }
                    if ($t == 2)
                    {
                        $resultset = $resultset2;
                    }
                    $new = str_replace("www.", "", $resultset[$s][1]);
                    if ((!in_array(md5($new) , $urlcollection)) && ($new != ""))
                    {
                        $urlcollection[$u] = md5($new);
                        $finalmixresults[$u][1] = $resultset[$s][1];
                        $finalmixresults[$u][2] = $resultset[$s][2];
                        $finalmixresults[$u][3] = $resultset[$s][3];
                        $finalmixresults[$u][4] = trim($resultset[$s][4]);
                        if ($t == 1)
                        {
                            $finalmixresults[$u][5] = "10";
                        }
                        if ($t == 2)
                        {
                            $finalmixresults[$u][5] = "01";
                        }
                        $finalmixresults[$u][6] = $resultset[$s][4]; //video id
                        $u++;
                    }
                    else if (in_array(md5($new) , $urlcollection))
                    {
                        $p = array_search(md5($new) , $urlcollection, 'strict');
                        if ($p >= $h)
                        {
                            if ($t == 1)
                            {
                                $finalmixresults[$p][5] = substr_replace($finalmixresults[$p][5], "1", 0, 1);
                            }
                            if ($t == 2)
                            {
                                $finalmixresults[$p][5] = substr_replace($finalmixresults[$p][5], "1", 1, 1);
                            }
                        }
                        else
                        {
                            if ($t == 1)
                            {
                                $finalmixresults[$p][5] = substr_replace($finalmixresults[$p][5], "1", 0, 1);
                            }
                            if ($t == 2)
                            {
                                $finalmixresults[$p][5] = substr_replace($finalmixresults[$p][5], "1", 1, 1);
                            }
							}
						}
						++$t;
						if($t>=3)
						{
							$t=1; $s=$s+1;
						}
					}
				}
				else
				{
					if(substr_count($mixing_video_sources,"T")!=0)
					{
						$resultset=$resultset1;
						$show= "10";
					}
					elseif(substr_count($mixing_video_sources,"B")!=0)
					{
						$resultset=$resultset2;
						$show= "01";
					}
                for ($i = 0;$i < $cnt;$i++)
                {
                    $new = str_replace("www.", "", $resultset[$s][1]);
                    if ((!in_array(md5($new) , $urlcollection)) && ($new != "")) //if($new!="")
                    {
                        $urlcollection[$u] = md5($new);
                        $finalmixresults[$u][1] = $resultset[$s][1];
                        $finalmixresults[$u][2] = $resultset[$s][2];
                        $finalmixresults[$u][3] = $resultset[$s][3];
                        $finalmixresults[$u][4] = $show;
                        $finalmixresults[$u][5] = $resultset[$s][4]; //video id
                        $u++;
                    }
                    $s = $s + 1;
                }
            }
            $onlygooglestatus = 0;
            $totcnt = count($finalmixresults);
            $newcnt = $totcnt - $h;
            if ($lastid != 0)
            {
                $rem = $resultcount - $h % $resultcount;
                if ($rem != $resultcount)
                {
                    if ($newcnt < $rem)
                    {
                        $rem = $newcnt;
                        $h = $h + $rem;
                    }
                    else $h = $h + $rem;
                }
                else $rem = 0;
            }
            $xmldataprev .= "{\"item\":[";
            for ($i = $h - $rem;$i < $h;$i++)
            {
                $jk = $h - 1;
                if ($jk == $i)
                {
                    $xmldataprev .= "{\"title\":\"" . $finalmixresults[$i][3] . "\",\"titleurl\":\"" . $finalmixresults[$i][1] . "\",\"imageurl\":\"" . $finalmixresults[$i][2] . "\",\"duration\":\"" . $finalmixresults[$i][4] . "\" }";
                }
                else
                {
                    $xmldataprev .= "{\"title\":\"" . $finalmixresults[$i][3] . "\",\"titleurl\":\"" . $finalmixresults[$i][1] . "\",\"imageurl\":\"" . $finalmixresults[$i][2] . "\",\"duration\":\"" . $finalmixresults[$i][4] . "\" },";
                }
            }
            $xmldataprev .= "]}";
            if ($h == $totcnt)
            {
                $newcntstatus = 0;
            }
            else
            {
                $newcntstatus = 1;
            }
            $xmldata = "";
            $maxcnt = max($total1, $total2);
            $maxfetch = max($totalfetchingcount1, $totalfetchingcount2);
            if ($maxcnt < $maxfetch)
            {
                $maxcnt = $total1 + $total2;
            }
            if (($totalcount != "") && ($totalcount != 0) && ($totalcount >= $maxcnt))
            {
                $maxcnt = $totalcount;
            }
            $xmldata .= "{\"item\":[";
            for ($i = $h;$i < $totcnt;$i++)
            {
                $jk = $totcnt - 1;
                if ($jk == $i)
                {
                    $xmldata .= "{\"title\":\"" . $finalmixresults[$i][3] . "\",\"titleurl\":\"" . $finalmixresults[$i][1] . "\",\"imageurl\":\"" . $finalmixresults[$i][2] . "\",\"duration\":\"" . $finalmixresults[$i][4] . "\" }";
                }
                else
                {
                    $xmldata .= "{\"title\":\"" . $finalmixresults[$i][3] . "\",\"titleurl\":\"" . $finalmixresults[$i][1] . "\",\"imageurl\":\"" . $finalmixresults[$i][2] . "\",\"duration\":\"" . $finalmixresults[$i][4] . "\" },";
                }
            }
            $xmldata .= "]}";
            $toturl = count($urlcollection);
            $csvstring = "";
            for ($i = 0;$i < $toturl;$i++)
            {
                $csvstring .= $finalmixresults[$i][5] . "." . $urlcollection[$i] . ",";
            }
        }
    }
    $endnum = $totcnt - 1;
    $db = new NesoteDALController();
    $currenttime = time();
    $time = getdate($currenttime);
    $year = $time['year'];
    $month = $time['mon'];
    $date = $time['mday'];
    {
        $db = new NesoteDALController();
        $db->select("nesote_inoutse_engines");
        $db->fields("tab_name");
        $db->where("id=?", array(
            $engineid
        ));
        $result = $db->query();
        $row = $db->fetchRow($result);
        $type = $row[0];
        $keyword = urlencode($keyword);
        include ('script.inc.php');
        include ($config_path . 'system.config.php');
    }
    $tot1 = $db->total("nesote_inoutse_engines", "id=? and cacheable=?", array(
        $engineid,
        1
    ));
    if ($tot1 == 1)
    {
        $index = $crawlindex;
        $startnum = $h;
        if ($totcnt != 0) $endnum = $totcnt - 1;
        else $endnum = $h;
        if ($allstatus == 0)
        {
            if (($newest == 1) && ($lastid == 0))
            {
                if (($startnum == 0) && ($endnum == 0) && ($finalmixresults == ""))
                {
                    $endnum = - 1;
                }
                $db->insert("nesote_inoutse_mixcache" . $cacheindex);
                $db->fields("engineid,keyterm,crawlindex,startnumber,endnumber,time,status1,status2,status3,status4,deletestatus");
                $db->values(array(
                    $engineid,
                    $keyterm,
                    $index,
                    $startnum,
                    $endnum,
                    time() ,
                    $status1,
                    $status2,
                    $status3,
                    $status4,
                    0
                ));
                $db->query();
                $id = $db->lastInsertid("nesote_inoutse_mixcache" . $cacheindex);
                if (($status1 == 0) && ($status2 == 0) && ($status3 == 0) && ($status4 == 0))
                {
                    if ($crawlindex == 1)
                    {
                        $totcnt = $maxcnt;
                    }
                    else
                    {
                        $totcnt = $endnum + 1;
                    }
                    $db->update("nesote_inoutse_mixcache" . $cacheindex);
                    $db->set("totalcount=?,status1=?,status2=?,status3=?,status4=?", array(
                        $totcnt,
                        $status1,
                        $status2,
                        $status3,
                        $status4
                    ));
                    $db->where("deletestatus=0 and keyterm=?", array(
                        $keyterm
                    ));
                    $db->query();
                }
                return "";
            }
            else if (($newest == 1) && ($lastid != 0))
            {
                $db->update("nesote_inoutse_mixcache" . $cacheindex);
                $db->set("status1=?,status2=?,status3=?,status4=?", array(
                    $status1,
                    $status2,
                    $status3,
                    $status4
                ));
                $db->where("id=?", array(
                    $lastid
                ));
                $db->query();
                if (($status1 == 0) && ($status2 == 0) && ($status3 == 0) && ($status4 == 0))
                {
                    if ($crawlindex >= $limit)
                    {
                        if ($endnum + 1 < $maxcnt) $totcnt = $maxcnt;
                        else $totcnt = $h;
                    }
                    else
                    {
                        $totcnt = $h;
                    }
                    $db->update("nesote_inoutse_mixcache" . $cacheindex);
                    $db->set("totalcount=?", array(
                        $totcnt
                    ));
                    $db->where("deletestatus=0 and keyterm=?", array(
                        $keyterm
                    ));
                    $db->query();
                }
                return "";
            }
            else if ($lastid != 0)
            {
                if ($maxcnt == "")
                {
                    $maxcnt = $totalcount;
                }
                $db->update("nesote_inoutse_mixcache" . $cacheindex);
                $db->set("status1=?,status2=?,status3=?,status4=?", array(
                    $status1,
                    $status2,
                    $status3,
                    $status4
                ));
                $db->where("id=?", array(
                    $lastid
                ));
                $db->query();
                if ($crawlst1 >= $h)
                {
                    $erd = $h - 1;
                }
                else $erd = $crawlst1;
                $xmlappend .= "{\"source\":[";
                for ($i = $crawlst;$i <= $erd;$i++)
                {
                    $statusarray[$i] = $csv1[$i][0];
                    if ($i == $erd)
                    {
                        $xmlappend .= "{\"sourcestatus\":\"" . $statusarray[$i] . "\"}";
                    }
                    else
                    {
                        $xmlappend .= "{\"sourcestatus\":\"" . $statusarray[$i] . "\"},";
                    }
                }
                $xmlappend .= "]}";
                $allstatus1s = 0;
                $xmldataprev = "{\"start\":\"" . $startprev . "\",\"totalcount\":\"" . $totalcount . "\",\"backupcount\":\"" . $h . "\",\"allstatus\":\"" . $allstatus1s . "\",\"onlygooglestatus\":\"" . $googleonly . "\"}" . '&@&' . $xmldataprev;
                return $xmldataprev . '&@&' . $xmlappend;
            }
            else
            {
                echo "this case is an imaginary case";
            }
        }
        if (($lastid != 0) && ($rem != 0))
        {  
            $t1 = $db->total("nesote_inoutse_mixcache" . $cacheindex, "crawlindex>=? and keyterm=? and deletestatus=0", array(
                $index,
                $keyterm
            ));
            if ($t1 == 0)
            {
                $lasttime = getdate($lasttime);
                $year1 = $lasttime['year'];
                $month1 = $lasttime['mon'];
                $date1 = $lasttime['mday'];
                $fp = fopen("mixedupxmldata/mixcache" . $cacheindex . "/$year1/$month1/$date1/$lastid" . ".data", "w");
                fputs($fp, $xmldataprev);
                fclose($fp);
                $db->update("nesote_inoutse_mixcache" . $cacheindex);
                $db->set("endnumber=?", array(
                    $startnum - 1
                ));
                $db->where("id=?", array(
                    $lastid
                ));
                $db->query();
            }
        }
        if ($newcntstatus == 0)
        {
            $db->update("nesote_inoutse_mixcache" . $cacheindex);
            $db->set("crawlindex=?", array(
                $index
            ));
            $db->where("id=?", array(
                $lastid
            ));
            $db->query();
        }
        if (($newcntstatus != 0) || ($lastid == 0))
        {
            $t1 = $db->total("nesote_inoutse_mixcache" . $cacheindex, "crawlindex>=? and keyterm=? and deletestatus=0", array(
                $index,
                $keyterm
            ));
            if ($t1 == 0)
            {
                if (($startnum == 0) && ($endnum == 0) && ($finalmixresults == ""))
                {
                    $endnum = - 1;
                }
                if (($status1 == 0) && ($status2 == 0) && ($status3 == 0) && ($status4 == 0))
                {
                    if ($crawlindex >= $limit)
                    {
                        if ($endnum + 1 < $maxcnt) $totcnt = $maxcnt;
                        else $totcnt = $endnum + 1;
                    }
                    else
                    {
                        $totcnt = $endnum + 1;
                    }
                }
                else
                {
                    if ($maxcnt > $totcnt + 1) $totcnt = $maxcnt;
                }
                $db->insert("nesote_inoutse_mixcache" . $cacheindex);
                $db->fields("engineid,keyterm,crawlindex,startnumber,endnumber,time,status1,status2,status3,status4,deletestatus,totalcount");
                $db->values(array(
                    $engineid,
                    $keyterm,
                    $index,
                    $startnum,
                    $endnum,
                    time() ,
                    $status1,
                    $status2,
                    $status3,
                    $status4,
                    0,
                    $totcnt
                ));
                $db->query();
                $id = $db->lastInsertid("nesote_inoutse_mixcache" . $cacheindex);
                if (($t1 == 0) || ($newcntstatus == 0))
                {
                    $source = $csvstring;
                }
                else
                {
                    $source = '';
                }
            $cachestore = new cachestorage();
		$cachestore->storemixcache($xmldata, $cacheindex, $id, $source);
            }
        }
    }
    if (($status1 == 0) && ($status2 == 0) && ($status3 == 0) && ($status4 == 0))
    {
        if ($crawlindex >= $limit)
        {
            if ($endnum + 1 < $maxcnt) $totcnt = $maxcnt;
            else $totcnt = $endnum + 1;
        }
        else
        {
            $totcnt = $endnum + 1;
        }
        $db->update("nesote_inoutse_mixcache" . $cacheindex);
        $db->set("totalcount=?", array(
            $totcnt
        ));
        $db->where("deletestatus=0 and keyterm=?", array(
            $keyterm
        ));
        $db->query();
        $maxcnt = $totcnt;
        $db->update("nesote_inoutse_mixcache" . $cacheindex);
        $db->set("status1=?,status2=?,status3=?,status4=?", array(
            $status1,
            $status2,
            $status3,
            $status4
        ));
        $db->where("id=?", array(
            $lastid
        ));
        $db->query();
    }
    else if (($totalcount != "") && ($totalcount != 0))
    {
        $maxcnt = $totalcount;
    }
    else
    {
        if ($maxcnt > $totcnt + 1) $maxcnt = $maxcnt;
        else $maxcnt = $totcnt;
    }
    if ($startprev1 != "")
    {
        $startprev = $startprev1;
    }
    if (($lastid != 0) && ($newest != 1))
    {
        $i = 0;
        $h = count($urlcollection);
        if ($crawlst1 < $h)
        {
            $xmlappend .= "{\"source\":[";
            for ($i = $crawlst;$i < $h;$i++)
            {
                $statusarray[$i] = $finalmixresults[$i][5];
                if (($i >= $crawlst) && ($i <= $crawlst1))
                {
                    if ($i == $crawlst1)
                    {
                        $xmlappend .= "{\"sourcestatus\":\"" . $statusarray[$i] . "\"}";
                    }
                    else
                    {
                        $xmlappend .= "{\"sourcestatus\":\"" . $statusarray[$i] . "\"},";
                    }
                }
            }
            $xmlappend .= "]}";
        }
        else
        {
            $start = $h - $resultcount;
            if ($start < 0)
            {
                $start = 0;
                $xmlappend .= "{\"source\":[";
                for ($i = 0;$i < $h;$i++)
                {
                    $statusarray[$start] = $finalmixresults[$start][5];
                    if ($i == $h)
                    {
                        $xmlappend .= "{\"sourcestatus\":\"" . $finalmixresults[$start][5] . "\"}";
                    }
                    else
                    {
                        $xmlappend .= "{\"sourcestatus\":\"" . $finalmixresults[$start][5] . "\"},";
                    }
                    $start++;
                }
                $xmlappend .= "]}";
            }
            else
            {
                $xmlappend .= "{\"source\":[";
                for ($i = 0;$i < $resultcount;$i++)
                {
                    $statusarray[$start] = $finalmixresults[$start][5];
                    if ($i == $resultcount)
                    {
                        $xmlappend .= "{\"sourcestatus\":\"" . $statusarray[$start] . "\"}";
                    }
                    else
                    {
                        $xmlappend .= "{\"sourcestatus\":\"" . $statusarray[$start] . "\"},";
                    }
                    $start++;
                }
                $xmlappend .= "]}";
            }
        }
        if (($status1 == 0) && ($status2 == 0) && ($status3 == 0) && ($status4 == 0))
        {
            $allstatus1 = 0;
        }
        else
        {
            $allstatus1 = 1;
        }
        $xmldataprev = "{\"start\":\"" . $startprev . "\",\"totalcount\":\"" . $maxcnt . "\",\"backupcount\":\"" . $h . "\",\"allstatus\":\"" . $allstatus1 . "\",\"onlygooglestatus\":\"" . $onlygooglestatus . "\"}" .'&@&'.$xmldata.'&@&'.$xmlappend;
        return $xmldataprev;
    }
    else if (((count($finalmixresults) - $crawlst) < 9) && (($status1 == 1) || ($status2 == 1) || ($status3 == 1) || ($status4 == 1)))
    {
        $i = 0;
        $h = count($urlcollection);
        if ($crawlst1 < $h)
        {
            $xmlappend .= "{\"source\":[";
            for ($i = $crawlst;$i < $h;$i++)
            {
                $statusarray[$i] = $finalmixresults[$i][5];
                if (($i >= $crawlst) && ($i <= $crawlst1))
                {
                    if ($i == $crawlst1)
                    {
                        $xmlappend .= "{\"sourcestatus\":\"" . $statusarray[$i] . "\"}";
                    }
                    else
                    {
                        $xmlappend .= "{\"sourcestatus\":\"" . $statusarray[$i] . "\"},";
                    }
                }
            }
            $xmlappend .= "]}";
        }
        else
        {
            $start = $h - $resultcount;
            if ($start < 0)
            {
                $start = 0;
                $xmlappend .= "{\"source\":[";
                for ($i = 0;$i < $h;$i++)
                {
                    $statusarray[$start] = $finalmixresults[$start][5];
                    if ($i == $h)
                    {
                        $xmlappend .= "{\"sourcestatus\":\"" . $statusarray[$start] . "\"}";
                    }
                    else
                    {
                        $xmlappend .= "{\"sourcestatus\":\"" . $statusarray[$start] . "\"},";
                    }
                    $start++;
                }
                $xmlappend .= "]}";
            }
            else
            {
                $xmlappend .= "{\"source\":[";
                for ($i = 0;$i < $resultcount;$i++)
                {
                    $statusarray[$start] = $finalmixresults[$start][5];
                    if ($i == $resultcount)
                    {
                        $xmlappend .= "{\"sourcestatus\":\"" . $statusarray[$start] . "\"}";
                    }
                    else
                    {
                        $xmlappend .= "{\"sourcestatus\":\"" . $statusarray[$start] . "\"},";
                    }
                    $start++;
                }
                $xmlappend .= "]}";
            }
        }
			if(($status1==0)&&($status2==0)&&($status3==0)&&($status4==0))
			{
				$allstatus1=0;
			}
			else
			{
				$allstatus1=1;
			}
        if ($newest != 1)
        {
            $xmldataprev = "{\"start\":\"" . $startprev . "\",\"totalcount\":\"" . $maxcnt . "\",\"backupcount\":\"" . $h . "\",\"allstatus\":\"" . $allstatus1 . "\",\"onlygooglestatus\":\"" . $onlygooglestatus . "\"}" .'&@&'.$xmldata.'&@&'.$xmlappend.'&@&'.$next.'&@&'.$prev;
             return $xmldataprev;
        }
        else
        {
            $xmldataprev = "{\"start\":\"" . $startprev . "\",\"totalcount\":\"" . $maxcnt . "\",\"backupcount\":\"" . $h . "\",\"allstatus\":\"" . $allstatus1 . "\",\"onlygooglestatus\":\"" . $onlygooglestatus . "\"}" .'&@&'.$xmldata.'&@&'.$xmlappend.'&@&'.$next.'&@&'.$prev;
            return $xmldataprev;
        }
    }
    else
    {
        $i = 0;
        $h = count($urlcollection);
        if ($crawlst1 < $h)
        {
            $xmlappend .= "{\"source\":[";
            for ($i = $crawlst;$i < $h;$i++)
            {
                $statusarray[$i] = $finalmixresults[$i][5];
                $jk = $h - 1;
                if ($i == $jk)
                {
                    $xmlappend .= "{\"sourcestatus\":\"" . $statusarray[$i] . "\"}";
                }
                else
                {
                    $xmlappend .= "{\"sourcestatus\":\"" . $statusarray[$i] . "\"},";
                }
            }
            $xmlappend .= "]}";
        }
        else
        {
            $start = $h - $resultcount;
            if ($start < 0)
            {
                $start = 0;
                $xmlappend .= "{\"source\":[";
                for ($i = 0;$i < $h;$i++)
                {
                    $statusarray[$start] = $finalmixresults[$start][5];
                    $jk = $h - 1;
                    if ($i == $jk)
                    {
                        $xmlappend .= "{\"sourcestatus\":\"" . $statusarray[$start] . "\"}";
                    }
                    else
                    {
                        $xmlappend .= "{\"sourcestatus\":\"" . $statusarray[$start] . "\"},";
                    }
                    $start++;
                }
                $xmlappend .= "]}";
            }
            else
            {
                $xmlappend .= "{\"source\":[";
                for ($i = 0;$i < $resultcount;$i++)
                {
                    $statusarray[$start] = $finalmixresults[$start][5];
                    if ($i == $resultcount)
                    {
                        $xmlappend .= "{\"sourcestatus\":\"" . $statusarray[$start] . "\"}";
                    }
                    else
                    {
                        $xmlappend .= "{\"sourcestatus\":\"" . $statusarray[$start] . "\"},";
                    }
                    $start++;
                }
                $xmlappend .= "]}";
            }
        }
        if (($status1 == 0) && ($status2 == 0) && ($status3 == 0) && ($status4 == 0))
        {
            $allstatus1 = 0;
        }
        else
        {
            $allstatus1 = 1;
        }
        $xmldataprev = "{\"start\":\"" . $startprev . "\",\"totalcount\":\"" . $maxcnt . "\",\"backupcount\":\"" . $h . "\",\"allstatus\":\"" . $allstatus1 . "\",\"onlygooglestatus\":\"" . $onlygooglestatus . "\"}" .'&@&'.$xmldata.'&@&'.$xmlappend.'&@&'.$next.'&@&'.$prev;
        return $xmldataprev;
    }
} 
	function widthandheight($img)
	{
		$db= new NesoteDALController();
		$size=getimagesize("photos/$img");
		$this->loadLibrary("Image");
		$width=$size[0];
		$height=$size[1];
		if(($height >= $width)&&($height > 100))
		{
			$width=($size[0]/$size[1])*100;
			echo "height"."="."100"." "."width"."=".$width;
		}
		else if(($width > $height)&&($width >100))
		{
			$height=($size[1]/$size[0])*100;
			echo "height"."=".$height." "."width"."="."100";
		}
		else
		{
			echo "height"."=".$size[1]." "."width"."=".$size[0];
		}
	}
	function disurl($url)
	{
		echo $url;
	}
	function webinstanceAction()
	{
		$valid=$this->uservalidation();
		$this->setValue("valid",$valid);
		$keyword=$_POST['search'];// reading search keyword
		$exactphrase=trim($_POST['exactphrase']);
		$searchdomain=trim($_POST['searchdomain']);
		$excludedword=trim($_POST['excludedword']);
		$excludeddomain=trim($_POST['excludeddomain']);
		$setkeyword="";
		if($exactphrase!="")
		{
			$setkeyword.=" \"$exactphrase\"" ;
		}
		if($searchdomain!="")
		{
			$setkeyword.=" site:".$searchdomain;
		}
		if($excludedword!="")
		{
			$setkeyword.=" -".$excludedword;
		}
		if($excludeddomain!="")
		{
			$setkeyword.=" -site:".$excludeddomain;
		}
		$quotestatus=get_magic_quotes_gpc();
		if($quotestatus==1)
		$keyword=stripslashes($keyword);
		$tabname=$_POST['type'];//    reading tab name
		$fl=$_POST['fl'];
		if((!isset($_POST['type']))||($_POST['type']==""))
		$tabname="web";
		if((!isset($_POST['search'])||($_POST['search']=="")))
		$keyword=str_replace("%2NNFF","/",$this->getParam(1));
		if(($setkeyword!="")&&($setkeyword!=" "))
		$keyword=$keyword.$setkeyword;
		$suggestion_keyword=$keyword;
		include('script.inc.php');
		include($config_path.'system.config.php');
		if($fl==1)
		$feelinglucky=1;
		$quotestatus=get_magic_quotes_gpc();
		if($quotestatus==1)
		$keyword=stripslashes($keyword);
		$keyword=str_replace('"',' " ',$keyword);
		$keyword=str_replace("'"," ' ",$keyword);
		$keyword=$this->familyfilter($keyword);
		$keyword=str_replace("' ","'",$keyword);
		$keyword=str_replace(" '","'",$keyword);
		$keyword=str_replace('" ','"',$keyword);
		$keyword=str_replace(' "','"',$keyword);
		$db= new NesoteDALController();
		$db->select("nesote_inoutse_engines");
		$db->fields("id,search_type");
		$db->where("tab_name=?",$tabname);
		$result=$db->query();
		$row=$db->fetchRow($result);
		$searchtype=$row[1];  // reading search type
		$engineid=$row[0];  // reading engine id
		$tot=$db->total("nesote_inoutse_engines","tab_name=? and status=?",array($tabname,1));
		if(($keyword=="")||($tot==0))
		{
			echo "no result1";exit;
		}
		$page=1;
		if(isset($_POST['startpage']))
		$page=$_POST['startpage'];   // reading page value
		if ($page=="")
		$page=1;
		$tabkeyword=str_replace("/","%2NNFF",$keyword);
		$this->setValue("keyword",$tabkeyword);
		$this->setValue("tabname",$tabname);
		$this->loadLibrary('Settings');
		$settings=new Settings('nesote_inoutse_settings');
		$settings->loadValues();
		$count=$settings->getValue("result_count");
		$relatedtag_count=$settings->getValue("related_tags_count");
		$styleid=$settings->getValue("result");
		$openin_newwindow=$settings->getValue("new_window");
		$emailafrnd=$settings->getValue("email_a_frnd");
		$quicklook=$settings->getValue("quicklook");
		$servicename=$settings->getValue("service_name");
		$member_status=$settings->getValue("member_status");
		$star_status=$settings->getValue("star_status");
		$this->setValue("star_status",$star_status);
		if($member_status==1)
		$comment_status=$settings->getValue("comment_status");
		else
		$comment_status=0;
		$moreimagearray=array("keyword"=>$keyword);
		$moreimage=$this->getmessagegrammer(26,$moreimagearray);
		$showimageresultsinweb=$settings->getValue("showimageresultsinweb");
		$thumbshot_user_override=$settings->getValue("thumbshot_user_override");
		$quicklook_user_override=$settings->getValue("quicklook_user_override");
		$rest_api_status=$settings->getValue("rest_api_search");
		$ad_codes=$settings->getValue("ad_codes");
		$message=array("servicename"=>$servicename);
		$home=$this->getmessagegrammer(47,$message,0);
		$enginename=$this->getenginename($engineid);
		define('PAGETITLE',$servicename." - ".$enginename." - ".$keyword);
		define('HEADERKEYWORD',$servicename.",search,search engine,".$keyword.",".$searchtype);
                $this->setValue('pagetitle',$servicename." - ".$enginename." - ".$keyword);
		$typearray=array("type"=>$enginename)	;
		$typesearch=$this->getmessagegrammer(23,$typearray);
		$xmldata=$this->getmixurlcontents($engineid,$searchtype,$page,$keyword,1);
		$cacheparts=explode("&@&",$xmldata);
		$cachepart1=$cacheparts[0];
		$cachepart2=$cacheparts[1];
		$cacheresult=json_decode($cachepart2);
		$cacheresultd = json_decode($cachepart1, true);
 		$start=$cacheresultd['start'];
 		$totalcount=$cacheresultd['totalcount'];
 		$backupcount=$cacheresultd['backupcount'];
 		$allstatus=$cacheresultd['allstatus'];
 		$onlygooglestatus=$cacheresultd['onlygooglestatus'];
        $stnum=$start;
        $source=$cacheparts[2];
		if($source!='')
		{
			$sourceresult=json_decode($source);
			foreach($sourceresult->source as $mydata)
		    {
		         $statusarray[1][].=$mydata->sourcestatus;
		    }
		}
		$totalhits=$totalcount;
		if($allstatus==0)
		{
			$total=$totalhits;
			$total1=$totalhits;
		}
		else
		{
			$onlygoogle=$onlygooglestatus;
			if($onlygoogle==1)
			{
				$total=$totalhits;
				$google_maxcount=$settings->getValue("google_totalfetchingcount");
				if($total>$google_maxcount)
				{
				   $total=$google_maxcount;
				}
			}
			else
			{
				$total=$totalhits;
			}
			$total1=$totalhits;
		}
		 $stnum=$start;
		$stnumber=$stnum;
		$this->setValue("totalhits",$total);
		$cacheresultcount=0;
		foreach($cacheresult->item as $mydata)
		{
			$cacheresultcount=$cacheresultcount+1;
		}
		if($cacheresultcount==0)
		{
			echo $this->testapi($keyword, $page, $tabname);
			exit;
		}
		$start=(10*($page-1))%$count;
		$startingnum=($page*10)-9;
		$endingnum=$page*10;
		if($total<$endingnum)
		$endingnum=$total;
		if($total<10)
		$startingnum=1;
		else
		$startingnum=($page*10)-9;
		$totalstring=number_format($total1);
		$message=array("startingnum"=>$startingnum,"endingnum"=>$endingnum,"total"=>$totalstring,"keyword"=>htmlentities($keyword,ENT_QUOTES,"UTF-8"));
		$style=array("resultcountstart","resultcountend","totalresults","keywordintotal");
		$totalstr=$this->getmessagegrammer(8,$message,$style);
		$keyword1=urlencode($keyword);
		$keywordsuggestion_status=$db->total("nesote_inoutse_engines","id=? and keyword_suggestion_status=1",array($engineid));
		if($page==1 && $keywordsuggestion_status!=0 && trim($suggestion_keyword)==trim($keyword))
		{
			$tot1=$db->total("nesote_inoutse_keywordsuggestions","engine_id=? and keyword=?",array($engineid,$suggestion_keyword));
			if($tot1==0)
			{
				$db->insert("nesote_inoutse_keywordsuggestions");
        		$db->fields("engine_id,keyword,total,searchcount,time");
        		$db->values(array($engineid,$suggestion_keyword,$total1,1,time()));
        		$db->query();
			}
			else
			{
				$db->update("nesote_inoutse_keywordsuggestions");
				$db->set("searchcount=searchcount+1,time=?,total=?",array(time(),$total1));
				$db->where("engine_id=? and keyword=?",array($engineid,$suggestion_keyword));
				$db->query();
			}
		}
		$previouspage=$page-1;
		if($page<=4)
		{
			$startpage=1;
			$endpage=5;
		}
		else
		{
			$startpage=$page-3;
			$endpage=$page+1;
		}
		$nextpage=$page+1;
		if($page!=1)
		{
		$footerlink.="<li class=\"pgntn-li float-left\"><a class=\"pgntn-a pgn-arw\" href=javascript:loadpage($previouspage)><i class=\"fas fa-chevron-left\"></i></a></li>";
		}
		for($i=$startpage;$i<=$endpage;$i++)
		{
			if($i*10<($total+10))
			{
				if($i!=$page)
				{
					$footerlink.="<li class=\"pgntn-li float-left\"><a class=\"pgntn-a pgn-cnt\" href=javascript:loadpage($i)>$i</a></li>";
				}
				else 
				{
					$footerlink.="<li class=\"pgntn-li float-left\"><a class=\"pgntn-a pgn-cnt pgn-actv\" href=javascript:loadpage($i)>$i</a></li>";
				}
			}
		}
		if($page*10<($total))
		{
		$footerlink.="<li class=\"pgntn-li float-left\"><a class=\"pgntn-a pgn-arw\" href=javascript:loadpage($nextpage)><i class=\"fas fa-chevron-right\"></i></a></li>";
		}
		$resultset=[];
foreach($cacheresult->item as $mydata)
    {
         $resultset[2][]=$mydata->titleurl;
    }
foreach($cacheresult->item as $mydata)
    {
         $resultset[1][]=base64_decode($mydata->title);
    }
foreach($cacheresult->item as $mydata)
    {
         $resultset[3][]=base64_decode($mydata->description);
    }
foreach($cacheresult->item as $mydata)
    {
         $resultset[4][]=$mydata->displayurl;
    }
		$finalresult2=$resultset;
		$finalresult=[];
		if(count($finalresult2)==0)
		{
			$keyword=urlencode($keyword);
			include('script.inc.php');
			include($config_path.'system.config.php');
			echo $this->testapi($keyword, $page, $tabname);
			exit;
		}
		$s=($page-1)*10-$stnumber; $u=0;
		$rescnt=$cacheresultcount;
		if($stnumber==0)
		{
			if($page<2)
			{
				if($priority_result_status==0)
				{
					$totcnt=10;
				}
				else if($priority_result_status==1)
				{
					$totcnt=10 + $priorityresultcount;
				}
			}
			else
			{
				if($priority_result_status==0)
				{
					$s=$s-$priorityresultcount;
				}
			}
		}
		if($page<2)
		{
			for($i=0;$i<$priorityresultcount;$i++)
			{
				$finalresult[$u][1]=$finalresultstemp[$i][1];
				$finalresult[$u][2]=$finalresultstemp[$i][2];
				$finalresult[$u][3]=$finalresultstemp[$i][3];
				$finalresult[$u][4]=$finalresultstemp[$i][4];
				$finalresult[$u][5]="0000";
				$finalresult[$u][6]=$this->getstar($finalresult[$u][4],$engineid);
				$u++;
			}
			for($i=$priorityresultcount;$i<$totcnt;$i++)
			{
				if($resultset[4][$s]!="")
				{
					$finalresult[$u][1]=$resultset[3][$s];                       
					if(strlen($finalresult[$u][1])>=150)
					{  $len=strlen($finalresult[$u][1]);
					$p=strpos($finalresult[$u][1]," ");
					if(($p=="")||($p>150))
					{  
						$fir=substr($finalresult[$u][1],0,150);
						$sec=substr($finalresult[$u][1],151,$len);
						$finalresult[$u][1]=$fir." ".$sec;
					}
					}
					$finalresult[$u][2]=$resultset[4][$s];
					if(strlen($finalresult[$u][2])>=60)                            
					$finalresult[$u][2]=substr($finalresult[$u][2],0,60)."...";
					$finalresult[$u][3]=$resultset[1][$s];                          
					if(strlen($finalresult[$u][3])>=100)
					$finalresult[$u][3]=substr($finalresult[$u][3],0,100)."...";
					$finalresult[$u][4]=$resultset[2][$s];                       
					$finalresult[$u][5]=$statusarray[1][$u];
					$finalresult[$u][6]=$this->getstar($finalresult[$u][4],$engineid);
					$u++;
				}
				$s=$s+1;
			}
		}
		else if($rescnt>=$s+10)
		{
			//echo "in2";exit;
			for($i=0;$i<10;$i++)
			{
				if($resultset[4][$s]!="")
				{
					$finalresult[$u][1]=$resultset[3][$s];                       
					if(strlen($finalresult[$u][1])>=150)
					{  $len=strlen($finalresult[$u][1]);
					$p=strpos($finalresult[$u][1]," ");
					if(($p=="")||($p>150))
					{   //echo "ghf";
						$fir=substr($finalresult[$u][1],0,150);
						$sec=substr($finalresult[$u][1],151,$len);
						$finalresult[$u][1]=$fir." ".$sec;
					}
					}
					$finalresult[$u][2]=$resultset[4][$s];
					if(strlen($finalresult[$u][2])>=60)                             
					$finalresult[$u][2]=substr($finalresult[$u][2],0,60)."...";
					$finalresult[$u][3]=$resultset[1][$s];                           
					if(strlen($finalresult[$u][3])>=100)
					$finalresult[$u][3]=substr($finalresult[$u][3],0,100)."...";
					$finalresult[$u][4]=$resultset[2][$s];                      
					$finalresult[$u][5]=$statusarray[1][$u];
					$finalresult[$u][6]=$this->getstar($finalresult[$u][4],$engineid);
					$u++;
				}
				$s=$s+1;
			}
		}
		else if($total-$startingnum+1>10)
		{
			//echo "in3";exit;
			$s= $rescnt-10;
			for($i=0;$i<10;$i++)
			{
				if($resultset[4][$s]!="")
				{
					$finalresult[$u][1]=$resultset[3][$s];
					if(strlen($finalresult[$u][1])>=150)
					{  $len=strlen($finalresult[$u][1]);
					$p=strpos($finalresult[$u][1]," ");
					if(($p=="")||($p>150))
					{   //echo "ghf";
						$fir=substr($finalresult[$u][1],0,150);
						$sec=substr($finalresult[$u][1],151,$len);
						$finalresult[$u][1]=$fir." ".$sec;
					}
					}
					$finalresult[$u][2]=$resultset[4][$s];
					if(strlen($finalresult[$u][2])>=60)                             
					$finalresult[$u][2]=substr($finalresult[$u][2],0,60)."...";
					$finalresult[$u][3]=$resultset[1][$s];                           
					if(strlen($finalresult[$u][3])>=100)
					$finalresult[$u][3]=substr($finalresult[$u][3],0,100)."...";
					$finalresult[$u][4]=$resultset[2][$s];
					$finalresult[$u][5]=$statusarray[1][$u];
					$finalresult[$u][6]=$this->getstar($finalresult[$u][4],$engineid);
					$u++;
				}
				$s=$s+1;
			}
		}
		else if($total-$startingnum+1>0)
		{
			//echo "in4";exit;
			$finish=$total-$startingnum+1;
			$statf=0;
			$s=0;
			for($i=0;$i<$finish;$i++)
			{
				if($resultset[4][$s]!="")
				{
					$finalresult[$u][1]=$resultset[3][$s];
					if(strlen($finalresult[$u][1])>=150)
					{  $len=strlen($finalresult[$u][1]);
					$p=strpos($finalresult[$u][1]," ");
					if(($p=="")||($p>150))
					{   
						$fir=substr($finalresult[$u][1],0,150);
						$sec=substr($finalresult[$u][1],151,$len);
						$finalresult[$u][1]=$fir." ".$sec;
					}
					}
					$finalresult[$u][2]=$resultset[4][$s];
					if(strlen($finalresult[$u][2])>=60)                            
					$finalresult[$u][2]=substr($finalresult[$u][2],0,60)."...";
					$finalresult[$u][3]=$resultset[1][$s];                          
					if(strlen($finalresult[$u][3])>=100)
					$finalresult[$u][3]=substr($finalresult[$u][3],0,100)."...";
					$finalresult[$u][4]=$resultset[2][$s];
					$finalresult[$u][5]=$statusarray[1][$statf];
					$finalresult[$u][6]=$this->getstar($finalresult[$u][4],$engineid);
					$u++; $statf++;
				}
				$s=$s+1;
			}
		}
		else
		{
			$keyword=urlencode($keyword);
			include('script.inc.php');
			include($config_path.'system.config.php');
			echo $this->testapi($keyword, $page, $tabname);
			exit;
		}
		if(($page==1)&&($feelinglucky==1))
		{
			header("Location:".strip_tags($finalresult[0][4]));
			exit(0);
		}
$finalcount=count($finalresult);
		for($i=0;$i<$finalcount;$i++)
		{
			$finalresult[$i][1]=$this->makebold($finalresult[$i][1],$keyword,1);
			$finalresult[$i][2]=$this->makebold($finalresult[$i][2],$keyword,0);
			$finalresult[$i][3]=$this->makebold($finalresult[$i][3],$keyword,0);
		}
		if($finalcount==0)
		{
			$keyword=urlencode($keyword);
			include('script.inc.php');
			include($config_path.'system.config.php');
			echo $this->testapi($keyword, $page, $tabname);
			exit;
		}
	
$str="";
	$str.='[&&]';$str.=$totalstr;$str.='[&&]';$str.=$typesearch;$str.='[&&]';
	$iplus=($page-1)*10;
		for($i=0;$i<$finalcount;$i++)
		{	$p1=$this->urlencode($finalresult[$i][4]);
			$p2=$this->getdomain($finalresult[$i][4]);
	$str.='';
                if(($thumbshotstatus==1) && ($thumshot_url!=""))	
                {	
                 if($finalresult[$i][5]=="0010")
                 {
                 }
                 else 
                 {
                 }
                }
                   else
                   {
                   }
$str.='<div class="float-left fullwidth my-2 rslt-out">
  <a class="wb-rslt-a" href="'.$finalresult[$i][4].'" target="_blank">
		<h3 class="wb-rslt-hd">'.$finalresult[$i][3].'</a></h3>&nbsp;';
		if($openin_newwindow==1){
$str.='<a target="_blank" href="'.$finalresult[$i][4].'"><i class="fas fa-external-link-alt fa_color" title="'.$this->getmessage(3).'"></i></a>';
}
					$str.='<!-- Ulitmate7 -->';
							if($valid==1)
							{
							if($star_status==1)	
							{				
							if($finalresult[$i][6]=="1")
							{
$str.='<a href="javascript:unclick(\''.$this->encode($finalresult[$i][1]).'\',\''.$iplus.'\',\''.$this->encode($finalresult[$i][3]).'\',\''.$this->encode($finalresult[$i][2]).'\',\''.$this->encode($finalresult[$i][4]).'\',\''.$engineid.'\')" ><span id="span1'.$iplus.'" style=" " class="add_favourites" title="'.$this->getmessage(640).'"><i class="fas fa-star" ></i></span></a>
<a href="javascript:click(\''.$this->encode($finalresult[$i][1]).'\',\''.$iplus.'\',\''.$this->encode($finalresult[$i][3]).'\',\''.$this->encode($finalresult[$i][2]).'\',\''.$this->encode($finalresult[$i][4]).'\',\''.$engineid.'\')" ><span id="span2'.$iplus.'" class="add_favourites" style="display: none;" title="'.$this->getmessage(640).'"> <i class="far fa-star"></i></span></a>';
							}
							if($finalresult[$i][6]=="0")
							{
$str.='<a href="javascript:click(\''.$this->encode($finalresult[$i][1]).'\',\''.$iplus.'\',\''.$this->encode($finalresult[$i][3]).'\',\''.$this->encode($finalresult[$i][2]).'\',\''.$this->encode($finalresult[$i][4]).'\',\''.$engineid.'\')" ><span id="span2'.$iplus.'" style="" class="add_favourites" title="'.$this->getmessage(641).'"> <i class="far fa-star"></i></span></a>
<a href="javascript:unclick(\''.$this->encode($finalresult[$i][1]).'\',\''.$iplus.'\',\''.$this->encode($finalresult[$i][3]).'\',\''.$this->encode($finalresult[$i][2]).'\',\''.$this->encode($finalresult[$i][4]).'\',\''.$engineid.'\')" > <span id="span1'.$iplus.'" class="add_favourites" style="display: none;" title="'.$this->getmessage(641).'"> <i class="far fa-star"></i></i></span></a>';
							}
							}}
$str.='<p class="wb-rslt-dmn"> '.$finalresult[$i][2].'</p>
		<div class="fullwidth float-left">
		<p class="wb-rslt-info"> '.$finalresult[$i][1].'</p>
		</div>';
				if($this->getalignment()==2)
                 {
                 } 
                      $str.='<div class="float-left ">'; 
                      if($emailafrnd==1)
                      {
$str.='<a class="rslt-lnk"><i class="fas fa-envelope rslt-lnk-ic" id="email_lnk"></i> Email Link</a>';
                      }
                      if($quicklook==1)
                      {
$str.='<span  id="qlook{loop:results}" class="rslt-lnk qk-look">  <i id="qlook_bti'.($iplus+1).'" class="fas fa-chevron-circle-right rslt-lnk-ic"></i> <a class="rslt-lnk qk-look"
							id="qlook_btn'.($iplus+1).'"
							href="javascript:qlook('.($iplus+1).',\''.$this->getmessage(39).'\',\''.$this->getmessage(41).'\',\''.$this->getmessage(40).'\')">'.$this->getmessage(39).'</a> </span> 
                     <span id="qlook_spn'.($iplus+1).'" style="display: none;"><i id="qlook_mmi'.($iplus+1).'" class="fas fa-plus-circle rslt-lnk-ic"></i>
                    &nbsp;<a class="rslt-lnk qk-look"
							id="qlook_mmb'.($iplus+1).'"
							href="javascript:qlookmm('.($iplus+1).',\''.$this->getmessage(41).'\',\''.$this->getmessage(43).'\')">'.$this->getmessage(41).'</a>
						<span id="qlook_mms'.($iplus+1).'"></span><i class="fa fa-home rslt-lnk-ic" aria-hidden="true"></i>
</i>&nbsp;<a
							class="qlook rslt-lnk qk-look " id="qlook_ghb'.($iplus+1).'"
							href="javascript:qlookgh('.($iplus+1).')">'.$this->getmessage(42).'</a>
						</span>';
                      }
						$str.='<!-- Ulitmate7 -->';							
					if($comment_status==1)
					{
$str.='<a class="rslt-lnk rslt-cmnt  cmnt_new_'.$iplus.'" href="javascript:comment(\''.$iplus.'\')"><i class="fas fa-comments rslt-lnk-ic"></i> '.$this->getmessage(579).'&nbsp;(<span id="comcount'.$iplus.'">'.$this->getcmntcount($finalresult[$i][4]).'</span>)</a>';
					}
$str.='</div>';
// suraaj start 
$str.='<a class="rslt-lnk" id="orisumm_'.($iplus+1).'" onclick="javascript:newopenaiindi(\''.$finalresult[$i][4].'\','.($iplus+1).');"><i class="fas fa-comment rslt-lnk-ic"></i>Ask AI to Summarise <span style="background: #F74343;color: #fff;font-size: 10px;position: relative;padding: 0px 3px;border-radius: 3px;margin-left: 4px;top: -1px;">New</span></a>';
$str.='<a class="rslt-lnk" id="dupsumm_'.($iplus+1).'" style="display:none;" onclick="closeai('.($iplus+1).');"><i class="fas fa-comment rslt-lnk-ic"></i>Close AI Summary</a>';

$str.='<div class="web-ai-rslt fullwidth float-left" id="resultmodeloop_'.($iplus+1).'" style="display:none;">
	<h4>AI Result Summary</h4>
	
</div>';
$str.='<iframe style="display:none;" id="myIframe6_'.($iplus+1).'" frameborder="0" marginwidth="0" marginheight="0"  width="100%"></iframe>';


//suraaj end
$str.='<div class="rslt-cmnt-drp" id="cmnt-drp_'.$iplus.'">
<input type="hidden" name="urlenc'.$iplus.'" id="urlenc'.$iplus.'" value="'.urlencode($finalresult[$i][4]).'">
<div class="drp-cmnt-area fullwidth"  id="div'.$iplus.'">';
$str.=$this->getcommentsnw($finalresult[$i][4],$results,"web");
$str.='</div>';
	if($valid!=1)	{
$str.='&nbsp;<span style="color: #686868;font-style: italic;">'.$this->getmessage(608).'</span>';
}else{
$str.='<input type="hidden" name="url" id="url'.$iplus.'" value="'.$finalresult[$i][4].'">';
$str.='<label class="radio-cstm">'.$this->getmessage(581).'
  <input type="radio" name="type" id="type2'.$iplus.'" value="title">
  <span class="checkmark"></span>
</label>
<label class="radio-cstm">'.$this->getmessage(587).'
  <input type="radio" name="type" id="type1'.$iplus.'" value="domain">
  <span class="checkmark"></span>
</label>';
$str.='<textarea class="rslt-cmnt-area" placeholder="Enter Your Comments." type="text" id="comment'.$iplus.'"></textarea>
<span class=" cmt_error_msg" id="cmterror'.$iplus.'"></span>
<button class="float-right rslt-cmnt-btn" onclick="postcomment('.$iplus.')" type="button">Send</button>';
}
$str.='</div>
</div>
<div class="rslt-cmnt-drp notlogin" id="cmnt-drp_nlog_'.$iplus.'">
<textarea class="rslt-cmnt-area" placeholder="'.$this->getmessage(608).'" type="text"></textarea>
</div>';
                if($quicklook==1)
                {
				$str.='<span id="qlookframe'.($iplus).'" style="'.$this->getqlookdisplaystatus().'" width="100%">
						<iframe class="qickfrmeifrmae" id="qlook_fra'.($iplus+1).'" src="" src1="'.$finalresult[$i][4].'"
							loaded="0" width="99%" height="300" scrolling="auto"
							style="display: none; margin-top: 3px;"></iframe>
						<div align="center" id="qlook_lsi'.($iplus+1).'"
							style="display: none; margin: 0;" width="100%"><img
							src="images/qlook/q_l10.gif" alt="Loading..." width="239"
							height="20" style="margin-top: 20px; margin-bottom: 250px;" /></div>
						</span>';
                }	
			$iplus=$iplus+1;	
		}
$str.='</div>';
		$str .='[&&]'.$footerlink;
		echo $str;
	    exit;
	}
	function imageinstanceAction()
	{
		$valid=$this->uservalidation();
		$this->setValue("valid",$valid);
		$keyword=$_POST['search'];// reading search keyword
		$quotestatus=get_magic_quotes_gpc();
		if($quotestatus==1)
		$keyword=stripslashes($keyword);
		$tabname=$_POST['type'];//    reading tab name
		$fl=$_POST['fl'];
		if((!isset($_POST['type']))||($_POST['type']==""))
		$tabname="images";
		if((!isset($_POST['search'])||($_POST['search']=="") ))
		$keyword=str_replace("%2NNFF","/",$this->getParam(2));
		$suggestion_keyword=$keyword;
		include('script.inc.php');
		include($config_path.'system.config.php');
		if($fl==1)
		$feelinglucky=1;
		$quotestatus=get_magic_quotes_gpc();
		if($quotestatus==1)
		$keyword=stripslashes($keyword);
		$keyword=str_replace('"',' " ',$keyword);
		$keyword=str_replace("'"," ' ",$keyword);
		$keyword=$this->familyfilter($keyword);
		$keyword=str_replace("' ","'",$keyword);
		$keyword=str_replace(" '","'",$keyword);
		$keyword=str_replace('" ','"',$keyword);
		$keyword=str_replace(' "','"',$keyword);
		$settings=new Settings('nesote_inoutse_settings');
		$settings->loadValues();
		$count=$settings->getValue("image_result_count");
		$lightbox=$settings->getValue("lightbox");
		$styleid=$settings->getValue("result");
		$servicename=$settings->getValue("service_name");
		$rest_api_status=$settings->getValue("rest_api_search");
		$source_status=$settings->getValue("source_status");
		$relatedtag_count=$settings->getValue("related_tags_count");
		$seasonal_logo_status=$settings->getValue("seasonal_logo");
		$star_status=$settings->getValue("star_status");
		$member_status=$settings->getValue("member_status");
		if($member_status==1)
		$comment_status=$settings->getValue("comment_status");
		else
		$comment_status=0;
		$db=new NesoteDALController();
		$db->select("nesote_inoutse_engines");
		$db->fields("id,search_type");
		$db->where("tab_name=?",$tabname);
		$result=$db->query();
		$row=$db->fetchRow($result);
		$searchtype=$row[1];  
		$engineid=$row[0]; 
		$db= new NesoteDALController();
		$tot=$db->total("nesote_inoutse_engines","tab_name=? and status=?",array($tabname,1));
		if(($keyword=="")||($tot==0))
		{
			echo "no result";exit;
		}
		$page=1;
		if(isset($_POST['startpage']))
		$page=$_POST['startpage']; 
		if ($page=="")
		$page=1;
		$tabkeyword=str_replace("/","%2NNFF",$keyword);
		$this->setValue("keyword",$tabkeyword);
		$this->setValue("tabname",$tabname);
		$xmldata=$this->getmixurlcontents($engineid,$searchtype,$page,$keyword,1);
		$cacheparts=explode("&@&",$xmldata);
		$cachepart1=$cacheparts[0];
		$cachepart2=$cacheparts[1];
		$source=$cacheparts[2];
		if($source!='')
		{
			$sourceresult=json_decode($source);
			foreach($sourceresult->source as $mydata)
		    {
		         $statusarray[1][].=$mydata->sourcestatus;
		    }
		}
		$cacheresult=json_decode($cachepart2);
		$cacheresultd = json_decode($cachepart1, true);
 		$start=$cacheresultd['start'];
 		$totalcount=$cacheresultd['totalcount'];
 		$backupcount=$cacheresultd['backupcount'];
 		$allstatus=$cacheresultd['allstatus'];
 		$onlygooglestatus=$cacheresultd['onlygooglestatus'];
		$style="";
		$this->setValue("style",$style);
		$resultflag=true;
		$xmldata=str_replace("\r\n","",$xmldata);
		$xmldata=str_replace("\n","",$xmldata);
		$xmldata=str_replace("\r","",$xmldata);
		if($xmldata=="expired")
		{
		$resultflag=false;
		}
		else 
		{
		$totalhits=$totalcount;
		if($allstatus==0)
		{
			$total=$backupcount;
			$total1=$totalhits;
		}
		else
		{
			$onlygoogle=$onlygooglestatus;
			if($onlygoogle==1)
			{
				$total=$totalhits;
				$google_maxcount=$settings->getValue("google_totalfetchingcount");
				if($total>$google_maxcount)
				{
				   $total=$google_maxcount;
				}
			}
			else
			{
				$total=$totalhits;
			}
			$total1=$totalhits;
		}
        $stnum=$start;
		$stnumber=$stnum;
		$this->setValue("totalhits",$total);
		$cacheresultcount=0;
		foreach($cacheresult->item as $mydata)
		{
			$cacheresultcount=$cacheresultcount+1;
		}
		if($cacheresultcount==0)
		{
            $resultflag=false;
		}
		else
		{
		$message=array("servicename"=>$servicename);
		$home=$this->getmessagegrammer(47,$message,0);
		$this->setValue("home",$home);
		$this->setValue("engineid",$engineid);
		$enginename=$this->getenginename($engineid);
		define('PAGETITLE',$servicename." - ".$enginename." - ".$keyword);
                $this->setValue('pagetitle',$servicename." - ".$enginename." - ".$keyword);
		define('HEADERKEYWORD',$servicename.",search,search engine,".$keyword.",".$searchtype);
		$typearray=array("type"=>$enginename);
		$typesearch=$this->getmessagegrammer(23,$typearray);
		$this->setValue("typesearch",$typesearch);
		$style="";
		$this->setValue("style",$style);
		$start=(15*($page-1))%$count;
		$startingnum=($page*15)-14;
		$endingnum=$page*15;
		if($total<$endingnum)
		$endingnum=$total;
		if($total<15)
		$startingnum=1;
		else
		$startingnum=($page*15)-14;
		$totalstring=number_format($total1);
		$message=array("startingnum"=>$startingnum,"endingnum"=>$endingnum,"total"=>$totalstring,"keyword"=>htmlentities($keyword,ENT_QUOTES,"UTF-8"));
		$style=array("resultcountstart","resultcountend","totalresults","keywordintotal");
		$totalstr=$this->getmessagegrammer(8,$message,$style);
		$keyword1=urlencode($keyword);
		$keywordsuggestion_status=$db->total("nesote_inoutse_engines","id=? and keyword_suggestion_status=1",array($engineid));
		if($page==1 && $keywordsuggestion_status!=0 && trim($suggestion_keyword)==trim($keyword))
		{
			$tot1=$db->total("nesote_inoutse_keywordsuggestions","engine_id=? and keyword=?",array($engineid,$suggestion_keyword));
			if($tot1==0)
			{
				$db->insert("nesote_inoutse_keywordsuggestions");
        		$db->fields("engine_id,keyword,total,searchcount,time");
        		$db->values(array($engineid,$suggestion_keyword,$total1,1,time()));
        		$db->query();
			}
			else
			{
				$db->update("nesote_inoutse_keywordsuggestions");
				$db->set("searchcount=searchcount+1,time=?,total=?",array(time(),$total1));
				$db->where("engine_id=? and keyword=?",array($engineid,$suggestion_keyword));
				$db->query();
			}
		}
	$previouspage=$page-1;
	if($page<=4)
		{
			$startpage=1;
			$endpage=5;
		}
		else
		{
			$startpage=$page-3;
			$endpage=$page+1;
		}
		$nextpage=$page+1;
		if($page!=1)
		{
		$footerlink.="<li class=\"pgntn-li float-left\"><a class=\"pgntn-a pgn-arw\" href=javascript:loadpage($previouspage)><i class=\"fas fa-chevron-left\"></i></a></li>";
		}
		for($i=$startpage;$i<=$endpage;$i++)
		{
			if($i*15<($total+15))
			{
				if($i!=$page)
				{
					$footerlink.="<li class=\"pgntn-li float-left\"><a class=\"pgntn-a pgn-cnt\" href=javascript:loadpage($i)>$i</a></li>";
				}
				else 
				{
					$footerlink.="<li class=\"pgntn-li float-left\"><a class=\"pgntn-a pgn-cnt pgn-actv\" href=javascript:loadpage($i)>$i</a></li>";
				}
			}
		}
		if($page*10<($total))
		{
		$footerlink.="<li class=\"pgntn-li float-left\"><a class=\"pgntn-a pgn-arw\" href=javascript:loadpage($nextpage)><i class=\"fas fa-chevron-right\"></i></a></li>";
		}
		$relatedkeywords=$this->getrelatedkeyword($keyword);
		$finalkeywordarray=[];
		for($i=0;$i<$relatedtag_count;$i++)
		{
			$finalkeywordarray[$i][0]=$relatedkeywords[$i];
		}
		if($finalkeywordarray[0][0]!="")
		$this->setValue("keywordstatus",1);
		else
		$this->setValue("keywordstatus",0);
		$this->setLoopValue("relatedkeywords",$finalkeywordarray);
		$j=0;
		$resultset=[];
foreach($cacheresult->item as $mydata)
    {
         $resultset[1][]=$mydata->type;
    }
foreach($cacheresult->item as $mydata)
    {
         $resultset[2][]=$mydata->width;
    }
foreach($cacheresult->item as $mydata)
    {
         $resultset[3][]=$mydata->imagelocation;
    }
    foreach($cacheresult->item as $mydata)
    {
         $resultset[4][]=$mydata->filesize;
    }
    foreach($cacheresult->item as $mydata)
    {
         $resultset[5][]=$mydata->thumburl;
    }
    foreach($cacheresult->item as $mydata)
    {
         $resultset[6][]=$mydata->title;
    }
    foreach($cacheresult->item as $mydata)
    {
         $resultset[7][]=$mydata->visibleurl;
    }
	foreach($cacheresult->item as $mydata)
    {
         $resultset[8][]=$mydata->height;
    }
	foreach($cacheresult->item as $mydata)
    {
         $resultset[9][]=$mydata->url;
    }
//print_r($resultset);
//exit;
		$finalresult2=$resultset;
		if($cacheresultcount==0)
		{
			$resultflag=false;
		}
        else
        {
		$s=($page-1)*15-$stnumber; $u=0;
		$rescnt=count($resultset[1]);
		if($rescnt>=$s+15)
		{
			for($i=0;$i<15;$i++)
			{
				if($resultset[4][$s]!="")
				{
					$finalresult[$u][1]=$resultset[1][$s];
					$finalresult[$u][2]=$resultset[2][$s];
					$finalresult[$u][3]=$resultset[3][$s];
					$finalresult[$u][4]=$resultset[4][$s];
					$finalresult[$u][5]=$resultset[5][$s];
					$finalresult[$u][6]=$resultset[6][$s];                           
					if(strlen($finalresult[$u][6])>=100)
					$finalresult[$u][6]=substr($finalresult[$u][6],0,100)."...";
					$finalresult[$u][7]=$resultset[7][$s];                           
					if(strlen($finalresult[$u][7])>=60)
					$finalresult[$u][7]=substr($finalresult[$u][7],0,60)."...";
					$finalresult[$u][8]=$resultset[8][$s];
					$finalresult[$u][9]=$resultset[9][$s];
					$finalresult[$u][10]=$statusarray[1][$u];
					$finalresult[$u][11]=$this->getstar($finalresult[$u][3],$engineid);
					$u++;
				}
				$s=$s+1;
			}
		}
		else if($total-$startingnum+1>15)
		{
			$s= $rescnt-15;
			for($i=0;$i<15;$i++)
			{
				if($resultset[4][$s]!="")
				{
					$finalresult[$u][1]=$resultset[1][$s];
					$finalresult[$u][2]=$resultset[2][$s];
					$finalresult[$u][3]=$resultset[3][$s];
					$finalresult[$u][4]=$resultset[4][$s];
					$finalresult[$u][5]=$resultset[5][$s];
					$finalresult[$u][6]=$resultset[6][$s];                           
					if(strlen($finalresult[$u][6])>=100)
					$finalresult[$u][6]=substr($finalresult[$u][6],0,100)."...";
					$finalresult[$u][7]=$resultset[7][$s];                           
					if(strlen($finalresult[$u][7])>=60)
					$finalresult[$u][7]=substr($finalresult[$u][7],0,60)."...";
					$finalresult[$u][8]=$resultset[8][$s];
					$finalresult[$u][9]=$resultset[9][$s];
					$finalresult[$u][10]=$statusarray[1][$u];
					$finalresult[$u][11]=$this->getstar($finalresult[$u][3],$engineid);
					$u++;
				}
				$s=$s+1;
			}
		}
		else if($total-$startingnum+1>0)
		{
			$finish=$total-$startingnum+1;
			$statf=0;
			$s=0;
			for($i=0;$i<$finish;$i++)
			{
				if($resultset[4][$s]!="")
				{
					$finalresult[$u][1]=$resultset[1][$s];
					$finalresult[$u][2]=$resultset[2][$s];
					$finalresult[$u][3]=$resultset[3][$s];
					$finalresult[$u][4]=$resultset[4][$s];
					$finalresult[$u][5]=$resultset[5][$s];
					$finalresult[$u][6]=$resultset[6][$s];                          
					if(strlen($finalresult[$u][6])>=100)
					$finalresult[$u][6]=substr($finalresult[$u][6],0,100)."...";
					$finalresult[$u][7]=$resultset[7][$s];                          
					if(strlen($finalresult[$u][7])>=60)
					$finalresult[$u][7]=substr($finalresult[$u][7],0,60)."...";
					$finalresult[$u][8]=$resultset[8][$s];
					$finalresult[$u][9]=$resultset[9][$s];
					$finalresult[$u][10]=$statusarray[1][$statf];
					$finalresult[$u][11]=$this->getstar($finalresult[$u][3],$engineid);
					$u++; $statf++;
				}
				$s=$s+1;
			}
		}
		else
		{
			$resultflag=false;
		}
		if(($page==1)&&($feelinglucky==1))
		{
			header("Location:".strip_tags($finalresult[0][3]));
			exit(0);
		}
$finalcount=count($finalresult);
		for($i=0;$i<$finalcount;$i++)
		{
			$finalresult[$i][7]=html_entity_decode($this->makebold($finalresult[$i][7],$keyword,0));
		}
		if($finalcount==0)
		{
			$resultflag=false;
		}
        }
		}
        }
	if($resultflag==false)
		{
			$typearray=array("type"=>$enginename);
		$typesearch=$this->getmessagegrammer(23,$typearray);
		$this->setValue("typesearch",$typesearch);
			$this->setValue("comment_status",0);
		list($finalresult,$total) = $this->testapiimagesdataAction($keyword, $page);
		$start=(15*($page-1))%$count;
		$startingnum=($page*15)-14;
		$endingnum=$page*15;
		if($total<$endingnum)
		$endingnum=$total;
		if($total<15)
		$startingnum=1;
		else
		$startingnum=($page*15)-14;
		$totalstring=number_format($total1);
		$message=array("startingnum"=>$startingnum,"endingnum"=>$endingnum,"total"=>$total,"keyword"=>htmlentities($keyword,ENT_QUOTES,"UTF-8"));
		$style=array("resultcountstart","resultcountend","totalresults","keywordintotal");
		$totalstr=$this->getmessagegrammer(8,$message,$style);
		$this->setValue("total",$totalstr);
			$previouspage=$page-1;
		if($page<=4)
		{
			$startpage=1;
			$endpage=7;
		}
		else
		{
			$startpage=$page-3;
			$endpage=$page+3;
		}
		$nextpage=$page+1;
		if($page!=1)
		{
		$footerlink.="<li class=\"pgntn-li float-left\"><a class=\"pgntn-a pgn-arw\" href=javascript:loadpage($previouspage)><i class=\"fas fa-chevron-left\"></i></a></li>";
		}
		for($i=$startpage;$i<=$endpage;$i++)
		{
		if($i*15<($total+15))
			{
				if($i!=$page)
				{
					$footerlink.="<li class=\"pgntn-li float-left\"><a class=\"pgntn-a pgn-cnt\" href=javascript:loadpage($i)>$i</a></li>";
				}
				else 
				{
					$footerlink.="<li class=\"pgntn-li float-left\"><a class=\"pgntn-a pgn-cnt pgn-actv\" href=javascript:loadpage($i)>$i</a></li>";
				}
			}
		}
			if($page*15<($total))
		{
		$footerlink.="<li class=\"pgntn-li float-left\"><a class=\"pgntn-a pgn-arw\" href=javascript:loadpage($nextpage)><i class=\"fas fa-chevron-right\"></i></a></li>";
		}
		$this->setValue("footerlink",$footerlink);
		}
		$finalcount=count($finalresult);
		$str="";
	$str.='[&&]';$str.=$totalstr;$str.='[&&]';$str.=$typesearch;$str.='[&&]';
	$iplus=($page-1)*15;
	for($i=0;$i<$finalcount;$i++)
		{
 $str.='<div class="grid-item">
  <a href="javascript:imageclick('.$iplus.')"  class="" id="'.$iplus.'">
<div class="grd-out">
  <div class="grid-inner float-left">
  <img src="'.$finalresult[$i][5].'" style="width:100%" alt="'.$this->gettitle($finalresult[$i][6],$keyword).'"">
 <a target="_blank" href="'.$finalresult[$i][3].'"> <p class="float-left fullwidth rslt-img-cont text-black">'.$this->gettitle($finalresult[$i][6],$keyword).'</p>
  <p class="float-left fullwidth rslt-img-link">'.$this->disurl($finalresult[$i][7]).'</p></a>';
		if($valid==1)
			{ 
				if($star_status==1)
				{
							if($finalresult[$i][11]=="1")
							{
$str.='<a href="javascript:unclick(\''.$this->encode($finalresult[$i][5]).'\',\''.$iplus.'\',\''.$this->encode($finalresult[$i][6]).'\',\''.$this->encode($finalresult[$i][7]).'\',\''.$this->encode($finalresult[$i][3]).'\',\''.$engineid.'\',\''.$finalresult[$i][2].'x'.$finalresult[$i][8].':'.$finalresult[$i][4].':'.$finalresult[$i][1].'\',\''.$this->encode($finalresult[$i][9]).'\')" ><span id="span1'.$iplus.'" class="add_favourites add_fav_images" title="'.$this->getmessage(640).'"><i class="fas fa-star" ></i></span></a>
<a href="javascript:click(\''.$this->encode($finalresult[$i][5]).'\',\''.$iplus.'\',\''.$this->encode($finalresult[$i][6]).'\',\''.$this->encode($finalresult[$i][7]).'\',\''.$this->encode($finalresult[$i][3]).'\',\''.$engineid.'\',\''.$finalresult[$i][2].'x'.$finalresult[$i][8].':'.$finalresult[$i][4].':'.$finalresult[$i][1].'\',\''.$this->encode($finalresult[$i][9]).'\')" ><span id="span2'.$iplus.'" class="add_favourites add_fav_images" style="display: none;" title="'.$this->getmessage(640).'"> <i class="far fa-star" ></i></span></a>';
							}
							if($finalresult[$i][11]=="0")
							{
$str.='<a href="javascript:click(\''.$this->encode($finalresult[$i][5]).'\',\''.$iplus.'\',\''.$this->encode($finalresult[$i][6]).'\',\''.$this->encode($finalresult[$i][7]).'\',\''.$this->encode($finalresult[$i][3]).'\',\''.$engineid.'\',\''.$finalresult[$i][2].'x'.$finalresult[$i][8].':'.$finalresult[$i][4].':'.$finalresult[$i][1].'\',\''.$this->encode($finalresult[$i][9]).'\')" ><span id="span2'.$iplus.'" class="add_favourites add_fav_images"  title="'.$this->getmessage(641).'"> <i class="far fa-star"></i></span></a>
<a href="javascript:unclick(\''.$this->encode($finalresult[$i][5]).'\',\''.$iplus.'\',\''.$this->encode($finalresult[$i][6]).'\',\''.$this->encode($finalresult[$i][7]).'\',\''.$this->encode($finalresult[$i][3]).'\',\''.$engineid.'\',\''.$finalresult[$i][2].'x'.$finalresult[$i][8].':'.$finalresult[$i][4].':'.$finalresult[$i][1].'\',\''.$this->encode($finalresult[$i][9]).'\')" ><span id="span1'.$iplus.'" class="add_favourites add_fav_images" style="display: none;"title="'.$this->getmessage(641).'"> <i class="far fa-star"></i></i> </span></a>';
}
					} 
			}
$str.='</div>
  </div></div>';
$str.='<div class="image-pop" id="image_de_popup'.$iplus.'" style="display:none;">
    <div class="main-container rs-pd" >
	    <div class="image-pop-lt">
		<div class=" pop-img-div">
		    <img src="'.$finalresult[$i][5].'" alt="image preview" class="pop-img"> 
			</div>
		</div>
	    <div class="image-pop-rt">
		    <div class="pop-cnt">
			<div class="fullwidth pop-txt mb-2">
		   <h4 class="pop-img-head">'.$this->gettitle($finalresult[$i][6],$keyword).'</h4>
				<p class="pop-img-p">'.$this->disurl($finalresult[$i][7]).'</p>
				<a class="pop-link" href="'.$finalresult[$i][3].'">Visit Site</a>
				'.$this->getpreviewlink($finalresult[$i][9],$finalresult[$i][2],$finalresult[$i][8]).'
				</div>
				<div class="fullwidth pop-txt">
			    <h4 class="pop-cmt">Comments&nbsp;(<span id="comcount'.$iplus.'">'.$this->getcmntcount($finalresult[$i][3]).'</span>)</h4>
				<div class="rslt-cmnt-drp img-cmnt-outr">
		<div>
<input type="hidden" name="url" id="url'.$iplus.'" value="'.$finalresult[$i][3].'">
<label class="radio-cstm radio-cstm-img">'.$this->getmessage(581).'
  <input type="radio" name="type" id="type2'.$iplus.'" value="title">
  <span class="checkmark checkmark-img"></span>
</label>
<label class="radio-cstm radio-cstm-img">'.$this->getmessage(587).'
  <input type="radio" name="type" id="type1'.$iplus.'" value="domain">
  <span class="checkmark checkmark-img"></span>
</label>
</div>
		<div class="drp-cmnt-area img-cmnt-ht fullwidth" id="oldercomments'.$iplus.'">
		<div class="cmnt-drp-outer">
'.$this->getcommentsnw_images($finalresult[$i][3]).'
</div>
</div>';
if($valid!=1){
$str.='&nbsp;<span style="color: #686868;font-style: italic;"><br>'.$this->getmessage(608).'</span>';
}else{
		$str.='<textarea class="rslt-cmnt-area img-cmnt-area" id="comment'.$iplus.'" placeholder="Enter Your Comments" type="text"></textarea>
<span class=" cmt_error_msg" id="cmterror'.$iplus.'"></span>
		<button class="float-right rslt-cmnt-btn" type="button" onclick="postcomment('.$iplus.')">Send</button>';
}
		$str.='</div>
				</div>
			</div>
		</div>
		<div class="close-img-bt" onclick="javascript:closeimage();" id="'.$iplus.'"><img class="cls-ic"  src="images/close-ic.png" alt="close"></div>
    </div>
</div>';
                      $str.='  </div>
                      </div>
                    </div>
                  </div>
                </div>
					';
		$iplus=$iplus+1;
		}
		$str .='[&&]'.$footerlink;
		echo "str=$str";
	    exit;
	}
	function newsinstanceAction()
	{
		$valid=$this->uservalidation();
		$this->setValue("valid",$valid);
		$keyword=$_POST['search'];
		$quotestatus=get_magic_quotes_gpc();
		if($quotestatus==1)
		$keyword=stripslashes($keyword);
		$tabname=$_POST['type'];
		$fl=$_POST['fl'];
		if((!isset($_POST['type']))||($_POST['type']==""))
		$tabname="news";
		if((!isset($_POST['search'])||($_POST['search']=="")))
		$keyword=str_replace("%2NNFF","/",$this->POSTParam(1));
		$suggestion_keyword=$keyword;
		include('script.inc.php');
		include($config_path.'system.config.php');
		if($fl==1)
		$feelinglucky=1;
		$quotestatus=get_magic_quotes_gpc();
		if($quotestatus==1)
		$keyword=stripslashes($keyword);
		$keyword=str_replace('"',' " ',$keyword);
		$keyword=str_replace("'"," ' ",$keyword);
		$keyword=$this->familyfilter($keyword);
		$keyword=str_replace("' ","'",$keyword);
		$keyword=str_replace(" '","'",$keyword);
		$keyword=str_replace('" ','"',$keyword);
		$keyword=str_replace(' "','"',$keyword);
		$db= new NesoteDALController();
		$db->select("nesote_inoutse_engines");
		$db->fields("id,search_type");
		$db->where("tab_name=?",$tabname);
		$result=$db->query();
		$row=$db->fetchRow($result);
		$searchtype=$row[1];  
		$engineid=$row[0];  
		$db= new NesoteDALController();
		$tot=$db->total("nesote_inoutse_engines","tab_name=? and status=?",array($tabname,1));
		if(($keyword=="")||($tot==0))
		{
			echo "no result";exit;
		}
		$page=1;
		if(isset($_POST['startpage']))
		$page=$_POST['startpage'];   
		if ($page=="")
		$page=1;
		$tabkeyword=str_replace("/","%2NNFF",$keyword);
		$this->loadLibrary('Settings');
		$settings=new Settings('nesote_inoutse_settings');
		$settings->loadValues();
		$count=$settings->getValue("result_count");
		$styleid=$settings->getValue("result");
		$thumbshotstatus=$settings->getValue("thumbshot");
		if($_COOKIE['thumbshot']=="off")
		$thumbshotstatus=0;
				$thumshot_api=$settings->getValue("thumshot_url");		
		$thumshot_url="http://images.thumbshots.com/image.aspx?cid=$thumshot_api&v=1&w=120px&url=";
		$openin_newwindow=$settings->getValue("new_window");
		$emailafrnd=$settings->getValue("email_a_frnd");
		$quicklook=$settings->getValue("quicklook");
		$servicename=$settings->getValue("service_name");
		$ad_codes=$settings->getValue("ad_codes");
		$this->setValue("ad_codes",$ad_codes);
		$relatedtag_count=$settings->getValue("related_tags_count");
		$seasonal_logo_status=$settings->getValue("seasonal_logo");
		$star_status=$settings->getValue("star_status");
		$member_status=$settings->getValue("member_status");
		if($member_status==1)
		$comment_status=$settings->getValue("comment_status");
		else
		$comment_status=0;
		$rest_api_status=$settings->getValue("rest_api_search");
		$xmldata=$this->getmixurlcontents($engineid,$searchtype,$page,$keyword,1);
		$cacheparts=explode("&@&",$xmldata);
		$cachepart1=$cacheparts[0];
		$cachepart2=$cacheparts[1];
$cacheresult=json_decode($cachepart2);
$source=$cacheparts[2];
		if($source!='')
		{
			$sourceresult=json_decode($source);
			foreach($sourceresult->source as $mydata)
		    {
		         $statusarray[1][].=$mydata->sourcestatus;
		    }
		}
		$cacheresultd = json_decode($cachepart1, true);
 		$start=$cacheresultd['start'];
 		$totalcount=$cacheresultd['totalcount'];
 		$backupcount=$cacheresultd['backupcount'];
 		$allstatus=$cacheresultd['allstatus'];
 		$onlygooglestatus=$cacheresultd['onlygooglestatus'];
		$xmldata=str_replace("\r\n","",$xmldata);
		$xmldata=str_replace("\n","",$xmldata);
		$xmldata=str_replace("\r","",$xmldata);
		if($xmldata=="expired")
		{
			echo $this->testapi($keyword, $page, $tabname);
			exit;
		}
		$totalhits=$totalcount;
		if($allstatus==0)
		{
			$total=$backupcount;
			$total1=$totalhits;
		}
		else
		{
			$onlygoogle=$onlygooglestatus;
			if($onlygoogle==1)
			{
				$total=$totalhits;
				$google_maxcount=$settings->getValue("google_totalfetchingcount");
				if($total>$google_maxcount)
				{
				   $total=$google_maxcount;
				}
			}
			else
			{
				$total=$totalhits;
			}
			$total1=$totalhits;
		}
        $stnum=$start;
		$stnumber=$stnum;
		$resultset=[];
foreach($cacheresult->item as $mydata)
    {
         $resultset[2][]=base64_decode($mydata->title);
    }
foreach($cacheresult->item as $mydata)
    {
         $resultset[1][]=$mydata->titleurl;
    }
foreach($cacheresult->item as $mydata)
    {
         $resultset[3][]=base64_decode($mydata->description);
    }
foreach($cacheresult->item as $mydata)
    {
         $resultset[4][]=$mydata->displayurl;
    }
			$this->setValue("totalhits",$total);
		$cacheresultcount=0;
		foreach($cacheresult->item as $mydata)
		{
			$cacheresultcount=$cacheresultcount+1;
		}
		$this->setValue("totalhits",$total);
		if($cacheresultcount==0)
		{
			echo $this->testapi($keyword, $page, $tabname);
			exit;
		}
		$message=array("servicename"=>$servicename);
		$home=$this->getmessagegrammer(47,$message,0);
		$this->setValue("home",$home);
		$this->setValue("engineid",$engineid);
		$enginename=$this->getenginename($engineid);
		define('PAGETITLE',$servicename." - ".$enginename." - ".$keyword);
                $this->setValue('pagetitle',$servicename." - ".$enginename." - ".$keyword);
		define('HEADERKEYWORD',$servicename.",search,search engine,".$keyword.",".$searchtype);
		$typearray=array("type"=>$enginename);
		$typesearch=$this->getmessagegrammer(23,$typearray);
		$this->setValue("typesearch",$typesearch);
		$start=(10*($page-1))%$count;
		$startingnum=($page*10)-9;
		$endingnum=$page*10;
		if($total<$endingnum)
		$endingnum=$total;
		if($total<10)
		$startingnum=1;
		else
		$startingnum=($page*10)-9;
		$totalstring=number_format($total1);
		$message=array("startingnum"=>$startingnum,"endingnum"=>$endingnum,"total"=>$totalstring,"keyword"=>htmlentities($keyword,ENT_QUOTES,"UTF-8"));
		$style=array("resultcountstart","resultcountend","totalresults","keywordintotal");
		$totalstr=$this->getmessagegrammer(8,$message,$style);
		$this->setValue("total",$totalstr);
		$keyword1=urlencode($keyword);
	$previouspage=$page-1;
		if($page<=4)
		{
			$startpage=1;
			$endpage=5;
		}
		else
		{
			$startpage=$page-3;
			$endpage=$page+1;
		}
		$nextpage=$page+1;
		if($page!=1)
		{
		$footerlink.="<li class=\"pgntn-li float-left\"><a class=\"pgntn-a pgn-arw\" href=javascript:loadpage($previouspage)><i class=\"fas fa-chevron-left\"></i></a></li>";
		}
		for($i=$startpage;$i<=$endpage;$i++)
		{
			if($i*10<($total+10))
			{
				if($i!=$page)
				{
					$footerlink.="<li class=\"pgntn-li float-left\"><a class=\"pgntn-a pgn-cnt\" href=javascript:loadpage($i)>$i</a></li>";
				}
				else 
				{
					$footerlink.="<li class=\"pgntn-li float-left\"><a class=\"pgntn-a pgn-cnt pgn-actv\" href=javascript:loadpage($i)>$i</a></li>";
				}
			}
		}
		if($page*10<($total))
		{
		$footerlink.="<li class=\"pgntn-li float-left\"><a class=\"pgntn-a pgn-arw\" href=javascript:loadpage($nextpage)><i class=\"fas fa-chevron-right\"></i></a></li>";
		}
		$s=($page-1)*10-$stnumber; $u=0;
		$rescnt=$cacheresultcount;
		if($rescnt>=$s+10)
		{
			for($i=0;$i<10;$i++)
			{
				if($resultset[4][$s]!="")
				{
					$finalresult[$u][1]=$resultset[3][$s];
					if(strlen($finalresult[$u][1])>=150)
					{  $len=strlen($finalresult[$u][1]);
					$p=strpos($finalresult[$u][1]," ");
					if(($p=="")||($p>150))
					{  
						$fir=substr($finalresult[$u][1],0,150);
						$sec=substr($finalresult[$u][1],151,$len);
						$finalresult[$u][1]=$fir." ".$sec;
					}
					}
					$finalresult[$u][2]=$resultset[4][$s];
					if(strlen($finalresult[$u][2])>=60)                           
					$finalresult[$u][2]=substr($finalresult[$u][2],0,60)."...";
					$finalresult[$u][3]=$resultset[1][$s];                          
					if(strlen($finalresult[$u][3])>=100)
					$finalresult[$u][3]=substr($finalresult[$u][3],0,100)."...";
					$finalresult[$u][4]=$resultset[2][$s];
					$finalresult[$u][5]=$statusarray[1][$u];
					$finalresult[$u][6]=$this->getstar($finalresult[$u][4],$engineid);
					$u++;
				}
				$s=$s+1;
			}
		}
		else if($total-$startingnum+1>10)
		{
			$s= $rescnt-10;
			for($i=0;$i<10;$i++)
			{
				if($resultset[4][$s]!="")
				{
					$finalresult[$u][1]=$resultset[3][$s];
					if(strlen($finalresult[$u][1])>=150)
					{  $len=strlen($finalresult[$u][1]);
					$p=strpos($finalresult[$u][1]," ");
					if(($p=="")||($p>150))
					{  
						$fir=substr($finalresult[$u][1],0,150);
						$sec=substr($finalresult[$u][1],151,$len);
						$finalresult[$u][1]=$fir." ".$sec;
					}
					}
					$finalresult[$u][2]=$resultset[4][$s];
					if(strlen($finalresult[$u][2])>=60)                            
					$finalresult[$u][2]=substr($finalresult[$u][2],0,60)."...";
					$finalresult[$u][3]=$resultset[1][$s];                         
					if(strlen($finalresult[$u][3])>=100)
					$finalresult[$u][3]=substr($finalresult[$u][3],0,100)."...";
					$finalresult[$u][4]=$resultset[2][$s];
					$finalresult[$u][5]=$statusarray[1][$u];
					$finalresult[$u][6]=$this->getstar($finalresult[$u][4],$engineid);
					$u++;
				}
				$s=$s+1;
			}
		}
		else if($total-$startingnum+1>0)
		{
			$finish=$total-$startingnum+1;
			$statf=0;
			$s=0;
			for($i=0;$i<$finish;$i++)
			{
				if($resultset[4][$s]!="")
				{
					$finalresult[$u][1]=$resultset[3][$s];
					if(strlen($finalresult[$u][1])>=150)
					{  $len=strlen($finalresult[$u][1]);
					$p=strpos($finalresult[$u][1]," ");
					if(($p=="")||($p>150))
					{   
						$fir=substr($finalresult[$u][1],0,150);
						$sec=substr($finalresult[$u][1],151,$len);
						$finalresult[$u][1]=$fir." ".$sec;
					}
					}
					$finalresult[$u][2]=$resultset[4][$s];
					if(strlen($finalresult[$u][2])>=60)                             
					$finalresult[$u][2]=substr($finalresult[$u][2],0,60)."...";
					$finalresult[$u][3]=$resultset[1][$s];                         
					if(strlen($finalresult[$u][3])>=100)
					$finalresult[$u][3]=substr($finalresult[$u][3],0,100)."...";
					$finalresult[$u][4]=$resultset[2][$s];
					$finalresult[$u][5]=$statusarray[1][$statf];
					$finalresult[$u][6]=$this->getstar($finalresult[$u][4],$engineid);
					$u++; $statf++;
				}
				$s=$s+1;
			}
		}
		else
		{
			echo $this->testapi($keyword, $page, $tabname);
			exit;
		}
		if(($page==1)&&($feelinglucky==1))
		{
			header("Location:".strip_tags($finalresult[0][4]));
			exit(0);
		}
$finalcount=count($finalresult);
		for($i=0;$i<$finalcount;$i++)
		{
			$finalresult[$i][1]=$this->makebold($finalresult[$i][1],$keyword,1);
			$finalresult[$i][2]=$this->makebold($finalresult[$i][2],$keyword,0);
			$finalresult[$i][3]=$this->makebold($finalresult[$i][3],$keyword,0);
		}
		if($finalcount==0)
		{
			echo $this->testapi($keyword, $page, $tabname);
			exit;
		}
		
$str="";
	$str.='[&&]';$str.=$totalstr;$str.='[&&]';$str.=$typesearch;$str.='[&&]';
	$iplus=($page-1)*10;
		for($i=0;$i<$finalcount;$i++)
		{
$str.='';
                if(($thumbshotstatus==1) && ($thumshot_url!=""))	
                {
$str.='
                  <a href="'.$finalresult[$i][4].'" alt="'.strip_tags($finalresult[$i][2]).'" title="'.strip_tags($finalresult[$i][2]).'">';
                  if($finalresult[$i][5]=="0010")
                 {
                 }
                 else 
                 {
                 }
                }
                   else
                   {
                   }
$str.='<div class="float-left fullwidth my-2 rslt-out">
  <a class="wb-rslt-a" href="'.$finalresult[$i][4].'" target="_blank">
		<h3 class="wb-rslt-hd">'.$finalresult[$i][3].'</a></h3>&nbsp';
if($openin_newwindow==1){
$str.='<a target="_blank" href="'.$finalresult[$i][4].'"><i class="fas fa-external-link-alt fa_color" title="'.$this->getmessage(3).'"></i></a>';
}
					$str.='<!-- Ulitmate7 -->';
							if($valid==1)
							{
							if($star_status==1)	
							{				
							if($finalresult[$i][6]=="1")
							{
$str.='<a href="javascript:unclick(\''.$this->encode($finalresult[$i][1]).'\',\''.$iplus.'\',\''.$this->encode($finalresult[$i][3]).'\',\''.$this->encode($finalresult[$i][2]).'\',\''.$this->encode($finalresult[$i][4]).'\',\''.$engineid.'\')"><span id="span1'.$iplus.'" style=" " class="add_favourites" title="'.$this->getmessage(640).'"><i class="fas fa-star" ></i></span></a>
<a href="javascript:click(\''.$this->encode($finalresult[$i][1]).'\',\''.$iplus.'\',\''.$this->encode($finalresult[$i][3]).'\',\''.$this->encode($finalresult[$i][2]).'\',\''.$this->encode($finalresult[$i][4]).'\',\''.$engineid.'\')" ><span id="span2'.$iplus.'" class="add_favourites" style="display: none;" title="'.$this->getmessage(640).'"> <i class="far fa-star"></i></span></a>';
							}
							if($finalresult[$i][6]=="0")
							{
$str.='<a href="javascript:click(\''.$this->encode($finalresult[$i][1]).'\',\''.$iplus.'\',\''.$this->encode($finalresult[$i][3]).'\',\''.$this->encode($finalresult[$i][2]).'\',\''.$this->encode($finalresult[$i][4]).'\',\''.$engineid.'\')" ><span id="span2'.$iplus.'" style="" class="add_favourites" title="'.$this->getmessage(641).'"> <i class="far fa-star"></i></span></a>
<a href="javascript:unclick(\''.$this->encode($finalresult[$i][1]).'\',\''.$iplus.'\',\''.$this->encode($finalresult[$i][3]).'\',\''.$this->encode($finalresult[$i][2]).'\',\''.$this->encode($finalresult[$i][4]).'\',\''.$engineid.'\')" > <span id="span1'.$iplus.'" class="add_favourites" style="display: none;" title="'.$this->getmessage(641).'"> <i class="far fa-star"></i></i></span></a>';
							}
							}}
$str.='<p class="wb-rslt-dmn"> '.$finalresult[$i][2].'</p>
		<div class="fullwidth float-left">
		<p class="wb-rslt-info"> '.$finalresult[$i][1].'</p>
		</div>';
                       $str.='<div class="float-left ">'; 
                      if($emailafrnd==1)
                      {
$str.='<a class="rslt-lnk"><i class="fas fa-envelope rslt-lnk-ic" id="email_lnk"></i> Email Link</a>';
                      }
                      if($quicklook==1)
                      {
$str.='<span  id="qlook{loop:results}" class="rslt-lnk qk-look">  <i id="qlook_bti'.($iplus+1).'" class="fas fa-chevron-circle-right rslt-lnk-ic"></i> <a class="rslt-lnk qk-look"
							id="qlook_btn'.($iplus+1).'"
							href="javascript:qlook('.($iplus+1).',\''.$this->getmessage(39).'\',\''.$this->getmessage(41).'\',\''.$this->getmessage(40).'\')">'.$this->getmessage(39).'</a> </span> 
                     <span id="qlook_spn'.($iplus+1).'" style="display: none;"><i id="qlook_mmi'.($iplus+1).'" class="fas fa-plus-circle rslt-lnk-ic"></i>
                    &nbsp;<a class="rslt-lnk qk-look"
							id="qlook_mmb'.($iplus+1).'"
							href="javascript:qlookmm('.($iplus+1).',\''.$this->getmessage(41).'\',\''.$this->getmessage(43).'\')">'.$this->getmessage(41).'</a>
						<span id="qlook_mms'.($iplus+1).'"></span><i class="fa fa-home rslt-lnk-ic" aria-hidden="true"></i>
</i>&nbsp;<a
							class="qlook rslt-lnk qk-look " id="qlook_ghb'.($iplus+1).'"
							href="javascript:qlookgh('.($iplus+1).')">'.$this->getmessage(42).'</a>
						</span>';
                      }
						$str.='<!-- Ulitmate7 -->';							
if($comment_status==1)
					{
$str.='<a class="rslt-lnk rslt-cmnt  cmnt_new_'.$iplus.'" href="javascript:comment(\''.$iplus.'\')"><i class="fas fa-comments rslt-lnk-ic"></i> '.$this->getmessage(579).'&nbsp;(<span id="comcount'.$iplus.'">'.$this->getcmntcount($finalresult[$i][4]).'</span>)</a>';
					}
$str.='</div>';
$str.='<div class="rslt-cmnt-drp" id="cmnt-drp_'.$iplus.'">
<input type="hidden" name="urlenc'.$iplus.'" id="urlenc'.$iplus.'" value="'.urlencode($finalresult[$i][4]).'">
<div class="drp-cmnt-area fullwidth"  id="div'.$iplus.'">';
$str.=$this->getcommentsnw($finalresult[$i][4],$results,"web");
$str.='</div>';
	if($valid!=1)	{
$str.='&nbsp;<span style="color: #686868;font-style: italic;">'.$this->getmessage(608).'</span>';
}else{
$str.='<input type="hidden" name="url" id="url'.$iplus.'" value="'.$finalresult[$i][4].'">';
$str.='<label class="radio-cstm">'.$this->getmessage(581).'
  <input type="radio" name="type" id="type2'.$iplus.'" value="title">
  <span class="checkmark"></span>
</label>
<label class="radio-cstm">'.$this->getmessage(587).'
  <input type="radio" name="type" id="type1'.$iplus.'" value="domain">
  <span class="checkmark"></span>
</label>';
$str.='<textarea class="rslt-cmnt-area" placeholder="Enter Your Comments." type="text" id="comment'.$iplus.'"></textarea>
<span class=" cmt_error_msg" id="cmterror'.$iplus.'"></span>
<button class="float-right rslt-cmnt-btn" onclick="postcomment('.$iplus.')" type="button">Send</button>';
}
$str.='</div>
</div>
<div class="rslt-cmnt-drp notlogin" id="cmnt-drp_nlog_'.$iplus.'">
<textarea class="rslt-cmnt-area" placeholder="'.$this->getmessage(608).'" type="text"></textarea>
</div>';
                if($quicklook==1)
                {
				$str.='<span id="qlookframe'.($iplus).'" style="'.$this->getqlookdisplaystatus().'" width="100%">
						<iframe class="qickfrmeifrmae"	id="qlook_fra'.($iplus+1).'" src="" src1="'.$finalresult[$i][3].'"
							loaded="0" width="99%" height="300" scrolling="auto"
							style="display: none; margin-top: 3px;"></iframe>
						<div align="center" id="qlook_lsi'.($iplus+1).'"
							style="display: none; margin: 0;" width="100%"><img
							src="images/qlook/q_l10.gif" alt="Loading..." width="239"
							height="20" style="margin-top: 20px; margin-bottom: 250px;" /></div>
						</span>';
                }	
			else{
}
			$iplus=$iplus+1;	
		}
$str.='</div>';
		$str .='[&&]'.$footerlink;
		echo $str;
	    exit;
	}
	function specialinstanceAction()
	{
		$valid=$this->uservalidation();
		$this->setValue("valid",$valid);
		$keyword=$_POST['search'];
		$quotestatus=get_magic_quotes_gpc();
		if($quotestatus==1)
		$keyword=stripslashes($keyword);
		$tabname=$_POST['type'];
		$fl=$_POST['fl'];
		if((!isset($_POST['type']))||($_POST['type']==""))
		$tabname=$this->getParam(1);
		if((!isset($_POST['search'])||($_POST['search']=="")))
		$keyword=str_replace("%2NNFF","/",$this->getParam(2));
		$suggestion_keyword=$keyword;
		include("script.inc.php");
		include("{$config_path}system.config.php");
		if($fl==1)
		$feelinglucky=1;
		$quotestatus=get_magic_quotes_gpc();
		if($quotestatus==1)
		$keyword=stripslashes($keyword);
		$keyword=str_replace('"',' " ',$keyword);
		$keyword=str_replace("'"," ' ",$keyword);
		$keyword=$this->familyfilter($keyword);
		$keyword=str_replace("' ","'",$keyword);
		$keyword=str_replace(" '","'",$keyword);
		$keyword=str_replace('" ','"',$keyword);
		$keyword=str_replace(' "','"',$keyword);
		$db= new NesoteDALController();
		$db->select("nesote_inoutse_engines");
		$db->fields("id,search_type,tab_name");
		$db->where("tab_name=?",$tabname);
		$result=$db->query();
		$row=$db->fetchRow($result);
		$searchtype=$row[1];  // reading search type
		$engineid=$row[0];  // reading engine id
		$enginename=$row[2];//reading tab name
		$this->setValue("engineid",$engineid);
		$tabkeyword=str_replace("/","%2NNFF",$keyword);
		$this->setValue("keyword",$tabkeyword);
		$this->setValue("tabname",$tabname);
		$db= new NesoteDALController();
		$tot=$db->total("nesote_inoutse_engines","tab_name=? and status=?",array($tabname,1));
		if(($keyword=="")||($tot==0))
		{
			echo "no result";exit;
		}
		$db->select("nesote_inoutse_engines");
		$db->fields("special_status");
		$db->where("tab_name=? and status=?",array($tabname,1));
		$tabstatus=$db->query();
		$statusrow=$db->fetchRow($tabstatus);
		$this->setValue("statusrow",$statusrow[0]);
		$page=1;
		if(isset($_POST['startpage']))
		$page=$_POST['startpage'];   
		if ($page=="")
		$page=1;
		$xmldata=$this->getmixurlcontents($engineid,$searchtype,$page,$keyword,1);
		$cacheparts=explode("&@&",$xmldata);
		$cachepart1=$cacheparts[0];
		$cachepart2=$cacheparts[1];
		$cacheresult=json_decode($cachepart2);
		$cacheresultd = json_decode($cachepart1, true);
		$source=$cacheparts[2];
		if($source!='')
		{
			$sourceresult=json_decode($source);
			foreach($sourceresult->source as $mydata)
		    {
		         $statusarray[1][].=$mydata->sourcestatus;
		    }
		}
		$source=$cacheparts[2];
		if($source!='')
		{
			$sourceresult=json_decode($source);
			foreach($sourceresult->source as $mydata)
		    {
		         $statusarray[1][].=$mydata->sourcestatus;
		    }
		}
		$start=$cacheresultd['start'];
		$totalcount=$cacheresultd['totalcount'];
		$backupcount=$cacheresultd['backupcount'];
		$allstatus=$cacheresultd['allstatus'];
		$onlygooglestatus=$cacheresultd['onlygooglestatus'];
		$resultset=[];
		$resultset=[];
		foreach($cacheresult->item as $mydata)
		{
			$resultset[2][]=$mydata->titleurl;
		}
		foreach($cacheresult->item as $mydata)
		{
			$resultset[1][]=base64_decode($mydata->title);
		}
		foreach($cacheresult->item as $mydata)
		{
			$resultset[3][]=base64_decode($mydata->description);
		}
		foreach($cacheresult->item as $mydata)
		{
			$resultset[4][]=$mydata->displayurl;
		}
		$cacheresultcount=0;
		foreach($cacheresult->item as $mydata)
		{
			$cacheresultcount=$cacheresultcount+1;
		}
		$this->loadLibrary('Settings');
		$settings=new Settings('nesote_inoutse_settings');
		$settings->loadValues();
		$count=$settings->getValue("result_count");
		$isbold=$settings->getValue("keyword_bold");
		$relatedtag_count=$settings->getValue("related_tags_count");
		$styleid=$settings->getValue("result");
		$thumbshotstatus=$settings->getValue("thumbshot");
		if($_COOKIE['thumbshot']=="off")
		$thumbshotstatus=0;
		$this->setValue("thumbshotstatus",$thumbshotstatus);
				$thumshot_api=$settings->getValue("thumshot_url");		
		$thumshot_url="http://images.thumbshots.com/image.aspx?cid=$thumshot_api&v=1&w=120px&url=";
		$this->setValue("thumshot_url",$thumshot_url);
		$openin_newwindow=$settings->getValue("new_window");
		$this->setValue("newwindow",$openin_newwindow);
		$emailafrnd=$settings->getValue("email_a_frnd");
		$this->setValue("emailafrnd",$emailafrnd);
		$quicklook=$settings->getValue("quicklook");
		$this->setValue("quicklook",$quicklook);
		$servicename=$settings->getValue("service_name");
		$this->setValue("servicename",$servicename);
		$ad_codes=$settings->getValue("ad_codes");
		$seasonal_logo_status=$settings->getValue("seasonal_logo");
		$star_status=$settings->getValue("star_status");
		$member_status=$settings->getValue("member_status");
		if($member_status==1)
		$comment_status=$settings->getValue("comment_status");
		else
		$comment_status=0;
		$rest_api_status=$settings->getValue("rest_api_search");
		$specialstatus=$this->getspecialstatus($engineid);
		if($specialstatus==2)
		$thumbshotstatus=0;
		else
		$thumbshotstatus=$settings->getValue("thumbshot");
		if($_COOKIE['thumbshot']=="off")
		$thumbshotstatus=0;
		$thumbshot_user_override=$settings->getValue("thumbshot_user_override");
		if(($thumbshotstatus==1)&&($thumbshot_user_override==1))
		{
			$status=1;
			$this->setValue("thumbshotstatus",$status);
		}
		else
		$this->setValue("thumbshotstatus",$thumbshotstatus);
		$message=array("servicename"=>$servicename);
		$home=$this->getmessagegrammer(47,$message,0);
		$enginename1=$this->getenginename($engineid);
		define('PAGETITLE',$servicename." - ".$enginename1." - ".$keyword);
		define('HEADERKEYWORD',$servicename.",search,search engine,".$keyword.",".$searchtype);
		$typearray=array("type"=>$enginename1)	;
		$typesearch=$this->getmessagegrammer(23,$typearray);
		$xmldata=str_replace("\r\n","",$xmldata);
		$xmldata=str_replace("\n","",$xmldata);
		$xmldata=str_replace("\r","",$xmldata);
		if($xmldata=="expired")
		{
			echo $this->testapi($keyword, $page, $tabname);
			exit;
		}
		$totalhits=$totalcount;
		if($allstatus==0)
		{
			$total=$backupcount;
			$total1=$totalhits;
		}
		else
		{
			$onlygoogle=$onlygooglestatus;
			if($onlygoogle==1)
			{
				$total=$totalhits;
				$google_maxcount=$settings->getValue("google_totalfetchingcount");
				if($total>$google_maxcount)
				{
				   $total=$google_maxcount;
				}
			}
			else
			{
				$total=$totalhits;
			}
			$total1=$totalhits;
		}
        $stnum=$start;
		$stnumber=$stnum;
		$this->setValue("totalhits",$total);
		if($cacheresultcount==0)
		{
			echo $this->testapi($keyword, $page, $tabname);
			exit;
		}
		$pagecount=$page*10;
		$start=(10*($page-1))%$count;
		$startingnum=($page*10)-9;
		$endingnum=$page*10;
		if($total<$endingnum)
		$endingnum=$total;
		if($total<10)
		$startingnum=1;
		else
		$startingnum=($page*10)-9;
		$totalstring=number_format($total1);
		$message=array("startingnum"=>$startingnum,"endingnum"=>$endingnum,"total"=>$totalstring,"keyword"=>htmlentities($keyword,ENT_QUOTES,"UTF-8"));
		$style=array("resultcountstart","resultcountend","totalresults","keywordintotal");
		$totalstr=$this->getmessagegrammer(8,$message,$style);
		$this->setValue("total",$totalstr);
		$keyword1=urlencode($keyword);
		$keywordsuggestion_status=$db->total("nesote_inoutse_engines","id=? and keyword_suggestion_status=1",array($engineid));
		if($page==1 && $keywordsuggestion_status!=0 && trim($suggestion_keyword)==trim($keyword))
		{
			$tot1=$db->total("nesote_inoutse_keywordsuggestions","engine_id=? and keyword=?",array($engineid,$suggestion_keyword));
			if($tot1==0)
			{
				$db->insert("nesote_inoutse_keywordsuggestions");
        		$db->fields("engine_id,keyword,total,searchcount,time");
        		$db->values(array($engineid,$suggestion_keyword,$total1,1,time()));
        		$db->query();
			}
			else
			{
				$db->update("nesote_inoutse_keywordsuggestions");
				$db->set("searchcount=searchcount+1,time=?,total=?",array(time(),$total1));
				$db->where("engine_id=? and keyword=?",array($engineid,$suggestion_keyword));
				$db->query();
			}
		}
		$previouspage=$page-1;
		if($page<=4)
		{
			$startpage=1;
			$endpage=5;
		}
		else
		{
			$startpage=$page-3;
			$endpage=$page+1;
		}
		$nextpage=$page+1;
		if($page!=1)
		{
		$footerlink.="<li class=\"pgntn-li float-left\"><a class=\"pgntn-a pgn-arw\" href=javascript:loadpage($previouspage)><i class=\"fas fa-chevron-left\"></i></a></li>";
		}
		for($i=$startpage;$i<=$endpage;$i++)
		{
			if($i*10<($total+10))
			{
				if($i!=$page)
				{
					$footerlink.="<li class=\"pgntn-li float-left\"><a class=\"pgntn-a pgn-cnt\" href=javascript:loadpage($i)>$i</a></li>";
				}
				else 
				{
					$footerlink.="<li class=\"pgntn-li float-left\"><a class=\"pgntn-a pgn-cnt pgn-actv\" href=javascript:loadpage($i)>$i</a></li>";
				}
			}
		}
		if($page*10<($total))
		{
		$footerlink.="<li class=\"pgntn-li float-left\"><a class=\"pgntn-a pgn-arw\" href=javascript:loadpage($nextpage)><i class=\"fas fa-chevron-right\"></i></a></li>";
		}
		$s=($page-1)*10-$stnumber; $u=0;
		$rescnt=count($resultset[1]);
		if($rescnt>=$s+10)
		{
			for($i=0;$i<10;$i++)
			{
				if($resultset[4][$s]!="")
				{
					$finalresult[$u][1]=$resultset[3][$s];
					if(strlen($finalresult[$u][1])>=150)
					{  $len=strlen($finalresult[$u][1]);
					$p=strpos($finalresult[$u][1]," ");
					if(($p=="")||($p>150))
					{  
						$fir=substr($finalresult[$u][1],0,150);
						$sec=substr($finalresult[$u][1],151,$len);
						$finalresult[$u][1]=$fir." ".$sec;
					}
					}
					$finalresult[$u][2]=$resultset[4][$s];
					if(strlen($finalresult[$u][2])>=60)                             
					$finalresult[$u][2]=substr($finalresult[$u][2],0,60)."...";
					$finalresult[$u][3]=$resultset[1][$s];                          
					if(strlen($finalresult[$u][3])>=100)
					$finalresult[$u][3]=substr($finalresult[$u][3],0,100)."...";
					$finalresult[$u][4]=$resultset[2][$s];
					$finalresult[$u][5]=$statusarray[1][$u];
					$finalresult[$u][6]=$this->getstar($finalresult[$u][4],$engineid);
					$u++;
				}
				$s=$s+1;
			}
		}
		else if($total-$startingnum+1>10)
		{
			$s= $rescnt-10;
			for($i=0;$i<10;$i++)
			{
				if($resultset[4][$s]!="")
				{
					$finalresult[$u][1]=$resultset[3][$s];
					if(strlen($finalresult[$u][1])>=150)
					{  $len=strlen($finalresult[$u][1]);
					$p=strpos($finalresult[$u][1]," ");
					if(($p=="")||($p>150))
					{   
						$fir=substr($finalresult[$u][1],0,150);
						$sec=substr($finalresult[$u][1],151,$len);
						$finalresult[$u][1]=$fir." ".$sec;
					}
					}
					$finalresult[$u][2]=$resultset[4][$s];
					if(strlen($finalresult[$u][2])>=60)                             
					$finalresult[$u][2]=substr($finalresult[$u][2],0,60)."...";
					$finalresult[$u][3]=$resultset[1][$s];                          
					if(strlen($finalresult[$u][3])>=100)
					$finalresult[$u][3]=substr($finalresult[$u][3],0,100)."...";
					$finalresult[$u][4]=$resultset[2][$s];
					$finalresult[$u][5]=$statusarray[1][$u];
					$finalresult[$u][6]=$this->getstar($finalresult[$u][4],$engineid);
					$u++;
				}
				$s=$s+1;
			}
		}
		else if($total-$startingnum+1>0)
		{
			$finish=$total-$startingnum+1;
			$statf=0;
			$s=0;
			for($i=0;$i<$finish;$i++)
			{
				if($resultset[4][$s]!="")
				{
					$finalresult[$u][1]=$resultset[3][$s];
					if(strlen($finalresult[$u][1])>=150)
					{  $len=strlen($finalresult[$u][1]);
					$p=strpos($finalresult[$u][1]," ");
					if(($p=="")||($p>150))
					{  
						$fir=substr($finalresult[$u][1],0,150);
						$sec=substr($finalresult[$u][1],151,$len);
						$finalresult[$u][1]=$fir." ".$sec;
					}
					}
					$finalresult[$u][2]=$resultset[4][$s];
					if(strlen($finalresult[$u][2])>=60)                            
					$finalresult[$u][2]=substr($finalresult[$u][2],0,60)."...";
					$finalresult[$u][3]=$resultset[1][$s];                          
					if(strlen($finalresult[$u][3])>=100)
					$finalresult[$u][3]=substr($finalresult[$u][3],0,100)."...";
					$finalresult[$u][4]=$resultset[2][$s];
					$finalresult[$u][5]=$statusarray[1][$statf];
					$finalresult[$u][6]=$this->getstar($finalresult[$u][4],$engineid);
					$u++; $statf++;
				}
				$s=$s+1;
			}
		}
		else
		{
			echo $this->testapi($keyword, $page, $tabname);
			exit;
		}
		if(($page==1)&&($feelinglucky==1))
		{
			header("Location:".strip_tags($finalresult[0][4]));
			exit(0);
		}
$finalcount=count($finalresult);
		for($i=0;$i<$finalcount;$i++)
		{
			$finalresult[$i][1]=$this->makebold($finalresult[$i][1],$keyword,1);
			$finalresult[$i][2]=$this->makebold($finalresult[$i][2],$keyword,0);
			$finalresult[$i][3]=$this->makebold($finalresult[$i][3],$keyword,0);
		}
		if($finalcount==0)
		{
			echo $this->testapi($keyword, $page, $tabname);
			exit;
		}
		
	$str="";
	$str.='[&&]';$str.=$totalstr;$str.='[&&]';$str.=$typesearch;$str.='[&&]';
	$iplus=($page-1)*10;
			for($i=0;$i<$finalcount;$i++)
		{
$str.='';
                if(($thumbshotstatus==1) && ($thumshot_url!=""))	
                {	
                     if($finalresult[$i][5]=="0010")
                 {
                 }
                 else 
                 {
                 }
                }
                   else
                   {
                   }
$str.='<div class="float-left fullwidth my-2 rslt-out">
  <a class="wb-rslt-a" href="'.$finalresult[$i][4].'" target="_blank">
		<h3 class="wb-rslt-hd">'.$finalresult[$i][1].'</a></h3>&nbsp';
if($openin_newwindow==1){
$str.='<a target="_blank" href="'.$finalresult[$i][4].'"><i class="fas fa-external-link-alt fa_color" title="'.$this->getmessage(3).'"></i></a>';
}
                 if($this->getalignment()!=2)
                 {
                 }  if($openin_newwindow==1) 
                    {
                    }
					$str.='<!-- Ulitmate7 -->';
						if($valid==1)
							{
							if($star_status==1)	
							{				
							if($finalresult[$i][6]=="1")
							{
$str.='<a href="javascript:unclick(\''.$this->encode($finalresult[$i][1]).'\',\''.$iplus.'\',\''.$this->encode($finalresult[$i][3]).'\',\''.$this->encode($finalresult[$i][2]).'\',\''.$this->encode($finalresult[$i][4]).'\',\''.$engineid.'\')" ><span id="span1'.$iplus.'" style=" " class="add_favourites" title="'.$this->getmessage(640).'"><i class="fas fa-star" ></i></span></a>
<a href="javascript:click(\''.$this->encode($finalresult[$i][1]).'\',\''.$iplus.'\',\''.$this->encode($finalresult[$i][3]).'\',\''.$this->encode($finalresult[$i][2]).'\',\''.$this->encode($finalresult[$i][4]).'\',\''.$engineid.'\')" ><span id="span2'.$iplus.'" class="add_favourites" style="display: none;" title="'.$this->getmessage(640).'"> <i class="far fa-star"></i></span></a>';
							}
							if($finalresult[$i][6]=="0")
							{
$str.='<a href="javascript:click(\''.$this->encode($finalresult[$i][1]).'\',\''.$iplus.'\',\''.$this->encode($finalresult[$i][3]).'\',\''.$this->encode($finalresult[$i][2]).'\',\''.$this->encode($finalresult[$i][4]).'\',\''.$engineid.'\')" ><span id="span2'.$iplus.'" style="" class="add_favourites" title="'.$this->getmessage(641).'"> <i class="far fa-star"></i></span></a>
<a href="javascript:unclick(\''.$this->encode($finalresult[$i][1]).'\',\''.$iplus.'\',\''.$this->encode($finalresult[$i][3]).'\',\''.$this->encode($finalresult[$i][2]).'\',\''.$this->encode($finalresult[$i][4]).'\',\''.$engineid.'\')" > <span id="span1'.$iplus.'" class="add_favourites" style="display: none;"title="'.$this->getmessage(641).'"> <i class="far fa-star"></i></i></span></a>';
							}
							}}
$str.='<p class="wb-rslt-dmn"> '.$finalresult[$i][2].'</p>
		<div class="fullwidth float-left">
		<p class="wb-rslt-info"> '.$finalresult[$i][1].'</p>
		</div>';
		if($this->getalignment()==2)
                 {
                 }
				$str.='<!-- Ulitmate7 -->';
                      if($emailafrnd==1)
                      {
$str.='<a class="rslt-lnk"><i class="fas fa-envelope rslt-lnk-ic" id="email_lnk"></i>'.$this->getmessage(27).'</a>';
                      }
                      if($quicklook==1)
                      {
$str.='<span  id="qlook{loop:results}" class="rslt-lnk qk-look">  <i id="qlook_bti'.($iplus+1).'" class="fas fa-chevron-circle-right rslt-lnk-ic"></i> <a class="rslt-lnk qk-look"
							id="qlook_btn'.($iplus+1).'"
							href="javascript:qlook('.($iplus+1).',\''.$this->getmessage(39).'\',\''.$this->getmessage(41).'\',\''.$this->getmessage(40).'\')">'.$this->getmessage(39).'</a> </span> 
                     <span id="qlook_spn'.($iplus+1).'" style="display: none;"><i id="qlook_mmi'.($iplus+1).'" class="fas fa-plus-circle rslt-lnk-ic"></i>
                    &nbsp;<a class="rslt-lnk qk-look"
							id="qlook_mmb'.($iplus+1).'"
							href="javascript:qlookmm('.($iplus+1).',\''.$this->getmessage(41).'\',\''.$this->getmessage(43).'\')">'.$this->getmessage(41).'</a>
						<span id="qlook_mms'.($iplus+1).'"></span><i class="fa fa-home rslt-lnk-ic" aria-hidden="true"></i>
</i>&nbsp;<a
							class="qlook rslt-lnk qk-look " id="qlook_ghb'.($iplus+1).'"
							href="javascript:qlookgh('.($iplus+1).')">'.$this->getmessage(42).'</a>
						</span>';
                      }
						$str.='<!-- Ulitmate7 -->';							
if($comment_status==1)
					{
$str.='<a class="rslt-lnk rslt-cmnt  cmnt_new_'.$iplus.'" href="javascript:comment(\''.$iplus.'\')"><i class="fas fa-comments rslt-lnk-ic"></i> '.$this->getmessage(579).'&nbsp;(<span id="comcount'.$iplus.'">'.$this->getcmntcount($finalresult[$i][4]).'</span>)</a>';
					}
$str.='<div class="rslt-cmnt-drp" id="cmnt-drp_'.$iplus.'">
<input type="hidden" name="urlenc'.$iplus.'" id="urlenc'.$iplus.'" value="'.urlencode($finalresult[$i][4]).'">
<div class="drp-cmnt-area fullwidth"  id="div'.$iplus.'">';
$str.=$this->getcommentsnw($finalresult[$i][4],$results,"special");
$str.='</div>';
	if($valid!=1)	{
$str.='&nbsp;<span style="color: #686868;font-style: italic;">'.$this->getmessage(608).'</span>';
}else{
$str.='<input type="hidden" name="url" id="url'.$iplus.'" value="'.$finalresult[$i][4].'">';
$str.='<label class="radio-cstm">'.$this->getmessage(581).'
  <input type="radio" name="type" id="type2'.$iplus.'" value="title">
  <span class="checkmark"></span>
</label>
<label class="radio-cstm">'.$this->getmessage(587).'
  <input type="radio" name="type" id="type1'.$iplus.'" value="domain">
  <span class="checkmark"></span>
</label>';
$str.='<textarea class="rslt-cmnt-area" placeholder="Enter Your Comments." type="text" id="comment'.$iplus.'"></textarea>
<span class=" cmt_error_msg" id="cmterror'.$iplus.'"></span>
<button class="float-right rslt-cmnt-btn" onclick="postcomment('.$iplus.')" type="button">Send</button>';
}
$str.='</div>
</div>
<div class="rslt-cmnt-drp notlogin" id="cmnt-drp_nlog_'.$iplus.'">
<textarea class="rslt-cmnt-area" placeholder="'.$this->getmessage(608).'" type="text"></textarea>
</div>';
                if($quicklook==1)
                {
				$str.='<span id="qlookframe'.($iplus).'" style="'.$this->getqlookdisplaystatus().'" width="100%">
						<iframe class="qickfrmeifrmae"	id="qlook_fra'.($iplus+1).'" src="" src1="'.$finalresult[$i][4].'"
							loaded="0" width="99%" height="300" scrolling="auto"
							style="display: none; margin-top: 3px;"></iframe>
						<div align="center" id="qlook_lsi'.($iplus+1).'"
							style="display: none; margin: 0;" width="100%"><img
							src="images/qlook/q_l10.gif" alt="Loading..." width="239"
							height="20" style="margin-top: 20px; margin-bottom: 250px;" /></div>
						</span>';
                }	
			else{
}
			$iplus=$iplus+1;	
		}
$str.='</div>';
		$str .='[&&]'.$footerlink;
		echo $str;
	    exit;
	}
	function videosinstanceAction()
	{
	$db= new NesoteDALController();
		$valid=$this->uservalidation();
		$this->setValue("valid",$valid);
		$keyword=$_POST['search'];// reading search keyword
		$quotestatus=get_magic_quotes_gpc();
		if($quotestatus==1)
		$keyword=stripslashes($keyword);
		$tabname=$_POST['type'];//    reading tab name
		$fl=$_POST['fl'];
			$this->loadLibrary('Settings');
		$settings=new Settings('nesote_inoutse_settings');
		$settings->loadValues();
		$mixing_video_sources=$settings->getValue("video_api_search");
		$nextpage=$_POST['nextpagetkn'];
		if((!isset($_POST['type']))||($_POST['type']==""))
		$tabname="videos";
		if((!isset($_POST['search'])||($_POST['search']=="")))
		$keyword=str_replace("%2NNFF","/",$this->getParam(1));
		$suggestion_keyword=$keyword;
		include('script.inc.php');
		include($config_path.'system.config.php');
		if($fl==1)
		$feelinglucky=1;
		$quotestatus=get_magic_quotes_gpc();
		if($quotestatus==1)
		$keyword=stripslashes($keyword);
		$keyword=str_replace('"',' " ',$keyword);
		$keyword=str_replace("'"," ' ",$keyword);
		$keyword=$this->familyfilter($keyword);
		$keyword=str_replace("' ","'",$keyword);
		$keyword=str_replace(" '","'",$keyword);
		$keyword=str_replace('" ','"',$keyword);
		$keyword=str_replace(' "','"',$keyword);
		$db->select("nesote_inoutse_engines");
		$db->fields("id,search_type");
		$db->where("tab_name=?",$tabname);
		$result=$db->query();
		$row=$db->fetchRow($result);
		$searchtype=$row[1];  // reading search type
		$engineid=$row[0];  // reading engine id
		$tot=$db->total("nesote_inoutse_engines","tab_name=? and status=?",array($tabname,1));
		if(($keyword=="")||($tot==0))
		{
			echo "no result2";exit;
		}
		$this->loadLibrary('Settings');
		$settings=new Settings('nesote_inoutse_settings');
		$settings->loadValues();
		$mixing_video_status=$settings->getValue("mixing_video_status");
		$page=1;
		if(isset($_POST['startpage']))
		$page=$_POST['startpage'];   // reading page value
		if($page=="")
		$page=1;
		//echo $page; exit;
		$tabkeyword=str_replace("/","%2NNFF",$keyword);
		$this->loadLibrary('Settings');
		$settings=new Settings('nesote_inoutse_settings');
		$settings->loadValues();
		$count=$settings->getValue("image_result_count");
		$servicename=$settings->getValue("service_name");
		$source_status=$settings->getValue("source_status");
		$styleid=$settings->getValue("result");
		$relatedtag_count=$settings->getValue("related_tags_count");
		$seasonal_logo_status=$settings->getValue("seasonal_logo");
		$star_status=$settings->getValue("star_status");
		$member_status=$settings->getValue("member_status");
		if($member_status==1)
		$comment_status=$settings->getValue("comment_status");
		else
		$comment_status=0;
		$this->setValue("comment_status",$comment_status);
		$video_api_status=$settings->getValue("video_api_search");
		$this->setValue("yahooboss_status",$video_api_status);
		$xmldata=$this->getmixurlcontents($engineid,$searchtype,$page,$keyword,1,$nextpage);
		$cacheparts=explode("&@&",$xmldata);
		$cachepart1=$cacheparts[0];
		$cachepart2=$cacheparts[1];
		$cachenext=$cacheparts[2];
		$cacheprev=$cacheparts[3];
		$cacheresult=json_decode($cachepart2);
		$cacheresultd = json_decode($cachepart1, true);
 		$start=$cacheresultd['start'];
 		$totalcount=$cacheresultd['totalcount'];
 		$backupcount=$cacheresultd['backupcount'];
 		$allstatus=$cacheresultd['allstatus'];
 		$onlygooglestatus=$cacheresultd['onlygooglestatus'];
 		$cachenext = json_decode($cachenext, true);
 		$next=$cachenext[0];
 		$cacheprev = json_decode($cacheprev, true);
 		$prev=$cacheprev[0];
		$xmldata=str_replace("\r\n","",$xmldata);
		$xmldata=str_replace("\n","",$xmldata);
		$xmldata=str_replace("\r","",$xmldata);
		if($xmldata=="expired")
		{
			if($mod_rewrite==true)
			header("Location:".$this->url("search/noresults?search=$keyword&type=$searchtype&status=$xmldata"));
			else
			header("Location:".$this->url("search/noresults&search=$keyword&type=$searchtype&status=$xmldata"));
			exit(0);
		}
         $totalhits=$totalcount;
		if($allstatus==0)
		{
			$total=$backupcount; 
			$total1=$totalhits;
		}
		else
		{
			$total=$totalhits;
			$total1=$totalhits;
		}
		$stnum=$start;
		$stnumber=$stnum;
		$this->setValue("totalhits",$total);
		$this->setValue("total",$total);
		$cacheresultcount=0;
		foreach($cacheresult->item as $mydata)
		{
		$cacheresultcount=$cacheresultcount+1;
		}
		if($cacheresultcount==0)
		{
			echo "no result";exit;
		}
		$message=array("servicename"=>$servicename);
		$home=$this->getmessagegrammer(47,$message,0);
		$enginename=$this->getenginename($engineid);
		define('PAGETITLE',$servicename." - ".$enginename." - ".$keyword);
$this->setValue('pagetitle',$servicename." - ".$enginename." - ".$keyword);
		define('HEADERKEYWORD',$servicename.",search,search engine,".$keyword.",".$searchtype);
		$typearray=array("type"=>$enginename);
		$typesearch=$this->getmessagegrammer(23,$typearray);
		$start=((15*($page-1))%$count);
		$startingnum=($page*15)-14;
		$endingnum=$page*15;
		if($total<$endingnum)
		$endingnum=$total;
		if($total<15)
		$startingnum=1;
		else
		$startingnum=($page*15)-14;
		$totalstring=number_format($total1);
		$message=array("startingnum"=>$startingnum,"endingnum"=>$endingnum,"total"=>$totalstring,"keyword"=>htmlentities($keyword,ENT_QUOTES,"UTF-8"));
		$style=array("resultcountstart","resultcountend","totalresults","keywordintotal");
		$totalstr=$this->getmessagegrammer(8,$message,$style);
		$keyword1=urlencode($keyword);
		$keywordsuggestion_status=$db->total("nesote_inoutse_engines","id=? and keyword_suggestion_status=1",array($engineid));
		if($page==1 && $keywordsuggestion_status!=0 && trim($suggestion_keyword)==trim($keyword))
		{
			$tot1=$db->total("nesote_inoutse_keywordsuggestions","engine_id=? and keyword=?",array($engineid,$suggestion_keyword));
			if($tot1==0)
			{
				$db->insert("nesote_inoutse_keywordsuggestions");
        		$db->fields("engine_id,keyword,total,searchcount,time");
        		$db->values(array($engineid,$suggestion_keyword,$total1,1,time()));
        		$db->query();
			}
			else
			{
				$db->update("nesote_inoutse_keywordsuggestions");
				$db->set("searchcount=searchcount+1,time=?,total=?",array(time(),$total1));
				$db->where("engine_id=? and keyword=?",array($engineid,$suggestion_keyword));
				$db->query();
			}
		}
		$previouspage=$page-1;
if($page<=4)
		{
			$startpage=1;
			$endpage=5;
		}
		else
		{
			$startpage=$page-3;
			$endpage=$page+1;
		}
		$nextpage=$page+1;
		if($page!=1)
		{
		$footerlink.="<li class=\"pgntn-li float-left\"><a class=\"pgntn-a pgn-arw\" href=javascript:loadpage($previouspage,'$prev')><i class=\"fas fa-chevron-left\"></i></a></li>";
		}
		if($page*10<($total))
		{
		$footerlink.="<li class=\"pgntn-li float-left\"><a class=\"pgntn-a pgn-arw\" href=javascript:loadpage($nextpage,'$next')><i class=\"fas fa-chevron-right\"></i></a></li>";
		}
		$j=0;
	$resultset=[];
foreach($cacheresult->item as $mydata)
    {
         $resultset[1][]=$mydata->title;
    }
foreach($cacheresult->item as $mydata)
    {
         $resultset[2][]=$mydata->titleurl;
    }
foreach($cacheresult->item as $mydata)
    {
         $resultset[3][]=$mydata->imageurl;
    }
    foreach($cacheresult->item as $mydata)
    {
         $resultset[4][]=$mydata->duration;
    }
		$finalresult2=$resultset;
		if($cacheresultcount==0)
		{
			echo "no result";exit;
		}
		$s=($page-1)*15-$stnumber; $u=0;
		$rescnt=$cacheresultcount;
		if($rescnt>=$s+15)
		{
			for($i=0;$i<15;$i++)
			{
				if($resultset[4][$s]!="")
				{
					$finalresult[$u][1]=$resultset[3][$s];
					if(strlen($finalresult[$u][1])>=150)
					{  $len=strlen($finalresult[$u][1]);
					$p=strpos($finalresult[$u][1]," ");
					if(($p=="")||($p>150))
					{  
						$fir=substr($finalresult[$u][1],0,150);
						$sec=substr($finalresult[$u][1],151,$len);
						$finalresult[$u][1]=$fir." ".$sec;
					}
					}
					$finalresult[$u][2]=$resultset[4][$s];
					if(strlen($finalresult[$u][2])>=60)                            
					$finalresult[$u][2]=substr($finalresult[$u][2],0,60)."...";
					$finalresult[$u][3]=$resultset[1][$s];                           
					if(strlen($finalresult[$u][3])>=100)
					$finalresult[$u][3]=substr($finalresult[$u][3],0,100)."...";
					$finalresult[$u][4]=$resultset[2][$s];
					$finalresult[$u][5]=$statusarray[1][$u];
					$finalresult[$u][6]=$this->getstar($finalresult[$u][4],$engineid);
					$u++;
				}
				$s=$s+1;
			}
		}
		else if($total-$startingnum+1>15)
		{
			$s= $rescnt-15;
			for($i=0;$i<15;$i++)
			{
				if($resultset[4][$s]!="")
				{
					$finalresult[$u][1]=$resultset[3][$s];
					if(strlen($finalresult[$u][1])>=150)
					{  $len=strlen($finalresult[$u][1]);
					$p=strpos($finalresult[$u][1]," ");
					if(($p=="")||($p>150))
					{   
						$fir=substr($finalresult[$u][1],0,150);
						$sec=substr($finalresult[$u][1],151,$len);
						$finalresult[$u][1]=$fir." ".$sec;
					}
					}
					$finalresult[$u][2]=$resultset[4][$s];
					if(strlen($finalresult[$u][2])>=60)                             
					$finalresult[$u][2]=substr($finalresult[$u][2],0,60)."...";
					$finalresult[$u][3]=$resultset[1][$s];                           
					if(strlen($finalresult[$u][3])>=100)
					$finalresult[$u][3]=substr($finalresult[$u][3],0,100)."...";
					$finalresult[$u][4]=$resultset[2][$s];
					$finalresult[$u][5]=$statusarray[1][$u];
					$finalresult[$u][6]=$this->getstar($finalresult[$u][4],$engineid);
					$u++;
				}
				$s=$s+1;
			}
		}
		else if($total-$startingnum+1>0)
		{
			$finish=$total-$startingnum+1;
			$statf=0;
			$s=0;
			for($i=0;$i<$finish;$i++)
			{
				if($resultset[4][$s]!="")
				{
					$finalresult[$u][1]=$resultset[3][$s];
					if(strlen($finalresult[$u][1])>=150)
					{  $len=strlen($finalresult[$u][1]);
					$p=strpos($finalresult[$u][1]," ");
					if(($p=="")||($p>150))
					{   
						$fir=substr($finalresult[$u][1],0,150);
						$sec=substr($finalresult[$u][1],151,$len);
						$finalresult[$u][1]=$fir." ".$sec;
					}
					}
					$finalresult[$u][2]=$resultset[4][$s];
					if(strlen($finalresult[$u][2])>=60)                             
					$finalresult[$u][2]=substr($finalresult[$u][2],0,60)."...";
					$finalresult[$u][3]=$resultset[1][$s];                           
					if(strlen($finalresult[$u][3])>=100)
					$finalresult[$u][3]=substr($finalresult[$u][3],0,100)."...";
					$finalresult[$u][4]=$resultset[2][$s];
					$finalresult[$u][5]=$statusarray[1][$statf];
					$finalresult[$u][6]=$this->getstar($finalresult[$u][4],$engineid);
					$u++; $statf++;
				}
				$s=$s+1;
			}
		}
		else
		{
			echo "no result";exit;
		}
		if(($page==1)&&($feelinglucky==1))
		{
			header("Location:".strip_tags($finalresult[0][4]));
			exit(0);
		}
$finalcount=count($finalresult);
		if($finalcount==0)
		{
		echo "no result";exit;
		}
		
	$str="";
	$str.='[&&]';$str.=$totalstr;$str.='[&&]';$str.=$typesearch;$str.='[&&]';
	$iplus=($page-1)*15;
		for($i=0;$i<$finalcount;$i++)
		{
		$iplus=$iplus+1;	
			$p1=$this->urlencode($finalresult[$i][4]);
			$p2=$this->getdomain($finalresult[$i][4]);
$str.='<div class="cmnt-pop" id="cmnt-pop'.$iplus.'">
<div class="close-cmnt-bt"><img class="cls-ic clseimg"  onclick="javascript:closeimage('.$iplus.');" id="clseimg'.$iplus.'" src="images/close-ic.png" alt="close"></div>
    <div class="cmnt-pop-inner">
	<h4 class="text-black">View Comments</h4>
		<div>
</div>
<div class="drp-cmnt-area fullwidth">
		<div class="cmnt-drp-outer drp-cmnt-v fullwidth" id="oldercomments'.$iplus.'">
'.$this->getcommentsnwvideo($finalresult[$i][4]).'
			</div>
		</div>
        <input type="hidden" name="titleurl" id="titleurl'.$iplus.'" value="'.$this->urlencode($finalresult[$i][4]).'">
	<input type="hidden" name="domainurl" id="domainurl'.$iplus.'" value="'.$this->getdomain($results[4]).'">';
if($valid!=1){
$str.='&nbsp;<span style="color: #686868;font-style: italic;"><br>'.$this->getmessage(608).'</span>';
}else{
$str.='<textarea class="rslt-cmnt-area" placeholder="Enter Your Comments." id="comment'.$iplus.'" type="text"></textarea>
<span class=" cmt_error_msg" id="cmterror'.$iplus.'"></span>
<button class="float-right rslt-cmnt-btn" type="button"  onclick="postcomment('.$iplus.')">Send</button>';
}
		$str.='</div>
</div>';
$str.='<div class="col-md-3 col-sm-4">
			    <div class="video-inner">
				    <div class="video-thumb fullwidth float-left position-relative"><a href="'.$finalresult[$i][4].'"><img src="'.$finalresult[$i][1].'" alt="video thumbnail" width="100%"></a>
					<div class="position-absolute video-ply"><i class="fas fa-play"></i>'.$this->getyoutubeduration($finalresult[$i][2]).'</div>
					</div> 
					<div class="video-dtl fullwidth float-left">
					<p class="vdo-ttl text-black">'.$this->gettitle($finalresult[$i][3],$keyword).'</p>
<span class="video-view">'.$this->getsourcestatus($finalresult[$i][2],1).'</span>
<a class="rslt-lnk rslt-cmnt pl-0" onclick="javascript:showpopup('.$iplus.')" id="'.$iplus.'"><i class="fas fa-comments rslt-lnk-ic"></i> Comments (<span id="comcount'.$iplus.'">'.$this->getcmntcount($finalresult[$i][4]).'</span>)</a>';
		if($valid==1)
		{
			if($star_status==1)
			{					
			if($finalresult[$i][6]=="1")
			{
							$str.='
                   <a href="javascript:unclick(\''.$this->encode($finalresult[$i][1]).'\',\''.$iplus.'\',\''.$this->encode($finalresult[$i][3]).'\',\''.$this->encode($finalresult[$i][2]).'\',\''.$this->encode($finalresult[$i][4]).'\',\''.$engineid.'\')" ><span id="span1'.$iplus.'" class="add_favourites " ><i class="fas fa-star" title="'.$this->getmessage(640).'"></i></span></a>
							<a href="javascript:click(\''.$this->encode($finalresult[$i][1]).'\',\''.$iplus.'\',\''.$this->encode($finalresult[$i][3]).'\',\''.$this->encode($finalresult[$i][2]).'\',\''.$this->encode($finalresult[$i][4]).'\',\''.$engineid.'\')" ><span id="span2'.$iplus.'" class="add_favourites " style="display: none;" title="'.$this->getmessage(640).'"> <i class="far fa-star"></i></span></a>';
						}
				if($finalresult[$i][6]=="0")
				{
							$str.='
							<a href="javascript:click(\''.$this->encode($finalresult[$i][1]).'\',\''.$iplus.'\',\''.$this->encode($finalresult[$i][3]).'\',\''.$this->encode($finalresult[$i][2]).'\',\''.$this->encode($finalresult[$i][4]).'\',\''.$engineid.'\')" ><span class="add_favourites" id="span2'.$iplus.'" class="add_favourites"  title="'.$this->getmessage(641).'"> <i class="far fa-star"></i></span></a>
							<a href="javascript:unclick(\''.$this->encode($finalresult[$i][1]).'\',\''.$iplus.'\',\''.$this->encode($finalresult[$i][3]).'\',\''.$this->encode($finalresult[$i][2]).'\',\''.$this->encode($finalresult[$i][4]).'\',\''.$engineid.'\')" ><span id="span1'.$iplus.'" class="add_favourites  " style="display: none;"title="'.$this->getmessage(641).'"> <i class="far fa-star"></i></i></span></a>
							';
				}					
			}
		}
					$str.='</div>
				</div>
		</div>';
		}
		$str .="[&&]".$footerlink;
		$str.="[&&]".$next;
		echo  $str;
		exit;
	}
	function rsssourceinstanceAction()
	{
		$valid=$this->uservalidation();
		$this->setValue("valid",$valid);
		$keyword=$_POST['search'];// reading search keyword
		$quotestatus=get_magic_quotes_gpc();
		if($quotestatus==1)
		$keyword=stripslashes($keyword);
		$tabname=$_POST['type'];//    reading tab name
		$fl=$_GET['fl'];
		if((!isset($_POST['type']))||($_POST['type']==""))
		$tabname=$this->getParam(1);
		if((!isset($_POST['search'])||($_POST['search']=="")))
		$keyword=str_replace("%2NNFF","/",$this->getParam(2));
		$suggestion_keyword=$keyword;
		include('script.inc.php');
		include($config_path.'system.config.php');
		if($fl==1)
		$feelinglucky=1;
		$quotestatus=get_magic_quotes_gpc();
		if($quotestatus==1)
		$keyword=stripslashes($keyword);
		$keyword=str_replace('"',' " ',$keyword);
		$keyword=str_replace("'"," ' ",$keyword);
		$keyword=$this->familyfilter($keyword);
		$keyword=str_replace("' ","'",$keyword);
		$keyword=str_replace(" '","'",$keyword);
		$keyword=str_replace('" ','"',$keyword);
		$keyword=str_replace(' "','"',$keyword);
		$db= new NesoteDALController();
		$db->select("nesote_inoutse_engines");
		$db->fields("id,search_type");
		$db->where("tab_name=?",$tabname);
		$result=$db->query();
		$row=$db->fetchRow($result);
		$searchtype=$row[1];  // reading search type
		$engineid=$row[0];  // reading engine id
		$db= new NesoteDALController();
		$tot=$db->total("nesote_inoutse_engines","tab_name=? and status=?",array($tabname,1));
		if(($keyword=="")||($tot==0))
		{
				echo "no results";	exit(0);
		}
		$page=1;
		if(isset($_POST['startpage']))
		$page=$_POST['startpage'];   // reading page value
		if ($page=="")
		$page=1;
		$tabkeyword=str_replace("/","%2NNFF",$keyword);
		$this->setValue("keyword",$tabkeyword);
		$this->setValue("tabname",$tabname);
		$this->setValue("engineid",$engineid);
		$this->loadLibrary('Settings');
		$settings=new Settings('nesote_inoutse_settings');
		$settings->loadValues();
		$count=$settings->getValue("rss_resultcount");
		$styleid=$settings->getValue("result");
		$thumbshotstatus=$settings->getValue("thumbshot");
		if($_COOKIE['thumbshot']=="off")
		$thumbshotstatus=0;
		$newwindow=$settings->getValue("new_window");
		$emailafrnd=$settings->getValue("email_a_frnd");
		$quicklook=$settings->getValue("quicklook");
		$servicename=$settings->getValue("service_name");
		$ad_codes=$settings->getValue("ad_codes");
		$relatedtag_count=$settings->getValue("related_tags_count");
		$seasonal_logo_status=$settings->getValue("seasonal_logo");
		$star_status=$settings->getValue("star_status");
		$member_status=$settings->getValue("member_status");
		if($member_status==1)
		$comment_status=$settings->getValue("comment_status");
		else
		$comment_status=0;
		$typearray=array("type"=>$enginename);
		$typesearch=$this->getmessagegrammer(23,$typearray);
		$this->setValue("typesearch",$typesearch);
		$db->select("nesote_inoutse_engines");
		$db->fields("hidden_keyword");
		$db->where("id=?",$engineid);
		$rest=$db->query();
		$frow=$db->fetchRow($rest);
		$hiddenkeyword=$frow[0];   /////////// reading hidden keyword
		if($hiddenkeyword!="")
		$keyword.=" ".$hiddenkeyword;
		$pagetmp=$page;
		if($page%($count/10)==0)
		$pagetmp=$pagetmp-1;
		$startpage=($pagetmp-($pagetmp%($count/10)))*10;
		require("script.inc.php");
		require($config_path."system.config.php");
		$urlreplaces=array();
		$var=$_SERVER['SCRIPT_NAME'];
		$var=substr($var,0,strrpos($var,"/"));
		$hostdir= "http://".$_SERVER['HTTP_HOST']."".$var."/";
		$url=$hostdir."admin/index.php?page=rss/rssresult/$engineid&search=".urlencode($keyword)."&start=$startpage&count=$count";
		$xmldata=$this->geturlcontent($url,$engineid,$keyword);
		$xmldata=str_replace("\r\n","",$xmldata);
		$xmldata=str_replace("\n","",$xmldata);
		$xmldata=str_replace("\r","",$xmldata);
		preg_match("/<total>(.+?)<\/total>/i",$xmldata,$totalcount);
		$total=$totalcount[1];
		$resultset=="";
		if($total>0)
		{
			preg_match_all("/<item><data><title>(.+?)<\/title><description>(.+?)<\/description><url>(.+?)<\/url>\<\/data><\/item>/i",$xmldata,$resultset);
		}
		if(count($resultset[0])==0)
		{
			echo "no results";	exit(0);
		}
		$start=(10*($page-1))%$count;
		$startingnum=($page*10)-9;
		$endingnum=$page*10;
		if($total<$endingnum)
		$endingnum=$total;
		if($total<10)
		$startingnum=1;
		else
		$startingnum=($page*10)-9;
		$totalstring=number_format($total);
		$message=array("startingnum"=>$startingnum,"endingnum"=>$endingnum,"total"=>$totalstring,"keyword"=>htmlentities($keyword,ENT_QUOTES,"UTF-8"));
		$style=array("resultcountstart","resultcountend","totalresults","keywordintotal");
		$totalstr=$this->getmessagegrammer(8,$message,$style);
		$this->setValue("total",$totalstr);
		$keyword1=urlencode($keyword);
		$keywordsuggestion_status=$db->total("nesote_inoutse_engines","id=? and keyword_suggestion_status=1",array($engineid));
		if($page==1 && $keywordsuggestion_status!=0 && trim($suggestion_keyword)==trim($keyword))
		{
			$tot1=$db->total("nesote_inoutse_keywordsuggestions","engine_id=? and keyword=?",array($engineid,$suggestion_keyword));
			if($tot1==0)
			{
				$db->insert("nesote_inoutse_keywordsuggestions");
        		$db->fields("engine_id,keyword,total,searchcount,time");
        		$db->values(array($engineid,$suggestion_keyword,$total,1,time()));
        		$db->query();
			}
			else
			{
				$db->update("nesote_inoutse_keywordsuggestions");
				$db->set("searchcount=searchcount+1,time=?,total=?",array(time(),$total));
				$db->where("engine_id=? and keyword=?",array($engineid,$suggestion_keyword));
				$db->query();
			}
		}
		$db->select("nesote_inoutse_rssengines");
		$db->fields("source_description,thumbshots_status");
		$db->where("engineid=?",$engineid);
		$result=$db->query();
		$row=$db->fetchRow($result);
		$thumbshots_status=$row[1];
		if($thumbshots_status==1)
		$this->setValue("rssthumbstatus",1);
		else
		$this->setValue("rssthumbstatus",0);
		$j=0;
		for($i=$start;$i<=($start+9)&& $i<=$total;$i++)
		{
			if($resultset[1][$i]=="")
			break;
			if(($i==0)&&($feelinglucky==1))
			{
				header("Location:".strip_tags($resultset[3][$i]));
				exit(0);
			}
			$finalresult[$j][1]=$this->makebold($resultset[1][$i],$keyword,1);//title
			$finalresult[$j][2]=$this->makebold($resultset[2][$i],$keyword,1);//description
			$finalresult[$j][3]=html_entity_decode($resultset[3][$i]);//url
			$finalresult[$j][4]=$this->makebold(substr($resultset[3][$i],7),$keyword,0);//displayurl
			$finalresult[$j][5]=$this->getstar($finalresult[$j][3],$engineid);
			$j++;
		}
$finalcount=count($finalresult);
		if($finalcount==0)
		{
			echo "no results";	exit(0);
		}
		
		$str="";
	$str.='[&&]';$str.=$totalstr;$str.='[&&]';$str.=$typesearch;$str.='[&&]';
	$iplus=($page-1)*10;
		for($i=0;$i<$finalcount;$i++)
		{
			$str.='<li class="result_li">';
                if(($thumbshotstatus==1) && ($thumshot_url!=""))	
                {	
                 $str.='<div id="thumbshot$i" class="web_thumb_imge">
                  <a href="'.$finalresult[$i][3].'" alt="'.strip_tags($finalresult[$i][4]).'" title="'.strip_tags($finalresult[$i][4]).'">
                   <img class="web_thumb_img"  src="'.$thumshot_url.$finalresult[$i][3].'" /> 
                   </a>
                   </div>';
                }
                   else
                   {
                  $str.='<div id="thumbshot'.$iplus.'" class="web_thumb_imge">
                     &nbsp;
                     </div>';
                   }
                 $str.= '<div class="web_rslt_txt">
                    <div class="web_result_title">';
                 if($this->getalignment()!=2)
                 {
                 $str.=' <a href="'.$finalresult[$i][3].'" class="web_result_link"> '.strip_tags($finalresult[$i][1]).' </a>'; 
                 }  if($openin_newwindow==1) 
                    {
                   $str.='<a target="_blank" class="web_result_link"
							href="'.$finalresult[$i][3].'" alt="'.$this->getmessage(3).'" title="'.$this->getmessage(3).'"><i class="fa fa-external-link fa_color fa_bold" title="'.$this->getmessage(3).'"></i> </a>';
                    }
					$str.='<!-- Ulitmate7 -->';
							if($valid==1)
							{
							if($star_status==1)	
							{				
							if($finalresult[$i][5]=="images/fullstar.gif")
							{
                            	$str.='<span id="span1'.$iplus.'" style=""><a href="javascript:unclick(\''.$this->encode($finalresult[$i][2]).'\',\''.$iplus.'\',\''.$this->encode($finalresult[$i][1]).'\',\''.$this->encode($finalresult[$i][4]).'\',\''.$this->encode($finalresult[$i][3]).'\',\''.$engineid.'\')">
							<img src="images/fullstar.gif" border="0"  id="img1'.$iplus.'"></a></span>
							<span id="span2'.$iplus.'" style="display: none;"><a href="javascript:click(\''.$this->encode($finalresult[$i][2]).'\',\''.$iplus.'\',\''.$this->encode($finalresult[$i][1]).'\',\''.$this->encode($finalresult[$i][4]).'\',\''.$this->encode($finalresult[$i][3]).'\',\''.$engineid.'\')">
							<img src="images/greystar.gif" border="0"  id="img2'.$iplus.'"></a></span>';
							}
							if($finalresult[$i][5]=="images/greystar.gif")
							{
							$str.='<span id="span2'.$iplus.'" style=""><a href="javascript:click(\''.$this->encode($finalresult[$i][2]).'\',\''.$iplus.'\',\''.$this->encode($finalresult[$i][1]).'\',\''.$this->encode($finalresult[$i][4]).'\',\''.$this->encode($finalresult[$i][3]).'\',\''.$engineid.'\')">
							<img src="images/greystar.gif" border="0"  id="img2'.$iplus.'"></a></span>								
							<span id="span1'.$iplus.'" style="display: none;"><a href="javascript:unclick(\''.$this->encode($finalresult[$i][2]).'\',\''.$iplus.'\',\''.$this->encode($finalresult[$i][1]).'\',\''.$this->encode($finalresult[$i][4]).'\',\''.$this->encode($finalresult[$i][3]).'\',\''.$engineid.'\')">
							<img src="images/fullstar.gif" border="0"  id="img1'.$iplus.'"></a></span>';
							}
							}}
				if($this->getalignment()==2)
                 {
                 $str.=' <a href="'.$finalresult[$i][3].'" class="web_result_link"> '.strip_tags($finalresult[$i][1]).' </a>'; 
                 } 
				$str.='<!-- Ulitmate7 -->';
				$str.='</div>
                    <div class="web_resultdescription">
                      <p class="rslt_dscrptn_p"> '.$finalresult[$i][2].' </p>
                    </div>
                    <div class="web_result_bottom">
                      <div class="web_resulturl"> '.$finalresult[$i][4].' '.$this->getbreak($finalresult[$i][4]).'</div>';
                      $str.='<div class="bottom_web_reultlinks">'; 
                      if($emailafrnd==1)
                      {
                      $str.='<span class="web_rslt_emaillink"> <i class="fa fa_color fa-envelope"></i> <A
							class="email_link"
							HREF="javascript:popUp(\''.$this->createlink($finalresult[$i][3]).'\')">'.$this->getmessage(27).'</A>
							</span> ';
                      }
                      if($quicklook==1)
                      {
                     $str.='<span  id="qlook'.$iplus.'" class="web_rslt_quicklink"> <i id="qlook_bti'.($iplus+1).'" class="fa fa_color fa-chevron-circle-right"></i>
                     <a class="email_link"
							id="qlook_btn'.($iplus+1).'"
							href="javascript:qlook('.($iplus+1).',\''.$this->getmessage(39).'\',\''.$this->getmessage(41).'\',\''.$this->getmessage(40).'\')">'.$this->getmessage(39).'</a> </span> 
                     <span id="qlook_spn'.($iplus+1).'" style="display: none;"><i id="qlook_mmi'.($iplus+1).'" class="fa fa_color fa-plus-circle"></i>
                     	&nbsp;<a class="qlook"
							id="qlook_mmb'.($iplus+1).'"
							href="javascript:qlookmm('.($iplus+1).',\''.$this->getmessage(41).'\',\''.$this->getmessage(43).'\')">'.$this->getmessage(41).'</a>
						<span id="qlook_mms'.($iplus+1).'"></span><i  class="fa fa_color fa-home"></i>&nbsp;<a
							class="qlook" id="qlook_ghb'.($iplus+1).'"
							href="javascript:qlookgh('.($iplus+1).')">'.$this->getmessage(42).'</a>
						</span>';
                      }
						$str.='<!-- Ulitmate7 -->';							
					if($comment_status==1)
					{
                      $str.='<span class="web_rslt_comments"> <i class="fa fa_color fa-comments"></i><a class="comments_reslt" href="javascript:comment('.$iplus.')">'.$this->getmessage(579).'&nbsp;(<span id="comcount'.$iplus.'">'.$this->getcmntcount($finalresult[$i][4]).'</span>)</a> </span>'; 
				$str.='<!-- Ulitmate7 -->';
						$str.= '<div class="cmntdivb" id="commentdiv'.$iplus.'" style="display: none;" >
					<div ><div style="display: none;" id="div'.$iplus.'">';
							$str.='<input type="hidden" name="urlenc'.$iplus.'" id="urlenc'.$iplus.'" value="'.urlencode($finalresult[$i][4]).'">';
							$this->getcommentsnw($finalresult[$i][3],$results,"rss");
							$str.='</div>';
								$str.= '<span id="commentbox'.$iplus.'"style="font-size: 12px;font-family:Verdana, Helvetica, sans-serif;">';
							if($valid!=1)
							{
							$str.='&nbsp;<span style="color: #686868;font-style: italic;">'.$this->getmessage(608).'</span>';
							}
							else
							{
							$str.= '<ul class="post_cmntul">
							<li class="post_cmntli">
						<b>'.$this->getmessage(586).'</b></li>
							<li class="post_cmntli">
							<input type="hidden" name="url" id="url'.$iplus.'" value="'.$finalresult[$i][4].'">
							</li>
							<li class="post_cmntli">
							<input type="radio" name="type" id="type2'.$iplus.'" value="title">'.$this->getmessage(581).'&nbsp;
							</li>
							<li class="post_cmntli">
							<input type="radio" name="type" id="type1'.$iplus.'" value="domain"> '.$this->getmessage(587).'							
							</li>
							</ul>
							<textarea id="comment'.$iplus.'" rows="3" cols="0" class="postcomment postcommentimg"></textarea>
							<br>
							<span class="post_cmntbtn" style="float:right;">
							<input class="butn1" type="submit" name="post" value="'.$this->getmessage(580).'" onclick="postcomment('.$iplus.')">
							</span>';
							}
						$str.='
							</span></div>
                    </div>';
    						}   
    						$str.='</div>';
                    $str.= '</div>
                  </div>
                </li> ';
                if($quicklook==1)
                {
				$str.='<span id="qlookframe'.($iplus).'" style="'.$this->getqlookdisplaystatus().'" width="100%">
						<iframe class="qickfrmeifrmae"	id="qlook_fra'.($iplus+1).'" src="" src1="'.$finalresult[$i][4].'"
							loaded="0" width="99%" height="300" scrolling="auto"
							style="display: none; margin-top: 3px;"></iframe>
						<div align="center" id="qlook_lsi'.($iplus+1).'"
							style="display: none; margin: 0;" width="100%"><img
							src="images/qlook/q_l10.gif" alt="Loading..." width="239"
							height="20" style="margin-top: 20px; margin-bottom: 250px;" /></div>
						</span>';
                }	
			else
{
}
			$iplus=$iplus+1;	
		}
		$str .='[&&]'.$footerlink;
		echo $str;
	    exit;
	}
function twitterinstanceAction()
	{
		///////////////////////// Ultimate7 /////////////////////////////////////
		$valid=$this->uservalidation();
		$keyword=$_POST['search']; //reading search keyword
		$quotestatus=get_magic_quotes_gpc();
		if($quotestatus==1)
		$keyword=stripslashes($keyword);
		$tabname=$_POST['type']; //reading tab name
		$fl=$_POST['fl'];
		if((!isset($_POST['type']))||($_POST['type']==""))
		$tabname="twitter";
		if((!isset($_POST['search'])||($_POST['search']=="")))
		$keyword=str_replace("%2NNFF","/",$this->getParam(1));
		$suggestion_keyword=$keyword;
		include('script.inc.php');
		include($config_path.'system.config.php');
		if($fl==1)
		$feelinglucky=1;
		$quotestatus=get_magic_quotes_gpc();
		if($quotestatus==1)
		$keyword=stripslashes($keyword);
		$keyword=str_replace('"',' " ',$keyword);
		$keyword=str_replace("'"," ' ",$keyword);
		$keyword=$this->familyfilter($keyword);
		$keyword=str_replace("' ","'",$keyword);
		$keyword=str_replace(" '","'",$keyword);
		$keyword=str_replace('" ','"',$keyword);
		$keyword=str_replace(' "','"',$keyword);
		$db= new NesoteDALController();
		$db->select("nesote_inoutse_engines");
		$db->fields("id,search_type");
		$db->where("tab_name=?",$tabname);
		$result=$db->query();
		$row=$db->fetchRow($result);
		$searchtype=$row[1]; //reading search type
		$engineid=$row[0];   //reading engine id
		$db= new NesoteDALController();
		$tot=$db->total("nesote_inoutse_engines","tab_name=? and status=?",array($tabname,1));
		if(($keyword=="")||($tot==0))
		{
			$str="no result"; echo $str; exit;
		}
		$page=1;
		if(isset($_POST['startpage']))
		$page=$_POST['startpage'];   // reading page value
		if ($page=="")
		$page=1;
		$tabkeyword=str_replace("/","%2NNFF",$keyword);
		$this->loadLibrary('Settings');
		$settings=new Settings('nesote_inoutse_settings');
		$settings->loadValues();
		$count=$settings->getValue("twitter_result_count");// read no of results to be fetched for ebay from settings
		$relatedtag_count=$settings->getValue("related_tags_count");
		$styleid=$settings->getValue("result");
		$openin_newwindow=$settings->getValue("new_window");
		$emailafrnd=$settings->getValue("email_a_frnd");
		$quicklook=$settings->getValue("quicklook");
		$servicename=$settings->getValue("service_name");
		$quicklook_user_override=$settings->getValue("quicklook_user_override");
		$ad_codes=$settings->getValue("ad_codes");
		///////////////////////// Ultimate7 /////////////////////////////////////
		$star_status=$settings->getValue("star_status");
		$member_status=$settings->getValue("member_status");
		if($member_status==1)
		$comment_status=$settings->getValue("comment_status");
		else
		$comment_status=0;
		$tab_status=$settings->getValue("tabstatus");
		////////////////////////////////////////////////////////////////////////
		$message=array("servicename"=>$servicename);
		$home=$this->getmessagegrammer(47,$message,0);
		$enginename=$this->getenginename($engineid);
		define('PAGETITLE',$servicename." - ".$enginename." - ".$keyword);
$this->setValue('pagetitle',$servicename." - ".$enginename." - ".$keyword);
		define('HEADERKEYWORD',$servicename.",search,search engine,".$keyword.",".$searchtype);
		$typearray=array("type"=>$enginename)	;
		$typesearch=$this->getmessagegrammer(23,$typearray);
		$url=$this->geturl($engineid,$searchtype,$keyword,$page);
		$xmldata=$this->geturlcontent($url,$engineid,$keyword);
		$result1=array();
		foreach ($xmldata->statuses as $result)
		{
			$result1[]=array('text'=>$result->text,
    		'desc'=>$result->user->description,
    		'imgurl'=>$result->user->profile_image_url,
    		'url'=>$result->user->url,
    		'auther'=>$result->user->name,
    		'autheurl'=>$result->user->profile_image_url);
		}
		for($i=0;$i<count($result1);$i++)
		{
			$resultset[1][$i]=strip_tags($result1[$i]['text']);
			$resultset[2][$i]=strip_tags($result1[$i]['desc']);
			$resultset[3][$i]=strip_tags($result1[$i]['imgurl']);
			$resultset[4][$i]=strip_tags($result1[$i]['url']);
			$resultset[5][$i]=strip_tags($result1[$i]['auther']);
			$resultset[6][$i]=strip_tags($result1[$i]['autheurl']);
		}
		$total=100;
		if(count($resultset[1])==0)
		{
			$str="no result"; echo $str; exit;
		}
		$keyword1=urlencode($keyword);
		$keywordsuggestion_status=$db->total("nesote_inoutse_engines","id=? and keyword_suggestion_status=1",array($engineid));
		if($page==1 && $keywordsuggestion_status!=0 && trim($suggestion_keyword)==trim($keyword))
		{
			$tot1=$db->total("nesote_inoutse_keywordsuggestions","engine_id=? and keyword=?",array($engineid,$suggestion_keyword));
			if($tot1==0)
			{
				$db->insert("nesote_inoutse_keywordsuggestions");
        		$db->fields("engine_id,keyword,total,searchcount,time");
        		$db->values(array($engineid,$suggestion_keyword,$total1,1,time()));
        		$db->query();
			}
			else
			{
				$db->update("nesote_inoutse_keywordsuggestions");
				$db->set("searchcount=searchcount+1,time=?,total=?",array(time(),$total1));
				$db->where("engine_id=? and keyword=?",array($engineid,$suggestion_keyword));
				$db->query();
			}
		}
		$finalkeywordarray=[];
		$j=0;
		$finalresult=[];
			$count=count($resultset[1]);
		for($i=0;$i<$count-1;$i++)
		{
			if(($i==0)&&($feelinglucky==1))
			{
				header("Location:".strip_tags($resultset[2][$i]));
				exit(0);
			}
			$finalresult[$j][1]=$this->makebold(strip_tags($resultset[1][$i]),$keyword,0);//title
			$var=html_entity_decode($resultset[2][$i]);//content
			$var=str_replace("<b>","",$var);
			$var=str_replace("</b>","",$var);
			$finalresult[$j][2]=$this->makebold($var,$keyword,0);
			$finalresult[$j][3]=html_entity_decode($resultset[3][$i]);//imageurl
			$finalresult[$j][4]=trim(html_entity_decode($resultset[4][$i]));//title url
			$finalresult[$j][5]=$this->makebold(strip_tags($resultset[5][$i]),$keyword,0);//author
			$finalresult[$j][6]=$resultset[6][$i];//author url
			$finalresult[$j][7]=$this->getstar($finalresult[$j][4],$engineid);
			$j++;
		}
$finalcount=count($finalresult);
		if($finalcount==0)
		{
		$str="no result"; echo $str; exit;
		}		
		$str="";
	$str.='[&&]';$str.=$totalstr;$str.='[&&]';$str.=$typesearch;$str.='[&&]';
	$iplus=($page-1)*10;
		for($i=0;$i<$finalcount;$i++)
		{
$str.='<div class="float-left fullwidth my-2 rslt-out">';
$str.='
<div class="position-absolute twtr-img-div"><img src="'.$finalresult[$i][3].'" class="twt-img fullwidth" alt="twitter image"></div>
	<div class="rslt-twtr fullwidth">
	    <a class="wb-rslt-a" href="'.$finalresult[$i][4].'" alt="'.strip_tags($finalresult[$i][1]).'" title="'.strip_tags($finalresult[$i][1]).'" target="_blank">
		<h3 class="wb-rslt-hd twt_desc"> '.$finalresult[$i][5].'</a></h3>&nbsp;';
                 if($this->getalignment()!=2)
                 {
                 }  
if($openin_newwindow==1) 
                    {
$str.='<a target="_blank" href="'.$finalresult[$i][4].'"><i class="fas fa-external-link-alt fa_color" title="'.$this->getmessage(3).'"></i></a>';
                    }
					$str.='<!-- Ulitmate7 -->';
							if($valid==1)
							{
							if($star_status==1)	
							{				
							if($finalresult[$i][7]=="1")
							{
                            	$str.='<a href="javascript:unclick('.$this->encode($finalresult[$i][2]).'[::]'.$finalresult[$i][3].','.$iplus.','.$this->encode($finalresult[$i][5]).','.$this->encode($finalresult[$i][6]).','.$this->encode($finalresult[$i][4]).','.$engineid.')" ><span id="span1'.$iplus.'" class="add_favourites" ><i class="fas fa-star" title="'.$this->getmessage(640).'"></i></span></a>
							<a href="javascript:click('.$this->encode($finalresult[$i][2]).'[::]'.$finalresult[$i][3].','.$iplus.','.$this->encode($finalresult[$i][5]).','.$this->encode($finalresult[$i][6]).','.$this->encode($finalresult[$i][4]).','.$engineid.')" ><span class="add_favourites" id="span2'.$iplus.'" style="display: none;" title="'.$this->getmessage(640).'"> <i class="far fa-star"></i></span></a>';
							}
							if($finalresult[$i][7]=="0")
							{
							$str.='<a href="javascript:click('.$this->encode($finalresult[$i][2]).'[::]'.$finalresult[$i][3].','.$iplus.','.$this->encode($finalresult[$i][5]).','.$this->encode($finalresult[$i][6]).','.$this->encode($finalresult[$i][4]).','.$engineid.')" ><span class="add_favourites" id="span2'.$iplus.'" style="" title="'.$this->getmessage(641).'"> <i class="far fa-star"></i></span></a>
							<a href="javascript:unclick('.$this->encode($finalresult[$i][2]).'[::]'.$finalresult[$i][3].','.$iplus.','.$this->encode($finalresult[$i][5]).','.$this->encode($finalresult[$i][6]).','.$this->encode($finalresult[$i][4]).','.$engineid.')" ><span class="add_favourites" id="span1'.$iplus.'" style="display: none;"title="'.$this->getmessage(641).'"> <i class="far fa-star"></i></i></span></a>';
							}
							}}
				if($this->getalignment()==2)
                 {
                 } 
$str.='<p class="wb-rslt-dmn"></p>
<div class="fullwidth twt-cnt">
		<p class="wb-rslt-info twitter_desc">'.html_entity_decode($finalresult[$i][2]).'</p>
		</div>
		</div>
		<div class="float-left ">';
                      if($emailafrnd==1)
                      {
$str.='<a class="rslt-lnk" href="javascript:emailafrnd(\''.$this->createlink($finalresult[$i][9]).'\')" ><i class="fas fa-envelope rslt-lnk-ic" id="email_lnk"></i> '.$this->getmessage(27).'</a>';
                      }
                      if($quicklook==1)
                      {
$str.='<span  id="qlook{loop:results}" class="rslt-lnk qk-look">  <i id="qlook_bti'.($iplus+1).'" class="fas fa-chevron-circle-right rslt-lnk-ic"></i> <a class="rslt-lnk qk-look"
							id="qlook_btn'.($iplus+1).'"
							href="javascript:qlook('.($iplus+1).',\''.$this->getmessage(39).'\',\''.$this->getmessage(41).'\',\''.$this->getmessage(40).'\')">'.$this->getmessage(39).'</a> </span> 
                     <span id="qlook_spn'.($iplus+1).'" style="display: none;"><i id="qlook_mmi'.($iplus+1).'" class="fas fa-plus-circle rslt-lnk-ic"></i>
                    &nbsp;<a class="rslt-lnk qk-look"
							id="qlook_mmb'.($iplus+1).'"
							href="javascript:qlookmm('.($iplus+1).',\''.$this->getmessage(41).'\',\''.$this->getmessage(43).'\')">'.$this->getmessage(41).'</a>
						<span id="qlook_mms'.($iplus+1).'"></span><i class="fa fa-home rslt-lnk-ic" aria-hidden="true"></i>
</i>&nbsp;<a
							class="qlook rslt-lnk qk-look " id="qlook_ghb'.($iplus+1).'"
							href="javascript:qlookgh('.($iplus+1).')">'.$this->getmessage(42).'</a>
						</span>';
                      }
						$str.='<!-- Ulitmate7 -->';							
					if($comment_status==1)
					{
$str.='<a class="rslt-lnk rslt-cmnt  cmnt_new_'.$iplus.'" href="javascript:comment(\''.$iplus.'\')"><i class="fas fa-comments rslt-lnk-ic"></i> '.$this->getmessage(579).'&nbsp;(<span id="comcount'.$iplus.'">'.$this->getcmntcount($finalresult[$i][9]).'</span>)</a>';
    						} 
$str.='</div>';
$str.='<div class="rslt-cmnt-drp" id="cmnt-drp_'.$iplus.'">
<input type="hidden" name="urlenc'.$iplus.'" id="urlenc'.$iplus.'" value="'.urlencode($finalresult[$i][4]).'">
<div class="drp-cmnt-area fullwidth"  id="div'.$iplus.'">';
$this->getcomments($finalresult[$i][9],$results,"twitter");
$str.='</div>';
	if($valid!=1)	{
$str.='&nbsp;<span style="color: #686868;font-style: italic;">'.$this->getmessage(608).'</span>';
}else{
$str.='<input type="hidden" name="url" id="url'.$iplus.'" value="'.$finalresult[$i][4].'">';
$str.='<input type="radio" name="type" id="type2'.$iplus.'" value="title">'.$this->getmessage(581).'&nbsp';
$str.='<input type="radio" name="type" id="type1'.$iplus.'" value="domain">'.$this->getmessage(587).'';
$str.='<textarea class="rslt-cmnt-area" placeholder="Enter Your Comments." type="text" id="comment'.$iplus.'"></textarea>
<span class=" cmt_error_msg" id="cmterror'.$iplus.'"></span>
<button class="float-right rslt-cmnt-btn" onclick="postcomment('.$iplus.')" type="button">Send</button>';
}
$str.='</div>
</div>
<div class="rslt-cmnt-drp notlogin" id="cmnt-drp_nlog_'.$iplus.'">
<textarea class="rslt-cmnt-area" placeholder="'.$this->getmessage(608).'" type="text"></textarea>
</div>';
                if($quicklook==1)
                {
				$str.='<span id="qlookframe'.($iplus).'" style="'.$this->getqlookdisplaystatus().'" width="100%">
						<iframe class="qickfrmeifrmae"	id="qlook_fra'.($iplus+1).'" src="" src1="'.$finalresult[$i][9].'"
							loaded="0" width="99%" height="300" scrolling="auto"
							style="display: none; margin-top: 3px;"></iframe>
						<div align="center" id="qlook_lsi'.($iplus+1).'"
							style="display: none; margin: 0;" width="100%"><img
							src="images/qlook/q_l10.gif" alt="Loading..." width="239"
							height="20" style="margin-top: 20px; margin-bottom: 250px;" /></div>
						</span>';
                }	
			else
			{	
}
			$iplus=$iplus+1;	
		}
		$str .='[&&]'.$footerlink;
		echo $str;
	    exit;
				$str.='[&&]';$str.=$totalstr;$str.='[&&]';$str.=$typesearch;$str.='[&&]';
		$iplus=($page-1)*10;
		$str.='<table border="0" cellpadding="0" cellspacing="0"
	class="resultsetwrapper" align="left">';
		for($i=0;$i<$finalcount;$i++)
		{
		$iplus=$iplus+1;	
			$str.='
	<tr>
		<td class="resultsetwrappertd" align="left">
		<table border="0" cellpadding="0" cellspacing="0" class="resulttable">
			<tr>
               <td class="thumbshottd" align="left" width="1%">
			   <span class="uniq1"><div><a href="'.$finalresult[$i][4].'" alt="'.strip_tags($results[1]).'" title="'.strip_tags($results[1]).'">
			   <img class="twitterthumbshotimage"	src="'.$finalresult[$i][3].'" border="0"/></a></div></span></td>
					<td class="resulttd" valign="top" align="left">
					<table cellpadding="0" cellspacing="0" height="20px" border="0"><tr><td>
					<span class="resulttitle" >
				<a href="'.$finalresult[$i][6].'">'.$finalresult[$i][5].'</a>';
			if($openin_newwindow==1)
			{
			$str.='<a target="_blank" class="resultlink"
					href="'.$finalresult[$i][4].'" alt="'.$this->getmessage(3).'" title="'.$this->getmessage(3).'"><img class="newwindowimage" border="0"
					src="images/nw_blue.gif"></a>';
			}
			$str.='</span>
				</td><td valign="top">
		';
			if($star_status==1)
				{
					if($finalresult[$i][7]=="images/fullstar.gif")
					{
						$str.='
                            <span id="span1'.$iplus.'" style="display: block;float: left;"><a href="javascript:unclick('.$this->encode($finalresult[$i][2]).'[::]'.$finalresult[$i][3].','.$iplus.','.$this->encode($finalresult[$i][5]).','.$this->encode($finalresult[$i][6]).','.$this->encode($finalresult[$i][4]).','.$engineid.')">
							<img src="images/fullstar.gif" border="0"  id="img1'.$iplus.'"></a></span>
							<span id="span2'.$iplus.'" style="display: none;float: left;"><a href="javascript:click('.$this->encode($finalresult[$i][2]).'[::]'.$finalresult[$i][3].','.$iplus.','.$this->encode($finalresult[$i][5]).','.$this->encode($finalresult[$i][6]).','.$this->encode($finalresult[$i][4]).','.$engineid.')">
							<img src="images/greystar.gif" border="0"  id="img2'.$iplus.'"></a></span>';
					}
					if($finalresult[$i][7]=="images/greystar.gif")
					{
						$str.='
							<span id="span2'.$iplus.'" style="display: block;float: left;"><a href="javascript:unclick('.$this->encode($finalresult[$i][2]).'[::]'.$finalresult[$i][3].','.$iplus.','.$this->encode($finalresult[$i][5]).','.$this->encode($finalresult[$i][6]).','.$this->encode($finalresult[$i][4]).','.$engineid.')">
							<img src="images/greystar.gif" border="0"  id="img2'.$iplus.'"></a></span>
							<span id="span1'.$iplus.'" style="display: none;float: left;"><a href="javascript:unclick('.$this->encode($finalresult[$i][2]).'[::]'.$finalresult[$i][3].','.$iplus.','.$this->encode($finalresult[$i][5]).','.$this->encode($finalresult[$i][6]).','.$this->encode($finalresult[$i][4]).','.$engineid.')">
							<img src="images/fullstar.gif" border="0"  id="img1'.$iplus.'"></a></span>';
					}
				}
			$str.='
				</td></tr><tr><td style="line-height: 3px;">&nbsp;</td></tr></table>
				<div class="resultdescription" style="padding-top:5px;padding-bottom:2px;">'.html_entity_decode($finalresult[$i][2]).'
				<br>
				</div>';
		$str.='&nbsp;	 <span> <a href="" class="sharegc ">
                       <img src="images/s_connect.png" alt="share">&nbsp;Connect</a>
                       </span>&nbsp;	
<span><a href="#slide" class="sharegc initialism slide'.$iplus.'_open btn btn-success" onClick="openitpop('.$iplus.')">
<img src="images/share.png" alt="share">&nbsp;Share</a>
</span>&nbsp;
                      ';	
			if($comment_status==1)
			{
			$str.='
					&nbsp;
							<span style="font-weight: normal;"><img class="emaillinkimage"
							src="images/1309159564_comment.png" border="0">&nbsp;<a class="qlook" href="javascript:comment('.$iplus.')">'.$this->getmessage(579).'&nbsp;(<span id="comcount'.$iplus.'">'.$this->getcmntcount($finalresult[$i][4]).'</span>)</a></span>
							';
		}
			$str.='</span> 
						</td>
					</tr>
		</table>
		</td>
	</tr>
							<tr><td class="resulttd" style="padding-left: 10px" colspan="2" width="500px">';
			$str.='<div class="c_areawraper">
							<div style="display: none;" id="div'.$iplus.'">
							<input type="hidden" name="urlenc'.$iplus.'" id="urlenc'.$iplus.'" value="'.$this->urlencode($finalresult[$i][4]).'">';
						$str.=' 	</div>
							<span id="commentbox'.$iplus.'" style="display:none;font-size: 12px;font-family:Verdana, Helvetica, sans-serif;">
				           ';
			$str.=' 	<div class="old_cmtns">
	<ul class="old_cmntul" id="nwcmnt'.$iplus.'">';
			$str.=$this->getcommentsnw($finalresult[$i][4],$finalresult,'twitter');
 $str.='</ul>
</div>';
		$str.='<div class="coment_areagc">';	
			if($valid!=1)
			{
			$str.='&nbsp;<span style="color: #686868;font-style: italic;">'.$this->getmessage(608).'</span>';
			}
			else {
			$str.='<b>'.$this->getmessage(586).'</b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
							<input type="hidden" name="url" id="url'.$iplus.'" value="'.$finalresult[$i][4].'">
							<input type="hidden" name="type" id="type'.$iplus.'" value="title">							<br>
							<textarea id="comment'.$iplus.'" rows="3" cols="101" class="comnt_txtarea"  placeholder="Comments..."></textarea>
							<br>
							<span style="padding-left: 650px">
							<input size="50" type="submit" name="post" class="s_btngc"  value="'.$this->getmessage(580).'" onclick="postcomment('.$iplus.')">
							</span>';
			}
			$str.='</div>
							</span></div>';
		}
	echo $str;exit;
	}
	function itunesinstanceAction()
	{
		$keyword=$_POST['search']; //reading search keyword
		$quotestatus=get_magic_quotes_gpc();
		if($quotestatus==1)
		$keyword=stripslashes($keyword);
		$tabname=$_POST['type']; //reading tab name
		$fl=$_POST['fl'];
		if((!isset($_POST['type']))||($_POST['type']==""))
		$tabname="itunes";
		if((!isset($_POST['search'])||($_POST['search']=="")))
		$keyword=str_replace("%2NNFF","/",$this->getParam(1));
		$suggestion_keyword=$keyword;
		include('script.inc.php');
		include($config_path.'system.config.php');
		if($fl==1)
		$feelinglucky=1;
		$quotestatus=get_magic_quotes_gpc();
		if($quotestatus==1)
		$keyword=stripslashes($keyword);
		$keyword=str_replace('"',' " ',$keyword);
		$keyword=str_replace("'"," ' ",$keyword);
		$keyword=$this->familyfilter($keyword);
		$keyword=str_replace("' ","'",$keyword);
		$keyword=str_replace(" '","'",$keyword);
		$keyword=str_replace('" ','"',$keyword);
		$keyword=str_replace(' "','"',$keyword);
		$db= new NesoteDALController();
		$db->select("nesote_inoutse_engines");
		$db->fields("id,search_type");
		$db->where("tab_name=?",$tabname);
		$result=$db->query();
		$row=$db->fetchRow($result);
		$searchtype=$row[1]; //reading search type
		$engineid=$row[0];   //reading engine id
		$db= new NesoteDALController();
		$tot=$db->total("nesote_inoutse_engines","tab_name=? and status=?",array($tabname,1));
		if(($keyword=="")||($tot==0))
		{
					$str="no result"; echo $str; exit;
		}
		$page=1;
		if(isset($_POST['startpage']))
		$page=$_POST['startpage'];   // reading page value
		if ($page=="")
		$page=1;
		$tabkeyword=str_replace("/","%2NNFF",$keyword);
		$this->setValue("tabname",$tabname);
		$this->setValue("fl",$fl);
		if($mod_rewrite==true)
		$this->setValue("mod","1");
		else
		$this->setValue("mod","0");
		$this->loadLibrary('Settings');
		$settings=new Settings('nesote_inoutse_settings');
		$settings->loadValues();
		$count=$settings->getValue("itune_result_count");// read no of results to be fetched for itune from settings
		$relatedtag_count=$settings->getValue("related_tags_count");
		$styleid=$settings->getValue("result");
		$newwindow=$settings->getValue("new_window");
		$emailafrnd=$settings->getValue("email_a_frnd");
		$quicklook=$settings->getValue("quicklook");
		$servicename=$settings->getValue("service_name");
		$star_status=$settings->getValue("star_status");
		$member_status=$settings->getValue("member_status");
		if($member_status==1)
		$comment_status=$settings->getValue("comment_status");
		else
		$comment_status=0;
		$message=array("servicename"=>$servicename);
		$home=$this->getmessagegrammer(47,$message,0);
		$enginename=$this->getenginename($engineid);
		define('PAGETITLE',$servicename." - ".$enginename." - ".$keyword);
		define('HEADERKEYWORD',$servicename.",search,search engine,".$keyword.",".$searchtype);
		$typearray=array("type"=>$enginename)	;
		$typesearch=$this->getmessagegrammer(23,$typearray);
		$db->select("nesote_inoutse_itune_countries");
		$db->fields("*");
		$db->order("country_name");
		$countrylist=$db->query();
		$this->setLoopValue("countrylist",$countrylist->getresult());
		$country=$_COOKIE["itune_country"];
		if($country=="")
		{
			$country="US";
		}
		$this->setValue("curcountry",$country);
		$db->select("nesote_inoutse_itune_medias");
		$db->fields("id,media");
		$medialist=$db->query();
		$this->setLoopValue("medialist",$medialist->getresult());
		$media=$_COOKIE["itune_media"];
		if($media=="")
		{
			$media="all";
		}
		$url="http://ax.itunes.apple.com/WebObjects/MZStoreServices.woa/wa/wsSearch?term=$keyword&country=$country&media=$media&limit=$count";
		$xmldata=$this->geturlcontent($url,$engineid,$keyword);
		$xmldata=str_replace("\r\n","",$xmldata);
		$xmldata=str_replace("\n","",$xmldata);
		$xmldata=str_replace("\r","",$xmldata);
		$responseobject = json_decode($xmldata, true);
		$countitune=$responseobject['resultCount'];
		$allresponseresults=$responseobject['results'];
		foreach ($allresponseresults as $responseresult)
		{
			if($media!="software")
			$img=$responseresult['artworkUrl100'];
			else
			$img=$responseresult['artworkUrl60'];
			if($media=="ebook")
			{
				$description= substr( strip_tags( $responseresult['description']),0,100);
				$wrapper=$responseresult['wrapperType'];
				if($wrapper=="")
				{
					$wrapper="ebook";
				}
			}
			else
			{
				$description=$responseresult['primaryGenreName'];
				$wrapper=$responseresult['wrapperType'];
			}
			$resultitune[] = array(
						'0' => $wrapper,
		                '1' => $responseresult['kind'],		               
			            '2' => $responseresult['artistName'],
		            	'3' => $responseresult['trackName'],
			            '4' => $responseresult['collectionName'],
			            '5' => $img,
		                '6' => $responseresult['artistViewUrl'],
		            	'7' => $responseresult['trackViewUrl'],
			            '8' => $responseresult['collectionViewUrl'],
			            '9' => $responseresult['releaseDate'],
			 		   '10' => $description,
		               '11' => $responseresult['trackPrice'],
		               '12' => $responseresult['collectionPrice'],
			           '13' => $responseresult['price'],
			           '14' => $responseresult['currency']
			);
		}
		if(count($resultitune)==0) // or  if($countitune==0)
		{		$str="no result"; echo $str; exit;
		}
		$total=$countitune;
		$start=10*($page-1);
		$startingnum=($page*10)-9;
		$endingnum=$page*10;
		if($total<$endingnum)
		$endingnum=$total;
		if($total<10)
		$startingnum=1;
		else
		$startingnum=($page*10)-9;
		$baseurl=$this->url();
		$this->setValue("baseurl",$baseurl);
			$message=array("startingnum"=>"","endingnum"=>"","keyword"=>htmlentities($keyword,ENT_QUOTES,"UTF-8"));
		$style=array("resultcountstart","resultcountend","keywordintotal");
		$totalstr=$this->getmessagegrammer(419,$message,$style);
		$this->setValue("total",$totalstr);
		$keyword1=urlencode($keyword);
		//...........................................keyword suggestion -start..........................................//
		$keywordsuggestion_status=$db->total("nesote_inoutse_engines","id=? and keyword_suggestion_status=1",array($engineid));
		if($page==1 && $keywordsuggestion_status!=0 && trim($suggestion_keyword)==trim($keyword))
		{
			$tot1=$db->total("nesote_inoutse_keywordsuggestions","engine_id=? and keyword=?",array($engineid,$suggestion_keyword));
			if($tot1==0)
			{
				$db->insert("nesote_inoutse_keywordsuggestions");
        		$db->fields("engine_id,keyword,searchcount,time");
        		$db->values(array($engineid,$suggestion_keyword,1,time()));
        		$db->query();
			}
			else
			{
				$db->update("nesote_inoutse_keywordsuggestions");
				$db->set("searchcount=searchcount+1,time=?",array(time()));
				$db->where("engine_id=? and keyword=?",array($engineid,$suggestion_keyword));
				$db->query();
			}
		}
		if($page<=2)
		{
			$startpage=1;
			$endpage=5;
		}
		else
		{
			$startpage=$page-3;
			$endpage=$page+1;
		}
		$nextpage=$page+1;
		if($page!=1)
		{
		$footerlink.="<li class=\"pgntn-li float-left\"><a class=\"pgntn-a pgn-arw\" href=javascript:loadpage($previouspage)><i class=\"fas fa-chevron-left\"></i></a></li>";
		}
		for($i=$startpage;$i<=$endpage;$i++)
		{
			if($i*10<($total+10))
			{
				if($i!=$page)
				{
					$footerlink.="<li class=\"pgntn-li float-left\"><a class=\"pgntn-a pgn-cnt\" href=javascript:loadpage($i)>$i</a></li>";
				}
				else 
				{
					$footerlink.="<li class=\"pgntn-li float-left\"><a class=\"pgntn-a pgn-cnt pgn-actv\" href=javascript:loadpage($i)>$i</a></li>";
				}
			}
		}
		if($page*10<($total))
		{
		$footerlink.="<li class=\"pgntn-li float-left\"><a class=\"pgntn-a pgn-arw\" href=javascript:loadpage($nextpage)><i class=\"fas fa-chevron-right\"></i></a></li>";
		}
		$j=0;
		$finalresult=[];
		for($i=$start;$i<=($start+9)&& $i<=$total;$i++)
		{
			if(($resultitune[$i][0]=="")&&($resultitune[$i][6]=="")&&($resultitune[$i][5]==""))
			break;
			if(($i==0)&&($feelinglucky==1))
			{
				if($resultitune[$i][7]!="")
				{
					header("Location:".strip_tags($resultitune[$i][7]));
					exit(0);
				}
				else
				{
					header("Location:".strip_tags($resultitune[$i][6]));
					exit(0);
				}
			}
			$finalresult[$j][1]=$resultitune[$i][0]; //wrapper
			$finalresult[$j][2]=$resultitune[$i][1]; //kind
			$finalresult[$j][3]=$this->makebold(strip_tags($resultitune[$i][2]),$keyword,0); //artistname
			$finalresult[$j][4]=$this->makebold(strip_tags($resultitune[$i][3]),$keyword,0); //trackname
			$finalresult[$j][5]=$this->makebold(strip_tags($resultitune[$i][4]),$keyword,0); //collectionname
			$finalresult[$j][6]=html_entity_decode($resultitune[$i][5]); //imageurl
			$finalresult[$j][7]=html_entity_decode($resultitune[$i][6]); //artistViewUrl
			$finalresult[$j][8]=html_entity_decode($resultitune[$i][7]); //trackViewUrl
			$finalresult[$j][9]=html_entity_decode($resultitune[$i][8]); //collectionViewUrl
			$finalresult[$j][10]=$resultitune[$i][9]; //releaseDate
			$finalresult[$j][11]=$resultitune[$i][10]; //primaryGenreName
			$finalresult[$j][12]=$resultitune[$i][11]; //trackPrice
			$finalresult[$j][13]=$resultitune[$i][12]; //collectionPrice
			$finalresult[$j][14]=$resultitune[$i][13]; //price
			$finalresult[$j][15]=$resultitune[$i][14]; //currency
			$finalresult[$j][16]=$this->getstar($finalresult[$j][4],$engineid);
			$j++;
		}
	$finalcount=count($finalresult);
		if($finalcount==0)
		{
					$str="no result"; echo $str; exit;
		}
			$str.='[&&]';$str.=$totalstr;$str.='[&&]';$str.=$typesearch;$str.='[&&]';
		$iplus=($page-1)*10;
		for($i=0;$i<$finalcount;$i++)
		{
$iplus=$iplus+1;
			if(($finalresult[$i][7]!="")||($finalresult[$i][4]!=""))
			{
$str .='<div class="float-left fullwidth my-2 rslt-out">
	<div class="position-absolute twtr-img-div"><img src="'.$finalresult[$i][6].'" class="twt-img fullwidth" alt="twitter image"></div>
	<div class="rslt-twtr fullwidth">
	    <a class="wb-rslt-a it_heading" href="'.$finalresult[$i][8].'" alt="'.strip_tags($finalresult[$i][4]).'" title="'.strip_tags($finalresult[$i][4]).'">';
					if($finalresult[$i][3]!="")
					{
$str.='<h3 class="wb-rslt-hd ">'.$finalresult[$i][3].'</h3></a>&nbsp';
if($newwindow==1)
$str.='<a target="_blank" href="'.$finalresult[$i][7].'"><i class="fas fa-external-link-alt fa_color externl_lnk_icn" title="'.$this->getmessage(3).'"></i></a>';		
					}
				if($finalresult[$i][4]!="")
				{$str.='
				-	
<a class="wb-rslt-a title_itns" href="'.$finalresult[$i][8].'">'.$finalresult[$i][4].'</a>';			
				}
				if($finalresult[$i][5]!="")
				{	$str.='
				-
<a class="wb-rslt-a title_itns" href="'.$finalresult[$i][9].'">'.$finalresult[$i][5].'</a>';				
				}
$str.='<p class="wb-rslt-dmn">';
		if($finalresult[$i][1]!="")
				{
					$str.=$finalresult[$i][1].' - ';
				}
				if($finalresult[$i][2]!="")
				{
					$str.=$finalresult[$i][2].' - ';
				}
				if($finalresult[$i][11]!="")
				{
					$str.=$finalresult[$i][11];
				}
				$str.='<br>';
				if(($finalresult[$i][12]!="")&&($finalresult[$i][12]>0))
				{
					if($finalresult[$i][15]!="")
					{
						$str.=$finalresult[$i][15];
					}
					$str.=$finalresult[$i][12].'('.$this->getmessage(426).')';
				}
				if(($finalresult[$i][13]!="")&&($finalresult[$i][13]>0))
				{
					if($finalresult[$i][15]!="")
					{
						$str.=$finalresult[$i][15];
					}
					$str.=$finalresult[$i][13].'('.$this->getmessage(425).')';
				}
				if(($finalresult[$i][14]!="")&&($finalresult[$i][14]>0))
				{
					if($finalresult[$i][15]!="")
					{
						$str.=$finalresult[$i][15];
					}
					$str.=$finalresult[$i][14].'('.$this->getmessage(427).') ';
				}
				$str.= '</p>
				</div>';
				$str.='<div class="fullwidth twt-cnt">
		</div>	';				
				if($emailafrnd==1)
$str.='<a class="rslt-lnk" href="javascript:emailafrnd(\''.$this->createlink($finalresult[$i][7]).'\')" ><i class="fas fa-envelope rslt-lnk-ic" id="email_lnk"></i> '.$this->getmessage(27).'</a>';
if($quicklook==1)
					{
$str.='<span  id="qlook{loop:results}" class="rslt-lnk qk-look">  <i id="qlook_bti'.($iplus+1).'" class="fas fa-chevron-circle-right rslt-lnk-ic"></i> <a class="rslt-lnk qk-look"
							id="qlook_btn'.($iplus+1).'"
							href="javascript:qlook('.($iplus+1).',\''.$this->getmessage(39).'\',\''.$this->getmessage(41).'\',\''.$this->getmessage(40).'\')">'.$this->getmessage(39).'</a> </span> 
                     <span id="qlook_spn'.($iplus+1).'" style="display: none;"><i id="qlook_mmi'.($iplus+1).'" class="fas fa-plus-circle rslt-lnk-ic"></i>
                    &nbsp;<a class="rslt-lnk qk-look"
							id="qlook_mmb'.($iplus+1).'"
							href="javascript:qlookmm('.($iplus+1).',\''.$this->getmessage(41).'\',\''.$this->getmessage(43).'\')">'.$this->getmessage(41).'</a>
						<span id="qlook_mms'.($iplus+1).'"></span><i class="fa fa-home rslt-lnk-ic" aria-hidden="true"></i>
</i>&nbsp;<a
							class="qlook rslt-lnk qk-look " id="qlook_ghb'.($iplus+1).'"
							href="javascript:qlookgh('.($iplus+1).')">'.$this->getmessage(42).'</a>
						</span>';
			}
						$str.='	</div>';
						if($quicklook==1)
						$str.='
						<span id="qlookframe'.$iplus.'" style="'.$this->getqlookdisplaystatus().'">
						<iframe class="qickfrmeifrmae"	id="qlook_fra'.($iplus+1).'" src="" src1="'.$finalresult[$i][7].'"
							loaded="0" width="99%" height="300" scrolling="auto"
							style="display: none; margin-top: 3px;"></iframe>
						<div align="center" id="qlook_lsi'.($iplus+1).'"
							style="display: none; margin: 0;"><img
							src="images/qlook/q_l10.gif" alt="Loading..." width="239"
							height="20" style="margin-top: 20px; margin-bottom: 250px;" /></div>';
							$str.='</span> 
							';
			}
		}
				$str.='[&&]'.$footerlink;
		echo $str;exit;
	}
	function testapi($keyword,$page,$src)
	{
		$valid=$this->uservalidation();
		$this->loadLibrary('Settings');
		$settings=new Settings('nesote_inoutse_settings');
		$settings->loadValues();
		$count=$settings->getValue("result_count");
		$relatedtag_count=$settings->getValue("related_tags_count");
		$styleid=$settings->getValue("result");
		$openin_newwindow=$settings->getValue("new_window");
		$emailafrnd=$settings->getValue("email_a_frnd");
		$quicklook=$settings->getValue("quicklook");
		$xmldata=$this->getalturlcontent($src,$page,$keyword);
		$xmldata=str_replace("\r\n","",$xmldata);
		$xmldata=str_replace("\n","",$xmldata);
		$xmldata=str_replace("\r","",$xmldata);
		$xmldata=str_replace("  ","",$xmldata);
		preg_match_all("/<result><title>(.+?)<\/title><url>(.+?)<\/url><domain>(.+?)<\/domain>(.+?)<kwic>(.+?)<\/kwic>(.+?)<\/result>/",$xmldata,$resultset);
		preg_match("/<count>(.+?)<\/count>/i",$xmldata,$totalhits);
		$finalresult=[];
		$cnt= count($resultset[1]);
	if($cnt==0)
		{
			echo "no results";
			exit;
		}
		for($i=0;$i<$cnt;$i++)
		{
			$finalresult[$i][1]=$resultset[5][$i];
			$finalresult[$i][2]=$resultset[3][$i];
			$finalresult[$i][3]=$resultset[1][$i];
			$finalresult[$i][4]=$resultset[2][$i];
		}
		$total=$totalhits[1];
		$finalcount=count($finalresult);
	$previouspage=$page-1;
		if($page<=4)
		{
			$startpage=1;
			$endpage=7;
		}
		else
		{
			$startpage=$page-3;
			$endpage=$page+3;
		}
		$nextpage=$page+1;
		if($page!=1)
		{
		$footerlink.="<li class=\"pagenubrli\"><a class=pagenubrsa href=javascript:loadpage($previouspage)>".$this->getmessage(6)."</a></li>";
		}
		for($i=$startpage;$i<=$endpage;$i++)
		{
			if($i*10<($total+10))
			{
				if($i!=$page)
				{
					$footerlink.="<li class=\"pagenubrli\"><a class=\"pagenubrsa\" href=javascript:loadpage($i)>$i</a></li>";
				}
				else 
				{
					$footerlink.="<li class=\"pagenubrli\"><a class=\"pagenubrsa pagenubrsactive\" href=javascript:loadpage($i)>$i</a></li>";
				}
			}
		}
		if($page*10<($total))
		{
		$footerlink.="<li class=\"pagenubrli\"><a class=pagenubrsa href=javascript:loadpage($nextpage)>".$this->getmessage(5)."</a></li>";
		}
		$message=array("startingnum"=>(($page-1)*10)+1,"endingnum"=>(($page-1)*10)+10,"total"=>$total,"keyword"=>htmlentities($keyword,ENT_QUOTES,"UTF-8"));
		$style=array("resultcountstart","resultcountend","totalresults","keywordintotal");
		$totalstr=$this->getmessagegrammer(8,$message,$style);
$str="";
	$str.='[&&]';$str.=$totalstr;$str.='[&&]';$str.="free";$str.='[&&]';
	$iplus=($page)*10;
		for($i=0;$i<$finalcount;$i++)
		{
			$str.='<li class="result_li">';
                if(($thumbshotstatus==1) && ($thumshot_url!=""))	
                {	
                 $str.='<div id="thumbshot$i" class="web_thumb_imge">
                  <a href="'.$finalresult[$i][4].'" alt="'.strip_tags($finalresult[$i][2]).'" title="'.strip_tags($finalresult[$i][2]).'">
                   <img src="'.$thumshot_url.$finalresult[$i][4].'" /> 
                   </a>
                   </div>';
                }
                   else
                   {
                  $str.='<div id="thumbshot'.$iplus.'" class="web_thumb_imge">
                     &nbsp;
                     </div>';
                   }
                 $str.= '<div class="web_rslt_txt">
                    <div class="web_result_title"> <a href="'.$finalresult[$i][4].'" class="web_result_link"> '.$finalresult[$i][3].' </a>'; 
                    if($openin_newwindow==1) 
                    {
                   $str.='<a target="_blank" class="web_result_link"
							href="'.$finalresult[$i][4].'" alt="'.$this->getmessage(3).'" title="'.$this->getmessage(3).'"><i class="fa fa-external-link fa_color fa_bold" title="'.$this->getmessage(3).'"></i></a>';
                    }
					$str.='<!-- Ulitmate7 -->';
				$str.='<!-- Ulitmate7 -->';
				$str.='</div>
                    <div class="web_resultdescription">
                      <p class="rslt_dscrptn_p"> '.$finalresult[$i][1].' </p>
                    </div>
                    <div class="web_result_bottom">
                      <div class="web_resulturl"> '.$finalresult[$i][2].' <span class="sourcestatusdisplay">Found on Faroo</span></div>
                      <br>'.$this->getbreak($finalresult[$i][2]);
                      $str.='<div class="bottom_web_reultlinks">'; 
                      if($emailafrnd==1)
                      {
                      $str.='<span class="web_rslt_emaillink">  <i class="fa fa_color fa-envelope"></i> <A
							class="email_link"
							HREF="javascript:popUp(\''.$this->createlink($finalresult[$i][4]).'\')">'.$this->getmessage(27).'</A>
							</span> ';
                      }
                      if($quicklook==1)
                      {
                     $str.='<span  id="qlook'.$iplus.'" class="web_rslt_quicklink"> <i id="qlook_bti'.($iplus+1).'" class="fa fa_color fa-chevron-circle-right"></i><a class="email_link"
							id="qlook_btn'.($iplus+1).'"
							href="javascript:qlook('.($iplus+1).',\''.$this->getmessage(39).'\',\''.$this->getmessage(41).'\',\''.$this->getmessage(40).'\')">'.$this->getmessage(39).'</a> </span> 
                     <span id="qlook_spn'.($iplus+1).'" style="display: none;"><i id="qlook_mmi'.($iplus+1).'" class="fa fa_color fa-plus-circle"></i>
                     &nbsp;<a class="qlook"
							id="qlook_mmb'.($iplus+1).'"
							href="javascript:qlookmm('.($iplus+1).',\''.$this->getmessage(41).'\',\''.$this->getmessage(43).'\')">'.$this->getmessage(41).'</a>
						<span id="qlook_mms'.($iplus+1).'"></span><i  class="fa fa_color fa-home"></i>&nbsp;<a
							class="qlook" id="qlook_ghb'.($iplus+1).'"
							href="javascript:qlookgh('.($iplus+1).')">'.$this->getmessage(42).'</a>
						</span>';
                      }
						$str.='<!-- Ulitmate7 -->';							
    						$str.='</div>';
                    $str.= '</div>
                  </div>
                </li> ';
                if($quicklook==1)
                {
				$str.='<span id="qlookframe'.($iplus).'" style="'.$this->getqlookdisplaystatus().'" width="100%">
						<iframe class="qickfrmeifrmae"	id="qlook_fra'.($iplus+1).'" src="" src1="'.$finalresult[$i][4].'"
							loaded="0" width="99%" height="300" scrolling="auto"
							style="display: none; margin-top: 3px;"></iframe>
						<div align="center" id="qlook_lsi'.($iplus+1).'"
							style="display: none; margin: 0;" width="100%"><img
							src="images/qlook/q_l10.gif" alt="Loading..." width="239"
							height="20" style="margin-top: 20px; margin-bottom: 250px;" /></div>
						</span>';
                }	
			$iplus=$iplus+1;	
		}
		$str.="[&&]".$footerlink;
		return $str;
	    exit;
	}
function testfarooapiAction()
	{
		$valid=$this->uservalidation();
		$keyword=$_POST['search'];// reading search keyword
		$quotestatus=get_magic_quotes_gpc();
		if($quotestatus==1)
		$keyword=stripslashes($keyword);
		$this->loadLibrary('Settings');
		$settings=new Settings('nesote_inoutse_settings');
		$settings->loadValues();
		$count=$settings->getValue("result_count");
		$relatedtag_count=$settings->getValue("related_tags_count");
		$styleid=$settings->getValue("result");
		$openin_newwindow=$settings->getValue("new_window");
		$emailafrnd=$settings->getValue("email_a_frnd");
		$quicklook=$settings->getValue("quicklook");
		$servicename=$settings->getValue("service_name");	
		if((!isset($_POST['search'])||($_POST['search']=="")))
		$keyword=str_replace("%2NNFF","/",$this->getParam(1));
		$src="web";
		$page=1;
		if(isset($_POST['startpage']))
		$page=$_POST['startpage'];   // reading page value
		if ($page=="")
		$page=1;
		$xmldata=$this->getalturlcontent($src,$page,$keyword);
		$xmldata=str_replace("\r\n","",$xmldata);
		$xmldata=str_replace("\n","",$xmldata);
		$xmldata=str_replace("\r","",$xmldata);
		$xmldata=str_replace("  ","",$xmldata);
		preg_match_all("/<result><title>(.+?)<\/title><url>(.+?)<\/url><domain>(.+?)<\/domain>(.+?)<kwic>(.+?)<\/kwic>(.+?)<\/result>/",$xmldata,$resultset);
		$finalresult=[];
		$cnt= count($resultset[1]);
		for($i=0;$i<10;$i++)
		{
			$finalresult[$i][1]=$resultset[5][$i];//description
			if(strlen($resultset[3][$i])>=60) 
			{
				$finalresult[$i][2]=substr($resultset[3][$i],0,60);// display url
			}
			else 
			{
				$finalresult[$i][2]=$resultset[3][$i];// display url
			}
			if(strlen($resultset[1][$i])>=100)
			{
				$finalresult[$i][3]=substr($resultset[1][$i],0,100);//title
			}
			else 
			{
				$finalresult[$i][3]=$resultset[1][$i];//title
			}
			$finalresult[$i][4]=$resultset[2][$i];//link
		}
$finalcount=count($finalresult);
		for($i=0;$i<$finalcount;$i++)
		{
			$finalresult[$i][1]=$this->makebold($finalresult[$i][1],$keyword,1);
			$finalresult[$i][2]=$this->makebold($finalresult[$i][2],$keyword,0);
			$finalresult[$i][3]=$this->makebold($finalresult[$i][3],$keyword,0);
		}
		
$str="";
	$str.='[&&]';$str.="1000";$str.='[&&]';$str.="free";$str.='[&&]';
	$iplus=($page-1)*10;
		for($i=0;$i<$finalcount;$i++)
		{
			$str.='<li class="result_li">';
                if(($thumbshotstatus==1) && ($thumshot_url!=""))	
                {	
                 $str.='<div id="thumbshot$i" class="web_thumb_imge">
                  <a href="'.$finalresult[$i][4].'" alt="'.strip_tags($finalresult[$i][2]).'" title="'.strip_tags($finalresult[$i][2]).'">
                   <img src="'.$thumshot_url.$finalresult[$i][4].'" /> 
                   </a>
                   </div>';
                }
                   else
                   {
                  $str.='<div id="thumbshot'.$iplus.'" class="web_thumb_imge">
                     &nbsp;
                     </div>';
                   }
                 $str.= '<div class="web_rslt_txt">
                    <div class="web_result_title">';
                 $str.='<a href="'.$finalresult[$i][4].'" class="web_result_link"> '.$finalresult[$i][3].' </a>'; 
                    if($openin_newwindow==1) 
                    {
                   $str.='<a target="_blank" class="web_result_link"
							href="'.$finalresult[$i][4].'" alt="'.$this->getmessage(3).'" title="'.$this->getmessage(3).'"><img src="images/openinnew.png" title="open in new window" alt="open in new window" /> </a>';
                    }
					$str.='<!-- Ulitmate7 -->';
				$str.='<!-- Ulitmate7 -->';
				$str.='</div>
                    <div class="web_resultdescription">
                      <p class="rslt_dscrptn_p"> '.$finalresult[$i][1].' </p>
                    </div>
                    <div class="web_result_bottom">
                      <div class="web_resulturl"> '.$finalresult[$i][2].' <span class="sourcestatusdisplay"> Found on Faroo</span></div>
                      <br>'.$this->getbreak($finalresult[$i][2]);
                      $str.='<div class="bottom_web_reultlinks">'; 
                      if($emailafrnd==1)
                      {
                      $str.='<span class="web_rslt_emaillink"> <img src="images/email_ico.png" alt="icons" /> <A
							class="email_link"
							HREF="javascript:popUp(\''.$this->createlink($finalresult[$i][4]).'\')">'.$this->getmessage(27).'</A>
							</span> ';
                      }
                      if($quicklook==1)
                      {
                     $str.='<span  id="qlook'.$iplus.'" class="web_rslt_quicklink"> <img id="qlook_bti'.($iplus+1).'" src="images/quick_link_ico.png" alt="icons" /> <a class="email_link"
							id="qlook_btn'.($iplus+1).'"
							href="javascript:qlook('.($iplus+1).',\''.$this->getmessage(39).'\',\''.$this->getmessage(41).'\',\''.$this->getmessage(40).'\')">'.$this->getmessage(39).'</a> </span> 
                     <span id="qlook_spn'.($iplus+1).'" style="display: none;"><img
							id="qlook_mmi'.($iplus+1).'" src="images/qlook/max.gif"
							width=11 height=11 align="absmiddle">&nbsp;<a class="qlook"
							id="qlook_mmb'.($iplus+1).'"
							href="javascript:qlookmm('.($iplus+1).',\''.$this->getmessage(41).'\',\''.$this->getmessage(43).'\')">'.$this->getmessage(41).'</a>
						<span id="qlook_mms'.($iplus+1).'"></span><img
							src="images/qlook/home.gif" width=11 height=12 align="absmiddle">&nbsp;<a
							class="qlook" id="qlook_ghb'.($iplus+1).'"
							href="javascript:qlookgh('.($iplus+1).')">'.$this->getmessage(42).'</a>
						</span>';
                      }
						$str.='<!-- Ulitmate7 -->';							
    						$str.='</div>';
                    $str.= '</div>
                  </div>
                </li> ';
                if($quicklook==1)
                {
				$str.='<span id="qlookframe'.($iplus).'" style="'.$this->getqlookdisplaystatus().'" width="100%">
						<iframe	class="qickfrmeifrmae" id="qlook_fra'.($iplus+1).'" src="" src1="'.$finalresult[$i][4].'"
							loaded="0" width="99%" height="300" scrolling="auto"
							style="display: none; margin-top: 3px;"></iframe>
						<div align="center" id="qlook_lsi'.($iplus+1).'"
							style="display: none; margin: 0;" width="100%"><img
							src="images/qlook/q_l10.gif" alt="Loading..." width="239"
							height="20" style="margin-top: 20px; margin-bottom: 250px;" /></div>
						</span>';
                }	
			$iplus=$iplus+1;	
		}
		echo  $str;
	    exit;
	}
	function testapiimagesdataAction($keyword,$page)
	{
		$keyword=urlencode($keyword);
		$this->loadLibrary('Settings');
		$settings=new Settings('nesote_inoutse_settings');
		$settings->loadValues();
		$pixabay_user_name=$settings->getValue("pixabay_user_name");
		$pixabay_api_key=$settings->getValue("pixabay_api_key");
	
	
        $url="https://pixabay.com/api/?username=$pixabay_user_name&key=$pixabay_api_key&search_term=$keyword&image_type=photo&page=$page&per_page=15";
	//	echo $url;
		  //  $data = file_get_contents($url);
		   
		
			
	

		if (function_exists('curl_init'))
	{	 	 $ch = curl_init();
  	 curl_setopt($ch, CURLOPT_URL,$url);
 	 curl_setopt($ch, CURLOPT_HEADER, 0);
 	 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
 	 $data = curl_exec($ch);
 	 curl_close($ch);
		}
		$xmldata=json_decode($data,true);
		 
		
		$finalresult=array();
		$i=0;
		foreach($xmldata['hits'] as $result)
		{
			$finalresult[$i][1]=".jpg";
			$finalresult[$i][2]=$result["imageWidth"];
			$finalresult[$i][3]=$result["pageURL"];
			$finalresult[$i][4]=$result["webformatURL"];
			$finalresult[$i][5]=$result["previewURL"];
			$finalresult[$i][6]=$result["tags"];
			$finalresult[$i][7]=$result["webformatURL"];
			$finalresult[$i][8]=$result["imageHeight"];
			$finalresult[$i][9]=$result["webformatURL"];
			$i=$i+1;
		}
		$finalcount=count($finalresult);
	
		
		if($finalcount == 0)
		{
			if($mod_rewrite==true)
			header("Location:".$this->url("search/noresults?search=$keyword&type=$searchtype&status=$xmldata"));
			else
			header("Location:".$this->url("search/noresults&search=$keyword&type=$searchtype&status=$xmldata"));
			exit(0);
		}
		else
		{
			return array($finalresult,$xmldata['totalHits']);
		}
	}
	function testapiimagesAction()
	{
		$keyword=$_POST['search'];// reading search keyword
		$page=1;
		if(isset($_POST['startpage']))
		$page=$_POST['startpage'];   // reading page value
		if ($page=="")
		$page=1;
		$keyword=urlencode($keyword);
		$this->loadLibrary('Settings');
		$settings=new Settings('nesote_inoutse_settings');
		$settings->loadValues();
		$pixabay_user_name=$settings->getValue("pixabay_user_name");
		$pixabay_api_key=$settings->getValue("pixabay_api_key");
		$data = file_get_contents("http://pixabay.com/api/?username=$pixabay_user_name&key=$pixabay_api_key&search_term=$keyword&image_type=photo&page=$page&per_page=15");
			$xmldata=json_decode($data,true);
		$finalresult=array();
		$i=0;
		foreach($xmldata['hits'] as $result)
		{
			$finalresult[$i][1]=".jpg";
			$finalresult[$i][2]=$result["imageWidth"];
			$finalresult[$i][3]=$result["pageURL"];
			$finalresult[$i][4]=$result["webformatURL"];
			$finalresult[$i][5]=$result["previewURL"];
			$finalresult[$i][6]=$result["tags"];
			$finalresult[$i][7]=$result["webformatURL"];
			$finalresult[$i][8]=$result["imageHeight"];
			$finalresult[$i][9]=$result["webformatURL"];
			$i=$i+1;
		}
		$finalcount=count($finalresult);
		$str="";
		$str.='[&&]';$str.="1000";$str.='[&&]';$str.=$typesearch;$str.='[&&]';
	$iplus=($page-1)*15;
	for($i=0;$i<$finalcount;$i++)
		{
			$str .= '<li>
				<a class="og_grid_image'.$page.'"> <img src="'.$finalresult[$i][5].'" alt="'.$this->gettitle($finalresult[$i][6],$keyword).'"/></a>
                <div class="result_showingnew">
                  <div class="inside_result_showing">
                    <div class="resltarrow"></div>
                    <div class="closebtn"></div>
                    <div class="fullresult">
                      <div class="full_imagenew"> <a href="'.$finalresult[$i][3].'"><img src="'.$finalresult[$i][5].'" alt="result" /></a> </div>
                      <div class="linereslt"></div>
                      <div class="fullheadingnew">
                        <h2 class="result_names result_namesnew"><a href="'.$finalresult[$i][3].'">'.$this->gettitle($finalresult[$i][6],$keyword).'</a></h2>
                        <div class="result_image_details"> <span class="d1">'.$this->disurl($finalresult[$i][7]).'</span> <span class="d1">'.$finalresult[$i][2].'x'.$finalresult[$i][8].'&nbsp;-&nbsp;'.$this->getsize($finalresult[$i][4]).'&nbsp;-&nbsp;'.$finalresult[$i][1].'</span> <!-- <span class="d1"><a href="#">Search by image</a></span> --></div>
                        <!-- <div class="result_discrbtn"><span class="discrptnspan">Find - A classy website design template</span></div>-->
                        <div class="full_links">
                          <div class="bu1"> '.$finalresult[$i][7].'
                          </div>
                          <div class="bu1"> <a class="butn1" href="'.$finalresult[$i][3].'">View Site</a> </div>
                          <!-- Ulitmate7 -->
							'; 
							$str.='<!-- Ulitmate7 -->
                        </div>
                      </div>
                    </div>
                  </div>
                </div>
					</li>';
		$iplus=$iplus+1;
		}
		echo "str=$str";
	    exit;
	}
	function getalturlcontent($searchtype,$page,$keyword="")
	{
		$settings=new Settings('nesote_inoutse_settings');
		$settings->loadValues();	
		$resultcount=$settings->getValue("result_count");
		$fetchcount=$settings->getValue("result_fetchcount");
		$page =(($page-1) * 10)+1;
		if($searchtype != "web" || $searchtype != "news")
		{
			$keyword=$searchtype." ".$keyword;
			$searchtype ="web";
		}
		$keyword=urlencode($keyword);
		$faroo_api_key=$settings->getValue("faroo_api_key");
		$url = "http://www.faroo.com/api?q=$keyword&start=$page&length=$resultcount&l=en&src=$searchtype&f=xml&key=$faroo_api_key";
				$xmldata="";
		if (function_exists('curl_init'))
		{
	 	 $ch = curl_init();
	  	 curl_setopt($ch, CURLOPT_URL,$url);
	 	 curl_setopt($ch, CURLOPT_HEADER, 0);
	  	 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
	  	 $xmldata = curl_exec($ch);
	  	 curl_close($ch);
		}
		return $xmldata;
		exit(0);
	}
    function getalturlcontentdata($searchtype,$page,$keyword="")
	{
		$keyword=urlencode($keyword);
		$settings=new Settings('nesote_inoutse_settings');
		$settings->loadValues();	
		$resultcount=$settings->getValue("result_count");
		$fetchcount=$settings->getValue("result_fetchcount");
		$page =(($page-1) * 10)+1;
		$faroo_api_key=$settings->getValue("faroo_api_key");
		$url = "http://www.faroo.com/api?q=$keyword&start=$page&length=$resultcount&l=en&src=web&f=xml&key=$faroo_api_key";
			$xmldata="";
		if (function_exists('curl_init'))
		{
	 	 $ch = curl_init();
	  	 curl_setopt($ch, CURLOPT_URL,$url);
	 	 curl_setopt($ch, CURLOPT_HEADER, 0);
	  	 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
	  	 $xmldata = curl_exec($ch);
	  	 curl_close($ch);
		}
		$xmldata=str_replace("\r\n","",$xmldata);
		$xmldata=str_replace("\n","",$xmldata);
		$xmldata=str_replace("\r","",$xmldata);
		$xmldata=str_replace("  ","",$xmldata);
		preg_match_all("/<result><title>(.+?)<\/title><url>(.+?)<\/url><domain>(.+?)<\/domain>(.+?)<kwic>(.+?)<\/kwic>(.+?)<\/result>/",$xmldata,$resultset);
		preg_match_all("/<count>(.+?)<\/count>/i",$xmldata,$total);
		$totals= $total[1];
		$finalresult=[];
		$cnt= count($resultset[1]);
                 	if($cnt==0)
		{
			if($mod_rewrite==true)
			header("Location:".$this->url("search/noresults?search=$keyword&type=$searchtype"));
			else
			header("Location:".$this->url("search/noresults&search=$keyword&type=$searchtype"));
			exit(0);
		}
		for($i=0;$i<$cnt;$i++)
		{
			$finalresult[$i][1]=$resultset[5][$i];//description
			if(strlen($resultset[3][$i])>=60) 
			{
				$finalresult[$i][2]=substr($resultset[3][$i],0,60);// display url
			}
			else 
			{
				$finalresult[$i][2]=$resultset[3][$i];// display url
			}
			if(strlen($resultset[1][$i])>=100)
			{
				$finalresult[$i][3]=substr($resultset[1][$i],0,100);//title
			}
			else 
			{
				$finalresult[$i][3]=$resultset[1][$i];//title
			}
			$finalresult[$i][4]=$resultset[2][$i];//link
			$finalresult[$i][5]="faroo";
			$finalresult[$i][6]="";
		}
$finalcount=count($finalresult);
		for($i=0;$i<$finalcount;$i++)
		{
			$finalresult[$i][1]=$this->makebold($finalresult[$i][1],$keyword,1);
			$finalresult[$i][2]=$this->makebold($finalresult[$i][2],$keyword,0);
			$finalresult[$i][3]=$this->makebold($finalresult[$i][3],$keyword,0);
		}
		return array($finalresult,$totals);
	}
	function getaltimageurlcontent($page=false,$keyword="")
	{
		$keyword=urlencode($keyword);
		$settings=new Settings('nesote_inoutse_settings');
		$settings->loadValues();	
		$resultcount=$settings->getValue("result_count");
		$fetchcount=$settings->getValue("result_fetchcount");
		$page =(($page-1) * 10)+1;
		$pixabay_user_name=$settings->getValue("pixabay_user_name");
		$pixabay_api_key=$settings->getValue("pixabay_api_key");
		$data = file_get_contents("http://pixabay.com/api/?username=$pixabay_user_name&key=$pixabay_api_key&search_term=$keyword&image_type=photo&page=$page&per_page=15");
			$xmldata="";
		if (function_exists('curl_init'))
		{
	 	 $ch = curl_init();
	  	 curl_setopt($ch, CURLOPT_URL,$url);
	 	 curl_setopt($ch, CURLOPT_HEADER, 0);
	  	 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
	  	 $xmldata = curl_exec($ch);
	  	 curl_close($ch);
		}
		print_r($xmldata);
		exit(0);
	}
function datasourceinstanceAction($alignment=0)
	{
		$valid=$this->uservalidation();
		$this->setValue("valid",$valid);
		$keyword=$_POST['search'];// reading search keyword
		$quotestatus=get_magic_quotes_gpc();
		if($quotestatus==1)
		$keyword=stripslashes($keyword);
		$tabname=$_POST['type'];//    reading tab name
		$fl=$_POST['fl'];
		if((!isset($_POST['type']))||($_POST['type']==""))
		$tabname=$this->getParam(1);
		if((!isset($_POST['search'])||($_POST['search']=="")))
		$keyword=str_replace("%2NNFF","/",$this->getParam(2));
		$suggestion_keyword=$keyword;
		include("script.inc.php");
		include("{$config_path}system.config.php");
		if($fl==1)
		$feelinglucky=1;
		$quotestatus=get_magic_quotes_gpc();
		if($quotestatus==1)
		$keyword=stripslashes($keyword);
		$keyword=str_replace('"',' " ',$keyword);
		$keyword=str_replace("'"," ' ",$keyword);
		$keyword=$this->familyfilter($keyword);
		$keyword=str_replace("' ","'",$keyword);
		$keyword=str_replace(" '","'",$keyword);
		$keyword=str_replace('" ','"',$keyword);
		$keyword=str_replace(' "','"',$keyword);
		$db= new NesoteDALController();
		$db->select("nesote_inoutse_engines");
		$db->fields("id,search_type,tab_name");
		$db->where("tab_name=?",$tabname);
		$result=$db->query();
		$row=$db->fetchRow($result);
		$searchtype=$row[1];  // reading search type
		$engineid=$row[0];  // reading engine id
		$enginename=$row[2];//reading tab name
		$this->setValue("engineid",$engineid);
		$tabkeyword=str_replace("/","%2NNFF",$keyword);
		$this->setValue("keyword",$tabkeyword);
		$this->setValue("tabname",$tabname);
		$this->loadLibrary('Settings');
		$settings=new Settings('nesote_inoutse_settings');
		$settings->loadValues();
		$count=$settings->getValue("result_count");
		$db= new NesoteDALController();
		$tot=$db->total("nesote_inoutse_engines","tab_name=? and status=?",array($tabname,1));
		if(($keyword=="")||($tot==0))
		{
			echo "no result";exit;
		}
		$page=1;
		if(isset($_POST['startpage']))
		$page=$_POST['startpage'];   // reading page value
		if ($page=="")
		$page=1;
		$this->loadLibrary('Settings');
		$settings=new Settings('nesote_inoutse_settings');
		$settings->loadValues();
		$count=$settings->getValue("result_count");
		$isbold=$settings->getValue("keyword_bold");
		$relatedtag_count=$settings->getValue("related_tags_count");
		$styleid=$settings->getValue("result");
		$servicename=$settings->getValue("service_name");
		$relatedkeyword_status=$settings->getValue("db_related_keyword");
		$spell_status=$settings->getValue("db_spelling_suggestion");
		$star_status=$settings->getValue("star_status");
			$member_status=$settings->getValue("member_status");
		if($member_status==1)
		$comment_status=$settings->getValue("comment_status");
		else
		$comment_status=0;
		if($spell_status==1)
		{
			$spellurl=$this->getspellurl($keyword,$engineid);
			$spellsuggestion=$this->getspellcontent($spellurl,$keyword,$tabname);
			if($spellsuggestion!="")
			{
				$spell=array("spell"=>$spellsuggestion);
				$style=array("keyword_in_spellsuggestion_class");
				$spellstr=$this->getmessagegrammer(24,$spell,$style);
				$spellstr=str_replace("<span class=\"keyword_in_spellsuggestion_class\">".$spellsuggestion."</span>","<a class=\"spelllink\" href=\"".$this->url("search/special&search=".$spellsuggestion."&type=$tabname")."\">".$spellsuggestion."</a>",$spellstr);
				$this->setValue("spell","<span class=\"spellsuggestiontext\">".$spellstr."</span>");
			}
			else
			$this->setValue("spell","");
		}
		else
		{
			$this->setValue("spell","");
		}
		$ad_codes=$settings->getValue("ad_codes");
		$this->setValue("ad_codes",$ad_codes);
		$message=array("servicename"=>$servicename);
		$home=$this->getmessagegrammer(47,$message,0);
		$enginename1=$this->getenginename($engineid);
		define('PAGETITLE',$servicename." - ".$enginename1." - ".$keyword);
		define('HEADERKEYWORD',$servicename.",search,search engine,".$keyword.",".$searchtype);
		$typearray=array("type"=>$enginename1)	;
		$typesearch=$this->getmessagegrammer(23,$typearray);
		$db->select("nesote_inoutse_engines");
		$db->fields("hidden_keyword");
		$db->where("id=?",$engineid);
		$rest=$db->query();
		$frow=$db->fetchRow($rest);
		$hiddenkeyword=$frow[0];   /////////// reading hidden keyword
		if($hiddenkeyword!="")
		$keyword.="+".$hiddenkeyword;
		$pagetmp=$page;
		if($page%($count/10)==0)
		$pagetmp=$pagetmp-1;
		$startpage=($pagetmp-($pagetmp%($count/10)))*10;
		$keyword=urlencode($keyword);
		require("script.inc.php");
		require($config_path."system.config.php");
		$urlreplaces=array();
		$var=$_SERVER['SCRIPT_NAME'];
		$var=substr($var,0,strrpos($var,"/"));
		$hostdir= "http://".$_SERVER['HTTP_HOST']."".$var."/";
		$url=$hostdir."admin/index.php?page=rss/result/$engineid&search=$keyword&start=$startpage&count=$count";
		$xmldata=$this->geturlcontent($url,$engineid,$keyword);
		$xmldata=str_replace("\r\n","",$xmldata);
		$xmldata=str_replace("\n","",$xmldata);
		$xmldata=str_replace("\r","",$xmldata);
		preg_match("/<total>(.+?)<\/total>/i",$xmldata,$totalcount);
		$total=$totalcount[1];
		$resultset=="";
		if($total>0)
		{
			preg_match_all("/<item><data>(.+?)<\/data>/i",$xmldata,$resultset);
		}
		if(count($resultset[0])==0)
		{
				echo "no result";exit;
		}
		$pagecount=$page*10;
		$start=(10*($page-1))%$count;
		$startingnum=($page*10)-9;
		$endingnum=$page*10;
		if($total<$endingnum)
		$endingnum=$total;
		if($total<10)
		$startingnum=1;
		else
		$startingnum=($page*10)-9;
		$totalstring=number_format($total);
		$message=array("startingnum"=>$startingnum,"endingnum"=>$endingnum,"total"=>$totalstring,"keyword"=>htmlentities($keyword,ENT_QUOTES,"UTF-8"));
		$style=array("resultcountstart","resultcountend","totalresults","keywordintotal");
		$totalstr=$this->getmessagegrammer(8,$message,$style);
		$keyword1=urlencode($keyword);
		$keywordsuggestion_status=$db->total("nesote_inoutse_engines","id=? and keyword_suggestion_status=1",array($engineid));
		if($page==1 && $keywordsuggestion_status!=0 && trim($suggestion_keyword)==trim($keyword))
		{
			$tot1=$db->total("nesote_inoutse_keywordsuggestions","engine_id=? and keyword=?",array($engineid,$suggestion_keyword));
			if($tot1==0)
			{
				$db->insert("nesote_inoutse_keywordsuggestions");
        		$db->fields("engine_id,keyword,total,searchcount,time");
        		$db->values(array($engineid,$suggestion_keyword,$total,1,time()));
        		$db->query();
			}
			else
			{
				$db->update("nesote_inoutse_keywordsuggestions");
				$db->set("searchcount=searchcount+1,time=?,total=?",array(time(),$total));
				$db->where("engine_id=? and keyword=?",array($engineid,$suggestion_keyword));
				$db->query();
			}
		}
		$previouspage=$page-1;
		$footerlink=substr($footerlink,0,-6);
		$nextpage=$page+1;
		$j=0;
		for($i=$start;$i<=($start+9) && $i<=$total;$i++)
		{
			if($resultset[1][$i]=="")
			break;
			$var=$this->makebold(strip_tags($resultset[1][$i]),$keyword,1);
			$finalresult[$j][1]=html_entity_decode($var);
			$finalresult[$j][2]=$this->getstar($finalresult[$j][1],$engineid);
			$j++;
		}
$finalcount=count($finalresult);
		if($finalcount==0)
		{
				echo "no result";exit;
		}
		
		$str="";
	$str.='[&&]';$str.=$totalstr;$str.='[&&]';$str.=$typesearch;$str.='[&&]';
	$iplus=($page-1)*10;
		for($i=0;$i<$finalcount;$i++)
		{	$p1=$this->urlencode($finalresult[$i][4]);
			$p2=$this->getdomain($finalresult[$i][4]);
			$str.='<li class="result_li">';
                 $str.= '<div class="web_rslt_txt">
                    <div class="web_result_title">';
                 if($this->getalignment()!=2)
                 {
                 	$str.=$finalresult[$i][1];
                 } 
					$str.='<!-- Ulitmate7 -->';
							if($valid==1)
							{
							if($star_status==1)	
							{				
							if($finalresult[$i][2]=="images/fullstar.gif")
							{
                            	$str.='<span id="span1'.$iplus.'" style=""><a href="javascript:unclick(\''.$this->encode($finalresult[$i][1]).'\',\''.$iplus.'\',\''.$engineid.'\')">
							<img src="images/fullstar.gif" border="0"  id="img1'.$iplus.'"></a></span>
							<span id="span2'.$iplus.'" style="display: none;"><a href="javascript:click(\''.$this->encode($finalresult[$i][1]).'\',\''.$iplus.'\',\''.$engineid.'\')">
							<img src="images/greystar.gif" border="0"  id="img2'.$iplus.'"></a></span>';
							}
							if($finalresult[$i][2]=="images/greystar.gif")
							{
							$str.='<span id="span2'.$iplus.'" style=""><a href="javascript:click(\''.$this->encode($finalresult[$i][1]).'\',\''.$iplus.'\',\''.$engineid.'\')">
							<img src="images/greystar.gif" border="0"  id="img2'.$iplus.'"></a></span>								
							<span id="span1'.$iplus.'" style="display: none;"><a href="javascript:unclick(\''.$this->encode($finalresult[$i][1]).'\',\''.$iplus.'\',\''.$engineid.'\')">
							<img src="images/fullstar.gif" border="0"  id="img1'.$iplus.'"></a></span>';
							}
							}
							}
				if($this->getalignment()==2)
                 {
                 	$str.=$finalresult[$i][1];
                 } 
				$str.='<!-- Ulitmate7 -->';
				$str.='</div><div class="web_resultdescription">
                      <p class="rslt_dscrptn_p">'.$finalresult[$i][1].'</p>
                    </div>';
                        $str.='<div class="web_result_bottom"><div class="bottom_web_reultlinks">'; 
                   	if($comment_status==1)
					{
						$str.='<span class="web_rslt_comments">
						  <i class="fa fa_color fa-comments"></i> 
						  <a class="comments_reslt" href="javascript:comment('.$iplus.')">
						  '.$this->getmessage(579).'&nbsp;(<span id="comcount'.$iplus.'">'.$this->getcmntcount($finalresult[$i][1],'datasource',$engineid).'</span>)</a> </span> 
       ';
						$str.='<!-- Ulitmate7 --><div class="cmntdivb" id="commentdiv'.$iplus.'" style="display: none;" >
					<div >
				';
                  $str.= '<div style="display: none;" id="div'.$iplus.'">';
							$str.='<input type="hidden" name="urlenc'.$iplus.'" id="urlenc'.$iplus.'" value="'.urlencode($finalresult[$i][4]).'">';
							$str.=$this->getcommentsnw($finalresult[$i][1],$results,datasource,$engineid);
					$str.='</div>';
								$str.= '<span id="commentbox'.$iplus.'"style="font-size: 12px;font-family:Verdana, Helvetica, sans-serif;">';
							if($valid!=1)
							{
							$str.='&nbsp;<span style="color: #686868;font-style: italic;">'.$this->getmessage(608).'</span>';
							}
							else
							{
							$str.= '<ul class="post_cmntul">
							<li class="post_cmntli">
							<b>'.$this->getmessage(586).'</b></li>
							<li class="post_cmntli">
							<input type="hidden" name="url" id="url'.$iplus.'" value="'.$finalresult[$i][1].'">
							<input type="hidden" name="type" id="type'.$iplus.'" value="datasource">&nbsp;
							</li>							
							</ul>
							<textarea id="comment'.$iplus.'" rows="3" cols="0" class="postcomment postcommentimg"></textarea>
							<br>
							<span class="post_cmntbtn" style="float:right;">
							<input class="butn1" type="submit" name="post" value="'.$this->getmessage(580).'" onclick="postcomment('.$iplus.')">
							</span>';
							}
						$str.='
							</span>
							</div>
							</div>';
    						}
    						$str.='
                    </div>
                  </div>
                </li> ';
				$str.='&nbsp;';
			$iplus=$iplus+1;	
		}
		$str .='[&&]'.$footerlink;
		echo $str;
		exit();
	}
	function getengineicon($engine_id)
	{
		  $db=new NesoteDALController();
		  $db->select("nesote_inoutse_engineicons");
	      $db->fields("id,file_name");
		  $db->where("engine_id=?",$engine_id);
		  $icoresult=$db->query();
		  $num=$db->numRows($icoresult);
		  if($num == 0)
		  {
		  	return "default_icon.png";
		  }
		  else 
		  {
		  	$icorow=$icoresult->fetchRow();
		    return $icorow[1];
		  }
	}
	function googlecustomimage_search($response)
	{
		$result = array();
		$responseobject = json_decode($response, true);
		$nextpage=($responseobject['queries']['nextPage']); 
		if (count($nextpage[0]['totalResults'])==0)
		{
			return $result;
		}
		$allresponseresults=array();
		for($i=0;$i<10;$i++)
		{
		$allresponseresults[]= $responseobject['items'][$i];
		}
		foreach ($allresponseresults as $responseresult)
		{
			$result[] = array(
              'url' => $responseresult['displayLink'],
             'title' => $responseresult['title'],
             'snippet' => $responseresult['snippet'],
             'contextlink' => $responseresult['image']['contextLink'],
			'link' => $responseresult['link'],
			 'width' => $responseresult['image']['width'],
			 'height' => $responseresult['image']['height'],
			 'thumbnailLink' => $responseresult['image']['thumbnailLink']);
		}
		return $result;
	}
	function googlecustomimage_search2($response)
	{
	$result = array();
		$responseobject = json_decode($response, true);
 	$nextpage=($responseobject['queries']['nextPage']); 
		$allresponsecursor = $nextpage[0]['totalResults'];
		return $allresponsecursor;
	}
	function mapsAction()
	{
		$this->loadLibrary('Settings');
		$settings=new Settings('nesote_inoutse_settings');
		$settings->loadValues();
		$servicename=$settings->getValue("service_name");
		$this->setValue("servicename",$servicename);
		$googlemap_apikey=$settings->getValue("googlemap_apikey");
		$this->setValue("googlemap_apikey",$googlemap_apikey);
		$db= new NesoteDALController();
	    $db->select("nesote_inoutse_engines");
		$db->fields("id,search_type");
		$db->where("tab_name=?",'Maps');
		$result=$db->query();
		$row=$db->fetchRow($result);
		$searchtype=$row[1];  // reading search type
		$engineid=$row[0];  // reading engine id
	     $this->setValue("engineid",$engineid);
		$seasonal_logo_status=$settings->getValue("seasonal_logo");
		if($seasonal_logo_status==1)
		{
			$time=time();
			$db= new NesoteDALController();
			$db->select("nesote_inoutse_seasonallogo");
			$db->fields("id,resultpage_logo");
			$db->where("startdate<=? and enddate>=? and status=1",$time);
			$result=$db->query();
			$row=$db->fetchRow($result);
			if($row[1]!="")
			{
				$logostatus=1;
				$userlogo=$row[1];
				$this->setValue("logoid",$row[0]);
			}
			elseif($row[1]=="")
			{
				$logostatus=0;
				$userlogo=$settings->getValue("result_logo");  ////////////     seasonal logo status
			}
		}
		else
		{
			$logostatus=0;
			$userlogo=$settings->getValue("result_logo");
		}
		$this->setValue("logo",$userlogo);
		$this->setValue("logostatus",$logostatus);
		if(isset($_COOKIE['theme']))
		{
			$themeid=$_COOKIE['theme'];
			$db=new NesoteDALController();
			$db->select("nesote_inoutse_themegroups");
			$db->fields("resultpage_id,generalpage_id");
			$db->where("id=?",$themeid);
			$result=$db->query();
			$row=$db->fetchRow($result);
			$db->select("nesote_inoutse_themes");
			$db->fields("style");
			$db->where("id=?",$row[0]);
			$result=$db->query();
			$row1=$db->fetchRow($result);
			$style=$row1[0];
			$db->select("nesote_inoutse_themes");
			$db->fields("style");
			$db->where("id=?",$row[1]);
			$result=$db->query();
			$row1=$db->fetchRow($result);
			$style.=$row1[0];
		}
		else
		{
			$this->loadLibrary('Settings');
			$settings=new Settings('nesote_inoutse_settings');
			$settings->loadValues();
			$styleid1=$settings->getValue("result");
			$styleid2=$settings->getValue("generalstyle");
			$db= new NesoteDALController();
			$db->select("nesote_inoutse_themes");
			$db->fields("style");
			$db->where("id=?",$styleid1);
			$result=$db->query();
			$row=$db->fetchRow($result);
			$style=$row[0];
			$db= new NesoteDALController();
			$db->select("nesote_inoutse_themes");
			$db->fields("style");
			$db->where("id=?",$styleid2);
			$result=$db->query();
			$row=$db->fetchRow($result);
			$style.=$row[0];
		}
			$this->setValue("style",$style);	
		define('PAGETITLE',$servicename);
		define('HEADERKEYWORD',$servicename);
		$message=array("servicename"=>$servicename);
		$home=$this->getmessagegrammer(47,$message,0);
		$this->setValue("home",$home);
	}
function postcommentvideoAction()
	{
		include('script.inc.php');
		include($config_path.'system.config.php');
		$engine=$_POST['engine'];
		$url=$_POST['titleurl'];
		$domainurl=$_POST['domainurl'];
		$type=$_POST['type'];
		$comment=trim(stripslashes($_POST['comment']));
		$time=time();
		$engine_id=$_POST['engine_id'];
		$titleurl=$url;
		if($this->uservalidation())
		{
			$username=$_COOKIE['io_username'];
			$password=$_COOKIE['io_password'];
			$db=new NesoteDALController();
			$db->select("nesote_inoutscripts_users");
			$db->fields("id");
			$db->where("username=? and password=? and status=?",array($username,$password,1));
			$res=$db->query();
			$num=$db->numRows($res);
			if($num==1)
			{
				$fetch=$db->fetchRow($res);
				$uid=$fetch[0];
	                          $domainurl=base64_decode($domainurl);
					$cacheindex=$this->getcacheindex($domainurl);
					$domain=md5($domainurl);
					$comment=addslashes($comment);
					$db->insert("nesote_inoutse_commentcache".$cacheindex);
					$db->fields("type,uid,title_url,domain_url,time,status,comment");
					$db->values(array($type,$uid,$titleurl,$domain,$time,'0',$comment));
					$db->query();
					$domainurl=base64_encode($domainurl);
					$msg=$this->getmessage(588);
echo 1;exit;
			}
		}
	}
function getcommentsnw_videoAction(){
include('script.inc.php');
		include($config_path.'system.config.php');
$domain=$_POST['domainurl'];
$titleurl=$_POST['url'];
                         $domainurl=base64_decode($domain);
			$cacheindex=$this->getcacheindex($domainurl);
			$domainurl=md5($domainurl);
			$type="title";
			$db=new NesoteDALController();
			$titlenum=$db->total("nesote_inoutse_commentcache".$cacheindex,"title_url=? and type=? and status=?",array($titleurl,$type,0));
			$db->query();
	        $tot=$titlenum;
                $type="title";
		$db->select("nesote_inoutse_commentcache".$cacheindex);
		$db->fields("*");
		$db->where("title_url=? and type=? and status=?",array($titleurl,$type,0));
		$db->order("time desc");
		$titleresult=$db->query();
		$titlenum=$db->numRows($titleresult);
while($rt=$db->fetchRow($titleresult))
		{
                                      $time=date("d-m-Y",$rt[5]);
					$uid=$rt[2];
					$db->select("nesote_inoutscripts_users");
					$db->fields("username");
					$db->where("id=? and status=?",array($uid,1));
					$res=$db->query();
					$fetch=$db->fetchRow($res);
					$username1=$fetch[0];
$response.="<div class=\"fullwidth drp-cmnts\">
			    <h5 class=\"cmnt-name\">".$this->getmessage(584).'&nbsp'.$username1."</h5>
				<span class=\"cmnt-date-time\">".$this->getmessage(585).'&nbsp;'.$time."</span>
				<p class=\"cmnt-cnt\">".$rt[7]."</p>
</div>";
}
echo $response;exit;
}
function getcommentsnwvideo($url){
$titleurl=$this->urlencode($url);
$domain=$this->getdomain($url);
                         $domainurl=base64_decode($domain);
			$cacheindex=$this->getcacheindex($domainurl);
			$domainurl=md5($domainurl);
			$type="title";
			$db=new NesoteDALController();
			$titlenum=$db->total("nesote_inoutse_commentcache".$cacheindex,"title_url=? and type=? and status=?",array($titleurl,$type,0));
			$db->query();
	        $tot=$titlenum;
                $type="title";
		$db->select("nesote_inoutse_commentcache".$cacheindex);
		$db->fields("*");
		$db->where("title_url=? and type=? and status=?",array($titleurl,$type,0));
		$db->order("time desc");
		$titleresult=$db->query();
		$titlenum=$db->numRows($titleresult);
while($rt=$db->fetchRow($titleresult))
		{
					$time=date("d-m-Y",$rt[5]);
					$uid=$rt[2];
					$db->select("nesote_inoutscripts_users");
					$db->fields("username");
					$db->where("id=? and status=?",array($uid,1));
					$res=$db->query();
					$fetch=$db->fetchRow($res);
					$username1=$fetch[0];
$response.="<div class=\"fullwidth drp-cmnts\">
			    <h5 class=\"cmnt-name\">".$this->getmessage(584).'&nbsp'.$username1."</h5>
				<span class=\"cmnt-date-time\">".$this->getmessage(585).'&nbsp;'.$time."</span>
				<p class=\"cmnt-cnt\">".$rt[7]."</p>
</div>";
}
return $response;
}
};
?>
