Пример #1
0
 /**
  * Files list
  */
 public function fslistAction()
 {
     $path = Request::post('node', 'string', '');
     $path = str_replace('.', '', $path);
     $dirPath = $this->_config->get('controllers');
     if (!is_dir($dirPath)) {
         Response::jsonArray(array());
     }
     if (!strlen($path)) {
         $files = array($dirPath . 'Backend', $dirPath . 'Frontend');
     } else {
         $files = File::scanFiles($dirPath . $path, array('.php'), false, File::Files_Dirs);
     }
     if (empty($files)) {
         Response::jsonArray(array());
     }
     sort($files);
     $list = array();
     foreach ($files as $k => $fpath) {
         $text = basename($fpath);
         if ($text === '.svn') {
             continue;
         }
         $obj = new stdClass();
         $obj->id = str_replace($dirPath, '', $fpath);
         $obj->text = $text;
         if ($obj->text === 'Controller.php') {
             $controllerName = str_replace(array($dirPath, DIRECTORY_SEPARATOR), array('', '_'), substr($fpath, 0, -4));
             $obj->url = Backend_Designer_Code::getControllerUrl($controllerName);
         } else {
             $obj->url = '';
         }
         if (is_dir($fpath)) {
             $obj->expanded = false;
             $obj->leaf = false;
         } else {
             if ($text !== 'Controller.php') {
                 continue;
             }
             $obj->leaf = true;
         }
         $list[] = $obj;
     }
     if ($this->_configMain->get('allow_externals') && $path == '') {
         $config = Config::factory(Config::File_Array, $this->_configMain->get('configs') . 'externals.php');
         $eExpert = new Externals_Expert($this->_configMain, $config);
         $list[] = $eExpert->getControllersTree();
     }
     Response::jsonArray($list);
 }
Пример #2
0
 /**
  * Get controllers list for tree 
  * @return array
  */
 public function getControllersTree()
 {
     $data = array();
     foreach ($this->_configs as $path => $config) {
         if (isset($config['CLASSES'])) {
             foreach ($config['CLASSES'] as $name => $srcPath) {
                 if (substr($name, -10) == 'Controller') {
                     if (strpos($name, 'Frontend') === 0) {
                         $data[$config['INFO']['namespace']][$config['INFO']['name']]['Frontend'][] = $name;
                     } elseif (strpos($name, 'Backend') === 0) {
                         $data[$config['INFO']['namespace']][$config['INFO']['name']]['Backend'][] = $name;
                     }
                 }
             }
         }
     }
     $objRoot = '';
     if (!empty($data)) {
         foreach ($data as $vendor => $module) {
             $vendorItems = array();
             foreach ($module as $name => $item) {
                 $moduleItems = array();
                 if (isset($item['Frontend'])) {
                     $obj = new stdClass();
                     $obj->id = $this->_externalsPath . $vendor . '/' . $name . '/frontend/';
                     $obj->text = 'Frontend';
                     $obj->expanded = false;
                     $obj->leaf = false;
                     $classList = array();
                     foreach ($item['Frontend'] as $class) {
                         $obj2 = new stdClass();
                         $obj2->id = $class;
                         $obj2->text = $class;
                         $obj2->leaf = true;
                         $obj2->url = Backend_Designer_Code::getControllerUrl($class);
                         $classList[] = $obj2;
                     }
                     $obj->children = $classList;
                     $moduleItems[] = $obj;
                 }
                 if (isset($item['Backend'])) {
                     $obj = new stdClass();
                     $obj->id = $this->_externalsPath . $vendor . '/' . $name . '/backend/';
                     $obj->text = 'Backend';
                     $obj->expanded = false;
                     $obj->leaf = false;
                     $classList = array();
                     foreach ($item['Backend'] as $class) {
                         $obj2 = new stdClass();
                         $obj2->id = $class;
                         $obj2->text = $class;
                         $obj2->leaf = true;
                         $obj2->url = Backend_Designer_Code::getControllerUrl($class);
                         $classList[] = $obj2;
                     }
                     $obj->children = $classList;
                     $moduleItems[] = $obj;
                 }
                 $obj = new stdClass();
                 $obj->id = $this->_externalsPath . $vendor . '/' . $name;
                 $obj->text = $name;
                 $obj->expanded = false;
                 $obj->leaf = false;
                 $obj->children = $moduleItems;
                 $vendorItems[] = $obj;
             }
             $obj = new stdClass();
             $obj->id = $this->_externalsPath . $vendor;
             $obj->text = $vendor;
             $obj->expanded = false;
             $obj->leaf = false;
             $obj->children = $vendorItems;
         }
         $objRoot = new stdClass();
         $objRoot->id = 'externalroot';
         $objRoot->text = Lang::lang()->get('EXTERNAL');
         $objRoot->expanded = false;
         $objRoot->leaf = false;
         $objRoot->children = array($obj);
     }
     return $objRoot;
 }