<?php

function ndtrck_ntp_echo_portfolio_settings($post)
{
	$nt_portfolio_set_primarycolor = get_post_meta( $post->ID, 'nt-portfolio-set-primarycolor', true);
    $nt_portfolio_set_secondarycolor = get_post_meta( $post->ID, 'nt-portfolio-set-secondarycolor', true);
    $nt_portfolio_set_autoplay = get_post_meta( $post->ID, 'nt-portfolio-set-autoplay', true);
    $nt_portfolio_set_sliderskin = get_post_meta( $post->ID, 'nt-portfolio-set-sliderskin', true);
    $nt_portfolio_set_effect = get_post_meta( $post->ID, 'nt-portfolio-set-effect', true);
    $nt_portfolio_set_pauseonhover = get_post_meta( $post->ID, 'nt-portfolio-set-pauseonhover', true);
    $nt_portfolio_set_navigation = get_post_meta( $post->ID, 'nt-portfolio-set-navigation', true);
    $nt_portfolio_set_pagination = get_post_meta( $post->ID, 'nt-portfolio-set-pagination', true);
    $nt_portfolio_set_thumbnails = get_post_meta( $post->ID, 'nt-portfolio-set-thumbnails', true);
    $nt_portfolio_set_slideduration = get_post_meta( $post->ID, 'nt-portfolio-set-slideduration', true);
    $nt_portfolio_set_transduration = get_post_meta( $post->ID, 'nt-portfolio-set-transduration', true);
    $nt_portfolio_set_sliderheight = get_post_meta( $post->ID, 'nt-portfolio-set-sliderheight', true);


	?>
    <div>
    <p><span style="font-weight: 700">Tile settings for listing: </span></p>
    
    <p><span>Primary color: </span><input class="nt-portfolio-settings color-picker" name="nt-portfolio-set-primarycolor" data-alpha="true" value="<?php echo $nt_portfolio_set_primarycolor ?>"/></p>
    
    <p><span>Secondary color: </span><input class="nt-portfolio-settings color-picker" name="nt-portfolio-set-secondarycolor" data-alpha="true" value="<?php echo $nt_portfolio_set_secondarycolor ?>"/></p>
</div>
<div style="background-color: black;height:1px"></div>
<div>
    <p><span style="font-weight: 700">Slider Settings for single item:</span></p>
    
    <p><span>Slider Skin: </span><select name="nt-portfolio-set-sliderskin" form="post"><option value="camera_amber_skin" <?php if($nt_portfolio_set_sliderskin=="camera_amber_skin"){echo "selected";} ?> > amber </option><option value="camera_ash_skin" <?php if($nt_portfolio_set_sliderskin=="camera_ash_skin"){echo "selected";} ?> > ash </option><option value="camera_azure_skin" <?php if($nt_portfolio_set_sliderskin=="camera_azure_skin"){echo "selected";} ?> > azure </option><option value="camera_beige_skin" <?php if($nt_portfolio_set_sliderskin=="camera_beige_skin"){echo "selected";} ?> > beige </option><option value="camera_black_skin" <?php if($nt_portfolio_set_sliderskin=="camera_black_skin"){echo "selected";} ?> > black </option><option value="camera_blue_skin" <?php if($nt_portfolio_set_sliderskin=="camera_blue_skin"){echo "selected";} ?> > blue </option><option value="camera_brown_skin" <?php if($nt_portfolio_set_sliderskin=="camera_brown_skin"){echo "selected";} ?> > brown </option><option value="camera_burgundy_skin" <?php if($nt_portfolio_set_sliderskin=="camera_burgundy_skin"){echo "selected";} ?> > burgundy </option><option value="camera_charcoal_skin" <?php if($nt_portfolio_set_sliderskin=="camera_charcoal_skin"){echo "selected";} ?> > charcoal </option><option value="camera_chocolate_skin" <?php if($nt_portfolio_set_sliderskin=="camera_chocolate_skin"){echo "selected";} ?> > chocolate </option><option value="camera_coffee_skin" <?php if($nt_portfolio_set_sliderskin=="camera_coffee_skin"){echo "selected";} ?> > coffee </option><option value="camera_cyan_skin" <?php if($nt_portfolio_set_sliderskin=="camera_cyan_skin"){echo "selected";} ?> > cyan </option><option value="camera_fuchsia_skin" <?php if($nt_portfolio_set_sliderskin=="camera_fuchsia_skin"){echo "selected";} ?> > fuchsia </option><option value="camera_gold_skin" <?php if($nt_portfolio_set_sliderskin=="camera_gold_skin"){echo "selected";} ?> > gold </option><option value="camera_green_skin" <?php if($nt_portfolio_set_sliderskin=="camera_green_skin"){echo "selected";} ?> > green </option><option value="camera_grey_skin" <?php if($nt_portfolio_set_sliderskin=="camera_grey_skin"){echo "selected";} ?> > grey </option><option value="camera_indigo_skin" <?php if($nt_portfolio_set_sliderskin=="camera_indigo_skin"){echo "selected";} ?> > indigo </option><option value="camera_khaki_skin" <?php if($nt_portfolio_set_sliderskin=="camera_khaki_skin"){echo "selected";} ?> > khaki </option><option value="camera_lime_skin" <?php if($nt_portfolio_set_sliderskin=="camera_lime_skin"){echo "selected";} ?> > lime </option><option value="camera_magenta_skin" <?php if($nt_portfolio_set_sliderskin=="camera_magenta_skin"){echo "selected";} ?> > magenta </option><option value="camera_maroon_skin" <?php if($nt_portfolio_set_sliderskin=="camera_maroon_skin"){echo "selected";} ?> > maroon </option><option value="camera_orange_skin" <?php if($nt_portfolio_set_sliderskin=="camera_orange_skin"){echo "selected";} ?> > orange </option><option value="camera_olive_skin" <?php if($nt_portfolio_set_sliderskin=="camera_olive_skin"){echo "selected";} ?> > olive </option><option value="camera_pink_skin" <?php if($nt_portfolio_set_sliderskin=="camera_pink_skin"){echo "selected";} ?> > pink </option><option value="camera_pistachio_skin" <?php if($nt_portfolio_set_sliderskin=="camera_pistachio_skin"){echo "selected";} ?> > pistachio </option><option value="camera_pink_skin" <?php if($nt_portfolio_set_sliderskin=="camera_pink_skin"){echo "selected";} ?> > pink </option><option value="camera_red_skin" <?php if($nt_portfolio_set_sliderskin=="camera_red_skin"){echo "selected";} ?> > red </option><option value="camera_tangerine_skin" <?php if($nt_portfolio_set_sliderskin=="camera_tangerine_skin"){echo "selected";} ?> > tangerine </option><option value="camera_turquoise_skin" <?php if($nt_portfolio_set_sliderskin=="camera_turquoise_skin"){echo "selected";} ?> > turquoise </option><option value="camera_violet_skin" <?php if($nt_portfolio_set_sliderskin=="camera_violet_skin"){echo "selected";} ?> > violet </option><option value="camera_white_skin" <?php if($nt_portfolio_set_sliderskin=="camera_white_skin"){echo "selected";} ?> > white </option><option value="camera_yellow_skin" <?php if($nt_portfolio_set_sliderskin=="camera_yellow_skin"){echo "selected";} ?> > yellow </option></select></p>

    <p><span>Autoplay: </span> <input class="nt-portfolio-settings" name="nt-portfolio-set-autoplay" type="checkbox" <?php if(!empty($nt_portfolio_set_autoplay)){echo "checked";} ?>/></p>
   
    <p><span>Slider Height: </span> <input class="nt-portfolio-settings" name="nt-portfolio-set-sliderheight" type="number" min="0" max="100" value="<?php if(!empty($nt_portfolio_set_sliderheight)){echo $nt_portfolio_set_sliderheight;} ?>"/>%</p>
    
    <p><span>Transition Effect: </span><select name="nt-portfolio-set-effect" form="post"><option value="simpleFade" <?php if($nt_portfolio_set_effect=="simpleFade"){echo "selected";} ?>>simpleFade</option><option value="curtainTopLeft" <?php if($nt_portfolio_set_effect=="curtainTopLeft"){echo "selected";} ?>>curtainTopLeft</option><option value="curtainTopRight" <?php if($nt_portfolio_set_effect=="curtainTopRight"){echo "selected";} ?>>curtainTopRight</option><option value="curtainBottomLeft" <?php if($nt_portfolio_set_effect=="curtainBottomLeft"){echo "selected";} ?>>curtainBottomLeft</option><option value="curtainBottomRight" <?php if($nt_portfolio_set_effect=="curtainBottomRight"){echo "selected";} ?>>curtainBottomRight</option><option value="curtainSliceLeft" <?php if($nt_portfolio_set_effect=="curtainSliceLeft"){echo "selected";} ?>>curtainSliceLeft</option><option value="curtainSliceRight" <?php if($nt_portfolio_set_effect=="curtainSliceRight"){echo "selected";} ?>>curtainSliceRight</option><option value="blindCurtainTopLeft" <?php if($nt_portfolio_set_effect=="blindCurtainTopLeft"){echo "selected";} ?>>blindCurtainTopLeft</option><option value="blindCurtainTopRight" <?php if($nt_portfolio_set_effect=="blindCurtainTopRight"){echo "selected";} ?>>blindCurtainTopRight</option><option value="blindCurtainBottomLeft" <?php if($nt_portfolio_set_effect=="blindCurtainBottomLeft"){echo "selected";} ?>>blindCurtainBottomLeft</option><option value="blindCurtainBottomRight" <?php if($nt_portfolio_set_effect=="blindCurtainBottomRight"){echo "selected";} ?>>blindCurtainBottomRight</option><option value="blindCurtainSliceBottom" <?php if($nt_portfolio_set_effect=="blindCurtainSliceBottom"){echo "selected";} ?>>blindCurtainSliceBottom</option><option value="blindCurtainSliceTop" <?php if($nt_portfolio_set_effect=="blindCurtainSliceTop"){echo "selected";} ?>>blindCurtainSliceTop</option><option value="stampede" <?php if($nt_portfolio_set_effect=="stampede"){echo "selected";} ?>>stampede</option><option value="mosaic" <?php if($nt_portfolio_set_effect=="mosaic"){echo "selected";} ?>>mosaic</option><option value="mosaicReverse" <?php if($nt_portfolio_set_effect=="mosaicReverse"){echo "selected";} ?>>mosaicReverse</option><option value="mosaicRandom" <?php if($nt_portfolio_set_effect=="mosaicRandom"){echo "selected";} ?>>mosaicRandom</option><option value="mosaicSpiral" <?php if($nt_portfolio_set_effect=="mosaicSpiral"){echo "selected";} ?>>mosaicSpiral</option><option value="mosaicSpiralReverse" <?php if($nt_portfolio_set_effect=="mosaicSpiralReverse"){echo "selected";} ?>>mosaicSpiralReverse</option><option value="topLeftBottomRight" <?php if($nt_portfolio_set_effect=="topLeftBottomRight"){echo "selected";} ?>>topLeftBottomRight</option><option value="bottomRightTopLeft" <?php if($nt_portfolio_set_effect=="bottomRightTopLeft"){echo "selected";} ?>>bottomRightTopLeft</option><option value="bottomLeftTopRight" <?php if($nt_portfolio_set_effect=="bottomLeftTopRight"){echo "selected";} ?>>bottomLeftTopRight</option><option value="bottomLeftTopRight" <?php if($nt_portfolio_set_effect=="bottomLeftTopRight"){echo "selected";} ?>>bottomLeftTopRight</option><option value="scrollLeft" <?php if($nt_portfolio_set_effect=="scrollLeft"){echo "selected";} ?>>scrollLeft</option><option value="scrollRight" <?php if($nt_portfolio_set_effect=="scrollRight"){echo "selected";} ?>>scrollRight</option><option value="scrollHorz" <?php if($nt_portfolio_set_effect=="scrollHorz"){echo "selected";} ?>>scrollHorz</option><option value="scrollBottom" <?php if($nt_portfolio_set_effect=="scrollBottom"){echo "selected";} ?>>scrollBottom</option><option value="scrollTop" <?php if($nt_portfolio_set_effect=="scrollTop"){echo "selected";} ?>>scrollTop</option></select></p>
    
    <p><span>Pause on hover: </span> <input class="nt-portfolio-settings" name="nt-portfolio-set-pauseonhover" type="checkbox" <?php if(!empty($nt_portfolio_set_pauseonhover)){echo "checked";} ?> /></p>
    
    <p><span>Navigation: </span> <input class="nt-portfolio-settings" name="nt-portfolio-set-navigation" type="checkbox" <?php if(!empty($nt_portfolio_set_navigation)){echo "checked";} ?>/></p>
    
    <p><span>Pagination: </span> <input class="nt-portfolio-settings" name="nt-portfolio-set-pagination" type="checkbox" <?php if(!empty($nt_portfolio_set_pagination)){echo "checked";} ?>/></p>
    
    <p><span>Thumbnails: </span> <input class="nt-portfolio-settings" name="nt-portfolio-set-thumbnails" type="checkbox" <?php if(!empty($nt_portfolio_set_thumbnails)){echo "checked";} ?>/></p>
    
    <p><span>Slide Duration (ms): </span> <input class="nt-portfolio-settings" name="nt-portfolio-set-slideduration" type="number" min="0" value="<?php if(!empty($nt_portfolio_set_slideduration)){echo $nt_portfolio_set_slideduration;} ?>"/></p>
    
    <p><span>Transition Duration: </span> <input class="nt-portfolio-settings" name="nt-portfolio-set-transduration" type="number" min="0" value="<?php if(!empty($nt_portfolio_set_transduration)){echo $nt_portfolio_set_transduration;} ?>"/></p>
</div>
	<?php
}

function ndtrck_ntp_save_portfolio_meta($post_id)
{
	 if(get_post_type($post_id)!="nt_portfolio")
        return;

    delete_post_meta($post_id, 'nt-portfolio-image');

    if(array_key_exists('nt-portfolio-image', $_POST))
    {
        $filtered = array_map("absint", $_POST['nt-portfolio-image']);
        foreach ($filtered as $value) {
            if(!is_null($value) && $value != 0)
                add_post_meta($post_id, 'nt-portfolio-image', $value);
        }
    }

    delete_post_meta($post_id, 'nt-portfolio-link');
    if(array_key_exists('nt-portfolio-link', $_POST))
    {
        add_post_meta($post_id, 'nt-portfolio-link',esc_url_raw(  $_POST['nt-portfolio-link'] ),  true);
    }

    delete_post_meta($post_id, 'nt-portfolio-linktext');
    if(array_key_exists('nt-portfolio-linktext', $_POST))
    {
        add_post_meta($post_id, 'nt-portfolio-linktext', sanitize_text_field($_POST['nt-portfolio-linktext']),  true);
    }

    delete_post_meta($post_id, 'nt-portfolio-subtitle');
    if(array_key_exists('nt-portfolio-subtitle', $_POST))
    {
        add_post_meta($post_id, 'nt-portfolio-subtitle', sanitize_text_field($_POST['nt-portfolio-subtitle']),  true);
    }

    //----------------------------------------

    delete_post_meta($post_id, 'nt-portfolio-set-primarycolor');
    if(array_key_exists('nt-portfolio-set-primarycolor',$_POST))
    {
        add_post_meta($post_id, 'nt-portfolio-set-primarycolor', sanitize_text_field($_POST['nt-portfolio-set-primarycolor']), true);
    }

     delete_post_meta($post_id, 'nt-portfolio-set-secondarycolor');
    if(array_key_exists('nt-portfolio-set-secondarycolor',$_POST))
    {
        add_post_meta($post_id, 'nt-portfolio-set-secondarycolor', sanitize_text_field($_POST['nt-portfolio-set-secondarycolor']), true);
    }

    delete_post_meta($post_id, 'nt-portfolio-set-autoplay');
    if(array_key_exists('nt-portfolio-set-autoplay',$_POST))
    {
        add_post_meta($post_id, 'nt-portfolio-set-autoplay', sanitize_text_field($_POST['nt-portfolio-set-autoplay']), true);
    }

     delete_post_meta($post_id, 'nt-portfolio-set-sliderskin');
    if(array_key_exists('nt-portfolio-set-sliderskin',$_POST))
    {
        add_post_meta($post_id, 'nt-portfolio-set-sliderskin', sanitize_text_field($_POST['nt-portfolio-set-sliderskin']), true);
    }


    delete_post_meta($post_id, 'nt-portfolio-set-effect');
    if(array_key_exists('nt-portfolio-set-effect',$_POST))
    {
        add_post_meta($post_id, 'nt-portfolio-set-effect', sanitize_text_field($_POST['nt-portfolio-set-effect']), true);
    }

    delete_post_meta($post_id, 'nt-portfolio-set-pauseonhover');
    if(array_key_exists('nt-portfolio-set-pauseonhover',$_POST))
    {
        add_post_meta($post_id, 'nt-portfolio-set-pauseonhover', sanitize_text_field($_POST['nt-portfolio-set-pauseonhover']), true);
    }


    delete_post_meta($post_id, 'nt-portfolio-set-navigation');
    if(array_key_exists('nt-portfolio-set-navigation',$_POST))
    {
        add_post_meta($post_id, 'nt-portfolio-set-navigation', sanitize_text_field($_POST['nt-portfolio-set-navigation']), true);
    }

    delete_post_meta($post_id, 'nt-portfolio-set-pagination');
    if(array_key_exists('nt-portfolio-set-pagination',$_POST))
    {
        add_post_meta($post_id, 'nt-portfolio-set-pagination', sanitize_text_field($_POST['nt-portfolio-set-pagination']), true);
    }

    delete_post_meta($post_id, 'nt-portfolio-set-thumbnails');
    if(array_key_exists('nt-portfolio-set-thumbnails',$_POST))
    {
        add_post_meta($post_id, 'nt-portfolio-set-thumbnails', sanitize_text_field($_POST['nt-portfolio-set-thumbnails']), true);
    }

    delete_post_meta($post_id, 'nt-portfolio-set-slideduration');
    if(array_key_exists('nt-portfolio-set-slideduration',$_POST))
    {
        add_post_meta($post_id, 'nt-portfolio-set-slideduration', absint($_POST['nt-portfolio-set-slideduration']), true);
    }

    delete_post_meta($post_id, 'nt-portfolio-set-transduration');
    if(array_key_exists('nt-portfolio-set-transduration',$_POST))
    {
        add_post_meta($post_id, 'nt-portfolio-set-transduration', absint($_POST['nt-portfolio-set-transduration']), true);
    }

    delete_post_meta($post_id, 'nt-portfolio-set-sliderheight');
    if(array_key_exists('nt-portfolio-set-sliderheight',$_POST))
    {
        add_post_meta($post_id, 'nt-portfolio-set-sliderheight', floatval($_POST['nt-portfolio-set-sliderheight']), true);
    }

}


function ndtrck_ntp_get_portfolio_options($post)
{
	$nt_portfolio_set_autoplay = get_post_meta( $post->ID, 'nt-portfolio-set-autoplay', true);
    $nt_portfolio_set_sliderskin = get_post_meta( $post->ID, 'nt-portfolio-set-sliderskin', true);
    $nt_portfolio_set_barpos = get_post_meta( $post->ID, 'nt-portfolio-set-barpos', true);
    $nt_portfolio_set_effect = get_post_meta( $post->ID, 'nt-portfolio-set-effect', true);
    $nt_portfolio_set_pauseonhover = get_post_meta( $post->ID, 'nt-portfolio-set-pauseonhover', true);
    
    $nt_portfolio_set_navigation = get_post_meta( $post->ID, 'nt-portfolio-set-navigation', true);
    $nt_portfolio_set_pagination = get_post_meta( $post->ID, 'nt-portfolio-set-pagination', true);
    $nt_portfolio_set_thumbnails = get_post_meta( $post->ID, 'nt-portfolio-set-thumbnails', true);
    $nt_portfolio_set_slideduration = get_post_meta( $post->ID, 'nt-portfolio-set-slideduration', true);
    $nt_portfolio_set_transduration = get_post_meta( $post->ID, 'nt-portfolio-set-transduration', true);
    $nt_portfolio_set_sliderheight = get_post_meta( $post->ID, 'nt-portfolio-set-sliderheight', true);

    $options = array("fx"=>$nt_portfolio_set_effect, 
        "hover"=>!empty($nt_portfolio_set_pauseonhover)? true : false, 
        "autoAdvance"=> !empty($nt_portfolio_set_autoplay)? true : false,
        "mobileAutoAdvance" => !empty($nt_portfolio_set_autoplay)? true : false,
        "navigation"=>!empty($nt_portfolio_set_navigation)? true : false, 
        "playPause" =>!empty($nt_portfolio_set_navigation)? true : false,
        "pagination"=>!empty($nt_portfolio_set_pagination)? true : false, 
        "thumbnails"=>!empty($nt_portfolio_set_thumbnails)? true : false, 
        "time" => $nt_portfolio_set_slideduration,
        "transPeriod" => $nt_portfolio_set_transduration,
        "height"=> $nt_portfolio_set_sliderheight."%",
        "loader"=>"none",
        "sliderSkin" => $nt_portfolio_set_sliderskin);

    return $options;
}



?>