Changeset 39 for branches/testa-single-bookmark/php/NorthernCross
- Timestamp:
- Aug 30, 2019 7:43:41 AM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/testa-single-bookmark/php/NorthernCross/ns/PathInfo.php
r23 r39 8 8 protected $root_path; 9 9 10 function __construct( $root_path ){ 10 function __construct( $part, $root_path , $restrict = null){ 11 $this->part = $part; 11 12 $this->root_path = $root_path; 12 13 $this->root = new PathItem( "/" , "/"); 13 14 $this->hier_hash = array(); 14 15 $this->hier_hash["/"] = $this->root; 16 $this->restrict = null; 17 $this->restrict_dir = array(); 18 if( $restrict !== null ){ 19 $this->restrict = array(); 20 foreach($restrict as $k => $v){ 21 $pathinfo = pathinfo($v); 22 array_push( $this->restrict, $pathinfo['filename'] ); 23 } 24 } 25 } 26 27 public function match_in_list0( $path2, $list ){ 28 $hit = false; 29 30 foreach( $list as $k => $r ){ 31 if( preg_match($r , $path2) ){ 32 $hit = true; 33 break; 34 } 35 } 36 return $hit; 37 } 38 39 public function match_in_list( $path, $list ){ 40 $hit = false; 41 42 $pathinfo = pathinfo($path); 43 $index = array_search( $pathinfo['dirname'] , $list ); 44 if( $index !== FALSE ){ 45 $hit = true; 46 } 47 return $hit; 48 } 49 50 public function scan( $path ){ 51 $pathinfo = pathinfo( $path ); 52 53 $filename = $pathinfo['filename']; 54 # echo "filename=" . $filename . "\n"; 55 # $basename = $pathinfo['basename']; 56 # echo "basename=" . $basename . "\n"; 57 58 if( $this->restrict !== null ){ 59 $index = array_search( $filename , $this->restrict ); 60 if( $index !== FALSE ){ 61 $dirname = $pathinfo['dirname']; 62 $this->restrict_dir[ $dirname ] = ""; 63 } 64 } 65 } 66 67 public function show_restrict() { 68 var_dump( $this->restrict ); 69 } 70 71 public function show_restrict_dir() { 72 var_dump( $this->restrict_dir ); 15 73 } 16 74 17 75 public function register( $path ){ 18 76 $path2 = trim($path); 77 19 78 if( strlen($path2) == 0 ){ 20 79 echo "size is 0 - A\n"; 21 80 exit(0); 22 81 } 82 23 83 if( array_key_exists($path2, $this->hier_hash)){ 84 echo "register" . "\n"; 24 85 return; 25 86 } 87 88 if( $this->restrict !== null ){ 89 # echo "match_in_list\n"; 90 if( ! $this->match_in_list( $path2, array_keys( $this->restrict_dir ) ) ){ 91 # echo "!match path2=" . $path2 . "\n"; 92 return; 93 } 94 } 95 # echo "path2=" . $path2 . "\n"; 96 26 97 $array = explode("/", $path2); 27 98 $name = array_pop($array); … … 61 132 public function pathinfo_list_in_json(){ 62 133 $array = array(); 63 foreach( $this->hier_hash as $a => $b ){ 134 $keys = array_keys( $this->hier_hash ); 135 sort( $keys , SORT_STRING ); 136 foreach( $keys as $key ){ 137 $b = $this->hier_hash[ $key ]; 64 138 $names = array_map(array($this, 'get_pathitem_name'), $b->get_children()); 65 $array[$a]=$names; 66 } 139 sort($names, SORT_STRING); 140 $array[$key]=$names; 141 } 67 142 return json_encode($array); 68 143 } 69 144 70 145 public function dump() { 71 # var_dump($this->hier_hash);72 146 foreach( $this->hier_hash as $a => $b ){ 73 147 echo "###########\n";
Note: See TracChangeset
for help on using the changeset viewer.
![(trac.ini の [header_logo] セクションを設定してください)](/python/trac/Flist/chrome/common/trac_logo_mini.png)