Powerful and easy to use cms to build websites, blogs or ecommerce stores.
HTML backendblogblog-engineblog-platformbloggingcmscontent-managementcontent-management-systemecommerceecommerce-platformno-codepage-builderphpphp-cmsphp7php8self-hostedshopping-cartweb-applicationwebsite-builder
Text editor link autocomplete for post/pages, products and quick commands.
givanzb94071127853
diff --git a/admin/controller/content/autocomplete-trait.php b/admin/controller/content/autocomplete-trait.phpindex 74a426a..2624ac2 100644--- a/admin/controller/content/autocomplete-trait.php+++ b/admin/controller/content/autocomplete-trait.php@@ -24,6 +24,7 @@ namespace Vvveb\Controller\Content;use \Vvveb\Sql\categorySQL;use Vvveb\System\Images;+use function Vvveb\url;trait AutocompleteTrait {function categoriesAutocomplete() {@@ -108,6 +109,55 @@ trait AutocompleteTrait {return false;}+ function urlAutocomplete() {+ $products = new \Vvveb\Sql\ProductSQL();++ $options = [+ 'start' => 0,+ 'limit' => 5,+ 'like' => trim($this->request->get['text']),+ ] + $this->global;++ unset($options['admin_id']);+ $results = $products->getAll($options);++ $search = [];++ if (isset($results['products'])) {+ foreach ($results['products'] as $product) {+ $product['image'] = Images::image($product['image'], 'product', 'thumb');+ $search[] = [+ 'type' => 'cardimage',+ 'src' => $product['image'],+ 'text' => $product['name'],+ 'value'=> '<a href="' . url('product/product/index', ['slug'=> $product['slug']]) . '">' . $product['name'] . '</a>',+ ];+ }+ }++ if (count($search) < 5) {+ $posts = new \Vvveb\Sql\PostSQL();+ $results = $posts->getAll($options);++ if (isset($results['posts'])) {+ foreach ($results['posts'] as $post) {+ $post['image'] = Images::image($post['image'], 'post', 'thumb');+ $search[] = [+ 'type' => 'cardimage',+ 'src' => $post['image'],+ 'text' => $post['name'],+ 'value'=> '<a href="' . url('content/post/index', ['slug'=> $post['slug']]) . '">' . $post['name'] . '</a>',+ ];+ }+ }+ }+ //echo json_encode($search);+ $this->response->setType('json');+ $this->response->output($search);++ return false;+ }+function productsAutocomplete() {$products = new \Vvveb\Sql\ProductSQL();diff --git a/admin/controller/content/edit.php b/admin/controller/content/edit.phpindex be173d8..704fb00 100644--- a/admin/controller/content/edit.php+++ b/admin/controller/content/edit.php@@ -90,6 +90,7 @@ class Edit extends Base {$controllerPath = $admin_path . 'index.php?module=media/media';$view->scanUrl = "$controllerPath&action=scan";$view->uploadUrl = "$controllerPath&action=upload";+ $view->linkUrl = $admin_path . 'index.php?module=content/post&action=urlAutocomplete';$theme = Sites::getTheme() ?? 'default';$view->themeCss = PUBLIC_PATH . "themes/$theme/css/admin-post-editor.css";//$view->themeCss = PUBLIC_PATH . "themes/$theme/css/style.css";diff --git a/admin/sql/mysqli/post.sql b/admin/sql/mysqli/post.sqlindex 9f3b8d4..80fa448 100755--- a/admin/sql/mysqli/post.sql+++ b/admin/sql/mysqli/post.sql@@ -6,6 +6,7 @@IN start INT,IN limit INT,IN search CHAR,+ IN like CHAR,IN username CHAR,IN status CHAR,IN taxonomy_item_slug CHAR,@@ -174,6 +175,12 @@AND MATCH(pd.name, pd.content) AGAINST(:search)END @IF+ -- like+ @IF isset(:like) && !empty(:like)+ THEN+ AND pd.name LIKE CONCAT('%',:like,'%')+ END @IF+-- post_id@IF isset(:post_id) && count(:post_id) > 0THENdiff --git a/admin/sql/pgsql/post.sql b/admin/sql/pgsql/post.sqlindex 294ccf8..16580d9 100755--- a/admin/sql/pgsql/post.sql+++ b/admin/sql/pgsql/post.sql@@ -6,6 +6,7 @@IN start INT,IN limit INT,IN search CHAR,+ IN like CHAR,IN username CHAR,IN status CHAR,IN taxonomy_item_slug CHAR,@@ -113,6 +114,13 @@AND to_tsvector(name) || to_tsvector(content) @@ plainto_tsquery(:search)END @IF+ -- like+ @IF isset(:like) && !empty(:like)+ THEN+ AND pd.name ILIKE '%' || :like || '%'+ END @IF++-- post_id@IF isset(:post_id) && count(:post_id) > 0THENdiff --git a/admin/sql/sqlite/post.sql b/admin/sql/sqlite/post.sqlindex 31a2cd7..333ce58 100755--- a/admin/sql/sqlite/post.sql+++ b/admin/sql/sqlite/post.sql@@ -6,6 +6,7 @@IN start INT,IN limit INT,IN search CHAR,+ IN like CHAR,IN username CHAR,IN status CHAR,IN taxonomy_item_slug CHAR,@@ -109,6 +110,12 @@AND (post_content_search = :search)END @IF+ -- like+ @IF isset(:like) && !empty(:like)+ THEN+ AND pd.name LIKE '%' || :like || '%'+ END @IF+-- post_id@IF isset(:post_id) && count(:post_id) > 0THENdiff --git a/public/admin/default b/public/admin/defaultindex 085aee2..b127fff 160000--- a/public/admin/default+++ b/public/admin/default@@ -1 +1 @@-Subproject commit 085aee2c3246884dae28c11bcd607dd3616337e5+Subproject commit b127fffded85240a7955611d8e46d20bb0fd0b66diff --git a/public/js/libs/tinymce-options.js b/public/js/libs/tinymce-options.jsindex 73109de..caca2aa 100755--- a/public/js/libs/tinymce-options.js+++ b/public/js/libs/tinymce-options.js@@ -158,6 +158,196 @@ let tinyMceOptions = {});window.dispatchEvent(new CustomEvent("tinymce.setup", {detail: editor}));+++ //product and posts/pages autocomplete+ const onAction = (autocompleteApi, rng, value) => {+ editor.selection.setRng(rng);+ editor.insertContent(value);+ autocompleteApi.hide();+ };++ let insertActions = [+ {+ text: 'Heading 1',+ icon: 'h1',+ action: function () {+ editor.execCommand('mceInsertContent', false, '<h1>Heading 1</h1>')+ editor.selection.select(editor.selection.getNode());+ }+ },+ {+ text: 'Heading 2',+ icon: 'h2',+ action: function () {+ editor.execCommand('mceInsertContent', false, '<h2>Heading 2</h2>');+ editor.selection.select(editor.selection.getNode());+ }+ },+ {+ text: 'Heading 3',+ icon: 'h3',+ action: function () {+ editor.execCommand('mceInsertContent', false, '<h3>Heading 3</h3>');+ editor.selection.select(editor.selection.getNode());+ }+ },+ {+ type: 'separator'+ },+ {+ text: 'Table',+ icon: 'table',+ action: function () {+ editor.execCommand('mceInsertTable', false, { rows: 2, columns: 2 });+ }+ }, {+ text: 'Image',+ icon: 'image',+ action: function () {+ //editor.execCommand('mceImage');+ //editor.execCommand('InsertImage', false, '../img/logo.png');+ if (!Vvveb.MediaModal) {+ Vvveb.MediaModal = new MediaModal(true);+ Vvveb.MediaModal.mediaPath = mediaPath;+ }+ Vvveb.MediaModal.open(null, function (file) {+ editor.insertContent("<div>" + editor.dom.createHTML('img', {+ src: file,+ "class": "align-center"+ }) + "</div>");+ });+ }+ },+ {+ type: 'separator'+ },+ {+ text: 'Bulleted list',+ icon: 'unordered-list',+ action: function () {+ editor.execCommand('InsertUnorderedList', false);+ }+ },+ {+ text: 'Numbered list',+ icon: 'ordered-list',+ action: function () {+ editor.execCommand('InsertOrderedList', false);+ }+ }, {+ text: 'Separator',+ icon: 'line',+ action: function () {+ editor.execCommand('InsertHorizontalRule');+ }+ },/*+ {+ type: 'separator'+ }, {+ text: 'Embed',+ icon: 'embed',+ action: function () {+ //editor.execCommand('mceLink', false, { dialog: true });+ editor.dispatch('contexttoolbar-show', { toolbarKey: 'quicklink' });+ //editor.execCommand('mceMedia');+ }+ }, {+ text: 'Youtube',+ icon: 'embed',+ action: function () {+ editor.execCommand('mceMedia');+ }+ }, {+ text: 'Twitter',+ icon: 'embed-page',+ action: function () {+ editor.execCommand('mceMedia');+ }+ }*/+ ];++ // Register the slash commands autocompleter+ editor.ui.registry.addAutocompleter('slashcommands', {+ ch: '/',+ minChars: 0,+ columns: 1,+ fetch: function (pattern) {+ const matchedActions = insertActions.filter(function (action) {+ return action.type === 'separator' ||+ action.text.toLowerCase().indexOf(pattern.toLowerCase()) !== -1;+ });++ return new Promise((resolve) => {+ var results = matchedActions.map(function (action) {+ return {+ meta: action,+ text: action.text,+ icon: action.icon,+ value: action.text,+ type: action.type+ }+ });+ resolve(results);+ });+ },+ onAction: function (autocompleteApi, rng, action, meta) {+ editor.selection.setRng(rng);+ // Some actions don't delete the "slash", so we delete all the slash+ // command content before performing the action+ editor.execCommand('Delete');+ meta.action();+ autocompleteApi.hide();+ }+ });++ editor.ui.registry.addAutocompleter('links', {+ ch: '/',+ minChars: 1,+ columns: 1,+ highlightOn: ['char_name'],+ onAction: onAction,+ fetch: (pattern) => {+ return new Promise((resolve) => {+ fetch(linkUrl + "&"+ new URLSearchParams({text:pattern}))+ .then((response) => {+ if (!response.ok) { throw new Error(response) }+ return response.json()+ })+ .then((data) => {+ const results = data.map(char => ({+ type: 'cardmenuitem',+ value: char.value,+ label: char.text,+ items: [+ {+ type: 'cardcontainer',+ direction: 'horizontal',+ items: [+ {+ type: 'cardimage',+ src: char.src,+ alt: char.text,+ classes: ['w-25', 'me-2']+ },+ {+ type: 'cardtext',+ text: char.text,+ name: 'char_name'+ }+ ]+ }+ ]+ }));+ resolve(results);+ })+ .catch(error => {+ console.log(error);+ displayToast("bg-danger", "Error", "Error renaming page!");+ });+ });+ }+ });},plugins: 'preview searchreplace autolink autosave autoresize directionality code visualblocks visualchars fullscreen image media link table charmap lists wordcount help quickbars emoticons table accordion',@@ -287,6 +477,8 @@ let tinyMceOptions = {table_default_attributes: {"class": 'table table-bordered',},+ link_quicklink: true,+ link_list: linkUrl,table_class_list: [{title: 'None', value: 'table'},{title: 'striped', value: 'table-striped'},