Skip to content

Commit

Permalink
ðŸŽĻ clean up code formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
popiazaza committed Mar 7, 2023
1 parent 9cb2ea5 commit b457a55
Show file tree
Hide file tree
Showing 15 changed files with 791 additions and 674 deletions.
25 changes: 15 additions & 10 deletions addon/block_thchat.php
Original file line number Diff line number Diff line change
@@ -1,26 +1,31 @@
<?php

if(!defined('IN_DISCUZ')) {
if (!defined('IN_DISCUZ')) {
exit('Access Denied');
}

require_once libfile('commonblock_html', 'class/block/html');

class block_thchat extends commonblock_html {
class block_thchat extends commonblock_html
{

function name() {
function name()
{
return '2th Chat';
}

function block_forumtree() {}
function getsetting() {}

function getdata($style, $parameter) {
function block_forumtree()
{
}
function getsetting()
{
}

function getdata($style, $parameter)
{
global $_G;
include DISCUZ_ROOT. './source/plugin/th_chat/include.php';
include DISCUZ_ROOT . './source/plugin/th_chat/include.php';
include template('th_chat:discuz');
return array('html' => $return, 'data' => null);
}
}

?>
5 changes: 3 additions & 2 deletions th_chat/chat_full.inc.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php
if(!defined('IN_DISCUZ')) { exit('Access Denied'); }
if (!defined('IN_DISCUZ')) {
exit('Access Denied');
}
include 'include.php';
include template('th_chat:big');
?>
99 changes: 51 additions & 48 deletions th_chat/functions.php
Original file line number Diff line number Diff line change
@@ -1,95 +1,98 @@
<?php
function getat($attextn){
function getat($attextn)
{
global $config;
if(preg_match_all('/@(.*?)(\s|\z)/',$attextn,$atmatch)) {
foreach ($atmatch[1] as $atvalue) {
$atuser = DB::fetch_first("SELECT m.uid,m.groupid,g.color FROM ".DB::table('common_member')." m LEFT JOIN ".DB::table('common_usergroup')." g ON m.groupid=g.groupid WHERE m.username='{$atvalue}' LIMIT 1");
if($atuser){
$attext = addslashes('<a class="nzuserat nzat_'.$atuser['uid'].'" onclick="nzAt(\''.($atvalue).'\');"'.($atuser['color']?' style="color:'.$atuser['color'].'"':'').'>@'.stripslashes($atvalue).'</a> ');
}else{
$attext = '@'.$atvalue;
if (preg_match_all('/@(.*?)(\s|\z)/', $attextn, $atmatch)) {
foreach ($atmatch[1] as $atvalue) {
$atuser = DB::fetch_first("SELECT m.uid,m.groupid,g.color FROM " . DB::table('common_member') . " m LEFT JOIN " . DB::table('common_usergroup') . " g ON m.groupid=g.groupid WHERE m.username='{$atvalue}' LIMIT 1");
if ($atuser) {
$attext = addslashes('<a class="nzuserat nzat_' . $atuser['uid'] . '" onclick="nzAt(\'' . ($atvalue) . '\');"' . ($atuser['color'] ? ' style="color:' . $atuser['color'] . '"' : '') . '>@' . stripslashes($atvalue) . '</a> ');
} else {
$attext = '@' . $atvalue;
}
$attextn = str_replace("@".$atvalue,$attext,$attextn);
}
$attextn = str_replace("@" . $atvalue, $attext, $attextn);
}
}
return $attextn;
}
function getat2($uid){
function getat2($uid)
{
global $config;
$atuser = DB::fetch_first("SELECT m.uid,m.username,m.groupid,g.color FROM ".DB::table('common_member')." m LEFT JOIN ".DB::table('common_usergroup')." g ON m.groupid=g.groupid WHERE m.uid='{$uid}' LIMIT 1");
$attext = '<a class="nzuserat2 nzat_'.$atuser['uid'].'" onclick="showWindow(\'th_chat_profile\', \'plugin.php?id=th_chat:profile&uid='.$uid.'\');return false;"'.($atuser['color']?' style="color:'.$atuser['color'].'"':'').'>'.$atuser['username'].'</a>';
$atuser = DB::fetch_first("SELECT m.uid,m.username,m.groupid,g.color FROM " . DB::table('common_member') . " m LEFT JOIN " . DB::table('common_usergroup') . " g ON m.groupid=g.groupid WHERE m.uid='{$uid}' LIMIT 1");
$attext = '<a class="nzuserat2 nzat_' . $atuser['uid'] . '" onclick="showWindow(\'th_chat_profile\', \'plugin.php?id=th_chat:profile&uid=' . $uid . '\');return false;"' . ($atuser['color'] ? ' style="color:' . $atuser['color'] . '"' : '') . '>' . $atuser['username'] . '</a>';
return $attext;
}
function getat3($uid){
function getat3($uid)
{
global $config;
$atuser = DB::fetch_first("SELECT m.uid,m.username,m.groupid,g.color FROM ".DB::table('common_member')." m LEFT JOIN ".DB::table('common_usergroup')." g ON m.groupid=g.groupid WHERE m.uid='{$uid}' LIMIT 1");
$attext = '<a class="nzuserat nzat_'.$atuser['uid'].'" onclick="nzAt(\''.addslashes($atuser['username']).'\');"'.($atuser['color']?' style="color:'.$atuser['color'].'"':'').'>'.$atuser['username'].'</a>';
$atuser = DB::fetch_first("SELECT m.uid,m.username,m.groupid,g.color FROM " . DB::table('common_member') . " m LEFT JOIN " . DB::table('common_usergroup') . " g ON m.groupid=g.groupid WHERE m.uid='{$uid}' LIMIT 1");
$attext = '<a class="nzuserat nzat_' . $atuser['uid'] . '" onclick="nzAt(\'' . addslashes($atuser['username']) . '\');"' . ($atuser['color'] ? ' style="color:' . $atuser['color'] . '"' : '') . '>' . $atuser['username'] . '</a>';
return $attext;
}
function getquota($quota){
function getquota($quota)
{
global $config;
if($quo = DB::query("SELECT uid,text FROM ".DB::table('newz_data')." WHERE id='".$quota."'"))
{
if ($quo = DB::query("SELECT uid,text FROM " . DB::table('newz_data') . " WHERE id='" . $quota . "'")) {
$quo = DB::fetch($quo);
$quo['text'] = preg_replace('/\[quota\](.*?)\[\/quota\]/', '', $quo['text']);
$attext = getat3($quo['uid']);
$text = '[quota]'.addslashes('<div class="nzblockquote">'.$attext.': '.$quo['text'].'</div>').'[/quota]';
$text = '[quota]' . addslashes('<div class="nzblockquote">' . $attext . ': ' . $quo['text'] . '</div>') . '[/quota]';
}
return $text;
}
function chatrow($id,$text,$uid_p,$username,$time,$touid,$icon,$mod){
global $uid,$config,$_G;
function chatrow($id, $text, $uid_p, $username, $time, $touid, $icon, $mod)
{
global $uid, $config, $_G;
$tag = '';
if($icon=='alert'){
if ($icon == 'alert') {
$tag = '<span class="nztag" style="background:#e53935">āđāļˆāđ‰āļ‡āđ€āļ•āļ·āļ­āļ™</span>';
}elseif($icon=='bot'){
} elseif ($icon == 'bot') {
$tag = '<span class="nztag" style="background:#546E7A">āļ­āļąāļ•āđ‚āļ™āļĄāļąāļ•āļī</span>';
}
if($uid_p == $_G['uid']){
return '<div class="nzchatrow" id="nzrows_'.$id.'" onMouseOver="nzchatobj(\'#nzchatquota'.$id.'\').css(\'opacity\',\'1\');" onMouseOut="nzchatobj(\'#nzchatquota'.$id.'\').css(\'opacity\',\'0\');">
if ($uid_p == $_G['uid']) {
return '<div class="nzchatrow" id="nzrows_' . $id . '" onMouseOver="nzchatobj(\'#nzchatquota' . $id . '\').css(\'opacity\',\'1\');" onMouseOut="nzchatobj(\'#nzchatquota' . $id . '\').css(\'opacity\',\'0\');">
<div></div>
<div class="nzcontentt nzme">
<div class="nzchatimenu">
<span id="nzchatquota'.$id.'" class="nzcq"><a href="javascript:void(0);" onClick="nzQuota('.$id.')">āļ­āđ‰āļēāļ‡āļ­āļīāļ‡</a> '.(($config['editmsg']==1)&&$mod||($config['editmsg']==2)&&$mod||(($config['editmsg']==3))?' <a href="javascript:;" onClick=\'nzCommand("edit","'.$id.'");\'>āđāļāđ‰āđ„āļ‚</a>':'').($mod?' <a href="javascript:;" onClick=\'nzCommand("del","'.$id.'");\'>āļĨāļš</a>':'').'</span>
<span id="nzchatquota' . $id . '" class="nzcq"><a href="javascript:void(0);" onClick="nzQuota(' . $id . ')">āļ­āđ‰āļēāļ‡āļ­āļīāļ‡</a> ' . (($config['editmsg'] == 1) && $mod || ($config['editmsg'] == 2) && $mod || (($config['editmsg'] == 3)) ? ' <a href="javascript:;" onClick=\'nzCommand("edit","' . $id . '");\'>āđāļāđ‰āđ„āļ‚</a>' : '') . ($mod ? ' <a href="javascript:;" onClick=\'nzCommand("del","' . $id . '");\'>āļĨāļš</a>' : '') . '</span>
<br>
<span class="nztime" title="'.date("c",$time).'">'.get_date($time).'</span>
<span class="nztime" title="' . date("c", $time) . '">' . get_date($time) . '</span>
</div>
<div class="nzinnercontent">'.$tag.$text.'</div>
<div class="nzinnercontent">' . $tag . $text . '</div>
</div>
</div>
<script>nzchatobj("#nzrows_'.$id.' span.nztime").timeago();</script>';
}else{
return '<div class="nzchatrow" id="nzrows_'.$id.'" onMouseOver="nzchatobj(\'#nzchatquota'.$id.'\').css(\'opacity\',\'1\');" onMouseOut="nzchatobj(\'#nzchatquota'.$id.'\').css(\'opacity\',\'0\');">
<script>nzchatobj("#nzrows_' . $id . ' span.nztime").timeago();</script>';
} else {
return '<div class="nzchatrow" id="nzrows_' . $id . '" onMouseOver="nzchatobj(\'#nzchatquota' . $id . '\').css(\'opacity\',\'1\');" onMouseOut="nzchatobj(\'#nzchatquota' . $id . '\').css(\'opacity\',\'0\');">
<div class="nzavatart">
<a href="javascript:void(0);" onclick="showWindow(\'th_chat_profile\', \'plugin.php?id=th_chat:profile&uid='.$uid_p.'\');return false;"><img src="'.avatar($uid_p,'small',1).'" title="'.$username.'" class="nzchatavatar" onError="this.src=\'uc_server/images/noavatar_small.gif\';" /></a>
<a href="javascript:void(0);" onclick="showWindow(\'th_chat_profile\', \'plugin.php?id=th_chat:profile&uid=' . $uid_p . '\');return false;"><img src="' . avatar($uid_p, 'small', 1) . '" title="' . $username . '" class="nzchatavatar" onError="this.src=\'uc_server/images/noavatar_small.gif\';" /></a>
</div>
<div class="nzcontentt">
'.getat2($uid_p).'
' . getat2($uid_p) . '
<br>
<div style="display:flex;align-items:flex-end;">
<div class="nzinnercontent">'.$tag.$text.'</div>
<div class="nzinnercontent">' . $tag . $text . '</div>
<div class="nzchatimenu">
<span id="nzchatquota'.$id.'" class="nzcq"><a href="javascript:void(0);" onClick="nzQuota('.$id.')">āļ­āđ‰āļēāļ‡āļ­āļīāļ‡</a> <a href="javascript:void(0);" onclick="nzAt(\''.addslashes($username).'\')">@</a> <a href="javascript:void(0);" onclick="nzTouid('.$uid_p.')">āđāļŠāļ—āļŠāđˆāļ§āļ™āļ•āļąāļ§</a> '.(($config['editmsg']==1)&&$mod?' <a href="javascript:;" onClick=\'nzCommand("edit","'.$id.'");\'>āđāļāđ‰āđ„āļ‚</a>':'').($mod?' <a href="javascript:;" onClick=\'nzCommand("del","'.$id.'");\'>āļĨāļš</a>':'').'</span>
<span id="nzchatquota' . $id . '" class="nzcq"><a href="javascript:void(0);" onClick="nzQuota(' . $id . ')">āļ­āđ‰āļēāļ‡āļ­āļīāļ‡</a> <a href="javascript:void(0);" onclick="nzAt(\'' . addslashes($username) . '\')">@</a> <a href="javascript:void(0);" onclick="nzTouid(' . $uid_p . ')">āđāļŠāļ—āļŠāđˆāļ§āļ™āļ•āļąāļ§</a> ' . (($config['editmsg'] == 1) && $mod ? ' <a href="javascript:;" onClick=\'nzCommand("edit","' . $id . '");\'>āđāļāđ‰āđ„āļ‚</a>' : '') . ($mod ? ' <a href="javascript:;" onClick=\'nzCommand("del","' . $id . '");\'>āļĨāļš</a>' : '') . '</span>
<br>
<span class="nztime" title="'.date("c",$time).'">'.get_date($time).'</span>
<span class="nztime" title="' . date("c", $time) . '">' . get_date($time) . '</span>
</div>
</div>
</div>
</div>
<script>nzchatobj("#nzrows_'.$id.' span.nztime").timeago();</script>';
<script>nzchatobj("#nzrows_' . $id . ' span.nztime").timeago();</script>';
}
}
function get_date($timestamp)
function get_date($timestamp)
{
$strYear = substr(date("Y",$timestamp)+543,2,2);
$strMonth= date("n",$timestamp);
$strDay= date("j",$timestamp);
$strHour= date("H",$timestamp);
$strMinute= date("i",$timestamp);
$strSeconds= date("s",$timestamp);
$strMonthCut = array("","āļĄ.āļ„.","āļ.āļž.","āļĄāļĩ.āļ„.","āđ€āļĄ.āļĒ.","āļž.āļ„.","āļĄāļī.āļĒ.","āļ.āļ„.","āļŠ.āļ„.","āļ.āļĒ.","āļ•.āļ„.","āļž.āļĒ.","āļ˜.āļ„.");
$strMonthThai=$strMonthCut[$strMonth];
$strYear = substr(date("Y", $timestamp) + 543, 2, 2);
$strMonth = date("n", $timestamp);
$strDay = date("j", $timestamp);
$strHour = date("H", $timestamp);
$strMinute = date("i", $timestamp);
$strSeconds = date("s", $timestamp);
$strMonthCut = array("", "āļĄ.āļ„.", "āļ.āļž.", "āļĄāļĩ.āļ„.", "āđ€āļĄ.āļĒ.", "āļž.āļ„.", "āļĄāļī.āļĒ.", "āļ.āļ„.", "āļŠ.āļ„.", "āļ.āļĒ.", "āļ•.āļ„.", "āļž.āļĒ.", "āļ˜.āļ„.");
$strMonthThai = $strMonthCut[$strMonth];
return "$strDay $strMonthThai $strYear $strHour:$strMinute āļ™.";
}
$time = TIMESTAMP;
?>
54 changes: 28 additions & 26 deletions th_chat/img.inc.php
Original file line number Diff line number Diff line change
@@ -1,56 +1,58 @@
<?php
if (!defined('IN_DISCUZ')) {exit('Access Denied');}
if (!defined('IN_DISCUZ')) {
exit('Access Denied');
}
loadcache('plugin');
$config = $_G['cache']['plugin']['th_chat'];
if ($_G['uid'] < 1) {
die('Login');
die('Login');
}
$maximgsize = 0;
if(!empty($_G['group']['maxattachsize'])) {
if (!empty($_G['group']['maxattachsize'])) {
$maximgsize = intval($_G['group']['maxattachsize']);
} else {
$maximgsize = @ini_get(upload_max_filesize);
$unit = strtolower(substr($maximgsize, -1, 1));
$maximgsize = intval($maximgsize);
if($unit == 'k') {
$maximgsize = $maximgsize*1024;
} elseif($unit == 'm') {
$maximgsize = $maximgsize*1024*1024;
} elseif($unit == 'g') {
$maximgsize = $maximgsize*1024*1024*1024;
if ($unit == 'k') {
$maximgsize = $maximgsize * 1024;
} elseif ($unit == 'm') {
$maximgsize = $maximgsize * 1024 * 1024;
} elseif ($unit == 'g') {
$maximgsize = $maximgsize * 1024 * 1024 * 1024;
}
}
$todayimgcount = 0;
$todayimgsize = 0;
foreach (glob(__DIR__ . '/img_up/' . $_G['uid'] . '_'.date('Ymd',TIMESTAMP).'*') as $filename) {
foreach (glob(__DIR__ . '/img_up/' . $_G['uid'] . '_' . date('Ymd', TIMESTAMP) . '*') as $filename) {
$todayimgcount++;
$todayimgsize += filesize($filename);
}
if($_G['group']['maxattachnum']) {
if($todayimgcount >= $_G['group']['maxattachnum']){
if ($_G['group']['maxattachnum']) {
if ($todayimgcount >= $_G['group']['maxattachnum']) {
header('Content-Type: application/json');
echo json_encode(array('error' => 'āļ‚āļ­āļ­āļ āļąāļĒ āļāļĨāļļāđˆāļĄāļŠāļĄāļēāļŠāļīāļāļ‚āļ­āļ‡āļ„āļļāļ“āļ­āļąāļ›āđ‚āļŦāļĨāļ”āļ āļēāļžāđ€āļžāļĩāļĒāļ‡āļ§āļąāļ™āļĨāļ° '.$_G['group']['maxattachnum'].' āļ āļēāļžāđ€āļ—āđˆāļēāļ™āļąāđ‰āļ™'));
exit();
echo json_encode(array('error' => 'āļ‚āļ­āļ­āļ āļąāļĒ āļāļĨāļļāđˆāļĄāļŠāļĄāļēāļŠāļīāļāļ‚āļ­āļ‡āļ„āļļāļ“āļ­āļąāļ›āđ‚āļŦāļĨāļ”āļ āļēāļžāđ€āļžāļĩāļĒāļ‡āļ§āļąāļ™āļĨāļ° ' . $_G['group']['maxattachnum'] . ' āļ āļēāļžāđ€āļ—āđˆāļēāļ™āļąāđ‰āļ™'));
exit();
}
}
if($_G['group']['maxsizeperday']) {
if($todayimgsize >= $_G['group']['maxsizeperday']){
if ($_G['group']['maxsizeperday']) {
if ($todayimgsize >= $_G['group']['maxsizeperday']) {
header('Content-Type: application/json');
echo json_encode(array('error' => 'āļ‚āļ­āļ­āļ āļąāļĒ āļāļĨāļļāđˆāļĄāļŠāļĄāļēāļŠāļīāļāļ‚āļ­āļ‡āļ„āļļāļ“āļ­āļąāļ›āđ‚āļŦāļĨāļ”āļ āļēāļžāđ€āļžāļĩāļĒāļ‡āļ§āļąāļ™āļĨāļ° '.$_G['group']['maxsizeperday'].' Kb āđ€āļ—āđˆāļēāļ™āļąāđ‰āļ™'));
exit();
echo json_encode(array('error' => 'āļ‚āļ­āļ­āļ āļąāļĒ āļāļĨāļļāđˆāļĄāļŠāļĄāļēāļŠāļīāļāļ‚āļ­āļ‡āļ„āļļāļ“āļ­āļąāļ›āđ‚āļŦāļĨāļ”āļ āļēāļžāđ€āļžāļĩāļĒāļ‡āļ§āļąāļ™āļĨāļ° ' . $_G['group']['maxsizeperday'] . ' Kb āđ€āļ—āđˆāļēāļ™āļąāđ‰āļ™'));
exit();
}
}
require_once "bulletproof.php";
$image = new Bulletproof\Image($_FILES);
$image->setSize(1, $maximgsize);
$image->setLocation(__DIR__ . "/img_up");
$image->setName($_G['uid'] . '_' . date('YmdHis',TIMESTAMP));
$image->setName($_G['uid'] . '_' . date('YmdHis', TIMESTAMP));
if ($image["pictures"]) {
$upload = $image->upload();
header('Content-Type: application/json');
if ($upload) {
echo json_encode(array('url' => $_G['siteurl'] . 'source/plugin/th_chat/img_up/' . $image->getName() . '.' . $image->getMime()));
} else {
echo json_encode(array('error' => $image->getError()));
}
$upload = $image->upload();
header('Content-Type: application/json');
if ($upload) {
echo json_encode(array('url' => $_G['siteurl'] . 'source/plugin/th_chat/img_up/' . $image->getName() . '.' . $image->getMime()));
} else {
echo json_encode(array('error' => $image->getError()));
}
}
Loading

0 comments on commit b457a55

Please sign in to comment.