Skip to content

Commit

Permalink
Transfer Verbum app into into jetpack-mu-wpcom (#35196)
Browse files Browse the repository at this point in the history
Co-authored-by: heavyweight <kpapazov@gmail.com>

Committed via a GitHub action: https://github.com/Automattic/jetpack/actions/runs/7641167060
  • Loading branch information
heavyweight authored and matticbot committed Jan 24, 2024
1 parent ed238c3 commit 8f7f31c
Show file tree
Hide file tree
Showing 78 changed files with 6,070 additions and 66 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## 2.0.16-alpha - unreleased

This is an alpha version! The changes listed here are not final.

## 2.0.15 - 2024-01-23
### Changed
- Internal updates.
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"type": "wordpress-plugin",
"license": "GPL-2.0-or-later",
"require": {
"automattic/jetpack-mu-wpcom": "^5.9.0"
"automattic/jetpack-mu-wpcom": "^5.10.0-alpha"
},
"require-dev": {
"yoast/phpunit-polyfills": "1.1.0",
Expand Down Expand Up @@ -37,6 +37,6 @@
]
},
"config": {
"autoloader-suffix": "d9d132a783958a00a2c7cccff60ca42d_jetpack_mu_wpcom_pluginⓥ2_0_15"
"autoloader-suffix": "d9d132a783958a00a2c7cccff60ca42d_jetpack_mu_wpcom_pluginⓥ2_0_16_alpha"
}
}
10 changes: 5 additions & 5 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion mu-wpcom-plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* Plugin Name: WordPress.com Features
* Description: Test plugin for the jetpack-mu-wpcom package
* Version: 2.0.15
* Version: 2.0.16-alpha
* Author: Automattic
* License: GPLv2 or later
* Text Domain: jetpack-mu-wpcom-plugin
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"private": true,
"name": "@automattic/jetpack-mu-wpcom-plugin",
"version": "2.0.15",
"version": "2.0.16-alpha",
"description": "Test plugin for the jetpack-mu-wpcom package",
"homepage": "https://jetpack.com",
"bugs": {
Expand Down
2 changes: 1 addition & 1 deletion vendor/autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@

require_once __DIR__ . '/composer/autoload_real.php';

return ComposerAutoloaderInitd9d132a783958a00a2c7cccff60ca42d_jetpack_mu_wpcom_pluginⓥ2_0_15::getLoader();
return ComposerAutoloaderInitd9d132a783958a00a2c7cccff60ca42d_jetpack_mu_wpcom_pluginⓥ2_0_16_alpha::getLoader();
8 changes: 8 additions & 0 deletions vendor/automattic/jetpack-mu-wpcom/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [5.10.0-alpha] - unreleased

This is an alpha version! The changes listed here are not final.

### Added
- Add Verbum Comments in jetpack-mu-wpcom plugin

## [5.9.0] - 2024-01-22
### Added
- Added the completion logic for the 'Install the mobile app' task [#35110]
Expand Down Expand Up @@ -537,6 +544,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Testing initial package release.

[5.10.0-alpha]: https://github.com/Automattic/jetpack-mu-wpcom/compare/v5.9.0...v5.10.0-alpha
[5.9.0]: https://github.com/Automattic/jetpack-mu-wpcom/compare/v5.8.2...v5.9.0
[5.8.2]: https://github.com/Automattic/jetpack-mu-wpcom/compare/v5.8.1...v5.8.2
[5.8.1]: https://github.com/Automattic/jetpack-mu-wpcom/compare/v5.8.0...v5.8.1
Expand Down
2 changes: 1 addition & 1 deletion vendor/automattic/jetpack-mu-wpcom/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
},
"autotagger": true,
"branch-alias": {
"dev-trunk": "5.9.x-dev"
"dev-trunk": "5.10.x-dev"
},
"textdomain": "jetpack-mu-wpcom",
"version-constants": {
Expand Down
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;
}
}
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' );
Loading

0 comments on commit 8f7f31c

Please sign in to comment.