This commit is contained in:
2026-04-26 23:47:49 +02:00
parent 1b95f03d1e
commit b073e009d8
5288 changed files with 1112699 additions and 55536 deletions

View File

@@ -0,0 +1,340 @@
<?php
namespace SmashBalloon\YouTubeFeed\Services\Admin\Settings;
use SmashBalloon\YouTubeFeed\Helpers\Util;
class AboutPage extends BaseSettingPage {
protected $menu_slug = 'about';
protected $menu_title = 'About Us';
protected $page_title = 'About Us';
protected $has_menu = true;
protected $template_file = 'settings.index';
protected $has_assets = true;
protected $menu_position = 4;
protected $menu_position_free_version = 4;
public function register() {
parent::register();
add_filter( 'sby_localized_settings', [ $this, 'filter_settings_object' ] );
add_action( 'wp_ajax_sby_install_addon', [ $this, 'ajax_install_addon' ] );
add_action( 'wp_ajax_sby_activate_addon', [ $this, 'ajax_activate_addon' ] );
}
public function ajax_activate_addon() {
Util::ajaxPreflightChecks();
// Check for permissions.
if ( ! current_user_can( 'activate_plugins' ) ) {
wp_send_json_error();
}
if ( isset( $_POST['plugin'] ) ) {
$type = 'addon';
if ( ! empty( $_POST['type'] ) ) {
$type = sanitize_key( $_POST['type'] );
}
$activate = activate_plugins( preg_replace( '/[^a-z-_\/]/', '', wp_unslash( str_replace( '.php', '', $_POST['plugin'] ) ) ) . '.php' );
if ( ! is_wp_error( $activate ) ) {
if ( 'plugin' === $type ) {
wp_send_json_success( esc_html__( 'Plugin activated.', 'feeds-for-youtube' ) );
} else {
wp_send_json_success( esc_html__( 'Addon activated.', 'feeds-for-youtube' ) );
}
}
}
wp_send_json_error( esc_html__( 'Could not activate addon. Please activate from the Plugins page.', 'feeds-for-youtube' ) );
}
public function ajax_install_addon() {
// Run a security check.
Util::ajaxPreflightChecks();
// Check for permissions.
if ( ! current_user_can( 'install_plugins' ) ) {
wp_send_json_error();
}
$error = esc_html__( 'Could not install addon. Please download from wpforms.com and install manually.', 'feeds-for-youtube' );
if ( empty( $_POST['plugin'] ) ) {
wp_send_json_error( $error );
}
// Only install plugins from the .org repo
if ( strpos( $_POST['plugin'], 'https://downloads.wordpress.org/plugin/' ) !== 0 ) {
wp_send_json_error( $error );
}
// Set the current screen to avoid undefined notices.
set_current_screen( 'youtube-feed-about' );
// Prepare variables.
$url = esc_url_raw(
add_query_arg(
array(
'page' => 'youtube-feed-about',
),
admin_url( 'admin.php' )
)
);
$creds = request_filesystem_credentials( $url, '', false, false, null );
// Check for file system permissions.
if ( false === $creds ) {
wp_send_json_error( $error );
}
if ( ! WP_Filesystem( $creds ) ) {
wp_send_json_error( $error );
}
/*
* We do not need any extra credentials if we have gotten this far, so let's install the plugin.
*/
// Do not allow WordPress to search/download translations, as this will break JS output.
remove_action( 'upgrader_process_complete', array( 'Language_Pack_Upgrader', 'async_upgrade' ), 20 );
if(!class_exists("Plugin_Upgrader")) {
include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
include_once ABSPATH . 'wp-admin/includes/class-plugin-upgrader.php';
include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader-skin.php';
}
// Create the plugin upgrader with our custom skin.
$installer = new \Plugin_Upgrader( new \WP_Upgrader_Skin() );
// Error check.
if ( empty( $_POST['plugin'] ) ) {
wp_send_json_error( $error );
}
$installer->install( esc_url_raw( wp_unslash( $_POST['plugin'] ) ) );
// Flush the cache and return the newly installed plugin basename.
wp_cache_flush();
$plugin_basename = $installer->plugin_info();
if ( $plugin_basename ) {
$type = 'addon';
if ( ! empty( $_POST['type'] ) ) {
$type = sanitize_key( $_POST['type'] );
}
// Activate the plugin silently.
$activated = activate_plugin( $plugin_basename );
if ( ! is_wp_error( $activated ) ) {
wp_send_json_success(
array(
'msg' => 'plugin' === $type ? esc_html__( 'Plugin installed & activated.', 'feeds-for-youtube' ) : esc_html__( 'Addon installed & activated.', 'feeds-for-youtube' ),
'is_activated' => true,
'basename' => $plugin_basename,
)
);
} else {
wp_send_json_success(
array(
'msg' => 'plugin' === $type ? esc_html__( 'Plugin installed.', 'feeds-for-youtube' ) : esc_html__( 'Addon installed.', 'feeds-for-youtube' ),
'is_activated' => false,
'basename' => $plugin_basename,
)
);
}
}
wp_send_json_error( $error );
}
public function filter_settings_object( $settings ) {
$sb_other_plugins = sby_get_active_plugins_info();
$installed_plugins = $sb_other_plugins['installed_plugins'];
$license_key = get_option( 'sby_license_key', null );
$settings['pluginInfo'] = [
"plugins" => [
'facebook' => array(
'plugin' => $sb_other_plugins['facebook_plugin'],
'download_plugin' => 'https://downloads.wordpress.org/plugin/custom-facebook-feed.zip',
'title' => __( 'Facebook Feeds', 'feeds-for-youtube' ),
'description' => __( 'Get in depth analytics on all your social feeds in a single place', 'feeds-for-youtube' ),
'icon' => 'fb-icon.svg',
'installed' => isset( $sb_other_plugins['is_facebook_installed'] ) && $sb_other_plugins['is_facebook_installed'] == true,
'activated' => is_plugin_active( $sb_other_plugins['facebook_plugin'] ),
),
'instagram' => array(
'plugin' => $sb_other_plugins['instagram_plugin'],
'download_plugin' => 'https://downloads.wordpress.org/plugin/instagram-feed.zip',
'title' => __( 'Instagram Feeds', 'feeds-for-youtube' ),
'description' => __( 'Display customizable Instagram feeds in WordPress', 'feeds-for-youtube' ),
'icon' => 'insta-icon.svg',
'installed' => isset( $sb_other_plugins['is_instagram_installed'] ) && $sb_other_plugins['is_instagram_installed'] == true,
'activated' => is_plugin_active( $sb_other_plugins['instagram_plugin'] ),
),
'twitter' => array(
'plugin' => $sb_other_plugins['twitter_plugin'],
'download_plugin' => 'https://downloads.wordpress.org/plugin/custom-twitter-feeds.zip',
'title' => __( 'Twitter Feeds', 'feeds-for-youtube' ),
'description' => __( 'Display customizable Twitter feeds in WordPress', 'feeds-for-youtube' ),
'icon' => 'twitter-icon.svg',
'installed' => isset( $sb_other_plugins['is_twitter_installed'] ) && $sb_other_plugins['is_twitter_installed'] == true,
'activated' => is_plugin_active( $sb_other_plugins['twitter_plugin'] ),
),
'youtube' => array(
'plugin' => $sb_other_plugins['youtube_plugin'],
'download_plugin' => 'https://downloads.wordpress.org/plugin/feeds-for-youtube.zip',
'title' => __( 'YouTube Feeds', 'feeds-for-youtube' ),
'description' => __( 'Display customizable YouTube feeds in WordPress', 'feeds-for-youtube' ),
'icon' => 'youtube-icon.svg',
'installed' => isset( $sb_other_plugins['is_youtube_installed'] ) && $sb_other_plugins['is_youtube_installed'] == true,
'activated' => is_plugin_active( $sb_other_plugins['youtube_plugin'] ),
),
'tiktok' => array(
'plugin' => $sb_other_plugins['tiktok_plugin'],
'download_plugin' => 'https://downloads.wordpress.org/plugin/feeds-for-tiktok.zip',
'title' => __( 'Tiktok Feeds', 'feeds-for-youtube' ),
'description' => __( 'Display customizable TikTok feeds in WordPress', 'feeds-for-youtube' ),
'icon' => 'tiktok-icon.svg',
'installed' => isset( $sb_other_plugins['is_tiktok_installed'] ) && $sb_other_plugins['is_tiktok_installed'] == true,
'activated' => is_plugin_active( $sb_other_plugins['tiktok_plugin'] ),
),
],
'social_wall' => array(
'plugin' => 'social-wall/social-wall.php',
'title' => __( 'Social Wall', 'feeds-for-youtube' ),
'description' => __( 'Connect all social feeds in a single feed with Social Wall', 'feeds-for-youtube' ),
'graphic' => 'social-wall-graphic.png',
'icon' => 'reviews-icon.svg',
'permalink' => sprintf( 'https://smashballoon.com/social-wall/demo?edd_license_key=%s&upgrade=true&utm_campaign='. sby_utm_campaign() .'&utm_source=about&utm_medium=social-wall', $license_key ),
'permalink_text' => __( 'See Demo', 'feeds-for-youtube' ),
'installed' => isset( $sb_other_plugins['is_social_wall_installed'] ) && $sb_other_plugins['is_social_wall_installed'] == true,
'activated' => is_plugin_active( $sb_other_plugins['social_wall_plugin'] ),
),
'reviews' => array(
'plugin' => $sb_other_plugins['reviews_plugin'],
'download_plugin' => 'https://downloads.wordpress.org/plugin/reviews-feed.zip',
'title' => __( 'Reviews Feeds', 'feeds-for-youtube' ),
'description' => __( 'Display customizable Reviews feeds in WordPress', 'feeds-for-youtube' ),
'icon' => 'reviews-icon.svg',
'installed' => isset( $sb_other_plugins['is_reviews_installed'] ) && $sb_other_plugins['is_reviews_installed'] == true,
'activated' => is_plugin_active( $sb_other_plugins['reviews_plugin'] ),
),
'click_social' => array(
'plugin' => $sb_other_plugins['click_social_plugin'],
'download_plugin' => 'https://downloads.wordpress.org/plugin/click-social.zip',
'title' => __( 'ClickSocial', 'feeds-for-youtube' ),
'description' => __( 'Effortlessly manage your social media presence directly within WordPress. ', 'feeds-for-youtube' ),
'icon' => 'click-social-icon.svg',
'installed' => isset( $sb_other_plugins['is_click_social_installed'] ) && $sb_other_plugins['is_click_social_installed'] == true,
'activated' => is_plugin_active( $sb_other_plugins['click_social_plugin'] ),
),
'feed_analytics' => array(
'plugin' => $sb_other_plugins['click_social_plugin'],
'download_plugin' => '',
'title' => __( 'Feed Analytics', 'feeds-for-youtube' ),
'description' => __( 'Get in depth analytics on all your social feeds in a single place', 'feeds-for-youtube' ),
'icon' => 'feed-analytics-icon.svg',
'permalink' => sprintf( 'https://smashballoon.com/social-wall/demo?edd_license_key=%s&upgrade=true&utm_campaign='. sby_utm_campaign() .'&utm_source=about&utm_medium=social-wall', $license_key ),
'permalink_text' => __( 'See Demo', 'feeds-for-youtube' ),
'installed' => isset( $sb_other_plugins['is_click_social_installed'] ) && $sb_other_plugins['is_click_social_installed'] == true,
'activated' => is_plugin_active( $sb_other_plugins['click_social_plugin'] ),
),
'recommendedPlugins' => array(
'aioseo' => array(
'plugin' => 'all-in-one-seo-pack/all_in_one_seo_pack.php',
'download_plugin' => 'https://downloads.wordpress.org/plugin/all-in-one-seo-pack.zip',
'title' => __('All in One SEO Pack', 'feeds-for-youtube'),
'description' => __('The original WordPress SEO plugin and toolkit that improves your website\'s search rankings. Comes with all the SEO features like Local SEO, WooCommerce SEO, sitemaps, SEO optimizer, schema, and more.', 'feeds-for-youtube'),
'icon' => 'plugin-seo.png',
'installed' => isset( $installed_plugins['all-in-one-seo-pack/all_in_one_seo_pack.php'] ) ? true : false,
'activated' => is_plugin_active('all-in-one-seo-pack/all_in_one_seo_pack.php'),
'installs_number' => __('3 Million+ Installs', 'feeds-for-youtube')
),
'wpforms' => array(
'plugin' => 'wpforms-lite/wpforms.php',
'download_plugin' => 'https://downloads.wordpress.org/plugin/wpforms-lite.zip',
'title' => __('WPForms', 'feeds-for-youtube'),
'description' => __('The best drag & drop WordPress form builder. Easily create beautiful contact forms, surveys, payment forms, and more with our 900+ form templates. Trusted by over 6 million websites as the best forms plugin.', 'feeds-for-youtube'),
'icon' => 'plugin-wpforms.png',
'installed' => isset( $installed_plugins['wpforms-lite/wpforms.php'] ) ? true : false,
'activated' => is_plugin_active('wpforms-lite/wpforms.php'),
'installs_number' => __('6 Million+ Installs', 'feeds-for-youtube')
),
'monsterinsights' => array(
'plugin' => 'google-analytics-for-wordpress/googleanalytics.php',
'download_plugin' => 'https://downloads.wordpress.org/plugin/google-analytics-for-wordpress.zip',
'title' => __('MonsterInsights', 'feeds-for-youtube'),
'description' => __('The leading WordPress analytics plugin that shows you how people find and use your website, so you can make data driven decisions to grow your business. Properly set up Google Analytics without writing code.', 'feeds-for-youtube'),
'icon' => 'plugin-mi.png',
'installed' => isset( $installed_plugins['google-analytics-for-wordpress/googleanalytics.php'] ) ? true : false,
'activated' => is_plugin_active('google-analytics-for-wordpress/googleanalytics.php'),
'installs_number' => __('3 Million+ Installs', 'feeds-for-youtube')
),
'optinmonster' => array(
'plugin' => 'optinmonster/optin-monster-wp-api.php',
'download_plugin' => 'https://downloads.wordpress.org/plugin/optinmonster.zip',
'title' => __('OptinMonster', 'feeds-for-youtube'),
'description' => __('Instantly get more subscribers, leads, and sales with the #1 conversion optimization toolkit. Create high converting popups, announcement bars, spin a wheel, and more with smart targeting and personalization.', 'feeds-for-youtube'),
'icon' => 'plugin-om.png',
'installed' => isset( $installed_plugins['optinmonster/optin-monster-wp-api.php'] ) ? true : false,
'activated' => is_plugin_active('optinmonster/optin-monster-wp-api.php'),
'installs_number' => __('1 Million+ Installs', 'feeds-for-youtube')
),
'wp_mail_smtp' => array(
'plugin' => 'wp-mail-smtp/wp_mail_smtp.php',
'download_plugin' => 'https://downloads.wordpress.org/plugin/wp-mail-smtp.zip',
'title' => __('WP Mail SMTP', 'feeds-for-youtube'),
'description' => __('Improve your WordPress email deliverability and make sure that your website emails reach user\'s inbox with the #1 SMTP plugin for WordPress. Over 3 million websites use it to fix WordPress email issues.', 'feeds-for-youtube'),
'icon' => 'plugin-smtp.png',
'installed' => isset( $installed_plugins['wp-mail-smtp/wp_mail_smtp.php'] ) ? true : false,
'activated' => is_plugin_active('wp-mail-smtp/wp_mail_smtp.php'),
'installs_number' => __('3 Million+ Installs', 'feeds-for-youtube')
),
'rafflepress' => array(
'plugin' => 'rafflepress/rafflepress.php',
'download_plugin' => 'https://downloads.wordpress.org/plugin/rafflepress.zip',
'title' => __('RafflePress', 'feeds-for-youtube'),
'description' => __('Turn your website visitors into brand ambassadors! Easily grow your email list, website traffic, and social media followers with the most powerful giveaways & contests plugin for WordPress.', 'feeds-for-youtube'),
'icon' => 'plugin-rp.png',
'installed' => isset( $installed_plugins['rafflepress/rafflepress.php'] ) ? true : false,
'activated' => is_plugin_active('rafflepress/rafflepress.php'),
'installs_number' => __('20 Thousand+ Installs', 'feeds-for-youtube')
),
'seedprod' => array(
'plugin' => 'coming-soon/coming-soon.php',
'download_plugin' => 'https://downloads.wordpress.org/plugin/coming-soon.zip',
'title' => __('SeedProd Website Builder', 'feeds-for-youtube'),
'description' => __('The fastest drag & drop landing page builder for WordPress. Create custom landing pages without writing code, connect a CRM, collect subscribers, and grow an audience. Trusted by 1 million sites.', 'feeds-for-youtube'),
'icon' => 'plugin-seedprod.png',
'installed' => isset( $installed_plugins['coming-soon/coming-soon.php'] ) ? true : false,
'activated' => is_plugin_active('coming-soon/coming-soon.php'),
'installs_number' => __('800 Thousand+ Installs', 'feeds-for-youtube')
),
'pushengage' => array(
'plugin' => 'pushengage/main.php',
'download_plugin' => 'https://downloads.wordpress.org/plugin/pushengage.zip',
'title' => __('PushEngage Web Push Notifications', 'feeds-for-youtube'),
'description' => __('Connect with your visitors after they leave your website with the leading web push notification software. Over 10,000+ businesses worldwide use PushEngage to send 15 billion notifications each month.', 'feeds-for-youtube'),
'icon' => 'plugin-push.png',
'installed' => isset( $installed_plugins['pushengage/main.php'] ) ? true : false,
'activated' => is_plugin_active('pushengage/main.php'),
'installs_number' => __('10 Thousand+ Installs', 'feeds-for-youtube')
)
),
];
return $settings;
}
}

View File

@@ -0,0 +1,129 @@
<?php
namespace SmashBalloon\YouTubeFeed\Services\Admin\Settings;
use Smashballoon\Customizer\Feed_Builder;
use Smashballoon\Stubs\Services\ServiceProvider;
use SmashBalloon\YouTubeFeed\Admin\SBY_Notifications;
use SmashBalloon\YouTubeFeed\Container;
use SmashBalloon\YouTubeFeed\Helpers\Util;
use SmashBalloon\YouTubeFeed\Pro\SBY_CPT;
use SmashBalloon\YouTubeFeed\SBY_View;
use Smashballoon\Customizer\YouTube_License_Tier;
abstract class BaseSettingPage extends ServiceProvider {
protected $has_menu = false;
protected $has_assets = false;
protected $page_title = "";
protected $menu_title = "";
protected $menu_slug = "";
protected $template_file = "";
protected $menu_position = 0;
protected $has_page_restriction = false;
protected $menu_position_free_version = 0;
public function register() {
if ( true === $this->has_menu ) {
add_action('admin_menu', [$this, 'register_menu_page']);
}
if ( ( true === $this->has_assets ) && isset( $_GET['page'] ) && false !== strpos( $_GET['page'],
SBY_SLUG . '-' . $this->menu_slug ) ) {
add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_assets' ] );
}
}
public function render() {
SBY_View::render($this->template_file);
}
public function enqueue_assets() {
wp_enqueue_style(
'sby-global-style',
CUSTOMIZER_PLUGIN_URL . 'assets/css/global.css',
false,
SBYVER
);
//settings page script
$script_file = SBY_PLUGIN_URL . 'frontend/build/static/js/main.js';
if ( ! Util::isProduction() ) {
$script_file = "http://localhost:3000/static/js/main.js";
} else {
wp_enqueue_style(
'sby-settings-style',
SBY_PLUGIN_URL . 'frontend/build/static/css/main.css',
false,
SBYVER
);
}
wp_enqueue_script(
'sby-settings',
$script_file,
array( 'wp-i18n' ),
SBYVER,
true
);
wp_localize_script(
'sby-settings',
'sby_settings',
$this->get_settings_object()
);
wp_set_script_translations('sby-settings', 'feeds-for-youtube', SBY_PLUGIN_DIR . 'languages/');
}
public function register_menu_page() {
$menu_slug = SBY_SLUG . '-' . $this->menu_slug;
if ($this->has_page_restriction) {
$menu_slug = 'admin.php?page=sby-feed-builder&tab=more';
}
add_submenu_page(
SBY_MENU_SLUG,
$this->page_title,
$this->menu_title,
'manage_options',
$menu_slug,
[$this, 'render'],
$this->menu_position
);
}
private function get_notifications() {
return Container::get_instance()->get(SBY_Notifications::class)->output_return();
}
protected function get_settings_object() {
return apply_filters( 'sby_localized_settings', [
'admin_url' => admin_url(),
'ajax_handler' => admin_url( 'admin-ajax.php' ),
'nonce' => wp_create_nonce( 'sby-admin' ),
'setupPageUrl' => admin_url( 'admin.php?page=youtube-feed-setup' ),
'supportPageUrl' => admin_url( 'admin.php?page=youtube-feed-support' ),
'settingsPageUrl' => admin_url( 'admin.php?page=youtube-feed-settings' ),
'builderUrl' => admin_url( 'admin.php?page=sby-feed-builder' ),
'connectionURL' => Feed_Builder::oauth_connet_url(),
'manageLicense' => 'https://smashballoon.com/account/downloads/?utm_campaign='. sby_utm_campaign() .'&utm_source=settings&utm_medium=manage-license',
'single_video_settings' => sby_is_pro() ? SBY_CPT::get_sby_cpt_settings() : [],
'single_video_admin_url' => admin_url("admin.php?page=youtube-feed-settings#/single-videos"),
'pluginItemName' => SBY_PLUGIN_EDD_NAME,
'licenseType' => 'pro',
'socialWallLinks' => Feed_Builder::get_social_wall_links(),
'socialWallActivated' => is_plugin_active( 'social-wall/social-wall.php' ),
'genericText' => Feed_Builder::get_generic_text(),
'licenseTierFeatures' => (new YouTube_License_Tier)->tier_features(),
'tooltipHelpSvg' => '<svg width="20" height="21" viewBox="0 0 20 21" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M9.1665 8H10.8332V6.33333H9.1665V8ZM9.99984 17.1667C6.32484 17.1667 3.33317 14.175 3.33317 10.5C3.33317 6.825 6.32484 3.83333 9.99984 3.83333C13.6748 3.83333 16.6665 6.825 16.6665 10.5C16.6665 14.175 13.6748 17.1667 9.99984 17.1667ZM9.99984 2.16666C8.90549 2.16666 7.82186 2.38221 6.81081 2.801C5.79976 3.21979 4.8811 3.83362 4.10728 4.60744C2.54448 6.17024 1.6665 8.28986 1.6665 10.5C1.6665 12.7101 2.54448 14.8298 4.10728 16.3926C4.8811 17.1664 5.79976 17.7802 6.81081 18.199C7.82186 18.6178 8.90549 18.8333 9.99984 18.8333C12.21 18.8333 14.3296 17.9554 15.8924 16.3926C17.4552 14.8298 18.3332 12.7101 18.3332 10.5C18.3332 9.40565 18.1176 8.32202 17.6988 7.31097C17.28 6.29992 16.6662 5.38126 15.8924 4.60744C15.1186 3.83362 14.1999 3.21979 13.1889 2.801C12.1778 2.38221 11.0942 2.16666 9.99984 2.16666ZM9.1665 14.6667H10.8332V9.66666H9.1665V14.6667Z" fill="#434960"/></svg>',
'svgIcons' => Feed_Builder::builder_svg_icons(),
'smashBalloonInfo' => Feed_Builder::get_smashballoon_info(),
'assetsURL' => SBY_PLUGIN_URL . 'frontend/build',
'notifications' => $this->get_notifications(),
'shouldShowPostGracePeriodNotice' => Util::expiredLicenseWithGracePeriodEnded(),
'isLicenseInactive' => empty( Util::get_license_key() ),
] );
}
}

View File

@@ -0,0 +1,342 @@
<?php
namespace SmashBalloon\YouTubeFeed\Services\Admin\Settings;
use Smashballoon\Customizer\Container;
use Smashballoon\Customizer\Feed_Builder;
use SmashBalloon\YouTubeFeed\Builder\SBY_Feed_Builder;
use SmashBalloon\YouTubeFeed\SBY_Settings;
class HelpPage extends BaseSettingPage {
protected $menu_slug = 'support';
protected $menu_title = 'Support';
protected $page_title = 'Support';
protected $has_menu = true;
protected $template_file = 'settings.index';
protected $has_assets = true;
protected $menu_position = 3;
protected $menu_position_free_version = 3;
/**
* @var Feed_Builder
*/
private $feed_builder;
public function __construct() {
$this->feed_builder = Container::getInstance()->get(Feed_Builder::class);
}
public function register() {
parent::register();
add_filter( 'sby_localized_settings', [ $this, 'filter_settings_object' ] );
}
public static function get_whitespace( $times ) {
return str_repeat( '&nbsp;', $times );
}
public function filter_settings_object( $settings ) {
$settings['system_info'] = $this->get_system_info();
$settings['system_info_n'] = str_replace( '<br />', "\n", $this->get_system_info() );
$settings['feeds'] = Container::getInstance()->get(Feed_Builder::class)->get_feed_list();
return $settings;
}
public function get_system_info() {
$output = '';
// Build the output strings
$output .= $this->get_site_n_server_info();
$output .= $this->get_active_plugins_info();
$output .= $this->get_global_settings_info();
$output .= $this->get_feeds_settings_info();
$output .= $this->get_sources_info();
$output .= $this->get_cron_report();
return $output;
}
/**
* Get Site and Server Info
*
* @since 6.0
*
* @return string
*/
public function get_site_n_server_info() {
$allow_url_fopen = ini_get( 'allow_url_fopen' ) ? 'Yes' : 'No';
$php_curl = is_callable( 'curl_init' ) ? 'Yes' : 'No';
$php_json_decode = function_exists( 'json_decode' ) ? 'Yes' : 'No';
$php_ssl = in_array( 'https', stream_get_wrappers(), true ) ? 'Yes' : 'No';
$settings = sby_get_database_settings();
$api_verification_status = get_option('sby_api_key_verification', null);
$output = '## SITE/SERVER INFO: ##<br />';
$output .= 'Plugin Version:' . self::get_whitespace( 11 ) . esc_html( SBY_PLUGIN_NAME ) . '<br />';
$output .= 'Site URL:' . self::get_whitespace( 17 ) . esc_html( site_url() ) . '<br />';
$output .= 'Home URL:' . self::get_whitespace( 17 ) . esc_html( home_url() ) . '<br />';
$output .= 'WordPress Version:' . self::get_whitespace( 8 ) . esc_html( get_bloginfo( 'version' ) ) . '<br />';
$output .= 'PHP Version:' . self::get_whitespace( 14 ) . esc_html( PHP_VERSION ) . '<br />';
$output .= 'Web Server Info:' . self::get_whitespace( 10 ) . esc_html( $_SERVER['SERVER_SOFTWARE'] ) . '<br />';
$output .= 'PHP allow_url_fopen:' . self::get_whitespace( 6 ) . esc_html( $allow_url_fopen ) . '<br />';
$output .= 'PHP cURL:' . self::get_whitespace( 17 ) . esc_html( $php_curl ) . '<br />';
$output .= 'JSON:' . self::get_whitespace( 21 ) . esc_html( $php_json_decode ) . '<br />';
$output .= 'SSL Stream:' . self::get_whitespace( 15 ) . esc_html( $php_ssl ) . '<br />';
$output .= 'API Key:' . self::get_whitespace( 18 ) . esc_html( isset($settings['api_key']) ? $settings['api_key'] : 'Empty' ) . '<br />';
$output .= 'API Status:' . self::get_whitespace( 15 ) . esc_html( !empty($api_verification_status) ? ($api_verification_status->status == true ? "Successful" : "Failed") : 'Unknown' ) . '<br />';
$output .= '<br />';
return $output;
}
/**
* Get Active Plugins
*
* @since 6.0
*
* @return string
*/
public function get_active_plugins_info() {
$plugins = get_plugins();
$active_plugins = get_option( 'active_plugins' );
$output = '## ACTIVE PLUGINS: ## <br />';
foreach ( $plugins as $plugin_path => $plugin ) {
if ( in_array( $plugin_path, $active_plugins, true ) ) {
$output .= esc_html( $plugin['Name'] ) . ': ' . esc_html( $plugin['Version'] ) . '<br />';
}
}
$output .= '<br />';
return $output;
}
/**
* Get Global Settings
*
* @since 6.0
*
* @return string
*/
public function get_global_settings_info() {
$output = '## GLOBAL SETTINGS: ## <br />';
$sby_license_key = get_option( 'sby_license_key' );
$sby_license_data = get_option( 'sby_license_data' );
$sby_license_status = get_option( 'sby_license_status' );
$sby_settings = get_option( 'settings', array() );
$usage_tracking = get_option(
'sby_usage_tracking',
array(
'last_send' => 0,
'enabled' => \sby_is_pro_version(),
)
);
$output .= 'License key: ';
if ( $sby_license_key ) {
$output .= esc_html( $sby_license_key );
} else {
$output .= ' Not added';
}
$output .= '<br />';
$output .= 'License status: ';
if ( $sby_license_status ) {
$output .= $sby_license_status;
} else {
$output .= ' Inactive';
}
$output .= '<br />';
$output .= 'Preserve settings if plugin is removed: ';
$output .= isset( $sby_settings['preserve_settings'] ) && ( $sby_settings['preserve_settings'] ) ? 'Yes' : 'No';
$output .= '<br />';
$output .= 'Connected Accounts: ';
$output .= 'Placeholder!';
$output .= '<br />';
$output .= 'Caching: ';
if ( wp_next_scheduled( 'sby_feed_update' ) ) {
$time_format = get_option( 'time_format' );
if ( ! $time_format ) {
$time_format = 'g:i a';
}
//
$schedule = wp_get_schedule( 'sby_feed_update' );
if ( $schedule === '30mins' ) {
$schedule = __( 'every 30 minutes', 'feeds-for-youtube' );
}
if ( $schedule === 'twicedaily' ) {
$schedule = __( 'every 12 hours', 'feeds-for-youtube' );
}
$sby_next_cron_event = wp_next_scheduled( 'sby_feed_update' );
$output = __( 'Next check', 'feeds-for-youtube' ) . ': ' . gmdate( $time_format, $sby_next_cron_event + sby_get_utc_offset() ) . ' (' . $schedule . ')';
} else {
$output .= 'Nothing currently scheduled';
}
$output .= '<br />';
$output .= 'GDPR: ';
$output .= isset( $sby_settings['gdpr'] ) ? $sby_settings['gdpr'] : ' Not setup';
$output .= '<br />';
$output .= 'Custom CSS: ';
$output .= isset( $sby_settings['custom_css'] ) && ! empty( $sby_settings['custom_css'] ) ? $sby_settings['custom_css'] : 'Empty';
$output .= '<br />';
$output .= 'Custom JS: ';
$output .= isset( $sby_settings['custom_js'] ) && ! empty( $sby_settings['custom_js'] ) ? $sby_settings['custom_js'] : 'Empty';
$output .= '<br />';
$output .= 'Usage Tracking: ';
$output .= isset( $usage_tracking['enabled'] ) && $usage_tracking['enabled'] === true ? 'Enabled' : 'Disabled';
$output .= '<br />';
$output .= 'AJAX theme loading fix: ';
$output .= isset( $sby_settings['ajax_theme'] ) && $sby_settings['ajax_theme'] ? 'Enabled' : 'Disabled';
$output .= '<br />';
$output .= 'AJAX Initial: ';
$output .= isset( $sby_settings['sb_ajax_initial'] ) && $sby_settings['sb_ajax_initial'] === true ? 'Enabled' : 'Disabled';
$output .= '<br />';
$output .= 'Enqueue in Head: ';
$output .= isset( $sby_settings['enqueue_js_in_head'] ) && $sby_settings['enqueue_js_in_head'] === true ? 'Enabled' : 'Disabled';
$output .= '<br />';
$output .= 'Disable WP Posts: ';
$output .= !empty($sby_settings['disable_wp_posts']) ? 'True' : 'False';;
$output .= '<br />';
$output .= 'Enqueue in Shortcode: ';
$output .= isset( $sby_settings['enqueue_css_in_shortcode'] ) && $sby_settings['enqueue_css_in_shortcode'] === true ? 'Enabled' : 'Disabled';
$output .= '<br />';
$output .= 'Enable JS Image: ';
$output .= isset( $sby_settings['disable_js_image_loading'] ) && $sby_settings['disable_js_image_loading'] === false ? 'Enabled' : 'Disabled';
$output .= '<br />';
$output .= 'Admin Error Notice: ';
$output .= isset( $sby_settings['disable_admin_notice'] ) && $sby_settings['disable_admin_notice'] === false ? 'Enabled' : 'Disabled';
$output .= '<br />';
return $output;
}
/**
* Get Feeds Settings
*
* @since 6.0
*
* @return string
*/
public function get_feeds_settings_info() {
$output = '## FEEDS: ## <br />';
$feeds_list = $this->feed_builder->get_feed_list();
$i = 0;
foreach ( $feeds_list as $feed ) {
$settings = json_decode($feed['settings'], true);
$type = ! empty( $settings['type'] ) ? $settings['type'] : 'channel';
if ( $i >= 25 ) {
break;
}
$output .= $feed['feed_name'];
$output .= '<br />';
if ( isset( $feed['location_summary'] ) && count( $feed['location_summary'] ) > 0 ) {
$first_feed = $feed['location_summary'][0];
if ( ! empty( $first_feed['link'] ) ) {
$output .= esc_html( $first_feed['link'] ) . '?sb_debug';
$output .= '<br />';
}
}
if ( $i < ( count( $feeds_list ) - 1 ) ) {
$output .= '<br />';
}
$i++;
}
$output .= '<br />';
return $output;
}
/**
* Get Feeds Settings
*
* @since 6.0
*
* @return string
*/
public function get_sources_info() {
$output = '## Sources: ## <br />';
foreach ( [] as $source ) {
$output .= $source['account_id'];
$output .= '<br />';
$output .= 'Type: ' . esc_html( $source['account_type'] );
$output .= '<br />';
$output .= 'Username: ' . esc_html( $source['username'] );
$output .= '<br />';
$output .= 'Error: ' . esc_html( $source['error'] );
$output .= '<br />';
$output .= '<br />';
$output .= '<br />';
}
$output .= '<br />';
return $output;
}
/**
* Get Reports
*
* @since 6.0
*
* @return string
*/
public function get_cron_report() {
$output = '## Cron Cache Report: ## <br />';
$cron_report = get_option( 'sby_cron_report', array() );
if ( ! empty( $cron_report ) ) {
$output .= 'Time Ran: ' . esc_html( $cron_report['notes']['time_ran'] );
$output .= '<br />';
$output .= 'Found Feeds: ' . esc_html( $cron_report['notes']['num_found_transients'] );
$output .= '<br />';
$output .= '<br />';
foreach ( $cron_report as $key => $value ) {
if ( $key !== 'notes' ) {
$output .= esc_html( $key ) . ':';
$output .= '<br />';
if ( ! empty( $value['last_retrieve'] ) ) {
$output .= 'Last Retrieve: ' . esc_html( $value['last_retrieve'] );
$output .= '<br />';
}
$output .= 'Did Update: ' . esc_html( $value['did_update'] );
$output .= '<br />';
$output .= '<br />';
}
}
} else {
$output .= '<br />';
}
$cron = _get_cron_array();
foreach ( $cron as $key => $data ) {
$is_target = false;
foreach ( $data as $key2 => $val ) {
if ( strpos( $key2, 'sby' ) !== false || strpos( $key2, 'sb_youtube' ) !== false ) {
$is_target = true;
$output .= esc_html( $key2 );
$output .= '<br />';
}
}
if ( $is_target ) {
$output .= esc_html( date( 'Y-m-d H:i:s', $key ) );
$output .= '<br />';
$output .= esc_html( 'Next Scheduled: ' . round( ( (int) $key - time() ) / 60 ) . ' minutes' );
$output .= '<br />';
$output .= '<br />';
}
}
return $output;
}
}

View File

@@ -0,0 +1,23 @@
<?php
namespace SmashBalloon\YouTubeFeed\Services\Admin\Settings;
use Smashballoon\Stubs\Services\ServiceProvider;
use SmashBalloon\YouTubeFeed\Container;
class PagesServiceContainer extends ServiceProvider {
private $services = [
SettingsPage::class,
SingleVideoPage::class,
HelpPage::class,
AboutPage::class,
SetupPage::class,
];
public function register() {
$container = Container::get_instance();
foreach ( $this->services as $service ) {
$container->get($service)->register();
}
}
}

View File

@@ -0,0 +1,145 @@
<?php
namespace SmashBalloon\YouTubeFeed\Services\Admin\Settings;
use Smashballoon\Customizer\Container;
use Smashballoon\Customizer\Feed_Builder;
use Smashballoon\Customizer\Feed_Saver;
use SmashBalloon\YouTubeFeed\Helpers\Util;
use SmashBalloon\YouTubeFeed\Pro\SBY_CPT;
use SmashBalloon\YouTubeFeed\SBY_Settings;
class SettingsPage extends BaseSettingPage {
protected $has_assets = true;
protected $has_menu = true;
protected $template_file = 'settings.index';
/**
* @var SBY_Settings
*/
private $settings;
/**
* @var Feed_Saver
*/
private $feed_saver;
public function __construct( Feed_Saver $feed_saver, SBY_Settings $settings) {
$this->page_title = __( 'Settings', 'feeds-for-youtube' );
$this->menu_title = __( 'Settings', 'feeds-for-youtube' );
$this->menu_slug = 'settings';
$this->menu_position = 1;
$this->menu_position_free_version = 1;
$this->settings = $settings;
$this->feed_saver = $feed_saver;
}
public function register() {
parent::register();
add_action( 'wp_ajax_sby_update_settings', [ $this, 'handle_settings_update' ] );
add_filter( 'sby_localized_settings', [ $this, 'filter_settings_object' ] );
}
public function handle_settings_update() {
check_ajax_referer( 'sby-admin', 'nonce' );
if ( ! current_user_can( 'manage_options' ) ) {
wp_send_json_error();
}
$sanitization_skip = [
'custom_js'
];
unset( $_POST['nonce'] );
if ( ! current_user_can( 'unfiltered_html' ) ) {
unset($_POST['custom_css']);
unset($_POST['custom_js']);
}
$update_array = $_POST;
$this->handle_single_video_settings( $update_array );
foreach ( $_POST as $item => $value ) {
if ( ! in_array( $item, $sanitization_skip ) ) {
$update_array[ $item ] = sanitize_text_field( $value );
}
}
wp_clear_scheduled_hook('sby_feed_update');
if ( $this->settings->update_settings( $update_array ) ) {
wp_send_json_success();
} else {
wp_send_json_error();
}
}
private function handle_single_video_settings( &$settings ) {
$prefix = "single_video_info_";
$includes = [];
$post_status = "draft";
foreach ( $settings as $key => $setting ) {
if ( false !== strpos( $key, $prefix ) ) {
$setting_name = str_replace( $prefix, "", $key );
if ( ( $setting_name !== 'post_status' ) ) {
if ( $setting === "true" ) {
$includes[] = $setting_name;
}
} else {
$post_status = $setting;
}
unset( $settings[ $key ] );
}
}
update_option( SBY_CPT . '_settings', [
"include" => $includes,
"post_status" => $post_status
] );
}
private function get_next_cron_schedule() {
$timestamp = wp_next_scheduled('sby_feed_update');
$date = new \DateTime();
$date->setTimestamp($timestamp);
$date->setTimezone(wp_timezone());
$date_string = $date->format('h:i');
$settings = $this->settings->get_settings();
$interval = !empty($settings['cache_cron_interval']) ? $settings['cache_cron_interval'] : '1hour';
$am_pm = !empty($settings['cache_cron_am_pm']) ? $settings['cache_cron_am_pm'] : 'AM';
switch($interval) {
case '30mins':
$interval_string = __('every 30 minutes', 'feeds-for-youtube');
break;
case '12hours':
$interval_string = 'every 12 hours';
break;
case '24hours':
$interval_string = 'every 24 hours';
break;
default:
$interval_string = __('every hour', 'feeds-for-youtube');
}
return sprintf(__('<strong>Next check: %s %s (%s)</strong> - Note: Clicking "Clear All Caches" will reset this schedule.', 'feeds-for-youtube'), $date_string, strtoupper($am_pm), $interval_string);
}
public function filter_settings_object( $settings ) {
$settings['settings'] = $this->settings->get_settings();
$settings['sources'] = $this->feed_saver->get_source_list();
$settings['sbyIsPro'] = \sby_is_pro() ? true : false;
$settings['user_can_unfiltered_html'] = \current_user_can( 'unfiltered_html' ) ? true : false;
$settings['feeds'] = Container::getInstance()->get(Feed_Builder::class)->get_feed_list();
$settings['next_cron'] = $this->get_next_cron_schedule();
$settings['connect_site_parameters'] = sby_builder_pro()->oauth_connet_parameters();
return $settings;
}
}

View File

@@ -0,0 +1,289 @@
<?php
namespace SmashBalloon\YouTubeFeed\Services\Admin\Settings;
use Smashballoon\Customizer\Container;
use Smashballoon\Customizer\Feed_Builder;
use SmashBalloon\YouTubeFeed\Services\AdminAjaxService;
use SmashBalloon\YouTubeFeed\Helpers\Util;
class SetupPage extends BaseSettingPage
{
protected $menu_slug = 'setup';
protected $menu_title = 'Setup';
protected $page_title = 'Setup';
protected $has_menu = true;
protected $template_file = 'settings.index';
protected $has_assets = true;
protected $menu_position = 0;
protected $menu_position_free_version = 0;
static $plugin_name = 'youtube';
static $statues_name = 'sby_statuses';
/**
* Filter settings object
*
* @since 2.2.4
*
* @return void
*/
public function register()
{
if(! sby_is_pro() && self::should_init_wizard() ) {
parent::register();
add_action( 'wp_ajax_sby_process_wizard', [ $this, 'ajax_process_wizard' ] );
add_action( 'wp_ajax_sby_dismiss_wizard', [ $this, 'ajax_dismiss_wizard' ] );
add_filter('sby_localized_settings', [$this, 'filter_settings_object']);
}
}
/**
* Filter settings object
*
* @param array $settings
*
* @since 2.2.4
*
* @return array
*/
public function filter_settings_object($settings)
{
$settings['onboardWizardYoutubeAccountConnectURL'] = Feed_Builder::oauth_connet_url(admin_url('admin.php?page=youtube-feed-setup&step=2'));
return $settings;
}
/**
* Check if we need to Init the Onboarding wizard
*
* @since 2.2.4
*
* @return bool
*/
public static function should_init_wizard() {
$statues = get_option( self::$statues_name, array() );
if(!isset($statues['wizard_dismissed']) || $statues['wizard_dismissed'] === false ){
return true;
}
return false;
}
/**
* Install Plugin
*
* @param string $plugin_url
*
* @since 2.2.4
*
* @return void
*/
public static function install_single_plugin( $plugin_url ){
if( !$plugin_url || !current_user_can('install_plugins') ){
return false;
}
set_current_screen( 'youtube-feed-setup' );
// Prepare variables.
$url = esc_url_raw(
add_query_arg(
array(
'page' => 'youtube-feed-setup',
),
admin_url( 'admin.php' )
)
);
$creds = request_filesystem_credentials( $url, '', false, false, null );
// Check for file system permissions.
if ( false === $creds ) {
wp_send_json_error( $error );
}
if ( ! WP_Filesystem( $creds ) ) {
wp_send_json_error( $error );
}
/*
* We do not need any extra credentials if we have gotten this far, so let's install the plugin.
*/
require_once SBY_PLUGIN_DIR . 'inc/class-install-skin.php';
// Do not allow WordPress to search/download translations, as this will break JS output.
remove_action( 'upgrader_process_complete', array( 'Language_Pack_Upgrader', 'async_upgrade' ), 20 );
// Create the plugin upgrader with our custom skin.
$installer = new \SmashBalloon\YouTubeFeed\PluginSilentUpgrader( new \SmashBalloon\YouTubeFeed\SBY_Install_Skin() );
// Error check.
if ( ! method_exists( $installer, 'install' ) || empty( $plugin_url ) ) {
wp_send_json_error( $error );
}
$installer->install( esc_url_raw( wp_unslash( $plugin_url ) ) );
// Flush the cache and return the newly installed plugin basename.
wp_cache_flush();
$plugin_basename = $installer->plugin_info();
if ( $plugin_basename ) {
activate_plugin( $plugin_basename );
}
}
/**
* Process Wizard Data
* Save Settings, Install Plugins and more
*
* @since 2.2.4
*
* @return void
*/
public function ajax_process_wizard(){
Util::ajaxPreflightChecks();
if( ! isset( $_POST['data'] ) ){
wp_send_json_error();
}
// If in the future we need to support settings.
// $sby_settings = get_option( 'sby_settings', array() );
$onboarding_data = sanitize_text_field( stripslashes( $_POST['data'] ) );
$onboarding_data = json_decode( $onboarding_data, true);
foreach (array_keys($onboarding_data) as $key) {
// If in the future we need to support settings.
// if( !empty($key) && 'settings' === $key ){
// }
if( $key && 'plugins' === $key && !empty($onboarding_data[$key]) && current_user_can( 'install_plugins' ) ){
foreach ($onboarding_data[$key] as $single) {
if(!empty($single['url']) && !empty($single['slug'])) {
@self::install_single_plugin($single['url']);
$this->disable_installed_plugins_redirect($single['slug']);
}
}
}
}
// If in the future we need to support settings.
//update_option( 'sby_settings', $sby_settings );
}
/**
* Dismiss Onboarding Wizard
*
* @since 2.2.4
*
* @return void
*/
public function ajax_dismiss_wizard(){
Util::ajaxPreflightChecks();
$sby_statuses_option = get_option( 'sby_statuses', array() );
$sby_statuses_option['wizard_dismissed'] = true;
update_option( 'sby_statuses', $sby_statuses_option );
wp_send_json_error();
}
/**
* Disable Installed Plugins Redirect
*
* @param string $plugin_slug
*
* @since 2.2.4
*
* @return void
*/
public function disable_installed_plugins_redirect($plugin_slug){
//Monster Insight
if( 'monsterinsights' === $plugin_slug ) {
delete_transient( '_monsterinsights_activation_redirect' );
}
//All in one SEO
if( 'aioseo' === $plugin_slug ) {
update_option( 'aioseo_activation_redirect', true );
}
//WPForms
if( 'wpforms' === $plugin_slug ) {
update_option( 'wpforms_activation_redirect', true );
}
//Optin Monster
if( 'optinmonster' === $plugin_slug ) {
delete_transient( 'optin_monster_api_activation_redirect' );
update_option( 'optin_monster_api_activation_redirect_disabled', true );
}
//Seed PROD
if( 'seedprod' === $plugin_slug ) {
update_option( 'seedprod_dismiss_setup_wizard', true );
}
//PushEngage
if( 'pushengage' === $plugin_slug ) {
delete_transient( 'pushengage_activation_redirect' );
}
//WP SMTP
if( 'wp_mail_smtp' === $plugin_slug ) {
delete_transient( 'wp_mail_smtp_activation_redirect' );
}
//Rafflepress
if( 'rafflepress' === $plugin_slug ) {
delete_transient( '_rafflepress_welcome_screen_activation_redirect' );
}
//Smash Plugin redirect remove
$this->disable_smash_installed_plugins_redirect($plugin_slug);
}
/**
* Disable Smash Balloon Plugins Redirect
*
* @param string $plugin_slug
*
* @since 2.2.4
*
* @return void
*/
public function disable_smash_installed_plugins_redirect($plugin_slug)
{
$smash_list = [
'facebook' => 'cff_plugin_do_activation_redirect',
'instagram' => 'sbi_plugin_do_activation_redirect',
'youtube' => 'sby_plugin_do_activation_redirect',
'twitter' => 'ctf_plugin_do_activation_redirect',
'reviews' => 'sbr_plugin_do_activation_redirect',
];
if(!empty($smash_list[self::$plugin_name])){
unset($smash_list[self::$plugin_name]);
}
if (!empty($smash_list[$plugin_slug])) {
delete_option($smash_list[$plugin_slug]);
}
}
}

View File

@@ -0,0 +1,144 @@
<?php
namespace SmashBalloon\YouTubeFeed\Services\Admin\Settings;
use Smashballoon\Customizer\Feed_Builder;
use Smashballoon\Customizer\Feed_Saver;
use SmashBalloon\YouTubeFeed\Helpers\Util;
use SmashBalloon\YouTubeFeed\SBY_Settings;
use Smashballoon\Customizer\YouTube_License_Tier;
class SingleVideoPage extends BaseSettingPage {
protected $has_assets = true;
protected $has_menu = true;
protected $menu_slug = 'single-videos';
protected $template_file = 'settings.index';
protected $menu_position = 2;
protected $menu_position_free_version = 2;
private $posts_table;
private $meta_table;
public function __construct() {
$this->page_title = __('Single Videos', 'feeds-for-youtube');
$this->menu_title = __('Single Videos', 'feeds-for-youtube');
// YouTube license tier
$license_tier = new YouTube_License_Tier;
$license_tier_features = $license_tier->tier_features();
// Hide Single Videos page if feature is not available in the tier
if (!in_array('convert_videos_to_cpt', $license_tier_features)) {
$this->has_page_restriction = true;
$this->menu_title = '<span class="sby-single-videos-upsell">' . __('Single Videos', 'feeds-for-youtube') . '</span>';
}
}
public function register() {
global $wpdb;
parent::register();
$this->posts_table = $wpdb->prefix . 'posts';
$this->meta_table = $wpdb->prefix . 'postmeta';
add_action( 'wp_ajax_sby_get_single_videos', [ $this, 'ajax_query_single_videos' ] );
add_action( 'wp_ajax_sby_all_videos_action', [ $this, 'ajax_all_video_action' ] );
add_action( 'pre_get_posts', [ $this, 'filter_single_videos' ] );
add_action( 'sby_localized_settings', [ $this, 'localize_listing_url' ] );
}
public function ajax_query_single_videos() {
Util::ajaxPreflightChecks();
$page = esc_sql($_POST['page']);
wp_send_json_success(['total_result' => $this->single_videos_total(), 'results' => $this->query_single_videos($page)]);
}
public function ajax_all_video_action() {
Util::ajaxPreflightChecks();
$meta_query = [
'relation' => 'OR'
];
$exploded_channels = explode(',', $_POST['channel']);
if ( is_array( $exploded_channels ) ) {
foreach ( $exploded_channels as $channel_id ) {
$meta_query[] = [
'key' => 'sby_channel_title',
'value' => esc_sql( $channel_id ),
'compare' => '=',
];
}
} else {
$meta_query[] = [
'key' => 'sby_channel_title',
'value' => esc_sql( $exploded_channels ),
'compare' => '=',
];
}
$args = array(
'post_type' => SBY_CPT,
'meta_key' => 'sby_channel_title',
'posts_per_page' => -1,
'meta_query' => $meta_query
);
$query = new \WP_Query($args);
if($_POST['perform'] === 'publish') {
foreach ( $query->get_posts() as $post ) {
$postData = [ 'ID' => $post->ID, 'post_status' => 'publish' ];
wp_update_post( $postData );
}
}
if($_POST['perform'] === 'delete') {
foreach ( $query->get_posts() as $post ) {
wp_delete_post( $post->ID, true );
}
}
wp_send_json_success();
}
public function filter_single_videos($query) {
global $pagenow;
if ( isset($_GET['post_type'], $_GET['sby_channel_filter']) && $_GET['post_type'] === SBY_CPT && $pagenow === 'edit.php' && is_admin() && $query->is_main_query() ) {
$query->set( 'meta_key', 'sby_channel_title' );
$query->set( 'meta_value', $_GET['sby_channel_filter'] );
}
return $query;
}
public function localize_listing_url($settings) {
$settings['single_videos_list'] = admin_url(sprintf('edit.php?post_type=%s', SBY_CPT));
return $settings;
}
private function query_single_videos($page, $limit = 5) {
global $wpdb;
$query = sprintf( 'SELECT SUM(%1$s.post_status="publish") AS publish,SUM(%1$s.post_status="draft") AS draft, %2$s.meta_value as title FROM `%2$s`
JOIN %1$s ON %2$s.post_id=%1$s.ID
WHERE %2$s.meta_key="sby_channel_title"
GROUP BY %2$s.meta_value ORDER BY %1$s.ID DESC LIMIT %3$s, %4$s', $this->posts_table, $this->meta_table, ($page * $limit), $limit );
$query = $wpdb->prepare($query);
return $wpdb->get_results($query);
}
private function single_videos_total() {
global $wpdb;
$total_query = sprintf( 'SELECT SUM(%1$s.post_status="publish") AS publish,SUM(%1$s.post_status="draft") AS draft, %2$s.meta_value as title FROM `%2$s`
JOIN %1$s ON %2$s.post_id=%1$s.ID
WHERE %2$s.meta_key="sby_channel_title"
GROUP BY %2$s.meta_value', $this->posts_table, $this->meta_table );
$total_query = $wpdb->prepare($total_query);
$wpdb->get_results($total_query);
return $wpdb->num_rows;
}
}