/**
  * regiter acf fields group
  */
 private function implement_acf_fields()
 {
     $list = hw_get_setting(array('my_taxonomy_settings', 'allow_taxonomies_image'));
     if (!empty($list)) {
         HW_ACF_API::hw_acf_register_field_group_taxonomy_image($list);
         foreach ($list as $tax) {
             //hiển thị columns taxonomy
             add_filter("manage_edit-{$tax}_columns", array($this, '_custom_taxonomy_admin_columns'));
             add_filter("manage_{$tax}_custom_column", array($this, '_manage_taxonomy_columns_content'), 10, 3);
             //column content
         }
     }
 }
 /**
  * setup widget feature
  * @call HW_AWC call from method HW_AWC/_hw_awc_in_widget_form
  * @param WP_Widget $widget
  */
 public static function setup_features_widgets(WP_Widget $widget)
 {
     static $active_features_widgets;
     if (empty($active_features_widgets)) {
         $active_features_widgets = hw_get_setting(array(self::SETTINGS_GROUP, 'active_features_widgets'), array());
     }
     foreach ($active_features_widgets as $item) {
         if (isset($item['active']) && strtolower($item['active']) == 'on' && $item['widget'] == $widget->id_base) {
             HW_AWC_WidgetFeatures::register_widget_feature($widget, $item['feature']);
             //_print($widget->id_base);
             //break;    //please do not break because one widget has more than one feature
         }
     }
 }
 /**
  * allow upload mimes type
  * @hook upload_mimes
  * @param array $existing_mimes
  * @return array
  */
 public function _custom_upload_mimes($existing_mimes = array())
 {
     $mimes = hw_list_mines_type();
     $allow_uploadfile_type = hw_get_setting('allow_uploadfile_type');
     // add your extension to the array, add as many as you like
     foreach ($mimes as $mime_type => $ext) {
         if (isset($allow_uploadfile_type[$mime_type]) && $allow_uploadfile_type[$mime_type]) {
             $existing_mimes[$mime_type] = $ext;
         }
     }
     // removing existing file types
     //unset( $existing_mimes['exe'] );
     // and return the new full result
     return $existing_mimes;
 }
 /**
  * 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;
 }
Example #5
0
 /**
  * get current context loop template
  */
 public static function get_current_context_loop_template()
 {
     //$context = self::get_current_template_file();   //get current template
     //get loop templates options
     $loop_temps = hw_get_setting(array('my_templates', 'main_loop_content_style'));
     if (is_array($loop_temps)) {
         foreach ($loop_temps as $item) {
             $is_temp = self::check_template_page($item['layout'], false);
             if ($is_temp['result']) {
                 if (isset($is_temp['object'])) {
                     $item['template_object'] = $is_temp['object'];
                 }
                 return $item;
                 break;
             }
         }
     }
 }
/**
 * custom dynamic sidebar for dynamic_sidebar() function
 * @param $name: sidebar id
 */
function hw_dynamic_sidebar($name)
{
    $name = apply_filters('hw_dynamic_sidebar', $name);
    $dynamic_settings = HW_AWC_Frontend::get_active_sidebars_settings();
    //_print($dynamic_settings);
    $pages_condition_and = array();
    $pages_condition_or = array();
    //match occurence condition
    $match_occurence = hw_get_setting('match_occurence', 'first_occurence');
    //get cache result for first
    $detect_addition_sidebar = false;
    $data = get_transient('hw_dynamic_sidebar');
    if (empty($data)) {
        $data = array();
    }
    #see: other way in includes/layout-templates/theme.php/HW__Template_Condition
    foreach ($dynamic_settings as $id => $setting) {
        $result = $result_or = array();
        //$and = APF_hw_condition_rules::parseQuery($setting['query_data_and']); //AND relation
        //$or = APF_hw_condition_rules::parseQuery($setting['query_data_or']);  //OR relation
        if (!empty($setting['query_data_and'])) {
            $_result = HW_AWC_Frontend::check_sidebar_changing($setting['query_data_and'], 'AND');
            list($k, $v) = each($_result);
            $result[] = array('template' => $k, 'result' => $v, 'setting' => $setting);
            //$result[$k]
            $pages_condition_and = array_merge($pages_condition_and, $result);
            //override page result for AND relation
        }
        if (!empty($setting['query_data_or'])) {
            $_result_or = HW_AWC_Frontend::check_sidebar_changing($setting['query_data_or'], 'OR');
            list($k, $v) = each($_result_or);
            $result_or[] = array('template' => $k, 'result' => $v, 'setting' => $setting);
            $pages_condition_or = array_merge($pages_condition_or, $result_or);
            //override page result for OR relation
        }
    }
    foreach (array($pages_condition_and, $pages_condition_or) as $pages_condition) {
        if (isset($pages_condition) && is_array($pages_condition)) {
            //get sidebar alternate with AND relation
            $key = base64_encode(serialize($pages_condition));
            if (!empty($data[$key])) {
                $name = $data[$key];
            } else {
                foreach ($pages_condition as $temp => $meet_condition) {
                    if ($meet_condition['result']) {
                        $_name = HW_Validation::valid_objname($name);
                        //get active sidebars
                        $sidebar = get_post_meta($meet_condition['setting']['post_ID'], $_name, true);
                        if (is_active_sidebar($sidebar)) {
                            //make sure sidebar not empty
                            if ($match_occurence == 'first_occurence' && !$detect_addition_sidebar || $match_occurence == 'last_occurence') {
                                $name = $sidebar;
                                //rename sidebar
                                $data[$key] = $name;
                                //save redirect sidebar name
                                $detect_addition_sidebar = true;
                                //detect append
                            }
                        }
                    }
                }
            }
        }
    }
    /*
    if(isset($pages_condition_and) && is_array($pages_condition_and)) {     //get sidebar alternate with AND relation
        $and_key = base64_encode(serialize($pages_condition_and));
        if(!empty($data[$and_key])) $name = $data[$and_key];
        else{
            foreach ($pages_condition_and as $temp => $meet_condition) {
                if($meet_condition['result']) {
                    $_name = HW_Validation::valid_objname($name);
                    //get active sidebars
                    $sidebar = get_post_meta($meet_condition['setting']['post_ID'], $_name, true);
                    if(is_active_sidebar($sidebar)) {   //make sure sidebar not empty
                        $name = $sidebar;   //rename sidebar
                        $data[$and_key] = $name;     //save redirect sidebar name
                        $detect_addition_sidebar = true;    //detect append
                    }
                }
            }
        }
    
    }
    if(isset($pages_condition_or) && is_array($pages_condition_or)) {   //get sidebar alternate with OR relation
        $or_key = base64_encode(serialize($pages_condition_or));
        if(!empty($data[$or_key])) {
            $name = $data[$or_key];
        }
        else {
            foreach ($pages_condition_or as $temp => $meet_condition) {
                if($meet_condition['result']) {
                    $_name = HW_Validation::valid_objname($name);
                    //get active sidebars
                    $sidebar = get_post_meta($meet_condition['setting']['post_ID'], $_name, true);
                    if(is_active_sidebar($sidebar)){    //make sure sidebar not empty
                        $name = $sidebar;   //rename sidebar
                        $data[$or_key] = $name;     //save redirect sidebar name
                        $detect_addition_sidebar = true;        //detect append
                    }
                }
            }
        }
    
    }
    */
    //cache result to database
    if ($detect_addition_sidebar == true) {
        set_transient('hw_dynamic_sidebar', $data);
    }
    dynamic_sidebar($name);
    //load sidebar
}
 /**
  * @hook init
  * init action callback (testing)
  */
 public function _init_something()
 {
     //show/hide advanced feature exists in admin menu
     $show_advanced = hw_get_setting('enable_developer_feature');
     if (!$show_advanced) {
         //acf menu, according to http://www.advancedcustomfields.com/resources/how-to-hide-acf-menu-from-clients/
         add_filter('acf/settings/show_admin', '__return_false');
     }
     //register help for the plugin
     if (class_exists('HW_HELP')) {
         HW_HELP::set_helps_path('hoangweb', HW_HOANGWEB_PATH . 'helps');
         HW_HELP::set_helps_url('hoangweb', HW_HOANGWEB_URL . '/helps');
         HW_HELP::register_help('hoangweb');
         HW_HELP::load_module_help('hoangweb');
     }
 }
 /**
  * get template for current context
  */
 public static function get_current_context_template()
 {
     global $post;
     $taxonomies_template = hw_get_setting(array('my_taxonomy_settings', 'taxonomies_template'), array());
     //taxonomy template
     foreach ($taxonomies_template as $item) {
         if (!isset($item['enable']) || strtolower($item['enable']) == 'off' || !$item['enable']) {
             continue;
         }
         //taxonomy template
         if ((is_tax() || is_category()) && (!empty($item['term']) && (is_tax($item['taxonomy'], $item['term']) || is_category($item['term'])) || (empty($item['term']) || $item['term'] == -1))) {
             $item['found'] = 'taxonomy';
             $item['template'] = base64_decode($item['template']);
             //get real path
             /*if(file_exists($item['template'])) {
                   $template = $item['template'];
               }
               else*/
             if (file_exists(locate_template($item['template']))) {
                 $item['template'] = locate_template($item['template']);
             }
             //return $item;
             break;
         }
         //single template
         if (is_single() && (!empty($item['term']) && in_category($item['term'], $post) || $item['term'] == -1)) {
             $item['found'] = 'single';
             $item['single_template'] = base64_decode($item['single_template']);
             //decode path
             /*if(file_exists($item['single_template'])) {
                   return $item['single_template'];
               }
               else*/
             if (file_exists(locate_template($item['single_template']))) {
                 $item['single_template'] = locate_template($item['single_template']);
             }
             //return $item;
             break;
         }
     }
     if (isset($item['found'])) {
         if (isset($item['loop_template']) && isset($item['loop_template']['hwskin_config'])) {
             //parse loop template
             $item['skin'] = HW_SKIN::resume_skin($item['loop_template']['hwskin_config']);
         }
         return $item;
     }
 }