Difference between revisions of "Addons"

From GExtension Wiki
Jump to navigation Jump to search
Line 109: Line 109:
 
All themes must be a PHP file ending with ".css.php". To process the file it's necessary to add the following line to the code:
 
All themes must be a PHP file ending with ".css.php". To process the file it's necessary to add the following line to the code:
 
  header('Content-type: text/css');
 
  header('Content-type: text/css');
The GET parameter "color" contains the current style color if you want to use it.
+
The GET parameter "color" contains the current style color ('#12345' will be '12345') if you want to use it.
  
 
== Working In Progress ==
 
== Working In Progress ==

Revision as of 09:10, 21 May 2017

This article explais, how to create an addon for GExtension.

See Code Structure for information about how GExtension is coded. IMPORTANT!

Folder Structure

The folder structure is similar to the one of Garry's Mod. First, you should create a folder: "addons/[your-addon]"

That's your main addon folder, where all files of your addon should be in. Additionally, you can create the following subfolders:

/api
/assets
/language
/main 
/pages
/request
/settings
/themes

The meaning and function of those folders are explained below. Please try to imitate the folder structure of the GExtension core files.

Extending Existing Pages

It's possible to extend existing files. If there are two files with the same name, for example "pages/search.php" and "addons/[your-addon]/pages/search.php", the original file will be included and the addon file afterwards. This can be used to extend for example pages or language files.

Addon Folder

Additionaly to the subfolders named above, the main addon folder can contain some more files:

  • addon.txt: Optional. Contains a json object with information about the addon, important at the moment are, "author" and "version".
  • install.php: Optional. If existent, gives the user the ability to run a one-time setup to complete the addon installation. Possible by navigating to Admin -> Settings -> Addons. Must contain a function Install(). The process will create a installed.txt in the main addon folder, containing the date of the installation and the steamid64 of the user who ran it.
  • uninstall.php: Optional. If existent, this script will be run when the addon gets uninstalled (by navigating to Admin -> Settings -> Addons). Should be used to remove any leftovers. Must contain a function Uninstall()

Section: pages

Name and first line

The pages section represents all pages a user could be able to visit. The filename should be <rawname>.php, where <rawname> is a lowercase identifiert. Pages for administrative purposes should begin with "admin_".

The first line of a page PHP file should always be the following:

<!--{"language":"<language-identifier>","icon":"<fontawesome-icon>","place":"<main|help|admin|user|none>","position":<position>}-->

Example:

<!--{"language":"search","icon":"fa-search","place":"main","position":40,"nologin":true}-->

Additionally is it possible to add the "nonlogin" paramter, to define that a page can be used without being logged in. See FontAwesome for icons.

Security Check

To verify that the file was included by GExtension, it's required to include the following code after the first line:

<?php 
	if(!isset($G_MAIN)){
		die(json_encode(array("error" => "authentification failed")));
	}
?>

Other

After creating a page, it is available under index.php?t=<rawname>. <rawname> is the name of the file without ".php".

You may want to allow a common page for all groups:

Permissions::AllowPagesForEveryone($rawname1, $rawname2, ...);

Check out existing pages for examples.


Section: request

General and Name

The request environment can be used to provide pages that can be called for example in AJAX requests. It's a clean site, but with all variables, classes and functions that GExtension has. The request file is then available under request.php?t=<rawname>.

If a request page is related to a page, the file should have the same name.

Security Check

To verify that the file was included by GExtension, it's required to include the following code at the beginning of the file:

<?php 
	if(!isset($G_REQUEST)){
		die(json_encode(array("error" => "authentification failed")));
	}
?>

No Login

By default, using a request page is only possible when logged in. To make a file public, you need to run the following function once (may put it in the install.php):

NoAuthFiles::Add('request', '<rawname>');


Section: settings

General and first line

Adding a page for the settings is similar to adding a normal page, but there is a difference in the first line. The first line must be:

<!--{"language":"<language-identifier>","icon":"<fontawesome-icon>","position":<position>}-->

Example:

<!--{"language":"general","icon":"fa-wrench","position":10}-->

Required Actions

When inventing a new settings page, it's required to add a permission and language identifier:

Permission:

Permissions::Add('settings_<rawname>');

Language:

$language['perm_desc_settings_<rawname>'] = 'Access to <rawname> settings';

Security Check

To verify that the file was included by GExtension, it's required to include the following code after the first line:

<?php 
    if (!isset($G_MAIN) && !isset($G_REQUEST)) {
        die(json_encode(array("error" => "authentification failed")));
    }
?>

Section: themes

General and Name

All themes must be a PHP file ending with ".css.php". To process the file it's necessary to add the following line to the code:

header('Content-type: text/css');

The GET parameter "color" contains the current style color ('#12345' will be '12345') if you want to use it.

Working In Progress

This artile will be extended soon.