Alex Trofimov 6 лет назад
Родитель
Сommit
a3d0b93e8e

+ 20 - 0
modules/boonex/api/classes/BxApiConfig.php

@@ -0,0 +1,20 @@
+<?php defined('BX_DOL') or die('hack attempt');
+/**
+ * Copyright (c) UNA, Inc - https://una.io
+ * MIT License - https://opensource.org/licenses/MIT
+ *
+ * @defgroup    API API to the UNA backend
+ * @ingroup     UnaModules
+ *
+ * @{
+ */
+
+class BxApiConfig extends BxDolModuleConfig
+{
+    function __construct($aModule)
+    {
+        parent::__construct($aModule);
+    }
+}
+
+/** @} */

+ 20 - 0
modules/boonex/api/classes/BxApiDb.php

@@ -0,0 +1,20 @@
+<?php defined('BX_DOL') or die('hack attempt');
+/**
+ * Copyright (c) UNA, Inc - https://una.io
+ * MIT License - https://opensource.org/licenses/MIT
+ *
+ * @defgroup    API API to the UNA backend
+ * @ingroup     UnaModules
+ *
+ * @{
+ */
+
+class BxApiDb extends BxDolModuleDb
+{
+    function __construct(&$oConfig)
+    {
+        parent::__construct($oConfig);
+    }
+}
+
+/** @} */

+ 120 - 0
modules/boonex/api/classes/BxApiModule.php

@@ -0,0 +1,120 @@
+<?php defined('BX_DOL') or die('hack attempt');
+/**
+ * Copyright (c) UNA, Inc - https://una.io
+ * MIT License - https://opensource.org/licenses/MIT
+ *
+ * @defgroup    API API to the UNA backend
+ * @ingroup     UnaModules
+ *
+ * @{
+ */
+
+class BxApiModule extends BxDolModule
+{
+    function __construct(&$aModule)
+    {
+        parent::__construct($aModule);
+    }
+
+    public function serviceGetPublicServices()
+    {
+        $a = parent::serviceGetPublicServices();
+        return array_merge($a, array (
+            'Test' => '',
+            'GetPage' => '',
+        ));
+    }
+
+    /**
+     * @page public_api API Public
+     * @section public_api_api_test /m/oauth2/com/test
+     * 
+     * Test method to check public API
+     * 
+     * **HTTP Method:** 
+     * `GET`
+     *
+     * **Request params:**
+     * n/a
+     *
+     * **Response (success):**
+     * @code
+     * {  
+     *    "result": "Test passed."
+     * }
+     * @endcode
+     */
+    public function serviceTest()
+    {
+        return array('result' => 'Test passed.');
+    }
+
+    /**
+     * @page public_api API Public
+     * @section public_api_api_get_page /m/oauth2/com/get_page?uri=about
+     * 
+     * Get page with cells and blocks as array
+     * 
+     * **HTTP Method:** 
+     * `POST`
+     *
+     * **Request params:**
+     * - `uri` - page URI
+     *
+     * **Response (success):**
+     * @code
+     * {  
+     *     "id": "123", // page ID
+     *     "layout": "5", // page layout, 5 is simplest page with one cell
+     *     "module": "system", // module which this page 
+     *     "title": "Test page", // page title
+     *     "type": 1, // page type, 1 is for default page with header and footer
+     *     "uri": "test", // page URI, which is part of page URL
+     *     "elements": {
+     *         "cell_1": [
+     *             {
+     *                 "content": "test content", // block content, it can be array as well
+     *                 "designbox_id": "11", // block design, such as padding, border, title
+     *                 "hidden_on": "", // not empty block need to be hidden on mobile, or desktop
+     *                 "id": "321",
+     *                 "module": "system", // module name this block is related to
+     *                 "order": "1", // block order
+     *                 "title": "Test block", // block title
+     *                 "type": "raw" // block type
+     *             }
+     *      ]
+     * }
+     * @endcode
+     *
+     * **Response (error):**
+     * @code
+     * {  
+     *    "error":"short error description here",
+     *    "error_description":"long error description here"
+     * }
+     * @endcode
+     */
+    public function serviceGetPage()
+    {
+        $sUri = bx_get('uri');
+        $oPage = BxDolPage::getObjectInstanceByURI($sUri);
+        if (!$oPage) {
+            return array(
+                'code' => 404,
+                'error' => 'Not Found',
+                'desc' => 'This page doesn\'t exist',
+            );
+        }
+        if (!$oPage->isVisiblePage()) {
+            return array(
+                'code' => 403,
+                'error' => 'Forbidden',
+                'desc' => 'This page requires special right to be viewed',
+            );
+        }
+
+        return $oPage->getPage ();
+    }
+}
+
+/** @} */

+ 20 - 0
modules/boonex/api/classes/BxApiTemplate.php

@@ -0,0 +1,20 @@
+<?php defined('BX_DOL') or die('hack attempt');
+/**
+ * Copyright (c) UNA, Inc - https://una.io
+ * MIT License - https://opensource.org/licenses/MIT
+ *
+ * @defgroup    API API to the UNA backend
+ * @ingroup     UnaModules
+ *
+ * @{
+ */
+
+class BxApiTemplate extends BxDolModuleTemplate
+{
+    function __construct(&$oConfig, &$oDb)
+    {
+        parent::__construct($oConfig, $oDb);
+    }
+}
+
+/** @} */

+ 70 - 0
modules/boonex/api/install/config.php

@@ -0,0 +1,70 @@
+<?php
+/**
+ * Copyright (c) UNA, Inc - https://una.io
+ * MIT License - https://opensource.org/licenses/MIT
+ *
+ * @defgroup    API API to the UNA backend
+ * @ingroup     UnaModules
+ *
+ * @{
+ */
+
+$aConfig = array(
+    /**
+     * Main Section.
+     */
+    'type' => BX_DOL_MODULE_TYPE_MODULE,
+    'name' => 'bx_api',
+    'title' => 'API',
+    'note' => 'API for backend.',
+    'version' => '11.0.0.DEV',
+    'vendor' => 'BoonEx',
+	'help_url' => 'http://feed.una.io/?section={module_name}',
+
+    'compatible_with' => array(
+        '11.0.x'
+    ),
+
+    /**
+     * 'home_dir' and 'home_uri' - should be unique. Don't use spaces in 'home_uri' and the other special chars.
+     */
+    'home_dir' => 'boonex/api/',
+    'home_uri' => 'api',
+
+    'db_prefix' => 'bx_api_',
+    'class_prefix' => 'BxApi',
+
+    /**
+     * Category for language keys.
+     */
+    'language_category' => 'API',
+
+    /**
+     * Installation/Uninstallation Section.
+     */
+    'install' => array(
+        'execute_sql' => 1,
+        'update_languages' => 1,
+    ),
+    'uninstall' => array (
+        'execute_sql' => 1,
+        'update_languages' => 1,
+    ),
+    'enable' => array(
+        'execute_sql' => 1,
+        'clear_db_cache' => 1,
+    ),
+    'disable' => array(
+        'execute_sql' => 1,
+        'clear_db_cache' => 1,
+    ),
+
+    /**
+     * Dependencies Section
+     */
+    'dependencies' => array(
+        'oauth2' => 'BoonEx OAuth2 Server Module'
+    ),
+);
+
+/** @} */

+ 20 - 0
modules/boonex/api/install/installer.php

@@ -0,0 +1,20 @@
+<?php defined('BX_DOL') or die('hack attempt');
+/**
+ * Copyright (c) UNA, Inc - https://una.io
+ * MIT License - https://opensource.org/licenses/MIT
+ *
+ * @defgroup    API API to the UNA backend
+ * @ingroup     UnaModules
+ *
+ * @{
+ */
+
+class BxApiInstaller extends BxDolStudioInstaller
+{
+    function __construct($aConfig)
+    {
+        parent::__construct($aConfig);
+    }
+}
+
+/** @} */

+ 5 - 0
modules/boonex/api/install/langs/en.xml

@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources name="en" flag="gb" title="English">
+	<string name="_sys_module_api"><![CDATA[API]]></string>
+	<string name="_bx_api"><![CDATA[API]]></string>
+</resources>

+ 0 - 0
modules/boonex/api/install/sql/disable.sql


+ 4 - 0
modules/boonex/api/install/sql/enable.sql

@@ -0,0 +1,4 @@
+
+
+
+

+ 14 - 0
modules/boonex/api/install/sql/install.sql

@@ -0,0 +1,14 @@
+
+-- Studio page and widget
+
+INSERT INTO `sys_std_pages`(`index`, `name`, `header`, `caption`, `icon`) VALUES
+(3, 'bx_api', '_bx_api', '_bx_api', 'bx_api@modules/boonex/api/|std-icon.svg');
+SET @iPageId = LAST_INSERT_ID();
+
+SET @iParentPageId = (SELECT `id` FROM `sys_std_pages` WHERE `name` = 'home');
+SET @iParentPageOrder = (SELECT MAX(`order`) FROM `sys_std_pages_widgets` WHERE `page_id` = @iParentPageId);
+INSERT INTO `sys_std_widgets` (`page_id`, `module`, `url`, `click`, `icon`, `caption`, `cnt_notices`, `cnt_actions`) VALUES
+(@iPageId, 'bx_api', '{url_studio}module.php?name=bx_api', '', 'bx_api@modules/boonex/api/|std-icon.svg', '_bx_api', '', 'a:4:{s:6:"module";s:6:"system";s:6:"method";s:11:"get_actions";s:6:"params";a:0:{}s:5:"class";s:18:"TemplStudioModules";}');
+INSERT INTO `sys_std_pages_widgets` (`page_id`, `widget_id`, `order`) VALUES
+(@iParentPageId, LAST_INSERT_ID(), IF(ISNULL(@iParentPageOrder), 1, @iParentPageOrder + 1));
+

+ 7 - 0
modules/boonex/api/install/sql/uninstall.sql

@@ -0,0 +1,7 @@
+
+-- Studio page and widget
+
+DELETE FROM `tp`, `tw`, `tpw`
+USING `sys_std_pages` AS `tp`, `sys_std_widgets` AS `tw`, `sys_std_pages_widgets` AS `tpw`
+WHERE `tp`.`id` = `tw`.`page_id` AND `tw`.`id` = `tpw`.`widget_id` AND `tp`.`name` = 'bx_api';
+

+ 20 - 0
modules/boonex/api/request.php

@@ -0,0 +1,20 @@
+<?php
+/**
+ * Copyright (c) UNA, Inc - https://una.io
+ * MIT License - https://opensource.org/licenses/MIT
+ *
+ * @defgroup    API API to the UNA backend
+ * @ingroup     UnaModules
+ *
+ * @{
+ */
+
+check_logged();
+
+if ( empty($aRequest) || empty($aRequest[0]) ) {
+    BxDolRequest::processAsFile($aModule, $aRequest);
+} else {
+    BxDolRequest::processAsAction($aModule, $aRequest);
+}
+
+/** @} */

+ 109 - 0
modules/boonex/api/template/images/icons/std-icon.svg

@@ -0,0 +1,109 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<svg
+   xmlns:dc="http://purl.org/dc/elements/1.1/"
+   xmlns:cc="http://creativecommons.org/ns#"
+   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+   xmlns:svg="http://www.w3.org/2000/svg"
+   xmlns="http://www.w3.org/2000/svg"
+   xmlns:xlink="http://www.w3.org/1999/xlink"
+   xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
+   xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
+   width="606px"
+   height="606px"
+   viewBox="0 0 606 606"
+   version="1.1"
+   id="svg22"
+   sodipodi:docname="std-icon.svg"
+   inkscape:version="0.92.2 5c3e80d, 2017-08-06">
+  <metadata
+     id="metadata26">
+    <rdf:RDF>
+      <cc:Work
+         rdf:about="">
+        <dc:format>image/svg+xml</dc:format>
+        <dc:type
+           rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
+      </cc:Work>
+    </rdf:RDF>
+  </metadata>
+  <sodipodi:namedview
+     pagecolor="#ffffff"
+     bordercolor="#666666"
+     borderopacity="1"
+     objecttolerance="10"
+     gridtolerance="10"
+     guidetolerance="10"
+     inkscape:pageopacity="0"
+     inkscape:pageshadow="2"
+     inkscape:window-width="1436"
+     inkscape:window-height="837"
+     id="namedview24"
+     showgrid="false"
+     inkscape:zoom="0.38943894"
+     inkscape:cx="-32.097458"
+     inkscape:cy="303"
+     inkscape:window-x="0"
+     inkscape:window-y="0"
+     inkscape:window-maximized="0"
+     inkscape:current-layer="svg22" />
+  <defs
+     id="defs8">
+    <linearGradient
+       x1="50%"
+       y1="0%"
+       x2="50%"
+       y2="100%"
+       id="linearGradient-1">
+      <stop
+         stop-color="#984f65"
+         stop-opacity="1"
+         offset="0%"
+         id="stop2" />
+      <stop
+         stop-color="#691c35"
+         stop-opacity="1"
+         offset="100%"
+         id="stop4" />
+    </linearGradient>
+    <path
+       d="M552.268958,552.268958 C600,504.537813 600,431.458333 600,300 C600,168.541667 600,95.4621875 552.268958,47.7310417 C504.537813,0 431.458333,0 300,0 C168.541667,0 95.4621875,0 47.7310417,47.7310417 C0,95.4621875 0,168.541667 0,300 C0,431.458333 0,504.537813 47.7310417,552.268958 C95.4621875,600 168.541667,600 300,600 C431.458333,600 504.537813,600 552.268958,552.268958 Z"
+       id="path-2" />
+  </defs>
+  <g
+     id="Page-1"
+     stroke="none"
+     stroke-width="1"
+     fill="none"
+     fill-rule="evenodd">
+    <g
+       id="una-connect"
+       transform="translate(3.000000, 3.000000)">
+      <g
+         id="Squircle2-Copy-6">
+        <g
+           id="Shape">
+          <use
+             fill="#FFFFFF"
+             xlink:href="#path-2"
+             id="use10" />
+          <use
+             stroke="#000000"
+             stroke-width="4.04"
+             fill="url(#linearGradient-1)"
+             xlink:href="#path-2"
+             id="use12" />
+        </g>
+      </g>
+      <g
+         id="g18">
+        <text
+           x="50%"
+           y="55%"
+           style="text-anchor: middle; fill: #ffffff; stroke: #000000; font-size: 100px;"
+           id="text16">
+                    API
+                </text>
+      </g>
+    </g>
+  </g>
+</svg>