5; $thread_private_comment = kv_get('chuan_thread_private_comment_'.$thread['tid']); $chuan_theme_setting = kv_get('chuan_theme_setting'); empty($chuan_theme_setting) AND $chuan_theme_setting = array(); $login_required_comments = !empty($chuan_theme_setting['login_required_comments']); $comment_filter = param('comment_filter', ''); $comment_order = param('comment_order', 'asc'); $comment_order == 'desc' OR $comment_order = 'asc'; // Collect all unique uids from postlist and the thread itself $uids = array(); if (!empty($postlist)) { foreach ($postlist as $_post) { $uids[] = $_post['uid']; } } $uids[] = $thread['uid']; $uids = array_unique(array_filter($uids)); if (!empty($uids)) { global $chuan_theme_cache; if (!isset($chuan_theme_cache)) $chuan_theme_cache = array(); // 1. Batch load chuan_user_profile_{uid} from KV table $keys = array(); foreach ($uids as $_uid) { $keys[] = 'chuan_user_profile_' . $_uid; } $kv_list = db_find('kv', array('k' => $keys)); if (!isset($chuan_theme_cache['user_profiles'])) $chuan_theme_cache['user_profiles'] = array(); foreach ($uids as $_uid) { $chuan_theme_cache['user_profiles'][$_uid] = array(); } if ($kv_list) { foreach ($kv_list as $_kv) { $uid_from_key = intval(substr($_kv['k'], 19)); $chuan_theme_cache['user_profiles'][$uid_from_key] = xn_json_decode($_kv['v']); } } // 2. Batch load merchants $merchant_on = function_exists('chuan_plugin_is_on') ? chuan_plugin_is_on('Chuan_merchant_stately') : false; if ($merchant_on) { $merchants = db_find('merchant', array('uid' => $uids, 'status' => 2)); if (!isset($chuan_theme_cache['merchants'])) $chuan_theme_cache['merchants'] = array(); foreach ($uids as $_uid) { $chuan_theme_cache['merchants'][$_uid] = null; } if ($merchants) { foreach ($merchants as $_m) { $chuan_theme_cache['merchants'][$_m['uid']] = $_m; } } } // 3. Batch load equipped user badges $badge_on = function_exists('chuan_plugin_is_on') ? chuan_plugin_is_on('Chuan_badge') : false; if ($badge_on) { if (!isset($chuan_theme_cache['equipped_badges'])) $chuan_theme_cache['equipped_badges'] = array(); foreach ($uids as $_uid) { $chuan_theme_cache['equipped_badges'][$_uid] = ''; } $user_badges = db_find('chuan_user_badge', array('uid' => $uids, 'equipped' => 1)); if ($user_badges) { $badge_ids = array(); foreach ($user_badges as $_ub) { $badge_ids[] = $_ub['badgeid']; } $badge_ids = array_unique($badge_ids); // Batch load badge details $badges = db_find('chuan_badge', array('badgeid' => $badge_ids)); $badges_map = array(); if ($badges) { if (!isset($chuan_theme_cache['badges'])) $chuan_theme_cache['badges'] = array(); foreach ($badges as $_b) { $chuan_theme_cache['badges'][$_b['badgeid']] = $_b; $badges_map[$_b['badgeid']] = $_b; } } foreach ($user_badges as $_ub) { $_uid = $_ub['uid']; $_bid = $_ub['badgeid']; if (isset($badges_map[$_bid]) && !empty($badges_map[$_bid]['enabled'])) { $_b = $badges_map[$_bid]; $_icon = chuan_badge_icon_html($_b['icon'], $_b['color']); $chuan_theme_cache['equipped_badges'][$_uid] = ''.$_icon.''; } } } } } if($thread_no_comment) $allowpost = FALSE; if(empty($uid)) $allowpost = FALSE; if(!function_exists('chuan_plugin_is_on')) { function chuan_plugin_is_on($dir) { if(function_exists('plugin_paths_enabled')) { $plugins = plugin_paths_enabled(); $path = APP_PATH.'plugin/'.$dir; return !empty($plugins[$path]) && !empty($plugins[$path]['enable']); } $plugins = G('plugins', array()); return !empty($plugins[$dir]) && !empty($plugins[$dir]['enable']); } } $thread_like_count = db_count('chuan_thread_like', array('tid'=>$tid)); $thread_liked = $uid ? db_find_one('chuan_thread_like', array('uid'=>$uid, 'tid'=>$tid)) : array(); $thread_ad_on = function_exists('chuan_plugin_is_on') ? chuan_plugin_is_on('Chuan_ad') : FALSE; $thread_sponsor_on = function_exists('chuan_plugin_is_on') ? chuan_plugin_is_on('Chuan_sponsor') : FALSE; $thread_share_on = function_exists('chuan_plugin_is_on') ? chuan_plugin_is_on('Chuan_share') : FALSE; // Fetch related recommendations $related_threads = thread_find_by_fid($fid, 1, 6); if (!empty($related_threads)) { foreach ($related_threads as $k => $_r_thread) { if ($_r_thread['tid'] == $tid) { unset($related_threads[$k]); } } $related_threads = array_slice($related_threads, 0, 5); } $ai_setting = kv_get('chuan_ai_comment_setting'); $ai_list = array(); if (!empty($ai_setting) && !empty($ai_setting['enabled']) && !empty($ai_setting['ais'])) { foreach ($ai_setting['ais'] as $ai) { if (!empty($ai['enabled'])) { $_ai_user = !empty($ai['uid']) ? user_read($ai['uid']) : array(); $ai_list[] = array( 'name' => $ai['name'], 'uid' => $ai['uid'], 'avatar' => !empty($_ai_user['avatar_url']) ? $_ai_user['avatar_url'] : 'view/img/avatar.png' ); } } } $comment_children = array(); $comment_roots = array(); if (!empty($postlist)) { if($login_required_comments && empty($uid)) $postlist = array(); if($thread_private_comment && $uid != $thread['uid'] && $gid > 5) { foreach($postlist as $_pid => $_comment) { if($_comment['uid'] != $uid) unset($postlist[$_pid]); } } if($comment_filter == 'author') { foreach($postlist as $_pid => $_comment) { if($_comment['uid'] != $thread['uid']) unset($postlist[$_pid]); } } foreach ($postlist as $_comment_pid => $_comment) { $_quote_pid = empty($_comment['quotepid']) ? 0 : intval($_comment['quotepid']); if ($_quote_pid > 0 && isset($postlist[$_quote_pid])) { if (empty($comment_children[$_quote_pid])) $comment_children[$_quote_pid] = array(); $comment_children[$_quote_pid][] = $_comment_pid; } else { $comment_roots[] = $_comment_pid; } } if($comment_order == 'desc') $comment_roots = array_reverse($comment_roots); } if (!function_exists('chuan_theme_get_all_descendants')) { function chuan_theme_get_all_descendants($pid, &$comment_children) { $arr = array(); if (!empty($comment_children[$pid])) { foreach ($comment_children[$pid] as $child_pid) { $arr[] = $child_pid; $arr = array_merge($arr, chuan_theme_get_all_descendants($child_pid, $comment_children)); } } return $arr; } } if (!function_exists('chuan_theme_render_comment_tree')) { function chuan_theme_render_comment_tree($pid, &$postlist, &$comment_children, $allowpost, $allowupdate, $allowdelete, $depth = 0) { global $thread, $uid, $gid; if (empty($postlist[$pid])) return; $_post = $postlist[$pid]; $_is_child = $depth > 0; global $chuan_theme_cache; $_profile = isset($chuan_theme_cache['user_profiles'][$_post['uid']]) ? $chuan_theme_cache['user_profiles'][$_post['uid']] : array(); empty($_profile) AND $_profile = array(); $_signature = trim(array_value($_profile, 'bio', '')); $_username_html = chuan_theme_username_html($_post['uid'], $_post['username']); ?>