Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
W
Website
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jonas Leder
Website
Commits
f8e37db2
Commit
f8e37db2
authored
3 years ago
by
Jonas Leder
Browse files
Options
Downloads
Patches
Plain Diff
get post from API
parent
5a315093
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
js/script.js
+1
-0
1 addition, 0 deletions
js/script.js
js/viewPost.js
+40
-0
40 additions, 0 deletions
js/viewPost.js
public/API/getPost.php
+24
-0
24 additions, 0 deletions
public/API/getPost.php
public/post.html
+14
-31
14 additions, 31 deletions
public/post.html
with
79 additions
and
31 deletions
js/script.js
+
1
−
0
View file @
f8e37db2
...
@@ -4,6 +4,7 @@ require("./imgPreview");
...
@@ -4,6 +4,7 @@ require("./imgPreview");
require
(
"
./includeHTML
"
);
require
(
"
./includeHTML
"
);
require
(
"
./ntpGraph
"
);
require
(
"
./ntpGraph
"
);
require
(
"
./ntpMenu
"
);
require
(
"
./ntpMenu
"
);
require
(
"
./viewPost
"
);
require
(
"
./customElements/cookie
"
);
require
(
"
./customElements/cookie
"
);
require
(
"
./customElements/svgLoader
"
);
require
(
"
./customElements/svgLoader
"
);
...
...
This diff is collapsed.
Click to expand it.
js/viewPost.js
0 → 100644
+
40
−
0
View file @
f8e37db2
if
(
window
.
location
[
'
pathname
'
]
==
"
/post.html
"
){
loadPost
();
}
function
getParameter
(
key
)
{
// Address of the current window
let
address
=
window
.
location
.
search
// Returns a URLSearchParams object instance
let
parameterList
=
new
URLSearchParams
(
address
)
// Returning the respected value associated
// with the provided key
return
parameterList
.
get
(
key
)
}
async
function
loadPost
()
{
let
id
=
getParameter
(
"
id
"
);
let
header
=
document
.
createElement
(
"
jl-header
"
);
let
footer
=
document
.
createElement
(
"
jl-footer
"
);
let
content
=
document
.
createElement
(
"
div
"
);
if
(
id
==
null
)
{
content
.
innerHTML
=
"
<h1>404 - Post not found</h1>
"
;
}
else
{
let
post
=
await
(
await
fetch
(
"
/API/getPost.php?id=
"
+
id
)).
json
();
content
.
innerHTML
=
post
[
"
content
"
];
document
.
title
=
post
[
"
title
"
]
+
"
- Jonas Leder
"
;
header
.
setAttribute
(
"
data-title
"
,
post
[
"
title
"
]);
}
content
.
id
=
"
content
"
;
document
.
body
.
appendChild
(
header
);
document
.
body
.
appendChild
(
content
);
document
.
body
.
appendChild
(
footer
);
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
public/API/getPost.php
0 → 100644
+
24
−
0
View file @
f8e37db2
<?php
include
"./lib/config.php"
;
include
"./lib/mysql.php"
;
$id
=
$conn
->
real_escape_string
(
$_GET
[
"id"
]);
$result
=
$conn
->
query
(
"SELECT * FROM posts WHERE id=
$id
"
);
if
(
$result
->
num_rows
>
0
)
{
$row
=
$result
->
fetch_assoc
();
}
else
{
die
(
"Post not found"
);
}
$title
=
$row
[
"title"
];
$content
=
$row
[
"content"
];
$date
=
$row
[
"date"
];
$id
=
$row
[
"id"
];
header
(
'Content-Type: application/json'
);
echo
json_encode
([
"title"
=>
$title
,
"content"
=>
$content
,
"date"
=>
$date
,
"id"
=>
$id
]);
\ No newline at end of file
This diff is collapsed.
Click to expand it.
public/post.html
+
14
−
31
View file @
f8e37db2
<?php
include "internal/header.php";
include "internal/footer.php";
if(isset($_GET["template"])){
<!DOCTYPE html >
$title = "[TITLE]";
<html
lang =
"de"
>
$content = "[CONTENT]";
<html
>
$date = "DATE NOT SHOWN IN PREVIEW";
<head
>
$id = "0";
<meta
charset =
"UTF-8"
>
<meta
name =
"viewport"
content =
"width=device-width, initial-scale=1.0"
>
} else{
<title></title
>
$id = $conn->real_escape_string($_GET["id"]);
$result = $conn->query("SELECT * FROM posts WHERE id=$id");
<link
href =
"/css/style.css"
rel =
"stylesheet"
>
if ($result->num_rows > 0) {
</head
>
$row = $result->fetch_assoc();
<body
>
} else {
<script
src=
"/js/script.js"
></script>
die("Post not found");
</body>
}
</html>
\ No newline at end of file
$title = $row["title"];
$content = $row["content"];
$date = $row["date"];
$id = $row["id"];
}
getHeader($title, "");
?>
<p>
<?php echo($content); ?>
</p>
<
?
php
getFooter
();
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment