<?php
class htmlBasePrinter implements htmlPrinterInterface {
	
	private function _mainImageStd( $width ) {
		$height = null;
		$imageUrl = ffGalleryCollection::getGallery()->getFeaturedImage();
		
		if( empty( $imageUrl ) ) return false;
		
		echo '<a href="'.get_permalink().'" >';
		echo 	'<img src="'. $imageUrl->image->resize($width, $height, true).'" alt="'.get_the_title().'"/>';
		echo '</a>';
	}
	
	private function _mainImageLightbox( $width ) {
		$height = null;
		
		$imageUrl = ffGalleryCollection::getGallery()->getFeaturedImage();
		
		if( empty( $imageUrl ) ) return false;
		
		$lightboxCode = 'rel="prettyPhoto[Gallery]" title="Gallery"';
		
		echo '<a href="'.$imageUrl->image->url.'" '.$lightboxCode.' >';
		echo 	'<img src="'. $imageUrl->image->resize($width, $height, true).'" alt="'.get_the_title().'"/>';
		echo '</a>';
	}
	
	public function mainImage( $width ) {
		$type = metaBoxManager::getMeta('featured_image_type');
		
		switch( $type ) { 
			case 'std':
				$this->_mainImageStd( $width ); 
				break;
			case 'lightbox':
				$this->_mainImageLightbox( $width );
				break;
			case 'video':
				$this->_mainImageVideo( $width );
				break;
		}
		
		
	}
	
	private function _mainImageVideo( $width ) {
		$height = $width * 0.56;
		$mediaInserter  = new ffMediaInserter();
		$videoLink = metaBoxManager::getMeta('featured_image_video_link');
		
		$src = $mediaInserter->getIframeSource( $videoLink );
		
		echo '<div class="video-wrapper" style="width:'.$width.'px;">';
		echo '<iframe src="'.$src.'" style="width:'.$width.'px;height:'.$height.'px;">';
		echo '</iframe>';
		echo '</div>';
		
		
	}
	
	public function titlePortfolio() {
		$showTitle = true;
		if( !$showTitle ) return;
	
		echo '<div class="title_holder">';
        	$this->title( $showComments = false );
        echo '</div><!--  END "title_holder"  //-->';
	}
	public function title( $showComments = true ) {
		
		echo '<h1>';
		echo '<a href="'.get_permalink().'" class="title">'.get_the_title().'</a>';
		if( $showComments && comments_open() ) $this->commentsBubble();
		echo '</h1>';
	}
	
	public function commentsBubble() {
		global $post;
		if ( ! isset($post->comment_count) )
			$count = 0;
		else
			$count = $post->comment_count;
		
		echo '<a href="'.get_permalink().'#respond" class="comment_counter"  title="'.get_the_title().'">'.$count.'</a>';
	}
	public function meta() {
 		$posted_in = fOpt::Get('translation', 'post-posted-in');
 		if( fEnv::getCategoryOption('postmeta_category') != 1 ) return;
 		echo '<h3>';
 			echo $posted_in; 
 			echo ' <span>';
 				the_category(', ');
 			echo '</span>';
 		echo '</h3>'; 
	}

	public function printGalleryPage( $fullwidth = false ) {
		( $fullwidth == true ) ? $gallery_id = 'gallery_fullwidth' : $gallery_id = 'gallery';
		
		$gallery = ffGalleryCollection::getGallery();
		$gallery->loadGalleryFromMeta('gallery_slider');
		
		if( $gallery->getNumberOfImages() > 0 ) {
			echo '<div id="'.$gallery_id.'">';
				foreach($gallery as $oneImage )
				{
					echo '<a alt="'.$oneImage->altText.'" title="'.$oneImage->title.'" rel="prettyPhoto[Gallery]" href="'.$oneImage->image->url.'" class="gallery_link">';
						echo  '<img src="'.$oneImage->image->resize(123,123, 1).'" class="gallery_thumb" alt=""/>';
					echo '</a>';
				}
				echo '<div class="clear"></div>';
			echo '</div><!--  END "gallery"  //-->';
		}
	}
	
	public function content() {
		global $post;
		$readMore = fOpt::Get('translation', 'post-button-readmore');
		if(!empty($post->post_excerpt) && !is_singular() ) {
			
			the_excerpt( $readMore );
			echo '<a href="'.get_permalink().'" class="more-link">'.$readMore.'</a>';
		}
		else
		{
			the_content($readMore);
		}
		
		
	}
	private function _prepareDate() {
		$dateUnsepared = get_the_date('d,M,Y,');
		$dateSepared = explode(',', $dateUnsepared);
		
		$dateReturn['day'] = $dateSepared[0];
		$dateReturn['month'] = $dateSepared[1];
		$dateReturn['year'] = $dateSepared[2];
		
		return $dateReturn;
	}
	
	public function formatedDate() {
		$date = $this->_prepareDate();
		echo '<div class="date clearfix">';
			echo '<div class="date_holder">';
				echo '<span class="month">';
					echo $date['month'];
					echo '<span class="year">';
						echo $date['year'];
					echo '</span>';
				echo '</span>';
				echo '<span class="day">';
					echo $date['day'];
				echo '</span>';
			echo '</div><!--  END "date_holder"  //-->';
		echo '</div><!--  END "date"  //-->';
		
	}
	

		
}
