| @@ -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 ); |
| @@ -333,8 +351,24 @@ | ||
| 333 | 351 | $result["title"] = __("Error : Block was not there","maxbuttons"); |
| 334 | 352 | return $result; |
| 335 | 353 | } |
| 336 | 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 | + | |
| 337 | 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 */ |
| 338 | 372 | public function save($post) |
| 339 | 373 | { |
| 340 | 374 | $data = array(); |
| @@ -606,14 +640,14 @@ | ||
| 606 | 640 | { |
| 607 | 641 | if (! $this->is_showable) |
| 608 | 642 | return; |
| 609 | 643 | |
| 610 | - | |
| 611 | - /*if (method_exists(MB(), 'load_library')) | |
| 644 | + /* 1.8 Deprecated. Not included in MB() anymore, using svg method. | |
| 645 | + if (method_exists(MB(), 'load_library')) | |
| 612 | 646 | { |
| 613 | 647 | MB()->load_library('fontawesome'); // always load lib since change is about 100% this includes FA. |
| 614 | - } */ | |
| 615 | - | |
| 648 | + } | |
| 649 | + */ | |
| 616 | 650 | maxUtils::startTime('collection-display-' . self::$count); |
| 617 | 651 | |
| 618 | 652 | $w = MBSocial()->whistle(); |
| 619 | 653 | |
| @@ -673,8 +707,23 @@ | ||
| 673 | 707 | } |
| 674 | 708 | |
| 675 | 709 | } |
| 676 | 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 | + | |
| 677 | 726 | public function displayCSS($css, $args = array() ) // $echo = true, $style_tag = true) |
| 678 | 727 | { |
| 679 | 728 | |
| 680 | 729 | $default = array( |
| @@ -686,8 +735,9 @@ | ||
| 686 | 735 | if ($args['load_type'] == 'inline') |
| 687 | 736 | $args['style_tag'] =true; |
| 688 | 737 | |
| 689 | 738 | $output = ''; |
| 739 | + $css = apply_filters('mbsocial/displaycss/', $css); | |
| 690 | 740 | |
| 691 | 741 | if ($args["style_tag"]) |
| 692 | 742 | $output .= "<style type='text/css'>"; |
| 693 | 743 | |
| @@ -700,13 +750,22 @@ | ||
| 700 | 750 | if ($args["load_type"] == 'footer') |
| 701 | 751 | { |
| 702 | 752 | $load_id = 'collection-' . $this->collection_id; // must be unique for unique items, otherwise css won't be output |
| 703 | 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 | + | |
| 704 | 762 | if (self::$count > 1) |
| 705 | 763 | { |
| 706 | 764 | $load_id .= "-" . self::$count; |
| 707 | 765 | } |
| 708 | 766 | |
| 767 | + | |
| 709 | 768 | do_action('mb-footer',$load_id, $output); |
| 710 | 769 | } |
| 711 | 770 | elseif ($args["load_type"] == 'inline') |
| 712 | 771 | { |
| @@ -716,9 +775,9 @@ | ||
| 716 | 775 | } |
| 717 | 776 | |
| 718 | 777 | } |
| 719 | 778 | |
| 720 | - public function displayJS($js, $args = array() ) // $echo = true, $style_tag = true) | |
| 779 | + public function displayJS($js, $args = array() ) | |
| 721 | 780 | { |
| 722 | 781 | $default = array( |
| 723 | 782 | "echo" => true, |
| 724 | 783 | "js_tag" => true, |
| @@ -739,12 +798,9 @@ | ||
| 739 | 798 | |
| 740 | 799 | if ($args["js_tag"]) |
| 741 | 800 | { |
| 742 | 801 | $output .= "<script type='text/javascript'> "; |
| 743 | -// $output .= " if (typeof MBcollection" . $this->collection_id . " == 'undefined') { "; | |
| 744 | -// $output .= " function MBcollection" . $this->collection_id . "() { "; | |
| 745 | 802 | |
| 746 | - | |
| 747 | 803 | } |
| 748 | 804 | |
| 749 | 805 | foreach($js as $index => $code) |
| 750 | 806 | { |
| @@ -752,11 +808,9 @@ | ||
| 752 | 808 | } |
| 753 | 809 | |
| 754 | 810 | if ($args["js_tag"]) |
| 755 | 811 | { |
| 756 | - $output .= " // } | |
| 757 | - // } | |
| 758 | - // window.onload = MBcollection" . $this->collection_id . "(); | |
| 812 | + $output .= " | |
| 759 | 813 | </script> "; |
| 760 | 814 | } |
| 761 | 815 | |
| 762 | 816 | |
| @@ -789,9 +843,9 @@ | ||
| 789 | 843 | $collectionObj = new simple_html_dom(); |
| 790 | 844 | $collection_id = $this->collection_id; |
| 791 | 845 | |
| 792 | 846 | $styleObj = $this->styleObj; |
| 793 | - $style_class = ''; //$styleObj->class; | |
| 847 | + $style_class = ''; | |
| 794 | 848 | $style_class = $this->orientation; |
| 795 | 849 | |
| 796 | 850 | // create container |
| 797 | 851 | if (self::$count > 1) |
| @@ -797,9 +851,9 @@ | ||
| 797 | 851 | if (self::$count > 1) |
| 798 | 852 | { |
| 799 | 853 | $style_class .= ' doc-' . self::$count; |
| 800 | 854 | } |
| 801 | - $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) . "''> | |
| 802 | 856 | </div>"; |
| 803 | 857 | $node = apply_filters("maxbuttons/social/basic-container",$node); |
| 804 | 858 | |
| 805 | 859 | $collectionObj->load($node); |
| @@ -804,8 +858,9 @@ | ||
| 804 | 858 | |
| 805 | 859 | $collectionObj->load($node); |
| 806 | 860 | |
| 807 | 861 | $active = ( isset($this->data['network']['network_active']) && is_array($this->data['network']['network_active']) ) ? $this->data['network']['network_active'] : array(); |
| 862 | + | |
| 808 | 863 | if (count($active) == 0 && $args['preview'] == true) |
| 809 | 864 | { |
| 810 | 865 | $networks = $admin->get_default_networks(); |
| 811 | 866 | $use_networks = $networks['unselected']; |
| @@ -826,12 +881,19 @@ | ||
| 826 | 881 | if (! is_object($network)) |
| 827 | 882 | { |
| 828 | 883 | continue; |
| 829 | 884 | } |
| 885 | + if (! $is_preview) | |
| 886 | + { | |
| 887 | + if ( ($this->is_mobile && ! $network->forMobile() ) || $this->is_desktop && ! $network->forDesktop() ) | |
| 888 | + { | |
| 889 | + continue; | |
| 890 | + } | |
| 891 | + } | |
| 830 | 892 | $w->tell('display/parse/network', $network); |
| 831 | 893 | |
| 832 | 894 | $button_args = array('link' => $network->get_url(), |
| 833 | - 'preview' => $is_preview, | |
| 895 | + 'preview' => $is_preview, | |
| 834 | 896 | 'index' => $index, |
| 835 | 897 | 'name' => $network->get('network'), |
| 836 | 898 | 'data' => $this->data, |
| 837 | 899 | 'collection_count' => self::$count, |
| @@ -936,8 +998,9 @@ | ||
| 936 | 998 | $css = $this->styleObj->preParse($css); |
| 937 | 999 | $css = apply_filters('mbsocial/parsecss/', $css); // anybody else |
| 938 | 1000 | |
| 939 | 1001 | $css = $this->getCSSParser()->parse($css); |
| 1002 | + | |
| 940 | 1003 | maxUtils::endTime('collection-parseCSS-'. self::$count); |
| 941 | 1004 | return $css; |
| 942 | 1005 | } |
| 943 | 1006 | |