Update the example module

This commit is contained in:
Yağızhan committed 2021-10-08 21:47:18 +03:00
1 parent b56e36170a
commit bdee2c91db
5 files changed
+49 -82

No files matched your search

+3 -3
View File
@@ -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)
{
+14 -39
View File
@@ -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;
}
}
+16 -24
View File
@@ -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
We recommend hosting your extensions on a public [GitHub](https://github.com) repository.
@@ -8,22 +8,22 @@
<div class="widget">
<div class="head">
<h5>{% trans 'Example module title' %}</h5>
<h5>{% trans 'Example module for developers' %}</h5>
</div>
<div class="help">
<h3>{% trans 'This is an example extension content' %}</h3>
</div>
<div class="body">
<a href="{{ 'example'|alink }}">Example module index</a> <br/>
<a href="{{ 'extension/settings/example'|alink }}">Example settings page</a> <br/>
<a href="{{ 'example'|alink }}/test">Test link with static URL</a> <br/>
<a href="{{ 'example'|alink }}/user/1">Test link location with parameter 1</a> <br/>
<a href="{{ 'example'|alink }}/user/2">Test link location with parameter 2</a> <br/>
<a href="{{ 'example'|alink }}/user/3">Test link location with parameter 3</a> <br/>
<a href="{{ 'example'|alink }}/api">API example</a>
<a href="{{ 'example'|link }}" target="_blank">Client area link example</a>
<h3>{% trans 'This is an example extension' %}</h3>
</div>
<ul>
<li><a href="{{ 'example'|alink }}">Example module index</a></li>
<li><a href="{{ 'extension/settings/example'|alink }}">Example settings page</a></li>
<li><a href="{{ 'example'|alink }}/test">Test link with static URL</a></li>
<li><a href="{{ 'example'|alink }}/user/1">Test link location with parameter 1</a></li>
<li><a href="{{ 'example'|alink }}/user/2">Test link location with parameter 2</a></li>
<li><a href="{{ 'example'|alink }}/user/3">Test link location with parameter 3</a></li>
<li><a href="{{ 'example'|alink }}/api">API example</a></li>
<li><a href="{{ 'example'|link }}" target="_blank">Client area link example</a></li>
</ul>
{# Check if example parameters passed to template file #}
{% if youparamname %}
@@ -69,7 +69,7 @@
</div>
<div class="body list arrowBlue">
{{ guest.example_readme|markdown }}
{{ guest.example_readme|bbmd }}
</div>
</div>
@@ -15,7 +15,7 @@
<div class="widget">
<div class="head">
<h5 class="iCog">{% trans 'Example extension settings' %}</h5>
<h5 class="iCog">{% trans 'Example module settings' %}</h5>
</div>
{% set params = admin.extension_config_get({"ext":"mod_example"}) %}
@@ -37,9 +37,9 @@
</div>
<div class="rowElem">
<label>{% trans 'Public Parameter title' %}</label>
<label>{% trans 'Public parameter title' %}</label>
<div class="formRight">
<input type="text" name="public[param]" value="{{params.public.param}}" placeholder="{% trans 'This setting will be accessible by Guest API' %}"/>
<input type="text" name="public[param]" value="{{params.public.param}}" placeholder="{% trans 'This setting will be accessible by the Guest API' %}"/>
</div>
<div class="fix"></div>
</div>