PageRenderTime 30ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 1ms

/uploads/include/common.func.php

http://pj-photohost.googlecode.com/
PHP | 1082 lines | 1027 code | 42 blank | 13 comment | 68 complexity | aa5d0f39976290cdd3a472720b7f7b1f MD5 | raw file
Possible License(s): LGPL-2.1
  1. <?php
  2. if(!defined('DEDEINC')) exit('dedecms');
  3. require_once(DEDEINC.'/charset.func.php');
  4. //???????
  5. $pinyins = Array();
  6. $g_ftpLink = false;
  7. //?????????
  8. function GetCurUrl()
  9. {
  10. if(!empty($_SERVER["REQUEST_URI"]))
  11. {
  12. $scriptName = $_SERVER["REQUEST_URI"];
  13. $nowurl = $scriptName;
  14. }
  15. else
  16. {
  17. $scriptName = $_SERVER["PHP_SELF"];
  18. if(empty($_SERVER["QUERY_STRING"]))
  19. {
  20. $nowurl = $scriptName;
  21. }
  22. else
  23. {
  24. $nowurl = $scriptName."?".$_SERVER["QUERY_STRING"];
  25. }
  26. }
  27. return $nowurl;
  28. }
  29. //??php4
  30. if(!function_exists('file_put_contents'))
  31. {
  32. function file_put_contents($n,$d)
  33. {
  34. $f=@fopen($n,"w");
  35. if (!$f)
  36. {
  37. return false;
  38. }
  39. else
  40. {
  41. fwrite($f,$d);
  42. fclose($f);
  43. return true;
  44. }
  45. }
  46. }
  47. //??????????
  48. function MyDate($format='Y-m-d H:i:s',$timest=0)
  49. {
  50. global $cfg_cli_time;
  51. $addtime = $cfg_cli_time * 3600;
  52. if(empty($format))
  53. {
  54. $format = 'Y-m-d H:i:s';
  55. }
  56. return gmdate ($format,$timest+$addtime);
  57. }
  58. function GetAlabNum($fnum)
  59. {
  60. $nums = array("?","?","?","?","?","?","?","?","?","?");
  61. //$fnums = "0123456789";
  62. $fnums = array("0","1","2","3","4","5","6","7","8","9");
  63. $fnum = str_replace($nums,$fnums,$fnum);
  64. $fnum = ereg_replace("[^0-9\.-]",'',$fnum);
  65. if($fnum=='')
  66. {
  67. $fnum=0;
  68. }
  69. return $fnum;
  70. }
  71. function Html2Text($str,$r=0)
  72. {
  73. if(!function_exists('SpHtml2Text'))
  74. {
  75. require_once(DEDEINC."/inc/inc_fun_funString.php");
  76. }
  77. if($r==0)
  78. {
  79. return SpHtml2Text($str);
  80. }
  81. else
  82. {
  83. $str = SpHtml2Text(stripslashes($str));
  84. return addslashes($str);
  85. }
  86. }
  87. //???HTML
  88. function Text2Html($txt)
  89. {
  90. $txt = str_replace(" ","?",$txt);
  91. $txt = str_replace("<","&lt;",$txt);
  92. $txt = str_replace(">","&gt;",$txt);
  93. $txt = preg_replace("/[\r\n]{1,}/isU","<br/>\r\n",$txt);
  94. return $txt;
  95. }
  96. function AjaxHead()
  97. {
  98. @header("Pragma:no-cache\r\n");
  99. @header("Cache-Control:no-cache\r\n");
  100. @header("Expires:0\r\n");
  101. }
  102. //????2????????
  103. //???request????????????
  104. function cn_substrR($str,$slen,$startdd=0)
  105. {
  106. $str = cn_substr(stripslashes($str),$slen,$startdd);
  107. return addslashes($str);
  108. }
  109. //????2????????
  110. function cn_substr($str,$slen,$startdd=0)
  111. {
  112. global $cfg_soft_lang;
  113. if($cfg_soft_lang=='utf-8')
  114. {
  115. return cn_substr_utf8($str,$slen,$startdd);
  116. }
  117. $restr = '';
  118. $c = '';
  119. $str_len = strlen($str);
  120. if($str_len < $startdd+1)
  121. {
  122. return '';
  123. }
  124. if($str_len < $startdd + $slen || $slen==0)
  125. {
  126. $slen = $str_len - $startdd;
  127. }
  128. $enddd = $startdd + $slen - 1;
  129. for($i=0;$i<$str_len;$i++)
  130. {
  131. if($startdd==0)
  132. {
  133. $restr .= $c;
  134. }
  135. else if($i > $startdd)
  136. {
  137. $restr .= $c;
  138. }
  139. if(ord($str[$i])>0x80)
  140. {
  141. if($str_len>$i+1)
  142. {
  143. $c = $str[$i].$str[$i+1];
  144. }
  145. $i++;
  146. }
  147. else
  148. {
  149. $c = $str[$i];
  150. }
  151. if($i >= $enddd)
  152. {
  153. if(strlen($restr)+strlen($c)>$slen)
  154. {
  155. break;
  156. }
  157. else
  158. {
  159. $restr .= $c;
  160. break;
  161. }
  162. }
  163. }
  164. return $restr;
  165. }
  166. //utf-8????????????
  167. function cn_substr_utf8($str, $length, $start=0)
  168. {
  169. if(strlen($str) < $start+1)
  170. {
  171. return '';
  172. }
  173. preg_match_all("/./su", $str, $ar);
  174. $str = '';
  175. $tstr = '';
  176. //????mysql4.1????,????varchar??,?????????
  177. for($i=0; isset($ar[0][$i]); $i++)
  178. {
  179. if(strlen($tstr) < $start)
  180. {
  181. $tstr .= $ar[0][$i];
  182. }
  183. else
  184. {
  185. if(strlen($str) < $length + strlen($ar[0][$i]) )
  186. {
  187. $str .= $ar[0][$i];
  188. }
  189. else
  190. {
  191. break;
  192. }
  193. }
  194. }
  195. return $str;
  196. }
  197. function GetMkTime($dtime)
  198. {
  199. global $cfg_cli_time;
  200. if(!ereg("[^0-9]",$dtime))
  201. {
  202. return $dtime;
  203. }
  204. $dtime = trim($dtime);
  205. $dt = Array(1970,1,1,0,0,0);
  206. $dtime = ereg_replace("[\r\n\t]|?|?"," ",$dtime);
  207. $dtime = str_replace("?","-",$dtime);
  208. $dtime = str_replace("?","-",$dtime);
  209. $dtime = str_replace("?",":",$dtime);
  210. $dtime = str_replace("?",":",$dtime);
  211. $dtime = trim(ereg_replace("[ ]{1,}"," ",$dtime));
  212. $ds = explode(" ",$dtime);
  213. $ymd = explode("-",$ds[0]);
  214. if(!isset($ymd[1]))
  215. {
  216. $ymd = explode(".",$ds[0]);
  217. }
  218. if(isset($ymd[0]))
  219. {
  220. $dt[0] = $ymd[0];
  221. }
  222. if(isset($ymd[1]))
  223. {
  224. $dt[1] = $ymd[1];
  225. }
  226. if(isset($ymd[2]))
  227. {
  228. $dt[2] = $ymd[2];
  229. }
  230. if(strlen($dt[0])==2)
  231. {
  232. $dt[0] = '20'.$dt[0];
  233. }
  234. if(isset($ds[1]))
  235. {
  236. $hms = explode(":",$ds[1]);
  237. if(isset($hms[0]))
  238. {
  239. $dt[3] = $hms[0];
  240. }
  241. if(isset($hms[1]))
  242. {
  243. $dt[4] = $hms[1];
  244. }
  245. if(isset($hms[2]))
  246. {
  247. $dt[5] = $hms[2];
  248. }
  249. }
  250. foreach($dt as $k=>$v)
  251. {
  252. $v = ereg_replace("^0{1,}",'',trim($v));
  253. if($v=='')
  254. {
  255. $dt[$k] = 0;
  256. }
  257. }
  258. $mt = @gmmktime($dt[3],$dt[4],$dt[5],$dt[1],$dt[2],$dt[0]) - 3600 * $cfg_cli_time;
  259. if(!empty($mt))
  260. {
  261. return $mt;
  262. }
  263. else
  264. {
  265. return time();
  266. }
  267. }
  268. function SubDay($ntime,$ctime)
  269. {
  270. $dayst = 3600 * 24;
  271. $cday = ceil(($ntime-$ctime)/$dayst);
  272. return $cday;
  273. }
  274. function AddDay($ntime,$aday)
  275. {
  276. $dayst = 3600 * 24;
  277. $oktime = $ntime + ($aday * $dayst);
  278. return $oktime;
  279. }
  280. function GetDateTimeMk($mktime)
  281. {
  282. return MyDate('Y-m-d H:i:s',$mktime);
  283. }
  284. function GetDateMk($mktime)
  285. {
  286. return MyDate("Y-m-d",$mktime);
  287. }
  288. function GetIP()
  289. {
  290. if(!empty($_SERVER["HTTP_CLIENT_IP"]))
  291. {
  292. $cip = $_SERVER["HTTP_CLIENT_IP"];
  293. }
  294. else if(!empty($_SERVER["HTTP_X_FORWARDED_FOR"]))
  295. {
  296. $cip = $_SERVER["HTTP_X_FORWARDED_FOR"];
  297. }
  298. else if(!empty($_SERVER["REMOTE_ADDR"]))
  299. {
  300. $cip = $_SERVER["REMOTE_ADDR"];
  301. }
  302. else
  303. {
  304. $cip = '';
  305. }
  306. preg_match("/[\d\.]{7,15}/", $cip, $cips);
  307. $cip = isset($cips[0]) ? $cips[0] : 'unknown';
  308. unset($cips);
  309. return $cip;
  310. }
  311. //?????gbk????
  312. function GetPinyin($str,$ishead=0,$isclose=1)
  313. {
  314. global $cfg_soft_lang;
  315. if(!function_exists('SpGetPinyin'))
  316. {
  317. require_once(DEDEINC."/inc/inc_fun_funAdmin.php");
  318. }
  319. if($cfg_soft_lang=='utf-8')
  320. {
  321. return SpGetPinyin(utf82gb($str),$ishead,$isclose);
  322. }
  323. else
  324. {
  325. return SpGetPinyin($str,$ishead,$isclose);
  326. }
  327. }
  328. function GetNewInfo()
  329. {
  330. if(!function_exists('SpGetNewInfo'))
  331. {
  332. require_once(DEDEINC."/inc/inc_fun_funAdmin.php");
  333. }
  334. return SpGetNewInfo();
  335. }
  336. function UpdateStat()
  337. {
  338. include_once(DEDEINC."/inc/inc_stat.php");
  339. return SpUpdateStat();
  340. }
  341. $arrs1 = array(0x63,0x66,0x67,0x5f,0x70,0x6f,0x77,0x65,0x72,0x62,0x79);
  342. $arrs2 = array(0x20,0x3c,0x61,0x20,0x68,0x72,0x65,0x66,0x3d,0x68,0x74,0x74,0x70,0x3a,0x2f,0x2f,
  343. 0x77,0x77,0x77,0x2e,0x64,0x65,0x64,0x65,0x63,0x6d,0x73,0x2e,0x63,0x6f,0x6d,0x20,0x74,0x61,0x72,
  344. 0x67,0x65,0x74,0x3d,0x27,0x5f,0x62,0x6c,0x61,0x6e,0x6b,0x27,0x3e,0x50,0x6f,0x77,0x65,0x72,0x20,
  345. 0x62,0x79,0x20,0x44,0x65,0x64,0x65,0x43,0x6d,0x73,0x3c,0x2f,0x61,0x3e);
  346. function ShowMsg($msg,$gourl,$onlymsg=0,$limittime=0)
  347. {
  348. if(empty($GLOBALS['cfg_phpurl'])) $GLOBALS['cfg_phpurl'] = '..';
  349. $htmlhead = "<html>\r\n<head>\r\n<title>DEDECMS????</title>\r\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=gb2312\" />\r\n";
  350. $htmlhead .= "<base target='_self'/>\r\n<style>div{line-height:160%;}</style></head>\r\n<body leftmargin='0' topmargin='0'>".(isset($GLOBALS['ucsynlogin']) ? $GLOBALS['ucsynlogin'] : '')."\r\n<center>\r\n<script>\r\n";
  351. $htmlfoot = "</script>\r\n</center>\r\n</body>\r\n</html>\r\n";
  352. $litime = ($limittime==0 ? 1000 : $limittime);
  353. $func = '';
  354. if($gourl=='-1')
  355. {
  356. if($limittime==0) $litime = 5000;
  357. $gourl = "javascript:history.go(-1);";
  358. }
  359. if($gourl=='' || $onlymsg==1)
  360. {
  361. $msg = "<script>alert(\"".str_replace("\"","“",$msg)."\");</script>";
  362. }
  363. else
  364. {
  365. //????:close::objname ?, ??????id=objname??
  366. if(eregi('close::',$gourl))
  367. {
  368. $tgobj = trim(eregi_replace('close::', '', $gourl));
  369. $gourl = 'javascript:;';
  370. $func .= "window.parent.document.getElementById('{$tgobj}').style.display='none';\r\n";
  371. }
  372. $func .= " var pgo=0;
  373. function JumpUrl(){
  374. if(pgo==0){ location='$gourl'; pgo=1; }
  375. }\r\n";
  376. $rmsg = $func;
  377. $rmsg .= "document.write(\"<br /><div style='width:450px;padding:0px;border:1px solid #D1DDAA;'>";
  378. $rmsg .= "<div style='padding:6px;font-size:12px;border-bottom:1px solid #D1DDAA;background:#DBEEBD url({$GLOBALS['cfg_phpurl']}/img/wbg.gif)';'><b>DEDECMS ?????</b></div>\");\r\n";
  379. $rmsg .= "document.write(\"<div style='height:130px;font-size:10pt;background:#ffffff'><br />\");\r\n";
  380. $rmsg .= "document.write(\"".str_replace("\"","“",$msg)."\");\r\n";
  381. $rmsg .= "document.write(\"";
  382. if($onlymsg==0)
  383. {
  384. if( $gourl != 'javascript:;' && $gourl != '')
  385. {
  386. $rmsg .= "<br /><a href='{$gourl}'>????????????????...</a>";
  387. $rmsg .= "<br/></div>\");\r\n";
  388. $rmsg .= "setTimeout('JumpUrl()',$litime);";
  389. }
  390. else
  391. {
  392. $rmsg .= "<br/></div>\");\r\n";
  393. }
  394. }
  395. else
  396. {
  397. $rmsg .= "<br/><br/></div>\");\r\n";
  398. }
  399. $msg = $htmlhead.$rmsg.$htmlfoot;
  400. }
  401. echo $msg;
  402. }
  403. function ExecTime()
  404. {
  405. $time = explode(" ", microtime());
  406. $usec = (double)$time[0];
  407. $sec = (double)$time[1];
  408. return $sec + $usec;
  409. }
  410. function GetEditor($fname,$fvalue,$nheight="350",$etype="Basic",$gtype="print",$isfullpage="false")
  411. {
  412. if(!function_exists('SpGetEditor'))
  413. {
  414. require_once(DEDEINC."/inc/inc_fun_funAdmin.php");
  415. }
  416. return SpGetEditor($fname,$fvalue,$nheight,$etype,$gtype,$isfullpage);
  417. }
  418. function GetTemplets($filename)
  419. {
  420. if(file_exists($filename))
  421. {
  422. $fp = fopen($filename,"r");
  423. $rstr = fread($fp,filesize($filename));
  424. fclose($fp);
  425. return $rstr;
  426. }
  427. else
  428. {
  429. return '';
  430. }
  431. }
  432. function GetSysTemplets($filename)
  433. {
  434. return GetTemplets($GLOBALS['cfg_basedir'].$GLOBALS['cfg_templets_dir'].'/system/'.$filename);
  435. }
  436. function AttDef($oldvar,$nv)
  437. {
  438. return empty($oldvar) ? $nv : $oldvar;
  439. }
  440. function dd2char($ddnum)
  441. {
  442. $ddnum = strval($ddnum);
  443. $slen = strlen($ddnum);
  444. $okdd = '';
  445. $nn = '';
  446. for($i=0;$i<$slen;$i++)
  447. {
  448. if(isset($ddnum[$i+1]))
  449. {
  450. $n = $ddnum[$i].$ddnum[$i+1];
  451. if( ($n>96 && $n<123) || ($n>64 && $n<91) )
  452. {
  453. $okdd .= chr($n);
  454. $i++;
  455. }
  456. else
  457. {
  458. $okdd .= $ddnum[$i];
  459. }
  460. }
  461. else
  462. {
  463. $okdd .= $ddnum[$i];
  464. }
  465. }
  466. return $okdd;
  467. }
  468. function PutCookie($key,$value,$kptime=0,$pa="/")
  469. {
  470. global $cfg_cookie_encode;
  471. setcookie($key,$value,time()+$kptime,$pa);
  472. setcookie($key.'__ckMd5',substr(md5($cfg_cookie_encode.$value),0,16),time()+$kptime,$pa);
  473. }
  474. function DropCookie($key)
  475. {
  476. setcookie($key,'',time()-360000,"/");
  477. setcookie($key.'__ckMd5','',time()-360000,"/");
  478. }
  479. function GetCookie($key)
  480. {
  481. global $cfg_cookie_encode;
  482. if( !isset($_COOKIE[$key]) || !isset($_COOKIE[$key.'__ckMd5']) )
  483. {
  484. return '';
  485. }
  486. else
  487. {
  488. if($_COOKIE[$key.'__ckMd5']!=substr(md5($cfg_cookie_encode.$_COOKIE[$key]),0,16))
  489. {
  490. return '';
  491. }
  492. else
  493. {
  494. return $_COOKIE[$key];
  495. }
  496. }
  497. }
  498. function GetCkVdValue()
  499. {
  500. @session_start();
  501. return isset($_SESSION['dd_ckstr']) ? $_SESSION['dd_ckstr'] : '';
  502. }
  503. //php?????Bug?????????????session?????????????????
  504. function ResetVdValue()
  505. {
  506. @session_start();
  507. $_SESSION['dd_ckstr'] = '';
  508. $_SESSION['dd_ckstr_last'] = '';
  509. }
  510. function FtpMkdir($truepath,$mmode,$isMkdir=true)
  511. {
  512. global $cfg_basedir,$cfg_ftp_root,$g_ftpLink;
  513. OpenFtp();
  514. $ftproot = ereg_replace($cfg_ftp_root.'$','',$cfg_basedir);
  515. $mdir = ereg_replace('^'.$ftproot,'',$truepath);
  516. if($isMkdir)
  517. {
  518. ftp_mkdir($g_ftpLink,$mdir);
  519. }
  520. return ftp_site($g_ftpLink,"chmod $mmode $mdir");
  521. }
  522. function FtpChmod($truepath,$mmode)
  523. {
  524. return FtpMkdir($truepath,$mmode,false);
  525. }
  526. function OpenFtp()
  527. {
  528. global $cfg_basedir,$cfg_ftp_host,$cfg_ftp_port, $cfg_ftp_user,$cfg_ftp_pwd,$cfg_ftp_root,$g_ftpLink;
  529. if(!$g_ftpLink)
  530. {
  531. if($cfg_ftp_host=='')
  532. {
  533. echo "???????PHP????????????FTP???????????????FTP??????";
  534. exit();
  535. }
  536. $g_ftpLink = ftp_connect($cfg_ftp_host,$cfg_ftp_port);
  537. if(!$g_ftpLink)
  538. {
  539. echo "??FTP???";
  540. exit();
  541. }
  542. if(!ftp_login($g_ftpLink,$cfg_ftp_user,$cfg_ftp_pwd))
  543. {
  544. echo "??FTP???";
  545. exit();
  546. }
  547. }
  548. }
  549. function CloseFtp()
  550. {
  551. global $g_ftpLink;
  552. if($g_ftpLink)
  553. {
  554. @ftp_quit($g_ftpLink);
  555. }
  556. }
  557. function MkdirAll($truepath,$mmode)
  558. {
  559. global $cfg_ftp_mkdir,$isSafeMode,$cfg_dir_purview;
  560. if($isSafeMode||$cfg_ftp_mkdir=='Y')
  561. {
  562. return FtpMkdir($truepath,$mmode);
  563. }
  564. else
  565. {
  566. if(!file_exists($truepath))
  567. {
  568. mkdir($truepath,$cfg_dir_purview);
  569. chmod($truepath,$cfg_dir_purview);
  570. return true;
  571. }
  572. else
  573. {
  574. return true;
  575. }
  576. }
  577. }
  578. function ParCv($n)
  579. {
  580. return chr($n);
  581. }
  582. function ChmodAll($truepath,$mmode)
  583. {
  584. global $cfg_ftp_mkdir,$isSafeMode;
  585. if($isSafeMode||$cfg_ftp_mkdir=='Y')
  586. {
  587. return FtpChmod($truepath,$mmode);
  588. }
  589. else
  590. {
  591. return chmod($truepath,'0'.$mmode);
  592. }
  593. }
  594. function CreateDir($spath)
  595. {
  596. if(!function_exists('SpCreateDir'))
  597. {
  598. require_once(DEDEINC.'/inc/inc_fun_funAdmin.php');
  599. }
  600. return SpCreateDir($spath);
  601. }
  602. // $rptype = 0 ????? html??
  603. // $rptype = 1 ???? html????????????
  604. // $rptype = 2 ???? html????????????
  605. // $rptype = -1 ????? html?????
  606. function HtmlReplace($str,$rptype=0)
  607. {
  608. $str = stripslashes($str);
  609. if($rptype==0)
  610. {
  611. $str = htmlspecialchars($str);
  612. }
  613. else if($rptype==1)
  614. {
  615. $str = htmlspecialchars($str);
  616. $str = str_replace("?",' ',$str);
  617. $str = ereg_replace("[\r\n\t ]{1,}",' ',$str);
  618. }
  619. else if($rptype==2)
  620. {
  621. $str = htmlspecialchars($str);
  622. $str = str_replace("?",'',$str);
  623. $str = ereg_replace("[\r\n\t ]",'',$str);
  624. }
  625. else
  626. {
  627. $str = ereg_replace("[\r\n\t ]{1,}",' ',$str);
  628. $str = eregi_replace('script','??????',$str);
  629. $str = eregi_replace("<[/]{0,1}(link|meta|ifr|fra)[^>]*>",'',$str);
  630. }
  631. return addslashes($str);
  632. }
  633. //????????tag
  634. function GetTags($aid)
  635. {
  636. global $dsql;
  637. $tags = '';
  638. $query = "Select tag From `#@__taglist` where aid='$aid' ";
  639. $dsql->Execute('tag',$query);
  640. while($row = $dsql->GetArray('tag'))
  641. {
  642. $tags .= ($tags=='' ? $row['tag'] : ','.$row['tag']);
  643. }
  644. return $tags;
  645. }
  646. function ParamError()
  647. {
  648. ShowMsg('?????????????','javascript:;');
  649. exit();
  650. }
  651. //??????????
  652. function FilterSearch($keyword)
  653. {
  654. global $cfg_soft_lang;
  655. if($cfg_soft_lang=='utf-8')
  656. {
  657. $keyword = ereg_replace("[\"\r\n\t\$\\><']",'',$keyword);
  658. if($keyword != stripslashes($keyword))
  659. {
  660. return '';
  661. }
  662. else
  663. {
  664. return $keyword;
  665. }
  666. }
  667. else
  668. {
  669. $restr = '';
  670. for($i=0;isset($keyword[$i]);$i++)
  671. {
  672. if(ord($keyword[$i]) > 0x80)
  673. {
  674. if(isset($keyword[$i+1]) && ord($keyword[$i+1]) > 0x40)
  675. {
  676. $restr .= $keyword[$i].$keyword[$i+1];
  677. $i++;
  678. }
  679. else
  680. {
  681. $restr .= ' ';
  682. }
  683. }
  684. else
  685. {
  686. if(eregi("[^0-9a-z@#\.]",$keyword[$i]))
  687. {
  688. $restr .= ' ';
  689. }
  690. else
  691. {
  692. $restr .= $keyword[$i];
  693. }
  694. }
  695. }
  696. }
  697. return $restr;
  698. }
  699. //????HTML????????
  700. function TrimMsg($msg)
  701. {
  702. $msg = trim(stripslashes($msg));
  703. $msg = nl2br(htmlspecialchars($msg));
  704. $msg = str_replace(" ","&nbsp;&nbsp;",$msg);
  705. return addslashes($msg);
  706. }
  707. //????????
  708. function GetOneArchive($aid)
  709. {
  710. global $dsql;
  711. include_once(DEDEINC."/channelunit.func.php");
  712. $aid = trim(ereg_replace('[^0-9]','',$aid));
  713. $reArr = array();
  714. $chRow = $dsql->GetOne("Select arc.*,ch.maintable,ch.addtable,ch.issystem From `#@__arctiny` arc left join `#@__channeltype` ch on ch.id=arc.channel where arc.id='$aid' ");
  715. if(!is_array($chRow)) {
  716. return $reArr;
  717. }
  718. else {
  719. if(empty($chRow['maintable'])) $chRow['maintable'] = '#@__archives';
  720. }
  721. if($chRow['issystem']!=-1)
  722. {
  723. $nquery = " Select arc.*,tp.typedir,tp.topid,tp.namerule,tp.moresite,tp.siteurl,tp.sitepath
  724. From `{$chRow['maintable']}` arc left join `#@__arctype` tp on tp.id=arc.typeid
  725. where arc.id='$aid' ";
  726. }
  727. else
  728. {
  729. $nquery = " Select arc.*,1 as ismake,0 as money,'' as filename,tp.typedir,tp.topid,tp.namerule,tp.moresite,tp.siteurl,tp.sitepath
  730. From `{$chRow['addtable']}` arc left join `#@__arctype` tp on tp.id=arc.typeid
  731. where arc.aid='$aid' ";
  732. }
  733. $arcRow = $dsql->GetOne($nquery);
  734. if(!is_array($arcRow)) {
  735. return $reArr;
  736. }
  737. if(!isset($arcRow['description'])) {
  738. $arcRow['description'] = '';
  739. }
  740. if(empty($arcRow['description']) && isset($arcRow['body'])) {
  741. $arcRow['description'] = cn_substr(html2text($arcRow['body']),250);
  742. }
  743. if(!isset($arcRow['pubdate'])) {
  744. $arcRow['pubdate'] = $arcRow['senddate'];
  745. }
  746. if(!isset($arcRow['notpost'])) {
  747. $arcRow['notpost'] = 0;
  748. }
  749. $reArr = $arcRow;
  750. $reArr['aid'] = $aid;
  751. $reArr['topid'] = $arcRow['topid'];
  752. $reArr['arctitle'] = $arcRow['title'];
  753. $reArr['arcurl'] = GetFileUrl($aid,$arcRow['typeid'],$arcRow['senddate'],$reArr['title'],$arcRow['ismake'],$arcRow['arcrank'],$arcRow['namerule'],
  754. $arcRow['typedir'],$arcRow['money'],$arcRow['filename'],$arcRow['moresite'],$arcRow['siteurl'],$arcRow['sitepath']);
  755. return $reArr;
  756. }
  757. //????????
  758. function GetChannelTable($id,$formtype='channel')
  759. {
  760. global $dsql;
  761. if($formtype == 'archive')
  762. {
  763. $query = "select ch.maintable, ch.addtable from #@__arctiny tin left join #@__channeltype ch on ch.id=tin.channel where tin.id='$id'";
  764. }
  765. elseif($formtype == 'typeid')
  766. {
  767. $query = "select ch.maintable, ch.addtable from #@__arctype act left join #@__channeltype ch on ch.id=act.channeltype where act.id='$id'";
  768. }
  769. else
  770. {
  771. $query = "select maintable, addtable from #@__channeltype where id='$id'";
  772. }
  773. $row = $dsql->getone($query);
  774. return $row;
  775. }
  776. function jstrim($str,$len)
  777. {
  778. $str = preg_replace("/{quote}(.*){\/quote}/is",'',$str);
  779. $str = str_replace('&lt;br/&gt;',' ',$str);
  780. $str = cn_substr($str,$len);
  781. $str = ereg_replace("['\"\r\n]","",$str);
  782. return $str;
  783. }
  784. /*-------------------------------
  785. //????????????
  786. //filetype: image?media?addon
  787. //return: -1 ????????0 ???????, -2 ?????????????????
  788. //$file_type='' ??swfupload?????? ????filetype?????????????????
  789. -------------------------------*/
  790. function AdminUpload($uploadname, $ftype='image', $rnddd=0, $watermark=true, $filetype='' )
  791. {
  792. global $dsql, $cuserLogin, $cfg_addon_savetype, $cfg_dir_purview;
  793. global $cfg_basedir, $cfg_image_dir, $cfg_soft_dir, $cfg_other_medias;
  794. global $cfg_imgtype, $cfg_softtype, $cfg_mediatype;
  795. if($watermark) include_once(DEDEINC.'/image.func.php');
  796. $file_tmp = isset($GLOBALS[$uploadname]) ? $GLOBALS[$uploadname] : '';
  797. if($file_tmp=='' || !is_uploaded_file($file_tmp) )
  798. {
  799. return -1;
  800. }
  801. $file_tmp = $GLOBALS[$uploadname];
  802. $file_size = filesize($file_tmp);
  803. $file_type = $filetype=='' ? strtolower(trim($GLOBALS[$uploadname.'_type'])) : $filetype;
  804. $file_name = isset($GLOBALS[$uploadname.'_name']) ? $GLOBALS[$uploadname.'_name'] : '';
  805. $file_snames = explode('.', $file_name);
  806. $file_sname = strtolower(trim($file_snames[count($file_snames)-1]));
  807. if($ftype=='image' || $ftype=='imagelit')
  808. {
  809. $filetype = '1';
  810. $sparr = Array('image/pjpeg', 'image/jpeg', 'image/gif', 'image/png', 'image/xpng', 'image/wbmp');
  811. if(!in_array($file_type, $sparr)) return 0;
  812. if($file_sname=='')
  813. {
  814. if($file_type=='image/gif') $file_sname = 'jpg';
  815. else if($file_type=='image/png' || $file_type=='image/xpng') $file_sname = 'png';
  816. else if($file_type=='image/wbmp') $file_sname = 'bmp';
  817. else $file_sname = 'jpg';
  818. }
  819. $filedir = $cfg_image_dir.'/'.MyDate($cfg_addon_savetype, time());
  820. }
  821. else if($ftype=='media')
  822. {
  823. $filetype = '3';
  824. if( !eregi($cfg_mediatype, $file_sname) ) return 0;
  825. $filedir = $cfg_other_medias.'/'.MyDate($cfg_addon_savetype, time());
  826. }
  827. else
  828. {
  829. $filetype = '4';
  830. $cfg_softtype .= '|'.$cfg_mediatype.'|'.$cfg_imgtype;
  831. $cfg_softtype = ereg_replace('||', '|', $cfg_softtype);
  832. if( !eregi($cfg_softtype, $file_sname) ) return 0;
  833. $filedir = $cfg_soft_dir.'/'.MyDate($cfg_addon_savetype, time());
  834. }
  835. if(!is_dir(DEDEROOT.$filedir))
  836. {
  837. MkdirAll($cfg_basedir.$filedir, $cfg_dir_purview);
  838. CloseFtp();
  839. }
  840. $filename = $cuserLogin->getUserID().'-'.dd2char(MyDate('ymdHis', time())).$rnddd;
  841. if($ftype=='imagelit') $filename .= '-L';
  842. if( file_exists($cfg_basedir.$filedir.'/'.$filename.'.'.$file_sname) )
  843. {
  844. for($i=50; $i <= 5000; $i++)
  845. {
  846. if( !file_exists($cfg_basedir.$filedir.'/'.$filename.'-'.$i.'.'.$file_sname) )
  847. {
  848. $filename = $filename.'-'.$i;
  849. break;
  850. }
  851. }
  852. }
  853. $fileurl = $filedir.'/'.$filename.'.'.$file_sname;
  854. $rs = move_uploaded_file($file_tmp, $cfg_basedir.$fileurl);
  855. if(!$rs) return -2;
  856. if($ftype=='image' && $watermark)
  857. {
  858. WaterImg($cfg_basedir.$fileurl, 'up');
  859. }
  860. //????????
  861. $title = $filename.'.'.$file_sname;
  862. $inquery = "INSERT INTO `#@__uploads`(title,url,mediatype,width,height,playtime,filesize,uptime,mid)
  863. VALUES ('$title','$fileurl','$filetype','0','0','0','".filesize($cfg_basedir.$fileurl)."','".time()."','".$cuserLogin->getUserID()."'); ";
  864. $dsql->ExecuteNoneQuery($inquery);
  865. $fid = $dsql->GetLastID();
  866. AddMyAddon($fid, $fileurl);
  867. return $fileurl;
  868. }
  869. //??????
  870. function CheckEmail($email)
  871. {
  872. return eregi("^[0-9a-z][a-z0-9\._-]{1,}@[a-z0-9-]{1,}[a-z0-9]\.[a-z\.]{1,}[a-z]$", $email);
  873. }
  874. //??????????
  875. //$upname ???????????????????
  876. //$handname ????????????????
  877. function MemberUploads($upname,$handname,$userid=0,$utype='image',$exname='',$maxwidth=0,$maxheight=0,$water=false,$isadmin=false)
  878. {
  879. global $cfg_imgtype,$cfg_mb_addontype,$cfg_mediatype,$cfg_user_dir,$cfg_basedir,$cfg_dir_purview;
  880. //????????????? id ? 0
  881. if( empty($userid) ) $userid = 0;
  882. if(!is_dir($cfg_basedir.$cfg_user_dir."/$userid"))
  883. {
  884. MkdirAll($cfg_basedir.$cfg_user_dir."/$userid", $cfg_dir_purview);
  885. CloseFtp();
  886. }
  887. //?????
  888. $allAllowType = str_replace('||', '|', $cfg_imgtype.'|'.$cfg_mediatype.'|'.$cfg_mb_addontype);
  889. if(!empty($GLOBALS[$upname]) && is_uploaded_file($GLOBALS[$upname]))
  890. {
  891. $nowtme = time();
  892. $GLOBALS[$upname.'_name'] = trim(ereg_replace("[ \r\n\t\*\%\\/\?><\|\":]{1,}",'',$GLOBALS[$upname.'_name']));
  893. //???????
  894. if($utype=='image')
  895. {
  896. if(!eregi("\.(".$cfg_imgtype.")$", $GLOBALS[$upname.'_name']))
  897. {
  898. ShowMsg("???????????????????{$cfg_imgtype}???",'-1');
  899. exit();
  900. }
  901. $sparr = Array("image/pjpeg","image/jpeg","image/gif","image/png","image/xpng","image/wbmp");
  902. $imgfile_type = strtolower(trim($GLOBALS[$upname.'_type']));
  903. if(!in_array($imgfile_type,$sparr))
  904. {
  905. ShowMsg('?????????????JPEG?GIF?PNG?WBMP????????', '-1');
  906. exit();
  907. }
  908. }
  909. else if($utype=='flash' && !eregi("\.swf$", $GLOBALS[$upname.'_name']))
  910. {
  911. ShowMsg('????????flash???', '-1');
  912. exit();
  913. }
  914. else if($utype=='media' && !eregi("\.(".$cfg_mediatype.")$",$GLOBALS[$upname.'_name']))
  915. {
  916. ShowMsg('?????????????'.$cfg_mediatype, '-1');
  917. exit();
  918. }
  919. else if(!eregi("\.(".$allAllowType.")$", $GLOBALS[$upname.'_name']))
  920. {
  921. ShowMsg("??????????????",'-1');
  922. exit();
  923. }
  924. //??????????????????????
  925. $fs = explode('.', $GLOBALS[$upname.'_name']);
  926. $sname = $fs[count($fs)-1];
  927. $alltypes = explode('|', $allAllowType);
  928. if(!in_array(strtolower($sname), $alltypes))
  929. {
  930. ShowMsg('??????????????', '-1');
  931. exit();
  932. }
  933. //?????????
  934. if(eregi("\.(asp|php|pl|cgi|shtm|js)", $sname))
  935. {
  936. ShowMsg('???????????????', '-1');
  937. exit();
  938. }
  939. if($exname=='')
  940. {
  941. $filename = $cfg_user_dir."/$userid/".dd2char($nowtme.'-'.mt_rand(1000,9999)).'.'.$sname;
  942. }
  943. else
  944. {
  945. $filename = $cfg_user_dir."/{$userid}/{$exname}.".$sname;
  946. }
  947. move_uploaded_file($GLOBALS[$upname],$cfg_basedir.$filename) or die("????? {$filename} ???");
  948. @unlink($GLOBALS[$upname]);
  949. if(@filesize($cfg_basedir.$filename) > $GLOBALS['cfg_mb_upload_size'] * 1024)
  950. {
  951. @unlink($cfg_basedir.$filename);
  952. ShowMsg('???????????????', '-1');
  953. exit();
  954. }
  955. //????????
  956. if($utype=='image')
  957. {
  958. include_once(DEDEINC.'/image.func.php');
  959. if($maxwidth>0 || $maxheight>0)
  960. {
  961. ImageResize($cfg_basedir.$filename, $maxwidth, $maxheight);
  962. }
  963. else if($water)
  964. {
  965. WaterImg($cfg_basedir.$filename);
  966. }
  967. }
  968. return $filename;
  969. }
  970. //??????
  971. else
  972. {
  973. //?????????
  974. if($handname=='')
  975. {
  976. return $handname;
  977. }
  978. else if(eregi("\.(asp|php|pl|cgi|shtm|js)", $handname))
  979. {
  980. exit('Not allow filename for not safe!');
  981. }
  982. else if( !eregi("\.(".$allAllowType.")$", $handname) )
  983. {
  984. exit('Not allow filename for filetype!');
  985. }
  986. else if( !eregi('^http:', $handname) && !eregi('^'.$cfg_user_dir.'/'.$userid, $handname) && !$isadmin )
  987. {
  988. exit('Not allow filename for not userdir!');
  989. }
  990. return $handname;
  991. }
  992. }
  993. //???????
  994. if( file_exists(DEDEINC.'/extend.func.php') )
  995. {
  996. require_once(DEDEINC.'/extend.func.php');
  997. }
  998. ?>