0 ) {
ob_flush();
}
}
/**
* Function called via a preg_replace_callback() in order to handle matched part of a regular expression.
*
* @author Nevma (info@nevma.gr)
*
* @param $matches array The data of the current match of the regular expression.
*
* @return void
*/
function adaptive_images_front_replace_img_src ( $matches ) {
return $matches[1] . 'data-adaptive-images-src' . $matches[2] . '';
}
/**
* Function called via a preg_replace_callback() in order to handle matched part of a regular expression.
*
* @author Nevma (info@nevma.gr)
*
* @param $matches array The data of the current match of the regular expression.
*
* @return void
*/
function adaptive_images_front_replace_srcset ( $matches ) {
return $matches[1] . 'data-adaptive-images-srcset' . $matches[2];
}
/**
* Replaces HTML image src attributes with a special data attribute which will be handled by Javascript on the
* browser side and be replaced there with the appropriate source according to the device dimensions.
*
* @author Nevma (info@nevma.gr)
*
* @param $buffer string The HTML source that is to be sent to the browser.
*
* @return string The HTML source to be sent to the browser where the image src attributes have been replaced
* with appropriate data attributes.
*/
function adaptive_images_front_replace_image_sources_from_html ( $buffer ) {
// Regular expression tests: http://regexr.com/3e3ji, http://regexr.com/3e47e
$image_src_reg_exp = '/(\"\'=]*\s*=\s*\"[^\"]*\"\s+)*)src(\s*=\s*\"[^\"]*\"(?:\s+[^\s>\"\'=]*\s*=\s*\"[^\"]*\")*\s*\/?>)/im';
$buffer = preg_replace_callback( $image_src_reg_exp, 'adaptive_images_front_replace_img_src', $buffer );
$srcset_reg_exp = '/(<(?:img|source)\s+(?:[^\s>\"\'=]*\s*=\s*\"[^\"]*\"\s+)*)srcset(\s*=\s*\"[^\"]*\"(?:\s+[^\s>\"\'=]*\s*=\s*\"[^\"]*\")*\s*\/?>)/im';
$buffer = preg_replace_callback( $srcset_reg_exp, 'adaptive_images_front_replace_srcset', $buffer );
return $buffer;
}
?>