PluginProbe ʕ •ᴥ•ʔ
Tracking Code Manager / 2.1.0
Tracking Code Manager v2.1.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 / core / Manager.php
tracking-code-manager / includes / classes / core Last commit date
Manager.php 2 years ago Singleton.php 3 years ago
Manager.php
692 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['name'] = sanitize_text_field( $snippet['name'] );
202 $snippet['code'] = trim( $snippet['code'] );
203 $snippet['position'] = intval( $snippet['position'] );
204 if ( '' == $snippet['trackMode'] ) {
205 $snippet['trackMode'] = TCMP_TRACK_MODE_CODE;
206 } else {
207 $snippet['trackMode'] = intval( $snippet['trackMode'] );
208 }
209 if ( '' == $snippet['trackPage'] ) {
210 $snippet['trackPage'] = $page;
211 } else {
212 $snippet['trackPage'] = intval( $snippet['trackPage'] );
213 }
214
215 $snippet['includeEverywhereActive'] = 0;
216 if ( TCMP_TRACK_PAGE_ALL == $snippet['trackPage'] ) {
217 $snippet['includeEverywhereActive'] = 1;
218 }
219
220 $code = strtolower( $snippet['code'] );
221 $cnt = substr_count( $code, '<iframe' ) + substr_count( $code, '<script' );
222 if ( $cnt <= 0 ) {
223 $cnt = 1;
224 }
225 $snippet['codes_count'] = $cnt;
226 return $snippet;
227 }
228 private function uarray( $snippet, $key, $is_integer = true ) {
229 $array = $snippet[ $key ];
230 if ( ! is_array( $array ) ) {
231 $array = explode( ',', $array );
232 }
233
234 if ( $is_integer ) {
235 for ( $i = 0; $i < count( $array ); $i++ ) {
236 if ( isset( $array[ $i ]) ) {
237 $array[ $i ] = intval( $array[ $i ] );
238 }
239 }
240 }
241
242 $array = array_unique( $array );
243 $snippet[ $key ] = $array;
244 return $snippet;
245 }
246
247 //add or update a snippet (html tracking code)
248 public function put( $id, $snippet ) {
249 global $tcmp;
250
251 if ( '' == $id || intval( $id ) <= 0 ) {
252 //if is a new code create a new unique id
253 $id = $this->get_last_id() + 1;
254 $snippet['id'] = $id;
255 }
256 $snippet = $this->sanitize( $id, $snippet );
257 $tcmp->options->setSnippet( $id, $snippet );
258
259 $keys = $this->keys();
260 if ( is_array( $keys ) && ! in_array( $id, $keys ) ) {
261 $keys[] = $id;
262 $this->keys( $keys );
263 }
264 return $snippet;
265 }
266
267 //remove the id snippet
268 public function remove( $id ) {
269 global $tcmp;
270 $tcmp->options->remove_snippet( $id );
271 $keys = $this->keys();
272 $result = false;
273 if ( is_array( $keys ) && in_array( $id, $keys ) ) {
274 $keys = array_diff( $keys, array( $id ) );
275 $this->keys( $keys );
276 $result = true;
277 }
278 return $result;
279 }
280
281 //verify if match with this snippet
282 private function match_snippet( $post_id, $post_type, $categories_ids, $tags_ids, $prefix, $snippet ) {
283 global $tcmp;
284 if ( ! $this->match_device_type( $snippet ) ) {
285 return false;
286 }
287
288 $include = false;
289 $post_id = intval( $post_id );
290 if ( $post_id > 0 ) {
291 $what = $prefix . 'PostsOfType_' . $post_type;
292 //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>';
293 if ( isset( $snippet[ $what . '_Active' ] ) && isset( $snippet[ $what ] ) && $snippet[ $what . '_Active' ] && $tcmp->utils->in_all_array( $post_id, $snippet[ $what ] ) ) {
294 $tcmp->log->debug(
295 'MATCH=%s SNIPPET=%s[%s] DUE TO POST=%s OF TYPE=%s IN [%s]',
296 $prefix,
297 $snippet['id'],
298 $snippet['name'],
299 $post_id,
300 $post_type,
301 $snippet[ $what ]
302 );
303 $include = true;
304 //echo '<p>DEBUG: snippet matched</p>';
305 }
306 }
307
308 return $include;
309 }
310
311 public function write_codes( $position ) {
312 global $tcmp;
313
314 $text = '';
315 $position_text = '';
316 switch ( $position ) {
317 case TCMP_POSITION_HEAD:
318 $position_text = 'HEAD';
319 break;
320 case TCMP_POSITION_BODY:
321 $position_text = 'BODY';
322 break;
323 case TCMP_POSITION_FOOTER:
324 $position_text = 'FOOTER';
325 break;
326 case TCMP_POSITION_CONVERSION:
327 $position_text = 'CONVERSION';
328 break;
329 }
330
331 $post = $tcmp->options->getPostShown();
332 $args = array( 'field' => 'code' );
333 $codes = $tcmp->manager->get_codes( $position, $post, $args );
334 if ( is_array( $codes ) && count( $codes ) > 0 ) {
335 $version = TCMP_PLUGIN_VERSION;
336 $text = "\n<!--BEGIN: TRACKING CODE MANAGER (v$version) BY INTELLYWP.COM IN $position_text//-->";
337 foreach ( $codes as $v ) {
338 $text .= "\n$v";
339 }
340 $text .= "\n<!--END: https://wordpress.org/plugins/tracking-code-manager IN $position_text//-->";
341
342 $purchase = $tcmp->options->getEcommercePurchase();
343 if ( false != $purchase && intval( $tcmp->options->getLicenseSiteCount() ) > 0 ) {
344 $text = $this->insert_dynamic_conversion_values( $purchase, $text );
345 }
346 echo $this->esc_js_code( $text );
347 }
348 }
349
350 private function esc_js_code( $text ) {
351 global $tcmp;
352 global $tcmp_allowed_html_tags;
353
354 if ( ! $tcmp->options->getSkipCodeSanitization() ) {
355 $text = wp_kses( $text, $tcmp_allowed_html_tags );
356 }
357 $text = str_replace( '&lt;', '<', $text );
358 $text = str_replace( '&gt;', '>', $text );
359 $text = str_replace( '&amp;', '&', $text );
360 $text = str_replace( '&quot;', '"', $text );
361 $text = str_replace( '&#039;', "'", $text );
362 return $text;
363 }
364
365 private function insert_dynamic_conversion_values( $purchase, $text ) {
366 global $tcmp;
367 $purchase->user_id = intval( $purchase->user_id );
368 if ( $purchase->user_id > 0 ) {
369 $user = get_user_by( 'id', $purchase->user_id );
370 if ( ! is_null( $user ) && false != $user && get_class( $user ) == 'WP_User' ) {
371 /* @var $user WP_User */
372 $purchase->email = $user->user_email;
373 $purchase->fullname = $user->user_firstname;
374 if ( '' != $user->user_lastname ) {
375 $purchase->fullname .= ' ' . $user->user_lastname;
376 }
377 }
378 }
379
380 $purchase->total = floatval( $purchase->total );
381 $purchase->amount = floatval( $purchase->amount );
382 $purchase->tax = floatval( $purchase->tax );
383
384 $fields = array(
385 'ORDERID' => $purchase->order_id,
386 'CURRENCY' => $purchase->currency,
387 'FULLNAME' => $purchase->fullname,
388 'EMAIL' => $purchase->email,
389 'PRODUCTS' => $purchase->products,
390 'AMOUNT' => $purchase->amount,
391 'TOTAL' => $purchase->total,
392 'TAX' => $purchase->tax,
393 );
394
395 $sep = '@@';
396 $buffer = '';
397 $previous = 0;
398 $start = strpos( $text, $sep );
399 if ( false == $start ) {
400 $buffer = $text;
401 } else {
402 while ( false != $start ) {
403 $buffer .= $tcmp->utils->substr( $text, $previous, $start );
404 $end = strpos( $text, $sep, $start + strlen( $sep ) );
405 if ( false != $end ) {
406 $code = $tcmp->utils->substr( $text, $start + strlen( $sep ), $end );
407 $code = $tcmp->utils->to_array( $code );
408 if ( 1 == count( $code ) ) {
409 $code[] = '';
410 }
411
412 $v = false;
413 if ( isset( $fields[ $code[0] ] ) ) {
414 $v = $fields[ $code[0] ];
415 }
416 if ( is_null( $v ) || false == $v ) {
417 $v = $code[1];
418 }
419 if ( is_numeric( $v ) ) {
420 $v = floatval( $v );
421 $v = round( $v, 2 );
422 switch ( $code[0] ) {
423 case 'TOTAL':
424 case 'AMOUNT':
425 case 'TAX':
426 $v = number_format( $v, 2, '.', '' );
427 break;
428 default:
429 $v = intval( $v );
430 break;
431 }
432 } elseif ( is_array( $v ) ) {
433 $a = '';
434 foreach ( $v as $t ) {
435 $t = str_replace( ',', '', $t );
436 if ( '' != $a ) {
437 $a .= ',';
438 }
439 $a .= $t;
440 }
441 $v = $a;
442 }
443 $v = str_replace( "'", '', $v );
444 $v = str_replace( '"', '', $v );
445 $buffer .= $v;
446
447 $previous = $end + strlen( $sep );
448 $start = strpos( $text, $sep, $previous );
449 } else {
450 $buffer .= $tcmp->utils->substr( $text, $start );
451 $previous = false;
452 $start = false;
453 }
454 }
455
456 if ( false != $previous && $previous < strlen( $text ) ) {
457 $code = $tcmp->utils->substr( $text, $previous );
458 $buffer .= $code;
459 }
460 }
461 return $buffer;
462 }
463
464 //return snippets that match with options
465 public function get_conversion_snippets( $options = null ) {
466 global $tcmp;
467
468 $defaults = array(
469 'pluginId' => 0,
470 'categoriesIds' => array(),
471 'productsIds' => array(),
472 'tagsIds' => array(),
473 );
474 $options = $tcmp->utils->parseArgs( $options, $defaults );
475
476 $result = array();
477 $plugin_id = intval( $options['pluginId'] );
478 $values = $this->values();
479
480 foreach ( $values as $snippet ) {
481 $snippet['trackMode'] = intval( $snippet['trackMode'] );
482 if ( $snippet && $snippet['trackMode'] > 0 && $snippet['trackMode'] == $plugin_id ) {
483 $match = false;
484
485 $match = ( $match || $this->match_conversion( $snippet, $plugin_id, 'ProductsIds', $options['productsIds'] ) );
486 $match = ( $match && $this->match_device_type( $snippet ) );
487 if ( ! $match ) {
488 //no selected so..all match! :)
489 if ( 0 == count( $snippet[ 'CTC_' . $plugin_id . '_ProductsIds' ] )
490 && 0 == count( $snippet[ 'CTC_' . $plugin_id . '_CategoriesIds' ] )
491 && 0 == count( $snippet[ 'CTC_' . $plugin_id . '_TagsIds' ] ) ) {
492 $match = true;
493 }
494 }
495
496 if ( $match ) {
497 $result[] = $snippet;
498 }
499 }
500 }
501 return $result;
502 }
503 private function match_conversion( $snippet, $plugin_id, $suffix, $current_ids ) {
504 global $tcmp;
505
506 $settings_ids = 'CTC_' . $plugin_id . '_' . $suffix;
507 if ( isset( $snippet[ $settings_ids ] ) ) {
508 $settings_ids = $snippet[ $settings_ids ];
509 } else {
510 $settings_ids = array();
511 }
512
513 $result = $tcmp->utils->in_all_array( $current_ids, $settings_ids );
514 return $result;
515 }
516
517 //from a post retrieve the html code that is needed to insert into the page code
518 public function get_codes( $position, $post, $args = array() ) {
519 global $tcmp;
520
521 $defaults = array( 'field' => 'code' );
522 $args = $tcmp->utils->parseArgs( $args, $defaults );
523
524 $post_id = 0;
525 $post_type = 'page';
526 $tags_ids = array();
527 $categories_ids = array();
528 if ( $post ) {
529 $post_id = $tcmp->utils->get( $post, 'ID', false );
530 if ( false == $post_id ) {
531 $post_id = $tcmp->utils->get( $post, 'post_ID' );
532 }
533 $post_type = $tcmp->utils->get( $post, 'post_type' );
534
535 $options = array(
536 'orderby' => 'name',
537 'order' => 'ASC',
538 'fields' => 'ids',
539 );
540 if ( isset( $post->ID ) ) {
541 $tags_ids = wp_get_post_tags( $post->ID, $options );
542 $categories_ids = wp_get_post_categories( $post->ID );
543 } else {
544 $tags_ids = array();
545 $categories_ids = array();
546 }
547 }
548
549 $tcmp->options->clearSnippetsWritten();
550 if ( TCMP_POSITION_CONVERSION == $position ) {
551 //write snippets previously appended
552 $ids = $tcmp->options->get_conversion_snippet_ids();
553 if ( false != $ids && count( $ids ) > 0 ) {
554 foreach ( $ids as $id ) {
555 $snippet = $tcmp->manager->get( $id );
556 if ( $snippet ) {
557 $tcmp->options->pushSnippetWritten( $snippet );
558 }
559 }
560 }
561 } else {
562 $snippets = $this->values();
563 foreach ( $snippets as $v ) {
564 if ( ! $v || ( $position > -1 && $v['position'] != $position ) || '' == $v['code'] || ! $v['active'] ) {
565 continue;
566 }
567 if ( TCMP_TRACK_MODE_CODE != $v['trackMode'] ) {
568 continue;
569 }
570 if ( $tcmp->options->hasSnippetWritten( $v ) ) {
571 $tcmp->log->debug( 'SKIPPED SNIPPET=%s[%s] DUE TO ALREADY WRITTEN', $v['id'], $v['name'] );
572 continue;
573 }
574
575 $match = false;
576 if ( ! $match && ( TCMP_TRACK_PAGE_ALL == $v['trackPage'] || $v['includeEverywhereActive'] ) ) {
577 $tcmp->log->debug( 'INCLUDED SNIPPET=%s[%s] DUE TO EVERYWHERE', $v['id'], $v['name'] );
578 $match = true;
579 }
580 if ( ! $match && $post_id > 0 && $this->match_snippet( $post_id, $post_type, $categories_ids, $tags_ids, 'include', $v ) ) {
581 $match = true;
582 }
583
584 if ( $match && $post_id > 0 ) {
585 //echo '<textarea cols="100" rows="4">check for exclude' . print_r($v, true) . '</textarea>';
586 if ( $this->match_snippet( $post_id, $post_type, $categories_ids, $tags_ids, 'except', $v ) ) {
587 //echo '<textarea cols="100" rows="4">exclude ' . print_r($v, true) . '</textarea>';
588 $tcmp->log->debug( 'FOUND AT LEAST ONE EXCEPT TO EXCLUDE SNIPPET=%s [%s]', $v['id'], $v['name'] );
589 $match = false;
590 }
591 }
592
593 if ( $match ) {
594 $tcmp->options->pushSnippetWritten( $v );
595 }
596 }
597 }
598
599 //obtain result as snippets or array of one field (tipically "id")
600 $result = $tcmp->options->getSnippetsWritten();
601 if ( 'all' != $args['field'] ) {
602 $array = array();
603 foreach ( $result as $k => $v ) {
604 $k = $args['field'];
605 if ( isset( $v[ $k ] ) ) {
606 $array[] = $v[ $k ];
607 } else {
608 $tcmp->log->error( 'SNIPPET=%s [%s] WITHOUT FIELD=%s', $v['id'], $v['name'], $k );
609 }
610 }
611 $result = $array;
612 }
613 return $result;
614 }
615
616 //ottiene o salva tutte le chiavi dei tracking code utilizzati ordinati per id
617 public function keys( $keys = null ) {
618 global $tcmp;
619
620 if ( is_array( $keys ) ) {
621 $tcmp->options->setSnippetList( $keys );
622 $result = $keys;
623 } else {
624 $result = $tcmp->options->getSnippetList();
625 }
626
627 if ( ! is_array( $result ) ) {
628 $result = array();
629 } else {
630 sort( $result );
631 }
632 return $result;
633 }
634
635 //ottiene il conteggio attuale dei tracking code
636 public function count() {
637 $result = count( $this->keys() );
638 return $result;
639 }
640 public function codes_count() {
641 $result = 0;
642 $ids = $this->keys();
643 foreach ( $ids as $id ) {
644 $snippet = $this->get( $id );
645 if ( $snippet ) {
646 $result += 1;
647 }
648 }
649 return $result;
650 }
651 public function get_last_id() {
652 $result = 0;
653 $list = $this->keys();
654 foreach ( $list as $v ) {
655 $v = intval( $v );
656 if ( $v > $result ) {
657 $result = $v;
658 }
659 }
660 return $result;
661 }
662
663 public function values() {
664 $keys = $this->keys();
665 $array = array();
666 foreach ( $keys as $k ) {
667 $v = $this->get( $k );
668 $array[] = $v;
669 }
670 usort( $array, array( $this, 'values_compare' ) );
671
672 $result = array();
673 foreach ( $array as $v ) {
674 $id = $v['id'];
675 $result[ $id ] = $v;
676 }
677 return $result;
678 }
679 public function values_compare( $o1, $o2 ) {
680 global $tcmp;
681 $v1 = $tcmp->utils->iget( $o1, 'order', false );
682 $v2 = $tcmp->utils->iget( $o2, 'order', false );
683 $result = ( $v1 - $v2 );
684 if ( 0 == $result ) {
685 $v1 = $tcmp->utils->get( $o1, 'name', false );
686 $v2 = $tcmp->utils->get( $o2, 'name', false );
687 $result = strcasecmp( $v1, $v2 );
688 }
689 return $result;
690 }
691 }
692