-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcase_study_module.php
426 lines (313 loc) · 14.1 KB
/
case_study_module.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
<?php
/*
* @Author Jeremy HUTCH Hutchcraft - jhutchcraft.com
* @Version 1.3
*/
class Work_Module{
public $post_id;
public $modules;
public $post_title;
function __construct($post_id) {
$this->post_id = $post_id;
$this->post_title = get_the_title($post_id);
}
/**
* if $post_id property is defined, return it, else throw error
* @return array
*/
public function get_post_id(){
if(isset($this->post_id)){
return $this->post_id;
} else {
return 'WTF MATE';
}
}
/**
* Get Module (custom fields attached to post_id)
* @return array
*/
public function get_modules(){
$this->modules = get_field('modules', $this->post_id);
return $this->modules;
}
/**
* Render global css data containers
* @return array
*/
public function render_css_data($pid = null){
$pid = $pid ?: $this->post_id;
$css_data = array(
'hex_logo' => get_field('hex_logo', $pid),
'hex_socials' => get_field('hex_socials', $pid),
'hex_nav_items' => get_field('hex_nav_items', $pid),
'hex_nav_items_hover' => get_field('hex_nav_items_hover', $pid),
);
// pre_print_r($css_data);
?>
<div class="css-data-container">
<?php if(isset($css_data['hex_logo']) && $css_data['hex_logo'] != ''){ ?><i class="hex-box" id="logo-color" data-hex="<?php echo $css_data['hex_logo']; ?>"></i><?php } ?>
<?php if(isset($css_data['hex_socials']) && $css_data['hex_socials'] != ''){ ?><i class="hex-box" id="socials-color" data-hex="<?php echo $css_data['hex_socials']; ?>"></i><?php } ?>
<?php if(isset($css_data['hex_nav_items']) && $css_data['hex_nav_items'] != ''){ ?><i class="hex-box" id="nav-items-color" data-hex="<?php echo $css_data['hex_nav_items']; ?>"></i><?php } ?>
<?php if(isset($css_data['hex_nav_items_hover']) && $css_data['hex_nav_items_hover'] != ''){ ?><i class="hex-box" id="nav-items-hover-color" data-hex="<?php echo $css_data['hex_nav_items_hover']; ?>"></i><?php } ?>
</div>
<?php
}
/**
* Render home tiles - print global css data containers, project logos, and solid background tiles
* @return array
*/
public function render_home_tiles(){
$args = array(
'post_type' => 'otml_work',
'posts_per_page' => -1
);
$projects = get_posts($args);
foreach($projects as $key => $post){ setup_postdata($post);
$pid = $post->ID;
$pid = $pid ?: $this->post_id;
$logo_color = get_field('hex_logo', $pid);
/* Obtain Thumbnail Information */
$thumb_id = get_post_thumbnail_id($pid);
if($thumb_id){
$thumb_url_array = wp_get_attachment_image_src($thumb_id, 'work-logo', true);
$thumb_url = $thumb_url_array[0];
$pattern = '/default.png/';
$is_default_img = preg_match($pattern, $thumb_url);
}
?>
<a href="<?php echo get_permalink($pid); ?>" class="a-home-tile dtc" data-bgc="<?php echo $this->get_hex_bgc($pid); ?>">
<?php if (isset($thumb_url) && !$is_default_img): ?>
<div class="outer">
<div class="inner">
<img class="work-logo" src="<?php echo $thumb_url ?>" alt="Logo for <?php echo $this->post_title; ?> - a project by John Oates">
</div>
</div>
<?php endif; ?>
<span class="view-work" data-hex="<?php echo $logo_color; ?>">View Work</span>
</a>
<?php }
}
/**
* Render project - print project header, global css data containers, project modules
* @return array
*/
public function render_project(){
$this->render_css_data();
$this->render_project_header();
$this->render_modules();
$this->render_footer();
}
/**
* Render home tiles - print global css data containers, project logos, and solid background tiles
* @return array
*/
public function render_project_header(){
?>
<div class="work-header dtc" data-bgc=<?php echo $this->get_hex_bgc(); ?>>
<div class="outer">
<div class="inner">
<div class="header-content">
<img src="<?php echo $this->get_featured_img(); ?>" alt="alt="Logo for <?php $this->post_title; ?> - a project by John Oates"" class="work-logo">
<div class="the-content">
<?php the_content(); ?>
</div>
</div>
</div>
</div>
</div>
<?php
}
/**
* Get Module (custom fields attached to post_id)
* @return array
*/
public function render_modules(){
$mods = $this->get_modules();
if ($mods) {
foreach($mods as $key => $module){
switch($module['module_type']):
case 'two_col':
$this->module_two_col($module);
break;
case 'small_image':
$this->module_small_image($module);
break;
case 'image':
$this->module_full_w_image($module, null, 'img');
break;
case 'background_image':
$this->module_full_w_image($module, null, 'bg-img');
break;
endswitch;
}
} else {
// echo "<h2>We're Sorry, there has been no content added to this project yet. Please check back soon!</h2>";
}
}
/**
* Print Project footer
* @return array
*/
public function render_footer(){
$next_post = get_next_post();
$prev_post = get_previous_post();
// $debugger = array(print_r($prev_post, 1), print_r($next_post, 1));
// pre_print_r($debugger);
$work_footer_content = get_field('work_footer_content', $this->post_id);
if (is_a($next_post, 'WP_Post')) {
$next_post_bg = get_field('next_btn_hover_bg', $next_post->ID);
}
if (is_a($prev_post, 'WP_Post')) {
$prev_post_bg = get_field('next_btn_hover_bg', $prev_post->ID);
}
$has_both = (is_a($prev_post, 'WP_Post') && is_a($next_post, 'WP_Post'));
?>
<div class="work-footer dtc" data-bgc="<?php echo $this->get_hex_bgc(); ?>">
<?php if(isset($prev_post_bg) && $prev_post_bg != ''){ ?><div class="hover-wallpaper next" style="background-image: url('<?php echo $prev_post_bg['url']; ?>');"></div><?php } ?>
<?php if(isset($next_post_bg) && $next_post_bg != ''){ ?><div class="hover-wallpaper prev" style="background-image: url('<?php echo $next_post_bg['url']; ?>');"></div><?php } ?>
<div class="center">
<div class="outer">
<div class="inner">
<div class="work-footer-content">
<h3 class="work-footer-heading"><?php echo $this->post_title; ?></h3>
<?php if (isset($work_footer_content) && $work_footer_content != ''): ?>
<?php echo $work_footer_content; ?>
<?php endif ?>
</div>
<div class="work-footer-nav<?php if($has_both){ echo ' has-both-links'; } ?>">
<?php if (is_a($next_post, 'WP_Post')): ?>
<a href="<?php echo get_permalink($next_post->ID) ?>" class="nav-btn prev" data-dir="prev">PREVIOUS</a>
<?php else: ?>
<?php // <span href="#" class="nav-btn prev disabled" data-dir="prev">PREVIOUS</span> ?>
<?php endif ?>
<?php if (is_a($prev_post, 'WP_Post')): ?>
<a href="<?php echo get_permalink($prev_post->ID) ?>" class="nav-btn next" data-dir="next">NEXT</a>
<?php else: ?>
<?php // <span href="#" class="nav-btn next disabled" data-dir="next">NEXT</span> ?>
<?php endif ?>
</div>
</div>
</div>
</div>
</div>
<?php
}
/**
* MODULE - Two Column
* @return array
*/
public function module_two_col($module, $debug = false){
if($debug){
pre_print_r($module);
}
$cols = $module['columns'][0];
$image = $cols['image']['url'];
$content = $cols['content'];
$hex_text_col_bgc = $cols['text_col_bgc'];
if(isset($cols['images']) && count($cols['images']) == 2){
$image1 = $cols['images'][0]['url'];
$image2 = $cols['images'][1]['url'];
}
?> <div class="a-module two-col <?php if(isset($module['cols_layout']) && $module['cols_layout'] != ''){ echo $module['cols_layout']; } ?>"> <?php
switch($module['cols_layout']):
case 'img_left': ?>
<div class="left-col img-col" style="background-image: url('<?php if(isset($image) && $image != ''){ echo $image; } ?>');"></div>
<div class="right-col txt-col dtc" data-bgc="<?php if(isset($hex_text_col_bgc) && $hex_text_col_bgc != ''){ echo $hex_text_col_bgc; } ?>">
<div class="outer">
<div class="inner">
<div class="the-content">
<?php if(isset($content) && $content != ''){ echo $content; } ?>
</div>
</div>
</div>
</div>
<?php break;
case 'img_right': ?>
<div class="left-col txt-col dtc" data-bgc="<?php echo $hex_text_col_bgc; ?>">
<div class="outer">
<div class="inner">
<div class="the-content">
<?php echo $content; ?>
</div>
</div>
</div>
</div>
<div class="right-col img-col dtc" style="background-image: url('<?php if(isset($image) && $image != ''){ echo $image; } ?>');"></div>
<?php break;
case 'double_img': ?>
<div class="left-col img-col" style="background-image: url('<?php if(isset($image2) && $image2 != ''){ echo $image2; } ?>');"></div>
<div class="right-col img-col" style="background-image: url('<?php if(isset($image1) && $image1 != ''){ echo $image1; } ?>');"></div>
<?php break;
endswitch;
?> <div class="clear"></div>
</div> <?php
}
/**
* MODULE - Small, Centered, Image with Background Image
* @return array
*/
public function module_small_image($module, $debug = false){
if($debug){
pre_print_r($module);
}
$bg_type = $module['background_type'];
switch($bg_type):
case 'solid':
$hex_bgc = $module['hex_small_img_bgc'];
break;
case 'bg_image':
$bg_img = $module['small_img_bg']['url'];
break;
endswitch;
$image = $module['image']['url'];
?>
<div class="a-module small-img" data-bgc="<?php if(isset($hex_bgc) && $hex_bgc != ''){ echo $hex_bgc; } ?>">
<div class="inner-wrap">
<img class="the-img" src="<?php echo $image; ?>" alt="Case study image for <?php echo $this->post_title; ?>, a project by John Oates">
</div>
</div>
<?php
}
/**
* MODULE - Full Width Image
* @return array
*/
public function module_full_w_image($module, $debug = false, $style = 'img'){
if($debug){
pre_print_r($module);
}
$image = $module['image']['url'];
$height = $module['height'];
switch($style):
case 'img': ?>
<div class="a-module full-w-image img">
<img class="work-img" src="<?php echo $image; ?>" alt="Case study image for <?php echo $this->post_title; ?>, a project by John Oates">
</div>
<?php break;
case 'bg-img': ?>
<div class="a-module full-w-image bg-img<?php if(isset($height) && $height != ''){ echo ' '.$height; } ?>" style="background-image: url('<?php echo $image; ?>');"></div>
<?php break;
endswitch;
}
/**
* Get Hex Value - Project Background Color
* @return array
*/
public function get_hex_bgc($pid = null){
$pid = isset($pid) ? $pid : $this->post_id;
$hex_bgc = get_field('hex_bgc', $pid);
return $hex_bgc ?: '000000';
}
public function get_featured_img($pid = null){
$pid = isset($pid) ? $pid : $this->post_id;
/* Obtain Thumbnail Information */
$thumb_id = get_post_thumbnail_id($pid);
if($thumb_id){
$thumb_url_array = wp_get_attachment_image_src($thumb_id, 'work-logo', true);
$thumb_url = $thumb_url_array[0];
$pattern = '/default.png/';
$is_default_img = preg_match($pattern, $thumb_url);
}
return (isset($thumb_url) && !$is_default_img) ? $thumb_url : false;
}
}