PageRenderTime 50ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/source/function/function_home.php

https://github.com/kuaileshike/upload
PHP | 612 lines | 538 code | 68 blank | 6 comment | 139 complexity | 8bfcde8500f141bc3b91749aa6cfb6d2 MD5 | raw file
  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_home.php 30195 2012-05-16 07:15:03Z zhengqingpeng $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. function getstr($string, $length, $in_slashes=0, $out_slashes=0, $bbcode=0, $html=0) {
  12. global $_G;
  13. $string = trim($string);
  14. $sppos = strpos($string, chr(0).chr(0).chr(0));
  15. if($sppos !== false) {
  16. $string = substr($string, 0, $sppos);
  17. }
  18. if($in_slashes) {
  19. $string = dstripslashes($string);
  20. }
  21. $string = preg_replace("/\[hide=?\d*\](.*?)\[\/hide\]/is", '', $string);
  22. if($html < 0) {
  23. $string = preg_replace("/(\<[^\<]*\>|\r|\n|\s|\[.+?\])/is", ' ', $string);
  24. } elseif ($html == 0) {
  25. $string = dhtmlspecialchars($string);
  26. }
  27. if($length) {
  28. $string = cutstr($string, $length);
  29. }
  30. if($bbcode) {
  31. require_once DISCUZ_ROOT.'./source/class/class_bbcode.php';
  32. $bb = & bbcode::instance();
  33. $string = $bb->bbcode2html($string, $bbcode);
  34. }
  35. if($out_slashes) {
  36. $string = daddslashes($string);
  37. }
  38. return trim($string);
  39. }
  40. function obclean() {
  41. ob_end_clean();
  42. if (getglobal('config/output/gzip') && function_exists('ob_gzhandler')) {
  43. ob_start('ob_gzhandler');
  44. } else {
  45. ob_start();
  46. }
  47. }
  48. function dreaddir($dir, $extarr=array()) {
  49. $dirs = array();
  50. if($dh = opendir($dir)) {
  51. while (($file = readdir($dh)) !== false) {
  52. if(!empty($extarr) && is_array($extarr)) {
  53. if(in_array(strtolower(fileext($file)), $extarr)) {
  54. $dirs[] = $file;
  55. }
  56. } else if($file != '.' && $file != '..') {
  57. $dirs[] = $file;
  58. }
  59. }
  60. closedir($dh);
  61. }
  62. return $dirs;
  63. }
  64. function url_implode($gets) {
  65. $arr = array();
  66. foreach ($gets as $key => $value) {
  67. if($value) {
  68. $arr[] = $key.'='.urlencode($value);
  69. }
  70. }
  71. return implode('&', $arr);
  72. }
  73. function ckstart($start, $perpage) {
  74. global $_G;
  75. $_G['setting']['maxpage'] = $_G['setting']['maxpage'] ? $_G['setting']['maxpage'] : 100;
  76. $maxstart = $perpage*intval($_G['setting']['maxpage']);
  77. if($start < 0 || ($maxstart > 0 && $start >= $maxstart)) {
  78. showmessage('length_is_not_within_the_scope_of');
  79. }
  80. }
  81. function get_my_app() {
  82. global $_G;
  83. if($_G['setting']['my_app_status']) {
  84. foreach(C::t('common_myapp')->fetch_all_by_flag(1, '=', 'DESC') as $value) {
  85. $_G['my_app'][$value['appid']] = $value;
  86. }
  87. }
  88. }
  89. function get_my_userapp() {
  90. global $_G;
  91. if($_G['setting']['my_app_status'] && $_G['uid']) {
  92. foreach(C::t('home_userapp')->fetch_all_by_uid_appid($_G['uid'], 0, 'displayorder') as $value) {
  93. if(!empty($value['appname'])) {
  94. $_G['my_userapp'][$value['appid']] = $value;
  95. }
  96. }
  97. }
  98. }
  99. function getspace($uid) {
  100. return getuserbyuid($uid);
  101. }
  102. function ckprivacy($key, $privace_type) {
  103. global $_G, $space;
  104. $var = "home_ckprivacy_{$key}_{$privace_type}";
  105. if(isset($_G[$var])) {
  106. return $_G[$var];
  107. }
  108. space_merge($space, 'field_home');
  109. $result = false;
  110. if($_G['adminid'] == 1) {
  111. $result = true;
  112. } else {
  113. if($privace_type == 'feed') {
  114. if(!empty($space['privacy'][$privace_type][$key])) {
  115. $result = true;
  116. }
  117. } elseif($space['self']){
  118. $result = true;
  119. } else {
  120. if(empty($space['privacy'][$privace_type][$key])) {
  121. $result = true;
  122. } elseif ($space['privacy'][$privace_type][$key] == 1) {
  123. include_once libfile('function/friend');
  124. if(friend_check($space['uid'])) {
  125. $result = true;
  126. }
  127. } elseif ($space['privacy'][$privace_type][$key] == 3) {
  128. $result = in_array($_G['groupid'], array(4, 5, 6, 7)) ? false : true;
  129. }
  130. }
  131. }
  132. $_G[$var] = $result;
  133. return $result;
  134. }
  135. function app_ckprivacy($privacy) {
  136. global $_G, $space;
  137. $var = "home_app_ckprivacy_{$privacy}";
  138. if(isset($_G[$var])) {
  139. return $_G[$var];
  140. }
  141. $result = false;
  142. switch ($privacy) {
  143. case 0:
  144. $result = true;
  145. break;
  146. case 1:
  147. include_once libfile('function/friend');
  148. if(friend_check($space['uid'])) {
  149. $result = true;
  150. }
  151. break;
  152. case 2:
  153. break;
  154. case 3:
  155. if($space['self']) {
  156. $result = true;
  157. }
  158. break;
  159. case 4:
  160. break;
  161. case 5:
  162. break;
  163. default:
  164. $result = true;
  165. break;
  166. }
  167. $_G[$var] = $result;
  168. return $result;
  169. }
  170. function formatsize($size) {
  171. $prec=3;
  172. $size = round(abs($size));
  173. $units = array(0=>" B ", 1=>" KB", 2=>" MB", 3=>" GB", 4=>" TB");
  174. if ($size==0) return str_repeat(" ", $prec)."0$units[0]";
  175. $unit = min(4, floor(log($size)/log(2)/10));
  176. $size = $size * pow(2, -10*$unit);
  177. $digi = $prec - 1 - floor(log($size)/log(10));
  178. $size = round($size * pow(10, $digi)) * pow(10, -$digi);
  179. return $size.$units[$unit];
  180. }
  181. function ckfriend($touid, $friend, $target_ids='') {
  182. global $_G;
  183. if(empty($_G['uid'])) return $friend?false:true;
  184. if($touid == $_G['uid'] || $_G['adminid'] == 1) return true;
  185. $var = 'home_ckfriend_'.md5($touid.'_'.$friend.'_'.$target_ids);
  186. if(isset($_G[$var])) return $_G[$var];
  187. $_G[$var] = false;
  188. switch ($friend) {
  189. case 0:
  190. $_G[$var] = true;
  191. break;
  192. case 1:
  193. include_once libfile('function/friend');
  194. if(friend_check($touid)) {
  195. $_G[$var] = true;
  196. }
  197. break;
  198. case 2:
  199. if($target_ids) {
  200. $target_ids = explode(',', $target_ids);
  201. if(in_array($_G['uid'], $target_ids)) $_G[$var] = true;
  202. }
  203. break;
  204. case 3:
  205. break;
  206. case 4:
  207. $_G[$var] = true;
  208. break;
  209. default:
  210. break;
  211. }
  212. return $_G[$var];
  213. }
  214. function ckfollow($followuid) {
  215. global $_G;
  216. if(empty($_G['uid'])) return false;
  217. $var = 'home_follow_'.$_G['uid'].'_'.$followuid;
  218. if(isset($_G[$var])) return $_G[$var];
  219. $_G[$var] = false;
  220. $follow = C::t('home_follow')->fetch_status_by_uid_followuid($_G['uid'], $followuid);
  221. if(isset($follow[$_G['uid']])) {
  222. $_G[$var] = true;
  223. }
  224. return $_G[$var];
  225. }
  226. function sub_url($url, $length) {
  227. if(strlen($url) > $length) {
  228. $url = str_replace(array('%3A', '%2F'), array(':', '/'), rawurlencode($url));
  229. $url = substr($url, 0, intval($length * 0.5)).' ... '.substr($url, - intval($length * 0.3));
  230. }
  231. return $url;
  232. }
  233. function space_domain($space) {
  234. global $_G;
  235. if($_G['setting']['allowspacedomain'] && $_G['setting']['domain']['root']['home']) {
  236. space_merge($space, 'field_home');
  237. if($space['domain']) {
  238. $space['domainurl'] = 'http://'.$space['domain'].'.'.$_G['setting']['domain']['root']['home'];
  239. }
  240. }
  241. if(!empty($_G['setting']['domain']['app']['home'])) {
  242. $space['domainurl'] = 'http://'.$_G['setting']['domain']['app']['home'].'/?'.$space['uid'];
  243. } elseif(empty($space['domainurl'])) {
  244. $space['domainurl'] = $_G['siteurl'].'?'.$space['uid'];
  245. }
  246. return $space['domainurl'];
  247. }
  248. function g_name($groupid) {
  249. global $_G;
  250. echo $_G['cache']['usergroups'][$groupid]['grouptitle'];
  251. }
  252. function g_color($groupid) {
  253. global $_G;
  254. if(empty($_G['cache']['usergroups'][$groupid]['color'])) {
  255. echo '';
  256. } else {
  257. echo ' style="color:'.$_G['cache']['usergroups'][$groupid]['color'].';"';
  258. }
  259. }
  260. function mob_perpage($perpage) {
  261. global $_G;
  262. $newperpage = isset($_GET['perpage'])?intval($_GET['perpage']):0;
  263. if($_G['mobile'] && $newperpage>0 && $newperpage<500) {
  264. $perpage = $newperpage;
  265. }
  266. return $perpage;
  267. }
  268. function ckicon_uid($feed) {
  269. global $_G, $space;
  270. space_merge($space, 'field_home');
  271. $filter_icon = empty($space['privacy']['filter_icon'])?array():array_keys($space['privacy']['filter_icon']);
  272. if($filter_icon && (in_array($feed['icon'].'|0', $filter_icon) || in_array($feed['icon'].'|'.$feed['uid'], $filter_icon))) {
  273. return false;
  274. }
  275. return true;
  276. }
  277. function sarray_rand($arr, $num=1) {
  278. $r_values = array();
  279. if($arr && count($arr) > $num) {
  280. if($num > 1) {
  281. $r_keys = array_rand($arr, $num);
  282. foreach ($r_keys as $key) {
  283. $r_values[$key] = $arr[$key];
  284. }
  285. } else {
  286. $r_key = array_rand($arr, 1);
  287. $r_values[$r_key] = $arr[$r_key];
  288. }
  289. } else {
  290. $r_values = $arr;
  291. }
  292. return $r_values;
  293. }
  294. function my_showgift() {
  295. global $_G, $space;
  296. if($_G['setting']['my_showgift'] && $_G['my_userapp'][$_G['home_gift_appid']]) {
  297. echo '<script language="javascript" type="text/javascript" src="http://gift.manyou-apps.com/recommend.js"></script>';
  298. }
  299. }
  300. function getsiteurl() {
  301. global $_G;
  302. return $_G['siteurl'];
  303. }
  304. function pic_get($filepath, $type, $thumb, $remote, $return_thumb=1, $hastype = '') {
  305. global $_G;
  306. $url = $filepath;
  307. if($return_thumb && $thumb) $url = getimgthumbname($url);
  308. if($remote > 1 && $type == 'album') {
  309. $remote -= 2;
  310. $type = 'forum';
  311. }
  312. $type = $hastype ? '' : $type.'/';
  313. return ($remote?$_G['setting']['ftp']['attachurl']:$_G['setting']['attachurl']).$type.$url;
  314. }
  315. function pic_cover_get($pic, $picflag) {
  316. global $_G;
  317. $type = 'album';
  318. if($picflag > 2) {
  319. $picflag = $picflag - 2;
  320. $type = 'forum';
  321. }
  322. if($picflag == 1) {
  323. $url = $_G['setting']['attachurl'].$type.'/'.$pic;
  324. } elseif ($picflag == 2) {
  325. $url = $_G['setting']['ftp']['attachurl'].$type.'/'.$pic;
  326. } else {
  327. $url = $pic;
  328. }
  329. return $url;
  330. }
  331. function pic_delete($pic, $type, $thumb, $remote) {
  332. global $_G;
  333. if($remote > 1 && $type == 'album') {
  334. $remote -= 2;
  335. $type = 'forum';
  336. return true;
  337. }
  338. if($remote) {
  339. ftpcmd('delete', $type.'/'.$pic);
  340. if($thumb) {
  341. ftpcmd('delete', $type.'/'.getimgthumbname($pic));
  342. }
  343. ftpcmd('close');
  344. } else {
  345. @unlink($_G['setting']['attachdir'].'/'.$type.'/'.$pic);
  346. if($thumb) {
  347. @unlink($_G['setting']['attachdir'].'/'.$type.'/'.getimgthumbname($pic));
  348. }
  349. }
  350. return true;
  351. }
  352. function pic_upload($FILES, $type='album', $thumb_width=0, $thumb_height=0, $thumb_type=2) {
  353. $upload = new discuz_upload();
  354. $result = array('pic'=>'', 'thumb'=>0, 'remote'=>0);
  355. $upload->init($FILES, $type);
  356. if($upload->error()) {
  357. return array();
  358. }
  359. $upload->save();
  360. if($upload->error()) {
  361. return array();
  362. }
  363. $result['pic'] = $upload->attach['attachment'];
  364. if($thumb_width && $thumb_height) {
  365. require_once libfile('class/image');
  366. $image = new image();
  367. if($image->Thumb($upload->attach['target'], '', $thumb_width, $thumb_height, $thumb_type)) {
  368. $result['thumb'] = 1;
  369. }
  370. }
  371. if(getglobal('setting/ftp/on')) {
  372. if(ftpcmd('upload', $type.'/'.$upload->attach['attachment'])) {
  373. if($result['thumb']) {
  374. ftpcmd('upload', $type.'/'.getimgthumbname($upload->attach['attachment']));
  375. }
  376. ftpcmd('close');
  377. $result['remote'] = 1;
  378. } else {
  379. if(getglobal('setting/ftp/mirror')) {
  380. @unlink($upload->attach['target']);
  381. @unlink(getimgthumbname($upload->attach['target']));
  382. return array();
  383. }
  384. }
  385. }
  386. return $result;
  387. }
  388. function member_count_update($uid, $counts) {
  389. global $_G;
  390. $setsqls = array();
  391. foreach ($counts as $key => $value) {
  392. if($key == 'credit') {
  393. if($_G['setting']['creditstransextra'][6]) {
  394. $key = 'extcredits'.intval($_G['setting']['creditstransextra'][6]);
  395. } elseif ($_G['setting']['creditstrans']) {
  396. $key = 'extcredits'.intval($_G['setting']['creditstrans']);
  397. } else {
  398. continue;
  399. }
  400. }
  401. $setsqls[$key] = $value;
  402. }
  403. if($setsqls) {
  404. updatemembercount($uid, $setsqls);
  405. }
  406. }
  407. function getdefaultdoing() {
  408. global $_G;
  409. $result = array();
  410. $key = 0;
  411. if(($result = C::t('common_setting')->fetch('defaultdoing'))) {
  412. $_G['setting']['defaultdoing'] = explode("\r\n", $result);
  413. $key = rand(0, count($_G['setting']['defaultdoing'])-1);
  414. } else {
  415. $_G['setting']['defaultdoing'] = array(lang('space', 'doing_you_can'));
  416. }
  417. return $_G['setting']['defaultdoing'][$key];
  418. }
  419. function getuserdiydata($space) {
  420. global $_G;
  421. if(empty($_G['blockposition'])) {
  422. $userdiy = getuserdefaultdiy();
  423. if (!empty($space['blockposition'])) {
  424. $blockdata = dunserialize($space['blockposition']);
  425. foreach ((array)$blockdata as $key => $value) {
  426. if ($key == 'parameters') {
  427. foreach ((array)$value as $k=>$v) {
  428. if (!empty($v)) $userdiy[$key][$k] = $v;
  429. }
  430. } else {
  431. if (!empty($value)) $userdiy[$key] = $value;
  432. }
  433. }
  434. }
  435. $_G['blockposition'] = $userdiy;
  436. }
  437. return $_G['blockposition'];
  438. }
  439. function getuserdefaultdiy() {
  440. $defaultdiy = array(
  441. 'currentlayout' => '1:2:1',
  442. 'block' => array(
  443. 'frame`frame1' => array(
  444. 'attr' => array('name'=>'frame1'),
  445. 'column`frame1_left' => array(
  446. 'block`profile' => array('attr' => array('name'=>'profile')),
  447. 'block`statistic' => array('attr' => array('name'=>'statistic')),
  448. 'block`album' => array('attr' => array('name'=>'album')),
  449. 'block`doing' => array('attr' => array('name'=>'doing'))
  450. ),
  451. 'column`frame1_center' => array(
  452. 'block`personalinfo' => array('attr' => array('name'=>'personalinfo')),
  453. 'block`feed' => array('attr' => array('name'=>'feed')),
  454. 'block`share' => array('attr' => array('name'=>'share')),
  455. 'block`blog' => array('attr' => array('name'=>'blog')),
  456. 'block`thread' => array('attr' => array('name'=>'thread')),
  457. 'block`wall' => array('attr' => array('name'=>'wall'))
  458. ),
  459. 'column`frame1_right' => array(
  460. 'block`myapp' => array('attr' => array('name'=>'myapp')),
  461. 'block`friend' => array('attr' => array('name'=>'friend')),
  462. 'block`visitor' => array('attr' => array('name'=>'visitor')),
  463. 'block`group' => array('attr' => array('name'=>'group'))
  464. )
  465. )
  466. ),
  467. 'parameters' => array(
  468. 'blog' => array('showmessage' => 150, 'shownum' => 6),
  469. 'doing' => array('shownum' => 15),
  470. 'album' => array('shownum' => 8),
  471. 'thread' => array('shownum' => 10),
  472. 'share' => array('shownum' => 10),
  473. 'friend' => array('shownum' => 18),
  474. 'group' => array('shownum' => 12),
  475. 'visitor' => array('shownum' => 18),
  476. 'wall' => array('shownum' => 16),
  477. 'feed' => array('shownum' => 16),
  478. 'myapp' => array('shownum' => 9, 'logotype'=> 'logo'),
  479. ),
  480. 'nv' => array(
  481. 'nvhidden' => 0,
  482. 'items' => array(),
  483. 'banitems' => array(),
  484. ),
  485. );
  486. return $defaultdiy;
  487. }
  488. function getonlinemember($uids) {
  489. global $_G;
  490. if ($uids && is_array($uids) && empty($_G['ols'])) {
  491. $_G['ols'] = array();
  492. foreach(C::app()->session->fetch_all_by_uid($uids) as $value) {
  493. if(!$value['invisible']) {
  494. $_G['ols'][$value['uid']] = $value['lastactivity'];
  495. }
  496. }
  497. }
  498. }
  499. function getfollowfeed($uid, $viewtype, $archiver = false, $start = 0, $perpage = 0) {
  500. global $_G;
  501. $list = array();
  502. if(isset($_G['follwusers'][$uid])) {
  503. $list['user'] = $_G['follwusers'][$uid];
  504. } else {
  505. if($viewtype == 'follow') {
  506. $list['user'] = C::t('home_follow')->fetch_all_following_by_uid($uid);
  507. $list['user'][$uid] = array('uid' => $uid);
  508. } elseif($viewtype == 'special') {
  509. $list['user'] = C::t('home_follow')->fetch_all_following_by_uid($uid, 1);
  510. }
  511. if(!empty($list['user'])) {
  512. $_G['follwusers'][$uid] = $list['user'];
  513. }
  514. }
  515. $uids = in_array($viewtype, array('other', 'self')) ? $uid : array_keys($list['user']);
  516. if(!empty($uids) || in_array($viewtype, array('other', 'self'))) {
  517. $list['feed'] = C::t('home_follow_feed')->fetch_all_by_uid($uids, $archiver, $start, $perpage);
  518. if($list['feed']) {
  519. $list['content'] = C::t('forum_threadpreview')->fetch_all(C::t('home_follow_feed')->get_tids());
  520. if(!$_G['group']['allowgetattach'] || !$_G['group']['allowgetimage']) {
  521. foreach($list['content'] as $key => $feed) {
  522. if(!$_G['group']['allowgetimage']) {
  523. $list['content'][$key]['content'] = preg_replace("/[ \t]*\<li\>\<img id=\"aimg_(.+?)\".*?\>[ \t]*\<\/li\>/is", '', $feed['content']);
  524. }
  525. if(!$_G['group']['allowgetattach']) {
  526. $list['content'][$key]['content'] = preg_replace("/[ \t]*\<li\>\<a href=\"(.+?)\" id=\"attach_(.+?)\".*?\>.*?\<\/a\>[ \t]*\<\/li\>/is", '', $feed['content']);
  527. }
  528. }
  529. }
  530. $list['threads'] = C::t('forum_thread')->fetch_all_by_tid(C::t('home_follow_feed')->get_tids());
  531. }
  532. }
  533. return $list;
  534. }
  535. function getthread() {
  536. $threads = array();
  537. foreach(C::t('home_follow_feed')->get_ids() as $idtype => $ids) {
  538. if($idtype == 'thread') {
  539. $threads = C::t('forum_thread')->fetch_all_by_tid($ids);
  540. }
  541. }
  542. return $threads;
  543. }
  544. ?>