openrat-cms

OpenRat Content Management System
git clone http://git.code.weiherhei.de/openrat-cms.git
Log | Files | Refs

commit 8daaad13c792cf61a8911704b74cdc109690bdcd
parent bd889dde612fc4deaf0feacf3a93088290f95bca
Author: Jan Dankert <develop@jandankert.de>
Date:   Tue, 29 Sep 2020 01:13:54 +0200

Fix: The search function now finds objects id with a length less than 3.

Diffstat:
modules/cms/action/SearchAction.class.php | 68++++++++++++++++++++++++++++++++++++++------------------------------
modules/cms/base/DefaultConfig.class.php | 2+-
modules/cms/ui/themes/default/script/openrat.js | 2+-
modules/cms/ui/themes/default/script/openrat.min.js | 2+-
modules/cms/ui/themes/default/script/plugin/jquery-plugin-orSearch.js | 2+-
5 files changed, 42 insertions(+), 34 deletions(-)

diff --git a/modules/cms/action/SearchAction.class.php b/modules/cms/action/SearchAction.class.php @@ -2,6 +2,7 @@ namespace cms\action; +use cms\base\Configuration as C; use cms\model\Acl; use cms\model\Project; use cms\model\User; @@ -13,7 +14,6 @@ use cms\model\File; use util\Session; -use util\Html; @@ -35,11 +35,6 @@ use util\Html; // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -define('SEARCH_FLAG_ID' , 1); -define('SEARCH_FLAG_NAME' , 2); -define('SEARCH_FLAG_FILENAME' , 4); -define('SEARCH_FLAG_DESCRIPTION', 8); -define('SEARCH_FLAG_VALUE' ,16); /** @@ -51,9 +46,14 @@ define('SEARCH_FLAG_VALUE' ,16); */ class SearchAction extends BaseAction { + const FLAG_ID = 1; + const FLAG_NAME = 2; + const FLAG_FILENAME = 4; + const FLAG_DESCRIPTION = 8; + const FLAG_VALUE = 16; + public $security = Action::SECURITY_USER; - /** * leerer Kontruktor */ @@ -80,11 +80,11 @@ class SearchAction extends BaseAction $suchText = $this->getRequestVar('text'); $searchFlags = 0; - if ( $this->hasRequestVar('id' ) ) $searchFlags |= SEARCH_FLAG_ID; - if ( $this->hasRequestVar('filename' ) ) $searchFlags |= SEARCH_FLAG_FILENAME; - if ( $this->hasRequestVar('name' ) ) $searchFlags |= SEARCH_FLAG_NAME; - if ( $this->hasRequestVar('description') ) $searchFlags |= SEARCH_FLAG_DESCRIPTION; - if ( $this->hasRequestVar('content' ) ) $searchFlags |= SEARCH_FLAG_VALUE; + if ( $this->hasRequestVar('id' ) ) $searchFlags |= self::FLAG_ID; + if ( $this->hasRequestVar('filename' ) ) $searchFlags |= self::FLAG_FILENAME; + if ( $this->hasRequestVar('name' ) ) $searchFlags |= self::FLAG_NAME; + if ( $this->hasRequestVar('description') ) $searchFlags |= self::FLAG_DESCRIPTION; + if ( $this->hasRequestVar('content' ) ) $searchFlags |= self::FLAG_VALUE; $this->performSearch($suchText, $searchFlags); @@ -108,26 +108,34 @@ class SearchAction extends BaseAction */ public function quicksearchView() { - $conf = \cms\base\Configuration::rawConfig(); + $searchConfig = C::subset('search')->subset('quicksearch'); $text = $this->getRequestVar('search'); - $flag = $conf['search']['quicksearch']['flag']; + $flag = $searchConfig->subset('flag'); + $searchFlags = 0; - if ( $flag['id' ] ) $searchFlags |= SEARCH_FLAG_ID; - if ( $flag['name' ] ) $searchFlags |= SEARCH_FLAG_NAME; - if ( $flag['filename' ] ) $searchFlags |= SEARCH_FLAG_FILENAME; - if ( $flag['description'] ) $searchFlags |= SEARCH_FLAG_DESCRIPTION; - if ( $flag['content' ] ) $searchFlags |= SEARCH_FLAG_VALUE; - + + // Always search for the id without a max length + if ( $flag->is('id' ) ) $searchFlags |= self::FLAG_ID; + + if ( strlen($text) >= $searchConfig->get('maxlength',3 ) ) { + + if ( $flag->is('name' ) ) $searchFlags |= self::FLAG_NAME; + if ( $flag->is('filename' ) ) $searchFlags |= self::FLAG_FILENAME; + if ( $flag->is('description') ) $searchFlags |= self::FLAG_DESCRIPTION; + if ( $flag->is('content' ) ) $searchFlags |= self::FLAG_VALUE; + } + $this->performSearch($text, $searchFlags); } - - - + + /** - * Durchf?hren der Suche - * und Anzeige der Ergebnisse + * Query the search + * + * @param $searchText string search query text + * @param $searchFlag int field selector */ private function performSearch($searchText, $searchFlag) { @@ -137,7 +145,7 @@ class SearchAction extends BaseAction $resultList = array(); - if ( $searchFlag & SEARCH_FLAG_ID ) + if ( $searchFlag & self::FLAG_ID ) { if ( BaseObject::available( intval($searchText) ) ) $listObjectIds[] = intval( $searchText ); @@ -163,7 +171,7 @@ class SearchAction extends BaseAction } } - if ( $searchFlag & SEARCH_FLAG_NAME ) + if ( $searchFlag & self::FLAG_NAME ) { if ( $this->userIsAdmin() ) { @@ -182,12 +190,12 @@ class SearchAction extends BaseAction $listObjectIds += BaseObject::getObjectIdsByName( $searchText ); } - if ( $searchFlag & SEARCH_FLAG_DESCRIPTION ) + if ( $searchFlag & self::FLAG_DESCRIPTION ) { $listObjectIds += BaseObject::getObjectIdsByDescription( $searchText ); } - if ( $searchFlag & SEARCH_FLAG_FILENAME ) + if ( $searchFlag & self::FLAG_FILENAME ) { $listObjectIds += BaseObject::getObjectIdsByFilename( $searchText ); @@ -195,7 +203,7 @@ class SearchAction extends BaseAction } // Inhalte durchsuchen - if ( $searchFlag & SEARCH_FLAG_VALUE ) + if ( $searchFlag & self::FLAG_VALUE ) { $e = new Value(); $listObjectIds += $e->getObjectIdsByValue( $searchText ); diff --git a/modules/cms/base/DefaultConfig.class.php b/modules/cms/base/DefaultConfig.class.php @@ -810,7 +810,7 @@ class DefaultConfig { ], 'search' => [ - '' => '0', + 'minlength' => 3, 'quicksearch' => [ 'flag' => diff --git a/modules/cms/ui/themes/default/script/openrat.js b/modules/cms/ui/themes/default/script/openrat.js @@ -133,7 +133,7 @@ jQuery.fn.orSearch = function( options ) let searchArgument = $(this).val(); let dropdownEl = $( settings.dropdown ); - if ( searchArgument.length > 3 ) + if ( searchArgument.length ) { $(dropdownEl).empty(); // Leeren. diff --git a/modules/cms/ui/themes/default/script/openrat.min.js b/modules/cms/ui/themes/default/script/openrat.min.js @@ -113,7 +113,7 @@ else{if(this.containers[s].containerCache.over){this.containers[s]._trigger("out else{c=10000;n=null;h=r.floating||this._isFloating(this.currentItem);p=h?"left":"top";u=h?"width":"height";l=h?"pageX":"pageY";for(o=this.items.length-1;o>=0;o--){if(!t.contains(this.containers[i].element[0],this.items[o].item[0])){continue};if(this.items[o].item[0]===this.currentItem[0]){continue};a=this.items[o].item.offset()[p];f=!1;if(e[l]-a>this.items[o][u]/2){f=!0};if(Math.abs(e[l]-a)<c){c=Math.abs(e[l]-a);n=this.items[o];this.direction=f?"up":"down"}};if(!n&&!this.options.dropOnEmpty){return};if(this.currentContainer===this.containers[i]){if(!this.currentContainer.containerCache.over){this.containers[i]._trigger("over",e,this._uiHash());this.currentContainer.containerCache.over=1};return};n?this._rearrange(e,n,null,!0):this._rearrange(e,null,this.containers[i].element,!0);this._trigger("change",e,this._uiHash());this.containers[i]._trigger("change",e,this._uiHash(this));this.currentContainer=this.containers[i];this.options.placeholder.update(this.currentContainer,this.placeholder);this.containers[i]._trigger("over",e,this._uiHash(this));this.containers[i].containerCache.over=1}},_createHelper:function(e){var s=this.options,i=t.isFunction(s.helper)?t(s.helper.apply(this.element[0],[e,this.currentItem])):(s.helper==="clone"?this.currentItem.clone():this.currentItem);if(!i.parents("body").length){t(s.appendTo!=="parent"?s.appendTo:this.currentItem[0].parentNode)[0].appendChild(i[0])};if(i[0]===this.currentItem[0]){this._storedCSS={width:this.currentItem[0].style.width,height:this.currentItem[0].style.height,position:this.currentItem.css("position"),top:this.currentItem.css("top"),left:this.currentItem.css("left")}};if(!i[0].style.width||s.forceHelperSize){i.width(this.currentItem.width())};if(!i[0].style.height||s.forceHelperSize){i.height(this.currentItem.height())};return i},_adjustOffsetFromHelper:function(e){if(typeof e==="string"){e=e.split(" ")};if(t.isArray(e)){e={left:+e[0],top:+e[1]||0}};if("left" in e){this.offset.click.left=e.left+this.margins.left};if("right" in e){this.offset.click.left=this.helperProportions.width-e.right+this.margins.left};if("top" in e){this.offset.click.top=e.top+this.margins.top};if("bottom" in e){this.offset.click.top=this.helperProportions.height-e.bottom+this.margins.top}},_getParentOffset:function(){this.offsetParent=this.helper.offsetParent();var e=this.offsetParent.offset();if(this.cssPosition==="absolute"&&this.scrollParent[0]!==this.document[0]&&t.contains(this.scrollParent[0],this.offsetParent[0])){e.left+=this.scrollParent.scrollLeft();e.top+=this.scrollParent.scrollTop()};if(this.offsetParent[0]===this.document[0].body||(this.offsetParent[0].tagName&&this.offsetParent[0].tagName.toLowerCase()==="html"&&t.ui.ie)){e={top:0,left:0}};return{top:e.top+(parseInt(this.offsetParent.css("borderTopWidth"),10)||0),left:e.left+(parseInt(this.offsetParent.css("borderLeftWidth"),10)||0)}},_getRelativeOffset:function(){if(this.cssPosition==="relative"){var t=this.currentItem.position();return{top:t.top-(parseInt(this.helper.css("top"),10)||0)+this.scrollParent.scrollTop(),left:t.left-(parseInt(this.helper.css("left"),10)||0)+this.scrollParent.scrollLeft()}} else{return{top:0,left:0}}},_cacheMargins:function(){this.margins={left:(parseInt(this.currentItem.css("marginLeft"),10)||0),top:(parseInt(this.currentItem.css("marginTop"),10)||0)}},_cacheHelperProportions:function(){this.helperProportions={width:this.helper.outerWidth(),height:this.helper.outerHeight()}},_setContainment:function(){var e,s,o,i=this.options;if(i.containment==="parent"){i.containment=this.helper[0].parentNode};if(i.containment==="document"||i.containment==="window"){this.containment=[0-this.offset.relative.left-this.offset.parent.left,0-this.offset.relative.top-this.offset.parent.top,i.containment==="document"?this.document.width():this.window.width()-this.helperProportions.width-this.margins.left,(i.containment==="document"?(this.document.height()||document.body.parentNode.scrollHeight):this.window.height()||this.document[0].body.parentNode.scrollHeight)-this.helperProportions.height-this.margins.top]};if(!(/^(document|window|parent)$/).test(i.containment)){e=t(i.containment)[0];s=t(i.containment).offset();o=(t(e).css("overflow")!=="hidden");this.containment=[s.left+(parseInt(t(e).css("borderLeftWidth"),10)||0)+(parseInt(t(e).css("paddingLeft"),10)||0)-this.margins.left,s.top+(parseInt(t(e).css("borderTopWidth"),10)||0)+(parseInt(t(e).css("paddingTop"),10)||0)-this.margins.top,s.left+(o?Math.max(e.scrollWidth,e.offsetWidth):e.offsetWidth)-(parseInt(t(e).css("borderLeftWidth"),10)||0)-(parseInt(t(e).css("paddingRight"),10)||0)-this.helperProportions.width-this.margins.left,s.top+(o?Math.max(e.scrollHeight,e.offsetHeight):e.offsetHeight)-(parseInt(t(e).css("borderTopWidth"),10)||0)-(parseInt(t(e).css("paddingBottom"),10)||0)-this.helperProportions.height-this.margins.top]}},_convertPositionTo:function(e,i){if(!i){i=this.position};var s=e==="absolute"?1:-1,o=this.cssPosition==="absolute"&&!(this.scrollParent[0]!==this.document[0]&&t.contains(this.scrollParent[0],this.offsetParent[0]))?this.offsetParent:this.scrollParent,n=(/(html|body)/i).test(o[0].tagName);return{top:(i.top+this.offset.relative.top*s+this.offset.parent.top*s-((this.cssPosition==="fixed"?-this.scrollParent.scrollTop():(n?0:o.scrollTop()))*s)),left:(i.left+this.offset.relative.left*s+this.offset.parent.left*s-((this.cssPosition==="fixed"?-this.scrollParent.scrollLeft():n?0:o.scrollLeft())*s))}},_generatePosition:function(e){var s,o,i=this.options,n=e.pageX,r=e.pageY,a=this.cssPosition==="absolute"&&!(this.scrollParent[0]!==this.document[0]&&t.contains(this.scrollParent[0],this.offsetParent[0]))?this.offsetParent:this.scrollParent,h=(/(html|body)/i).test(a[0].tagName);if(this.cssPosition==="relative"&&!(this.scrollParent[0]!==this.document[0]&&this.scrollParent[0]!==this.offsetParent[0])){this.offset.relative=this._getRelativeOffset()};if(this.originalPosition){if(this.containment){if(e.pageX-this.offset.click.left<this.containment[0]){n=this.containment[0]+this.offset.click.left};if(e.pageY-this.offset.click.top<this.containment[1]){r=this.containment[1]+this.offset.click.top};if(e.pageX-this.offset.click.left>this.containment[2]){n=this.containment[2]+this.offset.click.left};if(e.pageY-this.offset.click.top>this.containment[3]){r=this.containment[3]+this.offset.click.top}};if(i.grid){s=this.originalPageY+Math.round((r-this.originalPageY)/i.grid[1])*i.grid[1];r=this.containment?((s-this.offset.click.top>=this.containment[1]&&s-this.offset.click.top<=this.containment[3])?s:((s-this.offset.click.top>=this.containment[1])?s-i.grid[1]:s+i.grid[1])):s;o=this.originalPageX+Math.round((n-this.originalPageX)/i.grid[0])*i.grid[0];n=this.containment?((o-this.offset.click.left>=this.containment[0]&&o-this.offset.click.left<=this.containment[2])?o:((o-this.offset.click.left>=this.containment[0])?o-i.grid[0]:o+i.grid[0])):o}};return{top:(r-this.offset.click.top-this.offset.relative.top-this.offset.parent.top+((this.cssPosition==="fixed"?-this.scrollParent.scrollTop():(h?0:a.scrollTop())))),left:(n-this.offset.click.left-this.offset.relative.left-this.offset.parent.left+((this.cssPosition==="fixed"?-this.scrollParent.scrollLeft():h?0:a.scrollLeft())))}},_rearrange:function(t,e,i,s){i?i[0].appendChild(this.placeholder[0]):e.item[0].parentNode.insertBefore(this.placeholder[0],(this.direction==="down"?e.item[0]:e.item[0].nextSibling));this.counter=this.counter?++this.counter:1;var o=this.counter;this._delay(function(){if(o===this.counter){this.refreshPositions(!s)}})},_clear:function(t,e){this.reverting=!1;var i,s=[];if(!this._noFinalSort&&this.currentItem.parent().length){this.placeholder.before(this.currentItem)};this._noFinalSort=null;if(this.helper[0]===this.currentItem[0]){for(i in this._storedCSS){if(this._storedCSS[i]==="auto"||this._storedCSS[i]==="static"){this._storedCSS[i]=""}};this.currentItem.css(this._storedCSS);this._removeClass(this.currentItem,"ui-sortable-helper")} else{this.currentItem.show()};if(this.fromOutside&&!e){s.push(function(t){this._trigger("receive",t,this._uiHash(this.fromOutside))})};if((this.fromOutside||this.domPosition.prev!==this.currentItem.prev().not(".ui-sortable-helper")[0]||this.domPosition.parent!==this.currentItem.parent()[0])&&!e){s.push(function(t){this._trigger("update",t,this._uiHash())})};if(this!==this.currentContainer){if(!e){s.push(function(t){this._trigger("remove",t,this._uiHash())});s.push((function(t){return function(e){t._trigger("receive",e,this._uiHash(this))}}).call(this,this.currentContainer));s.push((function(t){return function(e){t._trigger("update",e,this._uiHash(this))}}).call(this,this.currentContainer))}};function o(t,e,i){return function(s){i._trigger(t,s,e._uiHash(e))}};for(i=this.containers.length-1;i>=0;i--){if(!e){s.push(o("deactivate",this,this.containers[i]))};if(this.containers[i].containerCache.over){s.push(o("out",this,this.containers[i]));this.containers[i].containerCache.over=0}};if(this.storedCursor){this.document.find("body").css("cursor",this.storedCursor);this.storedStylesheet.remove()};if(this._storedOpacity){this.helper.css("opacity",this._storedOpacity)};if(this._storedZIndex){this.helper.css("zIndex",this._storedZIndex==="auto"?"":this._storedZIndex)};this.dragging=!1;if(!e){this._trigger("beforeStop",t,this._uiHash())};this.placeholder[0].parentNode.removeChild(this.placeholder[0]);if(!this.cancelHelperRemoval){if(this.helper[0]!==this.currentItem[0]){this.helper.remove()};this.helper=null};if(!e){for(i=0;i<s.length;i++){s[i].call(this,t)};this._trigger("stop",t,this._uiHash())};this.fromOutside=!1;return!this.cancelHelperRemoval},_trigger:function(){if(t.Widget.prototype._trigger.apply(this,arguments)===!1){this.cancel()}},_uiHash:function(e){var i=e||this;return{helper:i.helper,placeholder:i.placeholder||t([]),position:i.position,originalPosition:i.originalPosition,offset:i.positionAbs,item:i.currentItem,sender:e?e.element:null}}})})); -;jQuery.fn.orSearch=function(e){var t=$.extend({'dropdown':$(),'select':function(e){}},e);return $(this).on('input',function(){let searchArgument=$(this).val();let dropdownEl=$(t.dropdown);if(searchArgument.length>3){$(dropdownEl).empty();$.ajax({'type':'GET',url:'./api/?action=search&subaction=quicksearch&output=json&search='+searchArgument,data:null,success:function(e,n,r){for(id in e.output.result){let result=e.output.result[id];let div=$('<div class="entry or-search-result" title="'+result.desc+'"></div>');div.data('object',{'name':result.name,'action':result.type,'id':result.id});let link=$('<a />').attr('href',Openrat.Navigator.createShortUrl(result.type,result.id));link.click(function(e){e.preventDefault()});$(link).append('<i class="image-icon image-icon--action-'+result.type+'" />');$(link).append('<span>'+result.name+'</span>');$(div).append(link);$(dropdownEl).append(div)};$(dropdownEl).closest('.or-menu').addClass('open');$(dropdownEl).find('.or-search-result').click(function(e){t.select($(this).data('object'))})}})} +;jQuery.fn.orSearch=function(e){var t=$.extend({'dropdown':$(),'select':function(e){}},e);return $(this).on('input',function(){let searchArgument=$(this).val();let dropdownEl=$(t.dropdown);if(searchArgument.length){$(dropdownEl).empty();$.ajax({'type':'GET',url:'./api/?action=search&subaction=quicksearch&output=json&search='+searchArgument,data:null,success:function(e,n,r){for(id in e.output.result){let result=e.output.result[id];let div=$('<div class="entry or-search-result" title="'+result.desc+'"></div>');div.data('object',{'name':result.name,'action':result.type,'id':result.id});let link=$('<a />').attr('href',Openrat.Navigator.createShortUrl(result.type,result.id));link.click(function(e){e.preventDefault()});$(link).append('<i class="image-icon image-icon--action-'+result.type+'" />');$(link).append('<span>'+result.name+'</span>');$(div).append(link);$(dropdownEl).append(div)};$(dropdownEl).closest('.or-menu').addClass('open');$(dropdownEl).find('.or-search-result').click(function(e){t.select($(this).data('object'))})}})} else{$(dropdownEl).empty()}})}; ;var popupWindow;jQuery.fn.orLinkify=function(){$(this).find('a').click(function(t){t.preventDefault()});return $(this).click(function(){$(this).find('a').first().each(function(){let type=$(this).attr('data-type');if($(this).parent().hasClass('inactive'))return;switch(type){case'post':$form=$('<form />').attr('method','POST').addClass('invisible');$form.data('afterSuccess',$(this).data('afterSuccess'));let params=jQuery.parseJSON($(this).attr('data-data'));params.output='json';$.each(params,function(t,a){let $input=$('<input />').attr('type','hidden').attr('name',t).attr('value',a);$form.append($input)});let form=new Openrat.Form();form.initOnElement($form);form.submit();break;case'edit':case'dialog':startDialog($(this).attr('data-name'),$(this).attr('data-action'),$(this).attr('data-method'),$(this).attr('data-id'),$(this).attr('data-extra'));break;case'external':window.open($(this).attr('data-url'),' _blank');break;case'popup':popupWindow=window.open($(this).attr('data-url'),'Popup','location=no,menubar=no,scrollbars=yes,toolbar=no,resizable=yes');break;case'help':help(this,$(this).attr('data-url'),$(this).attr('data-suffix'));break;case'fullscreen':fullscreen(this);break;case'open':openNewAction($(this).attr('data-name'),$(this).attr('data-action'),$(this).attr('data-id'));break;default:throw'UI error: Unknown link type: '+type+' in link '+$(this).html()}})})}; ;jQuery.fn.orTree=function(){$(this).each(function(n,e){$(e).children('.or-navtree-node-control').click(function(){let $node=$(this).parent('.or-navtree-node');if($node.is('.or-navtree-node--is-open')){$node.children('ul').slideUp('fast').remove();$node.removeClass('or-navtree-node--is-open').addClass('or-navtree-node--is-closed').find('.tree-icon').removeClass('image-icon--node-open').addClass('image-icon--node-closed')} diff --git a/modules/cms/ui/themes/default/script/plugin/jquery-plugin-orSearch.js b/modules/cms/ui/themes/default/script/plugin/jquery-plugin-orSearch.js @@ -15,7 +15,7 @@ jQuery.fn.orSearch = function( options ) let searchArgument = $(this).val(); let dropdownEl = $( settings.dropdown ); - if ( searchArgument.length > 3 ) + if ( searchArgument.length ) { $(dropdownEl).empty(); // Leeren.