Skip to content

Commit

Permalink
Updated
Browse files Browse the repository at this point in the history
  • Loading branch information
pepiuox committed Nov 9, 2023
1 parent f6d7784 commit 4f0528c
Show file tree
Hide file tree
Showing 3 changed files with 156 additions and 12 deletions.
106 changes: 106 additions & 0 deletions config/Routers.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
<?php
class Routers
{
protected $conn;
public $url;
public $host;
public $basename;
public $protocol;
public $escaped_url;
public $url_path;
public $active = 1;
public $parent = 0;
public $pg404;

public function __construct()
{
global $conn;
$this->conn = $conn;

$this->protocol =
(!empty($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] != "off") ||
$_SERVER["SERVER_PORT"] == 443
? "https://"
: "http://";
$this->host = $this->protocol . $_SERVER["HTTP_HOST"] . "/";
$this->pg404 = $this->host . "404.php";
$this->url =
$this->protocol . $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"];
$this->escaped_url = htmlspecialchars($this->url, ENT_QUOTES, "UTF-8");
$this->url_path = parse_url($this->escaped_url, PHP_URL_PATH);
$this->basename = pathinfo($this->url_path, PATHINFO_BASENAME);
}

public function Pages($plink)
{
$pg = $this->conn->prepare(
"SELECT link, parent, active FROM page WHERE link = ? AND active = ? "
);
$pg->bind_param("si", $plink, $this->active);
$pg->execute();
$rs = $pg->get_result();
$pg->close();
if ($rs->num_rows == 1) {
$row = $rs->fetch_assoc();
if ($row["parent"] > 0) {
$link = $this->GetParent($row["parent"]);
return $this->host . $link . "/" . $row["link"];
} else {
return $this->host . $row["link"];
}
} else {
header("Location: $this->pg404");
exit();
}
}

public function GetParent($parent)
{
$pr = $this->conn->prepare(
"SELECT id, link, parent, active FROM page WHERE id = ? AND active = ? "
);
$pr->bind_param("ii", $parent, $this->active);
$pr->execute();
$rp = $pr->get_result();
$pr->close();
$row = $rp->fetch_assoc();
if ($row["parent"] > 0) {
$link = $this->GetSecondParent($row["parent"]);
return $link . "/" . $row["link"];
} else {
return $row["link"];
}
}

public function GetSecondParent($parent)
{
$pr = $this->conn->prepare(
"SELECT id, link, parent, active FROM page WHERE id = ? AND active = ? "
);
$pr->bind_param("ii", $parent, $this->active);
$pr->execute();
$rp = $pr->get_result();
$pr->close();
$row = $rp->fetch_assoc();
if ($row["parent"] > 0) {
$link = $this->GetThirdParent($row["parent"]);
return $link . "/" . $row["link"];
} else {
return $row["link"];
}
}

public function GetThirdParent($parent)
{
$pr = $this->conn->prepare(
"SELECT id, link, parent, active FROM page WHERE id = ? AND active = ? "
);
$pr->bind_param("ii", $parent, $this->active);
$pr->execute();
$rp = $pr->get_result();
$pr->close();
$row = $rp->fetch_assoc();
return $row["link"];
}

}
26 changes: 26 additions & 0 deletions config/dbconnection.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

include 'error_report.php';
include 'Database.php';
$link = new Database();
$conn = $link->MysqliConnection();
require_once 'Routers.php';
require_once 'function.php';
include_once 'define.php';

$protocol =
(!empty($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] != "off") ||
$_SERVER["SERVER_PORT"] == 443
? "https://"
: "http://";

if (!empty(SITE_PATH)) {
$siteinstall = SITE_PATH;
} else {
$base = $protocol . $_SERVER['HTTP_HOST'] . '/';
}
$fname = basename($_SERVER['SCRIPT_FILENAME'], '.php');
$rname = $fname . '.php';
$alertpg = $_SERVER['REQUEST_URI'];
?>

36 changes: 24 additions & 12 deletions elements/view.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,20 @@
require_once 'classes/UserClass.php';
require_once 'classes/GetVisitor.php';

$pages = new Routers();
$login = new UserClass();
$visitor = new GetVisitor();

$_SESSION['language'] = '';
$initweb = 'http://' . $_SERVER['HTTP_HOST'] . '/';
$url = "http://{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}";
$escaped_url = htmlspecialchars($url, ENT_QUOTES, 'UTF-8');
$_SESSION["language"] = "";
$initweb = $protocol . $_SERVER["HTTP_HOST"] . "/";
$pg404 = $initweb . "404.php";
$url = $protocol . $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"];
$escaped_url = htmlspecialchars($url, ENT_QUOTES, "UTF-8");
$url_path = parse_url($escaped_url, PHP_URL_PATH);
$basename = pathinfo($url_path, PATHINFO_BASENAME);
$active = 1;
$startpage = 1;
$nm = '';
$nm = "";

if ($initweb === $url) {
$spg = $conn->prepare("SELECT * FROM page WHERE startpage = ? AND active = ? ");
Expand All @@ -34,22 +36,32 @@
$spg->execute();
$rs = $spg->get_result();
$rpx = $rs->fetch_assoc();
$namelink = $initweb . $rpx['link'];
header("Location: $namelink");
exit();
if ($nm > 0) {
$rpx = $rs->fetch_assoc();
$namelink = $pages->Pages($rpx["link"]);
} else {
header("Location: $namelink");
exit();
}
} elseif (isset($basename) && !empty($basename)) {
$spg = $conn->prepare("SELECT * FROM page WHERE link = ? AND active = ? ");
$npg = $pages->Pages($basename);
if($npg == $url ){
$spg = $conn->prepare(
"SELECT * FROM page WHERE link = ? AND active = ? "
);
$spg->bind_param("si", $basename, $active);
$spg->execute();
$rs = $spg->get_result();
$spg->close();
$nm = $rs->num_rows;

if ($nm > 0) {
$rpx = $rs->fetch_assoc();
} else {
header("Location: $initweb");
}
}else{
header("Location: $npg");
exit();
}
}
}

if ($nm > 0) {
Expand Down

0 comments on commit 4f0528c

Please sign in to comment.