From 048892d2499aaad75ad9b958b88cba22bfdc8edd Mon Sep 17 00:00:00 2001 From: 7trey <7trey@noreply.codeberg.org> Date: Thu, 1 Apr 2021 06:42:30 +0200 Subject: [PATCH] Add 'tool/mastodonfind/index.php' --- tool/mastodonfind/index.php | 179 ++++++++++++++++++++++++++++++++++++ 1 file changed, 179 insertions(+) create mode 100644 tool/mastodonfind/index.php diff --git a/tool/mastodonfind/index.php b/tool/mastodonfind/index.php new file mode 100644 index 000000000..8de02e8c3 --- /dev/null +++ b/tool/mastodonfind/index.php @@ -0,0 +1,179 @@ + +$vi_opt_timeB = $_GET['tib']??$_POST['tib']; +if (!preg_match("/^2([0-9]{3})\-([0-9]{2})\-([0-9]{2})$/", $vi_opt_timeB)) { + $vi_opt_timeB = ''; +} //<-B +$vi_internal_tia = $vi_internal_tib = ''; +if ($vi_opt_timeA != '') { + $vi_internal_tia = gmdate('U', strtotime($vi_opt_timeA . ' 00:00:00')); + if ($vi_internal_tia > NOWTIME_U) { + $vi_internal_tia = NOWTIME_U; + } +} +if ($vi_opt_timeB != '') { + $vi_internal_tib = gmdate('U', strtotime($vi_opt_timeB . ' 23:59:59')); + if ($vi_internal_tib > NOWTIME_U) { + $vi_internal_tib = NOWTIME_U; + } +} +if (isset($vi_query)) { + $vi_query = cleanse_str($vi_query); + if (is_attackable_str($vi_query)) { + $vi_query = ''; + } +} +$vi_showquery = htmlspecialchars($vi_query, ENT_QUOTES); +$sql_Result = []; +if (strlen($vi_query) >= 2) { + $sqlme = @new mysqli('localhost', 'REDACTED', 'REDACTED', 'REDACTED'); + if ($sqlme->connect_errno) { + echo ('DB ERROR TRY AGAIN LATER'); + exit; + } + $sql_Query = 'SELECT * FROM REDACTED WHERE '; + $sql_Pcs = []; + $sql_smt = ($vi_opt_sm == 'a') ? 'who' : 'body'; + if (!$vi_opt_inclcf) { + $sql_Pcs[] = "iscf = '0' "; + } + if ($vi_opt_limitlg != '') { + $sql_Pcs[] = "lang = '{$vi_opt_limitlg}' "; + } + if ($vi_internal_tia != '') { + $sql_Pcs[] = "`when` >= '{$vi_internal_tia}' "; + } + if ($vi_internal_tib != '') { + $sql_Pcs[] = "`when` <= '{$vi_internal_tib}' "; + } + foreach (explode(' ', $vi_query) as $w) { + if (strlen($w) <= 1) { + continue; + } + if (strpos($w, 'author:') === 0) { + $w = str_replace('author:', '', $w); + if (strlen($w) < 2) { + continue; + } + $sql_Pcs[] = "who LIKE '%{$w}%' "; + continue; + } + if (strpos($w, '-author:') === 0) { + $w = str_replace('-author:', '', $w); + if (strlen($w) < 2) { + continue; + } + $sql_Pcs[] = "who NOT LIKE '%{$w}%' "; + continue; + } + if (strpos($w, '-') === 0) { + $w = str_replace('-', '', $w); + if (strlen($w) < 2) { + continue; + } + $sql_Pcs[] = "{$sql_smt} NOT LIKE '%{$w}%' "; + continue; + } + $sql_Pcs[] = "{$sql_smt} LIKE '%{$w}%' "; + } + if ($result = $sqlme->query($sql_Query . implode('AND ', $sql_Pcs) . ' ORDER BY `when` DESC LIMIT 500;')) { + while ($g = $result->fetch_array()) { + $sql_Result[] = $g; + } + } + $sqlme->close(); +} +if (isset($vi_json)) { + header('Content-Type: application/json; charset=utf-8'); + $finalRESP = []; + if ($vi_showquery == '') { + $finalRESP = ['method' => ['POST', 'GET'], 'accept_param' => ['q' => ['type' => 'string', 'value' => 'any', 'note' => 'Required'], 'sm' => ['type' => 'string', 'value' => ['a' => 'Account', 't' => 'Toot'], 'note' => 'default is t'], 'cf' => ['type' => 'existence', 'value' => 'any'], 'lg' => ['type' => 'string', 'value' => '2 letter'], 'tia' => ['type' => 'date', 'value' => 'Y-m-d'], 'tib' => ['type' => 'date', 'value' => 'Y-m-d']], 'example' => ['GET' => ['/?json&q=friend', '/?json&cf&lg=en&q=news']]]; + } else { + foreach ($sql_Result as $g) { + $finalRESP[] = ['url' => $g['url'], 'who' => $g['who'], 'when' => $g['when'], 'iscf' => $g['iscf'], 'lang' => $g['lang'], 'body' => str_replace(' ', ' ', $g['body']) ]; + } + } + echo (json_encode($finalRESP)); + exit; +} else { + header('Content-Type: text/html; charset=UTF-8'); + $finalRESP = ''; + foreach ($sql_Result as $g) { + $finalRESP.= '