Skip to content

reference:Plugin API

Aaron Junker edited this page Jan 20, 2021 · 8 revisions

This function gets implemented with Pb2.4Bfx0

(Pb2.4Bfx0)

The content system

A content type declares how something get stored and displayed in USOC. It exists out of a database and a file that declares how the content should be handled. This file should be included in the file plugins/plugins.php and the file itsself should be located in the plugins folder. In a manual the plugin should tell the user, how to create the database table needed for a plugin.

The plugin API

To add a plugin you must add a key with a other array to the $U->contentHandlers[] array.

Name of the key

The name is the name of the plugin.

Key Name

  • Type: string

Name of the database.

Key DisplayName

  • Type: string

Name of the plugin shown for the user. In the best case it's a translated string. (It should match to "Create/Upload new ..."(for example "Create/Upload new blog page")

Key Author

  • Type: string

Name of the author of the plugin

Key InfoURL

  • Type: string

URL to the info of the plugin

Key URL

  • Type: string

The URL handler for the content type. For example /blog/.

Key AddHandler

  • Type: function
  • Returns: boolean
function (int $Id , array $data) : bool

A function that get executed if a new content page get created. Should return false if the insertion process should get aborted.

Parameter $Id

The Id of the created page

Parameter $data

PageData array.

See: reference:PageData

Key DeleteHandler

  • Type: function
  • Returns: boolean
function (int $Id) : bool

A function that get executed if a content page get deleted. Should return false if deleting isn't allowed.

Parameter $Id

The Id the created page that should be deleted.

Key ShowHandler

  • Type: function
  • Returns: string
function (string $code , array $data) : string

A function that get executed if content page get shown to the user. Returns the HTML code that should be displayed.

Parameter $code

The code of the page that should be shown.

Parameter $data

PageData array.

See: reference:PageData

Key EditHandler

  • Type: function
  • Returns: boolean
function (int $Id , array $data) : bool

A function that get executed if content page get edited. Should return false if the the edit process should get aborted.

Parameter $Id

The Id of the page that should be edited.

Parameter $data

PageData array.

See: reference:PageData

Key CreateNewContent

  • Type: boolean Sets the permission for the admin user if he can create content.

Key ContentCreateHandler

  • Type: string Sets how creating a new content page in admin looks like. Two options are available:
  1. "Text": Open's text editor
  2. File path: Path to a file that gets included.

Key ContentEditHandler

  • Type: string Sets how creating a new content page in admin looks like. Two options are available:
  1. "Text": Open's text editor
  2. File path: Path to a file that gets included.

Key HTML

  • Type: boolean
  • Optional
  • Default: True If set to False the code don't get proceed through htmlspecialchars()

Key PackageVersion

  • Type: int Version of the Plugin API. Current version: 1

Example

$this->contentHandlers["Test"] = ["Name" => "Test", "URL" => "/test/", "AddHandler" => function ($Id, $data){
   if($data["Name"] == "Test"){
      return False;
   }
}, "DeleteHandler" => function ($Id){
   if($Id==0){
      return False;
   }
}, "ShowHandler" => function ($Code, $data){
   return $code;
}, "EditHandler" => function ($Id, $data){
   return true;
}, "CreateNewContent" => True, "ContentCreateHandler" => "../plugins/Test/new.php", "ContentEditHandler" => "../plugins/Test/edit.php"];
Clone this wiki locally