if($value[3] == "imagegalery" AND $xfieldsdata[$value[0]] AND stripos ( $tpl2->copy_template, "[xfvalue_{$value[0]}" ) !== false) {
$fieldvalue_arr = explode(',', $xfieldsdata[$value[0]]);
$gallery_image = array();
$gallery_single_image = array();
$xf_image_count = 0;
foreach ($fieldvalue_arr as $temp_value) {
$xf_image_count ++;
$temp_value = trim($temp_value);
if($temp_value == "") continue;
$temp_array = explode('|', $temp_value);
if (count($temp_array) == 1 OR count($temp_array) == 5 ){
$temp_alt = '';
$temp_value = implode('|', $temp_array );
} else {
$temp_alt = $temp_array[0];
$temp_alt = str_replace( ",", ",", $temp_alt );
$temp_alt = str_replace( "|", "|", $temp_alt );
unset($temp_array[0]);
$temp_value = implode('|', $temp_array );
}
$path_parts = get_uploaded_image_info($temp_value);
if($value[12] AND $path_parts->thumb) {
$gallery_image[] = "<li><a href=\"{$path_parts->url}\" onclick=\"return hs.expand(this, { slideshowGroup: 'xf_{$row['id']}_{$value[0]}' })\" target=\"_blank\"><img src=\"{$path_parts->thumb}\" alt=\"{$temp_alt}\"></a></li>";
$gallery_single_image['[xfvalue_'.$value[0].' image="'.$xf_image_count.'"]'] = "<a href=\"{$path_parts->url}\" class=\"highslide\" target=\"_blank\"><img class=\"xfieldimage {$value[0]}\" src=\"{$path_parts->thumb}\" alt=\"{$temp_alt}\"></a>";
} else {
$gallery_image[] = "<li><img src=\"{$path_parts->url}\" alt=\"{$temp_alt}\"></li>";
$gallery_single_image['[xfvalue_'.$value[0].' image="'.$xf_image_count.'"]'] = "<img class=\"xfieldimage {$value[0]}\" src=\"{$path_parts->url}\" alt=\"{$temp_alt}\">";
}
$gallery_single_image['[xfvalue_'.$value[0].' image-description="'.$xf_image_count.'"]'] = $temp_alt;
$gallery_single_image['[xfvalue_'.$value[0].' image-thumb-url="'.$xf_image_count.'"]'] = $path_parts->thumb;
$gallery_single_image['[xfvalue_'.$value[0].' image-url="'.$xf_image_count.'"]'] = $path_parts->url;
$tpl2->copy_template = str_ireplace( '[xfgiven_'.$value[0].' image="'.$xf_image_count.'"]', "", $tpl2->copy_template );
$tpl2->copy_template = str_ireplace( '[/xfgiven_'.$value[0].' image="'.$xf_image_count.'"]', "", $tpl2->copy_template );
$tpl2->copy_template = preg_replace( "'\\[xfnotgiven_{$preg_safe_name} image=\"{$xf_image_count}\"\\](.*?)\\[/xfnotgiven_{$preg_safe_name} image=\"{$xf_image_count}\"\\]'is", "", $tpl2->copy_template );
}
if(count($gallery_single_image) ) {
foreach($gallery_single_image as $temp_key => $temp_value) $tpl2->set( $temp_key, $temp_value);
}
$xfieldsdata[$value[0]] = "<ul class=\"xfieldimagegallery {$value[0]}\">".implode($gallery_image)."</ul>";
}
$tpl2->copy_template = preg_replace( "'\\[xfgiven_{$preg_safe_name} image=\"(\d+)\"\\](.*?)\\[/xfgiven_{$preg_safe_name} image=\"(\d+)\"\\]'is", "", $tpl2->copy_template );
$tpl2->copy_template = preg_replace( "'\\[xfnotgiven_{$preg_safe_name} image=\"(\d+)\"\\]'i", "", $tpl2->copy_template );
$tpl2->copy_template = preg_replace( "'\\[/xfnotgiven_{$preg_safe_name} image=\"(\d+)\"\\]'i", "", $tpl2->copy_template );
if ($config['image_lazy'] AND $view_template != "print" ) $xfieldsdata[$value[0]] = preg_replace_callback ( "#<(img|iframe)(.+?)>#i", "enable_lazyload", $xfieldsdata[$value[0]] );
$tpl2->set( "[xfvalue_{$value[0]}]", $xfieldsdata[$value[0]] );
if ( preg_match( "#\\[xfvalue_{$preg_safe_name} limit=['\"](.+?)['\"]\\]#i", $tpl2->copy_template, $matches ) ) {
$tpl2->set( $matches[0], clear_content($xfieldsdata[$value[0]], $matches[1]) );
}
}
}
$tpl2->compile( 'content' );
}