Changeset 27 for branches/testa/php/content.php
- Timestamp:
- Aug 24, 2019 10:26:26 PM (6 years ago)
- File:
-
- 1 edited
-
branches/testa/php/content.php (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/testa/php/content.php
r25 r27 12 12 function get_url_data_array() 13 13 { 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; 16 16 } 17 17 … … 33 33 } 34 34 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); 35 function 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 54 function 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 } 43 69 $cmd_line = implode(" " , $cmd_line_items); 44 70 … … 67 93 } 68 94 echo $v . "||(" . strlen($v) . ")\n"; 69 }95 } 70 96 } 71 97 … … 81 107 } 82 108 83 function get_path_info( $num ){84 $path_info = get_path_list_by_url( $num );109 function get_path_info( $num , $part){ 110 $path_info = get_path_list_by_url( $num , $part); 85 111 $pathinfo = new ns\PathInfo($path_info["top_path"]); 86 # $pathinfo = new PathInfo($path_info["top_path"]);87 112 foreach($path_info["file_list"] as $path){ 88 113 $pathinfo->register($path); 89 114 } 90 115 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 118 function 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 127 function print_get_path_info( $num ,$part){ 128 echo get_path_info( $num , $part); 129 } 130 131 function print_get_setting_path_info( $num ){ 132 echo get_setting_path_info( $num ); 98 133 } 99 134 … … 113 148 } 114 149 115 function get_content( $num , $path ) {116 $top_dir = get_path_from_url_data( $num );150 function get_content( $num , $path , $part) { 151 $top_dir = get_path_from_url_data( $num , $part); 117 152 $full_path = implode( '/', [$top_dir, $path]); 118 153 $result = input_file( $full_path ); … … 121 156 122 157 function cmdx(){ 123 $filelist_filename = "filelist.json"; 124 $setting_filelist_filename = "setting-filelist.json"; 158 $filelist_filename = array("data"=> "filelist.json", "setting"=> "setting-filelist.json"); 125 159 $storage_dir = dirname(__FILE__) . '/../storage'; 126 160 … … 130 164 if (isset($_GET['num'])) { 131 165 $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; 138 216 } 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;169 217 } 170 218 } 171 219 } 220 172 221 elseif (isset($_POST['cmd'])) { 173 222 $cmd = $_POST['cmd']; 174 223 if (isset($_POST['num'])) { 175 224 $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; 188 249 } 189 else{190 $content = "P-UPLOAD_CONTENT-NO-PATH";191 }192 193 default:194 debug_x("P-DEFAULT");195 /* $content = "P-DEFAULT";*/196 break;197 250 } 198 251 } … … 221 274 #print_get_path_info( 0 ); 222 275 #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 223 282 cmdx(); 224 283
Note: See TracChangeset
for help on using the changeset viewer.
![(trac.ini の [header_logo] セクションを設定してください)](/python/trac/Flist/chrome/common/trac_logo_mini.png)