From 0a67f3be55a2c73096f12922cfba20ca52484c74 Mon Sep 17 00:00:00 2001 From: vikram chand Date: Fri, 26 Feb 2021 12:42:37 +0530 Subject: [PATCH 01/16] Added: seeder for insights --- Http/Middleware/SetContent.php | 2 +- Libraries/CmsSeeder.php | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/Http/Middleware/SetContent.php b/Http/Middleware/SetContent.php index 432f7c4..cd6f29b 100644 --- a/Http/Middleware/SetContent.php +++ b/Http/Middleware/SetContent.php @@ -26,7 +26,7 @@ public function handle(Request $request, Closure $next) $permalink = $request->segment(2); - if(isset($content_type) || !isset($permalink)) + if(isset($content_type) && !isset($permalink)) { $permalink = $content_type; $content_type = 'pages'; diff --git a/Libraries/CmsSeeder.php b/Libraries/CmsSeeder.php index 5f22b97..c7cfc49 100644 --- a/Libraries/CmsSeeder.php +++ b/Libraries/CmsSeeder.php @@ -210,7 +210,7 @@ public static function contentTypes($file_path) } } //------------------------------------------------------- - public static function pages($theme_slug, $file_path) + public static function createSampleField($theme_slug, $file_path, $content_type_slug = 'pages') { $theme = self::getTheme($theme_slug); @@ -230,7 +230,7 @@ public static function pages($theme_slug, $file_path) return false; } - $content_type = ContentType::where('slug', 'pages') + $content_type = ContentType::where('slug', $content_type_slug) ->with(['groups.fields.type']) ->first()->toArray(); @@ -252,6 +252,10 @@ public static function pages($theme_slug, $file_path) continue; } + if(!isset($item['slug']) || !$item['slug']){ + $item['slug'] = Str::slug($item['name']); + } + $page = Content::where('slug', $item['slug']) ->where('vh_cms_content_type_id', $content_type['id']) ->where('vh_theme_id', $theme->id) @@ -288,6 +292,8 @@ public static function pages($theme_slug, $file_path) } } + //------------------------------------------------------- + //------------------------------------------------------- public static function fillFields($groups) { From ee8c8fcd24a27c9e588c09b33eca62382beba108 Mon Sep 17 00:00:00 2001 From: vikram chand Date: Tue, 2 Mar 2021 14:25:00 +0530 Subject: [PATCH 02/16] Added: dynamic variables --- Entities/Block.php | 4 ++- Http/Controllers/Backend/BlocksController.php | 20 ++++++++++++ Vue/pages/blocks/Edit.vue | 30 ++++++++++++++++- Vue/pages/blocks/EditJs.js | 32 +++++++++++++++++++ Vue/pages/blocks/ViewJs.js | 22 +++++++++++-- 5 files changed, 104 insertions(+), 4 deletions(-) diff --git a/Entities/Block.php b/Entities/Block.php index 9a53110..ff7b966 100644 --- a/Entities/Block.php +++ b/Entities/Block.php @@ -534,7 +534,9 @@ public static function getBlock($block_slug) return false; } - return $block->content; + $output = str_replace("{{url('/')}}",url('/'),$block->content); + + return $output; } //--------------------------------------------------------------------------- diff --git a/Http/Controllers/Backend/BlocksController.php b/Http/Controllers/Backend/BlocksController.php index 111e8ce..e48f77e 100644 --- a/Http/Controllers/Backend/BlocksController.php +++ b/Http/Controllers/Backend/BlocksController.php @@ -23,6 +23,26 @@ public function __construct() public function getAssets(Request $request) { + $data['replace_strings'] = [ + + 0=>[ + 'name' => '{{MODULE_URL}}', + 'value' => url('/vaahcms/modules'), + ], + 1=>[ + 'name' => '{{THEME_URL}}', + 'value' => url('/vaahcms/themes'), + ], + 2=>[ + 'name' => '{{STORAGE_URL}}', + 'value' => url('/storage'), + ], + 3=>[ + 'name' => '{{PUBLIC_URL}}', + 'value' => url('/'), + ], + ]; + $data['field_types'] = FieldType::select('id', 'name', 'slug', 'meta') ->get(); diff --git a/Vue/pages/blocks/Edit.vue b/Vue/pages/blocks/Edit.vue index 696deea..77bc5f1 100644 --- a/Vue/pages/blocks/Edit.vue +++ b/Vue/pages/blocks/Edit.vue @@ -29,11 +29,35 @@

Code Editor

+

+ + + + + + + + + {{string.name.replace(/[^a-zA-Z ]/g, " ")}} + + + + + + +

@@ -41,14 +65,18 @@
+ + + { + $.each(self.page.assets.replace_strings, function( index, string ) { + let regex = new RegExp(string.name, "g"); + data.content = data.content.replace(regex, string.value); + if (index === self.page.assets.replace_strings.length -1) resolve(); + }); + + }); + + bar.then(() => { + this.update('active_item', data); + }); + + } else { //if item does not exist or delete then redirect to list From 3c47d3fe386103ed019c90e3062d075b8abbc841 Mon Sep 17 00:00:00 2001 From: vikram chand Date: Wed, 3 Mar 2021 18:34:03 +0530 Subject: [PATCH 03/16] Updated submodule Vue/vaahvue --- Vue/vaahvue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Vue/vaahvue b/Vue/vaahvue index 70a2068..4bcb875 160000 --- a/Vue/vaahvue +++ b/Vue/vaahvue @@ -1 +1 @@ -Subproject commit 70a206801477d723a17b1f77eeac81f567244918 +Subproject commit 4bcb8755d06ced953fd528c8ecfea9c13fb6ffce From e31c9dae6640879d9309dce5a5bbd53915f3861d Mon Sep 17 00:00:00 2001 From: vikram chand Date: Fri, 5 Mar 2021 16:04:44 +0530 Subject: [PATCH 04/16] Testing --- Providers/CmsServiceProvider.php | 1 + 1 file changed, 1 insertion(+) diff --git a/Providers/CmsServiceProvider.php b/Providers/CmsServiceProvider.php index 3d898d5..3d9201d 100644 --- a/Providers/CmsServiceProvider.php +++ b/Providers/CmsServiceProvider.php @@ -33,6 +33,7 @@ public function boot(Router $router) $this->registerConfig(); $this->registerViews(); $this->registerAssets(); + //$this->registerFactories(); $this->loadMigrationsFrom(__DIR__ . '/../Database/Migrations'); $this->registerSeeders(); From 8edc9a4b9383a7cb366c4e02a6a057fca7ae005f Mon Sep 17 00:00:00 2001 From: vikram chand Date: Fri, 12 Mar 2021 15:32:47 +0530 Subject: [PATCH 05/16] Added: Add dynamic variable replace method --- Entities/Content.php | 11 +++- Helpers/cms.php | 58 +++++++++++++++++++ Http/Controllers/Backend/BlocksController.php | 20 +------ Vue/pages/blocks/Edit.vue | 6 +- Vue/pages/blocks/EditJs.js | 21 +++++-- 5 files changed, 87 insertions(+), 29 deletions(-) diff --git a/Entities/Content.php b/Entities/Content.php index 2117b66..4d7c62a 100644 --- a/Entities/Content.php +++ b/Entities/Content.php @@ -438,11 +438,16 @@ public static function getFormGroups(Content $content, $type, array $fields=null $field_content->where('vh_cms_form_field_id', $field->id); $field_content = $field_content->first(); - if($field_content) { $groups[$i]['fields'][$y]['vh_cms_form_field_id'] = $field_content->id; - $groups[$i]['fields'][$y]['content'] = $field_content->content; + + if($field_content->content && !is_array($field_content->content) && !is_object($field_content->content)){ + $groups[$i]['fields'][$y]['content'] = replace_dynamic_strings($field_content->content); + }else{ + $groups[$i]['fields'][$y]['content'] = $field_content->content; + } + $groups[$i]['fields'][$y]['content_meta'] = $field_content->meta; } @@ -536,6 +541,8 @@ public static function storeFormGroups(Content $content, $groups) if(is_array($field['content']) || is_object($field['content'])) { $field['content'] = json_encode($field['content']); + }else{ + $field['content'] = replace_dynamic_strings($field['content'],true); } if($field['type']['slug'] == 'user' && $field['content']){ diff --git a/Helpers/cms.php b/Helpers/cms.php index a7e41cc..e86862f 100644 --- a/Helpers/cms.php +++ b/Helpers/cms.php @@ -18,12 +18,70 @@ //----------------------------------------------------------------------------------- use VaahCms\Modules\Cms\Entities\Content; + +//----------------------------------------------------------------------------------- +function cms_dynamic_variables() +{ + $list = [ + [ + 'name' => '#!PUBLIC:MODULE_URL!#', + 'value' => url('/vaahcms/modules'), + 'detail'=>'Will be replaced with public module url.' + ], + [ + 'name' => '#!PUBLIC:THEME_URL!#', + 'value' => url('/vaahcms/themes'), + 'detail'=>'Will be replaced with public theme url.' + ], + [ + 'name' => '#!PUBLIC:STORAGE_URL!#', + 'value' => url('/storage'), + 'detail'=>'Will be replaced with public storage url.' + ], + [ + 'name' => '#!PUBLIC:BASE_URL!#', + 'value' => url('/'), + 'detail'=>'Will be replaced with public url.', + ] + ]; + + return $list; + +} + function get_content_types(array $args = null) { +} + +function replace_dynamic_strings($content = null,$has_replace_string = false) +{ + + $extend = new \WebReinvent\VaahCms\Http\Controllers\ExtendController(); + + $dynamic_string = $extend->getPublicUrls(); + + if($dynamic_string && $dynamic_string['status'] === 'success'){ + foreach ($dynamic_string['data'] as $string){ + + if($has_replace_string){ + $content = str_replace($string['value'],$string['name'],$content); + }else{ + $content = str_replace($string['name'],$string['value'],$content); + } + + + } + } + + return $content; + + + + } //----------------------------------------------------------------------------------- function get_content_type($id, array $args = null) diff --git a/Http/Controllers/Backend/BlocksController.php b/Http/Controllers/Backend/BlocksController.php index e48f77e..b98643d 100644 --- a/Http/Controllers/Backend/BlocksController.php +++ b/Http/Controllers/Backend/BlocksController.php @@ -23,25 +23,7 @@ public function __construct() public function getAssets(Request $request) { - $data['replace_strings'] = [ - - 0=>[ - 'name' => '{{MODULE_URL}}', - 'value' => url('/vaahcms/modules'), - ], - 1=>[ - 'name' => '{{THEME_URL}}', - 'value' => url('/vaahcms/themes'), - ], - 2=>[ - 'name' => '{{STORAGE_URL}}', - 'value' => url('/storage'), - ], - 3=>[ - 'name' => '{{PUBLIC_URL}}', - 'value' => url('/'), - ], - ]; + $data['replace_strings'] = vh_action('getPublicUrls', null, 'array'); $data['field_types'] = FieldType::select('id', 'name', 'slug', 'meta') ->get(); diff --git a/Vue/pages/blocks/Edit.vue b/Vue/pages/blocks/Edit.vue index 77bc5f1..ddf861c 100644 --- a/Vue/pages/blocks/Edit.vue +++ b/Vue/pages/blocks/Edit.vue @@ -22,14 +22,14 @@

Editor

Code Editor @@ -45,7 +45,7 @@ - + Date: Fri, 12 Mar 2021 18:08:52 +0530 Subject: [PATCH 06/16] Fixed: Update cms replace dynamic string --- Helpers/cms.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Helpers/cms.php b/Helpers/cms.php index e86862f..7e760b3 100644 --- a/Helpers/cms.php +++ b/Helpers/cms.php @@ -199,6 +199,9 @@ function setReturnValue($field,$return_html=true) return $field->content; } + if(!is_array($field->content) && !is_object($field->content)){ + $field->content = replace_dynamic_strings($field->content); + } switch($field['type']['slug']){ From ba7f6dc2af7845aa09ab1b30600ed9dde4d4ef78 Mon Sep 17 00:00:00 2001 From: vikram chand Date: Fri, 26 Feb 2021 12:42:37 +0530 Subject: [PATCH 07/16] Added: seeder for insights --- Libraries/CmsSeeder.php | 2 ++ Vue/vaahvue | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Libraries/CmsSeeder.php b/Libraries/CmsSeeder.php index ca9268c..c7cfc49 100644 --- a/Libraries/CmsSeeder.php +++ b/Libraries/CmsSeeder.php @@ -292,6 +292,8 @@ public static function createSampleField($theme_slug, $file_path, $content_type_ } } + //------------------------------------------------------- + //------------------------------------------------------- public static function fillFields($groups) { diff --git a/Vue/vaahvue b/Vue/vaahvue index 177129f..4bcb875 160000 --- a/Vue/vaahvue +++ b/Vue/vaahvue @@ -1 +1 @@ -Subproject commit 177129fb5c616e6c882d8d6d9abd1e1be4462fb5 +Subproject commit 4bcb8755d06ced953fd528c8ecfea9c13fb6ffce From 209955a88b3c16992c71418eb859bcc5a0acb859 Mon Sep 17 00:00:00 2001 From: vikram chand Date: Tue, 2 Mar 2021 14:25:00 +0530 Subject: [PATCH 08/16] Added: dynamic variables --- Entities/Block.php | 4 ++- Http/Controllers/Backend/BlocksController.php | 20 ++++++++++++ Vue/pages/blocks/Edit.vue | 30 ++++++++++++++++- Vue/pages/blocks/EditJs.js | 32 +++++++++++++++++++ Vue/pages/blocks/ViewJs.js | 22 +++++++++++-- 5 files changed, 104 insertions(+), 4 deletions(-) diff --git a/Entities/Block.php b/Entities/Block.php index 9a53110..ff7b966 100644 --- a/Entities/Block.php +++ b/Entities/Block.php @@ -534,7 +534,9 @@ public static function getBlock($block_slug) return false; } - return $block->content; + $output = str_replace("{{url('/')}}",url('/'),$block->content); + + return $output; } //--------------------------------------------------------------------------- diff --git a/Http/Controllers/Backend/BlocksController.php b/Http/Controllers/Backend/BlocksController.php index 111e8ce..e48f77e 100644 --- a/Http/Controllers/Backend/BlocksController.php +++ b/Http/Controllers/Backend/BlocksController.php @@ -23,6 +23,26 @@ public function __construct() public function getAssets(Request $request) { + $data['replace_strings'] = [ + + 0=>[ + 'name' => '{{MODULE_URL}}', + 'value' => url('/vaahcms/modules'), + ], + 1=>[ + 'name' => '{{THEME_URL}}', + 'value' => url('/vaahcms/themes'), + ], + 2=>[ + 'name' => '{{STORAGE_URL}}', + 'value' => url('/storage'), + ], + 3=>[ + 'name' => '{{PUBLIC_URL}}', + 'value' => url('/'), + ], + ]; + $data['field_types'] = FieldType::select('id', 'name', 'slug', 'meta') ->get(); diff --git a/Vue/pages/blocks/Edit.vue b/Vue/pages/blocks/Edit.vue index 696deea..77bc5f1 100644 --- a/Vue/pages/blocks/Edit.vue +++ b/Vue/pages/blocks/Edit.vue @@ -29,11 +29,35 @@

Code Editor

+

+ + + + + + + + + {{string.name.replace(/[^a-zA-Z ]/g, " ")}} + + + + + + +

@@ -41,14 +65,18 @@
+ + + { + $.each(self.page.assets.replace_strings, function( index, string ) { + let regex = new RegExp(string.name, "g"); + data.content = data.content.replace(regex, string.value); + if (index === self.page.assets.replace_strings.length -1) resolve(); + }); + + }); + + bar.then(() => { + this.update('active_item', data); + }); + + } else { //if item does not exist or delete then redirect to list From 0c9c034c268be0420a842208516729a6a4bdc9c9 Mon Sep 17 00:00:00 2001 From: vikram chand Date: Fri, 5 Mar 2021 16:04:44 +0530 Subject: [PATCH 09/16] Testing --- Providers/CmsServiceProvider.php | 1 + 1 file changed, 1 insertion(+) diff --git a/Providers/CmsServiceProvider.php b/Providers/CmsServiceProvider.php index 3d898d5..3d9201d 100644 --- a/Providers/CmsServiceProvider.php +++ b/Providers/CmsServiceProvider.php @@ -33,6 +33,7 @@ public function boot(Router $router) $this->registerConfig(); $this->registerViews(); $this->registerAssets(); + //$this->registerFactories(); $this->loadMigrationsFrom(__DIR__ . '/../Database/Migrations'); $this->registerSeeders(); From caf1f074ffa8a52ac4cf00bf3da852ba0f4bc109 Mon Sep 17 00:00:00 2001 From: vikram chand Date: Fri, 12 Mar 2021 15:32:47 +0530 Subject: [PATCH 10/16] Added: Add dynamic variable replace method --- Entities/Content.php | 11 +++- Helpers/cms.php | 58 +++++++++++++++++++ Http/Controllers/Backend/BlocksController.php | 20 +------ Vue/pages/blocks/Edit.vue | 6 +- Vue/pages/blocks/EditJs.js | 21 +++++-- 5 files changed, 87 insertions(+), 29 deletions(-) diff --git a/Entities/Content.php b/Entities/Content.php index 2117b66..4d7c62a 100644 --- a/Entities/Content.php +++ b/Entities/Content.php @@ -438,11 +438,16 @@ public static function getFormGroups(Content $content, $type, array $fields=null $field_content->where('vh_cms_form_field_id', $field->id); $field_content = $field_content->first(); - if($field_content) { $groups[$i]['fields'][$y]['vh_cms_form_field_id'] = $field_content->id; - $groups[$i]['fields'][$y]['content'] = $field_content->content; + + if($field_content->content && !is_array($field_content->content) && !is_object($field_content->content)){ + $groups[$i]['fields'][$y]['content'] = replace_dynamic_strings($field_content->content); + }else{ + $groups[$i]['fields'][$y]['content'] = $field_content->content; + } + $groups[$i]['fields'][$y]['content_meta'] = $field_content->meta; } @@ -536,6 +541,8 @@ public static function storeFormGroups(Content $content, $groups) if(is_array($field['content']) || is_object($field['content'])) { $field['content'] = json_encode($field['content']); + }else{ + $field['content'] = replace_dynamic_strings($field['content'],true); } if($field['type']['slug'] == 'user' && $field['content']){ diff --git a/Helpers/cms.php b/Helpers/cms.php index a7e41cc..e86862f 100644 --- a/Helpers/cms.php +++ b/Helpers/cms.php @@ -18,12 +18,70 @@ //----------------------------------------------------------------------------------- use VaahCms\Modules\Cms\Entities\Content; + +//----------------------------------------------------------------------------------- +function cms_dynamic_variables() +{ + $list = [ + [ + 'name' => '#!PUBLIC:MODULE_URL!#', + 'value' => url('/vaahcms/modules'), + 'detail'=>'Will be replaced with public module url.' + ], + [ + 'name' => '#!PUBLIC:THEME_URL!#', + 'value' => url('/vaahcms/themes'), + 'detail'=>'Will be replaced with public theme url.' + ], + [ + 'name' => '#!PUBLIC:STORAGE_URL!#', + 'value' => url('/storage'), + 'detail'=>'Will be replaced with public storage url.' + ], + [ + 'name' => '#!PUBLIC:BASE_URL!#', + 'value' => url('/'), + 'detail'=>'Will be replaced with public url.', + ] + ]; + + return $list; + +} + function get_content_types(array $args = null) { +} + +function replace_dynamic_strings($content = null,$has_replace_string = false) +{ + + $extend = new \WebReinvent\VaahCms\Http\Controllers\ExtendController(); + + $dynamic_string = $extend->getPublicUrls(); + + if($dynamic_string && $dynamic_string['status'] === 'success'){ + foreach ($dynamic_string['data'] as $string){ + + if($has_replace_string){ + $content = str_replace($string['value'],$string['name'],$content); + }else{ + $content = str_replace($string['name'],$string['value'],$content); + } + + + } + } + + return $content; + + + + } //----------------------------------------------------------------------------------- function get_content_type($id, array $args = null) diff --git a/Http/Controllers/Backend/BlocksController.php b/Http/Controllers/Backend/BlocksController.php index e48f77e..b98643d 100644 --- a/Http/Controllers/Backend/BlocksController.php +++ b/Http/Controllers/Backend/BlocksController.php @@ -23,25 +23,7 @@ public function __construct() public function getAssets(Request $request) { - $data['replace_strings'] = [ - - 0=>[ - 'name' => '{{MODULE_URL}}', - 'value' => url('/vaahcms/modules'), - ], - 1=>[ - 'name' => '{{THEME_URL}}', - 'value' => url('/vaahcms/themes'), - ], - 2=>[ - 'name' => '{{STORAGE_URL}}', - 'value' => url('/storage'), - ], - 3=>[ - 'name' => '{{PUBLIC_URL}}', - 'value' => url('/'), - ], - ]; + $data['replace_strings'] = vh_action('getPublicUrls', null, 'array'); $data['field_types'] = FieldType::select('id', 'name', 'slug', 'meta') ->get(); diff --git a/Vue/pages/blocks/Edit.vue b/Vue/pages/blocks/Edit.vue index 77bc5f1..ddf861c 100644 --- a/Vue/pages/blocks/Edit.vue +++ b/Vue/pages/blocks/Edit.vue @@ -22,14 +22,14 @@

Editor

Code Editor @@ -45,7 +45,7 @@ - + Date: Fri, 12 Mar 2021 18:08:52 +0530 Subject: [PATCH 11/16] Fixed: Update cms replace dynamic string --- Helpers/cms.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Helpers/cms.php b/Helpers/cms.php index e86862f..7e760b3 100644 --- a/Helpers/cms.php +++ b/Helpers/cms.php @@ -199,6 +199,9 @@ function setReturnValue($field,$return_html=true) return $field->content; } + if(!is_array($field->content) && !is_object($field->content)){ + $field->content = replace_dynamic_strings($field->content); + } switch($field['type']['slug']){ From e0c55bab2fe4ed586ea48e5dc84051e2a0e485aa Mon Sep 17 00:00:00 2001 From: vikram chand Date: Mon, 15 Mar 2021 11:09:17 +0530 Subject: [PATCH 12/16] Fixed: return dynamic string to block --- Entities/Block.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/Entities/Block.php b/Entities/Block.php index ff7b966..a451ae3 100644 --- a/Entities/Block.php +++ b/Entities/Block.php @@ -534,9 +534,7 @@ public static function getBlock($block_slug) return false; } - $output = str_replace("{{url('/')}}",url('/'),$block->content); - - return $output; + return replace_dynamic_strings($block->content); } //--------------------------------------------------------------------------- @@ -562,7 +560,7 @@ public static function getBlocksByLocation($location) $data = ""; foreach ($blocks as $block){ - $data .= $block->content; + $data .= replace_dynamic_strings($block->content); } From cafbe06a2381b299e9cd88a96f41042f2108469c Mon Sep 17 00:00:00 2001 From: vikram chand Date: Mon, 15 Mar 2021 13:30:40 +0530 Subject: [PATCH 13/16] Fixed: add dynamic string method to block --- Entities/Block.php | 5 +++++ Vue/pages/blocks/EditJs.js | 15 +++------------ Vue/pages/blocks/ViewJs.js | 17 +---------------- 3 files changed, 9 insertions(+), 28 deletions(-) diff --git a/Entities/Block.php b/Entities/Block.php index a451ae3..8b371ec 100644 --- a/Entities/Block.php +++ b/Entities/Block.php @@ -307,6 +307,8 @@ public static function getItem($id) ->withTrashed() ->first(); + $item['content'] = replace_dynamic_strings($item['content']); + $response['status'] = 'success'; $response['data'] = $item; @@ -323,6 +325,7 @@ public static function postStore($request,$id) return $validation; } + // check if name exist $name_exist = static::where('id','!=',$request['id']) ->where('name',$request['name']) @@ -363,6 +366,8 @@ public static function postStore($request,$id) return $response; } + $request['content'] = replace_dynamic_strings($request['content'],true); + $update = static::where('id',$id)->withTrashed()->first(); $update->fill($request->all()); diff --git a/Vue/pages/blocks/EditJs.js b/Vue/pages/blocks/EditJs.js index aa476e7..40a9338 100644 --- a/Vue/pages/blocks/EditJs.js +++ b/Vue/pages/blocks/EditJs.js @@ -181,15 +181,6 @@ export default { store: function () { this.$Progress.start(); - let self = this; - - console.log(122,this.item); - - $.each(this.assets.replace_strings, function( index, string ) { - let regex = new RegExp(string.value, "g"); - self.item.content = self.item.content.replace(regex, string.name); - }); - let params = this.item; let url = this.ajax_url+'/store/'+this.item.id; @@ -294,13 +285,13 @@ export default { }else{ $.each(self.assets.replace_strings.success, function( index, string ) { - let regex = new RegExp(string.value, "g"); - self.item.content = self.item.content.replace(regex, string.name); + let regex = new RegExp(string.name, "g"); + self.item.content = self.item.content.replace(regex, string.value); }); } - self.is_textarea_disable = true; + self.is_textarea_disable = value; }, diff --git a/Vue/pages/blocks/ViewJs.js b/Vue/pages/blocks/ViewJs.js index b8d8b6e..1be296b 100644 --- a/Vue/pages/blocks/ViewJs.js +++ b/Vue/pages/blocks/ViewJs.js @@ -91,22 +91,7 @@ export default { data.is_active = 'No'; } - - let self = this; - - - var bar = new Promise((resolve, reject) => { - $.each(self.page.assets.replace_strings, function( index, string ) { - let regex = new RegExp(string.name, "g"); - data.content = data.content.replace(regex, string.value); - if (index === self.page.assets.replace_strings.length -1) resolve(); - }); - - }); - - bar.then(() => { - this.update('active_item', data); - }); + this.update('active_item', data); } else From 06d211a282560598bb508149df4300609ca0d0dc Mon Sep 17 00:00:00 2001 From: vikram chand Date: Mon, 15 Mar 2021 16:15:17 +0530 Subject: [PATCH 14/16] Fixed: update vh_translation --- Entities/Block.php | 8 ++++---- Entities/Content.php | 4 ++-- Helpers/cms.php | 29 +---------------------------- 3 files changed, 7 insertions(+), 34 deletions(-) diff --git a/Entities/Block.php b/Entities/Block.php index 8b371ec..cf52034 100644 --- a/Entities/Block.php +++ b/Entities/Block.php @@ -307,7 +307,7 @@ public static function getItem($id) ->withTrashed() ->first(); - $item['content'] = replace_dynamic_strings($item['content']); + $item['content'] = vh_translate_dynamic_strings($item['content']); $response['status'] = 'success'; $response['data'] = $item; @@ -366,7 +366,7 @@ public static function postStore($request,$id) return $response; } - $request['content'] = replace_dynamic_strings($request['content'],true); + $request['content'] = vh_translate_dynamic_strings($request['content'],['has_replace_string' => true]); $update = static::where('id',$id)->withTrashed()->first(); @@ -539,7 +539,7 @@ public static function getBlock($block_slug) return false; } - return replace_dynamic_strings($block->content); + return vh_translate_dynamic_strings($block->content); } //--------------------------------------------------------------------------- @@ -565,7 +565,7 @@ public static function getBlocksByLocation($location) $data = ""; foreach ($blocks as $block){ - $data .= replace_dynamic_strings($block->content); + $data .= vh_translate_dynamic_strings($block->content); } diff --git a/Entities/Content.php b/Entities/Content.php index 4d7c62a..c8eb930 100644 --- a/Entities/Content.php +++ b/Entities/Content.php @@ -443,7 +443,7 @@ public static function getFormGroups(Content $content, $type, array $fields=null $groups[$i]['fields'][$y]['vh_cms_form_field_id'] = $field_content->id; if($field_content->content && !is_array($field_content->content) && !is_object($field_content->content)){ - $groups[$i]['fields'][$y]['content'] = replace_dynamic_strings($field_content->content); + $groups[$i]['fields'][$y]['content'] = vh_translate_dynamic_strings($field_content->content); }else{ $groups[$i]['fields'][$y]['content'] = $field_content->content; } @@ -542,7 +542,7 @@ public static function storeFormGroups(Content $content, $groups) { $field['content'] = json_encode($field['content']); }else{ - $field['content'] = replace_dynamic_strings($field['content'],true); + $field['content'] = vh_translate_dynamic_strings($field['content'],['has_replace_string' => true]); } if($field['type']['slug'] == 'user' && $field['content']){ diff --git a/Helpers/cms.php b/Helpers/cms.php index 7e760b3..9b0d708 100644 --- a/Helpers/cms.php +++ b/Helpers/cms.php @@ -55,33 +55,6 @@ function get_content_types(array $args = null) -} - -function replace_dynamic_strings($content = null,$has_replace_string = false) -{ - - $extend = new \WebReinvent\VaahCms\Http\Controllers\ExtendController(); - - $dynamic_string = $extend->getPublicUrls(); - - if($dynamic_string && $dynamic_string['status'] === 'success'){ - foreach ($dynamic_string['data'] as $string){ - - if($has_replace_string){ - $content = str_replace($string['value'],$string['name'],$content); - }else{ - $content = str_replace($string['name'],$string['value'],$content); - } - - - } - } - - return $content; - - - - } //----------------------------------------------------------------------------------- function get_content_type($id, array $args = null) @@ -200,7 +173,7 @@ function setReturnValue($field,$return_html=true) } if(!is_array($field->content) && !is_object($field->content)){ - $field->content = replace_dynamic_strings($field->content); + $field->content = vh_translate_dynamic_strings($field->content); } switch($field['type']['slug']){ From 0e726d0c6c5e588625072ebc5825094ec8bc3535 Mon Sep 17 00:00:00 2001 From: vikram chand Date: Tue, 16 Mar 2021 14:10:23 +0530 Subject: [PATCH 15/16] Fixed: replace dynamic string in array and object --- Entities/Content.php | 25 +++++++++++++++++-------- Helpers/cms.php | 8 ++++++-- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/Entities/Content.php b/Entities/Content.php index c8eb930..a0aebd0 100644 --- a/Entities/Content.php +++ b/Entities/Content.php @@ -167,7 +167,7 @@ public function authorUser() 'author', 'id' )->select( 'id', 'uuid', 'first_name', 'last_name', 'email', - 'username', 'display_name', 'title', 'bio', 'website', + 'username', 'display_name', 'title', 'bio', 'website' ); } //------------------------------------------------- @@ -442,10 +442,12 @@ public static function getFormGroups(Content $content, $type, array $fields=null { $groups[$i]['fields'][$y]['vh_cms_form_field_id'] = $field_content->id; - if($field_content->content && !is_array($field_content->content) && !is_object($field_content->content)){ - $groups[$i]['fields'][$y]['content'] = vh_translate_dynamic_strings($field_content->content); + if(is_array($field_content->content) || is_object($field_content->content)){ + $groups[$i]['fields'][$y]['content'] = json_decode( + vh_translate_dynamic_strings(json_encode($field_content->content)) + ); }else{ - $groups[$i]['fields'][$y]['content'] = $field_content->content; + $groups[$i]['fields'][$y]['content'] = vh_translate_dynamic_strings($field_content->content); } $groups[$i]['fields'][$y]['content_meta'] = $field_content->meta; @@ -538,11 +540,18 @@ public static function storeFormGroups(Content $content, $groups) $stored_field->vh_cms_form_field_id = $field['id']; } - if(is_array($field['content']) || is_object($field['content'])) - { - $field['content'] = json_encode($field['content']); + if(is_array($field['content']) || is_object($field['content'])){ + $field['content'] = json_decode( + vh_translate_dynamic_strings( + json_encode($field['content']), + ['has_replace_string' => true] + ) + ); }else{ - $field['content'] = vh_translate_dynamic_strings($field['content'],['has_replace_string' => true]); + $field['content'] = vh_translate_dynamic_strings( + $field['content'], + ['has_replace_string' => true] + ); } if($field['type']['slug'] == 'user' && $field['content']){ diff --git a/Helpers/cms.php b/Helpers/cms.php index 9b0d708..8d9dc38 100644 --- a/Helpers/cms.php +++ b/Helpers/cms.php @@ -172,8 +172,12 @@ function setReturnValue($field,$return_html=true) return $field->content; } - if(!is_array($field->content) && !is_object($field->content)){ - $field->content = vh_translate_dynamic_strings($field->content); + if(is_array($field->content) || is_object($field->content)){ + $field->content = json_decode( + vh_translate_dynamic_strings(json_encode($field['content'])) + ); + }else{ + $field->content = vh_translate_dynamic_strings($field['content']); } switch($field['type']['slug']){ From 6778684464cb1b6e89bdced33f96140514644eb5 Mon Sep 17 00:00:00 2001 From: vikram chand Date: Tue, 16 Mar 2021 15:55:15 +0530 Subject: [PATCH 16/16] Fixed: block console issue --- Entities/Block.php | 28 ++++++++++++++++++++++------ Vue/pages/blocks/Edit.vue | 3 --- Vue/pages/blocks/EditJs.js | 26 -------------------------- 3 files changed, 22 insertions(+), 35 deletions(-) diff --git a/Entities/Block.php b/Entities/Block.php index cf52034..48383f3 100644 --- a/Entities/Block.php +++ b/Entities/Block.php @@ -64,6 +64,28 @@ public function getNameAttribute($value) return null; } //------------------------------------------------- + public function setContentAttribute($value) + { + if($value) + { + $this->attributes['content'] = vh_translate_dynamic_strings($value,['has_replace_string' => true]); + } else{ + $this->attributes['content'] = null; + } + + } + //------------------------------------------------- + public function getContentAttribute($value) + { + if($value) + { + return vh_translate_dynamic_strings($value); + } + + return null; + + } + //------------------------------------------------- public function setMetaAttribute($value) { if($value) @@ -223,8 +245,6 @@ public static function getList($request) $data['list'] = $list->paginate(config('vaahcms.per_page')); - - $response['status'] = 'success'; $response['data'] = $data; @@ -307,8 +327,6 @@ public static function getItem($id) ->withTrashed() ->first(); - $item['content'] = vh_translate_dynamic_strings($item['content']); - $response['status'] = 'success'; $response['data'] = $item; @@ -366,8 +384,6 @@ public static function postStore($request,$id) return $response; } - $request['content'] = vh_translate_dynamic_strings($request['content'],['has_replace_string' => true]); - $update = static::where('id',$id)->withTrashed()->first(); $update->fill($request->all()); diff --git a/Vue/pages/blocks/Edit.vue b/Vue/pages/blocks/Edit.vue index ddf861c..490efa8 100644 --- a/Vue/pages/blocks/Edit.vue +++ b/Vue/pages/blocks/Edit.vue @@ -65,18 +65,15 @@

- -