Merge branch 'master' of github.com:humhub/humhub

This commit is contained in:
buddh4 2017-02-14 16:30:09 +01:00
commit 237b043b47
14 changed files with 432 additions and 25 deletions

View File

@ -226,7 +226,15 @@ class View extends \yii\web\View
$value = Html::encode(array_values($viewStatus)[0]);
$this->registerJs('humhub.modules.ui.status.' . $type . '("' . $value . '")', View::POS_END, 'viewStatusMessage');
}
if (Yii::$app->session->hasFlash('executeJavascript')) {
$position = self::POS_READY;
if (Yii::$app->session->hasFlash('executeJavascriptPosition')) {
$position = Yii::$app->session->hasFlash('executeJavascriptPosition');
}
$this->registerJs(Yii::$app->session->getFlash('executeJavascript'));
}
if (Yii::$app->request->isPjax) {
echo \humhub\widgets\LayoutAddons::widget();
$this->flushJsConfig();

View File

@ -27,6 +27,8 @@ HumHub Change Log
- Enh: TopMenu / TopMenuRightStack hide content when user is not logged in without guest mode
- Enh: Added showUserName option in AccountTopMenu widget
- Enh: Added isGuestAccessEnabled method in User component
- Enh: Added flash variable (executeJavascript)to execute js on the next page load
- Enh: Added possibility to create own file handlers (edit, create, import, export)
1.2.0-beta.1 (February 08, 2017)
--------------------------------

View File

@ -16,6 +16,7 @@ use humhub\modules\space\models\Space;
use humhub\modules\content\models\Content;
use humhub\modules\content\components\ContentContainerActiveRecord;
use humhub\modules\content\components\ContentActiveRecord;
use humhub\modules\file\handler\FileHandlerCollection;
/**
* WallCreateContentForm is the base widget to create "quick" create content forms above Stream/Wall.
@ -87,13 +88,17 @@ class WallCreateContentForm extends Widget
$defaultVisibility = Content::VISIBILITY_PRIVATE;
}
$fileHandlerImport = FileHandlerCollection::getByType(FileHandlerCollection::TYPE_IMPORT);
$fileHandlerCreate = FileHandlerCollection::getByType(FileHandlerCollection::TYPE_CREATE);
return $this->render('@humhub/modules/content/widgets/views/wallCreateContentForm', array(
'form' => $this->renderForm(),
'contentContainer' => $this->contentContainer,
'submitUrl' => $this->contentContainer->createUrl($this->submitUrl),
'submitButtonText' => $this->submitButtonText,
'defaultVisibility' => $defaultVisibility,
'canSwitchVisibility' => $canSwitchVisibility
'canSwitchVisibility' => $canSwitchVisibility,
'fileHandlers' => array_merge($fileHandlerCreate, $fileHandlerImport),
));
}

View File

@ -17,19 +17,21 @@ $this->registerJsConfig('content.form', [
<div class="panel panel-default clearfix">
<div class="panel-body" id="contentFormBody" style="display:none;" data-action-component="content.form.CreateForm" >
<?= Html::beginForm($submitUrl, 'POST'); ?>
<?= Html::beginForm($submitUrl, 'POST'); ?>
<?= $form; ?>
<div id="notifyUserContainer" class="form-group" style="margin-top: 15px;display:none;">
<?= humhub\modules\user\widgets\UserPickerField::widget([
<?=
humhub\modules\user\widgets\UserPickerField::widget([
'id' => 'notifyUserInput',
'url' => ($contentContainer instanceof Space) ? $contentContainer->createUrl('/space/membership/search') : null,
'formName' => 'notifyUserInput',
'maxSelection' => 10,
'disabledItems' => [Yii::$app->user->guid],
'placeholder' => Yii::t('ContentModule.widgets_views_contentForm', 'Add a member to notify'),
])?>
])
?>
</div>
<?= Html::hiddenInput("containerGuid", $contentContainer->guid); ?>
@ -44,12 +46,15 @@ $this->registerJsConfig('content.form', [
<?= $submitButtonText ?>
</button>
<?= humhub\modules\file\widgets\UploadButton::widget([
'id' => 'contentFormFiles',
'progress' => '#contentFormFiles_progress',
'preview' => '#contentFormFiles_preview',
'dropZone' => '#contentFormBody'
])?>
<?php
$uploadButton = humhub\modules\file\widgets\UploadButton::widget([
'id' => 'contentFormFiles',
'progress' => '#contentFormFiles_progress',
'preview' => '#contentFormFiles_preview',
'dropZone' => '#contentFormBody'
]);
?>
<?= humhub\modules\file\widgets\FileHandlerButtonDropdown::widget(['primaryButton' => $uploadButton, 'handlers' => $fileHandlers, 'cssButtonClass' => 'btn-default']); ?>
<!-- public checkbox -->
<?php echo Html::checkbox("visibility", "", array('id' => 'contentForm_visibility', 'class' => 'contentForm hidden')); ?>
@ -82,12 +87,12 @@ $this->registerJsConfig('content.form', [
</div>
</div>
<?= \humhub\modules\file\widgets\UploadProgress::widget(['id' => 'contentFormFiles_progress']) ?>
<?= \humhub\modules\file\widgets\FilePreview::widget(['id' => 'contentFormFiles_preview', 'edit' => true, 'options' => ['style' => 'margin-top:10px;']]); ?>
<?= \humhub\modules\file\widgets\UploadProgress::widget(['id' => 'contentFormFiles_progress']) ?>
<?= \humhub\modules\file\widgets\FilePreview::widget(['id' => 'contentFormFiles_preview', 'edit' => true, 'options' => ['style' => 'margin-top:10px;']]); ?>
</div>
<!-- /contentForm_Options -->
<?php echo Html::endForm(); ?>
<?php echo Html::endForm(); ?>
</div>
<!-- /panel body -->
</div> <!-- /panel -->

View File

@ -140,6 +140,7 @@ class UploadAction extends Action
'mimeIcon' => MimeHelper::getMimeIconClassByExtension(FileHelper::getExtension($file->file_name)),
'size_format' => Yii::$app->formatter->asSize($file->size),
'url' => $file->getUrl(),
'openLink' => FileHelper::createLink($file),
'thumbnailUrl' => $thumbnailUrl,
];
}

View File

@ -33,13 +33,16 @@ class FileController extends \humhub\components\Controller
'class' => AccessControl::className(),
'guestAllowedActions' => ['download']
],
'httpCache' => [
'class' => 'yii\filters\HttpCache',
'cacheControlHeader' => 'public, max-age=31536000',
'etagSeed' => function ($action, $params) {
return serialize([\yii\helpers\Url::current()]);
},
],
/*
'httpCache' => [
'class' => 'yii\filters\HttpCache',
'only' => ['download'],
'cacheControlHeader' => 'public, max-age=31536000',
'etagSeed' => function ($action, $params) {
return serialize([\yii\helpers\Url::current()]);
},
],
*/
];
}
@ -74,7 +77,7 @@ class FileController extends \humhub\components\Controller
}
$file->delete();
Yii::$app->response->format = 'json';
return ['success' => true];
}

View File

@ -0,0 +1,65 @@
<?php
/**
* @link https://www.humhub.org/
* @copyright Copyright (c) 2017 HumHub GmbH & Co. KG
* @license https://www.humhub.com/licences
*/
namespace humhub\modules\file\controllers;
use Yii;
use yii\web\HttpException;
use humhub\components\behaviors\AccessControl;
use humhub\modules\file\models\File;
use humhub\modules\file\handler\FileHandlerCollection;
/**
* ViewControllers provides the open modal for files
*
* @since 1.2
*/
class ViewController extends \humhub\components\Controller
{
/**
* @inheritdoc
*/
public function behaviors()
{
return [
'acl' => [
'class' => AccessControl::className(),
'guestAllowedActions' => ['view']
],
];
}
public function actionIndex()
{
$guid = Yii::$app->request->get('guid');
$file = File::findOne(['guid' => $guid]);
if ($file == null) {
throw new HttpException(404, Yii::t('FileModule.base', 'Could not find requested file!'));
}
$viewHandler = FileHandlerCollection::getByType(FileHandlerCollection::TYPE_VIEW, $file);
$exportHandler = FileHandlerCollection::getByType(FileHandlerCollection::TYPE_EXPORT, $file);
$editHandler = [];
$importHandler = [];
if ($file->canDelete()) {
$editHandler = FileHandlerCollection::getByType(FileHandlerCollection::TYPE_EDIT, $file);
$importHandler = FileHandlerCollection::getByType(FileHandlerCollection::TYPE_IMPORT, $file);
}
return $this->renderAjax('index', [
'file' => $file,
'importHandler' => $importHandler,
'exportHandler' => $exportHandler,
'editHandler' => $editHandler,
'viewHandler' => $viewHandler
]);
}
}

View File

@ -0,0 +1,33 @@
<?php
/**
* @link https://www.humhub.org/
* @copyright Copyright (c) 2017 HumHub GmbH & Co. KG
* @license https://www.humhub.com/licences
*/
namespace humhub\modules\file\handler;
/**
* BaseFileHandler
*
* @since 1.2
* @author Luke
*/
abstract class BaseFileHandler extends \yii\base\Component
{
/**
* @var \humhub\modules\file\models\File the file
*/
public $file;
/**
* The file handler link
*
* @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered.
* @see \humhub\modules\file\widgets\FileHandlerButtonDropdown
* @return array the HTML attributes of the button.
*/
abstract public function getLinkAttributes();
}

View File

@ -0,0 +1,35 @@
<?php
/**
* @link https://www.humhub.org/
* @copyright Copyright (c) 2017 HumHub GmbH & Co. KG
* @license https://www.humhub.com/licences
*/
namespace humhub\modules\file\handler;
use Yii;
use yii\helpers\Url;
/**
* DownloadFileHandler provides the download link for a file
*
* @since 1.2
* @author Luke
*/
class DownloadFileHandler extends BaseFileHandler
{
/**
* @inheritdoc
*/
public function getLinkAttributes()
{
return [
'label' => Yii::t('FileModule.base', 'Download') . ' <small>(' . Yii::$app->formatter->asShortSize($this->file->size, 1) . ')</small>',
'href' => Url::to(['/file/file/download', 'guid' => $this->file->guid]),
'target' => '_blank',
];
}
}

View File

@ -0,0 +1,100 @@
<?php
/**
* @link https://www.humhub.org/
* @copyright Copyright (c) 2017 HumHub GmbH & Co. KG
* @license https://www.humhub.com/licences
*/
namespace humhub\modules\file\handler;
use Yii;
/**
* FileHandlerCollection
*
* @since 1.2
* @author Luke
*/
class FileHandlerCollection extends \yii\base\Component
{
/**
* @event the init event - use to register file handlers
*/
const EVENT_INIT = 'init';
/**
* Collection Types
*/
const TYPE_VIEW = 'view';
const TYPE_IMPORT = 'import';
const TYPE_EXPORT = 'export';
const TYPE_CREATE = 'create';
const TYPE_EDIT = 'edit';
/**
* @var string current collection type
*/
public $type;
/**
* @var \humhub\modules\file\models\File
*/
public $file = null;
/**
* @var type
*/
public $handlers = [];
/**
* @inheritdoc
*/
public function init()
{
parent::init();
$this->trigger(self::EVENT_INIT);
// Register Core Handler
if ($this->type === self::TYPE_VIEW) {
$this->register(Yii::createObject(['class' => DownloadFileHandler::class]));
}
}
/**
* @param \humhub\modules\file\components\BaseFileHandler $handler
*/
public function register(BaseFileHandler $handler)
{
$handler->file = $this->file;
$this->handlers[] = $handler;
}
/**
* Returns registered handlers by type
*
* @param string|array $type or multiple type array
* @param \humhub\modules\file\models\File $file the file (optional)
* @return BaseFileHandler[] the registered handlers
*/
public static function getByType($types, $file = null)
{
$handlers = [];
if (!is_array($types)) {
$types = [$types];
}
foreach ($types as $type) {
$handlers = array_merge($handlers, Yii::createObject([
'class' => self::class,
'file' => $file,
'type' => $type
])->handlers);
}
return $handlers;
}
}

View File

@ -11,6 +11,8 @@ namespace humhub\modules\file\libs;
use humhub\libs\Html;
use yii\helpers\Url;
use humhub\modules\file\models\File;
use humhub\modules\file\handler\FileHandlerCollection;
use humhub\modules\file\handler\DownloadFileHandler;
/**
* FileHelper
@ -54,12 +56,20 @@ class FileHelper extends \yii\helpers\FileHelper
/**
* Creates a file with options
*
* @since 1.2
* @param \humhub\modules\file\models\File $file
* @return string the rendered HTML link
*/
public static function createLink($file, $options = [], $htmlOptions = [])
{
$label = (isset($htmlOptions['label'])) ? $htmlOptions['label'] : Html::encode($file->fileName);
$fileHandlers = FileHandlerCollection::getByType([FileHandlerCollection::TYPE_VIEW, FileHandlerCollection::TYPE_EXPORT, FileHandlerCollection::TYPE_EDIT, FileHandlerCollection::TYPE_IMPORT], $file);
if (count($fileHandlers) === 1 && $fileHandlers[0] instanceof DownloadFileHandler) {
$htmlOptions['target'] = '_blank';
return Html::a($label, Url::to(['/file/file/download', 'guid' => $file->guid]), $htmlOptions);
}
$htmlOptions = array_merge($htmlOptions, ['data-target' => '#globalModal']);
return Html::a($label, Url::to(['/file/view', 'guid' => $file->guid]), $htmlOptions);
}
@ -67,6 +77,7 @@ class FileHelper extends \yii\helpers\FileHelper
/**
* Determines the content container of a File record
*
* @since 1.2
* @param File $file
* @return \humhub\modules\content\components\ContentContainerActiveRecord the content container or null
*/

View File

@ -366,8 +366,8 @@ humhub.module('file', function(module, require, $) {
Preview.template = {
root: '<ul class="files" style="list-style:none; margin:0;padding:0px;"></ul>',
file_edit: '<li class="file-preview-item mime {mimeIcon}" data-preview-guid="{guid}" style="padding-left:24px;display:none;"><span class="file-preview-content">{name}<span class="file_upload_remove_link" data-ui-loader> <i class="fa fa-times-circle"></i>&nbsp;</span></li>',
file: '<li class="file-preview-item mime {mimeIcon}" data-preview-guid="{guid}" style="padding-left:24px;display:none;"><span class="file-preview-content"><a href="{url}" target="_blank"><span class="filename">{name}</span></a><span class="time" style="padding-right: 20px;"> - {size_format}</span></li>',
file_image: '<li class="file-preview-item mime {mimeIcon}" data-preview-guid="{guid}" style="padding-left:24px;display:none;"><span class="file-preview-content"><a href="{url}" data-ui-gallery="{galleryId}"><span class="filename">{name}</span></a><span class="time" style="padding-right: 20px;"> - {size_format}</span></li>',
file: '<li class="file-preview-item mime {mimeIcon}" data-preview-guid="{guid}" style="padding-left:24px;display:none;"><span class="file-preview-content">{openLink}<span class="time" style="padding-right: 20px;"> - {size_format}</span></li>',
file_image: '<li class="file-preview-item mime {mimeIcon}" data-preview-guid="{guid}" style="padding-left:24px;display:none;"><span class="file-preview-content">{openLink}<span class="time" style="padding-right: 20px;"> - {size_format}</span></li>',
popover: '<img alt="{name}" src="{thumbnailUrl}" />'
};

View File

@ -0,0 +1,48 @@
<?php
use humhub\libs\Html;
use humhub\widgets\ModalDialog;
use humhub\modules\file\converter\PreviewImage;
use humhub\modules\file\widgets\FileHandlerButtonDropdown;
use yii\bootstrap\ButtonDropdown;
$modal = ModalDialog::begin(['header' => Yii::t('FileModule.base', '<strong>Open</strong> file', ['fileName' => Html::encode($file->file_name)])])
?>
<div class="modal-body">
<?php
$thumbnailUrl = '';
$previewImage = new PreviewImage();
if ($previewImage->applyFile($file)) {
$thumbnailUrl = $previewImage->getUrl();
}
?>
<img src="<?= $thumbnailUrl; ?>" class="pull-left" style="padding-right:12px">
<h3 style="padding-top:0px;margin-top:0px"><?= Html::encode($file->file_name); ?></h3>
<br />
<p style="line-height:20px">
<strong>Size:</strong> <?= Yii::$app->formatter->asShortSize($file->size, 1); ?><br />
<strong>Created by:</strong> <?= $file->createdBy->displayName; ?> (<?= Yii::$app->formatter->asDatetime($file->created_at, 'short'); ?>)<br />
<?php if (!empty($file->updated_at) && $file->updated_at != $file->created_at) : ?>
<strong>Last update by:</strong> <?= $file->updatedBy->displayName; ?> (<?= Yii::$app->formatter->asDatetime($file->updated_at, 'short'); ?>)<br/>
<?php endif; ?>
</p>
<div class="clearfix"></div>
</div>
<div class="modal-footer">
<hr />
<div class="pull-left">
<?= FileHandlerButtonDropdown::widget(['handlers' => array_merge($viewHandler, $exportHandler)]); ?>
<?= FileHandlerButtonDropdown::widget(['handlers' => array_merge($editHandler, $importHandler)]); ?>
</div>
<a href="#" data-dismiss="modal" class="btn btn-default pull-right" data-ui-loader>Close</a>
</div>
<?php ModalDialog::end(); ?>

View File

@ -0,0 +1,91 @@
<?php
/**
* @link https://www.humhub.org/
* @copyright Copyright (c) 2017 HumHub GmbH & Co. KG
* @license https://www.humhub.com/licences
*/
namespace humhub\modules\file\widgets;
use yii\helpers\ArrayHelper;
use humhub\libs\Html;
/**
* FileHandlerButtonWidget shows a dropdown with different file handlers
*
* @since 1.2
* @author Luke
*/
class FileHandlerButtonDropdown extends \humhub\components\Widget
{
/**
* @var string the primary button html code, if not set the first handler will be used
*/
public $primaryButton;
/**
* @var string the default css bootstrap button class
*/
public $cssButtonClass = 'btn-success';
/**
* @var \humhub\modules\file\handler\BaseFileHandler[] the handlers to show
*/
public $handlers;
/**
* @inheritdoc
*/
public function run()
{
if (!$this->primaryButton && count($this->handlers) === 0) {
return;
}
$output = Html::beginTag('div', ['class' => 'btn-group']);
if (!$this->primaryButton) {
$firstButton = array_shift($this->handlers)->getLinkAttributes();
Html::addCssClass($firstButton, ['btn', $this->cssButtonClass]);
$output .= $this->renderLink($firstButton);
} else {
$output .= $this->primaryButton;
}
if (count($this->handlers) !== 0) {
$output .= '<button type="button" class="btn ' . $this->cssButtonClass . ' dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><span class="caret"></span><span class="sr-only">Toggle Dropdown</span></button>';
$output .= Html::beginTag('ul', ['class' => 'dropdown-menu']);
foreach ($this->handlers as $handler) {
$output .= Html::beginTag('li');
$output .= $this->renderLink($handler->getLinkAttributes());
$output .= Html::endTag('li');
}
$output .= Html::endTag('ul');
}
$output .= Html::endTag('div');
return $output;
}
/**
* Renders the file handle link
*
* @param array $options the HTML options
* @return string the rendered HTML tag
*/
protected function renderLink($options)
{
$label = ArrayHelper::remove($options, 'label', 'Label');
if (isset($options['url'])) {
$url = ArrayHelper::remove($options, 'url', '#');
$options['href'] = $url;
}
return Html::tag('a', $label, $options);
}
}