Ignore:
Timestamp:
Sep 5, 2019 9:42:27 AM (6 years ago)
Author:
anonymous
Message:

full, partial

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/testa-single-bookmark/php/content3.php

    r63 r67  
    1515require_once( dirname(__FILE__) . "/spyc-0.5/spyc.php"); // ★の部分にはspyc.phpを置いたパスを入れます
    1616
    17 $exec_path = dirname(__FILE__) . "/..";
     17$Top_path = dirname(__FILE__) . "/..";
     18$Url_data = null;
     19$Url_data_array = null;
    1820
    1921function get_url_data_array()
     
    2527}
    2628
    27 function get_url_data_array0()
    28 {
    29         $array = array(
    30         array('url' => 'https://toppers.jp', 'path' =>  '/var/www/vhosts/devconf.northern-cross.info/httpdocs/a/tmp/devconf-guest-4/tmp/md2site-x/_xtest/wtjx/t12/src') );
    31 
    32         return $array;
    33 }
    34 
    3529function get_url_data( $num ){
    36     $array = get_url_data_array();
    37     return $array[$num];
     30    global $Url_data_array;
     31    return $Url_data_array[$num];
    3832}
    3933
     
    4337
    4438function get_path_from_url_data( $num , $part){
     39    global $Url_data_array;
     40
    4541    switch($part){
    4642    case 'data':
    47         $ret = get_url_data( $num )['path'];
     43        $ret = $Url_data_array[$num]['path'];
    4844        break;
    4945    case 'conf':
    50         $ret = get_url_data( $num )['conf_path'];
     46        $ret = $Url_data_array[$num]['conf_path'];
    5147        break;
    5248    case 'output':
    53         $ret = get_url_data( $num )['output_path'];
     49        $ret = $Url_data_array[$num]['output_path'];
    5450        break;
    5551    default:
     
    123119}
    124120
    125 
    126121function get_path_info( $num , $part){
    127122    $path_info = get_path_list_by_url( $num , $part);
     
    138133function ensure_storage_dir( $storage_dir , $num, $filename ) {
    139134    $dir = implode( "/" , array( $storage_dir , $num) );
    140     mkdir($dir);
     135    if( !file_exists( $dir ) ){
     136        mkdir($dir);
     137    }
    141138    $path = implode( "/" , array( $dir , $filename) );
    142139    ensure_dir( $dir );
     
    152149}
    153150
    154 function build_one_html( $exec_path, $num , $md_path , $part) {
     151function build_one_html( $top_path, $num , $md_path , $part) {
    155152    $pathinfo = pathinfo( $md_path );
    156153    $md_fname = $pathinfo['basename'];
     
    169166    $output_url = $url_data["output_url"];
    170167
    171     $cmd_line_items = array( $exec_path . "/bin/build.sh" , $bundle_path , $t, $s, $conf_path);
     168    $cmd_line_items = array( $top_path . "/bin/build.sh" , $bundle_path , $t, $s, $conf_path);
    172169
    173170    $cmd_line = implode(" " , $cmd_line_items);
     
    191188
    192189function cmdx(){
    193     global $exec_path;
     190    global $Top_path;
     191    global $Url_data;
     192    global $Url_data_array;
     193
     194    $Url_data_array = get_url_data_array();
    194195
    195196    $filelist_filename = array("data"=> "filelist.json", "conf"=> "conf-filelist.json", "output" => "output-filelist.json");
     197    $output_url_filename = "output_url.json";
    196198    #    $storage_dir = dirname(__FILE__) . '/../storage';
    197199    $storage_dir = dirname(__FILE__) . '/../storage-devconf';
     
    202204        if (isset($_GET['num'])) {
    203205            $num = $_GET['num'];
     206
     207            $Url_data = get_url_data($num);
     208
    204209            if (isset($_GET['part'])) {
    205210                $part = $_GET['part'];
     
    237242                    $content = json_encode($info);
    238243                    break;
     244                case 'update_output_url_listx':
     245                    $content = update_output_url_list( $num );
     246                case 'get_output_url_listx':
     247                    $path = ensure_storage_dir( $storage_dir , $num , $output_url_filename );
     248                    if( file_exists($path) ){
     249                        $content = input_file( $path );
     250                    }
     251                    else {
     252                        $content = update_output_url_list( $num );
     253                    }
     254                    break;
    239255                default:
     256                    $content = "bad cmd=" . $cmd;
    240257                    break;
    241258                }
     
    248265        if (isset($_POST['num'])) {
    249266            $num = $_POST['num'];
     267
     268            $Url_data = get_url_data($num);
     269
    250270            if (isset($_POST['part'])) {
    251271                $part = $_POST['part'];
     
    259279                        $top_path = get_path_from_url_data( $num , $part);
    260280                        $filename_abs_path = $top_path . DIRECTORY_SEPARATOR . $path;
    261                         $ret = build_one_html( $exec_path , $num, $path, $part );
     281                        $ret = build_one_html( $Top_path , $num, $path, $part );
    262282                    }
    263283                    else{
     
    304324    }
    305325    else{
    306         echo($content);
     326        echo("no content");
    307327    }
    308328}
     
    331351
    332352function get_full_path($num, $key, $fname){
    333     $array = get_url_data_array();
    334     return $array[$num][$key] . "/" . $fname;
    335 }
    336 
    337 function get_restrict_from_settings_yml() {
    338     $settings = get_url_data_array();
    339     $array = $settings[0]['restrict'];
     353    global $Url_data_array;
     354    return $Url_data_array[$num][$key] . "/" . $fname;
     355}
     356
     357function get_restrict_from_settings_yml( $num ) {
     358    global $Url_data_array;
     359
     360    /*    $settings = get_url_data_array();*/
     361    $settings = $Url_data_array;
     362    if( !isset($settings[$num]) ){
     363        return array();
     364    }
     365    $array = $settings[$num]['restrict'];
     366    if( !isset( $array ) ){
     367        return array();
     368    }
    340369
    341370    $r_keys = array_keys( $array );
     
    361390    $list = get_site_tsv($num );
    362391
    363     $restrict_array = get_restrict_from_settings_yml();
     392    $restrict_array = get_restrict_from_settings_yml( $num );
    364393
    365394    foreach( $list as $k => $v ){
     
    399428}
    400429
     430function update_output_url_list( $num ){
     431    $json_data = get_output_url_list( $num );
     432    $content = json_encode($json_data);
     433    output_file( $path , $content );
     434
     435    return $content;
     436}
     437
     438function get_output_url_list( $num ){
     439    $output_url = get_output_url($num);
     440    $data = array( "output_url" => get_output_url($num),
     441           "htmlfname" => array()
     442    );
     443
     444    $list = get_site_tsv( $num );
     445    $restrict_htmlnames = get_restrict_basenames( $num );
     446
     447    $output_path = get_path_from_url_data( $num, 'output' );
     448    foreach( $list as $k => $v ){
     449        $htmlfname = $v["output_html"];
     450        if( $htmlfname !== null ){
     451            $array = array( "full" => "", "partial" => "" );
     452            if( !isset( $restrict_htmlnames[$htmlfname] ) ){
     453                $fpath =  $output_path . '/' . $htmlfname;
     454                if( file_exist($fpath) ){
     455                    $array["full"] = $htmlfname;
     456                }
     457                $fpath_tmp =  $fpath . '.tmp';
     458                if( file_exist($fpath_tmp) ){
     459                    $array["partial"] = $htmlfname_tmp;
     460                }
     461                array_push( $data["htmlfname"] , $array);
     462            }
     463        }
     464    }
     465
     466    return $data;
     467}
     468
    401469function get_output_url($num){
    402     $settings = get_url_data_array();
    403     return $settings[$num]['output_url'];
     470    return $Url_data['output_url'];
    404471}
    405472
    406473function get_restrict($num){
    407     $settings = get_url_data_array();
    408     return $settings[$num]['restrict'];
    409 }
    410 
    411 function get_item($num, $name){
    412     $settings = get_url_data_array();
    413     return $settings[$num][$name];
    414 }
    415 
    416 function get_settings_file( $name ){
    417     $dir = get_item( 0 , "conf_path" );
    418     $path = implode( "/" , [$dir, $name] );
    419 
    420     return $path;
    421 }
    422 
    423 function do_exec(){
    424     $cmd = "ls -l /z";
    425 
    426     exec($cmd, $opt, $ret);
    427 
    428 #    print_r($opt);
    429 #    echo "ret=" . $ret . "\n";
     474    /*    $settings = get_url_data_array();*/
     475    global $Url_data_array;
     476    return $Url_data_array[$num]['restrict'];
    430477}
    431478
    432479cmdx();
    433 /*
    434 do_exec();
    435 */
    436 /*
    437 $num = 0;
    438 $path = "/attempt/devconf2018/data/devconf2018.md";
    439 $part = "data";
    440 $lines = build_one_html( $exec_path, $num , $path , $part );
    441 
    442 var_dump( $lines );
    443 
    444 foreach( $lines as $k => $v ){
    445     if( is_array( $v )){
    446         echo implode( "\n" , $v );
    447     }
    448     else{
    449         echo $v . "\n";
    450     }
    451 }
    452 */
     480
     481#echo json_encode( get_output_url_list(0) );
     482# var_dump( get_output_url_list(0) );
     483#var_dump( get_output_url_list(0) );
     484#echo json_encode( get_output_url_list(0) );
    453485?>
Note: See TracChangeset for help on using the changeset viewer.