Няма описание

class.json-api-site-jetpack-base.php 5.6KB

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