Skip to content

How to code a AVideo Platform plugin

Daniel Neto edited this page Jan 13, 2025 · 10 revisions

How to Create a New Plugin in AVideo: Step-by-Step Guide for Beginners

Follow these steps to create a simple plugin for AVideo.


1. Choose a Plugin Name

  • Decide on a name for your plugin, e.g., SamplePlugin.

2. Set Up the Directory, File, and Class

  • 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.


3. Start Your Plugin with Basic Code

  • In your SamplePlugin.php file, define a new class that extends the PluginAbstract 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.

4. Plugin File Structure

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.

5. Use the Plugin Generator Tool

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.

image


6. Events in Plugins

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.

How to Add Event Functions

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.


List of Available Events and Examples

  1. 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
  2. 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
  3. 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

Additional Events

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.


Key Points to Remember

  • 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.

Clone this wiki locally