If you plan to modify the app to fit your needs, then you can do it by developing your own plugin. Thus, your modification will be compatible with app updates.

In this article, using the example of the “Hello, world!” plugin, I will explain how to create your own plugin in the app.

Prehistory

Initially, the project used the Symfony PHP Framework version 1.3. But over time, support for this version of the framework has ceased, and I decided not to use any framework in order not to depend on it, however, when writing a program, I created a similar architecture.

Libs

By default app using: jQueryjQuery UIBootstrap 3 and you can use the functions of these libraries.

Start of work

Download the “Hello world!” Plugin and unpack the archive into the /plugins folder
Open file /config/server.php and in option AVAILABLE_PLUGINS add “hello” in result you should have next code:
define('AVAILABLE_PLUGINS','ext,hello');

This variable lists all available plugins that will be automatically connected.

Link to the page

As a result, as a system administrator, you should see a link to the “Hello world!” Page in the left menu. Click on it and you will be taken to the page with the “Send Message” button.

The link looks like this:
[your site]index.php?module=hello/my_page/index
hello — Plugin name.
my_page — Page name.
index — Action name.

Program behavior

When you open “index.php?module=hello/my_page/index” then run next actions:

  1. plugins\hello\application_top.php (not required file)
    In this file you can include all libs
  2. plugins\hello\modules\my_page\module_top.php (not required file)
    This file is included in any actions on this page. Can be used for access checks, etc.
  3. plugins\hello\modules\my_page\actions\index.php (not required file)
    Action handler.
  4. plugins\hello\modules\my_page\views\index.php
    Content output.

The link in the app is formed using a special function url_for()
url_for('hello/my_page/index','action=send')
The functions for working with links are located in the file. includes\functions\urls.php

HTML form and popup

After clicking on the “Send message” button, a pop-up window will open with a simple field for entering text. An example of this form is located in the file plugins\hello\modules\my_page\views\form.php
Functions for working with html forms are located in the file includes\functions\html.php

MySQL Query

An example of a database query can be found in the file plugins\hello\classes\my_class.php
$user_info_query = db_query("select * from app_entity_1 where id='" . $app_user['id'] . "'");
if($user_info = db_fetch_array($user_info_query))

In this request, we select information about the current user.
Functions for working with the database are in the file includes\functions\database.php

$app_user - this is a session variable that stores information about the current user.. group_id — this is the current access group. For administrators group_id=0.

Menu

File plugins\hello\menu.php included automatically. In this file, you can specify a link to a page in the menu.
$app_plugin_menu['menu'][] = array('title'=>TEXT_PLUGIN_HELLO_WORLD,'url'=>url_for('hello/my_page/index'),'class'=>'fa-anchor');
menu — main manu
reports — menu “Reports”
account_menu — user menu in the upper right corner.

In the main menu, you can create nested menus, for example:
$s = array();
$s[] = array('title'=>TEXT_PLUGIN_HELLO_WORLD,'url'=>url_for('hello/my_page/index'),'class'=>'fa-anchor');
$app_plugin_menu['menu'][] = array('title'=>TEXT_PLUGIN_HELLO_WORLD,'url'=>url_for('hello/my_page/index'),'class'=>'fa-anchor','submenu'=>$s);

Public Page

To allow access to the page without logging in, create a public_modules.php file in the plugin folder and add the following code:

<?php
$allowed_modules[] = 'hello/my_page/index';

Then open the file plugins\hello\modules\my_page\actions\index.php and add the following code to the end of the file:

$app_layout = 'public_layout.php';

File public_layout.php located in the folder template\public_layout.php . Based on it, you can create your own template, for example my_public_layout.php , and use it in the $app_layout variable.