blog eingefügt

This commit is contained in:
klaas 2025-01-15 20:02:23 +01:00
parent 614b597470
commit 37019416b2
41 changed files with 1639 additions and 1 deletions

BIN
blog/.DS_Store vendored Executable file

Binary file not shown.

BIN
blog/._.DS_Store Executable file

Binary file not shown.

35
blog/autoload.php Executable file
View File

@ -0,0 +1,35 @@
<?php
/**
* @param string $class The fully-qualified class name.
* @return void
*/
spl_autoload_register(function ($class) {
// project-specific namespace prefix
$prefix = 'App\\';
// base directory for the namespace prefix
$base_dir = __DIR__ . '/src/';
// does the class use the namespace prefix?
$len = strlen($prefix);
if (strncmp($prefix, $class, $len) !== 0) {
// no, move to the next registered autoloader
return;
}
// get the relative class name
$relative_class = substr($class, $len);
// replace the namespace prefix with the base directory, replace namespace
// separators with directory separators in the relative class name, append
// with .php
$file = $base_dir . str_replace('\\', '/', $relative_class) . '.php';
// if the file exists, require it
if (file_exists($file)) {
require $file;
}
});

35
blog/init.php Executable file
View File

@ -0,0 +1,35 @@
<?php
require __DIR__ . "/autoload.php";
function e($str)
{
return htmlentities($str, ENT_QUOTES, 'UTF-8');
}
$container = new App\Core\Container();
// return GET['index'], set SESION['index'], OR return default
function getPostAndSetSession($index, $session, $default){
if ((isset($_POST[$index])) || !empty($_SESSION[$index])){
$_SESSION[$session] = $_POST[$index];
} else {
if (!isset($_SESSION[$session])){
$_SESSION[$session] = $default;
}
}
return $_SESSION[$session];
}
// return GET['index'], set SESION['index'], OR return default
function getAndSetSession($index, $session, $default){
if ((isset($_GET[$index])) || !empty($_GET[$index])){
$_SESSION[$session] = $_GET[$index];
} else {
if (!isset($_SESSION[$session])){
$_SESSION[$session] = $default;
}
}
return $_SESSION[$session];
}
?>

71
blog/public/index.php Executable file
View File

@ -0,0 +1,71 @@
<?php
session_start();
require __DIR__ . "/../init.php";
$pathInfo = $_SERVER['PATH_INFO'];
//var_dump($pathInfo);die();
$routes = [
'/login' => [
'controller' => 'loginController',
'method' => 'login'
],
'/logout' => [
'controller' => 'loginController',
'method' => 'logout'
],
'/homepages' => [
'controller' => 'loginController',
'method' => 'homepages' // show Methode anwenden
],
'/index' => [
'controller' => 'postsController',
'method' => 'index'
],
'/index_c' => [
'controller' => 'postsController',
'method' => 'index_c'
],
'/dashboard' => [
'controller' => 'loginController',
'method' => 'dashboard'
],
'/post' => [
'controller' => 'postsController',
'method' => 'comment' //'show' //'comments'
],
'/post_c' => [
'controller' => 'postsController',
'method' => 'show' //'show' //'comments'
],
'/posts-admin' => [
'controller' => 'postsAdminController',
'method' => 'index'
],
'/posts-admin_c' => [
'controller' => 'postsAdminController',
'method' => 'post_c' //'method' => 'index_c'
],
'/posts-edit' => [
'controller' => 'postsAdminController',
'method' => 'edit'
],
'/posts-edit_c' => [
'controller' => 'postsAdminController',
'method' => 'edit_c'
],
'/impressum' => [
'controller' => 'loginController',
'method' => 'impressum' // index Methode anwenden
],
];
//var_dump($routes[$pathInfo]); die();
if (isset($routes[$pathInfo])) {
$route = $routes[$pathInfo];
$controller = $container->make($route['controller']);
$method = $route['method'];
//echo "method: ".$method." - ";
//var_dump($controller); die();
$controller->$method();
}
?>

22
blog/src/Blog/Post.php Executable file
View File

@ -0,0 +1,22 @@
<?php
namespace App\Blog;
// ermöglicht das Laden aus einer anderen namespace
use App\User\User as SomeUser;
class Post implements PostInterface
{
public $title;
public $user;
public function __construct()
{
// $this->user = new App\User\User();
// durch use User\User; kann einfach geschrieben werden
// $this->user = new User();
// durch use User\User as SomeUser kann eine neuer user aus der class User/user gebildet werden
$this->user = new SomeUser();
}
}
?>

10
blog/src/Blog/Postinterface.php Executable file
View File

@ -0,0 +1,10 @@
<?php
// Die verwendung vom namespace erlaubt die Verwendung
// des selben class name in verschiedenen class definitions
namespace App\Blog;
interface Postinterface
{
}
?>

View File

@ -0,0 +1,14 @@
<?php
namespace App\Core;
abstract class AbstractController
{
protected function render($view, $params)
{
extract($params);
include __DIR__ . "/../../views/{$view}.php";
}
}
?>

26
blog/src/Core/AbstractModel.php Executable file
View File

@ -0,0 +1,26 @@
<?php
namespace App\Core;
use ArrayAccess;
abstract class AbstractModel implements ArrayAccess
{
public function offsetExists ($offset) {
return isset($this->$offset);
}
public function offsetGet ($offset) {
return $this->$offset;
}
public function offsetSet ($offset, $value) {
$this->$offset = $value;
}
public function offsetUnset ($offset) {
unset ($this->$offset);
}
}
?>

View File

@ -0,0 +1,34 @@
<?php
namespace App\Core;
use PDO;
abstract class AbstractRepository{
protected $pdo;
public function __construct(PDO $pdo){
$this->pdo = $pdo;
}
abstract public function getTableName();
abstract public function getModelName();
function all(){
$table = $this->getTableName();
$model = $this->getModelName();
$stmt = $this->pdo->query("SELECT * FROM `$table`");
$posts = $stmt->fetchAll(PDO::FETCH_CLASS, $model);
return $posts;
}
function find($id){
$table = $this->getTableName();
$model = $this->getModelName();
$stmt = $this->pdo->prepare("SELECT * FROM `$table` WHERE id = :id");
$stmt->execute(['id' => $id]);
$stmt->setFetchMode(PDO::FETCH_CLASS, $model);
$post = $stmt->fetch(PDO::FETCH_CLASS);
return $post;
}
}
?>

89
blog/src/Core/Container.php Executable file
View File

@ -0,0 +1,89 @@
<?php
namespace App\Core;
use PDO;
use Exception;
use PDOException;
use App\Post\PostsRepository;
use App\Post\CommentsRepository;
use App\Post\PostsController;
use App\Post\PostsAdminController;
use App\User\UsersRepository;
use App\User\LoginController;
use App\User\LoginService;
class Container
{
private $receipts = [];
private $instances = [];
public function __construct()
{
$this->receipts = [
'postsAdminController' => function() {
return new PostsAdminController(
$this->make("postsRepository"),
$this->make("commentsRepository"),
$this->make("loginService")
);
},
'loginService' => function() {
return new LoginService(
$this->make("usersRepository")
);
},
'loginController' => function() {
return new LoginController(
$this->make("loginService")
);
},
'postsController' => function() {
return new PostsController(
$this->make('postsRepository'),
$this->make('commentsRepository')
);
},
'postsRepository' => function() {
return new PostsRepository(
$this->make("pdo")
);
},
'usersRepository' => function() {
return new UsersRepository(
$this->make("pdo")
);
},
'commentsRepository' => function() {
return new CommentsRepository(
$this->make("pdo")
);
},
'pdo' => function() {
$servername = "mysqle8e6.netcup.net";
$port = "3306";
$username = "k46054_hbc";
$password = "cXZm/E97dKvZy6Cg*";
$dbname="k46054_hbc";
$pdo = new PDO("mysql:host=$servername;dbname=$dbname;port=$port", $username, $password);
$pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
return $pdo;
}
];
}
public function make($name)
{
if (!empty($this->instances[$name]))
{
return $this->instances[$name];
}
if (isset($this->receipts[$name])) {
$this->instances[$name] = $this->receipts[$name]();
}
return $this->instances[$name];
}
}
?>

16
blog/src/Post/CommentModel.php Executable file
View File

@ -0,0 +1,16 @@
<?php
namespace App\Post;
use App\Core\AbstractModel;
class CommentModel extends AbstractModel
{
public $id;
public $content;
public $post_id;
public $original;
}

View File

@ -0,0 +1,73 @@
<?php
namespace App\Post;
use PDO;
use App\Core\AbstractRepository;
//use App\Post\PostAdminController;
class CommentsRepository extends AbstractRepository
{
public function getTableName()
{
return "blog_comments";
}
public function getModelName()
{
return "App\\Post\\CommentModel";
}
public function insertForPost($postId, $content)
{
$table = $this->getTableName();
$stmt = $this->pdo->prepare(
"INSERT INTO `$table` (`content`, `post_id`) VALUES (:content, :postId)"
);
$stmt->execute([
'content' => $content,
'postId' => $postId
]);
}
public function update($postId, $content, $id, $org) {
echo "here";
$table = $this->getTableName();
$model = $this->getModelName();
$stmt = $this->pdo->prepare(
"UPDATE `{$table}` SET `content` = :content, `post_id` = :postId, `original` = :original
WHERE `id` = :id");
$stmt->execute([
'content' => $content,
'postId' => $postId,
'id' => $id,
'original' => $org
]);
}
public function allByPost($id) {
$table = $this->getTableName();
$model = $this->getModelName();
$stmt = $this->pdo->prepare("SELECT * FROM `$table` WHERE post_id = :id");
$stmt->execute(['id' => $id]);
$comments = $stmt->fetchAll(PDO::FETCH_CLASS, $model);
return $comments;
}
public function allCommentsByID($id) {
$table = $this->getTableName();
$model = $this->getModelName();
$stmt = $this->pdo->prepare("SELECT * FROM `$table` WHERE post_id = :id");
$stmt->execute(['id' => $id]);
$comments = $stmt->fetchAll(PDO::FETCH_CLASS, $model);
return $comments;
}
}
?>

17
blog/src/Post/PostModel.php Executable file
View File

@ -0,0 +1,17 @@
<?php
namespace App\Post;
use App\Core\AbstractModel;
class PostModel extends AbstractModel
{
public $id;
public $title;
public $content;
}
?>

View File

@ -0,0 +1,90 @@
<?php
namespace App\Post;
use App\Core\AbstractController;
use App\User\LoginService;
use App\Post\CommentsRepository;
use PDO;
class PostsAdminController extends AbstractController
{
public function __construct(
PostsRepository $postsRepository,
CommentsRepository $commentsRepository,
LoginService $loginService
)
{
$this->postsRepository = $postsRepository;
$this->commentsRepository = $commentsRepository;
$this->loginService = $loginService;
}
public function index() {
$this->loginService->check();
$all = $this->postsRepository->all();
$this->render("post/admin/index", [
'all' => $all
]);
}
public function index_c() {
$this->loginService->check();
$all = $this->postsRepository->all();
// $comments = $this->commentsRepository->allCommentsByID($id); //allByPost($id);
$this->render("post/admin/index_c", [
'all' => $all,
// 'comments' => $comments
]);
}
public function getComment($id) {
$post = $this->postsRepository->find($id);
$comments = $this->commentsRepository->allByPost($id);
return $comments;
}
public function edit_c() {
$id = getAndSetSession('id', 'id', '1');
$this->loginService->check();
$savedSuccess = false;
if (!empty($_POST['id']) AND !empty($_POST['content'])) {
$content = $_POST['content'];
$postId = $_POST['post_id'];
$p_id = $_POST['id'];
$org = $_POST['original'];
$this->commentsRepository->update($postId, $content, $p_id, $org);
$savedSuccess = true;
}
$post = $this->postsRepository->find($id);
$comments = $this->commentsRepository->allCommentsByID($id);
$this->render("post/admin/edit_c", [
'comments' => $comments,
'post' => $post,
'savedSuccess' => $savedSuccess
]);
}
public function edit() {
$this->loginService->check();
$id = $_GET['id'];
$entry = $this->postsRepository->find($id);
$savedSuccess = false;
if (!empty($_POST['title']) AND !empty($_POST['content'])) {
$entry->title = $_POST['title'];
$entry->content = $_POST['content'];
$this->postsRepository->update($entry);
$savedSuccess = true;
}
$this->render("post/admin/edit", [
'entry' => $entry,
'savedSuccess' => $savedSuccess
]);
}
}
?>

View File

@ -0,0 +1,83 @@
<?php
namespace App\Post;
use App\Core\AbstractController;
class PostsController extends AbstractController
{
public function __construct(
PostsRepository $postsRepository,
CommentsRepository $commentsRepository
)
{
$this->postsRepository = $postsRepository;
$this->commentsRepository = $commentsRepository;
}
public function index()
{
$posts = $this->postsRepository->all();
$this->render("post/index", [
'posts' => $posts
]);
}
public function index_c()
{
$post = $this->postsRepository->all(); //find($id);
$comments = $this->commentsRepository->allByPost($id);
$this->render("post/show", [
'post' => $post,
'comments' => $comments
]);
}
public function comment()
{
$id = $_GET['id'];
if (isset($_POST['content'])) {
$content = $_POST['content'];
//$this->commentsRepository->insertForPost($id, $content);
}
$post = $this->postsRepository->find($id);
$comments = $this->commentsRepository->allByPost($id);
//$this->render("post/show", [
$this->render("post/comment", [
'post' => $post,
'comments' => $comments
]);
}
public function show()
{
$id = $_GET['id'];
echo "ID= ".$id;
//die();
if (isset($_POST['content'])) {
$content = $_POST['content'];
var_dump($content);
//$this->commentsRepository->insertForPost($id, $content);
}
$post = $this->postsRepository->find($id);
$comments = $this->commentsRepository->allByPost($id);
//die();
//$this->render("post/show", [
$this->render("post/show", [
'post' => $post,
'comments' => $comments
]);
}
public function getComment($id)
{
$post = $this->postsRepository->find($id);
$comments = $this->commentsRepository->allByPost($id);
return $comments;
}
}
?>

View File

@ -0,0 +1,32 @@
<?php
namespace App\Post;
use App\Core\AbstractRepository;
class PostsRepository extends AbstractRepository
{
public function getTableName()
{
return "blog_posts";
}
public function getModelName()
{
return "App\\Post\\PostModel";
}
public function update(PostModel $model)
{
$table = $this->getTableName();
$stmt = $this->pdo->prepare("UPDATE `{$table}` SET `content` = :content, `title` = :title WHERE `id` = :id");
$stmt->execute([
'content' => $model->content,
'title' => $model->title,
'id' => $model->id
]);
}
}
?>

View File

@ -0,0 +1,50 @@
<?php
namespace App\User;
use App\Core\AbstractController;
class LoginController extends AbstractController
{
public function __construct(LoginService $loginService){
$this->loginService = $loginService;
}
public function dashboard(){
$this->loginService->check();
$this->render("user/dashboard", []);
}
public function impressum(){
$this->render("user/impressum", []);
}
public function homepages(){
$this->render("user/homepages", []);
}
public function logout(){
$this->loginService->logout();
header("Location: login");
}
public function login(){
$error = false;
if (!empty($_POST['username']) AND !empty($_POST['password'])) {
$username = $_POST['username'];
$password = $_POST['password'];
if ($this->loginService->attempt($username, $password)) {
header("Location: dashboard");
return;
} else {
$error = true;
}
}
$this->render("user/login", [
'error' => $error
]);
}
}
?>

45
blog/src/User/LoginService.php Executable file
View File

@ -0,0 +1,45 @@
<?php
namespace App\User;
class LoginService
{
public function __construct(UsersRepository $usersRepository)
{
$this->usersRepository = $usersRepository;
}
public function check() {
if (isset($_SESSION['login'])) {
return true;
} else {
header("Location: login");
die();
}
}
public function attempt($username, $password) {
$user = $this->usersRepository->findByUsername($username);
if (empty($user)) {
return false;
}
if (password_verify($password, $user->password)) {
$_SESSION['login'] = $user->username;
$_SESSION['rechte'] = $user->rechte;
session_regenerate_id(true);
//var_dump($_SESSION); die();
return true;
} else {
return false;
}
}
public function logout()
{
unset($_SESSION['login']);
unset($_SESSION['rechte']);
session_regenerate_id(true);
}
}
?>

13
blog/src/User/UserModel.php Executable file
View File

@ -0,0 +1,13 @@
<?php
namespace App\User;
use App\Core\AbstractModel;
class UserModel extends AbstractModel
{
public $id;
public $username;
public $password;
}
?>

View File

@ -0,0 +1,33 @@
<?php
namespace App\User;
use App\Core\AbstractRepository;
use PDO;
class UsersRepository extends AbstractRepository
{
public function getModelName()
{
return "App\\User\\UserModel";
}
public function getTableName()
{
return "users";
}
public function findByUsername($username)
{
$table = $this->getTableName();
$model = $this->getModelName();
$stmt = $this->pdo->prepare("SELECT * FROM `$table` WHERE username = :username");
$stmt->execute(['username' => $username]);
$stmt->setFetchMode(PDO::FETCH_CLASS, $model);
$user = $stmt->fetch(PDO::FETCH_CLASS);
return $user;
}
}
?>

52
blog/views/layout/css/navi.css Executable file
View File

@ -0,0 +1,52 @@
<style>
#navbar #currentpage a {
background-color: black;
color: white;
font-weight: bold;
}
.catcher {
position: relative;
text-align: center;
color: white;
}
.bottom-left {
position: absolute;
bottom: 8px;
left: 16px;
}
.top-left {
position: absolute;
top: 8px;
left: 16px;
}
.top-right {
position: absolute;
top: 8px;
right: 16px;
}
.bottom-right {
position: absolute;
bottom: 8px;
right: 16px;
}
.bottom-centered {
position: absolute;
bottom: 30px;
left: 50%;
transform: translate(-50%, -50%);
}
.centered {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
</style>

10
blog/views/layout/footer.php Executable file
View File

@ -0,0 +1,10 @@
</div>
<DIV class="footer" style="background-color: #333; color:grey">
<hr><p><?php echo $thissheet;?></p>
</DIV>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>
</body>
</html>

13
blog/views/layout/header.php Executable file
View File

@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css"
integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7"
crossorigin="anonymous">
<link href='open-sans.css' rel='stylesheet' type='text/css'>
<link rel="icon" href="../../../logo_mini.png" type="image/png"/>
</head>

View File

@ -0,0 +1,47 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>harald börgmann website</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css">
<!--link href="https://fonts.googleapis.com/css?family=Open+Sans:400,600,300" rel="stylesheet" type="text/css"-->
<link href='open-sans.css' rel='stylesheet' type='text/css'>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/js/bootstrap.min.js"></script>
<link rel="icon" href="/../../../logo_mini.png" type="image/png"/>
</head>
<body>
<nav class="navbar navbar-inverse navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button><?php
if ($thisPage=="start") {
echo "<a class=\"navbar-brand\" style=\"background-color:black;
color:white; font-weight:bold\" href=\"index\">Website</a>";
} else {
echo "<a class=\"navbar-brand\" href=\"index\">Website</a>";
} ?>
</div>
<div id="navbar" class="collapse navbar-collapse">
<ul class="nav navbar-nav" style="float:right">
<li<?php if ($thisPage=="impressum"){
echo " id=\"currentpage\""; }?>>
<a href="impressum">Impressum</a></li>
</ul>
</div><!--/.nav-collapse -->
</div>
</nav>
<br>
<br>

View File

@ -0,0 +1,49 @@
<nav class="navbar navbar-inverse navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="homepages">Website</a>
</div>
<div id="navbar" class="collapse navbar-collapse">
<ul class="nav navbar-nav">
<li <?php if ($thisPage=="blog")
{echo " id=\"currentpage\""; }?> >
<a href="index">Blog</a></li>
</ul>
<ul class="nav navbar-nav">
<li <?php if ($thisPage=="login") {
echo " id=\"currentpage\""; }?> >
<a href="login">Login</a>
</li>
</ul><?php
if (isset($_SESSION['rechte'])){ // admin rechte
if ($_SESSION['rechte'] == "admin") { ?>
<ul class="nav navbar-nav">
<li <?php if ($thisPage=="admin") {
echo " id=\"currentpage\""; } ?> >
<a href="posts-admin">Admin</a>
</li>
</ul><?php
}
} ?>
<ul class="nav navbar-nav" style="float:right">
<li>
<a href="impressum">Impressum</a>
</li>
</ul>
</div><!--/.nav-collapse -->
</div>
</nav>
<br />
<br />
<br />

55
blog/views/post/admin/edit.php Executable file
View File

@ -0,0 +1,55 @@
<?php
$thisPage="admin";
$thissheet = "/admin/edit";
require __DIR__ . "/../../layout/header.php";
include __DIR__ . "./../../../views/layout/css/navi.css";
require __DIR__ . "/../../layout/navigation.php";
//echo "edit: "; var_dump($entry);
?>
<br /> <br />
<div class="container">
<div class="starter-template">
<h3>Edit - Post editieren!</h3><?php
if(!empty($savedSuccess)): ?>
<p>Die Korrektur wurde erfolgreich gespeichert</p><?php
else: ?>
<p> &nbsp; </p> <?php
endif;
// Kommentar Titel anzeigen ?>
<div class="panel panel-default">
<div class="panel-heading">
<h1 class="panel-title"><?php echo e($entry->title); ?></h1>
</div>
</div><?php
// Kommentarfelder anzeigen?>
<form method="POST" action="posts-edit?id=<?php echo e($entry->id); ?>" class="form-horizontal">
<div class="form-group">
<label class="control-label col-md-3">
Titel:
</label>
<div class="col-md-9">
<input type="text" name="title" value="<?php echo e($entry->title); ?>" class="form-control" />
</div>
</div>
<div class="form-group">
<label class="control-label col-md-3">
Inhalt:
</label>
<div class="col-md-9">
<textarea name="content" class="form-control" rows="10"><?php echo e($entry->content); ?></textarea>
</div>
</div><?php
// Speichern?>
<input type="submit" value="Post (Korrektur) speichern!" class="btn btn-primary" />
</form>
<br><?php
// Ohne Speichern zurück ?>
<div class="w3-container">
<a href="posts-admin" class="w3-btn w3-red">zurück</a>
</div>
</div>
</div>
<?php include __DIR__ . "/../../layout/footer.php"; ?>

116
blog/views/post/admin/edit_c.php Executable file
View File

@ -0,0 +1,116 @@
<?php
$thisPage="admin";
$thissheet = "/admin/edit_c";
require(__DIR__ . "/../../layout/header.php");
include __DIR__ . "./../../../views/layout/css/navi.css";
require __DIR__ . "/../../layout/navigation.php";
$c_id = getAndSetSession('c_id', 'c_id', '1'); ?>
<div class="container">
<div class="starter-template">
<h3>Kommentare editieren</h3><?php
if(!empty($savedSuccess)): ?>
<p>Der Kommentar wurde erfolgreich gespeichert</p><?php
endif; ?>
<h3> <?php echo "Post ".e($post->id).": ".e($post->title); ?></h3>
<h4> <?php echo "Content: ".e($post->content); ?></h4>
<!-- ***************************** Beginn commente *****************************-->
<div>
<table>
<tr style="font-weight: bold; background-color:lightgrey">
</tr><?php
$anzahl = count($comments); // Anzahl
$com = array();
$comment = array();
if ($anzahl != 0) { // Anzahl > 0 dann
foreach ($comments as $mem){ //($commente as $mem) {
$comment = [
'post_id' => $mem->post_id, // id des posts
'id' => $mem->id, // id des Kommentars
'content' => $mem->content,
'original' => $mem->original
];
$com[] = $comment;
}
}
$id_o_no = 0; // Zähler für array
$tr0 = "<tr style=\"background-color:lightcyan;\">"; ?>
<hr>
</div>
</div>
</div>
<div><?php
$anz = count($com);
if ($c_id >= $anz ) {$c_id = 0;}
$action = 1; ?>
<form method="post">
<p><b>content</b></p>
<p><textarea autofocus id="content" name="content" cols="150" rows="4" > <?php echo $com["$c_id"]['content'];?>
</textarea></p>
<table style="width:600px">
<tr>
<td><input style="background-color:yellow;" type="submit" name="submit"
value="<?php if (count($com)!=0) {echo "update";}else {echo "update not possible";} ?>"
placeholder="update" size="20%"/></td>
<td><input type="text" name="post_id" id="post_id" hidden="true"
value="<?php echo $com["$c_id"]["post_id"];?>" placeholder="post_id" size="5%" readonly />&nbsp;</td>
<td><input type="text" name="id" id="id" hidden="true"
value="<?php echo $com["$c_id"]["id"];?>" size="5%" readonly >&nbsp;</td>
<td><input style="text-align: center; background-color:lightyellow width:3%" type="text" name="original" id="original"
value="<?php if (count($com) != 0) {
echo $com["$c_id"]["original"];}?>" placeholder="erl" size="5%" />
&nbsp;veränderter Text: > 0 </td>
<td style=size:"40%" >&nbsp; </td>
</tr>
</table>
</form>
</br>
<table style="width:100%">
<tr>
<td colspan="5"><?php echo "Anzahl Kommentare: " .$anzahl; ?>
</td>
</tr>
<tr style="font-weight:bold; background-color:lightgrey">
<td>s &nbsp;</td><td>&nbsp;post&nbsp;</td><td>&nbsp;id&nbsp;</td><td>&nbsp;Kommentar&nbsp;</td>
<td>&nbsp;original</td>
</tr>
<form name="c_id" action="posts-edit_c" id="c_id" method="get"><?php
$id_no = 0; // Zähler für array
foreach ($com AS $key => $issue) {
echo $tr0; ?>
<td><input type="radio" name="c_id" id="c_id" value="<?php echo $id_no;?>"<?php
if ($c_id == $id_no) { echo "checked=checked";} ?> onchange="submit()" /></td><?php
$id_no = $id_no + 1;
foreach ($issue AS $key1 => $data) {
echo "<td>&nbsp;".$data."&nbsp;</td>";
}
echo "</tr>";
} ?>
</form>
</table>
</div>
</br>
<div class="w3-container">
<a href="posts-admin" class="w3-btn w3-red">zurück</a>
</div>
<?php include (__DIR__ . "/../../layout/footer.php"); ?>

38
blog/views/post/admin/index.php Executable file
View File

@ -0,0 +1,38 @@
<?php
$thisPage="admin";
$thissheet = "/admin/index";
require(__DIR__ . "/../../layout/header.php");
include __DIR__ . "./../../../views/layout/css/navi.css";
require __DIR__ . "/../../layout/navigation.php";
?>
<div class="container">
<div class="starter-template">
<h3>Posts verwalten (posts-admin)</h3>
<h4>Posts editieren (posts-edit)</h4>
<ul><?php
foreach ($all AS $entry): ?>
<li>
<a href="posts-edit?id=<?php echo e($entry->id); ?>">
<?php echo e($entry->title); ?>
</a>
</li> <?php
endforeach; ?>
</ul>
<h4>Kommentare editieren (posts-edit_c)</h4>
<ul><?php
foreach ($all AS $a): ?>
<li>
<a href="posts-edit_c?id=<?php echo e($a->id); ?>">
<?php echo e($a->title)."<br></a>";
echo " -> ".e($a->content);?>
</li> <?php
endforeach; ?>
</ul>
</div>
</div>
<?php include (__DIR__ . "./../../layout/footer.php"); ?>

View File

@ -0,0 +1,52 @@
<?php
$thisPage="admin";
$thissheet = "/admin/index_c";
require(__DIR__ . "/../../layout/header.php");
include __DIR__ . "./../../../views/layout/css/navi.css";
require __DIR__ . "/../../layout/navigation.php";
var_dump($all);
echo "<br>";
var_dump($comment);
//die();
?>
<br /> <br />
<div class="container">
<div class="starter-template">
<h3>Posts editieren ?</h3>
<ul>
<?php foreach ($all AS $entry): ?>
<li>
<a href="posts-edit?id=<?php echo e($entry->id); ?>">
<?php echo e($entry->title); ?>
</a>
</li>
<?php endforeach; ?>
</ul>
<ul>
<?php foreach ($all AS $entry): ?>
<li>
<a href="admin_c?id=<?php echo e($entry->id); ?>">
<?php echo e($entry->content); ?>
</a>
</li>
<?php endforeach; ?>
</ul>
<h3>Kommentare editieren</h3>
<ul class="list-group"><?php
$i = 1;
foreach($comments AS $comment): ?>
<li class="list-group-item"><?php
echo $i.". ".e($comment->content);
$i++;?>
</li>
<?php endforeach; ?>
</ul>
</div>
</div>
<?php include __DIR__ . "/../../layout/footer.php"; ?>

View File

@ -0,0 +1,46 @@
<?php
$thisPage="admin";
$thissheet = "/admin/verwalten";
require(__DIR__ . "/../../layout/header.php");
include __DIR__ . "./../../../views/layout/css/navi.css";
require __DIR__ . "/../../layout/navigation.php";
foreach ($all as $a) {
echo "<br>";var_dump($a);
}
echo "<br>";
//var_dump($entry);
?>
<div class="container">
<div class="starter-template">
<h3>Posts verwalten (posts-admin)</h3>
<h4>Posts editieren (posts-edit)</h4>
<ul>
<?php foreach ($all AS $entry): ?>
<li>
<a href="posts-edit?id=<?php echo e($entry->id); ?>">
<?php echo e($entry->title); ?>
</a>
</li>
<?php endforeach; ?>
</ul>
<h4>Kommentare editieren (posts-edit_c)</h4>
<ul>
<?php foreach ($all AS $entry): ?>
<li>
<a href="posts-edit_c?id=<?php echo e($entry->id); ?>">
<?php echo e($entry->title); ?>
</a><?php
echo "<br>".$entry->content."<br>"; ?>
</li>
<?php endforeach; ?>
</ul>
</div>
</div>
<?php require(__DIR__ . "/../../layout/footer.php"); ?>

50
blog/views/post/comment.php Executable file
View File

@ -0,0 +1,50 @@
<?php
$thisPage="blog";
$thissheet = "comment";
require(__DIR__ . "/../layout/header.php");
include __DIR__ . "./../../views/layout/css/navi.css";
require __DIR__ . "/../layout/navigation.php"; ?>
<div class="container">
<div class="starter-template">
<h3>Kommentar zum Post zufügen:</h3><?php
// Topic aus posts ?>
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title"><?php echo "Post: ".e($post['title']); ?></h3>
</div>
</div><?php
// Thema des posts?>
<div class="panel-body">
<?php echo "<b>Inhalt: ".nl2br(e($post['content']))."</b>";?>
</div><?php
// Kommentare dazu auflisten ?>
<ul class="list-group"><?php
$i = 1;
foreach($comments AS $comment):?>
<li class="list-group-item"><?php
echo $i.". "
//echo "<br>ID=".$comment->id. " -> "
.$comment->content;
$i++; ?>
</li>
<?php endforeach; ?>
</ul><?php
// weiteres Kommentar Feld hinzufügen ?>
<form method="post" action="post?id=<?php echo e($post['id']);?>">
<textarea name="content" class="form-control"></textarea>
</br>
<input type="submit" value="Kommentar hinzufügen" class="btn btn-primary"/>
</form>
</br>
</br>
</div>
<div class="w3-container">
<a href="index" class="w3-btn w3-red">zurück</a>
</div>
</div>
<?php
include __DIR__ . "/../layout/footer.php";
?>

31
blog/views/post/index.php Executable file
View File

@ -0,0 +1,31 @@
<?php
$thisPage="blog";
$thissheet = "/index";
include __DIR__ . "/../layout/header.php";
include __DIR__ . "./../../views/layout/css/navi.css";
include __DIR__ . "/../layout/navigation.php";
//unset($_SESSION['login']);
?>
<div class="container">
<div class="starter-template">
<h1>Haralds Blog</h1>
<p class="lead">In diesem Blog können Sie Kommentare zur Gestaltung meiner Seite abgeben oder </br>
ergänzende Informationen zu Personen eintragen sowie fehlerhafte Daten kommentieren.</p>
<ul>
<?php foreach ($posts as $post): ?>
<li>
<a href="post?id=<?php echo e($post['id']); ?>">
<?php echo e($post['title']); ?>
</a>
</li>
<?php endforeach;?>
</ul>
</div>
</div>
<?php
include __DIR__ . "/../layout/footer.php";
?>

41
blog/views/post/index_admin.php Executable file
View File

@ -0,0 +1,41 @@
<?php
$thisPage="blog";
$thissheet = "index_admin";
include __DIR__ . "/../layout/header.php";
include __DIR__ . "./../../views/layout/css/navi.css";
include __DIR__ . "/../layout/navigation.php";
//unset($_SESSION['login']);
?>
<div class="container">
<div class="starter-template">
<h1>Haralds Blog</h1>
<p class="lead">In diesem Blog können Sie Kommentare zur Gestaltung meiner Seite abgeben oder </br>
ergänzende Informationen zu Personen eintragen sowie fehlerhafte Daten kommentieren.</p>
<ul>
<?php foreach ($posts as $post): ?>
<li>
<a href="post?id=<?php echo e($post['id']); ?>">
<?php echo e($post['title']); ?>
</a>
</li>
<?php endforeach;?>
</ul>
<ul>
<?php foreach ($all AS $entry): ?>
<li>
<a href="posts-edit_c?id=<?php echo e($entry->id); ?>">
<?php echo e($entry->title); ?>
</a>
</li>
<?php endforeach; ?>
</ul>
</div>
</div>
<?php
include __DIR__ . "/../layout/footer.php";
?>

42
blog/views/post/index_c.php Executable file
View File

@ -0,0 +1,42 @@
<?php
$thisPage="blog";
$thissheet = "/index_c";
include __DIR__ . "/../layout/header.php";
include __DIR__ . "./../../views/layout/css/navi.css";
include __DIR__ . "/../layout/navigation.php";
//unset($_SESSION['login']);
?>
<div class="container">
<div class="starter-template">
<h1>Haralds Blog</h1>
<p class="lead">In diesem Blog können Sie Kommentare zur Gestaltung meiner Seite abgeben oder </br>
ergänzende Informationen zu Personen eintragen sowie fehlerhafte Daten kommentieren.</p>
<ul>
<?php foreach ($posts as $post): ?>
<li>
<a href="post?id=<?php echo e($post['id']); ?>">
<?php echo e($post['title']); ?>
</a>
</li>
<?php endforeach;?>
</ul>
<?php/*
<ul>
<?php foreach ($all AS $entry): ?>
<li>
<a href="posts-edit_c?id=<?php echo e($entry->id); ?>">
<?php echo e($entry->title); ?>
</a>
</li>
<?php endforeach; ?>
</ul>
*/?>
</div>
</div>
<?php
include __DIR__ . "/../layout/footer.php";
?>

54
blog/views/post/show.php Executable file
View File

@ -0,0 +1,54 @@
<?php
$thisPage="blog";
$thissheet = "/show";
require(__DIR__ . "/../layout/header.php");
include __DIR__ . "./../../views/layout/css/navi.css";
include __DIR__ . "/../layout/navigation.php";
//unset($_SESSION['login']);
//unset($_SESSION['rechte'])
var_dump($post); echo "<br><br>";
var_dump($comments);
?>
<div class="container">
<div class="starter-template">
<h3>Show - Kommentar zufügen:</h3>
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title"><?php echo e($post['title']); ?></h3>
</div>
</div>
<div class="panel-body">
<?php echo nl2br(e($post['content'])); ?>
</div>
<ul class="list-group"><?php
$i = 1;
foreach($comments AS $comment): ?>
<li class="list-group-item">
<a href="posts-edit_c?id=<?php echo e($comment['id']); ?>"><?php
echo $i.". ".e($comment->content)."</a>";
echo "<br>ID=".e($comment->id). " -> ";
echo "post-ID=".e($comment->post_id). " -> ";
echo "content=".e($comment->content);
$i++;?>
</li>
<?php endforeach; ?>
</ul>
<form method="post" action="post?id=<?php echo e($post['id']);?>">
<textarea name="content" class="form-control"></textarea>
</br>
<input type="submit" value="Kommentar hinzufügen" class="btn btn-primary"/>
</form>
</br>
</br>
</div>
</div>
<?php
include __DIR__ . "/../layout/header.php";
?>

55
blog/views/user/dashboard.php Executable file
View File

@ -0,0 +1,55 @@
<?php
$thisPage="admin";
require(__DIR__ . "/../layout/header.php");
include __DIR__ . "./../../views/layout/css/navi.css";
require __DIR__ . "/../layout/navigation.php";
$melde_0 = "<p style='color:red'><b>Diese Seite ist dem Admin vorbehalten!</b></p>";
$melde_1 = "<p style='color:red'><b>Hier können die posts editiert werden!</b></p>";
?>
<br /> <br />
<div class="container">
<div class="starter-template">
<h3>Posts Dashboard</h3>
<ul><?php
if ((isset($_SESSION['rechte'])) && (!($_SESSION['rechte'] == "admin"))) {
echo $melde_0;?>
<br>
<li>
<a href="index"> Zurück zum Blog (Kommentare) </a>
</li> <br>
<li>
<a href="login">Login (erneuter Login als admin) </a>
</li> <br>
<li>
<a href="homepages">Logout zur Website </a>
</li> <?php
} else {
echo $melde_1;?>
<li>
<a href="posts-admin">Posts verwalten </a>
</li>
<li>
<a href="index">Kommmentar hinzufügen </a>
</li>
<?php
}?>
</ul>
</div>
</div>
<?php
// die();
?>
</br></br><h1>Startseite</h1>
<?php
header("Location: /../../public/index.php/index");
die(); // hier könnte auch eine exeption ausgeführt werden
?>
<?php
include __DIR__ . "/../layout/footer.php";
?>

25
blog/views/user/homepages.php Executable file
View File

@ -0,0 +1,25 @@
<?php
$thisPage="homepages";
include __DIR__ . "/../layout/header.php";
include __DIR__ . "/../layout/navigation.php";
include __DIR__ . "/../layout/css/navi.css";
?>
</br></br><h1>Startseite</h1>
<?php
header("Location: ../../../public/index.php/index");
die(); // hier könnte auch eine exeption ausgeführt werden
?>
<DIV class="footer">
<hr><br>
<p style= "text-align:center;"><a href="impressum">Impressum</a></p>
<br>
</DIV>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"
integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS"
crossorigin="anonymous"></script>
</body>
</html>

26
blog/views/user/impressum.php Executable file
View File

@ -0,0 +1,26 @@
<?php
$thisPage="homepages";
include __DIR__ . "/../layout/header.php";
include __DIR__ . "/../layout/navigation.php";
//include __DIR__ . "/../layout/css/navi.css";
//echo "hier";
//die();
?>
</br></br><h1>Startseite</h1>
<?php
header("Location: ../../../public/index.php/impressum");
die(); // hier könnte auch eine exeption ausgeführt werden
?>
<DIV class="footer">
<hr><br>
<p style= "text-align:center;"><a href="impressum">Impressum</a></p>
<br>
</DIV>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"
integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS"
crossorigin="anonymous"></script>
</body>
</html>

48
blog/views/user/login.php Executable file
View File

@ -0,0 +1,48 @@
<?php
$thisPage="login";
$thissheet = "login";
include __DIR__ . "/../layout/header.php";
include __DIR__ . "./../../views/layout/css/navi.css";
include __DIR__ . "/../layout/navigation.php";
?>
<!--Blog/views/user/login.php-->
<div class="container">
<div class="starter-template">
<h1>Login</h1>
<?php if (!empty($error)): ?>
<p>
<?php echo "Die Kombination aus Benutzername und Passwort ist falsch"; // wird im LoginController gesetzt?>
</p>
<?php endif ?>
<form method="POST" method "login" class="form-horizontal">
<div class="form-group">
<label class="control-label col-md-3">
Benutzername:
</label>
<div class="col-md-9">
<input type="text" name="username" class="form-control" />
</div>
</div>
<div class="form-group">
<label class="control-label col-md-3">
Passwort:
</label>
<div class="col-md-9">
<input type="password" name="password" class="form-control" />
</div>
</div>
<input type="submit" value="Einloggen" class="btn btn-primary" />
</form>
</div>
</div>
<?php
include __DIR__ . "./../layout/footer.php";
?>

View File

@ -1 +1 @@
11 19