|
|
Line 26: |
Line 26: |
| *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. | | *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() | | *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:
| |
− | <pre><!--{"language":"<language-identifier>","icon":"<fontawesome-icon>","place":"<main|help|admin|user|none>","position":<position>}--></pre>
| |
− | Example:
| |
− | <pre><!--{"language":"search","icon":"fa-search","place":"main","position":40,"nologin":true}--></pre>
| |
− |
| |
− | Additionally is it possible to add the "nonlogin" paramter, to define that a page can be used without being logged in. See [http://fontawesome.io/icons/ 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:
| |
− | <pre>
| |
− | <?php
| |
− | if(!isset($G_MAIN)){
| |
− | die(json_encode(array("error" => "authentification failed")));
| |
− | }
| |
− | ?>
| |
− | </pre>
| |
− |
| |
− | === 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:
| |
− | <pre>
| |
− | <?php
| |
− | if(!isset($G_REQUEST)){
| |
− | die(json_encode(array("error" => "authentification failed")));
| |
− | }
| |
− | ?>
| |
− | </pre>
| |
− |
| |
− | === 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:
| |
− | <pre><!--{"language":"<language-identifier>","icon":"<fontawesome-icon>","position":<position>}--></pre>
| |
− | Example:
| |
− | <pre><!--{"language":"general","icon":"fa-wrench","position":10}--></pre>
| |
− |
| |
− | === 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:
| |
− | <pre>
| |
− | <?php
| |
− | if (!isset($G_MAIN) && !isset($G_REQUEST)) {
| |
− | die(json_encode(array("error" => "authentification failed")));
| |
− | }
| |
− | ?>
| |
− | </pre>
| |
− |
| |
− | == 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.
| |
| | | |
| [[Category:Addons]] | | [[Category:Addons]] |
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()