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 ( 33c4ea...214779 )
by Marko
01:36
created

Tabify_Edit_Screen_Settings_Base::get_default_items()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
class Tabify_Edit_Screen_Settings_Base {
4
	private $type;
5
	private $sections;
6
	private $base_url;
7
	private $tabs;
8
9
	private $options;
10
11
	protected $items = array();
12
13
	public function __construct( $type ) {
1 ignored issue
show
Coding Style introduced by
__construct uses the super-global variable $_SERVER which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
14
		$this->type = $type;
15
		$this->sections = $this->load_sections();
16
		$this->base_url = remove_query_arg( array( 'type', 'section' ), $_SERVER["REQUEST_URI"] );
17
18
		$this->tabs     = new Tabify_Edit_Screen_Tabs( $this->sections, 'vertical', 'subtab' );
19
	}
20
21
	protected function load_sections() {
22
		return array();
23
	}
24
25
	protected function get_sections() {
26
		return $this->sections;
27
	}
28
29
	public function get_sections_menu() {
30
		echo $this->tabs->get_tabs_with_container();
31
	}
32
33
	public function get_default_items() {
34
		return array();
35
	}
36
37
	/**
38
	 * Echo all the items
39
	 *
40
	 * @since 0.1.0
41
	 */
42
	public function get_section() {
43
		$sections = $this->get_sections();
44
		$items    = $this->items;
45
		$options  = $this->get_options( $this->type );
46
47
		foreach ( $sections as $section => $label ) {
48
			$default_items = $this->get_default_items( $section );
0 ignored issues
show
Unused Code introduced by
The call to Tabify_Edit_Screen_Setti...se::get_default_items() has too many arguments starting with $section.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
49
50
			if ( ! isset( $options[ $section ] ) ) {
51
				$options[ $section ] = array (
52
					'tabs' => array(
53
						array( 'title' => __( 'Others', 'tabify-edit-screen' ), 'items' => array() )
54
					)
55
				);
56
			}
57
58
			if ( $section == $this->tabs->get_current_tab() ) {
59
				echo '<div class="tabifybox tabifybox-' . $section . '">';
60
			}
61
			else {
62
				echo '<div class="tabifybox tabifybox-hide tabifybox-' . $section . '" style="display: none;">';
63
			}
64
65
			$checked = '';
66
			if ( isset( $options[ $section ]['show'] ) && $options[ $section ]['show'] == 1 ) {
67
				$checked = ' checked="checked"';
68
			}
69
70
			echo '<div class="tabifybox-options">';
71
			echo '<p id="show-type">';
72
			_e( 'Show tabs in this post type:', 'tabify-edit-screen' );
73
			echo '<span class="onoffswitch">';
74
			echo '<input type="checkbox" name="tabify[' . $this->type . '][' . $section . '][show]" value="1" class="onoffswitch-checkbox" id="switch-' . $this->type . '"' . $checked . '>';
75
			echo '<label class="onoffswitch-label" for="switch-' . $this->type . '">';
76
			echo '<span class="onoffswitch-inner"></span>';
77
			echo '<span class="onoffswitch-switch"></span>';
78
			echo '</label>';
79
			echo '</span>';
80
			echo '</p>';
81
82
			do_action( 'tabify_settings', $this->type, $section, $options[ $section ] );
83
			echo '</div>';
84
85
			echo '<div class="tabify_control tabify_control_tabs">';
86
87
			$tab_id = 0;
88
			$remove = false;
89
90
			if ( 1 < count( $options[ $section ]['tabs'] ) ) {
91
				$remove = true;
92
			}
93
94
			foreach ( $options[ $section ]['tabs'] as $tab ) {
95
				$tab['id'] = $tab_id;
96
97
				if ( ! isset( $tab['permissions'] ) ) {
98
					$tab['permissions'] = array();
99
				}
100
101
				// Backwards compatibily from 0.5 to 0.6
102 View Code Duplication
				if ( ! isset( $tab['items'] ) && isset( $tab['metaboxes'] ) ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
103
					$tab['items'] = $tab['metaboxes'];
104
				}
105
106
				if ( $tab['title'] == '' ) {
107
					$tab['title'] = __( 'Choose title', 'tabify-edit-screen' );
108
				}
109
110
				echo '<div class="menu-item-handle tabify_tab">';
111
112
				$this->get_section_tab_title( $section, $tab['title'], $tab, $remove );
113
114
				echo '<ul>';
115
				if ( isset( $tab['items'] ) ) {
116
					foreach ( $tab['items'] as $item_id_fallback => $item_id ) {
117
						// Backwards compatibily from 0.3 to 0.4.
118
						if ( intval( $item_id_fallback ) == 0 && $item_id_fallback !== 0 ) {
119
							$item_id = $item_id_fallback;
120
						}
121
122
						if ( empty( $item_id ) ) {
123
							continue;
124
						}
125
126
						$item_title = '';
127
						if ( isset( $items[ $section ][ $item_id ] ) ) {
128
							$item_title = $items[ $section ][ $item_id ];
129
130
							$item_title = apply_filters( 'tabify_items_title', $item_title, $item_id );
131
							$item_title = apply_filters( 'tabify_items_title_' . $item_id , $item_title );
132
						}
133
134
						$this->list_show_items( $item_id, $item_title, $tab_id, $section, $default_items );
135
136
						unset( $items[ $section ][ $item_id ] );
137
					}
138
				}
139
140
				if ( count( $options[ $section ]['tabs'] ) == ( $tab_id + 1 ) ) {
141
					foreach ( $items[ $section ] as $item_id => $item_title ) {
142
						if ( empty( $item_id ) ) {
143
							continue;
144
						}
145
146
						$item_title = apply_filters( 'tabify_items_title', $item_title, $item_id );
147
						$item_title = apply_filters( 'tabify_items_title_' . $item_id , $item_title );
148
149
						$this->list_show_items( $item_id, $item_title, $tab_id, $section, $default_items );
150
					}
151
				}
152
153
				echo '</ul>';
154
				echo '</div>';
155
156
				$tab_id++;
157
			}
158
159
160
			echo '</div>';
161
162
			echo '</div>';
163
		}
164
165
		echo '<p class="submit">';
166
		echo '<input type="submit" id="create_tab" name="create_tab" class="button button-secondary" value="' . __( 'Create a new tab', 'tabify-edit-screen' ) . '" />';
167
		submit_button( '', 'primary', 'submit', false );
168
		echo '</p>';
169
170
		$this->print_onoff_switch();
171
		$this->print_backbone_template();
172
	}
173
174
	private function get_section_tab_title( $section, $title, $tab, $remove ) {
175
		echo '<h2><span class="hide-if-no-js">' . $title . '</span><input type="text" name="tabify[' . $this->type . '][' . $section . '][tabs][' . $tab['id'] . '][title]" value="' . esc_html( $title ) . '" class="hide-if-js" /></h2>';
176
177
		echo '<div class="tabify-title-box">';
178
			do_action( 'tabify_settings_tab_title_box', $tab, $section, $this->type );
179
180
			echo '<a href="#" class="tabify-remove-tab hide-if-no-js"';
181
			if ( ! $remove ) {
182
				echo ' style="display: none;"';
183
			}
184
			echo '>' . __( 'Remove', 'tabify-edit-screen' ) . '</a>';
185
		echo '</div>';
186
187
		echo '<div class="clear"></div>';
188
		do_action( 'tabify_settings_tab_title_after', $tab, $section, $this->type );
189
	}
190
191
	private function print_backbone_template() {
192
		$tab = array(
193
			'id'          => '{{ data.tab_id }}',
194
			'permissions' => array()
195
		);
196
197
		echo '<script type="text/template" id="tmpl-new-tab">';
198
		echo '<div class="menu-item-handle tabify_tab">';
199
			$this->get_section_tab_title( '{{ data.section }}', __( 'Choose title', 'tabify-edit-screen' ), $tab, true );
200
			echo '<ul></ul>';
201
		echo '</div>';
202
203
		echo '</script>';
204
	}
205
206
	private function print_onoff_switch() {
207
		global $_wp_admin_css_colors;
208
209
		$color = get_user_option('admin_color');
210
211
		if ( empty( $color ) || ! isset($_wp_admin_css_colors[ $color ] ) ) {
212
			$color = 'fresh';
213
		}
214
215
		echo '<style>';
216
		echo '.onoffswitch-inner:before { content: "' . __( 'On', 'sitemanager' ) . '"; }';
217
		echo '.onoffswitch-inner:after { content: "' . __( 'Off', 'sitemanager' ) . '"; }';
218
		echo '.form-table .onoffswitch-label { border-color: ' . $_wp_admin_css_colors[$color]->colors[2] . '; }';
219
		echo '.form-table .onoffswitch-inner:before { background-color: ' . $_wp_admin_css_colors[$color]->colors[3] . '; }';
220
		echo '.form-table .onoffswitch-switch { background-color: ' . $_wp_admin_css_colors[$color]->colors[2] . '; }';
221
		echo '</style>';
222
	}
223
224
	protected function get_options( $type = null ) {
225
		if ( ! $this->options ) {
226
			$this->options = get_option( 'tabify-edit-screen', array() );
227
		}
228
229
		if ( $type && isset( $this->options[ $type ] ) ) {
230
			return $this->options[ $type ];
231
		}
232
233
		return $this->options;
234
	}
235
236
	/**
237
	 * Show the items for the sortable list
238
	 *
239
	 * @since 0.4.0
240
	 */
241
	protected function list_show_items( $item_id, $item_title, $tab_id, $type, $default_items ) {
242
		$options = $this->get_options( $this->type );
243
244
		// Most likely a meta box that doesn't exist anymore
245
		if ( empty( $item_title ) ) {
246
			return;
247
		}
248
249
		$item_title = strip_tags( $item_title );
250
251
		if ( in_array( $item_id, $default_items ) ) {
252
			echo '<li id="' . $type . '-' . $item_id . '" class="tabifybox-hide">';
253
		}
254
		else {
255
			echo '<li id="' . $type . '-' . $item_id . '">';
256
		}
257
258
		echo '<div class="menu-item-bar"><div class="menu-item-handle">';
259
		echo '<span class="item-title">' . $item_title . '</span>';
260
261
		echo '<input type="hidden" name="tabify[' . $this->type . '][' . $type . '][tabs][' . $tab_id . '][items][]" value="' . $item_id . '" />';
262
263
		echo '<span class="item-order hide-if-js">';
264
		echo '<select name="tabify[' . $this->type . '][' . $type . '][tabs][' . $tab_id . '][items_tab][]">';
265
266
		if ( isset( $options[ $type ] ) ) {
267
			$amount_tabs = count( $options[ $type ]['tabs'] );
268
269
			for( $i = 0; $i < $amount_tabs; $i++ ) {
270
				if ( ! isset( $options[ $type ]['tabs'][ $i ] ) ) {
271
					continue;
272
				}
273
274
				if ( $i == $tab_id ) {
275
					echo '<option value="' . $i . '" selected="selected">' . esc_html( $options[ $type ]['tabs'][ $i ]['title'] ) . '</option>';
276
				}
277
				else {
278
					echo '<option value="' . $i . '">' . esc_html( $options[ $type ]['tabs'][ $i ]['title'] ) . '</option>';
279
				}
280
			}
281
		}
282
283
		echo '</select>';
284
		echo '</span>';
285
		echo '</div></div></li>';
286
	}
287
288
}
289