This commit is contained in:
buddh4 2017-03-16 18:51:38 +01:00
commit afa8baf6e7
30 changed files with 487 additions and 338 deletions

View File

@ -21,6 +21,11 @@ use yii\helpers\Html;
class Controller extends \yii\web\Controller
{
/**
* @event \yii\base\Event an event raised on init a controller.
*/
const EVENT_INIT = 'init';
/**
* @var null|string the name of the sub layout to be applied to this controller's views.
* This property mainly affects the behavior of [[render()]].
@ -42,6 +47,15 @@ class Controller extends \yii\web\Controller
*/
public $prependActionTitles = true;
/**
* @inheritdoc
*/
public function init()
{
parent::init();
$this->trigger(self::EVENT_INIT);
}
/**
* @inheritdoc
*/
@ -92,7 +106,7 @@ class Controller extends \yii\web\Controller
if (\Yii::$app->request->method != 'POST') {
throw new \yii\web\HttpException(405, Yii::t('ContentModule.controllers_ContentController', 'Invalid request method!'));
}
return true;
}
@ -143,7 +157,7 @@ class Controller extends \yii\web\Controller
$this->getView()->pageTitle = $this->pageTitle;
}
if(!Yii::$app->request->isAjax || Yii::$app->request->isPjax) {
if (!Yii::$app->request->isAjax || Yii::$app->request->isPjax) {
$this->setJsViewStatus();
}
@ -223,7 +237,7 @@ class Controller extends \yii\web\Controller
$modluleId = (Yii::$app->controller->module) ? Yii::$app->controller->module->id : '';
$this->view->registerJs('humhub.modules.ui.view.setState("' . $modluleId . '", "' . Yii::$app->controller->id . '", "' . Yii::$app->controller->action->id . '");', \yii\web\View::POS_BEGIN);
if(Yii::$app->request->isPjax) {
if (Yii::$app->request->isPjax) {
\humhub\widgets\TopMenu::setViewState();
}
}

View File

@ -14,6 +14,7 @@ use yii\helpers\Json;
/**
* Base Class for Modules / Extensions
*
* @property SettingsManager $settings
* @author luke
*/
class Module extends \yii\base\Module

View File

@ -76,6 +76,10 @@ HumHub Change Log
- Enh: Directory view templates cleanups
- Fix: All LDAP Users have been disabled and not reenabled by hourly cronjob if ldap server not reachable.
- Enh: Cleanup authentication layout file
- Fix: Console image converter memory limit allocation
- Enh: Added new controller init event
- Enh: Made admin base controller method "getAccessRules()" non static
- Enh: Created new ImageController for user image and banner handling
1.2.0-beta.2 (February 24, 2017)
--------------------------------

View File

@ -1,26 +1,13 @@
<?php
/**
* HumHub
* Copyright © 2014 The HumHub Project
*
* The texts of the GNU Affero General Public License with an additional
* permission and of our proprietary license can be found at and
* in the LICENSE file you have received along with this program.
*
* According to our dual licensing model, this program can be used either
* under the terms of the GNU Affero General Public License, version 3,
* or under a proprietary license.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
* @link https://www.humhub.org/
* @copyright Copyright (c) 2017 HumHub GmbH & Co. KG
* @license https://www.humhub.com/licences
*/
namespace humhub\models\forms;
use yii\base\Model;
/**
@ -54,6 +41,16 @@ class CropProfileImage extends Model
*/
public $cropH;
/**
* @var int image ratio
*/
public $aspectRatio = 1;
/**
* @var array crop default position
*/
public $cropSetSelect = [0, 0, 100, 100];
/**
* Declares the validation rules.
*

View File

@ -23,7 +23,7 @@ class AdminController extends Controller
/**
* @inheritdoc
*/
public static function getAccessRules()
public function getAccessRules()
{
return [
['permissions' => \humhub\modules\admin\permissions\ManageSettings::className()]

View File

@ -23,7 +23,7 @@ class Controller extends \humhub\components\Controller
* @inheritdoc
*/
public $subLayout = "@humhub/modules/admin/views/layouts/main";
/**
* @var boolean if true only allows access for system admins else the access is restricted by getAccessRules()
*/
@ -35,7 +35,7 @@ class Controller extends \humhub\components\Controller
public function init()
{
$this->appendPageTitle(\Yii::t('AdminModule.base', 'Administration'));
return parent::init();
parent::init();
}
/**
@ -44,7 +44,7 @@ class Controller extends \humhub\components\Controller
public function behaviors()
{
// Workaround for module configuration actions @see getAccessRules()
if (Yii::$app->controller->module->id != 'admin') {
if ($this->module->id != 'admin') {
$this->adminOnly = false;
}
@ -52,15 +52,21 @@ class Controller extends \humhub\components\Controller
'acl' => [
'class' => AccessControl::className(),
'adminOnly' => $this->adminOnly,
'rules' => static::getAccessRules()
'rules' => $this->getAccessRules()
]
];
}
public static function getAccessRules()
/**
* Returns access rules for the standard access control behavior
*
* @see AccessControl
* @return array the access permissions
*/
public function getAccessRules()
{
// Workaround for module configuration actions
if (Yii::$app->controller->module->id != 'admin') {
// Use by default ManageModule permission, if method is not overwritten by custom module
if ($this->module->id != 'admin') {
return [
['permissions' => \humhub\modules\admin\permissions\ManageModules::className()]
];

View File

@ -35,8 +35,11 @@ class ApprovalController extends Controller
$this->appendPageTitle(Yii::t('AdminModule.base', 'Approval'));
return parent::init();
}
public static function getAccessRules()
/**
* @inheritdoc
*/
public function getAccessRules()
{
return [
['permissions' => [

View File

@ -21,7 +21,7 @@ class AuthenticationController extends Controller
* @inheritdoc
*/
public $adminOnly = false;
/**
* @inheritdoc
*/
@ -37,7 +37,10 @@ class AuthenticationController extends Controller
return parent::init();
}
public static function getAccessRules()
/**
* @inheritdoc
*/
public function getAccessRules()
{
return [
['permissions' => \humhub\modules\admin\permissions\ManageSettings::className()]

View File

@ -37,7 +37,10 @@ class GroupController extends Controller
return parent::init();
}
public static function getAccessRules()
/**
* @inheritdoc
*/
public function getAccessRules()
{
return [
['permissions' => \humhub\modules\admin\permissions\ManageGroups::className()]
@ -128,12 +131,12 @@ class GroupController extends Controller
$this->forcePostRequest();
$group = Group::findOne(['id' => Yii::$app->request->get('id')]);
$group->removeUser(Yii::$app->request->get('userId'));
if(Yii::$app->request->isAjax) {
Yii::$app->response->format = 'json';
return ['success' => true];
}
return $this->redirect(['/admin/group/manage-group-users', 'id' => $group->id]);
}
@ -204,9 +207,9 @@ class GroupController extends Controller
$subQuery = (new \yii\db\Query())->select('*')->from(GroupUser::tableName(). ' g')->where([
'and', 'g.user_id=user.id', ['g.group_id' => $group->id]]);
$query = User::find()->where(['not exists', $subQuery]);
$result = UserPicker::filter([
'keyword' => $keyword,
'query' => $query,

View File

@ -13,7 +13,7 @@ use humhub\modules\admin\components\Controller;
/**
* IndexController is the admin section start point.
*
*
* @since 0.5
*/
class IndexController extends Controller
@ -24,7 +24,10 @@ class IndexController extends Controller
*/
public $adminOnly = false;
public static function getAccessRules()
/**
* @inheritdoc
*/
public function getAccessRules()
{
return [
['permissions' => Yii::$app->getModule('admin')->getPermissions()]

View File

@ -14,12 +14,12 @@ use humhub\modules\admin\libs\HumHubAPI;
/**
* Informations
*
*
* @since 0.5
*/
class InformationController extends Controller
{
/**
* @inheritdoc
*/
@ -35,8 +35,11 @@ class InformationController extends Controller
$this->subLayout = '@admin/views/layouts/information';
return parent::init();
}
public static function getAccessRules()
/**
* @inheritdoc
*/
public function getAccessRules()
{
return [
['permissions' => \humhub\modules\admin\permissions\SeeAdminInformation::className()]

View File

@ -32,7 +32,10 @@ class LoggingController extends Controller
return parent::init();
}
public static function getAccessRules()
/**
* @inheritdoc
*/
public function getAccessRules()
{
return [
['permissions' => \humhub\modules\admin\permissions\SeeAdminInformation::className()]

View File

@ -39,7 +39,10 @@ class ModuleController extends Controller
return parent::init();
}
public static function getAccessRules()
/**
* @inheritdoc
*/
public function getAccessRules()
{
return [
['permissions' => \humhub\modules\admin\permissions\ManageModules::className()]
@ -333,7 +336,7 @@ class ModuleController extends Controller
$userDefaultModule->state = $model->userDefaultState;
if (!$userDefaultModule->save()) {
throw new HttpException('Could not save: ' . print_r($userDefaultModule->getErrors(), 1));
}
}
}
return $this->renderModalClose();

View File

@ -55,7 +55,7 @@ class SettingController extends Controller
/**
* @inheritdoc
*/
public static function getAccessRules()
public function getAccessRules()
{
return [
['permissions' => \humhub\modules\admin\permissions\ManageSettings::className()]

View File

@ -36,7 +36,10 @@ class SpaceController extends Controller
return parent::init();
}
public static function getAccessRules()
/**
* @inheritdoc
*/
public function getAccessRules()
{
return [
['permissions' => [

View File

@ -23,7 +23,7 @@ use humhub\modules\admin\permissions\ManageSettings;
/**
* User management
*
*
* @since 0.5
*/
class UserController extends Controller
@ -41,7 +41,10 @@ class UserController extends Controller
return parent::init();
}
public static function getAccessRules()
/**
* @inheritdoc
*/
public function getAccessRules()
{
return [
['permissions' => [
@ -176,9 +179,9 @@ class UserController extends Controller
return $this->render('edit', array('hForm' => $form, 'user' => $user));
}
public function canBecomeUser($user) {
return Yii::$app->user->isAdmin()
return Yii::$app->user->isAdmin()
&& $user->id != Yii::$app->user->getIdentity()->id
&& !$user->isSystemAdmin();
}

View File

@ -19,7 +19,7 @@ use humhub\modules\user\models\fieldtype\BaseType;
/**
* UserprofileController provides manipulation of the user's profile fields & categories.
*
*
* @since 0.5
*/
class UserProfileController extends Controller
@ -40,7 +40,10 @@ class UserProfileController extends Controller
return parent::init();
}
public static function getAccessRules()
/**
* @inheritdoc
*/
public function getAccessRules()
{
return [
['permissions' => \humhub\modules\admin\permissions\ManageUsers::className()]

View File

@ -2,7 +2,7 @@
/**
* Message translations.
*
* This file is automatically generated by 'yii message/extract' command.
* This file is automatically generated by 'yii message/extract-module' command.
* It contains the localizable messages extracted from source code.
* You may modify this file by translating the extracted messages.
*
@ -17,11 +17,12 @@
* NOTE: this file must be saved in UTF-8 encoding.
*/
return [
'Specify your LDAP-backend used to fetch user accounts.' => 'Задайте настройки LDAP-сервера, который будет использоваться для извлечения учетных записей пользователей.',
'A TLS/SSL is strongly favored in production environments to prevent passwords from be transmitted in clear text.' => 'Рекомендуется использовать TLS/SSL шифрование на реальных проектах, чтобы защититься от передачи паролей в открытом виде.',
'Defines the filter to apply, when login is attempted. %s replaces the username in the login action. Example: &quot;(sAMAccountName=%s)&quot; or &quot;(uid=%s)&quot;' => 'Задает фильтр, который должен применяться при попытке входа. %s заменяет имя пользователя во время логина. Например: &quot;(sAMAccountName=%s)&quot; или &quot;(uid=%s)&quot;',
'LDAP Attribute for E-Mail Address. Default: &quotmail&quot;' => 'LDAP Атрибут для E-Mail адреса. По умолчанию: &quotmail&quot;',
'LDAP Attribute for Username. Example: &quotuid&quot; or &quot;sAMAccountName&quot;' => 'LDAP Атрибут для Логина. Пример: & quotuid & Quot; или & Quot; sAMAccountName&quot;',
'Limit access to users meeting this criteria. Example: &quot(objectClass=posixAccount)&quot; or &quot;(&(objectClass=person)(memberOf=CN=Workers,CN=Users,DC=myDomain,DC=com))&quot;' => 'Ограничить доступ к пользователям с указанными критериями. Example: &quot(objectClass=posixAccount)&quot; or &quot;(&(objectClass=person)(memberOf=CN=Workers,CN=Users,DC=myDomain,DC=com))&quot;',
'LDAP Attribute for Username. Example: &quotuid&quot; or &quot;sAMAccountName&quot;' => 'LDAP Атрибут для Логина. Например: &quot;uid&quot; или &quot;sAMAccountName&quot;',
'Limit access to users meeting this criteria. Example: &quot(objectClass=posixAccount)&quot; or &quot;(&(objectClass=person)(memberOf=CN=Workers,CN=Users,DC=myDomain,DC=com))&quot;' => 'Ограничить доступ к пользователям с указанными критериями. Например: &quot;(objectClass=posixAccount)&quot; or &quot;(&(objectClass=person)(memberOf=CN=Workers,CN=Users,DC=myDomain,DC=com))&quot;',
'Save' => 'Сохранить',
'Status: Error! (Message: {message})' => 'Статус: Ошибка! (Текст ошибки: {message})',
'Status: OK! ({userCount} Users)' => 'Статус: OK! ({userCount} Пользователей)',

View File

@ -1,67 +1,77 @@
<?php
use yii\widgets\ActiveForm;
use humhub\compat\CHtml;
/**
* @var $this \yii\web\View
* @var $enabled boolean
* @var $errorMessage string
* @var $model \humhub\modules\admin\models\forms\AuthenticationLdapSettingsForm
* @var $userCount string
*/
use humhub\models\Setting;
use yii\helpers\Html;
use yii\widgets\ActiveForm;
?>
<?php $this->beginContent('@admin/views/authentication/_authenticationLayout.php') ?>
<div class="panel-body">
<div class="help-block">Specify your LDAP-backend used to fetch user accounts.</div>
<div class="help-block">
<?= Yii::t('AdminModule.views_setting_authentication_ldap', 'Specify your LDAP-backend used to fetch user accounts.') ?>
</div>
<br />
<?php if ($enabled): ?>
<?php if ($errorMessage != ""): ?>
<div
class="alert alert-danger"><?php echo Yii::t('AdminModule.views_setting_authentication_ldap', 'Status: Error! (Message: {message})', array('{message}' => $errorMessage)); ?></div>
class="alert alert-danger"><?= Yii::t('AdminModule.views_setting_authentication_ldap', 'Status: Error! (Message: {message})', array('{message}' => $errorMessage)); ?></div>
<?php else: ?>
<div
class="alert alert-success"><?php echo Yii::t('AdminModule.views_setting_authentication_ldap', 'Status: OK! ({userCount} Users)', array('{userCount}' => $userCount)); ?></div>
class="alert alert-success"><?= Yii::t('AdminModule.views_setting_authentication_ldap', 'Status: OK! ({userCount} Users)', array('{userCount}' => $userCount)); ?></div>
<?php endif; ?>
<?php endif; ?>
<?php $form = ActiveForm::begin(['id' => 'authentication-settings-form']); ?>
<?php echo $form->field($model, 'enabled')->checkbox(['readonly' => Setting::IsFixed('auth.ldap.enabled', 'user')]); ?>
<?= $form->field($model, 'enabled')->checkbox(['readonly' => Setting::IsFixed('auth.ldap.enabled', 'user')]); ?>
<hr>
<?php echo $form->field($model, 'hostname')->textInput(['readonly' => Setting::IsFixed('auth.ldap.hostname', 'user')]); ?>
<?= $form->field($model, 'hostname')->textInput(['readonly' => Setting::IsFixed('auth.ldap.hostname', 'user')]); ?>
<?php echo $form->field($model, 'port')->textInput(['readonly' => Setting::IsFixed('auth.ldap.port', 'user')]); ?>
<?= $form->field($model, 'port')->textInput(['readonly' => Setting::IsFixed('auth.ldap.port', 'user')]); ?>
<?php echo $form->field($model, 'encryption')->dropDownList($model->encryptionTypes, ['readonly' => Setting::IsFixed('auth.ldap.encryption', 'user')]); ?>
<p class="help-block"><?php echo Yii::t('AdminModule.views_setting_authentication_ldap', 'A TLS/SSL is strongly favored in production environments to prevent passwords from be transmitted in clear text.'); ?></p>
<?= $form->field($model, 'encryption')->dropDownList($model->encryptionTypes, ['readonly' => Setting::IsFixed('auth.ldap.encryption', 'user')]); ?>
<p class="help-block"><?= Yii::t('AdminModule.views_setting_authentication_ldap', 'A TLS/SSL is strongly favored in production environments to prevent passwords from be transmitted in clear text.'); ?></p>
<?php echo $form->field($model, 'username')->textInput(['readonly' => Setting::IsFixed('auth.ldap.username', 'user')]); ?>
<p class="help-block"><?php echo Yii::t('AdminModule.views_setting_authentication_ldap', 'The default credentials username. Some servers require that this be in DN form. This must be given in DN form if the LDAP server requires a DN to bind and binding should be possible with simple usernames.'); ?></p>
<?= $form->field($model, 'username')->textInput(['readonly' => Setting::IsFixed('auth.ldap.username', 'user')]); ?>
<p class="help-block"><?= Yii::t('AdminModule.views_setting_authentication_ldap', 'The default credentials username. Some servers require that this be in DN form. This must be given in DN form if the LDAP server requires a DN to bind and binding should be possible with simple usernames.'); ?></p>
<?php echo $form->field($model, 'password')->passwordInput(['readonly' => Setting::IsFixed('auth.ldap.password', 'user')]); ?>
<p class="help-block"><?php echo Yii::t('AdminModule.views_setting_authentication_ldap', 'The default credentials password (used only with username above).'); ?></p>
<?= $form->field($model, 'password')->passwordInput(['readonly' => Setting::IsFixed('auth.ldap.password', 'user')]); ?>
<p class="help-block"><?= Yii::t('AdminModule.views_setting_authentication_ldap', 'The default credentials password (used only with username above).'); ?></p>
<?php echo $form->field($model, 'baseDn')->textInput(['readonly' => Setting::IsFixed('auth.ldap.baseDn', 'user')]); ?>
<p class="help-block"><?php echo Yii::t('AdminModule.views_setting_authentication_ldap', 'The default base DN used for searching for accounts.'); ?></p>
<?= $form->field($model, 'baseDn')->textInput(['readonly' => Setting::IsFixed('auth.ldap.baseDn', 'user')]); ?>
<p class="help-block"><?= Yii::t('AdminModule.views_setting_authentication_ldap', 'The default base DN used for searching for accounts.'); ?></p>
<?php echo $form->field($model, 'loginFilter')->textInput(['readonly' => Setting::IsFixed('auth.ldap.loginFilter', 'user')]); ?>
<p class="help-block"><?php echo Yii::t('AdminModule.views_setting_authentication_ldap', 'Defines the filter to apply, when login is attempted. %s replaces the username in the login action. Example: &quot;(sAMAccountName=%s)&quot; or &quot;(uid=%s)&quot;'); ?></p>
<?= $form->field($model, 'loginFilter')->textInput(['readonly' => Setting::IsFixed('auth.ldap.loginFilter', 'user')]); ?>
<p class="help-block"><?= Yii::t('AdminModule.views_setting_authentication_ldap', 'Defines the filter to apply, when login is attempted. %s replaces the username in the login action. Example: &quot;(sAMAccountName=%s)&quot; or &quot;(uid=%s)&quot;'); ?></p>
<?php echo $form->field($model, 'userFilter')->textInput(['readonly' => Setting::IsFixed('auth.ldap.userFilter', 'user')]); ?>
<p class="help-block"><?php echo Yii::t('AdminModule.views_setting_authentication_ldap', 'Limit access to users meeting this criteria. Example: &quot(objectClass=posixAccount)&quot; or &quot;(&(objectClass=person)(memberOf=CN=Workers,CN=Users,DC=myDomain,DC=com))&quot;'); ?></p>
<?= $form->field($model, 'userFilter')->textInput(['readonly' => Setting::IsFixed('auth.ldap.userFilter', 'user')]); ?>
<p class="help-block"><?= Yii::t('AdminModule.views_setting_authentication_ldap', 'Limit access to users meeting this criteria. Example: &quot(objectClass=posixAccount)&quot; or &quot;(&(objectClass=person)(memberOf=CN=Workers,CN=Users,DC=myDomain,DC=com))&quot;'); ?></p>
<?php echo $form->field($model, 'usernameAttribute')->textInput(['readonly' => Setting::IsFixed('auth.ldap.usernameAttribute', 'user')]); ?>
<p class="help-block"><?php echo Yii::t('AdminModule.views_setting_authentication_ldap', 'LDAP Attribute for Username. Example: &quotuid&quot; or &quot;sAMAccountName&quot;'); ?></p>
<?= $form->field($model, 'usernameAttribute')->textInput(['readonly' => Setting::IsFixed('auth.ldap.usernameAttribute', 'user')]); ?>
<p class="help-block"><?= Yii::t('AdminModule.views_setting_authentication_ldap', 'LDAP Attribute for Username. Example: &quotuid&quot; or &quot;sAMAccountName&quot;'); ?></p>
<?php echo $form->field($model, 'emailAttribute')->textInput(['readonly' => Setting::IsFixed('auth.ldap.emailAttribute', 'user')]); ?>
<p class="help-block"><?php echo Yii::t('AdminModule.views_setting_authentication_ldap', 'LDAP Attribute for E-Mail Address. Default: &quotmail&quot;'); ?></p>
<?= $form->field($model, 'emailAttribute')->textInput(['readonly' => Setting::IsFixed('auth.ldap.emailAttribute', 'user')]); ?>
<p class="help-block"><?= Yii::t('AdminModule.views_setting_authentication_ldap', 'LDAP Attribute for E-Mail Address. Default: &quotmail&quot;'); ?></p>
<?php echo $form->field($model, 'refreshUsers')->checkbox(['readonly' => Setting::IsFixed('auth.ldap.refreshUsers', 'user')]); ?>
<?= $form->field($model, 'refreshUsers')->checkbox(['readonly' => Setting::IsFixed('auth.ldap.refreshUsers', 'user')]); ?>
<hr>
<?php echo CHtml::submitButton(Yii::t('AdminModule.views_setting_authentication_ldap', 'Save'), array('class' => 'btn btn-primary', 'data-ui-loader' => "")); ?>
<?= Html::submitButton(Yii::t('AdminModule.views_setting_authentication_ldap', 'Save'),
['class' => 'btn btn-primary', 'data-ui-loader' => ""]); ?>
<?php echo \humhub\widgets\DataSaved::widget(); ?>
<?= \humhub\widgets\DataSaved::widget(); ?>
<?php ActiveForm::end(); ?>
</div>
<?php $this->endContent(); ?>
<?php $this->endContent(); ?>

View File

@ -114,6 +114,12 @@ class ImageConverter
list ($width, $height) = getimagesize($sourceFile);
// get defined memory limit from php_ini
$memoryLimit = ini_get('memory_limit');
// No memory limit set
if ($memoryLimit == -1) {
return;
}
// calc needed size for processing image dimensions in Bytes.
$neededMemory = floor(($width * $height * $bytesPerPixel * $tweakFactor + 1048576) / 1048576);
$maxMemoryAllocation = Yii::$app->getModule('file')->settings->get(self::SETTINGS_NAME_MAX_MEMORY_ALLOCATION);

View File

@ -19,11 +19,11 @@ use humhub\modules\notification\models\forms\NotificationSettings;
* @author Luke
*/
class AdminController extends Controller
{
{
/**
* @inheritdoc
*/
public static function getAccessRules()
public function getAccessRules()
{
return [
['permissions' => \humhub\modules\admin\permissions\ManageSettings::className()]
@ -33,7 +33,7 @@ class AdminController extends Controller
public function actionDefaults()
{
$this->subLayout = '@admin/views/layouts/setting';
$form = new NotificationSettings();
if ($form->load(Yii::$app->request->post()) && $form->save()) {
$this->view->saved();

View File

@ -27,7 +27,7 @@ class Notification extends \humhub\components\ActiveRecord
* @var int number of found grouped notifications
*/
public $group_count;
/*
* @var int number of involved users of grouped notifications
*/
@ -95,7 +95,7 @@ class Notification extends \humhub\components\ActiveRecord
/**
* Returns the business model of this notification
*
*
* @return \humhub\modules\notification\components\BaseNotification
*/
public function getBaseModel($params = [])
@ -111,7 +111,7 @@ class Notification extends \humhub\components\ActiveRecord
->andWhere(['class' => $this->class, 'user_id' => $this->user_id, 'group_key' => $this->group_key])
->one();
$params['originator'] = $params['record']->originator;
} else {
$params['record'] = $this;
}
@ -141,7 +141,7 @@ class Notification extends \humhub\components\ActiveRecord
/**
* Returns space of this notification
*
*
* @deprecated since version 1.1
* @return type
*/
@ -152,7 +152,7 @@ class Notification extends \humhub\components\ActiveRecord
/**
* Returns polymorphic relation linked with this notification
*
*
* @return \humhub\components\ActiveRecord
*/
public function getSourceObject()
@ -166,7 +166,7 @@ class Notification extends \humhub\components\ActiveRecord
/**
* Returns all available notifications of a module identified by its modulename.
*
*
* @return array with format [moduleId => notifications[]]
*/
public static function getModuleNotifications()
@ -196,7 +196,7 @@ class Notification extends \humhub\components\ActiveRecord
/**
* Loads a certain amount ($limit) of grouped notifications from a given id set by $from.
*
*
* @param integer $from notificatoin id which was the last loaded entry.
* @param limit $limit limit count of results.
* @since 1.2
@ -217,7 +217,7 @@ class Notification extends \humhub\components\ActiveRecord
/**
* Finds grouped notifications if $sendWebNotifications is set to 1 we filter only notifications
* with send_web_notifications setting to 1.
*
*
* @return \yii\db\ActiveQuery
*/
public static function findGrouped(User $user = null, $sendWebNotifications = 1)
@ -235,7 +235,24 @@ class Notification extends \humhub\components\ActiveRecord
$query->andWhere(['user_id' => $user->id]);
$query->andWhere(['send_web_notifications' => $sendWebNotifications]);
$query->addGroupBy(['COALESCE(group_key, id)', 'class']);
$query->addGroupBy([
'COALESCE(group_key, id)',
'id',
'class',
'user_id',
'notification.user_id',
'notification.seen',
'notification.source_class',
'notification.source_pk',
'notification.space_id',
'notification.emailed',
'notification.created_at',
'notification.desktop_notified',
'notification.originator_user_id',
'notification.module',
'notification.group_key',
'notification.send_web_notifications',
]);
$query->orderBy(['group_seen' => SORT_ASC, 'group_created_at' => SORT_DESC]);
return $query;
@ -244,7 +261,7 @@ class Notification extends \humhub\components\ActiveRecord
/**
* Finds all grouped unseen notifications for the given user or the current loggedIn user
* if no User instance is provided.
*
*
* @param \humhub\modules\notification\models\User $user
* @since 1.2
*/
@ -257,7 +274,7 @@ class Notification extends \humhub\components\ActiveRecord
/**
* Finds all grouped unseen notifications which were not already sent to the frontend.
*
*
* @param \humhub\modules\notification\models\User $user
* @since 1.2
*/

View File

@ -20,13 +20,25 @@ use humhub\components\behaviors\AccessControl;
class BaseAccountController extends \humhub\components\Controller
{
/**
* @inheritdoc
*/
public $subLayout = "@humhub/modules/user/views/account/_layout";
public function init() {
/**
* @var \humhub\modules\user\models\User the user
*/
public $user;
/**
* @inheritdoc
*/
public function init()
{
$this->appendPageTitle(\Yii::t('UserModule.base', 'My Account'));
return parent::init();
}
/**
* @inheritdoc
*/
@ -46,7 +58,11 @@ class BaseAccountController extends \humhub\components\Controller
*/
public function getUser()
{
return Yii::$app->user->getIdentity();
if ($this->user === null) {
$this->user = Yii::$app->user->getIdentity();
}
return $this->user;
}
}

View File

@ -13,6 +13,8 @@ use yii\web\HttpException;
use humhub\modules\user\components\BaseAccountController;
use humhub\modules\user\models\User;
use humhub\modules\notification\models\forms\NotificationSettings;
use humhub\modules\user\controllers\ImageController;
/**
* AccountController provides all standard actions for the current logged in
* user account.
@ -23,6 +25,9 @@ use humhub\modules\notification\models\forms\NotificationSettings;
class AccountController extends BaseAccountController
{
/**
* @inheritdoc
*/
public function init()
{
$this->setActionTitles([
@ -213,7 +218,7 @@ class AccountController extends BaseAccountController
if (!$user->isModuleEnabled($moduleId)) {
$user->enableModule($moduleId);
}
if (!Yii::$app->request->isAjax) {
return $this->redirect(['/user/account/edit-modules']);
} else {
@ -233,7 +238,7 @@ class AccountController extends BaseAccountController
$user->disableModule($moduleId);
}
if (!Yii::$app->request->isAjax) {
if (!Yii::$app->request->isAjax) {
return $this->redirect(['/user/account/edit-modules']);
} else {
Yii::$app->response->format = 'json';
@ -366,129 +371,57 @@ class AccountController extends BaseAccountController
/**
* Crops the banner image of the user
* @deprecated since version 1.2
*/
public function actionCropBannerImage()
{
$model = new \humhub\models\forms\CropProfileImage();
$profileImage = new \humhub\libs\ProfileBannerImage($this->getUser()->guid);
if ($model->load(Yii::$app->request->post()) && $model->validate()) {
$profileImage->cropOriginal($model->cropX, $model->cropY, $model->cropH, $model->cropW);
return $this->htmlRedirect($this->getUser()->getUrl());
}
return $this->renderAjax('cropBannerImage', ['model' => $model, 'profileImage' => $profileImage, 'user' => $this->getUser()]);
return Yii::$app->runAction('/user/image/crop', ['type' => ImageController::TYPE_PROFILE_BANNER_IMAGE]);
}
/**
* Handle the banner image upload
*
* @deprecated since version 1.2
*/
public function actionBannerImageUpload()
{
\Yii::$app->response->format = 'json';
$model = new \humhub\models\forms\UploadProfileImage();
$json = array();
$files = \yii\web\UploadedFile::getInstancesByName('bannerfiles');
$file = $files[0];
$model->image = $file;
if ($model->validate()) {
$profileImage = new \humhub\libs\ProfileBannerImage($this->getUser()->guid);
$profileImage->setNew($model->image);
$json['error'] = false;
$json['name'] = "";
$json['url'] = $profileImage->getUrl();
$json['size'] = $model->image->size;
$json['deleteUrl'] = "";
$json['deleteType'] = "";
} else {
$json['error'] = true;
$json['errors'] = $model->getErrors();
// Ensure view file backward compatibility prior 1.2
if (isset($_FILES['bannerfiles'])) {
$_FILES['images'] = $_FILES['bannerfiles'];
}
return ['files' => $json];
return Yii::$app->runAction('/user/image/upload', ['type' => ImageController::TYPE_PROFILE_BANNER_IMAGE]);
}
/**
* Handle the profile image upload
*
* @deprecated since version 1.2
*/
public function actionProfileImageUpload()
{
\Yii::$app->response->format = 'json';
$model = new \humhub\models\forms\UploadProfileImage();
$json = array();
$files = \yii\web\UploadedFile::getInstancesByName('profilefiles');
$file = $files[0];
$model->image = $file;
if ($model->validate()) {
$json['error'] = false;
$profileImage = new \humhub\libs\ProfileImage($this->getUser()->guid);
$profileImage->setNew($model->image);
$json['name'] = "";
$json['url'] = $profileImage->getUrl();
$json['size'] = $model->image->size;
$json['deleteUrl'] = "";
$json['deleteType'] = "";
} else {
$json['error'] = true;
$json['errors'] = $model->getErrors();
// Ensure view file backward compatibility prior 1.2
if (isset($_FILES['profilefiles'])) {
$_FILES['images'] = $_FILES['profilefiles'];
}
return array('files' => $json);
return Yii::$app->runAction('/user/image/upload', ['type' => ImageController::TYPE_PROFILE_IMAGE]);
}
/**
* Crops the profile image of the user
* @deprecated since version 1.2
*/
public function actionCropProfileImage()
{
$model = new \humhub\models\forms\CropProfileImage();
$profileImage = new \humhub\libs\ProfileImage($this->getUser()->guid);
if ($model->load(Yii::$app->request->post()) && $model->validate()) {
$profileImage->cropOriginal($model->cropX, $model->cropY, $model->cropH, $model->cropW);
return $this->htmlRedirect($this->getUser()->getUrl());
}
return $this->renderAjax('cropProfileImage', array('model' => $model, 'profileImage' => $profileImage, 'user' => $this->getUser()));
return Yii::$app->runAction('/user/image/crop', ['type' => ImageController::TYPE_PROFILE_IMAGE]);
}
/**
* Deletes the profile image or profile banner
* @deprecated since version 1.2
*/
public function actionDeleteProfileImage()
{
\Yii::$app->response->format = 'json';
$this->forcePostRequest();
$type = Yii::$app->request->get('type', 'profile');
$json = array('type' => $type);
$image = null;
if ($type == 'profile') {
$image = new \humhub\libs\ProfileImage($this->getUser()->guid);
} elseif ($type == 'banner') {
$image = new \humhub\libs\ProfileBannerImage($this->getUser()->guid);
}
if ($image) {
$image->delete();
$json['defaultUrl'] = $image->getUrl();
}
return $json;
return Yii::$app->runAction('/user/image/delete', ['type' => (Yii::$app->request->get('type', 'profile') == 'profile') ? ImageController::TYPE_PROFILE_IMAGE : ImageController::TYPE_PROFILE_BANNER_IMAGE]);
}
/**

View File

@ -0,0 +1,198 @@
<?php
/**
* @link https://www.humhub.org/
* @copyright Copyright (c) 2017 HumHub GmbH & Co. KG
* @license https://www.humhub.com/licences
*/
namespace humhub\modules\user\controllers;
use Yii;
use yii\web\HttpException;
use humhub\models\forms\CropProfileImage;
use humhub\modules\user\models\User;
use humhub\models\forms\UploadProfileImage;
use humhub\libs\ProfileImage;
use humhub\libs\ProfileBannerImage;
use yii\web\UploadedFile;
use humhub\modules\user\components\BaseAccountController;
/**
* ImageController handles user profile or user banner image modifications
*
* @since 1.2
* @author Luke
*/
class ImageController extends BaseAccountController
{
const TYPE_PROFILE_IMAGE = 'image';
const TYPE_PROFILE_BANNER_IMAGE = 'banner';
/**
* @var boolean allow modification of profile image
* Note: this value may be changed via events (e.g. block auto synced images)
*/
public $allowModifyProfileImage = false;
/**
* @var boolean allow modification of profile banner
* Note: this value may be changed via events (e.g. block auto synced images)
*/
public $allowModifyProfileBanner = false;
/**
* @inheritdoc
*/
public function init()
{
if (!Yii::$app->user->isGuest) {
if (Yii::$app->user->getIdentity()->isSystemAdmin() && Yii::$app->getModule('user')->adminCanChangeUserProfileImages) {
$this->allowModifyProfileBanner = true;
$this->allowModifyProfileImage = true;
} elseif (Yii::$app->user->getIdentity()->id == $this->getUser()->id) {
$this->allowModifyProfileBanner = true;
$this->allowModifyProfileImage = true;
}
}
// Make sure to execute this on the end of initialization, to allow events
// to modify the attributes (e.g. allowModifyProfileImage)
parent::init();
}
/**
* Uploads a new image
*
* @param string $type
* @return \yii\web\Response the response
*/
public function actionUpload($type)
{
$model = new UploadProfileImage();
$files = UploadedFile::getInstancesByName('images');
if (isset($files[0])) {
$model->image = $files[0];
}
if (!$model->validate()) {
return $this->asJson(['files' => [
'error' => true,
'errors' => $model->getErrors()
]]);
}
$image = $this->getProfileImage($type);
$image->setNew($model->image);
return $this->asJson(['files' => [
'name' => '',
'deleteUrl' => '',
'deleteType' => '',
'size' => $model->image->size,
'url' => $image->getUrl(),
]]);
}
/**
* Crops a image
*
* @param string $type
* @return \yii\web\Response the response
*/
public function actionCrop($type)
{
$model = new CropProfileImage();
if ($type == static::TYPE_PROFILE_IMAGE) {
$title = Yii::t('UserModule.account', '<strong>Modify</strong> your profile image');
} elseif ($type == static::TYPE_PROFILE_BANNER_IMAGE) {
$title = Yii::t('UserModule.account', '<strong>Modify</strong> your title image');
$model->aspectRatio = '6.3';
$model->cropSetSelect = [0, 0, 267, 48];
}
$image = $this->getProfileImage($type);
if ($model->load(Yii::$app->request->post()) && $model->validate()) {
$image->cropOriginal($model->cropX, $model->cropY, $model->cropH, $model->cropW);
return $this->htmlRedirect($this->getUser()->getUrl());
}
return $this->renderAjax('crop', [
'model' => $model,
'profileImage' => $image,
'user' => $this->getUser(),
'type' => $type,
'title' => $title,
]);
}
/**
* Delete an image
*
* @param string $type
* @return \yii\web\Response the response
*/
public function actionDelete($type)
{
Yii::$app->response->format = 'json';
$this->forcePostRequest();
$image = $this->getProfileImage($type);
$image->delete();
return $this->asJson([
'type' => $type,
'defaultUrl' => $image->getUrl()
]);
}
/**
* Returns the Profile Image
*
* @param string $type
* @return ProfileImage|ProfileBannerImage
* @throws HttpException
*/
protected function getProfileImage($type)
{
if ($type == static::TYPE_PROFILE_IMAGE) {
if (!$this->allowModifyProfileImage) {
throw new HttpException(403, 'Access denied!');
}
return new ProfileImage($this->getUser()->guid);
} elseif ($type == static::TYPE_PROFILE_BANNER_IMAGE) {
if (!$this->allowModifyProfileBanner) {
throw new HttpException(403, 'Access denied!');
}
return new ProfileBannerImage($this->getUser()->guid);
} else {
throw new HttpException(400, 'Invalid image type given!');
}
}
/**
* Returns the current user of this account
*
* An administration can also pass a user id via GET parameter to change users
* accounts settings.
*
* @return User the user
*/
public function getUser()
{
if ($this->user === null && Yii::$app->request->get('userGuid') != '' && Yii::$app->user->getIdentity()->isSystemAdmin()) {
$user = User::findOne(['guid' => Yii::$app->request->get('userGuid')]);
if ($user === null) {
throw new HttpException(404, 'Could not find user!');
}
$this->user = $user;
}
return parent::getUser();
}
}

View File

@ -1,88 +0,0 @@
<?php
use humhub\compat\CActiveForm;
use yii\helpers\Url;
?>
<div class="modal-dialog modal-dialog-small animated fadeIn">
<div class="modal-content">
<?php $form = CActiveForm::begin(['id' => 'profile-crop-image-form']); ?>
<?php echo $form->errorSummary($model); ?>
<?php echo $form->hiddenField($model, 'cropX', ['id' => 'cropX']); ?>
<?php echo $form->hiddenField($model, 'cropY', ['id' => 'cropY']); ?>
<?php echo $form->hiddenField($model, 'cropW', ['id' => 'cropW']); ?>
<?php echo $form->hiddenField($model, 'cropH', ['id' => 'cropH']); ?>
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
<h4 class="modal-title"
id="myModalLabel"><?php echo Yii::t('UserModule.views_profile_cropProfileImage', '<strong>Modify</strong> your profile image'); ?></h4>
</div>
<div class="modal-body">
<style>
/* Dirty Workaround against bootstrap and jcrop */
img {
max-width: none;
}
.jcrop-keymgr {
display: none !important;
}
</style>
<div id="cropimage">
<?php
echo \yii\helpers\Html::img($profileImage->getUrl('_org'), ['id' => 'foobar']);
echo raoul2000\jcrop\JCropWidget::widget([
'selector' => '#foobar',
'pluginOptions' => [
'aspectRatio' => 1,
'minSize' => [50, 50],
//'maxSize' => [200, 200],
'setSelect' => [0, 0, 100, 100],
'bgColor' => 'black',
'bgOpacity' => '0.5',
'boxWidth' => '440',
'onChange' => new yii\web\JsExpression('function(c){ $("#cropX").val(c.x);$("#cropY").val(c.y);$("#cropW").val(c.w);$("#cropH").val(c.h); }')
]
]);
?>
</div>
</div>
<div class="modal-footer">
<?php
echo \humhub\widgets\AjaxButton::widget([
'label' => Yii::t('UserModule.views_profile_cropProfileImage', 'Save'),
'ajaxOptions' => [
'type' => 'POST',
'id' => 'blabla',
'beforeSend' => new yii\web\JsExpression('function(){ setModalLoader(); }'),
'success' => new yii\web\JsExpression('function(html){ $("#globalModal").html(html); }'),
'url' => Url::toRoute(['/user/account/crop-profile-image', 'userGuid' => $user->guid]),
],
'htmlOptions' => [
'class' => 'btn btn-primary'
]
]);
?>
<button type="button" class="btn btn-primary"
data-dismiss="modal"><?php echo Yii::t('UserModule.views_profile_cropProfileImage', 'Close'); ?></button>
<?php echo \humhub\widgets\LoaderWidget::widget(['id' => 'crop-loader', 'cssClass' => 'loader-modal hidden']); ?>
</div>
<?php echo \humhub\widgets\DataSaved::widget(); ?>
<?php CActiveForm::end(); ?>
</div>
</div>

View File

@ -14,19 +14,14 @@ use yii\helpers\Url;
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
<h4 class="modal-title"
id="myModalLabel"><?php echo Yii::t('UserModule.views_profile_cropBannerImage', '<strong>Modify</strong> your title image'); ?></h4>
id="myModalLabel"><?= $title; ?></h4>
</div>
<div class="modal-body">
<style>
/* Dirty Workaround against bootstrap and jcrop */
img {
max-width: none;
}
</style>
<div id="cropimage">
@ -36,10 +31,9 @@ use yii\helpers\Url;
echo raoul2000\jcrop\JCropWidget::widget([
'selector' => '#foobar',
'pluginOptions' => [
'aspectRatio' => '6.3',
'aspectRatio' => $model->aspectRatio,
'minSize' => [50, 50],
//'maxSize' => [200, 200],
'setSelect' => [0, 0, 267, 48],
'setSelect' => $model->cropSetSelect,
'bgColor' => 'black',
'boxWidth' => '440',
'bgOpacity' => '0.5',
@ -59,7 +53,7 @@ use yii\helpers\Url;
'type' => 'POST',
'beforeSend' => new yii\web\JsExpression('function(){ setModalLoader(); }'),
'success' => new yii\web\JsExpression('function(html){ $("#globalModal").html(html); }'),
'url' => Url::to(['/user/account/crop-banner-image', 'userGuid' => $user->guid]),
'url' => Url::to(['/user/image/crop', 'userGuid' => $user->guid, 'type' => $type]),
],
'htmlOptions' => [
'class' => 'btn btn-primary'

View File

@ -2,7 +2,7 @@
/**
* @link https://www.humhub.org/
* @copyright Copyright (c) 2016 HumHub GmbH & Co. KG
* @copyright Copyright (c) 2017 HumHub GmbH & Co. KG
* @license https://www.humhub.com/licences
*/
@ -13,6 +13,7 @@ use humhub\modules\space\models\Space;
use humhub\modules\user\models\User;
use humhub\modules\space\models\Membership;
use humhub\modules\friendship\models\Friendship;
use humhub\modules\user\controllers\ImageController;
/**
* Displays the profile header of a user
@ -45,13 +46,8 @@ class ProfileHeader extends \yii\base\Widget
$this->user = $this->getController()->getUser();
}
// Check if profile header can be edited
if (!Yii::$app->user->isGuest) {
if (Yii::$app->user->getIdentity()->isSystemAdmin() && Yii::$app->getModule('user')->adminCanChangeUserProfileImages) {
$this->isProfileOwner = true;
} elseif (Yii::$app->user->id == $this->user->id) {
$this->isProfileOwner = true;
}
if (!Yii::$app->user->isGuest && Yii::$app->user->id == $this->user->id) {
$this->isProfileOwner = true;
}
parent::init();
@ -71,10 +67,8 @@ class ProfileHeader extends \yii\base\Widget
$countFollowing = $this->user->getFollowingCount(User::className());
$countUserSpaces = Membership::getUserSpaceQuery($this->user)
->andWhere(['!=', 'space.visibility', Space::VISIBILITY_NONE])
->andWhere(['space.status' => Space::STATUS_ENABLED])
->count();
/* @var $imageController ImageController */
$imageController = new ImageController('image-controller', null, ['user' => $this->user]);
return $this->render('profileHeader', array(
'user' => $this->user,
@ -83,10 +77,25 @@ class ProfileHeader extends \yii\base\Widget
'countFriends' => $countFriends,
'countFollowers' => $this->user->getFollowerCount(),
'countFollowing' => $countFollowing,
'countSpaces' => $countUserSpaces,
'countSpaces' => $this->getFollowingSpaceCount(),
'allowModifyProfileImage' => $imageController->allowModifyProfileImage,
'allowModifyProfileBanner' => $imageController->allowModifyProfileBanner,
));
}
/**
* Returns the number of followed public space
*
* @return int the follow count
*/
protected function getFollowingSpaceCount()
{
return Membership::getUserSpaceQuery($this->user)
->andWhere(['!=', 'space.visibility', Space::VISIBILITY_NONE])
->andWhere(['space.status' => Space::STATUS_ENABLED])
->count();
}
}
?>

View File

@ -2,13 +2,14 @@
use yii\helpers\Html;
use yii\helpers\Url;
use humhub\modules\user\controllers\ImageController;
if ($isProfileOwner) {
if ($allowModifyProfileBanner || $allowModifyProfileImage) {
$this->registerJsFile('@web-static/resources/user/profileHeaderImageUpload.js');
$this->registerJs("var profileImageUploaderUserGuid='" . $user->guid . "';", \yii\web\View::POS_BEGIN);
$this->registerJs("var profileImageUploaderCurrentUserGuid='" . Yii::$app->user->getIdentity()->guid . "';", \yii\web\View::POS_BEGIN);
$this->registerJs("var profileImageUploaderUrl='" . Url::to(['/user/account/profile-image-upload', 'userGuid' => $user->guid]) . "';", \yii\web\View::POS_BEGIN);
$this->registerJs("var profileHeaderUploaderUrl='" . Url::to(['/user/account/banner-image-upload', 'userGuid' => $user->guid]) . "';", \yii\web\View::POS_BEGIN);
$this->registerJs("var profileImageUploaderUrl='" . Url::to(['/user/image/upload', 'userGuid' => $user->guid, 'type' => ImageController::TYPE_PROFILE_IMAGE]) . "';", \yii\web\View::POS_BEGIN);
$this->registerJs("var profileHeaderUploaderUrl='" . Url::to(['/user/image/upload', 'userGuid' => $user->guid, 'type' => ImageController::TYPE_PROFILE_BANNER_IMAGE]) . "';", \yii\web\View::POS_BEGIN);
}
?>
<div class="panel panel-default panel-profile">
@ -22,10 +23,10 @@ if ($isProfileOwner) {
width="100%" style="width: 100%; max-height: 192px;">
<!-- check if the current user is the profile owner and can change the images -->
<?php if ($isProfileOwner) : ?>
<?php if ($allowModifyProfileBanner) : ?>
<form class="fileupload" id="bannerfileupload" action="" method="POST" enctype="multipart/form-data"
style="position: absolute; top: 0; left: 0; opacity: 0; width: 100%; height: 100%;">
<input type="file" name="bannerfiles[]">
<input type="file" name="images[]">
</form>
<?php
@ -59,7 +60,7 @@ if ($isProfileOwner) {
</div>
<!-- check if the current user is the profile owner and can change the images -->
<?php if ($isProfileOwner): ?>
<?php if ($allowModifyProfileBanner): ?>
<div class="image-upload-buttons" id="banner-image-upload-buttons">
<a href="#" onclick="javascript:$('#bannerfileupload input').click();"
class="btn btn-info btn-sm"><i
@ -70,7 +71,7 @@ if ($isProfileOwner) {
echo 'display: none;';
}
?>"
href="<?php echo Url::to(['/user/account/crop-banner-image', 'userGuid' => $user->guid]); ?>"
href="<?php echo Url::to(['/user/image/crop', 'userGuid' => $user->guid, 'type' => ImageController::TYPE_PROFILE_BANNER_IMAGE]); ?>"
class="btn btn-info btn-sm" data-target="#globalModal" data-backdrop="static"><i
class="fa fa-edit"></i></a>
<?php
@ -84,7 +85,7 @@ if ($isProfileOwner) {
'linkContent' => '<i class="fa fa-times"></i>',
'cssClass' => 'btn btn-danger btn-sm',
'style' => $user->getProfileBannerImage()->hasImage() ? '' : 'display: none;',
'linkHref' => Url::to(["/user/account/delete-profile-image", 'type' => 'banner', 'userGuid' => $user->guid]),
'linkHref' => Url::to(['/user/image/delete', 'userGuid' => $user->guid, 'type' => ImageController::TYPE_PROFILE_BANNER_IMAGE]),
'confirmJS' => 'function(jsonResp) { resetProfileImage(jsonResp); }'
));
?>
@ -107,10 +108,10 @@ if ($isProfileOwner) {
<?php endif; ?>
<!-- check if the current user is the profile owner and can change the images -->
<?php if ($isProfileOwner) : ?>
<?php if ($allowModifyProfileImage) : ?>
<form class="fileupload" id="profilefileupload" action="" method="POST" enctype="multipart/form-data"
style="position: absolute; top: 0; left: 0; opacity: 0; height: 140px; width: 140px;">
<input type="file" name="profilefiles[]">
<input type="file" name="images[]">
</form>
<div class="image-upload-loader" id="profile-image-upload-loader" style="padding-top: 60px;">
@ -131,7 +132,7 @@ if ($isProfileOwner) {
echo 'display: none;';
}
?>"
href="<?php echo Url::to(['/user/account/crop-profile-image', 'userGuid' => $user->guid]); ?>"
href="<?php echo Url::to(['/user/image/crop', 'userGuid' => $user->guid, 'type' => ImageController::TYPE_PROFILE_IMAGE]); ?>"
class="btn btn-info btn-sm" data-target="#globalModal" data-backdrop="static"><i
class="fa fa-edit"></i></a>
<?php
@ -145,7 +146,7 @@ if ($isProfileOwner) {
'linkContent' => '<i class="fa fa-times"></i>',
'cssClass' => 'btn btn-danger btn-sm',
'style' => $user->getProfileImage()->hasImage() ? '' : 'display: none;',
'linkHref' => Url::to(["/user/account/delete-profile-image", 'type' => 'profile', 'userGuid' => $user->guid]),
'linkHref' => Url::to(["/user/image/delete", 'type' => ImageController::TYPE_PROFILE_IMAGE, 'userGuid' => $user->guid]),
'confirmJS' => 'function(jsonResp) { resetProfileImage(jsonResp); }'
));
?>

View File

@ -1,10 +1,10 @@
/**
* Handle Image Upload
*/
$(document).on('ready pjax:success', function() {
$(document).on('ready pjax:success', function () {
'use strict';
$('.fileupload').each(function() {
$('.fileupload').each(function () {
if ($(this).attr('id') == "profilefileupload") {
@ -19,18 +19,18 @@ $(document).on('ready pjax:success', function() {
singleFileUploads: true,
//formData: {'CSRF_TOKEN': csrfValue},
limitMultiFileUploads: 1,
progressall: function(e, data) {
progressall: function (e, data) {
var progress = parseInt(data.loaded / data.total * 100, 10);
$('#profile-image-upload-bar .progress-bar').css('width', progress + '%');
},
done: function(e, data) {
done: function (e, data) {
if (data.result.files.error == true) {
handleUploadError(data.result);
} else {
if (profileImageUploaderUserGuid === profileImageUploaderCurrentUserGuid) {
$('#user-account-image').attr('src', data.result.files.url + '&c=' + Math.random());
}
}
$('#user-profile-image').attr('src', data.result.files.url + '&c=' + Math.random());
$('.user-' + profileImageUploaderUserGuid).attr('src', data.result.files.url + '&c=' + Math.random());
$('#user-profile-image').addClass('animated bounceIn');
@ -43,9 +43,9 @@ $(document).on('ready pjax:success', function() {
}
}).bind('fileuploadstart', function(e) {
}).bind('fileuploadstart', function (e) {
$('#profile-image-upload-loader').show();
}).bind('fileuploadstart', function(e) {
}).bind('fileuploadstart', function (e) {
$('#user-profile-image').removeClass('animated bounceIn');
})
@ -61,11 +61,11 @@ $(document).on('ready pjax:success', function() {
singleFileUploads: true,
//formData: {'CSRF_TOKEN': csrfValue},
limitMultiFileUploads: 1,
progressall: function(e, data) {
progressall: function (e, data) {
var progress = parseInt(data.loaded / data.total * 100, 10);
$('#banner-image-upload-bar .progress-bar').css('width', progress + '%');
},
done: function(e, data) {
done: function (e, data) {
if (data.result.files.error == true) {
handleUploadError(data.result);
@ -79,9 +79,9 @@ $(document).on('ready pjax:success', function() {
$('#banner-image-upload-loader').hide();
$('#banner-image-upload-bar .progress-bar').css('width', '0%');
}
}).bind('fileuploadstart', function(e) {
}).bind('fileuploadstart', function (e) {
$('#banner-image-upload-loader').show();
}).bind('fileuploadstart', function(e) {
}).bind('fileuploadstart', function (e) {
$('#user-banner-image').removeClass('animated bounceIn');
})
@ -107,7 +107,7 @@ function handleUploadError(json) {
function resetProfileImage(json) {
if (json.type == 'profile') {
if (json.type == 'image') {
$('#user-profile-image img').attr('src', json.defaultUrl);
$('#user-profile-image').attr('src', json.defaultUrl);
$('#deleteLinkPost_modal_profileimagedelete').hide();
@ -121,41 +121,41 @@ function resetProfileImage(json) {
$('.image-upload-buttons').hide();
}
$(document).on('ready pjax:success', function() {
$(document).on('ready pjax:success', function () {
// override standard drag and drop behavior
$(document).off('drop.humhub dragover.humhub').on('drop.humhub dragover.humhub', function(e) {
$(document).off('drop.humhub dragover.humhub').on('drop.humhub dragover.humhub', function (e) {
e.preventDefault();
});
// show buttons at image rollover
$('#profilefileupload').mouseover(function() {
$('#profilefileupload').mouseover(function () {
$('#profile-image-upload-buttons').show();
})
// show buttons also at buttons rollover (better: prevent the mouseleave event)
$('#profile-image-upload-buttons').mouseover(function() {
$('#profile-image-upload-buttons').mouseover(function () {
$('#profile-image-upload-buttons').show();
});
// hide buttons at image mouse leave
$('#profilefileupload').mouseleave(function() {
$('#profilefileupload').mouseleave(function () {
$('#profile-image-upload-buttons').hide();
})
// show buttons at image rollover
$('#bannerfileupload, .img-profile-data').mouseover(function() {
$('#bannerfileupload, .img-profile-data').mouseover(function () {
$('#banner-image-upload-buttons').show();
})
// show buttons also at buttons rollover (better: prevent the mouseleave event)
$('#banner-image-upload-buttons').mouseover(function() {
$('#banner-image-upload-buttons').mouseover(function () {
$('#banner-image-upload-buttons').show();
})
// hide buttons at image mouse leave
$('#bannerfileupload, .img-profile-data').mouseleave(function() {
$('#bannerfileupload, .img-profile-data').mouseleave(function () {
$('#banner-image-upload-buttons').hide();
})