Download all files FTP
This commit is contained in:
@@ -0,0 +1,159 @@
|
||||
<?php
|
||||
|
||||
// uncomment this line for testing
|
||||
//set_site_transient( 'update_plugins', null );
|
||||
|
||||
class DrawAttention_ImportExport {
|
||||
public $parent;
|
||||
|
||||
function __construct( $parent ) {
|
||||
$this->parent = $parent;
|
||||
|
||||
add_action( 'admin_menu', array( $this, 'admin_menu' ) );
|
||||
}
|
||||
|
||||
public function is_action( $action ) {
|
||||
if ( !empty( $_POST['action'] ) && $_POST['action'] === $action ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function process_import() {
|
||||
if ( !$this->is_action( 'import' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( empty( $_POST['import_code'] ) ) {
|
||||
return;
|
||||
}
|
||||
$import_code = stripslashes($_POST['import_code']);
|
||||
$import_array = json_decode( $import_code, true );
|
||||
if ( empty( $import_array['0']['post']['ID'] ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$imported = array();
|
||||
$errors = array();
|
||||
|
||||
foreach ($import_array as $key => $to_import) {
|
||||
unset($to_import['post']['ID']);
|
||||
$insert_id = wp_insert_post( $to_import['post'], false );
|
||||
if ( !empty( $insert_id ) ) {
|
||||
$imported[] = array(
|
||||
'ID' => $insert_id,
|
||||
'post_title' => $to_import['post']['post_title'],
|
||||
);
|
||||
} else {
|
||||
$errors[] = $to_import;
|
||||
}
|
||||
}
|
||||
|
||||
return array(
|
||||
'imported' => $imported,
|
||||
'errors' => $errors,
|
||||
);
|
||||
}
|
||||
|
||||
public function get_export_array( $ids=array() ) {
|
||||
$response = array();
|
||||
foreach ($ids as $key => $id) {
|
||||
$post = get_post( $id );
|
||||
if ( empty( $post->post_type ) || $post->post_type !== 'da_image' ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$response[$key] = array(
|
||||
'id' => $id,
|
||||
'post' => (array)$post,
|
||||
);
|
||||
$metadata = get_post_meta( $id, '', true );
|
||||
foreach ($metadata as $meta_key => $meta_value) {
|
||||
if ( strpos( $meta_key, '_da_' ) !== 0 ) {
|
||||
continue;
|
||||
}
|
||||
$response[$key]['post']['meta_input'][$meta_key] = maybe_unserialize( $meta_value[0] );
|
||||
}
|
||||
}
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
public function get_export_json( $ids=array() ) {
|
||||
$export_array = $this->get_export_array( $ids );
|
||||
return json_encode( $export_array );
|
||||
}
|
||||
|
||||
public function admin_menu() {
|
||||
global $submenu;
|
||||
|
||||
add_submenu_page( 'edit.php?post_type=da_image', __( 'Import / Export', 'draw-attention' ), __( 'Import / Export', 'draw-attention' ), 'delete_others_posts', 'import_export', array( $this, 'output_import_export_page' ) );
|
||||
}
|
||||
|
||||
public function output_import_export_page() {
|
||||
// only allow users with capability: "delete_others_posts"
|
||||
if ( ! current_user_can( 'delete_others_posts' ) ) {
|
||||
return;
|
||||
}
|
||||
?>
|
||||
<div class="import">
|
||||
<h3>Import</h3>
|
||||
<p>If you've already exported from another site, paste the export code below:</p>
|
||||
<form method="POST" name="import" action="edit.php?post_type=da_image&page=import_export">
|
||||
<input type="hidden" name="action" value="import" />
|
||||
<textarea name="import_code" cols="100" rows="5" placeholder=""></textarea><br />
|
||||
<input type="submit" value="Import" />
|
||||
</form>
|
||||
<?php $response = $this->process_import(); ?>
|
||||
<?php if ( !empty( $response ) ): ?>
|
||||
<?php foreach ($response['imported'] as $key => $value): ?>
|
||||
<h4>
|
||||
Successfully imported
|
||||
<a href="<?php echo admin_url( 'post.php?post='.$value['ID'].'&action=edit' ); ?>">
|
||||
<?php echo $value['post_title']; ?>
|
||||
</a>
|
||||
</h4>
|
||||
<?php endforeach ?>
|
||||
<h3>Note: the image itself isn't transferred over, so you will need to reupload it. But most importantly all the colors and shapes are transferred over!
|
||||
<?php endif ?>
|
||||
</div>
|
||||
<br />
|
||||
<div class="export">
|
||||
<h3>Export</h3>
|
||||
<p>Choose images to export</p>
|
||||
<form method="POST" name="export" action="edit.php?post_type=da_image&page=import_export">
|
||||
<input type="hidden" name="action" value="export" />
|
||||
<?php
|
||||
$da_images = new WP_Query( array(
|
||||
'post_type' => 'da_image',
|
||||
'post_status' => 'any',
|
||||
'posts_per_page' => -1,
|
||||
) );
|
||||
$export_ids = ( empty( $_POST['export_ids'] ) ) ? array() : (array)$_POST['export_ids'];
|
||||
foreach ($da_images->posts as $key => $da_image): ?>
|
||||
<input type="checkbox" name="export_ids[]" value="<?php echo $da_image->ID; ?>" id="export_id_<?php echo $da_image->ID; ?>" <?php if( in_array( $da_image->ID, $export_ids ) ) echo 'checked="checked"'; ?> /> <label for="export_id_<?php echo $da_image->ID; ?>"><?php echo $da_image->post_title; ?></label><br />
|
||||
<?php endforeach; ?>
|
||||
<input type="submit" value="Generate Export Code" />
|
||||
</form>
|
||||
|
||||
<?php if ( $this->is_action( 'export' ) ): ?>
|
||||
<?php if ( empty( $_POST['export_ids'] ) ): ?>
|
||||
Please select one or more images above to export
|
||||
<?php else: ?>
|
||||
<?php
|
||||
$export_ids = $_POST['export_ids'];
|
||||
if ( !is_array( $export_ids ) ) {
|
||||
$export_ids = array();
|
||||
}
|
||||
$export_ids = array_map( 'esc_attr', $export_ids );
|
||||
$export_json = $this->get_export_json( $export_ids );
|
||||
?>
|
||||
<textarea cols="100" rows="20"><?php echo $export_json; ?></textarea>
|
||||
<?php endif ?>
|
||||
<?php endif ?>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,584 @@
|
||||
<?php
|
||||
class DrawAttention_Pro {
|
||||
public $parent;
|
||||
public $photon_excluded_images = array();
|
||||
|
||||
function __construct( $parent ) {
|
||||
$this->parent = $parent;
|
||||
|
||||
add_action( 'add_meta_boxes', array( $this, 'add_shortcode_metabox' ), 15 );
|
||||
add_filter( 'cmb2_meta_boxes', array( $this, 'add_layout_metabox' ), 20 );
|
||||
add_filter( 'da_themes', array( $this, 'add_pro_themes' ) );
|
||||
|
||||
remove_shortcode( 'drawattention' );
|
||||
add_shortcode( 'drawattention', array( $this, 'shortcode' ) );
|
||||
add_filter( 'da_detail_image_size', array( $this, 'optimize_detail_image_size' ), 5, 4 );
|
||||
add_filter( 'jetpack_photon_skip_image', array ($this, 'jetpack_photon_skip_image' ), 10, 3 );
|
||||
}
|
||||
|
||||
function add_layout_metabox( $metaboxes ) {
|
||||
$metaboxes['da_layout'] = array(
|
||||
'id' => 'da_layout_metabox',
|
||||
'title' => __( 'Layout', 'draw-attention' ),
|
||||
'object_types' => array( $this->parent->cpt->post_type, ),
|
||||
'context' => 'side',
|
||||
'priority' => 'low',
|
||||
'fields' => array(
|
||||
|
||||
array(
|
||||
'name' => __( '', 'draw-attention' ),
|
||||
'desc' => __( '', 'draw-attention' ),
|
||||
'id' => $this->parent->custom_fields->prefix . 'map_layout',
|
||||
'type' => 'radio',
|
||||
'options' => array(
|
||||
'left' => __('Left', 'draw-attention' ),
|
||||
'right' => __('Right', 'draw-attention' ),
|
||||
'bottom' => __('Bottom', 'draw-attention' ),
|
||||
'top' => __('Top', 'draw-attention' ),
|
||||
'lightbox' => __('Lightbox', 'draw-attention' ),
|
||||
'tooltip' => __('Tooltip', 'draw-attention' ),
|
||||
),
|
||||
'default' => 'left',
|
||||
),
|
||||
|
||||
array(
|
||||
'name' => __( 'Show more info on', 'draw-attention' ),
|
||||
'desc' => __( 'Click is recommended for best results. If you use Hover, please test carefully with your image', 'draw-attention' ),
|
||||
'id' => $this->parent->custom_fields->prefix . 'event_trigger',
|
||||
'type' => 'select',
|
||||
'options' => array(
|
||||
'click' => __('Click', 'draw-attention' ),
|
||||
'hover' => __('Hover', 'draw-attention' ),
|
||||
),
|
||||
'default' => 'click',
|
||||
),
|
||||
|
||||
),
|
||||
);
|
||||
|
||||
return $metaboxes;
|
||||
}
|
||||
|
||||
public function optimize_detail_image_size( $size, $hotspot, $image, $settings ) {
|
||||
$layout = $settings[$this->parent->custom_fields->prefix.'map_layout'][0];
|
||||
|
||||
if ( in_array( $layout, array( 'top', 'bottom', 'lightbox' ) ) ) {
|
||||
$size = 'large';
|
||||
} elseif ( in_array( $layout, array( 'left', 'right', 'tooltip' ) ) ) {
|
||||
$size = 'medium';
|
||||
}
|
||||
|
||||
return $size;
|
||||
}
|
||||
|
||||
public function jetpack_photon_skip_image( $val, $src, $tag ) {
|
||||
if ( in_array( $src, $this->photon_excluded_images ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return $val;
|
||||
}
|
||||
|
||||
public function shortcode( $atts ) {
|
||||
$a = shortcode_atts( array(
|
||||
'id' => ''
|
||||
), $atts);
|
||||
|
||||
// Begin settings array
|
||||
$settings = array(
|
||||
'image_id' => $a['id'],
|
||||
'has_photon' => class_exists( 'Jetpack_Photon' ),
|
||||
'url_hotspots' => array(),
|
||||
'urls_only' => false,
|
||||
'urls_class' => '',
|
||||
);
|
||||
|
||||
// If no ID is passed, get the most recent DA image
|
||||
if ( empty ( $settings['image_id'] ) ) {
|
||||
$latest_da = get_posts('post_type=' . $this->parent->cpt->post_type . '&numberposts=1');
|
||||
$settings['image_id'] = $latest_da[0]->ID;
|
||||
}
|
||||
|
||||
// Get and set DA settings
|
||||
$settings['img_settings'] = get_metadata( 'post', $settings['image_id'], '', false );
|
||||
if ( empty( $settings['img_settings']['_da_map_more_info'] ) ) {
|
||||
$settings['img_settings']['_da_map_more_info'] = array( '' );
|
||||
}
|
||||
$settings['spot_id'] = 'hotspot-' . $settings['image_id'];
|
||||
|
||||
// Add hotspots to settings
|
||||
$settings['hotspots'] = get_post_meta( $settings['image_id'], $this->parent->custom_fields->prefix . 'hotspots', true );
|
||||
if ( ! empty( $settings['hotspots'] ) ) {
|
||||
foreach( $settings['hotspots'] as $hotspot_key => $hotspot ) {
|
||||
if ( empty( $settings['hotspots'][$hotspot_key]['shape'] ) ) {
|
||||
$settings['hotspots'][$hotspot_key]['shape'] = 'polygon';
|
||||
}
|
||||
}
|
||||
}
|
||||
$settings['hotspots'] = apply_filters( 'da_render_hotspots', $settings['hotspots'], $settings['image_id'] );
|
||||
if ( empty( $settings['hotspots'] ) ) {
|
||||
$settings['url_hotspots'] = array();
|
||||
} else {
|
||||
$settings['url_hotspots'] = array_filter($settings['hotspots'], function($var){
|
||||
if ( empty( $var['action'] ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $var['action'] == 'url';
|
||||
});
|
||||
if ( count( $settings['hotspots'] ) == count( $settings['url_hotspots'] ) ) {
|
||||
$settings['urls_only'] = true;
|
||||
$settings['urls_class'] = 'links-only';
|
||||
}
|
||||
}
|
||||
|
||||
// Set default values for missing settings
|
||||
$settings['layout'] = !empty($settings['img_settings'][$this->parent->custom_fields->prefix . 'map_layout'][0]) ? $settings['img_settings'][$this->parent->custom_fields->prefix . 'map_layout'][0] : 'left';
|
||||
$settings['event_trigger'] = !empty($settings['img_settings'][$this->parent->custom_fields->prefix.'event_trigger'][0]) ? $settings['img_settings'][$this->parent->custom_fields->prefix.'event_trigger'][0] : 'click';
|
||||
$settings['always_visible'] = !empty($settings['img_settings'][$this->parent->custom_fields->prefix . 'always_visible'][0]) ? $settings['img_settings'][$this->parent->custom_fields->prefix . 'always_visible'][0] : 'false';
|
||||
|
||||
// Add styles to settings
|
||||
$settings['styles'] = get_post_meta( $settings['image_id'], $this->parent->custom_fields->prefix . 'styles', true );
|
||||
$map_style_names_to_titles = array();
|
||||
if ( ! empty( $this->parent->custom_fields->styles['user'] ) ) {
|
||||
$map_style_names_to_titles = $this->parent->custom_fields->styles['user']->get_saved_styles( $settings['image_id']);
|
||||
}
|
||||
$settings['border_width'] = $settings['img_settings'][$this->parent->custom_fields->prefix.'map_border_width'][0];
|
||||
$settings['border_opacity'] = $settings['img_settings'][$this->parent->custom_fields->prefix.'map_border_opacity'][0];
|
||||
$settings['more_info_bg'] = ( !empty( $settings['img_settings'][$this->parent->custom_fields->prefix.'map_background_color'][0] ) ) ? $settings['img_settings'][$this->parent->custom_fields->prefix.'map_background_color'][0] : '';
|
||||
$settings['more_info_text'] = ( !empty( $settings['img_settings'][$this->parent->custom_fields->prefix.'map_text_color'][0] ) ) ? $settings['img_settings'][$this->parent->custom_fields->prefix.'map_text_color'][0] : '';
|
||||
$settings['more_info_title'] = ( !empty( $settings['img_settings'][$this->parent->custom_fields->prefix.'map_title_color'][0] ) ) ? $settings['img_settings'][$this->parent->custom_fields->prefix.'map_title_color'][0] : '';
|
||||
$settings['img_bg'] = ( !empty( $settings['img_settings'][$this->parent->custom_fields->prefix.'image_background_color'][0] ) ) ? $settings['img_settings'][$this->parent->custom_fields->prefix.'image_background_color'][0] : '#efefef';
|
||||
|
||||
// Create default style
|
||||
if ( empty( $settings['styles'] ) ) {
|
||||
$settings['styles'] = array();
|
||||
}
|
||||
$settings['styles'][] = array(
|
||||
'title' => 'default',
|
||||
'map_highlight_color' => !empty( $settings['img_settings'][$this->parent->custom_fields->prefix.'map_highlight_color'][0] ) ? $settings['img_settings'][$this->parent->custom_fields->prefix.'map_highlight_color'][0] : '',
|
||||
'map_highlight_opacity' => !empty( $settings['img_settings'][$this->parent->custom_fields->prefix.'map_highlight_opacity'][0] ) ? $settings['img_settings'][$this->parent->custom_fields->prefix.'map_highlight_opacity'][0] : '',
|
||||
'map_border_color' => !empty( $settings['img_settings'][$this->parent->custom_fields->prefix.'map_border_color'][0] ) ? $settings['img_settings'][$this->parent->custom_fields->prefix.'map_border_color'][0] : '',
|
||||
'_da_map_hover_color' => !empty( $settings['img_settings'][$this->parent->custom_fields->prefix.'map_hover_color'][0] ) ? $settings['img_settings'][$this->parent->custom_fields->prefix.'map_hover_color'][0] : '',
|
||||
'_da_map_hover_opacity' => !empty( $settings['img_settings'][$this->parent->custom_fields->prefix.'map_hover_opacity'][0] ) ? $settings['img_settings'][$this->parent->custom_fields->prefix.'map_hover_opacity'][0] : ''
|
||||
);
|
||||
|
||||
// Create formatted array of styles
|
||||
$formatted_styles = array();
|
||||
foreach ($settings['styles'] as $key => $style) {
|
||||
if ( empty( $style['title'] ) ) {
|
||||
$style['title'] = 'Custom';
|
||||
$style['title'] = 'Style #'.(((int)$key)+1);
|
||||
}
|
||||
|
||||
$style_slug = array_search($style['title'], $map_style_names_to_titles);
|
||||
$new_style = array(
|
||||
'name' => $style_slug ? $style_slug : $style['title'],
|
||||
'borderWidth' => $settings['border_width'],
|
||||
);
|
||||
|
||||
if ( $settings['always_visible'] && $settings['always_visible'] !== 'false' ) {
|
||||
if ( empty( $style['map_border_color'] ) ) {
|
||||
$style['map_border_color'] = '#FFFFFF';
|
||||
}
|
||||
|
||||
$new_style['display'] = array(
|
||||
'fillColor' => $style['map_highlight_color'],
|
||||
'fillOpacity' => $style['map_highlight_opacity'],
|
||||
'borderColor' => $style['map_border_color'],
|
||||
'borderOpacity' => $settings['border_opacity'],
|
||||
);
|
||||
$new_style['hover'] = array(
|
||||
'fillColor' => $style['_da_map_hover_color'],
|
||||
'fillOpacity' => $style['_da_map_hover_opacity'],
|
||||
'borderColor' => $style['map_border_color'],
|
||||
'borderOpacity' => $settings['border_opacity'],
|
||||
);
|
||||
} else {
|
||||
$new_style['display'] = array(
|
||||
'fillColor' => '#ffffff',
|
||||
'fillOpacity' => 0,
|
||||
'borderColor' => '#ffffff',
|
||||
'borderOpacity' => 0,
|
||||
);
|
||||
$new_style['hover'] = array(
|
||||
'fillColor' => $style['map_highlight_color'],
|
||||
'fillOpacity' => $style['map_highlight_opacity'],
|
||||
'borderColor' => $style['map_border_color'],
|
||||
'borderOpacity' => $settings['border_opacity'],
|
||||
);
|
||||
}
|
||||
array_push($formatted_styles, $new_style);
|
||||
}
|
||||
|
||||
// Get image post, src, and meta
|
||||
$settings['img_post'] = get_post($settings['image_id']);
|
||||
$settings['img_src'] = wp_get_attachment_image_src( get_post_thumbnail_id( $settings['image_id'] ), 'full' );
|
||||
$settings['img_url'] = $settings['img_src'][0];
|
||||
$settings['img_width'] = $settings['img_src'][1];
|
||||
$settings['img_height'] = $settings['img_src'][2];
|
||||
$settings['img_alt'] = get_post_meta( get_post_thumbnail_id( $settings['img_post'] ), '_wp_attachment_image_alt', true );
|
||||
if ( empty( $settings['img_alt'] ) ) {
|
||||
$settings['img_alt'] = get_the_title( $settings['img_post'] );
|
||||
}
|
||||
|
||||
|
||||
// TODO: Figure out how to enqueue lightbox and tooltip scripts only when needed.
|
||||
|
||||
// Enqueue CSS and Scripts
|
||||
wp_enqueue_style( $this->parent->plugin_slug . '-plugin-styles' );
|
||||
wp_enqueue_script( $this->parent->plugin_slug . '-plugin-script' );
|
||||
|
||||
$this->photon_excluded_images[ $settings['image_id'] ] = $settings['img_url'];
|
||||
|
||||
// Create a new embed
|
||||
$wp_embed = new WP_Embed();
|
||||
|
||||
ob_start();
|
||||
|
||||
require( $this->parent->get_plugin_dir() . '/public/views/shortcode_template.php' );
|
||||
|
||||
return ob_get_clean();
|
||||
}
|
||||
|
||||
function add_shortcode_metabox() {
|
||||
remove_meta_box( 'da_shortcode', $this->parent->cpt->post_type, 'side', 'low' );
|
||||
add_meta_box( 'da_shortcode_pro', __('Copy Shortcode', 'draw-attention' ), array( $this, 'display_shortcode_metabox' ), $this->parent->cpt->post_type, 'side', 'low');
|
||||
}
|
||||
|
||||
function display_shortcode_metabox() {
|
||||
echo '[drawattention ID="'.get_the_id().'"]';
|
||||
}
|
||||
|
||||
function add_pro_themes( $themes ) {
|
||||
$themes = array_merge( $themes, array(
|
||||
'suzette' => array(
|
||||
'slug' => 'suzette',
|
||||
'name' => 'Suzette',
|
||||
'values' => array(
|
||||
'map_highlight_color' => '#FE59C2',
|
||||
'map_highlight_opacity' => 0.8,
|
||||
|
||||
'map_border_color' => '#D82B99',
|
||||
'map_border_opacity' => 0.8,
|
||||
'map_border_width' => 3,
|
||||
|
||||
'map_hover_color' => '#fe26af',
|
||||
'map_hover_opacity' => 0.9,
|
||||
|
||||
'map_title_color' => '#FF80D1',
|
||||
'map_text_color' => '#FFCCEC',
|
||||
'map_background_color' => '#8B0059',
|
||||
),
|
||||
),
|
||||
'autumn' => array(
|
||||
'slug' => 'autumn',
|
||||
'name' => 'Autumn',
|
||||
'values' => array(
|
||||
'map_highlight_color' => '#9E0303',
|
||||
'map_highlight_opacity' => 0.8,
|
||||
|
||||
'map_border_color' => '#210900',
|
||||
'map_border_opacity' => 0.8,
|
||||
'map_border_width' => 1,
|
||||
|
||||
'map_hover_color' => '#6c0202',
|
||||
'map_hover_opacity' => 0.9,
|
||||
|
||||
'map_title_color' => '#D4A600',
|
||||
'map_text_color' => '#F2EACB',
|
||||
'map_background_color' => '#590015',
|
||||
),
|
||||
),
|
||||
'spring' => array(
|
||||
'slug' => 'spring',
|
||||
'name' => 'Spring',
|
||||
'values' => array(
|
||||
'map_highlight_color' => '#DAA2BE',
|
||||
'map_highlight_opacity' => 0.8,
|
||||
|
||||
'map_border_color' => '#A2BEDA',
|
||||
'map_border_opacity' => 0.8,
|
||||
'map_border_width' => 5,
|
||||
|
||||
'map_hover_color' => '#c26594',
|
||||
'map_hover_opacity' => 0.9,
|
||||
|
||||
'map_title_color' => '#DAA2BE',
|
||||
'map_text_color' => '#8FB46B',
|
||||
'map_background_color' => '#F1FFE4',
|
||||
),
|
||||
),
|
||||
'midnight' => array(
|
||||
'slug' => 'midnight',
|
||||
'name' => 'Midnight',
|
||||
'values' => array(
|
||||
'map_highlight_color' => '#002244',
|
||||
'map_highlight_opacity' => 0.7,
|
||||
|
||||
'map_border_color' => '#000D1A',
|
||||
'map_border_opacity' => 1,
|
||||
'map_border_width' => 1,
|
||||
|
||||
'map_hover_color' => '#004488',
|
||||
'map_hover_opacity' => 0.9,
|
||||
|
||||
'map_title_color' => '#ffffff',
|
||||
'map_text_color' => '#A2BEDA',
|
||||
'map_background_color' => '#002244',
|
||||
),
|
||||
),
|
||||
'blacktie' => array(
|
||||
'slug' => 'blacktie',
|
||||
'name' => 'Black Tie',
|
||||
'values' => array(
|
||||
'map_highlight_color' => '#FF023D',
|
||||
'map_highlight_opacity' => 0.8,
|
||||
|
||||
'map_border_color' => '#636366',
|
||||
'map_border_opacity' => 1,
|
||||
'map_border_width' => 2,
|
||||
|
||||
'map_hover_color' => '#9b0024',
|
||||
'map_hover_opacity' => 0.9,
|
||||
|
||||
'map_title_color' => '#FF023D',
|
||||
'map_text_color' => '#FFFFFF',
|
||||
'map_background_color' => '#050004',
|
||||
),
|
||||
),
|
||||
'crimson' => array(
|
||||
'slug' => 'crimson',
|
||||
'name' => 'Crimson',
|
||||
'values' => array(
|
||||
'map_highlight_color' => '#CC0000',
|
||||
'map_highlight_opacity' => 0.8,
|
||||
|
||||
'map_border_color' => '#800000',
|
||||
'map_border_opacity' => 1,
|
||||
'map_border_width' => 2,
|
||||
|
||||
'map_hover_color' => '#770000',
|
||||
'map_hover_opacity' => 0.9,
|
||||
|
||||
'map_title_color' => '#F22424',
|
||||
'map_text_color' => '#FF7373',
|
||||
'map_background_color' => '#590000',
|
||||
),
|
||||
),
|
||||
'tangerine' => array(
|
||||
'slug' => 'tangerine',
|
||||
'name' => 'Tangerine',
|
||||
'values' => array(
|
||||
'map_highlight_color' => '#F28500',
|
||||
'map_highlight_opacity' => 0.8,
|
||||
|
||||
'map_border_color' => '#FFC073',
|
||||
'map_border_opacity' => 1,
|
||||
'map_border_width' => 2,
|
||||
|
||||
'map_hover_color' => '#ae6000',
|
||||
'map_hover_opacity' => 0.9,
|
||||
|
||||
'map_title_color' => '#FFC073',
|
||||
'map_text_color' => '#7F4600',
|
||||
'map_background_color' => '#F28500',
|
||||
),
|
||||
),
|
||||
'sunnyday' => array(
|
||||
'slug' => 'sunnyday',
|
||||
'name' => 'Sunny Day',
|
||||
'values' => array(
|
||||
'map_highlight_color' => '#FFCC33',
|
||||
'map_highlight_opacity' => 0.8,
|
||||
|
||||
'map_border_color' => '#5983FF',
|
||||
'map_border_opacity' => 0.8,
|
||||
'map_border_width' => 2,
|
||||
|
||||
'map_hover_color' => '#9db6ff',
|
||||
'map_hover_opacity' => 0.9,
|
||||
|
||||
'map_title_color' => '#FFCC33',
|
||||
'map_text_color' => '#A6BCFF',
|
||||
'map_background_color' => '#0B3ED9',
|
||||
),
|
||||
),
|
||||
'forest' => array(
|
||||
'slug' => 'forest',
|
||||
'name' => 'Forest',
|
||||
'values' => array(
|
||||
'map_highlight_color' => '#1C8C15',
|
||||
'map_highlight_opacity' => 0.8,
|
||||
|
||||
'map_border_color' => '#066600',
|
||||
'map_border_opacity' => 0.8,
|
||||
'map_border_width' => 3,
|
||||
|
||||
'map_hover_color' => '#2bd620',
|
||||
'map_hover_opacity' => 0.9,
|
||||
|
||||
'map_title_color' => '#3DB235',
|
||||
'map_text_color' => '#68D861',
|
||||
'map_background_color' => '#044000',
|
||||
),
|
||||
),
|
||||
'blueprint' => array(
|
||||
'slug' => 'blueprint',
|
||||
'name' => 'Blueprint',
|
||||
'values' => array(
|
||||
'map_highlight_color' => '#20418D',
|
||||
'map_highlight_opacity' => 0.8,
|
||||
|
||||
'map_border_color' => '#001440',
|
||||
'map_border_opacity' => 0.8,
|
||||
'map_border_width' => 3,
|
||||
|
||||
'map_hover_color' => '#0d1b3a',
|
||||
'map_hover_opacity' => 0.9,
|
||||
|
||||
'map_title_color' => '#20418D',
|
||||
'map_text_color' => '#001440',
|
||||
'map_background_color' => '#FAFBFF',
|
||||
),
|
||||
),
|
||||
'violet' => array(
|
||||
'slug' => 'violet',
|
||||
'name' => 'Violet',
|
||||
'values' => array(
|
||||
'map_highlight_color' => '#C523EB',
|
||||
'map_highlight_opacity' => 0.8,
|
||||
|
||||
'map_border_color' => '#9F00C5',
|
||||
'map_border_opacity' => 0.8,
|
||||
'map_border_width' => 2,
|
||||
|
||||
'map_hover_color' => '#590a6b',
|
||||
'map_hover_opacity' => 0.9,
|
||||
|
||||
'map_title_color' => '#9a36b2',
|
||||
'map_text_color' => '#75158C',
|
||||
'map_background_color' => '#EB99FF',
|
||||
),
|
||||
),
|
||||
'america' => array(
|
||||
'slug' => 'america',
|
||||
'name' => 'America',
|
||||
'values' => array(
|
||||
'map_highlight_color' => '#E0162B',
|
||||
'map_highlight_opacity' => 0.8,
|
||||
|
||||
'map_border_color' => '#0052A5',
|
||||
'map_border_opacity' => 0.8,
|
||||
'map_border_width' => 5,
|
||||
|
||||
'map_hover_color' => '#0052a5',
|
||||
'map_hover_opacity' => 0.9,
|
||||
|
||||
'map_title_color' => '#ffffff',
|
||||
'map_text_color' => '#ffffff',
|
||||
'map_background_color' => '#0052A5',
|
||||
),
|
||||
),
|
||||
'mintchip' => array(
|
||||
'slug' => 'mintchip',
|
||||
'name' => 'Mint Chip',
|
||||
'values' => array(
|
||||
'map_highlight_color' => '#9CBD8E',
|
||||
'map_highlight_opacity' => 0.8,
|
||||
|
||||
'map_border_color' => '#3B240C',
|
||||
'map_border_opacity' => 0.8,
|
||||
'map_border_width' => 3,
|
||||
|
||||
'map_hover_color' => '#6e9b5b',
|
||||
'map_hover_opacity' => 0.9,
|
||||
|
||||
'map_title_color' => '#9CBD8E',
|
||||
'map_text_color' => '#F0E6BD',
|
||||
'map_background_color' => '#4A2607',
|
||||
),
|
||||
),
|
||||
'candybox' => array(
|
||||
'slug' => 'candybox',
|
||||
'name' => 'Candy Box',
|
||||
'values' => array(
|
||||
'map_highlight_color' => '#EB9F9F',
|
||||
'map_highlight_opacity' => 0.8,
|
||||
|
||||
'map_border_color' => '#A79C8E',
|
||||
'map_border_opacity' => 0.8,
|
||||
'map_border_width' => 3,
|
||||
|
||||
'map_hover_color' => '#f8ecc9',
|
||||
'map_hover_opacity' => 0.9,
|
||||
|
||||
'map_title_color' => '#F1BBBA',
|
||||
'map_text_color' => '#F8ECC9',
|
||||
'map_background_color' => '#6B5344',
|
||||
),
|
||||
),
|
||||
'stormyseas' => array(
|
||||
'slug' => 'stormyseas',
|
||||
'name' => 'Stormy Seas',
|
||||
'values' => array(
|
||||
'map_highlight_color' => '#3E838C',
|
||||
'map_highlight_opacity' => 0.8,
|
||||
|
||||
'map_border_color' => '#195E63',
|
||||
'map_border_opacity' => 0.8,
|
||||
'map_border_width' => 3,
|
||||
|
||||
'map_hover_color' => '#8ebdb6',
|
||||
'map_hover_opacity' => 0.9,
|
||||
|
||||
'map_title_color' => '#8EBDB6',
|
||||
'map_text_color' => '#ECE1C3',
|
||||
'map_background_color' => '#063940',
|
||||
),
|
||||
),
|
||||
'planetearth' => array(
|
||||
'slug' => 'planetearth',
|
||||
'name' => 'Planet Earth',
|
||||
'values' => array(
|
||||
'map_highlight_color' => '#036564',
|
||||
'map_highlight_opacity' => 0.8,
|
||||
|
||||
'map_border_color' => '#031634',
|
||||
'map_border_opacity' => 0.8,
|
||||
'map_border_width' => 3,
|
||||
|
||||
'map_hover_color' => '#cdb380',
|
||||
'map_hover_opacity' => 0.9,
|
||||
|
||||
'map_title_color' => '#CDB380',
|
||||
'map_text_color' => '#E8DDCB',
|
||||
'map_background_color' => '#033649',
|
||||
),
|
||||
),
|
||||
'partyatmidnight' => array(
|
||||
'slug' => 'partyatmidnight',
|
||||
'name' => 'Party at Midnight',
|
||||
'values' => array(
|
||||
'map_highlight_color' => '#FFAB98',
|
||||
'map_highlight_opacity' => 0.8,
|
||||
|
||||
'map_border_color' => '#7F9CA0',
|
||||
'map_border_opacity' => 0.8,
|
||||
'map_border_width' => 3,
|
||||
|
||||
'map_hover_color' => '#7f9ca0',
|
||||
'map_hover_opacity' => 0.9,
|
||||
|
||||
'map_title_color' => '#F74553',
|
||||
'map_text_color' => '#E5DBC0',
|
||||
'map_background_color' => '#0B0E31',
|
||||
),
|
||||
),
|
||||
|
||||
) );
|
||||
|
||||
return $themes;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,640 @@
|
||||
<?php
|
||||
|
||||
// uncomment this line for testing
|
||||
//set_site_transient( 'update_plugins', null );
|
||||
|
||||
class DrawAttention_Updater {
|
||||
public $parent;
|
||||
|
||||
const edd_store_url = 'https://wpdrawattention.com';
|
||||
|
||||
function __construct( $parent ) {
|
||||
$this->parent = $parent;
|
||||
|
||||
add_action( 'admin_init', array( $this, 'plugin_updater') );
|
||||
add_action( 'admin_init', array( $this, 'activate_license' ) );
|
||||
|
||||
add_action( 'admin_menu', array( $this, 'admin_menu' ) );
|
||||
add_filter( 'plugin_action_links_' . 'draw-attention-pro/'.$this->parent->plugin_slug.'.php', array( $this, 'add_action_links' ) );
|
||||
}
|
||||
|
||||
public function admin_menu() {
|
||||
global $submenu;
|
||||
|
||||
add_submenu_page( 'edit.php?post_type=da_image', __( 'License & Support', 'draw-attention' ), __( 'License & Support', 'draw-attention' ), 'manage_options', 'da_license', array( $this, 'output_license_page' ) );
|
||||
}
|
||||
|
||||
public function add_action_links( $links ) {
|
||||
$license_key_status = get_option( 'da_license_key_status' );
|
||||
if ( $license_key_status == 'valid' ) { return $links; }
|
||||
|
||||
return array_merge(
|
||||
array(
|
||||
'license' => '<a href="'.admin_url( 'edit.php?post_type=da_image&page=da_license' ).'">' . __( 'Enter License Key', 'draw-attention' ) . '</a>'
|
||||
),
|
||||
$links
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
function output_license_page() {
|
||||
echo '<div class="wrap">';
|
||||
echo '<h1>'.__('Draw Attention Pro', 'draw-attention' ).'</h1>';
|
||||
echo '<h2 class="title">'.__('License', 'draw-attention' ).'</h2>';
|
||||
echo '<p>'.__('Please enter your license key to enable automatic updates.', 'draw-attention' ).'</p>';
|
||||
echo $this->license_key_html();
|
||||
echo '<h2 class="title">'.__('Support', 'draw-attention' ).'</h2>';
|
||||
echo '<p>'.__('If you need help getting started, please review <a target="_blank" href="https://wpdrawattention.com/help-center/features/getting-started/">our documentation</a>.', 'draw-attention' ).'</p>';
|
||||
echo '<p>'.__('If you have any questions or problems, please <a target="_blank" href="https://wpdrawattention.com/contact/">contact our 5-star support team</a>.', 'draw-attention' ).'</p>';
|
||||
echo '</div>';
|
||||
}
|
||||
|
||||
function license_key_html() {
|
||||
$license_key_status = get_option( 'da_license_key_status' );
|
||||
if ( empty( $license_key_status ) ) {
|
||||
$license_key_status_html = '<span class="status status-yellow">'.__( 'Please enter your license key to receive support & updates', 'draw-attention' ).'. <a href="https://wpdrawattention.com" target="_blank">'.__( 'Click here to purchase or renew a license', 'draw-attention' ).'</a></span>';
|
||||
} elseif ( $license_key_status == 'valid' ) {
|
||||
$license_key_status_html = '<span class="status status-green">'.__( 'Valid license', 'draw-attention' ).'</span>';
|
||||
} elseif ( $license_key_status == 'invalid' ) {
|
||||
$license_key_status_html = '<span class="status status-red">'.__( 'Invalid license. Please verify the license key, you may need to <a href="https://wpdrawattention.com" target="_blank">renew your license</a> or <a href="mailto:support@wpdrawattention.com">contact support</a></span>', 'draw-attention' );
|
||||
}
|
||||
|
||||
$html = '<form>';
|
||||
$html .= '<input type="hidden" name="post_type" value="da_image" />';
|
||||
$html .= '<input type="hidden" name="page" value="da_license" />';
|
||||
$html .= '<table class="form-table" role="presentation">';
|
||||
$html .= '<tbody>';
|
||||
$html .= '<tr>';
|
||||
$html .= '<th scope="row">';
|
||||
$html .= '<label for="da_license_key">'.__( 'License Key', 'draw-attention' ).'</label>';
|
||||
$html .= '</th>';
|
||||
$html .= '<td>';
|
||||
if ( $license_key = get_option( 'da_license_key' ) ) {
|
||||
$html .= '<input type="password" name="da_license_key" id="da_license_key" size="32" value="'.$license_key.'" class="regular-text" />';
|
||||
} else {
|
||||
$html .= '<input type="text" name="da_license_key" id="da_license_key" size="32" class="regular-text" />';
|
||||
}
|
||||
$html .= '<div>';
|
||||
$html .= $license_key_status_html;
|
||||
$html .= '</div>';
|
||||
$html .= '</td>';
|
||||
$html .= '</tr>';
|
||||
$html .= '</tbody>';
|
||||
$html .= '</table>';
|
||||
$html .= '<p class="submit">';
|
||||
$html .= '<input type="submit" value="'.__( 'Update', 'draw-attention' ).'" class="button button-primary" />';
|
||||
$html .= '</p>';
|
||||
$html .= '</form>';
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
function plugin_updater() {
|
||||
$license_key = trim( get_option( 'da_license_key' ) );
|
||||
// $edd_updater = new TD_DA_EDD_SL_Plugin_Updater( self::edd_store_url, dirname ( dirname( DrawAttention::file ) ).'/draw-attention.php', array(
|
||||
// 'version' => DrawAttention::VERSION, // current version number
|
||||
// 'license' => $license_key, // license key (used get_option above to retrieve from DB)
|
||||
// 'item_name' => DrawAttention::name, // name of this plugin
|
||||
// 'author' => 'Tyler Digital' // author of this plugin
|
||||
// )
|
||||
// );
|
||||
}
|
||||
|
||||
function activate_license() {
|
||||
if ( !isset( $_REQUEST['da_license_key'] ) ) return;
|
||||
|
||||
$license_key = trim( $_REQUEST['da_license_key'] );
|
||||
if ( empty( $license_key ) ) {
|
||||
delete_option( 'da_license_key_status' );
|
||||
delete_option( 'da_license_key' );
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// data to send in our API request
|
||||
$api_params = array(
|
||||
'edd_action'=> 'activate_license',
|
||||
'license' => $license_key,
|
||||
'item_name' => urlencode( DrawAttention::name ) // the name of our product in EDD
|
||||
);
|
||||
|
||||
// Call the custom API.
|
||||
$response = wp_remote_get( add_query_arg( $api_params, DrawAttention_Updater::edd_store_url ), array( 'timeout' => 15, 'sslverify' => false ) );
|
||||
|
||||
// make sure the response came back okay
|
||||
if ( is_wp_error( $response ) )
|
||||
return false;
|
||||
|
||||
// decode the license data
|
||||
$license_data = json_decode( wp_remote_retrieve_body( $response ) );
|
||||
|
||||
// $license_data->license will be either "active" or "inactive"
|
||||
|
||||
update_option( 'da_license_key_status', $license_data->license );
|
||||
|
||||
if ( $license_data->license == 'valid' ) {
|
||||
update_option( 'da_license_key', $license_key );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
if ( class_exists( 'TD_DA_EDD_SL_Plugin_Updater' ) ) return;
|
||||
class TD_DA_EDD_SL_Plugin_Updater {
|
||||
private $api_url = '';
|
||||
private $api_data = array();
|
||||
private $name = '';
|
||||
private $slug = '';
|
||||
public $version;
|
||||
public $wp_override;
|
||||
public $beta;
|
||||
public $cache_key;
|
||||
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @uses plugin_basename()
|
||||
* @uses hook()
|
||||
*
|
||||
* @param string $_api_url The URL pointing to the custom API endpoint.
|
||||
* @param string $_plugin_file Path to the plugin file.
|
||||
* @param array $_api_data Optional data to send with API calls.
|
||||
* @return void
|
||||
*/
|
||||
function __construct( $_api_url, $_plugin_file, $_api_data = null ) {
|
||||
$this->api_url = trailingslashit( $_api_url );
|
||||
$this->api_data = $_api_data;
|
||||
$this->name = plugin_basename( $_plugin_file );
|
||||
$this->slug = basename( $_plugin_file, '.php' );
|
||||
$this->version = $_api_data['version'];
|
||||
$this->wp_override = isset( $_api_data['wp_override'] ) ? (bool) $_api_data['wp_override'] : false;
|
||||
$this->beta = ! empty( $this->api_data['beta'] ) ? true : false;
|
||||
$this->cache_key = md5( serialize( $this->slug . $this->api_data['license'] . $this->beta ) );
|
||||
|
||||
$edd_plugin_data[ $this->slug ] = $this->api_data;
|
||||
|
||||
// Set up hooks.
|
||||
$this->init();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Set up WordPress filters to hook into WP's update process.
|
||||
*
|
||||
* @uses add_filter()
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function init() {
|
||||
|
||||
add_filter( 'pre_set_site_transient_update_plugins', array( $this, 'check_update' ) );
|
||||
add_filter( 'plugins_api', array( $this, 'plugins_api_filter' ), 10, 3 );
|
||||
remove_action( 'after_plugin_row_' . $this->name, 'wp_plugin_update_row', 10 );
|
||||
add_action( 'after_plugin_row_' . $this->name, array( $this, 'show_update_notification' ), 10, 2 );
|
||||
add_action( 'admin_init', array( $this, 'show_changelog' ) );
|
||||
add_action( 'after_plugin_row_' . $this->name, array( $this, 'maybe_display_invalid_license_banner' ), 10, 2 );
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Check for Updates at the defined API endpoint and modify the update array.
|
||||
*
|
||||
* This function dives into the update API just when WordPress creates its update array,
|
||||
* then adds a custom API call and injects the custom plugin data retrieved from the API.
|
||||
* It is reassembled from parts of the native WordPress plugin update code.
|
||||
* See wp-includes/update.php line 121 for the original wp_update_plugins() function.
|
||||
*
|
||||
* @uses api_request()
|
||||
*
|
||||
* @param array $_transient_data Update array build by WordPress.
|
||||
* @return array Modified update array with custom plugin data.
|
||||
*/
|
||||
public function check_update( $_transient_data ) {
|
||||
|
||||
global $pagenow;
|
||||
|
||||
if ( ! is_object( $_transient_data ) ) {
|
||||
$_transient_data = new stdClass;
|
||||
}
|
||||
|
||||
if ( 'plugins.php' == $pagenow && is_multisite() ) {
|
||||
return $_transient_data;
|
||||
}
|
||||
|
||||
if ( ! empty( $_transient_data->response ) && ! empty( $_transient_data->response[ $this->name ] ) && false === $this->wp_override ) {
|
||||
return $_transient_data;
|
||||
}
|
||||
|
||||
$version_info = $this->get_cached_version_info();
|
||||
|
||||
if ( false === $version_info ) {
|
||||
$version_info = $this->api_request( 'plugin_latest_version', array( 'slug' => $this->slug, 'beta' => $this->beta ) );
|
||||
|
||||
$this->set_version_info_cache( $version_info );
|
||||
|
||||
}
|
||||
|
||||
if ( false !== $version_info && is_object( $version_info ) && isset( $version_info->new_version ) ) {
|
||||
|
||||
if ( version_compare( $this->version, $version_info->new_version, '<' ) ) {
|
||||
|
||||
$_transient_data->response[ $this->name ] = $version_info;
|
||||
|
||||
}
|
||||
|
||||
$_transient_data->last_checked = current_time( 'timestamp' );
|
||||
$_transient_data->checked[ $this->name ] = $this->version;
|
||||
|
||||
}
|
||||
|
||||
return $_transient_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* show update nofication row -- needed for multisite subsites, because WP won't tell you otherwise!
|
||||
*
|
||||
* @param string $file
|
||||
* @param array $plugin
|
||||
*/
|
||||
public function show_update_notification( $file, $plugin ) {
|
||||
|
||||
if ( is_network_admin() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if( ! current_user_can( 'update_plugins' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if( ! is_multisite() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( $this->name != $file ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Remove our filter on the site transient
|
||||
remove_filter( 'pre_set_site_transient_update_plugins', array( $this, 'check_update' ), 10 );
|
||||
|
||||
$update_cache = get_site_transient( 'update_plugins' );
|
||||
|
||||
$update_cache = is_object( $update_cache ) ? $update_cache : new stdClass();
|
||||
|
||||
if ( empty( $update_cache->response ) || empty( $update_cache->response[ $this->name ] ) ) {
|
||||
|
||||
$version_info = $this->get_cached_version_info();
|
||||
|
||||
if ( false === $version_info ) {
|
||||
$version_info = $this->api_request( 'plugin_latest_version', array( 'slug' => $this->slug, 'beta' => $this->beta ) );
|
||||
|
||||
$this->set_version_info_cache( $version_info );
|
||||
}
|
||||
|
||||
if ( ! is_object( $version_info ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( version_compare( $this->version, $version_info->new_version, '<' ) ) {
|
||||
|
||||
$update_cache->response[ $this->name ] = $version_info;
|
||||
|
||||
}
|
||||
|
||||
$update_cache->last_checked = current_time( 'timestamp' );
|
||||
$update_cache->checked[ $this->name ] = $this->version;
|
||||
|
||||
set_site_transient( 'update_plugins', $update_cache );
|
||||
|
||||
} else {
|
||||
|
||||
$version_info = $update_cache->response[ $this->name ];
|
||||
|
||||
}
|
||||
|
||||
// Restore our filter
|
||||
add_filter( 'pre_set_site_transient_update_plugins', array( $this, 'check_update' ) );
|
||||
|
||||
if ( ! empty( $update_cache->response[ $this->name ] ) && version_compare( $this->version, $version_info->new_version, '<' ) ) {
|
||||
|
||||
// build a plugin list row, with update notification
|
||||
$wp_list_table = _get_list_table( 'WP_Plugins_List_Table' );
|
||||
# <tr class="plugin-update-tr"><td colspan="' . $wp_list_table->get_column_count() . '" class="plugin-update colspanchange">
|
||||
echo '<tr class="plugin-update-tr" id="' . $this->slug . '-update" data-slug="' . $this->slug . '" data-plugin="' . $this->slug . '/' . $file . '">';
|
||||
echo '<td colspan="3" class="plugin-update colspanchange">';
|
||||
echo '<div class="update-message notice inline notice-warning notice-alt">';
|
||||
|
||||
$changelog_link = self_admin_url( 'index.php?edd_sl_action=view_plugin_changelog&plugin=' . $this->name . '&slug=' . $this->slug . '&TB_iframe=true&width=772&height=911' );
|
||||
|
||||
if ( empty( $version_info->download_link ) ) {
|
||||
printf(
|
||||
__( 'There is a new version of %1$s available. %2$sView version %3$s details%4$s.', 'easy-digital-downloads' ),
|
||||
esc_html( $version_info->name ),
|
||||
'<a target="_blank" class="thickbox" href="' . esc_url( $changelog_link ) . '">',
|
||||
esc_html( $version_info->new_version ),
|
||||
'</a>'
|
||||
);
|
||||
} else {
|
||||
printf(
|
||||
__( 'There is a new version of %1$s available. %2$sView version %3$s details%4$s or %5$supdate now%6$s.', 'easy-digital-downloads' ),
|
||||
esc_html( $version_info->name ),
|
||||
'<a target="_blank" class="thickbox" href="' . esc_url( $changelog_link ) . '">',
|
||||
esc_html( $version_info->new_version ),
|
||||
'</a>',
|
||||
'<a href="' . esc_url( wp_nonce_url( self_admin_url( 'update.php?action=upgrade-plugin&plugin=' ) . $this->name, 'upgrade-plugin_' . $this->name ) ) .'">',
|
||||
'</a>'
|
||||
);
|
||||
}
|
||||
|
||||
do_action( "in_plugin_update_message-{$file}", $plugin, $version_info );
|
||||
|
||||
echo '</div></td></tr>';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates information on the "View version x.x details" page with custom data.
|
||||
*
|
||||
* @uses api_request()
|
||||
*
|
||||
* @param mixed $_data
|
||||
* @param string $_action
|
||||
* @param object $_args
|
||||
* @return object $_data
|
||||
*/
|
||||
public function plugins_api_filter( $_data, $_action = '', $_args = null ) {
|
||||
|
||||
if ( $_action != 'plugin_information' ) {
|
||||
|
||||
return $_data;
|
||||
|
||||
}
|
||||
|
||||
if ( ! isset( $_args->slug ) || ( $_args->slug != $this->slug ) ) {
|
||||
|
||||
return $_data;
|
||||
|
||||
}
|
||||
|
||||
$to_send = array(
|
||||
'slug' => $this->slug,
|
||||
'is_ssl' => is_ssl(),
|
||||
'fields' => array(
|
||||
'banners' => array(),
|
||||
'reviews' => false
|
||||
)
|
||||
);
|
||||
|
||||
$cache_key = 'edd_api_request_' . md5( serialize( $this->slug . $this->api_data['license'] . $this->beta ) );
|
||||
|
||||
// Get the transient where we store the api request for this plugin for 24 hours
|
||||
$edd_api_request_transient = $this->get_cached_version_info( $cache_key );
|
||||
|
||||
//If we have no transient-saved value, run the API, set a fresh transient with the API value, and return that value too right now.
|
||||
if ( empty( $edd_api_request_transient ) ) {
|
||||
|
||||
$api_response = $this->api_request( 'plugin_information', $to_send );
|
||||
|
||||
// Expires in 3 hours
|
||||
$this->set_version_info_cache( $api_response, $cache_key );
|
||||
|
||||
if ( false !== $api_response ) {
|
||||
$_data = $api_response;
|
||||
}
|
||||
|
||||
} else {
|
||||
$_data = $edd_api_request_transient;
|
||||
}
|
||||
|
||||
// Convert sections into an associative array, since we're getting an object, but Core expects an array.
|
||||
if ( isset( $_data->sections ) && ! is_array( $_data->sections ) ) {
|
||||
$new_sections = array();
|
||||
foreach ( $_data->sections as $key => $value ) {
|
||||
$new_sections[ $key ] = $value;
|
||||
}
|
||||
|
||||
$_data->sections = $new_sections;
|
||||
}
|
||||
|
||||
// Convert banners into an associative array, since we're getting an object, but Core expects an array.
|
||||
if ( isset( $_data->banners ) && ! is_array( $_data->banners ) ) {
|
||||
$new_banners = array();
|
||||
foreach ( $_data->banners as $key => $value ) {
|
||||
$new_banners[ $key ] = $value;
|
||||
}
|
||||
|
||||
$_data->banners = $new_banners;
|
||||
}
|
||||
|
||||
return $_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable SSL verification in order to prevent download update failures
|
||||
*
|
||||
* @param array $args
|
||||
* @param string $url
|
||||
* @return object $array
|
||||
*/
|
||||
public function http_request_args( $args, $url ) {
|
||||
// If it is an https request and we are performing a package download, disable ssl verification
|
||||
if ( strpos( $url, 'https://' ) !== false && strpos( $url, 'edd_action=package_download' ) ) {
|
||||
$args['sslverify'] = false;
|
||||
}
|
||||
return $args;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls the API and, if successfull, returns the object delivered by the API.
|
||||
*
|
||||
* @uses get_bloginfo()
|
||||
* @uses wp_remote_post()
|
||||
* @uses is_wp_error()
|
||||
*
|
||||
* @param string $_action The requested action.
|
||||
* @param array $_data Parameters for the API action.
|
||||
* @return false|object
|
||||
*/
|
||||
private function api_request( $_action, $_data ) {
|
||||
|
||||
global $wp_version;
|
||||
|
||||
$data = array_merge( $this->api_data, $_data );
|
||||
|
||||
if ( $data['slug'] != $this->slug ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if( $this->api_url == trailingslashit (home_url() ) ) {
|
||||
return false; // Don't allow a plugin to ping itself
|
||||
}
|
||||
|
||||
$api_params = array(
|
||||
'edd_action' => 'get_version',
|
||||
'license' => ! empty( $data['license'] ) ? $data['license'] : '',
|
||||
'item_name' => isset( $data['item_name'] ) ? $data['item_name'] : false,
|
||||
'item_id' => isset( $data['item_id'] ) ? $data['item_id'] : false,
|
||||
'version' => isset( $data['version'] ) ? $data['version'] : false,
|
||||
'slug' => $data['slug'],
|
||||
'author' => $data['author'],
|
||||
'url' => home_url(),
|
||||
'beta' => ! empty( $data['beta'] ),
|
||||
);
|
||||
|
||||
$request = wp_remote_post( $this->api_url, array( 'timeout' => 15, 'sslverify' => false, 'body' => $api_params ) );
|
||||
|
||||
if ( ! is_wp_error( $request ) ) {
|
||||
$request = json_decode( wp_remote_retrieve_body( $request ) );
|
||||
}
|
||||
|
||||
if ( $request && isset( $request->sections ) ) {
|
||||
$request->sections = maybe_unserialize( $request->sections );
|
||||
} else {
|
||||
$request = false;
|
||||
}
|
||||
|
||||
if ( $request && isset( $request->banners ) ) {
|
||||
$request->banners = maybe_unserialize( $request->banners );
|
||||
}
|
||||
|
||||
if( ! empty( $request->sections ) ) {
|
||||
foreach( $request->sections as $key => $section ) {
|
||||
$request->$key = (array) $section;
|
||||
}
|
||||
}
|
||||
|
||||
return $request;
|
||||
}
|
||||
|
||||
public function show_changelog() {
|
||||
|
||||
global $edd_plugin_data;
|
||||
|
||||
if( empty( $_REQUEST['edd_sl_action'] ) || 'view_plugin_changelog' != $_REQUEST['edd_sl_action'] ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if( empty( $_REQUEST['plugin'] ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if( empty( $_REQUEST['slug'] ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if( ! current_user_can( 'update_plugins' ) ) {
|
||||
wp_die( __( 'You do not have permission to install plugin updates', 'easy-digital-downloads' ), __( 'Error', 'easy-digital-downloads' ), array( 'response' => 403 ) );
|
||||
}
|
||||
|
||||
$data = $edd_plugin_data[ $_REQUEST['slug'] ];
|
||||
$beta = ! empty( $data['beta'] ) ? true : false;
|
||||
$cache_key = md5( 'edd_plugin_' . sanitize_key( $_REQUEST['plugin'] ) . '_' . $beta . '_version_info' );
|
||||
$version_info = $this->get_cached_version_info( $cache_key );
|
||||
|
||||
if( false === $version_info ) {
|
||||
|
||||
$api_params = array(
|
||||
'edd_action' => 'get_version',
|
||||
'item_name' => isset( $data['item_name'] ) ? $data['item_name'] : false,
|
||||
'item_id' => isset( $data['item_id'] ) ? $data['item_id'] : false,
|
||||
'slug' => $_REQUEST['slug'],
|
||||
'author' => $data['author'],
|
||||
'url' => home_url(),
|
||||
'beta' => ! empty( $data['beta'] )
|
||||
);
|
||||
|
||||
$request = wp_remote_post( $this->api_url, array( 'timeout' => 15, 'sslverify' => false, 'body' => $api_params ) );
|
||||
|
||||
if ( ! is_wp_error( $request ) ) {
|
||||
$version_info = json_decode( wp_remote_retrieve_body( $request ) );
|
||||
}
|
||||
|
||||
|
||||
if ( ! empty( $version_info ) && isset( $version_info->sections ) ) {
|
||||
$version_info->sections = maybe_unserialize( $version_info->sections );
|
||||
} else {
|
||||
$version_info = false;
|
||||
}
|
||||
|
||||
if( ! empty( $version_info ) ) {
|
||||
foreach( $version_info->sections as $key => $section ) {
|
||||
$version_info->$key = (array) $section;
|
||||
}
|
||||
}
|
||||
|
||||
$this->set_version_info_cache( $version_info, $cache_key );
|
||||
|
||||
}
|
||||
|
||||
if( ! empty( $version_info ) && isset( $version_info->sections['changelog'] ) ) {
|
||||
echo '<div style="background:#fff;padding:10px;">' . $version_info->sections['changelog'] . '</div>';
|
||||
}
|
||||
|
||||
exit;
|
||||
}
|
||||
|
||||
public function get_cached_version_info( $cache_key = '' ) {
|
||||
|
||||
if( empty( $cache_key ) ) {
|
||||
$cache_key = $this->cache_key;
|
||||
}
|
||||
|
||||
$cache = get_option( $cache_key );
|
||||
|
||||
if( empty( $cache['timeout'] ) || current_time( 'timestamp' ) > $cache['timeout'] ) {
|
||||
return false; // Cache is expired
|
||||
}
|
||||
|
||||
return json_decode( $cache['value'] );
|
||||
|
||||
}
|
||||
|
||||
public function set_version_info_cache( $value = '', $cache_key = '' ) {
|
||||
|
||||
if( empty( $cache_key ) ) {
|
||||
$cache_key = $this->cache_key;
|
||||
}
|
||||
|
||||
$data = array(
|
||||
'timeout' => strtotime( '+3 hours', current_time( 'timestamp' ) ),
|
||||
'value' => json_encode( $value )
|
||||
);
|
||||
|
||||
update_option( $cache_key, $data );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Prompt unlicensed users to activate/purchase license in wp-admin/plugins.php list
|
||||
*
|
||||
* @since 3.0.5
|
||||
*
|
||||
* @param string $file
|
||||
* @param array $plugin
|
||||
*/
|
||||
public function maybe_display_invalid_license_banner( $file, $plugin ) {
|
||||
|
||||
|
||||
$license_key_status = get_option( 'da_license_key_status' );
|
||||
|
||||
if ( ! empty( $license_key_status ) && $license_key_status == 'valid' ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$license_page = admin_url( 'edit.php?post_type=da_image&page=da_license' );
|
||||
$store = 'https://wpdrawattention.com';
|
||||
|
||||
echo '<tr class="plugin-update-tr active">';
|
||||
echo '<td colspan="4" class="plugin-update colspanchange">';
|
||||
echo '<div class="update-message notice inline notice-warning notice-alt">';
|
||||
echo '<p>' . sprintf( __( 'Your Draw Attention License key is currently inactive or expired. %1$s Enter your license key %2$s or %3$s purchase a new one %4$s to enable automatic updates and support.', 'draw-attention' ),
|
||||
'<a href="' . $license_page . '">',
|
||||
'</a>',
|
||||
'<a href="' . $store . '" target="_blank">',
|
||||
'</a>' ) . '</p>';
|
||||
echo '</div>';
|
||||
echo '</td>';
|
||||
echo '</tr>';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user