瀏覽代碼

spy story

amic 11 月之前
父節點
當前提交
1fd7f28c9c

+ 7 - 0
config/web.php

@@ -44,6 +44,13 @@ $config = [
         'user' => [
             'identityClass' => 'app\models\User',
             'enableAutoLogin' => true,
+			'on afterLogin' => function($event) {
+					$user = $event->identity;
+					if( !Yii::$app->user->isGuest ){
+						$user->last_login_at = time();
+						$user->save();
+					}
+			}
         ],
         'errorHandler' => [
             'errorAction' => 'site/error',

+ 17 - 0
modules/manager/controllers/SpyController.php

@@ -14,6 +14,23 @@ class SpyController extends BaseController
         return $this->redirect("news/list");
     }
 
+    public function actionView()
+    {
+		$cache = Yii::$app->memcache;
+		$user = Yii::$app->user->identity->profile->name;
+		$id = Yii::$app->user->identity->profile->user_id;
+		$mduser = $id;
+		$uactive = $cache->get(self::keylist);
+		$html = '';
+		if( $uactive ){
+			$uactive = unserialize($uactive);
+			$html = $this->renderPartial('_item',['users'=>$uactive, 'obj'=>$this, 'id'=>$id]);
+		}else{
+			$html = '';
+		}
+        return $this->render("view", ['html'=>$html]);
+    }
+
     public function actionAuthorping()
     {
 		$cache = Yii::$app->memcache;

+ 92 - 0
modules/manager/controllers/UserexController.php

@@ -0,0 +1,92 @@
+<?php
+
+namespace manager\controllers;
+
+
+use dektrium\user\models\Profile;
+use dektrium\user\models\User;
+use yii\web\Controller;
+use yii\web\NotFoundHttpException;
+use yii\filters\VerbFilter;
+
+
+class UserexController extends BaseController
+{
+
+	public static $story_dir = 'images/users';
+    /**
+     * Displays a single User model.
+     * @param int $id id
+     * @return string
+     * @throws NotFoundHttpException if the model cannot be found
+     */
+    public function actionIndex($id)
+    {
+        $model = $this->findModel($id);
+
+        if ($model && $this->request->isPost ) {
+			$name = $_FILES['User']['tmp_name']['photo'];
+			if (is_uploaded_file($name)) {
+				$post = \Yii::$app->request->post();
+				$pcut = isset($post['cropping'])?$post['cropping']:false;
+				$file_tmp = \Yii::getAlias('@webroot').'/'.static::$story_dir."/".basename($name);
+				if( move_uploaded_file($_FILES['User']['tmp_name']['photo'], $file_tmp) ){
+
+					list($width, $height) = getimagesize($file_tmp);
+					if( $pcut ){
+						$cut = ['x'=>round($pcut['x']), 'y'=>round($pcut['y']), 'w'=>round($pcut['width']), 'h'=>round($pcut['height'])];
+
+						$name = basename($id."_sm.jpg");
+						$cutfile = \Yii::getAlias('@webroot').'/'.static::$story_dir."/$name";
+						$this->generateImageCrop($file_tmp, $cutfile, 128, 128, $cut, ['sharpen' => 10]);
+
+						$name = basename($id."_norm.jpg");
+						$cutfile = \Yii::getAlias('@webroot').'/'.static::$story_dir."/$name";
+						$this->generateImageCrop($file_tmp, $cutfile, 256, 256, $cut, ['sharpen' => 5]);
+					}
+					unlink($file_tmp);
+				}
+			}
+            return $this->redirect(['/user/admin/index']);
+        }
+
+        return $this->render('view', [
+            'model' => $this->findModel($id), 'obj' => $this
+        ]);
+    }
+
+    public function generateImageCrop( $ifile, $ofile, $ww, $hh, $param )
+    {
+		// to do add rotate, etc
+		extract( $param );
+		list($width, $height) = getimagesize($ifile);
+		$addp = '';
+		if( strrpos($ofile, '.webp') == strlen($ofile) - strlen('.webp') )
+		{
+			$addp = " -background '#FFFFFF' -alpha off -strip Plane -quality 88 -define webp:method=6 "; //-interlace
+		}
+		if(isset($sharpen))
+		{
+			$addp = $addp." -sharpen ".$sharpen;
+		}
+		$addp .= " -quality 80";
+		umask(0113);
+		exec("convert -define jpeg:size=".$width."x".$height."+0+0 $ifile -crop ".$w."x".$h."+".$x."+".$y." -thumbnail ".$ww."x".$hh."^ $addp -gravity center $ofile" );
+    }
+
+    /**
+     * Finds the Authors model based on its primary key value.
+     * If the model is not found, a 404 HTTP exception will be thrown.
+     * @param int $id id
+     * @return Authors the loaded model
+     * @throws NotFoundHttpException if the model cannot be found
+     */
+    protected function findModel($id)
+    {
+        if (($model = User::findOne(['id' => $id])) !== null) {
+            return $model;
+        }
+
+        throw new NotFoundHttpException('The requested page does not exist.');
+    }
+}

+ 1 - 1
modules/manager/views/layouts/navbar.php

@@ -64,7 +64,7 @@ $setdate = (isset($_GET['dt']))?strtotime($_GET['dt']):$get;
             </a>
             <div class="dropdown-menu dropdown-menu-lg dropdown-menu-right">
 				<div id="user_active"></div>
-                <a href="#" class="dropdown-item dropdown-footer">Смотреть подробности</a>
+                <a href="/manager/spy/view" class="dropdown-item dropdown-footer">Смотреть подробности</a>
             </div>
         </li>
         <!-- Notifications Dropdown Menu -->

+ 43 - 0
modules/manager/views/spy/_item.php

@@ -0,0 +1,43 @@
+<?
+use yii\web\View;
+$assetDir = Yii::$app->assetManager->getPublishedUrl('@vendor/almasaeed2010/adminlte/dist');
+
+foreach($users as $userid => $data){
+	$op = ( $userid == $id )?0.5:1;
+	$mark = (  time()-$data['time'] < $obj::sleep )?'fas fa-user-check':'fas fa-mug-hot';
+	$mark = (  time()-$data['time'] < $obj::dead )?'fas fa-user-check':'fas fa-bed';
+	$markd = (  time()-$data['time'] < $obj::sleep )?'text-success':'text-warning';
+	$markd = (  time()-$data['time'] < $obj::dead )?'text-success':'text-danger';
+	if(  time()-$data['time'] < $obj::kill ) {
+		$photo = "/images/users/".$userid."_norm.jpg";
+		if( !file_exists( Yii::getAlias('@webroot').$photo ) ){
+			$photo = $assetDir."/img/user1-128x128.jpg";
+		}
+?>
+<div class="col-md-3">
+<div class="card card-primary card-outline">
+   <div class="card-body box-profile">
+      <div class="text-center">
+         <img class="profile-user-img img-fluid img-circle" src="<?=$photo?>" alt="User profile picture">
+      </div>
+      <h3 class="profile-username text-center"><?=$data['name']?></h3>
+      <p class="text-muted text-center"><?=$data['name']?></p>
+      <ul class="list-group list-group-unbordered mb-3">
+         <li class="list-group-item">
+            <b>Неактивен: </b> <i class="far fa-clock mr-1"></i> <?=date("i:s", time()-$data['time'])?><span class="float-right text-sm <?=$markd?>"><i class="<?=$mark?>"></i></span>
+         </li>
+         <li class="list-group-item">
+            <b>Following</b> <a class="float-right">543</a>
+         </li>
+         <li class="list-group-item">
+            <b>Friends</b> <a class="float-right">13,287</a>
+         </li>
+      </ul>
+   </div>
+</div>
+</div>
+
+                <div class="dropdown-divider"></div>
+<?
+	}
+}

+ 5 - 1
modules/manager/views/spy/list.php

@@ -9,11 +9,15 @@ foreach($users as $userid => $data){
 	$markd = (  time()-$data['time'] < $obj::sleep )?'text-success':'text-warning';
 	$markd = (  time()-$data['time'] < $obj::dead )?'text-success':'text-danger';
 	if(  time()-$data['time'] < $obj::kill ) {
+		$photo = "/images/users/".$userid."_sm.jpg";
+		if( !file_exists( Yii::getAlias('@webroot').$photo ) ){
+			$photo = $assetDir."/img/user1-128x128.jpg";
+		}
 ?>
                 <a href="#" class="dropdown-item">
                     <!-- Message Start -->
                     <div class="media" style="opacity:<?=$op?>">
-                        <img src="<?=$assetDir?>/img/user1-128x128.jpg" alt="User Avatar" class="img-size-50 mr-3 img-circle">
+                        <img src="<?=$photo?>" alt="User Avatar" class="img-size-50 mr-3 img-circle">
                         <div class="media-body">
                             <h3 class="dropdown-item-title">
                                 <?=$data['name']?>

+ 13 - 0
modules/manager/views/spy/view.php

@@ -0,0 +1,13 @@
+<?php
+
+use yii\helpers\Html;
+use yii\widgets\DetailView;
+
+/** @var yii\web\View $this */
+/** @var manager\models\CommentsFilter $model */
+$this->title = 'В сети';
+$this->params['breadcrumbs'][] = ['label' => 'В сети', 'url' => ['index']];
+?>
+<div class="row">
+<?=$html?>
+</div>

+ 20 - 1
modules/manager/views/user/admin/index.php

@@ -43,6 +43,18 @@ $this->params['breadcrumbs'][] = $this->title;
             'attribute' => 'id',
             'headerOptions' => ['style' => 'width:90px;'], # 90px is sufficient for 5-digit user ids
         ],
+        [
+            'attribute' => 'Фото',
+            'value' => function ($model) {
+				if( file_exists(Yii::getAlias('@webroot').'/images/users/'.$model->id.'_sm.jpg') ){
+					$s = Html::img('/images/users/'.$model->id.'_sm.jpg',['class' => "direct-chat-img"]);
+				}else{
+					$s = '';
+				}
+                return $s;
+            },
+            'format' => 'html',
+        ],
         'username',
         [
             'attribute' => 'Name',
@@ -137,7 +149,7 @@ $this->params['breadcrumbs'][] = $this->title;
         ],
         [
             'class' => 'yii\grid\ActionColumn',
-            'template' => '{switch} {resend_password} {update} {delete}',
+            'template' => '{switch} {resend_password} {update} {avatar} {delete}',
             'buttons' => [
                 'resend_password' => function ($url, $model, $key) {
                     if (\Yii::$app->user->identity->isAdmin && !$model->isAdmin) {
@@ -155,6 +167,13 @@ $this->params['breadcrumbs'][] = $this->title;
                             'data-method' => 'POST',
                         ]);
                     }
+                },
+                'avatar' => function ($url, $model) {
+                    if(\Yii::$app->user->identity->isAdmin && Yii::$app->getModule('user')->enableImpersonateUser) {
+                        return Html::a('<span class="glyphicon glyphicon-picture"></span>', ['/manager/userex', 'id' => $model->id], [
+                            'title' => Yii::t('user', 'Avatar this user')
+                        ]);
+                    }
                 }
             ]
         ],

+ 50 - 0
modules/manager/views/userex/view.php

@@ -0,0 +1,50 @@
+<?php
+
+use yii\helpers\Html;
+use yii\widgets\ActiveForm;
+use app\widgets\CropperjsWidget;
+use yii\web\View;
+
+/** @var yii\web\View $this */
+/** @var app\models\Authors $model */
+/** @var yii\widgets\ActiveForm $form */
+$this->title='Редактировать карточку '.$model->getProfile()->one()->name;
+$photo = "/".$obj::$story_dir."/".$model->id."_norm.jpg";
+if( file_exists( Yii::getAlias('@webroot').$photo ) ){
+	$imageSrc = $photo."?r=".rand();
+}else{
+	$imageSrc = '/img/e.gif';
+}
+?>
+<style>
+#image {
+	width: 420px;
+	background: URL(/img/image.svg) no-repeat 50% 50%;
+	background-size: contain;
+	background-color: #fff;
+	cursor: pointer;
+	aspect-ratio: 1/1;
+	background-size: 70%;
+}
+</style>
+<?php $form = ActiveForm::begin(['options' => ['enctype' => 'multipart/form-data']]) ?>
+<div class="container-fluid authors-form">
+<div class="row">
+	<div class="col-6 col-sm-6">
+		<div class="input-group mb-3">
+			<img id="image" class="img-circle elevation-2" src="<?=$imageSrc?>" onClick="$('#modal').modal('show');document.getElementById('inputImage').click();" >
+<? echo CropperjsWidget::widget(['image' => 'image', 'file' => 'User[photo]', 'post' => 'cropping', 'aspectRatio' => '1/1']); ?>
+		</div>
+	</div>
+</div>
+<div class="row">
+	<div class="col">
+
+	<div class="form-group">
+        <?= Html::submitButton('Сохранить', ['class' => 'btn btn-success']) ?>
+    </div>
+	</div>
+</div>
+</div>
+<?php ActiveForm::end(); ?>
+