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