'[aesop_gallery id="'.$post_ID.'"', 'post_type' => array ( 'page', 'post' ) ) );
$count = 0;
if ( $pages ) :
foreach ( $pages as $page ) {
$count ++;
if ( has_shortcode( $page->post_content , 'aesop_gallery' ) ) {
echo ''.$page->post_title.' ';
if ( $count != count( $pages ) ) {
echo ', ';
}
}
}
endif;
}//end if
}
/**
* Load the assets that we need for the gallery meta
*
* @since 1.4
*/
public function gallery_box_assets() {
if ( 'ai_galleries' == get_current_screen()->id ) {
wp_enqueue_script( 'jquery-ui-sortable' );
}
}
/**
* New metabox to better manage images within galleries
*
* @since 1.4
*/
public function new_gallery_box() {
// images
add_meta_box( 'ase_gallery_component', __( 'Add Images', 'aesop-core' ), array( $this, 'render_gallery_box' ), 'ai_galleries', 'normal', 'core' );
// layout
add_meta_box( 'ase_gallery_layout', __( 'Select Layout', 'aesop-core' ), array( $this, 'render_layout_box' ), 'ai_galleries', 'normal', 'core' );
// global options
add_meta_box( 'ase_gallery_options', __( 'Set Options', 'aesop-core' ), array( $this, 'render_options_box' ), 'ai_galleries', 'normal', 'core' );
}
/**
* Render meta box used for the gallery
*
* @param WP_Post $post The post object.
* @since 1.4
*
*/
public function render_gallery_box( $post ) {
echo '
';
wp_nonce_field( 'ase_gallery_meta', 'ase_gallery_meta_nonce' );
echo '
';
// get the existing images for this post prior to 1.4, else get the IDs set into post meta for 1.4
if ( AI_CORE_VERSION < 1.4 ) {
$get_image_ids = get_post_gallery( $post->ID, false );
$image_ids = explode( ',', $get_image_ids['ids'] );
} else {
$get_image_ids = get_post_meta( $post->ID, '_ase_gallery_images', true );
$image_ids = explode( ',', $get_image_ids );
}
echo 'Add Images ';
echo '';
if ( ! empty( $get_image_ids ) ):
foreach ( $image_ids as $image_id ):
$image = wp_get_attachment_image_src( $image_id, 'thumbnail', false );
?>
';
echo ' ';
}
/**
* Draw the metabox used to pick the layout of the gallery
*
* @param WP_Post $post The post object.
* @since 1.4
*/
public function render_layout_box( $post ) {
$type = get_post_meta( $post->ID, 'aesop_gallery_type', true );
?>
>
>
>Sequence
>
>
>
ID;
// global
$width = get_post_meta( $id, 'aesop_gallery_width', true );
$caption = get_post_meta( $id, 'aesop_gallery_caption', true );
// grid
$grid_item_width = get_post_meta( $id, 'aesop_grid_gallery_width', true );
$aesop_lightbox_text = get_post_meta( $id, 'aesop_lightbox_text', true );
// thumbnail
$thumb_trans = get_post_meta( $id, 'aesop_thumb_gallery_transition', true );
$thumb_speed = get_post_meta( $id, 'aesop_thumb_gallery_transition_speed', true );
$thumb_hide = get_post_meta( $id, 'aesop_thumb_gallery_hide_thumbs', true );
//sequence
$sequence_panorama = get_post_meta( $id, 'aesop_sequence_gallery_panorama', true );
$sequence_panorama_height = get_post_meta( $id, 'aesop_sequence_gallery_panorama_height', true ) ;
$sequence_panorama_height = $sequence_panorama_height ? $sequence_panorama_height: 500;
// photoset
$photoset_layout = get_post_meta( $id, 'aesop_photoset_gallery_layout', true );
$photoset_lb = get_post_meta( $id, 'aesop_photoset_gallery_lightbox', true );
//parallax
$parallax_mobile_panorama = get_post_meta( $id, 'aesop_parallax_gallery_mobile_panorama', true );
//hero
$hero_content = get_post_meta( $id, 'aesop_hero_gallery_content', true );
$hero_width_to_height_ratio = get_post_meta( $id, 'aesop_hero_gallery_height', true );
$hero_trans = get_post_meta( $id, 'aesop_hero_gallery_transition', true );
// if hero option is not set use the thumb gallery option
$hero_trans = $hero_trans ? $hero_trans: $thumb_trans;
$hero_speed = get_post_meta( $id, 'aesop_hero_gallery_transition_speed', true );
$hero_speed = $hero_speed ? $hero_speed: $thumb_speed;
$hero_anim_speed = get_post_meta( $id, 'aesop_hero_gallery_transition_anim_speed', true );
$hero_anim_speed = $hero_anim_speed ? $hero_anim_speed: 1500;
$hero_enable_nav = get_post_meta( $id, 'aesop_hero_gallery_enable_nav', true );
$aesop_hero_image_text = get_post_meta( $id, 'aesop_hero_image_text', true );
?>
post_type ) {
return $post_id; }
// gallery ids
$gallery_ids = isset( $_POST['ase_gallery_ids'] ) ? urldecode( $_POST['ase_gallery_ids'] ) : false;
$type = isset( $_POST['aesop_gallery_type'] ) ? $_POST['aesop_gallery_type'] : 'grid';
// global
$width = isset( $_POST['aesop_gallery_width'] ) ? $_POST['aesop_gallery_width'] : false;
$caption = isset( $_POST['aesop_gallery_caption'] ) ? $_POST['aesop_gallery_caption'] : false;
// grid
$grid_item_width = isset( $_POST['aesop_grid_gallery_width'] ) ? $_POST['aesop_grid_gallery_width'] : false;
$aesop_lightbox_text = isset( $_POST['aesop_lightbox_text'] ) ? $_POST['aesop_lightbox_text'] : false;
// thumbnail
$thumb_trans = isset( $_POST['aesop_thumb_gallery_transition'] ) ? $_POST['aesop_thumb_gallery_transition'] : false;
$thumb_speed = isset( $_POST['aesop_thumb_gallery_transition_speed'] ) ? $_POST['aesop_thumb_gallery_transition_speed'] : false;
$thumb_hide = isset( $_POST['aesop_thumb_gallery_hide_thumbs'] ) ? $_POST['aesop_thumb_gallery_hide_thumbs'] : false;
// sequence
$sequence_panorama = isset( $_POST['aesop_sequence_gallery_panorama'] ) ? $_POST['aesop_sequence_gallery_panorama'] : false;
$sequence_panorama_height = isset( $_POST['aesop_sequence_gallery_panorama_height'] ) ? $_POST['aesop_sequence_gallery_panorama_height'] : false;
// photoset
$photoset_layout = isset( $_POST['aesop_photoset_gallery_layout'] ) ? $_POST['aesop_photoset_gallery_layout'] : false;
$photoset_lb = isset( $_POST['aesop_photoset_gallery_lightbox'] ) ? $_POST['aesop_photoset_gallery_lightbox'] : false;
// parallax
$parallax_mobile_panorama = isset( $_POST['aesop_parallax_gallery_mobile_panorama'] ) ? $_POST['aesop_parallax_gallery_mobile_panorama'] : false;
// hero
$hero_content = isset( $_POST['aesop_hero_gallery_content'] ) ? $_POST['aesop_hero_gallery_content'] : false;
$hero_width_to_height_ratio = isset( $_POST['aesop_hero_gallery_height'] ) ? $_POST['aesop_hero_gallery_height'] : false;
$hero_speed = isset( $_POST['aesop_hero_gallery_transition_speed'] ) ? $_POST['aesop_hero_gallery_transition_speed'] : false;
$hero_anim_speed = isset( $_POST['aesop_hero_gallery_transition_anim_speed'] ) ? $_POST['aesop_hero_gallery_transition_anim_speed'] : false;
$hero_trans = isset( $_POST['aesop_hero_gallery_transition'] ) ? $_POST['aesop_hero_gallery_transition'] : false;
$hero_enable_nav = isset( $_POST['aesop_hero_gallery_enable_nav'] ) ? $_POST['aesop_hero_gallery_enable_nav'] : false;
$aesop_hero_image_text = isset( $_POST['aesop_hero_image_text'] ) ? $_POST['aesop_hero_image_text'] : 'none';
// safe to proceed
delete_post_meta( $post_id, '_ase_gallery_images' );
// gallery ids
update_post_meta( $post_id, '_ase_gallery_images', $gallery_ids );
// update gallery type
update_post_meta( $post_id, 'aesop_gallery_type', sanitize_text_field( trim( $type ) ) );
// global
update_post_meta( $post_id, 'aesop_gallery_width', sanitize_text_field( $width ) );
update_post_meta( $post_id, 'aesop_gallery_caption', sanitize_text_field( $caption ) );
// grid
update_post_meta( $post_id, 'aesop_grid_gallery_width', absint( $grid_item_width ) );
update_post_meta( $post_id, 'aesop_lightbox_text', $aesop_lightbox_text );
// thumbnail
update_post_meta( $post_id, 'aesop_thumb_gallery_transition', sanitize_text_field( $thumb_trans ) );
update_post_meta( $post_id, 'aesop_thumb_gallery_transition_speed', absint( $thumb_speed ) );
update_post_meta( $post_id, 'aesop_thumb_gallery_hide_thumbs', $thumb_hide );
// sequence
update_post_meta( $post_id, 'aesop_sequence_gallery_panorama', $sequence_panorama );
update_post_meta( $post_id, 'aesop_sequence_gallery_panorama_height', $sequence_panorama_height );
// photoset
update_post_meta( $post_id, 'aesop_photoset_gallery_layout', absint( $photoset_layout ) );
update_post_meta( $post_id, 'aesop_photoset_gallery_lightbox', $photoset_lb );
// parallax
update_post_meta( $post_id, 'aesop_parallax_gallery_mobile_panorama', $parallax_mobile_panorama );
// hero width_to_height_ratio
update_post_meta( $post_id, 'aesop_hero_gallery_content', aesop_component_media_filter( $hero_content ) );
update_post_meta( $post_id, 'aesop_hero_gallery_height', sanitize_text_field($hero_width_to_height_ratio) );
update_post_meta( $post_id, 'aesop_hero_gallery_transition_speed', absint( $hero_speed ) );
update_post_meta( $post_id, 'aesop_hero_gallery_transition_anim_speed', absint( $hero_anim_speed ) );
update_post_meta( $post_id, 'aesop_hero_gallery_transition', sanitize_text_field( $hero_trans ) );
update_post_meta( $post_id, 'aesop_hero_gallery_enable_nav', sanitize_text_field( $hero_enable_nav ) );
update_post_meta( $post_id, 'aesop_hero_image_text', $aesop_hero_image_text );
}
/**
* Map the old galleries to post meta
*
* @since 1.4
*/
public function upgrade_galleries_notice() {
// only run if we have markers and have never upgraded
if ( ! get_option( 'ase_galleries_upgraded_to' ) && 'true' == self::aesop_check_for_galleries() && current_user_can('manage_options') ) {
$out = '';
echo $out;
}
}
/**
* When the user starts the upgrade process let's run a function to map the old gallery ids to psot meta
*
* @since 1.4
*/
public function upgrade_galleries() {
check_ajax_referer( 'aesop-galleries-upgrade', 'security' );
if ( ! current_user_can( 'manage_options' ) ) {
return;
}
// get the posts with the maps shortode
$posts = get_posts( array( 'post_type' => array( 'ai_galleries' ), 'posts_per_page' => -1 ) );
if ( $posts ) :
foreach ( $posts as $post ) {
$id = $post->ID;
$old_image_ids = get_post_gallery( $id, false );
$old_image_ids = $old_image_ids['ids'];
if ( ! empty ( $old_image_ids ) ) {
add_post_meta( $id, '_ase_gallery_images', $old_image_ids );
}
}
endif;
update_option( 'ase_galleries_upgraded_to', AI_CORE_VERSION );
echo __( 'All done!', 'aesop-core' );
exit;
}
/**
* Handles the click function for upgrading the old gallery ids to post meta
*
* @since 1.3
*/
public function upgrade_click_handle() {
$nonce = wp_create_nonce( 'aesop-galleries-upgrade' );
// only run if we have galleries and haven't yet upgraded
if ( get_option( 'ase_galleries_upgraded_to' ) < AI_CORE_VERSION && 'true' == self::aesop_check_for_galleries() ) { ?>
array( 'ai_galleries' ) ) );
if ( $galleries ) :
$return = 'true';
else :
$return = 'false';
endif;
return $return;
}
}
new AesopGalleryComponentAdmin;