PluginProbe ʕ •ᴥ•ʔ
Tracking Code Manager / 2.0.16
Tracking Code Manager v2.0.16
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 / core / Manager.php
tracking-code-manager / includes / classes / core Last commit date
Manager.php 3 years ago Singleton.php 4 years ago
Manager.php
689 lines
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) {
3 exit;
4 }
5
6 class TCMP_Manager {
7 public function __construct() {
8 }
9 public function init() {
10 add_action( 'wp_ajax_TCMP_changeOrder', array( &$this, 'change_order' ) );
11 }
12 public function is_limit_reached( $notice = true ) {
13 global $tcmp;
14 $cnt = $this->codes_count();
15 $result = ( $cnt >= TCMP_SNIPPETS_LIMIT );
16 if ( $result && $notice ) {
17 $tcmp->options->pushWarningMessage( 'SnippetsLimitReached', TCMP_SNIPPETS_LIMIT, TCMP_PAGE_PREMIUM );
18 } elseif ( $notice && $cnt > 0 ) {
19 $tcmp->options->pushSuccessMessage( 'SnippetsLimitNotice', $cnt, TCMP_SNIPPETS_LIMIT, TCMP_PAGE_PREMIUM );
20 }
21 return $result;
22 }
23 public function change_order() {
24 global $tcmp;
25 if ( ! isset( $_POST['order'] ) ) {
26 return;
27 }
28
29 $data = array();
30 parse_str( tcmp_sqs( 'order' ), $data );
31
32 if ( isset( $data['row'] ) ) {
33 $snippets = $this->values();
34 foreach ( $snippets as $id => $v ) {
35 $v['order'] = 0;
36 $snippets[ $id ] = $v;
37 }
38
39 $index = 1;
40 foreach ( $data['row'] as $order => $id ) {
41 $v = $snippets[ $id ];
42 $v['order'] = $index;
43 $snippets[ $id ] = $v;
44 ++$index;
45 }
46
47 foreach ( $snippets as $id => $v ) {
48 $this->put( $id, $v );
49 }
50 }
51 echo 'OK';
52 wp_die();
53 }
54
55 public function match_device_type( $snippet ) {
56 global $tcmp;
57 $device_type = $tcmp->utils->get( $snippet, 'deviceType', false );
58 $device_type = $tcmp->utils->to_array( $device_type );
59 if ( false == $device_type || 0 == count( $device_type ) ) {
60 return true;
61 }
62
63 $detect = new TCMP_Mobile_Detect();
64 if ( $detect->isMobile() ) {
65 $type = TCMP_DEVICE_TYPE_MOBILE;
66 } elseif ( $detect->isTablet() ) {
67 $type = TCMP_DEVICE_TYPE_TABLET;
68 } else { //if(!$detect->isMobile() && !$detect->isTablet()) {
69 $type = TCMP_DEVICE_TYPE_DESKTOP;
70 }
71
72 $result = false;
73 if ( in_array( TCMP_DEVICE_TYPE_ALL, $device_type ) || in_array( $type, $device_type ) ) {
74 $result = true;
75 }
76 return $result;
77 }
78 public function is_mode_script( $snippet ) {
79 global $tcmp;
80 $result = $tcmp->utils->iget( $snippet, 'trackMode', 0 );
81 return ( 0 == $result );
82 }
83 public function is_mode_conversion( $snippet ) {
84 global $tcmp;
85 $result = $tcmp->utils->iget( $snippet, 'trackMode', 0 );
86 return ( 0 != $result );
87 }
88 public function is_page_everywhere( $snippet ) {
89 global $tcmp;
90 if ( ! $this->is_mode_script( $snippet ) ) {
91 return false;
92 }
93
94 $result = $tcmp->utils->iget( $snippet, 'trackPage', 0 );
95 return ( TCMP_TRACK_PAGE_ALL == $result );
96 }
97 public function is_page_specific( $snippet ) {
98 global $tcmp;
99 if ( ! $this->is_mode_script( $snippet ) ) {
100 return false;
101 }
102
103 $result = $tcmp->utils->iget( $snippet, 'trackPage', 0 );
104 return ( TCMP_TRACK_PAGE_SPECIFIC == $result );
105 }
106
107 public function exists( $name ) {
108 $snippets = $this->values();
109 $result = null;
110 $name = strtoupper( $name );
111 if ( isset( $snippets[ $name ] ) ) {
112 $result = $snippets[ $name ];
113 }
114 return $result;
115 }
116
117 //get a code snippet
118 public function get( $id, $new = false ) {
119 global $tcmp;
120
121 $snippet = $tcmp->options->getSnippet( $id );
122 if ( ! $snippet && $new ) {
123 $snippet = array();
124 $snippet['active'] = 1;
125 $snippet['trackMode'] = -1;
126 $snippet['trackPage'] = -1;
127 }
128
129 $snippet = $this->sanitize( $id, $snippet );
130 return $snippet;
131 }
132
133 public function sanitize( $id, $snippet ) {
134 global $tcmp;
135 if ( null == $snippet || ! is_array( $snippet ) ) {
136 return null;
137 }
138
139 $page = 0;
140 if ( isset( $snippet['includeEverywhereActive'] ) ) {
141 $page = ( intval( 1 == $snippet['includeEverywhereActive'] ) ? 0 : 1 );
142 }
143 $defaults = array(
144 'id' => $id,
145 'active' => 0,
146 'name' => '',
147 'code' => '',
148 'order' => 1000,
149 'position' => TCMP_POSITION_HEAD,
150 'trackMode' => TCMP_TRACK_MODE_CODE,
151 'trackPage' => $page,
152 'includeEverywhereActive' => 0,
153 'includeCategoriesActive' => 0,
154 'includeCategories' => array(),
155 'includeTagsActive' => 0,
156 'includeTags' => array(),
157 'exceptCategoriesActive' => 0,
158 'exceptCategories' => array(),
159 'exceptTagsActive' => 0,
160 'exceptTags' => array(),
161 'deviceType' => TCMP_DEVICE_TYPE_ALL,
162 );
163
164 $types = $tcmp->utils->query( TCMP_QUERY_POST_TYPES );
165 foreach ( $types as $v ) {
166 $defaults[ 'includePostsOfType_' . $v['id'] . '_Active' ] = 0;
167 $defaults[ 'includePostsOfType_' . $v['id'] ] = array();
168 $defaults[ 'exceptPostsOfType_' . $v['id'] . '_Active' ] = 0;
169 $defaults[ 'exceptPostsOfType_' . $v['id'] ] = array();
170 }
171
172 $types = $tcmp->utils->query( TCMP_QUERY_CONVERSION_PLUGINS );
173 foreach ( $types as $v ) {
174 //CP stands for ConversionTrackingCode
175 //$defaults['CTC_'.$v['id'].'_Active']=0;
176 $defaults[ 'CTC_' . $v['id'] . '_ProductsIds' ] = array();
177 $defaults[ 'CTC_' . $v['id'] . '_CategoriesIds' ] = array();
178 $defaults[ 'CTC_' . $v['id'] . '_TagsIds' ] = array();
179 }
180 $snippet = $tcmp->utils->parseArgs( $snippet, $defaults );
181
182 foreach ( $snippet as $k => $v ) {
183 if ( stripos( $k, 'active' ) != false ) {
184 $snippet[ $k ] = intval( $v );
185 } elseif ( is_array( $v ) ) {
186 switch ( $k ) {
187 /*
188 case 'includePostsTypes':
189 case 'excludePostsTypes':
190 //keys are string and not number
191 $result=$this->uarray($snippet, $k, FALSE);
192 break;
193 */
194 default:
195 //keys are number
196 $result = $this->uarray( $snippet, $k, true );
197 break;
198 }
199 }
200 }
201 $snippet['code'] = trim( $snippet['code'] );
202 $snippet['position'] = intval( $snippet['position'] );
203 if ( '' == $snippet['trackMode'] ) {
204 $snippet['trackMode'] = TCMP_TRACK_MODE_CODE;
205 } else {
206 $snippet['trackMode'] = intval( $snippet['trackMode'] );
207 }
208 if ( '' == $snippet['trackPage'] ) {
209 $snippet['trackPage'] = $page;
210 } else {
211 $snippet['trackPage'] = intval( $snippet['trackPage'] );
212 }
213
214 $snippet['includeEverywhereActive'] = 0;
215 if ( TCMP_TRACK_PAGE_ALL == $snippet['trackPage'] ) {
216 $snippet['includeEverywhereActive'] = 1;
217 }
218
219 $code = strtolower( $snippet['code'] );
220 $cnt = substr_count( $code, '<iframe' ) + substr_count( $code, '<script' );
221 if ( $cnt <= 0 ) {
222 $cnt = 1;
223 }
224 $snippet['codes_count'] = $cnt;
225 return $snippet;
226 }
227 private function uarray( $snippet, $key, $is_integer = true ) {
228 $array = $snippet[ $key ];
229 if ( ! is_array( $array ) ) {
230 $array = explode( ',', $array );
231 }
232
233 if ( $is_integer ) {
234 for ( $i = 0; $i < count( $array ); $i++ ) {
235 $array[ $i ] = intval( $array[ $i ] );
236 }
237 }
238
239 $array = array_unique( $array );
240 $snippet[ $key ] = $array;
241 return $snippet;
242 }
243
244 //add or update a snippet (html tracking code)
245 public function put( $id, $snippet ) {
246 global $tcmp;
247
248 if ( '' == $id || intval( $id ) <= 0 ) {
249 //if is a new code create a new unique id
250 $id = $this->get_last_id() + 1;
251 $snippet['id'] = $id;
252 }
253 $snippet = $this->sanitize( $id, $snippet );
254 $tcmp->options->setSnippet( $id, $snippet );
255
256 $keys = $this->keys();
257 if ( is_array( $keys ) && ! in_array( $id, $keys ) ) {
258 $keys[] = $id;
259 $this->keys( $keys );
260 }
261 return $snippet;
262 }
263
264 //remove the id snippet
265 public function remove( $id ) {
266 global $tcmp;
267 $tcmp->options->remove_snippet( $id );
268 $keys = $this->keys();
269 $result = false;
270 if ( is_array( $keys ) && in_array( $id, $keys ) ) {
271 $keys = array_diff( $keys, array( $id ) );
272 $this->keys( $keys );
273 $result = true;
274 }
275 return $result;
276 }
277
278 //verify if match with this snippet
279 private function match_snippet( $post_id, $post_type, $categories_ids, $tags_ids, $prefix, $snippet ) {
280 global $tcmp;
281 if ( ! $this->match_device_type( $snippet ) ) {
282 return false;
283 }
284
285 $include = false;
286 $post_id = intval( $post_id );
287 if ( $post_id > 0 ) {
288 $what = $prefix . 'PostsOfType_' . $post_type;
289 //echo '<textarea cols="100" rows="4">DEBUG:'.'Post Id = '.$post_id .' $what = '. $what .' What = '.$snippet[$what.'_Active'] .' Active = '.$snippet[$what.'_Active']. ' InAllArray = ' . $tcmp->utils->in_all_array( $post_id, $snippet[$what] ) . '</textarea>';
290 if ( isset( $snippet[ $what . '_Active' ] ) && isset( $snippet[ $what ] ) && $snippet[ $what . '_Active' ] && $tcmp->utils->in_all_array( $post_id, $snippet[ $what ] ) ) {
291 $tcmp->log->debug(
292 'MATCH=%s SNIPPET=%s[%s] DUE TO POST=%s OF TYPE=%s IN [%s]',
293 $prefix,
294 $snippet['id'],
295 $snippet['name'],
296 $post_id,
297 $post_type,
298 $snippet[ $what ]
299 );
300 $include = true;
301 //echo '<p>DEBUG: snippet matched</p>';
302 }
303 }
304
305 return $include;
306 }
307
308 public function write_codes( $position ) {
309 global $tcmp;
310
311 $text = '';
312 $position_text = '';
313 switch ( $position ) {
314 case TCMP_POSITION_HEAD:
315 $position_text = 'HEAD';
316 break;
317 case TCMP_POSITION_BODY:
318 $position_text = 'BODY';
319 break;
320 case TCMP_POSITION_FOOTER:
321 $position_text = 'FOOTER';
322 break;
323 case TCMP_POSITION_CONVERSION:
324 $position_text = 'CONVERSION';
325 break;
326 }
327
328 $post = $tcmp->options->getPostShown();
329 $args = array( 'field' => 'code' );
330 $codes = $tcmp->manager->get_codes( $position, $post, $args );
331 if ( is_array( $codes ) && count( $codes ) > 0 ) {
332 $version = TCMP_PLUGIN_VERSION;
333 $text = "\n<!--BEGIN: TRACKING CODE MANAGER (v$version) BY INTELLYWP.COM IN $position_text//-->";
334 foreach ( $codes as $v ) {
335 $text .= "\n$v";
336 }
337 $text .= "\n<!--END: https://wordpress.org/plugins/tracking-code-manager IN $position_text//-->";
338
339 $purchase = $tcmp->options->getEcommercePurchase();
340 if ( false != $purchase && intval( $tcmp->options->getLicenseSiteCount() ) > 0 ) {
341 $text = $this->insert_dynamic_conversion_values( $purchase, $text );
342 }
343 echo $this->esc_js_code( $text );
344 }
345 }
346
347 private function esc_js_code( $text ) {
348 global $tcmp;
349 global $tcmp_allowed_html_tags;
350
351 if ( ! $tcmp->options->getSkipCodeSanitization() ) {
352 $text = wp_kses( $text, $tcmp_allowed_html_tags );
353 }
354 $text = str_replace( '&lt;', '<', $text );
355 $text = str_replace( '&gt;', '>', $text );
356 $text = str_replace( '&amp;', '&', $text );
357 $text = str_replace( '&quot;', '"', $text );
358 $text = str_replace( '&#039;', "'", $text );
359 return $text;
360 }
361
362 private function insert_dynamic_conversion_values( $purchase, $text ) {
363 global $tcmp;
364 $purchase->user_id = intval( $purchase->user_id );
365 if ( $purchase->user_id > 0 ) {
366 $user = get_user_by( 'id', $purchase->user_id );
367 if ( ! is_null( $user ) && false != $user && get_class( $user ) == 'WP_User' ) {
368 /* @var $user WP_User */
369 $purchase->email = $user->user_email;
370 $purchase->fullname = $user->user_firstname;
371 if ( '' != $user->user_lastname ) {
372 $purchase->fullname .= ' ' . $user->user_lastname;
373 }
374 }
375 }
376
377 $purchase->total = floatval( $purchase->total );
378 $purchase->amount = floatval( $purchase->amount );
379 $purchase->tax = floatval( $purchase->tax );
380
381 $fields = array(
382 'ORDERID' => $purchase->order_id,
383 'CURRENCY' => $purchase->currency,
384 'FULLNAME' => $purchase->fullname,
385 'EMAIL' => $purchase->email,
386 'PRODUCTS' => $purchase->products,
387 'AMOUNT' => $purchase->amount,
388 'TOTAL' => $purchase->total,
389 'TAX' => $purchase->tax,
390 );
391
392 $sep = '@@';
393 $buffer = '';
394 $previous = 0;
395 $start = strpos( $text, $sep );
396 if ( false == $start ) {
397 $buffer = $text;
398 } else {
399 while ( false != $start ) {
400 $buffer .= $tcmp->utils->substr( $text, $previous, $start );
401 $end = strpos( $text, $sep, $start + strlen( $sep ) );
402 if ( false != $end ) {
403 $code = $tcmp->utils->substr( $text, $start + strlen( $sep ), $end );
404 $code = $tcmp->utils->to_array( $code );
405 if ( 1 == count( $code ) ) {
406 $code[] = '';
407 }
408
409 $v = false;
410 if ( isset( $fields[ $code[0] ] ) ) {
411 $v = $fields[ $code[0] ];
412 }
413 if ( is_null( $v ) || false == $v ) {
414 $v = $code[1];
415 }
416 if ( is_numeric( $v ) ) {
417 $v = floatval( $v );
418 $v = round( $v, 2 );
419 switch ( $code[0] ) {
420 case 'TOTAL':
421 case 'AMOUNT':
422 case 'TAX':
423 $v = number_format( $v, 2, '.', '' );
424 break;
425 default:
426 $v = intval( $v );
427 break;
428 }
429 } elseif ( is_array( $v ) ) {
430 $a = '';
431 foreach ( $v as $t ) {
432 $t = str_replace( ',', '', $t );
433 if ( '' != $a ) {
434 $a .= ',';
435 }
436 $a .= $t;
437 }
438 $v = $a;
439 }
440 $v = str_replace( "'", '', $v );
441 $v = str_replace( '"', '', $v );
442 $buffer .= $v;
443
444 $previous = $end + strlen( $sep );
445 $start = strpos( $text, $sep, $previous );
446 } else {
447 $buffer .= $tcmp->utils->substr( $text, $start );
448 $previous = false;
449 $start = false;
450 }
451 }
452
453 if ( false != $previous && $previous < strlen( $text ) ) {
454 $code = $tcmp->utils->substr( $text, $previous );
455 $buffer .= $code;
456 }
457 }
458 return $buffer;
459 }
460
461 //return snippets that match with options
462 public function get_conversion_snippets( $options = null ) {
463 global $tcmp;
464
465 $defaults = array(
466 'pluginId' => 0,
467 'categoriesIds' => array(),
468 'productsIds' => array(),
469 'tagsIds' => array(),
470 );
471 $options = $tcmp->utils->parseArgs( $options, $defaults );
472
473 $result = array();
474 $plugin_id = intval( $options['pluginId'] );
475 $values = $this->values();
476
477 foreach ( $values as $snippet ) {
478 $snippet['trackMode'] = intval( $snippet['trackMode'] );
479 if ( $snippet && $snippet['trackMode'] > 0 && $snippet['trackMode'] == $plugin_id ) {
480 $match = false;
481
482 $match = ( $match || $this->match_conversion( $snippet, $plugin_id, 'ProductsIds', $options['productsIds'] ) );
483 $match = ( $match && $this->match_device_type( $snippet ) );
484 if ( ! $match ) {
485 //no selected so..all match! :)
486 if ( 0 == count( $snippet[ 'CTC_' . $plugin_id . '_ProductsIds' ] )
487 && 0 == count( $snippet[ 'CTC_' . $plugin_id . '_CategoriesIds' ] )
488 && 0 == count( $snippet[ 'CTC_' . $plugin_id . '_TagsIds' ] ) ) {
489 $match = true;
490 }
491 }
492
493 if ( $match ) {
494 $result[] = $snippet;
495 }
496 }
497 }
498 return $result;
499 }
500 private function match_conversion( $snippet, $plugin_id, $suffix, $current_ids ) {
501 global $tcmp;
502
503 $settings_ids = 'CTC_' . $plugin_id . '_' . $suffix;
504 if ( isset( $snippet[ $settings_ids ] ) ) {
505 $settings_ids = $snippet[ $settings_ids ];
506 } else {
507 $settings_ids = array();
508 }
509
510 $result = $tcmp->utils->in_all_array( $current_ids, $settings_ids );
511 return $result;
512 }
513
514 //from a post retrieve the html code that is needed to insert into the page code
515 public function get_codes( $position, $post, $args = array() ) {
516 global $tcmp;
517
518 $defaults = array( 'field' => 'code' );
519 $args = $tcmp->utils->parseArgs( $args, $defaults );
520
521 $post_id = 0;
522 $post_type = 'page';
523 $tags_ids = array();
524 $categories_ids = array();
525 if ( $post ) {
526 $post_id = $tcmp->utils->get( $post, 'ID', false );
527 if ( false == $post_id ) {
528 $post_id = $tcmp->utils->get( $post, 'post_ID' );
529 }
530 $post_type = $tcmp->utils->get( $post, 'post_type' );
531
532 $options = array(
533 'orderby' => 'name',
534 'order' => 'ASC',
535 'fields' => 'ids',
536 );
537 if ( isset( $post->ID ) ) {
538 $tags_ids = wp_get_post_tags( $post->ID, $options );
539 $categories_ids = wp_get_post_categories( $post->ID );
540 } else {
541 $tags_ids = array();
542 $categories_ids = array();
543 }
544 }
545
546 $tcmp->options->clearSnippetsWritten();
547 if ( TCMP_POSITION_CONVERSION == $position ) {
548 //write snippets previously appended
549 $ids = $tcmp->options->get_conversion_snippet_ids();
550 if ( false != $ids && count( $ids ) > 0 ) {
551 foreach ( $ids as $id ) {
552 $snippet = $tcmp->manager->get( $id );
553 if ( $snippet ) {
554 $tcmp->options->pushSnippetWritten( $snippet );
555 }
556 }
557 }
558 } else {
559 $snippets = $this->values();
560 foreach ( $snippets as $v ) {
561 if ( ! $v || ( $position > -1 && $v['position'] != $position ) || '' == $v['code'] || ! $v['active'] ) {
562 continue;
563 }
564 if ( TCMP_TRACK_MODE_CODE != $v['trackMode'] ) {
565 continue;
566 }
567 if ( $tcmp->options->hasSnippetWritten( $v ) ) {
568 $tcmp->log->debug( 'SKIPPED SNIPPET=%s[%s] DUE TO ALREADY WRITTEN', $v['id'], $v['name'] );
569 continue;
570 }
571
572 $match = false;
573 if ( ! $match && ( TCMP_TRACK_PAGE_ALL == $v['trackPage'] || $v['includeEverywhereActive'] ) ) {
574 $tcmp->log->debug( 'INCLUDED SNIPPET=%s[%s] DUE TO EVERYWHERE', $v['id'], $v['name'] );
575 $match = true;
576 }
577 if ( ! $match && $post_id > 0 && $this->match_snippet( $post_id, $post_type, $categories_ids, $tags_ids, 'include', $v ) ) {
578 $match = true;
579 }
580
581 if ( $match && $post_id > 0 ) {
582 //echo '<textarea cols="100" rows="4">check for exclude' . print_r($v, true) . '</textarea>';
583 if ( $this->match_snippet( $post_id, $post_type, $categories_ids, $tags_ids, 'except', $v ) ) {
584 //echo '<textarea cols="100" rows="4">exclude ' . print_r($v, true) . '</textarea>';
585 $tcmp->log->debug( 'FOUND AT LEAST ONE EXCEPT TO EXCLUDE SNIPPET=%s [%s]', $v['id'], $v['name'] );
586 $match = false;
587 }
588 }
589
590 if ( $match ) {
591 $tcmp->options->pushSnippetWritten( $v );
592 }
593 }
594 }
595
596 //obtain result as snippets or array of one field (tipically "id")
597 $result = $tcmp->options->getSnippetsWritten();
598 if ( 'all' != $args['field'] ) {
599 $array = array();
600 foreach ( $result as $k => $v ) {
601 $k = $args['field'];
602 if ( isset( $v[ $k ] ) ) {
603 $array[] = $v[ $k ];
604 } else {
605 $tcmp->log->error( 'SNIPPET=%s [%s] WITHOUT FIELD=%s', $v['id'], $v['name'], $k );
606 }
607 }
608 $result = $array;
609 }
610 return $result;
611 }
612
613 //ottiene o salva tutte le chiavi dei tracking code utilizzati ordinati per id
614 public function keys( $keys = null ) {
615 global $tcmp;
616
617 if ( is_array( $keys ) ) {
618 $tcmp->options->setSnippetList( $keys );
619 $result = $keys;
620 } else {
621 $result = $tcmp->options->getSnippetList();
622 }
623
624 if ( ! is_array( $result ) ) {
625 $result = array();
626 } else {
627 sort( $result );
628 }
629 return $result;
630 }
631
632 //ottiene il conteggio attuale dei tracking code
633 public function count() {
634 $result = count( $this->keys() );
635 return $result;
636 }
637 public function codes_count() {
638 $result = 0;
639 $ids = $this->keys();
640 foreach ( $ids as $id ) {
641 $snippet = $this->get( $id );
642 if ( $snippet ) {
643 $result += 1;
644 }
645 }
646 return $result;
647 }
648 public function get_last_id() {
649 $result = 0;
650 $list = $this->keys();
651 foreach ( $list as $v ) {
652 $v = intval( $v );
653 if ( $v > $result ) {
654 $result = $v;
655 }
656 }
657 return $result;
658 }
659
660 public function values() {
661 $keys = $this->keys();
662 $array = array();
663 foreach ( $keys as $k ) {
664 $v = $this->get( $k );
665 $array[] = $v;
666 }
667 usort( $array, array( $this, 'values_compare' ) );
668
669 $result = array();
670 foreach ( $array as $v ) {
671 $id = $v['id'];
672 $result[ $id ] = $v;
673 }
674 return $result;
675 }
676 public function values_compare( $o1, $o2 ) {
677 global $tcmp;
678 $v1 = $tcmp->utils->iget( $o1, 'order', false );
679 $v2 = $tcmp->utils->iget( $o2, 'order', false );
680 $result = ( $v1 - $v2 );
681 if ( 0 == $result ) {
682 $v1 = $tcmp->utils->get( $o1, 'name', false );
683 $v2 = $tcmp->utils->get( $o2, 'name', false );
684 $result = strcasecmp( $v1, $v2 );
685 }
686 return $result;
687 }
688 }
689