GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — feature/gallery-template-clien... ( 6eed57...a5e10a )
by Brad
02:39
created

__construct()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 18
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 10
nc 4
nop 1
dl 0
loc 18
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: brad
5
 * Date: 2017/04/19
6
 * Time: 1:19 PM
7
 */
8
9
10
if ( ! class_exists( 'FooGallery_Admin_Gallery_MetaBox_Settings' ) ) {
11
12
    class FooGallery_Admin_Gallery_MetaBox_Settings {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
13
14
        /**
15
         * @var FooGallery
16
         */
17
        private $gallery;
18
19
        /**
20
         * @var bool
21
         */
22
        private $hide_help;
23
24
        /**
25
         * @var array
26
         */
27
        public $gallery_templates;
28
29
        /**
30
         * FooGallery_Admin_Gallery_MetaBox_Settings constructor.
31
         * @param $gallery FooGallery
32
         */
33
        function __construct($gallery) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
34
            $this->gallery = $gallery;
35
            $this->hide_help = 'on' == foogallery_get_setting( 'hide_gallery_template_help' );
36
37
            $this->gallery_templates = foogallery_gallery_templates();
38
39
            //check if we have no templates
40
            if ( 0 === count( $this->gallery_templates ) ) {
41
                //force the default template to activate if there are no other gallery templates
42
                foogallery_activate_default_templates_extension();
43
                $this->gallery_templates = foogallery_gallery_templates();
44
            }
45
46
            $this->current_gallery_template = foogallery_default_gallery_template();
0 ignored issues
show
Bug introduced by
The property current_gallery_template does not seem to exist. Did you mean gallery?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
47
            if ( ! empty($this->gallery->gallery_template) ) {
48
                $this->current_gallery_template = $this->gallery->gallery_template;
0 ignored issues
show
Bug introduced by
The property current_gallery_template does not seem to exist. Did you mean gallery?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
49
            }
50
        }
51
52
        private function render_gallery_template_settings_tabs( $template, $sections ) {
53
            $tab_active = 'foogallery-tab-active';
54
            foreach ( $sections as $section_slug => $section ) { ?>
55
                <div class="foogallery-vertical-tab <?php echo $tab_active; ?>"
56
                     data-name="<?php echo $template['slug']; ?>-<?php echo $section_slug; ?>">
57
                    <span class="dashicons <?php echo $section['icon_class']; ?>"></span>
58
                    <span class="foogallery-tab-text"><?php echo $section['name']; ?></span>
59
                </div>
60
            <?php
61
                $tab_active = '';
62
            }
63
        }
64
65
        private function render_gallery_template_settings_tab_contents( $template, $sections ) {
66
            $tab_active = 'foogallery-tab-active';
67
            foreach ( $sections as $section_slug => $section ) { ?>
68
                <div class="foogallery-tab-content <?php echo $tab_active; ?>"
69
                     data-name="<?php echo $template['slug']; ?>-<?php echo $section_slug; ?>">
70
                    <?php $this->render_gallery_template_settings_tab_contents_fields( $template, $section ); ?>
71
                </div>
72
            <?php
73
                $tab_active = '';
74
            }
75
        }
76
77
        private function render_gallery_template_settings_tab_contents_fields( $template, $section ) {
78
            ?>
79
            <table class="foogallery-metabox-settings">
80
                <tbody>
81
                <?php
82
                foreach ( $section['fields'] as $field ) {
83
                    $field_type = isset( $field['type'] ) ? $field['type'] : 'unknown';
84
                    $field_class ="foogallery_template_field foogallery_template_field_type-{$field_type} foogallery_template_field-{$template['slug']} foogallery_template_field-{$template['slug']}-{$field['id']}";
85
                    ?>
86
                    <tr class="<?php echo $field_class; ?>">
87
                        <?php if ( 'help' == $field_type ) { ?>
88
                            <td colspan="2">
89
                                <div class="foogallery-help">
90
                                    <?php echo $field['desc']; ?>
91
                                </div>
92
                            </td>
93
                        <?php } else { ?>
94
                            <th>
95
                                <label for="FooGallerySettings_<?php echo $template['slug'] . '_' . $field['id']; ?>"><?php echo $field['title']; ?></label>
96
                                <?php if ( !empty( $field['desc'] ) ) { ?>
97
                                <span data-balloon-length="large" data-balloon-pos="right" data-balloon="<?php echo esc_attr($field['desc']); ?>"><i class="dashicons dashicons-editor-help"></i></span>
98
                                <?php } ?>
99
                            </th>
100
                            <td>
101
                                <?php do_action( 'foogallery_render_gallery_template_field', $field, $this->gallery, $template ); ?>
102
                            </td>
103
                        <?php } ?>
104
                    </tr>
105
                <?php } ?>
106
                </tbody>
107
            </table>
108
            <?php
109
        }
110
111
        private function render_gallery_template_settings( $template ) {
112
            $sections = $this->build_model_for_template( $template );
113
            ?>
114
            <div class="foogallery-settings">
115
                <div class="foogallery-vertical-tabs">
116
                    <?php $this->render_gallery_template_settings_tabs( $template, $sections ); ?>
117
                </div>
118
                <div class="foogallery-tab-contents">
119
                    <?php $this->render_gallery_template_settings_tab_contents( $template, $sections ); ?>
120
                </div>
121
            </div>
122
            <?php
123
        }
124
125
        public function render_gallery_settings() {
126
            foreach ( $this->gallery_templates as $template ) {
127
                $field_visibility = ($this->current_gallery_template !== $template['slug']) ? 'style="display:none"' : '';
0 ignored issues
show
Bug introduced by
The property current_gallery_template does not seem to exist. Did you mean gallery?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
128
                ?><div
129
                    class="foogallery-settings-container foogallery-settings-container-<?php echo $template['slug']; ?>"
130
                    <?php echo $field_visibility; ?>>
131
                    <?php $this->render_gallery_template_settings( $template ); ?>
132
                </div><?php
133
            }
134
        }
135
136
        /**
137
         * build up and return a model that we can use to render the gallery settings
138
         */
139
        private function build_model_for_template($template) {
140
            //allow for extensions to override fields for every gallery template.
141
            // Also passes the $template along so you can inspect and conditionally alter fields based on the template properties
142
            $fields = apply_filters( 'foogallery_override_gallery_template_fields', $template['fields'], $template );
143
144
            //allow for extensions to override fields for every gallery template.
145
            // Also passes the $template along so you can inspect and conditionally alter fields based on the template properties
146
            $fields = apply_filters( "foogallery_override_gallery_template_fields-{$template['slug']}", $fields, $template );
147
148
            //create a sections array and fill it with fields
149
            $sections = array();
150
            foreach ( $fields as $field ) {
151
                //allow for the field to be altered by extensions. Also used by the build-in fields, e.g. lightbox
152
                $field = apply_filters( 'foogallery_alter_gallery_template_field', $field, $this->gallery );
153
154
                if (isset($field['type']) && 'help' == $field['type'] && $this->hide_help) {
155
                    continue; //skip help if the 'hide help' setting is turned on
156
                }
157
158
                $section_name = isset($field['section']) ? $field['section'] : __( 'General', 'foogallery' );
159
160
                $section_slug = strtolower( $section_name );
161
162
                if ( !isset( $sections[ $section_slug ] ) ) {
163
                    $sections[ $section_slug ] = array (
164
                        'name' => $section_name,
165
                        'icon_class' => apply_filters( 'foogallery_gallery_settings_metabox_section_icon', $section_slug ),
166
                        'fields' => array()
167
                    );
168
                }
169
170
                $sections[ $section_slug ]['fields'][] = $field;
171
            }
172
173
            return $sections;
174
        }
175
176
        public function render_hidden_gallery_template_selector() {
177
            ?>
178
            <span class="hidden foogallery-template-selector"> &mdash;
179
                <select id="FooGallerySettings_GalleryTemplate" name="<?php echo FOOGALLERY_META_TEMPLATE; ?>">
180
                    <?php
181
                    foreach ( $this->gallery_templates as $template ) {
182
                        $selected = ($this->current_gallery_template === $template['slug']) ? 'selected' : '';
0 ignored issues
show
Bug introduced by
The property current_gallery_template does not seem to exist. Did you mean gallery?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
183
184
                        $preview_css = '';
185
                        if ( isset( $template['preview_css'] ) ) {
186
                            if ( is_array( $template['preview_css'] ) ) {
187
                                //dealing with an array of css files to include
188
                                $preview_css = implode( ',', $template['preview_css'] );
189
                            } else {
190
                                $preview_css = $template['preview_css'];
191
                            }
192
                        }
193
                        $preview_css = empty( $preview_css ) ? '' : ' data-preview-css="' . $preview_css . '" ';
194
195
                        echo "<option {$selected}{$preview_css} value=\"{$template['slug']}\">{$template['name']}</option>";
196
                    }
197
                    ?>
198
                </select>
199
            </span>
200
            <?php
201
        }
202
    }
203
}