{"id":13770691,"url":"https://github.com/editor-js/editorjs-php","last_synced_at":"2026-01-11T15:05:07.331Z","repository":{"id":44427987,"uuid":"82296669","full_name":"editor-js/editorjs-php","owner":"editor-js","description":"PHP backend for Editor.js","archived":false,"fork":false,"pushed_at":"2024-04-17T19:31:41.000Z","size":176,"stargazers_count":262,"open_issues_count":14,"forks_count":49,"subscribers_count":22,"default_branch":"master","last_synced_at":"2025-12-05T03:18:20.826Z","etag":null,"topics":["codex","codex-editor","htmlpurifier"],"latest_commit_sha":null,"homepage":"https://editorjs.io","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/editor-js.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-02-17T12:46:34.000Z","updated_at":"2025-11-02T03:49:31.000Z","dependencies_parsed_at":"2024-06-18T12:40:59.830Z","dependency_job_id":null,"html_url":"https://github.com/editor-js/editorjs-php","commit_stats":{"total_commits":106,"total_committers":11,"mean_commits":9.636363636363637,"dds":0.5188679245283019,"last_synced_commit":"9446738b6046ab05fe850dec2814dec535fe2e48"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/editor-js/editorjs-php","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/editor-js%2Feditorjs-php","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/editor-js%2Feditorjs-php/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/editor-js%2Feditorjs-php/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/editor-js%2Feditorjs-php/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/editor-js","download_url":"https://codeload.github.com/editor-js/editorjs-php/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/editor-js%2Feditorjs-php/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28309752,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-11T14:58:17.114Z","status":"ssl_error","status_checked_at":"2026-01-11T14:55:53.580Z","response_time":60,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["codex","codex-editor","htmlpurifier"],"created_at":"2024-08-03T17:00:40.681Z","updated_at":"2026-01-11T15:05:07.310Z","avatar_url":"https://github.com/editor-js.png","language":"PHP","funding_links":[],"categories":["Libraries"],"sub_categories":["PHP"],"readme":"# Editor.js PHP\n\nServer-side implementation sample for the Editor.js. It contains data validation, HTML sanitization and converts output from Editor.js to the Block objects.\n\n# Installation\n\nTo install lib use composer:\n```\ncomposer require codex-team/editor.js:dev-master\n```\n\n# Guide \n\nAdd this line at the top of your PHP script\n\n```php\nuse \\EditorJS\\EditorJS;\n```\n\nthis line allows you to get editors class that has the following method:\n\n`getBlocks` - return array of sanitized blocks\n\n# Basic usage\n\nYou can get data from editor and send as param to editor's server validator like\n\n```php\ntry {\n    // Initialize Editor backend and validate structure\n    $editor = new EditorJS( $data, $configuration );\n    \n    // Get sanitized blocks (according to the rules from configuration)\n    $blocks = $editor-\u003egetBlocks();\n    \n} catch (\\EditorJSException $e) {\n    // process exception\n}\n```\n\nEditor.js constructor has the following arguments:\n\n`$data` — JSON string with data from CodeX Editor frontend.\n\n`$configuration` — JSON string with CodeX Editor tools configuration (see an example in the following paragraph).\n\n# Configuration file\n\nYou can manually configure validation rules for different types of Editor.js tools (header, paragraph, list, quote and other).\nYou can also extend configuration with new tools.\n\nSample validation rule set:\n\n```$json\n{\n  \"tools\": {\n    \"header\": {\n      \"text\": {\n        \"type\": \"string\",\n        \"required\": true,\n        \"allowedTags\": \"b,i,a[href]\"\n      },\n      \"level\": {\n        \"type\": \"int\",\n        \"canBeOnly\": [2, 3, 4]\n      }\n    }\n  }\n}\n```\n\nWhere:\n\n`tools` — array of supported Editor.js tools.\n\n`header` — defines `header` tool settings.\n\n`text` and `level` — parameters in `header` tool structure.\n \n`text` is a **required** *string*, which will be sanitized except *b*, *i* and *a[href]* tags.  \n\n`level` is an **optional** *integer* that can be only 0, 1 or 2.\n\n`allowedTags` param should follow [HTMLPurifier](https://github.com/ezyang/htmlpurifier) format.\n\n#### There are three common parameters for every block:\n\n1. `type` (**required**) — type of the block\n\n|value|description|\n|---|---|\n|`string`|field with string value|\n|`int`/`integer`|field with integer value|\n|`bool`/`boolean`|field with boolean value|\n|`array`|field with nested fields|\n\n2. `allowedTags` (optional) — HTML tags in string that won't be removed\n \n |value|default|description|\n|---|---|---|\n|`empty`|yes|all tags will be removed|\n|`*`|no|all tags are allowed|\n\nOther values are allowed according to the  [HTMLPurifier](https://github.com/ezyang/htmlpurifier) format.\n\nExample:\n```\n\"paragraph\": {\n    \"text\": {\n        \"type\": \"string\",\n        \"allowedTags\": \"i,b,u,a[href]\"\n    }\n}\n```\n\n3. `canBeOnly` (optional) — define set of allowed values\n\nExample:\n```\n\"quote\": {\n      \"text\": {\n        \"type\": \"string\"\n      },\n      \"caption\": {\n        \"type\": \"string\"\n      },\n      \"alignment\": {\n        \"type\": \"string\",\n        \"canBeOnly\": [\"left\", \"center\"]\n      }\n    }\n```\n\n### Short settings syntax\n\nSome syntax sugar has been added.\n\nTool settings can be a `string`. It defines tool's type with default settings.\n```json\n\"header\": {\n  \"text\": \"string\",\n  \"level\": \"int\"\n}\n```\n\nIt evaluates to:\n```json\n\"header\": {\n  \"text\": {\n    \"type\": \"string\",\n    \"allowedTags\": \"\",\n    \"required\": true\n  },\n  \"level\": {\n    \"type\": \"int\",\n    \"allowedTags\": \"\",\n    \"required\": true\n  }\n}\n```\n\nTool settings can be an `array`. It defines a set of allowed values without sanitizing.\n```json\n\"quote\": {\n  \"alignment\": [\"left\", \"center\"],\n  \"caption\": \"string\"\n}\n```\n\nIt evaluates to:\n```json\n\"quote\": {\n  \"alignment\": {\n    \"type\": \"string\",\n    \"canBeOnly\": [\"left\", \"center\"]\n  },\n  \"caption\": {\n      \"type\": \"string\",\n      \"allowedTags\": \"\",\n      \"required\": true\n    }\n}\n```\n\nAnother configuration example: [/tests/samples/syntax-sugar.json](/tests/samples/syntax-sugar.json)\n\n### Nested tools\n\nTools can contain nested values. It is possible with the `array` type.\n\nLet the JSON input be the following:\n```\n{\n    \"blocks\": [\n        \"type\": list,\n        \"data\": {\n            \"items\": [\n                \"first\", \"second\", \"third\"\n            ],\n            \"style\": {\n                \"background-color\": \"red\",\n                \"font-color\": \"black\"\n            }\n        }\n    ]\n}\n```\n\nWe can define validation rules for this input in the config:\n```\n\"list\": {\n  \"items\": {\n    \"type\": \"array\",\n    \"data\": {\n      \"-\": {\n        \"type\": \"string\",\n        \"allowedTags\": \"i,b,u\"\n      }\n    }\n  },\n  \"style\": {\n      \"type\": \"array\",\n      \"data\": {\n        \"background-color\": {\n            \"type\": \"string\",\n            \"canBeOnly\": [\"red\", \"blue\", \"green\"]\n        },\n        \"font-color\": {\n            \"type\": \"string\",\n            \"canBeOnly\": [\"black\", \"white\"]\n        }\n      }\n  }\n}\n```\n\nwhere `data` is the container for values of the array and `-` is the special shortcut for values if the array is sequential.\n\n\n\nAnother configuration example: [/tests/samples/test-config.json](/tests/samples/test-config.json)\n\n# Exceptions\n\n### EditorJS class\n| Exception text                | Cause\n| ----------------------------- | ------------------------------------------------\n| JSON is empty                 | EditorJS initiated with empty `$json` argument\n| Wrong JSON format: `error`    | `json_decode` failed during `$json` processing\n| Input is null                 | `json_decode` returned null `$data` object\n| Input array is empty          | `$data` is an empty array\n| Field \\`blocks\\` is missing   | `$data` doesn't contain 'blocks' key\n| Blocks is not an array        | `$data['blocks']` is not an array\n| Block must be an Array        | one element in `$data['blocks']` is not an array\n\n### BlockHandler class\n| Exception text        | Cause\n| --------------------- | -----------------------------------------------\n| Tool \\`**TOOL_NAME**\\` not found in the configuration         | Configuration file doesn't contain **TOOL_NAME** in `tools{}` dictionary\n| Not found required param \\`**key**\\`                          | **key** tool param exists in configuration but doesn't exist in input data. *(Params are always required by default unless `required: false` is set)*\n| Found extra param \\`**key**\\`                                 | Param **key** exists in input data but doesn't defined in configuration\n| Option \\`**key**\\` with value \\`**value**\\` has invalid value. Check canBeOnly param. | Parameter must have one of the values from **canBeOnly** array in tool configuration\n| Option \\`**key**\\` with value \\`**value**\\` must be **TYPE**  | Param must have type which is defined in tool configuration *(string, integer, boolean)*\n| Unhandled type \\`**elementType**\\`                            | Param type in configuration is invalid\n\n### ConfigLoader class\n| Exception text                | Cause\n| ----------------------------- | ------------------------------------------------\n| Configuration data is empty                       | EditorJS initiated with empty `$configuration` argument\n| Tools not found in configuration                  | Configuration file doesn't contain `tools` key\n| Duplicate tool \\`**toolName**\\` in configuration  | Configuration file has different tools with the same name\n\n# Make Tools\n\nIf you connect a new Tool on the frontend-side, then you should create a configuration rule for that Tool to validate it on server-side.\n\n## Repository \n\u003ca href=\"https://github.com/codex-editor/editorjs-php/\"\u003ehttps://github.com/codex-editor/editorjs-php/\u003c/a\u003e\n\n\n## About CodeX\nWe are small team of Web-developing fans consisting of IFMO students and graduates located in St. Petersburg, Russia. \nFeel free to give us a feedback on \u003ca href=\"mailto::team@ifmo.su\"\u003eteam@ifmo.su\u003c/a\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feditor-js%2Feditorjs-php","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feditor-js%2Feditorjs-php","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feditor-js%2Feditorjs-php/lists"}