diff --git a/Entities/Block.php b/Entities/Block.php index 9a53110..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; @@ -323,6 +343,7 @@ public static function postStore($request,$id) return $validation; } + // check if name exist $name_exist = static::where('id','!=',$request['id']) ->where('name',$request['name']) @@ -534,7 +555,7 @@ public static function getBlock($block_slug) return false; } - return $block->content; + return vh_translate_dynamic_strings($block->content); } //--------------------------------------------------------------------------- @@ -560,7 +581,7 @@ public static function getBlocksByLocation($location) $data = ""; foreach ($blocks as $block){ - $data .= $block->content; + $data .= vh_translate_dynamic_strings($block->content); } diff --git a/Entities/Content.php b/Entities/Content.php index 2117b66..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' ); } //------------------------------------------------- @@ -438,11 +438,18 @@ 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(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'] = vh_translate_dynamic_strings($field_content->content); + } + $groups[$i]['fields'][$y]['content_meta'] = $field_content->meta; } @@ -533,9 +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] + ); } if($field['type']['slug'] == 'user' && $field['content']){ diff --git a/Helpers/cms.php b/Helpers/cms.php index a7e41cc..8d9dc38 100644 --- a/Helpers/cms.php +++ b/Helpers/cms.php @@ -18,6 +18,37 @@ //----------------------------------------------------------------------------------- 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) { @@ -141,6 +172,13 @@ function setReturnValue($field,$return_html=true) return $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']){ diff --git a/Http/Controllers/Backend/BlocksController.php b/Http/Controllers/Backend/BlocksController.php index 111e8ce..b98643d 100644 --- a/Http/Controllers/Backend/BlocksController.php +++ b/Http/Controllers/Backend/BlocksController.php @@ -23,6 +23,8 @@ public function __construct() public function getAssets(Request $request) { + $data['replace_strings'] = vh_action('getPublicUrls', null, 'array'); + $data['field_types'] = FieldType::select('id', 'name', 'slug', 'meta') ->get(); 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/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(); diff --git a/Vue/pages/blocks/Edit.vue b/Vue/pages/blocks/Edit.vue index 696deea..490efa8 100644 --- a/Vue/pages/blocks/Edit.vue +++ b/Vue/pages/blocks/Edit.vue @@ -22,18 +22,42 @@

Editor

Code Editor

+

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

@@ -46,6 +70,7 @@ :options="cm_options" /> +