update
This commit is contained in:
@@ -0,0 +1,196 @@
|
||||
<?php
|
||||
|
||||
namespace SmashBalloon\YouTubeFeed\Services\Integrations\Divi;
|
||||
|
||||
use SmashBalloon\YouTubeFeed\Services\Integrations\SBY_Integration;
|
||||
use SmashBalloon\YouTubeFeed\Helpers\Util;
|
||||
|
||||
/**
|
||||
* Class Divi Handler.
|
||||
*
|
||||
* @since 2.3
|
||||
*/
|
||||
class SBY_Divi_Handler
|
||||
{
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @since 2.3
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
$this->load();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Indicate if current integration is allowed to load.
|
||||
*
|
||||
* @since 2.3
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function allow_load()
|
||||
{
|
||||
if (function_exists('et_divi_builder_init_plugin')) {
|
||||
return true;
|
||||
}
|
||||
$allow_themes = [ 'Divi' ];
|
||||
$theme_name = get_template();
|
||||
|
||||
return in_array($theme_name, $allow_themes, true);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Load an integration.
|
||||
*
|
||||
* @since 2.3
|
||||
*/
|
||||
public function load()
|
||||
{
|
||||
if ($this->allow_load()) {
|
||||
$this->hooks();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Hooks.
|
||||
*
|
||||
* @since 2.3
|
||||
*/
|
||||
public function hooks()
|
||||
{
|
||||
add_action('et_builder_ready', [ $this, 'register_module' ]);
|
||||
|
||||
if (wp_doing_ajax()) {
|
||||
add_action('wp_ajax_sb_youtubefeed_divi_preview', [ $this, 'preview' ]);
|
||||
}
|
||||
|
||||
if ($this->is_divi_builder()) {
|
||||
add_action('wp_enqueue_scripts', [ $this, 'builder_scripts' ]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Load scripts.
|
||||
*
|
||||
* @since 2.3
|
||||
*/
|
||||
public function builder_scripts()
|
||||
{
|
||||
|
||||
$css_free_file_name = 'sb-youtube-free.min.css';
|
||||
$css_pro_file_name = 'sb-youtube.min.css';
|
||||
$css_file_name = sby_is_pro() ? $css_pro_file_name : $css_free_file_name;
|
||||
|
||||
wp_enqueue_style('sby_styles', trailingslashit(SBY_PLUGIN_URL) . 'css/' . $css_file_name, array(), SBYVER);
|
||||
|
||||
$data = array(
|
||||
'isAdmin' => is_admin(),
|
||||
'adminAjaxUrl' => admin_url('admin-ajax.php'),
|
||||
'placeholder' => trailingslashit(SBY_PLUGIN_URL) . 'img/placeholder.png',
|
||||
'placeholderNarrow' => trailingslashit(SBY_PLUGIN_URL) . 'img/placeholder-narrow.png',
|
||||
'lightboxPlaceholder' => trailingslashit(SBY_PLUGIN_URL) . 'img/lightbox-placeholder.png',
|
||||
'lightboxPlaceholderNarrow' => trailingslashit(SBY_PLUGIN_URL) . 'img/lightbox-placeholder-narrow.png',
|
||||
'autoplay' => false,
|
||||
'semiEagerload' => false,
|
||||
'eagerload' => false,
|
||||
'nonce' => wp_create_nonce('sby_nonce'),
|
||||
'isPro' => sby_is_pro(),
|
||||
'resized_url' => Util::sby_get_resized_uploads_url(),
|
||||
'isCustomizer' => false
|
||||
);
|
||||
|
||||
wp_enqueue_script(
|
||||
'sbyscripts',
|
||||
SBY_PLUGIN_URL . 'js/sb-youtube.min.js',
|
||||
array('jquery'),
|
||||
SBYVER,
|
||||
true
|
||||
);
|
||||
wp_localize_script('sbyscripts', 'sbyOptions', $data);
|
||||
|
||||
wp_enqueue_script(
|
||||
'sbyoutube-divi',
|
||||
// The unminified version is not supported by the browser.
|
||||
SBY_PLUGIN_URL . 'js/divi-handler.min.js',
|
||||
['react', 'react-dom', 'jquery'],
|
||||
SBYVER,
|
||||
true
|
||||
);
|
||||
|
||||
wp_enqueue_script(
|
||||
'sby-divi-handler',
|
||||
// The unminified version is not supported by the browser.
|
||||
SBY_PLUGIN_URL . 'js/divi-preview-handler.js',
|
||||
['jquery'],
|
||||
SBYVER,
|
||||
true
|
||||
);
|
||||
|
||||
wp_localize_script(
|
||||
'sbyoutube-divi',
|
||||
'sb_divi_builder',
|
||||
[
|
||||
'ajax_handler' => admin_url('admin-ajax.php'),
|
||||
'nonce' => wp_create_nonce('sby-admin'),
|
||||
'feed_splash' => htmlspecialchars(SBY_Integration::get_widget_cta('button'), ENT_QUOTES | ENT_HTML5)
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register module.
|
||||
*
|
||||
* @since 2.3
|
||||
*/
|
||||
public function register_module()
|
||||
{
|
||||
if (!class_exists('ET_Builder_Module')) {
|
||||
return;
|
||||
}
|
||||
|
||||
new SB_YouTube_Feed();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Ajax handler for the Feed preview.
|
||||
*
|
||||
* @since 2.3
|
||||
*/
|
||||
public function preview()
|
||||
{
|
||||
check_ajax_referer('sby-admin', 'nonce');
|
||||
|
||||
$cap = current_user_can('manage_youtube_feed_options') ? 'manage_youtube_feed_options' : 'manage_options';
|
||||
$cap = apply_filters('sby_settings_pages_capability', $cap);
|
||||
if (! current_user_can($cap)) {
|
||||
wp_send_json_error(); // This auto-dies.
|
||||
}
|
||||
|
||||
$feed_id = absint(filter_input(INPUT_POST, 'feed_id', FILTER_SANITIZE_NUMBER_INT));
|
||||
|
||||
wp_send_json_success(
|
||||
do_shortcode(
|
||||
sprintf(
|
||||
'[youtube-feed feed="%1$s"]',
|
||||
absint($feed_id)
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if a current page is opened in the Divi Builder.
|
||||
*
|
||||
* @since 2.3
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function is_divi_builder()
|
||||
{
|
||||
return !empty($_GET['et_fb']); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
<?php
|
||||
|
||||
namespace SmashBalloon\YouTubeFeed\Services\Integrations\Divi;
|
||||
|
||||
use ET_Builder_Module;
|
||||
use SmashBalloon\YouTubeFeed\Builder\SBY_Db;
|
||||
|
||||
class SB_YouTube_Feed extends ET_Builder_Module {
|
||||
/**
|
||||
* Module slug.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $slug = 'sb_youtube_feed';
|
||||
|
||||
/**
|
||||
* VB support.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $vb_support = 'on';
|
||||
|
||||
|
||||
/**
|
||||
* Init module.
|
||||
*
|
||||
* @since 2.3
|
||||
*/
|
||||
public function init() {
|
||||
$this->name = esc_html__('YouTube Feed', 'feeds-for-youtube');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get list of settings.
|
||||
*
|
||||
* @since 2.3
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_fields() {
|
||||
$feeds_divi = array();
|
||||
$feeds_list = SBY_Db::elementor_feeds_query();
|
||||
|
||||
if ( ! empty( $feeds_list ) ) {
|
||||
$feeds_divi[ 'sby-0' ] = esc_html__('Select Youtube Feed', 'feeds-for-youtube');
|
||||
foreach ( $feeds_list as $key => $feed ) {
|
||||
$feeds_divi[ 'sby-' . $key ] = $feed;
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
'feed_id' => [
|
||||
'label' => esc_html__('Feed', 'feeds-for-youtube'),
|
||||
'type' => 'select',
|
||||
'option_category' => 'basic_option',
|
||||
'toggle_slug' => 'main_content',
|
||||
'options' => $feeds_divi,
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable advanced fields configuration.
|
||||
*
|
||||
* @since 2.3
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_advanced_fields_config() {
|
||||
return [
|
||||
'link_options' => false,
|
||||
'text' => false,
|
||||
'background' => false,
|
||||
'borders' => false,
|
||||
'box_shadow' => false,
|
||||
'button' => false,
|
||||
'filters' => false,
|
||||
'fonts' => false,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Render module on the frontend.
|
||||
*
|
||||
* @since 2.3
|
||||
*
|
||||
* @param array $attrs List of unprocessed attributes.
|
||||
* @param string $content Content being processed.
|
||||
* @param string $render_slug Slug of module that is used for rendering output.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function render($attrs, $content = null, $render_slug = '') {
|
||||
if (empty($this->props['feed_id'])) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$feed_id = str_replace('sby-', '', $this->props['feed_id']);
|
||||
|
||||
return do_shortcode(
|
||||
sprintf(
|
||||
'[youtube-feed feed="%1$s"]',
|
||||
absint($feed_id)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user