Filter löschen button
class MFLib {
// Public Variables to be accessed though Class Initialisation in Variable
public $searchQuery = ""; // string: What has been searched; Public Access
public $limitperpage = 15; // int: Default -> 15; Can be overridden
public $current_species; // string: Current Filtered Species (Get Through Database);
public $current_speciesShort; // string: Shorted version of current Filtered Species (Get Through Database); Public Access
public $currentSection = 0;
public $isItMobile = true;
// Private Variables for Class only
private $dbConn; // object: Database Object to interact with while Class is Accessed through function; not for Public access
private $limitbegin; // string: Will be set through current pagenumber; Database knows through this where to start the current Search; no for Public access
private $nsfwfilter;
private $nsfwfilter2;
private $totalpages;
private $lastpage;
private $ifsearch; // string: While a SearchQuery is present it will contain a specific part for the Redirection URL at Footer Page Navigation; not for Public access
private $query_over_species;
private $PageContent;
// Main Functions
function initialize() {
$this->initializeDB();
$this->isMobile();
$this->setCookie();
$this->doNSFW($this->getLink(), $this->getSection());
$this->doNSFWBlur($this->getLink());
$this->doSearch();
$this->doLastPage();
$this->setBeginn();
$this->setCurrentSpecies();
$this->setCurrentTotalPages();
$this->setErrorHandlerFunc();
}
function getSection() {
$section = 0;
if (str_contains($_SERVER['REQUEST_URI'], 'avatar-bases')) {
$section = 3;
} else if (str_contains($_SERVER['REQUEST_URI'], 'avatar-assets')) {
$section = 1;
} else if (str_contains($_SERVER['REQUEST_URI'], 'avatars')) {
$section = 2;
} else if (str_contains($_SERVER['REQUEST_URI'], 'worlds')) {
$section = 4;
}
$this->currentSection = $section;
return $section;
}
function getLink() {
return (empty($_SERVER['HTTPS']) ? 'http' : 'https') . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
}
function isMobile() {
$useragent = $_SERVER['HTTP_USER_AGENT'];
if(preg_match('/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i',$useragent)||preg_match('/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i',$useragent)) {
$this->isItMobile = true;
} else {
$this->isItMobile = false;
}
return $this->isItMobile;
}
// Override Section
function doNSFW($link, $section) {
if (isset($_GET["nsfw"])) {
if ($_GET["nsfw"] == "true") {
$_SESSION["nsfw"] = true;
$_SESSION["promtshown"] = true;
$_SESSION["nsfwblur"] = true;
$link = str_replace("&nsfw=true", "", str_replace("?nsfw=true&", "?", str_replace("?nsfw=true", "", $link)));
header("Location: " . $link);
die();
}
if ($_GET["nsfw"] == "false") {
$_SESSION["nsfw"] = false;
$_SESSION["promtshown"] = true;
$_SESSION["nsfwblur"] = true;
$link = str_replace("&nsfw=false", "", str_replace("?nsfw=false&", "?", str_replace("?nsfw=false", "", $link)));
header("Location: " . $link);
die();
}
}
if (isset($_SESSION["nsfw"]) && $_SESSION["nsfw"] == true) {
$this->nsfwfilter = "AND section=" . $section;
$this->nsfwfilter2 = "WHERE section=" . $section;
} else {
$this->nsfwfilter = "AND section=" . $section . " AND nsfw='0'";
$this->nsfwfilter2 = "WHERE section=" . $section . " AND nsfw='0'";
}
}
function doNSFWBlur($link) {
if (isset($_GET["nsfwblur"])) {
if ($_GET["nsfwblur"] == "true") {
$_SESSION["nsfwblur"] = true;
$link = str_replace("&nsfwblur=true", "", str_replace("?nsfwblur=true&", "?", str_replace("?nsfwblur=true", "", $link)));
header("Location: " . $link);
} else {
$_SESSION["nsfwblur"] = false;
$link = str_replace("&nsfwblur=false", "", str_replace("?nsfwblur=false&", "?", str_replace("?nsfwblur=false", "", $link)));
header("Location: " . $link);
}
}
}
function doSearch() {
if (isset($_GET["s"])) {
$this->searchQuery = str_replace("'", "\'", str_replace("`", "\`", str_replace('"', '\"', $_GET["s"])));
}
if (isset($_GET["s"])) {
$this->ifsearch = "&s=" . $_GET["s"];
} else $this->ifsearch = "";
}
function doLastPage() {
if (isset($_GET["p"])) {
$this->lastpage = $_GET["p"];
} else $this->lastpage = 1;
}
function setBeginn() {
if (isset($_GET["p"])) {
$this->limitbegin = ($_GET["p"] - 1) * $this->limitperpage;
} else {
$_GET["p"] = 1;
$this->limitbegin = 0;
}
}
function setCurrentSpecies() {
if (isset($_GET["t"])) {
$sql = "SELECT * FROM species WHERE `shorted`=\"" . $_GET["t"] . "\" ORDER BY id ASC";
$result = $this->dbConn->query($sql);
$current_type = $result->fetch_assoc();
if ($current_type["species"] == "( - Props - )") $current_type["species"] = "Props";
$this->current_species = $current_type["species"];
$this->current_speciesShort = $current_type["shorted"];
$this->current_species = str_replace("'","\'",str_replace("`","\`",str_replace('"','\"',$this->current_species)));
}
}
function setCookie() {
$maxlifetime = 86400;
$secure = true;
$httponly = true;
$samesite = 'lax';
session_set_cookie_params([
'lifetime' => $maxlifetime,
'path' => '/',
'domain' => $_SERVER['HTTP_HOST'],
'secure' => $secure,
'httponly' => $httponly,
'samesite' => $samesite
]);
}
function setCurrentTotalPages() {
$SEARCH = $this->searchQuery;
if (isset($_GET["sort"]) && $_GET["sort"] == "free") {
$PRICE = "price=0";
} else {
$PRICE = "price IS NOT NULL";
}
// Setting the NSFW Filter for the Content
if (isset($_SESSION["nsfw"]) && $_SESSION["nsfw"] == true) {
$NSFW = "nsfw IS NOT NULL"; // Disable NSFW Filter
} else {
$NSFW = "nsfw=0"; // Enable NSFW Filter
}
$SECTION = "section=" . $this->currentSection;
if ($SEARCH != "") {
$NAME_SEARCH = "name LIKE '%" . $SEARCH . "%'";
$CREATOR_SEARCH = "creator LIKE '%" . $SEARCH . "%'";
$SPECIES_SEARCH = "species LIKE '%" . $SEARCH . "%'";
} else {
$NAME_SEARCH = "name IS NOT NULL";
$CREATOR_SEARCH = "creator IS NOT NULL";
$SPECIES_SEARCH = "species IS NOT NULL";
}
$sql = "SELECT count(*) as total from content WHERE
" . $PRICE . " AND " . $NAME_SEARCH . " AND " . $SECTION . " AND " . $NSFW . "
OR " . $PRICE . " AND " . $CREATOR_SEARCH . " AND " . $SECTION . " AND " . $NSFW . "
OR " . $PRICE . " AND " . $SPECIES_SEARCH . " AND " . $SECTION . " AND " . $NSFW . ";";
$this->totalpages = ceil($this->setQuery($sql)[0]['total'] / $this->limitperpage);
}
function setErrorHandlerFunc() {
// A user-defined error handler function
function myErrorHandler($errno, $errstr, $errfile, $errline) {
echo "Custom error: [$errno] $errstr
";
echo " Error on line $errline in $errfile
";
}
// Set user-defined error handler function
set_error_handler("myErrorHandler");
}
function getErrorPage($page) {
$htmlFile = file_get_contents("/var/www/error/" . $page . ".html");
return $htmlFile;
}
// Database Initialisation
function initializeDB() {
$servername = "localhost";
$username = "database_access";
$password = "DataAccess1.";
$dbname = "avali_shop";
try {
$this->dbConn = new mysqli($servername, $username, $password, $dbname);
$this->testDB();
} catch (Exception $e) {
echo $this->getErrorPage(500);
die();
}
}
function testDB() {
if ($this->dbConn->connect_error) {
die("Connection failed: " . $this->dbConn->connect_error);
}
}
function setQuery($sql) {
$query = $this->dbConn->query($sql);
$array = array();
if ($query->num_rows > 0) {
while ($row = $query->fetch_assoc()) {
$temparray = array();
foreach ($row as $element) {
$key = array_search ($element, $row);
$temparray = $temparray + array($key => $element);
}
array_push($array, $temparray);
}
}
return $array;
}
// Get Database Data
function dataGetOverSpecies() {
return $this->setQuery("SELECT * FROM over_species");
}
function dataGetOtherSpecies() {
return $this->setQuery("SELECT * FROM species WHERE a_tag=\"\"");
}
function dataGetSpecies($tag) {
return $this->setQuery("SELECT * FROM species WHERE a_tag=\"" . $tag . "\" ORDER BY species ASC");
}
function dataGetAllSpecies() {
return $this->setQuery("SELECT * FROM species");
}
function dataGetPageContent() {
$SEARCH = $this->searchQuery;
$LIMIT = "LIMIT " . $this->limitbegin . ", " . $this->limitperpage;
if (isset($_GET["sort"]) && $_GET["sort"] == "free") {
$PRICE = "price=0";
} else {
$PRICE = "price IS NOT NULL";
}
if (isset($_GET["sort"]) && $_GET["sort"] == "priceup") {
$ORDER = "ORDER BY price ASC"; // Sort by Lowest to Highes Price
} else if (isset($_GET["sort"]) && $_GET["sort"] == "pricedown") {
$ORDER = "ORDER BY price DESC"; // Sort by Highes to Lowest Price
} else {
$ORDER = "ORDER BY id DESC"; // Sort by Recently Added
}
// Setting the NSFW Filter for the Content
if (isset($_SESSION["nsfw"]) && $_SESSION["nsfw"] == true) {
$NSFW = "nsfw IS NOT NULL"; // Disable NSFW Filter
} else {
$NSFW = "nsfw=0"; // Enable NSFW Filter
}
$SECTION = "section=" . $this->currentSection;
if ($SEARCH != "") {
$NAME_SEARCH = "name LIKE '%" . $SEARCH . "%'";
$CREATOR_SEARCH = "creator LIKE '%" . $SEARCH . "%'";
$SPECIES_SEARCH = "species LIKE '%" . $SEARCH . "%'";
$SPECIES_TYPE = "";
} else {
$NAME_SEARCH = "name IS NOT NULL";
$CREATOR_SEARCH = "creator IS NOT NULL";
$SPECIES_SEARCH = "species IS NOT NULL";
$SPECIES_TYPE = "species";
}
if (isset($_GET["t"])) {
$TYPE = "AND species LIKE \"%" . $this->current_species . "%\"";
} else {
$TYPE = "";
}
$sql = "SELECT * from content WHERE
" . $PRICE . " AND " . $NAME_SEARCH . " AND " . $SECTION . " " . $TYPE . " AND " . $NSFW . "
OR " . $PRICE . " AND " . $CREATOR_SEARCH . " AND " . $SECTION . " " . $TYPE . " AND " . $NSFW . "
OR " . $PRICE . " AND " . $SPECIES_SEARCH . " AND " . $SECTION . " " . $TYPE . " AND " . $NSFW . "
" . $ORDER . " " . $LIMIT . ";";
$return = $this->setQuery($sql);
$this->PageContent = $return;
return $return;
}
function dataGetWishlist() {
if (isset($_SESSION["uuid"])) {
$wishArray = json_decode($this->setQuery("SELECT * FROM wishlist_uuid WHERE uuid=\"" . $_SESSION["uuid"] . "\"")[0]["array"]);
} else $wishArray = null;
$descWishArray = array();
$returnArray = array();
if ($wishArray != null) {
for($x = 0; $x < count($wishArray); $x++) {
$descWishArray[] = $wishArray[count($wishArray) - 1 - $x];
}
} else {
return null;
}
if ($descWishArray != null) {
foreach ($descWishArray as $wish) {
$returnArray[] = $this->setQuery("SELECT * FROM content WHERE id=\"" . $wish . "\"")[0];
}
}
return $returnArray;
}
// Print Footer
function footerBackArrow() {
$tmp = "";
$hrefbuilder = "?p=" . ($this->lastpage - 1);
if (isset($_GET["t"]) && $_GET["t"] != "") $hrefbuilder .= "&t=" . $this->current_speciesShort . "";
if (isset($_GET["s"]) && $_GET["s"] != "") $hrefbuilder .= "&s=" . $_GET["s"];
if (isset($_GET["sort"]) && $_GET["sort"] != "") $hrefbuilder .= "&sort=" . $_GET["sort"];
if (isset($_GET["p"]) && $this->lastpage != 1) {
$tmp = "‹";
}
return $tmp;
}
function footerForwardArrow() {
$tmp = "";
$hrefbuilder = "?p=" . ($this->lastpage + 1);
if (isset($_GET["t"]) && $_GET["t"] != "") $hrefbuilder .= "&t=" . $this->current_speciesShort . "";
if (isset($_GET["s"]) && $_GET["s"] != "") $hrefbuilder .= "&s=" . $_GET["s"];
if (isset($_GET["sort"]) && $_GET["sort"] != "") $hrefbuilder .= "&sort=" . $_GET["sort"];
if ($this->lastpage != $this->totalpages && $this->totalpages != 0) {
$tmp = "›";
}
return $tmp;
}
function footerBackDots() {
$tmp = "";
$hrefbuilder = "?p=1";
if (isset($_GET["t"]) && $_GET["t"] != "") $hrefbuilder .= "&t=" . $this->current_speciesShort . "";
if (isset($_GET["s"]) && $_GET["s"] != "") $hrefbuilder .= "&s=" . $_GET["s"];
if (isset($_GET["sort"]) && $_GET["sort"] != "") $hrefbuilder .= "&sort=" . $_GET["sort"];
if (1 != $this->lastpage && 1 < $this->lastpage && 1 < $this->lastpage + 1 && 2 != $this->lastpage) {
$tmp = "1";
if (3 != $this->lastpage) {
$tmp = $tmp . "…";
}
}
return $tmp;
}
function footerForwardDots() {
$tmp = "";
$hrefbuilder = "?p=" . $this->totalpages;
if (isset($_GET["t"]) && $_GET["t"] != "") $hrefbuilder .= "&t=" . $this->current_speciesShort . "";
if (isset($_GET["s"]) && $_GET["s"] != "") $hrefbuilder .= "&s=" . $_GET["s"];
if (isset($_GET["sort"]) && $_GET["sort"] != "") $hrefbuilder .= "&sort=" . $_GET["sort"];
if ($this->totalpages != $this->lastpage && $this->totalpages > $this->lastpage && $this->totalpages > $this->lastpage + 1) {
if ($this->totalpages - 1 > $this->lastpage + 1) {
$tmp = $tmp . "…";
}
$tmp = $tmp . "" . $this->totalpages . "";
}
return $tmp;
}
function footerPages() {
$tmp = " ";
for ($x = 0; $x < $this->totalpages; $x++) {
if ($_GET["p"] == $x + 1) {
$temp = "style=\"color: white;\"";
} else {
$temp = "";
}
$hrefbuilder = "?p=" . ($x + 1);
if (isset($_GET["t"]) && $_GET["t"] != "") $hrefbuilder .= "&t=" . $this->current_speciesShort . "";
if (isset($_GET["s"]) && $_GET["s"] != "") $hrefbuilder .= "&s=" . $_GET["s"];
if (isset($_GET["sort"]) && $_GET["sort"] != "") $hrefbuilder .= "&sort=" . $_GET["sort"];
if ($x + 1 == $_GET["p"] - 1 || $x + 1 == $_GET["p"] || $x + 1 == $_GET["p"] + 1) {
$tmp = $tmp . "" . ($x + 1) . "";
}
}
return $tmp;
}
}