Просмотр исходного кода

#1970 - Hashtag autosuggestion for existing (or popular) hashtags

RomanL 4 лет назад
Родитель
Сommit
a4e99e089f

+ 14 - 0
inc/classes/BxDolMetatags.php

@@ -679,6 +679,20 @@ class BxDolMetatags extends BxDolFactory implements iBxDolFactoryObject
         return $aRet;
     }
     
+    static public function getMetatagsDataByTerm($sMeta, $sMetaItem, $sTerm)
+    {
+        $aValues = [];
+        $aObjects = BxDolMetatagsQuery::getMetatagsObjects();
+        foreach ($aObjects as $aObject) {
+            $oObject = BxDolMetatags::getObjectInstance($aObject['object']);
+            $aData = call_user_func_array(array($oObject->_oQuery, $sMeta . 'GetByTerm'), [$sTerm]);
+            foreach ($aData as $aMeta) {
+                $aValues[$aMeta[$sMetaItem]] = ['id' => $aMeta['object_id'], 'meta' => $aMeta[$sMetaItem], 'url' => $oObject->keywordsGetHashTagUrl($aMeta[$sMetaItem], $aMeta['object_id'])];
+            }
+        }
+        return $aValues;
+    }
+    
     /**
      * Add location for the content from POST data
      * @param $iId content id

+ 17 - 0
inc/classes/BxDolMetatagsQuery.php

@@ -32,6 +32,17 @@ class BxDolMetatagsQuery extends BxDolDb
         return $aObject;
     }
     
+    static public function getMetatagsObjects ()
+    {
+        $oDb = BxDolDb::getInstance();
+        $sQuery = $oDb->prepare("SELECT * FROM `sys_objects_metatags`");
+        $aObject = $oDb->getAll($sQuery);
+        if (!$aObject || !is_array($aObject))
+            return false;
+
+        return $aObject;
+    }
+
     public function mentionsAdd($mixedContentId, $aMentions, $bDeletePrevious = true)
     {
         return $this->metaAdd($mixedContentId, $aMentions, $bDeletePrevious, 'mentionsDelete', $this->_aObject['table_mentions'], 'profile_id');
@@ -66,6 +77,12 @@ class BxDolMetatagsQuery extends BxDolDb
         $sQuery = $this->prepare("SELECT `keyword` FROM `{$this->_aObject['table_keywords']}` WHERE `object_id` = ? ORDER BY CHAR_LENGTH(`keyword`) DESC LIMIT ?", $mixedContentId, (int)getParam('sys_metatags_hashtags_max'));
         return $this->getColumn($sQuery);
     }
+    
+    public function keywordsGetByTerm($sTerm)
+    {
+        $sQuery = $this->prepare("SELECT `object_id`, `keyword` FROM `{$this->_aObject['table_keywords']}`  WHERE `keyword` LIKE ? ORDER BY CHAR_LENGTH(`keyword`) DESC", $sTerm . '%');
+        return $this->getAll($sQuery);
+    }
 
     public function keywordsGetSQLParts($sContentTable, $sContentField, $mixedKeyword)
     {

+ 25 - 1
inc/classes/BxDolSearchExtended.php

@@ -107,10 +107,34 @@ class BxDolSearchExtended extends BxDolFactory implements iBxDolFactoryObject
     static public function actionGetAuthors()
     {
         $aResult = BxDolService::call('system', 'profiles_search', array(bx_get('term')), 'TemplServiceProfiles');
-
+        foreach ($aResult as &$aItem) {
+            $aItem['symbol'] = bx_get('symbol');
+        }
         header('Content-Type:text/javascript; charset=utf-8');
         echo json_encode($aResult);
     }
+    
+    static public function actionGetHashtags()
+    {
+        $aResult = [];
+        if (bx_get('term')){
+            $aData = BxDolMetatags::getMetatagsDataByTerm('keywords', 'keyword', bx_get('term'));
+            foreach ($aData as $aItem) {
+                $aResult[] = ['label' => $aItem['meta'], 'value' => $aItem['id'], 'url' => $aItem['url'], 'symbol' => bx_get('symbol')];
+            }
+        }
+        header('Content-Type:text/javascript; charset=utf-8');
+        echo json_encode($aResult);
+    }
+    
+    static public function actionGetMention()
+    {
+        if(bx_get('symbol') == '@')
+            self::actionGetAuthors();
+        
+        if(bx_get('symbol') == '#')
+            self::actionGetHashtags();
+    }
 
     public function isEnabled()
     {

+ 18 - 12
inc/js/editor.quill.js

@@ -60,18 +60,20 @@ function bx_editor_init(oEditor, oParams){
                 let node = super.create(value);
                 if (value.id && value.value){
                     node.setAttribute('href', value.id);
-                    node.innerHTML = '@' + value.value;
-                    node.setAttribute('title', '@' + value.value);
+                    node.innerHTML = value.denotationChar + value.value;
+                    node.setAttribute('title', value.value);
+                    node.setAttribute('dchar', value.denotationChar);
                 }
                 return node;
             }
             
             format(name, value) {
-                if (name === 'href' || name === 'title') {
+                console.log('1',name, value)
+                if (name === 'href' || name === 'title' || name === 'dchar') {
                     if (value) {
                         this.domNode.setAttribute(name, value);
-                        if (name === 'title'){
-                            this.domNode.innerHTML = value;
+                        if (name === 'dchar'){
+                            this.domNode.innerHTML = value + this.domNode.getAttribute('title');
                         }
                     } else {
                         this.domNode.removeAttribute(name, value);
@@ -83,6 +85,7 @@ function bx_editor_init(oEditor, oParams){
             };
                 
             static formats(node) {
+                console.log('2',node)
                 let format = {};
                 if (node.hasAttribute('href')) {
                     format.href = node.getAttribute('href');
@@ -90,6 +93,9 @@ function bx_editor_init(oEditor, oParams){
                 if (node.hasAttribute('title')) {
                     format.title = node.getAttribute('title');
                 }
+                if (node.hasAttribute('dchar')) {
+                    format.dchar = node.getAttribute('dchar');
+                }
                 return format;
             }  
             
@@ -154,18 +160,18 @@ function bx_editor_init(oEditor, oParams){
             toolbar: oParams.toolbar,
             mention: {
                 allowedChars: /^[A-Za-z\sÅÄÖåäö]*$/,
-                mentionDenotationChars: ["@"],
-                showDenotationChar: false,
+                mentionDenotationChars: ["@", "#"],
+                showDenotationChar: true,
                 blotName: 'menthion-link',
                 source: function (searchTerm, renderList, mentionChar) {
-                  $.getJSON(oParams.root_url + 'searchExtended.php?action=get_authors&', { term: searchTerm}, function(data){
-                    renderList(data, searchTerm);
+                  $.getJSON(oParams.root_url + 'searchExtended.php?action=get_mention&', { symbol: mentionChar, term: searchTerm}, function(data){
+                      renderList(data, searchTerm);
                   });
                 },
                 renderItem: function(item, searchTerm){
-                  item.id = item.url;
-                  item.value = item.label;
-                  return '@' + item.value;
+                    item.id = item.url;
+                    item.value = item.label;
+                    return item.symbol + item.value;
                 },
                 onSelect: function(item, insertItem){
                     insertItem(item, false)

+ 0 - 26
inc/js/functions.js

@@ -1305,30 +1305,4 @@ function bx_regexp_escape(s)
         .replace(/-/mg, '\\x2d');
 }
 
-function bx_copy_to_clipboard(s) 
-{
-    console.log(s);
-    if (window.clipboardData && window.clipboardData.setData) {
-        return window.clipboardData.setData("Text", text);
-
-    }
-    else if (document.queryCommandSupported && document.queryCommandSupported("copy")) {
-        var textarea = document.createElement("textarea");
-        textarea.textContent = s;
-        textarea.style.position = "fixed";  // Prevent scrolling to bottom of page in Microsoft Edge.
-        document.body.appendChild(textarea);
-        textarea.select();
-        try {
-            return document.execCommand("copy");  // Security exception may be thrown by some browsers.
-        }
-        catch (ex) {
-            console.warn("Copy to clipboard failed.", ex);
-            return prompt("Copy to clipboard: Ctrl+C, Enter", text);
-        }
-        finally {
-            document.body.removeChild(textarea);
-        }
-    }
-}
-
 /** @} */