From 0ce715a4d329613d79e915b6760164f1e67920d4 Mon Sep 17 00:00:00 2001
From: Piotr Po <potreb@gmail.com>
Date: Mon, 7 Nov 2022 08:23:49 +0100
Subject: [PATCH] feat: plugin path, lang, scripts version

---
 .editorconfig                  | 78 +++++++++++++++++++++++++++++++---
 .gitignore                     | 14 ++++++
 .gitlab/issue_templates/Bug.md | 32 --------------
 CHANGELOG.md                   |  8 +++-
 composer.json                  | 73 +++++++++++++++++--------------
 lang/pl_PL.po                  | 38 +++++++++++++++++
 src/Plugin/AbstractPlugin.php  | 43 +++++++++++++------
 7 files changed, 203 insertions(+), 83 deletions(-)
 delete mode 100644 .gitlab/issue_templates/Bug.md
 create mode 100644 lang/pl_PL.po

diff --git a/.editorconfig b/.editorconfig
index d8c5892..a8487df 100644
--- a/.editorconfig
+++ b/.editorconfig
@@ -4,6 +4,8 @@
 # WordPress Coding Standards
 # https://make.wordpress.org/core/handbook/coding-standards/
 
+# Configuration for PhpStorm
+
 root = true
 
 [*]
@@ -12,10 +14,76 @@ end_of_line = lf
 insert_final_newline = true
 trim_trailing_whitespace = true
 indent_style = tab
+indent_size = 4
+tab_width = 4
+ij_continuation_indent_size = 4
+
+[{*.scss,*.css}]
+ij_scss_enforce_quotes_on_format = true
+ij_scss_hex_color_long_format = true
+ij_scss_hex_color_lower_case = true
+
+[{*.cjs,*.js}]
+ij_javascript_do_while_brace_force = always
+ij_javascript_if_brace_force = always
+ij_javascript_import_sort_module_name = true
+ij_javascript_reformat_c_style_comments = true
+ij_javascript_space_after_unary_not = true
+ij_javascript_space_before_unary_not = true
+ij_javascript_spaces_within_array_initializer_brackets = true
+ij_javascript_spaces_within_brackets = true
+ij_javascript_spaces_within_catch_parentheses = true
+ij_javascript_spaces_within_for_parentheses = true
+ij_javascript_spaces_within_if_parentheses = true
+ij_javascript_spaces_within_imports = true
+ij_javascript_spaces_within_interpolation_expressions = true
+ij_javascript_spaces_within_method_call_parentheses = true
+ij_javascript_spaces_within_method_parentheses = true
+ij_javascript_spaces_within_object_literal_braces = true
+ij_javascript_spaces_within_parentheses = true
+ij_javascript_spaces_within_switch_parentheses = true
+ij_javascript_spaces_within_while_parentheses = true
+ij_javascript_while_brace_force = always
 
-[*.yml]
-indent_style = space
-indent_size = 2
+[{*.ctp,*.hphp,*.inc,*.module,*.php,*.php4,*.php5,*.phtml}]
+ij_php_align_assignments = true
+ij_php_align_class_constants = true
+ij_php_align_key_value_pairs = true
+ij_php_align_phpdoc_comments = true
+ij_php_align_phpdoc_param_names = true
+ij_php_class_brace_style = end_of_line
+ij_php_comma_after_last_array_element = true
+ij_php_else_if_style = combine
+ij_php_force_short_declaration_array_style = true
+ij_php_getters_setters_naming_style = snake_case
+ij_php_if_brace_force = always
+ij_php_lower_case_boolean_const = true
+ij_php_lower_case_null_const = true
+ij_php_method_brace_style = end_of_line
+ij_php_phpdoc_blank_line_before_tags = true
+ij_php_phpdoc_blank_lines_around_parameters = true
+ij_php_phpdoc_keep_blank_lines = false
+ij_php_phpdoc_wrap_long_lines = true
+ij_php_space_after_type_cast = true
+ij_php_space_after_unary_not = true
+ij_php_space_before_unary_not = true
+ij_php_spaces_around_var_within_brackets = true
+ij_php_spaces_within_array_initializer_braces = true
+ij_php_spaces_within_catch_parentheses = true
+ij_php_spaces_within_for_parentheses = true
+ij_php_spaces_within_if_parentheses = true
+ij_php_spaces_within_method_call_parentheses = true
+ij_php_spaces_within_method_parentheses = true
+ij_php_spaces_within_parentheses = true
+ij_php_spaces_within_switch_parentheses = true
+ij_php_spaces_within_while_parentheses = true
+ij_php_ternary_operation_signs_on_next_line = true
+ij_php_variable_naming_style = snake_case
 
-[*.md]
-trim_trailing_whitespace = false
\ No newline at end of file
+[{*.htm,*.html,*.ng,*.sht,*.shtm,*.shtml}]
+ij_html_add_new_line_before_tags = div,p,a
+ij_html_align_attributes = false
+ij_html_do_not_indent_children_of_tags = html,thead,tbody,tfoot
+ij_html_new_line_after_last_attribute = when multiline
+ij_html_space_inside_empty_tag = true
+ij_html_uniform_ident = true
diff --git a/.gitignore b/.gitignore
index 30babff..773e4ea 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,17 @@
+/.gitlab/
+/tmp_artifacts/
 /vendor/
+/vendor_prefixed/
+/.webpack/node_modules/
+/.webpack/v8-compile-cache-0/
 .idea
+build-coverage
+.DS_Store
+.commit
+lang/wpdesk-wp-builder-pl_PL.po
+wpdesk-wp-builder-pl_PL.po
+lang/wpdesk-wp-builder-pl_PL.mo
+wpdesk-wp-builder-pl_PL.mo
+assets/css/admin.css.map
 composer.lock
+.phpcs-cache
diff --git a/.gitlab/issue_templates/Bug.md b/.gitlab/issue_templates/Bug.md
deleted file mode 100644
index fb98b9e..0000000
--- a/.gitlab/issue_templates/Bug.md
+++ /dev/null
@@ -1,32 +0,0 @@
-### Select WooCommerce version e.g: [x] 2.6
-<!--- Select the WooCommerce version on which the error occurred -->
-
-- [ ] [2.6](http://woo26.tests.wpdesk.org)
-- [ ] [2.7](http://woo27.tests.wpdesk.org)
-- [ ] [3.0](http://woo30.tests.wpdesk.org)
-- [ ] [3.1](http://woo31.tests.wpdesk.org)
-- [ ] [3.2](http://woo32.tests.wpdesk.org)
-- [ ] [3.3](http://woo33.tests.wpdesk.org)
-- [ ] [3.4](http://woo34.tests.wpdesk.org)
-- [ ] [Stable](https://stable.wpdesk.org/) 
-
-### Select PHP version e.g: [x] 5.6
-<!--- Select the PHP version on which the error occurred -->
-
-- [ ] 5.3 
-- [ ] 5.5
-- [ ] 5.6
-- [ ] 7.1
-- [ ] 7.2
-
-## Steps to Reproduce
-<!--- Provide a link to a live example, or an unambiguous set of steps to -->
-
-1. 
-2. 
-
-
-## Expected Behavior
-<!--- Tell what should happen -->
-
-1. 
\ No newline at end of file
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 5e63a15..f6e42ff 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,4 +1,10 @@
-## [2.0.0] - 2021-00-07
+## [2.1.0] - 2022-11-07
+### Added
+- plugin path
+- plugin lang
+- scripts version
+
+## [2.0.0] - 2021-01-07
 ### Added
 - plugin shops in WPDesk_Plugin_Info
 
diff --git a/composer.json b/composer.json
index 426d7d1..4886956 100644
--- a/composer.json
+++ b/composer.json
@@ -1,33 +1,44 @@
 {
-    "name": "wpdesk/wp-builder",
-    "authors": [
-        {
-            "name": "Krzysiek",
-            "email": "krzysiek@wpdesk.pl"
-        }
-    ],
-    "require": {
-        "php": ">=5.5"
-    },
-    "require-dev": {
-        "phpunit/phpunit": "<7",
-        "wp-coding-standards/wpcs": "^0.14.1",
-        "squizlabs/php_codesniffer": "^3.0.2",
-        "mockery/mockery": "*",
-        "10up/wp_mock": "*",
-        "wimg/php-compatibility": "^8"
-    },
-    "autoload": {
-		"psr-4": {"WPDesk\\PluginBuilder\\": "src/"},
-		"classmap": ["src/Plugin/WithoutNamespace"]
-    },
-    "autoload-dev": {
-    },
-    "scripts": {
-        "phpcs": "phpcs",
-        "phpunit-unit": "phpunit --configuration phpunit-unit.xml --coverage-text --colors=never",
-        "phpunit-unit-fast": "phpunit --configuration phpunit-unit.xml --no-coverage",
-        "phpunit-integration": "phpunit --configuration phpunit-integration.xml --coverage-text --colors=never",
-        "phpunit-integration-fast": "phpunit --configuration phpunit-integration.xml --no-coverage"
-    }
+  "name": "wpdesk/wp-builder",
+  "authors": [
+	{
+	  "name": "Krzysiek",
+	  "email": "krzysiek@wpdesk.pl"
+	}
+  ],
+  "require": {
+	"php": ">=5.5"
+  },
+  "require-dev": {
+	"phpunit/phpunit": "<7",
+	"wp-coding-standards/wpcs": "^0.14.1",
+	"squizlabs/php_codesniffer": "^3.0.2",
+	"mockery/mockery": "*",
+	"10up/wp_mock": "*",
+	"wimg/php-compatibility": "^8"
+  },
+  "autoload": {
+	"psr-4": {
+	  "WPDesk\\PluginBuilder\\": "src/"
+	},
+	"classmap": [
+	  "src/Plugin/WithoutNamespace"
+	]
+  },
+  "autoload-dev": {
+  },
+  "extra": {
+	"text-domain": "wpdesk-wp-builder",
+	"translations-folder": "lang",
+	"po-files": {
+	  "pl_PL": "pl_PL.po"
+	}
+  },
+  "scripts": {
+	"phpcs": "phpcs",
+	"phpunit-unit": "phpunit --configuration phpunit-unit.xml --coverage-text --colors=never",
+	"phpunit-unit-fast": "phpunit --configuration phpunit-unit.xml --no-coverage",
+	"phpunit-integration": "phpunit --configuration phpunit-integration.xml --coverage-text --colors=never",
+	"phpunit-integration-fast": "phpunit --configuration phpunit-integration.xml --no-coverage"
+  }
 }
diff --git a/lang/pl_PL.po b/lang/pl_PL.po
new file mode 100644
index 0000000..d841808
--- /dev/null
+++ b/lang/pl_PL.po
@@ -0,0 +1,38 @@
+msgid ""
+msgstr ""
+"Project-Id-Version: Flexible Invoices Advanced Filters 1.0.0\n"
+"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/flexible-invoices-"
+"advanced-filters\n"
+"POT-Creation-Date: 2022-11-05 10:34+0100\n"
+"PO-Revision-Date: 2022-11-05 10:34+0100\n"
+"Last-Translator: \n"
+"Language-Team: \n"
+"Language: pl_PL\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+"Plural-Forms: nplurals=3; plural=(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 "
+"|| n%100>=20) ? 1 : 2);\n"
+"X-Generator: Poedit 3.2.1\n"
+"X-Domain: flexible-invoices-filters\n"
+"X-Poedit-Basepath: ..\n"
+"X-Poedit-KeywordsList: __;_e;_n:1,2;_x:1,2c;_ex:1,2c;_nx:4c,1,2;esc_attr__;"
+"esc_attr_e;esc_attr_x:1,2c;esc_html__;esc_html_e;esc_html_x:1,2c;_n_noop:1,2;"
+"\"\n"
+"X-Poedit-SourceCharset: UTF-8\n"
+"X-Poedit-SearchPath-0: .\n"
+"X-Poedit-SearchPathExcluded-0: vendor_prefixed\n"
+"X-Poedit-SearchPathExcluded-1: vendor\n"
+"X-Poedit-SearchPathExcluded-2: tests\n"
+
+#: src/Plugin/AbstractPlugin.php:201
+msgid "Support"
+msgstr "Wsparcie"
+
+#: src/Plugin/AbstractPlugin.php:207
+msgid "Docs"
+msgstr "Dokumentacja"
+
+#: src/Plugin/AbstractPlugin.php:214
+msgid "Settings"
+msgstr "Ustawienia"
diff --git a/src/Plugin/AbstractPlugin.php b/src/Plugin/AbstractPlugin.php
index 61c1569..5a09b8b 100644
--- a/src/Plugin/AbstractPlugin.php
+++ b/src/Plugin/AbstractPlugin.php
@@ -4,10 +4,7 @@ namespace WPDesk\PluginBuilder\Plugin;
 
 /**
  * Base plugin with most basic functionalities used by every WPDesk plugin.
- *
- *
  * Known issues:
- *
  * The class name is too generic but can't be changed as it would introduce a major incompatibility for most of the plugins.
  * The $plugin_url, $docs_url and most other fields should be removed as they only litter the place but for compatibility reasons we can't do it right now.
  * Hook methods should be moved to external classes but for compatibility reasons we can't do it right now.
@@ -73,14 +70,12 @@ abstract class AbstractPlugin extends SlimPlugin {
 	 *
 	 * @return void
 	 * @deprecated Just use __construct to initialize plugin internal state.
-	 *
 	 */
 	public function init_base_variables() {
 	}
 
 	/**
 	 * Initializes plugin external state.
-	 *
 	 * The plugin internal state is initialized in the constructor and the plugin should be internally consistent after creation.
 	 * The external state includes hooks execution, communication with other plugins, integration with WC etc.
 	 *
@@ -126,6 +121,15 @@ abstract class AbstractPlugin extends SlimPlugin {
 		return esc_url( trailingslashit( $this->plugin_url ) );
 	}
 
+	/**
+	 * Returns plugin path.
+	 *
+	 * @return string
+	 */
+	public function get_plugin_path() {
+		return trailingslashit( $this->plugin_info->get_plugin_dir() );
+	}
+
 	/**
 	 * Returns plugin absolute URL to dir with front end assets.
 	 *
@@ -138,7 +142,6 @@ abstract class AbstractPlugin extends SlimPlugin {
 	/**
 	 * @return $this
 	 * @deprecated For backward compatibility.
-	 *
 	 */
 	public function get_plugin() {
 		return $this;
@@ -153,11 +156,9 @@ abstract class AbstractPlugin extends SlimPlugin {
 		add_action( 'admin_enqueue_scripts', [ $this, 'admin_enqueue_scripts' ] );
 		add_action( 'wp_enqueue_scripts', [ $this, 'wp_enqueue_scripts' ] );
 		add_action( 'plugins_loaded', [ $this, 'load_plugin_text_domain' ] );
-		add_filter( 'plugin_action_links_' . plugin_basename( $this->get_plugin_file_path() ), [
-			$this,
-			'links_filter'
-		] );
+		add_filter( 'plugin_action_links_' . plugin_basename( $this->get_plugin_file_path() ), [ $this,	'links_filter' ] );
 	}
+
 	/**
 	 * Initialize plugin test domain. This is a hook function. Do not execute directly.
 	 *
@@ -172,7 +173,7 @@ abstract class AbstractPlugin extends SlimPlugin {
 	 *
 	 * @return void
 	 */
-	public function admin_enqueue_scripts() {
+	public function admin_enqueue_scripts( $hook = '' ) {
 	}
 
 	/**
@@ -183,6 +184,20 @@ abstract class AbstractPlugin extends SlimPlugin {
 	public function wp_enqueue_scripts() {
 	}
 
+	/**
+	 * @param string $prefix
+	 * @param bool   $random
+	 *
+	 * @return int|string
+	 */
+	public function get_scripts_version( $prefix = '', $random = false ) {
+		if ( $random ) {
+			return time();
+		}
+
+		return $prefix . $this->plugin_info->get_version();
+	}
+
 	/**
 	 * Initialize plugin admin links. This is a hook function. Do not execute directly.
 	 *
@@ -198,20 +213,20 @@ abstract class AbstractPlugin extends SlimPlugin {
 		}
 
 		$plugin_links = [
-			'<a target="_blank" href="' . $support_link . '">' . __( 'Support', $this->get_text_domain() ) . '</a>',
+			'<a target="_blank" href="' . $support_link . '">' . esc_html__( 'Support', $this->get_text_domain() ) . '</a>',
 		];
 		$links        = array_merge( $plugin_links, $links );
 
 		if ( $this->docs_url ) {
 			$plugin_links = [
-				'<a target="_blank" href="' . $this->docs_url . '">' . __( 'Docs', $this->get_text_domain() ) . '</a>',
+				'<a target="_blank" href="' . $this->docs_url . '">' . esc_html__( 'Docs', $this->get_text_domain() ) . '</a>',
 			];
 			$links        = array_merge( $plugin_links, $links );
 		}
 
 		if ( $this->settings_url ) {
 			$plugin_links = [
-				'<a href="' . $this->settings_url . '">' . __( 'Settings', $this->get_text_domain() ) . '</a>',
+				'<a href="' . $this->settings_url . '">' . esc_html__( 'Settings', $this->get_text_domain() ) . '</a>',
 			];
 			$links        = array_merge( $plugin_links, $links );
 		}
-- 
GitLab