diff --git a/src/bb-modules/Example/Api/Client.php b/src/bb-modules/Example/Api/Client.php index e2fd9daa0..ace2d840d 100644 --- a/src/bb-modules/Example/Api/Client.php +++ b/src/bb-modules/Example/Api/Client.php @@ -11,8 +11,8 @@ */ /** - * All public methods in this class are exposed to client using API. - * Always think what kind of information you are exposing. + * All public methods in this class are exposed to the client using API. + * Always think about the information you are exposing. */ namespace Box\Mod\Example\Api; @@ -25,7 +25,7 @@ class Client extends \Api_Abstract * This method will collect data from all APIs and merge * into one result. * - * Be careful not to expose sensitive data from Admin API. + * Be careful not to expose sensitive data from the Admin API. */ public function get_info($data) { diff --git a/src/bb-modules/Example/Api/Guest.php b/src/bb-modules/Example/Api/Guest.php index 714849115..5d0e9fd65 100644 --- a/src/bb-modules/Example/Api/Guest.php +++ b/src/bb-modules/Example/Api/Guest.php @@ -19,59 +19,34 @@ * */ + // Change "Example" with your module's name namespace Box\Mod\Example\Api; class Guest extends \Api_Abstract { /** - * Get readme.md file contents + * Return extension README. + * + * @return string */ public function readme($data) { + // $this->di['tools'] returns tools from /bb-library/Box/Tools.php + // We'll be using the file_get_contents from our tools to fetch the full content of the README file + // Our example admin and client area pages will use this function to fetch the README data + // Then, we'll tell Twig to parse and display the markdown output + $readme = $this->di['tools']->file_get_contents(BB_PATH_MODS . '/Example/README.md'); return $readme; } /** - * Get Top Songs from iTunes Store - * @param int $limit - define songs limit + * Return a random number between 1 and 100 + * + * @return int */ - public function top_songs($data) + public function random_number() { - $limit = $this->di['array_get']($data, 'limit', 10); - $feed = "http://ax.itunes.apple.com/WebObjects/MZStoreServices.woa/ws/RSS/topsongs/limit=$limit/xml"; - $top_songs = $this->di['tools']->file_get_contents($feed); - $xml = simplexml_load_string($top_songs); - $array = array(); - $this->_convertXmlObjToArr($xml, $array); - return $array; + return random_int(1, 100); } - - private function _convertXmlObjToArr($obj, &$arr) - { - $children = $obj->children(); - foreach ($children as $elementName => $node) - { - $nextIdx = count($arr); - $arr[$nextIdx] = array(); - $arr[$nextIdx]['_name'] = strtolower((string)$elementName); - $arr[$nextIdx]['_attributes'] = array(); - $attributes = $node->attributes(); - foreach ($attributes as $attributeName => $attributeValue) - { - $attribName = strtolower(trim((string)$attributeName)); - $attribVal = trim((string)$attributeValue); - $arr[$nextIdx]['_attributes'][$attribName] = $attribVal; - } - $text = (string)$node; - $text = trim($text); - if (strlen($text) > 0) - { - $arr[$nextIdx]['_text'] = $text; - } - $arr[$nextIdx]['_children'] = array(); - $this->_convertXmlObjToArr($node, $arr[$nextIdx]['_children']); - } - return; - } } \ No newline at end of file diff --git a/src/bb-modules/Example/README.md b/src/bb-modules/Example/README.md index 2606574df..b47a4c0aa 100644 --- a/src/bb-modules/Example/README.md +++ b/src/bb-modules/Example/README.md @@ -1,38 +1,30 @@ -# Example extension readme file +# Example module README file -Module purpose is to provide a starting point for developer to get started -creating his own BoxBilling module. +This module provides a starting point for the developers on creating their BoxBilling module. -Explore the files and comments in the code to better understand the structure -of module. Contact Development helpdesk at www.boxbilling.com if you need more -information. +Explore the files and comments in the code to understand the structure of the module better. See the social links on [our website](https://boxbilling.org) if you need further information. -In general modules are used to extend BoxBilling basic functionality. +In general, we use modules to extend the functionality of BoxBilling. -All modules can access other modules via API or database +All modules can communicate with the other modules using their API endpoints. -More about extensions at https://extensions.boxbilling.com/article/getting-started - -# BoxBilling module requirements +# Technical requirements about modules ## Required - -* Folder must contain **manifest.json** file to describe itself +* API folder has to contain a **manifest.json** file to describe itself. The module engine will look for this file to find information about your extension. ## Optional - * **README.md** - file for installation and getting started instructions -* Folder **html_admin** - for admin area templates, to store custom *.phtml files -* Folder **html_client** - for client area templates, to store custom *.phtml files +* **html_admin** folder - for admin area templates, to store custom *.phtml files +* **html_client** folder - for client area templates, to store custom *.phtml files ###### Controller folder -* **Admin.php** - if module has install/uninstall instructions or - admin area interface -* **Client.php** - if module has client area interface +* **Admin.php** - if the module has install/uninstall instructions or + an admin area interface +* **Client.php** - if the module has a client area interface ###### Api folder -* **Admin.php** - file for Admin API -* **Client.php** - file for Client API -* **Guest.php** - file for Guest API +* **Admin.php** - Administrator API, only authorized administrators will be able to call these endpoints. +* **Client.php** - Client API, only logged in clients will be able to call these endpoints. +* **Guest.php** - Guest API, no authorization is needed for these endpoints. Don't provide confidential data over these endpoints. Anybody over the internet will be able to access these information, including bots. # Tips - -We recommend to host your extensions on public [github.com](http://github.com) repository \ No newline at end of file +We recommend hosting your extensions on a public [GitHub](https://github.com) repository. \ No newline at end of file diff --git a/src/bb-modules/Example/html_admin/mod_example_index.phtml b/src/bb-modules/Example/html_admin/mod_example_index.phtml index a84fe8f91..7fd1789ae 100644 --- a/src/bb-modules/Example/html_admin/mod_example_index.phtml +++ b/src/bb-modules/Example/html_admin/mod_example_index.phtml @@ -8,22 +8,22 @@
-
{% trans 'Example module title' %}
+
{% trans 'Example module for developers' %}
-

{% trans 'This is an example extension content' %}

-
-
- Example module index
- Example settings page
- Test link with static URL
- Test link location with parameter 1
- Test link location with parameter 2
- Test link location with parameter 3
- API example - Client area link example +

{% trans 'This is an example extension' %}

+ {# Check if example parameters passed to template file #} {% if youparamname %} @@ -69,7 +69,7 @@
- {{ guest.example_readme|markdown }} + {{ guest.example_readme|bbmd }}
diff --git a/src/bb-modules/Example/html_admin/mod_example_settings.phtml b/src/bb-modules/Example/html_admin/mod_example_settings.phtml index 12dd2dd39..5558f93ab 100644 --- a/src/bb-modules/Example/html_admin/mod_example_settings.phtml +++ b/src/bb-modules/Example/html_admin/mod_example_settings.phtml @@ -15,7 +15,7 @@
-
{% trans 'Example extension settings' %}
+
{% trans 'Example module settings' %}
{% set params = admin.extension_config_get({"ext":"mod_example"}) %} @@ -37,9 +37,9 @@
- +
- +