|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace DavideCasiraghi\LaravelColumns; |
|
4
|
|
|
|
|
5
|
|
|
use DavideCasiraghi\LaravelColumns\Models\Column; |
|
6
|
|
|
use DavideCasiraghi\LaravelColumns\Models\ColumnGroup; |
|
7
|
|
|
|
|
8
|
|
|
class LaravelColumns |
|
9
|
|
|
{ |
|
10
|
|
|
/**************************************************************************/ |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Provide the column data array. |
|
14
|
|
|
* |
|
15
|
|
|
* @param int $columnId |
|
16
|
|
|
* @return \DavideCasiraghi\LaravelColumns\Models\Column $ret |
|
17
|
|
|
**/ |
|
18
|
2 |
|
public static function getColumn($columnId) |
|
19
|
|
|
{ |
|
20
|
2 |
|
$ret = Column::where('id', $columnId)->first(); |
|
21
|
|
|
|
|
22
|
2 |
|
return $ret; |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
/**************************************************************************/ |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* Provide the columns of a specfied group. |
|
29
|
|
|
* |
|
30
|
|
|
* @param int $columnId |
|
31
|
|
|
* @return \DavideCasiraghi\LaravelColumns\Models\Column $ret |
|
32
|
|
|
**/ |
|
33
|
2 |
|
public static function getColumnsByGroup($columnGroupId) |
|
34
|
|
|
{ |
|
35
|
2 |
|
$ret = Column::where('columns_group', $columnGroupId)->get(); |
|
36
|
|
|
|
|
37
|
2 |
|
return $ret; |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/**************************************************************************/ |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* Provide the column group data array. |
|
44
|
|
|
* |
|
45
|
|
|
* @param int $columnGroupId |
|
46
|
|
|
* @return \DavideCasiraghi\LaravelColumns\Models\ColumnGroup $ret |
|
47
|
|
|
**/ |
|
48
|
2 |
|
public static function getColumnGroup($columnGroupId) |
|
49
|
|
|
{ |
|
50
|
2 |
|
$ret = ColumnGroup::where('id', $columnGroupId)->first(); |
|
51
|
|
|
|
|
52
|
2 |
|
return $ret; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/**************************************************************************/ |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* Find the column snippet occurances in the text. |
|
59
|
|
|
* |
|
60
|
|
|
* @param string $text |
|
61
|
|
|
* @return array $matches |
|
62
|
|
|
**/ |
|
63
|
4 |
|
public static function getColumnGroupSnippetOccurrences($text) |
|
64
|
|
|
{ |
|
65
|
4 |
|
$re = '/{\# |
|
66
|
|
|
\h+column_group |
|
67
|
|
|
\h+(column_group_id)=\[([^]]*)] |
|
68
|
|
|
\h*\#}/x'; |
|
69
|
|
|
|
|
70
|
4 |
|
if (preg_match_all($re, $text, $matches, PREG_SET_ORDER, 0)) { |
|
71
|
3 |
|
return $matches; |
|
72
|
|
|
} else { |
|
73
|
1 |
|
return; |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/**************************************************************************/ |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* Returns the plugin parameters. |
|
81
|
|
|
* |
|
82
|
|
|
* @param array $matches |
|
83
|
|
|
* @return array $ret |
|
84
|
|
|
**/ |
|
85
|
2 |
|
public static function getSnippetParameters($matches) |
|
86
|
|
|
{ |
|
87
|
2 |
|
$ret = []; |
|
88
|
|
|
|
|
89
|
|
|
// Get activation string parameters (from article) |
|
90
|
2 |
|
$ret['token'] = $matches[0]; |
|
91
|
|
|
//dump($matches); |
|
92
|
|
|
|
|
93
|
2 |
|
$ret['column_group_id'] = $matches[2]; |
|
94
|
|
|
|
|
95
|
2 |
|
return $ret; |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
/**************************************************************************/ |
|
99
|
|
|
|
|
100
|
|
|
/** |
|
101
|
|
|
* Return the same text with the columns HTML replaced |
|
102
|
|
|
* where the token strings has been found. |
|
103
|
|
|
* |
|
104
|
|
|
* @param string $text |
|
105
|
|
|
* @return string $ret |
|
106
|
|
|
**/ |
|
107
|
2 |
|
public function replace_column_group_snippets_with_template($text) |
|
108
|
|
|
{ |
|
109
|
2 |
|
$matches = self::getColumnGroupSnippetOccurrences($text); |
|
110
|
|
|
// aaaaaa |
|
111
|
|
|
|
|
112
|
2 |
|
if (! empty($matches)) { |
|
113
|
2 |
|
foreach ($matches as $key => $single_gallery_matches) { |
|
114
|
2 |
|
$snippetParameters = self::getSnippetParameters($single_gallery_matches); |
|
115
|
|
|
|
|
116
|
2 |
|
$columnGroupId = $snippetParameters['column_group_id']; |
|
117
|
|
|
|
|
118
|
2 |
|
$columnGroup = self::getColumnGroup($columnGroupId); |
|
119
|
2 |
|
$columnGroupParameters = ($columnGroup) ? (self::getParametersArray($columnGroup)) : null; |
|
120
|
2 |
|
$columns = self::getColumnsByGroup($columnGroupId); |
|
121
|
|
|
|
|
122
|
2 |
|
$columnView = self::showColumnGroup($columnGroup, $columnGroupParameters, $columns); |
|
|
|
|
|
|
123
|
2 |
|
$columnHtml = $columnView->render(); |
|
124
|
|
|
|
|
125
|
|
|
// Substitute the column html to the token that has been found |
|
126
|
2 |
|
$text = str_replace($snippetParameters['token'], $columnHtml, $text); |
|
127
|
|
|
} |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
2 |
|
$ret = $text; |
|
131
|
|
|
|
|
132
|
2 |
|
return $ret; |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
/***************************************************************************/ |
|
136
|
|
|
|
|
137
|
|
|
/** |
|
138
|
|
|
* Show a Column group. |
|
139
|
|
|
* |
|
140
|
|
|
* @param \DavideCasiraghi\LaravelColumns\Models\ColumnGroup $columnGroup |
|
141
|
|
|
* @param array $columnGroupParameters |
|
142
|
|
|
* @param \DavideCasiraghi\LaravelColumns\Models\Column $columns |
|
143
|
|
|
* @return \Illuminate\Http\Response |
|
144
|
|
|
*/ |
|
145
|
2 |
|
public function showColumnGroup($columnGroup, $columnGroupParameters, $columns) |
|
146
|
|
|
{ |
|
147
|
2 |
|
return view('laravel-columns::show-column-group', compact('columnGroup')) |
|
148
|
2 |
|
->with('columnGroupParameters', $columnGroupParameters) |
|
149
|
2 |
|
->with('columns', $columns); |
|
150
|
|
|
} |
|
151
|
|
|
|
|
152
|
|
|
/***************************************************************************/ |
|
153
|
|
|
|
|
154
|
|
|
/** |
|
155
|
|
|
* Return an array with the parameters for the column. |
|
156
|
|
|
* @param \DavideCasiraghi\LaravelColumns\Models\ColumnGroup $columnGroup |
|
157
|
|
|
* @return array |
|
158
|
|
|
*/ |
|
159
|
3 |
|
public static function getParametersArray($columnGroup) |
|
160
|
|
|
{ |
|
161
|
3 |
|
$container_style = ''; |
|
162
|
|
|
|
|
163
|
3 |
|
$group_title_style = 'text-align:'.$columnGroup->text_alignment.'; '; |
|
|
|
|
|
|
164
|
3 |
|
$group_title_style = 'color:'.$columnGroup->group_title_color.'; '; |
|
165
|
3 |
|
$group_title_style .= 'font-size:'.$columnGroup->group_title_font_size.'; '; |
|
166
|
|
|
|
|
167
|
3 |
|
$group_description_style = 'text-align:'.$columnGroup->text_alignment.'; '; |
|
168
|
3 |
|
$group_button_style = 'text-align:'.$columnGroup->text_alignment.'; '; |
|
169
|
|
|
|
|
170
|
|
|
/* Wrapper style */ |
|
171
|
3 |
|
$wrapper_style = 'justify-content:'.$columnGroup->justify_content.'; '; |
|
172
|
3 |
|
$wrapper_style .= 'flex-flow:'.$columnGroup->flex_flow.'; '; |
|
173
|
3 |
|
$wrapper_style .= 'flex-wrap:'.$columnGroup->flex_wrap.'; '; |
|
174
|
3 |
|
$wrapper_style .= 'text-align:'.$columnGroup->text_alignment.'; '; |
|
175
|
|
|
|
|
176
|
3 |
|
switch ($columnGroup->background_type) { |
|
177
|
|
|
case 1: |
|
178
|
|
|
$container_style .= 'background-color: '.$columnGroup->bkg_color.';'; |
|
179
|
|
|
break; |
|
180
|
|
|
case 2: |
|
181
|
|
|
// gradient |
|
182
|
3 |
|
break; |
|
183
|
3 |
|
case 3: |
|
184
|
|
|
$wrapper_style .= 'background-image:url(/storage/images/column_groups/'.$columnGroup->background_image.');'; |
|
185
|
|
|
$wrapper_style .= 'background-position:'.$columnGroup->background_image_position.'; '; |
|
186
|
3 |
|
break; |
|
187
|
|
|
default: |
|
188
|
|
|
// code... |
|
189
|
3 |
|
break; |
|
190
|
3 |
|
} |
|
191
|
3 |
|
|
|
192
|
|
|
$bg_overlay_style = 'opacity: '.$columnGroup->opacity; |
|
193
|
|
|
|
|
194
|
|
|
/* Title style */ |
|
195
|
|
|
$title_style = 'color:'.$columnGroup->column_title_color.'; '; |
|
196
|
3 |
|
$title_style .= 'font-size:'.$columnGroup->column_title_font_size.'; '; |
|
197
|
3 |
|
|
|
198
|
3 |
|
/* Description style */ |
|
199
|
|
|
$description_style = 'font-size:'.$columnGroup->description_font_size.'; '; |
|
200
|
|
|
|
|
201
|
|
|
/* Button class*/ |
|
202
|
3 |
|
$button_class = $columnGroup->button_color.' '; |
|
203
|
3 |
|
$button_class .= $columnGroup->button_corners.' '; |
|
204
|
|
|
if ($columnGroup->link_style == 3) { |
|
205
|
|
|
$button_class .= 'press-ghost '; |
|
206
|
|
|
} |
|
207
|
|
|
|
|
208
|
3 |
|
// Image style and class |
|
209
|
3 |
|
$image_style = ''; |
|
210
|
3 |
|
$image_style .= 'width:'.$columnGroup->columns_images_width.'; '; |
|
211
|
3 |
|
if ($columnGroup->columns_round_images) { |
|
212
|
3 |
|
$image_style .= 'border-radius: 50%;'; |
|
213
|
3 |
|
} |
|
214
|
3 |
|
|
|
215
|
3 |
|
$image_class = ''; |
|
216
|
3 |
|
if ($columnGroup->columns_images_hide_mobile) { |
|
217
|
3 |
|
$image_class .= 'hide-image-mobile'; |
|
218
|
3 |
|
} |
|
219
|
|
|
|
|
220
|
|
|
$ret = [ |
|
221
|
|
|
'container_style' => $container_style, |
|
222
|
|
|
'group_title_style' => $group_title_style, |
|
223
|
|
|
'group_description_style' => $group_description_style, |
|
224
|
|
|
'group_button_style' => $group_button_style, |
|
225
|
|
|
'wrapper_style' => $wrapper_style, |
|
226
|
|
|
'title_style' => $title_style, |
|
227
|
|
|
'description_style' => $description_style, |
|
228
|
|
|
'image_style' => $image_style, |
|
229
|
|
|
'image_class' => $image_class, |
|
230
|
|
|
'button_class' => $button_class, |
|
231
|
|
|
'bg_overlay_style' => $bg_overlay_style, |
|
232
|
|
|
]; |
|
233
|
|
|
|
|
234
|
|
|
/*$ret = [ |
|
235
|
|
|
'img_col_size_class' => 'col-md-'.$column->img_col_size, |
|
236
|
|
|
'text_col_size_class' => 'col-md-'.(12 - $column->img_col_size), |
|
237
|
|
|
'bkg_color' => 'background-color: '.$column->bkg_color.';', |
|
238
|
|
|
'text_color' => 'color: '.$column->text_color.';', |
|
239
|
|
|
'container_wrap' => ($column->container_wrap == 'true') ? 1 : 0, |
|
240
|
3 |
|
];*/ |
|
241
|
|
|
|
|
242
|
|
|
/*switch ($column->img_alignment) { |
|
243
|
|
|
case 'left': |
|
244
|
|
|
$ret['img_col_order_class'] = 'order-md-1'; |
|
245
|
|
|
$ret['text_col_order_class'] = 'order-md-2'; |
|
246
|
|
|
break; |
|
247
|
|
|
case 'right': |
|
248
|
|
|
$ret['img_col_order_class'] = 'order-md-2'; |
|
249
|
|
|
$ret['text_col_order_class'] = 'order-md-1'; |
|
250
|
|
|
break; |
|
251
|
|
|
}*/ |
|
252
|
|
|
|
|
253
|
|
|
return $ret; |
|
254
|
|
|
} |
|
255
|
|
|
} |
|
256
|
|
|
|