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

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