* @throws TypeError
  • */
  • function sodium_crypto_sign_keypair_from_secretkey_and_publickey($sk, $pk)
  • {
  • return ParagonIE_Sodium_Compat::crypto_sign_keypair_from_secretkey_and_publickey($sk, $pk);
  • }
  • }
  • if (!is_callable('sodium_crypto_sign_keypair')) {
  • /**
  • * @see ParagonIE_Sodium_Compat::crypto_sign_keypair()
  • * @return string
  • * @throws SodiumException
  • * @throws TypeError
  • */
  • function sodium_crypto_sign_keypair()
  • {
  • return ParagonIE_Sodium_Compat::crypto_sign_keypair();
  • }
  • }
  • if (!is_callable('sodium_crypto_sign_open')) {
  • /**
  • * @see ParagonIE_Sodium_Compat::crypto_sign_open()
  • * @param string $signedMessage
  • * @param string $pk
  • * @return string|bool
  • */
  • function sodium_crypto_sign_open($signedMessage, $pk)
  • {
  • try {
  • return ParagonIE_Sodium_Compat::crypto_sign_open($signedMessage, $pk);
  • } catch (Error $ex) {
  • return false;
  • } catch (Exception $ex) {
  • return false;
  • }
  • }
  • }
  • if (!is_callable('sodium_crypto_sign_publickey')) {
  • /**
  • * @see ParagonIE_Sodium_Compat::crypto_sign_publickey()
  • * @param string $keypair
  • * @return string
  • * @throws SodiumException
  • * @throws TypeError
  • */
  • function sodium_crypto_sign_publickey($keypair)
  • {
  • return ParagonIE_Sodium_Compat::crypto_sign_publickey($keypair);
  • }
  • }
  • if (!is_callable('sodium_crypto_sign_publickey_from_secretkey')) {
  • /**
  • * @see ParagonIE_Sodium_Compat::crypto_sign_publickey_from_secretkey()
  • * @param string $sk
  • * @return string
  • * @throws SodiumException
  • * @throws TypeError
  • */
  • function sodium_crypto_sign_publickey_from_secretkey($sk)
  • {
  • return ParagonIE_Sodium_Compat::crypto_sign_publickey_from_secretkey($sk);
  • }
  • }
  • if (!is_callable('sodium_crypto_sign_secretkey')) {
  • /**
  • * @see ParagonIE_Sodium_Compat::crypto_sign_secretkey()
  • * @param string $keypair
  • * @return string
  • * @throws SodiumException
  • * @throws TypeError
  • */
  • function sodium_crypto_sign_secretkey($keypair)
  • {
  • return ParagonIE_Sodium_Compat::crypto_sign_secretkey($keypair);
  • }
  • }
  • if (!is_callable('sodium_crypto_sign_seed_keypair')) {
  • /**
  • * @see ParagonIE_Sodium_Compat::crypto_sign_seed_keypair()
  • * @param string $seed
  • * @return string
  • * @throws SodiumException
  • * @throws TypeError
  • */
  • function sodium_crypto_sign_seed_keypair($seed)
  • {
  • return ParagonIE_Sodium_Compat::crypto_sign_seed_keypair($seed);
  • }
  • }
  • if (!is_callable('sodium_crypto_sign_verify_detached')) {
  • /**
  • * @see ParagonIE_Sodium_Compat::crypto_sign_verify_detached()
  • * @param string $signature
  • * @param string $message
  • * @param string $pk
  • * @return bool
  • * @throws SodiumException
  • * @throws TypeError
  • */
  • function sodium_crypto_sign_verify_detached($signature, $message, $pk)
  • {
  • return ParagonIE_Sodium_Compat::crypto_sign_verify_detached($signature, $message, $pk);
  • }
  • }
  • if (!is_callable('sodium_crypto_sign_ed25519_pk_to_curve25519')) {
  • /**
  • * @see ParagonIE_Sodium_Compat::crypto_sign_ed25519_pk_to_curve25519()
  • * @param string $pk
  • * @return string
  • * @throws SodiumException
  • * @throws TypeError
  • */
  • function sodium_crypto_sign_ed25519_pk_to_curve25519($pk)
  • {
  • return ParagonIE_Sodium_Compat::crypto_sign_ed25519_pk_to_curve25519($pk);
  • }
  • }
  • if (!is_callable('sodium_crypto_sign_ed25519_sk_to_curve25519')) {
  • /**
  • * @see ParagonIE_Sodium_Compat::crypto_sign_ed25519_sk_to_curve25519()
  • * @param string $sk
  • * @return string
  • * @throws SodiumException
  • * @throws TypeError
  • */
  • function sodium_crypto_sign_ed25519_sk_to_curve25519($sk)
  • {
  • return ParagonIE_Sodium_Compat::crypto_sign_ed25519_sk_to_curve25519($sk);
  • }
  • }
  • if (!is_callable('sodium_crypto_stream')) {
  • /**
  • * @see ParagonIE_Sodium_Compat::crypto_stream()
  • * @param int $len
  • * @param string $nonce
  • * @param string $key
  • * @return string
  • * @throws SodiumException
  • * @throws TypeError
  • */
  • function sodium_crypto_stream($len, $nonce, $key)
  • {
  • return ParagonIE_Sodium_Compat::crypto_stream($len, $nonce, $key);
  • }
  • }
  • if (!is_callable('sodium_crypto_stream_keygen')) {
  • /**
  • * @see ParagonIE_Sodium_Compat::crypto_stream_keygen()
  • * @return string
  • * @throws Exception
  • */
  • function sodium_crypto_stream_keygen()
  • {
  • return ParagonIE_Sodium_Compat::crypto_stream_keygen();
  • }
  • }
  • if (!is_callable('sodium_crypto_stream_xor')) {
  • /**
  • * @see ParagonIE_Sodium_Compat::crypto_stream_xor()
  • * @param string $message
  • * @param string $nonce
  • * @param string $key
  • * @return string
  • * @throws SodiumException
  • * @throws TypeError
  • */
  • function sodium_crypto_stream_xor($message, $nonce, $key)
  • {
  • return ParagonIE_Sodium_Compat::crypto_stream_xor($message, $nonce, $key);
  • }
  • }
  • require_once dirname(__FILE__) . '/stream-xchacha20.php';
  • if (!is_callable('sodium_hex2bin')) {
  • /**
  • * @see ParagonIE_Sodium_Compat::hex2bin()
  • * @param string $string
  • * @return string
  • * @throws SodiumException
  • * @throws TypeError
  • */
  • function sodium_hex2bin($string)
  • {
  • return ParagonIE_Sodium_Compat::hex2bin($string);
  • }
  • }
  • if (!is_callable('sodium_increment')) {
  • /**
  • * @see ParagonIE_Sodium_Compat::increment()
  • * @param string $string
  • * @return void
  • * @throws SodiumException
  • * @throws TypeError
  • */
  • function sodium_increment(&$string)
  • {
  • ParagonIE_Sodium_Compat::increment($string);
  • }
  • }
  • if (!is_callable('sodium_library_version_major')) {
  • /**
  • * @see ParagonIE_Sodium_Compat::library_version_major()
  • * @return int
  • */
  • function sodium_library_version_major()
  • {
  • return ParagonIE_Sodium_Compat::library_version_major();
  • }
  • }
  • if (!is_callable('sodium_library_version_minor')) {
  • /**
  • * @see ParagonIE_Sodium_Compat::library_version_minor()
  • * @return int
  • */
  • function sodium_library_version_minor()
  • {
  • return ParagonIE_Sodium_Compat::library_version_minor();
  • }
  • }
  • if (!is_callable('sodium_version_string')) {
  • /**
  • * @see ParagonIE_Sodium_Compat::version_string()
  • * @return string
  • */
  • function sodium_version_string()
  • {
  • return ParagonIE_Sodium_Compat::version_string();
  • }
  • }
  • if (!is_callable('sodium_memcmp')) {
  • /**
  • * @see ParagonIE_Sodium_Compat::memcmp()
  • * @param string $a
  • * @param string $b
  • * @return int
  • * @throws SodiumException
  • * @throws TypeError
  • */
  • function sodium_memcmp($a, $b)
  • {
  • return ParagonIE_Sodium_Compat::memcmp($a, $b);
  • }
  • }
  • if (!is_callable('sodium_memzero')) {
  • /**
  • * @see ParagonIE_Sodium_Compat::memzero()
  • * @param string $str
  • * @return void
  • * @throws SodiumException
  • * @throws TypeError
  • */
  • function sodium_memzero(&$str)
  • {
  • ParagonIE_Sodium_Compat::memzero($str);
  • }
  • }
  • if (!is_callable('sodium_pad')) {
  • /**
  • * @see ParagonIE_Sodium_Compat::pad()
  • * @param string $unpadded
  • * @param int $blockSize
  • * @return int
  • * @throws SodiumException
  • * @throws TypeError
  • */
  • function sodium_pad($unpadded, $blockSize)
  • {
  • return ParagonIE_Sodium_Compat::pad($unpadded, $blockSize, true);
  • }
  • }
  • if (!is_callable('sodium_unpad')) {
  • /**
  • * @see ParagonIE_Sodium_Compat::pad()
  • * @param string $padded
  • * @param int $blockSize
  • * @return int
  • * @throws SodiumException
  • * @throws TypeError
  • */
  • function sodium_unpad($padded, $blockSize)
  • {
  • return ParagonIE_Sodium_Compat::unpad($padded, $blockSize, true);
  • }
  • }
  • if (!is_callable('sodium_randombytes_buf')) {
  • /**
  • * @see ParagonIE_Sodium_Compat::randombytes_buf()
  • * @param int $amount
  • * @return string
  • * @throws Exception
  • */
  • function sodium_randombytes_buf($amount)
  • {
  • return ParagonIE_Sodium_Compat::randombytes_buf($amount);
  • }
  • }
  • if (!is_callable('sodium_randombytes_uniform')) {
  • /**
  • * @see ParagonIE_Sodium_Compat::randombytes_uniform()
  • * @param int $upperLimit
  • * @return int
  • * @throws Exception
  • */
  • function sodium_randombytes_uniform($upperLimit)
  • {
  • return ParagonIE_Sodium_Compat::randombytes_uniform($upperLimit);
  • }
  • }
  • if (!is_callable('sodium_randombytes_random16')) {
  • /**
  • * @see ParagonIE_Sodium_Compat::randombytes_random16()
  • * @return int
  • * @throws Exception
  • */
  • function sodium_randombytes_random16()
  • {
  • return ParagonIE_Sodium_Compat::randombytes_random16();
  • }
  • }
  • tum/whitesports - Gogs: Simplico Git Service

    Нет описания

    class.json-api-site-jetpack.php 7.8KB

    123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
    1. <?php
    2. use Automattic\Jetpack\Sync\Functions;
    3. require_once dirname( __FILE__ ) . '/class.json-api-site-jetpack-base.php';
    4. require_once dirname( __FILE__ ) . '/class.json-api-post-jetpack.php';
    5. // this code runs on Jetpack (.org) sites
    6. class Jetpack_Site extends Abstract_Jetpack_Site {
    7. protected function get_mock_option( $name ) {
    8. return get_option( 'jetpack_'.$name );
    9. }
    10. protected function get_constant( $name ) {
    11. if ( defined( $name) ) {
    12. return constant( $name );
    13. }
    14. return null;
    15. }
    16. protected function main_network_site() {
    17. return network_site_url();
    18. }
    19. protected function wp_version() {
    20. global $wp_version;
    21. return $wp_version;
    22. }
    23. protected function max_upload_size() {
    24. return wp_max_upload_size();
    25. }
    26. protected function wp_memory_limit() {
    27. return wp_convert_hr_to_bytes( WP_MEMORY_LIMIT );
    28. }
    29. protected function wp_max_memory_limit() {
    30. return wp_convert_hr_to_bytes( WP_MAX_MEMORY_LIMIT );
    31. }
    32. protected function is_main_network() {
    33. return Jetpack::is_multi_network();
    34. }
    35. public function is_multisite() {
    36. return (bool) is_multisite();
    37. }
    38. public function is_single_user_site() {
    39. return (bool) Jetpack::is_single_user_site();
    40. }
    41. protected function is_version_controlled() {
    42. return Functions::is_version_controlled();
    43. }
    44. protected function file_system_write_access() {
    45. return Functions::file_system_write_access();
    46. }
    47. protected function current_theme_supports( $feature_name ) {
    48. return current_theme_supports( $feature_name );
    49. }
    50. protected function get_theme_support( $feature_name ) {
    51. return get_theme_support( $feature_name );
    52. }
    53. /**
    54. * Fetch a list of active plugins that are using Jetpack Connection.
    55. *
    56. * @return array An array of active plugins (by slug) that are using Jetpack Connection.
    57. */
    58. protected function get_connection_active_plugins() {
    59. $plugins = $this->get_mock_option( 'connection_active_plugins' );
    60. return is_array( $plugins ) ? array_keys( $plugins ) : array();
    61. }
    62. public function get_updates() {
    63. return (array) Jetpack::get_updates();
    64. }
    65. function get_id() {
    66. return $this->platform->token->blog_id;
    67. }
    68. function has_videopress() {
    69. // TODO - this only works on wporg site - need to detect videopress option for remote Jetpack site on WPCOM
    70. $videopress = Jetpack_Options::get_option( 'videopress', array() );
    71. if ( isset( $videopress['blog_id'] ) && $videopress['blog_id'] > 0 ) {
    72. return true;
    73. }
    74. return false;
    75. }
    76. function upgraded_filetypes_enabled() {
    77. return true;
    78. }
    79. function is_mapped_domain() {
    80. return true;
    81. }
    82. function get_unmapped_url() {
    83. // Fallback to the home URL since all Jetpack sites don't have an unmapped *.wordpress.com domain.
    84. return $this->get_url();
    85. }
    86. function is_redirect() {
    87. return false;
    88. }
    89. function is_following() {
    90. return false;
    91. }
    92. function has_wordads() {
    93. return Jetpack::is_module_active( 'wordads' );
    94. }
    95. function get_frame_nonce() {
    96. return false;
    97. }
    98. function get_jetpack_frame_nonce() {
    99. return false;
    100. }
    101. function is_headstart_fresh() {
    102. return false;
    103. }
    104. function allowed_file_types() {
    105. $allowed_file_types = array();
    106. // https://codex.wordpress.org/Uploading_Files
    107. $mime_types = get_allowed_mime_types();
    108. foreach ( $mime_types as $type => $mime_type ) {
    109. $extras = explode( '|', $type );
    110. foreach ( $extras as $extra ) {
    111. $allowed_file_types[] = $extra;
    112. }
    113. }
    114. return $allowed_file_types;
    115. }
    116. /**
    117. * Return site's privacy status.
    118. *
    119. * @return boolean Is site private?
    120. */
    121. function is_private() {
    122. return (int) $this->get_atomic_cloud_site_option( 'blog_public' ) === -1;
    123. }
    124. /**
    125. * Return site's coming soon status.
    126. *
    127. * @return boolean Is site "Coming soon"?
    128. */
    129. function is_coming_soon() {
    130. return $this->is_private() && (int) $this->get_atomic_cloud_site_option( 'wpcom_coming_soon' ) === 1;
    131. }
    132. /**
    133. * Return site's launch status.
    134. *
    135. * @return string|boolean Launch status ('launched', 'unlaunched', or false).
    136. */
    137. function get_launch_status() {
    138. return $this->get_atomic_cloud_site_option( 'launch-status' );
    139. }
    140. function get_atomic_cloud_site_option( $option ) {
    141. if ( ! jetpack_is_atomic_site() ) {
    142. return false;
    143. }
    144. $jetpack = Jetpack::init();
    145. if ( ! method_exists( $jetpack, 'get_cloud_site_options' ) ) {
    146. return false;
    147. }
    148. $result = $jetpack->get_cloud_site_options( [ $option ] );
    149. if ( ! array_key_exists( $option, $result ) ) {
    150. return false;
    151. }
    152. return $result[ $option ];
    153. }
    154. function get_plan() {
    155. return false;
    156. }
    157. function get_subscribers_count() {
    158. return 0; // special magic fills this in on the WPCOM side
    159. }
    160. function get_capabilities() {
    161. return false;
    162. }
    163. function get_locale() {
    164. return get_bloginfo( 'language' );
    165. }
    166. /**
    167. * The flag indicates that the site has Jetpack installed
    168. *
    169. * @return bool
    170. */
    171. public function is_jetpack() {
    172. return true;
    173. }
    174. /**
    175. * The flag indicates that the site is connected to WP.com via Jetpack Connection
    176. *
    177. * @return bool
    178. */
    179. public function is_jetpack_connection() {
    180. return true;
    181. }
    182. public function get_jetpack_version() {
    183. return JETPACK__VERSION;
    184. }
    185. function get_ak_vp_bundle_enabled() {}
    186. function get_jetpack_seo_front_page_description() {
    187. return Jetpack_SEO_Utils::get_front_page_meta_description();
    188. }
    189. function get_jetpack_seo_title_formats() {
    190. return Jetpack_SEO_Titles::get_custom_title_formats();
    191. }
    192. function get_verification_services_codes() {
    193. return get_option( 'verification_services_codes', null );
    194. }
    195. function get_podcasting_archive() {
    196. return null;
    197. }
    198. function is_connected_site() {
    199. return true;
    200. }
    201. function is_wpforteams_site() {
    202. return false;
    203. }
    204. function current_user_can( $role ) {
    205. return current_user_can( $role );
    206. }
    207. /**
    208. * Check if full site editing should be considered as currently active. Full site editing
    209. * requires the FSE plugin to be installed and activated, as well the current
    210. * theme to be FSE compatible. The plugin can also be explicitly disabled via the
    211. * a8c_disable_full_site_editing filter.
    212. *
    213. * @since 7.7.0
    214. *
    215. * @return bool true if full site editing is currently active.
    216. */
    217. function is_fse_active() {
    218. if ( ! Jetpack::is_plugin_active( 'full-site-editing/full-site-editing-plugin.php' ) ) {
    219. return false;
    220. }
    221. return function_exists( '\A8C\FSE\is_full_site_editing_active' ) && \A8C\FSE\is_full_site_editing_active();
    222. }
    223. /**
    224. * Check if site should be considered as eligible for full site editing. Full site editing
    225. * requires the FSE plugin to be installed and activated. For this method to return true
    226. * the current theme does not need to be FSE compatible. The plugin can also be explicitly
    227. * disabled via the a8c_disable_full_site_editing filter.
    228. *
    229. * @since 8.1.0
    230. *
    231. * @return bool true if site is eligible for full site editing
    232. */
    233. public function is_fse_eligible() {
    234. if ( ! Jetpack::is_plugin_active( 'full-site-editing/full-site-editing-plugin.php' ) ) {
    235. return false;
    236. }
    237. return function_exists( '\A8C\FSE\is_site_eligible_for_full_site_editing' ) && \A8C\FSE\is_site_eligible_for_full_site_editing();
    238. }
    239. /**
    240. * Check if site should be considered as eligible for use of the core Site Editor.
    241. * The Site Editor requires a block based theme to be active.
    242. *
    243. * @return bool true if site is eligible for the Site Editor
    244. */
    245. public function is_core_site_editor_enabled() {
    246. return function_exists( 'gutenberg_is_fse_theme' ) && gutenberg_is_fse_theme();
    247. }
    248. /**
    249. * Return the last engine used for an import on the site.
    250. *
    251. * This option is not used in Jetpack.
    252. */
    253. function get_import_engine() {
    254. return null;
    255. }
    256. /**
    257. * Post functions
    258. */
    259. function wrap_post( $post, $context ) {
    260. return new Jetpack_Post( $this, $post, $context );
    261. }
    262. /**
    263. * Get the option storing the Anchor podcast ID that identifies a site as a podcasting site.
    264. *
    265. * @return string
    266. */
    267. public function get_anchor_podcast() {
    268. return $this->get_atomic_cloud_site_option( 'anchor_podcast' );
    269. }
    270. }