Ejemplo n.º 1
0
 /**
  * Get possible actions from Controller class.
  * Note! Code accelerator (eaccelerator, apc, xcache, etc ) should be disabled to get comment line.
  * Method returns only public methods that ends with "Action" 
  * @param string $controllerName
  * @return array like array(
  * 		array(
  * 			'name' => action name without "Action" postfix
  * 			'comment'=> doc comment
  * 		)
  * )
  */
 public static function getPossibleActions($controllerName)
 {
     $manager = new Backend_Modules_Manager();
     $appCfg = Registry::get('main', 'config');
     $designerConfig = Config::factory(Config::File_Array, $appCfg->get('configs') . 'designer.php');
     $templates = $designerConfig->get('templates');
     $reflector = new ReflectionClass($controllerName);
     if (!$reflector->isSubclassOf('Backend_Controller') && !$reflector->isSubclassOf('Frontend_Controller')) {
         return array();
     }
     $actions = array();
     $methods = $reflector->getMethods(ReflectionMethod::IS_PUBLIC);
     $url = array();
     if ($reflector->isSubclassOf('Backend_Controller')) {
         $url[] = $templates['adminpath'];
         $url[] = $manager->getModuleName($controllerName);
     } elseif ($reflector->isSubclassOf('Frontend_Controller')) {
         if ($appCfg['frontend_router_type'] == 'module') {
             $module = self::_moduleByClass($controllerName);
             if ($module !== false) {
                 $urlcode = Model::factory('Page')->getCodeByModule($module);
                 if ($urlcode !== false) {
                     $url[] = $urlcode;
                 }
             }
         } elseif ($appCfg['frontend_router_type'] == 'path') {
             $paths = explode('_', str_replace(array('Frontend_'), '', $controllerName));
             $pathsCount = count($paths) - 1;
             if ($paths[$pathsCount] === 'Controller') {
                 $paths = array_slice($paths, 0, $pathsCount);
             }
             $url = array_merge($url, $paths);
         } elseif ($appCfg['frontend_router_type'] == 'config') {
             $urlCode = self::_moduleByClass($controllerName);
             if ($urlCode !== false) {
                 $url[] = $urlCode;
             }
         }
     }
     if (!empty($methods)) {
         Request::setDelimiter($templates['urldelimiter']);
         Request::setRoot($templates['wwwroot']);
         foreach ($methods as $method) {
             if (substr($method->name, -6) !== 'Action') {
                 continue;
             }
             $actionName = substr($method->name, 0, -6);
             $paths = $url;
             $paths[] = $actionName;
             $actions[] = array('name' => $actionName, 'code' => $method->name, 'url' => Request::url($paths, false), 'comment' => self::_clearDocSymbols($method->getDocComment()));
         }
         Request::setDelimiter($appCfg['urlDelimiter']);
         Request::setRoot($appCfg['wwwroot']);
     }
     return $actions;
 }
Ejemplo n.º 2
0
 /**
  * Delete module
  */
 public function deletemoduleAction()
 {
     $this->_checkCanEdit();
     $module = Request::post('id', 'string', false);
     $removeRelated = Request::post('delete_related', 'boolean', false);
     $manager = new Backend_Modules_Manager();
     $moduleName = $manager->getModuleName($module);
     if (!$module || !strlen($module) || !$manager->isValidModule($moduleName)) {
         Response::jsonError($this->_lang->WRONG_REQUEST);
     }
     $filesToDelete = array();
     if ($removeRelated) {
         $item = $manager->getModuleConfig($moduleName);
         $classFile = './system/app/' . str_replace('_', '/', $item['class']) . '.php';
         if (file_exists($classFile)) {
             $filesToDelete[] = $classFile;
         }
         if (!empty($item['designer'])) {
             if (file_exists($item['designer'])) {
                 $filesToDelete[] = $item['designer'];
             }
             $crudJs = './js/app/system/crud/' . strtolower($manager->getModuleName($item['class'])) . '.js';
             if (file_exists($crudJs)) {
                 $filesToDelete[] = $crudJs;
             }
             $actionJs = './js/app/actions/' . strtolower($manager->getModuleName($item['class'])) . '.js';
             if (file_exists($actionJs)) {
                 $filesToDelete[] = $actionJs;
             }
         }
     }
     // check before deleting
     if (!empty($filesToDelete)) {
         $err = array();
         foreach ($filesToDelete as $file) {
             if (!is_writable($file)) {
                 $err[] = $file;
             }
         }
         if (!empty($err)) {
             Response::jsonError($this->_lang->CANT_WRITE_FS . "\n<br>" . implode(",\n<br>", $err));
         }
     }
     $manager->removeModule($moduleName);
     if (!$manager->save()) {
         Response::jsonError($this->_lang->CANT_WRITE_FS . ' ' . $manager->getConfig()->getName());
     }
     // try to delete
     if (!empty($filesToDelete)) {
         $err = array();
         foreach ($filesToDelete as $file) {
             if (!unlink($file)) {
                 $err[] = $file;
             }
         }
         if (!empty($err)) {
             Response::jsonError($this->_lang->CANT_WRITE_FS . "\n<br>" . implode(",\n<br>", $err));
         }
     }
     Response::jsonSuccess();
 }