-
Notifications
You must be signed in to change notification settings - Fork 979
How to code a AVideo Platform plugin
Follow these steps to create a simple plugin for AVideo.
- Decide on a name for your plugin, e.g.,
SamplePlugin
.
-
Folder: Create a folder named
SamplePlugin
in the/plugin
directory on your AVideo site. -
File: Inside this folder, create a file named
SamplePlugin.php
. -
Class: In this file, create a class named
SamplePlugin
.
Important: The folder, file, and class names must all match exactly for the plugin to work.
- In your
SamplePlugin.php
file, define a new class that extends thePluginAbstract
class, like this:
class SamplePlugin extends PluginAbstract {
public function getDescription() {
return "This is a sample plugin";
}
public function getName() {
return "SamplePlugin";
}
public function getUUID() {
return "sample-plugin-44fb-aa33-51cba620d92e";
}
public function getEmptyDataObject() {
$obj = new stdClass();
$obj->option = false; // Add your own options here
return $obj;
}
}
- getDescription(): Describes what your plugin does.
- getName(): Returns the plugin name. This name should match your class name.
- getUUID(): Returns a unique ID for your plugin.
- getEmptyDataObject() (optional): Defines any settings or options for your plugin.
Your plugin folder might look like this:
/plugin/
│
└───SamplePlugin/
│ SamplePlugin.php
│ (optional) any other files your plugin needs
-
/plugin/
: The main directory where all AVideo plugins are stored. -
SamplePlugin/
: Folder where your plugin lives. -
SamplePlugin.php
: Main file for your plugin code.
To make things even easier, AVideo offers a tool to help you start your plugin. This tool generates a base code structure for a new plugin based on the SQL you provide. This base isn’t a complete plugin but gives you a starting point. You can find it by going to your AVideo plugin manager and clicking "Create a Plugin" at the top.
AVideo provides several event hooks that allow your plugin to execute custom actions when specific events occur. These events are triggered during various stages of platform operation.
To create event-based functionality, you need to add a function to your plugin class exactly as it is described in the [Plugin.abstract.php](https://github.com/WWBN/AVideo/blob/master/plugin/Plugin.abstract.php)
file. The event function must match the method signature in the abstract class, or it will not work.
You can view all available events in the Plugin.abstract.php
file here: Plugin.abstract.php.
-
afterNewVideo
- Triggered after any new video, audio, article, etc., is created.
- Example:
public function afterNewVideo($videos_id) { error_log("A new video was created with ID: {$videos_id}"); }
- See full example here
-
onUploadIsDone
- Triggered when a direct upload (e.g., MP4 or MP3) finishes.
- Example:
public function onUploadIsDone($videos_id) { error_log("Direct upload completed for video ID: {$videos_id}"); }
- See full example here
-
onEncoderNotifyIsDone
- Triggered when the encoder finishes its work.
- Example:
public function onEncoderNotifyIsDone($videos_id) { error_log("Encoding process completed for video ID: {$videos_id}"); }
- See full example here
Here are other events available for use in your plugin:
- onEncoderReceiveImage
- onReceiveFile
- onNewVideo
- onUpdateVideo
- onDeleteVideo
- onVideoLikeDislike
- onNewSubscription
- afterDonation
- afterNewComment
- afterNewResponse
Each event can be used by defining a function in your plugin that matches the exact signature in the Plugin.abstract.php
.
- Plugin Must Be Enabled: Event functions are only called when the plugin is enabled. If the plugin is disabled, the events will not trigger.
-
Function Signatures Must Match: Ensure the function signature matches exactly as defined in
Plugin.abstract.php
. -
Use Logs for Debugging: Use
error_log
or similar methods to debug and verify that your event functions are working as expected.