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... ( a5e10a...a6b5cf )
by Brad
02:25
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 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
			//check if we have no templates
37
			if ( 0 === count( $this->gallery_templates ) ) {
38
				//force the default template to activate if there are no other gallery templates
39
				foogallery_activate_default_templates_extension();
40
				$this->gallery_templates = foogallery_gallery_templates();
41
			}
42
43
			$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...
44
			if ( ! empty($this->gallery->gallery_template) ) {
45
				$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...
46
			}
47
		}
48
49
		private function render_gallery_template_settings_tabs( $template, $sections ) {
50
			$tab_active = 'foogallery-tab-active';
51
			foreach ( $sections as $section_slug => $section ) { ?>
52
				<div class="foogallery-vertical-tab <?php echo $tab_active; ?>"
53
					 data-name="<?php echo $template['slug']; ?>-<?php echo $section_slug; ?>">
54
					<span class="dashicons <?php echo $section['icon_class']; ?>"></span>
55
					<span class="foogallery-tab-text"><?php echo $section['name']; ?></span>
56
				</div>
57
				<?php
58
				$tab_active = '';
59
			}
60
		}
61
62
		private function render_gallery_template_settings_tab_contents( $template, $sections ) {
63
			$tab_active = 'foogallery-tab-active';
64
			foreach ( $sections as $section_slug => $section ) { ?>
65
				<div class="foogallery-tab-content <?php echo $tab_active; ?>"
66
					 data-name="<?php echo $template['slug']; ?>-<?php echo $section_slug; ?>">
67
					<?php $this->render_gallery_template_settings_tab_contents_fields( $template, $section ); ?>
68
				</div>
69
				<?php
70
				$tab_active = '';
71
			}
72
		}
73
74
		private function render_gallery_template_settings_tab_contents_fields( $template, $section ) {
75
			?>
76
			<table class="foogallery-metabox-settings">
77
				<tbody>
78
				<?php
79
				foreach ( $section['fields'] as $field ) {
80
					$field_type = isset( $field['type'] ) ? $field['type'] : 'unknown';
81
					$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']}";
82
					$field_row_data_html = '';
83
					if ( isset( $field['row_data'] ) ) {
84
						$field_row_data = array_map( 'esc_attr', $field['row_data'] );
85
						foreach ( $field_row_data as $field_row_data_name => $field_row_data_value ) {
86
							$field_row_data_html .= " $field_row_data_name=" . '"' . $field_row_data_value . '"';
87
						}
88
					}
89
					?>
90
					<tr class="<?php echo $field_class; ?>"<?php echo $field_row_data_html; ?>>
91
						<?php if ( 'help' == $field_type ) { ?>
92
							<td colspan="2">
93
								<div class="foogallery-help">
94
									<?php echo $field['desc']; ?>
95
								</div>
96
							</td>
97
						<?php } else { ?>
98
							<th>
99
								<label for="FooGallerySettings_<?php echo $template['slug'] . '_' . $field['id']; ?>"><?php echo $field['title']; ?></label>
100
								<?php if ( !empty( $field['desc'] ) ) { ?>
101
									<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>
102
								<?php } ?>
103
							</th>
104
							<td>
105
								<?php do_action( 'foogallery_render_gallery_template_field', $field, $this->gallery, $template ); ?>
106
							</td>
107
						<?php } ?>
108
					</tr>
109
				<?php } ?>
110
				</tbody>
111
			</table>
112
			<?php
113
		}
114
115
		private function render_gallery_template_settings( $template ) {
116
			$sections = $this->build_model_for_template( $template );
117
			?>
118
			<div class="foogallery-settings">
119
				<div class="foogallery-vertical-tabs">
120
					<?php $this->render_gallery_template_settings_tabs( $template, $sections ); ?>
121
				</div>
122
				<div class="foogallery-tab-contents">
123
					<?php $this->render_gallery_template_settings_tab_contents( $template, $sections ); ?>
124
				</div>
125
			</div>
126
			<?php
127
		}
128
129
		public function render_gallery_settings() {
130
			foreach ( $this->gallery_templates as $template ) {
131
				$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...
132
				?><div
133
				class="foogallery-settings-container foogallery-settings-container-<?php echo $template['slug']; ?>"
134
				<?php echo $field_visibility; ?>>
135
				<?php $this->render_gallery_template_settings( $template ); ?>
136
				</div><?php
137
			}
138
		}
139
140
		/**
141
		 * build up and return a model that we can use to render the gallery settings
142
		 */
143
		private function build_model_for_template($template) {
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['fields'], $template );
147
148
			//allow for extensions to override fields for every gallery template.
149
			// Also passes the $template along so you can inspect and conditionally alter fields based on the template properties
150
			$fields = apply_filters( "foogallery_override_gallery_template_fields-{$template['slug']}", $fields, $template );
151
152
			//create a sections array and fill it with fields
153
			$sections = array();
154
			foreach ( $fields as $field ) {
155
				//allow for the field to be altered by extensions. Also used by the build-in fields, e.g. lightbox
156
				$field = apply_filters( 'foogallery_alter_gallery_template_field', $field, $this->gallery );
157
158
				if (isset($field['type']) && 'help' == $field['type'] && $this->hide_help) {
159
					continue; //skip help if the 'hide help' setting is turned on
160
				}
161
162
				$section_name = isset($field['section']) ? $field['section'] : __( 'General', 'foogallery' );
163
164
				$section_slug = strtolower( $section_name );
165
166
				if ( !isset( $sections[ $section_slug ] ) ) {
167
					$sections[ $section_slug ] = array (
168
						'name' => $section_name,
169
						'icon_class' => apply_filters( 'foogallery_gallery_settings_metabox_section_icon', $section_slug ),
170
						'fields' => array()
171
					);
172
				}
173
174
				$sections[ $section_slug ]['fields'][] = $field;
175
			}
176
177
			return $sections;
178
		}
179
180
		public function render_hidden_gallery_template_selector() {
181
			?>
182
			<span class="hidden foogallery-template-selector"> &mdash;
183
				<select id="FooGallerySettings_GalleryTemplate" name="<?php echo FOOGALLERY_META_TEMPLATE; ?>">
184
                    <?php
185
					foreach ( $this->gallery_templates as $template ) {
186
						$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...
187
188
						$preview_css = '';
189
						if ( isset( $template['preview_css'] ) ) {
190
							if ( is_array( $template['preview_css'] ) ) {
191
								//dealing with an array of css files to include
192
								$preview_css = implode( ',', $template['preview_css'] );
193
							} else {
194
								$preview_css = $template['preview_css'];
195
							}
196
						}
197
						$preview_css = empty( $preview_css ) ? '' : ' data-preview-css="' . $preview_css . '" ';
198
199
						echo "<option {$selected}{$preview_css} value=\"{$template['slug']}\">{$template['name']}</option>";
200
					}
201
					?>
202
                </select>
203
            </span>
204
			<?php
205
		}
206
	}
207
}