| 1 |
<?php |
| 2 |
namespace MBSocial; |
| 3 |
defined('ABSPATH') or die('No direct access permitted'); |
| 4 |
|
| 5 |
$collectionBlock["twitter"] = array('class' => "twitterBlock", |
| 6 |
'order' => 100); |
| 7 |
|
| 8 |
use \MaxButtons\maxField as maxField; |
| 9 |
use \MaxButtons\maxBlocks as maxBlocks; |
| 10 |
use \MaxButtons\maxUtils as maxUtils; |
| 11 |
|
| 12 |
|
| 13 |
class twitterBlock extends block |
| 14 |
{ |
| 15 |
|
| 16 |
protected $blockname = "twitter"; |
| 17 |
protected $fields = array( 'twitter_handle' => array('default' => ''), |
| 18 |
'twitter_hash' => array('default' => ''), |
| 19 |
); |
| 20 |
|
| 21 |
protected $meta_fields = array( |
| 22 |
'twitter_hash' => array('default' => ''), |
| 23 |
'twitter_handle' => array('default' => ''), |
| 24 |
|
| 25 |
); |
| 26 |
|
| 27 |
static $hooked = null; |
| 28 |
|
| 29 |
public function __construct() |
| 30 |
{ |
| 31 |
$w = MBSocial()->whistle(); |
| 32 |
|
| 33 |
if (self::$hooked == null) // listen just once. |
| 34 |
{ |
| 35 |
$w->listen('display/vars/twitter_handle', array($this, 'twitter_handle'), 'ask'); |
| 36 |
$w->listen('display/vars/twitter_hashtags', array($this, 'twitter_hashtags'), 'ask'); |
| 37 |
self::$hooked = true; |
| 38 |
} |
| 39 |
} |
| 40 |
|
| 41 |
public function twitter_handle() |
| 42 |
{ |
| 43 |
|
| 44 |
$post_id = $this->collection->post_id; |
| 45 |
$metadata = $this->get_block_meta_data($post_id); |
| 46 |
$blockdata = $this->data[$this->blockname]; |
| 47 |
|
| 48 |
$handle = ( isset($metadata['twitter_handle']) ) ? $metadata['twitter_handle'] : false; |
| 49 |
if (! $handle) |
| 50 |
$handle = ( isset($blockdata['twitter_handle']) ) ? $blockdata['twitter_handle'] : false; |
| 51 |
|
| 52 |
$handle = str_replace('@', '', $handle); |
| 53 |
|
| 54 |
return $handle; |
| 55 |
|
| 56 |
} |
| 57 |
|
| 58 |
public function twitter_hashtags() |
| 59 |
{ |
| 60 |
$post_id = $this->collection->post_id; |
| 61 |
$metadata = $this->get_block_meta_data($post_id); |
| 62 |
$blockdata = $this->data[$this->blockname]; |
| 63 |
|
| 64 |
$hash = ( isset($metadata['twitter_hash']) ) ? $metadata['twitter_hash'] : false; |
| 65 |
if (! $hash) |
| 66 |
$hash = ( isset($blockdata['twitter_hash'] )) ? $blockdata['twitter_hash'] : false; |
| 67 |
|
| 68 |
if ($hash && strlen($hash) > 0) |
| 69 |
{ |
| 70 |
|
| 71 |
$hashes = array_filter(explode(',', trim($hash)) ); |
| 72 |
$hashes = array_map('trim', $hashes); |
| 73 |
$hash = implode(',', $hashes); |
| 74 |
} |
| 75 |
return $hash; |
| 76 |
|
| 77 |
} |
| 78 |
|
| 79 |
public function do_meta_boxes($content, $post) |
| 80 |
{ |
| 81 |
$admin = mbSocial()->admin(); |
| 82 |
|
| 83 |
$metadata = $this->get_block_meta_data($post->ID); |
| 84 |
|
| 85 |
if (! Install::isPro() ) |
| 86 |
{ |
| 87 |
$gopro = new maxField('generic'); |
| 88 |
$gopro->id = 'pro'; |
| 89 |
$gopro->content = "<div class='forpro overlay'><div>" . $admin->getProMessage() . "</div></div>"; |
| 90 |
$admin->addField($gopro, false,false); |
| 91 |
} |
| 92 |
|
| 93 |
$hash = new maxField(); |
| 94 |
$hash->id = 'twitter_hash'; |
| 95 |
$hash->name = 'twitter_hash'; |
| 96 |
$hash->label = __('Twitter Hash Tag(s)', 'mbsocial'); |
| 97 |
$hash->placeholder = '#'; |
| 98 |
$hash->note = __('Seperate multiple tags with a comma', 'mbsocial'); |
| 99 |
$hash->value = isset($metadata['twitter_hash']) ? $metadata['twitter_hash'] : ''; |
| 100 |
|
| 101 |
$admin->addField($hash, 'start', 'end'); |
| 102 |
|
| 103 |
$handle = new maxField(); |
| 104 |
$handle->id = 'twitter_handle'; |
| 105 |
$handle->name = $handle->id; |
| 106 |
$handle->label = __('Twitter Handle', 'mbsocial'); |
| 107 |
$handle->note = __('Leave empty for global default','mbsocial'); |
| 108 |
$handle->value = isset($metadata['twitter_handle']) ? $metadata['twitter_handle'] : ''; |
| 109 |
|
| 110 |
$admin->addField($handle, 'start', 'end'); |
| 111 |
|
| 112 |
$fields = $admin->display_fields(true, true); |
| 113 |
|
| 114 |
|
| 115 |
$content['twitter'] = array('title' => __('Twitter', 'mbsocial'), |
| 116 |
'icon' => 'twitter', |
| 117 |
'content' => $fields, |
| 118 |
); |
| 119 |
|
| 120 |
return $content; |
| 121 |
|
| 122 |
} |
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
public function admin() |
| 127 |
{ |
| 128 |
$admin = mbSocial()->admin(); |
| 129 |
$blockdata = $this->data[$this->blockname]; |
| 130 |
|
| 131 |
|
| 132 |
?> |
| 133 |
<div class='options option-container layout' id='twitterBlock' |
| 134 |
data-has='{"target":"network_item_active[]","values":["twitter"]}' > |
| 135 |
<div class='title'><?php _e('Default Twitter Options', 'mbsocial' ); ?> </div> |
| 136 |
<div class='inside'> |
| 137 |
|
| 138 |
<?php |
| 139 |
$handle = new maxField(); |
| 140 |
$handle->id = 'twitter_handle'; |
| 141 |
$handle->name = $handle->id; |
| 142 |
$handle->label = __('Twitter Handle', 'mbsocial'); |
| 143 |
$handle->value = $this->getValue('twitter_handle') ; |
| 144 |
$handle->placeholder = '@example'; |
| 145 |
$handle->inputclass = 'medium'; |
| 146 |
$handle->help = __('Adding a handle will include the handle in the proposed message (via)', 'mb-social'); |
| 147 |
$admin->addField($handle, 'start', 'end', false); |
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
$hash = new maxField(); |
| 152 |
$hash->id = 'twitter_hash'; |
| 153 |
$hash->name = 'twitter_hash'; |
| 154 |
$hash->label = __('Twitter Default Hash Tag(s)', 'mbsocial'); |
| 155 |
$hash->value = $this->getValue('twitter_hash'); |
| 156 |
$hash->inputclass = 'medium'; |
| 157 |
$hash->help = __('Separate multiple hashtags with a comma (first,second)', 'mb-social'); |
| 158 |
$hash->placeholder = '#'; |
| 159 |
|
| 160 |
$admin->addField($hash, 'start', 'end', false); |
| 161 |
|
| 162 |
$admin->display_fields(); |
| 163 |
?> |
| 164 |
|
| 165 |
</div> <!-- inside --> |
| 166 |
</div> |
| 167 |
<?php |
| 168 |
|
| 169 |
|
| 170 |
} |
| 171 |
|
| 172 |
} |
| 173 |
|