php7 fixes
[Pman.Builder] / PropList.php
1 <?php
2
3 /**
4  * 
5  * Use the Roo data to work out properties..
6  * 
7
8  * 
9  * 
10  */
11
12
13 require_once 'Pman.php';
14
15 class Pman_Builder_PropList extends Pman 
16 {
17     
18     
19     function getAuth() {
20        // parent::getAuth(); // load company!
21        // $au = $this->getAuthUser();
22        // if (!$au) {
23        //     $this->jerr("Not authenticated", array('authFailure' => true));
24         //}
25         //$this->authUser = $au;
26         return true;
27     }
28     function get($base, $opts = array())
29     {
30         // should be in the root directory...
31         
32         $opts = HTML_FlexyFramework::get();
33         
34         $this->src = isset($opts->Pman_Builder['roojs1_path']) ?
35             $opts->Pman_Builder['roojs1_path'] .'/docs/json':
36             realpath($opts->rootDir. '/roojs1/docs/json');
37         if (!$this->src) {
38             $this->jerr("roojs1 directory is not in top level folder, or Builder.roojs1_path is not set");
39         }
40         
41         
42         if (empty($_REQUEST['xtype'])) {
43             $this->jerr("no xtype");
44         }
45         if ($_REQUEST['xtype'] == '*all') {
46             $this->allProps();
47         }
48         
49         
50         if ($_REQUEST['xtype'] == 'Array') {
51             $this->jdata(array());
52         }
53         
54         $view = empty($_REQUEST['view']) ? 'props' : 'events';
55         
56         $ret = array( );
57         
58         if ($_REQUEST['xtype'] == '*Module' && $view == 'props') {
59             $this->jdata($this->defModule()); 
60         }
61          
62          
63         // strip non alpha chars == our  dummy xtype use '*'
64         $xtype = preg_replace('/[^a-z0-9_.-]+/i', '', $_REQUEST['xtype']);
65         //var_dump($xtype);exit;
66         
67         $guess  = array( 'Roo',  'Roo.menu' , 'Roo.form',  'Roo.data',   'Roo.grid',   'Roo.Toolbar');
68         if (!empty($_REQUEST['xns'])) {
69             $guess = array( preg_replace('/[^a-z0-9_.-]+/i', '', $_REQUEST['xns']) );
70         }
71         
72         
73         foreach( $guess as $p) {
74             $fp = $this->src . '/'. $p.'.'.$xtype . '.json';
75             if (!file_exists($fp)) {
76                 continue;
77             }
78            // var_dump(file_get_contents($fp) );
79             // is this needed?? can we just dump it out.. with a bit of kluding?
80             $jd = json_decode( file_get_contents($fp) );
81             //print_r($jd);
82             
83             foreach($jd->$view as $n=>$inf) {
84                 $ret[] = (array)$inf;
85             }
86             if ($view == 'props') {
87                 $ret = array_merge($ret, $this->defProps());
88             }
89             $this->jdata($ret);
90             exit;     
91         }
92         if (isset($_REQUEST['dataonly'])) {
93             $this->jerr('Not available');
94         }
95         return $this->jdata(array());
96     
97     }
98     
99     function defModule() {
100         return array(
101            array( 'name'=>'app', 'type'=>'Object', 'desc'=>'Application (used in perm name) and relates to directory that file is written to..' , 'def'=>'' ),
102            // we could get rid of these... and use the disabled function!!!
103            array( 'name'=>'perm', 'type'=>'String', 'desc'=>'(Optional) Permision name (eg. ListCompanies)' , 'def'=>'' ),
104            array( 'name'=> 'permtype', 'type'=>'String', 'desc'=>'Optional) A,E,S...' , 'def'=>'S' ),
105            
106            array( 'name'=>'disabled', 'type'=>'Number', 'desc'=>'Disable this panel (turn it into a function to run things at module load time)' , 'def'=>'1' ),
107            array( 'name'=>'modkey', 'type'=>'Number', 'desc'=>'Order of item (for tabs)', 'def'=>''  ),
108            
109            array( 'name'=>'module', 'type'=>'Object', 'desc'=>'Module name (eg. Pman.Tab.XXXX or Pman.Dialog.XXXX' , 'def'=>'Pman.Tab.' ),
110            array( 'name'=>'region', 'type'=>'String', 'desc'=>'center|south|east|west|north' , 'def'=>'center' ),
111            array( 'name'=>'parent', 'type'=>'Object', 'desc'=>'Name of Module to add this to.' , 'def'=> 'Pman' ),
112            array( 'name'=>'name', 'type'=>'String', 'desc'=>'Text to display when loading' , 'def'=>'Un-named Part' ),
113            
114         );
115     }
116     
117     function defProps() {
118         return  array(
119                array( 'name'=>'xtype', 'type'=>'String', 'desc'=>'Xtype name of element'),
120                array( 'name'=>'|xns', 'type'=>'Object', 'desc'=>'Namespace for xtype'),
121                
122                array( 'name'=>'style', 'type'=>'String', 'desc'=>'CSS Style'),
123                array( 'name'=>'region', 'type'=>'String', 'desc'=>'Region '), // need for panels..
124                array( 'name'=>'+buildershow', 'type'=>'Boolean', 'desc'=>'Hide from builder'), // need for panels.
125                array( 'name'=>'*prop', 'type'=>'String', 'desc'=>'Change to property'), // need for panels.
126             );
127     }
128     
129     
130     function jdata($ar, $total = false, $extra = array(), $cachekey = false)
131     {
132         if (isset($_REQUEST['dataonly'])) {
133             $this->jok($ar);
134         }
135         parent::jdata($ar);
136     }
137     function allProps()
138     {
139         $defprops = $this->defProps();
140         $ret = array();
141         $ret['*Module'] = array('events' => array(), 'props' => $this->defModule());
142         
143         foreach(scandir($this->src) as $f) {
144             if (empty($f) || $f[0] == '.' || !preg_match('/\.json$/', $f)) {
145                 continue;
146             }
147             $cls = preg_replace('/\.json$/', '', $f);
148             $fp = $this->src. '/'. $f;
149             $jd = json_decode( file_get_contents($fp) );
150             if (empty($jd->props) && empty($jd->events)) {
151                 continue;
152             }
153             $jd->props = array_merge($jd->props , $defprops);
154             $ret[$cls] = $jd;
155             
156             
157         }
158         
159         $this->jok($ret);
160         
161         $this->jok("OK");
162     }
163     
164     
165 }