| 1 |
<?php |
<?php |
| 2 |
// $Id: base.inc,v 1.2.2.2 2009/11/16 19:52:56 merlinofchaos Exp $ |
// $Id: base.inc,v 1.2.2.3 2009/11/16 20:05:39 merlinofchaos Exp $ |
| 3 |
/** |
/** |
| 4 |
* @file |
* @file |
| 5 |
* |
* |
| 76 |
* Unpack options over our existing defaults, drilling down into arrays |
* Unpack options over our existing defaults, drilling down into arrays |
| 77 |
* so that defaults don't get totally blown away. |
* so that defaults don't get totally blown away. |
| 78 |
*/ |
*/ |
| 79 |
function unpack_options(&$storage, $options, $definition = NULL) { |
function unpack_options(&$storage, $options, $definition = NULL, $all = TRUE) { |
| 80 |
if (!is_array($options)) { |
if (!is_array($options)) { |
| 81 |
return; |
return; |
| 82 |
} |
} |
| 91 |
$storage[$key] = array(); |
$storage[$key] = array(); |
| 92 |
} |
} |
| 93 |
|
|
| 94 |
$this->unpack_options($storage[$key], $value, isset($definition[$key]['contains']) ? $definition[$key]['contains'] : array()); |
// If we're just unpacking our known options, and we're dropping an |
| 95 |
|
// unknown array (as might happen for a dependent plugin fields) go |
| 96 |
|
// ahead and drop that in. |
| 97 |
|
if (!$all && isset($definition[$key]) && !isset($definition[$key]['contains'])) { |
| 98 |
|
$storage[$key] = $value; |
| 99 |
|
continue; |
| 100 |
|
} |
| 101 |
|
|
| 102 |
|
$this->unpack_options($storage[$key], $value, isset($definition[$key]['contains']) ? $definition[$key]['contains'] : array(), $all); |
| 103 |
} |
} |
| 104 |
else if (!empty($definition[$key]['translatable']) && !empty($value)) { |
else if (!empty($definition[$key]['translatable']) && !empty($value)) { |
| 105 |
$storage[$key] = t($value); |
$storage[$key] = t($value); |
| 106 |
} |
} |
| 107 |
else { |
else if ($all || !empty($definition[$key])) { |
| 108 |
$storage[$key] = $value; |
$storage[$key] = $value; |
| 109 |
} |
} |
| 110 |
} |
} |
| 133 |
unset($this->query); |
unset($this->query); |
| 134 |
} |
} |
| 135 |
} |
} |
| 136 |
|
|
| 137 |
|
function export_options($indent, $prefix) { |
| 138 |
|
$output = ''; |
| 139 |
|
foreach ($this->option_definition() as $option => $definition) { |
| 140 |
|
$output .= $this->export_option($indent, $prefix, $this->options, $option, $definition, array()); |
| 141 |
|
} |
| 142 |
|
|
| 143 |
|
return $output; |
| 144 |
|
} |
| 145 |
|
|
| 146 |
|
function export_option($indent, $prefix, $storage, $option, $definition, $parents) { |
| 147 |
|
// Do not export options for which we have no settings. |
| 148 |
|
if (!isset($storage[$option])) { |
| 149 |
|
return; |
| 150 |
|
} |
| 151 |
|
|
| 152 |
|
if (isset($definition['export'])) { |
| 153 |
|
if ($definition['export'] === FALSE) { |
| 154 |
|
return; |
| 155 |
|
} |
| 156 |
|
|
| 157 |
|
// Special handling for some items |
| 158 |
|
if (method_exists($this, $definition['export'])) { |
| 159 |
|
return $this->{$definition['export']}($indent, $prefix, $storage, $option, $definition, $parents); |
| 160 |
|
} |
| 161 |
|
} |
| 162 |
|
|
| 163 |
|
// Add the current option to the parents tree. |
| 164 |
|
$parents[] = $option; |
| 165 |
|
$output = ''; |
| 166 |
|
|
| 167 |
|
// If it has child items, export those separately. |
| 168 |
|
if (isset($definition['contains'])) { |
| 169 |
|
foreach ($definition['contains'] as $sub_option => $sub_definition) { |
| 170 |
|
$output .= $this->export_option($indent, $prefix, $storage[$option], $sub_option, $sub_definition, $parents); |
| 171 |
|
} |
| 172 |
|
} |
| 173 |
|
// Otherwise export just this item. |
| 174 |
|
else { |
| 175 |
|
$default = isset($definition['default']) ? $definition['default'] : NULL; |
| 176 |
|
$value = $storage[$option]; |
| 177 |
|
if (isset($definition['bool'])) { |
| 178 |
|
$value = (bool) $value; |
| 179 |
|
} |
| 180 |
|
|
| 181 |
|
if ($value !== $default) { |
| 182 |
|
$output .= $indent . $prefix . "['" . implode("']['", $parents) . "'] = "; |
| 183 |
|
if (isset($definition['bool'])) { |
| 184 |
|
$output .= empty($storage[$option]) ? 'FALSE' : 'TRUE'; |
| 185 |
|
} |
| 186 |
|
else { |
| 187 |
|
$output .= views_var_export($storage[$option], $indent); |
| 188 |
|
} |
| 189 |
|
|
| 190 |
|
$output .= ";\n"; |
| 191 |
|
} |
| 192 |
|
} |
| 193 |
|
return $output; |
| 194 |
|
} |
| 195 |
} |
} |