Ejemplo n.º 1
0
/**
 *
 * enqueue all active skins resource
 * @hook wp_enqueue_scripts
 */
function _hwskin_wp_enqueue_scripts()
{
    //validation
    if (!class_exists('HW_Condition')) {
        return;
    }
    $skins = hwskin_get_actived_skins();
    #$dynamic_settings = HW__Template_Condition::get_active_templates_settings();
    $dynamic_settings = HW_Condition::get_active_conditions_settings();
    foreach ($skins as $id => $skin) {
        if (!empty($skin->instance)) {
            if (isset($skin->hwskin_condition) && isset($dynamic_settings[$skin->hwskin_condition])) {
                $setting = array($skin->hwskin_condition => $dynamic_settings[$skin->hwskin_condition]);
                $setting_conditions = HW__Template_Condition::parse_template_conditions($setting);
                foreach ($setting_conditions as $pages_condition) {
                    //and, or condition
                    if (isset($pages_condition) && is_array($pages_condition)) {
                        //get template alternate with AND relation
                        foreach ($pages_condition as $temp => $meet_condition) {
                            if ($meet_condition['result']) {
                                #$_name = HW_Validation::valid_objname($file);
                                HW_SKIN::enqueue_skins($skin);
                                break;
                                //first occurence
                            }
                        }
                    }
                }
            } else {
                HW_SKIN::enqueue_skins($skin);
            }
        }
    }
}
Ejemplo n.º 2
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í')));
 }
Ejemplo n.º 3
0
 /**
  * @param $name
  * @param string $value
  * @param array $atts
  */
 public function get_skin_template_condition_selector($wfname, $value = '', $atts = array())
 {
     if (!class_exists('HW_Condition')) {
         return 'Error: class HW_Condition not exists, please active module `Condition`.';
     }
     $widget = $this->widget_ref;
     //get current widget
     if (is_object($widget) && $widget instanceof WP_Widget) {
         //if whether object reference of widget
         if ($wfname) {
             $name = $widget->get_field_name($wfname);
         } elseif (isset($atts['name'])) {
             $name = $widget->get_field_name($atts['name']);
         }
         //get key 'name' from $atts
         if ($wfname) {
             $id = $widget->get_field_id($wfname);
         } elseif (isset($atts['id'])) {
             $id = $widget->get_field_id($atts['id']);
         }
         //get key 'id' from $atts
     } else {
         if ($wfname) {
             $name = $wfname;
         } elseif (isset($atts['name'])) {
             $name = $atts['name'];
         }
         if ($wfname) {
             $id = $this->uniqueID($wfname);
         } elseif (isset($atts['id'])) {
             $id = $this->uniqueID($atts['id']);
         }
     }
     //set attributes requirement
     if (!is_array($atts)) {
         $atts = array();
     }
     if (!isset($atts['name'])) {
         $atts['name'] = $name;
     }
     //you can define attr 'name' with $atts param
     if (!isset($atts['id'])) {
         $atts['id'] = self::valid_objname($id);
     }
     //override id attribute if not exists in $atts
     $w_instance = self::get_widget_instance($widget);
     if (!$value && isset($w_instance[$wfname])) {
         $value = $w_instance[$wfname];
     }
     //get current skin hash string
     //select options
     $dynamic_settings = HW_Condition::get_active_conditions_settings();
     $out = '<p>';
     $out .= '<label for="' . $atts['id'] . '">' . __('Lựa chọn điều kiện sử dụng giao diện', 'hw-skin') . '</label><br/>';
     $out .= '<select ' . self::array2attrs($atts) . '>';
     $out .= '<option value="">--- Chọn ---</option>';
     foreach ($dynamic_settings as $id => $item) {
         $out .= sprintf('<option %s value="%s">%s</option>', selected($value, $id, false), $id, $item['title']);
     }
     $out .= '</select>';
     $out .= '</p>';
     return $out;
 }
 /**
  * check widget is show/hide
  * @param $feature
  * @param $instance
  */
 private static function show_widget($feature, $instance)
 {
     static $dynamic_settings;
     if (!$dynamic_settings) {
         $dynamic_settings = HW_Condition::get_active_conditions_settings();
     }
     $hide_option = $feature->get_field_value('hide_option', false, $instance);
     $condition = $feature->get_field_value('condition', false, $instance);
     if (!$condition || !isset($dynamic_settings[$condition])) {
         return !$hide_option;
     }
     $result = 0;
     if ($hide_option) {
         $setting = array($condition => $dynamic_settings[$condition]);
         $setting_conditions = HW__Template_Condition::parse_template_conditions($setting);
         #_print($setting_conditions);
         foreach ($setting_conditions as $pages_condition) {
             //and, or condition
             if (isset($pages_condition) && is_array($pages_condition)) {
                 //get template alternate with AND relation
                 foreach ($pages_condition as $temp => $meet_condition) {
                     if ($meet_condition['result']) {
                         return 0;
                         //break;  //first occurence
                     } else {
                         $result = 1;
                     }
                 }
             }
         }
     }
     return $result;
 }