/
collections.php
105 lines (90 loc) · 3.12 KB
/
collections.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
<?php
/*
Materializer - Material Design components for WordPress
Copyright (c) Cody Reichert - 2015
*/
/* Code starts here */
class Collections extends MaterializerShortcodes {
/**
* Collection [collection]
* Available Attributes:
* @color: background color
* @textColor: text color
*/
public function collection($atts, $content) {
$color = !empty($atts['color']) ? $atts['color'] : '';
$text = !empty($atts['text']) ? $atts['text'] : '';
$type = !empty($atts['type']) ? $atts['type'] : '';
$class = $color . " " . $text . "-text";
$items = parent::get_stripped_shortcodes($content, 'collection_item');
$stripped_content = parent::strip_shortcode($content, 'collection_item');
$collection_items = $items[0];
if($type === "") {
ob_start();
?>
<span class="materializer">
<ul class="collection <?php echo $class; ?>">
<?php
if(!empty($collection_items)) {
foreach($collection_items as $item) {
echo do_shortcode($item);
}
}
?>
</ul>
</span>
<?php
return ob_get_clean();
}
if($type === "links") {
$links = preg_replace("/collection_item/", "collection_link", $collection_items);
ob_start();
?>
<span class="materializer">
<div class="collection <?php echo $class; ?>">
<?php
if(!empty($links)) {
foreach($links as $link) {
echo do_shortcode($link);
}
}
?>
</div>
</span>
<?php
return ob_get_clean();
}
}
public function collectionItem($atts, $content) {
$color = !empty($atts['color']) ? $atts['color'] : '';
$text = !empty($atts['text']) ? $atts['text'] : '';
$class = $color . " " . $text . "-text";
ob_start();
?>
<li class="collection-item <?php echo $class; ?>">
<?php echo do_shortcode($content); ?>
</li>
<?php
return ob_get_clean();
}
/**
* Link Collection [collection_links]
* Available Attributes:
* @color: background color
* @textColor: text color
* @active: a preselected active item
*/
public function collectionLink($atts, $content) {
$color = !empty($atts['color']) ? $atts['color'] : '';
$text = !empty($atts['text']) ? $atts['text'] : '';
$to = !empty($atts['to']) ? $atts['to'] : '';
$class = $color . " " . $text . "-text";
ob_start();
?>
<a href="<?php echo $to; ?>" class="collection-item <?php echo $class; ?>">
<?php echo do_shortcode($content); ?>
</a>
<?php
return ob_get_clean();
}
}