PluginProbe
Social Share Buttons / 1.15
Social Share Buttons v1.15
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.15, at classes/blocks/profile_block.php

163 lines 4.2 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 }
35 }
36
37 MBSocial()->whistle()->listen('display/vars/profile', array($this, 'get_profile'), 'ask'); // somebody asks for profile name
38 MBSocial()->whistle()->listen('editor/profile/use', array($this, 'get_profile_use'), 'ask'); // somebody asks for useprofile settings
39 }
40
41 public function get_profile()
42 {
43 $network = MBSocial()->whistle()->ask('display/parse/network');
44
45 if (is_object($network))
46 {
47 $name = $network->get('network');
48 $blockdata = $this->data[$this->blockname];
49
50 if (isset($blockdata['profile_' . $name]))
51 {
52 $profile = $blockdata['profile_' . $name];
53 return $profile;
54 }
55 }
56
57 return '';
58 }
59
60 public function get_profile_use()
61 {
62 $network = MBSocial()->whistle()->ask('display/parse/network');
63
64 if (is_object($network))
65 {
66 $name = $network->get('network');
67 $blockdata = $this->data[$this->blockname];
68
69 if (isset($blockdata['useprofile_'. $name]))
70 {
71 return $blockdata['useprofile_' . $name];
72 }
73 else {
74 return false;
75 }
76 }
77 }
78
79 public function admin()
80 {
81 $admin = mbSocial()->admin();
82 $active_networks = isset($this->data['network']['active']) ? $this->data['network']['active'] : array();
83 $networks = mbSocial()->networks()->get(); // all networks!
84
85 foreach($networks as $network)
86 {
87 if ($network->is_share_icon() )
88 {
89 $name = $network->get('network');
90 $placeholder = $network->get('profile_placeholder');
91 $profile_url = $network->get('profile_url');
92
93 $profile_url = str_replace('{profile}', '', $profile_url);
94 if ($profile_url != '')
95 $profile_url = trailingslashit($profile_url);
96 $conditional = htmlentities(json_encode(array("target" => 'network_item_active[]', 'values' => array($name))));
97
98 $field = new maxField('text');
99 $field->id = 'profile_' . $name;
100 $field->name = $field->id;
101 $field->label = $network->get_nice_name();
102 $field->value = $this->getValue($field->id);
103 $field->placeholder = $placeholder;
104 $field->before_input = $profile_url;
105 $field->inputclass = 'medium';
106
107 $field->start_cond_type = 'has';
108 $field->start_conditional = $conditional;
109
110 if ($network->is_social_share())
111 $admin->addField($field, 'start', '', false);
112 else {
113 $admin->addField($field, 'start', 'end', false);
114 }
115
116 // when it's both, display choice
117 if ($network->is_social_share() )
118 {
119 $sw = new maxField('switch');
120 $sw->id = 'useprofile_' . $name;
121 $sw->name = $sw->id;
122 $sw->label = '';
123 $sw->label = __('Share Profile', 'mbsocial');
124 $sw->value = 1;
125 $sw->inputclass = 'check_button icon';
126 $sw->checked = checked(1, $this->getValue($sw->name), false);
127
128 $sw->mainclass = 'switch';
129
130 $admin->addField($sw, 'group_start',array('group_end', 'end'), false);
131 }
132
133 }
134
135
136 }
137
138 if (count($networks) > 0)
139 {
140 ?>
141 <div class='help-side'>
142 <h3><?php _e('Profile Options', 'mbsocial'); ?></h3>
143
144 <p>Fill out the link to your profile on the network. </p>
145
146 <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>
147 </div>
148
149 <div class='options option-container layout' id='profileBlock' data-refresh='previewBlock' >
150 <div class='title'><?php _e('Profiles', 'mbsocial' ); ?></div>
151 <div class='inside'>
152 <?php
153 $admin->display_fields();
154 ?>
155 </div>
156 </div>
157 <?php
158 }
159
160 }
161
162 }
163