| 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 save_fields($data, $post) |
| 104 |
{ |
| 105 |
$data = parent::save_fields($data, $post); |
| 106 |
|
| 107 |
// Filter URL |
| 108 |
if (isset($data[$this->blockname]['profile_rss']) && strlen($data[$this->blockname]['profile_rss'] > 0)) |
| 109 |
{ |
| 110 |
$data[$this->blockname]['profile_rss'] = esc_url_raw($data[$this->blockname]['profile_rss']); |
| 111 |
} |
| 112 |
|
| 113 |
return $data; |
| 114 |
} |
| 115 |
|
| 116 |
public function admin() |
| 117 |
{ |
| 118 |
$admin = mbSocial()->admin(); |
| 119 |
$active_networks = isset($this->data['network']['active']) ? $this->data['network']['active'] : array(); |
| 120 |
$networks = mbSocial()->networks()->get(); // all networks! |
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
foreach($networks as $network) |
| 125 |
{ |
| 126 |
if ($network->is_share_icon() ) |
| 127 |
{ |
| 128 |
$name = $network->get('network'); |
| 129 |
$placeholder = $network->get('profile_placeholder'); |
| 130 |
$profile_url = $network->get('profile_url'); |
| 131 |
|
| 132 |
$profile_url = str_replace('{profile}', '', $profile_url); |
| 133 |
if ($profile_url != '') |
| 134 |
$profile_url = trailingslashit($profile_url); |
| 135 |
$conditional = htmlentities(json_encode(array("target" => 'network_item_active[]', 'values' => array($name)))); |
| 136 |
|
| 137 |
$field = new maxField('text'); |
| 138 |
$field->id = 'profile_' . $name; |
| 139 |
$field->name = $field->id; |
| 140 |
$field->label = $network->get_nice_name(); |
| 141 |
$field->value = $this->getValue($field->id); |
| 142 |
$field->placeholder = $placeholder; |
| 143 |
$field->before_input = $profile_url; |
| 144 |
$field->inputclass = 'medium'; |
| 145 |
|
| 146 |
$field->start_cond_type = 'has'; |
| 147 |
$field->start_conditional = $conditional; |
| 148 |
|
| 149 |
if ($network->is_social_share()) |
| 150 |
$admin->addField($field, 'start', '', false); |
| 151 |
else { |
| 152 |
$admin->addField($field, 'start', 'end', false); |
| 153 |
} |
| 154 |
|
| 155 |
// when it's both, display choice |
| 156 |
if ($network->is_social_share() ) |
| 157 |
{ |
| 158 |
$sw = new maxField('switch'); |
| 159 |
$sw->id = 'useprofile_' . $name; |
| 160 |
$sw->name = $sw->id; |
| 161 |
$sw->label = __('Share Profile', 'mbsocial'); |
| 162 |
$sw->value = 1; |
| 163 |
$sw->inputclass = 'check_button icon'; |
| 164 |
$sw->checked = checked(1, $this->getValue($sw->name), false); |
| 165 |
|
| 166 |
// $sw->mainclass = 'switch'; |
| 167 |
|
| 168 |
// dunno about that. |
| 169 |
//$admin->addField($sw, 'group_start',array('group_end', 'end'), false); |
| 170 |
// $end = $network->has_alternate() ? '' : 'end'; |
| 171 |
$admin->addField($sw, '', 'end', false); |
| 172 |
} |
| 173 |
|
| 174 |
if ($network->has_alternate()) |
| 175 |
{ |
| 176 |
$spacer = new maxField('spacer'); |
| 177 |
$spacer->id = 'spacer-alternate'; |
| 178 |
$spacer->name = $spacer->id; |
| 179 |
$spacer->label = ' '; |
| 180 |
$spacer->main_class = 'option alternate_profile'; |
| 181 |
$spacer->start_conditional = htmlentities(json_encode(array("target" => 'useprofile_'. $name, 'values' => 'checked'))); |
| 182 |
|
| 183 |
$spacer2 = clone $spacer; |
| 184 |
$spacer2->id = 'spacer-alt-2'; |
| 185 |
$spacer2->name = $spacer2->id; |
| 186 |
|
| 187 |
$admin->addField($spacer, 'start', '', false); |
| 188 |
$admin->addField($spacer2, '', '', false); |
| 189 |
|
| 190 |
$alt = new MaxField('switch'); |
| 191 |
$alt->id = 'use_alternate_' . $name; |
| 192 |
$alt->name = $alt->id; |
| 193 |
$alt->label = $network->get('alternate_label'); |
| 194 |
$alt->value = 1; |
| 195 |
$alt->inputclass = 'check_button icon'; |
| 196 |
$alt->checked = checked($alt->value, $this->getValue($alt->name), false); |
| 197 |
|
| 198 |
$admin->addField($alt, '','end', false); |
| 199 |
} |
| 200 |
} |
| 201 |
|
| 202 |
} |
| 203 |
|
| 204 |
if (count($networks) > 0) |
| 205 |
{ |
| 206 |
?> |
| 207 |
<div class='help-side'> |
| 208 |
<h3><?php _e('Profile Options', 'mbsocial'); ?></h3> |
| 209 |
|
| 210 |
<p>Fill out the link to your profile on the network. </p> |
| 211 |
|
| 212 |
<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> |
| 213 |
</div> |
| 214 |
|
| 215 |
<div class='options option-container layout' id='profileBlock' data-refresh='previewBlock' > |
| 216 |
<div class='title'><?php _e('Profiles', 'mbsocial' ); ?></div> |
| 217 |
<div class='inside'> |
| 218 |
<?php |
| 219 |
$admin->display_fields(); |
| 220 |
?> |
| 221 |
</div> |
| 222 |
</div> |
| 223 |
<?php |
| 224 |
} |
| 225 |
|
| 226 |
} |
| 227 |
|
| 228 |
} |
| 229 |
|