-
Notifications
You must be signed in to change notification settings - Fork 798
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Calypsoify: Copy the module code to the Calypsoify package #37339
Merged
Merged
Changes from 6 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
1002a21
Copying and moving the Calypsoify code to the Calypsoify package
coder-karen 99edeb2
changelog
coder-karen 056e97d
Modifying how the Jetpack conversion constant is received, and adding…
coder-karen 8955ba1
Update composer.json to include the correct file path to find the pac…
coder-karen fb28039
Re-add the phan baseline file to make sure phan false positives are c…
coder-karen d5be7c7
Updating phan as well as the package version const and package reqs
coder-karen d24a308
Adding a webpack build to build CSS and JS files, and update related …
coder-karen b9c39b5
Update the lock file
coder-karen 0de549a
Tweak package.json build steps
coder-karen db53908
Merge remote-tracking branch 'origin/trunk' into add/calypsoify-packa…
coder-karen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
/** | ||
* This is an automatically generated baseline for Phan issues. | ||
* When Phan is invoked with --load-baseline=path/to/baseline.php, | ||
* The pre-existing issues listed in this file won't be emitted. | ||
* | ||
* This file can be updated by invoking Phan with --save-baseline=path/to/baseline.php | ||
* (can be combined with --load-baseline) | ||
*/ | ||
return [ | ||
// # Issue statistics: | ||
// PhanTypeMismatchArgumentProbablyReal : 1 occurrence | ||
// PhanTypeMismatchPropertyDefault : 1 occurrence | ||
|
||
// Currently, file_suppressions and directory_suppressions are the only supported suppressions | ||
'file_suppressions' => [ | ||
'src/class-jetpack-calypsoify.php' => ['PhanTypeMismatchArgumentProbablyReal', 'PhanTypeMismatchPropertyDefault'], | ||
], | ||
// 'directory_suppressions' => ['src/directory_name' => ['PhanIssueName1', 'PhanIssueName2']] can be manually added if needed. | ||
// (directory_suppressions will currently be ignored by subsequent calls to --save-baseline, but may be preserved in future Phan releases) | ||
]; |
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
4 changes: 4 additions & 0 deletions
4
projects/packages/calypsoify/changelog/add-calypsoify-package-code
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,4 @@ | ||
Significance: minor | ||
Type: added | ||
|
||
Calypsoify: Copy the code from the Jetpack module into the package. |
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 was deleted.
Oops, something went wrong.
215 changes: 215 additions & 0 deletions
215
projects/packages/calypsoify/src/class-jetpack-calypsoify.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,215 @@ | ||
<?php | ||
/** | ||
* This is Calypso skin of the wp-admin interface that is conditionally triggered via the ?calypsoify=1 param. | ||
* | ||
* @package automattic/jetpack-calypsoify | ||
*/ | ||
|
||
namespace Automattic\Jetpack\Calypsoify; | ||
|
||
use Automattic\Jetpack\Status; | ||
|
||
/** | ||
* Class Jetpack_Calypsoify | ||
*/ | ||
class Jetpack_Calypsoify { | ||
|
||
const PACKAGE_VERSION = '0.1.0-alpha'; | ||
|
||
/** | ||
* Singleton instance of `Jetpack_Calypsoify`. | ||
* | ||
* @var object | ||
*/ | ||
public static $instance = false; | ||
|
||
/** | ||
* Is Calypsoify enabled, based on any value of `calypsoify` user meta. | ||
* | ||
* @var bool | ||
*/ | ||
public $is_calypsoify_enabled = false; | ||
|
||
/** | ||
* Jetpack_Calypsoify constructor. | ||
*/ | ||
private function __construct() { | ||
add_action( 'admin_init', array( $this, 'setup' ), 4 ); | ||
} | ||
|
||
/** | ||
* Singleton. | ||
* | ||
* @return Jetpack_Calypsoify | ||
*/ | ||
public static function get_instance() { | ||
if ( ! self::$instance ) { | ||
self::$instance = new self(); | ||
} | ||
|
||
return self::$instance; | ||
} | ||
|
||
/** | ||
* Setup function that is loaded on the `wp_loaded` hook via the constructor. | ||
*/ | ||
public function setup() { | ||
$this->is_calypsoify_enabled = isset( $_GET['calypsoify'] ) && 1 === (int) $_GET['calypsoify'] && $this->is_page_gutenberg(); // phpcs:ignore WordPress.Security.NonceVerification.Recommended | ||
|
||
$this->check_meta(); | ||
|
||
if ( $this->is_calypsoify_enabled ) { | ||
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_for_gutenberg' ), 100 ); | ||
} | ||
} | ||
|
||
/** | ||
* Enqueues scripts, data, and styles for Gutenberg. | ||
*/ | ||
public function enqueue_for_gutenberg() { | ||
$site_suffix = ( new Status() )->get_site_suffix(); | ||
wp_enqueue_style( 'calypsoify_wpadminmods_css', plugin_dir_url( __FILE__ ) . 'style-gutenberg.min.css', false, self::PACKAGE_VERSION ); | ||
wp_style_add_data( 'calypsoify_wpadminmods_css', 'rtl', 'replace' ); | ||
wp_style_add_data( 'calypsoify_wpadminmods_css', 'suffix', '.min' ); | ||
|
||
wp_enqueue_script( 'calypsoify_wpadminmods_js', plugin_dir_url( __FILE__ ) . 'mods-gutenberg.js', array( 'jquery' ), self::PACKAGE_VERSION, false ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since we changed the file structure with js files currently living under the |
||
wp_localize_script( | ||
'calypsoify_wpadminmods_js', | ||
'calypsoifyGutenberg', | ||
array( | ||
'closeUrl' => $this->get_close_gutenberg_url(), | ||
'manageReusableBlocksUrl' => $this->get_calypso_origin() . '/types/wp_block/' . $site_suffix, | ||
'createNewPostUrl' => $this->get_calypso_origin() . '/post/' . $site_suffix, | ||
) | ||
); | ||
} | ||
|
||
/** | ||
* Returns the Calypso domain that originated the current request. | ||
* | ||
* @return string | ||
*/ | ||
private function get_calypso_origin() { | ||
$origin = ! empty( $_GET['origin'] ) ? wp_unslash( $_GET['origin'] ) : 'https://wordpress.com'; // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized | ||
$allowed = array( | ||
'http://calypso.localhost:3000', | ||
'http://127.0.0.1:41050', // Desktop App. | ||
'https://wpcalypso.wordpress.com', | ||
'https://horizon.wordpress.com', | ||
'https://wordpress.com', | ||
); | ||
return in_array( $origin, $allowed, true ) ? $origin : 'https://wordpress.com'; | ||
} | ||
|
||
/** | ||
* Returns the Calypso URL that displays either the current post type list (if no args | ||
* are supplied) or the classic editor for the current post (if a post ID is supplied). | ||
* | ||
* @param int|null $post_id Post ID. | ||
* | ||
* @return string | ||
*/ | ||
public function get_calypso_url( $post_id = null ) { | ||
$screen = get_current_screen(); | ||
$post_type = $screen->post_type; | ||
$site_suffix = ( new Status() )->get_site_suffix(); | ||
|
||
if ( $post_id === null ) { | ||
// E.g. posts or pages have no special suffix. CPTs are in the `types/{cpt}` format. | ||
$post_type_suffix = ( 'post' === $post_type || 'page' === $post_type ) | ||
? "/{$post_type}s/" | ||
: "/types/{$post_type}/"; | ||
$post_suffix = ''; | ||
} else { | ||
$post_type_suffix = ( 'post' === $post_type || 'page' === $post_type ) | ||
? "/{$post_type}/" | ||
: "/edit/{$post_type}/"; | ||
$post_suffix = "/{$post_id}"; | ||
} | ||
|
||
return $this->get_calypso_origin() . $post_type_suffix . $site_suffix . $post_suffix; | ||
} | ||
|
||
/** | ||
* Returns the URL to be used on the block editor close button for going back to the | ||
* Calypso post list. | ||
* | ||
* @return string | ||
*/ | ||
public function get_close_gutenberg_url() { | ||
return $this->get_calypso_url(); | ||
} | ||
|
||
/** | ||
* Returns the URL for switching the user's editor to the Calypso (WordPress.com Classic) editor. | ||
* | ||
* @return string | ||
*/ | ||
public function get_switch_to_classic_editor_url() { | ||
return add_query_arg( | ||
'set-editor', | ||
'classic', | ||
$this->is_calypsoify_enabled ? $this->get_calypso_url( get_the_ID() ) : false | ||
); | ||
} | ||
|
||
/** | ||
* Checks if the calypsoify user meta value is set, and deletes it if it is. | ||
* This is to ensure that Calypsoify is not activated without the URL parameter. | ||
*/ | ||
public function check_meta() { | ||
if ( ! empty( get_user_meta( get_current_user_id(), 'calypsoify', true ) ) ) { | ||
delete_user_meta( get_current_user_id(), 'calypsoify' ); | ||
} | ||
} | ||
|
||
/** | ||
* Return whether a post type should display the Gutenberg/block editor. | ||
* | ||
* @since jetpack-6.7.0 | ||
* | ||
* @param string $post_type Post type. | ||
*/ | ||
public function is_post_type_gutenberg( $post_type ) { | ||
return use_block_editor_for_post_type( $post_type ); | ||
} | ||
|
||
/** | ||
* Determines if the page is an instance of the Gutenberg block editor. | ||
* | ||
* @return bool | ||
*/ | ||
public function is_page_gutenberg() { | ||
// phpcs:disable WordPress.Security.NonceVerification.Recommended | ||
// Disabling WordPress.Security.NonceVerification.Recommended because this function fires within admin_init and this is only changing display. | ||
$page = isset( $_SERVER['REQUEST_URI'] ) ? wp_basename( esc_url_raw( wp_unslash( $_SERVER['REQUEST_URI'] ) ) ) : ''; | ||
|
||
if ( str_contains( $page, 'post-new.php' ) && empty( $_GET['post_type'] ) ) { | ||
return true; | ||
} | ||
|
||
if ( str_contains( $page, 'post-new.php' ) && isset( $_GET['post_type'] ) && $this->is_post_type_gutenberg( sanitize_key( $_GET['post_type'] ) ) ) { | ||
return true; | ||
} | ||
|
||
if ( str_contains( $page, 'post.php' ) ) { | ||
$post = get_post( isset( $_GET['post'] ) ? intval( $_GET['post'] ) : null ); | ||
if ( isset( $post ) && isset( $post->post_type ) && $this->is_post_type_gutenberg( $post->post_type ) ) { | ||
return true; | ||
} | ||
} | ||
|
||
if ( str_contains( $page, 'revision.php' ) ) { | ||
$post = get_post( isset( $_GET['revision'] ) ? intval( $_GET['revision'] ) : null ); | ||
$parent = get_post( $post->post_parent ); | ||
if ( isset( $parent ) && isset( $parent->post_type ) && $this->is_post_type_gutenberg( $parent->post_type ) ) { | ||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
// phpcs:enable | ||
} | ||
} | ||
|
||
Jetpack_Calypsoify::get_instance(); |
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,85 @@ | ||
/** | ||
* Hide Fullscreen option from post-editor | ||
* | ||
* The entire menu group is not rendered on smaller screens so we need a media query. | ||
* Hide the third item of the first group when the screen is big enough. | ||
*/ | ||
@media (min-width: 782px) { | ||
.interface-more-menu-dropdown__content .components-menu-group:first-child .components-button:nth-child(3) { | ||
display: none; | ||
} | ||
} | ||
|
||
/* Hides the Fullscreen option from the Site Editor View modes */ | ||
.edit-site-more-menu__content .components-menu-group:first-child > [role=group] > .components-menu-item__button:last-of-type { | ||
display: none; | ||
} | ||
|
||
/* REVISIONS */ | ||
|
||
.revision-php { | ||
background: #f3f6f8; | ||
} | ||
|
||
.wp-toolbar .revision-php { | ||
margin-top: -32px; | ||
} | ||
|
||
.revision-php #wpadminbar, | ||
.revision-php #adminmenumain, | ||
.revision-php #wp-admin-bar-menu-toggle { | ||
display: none; | ||
} | ||
|
||
.revision-php #wpcontent { | ||
margin-left: 50px !important; | ||
} | ||
|
||
.revision-php #wpbody { | ||
padding-top: 0; | ||
} | ||
|
||
.revision-php #screen-meta-links { | ||
display: none !important; | ||
} | ||
|
||
.revision-php #wpfooter { | ||
display: none !important; | ||
} | ||
|
||
.revision-tickmarks { | ||
margin-top: 8px; | ||
} | ||
|
||
.revisions-controls { | ||
height: 118px; | ||
} | ||
.comparing-two-revisions .revisions-controls { | ||
height: 176px; | ||
} | ||
|
||
.revisions-meta { | ||
margin-top: 28px; | ||
} | ||
|
||
.diff-meta { | ||
min-height: 46px; | ||
} | ||
.revisions-controls .author-card .avatar { | ||
border-radius: 50%; | ||
height: 38px; | ||
margin-top: 4px; | ||
width: 38px; | ||
} | ||
.revisions-controls .author-card .author-info { | ||
line-height: 20px; | ||
margin-top: 4px; | ||
} | ||
|
||
.revision-toggle-compare-mode label { | ||
vertical-align: top; | ||
} | ||
|
||
.revisions-tooltip { | ||
transform: translateY(-36px); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we changed the file structure with css files currently living under the
css
folder we'll need to fix the path here as well.I guess the
style-gutenberg.min.css
will be created on build but added to the.gitignore
too?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, thanks!