Difference between revisions of "Addons"

From GExtension Wiki
Jump to navigation Jump to search
 
(20 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!'''
  
 
== Folder Structure ==
 
== Folder Structure ==
Line 5: 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:
 
+
  [[Addons:API|/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.
 
 
 
== Useful Functions ==
 
*string Lang(string $identifier): Returns the language string for the given identifier.
 
*string AP(__DIR__): Returns the path of your addon folder (e.g. "addons/[you-addon]/"), useful if you want to access the "assets" folder.
 
*string ValidateHTML(string $html): Validates a given HTML code, prevents XSS.
 
*void RequiredArguments(string $arg1, string $arg2, ...): Checks if the given strings are available as $_REQUEST paramters. If true, they will be transformed to global variables with the same name. If not, a die() with error message will be executed.
 
*void Error(string $reason, bool $debug): die() with format {"error":"$reason"}. Writes error in the gex_debug mysql table if $debug is set to true.
 
*void Success(): die() with format {"success":true}
 
*void Result(array $result): die() with the array in json format
 
*string Hostname(): Returns the url to the domain (e.g. https://www.community.com/).
 
*string GetCurrentLocation(): Returns the url to the GExtension directory (e.g. https://www.community.com/gmodweb/).
 
*array FromJson(string $json): Same as json_decode() but with save return
 
*string ToJson(array $array): Same as json_encode() but wuth save return
 
*void Redirect(string $url,  bool $delay = false): Initiates a JavaScript redirect, with 500ms delay if wanted
 
*bool StartsWith(string $haystack, string $needle)
 
*bool EndsWith(string $haystack, string $needle)
 
*string FormatDate(string $date): Formats a given date string (not unix).
 
*float FormatPrice(float $price): Formats a given price to two decimals
 
*void Debug(string $text): Writes a text into the gex_debug mysql table.
 
*void PermissionsError(bool $queue = false): Display a permissions error warning, queued for the next redirect if wanted.
 
*string SteamIDTo64(string $steamid32): Converts a 32 Bit SteamID into a 64 Bit SteamID.
 
*string SteamIDFrom64(string $steamid62): Converts a 64 Bit SteamID into a 32 Bit SteamID.
 
  
See assets/php/util.php and assets/php/classes/*.class.php for more functions.
+
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.
  
== Database ==
+
=== Extending Existing Pages ===
GExtension uses a MySQLi class which is documentated [https://github.com/joshcam/PHP-MySQLi-Database-Class here].
+
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.
 
 
The object is named $db and can be used by functions with:
 
$db = MysqliDb::getInstance();
 
or
 
global $db;
 
  
 
== 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.
 
 
== 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.