Exemplo 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);
            }
        }
    }
}
 /**
  * found current template file
  * @param $file
  */
 public function _hw_get_template_include($file)
 {
     if (is_admin()) {
         return $file;
     }
     $GLOBALS['hw_current_theme_template'] = basename($file);
     //save current theme template file
     //get templates dynamic
     $dynamic_settings = HW__Template_Condition::get_active_templates_settings();
     $setting_conditions = HW__Template_Condition::parse_template_conditions($dynamic_settings);
     $pages_condition_and = $setting_conditions['pages_condition_and'];
     $pages_condition_or = $setting_conditions['pages_condition_or'];
     //match occurence condition
     $match_occurence = hw_get_setting('match_occurence');
     //get cache result for first
     #$data = get_transient('hw_dynamic_template');
     #if(empty($data) ) $data = array();
     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);
                     //get active template
                     $template = get_post_meta($meet_condition['setting']['post_ID'], 'template', true);
                     if (trim($template) != "" && file_exists(get_stylesheet_directory() . '/' . $template)) {
                         //check new template for exists
                         $file = locate_template($template);
                         //change template file
                         if ($match_occurence == 'first_occurence') {
                             break;
                         }
                     }
                 }
             }
             if ($match_occurence == 'first_occurence') {
                 break;
             }
         }
     }
     //cache result to database
     /*if($detect_addition_sidebar == true) {
           set_transient('hw_dynamic_sidebar', $data);
       }*/
     return $file;
 }
Exemplo n.º 3
0
 /**
  * desploy modules with positions
  */
 private function desploy_modules_position()
 {
     if (is_admin()) {
         return;
     }
     $modules_positions = $this->get_field_value('modules_position');
     if (is_array($modules_positions)) {
         foreach ($modules_positions as $module => $item) {
             //if($item['condition'] == 0) continue;
             $match = 1;
             //check condition before module can display
             $dynamic_settings = HW_Condition::get_active_conditions_settings();
             $condition = $item['condition'];
             //condition id
             if ($condition) {
                 if (!isset($dynamic_settings[$condition])) {
                     continue;
                 }
                 $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']) {
                                 $match = 1;
                                 //break;  //first occurence
                             } else {
                                 $match = 0;
                             }
                         }
                     }
                 }
             }
             if ($match) {
                 //add action for module position
                 $module_inst = HW_Module_Settings_page::get_modules($module);
                 if (!empty($module_inst)) {
                     HW_Module_Positions::add_position_hook($item['position'], $module_inst->get_module_content_cb());
                 }
             }
         }
     }
 }
 /**
  * whether replace a new sidebar
  * @param $bind_data
  * @return bool
  */
 public static function check_sidebar_changing($bind_data, $relation = 'AND')
 {
     return HW__Template_Condition::check_template_changing($bind_data, $relation);
 }
 /**
  * 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;
 }