function tietuku_upload_file($filepath, $filename) { global $conf; $token = $conf['tietuku_token']; $post_url = 'http://up.tietuku.com/'; if (!is_file($filepath)) { return xn_error(-1, '文件不存在'); } elseif (filesize($filepath) == 0) { return xn_error(-1, '文件大小为 0'); } //$token = '00f47da319173e011683b6f4c63b46f8fe8a9471:ak9XYzQ5YmhIalIwYlNwMFJwaVB6Vm9XMFBjPQ==:eyJkZWFkbGluZSI6MTQ0MDY2MzkzOSwiYWN0aW9uIjoiZ2V0IiwidWlkIjoiNTgyNyIsImFpZCI6IjEyNzc5IiwiZnJvbSI6ImZpbGUifQ=='; $postdata = array(); $postdata['Token'] = $token; $postdata['file'] = curl_file_create($filepath, $filename); $s = http_post_file($post_url, $postdata); $arr = json_decode($s, 1); if (empty($arr) || empty($arr['size'])) { return xn_error(-3, '返回数据格式有问题:' . $s); } return $arr; }
function agree_update($touid, $pid, $tid, $fid, $isfirst) { global $conf, $time, $group, $longip, $sid, $uid, $gid, $user; //user_login_check($user); if (!forum_access_user($fid, $gid, 'allowagree')) { return xn_error(10, '您(' . $user['groupname'] . ')无权限在此版块点喜欢'); } if ($uid > 0) { // 每日最大喜欢数限制 if ($time - $user['last_agree_date'] > 86400) { user__update($uid, array('last_agree_date' => $time)); $user['today_agrees'] = 0; } $user['last_agree_date'] = $time; $user['today_agrees']++; if ($user['today_agrees'] > $group['maxagrees']) { return xn_error(-1, '请您休息会,您所在的用户组每日最大喜欢数为:' . $group['maxagrees']); } $agree = myagree_read($pid, $uid); if ($agree) { // 取消喜欢 $r = myagree_delete($uid, $pid, $isfirst); if ($r === FALSE) { return xn_error(2, '取消喜欢失败'); } thread_tids_cache_delete_by_order($fid, 'agree'); return xn_error(1, '取消喜欢成功'); // 1 表示取喜欢喜欢,前台会根据此项判断减1 } else { // 点击喜欢 $r = myagree_create($uid, $touid, $pid, $tid, $isfirst); if ($r === FALSE) { return xn_error(2, '点喜欢失败'); } thread_tids_cache_delete_by_order($fid, 'agree'); return xn_error(0, '点喜欢成功'); } } else { // ip 限制 $n = guest_agree_count_by_ip($longip); if ($n > $group['maxagrees']) { return xn_error(-1, '请您休息会,您所在的用户组每日最大喜欢数为:' . $group['maxagrees']); } // sid 限制 $agree = guest_agree_read($sid, $pid); if ($agree) { // 取消喜欢 $r = guest_agree_delete($sid, $pid, $touid, $isfirst ? $tid : 0); if ($r === FALSE) { return xn_error(2, '取消喜欢失败'); } thread_tids_cache_delete_by_order($fid, 'agree'); return xn_error(1, '取消喜欢成功'); // 1 表示取消喜欢,前台会根据此项判断减1 } else { // 点击喜欢 $r = guest_agree_create($sid, $longip, $pid, $touid, $isfirst ? $tid : 0); if ($r === FALSE) { return xn_error(2, '点喜欢失败'); } thread_tids_cache_delete_by_order($fid, 'agree'); return xn_error(0, '点喜欢成功'); } } }
function xn_send_mail($smtp, $username, $email, $subject, $message, $charset = 'UTF-8') { // 部分 SMTP 不支持UTF-8 /* if(in_array($smtp, array('smtp.126.com', 'smtp.163.com'))) { $charset = 'GBK'; } else { $charset = 'UTF-8'; } $charset = 'GBK'; */ $mail = new PHPMailer(); //$mail->PluginDir = FRAMEWORK_PATH.'lib/'; $mail->IsSMTP(); // telling the class to use SMTP $mail->IsHTML(TRUE); //$mail->ContentType= 'text/html'; $mail->SMTPDebug = 0; // enables SMTP debug information (for testing) // 1 = errors and messages // 2 = messages only $mail->SMTPAuth = TRUE; // enable SMTP authentication $mail->Host = $smtp['host']; // sets the SMTP server $mail->Port = $smtp['port']; // set the SMTP port for the GMAIL server $mail->Username = $smtp['user']; // SMTP account username $mail->Password = $smtp['pass']; // SMTP account password $mail->Timeout = 5; // $mail->CharSet = $charset; $mail->Encoding = 'base64'; //$subject = $charset == 'UTF-8' ? iconv('UTF-8', 'GBK', $subject) : $subject; //$message = $charset == 'UTF-8' ? iconv('UTF-8', 'GBK', $message) : $message; //$username = $charset == 'UTF-8' ? iconv('UTF-8', 'GBK', $username) : $username; //$fromemail = $this->conf['reg_email_user'].'@'.$this->conf['reg_email_host']; $mail->SetFrom($smtp['email'], $username); $mail->AddReplyTo($smtp['email'], $email); $mail->Subject = $subject; $mail->AltBody = $message; // optional, comment out and test $message = str_replace("\\", '', $message); $mail->MsgHTML($message); $mail->AddAddress($email, $username); //$mail->AddAttachment("images/phpmailer.gif"); // attachment //$mail->AddAttachment("images/phpmailer_mini.gif"); // attachment if (!$mail->Send()) { return xn_error(-1, $mail->ErrorInfo); } else { return TRUE; } }
function https_post($url, $timeout = 30, $post = '', $cookie = '') { $w = stream_get_wrappers(); $allow_url_fopen = strtolower(ini_get('allow_url_fopen')); $allow_url_fopen = empty($allow_url_fopen) || $allow_url_fopen == 'off' ? 0 : 1; if (extension_loaded('openssl') && in_array('https', $w) && $allow_url_fopen) { return file_get_contents($url); } elseif (!function_exists('curl_init')) { return xn_error(-1, 'server not installed curl.'); } $ch = curl_init(); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HEADER, 2); // 1/2 curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); // 对认证证书来源的检查 curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 1); // 从证书中检查SSL加密算法是否存在 if ($post) { curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $post); } if ($cookie) { curl_setopt($ch, CURLOPT_HTTPHEADER, array("Cookie: {$cookie}")); } !ini_get('safe_mode') && !ini_get('open_basedir') && curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); // 使用自动跳转, 安全模式不允许 curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); $data = curl_exec($ch); if (curl_errno($ch)) { return xn_error(-1, 'Errno' . curl_error($ch)); } if (!$data) { curl_close($ch); return ''; } list($header, $data) = explode("\r\n\r\n", $data); $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); if ($http_code == 301 || $http_code == 302) { $matches = array(); preg_match('/Location:(.*?)\\n/', $header, $matches); $url = trim(array_pop($matches)); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HEADER, false); $data = curl_exec($ch); } curl_close($ch); return $data; }
function qq_login_create_user($username, $avatar_url_2, $openid) { global $conf, $time, $longip; $arr = qq_login_read_user_by_openid($openid); if ($arr) { return xn_error(-2, '已经注册'); } // 自动产生一个用户名 $r = user_read_by_username($username); if ($r) { $username = $username . '_' . $time; $r = user_read_by_username($username); if ($r) { return xn_error(-1, '用户名被占用。'); } } // 自动产生一个 Email $email = "qq_{$time}@qq.com"; $r = user_read_by_email($email); if ($r) { return xn_error(-1, 'Email 被占用'); } // 随机密码 $password = md5(rand(1000000000, 9999999999) . $time); $user = array('username' => $username, 'email' => $email, 'password' => $password, 'gid' => 101, 'salt' => rand(100000, 999999), 'create_date' => $time, 'create_ip' => $longip, 'avatar' => 0, 'logins' => 1, 'login_date' => $time, 'login_ip' => $longip); $uid = user_create($user); if (empty($uid)) { return xn_error(-1, '注册失败'); } $user = user_read($uid); $r = db_exec("INSERT INTO bbs_user_open_plat SET uid='{$uid}', platid='1', openid='{$openid}'"); if (empty($uid)) { return xn_error(-1, '注册失败'); } runtime_set('users+', '1'); runtime_set('todayusers+', '1'); // 头像不重要,忽略错误。 if ($avatar_url_2) { $filename = "{$uid}.png"; $dir = substr(sprintf("%09d", $uid), 0, 3) . '/'; $path = $conf['upload_path'] . 'avatar/' . $dir; !is_dir($path) and mkdir($path, 0777, TRUE); $data = file_get_contents($avatar_url_2); file_put_contents($path . $filename, $data); user_update($uid, array('avatar' => $time)); } return $user; }
function sphinx_search($keyword) { $fid = 0; $daterange = 0; $orderby = 'match'; $page = 1; $pagesize = 60; global $conf, $time; $cl = new SphinxClient(); $cl->SetServer($conf['sphinx_host'], $conf['sphinx_port']); $cl->SetConnectTimeout(3); $cl->SetArrayResult(TRUE); $cl->SetWeights(array(100, 1, 5)); // 标题权重100,内容权重1,作者权重10 $fid && $cl->SetFilter('fid', array($fid)); $daterange && $cl->setFilterRange('dateline', $time - $daterange * 86400, $time); $cl->SetMatchMode(SPH_MATCH_ALL); if ($orderby == 'match') { $cl->SetSortMode(SPH_SORT_RELEVANCE); // 如果不设置,默认按照权重排序!但是TMD是正序! } elseif ($orderby == 'timeasc') { $cl->SetSortMode(SPH_SORT_ATTR_ASC, 'tid'); } elseif ($orderby == 'timedesc') { $cl->SetSortMode(SPH_SORT_ATTR_DESC, 'tid'); } //$cl->SetSortMode (SPH_SORT_ATTR_DESC, 'tid'); // 如果不设置,默认按照权重排序!但是TMD是正序! /* $cl->SetMatchMode ( SPH_MATCH_EXTENDED ); //设置模式 $cl->SetRankingMode ( SPH_RANK_PROXIMITY ); //设置评分模式 $cl->SetFieldWeights (array('subject'=>100,'message'=>10,'username'=>1));//设置字段的权重,如果area命中,那么权重算2 $cl->SetSortMode ('SPH_SORT_EXPR','@weight'); //按照权重排序 */ // --------------> 优先搜索增量索引 $newlist = array(); $forums = array(); if ($page == 1) { $cl->SetLimits(0, $pagesize, 1000); // 最大结果集 $res = $cl->Query($keyword, $conf['sphinx_deltasrc']); // * 为所有的索引 if (!empty($cl->_error)) { return xn_error(-1, 'Sphinx 错误:' . $cl->_error); } if (!empty($res) && !empty($res['total'])) { $deltamatch = $res['matches']; } $res['matches'] && arrlist_change_key($res['matches'], 'id'); $newlist = array(); $forums = array(); foreach ((array) $res['matches'] as $v) { if (empty($v['attrs'])) { continue; } if (empty($v['attrs']['fid'])) { continue; } $fid = $v['attrs']['fid']; $thread = thread_read($v['attrs']['tid']); if (empty($thread)) { continue; } if (stripos($thread['subject'], $keyword) === FALSE) { continue; } $thread['subject'] = str_replace($keyword, '<span class="red">' . $keyword . '</span>', $thread['subject']); $newlist[] = $thread; } } // --------------> 再搜索主索引 $start = ($page - 1) * $pagesize; $cl->SetLimits($start, $pagesize, 1000); // 最大结果集 $res = $cl->Query($keyword, $conf['sphinx_datasrc']); if (!empty($cl->_error)) { return xn_error(-1, 'Sphinx 错误:' . $cl->_error); } if (empty($res) || empty($res['total'])) { $res['matches'] = $deltamatch; } else { arrlist_change_key($res['matches'], 'id'); } $threadlist = array(); foreach ((array) $res['matches'] as $v) { if (empty($v['attrs'])) { continue; } if (empty($v['attrs']['fid'])) { continue; } $fid = $v['attrs']['fid']; $thread = thread_read($v['attrs']['tid']); if (empty($thread)) { continue; } $thread['subject'] = str_replace($keyword, '<span class="red">' . $keyword . '</span>', $thread['subject']); $threadlist[] = $thread; } $arrlist = $newlist + $threadlist; return $arrlist; }
function plugin_unstall_code($file, $code) { $range_start = range_start_keyword($file, $code); if ($range_start === FALSE) { return xn_error(-1, '未找到特定字符串,可能版本不对或插件已经卸载。'); } $range_end = $range_start + strlen($code . $keyword); if (range_start_keyword($file, $code) === FALSE) { return xn_error(-1, '插件点已经卸载。'); } $plugin = array('file' => $file, 'range_start' => $range_start, 'range_end' => $range_end, 'code' => $keyword); return plugin_install($plugin); }