微擎系统函数tomedia的应用

tomedia函数

tomedia函数的应用其实很广,主要是用来在前端中显示图片。用法为

img src="{php echo tomedia($nav['icon'])}" />

这个函数在微擎代码中的位置是/framework/function/global.func.php,代码如下

function tomedia($src, $local_path = false, $is_cahce = false){
	global $_W;
	$src = trim($src);
	if (empty($src)) {
		return '';
	}
	if ($is_cahce) {
		$src .= "?v=" . time ();
	}

	if (strexists($src, "c=utility&a=wxcode&do=image&attach=")) {
		return $src;
	}

	$t = strtolower($src);
	if (strexists($t, 'https://mmbiz.qlogo.cn') || strexists($t, 'http://mmbiz.qpic.cn')) {
		$url = url('utility/wxcode/image', array('attach' => $src));
		return $_W['siteroot'] . 'web' . ltrim($url, '.');
	}

	if (substr($src, 0, 2) == '//') {
		return 'http:' . $src;
	}
	if ((substr($src, 0, 7) == 'http://') || (substr($src, 0, 8) == 'https://')) {
		return $src;
	}

	if (strexists($src, 'addons/')) {
		return $_W['siteroot'] . substr($src, strpos($src, 'addons/'));
	}
		if (strexists($src, $_W['siteroot']) && !strexists($src, '/addons/')) {
		$urls = parse_url($src);
		$src = $t = substr($urls['path'], strpos($urls['path'], 'images'));
	}
	$uni_remote_setting = uni_setting_load('remote');
		if ($local_path ||
		empty($_W['setting']['remote']['type']) && (empty($_W['uniacid']) || !empty($_W['uniacid']) && empty($uni_remote_setting['remote']['type'])) ||
		file_exists(IA_ROOT . '/' . $_W['config']['upload']['attachdir'] . '/' . $src)) {

		$src = $_W['siteroot'] . $_W['config']['upload']['attachdir'] . '/' . $src;
	} else {
		$src = $_W['attachurl_remote'] . $src;
	}
	return $src;
}


CopyRight © 2017 www.wenoew.cn
赣ICP备17014667号-3