| Current Path : /home/ereika83/www/wp-content/plugins/genesis-club-pro/classes/ |
| Current File : /home/ereika83/www/wp-content/plugins/genesis-club-pro/classes/class-media-admin.php |
<?php
class Genesis_Club_Media_Admin extends Genesis_Club_Admin {
const DISABLE_FITVIDS = 'genesis_club_fitvids';
private $media;
private $tips = array(
'favicon_img' => array('heading' => 'Favicon Image', 'tip' => 'Current Favicon image'),
'favicon_url' => array('heading' => 'Favicon URL', 'tip' => 'URL of the current favicon.'),
'favicon' => array('heading' => 'New Favicon', 'tip' => 'Upload a new favicon with a filename of favicon.ico, favicon.png or favicon.jpg.'),
'thumbnails' => array('heading' => 'Enable Thumbnails', 'tip' => 'Generate thumbnails of remotely hosted images for use on archive pages and featured post widgets. WordPress normally only supports featured images which are hosted in the WordPress Media library. This facility allows you to have <i>featured image-like</i> behaviour for externally hosted images.'),
'thumbnail_quality' => array('heading' => 'JPEG Quality', 'tip' => 'Thumbnail quality for JPGs: recommended minimum is 30, recommended maximum is 90.'),
'regenerate_thumbnails' => array('heading' => 'Enable Regeneration', 'tip' => 'Click to delete the Alt Featured Image thumbnails. You will want to do this if you change the dimensions of your images. New thumbnails of the required size will be generated on demand.'),
'header_image' => array('heading' => 'Image URL', 'tip' => 'Enter the full URL of a large image that will appear as the background of the header section of the site. Consult the theme instructions for recommendation on the image dimensions. The image file can be located in your media library, on Amazon S3 or a CDN.'),
'home_big_image' => array('heading' => 'Feature Image URL', 'tip' => 'Enter the full URL of an image of size 1600 by 600 px that will appear on your home page. The image can be located in your media library, on Amazon S3 or a CDN.'),
'peelback_enabled' => array('heading' => 'Enable Peelback', 'tip' => 'Click to enable the Peelback.'),
'peelback_image' => array('heading' => 'Image URL', 'tip' => 'Enter the full URL of an image of size 500 by 500 px that will appear on your home page when the peelback is revealed. The image can be located in your media library, on Amazon S3 or a CDN.'),
'peelback_target' => array('heading' => 'Target URL', 'tip' => 'Enter the full URL of the link to visit when the user clicks the peelback.'),
'peelback_tracking' => array('heading' => 'Tracking Label', 'tip' => 'Enter the Google Analytics code you want to use to track clicks on the peeback image.'),
'fitvids_home' => array('heading' => 'Home Page', 'tip' => 'Make any home page videos mobile responsive.'),
'fitvids_setting' => array('heading' => 'Other Pages', 'tip' => 'Control whether or not to make videos mobile responsive on other pages on the site.'),
'fitvids_none' => array('heading' => 'none', 'tip' => 'Mobile responsive code is not included on the page.'),
'fitvids_on_demand' => array('heading' => 'on demand', 'tip' => 'Only include mobile responsive code for videos on pages when individually selected.'),
'fitvids_all' => array('heading' => 'all', 'tip' => 'Include mobile responsive code for videos on all pages.'),
);
private $post_tips = array(
'featured_image' => array('heading' => 'Alternative Featured Image', 'tip' => 'Enter a value here for a featured image not held in the Media Library'),
'featured_image_alt' => array('heading' => 'Image Alt Tag', 'tip' => 'Enter the ALt tag for the featured image'),
);
function init() {
$this->media = $this->plugin->get_module('media');
add_action('admin_menu',array($this, 'admin_menu'));
if ($favicon = $this->media->get_option('favicon_url')) { //if there is a loaded favicon then use it in the admin site too
add_filter('genesis_pre_load_favicon', array($this->media,'favicon_url'));
add_action('admin_head', 'genesis_load_favicon' );
}
$fitvids = $this->media->get_option('fitvids');
if ('on_demand'==$fitvids['setting']) {
add_action('genesis_club_hiding_settings_show', array($this, 'add_page_visibility'), 10, 2);
add_action('genesis_club_hiding_settings_save', array($this, 'save_page_visibility'), 10, 1);
}
add_action('do_meta_boxes', array( $this, 'do_meta_boxes'), 20, 2 );
add_action('save_post', array( $this, 'save_post'));
}
function admin_menu() {
$this->screen_id = add_submenu_page($this->get_parent_slug(), __('Media'), __('Media'), 'manage_options',
$this->get_slug(), array($this,'page_content'));
add_action('load-'.$this->get_screen_id(), array($this, 'load_page'));
}
function page_content() {
$title = $this->admin_heading('Genesis Club Media Settings');
$this->print_admin_form($title, __CLASS__, $this->get_keys(), true); //enctype parameter true as file can be uploaded
}
function load_page() {
$this->set_tooltips($this->tips);
if (isset($_POST['options_update'])) $this->save_media();
$this->add_meta_box('intro', 'Introduction', 'intro_panel');
$this->add_meta_box('settings', 'Settings', 'media_panel', array ('options' => $this->media->get_options()));
$this->add_meta_box('news', 'Genesis Club News', 'news_panel', null, 'advanced');
add_action ('admin_enqueue_scripts',array($this, 'enqueue_admin_styles'));
add_action ('admin_enqueue_scripts',array($this, 'enqueue_postbox_scripts'));
add_action ('admin_enqueue_scripts',array($this, 'enqueue_metabox_scripts'));
}
function do_meta_boxes( $post_type, $context) {
$post_types=get_post_types();
if ( in_array($post_type, $post_types ) && ('advanced' === $context )) {
add_filter( 'genesis_club_post_settings', array($this, 'add_post_panel'), 10, 2); //add to plugin metabox on post page
}
}
function add_page_visibility($content, $post) {
return $content . $this->fetch_page_visibility($post);
}
function fetch_page_visibility($post) {
$key = self::DISABLE_FITVIDS;
$meta_key = Genesis_Club_Media::FITVIDS_DISABLE_METAKEY;
return $this->form_field($key, $key,
__('Do not show automatically resized videos on this page (i.e. disable video auto-sizing)' ),
get_post_meta($post->ID, $meta_key, true), 'checkbox', array(), array(), 'br') ;
}
function save_page_visibility($post_id) {
$key = self::DISABLE_FITVIDS;
$meta_key = Genesis_Club_Media::FITVIDS_DISABLE_METAKEY;
update_post_meta( $post_id, $meta_key, array_key_exists($key, $_POST) ? $_POST[$key] : false);
}
function save_media() {
check_admin_referer(__CLASS__);
$message='';
$page_options = explode(',', stripslashes($_POST['page_options']));
if ($page_options) {
$options = $this->media->get_options();
$updates = false;
foreach ($_FILES as $favicon) {
$file = wp_handle_upload($favicon, array( 'test_form' => false ));
if (isset($file['url']) && (strpos($file['url'],'favicon')!== FALSE)) $_POST['favicon_url'] = $file['url'];
}
if (isset($_POST['regenerate_thumbnails'])) {
unset($_POST['regenerate_thumbnails']);
$this->delete_thumbnails();
$this->add_admin_notice('Thumbnails:', 'Alt Featured Image thumbnails have been deleted', false);
}
foreach ($page_options as $option) {
$val = array_key_exists($option, $_POST) ? trim(stripslashes($_POST[$option])) : '';
if (substr($option,0,9)=='peelback_') {
$option = substr($option,9);
$options['peelback'][$option] = esc_html($val);
} elseif (substr($option,0,8)=='fitvids_') {
$option = substr($option,8);
$options['fitvids'][$option] = esc_html($val);
} else {
$options[$option] = $val;
}
} //end for
$saved = $this->media->save_options($options) ;
$message = $saved ? 'updated successfully' : 'have not been updated';
$is_error = false;
} else {
$message= ' not found!';
$is_error = true;
}
$this->add_admin_notice('Media settings ', $message, $is_error);
return $saved;
}
function add_post_panel($content, $post) {
return $content + array ('Featured Image' => $this->featured_image_panel($post)) ;
}
function featured_image_panel($post) {
$this->set_tooltips($this->post_tips);
if (($featured_image = $this->get_meta_form_data(Genesis_Club_Media::FEATURED_IMAGE_KEY, 'featured_image'))
&& ($featured_image_alt = $this->get_meta_form_data(Genesis_Club_Media::FEATURED_IMAGE_ALT_KEY, 'featured_image_alt')))
return sprintf ('<div class="diy-wrap">%1$s%2$s<p class="meta-options"><input type="hidden" name="genesis_club_featured_image" value="1" /><input type="hidden" name="genesis_club_featured_image_alt" value="1" /></p></div>',
$this->meta_form_field($featured_image, '', 'text', array(), array('class' => 'large-text')),
$this->meta_form_field($featured_image_alt, '', 'text', array(), array('class' => 'large-text')));
}
function favicon_panel($post, $metabox){
$options = $metabox['args']['options'];
$favicon_url = $this->media->favicon_url($this->media->get_default_favicon());
$favicon_img = empty($favicon_url) ? '' : sprintf('<img alt="favicon" src="%1$s" />',$favicon_url);
return $this->fetch_form_field('favicon_img', $favicon_img, 'favicon') .
$this->fetch_form_field('favicon_url', $favicon_url, 'text', array(), array('size' => 80)).
$this->fetch_form_field('favicon', $favicon_url, 'file', array(), array('size' => 80));
}
function header_image_panel($post,$metabox){
$options = $metabox['args']['options'];
return $this->fetch_form_field('header_image', $options['header_image'], 'text', array(), array('size' => 80));
}
function big_image_panel($post,$metabox){
$options = $metabox['args']['options'];
return $this->fetch_form_field('home_big_image', $options['home_big_image'], 'text', array(), array('size' => 80));
}
function thumbnails_panel($post,$metabox){
$options = $metabox['args']['options'];
return
$this->fetch_form_field('thumbnails', $options['thumbnails'], 'checkbox').
$this->fetch_form_field('thumbnail_quality', $options['thumbnail_quality'], 'text', array(), array('size' => 3)) .
$this->fetch_form_field('regenerate_thumbnails', false, 'checkbox');
}
function peelback_panel($post,$metabox){
$options = $metabox['args']['options']['peelback'];
return $this->fetch_form_field('peelback_enabled', $options['enabled'], 'checkbox').
$this->fetch_form_field('peelback_image', $options['image'], 'text', array(), array('size' => 100)) .
$this->fetch_form_field('peelback_target', $options['target'], 'text', array(), array('size' => 100)) .
$this->fetch_form_field('peelback_tracking', $options['tracking'], 'text', array(), array('size' => 20));
}
function fitvids_panel($post,$metabox){
$fitvids = $metabox['args']['options']['fitvids'];
return $this->fetch_form_field('fitvids_home', $fitvids['home'], 'checkbox') .
$this->fetch_form_field('fitvids_setting', $fitvids['setting'], 'radio',
array('none' => $this->get_tip('fitvids_none'),
'on_demand' => $this->get_tip('fitvids_on_demand'),
'all' => $this->get_tip('fitvids_all')),
array('legend' => 'Page Specific Settings'));
}
function media_panel($post,$metabox) {
$tabs = array('Favicon' => $this->favicon_panel($post,$metabox));
if (current_theme_supports('custom-header'))
$tabs['Header Background'] = $this->header_image_panel($post,$metabox);
if (defined('GENESIS_CLUB_HAS_BIG_IMAGE') || current_theme_supports('genesis-club-home-featured-image'))
$tabs['Home Page Feature'] = $this->big_image_panel($post,$metabox);
if (defined('GENESIS_CLUB_HAS_PEELBACK') || current_theme_supports('genesis-club-peelback'))
$tabs['Home Page Peelback'] = $this->peelback_panel($post,$metabox);
$tabs['Alt Featured Images'] = $this->thumbnails_panel($post,$metabox);
$tabs['Fitvids'] = $this->fitvids_panel($post,$metabox);
print $this->tabbed_metabox($metabox['id'], $tabs);
}
function save_post($post_id) {
if ( wp_is_post_revision( $post_id ) ) return;
$keys = array(
'genesis_club_featured_image' => Genesis_Club_Media::FEATURED_IMAGE_KEY,
'genesis_club_featured_image_alt' => Genesis_Club_Media::FEATURED_IMAGE_ALT_KEY);
$this->save_postmeta($post_id, $keys);
}
function delete_thumbnails() {
global $wpdb;
$delete = sprintf('DELETE FROM %1$spostmeta WHERE meta_key = \'%2$s\' ', $wpdb->prefix, Genesis_Club_Media::FEATURED_THUMBS_KEY);
$wpdb->query($delete);
}
function upgrade() {
global $wpdb;
$updated = false;
$update = sprintf('UPDATE %1$spostmeta set meta_key = \'%2$s\' where meta_key=\'genesis_club_featured_thumbs\' ', $wpdb->prefix, Genesis_Club_Media::FEATURED_THUMBS_KEY);
if ($wpdb->query($update)) $updated = true;
$update = sprintf('UPDATE %1$spostmeta set meta_key = \'%2$s\' where meta_key=\'genesis_club_featured_image\' ', $wpdb->prefix, Genesis_Club_Media::FEATURED_IMAGE_KEY);
if ($wpdb->query($update)) $updated = true;
}
function intro_panel(){
printf( '<p>The features below are concerned with manipulation of images and video and are exclusive to Genesis Club Pro members</p>');
}
}