PluginProbe
Social Share Buttons / 1.1
Social Share Buttons v1.1
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.1, at classes/class-admin.php

188 lines 4.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
61 foreach($fields as $id => $item)
62 {
63 $field = $item['field'];
64 $output .= $field->output($item['start'], $item['end']);
65 }
66
67 // auto-update system
68 $updatable = $this->defined_updatable;
69 foreach($updatable as $index => $field)
70 {
71 $updatable[$index] = '#' . $field;
72 }
73
74 $output .= ' <span class="updatables hidden">' . implode(',', $updatable) . '</span>';
75
76 if ($clean)
77 {
78 $this->fields = array();
79 $this->defined_updatable = array();
80 }
81
82 if (! $return)
83 echo $output;
84 else
85 return $output;
86
87 }
88
89 public function output_defined_fields()
90 {
91 $fields = $this->defined_fields;
92 $fields = implode(',', $fields);
93
94 echo '<input type="hidden" name="defined_fields" value="' . $fields . '">';
95 }
96
97 /** @param $active_networks - Networks that were saved by the users. This should be loaded instead of the default ones **/
98 public function get_default_networks($active_networks = array() )
99 {
100 if (! is_array($active_networks))
101 {
102 $active_networks = array();
103 }
104 $networks = mbSocial()->networks()->get();
105
106 $selected = array();
107 $unselected = array();
108 $readmore = array();
109
110 // set active networks. Support doubles.
111 foreach($active_networks as $index => $network_name)
112 {
113 $network = mbSocial()->networks()->get($network_name);
114 $selected[$index] = $network;
115 }
116
117 foreach($networks as $index => $network)
118 {
119 $priority = $network->get('priority');
120 $is_active = array_search($network->get('network'), $active_networks); // retrieve the array index
121
122 if ($is_active !== false)
123 {
124 $priority = 'selected';
125 }
126
127 /* if ($priority == 'selected')
128 {
129 continue; // ignore active, since it's set earlier.
130 //$selected[$is_active] = $network;
131
132 } */
133 if ($priority == 'unselected')
134 $unselected[] = $network;
135 if ($priority == 'readmore')
136 $readmore[] = $network;
137
138
139 if ($network->get('network') == 'maxbutton' && $priority != 'readmore') // exceptions
140 {
141 $readmore[] = $network;
142 }
143
144
145 } // foreach networks
146
147
148 // Sort networks by order saved.
149 ksort($selected);
150 return array('selected' => $selected, 'unselected' => $unselected, 'readmore' => $readmore);
151 }
152
153
154
155 /* Load saved networks, check which ones are selected. Load others as default settings if no save */
156 public function get_networks($active_networks = array() )
157 {
158 $networks_array = $this->get_default_networks($active_networks);
159 return $networks_array;
160 }
161
162 public function header( $args = array() )
163 {
164 $defaults = array(
165 'title' => '',
166 );
167
168 $args = array_merge($defaults, $args);
169 extract($args);
170
171 include_once( mbSocial()->get_plugin_path() . '/admin/header.php');
172 }
173
174 public function footer()
175 {
176 include_once( mbSocial()->get_plugin_path() . '/admin/footer.php');
177 }
178
179 public function getProMessage()
180 {
181 return __( sprintf('You can only change these settings in the PRO version. Click %shere%s for upgrading to MaxButtons PRO', '
182 <a href="https://maxbuttons.com" target="_blank">', '</a>') );
183 }
184
185
186
187 }
188