函数tpl_form_field_wechat_image在哪里实现
在 web\common\tpl.func.php 中
类似的函数有
tpl_form_field_wechat_image
tpl_form_field_wechat_multi_image
tpl_form_field_wechat_voice
tpl_form_field_wechat_video
如下
~~~
function tpl_form_field_wechat_image($name, $value = '', $default = '', $options = array()) {
global $_W;
if(!$_W['acid'] || $_W['account']['level'] < 3) {
$options['account_error'] = 1;
} else {
$options['acid'] = $_W['acid'];
}
if(empty($default)) {
$default = './resource/images/nopic.jpg';
}
$val = $default;
if (!empty($value)) {
$media_data = (array)media2local($value, true);
$val = $media_data['attachment'];
}
if (empty($options['class_extra'])) {
$options['class_extra'] = '';
}
$options['direct'] = true;
$options['multiple'] = false;
$options['type'] = empty($options['type']) ? 'image' : $options['type'];
$s = '';
if (!defined('TPL_INIT_WECHAT_IMAGE')) {
$s = '
<script type="text/javascript">
function showWechatImageDialog(elm, options) {
require(["util"], function(util){
var btn = $(elm);
var ipt = btn.parent().prev();
var val = ipt.val();
var img = ipt.parent().next().children();
util.wechat_image(val, function(url){
if(url.media_id){
if(img.length > 0){
img.get(0).src = url.url;
}
ipt.val(url.media_id);
}
}, options);
});
}
function deleteImage(elm){
require(["jquery"], function($){
$(elm).prev().attr("src", "./resource/images/nopic.jpg");
$(elm).parent().prev().find("input").val("");
});
}
</script>';
define('TPL_INIT_WECHAT_IMAGE', true);
}
$s .= '
<div class="input-group ' . $options['class_extra'] . '">
<input type="text" name="' . $name . '" value="' . $value . '"' . ($options['extras']['text'] ? $options['extras']['text'] : '') . ' class="form-control" autocomplete="off">
<span class="input-group-btn">
<button class="btn btn-default" type="button" onclick="showWechatImageDialog(this, ' . str_replace('"', '\'', json_encode($options)) . ');">选择图片</button>
</span>
</div>';
$s .=
'<div class="input-group ' . $options['class_extra'] . '" style="margin-top:.5em;">
<img src="' . $val . '" onerror="this.src=\'' . $default . '\'; this.title=\'图片未找到.\'" class="img-responsive img-thumbnail" ' . ($options['extras']['image'] ? $options['extras']['image'] : '') . ' width="150" />
<em class="close" style="position:absolute; top: 0px; right: -14px;" title="删除这张图片" onclick="deleteImage(this)">×</em>
</div>';
if (!empty($media_data) && $media_data['model'] == 'temp' && (time() - $media_data['createtime'] > 259200)) {
$s .= '<span class="help-block"><b class="text-danger">该素材已过期 [有效期为3天],请及时更新素材</b></span>';
}
return $s;
}
~~~