PluginProbe
Social Share Buttons / 1.2
Social Share Buttons v1.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-admin.php

class-admin.php in Social Share Buttons 1.2, at classes/class-admin.php

317 lines 7.4 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 // Helper for admin pages / fields / saving etc.
6
7 class admin
8 {
9 protected $fields = array();
10 protected $defined_fields = array();
11 protected $defined_updatable = array();
12 protected static $namespace;
13
14 public function __construct()
15 {
16 self::$namespace = __NAMESPACE__ . '\\'; // PHP 5.3
17
18 }
19
20 // add a maxfield to be displayed on the admin.
21 public function addfield( $field, $start = '', $end = '', $trigger_update = true)
22 {
23 $field_id = isset($field->id) ? $field->id : $field->template . \rand(0,1000);
24 if ($trigger_update)
25 {
26 $this->addUpdate($field); // make updating standard
27 }
28 $field->publish = false; // Output fields via class - never output.
29
30 $this->fields[$field_id] = array('field' => $field,
31 'start' => $start,
32 'end' => $end);
33 $this->fields = apply_filters('mbsocial/editor/addfield', $this->fields, $field);
34
35 $this->defined_fields[] = $field_id;
36
37 }
38
39 public function addUpdate($field)
40 {
41 $field_id = $field->id;
42 if (is_null($field_id) || $field_id == '')
43 return; // no bad names
44
45 if (! isset($this->defined_updatable[$field_id])) // no double sets
46 $this->defined_updatable[] = $field_id;
47 }
48
49
50 public function namespaceit($var)
51 {
52 return self::$namespace . $var;
53 }
54
55 public function display_fields($clean = true, $return = false)
56 {
57 $fields = apply_filters('mbsocial/display_fields', $this->fields);
58 $output = '';
59
60 foreach($fields as $id => $item)
61 {
62 $field = $item['field'];
63 $output .= $field->output($item['start'], $item['end']);
64 }
65
66 // auto-update system
67 $updatable = $this->defined_updatable;
68 foreach($updatable as $index => $field)
69 {
70 $updatable[$index] = '#' . $field;
71 }
72
73 $output .= ' <span class="updatables hidden">' . implode(',', $updatable) . '</span>';
74
75 if ($clean)
76 {
77 $this->fields = array();
78 $this->defined_updatable = array();
79 }
80
81 if (! $return)
82 echo $output;
83 else
84 return $output;
85
86 }
87
88 public function output_defined_fields()
89 {
90 $fields = $this->defined_fields;
91 $fields = implode(',', $fields);
92
93 echo '<input type="hidden" name="defined_fields" value="' . $fields . '">';
94 }
95
96 /** @param $active_networks - Networks that were saved by the users. This should be loaded instead of the default ones **/
97 public function get_default_networks($active_networks = array() )
98 {
99 if (! is_array($active_networks))
100 {
101 $active_networks = array();
102 }
103 $networks = mbSocial()->networks()->get();
104 $selected = array();
105 $unselected = array();
106 $readmore = array();
107
108 // set active networks. Support doubles.
109 foreach($active_networks as $index => $network_name)
110 {
111 $network = mbSocial()->networks()->get($network_name);
112 if ($network->get('is_active'))
113 $selected[$index] = $network;
114 }
115
116 foreach($networks as $index => $network)
117 {
118 $priority = $network->get('priority');
119 if (! $network->get('is_active'))
120 { continue; }
121 $is_active = array_search($network->get('network'), $active_networks); // retrieve the array index
122
123 if ($is_active !== false)
124 {
125 $priority = 'selected';
126 }
127
128
129 /* if ($priority == 'selected')
130 {
131 continue; // ignore active, since it's set earlier.
132 //$selected[$is_active] = $network;
133
134 } */
135 if ($priority == 'unselected')
136 $unselected[] = $network;
137 if ($priority == 'readmore')
138 $readmore[] = $network;
139
140
141 if ($network->get('network') == 'maxbutton' && $priority != 'readmore') // exceptions
142 {
143 $readmore[] = $network;
144 }
145
146
147 } // foreach networks
148
149
150 // Sort networks by order saved.
151 ksort($selected);
152 return array('selected' => $selected, 'unselected' => $unselected, 'readmore' => $readmore);
153 }
154
155
156
157 /* Load saved networks, check which ones are selected. Load others as default settings if no save */
158 public function get_networks($active_networks = array() )
159 {
160 $networks_array = $this->get_default_networks($active_networks);
161 return $networks_array;
162 }
163
164 // render icons with input from different icon libraries (/future)
165 public function renderIcon($args)
166 {
167 $defaults = array('icon' => '',
168 'icon_type' => '',
169 'icon_size' => 20,
170 'title' => '',
171 );
172
173 $args = wp_parse_args($args, $defaults);
174
175 $icon_type = $args['icon_type'];
176 $icon = $args['icon'];
177 $icon_size = $args['icon_size'];
178 $title = $args['title'];
179
180 $faUtils = FAUtils::getInstance();
181
182 switch($icon_type)
183 {
184 case 'fa': // FA5
185 case 'fab':
186 case 'fas':
187 case 'far':
188 $args = array('icon' => trim($icon_type) . ' ' . trim($icon), 'title' => $title);
189 if ($icon_size)
190 {
191 $args['size'] = $icon_size;
192 }
193
194 $svg = $faUtils->getFASVG($args);
195 $output = "<span class='mb-icon'>$svg</span>";
196 break;
197 case 'nucleo':
198 $output = "<span class='mb-icon'><i class='$icon_type $icon' title='$title' > </i></span>";
199 break;
200 case 'svg':
201 case 'png':
202 $output = "<span class='mb-icon " . $icon_type . "'><img src='" . $icon . "' alt='" . $title . "'></span>";
203 break;
204
205 default:
206 $output = '';
207 break;
208 }
209
210 return apply_filters('display/render/icon', $output, $args);
211 }
212
213 public function header( $args = array() )
214 {
215 $defaults = array(
216 'title' => '',
217 );
218
219 $args = array_merge($defaults, $args);
220 extract($args);
221
222 include_once( mbSocial()->get_plugin_path() . '/admin/header.php');
223 }
224
225 public function footer()
226 {
227 include_once( mbSocial()->get_plugin_path() . '/admin/footer.php');
228 }
229
230 public function getProMessage()
231 {
232 return __( sprintf('You can only change these settings in the PRO version. Click %shere%s for upgrading to MaxButtons PRO', '
233 <a href="https://maxbuttons.com" target="_blank">', '</a>') );
234 }
235
236
237 public function do_review_notice () {
238
239 $current_user_id = get_current_user_id();
240 $version = MBSOCIAL_VERSION_NUM;
241
242 $review = get_user_meta( $current_user_id, 'mbsocial_review_notice' , true );
243
244 if ($review == '')
245 {
246 //$created = get_option("MBFREE_CREATED");
247 $show = time() + (7* DAY_IN_SECONDS);
248 update_user_meta($current_user_id, 'mbsocial_review_notice', $show);
249 return;
250 }
251
252 $display_review = false;
253
254 if ($review == 'off')
255 { return; // no show
256
257 }
258 elseif (is_numeric($review))
259 {
260 $now = time();
261
262 if ($now > $review)
263 {
264 $display_review = true;
265
266 }
267 }
268
269 // load style / script. It's seperated since it should show everywhere in admin.
270 if ($display_review)
271 {
272 add_action( 'admin_notices', array( $this, 'mbsocial_review_notice'));
273 // registered in admin scripts
274 MB()->load_library('review_notice');
275 }
276
277 }
278
279 public function mbsocial_review_notice()
280 {
281 include_once( mbSocial()->get_plugin_path() . '/admin/review_notice.php');
282 }
283
284 public function save_review_notice()
285 {
286 $status = isset($_POST["status"]) ? sanitize_text_field($_POST["status"]) : '';
287 $current_user_id = get_current_user_id();
288
289 $updated = false;
290
291 if ($status == 'off')
292 {
293 $updated = true;
294 update_user_meta($current_user_id, 'mbsocial_review_notice', 'off');
295
296 }
297 if ($status == 'later')
298 {
299 $updated = true;
300 $later = time() + (14 * DAY_IN_SECONDS );
301
302 update_user_meta($current_user_id, 'mbsocial_review_notice', $later);
303 }
304 if ($status == 'reviewoffer-dismiss') // different ad!
305 {
306 $updated = true;
307 update_user_meta($current_user_id, 'mbsocial_review_notice', 'off');
308
309 }
310
311 echo json_encode(array("updated" => $updated)) ;
312
313 exit();
314 }
315
316 }
317