定制 liplum/flarum-trends 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

liplum/flarum-trends

Composer 安装命令:

composer require liplum/flarum-trends

包简介

The trending discussions for Flarum

README 文档

README

A Flarum extension to serve API for trending discussions.

Get Started

Installation

To install the dependencies for this extension, run the following commands:

composer require michaelbelgium/flarum-discussion-views
composer require liplum/flarum-trends

Update

composer update liplum/flarum-trends

Usage

This extension provides an API endpoint to retrieve trending discussions based on recent activity.

Endpoint

  • GET /api/trends

Query Parameters

  • limit (integer, optional): The maximum number of discussions to return. Defaults to 10.

Response

The API returns a JSON array of discussion objects. Each discussion object contains the following properties:

  • id (string): The discussion ID.
  • title (string): The discussion title.
  • commentCount (integer): The number of comments in the discussion.
  • participantCount (integer): The number of participants in the discussion.
  • viewCount (integer): The number of views of the discussion.
  • createdAt (string): The creation time of the discussion in ISO 8601 format.
  • lastActivityAt (string): The last activity time of the discussion in ISO 8601 format.
  • shareUrl (string): The URL to share the discussion.
  • trendingScore (number): The trending score of the discussion.
  • user (object): An object containing the user's ID and username.
    • id (string): The user ID.
    • username (string): The username.

Typing

interface TrendingDiscussionsResponse {
  data: TrendingDiscussion[];
}

interface TrendingDiscussion {
  type: 'discussions';
  id: string;
  attributes: {
    title: string;
    commentCount: number;
    participantCount: number;
    viewCount: number;
    createdAt: string;
    lastActivityAt: string;
    shareUrl: string;
    trendingScore: number;
  };
  relationships: {
    user: {
      data: {
        type: 'users';
        id: string;
        attributes: {
          username: string;
        };
      };
    };
  };
}

Example Request

GET /api/trends/recent?limit=5

Example Response

{
  "data": [
    {
      "type": "discussions",
      "id": "123",
      "attributes": {
        "title": "Discussion Title 1",
        "commentCount": 50,
        "participantCount": 20,
        "viewCount": 1000,
        "createdAt": "2023-10-27T10:00:00+00:00",
        "lastActivityAt": "2023-10-27T11:30:00+00:00",
        "shareUrl": "https://discuss.flarum.org/d/123",
        "trendingScore": 1234.56
      },
      "relationships": {
        "user": {
          "data": {
            "type": "users",
            "id": "1",
            "attributes": {
              "username": "user1"
            }
          }
        }
      }
    },
    {
      "type": "discussions",
      "id": "456",
      "attributes": {
        "title": "Discussion Title 2",
        "commentCount": 30,
        "participantCount": 15,
        "viewCount": 750,
        "createdAt": "2023-10-26T15:30:00+00:00",
        "lastActivityAt": "2023-10-26T15:30:00+00:00",
        "shareUrl": "https://discuss.flarum.org/d/456",
        "trendingScore": 876.54
      },
      "relationships": {
        "user": {
          "data": {
            "type": "users",
            "id": "2",
            "attributes": {
              "username": "user2"
            }
          }
        }
      }
    }
  ]
}

Trending Score Formula

$S$ = [($W_c \times N_c$) + ($W_p \times N_p$) + ($W_v \times N_v$)] $\times D(days)$

Where:

  • $W_c$: Weight assigned to comment count.
  • $N_c$: Number of comments in the discussion.
  • $W_p$: Weight assigned to participant count.
  • $N_p$: Number of participants in the discussion.
  • $W_v$: Weight assigned to view count.
  • $N_v$: Number of views of the discussion.
  • $D(days)$: Decay factor that controls the rate of time decay. It gradually reduces the score over time, reaching zero at the specified time limit.

The trending score is calculated for each discussion, and discussions are then sorted in descending order based on their scores.

Notes

  • Hidden, locked, and private discussions are excluded from the results.

liplum/flarum-trends 适用场景与选型建议

liplum/flarum-trends 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.26k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2025 年 03 月 13 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「hot」 「trends」 「flarum」 「popular」 「trending」 「flarum-extension」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 liplum/flarum-trends 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 liplum/flarum-trends 我们能提供哪些服务?
定制开发 / 二次开发

基于 liplum/flarum-trends 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 1.26k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 20
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-03-13