Ignore:
Timestamp:
Aug 24, 2019 10:26:26 PM (6 years ago)
Author:
anonymous
Message:

dispaly message for debug

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/testa/php/content.php

    r25 r27  
    1212function get_url_data_array()
    1313{
    14         $yaml= spyc_load_file( dirname(__FILE__) . "/../settings.yml");// ☆の部分にはyamlファイルがあるパスを入れます
    15         return $yaml;
     14    $yaml= spyc_load_file( dirname(__FILE__) . "/../settings.yml");// ☆の部分にはyamlファイルがあるパスを入れます
     15    return $yaml;
    1616}
    1717
     
    3333}
    3434
    35 function get_path_from_url_data( $num ){
    36     return get_url_data( $num )['path'];
    37 }
    38 
    39 function get_path_list_by_url( $num ){
    40     $pattern = "*.md";
    41     $top_path = get_path_from_url_data($num);
    42     $cmd_line_items = array("find" , $top_path , "-name", $pattern);
     35function get_path_from_url_data( $num , $part){
     36    switch($part){
     37    case 'data':
     38        $ret = get_url_data( $num )['path'];
     39        break;
     40    case 'setting':
     41        $ret = get_url_data( $num )['setting_path'];
     42        break;
     43    case 'output':
     44        $ret = get_url_data( $num )['output_path'];
     45        break;
     46    default:
     47        //exit(200);
     48        echo "get_path_from_url_data " . $part . "<br>";
     49    }
     50
     51    return $ret;
     52}
     53
     54function get_path_list_by_url( $num , $part){
     55    $top_path = get_path_from_url_data($num, $part);
     56
     57    switch($part){
     58    case 'data':
     59        $pattern = "*.md";
     60        $cmd_line_items = array("find" , $top_path , "-name", $pattern);
     61        break;
     62    case 'setting':
     63        $cmd_line_items = array("find" , $top_path , "-type", "f");
     64        break;
     65    default:
     66        echo "get_path_list_by_url=" . $part . "<br>";
     67        exit(100);
     68    }
    4369    $cmd_line = implode(" " , $cmd_line_items);
    4470
     
    6793        }
    6894        echo $v . "||(" . strlen($v) . ")\n";
    69    }
     95    }
    7096}
    7197
     
    81107}
    82108
    83 function get_path_info( $num ){
    84     $path_info = get_path_list_by_url( $num );
     109function get_path_info( $num , $part){
     110    $path_info = get_path_list_by_url( $num , $part);
    85111    $pathinfo = new ns\PathInfo($path_info["top_path"]);
    86 #    $pathinfo = new PathInfo($path_info["top_path"]);
    87112    foreach($path_info["file_list"] as $path){
    88113        $pathinfo->register($path);
    89114    }
    90115    return $pathinfo->pathinfo_list_in_json();
    91 #    $pathinfo->dump();
    92 #    $pathinfo->dump_root();
    93 #    dump_hier_list($pathinfo);
    94 }
    95 
    96 function print_get_path_info( $num ){
    97     echo get_path_info( $num );
     116}
     117
     118function get_setting_path_info( $num ){
     119    $path_info = get_setting_path_list_by_url( $num );
     120    $pathinfo = new ns\PathInfo($path_info["top_path"]);
     121    foreach($path_info["file_list"] as $path){
     122        $pathinfo->register($path);
     123    }
     124    return $pathinfo->pathinfo_list_in_json();
     125}
     126
     127function print_get_path_info( $num ,$part){
     128    echo get_path_info( $num , $part);
     129}
     130
     131function print_get_setting_path_info( $num ){
     132    echo get_setting_path_info( $num );
    98133}
    99134
     
    113148}
    114149
    115 function get_content( $num , $path ) {
    116     $top_dir = get_path_from_url_data( $num );
     150function get_content( $num , $path , $part) {
     151    $top_dir = get_path_from_url_data( $num , $part);
    117152    $full_path = implode( '/', [$top_dir, $path]);
    118153    $result = input_file( $full_path );
     
    121156
    122157function cmdx(){
    123     $filelist_filename = "filelist.json";
    124     $setting_filelist_filename = "setting-filelist.json";
     158    $filelist_filename = array("data"=> "filelist.json", "setting"=> "setting-filelist.json");
    125159    $storage_dir = dirname(__FILE__) . '/../storage';
    126160
     
    130164        if (isset($_GET['num'])) {
    131165            $num = $_GET['num'];
    132 
    133             switch ($cmd) {
    134             case 'get_setting_filelist':
    135                 $path = ensure_storage_dir( $storage_dir , $num, $setting_filelist_filename );
    136                 if( file_exists($path) ){
    137                     $content = input_file( $path );
     166            if (isset($_GET['part'])) {
     167                $part = $_GET['part'];
     168
     169                switch ($cmd) {
     170                case 'update_setting_filelist':
     171                    $path = ensure_storage_dir( $storage_dir , $num, $setting_filelist_filename );
     172                    $content = get_setting_path_info( $num );
     173                    output_file( $path , $content );
     174                    break;
     175                case 'get_setting_filelist':
     176                    $path = ensure_storage_dir( $storage_dir , $num, $setting_filelist_filename );
     177                    if( file_exists($path) ){
     178                        $content = input_file( $path );
     179                    }
     180                    else {
     181                        $content = get_setting_path_info( $num );
     182                        output_file( $path , $content );
     183                    }
     184                    break;
     185                case 'get_setting_content':
     186                    if (isset($_GET['path'])) {
     187                        $path = $_GET['path'];
     188                        $content = get_setting_content( $num , $path );
     189                    }
     190                    break;
     191                case 'build':
     192                    break;
     193                case 'get_content':
     194                    if (isset($_GET['path'])) {
     195                        $path = $_GET['path'];
     196                        $content = get_content( $num , $path , $part );
     197                    }
     198                    break;
     199                case 'update_filelistx':
     200                    $path = ensure_storage_dir( $storage_dir , $num, $filelist_filename[$part] );
     201                    $content = get_path_info( $num , $part);
     202                    output_file( $path , $content );
     203                    break;
     204                case 'get_filelistx':
     205                    $path = ensure_storage_dir( $storage_dir , $num, $filelist_filename[$part] );
     206                    if( file_exists($path) ){
     207                        $content = input_file( $path );
     208                    }
     209                    else {
     210                        $content = get_path_info( $num , $part);
     211                        output_file( $path , $content );
     212                    }
     213                    break;
     214                default:
     215                    break;
    138216                }
    139                 else {
    140                     $content = get_path_info( $num );
    141                     output_file( $path , $content );
    142                 }
    143                 break;
    144             case 'build':
    145                 break;
    146             case 'get_content':
    147                 if (isset($_GET['path'])) {
    148                     $path = $_GET['path'];
    149                     $content = get_content( $num , $path );
    150                 }
    151                 break;
    152             case 'update_filelist':
    153                 $path = ensure_storage_dir( $storage_dir , $num, $filelist_filename );
    154                 $content = get_path_info( $num );
    155                 output_file( $path , $content );
    156                 break;
    157             case 'get_filelist':
    158                 $path = ensure_storage_dir( $storage_dir , $num, $filelist_filename );
    159                 if( file_exists($path) ){
    160                     $content = input_file( $path );
    161                 }
    162                 else {
    163                     $content = get_path_info( $num );
    164                     output_file( $path , $content );
    165                 }
    166                 break;
    167             default:
    168                 break;
    169217            }
    170218        }
    171219    }
     220
    172221    elseif (isset($_POST['cmd'])) {
    173222        $cmd = $_POST['cmd'];
    174223        if (isset($_POST['num'])) {
    175224            $num = $_POST['num'];
    176 
    177             switch ($cmd) {
    178             case 'upload_content':
    179                 $array = get_lines_from_formdata( "mytext" );
    180                 $upload_content = implode( "\n" , $array );
    181                 if (isset($_POST['path'])) {
    182                     $path = $_POST['path'];
    183                     $top_path = get_path_from_url_data( $num );
    184                     $filename_abs_path = $top_path . DIRECTORY_SEPARATOR . $path;
    185 
    186                     output_file( $filename_abs_path , $upload_content );
    187                     $content = "P-UPLOAD_CONTENT-OK=" . $filename_abs_path;
     225            if (isset($_POST['part'])) {
     226                $part = $_POST['part'];
     227
     228
     229                switch ($cmd) {
     230                case 'upload_content':
     231                    $array = get_lines_from_formdata( "mytext" );
     232                    $upload_content = implode( "\n" , $array );
     233                    if (isset($_POST['path'])) {
     234                        $path = $_POST['path'];
     235                        $top_path = get_path_from_url_data( $num , $part);
     236                        $filename_abs_path = $top_path . DIRECTORY_SEPARATOR . $path;
     237                       
     238                        output_file( $filename_abs_path , $upload_content );
     239                        $content = "P-UPLOAD_CONTENT-OK=" . $filename_abs_path;
     240                    }
     241                    else{
     242                        $content = "P-UPLOAD_CONTENT-NO-PATH";
     243                    }
     244                   
     245                default:
     246                    debug_x("P-DEFAULT");
     247                    /* $content = "P-DEFAULT";*/
     248                    break;
    188249                }
    189                 else{
    190                     $content = "P-UPLOAD_CONTENT-NO-PATH";
    191                 }
    192 
    193             default:
    194                 debug_x("P-DEFAULT");
    195                 /* $content = "P-DEFAULT";*/
    196                 break;
    197250            }
    198251        }
     
    221274#print_get_path_info( 0 );
    222275#print_get_path_info( 1 );
     276#dump_url_data( 0 );
     277#echo( get_setting_path_from_url_data( 0 ) );
     278#var_dump( get_setting_path_list_by_url( 0 ) );
     279#echo( get_setting_path_info( 0 ) );
     280#print_get_setting_path_info( 0 );
     281
    223282cmdx();
    224283
Note: See TracChangeset for help on using the changeset viewer.