| | 65 | } |
|---|
| | 66 | |
|---|
| | 67 | function list_files($component) |
|---|
| | 68 | { |
|---|
| | 69 | $files = array(); |
|---|
| | 70 | |
|---|
| | 71 | $path = $this->_get_documentation_dir($component); |
|---|
| | 72 | if (!file_exists($path)) |
|---|
| | 73 | { |
|---|
| | 74 | return $files; |
|---|
| | 75 | } |
|---|
| | 76 | |
|---|
| | 77 | $directory = dir($path); |
|---|
| | 78 | while (false !== ($entry = $directory->read())) |
|---|
| | 79 | { |
|---|
| | 80 | if (substr($entry, 0, 1) == '.') |
|---|
| | 81 | { |
|---|
| | 82 | // Ignore dotfiles |
|---|
| | 83 | continue; |
|---|
| | 84 | } |
|---|
| | 85 | |
|---|
| | 86 | $filename_parts = explode('.', $entry); |
|---|
| | 87 | if (count($filename_parts) < 3) |
|---|
| | 88 | { |
|---|
| | 89 | continue; |
|---|
| | 90 | } |
|---|
| | 91 | |
|---|
| | 92 | if ($filename_parts[2] != 'txt') |
|---|
| | 93 | { |
|---|
| | 94 | // Not text file, skip |
|---|
| | 95 | continue; |
|---|
| | 96 | } |
|---|
| | 97 | |
|---|
| | 98 | if ( $filename_parts[1] != $_MIDCOM->i18n->get_current_language() |
|---|
| | 99 | && $filename_parts[1] != $GLOBALS['midcom_config']['i18n_fallback_language']) |
|---|
| | 100 | { |
|---|
| | 101 | // Wrong language |
|---|
| | 102 | continue; |
|---|
| | 103 | } |
|---|
| | 104 | |
|---|
| | 105 | $subject = $_MIDCOM->i18n->get_string($filename_parts[0], $component); |
|---|
| | 106 | |
|---|
| | 107 | // We need to parse the file to get a title |
|---|
| | 108 | $file_contents = $this->get_help_contents($filename_parts[0], $component); |
|---|
| | 109 | if (preg_match("/\<h1\>(.*)\<\/h1\>/", $file_contents, $titles)) |
|---|
| | 110 | { |
|---|
| | 111 | $subject = $titles[1]; |
|---|
| | 112 | } |
|---|
| | 113 | else |
|---|
| | 114 | if (preg_match("/\<h2\>(.*)\<\/h2\>/", $file_contents, $titles)) |
|---|
| | 115 | { |
|---|
| | 116 | $subject = $titles[1]; |
|---|
| | 117 | } |
|---|
| | 118 | |
|---|
| | 119 | $files[$filename_parts[0]] = array |
|---|
| | 120 | ( |
|---|
| | 121 | 'path' => "{$path}{$entry}", |
|---|
| | 122 | 'subject' => $subject, |
|---|
| | 123 | 'lang' => $filename_parts[1], |
|---|
| | 124 | ); |
|---|
| | 125 | } |
|---|
| | 126 | $directory->close(); |
|---|
| | 127 | |
|---|
| | 128 | return $files; |
|---|