PluginProbe
Social Share Buttons / 1.19
Social Share Buttons v1.19
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/class-collection.php +66 -16 1.11.19 View file →
@@ -1,11 +1,11 @@
1 1 <?php
2 2 namespace MBSocial;
3 3 defined('ABSPATH') or die('No direct access permitted');
4 4
5 -use \maxbuttons\maxUtils as maxUtils;
6 -use \maxbuttons\maxCSSParser as maxCSSParser;
7 -use \simple_html_dom as simple_html_dom;
5 +use \MaxButtons\maxUtils as maxUtils;
6 +use \MaxButtons\maxCSSParser as maxCSSParser;
7 +use \MaxButtons\simple_html_dom as simple_html_dom;
8 8
9 9
10 10 class collection
11 11 {
@@ -31,8 +31,10 @@
31 31 public $is_static = false;
32 32 public $is_post = false; // embedded in a post situation
33 33 public $is_mobile = false;
34 34 public $is_tablet = false;
35 + public $is_desktop = false;
36 +
35 37 public $orientation = 'horizontal';
36 38 public $display_mode = 'hidden';
37 39 public $post_id;
38 40
@@ -57,9 +59,9 @@
57 59 $block = collections::getBlock($block_name);
58 60 if ($block)
59 61 {
60 62 $block->setCollection($this);
61 - $default_data = $block->save_fields($default_data, null ); // force the fields to set a default pos.
63 + $default_data = $block->save_fields($default_data, array() ); // force the fields to set a default pos.
62 64
63 65 $this->blocks[$block_name] = $block;
64 66
65 67 }
@@ -78,9 +80,9 @@
78 80 }
79 81
80 82 if ($collection_id > 0)
81 83 {
82 - $this->set($collection_id);
84 + $this->set($collection_id); // set function loads the block values
83 85 }
84 86 }
85 87 /* Get all buttons that are currently loaded */
86 88 /*public function getLoadedButtons()
@@ -242,8 +244,9 @@
242 244 // check if on some mobile
243 245 $mobileDetect = new Mobile_Detect;
244 246 $this->is_mobile = $mobileDetect->isMobile();
245 247 $this->is_tablet = $mobileDetect->isTablet();
248 + $this->is_desktop = ($this->is_mobile) ? false : true;
246 249
247 250 $options = isset($data['display'][$hook . '_options']) ? $data['display'][$hook . '_options'] : array();
248 251
249 252 $orientation = isset($options['orientation']) ? $options['orientation'] : 'auto';
@@ -293,8 +296,23 @@
293 296 elseif (isset($meta['general']['active']) && $is_old_active === 0) // backward for 0.9.5 . Can go at some point
294 297 $this->is_showable = false;
295 298 }
296 299
300 +
301 + if ( Install::isPRO() ) {
302 + $show_mobile = (isset($data['display']['show_mobile']) && $data['display']['show_mobile'] == 0) ? false: true;
303 + $show_desktop = (isset($data['display']['show_desktop']) && $data['display']['show_desktop'] == 0) ? false: true;
304 +
305 + if ($this->is_mobile && ! $show_mobile)
306 + {
307 + $this->is_showable = false;
308 + }
309 + if ($this->is_desktop && ! $show_desktop)
310 + {
311 + $this->is_showable = false;
312 + }
313 + }
314 +
297 315 // new method of getting data around
298 316 $w->tell('display/env/hook', $hook);
299 317 $w->tell('display/env/post_id', $this->post_id);
300 318 $w->tell('display/env/is_static', $this->is_static );
@@ -606,14 +624,14 @@
606 624 {
607 625 if (! $this->is_showable)
608 626 return;
609 627
610 -
628 + /* 1.8 Deprecated. Not included in MB() anymore, using svg method.
611 629 if (method_exists(MB(), 'load_library'))
612 630 {
613 631 MB()->load_library('fontawesome'); // always load lib since change is about 100% this includes FA.
614 632 }
615 -
633 + */
616 634 maxUtils::startTime('collection-display-' . self::$count);
617 635
618 636 $w = MBSocial()->whistle();
619 637
@@ -639,9 +657,9 @@
639 657 $cache = false;
640 658
641 659 if (! $cache)
642 660 {
643 - $cssParser = $this->getCSSParser();
661 + //$cssParser = $this->getCSSParser();
644 662 $domObj = $this->parse($args);
645 663
646 664 //$css = $this->parseCSS($args);
647 665
@@ -673,8 +691,23 @@
673 691 }
674 692
675 693 }
676 694
695 + public function getDisplayCSS($doc_id = false) // For file output
696 + {
697 + $key = '_parsed_css';
698 +
699 + if ($doc_id)
700 + $key .= '_' . $doc_id;
701 +
702 + $meta = $this->get_meta($key);
703 + if (is_array($meta))
704 + return array_shift($meta);
705 + else
706 + return false;
707 +
708 + }
709 +
677 710 public function displayCSS($css, $args = array() ) // $echo = true, $style_tag = true)
678 711 {
679 712
680 713 $default = array(
@@ -686,8 +719,9 @@
686 719 if ($args['load_type'] == 'inline')
687 720 $args['style_tag'] =true;
688 721
689 722 $output = '';
723 + $css = apply_filters('mbsocial/displaycss/', $css);
690 724
691 725 if ($args["style_tag"])
692 726 $output .= "<style type='text/css'>";
693 727
@@ -700,13 +734,22 @@
700 734 if ($args["load_type"] == 'footer')
701 735 {
702 736 $load_id = 'collection-' . $this->collection_id; // must be unique for unique items, otherwise css won't be output
703 737
738 + $use_file = get_option('maxbuttons_usecssfile', false);
739 + if ($use_file)
740 + {
741 +
742 + wp_enqueue_style('maxbuttons-social-front-' . self::$count, admin_url('admin-ajax.php').'?action=maxbuttons_social_css&id=' . $this->collection_id . '&doc=' . self::$count) ;
743 + $this->update_meta($this->collection_id, '_parsed_css_' . self::$count, $css);
744 + }
745 +
704 746 if (self::$count > 1)
705 747 {
706 748 $load_id .= "-" . self::$count;
707 749 }
708 750
751 +
709 752 do_action('mb-footer',$load_id, $output);
710 753 }
711 754 elseif ($args["load_type"] == 'inline')
712 755 {
@@ -739,12 +782,9 @@
739 782
740 783 if ($args["js_tag"])
741 784 {
742 785 $output .= "<script type='text/javascript'> ";
743 -// $output .= " if (typeof MBcollection" . $this->collection_id . " == 'undefined') { ";
744 -// $output .= " function MBcollection" . $this->collection_id . "() { ";
745 786
746 -
747 787 }
748 788
749 789 foreach($js as $index => $code)
750 790 {
@@ -820,17 +860,23 @@
820 860 }
821 861
822 862 $index = 0; // used as unique button_id
823 863
824 -
825 864 maxUtils::startTime('collection-parse-network-' . self::$count);
826 865 foreach($use_networks as $network)
827 866 {
828 - $w->tell('display/parse/network', $network);
829 867 if (! is_object($network))
830 868 {
831 869 continue;
832 870 }
871 + if (! $is_preview)
872 + {
873 + if ( ($this->is_mobile && ! $network->forMobile() ) || $this->is_desktop && ! $network->forDesktop() )
874 + {
875 + continue;
876 + }
877 + }
878 + $w->tell('display/parse/network', $network);
833 879
834 880 $button_args = array('link' => $network->get_url(),
835 881 'preview' => $is_preview,
836 882 'index' => $index,
@@ -858,12 +904,17 @@
858 904 {
859 905
860 906 // save DOM structure to parser
861 907 $cssParser->loadDom($button);
908 + $css = '';
909 +
910 + $css = $this->parseCSS( array('preview' => $is_preview) );
911 +
862 912 $this->buttons[] = array('item_class' => $button_args['name'],
863 913 'obj' => $button,
864 - 'css' => $this->parseCSS( array('preview' => $is_preview) ),
914 + 'css' => $css,
865 915 );
916 +
866 917 }
867 918
868 919 $index++;
869 920
@@ -870,10 +921,8 @@
870 921 } // network loop.
871 922 maxUtils::endTime('collection-parse-network-' . self::$count);
872 923
873 924 // general parsing
874 -
875 -
876 925 $button_output = '';
877 926 $css = '';
878 927
879 928 foreach($this->buttons as $button_item)
@@ -932,8 +981,9 @@
932 981 }
933 982
934 983 // before the parse let have style have one more go
935 984 $css = $this->styleObj->preParse($css);
985 + $css = apply_filters('mbsocial/parsecss/', $css); // anybody else
936 986
937 987 $css = $this->getCSSParser()->parse($css);
938 988
939 989 maxUtils::endTime('collection-parseCSS-'. self::$count);