Procházet zdrojové kódy

Ticket #5438 - GitHub integration.

AntonLV před 6 měsíci
rodič
revize
886f68092b

+ 44 - 0
modules/boonex/github/classes/BxGitHubConfig.php

@@ -0,0 +1,44 @@
+<?php defined('BX_DOL') or die('hack attempt');
+/**
+ * Copyright (c) UNA, Inc - https://una.io
+ * MIT License - https://opensource.org/licenses/MIT
+ *
+ * @defgroup    GitHub GitHub
+ * @ingroup     UnaModules
+ *
+ * @{
+ */
+
+class BxGitHubConfig extends BxBaseModGeneralConfig
+{
+    protected $_oDb;
+
+    public function __construct($aModule)
+    {
+        parent::__construct($aModule);
+
+        $this->CNF = array (
+            // database tables
+            'TABLE_SETTINGS' => $aModule['db_prefix'] . 'settings',
+
+            // database fields
+            'FIELD_' => '',
+
+            // some params
+            'PARAM_' => 'bx_github_',
+
+            // objects
+            'OBJECT_FORM_SETTINGS' => 'bx_github_form_settings',
+            'OBJECT_FORM_SETTINGS_DISPLAY_EDIT' => 'bx_github_form_settings_edit',
+        );
+    }
+
+    public function init(&$oDb)
+    {
+        $this->_oDb = &$oDb;
+
+        //NOTE: Some settings can be inited here.
+    }
+}
+
+/** @} */

+ 58 - 0
modules/boonex/github/classes/BxGitHubDb.php

@@ -0,0 +1,58 @@
+<?php defined('BX_DOL') or die('hack attempt');
+/**
+ * Copyright (c) UNA, Inc - https://una.io
+ * MIT License - https://opensource.org/licenses/MIT
+ *
+ * @defgroup    GitHub GitHub
+ * @ingroup     UnaModules
+ *
+ * @{
+ */
+
+class BxGitHubDb extends BxDolModuleDb
+{
+    protected $_oConfig;
+
+    public function __construct(&$oConfig)
+    {
+        parent::__construct($oConfig);
+
+        $this->_oConfig = $oConfig;
+    }
+
+    public function getSettings($aParams = [])
+    {
+        $CNF = &$this->_oConfig->CNF;
+
+        $aMethod = ['name' => 'getAll', 'params' => [0 => 'query']];
+
+        $sSelectClause = "*";
+        $sWhereClause = $sOrderByClause = "";
+
+        switch($aParams['sample']) {
+            case 'id':
+                $aMethod['name'] = 'getRow';
+                $aMethod['params'][1] = [
+                    'id' => $aParams['id']
+                ];
+
+                $sWhereClause .= " AND `id`=:id";
+                break;
+
+            case 'profile_id':
+                $aMethod['name'] = 'getRow';
+                $aMethod['params'][1] = [
+                    'profile_id' => $aParams['profile_id']
+                ];
+
+                $sWhereClause .= " AND `profile_id`=:profile_id";
+                break;
+        }
+
+        $aMethod['params'][0] = "SELECT " . $sSelectClause . " FROM `" . $CNF['TABLE_SETTINGS'] . "` WHERE 1 " . $sWhereClause;
+
+        return call_user_func_array([$this, $aMethod['name']], $aMethod['params']);
+    }
+}
+
+/** @} */

+ 26 - 0
modules/boonex/github/classes/BxGitHubFormSettings.php

@@ -0,0 +1,26 @@
+<?php defined('BX_DOL') or die('hack attempt');
+/**
+ * Copyright (c) UNA, Inc - https://una.io
+ * MIT License - https://opensource.org/licenses/MIT
+ *
+ * @defgroup    Payment Payment
+ * @ingroup     UnaModules
+ *
+ * @{
+ */
+
+class BxGitHubFormSettings extends BxTemplFormView
+{
+    protected $_sModule;
+    protected $_oModule;
+
+    function __construct($aInfo, $oTemplate = false)
+    {
+        parent::__construct($aInfo, $oTemplate);
+
+        $this->_sModule = 'bx_github';
+        $this->_oModule = BxDolModule::getInstance($this->_sModule);
+    }
+}
+
+/** @} */

+ 63 - 0
modules/boonex/github/classes/BxGitHubModule.php

@@ -0,0 +1,63 @@
+<?php defined('BX_DOL') or die('hack attempt');
+/**
+ * Copyright (c) UNA, Inc - https://una.io
+ * MIT License - https://opensource.org/licenses/MIT
+ *
+ * @defgroup    GitHub GitHub
+ * @ingroup     UnaModules
+ *
+ * @{
+ */
+
+/*
+ * 
+ * Creating a fine-grained personal access token
+ * https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens#creating-a-fine-grained-personal-access-token
+ * 
+ * Creating a personal access token (classic)
+ * https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens#creating-a-personal-access-token-classic
+ * 
+ * Web application flow
+ * https://docs.github.com/en/apps/oauth-apps/building-oauth-apps/authorizing-oauth-apps#web-application-flow
+ * 
+ */
+
+class BxGitHubModule extends BxBaseModGeneralModule
+{
+    function __construct($aModule)
+    {
+        parent::__construct($aModule);
+
+        $this->_oConfig->init($this->_oDb);
+    }
+
+    /**
+     * ACTION METHODS
+     */
+
+    /**
+     * SERVICE METHODS
+     */
+    public function serviceGetBlockSettings($iProfileId = 0)
+    {
+        $iLoggedId = bx_get_logged_profile_id();
+        if(!$iProfileId || ($iProfileId != $iLoggedId && !$this->_isAdministrator()))
+            $iProfileId = $iLoggedId;
+
+        if(!$iProfileId)
+            return MsgBox(_t('_sys_txt_access_denied'));
+
+        return $this->_oTemplate->getBlockSettings($iProfileId);
+    }
+
+    public function serviceAddIssue($iProfileId, $sRepository, $sTitle, $sText = '')
+    {
+        //TODO: Create Issue in Repository.
+    }
+
+    /*
+     * COMMON METHODS
+     */
+}
+
+/** @} */

+ 38 - 0
modules/boonex/github/classes/BxGitHubPageSettings.php

@@ -0,0 +1,38 @@
+<?php defined('BX_DOL') or die('hack attempt');
+/**
+ * Copyright (c) UNA, Inc - https://una.io
+ * MIT License - https://opensource.org/licenses/MIT
+ *
+ * @defgroup    GitHub GitHub
+ * @ingroup     UnaModules
+ *
+ * @{
+ */
+
+class BxGitHubPageSettings extends BxTemplPage
+{
+    protected $_sModule;
+    protected $_oModule;
+
+    public function __construct($aObject, $oTemplate = false)
+    {
+        $this->_sModule = 'bx_github';
+        $this->_oModule = BxDolModule::getInstance($this->_sModule);
+
+        parent::__construct($aObject, $oTemplate);
+
+        $oMenuSubmenu = BxDolMenu::getObjectInstance('sys_site_submenu');
+        if($oMenuSubmenu) {
+            $sSubmenu = 'sys_account_settings_submenu';
+            $oMenuSubmenu->setObjectSubmenu($sSubmenu, [
+                'title' => _t('_sys_menu_item_title_account_settings'), 
+                'link' => '', 
+                'icon' => ''
+            ]);
+
+            BxDolMenu::getObjectInstance($sSubmenu)->setSelected($this->_sModule, 'github-settings');
+        }
+    }
+}
+
+/** @} */

+ 47 - 0
modules/boonex/github/classes/BxGitHubTemplate.php

@@ -0,0 +1,47 @@
+<?php defined('BX_DOL') or die('hack attempt');
+/**
+ * Copyright (c) UNA, Inc - https://una.io
+ * MIT License - https://opensource.org/licenses/MIT
+ *
+ * @defgroup    GitHub GitHub
+ * @ingroup     UnaModules
+ *
+ * @{
+ */
+
+class BxGitHubTemplate extends BxDolModuleTemplate
+{
+    public function __construct(&$oConfig, &$oDb)
+    {
+        parent::__construct($oConfig, $oDb);
+    }
+
+    public function getBlockSettings($iProfileId)
+    {
+        $CNF = &$this->_oConfig->CNF;
+
+        $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_SETTINGS'], $CNF['OBJECT_FORM_SETTINGS_DISPLAY_EDIT'], $this);
+        if(!$oForm)
+            return MsgBox(_t('_sys_txt_error_occured'));
+
+        $aSettings = $this->_oDb->getSettings(['sample' => 'profile_id', 'profile_id' => $iProfileId]);
+        $bSettings = !empty($aSettings) && is_array($aSettings);
+
+        $sResultTimer = 0;
+        $sResultMessage = '';
+
+        $oForm->initChecker($aSettings);
+        if($oForm->isSubmittedAndValid()) {
+            if((!$bSettings && (int)$oForm->insert(['profile_id' => $iProfileId]) > 0) || ($bSettings && $oForm->update($aSettings['id']) !== false)) {
+                $sResultTimer = 3;
+                $sResultMessage = '_bx_github_msg_save_settings';
+            }
+            else
+                $sResultMessage = '_bx_github_err_save_settings';
+        }
+
+        return (!empty($sResultMessage) ? MsgBox(_t($sResultMessage), $sResultTimer) : '') . $oForm->getCode();
+    }
+}
+
+/** @} */

+ 71 - 0
modules/boonex/github/install/config.php

@@ -0,0 +1,71 @@
+<?php
+/**
+ * Copyright (c) UNA, Inc - https://una.io
+ * MIT License - https://opensource.org/licenses/MIT
+ *
+ * @defgroup    GitHub GitHub
+ * @ingroup     UnaModules
+ *
+ * @{
+ */
+
+$aConfig = array(
+    /**
+     * Main Section.
+     */
+    'type' => BX_DOL_MODULE_TYPE_MODULE,
+    'name' => 'bx_github',
+    'title' => 'GitHub',
+    'note' => 'GitHub integration module.',
+    'version' => '15.0.0',
+    'vendor' => 'UNA INC',
+    'help_url' => 'http://feed.una.io/?section={module_name}',
+
+    'compatible_with' => array(
+        '15.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/github/',
+    'home_uri' => 'github',
+
+    'db_prefix' => 'bx_github_',
+    'class_prefix' => 'BxGitHub',
+
+    /**
+     * Category for language keys.
+     */
+    'language_category' => 'GitHub',
+
+    /**
+     * Installation/Uninstallation Section.
+     */
+    'install' => array(
+        'execute_sql' => 1,
+        'update_languages' => 1,
+        'clear_db_cache' => 1,
+    ),
+    'uninstall' => array (
+        'execute_sql' => 1,
+        'update_languages' => 1,
+        'clear_db_cache' => 1,
+    ),
+    'enable' => array(
+        'execute_sql' => 1,
+        'clear_db_cache' => 1,
+    ),
+    'disable' => array (
+        'execute_sql' => 1,
+        'clear_db_cache' => 1,
+    ),
+
+    /**
+     * Dependencies Section
+     */
+    'dependencies' => array(),
+
+);
+
+/** @} */

+ 20 - 0
modules/boonex/github/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    GitHub GitHub
+ * @ingroup     UnaModules
+ *
+ * @{
+ */
+
+class BxGitHubInstaller extends BxDolStudioInstaller
+{
+    function __construct($aConfig)
+    {
+        parent::__construct($aConfig);
+    }
+}
+
+/** @} */

+ 25 - 0
modules/boonex/github/install/langs/en.xml

@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources name="en" flag="gb" title="English">
+    <string name="_bx_github"><![CDATA[GitHub]]></string>
+
+    <string name="_bx_github_option_"><![CDATA[]]></string>
+
+    <string name="_bx_github_form_settings"><![CDATA[Settings]]></string>
+    <string name="_bx_github_form_settings_display_edit"><![CDATA[Edit Settings]]></string>
+    <string name="_bx_github_form_settings_input_sys_profile_id"><![CDATA[Profile ID]]></string>
+    <string name="_bx_github_form_settings_input_sys_pat"><![CDATA[Access token]]></string>
+    <string name="_bx_github_form_settings_input_pat"><![CDATA[Access token]]></string>
+    <string name="_bx_github_form_settings_input_sys_do_submit"><![CDATA[Submit]]></string>
+    <string name="_bx_github_form_settings_input_do_submit"><![CDATA[Submit]]></string>
+
+    <string name="_bx_github_page_title_sys_settings"><![CDATA[Settings]]></string>
+    <string name="_bx_github_page_title_settings"><![CDATA[GitHub Settings]]></string>
+    <string name="_bx_github_page_block_title_settings"><![CDATA[GitHub Settings]]></string>
+
+    <string name="_bx_github_menu_item_title_system_settings"><![CDATA[GitHub Settings]]></string>
+    <string name="_bx_github_menu_item_title_settings"><![CDATA[GitHub]]></string>
+
+    <string name="_bx_github_msg_save_settings"><![CDATA[Settings were successfully saved.]]></string>
+    <string name="_bx_github_err_save_settings"><![CDATA[Cannot save settings.]]></string>
+    <string name="_bx_github_txt_"><![CDATA[]]></string>
+</resources>

+ 16 - 0
modules/boonex/github/install/sql/disable.sql

@@ -0,0 +1,16 @@
+SET @sName = 'bx_github';
+
+
+-- SETTINGS
+DELETE FROM `tot`, `toc`, `to` USING `sys_options_types` AS `tot` LEFT JOIN `sys_options_categories` AS `toc` ON `tot`.`id`=`toc`.`type_id` LEFT JOIN `sys_options` AS `to` ON `toc`.`id`=`to`.`category_id` WHERE `tot`.`name`=@sName;
+
+
+-- PAGES & BLOCKS
+DELETE FROM `sys_objects_page` WHERE `module` = @sName;
+DELETE FROM `sys_pages_blocks` WHERE `module` = @sName OR `object` IN ('bx_github_settings');
+
+
+-- MENU
+DELETE FROM `sys_objects_menu` WHERE `module` = @sName;
+DELETE FROM `sys_menu_sets` WHERE `module` = @sName;
+DELETE FROM `sys_menu_items` WHERE `module` = @sName; -- OR `set_name` IN('');

+ 34 - 0
modules/boonex/github/install/sql/enable.sql

@@ -0,0 +1,34 @@
+SET @sName = 'bx_github';
+
+
+-- SETTINGS
+
+-- SET @iTypeOrder = (SELECT MAX(`order`) FROM `sys_options_types` WHERE `group` = 'modules');
+-- INSERT INTO `sys_options_types`(`group`, `name`, `caption`, `icon`, `order`) VALUES 
+-- ('modules', @sName, '_bx_github', 'bx_github@modules/boonex/github/|std-icon.svg', IF(ISNULL(@iTypeOrder), 1, @iTypeOrder + 1));
+-- SET @iTypeId = LAST_INSERT_ID();
+
+-- INSERT INTO `sys_options_categories` (`type_id`, `name`, `caption`, `order`)
+-- VALUES (@iTypeId, @sName, '_bx_github', 10);
+-- SET @iCategId = LAST_INSERT_ID();
+
+-- INSERT INTO `sys_options` (`name`, `value`, `category_id`, `caption`, `type`, `extra`, `check`, `check_error`, `order`) VALUES
+-- ('bx_github_badge_persons', '', @iCategId, '_bx_github_option_badge_persons', 'select', 'a:3:{s:6:"module";s:9:"bx_github";s:6:"method";s:17:"get_options_badge";s:6:"params";a:1:{i:0;s:10:"bx_persons";}}', '', '', 10);
+
+
+-- PAGES
+
+-- PAGE: settings
+INSERT INTO `sys_objects_page`(`object`, `title_system`, `title`, `module`, `layout_id`, `visible_for_levels`, `visible_for_levels_editable`, `uri`, `url`, `meta_description`, `meta_keywords`, `meta_robots`, `cache_lifetime`, `cache_editable`, `deletable`, `override_class_name`, `override_class_file`) VALUES
+('bx_github_settings', '_bx_github_page_title_sys_settings', '_bx_github_page_title_settings', @sName, 5, 2147483647, 1, 'github-settings', 'page.php?i=github-settings', '', '', '', 0, 1, 0, 'BxGitHubPageSettings', 'modules/boonex/github/classes/BxGitHubPageSettings.php');
+
+INSERT INTO `sys_pages_blocks` (`object`, `cell_id`, `module`, `title`, `designbox_id`, `visible_for_levels`, `type`, `content`, `deletable`, `copyable`, `order`) VALUES
+('bx_github_settings', 1, @sName, '_bx_github_page_block_title_settings', 11, 2147483647, 'service', 'a:2:{s:6:"module";s:9:"bx_github";s:6:"method";s:18:"get_block_settings";}', 0, 0, 1);
+
+
+-- MENUS
+
+-- MENU: account settings menu
+SET @iMoAccountSettings = (SELECT IFNULL(MAX(`order`), 0) FROM `sys_menu_items` WHERE `set_name`='sys_account_settings' AND `order` < 9999 LIMIT 1);
+INSERT INTO `sys_menu_items` (`set_name`, `module`, `name`, `title_system`, `title`, `link`, `onclick`, `target`, `icon`, `addon`, `submenu_object`, `visible_for_levels`, `active`, `copyable`, `editable`, `order`) VALUES
+('sys_account_settings', @sName, 'github-settings', '_bx_github_menu_item_title_system_settings', '_bx_github_menu_item_title_settings', 'page.php?i=github-settings', '', '_self', 'github', '', '', 2147483646, 1, 0, 1, @iMoAccountSettings + 1);

+ 42 - 0
modules/boonex/github/install/sql/install.sql

@@ -0,0 +1,42 @@
+SET @sName = 'bx_github';
+
+
+-- TABLE: settings
+CREATE TABLE IF NOT EXISTS `bx_github_settings` (
+  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
+  `profile_id` int(11) unsigned NOT NULL DEFAULT 0,
+  `pat` varchar(255) NOT NULL DEFAULT '',
+  PRIMARY KEY (`id`),
+  UNIQUE KEY `profile_id` (`profile_id`)
+);
+
+
+-- FORMS
+INSERT INTO `sys_objects_form` (`object`, `module`, `title`, `action`, `form_attrs`, `submit_name`, `table`, `key`, `uri`, `uri_title`, `params`, `deletable`, `active`, `override_class_name`, `override_class_file`) VALUES
+('bx_github_form_settings', @sName, '_bx_github_form_settings', '', '', 'do_submit', 'bx_github_settings', 'id', '', '', '', 0, 1, 'BxGitHubFormSettings', 'modules/boonex/github/classes/BxGitHubFormSettings.php');
+
+INSERT INTO `sys_form_displays` (`display_name`, `module`, `object`, `title`, `view_mode`) VALUES
+('bx_github_form_settings_edit', @sName, 'bx_github_form_settings', '_bx_github_form_settings_display_edit', 0);
+
+INSERT INTO `sys_form_inputs` (`object`, `module`, `name`, `value`, `values`, `checked`, `type`, `caption_system`, `caption`, `info`, `required`, `collapsed`, `html`, `attrs`, `attrs_tr`, `attrs_wrapper`, `checker_func`, `checker_params`, `checker_error`, `db_pass`, `db_params`, `editable`, `deletable`) VALUES
+('bx_github_form_settings', @sName, 'profile_id', '0', '', 0, 'hidden', '_bx_github_form_settings_input_sys_profile_id', '', '', 0, 0, 0, '', '', '', '', '', '', 'Int', '', 0, 0),
+('bx_github_form_settings', @sName, 'pat', '', '', 0, 'text', '_bx_github_form_settings_input_sys_pat', '_bx_github_form_settings_input_pat', '', 1, 0, 0, '', '', '', 'Avail', '', '_bx_github_form_input_err_enter', 'Xss', '', 0, 0),
+('bx_github_form_settings', @sName, 'do_submit', '_bx_github_form_settings_input_do_submit', '', 0, 'submit', '_bx_github_form_settings_input_sys_do_submit', '', '', 0, 0, 0, '', '', '', '', '', '', '', '', 1, 0);
+
+INSERT INTO `sys_form_display_inputs` (`display_name`, `input_name`, `visible_for_levels`, `active`, `order`) VALUES
+('bx_github_form_settings_edit', 'profile_id', 2147483647, 1, 1),
+('bx_github_form_settings_edit', 'pat', 2147483647, 1, 2),
+('bx_github_form_settings_edit', 'do_submit', 2147483647, 1, 3);
+
+
+-- STUDIO PAGE & WIDGET
+INSERT INTO `sys_std_pages`(`index`, `name`, `header`, `caption`, `icon`) VALUES
+(3, @sName, '_bx_github', '_bx_github', 'bx_github@modules/boonex/github/|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, @sName, '{url_studio}module.php?name=bx_github', '', 'bx_github@modules/boonex/github/|std-icon.svg', '_bx_github', '', '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));

+ 18 - 0
modules/boonex/github/install/sql/uninstall.sql

@@ -0,0 +1,18 @@
+SET @sName = 'bx_github';
+
+
+-- TABLES
+DROP TABLE IF EXISTS `bx_github_settings`;
+
+
+-- FORMS
+DELETE FROM `sys_form_display_inputs` WHERE `display_name` IN (SELECT `display_name` FROM `sys_form_displays` WHERE `module`=@sName);
+DELETE FROM `sys_form_inputs` WHERE `module`=@sName;
+DELETE FROM `sys_form_displays` WHERE `module`=@sName;
+DELETE FROM `sys_objects_form` WHERE `module`=@sName;
+
+
+-- STUDIO PAGE & 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` = @sName;

+ 18 - 0
modules/boonex/github/request.php

@@ -0,0 +1,18 @@
+<?php defined('BX_DOL') or die('hack attempt');
+/**
+ * Copyright (c) UNA, Inc - https://una.io
+ * MIT License - https://opensource.org/licenses/MIT
+ *
+ * @defgroup    GitHub GitHub
+ * @ingroup     UnaModules
+ *
+ * @{
+ */
+
+require_once(BX_DIRECTORY_PATH_INC . "design.inc.php");
+
+check_logged();
+
+BxDolRequest::processAsAction($GLOBALS['aModule'], $GLOBALS['aRequest']);
+
+/** @} */

Rozdílová data souboru nebyla zobrazena, protože soubor je příliš velký
+ 5 - 0
modules/boonex/github/template/images/icons/std-icon.svg


Některé soubory nejsou zobrazeny, neboť je v těchto rozdílových datech změněno mnoho souborů