From e1fe18dd2c6506865976a8e049310e63ea4eece7 Mon Sep 17 00:00:00 2001 From: kodinkat Date: Thu, 28 Mar 2024 14:14:58 +0000 Subject: [PATCH 1/3] Initial D.T Media Plugin shape --- .github/workflows/release.yml | 12 +- .rename.sh | 14 +- CONTRIBUTING.md | 6 +- LICENSE | 2 +- README.md | 18 +- admin/admin-menu-and-tabs.php | 247 ++---------- admin/connections-tab.php | 279 ++++++++++++++ admin/general-tab.php | 107 ++++++ admin/js/connections-tab.js | 352 ++++++++++++++++++ charts/charts-loader.php | 6 +- charts/one-page-chart-template.php | 8 +- disciple-tools-media-api.php | 82 ++++ disciple-tools-media-filters.php | 234 ++++++++++++ ...r-template.php => disciple-tools-media.php | 76 ++-- documentation/community/starter-readme.md | 14 +- languages/Readme.md | 2 +- languages/default.pot | 10 +- ...ple-tools-plugin-starter-template-es_ES.po | 8 +- ...ple-tools-plugin-starter-template-fr_FR.po | 6 +- languages/terms_to_exclude.pot | 6 +- magic-link/magic-link-home.php | 4 +- magic-link/magic-link-login-user-app.php | 8 +- magic-link/magic-link-map.php | 6 +- magic-link/magic-link-non-object.php | 6 +- magic-link/magic-link-user-app.php | 8 +- .../magic-link-post-type.php | 12 +- post-type/loader.php | 8 +- post-type/module-base.php | 90 ++--- rest-api/rest-api.php | 6 +- site-link/custom-site-to-site-links.php | 8 +- test/test_for_syntax_errors.sh | 2 +- test/test_phpcs.sh | 2 +- test/unit-test-plugin.php | 4 +- tile/custom-tile.php | 74 ++-- tile/profile-settings-tile.php | 20 +- version-control.json | 26 +- workflows/workflows.php | 24 +- 37 files changed, 1343 insertions(+), 454 deletions(-) mode change 100644 => 100755 .rename.sh create mode 100644 admin/connections-tab.php create mode 100644 admin/general-tab.php create mode 100644 admin/js/connections-tab.js create mode 100644 disciple-tools-media-api.php create mode 100644 disciple-tools-media-filters.php rename disciple-tools-plugin-starter-template.php => disciple-tools-media.php (79%) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 225b97b..7f73057 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -18,13 +18,13 @@ jobs: # - name: Run test suite # run: composer run-script test - # cp -r disciple-tools-plugin-starter-template.php includes languages spinner.svg version-control.json LICENSE SECURITY.md disciple-tools-plugin-starter-template/ + # cp -r disciple-tools-media.php includes languages spinner.svg version-control.json LICENSE SECURITY.md disciple-tools-media/ # Below borrowed from https://github.com/actions/upload-release-asset - name: Build project run: | - mkdir disciple-tools-plugin-starter-template - cp -r disciple-tools-plugin-starter-template.php admin charts languages magic-link post-type rest-api site-link tile workflows spinner.svg version-control.json LICENSE SECURITY.md disciple-tools-plugin-starter-template/ - zip -r disciple-tools-plugin-starter-template.zip disciple-tools-plugin-starter-template + mkdir disciple-tools-media + cp -r disciple-tools-media.php admin charts languages magic-link post-type rest-api site-link tile workflows spinner.svg version-control.json LICENSE SECURITY.md disciple-tools-media/ + zip -r disciple-tools-media.zip disciple-tools-media - name: Create Release id: create_release uses: actions/create-release@v1 @@ -42,6 +42,6 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: upload_url: ${{ steps.create_release.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps - asset_path: ./disciple-tools-plugin-starter-template.zip - asset_name: disciple-tools-plugin-starter-template.zip + asset_path: ./disciple-tools-media.zip + asset_name: disciple-tools-media.zip asset_content_type: application/zip diff --git a/.rename.sh b/.rename.sh old mode 100644 new mode 100755 index 02babc6..535b931 --- a/.rename.sh +++ b/.rename.sh @@ -1,7 +1,7 @@ -find ./ -type f -print0 | xargs -0 perl -pi -e 's/Disciple_Tools_Plugin_Starter_Template/Disciple_Tools_Plugin_Starter_Template/g'; -find ./ -type f -print0 | xargs -0 perl -pi -e 's/disciple_tools_plugin_starter_template/disciple_tools_plugin_starter_template/g'; -find ./ -type f -print0 | xargs -0 perl -pi -e 's/disciple-tools-plugin-starter-template/disciple-tools-plugin-starter-template/g'; -find ./ -type f -print0 | xargs -0 perl -pi -e 's/starter_post_type/starter_post_type/g'; -find ./ -type f -print0 | xargs -0 perl -pi -e 's/Plugin Starter Template/Plugin Starter Template/g'; -mv disciple-tools-plugin-starter-template.php disciple-tools-plugin-starter-template.php -rm .rename.sh \ No newline at end of file +find ./ -type f -print0 | xargs -0 perl -pi -e 's/Disciple_Tools_Media/Disciple_Tools_Media/g'; +find ./ -type f -print0 | xargs -0 perl -pi -e 's/disciple_tools_media/disciple_tools_media/g'; +find ./ -type f -print0 | xargs -0 perl -pi -e 's/disciple-tools-media/disciple-tools-media/g'; +find ./ -type f -print0 | xargs -0 perl -pi -e 's/media/media/g'; +find ./ -type f -print0 | xargs -0 perl -pi -e 's/Media/Media/g'; +mv disciple-tools-plugin-starter-template.php disciple-tools-media.php +# rm .rename.sh diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 0ab54d2..5a0d61b 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -2,7 +2,7 @@ Thank you for joining us in contributing to Disciple.Tools! These are the guidel ### Translations D.T is already being used in multiple languages. Please help us make D.T translable by taking full advantage of Wordpress’ translatable strings. Any string that will be read by the user must be marked as translatable. Ex: -`` +`` Make sure you look for these in PHP, HTML and JavaScript code. @@ -15,10 +15,10 @@ If you are working on a plugin based off our starter plugin run `./includes/admi You might need to run `composer install` first. -Note: rules for PHPCS are located in the `phpcs.xml` file. We sometimes update the rule list as PHPCS updates. We’ll update the [starter plugin](https://github.com/DiscipleTools/disciple-tools-plugin-starter-template) `phpcs.xml`, you might want to look there to get the latest version. +Note: rules for PHPCS are located in the `phpcs.xml` file. We sometimes update the rule list as PHPCS updates. We’ll update the [starter plugin](https://github.com/DiscipleTools/disciple-tools-media) `phpcs.xml`, you might want to look there to get the latest version. ### GitHub and Commits -For new plugins copy our [starter plugin](https://github.com/DiscipleTools/disciple-tools-plugin-starter-template). +For new plugins copy our [starter plugin](https://github.com/DiscipleTools/disciple-tools-media). To commit to the theme or an existing plugin start by creating a fork of the repository. When you are ready, create a pull request into our repo. diff --git a/LICENSE b/LICENSE index e6cb320..ce81629 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Disciple.Tools - Plugin Starter Template +Disciple.Tools - Media Copyright (C) 2018 by various contributors diff --git a/README.md b/README.md index 79fd914..b2732bb 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,16 @@ -![Build Status](https://github.com/DiscipleTools/disciple-tools-plugin-starter-template/actions/workflows/ci.yml/badge.svg?branch=master) +![Build Status](https://github.com/DiscipleTools/disciple-tools-media/actions/workflows/ci.yml/badge.svg?branch=master) ## Dev notes, delete me: This is a starter plugin to jumpstart your work with Disciple.Tools. Click the "Use this template" button above. -See instructions for refactoring and getting started in the [wiki](https://github.com/DiscipleTools/disciple-tools-plugin-starter-template/wiki) -See instructions for creating releases and publishing your plugin: [wiki](https://github.com/DiscipleTools/disciple-tools-plugin-starter-template/wiki) +See instructions for refactoring and getting started in the [wiki](https://github.com/DiscipleTools/disciple-tools-media/wiki) +See instructions for creating releases and publishing your plugin: [wiki](https://github.com/DiscipleTools/disciple-tools-media/wiki) In order to display the banner correctly on the Disciple.Tools Community Plugins Site, don't change the 'Plugin Banner' text on line 12; only the URL. ## readme format: -![Plugin Banner](https://raw.githubusercontent.com/DiscipleTools/disciple-tools-plugin-starter-template/b30402d97895e3f911efcb47fb8f29ccd1eb92e5/documentation/banner.png) +![Plugin Banner](https://raw.githubusercontent.com/DiscipleTools/disciple-tools-media/b30402d97895e3f911efcb47fb8f29ccd1eb92e5/documentation/banner.png) -# Disciple.Tools - Plugin Starter Template +# Disciple.Tools - Media Description Description Description Description Description Description Description Description Description Description Description Description Description Description @@ -48,11 +48,11 @@ Purpose purpose purpose purpose purpose purpose purpose purpose purpose purpose ## Contribution Contributions welcome. You can report issues and bugs in the -[Issues](https://github.com/DiscipleTools/disciple-tools-plugin-starter-template/issues) section of the repo. You can present ideas -in the [Discussions](https://github.com/DiscipleTools/disciple-tools-plugin-starter-template/discussions) section of the repo. And -code contributions are welcome using the [Pull Request](https://github.com/DiscipleTools/disciple-tools-plugin-starter-template/pulls) +[Issues](https://github.com/DiscipleTools/disciple-tools-media/issues) section of the repo. You can present ideas +in the [Discussions](https://github.com/DiscipleTools/disciple-tools-media/discussions) section of the repo. And +code contributions are welcome using the [Pull Request](https://github.com/DiscipleTools/disciple-tools-media/pulls) system for git. For a more details on contribution see the -[contribution guidelines](https://github.com/DiscipleTools/disciple-tools-plugin-starter-template/blob/master/CONTRIBUTING.md). +[contribution guidelines](https://github.com/DiscipleTools/disciple-tools-media/blob/master/CONTRIBUTING.md). ## Screenshots diff --git a/admin/admin-menu-and-tabs.php b/admin/admin-menu-and-tabs.php index d26b323..bb812a8 100644 --- a/admin/admin-menu-and-tabs.php +++ b/admin/admin-menu-and-tabs.php @@ -2,23 +2,23 @@ if ( ! defined( 'ABSPATH' ) ) { exit; } // Exit if accessed directly /** - * Class Disciple_Tools_Plugin_Starter_Template_Menu + * Class Disciple_Tools_Media_Menu */ -class Disciple_Tools_Plugin_Starter_Template_Menu { +class Disciple_Tools_Media_Menu { - public $token = 'disciple_tools_plugin_starter_template'; - public $page_title = 'Plugin Starter Template'; + public $token = 'disciple_tools_media'; + public $page_title = 'Media'; private static $_instance = null; /** - * Disciple_Tools_Plugin_Starter_Template_Menu Instance + * Disciple_Tools_Media_Menu Instance * - * Ensures only one instance of Disciple_Tools_Plugin_Starter_Template_Menu is loaded or can be loaded. + * Ensures only one instance of Disciple_Tools_Media_Menu is loaded or can be loaded. * * @since 0.1.0 * @static - * @return Disciple_Tools_Plugin_Starter_Template_Menu instance + * @return Disciple_Tools_Media_Menu instance */ public static function instance() { if ( is_null( self::$_instance ) ) { @@ -37,7 +37,7 @@ public function __construct() { add_action( 'admin_menu', array( $this, 'register_menu' ) ); - $this->page_title = __( 'Plugin Starter Template', 'disciple-tools-plugin-starter-template' ); + $this->page_title = __( 'Media', 'disciple-tools-media' ); } // End __construct() @@ -46,7 +46,7 @@ public function __construct() { * @since 0.1 */ public function register_menu() { - $this->page_title = __( 'Plugin Starter Template', 'disciple-tools-plugin-starter-template' ); + $this->page_title = __( 'Media', 'disciple-tools-media' ); add_submenu_page( 'dt_extensions', $this->page_title, $this->page_title, 'manage_dt', $this->token, [ $this, 'content' ] ); } @@ -69,219 +69,50 @@ public function content() { if ( isset( $_GET['tab'] ) ) { $tab = sanitize_key( wp_unslash( $_GET['tab'] ) ); } else { - $tab = 'general'; + $tab = 'connections'; } $link = 'admin.php?page='.$this->token.'&tab='; ?>
-

page_title ) ?>

+

DISCIPLE TOOLS : page_title ) ?>

content(); - break; - case 'second': - $object = new Disciple_Tools_Plugin_Starter_Template_Tab_Second(); - $object->content(); - break; - default: - break; + // Ensure required PHP version can be detected. + if ( version_compare( phpversion(), '8.1', '<' ) ) { + ?> +
+ + + + content(); + break;*/ + case 'connections': + require( 'connections-tab.php' ); + $object = new Disciple_Tools_Media_Tab_Connections(); + $object->content(); + break; + default: + break; + } } ?> -
- - -
-
-
-
- - - main_column() ?> - - -
-
- - - right_column() ?> - - -
-
-
-
-
-
- token; - $this->process_form_fields( $token ); - - $my_plugin_option = get_option( $token . '_my_plugin_option' ); - ?> -
- - - - - - - - - - - - - - - - - - -
Settings
- My Plugin Option - - -
- -
-
-
- - - - - - - - - - - - - -
Information
- Content -
-
- - -
-
-
-
- - - main_column() ?> - - -
-
- - - right_column() ?> - - -
-
-
-
-
-
- - - - - - - - - - - - - -
Header
- Content -
-
- - - - - - - - - - - - - - -
Information
- Content -
-
- process_updates(); + + // Load scripts and styles + $this->process_scripts(); + } + + private function final_post_param_sanitization( $str ) { + return str_replace( [ '<', '>' ], [ '<', '>' ], $str ); + } + + public function process_updates() { + + if ( isset( $_POST['m_main_col_update_form_nonce'] ) && wp_verify_nonce( sanitize_key( wp_unslash( $_POST['m_main_col_update_form_nonce'] ) ), 'm_main_col_update_form_nonce' ) ) { + if ( isset( $_POST['m_main_col_update_form_connection_obj'] ) ){ + + // Fetch newly updated link object. + $sanitized_input = filter_var( wp_unslash( $_POST['m_main_col_update_form_connection_obj'] ), FILTER_SANITIZE_FULL_SPECIAL_CHARS, FILTER_FLAG_NO_ENCODE_QUOTES ); + $updating_connection_obj = json_decode( $this->final_post_param_sanitization( $sanitized_input ) ); + + // Ensure we have something to work with. + if ( !empty( $updating_connection_obj ) && isset( $updating_connection_obj->id ) ) { + Disciple_Tools_Media_API::update_option_connection_obj( $updating_connection_obj ); + } + } + } + + if ( isset( $_POST['m_main_col_delete_form_nonce'] ) && wp_verify_nonce( sanitize_key( wp_unslash( $_POST['m_main_col_delete_form_nonce'] ) ), 'm_main_col_delete_form_nonce' ) ) { + if ( isset( $_POST['m_main_col_delete_form_connection_obj_id'] ) ) { + + // Fetch connection object id to be deleted. + $connection_obj_id = filter_var( wp_unslash( $_POST['m_main_col_delete_form_connection_obj_id'] ), FILTER_SANITIZE_FULL_SPECIAL_CHARS, FILTER_FLAG_NO_ENCODE_QUOTES ); + + // Ensure we have something to work with. + if ( ! empty( $connection_obj_id ) ) { + Disciple_Tools_Media_API::delete_option_connection_obj( $connection_obj_id ); + } + } + } + } + + private function fetch_previous_updated_connection_obj() { + if ( isset( $_POST['m_main_col_update_form_nonce'] ) && wp_verify_nonce( sanitize_key( wp_unslash( $_POST['m_main_col_update_form_nonce'] ) ), 'm_main_col_update_form_nonce' ) ) { + if ( isset( $_POST['m_main_col_update_form_connection_obj'] ) ) { + $sanitized_input = filter_var( wp_unslash( $_POST['m_main_col_update_form_connection_obj'] ), FILTER_SANITIZE_FULL_SPECIAL_CHARS, FILTER_FLAG_NO_ENCODE_QUOTES ); + + return json_decode( $this->final_post_param_sanitization( $sanitized_input ) ); + } + } + + return null; + } + + public function process_scripts() { + wp_enqueue_script( 'aws-sdk-s3', 'https://sdk.amazonaws.com/js/aws-sdk-2.1583.0.min.js', [ 'jquery' ], '2.1583.0', true ); + + dt_theme_enqueue_style( 'material-font-icons-local', 'dt-core/dependencies/mdi/css/materialdesignicons.min.css', array() ); + wp_enqueue_style( 'material-font-icons', 'https://cdn.jsdelivr.net/npm/@mdi/font@6.6.96/css/materialdesignicons.min.css' ); + + wp_enqueue_script( 'dt_media_script', plugin_dir_url( __FILE__ ) . 'js/connections-tab.js', [ + 'jquery', + 'aws-sdk-s3' + ], filemtime( dirname( __FILE__ ) . '/js/connections-tab.js' ), true ); + + wp_localize_script( + 'dt_media_script', 'dt_media', array( + 'connection_types' => Disciple_Tools_Media_API::list_supported_connection_types(), + 'connection_objs' => Disciple_Tools_Media_API::fetch_option_connection_objs(), + 'previous_updated_connection_obj' => $this->fetch_previous_updated_connection_obj() + ) + ); + } + + public function content() { + ?> +
+
+
+
+ + + main_column() ?> + + +
+
+ + + right_column() ?> + + +
+
+
+
+
+
+ + + + + + + + + + + + + +
Available Connections
+ main_column_available_connections(); ?> +
+
+ + + + + + +
+ + + +
+ + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + +
+ + + +
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + +
Enabled + +
Name + + +
Connection Type [?] + + +
+ +
+ +
+
+
+
+ + + main_column() ?> + + +
+
+ + + right_column() ?> + + +
+
+
+
+
+
+ token; + $this->process_form_fields( $token ); + + $my_plugin_option = get_option( $token . '_my_plugin_option' ); + ?> +
+ + + + + + + + + + + + + + + + + + +
Settings
+ My Plugin Option + + +
+ +
+
+
+ + + + + + + + + + + + + +
Information
+ Content +
+
+ + ').prop('disabled', true).prop('selected', true).val('').text('-- select available connection --')); + + $.each(connections, function (id, connection) { + $(connection_objs_select).append($('