<?php
// prepend.php
// RJM Programming
// October, 2025
// Message Board helper to talk_about_it.php

$avoice='';
$invoice='';
$outvoice='';
if (isset($_GET['voice'])) {
   $avoice=$_GET['voice'];
   $invoice='<input type=hidden name=voice value="' . str_replace('+',' ',urldecode($_GET['voice'])) . '"></input>';
   $outvoice='<input type=hidden id=overriding name=overriding value="' . explode(' ',str_replace('+',' ',urldecode($_GET['voice'])))[0] . '"></input>';
} else if (isset($_POST['voice'])) {
   $avoice=$_POST['voice'];
   $invoice='<input type=hidden name=voice value="' . str_replace('+',' ',urldecode($_POST['voice'])) . '"></input>';
   $outvoice='<input type=hidden id=overriding data-name=overriding value="" title="' . explode(' ',str_replace('+',' ',urldecode($_POST['voice'])))[0] . '"></input>';
}
$ifsay='';
$afters='';
$lastgmtatt='';
$eletype="textarea";
$eletype="div";
$sofarlist="|";
if (file_exists($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . ".." . DIRECTORY_SEPARATOR . "talktoday-user.txt")) {
    $sofarlist=file_get_contents($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . ".." . DIRECTORY_SEPARATOR . "talktoday-user.txt");
} else {
    file_put_contents($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . ".." . DIRECTORY_SEPARATOR . "talktoday-user.txt", "|");
}
        
function server_remote_addr() {
    $rma = $_SERVER['REMOTE_ADDR'];
    //$ua = strtolower($_SERVER['HTTP_USER_AGENT']);
    // you can add different browsers with the same way ..
    if (1 == 2) {
    if(preg_match('/(chromium)[ \/]([\w.]+)/', $ua))
            $rma = '000000'.$rma;
    elseif(preg_match('/(chrome)[ \/]([\w.]+)/', $ua))
            $rma = '00000'.$rma;
    elseif(preg_match('/(safari)[ \/]([\w.]+)/', $ua))
            $rma = '0000'.$rma;
    elseif(preg_match('/(opera)[ \/]([\w.]+)/', $ua))
            $rma = '000'.$rma;
    elseif(preg_match('/(msie)[ \/]([\w.]+)/', $ua))
            $rma = '00'.$rma;
    elseif(preg_match('/(mozilla)[ \/]([\w.]+)/', $ua))
            $rma = '0'.$rma;
    }
    return str_replace(':','_',str_replace('.','_',$rma));
}

function updatedet($ipis, $nnis, $locdtis, $grplookupis) {
    global $sofarlist;
    $cntis='';
    if (strpos((',' . $grplookupis . ','), ',' . $nnis . '[') !== false && strpos((',' . $grplookupis . ','), ',' . $nnis . '[]') === false) {
      if (strpos(explode("]", explode(',' . $nnis . '[', (',' . $grplookupis . ','))[1])[0], "@") !== false) {
        $cntis=explode("]", explode(',' . $nnis . '[', (',' . $grplookupis . ','))[1])[0];
      } else if (str_replace('0','',str_replace('1','',str_replace('2','',str_replace('3','',str_replace('4','',str_replace('5','',str_replace('6','',str_replace('7','',str_replace('8','',str_replace('9','',(explode("]", explode(',' . $nnis , '[', (',' . $grplookupis . ','))[1])[0]))))))))))) == '') {
        $cntis=explode("]", explode(',' . $nnis . '[', (',' . $grplookupis . ','))[1])[0];
      }
    }
    if (strpos($sofarlist, "|" . $nnis . "`") === false) {
      //file_put_contents("x.x", $nnis . " not found " . $sofarlist . "\n");
      $sofarlist.=str_replace('+',' ', urldecode($_GET['nickname'])) . "`" . $locdtis . "`" . $ipis . "`" . $cntis . "|";
      file_put_contents($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . ".." . DIRECTORY_SEPARATOR . "talktoday-user.txt", $sofarlist);
    } else if ($cntis != '' && strpos((explode('|', explode("|" . $nnis . "`", $sofarlist)[1])[0] . '|'), '`|') !== false) {
      //file_put_contents("x.x", $nnis . " found\n");
      $sofarlist=str_replace("|" . $nnis . "`" . explode('|', explode("|" . $nnis . "`", $sofarlist)[1])[0] . '|', "|" . $nnis . "`" . explode('|', explode("|" . $nnis . "`", $sofarlist)[1])[0] . $cntis . '|', $sofarlist);
      file_put_contents($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . ".." . DIRECTORY_SEPARATOR . "talktoday-user.txt", $sofarlist);
    //} else {
    //  file_put_contents("x.x", $nnis . " semi-found " . $sofarlist . " " . $cntis . " " . $grplookupis . "\n");
    }
} 

function nobrk($invb) {
  $invb=str_replace(' & ',' and ',$invb);
  return str_replace('"','',str_replace("'","",str_replace('{','',str_replace('}','',str_replace('(','',str_replace(')','',$invb))))));
}

function showlocaldt() {
  global $sofarlist;
  if (isset($_GET['localtz']) && isset($_GET['nickname'])) {
    $nnis=str_replace('+',' ', urldecode($_GET['nickname']));
    if (strpos($sofarlist, "|" . str_replace('+',' ', urldecode($_GET['nickname'])) . "`") === false) {
      $sofarlist.=str_replace('+',' ', urldecode($_GET['nickname'])) . "`" . str_replace('+',' ', urldecode($_GET['localtz'])) . "`" . server_remote_addr() . "`|";
      file_put_contents($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . ".." . DIRECTORY_SEPARATOR . "talktoday-user.txt", $sofarlist);
    } else if (substr((explode('|', explode("|" . $nnis . "`", $sofarlist)[1])[0] . '|'), 0,1) == "`") {
      $sofarlist=str_replace("|" . $nnis . "`" . explode('|', explode("|" . $nnis . "`", $sofarlist)[1])[0] . '|', str_replace("``", "`" . str_replace('+',' ', urldecode($_GET['localtz'])) . "`", "|" . $nnis . "`" . explode('|', explode("|" . $nnis . "`", $sofarlist)[1])[0] . '|'), $sofarlist);
      file_put_contents($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . ".." . DIRECTORY_SEPARATOR . "talktoday-user.txt", $sofarlist);
    }
  } else if (isset($_POST['localtz']) && isset($_POST['nickname'])) {
    $nnis=str_replace('+',' ', urldecode($_POST['nickname']));
    if (strpos($sofarlist, "|" . str_replace('+',' ', urldecode($_POST['nickname'])) . "`") === false) {
      $sofarlist.=str_replace('+',' ', urldecode($_POST['nickname'])) . "`" . str_replace('+',' ', urldecode($_POST['localtz'])) . "`" . server_remote_addr() . "`|";
      file_put_contents($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . ".." . DIRECTORY_SEPARATOR . "talktoday-user.txt", $sofarlist);
    } else if (substr((explode('|', explode("|" . $nnis . "`", $sofarlist)[1])[0] . '|'), 0,1) == "`") {
      $sofarlist=str_replace("|" . $nnis . "`" . explode('|', explode("|" . $nnis . "`", $sofarlist)[1])[0] . '|', str_replace("``", "`" . str_replace('+',' ', urldecode($_POST['localtz'])) . "`", "|" . $nnis . "`" . explode('|', explode("|" . $nnis . "`", $sofarlist)[1])[0] . '|'), $sofarlist);
      file_put_contents($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . ".." . DIRECTORY_SEPARATOR . "talktoday-user.txt", $sofarlist);
    }
  }
  if (isset($_GET['localdt'])) {
    if (strlen($_GET['localdt']) > 0) {
      return "{" . str_replace("  "," +",str_replace('+',' ', urldecode($_GET['localdt']))) . "}";
    }
  } else if (isset($_POST['localdt'])) {
    if (strlen($_POST['localdt']) > 0) {
      return "{" . str_replace("  "," +",str_replace('+',' ', urldecode($_POST['localdt']))) . "}";
    }
  }
}

function dtrework($bigixnts) {
  $ixnts=$bigixnts;
  if (strpos(strtolower($bigixnts), ' says at ') !== false) {
    $ixnts=explode(' ...',explode(' says at ', strtolower($bigixnts))[1])[0];
  }
  $slbits=explode('/', $ixnts);
  $scbits=explode(':', $ixnts);
  return explode(' ',$slbits[2])[0] . $slbits[1] . $slbits[0] . explode(':', explode(' ',$slbits[2])[1])[0] . explode(' ',$scbits[1])[0];
}

$myip=server_remote_addr();
$regarding=$myip;
if (isset($_POST['nickname'])) {
  if (strlen($_POST['nickname']) > 0) {
    if (isset($_POST['groupis'])) {
      updatedet($regarding, str_replace('+', ' ', urldecode($_POST['nickname'])), '', str_replace('+', ' ', urldecode($_POST['groupis'])));
    } else {
      updatedet($regarding, str_replace('+', ' ', urldecode($_POST['nickname'])), '', '');
    }
    $regarding=str_replace('+', ' ', urldecode($_POST['nickname']));
  }
} else if (isset($_GET['nickname'])) {
  if (strlen($_GET['nickname']) > 0) {
    if (isset($_GET['groupis'])) {
      updatedet($regarding, str_replace('+', ' ', urldecode($_GET['nickname'])), '', str_replace('+', ' ', urldecode($_GET['groupis'])));
    } else {
      updatedet($regarding, str_replace('+', ' ', urldecode($_GET['nickname'])), '', '');
    }
    if (isset($_GET['localtz'])) {
      showlocaldt();
    }
    $regarding=str_replace('+', ' ', urldecode($_GET['nickname']));
  }
}

$tabcol="yellow";
$groupis="";
$grpsuff="";
$grouptb="";
$ntry=0;
$sback="";
$isfilter=false;
$filterarr=[];
$recsarr=[];
date_default_timezone_set("UTC");
$localtime_assoc = localtime(time(), false);
$twoday=substr(('0' . $localtime_assoc[3]), -2, 2);
$twomon=substr(('0' . (1 + $localtime_assoc[4])), -2, 2);
$twohour=substr(('0' . $localtime_assoc[2]), -2, 2);
$twomin=substr(('0' . $localtime_assoc[1]), -2, 2);

if (isset($_POST['groupis'])) {
  $tabcol="orange";
  $groupis=str_replace('+', ' ', urldecode($_POST['groupis']));
  $grouptb="<input type=hidden id=groupis name=groupis value='" . $groupis . "'></input>";
  $regarding.=" group is " . $groupis;
  $grpsuff="_" . base64_encode($groupis);
  if (file_exists($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . ".." . DIRECTORY_SEPARATOR . "talktoday_" . $ntry . ".txt")) {
   $sback=shell_exec('fgrep -l "' . $groupis . '" ' . $_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . ".." . DIRECTORY_SEPARATOR . "talktoday_*.txt");
  }
  if (strpos($sback, "talktoday_") === false) {
  while (file_exists($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . ".." . DIRECTORY_SEPARATOR . "talktoday_" . $ntry . ".txt")) {
   $ntry++;
  }
  $grpsuff="_" . $ntry;
  file_put_contents($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . ".." . DIRECTORY_SEPARATOR . "talktoday" . $grpsuff . ".txt", $groupis . "\n");
  } else {
   $grpsuff=explode('.', explode(':', explode("talktoday", $sback)[1])[0])[0];
  }
} else if (isset($_GET['groupis'])) {
  $tabcol="orange";
  $groupis=str_replace('+', ' ', urldecode($_GET['groupis']));
  $grouptb="<input type=hidden id=groupis name=groupis value='" . $groupis . "'></input>";
  $regarding.=" group is " . $groupis;
  $grpsuff="_" . base64_encode($groupis);
  if (file_exists($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . ".." . DIRECTORY_SEPARATOR . "talktoday_" . $ntry . ".txt")) {
   $sback=shell_exec('fgrep -l "' . $groupis . '" ' . $_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . ".." . DIRECTORY_SEPARATOR . "talktoday_*.txt");
  }
  if (strpos($sback, "talktoday_") === false) {
  while (file_exists($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . ".." . DIRECTORY_SEPARATOR . "talktoday_" . $ntry . ".txt")) {
   $ntry++;
  }
  $grpsuff="_" . $ntry;
  file_put_contents($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . ".." . DIRECTORY_SEPARATOR . "talktoday" . $grpsuff . ".txt", $groupis . "\n");
  } else {
   $grpsuff=explode('.', explode(':', explode("talktoday", $sback)[1])[0])[0];
  }
}

if (isset($_POST['filteris'])) {
  if ($tabcol == "orange") {
  $tabcol="lightgreen";
  } else {
  $tabcol="lightblue";
  }
  $isfilter=true;
  $filterarr=explode(';', str_replace('+',' ',urldecode($_POST['filteris'])));
} else if (isset($_GET['filteris'])) {
  if ($tabcol == "orange") {
  $tabcol="lightgreen";
  } else {
  $tabcol="lightblue";
  }
  $isfilter=true;
  $filterarr=explode(';', str_replace('+',' ',urldecode($_GET['filteris'])));
}

$prerel="";
if (file_exists($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . ".." . DIRECTORY_SEPARATOR . "talktoday" . $grpsuff . ".txt")) {
  $prerel=str_replace("~~", "\n", file_get_contents($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . ".." . DIRECTORY_SEPARATOR . "talktoday" . $grpsuff . ".txt"));
}
if (isset($_POST['msg'])) {
  if (strlen($_POST['msg']) > 0) {
   $recpref="";
   if (str_replace("~~", "\n", str_replace('+', ' ', urldecode($_POST['msg']))) != str_replace('+', ' ', urldecode($_POST['msg']))) {
     $recpref="\n";
   }
   if (isset($_POST['nickname'])) {
    $regarding=str_replace('+', ' ', urldecode($_POST['nickname']));
    file_put_contents($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . ".." . DIRECTORY_SEPARATOR . "talk_today_" . $myip . ".txt", str_replace('+', ' ', urldecode($_POST['nickname'])) . " says at " . $twoday . '/' . $twomon . '/' . (1900 + $localtime_assoc[5]) . ' ' . $twohour . ':' . $twomin . " GMT " . showlocaldt() . " ... " . $recpref . str_replace("~~", "\n", str_replace('+', ' ', urldecode($_POST['msg']))));
   } else {
    file_put_contents($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . ".." . DIRECTORY_SEPARATOR . "talk_today_" . $myip . ".txt", $myip . " says at " . $twoday . '/' . $twomon . '/' . (1900 + $localtime_assoc[5]) . ' ' . $twohour . ':' . $twomin . " GMT " . showlocaldt() . " ... " . $recpref . str_replace("~~", "\n", str_replace('+', ' ', urldecode($_POST['msg']))));
   }
   if ($avoice != '') {
   }
  }
}
$tahtml="<" . $eletype . " style=width:95%;height:600px; id=myta value=''></" . $eletype . ">";
$reltalk="";
$it = new GlobIterator($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . ".." . DIRECTORY_SEPARATOR . "talk_today*.txt");
$last2mis = 9020;
foreach ( $it as $file ) {
    $reltalk.=file_get_contents($file) . "\n";
    if ((time() - $file->getMTime()) < $last2mis) {
      unlink($file);
    }
}

if ($reltalk != "") {
  $prerel.="\n" . $reltalk . "\n";
}


  if ($prerel != "") {
   $firstchar="\n";
   //file_put_contents('x.x', $prerel);
   $ourprerel=str_replace("\n", "\n\n", $prerel);
if ($avoice != '' && !isset($_POST['msg'])) {
   $firstw=str_replace('_',' ',explode(' ', str_replace('+',' ',urldecode($avoice)))[0]);
   if ($firstw == 'says at ') {
     $afters=$prerel;
   } else if (strpos($prerel, $firstw) !== false) {
     $afters=explode(explode($firstw, $prerel)[0] . $firstw . explode("\n",explode($firstw, $prerel)[1])[0] . "\n", $prerel)[1];
   //file_put_contents('xx.xx', $firstw . explode("\n",explode($firstw, $prerel)[1])[0] . "\n");
     if (1 == 1) {
     $afterlines=explode("\n", $afters);
     $prebit=explode("says at", $afters)[0];
     if ($prebit != '') {
       $prebit=str_replace("\n" . explode("\n",$prebit)[-1 + sizeof(explode("\n",$prebit))],"\n",$prebit);
     }
     if ($prebit != '') { 
       $afters=substr($afters, strlen($prebit)); 
     }
     if (trim($afters) != "") { 
   //file_put_contents('x.xx', '' . sizeof($afterlines) . ' +++ ' . $prebit . ' ... ' . $afters);
       if (!isset($_POST['msg'])) {
       if (PHP_OS == 'Darwin') {
   //file_put_contents('x.xxx', "say -v " . explode(" ",str_replace('+',' ',urldecode($avoice)))[-1 + sizeof(explode(" ",str_replace('+',' ',urldecode($avoice))))] . ' "' . str_replace("\n"," ",$afters) . '"');
       exec("say -v " . explode(" ",str_replace('+',' ',urldecode($avoice)))[-1 + sizeof(explode(" ",str_replace('+',' ',urldecode($avoice))))] . ' "' . nobrk(str_replace("\n"," ",$afters)) . '"');
       } else {
       $ifsay=("<iframe name=isayf id=isayf title='' style=display:none; src='/About_Us.html' onload=\"if (this.title.length == 0) { this.title='say';  window.open('http://localhost:8888/macos_say_record.php?justsayingforafriend=y&saythis=" . urlencode(nobrk($afters)) . "&voice=" . explode(" ",str_replace('+',' ',urldecode($avoice)))[-1 + sizeof(explode(" ",str_replace('+',' ',urldecode($avoice))))] . "','isayf'); }\"></iframe>");
       //file_put_contents('x.xxx', $ifsay);
       }
       }
     }
   //file_put_contents('xx.xxx', $tobereplaced);
   //file_put_contents('x.xxx', $afters);
     }
   }
}

 $lastgmtatt=' data-lastgmt="" data-afters="' . urlencode($afters) . '" ';
 $lastgs=explode(' says at ', $prerel);
 if (sizeof($lastgs) > 1) {
   $lastgmtatt=' data-lastgmt="' . str_replace('2YouWillNeverFindThis2:52','06:51',explode(' GMT', $lastgs[-1 + sizeof($lastgs)])[0]) . ' GMT" data-afters="' . urlencode($afters) . '" ';
 }
  }


if ($isfilter) {
  $recsarr=explode("\n", $prerel);
  $recisokay=false;
  $ist=0;
  if ($groupis != "") {
  $ist=1;
  if (strpos($prerel, $groupis) !== false) {
    $prerel=substr($prerel, strlen($groupis)) . "\n\n";
  } else {
    $prerel="";
  }
  } else {
    $prerel="";
  }

  for ($ih=0; $ih<sizeof($recsarr); $ih++) {
    $recisokay=true;
    $numis=0;
    $unitis='';
    $versuspart='';
    for ($ib=$ist; $ib<sizeof($filterarr); $ib++) {
      if (strpos(strtolower($recsarr[$ih]), ' says at ') === false) {
        $recisokay=false;
      } else if (trim($filterarr[$ib]) == '') {
        $recisokay=$recisokay;
      } else if (strpos(strtolower($filterarr[$ib]), 'last ') !== false) {
        //$versuspart=dtrework(explode(' ...',explode(strtolower($recsarr[$ih]), ' says at ')[1])[0]);
        $versuspart=dtrework($recsarr[$ih]);
        $numis=explode(' ',explode('last ', strtolower($filterarr[$ib]))[1])[0];
        if (trim($numis) != '' && substr(($numis . ' '),0,1) >= '0' && substr(($numis . ' '),0,1) <= '9') {
         $unitis=strtolower(explode(' ', trim($filterarr[$ib]))[-1 + sizeof(explode(' ', trim($filterarr[$ib])))]);
         if ($unitis == 'm' || strpos($unitis, 'minute') !== false) {
          $nlocaltime_assoc = localtime(((-60 * $numis) + time()), false);
         } else if ($unitis == 's' || strpos($unitis, 'second') !== false) {
          $nlocaltime_assoc = localtime(((-1 * $numis) + time()), false);
         } else if ($unitis == 'h' || strpos($unitis, 'hour') !== false) {
          $nlocaltime_assoc = localtime(((-3600 * $numis) + time()), false);
         } else if ($unitis == 'd' || strpos($unitis, 'day') !== false) {
          $nlocaltime_assoc = localtime(((-86400 * $numis) + time()), false);
         } else if ($unitis == 'y' || strpos($unitis, 'year') !== false) {
          $nlocaltime_assoc = localtime(((-31536 * $numis) + time()), false);
         } else if (strpos($unitis, 'month') !== false) {
          $nlocaltime_assoc = localtime(((-2628 * $numis) + time()), false);
         } else if ($numis == $unitis) {
          $nlocaltime_assoc = localtime(((-60 * $numis) + time()), false);
         } else {
          $unitis='';
         }
         if ($unitis != '') {
          $ntwoday=substr(('0' . $nlocaltime_assoc[3]), -2, 2);
          $ntwomon=substr(('0' . (1 + $nlocaltime_assoc[4])), -2, 2);
          $ntwohour=substr(('0' . $nlocaltime_assoc[2]), -2, 2);
          $ntwomin=substr(('0' . $nlocaltime_assoc[1]), -2, 2);
          if ($versuspart < dtrework($ntwoday . '/' . $ntwomon . '/' . (1900 + $nlocaltime_assoc[5]) . ' ' . $ntwohour . ':' . $ntwomin)) {
            $recisokay=false;
          }
         }
        }
      } else if (substr($filterarr[$ib], 0, 1) != '/' && (substr($filterarr[$ib], 0, 1) == '^' || substr($filterarr[$ib], -1, 1) == '$' || strpos($filterarr[$ib], '*') !== false || strpos($filterarr[$ib], '?') !== false || strpos($filterarr[$ib], ']') !== false)) {
        if (substr($filterarr[$ib], 0, 1) == '^' && substr($filterarr[$ib], -1, 1) == '$') {
          //echo "pattern is " . 'ynft' . substr($filterarr[$ib], 1, (-2 + strlen($filterarr[$ib]))) . 'ynft' . " regarding ynft" . $recsarr[$ih] . 'ynft';
          if (!fnmatch('ynft' . substr($filterarr[$ib], 1, (-2 + strlen($filterarr[$ib]))) . 'ynft', 'ynft' . $recsarr[$ih] . 'ynft')) {
          //if (strpos('~@#' . $recsarr[$ih] . '~@#', '~@#' . substr($filterarr[$ib], 1, (-2 + strlen($filterarr[$ib]))) . '~@#') === false) {
               $recisokay=false;
          }
        } else if (substr($filterarr[$ib], 0, 1) == '^') {
          //echo "pattern is " . '' . substr($filterarr[$ib], 1, (-1 + strlen($filterarr[$ib]))) . (substr($filterarr[$ib],-1,1) != '*' ? '*' : '') . " regarding " . $recsarr[$ih] . '';
          if (!fnmatch('' . substr($filterarr[$ib], 1, (-1 + strlen($filterarr[$ib]))) . (substr($filterarr[$ib],-1,1) != '*' ? '*' : ''), '' . $recsarr[$ih] . '')) {
          //if (strpos(substr($recsarr[$ih],0,(-1 + strlen($filterarr[$ib]))), substr($filterarr[$ib], 1)) === false) {
               $recisokay=false;
          }
        } else if (substr($filterarr[$ib], -1, 1) == '$') {
          //echo "pattern is " . (substr($filterarr[$ib],0,1) != '*' ? '*' : '') . substr($filterarr[$ib], 0, (-1 + strlen($filterarr[$ib]))) . 'ynft' . " regarding ynft" . $recsarr[$ih] . 'ynft';
          if (!fnmatch((substr($filterarr[$ib],0,1) != '*' ? '*' : '') . substr($filterarr[$ib], 0, (-1 + strlen($filterarr[$ib]))) . 'ynft', '' . $recsarr[$ih] . 'ynft')) {
          //if (strpos($recsarr[$ih] . '~@#', substr($filterarr[$ib], 0, (-1 + strlen($filterarr[$ib]))) . '~@#') === false) {
               $recisokay=false;
          }
        } else {
          if (!fnmatch((substr($filterarr[$ib],0,1) != '*' ? '*' : '') . $filterarr[$ib] . (substr($filterarr[$ib],-1,1) != '*' ? '*' : ''), $recsarr[$ih])) {
               $recisokay=false;
          }
        }
      } else if (substr($filterarr[$ib], 0, 1) == '/' && (substr($filterarr[$ib], 0, 2) == '/^' || substr($filterarr[$ib], -2, 2) == '$/' || substr($filterarr[$ib], 0, 1) == substr($filterarr[$ib], -1, 1))) {
        if (substr($filterarr[$ib], 0, 2) == '/^' && substr($filterarr[$ib], -2, 2) == '$/') {
          if (!fnmatch('ynft' . str_replace('/^','',str_replace('$/','',$filterarr[$ib])) . 'ynft', 'ynft' . $recsarr[$ih] . 'ynft')) {
               $recisokay=false;
          }
        } else if (substr($filterarr[$ib], 0, 2) == '/^') {
          //echo "pattern is " . 'ynft' . str_replace('/','',str_replace('/^','',$filterarr[$ib])) . (substr($filterarr[$ib],-2,1) != '*' ? '*' : '') . " regarding ynft" . $recsarr[$ih];
          if (!fnmatch('ynft' . str_replace('/','',str_replace('/^','',$filterarr[$ib])) . (substr($filterarr[$ib],-2,1) != '*' ? '*' : ''), 'ynft' . $recsarr[$ih])) {
               $recisokay=false;
               //echo "\noopS\n";
          }
        } else if (substr($filterarr[$ib], -2, 2) == '$/') {
          //echo "pattern is " . (substr($filterarr[$ib],1,1) != '*' ? '*' : '') . str_replace('/','',str_replace('$/','',$filterarr[$ib])) . 'ynft' . " regarding ynft" . $recsarr[$ih] . "ynft";
          if (!fnmatch((substr($filterarr[$ib],1,1) != '*' ? '*' : '') . str_replace('/','',str_replace('$/','',$filterarr[$ib])) . 'ynft', $recsarr[$ih] . 'ynft')) {
               $recisokay=false;
          }
        } else {
          //echo "pattern is " . (substr($filterarr[$ib],1,1) != '*' ? '*' : '') . substr($filterarr[$ib], 1, (-2 + strlen($filterarr[$ib]))) . " regarding " . $recsarr[$ih];
          if (!fnmatch((substr($filterarr[$ib],1,1) != '*' ? '*' : '') . substr($filterarr[$ib], 1, (-2 + strlen($filterarr[$ib]))) . (substr($filterarr[$ib],-2,1) != '*' ? '*' : ''), $recsarr[$ih])) {
               $recisokay=false;
          //echo "\n" . "oops\n";
          }
        }
      }
      
      
    }
    if ($recisokay) {
      $prerel.=$recsarr[$ih] . "\n\n";
    }
  }
}

$bigprerel=$prerel;
if ($groupis != "") {
  if (strpos($prerel, $groupis) !== false) {
    $prerel=substr($prerel, strlen($groupis));
  }
}

if ($prerel != "") {
 if ($lastgmtatt != '' && isset($_POST['msg'])) {
 $lastgs=explode(' says at ', $prerel);
 if (sizeof($lastgs) > 1) {
   if (isset($_POST['overriding'])) {
   $lastgmtatt=' data-lastgmt="' . str_replace('_',' ',str_replace('+',' ',urldecode($_POST['overriding'])))  . '" data-afters="' . urlencode($afters) . '" ';
   } else {
   $lastgmtatt=' data-lastgmt="' . str_replace('2YouWillNeverFindThis2:52','06:51',explode(' GMT', $lastgs[-1 + sizeof($lastgs)])[0]) . ' GMT" data-afters="' . urlencode($afters) . '" ';
   }
 }
 } else if ($lastgmtatt != '' && !isset($_POST['msg'])) {
 $lastgs=explode(' says at ', $prerel);
 if (sizeof($lastgs) > 1) {
   $lastgmtatt=' data-lastgmt="' . str_replace('2YouWillNeverFindThis2:52','06:51',explode(' GMT', $lastgs[-1 + sizeof($lastgs)])[0]) . ' GMT" data-afters="' . urlencode($afters) . '" ';
 }
 }
 if ($reltalk != "") {
  $tahtml="<" . $eletype . " " . ($eletype == "div" ? $lastgmtatt . " onmouseover='holdyourhorses=true;' onmouseout='holdyourhorses=false;' title='Can double click to reveal all the talk' ondblclick='prompt(this.innerText.replace(/\<br\>/g,String.fromCharCode(10)),this.innerText.replace(/\<br\>/g,String.fromCharCode(10)));' " : $lastgmtatt) . " data-refresh=y data-name=myta" . $myip . " style=" . ($eletype == "div" ? "overflow-y:scroll;flex-basis:500px;display:inline-flex;justify-content:flex-end;flex-direction:column;" : "") . "background-color:" . $tabcol . ";width:95%;height:70%; id=myta " . ($eletype == "div" ? "data-" : "") . "value=''>" . ($eletype == "div" ? str_replace("\n","<br>",$prerel) : $prerel) . "</" . $eletype . ">" . $ifsay . $invoice . $outvoice;
  file_put_contents($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . ".." . DIRECTORY_SEPARATOR . "talktoday" . $grpsuff . ".txt", $bigprerel);
 } else {
  $tahtml="<" . $eletype . " " . ($eletype == "div" ? $lastgmtatt . " onmouseover='holdyourhorses=true;' onmouseout='holdyourhorses=false;' title='Can double click to reveal all the talk' ondblclick='prompt(this.innerText.replace(/\<br\>/g,String.fromCharCode(10)),this.innerText.replace(/\<br\>/g,String.fromCharCode(10)));' " : $lastgmtatt) . " data-name=myta" . $myip . " style=" . ($eletype == "div" ? "overflow-y:scroll;flex-basis:500px;display:inline-flex;justify-content:flex-end;flex-direction:column;" : "") . "background-color:" . $tabcol . ";width:95%;height:70%; id=myta " . ($eletype == "div" ? "data-" : "") . "value=''>" . ($eletype == "div" ? str_replace("\n","<br>",$prerel) : $prerel) . "</" . $eletype . ">" . $ifsay . $invoice . $outvoice;
 }
}

?>