PluginProbe
Social Share Buttons / 0.9
Social Share Buttons v0.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 0.9, at classes/blocks/twitter_block.php

171 lines 4.4 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 public function parse($domObj, $args = array() )
28 {
29 if ($args['name'] !== 'twitter')
30 return $domObj; // only twitter network items
31
32 $post_id = $this->collection->post_id;
33
34 $metadata = $this->get_block_meta_data($post_id);
35 $blockdata = $this->data[$this->blockname];
36
37 $itemObj = $domObj->find('a', 0);
38 $href = $itemObj->href;
39
40
41
42 $handle = ( isset($metadata['twitter_handle']) ) ? $metadata['twitter_handle'] : false;
43 if (! $handle)
44 $handle = ( isset($blockdata['twitter_handle']) ) ? $blockdata['twitter_handle'] : false;
45
46 $hash = ( isset($metadata['twitter_hash']) ) ? $metadata['twitter_hash'] : false;
47 if (! $hash)
48 $hash = ( isset($blockdata['twitter_hash'] )) ? $blockdata['twitter_hash'] : false;
49
50
51 $network_block = $this->collection->getBlock('networkBlock');
52
53 $sharedata = $network_block->getShareData();
54
55 $url = isset($sharedata['url']) ? $sharedata['url'] : false;
56 $title = isset($sharedata['title']) ? $sharedata['title'] : false;
57
58 if ($url)
59 $href = add_query_arg('url', urlencode($url), $href);
60
61 if ($title)
62 $href = add_query_arg('text', $title, $href);
63
64 if ($handle && strlen($handle) > 0)
65 {
66 $handle = str_replace('@', '', $handle);
67 $href = add_query_arg('via', $handle, $href);
68 }
69
70 if ($hash && strlen($hash) > 0)
71 {
72 $hashes = array_filter(explode('#', $hash) );
73 $hashes = array_filter($hashes, 'trim');
74 $hash = implode(',', $hashes);
75 $href = add_query_arg('hashtags', $hash, $href);
76 }
77
78
79
80 $itemObj->href = $href;
81
82
83 return $domObj;
84 }
85
86 public function do_meta_boxes($content, $post)
87 {
88
89 $admin = mbSocial()->admin();
90
91 $metadata = $this->get_block_meta_data($post->ID);
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 = maxBlocks::getValue('twitter_handle') ;
144 $handle->placeholder = '@example';
145 $handle->inputclass = 'medium';
146 $admin->addField($handle, 'start', 'end');
147
148
149
150 $hash = new maxField();
151 $hash->id = 'twitter_hash';
152 $hash->name = 'twitter_hash';
153 $hash->label = __('Twitter Default Hash Tag(s)', 'mbsocial');
154 $hash->value = maxBlocks::getValue('twitter_hash');
155 $hash->inputclass = 'medium';
156 $hash->placeholder = '#';
157
158 $admin->addField($hash, 'start', 'end');
159
160 $admin->display_fields();
161 ?>
162
163 </div> <!-- inside -->
164 </div>
165 <?php
166
167
168 }
169
170 }
171