-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Transfer Verbum app into into jetpack-mu-wpcom (#35196)
Co-authored-by: heavyweight <kpapazov@gmail.com> Committed via a GitHub action: https://github.com/Automattic/jetpack/actions/runs/7641167060
- Loading branch information
1 parent
ed238c3
commit 8f7f31c
Showing
78 changed files
with
6,070 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
130 changes: 130 additions & 0 deletions
130
...attic/jetpack-mu-wpcom/src/build/verbum-comments/assets/class-verbum-gutenberg-editor.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
<?php | ||
/** | ||
* Verbum Gutenberg Editor | ||
* | ||
* @package automattic/jetpack-mu-plugins | ||
*/ | ||
|
||
declare( strict_types = 1 ); | ||
|
||
/** | ||
* Verbum_Gutenberg_Editor is responsible for loading the Gutenberg editor for comments. | ||
* | ||
* This loads the isolated editor, and sets up the editor to be used for Verbum_Comments. | ||
* | ||
* @see https://github.com/Automattic/isolated-block-editor | ||
*/ | ||
class Verbum_Gutenberg_Editor { | ||
/** | ||
* Class constructor | ||
*/ | ||
public function __construct() { | ||
define( 'VERBUM_USING_GUTENBERG', true ); | ||
|
||
// Override the placeholder text | ||
add_filter( | ||
'write_your_story', | ||
function () { | ||
return __( 'Write a comment...', 'jetpack-mu-wpcom' ); | ||
}, | ||
9999 | ||
); | ||
add_filter( 'comment_text', array( $this, 'render_verbum_blocks' ) ); | ||
add_filter( 'pre_comment_content', array( $this, 'remove_blocks' ) ); | ||
add_filter( 'wp_enqueue_scripts', array( $this, 'enqueue_assets' ) ); | ||
} | ||
|
||
/** | ||
* Enqueue the assets for the Gutenberg editor | ||
*/ | ||
public function enqueue_assets() { | ||
$vbe_cache_buster = filemtime( ABSPATH . '/widgets.wp.com/verbum-block-editor/build_meta.json' ); | ||
|
||
wp_enqueue_style( | ||
'verbum-gutenberg-css', | ||
'https://widgets.wp.com/verbum-block-editor/block-editor.css', | ||
array(), | ||
$vbe_cache_buster | ||
); | ||
} | ||
|
||
/** | ||
* Render blocks in the comment content | ||
* Filters blocks that aren't allowed | ||
* | ||
* @param string $comment_content - Text of the comment. | ||
* @return string | ||
*/ | ||
public function render_verbum_blocks( $comment_content ) { | ||
if ( ! has_blocks( $comment_content ) ) { | ||
return $comment_content; | ||
} | ||
|
||
$blocks = parse_blocks( $comment_content ); | ||
$comment_content = ''; | ||
|
||
$allowed_blocks = self::get_allowed_blocks(); | ||
foreach ( $blocks as $block ) { | ||
if ( in_array( $block['blockName'], $allowed_blocks, true ) ) { | ||
$comment_content .= render_block( $block ); | ||
} | ||
} | ||
|
||
return $comment_content; | ||
} | ||
|
||
/** | ||
* Remove blocks that aren't allowed | ||
* | ||
* @param string $content - Text of the comment. | ||
* @return string | ||
*/ | ||
public function remove_blocks( $content ) { | ||
if ( ! has_blocks( $content ) ) { | ||
return $content; | ||
} | ||
|
||
$allowed_blocks = self::get_allowed_blocks(); | ||
// The block attributes come slashed and `parse_blocks` won't be able to parse them. | ||
$content = wp_unslash( $content ); | ||
$blocks = parse_blocks( $content ); | ||
$output = ''; | ||
|
||
foreach ( $blocks as $block ) { | ||
if ( in_array( $block['blockName'], $allowed_blocks, true ) ) { | ||
$output .= serialize_block( $block ); | ||
} | ||
} | ||
|
||
return ltrim( $output ); | ||
} | ||
|
||
/** | ||
* Get a list of allowed blocks by looking at the allowed comment tags | ||
* | ||
* @return string[] | ||
*/ | ||
public static function get_allowed_blocks() { | ||
global $allowedtags; | ||
|
||
$allowed_blocks = array( 'core/paragraph', 'core/list', 'core/code', 'core/list-item', 'core/quote', 'core/image', 'core/embed' ); | ||
$convert = array( | ||
'blockquote' => 'core/quote', | ||
'h1' => 'core/heading', | ||
'h2' => 'core/heading', | ||
'h3' => 'core/heading', | ||
'img' => 'core/image', | ||
'ul' => 'core/list', | ||
'ol' => 'core/list', | ||
'pre' => 'core/code', | ||
); | ||
|
||
foreach ( array_keys( $allowedtags ) as $tag ) { | ||
if ( isset( $convert[ $tag ] ) ) { | ||
$allowed_blocks[] = $convert[ $tag ]; | ||
} | ||
} | ||
|
||
return $allowed_blocks; | ||
} | ||
} |
80 changes: 80 additions & 0 deletions
80
...jetpack-mu-wpcom/src/build/verbum-comments/assets/class-wpcom-rest-api-v2-verbum-auth.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
<?php | ||
/** | ||
* Plugin Name: Verbum Comments Experience Auth. | ||
* Description: This returns the user info based on their cookies/headers. | ||
* Author: Vertex | ||
* Text Domain: jetpack-mu-wpcom | ||
* | ||
* @package automattic/jetpack-mu-plugins | ||
*/ | ||
|
||
declare( strict_types = 1 ); | ||
|
||
/** | ||
* Verbum Comments Experience Auth endpoint. | ||
*/ | ||
class WPCOM_REST_API_V2_Verbum_Auth extends \WP_REST_Controller { | ||
/** | ||
* Constructor. | ||
*/ | ||
public function __construct() { | ||
$this->namespace = 'wpcom/v2'; | ||
$this->rest_base = '/verbum/auth'; | ||
$this->wpcom_is_wpcom_only_endpoint = false; | ||
$this->wpcom_is_site_specific_endpoint = false; | ||
add_action( 'rest_api_init', array( $this, 'register_routes' ) ); | ||
} | ||
|
||
/** | ||
* Register the routes for the objects of the controller. | ||
*/ | ||
public function register_routes() { | ||
register_rest_route( | ||
$this->namespace, | ||
$this->rest_base, | ||
array( | ||
'show_in_index' => false, | ||
'methods' => \WP_REST_Server::READABLE, | ||
'callback' => array( $this, 'get_auth' ), | ||
'permission_callback' => '__return_true', | ||
) | ||
); | ||
} | ||
|
||
/** | ||
* Authorize user based on their WordPress credentials or Facebook cookies. | ||
* | ||
* @return array|WP_Error | ||
*/ | ||
public function get_auth() { | ||
$user = wp_get_current_user(); | ||
if ( $user->ID ) { | ||
list( $wordpress_avatar_url ) = wpcom_get_avatar_url( $user->user_email, 60, '', true ); | ||
return array( | ||
'account' => $user->user_login, | ||
'avatar' => $wordpress_avatar_url, | ||
'email' => $user->user_email, | ||
'link' => ( ! empty( $user->user_url ) ? esc_url_raw( $user->user_url ) : esc_url_raw( 'http://gravatar.com/' . $user->user_login ) ), | ||
'name' => ( ! empty( $user->display_name ) ? $user->display_name : $user->user_login ), | ||
'uid' => $user->ID, | ||
'service' => 'wordpress', | ||
); | ||
} else { | ||
$fb = \Automattic\Jetpack\Verbum_Comments::verify_facebook_identity(); | ||
if ( ! is_wp_error( $fb ) ) { | ||
return array( | ||
'account' => $fb->name, | ||
'avatar' => $fb->picture->data->url, | ||
'email' => $fb->email, | ||
'link' => esc_url_raw( 'http://gravatar.com/' . $fb->email ), | ||
'name' => $fb->name, | ||
'uid' => $user->id, | ||
'service' => 'facebook', | ||
); | ||
} | ||
} | ||
return new \WP_Error( '403', 'Not Authorized', array( 'status' => 403 ) ); | ||
} | ||
} | ||
|
||
wpcom_rest_api_v2_load_plugin( 'WPCOM_REST_API_V2_Verbum_Auth' ); |
Oops, something went wrong.