From 945950dce2b6c810c5b8e299c6c42ccf81fe3617 Mon Sep 17 00:00:00 2001 From: aa25905 <57143976@qq.com> Date: Sun, 22 Dec 2013 23:54:21 +0800 Subject: [PATCH] Create vendors.php MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 个人自定义函数以后可以全部写入此文件,方便升级 --- wwwroot/Application/Admin/Common/vendors.php | 136 +++++++++++++++++++ 1 file changed, 136 insertions(+) create mode 100644 wwwroot/Application/Admin/Common/vendors.php diff --git a/wwwroot/Application/Admin/Common/vendors.php b/wwwroot/Application/Admin/Common/vendors.php new file mode 100644 index 00000000..e9f4921b --- /dev/null +++ b/wwwroot/Application/Admin/Common/vendors.php @@ -0,0 +1,136 @@ + +// +---------------------------------------------------------------------- + + +/** + * 系统公共库文件扩展 + * 主要定义系统公共函数库扩展 + */ + +//友好时间显示开始 + +function fdate($time) { + if (!$time) + return false; + $fdate = ''; + $d = time() - intval($time); + $ld = $time - mktime(0, 0, 0, 0, 0, date('Y')); //得出年 + $md = $time - mktime(0, 0, 0, date('m'), 0, date('Y')); //得出月 + $byd = $time - mktime(0, 0, 0, date('m'), date('d') - 2, date('Y')); //前天 + $yd = $time - mktime(0, 0, 0, date('m'), date('d') - 1, date('Y')); //昨天 + $dd = $time - mktime(0, 0, 0, date('m'), date('d'), date('Y')); //今天 + $td = $time - mktime(0, 0, 0, date('m'), date('d') + 1, date('Y')); //明天 + $atd = $time - mktime(0, 0, 0, date('m'), date('d') + 2, date('Y')); //后天 + if ($d == 0) { + $fdate = '刚刚'; + } else { + switch ($d) { + case $d < $atd: + $fdate = date('Y年m月d日', $time); + break; + case $d < $td: + $fdate = '后天' . date('H:i', $time); + break; + case $d < 0: + $fdate = '明天' . date('H:i', $time); + break; + case $d < 60: + $fdate = $d . '秒前'; + break; + case $d < 3600: + $fdate = floor($d / 60) . '分钟前'; + break; + case $d < $dd: + $fdate = floor($d / 3600) . '小时前'; + break; + case $d < $yd: + $fdate = '昨天' . date('H:i', $time); + break; + case $d < $byd: + $fdate = '前天' . date('H:i', $time); + break; + case $d < $md: + $fdate = date('m月d日 H:i', $time); + break; + case $d < $ld: + $fdate = date('m月d日', $time); + break; + default: + $fdate = date('Y年m月d日', $time); + break; + } + } + return $fdate; +} +//友好时间显示结束 +/** + * 获取 IP 地理位置 + * 淘宝IP接口 + * @Return: array + */ +function getCity($ip) +{ +$url="http://ip.taobao.com/service/getIpInfo.php?ip=".$ip; +$ipinfo=json_decode(file_get_contents($url)); +if($ipinfo->code=='1'){ +return false; +} +$city = $ipinfo->data->region.$ipinfo->data->city;//省市县 +$ip = $ipinfo->data->ip;//IP地址 +$ips = $ipinfo->data->isp;//运营商 +$guo = $ipinfo->data->country;//国家 +if($guo == '中国'){ +$guo = ''; +} +//if(in_array(strtok($ip, '.'), array('10', '127', '168', '192'))){ +//$city = "本机地址或局域网"; +//} +//$ipp = '110.113.161.105'; +//$ipss = ip2long($ipp); +return $guo.$city.$ips.'['.$ip.']'; + +} + + /** + * 添加邮件到队列 + */ + function _mail_queue($to, $subject, $body, $priority = 1) { + $to_emails = is_array($to) ? $to : array($to); + $mails = array(); + $time = time(); + foreach ($to_emails as $_email) { + $mails[] = array( + 'mail_to' => $_email, + 'mail_subject' => $subject, + 'mail_body' => $body, + 'priority' => $priority, + 'add_time' => $time, + 'lock_expiry' => $time, + ); + } + M('mail_queue')->addAll($mails); + + //异步发送邮件 + $this->send_mail(false); + } + + /** + * 发送邮件 + */ + function send_mail($is_sync = true) { + if (!$is_sync) { + //异步 + session('async_sendmail', true); + return true; + } else { + //同步 + session('async_sendmail', null); + return D('mail_queue')->send(); + } + }