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 @@
-
-