PluginProbe
Social Share Buttons / 1.9
Social Share Buttons v1.9
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 / twitter_block.php

twitter_block.php in Social Share Buttons 1.9, at classes/blocks/twitter_block.php

165 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 $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
28 public function __construct()
29 {
30 $w = MBSocial()->whistle();
31
32 $w->listen('display/vars/twitter_handle', array($this, 'twitter_handle'), 'ask');
33 $w->listen('display/vars/twitter_hashtags', array($this, 'twitter_hashtags'), 'ask');
34 }
35
36 public function twitter_handle()
37 {
38
39 $post_id = $this->collection->post_id;
40 $metadata = $this->get_block_meta_data($post_id);
41 $blockdata = $this->data[$this->blockname];
42
43 $handle = ( isset($metadata['twitter_handle']) ) ? $metadata['twitter_handle'] : false;
44 if (! $handle)
45 $handle = ( isset($blockdata['twitter_handle']) ) ? $blockdata['twitter_handle'] : false;
46
47 $handle = str_replace('@', '', $handle);
48
49 return $handle;
50
51 }
52
53 public function twitter_hashtags()
54 {
55 $post_id = $this->collection->post_id;
56 $metadata = $this->get_block_meta_data($post_id);
57 $blockdata = $this->data[$this->blockname];
58
59 $hash = ( isset($metadata['twitter_hash']) ) ? $metadata['twitter_hash'] : false;
60 if (! $hash)
61 $hash = ( isset($blockdata['twitter_hash'] )) ? $blockdata['twitter_hash'] : false;
62
63 if ($hash && strlen($hash) > 0)
64 {
65 $hashes = array_filter(explode('#', $hash) );
66 $hashes = array_filter($hashes, 'trim');
67 $hash = implode(',', $hashes);
68 }
69 return $hash;
70
71 }
72
73 public function do_meta_boxes($content, $post)
74 {
75 $admin = mbSocial()->admin();
76
77 $metadata = $this->get_block_meta_data($post->ID);
78
79 if (! Install::isPro() )
80 {
81 $gopro = new maxField('generic');
82 $gopro->id = 'pro';
83 $gopro->content = "<div class='forpro overlay'><div>" . $admin->getProMessage() . "</div></div>";
84 $admin->addField($gopro, false,false);
85 }
86
87 $hash = new maxField();
88 $hash->id = 'twitter_hash';
89 $hash->name = 'twitter_hash';
90 $hash->label = __('Twitter Hash Tag(s)', 'mbsocial');
91 $hash->placeholder = '#';
92 $hash->note = __('Seperate multiple tags with a comma', 'mbsocial');
93 $hash->value = isset($metadata['twitter_hash']) ? $metadata['twitter_hash'] : '';
94
95 $admin->addField($hash, 'start', 'end');
96
97 $handle = new maxField();
98 $handle->id = 'twitter_handle';
99 $handle->name = $handle->id;
100 $handle->label = __('Twitter Handle', 'mbsocial');
101 $handle->note = __('Leave empty for global default','mbsocial');
102 $handle->value = isset($metadata['twitter_handle']) ? $metadata['twitter_handle'] : '';
103
104 $admin->addField($handle, 'start', 'end');
105
106 $fields = $admin->display_fields(true, true);
107
108
109 $content['twitter'] = array('title' => __('Twitter', 'mbsocial'),
110 'icon' => 'twitter',
111 'content' => $fields,
112 );
113
114 return $content;
115
116 }
117
118
119
120 public function admin()
121 {
122 $admin = mbSocial()->admin();
123 $blockdata = $this->data[$this->blockname];
124
125
126 ?>
127 <div class='options option-container layout' id='twitterBlock'
128 data-has='{"target":"network_item_active[]","values":["twitter"]}' >
129 <div class='title'><?php _e('Default Twitter Options', 'mbsocial' ); ?> </div>
130 <div class='inside'>
131
132 <?php
133 $handle = new maxField();
134 $handle->id = 'twitter_handle';
135 $handle->name = $handle->id;
136 $handle->label = __('Twitter Handle', 'mbsocial');
137 $handle->value = $this->getValue('twitter_handle') ;
138 $handle->placeholder = '@example';
139 $handle->inputclass = 'medium';
140 $admin->addField($handle, 'start', 'end', false);
141
142
143
144 $hash = new maxField();
145 $hash->id = 'twitter_hash';
146 $hash->name = 'twitter_hash';
147 $hash->label = __('Twitter Default Hash Tag(s)', 'mbsocial');
148 $hash->value = $this->getValue('twitter_hash');
149 $hash->inputclass = 'medium';
150 $hash->placeholder = '#';
151
152 $admin->addField($hash, 'start', 'end', false);
153
154 $admin->display_fields();
155 ?>
156
157 </div> <!-- inside -->
158 </div>
159 <?php
160
161
162 }
163
164 }
165