| 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 = __('Use Profile', 'mbsocial'); |
| 124 |
$sw->value = 1; |
| 125 |
$sw->inputclass = 'check_button icon'; |
| 126 |
$sw->checked = checked(1, $this->getValue($sw->name), false); |
| 127 |
|
| 128 |
$admin->addField($sw, '','end', false); |
| 129 |
} |
| 130 |
|
| 131 |
} |
| 132 |
|
| 133 |
|
| 134 |
} |
| 135 |
|
| 136 |
if (count($networks) > 0) |
| 137 |
{ |
| 138 |
?> |
| 139 |
<div class='help-side'> |
| 140 |
<h3><?php _e('Profile Options', 'mbsocial'); ?></h3> |
| 141 |
|
| 142 |
<p>Fill out the link to your profile on the network. </p> |
| 143 |
|
| 144 |
<p><strong>Use Profile :</strong> Check this to share your profile instead of the current page. This option is available for networks supporting both options</p> |
| 145 |
</div> |
| 146 |
|
| 147 |
<div class='options option-container layout' id='profileBlock' data-refresh='previewBlock' > |
| 148 |
<div class='title'><?php _e('Profiles', 'mbsocial' ); ?></div> |
| 149 |
<div class='inside'> |
| 150 |
<?php |
| 151 |
$admin->display_fields(); |
| 152 |
?> |
| 153 |
</div> |
| 154 |
</div> |
| 155 |
<?php |
| 156 |
} |
| 157 |
|
| 158 |
} |
| 159 |
|
| 160 |
} |
| 161 |
|