PageRenderTime 47ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/source/function/function_spacecp.php

https://github.com/jinbo51/DiscuzX
PHP | 734 lines | 634 code | 94 blank | 6 comment | 161 complexity | e36baa2b245a699578eba3818fd4b7c6 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. <?php
  2. /**
  3. * [Discuz!] (C)2001-2099 Comsenz Inc.
  4. * This is NOT a freeware, use is subject to license terms
  5. *
  6. * $Id: function_spacecp.php 33068 2013-04-18 01:46:12Z zhengqingpeng $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. function album_creat_by_id($albumid, $catid = 0) {
  12. global $_G, $space;
  13. if(!$_G['uid']) {
  14. return 0;
  15. }
  16. preg_match("/^new\:(.+)$/i", $albumid, $matchs);
  17. if(!empty($matchs[1])) {
  18. $albumname = dhtmlspecialchars(trim($matchs[1]));
  19. if(empty($albumname)) $albumname = dgmdate($_G['timestamp'],'Ymd');
  20. $albumarr = array('albumname' => $albumname);
  21. if($catid) {
  22. $albumarr['catid'] = $catid;
  23. }
  24. $albumid = album_creat($albumarr);
  25. } else {
  26. $albumid = intval($albumid);
  27. if($albumid) {
  28. $value = C::t('home_album')->fetch_all_by_uid($_G['uid'], false, 0, 0, $albumid);
  29. if($value = $value[0]) {
  30. $albumname = addslashes($value['albumname']);
  31. $albumfriend = $value['friend'];
  32. } else {
  33. $albumname = dgmdate($_G['timestamp'],'Ymd');
  34. $albumarr = array('albumname' => $albumname);
  35. if($catid) {
  36. $albumarr['catid'] = $catid;
  37. }
  38. $albumid = album_creat($albumarr);
  39. }
  40. }
  41. }
  42. return $albumid;
  43. }
  44. function album_update_pic($albumid, $picid=0) {
  45. global $_G;
  46. $setarr = array();
  47. if(!$picid) {
  48. $piccount = C::t('home_pic')->check_albumpic($albumid, 0);
  49. if(empty($piccount) && C::t('home_pic')->check_albumpic($albumid) == 0) {
  50. C::t('home_album')->delete($albumid);
  51. return false;
  52. } else {
  53. $setarr['picnum'] = $piccount;
  54. }
  55. }
  56. $query = C::t('home_pic')->fetch_all_by_albumid($albumid, 0, 1, $picid, 1);
  57. if(!$pic = $query[0]) {
  58. return false;
  59. }
  60. $from = $pic['remote'];
  61. $pic['remote'] = $pic['remote'] > 1 ? $pic['remote'] - 2 : $pic['remote'];
  62. $basedir = !getglobal('setting/attachdir') ? (DISCUZ_ROOT.'./data/attachment/') : getglobal('setting/attachdir');
  63. $picdir = 'cover/'.substr(md5($albumid), 0, 2).'/';
  64. dmkdir($basedir.'./album/'.$picdir);
  65. if($pic['remote']) {
  66. $picsource = pic_get($pic['filepath'], $from > 1 ? 'forum' : 'album', $pic['thumb'], $pic['remote'], 0);
  67. } else {
  68. $picsource = $basedir.'./'.($from > 1 ? 'forum' : 'album').'/'.$pic['filepath'];
  69. }
  70. require_once libfile('class/image');
  71. $image = new image();
  72. if($image->Thumb($picsource, 'album/'.$picdir.$albumid.'.jpg', 120, 120, 2)) {
  73. $setarr['pic'] = $picdir.$albumid.'.jpg';
  74. $setarr['picflag'] = 1;
  75. if(getglobal('setting/ftp/on')) {
  76. if(ftpcmd('upload', 'album/'.$picdir.$albumid.'.jpg')) {
  77. $setarr['picflag'] = 2;
  78. @unlink($_G['setting']['attachdir'].'album/'.$picdir.$albumid.'.jpg');
  79. }
  80. }
  81. } else {
  82. if($pic['status'] == 0) {
  83. $setarr['pic'] = $pic['thumb'] ? getimgthumbname($pic['filepath']) : $pic['filepath'];
  84. }
  85. if($from > 1) {
  86. $setarr['picflag'] = $pic['remote'] ? 4:3;
  87. } else {
  88. $setarr['picflag'] = $pic['remote'] ? 2:1;
  89. }
  90. }
  91. $setarr['updatetime'] = $_G['timestamp'];
  92. C::t('home_album')->update($albumid, $setarr);
  93. return true;
  94. }
  95. function pic_save($FILE, $albumid, $title, $iswatermark = true, $catid = 0) {
  96. global $_G, $space;
  97. if($albumid<0) $albumid = 0;
  98. $allowpictype = array('jpg','jpeg','gif','png');
  99. $upload = new discuz_upload();
  100. $upload->init($FILE, 'album');
  101. if($upload->error()) {
  102. return lang('spacecp', 'lack_of_access_to_upload_file_size');
  103. }
  104. if(!$upload->attach['isimage']) {
  105. return lang('spacecp', 'only_allows_upload_file_types');
  106. }
  107. $oldgid = $_G['groupid'];
  108. if(empty($space)) {
  109. $_G['member'] = $space = getuserbyuid($_G['uid']);
  110. $_G['username'] = $space['username'];
  111. $_G['groupid'] = $space['groupid'];
  112. }
  113. $_G['member'] = $space;
  114. loadcache('usergroup_'.$space['groupid'], $oldgid != $_G['groupid'] ? true : false);
  115. $_G['group'] = $_G['cache']['usergroup_'.$space['groupid']];
  116. if(!checkperm('allowupload')) {
  117. return lang('spacecp', 'not_allow_upload');
  118. }
  119. if(!cknewuser(1)) {
  120. if($_G['setting']['newbiespan'] && $_G['timestamp'] - $_G['member']['regdate'] < $_G['setting']['newbiespan'] * 60) {
  121. return lang('message', 'no_privilege_newbiespan', array('newbiespan' => $_G['setting']['newbiespan']));
  122. }
  123. if($_G['setting']['need_avatar'] && empty($_G['member']['avatarstatus'])) {
  124. return lang('message', 'no_privilege_avatar');
  125. }
  126. if($_G['setting']['need_email'] && empty($_G['member']['emailstatus'])) {
  127. return lang('message', 'no_privilege_email');
  128. }
  129. if($_G['setting']['need_friendnum']) {
  130. space_merge($_G['member'], 'count');
  131. if($_G['member']['friends'] < $_G['setting']['need_friendnum']) {
  132. return lang('message', 'no_privilege_friendnum', array('friendnum' => $_G['setting']['need_friendnum']));
  133. }
  134. }
  135. }
  136. if($_G['group']['maximagesize'] && $upload->attach['size'] > $_G['group']['maximagesize']) {
  137. return lang('spacecp', 'files_can_not_exceed_size', array('extend' => $upload->attach['ext'], 'size' => sizecount($_G['group']['maximagesize'])));
  138. }
  139. $maxspacesize = checkperm('maxspacesize');
  140. if($maxspacesize) {
  141. space_merge($space, 'count');
  142. space_merge($space, 'field_home');
  143. if($space['attachsize'] + $upload->attach['size'] > $maxspacesize + $space['addsize'] * 1024 * 1024) {
  144. return lang('spacecp', 'inadequate_capacity_space');
  145. }
  146. }
  147. $showtip = true;
  148. $albumfriend = 0;
  149. if($albumid) {
  150. $catid = intval($catid);
  151. $albumid = album_creat_by_id($albumid, $catid);
  152. } else {
  153. $albumid = 0;
  154. $showtip = false;
  155. }
  156. $upload->save();
  157. if($upload->error()) {
  158. return lang('spacecp', 'mobile_picture_temporary_failure');
  159. }
  160. if(!$upload->attach['imageinfo'] || !in_array($upload->attach['imageinfo']['2'], array(1,2,3,6))) {
  161. @unlink($upload->attach['target']);
  162. return lang('spacecp', 'only_allows_upload_file_types');
  163. }
  164. $new_name = $upload->attach['target'];
  165. require_once libfile('class/image');
  166. $image = new image();
  167. $result = $image->Thumb($new_name, '', 140, 140, 1);
  168. $thumb = empty($result)?0:1;
  169. if($_G['setting']['maxthumbwidth'] && $_G['setting']['maxthumbheight']) {
  170. if($_G['setting']['maxthumbwidth'] < 300) $_G['setting']['maxthumbwidth'] = 300;
  171. if($_G['setting']['maxthumbheight'] < 300) $_G['setting']['maxthumbheight'] = 300;
  172. $image->Thumb($new_name, '', $_G['setting']['maxthumbwidth'], $_G['setting']['maxthumbheight'], 1, 1);
  173. }
  174. if ($iswatermark) {
  175. $image->Watermark($new_name, '', 'album');
  176. }
  177. $pic_remote = 0;
  178. $album_picflag = 1;
  179. if(getglobal('setting/ftp/on')) {
  180. $ftpresult_thumb = 0;
  181. $ftpresult = ftpcmd('upload', 'album/'.$upload->attach['attachment']);
  182. if($ftpresult) {
  183. @unlink($_G['setting']['attachdir'].'album/'.$upload->attach['attachment']);
  184. if($thumb) {
  185. $thumbpath = getimgthumbname($upload->attach['attachment']);
  186. ftpcmd('upload', 'album/'.$thumbpath);
  187. @unlink($_G['setting']['attachdir'].'album/'.$thumbpath);
  188. }
  189. $pic_remote = 1;
  190. $album_picflag = 2;
  191. } else {
  192. if(getglobal('setting/ftp/mirror')) {
  193. @unlink($upload->attach['target']);
  194. @unlink(getimgthumbname($upload->attach['target']));
  195. return lang('spacecp', 'ftp_upload_file_size');
  196. }
  197. }
  198. }
  199. $title = getstr($title, 200);
  200. $title = censor($title);
  201. if(censormod($title) || $_G['group']['allowuploadmod']) {
  202. $pic_status = 1;
  203. } else {
  204. $pic_status = 0;
  205. }
  206. $setarr = array(
  207. 'albumid' => $albumid,
  208. 'uid' => $_G['uid'],
  209. 'username' => $_G['username'],
  210. 'dateline' => $_G['timestamp'],
  211. 'filename' => addslashes($upload->attach['name']),
  212. 'postip' => $_G['clientip'],
  213. 'title' => $title,
  214. 'type' => addslashes($upload->attach['ext']),
  215. 'size' => $upload->attach['size'],
  216. 'filepath' => $upload->attach['attachment'],
  217. 'thumb' => $thumb,
  218. 'remote' => $pic_remote,
  219. 'status' => $pic_status,
  220. );
  221. $setarr['picid'] = C::t('home_pic')->insert($setarr, 1);
  222. C::t('common_member_count')->increase($_G['uid'], array('attachsize' => $upload->attach['size']));
  223. include_once libfile('function/stat');
  224. if($pic_status) {
  225. updatemoderate('picid', $setarr['picid']);
  226. }
  227. updatestat('pic');
  228. return $setarr;
  229. }
  230. function stream_save($strdata, $albumid = 0, $fileext = 'jpg', $name='', $title='', $delsize=0, $from = false) {
  231. global $_G, $space;
  232. if($albumid<0) $albumid = 0;
  233. $allowPicType = array('jpg','jpeg','gif','png');
  234. if(!in_array($fileext, $allowPicType)) {
  235. return -3;
  236. }
  237. $setarr = array();
  238. $upload = new discuz_upload();
  239. $filepath = $upload->get_target_dir('album').$upload->get_target_filename('album').'.'.$fileext;
  240. $newfilename = $_G['setting']['attachdir'].'./album/'.$filepath;
  241. if($handle = fopen($newfilename, 'wb')) {
  242. if(fwrite($handle, $strdata) !== FALSE) {
  243. fclose($handle);
  244. $size = filesize($newfilename);
  245. if(empty($space)) {
  246. $_G['member'] = $space = getuserbyuid($_G['uid']);
  247. $_G['username'] = $space['username'];
  248. }
  249. $_G['member'] = $space;
  250. loadcache('usergroup_'.$space['groupid']);
  251. $_G['group'] = $_G['cache']['usergroup_'.$space['groupid']];
  252. $maxspacesize = checkperm('maxspacesize');
  253. if($maxspacesize) {
  254. space_merge($space, 'count');
  255. space_merge($space, 'field_home');
  256. if($space['attachsize'] + $size - $delsize > $maxspacesize + $space['addsize'] * 1024 * 1024) {
  257. @unlink($newfilename);
  258. return -1;
  259. }
  260. }
  261. if(!$upload->get_image_info($newfilename)) {
  262. @unlink($newfilename);
  263. return -2;
  264. }
  265. require_once libfile('class/image');
  266. $image = new image();
  267. $result = $image->Thumb($newfilename, NULL, 140, 140, 1);
  268. $thumb = empty($result)?0:1;
  269. $image->Watermark($newfilename);
  270. $pic_remote = 0;
  271. $album_picflag = 1;
  272. if(getglobal('setting/ftp/on')) {
  273. $ftpresult_thumb = 0;
  274. $ftpresult = ftpcmd('upload', 'album/'.$filepath);
  275. if($ftpresult) {
  276. @unlink($_G['setting']['attachdir'].'album/'.$filepath);
  277. if($thumb) {
  278. $thumbpath = getimgthumbname($filepath);
  279. ftpcmd('upload', 'album/'.$thumbpath);
  280. @unlink($_G['setting']['attachdir'].'album/'.$thumbpath);
  281. }
  282. $pic_remote = 1;
  283. $album_picflag = 2;
  284. } else {
  285. if(getglobal('setting/ftp/mirror')) {
  286. @unlink($newfilename);
  287. @unlink(getimgthumbname($newfilename));
  288. return -3;
  289. }
  290. }
  291. }
  292. $filename = $name ? $name : substr(strrchr($filepath, '/'), 1);
  293. $title = getstr($title, 200);
  294. $title = censor($title);
  295. if(censormod($title) || $_G['group']['allowuploadmod']) {
  296. $pic_status = 1;
  297. } else {
  298. $pic_status = 0;
  299. }
  300. if($albumid) {
  301. $albumid = album_creat_by_id($albumid);
  302. } else {
  303. $albumid = 0;
  304. }
  305. $setarr = array(
  306. 'albumid' => $albumid,
  307. 'uid' => $_G['uid'],
  308. 'username' => $_G['username'],
  309. 'dateline' => $_G['timestamp'],
  310. 'filename' => $filename,
  311. 'postip' => $_G['clientip'],
  312. 'title' => $title,
  313. 'type' => $fileext,
  314. 'size' => $size,
  315. 'filepath' => $filepath,
  316. 'thumb' => $thumb,
  317. 'remote' => $pic_remote,
  318. 'status' => $pic_status,
  319. );
  320. $setarr['picid'] = C::t('home_pic')->insert($setarr, 1);
  321. C::t('common_member_count')->increase($_G['uid'], array('attachsize' => $size));
  322. include_once libfile('function/stat');
  323. updatestat('pic');
  324. return $setarr;
  325. } else {
  326. fclose($handle);
  327. }
  328. }
  329. return -3;
  330. }
  331. function album_creat($arr) {
  332. global $_G;
  333. $albumid = C::t('home_album')->fetch_albumid_by_albumname_uid($arr['albumname'], $_G['uid']);
  334. if($albumid) {
  335. return $albumid;
  336. } else {
  337. $arr['uid'] = $_G['uid'];
  338. $arr['username'] = $_G['username'];
  339. $arr['dateline'] = $arr['updatetime'] = $_G['timestamp'];
  340. $albumid = C::t('home_album')->insert($arr, TRUE);
  341. C::t('common_member_count')->increase($_G['uid'], array('albums' => 1));
  342. if(isset($arr['catid']) && $arr['catid']) {
  343. C::t('home_album_category')->update_num_by_catid('1', $arr['catid']);
  344. }
  345. return $albumid;
  346. }
  347. }
  348. function getfilepath($fileext, $mkdir=false) {
  349. global $_G;
  350. $filepath = "{$_G['uid']}_{$_G['timestamp']}".random(4).".$fileext";
  351. $name1 = gmdate('Ym');
  352. $name2 = gmdate('j');
  353. if($mkdir) {
  354. $newfilename = $_G['setting']['attachdir'].'./album/'.$name1;
  355. if(!is_dir($newfilename)) {
  356. if(!@mkdir($newfilename)) {
  357. runlog('error', "DIR: $newfilename can not make");
  358. return $filepath;
  359. }
  360. }
  361. $newfilename .= '/'.$name2;
  362. if(!is_dir($newfilename)) {
  363. if(!@mkdir($newfilename)) {
  364. runlog('error', "DIR: $newfilename can not make");
  365. return $name1.'/'.$filepath;
  366. }
  367. }
  368. }
  369. return $name1.'/'.$name2.'/'.$filepath;
  370. }
  371. function getalbumpic($uid, $id) {
  372. global $_G;
  373. $pic = C::t('home_pic')->fetch_album_pic($id, $uid);
  374. if($pic) {
  375. return $pic['thumb'] ? getimgthumbname($pic['filepath']) : $pic['filepath'];
  376. } else {
  377. return '';
  378. }
  379. }
  380. function getclassarr($uid) {
  381. global $_G;
  382. $classarr = array();
  383. $query = C::t('home_class')->fetch_all_by_uid($uid);
  384. foreach($query as $value) {
  385. $classarr[$value['classid']] = $value;
  386. }
  387. return $classarr;
  388. }
  389. function getalbums($uid) {
  390. global $_G;
  391. $albums = array();
  392. $query = C::t('home_album')->fetch_all_by_uid($uid, 'albumid');
  393. foreach($query as $value) {
  394. $albums[$value['albumid']] = $value;
  395. }
  396. return $albums;
  397. }
  398. function hot_update($idtype, $id, $hotuser) {
  399. global $_G;
  400. $hotusers = empty($hotuser)?array():explode(',', $hotuser);
  401. if($hotusers && in_array($_G['uid'], $hotusers)) {
  402. return false;
  403. } else {
  404. $hotusers[] = $_G['uid'];
  405. $hotuser = implode(',', $hotusers);
  406. }
  407. $hotuser = daddslashes($hotuser);
  408. $newhot = count($hotusers)+1;
  409. if($newhot == $_G['setting']['feedhotmin']) {
  410. $tablename = gettablebyidtype($idtype);
  411. if($tablename) {
  412. $item = C::t($tablename)->fetch_by_id_idtype($id);
  413. $itemuid = $item['uid'];
  414. updatecreditbyaction('hotinfo', $itemuid);
  415. }
  416. }
  417. switch ($idtype) {
  418. case 'blogid':
  419. C::t('home_blogfield')->update($id, array('hotuser' => $hotuser));
  420. C::t('home_blog')->increase($id, 0, array('hot' => 1));
  421. break;
  422. case 'picid':
  423. C::t('home_picfield')->insert(array('picid' => $id, 'hotuser' => $hotuser), 0, 1);
  424. C::t('home_pic')->update_hot($id);
  425. break;
  426. case 'sid':
  427. C::t('home_share')->update_hot_by_sid($id, $hotuser);
  428. break;
  429. default:
  430. return false;
  431. }
  432. if($feed = C::t('home_feed')->fetch($id, $idtype)) {
  433. if(empty($feed['friend'])) {
  434. C::t('home_feed')->update_hot_by_feedid($feed['feedid'], 1);
  435. }
  436. } elseif($idtype == 'picid') {
  437. require_once libfile('function/feed');
  438. feed_publish($id, $idtype);
  439. }
  440. return true;
  441. }
  442. function gettablebyidtype($idtype) {
  443. $tablename = '';
  444. if($idtype == 'blogid') {
  445. $tablename = 'home_blog';
  446. } elseif($idtype == 'picid') {
  447. $tablename = 'home_pic';
  448. } elseif($idtype == 'sid') {
  449. $tablename = 'home_share';
  450. }
  451. return $tablename;
  452. }
  453. function privacy_update() {
  454. global $_G, $space;
  455. C::t('common_member_field_home')->update($_G['uid'], array('privacy'=>serialize($space['privacy'])));
  456. }
  457. function ckrealname($return=0) {
  458. global $_G;
  459. $result = true;
  460. if($_G['adminid'] != 1 && $_G['setting']['verify'][6]['available'] && empty($_G['setting']['verify'][6]['viewrealname'])) {
  461. space_merge($_G['member'], 'profile');
  462. space_merge($_G['member'], 'verify');
  463. if(empty($_G['member']['realname']) || !$_G['member']['verify6']) {
  464. if(empty($return)) showmessage('no_privilege_realname', '', array(), array('return' => true));
  465. $result = false;
  466. }
  467. }
  468. return $result;
  469. }
  470. function ckvideophoto($tospace=array(), $return=0) {
  471. global $_G;
  472. if($_G['adminid'] != 1 && empty($_G['setting']['verify'][7]['available']) || $_G['member']['videophotostatus']) {
  473. return true;
  474. }
  475. space_merge($tospace, 'field_home');
  476. $result = true;
  477. if(empty($tospace) || empty($tospace['privacy']['view']['videoviewphoto'])) {
  478. if(!checkperm('videophotoignore') && empty($_G['setting']['verify'][7]['viewvideophoto']) && !checkperm('allowviewvideophoto')) {
  479. $result = false;
  480. }
  481. } elseif ($tospace['privacy']['view']['videoviewphoto'] == 2) {
  482. $result = false;
  483. }
  484. if($return) {
  485. return $result;
  486. } elseif(!$result) {
  487. showmessage('no_privilege_videophoto', '', array(), array('return' => true));
  488. }
  489. }
  490. function getvideophoto($filename) {
  491. $dir1 = substr($filename, 0, 1);
  492. $dir2 = substr($filename, 1, 1);
  493. return 'data/avatar/'.$dir1.'/'.$dir2.'/'.$filename.".jpg";
  494. }
  495. function videophoto_upload($FILE, $uid) {
  496. if($FILE['size']) {
  497. $newfilename = md5(substr($_G['timestamp'], 0, 7).$uid);
  498. $dir1 = substr($newfilename, 0, 1);
  499. $dir2 = substr($newfilename, 1, 1);
  500. if(!is_dir(DISCUZ_ROOT.'./data/avatar/'.$dir1)) {
  501. if(!mkdir(DISCUZ_ROOT.'./data/avatar/'.$dir1)) return '';
  502. }
  503. if(!is_dir(DISCUZ_ROOT.'./data/avatar/'.$dir1.'/'.$dir2)) {
  504. if(!mkdir(DISCUZ_ROOT.'./data/avatar/'.$dir1.'/'.$dir2)) return '';
  505. }
  506. $new_name = DISCUZ_ROOT.'./'.getvideophoto($newfilename);
  507. $tmp_name = $FILE['tmp_name'];
  508. if(@copy($tmp_name, $new_name)) {
  509. @unlink($tmp_name);
  510. } elseif((function_exists('move_uploaded_file') && @move_uploaded_file($tmp_name, $new_name))) {
  511. } elseif(@rename($tmp_name, $new_name)) {
  512. } else {
  513. return '';
  514. }
  515. return $newfilename;
  516. } else {
  517. return '';
  518. }
  519. }
  520. function isblacklist($touid) {
  521. global $_G;
  522. return C::t('home_blacklist')->count_by_uid_buid($touid, $_G['uid']);
  523. }
  524. function emailcheck_send($uid, $email) {
  525. global $_G;
  526. if($uid && $email) {
  527. $hash = authcode("$uid\t$email\t$_G[timestamp]", 'ENCODE', md5(substr(md5($_G['config']['security']['authkey']), 0, 16)));
  528. $verifyurl = $_G['siteurl'].'home.php?mod=misc&amp;ac=emailcheck&amp;hash='.urlencode($hash);
  529. $mailsubject = lang('email', 'email_verify_subject');
  530. $mailmessage = lang('email', 'email_verify_message', array(
  531. 'username' => $_G['member']['username'],
  532. 'bbname' => $_G['setting']['bbname'],
  533. 'siteurl' => $_G['siteurl'],
  534. 'url' => $verifyurl
  535. ));
  536. require_once libfile('function/mail');
  537. if(!sendmail($email, $mailsubject, $mailmessage)) {
  538. runlog('sendmail', "$email sendmail failed.");
  539. }
  540. }
  541. }
  542. function picurl_get($picurl, $maxlenth='200') {
  543. $picurl = dhtmlspecialchars(trim($picurl));
  544. if($picurl) {
  545. if(preg_match("/^http\:\/\/.{5,$maxlenth}\.(jpg|gif|png)$/i", $picurl)) return $picurl;
  546. }
  547. return '';
  548. }
  549. function avatar_file($uid, $size) {
  550. global $_G;
  551. $var = "home_avatarfile_{$uid}_{$size}";
  552. if(empty($_G[$var])) {
  553. $uid = abs(intval($uid));
  554. $uid = sprintf("%09d", $uid);
  555. $dir1 = substr($uid, 0, 3);
  556. $dir2 = substr($uid, 3, 2);
  557. $dir3 = substr($uid, 5, 2);
  558. $_G[$var] = $dir1.'/'.$dir2.'/'.$dir3.'/'.substr($uid, -2)."_avatar_$size.jpg";
  559. }
  560. return $_G[$var];
  561. }
  562. function makepokeaction($iconid) {
  563. global $_G;
  564. $icons = array(
  565. 0 => lang('home/template', 'say_hi'),
  566. 1 => '<img alt="cyx" src="'.STATICURL.'image/poke/cyx.gif" class="vm" /> '.lang('home/template', 'poke_1'),
  567. 2 => '<img alt="wgs" src="'.STATICURL.'image/poke/wgs.gif" class="vm" /> '.lang('home/template', 'poke_2'),
  568. 3 => '<img alt="wx" src="'.STATICURL.'image/poke/wx.gif" class="vm" /> '.lang('home/template', 'poke_3'),
  569. 4 => '<img alt="jy" src="'.STATICURL.'image/poke/jy.gif" class="vm" /> '.lang('home/template', 'poke_4'),
  570. 5 => '<img alt="pmy" src="'.STATICURL.'image/poke/pmy.gif" class="vm" /> '.lang('home/template', 'poke_5'),
  571. 6 => '<img alt="yb" src="'.STATICURL.'image/poke/yb.gif" class="vm" /> '.lang('home/template', 'poke_6'),
  572. 7 => '<img alt="fw" src="'.STATICURL.'image/poke/fw.gif" class="vm" /> '.lang('home/template', 'poke_7'),
  573. 8 => '<img alt="nyy" src="'.STATICURL.'image/poke/nyy.gif" class="vm" /> '.lang('home/template', 'poke_8'),
  574. 9 => '<img alt="gyq" src="'.STATICURL.'image/poke/gyq.gif" class="vm" /> '.lang('home/template', 'poke_9'),
  575. 10 => '<img alt="dyx" src="'.STATICURL.'image/poke/dyx.gif" class="vm" /> '.lang('home/template', 'poke_10'),
  576. 11 => '<img alt="yw" src="'.STATICURL.'image/poke/yw.gif" class="vm" /> '.lang('home/template', 'poke_11'),
  577. 12 => '<img alt="ppjb" src="'.STATICURL.'image/poke/ppjb.gif" class="vm" /> '.lang('home/template', 'poke_12'),
  578. 13 => '<img alt="yyk" src="'.STATICURL.'image/poke/yyk.gif" class="vm" /> '.lang('home/template', 'poke_13')
  579. );
  580. return isset($icons[$iconid]) ? $icons[$iconid] : $icons[0];
  581. }
  582. function interval_check($type) {
  583. global $_G;
  584. $waittime = 0;
  585. if(checkperm('disablepostctrl')) {
  586. return $waittime;
  587. }
  588. if($_G['setting']['floodctrl']) {
  589. space_merge($_G['member'], 'status');
  590. getuserprofile('lastpost');
  591. $waittime = $_G['setting']['floodctrl'] - ($_G['timestamp'] - $_G['member']['lastpost']);
  592. }
  593. return $waittime;
  594. }
  595. function geturltitle($link, $charset = '') {
  596. $title = $linkcharset = '';
  597. $linkstr = gzfile($link);
  598. $linkstr = implode('', $linkstr);
  599. if(!$charset) {
  600. preg_match('/<meta [^>]*charset="?(.*)"/i', $linkstr, $linkcharset);
  601. $charset = strtolower($linkcharset[1]);
  602. }
  603. if(!$charset) {
  604. return $title;
  605. }
  606. if($charset != strtolower(CHARSET)) {
  607. $linkstr = diconv($linkstr, $charset);
  608. }
  609. if(!empty($linkstr) && preg_match('/\<title\>(.*)\<\/title\>/i', $linkstr, $title)) {
  610. $tmptitle = explode('_', $title[1]);
  611. if($title[1] == $tmptitle[0]) {
  612. $tmptitle = explode('-', $title[1]);
  613. }
  614. $title = trim($tmptitle[0]);
  615. }
  616. return $title;
  617. }
  618. function allowverify($vid) {
  619. global $_G;
  620. if(empty($_G['setting']['verify'])) {
  621. loadcache('setting');
  622. }
  623. $allow = false;
  624. $vid = 0 < $vid && $vid < 8 ? intval($vid) : 0;
  625. if($vid) {
  626. $setting = $_G['setting']['verify'][$vid];
  627. if($setting['available'] && (empty($setting['groupid']) || in_array($_G['groupid'], $setting['groupid']))) {
  628. $allow = true;
  629. }
  630. } else {
  631. foreach($_G['setting']['verify'] as $key => $setting) {
  632. if($setting['available'] && (empty($setting['groupid']) || in_array($_G['groupid'], $setting['groupid']))) {
  633. $allow = true;
  634. break;
  635. }
  636. }
  637. }
  638. return $allow;
  639. }
  640. ?>