Browse Source

Change module manifest

Remote modules
master
Egorka 6 years ago
parent
commit
32045c3a15
  1. 45
      backend/controllers/ModuleController.php
  2. 2
      backend/messages/ru/main.php
  3. 68
      backend/views/module/remote-list.php
  4. 8
      core/components/modules/ModuleManager.php
  5. 41
      core/entities/user/User.php

45
backend/controllers/ModuleController.php

@ -38,7 +38,7 @@ class ModuleController extends Controller
'class' => AccessControl::class, 'class' => AccessControl::class,
'rules' => [ 'rules' => [
[ [
'actions' => ['list', 'disable', 'enable', 'delete'], 'actions' => ['list', 'disable', 'enable', 'delete', 'search'],
'allow' => true, 'allow' => true,
'roles' => ['ModuleManagement'], 'roles' => ['ModuleManagement'],
], ],
@ -96,6 +96,49 @@ class ModuleController extends Controller
return $this->redirect(['module/list']); return $this->redirect(['module/list']);
} }
public function actionInstall($name)
{
//
}
public function actionSearch()
{
//print_r(file_get_contents('https://gitlab.com/zertex/zxcms-blog.git')); die;
//https://gitlab.com/zertex/zxcms-blog/-/archive/master/zxcms-blog-master.zip
$message = null;
try {
$list = file_get_contents('http://zertex.ru/zxcms/modules.txt');
$links = array_filter(explode('|', $list));
$modules = [];
foreach ($links as $link) {
$manifest = file_get_contents($link);
$manifest = eval(str_replace('<?php', '', $manifest));
$languageFile = str_replace('manifest.php', 'messages/' . \Yii::$app->language . '/' . $manifest['name'] . '.php', $link);
try {
$language = file_get_contents($languageFile);
$language = eval(str_replace('<?php', '', $language));
$manifest['locale_name'] = isset($language[$manifest['name']]) ? $language[$manifest['name']] : $manifest['name'];
$manifest['locale_description'] = isset($language[$manifest['description']]) ? $language[$manifest['description']] : $manifest['description'];
} catch (\Exception $e) {
$manifest['locale_name'] = $manifest['name'];
$manifest['locale_description'] = $manifest['description'];
}
$modules[] = $manifest;
}
} catch (\Exception $e) {
$modules = [];
$message = \Yii::t('main', 'Available modules not found');
}
return $this->render('remote-list', [
'modules' => $modules,
'message' => $message,
]);
}
protected function findModel($id): ModuleRecord protected function findModel($id): ModuleRecord
{ {
if (($model = ModuleRecord::findOne($id)) !== null) { if (($model = ModuleRecord::findOne($id)) !== null) {

2
backend/messages/ru/main.php

@ -70,4 +70,6 @@ return [
'Fuchsia' => 'Фуксия', 'Fuchsia' => 'Фуксия',
'Purple' => 'Пурпурный', 'Purple' => 'Пурпурный',
'Maroon' => 'Вишнёвый', 'Maroon' => 'Вишнёвый',
'Available Modules' => 'Доступные модули',
'Installed' => 'Установлен',
]; ];

68
backend/views/module/remote-list.php

@ -0,0 +1,68 @@
<?php
/**
* Created by Error202
* Date: 17.08.2018
*/
use yii\helpers\Html;
/**
* @var $this \yii\web\View
* @var $modules array
* @var $message string
*/
$this->title = Yii::t('main', 'Available Modules');
$this->params['breadcrumbs'][] = $this->title;
?>
<?php if ($message) : ?>
<?php endif; ?>
<div class="row">
<?php foreach ($modules as $module) : ?>
<?php
/*$color = $module->isEnabled() ? '#00aced' : '#cccccc';
if ($module->isDisabled()) {
ModuleHelper::addModuleAdminTranslation($module->name);
}*/
//$module_name = in_array($module->name, array_keys(Yii::$app->getI18n()->translations)) ? Yii::t($module->name, $module->name) : $module->name;
//$module_description = in_array($module->name, array_keys(Yii::$app->getI18n()->translations)) ? Yii::t($module->name, $module->description) : $module->description;
$color = '#00aced';
$module_name = $module['locale_name'];
$module_description = $module['locale_description'];
?>
<div class="col-md-4">
<div class="box">
<div class="box-header with-border">
<h3 class="box-title"><?= $module_name ?></h3>
</div>
<div class="box-body">
<?= $module_description ?>
</div>
<div class="box-footer" style="text-align: right">
<?php if (Yii::$app->moduleManager->isExists($module['name'])) : ?>
<span class="text-bold text-green"><?= Yii::t('main', 'Installed') ?></span>
<?php else : ?>
<?= Html::a(Yii::t('main', 'Enable'), ['module/enable', 'id' => $module['name']], [
'class' => 'btn btn-default btn-sm',
'data' => [
'method' => 'post',
],
]) ?>
<?php endif; ?>
</div>
</div>
</div>
<?php endforeach; ?>
</div>

8
core/components/modules/ModuleManager.php

@ -9,6 +9,7 @@ namespace core\components\modules;
use core\entities\ModuleRecord; use core\entities\ModuleRecord;
use core\services\ModuleService; use core\services\ModuleService;
use Yii; use Yii;
use yii\helpers\ArrayHelper;
use yii\helpers\FileHelper; use yii\helpers\FileHelper;
class ModuleManager class ModuleManager
@ -73,6 +74,13 @@ class ModuleManager
return $this->modules; return $this->modules;
} }
public function isExists($name): bool
{
$this->getLocalModules();
$modules = ArrayHelper::getColumn($this->modules, 'name');
return in_array($name, $modules);
}
private function getLocalModulesNames(): void private function getLocalModulesNames(): void
{ {
if (!empty($this->moduleNames)) { if (!empty($this->moduleNames)) {

41
core/entities/user/User.php

@ -1,4 +1,5 @@
<?php <?php
namespace core\entities\user; namespace core\entities\user;
use core\entities\Session; use core\entities\Session;
@ -51,11 +52,9 @@ class User extends ActiveRecord implements AggregateRoot
$user->status = self::STATUS_ACTIVE; $user->status = self::STATUS_ACTIVE;
$user->auth_key = Yii::$app->security->generateRandomString(); $user->auth_key = Yii::$app->security->generateRandomString();
if ($user->user_pic) if ($user->user_pic) {
{
$fileName = md5('avatar-' . $user->user_pic->baseName . time()) . '.' . $user->user_pic->extension; $fileName = md5('avatar-' . $user->user_pic->baseName . time()) . '.' . $user->user_pic->extension;
if ($user->user_pic->saveAs((new AvatarGenerator())->getPath('avatar') . '/' . $fileName)) if ($user->user_pic->saveAs((new AvatarGenerator())->getPath('avatar') . '/' . $fileName)) {
{
$user->user_pic = $fileName; $user->user_pic = $fileName;
} }
} }
@ -69,11 +68,9 @@ class User extends ActiveRecord implements AggregateRoot
$this->email = $email; $this->email = $email;
$this->updated_at = time(); $this->updated_at = time();
if ($user_pic) if ($user_pic) {
{
$fileName = md5('avatar-' . $user_pic->baseName . time()) . '.' . $user_pic->extension; $fileName = md5('avatar-' . $user_pic->baseName . time()) . '.' . $user_pic->extension;
if ($user_pic->saveAs((new AvatarGenerator())->getPath('avatar') . '/' . $fileName)) if ($user_pic->saveAs((new AvatarGenerator())->getPath('avatar') . '/' . $fileName)) {
{
(new AvatarGenerator())->remove('avatar', $this->user_pic); (new AvatarGenerator())->remove('avatar', $this->user_pic);
$this->user_pic = $fileName; $this->user_pic = $fileName;
} }
@ -86,21 +83,25 @@ class User extends ActiveRecord implements AggregateRoot
} }
} }
public function editProfile(string $email, string $username, string $password = null, $user_pic = null, $language): void public function editProfile(
{ string $email,
string $username,
string $password = null,
$user_pic = null,
$language
): void {
$this->email = $email; $this->email = $email;
$this->username = $username; $this->username = $username;
if ($password && !empty($password)) { if ($password && !empty($password)) {
$this->setPassword( $password ); $this->setPassword($password);
} }
$this->updated_at = time(); $this->updated_at = time();
$this->backend_language = $language; $this->backend_language = $language;
/* @var $user_pic \yii\web\UploadedFile */ /* @var $user_pic \yii\web\UploadedFile */
if ($user_pic) if ($user_pic) {
{
$fileName = md5('avatar-' . $user_pic->baseName . time()) . '.' . $user_pic->extension; $fileName = md5('avatar-' . $user_pic->baseName . time()) . '.' . $user_pic->extension;
$path = Yii::getAlias( '@runtime/' . $fileName); $path = Yii::getAlias('@runtime/' . $fileName);
$user_pic->saveAs($path); $user_pic->saveAs($path);
$this->user_pic = basename(Yii::$app->avatar->update($username, null, $path)); $this->user_pic = basename(Yii::$app->avatar->update($username, null, $path));
if (file_exists($path)) { if (file_exists($path)) {
@ -120,6 +121,7 @@ class User extends ActiveRecord implements AggregateRoot
$user->email_confirm_token = Yii::$app->security->generateRandomString(); $user->email_confirm_token = Yii::$app->security->generateRandomString();
$user->generateAuthKey(); $user->generateAuthKey();
$user->recordEvent(new UserSignUpRequested($user)); $user->recordEvent(new UserSignUpRequested($user));
return $user; return $user;
} }
@ -140,6 +142,7 @@ class User extends ActiveRecord implements AggregateRoot
$user->status = self::STATUS_ACTIVE; $user->status = self::STATUS_ACTIVE;
$user->generateAuthKey(); $user->generateAuthKey();
$user->networks = [Network::create($network, $identity)]; $user->networks = [Network::create($network, $identity)];
return $user; return $user;
} }
@ -221,6 +224,7 @@ class User extends ActiveRecord implements AggregateRoot
* Finds user by username * Finds user by username
* *
* @param string $username * @param string $username
*
* @return static|null * @return static|null
*/ */
public static function findByUsername($username) public static function findByUsername($username)
@ -232,6 +236,7 @@ class User extends ActiveRecord implements AggregateRoot
* Finds user by password reset token * Finds user by password reset token
* *
* @param string $token password reset token * @param string $token password reset token
*
* @return static|null * @return static|null
*/ */
public static function findByPasswordResetToken($token) public static function findByPasswordResetToken($token)
@ -250,6 +255,7 @@ class User extends ActiveRecord implements AggregateRoot
* Finds out if password reset token is valid * Finds out if password reset token is valid
* *
* @param string $token password reset token * @param string $token password reset token
*
* @return bool * @return bool
*/ */
public static function isPasswordResetTokenValid($token) public static function isPasswordResetTokenValid($token)
@ -258,8 +264,9 @@ class User extends ActiveRecord implements AggregateRoot
return false; return false;
} }
$timestamp = (int) substr($token, strrpos($token, '_') + 1); $timestamp = (int)substr($token, strrpos($token, '_') + 1);
$expire = Yii::$app->params['user.passwordResetTokenExpire']; $expire = Yii::$app->params['user.passwordResetTokenExpire'];
return $timestamp + $expire >= time(); return $timestamp + $expire >= time();
} }
@ -267,6 +274,7 @@ class User extends ActiveRecord implements AggregateRoot
* Validates password * Validates password
* *
* @param string $password password to validate * @param string $password password to validate
*
* @return bool if password provided is valid for current user * @return bool if password provided is valid for current user
*/ */
public function validatePassword($password) public function validatePassword($password)
@ -292,7 +300,8 @@ class User extends ActiveRecord implements AggregateRoot
$this->auth_key = Yii::$app->security->generateRandomString(); $this->auth_key = Yii::$app->security->generateRandomString();
} }
public function attributeLabels() { public function attributeLabels()
{
return [ return [
'id' => Yii::t('user', 'ID'), 'id' => Yii::t('user', 'ID'),
'username' => Yii::t('user', 'Username'), 'username' => Yii::t('user', 'Username'),

Loading…
Cancel
Save