update
This commit is contained in:
1429
wp-content/plugins/youtube-feed-pro/inc/Admin/SBY_Admin.php
Normal file
1429
wp-content/plugins/youtube-feed-pro/inc/Admin/SBY_Admin.php
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,992 @@
|
||||
<?php
|
||||
|
||||
namespace SmashBalloon\YouTubeFeed\Admin;
|
||||
|
||||
use SmashBalloon\YouTubeFeed\Feed_Locator;
|
||||
|
||||
abstract class SBY_Admin_Abstract {
|
||||
|
||||
protected $vars;
|
||||
|
||||
protected $base_path;
|
||||
|
||||
protected $slug;
|
||||
|
||||
protected $plugin_name;
|
||||
|
||||
protected $capability;
|
||||
|
||||
protected $icon;
|
||||
|
||||
protected $tabs;
|
||||
|
||||
protected $active_tab;
|
||||
|
||||
protected $settings_sections;
|
||||
|
||||
protected $display_your_feed_sections;
|
||||
|
||||
protected $option_name;
|
||||
|
||||
protected $types;
|
||||
|
||||
protected $layouts;
|
||||
|
||||
protected $false_fields;
|
||||
|
||||
protected $textarea_fields;
|
||||
|
||||
protected $position;
|
||||
|
||||
protected $settings;
|
||||
|
||||
public function __construct( $vars, $base_path, $slug, $plugin_name, $capability, $icon, $position, $tabs, $settings, $active_tab = false, $option_name = 'sbspf_settings' ) {
|
||||
$this->vars = $vars;
|
||||
$this->base_path = $base_path;
|
||||
$this->slug = $slug;
|
||||
$this->plugin_name = $plugin_name;
|
||||
$this->capability = $capability;
|
||||
$this->icon = $icon;
|
||||
$this->position = $position;
|
||||
|
||||
$this->tabs = $tabs;
|
||||
|
||||
if ( $active_tab ) {
|
||||
$this->set_active_tab( $active_tab );
|
||||
} else {
|
||||
$this->set_active_tab( $tabs[0]['slug'] );
|
||||
}
|
||||
$this->settings = $settings;
|
||||
$this->option_name = $option_name;
|
||||
$this->false_fields = array();
|
||||
$this->textarea_fields = array();
|
||||
$this->display_your_feed_sections = array();
|
||||
}
|
||||
|
||||
public function get_vars() {
|
||||
return $this->vars;
|
||||
}
|
||||
|
||||
public function get_option_name() {
|
||||
return $this->option_name;
|
||||
}
|
||||
|
||||
public function verify_post( $post ) {
|
||||
return wp_verify_nonce( $post[ $this->option_name . '_validate' ], $this->option_name . '_validate' );
|
||||
}
|
||||
|
||||
public function hidden_fields_for_tab( $tab ) {
|
||||
wp_nonce_field( $this->get_option_name() . '_validate', $this->get_option_name() . '_validate', true, true );
|
||||
?>
|
||||
<input type="hidden" name="<?php echo $this->get_option_name() . '_tab_marker'; ?>" value="<?php echo esc_attr( $tab ); ?>"/>
|
||||
<?php
|
||||
}
|
||||
|
||||
public function init() {
|
||||
// add_action( 'admin_menu', array( $this, 'create_menus' ) );
|
||||
add_action( 'admin_init', array( $this, 'settings_init' ) );
|
||||
add_action( 'admin_init', array( $this, 'additional_settings_init' ) );
|
||||
|
||||
}
|
||||
|
||||
public function settings_init() {
|
||||
/**
|
||||
* Configure Tab
|
||||
*/
|
||||
$args = array(
|
||||
'id' => 'sbspf_types',
|
||||
'tab' => 'configure',
|
||||
'save_after' => 'true'
|
||||
);
|
||||
$this->add_settings_section( $args );
|
||||
|
||||
/* Types */
|
||||
$locator_html = '';
|
||||
if ( Feed_Locator::count_unique() > -1 ) {
|
||||
$locator_html .= '<div class="sby_locations_link">';
|
||||
$locator_html .= '<a href="?page=' . $this->slug .'&tab=allfeeds"><svg aria-hidden="true" focusable="false" data-prefix="far" data-icon="search" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" class="svg-inline--fa fa-search fa-w-16 fa-2x"><path fill="currentColor" d="M508.5 468.9L387.1 347.5c-2.3-2.3-5.3-3.5-8.5-3.5h-13.2c31.5-36.5 50.6-84 50.6-136C416 93.1 322.9 0 208 0S0 93.1 0 208s93.1 208 208 208c52 0 99.5-19.1 136-50.6v13.2c0 3.2 1.3 6.2 3.5 8.5l121.4 121.4c4.7 4.7 12.3 4.7 17 0l22.6-22.6c4.7-4.7 4.7-12.3 0-17zM208 368c-88.4 0-160-71.6-160-160S119.6 48 208 48s160 71.6 160 160-71.6 160-160 160z" class=""></path></svg> ' . __( 'Feed Finder', 'feeds-for-youtube' ) . '</a>';
|
||||
$locator_html .= '</div>';
|
||||
}
|
||||
$args = array(
|
||||
'name' => 'type',
|
||||
'section' => 'sbspf_types',
|
||||
'callback' => 'types',
|
||||
'title' => '<label>' . __( 'Select a Feed Type', 'feeds-for-youtube' ) .'</label>',
|
||||
'shortcode' => array(
|
||||
'key' => 'type',
|
||||
'example' => 'channel',
|
||||
'description' => __( 'Type of feed to display', 'feeds-for-youtube' ) . ' e.g. channel, playlist, search, favorites, live',
|
||||
'after_description' => $locator_html,
|
||||
'display_section' => 'configure'
|
||||
),
|
||||
'types' => $this->types
|
||||
);
|
||||
$this->add_settings_field( $args );
|
||||
|
||||
/* Cache */
|
||||
$args = array(
|
||||
'name' => 'cache',
|
||||
'section' => 'sbspf_types',
|
||||
'callback' => 'cache',
|
||||
'title' => __( 'Check for new posts', 'feeds-for-youtube' )
|
||||
);
|
||||
$this->add_settings_field( $args );
|
||||
|
||||
/**
|
||||
* Customize Tab
|
||||
*/
|
||||
$args = array(
|
||||
'title' => __( 'General', 'feeds-for-youtube' ),
|
||||
'id' => 'sbspf_general',
|
||||
'tab' => 'customize',
|
||||
'save_after' => 'true'
|
||||
);
|
||||
$this->add_settings_section( $args );
|
||||
|
||||
/* Width and Height */
|
||||
$select_options = array(
|
||||
array(
|
||||
'label' => '%',
|
||||
'value' => '%'
|
||||
),
|
||||
array(
|
||||
'label' => 'px',
|
||||
'value' => 'px'
|
||||
)
|
||||
);
|
||||
|
||||
$args = array(
|
||||
'name' => 'width',
|
||||
'default' => '100',
|
||||
'section' => 'sbspf_general',
|
||||
'callback' => 'text',
|
||||
'min' => 1,
|
||||
'size' => 4,
|
||||
'title' => __( 'Width of Feed', 'feeds-for-youtube' ),
|
||||
'shortcode' => array(
|
||||
'key' => 'width',
|
||||
'example' => '300px',
|
||||
'description' => __( 'The width of your feed. Any number with a unit like "px" or "%".', 'feeds-for-youtube' ),
|
||||
'display_section' => 'customize'
|
||||
),
|
||||
'select_name' => 'widthunit',
|
||||
'select_options' => $select_options,
|
||||
'hidden' => array(
|
||||
'callback' => 'checkbox',
|
||||
'name' => 'width_responsive',
|
||||
'label' => __( 'Set to be 100% width on mobile?', 'feeds-for-youtube' ),
|
||||
'before' => '<div id="sbspf_width_options">',
|
||||
'after' => '</div>',
|
||||
'tooltip_info' => __( 'If you set a width on the feed then this will be used on mobile as well as desktop. Check this setting to set the feed width to be 100% on mobile so that it is responsive.', 'feeds-for-youtube' )
|
||||
),
|
||||
);
|
||||
$this->add_settings_field( $args );
|
||||
|
||||
$select_options = array(
|
||||
array(
|
||||
'label' => '%',
|
||||
'value' => '%'
|
||||
),
|
||||
array(
|
||||
'label' => 'px',
|
||||
'value' => 'px'
|
||||
)
|
||||
);
|
||||
$args = array(
|
||||
'name' => 'height',
|
||||
'default' => '',
|
||||
'section' => 'sbspf_general',
|
||||
'callback' => 'text',
|
||||
'min' => 1,
|
||||
'size' => 4,
|
||||
'title' => __( 'Height of Feed', 'feeds-for-youtube' ),
|
||||
'shortcode' => array(
|
||||
'key' => 'height',
|
||||
'example' => '500px',
|
||||
'description' => __( 'The height of your feed. Any number with a unit like "px" or "em".', 'feeds-for-youtube' ),
|
||||
'display_section' => 'customize'
|
||||
),
|
||||
'select_name' => 'heightunit',
|
||||
'select_options' => $select_options,
|
||||
);
|
||||
$this->add_settings_field( $args );
|
||||
|
||||
$args = array(
|
||||
'name' => 'background',
|
||||
'default' => '',
|
||||
'section' => 'sbspf_general',
|
||||
'callback' => 'color',
|
||||
'title' => __( 'Background Color', 'feeds-for-youtube' ),
|
||||
'shortcode' => array(
|
||||
'key' => 'background',
|
||||
'example' => '#f00',
|
||||
'description' => __( 'Background color for the feed. Any hex color code.', 'feeds-for-youtube' ),
|
||||
'display_section' => 'customize'
|
||||
),
|
||||
);
|
||||
$this->add_settings_field( $args );
|
||||
|
||||
$args = array(
|
||||
'title' => __( 'Layout', 'feeds-for-youtube' ),
|
||||
'id' => 'sbspf_layout',
|
||||
'tab' => 'customize',
|
||||
'save_after' => 'true'
|
||||
);
|
||||
$this->add_settings_section( $args );
|
||||
|
||||
$args = array(
|
||||
'name' => 'layout',
|
||||
'section' => 'sbspf_layout',
|
||||
'callback' => 'layout',
|
||||
'title' => __( 'Layout Type', 'feeds-for-youtube' ),
|
||||
'layouts' => $this->layouts,
|
||||
'shortcode' => array(
|
||||
'key' => 'layout',
|
||||
'example' => 'list',
|
||||
'description' => __( 'How your posts are display visually.', 'feeds-for-youtube' ),
|
||||
'display_section' => 'layout'
|
||||
)
|
||||
);
|
||||
$this->add_settings_field( $args );
|
||||
}
|
||||
|
||||
public function additional_settings_init() {
|
||||
|
||||
}
|
||||
|
||||
public function add_false_field( $name, $tab ) {
|
||||
$this->false_fields[ $tab ][] = $name;
|
||||
}
|
||||
|
||||
public function get_false_fields( $tab ) {
|
||||
if ( isset( $this->false_fields[ $tab ] ) ) {
|
||||
return $this->false_fields[ $tab ];
|
||||
}
|
||||
|
||||
return array();
|
||||
}
|
||||
|
||||
public function add_textarea_field( $name, $tab ) {
|
||||
$this->textarea_fields[ $tab ][] = $name;
|
||||
}
|
||||
|
||||
public function get_textarea_fields( $tab ) {
|
||||
if ( isset( $this->textarea_fields[ $tab ] ) ) {
|
||||
return $this->textarea_fields[ $tab ];
|
||||
}
|
||||
|
||||
return array();
|
||||
}
|
||||
|
||||
public function blank() {
|
||||
|
||||
}
|
||||
|
||||
public function add_settings_section( $args ) {
|
||||
$title = isset( $args['title'] ) ? $args['title'] : '';
|
||||
$callback = isset( $args['callback'] ) ? $args['callback'] : array( $this, 'blank' );
|
||||
add_settings_section(
|
||||
$args['id'],
|
||||
$title,
|
||||
$callback,
|
||||
$args['id']
|
||||
);
|
||||
|
||||
$save_after = isset( $args['save_after'] ) ? $args['save_after'] : false;
|
||||
$this->settings_sections[ $args['tab'] ][] = array(
|
||||
'id' => $args['id'],
|
||||
'save_after' => $save_after
|
||||
);
|
||||
}
|
||||
|
||||
public function add_settings_field( $args ) {
|
||||
$title_after = '';
|
||||
$shortcode = false;
|
||||
if ( isset( $args['shortcode'] ) ) {
|
||||
$title_after = isset( $args['shortcode']['after'] ) ? $args['shortcode']['after'] : '';
|
||||
$shortcode = $args['shortcode'];
|
||||
}
|
||||
|
||||
if ( $shortcode ) {
|
||||
$this->display_your_feed_sections[ $shortcode['display_section'] ]['settings'][] = $shortcode;
|
||||
}
|
||||
|
||||
if ( $args['callback'] === 'types' ) {
|
||||
$formatted_label = '<label for="' . $this->option_name . '_' . $args['name'] . '">' . $args['title'] .'</label>';
|
||||
$formatted_label .= '<code class="sbspf_shortcode">type'. "\n";
|
||||
foreach ( $args['types'] as $type ) {
|
||||
$shortcode = array(
|
||||
'key' => $type['slug'],
|
||||
'example' => $type['example'],
|
||||
'description' => $type['description'],
|
||||
'display_section' => 'configure'
|
||||
);
|
||||
$this->display_your_feed_sections[ $shortcode['display_section'] ]['settings'][] = $shortcode;
|
||||
|
||||
|
||||
$formatted_label .= 'Eg: type=' . $type['slug'] . '<br>';
|
||||
$formatted_label .= $type['slug'] . '="' . substr( $type['example'], 0, 14) . '"<br>';
|
||||
|
||||
}
|
||||
$formatted_label .= '</code><br>';
|
||||
|
||||
if ( isset( $args['shortcode']['after_description'] ) ) {
|
||||
$formatted_label .= $args['shortcode']['after_description'];
|
||||
}
|
||||
$title = $formatted_label;
|
||||
} else {
|
||||
$title = $this->format_title( $args['title'], $args['name'], $shortcode, $title_after );
|
||||
}
|
||||
|
||||
if ( $args['callback'] === 'checkbox' || (isset( $args['falsefield'] ) && $args['falsefield'] === true) ) {
|
||||
$tab = 'none';
|
||||
foreach ( $this->settings_sections as $key => $settings_sections ) {
|
||||
foreach ( $settings_sections as $this_tab_sections ) {
|
||||
if ( $this_tab_sections['id'] === $args['section'] ) {
|
||||
$tab = $key;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
$this->add_false_field( $args['name'], $tab );
|
||||
}
|
||||
|
||||
if ( $args['callback'] === 'layout' || $args['callback'] === 'sub_option' ) {
|
||||
$tab = 'none';
|
||||
foreach ( $this->settings_sections as $key => $settings_sections ) {
|
||||
foreach ( $settings_sections as $this_tab_sections ) {
|
||||
if ( $this_tab_sections['id'] === $args['section'] ) {
|
||||
$tab = $key;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
$sub_options = isset( $args['layouts'] ) ? $args['layouts'] : $args['sub_options'];
|
||||
foreach ( $sub_options as $sub_option ) {
|
||||
if ( isset( $sub_option['options'] ) ) {
|
||||
foreach( $sub_option['options'] as $sub_sub_option ) {
|
||||
if ( ! empty( $sub_sub_option['shortcode'] ) ) {
|
||||
$key = ! empty( $sub_sub_option['shortcode']['key'] ) ? $sub_sub_option['shortcode']['key'] : $sub_option['slug'] . $sub_sub_option['name'];
|
||||
$example = ! empty( $sub_sub_option['shortcode']['example'] ) ? $sub_sub_option['shortcode']['example'] : '';
|
||||
$description = ! empty( $sub_sub_option['shortcode']['description'] ) ? $sub_sub_option['shortcode']['description'] : '';
|
||||
$display_section = ! empty( $sub_sub_option['shortcode']['display_section'] ) ? $sub_sub_option['shortcode']['display_section'] : str_replace( 'sbspf_', '', $args['section'] );
|
||||
$sub_shortcode = array(
|
||||
'key' => $key,
|
||||
'example' => $example,
|
||||
'description' => $description,
|
||||
'display_section' => $display_section
|
||||
);
|
||||
if ( isset( $this->display_your_feed_sections[ $display_section ] ) ) {
|
||||
$this->display_your_feed_sections[ $display_section ]['settings'][] = $sub_shortcode;
|
||||
}
|
||||
}
|
||||
if ( $sub_sub_option['callback'] === 'checkbox' ) {
|
||||
$this->add_false_field( $sub_option['slug'] . $sub_sub_option['name'], $tab );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( $args['callback'] === 'textarea' ) {
|
||||
$tab = 'none';
|
||||
foreach ( $this->settings_sections as $key => $settings_sections ) {
|
||||
foreach ( $settings_sections as $this_tab_sections ) {
|
||||
if ( $this_tab_sections['id'] === $args['section'] ) {
|
||||
$tab = $key;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
$this->add_textarea_field( $args['name'], $tab );
|
||||
}
|
||||
|
||||
add_settings_field(
|
||||
$args['name'],
|
||||
$title,
|
||||
array( $this, $args['callback'] ),
|
||||
$args['section'],
|
||||
$args['section'],
|
||||
$args
|
||||
);
|
||||
|
||||
if ( isset( $args['hidden'] ) ) {
|
||||
if ( $args['hidden']['callback'] === 'checkbox' ) {
|
||||
$tab = 'none';
|
||||
foreach ( $this->settings_sections as $key => $settings_sections ) {
|
||||
foreach ( $settings_sections as $this_tab_sections ) {
|
||||
if ( $this_tab_sections['id'] === $args['section'] ) {
|
||||
$tab = $key;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
$this->add_false_field( $args['hidden']['name'], $tab );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function set_feed_types( $types ) {
|
||||
$this->types = $types;
|
||||
}
|
||||
|
||||
public function set_feed_layouts( $layouts ) {
|
||||
$this->layouts = $layouts;
|
||||
}
|
||||
|
||||
public function set_display_table_sections( $headings ) {
|
||||
foreach ( $headings as $heading ) {
|
||||
$this->display_your_feed_sections[ $heading['slug'] ] = array(
|
||||
'label' => $heading['label'],
|
||||
'settings' => array()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public function checkbox( $args ) {
|
||||
$default = isset( $args['default'] ) ? $args['default'] : false;
|
||||
$selected = isset( $this->settings[ $args['name'] ] ) ? $this->settings[ $args['name'] ] : $default;
|
||||
$label = isset( $args['label'] ) ? $args['label'] : __( 'Yes' );
|
||||
$tooltip_text = isset( $args['tooltip_text'] ) ? $args['label'] : $this->default_tooltip_text();
|
||||
$has_shortcode = isset( $args['has_shortcode'] ) && $args['has_shortcode'] ? '1' : '';
|
||||
?>
|
||||
<input name="<?php echo $this->option_name .'['.esc_attr( $args['name'] ).']'; ?>" id="<?php echo $this->option_name . '_' . $args['name']; ?>" class="sbspf_single_checkbox" type="checkbox"<?php if ( $selected ) echo ' checked'; ?>/>
|
||||
<label for="<?php echo $this->option_name . '_' . $args['name'] . $has_shortcode; ?>"><?php echo esc_html( $label ); ?></label><?php if ( $has_shortcode === '1' ) : ?><code class="sbspf_shortcode"> <?php echo $args['name'] . "\n"; ?>
|
||||
Eg: <?php echo $args['name']; ?>=<?php echo $args['shortcode_example']; ?></code><br><?php endif; ?>
|
||||
<?php if ( isset( $args['tooltip_info'] ) ) : ?>
|
||||
<a class="sbspf_tooltip_link" href="JavaScript:void(0);"><?php echo $tooltip_text; ?></a>
|
||||
<p class="sbspf_tooltip sbspf_more_info"><?php echo $args['tooltip_info']; ?></p>
|
||||
<?php
|
||||
endif;
|
||||
}
|
||||
|
||||
public function multi_checkbox( $args ) {
|
||||
$default = isset( $args['default'] ) ? $args['default'] : false;
|
||||
$selection_array = isset( $this->settings[ $args['name'] ] ) ? (array)$this->settings[ $args['name'] ] : (array)$default;
|
||||
$tooltip_text = isset( $args['tooltip_text'] ) ? $args['label'] : $this->default_tooltip_text();
|
||||
$index = 0;
|
||||
?>
|
||||
<?php foreach ( $args['select_options'] as $select_option ) :
|
||||
$selected = in_array( $select_option['value'], $selection_array, true );
|
||||
$pro_only = (isset( $select_option['pro'] ) && $select_option['pro']) ? ' sbspf_pro_only' : '';
|
||||
$class = ! empty( $select_option['class'] ) ? ' ' . $select_option['class'] : '';
|
||||
?>
|
||||
<div class="sbspf_multi_checkbox_option<?php echo $pro_only . $class; ?>">
|
||||
<input name="<?php echo $this->option_name .'['.esc_attr( $args['name'] ).'][]'; ?>" id="<?php echo $this->option_name . '_' . $args['name']. '_' . $index; ?>" value="<?php echo esc_attr( $select_option['value'] ); ?>" type="checkbox"<?php if ( $selected ) echo ' checked'; ?>/>
|
||||
<label for="<?php echo $this->option_name . '_' . $args['name'] . '_' . $index; ?>"><?php echo esc_html( $select_option['label'] ); ?></label>
|
||||
</div>
|
||||
<?php
|
||||
$index++;
|
||||
endforeach; ?>
|
||||
|
||||
<?php if ( isset( $args['tooltip_info'] ) ) : ?>
|
||||
<a class="sbspf_tooltip_link" href="JavaScript:void(0);"><?php echo $tooltip_text; ?></a>
|
||||
<p class="sbspf_tooltip sbspf_more_info"><?php echo $args['tooltip_info']; ?></p>
|
||||
<?php
|
||||
endif;
|
||||
}
|
||||
|
||||
public function text( $args ) {
|
||||
$default = isset( $args['default'] ) ? $args['default'] : '';
|
||||
$value = isset( $this->settings[ $args['name'] ] ) ? $this->settings[ $args['name'] ] : $default;
|
||||
$size = ( isset( $args['size'] ) ) ? ' size="'. $args['size'].'"' : '';
|
||||
$class = isset( $args['class'] ) ? ' class="'. esc_attr( $args['class'] ) . '"' : '';
|
||||
|
||||
$tooltip_text = isset( $args['tooltip_text'] ) ? $args['label'] : $this->default_tooltip_text();
|
||||
|
||||
if ( isset( $args['min'] ) ) :
|
||||
$min = ( isset( $args['min'] ) ) ? ' min="'. $args['min'].'"' : '';
|
||||
$max = ( isset( $args['max'] ) ) ? ' max="'. $args['max'].'"' : '';
|
||||
$step = ( isset( $args['step'] ) ) ? ' step="'. $args['step'].'"' : '';
|
||||
$class = isset( $args['class'] ) ? ' class="sbspf_number_field sbspf_size_' . $args['size'] . ' '. esc_attr( $args['class'] ) . '"' : ' class="sbspf_number_field sbspf_size_' . $args['size'] . '"';
|
||||
?>
|
||||
<input name="<?php echo $this->option_name.'['.$args['name'].']'; ?>" id="<?php echo $this->option_name . '_' . $args['name']; ?>"<?php echo $class; ?> type="number"<?php echo $size; ?><?php echo $min; ?><?php echo $max; ?><?php echo $step; ?> value="<?php echo esc_attr( $value ); ?>" />
|
||||
<?php elseif ( isset( $args['color'] ) ) : ?>
|
||||
<input name="<?php echo $this->option_name.'['.$args['name'].']'; ?>" id="<?php echo $this->option_name . '_' . $args['name']; ?>" class="sbspf_colorpicker" type="text" value="#<?php echo esc_attr( str_replace('#', '', $value ) ); ?>" />
|
||||
<?php else: ?>
|
||||
<input name="<?php echo $this->option_name.'['.$args['name'].']'; ?>" id="<?php echo $this->option_name . '_' . $args['name']; ?>"<?php echo $class; ?> type="text" value="<?php echo esc_attr( stripslashes( $value ) ); ?>" />
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ( isset( $args['select_options'] ) ) :
|
||||
$value = isset( $this->settings[ $args['select_name'] ] ) ? $this->settings[ $args['select_name'] ] : $args['select_options'][0]['value'];
|
||||
?>
|
||||
<select name="<?php echo $this->option_name.'['.$args['select_name'].']'; ?>" id="<?php echo $this->option_name . '_' . $args['select_name']; ?>">
|
||||
<?php foreach ( $args['select_options'] as $select_option ) : ?>
|
||||
<option value="<?php echo esc_attr( $select_option['value'] ); ?>"<?php if ( (string)$select_option['value'] === (string)$value ) echo ' selected'; ?>><?php echo esc_html( $select_option['label'] ); ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ( isset( $args['hidden'] ) ) : ?>
|
||||
|
||||
<?php
|
||||
if ( is_callable( array( $this, $args['hidden']['callback'] ) ) ){
|
||||
echo $args['hidden']['before'];
|
||||
call_user_func_array(
|
||||
array( $this, $args['hidden']['callback'] ),
|
||||
array( $args['hidden'] )
|
||||
);
|
||||
echo $args['hidden']['after'];
|
||||
}
|
||||
?>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ( isset( $args['additional'] ) ) : ?>
|
||||
<?php echo $args['additional']; ?>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ( isset( $args['tooltip_info'] ) ) : ?>
|
||||
<a class="sbspf_tooltip_link" href="JavaScript:void(0);"><?php echo $tooltip_text; ?></a>
|
||||
<p class="sbspf_tooltip sbspf_more_info"><?php echo $args['tooltip_info']; ?></p>
|
||||
<?php
|
||||
endif;
|
||||
}
|
||||
|
||||
public function select( $args ) {
|
||||
$default = isset( $args['default'] ) ? $args['default'] : $args['options'][0]['value'];
|
||||
$value = isset( $this->settings[ $args['name'] ] ) ? $this->settings[ $args['name'] ] : $default;
|
||||
|
||||
if ( isset( $args['min'] ) && isset( $args['max'] ) && ((int)$args['min'] < (int)$args['max']) && empty( $args['options'] ) ) {
|
||||
$args['options'] = array();
|
||||
$i = (int)$args['min'];
|
||||
|
||||
while ( $i <= (int)$args['max'] ) {
|
||||
$args['options'][] = array(
|
||||
'label' => $i,
|
||||
'value' => $i
|
||||
);
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
|
||||
$tooltip_text = isset( $args['tooltip_text'] ) ? $args['label'] : $this->default_tooltip_text();
|
||||
?>
|
||||
<select name="<?php echo $this->option_name.'['.$args['name'].']'; ?>" id="<?php echo $this->option_name . '_' . $args['name']; ?>">
|
||||
<?php foreach ( $args['options'] as $select_option ) : ?>
|
||||
<option value="<?php echo esc_attr( $select_option['value'] ); ?>"<?php if ( (string)$select_option['value'] === (string)$value ) echo ' selected'; ?>><?php echo esc_html( $select_option['label'] ); ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
|
||||
<?php if ( isset( $args['additional'] ) ) : ?>
|
||||
<?php echo $args['additional']; ?>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ( isset( $args['tooltip_info'] ) ) : ?>
|
||||
<a class="sbspf_tooltip_link" href="JavaScript:void(0);"><?php echo $tooltip_text; ?></a>
|
||||
<p class="sbspf_tooltip sbspf_more_info"><?php echo $args['tooltip_info']; ?></p>
|
||||
<?php endif;
|
||||
}
|
||||
|
||||
public function textarea( $args ) {
|
||||
$default = isset( $args['default'] ) ? $args['default'] : '';
|
||||
$value = isset( $this->settings[ $args['name'] ] ) ? stripslashes( $this->settings[ $args['name'] ] ) : $default;
|
||||
|
||||
if ( isset( $args['tooltip_info'] ) ) : ?>
|
||||
<span><?php echo $args['tooltip_info']; ?></span><br>
|
||||
<?php endif; ?>
|
||||
|
||||
<textarea name="<?php echo $this->option_name.'['.$args['name'].']'; ?>" id="<?php echo $this->option_name . '_' . $args['name']; ?>"rows="7"><?php echo $value; ?></textarea>
|
||||
|
||||
<?php if ( isset( $args['note'] ) ) : ?>
|
||||
<br><span class="sbspf_note"><?php echo $args['note']; ?></span>
|
||||
<?php endif;
|
||||
}
|
||||
|
||||
public function color( $args ) {
|
||||
$args['color'] = true;
|
||||
$this->text( $args );
|
||||
}
|
||||
|
||||
public function types( $args ) {
|
||||
$type_selected = isset( $this->settings[ $args['name'] ] ) ? $this->settings[ $args['name'] ] : $args['types'][0]['slug'];
|
||||
|
||||
foreach ( $args['types'] as $type ) :
|
||||
$input_type = isset( $type['input_type'] ) ? $type['input_type'] : 'connected_account';
|
||||
$selected = ! empty( $this->settings[ $type['slug'] ] ) ? $this->settings[ $type['slug'] ] : $type['default'];
|
||||
if ( $input_type === 'connected_account' ) {
|
||||
$selected = isset( $this->settings[ $type['slug'] . '_ids' ] ) ? $this->settings[ $type['slug'] . '_ids' ] : array();
|
||||
}
|
||||
$on_select = isset( $type['onselect'] ) ? $type['onselect'] : false;
|
||||
?>
|
||||
<div class="sbspf_row sbspf_type_row" style="min-height: 29px;">
|
||||
<div class="sbspf_col sbspf_one">
|
||||
<input type="radio" name="<?php echo $this->option_name.'['.esc_attr( $args['name'] ).']'; ?>" class="sbspf_type_input" id="sbspf_type_<?php echo esc_attr( $type['slug'] ); ?>" value="<?php echo esc_attr( $type['slug'] ); ?>"<?php if ( $type_selected === $type['slug'] ) echo 'checked'; ?>>
|
||||
<label class="sbspf_radio_label" for="sbspf_type_<?php echo esc_attr( $type['slug'] ); ?>"><?php echo esc_html( $type['label'] ); ?>: <a class="sbspf_type_tooltip_link" href="JavaScript:void(0);"><i class="fa fa-question-circle" aria-hidden="true" style="margin-left: 2px;"></i></a></label>
|
||||
</div>
|
||||
<div class="sbspf_col sbspf_two">
|
||||
<?php if ( $input_type === 'text' ) :
|
||||
$placeholder = isset( $type['note'] ) ? ' placeholder="' . esc_attr( $type['note'] ). '"' : '';
|
||||
?>
|
||||
<input name="<?php echo $this->option_name.'['.esc_attr( $type['slug'] ).']'; ?>" id="sbspf_<?php echo esc_attr( $type['slug'] ); ?>" type="text" value="<?php echo esc_attr( $selected ); ?>" size="45"<?php echo $placeholder; ?>>
|
||||
<?php else :
|
||||
$connected_accounts = $this->get_connected_accounts(); ?>
|
||||
<div class="sbspf_<?php echo esc_attr( $type['slug'] ); ?>_feed_ids_wrap">
|
||||
<?php foreach ( $connected_accounts as $connected_account ) : if ( in_array( $connected_account['channel_id'], $selected, true ) ) : ?>
|
||||
<div id="sbspf_<?php echo esc_attr( $type['slug'] ); ?>_feed_id_<?php echo esc_attr( $connected_account['channel_id'] ); ?>" class="sbspf_<?php echo esc_attr( $type['slug'] ); ?>_feed_account_wrap">
|
||||
<strong><?php echo esc_html( $connected_account['username'] ); ?></strong> <span>(<?php echo esc_attr( $connected_account['channel_id'] ); ?>)</span><input type="hidden" name="<?php echo $this->option_name.'['.esc_attr( $type['slug'] ).'_feed_ids][]'; ?>" value="<?php echo esc_attr( $connected_account['channel_id'] ); ?>">
|
||||
</div>
|
||||
<?php endif; endforeach; ?>
|
||||
</div>
|
||||
<?php if ( empty( $selected ) ) : ?>
|
||||
<p class="sbspf_no_accounts" style="margin-top: -3px; margin-right: 10px;"><?php _e( 'Connect an account above', 'feeds-for-youtube' ); ?></p>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php endif; ?>
|
||||
<?php if ( $input_type !== 'text' && isset( $type['note'] ) ) : ?>
|
||||
<br><span class="sbspf_note"><?php echo $type['note']; ?></span>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<?php if ( $on_select ) : ?>
|
||||
<div class="sbspf_onselect">
|
||||
<?php call_user_func_array( array( $this, $on_select ), array( $type ) ); ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<div class="sbspf_tooltip sbspf_type_tooltip sbspf_more_info">
|
||||
<?php if ( ! empty( $type['tooltip'] ) ) : ?>
|
||||
<?php echo $type['tooltip']; ?>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
<?php endforeach;
|
||||
}
|
||||
|
||||
public function sub_option( $args ) {
|
||||
$value = isset( $this->settings[ $args['name'] ] ) ? $this->settings[ $args['name'] ] : 'related';
|
||||
|
||||
$cta_options = $args['sub_options'];
|
||||
?>
|
||||
<?php if ( ! empty( $args['before'] ) ) {
|
||||
echo $args['before'];
|
||||
}?>
|
||||
|
||||
<div class="sbspf_sub_options">
|
||||
<?php foreach ( $cta_options as $sub_option ) : ?>
|
||||
<div class="sbspf_sub_option_cell">
|
||||
<input class="sbspf_sub_option_type" id="sbspf_sub_option_type_<?php echo esc_attr( $sub_option['slug'] ); ?>" name="<?php echo $this->option_name.'['.$args['name'].']'; ?>" type="radio" value="<?php echo esc_attr( $sub_option['slug'] ); ?>"<?php if ( $sub_option['slug'] === $value ) echo ' checked'?>><label for="sbspf_sub_option_type_<?php echo esc_attr( $sub_option['slug'] ); ?>"><span class="sbspf_label"><?php echo $sub_option['label']; ?></span></label>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
|
||||
<div class="sbspf_box_setting">
|
||||
<?php if ( isset( $cta_options ) ) : foreach ( $cta_options as $sub_option ) : ?>
|
||||
<div class="sbspf_sub_option_settings sbspf_sub_option_type_<?php echo esc_attr( $sub_option['slug'] ); ?>">
|
||||
|
||||
<div class="sbspf_sub_option_setting">
|
||||
<?php echo sby_admin_icon( 'info-circle', 'sbspf_small_svg' ); ?> <span class="sbspf_note" style="margin-left: 0;"><?php echo $sub_option['note']; ?></span>
|
||||
</div>
|
||||
<?php if ( ! empty( $sub_option['options'] ) ) : ?>
|
||||
<?php foreach ( $sub_option['options'] as $option ) :
|
||||
$option['name'] = $sub_option['slug'].$option['name'];
|
||||
?>
|
||||
<div class="sbspf_sub_option_setting">
|
||||
<?php if ( $option['callback'] !== 'checkbox' ) :
|
||||
if ( isset( $option['shortcode'] ) ) : ?>
|
||||
<label title="<?php echo __( 'Click for shortcode option', 'feeds-for-youtube' ); ?>"><?php echo $option['label']; ?></label><code class="sbspf_shortcode"> <?php echo $option['name'] . "\n"; ?>
|
||||
Eg: <?php echo $option['name']; ?>=<?php echo $option['shortcode']['example']; ?></code><br>
|
||||
<?php else: ?>
|
||||
<label><?php echo $option['label']; ?></label><br>
|
||||
<?php endif; ?>
|
||||
<?php else:
|
||||
$option['shortcode_example'] = $option['shortcode']['example'];
|
||||
$option['has_shortcode'] = true;
|
||||
endif; ?>
|
||||
<?php call_user_func_array( array( $this, $option['callback'] ), array( $option ) ); ?>
|
||||
|
||||
</div>
|
||||
|
||||
<?php endforeach; ?>
|
||||
<?php endif; ?>
|
||||
|
||||
</div>
|
||||
|
||||
<?php endforeach; endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
public function cache( $args ) {
|
||||
$social_network = $this->vars->social_network();
|
||||
$type_selected = isset( $this->settings['caching_type'] ) ? $this->settings['caching_type'] : 'page';
|
||||
$caching_time = isset( $this->settings['caching_time'] ) ? $this->settings['caching_time'] : 1;
|
||||
$cache_time_unit_selected = isset( $this->settings['cache_time_unit'] ) ? $this->settings['cache_time_unit'] : 'hours';
|
||||
$cache_cron_interval_selected = isset( $this->settings['cache_cron_interval'] ) ? $this->settings['cache_cron_interval'] : '';
|
||||
$cache_cron_time = isset( $this->settings['cache_cron_time'] ) ? $this->settings['cache_cron_time'] : '';
|
||||
$cache_cron_am_pm = isset( $this->settings['cache_cron_am_pm'] ) ? $this->settings['cache_cron_am_pm'] : '';
|
||||
|
||||
?>
|
||||
<div class="sbspf_cache_settings_wrap">
|
||||
<div class="sbspf_row">
|
||||
<input type="radio" name="<?php echo $this->option_name.'[caching_type]'; ?>" class="sbspf_caching_type_input" id="sbspf_caching_type_page" value="page"<?php if ( $type_selected === 'page' ) echo ' checked'?>>
|
||||
<label class="sbspf_radio_label" for="sbspf_caching_type_page"><?php _e ( 'When the page loads', 'feeds-for-youtube' ); ?></label>
|
||||
<a class="sbspf_tooltip_link" href="JavaScript:void(0);" style="position: relative; top: 2px;"><?php echo $this->default_tooltip_text() ?></a>
|
||||
<p class="sbspf_tooltip sbspf_more_info"><?php echo sprintf( __( "Your %s data is temporarily cached by the plugin in your WordPress database. There are two ways that you can set the plugin to check for new data:<br><br>
|
||||
<b>1. When the page loads</b><br>Selecting this option means that when the cache expires then the plugin will check %s for new posts the next time that the feed is loaded. You can choose how long this data should be cached for with a minimum time of 15 minutes. If you set the time to 60 minutes then the plugin will clear the cached data after that length of time, and the next time the page is viewed it will check for new data. <b>Tip:</b> If you're experiencing an issue with the plugin not updating automatically then try enabling the setting labeled <b>'Cron Clear Cache'</b> which is located on the 'Customize' tab.<br><br>
|
||||
<b>2. In the background</b><br>Selecting this option means that the plugin will check for new data in the background so that the feed is updated behind the scenes. You can select at what time and how often the plugin should check for new data using the settings below. <b>Please note</b> that the plugin will initially check for data from YouTube when the page first loads, but then after that will check in the background on the schedule selected - unless the cache is cleared.", 'feeds-for-youtube' ), $social_network, $social_network ); ?>
|
||||
</p>
|
||||
</div>
|
||||
<div class="sbspf_row sbspf-caching-page-options" style="display: none;">
|
||||
<?php _e ( 'Every', 'feeds-for-youtube' ); ?>:
|
||||
<input name="<?php echo $this->option_name.'[caching_time]'; ?>" type="text" value="<?php echo esc_attr( $caching_time ); ?>" size="4">
|
||||
<select name="<?php echo $this->option_name.'[caching_time_unit]'; ?>">
|
||||
<option value="minutes"<?php if ( $cache_time_unit_selected === 'minutes' ) echo ' selected'?>><?php _e ( 'Minutes', 'feeds-for-youtube' ); ?></option>
|
||||
<option value="hours"<?php if ( $cache_time_unit_selected === 'hours' ) echo ' selected'?>><?php _e ( 'Hours', 'feeds-for-youtube' ); ?></option>
|
||||
<option value="days"<?php if ( $cache_time_unit_selected === 'days' ) echo ' selected'?>><?php _e ( 'Days', 'feeds-for-youtube' ); ?></option>
|
||||
</select>
|
||||
<a class="sbspf_tooltip_link" href="JavaScript:void(0);"><?php _e ( 'What does this mean?', 'feeds-for-youtube' ); ?></a>
|
||||
<p class="sbspf_tooltip sbspf_more_info"><?php echo sprintf( __("Your %s posts are temporarily cached by the plugin in your WordPress database. You can choose how long the posts should be cached for. If you set the time to 1 hour then the plugin will clear the cache after that length of time and check %s for posts again.", 'feeds-for-youtube' ), $social_network, $social_network ); ?></p>
|
||||
</div>
|
||||
|
||||
<div class="sbspf_row">
|
||||
<input type="radio" name="<?php echo $this->option_name.'[caching_type]'; ?>" id="sbspf_caching_type_cron" class="sbspf_caching_type_input" value="background" <?php if ( $type_selected === 'background' ) echo ' checked'?>>
|
||||
<label class="sbspf_radio_label" for="sbspf_caching_type_cron"><?php _e ( 'In the background', 'feeds-for-youtube' ); ?></label>
|
||||
</div>
|
||||
<div class="sbspf_row sbspf-caching-cron-options" style="display: block;">
|
||||
|
||||
<select name="<?php echo $this->option_name.'[cache_cron_interval]'; ?>" id="sbspf_cache_cron_interval">
|
||||
<option value="30mins"<?php if ( $cache_cron_interval_selected === '30mins' ) echo ' selected'?>><?php _e ( 'Every 30 minutes', 'feeds-for-youtube' ); ?></option>
|
||||
<option value="1hour"<?php if ( $cache_cron_interval_selected === '1hour' ) echo ' selected'?>><?php _e ( 'Every hour', 'feeds-for-youtube' ); ?></option>
|
||||
<option value="12hours"<?php if ( $cache_cron_interval_selected === '12hours' ) echo ' selected'?>><?php _e ( 'Every 12 hours', 'feeds-for-youtube' ); ?></option>
|
||||
<option value="24hours"<?php if ( $cache_cron_interval_selected === '24hours' ) echo ' selected'?>><?php _e ( 'Every 24 hours', 'feeds-for-youtube' ); ?></option>
|
||||
</select>
|
||||
|
||||
<div id="sbspf-caching-time-settings" style="">
|
||||
<?php _e ( 'at', 'feeds-for-youtube' ); ?>
|
||||
<select name="<?php echo $this->option_name.'[cache_cron_time]'; ?>" style="width: 80px">
|
||||
<option value="1"<?php if ( (int)$cache_cron_time === 1 ) echo ' selected'?>>1:00</option>
|
||||
<option value="2"<?php if ( (int)$cache_cron_time === 2 ) echo ' selected'?>>2:00</option>
|
||||
<option value="3"<?php if ( (int)$cache_cron_time === 3 ) echo ' selected'?>>3:00</option>
|
||||
<option value="4"<?php if ( (int)$cache_cron_time === 4 ) echo ' selected'?>>4:00</option>
|
||||
<option value="5"<?php if ( (int)$cache_cron_time === 5 ) echo ' selected'?>>5:00</option>
|
||||
<option value="6"<?php if ( (int)$cache_cron_time === 6 ) echo ' selected'?>>6:00</option>
|
||||
<option value="7"<?php if ( (int)$cache_cron_time === 7 ) echo ' selected'?>>7:00</option>
|
||||
<option value="8"<?php if ( (int)$cache_cron_time === 8 ) echo ' selected'?>>8:00</option>
|
||||
<option value="9"<?php if ( (int)$cache_cron_time === 9 ) echo ' selected'?>>9:00</option>
|
||||
<option value="10"<?php if ( (int)$cache_cron_time === 10 ) echo ' selected'?>>10:00</option>
|
||||
<option value="11"<?php if ( (int)$cache_cron_time === 11 ) echo ' selected'?>>11:00</option>
|
||||
<option value="0"<?php if ( (int)$cache_cron_time === 0 ) echo ' selected'?>>12:00</option>
|
||||
</select>
|
||||
|
||||
<select name="<?php echo $this->option_name.'[cache_cron_am_pm]'; ?>" style="width: 50px">
|
||||
<option value="am"<?php if ( $cache_cron_am_pm === 'am' ) echo ' selected'?>><?php _e ( 'AM', 'feeds-for-youtube' ); ?></option>
|
||||
<option value="pm"<?php if ( $cache_cron_am_pm === 'pm' ) echo ' selected'?>><?php _e ( 'PM', 'feeds-for-youtube' ); ?></option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
if ( wp_next_scheduled( 'sbspf_feed_update' ) ) {
|
||||
$time_format = get_option( 'time_format' );
|
||||
if ( ! $time_format ) {
|
||||
$time_format = 'g:i a';
|
||||
}
|
||||
//
|
||||
$schedule = wp_get_schedule( 'sbspf_feed_update' );
|
||||
if ( $schedule == '30mins' ) $schedule = __( 'every 30 minutes', 'feeds-for-youtube' );
|
||||
if ( $schedule == 'twicedaily' ) $schedule = __( 'every 12 hours', 'feeds-for-youtube' );
|
||||
$sbspf_next_cron_event = wp_next_scheduled( 'sbspf_feed_update' );
|
||||
echo '<p class="sbspf-caching-sched-notice"><span><b>' . __( 'Next check', 'feeds-for-youtube' ) . ': ' . date( $time_format, $sbspf_next_cron_event + sbspf_get_utc_offset() ) . ' (' . $schedule . ')</b> - ' . __( 'Note: Saving the settings on this page will clear the cache and reset this schedule', 'feeds-for-youtube' ) . '</span></p>';
|
||||
} else {
|
||||
echo '<p style="font-size: 11px; color: #666;">' . __( 'Nothing currently scheduled', 'feeds-for-youtube' ) . '</p>';
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
public function layout( $args ) {
|
||||
$default = isset( $args['default'] ) ? $args['default'] : $args['layouts'][0]['slug'];
|
||||
$value = isset( $this->settings[ $args['name'] ] ) ? $this->settings[ $args['name'] ] : $default;
|
||||
?>
|
||||
<div class="sbspf_layouts">
|
||||
<?php foreach ( $args['layouts'] as $layout ) : ?>
|
||||
<div class="sbspf_layout_cell">
|
||||
<input class="sbspf_layout_type" id="sbspf_layout_type_<?php echo esc_attr( $layout['slug'] ); ?>" name="<?php echo $this->option_name.'['.$args['name'].']'; ?>" type="radio" value="<?php echo esc_attr( $layout['slug'] ); ?>"<?php if ( $layout['slug'] === $value ) echo ' checked'?>><label for="sbspf_layout_type_<?php echo esc_attr( $layout['slug'] ); ?>"><span class="sbspf_label"><?php echo $layout['label']; ?></span><img src="<?php echo esc_url( $this->vars->plugin_url() . $layout['image'] ); ?>" alt=""></label>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
|
||||
<div class="sbspf_layout_options_wrap">
|
||||
<?php foreach ( $args['layouts'] as $layout ) : ?>
|
||||
<div class="sbspf_layout_settings sbspf_layout_type_<?php echo esc_attr( $layout['slug'] ); ?>">
|
||||
|
||||
<div class="sbspf_layout_setting">
|
||||
<?php echo sby_admin_icon( 'info-circle' ); ?> <span class="sbspf_note" style="margin-left: 0;"><?php echo $layout['note']; ?></span>
|
||||
</div>
|
||||
<?php if ( ! empty( $layout['options'] ) ) : ?>
|
||||
<?php foreach ( $layout['options'] as $option ) :
|
||||
$option['name'] = $layout['slug'].$option['name'];
|
||||
?>
|
||||
<div class="sbspf_layout_setting">
|
||||
<?php if ( $option['callback'] !== 'checkbox' ) : ?>
|
||||
<label title="<?php echo __( 'Click for shortcode option', 'feeds-for-youtube' ); ?>"><?php echo $option['label']; ?></label><code class="sbspf_shortcode"> <?php echo $option['name'] . "\n"; ?>
|
||||
Eg: <?php echo $option['name']; ?>=<?php echo $option['shortcode']['example']; ?></code><br>
|
||||
<?php else:
|
||||
$option['shortcode_example'] = $option['shortcode']['example'];
|
||||
$option['has_shortcode'] = true;
|
||||
endif; ?>
|
||||
<?php call_user_func_array( array( $this, $option['callback'] ), array( $option ) ); ?>
|
||||
|
||||
</div>
|
||||
|
||||
<?php endforeach; ?>
|
||||
<?php endif; ?>
|
||||
|
||||
</div>
|
||||
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
public function instructions( $args ) {
|
||||
?>
|
||||
<div class="sbspf_instructions_wrap">
|
||||
<?php echo $args['instructions']?>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
public function format_title( $label, $name, $shortcode_args = false, $after = '' ) {
|
||||
$formatted_label = '<label for="' . $this->option_name . '_' . $name . '">' . $label .'</label>';
|
||||
if ( $shortcode_args ) {
|
||||
$formatted_label .= '<code class="sbspf_shortcode"> ' . $shortcode_args['key'] . "\n";
|
||||
$formatted_label .= 'Eg: ' . $shortcode_args['key'] . '=' . $shortcode_args['example'] . '</code><br>';
|
||||
}
|
||||
$formatted_label .= $after;
|
||||
|
||||
return $formatted_label;
|
||||
}
|
||||
|
||||
public function validate_options( $input, $tab ) {
|
||||
$updated_options = get_option( $this->option_name, array() );
|
||||
$false_if_empty_keys = $this->get_false_fields( $tab );
|
||||
$textarea_keys = $this->get_textarea_fields( $tab );
|
||||
|
||||
foreach ( $false_if_empty_keys as $false_key ) {
|
||||
$updated_options[ $false_key ] = false;
|
||||
}
|
||||
|
||||
foreach ( $input as $key => $val ) {
|
||||
if ( 'custom_js' === $key ) {
|
||||
$updated_options[ $key ] = $val;
|
||||
} else if ( in_array( $key, $false_if_empty_keys ) ) {
|
||||
$updated_options[ $key ] = ($val === 'on');
|
||||
} elseif ( in_array( $key, $textarea_keys ) ) {
|
||||
$updated_options[ $key ] = sanitize_textarea_field( $val );
|
||||
} elseif ( is_array( $val ) ) {
|
||||
$updated_options[ $key ] = array();
|
||||
foreach ( $val as $key2 => $val2 ) {
|
||||
$updated_options[ $key ][ $key2 ] = sanitize_text_field( $val2 );
|
||||
}
|
||||
} else {
|
||||
$updated_options[ $key ] = sanitize_text_field( $val );
|
||||
}
|
||||
}
|
||||
|
||||
if ( $tab === 'configure' ) {
|
||||
do_action( $this->option_name . '_after_configure_save', $updated_options );
|
||||
}
|
||||
|
||||
return $updated_options;
|
||||
}
|
||||
|
||||
|
||||
public function update_options( $new_settings ) {
|
||||
update_option( $this->get_option_name(), $new_settings );
|
||||
$this->settings = $new_settings;
|
||||
}
|
||||
|
||||
public function get_sections( $tab ) {
|
||||
if ( isset( $this->settings_sections[ $tab ] ) ) {
|
||||
return $this->settings_sections[ $tab ];
|
||||
}
|
||||
return array();
|
||||
}
|
||||
|
||||
public function set_active_tab( $active_tab ) {
|
||||
foreach ( $this->tabs as $tab ) {
|
||||
if ( $tab['slug'] === $active_tab ) {
|
||||
$this->active_tab = $tab['slug'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function get_tabs() {
|
||||
return $this->tabs;
|
||||
}
|
||||
|
||||
public function get_active_tab() {
|
||||
return $this->active_tab;
|
||||
}
|
||||
|
||||
public function get_slug() {
|
||||
return $this->slug;
|
||||
}
|
||||
|
||||
public function get_plugin_name() {
|
||||
return $this->plugin_name;
|
||||
}
|
||||
|
||||
public function get_path( $view ) {
|
||||
return trailingslashit( $this->base_path ) . $view . '.php';
|
||||
}
|
||||
|
||||
public function create_options_page() {
|
||||
require_once trailingslashit( $this->base_path ) . 'main.php';
|
||||
}
|
||||
|
||||
public function next_step() {
|
||||
$return = array();
|
||||
$i = 0;
|
||||
foreach ( $this->tabs as $tab ) {
|
||||
if ( $this->active_tab === $tab['slug'] && isset( $tab['next_step_instructions'] ) ) {
|
||||
$next_tab_slug = isset( $this->tabs[ $i + 1 ]['slug'] ) ? $this->tabs[ $i + 1 ]['slug'] : $tab['slug'];
|
||||
$return = array(
|
||||
'instructions' => $tab['next_step_instructions'],
|
||||
'next_tab' => $next_tab_slug
|
||||
);
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
|
||||
public function get_connected_accounts() {
|
||||
global $sbspf_settings;
|
||||
|
||||
if ( isset( $sbspf_settings['connected_accounts'] ) ) {
|
||||
return $sbspf_settings['connected_accounts'];
|
||||
}
|
||||
return array();
|
||||
}
|
||||
|
||||
public static function connect_account( $args ) {
|
||||
global $sbspf_settings;
|
||||
|
||||
// do connection
|
||||
|
||||
// random fake data
|
||||
$account_id = time();
|
||||
|
||||
$sbspf_settings['connected_accounts'][ $account_id ] = array(
|
||||
'access_token' => 'at_' . str_shuffle( $account_id ),
|
||||
'channel_id' => $account_id,
|
||||
'username' => 'test' . $account_id,
|
||||
'is_valid' => true,
|
||||
'last_checked' => time(),
|
||||
'profile_picture' => $args['profile_picture']
|
||||
);
|
||||
|
||||
update_option( 'sbspf_settings', $sbspf_settings );
|
||||
|
||||
return $sbspf_settings['connected_accounts'][ $account_id ];
|
||||
}
|
||||
|
||||
public function default_tooltip_text() {
|
||||
return '<span class="screen-reader-text">' . __( 'What does this mean?', 'feeds-for-youtube' ) . '</span>' . sby_admin_icon( 'question-circle' );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
/**
|
||||
* SBY Admin Notice.
|
||||
*
|
||||
* @since 2.0
|
||||
*/
|
||||
namespace SmashBalloon\YouTubeFeed\Admin;
|
||||
|
||||
// Exit if accessed directly
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
class SBY_Admin_Notice {
|
||||
|
||||
public function register() {
|
||||
add_action( 'sby_admin_header_notices', array( $this, 'header_notices' ) );
|
||||
add_action( 'wp_ajax_sby_dismiss_upgrade_notice', array( $this, 'dismiss_upgrade_notice' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Header Notices
|
||||
*
|
||||
* @since 2.0
|
||||
*/
|
||||
public function header_notices() {
|
||||
if ( sby_is_pro() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$lite_notice_dismissed = get_transient( 'youtube_feed_dismiss_lite' );
|
||||
if ( $lite_notice_dismissed ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$output = '';
|
||||
|
||||
$upgrade_url = 'https://smashballoon.com/youtube-feed/demo/?utm_campaign='. sby_utm_campaign() .'&utm_source=lite-upgrade-bar';
|
||||
$output .= '<div id="sbc-notice-bar" class="sbc-header-notice">';
|
||||
$output .= sprintf(
|
||||
'<span class="sbc-notice-bar-message">%s <a href="%s" target="_blank" rel="noopener noreferrer">%s</a></span>',
|
||||
__('You\'re using YouTube Feeds Lite. To unlock more features consider', 'feeds-for-youtube'),
|
||||
$upgrade_url,
|
||||
__('upgrading to Pro', 'feeds-for-youtube')
|
||||
);
|
||||
|
||||
$output .= sprintf(
|
||||
'<button type="button" class="sbc-dismiss" id="sbc-dismiss-header-notice" title="%s" data-page="overview">%s</button>',
|
||||
__('Dismiss this message', 'feeds-for-youtube'),
|
||||
'<svg width="20" height="20" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M15.8327 5.34175L14.6577 4.16675L9.99935 8.82508L5.34102 4.16675L4.16602 5.34175L8.82435 10.0001L4.16602 14.6584L5.34102 15.8334L9.99935 11.1751L14.6577 15.8334L15.8327 14.6584L11.1744 10.0001L15.8327 5.34175Z" fill="white"/></svg>'
|
||||
);
|
||||
|
||||
$output .= '</div>';
|
||||
|
||||
echo $output;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Dismiss Upgrade Notice
|
||||
*
|
||||
* @since 2.0
|
||||
*/
|
||||
public function dismiss_upgrade_notice() {
|
||||
// Run a security check.
|
||||
check_ajax_referer( 'sby-admin' , 'nonce');
|
||||
|
||||
if ( ! sby_current_user_can( 'manage_youtube_feed_options' ) ) {
|
||||
wp_send_json_error();
|
||||
}
|
||||
// set the transient so it will hide for next 7 days
|
||||
set_transient( 'youtube_feed_dismiss_lite', 'dismiss', 2 * WEEK_IN_SECONDS );
|
||||
|
||||
wp_send_json_success();
|
||||
wp_die();
|
||||
}
|
||||
|
||||
}
|
||||
532
wp-content/plugins/youtube-feed-pro/inc/Admin/SBY_New_User.php
Normal file
532
wp-content/plugins/youtube-feed-pro/inc/Admin/SBY_New_User.php
Normal file
@@ -0,0 +1,532 @@
|
||||
<?php
|
||||
/**
|
||||
* SBY_New_User.
|
||||
*
|
||||
* @since 2.18
|
||||
*/
|
||||
|
||||
namespace SmashBalloon\YouTubeFeed\Admin;
|
||||
|
||||
class SBY_New_User extends SBY_Notifications {
|
||||
/**
|
||||
* Source of notifications content.
|
||||
*
|
||||
* @since 2.18
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const SOURCE_URL = 'https://plugin.smashballoon.com/newuser.json';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
const OPTION_NAME = 'sby_newuser_notifications';
|
||||
|
||||
/**
|
||||
* Register hooks.
|
||||
*
|
||||
* @since 2.18
|
||||
*/
|
||||
public function hooks() {
|
||||
add_action( 'admin_notices', array( $this, 'output' ), 8 );
|
||||
|
||||
add_action( 'admin_init', array( $this, 'dismiss' ) );
|
||||
add_action( 'wp_ajax_sby_review_notice_consent_update', array( $this, 'review_notice_consent' ) );
|
||||
}
|
||||
|
||||
public function option_name() {
|
||||
return self::OPTION_NAME;
|
||||
}
|
||||
|
||||
public function source_url() {
|
||||
return self::SOURCE_URL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify notification data before it is saved.
|
||||
*
|
||||
* @param array $notifications Array of notifications items to verify.
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @since 2.18
|
||||
*/
|
||||
public function verify( $notifications ) {
|
||||
$data = array();
|
||||
|
||||
if ( ! is_array( $notifications ) || empty( $notifications ) ) {
|
||||
return $data;
|
||||
}
|
||||
|
||||
$option = $this->get_option();
|
||||
|
||||
foreach ( $notifications as $key => $notification ) {
|
||||
|
||||
// The message should never be empty, if they are, ignore.
|
||||
if ( empty( $notification['content'] ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Ignore if notification has already been dismissed.
|
||||
if ( ! empty( $option['dismissed'] ) && in_array( $notification['id'], $option['dismissed'] ) ) { // phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict
|
||||
continue;
|
||||
}
|
||||
|
||||
$data[ $key ] = $notification;
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify saved notification data for active notifications.
|
||||
*
|
||||
* @since 2.18
|
||||
*
|
||||
* @param array $notifications Array of notifications items to verify.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function verify_active( $notifications ) {
|
||||
if ( ! is_array( $notifications ) || empty( $notifications ) ) {
|
||||
return array();
|
||||
}
|
||||
|
||||
$sby_statuses_option = get_option( 'sby_statuses', array() );
|
||||
$current_time = sby_get_current_time();
|
||||
|
||||
// rating notice logic
|
||||
$sby_rating_notice_option = get_option( 'sby_rating_notice', false );
|
||||
$sby_rating_notice_waiting = get_transient( 'feeds_for_youtube_rating_notice_waiting' );
|
||||
$should_show_rating_notice = ($sby_rating_notice_waiting !== 'waiting' && $sby_rating_notice_option !== 'dismissed');
|
||||
|
||||
// new user discount logic
|
||||
$in_new_user_month_range = true;
|
||||
$should_show_new_user_discount = false;
|
||||
$has_been_one_month_since_rating_dismissal = isset( $sby_statuses_option['rating_notice_dismissed'] ) ? ((int)$sby_statuses_option['rating_notice_dismissed'] + ((int)$notifications['review']['wait'] * DAY_IN_SECONDS)) < $current_time + 1: true;
|
||||
|
||||
if ( isset( $sby_statuses_option['first_install'] ) && $sby_statuses_option['first_install'] === 'from_update' ) {
|
||||
global $current_user;
|
||||
$user_id = $current_user->ID;
|
||||
$ignore_new_user_sale_notice_meta = get_user_meta( $user_id, 'sby_ignore_new_user_sale_notice' );
|
||||
$ignore_new_user_sale_notice_meta = isset( $ignore_new_user_sale_notice_meta[0] ) ? $ignore_new_user_sale_notice_meta[0] : '';
|
||||
if ( $ignore_new_user_sale_notice_meta !== 'always' ) {
|
||||
$should_show_new_user_discount = true;
|
||||
}
|
||||
} elseif ( $in_new_user_month_range && $has_been_one_month_since_rating_dismissal && $sby_rating_notice_waiting !== 'waiting' ) {
|
||||
global $current_user;
|
||||
$user_id = $current_user->ID;
|
||||
$ignore_new_user_sale_notice_meta = get_user_meta( $user_id, 'sby_ignore_new_user_sale_notice' );
|
||||
$ignore_new_user_sale_notice_meta = isset( $ignore_new_user_sale_notice_meta[0] ) ? $ignore_new_user_sale_notice_meta[0] : '';
|
||||
|
||||
if ( $ignore_new_user_sale_notice_meta !== 'always'
|
||||
&& isset( $sby_statuses_option['first_install'] )
|
||||
&& $current_time > (int)$sby_statuses_option['first_install'] + ((int)$notifications['discount']['wait'] * DAY_IN_SECONDS) ) {
|
||||
$should_show_new_user_discount = true;
|
||||
}
|
||||
}
|
||||
|
||||
if ( sby_is_pro_version() ) {
|
||||
$should_show_new_user_discount = false;
|
||||
}
|
||||
|
||||
if ( isset( $notifications['review'] ) && $should_show_rating_notice ) {
|
||||
return array( $notifications['review'] );
|
||||
} elseif ( isset( $notifications['discount'] ) && $should_show_new_user_discount ) {
|
||||
return array( $notifications['discount'] );
|
||||
}
|
||||
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get notification data.
|
||||
*
|
||||
* @since 2.18
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get() {
|
||||
if ( ! $this->has_access() ) {
|
||||
return array();
|
||||
}
|
||||
|
||||
$option = $this->get_option();
|
||||
|
||||
// Only update if does not exist.
|
||||
if ( empty( $option['update'] ) ) {
|
||||
$this->update();
|
||||
}
|
||||
|
||||
$events = ! empty( $option['events'] ) ? $this->verify_active( $option['events'] ) : array();
|
||||
$feed = ! empty( $option['feed'] ) ? $this->verify_active( $option['feed'] ) : array();
|
||||
|
||||
return array_merge( $events, $feed );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a manual notification event.
|
||||
*
|
||||
* @since 2.18
|
||||
*
|
||||
* @param array $notification Notification data.
|
||||
*/
|
||||
public function add( $notification ) {
|
||||
if ( empty( $notification['id'] ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$option = $this->get_option();
|
||||
|
||||
if ( in_array( $notification['id'], $option['dismissed'] ) ) { // phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ( $option['events'] as $item ) {
|
||||
if ( $item['id'] === $notification['id'] ) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
$notification = $this->verify( array( $notification ) );
|
||||
|
||||
update_option(
|
||||
$this->option_name(),
|
||||
array(
|
||||
'update' => $option['update'],
|
||||
'feed' => $option['feed'],
|
||||
'events' => array_merge( $notification, $option['events'] ),
|
||||
'dismissed' => $option['dismissed'],
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update notification data from feed.
|
||||
*
|
||||
* @since 2.18
|
||||
*/
|
||||
public function update() {
|
||||
$feed = $this->fetch_feed();
|
||||
$option = $this->get_option();
|
||||
|
||||
update_option(
|
||||
$this->option_name(),
|
||||
array(
|
||||
'update' => time(),
|
||||
'feed' => $feed,
|
||||
'events' => $option['events'],
|
||||
'dismissed' => $option['dismissed'],
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Do not enqueue anything extra.
|
||||
*
|
||||
* @since 2.18
|
||||
*/
|
||||
public function enqueues() {
|
||||
|
||||
}
|
||||
|
||||
public function review_notice_consent() {
|
||||
//Security Checks
|
||||
check_ajax_referer( 'sby-admin', 'sby_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.
|
||||
}
|
||||
|
||||
$consent = isset( $_POST[ 'consent' ] ) ? sanitize_text_field( $_POST[ 'consent' ] ) : '';
|
||||
|
||||
update_option( 'sby_review_consent', $consent );
|
||||
|
||||
if ( $consent == 'no' ) {
|
||||
$sby_statuses_option = get_option( 'sby_statuses', array() );
|
||||
update_option( 'sby_rating_notice', 'dismissed', false );
|
||||
$sby_statuses_option['rating_notice_dismissed'] = sby_get_current_time();
|
||||
update_option( 'sby_statuses', $sby_statuses_option, false );
|
||||
}
|
||||
wp_die();
|
||||
}
|
||||
|
||||
/**
|
||||
* Output notifications on Form Overview admin area.
|
||||
*
|
||||
* @since 2.18
|
||||
*/
|
||||
public function output() {
|
||||
// If the Instagram Feed plugin is active, notices only shown on SBY Settings pages
|
||||
if ( function_exists( 'sb_instagram_activate' )
|
||||
&& ! function_exists( 'sb_instagram_feed_pro_init' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( function_exists( 'cff_check_for_db_updates' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( function_exists( 'ctf_check_for_db_updates' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$notifications = $this->get();
|
||||
|
||||
if ( empty( $notifications ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// new user notices included in regular settings page notifications so this
|
||||
// checks to see if user is one of those pages
|
||||
if ( ! empty( $_GET['page'] )
|
||||
&& ( strpos( $_GET['page'], 'sby' ) !== false || strpos( $_GET['page'], 'youtube-feed' ) !== false ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$content_allowed_tags = array(
|
||||
'em' => array(),
|
||||
'strong' => array(),
|
||||
'span' => array(
|
||||
'style' => array(),
|
||||
),
|
||||
'a' => array(
|
||||
'href' => array(),
|
||||
'target' => array(),
|
||||
'rel' => array(),
|
||||
),
|
||||
);
|
||||
$image_overlay = '';
|
||||
|
||||
foreach ( $notifications as $notification ) {
|
||||
$img_src = SBY_PLUGIN_URL . 'img/' . sanitize_text_field( $notification['image'] );
|
||||
$type = sanitize_text_field( $notification['id'] );
|
||||
// check if this is a review notice
|
||||
if( $type == 'review' ) {
|
||||
$review_consent = get_option( 'sby_review_consent' );
|
||||
$sby_open_feedback_url = 'https://smashballoon.com/feedback/?plugin=youtube-free';
|
||||
// step #1 for the review notice
|
||||
if ( ! $review_consent ) {
|
||||
?>
|
||||
<div class="sby_notice sby_review_notice_step_1">
|
||||
<div class="sby_thumb">
|
||||
<img src="<?php echo esc_url( str_replace( array( 'sbi', 'png' ), array( 'sby', 'svg' ), $img_src ) ); ?>" alt="notice">
|
||||
</div>
|
||||
<div class="sby-notice-text">
|
||||
<p class="sby-notice-text-p"><?php echo __( 'Are you enjoying the YouTube Feeds Plugin?', 'feeds-for-youtube' ); ?></p>
|
||||
</div>
|
||||
<div class="sby-notice-consent-btns">
|
||||
<?php
|
||||
printf(
|
||||
'<button class="sby-btn-link" id="sby_review_consent_yes">%s</button>',
|
||||
__( 'Yes', 'feeds-for-youtube' )
|
||||
);
|
||||
|
||||
printf(
|
||||
'<a href="%s" target="_blank" rel="nofollow noopener" class="sby-btn-link" id="sby_review_consent_no">%s</a>',
|
||||
$sby_open_feedback_url,
|
||||
__( 'No', 'feeds-for-youtube' )
|
||||
);
|
||||
?>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
$close_href = add_query_arg( array( 'sby_dismiss' => $type ) );
|
||||
|
||||
$title = $this->get_notice_title( $notification );
|
||||
$content = $this->get_notice_content( $notification, $content_allowed_tags );
|
||||
|
||||
$buttons = array();
|
||||
if ( ! empty( $notification['btns'] ) && is_array( $notification['btns'] ) ) {
|
||||
foreach ( $notification['btns'] as $btn_type => $btn ) {
|
||||
if ( ! is_array( $btn['url'] ) ) {
|
||||
$buttons[ $btn_type ]['url'] = $this->replace_merge_fields( $btn['url'], $notification );
|
||||
} elseif ( is_array( $btn['url'] ) ) {
|
||||
$buttons[ $btn_type ]['url'] = add_query_arg( $btn['url'] );
|
||||
}
|
||||
|
||||
$buttons[ $btn_type ]['attr'] = '';
|
||||
if ( ! empty( $btn['attr'] ) ) {
|
||||
$buttons[ $btn_type ]['attr'] = ' target="_blank" rel="noopener noreferrer"';
|
||||
}
|
||||
|
||||
$buttons[ $btn_type ]['class'] = '';
|
||||
if ( ! empty( $btn['class'] ) ) {
|
||||
$buttons[ $btn_type ]['class'] = ' ' . $btn['class'];
|
||||
}
|
||||
|
||||
$buttons[ $btn_type ]['text'] = '';
|
||||
if ( ! empty( $btn['text'] ) ) {
|
||||
$buttons[ $btn_type ]['text'] = wp_kses( $btn['text'], $content_allowed_tags );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$review_consent = get_option( 'sby_review_consent' );
|
||||
$review_step2_style = '';
|
||||
if ( $type == 'review' && ! $review_consent ) {
|
||||
$review_step2_style = 'style="display: none;"';
|
||||
}
|
||||
?>
|
||||
|
||||
<div class="sby_notice_op sby_notice sby_<?php echo esc_attr( $type ); ?>_notice" <?php echo !empty( $review_step2_style ) ? $review_step2_style : ''; ?>>
|
||||
<div class="sby_thumb">
|
||||
<img src="<?php echo esc_url( str_replace( array( 'sbi', 'png' ), array( 'sby', 'svg' ), $img_src ) ); ?>" alt="notice">
|
||||
<?php echo $image_overlay; ?>
|
||||
</div>
|
||||
<div class="sby-notice-text">
|
||||
<div class="sby-notice-text-inner">
|
||||
<h3 class="sby-notice-text-header"><?php echo $title; ?></h3>
|
||||
<p class="sby-notice-text-p"><?php echo $content; ?></p>
|
||||
</div>
|
||||
<div class="sby-notice-btns-wrap">
|
||||
<p class="sby-notice-links">
|
||||
<?php
|
||||
foreach ( $buttons as $type => $button ) :
|
||||
$btn_classes = array('sby-btn');
|
||||
$btn_classes[] = esc_attr( $button['class'] );
|
||||
if ( $type == 'primary' ) {
|
||||
$btn_classes[] = 'sby-btn-blue';
|
||||
} else {
|
||||
$btn_classes[] = 'sby-btn-grey';
|
||||
}
|
||||
?>
|
||||
<a class="<?php echo implode(' ', $btn_classes); ?>" href="<?php echo esc_attr( str_replace( 'sbi_', 'sby_', $button['url'] ) ); ?>"<?php echo $button['attr']; ?>><?php echo $button['text']; ?></a>
|
||||
<?php endforeach; ?>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="sby-notice-dismiss">
|
||||
<a href="<?php echo esc_url( $close_href ); ?>">
|
||||
<svg width="14" height="14" viewBox="0 0 14 14" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<path d="M14 1.41L12.59 0L7 5.59L1.41 0L0 1.41L5.59 7L0 12.59L1.41 14L7 8.41L12.59 14L14 12.59L8.41 7L14 1.41Z" fill="#141B38"></path>
|
||||
</svg>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* SBY Get Notice Title depending on the notice type
|
||||
*
|
||||
* @since 2.0
|
||||
*
|
||||
* @param array $notification
|
||||
*
|
||||
* @return string $title
|
||||
*/
|
||||
public function get_notice_title( $notification ) {
|
||||
$type = $notification['id'];
|
||||
$title = '';
|
||||
|
||||
// Notice title depending on notice type
|
||||
if ( $type == 'review' ) {
|
||||
$title = __( 'Glad to hear you are enjoying it. Would you consider leaving a positive review?', 'feeds-for-youtube' );
|
||||
} else if ( $type == 'discount' ) {
|
||||
$title = __( 'Exclusive Offer! 60% OFF', 'feeds-for-youtube' );
|
||||
} else {
|
||||
$title = $this->replace_merge_fields( $notification['title'], $notification );
|
||||
}
|
||||
|
||||
return $title;
|
||||
}
|
||||
|
||||
/**
|
||||
* SBY Get Notice Content depending on the notice type
|
||||
*
|
||||
* @since 2.0
|
||||
*
|
||||
* @param array $notification
|
||||
* @param array $content_allowed_tags
|
||||
*
|
||||
* @return string $content
|
||||
*/
|
||||
public function get_notice_content( $notification, $content_allowed_tags ) {
|
||||
$type = $notification['id'];
|
||||
$content = '';
|
||||
|
||||
// Notice content depending on notice type
|
||||
if ( $type == 'review' ) {
|
||||
$content = __( 'It really helps to support the plugin and help others to discover it too!', 'feeds-for-youtube' );
|
||||
} else if ( $type == 'discount' ) {
|
||||
$content = __( 'We don’t run promotions very often, but for a limited time we’re offering 60% Off our Pro version to all users of our free YouTube Feeds.', 'feeds-for-youtube' );
|
||||
} else {
|
||||
if ( ! empty( $notification['content'] ) ) {
|
||||
$content = wp_kses( $this->replace_merge_fields( $notification['content'], $notification ), $content_allowed_tags );
|
||||
}
|
||||
}
|
||||
return $content;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hide messages permanently or some can be dismissed temporarily
|
||||
*
|
||||
* @since 2.18
|
||||
*/
|
||||
public function dismiss() {
|
||||
global $current_user;
|
||||
$user_id = $current_user->ID;
|
||||
$sby_statuses_option = get_option( 'sby_statuses', array() );
|
||||
|
||||
if ( isset( $_GET['sby_ignore_rating_notice_nag'] ) ) {
|
||||
if ( (int)$_GET['sby_ignore_rating_notice_nag'] === 1 ) {
|
||||
update_option( 'sby_rating_notice', 'dismissed', false );
|
||||
$sby_statuses_option['rating_notice_dismissed'] = sby_get_current_time();
|
||||
update_option( 'sby_statuses', $sby_statuses_option, false );
|
||||
|
||||
} elseif ( $_GET['sby_ignore_rating_notice_nag'] === 'later' ) {
|
||||
set_transient( 'feeds_for_youtube_rating_notice_waiting', 'waiting', 2 * WEEK_IN_SECONDS );
|
||||
update_option( 'sby_rating_notice', 'pending', false );
|
||||
}
|
||||
}
|
||||
|
||||
if ( isset( $_GET['sby_ignore_new_user_sale_notice'] ) ) {
|
||||
$response = sanitize_text_field( $_GET['sby_ignore_new_user_sale_notice'] );
|
||||
if ( $response === 'always' ) {
|
||||
update_user_meta( $user_id, 'sby_ignore_new_user_sale_notice', 'always' );
|
||||
|
||||
$current_month_number = (int)date('n', sby_get_current_time() );
|
||||
$not_early_in_the_year = ($current_month_number > 5);
|
||||
|
||||
if ( $not_early_in_the_year ) {
|
||||
update_user_meta( $user_id, 'sby_ignore_bfcm_sale_notice', date( 'Y', sby_get_current_time() ) );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if ( isset( $_GET['sby_ignore_bfcm_sale_notice'] ) ) {
|
||||
$response = sanitize_text_field( $_GET['sby_ignore_bfcm_sale_notice'] );
|
||||
if ( $response === 'always' ) {
|
||||
update_user_meta( $user_id, 'sby_ignore_bfcm_sale_notice', 'always' );
|
||||
} elseif ( $response === date( 'Y', sby_get_current_time() ) ) {
|
||||
update_user_meta( $user_id, 'sby_ignore_bfcm_sale_notice', date( 'Y', sby_get_current_time() ) );
|
||||
}
|
||||
update_user_meta( $user_id, 'sby_ignore_new_user_sale_notice', 'always' );
|
||||
}
|
||||
|
||||
if ( isset( $_GET['sby_dismiss'] ) ) {
|
||||
if ( $_GET['sby_dismiss'] === 'review' ) {
|
||||
update_option( 'sby_rating_notice', 'dismissed', false );
|
||||
$sby_statuses_option['rating_notice_dismissed'] = sby_get_current_time();
|
||||
update_option( 'sby_statuses', $sby_statuses_option, false );
|
||||
} elseif ( $_GET['sby_dismiss'] === 'discount' ) {
|
||||
update_user_meta( $user_id, 'sby_ignore_new_user_sale_notice', 'always' );
|
||||
|
||||
$current_month_number = (int)date('n', sby_get_current_time() );
|
||||
$not_early_in_the_year = ($current_month_number > 5);
|
||||
|
||||
if ( $not_early_in_the_year ) {
|
||||
update_user_meta( $user_id, 'sby_ignore_bfcm_sale_notice', date( 'Y', sby_get_current_time() ) );
|
||||
}
|
||||
}
|
||||
update_user_meta( $user_id, 'sby_ignore_new_user_sale_notice', 'always' );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,832 @@
|
||||
<?php
|
||||
/**
|
||||
* SBY_Notifications.
|
||||
*
|
||||
* @since 2.0
|
||||
*/
|
||||
namespace SmashBalloon\YouTubeFeed\Admin;
|
||||
|
||||
// Exit if accessed directly
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
class SBY_Notifications {
|
||||
|
||||
/**
|
||||
* Source of notifications content.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const SOURCE_URL = 'https://plugin.smashballoon.com/notifications.json';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
const OPTION_NAME = 'sby_notifications';
|
||||
|
||||
/**
|
||||
* JSON data contains notices for all plugins. This is used
|
||||
* to select messages only meant for this plugin
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const PLUGIN = 'youtube';
|
||||
|
||||
/**
|
||||
* Option value.
|
||||
*
|
||||
* @since 2.6/5.9
|
||||
*
|
||||
* @var bool|array
|
||||
*/
|
||||
public $option = false;
|
||||
|
||||
/**
|
||||
* Initialize class.
|
||||
*
|
||||
* @since 2.6/5.9
|
||||
*/
|
||||
public function init() {
|
||||
$this->hooks();
|
||||
}
|
||||
|
||||
/**
|
||||
* Use this function to get the option name to allow
|
||||
* inheritance for the New_User class
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function option_name() {
|
||||
return self::OPTION_NAME;
|
||||
}
|
||||
|
||||
/**
|
||||
* Use this function to get the source URL to allow
|
||||
* inheritance for the New_User class
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function source_url() {
|
||||
return self::SOURCE_URL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register hooks.
|
||||
*
|
||||
* @since 2.6/5.9
|
||||
*/
|
||||
public function hooks() {
|
||||
add_action( 'admin_enqueue_scripts', array( $this, 'enqueues' ) );
|
||||
|
||||
add_action( 'sby_admin_notices', array( $this, 'output' ) );
|
||||
|
||||
// on cron. Once a week?
|
||||
add_action( 'sby_notification_update', array( $this, 'update' ) );
|
||||
|
||||
add_action( 'wp_ajax_sby_dashboard_notification_dismiss', array( $this, 'dismiss' ) );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check if user has access and is enabled.
|
||||
*
|
||||
* @since 2.6/5.9
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function has_access() {
|
||||
$access = false;
|
||||
|
||||
if ( current_user_can( 'manage_youtube_feed_options' ) || current_user_can( 'manage_options' ) ) {
|
||||
$access = true;
|
||||
}
|
||||
|
||||
return apply_filters( 'sby_admin_notifications_has_access', $access );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get option value.
|
||||
*
|
||||
* @since 2.6/5.9
|
||||
*
|
||||
* @param bool $cache Reference property cache if available.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_option( $cache = true ) {
|
||||
if ( $this->option && $cache ) {
|
||||
return $this->option;
|
||||
}
|
||||
|
||||
$option = get_option( $this->option_name(), array() );
|
||||
|
||||
$this->option = array(
|
||||
'update' => ! empty( $option['update'] ) ? $option['update'] : 0,
|
||||
'events' => ! empty( $option['events'] ) ? $option['events'] : array(),
|
||||
'feed' => ! empty( $option['feed'] ) ? $option['feed'] : array(),
|
||||
'dismissed' => ! empty( $option['dismissed'] ) ? $option['dismissed'] : array(),
|
||||
);
|
||||
|
||||
return $this->option;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch notifications from feed.
|
||||
*
|
||||
* @since 2.6/5.9
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function fetch_feed() {
|
||||
$res = wp_remote_get( $this->source_url() );
|
||||
|
||||
if ( is_wp_error( $res ) ) {
|
||||
return array();
|
||||
}
|
||||
|
||||
$body = wp_remote_retrieve_body( $res );
|
||||
|
||||
if ( empty( $body ) ) {
|
||||
return array();
|
||||
}
|
||||
|
||||
return $this->verify( json_decode( $body, true ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify notification data before it is saved.
|
||||
*
|
||||
* @since 2.6/5.9
|
||||
*
|
||||
* @param array $notifications Array of notifications items to verify.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function verify( $notifications ) { // phpcs:ignore Generic.Metrics.CyclomaticComplexity.TooHigh
|
||||
$data = array();
|
||||
|
||||
if ( ! is_array( $notifications ) || empty( $notifications ) ) {
|
||||
return $data;
|
||||
}
|
||||
|
||||
$option = $this->get_option();
|
||||
|
||||
foreach ( $notifications as $notification ) {
|
||||
|
||||
// Ignore if not a targeted plugin
|
||||
if ( ! empty( $notification['plugin'] ) && is_array( $notification['plugin'] ) && ! in_array( self::PLUGIN, $notification['plugin'], true ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Ignore if max wp version detected
|
||||
if ( ! empty( $notification['maxwpver'] ) && version_compare( get_bloginfo( 'version' ), $notification['maxwpver'], '>' ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Ignore if max version has been reached
|
||||
if ( ! empty( $notification['maxver'] ) && version_compare( $notification['maxver'], SBYVER ) < 0 ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Ignore if min version has not been reached
|
||||
if ( ! empty( $notification['minver'] ) && version_compare( $notification['minver'], SBYVER ) > 0 ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Ignore if a specific sby_status is empty or false
|
||||
if ( ! empty( $notification['statuscheck'] ) ) {
|
||||
$status_key = sanitize_key( $notification['statuscheck'] );
|
||||
$sby_statuses_option = get_option( 'sby_statuses', array() );
|
||||
|
||||
if ( empty( $sby_statuses_option[ $status_key ] ) ) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// The message and license should never be empty, if they are, ignore.
|
||||
if ( empty( $notification['content'] ) || empty( $notification['type'] ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Ignore if license type does not match.
|
||||
$license = sby_is_pro_version() ? 'pro' : 'free';
|
||||
|
||||
if ( ! in_array( $license, $notification['type'], true ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Ignore if expired.
|
||||
if ( ! empty( $notification['end'] ) && time() > strtotime( $notification['end'] ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Ignore if notification has already been dismissed.
|
||||
if ( ! empty( $option['dismissed'] ) && in_array( $notification['id'], $option['dismissed'] ) ) { // phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict
|
||||
continue;
|
||||
}
|
||||
|
||||
// Ignore message "9".
|
||||
if ( in_array( (int)$notification['id'], array( 9 ) ) ) { // phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict
|
||||
continue;
|
||||
}
|
||||
|
||||
// TODO: Ignore if notification existed before installing SBY.
|
||||
// Prevents bombarding the user with notifications after activation.
|
||||
$activated = false;
|
||||
if ( ! empty( $activated )
|
||||
&& ! empty( $notification['start'] )
|
||||
&& $activated > strtotime( $notification['start'] ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$data[] = $notification;
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify saved notification data for active notifications.
|
||||
*
|
||||
* @since 2.6/5.9
|
||||
*
|
||||
* @param array $notifications Array of notifications items to verify.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function verify_active( $notifications ) {
|
||||
if ( ! is_array( $notifications ) || empty( $notifications ) ) {
|
||||
return array();
|
||||
}
|
||||
|
||||
// Remove notfications that are not active.
|
||||
foreach ( $notifications as $key => $notification ) {
|
||||
if ( ( ! empty( $notification['start'] ) && sby_get_current_time() < strtotime( $notification['start'] ) )
|
||||
|| ( ! empty( $notification['end'] ) && sby_get_current_time() > strtotime( $notification['end'] ) ) ) {
|
||||
unset( $notifications[ $key ] );
|
||||
}
|
||||
|
||||
if ( empty( $notification['recent_install_override'] ) && $this->recently_installed() ) {
|
||||
unset( $notifications[ $key ] );
|
||||
}
|
||||
|
||||
// Ignore if max version has been reached
|
||||
if ( ! empty( $notification['maxver'] ) && version_compare( $notification['maxver'], SBYVER ) < 0 ) {
|
||||
unset( $notifications[ $key ] );
|
||||
}
|
||||
|
||||
// Ignore if max wp version detected
|
||||
if ( ! empty( $notification['maxwpver'] ) && version_compare( get_bloginfo( 'version' ), $notification['maxwpver'], '>' ) ) {
|
||||
unset( $notifications[ $key ] );
|
||||
}
|
||||
|
||||
// Ignore if min version has not been reached
|
||||
if ( ! empty( $notification['minver'] ) && version_compare( $notification['minver'], SBYVER ) > 0 ) {
|
||||
unset( $notifications[ $key ] );
|
||||
}
|
||||
|
||||
// Ignore if a specific sby_status is empty or false
|
||||
if ( ! empty( $notification['statuscheck'] ) ) {
|
||||
$status_key = sanitize_key( $notification['statuscheck'] );
|
||||
$sby_statuses_option = get_option( 'sby_statuses', array() );
|
||||
|
||||
if ( empty( $sby_statuses_option[ $status_key ] ) ) {
|
||||
unset( $notifications[ $key ] );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $notifications;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*
|
||||
* @since 1.4.5/1.4.2
|
||||
*/
|
||||
public function recently_installed() {
|
||||
$sby_statuses_option = get_option( 'sby_statuses', array() );
|
||||
|
||||
if ( ! isset( $sby_statuses_option['first_install'] ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Plugin was installed less than a week ago
|
||||
if ( (int) $sby_statuses_option['first_install'] > time() - WEEK_IN_SECONDS ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get notification data.
|
||||
*
|
||||
* @since 2.6/5.9
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get() {
|
||||
if ( ! $this->has_access() ) {
|
||||
return array();
|
||||
}
|
||||
|
||||
$option = $this->get_option();
|
||||
|
||||
// Update notifications using async task.
|
||||
if ( empty( $option['update'] ) || sby_get_current_time() > $option['update'] + DAY_IN_SECONDS ) {
|
||||
$this->update();
|
||||
}
|
||||
|
||||
$events = ! empty( $option['events'] ) ? $this->verify_active( $option['events'] ) : array();
|
||||
$feed = ! empty( $option['feed'] ) ? $this->verify_active( $option['feed'] ) : array();
|
||||
|
||||
// If there is a new user notification, add it to the beginning of the notification list
|
||||
$sby_newuser = new SBY_New_User();
|
||||
$newuser_notifications = $sby_newuser->get();
|
||||
|
||||
if ( ! empty( $newuser_notifications ) ) {
|
||||
return $newuser_notifications;
|
||||
}
|
||||
|
||||
return array_merge( $events, $feed );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get notification count.
|
||||
*
|
||||
* @since 2.6/5.9
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function get_count() {
|
||||
return count( $this->get() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a manual notification event.
|
||||
*
|
||||
* @since 2.6/5.9
|
||||
*
|
||||
* @param array $notification Notification data.
|
||||
*/
|
||||
public function add( $notification ) {
|
||||
if ( empty( $notification['id'] ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$option = $this->get_option();
|
||||
|
||||
if ( in_array( $notification['id'], $option['dismissed'] ) ) { // phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ( $option['events'] as $item ) {
|
||||
if ( $item['id'] === $notification['id'] ) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
$notification = $this->verify( array( $notification ) );
|
||||
|
||||
update_option(
|
||||
'sby_notifications',
|
||||
array(
|
||||
'update' => $option['update'],
|
||||
'feed' => $option['feed'],
|
||||
'events' => array_merge( $notification, $option['events'] ),
|
||||
'dismissed' => $option['dismissed'],
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update notification data from feed.
|
||||
*
|
||||
* @since 2.6/5.9
|
||||
*/
|
||||
public function update() {
|
||||
$feed = $this->fetch_feed();
|
||||
$option = $this->get_option();
|
||||
|
||||
update_option(
|
||||
'sby_notifications',
|
||||
array(
|
||||
'update' => sby_get_current_time(),
|
||||
'feed' => $feed,
|
||||
'events' => $option['events'],
|
||||
'dismissed' => $option['dismissed'],
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Admin area Form Overview enqueues.
|
||||
*
|
||||
* @since 2.6/5.9
|
||||
*/
|
||||
public function enqueues() {
|
||||
if ( ! $this->has_access() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$notifications = $this->get();
|
||||
|
||||
if ( empty( $notifications ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$min = '';
|
||||
|
||||
wp_enqueue_style(
|
||||
'sby-admin-notifications',
|
||||
SBY_PLUGIN_URL . "css/admin-notifications{$min}.css",
|
||||
array(),
|
||||
SBYVER
|
||||
);
|
||||
|
||||
wp_enqueue_script(
|
||||
'sby-admin-notifications',
|
||||
SBY_PLUGIN_URL . "js/admin-notifications{$min}.js",
|
||||
array( 'jquery' ),
|
||||
SBYVER,
|
||||
true
|
||||
);
|
||||
wp_localize_script( 'sby-admin-notifications', 'sby_admin', array(
|
||||
'ajax_url' => admin_url( 'admin-ajax.php' ),
|
||||
'nonce' => wp_create_nonce( 'sby-admin' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fields from the remote source contain placeholders to allow
|
||||
* some messages to be used for multiple plugins.
|
||||
*
|
||||
* @param $content string
|
||||
* @param $notification array
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @since 2.6/5.9
|
||||
*/
|
||||
public function replace_merge_fields( $content, $notification ) {
|
||||
$merge_fields = array(
|
||||
'{plugin}' => 'YouTube Feeds',
|
||||
'{amount}' => isset( $notification['amount'] ) ? $notification['amount'] : '',
|
||||
'{platform}' => 'YouTube',
|
||||
'{lowerplatform}' => 'youtube',
|
||||
'{review-url}' => 'https://wordpress.org/support/plugin/feeds-for-youtube/reviews/',
|
||||
'{slug}' => 'feeds-for-youtube',
|
||||
'{campaign}' => sby_utm_campaign()
|
||||
);
|
||||
|
||||
if ( sby_is_pro_version() ) {
|
||||
$merge_fields['{campaign}'] = 'youtube-pro';
|
||||
$merge_fields['{plugin}'] = 'YouTube Feeds Pro';
|
||||
}
|
||||
|
||||
foreach ( $merge_fields as $find => $replace ) {
|
||||
$content = str_replace( $find, $replace, $content );
|
||||
}
|
||||
|
||||
return $content;
|
||||
}
|
||||
|
||||
/**
|
||||
* Output notifications on YouTube Feeds admin area.
|
||||
*
|
||||
* @since 2.6/5.9
|
||||
*/
|
||||
public function output() {
|
||||
// if we are one single feed page then return
|
||||
if ( isset( $_GET['feed_id'] ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$notifications = $this->get();
|
||||
|
||||
if ( empty( $notifications ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$is_review_notice = ! empty( $notifications[0] ) && ! empty( $notifications[0]['id'] ) && $notifications[0]['id'] === 'review';
|
||||
|
||||
if ( ! $is_review_notice && ! empty( $_GET['feed_id'] ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$notifications_html = '';
|
||||
$current_class = ' current';
|
||||
$content_allowed_tags = array(
|
||||
'em' => array(),
|
||||
'strong' => array(),
|
||||
'span' => array(
|
||||
'style' => array(),
|
||||
),
|
||||
'a' => array(
|
||||
'href' => array(),
|
||||
'target' => array(),
|
||||
'rel' => array(),
|
||||
),
|
||||
);
|
||||
|
||||
foreach ( $notifications as $notification ) {
|
||||
$type = $notification['id'];
|
||||
// Buttons HTML.
|
||||
$buttons_html = '';
|
||||
if ( ! empty( $notification['btns'] ) && is_array( $notification['btns'] ) ) {
|
||||
foreach ( $notification['btns'] as $btn_type => $btn ) {
|
||||
if ( $type == 'review' || $type == 'discount' ) {
|
||||
$btn_class = $btn_type === 'primary' ? 'sby-btn-blue' : 'sby-btn-grey';
|
||||
} else {
|
||||
$btn_class = $btn_type === 'primary' ? 'sby-btn-orange' : 'sby-btn-grey';
|
||||
}
|
||||
if ( is_array( $btn['url'] ) ) {
|
||||
$args = array();
|
||||
foreach ( $btn['url'] as $key => $value ) {
|
||||
$args[ sanitize_key( $key ) ] = sanitize_key( $value );
|
||||
}
|
||||
$btn['url'] = add_query_arg( $args );
|
||||
}
|
||||
if ( ! empty( $btn['attr'] ) ) {
|
||||
$btn['target'] = '_blank';
|
||||
}
|
||||
if ( empty( $btn['class'] ) ) {
|
||||
$btn['class'] = '';
|
||||
}
|
||||
$buttons_html .= sprintf(
|
||||
'<a href="%1$s" class="sby-btn %2$s %3$s"%4$s>%5$s</a>',
|
||||
! empty( $btn['url'] ) ? esc_url( $this->replace_merge_fields( str_replace( 'sbi_', 'sby_', $btn['url'] ), $notification ) ) : '',
|
||||
esc_attr( $btn['class'] ),
|
||||
esc_attr( $btn_class ),
|
||||
! empty( $btn['target'] ) && $btn['target'] === '_blank' ? ' target="_blank" rel="noopener noreferrer"' : '',
|
||||
! empty( $btn['text'] ) ? sanitize_text_field( $btn['text'] ) : ''
|
||||
);
|
||||
}
|
||||
$buttons_html = ! empty( $buttons_html ) ? '<div class="buttons">' . $buttons_html . '</div>' : '';
|
||||
}
|
||||
|
||||
if ( empty( $notification['image'] ) ) {
|
||||
$image_html = '<div class="bell">';
|
||||
|
||||
$image_html .= '<svg xmlns="http://www.w3.org/2000/svg" width="42" height="48" viewBox="0 0 42 48"><defs><style>.a{fill:#777;}.b{fill:#ca4a1f;}</style></defs><path class="a" d="M23-79a6.005,6.005,0,0,1-6-6h10.06a12.066,12.066,0,0,0,1.791,1.308,6.021,6.021,0,0,1-2.077,3.352A6.008,6.008,0,0,1,23-79Zm1.605-9H5.009a2.955,2.955,0,0,1-2.173-.923A3.088,3.088,0,0,1,2-91a2.919,2.919,0,0,1,.807-2.036c.111-.12.229-.243.351-.371a14.936,14.936,0,0,0,3.126-4.409A23.283,23.283,0,0,0,8.007-107.5a14.846,14.846,0,0,1,.906-5.145,14.5,14.5,0,0,1,2.509-4.324A15.279,15.279,0,0,1,20-122.046V-124a3,3,0,0,1,3-3,3,3,0,0,1,3,3v1.954a15.28,15.28,0,0,1,8.58,5.078,14.5,14.5,0,0,1,2.509,4.324,14.846,14.846,0,0,1,.906,5.145c0,.645.016,1.281.047,1.888A12.036,12.036,0,0,0,35-106a11.921,11.921,0,0,0-8.485,3.515A11.923,11.923,0,0,0,23-94a12,12,0,0,0,1.6,6Z" transform="translate(-2 127)"/><circle class="b" cx="9" cy="9" r="9" transform="translate(24 24)"/></svg>';
|
||||
$image_html .= '</div>';
|
||||
} else {
|
||||
if ( $notification['image'] === 'balloon' ) {
|
||||
$image_html = sprintf(
|
||||
'<div class="bell"><img src="%s" alt="notice">',
|
||||
SBY_PLUGIN_URL . 'img/balloon.svg' );
|
||||
} else if ( $notification['id'] === 'review' || $notification['id'] === 'discount' ) {
|
||||
$image_html = sprintf(
|
||||
'<div class="bell"><img src="%s" alt="notice">',
|
||||
SBY_PLUGIN_URL . 'img/' . sanitize_text_field( str_replace( array( 'sbi', '.png' ), array( 'sby', '.svg' ), $notification['image'] ) )
|
||||
);
|
||||
} else {
|
||||
$image_html = '<div class="thumb">';
|
||||
$img_src = SBY_PLUGIN_URL . 'img/' . sanitize_text_field( $notification['image'] );
|
||||
$image_html .= '<img src="'.esc_url( $img_src ).'" alt="notice">';
|
||||
|
||||
if ( isset( $notification['image_overlay'] ) ) {
|
||||
$image_html .= '<div class="img-overlay">'. esc_html( str_replace( '%', '%%', $notification['image_overlay'] ) ).'</div>';
|
||||
}
|
||||
}
|
||||
$image_html .= '</div>';
|
||||
|
||||
}
|
||||
|
||||
// Check if it's review notice then show step #1
|
||||
if ( $type == 'review' ) {
|
||||
$step1_img = SBY_PLUGIN_URL . 'img/' . sanitize_text_field( str_replace( array( 'sbi', 'png' ), array( 'sby', 'svg' ), $notification['image'] ) );
|
||||
$step1_img_html = sprintf('<div class="bell"><img src="%s" alt="notice"></div>', $step1_img);
|
||||
|
||||
$review_consent = get_option( 'sby_review_consent' );
|
||||
$sby_open_feedback_url = 'https://smashballoon.com/feedback/?plugin=' . sby_utm_campaign();
|
||||
// step #1 for the review notice
|
||||
if ( ! $review_consent ) {
|
||||
$step1_btns = sprintf(
|
||||
'<button class="sby-btn-link" id="sby_review_consent_yes">%s</button>',
|
||||
__( 'Yes', 'feeds-for-youtube' )
|
||||
);
|
||||
$step1_btns .= sprintf(
|
||||
'<a href="%s" target="_blank" rel="nofollow noopener" class="sby-btn-link" id="sby_review_consent_no">%s</a>',
|
||||
$sby_open_feedback_url,
|
||||
__( 'No', 'feeds-for-youtube' )
|
||||
);
|
||||
$notifications_html .= sprintf(
|
||||
'<div class="sby_review_step1_notice" data-message-id="%3$s">' . $step1_img_html . '
|
||||
<h3 class="title">%1$s</h3>
|
||||
<div class="review-step-1-btns">%2$s</div>
|
||||
</div>',
|
||||
__( 'Are you enjoying the YouTube Feeds Plugin?', 'feeds-for-youtube' ),
|
||||
$step1_btns,
|
||||
! empty( $notification['id'] ) ? esc_attr( sanitize_text_field( $notification['id'] ) ) : 0
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$review_consent = get_option( 'sby_review_consent' );
|
||||
$review_step2_style = '';
|
||||
if ( $type == 'review' && ! $review_consent ) {
|
||||
$review_step2_style = 'style="display: none;"';
|
||||
}
|
||||
|
||||
// Build the notification HTML for review notice
|
||||
if ( $type == 'review' ) {
|
||||
$notifications_html .= sprintf(
|
||||
'<div class="message%5$s %7$s" data-message-id="%4$s" %6$s>' . $image_html . '
|
||||
<h3 class="title">%1$s</h3>
|
||||
<p class="content">%2$s</p>
|
||||
%3$s
|
||||
</div>',
|
||||
__( 'Glad to hear you are enjoying it. Would you consider leaving a positive review?', 'feeds-for-youtube' ),
|
||||
__( 'It really helps to support the plugin and help others to discover it too!', 'feeds-for-youtube' ),
|
||||
$buttons_html,
|
||||
! empty( $notification['id'] ) ? esc_attr( sanitize_text_field( $notification['id'] ) ) : 0,
|
||||
$current_class,
|
||||
( $notification['id'] == 'review' && ! empty( $review_step2_style ) ) ? $review_step2_style : '',
|
||||
( $type == 'review' ) ? 'rn_step_2' : ''
|
||||
);
|
||||
} else if ( $type == 'discount' ) {
|
||||
// Notification HTML for other notices
|
||||
$notifications_html .= sprintf(
|
||||
'<div class="message%5$s" data-message-id="%4$s" %6$s>' . $image_html . '
|
||||
<h3 class="title">%1$s</h3>
|
||||
<p class="content">%2$s</p>
|
||||
%3$s
|
||||
</div>',
|
||||
! empty( $notification['title'] ) ? $this->get_notice_title( $notification ) : '',
|
||||
! empty( $notification['content'] ) ? $this->get_notice_content( $notification, $content_allowed_tags ) : '',
|
||||
$buttons_html,
|
||||
! empty( $notification['id'] ) ? esc_attr( sanitize_text_field( $notification['id'] ) ) : 0,
|
||||
$current_class,
|
||||
( $notification['id'] == 'review' && ! empty( $review_step2_style ) ) ? $review_step2_style : ''
|
||||
);
|
||||
} else {
|
||||
// Notification HTML for other notices
|
||||
$notifications_html .= sprintf(
|
||||
'<div class="message%5$s" data-message-id="%4$s" %6$s>' . $image_html . '
|
||||
<h3 class="title">%1$s</h3>
|
||||
<p class="content">%2$s</p>
|
||||
%3$s
|
||||
</div>',
|
||||
! empty( $notification['title'] ) ? $this->replace_merge_fields( sanitize_text_field( $notification['title'] ), $notification ) : '',
|
||||
! empty( $notification['content'] ) ? wp_kses( $this->replace_merge_fields( $notification['content'], $notification ), $content_allowed_tags ) : '',
|
||||
$buttons_html,
|
||||
! empty( $notification['id'] ) ? esc_attr( sanitize_text_field( $notification['id'] ) ) : 0,
|
||||
$current_class,
|
||||
( $notification['id'] == 'review' && ! empty( $review_step2_style ) ) ? $review_step2_style : ''
|
||||
);
|
||||
}
|
||||
|
||||
// Only first notification is current.
|
||||
$current_class = '';
|
||||
}
|
||||
|
||||
$close_href = add_query_arg( array( 'sby_dismiss' => $type ) );
|
||||
$type_class = '';
|
||||
if ( $type === 'review' || $type == 'discount' ) {
|
||||
$type_class = $type === 'review' ? 'sby_review_notice' : 'sby_discount_notice';
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
<div id="sby-notifications" class="<?php echo esc_attr( $type_class ); ?>">
|
||||
<a
|
||||
class="dismiss"
|
||||
title="<?php echo esc_attr__( 'Dismiss this message', 'feeds-for-youtube' ); ?>"
|
||||
<?php echo ( $type == 'review' || $type == 'discount' ) ? 'href="'. esc_attr( $close_href ) .'"' : '' ?>
|
||||
>
|
||||
<svg width="10" height="10" viewBox="0 0 10 10" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<path d="M9.66683 1.27325L8.72683 0.333252L5.00016 4.05992L1.2735 0.333252L0.333496 1.27325L4.06016 4.99992L0.333496 8.72659L1.2735 9.66659L5.00016 5.93992L8.72683 9.66659L9.66683 8.72659L5.94016 4.99992L9.66683 1.27325Z" fill="white"/>
|
||||
</svg>
|
||||
</a>
|
||||
|
||||
<?php if ( count( $notifications ) > 1 ) : ?>
|
||||
<div class="navigation">
|
||||
<a class="prev disabled" title="<?php echo esc_attr__( 'Previous message', 'feeds-for-youtube' ); ?>"><svg aria-hidden="true" focusable="false" data-prefix="fas" data-icon="chevron-left" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 320 512" class="svg-inline--fa fa-chevron-left fa-w-10"><path fill="currentColor" d="M34.52 239.03L228.87 44.69c9.37-9.37 24.57-9.37 33.94 0l22.67 22.67c9.36 9.36 9.37 24.52.04 33.9L131.49 256l154.02 154.75c9.34 9.38 9.32 24.54-.04 33.9l-22.67 22.67c-9.37 9.37-24.57 9.37-33.94 0L34.52 272.97c-9.37-9.37-9.37-24.57 0-33.94z" class=""></path></svg></a>
|
||||
<a class="next disabled" title="<?php echo esc_attr__( 'Next message', 'feeds-for-youtube' ); ?>"><svg aria-hidden="true" focusable="false" data-prefix="fas" data-icon="chevron-right" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 320 512" class="svg-inline--fa fa-chevron-right fa-w-10"><path fill="currentColor" d="M285.476 272.971L91.132 467.314c-9.373 9.373-24.569 9.373-33.941 0l-22.667-22.667c-9.357-9.357-9.375-24.522-.04-33.901L188.505 256 34.484 101.255c-9.335-9.379-9.317-24.544.04-33.901l22.667-22.667c9.373-9.373 24.569-9.373 33.941 0L285.475 239.03c9.373 9.372 9.373 24.568.001 33.941z" class=""></path></svg></a>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<div class="messages">
|
||||
<?php echo $notifications_html; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* SBY Get Notice Title depending on the notice type
|
||||
*
|
||||
* @since 2.0
|
||||
*
|
||||
* @param array $notification
|
||||
*
|
||||
* @return string $title
|
||||
*/
|
||||
public function get_notice_title( $notification ) {
|
||||
$type = $notification['id'];
|
||||
$title = '';
|
||||
|
||||
// Notice title depending on notice type
|
||||
if ( $type == 'review' ) {
|
||||
$title = __( 'Glad to hear you are enjoying it. Would you consider leaving a positive review?', 'feeds-for-youtube' );
|
||||
} else if ( $type == 'discount' ) {
|
||||
$title = __( 'Exclusive Offer! 60% OFF', 'feeds-for-youtube' );
|
||||
} else {
|
||||
$title = $this->replace_merge_fields( $notification['title'], $notification );
|
||||
}
|
||||
|
||||
return $title;
|
||||
}
|
||||
|
||||
/**
|
||||
* SBY Get Notice Content depending on the notice type
|
||||
*
|
||||
* @since 2.0
|
||||
*
|
||||
* @param array $notification
|
||||
* @param array $content_allowed_tags
|
||||
*
|
||||
* @return string $content
|
||||
*/
|
||||
public function get_notice_content( $notification, $content_allowed_tags ) {
|
||||
$type = $notification['id'];
|
||||
$content = '';
|
||||
|
||||
// Notice content depending on notice type
|
||||
if ( $type == 'review' ) {
|
||||
$content = __( 'It really helps to support the plugin and help others to discover it too!', 'feeds-for-youtube' );
|
||||
} else if ( $type == 'discount' ) {
|
||||
$content = __( 'We don’t run promotions very often, but for a limited time we’re offering 60% Off our Pro version to all users of our free YouTube Feeds.', 'feeds-for-youtube' );
|
||||
} else {
|
||||
if ( ! empty( $notification['content'] ) ) {
|
||||
$content = wp_kses( $this->replace_merge_fields( $notification['content'], $notification ), $content_allowed_tags );
|
||||
}
|
||||
}
|
||||
return $content;
|
||||
}
|
||||
|
||||
/**
|
||||
* Dismiss notification via AJAX. If it's a new user message, also dismiss it
|
||||
* on all admin pages.
|
||||
*
|
||||
* @since 2.6/5.9
|
||||
*/
|
||||
public function dismiss() {
|
||||
// Run a security check.
|
||||
check_ajax_referer( 'sby-admin', 'nonce' );
|
||||
|
||||
// Check for access and required param.
|
||||
if ( ! $this->has_access() || empty( $_POST['id'] ) ) {
|
||||
wp_send_json_error();
|
||||
}
|
||||
|
||||
$id = sanitize_text_field( wp_unslash( $_POST['id'] ) );
|
||||
|
||||
if ( $id === 'review' ) {
|
||||
$sby_statuses_option = get_option( 'sby_statuses', array() );
|
||||
|
||||
update_option( 'sby_rating_notice', 'dismissed', false );
|
||||
$sby_statuses_option['rating_notice_dismissed'] = sby_get_current_time();
|
||||
update_option( 'sby_statuses', $sby_statuses_option, false );
|
||||
} elseif ( $id === 'discount' ) {
|
||||
update_user_meta( get_current_user_id(), 'sby_ignore_new_user_sale_notice', 'always' );
|
||||
|
||||
$current_month_number = (int)date('n', sby_get_current_time() );
|
||||
$not_early_in_the_year = ($current_month_number > 5);
|
||||
|
||||
if ( $not_early_in_the_year ) {
|
||||
update_user_meta( get_current_user_id(), 'sby_ignore_bfcm_sale_notice', date( 'Y', sby_get_current_time() ) );
|
||||
}
|
||||
}
|
||||
|
||||
$option = $this->get_option();
|
||||
$type = is_numeric( $id ) ? 'feed' : 'events';
|
||||
|
||||
$option['dismissed'][] = $id;
|
||||
$option['dismissed'] = array_unique( $option['dismissed'] );
|
||||
|
||||
// Remove notification.
|
||||
if ( is_array( $option[ $type ] ) && ! empty( $option[ $type ] ) ) {
|
||||
foreach ( $option[ $type ] as $key => $notification ) {
|
||||
if ( $notification['id'] == $id ) { // phpcs:ignore WordPress.PHP.StrictComparisons
|
||||
unset( $option[ $type ][ $key ] );
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
update_option( 'sby_notifications', $option );
|
||||
|
||||
wp_send_json_success();
|
||||
}
|
||||
|
||||
public function output_return() {
|
||||
ob_start();
|
||||
$this->output();
|
||||
return ob_get_clean();
|
||||
}
|
||||
}
|
||||
371
wp-content/plugins/youtube-feed-pro/inc/Admin/SBY_Tracking.php
Normal file
371
wp-content/plugins/youtube-feed-pro/inc/Admin/SBY_Tracking.php
Normal file
@@ -0,0 +1,371 @@
|
||||
<?php
|
||||
/**
|
||||
* Tracking functions for reporting plugin usage to the Smash Balloon site for users that have opted in
|
||||
*
|
||||
* @copyright Copyright (c) 2018, Chris Christoff
|
||||
* @since
|
||||
*/
|
||||
|
||||
namespace SmashBalloon\YouTubeFeed\Admin;
|
||||
|
||||
use Smashballoon\Customizer\DB;
|
||||
use Smashballoon\Framework\Utilities\UsageTracking;
|
||||
use SmashBalloon\YouTubeFeed\Builder\SBY_Db;
|
||||
use SmashBalloon\YouTubeFeed\Builder\SBY_Feed_Saver;
|
||||
|
||||
/**
|
||||
* Usage tracking
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*@since 5.6
|
||||
*/
|
||||
class SBY_Tracking {
|
||||
|
||||
protected $DB;
|
||||
|
||||
public function __construct( DB $DB) {
|
||||
add_action( 'init', array( $this, 'schedule_send' ) );
|
||||
add_filter( 'cron_schedules', array( $this, 'add_schedules' ) );
|
||||
add_filter( 'sb_usage_tracking_data', [ $this, 'filter_usage_tracking_data' ], 10, 2 );
|
||||
add_action( 'sby_usage_tracking_cron', array( $this, 'send_checkin' ) );
|
||||
|
||||
$this->DB = $DB;
|
||||
}
|
||||
|
||||
private function normalize_and_format( $key, $value ) {
|
||||
$normal_bools = array(
|
||||
'widthresp',
|
||||
'disablemobile',
|
||||
'showheader',
|
||||
'showdescription',
|
||||
'headerchannel',
|
||||
'customsearch',
|
||||
'showbutton',
|
||||
'headeroutside',
|
||||
'showsubscribe',
|
||||
'backup_cache_enabled',
|
||||
'disable_resize',
|
||||
'favor_local',
|
||||
'disable_js_image_loading',
|
||||
'ajax_post_load',
|
||||
'ajaxtheme',
|
||||
'enqueue_css_in_shortcode',
|
||||
'customtemplates',
|
||||
'eagerload',
|
||||
|
||||
// pro only
|
||||
'usecustomsearch',
|
||||
'showlikes',
|
||||
'carouselarrows',
|
||||
'carouselpag',
|
||||
'carouselautoplay',
|
||||
'userelative',
|
||||
'showsubscribers',
|
||||
);
|
||||
$custom_text_settings = array(
|
||||
'class',
|
||||
'buttontext',
|
||||
'subscribetext',
|
||||
'customheadertext',
|
||||
|
||||
// pro only
|
||||
'customdate',
|
||||
'subscriberstext',
|
||||
'viewstext',
|
||||
'agotext',
|
||||
'beforedatetext',
|
||||
'beforestreamtimetext',
|
||||
'minutetext',
|
||||
'minutestext',
|
||||
'hourstext',
|
||||
'thousandstext',
|
||||
'millionstext',
|
||||
'watchnowtext',
|
||||
'linktext',
|
||||
'linkurl',
|
||||
'custom_css',
|
||||
'custom_js'
|
||||
);
|
||||
$comma_separate_counts_settings = array(
|
||||
'channel',
|
||||
'playlist',
|
||||
'favorites',
|
||||
'search',
|
||||
'live',
|
||||
'single',
|
||||
'includewords',
|
||||
'excludewords',
|
||||
'includewords',
|
||||
'hidevideos',
|
||||
);
|
||||
$defaults = sby_settings_defaults();
|
||||
|
||||
if ( is_array( $value ) ) {
|
||||
if ( empty( $value ) ) {
|
||||
return 0;
|
||||
}
|
||||
return count( $value );
|
||||
// 0 for anything that might be false, 1 for everything else
|
||||
} elseif ( in_array( $key, $normal_bools, true ) ) {
|
||||
if ( in_array( $value, array( false, 0, '0', 'false', '' ), true ) ) {
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
|
||||
// if a custom text setting, we just want to know if it's different than the default
|
||||
} elseif ( in_array( $key, $custom_text_settings, true ) ) {
|
||||
if ( $defaults[ $key ] === $value ) {
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
} elseif ( in_array( $key, $comma_separate_counts_settings, true ) ) {
|
||||
if ( str_replace( ' ', '', $value ) === '' ) {
|
||||
return 0;
|
||||
}
|
||||
$split_at_comma = explode( ',', $value );
|
||||
return count( $split_at_comma );
|
||||
}
|
||||
|
||||
return $value;
|
||||
|
||||
}
|
||||
|
||||
private function get_data() {
|
||||
$data = array();
|
||||
|
||||
// Retrieve current theme info
|
||||
$theme_data = wp_get_theme();
|
||||
|
||||
$count_b = 1;
|
||||
if ( is_multisite() ) {
|
||||
if ( function_exists( 'get_blog_count' ) ) {
|
||||
$count_b = get_blog_count();
|
||||
} else {
|
||||
$count_b = 'Not Set';
|
||||
}
|
||||
}
|
||||
|
||||
$php_version = rtrim( ltrim( sanitize_text_field( phpversion() ) ) );
|
||||
$php_version = ! empty( $php_version ) ? substr( $php_version, 0, strpos( $php_version, '.', strpos( $php_version, '.' ) + 1 ) ) : phpversion();
|
||||
|
||||
global $wp_version;
|
||||
$data['this_plugin'] = 'yt';
|
||||
$data['php_version'] = $php_version;
|
||||
$data['mi_version'] = SBYVER;
|
||||
$data['wp_version'] = $wp_version;
|
||||
$data['server'] = isset( $_SERVER['SERVER_SOFTWARE'] ) ? $_SERVER['SERVER_SOFTWARE'] : '';
|
||||
$data['multisite'] = is_multisite();
|
||||
$data['url'] = 'f'.home_url();
|
||||
$data['themename'] = $theme_data->Name;
|
||||
$data['themeversion'] = $theme_data->Version;
|
||||
$data['settings'] = array();
|
||||
$data['pro'] = sby_is_pro_version() ? '1' : '';
|
||||
$data['sites'] = $count_b;
|
||||
$data['usagetracking'] = get_option( 'sby_usage_tracking_config', false );
|
||||
$num_users = function_exists( 'count_users' ) ? count_users() : 'Not Set';
|
||||
$data['usercount'] = is_array( $num_users ) ? $num_users['total_users'] : 1;
|
||||
$data['timezoneoffset']= date('P');
|
||||
|
||||
$settings_to_send = array();
|
||||
$raw_settings = get_option( 'sby_settings', array() );
|
||||
|
||||
foreach ( $raw_settings as $key => $value ) {
|
||||
$combine_arrays = array(
|
||||
'include',
|
||||
'hoverinclude',
|
||||
);
|
||||
|
||||
if ( $key === 'api_key' ) {
|
||||
// do not sent
|
||||
} elseif ( $key === 'connected_accounts' ) {
|
||||
if ( is_array( $raw_settings['connected_accounts'] ) ) {
|
||||
$settings_to_send['connected_accounts'] = count( $raw_settings['connected_accounts'] );
|
||||
} else {
|
||||
$settings_to_send['connected_accounts'] = 0;
|
||||
}
|
||||
} elseif ( in_array( $key, $combine_arrays, true ) && is_array( $value ) ) {
|
||||
foreach ( $value as $item ) {
|
||||
$settings_to_send[ $key . '_' . $item ] = 1;
|
||||
}
|
||||
} else {
|
||||
$value = $this->normalize_and_format( $key, $value );
|
||||
if ( $value !== false ) {
|
||||
$settings_to_send[ $key ] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$feed_settings = array();
|
||||
$settings_to_send = array_merge( $settings_to_send, $feed_settings );
|
||||
|
||||
global $wpdb;
|
||||
$feed_caches = array();
|
||||
|
||||
$results = $wpdb->get_results( "
|
||||
SELECT option_name
|
||||
FROM $wpdb->options
|
||||
WHERE `option_name` LIKE ('%\_transient\_sby\_%')
|
||||
AND `option_name` NOT LIKE ('%\_transient\_sby\_header%');", ARRAY_A );
|
||||
|
||||
if ( isset( $results[0] ) ) {
|
||||
$feed_caches = $results;
|
||||
}
|
||||
$settings_to_send['num_found_feed_caches'] = count( $feed_caches );
|
||||
|
||||
$settings_to_send['custom_header_template'] = '' !== locate_template( 'sby/header.php', false, false ) ? 1 : 0;
|
||||
$settings_to_send['custom_player_template'] = '' !== locate_template( 'sby/player.php', false, false ) ? 1 : 0;
|
||||
$settings_to_send['custom_info_template'] = '' !== locate_template( 'sby/info.php', false, false ) ? 1 : 0;
|
||||
$settings_to_send['custom_cta_template'] = '' !== locate_template( 'sby/cta.php', false, false ) ? 1 : 0;
|
||||
$settings_to_send['custom_header_generic_template'] = '' !== locate_template( 'sby/header-generic.php', false, false ) ? 1 : 0;
|
||||
$settings_to_send['custom_item_template'] = '' !== locate_template( 'sby/item.php', false, false ) ? 1 : 0;
|
||||
$settings_to_send['custom_footer_template'] = '' !== locate_template( 'sby/footer.php', false, false ) ? 1 : 0;
|
||||
$settings_to_send['custom_feed_template'] = '' !== locate_template( 'sby/feed.php', false, false ) ? 1 : 0;
|
||||
|
||||
// Retrieve current plugin information
|
||||
if( ! function_exists( 'get_plugins' ) ) {
|
||||
include ABSPATH . '/wp-admin/includes/plugin.php';
|
||||
}
|
||||
|
||||
$plugins = get_plugins();
|
||||
$active_plugins = get_option( 'active_plugins', array() );
|
||||
$plugins_to_send = array();
|
||||
|
||||
foreach ( $plugins as $plugin_path => $plugin ) {
|
||||
// If the plugin isn't active, don't show it.
|
||||
if ( ! in_array( $plugin_path, $active_plugins ) )
|
||||
continue;
|
||||
|
||||
$plugins_to_send[] = $plugin['Name'];
|
||||
}
|
||||
|
||||
$data['active_plugins'] = $plugins_to_send;
|
||||
$data['locale'] = get_locale();
|
||||
if ( isset( $data['settings']['api_key'] ) ) {
|
||||
unset( $data['settings']['api_key'] );
|
||||
}
|
||||
if ( isset( $data['settings']['access_token'] ) ) {
|
||||
unset( $data['settings']['access_token'] );
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function send_checkin( $override = false, $ignore_last_checkin = false ) {
|
||||
|
||||
$home_url = trailingslashit( home_url() );
|
||||
|
||||
if ( strpos( $home_url, 'smashballoon.com' ) !== false ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if( ! $this->tracking_allowed() && ! $override ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return UsageTracking::send_usage_update($this->get_data(), 'sby');
|
||||
}
|
||||
|
||||
private function tracking_allowed() {
|
||||
$usage_tracking = get_option( 'sby_usage_tracking', array( 'last_send' => 0, 'enabled' => sby_is_pro_version() ) );
|
||||
$tracking_allowed = isset( $usage_tracking['enabled'] ) ? $usage_tracking['enabled'] : sby_is_pro_version();
|
||||
|
||||
return $tracking_allowed;
|
||||
}
|
||||
|
||||
public function schedule_send() {
|
||||
if ( ! wp_next_scheduled( 'sby_usage_tracking_cron' ) ) {
|
||||
$tracking = array();
|
||||
$tracking['day'] = rand( 0, 6 );
|
||||
$tracking['hour'] = rand( 0, 23 );
|
||||
$tracking['minute'] = rand( 0, 59 );
|
||||
$tracking['second'] = rand( 0, 59 );
|
||||
$tracking['offset'] = ( $tracking['day'] * DAY_IN_SECONDS ) +
|
||||
( $tracking['hour'] * HOUR_IN_SECONDS ) +
|
||||
( $tracking['minute'] * MINUTE_IN_SECONDS ) +
|
||||
$tracking['second'];
|
||||
$last_sunday = strtotime("next sunday") - (7 * DAY_IN_SECONDS);
|
||||
if ( ($last_sunday + $tracking['offset']) > time() + 6 * HOUR_IN_SECONDS ) {
|
||||
$tracking['initsend'] = $last_sunday + $tracking['offset'];
|
||||
} else {
|
||||
$tracking['initsend'] = strtotime("next sunday") + $tracking['offset'];
|
||||
}
|
||||
|
||||
wp_schedule_event( $tracking['initsend'], 'weekly', 'sby_usage_tracking_cron' );
|
||||
update_option( 'sby_usage_tracking_config', $tracking );
|
||||
}
|
||||
}
|
||||
|
||||
public function add_schedules( $schedules = array() ) {
|
||||
// Adds once weekly to the existing schedules.
|
||||
$schedules['weekly'] = array(
|
||||
'interval' => 604800,
|
||||
'display' => __( 'Once Weekly', 'feeds-for-youtube' )
|
||||
);
|
||||
return $schedules;
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter the usage tracking data
|
||||
*
|
||||
* @param array $data
|
||||
* @param string $plugin_slug
|
||||
*
|
||||
* @handles sb_usage_tracking_data
|
||||
*
|
||||
* @return array|mixed
|
||||
*/
|
||||
public function filter_usage_tracking_data( $data, $plugin_slug ) {
|
||||
if ( 'sby' !== $plugin_slug ) {
|
||||
return $data;
|
||||
}
|
||||
|
||||
if ( ! is_array( $data ) ) {
|
||||
return $data;
|
||||
}
|
||||
|
||||
if ( ! isset( $data['settings'] ) ) {
|
||||
$data['settings'] = [];
|
||||
}
|
||||
|
||||
$tracked_boolean_settings = explode( ',',
|
||||
'widthresp,class,height,heightunit,disablemobile,itemspacing,itemspacingunit,
|
||||
background,headercolor,subscribecolor,subscribetextcolor,buttoncolor,buttontextcolor,
|
||||
showheader,showdescription,showbutton,headersize,headeroutside,showsubscribe,buttontext,
|
||||
subscribetext,backup_cache_enabled,resizeprocess,disable_resize,storage_process,
|
||||
favor_local,disable_js_image_loading,ajax_post_load,ajaxtheme,enqueue_css_in_shortcode,
|
||||
customtemplates,gallerycols,gallerycolsmobile,gridcols,gridcolsmobile,eagerload,custom_css,
|
||||
custom_js,disablecdn,allowcookies,usecustomsearch,headerchannel,customsearch,showpast,showlikes,
|
||||
carouselarrows,carouselpag,carouselautoplay,include,hoverinclude,descriptionlength,userelative,
|
||||
dateformat,customdate,showsubscribers,descriptiontextsize,subscriberstext,viewstext,agotext,
|
||||
beforedatetext,beforestreamtimetext,minutetext,minutestext,hourstext,thousandstext,millionstext,
|
||||
watchnowtext,cta,linktext,linkurl,linkopentype,linkcolor,linktextcolor'
|
||||
);
|
||||
$tracked_string_settings = explode( ',',
|
||||
'type,num,nummobile,layout,playvideo,sortby,cache_time,cache_time_unit,playerratio,gdpr,carouselcols,carouselcolsmobile,infoposition'
|
||||
);
|
||||
|
||||
$feeds = SBY_Db::feeds_query();
|
||||
$settings_defaults = SBY_Feed_Saver::settings_defaults();
|
||||
|
||||
// Track settings of the first feed
|
||||
if ( ! empty( $feeds ) ) {
|
||||
$feed = $feeds[0];
|
||||
$feed_settings = ( new SBY_Feed_Saver( $feed['id'] ) )->get_feed_settings();
|
||||
|
||||
if(!is_array($feed_settings)) {
|
||||
return $data;
|
||||
}
|
||||
|
||||
$booleans = UsageTracking::tracked_settings_to_booleans($tracked_boolean_settings, $settings_defaults, $feed_settings);
|
||||
$strings = UsageTracking::tracked_settings_to_strings($tracked_string_settings, $feed_settings);
|
||||
|
||||
if ( is_array( $booleans ) && is_array( $strings ) ) {
|
||||
$data['settings'] = array_merge( $data['settings'], $booleans, $strings );
|
||||
}
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
396
wp-content/plugins/youtube-feed-pro/inc/Admin/SBY_Upgrader.php
Normal file
396
wp-content/plugins/youtube-feed-pro/inc/Admin/SBY_Upgrader.php
Normal file
@@ -0,0 +1,396 @@
|
||||
<?php
|
||||
/**
|
||||
* Upgrade to the Pro version
|
||||
*
|
||||
* @since 4.0
|
||||
*/
|
||||
|
||||
namespace SmashBalloon\YouTubeFeed\Admin;
|
||||
|
||||
|
||||
class SBY_Upgrader {
|
||||
|
||||
/**
|
||||
* URL where licensing is done
|
||||
*/
|
||||
const STORE_URL = 'https://smashballoon.com/';
|
||||
|
||||
/**
|
||||
* URL to connect to Smash Balloon App and upgrade to Pro
|
||||
*/
|
||||
const UPGRADE_URL = 'https://connect.smashballoon.com/activate/index.php';
|
||||
|
||||
/**
|
||||
* Check the license key URL
|
||||
*/
|
||||
const CHECK_URL = 'https://connect.smashballoon.com/activate/check.php';
|
||||
|
||||
const NAME = 'youtube';
|
||||
|
||||
const SLUG = 'youtube-feed-pro/youtube-feed-pro.php';
|
||||
|
||||
const REDIRECT = 'youtube-feed-settings';
|
||||
|
||||
const INSTALL_INSTRUCTIONS = 'https://smashballoon.com/doc/setting-up-the-feeds-for-youtube-pro-wordpress-plugin/?youtube&utm_campaign=youtube-free&utm_source=settings&utm_medium=freetopro&utm_content=Upgrade Manually';
|
||||
|
||||
|
||||
/**
|
||||
* AJAX hooks for creating the redirect
|
||||
*
|
||||
* @since 4.0
|
||||
*/
|
||||
public function hooks() {
|
||||
add_action( 'wp_ajax_nopriv_sby_run_one_click_upgrade', array( 'SmashBalloon\YouTubeFeed\Admin\SBY_Upgrader', 'install_upgrade' ) );
|
||||
add_action( 'wp_ajax_sby_maybe_upgrade_redirect', array( 'SmashBalloon\YouTubeFeed\Admin\SBY_Upgrader', 'maybe_upgrade_redirect' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Connect to licensing API to get download URL for Pro version
|
||||
*
|
||||
* @param $license_data
|
||||
*
|
||||
* @return bool|mixed|null
|
||||
*
|
||||
* @since 4.0
|
||||
*/
|
||||
public static function get_version_info( $license_data, $license_key ) {
|
||||
$api_params = array(
|
||||
'edd_action' => 'get_version',
|
||||
'license' => $license_key,
|
||||
'item_name' => isset( $license_data['item_name'] ) ? $license_data['item_name'] : false,
|
||||
'item_id' => isset( $license_data['item_id'] ) ? $license_data['item_id'] : false,
|
||||
'version' => '0',
|
||||
'slug' => self::SLUG,
|
||||
'author' => 'SmashBalloon',
|
||||
'url' => home_url(),
|
||||
'beta' => false,
|
||||
'nocache' => '1'
|
||||
);
|
||||
|
||||
$api_url = trailingslashit( self::STORE_URL );
|
||||
|
||||
$request = wp_remote_post(
|
||||
$api_url,
|
||||
array(
|
||||
'timeout' => 15,
|
||||
'sslverify' => true,
|
||||
'body' => $api_params,
|
||||
)
|
||||
);
|
||||
|
||||
if ( ! is_wp_error( $request ) ) {
|
||||
$version_info = json_decode( wp_remote_retrieve_body( $request ) );
|
||||
return $version_info;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ajax handler for grabbing the upgrade url.
|
||||
*
|
||||
* @since 4.0
|
||||
*/
|
||||
public static function maybe_upgrade_redirect() {
|
||||
$home_url = home_url();
|
||||
check_ajax_referer( 'sby-admin', 'nonce' );
|
||||
if ( ! sby_current_user_can( 'manage_youtube_feed_options' ) ) {
|
||||
wp_send_json_error();
|
||||
}
|
||||
|
||||
// Check for permissions.
|
||||
if ( ! current_user_can( 'install_plugins' ) ) {
|
||||
wp_send_json_error( array( 'message' => esc_html__( 'You are not allowed to install plugins.', 'feeds-for-youtube' ) ) );
|
||||
}
|
||||
if ( self::is_dev_url( home_url() ) ) {
|
||||
wp_send_json_success(
|
||||
array(
|
||||
'url' => self::INSTALL_INSTRUCTIONS,
|
||||
)
|
||||
);
|
||||
}
|
||||
// Check license key.
|
||||
$license = ! empty( $_POST['license_key'] ) ? sanitize_key( $_POST['license_key'] ) : '';
|
||||
if ( empty( $license ) ) {
|
||||
wp_send_json_error( array( 'message' => esc_html__( 'You are not licensed.', 'feeds-for-youtube' ) ) );
|
||||
}
|
||||
|
||||
$args = array(
|
||||
'edd_action' => 'check_license',
|
||||
'license' => $license,
|
||||
'item_name' => urlencode( SBY_PLUGIN_EDD_NAME ), // the name of our product in EDD
|
||||
);
|
||||
$url = add_query_arg( $args, SBY_STORE_URL );
|
||||
|
||||
$remote_request_args = array(
|
||||
'timeout' => '20',
|
||||
'headers' => array(
|
||||
'referer' => home_url(),
|
||||
)
|
||||
);
|
||||
|
||||
$response = wp_remote_get( $url, $remote_request_args );
|
||||
|
||||
if ( ! is_wp_error( $response ) ) {
|
||||
$body = wp_remote_retrieve_body( $response );
|
||||
|
||||
$license_data = json_decode( $body, true );
|
||||
|
||||
if ( empty( $license_data ) ) {
|
||||
wp_send_json_error(
|
||||
array(
|
||||
'message' => esc_html( self::get_error_message( $license_data ) ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if ( isset( $license_data['error'] ) && ! empty( $license_data['error'] ) ) {
|
||||
wp_send_json_error(
|
||||
array(
|
||||
'message' => self::get_error_message( $license_data ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if ( $license_data['license'] !== 'valid' ) {
|
||||
wp_send_json_error(
|
||||
array(
|
||||
'message' => self::get_error_message( $license_data ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
update_option( 'sby_license_key', $license );
|
||||
update_option( 'sby_license_data', $license_data );
|
||||
update_option( 'sby_license_status', $license_data['license'] );
|
||||
|
||||
// Redirect.
|
||||
$oth = hash( 'sha512', wp_rand() );
|
||||
$hashed_oth = hash_hmac( 'sha512', $oth, wp_salt() );
|
||||
|
||||
update_option( 'sby_one_click_upgrade', $oth );
|
||||
$version = '1.0';
|
||||
$version_info = self::get_version_info( $license_data, $license );
|
||||
$file = '';
|
||||
if ( isset( $version_info->package ) ) {
|
||||
$file = $version_info->package;
|
||||
}
|
||||
$siteurl = admin_url();
|
||||
$endpoint = admin_url( 'admin-ajax.php' );
|
||||
$redirect = admin_url( 'admin.php?page=' . self::REDIRECT );
|
||||
$url = add_query_arg(
|
||||
array(
|
||||
'key' => $license,
|
||||
'oth' => $hashed_oth,
|
||||
'endpoint' => $endpoint,
|
||||
'version' => $version,
|
||||
'siteurl' => $siteurl,
|
||||
'homeurl' => $home_url,
|
||||
'redirect' => rawurldecode( base64_encode( $redirect ) ),
|
||||
'file' => rawurldecode( base64_encode( $file ) ),
|
||||
'plugin_name' => self::NAME,
|
||||
),
|
||||
self::UPGRADE_URL
|
||||
);
|
||||
wp_send_json_success(
|
||||
array(
|
||||
'url' => $url,
|
||||
)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
wp_send_json_error( array( 'message' => esc_html__( 'Could not connect.', 'feeds-for-youtube' ) ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Endpoint for one-click upgrade.
|
||||
*
|
||||
* @since 4.0
|
||||
*/
|
||||
public function install_upgrade() {
|
||||
$error = esc_html__( 'Could not install upgrade. Please download from smashballoon.com and install manually.', 'feeds-for-youtube' );
|
||||
// verify params present (oth & download link).
|
||||
$post_oth = ! empty( $_REQUEST['oth'] ) ? sanitize_text_field( $_REQUEST['oth'] ) : '';
|
||||
$post_url = ! empty( $_REQUEST['file'] ) ? $_REQUEST['file'] : '';
|
||||
|
||||
if ( empty( $post_oth ) || empty( $post_url ) ) {
|
||||
wp_send_json_error( $error );
|
||||
}
|
||||
// Verify oth.
|
||||
$oth = get_option( 'sby_one_click_upgrade' );
|
||||
|
||||
if ( empty( $oth ) ) {
|
||||
wp_send_json_error( $error );
|
||||
}
|
||||
|
||||
if ( hash_hmac( 'sha512', $oth, wp_salt() ) !== $post_oth ) {
|
||||
wp_send_json_error( $error );
|
||||
}
|
||||
|
||||
// Delete so cannot replay.
|
||||
delete_option( 'sby_one_click_upgrade' );
|
||||
// Set the current screen to avoid undefined notices.
|
||||
set_current_screen( self::REDIRECT );
|
||||
// Prepare variables.
|
||||
$url = esc_url_raw(
|
||||
add_query_arg(
|
||||
array(
|
||||
'page' => self::REDIRECT,
|
||||
),
|
||||
admin_url( 'admin.php' )
|
||||
)
|
||||
);
|
||||
|
||||
// Verify pro not installed.
|
||||
$active = activate_plugin( self::SLUG, $url, false, true );
|
||||
if ( ! is_wp_error( $active ) ) {
|
||||
deactivate_plugins( plugin_basename( SBY_PLUGIN_DIR ) );
|
||||
wp_send_json_success( esc_html__( 'Plugin installed & activated.', 'feeds-for-youtube' ) );
|
||||
}
|
||||
|
||||
$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.
|
||||
$license = get_option( 'sby_license_key' );
|
||||
if ( empty( $license ) ) {
|
||||
wp_send_json_error( new \WP_Error( '403', esc_html__( 'You are not licensed.', 'feeds-for-youtube' ) ) );
|
||||
}
|
||||
|
||||
// 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.
|
||||
require_once trailingslashit( SBY_PLUGIN_DIR ) . 'inc/Admin/PluginSilentUpgrader.php';
|
||||
require_once trailingslashit( SBY_PLUGIN_DIR ) . 'inc/Admin/PluginSilentUpgraderSkin.php';
|
||||
require_once trailingslashit( SBY_PLUGIN_DIR ) . 'inc/Admin/class-install-skin.php';
|
||||
$installer = new \SBY\Helpers\PluginSilentUpgrader( new \SBY_Install_Skin() );
|
||||
|
||||
// Error check.
|
||||
if ( ! method_exists( $installer, 'install' ) || empty( $post_url ) ) {
|
||||
wp_send_json_error( $error );
|
||||
}
|
||||
|
||||
$license_data = get_option( 'sby_license_data' );
|
||||
|
||||
if ( ! empty( $license_data ) ) {
|
||||
$version_info = self::get_version_info( $license_data );
|
||||
|
||||
$file = '';
|
||||
if ( isset( $version_info->package ) ) {
|
||||
$file = $version_info->package;
|
||||
}
|
||||
} else {
|
||||
wp_send_json_error( new \WP_Error( '403', esc_html__( 'You are not licensed.', 'feeds-for-youtube' ) ) );
|
||||
}
|
||||
|
||||
if ( ! empty( $file ) ) {
|
||||
|
||||
$installer->install( $file ); // phpcs:ignore
|
||||
// Check license key.
|
||||
// Flush the cache and return the newly installed plugin basename.
|
||||
wp_cache_flush();
|
||||
|
||||
$plugin_basename = $installer->plugin_info();
|
||||
|
||||
if ( $plugin_basename ) {
|
||||
deactivate_plugins( plugin_basename( SBY_PLUGIN_BASENAME ), true );
|
||||
|
||||
// Activate the plugin silently.
|
||||
$activated = activate_plugin( $plugin_basename );
|
||||
|
||||
if ( ! is_wp_error( $activated ) ) {
|
||||
wp_send_json_success( esc_html__( 'Plugin installed & activated.', 'feeds-for-youtube' ) );
|
||||
} else {
|
||||
// Reactivate the lite plugin if pro activation failed.
|
||||
$activated = activate_plugin( plugin_basename( SBY_PLUGIN_BASENAME ), '', false, true );
|
||||
wp_send_json_error( esc_html__( 'Pro version installed but needs to be activated from the Plugins page inside your WordPress admin.', 'feeds-for-youtube' ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
wp_send_json_error( $error );
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether or not it's likely to be a reachable URL for upgrade
|
||||
*
|
||||
* @param string $url
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @since 4.0
|
||||
*/
|
||||
public static function is_dev_url( $url = '' ) {
|
||||
$is_local_url = false;
|
||||
// Trim it up
|
||||
$url = strtolower( trim( $url ) );
|
||||
// Need to get the host...so let's add the scheme so we can use parse_url
|
||||
if ( false === strpos( $url, 'http://' ) && false === strpos( $url, 'https://' ) ) {
|
||||
$url = 'http://' . $url;
|
||||
}
|
||||
$url_parts = parse_url( $url );
|
||||
$host = ! empty( $url_parts['host'] ) ? $url_parts['host'] : false;
|
||||
if ( ! empty( $url ) && ! empty( $host ) ) {
|
||||
if ( false !== ip2long( $host ) ) {
|
||||
if ( ! filter_var( $host, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE ) ) {
|
||||
$is_local_url = true;
|
||||
}
|
||||
} elseif ( 'localhost' === $host ) {
|
||||
$is_local_url = true;
|
||||
}
|
||||
|
||||
$tlds_to_check = array( '.local', ':8888', ':8080', ':8081', '.invalid', '.example', '.test' );
|
||||
foreach ( $tlds_to_check as $tld ) {
|
||||
if ( false !== strpos( $host, $tld ) ) {
|
||||
$is_local_url = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ( substr_count( $host, '.' ) > 1 ) {
|
||||
$subdomains_to_check = array();
|
||||
foreach ( $subdomains_to_check as $subdomain ) {
|
||||
$subdomain = str_replace( '.', '(.)', $subdomain );
|
||||
$subdomain = str_replace( array( '*', '(.)' ), '(.*)', $subdomain );
|
||||
if ( preg_match( '/^(' . $subdomain . ')/', $host ) ) {
|
||||
$is_local_url = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return $is_local_url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle API Response and check for an error.
|
||||
*
|
||||
* @param array $response
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @since 4.0
|
||||
*/
|
||||
public static function get_error_message( $response ) {
|
||||
$message = '';
|
||||
if ( isset( $response['error'] ) ) {
|
||||
$error = sanitize_text_field( $response['error'] );
|
||||
switch ( $error ) {
|
||||
case 'expired':
|
||||
$message = __( 'This license is expired.', 'feeds-for-youtube' );
|
||||
break;
|
||||
default:
|
||||
$message = __( 'We encountered a problem unlocking the PRO features. Please install the PRO version manually.', 'feeds-for-youtube' );
|
||||
}
|
||||
}
|
||||
|
||||
return $message;
|
||||
}
|
||||
|
||||
}
|
||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user