function smarty_function_picture($params, $template) { $src = smarty_plugin_get_variable($params, $template, 'src', true); $alt = smarty_plugin_get_variable($params, $template, 'alt'); $path = smarty_plugin_get_variable($params, $template, 'path'); $CI =& get_instance(); $CI->load->helper('image'); $file = find_file($src, 'static/img/'); // Try to find the image in static/img if ($file == null) { // We can't read the file $file = find_file($src, 'static/uploads/'); if ($file == null) { $src = 'default.png'; } } $size = get_image_size($src); $size = $size['width']; $attr = $params; $medias = array(); $ret = array(); $attr['src'] = $src; if ($path != '') { $attr['path'] = site_url($path); } $ret[] = '<picture ' . _parse_form_attributes($attr, array()) . ' >'; foreach ($params as $key => $value) { // Check if user has set the customized media if (strpos($key, 'media') !== false) { $media = str_replace('media', '', $key); $medias[] = $media; $ret[] = "\t" . '<source src="' . site_url('responsive/size/' . $value . '/' . $src) . '" media="(min-width:' . $media . 'px)">'; continue; } $attr[$key] = smarty_plugin_get_variable($params, $template, $key, false); } if ($path == '') { $resolutions = get_ci_config('resolutions'); foreach ($resolutions as $res) { if (array_search($res, $medias) !== false) { // If the resolution is already covered continue; } $ret[] = "\t" . '<source src="' . site_url('responsive/size/' . (double) $res / 2880 * (double) $size . '/' . $src) . '" media="(min-width:' . $res . 'px)">'; } } $ret[] = "\t" . '<noscript>'; $ret[] = "\t\t" . '<img src="' . site_url('static/img/' . $src) . '" alt="' . $alt . '">'; $ret[] = "\t" . '</noscript>'; $ret[] = '</picture>'; return implode("\n", $ret); }
function smarty_block_figure($params, $content = '', $template, &$repeat) { if ($repeat) { // Skip the start part return; } $src = smarty_plugin_get_variable($params, $template, 'src', true); $path = smarty_plugin_get_variable($params, $template, 'path'); $size = get_image_size($src); $size = $size['width']; if ($path == '') { // If we are using auto resizing, skip the resolutions $resolutions = get_ci_config('resolutions'); foreach ($resolutions as $res) { $attr['data-media' . $res] = site_url('responsive/size/' . (double) $res / 2880 * (double) $size . '/' . $src); } } foreach ($params as $key => $value) { if ($key == 'path') { $attr[$key] = site_url(get_smarty_variable($params, $template, 'path', $value)); continue; } if (strpos($key, 'media') !== false) { $attr['data-' . $key] = site_url('responsive/size/' . $value . '/' . $src); } else { $attr[$key] = get_smarty_variable($params, $template, $value, $value); } } $ret = array(); $ret[] = '<figure ' . _parse_form_attributes($attr, array()) . '>'; if (isset($attr['action'])) { $ret[] = '<a href="' . $attr['action'] . '">'; } $ret[] = '<noscript>'; $ret[] = '<img src="' . site_url('static/img/' . $src) . '">'; $ret[] = '</noscript>'; if (isset($attr['action'])) { $ret[] = '</a>'; } $ret[] = '<figcaption>'; $ret[] = $content; $ret[] = '</figcaption>'; $ret[] = '</figure>'; return implode("\n", $ret); }