~jlosito/wordpress/wp-plugin-yoast

« back to all changes in this revision

Viewing changes to vendor/yoast/i18n-module/src/i18n-module-wordpressorg.php

  • Committer: John Losito
  • Date: 2019-11-08 15:58:32 UTC
  • Revision ID: john.losito@canonical.com-20191108155832-bjb8eep3l9naaf8f
Updated to 12.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<?php
2
 
 
3
 
/**
4
 
 * The Yoast i18n module with a connection to WordPress.org.
5
 
 */
6
 
class Yoast_I18n_WordPressOrg_v3 {
7
 
 
8
 
        /**
9
 
         * The i18n object that presents the user with the notification.
10
 
         *
11
 
         * @var yoast_i18n_v3
12
 
         */
13
 
        protected $i18n;
14
 
 
15
 
        /**
16
 
         * Constructs the i18n module for wordpress.org. Required fields are the 'textdomain', 'plugin_name' and 'hook'
17
 
         *
18
 
         * @param array $args                   The settings for the i18n module.
19
 
         * @param bool $show_translation_box    Whether the translation box should be shown.
20
 
         */
21
 
        public function __construct( $args, $show_translation_box = true ) {
22
 
                $args = $this->set_defaults( $args );
23
 
 
24
 
                $this->i18n = new Yoast_I18n_v3( $args, $show_translation_box );
25
 
                $this->set_api_url( $args['textdomain'] );
26
 
        }
27
 
 
28
 
        /**
29
 
         * Returns the i18n_promo message from the i18n_module. Returns en empty string if the promo shouldn't be shown.
30
 
         *
31
 
         * @access public
32
 
         *
33
 
         * @return string The i18n promo message.
34
 
         */
35
 
        public function get_promo_message() {
36
 
                return $this->i18n->get_promo_message();
37
 
        }
38
 
 
39
 
        /**
40
 
         * Returns a button that can be used to dismiss the i18n-message.
41
 
         *
42
 
         * @access private
43
 
         *
44
 
         * @return string
45
 
         */
46
 
        public function get_dismiss_i18n_message_button() {
47
 
                return $this->i18n->get_dismiss_i18n_message_button();
48
 
        }
49
 
 
50
 
        /**
51
 
         * Sets the default values for wordpress.org
52
 
         *
53
 
         * @param array $args The arguments to set defaults for.
54
 
         *
55
 
         * @return array The arguments with the arguments set.
56
 
         */
57
 
        private function set_defaults( $args ) {
58
 
 
59
 
                if ( ! isset( $args['glotpress_logo'] ) ) {
60
 
                        $args['glotpress_logo'] = 'https://plugins.svn.wordpress.org/' . $args['textdomain'] . '/assets/icon-128x128.png';
61
 
                }
62
 
 
63
 
                if ( ! isset( $args['register_url'] ) ) {
64
 
                        $args['register_url'] = 'https://translate.wordpress.org/projects/wp-plugins/' . $args['textdomain'] . '/';
65
 
                }
66
 
 
67
 
                if ( ! isset( $args['glotpress_name'] ) ) {
68
 
                        $args['glotpress_name'] = 'Translating WordPress';
69
 
                }
70
 
 
71
 
                if ( ! isset( $args['project_slug'] ) ) {
72
 
                        $args['project_slug'] = $args['textdomain'];
73
 
                }
74
 
 
75
 
                return $args;
76
 
        }
77
 
 
78
 
        /**
79
 
         * Set the API URL on the i18n object.
80
 
         *
81
 
         * @param string $textdomain The textdomain to use for the API URL.
82
 
         */
83
 
        private function set_api_url( $textdomain ) {
84
 
                $this->i18n->set_api_url( 'https://translate.wordpress.org/api/projects/wp-plugins/' . $textdomain . '/stable/' );
85
 
        }
86
 
}