rokfor/rokfor-slim

Rokfor CMS:基于JSON api的无头CMS

安装: 1

依赖: 0

建议者: 0

安全: 0

星标: 10

关注者: 3

分支: 5

开放问题: 8

类型:项目


README

Rokfor基于Slim Framework(http://slimframework.com/)为PHP构建。Rokfor是一个以数据为中心的、以API为先的内容管理系统。其逻辑基于我们周围的一切:书籍和杂志。

概述

数据结构

  • 基本结构称为书籍,分为称为章节的部分
  • 书籍以(多个)称为问题的实例存在
  • 章节包含称为贡献的数据
  • 贡献是定义在模板中的字段的集合

模板

  • 文本:多字段数组,RTF文本,Markdown,纯文本
  • 表格:动态行和列
  • 数字:整数,浮点数或可自定义的日期
  • 位置:包括Google Maps和位置选择器
  • 图片和文件:自动调整到多个预览,保持原始大小
  • 选择框:单选、多选、可排序。各种数据关系(一对一、一对多,基于指向其他贡献、书籍或章节的外键)
  • 滑块:一维或二维

用户

  • 多用户设置
  • 角色:管理员、普通用户
  • 根据访问组访问章节、模板和书籍

API

  • 只读API,带有携带密钥认证
  • 基于JWT令牌的读写API
  • 基于用户配置文件的CORS设置和IP限制
  • RESTful

安装

  • 通过composer安装,使用grunt和bower作为构建系统
  • 运行在Nginx和Apache后面
  • 上传存储在服务器上或S3服务上,适用于云/负载均衡安装
  • 需要MySQL和(为了最佳性能)Redis
  • 可部署在EC2实例上(在Beanstalk上测试过),在Dokker(使用Dokku测试)和Heroku上运行

Rokfor针对速度进行了优化,尽管在大数据库上的复杂搜索查询可能需要一段时间。问题在于关系数据库的本质以及创建字段之间多对多关系的复杂性。简单的API调用很快,因为Rokfor在多个级别上实现了缓存方法

  • 可选地使用Redis作为重复查询的键/值存储,如果没有数据更改。
  • 使用MySQL缓存表以加快关系查询。

二进制上传可以存储在服务器上或推送到兼容S3的存储提供程序。

Rokfor与Nginx配合使用效果最佳,支持代理缓存和X-Accel-Headers以实现快速文件下载。

Dashboard

Rokfor已经有了更长的历史。旧的构建主要用于创建印刷品。为了使其对公众更有用,我们决定完全重新编写它,应用现代的PHP应用程序编写方式

  • Composer安装系统
  • AdminLTE后端主题
  • Propel ORM

设置和安装

1. 前提条件

  • MySQL数据库:服务器、用户名、密码和数据库名
  • PHP >= 5.5
  • Composer

2. 安装依赖项

克隆仓库并使用composer安装依赖项

$ git clone https://github.com/Rokfor/rokfor-slim.git
$ cd rokfor-slim
$ composer install
$ composer update

3. 配置

首先,创建数据库和设置配置文件的副本。将*.local.php重命名为*.php文件

$ cd config
$ cp database.local.php database.php
$ cp settings.local.php settings.php

只要您保持目录结构,settings.php 文件中的选项就不需要更改。谈到 目录:请确保,Web服务器可以访问 udbcache 文件夹。

public         _Webserver Document Root_
| index.php    
| udb          _Default Storage directory, chmod r/w for the webserver_
| assets
config         _Configuration Files_
locale         _Localization Files, currently only german_
cache          _Template Cache_
src            _Rokfor PHP Runtime Sources_
vendor         _Composer Dependencies_
templates      _Jade Templates_
build          _Css and Javascript Sources_

其次,您需要更改 database.php 中的数据库设置。为了实现这一点,您需要知道MySQL账户的用户、密码、数据库和服务器。如果您在配置文件中启用 版本控制,所有贡献的更改都将被跟踪。这在您想保留编辑历史的情况下很有用。缺点是,它将创建大量数据。如果您将日志 级别 更改为 \Monolog\Logger::DEBUG,所有SQL查询都将被记录。日志文件的路径可以在 log 设置中调整。

// Database settings

return [
  'host'      => 'localhost',                     // Server Address
  'user'      => '',                              // User Name
  'pass'      => '',                              // Password
  'dbname'    => '',                              // Database Name
  'log'       => __DIR__ . '/../logs/propel.log', // Log File for Propel
  'level'     => \Monolog\Logger::ERROR,          // Error Level
  'versioning'=> false,                           // Store Versions of  
                                                  // Contributions and Data
  //'socket'  => '/tmp/mysql.sock',               // Unix Socket, normally
                                                  // not needed
  //'port'    => 3306,                            // Port, if default not needed
];

运行Rokfor

PHP服务器模式(调试)

$ cd rokfor-slim (base directory of the repository)
$ php -S 0.0.0.0:8080 -t public public/index.php

现在您应该能够访问 https://:8080/rf 并使用默认用户 root 和密码 123 登录。

Apache

当使用Apache运行Rokfor时,有3件重要的事情需要记住

  1. 请确保Web服务器对 cacheudb 目录都具有读写访问权限
  2. 服务器的document_root需要指向 public 目录。如果您无法更改此设置,请根据您的服务器配置重命名目录,并重新配置settings.php文件。
  3. 还需要 mod_rewrite 来将所有流量重定向到 index.html

构建Rokfor

Rokfor使用grunt进行构建,并使用bower安装依赖项。假设您已安装node和npm

$ npm install
$ bower install
$ grunt

grunt任务会压缩CSS文件,创建JavaScript包,并将所有文件复制到public目录。只有在您想开发和为Rokfor做出贡献时才需要构建。

获取一些数据:只读API

访问密钥

为了访问数据,您需要在用户资料中设置用户并定义只读API密钥。只有以root身份登录才能添加用户。我们为什么使用API密钥进行只读访问有两个原因。首先,您可以定义哪些数据被发布,其次,密钥不是密码。即使发布了密钥,也无法登录系统并编辑内容。

通过带令牌认证头或access_token查询字符串发送密钥。发送头可能是更好的解决方案,因为查询字符串不会太混乱,并且API密钥可能不会出现在服务器日志中。虽然GET调用可能稍微困难一些,但它是可行的。

GET /api/contributions/1/1?access_token=[key]

$ curl -H "Authorization: Bearer [key]" https://:8080/api/contributions/1/1

当前API路由

使用选项加载贡献集合

GET /api/contributions/:issueid|:issueid-:issueid.../:chapterid|:chapterid-:chapterid...?[options]

Options:

- query=string                                                (default: empty)
- filter=[id|date|sort|templateid[s]]:[lt[e]|gt[e]|eq|like]   (default: [omitted]:like)
- sort=[[id|date|name|sort]|chapter|issue|templateid[s]]:[asc|desc]           (default: sort:asc)
- limit=int                                                   (default: empty)
- offset=int                                                  (default: empty)
- data=[Fieldname|Fieldname|XX]                               (default: empty)
- populate=true|false                                         (default: false)
- verbose=true|false                                          (default: false)
- template=id                                                 (default: empty)
- status=draft|published|both                                 (default: published)

  • 查询:在贡献名称或文本字段内搜索字符串。特殊查询:date:now被转换为当前时间戳
  • 过滤:将查询字符串中的搜索字符串应用于特定字段、创建日期、贡献ID或手动排序编号。默认情况下(如果省略字段),搜索查询应用于贡献名称及其内容字段(全文搜索)。此外,可以定义比较方式为等于、小于、大于或类似(eq、lt、lte、gt、gte、like)。小于和大于将自动将字符串转换为数字。
  • 排序:按ID、日期、名称或手动排序编号(排序)对结果进行排序,可以是升序或降序。也可以按模板字段的自定义ID进行排序。贡献还可以按章节或问题排序。请注意:您需要在id、date、name和sort之间进行选择。您可以添加一个自定义排序字段和章节/问题标志。例如:sort=date|chapter|issue|23将按日期、章节、问题排序,并按自定义字段23排序。
  • 限制和偏移:创建长度为[limit]元素的页面,从[偏移]开始。
  • 数据:向贡献的结果集中添加额外的字段信息。例如,您可能需要在结果集中已有的贡献标题字段来创建多语言菜单。或者,您可能需要多个贡献的幻灯片中的所有图片。
  • 填充:发送所有数据(true)。等同于 data=All|Available|Fields
  • 详细:发送关于数据集的完整信息。在大多数情况下,这会太多,只会减慢连接速度。
  • 模板:限制到特定的模板ID
  • 状态:包括草稿贡献、已发布贡献或两者都包括。永远不会显示开放的贡献。

示例

GET /api/contributions/1/14-5?query=New+York

Searches for all contributions within issue 1 and chapters 14 and 5 for the String "New York".

GET /api/contributions/1/14-5?query=New+York&filter=1|6:eq

Searches for all contributions within issue 1 and chapters 14 and 5 for the exact String "New York" within both fields with the template id 1 and 6.

GET /api/contributions/1/14-5?query=12&filter=sort:gtlimit=1

Searches for all contributions within issue 1 and chapters 14 and 5 with a sort value > 12 and a limitation to 1 item. This represents the next contribution in a manually sorted list, since the list is has a default sort order by 'sort, asc'.

GET /api/contributions/1/14-5?query=12&filter=sort:lt&sort:sort:desc&limit=1

Searches for all contributions within issue 1 and chapters 14 and 5 with a sort value < 12 and a limitation to 1 item, order descending. This represents the previous contribution in a manually sorted list.

GET /api/contributions/12/19?limit=10&offset=20

Returns 10 contributions of issue 12 and chapter 19 starting after contribution 20.

GET /api/contributions/5-6-7/1-2-3?sort=date:desc&data=Title|Subtitle

Returns all contributions of issue 5, 6 and 7 and chapter 1, 2 and 3 ordered by date, descending. Additionally, populates each contribution entry with the content of the fields Title and Subtitle.

GET /api/contributions/1/1?populate=true&verbose=true

Returns all contributions of chapter 1 and issue 1. Adds all fields to each contribution and additionally prints a lot of information to each field and contribution.

GET /api/contributions/1/1?template=12

Returns all contributions of chapter 1 and issue 1 based on the template 12

加载单个贡献

GET /api/contribution/:id?[options]

Options:

- verbose=true|false                   (default: false)

  • 详细:发送关于数据集的完整信息。在大多数情况下,这会太多,只会减慢连接速度。

示例

GET /api/contributions/12?verbose=true

Loads all available data from contribution with the id 12

结构化查询

GET /api/books|issues|chapters/[:id]?[options]

Options:

- data=[Fieldname|Fieldname|XX]        (default: empty)
- populate=true|false                  (default: false)
- verbose=true|false                   (default: false)

  • 数据:向贡献的结果集中添加额外的字段信息。例如,您可能需要在结果集中已有的贡献标题字段来创建多语言菜单。或者,您可能需要多个贡献的幻灯片中的所有图片。
  • 填充:发送所有数据(true)。等同于 data=All|Available|Fields
  • 详细:发送关于数据集的完整信息。在大多数情况下,这会太多,只会减慢连接速度。

示例

GET /api/books

Shows all books available for the current api key

GET /api/chapters/3

Shows all information about chapter 3

GET /api/issue/2?verbose=true&populate=true

Shows all information about issue 2. Additionally, raises the verbosity level and populates all data fields if a issue has backreferences to contributions.

路线图

在当前状态下,Rokfor能够存储和组织数据。在路线图上有将要实施的其他功能。

  • 批量功能:在特定章节的所有贡献上运行自定义操作。
  • 字段处理器:在存储数据时运行操作。
  • 导出器:将数据转换为其他格式(例如PDF)

支持

browserstack

Rokfor正在使用Browserstack来测试仪表板代码。