/**
  * setup form fields
  */
 public function setUp()
 {
     $current_module_tab = hw__get('module');
     //get current module setting tab $_GET['tab']==$_GET['module']
     if (HW_HOANGWEB::is_current_screen(self::PAGE_SLUG) && hw__get('tab') && $current_module_tab && (!HW_Module::is_active($current_module_tab) || isset(self::$modules[$current_module_tab]) && !self::$modules[$current_module_tab]->option('enable_tab_settings'))) {
         wp_die('Xin lỗi: Module này chưa kích hoạt hoặc không có form cài đặt.');
     }
     // Set the root menu (http://admin-page-framework.michaeluno.jp/en/v2/classes/AdminPageFramework_Menu.html)
     #$this->setRootMenuPage( 'Settings' );        // specifies to which parent menu to add.
     $this->setRootMenuPage('(H) Cấu hình modules', HW_HOANGWEB_URL . '/images/ie-gear-icon.png');
     // Add the sub menus and the pages/ addSubMenuItems
     $this->addSubMenuItem(array('title' => 'Cấu hình modules', 'page_slug' => self::PAGE_SLUG));
     /*$this->addSubMenuItem(array(
           'title' => 'sdf',
           'href' =>  self::get_module_setting_page('abc'),
           #'page_slug'    =>    self::PAGE_SLUG
       ));*/
     //define tabs
     $this->addInPageTabs(self::PAGE_SLUG, array('tab_slug' => 'modules-config', 'title' => __('Cấu hình chung')));
     //add more tabs
     foreach (self::$modules as $name => $inst) {
         $info = HW_Plugins_Manager::get_module($name);
         if (!empty($info) && $inst->option('enable_tab_settings')) {
             $this->addInPageTab(array('tab_slug' => $name, 'title' => $info['name']));
             // load + page slug + tab slug
             add_action('load_' . self::PAGE_SLUG . '_' . self::valid_tab_slug($name), array($inst, '_replyToAddFormElements'));
             //triggered before rendering the page.
             add_action('do_before_' . self::PAGE_SLUG . '_' . self::valid_tab_slug($name), array($inst, 'do_before_tab_hook'));
             // triggered in the middle of rendering the page.
             add_action('do_' . self::PAGE_SLUG . '_' . self::valid_tab_slug($name), array($inst, 'do_tab_hook'));
             //triggered after rendering the page
             add_action('do_after_' . self::PAGE_SLUG . '_' . self::valid_tab_slug($name), array($inst, 'do_after_tab_hook'));
             /**
              * filters
              */
             //receives the output of the middle part of the page including form input fields.
             add_filter('content_' . self::PAGE_SLUG . '_' . self::valid_tab_slug($name), array($inst, 'content_tab_filter'));
             /*
                            ==> find in : hw-hoangweb\lib\admin-page-framework\development
                             //receives the output of the top part of the page.
                             add_filter('head_'. self::PAGE_SLUG  . '_' . self::valid_tab_slug($name), array($inst, 'head_tab_filter'));
             
                             // receives the output of the bottom part of the page.
                             add_filter('foot_'. self::PAGE_SLUG  . '_' . self::valid_tab_slug($name), array($inst, 'foot_tab_filter'));
             
                             //receives the exporting array sent from the tab page.
                             add_filter('export_'. self::PAGE_SLUG  . '_' . self::valid_tab_slug($name), array($inst, 'export_tab_filter'));
                             //receives the importing array submitted from the tab page.
                             add_filter('import_'. self::PAGE_SLUG  . '_' . self::valid_tab_slug($name), array($inst, 'import_tab_filter'));
             */
             #add_filter(''. self::PAGE_SLUG  . '_' . self::valid_tab_slug($name), array($inst, 'tab_filter'));
             //receives the output of the CSS rules applied to the tab page of the slug.
             add_filter('style_' . self::PAGE_SLUG . '_' . self::valid_tab_slug($name), array($inst, 'print_styles'));
             //receives the output of the JavaScript script applied to the tab page of the slug.
             add_filter('script_' . self::PAGE_SLUG . '_' . self::valid_tab_slug($name), array($inst, 'print_scripts'));
             //receives the form submission values as array. The first parameter: submitted input array. The second parameter: the original array stored in the database.
             add_filter('validation_' . self::PAGE_SLUG . '_' . self::valid_tab_slug($name), array($inst, '_validation_tab_filter'));
         }
     }
     $this->setInPageTabTag('h2');
     // sets the tag used for in-page tabs
     //submit button
     /*$this->addSettingFields(
           array(
               'field_id' => 'submit_button',
               'type' => 'submit',
               'show_title_column' => false,
           )
       );*/
 }
예제 #2
0
 /**
  * init module
  */
 public static final function init()
 {
     $class = get_called_class();
     if ($class) {
         $inst = new $class();
         if (!$inst instanceof HW_Module) {
             return;
         }
         //get file name where a Class was Defined
         $reflector = new ReflectionClass($class);
         //path variables
         $inst->option('module_path', dirname($reflector->getFileName()));
         $module_slug = basename($inst->option('module_path'));
         $inst->option('module_name', $module_slug);
         $modules = HW_TGM_Module_Activation::get_register_modules();
         if (isset($modules[$module_slug])) {
             $info = array_filter(HW_Plugins_Manager::get_module_info($reflector->getFileName()));
             //migrate module information
             if (!empty($info)) {
                 $modules[$module_slug] = array_merge($modules[$module_slug], $info);
             }
             HW_Plugins_Manager::register_module($modules[$module_slug]);
             //update module data
             $inst->option('module_info', $modules[$module_slug]);
         }
         $inst->option('module_url', HW_HOANGWEB_PLUGINS_URL . '/' . $module_slug);
         HW_Module_Settings_page::add_module($module_slug, $inst);
         //setup actions belong to current module instance
         self::setup_actions($inst);
         //occur after all modules loaded
         add_action('hw_modules_loaded', array($inst, 'modules_loaded'));
         //after the module loaded
         if (method_exists($inst, 'module_loaded')) {
             $inst->module_loaded();
         }
         //load cli class for the module
         $command = $inst->get_module_cli_path();
         if (!empty($command) && defined('WP_CLI') && WP_CLI) {
             include_once $command;
             $cli_class = 'HW_CLI_' . HW_Validation::valid_objname($module_slug);
             //command line class
             WP_CLI::add_command($module_slug, strtoupper($cli_class));
             //WP_CLI::get_command(); #wrong
             //add module commands to manager
             HW_CLI_Command_Utilities::get_instance()->register_cli_cmds($module_slug, HW_Core::get_child_class_methods($cli_class, ReflectionMethod::IS_PUBLIC));
         }
         //load oher cli class for module
         $cli_files = $inst->get_commands();
         if (is_array($cli_files)) {
             foreach ($cli_files as $cli) {
                 //not found file to process command line,
                 if (!$cli) {
                     continue;
                 }
                 //!isset($cli['file']) purpose for module->register_cli that more cli class write in one file
                 if (isset($cli['file'])) {
                     include_once $cli['file'];
                 }
                 if (class_exists($cli['class'], false)) {
                     WP_CLI::add_command($cli['command'], $cli['class']);
                     //add module commands to manager
                     HW_CLI_Command_Utilities::get_instance()->register_cli_cmds($cli['command'], HW_Core::get_child_class_methods($cli['class'], ReflectionMethod::IS_PUBLIC));
                 }
             }
         }
     }
 }