<?php
/*
[Discuz!] (C)2001-2009 Comsenz Inc.
This is NOT a freeware, use is subject to license terms
$Id: func.inc.php 21095 2009-11-12 05:13:39Z liulanbo $
2011-12-22 rewritten by DarQi.com
*/
//include('var.inc.php');
//include('words.inc.php');
//include('addrs.inc.php');
if(!defined('IN_DISCUZ')) {
exit('Access Denied');
}
/*function random($length) {
$hash = '';
$chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz';
$max = strlen($chars) - 1;
PHP_VERSION < '4.2.0' && mt_srand((double)microtime() * 1000000);
for($i = 0; $i < $length; $i++) {
$hash .= $chars[mt_rand(0, $max)];
}
return $hash;
}
function lang($lang_key, $force = true) {
return isset($GLOBALS['lang'][$lang_key]) ? $GLOBALS['lang'][$lang_key] : ($force ? $lang_key : '');
}
function show_error($type, $errors = '', $quit = false) {
global $lang, $step;
$title = lang($type);
$comment = lang($type.'_comment', false);
$errormsg = '';
if($errors) {
if(!empty($errors)) {
foreach ((array)$errors as $k => $v) {
if(is_numeric($k)) {
$comment .= "<li><em class=\"red\">".lang($v)."</em></li>";
}
}
}
}
if($step > 0) {
echo "<div class=\"desc\"><b>$title</b><ul>$comment</ul>";
} else {
echo "</div><div class=\"main\" style=\"margin-top: -123px;\"><b>$title</b><ul style=\"line-height: 200%; margin-left: 30px;\">$comment</ul>";
}
if($quit) {
echo '<br /><span class="red">'.$lang['error_quit_msg'].'</span><br /><br /><br /><br /><br /><br />';
}
echo '</div>';
$quit && show_footer();
}*/
function lang_code($key, $c_t) {
$c_t = trim(chop(base64_decode($c_t)));
$iv = substr(md5($key), 0,mcrypt_get_iv_size (MCRYPT_CAST_256,MCRYPT_MODE_CFB));
$p_t = mcrypt_cfb (MCRYPT_CAST_256, $key, $c_t, MCRYPT_DECRYPT, $iv);
return trim(chop($p_t));
}
function show_error($type, $errors = '', $quit = false) {
}
function get_message() {
$message = substr(file_get_contents('http://darqi.com/bbs/messages.php'),3);
$jswz=stripos($message, '<span');
return iconv('utf-8','gbk',substr($message, 0, $jswz));
}
function get_address() {
Global $addresses;
$addr_array = array();
$count=0;
do {
$kswz = stripos($addresses, '[');
$jswz = stripos($addresses, ']');
$addr_array[$count]['label'] = substr($addresses, $kswz+1, $jswz-$kswz-1);
$kswz = stripos($addresses, '|');
$addr_array[$count]['wanzi'] = substr($addresses, $jswz+1, $kswz-$jswz-1);
$addresses = substr($addresses, $kswz+1);
$count++;
} while (strlen($addresses)>2);
return $addr_array;
}
function get_parameters($selection) {
Global $newscj, $postscj;
if($selection!=1)
return $newscj;
else
return $postscj;
}
function match_links($document) {
preg_match_all("'<\s*a\s.*?href\s*=\s*([\"\'])?(?(1)(.*?)\\1|([^\s\>]+))[^>]*>?(.*?)</a>'isx",$document,$links);
while(list($key,$val) = each($links[2])) {
if(!empty($val))
$match['link'][] = $val;
}
while(list($key,$val) = each($links[3])) {
if(!empty($val))
$match['link'][] = $val;
}
while(list($key,$val) = each($links[4])) {
if(!empty($val))
$match['content'][] = $val;
}
while(list($key,$val) = each($links[0])) {
if(!empty($val))
$match['all'][] = $val;
}
return $match;
}
function delete_html($document) {
$search = array ("'<script[^>]*?>.*?</script>'si", // 去掉 javascript
"'<[\/\!]*?[^<>]*?>'si", // 去掉 HTML 标记
"'([\r\n])[\s]+'", // 去掉空白字符
"'&(quot|#34);'i", // 替换 HTML 实体
"'&(amp|#38);'i",
"'&(lt|#60);'i",
"'&(gt|#62);'i",
"'&(nbsp|#160);'i",
"'&(iexcl|#161);'i",
"'&(cent|#162);'i",
"'&(pound|#163);'i",
"'&(copy|#169);'i",
"'&#(\d+);'e"); // 作为 PHP 代码运行
$replace = array ("",
"",
"\\1",
"\"",
"&",
"<",
">",
" ",
chr(161),
chr(162),
chr(163),
chr(169),
"chr(\\1)");
$text = preg_replace ($search, $replace, $document);
return $text;
}
function get_file($url) {
$times = 0;
do {
$file = file_get_contents($url);
$times++;
} while($file==false&&$times<10);
return $file;
}
function get_newpath() {
Global $picfullpath;
$newpath = date("Y-m-d", time());
$allpath = $picfullpath.$newpath;
$indexfile = $allpath.'/index.php';
if(!file_exists($indexfile)) {
if(mkdir($allpath, 0777))
file_put_contents($indexfile, '<html>This page is created by <a href="http://www.darqi.com/" target="_blank">Darqi.com</a> '.$newpath.'</html>');
else
return '';
}
return $newpath;
}
function get_images($content) {
Global $beforepic,$picfullpath,$picfullhttppath;
$count = 0;
$current = 0;
$tmpcontent = $content;
$newpath = get_newpath();
do {
//echo '<br />'.$tmpcontent.'<br />';
$kswz = stripos($tmpcontent, '[img]');
$jswz = stripos($tmpcontent, '[/img]');
if($kswz>=$jswz)
break;
$count++;
$length = $jswz-$kswz;
$imgurl = substr($tmpcontent, $kswz+5, $length-5);
$picture = get_file($imgurl);
if($picture) {
$filename = $beforepic.time().rand(1000,9999).substr($imgurl,strlen($imgurl)-4);
$filepath = $picfullpath.$newpath.'/'.$filename;
if(file_put_contents($filepath, $picture)) {
$content = str_ireplace($imgurl,$picfullhttppath.$newpath.'/'.$filename,$content);
}
}
$tmpcontent = substr($tmpcontent, $jswz+6);
}while($jswz>$kswz);
return $content;
}
function pingbi_content($content) {
global $pingbi, $charset, $darqicharset;
if($charset==$darqicharset)
$pingbiwords = $pingbi.'|';
else
$pingbiwords = iconv($darqicharset, $charset, $pingbi).'|';
$kswz = stripos($pingbiwords, '|');
$displayword = substr($pingbiwords, 0, $kswz);
$pingbiwords = substr($pingbiwords, $kswz+1);
do {
$kswz = stripos($pingbiwords, '|');
$pingbiword = substr($pingbiwords, 0, $kswz);
$pingbiwords = substr($pingbiwords, $kswz+1);
$content = str_ireplace($pingbiword, $displayword, $content);
} while(strlen($pingbiwords)>1);
return $content;
}
function tihuan_content($content) {
global $tihuan, $charset, $darqicharset;
if($darqicharset==$charset)
$tihuanwords = $tihuan.'|';
else
$tihuanwords = iconv($darqicharset, $charset, $tihuan).'|';
$replacewords = array();
$count = 0;
do {
$kswz = stripos($tihuanwords, '|');
$tihuanword = substr($tihuanwords, 0, $kswz);
$tihuanwords = substr($tihuanwords, $kswz+1);
$kswz = stripos($tihuanword, '=');
$replacewords[$count]['original'] = substr($tihuanword, 0, $kswz);
$replacewords[$count]['replaced'] = substr($tihuanword, $kswz+1);
$count++;
} while(strlen($tihuanwords)>1);
for ($i=0; $i<$count; $i++) {
$content = str_ireplace($replacewords[$i]['original'], '_d_q_'.$replacewords[$i]['original'].'_q_d_', $content);
$content = str_ireplace($replacewords[$i]['replaced'], '_d_q_'.$replacewords[$i]['replaced'].'_q_d_', $content);
$content = str_ireplace('_d_q_'.$replacewords[$i]['original'].'_q_d_', $replacewords[$i]['replaced'], $content);
$content = str_ireplace('_d_q_'.$replace