PluginProbe
Social Share Buttons / 1.16
Social Share Buttons v1.16
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.16, at classes/network/mbcustom.php

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