PluginProbe
Social Share Buttons / 1.30
Social Share Buttons v1.30
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 +93 -22 1.01.30 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()
@@ -221,9 +223,10 @@
221 223 $display = 'shortcode'; // exception
222 224
223 225 $this->display_mode = $display;
224 226
225 - if (! is_admin() )
227 +
228 + if (! is_admin() && is_singular() )
226 229 {
227 230 global $post;
228 231 $this->post_id = $post->ID;
229 232 }
@@ -241,8 +244,9 @@
241 244 // check if on some mobile
242 245 $mobileDetect = new Mobile_Detect;
243 246 $this->is_mobile = $mobileDetect->isMobile();
244 247 $this->is_tablet = $mobileDetect->isTablet();
248 + $this->is_desktop = ($this->is_mobile) ? false : true;
245 249
246 250 $options = isset($data['display'][$hook . '_options']) ? $data['display'][$hook . '_options'] : array();
247 251
248 252 $orientation = isset($options['orientation']) ? $options['orientation'] : 'auto';
@@ -292,8 +296,23 @@
292 296 elseif (isset($meta['general']['active']) && $is_old_active === 0) // backward for 0.9.5 . Can go at some point
293 297 $this->is_showable = false;
294 298 }
295 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 +
296 315 // new method of getting data around
297 316 $w->tell('display/env/hook', $hook);
298 317 $w->tell('display/env/post_id', $this->post_id);
299 318 $w->tell('display/env/is_static', $this->is_static );
@@ -332,8 +351,24 @@
332 351 $result["title"] = __("Error : Block was not there","maxbuttons");
333 352 return $result;
334 353 }
335 354
355 + public function endAjaxRequest($args = array())
356 + {
357 + $defaults = array(
358 + "error" => true, // can have errors and still result true on success
359 + "result" => true,
360 + "body" => "",
361 + "title" => "",
362 + "data" => array(),
363 + );
364 +
365 + $args = wp_parse_args($args, $defaults);
366 +
367 + echo json_encode($args);
368 + die();
369 + }
370 +
336 371 /** Save the collection post data to the database. This will invoke the save functions of the blocks itself to gather, verify and manipulate data */
337 372 public function save($post)
338 373 {
339 374 $data = array();
@@ -605,8 +640,14 @@
605 640 {
606 641 if (! $this->is_showable)
607 642 return;
608 643
644 + /* 1.8 Deprecated. Not included in MB() anymore, using svg method.
645 + if (method_exists(MB(), 'load_library'))
646 + {
647 + MB()->load_library('fontawesome'); // always load lib since change is about 100% this includes FA.
648 + }
649 + */
609 650 maxUtils::startTime('collection-display-' . self::$count);
610 651
611 652 $w = MBSocial()->whistle();
612 653
@@ -632,9 +673,9 @@
632 673 $cache = false;
633 674
634 675 if (! $cache)
635 676 {
636 - $cssParser = $this->getCSSParser();
677 + //$cssParser = $this->getCSSParser();
637 678 $domObj = $this->parse($args);
638 679
639 680 //$css = $this->parseCSS($args);
640 681
@@ -666,8 +707,23 @@
666 707 }
667 708
668 709 }
669 710
711 + public function getDisplayCSS($doc_id = false) // For file output
712 + {
713 + $key = '_parsed_css';
714 +
715 + if ($doc_id)
716 + $key .= '_' . $doc_id;
717 +
718 + $meta = $this->get_meta($key);
719 + if (is_array($meta))
720 + return array_shift($meta);
721 + else
722 + return false;
723 +
724 + }
725 +
670 726 public function displayCSS($css, $args = array() ) // $echo = true, $style_tag = true)
671 727 {
672 728
673 729 $default = array(
@@ -679,8 +735,9 @@
679 735 if ($args['load_type'] == 'inline')
680 736 $args['style_tag'] =true;
681 737
682 738 $output = '';
739 + $css = apply_filters('mbsocial/displaycss/', $css);
683 740
684 741 if ($args["style_tag"])
685 742 $output .= "<style type='text/css'>";
686 743
@@ -693,13 +750,22 @@
693 750 if ($args["load_type"] == 'footer')
694 751 {
695 752 $load_id = 'collection-' . $this->collection_id; // must be unique for unique items, otherwise css won't be output
696 753
754 + $use_file = get_option('maxbuttons_usecssfile', false);
755 + if ($use_file)
756 + {
757 +
758 + wp_enqueue_style('maxbuttons-social-front-' . self::$count, admin_url('admin-ajax.php').'?action=maxbuttons_social_css&id=' . $this->collection_id . '&doc=' . self::$count) ;
759 + $this->update_meta($this->collection_id, '_parsed_css_' . self::$count, $css);
760 + }
761 +
697 762 if (self::$count > 1)
698 763 {
699 764 $load_id .= "-" . self::$count;
700 765 }
701 766
767 +
702 768 do_action('mb-footer',$load_id, $output);
703 769 }
704 770 elseif ($args["load_type"] == 'inline')
705 771 {
@@ -709,9 +775,9 @@
709 775 }
710 776
711 777 }
712 778
713 - public function displayJS($js, $args = array() ) // $echo = true, $style_tag = true)
779 + public function displayJS($js, $args = array() )
714 780 {
715 781 $default = array(
716 782 "echo" => true,
717 783 "js_tag" => true,
@@ -732,12 +798,9 @@
732 798
733 799 if ($args["js_tag"])
734 800 {
735 801 $output .= "<script type='text/javascript'> ";
736 -// $output .= " if (typeof MBcollection" . $this->collection_id . " == 'undefined') { ";
737 -// $output .= " function MBcollection" . $this->collection_id . "() { ";
738 802
739 -
740 803 }
741 804
742 805 foreach($js as $index => $code)
743 806 {
@@ -745,11 +808,9 @@
745 808 }
746 809
747 810 if ($args["js_tag"])
748 811 {
749 - $output .= " // }
750 - // }
751 - // window.onload = MBcollection" . $this->collection_id . "();
812 + $output .= "
752 813 </script> ";
753 814 }
754 815
755 816
@@ -782,9 +843,9 @@
782 843 $collectionObj = new simple_html_dom();
783 844 $collection_id = $this->collection_id;
784 845
785 846 $styleObj = $this->styleObj;
786 - $style_class = ''; //$styleObj->class;
847 + $style_class = '';
787 848 $style_class = $this->orientation;
788 849
789 850 // create container
790 851 if (self::$count > 1)
@@ -790,9 +851,9 @@
790 851 if (self::$count > 1)
791 852 {
792 853 $style_class .= ' doc-' . self::$count;
793 854 }
794 - $node = "<div class='maxsocial maxsocial-" . $collection_id . " $style_class ' data-collection='" . $collection_id . "'>
855 + $node = "<div class='maxsocial maxsocial-" . esc_attr($collection_id) . " $style_class ' data-collection='" . $collection_id . "' data-nonce='" . wp_create_nonce('maxsocial_ajax_action-' . $collection_id) . "''>
795 856 </div>";
796 857 $node = apply_filters("maxbuttons/social/basic-container",$node);
797 858
798 859 $collectionObj->load($node);
@@ -813,20 +874,26 @@
813 874 }
814 875
815 876 $index = 0; // used as unique button_id
816 877
817 -
818 878 maxUtils::startTime('collection-parse-network-' . self::$count);
819 879 foreach($use_networks as $network)
820 880 {
821 - $w->tell('display/parse/network', $network);
822 881 if (! is_object($network))
823 882 {
824 883 continue;
825 884 }
885 + if (! $is_preview)
886 + {
887 + if ( ($this->is_mobile && ! $network->forMobile() ) || $this->is_desktop && ! $network->forDesktop() )
888 + {
889 + continue;
890 + }
891 + }
892 + $w->tell('display/parse/network', $network);
826 893
827 894 $button_args = array('link' => $network->get_url(),
828 - 'preview' => $is_preview,
895 + 'preview' => $is_preview,
829 896 'index' => $index,
830 897 'name' => $network->get('network'),
831 898 'data' => $this->data,
832 899 'collection_count' => self::$count,
@@ -851,12 +918,17 @@
851 918 {
852 919
853 920 // save DOM structure to parser
854 921 $cssParser->loadDom($button);
922 + $css = '';
923 +
924 + $css = $this->parseCSS( array('preview' => $is_preview) );
925 +
855 926 $this->buttons[] = array('item_class' => $button_args['name'],
856 927 'obj' => $button,
857 - 'css' => $this->parseCSS( array('preview' => $is_preview) ),
928 + 'css' => $css,
858 929 );
930 +
859 931 }
860 932
861 933 $index++;
862 934
@@ -863,10 +935,8 @@
863 935 } // network loop.
864 936 maxUtils::endTime('collection-parse-network-' . self::$count);
865 937
866 938 // general parsing
867 -
868 -
869 939 $button_output = '';
870 940 $css = '';
871 941
872 942 foreach($this->buttons as $button_item)
@@ -925,8 +995,9 @@
925 995 }
926 996
927 997 // before the parse let have style have one more go
928 998 $css = $this->styleObj->preParse($css);
999 + $css = apply_filters('mbsocial/parsecss/', $css); // anybody else
929 1000
930 1001 $css = $this->getCSSParser()->parse($css);
931 1002
932 1003 maxUtils::endTime('collection-parseCSS-'. self::$count);