Changeset 61

Show
Ignore:
Timestamp:
06/28/05 13:58:28
Author:
hspath
Message:

- merged with version from patSite

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/extensions/file/patXMLRendererFileExtension.php

    r2 r61  
    55* 
    66*       @access public 
    7 *       @version        $Revision$ 
    8 *       @author         $Author$ 
     7*       @version        0.1.4 
     8*       @author         Stephan Schmidt <schst@php-tools.de> 
     9*       @author         Hans Spath <dev-pat@hans-spath.de> 
    910*       @package        patXMLRenderer 
    1011*/ 
     
    2324*       @var    string  $version 
    2425*/ 
    25         var     $version        =       "0.11"; 
     26        var     $version        =       "0.1.4"; 
    2627 
    2728/** 
     
    121122                                        case    "txt": 
    122123                                        default: 
    123                                                 if( !$attributes["NEWLINE"]
     124                                                if( !isset($attributes["NEWLINE"])
    124125                                                        $attributes["NEWLINE"]  =       ""; 
    125126                                                $content        =       @implode( $attributes["NEWLINE"], @file( $data ) ); 
     
    128129                                } 
    129130                                 
    130                                 switch( strtolower( $attributes["REPLACESPECIALCHARS"] ) ) 
     131                                switch( strtolower( @$attributes["REPLACESPECIALCHARS"] ) ) 
    131132                                { 
    132133                                        case    "html": 
     
    145146                        case    "SIZE": 
    146147                                $this->renderer->addExternalFile( $data ); 
    147                                 return  filesize( $data ); 
     148                                $fileSize       =       0; 
     149                                if( file_exists( $data ) ) 
     150                                { 
     151                                        if( is_readable( $data ) ) 
     152                                                $fileSize       =       filesize( $data ); 
     153                                } 
     154 
     155                                if( isset( $attributes["RETURNFORMAT"] ) && strtolower( $attributes["RETURNFORMAT"] ) == "pretty" ) 
     156                                { 
     157                                        if( $fileSize == 0 ) 
     158                                        { 
     159                                                if( isset( $attributes["IFZERO"] ) ) 
     160                                                        $fileSize       =       $attributes["IFZERO"]; 
     161                                                else 
     162                                                        $fileSize       =       "n/a"; 
     163                                        } 
     164                                        else 
     165                                        { 
     166                                                $transform              =       array( 
     167                                                                                                        "GByte" =>      1024 * 1024 * 1024, 
     168                                                                                                        "MByte" =>      1024 * 1024, 
     169                                                                                                        "KByte" =>      1024, 
     170                                                                                                        "Byte"  =>      1 
     171                                                                                                ); 
     172                                                foreach( $transform as $title => $div ) 
     173                                                { 
     174                                                        $size   =       $fileSize / $div; 
     175         
     176                                                        if( $size < 1 ) 
     177                                                                continue; 
     178                                                        $fileSize       =       number_format( $size, 2, ",", "." ) . " " . $title; 
     179                                                        break; 
     180                                                } 
     181                                        } 
     182                                } 
     183                                 
     184                                return  $fileSize; 
    148185                                break; 
    149186 
     
    162199                                        $percentage     =       75; 
    163200 
    164                                 if( $attributes["DIR"]
     201                                if( isset( $attributes["DIR"] )
    165202                                        $dirname        =       $attributes["DIR"]; 
    166203                                else 
    167204                                        $dirname        =       $this->renderer->getXMLDir(); 
    168205 
    169                                 $newdir                 =       dirname( $data ); 
    170          
    171          
    172                                 if( $newdir == $data )   
    173                                         $newdir         =       false; 
     206                                $files                  =       $this->getSimilarFiles( $data, $dirname, $percentage );  
     207                                         
     208                                if( !empty( $files ) ) 
     209                                { 
     210                                        $data   =       "<filelist>"; 
     211                                        for( $i=0; $i<count( $files ); $i++ ) 
     212                                                $data   .=      "<file url=\"".$files[$i]."\"/>"; 
     213                                        $data   .=      "</filelist>"; 
     214                                } 
    174215                                else 
    175                                         $data                   =       basename( $data ); 
    176                                  
    177                                 if( $newdir ) 
    178                                         $dirname        =       $dirname."/".$newdir; 
    179                                  
    180                                 //      open dir and read all files 
    181                                 $dir    =       dir( $dirname ); 
    182                                 $files  =       array(); 
    183                                 while( $entry = $dir->read() ) 
    184                                 { 
    185                                         if( $entry != "." && $entry != ".." ) 
    186                                         { 
    187                                                 $p              =       0; 
    188                                                 similar_text( $data, $entry, $p ); 
    189                                                 if( $p > $percentage ) 
    190                                                         array_push( $files, $entry ); 
    191                                         } 
    192                                 } 
    193                                 $dir->close(); 
    194  
    195                                 if( empty( $files ) ) 
    196                                         return  false; 
    197                                          
    198                                 $data   =       "<filelist>"; 
    199                                 for( $i=0; $i<count( $files ); $i++ ) 
    200                                         $data   .=      "<file url=\"".$files[$i]."\"/>"; 
    201                                 $data   .=      "</filelist>"; 
     216                                { 
     217                                        return  "<noFiles/>"; 
     218                                } 
    202219                                return  $data; 
    203220                                break; 
     
    209226                return  false; 
    210227        } 
     228 
     229/** 
     230*       search for similar files 
     231* 
     232*       @access private 
     233*       @param  string  $filename 
     234*       @param  string  $baseDir 
     235*       @param  integer $percentage 
     236*       @return array   $files 
     237*/ 
     238        function        getSimilarFiles( $filename, $baseDir, $percentage ) 
     239        { 
     240                //      extract dirname and filename 
     241                $newdir                 =       dirname( $filename ); 
     242         
     243                if( $newdir == $filename )       
     244                        $newdir         =       false; 
     245                else 
     246                        $filename       =       basename( $filename ); 
     247 
     248                         
     249                if( !empty( $newdir ) ) 
     250                { 
     251                        $dirname        =       $baseDir."/".$newdir; 
     252                        if( !file_exists( $dirname ) || !is_dir( $dirname ) ) 
     253                        { 
     254                                $dirname                =       $baseDir; 
     255                                $newdir                 =       ""; 
     256                        } 
     257                }        
     258 
     259                $files  =       $this->recursiveSearch( $filename, $dirname, $percentage, $newdir ); 
     260                return  $files; 
     261        } 
     262 
     263/** 
     264*       recursively search a directory 
     265* 
     266*       @access private 
     267*       @param  string  $filename 
     268*       @param  string  $baseDir 
     269*       @param  integer $percentage 
     270*       @param  string  $path 
     271*       @return array   $files 
     272*/ 
     273        function        recursiveSearch( $filename, $dirname, $percentage, $path = "" ) 
     274        { 
     275                //      open dir and read all files 
     276                if( !$dir = @dir( $dirname ) ) 
     277                        return  false; 
     278 
     279                $files  =       array(); 
     280         
     281                while( $entry = $dir->read() ) 
     282                { 
     283                        if( $entry == "." || $entry == ".." ) 
     284                                continue; 
     285 
     286                        if( is_dir( $dirname."/".$entry ) ) 
     287                        { 
     288                                //      scan the subdir 
     289                                $tmp    =       $this->recursiveSearch( $filename, $dirname."/".$entry, $percentage, $path.$entry ); 
     290 
     291                                if( !is_array( $tmp ) ) 
     292                                        continue; 
     293                                foreach( $tmp as $file ) 
     294                                        array_push( $files, $file ); 
     295                        } 
     296                        elseif( is_file( $dirname."/".$entry ) ) 
     297                        { 
     298                                $p              =       0; 
     299                                similar_text( $filename, $entry, $p ); 
     300                                if( $p > $percentage ) 
     301                                        array_push( $files, $path . "/" . $entry ); 
     302                        } 
     303                } 
     304                $dir->close(); 
     305                 
     306                if( empty( $files ) ) 
     307                        return  false; 
     308 
     309                return  $files; 
     310        } 
    211311} 
    212312?> 
  • trunk/extensions/file/patXMLRendererFileExtension.xml

    r2 r61  
    77                <configValue type="string" name="name">File Extension</configValue> 
    88                <configValue type="string" name="class">patXMLRendererFileExtension</configValue> 
    9                 <configValue type="float" name="version">0.11</configValue> 
     9                <configValue type="string" name="version">0.1.4</configValue> 
    1010                <configValue type="string" name="requiredRandyVersion">0.5</configValue> 
    1111                <configValue type="string" name="description"> 
     
    5656                                <configValue type="string" name="tag"> 
    5757                                        Returns the filesize of a file in bytes. 
     58                                </configValue> 
     59                                <configValue type="array" name="attribs"> 
     60                                        <configValue type="array" name="returnformat"> 
     61                                                <configValue type="string" name="desc">allows you to specify a returnformat for the value. By default the the filesize is returned in bytes</configValue> 
     62                                                <configValue type="array" name="values"> 
     63                                                        <configValue type="string" name="pretty">automatically converts the size to KByte, MByte or GByte</configValue> 
     64                                                </configValue> 
     65                                        </configValue> 
    5866                                </configValue> 
    5967                                <configValue type="string" name="cdata">