2018-10-16 16:28:42 +00:00
< ? php
2018-10-23 20:22:22 +00:00
defined ( 'BASEPATH' ) OR exit ( 'No direct script access allowed' );
2018-10-16 16:28:42 +00:00
2018-10-23 20:22:22 +00:00
use Coduo\PHPHumanizer\DateTimeHumanizer ;
2018-10-16 16:28:42 +00:00
2018-10-23 20:22:22 +00:00
class User extends MY_Controller
{
2018-10-16 16:28:42 +00:00
2018-10-23 20:22:22 +00:00
public function __construct ()
{
parent :: __construct ( 'profile' , 'language_names' , 'country_names' );
$this -> load -> model ( 'UserModel' , '' , TRUE );
$this -> load -> model ( 'PostsModel' , '' , TRUE );
$this -> load -> model ( 'FileModel' , '' , TRUE );
}
2018-10-16 16:28:42 +00:00
2018-10-23 20:22:22 +00:00
public function index ( $user = " " )
{
if ( $user == " " ) {
$title = " Error - Profile " ;
$message = [ " type " => " danger " , " message1 " => " Dieser Nutzer existiert nicht! " , " message2 " => " Es wurde kein Nutzername angegeben. " ];
} else {
2018-10-16 16:28:42 +00:00
$user_data = $this -> UserModel -> getUser ( $user );
$user_exists = ! empty ( $user_data );
if ( $user_exists ) {
$user_data = $user_data [ 0 ];
$user_stats = $this -> UserModel -> getUserStats ( $user_data [ 'ID' ]);
2018-10-23 20:22:22 +00:00
$user_posts = $this -> PostsModel -> getUserPosts ( $user_data [ 'ID' ], 3 , 0 , 192 );
$user_comments = $this -> UserModel -> getUserComments ( $user_data [ 'ID' ], 3 , 0 );
$user_blog_posts = $this -> UserModel -> getUserBlogPosts ( $user_data [ 'ID' ], 3 , 0 );
$date_created = strtotime ( $user_data [ 'date_created' ]);
$user_data [ 'time_existing' ] = DateTimeHumanizer :: difference ( new \DateTime (), new \DateTime ( " @ $date_created " ), $_SESSION [ 'site_lang' ]);
$title = $user_data [ 'displayname' ] . " - Profile " ;
2018-10-16 16:28:42 +00:00
$isCurrentUserFollowing = false ;
if ( isset ( $_SESSION [ 'user' ][ 'ID' ]))
$isCurrentUserFollowing = $this -> UserModel -> isFollowing ( $_SESSION [ 'user' ][ 'ID' ], $user_data [ 'ID' ]);
$_SESSION [ 'currentProfilePage' ] = $user_data [ 'ID' ];
} else {
$message = [ " type " => " danger " , " message1 " => " Dieser Nutzer existiert nicht! " , " message2 " => " Der angegebene Nutzername konnte nicht gefunden werden. " ];
$title = " Error - Profile " ;
}
}
2018-10-23 20:22:22 +00:00
$this -> load -> view ( 'header' , [ 'active' => 'profile' , 'title' => $title , 'additionalStyles' => [ 'profile_page.css' ]]);
if ( isset ( $message )) {
$this -> load -> view ( 'network/message' , $message );
2018-10-16 16:28:42 +00:00
}
2018-10-23 20:22:22 +00:00
if ( isset ( $user_data ) && isset ( $user_stats ) && isset ( $user_posts ) && isset ( $user_comments ) && isset ( $user_blog_posts )) {
$this -> load -> view ( 'network/user/profile_page' , [ 'data' => $user_data , 'stats' => $user_stats , 'posts' => $user_posts , 'comments' => $user_comments , 'blog_posts' => $user_blog_posts , 'isCurrentUserFollowing' => $isCurrentUserFollowing ]);
}
$this -> load -> view ( 'footer' , [ 'additionalScripts' => [ 'profile_page.js' ]]);
}
2018-10-16 16:28:42 +00:00
2018-10-23 20:22:22 +00:00
public function comments ( $user = " " )
{
if ( $user == " " ) {
$title = " Error - Profile " ;
$message = [ " type " => " danger " , " message1 " => " Dieser Nutzer existiert nicht! " , " message2 " => " Es wurde kein Nutzername angegeben. " ];
}
2018-10-16 16:28:42 +00:00
2018-10-23 20:22:22 +00:00
$user_data = $this -> UserModel -> getUser ( $user );
$user_exists = ! empty ( $user_data );
if ( $user_exists ) {
$user_data = $user_data [ 0 ];
$dateCreated = strtotime ( $user_data [ 'date_created' ]);
$user_data [ 'time_existing' ] = DateTimeHumanizer :: difference ( new \DateTime (), new \DateTime ( " @ $dateCreated " ), $_SESSION [ 'site_lang' ]);
$user_stats = $this -> UserModel -> getUserStats ( $user_data [ 'ID' ]);
$title = $user_data [ 'displayname' ] . " - Blog-Kommentare " ;
$isCurrentUserFollowing = false ;
if ( isset ( $_SESSION [ 'user' ][ 'ID' ]))
$isCurrentUserFollowing = $this -> UserModel -> isFollowing ( $_SESSION [ 'user' ][ 'ID' ], $user_data [ 'ID' ]);
$_SESSION [ 'currentProfilePage' ] = $user_data [ 'ID' ];
} else {
$message = [ " type " => " danger " , " message1 " => " Dieser Nutzer existiert nicht! " , " message2 " => " Der angegebene Nutzername konnte nicht gefunden werden. " ];
$title = " Error - Profile " ;
2018-10-16 16:28:42 +00:00
}
2018-10-23 20:22:22 +00:00
$this -> load -> view ( 'header' , [ 'active' => 'profile' , 'title' => $title , 'additionalStyles' => [ 'profile_page.css' ]]);
if ( isset ( $message )) {
$this -> load -> view ( 'network/message' , $message );
2018-10-16 16:28:42 +00:00
}
2018-10-23 20:22:22 +00:00
if ( $user_exists ) {
$this -> load -> view ( 'network/blog/user_comments' , [ 'data' => $user_data , 'stats' => $user_stats , 'isCurrentUserFollowing' => $isCurrentUserFollowing ]);
}
$this -> load -> view ( 'footer' , [ 'additionalScripts' => [ 'profile_page.js' ]]);
$this -> load -> view ( 'network/blog/user_comments_end' , [ 'data' => $user_data ]);
}
2018-10-16 16:28:42 +00:00
2018-10-23 20:22:22 +00:00
public function getComments ()
{
$user = ( int ) $this -> input -> get ( 'user' );
$amount = ( int ) $this -> input -> get ( 'amount' );
$offset = ( int ) $this -> input -> get ( 'offset' ) * $amount ;
$user_comments = $this -> UserModel -> getUserComments ( $user , $amount , $offset );
$comment_user = $this -> UserModel -> getUserByID ( $user )[ 0 ];
foreach ( $user_comments as $comment ) {
$this -> load -> view ( 'network/blog/comment_item' , [ 'data' => $comment_user , 'c' => $comment ]);
}
}
2018-10-16 16:28:42 +00:00
2018-10-23 20:22:22 +00:00
public function posts ( $user = " " )
{
if ( $user == " " ) {
redirect ( base_url ( 'user' ));
}
2018-10-16 16:28:42 +00:00
2018-10-23 20:22:22 +00:00
$user_data = $this -> UserModel -> getUser ( $user );
$user_exists = ! empty ( $user_data );
if ( $user_exists ) {
$user_data = $user_data [ 0 ];
$dateCreated = strtotime ( $user_data [ 'date_created' ]);
$user_data [ 'time_existing' ] = DateTimeHumanizer :: difference ( new \DateTime (), new \DateTime ( " @ $dateCreated " ), $_SESSION [ 'site_lang' ]);
$user_stats = $this -> UserModel -> getUserStats ( $user_data [ 'ID' ]);
$title = $user_data [ 'displayname' ] . " - Posts " ;
$isCurrentUserFollowing = false ;
if ( isset ( $_SESSION [ 'user' ][ 'ID' ]))
$isCurrentUserFollowing = $this -> UserModel -> isFollowing ( $_SESSION [ 'user' ][ 'ID' ], $user_data [ 'ID' ]);
$_SESSION [ 'currentProfilePage' ] = $user_data [ 'ID' ];
} else {
$message = [ " type " => " danger " , " message1 " => " Dieser Nutzer existiert nicht! " , " message2 " => " Der angegebene Nutzername konnte nicht gefunden werden. " ];
$title = " Error - Profile " ;
}
2018-10-16 16:28:42 +00:00
2018-10-23 20:22:22 +00:00
$this -> load -> view ( 'header' , [ 'active' => 'profile' , 'title' => $title , 'additionalStyles' => [ 'profile_page.css' ]]);
if ( isset ( $message )) {
$this -> load -> view ( 'network/message' , $message );
}
if ( $user_exists ) {
$this -> load -> view ( 'network/user/user_posts' , [ 'data' => $user_data , 'stats' => $user_stats , 'isCurrentUserFollowing' => $isCurrentUserFollowing ]);
2018-10-16 16:28:42 +00:00
}
2018-10-23 20:22:22 +00:00
$this -> load -> view ( 'footer' , [ 'additionalScripts' => [ 'profile_page.js' ]]);
$this -> load -> view ( 'network/user/user_posts_end' , [ 'data' => $user_data ]);
}
2018-10-16 16:28:42 +00:00
2018-10-23 20:22:22 +00:00
public function getPosts ()
{
$user = ( int ) $this -> input -> get ( 'user' );
$amount = ( int ) $this -> input -> get ( 'amount' );
$offset = ( int ) $this -> input -> get ( 'offset' ) * $amount ;
$user_posts = $this -> PostsModel -> getUserPosts ( $user , $amount , $offset );
2018-10-16 16:28:42 +00:00
2018-10-23 20:22:22 +00:00
foreach ( $user_posts as $post ) {
$this -> load -> view ( 'network/posts/post_item' , $post );
2018-10-16 16:28:42 +00:00
}
2018-10-23 20:22:22 +00:00
}
2018-10-16 16:28:42 +00:00
2018-10-23 20:22:22 +00:00
public function blogposts ( $user = " " )
{
if ( $user == " " ) {
redirect ( base_url ( 'user' ));
}
2018-10-16 16:28:42 +00:00
2018-10-23 20:22:22 +00:00
$user_data = $this -> UserModel -> getUser ( $user );
$user_exists = ! empty ( $user_data );
if ( $user_exists ) {
$user_data = $user_data [ 0 ];
$dateCreated = strtotime ( $user_data [ 'date_created' ]);
$user_data [ 'time_existing' ] = DateTimeHumanizer :: difference ( new \DateTime (), new \DateTime ( " @ $dateCreated " ), $_SESSION [ 'site_lang' ]);
$user_stats = $this -> UserModel -> getUserStats ( $user_data [ 'ID' ]);
$title = $user_data [ 'displayname' ] . " - Posts " ;
$isCurrentUserFollowing = false ;
if ( isset ( $_SESSION [ 'user' ][ 'ID' ]))
$isCurrentUserFollowing = $this -> UserModel -> isFollowing ( $_SESSION [ 'user' ][ 'ID' ], $user_data [ 'ID' ]);
$_SESSION [ 'currentProfilePage' ] = $user_data [ 'ID' ];
} else {
$message = [ " type " => " danger " , " message1 " => " Dieser Nutzer existiert nicht! " , " message2 " => " Der angegebene Nutzername konnte nicht gefunden werden. " ];
$title = " Error - Profile " ;
}
2018-10-16 16:28:42 +00:00
2018-10-23 20:22:22 +00:00
$this -> load -> view ( 'header' , [ 'active' => 'profile' , 'title' => $title , 'additionalStyles' => [ 'profile_page.css' ]]);
if ( isset ( $message )) {
$this -> load -> view ( 'network/message' , $message );
}
if ( $user_exists ) {
$this -> load -> view ( 'network/blog/user_blog_posts' , [ 'data' => $user_data , 'stats' => $user_stats , 'isCurrentUserFollowing' => $isCurrentUserFollowing ]);
}
$this -> load -> view ( 'footer' , [ 'additionalScripts' => [ 'profile_page.js' ]]);
$this -> load -> view ( 'network/blog/user_blog_posts_end' , [ 'data' => $user_data ]);
}
2018-10-16 16:28:42 +00:00
2018-10-23 20:22:22 +00:00
public function getBlogPosts ()
{
$user = ( int ) $this -> input -> get ( 'user' );
$amount = ( int ) $this -> input -> get ( 'amount' );
$offset = ( int ) $this -> input -> get ( 'offset' ) * $amount ;
$user_posts = $this -> UserModel -> getUserBlogPosts ( $user , $amount , $offset );
$post_user = $this -> UserModel -> getUserByID ( $user )[ 0 ];
foreach ( $user_posts as $post ) {
$this -> load -> view ( 'network/blog/blog_post_item' , [ 'data' => $post_user , 'post' => $post ]);
}
}
2018-10-16 16:28:42 +00:00
2018-10-23 20:22:22 +00:00
public function publishPost ()
{
if ( ! isset ( $_SESSION [ 'user' ]) || empty ( $_SESSION [ 'user' ])) {
?>
< div class = " alert alert-danger " role = " alert " >
< b > Veröffentlichen des Posts fehlgeschlagen !</ b >
Du musst in deinen Account eingeloggt sein , um Posts erstellen zu können .< br >
Bitte erstelle dir entweder
< a href = " <?= base_url('login') ?> " > kostenlos einen neuen Account </ a >
oder
< a href = " <?= base_url('login') ?> " > melde dich an </ a >
.
</ div >
< ? php
exit ;
}
2018-10-16 16:28:42 +00:00
2018-10-23 20:22:22 +00:00
$content = $this -> input -> post ( 'content' );
if ( strlen ( $content ) >= 10000 ) {
?>
< div class = " alert alert-warning " role = " alert " >
< b > Veröffentlichung des Posts fehlgeschlagen !</ b > Dein Post ist leider zu lang . Er darf maximal 10.000
Zeichen umfassen .
</ div >
< ? php
exit ;
}
2018-10-16 16:28:42 +00:00
2018-10-23 20:22:22 +00:00
$replyTo = $this -> input -> post ( 'replyTo' );
if ( $replyTo !== " -1 " && ! $this -> PostsModel -> isUUIDValid ( $replyTo )) {
?>
< div class = " alert alert-warning " role = " alert " >
< b > Veröffentlichung des Posts fehlgeschlagen !</ b > Der Post , an den du deine Antwort richten willst ,
existiert nicht ( mehr ) .< br >
Solltest du dies für einen Fehler halten , versuche es später erneut oder kontaktiere uns .
</ div >
< ? php
exit ;
}
2018-10-16 16:28:42 +00:00
2018-10-23 20:22:22 +00:00
$postID = - 1 ;
if ( $replyTo !== " -1 " ) {
$postID = $this -> PostsModel -> addReply ( $_SESSION [ 'user' ][ 'ID' ], $content , $replyTo );
} else {
$postID = $this -> PostsModel -> addPost ( $_SESSION [ 'user' ][ 'ID' ], $content );
2018-10-16 16:28:42 +00:00
}
2018-10-23 20:22:22 +00:00
$media = $this -> input -> post ( 'postMedia' );
if ( ! empty ( $media )) {
foreach ( $media as $entry ) {
$image = str_replace ( ' ' , '+' , $entry [ 'image' ]);
$image = substr ( $image , strpos ( $image , ',' ) + 1 );
$image = base64_decode ( $image );
2018-10-16 16:28:42 +00:00
2018-10-23 20:22:22 +00:00
$fileUrl = $this -> FileModel -> uploadFileByContent ( $image , $entry [ 'name' ], $entry [ 'type' ], $entry [ 'size' ]);
2018-10-16 16:28:42 +00:00
2018-10-23 20:22:22 +00:00
$this -> PostsModel -> addImageToPost ( $postID , $fileUrl );
2018-10-16 16:28:42 +00:00
}
2018-10-23 20:22:22 +00:00
?>
< div class = " alert alert-success " role = " alert " >
< b > Dein Post wurde erfolgreich veröffentlicht !</ b > Möchtest du nun deine Posts ansehen ? < br >
< button type = " button " class = " btn btn-sm btn-default " data - dismiss = " modal " > Nein </ button >
< a href = '<?= base_url(' user / ' . $_SESSION[' user '][' username '] . ' / posts ') ?>'
class = 'btn btn-sm btn-primary' > Ja </ a >
</ div >
< ? php
2018-10-16 16:28:42 +00:00
}
2018-10-23 20:22:22 +00:00
}
2018-10-16 16:28:42 +00:00
2018-10-23 20:22:22 +00:00
public function followers ( $user = " " )
{
if ( $user == " " ) {
$title = " Error - Profile " ;
$message = [ " type " => " danger " , " message1 " => " Dieser Nutzer existiert nicht! " , " message2 " => " Es wurde kein Nutzername angegeben. " ];
}
2018-10-16 16:28:42 +00:00
2018-10-23 20:22:22 +00:00
$user_data = $this -> UserModel -> getUser ( $user );
$user_exists = ! empty ( $user_data );
if ( $user_exists ) {
$user_data = $user_data [ 0 ];
$dateCreated = strtotime ( $user_data [ 'date_created' ]);
$user_data [ 'time_existing' ] = DateTimeHumanizer :: difference ( new \DateTime (), new \DateTime ( " @ $dateCreated " ), $_SESSION [ 'site_lang' ]);
$user_stats = $this -> UserModel -> getUserStats ( $user_data [ 'ID' ]);
$followers = $this -> UserModel -> getFollowers ( $user_data [ 'ID' ]);
$title = $user_data [ 'displayname' ] . " - Follower " ;
$isCurrentUserFollowing = false ;
if ( isset ( $_SESSION [ 'user' ][ 'ID' ]))
$isCurrentUserFollowing = $this -> UserModel -> isFollowing ( $_SESSION [ 'user' ][ 'ID' ], $user_data [ 'ID' ]);
$_SESSION [ 'currentProfilePage' ] = $user_data [ 'ID' ];
} else {
$message = [ " type " => " danger " , " message1 " => " Dieser Nutzer existiert nicht! " , " message2 " => " Der angegebene Nutzername konnte nicht gefunden werden. " ];
$title = " Error - Profile " ;
}
2018-10-16 16:28:42 +00:00
2018-10-23 20:22:22 +00:00
$this -> load -> view ( 'header' , [ 'active' => 'profile' , 'title' => $title , 'additionalStyles' => [ 'profile_page.css' ]]);
if ( isset ( $message )) {
$this -> load -> view ( 'network/message' , $message );
}
if ( $user_exists ) {
$this -> load -> view ( 'network/user/user_followers' , [ 'data' => $user_data , 'active' => 'followers' , 'stats' => $user_stats , 'isCurrentUserFollowing' => $isCurrentUserFollowing , 'followers' => $followers ]);
}
$this -> load -> view ( 'footer' , [ 'additionalScripts' => [ 'profile_page.js' ]]);
}
2018-10-16 16:28:42 +00:00
2018-10-23 20:22:22 +00:00
public function following ( $user = " " )
{
if ( $user == " " ) {
$title = " Error - Profile " ;
$message = [ " type " => " danger " , " message1 " => " Dieser Nutzer existiert nicht! " , " message2 " => " Es wurde kein Nutzername angegeben. " ];
2018-10-16 16:28:42 +00:00
}
2018-10-23 20:22:22 +00:00
$user_data = $this -> UserModel -> getUser ( $user );
$user_exists = ! empty ( $user_data );
if ( $user_exists ) {
$user_data = $user_data [ 0 ];
$dateCreated = strtotime ( $user_data [ 'date_created' ]);
$user_data [ 'time_existing' ] = DateTimeHumanizer :: difference ( new \DateTime (), new \DateTime ( " @ $dateCreated " ), $_SESSION [ 'site_lang' ]);
$user_stats = $this -> UserModel -> getUserStats ( $user_data [ 'ID' ]);
$following = $this -> UserModel -> getFollowing ( $user_data [ 'ID' ]);
$title = $user_data [ 'displayname' ] . " - Follower " ;
$isCurrentUserFollowing = false ;
if ( isset ( $_SESSION [ 'user' ][ 'ID' ]))
$isCurrentUserFollowing = $this -> UserModel -> isFollowing ( $_SESSION [ 'user' ][ 'ID' ], $user_data [ 'ID' ]);
$_SESSION [ 'currentProfilePage' ] = $user_data [ 'ID' ];
} else {
$message = [ " type " => " danger " , " message1 " => " Dieser Nutzer existiert nicht! " , " message2 " => " Der angegebene Nutzername konnte nicht gefunden werden. " ];
$title = " Error - Profile " ;
}
2018-10-16 16:28:42 +00:00
2018-10-23 20:22:22 +00:00
$this -> load -> view ( 'header' , [ 'active' => 'profile' , 'title' => $title , 'additionalStyles' => [ 'profile_page.css' ]]);
if ( isset ( $message )) {
$this -> load -> view ( 'network/message' , $message );
}
if ( $user_exists ) {
$this -> load -> view ( 'network/user/user_followers' , [ 'data' => $user_data , 'active' => 'following' , 'stats' => $user_stats , 'isCurrentUserFollowing' => $isCurrentUserFollowing , 'followers' => $following ]);
}
$this -> load -> view ( 'footer' , [ 'additionalScripts' => [ 'profile_page.js' ]]);
}
2018-10-16 16:28:42 +00:00
2018-10-23 20:22:22 +00:00
public function switchFollowing ()
{
header ( 'Content-Type: application/json' );
if ( ! isset ( $_SESSION [ 'currentProfilePage' ])) {
$response = [ 'type' => 'error' , 'code' => - 1 ];
echo json_encode ( $response );
exit ;
}
2018-10-16 16:28:42 +00:00
2018-10-23 20:22:22 +00:00
$followedUser = $_SESSION [ 'currentProfilePage' ];
2018-10-16 16:28:42 +00:00
2018-10-23 20:22:22 +00:00
// code 0: not logged in
// code 1: same user
// code 10: unfollowed
// code 11: now following
2018-10-16 16:28:42 +00:00
2018-10-23 20:22:22 +00:00
if ( ! isset ( $_SESSION [ 'user' ][ 'username' ])) {
$response = [ 'type' => 'error' , 'code' => 0 ];
echo json_encode ( $response );
exit ;
}
2018-10-16 16:28:42 +00:00
2018-10-23 20:22:22 +00:00
$follower = $_SESSION [ 'user' ][ 'ID' ];
2018-10-16 16:28:42 +00:00
2018-10-23 20:22:22 +00:00
if ( $follower == $followedUser ) {
$response = [ 'type' => 'error' , 'code' => 1 ];
2018-10-16 16:28:42 +00:00
echo json_encode ( $response );
exit ;
}
2018-10-23 20:22:22 +00:00
if ( $this -> UserModel -> isFollowing ( $follower , $followedUser )) {
$this -> UserModel -> unfollow ( $follower , $followedUser );
$response = [ 'type' => 'success' , 'code' => 10 ];
echo json_encode ( $response );
exit ;
}
2018-10-16 16:28:42 +00:00
2018-10-23 20:22:22 +00:00
$this -> UserModel -> follow ( $follower , $followedUser );
$response = [ 'type' => 'success' , 'code' => 11 ];
echo json_encode ( $response );
exit ;
}
public function edit ( $user = " " )
{
if ( $user == " " ) {
redirect ( base_url ( 'user' ));
}
$user_data = $this -> UserModel -> getUser ( $user );
$user_exists = ! empty ( $user_data );
if ( $user_exists ) {
$user_data = $user_data [ 0 ];
// Update Settings
$newData = [];
// TODO: Error messages
// Username
if ( isset ( $_POST [ 'username' ])) {
if ( ! preg_match ( '/[^A-Za-z0-9._]/' , $_POST [ 'username' ])) {
if ( $this -> LoginModel -> isAvailable ( $_POST [ 'username' ])) {
if ( strlen ( $_POST [ 'username' ]) >= 4 ) {
$newData [ 'username' ] = strtolower ( $_POST [ 'username' ]);
$newData [ 'displayname' ] = $_POST [ 'username' ];
2018-10-16 16:28:42 +00:00
} else {
2018-10-23 20:22:22 +00:00
$_SESSION [ 'profileEditNotification' ] .= " <div class='alert alert-danger' role='alert'><b>Zu kurzer Nutzername!</b> Dein Name muss 4 Zeichen oder mehr enthalten.</div> " ;
2018-10-16 16:28:42 +00:00
}
} else {
2018-10-23 20:22:22 +00:00
$_SESSION [ 'profileEditNotification' ] .= " <div class='alert alert-danger' role='alert'><b>Nutzername bereits vergeben!</b> Ein anderer Nutzer hat anscheinend diesen Namen bereits gewählt.</div> " ;
2018-10-16 16:28:42 +00:00
}
2018-10-23 20:22:22 +00:00
} else {
$_SESSION [ 'profileEditNotification' ] .= " <div class='alert alert-danger' role='alert'><b>Ungültiger Nutzername!</b> Dein Name darf nur Groß- (A-Z) und Kleinbuchstaben (a-z), Zahlen (0-9) und Punkte (.) sowie Unterstriche (_).</div> " ;
2018-10-16 16:28:42 +00:00
}
2018-10-23 20:22:22 +00:00
}
// Gender
if ( isset ( $_POST [ 'gender' ])) {
if ( $_POST [ 'gender' ] == " male " || $_POST [ 'gender' ] == " female " || $_POST [ 'gender' ] == 'other' ) {
$newData [ 'gender' ] = $_POST [ 'gender' ];
2018-10-16 16:28:42 +00:00
}
2018-10-23 20:22:22 +00:00
}
// Birth date
if ( isset ( $_POST [ 'birthdate-day' ]) && isset ( $_POST [ 'birthdate-month' ])) {
$day = intval ( $_POST [ 'birthdate-day' ]);
$month = intval ( $_POST [ 'birthdate-month' ]);
if ( $month > 0 && $month <= 12 ) {
$monthDayCount = [ 31 , 29 , 31 , 30 , 31 , 30 , 31 , 31 , 30 , 31 , 30 , 31 ];
if ( $day <= $monthDayCount [ $month - 1 ]) {
$newData [ 'birthdate' ] = $day . '.' . $month . '.' ;
2018-10-16 16:28:42 +00:00
}
}
2018-10-23 20:22:22 +00:00
}
if ( isset ( $_POST [ 'birthdate-year' ])) {
2018-10-16 16:28:42 +00:00
2018-10-23 20:22:22 +00:00
}
// Language
if ( isset ( $_POST [ 'language' ])) {
$newData [ 'language' ] = $_POST [ 'language' ];
}
// Country
if ( isset ( $_POST [ 'country' ])) {
$newData [ 'country' ] = $_POST [ 'country' ];
}
// Biography/About
if ( isset ( $_POST [ 'biography' ])) {
$newData [ 'about' ] = $_POST [ 'biography' ];
}
// Avatar
if ( isset ( $_FILES [ 'avatar' ])) {
$image = $this -> FileModel -> uploadCroppedImage ( 'avatar' , 4096 , $_FILES [ 'avatar' ][ 'name' ], 500 , 500 );
if ( $image != null )
$newData [ 'profile_picture' ] = $image ;
unset ( $_FILES [ 'avatar' ]);
}
// Header
if ( isset ( $_FILES [ 'header' ])) {
$image = $this -> FileModel -> uploadImage ( 'header' , 4096 , $_FILES [ 'header' ][ 'name' ], 1920 );
if ( $image != null )
$newData [ 'header_image' ] = $image ;
unset ( $_FILES [ 'header' ]);
}
// Social Networks
if ( isset ( $_POST [ 'social-networks' ])) {
2018-10-16 16:28:42 +00:00
2018-10-23 20:22:22 +00:00
}
// Profile color
if ( isset ( $_POST [ 'color' ])) {
2018-10-16 16:28:42 +00:00
2018-10-23 20:22:22 +00:00
}
// E-Mail-Address
if ( isset ( $_POST [ 'email' ])) {
if ( isset ( $_POST [ 'email-password' ]) && ! empty ( $_POST [ 'email-password' ])) {
$loginData = $this -> LoginModel -> getLoginData ( $_SESSION [ 'user' ][ 'username' ]);
if ( empty ( $loginData )) {
$_SESSION [ 'profileEditNotification' ] .= " <div class='alert alert-danger' role='alert'><b>Ungültiger Account</b> Anscheinend versuchst du die E-Mail-Adresse eines nicht existierenden Accounts zu ändern. Sollte es sich um einen Fehler handeln, kontaktiere bitte das Website-Team!</div> " ;
} else {
$loginData = $loginData [ 0 ];
$encryptedPassword = $this -> LoginModel -> getPasswordHash ( $_POST [ 'email-password' ], $loginData [ 'original_name' ]);
if ( $loginData [ 'password' ] == $encryptedPassword ) {
$isRegistered = $this -> LoginModel -> isRegistered ( $_POST [ 'email' ]);
if ( $isRegistered == " " ) {
$trashMail = $this -> LoginModel -> isTrashMail ( $_POST [ 'email' ]);
if ( $trashMail == '' ) {
$this -> LoginModel -> changeMailAddress ( $_POST [ 'email' ], $loginData [ 'username' ]);
$_SESSION [ 'profileEditNotification' ] .= " <div class='alert alert-warning' role='alert'><b>Deine E-Mail-Adresse wurde geändert!</b> Nun musst du nur noch in deinem Postfach vorbeischauen und die neue Adresse aktivieren.</div> " ;
2018-10-16 16:28:42 +00:00
} else {
2018-10-23 20:22:22 +00:00
$_SESSION [ 'profileEditNotification' ] .= $trashMail ;
2018-10-16 16:28:42 +00:00
}
} else {
2018-10-23 20:22:22 +00:00
$_SESSION [ 'profileEditNotification' ] .= $isRegistered ;
2018-10-16 16:28:42 +00:00
}
2018-10-23 20:22:22 +00:00
} else {
$_SESSION [ 'profileEditNotification' ] .= " <div class='alert alert-danger' role='alert'><b>Ungültiges Passwort!</b> Es scheint als wäre das eingegebene Passwort nicht mit dem richtigen übereinstimmend.</div> " ;
2018-10-16 16:28:42 +00:00
}
}
2018-10-23 20:22:22 +00:00
} else {
$_SESSION [ 'profileEditNotification' ] .= " <div class='alert alert-danger' role='alert'><b>Bitte gib dein Passwort ein!</b> Das Ändern der E-Mail-Adresse ist ein tiefgreifender Eingriff in den Account. Daher benötigen wir zur Sicherheit nochmal dein Passwort.</div> " ;
2018-10-16 16:28:42 +00:00
}
2018-10-23 20:22:22 +00:00
}
// Notifications
if ( isset ( $_POST [ 'email-notifications' ])) {
$newData [ 'receiveEmails' ] = filter_var ( $_POST [ 'email-notifications' ], FILTER_VALIDATE_BOOLEAN );
}
// Newsletter
if ( isset ( $_POST [ 'newsletter' ])) {
$newData [ 'receiveNewsletter' ] = filter_var ( $_POST [ 'newsletter' ], FILTER_VALIDATE_BOOLEAN );
}
// Password
if ( isset ( $_POST [ 'passwordNew' ])) {
if ( isset ( $_POST [ 'passwordOld' ])) {
$loginData = $this -> LoginModel -> getLoginData ( $_SESSION [ 'user' ][ 'username' ]);
if ( ! empty ( $loginData )) {
$loginData = $loginData [ 0 ];
$encryptedPassword = $this -> LoginModel -> getPasswordHash ( $_POST [ 'passwordOld' ], $loginData [ 'original_name' ]);
if ( $encryptedPassword == $loginData [ 'password' ]) {
if ( $this -> LoginModel -> checkPassword ( $_POST [ 'passwordNew' ])) {
if ( isset ( $_POST [ 'passwordNewRepeat' ]) && $_POST [ 'passwordNew' ] == $_POST [ 'passwordNewRepeat' ]) {
$this -> LoginModel -> changePassword ( $_POST [ 'passwordNew' ], $loginData [ 'original_name' ]);
$_SESSION [ 'profileEditNotification' ] .= " <div class='alert alert-success' role='alert'><b>Dein Passwort wurde geändert!</b> Du kannst dich nun damit einloggen</div> " ;
2018-10-16 16:28:42 +00:00
} else {
2018-10-23 20:22:22 +00:00
$_SESSION [ 'profileEditNotification' ] .= " <div class='alert alert-danger' role='alert'><b>Wiederholtes Passwort falsch!</b> Das Passwort, das du wiederholt hast, stimmt nicht mit dem eigentlichen überein.</div> " ;
2018-10-16 16:28:42 +00:00
}
} else {
2018-10-23 20:22:22 +00:00
$_SESSION [ 'profileEditNotification' ] .= " <div class='alert alert-danger' role='alert'><b>Zu unsicheres Passwort!</b> Dein Passwort sollte mindest 8 Zeichen lang sein und jeweils einen Groß-, einen Kleinbuchstaben, eine Zahl und ein Sonderzeichen enthalten.</div> " ;
2018-10-16 16:28:42 +00:00
}
} else {
2018-10-23 20:22:22 +00:00
$_SESSION [ 'profileEditNotification' ] .= " <div class='alert alert-danger' role='alert'><b>Altes Passwort falsch!</b> Dein altes eingegebenes Passwort ist falsch!</div> " ;
2018-10-16 16:28:42 +00:00
}
} else {
2018-10-23 20:22:22 +00:00
$_SESSION [ 'profileEditNotification' ] .= " <div class='alert alert-danger' role='alert'><b>Ungültiger Account</b> Anscheinend versuchst du die E-Mail-Adresse eines nicht existierenden Accounts zu ändern. Sollte es sich um einen Fehler handeln, kontaktiere bitte das Website-Team!</div> " ;
2018-10-16 16:28:42 +00:00
}
2018-10-23 20:22:22 +00:00
} else {
$_SESSION [ 'profileEditNotification' ] .= " <div class='alert alert-danger' role='alert'><b>Altes Passwort fehlend!</b> Bitte gib dein altes Passwort ebenfalls ein!</div> " ;
2018-10-16 16:28:42 +00:00
}
2018-10-23 20:22:22 +00:00
}
if ( isset ( $_POST [ 'showAds' ])) {
if ( isset ( $_SESSION [ 'user' ]) && $_SESSION [ 'user' ][ 'rank' ] >= 2 ) {
$newData [ 'showAds' ] = filter_var ( $_POST [ 'email-notifications' ], FILTER_VALIDATE_BOOLEAN );
} else {
$_SESSION [ 'profileEditNotification' ] .= " <div class='alert alert-danger' role='alert'><b>Du bist dazu nicht berechtigt!</b> Um diese Einstellung zu verändern, musst du mindestens ein Premium-Nutzer oder höher sein!</div> " ;
2018-10-16 16:28:42 +00:00
}
}
2018-10-23 20:22:22 +00:00
if ( ! empty ( $newData )) {
// Add entry to history
unset ( $user_data [ 'rankName' ]);
unset ( $_SESSION [ 'user' ]);
$this -> UserModel -> insertIntoHistory ( $user_data );
// Update profile
$this -> UserModel -> updateProfile ( $newData , $user_data [ 'ID' ]);
$this -> db -> cache_delete ( 'user' , $user_data [ 'username' ]);
2018-10-16 16:28:42 +00:00
2018-10-23 20:22:22 +00:00
$this -> LoginModel -> reloadLoginSession ( $user_data );
2018-10-16 16:28:42 +00:00
2018-10-23 20:22:22 +00:00
redirect ( base_url ( uri_string ()));
2018-10-16 16:28:42 +00:00
}
2018-10-23 20:22:22 +00:00
$user_stats = $this -> UserModel -> getUserStats ( $user_data [ 'ID' ]);
$title = $user_data [ 'displayname' ] . ' - Profil bearbeiten' ;
2018-10-16 16:28:42 +00:00
}
2018-10-23 20:22:22 +00:00
$this -> load -> view ( 'header' , [ 'active' => 'profile' , 'title' => $title , 'additionalStyles' => [ 'lib/selectize.css' , 'lib/selectize.bootstrap3.css' , 'profile_page.css' ]]);
$editMessage = isset ( $_SESSION [ 'profileEditNotification' ]) ? $_SESSION [ 'profileEditNotification' ] : " " ;
$_SESSION [ 'profileEditNotification' ] = " " ;
if ( isset ( $message )) {
$this -> load -> view ( 'network/message' , $message );
}
if ( $user_exists ) {
$this -> load -> view ( 'network/user/profile_edit' , [ 'message' => $editMessage , 'data' => $user_data , 'stats' => $user_stats ]);
}
$this -> load -> view ( 'footer' , [ 'additionalScripts' => [ 'lib/selectize.js' , 'profile_page.js' , 'profile_edit.js' ]]);
}
2018-10-16 16:28:42 +00:00
2018-10-23 20:22:22 +00:00
public function single_post ( $username = null , $uuid = null , $origin = null )
{
$origin = isset ( $_GET [ 'o' ]) ? $_GET [ 'o' ] : null ;
if ( $origin == null ) {
$origin = base_url ( 'user/' . $username );
} else {
$origin = base64_decode ( urldecode ( $origin ));
}
2018-10-16 16:28:42 +00:00
2018-10-23 20:22:22 +00:00
$this -> load -> view ( 'header' , [ 'active' => 'profile' , 'title' => 'Test' ]);
$this -> load -> view ( 'network/posts/user_post_page' , [ 'origin' => $origin , 'username' => $username , 'uuid' => $uuid ]);
$this -> load -> view ( 'footer' , [ 'additionalScripts' => [ 'single-post-page.js' ]]);
}
2018-10-16 16:28:42 +00:00
2018-10-23 20:22:22 +00:00
public function single_post_data ( $username = null , $uuid = null )
{
$message = " " ;
$post = [];
$replies = [];
if ( $username == null ) {
$message .= '<div class="alert alert-danger" role="alert"><b>Es wurde kein Nutzer angegeben!</b> Es können keine Posts von einem undefinierten Nutzer gefunden werden.</div>' ;
goto display ;
}
if ( $uuid == null ) {
$message .= '<div class="alert alert-danger" role="alert"><b>Es wurde keine Post-ID angegeben!</b> Es können keine undefinierten Posts gefunden werden.</div>' ;
goto display ;
}
2018-10-16 16:28:42 +00:00
2018-10-23 20:22:22 +00:00
$user = $this -> UserModel -> getUser ( $username );
if ( empty ( $user )) {
$message .= '<div class="alert alert-warning" role="alert"><b>Es wurde kein Nutzer mit dem angegebenen Namen gefunden!</b> Vielleicht kannst du ja diese Lücke füllen?</div>' ;
goto display ;
}
$user = $user [ 0 ];
2018-10-16 16:28:42 +00:00
2018-10-23 20:22:22 +00:00
$post = $this -> PostsModel -> getPostDetails ( $user [ 'ID' ], $uuid );
if ( empty ( $post )) {
$message .= '<div class="alert alert-warning" role="alert"><b>Es wurde kein Post mit der angegebenen ID gefunden!</b> Vielleicht kannst du ja diesen neuen Content erschaffen?</div>' ;
goto display ;
2018-10-16 16:28:42 +00:00
}
2018-10-23 20:22:22 +00:00
$post = $post [ 0 ];
$replies = $this -> PostsModel -> getPostReplies ( $post [ 'ID' ]);
display :
$this -> load -> view ( 'network/posts/user_post_content' , [ 'message' => $message , 'post' => $post , 'replies' => $replies ]);
2018-10-16 16:28:42 +00:00
}
2018-10-23 20:22:22 +00:00
}