Skip to content

reference:Plugin API

Aaron Junker edited this page Dec 19, 2020 · 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 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

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;
}]
Clone this wiki locally