<?php

/**
 * Snippet to create a link to the feature image of a testimonial.
 *
 * THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 *
 * @package clearFusionCMS\module\testimonials
 * @copyright Copyright (c) 2017 clearFusionCMS. All rights reserved.
 * @link http://clearfusioncms.com
 */

/* @var $tplEngine cfTemplateEngine */
$controller = $tplEngine->controller;

if(!isset($id) && isset($controller->pageData['contentid']))
	$id = $controller->pageData['contentid'];

if($id) {
	$size = isset($size) && preg_match('/^[tsmlo]$/', $size) ? $size : 'l';
	$testimonial = clearFusionCMS::getDb()->fetchRow('SELECT fileext,author FROM cf_testimonials_' . clearFusionCMS::getSite() . ' WHERE id=?', $id);

	if($testimonial && !empty($testimonial['fileext'])) {
		$imageRoute = $controller->content->getContainerRoute($controller->pageData['id'], 'images/:size/:id', array(), array(), $testimonial['fileext']);
		$src = $imageRoute->assemble(array('size' => $size, 'id' => $id));

		echo isset($linkOnly) && $linkOnly ? $src : '<img src="' . $src . '" alt="' . $testimonial['author'] . '" />';
	}
}
