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

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