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 — master ( bb6361...a2a740 )
by Brad
04:28
created

FooGallery_Admin_Gallery_MetaBox_Settings_Helper   A

Complexity

Total Complexity 31

Size/Duplication

Total Lines 189
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 189
rs 9.8
c 0
b 0
f 0
wmc 31
lcom 1
cbo 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 2
A render_gallery_template_settings_tabs() 0 12 2
A render_gallery_template_settings_tab_contents() 0 11 2
C render_gallery_template_settings_tab_contents_fields() 0 40 7
A render_gallery_template_settings() 0 13 1
A render_gallery_settings() 0 10 3
C build_model_for_template() 0 29 7
C render_hidden_gallery_template_selector() 0 31 7
1
<?php
2
/**
3
 * Created by bradvin
4
 * Date: 28/04/2017
5
 *
6
 */
7
if ( ! class_exists( 'FooGallery_Admin_Gallery_MetaBox_Settings_Helper' ) ) {
8
9
	class FooGallery_Admin_Gallery_MetaBox_Settings_Helper {
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...
10
11
		/**
12
		 * @var FooGallery
13
		 */
14
		private $gallery;
15
16
		/**
17
		 * @var bool
18
		 */
19
		private $hide_help;
20
21
		/**
22
		 * @var array
23
		 */
24
		public $gallery_templates;
25
26
		/**
27
		 * FooGallery_Admin_Gallery_MetaBox_Settings_Helper constructor.
28
		 * @param $gallery FooGallery
29
		 */
30
		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...
31
			$this->gallery = $gallery;
32
			$this->hide_help = 'on' == foogallery_get_setting( 'hide_gallery_template_help' );
33
34
			$this->gallery_templates = foogallery_gallery_templates();
35
36
			$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...
37
			if ( ! empty($this->gallery->gallery_template) ) {
38
				$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...
39
			}
40
		}
41
42
		private function render_gallery_template_settings_tabs( $template, $sections ) {
43
			$tab_active = 'foogallery-tab-active';
44
			foreach ( $sections as $section_slug => $section ) { ?>
45
				<div class="foogallery-vertical-tab <?php echo $tab_active; ?>"
46
					 data-name="<?php echo $template['slug']; ?>-<?php echo $section_slug; ?>">
47
					<span class="dashicons <?php echo $section['icon_class']; ?>"></span>
48
					<span class="foogallery-tab-text"><?php echo $section['name']; ?></span>
49
				</div>
50
				<?php
51
				$tab_active = '';
52
			}
53
		}
54
55
		private function render_gallery_template_settings_tab_contents( $template, $sections ) {
56
			$tab_active = 'foogallery-tab-active';
57
			foreach ( $sections as $section_slug => $section ) { ?>
58
				<div class="foogallery-tab-content <?php echo $tab_active; ?>"
59
					 data-name="<?php echo $template['slug']; ?>-<?php echo $section_slug; ?>">
60
					<?php $this->render_gallery_template_settings_tab_contents_fields( $template, $section ); ?>
61
				</div>
62
				<?php
63
				$tab_active = '';
64
			}
65
		}
66
67
		private function render_gallery_template_settings_tab_contents_fields( $template, $section ) {
68
			?>
69
			<table class="foogallery-metabox-settings">
70
				<tbody>
71
				<?php
72
				foreach ( $section['fields'] as $field ) {
73
					$field_type = isset( $field['type'] ) ? $field['type'] : 'unknown';
74
					$field_class ="foogallery_template_field foogallery_template_field_type-{$field_type} foogallery_template_field_id-{$field['id']} foogallery_template_field_template-{$template['slug']} foogallery_template_field_template_id-{$template['slug']}-{$field['id']}";
75
					$field_row_data_html = '';
76
					if ( isset( $field['row_data'] ) ) {
77
						$field_row_data = array_map( 'esc_attr', $field['row_data'] );
78
						foreach ( $field_row_data as $field_row_data_name => $field_row_data_value ) {
79
							$field_row_data_html .= " $field_row_data_name=" . '"' . $field_row_data_value . '"';
80
						}
81
					}
82
					?>
83
					<tr class="<?php echo $field_class; ?>"<?php echo $field_row_data_html; ?>>
84
						<?php if ( 'help' == $field_type ) { ?>
85
							<td colspan="2">
86
								<div class="foogallery-help">
87
									<?php echo $field['desc']; ?>
88
								</div>
89
							</td>
90
						<?php } else { ?>
91
							<th>
92
								<label for="FooGallerySettings_<?php echo $template['slug'] . '_' . $field['id']; ?>"><?php echo $field['title']; ?></label>
93
								<?php if ( !empty( $field['desc'] ) ) { ?>
94
									<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>
95
								<?php } ?>
96
							</th>
97
							<td>
98
								<?php do_action( 'foogallery_render_gallery_template_field', $field, $this->gallery, $template ); ?>
99
							</td>
100
						<?php } ?>
101
					</tr>
102
				<?php } ?>
103
				</tbody>
104
			</table>
105
			<?php
106
		}
107
108
		private function render_gallery_template_settings( $template ) {
109
			$sections = $this->build_model_for_template( $template );
110
			?>
111
			<div class="foogallery-settings">
112
				<div class="foogallery-vertical-tabs">
113
					<?php $this->render_gallery_template_settings_tabs( $template, $sections ); ?>
114
				</div>
115
				<div class="foogallery-tab-contents">
116
					<?php $this->render_gallery_template_settings_tab_contents( $template, $sections ); ?>
117
				</div>
118
			</div>
119
			<?php
120
		}
121
122
		public function render_gallery_settings() {
123
			foreach ( $this->gallery_templates as $template ) {
124
				$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...
125
				?><div
126
				class="foogallery-settings-container foogallery-settings-container-<?php echo $template['slug']; ?>"
127
				<?php echo $field_visibility; ?>>
128
				<?php $this->render_gallery_template_settings( $template ); ?>
129
				</div><?php
130
			}
131
		}
132
133
		/**
134
		 * build up and return a model that we can use to render the gallery settings
135
		 */
136
		private function build_model_for_template($template) {
137
138
		    $fields = foogallery_get_fields_for_template( $template );
139
140
			//create a sections array and fill it with fields
141
			$sections = array();
142
			foreach ( $fields as $field ) {
143
144
				if (isset($field['type']) && 'help' == $field['type'] && $this->hide_help) {
145
					continue; //skip help if the 'hide help' setting is turned on
146
				}
147
148
				$section_name = isset($field['section']) ? $field['section'] : __( 'General', 'foogallery' );
149
150
				$section_slug = strtolower( $section_name );
151
152
				if ( !isset( $sections[ $section_slug ] ) ) {
153
					$sections[ $section_slug ] = array (
154
						'name' => $section_name,
155
						'icon_class' => apply_filters( 'foogallery_gallery_settings_metabox_section_icon', $section_slug ),
156
						'fields' => array()
157
					);
158
				}
159
160
				$sections[ $section_slug ]['fields'][] = $field;
161
			}
162
163
			return $sections;
164
		}
165
166
		public function render_hidden_gallery_template_selector() {
167
			?>
168
			<span class="hidden foogallery-template-selector"> &mdash;
169
				<select id="FooGallerySettings_GalleryTemplate" name="<?php echo FOOGALLERY_META_TEMPLATE; ?>">
170
                    <?php
171
					foreach ( $this->gallery_templates as $template ) {
172
						$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...
173
174
						$preview_css = '';
175
						if ( isset( $template['preview_css'] ) ) {
176
							if ( is_array( $template['preview_css'] ) ) {
177
								//dealing with an array of css files to include
178
								$preview_css = implode( ',', $template['preview_css'] );
179
							} else {
180
								$preview_css = $template['preview_css'];
181
							}
182
						}
183
						$preview_css = empty( $preview_css ) ? '' : ' data-preview-css="' . $preview_css . '" ';
184
185
						$mandatory_classes = '';
186
						if ( isset( $template['mandatory_classes'] ) ) {
187
							$mandatory_classes = ' data-mandatory-classes="' . $template['mandatory_classes'] . '" ';
188
						}
189
190
						echo "<option {$selected}{$preview_css}{$mandatory_classes} value=\"{$template['slug']}\">{$template['name']}</option>";
191
					}
192
					?>
193
                </select>
194
            </span>
195
			<?php
196
		}
197
	}
198
}