PluginProbe
Social Share Buttons / 1.17
Social Share Buttons v1.17
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 / blocks / profile_block.php

profile_block.php in Social Share Buttons 1.17, at classes/blocks/profile_block.php

216 lines 5.8 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 use \MaxButtons\maxField as maxField;
6 use \MaxButtons\maxBlocks as maxBlocks;
7 use \MaxButtons\maxUtils as maxUtils;
8
9 $collectionBlock["profile"] = array('order' => 60,
10 'class' => "profileBlock"
11 );
12
13 class profileBlock extends block
14 {
15 protected $blockname = "profile";
16 protected $fields = array();
17
18
19 public function __construct()
20 {
21 // create the fields
22 $networks = MBSocial()->networks()->get();
23 foreach($networks as $network)
24 {
25 if ($network->is_share_icon())
26 {
27 $name = $network->get('network');
28 $this->fields['profile_' . $name] = array('default' => '');
29
30 if ($network->is_social_share())
31 {
32 $this->fields['useprofile_' . $name] = array('default' => 0);
33 }
34 if ($network->has_alternate())
35 {
36 $this->fields['use_alternate_' . $name] = array('default' => 0);
37 }
38 }
39 }
40
41 MBSocial()->whistle()->listen('display/vars/profile', array($this, 'get_profile'), 'ask'); // somebody asks for profile name
42 MBSocial()->whistle()->listen('editor/profile/use', array($this, 'get_profile_use'), 'ask'); // somebody asks for useprofile settings
43 MBSocial()->whistle()->listen('editor/profile/alternate', array($this, 'get_alternate_use'), 'ask'); // somebody
44 }
45
46 public function get_profile()
47 {
48 $network = MBSocial()->whistle()->ask('display/parse/network');
49
50 if (is_object($network))
51 {
52 $name = $network->get('network');
53 $blockdata = $this->data[$this->blockname];
54
55 if (isset($blockdata['profile_' . $name]))
56 {
57 $profile = $blockdata['profile_' . $name];
58 return $profile;
59 }
60 }
61
62 return '';
63 }
64
65 public function get_profile_use()
66 {
67 $network = MBSocial()->whistle()->ask('display/parse/network');
68
69 if (is_object($network))
70 {
71 $name = $network->get('network');
72 $blockdata = $this->data[$this->blockname];
73
74 if (isset($blockdata['useprofile_'. $name]))
75 {
76 return $blockdata['useprofile_' . $name];
77 }
78 else {
79 return false;
80 }
81 }
82 }
83
84 public function get_alternate_use()
85 {
86 $network = MBSocial()->whistle()->ask('display/parse/network');
87 $name = $network->get('network');
88 $blockdata = $this->data[$this->blockname];
89
90 if (is_object($network))
91 {
92 if ($network->has_alternate())
93 {
94 if (isset($blockdata['use_alternate_'. $name]))
95 {
96 return $blockdata['use_alternate_' . $name];
97 }
98 }
99 return false;
100 }
101 }
102
103 public function admin()
104 {
105 $admin = mbSocial()->admin();
106 $active_networks = isset($this->data['network']['active']) ? $this->data['network']['active'] : array();
107 $networks = mbSocial()->networks()->get(); // all networks!
108
109
110
111 foreach($networks as $network)
112 {
113 if ($network->is_share_icon() )
114 {
115 $name = $network->get('network');
116 $placeholder = $network->get('profile_placeholder');
117 $profile_url = $network->get('profile_url');
118
119 $profile_url = str_replace('{profile}', '', $profile_url);
120 if ($profile_url != '')
121 $profile_url = trailingslashit($profile_url);
122 $conditional = htmlentities(json_encode(array("target" => 'network_item_active[]', 'values' => array($name))));
123
124 $field = new maxField('text');
125 $field->id = 'profile_' . $name;
126 $field->name = $field->id;
127 $field->label = $network->get_nice_name();
128 $field->value = $this->getValue($field->id);
129 $field->placeholder = $placeholder;
130 $field->before_input = $profile_url;
131 $field->inputclass = 'medium';
132
133 $field->start_cond_type = 'has';
134 $field->start_conditional = $conditional;
135
136 if ($network->is_social_share())
137 $admin->addField($field, 'start', '', false);
138 else {
139 $admin->addField($field, 'start', 'end', false);
140 }
141
142 // when it's both, display choice
143 if ($network->is_social_share() )
144 {
145 $sw = new maxField('switch');
146 $sw->id = 'useprofile_' . $name;
147 $sw->name = $sw->id;
148 $sw->label = __('Share Profile', 'mbsocial');
149 $sw->value = 1;
150 $sw->inputclass = 'check_button icon';
151 $sw->checked = checked(1, $this->getValue($sw->name), false);
152
153 $sw->mainclass = 'switch';
154
155 // dunno about that.
156 //$admin->addField($sw, 'group_start',array('group_end', 'end'), false);
157 // $end = $network->has_alternate() ? '' : 'end';
158 $admin->addField($sw, '', 'end', false);
159 }
160
161 if ($network->has_alternate())
162 {
163 $spacer = new maxField('spacer');
164 $spacer->id = 'spacer-alternate';
165 $spacer->name = $spacer->id;
166 $spacer->label = '&nbsp;';
167 $spacer->main_class = 'option alternate_profile';
168 $spacer->start_conditional = htmlentities(json_encode(array("target" => 'useprofile_'. $name, 'values' => 'checked')));
169
170 $spacer2 = clone $spacer;
171 $spacer2->id = 'spacer-alt-2';
172 $spacer2->name = $spacer2->id;
173
174 $admin->addField($spacer, 'start', '', false);
175 $admin->addField($spacer2, '', '', false);
176
177 $alt = new MaxField('switch');
178 $alt->id = 'use_alternate_' . $name;
179 $alt->name = $alt->id;
180 $alt->label = $network->get('alternate_label');
181 $alt->value = 1;
182 $alt->inputclass = 'check_button icon';
183 $alt->checked = checked($alt->value, $this->getValue($alt->name), false);
184
185 $admin->addField($alt, '','end', false);
186 }
187 }
188
189 }
190
191 if (count($networks) > 0)
192 {
193 ?>
194 <div class='help-side'>
195 <h3><?php _e('Profile Options', 'mbsocial'); ?></h3>
196
197 <p>Fill out the link to your profile on the network. </p>
198
199 <p><strong>Share Profile :</strong> Check this to share your profile instead of the current page. This option is available for networks supporting both options</p>
200 </div>
201
202 <div class='options option-container layout' id='profileBlock' data-refresh='previewBlock' >
203 <div class='title'><?php _e('Profiles', 'mbsocial' ); ?></div>
204 <div class='inside'>
205 <?php
206 $admin->display_fields();
207 ?>
208 </div>
209 </div>
210 <?php
211 }
212
213 }
214
215 }
216