Added SearchHelper, allow File Converter config options

This commit is contained in:
Lucas Bartholemy 2017-09-12 18:32:54 +02:00
parent 889ada4601
commit 1c5c2df542
5 changed files with 87 additions and 11 deletions

View File

@ -38,4 +38,9 @@ class Module extends \humhub\components\Module
'image/jpeg'
];
/**
* @var array of converter options
*/
public $converterOptions = [];
}

View File

@ -8,6 +8,7 @@
namespace humhub\modules\file\converter;
use Yii;
use humhub\modules\file\models\File;
/**
@ -31,6 +32,18 @@ abstract class BaseConverter extends \yii\base\Object
*/
public $options = [];
/**
* @inheritdoc
*/
public function init()
{
parent::init();
if (!empty(Yii::$app->getModule('file')->converterOptions[$this->className()])) {
Yii::configure($this, Yii::$app->getModule('file')->converterOptions[$this->className()]);
}
}
/**
* Convert file
*/
@ -72,8 +85,8 @@ abstract class BaseConverter extends \yii\base\Object
*/
public function applyFile(File $file)
{
$this->file = $file;
if ($this->canConvert($file)) {
$this->file = $file;
return true;
}

View File

@ -340,6 +340,13 @@ humhub.module('file', function (module, require, $) {
Preview.prototype.add = function (file) {
file.galleryId = this.$.attr('id') + '_file_preview_gallery';
var template = this.getTemplate(file);
if(file.highlight) {
file.highlight = 'highlight';
} else {
file.highlight = '';
}
var $file = $(string.template(template, file));
if(this.source && this.source.options.uploadSingle) {
@ -446,8 +453,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">{openLink}<span class="time file-fileInfo" 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 file-fileInfo" 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"><span class="{highlight}">{openLink}</span><span class="time file-fileInfo" 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 {highlight}">{openLink}<span class="time file-fileInfo" style="padding-right: 20px;"> - {size_format}</span></li>',
popover: '<img alt="{name}" src="{thumbnailUrl}" />'
};

View File

@ -2,7 +2,7 @@
/**
* @link https://www.humhub.org/
* @copyright Copyright (c) 2015 HumHub GmbH & Co. KG
* @copyright Copyright (c) 2017 HumHub GmbH & Co. KG
* @license https://www.humhub.com/licences
*/
@ -13,7 +13,6 @@ use humhub\components\Controller;
use humhub\modules\space\models\Space;
use humhub\modules\user\models\User;
use humhub\modules\search\models\forms\SearchForm;
use humhub\modules\space\widgets\Image;
/**
@ -24,6 +23,15 @@ use humhub\modules\space\widgets\Image;
*/
class SearchController extends Controller
{
/**
* @var string the current search keyword
*/
public static $keyword = null;
/**
* @inheritdoc
*/
public function init()
{
$this->appendPageTitle(\Yii::t('SearchModule.base', 'Search'));
@ -64,7 +72,7 @@ class SearchController extends Controller
'pageSize' => Yii::$app->settings->get('paginationSize'),
'limitSpaces' => $limitSpaces
];
if ($model->scope == SearchForm::SCOPE_CONTENT) {
$options['type'] = \humhub\modules\search\engine\Search::DOCUMENT_TYPE_CONTENT;
} elseif ($model->scope == SearchForm::SCOPE_SPACE) {
@ -77,16 +85,19 @@ class SearchController extends Controller
$searchResultSet = Yii::$app->search->find($model->keyword, $options);
// store static for use in widgets (e.g. fileList)
self::$keyword = $model->keyword;
$pagination = new \yii\data\Pagination;
$pagination->totalCount = $searchResultSet->total;
$pagination->pageSize = $searchResultSet->pageSize;
return $this->render('index', array(
'model' => $model,
'results' => $searchResultSet->getResultInstances(),
'pagination' => $pagination,
'totals' => $model->getTotals($model->keyword, $options),
'limitSpaces' => $limitSpaces
'model' => $model,
'results' => $searchResultSet->getResultInstances(),
'pagination' => $pagination,
'totals' => $model->getTotals($model->keyword, $options),
'limitSpaces' => $limitSpaces
));
}
@ -117,4 +128,5 @@ class SearchController extends Controller
return $results;
}
}

View File

@ -0,0 +1,39 @@
<?php
/**
* @link https://www.humhub.org/
* @copyright Copyright (c) 2017 HumHub GmbH & Co. KG
* @license https://www.humhub.com/licences
*/
namespace humhub\modules\search\libs;
use yii\base\Object;
/**
* SearchHelper
*
* @since 1.2.3
* @author Luke
*/
class SearchHelper extends Object
{
/**
* Checks if given text matches a search query.
*
* @param string $query
* @param string $text
*/
public static function matchQuery($query, $text)
{
foreach (explode(" ", $query) as $keyword) {
if (strpos($text, $keyword) !== false) {
return true;
}
}
return false;
}
}