Skip to content

Commit a45657c

Browse files
authored
Merge pull request #6 from webreinvent/feature/add-insight-seeder
feature -> develop | Update dynamic string method
2 parents dbaa8df + 6778684 commit a45657c

File tree

10 files changed

+156
-40
lines changed

10 files changed

+156
-40
lines changed

Entities/Block.php

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,28 @@ public function getNameAttribute($value)
6464
return null;
6565
}
6666
//-------------------------------------------------
67+
public function setContentAttribute($value)
68+
{
69+
if($value)
70+
{
71+
$this->attributes['content'] = vh_translate_dynamic_strings($value,['has_replace_string' => true]);
72+
} else{
73+
$this->attributes['content'] = null;
74+
}
75+
76+
}
77+
//-------------------------------------------------
78+
public function getContentAttribute($value)
79+
{
80+
if($value)
81+
{
82+
return vh_translate_dynamic_strings($value);
83+
}
84+
85+
return null;
86+
87+
}
88+
//-------------------------------------------------
6789
public function setMetaAttribute($value)
6890
{
6991
if($value)
@@ -223,8 +245,6 @@ public static function getList($request)
223245

224246
$data['list'] = $list->paginate(config('vaahcms.per_page'));
225247

226-
227-
228248
$response['status'] = 'success';
229249
$response['data'] = $data;
230250

@@ -323,6 +343,7 @@ public static function postStore($request,$id)
323343
return $validation;
324344
}
325345

346+
326347
// check if name exist
327348
$name_exist = static::where('id','!=',$request['id'])
328349
->where('name',$request['name'])
@@ -534,7 +555,7 @@ public static function getBlock($block_slug)
534555
return false;
535556
}
536557

537-
return $block->content;
558+
return vh_translate_dynamic_strings($block->content);
538559
}
539560

540561
//---------------------------------------------------------------------------
@@ -560,7 +581,7 @@ public static function getBlocksByLocation($location)
560581
$data = "";
561582

562583
foreach ($blocks as $block){
563-
$data .= $block->content;
584+
$data .= vh_translate_dynamic_strings($block->content);
564585
}
565586

566587

Entities/Content.php

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ public function authorUser()
167167
'author', 'id'
168168
)->select(
169169
'id', 'uuid', 'first_name', 'last_name', 'email',
170-
'username', 'display_name', 'title', 'bio', 'website',
170+
'username', 'display_name', 'title', 'bio', 'website'
171171
);
172172
}
173173
//-------------------------------------------------
@@ -438,11 +438,18 @@ public static function getFormGroups(Content $content, $type, array $fields=null
438438
$field_content->where('vh_cms_form_field_id', $field->id);
439439
$field_content = $field_content->first();
440440

441-
442441
if($field_content)
443442
{
444443
$groups[$i]['fields'][$y]['vh_cms_form_field_id'] = $field_content->id;
445-
$groups[$i]['fields'][$y]['content'] = $field_content->content;
444+
445+
if(is_array($field_content->content) || is_object($field_content->content)){
446+
$groups[$i]['fields'][$y]['content'] = json_decode(
447+
vh_translate_dynamic_strings(json_encode($field_content->content))
448+
);
449+
}else{
450+
$groups[$i]['fields'][$y]['content'] = vh_translate_dynamic_strings($field_content->content);
451+
}
452+
446453
$groups[$i]['fields'][$y]['content_meta'] = $field_content->meta;
447454
}
448455

@@ -533,9 +540,18 @@ public static function storeFormGroups(Content $content, $groups)
533540
$stored_field->vh_cms_form_field_id = $field['id'];
534541
}
535542

536-
if(is_array($field['content']) || is_object($field['content']))
537-
{
538-
$field['content'] = json_encode($field['content']);
543+
if(is_array($field['content']) || is_object($field['content'])){
544+
$field['content'] = json_decode(
545+
vh_translate_dynamic_strings(
546+
json_encode($field['content']),
547+
['has_replace_string' => true]
548+
)
549+
);
550+
}else{
551+
$field['content'] = vh_translate_dynamic_strings(
552+
$field['content'],
553+
['has_replace_string' => true]
554+
);
539555
}
540556

541557
if($field['type']['slug'] == 'user' && $field['content']){

Helpers/cms.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,37 @@
1818
//-----------------------------------------------------------------------------------
1919
use VaahCms\Modules\Cms\Entities\Content;
2020

21+
22+
//-----------------------------------------------------------------------------------
23+
function cms_dynamic_variables()
24+
{
25+
$list = [
26+
[
27+
'name' => '#!PUBLIC:MODULE_URL!#',
28+
'value' => url('/vaahcms/modules'),
29+
'detail'=>'Will be replaced with public module url.'
30+
],
31+
[
32+
'name' => '#!PUBLIC:THEME_URL!#',
33+
'value' => url('/vaahcms/themes'),
34+
'detail'=>'Will be replaced with public theme url.'
35+
],
36+
[
37+
'name' => '#!PUBLIC:STORAGE_URL!#',
38+
'value' => url('/storage'),
39+
'detail'=>'Will be replaced with public storage url.'
40+
],
41+
[
42+
'name' => '#!PUBLIC:BASE_URL!#',
43+
'value' => url('/'),
44+
'detail'=>'Will be replaced with public url.',
45+
]
46+
];
47+
48+
return $list;
49+
50+
}
51+
2152
function get_content_types(array $args = null)
2253
{
2354

@@ -141,6 +172,13 @@ function setReturnValue($field,$return_html=true)
141172
return $field->content;
142173
}
143174

175+
if(is_array($field->content) || is_object($field->content)){
176+
$field->content = json_decode(
177+
vh_translate_dynamic_strings(json_encode($field['content']))
178+
);
179+
}else{
180+
$field->content = vh_translate_dynamic_strings($field['content']);
181+
}
144182

145183
switch($field['type']['slug']){
146184

Http/Controllers/Backend/BlocksController.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ public function __construct()
2323
public function getAssets(Request $request)
2424
{
2525

26+
$data['replace_strings'] = vh_action('getPublicUrls', null, 'array');
27+
2628
$data['field_types'] = FieldType::select('id', 'name', 'slug', 'meta')
2729
->get();
2830

Libraries/CmsSeeder.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,8 @@ public static function createSampleField($theme_slug, $file_path, $content_type_
292292
}
293293

294294
}
295+
//-------------------------------------------------------
296+
295297
//-------------------------------------------------------
296298
public static function fillFields($groups)
297299
{

Providers/CmsServiceProvider.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public function boot(Router $router)
3333
$this->registerConfig();
3434
$this->registerViews();
3535
$this->registerAssets();
36+
3637
//$this->registerFactories();
3738
$this->loadMigrationsFrom(__DIR__ . '/../Database/Migrations');
3839
$this->registerSeeders();

Vue/pages/blocks/Edit.vue

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,42 @@
2222

2323
<p class="control">
2424
<b-button type="is-light"
25-
@click="is_textarea_disable = false"
25+
@click="setDynamicContent(false)"
2626
:disabled="!is_textarea_disable">
2727
Editor
2828
</b-button>
2929
</p>
3030
<p class="control">
3131
<b-button type="is-light"
32-
@click="is_textarea_disable = true"
32+
@click="setDynamicContent(true)"
3333
:disabled="is_textarea_disable">
3434
Code Editor
3535
</b-button>
3636
</p>
37+
<p class="control">
38+
<b-dropdown position="is-bottom-left" :triggers="['hover']" aria-role="list">
39+
<template #trigger>
40+
<button class="button is-light"
41+
slot="trigger">
42+
<b-icon icon="caret-down"></b-icon>
43+
</button>
44+
</template>
45+
46+
47+
48+
<span v-for="string in assets.replace_strings.success">
49+
<b-dropdown-item >
50+
<vh-copy class="text-copyable"
51+
@copied="copyCode(string.name)"
52+
>
53+
<b-icon icon="copy"></b-icon> {{string.name.replace(/[^a-zA-Z ]/g, " ")}}
54+
</vh-copy>
55+
</b-dropdown-item>
56+
</span>
57+
58+
59+
</b-dropdown>
60+
</p>
3761
</div>
3862
</div>
3963

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

73+
4974
<ContentFieldAll v-else
5075
field_slug="editor"
5176
:labelPosition="labelPosition"

Vue/pages/blocks/EditJs.js

Lines changed: 34 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import ContentFieldAll from '../../vaahvue/reusable/content-fields/All'
33
import draggable from 'vuedraggable';
44
import { codemirror } from 'vue-codemirror'
55

6+
67
// language
78
import 'codemirror/mode/xml/xml.js'
89
// theme css
@@ -12,6 +13,7 @@ import 'codemirror/theme/monokai.css'
1213
import'codemirror/addon/selection/active-line.js'
1314
// autoCloseTags
1415
import'codemirror/addon/edit/closetag.js'
16+
import copy from "copy-to-clipboard";
1517

1618
let namespace = 'blocks';
1719

@@ -76,32 +78,6 @@ export default {
7678
}
7779
},
7880

79-
'item.plural': {
80-
deep: true,
81-
handler(new_val, old_val) {
82-
83-
if(new_val)
84-
{
85-
this.item.plural_slug = this.$vaah.strToSlug(new_val);
86-
this.updateNewItem();
87-
}
88-
89-
}
90-
},
91-
92-
'item.singular': {
93-
deep: true,
94-
handler(new_val, old_val) {
95-
96-
if(new_val)
97-
{
98-
this.item.singular_slug = this.$vaah.strToSlug(new_val);
99-
this.updateNewItem();
100-
}
101-
102-
}
103-
},
104-
10581
},
10682
mounted() {
10783
//----------------------------------------------------
@@ -271,5 +247,37 @@ export default {
271247
this.update('active_item', null);
272248
this.$router.push({name:'blocks.list'});
273249
},
250+
//---------------------------------------------------------------------
251+
setDynamicContent: function (value) {
252+
let self = this;
253+
254+
if(value){
255+
$.each(self.assets.replace_strings.success, function( index, string ) {
256+
let regex = new RegExp(string.value, "g");
257+
self.item.content = self.item.content.replace(regex, string.name);
258+
});
259+
260+
}else{
261+
$.each(self.assets.replace_strings.success, function( index, string ) {
262+
let regex = new RegExp(string.name, "g");
263+
self.item.content = self.item.content.replace(regex, string.value);
264+
});
265+
266+
}
267+
268+
self.is_textarea_disable = value;
269+
270+
271+
},
272+
//---------------------------------------------------------------------
273+
copyCode: function (item,has_location = false)
274+
{
275+
copy(item);
276+
277+
this.$buefy.toast.open({
278+
message: 'Copied!',
279+
type: 'is-success'
280+
});
281+
},
274282
}
275283
}

Vue/pages/blocks/ViewJs.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,17 @@ export default {
8383
this.$Progress.finish();
8484
this.is_content_loading = false;
8585

86-
if(data && data)
86+
if(data && data && this.page && this.page.assets )
8787
{
8888
if(data.is_active == 1){
8989
data.is_active = 'Yes';
9090
}else{
9191
data.is_active = 'No';
9292
}
93+
9394
this.update('active_item', data);
95+
96+
9497
} else
9598
{
9699
//if item does not exist or delete then redirect to list

0 commit comments

Comments
 (0)