Skip to content

Commit

Permalink
Add support for common file ( image, video ) URL (#1)
Browse files Browse the repository at this point in the history
Add support for common file ( image, video ) URL
  • Loading branch information
thrijith authored Jan 27, 2020
2 parents 209b864 + 4f9f541 commit fbc6049
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
2 changes: 1 addition & 1 deletion assets/css/rt-google-embed-main.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
@charset "UTF-8";

@import "embeds";
@import "./embeds";
23 changes: 16 additions & 7 deletions includes/classes/class-rtcamp-google-embeds.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public function __construct() {
$this->add_plugin_constants();
add_action( 'plugins_loaded', array( $this, 'load_textdomain' ) );
add_action( 'wp_enqueue_scripts', array( $this, 'rt_google_embed_enqueue_scripts' ) );
add_action( 'admin_enqueue_scripts', array( $this, 'rt_google_embed_enqueue_scripts' ) );
add_action( 'after_setup_theme', array( $this, 'rt_google_embed_add_editor_css' ) );
add_action( 'init', array( $this, 'register_embeds' ) );
}
Expand Down Expand Up @@ -89,32 +90,40 @@ public function register_embeds() {
// Google Docs regex.
$gdoc_oembed_pattern = '#https?:\\/\\/docs\\.google\\.com\\/document\\/d\\/(.*)\\/(.*)?#i';
wp_embed_register_handler(
'google_docs',
'rt_google_docs',
$gdoc_oembed_pattern,
array( $this, 'wpdocs_embed_handler_google_drive' )
);

// Google Sheets regex.
$gsheet_oembed_pattern = '#https?:\\/\\/docs\\.google\\.com\\/spreadsheets\\/d\\/(.*)\\/(.*)?#i';
wp_embed_register_handler(
'google_sheets',
'rt_google_sheets',
$gsheet_oembed_pattern,
array( $this, 'wpdocs_embed_handler_google_drive' )
);

// Google Slides regex.
$gslides_oembed_pattern = '#https?:\\/\\/docs\\.google\\.com\\/presentation\\/d\\/(.*)\\/(.*)?#i';
wp_embed_register_handler(
'google_presentations',
'rt_google_presentations',
$gslides_oembed_pattern,
array( $this, 'wpdocs_embed_handler_google_drive' )
);

// Common URL regex.
$gdoc_common_oembed_pattern = '#https?:\\/\\/drive\\.google\\.com\\/open\\?id\\=(.*)?#i';
$gdrive_common_oembed_pattern = '#https?:\\/\\/drive\\.google\\.com\\/open\\?id\\=(.*)?#i';
wp_embed_register_handler(
'google_doc_common',
$gdoc_common_oembed_pattern,
'rt_google_doc_common',
$gdrive_common_oembed_pattern,
array( $this, 'wpdocs_embed_handler_google_drive' )
);

// Common file URL regex.
$gdrive_common_file_oembed_pattern = '#https?:\\/\\/drive\\.google\\.com\\/file\\/d\\/(.*)\\/(.*)?#i';
wp_embed_register_handler(
'rt_google_file_common',
$gdrive_common_file_oembed_pattern,
array( $this, 'wpdocs_embed_handler_google_drive' )
);
}
Expand All @@ -137,7 +146,7 @@ public function wpdocs_embed_handler_google_drive( $matches, $attr, $url ) {
array(
'drive_file_url' => $url,
'thumbnail_url' => $thumbnail_url,
)
)
);
}

Expand Down
2 changes: 1 addition & 1 deletion templates/embeds/google-drive-file.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
?>
<div class="rt-google-doc-embed">
<a href="<?php echo esc_url( $drive_file_url ); ?>" title="<?php esc_attr_e( 'Open the Shared Document', 'rt-google-embeds' ); ?>" target="_blank">
<?php esc_html_e( 'Open Google Document.', 'rt-google-embeds' ); ?>
<?php esc_html_e( 'Open Shared Document.', 'rt-google-embeds' ); ?>
</a>
<img src="<?php echo esc_url( $thumbnail_url ); ?>" alt="<?php esc_attr_e( 'Shared Document Preview', 'rt-google-embeds' ); ?>" />
</div>

0 comments on commit fbc6049

Please sign in to comment.