| @@ -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 | - | |
| 611 | - /*if (method_exists(MB(), 'load_library')) | |
| 628 | + /* 1.8 Deprecated. Not included in MB() anymore, using svg method. | |
| 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 | - } */ | |
| 615 | - | |
| 632 | + } | |
| 633 | + */ | |
| 616 | 634 | maxUtils::startTime('collection-display-' . self::$count); |
| 617 | 635 | |
| 618 | 636 | $w = MBSocial()->whistle(); |
| 619 | 637 | |
| @@ -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 | { |
| @@ -804,8 +844,9 @@ | ||
| 804 | 844 | |
| 805 | 845 | $collectionObj->load($node); |
| 806 | 846 | |
| 807 | 847 | $active = ( isset($this->data['network']['network_active']) && is_array($this->data['network']['network_active']) ) ? $this->data['network']['network_active'] : array(); |
| 848 | + | |
| 808 | 849 | if (count($active) == 0 && $args['preview'] == true) |
| 809 | 850 | { |
| 810 | 851 | $networks = $admin->get_default_networks(); |
| 811 | 852 | $use_networks = $networks['unselected']; |
| @@ -826,8 +867,15 @@ | ||
| 826 | 867 | if (! is_object($network)) |
| 827 | 868 | { |
| 828 | 869 | continue; |
| 829 | 870 | } |
| 871 | + if (! $is_preview) | |
| 872 | + { | |
| 873 | + if ( ($this->is_mobile && ! $network->forMobile() ) || $this->is_desktop && ! $network->forDesktop() ) | |
| 874 | + { | |
| 875 | + continue; | |
| 876 | + } | |
| 877 | + } | |
| 830 | 878 | $w->tell('display/parse/network', $network); |
| 831 | 879 | |
| 832 | 880 | $button_args = array('link' => $network->get_url(), |
| 833 | 881 | 'preview' => $is_preview, |
| @@ -936,8 +984,9 @@ | ||
| 936 | 984 | $css = $this->styleObj->preParse($css); |
| 937 | 985 | $css = apply_filters('mbsocial/parsecss/', $css); // anybody else |
| 938 | 986 | |
| 939 | 987 | $css = $this->getCSSParser()->parse($css); |
| 988 | + | |
| 940 | 989 | maxUtils::endTime('collection-parseCSS-'. self::$count); |
| 941 | 990 | return $css; |
| 942 | 991 | } |
| 943 | 992 | |