| 1 |  |  | <?php # -*- coding: utf-8 -*- | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | declare(strict_types=1); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  | namespace MultisiteGlobalMedia; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use MultisiteGlobalMedia\Rest\Rest; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use MultisiteGlobalMedia\WooCommerce; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | class Plugin | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |      * @var string $rootFile | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |     private $rootFile; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |      * Plugin constructor. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |      * @param $file | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |     public function __construct(string $file) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |         $this->rootFile = $file; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |      * Integration the WordPress environment. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |     public function onLoad() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |         $pluginProperties = new PluginProperties($this->rootFile); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |         $site = new Site(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |         $singleSwitcher = new SingleSwitcher(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |         $assets = new Assets($pluginProperties); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |         $attachment = new Attachment($site, $singleSwitcher); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |         $thumbnail = new Thumbnail($site, $singleSwitcher); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |         $rest = new Rest($site); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |         add_action('admin_enqueue_scripts', [$assets, 'enqueueScripts']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |         add_action('admin_enqueue_scripts', [$assets, 'enqueueStyles']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |         add_action('wp_ajax_query-attachments', [$attachment, 'ajaxQueryAttachments'], 0); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |         add_action('wp_ajax_get-attachment', [$attachment, 'ajaxGetAttachment'], 0); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |         add_action('wp_ajax_send-attachment-to-editor', [$attachment, 'ajaxSendAttachmentToEditor'], 0); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |         add_filter('wp_get_attachment_image_src', [$attachment, 'attachmentImageSrc'], 99, 4); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |         add_filter('media_view_strings', [$attachment, 'mediaStrings']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |         remove_filter('the_content', 'wp_make_content_images_responsive'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |         add_filter('the_content', [$attachment, 'makeContentImagesResponsive']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |         add_action('save_post', [$thumbnail, 'saveThumbnailMeta'], 99); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |         add_action('wp_ajax_get-post-thumbnail-html', [$thumbnail, 'ajaxGetPostThumbnailHtml'], 99); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |         add_filter('admin_post_thumbnail_html', [$thumbnail, 'adminPostThumbnailHtml'], 99, 3); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |         add_filter('post_thumbnail_html', [$thumbnail, 'postThumbnailHtml'], 99, 5); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |         add_filter('register_post_type_args', [$rest, 'registerPostTypeArgs'], 10, 2); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |         add_filter('rest_request_after_callbacks', [$rest, 'restRequestAfterCallbacks'], 10, 3); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |          | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |         if (\function_exists('wc')) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |             $this->wcBootstrap($site, $singleSwitcher); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |         if (\function_exists('acf')) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |             $this->acfBootstrap($site, $singleSwitcher); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |      * Integration for WooCommerce and his gallery support. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |      * @param Site $site | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |      * @param SingleSwitcher $siteSwitcher | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |     public function wcBootstrap(Site $site, SingleSwitcher $siteSwitcher) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |         $wooCommerceGallery = new WooCommerce\Gallery($site, $siteSwitcher); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |         add_action('woocommerce_new_product', [$wooCommerceGallery, 'saveGalleryIds']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |         add_action('woocommerce_update_product', [$wooCommerceGallery, 'saveGalleryIds']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |      * Integration for ACF, specifically Image fields | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |      * @param Site $site | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |      * @param SingleSwitcher $siteSwitcher | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 89 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 90 |  |  |     public function acfBootstrap(Site $site, SingleSwitcher $siteSwitcher) | 
            
                                                                        
                            
            
                                    
            
            
                | 91 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 92 |  |  |         $acfImage = new ACF\Image($site, $siteSwitcher); | 
            
                                                                        
                            
            
                                    
            
            
                | 93 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 94 |  |  |         add_filter('acf/load_value/type=image', array($acfImage, 'acfLoadValue'), 10, 3); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 96 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 97 |  |  |  |