@@ -4,84 +4,84 @@ |
||
| 4 | 4 | |
| 5 | 5 | class SiteReviewsPopup extends TinymcePopupGenerator |
| 6 | 6 | { |
| 7 | - /** |
|
| 8 | - * @return array |
|
| 9 | - */ |
|
| 10 | - public function fields() |
|
| 11 | - { |
|
| 12 | - return [[ |
|
| 13 | - 'html' => sprintf('<p class="strong">%s</p>', esc_html__('All settings are optional.', 'site-reviews')), |
|
| 14 | - 'minWidth' => 320, |
|
| 15 | - 'type' => 'container', |
|
| 16 | - ], [ |
|
| 17 | - 'label' => esc_html__('Title', 'site-reviews'), |
|
| 18 | - 'name' => 'title', |
|
| 19 | - 'tooltip' => __('Enter a custom shortcode heading.', 'site-reviews'), |
|
| 20 | - 'type' => 'textbox', |
|
| 21 | - ], [ |
|
| 22 | - 'label' => esc_html__('Display', 'site-reviews'), |
|
| 23 | - 'maxLength' => 5, |
|
| 24 | - 'name' => 'display', |
|
| 25 | - 'size' => 3, |
|
| 26 | - 'text' => '10', |
|
| 27 | - 'tooltip' => __('How many reviews would you like to display (default: 10)?', 'site-reviews'), |
|
| 28 | - 'type' => 'textbox', |
|
| 29 | - ], [ |
|
| 30 | - 'label' => esc_html__('Rating', 'site-reviews'), |
|
| 31 | - 'name' => 'rating', |
|
| 32 | - 'options' => [ |
|
| 33 | - '5' => esc_html(sprintf(_n('%s star', '%s stars', 5, 'site-reviews'), 5)), |
|
| 34 | - '4' => esc_html(sprintf(_n('%s star', '%s stars', 4, 'site-reviews'), 4)), |
|
| 35 | - '3' => esc_html(sprintf(_n('%s star', '%s stars', 3, 'site-reviews'), 3)), |
|
| 36 | - '2' => esc_html(sprintf(_n('%s star', '%s stars', 2, 'site-reviews'), 2)), |
|
| 37 | - '1' => esc_html(sprintf(_n('%s star', '%s stars', 1, 'site-reviews'), 1)), |
|
| 38 | - '0' => esc_html(__('Unrated', 'site-reviews')), |
|
| 39 | - ], |
|
| 40 | - 'tooltip' => __('What is the minimum rating to display (default: 1 star)?', 'site-reviews'), |
|
| 41 | - 'type' => 'listbox', |
|
| 42 | - ], [ |
|
| 43 | - 'label' => esc_html__('Pagination', 'site-reviews'), |
|
| 44 | - 'name' => 'pagination', |
|
| 45 | - 'options' => [ |
|
| 46 | - 'true' => esc_html__('Enable', 'site-reviews'), |
|
| 47 | - 'ajax' => esc_html__('Enable (using ajax)', 'site-reviews'), |
|
| 48 | - 'false' => esc_html__('Disable', 'site-reviews'), |
|
| 49 | - ], |
|
| 50 | - 'tooltip' => __('When using pagination this shortcode can only be used once on a page. (default: disable)', 'site-reviews'), |
|
| 51 | - 'type' => 'listbox', |
|
| 52 | - ], |
|
| 53 | - $this->getTypes(__('Which type of review would you like to display?', 'site-reviews')), |
|
| 54 | - $this->getCategories(__('Limit reviews to this category.', 'site-reviews')), |
|
| 55 | - [ |
|
| 56 | - 'label' => esc_html__('Assigned To', 'site-reviews'), |
|
| 57 | - 'name' => 'assigned_to', |
|
| 58 | - 'tooltip' => __('Limit reviews to those assigned to this post ID (separate multiple IDs with a comma). You can also enter "post_id" to use the ID of the current page, or "parent_id" to use the ID of the parent page.', 'site-reviews'), |
|
| 59 | - 'type' => 'textbox', |
|
| 60 | - ], [ |
|
| 61 | - 'label' => esc_html__('Schema', 'site-reviews'), |
|
| 62 | - 'name' => 'schema', |
|
| 63 | - 'options' => [ |
|
| 64 | - 'true' => esc_html__('Enable rich snippets', 'site-reviews'), |
|
| 65 | - 'false' => esc_html__('Disable rich snippets', 'site-reviews'), |
|
| 66 | - ], |
|
| 67 | - 'tooltip' => __('Rich snippets are disabled by default.', 'site-reviews'), |
|
| 68 | - 'type' => 'listbox', |
|
| 69 | - ], [ |
|
| 70 | - 'label' => esc_html__('Classes', 'site-reviews'), |
|
| 71 | - 'name' => 'class', |
|
| 72 | - 'tooltip' => __('Add custom CSS classes to the shortcode.', 'site-reviews'), |
|
| 73 | - 'type' => 'textbox', |
|
| 74 | - ], [ |
|
| 75 | - 'columns' => 2, |
|
| 76 | - 'items' => $this->getHideOptions(), |
|
| 77 | - 'label' => esc_html__('Hide', 'site-reviews'), |
|
| 78 | - 'layout' => 'grid', |
|
| 79 | - 'spacing' => 5, |
|
| 80 | - 'type' => 'container', |
|
| 81 | - ], [ |
|
| 82 | - 'hidden' => true, |
|
| 83 | - 'name' => 'id', |
|
| 84 | - 'type' => 'textbox', |
|
| 85 | - ], ]; |
|
| 86 | - } |
|
| 7 | + /** |
|
| 8 | + * @return array |
|
| 9 | + */ |
|
| 10 | + public function fields() |
|
| 11 | + { |
|
| 12 | + return [[ |
|
| 13 | + 'html' => sprintf('<p class="strong">%s</p>', esc_html__('All settings are optional.', 'site-reviews')), |
|
| 14 | + 'minWidth' => 320, |
|
| 15 | + 'type' => 'container', |
|
| 16 | + ], [ |
|
| 17 | + 'label' => esc_html__('Title', 'site-reviews'), |
|
| 18 | + 'name' => 'title', |
|
| 19 | + 'tooltip' => __('Enter a custom shortcode heading.', 'site-reviews'), |
|
| 20 | + 'type' => 'textbox', |
|
| 21 | + ], [ |
|
| 22 | + 'label' => esc_html__('Display', 'site-reviews'), |
|
| 23 | + 'maxLength' => 5, |
|
| 24 | + 'name' => 'display', |
|
| 25 | + 'size' => 3, |
|
| 26 | + 'text' => '10', |
|
| 27 | + 'tooltip' => __('How many reviews would you like to display (default: 10)?', 'site-reviews'), |
|
| 28 | + 'type' => 'textbox', |
|
| 29 | + ], [ |
|
| 30 | + 'label' => esc_html__('Rating', 'site-reviews'), |
|
| 31 | + 'name' => 'rating', |
|
| 32 | + 'options' => [ |
|
| 33 | + '5' => esc_html(sprintf(_n('%s star', '%s stars', 5, 'site-reviews'), 5)), |
|
| 34 | + '4' => esc_html(sprintf(_n('%s star', '%s stars', 4, 'site-reviews'), 4)), |
|
| 35 | + '3' => esc_html(sprintf(_n('%s star', '%s stars', 3, 'site-reviews'), 3)), |
|
| 36 | + '2' => esc_html(sprintf(_n('%s star', '%s stars', 2, 'site-reviews'), 2)), |
|
| 37 | + '1' => esc_html(sprintf(_n('%s star', '%s stars', 1, 'site-reviews'), 1)), |
|
| 38 | + '0' => esc_html(__('Unrated', 'site-reviews')), |
|
| 39 | + ], |
|
| 40 | + 'tooltip' => __('What is the minimum rating to display (default: 1 star)?', 'site-reviews'), |
|
| 41 | + 'type' => 'listbox', |
|
| 42 | + ], [ |
|
| 43 | + 'label' => esc_html__('Pagination', 'site-reviews'), |
|
| 44 | + 'name' => 'pagination', |
|
| 45 | + 'options' => [ |
|
| 46 | + 'true' => esc_html__('Enable', 'site-reviews'), |
|
| 47 | + 'ajax' => esc_html__('Enable (using ajax)', 'site-reviews'), |
|
| 48 | + 'false' => esc_html__('Disable', 'site-reviews'), |
|
| 49 | + ], |
|
| 50 | + 'tooltip' => __('When using pagination this shortcode can only be used once on a page. (default: disable)', 'site-reviews'), |
|
| 51 | + 'type' => 'listbox', |
|
| 52 | + ], |
|
| 53 | + $this->getTypes(__('Which type of review would you like to display?', 'site-reviews')), |
|
| 54 | + $this->getCategories(__('Limit reviews to this category.', 'site-reviews')), |
|
| 55 | + [ |
|
| 56 | + 'label' => esc_html__('Assigned To', 'site-reviews'), |
|
| 57 | + 'name' => 'assigned_to', |
|
| 58 | + 'tooltip' => __('Limit reviews to those assigned to this post ID (separate multiple IDs with a comma). You can also enter "post_id" to use the ID of the current page, or "parent_id" to use the ID of the parent page.', 'site-reviews'), |
|
| 59 | + 'type' => 'textbox', |
|
| 60 | + ], [ |
|
| 61 | + 'label' => esc_html__('Schema', 'site-reviews'), |
|
| 62 | + 'name' => 'schema', |
|
| 63 | + 'options' => [ |
|
| 64 | + 'true' => esc_html__('Enable rich snippets', 'site-reviews'), |
|
| 65 | + 'false' => esc_html__('Disable rich snippets', 'site-reviews'), |
|
| 66 | + ], |
|
| 67 | + 'tooltip' => __('Rich snippets are disabled by default.', 'site-reviews'), |
|
| 68 | + 'type' => 'listbox', |
|
| 69 | + ], [ |
|
| 70 | + 'label' => esc_html__('Classes', 'site-reviews'), |
|
| 71 | + 'name' => 'class', |
|
| 72 | + 'tooltip' => __('Add custom CSS classes to the shortcode.', 'site-reviews'), |
|
| 73 | + 'type' => 'textbox', |
|
| 74 | + ], [ |
|
| 75 | + 'columns' => 2, |
|
| 76 | + 'items' => $this->getHideOptions(), |
|
| 77 | + 'label' => esc_html__('Hide', 'site-reviews'), |
|
| 78 | + 'layout' => 'grid', |
|
| 79 | + 'spacing' => 5, |
|
| 80 | + 'type' => 'container', |
|
| 81 | + ], [ |
|
| 82 | + 'hidden' => true, |
|
| 83 | + 'name' => 'id', |
|
| 84 | + 'type' => 'textbox', |
|
| 85 | + ], ]; |
|
| 86 | + } |
|
| 87 | 87 | } |
@@ -10,71 +10,71 @@ |
||
| 10 | 10 | public function fields() |
| 11 | 11 | { |
| 12 | 12 | return [[ |
| 13 | - 'html' => sprintf('<p class="strong">%s</p>', esc_html__('All settings are optional.', 'site-reviews')), |
|
| 13 | + 'html' => sprintf( '<p class="strong">%s</p>', esc_html__( 'All settings are optional.', 'site-reviews' ) ), |
|
| 14 | 14 | 'minWidth' => 320, |
| 15 | 15 | 'type' => 'container', |
| 16 | 16 | ], [ |
| 17 | - 'label' => esc_html__('Title', 'site-reviews'), |
|
| 17 | + 'label' => esc_html__( 'Title', 'site-reviews' ), |
|
| 18 | 18 | 'name' => 'title', |
| 19 | - 'tooltip' => __('Enter a custom shortcode heading.', 'site-reviews'), |
|
| 19 | + 'tooltip' => __( 'Enter a custom shortcode heading.', 'site-reviews' ), |
|
| 20 | 20 | 'type' => 'textbox', |
| 21 | 21 | ], [ |
| 22 | - 'label' => esc_html__('Display', 'site-reviews'), |
|
| 22 | + 'label' => esc_html__( 'Display', 'site-reviews' ), |
|
| 23 | 23 | 'maxLength' => 5, |
| 24 | 24 | 'name' => 'display', |
| 25 | 25 | 'size' => 3, |
| 26 | 26 | 'text' => '10', |
| 27 | - 'tooltip' => __('How many reviews would you like to display (default: 10)?', 'site-reviews'), |
|
| 27 | + 'tooltip' => __( 'How many reviews would you like to display (default: 10)?', 'site-reviews' ), |
|
| 28 | 28 | 'type' => 'textbox', |
| 29 | 29 | ], [ |
| 30 | - 'label' => esc_html__('Rating', 'site-reviews'), |
|
| 30 | + 'label' => esc_html__( 'Rating', 'site-reviews' ), |
|
| 31 | 31 | 'name' => 'rating', |
| 32 | 32 | 'options' => [ |
| 33 | - '5' => esc_html(sprintf(_n('%s star', '%s stars', 5, 'site-reviews'), 5)), |
|
| 34 | - '4' => esc_html(sprintf(_n('%s star', '%s stars', 4, 'site-reviews'), 4)), |
|
| 35 | - '3' => esc_html(sprintf(_n('%s star', '%s stars', 3, 'site-reviews'), 3)), |
|
| 36 | - '2' => esc_html(sprintf(_n('%s star', '%s stars', 2, 'site-reviews'), 2)), |
|
| 37 | - '1' => esc_html(sprintf(_n('%s star', '%s stars', 1, 'site-reviews'), 1)), |
|
| 38 | - '0' => esc_html(__('Unrated', 'site-reviews')), |
|
| 33 | + '5' => esc_html( sprintf( _n( '%s star', '%s stars', 5, 'site-reviews' ), 5 ) ), |
|
| 34 | + '4' => esc_html( sprintf( _n( '%s star', '%s stars', 4, 'site-reviews' ), 4 ) ), |
|
| 35 | + '3' => esc_html( sprintf( _n( '%s star', '%s stars', 3, 'site-reviews' ), 3 ) ), |
|
| 36 | + '2' => esc_html( sprintf( _n( '%s star', '%s stars', 2, 'site-reviews' ), 2 ) ), |
|
| 37 | + '1' => esc_html( sprintf( _n( '%s star', '%s stars', 1, 'site-reviews' ), 1 ) ), |
|
| 38 | + '0' => esc_html( __( 'Unrated', 'site-reviews' ) ), |
|
| 39 | 39 | ], |
| 40 | - 'tooltip' => __('What is the minimum rating to display (default: 1 star)?', 'site-reviews'), |
|
| 40 | + 'tooltip' => __( 'What is the minimum rating to display (default: 1 star)?', 'site-reviews' ), |
|
| 41 | 41 | 'type' => 'listbox', |
| 42 | 42 | ], [ |
| 43 | - 'label' => esc_html__('Pagination', 'site-reviews'), |
|
| 43 | + 'label' => esc_html__( 'Pagination', 'site-reviews' ), |
|
| 44 | 44 | 'name' => 'pagination', |
| 45 | 45 | 'options' => [ |
| 46 | - 'true' => esc_html__('Enable', 'site-reviews'), |
|
| 47 | - 'ajax' => esc_html__('Enable (using ajax)', 'site-reviews'), |
|
| 48 | - 'false' => esc_html__('Disable', 'site-reviews'), |
|
| 46 | + 'true' => esc_html__( 'Enable', 'site-reviews' ), |
|
| 47 | + 'ajax' => esc_html__( 'Enable (using ajax)', 'site-reviews' ), |
|
| 48 | + 'false' => esc_html__( 'Disable', 'site-reviews' ), |
|
| 49 | 49 | ], |
| 50 | - 'tooltip' => __('When using pagination this shortcode can only be used once on a page. (default: disable)', 'site-reviews'), |
|
| 50 | + 'tooltip' => __( 'When using pagination this shortcode can only be used once on a page. (default: disable)', 'site-reviews' ), |
|
| 51 | 51 | 'type' => 'listbox', |
| 52 | 52 | ], |
| 53 | - $this->getTypes(__('Which type of review would you like to display?', 'site-reviews')), |
|
| 54 | - $this->getCategories(__('Limit reviews to this category.', 'site-reviews')), |
|
| 53 | + $this->getTypes( __( 'Which type of review would you like to display?', 'site-reviews' ) ), |
|
| 54 | + $this->getCategories( __( 'Limit reviews to this category.', 'site-reviews' ) ), |
|
| 55 | 55 | [ |
| 56 | - 'label' => esc_html__('Assigned To', 'site-reviews'), |
|
| 56 | + 'label' => esc_html__( 'Assigned To', 'site-reviews' ), |
|
| 57 | 57 | 'name' => 'assigned_to', |
| 58 | - 'tooltip' => __('Limit reviews to those assigned to this post ID (separate multiple IDs with a comma). You can also enter "post_id" to use the ID of the current page, or "parent_id" to use the ID of the parent page.', 'site-reviews'), |
|
| 58 | + 'tooltip' => __( 'Limit reviews to those assigned to this post ID (separate multiple IDs with a comma). You can also enter "post_id" to use the ID of the current page, or "parent_id" to use the ID of the parent page.', 'site-reviews' ), |
|
| 59 | 59 | 'type' => 'textbox', |
| 60 | 60 | ], [ |
| 61 | - 'label' => esc_html__('Schema', 'site-reviews'), |
|
| 61 | + 'label' => esc_html__( 'Schema', 'site-reviews' ), |
|
| 62 | 62 | 'name' => 'schema', |
| 63 | 63 | 'options' => [ |
| 64 | - 'true' => esc_html__('Enable rich snippets', 'site-reviews'), |
|
| 65 | - 'false' => esc_html__('Disable rich snippets', 'site-reviews'), |
|
| 64 | + 'true' => esc_html__( 'Enable rich snippets', 'site-reviews' ), |
|
| 65 | + 'false' => esc_html__( 'Disable rich snippets', 'site-reviews' ), |
|
| 66 | 66 | ], |
| 67 | - 'tooltip' => __('Rich snippets are disabled by default.', 'site-reviews'), |
|
| 67 | + 'tooltip' => __( 'Rich snippets are disabled by default.', 'site-reviews' ), |
|
| 68 | 68 | 'type' => 'listbox', |
| 69 | 69 | ], [ |
| 70 | - 'label' => esc_html__('Classes', 'site-reviews'), |
|
| 70 | + 'label' => esc_html__( 'Classes', 'site-reviews' ), |
|
| 71 | 71 | 'name' => 'class', |
| 72 | - 'tooltip' => __('Add custom CSS classes to the shortcode.', 'site-reviews'), |
|
| 72 | + 'tooltip' => __( 'Add custom CSS classes to the shortcode.', 'site-reviews' ), |
|
| 73 | 73 | 'type' => 'textbox', |
| 74 | 74 | ], [ |
| 75 | 75 | 'columns' => 2, |
| 76 | 76 | 'items' => $this->getHideOptions(), |
| 77 | - 'label' => esc_html__('Hide', 'site-reviews'), |
|
| 77 | + 'label' => esc_html__( 'Hide', 'site-reviews' ), |
|
| 78 | 78 | 'layout' => 'grid', |
| 79 | 79 | 'spacing' => 5, |
| 80 | 80 | 'type' => 'container', |
@@ -8,97 +8,97 @@ |
||
| 8 | 8 | |
| 9 | 9 | class WelcomeController extends Controller |
| 10 | 10 | { |
| 11 | - /** |
|
| 12 | - * @return array |
|
| 13 | - * @filter plugin_action_links_site-reviews/site-reviews.php |
|
| 14 | - */ |
|
| 15 | - public function filterActionLinks(array $links) |
|
| 16 | - { |
|
| 17 | - $links['welcome'] = glsr(Builder::class)->a(__('About', 'site-reviews'), [ |
|
| 18 | - 'href' => admin_url('edit.php?post_type='.Application::POST_TYPE.'&page=welcome'), |
|
| 19 | - ]); |
|
| 20 | - return $links; |
|
| 21 | - } |
|
| 11 | + /** |
|
| 12 | + * @return array |
|
| 13 | + * @filter plugin_action_links_site-reviews/site-reviews.php |
|
| 14 | + */ |
|
| 15 | + public function filterActionLinks(array $links) |
|
| 16 | + { |
|
| 17 | + $links['welcome'] = glsr(Builder::class)->a(__('About', 'site-reviews'), [ |
|
| 18 | + 'href' => admin_url('edit.php?post_type='.Application::POST_TYPE.'&page=welcome'), |
|
| 19 | + ]); |
|
| 20 | + return $links; |
|
| 21 | + } |
|
| 22 | 22 | |
| 23 | - /** |
|
| 24 | - * @return string |
|
| 25 | - * @filter admin_title |
|
| 26 | - */ |
|
| 27 | - public function filterAdminTitle($title) |
|
| 28 | - { |
|
| 29 | - return Application::POST_TYPE.'_page_welcome' == glsr_current_screen()->id |
|
| 30 | - ? sprintf(__('Welcome to %s — WordPress', 'site-reviews'), glsr()->name) |
|
| 31 | - : $title; |
|
| 32 | - } |
|
| 23 | + /** |
|
| 24 | + * @return string |
|
| 25 | + * @filter admin_title |
|
| 26 | + */ |
|
| 27 | + public function filterAdminTitle($title) |
|
| 28 | + { |
|
| 29 | + return Application::POST_TYPE.'_page_welcome' == glsr_current_screen()->id |
|
| 30 | + ? sprintf(__('Welcome to %s — WordPress', 'site-reviews'), glsr()->name) |
|
| 31 | + : $title; |
|
| 32 | + } |
|
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * @param string $text |
|
| 36 | - * @return string |
|
| 37 | - * @filter admin_footer_text |
|
| 38 | - */ |
|
| 39 | - public function filterFooterText($text) |
|
| 40 | - { |
|
| 41 | - if (Application::POST_TYPE.'_page_welcome' != glsr_current_screen()->id) { |
|
| 42 | - return $text; |
|
| 43 | - } |
|
| 44 | - $url = 'https://wordpress.org/support/view/plugin-reviews/site-reviews?filter=5#new-post'; |
|
| 45 | - return wp_kses_post(sprintf( |
|
| 46 | - __('Please rate %s on %s and help us spread the word. Thank you so much!', 'site-reviews'), |
|
| 47 | - '<strong>'.glsr()->name.'</strong> <a href="'.$url.'" target="_blank">★★★★★</a>', |
|
| 48 | - '<a href="'.$url.'" target="_blank">wordpress.org</a>' |
|
| 49 | - )); |
|
| 50 | - } |
|
| 34 | + /** |
|
| 35 | + * @param string $text |
|
| 36 | + * @return string |
|
| 37 | + * @filter admin_footer_text |
|
| 38 | + */ |
|
| 39 | + public function filterFooterText($text) |
|
| 40 | + { |
|
| 41 | + if (Application::POST_TYPE.'_page_welcome' != glsr_current_screen()->id) { |
|
| 42 | + return $text; |
|
| 43 | + } |
|
| 44 | + $url = 'https://wordpress.org/support/view/plugin-reviews/site-reviews?filter=5#new-post'; |
|
| 45 | + return wp_kses_post(sprintf( |
|
| 46 | + __('Please rate %s on %s and help us spread the word. Thank you so much!', 'site-reviews'), |
|
| 47 | + '<strong>'.glsr()->name.'</strong> <a href="'.$url.'" target="_blank">★★★★★</a>', |
|
| 48 | + '<a href="'.$url.'" target="_blank">wordpress.org</a>' |
|
| 49 | + )); |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - /** |
|
| 53 | - * @param string $plugin |
|
| 54 | - * @param bool $isNetworkActivation |
|
| 55 | - * @return void |
|
| 56 | - * @action activated_plugin |
|
| 57 | - */ |
|
| 58 | - public function redirectOnActivation($plugin, $isNetworkActivation) |
|
| 59 | - { |
|
| 60 | - if (!$isNetworkActivation |
|
| 61 | - && 'cli' !== php_sapi_name() |
|
| 62 | - && $plugin === plugin_basename(glsr()->file)) { |
|
| 63 | - wp_safe_redirect(admin_url('edit.php?post_type='.Application::POST_TYPE.'&page=welcome')); |
|
| 64 | - exit; |
|
| 65 | - } |
|
| 66 | - } |
|
| 52 | + /** |
|
| 53 | + * @param string $plugin |
|
| 54 | + * @param bool $isNetworkActivation |
|
| 55 | + * @return void |
|
| 56 | + * @action activated_plugin |
|
| 57 | + */ |
|
| 58 | + public function redirectOnActivation($plugin, $isNetworkActivation) |
|
| 59 | + { |
|
| 60 | + if (!$isNetworkActivation |
|
| 61 | + && 'cli' !== php_sapi_name() |
|
| 62 | + && $plugin === plugin_basename(glsr()->file)) { |
|
| 63 | + wp_safe_redirect(admin_url('edit.php?post_type='.Application::POST_TYPE.'&page=welcome')); |
|
| 64 | + exit; |
|
| 65 | + } |
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | - /** |
|
| 69 | - * @return void |
|
| 70 | - * @action admin_menu |
|
| 71 | - */ |
|
| 72 | - public function registerPage() |
|
| 73 | - { |
|
| 74 | - add_submenu_page('edit.php?post_type='.Application::POST_TYPE, |
|
| 75 | - sprintf(__('Welcome to %s', 'site-reviews'), glsr()->name), |
|
| 76 | - glsr()->name, |
|
| 77 | - glsr()->getPermission('welcome'), |
|
| 78 | - 'welcome', |
|
| 79 | - [$this, 'renderPage'] |
|
| 80 | - ); |
|
| 81 | - remove_submenu_page('edit.php?post_type='.Application::POST_TYPE, 'welcome'); |
|
| 82 | - } |
|
| 68 | + /** |
|
| 69 | + * @return void |
|
| 70 | + * @action admin_menu |
|
| 71 | + */ |
|
| 72 | + public function registerPage() |
|
| 73 | + { |
|
| 74 | + add_submenu_page('edit.php?post_type='.Application::POST_TYPE, |
|
| 75 | + sprintf(__('Welcome to %s', 'site-reviews'), glsr()->name), |
|
| 76 | + glsr()->name, |
|
| 77 | + glsr()->getPermission('welcome'), |
|
| 78 | + 'welcome', |
|
| 79 | + [$this, 'renderPage'] |
|
| 80 | + ); |
|
| 81 | + remove_submenu_page('edit.php?post_type='.Application::POST_TYPE, 'welcome'); |
|
| 82 | + } |
|
| 83 | 83 | |
| 84 | - /** |
|
| 85 | - * @return void |
|
| 86 | - * @see $this->registerPage() |
|
| 87 | - * @callback add_submenu_page |
|
| 88 | - */ |
|
| 89 | - public function renderPage() |
|
| 90 | - { |
|
| 91 | - $tabs = apply_filters('site-reviews/addon/welcome/tabs', [ |
|
| 92 | - 'getting-started' => __('Getting Started', 'site-reviews'), |
|
| 93 | - 'whatsnew' => __('What\'s New', 'site-reviews'), |
|
| 94 | - 'upgrade-guide' => __('Upgrade Guide', 'site-reviews'), |
|
| 95 | - 'support' => __('Support', 'site-reviews'), |
|
| 96 | - ]); |
|
| 97 | - glsr()->render('pages/welcome/index', [ |
|
| 98 | - 'data' => ['context' => []], |
|
| 99 | - 'http_referer' => (string) wp_get_referer(), |
|
| 100 | - 'tabs' => $tabs, |
|
| 101 | - 'template' => glsr(Template::class), |
|
| 102 | - ]); |
|
| 103 | - } |
|
| 84 | + /** |
|
| 85 | + * @return void |
|
| 86 | + * @see $this->registerPage() |
|
| 87 | + * @callback add_submenu_page |
|
| 88 | + */ |
|
| 89 | + public function renderPage() |
|
| 90 | + { |
|
| 91 | + $tabs = apply_filters('site-reviews/addon/welcome/tabs', [ |
|
| 92 | + 'getting-started' => __('Getting Started', 'site-reviews'), |
|
| 93 | + 'whatsnew' => __('What\'s New', 'site-reviews'), |
|
| 94 | + 'upgrade-guide' => __('Upgrade Guide', 'site-reviews'), |
|
| 95 | + 'support' => __('Support', 'site-reviews'), |
|
| 96 | + ]); |
|
| 97 | + glsr()->render('pages/welcome/index', [ |
|
| 98 | + 'data' => ['context' => []], |
|
| 99 | + 'http_referer' => (string) wp_get_referer(), |
|
| 100 | + 'tabs' => $tabs, |
|
| 101 | + 'template' => glsr(Template::class), |
|
| 102 | + ]); |
|
| 103 | + } |
|
| 104 | 104 | } |
@@ -12,11 +12,11 @@ discard block |
||
| 12 | 12 | * @return array |
| 13 | 13 | * @filter plugin_action_links_site-reviews/site-reviews.php |
| 14 | 14 | */ |
| 15 | - public function filterActionLinks(array $links) |
|
| 15 | + public function filterActionLinks( array $links ) |
|
| 16 | 16 | { |
| 17 | - $links['welcome'] = glsr(Builder::class)->a(__('About', 'site-reviews'), [ |
|
| 18 | - 'href' => admin_url('edit.php?post_type='.Application::POST_TYPE.'&page=welcome'), |
|
| 19 | - ]); |
|
| 17 | + $links['welcome'] = glsr( Builder::class )->a( __( 'About', 'site-reviews' ), [ |
|
| 18 | + 'href' => admin_url( 'edit.php?post_type='.Application::POST_TYPE.'&page=welcome' ), |
|
| 19 | + ] ); |
|
| 20 | 20 | return $links; |
| 21 | 21 | } |
| 22 | 22 | |
@@ -24,10 +24,10 @@ discard block |
||
| 24 | 24 | * @return string |
| 25 | 25 | * @filter admin_title |
| 26 | 26 | */ |
| 27 | - public function filterAdminTitle($title) |
|
| 27 | + public function filterAdminTitle( $title ) |
|
| 28 | 28 | { |
| 29 | 29 | return Application::POST_TYPE.'_page_welcome' == glsr_current_screen()->id |
| 30 | - ? sprintf(__('Welcome to %s — WordPress', 'site-reviews'), glsr()->name) |
|
| 30 | + ? sprintf( __( 'Welcome to %s — WordPress', 'site-reviews' ), glsr()->name ) |
|
| 31 | 31 | : $title; |
| 32 | 32 | } |
| 33 | 33 | |
@@ -36,17 +36,17 @@ discard block |
||
| 36 | 36 | * @return string |
| 37 | 37 | * @filter admin_footer_text |
| 38 | 38 | */ |
| 39 | - public function filterFooterText($text) |
|
| 39 | + public function filterFooterText( $text ) |
|
| 40 | 40 | { |
| 41 | - if (Application::POST_TYPE.'_page_welcome' != glsr_current_screen()->id) { |
|
| 41 | + if( Application::POST_TYPE.'_page_welcome' != glsr_current_screen()->id ) { |
|
| 42 | 42 | return $text; |
| 43 | 43 | } |
| 44 | 44 | $url = 'https://wordpress.org/support/view/plugin-reviews/site-reviews?filter=5#new-post'; |
| 45 | - return wp_kses_post(sprintf( |
|
| 46 | - __('Please rate %s on %s and help us spread the word. Thank you so much!', 'site-reviews'), |
|
| 45 | + return wp_kses_post( sprintf( |
|
| 46 | + __( 'Please rate %s on %s and help us spread the word. Thank you so much!', 'site-reviews' ), |
|
| 47 | 47 | '<strong>'.glsr()->name.'</strong> <a href="'.$url.'" target="_blank">★★★★★</a>', |
| 48 | 48 | '<a href="'.$url.'" target="_blank">wordpress.org</a>' |
| 49 | - )); |
|
| 49 | + ) ); |
|
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | /** |
@@ -55,12 +55,12 @@ discard block |
||
| 55 | 55 | * @return void |
| 56 | 56 | * @action activated_plugin |
| 57 | 57 | */ |
| 58 | - public function redirectOnActivation($plugin, $isNetworkActivation) |
|
| 58 | + public function redirectOnActivation( $plugin, $isNetworkActivation ) |
|
| 59 | 59 | { |
| 60 | - if (!$isNetworkActivation |
|
| 60 | + if( !$isNetworkActivation |
|
| 61 | 61 | && 'cli' !== php_sapi_name() |
| 62 | - && $plugin === plugin_basename(glsr()->file)) { |
|
| 63 | - wp_safe_redirect(admin_url('edit.php?post_type='.Application::POST_TYPE.'&page=welcome')); |
|
| 62 | + && $plugin === plugin_basename( glsr()->file ) ) { |
|
| 63 | + wp_safe_redirect( admin_url( 'edit.php?post_type='.Application::POST_TYPE.'&page=welcome' ) ); |
|
| 64 | 64 | exit; |
| 65 | 65 | } |
| 66 | 66 | } |
@@ -71,14 +71,14 @@ discard block |
||
| 71 | 71 | */ |
| 72 | 72 | public function registerPage() |
| 73 | 73 | { |
| 74 | - add_submenu_page('edit.php?post_type='.Application::POST_TYPE, |
|
| 75 | - sprintf(__('Welcome to %s', 'site-reviews'), glsr()->name), |
|
| 74 | + add_submenu_page( 'edit.php?post_type='.Application::POST_TYPE, |
|
| 75 | + sprintf( __( 'Welcome to %s', 'site-reviews' ), glsr()->name ), |
|
| 76 | 76 | glsr()->name, |
| 77 | - glsr()->getPermission('welcome'), |
|
| 77 | + glsr()->getPermission( 'welcome' ), |
|
| 78 | 78 | 'welcome', |
| 79 | 79 | [$this, 'renderPage'] |
| 80 | 80 | ); |
| 81 | - remove_submenu_page('edit.php?post_type='.Application::POST_TYPE, 'welcome'); |
|
| 81 | + remove_submenu_page( 'edit.php?post_type='.Application::POST_TYPE, 'welcome' ); |
|
| 82 | 82 | } |
| 83 | 83 | |
| 84 | 84 | /** |
@@ -88,17 +88,17 @@ discard block |
||
| 88 | 88 | */ |
| 89 | 89 | public function renderPage() |
| 90 | 90 | { |
| 91 | - $tabs = apply_filters('site-reviews/addon/welcome/tabs', [ |
|
| 92 | - 'getting-started' => __('Getting Started', 'site-reviews'), |
|
| 93 | - 'whatsnew' => __('What\'s New', 'site-reviews'), |
|
| 94 | - 'upgrade-guide' => __('Upgrade Guide', 'site-reviews'), |
|
| 95 | - 'support' => __('Support', 'site-reviews'), |
|
| 96 | - ]); |
|
| 97 | - glsr()->render('pages/welcome/index', [ |
|
| 91 | + $tabs = apply_filters( 'site-reviews/addon/welcome/tabs', [ |
|
| 92 | + 'getting-started' => __( 'Getting Started', 'site-reviews' ), |
|
| 93 | + 'whatsnew' => __( 'What\'s New', 'site-reviews' ), |
|
| 94 | + 'upgrade-guide' => __( 'Upgrade Guide', 'site-reviews' ), |
|
| 95 | + 'support' => __( 'Support', 'site-reviews' ), |
|
| 96 | + ] ); |
|
| 97 | + glsr()->render( 'pages/welcome/index', [ |
|
| 98 | 98 | 'data' => ['context' => []], |
| 99 | - 'http_referer' => (string) wp_get_referer(), |
|
| 99 | + 'http_referer' => (string)wp_get_referer(), |
|
| 100 | 100 | 'tabs' => $tabs, |
| 101 | - 'template' => glsr(Template::class), |
|
| 102 | - ]); |
|
| 101 | + 'template' => glsr( Template::class ), |
|
| 102 | + ] ); |
|
| 103 | 103 | } |
| 104 | 104 | } |
@@ -6,41 +6,41 @@ |
||
| 6 | 6 | |
| 7 | 7 | class SiteReviewsDefaults extends Defaults |
| 8 | 8 | { |
| 9 | - /** |
|
| 10 | - * @var array |
|
| 11 | - */ |
|
| 12 | - protected $guarded = [ |
|
| 13 | - 'fallback', |
|
| 14 | - 'title', |
|
| 15 | - ]; |
|
| 9 | + /** |
|
| 10 | + * @var array |
|
| 11 | + */ |
|
| 12 | + protected $guarded = [ |
|
| 13 | + 'fallback', |
|
| 14 | + 'title', |
|
| 15 | + ]; |
|
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * @var array |
|
| 19 | - */ |
|
| 20 | - protected $mapped = [ |
|
| 21 | - 'count' => 'display', // @deprecated since v4.1.0 |
|
| 22 | - 'per_page' => 'display', |
|
| 23 | - ]; |
|
| 17 | + /** |
|
| 18 | + * @var array |
|
| 19 | + */ |
|
| 20 | + protected $mapped = [ |
|
| 21 | + 'count' => 'display', // @deprecated since v4.1.0 |
|
| 22 | + 'per_page' => 'display', |
|
| 23 | + ]; |
|
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * @return array |
|
| 27 | - */ |
|
| 28 | - protected function defaults() |
|
| 29 | - { |
|
| 30 | - return [ |
|
| 31 | - 'assigned_to' => '', |
|
| 32 | - 'category' => '', |
|
| 33 | - 'class' => '', |
|
| 34 | - 'display' => 5, |
|
| 35 | - 'fallback' => '', |
|
| 36 | - 'hide' => [], |
|
| 37 | - 'id' => '', |
|
| 38 | - 'offset' => '', |
|
| 39 | - 'pagination' => false, |
|
| 40 | - 'rating' => 0, |
|
| 41 | - 'schema' => false, |
|
| 42 | - 'title' => '', |
|
| 43 | - 'type' => 'local', |
|
| 44 | - ]; |
|
| 45 | - } |
|
| 25 | + /** |
|
| 26 | + * @return array |
|
| 27 | + */ |
|
| 28 | + protected function defaults() |
|
| 29 | + { |
|
| 30 | + return [ |
|
| 31 | + 'assigned_to' => '', |
|
| 32 | + 'category' => '', |
|
| 33 | + 'class' => '', |
|
| 34 | + 'display' => 5, |
|
| 35 | + 'fallback' => '', |
|
| 36 | + 'hide' => [], |
|
| 37 | + 'id' => '', |
|
| 38 | + 'offset' => '', |
|
| 39 | + 'pagination' => false, |
|
| 40 | + 'rating' => 0, |
|
| 41 | + 'schema' => false, |
|
| 42 | + 'title' => '', |
|
| 43 | + 'type' => 'local', |
|
| 44 | + ]; |
|
| 45 | + } |
|
| 46 | 46 | } |
@@ -6,31 +6,31 @@ |
||
| 6 | 6 | |
| 7 | 7 | class ReviewsDefaults extends Defaults |
| 8 | 8 | { |
| 9 | - /** |
|
| 10 | - * @var array |
|
| 11 | - */ |
|
| 12 | - protected $mapped = [ |
|
| 13 | - 'count' => 'per_page', // @deprecated since v4.1.0 |
|
| 14 | - 'display' => 'per_page', |
|
| 15 | - ]; |
|
| 9 | + /** |
|
| 10 | + * @var array |
|
| 11 | + */ |
|
| 12 | + protected $mapped = [ |
|
| 13 | + 'count' => 'per_page', // @deprecated since v4.1.0 |
|
| 14 | + 'display' => 'per_page', |
|
| 15 | + ]; |
|
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * @return array |
|
| 19 | - */ |
|
| 20 | - protected function defaults() |
|
| 21 | - { |
|
| 22 | - return [ |
|
| 23 | - 'assigned_to' => '', |
|
| 24 | - 'category' => '', |
|
| 25 | - 'offset' => '', |
|
| 26 | - 'order' => 'DESC', |
|
| 27 | - 'orderby' => 'date', |
|
| 28 | - 'pagination' => false, |
|
| 29 | - 'per_page' => 10, |
|
| 30 | - 'post__in' => [], |
|
| 31 | - 'post__not_in' => [], |
|
| 32 | - 'rating' => '', |
|
| 33 | - 'type' => '', |
|
| 34 | - ]; |
|
| 35 | - } |
|
| 17 | + /** |
|
| 18 | + * @return array |
|
| 19 | + */ |
|
| 20 | + protected function defaults() |
|
| 21 | + { |
|
| 22 | + return [ |
|
| 23 | + 'assigned_to' => '', |
|
| 24 | + 'category' => '', |
|
| 25 | + 'offset' => '', |
|
| 26 | + 'order' => 'DESC', |
|
| 27 | + 'orderby' => 'date', |
|
| 28 | + 'pagination' => false, |
|
| 29 | + 'per_page' => 10, |
|
| 30 | + 'post__in' => [], |
|
| 31 | + 'post__not_in' => [], |
|
| 32 | + 'rating' => '', |
|
| 33 | + 'type' => '', |
|
| 34 | + ]; |
|
| 35 | + } |
|
| 36 | 36 | } |
@@ -8,137 +8,137 @@ |
||
| 8 | 8 | |
| 9 | 9 | abstract class DefaultsAbstract |
| 10 | 10 | { |
| 11 | - /** |
|
| 12 | - * @var array |
|
| 13 | - */ |
|
| 14 | - protected $callable = [ |
|
| 15 | - 'defaults', 'filter', 'merge', 'restrict', 'unguarded', |
|
| 16 | - ]; |
|
| 17 | - |
|
| 18 | - /** |
|
| 19 | - * @var array |
|
| 20 | - */ |
|
| 21 | - protected $guarded = []; |
|
| 22 | - |
|
| 23 | - /** |
|
| 24 | - * @var array |
|
| 25 | - */ |
|
| 26 | - protected $mapped = []; |
|
| 27 | - |
|
| 28 | - /** |
|
| 29 | - * @param string $name |
|
| 30 | - * @return void|array |
|
| 31 | - */ |
|
| 32 | - public function __call($name, array $args = []) |
|
| 33 | - { |
|
| 34 | - if (!method_exists($this, $name) || !in_array($name, $this->callable)) { |
|
| 35 | - return; |
|
| 36 | - } |
|
| 37 | - $args[0] = $this->mapKeys(Arr::get($args, 0, [])); |
|
| 38 | - $defaults = call_user_func_array([$this, $name], $args); |
|
| 39 | - $hookName = (new ReflectionClass($this))->getShortName(); |
|
| 40 | - $hookName = str_replace('Defaults', '', $hookName); |
|
| 41 | - $hookName = Str::dashCase($hookName); |
|
| 42 | - return apply_filters('site-reviews/defaults/'.$hookName, $defaults, $name); |
|
| 43 | - } |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * @return array |
|
| 47 | - */ |
|
| 48 | - abstract protected function defaults(); |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * @return array |
|
| 52 | - */ |
|
| 53 | - protected function filter(array $values = []) |
|
| 54 | - { |
|
| 55 | - return $this->normalize($this->merge(array_filter($values)), $values); |
|
| 56 | - } |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * @return string |
|
| 60 | - */ |
|
| 61 | - protected function filteredJson(array $values = []) |
|
| 62 | - { |
|
| 63 | - $defaults = $this->flattenArray( |
|
| 64 | - array_diff_key($this->defaults(), array_flip($this->guarded)) |
|
| 65 | - ); |
|
| 66 | - $values = $this->flattenArray( |
|
| 67 | - shortcode_atts($defaults, $values) |
|
| 68 | - ); |
|
| 69 | - $filtered = array_filter(array_diff_assoc($values, $defaults), function ($value) { |
|
| 70 | - return !$this->isEmpty($value); |
|
| 71 | - }); |
|
| 72 | - return json_encode($filtered, JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_TAG | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - /** |
|
| 76 | - * @return array |
|
| 77 | - */ |
|
| 78 | - protected function flattenArray(array $values) |
|
| 79 | - { |
|
| 80 | - array_walk($values, function (&$value) { |
|
| 81 | - if (!is_array($value)) { |
|
| 82 | - return; |
|
| 83 | - } |
|
| 84 | - $value = implode(',', $value); |
|
| 85 | - }); |
|
| 86 | - return $values; |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - /** |
|
| 90 | - * @param mixed $var |
|
| 91 | - * @return bool |
|
| 92 | - */ |
|
| 93 | - protected function isEmpty($var) |
|
| 94 | - { |
|
| 95 | - return !is_numeric($var) && !is_bool($var) && empty($var); |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - /** |
|
| 99 | - * @return array |
|
| 100 | - */ |
|
| 101 | - protected function mapKeys(array $args) |
|
| 102 | - { |
|
| 103 | - foreach ($this->mapped as $old => $new) { |
|
| 104 | - if (array_key_exists($old, $args)) { |
|
| 105 | - $args[$new] = $args[$old]; |
|
| 106 | - unset($args[$old]); |
|
| 107 | - } |
|
| 108 | - } |
|
| 109 | - return $args; |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - /** |
|
| 113 | - * @return array |
|
| 114 | - */ |
|
| 115 | - protected function merge(array $values = []) |
|
| 116 | - { |
|
| 117 | - return $this->normalize(wp_parse_args($values, $this->defaults()), $values); |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - /** |
|
| 121 | - * @return array |
|
| 122 | - */ |
|
| 123 | - protected function normalize(array $values, array $originalValues) |
|
| 124 | - { |
|
| 125 | - $values['json'] = $this->filteredJson($originalValues); |
|
| 126 | - return $values; |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - /** |
|
| 130 | - * @return array |
|
| 131 | - */ |
|
| 132 | - protected function restrict(array $values = []) |
|
| 133 | - { |
|
| 134 | - return $this->normalize(shortcode_atts($this->defaults(), $values), $values); |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - /** |
|
| 138 | - * @return array |
|
| 139 | - */ |
|
| 140 | - protected function unguarded() |
|
| 141 | - { |
|
| 142 | - return array_diff_key($this->defaults(), array_flip($this->guarded)); |
|
| 143 | - } |
|
| 11 | + /** |
|
| 12 | + * @var array |
|
| 13 | + */ |
|
| 14 | + protected $callable = [ |
|
| 15 | + 'defaults', 'filter', 'merge', 'restrict', 'unguarded', |
|
| 16 | + ]; |
|
| 17 | + |
|
| 18 | + /** |
|
| 19 | + * @var array |
|
| 20 | + */ |
|
| 21 | + protected $guarded = []; |
|
| 22 | + |
|
| 23 | + /** |
|
| 24 | + * @var array |
|
| 25 | + */ |
|
| 26 | + protected $mapped = []; |
|
| 27 | + |
|
| 28 | + /** |
|
| 29 | + * @param string $name |
|
| 30 | + * @return void|array |
|
| 31 | + */ |
|
| 32 | + public function __call($name, array $args = []) |
|
| 33 | + { |
|
| 34 | + if (!method_exists($this, $name) || !in_array($name, $this->callable)) { |
|
| 35 | + return; |
|
| 36 | + } |
|
| 37 | + $args[0] = $this->mapKeys(Arr::get($args, 0, [])); |
|
| 38 | + $defaults = call_user_func_array([$this, $name], $args); |
|
| 39 | + $hookName = (new ReflectionClass($this))->getShortName(); |
|
| 40 | + $hookName = str_replace('Defaults', '', $hookName); |
|
| 41 | + $hookName = Str::dashCase($hookName); |
|
| 42 | + return apply_filters('site-reviews/defaults/'.$hookName, $defaults, $name); |
|
| 43 | + } |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * @return array |
|
| 47 | + */ |
|
| 48 | + abstract protected function defaults(); |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * @return array |
|
| 52 | + */ |
|
| 53 | + protected function filter(array $values = []) |
|
| 54 | + { |
|
| 55 | + return $this->normalize($this->merge(array_filter($values)), $values); |
|
| 56 | + } |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * @return string |
|
| 60 | + */ |
|
| 61 | + protected function filteredJson(array $values = []) |
|
| 62 | + { |
|
| 63 | + $defaults = $this->flattenArray( |
|
| 64 | + array_diff_key($this->defaults(), array_flip($this->guarded)) |
|
| 65 | + ); |
|
| 66 | + $values = $this->flattenArray( |
|
| 67 | + shortcode_atts($defaults, $values) |
|
| 68 | + ); |
|
| 69 | + $filtered = array_filter(array_diff_assoc($values, $defaults), function ($value) { |
|
| 70 | + return !$this->isEmpty($value); |
|
| 71 | + }); |
|
| 72 | + return json_encode($filtered, JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_TAG | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + /** |
|
| 76 | + * @return array |
|
| 77 | + */ |
|
| 78 | + protected function flattenArray(array $values) |
|
| 79 | + { |
|
| 80 | + array_walk($values, function (&$value) { |
|
| 81 | + if (!is_array($value)) { |
|
| 82 | + return; |
|
| 83 | + } |
|
| 84 | + $value = implode(',', $value); |
|
| 85 | + }); |
|
| 86 | + return $values; |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + /** |
|
| 90 | + * @param mixed $var |
|
| 91 | + * @return bool |
|
| 92 | + */ |
|
| 93 | + protected function isEmpty($var) |
|
| 94 | + { |
|
| 95 | + return !is_numeric($var) && !is_bool($var) && empty($var); |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + /** |
|
| 99 | + * @return array |
|
| 100 | + */ |
|
| 101 | + protected function mapKeys(array $args) |
|
| 102 | + { |
|
| 103 | + foreach ($this->mapped as $old => $new) { |
|
| 104 | + if (array_key_exists($old, $args)) { |
|
| 105 | + $args[$new] = $args[$old]; |
|
| 106 | + unset($args[$old]); |
|
| 107 | + } |
|
| 108 | + } |
|
| 109 | + return $args; |
|
| 110 | + } |
|
| 111 | + |
|
| 112 | + /** |
|
| 113 | + * @return array |
|
| 114 | + */ |
|
| 115 | + protected function merge(array $values = []) |
|
| 116 | + { |
|
| 117 | + return $this->normalize(wp_parse_args($values, $this->defaults()), $values); |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + /** |
|
| 121 | + * @return array |
|
| 122 | + */ |
|
| 123 | + protected function normalize(array $values, array $originalValues) |
|
| 124 | + { |
|
| 125 | + $values['json'] = $this->filteredJson($originalValues); |
|
| 126 | + return $values; |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + /** |
|
| 130 | + * @return array |
|
| 131 | + */ |
|
| 132 | + protected function restrict(array $values = []) |
|
| 133 | + { |
|
| 134 | + return $this->normalize(shortcode_atts($this->defaults(), $values), $values); |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + /** |
|
| 138 | + * @return array |
|
| 139 | + */ |
|
| 140 | + protected function unguarded() |
|
| 141 | + { |
|
| 142 | + return array_diff_key($this->defaults(), array_flip($this->guarded)); |
|
| 143 | + } |
|
| 144 | 144 | } |
@@ -29,17 +29,17 @@ discard block |
||
| 29 | 29 | * @param string $name |
| 30 | 30 | * @return void|array |
| 31 | 31 | */ |
| 32 | - public function __call($name, array $args = []) |
|
| 32 | + public function __call( $name, array $args = [] ) |
|
| 33 | 33 | { |
| 34 | - if (!method_exists($this, $name) || !in_array($name, $this->callable)) { |
|
| 34 | + if( !method_exists( $this, $name ) || !in_array( $name, $this->callable ) ) { |
|
| 35 | 35 | return; |
| 36 | 36 | } |
| 37 | - $args[0] = $this->mapKeys(Arr::get($args, 0, [])); |
|
| 38 | - $defaults = call_user_func_array([$this, $name], $args); |
|
| 39 | - $hookName = (new ReflectionClass($this))->getShortName(); |
|
| 40 | - $hookName = str_replace('Defaults', '', $hookName); |
|
| 41 | - $hookName = Str::dashCase($hookName); |
|
| 42 | - return apply_filters('site-reviews/defaults/'.$hookName, $defaults, $name); |
|
| 37 | + $args[0] = $this->mapKeys( Arr::get( $args, 0, [] ) ); |
|
| 38 | + $defaults = call_user_func_array( [$this, $name], $args ); |
|
| 39 | + $hookName = (new ReflectionClass( $this ))->getShortName(); |
|
| 40 | + $hookName = str_replace( 'Defaults', '', $hookName ); |
|
| 41 | + $hookName = Str::dashCase( $hookName ); |
|
| 42 | + return apply_filters( 'site-reviews/defaults/'.$hookName, $defaults, $name ); |
|
| 43 | 43 | } |
| 44 | 44 | |
| 45 | 45 | /** |
@@ -50,38 +50,38 @@ discard block |
||
| 50 | 50 | /** |
| 51 | 51 | * @return array |
| 52 | 52 | */ |
| 53 | - protected function filter(array $values = []) |
|
| 53 | + protected function filter( array $values = [] ) |
|
| 54 | 54 | { |
| 55 | - return $this->normalize($this->merge(array_filter($values)), $values); |
|
| 55 | + return $this->normalize( $this->merge( array_filter( $values ) ), $values ); |
|
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | /** |
| 59 | 59 | * @return string |
| 60 | 60 | */ |
| 61 | - protected function filteredJson(array $values = []) |
|
| 61 | + protected function filteredJson( array $values = [] ) |
|
| 62 | 62 | { |
| 63 | 63 | $defaults = $this->flattenArray( |
| 64 | - array_diff_key($this->defaults(), array_flip($this->guarded)) |
|
| 64 | + array_diff_key( $this->defaults(), array_flip( $this->guarded ) ) |
|
| 65 | 65 | ); |
| 66 | 66 | $values = $this->flattenArray( |
| 67 | - shortcode_atts($defaults, $values) |
|
| 67 | + shortcode_atts( $defaults, $values ) |
|
| 68 | 68 | ); |
| 69 | - $filtered = array_filter(array_diff_assoc($values, $defaults), function ($value) { |
|
| 70 | - return !$this->isEmpty($value); |
|
| 69 | + $filtered = array_filter( array_diff_assoc( $values, $defaults ), function( $value ) { |
|
| 70 | + return !$this->isEmpty( $value ); |
|
| 71 | 71 | }); |
| 72 | - return json_encode($filtered, JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_TAG | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); |
|
| 72 | + return json_encode( $filtered, JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_TAG | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE ); |
|
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | /** |
| 76 | 76 | * @return array |
| 77 | 77 | */ |
| 78 | - protected function flattenArray(array $values) |
|
| 78 | + protected function flattenArray( array $values ) |
|
| 79 | 79 | { |
| 80 | - array_walk($values, function (&$value) { |
|
| 81 | - if (!is_array($value)) { |
|
| 80 | + array_walk( $values, function( &$value ) { |
|
| 81 | + if( !is_array( $value ) ) { |
|
| 82 | 82 | return; |
| 83 | 83 | } |
| 84 | - $value = implode(',', $value); |
|
| 84 | + $value = implode( ',', $value ); |
|
| 85 | 85 | }); |
| 86 | 86 | return $values; |
| 87 | 87 | } |
@@ -90,18 +90,18 @@ discard block |
||
| 90 | 90 | * @param mixed $var |
| 91 | 91 | * @return bool |
| 92 | 92 | */ |
| 93 | - protected function isEmpty($var) |
|
| 93 | + protected function isEmpty( $var ) |
|
| 94 | 94 | { |
| 95 | - return !is_numeric($var) && !is_bool($var) && empty($var); |
|
| 95 | + return !is_numeric( $var ) && !is_bool( $var ) && empty($var); |
|
| 96 | 96 | } |
| 97 | 97 | |
| 98 | 98 | /** |
| 99 | 99 | * @return array |
| 100 | 100 | */ |
| 101 | - protected function mapKeys(array $args) |
|
| 101 | + protected function mapKeys( array $args ) |
|
| 102 | 102 | { |
| 103 | - foreach ($this->mapped as $old => $new) { |
|
| 104 | - if (array_key_exists($old, $args)) { |
|
| 103 | + foreach( $this->mapped as $old => $new ) { |
|
| 104 | + if( array_key_exists( $old, $args ) ) { |
|
| 105 | 105 | $args[$new] = $args[$old]; |
| 106 | 106 | unset($args[$old]); |
| 107 | 107 | } |
@@ -112,26 +112,26 @@ discard block |
||
| 112 | 112 | /** |
| 113 | 113 | * @return array |
| 114 | 114 | */ |
| 115 | - protected function merge(array $values = []) |
|
| 115 | + protected function merge( array $values = [] ) |
|
| 116 | 116 | { |
| 117 | - return $this->normalize(wp_parse_args($values, $this->defaults()), $values); |
|
| 117 | + return $this->normalize( wp_parse_args( $values, $this->defaults() ), $values ); |
|
| 118 | 118 | } |
| 119 | 119 | |
| 120 | 120 | /** |
| 121 | 121 | * @return array |
| 122 | 122 | */ |
| 123 | - protected function normalize(array $values, array $originalValues) |
|
| 123 | + protected function normalize( array $values, array $originalValues ) |
|
| 124 | 124 | { |
| 125 | - $values['json'] = $this->filteredJson($originalValues); |
|
| 125 | + $values['json'] = $this->filteredJson( $originalValues ); |
|
| 126 | 126 | return $values; |
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | /** |
| 130 | 130 | * @return array |
| 131 | 131 | */ |
| 132 | - protected function restrict(array $values = []) |
|
| 132 | + protected function restrict( array $values = [] ) |
|
| 133 | 133 | { |
| 134 | - return $this->normalize(shortcode_atts($this->defaults(), $values), $values); |
|
| 134 | + return $this->normalize( shortcode_atts( $this->defaults(), $values ), $values ); |
|
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | /** |
@@ -139,6 +139,6 @@ discard block |
||
| 139 | 139 | */ |
| 140 | 140 | protected function unguarded() |
| 141 | 141 | { |
| 142 | - return array_diff_key($this->defaults(), array_flip($this->guarded)); |
|
| 142 | + return array_diff_key( $this->defaults(), array_flip( $this->guarded ) ); |
|
| 143 | 143 | } |
| 144 | 144 | } |
@@ -7,106 +7,106 @@ |
||
| 7 | 7 | |
| 8 | 8 | class Labels |
| 9 | 9 | { |
| 10 | - /** |
|
| 11 | - * @param string $translation |
|
| 12 | - * @param string $test |
|
| 13 | - * @return string |
|
| 14 | - */ |
|
| 15 | - public function filterPostStatusLabels($translation, $text) |
|
| 16 | - { |
|
| 17 | - $replacements = $this->getStatusLabels(); |
|
| 18 | - return array_key_exists($text, $replacements) |
|
| 19 | - ? $replacements[$text] |
|
| 20 | - : $translation; |
|
| 21 | - } |
|
| 10 | + /** |
|
| 11 | + * @param string $translation |
|
| 12 | + * @param string $test |
|
| 13 | + * @return string |
|
| 14 | + */ |
|
| 15 | + public function filterPostStatusLabels($translation, $text) |
|
| 16 | + { |
|
| 17 | + $replacements = $this->getStatusLabels(); |
|
| 18 | + return array_key_exists($text, $replacements) |
|
| 19 | + ? $replacements[$text] |
|
| 20 | + : $translation; |
|
| 21 | + } |
|
| 22 | 22 | |
| 23 | - /** |
|
| 24 | - * @return array |
|
| 25 | - */ |
|
| 26 | - public function filterUpdateMessages(array $messages) |
|
| 27 | - { |
|
| 28 | - $post = get_post(); |
|
| 29 | - if (!($post instanceof WP_Post)) { |
|
| 30 | - return; |
|
| 31 | - } |
|
| 32 | - $strings = $this->getReviewLabels(); |
|
| 33 | - $restored = filter_input(INPUT_GET, 'revision'); |
|
| 34 | - if ($revisionTitle = wp_post_revision_title(intval($restored), false)) { |
|
| 35 | - $restored = sprintf($strings['restored'], $revisionTitle); |
|
| 36 | - } |
|
| 37 | - $scheduled_date = date_i18n('M j, Y @ H:i', strtotime($post->post_date)); |
|
| 38 | - $messages[Application::POST_TYPE] = [ |
|
| 39 | - 1 => $strings['updated'], |
|
| 40 | - 4 => $strings['updated'], |
|
| 41 | - 5 => $restored, |
|
| 42 | - 6 => $strings['published'], |
|
| 43 | - 7 => $strings['saved'], |
|
| 44 | - 8 => $strings['submitted'], |
|
| 45 | - 9 => sprintf($strings['scheduled'], '<strong>'.$scheduled_date.'</strong>'), |
|
| 46 | - 10 => $strings['draft_updated'], |
|
| 47 | - 50 => $strings['approved'], |
|
| 48 | - 51 => $strings['unapproved'], |
|
| 49 | - 52 => $strings['reverted'], |
|
| 50 | - ]; |
|
| 51 | - return $messages; |
|
| 52 | - } |
|
| 23 | + /** |
|
| 24 | + * @return array |
|
| 25 | + */ |
|
| 26 | + public function filterUpdateMessages(array $messages) |
|
| 27 | + { |
|
| 28 | + $post = get_post(); |
|
| 29 | + if (!($post instanceof WP_Post)) { |
|
| 30 | + return; |
|
| 31 | + } |
|
| 32 | + $strings = $this->getReviewLabels(); |
|
| 33 | + $restored = filter_input(INPUT_GET, 'revision'); |
|
| 34 | + if ($revisionTitle = wp_post_revision_title(intval($restored), false)) { |
|
| 35 | + $restored = sprintf($strings['restored'], $revisionTitle); |
|
| 36 | + } |
|
| 37 | + $scheduled_date = date_i18n('M j, Y @ H:i', strtotime($post->post_date)); |
|
| 38 | + $messages[Application::POST_TYPE] = [ |
|
| 39 | + 1 => $strings['updated'], |
|
| 40 | + 4 => $strings['updated'], |
|
| 41 | + 5 => $restored, |
|
| 42 | + 6 => $strings['published'], |
|
| 43 | + 7 => $strings['saved'], |
|
| 44 | + 8 => $strings['submitted'], |
|
| 45 | + 9 => sprintf($strings['scheduled'], '<strong>'.$scheduled_date.'</strong>'), |
|
| 46 | + 10 => $strings['draft_updated'], |
|
| 47 | + 50 => $strings['approved'], |
|
| 48 | + 51 => $strings['unapproved'], |
|
| 49 | + 52 => $strings['reverted'], |
|
| 50 | + ]; |
|
| 51 | + return $messages; |
|
| 52 | + } |
|
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * @return void |
|
| 56 | - */ |
|
| 57 | - public function translatePostStatusLabels() |
|
| 58 | - { |
|
| 59 | - global $wp_scripts; |
|
| 60 | - $strings = [ |
|
| 61 | - 'savePending' => __('Save as Unapproved', 'site-reviews'), |
|
| 62 | - 'published' => __('Approved', 'site-reviews'), |
|
| 63 | - ]; |
|
| 64 | - if (isset($wp_scripts->registered['post']->extra['data'])) { |
|
| 65 | - $l10n = &$wp_scripts->registered['post']->extra['data']; |
|
| 66 | - foreach ($strings as $search => $replace) { |
|
| 67 | - $l10n = preg_replace('/("'.$search.'":")([^"]+)/', '$1'.$replace, $l10n); |
|
| 68 | - } |
|
| 69 | - } |
|
| 70 | - } |
|
| 54 | + /** |
|
| 55 | + * @return void |
|
| 56 | + */ |
|
| 57 | + public function translatePostStatusLabels() |
|
| 58 | + { |
|
| 59 | + global $wp_scripts; |
|
| 60 | + $strings = [ |
|
| 61 | + 'savePending' => __('Save as Unapproved', 'site-reviews'), |
|
| 62 | + 'published' => __('Approved', 'site-reviews'), |
|
| 63 | + ]; |
|
| 64 | + if (isset($wp_scripts->registered['post']->extra['data'])) { |
|
| 65 | + $l10n = &$wp_scripts->registered['post']->extra['data']; |
|
| 66 | + foreach ($strings as $search => $replace) { |
|
| 67 | + $l10n = preg_replace('/("'.$search.'":")([^"]+)/', '$1'.$replace, $l10n); |
|
| 68 | + } |
|
| 69 | + } |
|
| 70 | + } |
|
| 71 | 71 | |
| 72 | - /** |
|
| 73 | - * @return array |
|
| 74 | - */ |
|
| 75 | - protected function getReviewLabels() |
|
| 76 | - { |
|
| 77 | - return [ |
|
| 78 | - 'approved' => __('Review has been approved and published.', 'site-reviews'), |
|
| 79 | - 'draft_updated' => __('Review draft updated.', 'site-reviews'), |
|
| 80 | - 'preview' => __('Preview review', 'site-reviews'), |
|
| 81 | - 'published' => __('Review approved and published.', 'site-reviews'), |
|
| 82 | - 'restored' => __('Review restored to revision from %s.', 'site-reviews'), |
|
| 83 | - 'reverted' => __('Review has been reverted to its original submission state (title, content, and submission date).', 'site-reviews'), |
|
| 84 | - 'saved' => __('Review saved.', 'site-reviews'), |
|
| 85 | - 'scheduled' => __('Review scheduled for: %s.', 'site-reviews'), |
|
| 86 | - 'submitted' => __('Review submitted.', 'site-reviews'), |
|
| 87 | - 'unapproved' => __('Review has been unapproved and is now pending.', 'site-reviews'), |
|
| 88 | - 'updated' => __('Review updated.', 'site-reviews'), |
|
| 89 | - 'view' => __('View review', 'site-reviews'), |
|
| 90 | - ]; |
|
| 91 | - } |
|
| 72 | + /** |
|
| 73 | + * @return array |
|
| 74 | + */ |
|
| 75 | + protected function getReviewLabels() |
|
| 76 | + { |
|
| 77 | + return [ |
|
| 78 | + 'approved' => __('Review has been approved and published.', 'site-reviews'), |
|
| 79 | + 'draft_updated' => __('Review draft updated.', 'site-reviews'), |
|
| 80 | + 'preview' => __('Preview review', 'site-reviews'), |
|
| 81 | + 'published' => __('Review approved and published.', 'site-reviews'), |
|
| 82 | + 'restored' => __('Review restored to revision from %s.', 'site-reviews'), |
|
| 83 | + 'reverted' => __('Review has been reverted to its original submission state (title, content, and submission date).', 'site-reviews'), |
|
| 84 | + 'saved' => __('Review saved.', 'site-reviews'), |
|
| 85 | + 'scheduled' => __('Review scheduled for: %s.', 'site-reviews'), |
|
| 86 | + 'submitted' => __('Review submitted.', 'site-reviews'), |
|
| 87 | + 'unapproved' => __('Review has been unapproved and is now pending.', 'site-reviews'), |
|
| 88 | + 'updated' => __('Review updated.', 'site-reviews'), |
|
| 89 | + 'view' => __('View review', 'site-reviews'), |
|
| 90 | + ]; |
|
| 91 | + } |
|
| 92 | 92 | |
| 93 | - /** |
|
| 94 | - * Store the labels to avoid unnecessary loops. |
|
| 95 | - * @return array |
|
| 96 | - */ |
|
| 97 | - protected function getStatusLabels() |
|
| 98 | - { |
|
| 99 | - static $labels; |
|
| 100 | - if (empty($labels)) { |
|
| 101 | - $labels = [ |
|
| 102 | - 'Pending' => __('Unapproved', 'site-reviews'), |
|
| 103 | - 'Pending Review' => __('Unapproved', 'site-reviews'), |
|
| 104 | - 'Privately Published' => __('Privately Approved', 'site-reviews'), |
|
| 105 | - 'Publish' => __('Approve', 'site-reviews'), |
|
| 106 | - 'Published' => __('Approved', 'site-reviews'), |
|
| 107 | - 'Save as Pending' => __('Save as Unapproved', 'site-reviews'), |
|
| 108 | - ]; |
|
| 109 | - } |
|
| 110 | - return $labels; |
|
| 111 | - } |
|
| 93 | + /** |
|
| 94 | + * Store the labels to avoid unnecessary loops. |
|
| 95 | + * @return array |
|
| 96 | + */ |
|
| 97 | + protected function getStatusLabels() |
|
| 98 | + { |
|
| 99 | + static $labels; |
|
| 100 | + if (empty($labels)) { |
|
| 101 | + $labels = [ |
|
| 102 | + 'Pending' => __('Unapproved', 'site-reviews'), |
|
| 103 | + 'Pending Review' => __('Unapproved', 'site-reviews'), |
|
| 104 | + 'Privately Published' => __('Privately Approved', 'site-reviews'), |
|
| 105 | + 'Publish' => __('Approve', 'site-reviews'), |
|
| 106 | + 'Published' => __('Approved', 'site-reviews'), |
|
| 107 | + 'Save as Pending' => __('Save as Unapproved', 'site-reviews'), |
|
| 108 | + ]; |
|
| 109 | + } |
|
| 110 | + return $labels; |
|
| 111 | + } |
|
| 112 | 112 | } |
@@ -12,10 +12,10 @@ discard block |
||
| 12 | 12 | * @param string $test |
| 13 | 13 | * @return string |
| 14 | 14 | */ |
| 15 | - public function filterPostStatusLabels($translation, $text) |
|
| 15 | + public function filterPostStatusLabels( $translation, $text ) |
|
| 16 | 16 | { |
| 17 | 17 | $replacements = $this->getStatusLabels(); |
| 18 | - return array_key_exists($text, $replacements) |
|
| 18 | + return array_key_exists( $text, $replacements ) |
|
| 19 | 19 | ? $replacements[$text] |
| 20 | 20 | : $translation; |
| 21 | 21 | } |
@@ -23,18 +23,18 @@ discard block |
||
| 23 | 23 | /** |
| 24 | 24 | * @return array |
| 25 | 25 | */ |
| 26 | - public function filterUpdateMessages(array $messages) |
|
| 26 | + public function filterUpdateMessages( array $messages ) |
|
| 27 | 27 | { |
| 28 | 28 | $post = get_post(); |
| 29 | - if (!($post instanceof WP_Post)) { |
|
| 29 | + if( !($post instanceof WP_Post) ) { |
|
| 30 | 30 | return; |
| 31 | 31 | } |
| 32 | 32 | $strings = $this->getReviewLabels(); |
| 33 | - $restored = filter_input(INPUT_GET, 'revision'); |
|
| 34 | - if ($revisionTitle = wp_post_revision_title(intval($restored), false)) { |
|
| 35 | - $restored = sprintf($strings['restored'], $revisionTitle); |
|
| 33 | + $restored = filter_input( INPUT_GET, 'revision' ); |
|
| 34 | + if( $revisionTitle = wp_post_revision_title( intval( $restored ), false ) ) { |
|
| 35 | + $restored = sprintf( $strings['restored'], $revisionTitle ); |
|
| 36 | 36 | } |
| 37 | - $scheduled_date = date_i18n('M j, Y @ H:i', strtotime($post->post_date)); |
|
| 37 | + $scheduled_date = date_i18n( 'M j, Y @ H:i', strtotime( $post->post_date ) ); |
|
| 38 | 38 | $messages[Application::POST_TYPE] = [ |
| 39 | 39 | 1 => $strings['updated'], |
| 40 | 40 | 4 => $strings['updated'], |
@@ -42,7 +42,7 @@ discard block |
||
| 42 | 42 | 6 => $strings['published'], |
| 43 | 43 | 7 => $strings['saved'], |
| 44 | 44 | 8 => $strings['submitted'], |
| 45 | - 9 => sprintf($strings['scheduled'], '<strong>'.$scheduled_date.'</strong>'), |
|
| 45 | + 9 => sprintf( $strings['scheduled'], '<strong>'.$scheduled_date.'</strong>' ), |
|
| 46 | 46 | 10 => $strings['draft_updated'], |
| 47 | 47 | 50 => $strings['approved'], |
| 48 | 48 | 51 => $strings['unapproved'], |
@@ -58,13 +58,13 @@ discard block |
||
| 58 | 58 | { |
| 59 | 59 | global $wp_scripts; |
| 60 | 60 | $strings = [ |
| 61 | - 'savePending' => __('Save as Unapproved', 'site-reviews'), |
|
| 62 | - 'published' => __('Approved', 'site-reviews'), |
|
| 61 | + 'savePending' => __( 'Save as Unapproved', 'site-reviews' ), |
|
| 62 | + 'published' => __( 'Approved', 'site-reviews' ), |
|
| 63 | 63 | ]; |
| 64 | - if (isset($wp_scripts->registered['post']->extra['data'])) { |
|
| 64 | + if( isset($wp_scripts->registered['post']->extra['data']) ) { |
|
| 65 | 65 | $l10n = &$wp_scripts->registered['post']->extra['data']; |
| 66 | - foreach ($strings as $search => $replace) { |
|
| 67 | - $l10n = preg_replace('/("'.$search.'":")([^"]+)/', '$1'.$replace, $l10n); |
|
| 66 | + foreach( $strings as $search => $replace ) { |
|
| 67 | + $l10n = preg_replace( '/("'.$search.'":")([^"]+)/', '$1'.$replace, $l10n ); |
|
| 68 | 68 | } |
| 69 | 69 | } |
| 70 | 70 | } |
@@ -75,18 +75,18 @@ discard block |
||
| 75 | 75 | protected function getReviewLabels() |
| 76 | 76 | { |
| 77 | 77 | return [ |
| 78 | - 'approved' => __('Review has been approved and published.', 'site-reviews'), |
|
| 79 | - 'draft_updated' => __('Review draft updated.', 'site-reviews'), |
|
| 80 | - 'preview' => __('Preview review', 'site-reviews'), |
|
| 81 | - 'published' => __('Review approved and published.', 'site-reviews'), |
|
| 82 | - 'restored' => __('Review restored to revision from %s.', 'site-reviews'), |
|
| 83 | - 'reverted' => __('Review has been reverted to its original submission state (title, content, and submission date).', 'site-reviews'), |
|
| 84 | - 'saved' => __('Review saved.', 'site-reviews'), |
|
| 85 | - 'scheduled' => __('Review scheduled for: %s.', 'site-reviews'), |
|
| 86 | - 'submitted' => __('Review submitted.', 'site-reviews'), |
|
| 87 | - 'unapproved' => __('Review has been unapproved and is now pending.', 'site-reviews'), |
|
| 88 | - 'updated' => __('Review updated.', 'site-reviews'), |
|
| 89 | - 'view' => __('View review', 'site-reviews'), |
|
| 78 | + 'approved' => __( 'Review has been approved and published.', 'site-reviews' ), |
|
| 79 | + 'draft_updated' => __( 'Review draft updated.', 'site-reviews' ), |
|
| 80 | + 'preview' => __( 'Preview review', 'site-reviews' ), |
|
| 81 | + 'published' => __( 'Review approved and published.', 'site-reviews' ), |
|
| 82 | + 'restored' => __( 'Review restored to revision from %s.', 'site-reviews' ), |
|
| 83 | + 'reverted' => __( 'Review has been reverted to its original submission state (title, content, and submission date).', 'site-reviews' ), |
|
| 84 | + 'saved' => __( 'Review saved.', 'site-reviews' ), |
|
| 85 | + 'scheduled' => __( 'Review scheduled for: %s.', 'site-reviews' ), |
|
| 86 | + 'submitted' => __( 'Review submitted.', 'site-reviews' ), |
|
| 87 | + 'unapproved' => __( 'Review has been unapproved and is now pending.', 'site-reviews' ), |
|
| 88 | + 'updated' => __( 'Review updated.', 'site-reviews' ), |
|
| 89 | + 'view' => __( 'View review', 'site-reviews' ), |
|
| 90 | 90 | ]; |
| 91 | 91 | } |
| 92 | 92 | |
@@ -97,14 +97,14 @@ discard block |
||
| 97 | 97 | protected function getStatusLabels() |
| 98 | 98 | { |
| 99 | 99 | static $labels; |
| 100 | - if (empty($labels)) { |
|
| 100 | + if( empty($labels) ) { |
|
| 101 | 101 | $labels = [ |
| 102 | - 'Pending' => __('Unapproved', 'site-reviews'), |
|
| 103 | - 'Pending Review' => __('Unapproved', 'site-reviews'), |
|
| 104 | - 'Privately Published' => __('Privately Approved', 'site-reviews'), |
|
| 105 | - 'Publish' => __('Approve', 'site-reviews'), |
|
| 106 | - 'Published' => __('Approved', 'site-reviews'), |
|
| 107 | - 'Save as Pending' => __('Save as Unapproved', 'site-reviews'), |
|
| 102 | + 'Pending' => __( 'Unapproved', 'site-reviews' ), |
|
| 103 | + 'Pending Review' => __( 'Unapproved', 'site-reviews' ), |
|
| 104 | + 'Privately Published' => __( 'Privately Approved', 'site-reviews' ), |
|
| 105 | + 'Publish' => __( 'Approve', 'site-reviews' ), |
|
| 106 | + 'Published' => __( 'Approved', 'site-reviews' ), |
|
| 107 | + 'Save as Pending' => __( 'Save as Unapproved', 'site-reviews' ), |
|
| 108 | 108 | ]; |
| 109 | 109 | } |
| 110 | 110 | return $labels; |
@@ -11,272 +11,272 @@ |
||
| 11 | 11 | |
| 12 | 12 | class Translation |
| 13 | 13 | { |
| 14 | - const SEARCH_THRESHOLD = 3; |
|
| 14 | + const SEARCH_THRESHOLD = 3; |
|
| 15 | 15 | |
| 16 | - /** |
|
| 17 | - * @var array |
|
| 18 | - */ |
|
| 19 | - protected $entries; |
|
| 16 | + /** |
|
| 17 | + * @var array |
|
| 18 | + */ |
|
| 19 | + protected $entries; |
|
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * @var array |
|
| 23 | - */ |
|
| 24 | - protected $results; |
|
| 21 | + /** |
|
| 22 | + * @var array |
|
| 23 | + */ |
|
| 24 | + protected $results; |
|
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * Returns all saved custom translations with translation context. |
|
| 28 | - * @return array |
|
| 29 | - */ |
|
| 30 | - public function all() |
|
| 31 | - { |
|
| 32 | - $translations = $this->translations(); |
|
| 33 | - $entries = $this->filter($translations, $this->entries())->results(); |
|
| 34 | - array_walk($translations, function (&$entry) use ($entries) { |
|
| 35 | - $entry['desc'] = array_key_exists($entry['id'], $entries) |
|
| 36 | - ? $this->getEntryString($entries[$entry['id']], 'msgctxt') |
|
| 37 | - : ''; |
|
| 38 | - }); |
|
| 39 | - return $translations; |
|
| 40 | - } |
|
| 26 | + /** |
|
| 27 | + * Returns all saved custom translations with translation context. |
|
| 28 | + * @return array |
|
| 29 | + */ |
|
| 30 | + public function all() |
|
| 31 | + { |
|
| 32 | + $translations = $this->translations(); |
|
| 33 | + $entries = $this->filter($translations, $this->entries())->results(); |
|
| 34 | + array_walk($translations, function (&$entry) use ($entries) { |
|
| 35 | + $entry['desc'] = array_key_exists($entry['id'], $entries) |
|
| 36 | + ? $this->getEntryString($entries[$entry['id']], 'msgctxt') |
|
| 37 | + : ''; |
|
| 38 | + }); |
|
| 39 | + return $translations; |
|
| 40 | + } |
|
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * @return array |
|
| 44 | - */ |
|
| 45 | - public function entries() |
|
| 46 | - { |
|
| 47 | - if (!isset($this->entries)) { |
|
| 48 | - $potFile = glsr()->path(glsr()->languages.'/'.Application::ID.'.pot'); |
|
| 49 | - $entries = $this->extractEntriesFromPotFile($potFile); |
|
| 50 | - $entries = apply_filters('site-reviews/translation/entries', $entries); |
|
| 51 | - $this->entries = $entries; |
|
| 52 | - } |
|
| 53 | - return $this->entries; |
|
| 54 | - } |
|
| 42 | + /** |
|
| 43 | + * @return array |
|
| 44 | + */ |
|
| 45 | + public function entries() |
|
| 46 | + { |
|
| 47 | + if (!isset($this->entries)) { |
|
| 48 | + $potFile = glsr()->path(glsr()->languages.'/'.Application::ID.'.pot'); |
|
| 49 | + $entries = $this->extractEntriesFromPotFile($potFile); |
|
| 50 | + $entries = apply_filters('site-reviews/translation/entries', $entries); |
|
| 51 | + $this->entries = $entries; |
|
| 52 | + } |
|
| 53 | + return $this->entries; |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | - /** |
|
| 57 | - * @param array|null $entriesToExclude |
|
| 58 | - * @param array|null $entries |
|
| 59 | - * @return static |
|
| 60 | - */ |
|
| 61 | - public function exclude($entriesToExclude = null, $entries = null) |
|
| 62 | - { |
|
| 63 | - return $this->filter($entriesToExclude, $entries, false); |
|
| 64 | - } |
|
| 56 | + /** |
|
| 57 | + * @param array|null $entriesToExclude |
|
| 58 | + * @param array|null $entries |
|
| 59 | + * @return static |
|
| 60 | + */ |
|
| 61 | + public function exclude($entriesToExclude = null, $entries = null) |
|
| 62 | + { |
|
| 63 | + return $this->filter($entriesToExclude, $entries, false); |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | - /** |
|
| 67 | - * @param string $potFile |
|
| 68 | - * @return array |
|
| 69 | - */ |
|
| 70 | - public function extractEntriesFromPotFile($potFile, array $entries = []) |
|
| 71 | - { |
|
| 72 | - try { |
|
| 73 | - $potEntries = $this->normalize(Parser::parseFile($potFile)->getEntries()); |
|
| 74 | - foreach ($potEntries as $key => $entry) { |
|
| 75 | - $entries[html_entity_decode($key, ENT_COMPAT, 'UTF-8')] = $entry; |
|
| 76 | - } |
|
| 77 | - } catch (Exception $e) { |
|
| 78 | - glsr_log()->error($e->getMessage()); |
|
| 79 | - } |
|
| 80 | - return $entries; |
|
| 81 | - } |
|
| 66 | + /** |
|
| 67 | + * @param string $potFile |
|
| 68 | + * @return array |
|
| 69 | + */ |
|
| 70 | + public function extractEntriesFromPotFile($potFile, array $entries = []) |
|
| 71 | + { |
|
| 72 | + try { |
|
| 73 | + $potEntries = $this->normalize(Parser::parseFile($potFile)->getEntries()); |
|
| 74 | + foreach ($potEntries as $key => $entry) { |
|
| 75 | + $entries[html_entity_decode($key, ENT_COMPAT, 'UTF-8')] = $entry; |
|
| 76 | + } |
|
| 77 | + } catch (Exception $e) { |
|
| 78 | + glsr_log()->error($e->getMessage()); |
|
| 79 | + } |
|
| 80 | + return $entries; |
|
| 81 | + } |
|
| 82 | 82 | |
| 83 | - /** |
|
| 84 | - * @param array|null $filterWith |
|
| 85 | - * @param array|null $entries |
|
| 86 | - * @param bool $intersect |
|
| 87 | - * @return static |
|
| 88 | - */ |
|
| 89 | - public function filter($filterWith = null, $entries = null, $intersect = true) |
|
| 90 | - { |
|
| 91 | - if (!is_array($entries)) { |
|
| 92 | - $entries = $this->results; |
|
| 93 | - } |
|
| 94 | - if (!is_array($filterWith)) { |
|
| 95 | - $filterWith = $this->translations(); |
|
| 96 | - } |
|
| 97 | - $keys = array_flip(glsr_array_column($filterWith, 'id')); |
|
| 98 | - $this->results = $intersect |
|
| 99 | - ? array_intersect_key($entries, $keys) |
|
| 100 | - : array_diff_key($entries, $keys); |
|
| 101 | - return $this; |
|
| 102 | - } |
|
| 83 | + /** |
|
| 84 | + * @param array|null $filterWith |
|
| 85 | + * @param array|null $entries |
|
| 86 | + * @param bool $intersect |
|
| 87 | + * @return static |
|
| 88 | + */ |
|
| 89 | + public function filter($filterWith = null, $entries = null, $intersect = true) |
|
| 90 | + { |
|
| 91 | + if (!is_array($entries)) { |
|
| 92 | + $entries = $this->results; |
|
| 93 | + } |
|
| 94 | + if (!is_array($filterWith)) { |
|
| 95 | + $filterWith = $this->translations(); |
|
| 96 | + } |
|
| 97 | + $keys = array_flip(glsr_array_column($filterWith, 'id')); |
|
| 98 | + $this->results = $intersect |
|
| 99 | + ? array_intersect_key($entries, $keys) |
|
| 100 | + : array_diff_key($entries, $keys); |
|
| 101 | + return $this; |
|
| 102 | + } |
|
| 103 | 103 | |
| 104 | - /** |
|
| 105 | - * @param string $template |
|
| 106 | - * @return string |
|
| 107 | - */ |
|
| 108 | - public function render($template, array $entry) |
|
| 109 | - { |
|
| 110 | - $data = array_combine( |
|
| 111 | - array_map(function ($key) { return 'data.'.$key; }, array_keys($entry)), |
|
| 112 | - $entry |
|
| 113 | - ); |
|
| 114 | - $data['data.class'] = $data['data.error'] = ''; |
|
| 115 | - if (false === array_search($entry['s1'], glsr_array_column($this->entries(), 'msgid'))) { |
|
| 116 | - $data['data.class'] = 'is-invalid'; |
|
| 117 | - $data['data.error'] = __('This custom translation is no longer valid as the original text has been changed or removed.', 'site-reviews'); |
|
| 118 | - } |
|
| 119 | - return glsr(Template::class)->build('partials/translations/'.$template, [ |
|
| 120 | - 'context' => array_map('esc_html', $data), |
|
| 121 | - ]); |
|
| 122 | - } |
|
| 104 | + /** |
|
| 105 | + * @param string $template |
|
| 106 | + * @return string |
|
| 107 | + */ |
|
| 108 | + public function render($template, array $entry) |
|
| 109 | + { |
|
| 110 | + $data = array_combine( |
|
| 111 | + array_map(function ($key) { return 'data.'.$key; }, array_keys($entry)), |
|
| 112 | + $entry |
|
| 113 | + ); |
|
| 114 | + $data['data.class'] = $data['data.error'] = ''; |
|
| 115 | + if (false === array_search($entry['s1'], glsr_array_column($this->entries(), 'msgid'))) { |
|
| 116 | + $data['data.class'] = 'is-invalid'; |
|
| 117 | + $data['data.error'] = __('This custom translation is no longer valid as the original text has been changed or removed.', 'site-reviews'); |
|
| 118 | + } |
|
| 119 | + return glsr(Template::class)->build('partials/translations/'.$template, [ |
|
| 120 | + 'context' => array_map('esc_html', $data), |
|
| 121 | + ]); |
|
| 122 | + } |
|
| 123 | 123 | |
| 124 | - /** |
|
| 125 | - * Returns a rendered string of all saved custom translations with translation context. |
|
| 126 | - * @return string |
|
| 127 | - */ |
|
| 128 | - public function renderAll() |
|
| 129 | - { |
|
| 130 | - $rendered = ''; |
|
| 131 | - foreach ($this->all() as $index => $entry) { |
|
| 132 | - $entry['index'] = $index; |
|
| 133 | - $entry['prefix'] = OptionManager::databaseKey(); |
|
| 134 | - $rendered.= $this->render($entry['type'], $entry); |
|
| 135 | - } |
|
| 136 | - return $rendered; |
|
| 137 | - } |
|
| 124 | + /** |
|
| 125 | + * Returns a rendered string of all saved custom translations with translation context. |
|
| 126 | + * @return string |
|
| 127 | + */ |
|
| 128 | + public function renderAll() |
|
| 129 | + { |
|
| 130 | + $rendered = ''; |
|
| 131 | + foreach ($this->all() as $index => $entry) { |
|
| 132 | + $entry['index'] = $index; |
|
| 133 | + $entry['prefix'] = OptionManager::databaseKey(); |
|
| 134 | + $rendered.= $this->render($entry['type'], $entry); |
|
| 135 | + } |
|
| 136 | + return $rendered; |
|
| 137 | + } |
|
| 138 | 138 | |
| 139 | - /** |
|
| 140 | - * @param bool $resetAfterRender |
|
| 141 | - * @return string |
|
| 142 | - */ |
|
| 143 | - public function renderResults($resetAfterRender = true) |
|
| 144 | - { |
|
| 145 | - $rendered = ''; |
|
| 146 | - foreach ($this->results as $id => $entry) { |
|
| 147 | - $data = [ |
|
| 148 | - 'desc' => $this->getEntryString($entry, 'msgctxt'), |
|
| 149 | - 'id' => $id, |
|
| 150 | - 'p1' => $this->getEntryString($entry, 'msgid_plural'), |
|
| 151 | - 's1' => $this->getEntryString($entry, 'msgid'), |
|
| 152 | - ]; |
|
| 153 | - $text = !empty($data['p1']) |
|
| 154 | - ? sprintf('%s | %s', $data['s1'], $data['p1']) |
|
| 155 | - : $data['s1']; |
|
| 156 | - $rendered.= $this->render('result', [ |
|
| 157 | - 'entry' => json_encode($data, JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_TAG | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE), |
|
| 158 | - 'text' => wp_strip_all_tags($text), |
|
| 159 | - ]); |
|
| 160 | - } |
|
| 161 | - if ($resetAfterRender) { |
|
| 162 | - $this->reset(); |
|
| 163 | - } |
|
| 164 | - return $rendered; |
|
| 165 | - } |
|
| 139 | + /** |
|
| 140 | + * @param bool $resetAfterRender |
|
| 141 | + * @return string |
|
| 142 | + */ |
|
| 143 | + public function renderResults($resetAfterRender = true) |
|
| 144 | + { |
|
| 145 | + $rendered = ''; |
|
| 146 | + foreach ($this->results as $id => $entry) { |
|
| 147 | + $data = [ |
|
| 148 | + 'desc' => $this->getEntryString($entry, 'msgctxt'), |
|
| 149 | + 'id' => $id, |
|
| 150 | + 'p1' => $this->getEntryString($entry, 'msgid_plural'), |
|
| 151 | + 's1' => $this->getEntryString($entry, 'msgid'), |
|
| 152 | + ]; |
|
| 153 | + $text = !empty($data['p1']) |
|
| 154 | + ? sprintf('%s | %s', $data['s1'], $data['p1']) |
|
| 155 | + : $data['s1']; |
|
| 156 | + $rendered.= $this->render('result', [ |
|
| 157 | + 'entry' => json_encode($data, JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_TAG | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE), |
|
| 158 | + 'text' => wp_strip_all_tags($text), |
|
| 159 | + ]); |
|
| 160 | + } |
|
| 161 | + if ($resetAfterRender) { |
|
| 162 | + $this->reset(); |
|
| 163 | + } |
|
| 164 | + return $rendered; |
|
| 165 | + } |
|
| 166 | 166 | |
| 167 | - /** |
|
| 168 | - * @return void |
|
| 169 | - */ |
|
| 170 | - public function reset() |
|
| 171 | - { |
|
| 172 | - $this->results = []; |
|
| 173 | - } |
|
| 167 | + /** |
|
| 168 | + * @return void |
|
| 169 | + */ |
|
| 170 | + public function reset() |
|
| 171 | + { |
|
| 172 | + $this->results = []; |
|
| 173 | + } |
|
| 174 | 174 | |
| 175 | - /** |
|
| 176 | - * @return array |
|
| 177 | - */ |
|
| 178 | - public function results() |
|
| 179 | - { |
|
| 180 | - $results = $this->results; |
|
| 181 | - $this->reset(); |
|
| 182 | - return $results; |
|
| 183 | - } |
|
| 175 | + /** |
|
| 176 | + * @return array |
|
| 177 | + */ |
|
| 178 | + public function results() |
|
| 179 | + { |
|
| 180 | + $results = $this->results; |
|
| 181 | + $this->reset(); |
|
| 182 | + return $results; |
|
| 183 | + } |
|
| 184 | 184 | |
| 185 | - /** |
|
| 186 | - * @param string $needle |
|
| 187 | - * @return static |
|
| 188 | - */ |
|
| 189 | - public function search($needle = '') |
|
| 190 | - { |
|
| 191 | - $this->reset(); |
|
| 192 | - $needle = trim(strtolower($needle)); |
|
| 193 | - foreach ($this->entries() as $key => $entry) { |
|
| 194 | - $single = strtolower($this->getEntryString($entry, 'msgid')); |
|
| 195 | - $plural = strtolower($this->getEntryString($entry, 'msgid_plural')); |
|
| 196 | - if (strlen($needle) < static::SEARCH_THRESHOLD) { |
|
| 197 | - if (in_array($needle, [$single, $plural])) { |
|
| 198 | - $this->results[$key] = $entry; |
|
| 199 | - } |
|
| 200 | - } elseif (Str::contains(sprintf('%s %s', $single, $plural), $needle)) { |
|
| 201 | - $this->results[$key] = $entry; |
|
| 202 | - } |
|
| 203 | - } |
|
| 204 | - return $this; |
|
| 205 | - } |
|
| 185 | + /** |
|
| 186 | + * @param string $needle |
|
| 187 | + * @return static |
|
| 188 | + */ |
|
| 189 | + public function search($needle = '') |
|
| 190 | + { |
|
| 191 | + $this->reset(); |
|
| 192 | + $needle = trim(strtolower($needle)); |
|
| 193 | + foreach ($this->entries() as $key => $entry) { |
|
| 194 | + $single = strtolower($this->getEntryString($entry, 'msgid')); |
|
| 195 | + $plural = strtolower($this->getEntryString($entry, 'msgid_plural')); |
|
| 196 | + if (strlen($needle) < static::SEARCH_THRESHOLD) { |
|
| 197 | + if (in_array($needle, [$single, $plural])) { |
|
| 198 | + $this->results[$key] = $entry; |
|
| 199 | + } |
|
| 200 | + } elseif (Str::contains(sprintf('%s %s', $single, $plural), $needle)) { |
|
| 201 | + $this->results[$key] = $entry; |
|
| 202 | + } |
|
| 203 | + } |
|
| 204 | + return $this; |
|
| 205 | + } |
|
| 206 | 206 | |
| 207 | - /** |
|
| 208 | - * Store the translations to avoid unnecessary loops. |
|
| 209 | - * @return array |
|
| 210 | - */ |
|
| 211 | - public function translations() |
|
| 212 | - { |
|
| 213 | - static $translations; |
|
| 214 | - if (empty($translations)) { |
|
| 215 | - $settings = glsr(OptionManager::class)->get('settings'); |
|
| 216 | - $translations = isset($settings['strings']) |
|
| 217 | - ? $this->normalizeSettings((array) $settings['strings']) |
|
| 218 | - : []; |
|
| 219 | - } |
|
| 220 | - return $translations; |
|
| 221 | - } |
|
| 207 | + /** |
|
| 208 | + * Store the translations to avoid unnecessary loops. |
|
| 209 | + * @return array |
|
| 210 | + */ |
|
| 211 | + public function translations() |
|
| 212 | + { |
|
| 213 | + static $translations; |
|
| 214 | + if (empty($translations)) { |
|
| 215 | + $settings = glsr(OptionManager::class)->get('settings'); |
|
| 216 | + $translations = isset($settings['strings']) |
|
| 217 | + ? $this->normalizeSettings((array) $settings['strings']) |
|
| 218 | + : []; |
|
| 219 | + } |
|
| 220 | + return $translations; |
|
| 221 | + } |
|
| 222 | 222 | |
| 223 | - /** |
|
| 224 | - * @param string $key |
|
| 225 | - * @return string |
|
| 226 | - */ |
|
| 227 | - protected function getEntryString(array $entry, $key) |
|
| 228 | - { |
|
| 229 | - return isset($entry[$key]) |
|
| 230 | - ? implode('', (array) $entry[$key]) |
|
| 231 | - : ''; |
|
| 232 | - } |
|
| 223 | + /** |
|
| 224 | + * @param string $key |
|
| 225 | + * @return string |
|
| 226 | + */ |
|
| 227 | + protected function getEntryString(array $entry, $key) |
|
| 228 | + { |
|
| 229 | + return isset($entry[$key]) |
|
| 230 | + ? implode('', (array) $entry[$key]) |
|
| 231 | + : ''; |
|
| 232 | + } |
|
| 233 | 233 | |
| 234 | - /** |
|
| 235 | - * @return array |
|
| 236 | - */ |
|
| 237 | - protected function normalize(array $entries) |
|
| 238 | - { |
|
| 239 | - $keys = [ |
|
| 240 | - 'msgctxt', 'msgid', 'msgid_plural', 'msgstr', 'msgstr[0]', 'msgstr[1]', |
|
| 241 | - ]; |
|
| 242 | - array_walk($entries, function (&$entry) use ($keys) { |
|
| 243 | - foreach ($keys as $key) { |
|
| 244 | - try { |
|
| 245 | - $entry = $this->normalizeEntryString($entry, $key); |
|
| 246 | - } catch (\TypeError $error) { |
|
| 247 | - glsr_log()->once('error', 'Translation/normalize', $error); |
|
| 248 | - glsr_log()->once('debug', 'Translation/normalize', $entry); |
|
| 249 | - } |
|
| 250 | - } |
|
| 251 | - }); |
|
| 252 | - return $entries; |
|
| 253 | - } |
|
| 234 | + /** |
|
| 235 | + * @return array |
|
| 236 | + */ |
|
| 237 | + protected function normalize(array $entries) |
|
| 238 | + { |
|
| 239 | + $keys = [ |
|
| 240 | + 'msgctxt', 'msgid', 'msgid_plural', 'msgstr', 'msgstr[0]', 'msgstr[1]', |
|
| 241 | + ]; |
|
| 242 | + array_walk($entries, function (&$entry) use ($keys) { |
|
| 243 | + foreach ($keys as $key) { |
|
| 244 | + try { |
|
| 245 | + $entry = $this->normalizeEntryString($entry, $key); |
|
| 246 | + } catch (\TypeError $error) { |
|
| 247 | + glsr_log()->once('error', 'Translation/normalize', $error); |
|
| 248 | + glsr_log()->once('debug', 'Translation/normalize', $entry); |
|
| 249 | + } |
|
| 250 | + } |
|
| 251 | + }); |
|
| 252 | + return $entries; |
|
| 253 | + } |
|
| 254 | 254 | |
| 255 | - /** |
|
| 256 | - * @param string $key |
|
| 257 | - * @return array |
|
| 258 | - */ |
|
| 259 | - protected function normalizeEntryString(array $entry, $key) |
|
| 260 | - { |
|
| 261 | - if (isset($entry[$key])) { |
|
| 262 | - $entry[$key] = $this->getEntryString($entry, $key); |
|
| 263 | - } |
|
| 264 | - return $entry; |
|
| 265 | - } |
|
| 255 | + /** |
|
| 256 | + * @param string $key |
|
| 257 | + * @return array |
|
| 258 | + */ |
|
| 259 | + protected function normalizeEntryString(array $entry, $key) |
|
| 260 | + { |
|
| 261 | + if (isset($entry[$key])) { |
|
| 262 | + $entry[$key] = $this->getEntryString($entry, $key); |
|
| 263 | + } |
|
| 264 | + return $entry; |
|
| 265 | + } |
|
| 266 | 266 | |
| 267 | - /** |
|
| 268 | - * @return array |
|
| 269 | - */ |
|
| 270 | - protected function normalizeSettings(array $strings) |
|
| 271 | - { |
|
| 272 | - $defaultString = array_fill_keys(['id', 's1', 's2', 'p1', 'p2'], ''); |
|
| 273 | - $strings = array_filter($strings, 'is_array'); |
|
| 274 | - foreach ($strings as &$string) { |
|
| 275 | - $string['type'] = isset($string['p1']) ? 'plural' : 'single'; |
|
| 276 | - $string = wp_parse_args($string, $defaultString); |
|
| 277 | - } |
|
| 278 | - return array_filter($strings, function ($string) { |
|
| 279 | - return !empty($string['id']); |
|
| 280 | - }); |
|
| 281 | - } |
|
| 267 | + /** |
|
| 268 | + * @return array |
|
| 269 | + */ |
|
| 270 | + protected function normalizeSettings(array $strings) |
|
| 271 | + { |
|
| 272 | + $defaultString = array_fill_keys(['id', 's1', 's2', 'p1', 'p2'], ''); |
|
| 273 | + $strings = array_filter($strings, 'is_array'); |
|
| 274 | + foreach ($strings as &$string) { |
|
| 275 | + $string['type'] = isset($string['p1']) ? 'plural' : 'single'; |
|
| 276 | + $string = wp_parse_args($string, $defaultString); |
|
| 277 | + } |
|
| 278 | + return array_filter($strings, function ($string) { |
|
| 279 | + return !empty($string['id']); |
|
| 280 | + }); |
|
| 281 | + } |
|
| 282 | 282 | } |
@@ -30,10 +30,10 @@ discard block |
||
| 30 | 30 | public function all() |
| 31 | 31 | { |
| 32 | 32 | $translations = $this->translations(); |
| 33 | - $entries = $this->filter($translations, $this->entries())->results(); |
|
| 34 | - array_walk($translations, function (&$entry) use ($entries) { |
|
| 35 | - $entry['desc'] = array_key_exists($entry['id'], $entries) |
|
| 36 | - ? $this->getEntryString($entries[$entry['id']], 'msgctxt') |
|
| 33 | + $entries = $this->filter( $translations, $this->entries() )->results(); |
|
| 34 | + array_walk( $translations, function( &$entry ) use ($entries) { |
|
| 35 | + $entry['desc'] = array_key_exists( $entry['id'], $entries ) |
|
| 36 | + ? $this->getEntryString( $entries[$entry['id']], 'msgctxt' ) |
|
| 37 | 37 | : ''; |
| 38 | 38 | }); |
| 39 | 39 | return $translations; |
@@ -44,10 +44,10 @@ discard block |
||
| 44 | 44 | */ |
| 45 | 45 | public function entries() |
| 46 | 46 | { |
| 47 | - if (!isset($this->entries)) { |
|
| 48 | - $potFile = glsr()->path(glsr()->languages.'/'.Application::ID.'.pot'); |
|
| 49 | - $entries = $this->extractEntriesFromPotFile($potFile); |
|
| 50 | - $entries = apply_filters('site-reviews/translation/entries', $entries); |
|
| 47 | + if( !isset($this->entries) ) { |
|
| 48 | + $potFile = glsr()->path( glsr()->languages.'/'.Application::ID.'.pot' ); |
|
| 49 | + $entries = $this->extractEntriesFromPotFile( $potFile ); |
|
| 50 | + $entries = apply_filters( 'site-reviews/translation/entries', $entries ); |
|
| 51 | 51 | $this->entries = $entries; |
| 52 | 52 | } |
| 53 | 53 | return $this->entries; |
@@ -58,24 +58,24 @@ discard block |
||
| 58 | 58 | * @param array|null $entries |
| 59 | 59 | * @return static |
| 60 | 60 | */ |
| 61 | - public function exclude($entriesToExclude = null, $entries = null) |
|
| 61 | + public function exclude( $entriesToExclude = null, $entries = null ) |
|
| 62 | 62 | { |
| 63 | - return $this->filter($entriesToExclude, $entries, false); |
|
| 63 | + return $this->filter( $entriesToExclude, $entries, false ); |
|
| 64 | 64 | } |
| 65 | 65 | |
| 66 | 66 | /** |
| 67 | 67 | * @param string $potFile |
| 68 | 68 | * @return array |
| 69 | 69 | */ |
| 70 | - public function extractEntriesFromPotFile($potFile, array $entries = []) |
|
| 70 | + public function extractEntriesFromPotFile( $potFile, array $entries = [] ) |
|
| 71 | 71 | { |
| 72 | 72 | try { |
| 73 | - $potEntries = $this->normalize(Parser::parseFile($potFile)->getEntries()); |
|
| 74 | - foreach ($potEntries as $key => $entry) { |
|
| 75 | - $entries[html_entity_decode($key, ENT_COMPAT, 'UTF-8')] = $entry; |
|
| 73 | + $potEntries = $this->normalize( Parser::parseFile( $potFile )->getEntries() ); |
|
| 74 | + foreach( $potEntries as $key => $entry ) { |
|
| 75 | + $entries[html_entity_decode( $key, ENT_COMPAT, 'UTF-8' )] = $entry; |
|
| 76 | 76 | } |
| 77 | - } catch (Exception $e) { |
|
| 78 | - glsr_log()->error($e->getMessage()); |
|
| 77 | + } catch( Exception $e ) { |
|
| 78 | + glsr_log()->error( $e->getMessage() ); |
|
| 79 | 79 | } |
| 80 | 80 | return $entries; |
| 81 | 81 | } |
@@ -86,18 +86,18 @@ discard block |
||
| 86 | 86 | * @param bool $intersect |
| 87 | 87 | * @return static |
| 88 | 88 | */ |
| 89 | - public function filter($filterWith = null, $entries = null, $intersect = true) |
|
| 89 | + public function filter( $filterWith = null, $entries = null, $intersect = true ) |
|
| 90 | 90 | { |
| 91 | - if (!is_array($entries)) { |
|
| 91 | + if( !is_array( $entries ) ) { |
|
| 92 | 92 | $entries = $this->results; |
| 93 | 93 | } |
| 94 | - if (!is_array($filterWith)) { |
|
| 94 | + if( !is_array( $filterWith ) ) { |
|
| 95 | 95 | $filterWith = $this->translations(); |
| 96 | 96 | } |
| 97 | - $keys = array_flip(glsr_array_column($filterWith, 'id')); |
|
| 97 | + $keys = array_flip( glsr_array_column( $filterWith, 'id' ) ); |
|
| 98 | 98 | $this->results = $intersect |
| 99 | - ? array_intersect_key($entries, $keys) |
|
| 100 | - : array_diff_key($entries, $keys); |
|
| 99 | + ? array_intersect_key( $entries, $keys ) |
|
| 100 | + : array_diff_key( $entries, $keys ); |
|
| 101 | 101 | return $this; |
| 102 | 102 | } |
| 103 | 103 | |
@@ -105,20 +105,20 @@ discard block |
||
| 105 | 105 | * @param string $template |
| 106 | 106 | * @return string |
| 107 | 107 | */ |
| 108 | - public function render($template, array $entry) |
|
| 108 | + public function render( $template, array $entry ) |
|
| 109 | 109 | { |
| 110 | 110 | $data = array_combine( |
| 111 | - array_map(function ($key) { return 'data.'.$key; }, array_keys($entry)), |
|
| 111 | + array_map( function( $key ) { return 'data.'.$key; }, array_keys( $entry ) ), |
|
| 112 | 112 | $entry |
| 113 | 113 | ); |
| 114 | 114 | $data['data.class'] = $data['data.error'] = ''; |
| 115 | - if (false === array_search($entry['s1'], glsr_array_column($this->entries(), 'msgid'))) { |
|
| 115 | + if( false === array_search( $entry['s1'], glsr_array_column( $this->entries(), 'msgid' ) ) ) { |
|
| 116 | 116 | $data['data.class'] = 'is-invalid'; |
| 117 | - $data['data.error'] = __('This custom translation is no longer valid as the original text has been changed or removed.', 'site-reviews'); |
|
| 117 | + $data['data.error'] = __( 'This custom translation is no longer valid as the original text has been changed or removed.', 'site-reviews' ); |
|
| 118 | 118 | } |
| 119 | - return glsr(Template::class)->build('partials/translations/'.$template, [ |
|
| 120 | - 'context' => array_map('esc_html', $data), |
|
| 121 | - ]); |
|
| 119 | + return glsr( Template::class )->build( 'partials/translations/'.$template, [ |
|
| 120 | + 'context' => array_map( 'esc_html', $data ), |
|
| 121 | + ] ); |
|
| 122 | 122 | } |
| 123 | 123 | |
| 124 | 124 | /** |
@@ -128,10 +128,10 @@ discard block |
||
| 128 | 128 | public function renderAll() |
| 129 | 129 | { |
| 130 | 130 | $rendered = ''; |
| 131 | - foreach ($this->all() as $index => $entry) { |
|
| 131 | + foreach( $this->all() as $index => $entry ) { |
|
| 132 | 132 | $entry['index'] = $index; |
| 133 | 133 | $entry['prefix'] = OptionManager::databaseKey(); |
| 134 | - $rendered.= $this->render($entry['type'], $entry); |
|
| 134 | + $rendered .= $this->render( $entry['type'], $entry ); |
|
| 135 | 135 | } |
| 136 | 136 | return $rendered; |
| 137 | 137 | } |
@@ -140,25 +140,25 @@ discard block |
||
| 140 | 140 | * @param bool $resetAfterRender |
| 141 | 141 | * @return string |
| 142 | 142 | */ |
| 143 | - public function renderResults($resetAfterRender = true) |
|
| 143 | + public function renderResults( $resetAfterRender = true ) |
|
| 144 | 144 | { |
| 145 | 145 | $rendered = ''; |
| 146 | - foreach ($this->results as $id => $entry) { |
|
| 146 | + foreach( $this->results as $id => $entry ) { |
|
| 147 | 147 | $data = [ |
| 148 | - 'desc' => $this->getEntryString($entry, 'msgctxt'), |
|
| 148 | + 'desc' => $this->getEntryString( $entry, 'msgctxt' ), |
|
| 149 | 149 | 'id' => $id, |
| 150 | - 'p1' => $this->getEntryString($entry, 'msgid_plural'), |
|
| 151 | - 's1' => $this->getEntryString($entry, 'msgid'), |
|
| 150 | + 'p1' => $this->getEntryString( $entry, 'msgid_plural' ), |
|
| 151 | + 's1' => $this->getEntryString( $entry, 'msgid' ), |
|
| 152 | 152 | ]; |
| 153 | 153 | $text = !empty($data['p1']) |
| 154 | - ? sprintf('%s | %s', $data['s1'], $data['p1']) |
|
| 154 | + ? sprintf( '%s | %s', $data['s1'], $data['p1'] ) |
|
| 155 | 155 | : $data['s1']; |
| 156 | - $rendered.= $this->render('result', [ |
|
| 157 | - 'entry' => json_encode($data, JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_TAG | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE), |
|
| 158 | - 'text' => wp_strip_all_tags($text), |
|
| 159 | - ]); |
|
| 156 | + $rendered .= $this->render( 'result', [ |
|
| 157 | + 'entry' => json_encode( $data, JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_TAG | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE ), |
|
| 158 | + 'text' => wp_strip_all_tags( $text ), |
|
| 159 | + ] ); |
|
| 160 | 160 | } |
| 161 | - if ($resetAfterRender) { |
|
| 161 | + if( $resetAfterRender ) { |
|
| 162 | 162 | $this->reset(); |
| 163 | 163 | } |
| 164 | 164 | return $rendered; |
@@ -186,18 +186,18 @@ discard block |
||
| 186 | 186 | * @param string $needle |
| 187 | 187 | * @return static |
| 188 | 188 | */ |
| 189 | - public function search($needle = '') |
|
| 189 | + public function search( $needle = '' ) |
|
| 190 | 190 | { |
| 191 | 191 | $this->reset(); |
| 192 | - $needle = trim(strtolower($needle)); |
|
| 193 | - foreach ($this->entries() as $key => $entry) { |
|
| 194 | - $single = strtolower($this->getEntryString($entry, 'msgid')); |
|
| 195 | - $plural = strtolower($this->getEntryString($entry, 'msgid_plural')); |
|
| 196 | - if (strlen($needle) < static::SEARCH_THRESHOLD) { |
|
| 197 | - if (in_array($needle, [$single, $plural])) { |
|
| 192 | + $needle = trim( strtolower( $needle ) ); |
|
| 193 | + foreach( $this->entries() as $key => $entry ) { |
|
| 194 | + $single = strtolower( $this->getEntryString( $entry, 'msgid' ) ); |
|
| 195 | + $plural = strtolower( $this->getEntryString( $entry, 'msgid_plural' ) ); |
|
| 196 | + if( strlen( $needle ) < static::SEARCH_THRESHOLD ) { |
|
| 197 | + if( in_array( $needle, [$single, $plural] ) ) { |
|
| 198 | 198 | $this->results[$key] = $entry; |
| 199 | 199 | } |
| 200 | - } elseif (Str::contains(sprintf('%s %s', $single, $plural), $needle)) { |
|
| 200 | + } elseif( Str::contains( sprintf( '%s %s', $single, $plural ), $needle ) ) { |
|
| 201 | 201 | $this->results[$key] = $entry; |
| 202 | 202 | } |
| 203 | 203 | } |
@@ -211,10 +211,10 @@ discard block |
||
| 211 | 211 | public function translations() |
| 212 | 212 | { |
| 213 | 213 | static $translations; |
| 214 | - if (empty($translations)) { |
|
| 215 | - $settings = glsr(OptionManager::class)->get('settings'); |
|
| 214 | + if( empty($translations) ) { |
|
| 215 | + $settings = glsr( OptionManager::class )->get( 'settings' ); |
|
| 216 | 216 | $translations = isset($settings['strings']) |
| 217 | - ? $this->normalizeSettings((array) $settings['strings']) |
|
| 217 | + ? $this->normalizeSettings( (array)$settings['strings'] ) |
|
| 218 | 218 | : []; |
| 219 | 219 | } |
| 220 | 220 | return $translations; |
@@ -224,28 +224,28 @@ discard block |
||
| 224 | 224 | * @param string $key |
| 225 | 225 | * @return string |
| 226 | 226 | */ |
| 227 | - protected function getEntryString(array $entry, $key) |
|
| 227 | + protected function getEntryString( array $entry, $key ) |
|
| 228 | 228 | { |
| 229 | 229 | return isset($entry[$key]) |
| 230 | - ? implode('', (array) $entry[$key]) |
|
| 230 | + ? implode( '', (array)$entry[$key] ) |
|
| 231 | 231 | : ''; |
| 232 | 232 | } |
| 233 | 233 | |
| 234 | 234 | /** |
| 235 | 235 | * @return array |
| 236 | 236 | */ |
| 237 | - protected function normalize(array $entries) |
|
| 237 | + protected function normalize( array $entries ) |
|
| 238 | 238 | { |
| 239 | 239 | $keys = [ |
| 240 | 240 | 'msgctxt', 'msgid', 'msgid_plural', 'msgstr', 'msgstr[0]', 'msgstr[1]', |
| 241 | 241 | ]; |
| 242 | - array_walk($entries, function (&$entry) use ($keys) { |
|
| 243 | - foreach ($keys as $key) { |
|
| 242 | + array_walk( $entries, function( &$entry ) use ($keys) { |
|
| 243 | + foreach( $keys as $key ) { |
|
| 244 | 244 | try { |
| 245 | - $entry = $this->normalizeEntryString($entry, $key); |
|
| 246 | - } catch (\TypeError $error) { |
|
| 247 | - glsr_log()->once('error', 'Translation/normalize', $error); |
|
| 248 | - glsr_log()->once('debug', 'Translation/normalize', $entry); |
|
| 245 | + $entry = $this->normalizeEntryString( $entry, $key ); |
|
| 246 | + } catch( \TypeError $error ) { |
|
| 247 | + glsr_log()->once( 'error', 'Translation/normalize', $error ); |
|
| 248 | + glsr_log()->once( 'debug', 'Translation/normalize', $entry ); |
|
| 249 | 249 | } |
| 250 | 250 | } |
| 251 | 251 | }); |
@@ -256,10 +256,10 @@ discard block |
||
| 256 | 256 | * @param string $key |
| 257 | 257 | * @return array |
| 258 | 258 | */ |
| 259 | - protected function normalizeEntryString(array $entry, $key) |
|
| 259 | + protected function normalizeEntryString( array $entry, $key ) |
|
| 260 | 260 | { |
| 261 | - if (isset($entry[$key])) { |
|
| 262 | - $entry[$key] = $this->getEntryString($entry, $key); |
|
| 261 | + if( isset($entry[$key]) ) { |
|
| 262 | + $entry[$key] = $this->getEntryString( $entry, $key ); |
|
| 263 | 263 | } |
| 264 | 264 | return $entry; |
| 265 | 265 | } |
@@ -267,15 +267,15 @@ discard block |
||
| 267 | 267 | /** |
| 268 | 268 | * @return array |
| 269 | 269 | */ |
| 270 | - protected function normalizeSettings(array $strings) |
|
| 270 | + protected function normalizeSettings( array $strings ) |
|
| 271 | 271 | { |
| 272 | - $defaultString = array_fill_keys(['id', 's1', 's2', 'p1', 'p2'], ''); |
|
| 273 | - $strings = array_filter($strings, 'is_array'); |
|
| 274 | - foreach ($strings as &$string) { |
|
| 272 | + $defaultString = array_fill_keys( ['id', 's1', 's2', 'p1', 'p2'], '' ); |
|
| 273 | + $strings = array_filter( $strings, 'is_array' ); |
|
| 274 | + foreach( $strings as &$string ) { |
|
| 275 | 275 | $string['type'] = isset($string['p1']) ? 'plural' : 'single'; |
| 276 | - $string = wp_parse_args($string, $defaultString); |
|
| 276 | + $string = wp_parse_args( $string, $defaultString ); |
|
| 277 | 277 | } |
| 278 | - return array_filter($strings, function ($string) { |
|
| 278 | + return array_filter( $strings, function( $string ) { |
|
| 279 | 279 | return !empty($string['id']); |
| 280 | 280 | }); |
| 281 | 281 | } |
@@ -74,7 +74,8 @@ discard block |
||
| 74 | 74 | foreach ($potEntries as $key => $entry) { |
| 75 | 75 | $entries[html_entity_decode($key, ENT_COMPAT, 'UTF-8')] = $entry; |
| 76 | 76 | } |
| 77 | - } catch (Exception $e) { |
|
| 77 | + } |
|
| 78 | + catch (Exception $e) { |
|
| 78 | 79 | glsr_log()->error($e->getMessage()); |
| 79 | 80 | } |
| 80 | 81 | return $entries; |
@@ -197,7 +198,8 @@ discard block |
||
| 197 | 198 | if (in_array($needle, [$single, $plural])) { |
| 198 | 199 | $this->results[$key] = $entry; |
| 199 | 200 | } |
| 200 | - } elseif (Str::contains(sprintf('%s %s', $single, $plural), $needle)) { |
|
| 201 | + } |
|
| 202 | + elseif (Str::contains(sprintf('%s %s', $single, $plural), $needle)) { |
|
| 201 | 203 | $this->results[$key] = $entry; |
| 202 | 204 | } |
| 203 | 205 | } |
@@ -243,7 +245,8 @@ discard block |
||
| 243 | 245 | foreach ($keys as $key) { |
| 244 | 246 | try { |
| 245 | 247 | $entry = $this->normalizeEntryString($entry, $key); |
| 246 | - } catch (\TypeError $error) { |
|
| 248 | + } |
|
| 249 | + catch (\TypeError $error) { |
|
| 247 | 250 | glsr_log()->once('error', 'Translation/normalize', $error); |
| 248 | 251 | glsr_log()->once('debug', 'Translation/normalize', $entry); |
| 249 | 252 | } |
@@ -6,97 +6,97 @@ |
||
| 6 | 6 | |
| 7 | 7 | class Translator |
| 8 | 8 | { |
| 9 | - /** |
|
| 10 | - * @param string $original |
|
| 11 | - * @param string $domain |
|
| 12 | - * @return string |
|
| 13 | - */ |
|
| 14 | - public function translate($original, $domain, array $args) |
|
| 15 | - { |
|
| 16 | - $domains = apply_filters('site-reviews/translator/domains', [Application::ID]); |
|
| 17 | - if (!in_array($domain, $domains)) { |
|
| 18 | - return $original; |
|
| 19 | - } |
|
| 20 | - $args = $this->normalizeTranslationArgs($args); |
|
| 21 | - $strings = $this->getTranslationStrings($args['single'], $args['plural']); |
|
| 22 | - if (empty($strings)) { |
|
| 23 | - return $original; |
|
| 24 | - } |
|
| 25 | - $string = current($strings); |
|
| 26 | - return 'plural' == $string['type'] |
|
| 27 | - ? $this->translatePlural($domain, $string, $args) |
|
| 28 | - : $this->translateSingle($domain, $string, $args); |
|
| 29 | - } |
|
| 9 | + /** |
|
| 10 | + * @param string $original |
|
| 11 | + * @param string $domain |
|
| 12 | + * @return string |
|
| 13 | + */ |
|
| 14 | + public function translate($original, $domain, array $args) |
|
| 15 | + { |
|
| 16 | + $domains = apply_filters('site-reviews/translator/domains', [Application::ID]); |
|
| 17 | + if (!in_array($domain, $domains)) { |
|
| 18 | + return $original; |
|
| 19 | + } |
|
| 20 | + $args = $this->normalizeTranslationArgs($args); |
|
| 21 | + $strings = $this->getTranslationStrings($args['single'], $args['plural']); |
|
| 22 | + if (empty($strings)) { |
|
| 23 | + return $original; |
|
| 24 | + } |
|
| 25 | + $string = current($strings); |
|
| 26 | + return 'plural' == $string['type'] |
|
| 27 | + ? $this->translatePlural($domain, $string, $args) |
|
| 28 | + : $this->translateSingle($domain, $string, $args); |
|
| 29 | + } |
|
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * Used when search/replacing a default text-domain translation |
|
| 33 | - * @return string |
|
| 34 | - */ |
|
| 35 | - public function getTranslation(array $args) |
|
| 36 | - { |
|
| 37 | - $args = $this->normalizeTranslationArgs($args); |
|
| 38 | - return get_translations_for_domain(Application::ID)->translate_plural($args['single'], $args['plural'], $args['number']); |
|
| 39 | - } |
|
| 31 | + /** |
|
| 32 | + * Used when search/replacing a default text-domain translation |
|
| 33 | + * @return string |
|
| 34 | + */ |
|
| 35 | + public function getTranslation(array $args) |
|
| 36 | + { |
|
| 37 | + $args = $this->normalizeTranslationArgs($args); |
|
| 38 | + return get_translations_for_domain(Application::ID)->translate_plural($args['single'], $args['plural'], $args['number']); |
|
| 39 | + } |
|
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * @param string $single |
|
| 43 | - * @param string $plural |
|
| 44 | - * @return array |
|
| 45 | - */ |
|
| 46 | - protected function getTranslationStrings($single, $plural) |
|
| 47 | - { |
|
| 48 | - return array_filter(glsr(Translation::class)->translations(), function ($string) use ($single, $plural) { |
|
| 49 | - return $string['s1'] == html_entity_decode($single, ENT_COMPAT, 'UTF-8') |
|
| 50 | - && $string['p1'] == html_entity_decode($plural, ENT_COMPAT, 'UTF-8'); |
|
| 51 | - }); |
|
| 52 | - } |
|
| 41 | + /** |
|
| 42 | + * @param string $single |
|
| 43 | + * @param string $plural |
|
| 44 | + * @return array |
|
| 45 | + */ |
|
| 46 | + protected function getTranslationStrings($single, $plural) |
|
| 47 | + { |
|
| 48 | + return array_filter(glsr(Translation::class)->translations(), function ($string) use ($single, $plural) { |
|
| 49 | + return $string['s1'] == html_entity_decode($single, ENT_COMPAT, 'UTF-8') |
|
| 50 | + && $string['p1'] == html_entity_decode($plural, ENT_COMPAT, 'UTF-8'); |
|
| 51 | + }); |
|
| 52 | + } |
|
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * @return array |
|
| 56 | - */ |
|
| 57 | - protected function normalizeTranslationArgs(array $args) |
|
| 58 | - { |
|
| 59 | - $defaults = [ |
|
| 60 | - 'context' => '', |
|
| 61 | - 'number' => 1, |
|
| 62 | - 'plural' => '', |
|
| 63 | - 'single' => '', |
|
| 64 | - ]; |
|
| 65 | - return shortcode_atts($defaults, $args); |
|
| 66 | - } |
|
| 54 | + /** |
|
| 55 | + * @return array |
|
| 56 | + */ |
|
| 57 | + protected function normalizeTranslationArgs(array $args) |
|
| 58 | + { |
|
| 59 | + $defaults = [ |
|
| 60 | + 'context' => '', |
|
| 61 | + 'number' => 1, |
|
| 62 | + 'plural' => '', |
|
| 63 | + 'single' => '', |
|
| 64 | + ]; |
|
| 65 | + return shortcode_atts($defaults, $args); |
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | - /** |
|
| 69 | - * @param string $domain |
|
| 70 | - * @return string |
|
| 71 | - */ |
|
| 72 | - protected function translatePlural($domain, array $string, array $args) |
|
| 73 | - { |
|
| 74 | - if (!empty($string['s2'])) { |
|
| 75 | - $args['single'] = $string['s2']; |
|
| 76 | - } |
|
| 77 | - if (!empty($string['p2'])) { |
|
| 78 | - $args['plural'] = $string['p2']; |
|
| 79 | - } |
|
| 80 | - return get_translations_for_domain($domain)->translate_plural( |
|
| 81 | - $args['single'], |
|
| 82 | - $args['plural'], |
|
| 83 | - $args['number'], |
|
| 84 | - $args['context'] |
|
| 85 | - ); |
|
| 86 | - } |
|
| 68 | + /** |
|
| 69 | + * @param string $domain |
|
| 70 | + * @return string |
|
| 71 | + */ |
|
| 72 | + protected function translatePlural($domain, array $string, array $args) |
|
| 73 | + { |
|
| 74 | + if (!empty($string['s2'])) { |
|
| 75 | + $args['single'] = $string['s2']; |
|
| 76 | + } |
|
| 77 | + if (!empty($string['p2'])) { |
|
| 78 | + $args['plural'] = $string['p2']; |
|
| 79 | + } |
|
| 80 | + return get_translations_for_domain($domain)->translate_plural( |
|
| 81 | + $args['single'], |
|
| 82 | + $args['plural'], |
|
| 83 | + $args['number'], |
|
| 84 | + $args['context'] |
|
| 85 | + ); |
|
| 86 | + } |
|
| 87 | 87 | |
| 88 | - /** |
|
| 89 | - * @param string $domain |
|
| 90 | - * @return string |
|
| 91 | - */ |
|
| 92 | - protected function translateSingle($domain, array $string, array $args) |
|
| 93 | - { |
|
| 94 | - if (!empty($string['s2'])) { |
|
| 95 | - $args['single'] = $string['s2']; |
|
| 96 | - } |
|
| 97 | - return get_translations_for_domain($domain)->translate( |
|
| 98 | - $args['single'], |
|
| 99 | - $args['context'] |
|
| 100 | - ); |
|
| 101 | - } |
|
| 88 | + /** |
|
| 89 | + * @param string $domain |
|
| 90 | + * @return string |
|
| 91 | + */ |
|
| 92 | + protected function translateSingle($domain, array $string, array $args) |
|
| 93 | + { |
|
| 94 | + if (!empty($string['s2'])) { |
|
| 95 | + $args['single'] = $string['s2']; |
|
| 96 | + } |
|
| 97 | + return get_translations_for_domain($domain)->translate( |
|
| 98 | + $args['single'], |
|
| 99 | + $args['context'] |
|
| 100 | + ); |
|
| 101 | + } |
|
| 102 | 102 | } |
@@ -11,31 +11,31 @@ discard block |
||
| 11 | 11 | * @param string $domain |
| 12 | 12 | * @return string |
| 13 | 13 | */ |
| 14 | - public function translate($original, $domain, array $args) |
|
| 14 | + public function translate( $original, $domain, array $args ) |
|
| 15 | 15 | { |
| 16 | - $domains = apply_filters('site-reviews/translator/domains', [Application::ID]); |
|
| 17 | - if (!in_array($domain, $domains)) { |
|
| 16 | + $domains = apply_filters( 'site-reviews/translator/domains', [Application::ID] ); |
|
| 17 | + if( !in_array( $domain, $domains ) ) { |
|
| 18 | 18 | return $original; |
| 19 | 19 | } |
| 20 | - $args = $this->normalizeTranslationArgs($args); |
|
| 21 | - $strings = $this->getTranslationStrings($args['single'], $args['plural']); |
|
| 22 | - if (empty($strings)) { |
|
| 20 | + $args = $this->normalizeTranslationArgs( $args ); |
|
| 21 | + $strings = $this->getTranslationStrings( $args['single'], $args['plural'] ); |
|
| 22 | + if( empty($strings) ) { |
|
| 23 | 23 | return $original; |
| 24 | 24 | } |
| 25 | - $string = current($strings); |
|
| 25 | + $string = current( $strings ); |
|
| 26 | 26 | return 'plural' == $string['type'] |
| 27 | - ? $this->translatePlural($domain, $string, $args) |
|
| 28 | - : $this->translateSingle($domain, $string, $args); |
|
| 27 | + ? $this->translatePlural( $domain, $string, $args ) |
|
| 28 | + : $this->translateSingle( $domain, $string, $args ); |
|
| 29 | 29 | } |
| 30 | 30 | |
| 31 | 31 | /** |
| 32 | 32 | * Used when search/replacing a default text-domain translation |
| 33 | 33 | * @return string |
| 34 | 34 | */ |
| 35 | - public function getTranslation(array $args) |
|
| 35 | + public function getTranslation( array $args ) |
|
| 36 | 36 | { |
| 37 | - $args = $this->normalizeTranslationArgs($args); |
|
| 38 | - return get_translations_for_domain(Application::ID)->translate_plural($args['single'], $args['plural'], $args['number']); |
|
| 37 | + $args = $this->normalizeTranslationArgs( $args ); |
|
| 38 | + return get_translations_for_domain( Application::ID )->translate_plural( $args['single'], $args['plural'], $args['number'] ); |
|
| 39 | 39 | } |
| 40 | 40 | |
| 41 | 41 | /** |
@@ -43,18 +43,18 @@ discard block |
||
| 43 | 43 | * @param string $plural |
| 44 | 44 | * @return array |
| 45 | 45 | */ |
| 46 | - protected function getTranslationStrings($single, $plural) |
|
| 46 | + protected function getTranslationStrings( $single, $plural ) |
|
| 47 | 47 | { |
| 48 | - return array_filter(glsr(Translation::class)->translations(), function ($string) use ($single, $plural) { |
|
| 49 | - return $string['s1'] == html_entity_decode($single, ENT_COMPAT, 'UTF-8') |
|
| 50 | - && $string['p1'] == html_entity_decode($plural, ENT_COMPAT, 'UTF-8'); |
|
| 48 | + return array_filter( glsr( Translation::class )->translations(), function( $string ) use ($single, $plural) { |
|
| 49 | + return $string['s1'] == html_entity_decode( $single, ENT_COMPAT, 'UTF-8' ) |
|
| 50 | + && $string['p1'] == html_entity_decode( $plural, ENT_COMPAT, 'UTF-8' ); |
|
| 51 | 51 | }); |
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | /** |
| 55 | 55 | * @return array |
| 56 | 56 | */ |
| 57 | - protected function normalizeTranslationArgs(array $args) |
|
| 57 | + protected function normalizeTranslationArgs( array $args ) |
|
| 58 | 58 | { |
| 59 | 59 | $defaults = [ |
| 60 | 60 | 'context' => '', |
@@ -62,22 +62,22 @@ discard block |
||
| 62 | 62 | 'plural' => '', |
| 63 | 63 | 'single' => '', |
| 64 | 64 | ]; |
| 65 | - return shortcode_atts($defaults, $args); |
|
| 65 | + return shortcode_atts( $defaults, $args ); |
|
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | /** |
| 69 | 69 | * @param string $domain |
| 70 | 70 | * @return string |
| 71 | 71 | */ |
| 72 | - protected function translatePlural($domain, array $string, array $args) |
|
| 72 | + protected function translatePlural( $domain, array $string, array $args ) |
|
| 73 | 73 | { |
| 74 | - if (!empty($string['s2'])) { |
|
| 74 | + if( !empty($string['s2']) ) { |
|
| 75 | 75 | $args['single'] = $string['s2']; |
| 76 | 76 | } |
| 77 | - if (!empty($string['p2'])) { |
|
| 77 | + if( !empty($string['p2']) ) { |
|
| 78 | 78 | $args['plural'] = $string['p2']; |
| 79 | 79 | } |
| 80 | - return get_translations_for_domain($domain)->translate_plural( |
|
| 80 | + return get_translations_for_domain( $domain )->translate_plural( |
|
| 81 | 81 | $args['single'], |
| 82 | 82 | $args['plural'], |
| 83 | 83 | $args['number'], |
@@ -89,12 +89,12 @@ discard block |
||
| 89 | 89 | * @param string $domain |
| 90 | 90 | * @return string |
| 91 | 91 | */ |
| 92 | - protected function translateSingle($domain, array $string, array $args) |
|
| 92 | + protected function translateSingle( $domain, array $string, array $args ) |
|
| 93 | 93 | { |
| 94 | - if (!empty($string['s2'])) { |
|
| 94 | + if( !empty($string['s2']) ) { |
|
| 95 | 95 | $args['single'] = $string['s2']; |
| 96 | 96 | } |
| 97 | - return get_translations_for_domain($domain)->translate( |
|
| 97 | + return get_translations_for_domain( $domain )->translate( |
|
| 98 | 98 | $args['single'], |
| 99 | 99 | $args['context'] |
| 100 | 100 | ); |
@@ -10,228 +10,228 @@ |
||
| 10 | 10 | |
| 11 | 11 | class TranslationController |
| 12 | 12 | { |
| 13 | - /** |
|
| 14 | - * @var Translator |
|
| 15 | - */ |
|
| 16 | - public $translator; |
|
| 17 | - |
|
| 18 | - public function __construct(Translator $translator) |
|
| 19 | - { |
|
| 20 | - $this->translator = $translator; |
|
| 21 | - } |
|
| 22 | - |
|
| 23 | - /** |
|
| 24 | - * @param array $messages |
|
| 25 | - * @return array |
|
| 26 | - * @filter bulk_post_updated_messages |
|
| 27 | - */ |
|
| 28 | - public function filterBulkUpdateMessages($messages, array $counts) |
|
| 29 | - { |
|
| 30 | - $messages = Arr::consolidateArray($messages); |
|
| 31 | - $messages[Application::POST_TYPE] = [ |
|
| 32 | - 'updated' => _n('%s review updated.', '%s reviews updated.', $counts['updated'], 'site-reviews'), |
|
| 33 | - 'locked' => _n('%s review not updated, somebody is editing it.', '%s reviews not updated, somebody is editing them.', $counts['locked'], 'site-reviews'), |
|
| 34 | - 'deleted' => _n('%s review permanently deleted.', '%s reviews permanently deleted.', $counts['deleted'], 'site-reviews'), |
|
| 35 | - 'trashed' => _n('%s review moved to the Trash.', '%s reviews moved to the Trash.', $counts['trashed'], 'site-reviews'), |
|
| 36 | - 'untrashed' => _n('%s review restored from the Trash.', '%s reviews restored from the Trash.', $counts['untrashed'], 'site-reviews'), |
|
| 37 | - ]; |
|
| 38 | - return $messages; |
|
| 39 | - } |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * @param string $translation |
|
| 43 | - * @param string $text |
|
| 44 | - * @param string $domain |
|
| 45 | - * @return string |
|
| 46 | - * @filter gettext |
|
| 47 | - */ |
|
| 48 | - public function filterGettext($translation, $text, $domain) |
|
| 49 | - { |
|
| 50 | - return apply_filters('site-reviews/gettext/'.$domain, $translation, $text); |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * @param string $translation |
|
| 55 | - * @param string $text |
|
| 56 | - * @return string |
|
| 57 | - * @filter site-reviews/gettext/site-reviews |
|
| 58 | - */ |
|
| 59 | - public function filterGettextSiteReviews($translation, $text) |
|
| 60 | - { |
|
| 61 | - return $this->translator->translate($translation, Application::ID, [ |
|
| 62 | - 'single' => $text, |
|
| 63 | - ]); |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - /** |
|
| 67 | - * @param string $translation |
|
| 68 | - * @param string $text |
|
| 69 | - * @param string $context |
|
| 70 | - * @param string $domain |
|
| 71 | - * @return string |
|
| 72 | - * @filter gettext_with_context |
|
| 73 | - */ |
|
| 74 | - public function filterGettextWithContext($translation, $text, $context, $domain) |
|
| 75 | - { |
|
| 76 | - return apply_filters('site-reviews/gettext_with_context/'.$domain, $translation, $text, $context); |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - /** |
|
| 80 | - * @param string $translation |
|
| 81 | - * @param string $text |
|
| 82 | - * @param string $context |
|
| 83 | - * @return string |
|
| 84 | - * @filter site-reviews/gettext_with_context/site-reviews |
|
| 85 | - */ |
|
| 86 | - public function filterGettextWithContextSiteReviews($translation, $text, $context) |
|
| 87 | - { |
|
| 88 | - return $this->translator->translate($translation, Application::ID, [ |
|
| 89 | - 'context' => $context, |
|
| 90 | - 'single' => $text, |
|
| 91 | - ]); |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - /** |
|
| 95 | - * @param string $translation |
|
| 96 | - * @param string $single |
|
| 97 | - * @param string $plural |
|
| 98 | - * @param int $number |
|
| 99 | - * @param string $domain |
|
| 100 | - * @return string |
|
| 101 | - * @filter ngettext |
|
| 102 | - */ |
|
| 103 | - public function filterNgettext($translation, $single, $plural, $number, $domain) |
|
| 104 | - { |
|
| 105 | - return apply_filters('site-reviews/ngettext/'.$domain, $translation, $single, $plural, $number); |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - /** |
|
| 109 | - * @param string $translation |
|
| 110 | - * @param string $single |
|
| 111 | - * @param string $plural |
|
| 112 | - * @param int $number |
|
| 113 | - * @return string |
|
| 114 | - * @filter site-reviews/ngettext/site-reviews |
|
| 115 | - */ |
|
| 116 | - public function filterNgettextSiteReviews($translation, $single, $plural, $number) |
|
| 117 | - { |
|
| 118 | - return $this->translator->translate($translation, Application::ID, [ |
|
| 119 | - 'number' => $number, |
|
| 120 | - 'plural' => $plural, |
|
| 121 | - 'single' => $single, |
|
| 122 | - ]); |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - /** |
|
| 126 | - * @param string $translation |
|
| 127 | - * @param string $single |
|
| 128 | - * @param string $plural |
|
| 129 | - * @param int $number |
|
| 130 | - * @param string $context |
|
| 131 | - * @param string $domain |
|
| 132 | - * @return string |
|
| 133 | - * @filter ngettext_with_context |
|
| 134 | - */ |
|
| 135 | - public function filterNgettextWithContext($translation, $single, $plural, $number, $context, $domain) |
|
| 136 | - { |
|
| 137 | - return apply_filters('site-reviews/ngettext_with_context/'.$domain, $translation, $single, $plural, $number, $context); |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - /** |
|
| 141 | - * @param string $translation |
|
| 142 | - * @param string $single |
|
| 143 | - * @param string $plural |
|
| 144 | - * @param int $number |
|
| 145 | - * @param string $context |
|
| 146 | - * @return string |
|
| 147 | - * @filter site-reviews/ngettext_with_context/site-reviews |
|
| 148 | - */ |
|
| 149 | - public function filterNgettextWithContextSiteReviews($translation, $single, $plural, $number, $context) |
|
| 150 | - { |
|
| 151 | - return $this->translator->translate($translation, Application::ID, [ |
|
| 152 | - 'context' => $context, |
|
| 153 | - 'number' => $number, |
|
| 154 | - 'plural' => $plural, |
|
| 155 | - 'single' => $single, |
|
| 156 | - ]); |
|
| 157 | - } |
|
| 158 | - |
|
| 159 | - /** |
|
| 160 | - * @param array $postStates |
|
| 161 | - * @param \WP_Post $post |
|
| 162 | - * @return array |
|
| 163 | - * @filter display_post_states |
|
| 164 | - */ |
|
| 165 | - public function filterPostStates($postStates, $post) |
|
| 166 | - { |
|
| 167 | - $postStates = Arr::consolidateArray($postStates); |
|
| 168 | - if (Application::POST_TYPE == Arr::get($post, 'post_type') && array_key_exists('pending', $postStates)) { |
|
| 169 | - $postStates['pending'] = __('Unapproved', 'site-reviews'); |
|
| 170 | - } |
|
| 171 | - return $postStates; |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - /** |
|
| 175 | - * @param string $translation |
|
| 176 | - * @param string $text |
|
| 177 | - * @return string |
|
| 178 | - * @filter site-reviews/gettext/default |
|
| 179 | - * @filter site-reviews/gettext_with_context/default |
|
| 180 | - */ |
|
| 181 | - public function filterPostStatusLabels($translation, $text) |
|
| 182 | - { |
|
| 183 | - return $this->canModifyTranslation() |
|
| 184 | - ? glsr(Labels::class)->filterPostStatusLabels($translation, $text) |
|
| 185 | - : $translation; |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - /** |
|
| 189 | - * @param string $translation |
|
| 190 | - * @param string $single |
|
| 191 | - * @param string $plural |
|
| 192 | - * @param int $number |
|
| 193 | - * @return string |
|
| 194 | - * @filter site-reviews/ngettext/default |
|
| 195 | - */ |
|
| 196 | - public function filterPostStatusText($translation, $single, $plural, $number) |
|
| 197 | - { |
|
| 198 | - if ($this->canModifyTranslation()) { |
|
| 199 | - $strings = [ |
|
| 200 | - 'Published' => __('Approved', 'site-reviews'), |
|
| 201 | - 'Pending' => __('Unapproved', 'site-reviews'), |
|
| 202 | - ]; |
|
| 203 | - foreach ($strings as $search => $replace) { |
|
| 204 | - if (!Str::contains($single, $search)) { |
|
| 205 | - continue; |
|
| 206 | - } |
|
| 207 | - return $this->translator->getTranslation([ |
|
| 208 | - 'number' => $number, |
|
| 209 | - 'plural' => str_replace($search, $replace, $plural), |
|
| 210 | - 'single' => str_replace($search, $replace, $single), |
|
| 211 | - ]); |
|
| 212 | - } |
|
| 213 | - } |
|
| 214 | - return $translation; |
|
| 215 | - } |
|
| 216 | - |
|
| 217 | - /** |
|
| 218 | - * @return void |
|
| 219 | - * @action admin_enqueue_scripts |
|
| 220 | - */ |
|
| 221 | - public function translatePostStatusLabels() |
|
| 222 | - { |
|
| 223 | - if ($this->canModifyTranslation()) { |
|
| 224 | - glsr(Labels::class)->translatePostStatusLabels(); |
|
| 225 | - } |
|
| 226 | - } |
|
| 227 | - |
|
| 228 | - /** |
|
| 229 | - * @return bool |
|
| 230 | - */ |
|
| 231 | - protected function canModifyTranslation() |
|
| 232 | - { |
|
| 233 | - $screen = glsr_current_screen(); |
|
| 234 | - return Application::POST_TYPE == $screen->post_type |
|
| 235 | - && in_array($screen->base, ['edit', 'post']); |
|
| 236 | - } |
|
| 13 | + /** |
|
| 14 | + * @var Translator |
|
| 15 | + */ |
|
| 16 | + public $translator; |
|
| 17 | + |
|
| 18 | + public function __construct(Translator $translator) |
|
| 19 | + { |
|
| 20 | + $this->translator = $translator; |
|
| 21 | + } |
|
| 22 | + |
|
| 23 | + /** |
|
| 24 | + * @param array $messages |
|
| 25 | + * @return array |
|
| 26 | + * @filter bulk_post_updated_messages |
|
| 27 | + */ |
|
| 28 | + public function filterBulkUpdateMessages($messages, array $counts) |
|
| 29 | + { |
|
| 30 | + $messages = Arr::consolidateArray($messages); |
|
| 31 | + $messages[Application::POST_TYPE] = [ |
|
| 32 | + 'updated' => _n('%s review updated.', '%s reviews updated.', $counts['updated'], 'site-reviews'), |
|
| 33 | + 'locked' => _n('%s review not updated, somebody is editing it.', '%s reviews not updated, somebody is editing them.', $counts['locked'], 'site-reviews'), |
|
| 34 | + 'deleted' => _n('%s review permanently deleted.', '%s reviews permanently deleted.', $counts['deleted'], 'site-reviews'), |
|
| 35 | + 'trashed' => _n('%s review moved to the Trash.', '%s reviews moved to the Trash.', $counts['trashed'], 'site-reviews'), |
|
| 36 | + 'untrashed' => _n('%s review restored from the Trash.', '%s reviews restored from the Trash.', $counts['untrashed'], 'site-reviews'), |
|
| 37 | + ]; |
|
| 38 | + return $messages; |
|
| 39 | + } |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * @param string $translation |
|
| 43 | + * @param string $text |
|
| 44 | + * @param string $domain |
|
| 45 | + * @return string |
|
| 46 | + * @filter gettext |
|
| 47 | + */ |
|
| 48 | + public function filterGettext($translation, $text, $domain) |
|
| 49 | + { |
|
| 50 | + return apply_filters('site-reviews/gettext/'.$domain, $translation, $text); |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * @param string $translation |
|
| 55 | + * @param string $text |
|
| 56 | + * @return string |
|
| 57 | + * @filter site-reviews/gettext/site-reviews |
|
| 58 | + */ |
|
| 59 | + public function filterGettextSiteReviews($translation, $text) |
|
| 60 | + { |
|
| 61 | + return $this->translator->translate($translation, Application::ID, [ |
|
| 62 | + 'single' => $text, |
|
| 63 | + ]); |
|
| 64 | + } |
|
| 65 | + |
|
| 66 | + /** |
|
| 67 | + * @param string $translation |
|
| 68 | + * @param string $text |
|
| 69 | + * @param string $context |
|
| 70 | + * @param string $domain |
|
| 71 | + * @return string |
|
| 72 | + * @filter gettext_with_context |
|
| 73 | + */ |
|
| 74 | + public function filterGettextWithContext($translation, $text, $context, $domain) |
|
| 75 | + { |
|
| 76 | + return apply_filters('site-reviews/gettext_with_context/'.$domain, $translation, $text, $context); |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + /** |
|
| 80 | + * @param string $translation |
|
| 81 | + * @param string $text |
|
| 82 | + * @param string $context |
|
| 83 | + * @return string |
|
| 84 | + * @filter site-reviews/gettext_with_context/site-reviews |
|
| 85 | + */ |
|
| 86 | + public function filterGettextWithContextSiteReviews($translation, $text, $context) |
|
| 87 | + { |
|
| 88 | + return $this->translator->translate($translation, Application::ID, [ |
|
| 89 | + 'context' => $context, |
|
| 90 | + 'single' => $text, |
|
| 91 | + ]); |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + /** |
|
| 95 | + * @param string $translation |
|
| 96 | + * @param string $single |
|
| 97 | + * @param string $plural |
|
| 98 | + * @param int $number |
|
| 99 | + * @param string $domain |
|
| 100 | + * @return string |
|
| 101 | + * @filter ngettext |
|
| 102 | + */ |
|
| 103 | + public function filterNgettext($translation, $single, $plural, $number, $domain) |
|
| 104 | + { |
|
| 105 | + return apply_filters('site-reviews/ngettext/'.$domain, $translation, $single, $plural, $number); |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + /** |
|
| 109 | + * @param string $translation |
|
| 110 | + * @param string $single |
|
| 111 | + * @param string $plural |
|
| 112 | + * @param int $number |
|
| 113 | + * @return string |
|
| 114 | + * @filter site-reviews/ngettext/site-reviews |
|
| 115 | + */ |
|
| 116 | + public function filterNgettextSiteReviews($translation, $single, $plural, $number) |
|
| 117 | + { |
|
| 118 | + return $this->translator->translate($translation, Application::ID, [ |
|
| 119 | + 'number' => $number, |
|
| 120 | + 'plural' => $plural, |
|
| 121 | + 'single' => $single, |
|
| 122 | + ]); |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + /** |
|
| 126 | + * @param string $translation |
|
| 127 | + * @param string $single |
|
| 128 | + * @param string $plural |
|
| 129 | + * @param int $number |
|
| 130 | + * @param string $context |
|
| 131 | + * @param string $domain |
|
| 132 | + * @return string |
|
| 133 | + * @filter ngettext_with_context |
|
| 134 | + */ |
|
| 135 | + public function filterNgettextWithContext($translation, $single, $plural, $number, $context, $domain) |
|
| 136 | + { |
|
| 137 | + return apply_filters('site-reviews/ngettext_with_context/'.$domain, $translation, $single, $plural, $number, $context); |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + /** |
|
| 141 | + * @param string $translation |
|
| 142 | + * @param string $single |
|
| 143 | + * @param string $plural |
|
| 144 | + * @param int $number |
|
| 145 | + * @param string $context |
|
| 146 | + * @return string |
|
| 147 | + * @filter site-reviews/ngettext_with_context/site-reviews |
|
| 148 | + */ |
|
| 149 | + public function filterNgettextWithContextSiteReviews($translation, $single, $plural, $number, $context) |
|
| 150 | + { |
|
| 151 | + return $this->translator->translate($translation, Application::ID, [ |
|
| 152 | + 'context' => $context, |
|
| 153 | + 'number' => $number, |
|
| 154 | + 'plural' => $plural, |
|
| 155 | + 'single' => $single, |
|
| 156 | + ]); |
|
| 157 | + } |
|
| 158 | + |
|
| 159 | + /** |
|
| 160 | + * @param array $postStates |
|
| 161 | + * @param \WP_Post $post |
|
| 162 | + * @return array |
|
| 163 | + * @filter display_post_states |
|
| 164 | + */ |
|
| 165 | + public function filterPostStates($postStates, $post) |
|
| 166 | + { |
|
| 167 | + $postStates = Arr::consolidateArray($postStates); |
|
| 168 | + if (Application::POST_TYPE == Arr::get($post, 'post_type') && array_key_exists('pending', $postStates)) { |
|
| 169 | + $postStates['pending'] = __('Unapproved', 'site-reviews'); |
|
| 170 | + } |
|
| 171 | + return $postStates; |
|
| 172 | + } |
|
| 173 | + |
|
| 174 | + /** |
|
| 175 | + * @param string $translation |
|
| 176 | + * @param string $text |
|
| 177 | + * @return string |
|
| 178 | + * @filter site-reviews/gettext/default |
|
| 179 | + * @filter site-reviews/gettext_with_context/default |
|
| 180 | + */ |
|
| 181 | + public function filterPostStatusLabels($translation, $text) |
|
| 182 | + { |
|
| 183 | + return $this->canModifyTranslation() |
|
| 184 | + ? glsr(Labels::class)->filterPostStatusLabels($translation, $text) |
|
| 185 | + : $translation; |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + /** |
|
| 189 | + * @param string $translation |
|
| 190 | + * @param string $single |
|
| 191 | + * @param string $plural |
|
| 192 | + * @param int $number |
|
| 193 | + * @return string |
|
| 194 | + * @filter site-reviews/ngettext/default |
|
| 195 | + */ |
|
| 196 | + public function filterPostStatusText($translation, $single, $plural, $number) |
|
| 197 | + { |
|
| 198 | + if ($this->canModifyTranslation()) { |
|
| 199 | + $strings = [ |
|
| 200 | + 'Published' => __('Approved', 'site-reviews'), |
|
| 201 | + 'Pending' => __('Unapproved', 'site-reviews'), |
|
| 202 | + ]; |
|
| 203 | + foreach ($strings as $search => $replace) { |
|
| 204 | + if (!Str::contains($single, $search)) { |
|
| 205 | + continue; |
|
| 206 | + } |
|
| 207 | + return $this->translator->getTranslation([ |
|
| 208 | + 'number' => $number, |
|
| 209 | + 'plural' => str_replace($search, $replace, $plural), |
|
| 210 | + 'single' => str_replace($search, $replace, $single), |
|
| 211 | + ]); |
|
| 212 | + } |
|
| 213 | + } |
|
| 214 | + return $translation; |
|
| 215 | + } |
|
| 216 | + |
|
| 217 | + /** |
|
| 218 | + * @return void |
|
| 219 | + * @action admin_enqueue_scripts |
|
| 220 | + */ |
|
| 221 | + public function translatePostStatusLabels() |
|
| 222 | + { |
|
| 223 | + if ($this->canModifyTranslation()) { |
|
| 224 | + glsr(Labels::class)->translatePostStatusLabels(); |
|
| 225 | + } |
|
| 226 | + } |
|
| 227 | + |
|
| 228 | + /** |
|
| 229 | + * @return bool |
|
| 230 | + */ |
|
| 231 | + protected function canModifyTranslation() |
|
| 232 | + { |
|
| 233 | + $screen = glsr_current_screen(); |
|
| 234 | + return Application::POST_TYPE == $screen->post_type |
|
| 235 | + && in_array($screen->base, ['edit', 'post']); |
|
| 236 | + } |
|
| 237 | 237 | } |
@@ -15,7 +15,7 @@ discard block |
||
| 15 | 15 | */ |
| 16 | 16 | public $translator; |
| 17 | 17 | |
| 18 | - public function __construct(Translator $translator) |
|
| 18 | + public function __construct( Translator $translator ) |
|
| 19 | 19 | { |
| 20 | 20 | $this->translator = $translator; |
| 21 | 21 | } |
@@ -25,15 +25,15 @@ discard block |
||
| 25 | 25 | * @return array |
| 26 | 26 | * @filter bulk_post_updated_messages |
| 27 | 27 | */ |
| 28 | - public function filterBulkUpdateMessages($messages, array $counts) |
|
| 28 | + public function filterBulkUpdateMessages( $messages, array $counts ) |
|
| 29 | 29 | { |
| 30 | - $messages = Arr::consolidateArray($messages); |
|
| 30 | + $messages = Arr::consolidateArray( $messages ); |
|
| 31 | 31 | $messages[Application::POST_TYPE] = [ |
| 32 | - 'updated' => _n('%s review updated.', '%s reviews updated.', $counts['updated'], 'site-reviews'), |
|
| 33 | - 'locked' => _n('%s review not updated, somebody is editing it.', '%s reviews not updated, somebody is editing them.', $counts['locked'], 'site-reviews'), |
|
| 34 | - 'deleted' => _n('%s review permanently deleted.', '%s reviews permanently deleted.', $counts['deleted'], 'site-reviews'), |
|
| 35 | - 'trashed' => _n('%s review moved to the Trash.', '%s reviews moved to the Trash.', $counts['trashed'], 'site-reviews'), |
|
| 36 | - 'untrashed' => _n('%s review restored from the Trash.', '%s reviews restored from the Trash.', $counts['untrashed'], 'site-reviews'), |
|
| 32 | + 'updated' => _n( '%s review updated.', '%s reviews updated.', $counts['updated'], 'site-reviews' ), |
|
| 33 | + 'locked' => _n( '%s review not updated, somebody is editing it.', '%s reviews not updated, somebody is editing them.', $counts['locked'], 'site-reviews' ), |
|
| 34 | + 'deleted' => _n( '%s review permanently deleted.', '%s reviews permanently deleted.', $counts['deleted'], 'site-reviews' ), |
|
| 35 | + 'trashed' => _n( '%s review moved to the Trash.', '%s reviews moved to the Trash.', $counts['trashed'], 'site-reviews' ), |
|
| 36 | + 'untrashed' => _n( '%s review restored from the Trash.', '%s reviews restored from the Trash.', $counts['untrashed'], 'site-reviews' ), |
|
| 37 | 37 | ]; |
| 38 | 38 | return $messages; |
| 39 | 39 | } |
@@ -45,9 +45,9 @@ discard block |
||
| 45 | 45 | * @return string |
| 46 | 46 | * @filter gettext |
| 47 | 47 | */ |
| 48 | - public function filterGettext($translation, $text, $domain) |
|
| 48 | + public function filterGettext( $translation, $text, $domain ) |
|
| 49 | 49 | { |
| 50 | - return apply_filters('site-reviews/gettext/'.$domain, $translation, $text); |
|
| 50 | + return apply_filters( 'site-reviews/gettext/'.$domain, $translation, $text ); |
|
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | /** |
@@ -56,11 +56,11 @@ discard block |
||
| 56 | 56 | * @return string |
| 57 | 57 | * @filter site-reviews/gettext/site-reviews |
| 58 | 58 | */ |
| 59 | - public function filterGettextSiteReviews($translation, $text) |
|
| 59 | + public function filterGettextSiteReviews( $translation, $text ) |
|
| 60 | 60 | { |
| 61 | - return $this->translator->translate($translation, Application::ID, [ |
|
| 61 | + return $this->translator->translate( $translation, Application::ID, [ |
|
| 62 | 62 | 'single' => $text, |
| 63 | - ]); |
|
| 63 | + ] ); |
|
| 64 | 64 | } |
| 65 | 65 | |
| 66 | 66 | /** |
@@ -71,9 +71,9 @@ discard block |
||
| 71 | 71 | * @return string |
| 72 | 72 | * @filter gettext_with_context |
| 73 | 73 | */ |
| 74 | - public function filterGettextWithContext($translation, $text, $context, $domain) |
|
| 74 | + public function filterGettextWithContext( $translation, $text, $context, $domain ) |
|
| 75 | 75 | { |
| 76 | - return apply_filters('site-reviews/gettext_with_context/'.$domain, $translation, $text, $context); |
|
| 76 | + return apply_filters( 'site-reviews/gettext_with_context/'.$domain, $translation, $text, $context ); |
|
| 77 | 77 | } |
| 78 | 78 | |
| 79 | 79 | /** |
@@ -83,12 +83,12 @@ discard block |
||
| 83 | 83 | * @return string |
| 84 | 84 | * @filter site-reviews/gettext_with_context/site-reviews |
| 85 | 85 | */ |
| 86 | - public function filterGettextWithContextSiteReviews($translation, $text, $context) |
|
| 86 | + public function filterGettextWithContextSiteReviews( $translation, $text, $context ) |
|
| 87 | 87 | { |
| 88 | - return $this->translator->translate($translation, Application::ID, [ |
|
| 88 | + return $this->translator->translate( $translation, Application::ID, [ |
|
| 89 | 89 | 'context' => $context, |
| 90 | 90 | 'single' => $text, |
| 91 | - ]); |
|
| 91 | + ] ); |
|
| 92 | 92 | } |
| 93 | 93 | |
| 94 | 94 | /** |
@@ -100,9 +100,9 @@ discard block |
||
| 100 | 100 | * @return string |
| 101 | 101 | * @filter ngettext |
| 102 | 102 | */ |
| 103 | - public function filterNgettext($translation, $single, $plural, $number, $domain) |
|
| 103 | + public function filterNgettext( $translation, $single, $plural, $number, $domain ) |
|
| 104 | 104 | { |
| 105 | - return apply_filters('site-reviews/ngettext/'.$domain, $translation, $single, $plural, $number); |
|
| 105 | + return apply_filters( 'site-reviews/ngettext/'.$domain, $translation, $single, $plural, $number ); |
|
| 106 | 106 | } |
| 107 | 107 | |
| 108 | 108 | /** |
@@ -113,13 +113,13 @@ discard block |
||
| 113 | 113 | * @return string |
| 114 | 114 | * @filter site-reviews/ngettext/site-reviews |
| 115 | 115 | */ |
| 116 | - public function filterNgettextSiteReviews($translation, $single, $plural, $number) |
|
| 116 | + public function filterNgettextSiteReviews( $translation, $single, $plural, $number ) |
|
| 117 | 117 | { |
| 118 | - return $this->translator->translate($translation, Application::ID, [ |
|
| 118 | + return $this->translator->translate( $translation, Application::ID, [ |
|
| 119 | 119 | 'number' => $number, |
| 120 | 120 | 'plural' => $plural, |
| 121 | 121 | 'single' => $single, |
| 122 | - ]); |
|
| 122 | + ] ); |
|
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | /** |
@@ -132,9 +132,9 @@ discard block |
||
| 132 | 132 | * @return string |
| 133 | 133 | * @filter ngettext_with_context |
| 134 | 134 | */ |
| 135 | - public function filterNgettextWithContext($translation, $single, $plural, $number, $context, $domain) |
|
| 135 | + public function filterNgettextWithContext( $translation, $single, $plural, $number, $context, $domain ) |
|
| 136 | 136 | { |
| 137 | - return apply_filters('site-reviews/ngettext_with_context/'.$domain, $translation, $single, $plural, $number, $context); |
|
| 137 | + return apply_filters( 'site-reviews/ngettext_with_context/'.$domain, $translation, $single, $plural, $number, $context ); |
|
| 138 | 138 | } |
| 139 | 139 | |
| 140 | 140 | /** |
@@ -146,14 +146,14 @@ discard block |
||
| 146 | 146 | * @return string |
| 147 | 147 | * @filter site-reviews/ngettext_with_context/site-reviews |
| 148 | 148 | */ |
| 149 | - public function filterNgettextWithContextSiteReviews($translation, $single, $plural, $number, $context) |
|
| 149 | + public function filterNgettextWithContextSiteReviews( $translation, $single, $plural, $number, $context ) |
|
| 150 | 150 | { |
| 151 | - return $this->translator->translate($translation, Application::ID, [ |
|
| 151 | + return $this->translator->translate( $translation, Application::ID, [ |
|
| 152 | 152 | 'context' => $context, |
| 153 | 153 | 'number' => $number, |
| 154 | 154 | 'plural' => $plural, |
| 155 | 155 | 'single' => $single, |
| 156 | - ]); |
|
| 156 | + ] ); |
|
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | /** |
@@ -162,11 +162,11 @@ discard block |
||
| 162 | 162 | * @return array |
| 163 | 163 | * @filter display_post_states |
| 164 | 164 | */ |
| 165 | - public function filterPostStates($postStates, $post) |
|
| 165 | + public function filterPostStates( $postStates, $post ) |
|
| 166 | 166 | { |
| 167 | - $postStates = Arr::consolidateArray($postStates); |
|
| 168 | - if (Application::POST_TYPE == Arr::get($post, 'post_type') && array_key_exists('pending', $postStates)) { |
|
| 169 | - $postStates['pending'] = __('Unapproved', 'site-reviews'); |
|
| 167 | + $postStates = Arr::consolidateArray( $postStates ); |
|
| 168 | + if( Application::POST_TYPE == Arr::get( $post, 'post_type' ) && array_key_exists( 'pending', $postStates ) ) { |
|
| 169 | + $postStates['pending'] = __( 'Unapproved', 'site-reviews' ); |
|
| 170 | 170 | } |
| 171 | 171 | return $postStates; |
| 172 | 172 | } |
@@ -178,10 +178,10 @@ discard block |
||
| 178 | 178 | * @filter site-reviews/gettext/default |
| 179 | 179 | * @filter site-reviews/gettext_with_context/default |
| 180 | 180 | */ |
| 181 | - public function filterPostStatusLabels($translation, $text) |
|
| 181 | + public function filterPostStatusLabels( $translation, $text ) |
|
| 182 | 182 | { |
| 183 | 183 | return $this->canModifyTranslation() |
| 184 | - ? glsr(Labels::class)->filterPostStatusLabels($translation, $text) |
|
| 184 | + ? glsr( Labels::class )->filterPostStatusLabels( $translation, $text ) |
|
| 185 | 185 | : $translation; |
| 186 | 186 | } |
| 187 | 187 | |
@@ -193,22 +193,22 @@ discard block |
||
| 193 | 193 | * @return string |
| 194 | 194 | * @filter site-reviews/ngettext/default |
| 195 | 195 | */ |
| 196 | - public function filterPostStatusText($translation, $single, $plural, $number) |
|
| 196 | + public function filterPostStatusText( $translation, $single, $plural, $number ) |
|
| 197 | 197 | { |
| 198 | - if ($this->canModifyTranslation()) { |
|
| 198 | + if( $this->canModifyTranslation() ) { |
|
| 199 | 199 | $strings = [ |
| 200 | - 'Published' => __('Approved', 'site-reviews'), |
|
| 201 | - 'Pending' => __('Unapproved', 'site-reviews'), |
|
| 200 | + 'Published' => __( 'Approved', 'site-reviews' ), |
|
| 201 | + 'Pending' => __( 'Unapproved', 'site-reviews' ), |
|
| 202 | 202 | ]; |
| 203 | - foreach ($strings as $search => $replace) { |
|
| 204 | - if (!Str::contains($single, $search)) { |
|
| 203 | + foreach( $strings as $search => $replace ) { |
|
| 204 | + if( !Str::contains( $single, $search ) ) { |
|
| 205 | 205 | continue; |
| 206 | 206 | } |
| 207 | - return $this->translator->getTranslation([ |
|
| 207 | + return $this->translator->getTranslation( [ |
|
| 208 | 208 | 'number' => $number, |
| 209 | - 'plural' => str_replace($search, $replace, $plural), |
|
| 210 | - 'single' => str_replace($search, $replace, $single), |
|
| 211 | - ]); |
|
| 209 | + 'plural' => str_replace( $search, $replace, $plural ), |
|
| 210 | + 'single' => str_replace( $search, $replace, $single ), |
|
| 211 | + ] ); |
|
| 212 | 212 | } |
| 213 | 213 | } |
| 214 | 214 | return $translation; |
@@ -220,8 +220,8 @@ discard block |
||
| 220 | 220 | */ |
| 221 | 221 | public function translatePostStatusLabels() |
| 222 | 222 | { |
| 223 | - if ($this->canModifyTranslation()) { |
|
| 224 | - glsr(Labels::class)->translatePostStatusLabels(); |
|
| 223 | + if( $this->canModifyTranslation() ) { |
|
| 224 | + glsr( Labels::class )->translatePostStatusLabels(); |
|
| 225 | 225 | } |
| 226 | 226 | } |
| 227 | 227 | |
@@ -232,6 +232,6 @@ discard block |
||
| 232 | 232 | { |
| 233 | 233 | $screen = glsr_current_screen(); |
| 234 | 234 | return Application::POST_TYPE == $screen->post_type |
| 235 | - && in_array($screen->base, ['edit', 'post']); |
|
| 235 | + && in_array( $screen->base, ['edit', 'post'] ); |
|
| 236 | 236 | } |
| 237 | 237 | } |