Changeset 39 for branches


Ignore:
Timestamp:
Aug 30, 2019 7:43:41 AM (6 years ago)
Author:
anonymous
Message:

restrict basenames

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/testa-single-bookmark/php/NorthernCross/ns/PathInfo.php

    r23 r39  
    88    protected $root_path;
    99
    10     function __construct( $root_path ){
     10    function __construct( $part, $root_path , $restrict = null){
     11        $this->part = $part;
    1112        $this->root_path = $root_path;
    1213        $this->root = new PathItem( "/" , "/");
    1314        $this->hier_hash = array();
    1415        $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 );
    1573    }
    1674
    1775    public function register( $path ){
    1876        $path2 = trim($path);
     77
    1978        if( strlen($path2) == 0 ){
    2079            echo "size is 0 - A\n";
    2180            exit(0);
    2281        }
     82
    2383        if( array_key_exists($path2,  $this->hier_hash)){
     84            echo "register" . "\n";
    2485            return;
    2586        }
     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       
    2697        $array = explode("/", $path2);
    2798        $name = array_pop($array);
     
    61132    public function pathinfo_list_in_json(){
    62133        $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 ];
    64138            $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        }
    67142        return json_encode($array);
    68143    }
    69144
    70145    public function dump() {
    71         #       var_dump($this->hier_hash);
    72146        foreach( $this->hier_hash as $a => $b ){
    73147            echo "###########\n";
Note: See TracChangeset for help on using the changeset viewer.