Przeglądaj źródła

Ticket #5652 - Mentions: Order suggestions list by weight.

AntonLV 1 miesiąc temu
rodzic
commit
f75c19e4d7

+ 6 - 4
inc/classes/BxDolSearchExtended.php

@@ -129,10 +129,12 @@ class BxDolSearchExtended extends BxDolFactory implements iBxDolFactoryObject
         switch($sSymbol) {
         switch($sSymbol) {
             case '@':
             case '@':
                 $aSearchParams = [];
                 $aSearchParams = [];
-                if(($iCid = bx_get('cid')) !== false)
-                    $aSearchParams['cid'] = $iCid;
-                if(($sCmod = bx_get('cmod')) !== false)
-                    $aSearchParams['cmod'] = bx_process_input($sCmod);
+                if(($iCntId = bx_get('ci')) !== false)
+                    $aSearchParams['ci'] = $iCntId;
+                if(($sCntModule = bx_get('cm')) !== false)
+                    $aSearchParams['cm'] = bx_process_input($sCntModule);
+                if(($sCntPrivacy = bx_get('cp')) !== false)
+                    $aSearchParams['cp'] = bx_process_input($sCntPrivacy);
 
 
                 $aSrvParams = [];
                 $aSrvParams = [];
                 if($aSearchParams)
                 if($aSearchParams)

+ 20 - 9
modules/base/general/classes/BxBaseModGeneralFormEntry.php

@@ -720,15 +720,9 @@ class BxBaseModGeneralFormEntry extends BxTemplFormView
 
 
     function getHtmlEditorQueryParams($aInput)
     function getHtmlEditorQueryParams($aInput)
     {
     {
-        $aQueryParams = parent::getHtmlEditorQueryParams($aInput);
-        if (isset($this->MODULE)){
-            $aQueryParams['m'] = $this->MODULE;
-            $aQueryParams['cmod'] = $this->MODULE;
-        }
-        if (isset($this->_iContentId) && $this->_iContentId){
-            $aQueryParams['cid'] = $this->_iContentId;
-        }
-        $aQueryParams['fi'] = '';
+        $aQueryParams = array_merge(parent::getHtmlEditorQueryParams($aInput), $this->getMentionsQueryParams($aInput), [
+            'fi' => ''
+        ]);
 
 
         /**
         /**
          * @hooks
          * @hooks
@@ -750,6 +744,23 @@ class BxBaseModGeneralFormEntry extends BxTemplFormView
         return $aQueryParams;
         return $aQueryParams;
     }
     }
 
 
+    function getMentionsQueryParams($aInput)
+    {
+        $CNF = &$this->_oModule->_oConfig->CNF;
+
+        $aParams = array_merge(parent::getMentionsQueryParams($aInput), [
+            'ct' => 'content',
+            'cm' => $this->MODULE ?: '',
+            'ci' => $this->_iContentId ?: 0,
+            'cp' => ''
+        ]);
+
+        if(($sF = $CNF['FIELD_ALLOW_VIEW_TO'] ?? false) && ($aF = $this->aInputs[$sF] ?? false) || ($sF = $CNF['FIELD_OBJECT_PRIVACY_VIEW'] ?? false) && ($aF = $this->aInputs[$sF] ?? false))
+            $aParams['cp'] = $aF['value'];
+
+        return $aParams;
+    }
+
     protected function _associalFileWithContent($oStorage, $iFileId, $iProfileId, $iContentId, $sPictureField = '')
     protected function _associalFileWithContent($oStorage, $iFileId, $iProfileId, $iContentId, $sPictureField = '')
     {
     {
         $oStorage->updateGhostsContentId ($iFileId, $iProfileId, $iContentId, $this->_isAdmin($iContentId));
         $oStorage->updateGhostsContentId ($iFileId, $iProfileId, $iContentId, $this->_isAdmin($iContentId));

+ 13 - 10
modules/base/profile/classes/BxBaseModProfileDb.php

@@ -133,23 +133,26 @@ class BxBaseModProfileDb extends BxBaseModGeneralDb
         if((is_numeric($mixedParams) && ($iLimit = (int)$mixedParams)) || (is_array($mixedParams) && isset($mixedParams['limit']) && ($iLimit = (int)$mixedParams['limit'])))
         if((is_numeric($mixedParams) && ($iLimit = (int)$mixedParams)) || (is_array($mixedParams) && isset($mixedParams['limit']) && ($iLimit = (int)$mixedParams['limit'])))
             $sLimit = $this->prepareAsString(" LIMIT ?", $iLimit);
             $sLimit = $this->prepareAsString(" LIMIT ?", $iLimit);
 
 
-        if(($iCid = $mixedParams['search_params']['cid'] ?? false) && ($sCmod = $mixedParams['search_params']['cmod'] ?? false)) {
-            $aContent = bx_srv($sCmod, 'get_info', [$iCid, false]);
-
-            $aPreferred = [];
-            if(!bx_srv('system', 'is_module_context', [$sCmod])) {
+        $aPreferred = [];
+        if(($iContext = (int)($mixedParams['search_params']['cp'] ?? 0)) < 0 && ($oContext = BxDolProfile::getInstance(abs($iContext))) !== false) {
+            $aPreferred = bx_srv($oContext->getModule(), 'fans', [$oContext->getContentId(), true]);
+        } 
+        else if(($iCntId = $mixedParams['search_params']['ci'] ?? false) && ($aCntModule = $mixedParams['search_params']['cm'] ?? false)) {
+            $aContent = bx_srv($aCntModule, 'get_info', [$iCntId, false]);
+
+            if(!bx_srv('system', 'is_module_context', [$aCntModule])) {
                 if(($sK = 'allow_view_to') && ($iContext = $aContent[$sK] ?? 0) < 0 && ($oContext = BxDolProfile::getInstance(abs($iContext))) !== false)
                 if(($sK = 'allow_view_to') && ($iContext = $aContent[$sK] ?? 0) < 0 && ($oContext = BxDolProfile::getInstance(abs($iContext))) !== false)
                     $aPreferred = bx_srv($oContext->getModule(), 'fans', [$oContext->getContentId(), true]);
                     $aPreferred = bx_srv($oContext->getModule(), 'fans', [$oContext->getContentId(), true]);
                 else
                 else
                     $aPreferred = BxDolConnection::getObjectInstance('sys_profiles_friends')->getConnectedContentByType(bx_get_logged_profile_id(), $aBindings['type'], true);
                     $aPreferred = BxDolConnection::getObjectInstance('sys_profiles_friends')->getConnectedContentByType(bx_get_logged_profile_id(), $aBindings['type'], true);
             }
             }
             else 
             else 
-                $aPreferred = bx_srv($sCmod, 'fans', [$iCid, true]);
+                $aPreferred = bx_srv($aCntModule, 'fans', [$iCntId, true]);
+        }
 
 
-            if($aPreferred) {
-                $sSelect .= ", IF(`p`.`id` IN (" . $this->implode_escape($aPreferred) . "), 1, 0) AS `profile_weight`";
-                $sOrderBy = " ORDER BY `profile_weight` DESC, `a`.`logged` DESC";
-            }
+        if($aPreferred) {
+            $sSelect .= ", IF(`p`.`id` IN (" . $this->implode_escape($aPreferred) . "), 1, 0) AS `profile_weight`";
+            $sOrderBy = " ORDER BY `profile_weight` DESC, `a`.`logged` DESC";
         }
         }
 
 
         /**
         /**

+ 25 - 14
template/scripts/BxBaseCmtsForm.php

@@ -41,21 +41,12 @@ class BxBaseCmtsForm extends BxTemplFormView
             $this->aInputs['cmt_image']['ghost_template'] = '';
             $this->aInputs['cmt_image']['ghost_template'] = '';
         }
         }
     }
     }
-    
+
     function getHtmlEditorQueryParams($aInput)
     function getHtmlEditorQueryParams($aInput)
     {
     {
-        $aQueryParams = parent::getHtmlEditorQueryParams($aInput);
-        if (isset($this->aInputs['id'])) {
-            $aQueryParams['cid'] = $this->aInputs['id']['value'];
-        }
-
-        $oObject = $this->_getObject(bx_process_input($this->aInputs['sys']['value']), (int)$this->aInputs['id']['value']);
-        if($oObject && ($aCmtInfo = $this->_oObject->getSystemInfo())) {
-            $aQueryParams['cmod'] = $aCmtInfo['module'] ?? '';
-        }
-
-        $aQueryParams['m'] = 'sys_cmts';
-        $aQueryParams['fi'] = '';
+        $aQueryParams = array_merge(parent::getHtmlEditorQueryParams($aInput), $this->getMentionsQueryParams($aInput), [
+            'fi' => ''
+        ]);
 
 
         /**
         /**
          * @hooks
          * @hooks
@@ -76,7 +67,27 @@ class BxBaseCmtsForm extends BxTemplFormView
         
         
         return $aQueryParams;
         return $aQueryParams;
     }
     }
-    
+
+    function getMentionsQueryParams($aInput)
+    {
+        $aParams = array_merge(parent::getMentionsQueryParams($aInput), [
+            'ct' => 'comment',
+            'cm' => '',
+            'ci' => 0,
+            'cp' => ''
+        ]);
+
+        if(($sSystem = $this->aInputs['sys']['value'] ?? false) && ($iObjectId = $this->aInputs['id']['value'] ?? false)) {
+            $aParams['ci'] = (int)$iObjectId;
+
+            $oObject = $this->_getObject(bx_process_input($sSystem), (int)$iObjectId);
+            if($oObject && ($aCmtInfo = $this->_oObject->getSystemInfo()))
+                $aParams['cm'] = $aCmtInfo['module'] ?? '';
+        }
+
+        return $aParams;
+    }
+
     public function getAttributeMask($sAttribute)
     public function getAttributeMask($sAttribute)
     {
     {
         $sName = '_sAttributeMask' . bx_gen_method_name($sAttribute);
         $sName = '_sAttributeMask' . bx_gen_method_name($sAttribute);

+ 13 - 3
template/scripts/BxBaseFormView.php

@@ -501,9 +501,14 @@ class BxBaseFormView extends BxDolForm
                 $aInput['value'] = $aVars;
                 $aInput['value'] = $aVars;
             }
             }
 
 
-            if ($bType && 'textarea' == $aInput['type']){
-                if (isset($aInput['value'], $aInput['html']) && (int)$aInput['html'] == 0)
-                    $aInput['value'] = strip_tags($aInput['value']);
+            if ($bType && 'textarea' == $aInput['type']) {
+                $iTaHtml = (int)($aInput['html'] ?? 0);
+
+                if(($sTaValue = $aInput['value'] ?? false) && $iTaHtml == 0)
+                    $aInput['value'] = strip_tags($sTaValue);
+
+                if($iTaHtml != 0)
+                    $aInput['mentions'] = $this->getMentionsQueryParams($aInput);
             }
             }
 
 
             if ($bType && 'price' == $aInput['type']) {
             if ($bType && 'price' == $aInput['type']) {
@@ -1909,6 +1914,11 @@ BLAH;
         return $aQueryParams;
         return $aQueryParams;
     }
     }
 
 
+    function getMentionsQueryParams($aInput)
+    {
+        return [];
+    }
+
     /**
     /**
      * Generate Select Box Element
      * Generate Select Box Element
      *
      *