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 / collections / picker-block.php

picker-block.php in MaxButtons – Create buttons 6.9, at collections/picker-block.php

274 lines 7.2 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 $collectionBlock["picker"] = "pickerCollectionBlock";
5
6 class pickerCollectionBlock extends collectionBlock
7 {
8 protected $blockname = "picker";
9 protected $fields = array("selection" => array("default" => array() ),
10
11 );
12
13 // get all buttons in collection, set as proper button object/
14 function getButtons()
15 { // should maybe but a 'light init' of buttons?
16 $selection = $this->data["selection"];
17
18 $buttonsArray = array();
19 if (count($selection) == 0)
20 return $buttonsArray;
21
22 $table = maxUtils::get_table_name();
23 $status = 'publish';
24
25 $query_selection = $selection;
26
27 $selectmask = implode( ', ', array_fill( 0, count( $query_selection ), '%d' ) );
28 $sql = "SELECT DISTINCT * FROM {$table} WHERE id in (" . $selectmask . ") and status = '%s' ";
29 $prepare_values = $query_selection;
30
31 array_push($prepare_values, $status);
32
33 global $wpdb;
34 $sql = $wpdb->prepare($sql, $prepare_values );
35 $results = $wpdb->get_results($sql, ARRAY_A);
36
37 $data_array = array();
38
39 foreach ($results as $result)
40 {
41 $data_array[$result['id']] = $result;
42 }
43
44 foreach($selection as $button_id)
45 {
46 $button = MB()->getClass("button");
47
48 // performance: bypass the set ( = query ) for every button
49 //$button->set($button_id);
50
51 $data = isset($data_array[$button_id]) ? $data_array[$button_id] : array();
52 if (count($data) > 0)
53 {
54 maxButtons::buttonLoad(array("button_id" => $button_id)); // central registration - from button
55 $button->setupData($data);
56 }
57 else
58 continue; // non-existing buttons should not show.
59
60 maxButtons::forceNextID();
61
62 $buttonsArray[] = $button;
63 }
64
65
66 return $buttonsArray;
67 }
68
69 function parse($domObj, $args)
70 {
71
72 $buttons = $this->collection->getLoadedButtons();
73
74 $output = '';
75
76 $collectionObj = $domObj->find('.maxcollection', 0);
77
78 $btn_display = '';
79
80 foreach($buttons as $button)
81 {
82
83 $button->reloadData();
84 $button_id = $button->getID();
85
86 $document_id = $button->getDocumentID();
87
88 $default_args = array("mode" => "normal",
89 "compile" => false,
90 "load_type" => "footer",
91 );
92 $button_args = wp_parse_args($args, $default_args);
93 $button_args["load_css"] = $button_args["load_type"];
94
95 $button_args["echo"] = false; // non-optional.
96
97 if (isset($args['preview']) && $args["preview"])
98 $button_args["mode"] = "preview"; // buttons work with mode.
99
100 $btn_display .= "<span class='mb-collection-item item-$button_id ' data-doc-id='" . $document_id . "'>" . $button->display($button_args) . "</span>";
101
102
103 }
104
105
106 $collectionObj->innertext = $btn_display;
107
108 $domObj->load($domObj->save());
109
110 return $domObj;
111
112 }
113
114 function save_fields($data, $post)
115 {
116 $blockdata = $this->data;
117
118 $selection = array();
119
120 $button = MB()->getClass("button");
121
122 if (isset($post["sorted"]))
123 {
124 $sorted = array_filter(explode(",",sanitize_text_field($post["sorted"])));
125 $i = 0;
126 foreach($sorted as $button_id)
127 {
128
129 if (intval($button_id) > 0)
130 {
131 $selection[$i] = $button_id;
132 $i++;
133
134 $set_bool = $button->set($button_id);
135 if (! $set_bool) continue; // buttons that don't exist, like virtuals.
136
137 $button_data = $button->get();
138 $collection_id = $this->collection->getID();
139 $collection_meta = isset($button_data["meta"]["in_collections"]) ?
140 $button_data["meta"]["in_collections"] : array();
141
142 if (! is_array($collection_meta))
143 $collection_meta = maybe_unserialize($collection_meta);
144
145 if (is_array($collection_meta))
146 {
147 $key = array_search($collection_id, $collection_meta);
148 if ($key === false)
149 {
150 $collection_meta[] = $collection_id;
151 $button_data["meta"]["in_collections"] = $collection_meta;
152 $button->update($button_data);
153 }
154 }
155 }
156 }
157 }
158 /* If a button id is in the previous selection, but not in the current, maybe the button should be deleted if the
159 button appears to be auto-generated only for this collection */
160 if (isset($post["previous_selection"]))
161 {
162 $previous = array_filter(explode(",",sanitize_text_field($post["previous_selection"])));
163 foreach($previous as $button_id)
164 {
165 if (! in_array($button_id, $selection) && intval($button_id) > 0)
166 $this->collection->maybe_delete_button($button_id);
167 }
168
169 }
170 $data[$this->blockname]["selection"] = $selection;
171 return $data;
172 }
173
174 function admin_fields()
175 {
176 extract($this->data); // admin data
177 $btns = $this->collection->editor_getPacks();
178 ?>
179
180 <?php ob_start(); ?>
181 <div id="picker-modal">
182 <div class='picker-packages'>
183
184 <ul>
185 <?php foreach ($btns as $index => $data)
186 { ?>
187 <li><a href="#" data-pack="<?php echo $index ?>"><?php echo $data["tab"]; ?></a></li>
188
189 <?php } ?>
190 </ul>
191 </div>
192 <div class='picker-main' >
193 </div>
194 <div class='picker-inselection'>
195 <div class='info'>
196 <span class='count'></span> <?php _e("Selected","maxbuttons"); ?>
197 <button type="button" name="clear" class='button-link clear-selection'><?php _e("Clear","maxbuttons"); ?></button>
198 </div>
199 <div class='items'>
200 </div>
201 <div class='add'>
202 <button type="button" name="add-buttons" class="button button-primary"><?php _e("Add selected buttons","maxbuttons"); ?></button>
203 </div>
204 </div>
205
206
207 </div>
208
209 <?php
210 global $mb_pick_modal;
211 $mb_pick_modal = ob_get_contents();
212
213 // print this outside of the main div since it messes with z-index
214 add_action('mb-interface-end', 'mb_print_modal' );
215 function mb_print_modal()
216 {
217 global $mb_pick_modal;
218 echo $mb_pick_modal;
219 }
220 ob_end_clean();
221
222 ?>
223 <div class="mb_tab option-container">
224 <div class="title">
225 <span class="dashicons dashicons-list-view"></span>
226 <span class='title'><?php _e("Buttons", "maxbuttons"); ?></span>
227 <button name="picker_popup" type="button" class="button"><?php _e("Select Social Share Icons","maxbuttons"); ?></button>
228 <span class='right'><button name="save" type="submit" data-form='collection_edit' class="button button-primary"><?php _e("Save All","maxbuttons"); ?></button>
229 </span>
230 </div>
231 <div class="inside">
232
233 <div class="option preview_collection">
234 <label> <?php _e("Current Selection","maxbuttons"); ?></label>
235 <p><?php _e("Drag the buttons to change the order of your selection. You can remove the button by clicking on the remove icon.",
236 "maxbuttons"); ?>
237 </p>
238
239
240 <div class="mb_collection_selection">
241 <input type="hidden" name="sorted" value="" />
242 <input type="hidden" name="previous_selection" value="" />
243
244 <div class="sortable buttons">
245
246 <?php
247 foreach($selection as $button_id)
248 {
249 echo "<div class='shortcode-container item' data-id='$button_id'>";
250 $button = MB()->getClass("button");
251 $button->set($button_id);
252 echo "<div id='maxbutton-$button_id'>";
253 $button->display(array( "load_css" => "inline" ));
254 echo "</div>";
255 echo "<div class='button-remove'><span class='dashicons dashicons-no'></span></div>";
256 echo "</div>";
257 }
258
259 ?>
260
261 </div>
262 </div>
263 </div> <!-- option -->
264 </div> <!-- inside -->
265 </div> <!-- tab -->
266
267 <?php
268
269 }
270
271 }
272
273 ?>
274