PluginProbe
Social Share Buttons / 1.1.2
Social Share Buttons v1.1.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
← All changes | classes/blocks/network-block.php +105 -94 trunk1.1.2 View file →
@@ -4,9 +4,9 @@
4 4
5 5 $collectionBlock["network"] = array('order' => 10,
6 6 'class' => "networkBlock");
7 7
8 -use \MaxButtons\simple_html_dom as simple_html_dom;
8 +use \simple_html_dom as simple_html_dom;
9 9 use \MaxButtons\maxField as maxField;
10 10 use \MaxButtons\maxBlocks as maxBlocks;
11 11 use \MaxButtons\maxInstall as maxInstall;
12 12
@@ -39,9 +39,9 @@
39 39 $blockdata = $this->data[$this->blockname];
40 40 $admin = MBSocial()->admin();
41 41
42 42 $network = $w->ask('display/parse/network');
43 - $is_popup = $network->is_popup();
43 + $popup = $network->is_popup();
44 44
45 45 $itemObj = $domObj->find('a', 0);
46 46
47 47 $url = $itemObj->href;
@@ -46,9 +46,9 @@
46 46
47 47 $url = $itemObj->href;
48 48
49 49 // replace all {} variables with data
50 - $url = $admin->applyVars($url);
50 + $url = $this->applyVars($url, $args);
51 51
52 52 // remove empty query parts from the URL
53 53 $parts = parse_url($url);
54 54 if(isset($parts['query']) > 0)
@@ -62,9 +62,9 @@
62 62 }
63 63
64 64 $itemObj->href = $url;
65 65
66 - if ($is_popup)
66 + if ($popup)
67 67 {
68 68 $tag = 'data-popup';
69 69 $dimensions = $network->get('popup_dimensions');
70 70 $dimensions = array('width' => $dimensions[0], 'height' => $dimensions[1]);
@@ -72,8 +72,9 @@
72 72 }
73 73 else {
74 74 if (! $network->get('forcesamewindow'))
75 75 $itemObj->target = "_blank";
76 +
76 77 }
77 78
78 79 $itemObj->rel = 'noopener nofollow';
79 80
@@ -95,9 +96,8 @@
95 96
96 97
97 98 public function renderIcon($network = false)
98 99 {
99 -
100 100 $w= MBSocial()->whistle();
101 101
102 102 if (! $network)
103 103 $network = $w->ask('display/parse/network');
@@ -104,31 +104,53 @@
104 104
105 105 $icon = $network->get('icon');
106 106 $icon_type = $network->get('icon_type');
107 107
108 + /*$fa5_present = method_exists('maxInstall', 'searchNewFa');
109 + var_dump($fa5_present);
110 + var_dump($icon_type);
111 + $fa5_present = true;
112 + if ($icon_type == 'fa' && $fa5_present)
113 + {
114 + $conversion_path = MB()->get_plugin_path() . '/assets/libraries/font-awesome-5/shims.json';
115 + $conversion_array = json_decode(file_get_contents($conversion_path), ARRAY_A);
116 +
117 + $icon = str_replace('fa-', '', $icon);
118 + $icon_type = '';
119 +
120 + $icon = maxInstall::searchNewFA($icon, $conversion_array);
121 + var_dump($icon);
122 + } */
123 +
108 124 $network_name = $network->get_nice_name();
125 + $layoutBlock = $this->collection->getBlock('layoutBlock');
109 126
110 - $icon_size = false;
111 - if ($this->collection)
127 + $faUtils = FAUtils::getInstance();
128 +
129 + switch($icon_type)
112 130 {
113 - $layoutBlock = $this->collection->getBlock('layoutBlock');
114 - $icon_size = $layoutBlock->getValue('font_icon_size');
115 - }
131 + case 'fa': // FA5
132 + case 'fab':
133 + case 'fas':
134 + case 'far':
135 + $icon_size = $layoutBlock->getValue('font_icon_size');
136 + $svg = $faUtils->getFASVG(array('icon' => trim($icon_type) . ' ' . trim($icon), 'title' => $network_name, 'size' => $icon_size));
137 + $output = "<span class='mb-icon'>$svg</span>";
138 + break;
139 + case 'nucleo':
140 + $output = "<span class='mb-icon'><i class='" . $icon_type . " " . $icon . "' title='" . $network_name . "' > </i></span>";
141 + break;
142 + case 'svg':
143 + case 'png':
144 + $output = "<span class='mb-icon " . $icon_type . "'><img src='" . $icon . "' alt='" . $network_name . "'></span>";
145 + break;
116 146
117 - $args = array('icon' => $icon,
118 - 'icon_type' => $icon_type,
119 - 'title' => $network_name,
120 - 'icon_size' => $icon_size
121 - );
122 -
123 - if ($icon_type == 'image')
124 - {
125 - $args['image_id'] = $network->get('icon_image_id');
126 - $args['image_size'] = $network->get('icon_image_size');
127 - $args['image_url'] = $network->get('icon_image_url');
147 + default:
148 + $output = '';
149 + break;
128 150 }
129 151
130 - return MBSocial()->admin()->renderIcon($args);
152 + return apply_filters('display/render/icon', $output, $this, $network);
131 153
132 154 }
133 155
134 156 /** Get data from the page to use in sharing. Like page title, url and image
@@ -156,9 +178,8 @@
156 178 $options = $this->data['display'][$hook . '_options'];
157 179
158 180 $share_setting = isset($options['share_setting']) ? $options['share_setting'] : 'auto';
159 181 $custom = isset($options['share_custom_url']) ? $options['share_custom_url'] : '';
160 - $custom_title = isset($options['share_custom_title']) ? $options['share_custom_title'] : '';
161 182 }
162 183 switch($share_setting)
163 184 {
164 185 case "home":
@@ -167,9 +188,8 @@
167 188 $img = $this->getImage(null, true);
168 189 break;
169 190 case "custom-url";
170 191 $url = $custom;
171 - $title = $custom_title;
172 192 $img = $this->getImage();
173 193 break;
174 194 case "current-post":
175 195 $url = get_permalink();
@@ -286,10 +306,56 @@
286 306 else
287 307 return '';
288 308 }
289 309
310 + public function applyVars($string)
311 + {
312 + //$vars = $this->getShareData();
313 + $w = MBSocial()->whistle();
290 314
315 + preg_match_all('/\{(.*?)\}/im', $string, $matches);
316 + //$vars = (isset($vars[0]) && count($vars[0]) > 0) ? $vars[0] : array();
291 317
318 + if (count($matches) == 0)
319 + return $string;
320 +
321 + $vars = $matches[0]; // i.e. {url}
322 + $clean_vars = $matches[1]; // i.e. url
323 +
324 + for($i = 0; $i < count($vars); $i++)
325 + {
326 + $var = $vars[$i];
327 + $clean_var = $clean_vars[$i];
328 +
329 + if (strpos($string, $var) !== false)
330 + {
331 + $val = $w->ask('display/vars/' . $clean_var);
332 + $string = str_replace($var, $val, $string);
333 + }
334 +
335 + }
336 +
337 +
338 +
339 + /*if (isset($vars["url"]))
340 + $string = str_replace("{url}", urlencode(esc_url($vars["url"])), $string);
341 + if (isset($vars["count"]))
342 + {
343 + $count = $this->formatCount($vars["count"]);
344 + $string = str_replace("{count}", "<span class='share_count'>" . $count . "</span>", $string);
345 + $string = str_replace("{c}", "<span class='share_count'>" . $count . "</span>", $string);
346 + }
347 + if (isset($vars["title"]))
348 + $string = str_replace("{title}", $vars["title"], $string);
349 + if (isset($vars["network_name"]))
350 + $string = str_replace("{network_name}", $vars["network_name"], $string);
351 +
352 + if (isset($vars["img"]))
353 + $string = str_replace("{img}", $vars["img"], $string);
354 +*/
355 + return $string;
356 + }
357 +
292 358 function save_fields($data, $post)
293 359 {
294 360 $data = parent::save_fields($data, $post);
295 361
@@ -297,14 +363,9 @@
297 363
298 364 $button = MB()->getClass("button");
299 365 $network_active = isset($post['network_item_active']) ? $post['network_item_active'] : array();
300 366
301 - // Dummy is to ensure conditionals work on network_active.
302 - $index = array_search('dummy', $network_active);
303 - if ($index !== false)
304 - unset($network_active[$index]);
305 367
306 -
307 368 //mbcustom
308 369 $mbcustom = isset($post['mbcustom_id']) ? $post['mbcustom_id'] : array();
309 370 $data[$this->blockname]['mbcustom'] = array();
310 371
@@ -333,17 +394,14 @@
333 394
334 395 }
335 396 }
336 397
398 + //echo "<PRE>"; print_R($post); print_R($data[$this->blockname]['mbcustom'] ); echo "</PRE>";
337 399 // new user, give default networks
338 400 $collection_id = $this->collection->getID();
339 -
340 -
341 401 if (count($network_active) == 0 && $collection_id == 0)
342 - $network_active = array('facebook', 'twitter'); // default options
402 + $network_active = array('facebook', 'twitter', 'linkedin'); // default options
343 403
344 -
345 -
346 404 $data[$this->blockname]["network_active"] = $network_active;
347 405 return $data;
348 406 }
349 407
@@ -383,35 +441,17 @@
383 441 $admin = mbSocial()->admin();
384 442 $blockdata = $this->data[$this->blockname];
385 443
386 444 $active_networks = isset($blockdata['network_active']) ? $blockdata['network_active'] : array();
445 +
387 446 $networks = $admin->get_networks($active_networks);
447 +
388 448 $styleObj = $this->collection->getStyle();
389 -
390 -/*
391 - No clue what this is doing here.
392 -foreach ($networks as $type => $data)
393 - {
394 - echo $type; var_dump($data);
395 - foreach ($data as $network_id => $network)
396 - {
397 - $label = $network->get_nice_name();
398 - $icon = $network->get('icon');
399 - $icon_type = $network->get('icon_type');
400 - $color = $network->get('color');
401 -
402 - $field = new maxField('switch');
403 - $field->id = $network->get('name');
404 - $field->label = $label;
405 -
406 - $admin->addField($field, 'start', 'end');
407 - }
408 - } */
409 449 ?>
410 450 <div class='help-side'>
411 451 <h3><?php _e('Social Networks','mbsocial'); ?></h3>
412 - <p><?php printf(__('%s Drag and drop %s the networks you want to use into the \'active\' box. You can find additional networks under the \'more networks\' tab.', 'mbsocial'), '<strong>', '</strong>'); ?></p>
413 - <p><?php __('Hold the mouse pointer over the network icon to see the network\'s name', 'mbsocial'); ?></p>
452 + <p>Drag and drop the networks you want to use into the 'active' box. You can find additional networks under the 'more networks' tab.</p>
453 + <p>Hold the mouse pointer over the network icon to see the network's name</p>
414 454 <p>The <strong>Share Page</strong> networks will share your website's URL to other networks. </p>
415 455 <p>The <strong>Share Profile</strong> networks will link from the website to your social accounts</p>
416 456 </div>
417 457 <div class='options networks option-container' id='networkBlock' data-refresh='previewBlock'>
@@ -425,9 +465,8 @@
425 465 $admin->addField($field_obj);
426 466 $admin->addUpdate($field_obj);
427 467 $admin->display_fields();
428 468
429 -
430 469 ?>
431 470 <div class='title'><?php _e('Social Networks','mbsocial') ?> </div>
432 471 <div class='inside'>
433 472 <div class='option active_network'>
@@ -434,10 +473,8 @@
434 473 <label><?php _e('Active','mbsocial'); ?></label>
435 474 <div class='drag-area input' data-area='active'>
436 475 <span class="updatables hidden">input[name="network_active"], input[name="network_item_active"]</span>
437 476
438 - <input type="hidden" name="network_item_active[]" value="dummy">
439 -
440 477 <?php if (isset($networks['selected'])): foreach($networks['selected'] as $index => $network): ?>
441 478
442 479 <?php
443 480 $args = array();
@@ -446,12 +483,9 @@
446 483
447 484 $this->printNetwork($index, $network, $args );
448 485
449 486 ?>
450 - <?php endforeach;
451 - else: ?>
452 - <?php
453 - endif; ?>
487 + <?php endforeach; endif; ?>
454 488 </div>
455 489 </div>
456 490
457 491
@@ -478,20 +512,10 @@
478 512
479 513 <?php endforeach; endif; ?>
480 514 </div>
481 515
482 - <?php if (Install::IsPro()): ?>
483 - <p><?php printf(__("Need another network? Check out the %s Network settings %s","mbsocial"),
484 - '<a href="' . admin_url('admin.php') . '?page=maxbuttons-social-settings" target="_blank">', '</a>');
485 - ?>
486 -
487 - </p>
488 - <?php else : ?>
489 - <p>
490 - <?php printf(__("More Networks or Customization needed? %s Check out our PRO offer %s ", 'mbsocial'),
491 - '<a href="https://maxbuttons.com/wordpress-share-buttons/#compare" target="_blank">', '</a>'); ?>
492 - </p>
493 - <?php endif; ?>
516 + <p><?php _e("Need another network?","mbsocial"); ?>
517 + <a href='mailto:support@maxfoundry.com'><?php _e('Email us','mbsocial'); ?> </a></p>
494 518 </span>
495 519
496 520 </div>
497 521 </div> <!-- option -->
@@ -498,9 +522,8 @@
498 522
499 523 <?php
500 524 // find caps of Networks
501 525 $networks = mbSocial()->networks()->get();
502 -
503 526 $nw_share = array();
504 527 $nw_profile = array();
505 528 foreach($networks as $nw)
506 529 {
@@ -535,9 +558,9 @@
535 558 </p>
536 559
537 560
538 561 <?php if (Install::isPro()): ?>
539 - <p><?php _e('The MaxButtons option lets you add a MaxButton and configure it.','mbsocial') ?></p>
562 + <p><?php _e('The MaxButtons option lets you a MaxButton and configure it.','mbsocial') ?></p>
540 563 <?php endif; ?>
541 564 </div>
542 565
543 566 <div class='hidden mbcustom-helper'>
@@ -568,23 +591,9 @@
568 591 $w = mbSocial()->whistle();
569 592 //$w->tell('display/parse/network', $network);
570 593 $network_name = $network->get('network');
571 594 $label = $network->get_nice_name();
572 -
573 - $icon = $network->get('icon');
574 - $icon_type = $network->get('icon_type');
575 - $color = $network->get('color');
576 -
577 - $icon_args = array('icon' => $icon, 'icon_type' => $icon_type);
578 -
579 - if ($icon_type == 'image')
580 - {
581 - $icon_args['image_id'] = $network->get('icon_image_id');
582 - $icon_args['image_size'] = $network->get('icon_image_size');
583 - $icon_args['image_url'] = $network->get('icon_image_url');
584 - }
585 -
586 - $icon_output = MBSocial()->admin()->renderIcon($icon_args);
595 + $icon_output = $this->renderIcon($network);
587 596 $is_share_icon = $network->is_share_icon();
588 597 $is_social_share = $network->is_social_share();
589 598
590 599 $input = $args['input'];
@@ -592,9 +601,9 @@
592 601 $classes = $network_name;
593 602 ?>
594 603
595 604
596 - <span style='background-color: <?php echo $color ?>' class="item <?php echo $classes ?> " title="<?php echo $label ?>">
605 + <span class="item <?php echo $classes ?> " title="<?php echo $label ?>">
597 606 <?php echo $icon_output ?>
598 607
599 608 <?php
600 609 /* if ($is_share_icon)
@@ -727,9 +736,11 @@
727 736
728 737 protected function printMBCustomButton()
729 738 {
730 739 ?>
731 - <span class='config_button'><button type='button' class='button-primary' ><?php _e('Config', 'mbsocial'); ?></button></span>
740 + <span class='config_button'><button type='button' class='button-primary' data-parent='#maxbuttons' data-callback='window.maxFoundry.maxSocial.selectMBCustomButton' data-nonce="<?php echo wp_create_nonce('maxajax'); ?>"><?php _e('Config', 'mbsocial'); ?></button></span>
732 741 <?php
733 742 }
734 743
735 744 }
745 +
746 +?>