| @@ -1,75 +1,86 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | namespace Barn2\Plugin\Posts_Table_Search_Sort; |
| 4 | 4 | |
| 5 | -use Barn2\Lib\Util, | |
| 6 | - Barn2\Lib\Registerable, | |
| 7 | - Barn2\Lib\Plugin\Plugin, | |
| 8 | - Barn2\Lib\Service; | |
| 5 | +use Barn2\Plugin\Posts_Table_Search_Sort\Dependencies\Lib\Plugin\Plugin; | |
| 6 | +use Barn2\Plugin\Posts_Table_Search_Sort\Dependencies\Lib\Registerable; | |
| 7 | +use Barn2\Plugin\Posts_Table_Search_Sort\Dependencies\Lib\Service\Standard_Service; | |
| 8 | +use Barn2\Plugin\Posts_Table_Search_Sort\Dependencies\Lib\Util; | |
| 9 | 9 | |
| 10 | 10 | /** |
| 11 | 11 | * Registers the frontend styles and scripts for the post tables. |
| 12 | 12 | * |
| 13 | - * @author Barn2 Media <info@barn2.co.uk> | |
| 13 | + * @package Barn2\posts-table-search-sort | |
| 14 | + * @author Barn2 Plugins <support@barn2.com> | |
| 14 | 15 | * @license GPL-3.0 |
| 15 | 16 | * @copyright Barn2 Media Ltd |
| 16 | 17 | */ |
| 17 | -class Frontend_Scripts implements Registerable, Service { | |
| 18 | +class Frontend_Scripts implements Registerable, Standard_Service { | |
| 18 | 19 | |
| 19 | - private $plugin; | |
| 20 | + const DATATABLES_VERSION = '1.11.3'; | |
| 20 | 21 | |
| 21 | - public function __construct( Plugin $plugin ) { | |
| 22 | - $this->plugin = $plugin; | |
| 23 | - } | |
| 22 | + private $plugin; | |
| 24 | 23 | |
| 25 | - public function register() { | |
| 26 | - \add_action( 'wp_enqueue_scripts', array( $this, 'register_styles' ) ); | |
| 27 | - \add_action( 'wp_enqueue_scripts', array( $this, 'register_scripts' ) ); | |
| 28 | - } | |
| 24 | + public function __construct( Plugin $plugin ) { | |
| 25 | + $this->plugin = $plugin; | |
| 26 | + } | |
| 29 | 27 | |
| 30 | - public function register_styles() { | |
| 31 | - $suffix = Util::get_script_suffix(); | |
| 28 | + public function register() { | |
| 29 | + add_action( 'wp_enqueue_scripts', [ $this, 'register_styles' ] ); | |
| 30 | + add_action( 'wp_enqueue_scripts', [ $this, 'register_scripts' ] ); | |
| 31 | + } | |
| 32 | 32 | |
| 33 | - \wp_enqueue_style( 'jquery-data-tables', \plugins_url( 'assets/js/datatables/datatables.min.css', $this->plugin->get_file() ), array(), '1.10.18' ); | |
| 34 | - \wp_enqueue_style( 'posts-data-table', \plugins_url( "assets/css/posts-data-table{$suffix}.css", $this->plugin->get_file() ), array( 'jquery-data-tables' ), $this->plugin->get_version() ); | |
| 35 | - } | |
| 33 | + public function register_styles() { | |
| 34 | + $suffix = Util::get_script_suffix(); | |
| 36 | 35 | |
| 37 | - public function register_scripts() { | |
| 38 | - $suffix = Util::get_script_suffix(); | |
| 36 | + wp_register_style( 'jquery-datatables-pss', plugins_url( 'assets/js/datatables/datatables.min.css', $this->plugin->get_file() ), [], self::DATATABLES_VERSION ); | |
| 37 | + wp_register_style( 'posts-data-table', plugins_url( "assets/css/posts-data-table-main.css", $this->plugin->get_file() ), [ 'jquery-datatables-pss' ], $this->plugin->get_version() ); | |
| 38 | + } | |
| 39 | 39 | |
| 40 | - \wp_enqueue_script( 'jquery-data-tables', \plugins_url( "assets/js/datatables/datatables.min.js", $this->plugin->get_file() ), array( 'jquery' ), '1.10.18', true ); | |
| 41 | - \wp_enqueue_script( 'posts-data-table', \plugins_url( "assets/js/posts-data-table{$suffix}.js", $this->plugin->get_file() ), array( 'jquery-data-tables' ), $this->plugin->get_version(), true ); | |
| 40 | + public function register_scripts() { | |
| 41 | + $suffix = Util::get_script_suffix(); | |
| 42 | 42 | |
| 43 | - $locale = \get_locale(); | |
| 44 | - $supported_locales = $this->get_supported_locales(); | |
| 43 | + wp_register_script( 'jquery-datatables-pss', plugins_url( "assets/js/datatables/datatables{$suffix}.js", $this->plugin->get_file() ), [ 'jquery' ], self::DATATABLES_VERSION, true ); | |
| 44 | + wp_register_script( 'posts-data-table', plugins_url( "assets/js/posts-data-table-main.js", $this->plugin->get_file() ), [ 'jquery', 'jquery-datatables-pss' ], $this->plugin->get_version(), true ); | |
| 45 | 45 | |
| 46 | - // Add language file to script if locale is supported (English file is not added as this is the default language) | |
| 47 | - if ( \array_key_exists( $locale, $supported_locales ) ) { | |
| 48 | - \wp_localize_script( 'posts-data-table', 'posts_data_table', array( | |
| 49 | - 'langurl' => $supported_locales[$locale] | |
| 50 | - ) ); | |
| 51 | - } | |
| 52 | - } | |
| 46 | + $locale = get_locale(); | |
| 47 | + $supported_locales = $this->get_supported_locales(); | |
| 53 | 48 | |
| 54 | - /** | |
| 55 | - * Returns an array of locales supported by the plugin. | |
| 56 | - * The array returned uses the locale as the array key mapped to the URL of the corresponding translation file. | |
| 57 | - * | |
| 58 | - * @return array The supported locales | |
| 59 | - */ | |
| 60 | - private function get_supported_locales() { | |
| 61 | - $lang_file_base_url = \plugins_url( 'languages/data-tables/', $this->plugin->get_file() ); | |
| 49 | + // Add language file to script if locale is supported (English file is not added as this is the default language) | |
| 50 | + if ( array_key_exists( $locale, $supported_locales ) ) { | |
| 51 | + wp_localize_script( | |
| 52 | + 'posts-data-table', | |
| 53 | + 'posts_data_table', | |
| 54 | + [ | |
| 55 | + 'langurl' => $supported_locales[ $locale ] | |
| 56 | + ] | |
| 57 | + ); | |
| 58 | + } | |
| 59 | + } | |
| 62 | 60 | |
| 63 | - return \apply_filters( 'posts_data_table_supported_languages', array( | |
| 64 | - 'es_ES' => $lang_file_base_url . 'Spanish.json', | |
| 65 | - 'fr_FR' => $lang_file_base_url . 'French.json', | |
| 66 | - 'fr_BE' => $lang_file_base_url . 'French.json', | |
| 67 | - 'fr_CA' => $lang_file_base_url . 'French.json', | |
| 68 | - 'de_DE' => $lang_file_base_url . 'German.json', | |
| 69 | - 'de_CH' => $lang_file_base_url . 'German.json', | |
| 70 | - 'el' => $lang_file_base_url . 'Greek.json', | |
| 71 | - 'el_EL' => $lang_file_base_url . 'Greek.json', | |
| 72 | - ) ); | |
| 73 | - } | |
| 61 | + /** | |
| 62 | + * Returns an array of locales supported by the plugin. | |
| 63 | + * The array returned uses the locale as the array key mapped to the URL of the corresponding translation file. | |
| 64 | + * | |
| 65 | + * @return array The supported locales | |
| 66 | + */ | |
| 67 | + private function get_supported_locales() { | |
| 68 | + $lang_file_base_url = plugins_url( 'languages/data-tables/', $this->plugin->get_file() ); | |
| 69 | + | |
| 70 | + return apply_filters( | |
| 71 | + 'posts_data_table_supported_languages', | |
| 72 | + [ | |
| 73 | + 'es_ES' => $lang_file_base_url . 'Spanish.json', | |
| 74 | + 'fr_FR' => $lang_file_base_url . 'French.json', | |
| 75 | + 'fr_BE' => $lang_file_base_url . 'French.json', | |
| 76 | + 'fr_CA' => $lang_file_base_url . 'French.json', | |
| 77 | + 'de_DE' => $lang_file_base_url . 'German.json', | |
| 78 | + 'de_CH' => $lang_file_base_url . 'German.json', | |
| 79 | + 'el' => $lang_file_base_url . 'Greek.json', | |
| 80 | + 'el_EL' => $lang_file_base_url . 'Greek.json', | |
| 81 | + 'zh_TW' => $lang_file_base_url . 'Taiwan.json', | |
| 82 | + ] | |
| 83 | + ); | |
| 84 | + } | |
| 74 | 85 | |
| 75 | 86 | } |