EDD_SL_Plugin_Updater.php
8 years ago
ad-ajax.php
8 years ago
ad-debug.php
8 years ago
ad-model.php
8 years ago
ad-select.php
9 years ago
ad.php
8 years ago
ad_ajax_callbacks.php
8 years ago
ad_group.php
8 years ago
ad_placements.php
8 years ago
ad_type_abstract.php
11 years ago
ad_type_content.php
8 years ago
ad_type_dummy.php
8 years ago
ad_type_group.php
8 years ago
ad_type_image.php
8 years ago
ad_type_plain.php
8 years ago
checks.php
8 years ago
display-conditions.php
8 years ago
filesystem.php
8 years ago
frontend_checks.php
8 years ago
plugin.php
8 years ago
upgrades.php
8 years ago
utils.php
8 years ago
visitor-conditions.php
8 years ago
widget.php
8 years ago
utils.php
77 lines
| 1 | <?php |
| 2 | class Advanced_Ads_Utils { |
| 3 | /** |
| 4 | * Merges multiple arrays, recursively, and returns the merged array. |
| 5 | * |
| 6 | * This function is similar to PHP's array_merge_recursive() function, but it |
| 7 | * handles non-array values differently. When merging values that are not both |
| 8 | * arrays, the latter value replaces the former rather than merging with it. |
| 9 | * |
| 10 | * Example: |
| 11 | * $link_options_1 = array( 'fragment' => 'x', 'class' => array( 'a', 'b' ) ); |
| 12 | * $link_options_2 = array( 'fragment' => 'y', 'class' => array( 'c', 'd' ) ); |
| 13 | * // This results in array( 'fragment' => 'y', 'class' => array( 'a', 'b', 'c', 'd' ) ). |
| 14 | * |
| 15 | * @param array $arrays An arrays of arrays to merge. |
| 16 | * @param bool $preserve_integer_keys (optional) If given, integer keys will be preserved and merged instead of appended. |
| 17 | * @return array The merged array. |
| 18 | * @copyright Copyright 2001 - 2013 Drupal contributors. License: GPL-2.0+. Drupal is a registered trademark of Dries Buytaert. |
| 19 | */ |
| 20 | public static function merge_deep_array( array $arrays, $preserve_integer_keys = FALSE ) { |
| 21 | $result = array(); |
| 22 | foreach ( $arrays as $array ) { |
| 23 | if ( ! is_array( $array ) ) { continue; } |
| 24 | |
| 25 | foreach ( $array as $key => $value ) { |
| 26 | // Renumber integer keys as array_merge_recursive() does unless |
| 27 | // $preserve_integer_keys is set to TRUE. Note that PHP automatically |
| 28 | // converts array keys that are integer strings (e.g., '1') to integers. |
| 29 | if ( is_integer( $key ) && ! $preserve_integer_keys ) { |
| 30 | $result[] = $value; |
| 31 | } |
| 32 | // Recurse when both values are arrays. |
| 33 | elseif ( isset( $result[ $key ] ) && is_array( $result[ $key ] ) && is_array( $value ) ) { |
| 34 | $result[ $key ] = self::merge_deep_array( array( $result[ $key ], $value ), $preserve_integer_keys ); |
| 35 | } |
| 36 | // Otherwise, use the latter value, overriding any previous value. |
| 37 | else { |
| 38 | $result[ $key ] = $value; |
| 39 | } |
| 40 | } |
| 41 | } |
| 42 | return $result; |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | * Convert array of html attributes to string. |
| 47 | * |
| 48 | * @param array $data |
| 49 | * @return string |
| 50 | * @since untagged |
| 51 | */ |
| 52 | public static function build_html_attributes( $data ) { |
| 53 | $result = ''; |
| 54 | foreach ( $data as $_html_attr => $_values ){ |
| 55 | if ( $_html_attr == 'style' ){ |
| 56 | $_style_values_string = ''; |
| 57 | foreach ( $_values as $_style_attr => $_style_values ){ |
| 58 | if ( is_array( $_style_values ) ) { |
| 59 | $_style_values_string .= $_style_attr . ': ' .implode( ' ', $_style_values ). '; '; } |
| 60 | else { |
| 61 | $_style_values_string .= $_style_attr . ': ' .$_style_values. '; '; } |
| 62 | } |
| 63 | $result .= " style=\"$_style_values_string\""; |
| 64 | } else { |
| 65 | if ( is_array( $_values ) ) { |
| 66 | $_values_string = implode( ' ', $_values ); } |
| 67 | else { |
| 68 | $_values_string = sanitize_title( $_values ); } |
| 69 | $result .= " $_html_attr=\"$_values_string\""; |
| 70 | } |
| 71 | } |
| 72 | return $result; |
| 73 | } |
| 74 | |
| 75 | |
| 76 | } |
| 77 | ?> |