From 96c086ea139047fc893ffb51843d3e24c5422c44 Mon Sep 17 00:00:00 2001 From: rabuzarus Date: Fri, 16 Mar 2018 13:55:26 +0100 Subject: [PATCH 1/3] hashtag autocomplete --- src/Module/Hashtag.php | 36 ++++++++++++++++++++++++++++++++++++ view/js/autocomplete.js | 27 +++++++++++++++++++++++++-- 2 files changed, 61 insertions(+), 2 deletions(-) create mode 100644 src/Module/Hashtag.php diff --git a/src/Module/Hashtag.php b/src/Module/Hashtag.php new file mode 100644 index 0000000000..879b27ea7a --- /dev/null +++ b/src/Module/Hashtag.php @@ -0,0 +1,36 @@ + strtolower($tag['term'])]; + } + dba::close($taglist); + + System::jsonExit($result); + } +} diff --git a/view/js/autocomplete.js b/view/js/autocomplete.js index 219ad794bc..eb9d5efbea 100644 --- a/view/js/autocomplete.js +++ b/view/js/autocomplete.js @@ -77,6 +77,10 @@ function contact_format(item) { return "
" + item.text + "
"; } +function tag_format(item) { + return ""; +} + function editor_replace(item) { if (typeof item.replace !== 'undefined') { return '$1$2' + item.replace; @@ -212,6 +216,15 @@ function string2bb(element) { template: contact_format, }; + // Autocomplete hashtags + tags = { + match: /(^|\s)(\#)([^ \n]{2,})$/, + index: 3, + search: function(term, callback) { $.getJSON(baseurl + '/hashtag/' + '?f=&t=' + term).done(function(data) { callback($.map(data, function(entry) { return entry.text.indexOf(term) === 0 ? entry : null; })); }); }, + replace: function(item) { return "$1$2" + item.text + ' '; }, + template: tag_format + }; + // Autocomplete smilies e.g. ":like" smilies = { match: /(^|\s)(:[a-z]{2,})$/, @@ -222,7 +235,7 @@ function string2bb(element) { }; this.attr('autocomplete','off'); - this.textcomplete([contacts, forums, smilies], {className:'acpopup', zIndex:10000}); + this.textcomplete([contacts, forums, smilies, tags], {className:'acpopup', zIndex:10000}); }; })( jQuery ); @@ -248,8 +261,18 @@ function string2bb(element) { replace: webbie_replace, template: contact_format, }; + + // Autocomplete hashtags + tags = { + match: /(^|\s)(\#)([^ \n]{2,})$/, + index: 3, + search: function(term, callback) { $.getJSON(baseurl + '/hashtag/' + '?f=&t=' + term).done(function(data) { callback($.map(data, function(entry) { return entry.text.indexOf(term) === 0 ? entry : null; })); }); }, + replace: function(item) { return "$1$2" + item.text; }, + template: tag_format + }; + this.attr('autocomplete', 'off'); - var a = this.textcomplete([contacts, community], {className:'acpopup', maxCount:100, zIndex: 10000, appendTo:'nav'}); + var a = this.textcomplete([contacts, community, tags], {className:'acpopup', maxCount:100, zIndex: 10000, appendTo:'nav'}); a.on('textComplete:select', function(e, value, strategy) { submit_form(this); }); }; })( jQuery ); From 86d84e5f31ad2798ae0f562929abee00f8472670 Mon Sep 17 00:00:00 2001 From: rabuzarus Date: Fri, 16 Mar 2018 14:27:04 +0100 Subject: [PATCH 2/3] fix code standards --- src/Module/Hashtag.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Module/Hashtag.php b/src/Module/Hashtag.php index 879b27ea7a..7dfd3cdb0a 100644 --- a/src/Module/Hashtag.php +++ b/src/Module/Hashtag.php @@ -11,10 +11,11 @@ use dba; /** * Hashtag module. */ -class Hashtag extends BaseModule { - - public static function init() +class Hashtag extends BaseModule { + + public static function content() + { $result = []; $t = escape_tags($_REQUEST['t']); From c209853e1d77f8362760e83ad3cbee2c044e6fef Mon Sep 17 00:00:00 2001 From: rabuzarus Date: Fri, 16 Mar 2018 14:44:51 +0100 Subject: [PATCH 3/3] add dependencies (require_once) to hashtag module --- src/Module/Hashtag.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Module/Hashtag.php b/src/Module/Hashtag.php index 7dfd3cdb0a..82cfa1f847 100644 --- a/src/Module/Hashtag.php +++ b/src/Module/Hashtag.php @@ -8,6 +8,9 @@ use Friendica\BaseModule; use Friendica\Core\System; use dba; +require_once 'include/dba.php'; +require_once 'include/text.php'; + /** * Hashtag module. */