哈囉大家~不知道有沒有跟站長一樣~程式相關的從業人員呢~
討論區文章格式,是支援程式碼的唷~
歡迎大家多多利用這個專區,來互相交流~
作為功能示範,站長貼一段梗圖倉庫的程式碼~
是一段很簡單的熱門分數演算法~
function refreshTrendingScore()
{
if ($this->approved_at < \Carbon\Carbon::now()->subHours(
24 * trending_image_beginning_live_days() + $this->total_like_count * trending_image_extra_hours_per_like()
)) {
$this->trending_score = 0;
$this->save();
return;
}
$score = 0;
if ($this->user_id != 0) {
$score += 100;
if ($this->user->intro) $score += 2;
if ($this->user->photo) $score += 2;
if ($this->user->created_at >= \Carbon\Carbon::now()->subDays(2) ||
$this->user->wtf_total_count < 4)
{
$score += 4;
}
}
if ($this->hashtag != '') $score += 2;
if ($this->contest_id != 0) $score += 2;
// $score = $score + floor($this->pageview / 1000) * 0;
$userId = $this->user_id;
$score += $this->likes->filter(function($like) use ($userId) { return $userId != $like->user_id; })->count() * 10;
if ($this->comments->filter(function($comment) use ($userId) { return $userId != $comment->user_id; })->count() > 0) {
$score += 10;
}
if ($score >= 10) {
$this->trending_score = $score;
} else {
$this->trending_score = 0;
}
if ($this->is_sensitive) {
$this->trending_score = 0;
}
$this->save();
}
拋磚引玉,歡迎大家多多利用這個專區交流~
謝謝大家~
請問站長,要如何在討論區使用這個格式呢?