PluginProbe
MaxButtons – Create buttons / 6.9
MaxButtons – Create buttons v6.9
6.23 6.24 6.25 6.26 6.26.1 6.27 6.28 6.3 6.4 6.5 6.6 6.7 6.8 6.9 7.0 7.1 7.1.1 7.1.2 7.1.3 7.10 7.11 7.13 7.13.1 7.13.2 7.13.3 All 100 releases
maxbuttons / classes / collection-block.php

collection-block.php in MaxButtons – Create buttons 6.9, at classes/collection-block.php

217 lines 4.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 defined('ABSPATH') or die('No direct access permitted');
3
4 abstract class collectionBlock
5 {
6 protected $data = array();
7 protected $collection = null;
8 protected $fields = array();
9 protected $fielddata = array();
10 protected $blockname;
11 protected $is_preview = false;
12
13
14
15 function setCollection($collection)
16 {
17 $this->collection = $collection;
18 }
19
20 function set($data)
21 {
22 //$blockname = $this->blockname;
23
24 if (! isset($data[$this->blockname]))
25 $blockdata = array();
26 else
27 $blockdata = $data[$this->blockname];
28
29
30 foreach($this->fields as $field => $options)
31 {
32 if ($field == 'multifields') // multifields can't set default since amount is unknown
33 {
34 $mf_id = $options["id"];
35 $mf_fields = $options["fields"];
36 if (isset($blockdata[$mf_id]))
37 {
38 $this->data[$mf_id] = $blockdata[$mf_id]; // why not.
39 }
40 }
41 else
42 {
43 if (isset($blockdata[$field]))
44 $this->data[$field] = $blockdata[$field];
45 elseif (isset($options["default"]))
46 $this->data[$field] = $options["default"];
47 }
48 }
49
50 return true;
51
52 }
53
54 // get the block data
55 function get()
56 {
57 return $this->data;
58
59 }
60
61 function setPreview($preview = true)
62 {
63 $this->is_preview = $preview;
64
65 }
66
67 /* Save fields on a per block data
68
69 Post data is sent unfiltered so sanitization must be done here!
70 */
71 function save_fields($data, $post)
72 {
73 $blockdata = array();
74
75 //if (isset($this->data[$this->blockname]))
76 $blockdata = $this->data;
77
78 foreach($this->fields as $field => $options)
79 {
80
81 if ($field == "multifields") // standardize multi fields
82 {
83 $mf_id = $options["id"];
84 $mf_fields = $options["fields"];
85
86 $multidata = array();
87
88 if (isset($post[$mf_id])) // the collection with the id's.
89 {
90 $i = 0; // id's might be duplicate i.e. two similar buttons.
91 foreach ($post[$mf_id] as $id) // id is button-id
92 {
93
94 foreach($mf_fields as $mf_field => $options)
95 {
96 $default = (isset($options["default"])) ? $options["default"] : '';
97 // POST[ field_name - $id ]
98 //
99 $multidata[$i][$id][$mf_field] = isset($post[$mf_field . "-" . $id . "-" . $i ]) ? $post[$mf_field . "-" . $id . "-" . $i] : $default;
100 }
101 $i++;
102 }
103 }
104 $blockdata[$mf_id] = $multidata;
105 }
106 else
107 {
108 $default = (isset($options["default"])) ? $options["default"] : '';
109 // stripslashes since the WP post var adds them.
110 $blockdata[$field] = (isset($post[$field])) ? stripslashes(sanitize_text_field($post[$field])) : $default;
111 }
112 }
113
114
115 $data[$this->blockname] = $blockdata;
116 return $data;
117
118 }
119
120 function parse($domObj, $args)
121 {
122
123 return $domObj; // nothing to do by default
124 }
125
126 function parseButtons($buttons)
127 {
128 return $buttons;
129 }
130
131 // Adepted from block class - maxbuttons
132 function parseCSS($css, $args)
133 {
134 $data = $this->data;
135
136 // get all fields from this block
137 foreach($this->fields as $field => $field_data)
138 {
139 // get cssparts, can be comma-seperated value
140 $csspart = (isset($field_data["csspart"])) ? explode(",",$field_data["csspart"]) : array('maxbutton');
141 $csspseudo = (isset($field_data["csspseudo"])) ? explode(",", $field_data["csspseudo"]) : 'normal';
142
143 // if this field has a css property
144 if (isset($field_data["css"]))
145 {
146 // get the property value from the data
147 $value = isset($data[$field]) ? $data[$field] : '';
148 $value = str_replace(array(";"), '', $value); //sanitize
149
150 if ( strpos($field_data["default"],"px") && ! strpos($value,"px"))
151 {
152 if ($value == '') $value = 0; // pixel values, no empty but 0
153 $value .= "px";
154 }
155 if (isset($data[$field]))
156 {
157 foreach($csspart as $part)
158 {
159 if (is_array($csspseudo))
160 {
161 foreach($csspseudo as $pseudo)
162 $css[$part][$pseudo][$field_data["css"]] = $value ;
163 }
164 else
165 $css[$part][$csspseudo][$field_data["css"]] = $value ;
166 }
167 }
168 }
169
170 }
171
172 return $css;
173 }
174
175 // default function
176 function parseJS($js)
177 {
178 return $js;
179 }
180
181 // for the preview
182 public function map_fields($map)
183 {
184 foreach($this->fields as $field => $field_data)
185 {
186 if (isset($field_data["css"]))
187 {
188 $cssdef = $field_data["css"];
189 $multidef = explode('-',$cssdef);
190 if ( count($multidef) > 1)
191 {
192 $cssdef = "";
193 for($i = 0; $i < count($multidef); $i++)
194 {
195 if ($i == 0)
196 $cssdef .= $multidef[$i];
197 else
198 $cssdef .= ucfirst($multidef[$i]);
199 //$multidef[$i] . ucfirst($multidef[1]);
200 }
201 }
202 $map[$field]["css"] = $cssdef;
203 if ( isset($field_data["default"]) && strpos($field_data["default"],"px") != false )
204 $map[$field]["css_unit"] = 'px';
205
206 }
207 if (isset($field_data["csspart"]))
208 $map[$field]["csspart"] = $field_data["csspart"];
209 }
210 return $map;
211
212 }
213
214 abstract function admin_fields();
215
216 } // class
217