Example #1
0
 /**
  * Triggered when the tab is loaded.
  * @param $oAdminPage
  */
 public function replyToAddFormElements($oAdminPage)
 {
     $modules_pos = HW_Modules_Manager::get_modules_displayable();
     //list displayable modules
     $avaiable_pages = HW__Template::get_pages_select();
     //pages
     //get all register positions
     $positions = HW_Module_Positions::get_positions();
     HW_UI_Component::empty_select_option($positions);
     //condition
     $conditions = array();
     $dynamic_settings = HW_Condition::get_active_conditions_settings();
     foreach ($dynamic_settings as $id => $item) {
         $conditions[$id] = $item['title'];
     }
     HW_UI_Component::empty_select_option($conditions);
     $this->addFieldLabel('Cấu hình vị trí của các modules');
     $this->addFields(array('field_id' => 'modules_position', 'type' => 'hw_table_fields', 'title' => '', 'show_title_column' => false, 'repeatable' => false, 'show_root_field' => true, 'data_base_field' => 'col1', 'attributes' => array('hw_table_fields' => array()), 'fields' => array('col1' => array('name' => 'module', 'type' => 'select', 'options' => $modules_pos, 'description' => ''), 'col2' => array('name' => 'condition', 'type' => 'select', 'options' => $conditions, 'description' => ''), 'col3' => array('name' => 'page', 'type' => 'select', 'options' => $avaiable_pages, 'description' => ''), 'col4' => array('name' => 'position', 'type' => 'select', 'options' => $positions)), 'table_header' => array('col1' => 'Module', 'col2' => 'Điều kiện', 'col3' => 'Trang hiển thị', 'col4' => 'Vị trí')));
 }
        {
            if (is_callable($callback)) {
                add_action(self::get_hook_name($name), $callback);
            }
        }
        /**
         * return hook for position name
         * @param $name
         * @return string
         */
        public static function get_hook_name($name)
        {
            return self::$hook_prefix . $name;
        }
        /**
         * return all positions
         * @return array
         */
        public static function get_positions()
        {
            $result = array();
            foreach (self::$positions as $pos) {
                $result[$pos['name']] = $pos['text'];
            }
            return $result;
        }
    }
    if (!is_admin()) {
        HW_Module_Positions::get_instance();
    }
}
/**
 * display or register modules content with position
 * @param $name
 * @param $callback
 */
function __position($name, $callback = null)
{
    if ($callback) {
        HW_Module_Positions::add_position_hook($name, $callback);
    } else {
        HW_Module_Positions::implement_position($name);
    }
}
Example #4
0
 /**
  * fields setting for positions tab
  */
 private function setting_form_positions_tab()
 {
     global $wp_registered_sidebars;
     $position_tab = $this->add_tab(array('id' => 'sidebars_pos', 'title' => 'Vị trí hiển thị', 'description' => 'Quản lý Vị trí hiển thị'));
     //get all register positions
     $positions = HW_Module_Positions::get_positions();
     HW_UI_Component::empty_select_option($positions);
     $position_tab->addFieldLabel('Cấu hình vị trí của sidebars');
     //list all avaiable sidebars
     $sidebars_list = array();
     foreach ($wp_registered_sidebars as $sidebar) {
         $sidebar = self::_valid_sidebar($sidebar);
         //valid
         if (!isset($sidebar['id'])) {
             continue;
         }
         $sidebars_list[$sidebar['id']] = !empty($sidebar['name']) ? $sidebar['name'] : $sidebar['description'];
     }
     $position_tab->addFields(array('field_id' => 'sidebars_position', 'type' => 'hw_table_fields', 'title' => '', 'show_title_column' => false, 'repeatable' => false, 'show_root_field' => true, 'data_base_field' => 'col1', 'attributes' => array('hw_table_fields' => array()), 'fields' => array('col1' => array('name' => 'sidebar', 'type' => 'select', 'options' => $sidebars_list, 'description' => ''), 'col2' => array('name' => 'position', 'type' => 'select', 'options' => $positions)), 'table_header' => array('col1' => 'Sidebar', 'col2' => 'Vị trí')));
 }