function_spacecp.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736
  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 36294 2016-12-14 03:11:30Z nemohou $
  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. 'port' => $_G['remoteport'],
  214. 'title' => $title,
  215. 'type' => addslashes($upload->attach['ext']),
  216. 'size' => $upload->attach['size'],
  217. 'filepath' => $upload->attach['attachment'],
  218. 'thumb' => $thumb,
  219. 'remote' => $pic_remote,
  220. 'status' => $pic_status,
  221. );
  222. $setarr['picid'] = C::t('home_pic')->insert($setarr, 1);
  223. C::t('common_member_count')->increase($_G['uid'], array('attachsize' => $upload->attach['size']));
  224. include_once libfile('function/stat');
  225. if($pic_status) {
  226. updatemoderate('picid', $setarr['picid']);
  227. }
  228. updatestat('pic');
  229. return $setarr;
  230. }
  231. function stream_save($strdata, $albumid = 0, $fileext = 'jpg', $name='', $title='', $delsize=0, $from = false) {
  232. global $_G, $space;
  233. if($albumid<0) $albumid = 0;
  234. $allowPicType = array('jpg','jpeg','gif','png');
  235. if(!in_array($fileext, $allowPicType)) {
  236. return -3;
  237. }
  238. $setarr = array();
  239. $upload = new discuz_upload();
  240. $filepath = $upload->get_target_dir('album').$upload->get_target_filename('album').'.'.$fileext;
  241. $newfilename = $_G['setting']['attachdir'].'./album/'.$filepath;
  242. if($handle = fopen($newfilename, 'wb')) {
  243. if(fwrite($handle, $strdata) !== FALSE) {
  244. fclose($handle);
  245. $size = filesize($newfilename);
  246. if(empty($space)) {
  247. $_G['member'] = $space = getuserbyuid($_G['uid']);
  248. $_G['username'] = $space['username'];
  249. }
  250. $_G['member'] = $space;
  251. loadcache('usergroup_'.$space['groupid']);
  252. $_G['group'] = $_G['cache']['usergroup_'.$space['groupid']];
  253. $maxspacesize = checkperm('maxspacesize');
  254. if($maxspacesize) {
  255. space_merge($space, 'count');
  256. space_merge($space, 'field_home');
  257. if($space['attachsize'] + $size - $delsize > $maxspacesize + $space['addsize'] * 1024 * 1024) {
  258. @unlink($newfilename);
  259. return -1;
  260. }
  261. }
  262. if(!$upload->get_image_info($newfilename)) {
  263. @unlink($newfilename);
  264. return -2;
  265. }
  266. require_once libfile('class/image');
  267. $image = new image();
  268. $result = $image->Thumb($newfilename, NULL, 140, 140, 1);
  269. $thumb = empty($result)?0:1;
  270. $image->Watermark($newfilename);
  271. $pic_remote = 0;
  272. $album_picflag = 1;
  273. if(getglobal('setting/ftp/on')) {
  274. $ftpresult_thumb = 0;
  275. $ftpresult = ftpcmd('upload', 'album/'.$filepath);
  276. if($ftpresult) {
  277. @unlink($_G['setting']['attachdir'].'album/'.$filepath);
  278. if($thumb) {
  279. $thumbpath = getimgthumbname($filepath);
  280. ftpcmd('upload', 'album/'.$thumbpath);
  281. @unlink($_G['setting']['attachdir'].'album/'.$thumbpath);
  282. }
  283. $pic_remote = 1;
  284. $album_picflag = 2;
  285. } else {
  286. if(getglobal('setting/ftp/mirror')) {
  287. @unlink($newfilename);
  288. @unlink(getimgthumbname($newfilename));
  289. return -3;
  290. }
  291. }
  292. }
  293. $filename = $name ? $name : substr(strrchr($filepath, '/'), 1);
  294. $title = getstr($title, 200);
  295. $title = censor($title);
  296. if(censormod($title) || $_G['group']['allowuploadmod']) {
  297. $pic_status = 1;
  298. } else {
  299. $pic_status = 0;
  300. }
  301. if($albumid) {
  302. $albumid = album_creat_by_id($albumid);
  303. } else {
  304. $albumid = 0;
  305. }
  306. $setarr = array(
  307. 'albumid' => $albumid,
  308. 'uid' => $_G['uid'],
  309. 'username' => $_G['username'],
  310. 'dateline' => $_G['timestamp'],
  311. 'filename' => $filename,
  312. 'postip' => $_G['clientip'],
  313. 'port' => $_G['remoteport'],
  314. 'title' => $title,
  315. 'type' => $fileext,
  316. 'size' => $size,
  317. 'filepath' => $filepath,
  318. 'thumb' => $thumb,
  319. 'remote' => $pic_remote,
  320. 'status' => $pic_status,
  321. );
  322. $setarr['picid'] = C::t('home_pic')->insert($setarr, 1);
  323. C::t('common_member_count')->increase($_G['uid'], array('attachsize' => $size));
  324. include_once libfile('function/stat');
  325. updatestat('pic');
  326. return $setarr;
  327. } else {
  328. fclose($handle);
  329. }
  330. }
  331. return -3;
  332. }
  333. function album_creat($arr) {
  334. global $_G;
  335. $albumid = C::t('home_album')->fetch_albumid_by_albumname_uid($arr['albumname'], $_G['uid']);
  336. if($albumid) {
  337. return $albumid;
  338. } else {
  339. $arr['uid'] = $_G['uid'];
  340. $arr['username'] = $_G['username'];
  341. $arr['dateline'] = $arr['updatetime'] = $_G['timestamp'];
  342. $albumid = C::t('home_album')->insert($arr, TRUE);
  343. C::t('common_member_count')->increase($_G['uid'], array('albums' => 1));
  344. if(isset($arr['catid']) && $arr['catid']) {
  345. C::t('home_album_category')->update_num_by_catid('1', $arr['catid']);
  346. }
  347. return $albumid;
  348. }
  349. }
  350. function getfilepath($fileext, $mkdir=false) {
  351. global $_G;
  352. $filepath = "{$_G['uid']}_{$_G['timestamp']}".random(4).".$fileext";
  353. $name1 = gmdate('Ym');
  354. $name2 = gmdate('j');
  355. if($mkdir) {
  356. $newfilename = $_G['setting']['attachdir'].'./album/'.$name1;
  357. if(!is_dir($newfilename)) {
  358. if(!@mkdir($newfilename)) {
  359. runlog('error', "DIR: $newfilename can not make");
  360. return $filepath;
  361. }
  362. }
  363. $newfilename .= '/'.$name2;
  364. if(!is_dir($newfilename)) {
  365. if(!@mkdir($newfilename)) {
  366. runlog('error', "DIR: $newfilename can not make");
  367. return $name1.'/'.$filepath;
  368. }
  369. }
  370. }
  371. return $name1.'/'.$name2.'/'.$filepath;
  372. }
  373. function getalbumpic($uid, $id) {
  374. global $_G;
  375. $pic = C::t('home_pic')->fetch_album_pic($id, $uid);
  376. if($pic) {
  377. return $pic['thumb'] ? getimgthumbname($pic['filepath']) : $pic['filepath'];
  378. } else {
  379. return '';
  380. }
  381. }
  382. function getclassarr($uid) {
  383. global $_G;
  384. $classarr = array();
  385. $query = C::t('home_class')->fetch_all_by_uid($uid);
  386. foreach($query as $value) {
  387. $classarr[$value['classid']] = $value;
  388. }
  389. return $classarr;
  390. }
  391. function getalbums($uid) {
  392. global $_G;
  393. $albums = array();
  394. $query = C::t('home_album')->fetch_all_by_uid($uid, 'albumid');
  395. foreach($query as $value) {
  396. $albums[$value['albumid']] = $value;
  397. }
  398. return $albums;
  399. }
  400. function hot_update($idtype, $id, $hotuser) {
  401. global $_G;
  402. $hotusers = empty($hotuser)?array():explode(',', $hotuser);
  403. if($hotusers && in_array($_G['uid'], $hotusers)) {
  404. return false;
  405. } else {
  406. $hotusers[] = $_G['uid'];
  407. $hotuser = implode(',', $hotusers);
  408. }
  409. $hotuser = daddslashes($hotuser);
  410. $newhot = count($hotusers)+1;
  411. if($newhot == $_G['setting']['feedhotmin']) {
  412. $tablename = gettablebyidtype($idtype);
  413. if($tablename) {
  414. $item = C::t($tablename)->fetch_by_id_idtype($id);
  415. $itemuid = $item['uid'];
  416. updatecreditbyaction('hotinfo', $itemuid);
  417. }
  418. }
  419. switch ($idtype) {
  420. case 'blogid':
  421. C::t('home_blogfield')->update($id, array('hotuser' => $hotuser));
  422. C::t('home_blog')->increase($id, 0, array('hot' => 1));
  423. break;
  424. case 'picid':
  425. C::t('home_picfield')->insert(array('picid' => $id, 'hotuser' => $hotuser), 0, 1);
  426. C::t('home_pic')->update_hot($id);
  427. break;
  428. case 'sid':
  429. C::t('home_share')->update_hot_by_sid($id, $hotuser);
  430. break;
  431. default:
  432. return false;
  433. }
  434. if($feed = C::t('home_feed')->fetch($id, $idtype)) {
  435. if(empty($feed['friend'])) {
  436. C::t('home_feed')->update_hot_by_feedid($feed['feedid'], 1);
  437. }
  438. } elseif($idtype == 'picid') {
  439. require_once libfile('function/feed');
  440. feed_publish($id, $idtype);
  441. }
  442. return true;
  443. }
  444. function gettablebyidtype($idtype) {
  445. $tablename = '';
  446. if($idtype == 'blogid') {
  447. $tablename = 'home_blog';
  448. } elseif($idtype == 'picid') {
  449. $tablename = 'home_pic';
  450. } elseif($idtype == 'sid') {
  451. $tablename = 'home_share';
  452. }
  453. return $tablename;
  454. }
  455. function privacy_update() {
  456. global $_G, $space;
  457. C::t('common_member_field_home')->update($_G['uid'], array('privacy'=>serialize($space['privacy'])));
  458. }
  459. function ckrealname($return=0) {
  460. global $_G;
  461. $result = true;
  462. if($_G['adminid'] != 1 && $_G['setting']['verify'][6]['available'] && empty($_G['setting']['verify'][6]['viewrealname'])) {
  463. space_merge($_G['member'], 'profile');
  464. space_merge($_G['member'], 'verify');
  465. if(empty($_G['member']['realname']) || !$_G['member']['verify6']) {
  466. if(empty($return)) showmessage('no_privilege_realname', '', array(), array('return' => true));
  467. $result = false;
  468. }
  469. }
  470. return $result;
  471. }
  472. function ckvideophoto($tospace=array(), $return=0) {
  473. global $_G;
  474. if($_G['adminid'] != 1 && empty($_G['setting']['verify'][7]['available']) || $_G['member']['videophotostatus']) {
  475. return true;
  476. }
  477. space_merge($tospace, 'field_home');
  478. $result = true;
  479. if(empty($tospace) || empty($tospace['privacy']['view']['videoviewphoto'])) {
  480. if(!checkperm('videophotoignore') && empty($_G['setting']['verify'][7]['viewvideophoto']) && !checkperm('allowviewvideophoto')) {
  481. $result = false;
  482. }
  483. } elseif ($tospace['privacy']['view']['videoviewphoto'] == 2) {
  484. $result = false;
  485. }
  486. if($return) {
  487. return $result;
  488. } elseif(!$result) {
  489. showmessage('no_privilege_videophoto', '', array(), array('return' => true));
  490. }
  491. }
  492. function getvideophoto($filename) {
  493. $dir1 = substr($filename, 0, 1);
  494. $dir2 = substr($filename, 1, 1);
  495. return 'data/avatar/'.$dir1.'/'.$dir2.'/'.$filename.".jpg";
  496. }
  497. function videophoto_upload($FILE, $uid) {
  498. if($FILE['size']) {
  499. $newfilename = md5(substr($_G['timestamp'], 0, 7).$uid);
  500. $dir1 = substr($newfilename, 0, 1);
  501. $dir2 = substr($newfilename, 1, 1);
  502. if(!is_dir(DISCUZ_ROOT.'./data/avatar/'.$dir1)) {
  503. if(!mkdir(DISCUZ_ROOT.'./data/avatar/'.$dir1)) return '';
  504. }
  505. if(!is_dir(DISCUZ_ROOT.'./data/avatar/'.$dir1.'/'.$dir2)) {
  506. if(!mkdir(DISCUZ_ROOT.'./data/avatar/'.$dir1.'/'.$dir2)) return '';
  507. }
  508. $new_name = DISCUZ_ROOT.'./'.getvideophoto($newfilename);
  509. $tmp_name = $FILE['tmp_name'];
  510. if(@copy($tmp_name, $new_name)) {
  511. @unlink($tmp_name);
  512. } elseif((function_exists('move_uploaded_file') && @move_uploaded_file($tmp_name, $new_name))) {
  513. } elseif(@rename($tmp_name, $new_name)) {
  514. } else {
  515. return '';
  516. }
  517. return $newfilename;
  518. } else {
  519. return '';
  520. }
  521. }
  522. function isblacklist($touid) {
  523. global $_G;
  524. return C::t('home_blacklist')->count_by_uid_buid($touid, $_G['uid']);
  525. }
  526. function emailcheck_send($uid, $email) {
  527. global $_G;
  528. if($uid && $email) {
  529. $hash = authcode("$uid\t$email\t$_G[timestamp]", 'ENCODE', md5(substr(md5($_G['config']['security']['authkey']), 0, 16)));
  530. $verifyurl = $_G['siteurl'].'home.php?mod=misc&amp;ac=emailcheck&amp;hash='.urlencode($hash);
  531. $mailsubject = lang('email', 'email_verify_subject');
  532. $mailmessage = lang('email', 'email_verify_message', array(
  533. 'username' => $_G['member']['username'],
  534. 'bbname' => $_G['setting']['bbname'],
  535. 'siteurl' => $_G['siteurl'],
  536. 'url' => $verifyurl
  537. ));
  538. require_once libfile('function/mail');
  539. if(!sendmail($email, $mailsubject, $mailmessage)) {
  540. runlog('sendmail', "$email sendmail failed.");
  541. }
  542. }
  543. }
  544. function picurl_get($picurl, $maxlenth='200') {
  545. $picurl = dhtmlspecialchars(trim($picurl));
  546. if($picurl) {
  547. if(preg_match("/^http\:\/\/.{5,$maxlenth}\.(jpg|gif|png)$/i", $picurl)) return $picurl;
  548. }
  549. return '';
  550. }
  551. function avatar_file($uid, $size) {
  552. global $_G;
  553. $var = "home_avatarfile_{$uid}_{$size}";
  554. if(empty($_G[$var])) {
  555. $uid = abs(intval($uid));
  556. $uid = sprintf("%09d", $uid);
  557. $dir1 = substr($uid, 0, 3);
  558. $dir2 = substr($uid, 3, 2);
  559. $dir3 = substr($uid, 5, 2);
  560. $_G[$var] = $dir1.'/'.$dir2.'/'.$dir3.'/'.substr($uid, -2)."_avatar_$size.jpg";
  561. }
  562. return $_G[$var];
  563. }
  564. function makepokeaction($iconid) {
  565. global $_G;
  566. $icons = array(
  567. 0 => lang('home/template', 'say_hi'),
  568. 1 => '<img alt="cyx" src="'.STATICURL.'image/poke/cyx.gif" class="vm" /> '.lang('home/template', 'poke_1'),
  569. 2 => '<img alt="wgs" src="'.STATICURL.'image/poke/wgs.gif" class="vm" /> '.lang('home/template', 'poke_2'),
  570. 3 => '<img alt="wx" src="'.STATICURL.'image/poke/wx.gif" class="vm" /> '.lang('home/template', 'poke_3'),
  571. 4 => '<img alt="jy" src="'.STATICURL.'image/poke/jy.gif" class="vm" /> '.lang('home/template', 'poke_4'),
  572. 5 => '<img alt="pmy" src="'.STATICURL.'image/poke/pmy.gif" class="vm" /> '.lang('home/template', 'poke_5'),
  573. 6 => '<img alt="yb" src="'.STATICURL.'image/poke/yb.gif" class="vm" /> '.lang('home/template', 'poke_6'),
  574. 7 => '<img alt="fw" src="'.STATICURL.'image/poke/fw.gif" class="vm" /> '.lang('home/template', 'poke_7'),
  575. 8 => '<img alt="nyy" src="'.STATICURL.'image/poke/nyy.gif" class="vm" /> '.lang('home/template', 'poke_8'),
  576. 9 => '<img alt="gyq" src="'.STATICURL.'image/poke/gyq.gif" class="vm" /> '.lang('home/template', 'poke_9'),
  577. 10 => '<img alt="dyx" src="'.STATICURL.'image/poke/dyx.gif" class="vm" /> '.lang('home/template', 'poke_10'),
  578. 11 => '<img alt="yw" src="'.STATICURL.'image/poke/yw.gif" class="vm" /> '.lang('home/template', 'poke_11'),
  579. 12 => '<img alt="ppjb" src="'.STATICURL.'image/poke/ppjb.gif" class="vm" /> '.lang('home/template', 'poke_12'),
  580. 13 => '<img alt="yyk" src="'.STATICURL.'image/poke/yyk.gif" class="vm" /> '.lang('home/template', 'poke_13')
  581. );
  582. return isset($icons[$iconid]) ? $icons[$iconid] : $icons[0];
  583. }
  584. function interval_check($type) {
  585. global $_G;
  586. $waittime = 0;
  587. if(checkperm('disablepostctrl')) {
  588. return $waittime;
  589. }
  590. if($_G['setting']['floodctrl']) {
  591. space_merge($_G['member'], 'status');
  592. getuserprofile('lastpost');
  593. $waittime = $_G['setting']['floodctrl'] - ($_G['timestamp'] - $_G['member']['lastpost']);
  594. }
  595. return $waittime;
  596. }
  597. function geturltitle($link, $charset = '') {
  598. $title = $linkcharset = '';
  599. $linkstr = gzfile($link);
  600. $linkstr = implode('', $linkstr);
  601. if(!$charset) {
  602. preg_match('/<meta [^>]*charset="?(.*)"/i', $linkstr, $linkcharset);
  603. $charset = strtolower($linkcharset[1]);
  604. }
  605. if(!$charset) {
  606. return $title;
  607. }
  608. if($charset != strtolower(CHARSET)) {
  609. $linkstr = diconv($linkstr, $charset);
  610. }
  611. if(!empty($linkstr) && preg_match('/\<title\>(.*)\<\/title\>/i', $linkstr, $title)) {
  612. $tmptitle = explode('_', $title[1]);
  613. if($title[1] == $tmptitle[0]) {
  614. $tmptitle = explode('-', $title[1]);
  615. }
  616. $title = trim($tmptitle[0]);
  617. }
  618. return $title;
  619. }
  620. function allowverify($vid = 0) {
  621. global $_G;
  622. if(empty($_G['setting']['verify'])) {
  623. loadcache('setting');
  624. }
  625. $allow = false;
  626. $vid = 0 < $vid && $vid < 8 ? intval($vid) : 0;
  627. if($vid) {
  628. $setting = $_G['setting']['verify'][$vid];
  629. if($setting['available'] && (empty($setting['groupid']) || in_array($_G['groupid'], $setting['groupid']))) {
  630. $allow = true;
  631. }
  632. } else {
  633. foreach($_G['setting']['verify'] as $key => $setting) {
  634. if($setting['available'] && (empty($setting['groupid']) || in_array($_G['groupid'], $setting['groupid']))) {
  635. $allow = true;
  636. break;
  637. }
  638. }
  639. }
  640. return $allow;
  641. }
  642. ?>