Creating PageCarton Plugins

 

Creating plugins with PageCarton is pretty easy. Unlike many other frameworks, PageCarton Plugins doesn't really need to be created with codes. In fact, PageCarton plugins are built using a Graphic Interface. Now, the built plugins may now contain widgets, templates, etc which are created with codes but the way PageCarton plugins work make it simply to create and use.

 

The concept of PageCarton plugins is to pack some components of a site in a way that it could be integrated into another website. So when a Plugin is built on Site A, it includes certain components - files, pages and other resources so that when such plugin is installed and activated on Site B, all the resources are available on site B just like they were originally on Site B. The moment the plugin is deactivated on Site B, the site go back to the way it was before the plugin was installed - without the components and functionalities introduced by the plugin built on Site A. In other words, a building a plugin is a way of creating a package which copies a functionality of a site into another.

 

Components of a plugin
 

Plugins could have a number of files and other resources which provides the functionalities the plugin introduces into the site it is installed on. There are a number of components on which a plugin can be built. Each of this component types introduces a diverse kind of functionality into a site. The components to build into a plugin must first be created on the site which the plugin is being built on. There are three basic categories of the components, they are:

 

 

  1. Widgets 

    Widgets are basically PHP classes of for some site-specific functions. Widgets can be built into plugins to export whatever functionalities such plugins are created for. Widgets bring specific functionalities to the site, depending on the kind of widget they are: Here are the kinds of widgets available:
     
    1. Standard Widgets

      Widgets are used to programmatically provides an output to the user.  As a matter of principle, whenever PageCarton want to output any content, a widget is used. PageCarton core comes with a lot of widgets bringing different functionalities, Plugin developers can develop their own widgets and include it in the plugin components.
       
    2. Settings

      Settings are special kinds of widgets in PageCarton which only provides forms and other interfaces to take settings data from the user. It directly links to the PageCarton Settings database to store and retrieves its data. When a settings is selected in building a plugin, the settings class will be used whenever the Plugin Settings is clicked on the site which has the plugin installed. 
       
    3. Databases

      Unlike most other frameworks and platforms of its kind. PageCarton has it's own database implementation using XML flat-file system. In PageCarton, databases are also a special kind of widgets - PHP classes which defines how a set of data is to be stored, retrieved and manipulated. PageCarton databases comes with ready APIs for CRUD systems, to insert, select, update and delete data from the tables. To include a database in the plugin, it must be selected under widgets. Including a database under widgets only include the database structure, including it under Database Tables allows the data to be included in the plugin.
       
  2. Documents

    Documents are files uploaded on the site, which can be retrieved directly using for example a URL: https://example.com/path/to/file.jpg. Documents can be built into plugins so that site that have them installed can also have those files on them. 
     
  3. Pages

    Plugins in PageCarton can also include pages. This allows for plugin developers to have pages defined in the plugin so that whenever the plugin is installed and activated on a new site, the defined pages becomes available immediately.
     
When creating a plugin, a developer will need to know the components required to make the plugin. While simple plugins may only contain one component, some complex plugins may combine some of the components to introduce a fantastic feature. 
 

Building a Plugin

 

  • Go to My Plugins

    My Plugins
     
  • Click on “Build New Plugins
     
    • Plugin Name could be the name of the plugin e.g. “Hello World”
    • Widgets - Select the widgets to include in the plugin
    • Settings - Select the settings widget to use as Plugin Settings
    • Databases - Which database table data to include in the plugins
    • Documents - What files should be included in the plugin.
    • Pages - What pages should be included in the plugin
    • Click “Continue” to submit
 
 

Installing the Plugin on Another Site

 

  • Go to Installed Plugins

    Installed Plugins

  • Click on “Upload New” to upload the plugin you have downloaded to your computer/device. The file should be a “tar.gz” archive.
  • Continue to Install and “Turn On” the plugin to enable the plugin
  • The components of the plugin should now be available on the site.
 

Uploading Plugin to PageCarton Plugin Repository
 

 

Examples

 

Content-based Plugin - Cookie notices plugin

 

A content based plugin is that which embeds/include a certain content into it's installed sites. We will consider a plugin to pop up cookie notices for GDPR and ePR compliance. For this plugin, we need two components

 

Creating Files

 

  1. Populate Site-wide widgets database

    PageCarton has a database which stores information of widgets saved in pages. The class of this database is "Ayoola_Object_PageWidget". It also has a special page "/sitewide-page-widgets" which stores widgets to display site-wide. 

    To populate this database we need to 
     
    1. External Javascript or CSS files - External files can be uploaded directly using the file manager. The URL may now be used in the content as a valid image, JS/CSS script

      File Manager
       
    2. Update "/sitewide-page-widgets" page to include all content to include in all the pages of the site.

      Edit /sitewide-page-widgets
      <!--sample HTML Text Content--> 
      <script src="/public/2019/01/01/cookieBubble.js"></script> <!--Include uploaded external javascript and other files --> 
      <script>
          (function ($) {
            $.cookieBubble();
           })(jQuery);
      </script>
      
      1. Click on "Widget Options" if you can't see widget containers (where you have "Insert Widget Here") on the page
      2. Click on "Insert Widget Here"
      3. Select "HTML Text"
      4. On the HTML Text box, switch the box to "Code View" 
      5. Paste the codes of the content to the code text area.
      6. Click Save on the lower left corner of the screen

        Click on the "Insert Widget Here" wherever you want the content to be, then select "HTML Text". When adding javascript files/code in "<script>" tags, it is best to include such in the last widget container (where you have "Insert Widget Here") on the page, it is best to switch the HTML Text widget to "Code View" mode when writing codes. The uploaded external files can be used here to display images, include CSS and JS in the page, etc.
         
Build Plugin
 
  • Go to My Plugins

    My Plugins
     
  • Click on “Build New Plugins
     
    • Plugin Name could be the name of the plugin e.g. “Cookie Compliance Plugin”
    • Plugin Widgets - Should be left blank since our plugin does not require a widget
    • Settings - Should be left blank since our plugin does not require settings
    • Databases - just one databases to include:
      • Ayoola_Object_PageWidget - The database for the page widgets
    • Documents - Select all the uploaded external files
    • Pages - Should be left blank since our plugin does not require a page
    • Click “Continue” to submit
    • Download plugin

 

...