Changeset 3312


Ignore:
Timestamp:
11/07/08 09:33:03 (5 years ago)
Author:
bsittler
Message:

better argument handling, and allow logo-caca.png as a special file argument

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcaca/trunk/caca-php/examples/www/img2txt.php

    r3310 r3312  
    2626 
    2727$argv = array(basename($img2txt_php)); 
    28 $args = ''; 
     28$file = isset($_FILES['file']) ? $_FILES['file']['tmp_name'] : NULL; 
     29$filename = isset($_FILES['file']) ? $_FILES['file']['name'] : NULL; 
     30$args = NULL; 
    2931if(isset($_REQUEST['args'])) 
    3032{ 
    3133        $args = $_REQUEST['args']; 
    32 } 
    33 $args=trim($args); 
    34 if(strlen($args)) 
    35 { 
    36         foreach(explode(' ', $args) as $arg) 
    37         { 
    38                 $argv[] = $arg; 
     34        if(strlen($args)) 
     35        { 
     36                foreach(explode(' ', $args) as $arg) 
     37                { 
     38                        $argv[] = $arg; 
     39                } 
    3940        } 
    4041} 
     
    224225        $stderr .= sprintf("Usage: %s [OPTIONS]... <IMAGE>\n", $argv[0]); 
    225226        $stderr .= sprintf("Convert IMAGE to any text based available format.\n"); 
    226         $stderr .= sprintf("Example : %s -w 80 -f ansi ./caca.png\n\n", $argv[0]); 
     227        $stderr .= sprintf("Example : -W 80 -f html logo-caca.png\n\n", $argv[0]); 
    227228        $stderr .= sprintf("Options:\n"); 
    228229        $stderr .= sprintf("  -h, --help\t\t\tThis help\n"); 
     
    348349        } 
    349350 
     351        global $file, $filename; 
     352 
     353        if((! $file) && ($argc == 2) && ($argv[1] == 'logo-caca.png')) 
     354        { 
     355                $file = 'logo-caca.png'; 
     356                $argc = 1; 
     357        } 
     358 
    350359        if($argc > 1) 
    351360        { 
     
    354363                return 1; 
    355364        } 
    356  
    357         $file = isset($_FILES['file']) ? $_FILES['file']['tmp_name'] : NULL; 
    358         $filename = isset($_FILES['file']) ? $_FILES['file']['name'] : NULL; 
    359365 
    360366        if(! $file) 
     
    466472        return 0; 
    467473} 
    468 if(main() || strlen($stdout) || strlen($stderr)) 
     474$ret = 1; 
     475if(isset($_REQUEST['args']) || $file) 
     476{ 
     477        $ret = main(); 
     478} 
     479if($ret || strlen($stdout) || strlen($stderr)) 
    469480{ 
    470481        header('Content-Type: text/html; charset=UTF-8'); 
     
    484495<br /> 
    485496<label for="args">Options:</label> 
    486 <input id="args" name="args" type="text" value="<?= htmlspecialchars($args) ?>" size="80" /> 
     497<input id="args" name="args" type="text" value="<?= isset($_REQUEST['args']) ? htmlspecialchars($_REQUEST['args']) : '' ?>" size="80" /> 
    487498<br /> 
    488499<input type="submit" /> 
     
    492503        if(strlen($stderr)) 
    493504        { 
    494                 ?><pre xml:space="preserve"><em><?= htmlspecialchars($stderr) ?></em></pre><?php 
     505                ?><pre xml:space="preserve"><em><?= preg_replace('!(logo-caca[.]png)!', '<a href="$1">$1</a>', htmlspecialchars($stderr)) ?></em></pre><?php 
    495506                        ; 
    496507        } 
    497508        if(strlen($stdout)) 
    498509        { 
    499                 ?><pre xml:space="preserve"><?= htmlspecialchars($stdout) ?></pre><?php 
     510                ?><pre xml:space="preserve"><?= preg_replace('!([&]lt;)([.a-zA-Z0-9]+[@][-.a-zA-Z0-9]+)([&]gt;)!', '$1<a href="mailto:$2">$2</a>$3', preg_replace('!(\s|^)(http://[-.:_/0-9a-zA-Z%?=&;#]+)(\s|$)!', '$1<a href="$2">$2</a>$3', htmlspecialchars($stdout))) ?></pre><?php 
    500511                        ; 
    501512        } 
Note: See TracChangeset for help on using the changeset viewer.