PluginProbe ʕ •ᴥ•ʔ
Tracking Code Manager / 2.8.0
Tracking Code Manager v2.8.0
2.8.0 2.7.0 trunk 1.11.8 1.11.9 1.12.0 1.12.1 1.12.2 1.12.3 1.4 1.5 2.0.0 2.0.1 2.0.13 2.0.14 2.0.15 2.0.16 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.1.0 2.2.0 2.3.0 2.4.0 2.5.0 2.6.0
tracking-code-manager / includes / classes / ui / Tabs.php
tracking-code-manager / includes / classes / ui Last commit date
Check.php 1 month ago Form.php 1 month ago Tabs.php 1 month ago
Tabs.php
346 lines
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) exit;
3 class TCMP_Tabs {
4 private $tabs = array();
5
6 function __construct() {
7 }
8 public function init() {
9 global $tcmp;
10 // Only register the admin-menu machinery in the admin context; the menu
11 // callback itself still enforces the manage_options capability (and the
12 // multisite unfiltered_html gate). Replaces the misleading always-true
13 // isAdminUser() stub (see F-13).
14 if ( is_admin() ) {
15 add_action( 'admin_menu', array( &$this, 'attach_menu' ) );
16 add_filter( 'plugin_action_links', array( &$this, 'plugin_actions' ), 10, 2 );
17 if ( $tcmp->utils->isPluginPage() ) {
18 add_action( 'admin_enqueue_scripts', array( &$this, 'enqueue_scripts' ) );
19 }
20 }
21 }
22
23 function attach_menu() {
24 add_submenu_page(
25 'options-general.php',
26 TCMP_PLUGIN_NAME,
27 TCMP_PLUGIN_NAME,
28 'manage_options',
29 TCMP_PLUGIN_SLUG,
30 array( &$this, 'showTabPage' )
31 );
32 }
33 function plugin_actions( $links, $file ) {
34 global $tcmp;
35 if ( TCMP_PLUGIN_SLUG . '/index.php' == $file ) {
36 $settings = array();
37 $settings[] = "<a href='" . TCMP_TAB_MANAGER_URI . "'>" . $tcmp->lang->L( 'Settings' ) . '</a>';
38 $settings[] = "<a href='" . TCMP_PAGE_PREMIUM . "'>" . $tcmp->lang->L( 'PREMIUM' ) . '</a>';
39 $links = array_merge( $settings, $links );
40 }
41 return $links;
42 }
43 function enqueue_scripts() {
44 wp_enqueue_script( 'jquery' );
45 wp_enqueue_script( 'jQuery' );
46 wp_enqueue_script( 'jquery-ui-sortable' );
47
48 $this->wpEnqueueStyle( 'assets/css/style.css' );
49 $this->wpEnqueueStyle( 'assets/css/manager.css' );
50 $this->wpEnqueueStyle( 'assets/deps/select2-4.0.13/select2.css' );
51 $this->wpEnqueueScript( 'assets/deps/select2-4.0.13/select2.full.js' );
52 $this->wpEnqueueScript( 'assets/deps/starrr/starrr.js' );
53
54 $this->wpEnqueueScript( 'assets/js/library.js' );
55 $this->wpEnqueueScript( 'assets/js/plugin.js' );
56
57 $this->wpEnqueueScript( 'assets/js/editor.js' );
58 $this->wpEnqueueScript( 'assets/js/manager.js' );
59 wp_localize_script('TCMP__manager', 'ajax_vars', array ('nonce' => wp_create_nonce('change_order')));
60 $this->wpEnqueueScript( 'assets/js/delete-confirm.js' );
61 $this->wpEnqueueScript( 'assets/js/ace/ace.js' );
62
63 $this->wpEnqueueStyle( 'assets/css/font-awesome.min.css' );
64
65 global $tcmp;
66 wp_add_inline_script( 'TCMP__delete-confirm', 'const delete_data = ' . json_encode( array(
67 'confirm' => $tcmp->lang->L( 'Question.DeleteQuestion' ),
68 'href' => TCMP_TAB_MANAGER_URI,
69 'nonce' => wp_create_nonce( 'tcmp_delete' ),
70 ) ), 'before' );
71 }
72 function wpEnqueueStyle( $uri, $name = '' ) {
73 if ( '' == $name ) {
74 $name = explode( '/', $uri );
75 $name = $name[ count( $name ) - 1 ];
76 $dot = strrpos( $name, '.' );
77 if ( false != $dot ) {
78 $name = substr( $name, 0, $dot );
79 }
80 $name = TCMP_PLUGIN_PREFIX . '_' . $name;
81 }
82
83 $v = '?v=' . TCMP_PLUGIN_VERSION;
84 wp_enqueue_style( $name, TCMP_PLUGIN_URI . $uri . $v );
85 }
86 function wpEnqueueScript( $uri, $name = '', $version = false ) {
87 if ( '' == $name ) {
88 $name = explode( '/', $uri );
89 $name = $name[ count( $name ) - 1 ];
90 $dot = strrpos( $name, '.' );
91 if ( false != $dot ) {
92 $name = substr( $name, 0, $dot );
93 }
94 $name = TCMP_PLUGIN_PREFIX . '_' . $name;
95 }
96
97 $v = '?v=' . TCMP_PLUGIN_VERSION;
98 $deps = array();
99 wp_enqueue_script( $name, TCMP_PLUGIN_URI . $uri . $v, $deps, $version, false );
100 }
101
102 function showTabPage() {
103 global $tcmp;
104
105 $v = $tcmp->options->getShowWhatsNewSeenVersion();
106 if ( TCMP_WHATSNEW_VERSION != $v ) {
107 $tcmp->options->setShowWhatsNew( true );
108 }
109
110 $hwb = tcmp_isqs( 'hwb', '' );
111 if ( '' != $hwb ) {
112 $tcmp->options->setShowWhatsNew( false );
113 }
114
115 $id = tcmp_isqs( 'id', 0 );
116 $default_tab = TCMP_TAB_MANAGER;
117 $tab = tcmp_sqs( 'tab', $default_tab );
118
119 if ( $tcmp->options->isShowWhatsNew() ) {
120 $tab = TCMP_TAB_WHATS_NEW;
121 $default_tab = $tab;
122 $this->tabs[ TCMP_TAB_WHATS_NEW ] = $tcmp->lang->L( 'What\'s New' );
123 //$this->tabs[TCMP_TAB_MANAGER]=$tcmp->lang->L('Start using the plugin!');
124 } else {
125 if ( $id > 0 || ! $tcmp->manager->is_limit_reached( false ) ) {
126 $this->tabs[ TCMP_TAB_EDITOR ] = $tcmp->lang->L( $id > 0 && TCMP_TAB_EDITOR == $tab ? 'Edit Script' : 'Add New Script' );
127 } elseif ( TCMP_TAB_EDITOR == $tab ) {
128 $tab = TCMP_TAB_MANAGER;
129 }
130
131 $this->tabs[ TCMP_TAB_MANAGER ] = $tcmp->lang->L( 'Manager' );
132 $this->tabs[ TCMP_TAB_ADMIN_OPTIONS ] = $tcmp->lang->L( 'Admin Options' );
133 $this->tabs[ TCMP_TAB_SETTINGS ] = $tcmp->lang->L( 'Settings' );
134 $this->tabs[ TCMP_TAB_DOCS ] = $tcmp->lang->L( 'Docs & FAQ' );
135 }
136
137 ?>
138
139 <div class="wrap" style="margin: 5px;">
140 <?php
141 $this->showTabs( $default_tab );
142 $header = '';
143 switch ( $tab ) {
144 case TCMP_TAB_EDITOR:
145 $header = ( $id > 0 ? 'Edit' : 'Add' );
146 break;
147 case TCMP_TAB_WHATS_NEW:
148 $header = '';
149 break;
150 case TCMP_TAB_MANAGER:
151 $header = 'Manager';
152 break;
153 case TCMP_TAB_ADMIN_OPTIONS:
154 $header = 'Admin Options';
155 break;
156 case TCMP_TAB_SETTINGS:
157 $header = 'Settings';
158 break;
159 }
160
161 if ( $tcmp->lang->H( $header . 'Title' ) ) {
162 ?>
163 <h2><?php $tcmp->lang->P( $header . 'Title', TCMP_PLUGIN_VERSION ); ?></h2>
164 <?php if ( $tcmp->lang->H( $header . 'Subtitle' ) ) { ?>
165 <div><?php $tcmp->lang->P( $header . 'Subtitle' ); ?></div>
166 <?php } ?>
167 <br/>
168 <?php
169 }
170
171 tcmp_ui_first_time();
172 ?>
173 <div style="float:left; margin:5px;">
174 <?php
175 $styles = array();
176 $styles[] = 'float:left';
177 $styles[] = 'margin-right:20px';
178 if ( TCMP_TAB_WHATS_NEW != $tab ) {
179 $styles[] = 'max-width:750px';
180 }
181 $styles = implode( '; ', $styles );
182 ?>
183 <div id="tcmp-page" style="<?php echo esc_attr( $styles ); ?>">
184 <?php
185 if (is_multisite())
186 {
187 if (!current_user_can('unfiltered_html'))
188 {
189 // Only the Super-Admin role has unfiltered_html by default
190 $refusal = 'For a multisite only, changing plugin settings requires the unfiltered_html capability.';
191 echo '<div class="tcmp-box-error"><p>' . esc_html( $refusal ) . '</p></div>';
192 // wp_die() rather than a bare die(): it ends the request with a
193 // themed, filterable error page instead of truncating the admin
194 // document mid-render, and it matches how change_order() already
195 // refuses. It is also interceptable, which is what makes this
196 // branch reachable from the test suite (see TabPageTest).
197 wp_die( esc_html( $refusal ) );
198 }
199 }
200 switch ( $tab ) {
201 case TCMP_TAB_WHATS_NEW:
202 tcmp_ui_whats_new();
203 break;
204 case TCMP_TAB_EDITOR:
205 tcmp_ui_editor();
206 break;
207 case TCMP_TAB_MANAGER:
208 tcmp_ui_manager();
209 break;
210 case TCMP_TAB_ADMIN_OPTIONS:
211 tcmp_ui_admin_options();
212 break;
213 case TCMP_TAB_SETTINGS:
214 tcmp_ui_track();
215 tcmp_ui_settings();
216 break;
217 }
218 ?>
219 </div>
220 <?php if ( TCMP_TAB_WHATS_NEW != $tab ) { ?>
221 <div id="tcmp-sidebar" style="float:left; max-width: 250px;">
222 <?php
223 $count = $this->getPluginsCount();
224 $plugins = array();
225 while ( count( $plugins ) < 2 ) {
226 $id = rand( 1, $count );
227 if ( ! isset( $plugins[ $id ] ) ) {
228 $plugins[ $id ] = $id;
229 }
230 }
231
232 $this->drawContactUsWidget();
233 foreach ( $plugins as $id ) {
234 $this->drawPluginWidget( $id );
235 }
236 ?>
237 </div>
238 <?php } ?>
239 </div>
240 </div>
241 <div style="clear:both"></div>
242 <?php
243 }
244 function getPluginsCount() {
245 global $tcmp;
246 $index = 1;
247 while ( $tcmp->lang->H( 'Plugin' . $index . '.Name' ) ) {
248 $index++;
249 }
250 return $index - 1;
251 }
252 function drawPluginWidget( $id ) {
253 global $tcmp;
254 ?>
255 <div class="tcmp-plugin-widget">
256 <b><?php $tcmp->lang->P( 'Plugin' . $id . '.Name' ); ?></b>
257 <br>
258 <i><?php $tcmp->lang->P( 'Plugin' . $id . '.Subtitle' ); ?></i>
259 <br>
260 <ul style="list-style: circle;">
261 <?php
262 $index = 1;
263 while ( $tcmp->lang->H( 'Plugin' . $id . '.Feature' . $index ) ) {
264 ?>
265 <li><?php $tcmp->lang->P( 'Plugin' . $id . '.Feature' . $index ); ?></li>
266 <?php
267 $index++;
268 }
269 ?>
270 </ul>
271 <a style="float:right;" class="button-primary" href="<?php $tcmp->lang->P( 'Plugin' . $id . '.Permalink' ); ?>" target="_blank">
272 <?php $tcmp->lang->P( 'PluginCTA' ); ?>
273 </a>
274 <div style="clear:both"></div>
275 </div>
276 <br>
277 <?php
278 }
279 function drawContactUsWidget() {
280 global $tcmp;
281 ?>
282 <b><?php $tcmp->lang->P( 'Sidebar.Title' ); ?></b>
283 <ul style="list-style: circle;">
284 <?php
285 $index = 1;
286 while ( $tcmp->lang->H( 'Sidebar' . $index . '.Name' ) ) {
287 ?>
288 <li>
289 <a href="<?php $tcmp->lang->P( 'Sidebar' . $index . '.Url' ); ?>" target="_blank">
290 <?php $tcmp->lang->P( 'Sidebar' . $index . '.Name' ); ?>
291 </a>
292 </li>
293 <?php
294 $index++;
295 }
296 ?>
297 </ul>
298 <?php
299 }
300 function showTabs( $default_tab ) {
301 global $tcmp;
302 $tab = $tcmp->check->of( 'tab', $default_tab );
303 if ( $tcmp->options->isShowWhatsNew() ) {
304 $tab = TCMP_TAB_WHATS_NEW;
305 }
306
307 ?>
308 <h2 class="nav-tab-wrapper" style="float:left; width:97%;">
309 <?php
310
311 foreach ( $this->tabs as $k => $v ) {
312 $active = ( $tab == $k ? 'nav-tab-active' : '' );
313 $style = '';
314 $target = '_self';
315 if ( $tcmp->options->isShowWhatsNew() && TCMP_TAB_MANAGER == $k ) {
316 $active = '';
317 $style = 'background-color:#F2E49B';
318 }
319 if ( TCMP_TAB_DOCS == $k ) {
320 $target = '_blank';
321 $style = 'background-color:#F2E49B';
322 ?>
323 <a href="<?php echo esc_url(TCMP_TAB_DOCS_URI) ?>" class="nav-tab <?php echo esc_attr( $active ); ?>" style="float:left; margin-left:10px;background-color:#F2E49B;" target="_blank">
324 <?php echo esc_attr( $v ); ?>
325 </a>
326 <?php
327 } else {
328 ?>
329 <a style="float:left; margin-left:10px; <?php echo esc_attr( $style ); ?>" class="nav-tab <?php echo esc_attr( $active ); ?>" target="<?php echo esc_attr( $target ); ?>" href="<?php echo esc_url( '?page=' . TCMP_PLUGIN_SLUG . '&tab=' . $k ); ?>"><?php echo esc_attr( $v ); ?></a>
330 <?php
331 }
332 }
333 ?>
334 <div style="float:right; display:none;" id="rate-box">
335 <span style="font-weight:700; font-size:13px; color:#555;"><?php $tcmp->lang->P( 'Rate us' ); ?></span>
336 <div id="tcmp-rate" class="starrr" data-connected-input="tcmp-rate-rank"></div>
337 <input type="hidden" id="tcmp-rate-rank" name="tcmp-rate-rank" value="5" />
338 <?php $tcmp->utils->twitter( 'data443risk' ); ?>
339 </div>
340 </h2>
341 <div style="clear:both;"></div>
342 <?php
343 }
344 }
345
346