PageRenderTime 64ms CodeModel.GetById 36ms RepoModel.GetById 1ms app.codeStats 0ms

/source/function/function_collection.php

https://github.com/jinbo51/DiscuzX
PHP | 164 lines | 139 code | 19 blank | 6 comment | 31 complexity | 1e196c88a1d4869fd2a28437a39f9713 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_collection.php 31438 2012-08-28 06:03:08Z chenmengshu $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. function getmycollection($uid) {
  12. $collections = C::t('forum_collection')->fetch_all_by_uid($uid);
  13. $collectionteamworker = C::t('forum_collectionteamworker')->fetch_all_by_uid($uid);
  14. return $collections + $collectionteamworker;
  15. }
  16. function getHotCollection($number = 500, $pK = true) {
  17. $collection = array();
  18. if($number > 0) {
  19. $collection = C::t('forum_collection')->range(0, $number, 10, $pK);
  20. if(!$collection || count($collection) < $number) {
  21. $collection += C::t('forum_collection')->range(0, $number, null, $pK);
  22. }
  23. }
  24. return $collection;
  25. }
  26. function checkcollectionperm($collection, $uid, $allowteamworker = false) {
  27. global $_G;
  28. if($_G['group']['allowmanagecollection'] == 1) {
  29. return true;
  30. }
  31. if($collection['uid'] == $uid) {
  32. return true;
  33. }
  34. if($allowteamworker) {
  35. $collectionteamworker = C::t('forum_collectionteamworker')->fetch_all_by_ctid($collection['ctid']);
  36. $collectionteamworker = array_keys($collectionteamworker);
  37. if(in_array($uid, $collectionteamworker)) {
  38. return true;
  39. }
  40. }
  41. return false;
  42. }
  43. function processCollectionData($collection, $tf = array(), $orderby = '') {
  44. if(count($collection) <= 0) {
  45. return array();
  46. }
  47. require_once libfile('function/discuzcode');
  48. foreach($collection as $ctid=>&$curvalue) {
  49. $curvalue['updated'] = ($curvalue['lastupdate'] > $tf[$ctid]['lastvisit']) ? 1 : 0;
  50. $curvalue['tflastvisit'] = $tf[$ctid]['lastvisit'];
  51. $curvalue['lastupdate'] = dgmdate($curvalue['lastupdate']);
  52. $curvalue['dateline'] = dgmdate($curvalue['dateline']);
  53. $curvalue['lastposttime'] = dgmdate($curvalue['lastposttime']);
  54. $curvalue['avgrate'] = number_format($curvalue['rate'], 1);
  55. $curvalue['star'] = imgdisplayrate($curvalue['rate']);
  56. $curvalue['lastposterhtml'] = rawurlencode($curvalue['lastposter']);
  57. $curvalue['shortdesc'] = cutstr(strip_tags(discuzcode($curvalue['desc'])), 50);
  58. $curvalue['arraykeyword'] = parse_keyword($curvalue['keyword'], false, false);
  59. if($curvalue['arraykeyword']) {
  60. foreach ($curvalue['arraykeyword'] as $kid=>$s_keyword) {
  61. $curvalue['urlkeyword'][$kid] = rawurlencode($s_keyword);
  62. }
  63. }
  64. if($orderby == 'commentnum') {
  65. $curvalue['displaynum'] = $curvalue['commentnum'];
  66. } elseif($orderby == 'follownum') {
  67. $curvalue['displaynum'] = $curvalue['follownum'];
  68. } else {
  69. $curvalue['displaynum'] = $curvalue['threadnum'];
  70. }
  71. }
  72. return $collection;
  73. }
  74. function collectionThread(&$threadlist, $foruminfo = false, $lastvisit = null, &$collectiontids = null) {
  75. global $todaytime;
  76. if($foruminfo) {
  77. foreach ($threadlist as $thread) {
  78. $fids[$thread['fid']] = $thread['fid'];
  79. }
  80. $foruminfo = C::t('forum_forum')->fetch_all($fids);
  81. }
  82. foreach($threadlist as $curtid=>&$curvalue) {
  83. if($lastvisit) {
  84. $curvalue['reason'] = &$collectiontids[$curtid]['reason'];
  85. $curvalue['updatedthread'] = $lastvisit !== null && $lastvisit < $curvalue['dateline'] ? 1 : 0;
  86. }
  87. if($foruminfo) {
  88. $curvalue['forumname'] = $foruminfo[$curvalue['fid']]['name'];
  89. }
  90. $curvalue['istoday'] = $curvalue['dateline'] > $todaytime ? 1 : 0;
  91. $curvalue['dbdateline'] = $curvalue['dateline'];
  92. $curvalue['htmlsubject'] = dhtmlspecialchars($curvalue['subject']);
  93. $curvalue['cutsubject'] = $curvalue['subject'];
  94. $curvalue['dateline'] = dgmdate($curvalue['dateline'], 'u', '9999', getglobal('setting/dateformat'));
  95. $curvalue['dblastpost'] = $curvalue['lastpost'];
  96. $curvalue['lastpost'] = dgmdate($curvalue['lastpost'], 'u');
  97. $curvalue['lastposterenc'] = rawurlencode($curvalue['lastposter']);
  98. }
  99. if($collectiontids) {
  100. foreach($collectiontids as $curkey=>&$curthread) {
  101. if(!$threadlist[$curthread['tid']]) {
  102. unset($collectiontids[$curkey]);
  103. } else {
  104. $curthread = $threadlist[$curthread['tid']] + $curthread;
  105. }
  106. }
  107. }
  108. }
  109. function imgdisplayrate($rate) {
  110. $roundscore = floor($rate);
  111. return $roundscore;
  112. }
  113. function parse_keyword($keywords, $string = false, $filter = true) {
  114. if($keywords == '') {
  115. return $string === true ? '' : array();
  116. }
  117. $return = array();
  118. if($filter === true) {
  119. $keywords = str_replace(array(chr(0xa3).chr(0xac), chr(0xa1).chr(0x41), chr(0xef).chr(0xbc).chr(0x8c)), ',', censor($keywords));
  120. }
  121. if(strexists($keywords, ',')) {
  122. $tagarray = array_unique(explode(',', $keywords));
  123. } else {
  124. $langcore = lang('core');
  125. $keywords = str_replace($langcore['fullblankspace'], ' ', $keywords);
  126. $tagarray = array_unique(explode(' ', $keywords));
  127. }
  128. $tagcount = 0;
  129. foreach($tagarray as $tagname) {
  130. $tagname = trim($tagname);
  131. if(preg_match('/^([\x7f-\xff_-]|\w|\s){3,20}$/', $tagname)) {
  132. $tagcount++;
  133. $return[] = $tagname;
  134. if($tagcount > 4) {
  135. unset($tagarray);
  136. break;
  137. }
  138. }
  139. }
  140. if($string === true) {
  141. $return = implode(',', $return);
  142. }
  143. return $return;
  144. }
  145. ?>