<?php if(! defined('ABSPATH')){ return; }
/**
 * Displays the layout for the post type PORTFOLIO, inside page.php
 * @internal
 * @see page-content-template.inc.php
 */

$affix = 'affixcontent';
$zn_sp_show_affix = get_post_meta( get_the_ID(), 'zn_sp_show_affix', true );

if(isset($zn_sp_show_affix) && $zn_sp_show_affix == 'no') {
	$affix = '';
}

?>
<div class="row hg-portfolio-item">

	<div class="col-sm-12 col-md-5">
		<div class="portfolio-item-content <?php echo $affix; ?>" >
			<?php

			// TITLE CHECK
			$title_show = get_post_meta( get_the_ID(), 'zn_page_title_show', true );
			if ( $title_show == 'yes' ) {
				echo '<h1 class="page-title portfolio-item-title">' . get_the_title() . '</h1>';
			}
			?>

			<?php if ( $post->post_content !== "" ) { ?>
			<div class="portfolio-item-desc">
				<div class="portfolio-item-desc-inner" data-collapse-at="150">
					<?php
					// The content
					the_content( '' );
					?>
				</div>
				<a href="#" class="portfolio-item-more-toggle js-toggle-class" data-target=".portfolio-item-desc" data-target-class="is-opened" data-more-text="<?php echo esc_attr( __( "see more", 'zn_framework' ) ) ?>" data-less-text="<?php echo esc_attr( __( "show less", 'zn_framework' ) ) ?>"><span class="glyphicon glyphicon-menu-down"></span> </a>
			</div>
			<?php } ?>

			<?php
			// Item Links
			$zn_sp_client = get_post_meta( get_the_ID(), 'zn_sp_client', true );
			$zn_sp_year = get_post_meta( get_the_ID(), 'zn_sp_year', true );
			$zn_sp_services = get_post_meta( get_the_ID(), 'zn_sp_services', true );
			$sp_col = get_post_meta( get_the_ID(), 'zn_sp_col', true );


			if ( ! empty ( $zn_sp_client ) || ! empty ( $zn_sp_year ) || ! empty ( $zn_sp_services ) || ! empty ( $sp_col ) ) {

				echo '<ul class="portfolio-item-details clearfix">';

					if ( ! empty ( $zn_sp_client ) ) {
						echo '
						<li class="portfolio-item-details-client clearfix">
							<span class="portfolio-item-details-label">' . __( "CLIENT ", 'zn_framework' ) . '</span>
							<span class="portfolio-item-details-item">' . $zn_sp_client . '</span>
						</li>';
					}

					if ( ! empty ( $zn_sp_year ) ) {
						echo '
						<li class="portfolio-item-details-year clearfix">
							<span class="portfolio-item-details-label">' . __( "YEAR ", 'zn_framework' ) . '</span>
							<span class="portfolio-item-details-item">' . $zn_sp_year . '</span>
						</li>';
					}

					if ( ! empty ( $zn_sp_services ) ) {
						echo '
						<li class="portfolio-item-details-services clearfix">
							<span class="portfolio-item-details-label">' . __( "WE DID ", 'zn_framework' ) . '</span>
							<span class="portfolio-item-details-item">' . $zn_sp_services . '</span>
						</li>';
					}

					if ( ! empty ( $sp_col ) ) {
						echo '
						<li class="portfolio-item-details-partners clearfix">
							<span class="portfolio-item-details-label">' . __( "PARTNERS ", 'zn_framework' ) . '</span>
							<span class="portfolio-item-details-item">' . $sp_col . '</span>
						</li>';
					}

					echo '
					<li class="portfolio-item-details-cat clearfix">
						<span class="portfolio-item-details-label">' . __( "CATEGORY ", 'zn_framework' ) . '</span>
						<span class="portfolio-item-details-item">' . get_the_term_list( get_the_ID(), 'project_category', '', ' , ', '' ) . '</span>
					</li>';

				echo '</ul>';
			}
			?>

			<div class="portfolio-item-otherdetails clearfix">
				<?php

				// Social Sharing
				$sp_show_social = get_post_meta( get_the_ID(), 'zn_sp_show_social', true );
				if ( ! empty ( $sp_show_social ) && $sp_show_social == 'yes' ) {
					?>
					<div class="portfolio-item-share clearfix" data-share-title="SHARE:">
					<?php

						$encoded_url = urlencode( get_permalink() );
						$share_text = htmlspecialchars( urlencode( __( "Check out - ", 'zn_framework' ) . get_the_title() ), ENT_COMPAT, 'UTF-8');

						$mail_subject = htmlspecialchars( __( "Check out this awesome project: ", 'zn_framework' ) .get_the_title() );
						$mail_body = htmlspecialchars( __( "You can see it live here ", 'zn_framework' ) .$encoded_url.'%3Futm_source%3Dsharemail .'."\n\n". __( " Made by ", 'zn_framework' ) . get_bloginfo() . ' ' . get_site_url() );

						$socialicons = array();
						$socialicons['twitter'] = array(
							'url' => 'https://twitter.com/intent/tweet?text='.$share_text.'&amp;url='.$encoded_url.'%3Futm_source%3Dsharetw',
							'icon' => array('family' => 'kl-social-icons', 'unicode' => 'ue82f')
						);
						$socialicons['facebook'] = array(
							'url' => 'https://www.facebook.com/sharer/sharer.php?display=popup&amp;u='.$encoded_url.'%3Futm_source%3Dsharefb',
							'icon' => array('family' => 'kl-social-icons', 'unicode' => 'ue83f')
						);
						$socialicons['gplus'] = array(
							'url' => 'https://plus.google.com/share?url='.$encoded_url.'%3Futm_source%3Dsharegp',
							'icon' => array('family' => 'kl-social-icons', 'unicode' => 'ue808')
						);
						$socialicons['pinterest'] = array(
							'url' => 'http://pinterest.com/pin/create/button?description='.$share_text.'&amp;url='.$encoded_url.'%3Futm_source%3Dsharepi',
							'icon' => array('family' => 'kl-social-icons', 'unicode' => 'ue80e')
						);
						$socialicons['mail'] = array(
							'url' => 'mailto:?body='.$mail_body.'&amp;subject='.$mail_subject,
							'icon' => array('family' => 'kl-social-icons', 'unicode' => 'ue836')
						);

						foreach ($socialicons as $key => $value) {
							echo '<a href="'.$value['url'].'" title="' . __( "SHARE ON", 'zn_framework' ) . ' '.strtoupper($key).'" class=" portfolio-item-share-'.$key.'">';
							echo '<span '. zn_generate_icon( $value['icon'] ) .'></span>';
							echo '</a>';
						}

					?>

					</div><!-- social links -->
				<?php
				}

				$sp_link = get_post_meta( get_the_ID(), 'zn_sp_link', true );
				if ( ! empty ( $sp_link['url'] ) ) {
					echo '
					<div class="portfolio-item-livelink">
						<a class="btn btn-lined lined-custom" href="' . $sp_link['url'] . '" target="' . $sp_link['target'] . '" >
							<span class="visible-sm visible-xs visible-lg">' . __( "PROJECT LIVE PREVIEW", 'zn_framework' ) . '</span>
							<span class="visible-md">' . __( "PREVIEW", 'zn_framework' ) . '</span>
						</a>
					</div>';
				}
				?>

			</div><!-- /.portfolio-item-otherdetails -->

		</div><!-- /.portfolio-item-content -->
	</div>

	<div class="col-sm-12 col-md-7">
		<div class="img-full portfolio-item-right mfp-gallery mfp-gallery--misc">
			<?php

			$images_width = 700;

			$port_media = get_post_meta( get_the_ID(), 'zn_port_media', true );
			if ( ! empty ( $port_media ) && is_array( $port_media ) ) {

				$all_media = count( $port_media );
				$has_image = false;
				$saved_image = '';

				// Modified portfolio display
				// Check to see if we have images
				if ( $portfolio_image = $port_media[0]['port_media_image_comb'] ) {

					if ( is_array( $portfolio_image ) ) {

						if ( $saved_image = $portfolio_image['image'] ) {
							if ( ! empty( $portfolio_image['alt'] ) ) {
								$saved_alt = $portfolio_image['alt'];
							}
							else {
								$saved_alt = '';
							}

							if ( ! empty( $portfolio_image['title'] ) ) {
								$saved_title = 'title="' . $portfolio_image['title'] . '"';
							}
							else {
								$saved_title = '';
							}

							$has_image = true;
						}
					}
					else {
						$saved_image = $portfolio_image;
						$has_image   = true;
						$saved_alt   = '';
						$saved_title = '';
					}

					if ( $has_image ) {
						$image = vt_resize( '', $saved_image, $images_width, '', true );
					}
				}

				// Check to see if we have video
				if ( $portfolio_media = $port_media[0]['port_media_video_comb'] ) {
				}

				// Display the media
				if ( ! empty( $saved_image ) && $portfolio_media ) {
					echo '<a href="' . $portfolio_media . '" data-lightbox="mfp" data-mfp="iframe" class="hoverBorder">';
					echo '<img src="' . $image['url'] . '" alt="' . $saved_alt . '" ' . $saved_title . ' class="img-responsive" />';
					echo '</a>';
				}
				elseif ( ! empty( $saved_image ) ) {
					echo '<a href="' . $saved_image . '" data-lightbox="mfp" data-mfp="image" class="hoverBorder">';
					echo '<img src="' . $image['url'] . '" alt="' . $saved_alt . '" ' . $saved_title . ' class="img-responsive" />';
					echo '</a>';
				}
				elseif ( $portfolio_media ) {
					echo '<div class="embed-responsive embed-responsive-16by9">';
						echo get_video_from_link( $portfolio_media, 'embed-responsive-item', '100%', '100%' );
					echo '</div>';
				}

				unset( $port_media[0] );
			}

			// Other
			if ( ! empty ( $port_media ) && is_array( $port_media ) ) {
				echo '<div class="zn_other_images portfolio-item-extraimages">';

				foreach ( $port_media as $media ) {
					$has_image = false;
					$extra_saved_image = '';
					// Modified portfolio display
					// Check to see if we have images
					if ( $portfolio_image = $media['port_media_image_comb'] ) {

						if ( is_array( $portfolio_image ) ) {

							if ( $extra_saved_image = $portfolio_image['image'] ) {

								if ( ! empty( $portfolio_image['alt'] ) ) {
									$saved_alt = $portfolio_image['alt'];
								}
								else {
									$saved_alt = '';
								}

								if ( ! empty( $portfolio_image['title'] ) ) {
									$saved_title = 'title="' . $portfolio_image['title'] . '"';
								}
								else {
									$saved_title = '';
								}

								$has_image = true;
							}
						}
						else {
							$extra_saved_image = $portfolio_image;
							$has_image   = true;
							$saved_alt   = '';
							$saved_title = '';
						}

						if ( $has_image ) {
							$image = vt_resize( '', $extra_saved_image, $images_width, '', true );
						}
					} // END PORTFOLIO IMAGE

					// Check to see if we have video
					if ( $portfolio_media = $media['port_media_video_comb'] ) {
					}

					// Display the media
					if ( ! empty( $extra_saved_image ) && $portfolio_media ) {
						echo '<div class="portfolio-item-extraimg">';
						echo '<a href="' . $portfolio_media . '" data-lightbox="mfp" data-mfp="iframe" class="hoverBorder">';
						echo '<img src="' . $image['url'] . '" alt="' . $saved_alt . '" ' . $saved_title . ' class="img-responsive"/>';
						echo '</a>';
						echo '</div>';
					}
					elseif ( ! empty( $extra_saved_image ) ) {
						echo '<div class="portfolio-item-extraimg">';
						echo '<a href="' . $extra_saved_image . '" data-lightbox="mfp" data-mfp="image" class="hoverBorder">';
						echo '<img src="' . $image['url'] . '" alt="' . $saved_alt . '" ' . $saved_title . ' class="img-responsive"/>';
						echo '</a>';
						echo '</div>';
					}
					elseif ( $portfolio_media ) {
						echo '<div class="portfolio-item-extraimg">';
						echo '<div class="embed-responsive embed-responsive-16by9">';
							echo get_video_from_link( $portfolio_media, 'embed-responsive-item', '100%', '100%' );
						echo '</div>';
						echo '</div>';
					}
				}
				echo '<div class="clearfix"></div>';
				echo '</div>';
			}
			?>

		</div>
	</div>
	<!-- right side -->

	<div class="clearfix"></div>

</div><!-- end Portfolio page -->
