From 47b9acb81d80b7fa9af2b61eaf6f98677f0bc237 Mon Sep 17 00:00:00 2001 From: Sergey Shorokhov Date: Thu, 4 Mar 2021 15:37:34 +0300 Subject: [PATCH] Adapt code for ChatAdditions (#2) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * ✨ adapt code for ChatAdditions --- protected/controllers/GaglistController.php | 85 ++++++++++ protected/controllers/GagsController.php | 85 ---------- protected/models/Gaglist.php | 147 ++++++++++++++++++ protected/models/Gags.php | 100 ------------ protected/views/{gags => gaglist}/_search.php | 2 +- protected/views/gaglist/index.php | 82 ++++++++++ protected/views/gags/index.php | 94 ----------- 7 files changed, 315 insertions(+), 280 deletions(-) create mode 100644 protected/controllers/GaglistController.php delete mode 100644 protected/controllers/GagsController.php create mode 100644 protected/models/Gaglist.php delete mode 100644 protected/models/Gags.php rename protected/views/{gags => gaglist}/_search.php (87%) create mode 100644 protected/views/gaglist/index.php delete mode 100644 protected/views/gags/index.php diff --git a/protected/controllers/GaglistController.php b/protected/controllers/GaglistController.php new file mode 100644 index 0000000..b67e924 --- /dev/null +++ b/protected/controllers/GaglistController.php @@ -0,0 +1,85 @@ +array( + 'class'=>'CCaptchaAction' + ) + ); + } + + public function actionDelete($id) + { + $model = $this->loadModel($id); + + if (!Webadmins::checkAccess('bans_delete')) { + throw new CHttpException(403, "У Вас недостаточно прав"); + } + + $model->delete(); + + if (!isset($_GET['ajax'])) { + $this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('admin')); + } + } + + public function actionIndex() + { + //$model=new Gaglist('search'); + $model = Gaglist::model()->with('admin'); + $model->unsetAttributes(); + if (isset($_GET['Gaglist'])) { + $model->attributes = $_GET['Gaglist']; + } + + $dataProvider=new CActiveDataProvider('Gaglist', array( + 'pagination' => array( + 'pageSize' => Yii::app()->config->bans_per_page), + 'sort' => array( + 'defaultOrder' => '`created_at` DESC', + 'attributes' => array( + 'created_at', + 'name', + 'admin_name', + 'reason' + ) + ) + ) + ); + + $this->render('index',array( + 'dataProvider'=>$dataProvider, + 'model'=>$model + )); + + } + + public function loadModel($id) + { + $model=Gaglist::model()->with('admin')->findByPk($id); + if ($model === null) { + throw new CHttpException(404, 'Запись не найдена.'); + } + return $model; + } + + protected function performAjaxValidation($model) + { + if(isset($_POST['ajax']) && $_POST['ajax']==='gags-form') { + echo CActiveForm::validate($model); + Yii::app()->end(); + } + } +} diff --git a/protected/controllers/GagsController.php b/protected/controllers/GagsController.php deleted file mode 100644 index 419fc66..0000000 --- a/protected/controllers/GagsController.php +++ /dev/null @@ -1,85 +0,0 @@ -array( - 'class'=>'CCaptchaAction' - ) - ); - } - - public function actionDelete($id) - { - $model = $this->loadModel($id); - - if (!Webadmins::checkAccess('bans_delete')) { - throw new CHttpException(403, "У Вас недостаточно прав"); - } - - $model->delete(); - - if (!isset($_GET['ajax'])) { - $this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('admin')); - } - } - - public function actionIndex() - { - //$model=new Gags('search'); - $model = Gags::model()->with('admin'); - $model->unsetAttributes(); - if (isset($_GET['Gags'])) { - $model->attributes = $_GET['Gags']; - } - - $dataProvider=new CActiveDataProvider('Gags', array( - 'pagination' => array( - 'pageSize' => Yii::app()->config->bans_per_page), - 'sort' => array( - 'defaultOrder' => '`create_time` DESC', - 'attributes' => array( - 'create_time', - 'name', - 'admin_name', - 'reason' - ) - ) - ) - ); - - $this->render('index',array( - 'dataProvider'=>$dataProvider, - 'model'=>$model - )); - - } - - public function loadModel($id) - { - $model=Gags::model()->with('admin')->findByPk($id); - if ($model === null) { - throw new CHttpException(404, 'Запись не найдена.'); - } - return $model; - } - - protected function performAjaxValidation($model) - { - if(isset($_POST['ajax']) && $_POST['ajax']==='gags-form') { - echo CActiveForm::validate($model); - Yii::app()->end(); - } - } -} diff --git a/protected/models/Gaglist.php b/protected/models/Gaglist.php new file mode 100644 index 0000000..0bf96a3 --- /dev/null +++ b/protected/models/Gaglist.php @@ -0,0 +1,147 @@ + '/^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/'), + array('authid, admin_authid', 'match', 'pattern' => '/^(STEAM|VALVE)_([0-9]):([0-9]):\d{1,21}$/'), + array('id, authid, name, ip, admin_name, admin_authid, created_at, expire_at', 'safe', 'on'=>'search'), + ); + } + + public function relations() + { + return array( + 'admin' => array( + self::HAS_ONE, + 'Amxadmins', + '', + 'on' => '`admin`.`steamid` = `t`.`admin_name` OR ' + . '`admin`.`steamid` = `t`.`admin_authid`' + ) + ); + } + + public function attributeLabels() + { + return array( + 'id' => 'Bid', + 'ip' => 'IP игрока', + 'authid' => 'Steam игрока', + 'name' => 'Ник игрока', + 'expire_at' => 'Истекает', + 'admin_name' => 'Ник админа', + 'reason' => 'Причина' + ); + } + + protected function afterFind() { + $country = strtolower(Yii::app()->IpToCountry->lookup($this->ip)); + $this->country = CHtml::image( + Yii::app()->urlManager->baseUrl + . '/images/country/' + . ($country != 'zz' ? $country : 'clear') . '.png' + ); + return parent::afterFind(); + } + + public function afterDelete() { + Syslog::add(Logs::LOG_DELETED, 'Удален gag игрока ' . $this->name . ''); + return parent::afterDelete(); + } + + public function search() + { + $criteria=new CDbCriteria; + + $criteria->compare('t.id',$this->id); + $criteria->addSearchCondition('t.ip',$this->ip); + $criteria->addSearchCondition('t.authid',$this->authid); + $criteria->addSearchCondition('t.name',$this->name); + $criteria->addSearchCondition('t.admin_name',$this->admin_name); + + $criteria->order = '`created_at` DESC'; + + return new CActiveDataProvider($this, array( + 'criteria'=>$criteria, + 'pagination' => array( + 'pageSize' => Yii::app()->config->bans_per_page + ) + )); + } + + public function getGagType() { + $str = ""; + $gagFlag_Chat = (1<<0); + $gagFlag_TeamChat = (1<<1); + $gagFlag_Voice = (1<<2); + + if($this->flags & $gagFlag_Chat) { + $str.="Chat + "; + } + if($this->flags & $gagFlag_TeamChat) { + $str.="Team chat + "; + } + if($this->flags & $gagFlag_Voice) { + $str.="Voice + "; + } + + $str = substr($str, 0, -3); + + return $str; + } + + public function getGagTimeleft($expireAt) { + $secondsLeft = strtotime($this->expire_at) - strtotime($this->created_at); + if($secondsLeft > 0) { + return Prefs::date2word($secondsLeft / 60); + } else { + return "Разбанен"; + } + } + + public function isGagExpired() { + return strtotime($this->expire_at) < time() && strtotime($this->expire_at); + } + + public function getAdmin() { + $adminName = CHtml::encode(mb_substr($this->admin_name, 0, 18, "UTF-8")); + if(!$this->admin) { + return $adminName; + } + + return CHtml::link( + $adminName, + Yii::app()->urlManager->baseUrl . "/amxadmins/#admin_" . $this->admin->id + ); + } +} diff --git a/protected/models/Gags.php b/protected/models/Gags.php deleted file mode 100644 index eacd90f..0000000 --- a/protected/models/Gags.php +++ /dev/null @@ -1,100 +0,0 @@ - '/^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/'), - array('steamid, admin_steamid', 'match', 'pattern' => '/^(STEAM|VALVE)_([0-9]):([0-9]):\d{1,21}$/'), - array('id, steamid, name, ip, admin_name, admin_steamid, create_time, expired_time', 'safe', 'on'=>'search'), - ); - } - - public function relations() - { - return array( - 'admin' => array( - self::HAS_ONE, - 'Amxadmins', - '', - 'on' => '`admin`.`steamid` = `t`.`admin_name` OR ' - . '`admin`.`steamid` = `t`.`admin_steamid`' - ) - ); - } - - public function attributeLabels() - { - return array( - 'id' => 'Bid', - 'ip' => 'IP игрока', - 'steamid' => 'Steam игрока', - 'name' => 'Ник игрока', - 'expired_time' => 'Истекает', - 'admin_name' => 'Ник админа', - 'reason' => 'Причина' - ); - } - - protected function afterFind() { - $country = strtolower(Yii::app()->IpToCountry->lookup($this->ip)); - $this->country = CHtml::image( - Yii::app()->urlManager->baseUrl - . '/images/country/' - . ($country != 'zz' ? $country : 'clear') . '.png' - ); - return parent::afterFind(); - } - - public function afterDelete() { - Syslog::add(Logs::LOG_DELETED, 'Удален gag игрока ' . $this->name . ''); - return parent::afterDelete(); - } - - public function search() - { - $criteria=new CDbCriteria; - - $criteria->compare('t.id',$this->id); - $criteria->addSearchCondition('t.ip',$this->ip); - $criteria->addSearchCondition('t.steamid',$this->steamid); - $criteria->addSearchCondition('t.name',$this->name); - $criteria->addSearchCondition('t.admin_name',$this->admin_name); - - $criteria->order = '`create_time` DESC'; - - return new CActiveDataProvider($this, array( - 'criteria'=>$criteria, - 'pagination' => array( - 'pageSize' => Yii::app()->config->bans_per_page - ) - )); - } -} diff --git a/protected/views/gags/_search.php b/protected/views/gaglist/_search.php similarity index 87% rename from protected/views/gags/_search.php rename to protected/views/gaglist/_search.php index ec02b4d..3d3b1c6 100644 --- a/protected/views/gags/_search.php +++ b/protected/views/gaglist/_search.php @@ -8,7 +8,7 @@ )); echo $form->textFieldRow($model,'name',array('maxlength'=>100)); -echo $form->textFieldRow($model,'steamid',array('maxlength'=>20)); +echo $form->textFieldRow($model,'authid',array('maxlength'=>20)); echo $form->textFieldRow($model,'admin_name',array('maxlength'=>100)); $this->widget('bootstrap.widgets.TbButton', array( diff --git a/protected/views/gaglist/index.php b/protected/views/gaglist/index.php new file mode 100644 index 0000000..b7e1e54 --- /dev/null +++ b/protected/views/gaglist/index.php @@ -0,0 +1,82 @@ +pageTitle = Yii::app()->name . ' - ' . $page; + +$this->breadcrumbs=array( + $page, +); + +Yii::app()->clientScript->registerScript('search', " +$('.search-form form').submit(function(){ + $.fn.yiiGridView.update('gags-grid', { + data: $(this).serialize() + }); + return false; +}); +"); + +$this->renderPartial('_search',array( + 'model'=>$model, +)); + +$this->widget('bootstrap.widgets.TbGridView', array( + 'type'=>'striped bordered condensed hoverable', + 'id'=>'gags-grid', + 'dataProvider'=>isset($_GET['Gaglist']) ? $model->search() : $dataProvider, + 'enableSorting' => array('created_at'), + 'summaryText' => 'Показано с {start} по {end} гагов из {count}. Страница {page} из {pages}', + 'htmlOptions' => array( + 'style' => 'width: 100%' + ), + 'rowHtmlOptionsExpression'=>'array( + "id" => "gag_$data->id", + "class" => $data->isGagExpired() ? "bantr success" : "bantr" + )', + 'pager' => array( + 'class'=>'bootstrap.widgets.TbPager', + 'displayFirstAndLast' => true, + ), + 'columns'=>array( + array( + 'header' => 'Дата', + 'name' => 'created_at', + 'value' => 'date("d.m.Y H:i", strtotime($data->created_at))', + 'htmlOptions' => array('style' => 'width:100px'), + ), + array( + 'header' => 'Ник', + 'type' => 'raw', + 'value' => '$data->country . " " . CHtml::encode($data->name)', + 'htmlOptions' => array('style' => 'width:100px'), + ), + array( + 'header' => 'Админ', + 'type' => 'raw', + 'value' => '$data->getAdmin()', + 'htmlOptions' => array('style' => 'width:100px'), + ), + array( + 'header' => 'Срок', + 'value' => '$data->getGagTimeleft()', + 'htmlOptions' => array('style' => 'width:100px'), + ), + array( + 'header' => 'Тип блокировки', + 'value' => '$data->getGagType()', + 'htmlOptions' => array('style' => 'width:100px'), + ), + array( + 'header' => 'Причина', + 'value' => '$data->reason ? $data->reason : ""', + 'htmlOptions' => array('style' => 'width:100px'), + ), + array( + 'class'=>'bootstrap.widgets.TbButtonColumn', + 'template' => '{delete}', + 'htmlOptions' => array('style' => 'width:20px'), + 'visible' => Webadmins::checkAccess('bans_edit') + ) + ), +)); +?> \ No newline at end of file diff --git a/protected/views/gags/index.php b/protected/views/gags/index.php deleted file mode 100644 index 45634bb..0000000 --- a/protected/views/gags/index.php +++ /dev/null @@ -1,94 +0,0 @@ -pageTitle = Yii::app()->name . ' - ' . $page; - -$this->breadcrumbs=array( - $page, -); - -Yii::app()->clientScript->registerScript('search', " -$('.search-form form').submit(function(){ - $.fn.yiiGridView.update('gags-grid', { - data: $(this).serialize() - }); - return false; -}); -"); - -$this->renderPartial('_search',array( - 'model'=>$model, -)); - -$this->widget('bootstrap.widgets.TbGridView', array( - 'type'=>'striped bordered condensed', - 'id'=>'gags-grid', - 'dataProvider'=>isset($_GET['Gags']) ? $model->search() : $dataProvider, - 'enableSorting' => array('create_time', 'name', 'admin_name', 'reason'), - 'summaryText' => 'Показано с {start} по {end} гагов из {count}. Страница {page} из {pages}', - 'htmlOptions' => array( - 'style' => 'width: 100%' - ), - 'rowHtmlOptionsExpression'=>'array( - "id" => "gag_$data->id", - "class" => ($data->expired_time < time() && $data->expired_time) ? "bantr success" : "bantr" - )', - 'pager' => array( - 'class'=>'bootstrap.widgets.TbPager', - 'displayFirstAndLast' => true, - ), - 'columns'=>array( - array( - 'header' => 'Дата', - 'name' => 'create_time', - 'value' => 'date("d.m.Y H:i", $data->create_time)', - 'htmlOptions' => array('style' => 'width:100px'), - ), - array( - 'header' => 'Ник', - 'type' => 'raw', - 'name' => 'name', - 'value' => '$data->country . " " . CHtml::encode($data->name)' - ), - - array( - 'header' => 'STEAM_ID', - 'type' => 'raw', - 'value' => '$data->steamid', - 'htmlOptions' => array( - 'style' => 'width: 130px' - ) - ), - - array( - 'header' => 'Админ', - 'type' => 'raw', - 'name' => 'admin_name', - 'value' => '$data->admin ? CHtml::link(CHtml::encode(mb_substr($data->admin_name, 0, 18, "UTF-8")), Yii::app()->urlManager->baseUrl . "/amxadmins/#admin_" . $data->admin->id) : CHtml::encode(mb_substr($data->admin_name, 0, 18, "UTF-8"))', - 'htmlOptions' => array( - 'style' => 'width: 130px' - ) - ), - - array( - 'header' => 'Срок до', - 'value' => '($data->expired_time >= 0) ? ($data->expired_time ? date("d.m.Y H:i", $data->expired_time) : "Навсегда") : "Разбанен"', - 'htmlOptions' => array('style' => 'width:100px'), - ), - - array( - 'header' => 'Причина', - 'name' => 'reason', - 'value' => '$data->reason ? $data->reason : ""', - 'htmlOptions' => array('style' => 'width:100px'), - ), - - array( - 'class'=>'bootstrap.widgets.TbButtonColumn', - 'template' => '{delete}', - 'htmlOptions' => array('style' => 'width:20px'), - 'visible' => Webadmins::checkAccess('bans_edit') - ) - ), -)); -?> \ No newline at end of file