fluxcms /inc/bx/popoon/components/generators/admintree.php

Language PHP Lines 157
MD5 Hash a0b7650197dc7d0a595b713825af5f30
Repository https://github.com/chregu/fluxcms.git View Raw File View Project SPDX
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
<?php

class popoon_components_generators_admintree extends popoon_components_reader {
    
    private $requestUri = "";
    
    
    function __construct ($sitemap) {
        parent::__construct($sitemap);
        $this->requestUri = str_replace('//', '/', $_SERVER['REQUEST_URI']);
    }
    
   
    function init($attribs) {
        parent::init($attribs);
    } 
    
    
    public function DomStart(&$xml) {
        
        if (!empty($this->requestUri)) {
            
            $strpos = strpos($this->requestUri,"/admin/navi/tree");
            $path = substr($this->requestUri,$strpos+16);
            if (!$path) {
                $path = '/';
            }
             /* strip GET params for collection lookup */
            $path = preg_replace("/\?.*$/", "", $path);
            $outputPath = $path;
            // FIXME: No hardcoded Paths, and no preg_replace'ing them 
            if (preg_match("/\/data\//", $path)) {
                $path = preg_replace("/\/data/", "", $path);
                
            }
            
           
        
        }
        $permObj = bx_permm::getInstance(bx_config::getInstance()->getConfProperty('permm'));

        $p = bx_collections::getCollectionAndFileParts($path, "output");
        $coll = $p['coll'];
        
        $dom = new domDocument();
        $dom->loadXML("<navitree/>");
        
        $pathNode = $dom->createElement('path');
        $pathNode->appendChild($dom->createTextNode($outputPath));
        $dom->documentElement->appendChild($pathNode);
        $params = $this->getGetParamsNode($dom);
        $dom->documentElement->appendChild($params);
     //   $dom->documentElement->appendChild());
        $ch = $coll->getChildren($p['rawname']) ;
        
        usort($ch,array("popoon_components_generators_admintree","sortByRang"));
        foreach( $ch as $element => $entry) {
            
            $el = $dom->createElement("item");
            $el->setAttribute('mimetype',$entry->getProperty("output-mimetype")); 
            $el->setAttribute('uri',$entry->getLocalName()); 
               
            switch ($entry->getProperty("output-mimetype")) {
                case "httpd/unix-directory":
                
                    $el->setAttribute('iconAction',"testopen('".$coll->uri.$p['rawname'].$entry->getBaseName()."/',this)");
                    $el->setAttribute('icon', BX_WEBROOT.'admin/webinc/img/icons/fileicon_folder.gif');
                    $el->setAttribute('openIcon', BX_WEBROOT.'admin/webinc/img/icons/fileicon_folder.gif');
                    $el->setAttribute('title',$entry->getDisplayName());
                    $el->setAttribute('src', BX_WEBROOT.'admin/navi/tree'.$entry->uri);
                    $do = $entry->getDisplayOrder();
                    if ($do) {
                        $do = " (".$do .")";
                    } else {
                        $do = '';
                    }
                    $el->setAttribute('name', $entry->getBaseName() .$do);
                    $el->setAttribute('action',BX_WEBROOT. 'admin/overview'.$coll->uri.$p['rawname'].$entry->getBaseName().'/');
                    
                    if($entry->getBaseName() == 'themes' AND $permObj->isAllowed('/',array('admin'))) {
                        $dom->documentElement->appendChild($el);
                    } else if($entry->getBaseName() != 'themes') {
                        $dom->documentElement->appendChild($el);
                    }
                
                break;

                default:
                    $mimetype = $entry->getMimeType();
                    $el->setAttribute('iconAction',"testopen('".$coll->uri.$p['rawname'].$entry->getLocalName()."',this)");
                    $el->setAttribute('action', BX_WEBROOT.'admin/overview'.$coll->uri.$p['rawname'].$entry->getLocalName());
                    $el->setAttribute('icon', BX_WEBROOT.'admin/webinc/img/icons/'.$mimetype.'.gif');
                    $el->setAttribute('openIcon', BX_WEBROOT.'admin/webinc/img/icons/'.$mimetype.'.gif');
                    $el->setAttribute('title',$entry->getDisplayName());
                    $el->setAttribute('name', $entry->getLocalName() );
                    $dom->documentElement->appendChild($el);
                    
                
            }
            
            
         }
        
        $xml = $dom;
    }
    
    
    static function sortByRang($a,$b) {
            
            $aIsDir = ($a->getMimeType() == "httpd/unix-directory") ?true :false;
             $bIsDir = ($b->getMimeType() == "httpd/unix-directory") ?true :false;
            
            if ($aIsDir && !($bIsDir)) {
                
                return -1;
            }
            
            if ($bIsDir && !($aIsDir)) {
                return 1;
            }
            $ad = $a->getDisplayOrder();
            $bd = $b->getDisplayOrder();
            
            if ($ad == $bd) {
                return (strtolower($a->getLocalName()) < strtolower($b->getLocalName())) ? -1 : 1;
            
            };
            if (!$ad) {
                return 1;
            }
            if (!$bd) {
                return -1;
            }
            return ($ad < $bd) ? -1 : 1;

    }
    
    
    protected static function getGetParamsNode(&$dom) {
        
        $params = $dom->createElement('params');
        
        foreach($_GET as $name => $value) {
       //     echo $name."00".$value."<br/>";
            $param = $dom->createElement('param');
            $param->setAttribute('name', $name);
            $param->setAttribute('value', $value);
            $params->appendChild($param);
        }
        
        return $params;
    }
    
}

?>
Back to Top