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/buttons.php +92 -136 7.136.28 View file →
@@ -1,104 +1,104 @@
1 -<?php
1 +<?php
2 2 namespace MaxButtons;
3 -/** Buttons class - handles paging issues and sanity check for individual buttons
3 +/** Buttons class - handles paging issues and sanity check for individual buttons
4 4 */
5 -class maxButtons
5 +class maxButtons
6 6 {
7 - protected static $loadedButtons = array(); // loaded button in current scope
8 - /*
9 -
7 + protected static $loadedButtons = array(); // loaded button in current scope
8 + /*
9 +
10 10 array [ index ] [ button_id ] [data - document_id, done (bool )
11 11 */
12 - protected static $documentArray = array(); // given out document ID's
13 -
14 - // override to give out next document id. This is useful when buttons are set but not displayed directly.
12 + protected static $documentArray = array(); // given out document ID's
13 +
14 + // override to give out next document id. This is useful when buttons are set but not displayed directly.
15 15 protected static $doNext = false;
16 - protected static $current_doc_id = null;
17 - protected static $current_button_id = null;
18 -
19 - protected static $instance = null;
20 -
21 -
16 + protected static $current_doc_id = null;
17 + protected static $current_button_id = null;
18 +
19 + protected static $instance = null;
20 +
21 +
22 22 public static function getInstance()
23 23 {
24 - if (is_null(self::$instance))
25 - self::$instance = MB()->getClass('button');
26 -
27 - return self::$instance;
24 + if (is_null(self::$instance))
25 + self::$instance = new maxButtons();
26 +
27 + return self::$instance;
28 28 }
29 -
29 +
30 30 static function buttonLoad($args)
31 31 {
32 32
33 - $button_id = $args["button_id"];
34 - self::$loadedButtons[] = $button_id;
35 - $document_id = self::getDocumentID(array("button_id" => $button_id));
36 - self::$documentArray[] = array($button_id => array('document_id' => $document_id , 'done' => false));
33 + $button_id = $args["button_id"];
34 + self::$loadedButtons[] = $button_id;
35 + $document_id = self::getDocumentID(array("button_id" => $button_id));
36 + self::$documentArray[] = array($button_id => array('document_id' => $document_id , 'done' => false));
37 37
38 38 }
39 -
40 - static function forceNextID()
39 +
40 + static function forceNextID()
41 41 {
42 42 self::$doNext = true;
43 43 self::$current_doc_id = null;
44 - self::$current_button_id = null;
44 + self::$current_button_id = null;
45 45 }
46 -
46 +
47 47 static function getDocumentID($args)
48 48 {
49 - $button_id = $args["button_id"];
50 -
51 - if (! is_null(self::$current_doc_id) && self::$current_button_id == $button_id )
49 + $button_id = $args["button_id"];
50 +
51 + if (! is_null(self::$current_doc_id) && self::$current_button_id == $button_id )
52 52 return self::$current_doc_id;
53 -
54 -
53 +
54 +
55 55 if (self::$doNext == false)
56 56 {
57 - foreach(self::$documentArray as $index => $ids)
57 + foreach(self::$documentArray as $index => $ids)
58 58 {
59 59 foreach($ids as $doc_button_id => $doc_vars)
60 60 {
61 - if ($doc_button_id == $button_id)
62 - {
63 - if (! $doc_vars["done"])
64 - return $doc_vars["document_id"];
61 + if ($doc_button_id == $button_id)
62 + {
63 + if (! $doc_vars["done"])
64 + return $doc_vars["document_id"];
65 65 }
66 -
66 +
67 67 }
68 -
68 +
69 69 }
70 - }
71 - // if not found in documentarray make a new one
72 - $loaded = self::$loadedButtons;
73 - end($loaded);
74 - $i = 0;
75 -
76 - foreach($loaded as $btn_id)
70 + }
71 + // if not found in documentarray make a new one
72 + $loaded = self::$loadedButtons;
73 + end($loaded);
74 + $i = 0;
75 +
76 + foreach($loaded as $btn_id)
77 77 {
78 78 if ($btn_id == $button_id)
79 - $i++;
79 + $i++;
80 80 }
81 81 $i--; // minus the current added button..
82 -
82 +
83 83 //$index = key($loaded); // find last index
84 - if ($i == 0)
85 - $document_id = $button_id;
84 + if ($i == 0)
85 + $document_id = $button_id;
86 86 else
87 - $document_id = $button_id . "_" . $i;
88 -
87 + $document_id = $button_id . "_" . $i;
88 +
89 89 self::$doNext = false;
90 90 self::$current_doc_id = $document_id;
91 - self::$current_button_id = $button_id;
92 - return $document_id;
93 -
91 + self::$current_button_id = $button_id;
92 + return $document_id;
93 +
94 94 }
95 95
96 96 static function buttonDone($args)
97 97 {
98 - $button_id = $args["button_id"];
99 - $document_id = $args["document_id"];
100 -
98 + $button_id = $args["button_id"];
99 + $document_id = $args["document_id"];
100 +
101 101 foreach(self::$documentArray as $index => $data)
102 102 {
103 103 foreach($data as $doc_button_id => $doc_data)
104 104 {
@@ -105,101 +105,57 @@
105 105 if ($doc_button_id == $button_id && $doc_data["document_id"] == $document_id)
106 106 {
107 107 self::$documentArray[$index][$button_id]["done"] = true;
108 108 }
109 +
109 110 }
111 +
110 112 }
113 +
111 114 }
112 -
113 - public static function ajax_action()
115 +
116 + public static function ajax_action()
114 117 {
115 - $action = sanitize_text_field($_POST['button_action']);
118 + $action = sanitize_text_field($_POST['button_action']);
116 119 $check = wp_verify_nonce($_POST['nonce'], 'button-' . $action);
117 - $button_id = isset($_POST['button_id']) ? intval($_POST["button_id"]) : -1;
118 - $button = MB()->getClass('button');
119 - $paged = isset($_POST['paged']) ? intval($_POST['paged']) : '';
120 -
121 - $redirect = admin_url() . 'admin.php?page=maxbuttons-list';
122 -
123 - if ($paged)
124 - $redirect = add_query_arg('paged', $paged, $redirect);
125 -
126 - if (! $check)
127 - exit('Invalid Nonce');
128 -
120 + $button_id = intval($_POST["button_id"]);
121 + $button = new maxButton();
122 +
123 + if (! $check)
124 + exit('Invalid Nonce');
125 +
129 126 switch($action)
130 127 {
131 - case "delete":
132 - $button->delete($button_id);
133 - $redirect = add_query_arg(array('action' => 'list', 'message' => '1delete'), $redirect);
134 - //$redirect_url = admin_url() . 'admin.php?page=maxbuttons-controller&action=list&message=1delete';
128 + case "delete":
129 + $button->delete($button_id);
130 + $redirect_url = admin_url() . 'admin.php?page=maxbuttons-controller&action=list&message=1delete';
135 131 break;
136 -
137 - case "trash":
138 - $result = $button->set($button_id);
132 +
133 + case "trash":
134 + $result = $button->set($button_id);
139 135 if ($result)
140 - $button->setStatus('trash');
141 - $redirect = add_query_arg(array('action' => 'list', 'message' => '1'), $redirect);
142 - //$redirect_url = admin_url() . 'admin.php?page=maxbuttons-controller&action=list&message=1';
143 - break;
144 - case "restore":
136 + $button->setStatus('trash');
137 + $redirect_url = admin_url() . 'admin.php?page=maxbuttons-controller&action=list&message=1';
138 + break;
139 + case "restore":
145 140 $set = $button->set($button_id,'','trash');
146 - $button->setStatus("publish");
147 - $redirect = add_query_arg(array('action' => 'list', 'message' => '1restore', 'status' => 'trash'), $redirect);
148 - //$redirect_url = admin_url() . 'admin.php?page=maxbuttons-controller&action=list&status=trash&message=1restore';
141 + $button->setStatus("publish");
142 + $redirect_url = admin_url() . 'admin.php?page=maxbuttons-controller&action=list&status=trash&message=1restore';
149 143 break;
150 - case "copy":
151 - $button->set($button_id);
152 - $new_id = $button->copy();
153 - $redirect = add_query_arg(array('action' => 'button', 'id' => $new_id), $redirect);
154 - //$redirect_url = admin_url() . 'admin.php?page=maxbuttons-controller&action=button&id=' . $new_id;
144 + case "copy":
145 + $button->set($button_id);
146 + $new_id = $button->copy();
147 + $redirect_url = admin_url() . 'admin.php?page=maxbuttons-controller&action=button&id=' . $new_id;
155 148 break;
156 - case 'empty-trash':
157 - $mbadmin = MB()->getClass("admin");
158 - $args = array('status' => 'trash', 'limit' => -1 );
159 - $buttons = $mbadmin->getButtons($args);
160 -
161 - foreach($buttons as $btnar)
162 - {
163 - $button_id = $btnar['id'];
164 - $button->delete($button_id);
165 - }
166 - $redirect = add_query_arg(array('action' => 'list', 'message' => 'empty-trash'), $redirect);
167 - // $redirect_url = admin_url() . 'admin.php?page=maxbuttons-controller&action=list&message=empty-trash';
168 - break;
169 -
149 +
170 150 }
171 -
172 - if (isset($redirect)) {
173 - $response = array('redirection' => $redirect);
151 +
152 + if (isset($redirect_url)) {
153 + $response = array('redirection' => $redirect_url);
174 154 echo json_encode($response);
175 155 exit();
176 156 }
177 -
157 +
178 158 exit(true);
179 - }
180 -
181 -
182 - public static function generate_css()
183 - {
184 - global $wpdb;
185 - $id = isset($_REQUEST['id']) ? sanitize_text_field($_REQUEST['id']) : false;
186 -
187 - if (! $id)
188 - return;
189 -
190 - $idar = explode(',', $id);
191 - $idar = array_filter($idar, 'is_numeric');
192 - $id = implode(',',$idar);
193 -
194 - $row = $wpdb->get_col($wpdb->prepare("SELECT cache FROM " . maxUtils::get_table_name() . " WHERE id in($id) and status ='%s'", 'publish'));
195 -
196 -
197 - header( "Content-type: text/css; charset: UTF-8" );
198 - foreach($row as $content)
199 - {
200 - echo $content;
201 - }
202 - exit();
203 159 }
204 160
205 161 } // class