| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | require_once dirname( __FILE__ ) . '/class.json-api-site-base.php'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  | abstract class Abstract_Jetpack_Site extends SAL_Site { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | 	abstract protected function get_constant( $name ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | 	abstract protected function current_theme_supports( $feature_name ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | 	abstract protected function get_theme_support( $feature_name ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | 	abstract protected function get_mock_option( $name ); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 12 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 13 |  |  | 	abstract public function get_jetpack_version(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | 	abstract public function get_updates(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | 	abstract protected function main_network_site(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | 	abstract protected function wp_version(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  | 	abstract protected function max_upload_size(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  | 	abstract protected function is_main_network(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  | 	abstract protected function is_version_controlled(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  | 	abstract protected function file_system_write_access(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  | 	function before_render() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  | 	protected function wp_memory_limit() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  | 		return $this->get_constant( 'WP_MEMORY_LIMIT' ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  | 	protected function wp_max_memory_limit() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  | 		return $this->get_constant( 'WP_MAX_MEMORY_LIMIT' ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  | 	function after_render( &$response ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  | 		// Add the updates only make them visible if the user has manage options permission and the site is the main site of the network | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  | 		if ( current_user_can( 'manage_options' ) && $this->is_main_site( $response ) ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  | 			$jetpack_update = $this->get_updates(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  | 			if ( ! empty( $jetpack_update ) ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  | 				// In previous version of Jetpack 3.4, 3.5, 3.6 we synced the wp_version into to jetpack_updates | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  | 				unset( $jetpack_update['wp_version'] ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  | 				// In previous version of Jetpack 3.4, 3.5, 3.6 we synced the site_is_version_controlled into to jetpack_updates | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  | 				unset( $jetpack_update['site_is_version_controlled'] ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  | 				$response['updates'] = $jetpack_update; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  | 	function after_render_options( &$options ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  | 		$options['jetpack_version'] = $this->get_jetpack_version(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  | 		if ( $main_network_site = $this->main_network_site() ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  | 			$options['main_network_site'] = (string) rtrim( $main_network_site, '/' ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  | 		if ( is_array( $active_modules = Jetpack_Options::get_option( 'active_modules' ) ) ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  | 			$options['active_modules'] = (array) array_values( $active_modules ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  | 		$options['software_version'] = (string) $this->wp_version(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  | 		$options['max_upload_size']  = $this->max_upload_size(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  | 		$options['wp_memory_limit']  = $this->wp_memory_limit(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  | 		$options['wp_max_memory_limit']  = $this->wp_max_memory_limit(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  | 		// Sites have to prove that they are not main_network site. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  | 		// If the sync happends right then we should be able to see that we are not dealing with a network site | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  | 		$options['is_multi_network'] = (bool) $this->is_main_network(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  | 		$options['is_multi_site']    = (bool) $this->is_multisite(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  | 		$file_mod_disabled_reasons = array_keys( array_filter( array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  | 			'automatic_updater_disabled'      => (bool) $this->get_constant( 'AUTOMATIC_UPDATER_DISABLED' ), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  | 			// WP AUTO UPDATE CORE defaults to minor, '1' if true and '0' if set to false. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  | 			'wp_auto_update_core_disabled'    => ! ( (bool)  $this->get_constant( 'WP_AUTO_UPDATE_CORE' ) ), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  | 			'is_version_controlled'           => (bool) $this->is_version_controlled(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  | 			// By default we assume that site does have system write access if the value is not set yet. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  | 			'has_no_file_system_write_access' => ! (bool) $this->file_system_write_access(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  | 			'disallow_file_mods'              => (bool)  $this->get_constant( 'DISALLOW_FILE_MODS' ), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  | 		) ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  | 		$options['file_mod_disabled'] = empty( $file_mod_disabled_reasons ) ? false : $file_mod_disabled_reasons; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  | 	function get_jetpack_modules() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  | 		return array_values( Jetpack_Options::get_option( 'active_modules', array() ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  | 	function is_module_active( $module ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  | 		return in_array ( $module, Jetpack_Options::get_option( 'active_modules', array() ), true ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  | 	function is_vip() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  | 		return false; // this may change for VIP Go sites, which sync using Jetpack | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  | 	function featured_images_enabled() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  | 		return $this->current_theme_supports( 'post-thumbnails' ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  | 	function get_post_formats() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  | 		// deprecated - see separate endpoint. get a list of supported post formats | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  | 		$all_formats = get_post_format_strings(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  | 		$supported   = $this->get_theme_support( 'post-formats' ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  | 		$supported_formats = array(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |  | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 114 |  | View Code Duplication | 		if ( isset( $supported[0] ) ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  | 			foreach ( $supported[0] as $format ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  | 				$supported_formats[ $format ] = $all_formats[ $format ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  | 		return $supported_formats; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  | 	function get_icon() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  | 		$icon_id = get_option( 'site_icon' ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  | 		if ( empty( $icon_id ) ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  | 			$icon_id = Jetpack_Options::get_option( 'site_icon_id' ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  | 		if ( empty( $icon_id ) ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  | 			return null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 133 |  |  | 		$icon = array_filter( array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 134 |  |  | 			'img' => wp_get_attachment_image_url( $icon_id, 'full' ), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 135 |  |  | 			'ico' => wp_get_attachment_image_url( $icon_id, array( 16, 16 ) ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 136 |  |  | 		) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 137 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 138 |  |  | 		if ( empty( $icon ) ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 139 |  |  | 			return null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 140 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 141 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 142 |  |  | 		if ( current_user_can( 'edit_posts', $icon_id ) ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 143 |  |  | 			$icon['media_id'] = (int) $icon_id; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 144 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 145 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 146 |  |  | 		return $icon; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 147 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 148 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 149 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 150 |  |  | 	 * Private methods | 
            
                                                                                                            
                            
            
                                    
            
            
                | 151 |  |  | 	 **/ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 152 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 153 |  |  | 	private function is_main_site( $response ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 154 |  |  | 		if ( isset( $response['options']->main_network_site, $response['options']->unmapped_url ) ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 155 |  |  | 			$main_network_site_url = set_url_scheme( $response['options']->main_network_site, 'http' ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 156 |  |  | 			$unmapped_url          = set_url_scheme( $response['options']->unmapped_url, 'http' ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 157 |  |  | 			if ( $unmapped_url === $main_network_site_url ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 158 |  |  | 				return true; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 159 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 160 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 161 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 162 |  |  | 		return false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 163 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 164 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 165 |  |  | 	// For Jetpack sites this will always return false | 
            
                                                                                                            
                            
            
                                    
            
            
                | 166 |  |  | 	protected function is_a8c_publication( $post_id ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 167 |  |  | 		return false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 168 |  |  | 	} | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 169 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 170 |  |  |  |