PluginProbe
MaxButtons – Create buttons / 6.28
MaxButtons – Create buttons v6.28
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
← All changes | classes/admin-class.php +230 -175 6.76.28 View file →
@@ -1,34 +1,39 @@
1 1 <?php
2 +namespace MaxButtons;
2 3 defined('ABSPATH') or die('No direct access permitted');
3 4
4 5 class maxButtonsAdmin
5 6 {
6 -
7 - protected $wpdb;
8 - protected static $instance = null;
9 -
7 +
8 + protected $wpdb;
9 + protected static $instance = null;
10 +
11 + protected $fields = array();
12 + protected $defined_fields = array();
13 + protected $defined_updatable = array();
14 +
10 15 function __construct()
11 16 {
12 - global $wpdb;
17 + global $wpdb;
13 18 $this->wpdb = $wpdb;
14 19 }
15 -
20 +
16 21 public static function getInstance()
17 22 {
18 - if (is_null(self::$instance))
19 - self::$instance = new maxButtonsAdmin();
20 -
21 - return self::$instance;
22 -
23 + if (is_null(self::$instance))
24 + self::$instance = new maxButtonsAdmin();
25 +
26 + return self::$instance;
27 +
23 28 }
24 29
25 - public function loadFonts()
30 + public function loadFonts()
26 31 {
27 32 $fonts = array(
28 - '' => '',
33 + '' => __('[Site Default]','maxbuttons'),
29 34 'Arial' => 'Arial',
30 - 'Courier New' => 'Courier New',
35 + 'Courier New' => 'Courier New',
31 36 'Georgia' => 'Georgia',
32 37 'Tahoma' => 'Tahoma',
33 38 'Times New Roman' => 'Times New Roman',
34 39 'Trebuchet MS' => 'Trebuchet MS',
@@ -36,127 +41,177 @@
36 41 );
37 42 return $fonts;
38 43 }
39 44
40 - /* Get multiple buttons
41 -
42 - Used for overview pages, retrieve buttons on basis of passed arguments.
43 -
45 +
46 + // add a maxfield to be displayed on the admin.
47 + public function addfield( $field, $start = '', $end = '')
48 + {
49 + $field_id = isset($field->id) ? $field->id : $field->template . \rand(0,1000);
50 +
51 + $field->publish = false; // Output fields via class - never output.
52 +
53 + $this->fields[$field_id] = array('field' => $field,
54 + 'start' => $start,
55 + 'end' => $end);
56 + $this->fields = apply_filters('mb/editor/addfield', $this->fields, $field);
57 +
58 + $this->defined_fields[] = $field_id;
59 + do_action('mb/editor/afterfield/'. $field_id);
60 + }
61 +
62 + public function display_fields($clean = true, $return = false)
63 + {
64 + $fields = apply_filters('mb/display_fields', $this->fields);
65 + $output = '';
66 +
67 +
68 + foreach($fields as $id => $item)
69 + {
70 + $field = $item['field'];
71 + $output .= $field->output($item['start'], $item['end']);
72 + }
73 +
74 + // auto-update system
75 + $updatable = $this->defined_updatable;
76 + foreach($updatable as $index => $field)
77 + {
78 + $updatable[$index] = '#' . $field;
79 + }
80 +
81 + $output .= ' <span class="updatables hidden">' . implode(',', $updatable) . '</span>';
82 +
83 + if ($clean)
84 + {
85 + $this->fields = array();
86 + $this->defined_updatable = array();
87 + }
88 +
89 + if (! $return)
90 + echo $output;
91 + else
92 + return $output;
93 +
94 +}
95 +
96 + /* Get multiple buttons
97 +
98 + Used for overview pages, retrieve buttons on basis of passed arguments.
99 +
44 100 @return array Array of found buttons with argument
45 - */
46 -
101 + */
102 +
47 103 function getButtons($args = array())
48 104 {
49 -
50 105 $defaults = array(
51 - "status" => "publish",
52 - "orderby" => "id",
106 + "status" => "publish",
107 + "orderby" => "id",
53 108 "order" => "DESC",
54 - "limit" => 20,
55 - "paged" => 1,
109 + "limit" => 20,
110 + "paged" => 1,
56 111 );
57 - $args = wp_parse_args($args, $defaults);
58 -
59 - $limit = intval($args["limit"]);
112 + $args = wp_parse_args($args, $defaults);
113 +
114 + $limit = intval($args["limit"]);
60 115 $page = intval($args["paged"]);
61 - $escape = array();
116 + $escape = array();
62 117 $escape[] = $args["status"];
63 -
118 +
64 119 // 'white-list' escaping
65 120 switch ($args["orderby"])
66 121 {
67 - case "id";
68 - $orderby = "id";
122 + case "id";
123 + $orderby = "id";
69 124 break;
70 - case "name":
71 - default:
72 - $orderby = "name";
125 + case "name":
126 + default:
127 + $orderby = "name";
73 128 break;
74 129
75 130 }
76 -
131 +
77 132 switch($args["order"])
78 133 {
79 - case "DESC":
80 - case "desc":
81 - $order = "DESC";
134 + case "DESC":
135 + case "desc":
136 + $order = "DESC";
82 137 break;
83 - case "ASC":
84 - case "asc":
138 + case "ASC":
139 + case "asc":
85 140 default:
86 - $order = "ASC";
141 + $order = "ASC";
87 142 break;
88 143 }
89 144
90 -
91 - $sql = "SELECT id FROM " . maxUtils::get_table_name() . " WHERE status = '%s'";
145 +
146 + $sql = "SELECT id FROM " . maxUtils::get_table_name() . " WHERE status = '%s'";
92 147 if ($args["orderby"] != '')
93 148 {
94 - $sql .= " ORDER BY $orderby $order";
95 -
96 - }
97 -
98 - if ($limit > 0)
149 + $sql .= " ORDER BY $orderby $order";
150 +
151 + }
152 +
153 + if ($limit > 0)
99 154 {
100 155
101 - if ($page == 1 )
102 - $offset = 0;
103 - else
156 + if ($page == 1 )
157 + $offset = 0;
158 + else
104 159 $offset = ($page-1) * $limit;
105 -
106 - $sql .= " LIMIT $offset, $limit ";
160 +
161 + $sql .= " LIMIT $offset, $limit ";
107 162 }
108 -
109 - $sql = $this->wpdb->prepare($sql,$escape , ARRAY_A);
110 -
163 +
164 + $sql = $this->wpdb->prepare($sql,$escape);
165 +
111 166 $buttons = $this->wpdb->get_results($sql, ARRAY_A);
112 -
113 -
167 +
168 +
114 169 return $buttons;
115 -
170 +
116 171 }
117 -
172 +
118 173 function getButtonCount($args = array())
119 174 {
120 175 $defaults = array(
121 - "status" => "publish",
122 -
176 + "status" => "publish",
177 +
123 178 );
124 - $args = wp_parse_args($args, $defaults);
125 -
126 - $sql = "SELECT count(id) FROM " . maxUtils::get_table_name() . " WHERE status = '%s'";
127 - $sql = $this->wpdb->prepare($sql, $args["status"] );
179 + $args = wp_parse_args($args, $defaults);
180 +
181 + $sql = "SELECT count(id) FROM " . maxUtils::get_table_name() . " WHERE status = '%s'";
182 + $sql = $this->wpdb->prepare($sql, $args["status"] );
128 183 $result = $this->wpdb->get_var($sql);
129 184 return $result;
130 -
185 +
131 186 }
132 -
187 +
133 188 function getButtonPages($args = array())
134 189 {
135 190 $defaults = array(
136 - "limit" => 20,
137 - "paged" => 1,
138 - "status" => "publish",
139 - "output" => "list", // not used, future arg.
191 + "limit" => 20,
192 + "paged" => 1,
193 + "status" => "publish",
194 + "output" => "list", // not used, future arg.
140 195 "view" => "all",
141 196
142 197 );
143 198
144 - $args = wp_parse_args($args, $defaults);
199 + $args = wp_parse_args($args, $defaults);
145 200
146 - $limit = intval($args["limit"]);
147 - $page = intval($args["paged"]);
201 + $limit = intval($args["limit"]);
202 + $page = intval($args["paged"]);
148 203 $view = $args["view"];
149 204
150 - $total = $this->getButtonCount(array("status" => $args["status"]));
151 -
152 - $num_pages = ceil($total / $limit);
153 -
154 - if ($num_pages == 0) $num_pages = 1; // lowest limit, page 1
155 - $output = '';
205 + $total = $this->getButtonCount(array("status" => $args["status"]));
206 +
207 + $num_pages = ceil($total / $limit);
208 +
209 + if ($num_pages == 0) $num_pages = 1; // lowest limit, page 1
210 + $output = '';
156 211 $url = $_SERVER['REQUEST_URI'];
157 212
158 - $url = remove_query_arg("view", $url);
213 + $url = remove_query_arg("view", $url);
159 214 $url = add_query_arg("view", $view, $url);
160 215
161 216 $first_url = ($page != 1 ) ? add_query_arg("paged", 1, $url) : false;
162 217 $last_url = ($page != $num_pages) ? add_query_arg("paged", $num_pages, $url) : false;
@@ -161,157 +216,157 @@
161 216 $first_url = ($page != 1 ) ? add_query_arg("paged", 1, $url) : false;
162 217 $last_url = ($page != $num_pages) ? add_query_arg("paged", $num_pages, $url) : false;
163 218 $next_url = ($page != $num_pages) ? add_query_arg("paged", ($page + 1), $url) : false;
164 219 $next_page = ($page != $num_pages) ? ($page + 1) : false;
165 - $prev_page = ($page != 1) ? ($page -1 ) : false;
220 + $prev_page = ($page != 1) ? ($page -1 ) : false;
166 221 $prev_url = ($page != 1 ) ? add_query_arg("paged", ($page -1), $url) : false;
167 -
168 222
223 +
169 224 $return = array(
170 - "first" => 1,
171 - "base" => remove_query_arg("paged",$url),
225 + "first" => 1,
226 + "base" => remove_query_arg("paged",$url),
172 227 "first_url" => esc_url($first_url),
173 228 "last" => $num_pages,
174 229 "last_url" => esc_url($last_url),
175 - "next_url" => esc_url($next_url),
230 + "next_url" => esc_url($next_url),
176 231 "prev_url" => esc_url($prev_url),
177 - "prev_page" => $prev_page,
178 - "next_page" => $next_page,
179 - "total" => $total,
180 - "current" => $page,
181 -
182 -
183 -
232 + "prev_page" => $prev_page,
233 + "next_page" => $next_page,
234 + "total" => $total,
235 + "current" => $page,
236 +
237 +
238 +
184 239 );
185 -
240 +
186 241 return $return;
187 242 }
188 -
243 +
189 244 static function getAjaxButtons()
190 245 {
191 -
246 +
192 247 $admin = self::getInstance();
193 - $args = array();
248 + $args = array();
194 249
195 - $paged = (isset($_REQUEST["paged"])) ? intval($_REQUEST["paged"]) : 1;
196 - if ($paged > 0)
250 + $paged = (isset($_REQUEST["paged"])) ? intval($_REQUEST["paged"]) : 1;
251 + if ($paged > 0)
197 252 $args["paged" ] = $paged;
198 253
199 -
200 - $button = new MaxButton();
254 +
255 + $button = new MaxButton();
201 256 $buttons = $admin->getButtons($args);
202 -
257 +
203 258 echo "<div id='maxbuttons'><div class='preview-buttons'>";
204 259
205 260 echo '<div class="tablenav top"> ';
206 - echo "<span class='hint'>" . __('Click on a button to select it and add the shortcode to the editor', 'maxbuttons') . "</span>";
207 - do_action('mb-display-pagination', $args);
208 - echo '<span class="loading"></span>';
209 - echo '</div>';
261 + echo "<span class='hint'>" . __('Click on a button to select it and add the shortcode to the editor', 'maxbuttons') . "</span>";
262 + do_action('mb-display-pagination', $args);
263 + echo '<span class="loading"></span>';
264 + echo '</div>';
210 265
211 266
212 - if (count($buttons) == 0)
267 + if (count($buttons) == 0)
213 268 {
214 -
269 +
215 270 $url = admin_url('admin.php?page=maxbuttons-controller&action=edit');
216 - echo "<p><strong>" . __("You didn't add any buttons yet!","maxbuttons") . "</strong></p>";
217 - echo "<P>" . sprintf(__("Click %shere%s to add one", "maxbuttons"),
218 - "<a href='$url' target='_blank'>", "</a>") . "</strong></p>";
271 + echo "<p><strong>" . __("You didn't add any buttons yet!","maxbuttons") . "</strong></p>";
272 + echo "<P>" . sprintf(__("Click %shere%s to add one", "maxbuttons"),
273 + "<a href='$url' target='_blank'>", "</a>") . "</strong></p>";
219 274
220 275 }
221 -
276 +
222 277 foreach($buttons as $b)
223 278 {
224 -
225 - $button_id = $b["id"];
279 +
280 + $button_id = $b["id"];
226 281 $button->set($button_id);
227 - echo "<div class='button-row button-select' data-button='$button_id'>";
228 - echo "<span class='col col_insert'> ";
282 + echo "<div class='button-row button-select' data-button='$button_id'>";
283 + echo "<span class='col col_insert'> ";
229 284
230 285 echo "<span class='small'>[ID: $button_id ]</span>
231 - </span> ";
232 -
286 + </span> ";
287 +
233 288 echo "<span class='col col_button'><div class='shortcode-container'>";
234 289 $button->display(array("mode" => "preview", "load_css" => "inline" ));
235 - echo "</div></span>";
290 + echo "</div></span>";
236 291 echo "<span class='col col_name'>" . $button->getName() . "</span>";
237 - echo "</div>";
292 + echo "</div>";
238 293 }
239 294 echo '<div class="tablenav bottom"> ';
240 - do_action('mb-display-pagination', $args);
241 - echo '<span class="loading"></span>';
242 - echo '</div>';
295 + do_action('mb-display-pagination', $args);
296 + echo '<span class="loading"></span>';
297 + echo '</div>';
243 298
244 -
299 +
245 300 echo "</div></div>";
246 - echo "<p>&nbsp;</p>";
247 -
248 - exit();
249 -
301 + echo "<p>&nbsp;</p>";
302 +
303 + exit();
304 +
250 305 }
251 306 function get_header($args =array() )
252 307 {
253 308 $defaults = array(
254 309 "tabs_active" => false,
255 - "title" => "",
256 - "action" => "",
257 - );
258 -
259 - $args = wp_parse_args($args, $defaults);
310 + "title" => "",
311 + "action" => "",
312 + );
313 +
314 + $args = wp_parse_args($args, $defaults);
260 315 extract($args);
261 -
262 - include_once(MB()->get_plugin_path() . "includes/admin_header.php");
263 -
316 +
317 + include_once(MB()->get_plugin_path() . "includes/admin_header.php");
318 +
264 319 }
265 320
266 -
321 +
267 322 function get_footer()
268 323 {
269 - include_once(MB()->get_plugin_path() . "includes/admin_footer.php");
270 -
324 + include_once(MB()->get_plugin_path() . "includes/admin_footer.php");
325 +
271 326 }
272 -
273 - // unified (future way to end ajax requests + feedback
327 +
328 + // unified (future way to end ajax requests + feedback
274 329 function endAjaxRequest($args = array())
275 330 {
276 331 $defaults = array(
277 332 "error" => true, // can have errors and still result true on success
278 - "result" => true,
279 - "body" => "",
333 + "result" => true,
334 + "body" => "",
280 335 "title" => "",
281 - "data" => array(),
336 + "data" => array(),
282 337 );
283 -
284 - $args = wp_parse_args($args, $defaults);
285 -
338 +
339 + $args = wp_parse_args($args, $defaults);
340 +
286 341 echo json_encode($args);
287 - die();
288 -
289 -
342 + die();
343 +
344 +
290 345 }
291 -
292 - function log($action, $message)
346 +
347 + function log($action, $message)
293 348 {
294 349 if (! defined('MAXBUTTONS_DEBUG') || ! MAXBUTTONS_DEBUG)
295 - return;
296 -
297 - $stack = debug_backtrace();
298 - $caller = $stack[1]['function'];
299 -
300 - $dir = MB()->get_plugin_path() . "logs";
301 - if (! is_dir($dir))
302 - @mkdir($dir, 0777, true); // silently fail here.
303 -
304 - if (! is_dir($dir))
305 - return false;
306 -
307 - $file = fopen($dir . "/maxbuttons.log", "a+");
308 - $now = new DateTime() ;
309 - $now_format = $now->format("d/M/Y H:i:s");
310 -
311 - $write_string = "[" . $now_format . "] $action - $message ( $caller )";
312 - fwrite($file, $write_string);
313 - fclose($file);
314 -
315 -
350 + return;
351 +
352 + $stack = debug_backtrace();
353 + $caller = $stack[1]['function'];
354 +
355 + $dir = MB()->get_plugin_path() . "logs";
356 + if (! is_dir($dir))
357 + @mkdir($dir, 0777, true); // silently fail here.
358 +
359 + if (! is_dir($dir))
360 + return false;
361 +
362 + $file = fopen( trailingslashit($dir) . "/maxbuttons.log", "a+");
363 + $now = new DateTime() ;
364 + $now_format = $now->format("d/M/Y H:i:s");
365 +
366 + $write_string = "[" . $now_format . "] $action - $message ( $caller )";
367 + fwrite($file, $write_string);
368 + fclose($file);
369 +
370 +
316 371 }
317 372 }