chat improved

This commit is contained in:
Dro1d.Ru 2019-07-12 22:21:00 +05:00
parent 1fa376d6fd
commit 0402b40a5f
17 changed files with 153 additions and 72 deletions

View file

@ -37,6 +37,12 @@
font-style: italic;
margin-bottom: 0;
}
.widget-chat-wrapper .widget-chat-messages .chat-message-date {
margin-left: 60px;
font-style: italic;
margin-bottom: 0;
font-size: 80%;
}
.widget-chat-wrapper .widget-chat-messages::-webkit-scrollbar {
width: 10px;
background-color: transparent;
@ -59,4 +65,9 @@
}
.widget-chat-wrapper .widget-chat-messages::-webkit-resizer {
background-color: rgba(0,0,0,.1);
}
.widget-chat-wrapper .chat-info {
margin: 0;
border-radius: 0;
padding: 10px;
}

View file

@ -63,6 +63,9 @@ class Index extends Zira\Controller {
$message .= Zira\Helper::tag_open('p', array('class'=>'chat-message-text parse-content'.$mclass)).$micon;
$message .= Zira\Content\Parse::bbcode(Zira\Helper::nl2br(Zira\Helper::html($row->content)));
$message .= Zira\Helper::tag_close('p');
$message .= Zira\Helper::tag_open('div', array('class'=>'chat-message-date'));
$message .= Zira\Helper::tag('span', null, array('class'=>'glyphicon glyphicon-time')).' '.(Zira\Helper::isCurrentDay(strtotime($row->date_created)) ? date('H:i', strtotime($row->date_created)) : date(Zira\Config::get('date_format'), strtotime($row->date_created)));
$message .= Zira\Helper::tag_close('div');
$message .= Zira\Helper::tag_close('div');
$response['messages'][]=$message;
$response['last_id'] = $row->id;

View file

@ -42,6 +42,7 @@ class Chat extends Form
$html .= $this->selectDropdown(Locale::t('Widget placeholder').'*','placeholder',$placeholders);
}
$html .= $this->input(Locale::t('Title').'*', 'title');
$html .= $this->textarea(Locale::tm('Information message', 'chat'), 'info', array('rows'=>4));
$html .= $this->selectDropdown(Locale::tm('Visibility', 'chat'), 'visible_group', array_merge(array('0'=>Locale::tm('Visible for everybody', 'chat')), Zira\Models\Group::getArray()));
$html .= $this->input(Locale::tm('Refresh timeout', 'chat').' ('.Locale::tm('sec.', 'chat').')'.'*', 'refresh_delay', array('placeholder'=>Locale::tm('in seconds', 'chat')));
$html .= $this->checkbox(Locale::tm('Check authentication', 'chat'), 'check_auth', null, false);
@ -57,6 +58,10 @@ class Chat extends Form
$validator->registerNoTags('title', Locale::t('Invalid value "%s"',Locale::t('Title')));
$validator->registerUtf8('title', Locale::t('Invalid value "%s"',Locale::t('Title')));
$validator->registerText('info', null, false, Locale::t('Invalid value "%s"',Locale::tm('Information message', 'chat')));
$validator->registerNoTags('info', Locale::t('Invalid value "%s"',Locale::tm('Information message', 'chat')));
$validator->registerUtf8('info', Locale::t('Invalid value "%s"',Locale::tm('Information message', 'chat')));
$validator->registerNumber('refresh_delay', 1, null, true, Locale::t('Invalid value "%s"',Locale::tm('Refresh timeout', 'chat')));
$validator->registerCustom(array(get_class(), 'checkGroup'), 'visible_group', Locale::t('Invalid value "%s"',Locale::tm('Visibility', 'chat')));

View file

@ -35,6 +35,7 @@ class Settings extends Form
protected function _render()
{
$html = $this->open();
$html .= $this->input(Locale::tm('Message retention period (in days)', 'chat').'*', 'chat_trash_time');
$html .= $this->checkbox(Locale::t('Always show CAPTCHA'), 'chat_captcha', null, false);
$html .= $this->checkbox(Locale::t('Always show CAPTCHA for authorized users'), 'chat_captcha_users', null, false);
$html .= $this->close();
@ -45,6 +46,6 @@ class Settings extends Form
{
$validator = $this->getValidator();
$validator->registerNumber('chat_trash_time',0,null,true,Locale::t('Invalid value "%s"',Locale::tm('Message retention period (in days)', 'chat')));
}
}

View file

@ -21,6 +21,7 @@ class Chat extends Table {
return array(
'id' => Field::primary(),
'title' => Field::string(true),
'info' => Field::text(),
'check_auth' => Field::int(true, true, 0),
'visible_group' => Field::int(true, true, 0),
'refresh_delay' => Field::int(true, true, 0),

View file

@ -27,7 +27,14 @@ class Chats extends Dash\Models\Model {
} else {
$chat = new Chat\Models\Chat();
}
$info = $form->getValue('info');
$info = str_replace("\r",'',$info);
$info = str_replace("\n","\r\n",$info);
$info = Zira\Helper::utf8Entity(html_entity_decode($info));
$chat->title = $form->getValue('title');
$chat->info = $info;
$chat->visible_group = (int)$form->getValue('visible_group');
$refresh_delay = (int)$form->getValue('refresh_delay');
$chat->refresh_delay = $refresh_delay ? $refresh_delay : Chat\Chat::DEFAULT_DELAY;

View file

@ -61,9 +61,12 @@ class Message extends Orm {
}
public static function cleanUp() {
$trash_days = intval(Zira\Config::get('chat_trash_time', floor(\Chat\Chat::TRASH_TIME / 86400)));
if ($trash_days <= 0) return;
$trash_time = $trash_days * 86400;
self::getCollection()
->delete()
->where('date_created','<',date('Y-m-d H:i:s', time()-\Chat\Chat::TRASH_TIME))
->where('date_created','<',date('Y-m-d H:i:s', time()-$trash_time))
->execute();
}
}

View file

@ -21,6 +21,7 @@ class Settings extends Dash\Models\Model {
$form = new Chat\Forms\Settings();
if ($form->isValid()) {
$options = array(
'chat_trash_time'=>'int',
'chat_captcha'=>'int',
'chat_captcha_users'=>'int'
);

View file

@ -44,6 +44,7 @@ class Settings extends Dash\Windows\Window {
$configs = Zira\Config::getArray();
$form = new \Chat\Forms\Settings();
if (!array_key_exists('chat_trash_time', $configs)) $configs['chat_trash_time'] = floor(\Chat\Chat::TRASH_TIME / 86400);
if (!array_key_exists('chat_captcha', $configs)) $configs['chat_captcha'] = 1;
if (!array_key_exists('chat_captcha_users', $configs)) $configs['chat_captcha_users'] = 1;
$form->setValues($configs);

View file

@ -25,5 +25,7 @@ return array(
'Incorrect message length' => 'Некорректная длина сообщения',
'Chat database cleaned up' => 'База чата почищена',
'Your message' => 'Ваше сообщение',
'Chat settings' => 'Настройки чата'
'Chat settings' => 'Настройки чата',
'Information message' => 'Информационное сообщение',
'Message retention period (in days)' => 'Срок хранения сообщений (в днях)'
);

View file

@ -1,34 +1,34 @@
/* cyrillic-ext */
@font-face {
font-family: 'Roboto';
font-style: normal;
font-weight: 400;
src: local('Roboto'), local('Roboto-Regular'), url(https://fonts.gstatic.com/s/roboto/v15/ek4gzZ-GeXAPcSbHtCeQI_esZW2xOQ-xsNqO47m55DA.woff2) format('woff2');
unicode-range: U+0460-052F, U+20B4, U+2DE0-2DFF, U+A640-A69F;
font-family: 'Roboto';
font-style: normal;
font-weight: 400;
src: local('Roboto'), local('Roboto-Regular'), url(https://fonts.gstatic.com/s/roboto/v15/ek4gzZ-GeXAPcSbHtCeQI_esZW2xOQ-xsNqO47m55DA.woff2) format('woff2');
unicode-range: U+0460-052F, U+20B4, U+2DE0-2DFF, U+A640-A69F;
}
/* cyrillic */
@font-face {
font-family: 'Roboto';
font-style: normal;
font-weight: 400;
src: local('Roboto'), local('Roboto-Regular'), url(https://fonts.gstatic.com/s/roboto/v15/mErvLBYg_cXG3rLvUsKT_fesZW2xOQ-xsNqO47m55DA.woff2) format('woff2');
unicode-range: U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
font-family: 'Roboto';
font-style: normal;
font-weight: 400;
src: local('Roboto'), local('Roboto-Regular'), url(https://fonts.gstatic.com/s/roboto/v15/mErvLBYg_cXG3rLvUsKT_fesZW2xOQ-xsNqO47m55DA.woff2) format('woff2');
unicode-range: U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}
/* latin-ext */
@font-face {
font-family: 'Roboto';
font-style: normal;
font-weight: 400;
src: local('Roboto'), local('Roboto-Regular'), url(https://fonts.gstatic.com/s/roboto/v15/Fcx7Wwv8OzT71A3E1XOAjvesZW2xOQ-xsNqO47m55DA.woff2) format('woff2');
unicode-range: U+0100-024F, U+1E00-1EFF, U+20A0-20AB, U+20AD-20CF, U+2C60-2C7F, U+A720-A7FF;
font-family: 'Roboto';
font-style: normal;
font-weight: 400;
src: local('Roboto'), local('Roboto-Regular'), url(https://fonts.gstatic.com/s/roboto/v15/Fcx7Wwv8OzT71A3E1XOAjvesZW2xOQ-xsNqO47m55DA.woff2) format('woff2');
unicode-range: U+0100-024F, U+1E00-1EFF, U+20A0-20AB, U+20AD-20CF, U+2C60-2C7F, U+A720-A7FF;
}
/* latin */
@font-face {
font-family: 'Roboto';
font-style: normal;
font-weight: 400;
src: local('Roboto'), local('Roboto-Regular'), url(https://fonts.gstatic.com/s/roboto/v15/CWB0XYA8bzo0kSThX0UTuA.woff2) format('woff2');
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2212, U+2215;
font-family: 'Roboto';
font-style: normal;
font-weight: 400;
src: local('Roboto'), local('Roboto-Regular'), url(https://fonts.gstatic.com/s/roboto/v15/CWB0XYA8bzo0kSThX0UTuA.woff2) format('woff2');
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2212, U+2215;
}
/*@font-face {
font-family: 'Roboto';

View file

@ -1,34 +1,34 @@
/* cyrillic-ext */
@font-face {
font-family: 'Roboto';
font-style: normal;
font-weight: 400;
src: local('Roboto'), local('Roboto-Regular'), url(https://fonts.gstatic.com/s/roboto/v15/ek4gzZ-GeXAPcSbHtCeQI_esZW2xOQ-xsNqO47m55DA.woff2) format('woff2');
unicode-range: U+0460-052F, U+20B4, U+2DE0-2DFF, U+A640-A69F;
font-family: 'Roboto';
font-style: normal;
font-weight: 400;
src: local('Roboto'), local('Roboto-Regular'), url(https://fonts.gstatic.com/s/roboto/v15/ek4gzZ-GeXAPcSbHtCeQI_esZW2xOQ-xsNqO47m55DA.woff2) format('woff2');
unicode-range: U+0460-052F, U+20B4, U+2DE0-2DFF, U+A640-A69F;
}
/* cyrillic */
@font-face {
font-family: 'Roboto';
font-style: normal;
font-weight: 400;
src: local('Roboto'), local('Roboto-Regular'), url(https://fonts.gstatic.com/s/roboto/v15/mErvLBYg_cXG3rLvUsKT_fesZW2xOQ-xsNqO47m55DA.woff2) format('woff2');
unicode-range: U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
font-family: 'Roboto';
font-style: normal;
font-weight: 400;
src: local('Roboto'), local('Roboto-Regular'), url(https://fonts.gstatic.com/s/roboto/v15/mErvLBYg_cXG3rLvUsKT_fesZW2xOQ-xsNqO47m55DA.woff2) format('woff2');
unicode-range: U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}
/* latin-ext */
@font-face {
font-family: 'Roboto';
font-style: normal;
font-weight: 400;
src: local('Roboto'), local('Roboto-Regular'), url(https://fonts.gstatic.com/s/roboto/v15/Fcx7Wwv8OzT71A3E1XOAjvesZW2xOQ-xsNqO47m55DA.woff2) format('woff2');
unicode-range: U+0100-024F, U+1E00-1EFF, U+20A0-20AB, U+20AD-20CF, U+2C60-2C7F, U+A720-A7FF;
font-family: 'Roboto';
font-style: normal;
font-weight: 400;
src: local('Roboto'), local('Roboto-Regular'), url(https://fonts.gstatic.com/s/roboto/v15/Fcx7Wwv8OzT71A3E1XOAjvesZW2xOQ-xsNqO47m55DA.woff2) format('woff2');
unicode-range: U+0100-024F, U+1E00-1EFF, U+20A0-20AB, U+20AD-20CF, U+2C60-2C7F, U+A720-A7FF;
}
/* latin */
@font-face {
font-family: 'Roboto';
font-style: normal;
font-weight: 400;
src: local('Roboto'), local('Roboto-Regular'), url(https://fonts.gstatic.com/s/roboto/v15/CWB0XYA8bzo0kSThX0UTuA.woff2) format('woff2');
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2212, U+2215;
font-family: 'Roboto';
font-style: normal;
font-weight: 400;
src: local('Roboto'), local('Roboto-Regular'), url(https://fonts.gstatic.com/s/roboto/v15/CWB0XYA8bzo0kSThX0UTuA.woff2) format('woff2');
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2212, U+2215;
}
/*@font-face {
font-family: 'Roboto';
@ -2289,6 +2289,14 @@ ul.vote-results li .vote-result {
background: #646975;
box-shadow: 0px 0px 4px #444554 inset;
}
/** chat **/
.widget-chat-wrapper .chat-info {
margin: 4px -9px 0px -9px;
border-radius: 3px;
}
.widget-chat-wrapper .widget-chat-messages {
margin: 8px 0px;
}
.zira-autocomplete-wnd {
background: #646975;
border: 1px solid #4d515a;

View file

@ -1,34 +1,34 @@
/* cyrillic-ext */
@font-face {
font-family: 'Roboto';
font-style: normal;
font-weight: 400;
src: local('Roboto'), local('Roboto-Regular'), url(https://fonts.gstatic.com/s/roboto/v15/ek4gzZ-GeXAPcSbHtCeQI_esZW2xOQ-xsNqO47m55DA.woff2) format('woff2');
unicode-range: U+0460-052F, U+20B4, U+2DE0-2DFF, U+A640-A69F;
font-family: 'Roboto';
font-style: normal;
font-weight: 400;
src: local('Roboto'), local('Roboto-Regular'), url(https://fonts.gstatic.com/s/roboto/v15/ek4gzZ-GeXAPcSbHtCeQI_esZW2xOQ-xsNqO47m55DA.woff2) format('woff2');
unicode-range: U+0460-052F, U+20B4, U+2DE0-2DFF, U+A640-A69F;
}
/* cyrillic */
@font-face {
font-family: 'Roboto';
font-style: normal;
font-weight: 400;
src: local('Roboto'), local('Roboto-Regular'), url(https://fonts.gstatic.com/s/roboto/v15/mErvLBYg_cXG3rLvUsKT_fesZW2xOQ-xsNqO47m55DA.woff2) format('woff2');
unicode-range: U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
font-family: 'Roboto';
font-style: normal;
font-weight: 400;
src: local('Roboto'), local('Roboto-Regular'), url(https://fonts.gstatic.com/s/roboto/v15/mErvLBYg_cXG3rLvUsKT_fesZW2xOQ-xsNqO47m55DA.woff2) format('woff2');
unicode-range: U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}
/* latin-ext */
@font-face {
font-family: 'Roboto';
font-style: normal;
font-weight: 400;
src: local('Roboto'), local('Roboto-Regular'), url(https://fonts.gstatic.com/s/roboto/v15/Fcx7Wwv8OzT71A3E1XOAjvesZW2xOQ-xsNqO47m55DA.woff2) format('woff2');
unicode-range: U+0100-024F, U+1E00-1EFF, U+20A0-20AB, U+20AD-20CF, U+2C60-2C7F, U+A720-A7FF;
font-family: 'Roboto';
font-style: normal;
font-weight: 400;
src: local('Roboto'), local('Roboto-Regular'), url(https://fonts.gstatic.com/s/roboto/v15/Fcx7Wwv8OzT71A3E1XOAjvesZW2xOQ-xsNqO47m55DA.woff2) format('woff2');
unicode-range: U+0100-024F, U+1E00-1EFF, U+20A0-20AB, U+20AD-20CF, U+2C60-2C7F, U+A720-A7FF;
}
/* latin */
@font-face {
font-family: 'Roboto';
font-style: normal;
font-weight: 400;
src: local('Roboto'), local('Roboto-Regular'), url(https://fonts.gstatic.com/s/roboto/v15/CWB0XYA8bzo0kSThX0UTuA.woff2) format('woff2');
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2212, U+2215;
font-family: 'Roboto';
font-style: normal;
font-weight: 400;
src: local('Roboto'), local('Roboto-Regular'), url(https://fonts.gstatic.com/s/roboto/v15/CWB0XYA8bzo0kSThX0UTuA.woff2) format('woff2');
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2212, U+2215;
}
/*@font-face {
font-family: 'Roboto';

View file

@ -1,13 +1,18 @@
<?php if (isset($chat)): ?>
<div id="widget-chat-<?php echo intval($chat->id) ?>" class="widget-chat-wrapper block" data-url="<?php echo Zira\Helper::url('chat/index/index?'.FORMAT_GET_VAR.'='.FORMAT_JSON); ?>" data-chat="<?php echo intval($chat->id) ?>" data-delay="<?php echo intval($chat->refresh_delay) ?>">
<div class="page-header">
<h2 class="widget-title"><?php echo Zira\Helper::html($chat->title) ?></h2>
</div>
<div class="widget-chat-messages"></div>
<?php if (!empty($form)): ?>
<div class="widget-chat-form">
<?php echo $form; ?>
</div>
<?php endif; ?>
<div class="page-header">
<h2 class="widget-title"><?php echo Zira\Helper::html($chat->title) ?></h2>
</div>
<?php if ($chat->info): ?>
<div class="chat-info alert alert-info"><p class="parse-content">
<?php echo Zira\Content\Parse::bbcode(Zira\Helper::nl2br(Zira\Helper::html($chat->info))); ?>
</p></div>
<?php endif; ?>
<div class="widget-chat-messages"></div>
<?php if (!empty($form)): ?>
<div class="widget-chat-form">
<?php echo $form; ?>
</div>
<?php endif; ?>
</div>
<?php endif; ?>

20
update/v5/chat.php Normal file
View file

@ -0,0 +1,20 @@
<?php
namespace Update\V5;
use Zira\Db\Alter;
use Zira\Db\Field;
class Chat extends Alter {
protected $_table = 'chats';
public function __construct() {
parent::__construct($this->_table);
}
public function getFieldsToAdd() {
return array(
'info' => Field::text()
);
}
}

7
update/v5/index.php Normal file
View file

@ -0,0 +1,7 @@
<?php
if (!defined('ZIRA_UPDATE') || !ZIRA_UPDATE) exit;
// adding new fields to chats table
$alterChats = new \Update\V5\Chat();
$alterChats->execute();
Zira\Log::write('Updated chats table');

View file

@ -183,6 +183,12 @@ class Helper {
$url = str_ireplace('%2F', '/', $url);
return $url;
}
public static function isCurrentDay($time) {
$day_str = date(Config::get('date_format'), $time);
$current_str = date(Config::get('date_format'), time());
return $day_str == $current_str;
}
public static function backtrace($return=false) {
$backtrace = debug_backtrace();