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