Created
April 30, 2014 16:19
-
-
Save clutterjoe/5e4e4a04837d5d55284d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$base_dir = __DIR__ . '/PATH_TO_SITE/sites/all/modules/features'; | |
function drupal_parse_info_format($data) { | |
$info = array(); | |
$constants = get_defined_constants(); | |
if (preg_match_all(' | |
@^\s* # Start at the beginning of a line, ignoring leading whitespace | |
((?: | |
[^=;\[\]]| # Key names cannot contain equal signs, semi-colons or square brackets, | |
\[[^\[\]]*\] # unless they are balanced and not nested | |
)+?) | |
\s*=\s* # Key/value pairs are separated by equal signs (ignoring white-space) | |
(?: | |
("(?:[^"]|(?<=\\\\)")*")| # Double-quoted string, which may contain slash-escaped quotes/slashes | |
(\'(?:[^\']|(?<=\\\\)\')*\')| # Single-quoted string, which may contain slash-escaped quotes/slashes | |
([^\r\n]*?) # Non-quoted string | |
)\s*$ # Stop at the next end of a line, ignoring trailing whitespace | |
@msx', $data, $matches, PREG_SET_ORDER)) { | |
foreach ($matches as $match) { | |
// Fetch the key and value string. | |
$i = 0; | |
foreach (array('key', 'value1', 'value2', 'value3') as $var) { | |
$$var = isset($match[++$i]) ? $match[$i] : ''; | |
} | |
$value = stripslashes(substr($value1, 1, -1)) . stripslashes(substr($value2, 1, -1)) . $value3; | |
// Parse array syntax. | |
$keys = preg_split('/\]?\[/', rtrim($key, ']')); | |
$last = array_pop($keys); | |
$parent = &$info; | |
// Create nested arrays. | |
foreach ($keys as $key) { | |
if ($key == '') { | |
$key = count($parent); | |
} | |
if (!isset($parent[$key]) || !is_array($parent[$key])) { | |
$parent[$key] = array(); | |
} | |
$parent = &$parent[$key]; | |
} | |
// Handle PHP constants. | |
if (isset($constants[$value])) { | |
$value = $constants[$value]; | |
} | |
// Insert actual value. | |
if ($last == '') { | |
$last = count($parent); | |
} | |
$parent[$last] = $value; | |
} | |
} | |
return $info; | |
} | |
$info_array = array(); | |
if (!file_exists($base_dir)) { | |
die("base dir $base_dir doesn't exist, fool!"); | |
} else { | |
if ($handle = opendir($base_dir)) { | |
while (false !== ($entry = readdir($handle))) { | |
if (substr($entry, 0, 1) != '.') { | |
$path_to_dir = $base_dir . '/' . $entry; | |
$info_file = $path_to_dir . '/' . $entry . '.info'; | |
if (!file_exists($info_file)) { | |
die("info file $info_file doesn't exist, fool!"); | |
} else { | |
$info_str = file_get_contents($info_file); | |
$info_array[$entry] = drupal_parse_info_format($info_str); | |
} | |
} | |
} | |
closedir($handle); | |
} | |
} | |
$csv_array = array(); | |
foreach($info_array as $feature => $feature_info) { | |
if (isset($feature_info['features']['node'])) { | |
$content_type = $feature_info['features']['node'][0]; | |
foreach($feature_info['features']['field_base'] as $field_base) | |
$csv_array[] = array( | |
'field_base' => $field_base, | |
'content_type' => $content_type, | |
'branch' => '', | |
'feature' => $feature, | |
); | |
} | |
} | |
var_dump($csv_array); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment