/**
 * Add a shortcode for displaying a list of testimonials
 */
function inti_shortcode_testimonials($atts, $content = null)
{
    $content = trim($content);
    extract(shortcode_atts(array('catid' => '', 'align' => '', 'order' => ''), $atts));
    if ($order != "ASC" || $order != "DESC") {
        $order = "ASC";
    }
    if (!empty($catid)) {
        $args = array('post_type' => 'inti-testimonial', 'orderby' => 'menu_order', 'order' => $order, 'posts_per_page' => 100, 'tax_query' => array(array('taxonomy' => 'inti-testimonial-category', 'field' => 'id', 'terms' => $catid)));
        $testimonials = new WP_Query($args);
        //$testimonials = new WP_Query('post_type=inti-testimonial&orderby=menu_order&order=ASC&posts_per_page=100&cat=' . $catid);
    } else {
        $args = array('post_type' => 'inti-testimonial', 'orderby' => 'menu_order', 'order' => $order, 'posts_per_page' => 100);
        $testimonials = new WP_Query($args);
        //$testimonials = new WP_Query('post_type=inti-testimonial&orderby=menu_order&order=ASC&posts_per_page=100');
    }
    ob_start();
    $right = false;
    while ($testimonials->have_posts()) {
        $testimonials->the_post();
        $has_image = has_post_thumbnail(get_the_ID());
        ?>

			<?php 
        if ($align == "left" || $align == "") {
            ?>

				<blockquote class="testimonial left">
					<?php 
            if ($has_image) {
                ?>
						<div class="row">
							<div class="medium-5 mlarge-4 columns">
								<div class="testimonial-image">
									<?php 
                the_post_thumbnail('testimonial-thumbnail');
                ?>
								</div>
							</div>
							<div class="medium-7 mlarge-8 columns">
								<div class="testimonial-text">
									<?php 
                the_content();
                ?>
									<cite class="testimonial-owner">
										<?php 
                the_testimonial_owner(get_the_ID());
                ?>
									</cite>
								</div>
							</div>
						</div>
					<?php 
            } else {
                ?>
						<div class="row">
							<div class="column">
								<div class="testimonial-text">
									<?php 
                the_content();
                ?>
									<cite class="testimonial-owner">
										<?php 
                the_testimonial_owner(get_the_ID());
                ?>
									</cite>
								</div>
							</div>
						</div>
					<?php 
            }
            ?>
				</blockquote>



			<?php 
        } elseif ($align == "right") {
            ?>

				<blockquote class="testimonial right">
					<?php 
            if ($has_image) {
                ?>
						<div class="row">
							<div class="medium-5 medium-push-7 mlarge-4 mlarge-push-8 columns">
								<div class="testimonial-image">
									<?php 
                the_post_thumbnail('testimonial-thumbnail');
                ?>
								</div>
							</div>
							<div class="medium-7 medium-pull-5 mlarge-8 mlarge-pull-4 columns">
								<div class="testimonial-text">
									<?php 
                the_content();
                ?>
									<cite class="testimonial-owner">
										<?php 
                the_testimonial_owner(get_the_ID());
                ?>
									</cite>
								</div>
							</div>
						</div>
					<?php 
            } else {
                ?>
						<div class="row">
							<div class="column">
								<div class="testimonial-text">
									<?php 
                the_content();
                ?>
									<cite class="testimonial-owner">
										<?php 
                the_testimonial_owner(get_the_ID());
                ?>
									</cite>
								</div>
							</div>
						</div>
					<?php 
            }
            ?>
				</blockquote>



			<?php 
        } elseif ($align == "mixed") {
            ?>
					<?php 
            if ($right) {
                ?>
						<blockquote class="testimonial mixed right">
							<?php 
                if ($has_image) {
                    ?>
								<div class="row">
									<div class="medium-5 medium-push-7 mlarge-4 mlarge-push-8 columns">
										<div class="testimonial-image">
											<?php 
                    the_post_thumbnail('testimonial-thumbnail');
                    ?>
										</div>
									</div>
									<div class="medium-7 medium-pull-5 mlarge-8 mlarge-pull-4 columns">
										<div class="testimonial-text">
											<?php 
                    the_content();
                    ?>
											<cite class="testimonial-owner">
												<?php 
                    the_testimonial_owner(get_the_ID());
                    ?>
											</cite>
										</div>
									</div>
								</div>
							<?php 
                } else {
                    ?>
								<div class="row">
									<div class="column">
										<div class="testimonial-text">
											<?php 
                    the_content();
                    ?>
											<cite class="testimonial-owner">
												<?php 
                    the_testimonial_owner(get_the_ID());
                    ?>
											</cite>
										</div>
									</div>
								</div>
							<?php 
                }
                ?>

					<?php 
                $right = false;
            } else {
                ?>
						<blockquote class="testimonial mixed left">
						<?php 
                if ($has_image) {
                    ?>
							<div class="row">
								<div class="medium-5 mlarge-4 columns">
									<div class="testimonial-image">
										<?php 
                    the_post_thumbnail('testimonial-thumbnail');
                    ?>
									</div>
								</div>
								<div class="medium-7 mlarge-8 columns">
									<div class="testimonial-text">
										<?php 
                    the_content();
                    ?>
										<cite class="testimonial-owner">
											<?php 
                    the_testimonial_owner(get_the_ID());
                    ?>
										</cite>
									</div>
								</div>
							</div>
						<?php 
                } else {
                    ?>
							<div class="row">
								<div class="column">
									<div class="testimonial-text">
										<?php 
                    the_content();
                    ?>
										<cite class="testimonial-owner">
											<?php 
                    the_testimonial_owner(get_the_ID());
                    ?>
										</cite>
									</div>
								</div>
							</div>
						<?php 
                }
                ?>

					<?php 
                $right = true;
            }
            ?>
				</blockquote>



			<?php 
        } elseif ($align == "vertical") {
            ?>

				<blockquote class="testimonial vertical">
					<?php 
            if ($has_image) {
                ?>
						<div class="row">
							<div class="column">
								<div class="testimonial-image">
									<?php 
                the_post_thumbnail('testimonial-thumbnail');
                ?>
								</div>
							</div>
							<div class="column">
								<div class="testimonial-text">
									<?php 
                the_content();
                ?>
									<cite class="testimonial-owner">
										<?php 
                the_testimonial_owner(get_the_ID());
                ?>
									</cite>
								</div>
							</div>
						</div>
					<?php 
            } else {
                ?>
						<div class="row">
							<div class="column">
								<div class="testimonial-text">
									<?php 
                the_content();
                ?>
									<cite class="testimonial-owner">
										<?php 
                the_testimonial_owner(get_the_ID());
                ?>
									</cite>
								</div>
							</div>
						</div>
					<?php 
            }
            ?>
				</blockquote>



			<?php 
        } else {
            ?>
				<div class="callout alert">
					<p><?php 
            _e('Alignment not recognized', 'inti-child');
            ?>
</p>
				</div>
			<?php 
        }
        ?>

			

		
		<?php 
    }
    wp_reset_query();
    $html = '<section class="testimonials-list">';
    $html .= ob_get_contents();
    $html .= '</section>';
    ob_end_clean();
    return $html;
}
/**
 * Add a shortcode for displaying single testimonials
 */
function inti_shortcode_testimonial_single($atts, $content = null)
{
    $content = trim($content);
    extract(shortcode_atts(array('id' => '', 'align' => ''), $atts));
    // fetch the testimonial
    $testimonial_object = get_post($id);
    if ($testimonial_object->post_type == 'inti-testimonial' && $testimonial_object->post_status == 'publish') {
        ob_start();
        $has_image = has_post_thumbnail($id);
        $image_html = '';
        $default_attr = array('alt' => $testimonial_object->post_title, 'title' => $testimonial_object->post_title);
        if (has_post_thumbnail($testimonial_object->ID)) {
            $image_html = get_the_post_thumbnail($testimonial_object->ID, 'testimonial-thumbnail', $default_attr);
        }
        ?>

				<?php 
        if ($align == "left" || $align == "") {
            ?>

					<blockquote class="testimonial">
						<?php 
            if ($has_image) {
                ?>
							<div class="row">
								<div class="medium-5 mlarge-4 columns">
									<div class="testimonial-image">
										<?php 
                echo $image_html;
                ?>
									</div>
								</div>
								<div class="medium-7 mlarge-8 columns">
									<div class="testimonial-text">
										<?php 
                echo wpautop($testimonial_object->post_content);
                ?>
										<cite class="testimonial-owner">
											<?php 
                the_testimonial_owner($testimonial_object->ID);
                ?>
										</cite>
									</div>
								</div>
							</div>
						<?php 
            } else {
                ?>
							<div class="row">
								<div class="column">
									<div class="testimonial-text">
										<?php 
                echo wpautop($testimonial_object->post_content);
                ?>
										<cite class="testimonial-owner">
											<?php 
                the_testimonial_owner($testimonial_object->ID);
                ?>
										</cite>
									</div>
								</div>
							</div>
						<?php 
            }
            ?>
					</blockquote>



				<?php 
        } elseif ($align == "right") {
            ?>

					<blockquote class="testimonial right callout">
						<?php 
            if ($has_image) {
                ?>
							<div class="row">
								<div class="medium-5 medium-push-7 mlarge-4 mlarge-push-8 columns">
									<div class="testimonial-image">
										<?php 
                echo $image_html;
                ?>
									</div>
								</div>
								<div class="medium-7 medium-pull-5 mlarge-8 mlarge-pull-4 columns">
									<div class="testimonial-text">
										<?php 
                echo wpautop($testimonial_object->post_content);
                ?>
										<cite class="testimonial-owner">
											<?php 
                the_testimonial_owner($testimonial_object->ID);
                ?>
										</cite>
									</div>
								</div>
							</div>
						<?php 
            } else {
                ?>
							<div class="row">
								<div class="column">
									<div class="testimonial-text">
										<?php 
                echo wpautop($testimonial_object->post_content);
                ?>
										<cite class="testimonial-owner">
											<?php 
                the_testimonial_owner($testimonial_object->ID);
                ?>
										</cite>
									</div>
								</div>
							</div>
						<?php 
            }
            ?>
					</blockquote>



				<?php 
        } elseif ($align == "vertical") {
            ?>

					<blockquote class="testimonial vertical callout">
						<?php 
            if ($has_image) {
                ?>
							<div class="row">
								<div class="column">
									<div class="testimonial-image">
										<?php 
                echo $image_html;
                ?>
									</div>
								</div>
								<div class="column">
									<div class="testimonial-text">
										<?php 
                echo wpautop($testimonial_object->post_content);
                ?>
										<cite class="testimonial-owner">
											<?php 
                the_testimonial_owner($testimonial_object->ID);
                ?>
										</cite>
									</div>
								</div>
							</div>
						<?php 
            } else {
                ?>
							<div class="row">
								<div class="column">
									<div class="testimonial-text">
										<?php 
                echo wpautop($testimonial_object->post_content);
                ?>
										<cite class="testimonial-owner">
											<?php 
                the_testimonial_owner($testimonial_object->ID);
                ?>
										</cite>
									</div>
								</div>
							</div>
						<?php 
            }
            ?>
					</blockquote>



				<?php 
        } else {
            ?>

					<div class="callout alert"><?php 
            the_testimonial_owner($testimonial_object->ID);
            ?>
						<p><?php 
            _e('No testimonial was found with this ID, you may need to re-insert this shortcode.', 'inti-child');
            ?>
</p>
					</div>
				<?php 
        }
        ?>

				

		
		<?php 
        $html = ob_get_contents();
        ob_end_clean();
    } else {
        ob_start();
        ?>
	
			<div class="callout alert">
				<p><?php 
        _e('No testimonial was found with this ID, you may need to re-insert this shortcode.', 'inti-child');
        ?>
</p>
			</div>

			<?php 
        $html = ob_get_contents();
        ob_end_clean();
    }
    wp_reset_query();
    return $html;
}
									<?php 
            } else {
                ?>
									<div class="column">
										
										<div class="testimonial-text">
											<?php 
                if ($content == "excerpt") {
                    the_excerpt();
                } else {
                    the_content();
                }
                ?>
											<cite class="testimonial-owner">	
												<?php 
                the_testimonial_owner(get_the_ID());
                ?>
		
											</cite>
										</div>
										
									</div>
									<?php 
            }
            ?>
	

								</div>
							</blockquote>