PluginProbe
Social Share Buttons / 1.6
Social Share Buttons v1.6
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 / network / mbcustom.php

mbcustom.php in Social Share Buttons 1.6, at classes/network/mbcustom.php

172 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 use MaxButtons\maxButton as maxButton;
6
7 class MBCustomNetwork extends MBnetwork
8 {
9
10 protected $network = 'maxbutton';
11 // protected $icon;
12 protected $icon_type = 'png';
13 protected $priority = 'readmore';
14 protected $color = '#88C5C2';
15
16 protected $popup = false;
17
18 protected $last_index = -1;
19 protected $currentNetwork = null;
20
21 protected $css = array();
22
23 protected $is_limitedpro = true;
24 protected $is_editable = false;
25 protected $is_custom = true; // maybe should be gone.
26
27
28 public function __construct()
29 {
30 $this->icon = MBSocial()->get_plugin_url() . 'images/mb-blue-network.png';
31 $this->label = __('No config', 'mbsocial');
32 parent::__construct();
33
34 $w = MBSocial()->whistle();
35 $w->listen('collection/new', array($this, 'resetIndex'), 'tell');
36 add_filter('mbsocial/parsecss/', array($this, 'fixIconCSS'));
37
38 }
39
40 /** Reset the count index when a new collection is put up */
41 public function resetIndex()
42 {
43 $this->last_index = -1;
44 }
45
46 public function get($name)
47 {
48
49 if (! is_null($this->currentNetwork))
50 {
51 return $this->currentNetwork->get($name);
52 }
53 else {
54 return parent::get($name);
55 }
56 }
57
58
59
60 public function is_popup()
61 {
62 if (! is_null($this->currentNetwork))
63 {
64 return $this->currentNetwork->is_popup();
65 }
66 else {
67 return parent::is_popup();
68 }
69 }
70
71 public function createButton($args = array())
72 {
73 $defaults = array('link' => 'javascript:void(0)',
74 'preview' => false,
75 'index' => -1,
76 'name' => '',
77 'data' => array(),
78 );
79
80 $this->currentNetwork = null;
81
82 $args = wp_parse_args($args, $defaults);
83 $data = $args['data'];
84
85 if (isset($data['network']) && isset($data['network']['mbcustom']))
86 {
87 $customs = $data['network']['mbcustom'];
88
89 $this->last_index++;
90 $settings = isset($customs[$this->last_index]) ? $customs[$this->last_index] : false;
91
92 $button_id = isset($settings['button_id']) ? $settings['button_id'] : false;
93
94 $mode = 'normal';
95 if ($args['preview'])
96 $mode = 'preview';
97
98 if($button_id > 0)
99 {
100 $button_args = array(
101 'echo' => false,
102 'load_css' => 'inline',
103 'compile' => true,
104 'mode' => $mode,
105 );
106
107 $use = isset($settings['use_network']) ? $settings['use_network'] : false;
108 $network = isset($settings['network']) ? $settings['network'] : false;
109 $url = isset($settings['url']) ? $settings['url'] : false;
110 $text = isset($settings['text']) ? $settings['text'] : false;
111
112 $button = MB()->getClass("button");
113 $button->set($button_id);
114
115 if ($url != '')
116 {
117 $button->setData('basic', array('url' => $url));
118 }
119 if ($text != '')
120 {
121 $button->setData('text', array('text' => $text));
122 }
123
124 $button_html = "<span class='mb-item item-" . $args['index'] . "'>";
125 $button_html .= $button->display($button_args);
126 $button_html .= "</span>";
127 $buttonObj = str_get_html($button_html);
128
129 // fix URL *after* button output since MB filters {url} type of URL's needed for ApplyVars
130 if ($use && $network)
131 {
132 $networkObj = MBSocial()->networks()->get($network);
133 $this->currentNetwork = $networkObj;
134 $url = $networkObj->get_url();
135
136 $itemObj = $buttonObj->find('a', 0);
137 $itemObj->href = $url;
138
139 }
140
141 return $buttonObj;
142
143 }
144 }
145
146 if ($args['preview'])
147 {
148 return parent::createButton($args);
149 }
150
151 return false;
152 }
153
154 public function fixIconCSS($css)
155 {
156 $w = MBSocial()->whistle();
157 $network = $w->ask('display/parse/network');
158
159 $classname = get_class($network); // hacky
160 if (strpos(strtolower($classname), 'mbcustom') !== false )
161 {
162 if (isset($css['mb-icon']))
163 {
164 unset($css['mb-icon']); // overrides mb icons, should not happen
165 }
166 }
167
168 return $css;
169
170 }
171 }
172