Post
Topic
Board Meta
Merits 20 from 6 users
Re: [BRAINSTORM] Any requests for custom extensions/user scripts for BitcoinTalk?
by
CryptoNeed
on 22/06/2019, 12:14:22 UTC
⭐ Merited by LoyceV (8) ,TryNinja (4) ,suchmoon (4) ,Halab (2) ,TheBeardedBaby (1) ,o_e_l_e_o (1)
Seems to work, could be improved for sure.
I think you're overestimating my php-knowledge: I have no idea what to do with this Tongue

Quote
it would be much faster to send individual request to the database (e.g. by GET).
If you tell us the structure of the database, it is actually super easy to implement.
I don't have a database, just static HTML. That makes it very fast to browse as the server just has to read the file from disk, but I'm also at the point that adding more functionality becomes exceedingly difficult. I know nothing about databases and php Sad

Np, I will write an example script based on your .txt.
Database details for such functionalities would have to be provided by btct admin anyways.

Will adjust the script now ...

Output in HTML:

Quote

//GET Request by: merithtml.php?donor=USERID

$url = "http://loyce.club/Merit/merit.all.txt";
$file = file($url);
$file = str_replace("   ", ",",$file);
$file = str_replace("\r\n", "",$file);
// put the array together
foreach ($file as $line => $value) {
   $value = explode(",", $value);
    $bigArray[] = array("Donor" => $value[3], "Recipient" => $value[4], "Merits" => $value[1], "Msg" => $value[2], "DTG" => $value[0]);
}

function searchForDonor($uid, $array) {
   echo "";
   foreach ($array as $key => $val) {
      if($val["Donor"] === $uid) {
         //print_r($array[$key]);
         echo "
               
               
               
               
               
            ";
      }
   }
   return null;
   echo "
".date("d.m.Y H:i:s", $val["DTG"])."".$val["Msg"]."".$val["Donor"]."-(".$val["Merits"].")->".$val["Recipient"]."
";
}

function searchForRecipient($uid, $array) {
   echo "";
   foreach ($array as $key => $val) {
      if($val["Recipient"] === $uid) {
         //print_r($array[$key]);
         echo "
               
               
               
               
               
            ";
      }
   }
   return null;
   echo "
".date("d.m.Y H:i:s", $val["DTG"])."".$val["Msg"]."".$val["Recipient"]."<-(".$val["Merits"].")-".$val["Donor"]."
";
}

if(isset($_GET["donor"])) {
   searchForDonor($_GET["donor"], $bigArray);
}

if(isset($_GET["recipient"])) {
   searchForRecipient($_GET["recipient"], $bigArray);
}

?>


Output as JSON array:

Quote

//GET Request by: meritjson.php?donor=USERID
header('Content-Type: application/json');
$url = "http://loyce.club/Merit/merit.all.txt";
$file = file($url);
$file = str_replace("   ", ",",$file);
$file = str_replace("\r\n", "",$file);
// put the array together
foreach ($file as $line => $value) {
   $value = explode(",", $value);
    $bigArray[] = array("Donor" => $value[3], "Recipient" => $value[4], "Merits" => $value[1], "Msg" => $value[2], "DTG" => $value[0]);
}

function searchForDonor($uid, $array) {
   foreach ($array as $key => $val) {
      if($val["Donor"] === $uid) {
         echo json_encode($array[$key], JSON_PRETTY_PRINT);
      }
   }
   return null;
}

function searchForRecipient($uid, $array) {
   foreach ($array as $key => $val) {
      if($val["Recipient"] === $uid) {
         echo json_encode($array[$key], JSON_PRETTY_PRINT);
      }
   }
   return null;
}

if(isset($_GET["donor"])) {
   searchForDonor($_GET["donor"], $bigArray);
}

if(isset($_GET["recipient"])) {
   searchForRecipient($_GET["recipient"], $bigArray);
}


?>


Once uploaded, you can search your .txt for merits given and received by users through file.php?donor=USERID and ?recipient=USERID
Hope it fits the needs.  Smiley