PageRenderTime 46ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/php/xuzhou58/xuzhou58.com/member/inc/inc_archives_functions.php

http://jqbird.googlecode.com/
PHP | 451 lines | 446 code | 1 blank | 4 comment | 2 complexity | 4be7fca0d3ee25aa998fb61f02edeebf MD5 | raw file
Possible License(s): GPL-3.0, LGPL-3.0, LGPL-2.1, GPL-2.0
  1. <?php
  2. if(!defined('DEDEMEMBER')) exit('dedecms');
  3. require_once(DEDEINC.'/image.func.php');
  4. require_once(DEDEINC.'/archives.func.php');
  5. require_once(DEDEINC."/userlogin.class.php");
  6. //?????????
  7. CheckNotAllow();
  8. //---------------------------
  9. //??HTML???????????
  10. //---------------------
  11. function GetCurContentAlbum($body,$rfurl,&$firstdd)
  12. {
  13. global $cfg_multi_site,$cfg_basehost,$ddmaxwidth,$cfg_basedir,$pagestyle,$cfg_mb_rmdown,$title,$cfg_ml,$cfg_user_dir;
  14. include_once(DEDEINC."/dedecollection.func.php");
  15. if(empty($ddmaxwidth)) $ddmaxwidth = 240;
  16. $rsimg = '';
  17. $basehost = "http://".$_SERVER["HTTP_HOST"];
  18. $img_array = array();
  19. preg_match_all("/(src|SRC)=[\"|'| ]{0,}(http:\/\/([^>]*)\.(gif|jpg|png))/isU",$body,$img_array);
  20. $img_array = array_unique($img_array[2]);
  21. $imgUrl = $cfg_user_dir."/".$cfg_ml->M_ID;
  22. $imgPath = $cfg_basedir.$imgUrl;
  23. if(!is_dir($imgPath."/"))
  24. {
  25. MkdirAll($imgPath,$GLOBALS['cfg_dir_purview']);
  26. CloseFtp();
  27. }
  28. $milliSecond = MyDate("ymdHis",time());
  29. foreach($img_array as $key=>$value)
  30. {
  31. if(eregi($basehost,$value))
  32. {
  33. continue;
  34. }
  35. if($cfg_basehost!=$basehost && eregi($cfg_basehost,$value))
  36. {
  37. continue;
  38. }
  39. if(!eregi("^http://",$value))
  40. {
  41. continue;
  42. }
  43. if($cfg_mb_rmdown=='Y')
  44. {
  45. $value = trim($value);
  46. $itype = substr($value,-4,4);
  47. if(!eregi("\.(gif|jpg|png)",$itype))
  48. {
  49. $itype = ".jpg";
  50. }
  51. $rndFileName = $imgPath."/".$milliSecond.$key.$itype;
  52. $iurl = $imgUrl."/".$milliSecond.$key.$itype;
  53. //???????
  54. //$rs = $htd->SaveToBin($rndFileName);
  55. $rs = DownImageKeep($value,$rfurl,$rndFileName,'',0,30);
  56. if($rs)
  57. {
  58. if($pagestyle > 2)
  59. {
  60. $litpicname = GetImageMapDD($iurl,$ddmaxwidth);
  61. if($litpicname!='')
  62. {
  63. SaveUploadInfo($title,$litpicname,1,$addinfos);
  64. }
  65. }
  66. else
  67. {
  68. $litpicname = '';
  69. }
  70. if(empty($firstdd))
  71. {
  72. $firstdd = $litpicname;
  73. if(!file_exists($cfg_basedir.$firstdd))
  74. {
  75. $firstdd = $iurl;
  76. }
  77. }
  78. @WaterImg($rndFileName,'down');
  79. $info = '';
  80. $imginfos = GetImageSize($rndFileName,$info);
  81. SaveUploadInfo($title,$iurl,1,$imginfos);
  82. $rsimg .= "{dede:img ddimg='$litpicname' text='' width='".$imginfos[0]."' height='".$imginfos[1]."'} $iurl {/dede:img}\r\n";
  83. }
  84. }
  85. else
  86. {
  87. $rsimg .= "{dede:img ddimg='$value' text='' width='0' height='0'} $value {/dede:img}\r\n";
  88. }
  89. }
  90. return $rsimg;
  91. }
  92. //????????
  93. function GetImageMapDD($filename, $ddm, $oldname='')
  94. {
  95. if($oldname!='' && !eregi("^http://",$oldname))
  96. {
  97. $ddpicok = $oldname;
  98. }
  99. else
  100. {
  101. $ddn = substr($filename,-3);
  102. $ddpicok = ereg_replace("\.".$ddn."$", "-lp.".$ddn, $filename);
  103. }
  104. $toFile = $GLOBALS['cfg_basedir'].$ddpicok;
  105. ImageResize($GLOBALS['cfg_basedir'].$filename, $ddm, 300, $toFile);
  106. return $ddpicok;
  107. }
  108. //-----------------------
  109. //????????????
  110. //------------------------
  111. function SaveUploadInfo($title,$filename,$medaitype=1,$addinfos='')
  112. {
  113. global $dsql,$cfg_ml,$cfg_basedir;
  114. if($filename=='')
  115. {
  116. return false;
  117. }
  118. if(!is_array($addinfos))
  119. {
  120. $addinfos[0] = $addinfos[1] = $addinfos[2] = 0;
  121. }
  122. if($medaitype==1)
  123. {
  124. $info = '';
  125. $addinfos = GetImageSize($cfg_basedir.$filename,$info);
  126. }
  127. $addinfos[2] = @filesize($cfg_basedir.$filename);
  128. $row = $dsql->GetOne("Select aid,title,url From `#@__uploads` where url like '$filename' And mid='".$cfg_ml->M_ID."'; ");
  129. $uptime = time();
  130. if(is_array($row))
  131. {
  132. $query = "Update `#@__uploads` set title='$title',mediatype='$medaitype',
  133. width='{$addinfos[0]}',height='{$addinfos[1]}',filesize='{$addinfos[2]}',uptime='$uptime'
  134. where aid='{$row['aid']}'; ";
  135. $dsql->ExecuteNoneQuery($query);
  136. }
  137. else
  138. {
  139. $inquery = "INSERT INTO `#@__uploads`(title,url,mediatype,width,height,playtime,filesize,uptime,mid)
  140. VALUES ('$title','$filename','$medaitype','".$addinfos[0]."','".$addinfos[1]."','0','".$addinfos[2]."','$uptime','".$cfg_ml->M_ID."'); ";
  141. $dsql->ExecuteNoneQuery($inquery);
  142. }
  143. $fid = $dsql->GetLastID();
  144. AddMyAddon($fid, $filename);
  145. return true;
  146. }
  147. //????????
  148. //-----------------------------
  149. function GetFormItemA($ctag)
  150. {
  151. return GetFormItem($ctag,'member');
  152. }
  153. //---------------------------
  154. //?????????
  155. //---------------------------
  156. function GetFieldValueA($dvalue,$dtype,$aid=0,$job='add',$addvar='')
  157. {
  158. return GetFieldValue($dvalue,$dtype,$aid,$job,$addvar,'member');
  159. }
  160. //???????(????)
  161. //-----------------------------
  162. function GetFormItemValueA($ctag,$fvalue)
  163. {
  164. return GetFormItemValue($ctag,$fvalue,'member');
  165. }
  166. //???????(????)
  167. function PrintAutoFieldsAdd(&$fieldset,$loadtype='all')
  168. {
  169. $dtp = new DedeTagParse();
  170. $dtp->SetNameSpace('field','<','>');
  171. $dtp->LoadSource($fieldset);
  172. $dede_addonfields = '';
  173. if(is_array($dtp->CTags))
  174. {
  175. foreach($dtp->CTags as $tid=>$ctag)
  176. {
  177. if($loadtype!='autofield' || $ctag->GetAtt('autofield')==1 )
  178. {
  179. $dede_addonfields .= ( $dede_addonfields=="" ? $ctag->GetName().",".$ctag->GetAtt('type') : ";".$ctag->GetName().",".$ctag->GetAtt('type') );
  180. echo GetFormItemA($ctag);
  181. }
  182. }
  183. }
  184. echo "<input type='hidden' name='dede_addonfields' value=\"".$dede_addonfields."\">\r\n";
  185. }
  186. //???????(????)
  187. function PrintAutoFieldsEdit(&$fieldset,&$fieldValues,$loadtype='all')
  188. {
  189. $dtp = new DedeTagParse();
  190. $dtp->SetNameSpace("field","<",">");
  191. $dtp->LoadSource($fieldset);
  192. $dede_addonfields = "";
  193. if(is_array($dtp->CTags))
  194. {
  195. foreach($dtp->CTags as $tid=>$ctag)
  196. {
  197. if($loadtype!='autofield'
  198. || ($loadtype=='autofield' && $ctag->GetAtt('autofield')==1) )
  199. {
  200. $dede_addonfields .= ( $dede_addonfields=='' ? $ctag->GetName().",".$ctag->GetAtt('type') : ";".$ctag->GetName().",".$ctag->GetAtt('type') );
  201. echo GetFormItemValueA($ctag,$fieldValues[$ctag->GetName()]);
  202. }
  203. }
  204. }
  205. echo "<input type='hidden' name='dede_addonfields' value=\"".$dede_addonfields."\">\r\n";
  206. }
  207. //-----------------------
  208. //????ID???
  209. //-----------------------
  210. function MakeArt($aid,$ismakesign=false)
  211. {
  212. global $cfg_makeindex,$cfg_basedir,$cfg_templets_dir,$cfg_df_style;
  213. include_once(DEDEINC.'/arc.archives.class.php');
  214. if($ismakesign)
  215. {
  216. $envs['makesign'] = 'yes';
  217. }
  218. $arc = new Archives($aid);
  219. $reurl = $arc->MakeHtml();
  220. if(isset($typeid))
  221. {
  222. $preRow = $arc->dsql->GetOne("Select id From `#@__arctiny` where id<$aid And arcrank>-1 And typeid='$typeid' order by id desc");
  223. $nextRow = $arc->dsql->GetOne("Select id From `#@__arctiny` where id>$aid And arcrank>-1 And typeid='$typeid' order by id asc");
  224. if(is_array($preRow))
  225. {
  226. $arc = new Archives($preRow['id']);
  227. $arc->MakeHtml();
  228. }
  229. if(is_array($nextRow))
  230. {
  231. $arc = new Archives($nextRow['id']);
  232. $arc->MakeHtml();
  233. }
  234. }
  235. return $reurl;
  236. }
  237. //??HTML????????????????
  238. function AnalyseHtmlBody($body,&$description,$dtype='')
  239. {
  240. global $cfg_mb_rmdown,$cfg_basehost,$cfg_auot_description,$arcID;
  241. $autolitpic = (empty($autolitpic) ? '' : $autolitpic);
  242. $body = stripslashes($body);
  243. //???????
  244. if($cfg_mb_rmdown=='Y')
  245. {
  246. $body = GetCurContent($body);
  247. }
  248. //????
  249. if($description=='' && $cfg_auot_description>0)
  250. {
  251. $description = cn_substr(html2text($body),$cfg_auot_description);
  252. $description = trim(preg_replace('/#p#|#e#/','',$description));
  253. $description = addslashes($description);
  254. }
  255. $body = addslashes($body);
  256. return $body;
  257. }
  258. //---------------------------
  259. //????body??????
  260. //---------------------------
  261. function GetCurContent(&$body)
  262. {
  263. global $cfg_multi_site,$cfg_basehost,$cfg_basedir,$cfg_user_dir,$title,$cfg_ml;
  264. include_once(DEDEINC."/dedecollection.func.php");
  265. $htd = new DedeHttpDown();
  266. $basehost = "http://".$_SERVER["HTTP_HOST"];
  267. $img_array = array();
  268. preg_match_all("/(src|SRC)=[\"|'| ]{0,}(http:\/\/([^>]*)\.(gif|jpg|png))/isU",$body,$img_array);
  269. $img_array = array_unique($img_array[2]);
  270. $imgUrl = $cfg_user_dir."/".$cfg_ml->M_ID;
  271. $imgPath = $cfg_basedir.$imgUrl;
  272. if(!is_dir($imgPath."/"))
  273. {
  274. MkdirAll($imgPath,$GLOBALS['cfg_dir_purview']);
  275. CloseFtp();
  276. }
  277. $milliSecond = MyDate("ymdHis",time());
  278. foreach($img_array as $key=>$value)
  279. {
  280. if(eregi($basehost,$value))
  281. {
  282. continue;
  283. }
  284. if($cfg_basehost!=$basehost && eregi($cfg_basehost,$value))
  285. {
  286. continue;
  287. }
  288. if(!eregi("^http://",$value))
  289. {
  290. continue;
  291. }
  292. $htd->OpenUrl($value);
  293. $itype = $htd->GetHead("content-type");
  294. $itype = substr($value,-4,4);
  295. if(!eregi("\.(jpg|gif|png)",$itype))
  296. {
  297. if($itype=='image/gif')
  298. {
  299. $itype = ".gif";
  300. }
  301. else if($itype=='image/png')
  302. {
  303. $itype = ".png";
  304. }
  305. else
  306. {
  307. $itype = '.jpg';
  308. }
  309. }
  310. $milliSecondN = dd2char($milliSecond.'-'.mt_rand(1000,8000));
  311. $value = trim($value);
  312. $rndFileName = $imgPath."/".$milliSecondN.'-'.$key.$itype;
  313. $fileurl = $imgUrl."/".$milliSecondN.'-'.$key.$itype;
  314. $rs = $htd->SaveToBin($rndFileName);
  315. if($rs)
  316. {
  317. $body = str_replace($value,$fileurl,$body);
  318. @WaterImg($rndFileName,'down');
  319. }
  320. $info = '';
  321. $imginfos = GetImageSize($rndFileName,$info);
  322. SaveUploadInfo($title,$fileurl,1,$imginfos);
  323. }
  324. $htd->Close();
  325. return $body;
  326. }
  327. //------------------------
  328. //???????????
  329. //------------------------
  330. /*
  331. //??? upname ?????
  332. //??? handurl ???????
  333. //??? ddisremote ???????? 0 ??, 1 ??
  334. //??? ntitle ???? ????? title ?????
  335. */
  336. function UploadOneImage($upname,$handurl='',$isremote=1,$ntitle='')
  337. {
  338. global $cfg_ml,$cfg_basedir,$cfg_image_dir,$dsql,$title, $dsql;
  339. if($ntitle!='')
  340. {
  341. $title = $ntitle;
  342. }
  343. $ntime = time();
  344. $filename = '';
  345. $isrm_up = false;
  346. $handurl = trim($handurl);
  347. //???????????
  348. if(!empty($_FILES[$upname]['tmp_name']) && is_uploaded_file($_FILES[$upname]['tmp_name']))
  349. {
  350. $istype = 0;
  351. $sparr = Array("image/pjpeg","image/jpeg","image/gif","image/png");
  352. $_FILES[$upname]['type'] = strtolower(trim($_FILES[$upname]['type']));
  353. if(!in_array($_FILES[$upname]['type'],$sparr))
  354. {
  355. ShowMsg("?????????????JPEG?GIF?PNG????????","-1");
  356. exit();
  357. }
  358. if(!empty($handurl) && !eregi("^http://",$handurl) && file_exists($cfg_basedir.$handurl) )
  359. {
  360. $dsql->ExecuteNoneQuery("Delete From #@__uploads where url like '$handurl' ");
  361. $fullUrl = eregi_replace("\.([a-z]*)$","",$handurl);
  362. }
  363. else
  364. {
  365. $savepath = $cfg_image_dir."/".strftime("%Y-%m",$ntime);
  366. CreateDir($savepath);
  367. $fullUrl = $savepath."/".strftime("%d",$ntime).dd2char(strftime("%H%M%S",$ntime).'0'.$cfg_ml->M_ID.'0'.mt_rand(1000,9999));
  368. }
  369. if(strtolower($_FILES[$upname]['type'])=="image/gif")
  370. {
  371. $fullUrl = $fullUrl.".gif";
  372. }
  373. else if(strtolower($_FILES[$upname]['type'])=="image/png")
  374. {
  375. $fullUrl = $fullUrl.".png";
  376. }
  377. else
  378. {
  379. $fullUrl = $fullUrl.".jpg";
  380. }
  381. //??
  382. @move_uploaded_file($_FILES[$upname]['tmp_name'],$cfg_basedir.$fullUrl);
  383. $filename = $fullUrl;
  384. //??
  385. @WaterImg($imgfile,'up');
  386. $isrm_up = true;
  387. }
  388. //?????????
  389. else{
  390. if($handurl=='')
  391. {
  392. return '';
  393. }
  394. //??????????
  395. if($isremote==1 && eregi("^http://",$handurl))
  396. {
  397. $ddinfos = GetRemoteImage($handurl,$cuserLogin->getUserID());
  398. if(!is_array($ddinfos))
  399. {
  400. $litpic = "";
  401. }
  402. else
  403. {
  404. $filename = $ddinfos[0];
  405. }
  406. $isrm_up = true;
  407. //?????????????
  408. }
  409. else
  410. {
  411. $filename = $handurl;
  412. }
  413. }
  414. $imgfile = $cfg_basedir.$filename;
  415. if(is_file($imgfile) && $isrm_up && $filename!='')
  416. {
  417. $info = "";
  418. $imginfos = GetImageSize($imgfile,$info);
  419. //?????????????????????
  420. $inquery = "
  421. INSERT INTO #@__uploads(title,url,mediatype,width,height,playtime,filesize,uptime,mid)
  422. VALUES ('$title','$filename','1','".$imginfos[0]."','".$imginfos[1]."','0','".filesize($imgfile)."','".time()."','".$cfg_ml->M_ID."');
  423. ";
  424. $dsql->ExecuteNoneQuery($inquery);
  425. }
  426. $fid = $dsql->GetLastID();
  427. AddMyAddon($fid, $filename);
  428. return $filename;
  429. }
  430. ?>