<?php
/**
 * 啦啦外卖 - 做好用的外卖系统!
 * =========================================================
 * Copy right 2015-2038 太原多讯网络科技有限公司, 保留所有权利。
 * ----------------------------------------------
 * 官方网址: http://www.duoxunwl.com/
 * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用。
 * 任何企业和个人不允许对程序代码以任何形式任何目的再发布。
 * =========================================================
 * @author : 啦啦外卖团队
 * @微信客服:HEIGEZX
 */
defined('IN_IA') or exit('Access Denied');
load()->model('attachment');
$dos = array('attachment', 'remote', 'buckets');
$do = in_array($do, $dos) ? $do : 'attachment';
 
 
if($do == 'attachment') {
	$_W['page']['title'] = '全局设置';
	if (empty($_W['setting']['upload'])) {
		$upload = $_W['config']['upload'];
	} else {
		$upload = $_W['setting']['upload'];
	}
	$post_max_size = ini_get('post_max_size');
	$post_max_size = $post_max_size > 0 ? bytecount($post_max_size) / 1024 : 0;
	$upload_max_filesize = ini_get('upload_max_filesize');
	if($_W['ispost']) {
		$harmtype = array('asp', 'php', 'jsp', 'js', 'css', 'php3', 'php4', 'php5', 'ashx', 'aspx', 'exe', 'cgi');
 
		$upload['attachment_limit'] = max(0, intval($_GPC['attachment_limit']));
 
		$upload['image']['thumb'] = intval($_GPC['image']['thumb']);
		$upload['image']['width'] = intval($_GPC['image']['width']);
		$upload['image']['extentions'] = array();
		$image_extentions = explode("\n", safe_gpc_string($_GPC['image']['extentions']));
		foreach ($image_extentions as $item) {
			$item = safe_gpc_string(trim($item));
			if (!empty($item) && !in_array($item, $harmtype) && !in_array($item, $upload['image']['extentions'])) {
				$upload['image']['extentions'][] = $item;
			}
		}
		$upload['image']['limit'] = max(0, min(intval($_GPC['image']['limit']), $post_max_size));
		$zip_percentage = intval($_GPC['image']['zip_percentage']);
		if ($zip_percentage <= 0 || $zip_percentage > 100) {
			$zip_percentage = 100;
		}
		$upload['image']['zip_percentage'] = $zip_percentage;
 
		$upload['audio']['extentions'] = array();
		$audio_extentions = explode("\n", safe_gpc_string($_GPC['audio']['extentions']));
		foreach ($audio_extentions as $item) {
			$item = safe_gpc_string(trim($item));
			if (!empty($item) && !in_array($item, $harmtype) && !in_array($item, $upload['audio']['extentions'])) {
				$upload['audio']['extentions'][] = $item;
			}
		}
		$upload['audio']['limit'] = max(0, min(intval($_GPC['audio']['limit']), $post_max_size));
 
		setting_set('upload', $upload);
		message(error(0, '附件设置保存成功'), url('sys/attachment/attachment'), 'ajax');
	}
 
	if(empty($upload['image']['thumb'])) {
		$upload['image']['thumb'] = 0;
	} else {
		$upload['image']['thumb'] = 1;
	}
	$upload['image']['width'] = intval($upload['image']['width']);
	if(empty($upload['image']['width'])) {
		$upload['image']['width'] = 800;
	}
	if(!empty($upload['image']['extentions']) && is_array($upload['image']['extentions'])) {
		$upload['image']['extentions'] = implode("\n", $upload['image']['extentions']);
	}
	if(!empty($upload['audio']['extentions']) && is_array($upload['audio']['extentions'])) {
		$upload['audio']['extentions'] = implode("\n", $upload['audio']['extentions']);
	}
	if(empty($upload['image']['zip_percentage'])) {
		$upload['image']['zip_percentage'] = 100;
	}
}
 
elseif($do == 'remote') {
   
	$_W['page']['title'] = '远程附件';
	$remote = $_W['setting']['remote_complete_info'];
	$remote_urls = array(
		'alioss' => array('old_url' => $remote['alioss']['url']),
		'ftp' => array('old_url' => $remote['ftp']['url']),
		'qiniu' => array('old_url' => $remote['qiniu']['url']),
		'cos' => array('old_url' => $remote['cos']['url']),
	);
	if($_W['ispost']) {
		$remote = array(
			'type' => intval($_GPC['type']),
			'ftp' => array(
				'ssl' => intval($_GPC['ftp']['ssl']),
				'host' => $_GPC['ftp']['host'],
				'port' => $_GPC['ftp']['port'],
				'username' => $_GPC['ftp']['username'],
				'password' => strexists($_GPC['ftp']['password'], '*') ? $_W['setting']['remote_complete_info']['ftp']['password'] : $_GPC['ftp']['password'],
				'pasv' => intval($_GPC['ftp']['pasv']),
				'dir' => $_GPC['ftp']['dir'],
				'url' => $_GPC['ftp']['url'],
				'overtime' => intval($_GPC['ftp']['overtime']),
			),
			'alioss' => array(
				'key' => trim($_GPC['alioss']['key']),
				'secret' => strexists($_GPC['alioss']['secret'], '*') ? $_W['setting']['remote_complete_info']['alioss']['secret'] : trim($_GPC['alioss']['secret']),
				'bucket' => $_GPC['alioss']['bucket'],
				'internal' => $_GPC['alioss']['internal'],
			),
			'qiniu' => array(
				'accesskey' => trim($_GPC['qiniu']['accesskey']),
				'secretkey' => strexists($_GPC['qiniu']['secretkey'], '*') ? $_W['setting']['remote_complete_info']['qiniu']['secretkey'] : trim($_GPC['qiniu']['secretkey']),
				'bucket' => trim($_GPC['qiniu']['bucket']),
				'url' => trim($_GPC['qiniu']['url']),
			),
			'cos' => array(
				'appid' => trim($_GPC['cos']['appid']),
				'secretid' => trim($_GPC['cos']['secretid']),
				'secretkey' => strexists(trim($_GPC['cos']['secretkey']), '*') ? $_W['setting']['remote_complete_info']['cos']['secretkey'] : trim($_GPC['cos']['secretkey']),
				'bucket' => trim($_GPC['cos']['bucket']),
				'local' => trim($_GPC['cos']['local']),
				'url' => trim($_GPC['cos']['url']),
			),
		);
		if($remote['type'] == 2) {
			if(empty($remote['alioss']['key'])) {
				message(error(-1, '阿里云OSS-Access Key ID不能为空'), '', 'ajax');
			}
			if(empty($remote['alioss']['secret'])) {
				message(error(-1, '阿里云OSS-Access Key Secret不能为空'), '', 'ajax');
			}
			$buckets = attachment_alioss_buctkets($remote['alioss']['key'], $remote['alioss']['secret']);
			if(is_error($buckets)) {
				message(error(-1, 'OSS-Access Key ID 或 OSS-Access Key Secret错误,请重新填写'), '', 'ajax');
			}
			list($remote['alioss']['bucket'], $remote['alioss']['url']) = explode('@@', $_GPC['alioss']['bucket']);
			if(empty($buckets[$remote['alioss']['bucket']])) {
				message(error(-1, 'Bucket不存在或是已经被删除'), '', 'ajax');
			}
			$remote['alioss']['url'] = 'http://' . $remote['alioss']['bucket'] . '.' . $buckets[$remote['alioss']['bucket']]['location'] . '.aliyuncs.com';
			$remote['alioss']['ossurl'] = $buckets[$remote['alioss']['bucket']]['location'] . '.aliyuncs.com';
			if (!empty($_GPC['custom']['url'])) {
				$url = trim($_GPC['custom']['url'], '/');
				if (!strexists($url, 'http://') && !strexists($url, 'https://')) {
					$url = 'http://' . $url;
				}
				$remote['alioss']['url'] = $url;
			}
			attachment_replace_article_remote_url($remote_urls['alioss']['old_url'], $remote['alioss']['url']);
		} elseif($remote['type'] == 1) {
			if (empty($remote['ftp']['host'])) {
				message(error(-1, 'FTP服务器地址为必填项.'), '', 'ajax');
			}
			if (empty($remote['ftp']['username'])) {
				message(error(-1, 'FTP帐号为必填项.'), '', 'ajax');
			}
			if (empty($remote['ftp']['password'])) {
				message(error(-1, 'FTP密码为必填项.'), '', 'ajax');
			}
			attachment_replace_article_remote_url($remote_urls['ftp']['old_url'], $_GPC['ftp']['url']);
		} elseif($remote['type'] == 3) {
			if (empty($remote['qiniu']['accesskey'])) {
				message(error(-1, '请填写Accesskey'), '', 'ajax');
			}
			if (empty($remote['qiniu']['secretkey'])) {
				message(error(-1, '请填写secretkey'), '', 'ajax');
			}
			if (empty($remote['qiniu']['bucket'])) {
				message(error(-1, '请填写bucket'), '', 'ajax');
			}
			if (empty($remote['qiniu']['url'])) {
				message(error(-1, '请填写url'), '', 'ajax');
			} else {
				$remote['qiniu']['url'] = strexists($remote['qiniu']['url'], 'http') ? trim($remote['qiniu']['url'], '/') : 'http://' . trim($remote['qiniu']['url'], '/');
			}
 			attachment_replace_article_remote_url($remote_urls['qiniu']['old_url'], $remote['qiniu']['url']);
// 			$auth = attachment_qiniu_auth($remote['qiniu']['accesskey'], $remote['qiniu']['secretkey'], $remote['qiniu']['bucket']);
// 			if (is_error($auth)) {
// 				$message = $auth['message']['error'] == 'bad token' ? 'Accesskey或Secretkey填写错误, 请检查后重新提交' : 'bucket填写错误或是bucket所对应的存储区域选择错误,请检查后重新提交';
// 				message(error(-1, $message), '', 'ajax');
// 			}
		} elseif ($remote['type'] == 4) {
			if (empty($remote['cos']['appid'])) {
				message(error(-1, '请填写APPID'), '', 'ajax');
			}
			if (empty($remote['cos']['secretid'])) {
				message(error(-1, '请填写SECRETID'), '', 'ajax');
			}
			if (empty($remote['cos']['secretkey'])) {
				message(error(-1, '请填写SECRETKEY'), '', 'ajax');
			}
			if (empty($remote['cos']['bucket'])) {
				message(error(-1, '请填写BUCKET'), '', 'ajax');
			}
			$remote['cos']['bucket'] = str_replace("-{$remote['cos']['appid']}", '', trim($remote['cos']['bucket']));
 
			if (empty($url)) {
				$url = sprintf('https://%s-%s.cos%s.myqcloud.com', $bucket, $appid, $_GPC['local']);
			}
			if (empty($remote['cos']['url'])) {
				$remote['cos']['url'] = sprintf('https://%s-%s.cos%s.myqcloud.com', $remote['cos']['bucket'], $remote['cos']['appid'], $remote['cos']['local']);
			}
			$remote['cos']['url'] = rtrim($remote['cos']['url'], '/');
			$_W['setting']['remote']['cos'] = array();
			attachment_replace_article_remote_url($remote_urls['cos']['old_url'], $remote['cos']['url']);
			$auth = attachment_cos_auth($remote['cos']['bucket'], $remote['cos']['appid'], $remote['cos']['secretid'], $remote['cos']['secretkey'], $remote['cos']['local']);
 
			if(is_error($auth)) {
				message(error(-1, $auth['message']), '', 'ajax');
			}
		}
		$_W['setting']['remote_complete_info']['type'] = $remote['type'];
		$_W['setting']['remote_complete_info']['alioss'] = $remote['alioss'];
		$_W['setting']['remote_complete_info']['ftp'] = $remote['ftp'];
		$_W['setting']['remote_complete_info']['qiniu'] = $remote['qiniu'];
		$_W['setting']['remote_complete_info']['cos'] = $remote['cos'];
		$result = setting_set('remote', $_W['setting']['remote_complete_info']);
		message(error(0, '远程附件配置信息更新成功!'), url('sys/attachment/remote'), 'ajax');
	}
}
 
elseif($do == 'buckets') {
	$key = $_GPC['key'];
	$secret = $_GPC['secret'];
	$buckets = attachment_alioss_buctkets($key, $secret);
	if(is_error($buckets)) {
		message($buckets, '', 'ajax');
	}
	$bucket_datacenter = attachment_alioss_datacenters();
	$bucket = array();
	foreach ($buckets as $key => $value) {
		$value['bucket_key'] = $value['name'] . '@@' . $value['location'];
		$value['loca_name'] = $key . '@@' . $bucket_datacenter[$value['location']];
		$bucket[] = $value;
	}
	message(error(0, $bucket), '', 'ajax');
}
 
template('sys/attachment');
 





最近给客户独立版啦啦外卖配置七牛云提示失败,参数都正确但是不行,特此记录一下修改

路径web/controller/sys/attachment.inc.php文件

直接修改这个文件里面的内容,用上面的替换掉



点赞(0)

评论列表 共有 0 条评论

暂无评论
立即
投稿
发表
评论
返回
顶部