Changeset 14477

Show
Ignore:
Timestamp:
01/17/08 15:05:49 (11 months ago)
Author:
bergie
Message:

New helper for listing help contents

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/midcom/midcom.admin.help/help.php

    r14329 r14477  
    5353    } 
    5454 
     55    function _get_documentation_dir($component) 
     56    { 
     57        $component_dir = str_replace('.', '/', $component); 
     58        return MIDCOM_ROOT . "/{$component_dir}/documentation/"; 
     59    } 
     60 
    5561    function _generate_file_path($help_id, $component, $language) 
    5662    { 
    57         $component_dir = str_replace('.', '/', $component); 
    58         $file = MIDCOM_ROOT . "/{$component_dir}/documentation/{$help_id}.{$language}.txt"; 
     63        $file = $this->_get_documentation_dir($component) . "{$help_id}.{$language}.txt"; 
    5964        return $file; 
     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; 
    60129    } 
    61130