PluginProbe
Social Share Buttons / 0.9
Social Share Buttons v0.9
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 0.9, at classes/class-block.php

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