| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
$file = <<< END |
|---|
| 5 |
#Control file for some plugin |
|---|
| 6 |
Maintainer: Rolando Espinoza La Fuente <rho@prosoftpeople.com> |
|---|
| 7 |
Title: Elgg test plugin |
|---|
| 8 |
Package: elggtest |
|---|
| 9 |
Priority: optional |
|---|
| 10 |
Version: 1.0 |
|---|
| 11 |
Depends: elgg (>=0.9) |
|---|
| 12 |
Tags: trackback, blog, integration |
|---|
| 13 |
Description: Brief description |
|---|
| 14 |
Description paragraph 1 |
|---|
| 15 |
. |
|---|
| 16 |
Description paragraph 2 |
|---|
| 17 |
Conflicts: elgg |
|---|
| 18 |
END; |
|---|
| 19 |
|
|---|
| 20 |
$control = parse_plugin_control($file); |
|---|
| 21 |
|
|---|
| 22 |
print_r($control); |
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
function parse_plugin_control($string) { |
|---|
| 26 |
$string = preg_replace("#\n+#", "\n", str_replace("\r", "", trim($string))); |
|---|
| 27 |
|
|---|
| 28 |
$lines = split("\n", $string); |
|---|
| 29 |
|
|---|
| 30 |
$control = array(); |
|---|
| 31 |
$lastfield = ''; |
|---|
| 32 |
|
|---|
| 33 |
foreach ($lines as $line) { |
|---|
| 34 |
if (preg_match("/^[\s\t]*#/", $line)) { |
|---|
| 35 |
continue; |
|---|
| 36 |
} |
|---|
| 37 |
elseif (preg_match("#^[^\t\s]#", $line)) { |
|---|
| 38 |
if (preg_match("#(\w+)\s*\:\s*(.*)\s*$#", $line, $matches)) { |
|---|
| 39 |
$key = $matches[1]; |
|---|
| 40 |
$val = $matches[2]; |
|---|
| 41 |
|
|---|
| 42 |
$control[$key] = $val; |
|---|
| 43 |
$lastfield = $key; |
|---|
| 44 |
} else { |
|---|
| 45 |
|
|---|
| 46 |
} |
|---|
| 47 |
} |
|---|
| 48 |
elseif (preg_match("#([\s\t]+)(.*)$#", $line, $matches)){ |
|---|
| 49 |
if (empty($lastfield)) { |
|---|
| 50 |
|
|---|
| 51 |
} |
|---|
| 52 |
elseif (trim($matches[2]) == '.') { |
|---|
| 53 |
$control[$lastfield] .= "\n"; |
|---|
| 54 |
} |
|---|
| 55 |
else { |
|---|
| 56 |
|
|---|
| 57 |
$control[$lastfield] .= "\n$matches[2]"; |
|---|
| 58 |
} |
|---|
| 59 |
} |
|---|
| 60 |
else { |
|---|
| 61 |
|
|---|
| 62 |
//error_log("Parse error: invalid plugin control file line\n$line"); |
|---|
| 63 |
} |
|---|
| 64 |
} |
|---|
| 65 |
|
|---|
| 66 |
return $control; |
|---|
| 67 |
} |
|---|
| 68 |
|
|---|
| 69 |
?> |
|---|
| 70 |
|
|---|