From 0c37926bbbd869fb2469555c45d0761c1a75f059 Mon Sep 17 00:00:00 2001 From: Bob Date: Wed, 29 Apr 2026 15:17:10 -0700 Subject: [PATCH] Add TSfun.php --- TSfun.php | 229 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 229 insertions(+) create mode 100644 TSfun.php diff --git a/TSfun.php b/TSfun.php new file mode 100644 index 0000000..2210e42 --- /dev/null +++ b/TSfun.php @@ -0,0 +1,229 @@ +"; + }else{ + $star=NULL; + $lk=""; + } + echo " + + ".$lk." + ".$data['SiteName']." + + ".$link."
+ ".$lk." + ".$data['title']." + + +
+ Read More".$data['lang']."     ".$star."  ".$data['share']." +

".$data['description']."

+
+ + ".$data['date']." (S:".pad_5($data['SiteID'])." B:".pad_3($data['BotID'])." P:".pad_8($data['PageID'])." H:".pad_3($data['HostID']).") ".pad_2($data['hits'])." + +
"; +} +function paging($ref,$pp,$rec_count,$qq,$off){ + $pages=round($rec_count/10,0,PHP_ROUND_HALF_DOWN)+1; + $prev_p=$next_p=0; + $page['page']=$pp; + + $jump_prev=$pp/10; + $jump_next=$pp*10; + + $prev_p=$pp-1; + if ($prev_p==0){$prev_p=$pages-1;} + if ($jump_prev<1){$jump_prev=$pages-10;} + + $next_p=$pp+1; + if ($next_p==$pages){$next_p=1;} + if ($jump_next<0){$jump_next=1;} +///////////////////////////////////// + $page['start']=($page['page']*10)-9; + $page['end']=$page['start']+9; + if (isset($qq)){$home="/?qq=".$qq;}else{$home="/";} +///////////////////////////////////// + $page[0]=" + + << + + + + + + H + + + + + + >> + + +"; + if (!is_null($qq)){ + $page[0]=" + + + + + H + + + + "; + } + unset($qq,$next_p,$prev_p,$dbt2,$page['page'],$pages,$pp,$rec_count); + memory_get_usage(); + return $page; +} +/* Highlight found search strings to display */ +function highlightStr($haystack,$needle,$highlightColorValue){ + if (isset($haystack)){ + $haystack=html_entity_decode($haystack,ENT_QUOTES|ENT_HTML5,'UTF-8'); + if (isset($haystack) and isset($needle)){ + if (strlen($haystack) < 1 || strlen($needle) < 1) { + return $haystack; + } + preg_match_all("/$needle+/i",$haystack,$matches); + if (is_array($matches[0]) && count($matches[0]) >= 1) { + foreach ($matches[0] as $match) { + $haystack = str_replace($match,''.$match.'',$haystack); + } + } + return $haystack; + }else{ + return "Error"; + } + }else{ + return NULL; + } +} +function log_files($notes,$name){ + $entry=html_entity_decode($notes,ENT_QUOTES|ENT_HTML5,'UTF-8')."\n"; + if (!file_exists($name)){touch ($name);} + $data_file=$name; + $handle=fopen($name, 'r'); + $new_data_file=fopen($data_file, 'a+') or die('Cannot open file: '.$data_file); + fwrite($new_data_file, $entry); + fclose($new_data_file); + fclose($handle); +} +/* Below, used to send messages VIA XMPP server */ +function send_group($BName,$Group,$Send,$Server){ + if (isset($_SERVER['SERVER_ADDR']) and $_SERVER['SERVER_ADDR']!=="127.0.0.1"){ + $ERROR=shell_exec("echo '".$Send."' | sendxmpp --username netbot --password 4cUTyfWwN5wc7St --jserver ".$Server." --resource ".$BName." --message-type=headline --chatroom ".$Group.""); + return $ERROR; + } +} +function send_user($BName,$recitp,$Send){ + include('/path/to/config/.tidysearch.php'); + $ERROR=shell_exec("echo '".$Send."' | ".$ChatPRG." --username='".$ChatUser."' --password='".$ChatPW."' --jserver='".$ChatServer."' --resource ".$BName." --message-type=headline ".$recitp); +} +function pad_2($ThisNumber){if (isset($ThisNumber)){return str_pad($ThisNumber,2,"0",STR_PAD_LEFT);}else{return "00";}} +function pad_3($ThisNumber){if (isset($ThisNumber)){return str_pad($ThisNumber,3,"0",STR_PAD_LEFT);}else{return "000";}} +function pad_5($ThisNumber){if (isset($ThisNumber)){return str_pad($ThisNumber,5,"0",STR_PAD_LEFT);}else{return "00000";}} +function pad_8($ThisNumber){if (isset($ThisNumber)){return str_pad($ThisNumber,8,"0",STR_PAD_LEFT);}else{return "00000000";}} +/* Test external sites */ +function channel_data($url){ + $ch=curl_init($url); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch, CURLOPT_POST, true); + curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); + curl_setopt($ch, CURLOPT_TIMEOUT, 10); + curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); + curl_setopt($ch, CURLOPT_CERTINFO, true); + curl_setopt($ch, CURLOPT_VERBOSE, true); + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); + curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); + curl_setopt($ch, CURLOPT_REFERER, 'http://search.mpaq.org'); + $config['useragent']='TidyBot (TidySearch http://search.mpaq.org)'; + $logFile=fopen("/tmp/Curl.log", "a"); + curl_setopt($ch, CURLOPT_STDERR, $logFile); + $config['cookie_file']="/tmp/cookie.txt"; + curl_setopt($ch, CURLOPT_COOKIEFILE, $config['cookie_file']); + curl_setopt($ch, CURLOPT_COOKIEJAR, $config['cookie_file']); + curl_setopt($ch, CURLOPT_USERAGENT, $config['useragent']); + $response=curl_exec($ch); + if (curl_errno($ch)){ + $send="Channel Failed: ".__LINE__."\nresponse: ".$response."\ncurl_error: ".curl_error($ch); + return false; + }else{ + curl_close($ch); + return trim($response); + } +} +function test_channel($url){ + $home_dir=dirname(__FILE__); + include('/path/to/config/.tidysearch.php'); + $curl_test = array( + CURLOPT_HEADER => true, // we want headers + CURLOPT_NOBODY => true, // we don't need body + CURLOPT_RETURNTRANSFER => 1, + CURLOPT_TIMEOUT => 1, // timeout on response + CURLOPT_USERAGENT => "TidySearch-".$version." (TidySearch Engine at http://search.mpaq.org)", // who am i + CURLOPT_CONNECTTIMEOUT => 1, // timeout on connect + CURLOPT_MAXREDIRS => 10, // stop after 10 redirects + CURLOPT_SSL_VERIFYPEER => false, + CURLOPT_SSL_VERIFYHOST => false + ); + $ch=curl_init($url); + curl_setopt_array($ch,$curl_test); + $output=curl_exec($ch); + $httpcode=curl_getinfo($ch, CURLINFO_HTTP_CODE); + if ($httpcode==200 or $httpcode==301){ + return true; + }else{ + return $httpcode; + } + return $httpcode; +} +function Hosts($BotID){ + $home_dir=dirname(__FILE__); + include('/path/to/config/.tidysearch.php'); + $con=mysqli_connect($dbro['host'],$dbro['user'],$dbro['passw'],"TidySearch"); + $sql="SELECT * FROM `Hosts` WHERE `HostID`!=".$BotID." AND type='sites' ORDER BY `Hosts`.`HostID` DESC;"; + $ret=mysqli_query($con,$sql); + while($row=mysqli_fetch_array($ret)){ + $HostID=$row['HostID']; + $LAN=$row['LAN_IP']; + $API=$row['API_IP']; + } + $con->close(); + if (test_channel($API)){$host=$API;} + if (test_channel($LAN)){$host=$LAN;} + return $host; +} +function time_check($StartTime){ + $interval = date_diff(date_create($StartTime),date_create(date('H:i:s'))); + return $interval->format('%R%H:%i:%s'); +} +/* A MySQL database that needs to move to PostSQL with language codes */ +function lang($code){ + $home_dir=__DIR__; + include('/path/to/config/.tidysearch.php'); + $lang=$flag=$img=NULL; + if (!isset($code) or $code==""){return NULL;} + $con=mysqli_connect($dbro['host'],$dbro['user'],$dbro['passw'],"users"); + $sql="SELECT * FROM `_lang` WHERE `code` LIKE '%".$code."%' or `lang` LIKE '".$code."';"; + $row=mysqli_fetch_assoc(mysqli_query($con,$sql)); + if (isset($row['lang'])){$lang=$row['lang'];}else{$lang="Language ".$code;} + if (isset($row['flag'])){$flag=$row['flag'];} + if (isset($flag) and file_exists("/var/www/00_00/icons/flags/".$flag)){ + $img="".$lang.""; + $lang=NULL; + } + $con->close(); + unset($code,$flag,$con); + return $lang." ".$img; +} +?> \ No newline at end of file