Difference between revisions of "Addons"

From GExtension Wiki
Jump to navigation Jump to search
 
(15 intermediate revisions by the same user not shown)
Line 1: Line 1:
This article explais, how to create an addon for GExtension.
+
This article explais how to create an addon for GExtension.
  
 
See [[Code Structure]] for information about how GExtension is coded. '''IMPORTANT!'''
 
See [[Code Structure]] for information about how GExtension is coded. '''IMPORTANT!'''
Line 7: Line 7:
  
 
That's your main addon folder, where all files of your addon should be in. Additionally, you can create the following subfolders:
 
That's your main addon folder, where all files of your addon should be in. Additionally, you can create the following subfolders:
  /api
+
  [[Addons:API|/api]]
 
  /assets
 
  /assets
  /language
+
  [[Addons:Language|/language]]
  /main  
+
  [[Addons:Main|/main ]]
  /pages
+
  [[Addons:Page|/pages]]
  /request
+
  [[Addons:Request|/request]]
  /settings
+
  [[Addons:Setting|/settings]]
  /themes
+
  [[Addons:Theme|/themes]]
  
The meaning and function of those folders are explained below. Please try to imitate the folder structure of the GExtension core files.
+
The meaning and function of those folders are explained in extra articles, '''click on a subfolder to get there'''. 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 ==
 
== Addon Folder ==
 
Additionaly to the subfolders named above, the main addon folder can contain some more files:
 
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".
+
*'''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.
+
*'''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() that returns true/false. The process will create an file called named 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() that returns true/false.
 
 
== 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.
 
 
 
== Working In Progress ==
 
This artile will be extended soon.
 
  
 
[[Category:Addons]]
 
[[Category:Addons]]

Latest revision as of 11:45, 15 February 2020

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 in extra articles, click on a subfolder to get there. 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() that returns true/false. The process will create an file called named 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() that returns true/false.