Commit dbd5094f authored by Eric Laufer's avatar Eric Laufer

Chat Update

Chat Update:
- Username Klickbar
- Smiley eintragbar
- User wird hervorgehoben wenn sein Nick mit @ markiert ist
- Chatarchiv überarbeitet
parent 92a0bf2d
......@@ -6,6 +6,12 @@ class chat{
private $error = 0;
private $meldung;
private $post = array();
const upload_folder = 'images/chat/';
const allowed_extensions = array('png', 'jpg', 'jpeg', 'gif');
const max_size = 5120*1024;
const allowed_types = array(IMAGETYPE_PNG, IMAGETYPE_JPEG, IMAGETYPE_GIF);
private $filename;
private $extension;
function __construct(){
global $datenbank;
......@@ -29,7 +35,7 @@ class chat{
private function make_array($post){
foreach($post AS $key => $value){
if($key != '' && $key != 'chat_save'){
if($key != '' && $key != 'run' && $value != ''){
$this->post[$key] = $this->db->escape($value);
}
}
......@@ -50,7 +56,7 @@ class chat{
</form>
</li>';
}
$aus .= '</ul>ul>';
$aus .= '</ul>';
return $aus;
}
......@@ -68,4 +74,85 @@ class chat{
$this->meldung = CHAT_DELETE_FALSE.$this->db->error();
}
}
private function CheckDateiendung(){
if(!in_array($this->extension, self::allowed_extensions)) {
$this->error = 1;
$this->meldung = PICUPLOADEXTENSENFALSE;
}
}
private function MaxSize($files){
if($files['datei']['size'] > self::max_size) {
$this->error = 1;
$this->meldung = PICUPLOADMAXSIZE;
}
}
private function ErrorFiles($files){
if(function_exists('exif_imagetype')) {
$detected_type = exif_imagetype($files['datei']['tmp_name']);
if(!in_array($detected_type, self::allowed_types)) {
$this->error = 1;
$this->meldung = PICUPLOADERRORFILES;
}
}
}
private function CheckExist(){
if($this->db->num_rows("SELECT id FROM ". PREFIX . CHATP ." WHERE kurz = '". $this->post['kurz'] ."' ") != 0){
$this->error = 1;
$this->meldung = CHATSMILEYKURZEXIST;
}
}
public function SmileyUpload($post,$files){
$this->make_array($post);
$this->filename = pathinfo($files['datei']['name'], PATHINFO_FILENAME);
$this->extension = strtolower(pathinfo($files['datei']['name'], PATHINFO_EXTENSION));
$this->CheckExist();
if($this->error == 0) $this->CheckDateiendung();
if($this->error == 0) $this->MaxSize($files);
if($this->error == 0) $this->ErrorFiles($files);
if($this->error == 0){
$new_path = $_SERVER['DOCUMENT_ROOT'].'/'.self::upload_folder . $this->filename .'.'.$this->extension;
move_uploaded_file($files['datei']['tmp_name'], $new_path);
$this->db->insert(PREFIX . CHATP , array("kurz" => $this->post['kurz'], "pic" => $this->filename .'.'.$this->extension));
$this->meldung = CHATSMILEYUPLOADTRUE;
}
meldung($this->error,$this->meldung);
}
public function SmileyAnsicht(){
$aus = '<div class="row" style="max-height:500px; overflow:auto">';
foreach($this->db->get_results("SELECT * FROM ". PREFIX . CHATP ." ") AS $res){
$aus .= '
<div class="col">
<form method="post" action="">
<input type="hidden" name="id" value="'. $res->id .'">
<img src="'. IMGtoBase64 ( $res->pic, 'chat' ) .'"><br>
<small>'. $res->kurz .'</small><br>
<input type="submit" name="run[SmileyDelete]" value="L&ouml;schen" class="btn btn-danger btn-sm">
</form>
</div>
';
}
$aus .= '</div>';
return $aus;
}
public function SmileyDelete($post){
$this->make_array($post);
$row = $this->db->get_row("SELECT pic FROM ". PREFIX . CHATP ." WHERE id = '". $this->post['id'] ."' ");
if($this->db->delete(PREFIX . CHATP, array("id" => $this->post['id'])) == true){
$this->meldung = SMILEYDELETETRUE;
unlink($_SERVER['DOCUMENT_ROOT'].'/images/chat/'. $row[0]);
}else{
$this->error = 1;
$this->meldung = SMILEYDELETEFALSE;
}
meldung($this->error,$this->meldung);
}
}
......@@ -2,39 +2,71 @@
$chat = Classloader('chat',true);
$chatSe = $datenbank->get_row("SELECT chat_aktiv,hintergrundfarbe,textfarbe,profillink FROM ".PREFIX . CHATSE ."",true);
head("Chat Grundeinstellungen");
echo '
<form method="post" action="">
<table class="table">
<tr>
<th>Chat Aktiv</th>
<td>
<select name="chat_aktiv" class="form-control">
<option value="1"'; if($chatSe->chat_aktiv == 1) echo'selected="selected"'; echo '>deaktiviert</option>
<option value="2"'; if ($chatSe->chat_aktiv == 2) echo'selected="selected"'; echo '>aktiviert</option>
</select>
</td>
</tr>
<tr>
<th>Hintergrundfarbe</th>
<td><input class="form-control" type="color" name="hintergrundfarbe" value="'.$chatSe->hintergrundfarbe.'"></td>
</tr>
<tr>
<th>Textfarbe</th>
<td><input class="form-control" type="color" name="textfarbe" value="'.$chatSe->textfarbe.'"></td>
</tr>
<tr>
<th>Profillinkfarbe</th>
<td><input class="form-control" type="color" name="profillink" value="'.$chatSe->profillink.'"></td>
</tr>
<tr>
<th></th>
<td><input class="btn btn-default" type="submit" name="run[chat_save]" value="Chat Einstellungen Speichern"></td>
</tr>
</table>
</form>';
?>
<div class="row">
<div class="col-6">
<div class="card">
<div class="card-header">Grundeinstellungen</div>
<div class="card-body">
<form method="post" action="">
<table class="table">
<tr>
<th>Chat Aktiv</th>
<td>
<select name="chat_aktiv" class="form-control">
<option value="1"<?php if($chatSe->chat_aktiv == 1) echo'selected="selected"';?>>deaktiviert</option>
<option value="2"<?php if ($chatSe->chat_aktiv == 2) echo'selected="selected"';?>>aktiviert</option>
</select>
</td>
</tr>
<tr>
<th>Hintergrundfarbe</th>
<td><input class="form-control" type="color" name="hintergrundfarbe" value="<?php echo $chatSe->hintergrundfarbe;?>"></td>
</tr>
<tr>
<th>Textfarbe</th>
<td><input class="form-control" type="color" name="textfarbe" value="<?php echo $chatSe->textfarbe;?>"></td>
</tr>
<tr>
<th>Profillinkfarbe</th>
<td><input class="form-control" type="color" name="profillink" value="<?php echo $chatSe->profillink;?>"></td>
</tr>
<tr>
<th></th>
<td><input class="btn btn-default" type="submit" name="run[chat_save]" value="Chat Einstellungen Speichern"></td>
</tr>
</table>
</form>
</div>
</div>
</div>
<div class="col-6">
<div class="card">
<div class="card-header">Smileyverwaltung</div>
<div class="card-body">
<form method="post" action="" enctype="multipart/form-data">
<div class="input-group mb-3">
<div class="input-group-prepend">
<span class="input-group-text" id="inputGroupFileAddon01">Upload</span>
</div>
<div class="custom-file">
<input name="datei" type="file" class="custom-file-input" id="inputGroupFile01" aria-describedby="inputGroupFileAddon01">
<label class="custom-file-label" for="inputGroupFile01">Choose file</label>
</div>
<input type="text" name="kurz" placeholder="Kurzzeichen" class="form-control" required>
<div class="input-group-append">
<input type="submit" name="run[SmileyUpload]" value="Speichern" class="btn btn-success">
</div>
</div>
</form>
<hr>
<?php echo $chat->SmileyAnsicht();?>
</div>
</div>
</div>
</div>
foot();
<?php
head("Chatverlauf");
echo $chat->Verlauf();
......
......@@ -38,6 +38,7 @@
define("FBBLACK","fb_blacklist");
define("CHATSE","chat_einstellungen");
define("CHAT","chat");
define("CHATP","chat_smiley");
define("ADMINBLACK","adminblackliste");
define("CMS","cms_seiten");
define("CRONS","crons");
......@@ -48,6 +49,7 @@
define("NEWSK","news_komment");
define("TEXTE","texte");
define("BLACKLIST","AddBlackList");
define("BETTELURLS","bettel_url_sperre");
//Passwort zusatz
define("PW_ZUSATZ","???PW???");
......
This diff is collapsed.
......@@ -9,7 +9,7 @@ require_once($_SERVER['DOCUMENT_ROOT'].'/lib/session.lib.php');
require_once($_SERVER['DOCUMENT_ROOT'].'/lib/class/chat.class.php');
$konto = Classloader('kontobuchung');
$chat = new chatClass;
$chat = Classloader('chat');
$chat->Insert($_POST);
......
<?php
require_once("class/db.class.php");
require_once("db_config.php");
$datenbank = new DB;
require_once("session.lib.php");
require_once("class/chat.class.php");
require_once($_SERVER['DOCUMENT_ROOT']."/lib/db_config.php");
require_once($_SERVER['DOCUMENT_ROOT'].'/lib/functions.lib.php');
$datenbank = Classloader('db');
$grundconfig = $datenbank->get_row("SELECT * FROM ". PREFIX . CONFIG ." ",true);
require_once($_SERVER['DOCUMENT_ROOT'].'/lib/session.lib.php');
require_once($_SERVER['DOCUMENT_ROOT'].'/lib/class/chat.class.php');
$id = intval( $_GET['lastTimeID'] );
$jsonData = chatClass::getRestChatLines($id);
print $jsonData;
$Class = Classloader('chat');
print $Class->getRestChatLines($id);
?>
<?php
class chatClass{
class chat{
private $db;
private $session = array();
private $array = array();
......@@ -9,6 +9,7 @@ class chatClass{
private $ChatSetting;
private $konto;
private $post;
private $smiley = array();
function __construct(){
global $datenbank,$_SESSION,$konto,$_POST;
......@@ -21,9 +22,18 @@ class chatClass{
$this->post[$key] = $this->db->escape($value);
}
}
foreach($this->db->get_results("SELECT * FROM ". PREFIX . CHATP ." ") AS $res){
$this->smiley[$res->kurz] = '<img src="images/chat/'. $res->pic .'" alt="'. $res->kurz .'">';
}
}
private function ChattextSmiley($text){
return strtr($text,$this->smiley);
}
public static function getRestChatLines($id){
public function getRestChatLines($id){
$arr = array();
$jsonData = '{"results":[';
$db_connection = new mysqli( DB_HOST, DB_USER, DB_PASS, DB_BASS);
......@@ -36,8 +46,9 @@ class chatClass{
while ($statement->fetch()) {
$line->id = $id;
$line->usrname = $usrname;
$line->chattext = $chattext;
$line->chattext = $this->ChattextSmiley($chattext);
$line->chattime = date('H:i:s', $chattime);
$line->userpic = IMGtoBase64($this->UserPic($usrname));
$arr[] = json_encode($line);
}
$statement->close();
......@@ -46,6 +57,17 @@ class chatClass{
$jsonData .= ']}';
return $jsonData;
}
private function UserPic($user){
$rowpic = $this->db->get_row("SELECT ava FROM ". PREFIX . USER ." WHERE nickname = '". $user ."' ");
if($rowpic[0] == ''){
$bild = 'default.png';
}else{
$bild = $rowpic[0];
}
return $bild;
}
public static function setChatLines( $chattext, $usrname, $color) {
$db_connection = new mysqli( DB_HOST, DB_USER, DB_PASS, DB_BASS);
......@@ -97,5 +119,75 @@ class chatClass{
}
meldung($this->error,$this->meldung);
}
private function Seiten(){
$aus = '<div class="btn-group" role="group" aria-label="Basic example">';
$anzahl = ceil($this->db->num_rows("SELECT id FROM ". PREFIX . CHAT ." ")/50);
for($i = 1; $i <= $anzahl; $i++){
$aus .= '<a href="?content=/chat/archiv&seite='. $i .'" class="btn btn-secondary">'. $i .'</a>';
}
$aus .= '</div>';
return $aus;
}
private function navigationsLeiste($seite,$art,$link){
$string = '';
$extVariables = '';
$SitesComplete = ceil($this->db->num_rows("SELECT id FROM ". PREFIX . CHAT ." ")/50);
$NavCeil = floor(NAV_LEISTE / 2);
if($seite > 1){
$string .= '<a class="btn btn-light" href="'. $link .'&'.$art.'=1'.$extVariables.'"><<</a>&nbsp;&nbsp;';
$string .= '<a class="btn btn-light" href="'. $link .'&'.$art.'='.($seite-1).$extVariables.'">
<</a>&nbsp;&nbsp;';
}
for($x=$seite-$NavCeil;$x<=$seite+$NavCeil;$x++){
// Alle Seitenzahlen vor und nach der aktuellen Seite verlinken
if(($x>0 && $x<$seite) || ($x>$seite && $x<=$SitesComplete))
$string .= '<a class="btn btn-light" href="'. $link .'&'.$art.'='.$x.$extVariables.'">'.$x.'</a>&nbsp;&nbsp;';
if($x==$seite)
$string .= '<button class="btn btn-primary" disabled="disabled">'.$x . '</button>';
}
if($seite < $SitesComplete){
$string .= '<a class="btn btn-light" href="'. $link .'&'.$art.'='.($seite+1).$extVariables.'">>
</a>&nbsp;&nbsp;';
$string .= '<a class="btn btn-light" href="'. $link .'&'.$art.'='.$SitesComplete.$extVariables.'">>>
</a>&nbsp;&nbsp;';
}
return $string;
}
public function Archive($seite){
$start = $seite * 50 - 50;
$aus = '<ul class="list-group">';
foreach($this->db->get_results("SELECT * FROM ". PREFIX . CHAT ." ORDER BY id DESC LIMIT $start,50") AS $res){
$aus .= '
<li class="list-group-item">
<div class="row">
<div class="col-md-2 text-left">
<img alt="'. $res->absender .'" src="'. IMGtoBase64($this->UserPic($res->absender)) .'" class="img-thumbnail rounded-circle" width="30">'. $res->absender .'<br>
<small>'. date("d.m.Y H:i", $res->time) .'</small>
</div>
<div class="col-md-10 text-left">
'. $res->nachricht .'
</div>
</div>
</li>
';
}
$aus .= '</ul><hr>';
$aus .= '<div class="text-center">'.$this->navigationsLeiste($seite,"seite","?content=/chat/archiv").'</div>';
return $aus;
}
public function Smileys(){
$aus = '';
foreach($this->db->get_results("SELECT * FROM ". PREFIX . CHATP ." ") AS $res){
$aus .= '<img src="'. IMGtoBase64($res->pic, 'chat') .'" onclick="InputValueAdd(\''. $res->kurz .'\');" class="avatar img-circle img-thumbnail" alt="avatar">';
}
return $aus;
}
}
?>
<?php
head("Archiv");
if ($_GET['seite'] == '') {$_GET['seite'] = '1';}
$start = $_GET['seite'] * 50 - 50;
$nac = db_query("SELECT * FROM ".$db_prefix."_chat ORDER BY id DESC LIMIT $start,50");
while($nachricht = mysqli_fetch_array($nac)){
$zeit = niceDate($nachricht['time']);
$user = mysqli_fetch_array(db_query("SELECT nickname FROM ".$db_prefix."_userdaten WHERE uid = '". mysqli_real_escape_string($sql_open,$nachricht['absender']) ."' "));
echo '
<div>
<a href="'.$domain.'/?content=/nickpage&nick='.$user['nickname'].'" target="_new">'.$user['nickname'].'</a>: '.$nachricht['nachricht'].'<br>
<font style="font-size:10px;">'.$zeit.'</font><br>
</div>
';
}
$seiten = db_query("SELECT id FROM " . $db_prefix . "_chat");
$menge = mysqli_num_rows($seiten);
$seitenanzahl = $menge / 50;
echo 'Seite: ';
for($a = 0; $a < $seitenanzahl; $a++) {
$b = $a + 1;
if ($_GET['seite'] == $b) {
echo '&nbsp;'.$b.'&nbsp;';
} else {
echo ' <a href="?content=/chat/archiv&seite='.$b.'">'.$b.'</a>&nbsp;';
}
}
foot();
\ No newline at end of file
head("Archiv");
if (!isset($_GET['seite'])) {$_GET['seite'] = '1';}
$Class = Classloader('chat');
echo $Class->Archive($_GET['seite']);
foot();
?>
\ No newline at end of file
<?php
$nickname = '';
if($_SESSION['login'] == 'true'){
$user = userinfo($_SESSION['uid']);
$nickname = $user->nickname;
}
?>
<script type="text/javascript">
var user = "<?php echo $nickname;?>";
var aus = '';
function ScrollDown(){
$('#flux').bind('scroll', function() {
......@@ -34,7 +42,23 @@ function getChatText(){
var html = "";
for (var i = 0; i < jsonLength; i++) {
var result = jsonData.results[i];
html += '<li class="list-group-item" style="padding:1px;"><div class="row"><div class="col-md-2 text-left">'+result.usrname+'<br><small>(' + result.chattime+ ')</small></div><div class="col-md-10 text-left">'+result.chattext+'</div></div>';
if(result.chattext.indexOf("@"+user) == -1){
if(result.chattext.indexOf("@all") == -1){
var CSSclass = '';
}else{
var CSSclass = 'list-group-item-secondary';
}
}else{
var CSSclass = 'list-group-item-secondary';
}
html += '<li class="list-group-item '+ CSSclass +'" style="padding:1px;">'+
'<div class="row">'+
'<div class="col-md-2 text-left">'+
'<span onclick="InputValueAdd(\'@'+result.usrname+'\')"><img alt="'+result.usrname+'" src="'+result.userpic+'" class="img-thumbnail rounded-circle" width="30">'+result.usrname+'</span><br>'+
'<small>(' + result.chattime+ ')</small>'+
'</div>'+
'<div class="col-md-10 text-left">'+result.chattext+'</div>'+
'</div>';
lastTimeID = result.id;
}
ScrollDown();
......@@ -55,9 +79,15 @@ setInterval(function(){
getChatText();
}, 1000);
function InputValueAdd(add){
$('#inhalt').val($('#inhalt').val()+' '+add+' ');
$('#inhalt').focus();
}
</script>
<?php
head("");
$Chat = Classloader('chat');
echo '
<center>
<br>
......@@ -70,6 +100,8 @@ echo '
</div>
<hr>
<div id="chatcontainer"></div>
'. $Chat->Smileys() .'
<hr>
<form method="post" action="js/chat.php" onsubmit="return fx_chat(this,\'#chatcontainer\');" >
<div class="input-group">
<input id="inhalt" class="form-control" name="inhalt">
......
<?php
include ('../../lib/datenbank.inc.php');
include ('../../lib/functions.lib.php');
require_once($_SERVER['DOCUMENT_ROOT'].'/lib/db_config.php');
require_once($_SERVER['DCUMENT_ROOT'].'/lib/datenbank.inc.php');
require_once($_SERVER['DOCUMENT_ROOT'].'/lib/functions.lib.php');
$daten_chat = mysqli_fetch_array(db_query("SELECT * FROM ".$db_prefix."_chat_einstellungen"));
?>
......@@ -9,6 +10,6 @@ $abfrage = db_query("SELECT nachricht,absender,time FROM ".$db_prefix."_chat ORD
while($row = mysqli_fetch_array($abfrage)){
$zeit = niceDate($row['time']);
$user = mysqli_fetch_array(db_query("SELECT nickname FROM ".$db_prefix."_userdaten WHERE uid = '". mysqli_real_escape_string($sql_open,$row['absender']) ."' "));
echo '<a href="?content=/nickpage&nick='.$user['nickname'].'">'.$user['nickname'].'</a>: '.$row['nachricht'].'<br /><i><font style="font-size:10px;">'.$zeit.'</i></font><br>';
echo '<a href="?page=/nickpage&nick='.$user['nickname'].'">'.$user['nickname'].'</a>: '.$row['nachricht'].'<br /><i><font style="font-size:10px;">'.$zeit.'</i></font><br>';
}
?>
\ No newline at end of file
?>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment