/**
 * Merges any number of arrays of any dimensions, the later overwriting
 * previous keys, unless the key is numeric, in whitch case, duplicated
 * values will not be added.
 *
 * The arrays to be merged are passed as arguments to the function.
 *
 * @access public
 * @return array Resulting array, once all have been merged
 */
function array_merge_replace_recursive()
{
    // Holds all the arrays passed
    $params =& func_get_args();
    // First array is used as the base, everything else overwrites on it
    $return = array_shift($params);
    // Merge all arrays on the first array
    foreach ($params as $array) {
        foreach ($array as $key => $value) {
            // Numeric keyed values are added (unless already there)
            if (is_numeric($key) && !in_array($value, $return)) {
                if (is_array($value)) {
                    $return[] = array_merge_replace_recursive($return[${$key}], $value);
                } else {
                    $return[] = $value;
                }
                // String keyed values are replaced
            } else {
                if (isset($return[$key]) && is_array($value) && is_array($return[$key])) {
                    $return[$key] = array_merge_replace_recursive($return[${$key}], $value);
                } else {
                    $return[$key] = $value;
                }
            }
        }
    }
    return $return;
}
/**
 * Magic merge of two arrays
 * - integer keys: values will be _appended_ to the first array
 * - string keys: Array-values will be _merged recursively_, non-Array-values will be _replaced_.
 *
 * Difference to array_merge_recursive:
 * - non-Array-values are replaced instead of transformation to an array (for string keys)
 * - initial array will be changed in the process instead of duplication
 *
 * @param array $array1 <p>
 * Initial array will be changed in the process!
 * </p>
 * @param array $array2
 * @return array
 */
function array_merge_replace_recursive(array &$array1, array &$array2)
{
    foreach ($array2 as $key => &$value2) {
        if (is_int($key)) {
            // append
            $array1[] = $value2;
        } else {
            if (isset($array1[$key]) && is_array($array1[$key]) && is_array($value2)) {
                // merge recursively
                array_merge_replace_recursive($array1[$key], $value2);
            } else {
                // replace
                $array1[$key] = $value2;
            }
        }
    }
    return $array1;
}
Example #3
0
 public function getApplied()
 {
     $defArray = array();
     foreach ($this->settingsDefinition as $col => $arr) {
         $defArray[$col] = array();
         foreach ($arr as $s => $def) {
             if (!empty($def['default'])) {
                 $defArray[$col][$s] = $def['default'];
             }
         }
     }
     $workingArray = array_merge_replace_recursive($defArray, $this->settings);
     //if($this->base) print_r($workingArray);
     if ($this->base) {
         $baseArr = $this->base->getApplied();
         $workingArray = array_merge_replace_recursive($baseArr, $workingArray);
     }
     //if($this->base) print_r($workingArray);
     return $workingArray;
 }
Example #4
0
$assignments = array();
global $gantry_override_assignment_info;
$gantry_override_assignment_info = array();
$data['template-options'] = get_option($gantry->templateName . '-template-options');
$override_id = 0;
$override_catalog = gantry_get_override_catalog($gantry->templateName);
if (isset($_GET['override_id'])) {
    $override_id = urldecode($_GET['override_id']);
}
if ($override_id != 0) {
    $override_option = $gantry->templateName . '-template-options-override-' . $override_id;
    $override_data = get_option($override_option);
    if ($override_data === false) {
        $override_data = array();
    }
    $data['template-options'] = array_merge_replace_recursive($data['template-options'], $override_data);
    $override_name = $override_catalog[$override_id];
    $override_assignments_option_name = $gantry->templateName . '-template-options-override-assignments-' . $override_id;
    $override_assignments = get_option($override_assignments_option_name);
    if ($override_assignments === false) {
        $override_assignments = array();
    }
    $assignments = $override_assignments;
} else {
    $next_override = count($override_catalog) > 0 ? max(array_keys($override_catalog)) + 1 : 1;
    $override_name = sprintf(_g('Custom Override %d'), $next_override);
}
GantryForm::addFormPath($gantry->templatePath);
GantryForm::addFieldPath($gantry->templatePath . '/fields');
GantryForm::addFieldPath($gantry->templatePath . '/admin/forms/fields');
$form = GantryForm::getInstance(GantryTemplateInfo::getInstance(), 'template-options', 'templateDetails', array(), true, '//config');
 /**
  * @param string $title
  */
 public function set_title($title)
 {
     $t = ['title' => ['text' => $title]];
     array_merge_replace_recursive($this->chart, $t);
     $this->chart['exportFileName'] = $title;
 }