PluginProbe
Social Share Buttons / 1.1.2
Social Share Buttons v1.1.2
trunk 0.9 1.0 1.1 1.1.1 1.1.2 1.10 1.11 1.12 1.15 1.16 1.17 1.18 1.19 1.2 1.20 1.3 1.30 1.4 1.5 1.6 1.7 1.8 1.9
share-button / classes / class-block.php

class-block.php in Social Share Buttons 1.1.2, at classes/class-block.php

264 lines 5.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace MBSocial;
3 defined('ABSPATH') or die('No direct access permitted');
4
5 abstract class block
6 {
7 protected $data = array();
8 protected $collection = null;
9 protected $network;
10 protected $fields = array();
11 protected $fielddata = array();
12 protected $blockname;
13 protected $is_preview = false;
14
15
16 public function __construct()
17 {
18 $w = MBSocial()->whistle();
19 $w->listen('display/parse/network', array($this, 'set_network'), 'tell');
20 }
21
22 public function set_network($network)
23 {
24 $this->network = $network;
25 }
26 function setCollection($collection)
27 {
28 $this->collection = $collection;
29 }
30
31
32 public function set($data)
33 {
34 $this->data = $data;
35 if (! isset($this->data[$this->blockname]) )
36 $this->data[$this->blockname] = array();
37
38 return true;
39
40 }
41
42 // get the block data
43 public function get()
44 {
45 return $this->data;
46
47 }
48
49
50 public function get_name()
51 {
52 return $this->blockname;
53 }
54
55 public function get_fields()
56 {
57 return $this->fields;
58 }
59
60 public function getValue($field)
61 {
62 $data = $this->data;
63
64 if (isset($data[$this->blockname][$field]))
65 {
66 return $data[$this->blockname][$field];
67 }
68
69 if (isset($this->fields[$field]['default']))
70 return $this->fields[$field]['default'];
71
72
73 // if not found return default
74 return false;
75 }
76
77 public function getColorValue($fieldname)
78 {
79 $value = $this->getValue($fieldname);
80 if (! $value )
81 return false;
82
83 if (substr($value,0,1) !== '#')
84 {
85 $value = '#' . $value;
86 }
87
88 return $value;
89
90 }
91
92
93 public function setPreview($preview = true)
94 {
95 $this->is_preview = $preview;
96
97 }
98
99 /* Save fields on a per block data
100 *
101 * Post data is sent unfiltered so sanitization must be done here!
102 * @param $data Array with all collection block data
103 * @param $post Array|null The post array or null. Null in case of loading defaults, not a post.
104 */
105 public function save_fields($data, $post)
106 {
107 $blockdata = array();
108
109 //if (isset($this->data[$this->blockname]))
110 // $blockdata = $this->data;
111 //$blockdata = $data;
112
113 foreach($this->fields as $field => $options)
114 {
115
116 if ($field == "multifields") // standardize multi fields
117 {
118 $mf_id = $options["id"];
119 $mf_fields = $options["fields"];
120
121 $multidata = array();
122
123 if (isset($post[$mf_id])) // the collection with the id's.
124 {
125 $i = 0; // id's might be duplicate i.e. two similar buttons.
126 foreach ($post[$mf_id] as $id) // id is button-id
127 {
128
129 foreach($mf_fields as $mf_field => $options)
130 {
131 $default = (isset($options["default"])) ? $options["default"] : '';
132 // POST[ field_name - $id ]
133 //
134 $multidata[$i][$id][$mf_field] = isset($post[$mf_field . "-" . $id . "-" . $i ]) ? $post[$mf_field . "-" . $id . "-" . $i] : $default;
135 }
136 $i++;
137 }
138 }
139 $blockdata[$mf_id] = $multidata;
140 }
141 else
142 {
143 $default = (isset($options["default"])) ? $options["default"] : '';
144 // stripslashes since the WP post var adds them.
145 $blockdata[$field] = (isset($post[$field])) ? stripslashes(sanitize_text_field($post[$field])) : $default;
146 }
147 }
148
149 $data[$this->blockname] = $blockdata;
150 return $data;
151
152 }
153
154 public function parse($domObj, $args = array() )
155 {
156
157 return $domObj; // nothing to do by default
158 }
159
160 public function parseButtons($buttons)
161 {
162 return $buttons;
163 }
164
165 // Adepted from block class - maxbuttons
166 public function parseCSS($css, $args)
167 {
168 $data = $this->data[$this->blockname];
169
170 // get all fields from this block
171 foreach($this->fields as $field => $field_data)
172 {
173 // get cssparts, can be comma-seperated value
174 $csspart = (isset($field_data["csspart"])) ? explode(",",$field_data["csspart"]) : array('maxbutton');
175 $csspseudo = (isset($field_data["csspseudo"])) ? explode(",", $field_data["csspseudo"]) : 'normal';
176
177 // if this field has a css property
178 if (isset($field_data["css"]))
179 {
180
181
182 // get the property value from the data
183 $value = isset($data[$field]) ? $data[$field] : $field_data['default'];
184 $value = str_replace(array(";"), '', $value); //sanitize
185
186 if ( strpos($field_data["default"],"px") && ! strpos($value,"px"))
187 {
188 if ($value == '') $value = 0; // pixel values, no empty but 0
189 $value .= "px";
190 }
191
192 if (isset($data[$field]))
193 {
194
195 foreach($csspart as $part)
196 {
197 if (is_array($csspseudo))
198 {
199 foreach($csspseudo as $pseudo)
200 $css[$part][$pseudo][$field_data["css"]] = $value ;
201 }
202 else
203 $css[$part][$csspseudo][$field_data["css"]] = $value ;
204 }
205 }
206 }
207
208 }
209
210 return $css;
211 }
212
213
214 // default function
215 public function parseJS($js)
216 {
217 return $js;
218 }
219
220 /** Get the post metadata of a certain block
221 * Used in post specific settings
222 * @param $post_id int Post id
223 * @return Array | Boolean . Array of setting data, or false if not metadata present
224 */
225 public function get_block_meta_data($post_id)
226 {
227 $meta = $this->collection->get_metadata($post_id);
228
229 if ( isset($meta[$this->blockname]))
230 return $meta[$this->blockname];
231 else
232 return false;
233
234 }
235
236 public function save_meta_boxes($metadata, $post_id, $post)
237 {
238 if (! isset($this->meta_fields))
239 return $metadata;
240
241 $blockmeta = array();
242
243 foreach($this->meta_fields as $field => $options)
244 {
245 $default = (isset($options["default"])) ? $options["default"] : '';
246 // stripslashes since the WP post var adds them.
247 $blockmeta[$field] = (isset($post[$field])) ? stripslashes(sanitize_text_field($post[$field])) : $default;
248 }
249
250 $metadata[$this->blockname] = $blockmeta;
251
252 return $metadata;
253 }
254
255 public function do_meta_boxes($array, $post)
256 {
257 return $array;
258 }
259
260
261 abstract function admin();
262
263 } // class
264