/**
  * valid field id from their name or any give string
  * @param $str
  */
 private static function generate_id($str)
 {
     return class_exists('HW_Validation') ? HW_Validation::valid_objname($str) : $str;
 }
Ejemplo n.º 2
0
 /**
  * localize script
  * @extend from HW_Module class
  * @param $handle
  * @param $object_name
  * @param array $data
  */
 public function localize_script($handle, $object_name, $data = array())
 {
     //validation
     if (!is_array($data)) {
         $data = array();
     }
     #$module = $this->get_module_name();
     //$handle = 'hw-module-'.$module.'-'. md5(self::get_file_name($file));
     wp_localize_script($handle, HW_Validation::valid_objname($object_name), $data);
 }
Ejemplo n.º 3
0
 /**
  * generate object name
  * @param $name: name
  */
 public static function generate_callback_name($name)
 {
     if (class_exists('HW_Validation')) {
         return HW_Validation::valid_objname($name);
     } else {
         $delimiter = '_';
         return preg_replace('/[\\s,.\\[\\]\\/\\#\\*@$%^\\!~\\-\\+\\=]+/', $delimiter, $name);
     }
 }
 /**
  * localize script
  * @param $handle
  * @param $object_name
  * @param array $data
  */
 public function localize_script($handle, $object_name, $data = array())
 {
     //validation
     if (!is_array($data)) {
         $data = array();
     }
     wp_localize_script($handle, HW_Validation::valid_objname($object_name), $data);
 }
Ejemplo n.º 5
0
 /**
  * validation form fields
  * @param $values
  * @return mixed
  */
 public function validation_tab_filter($_values)
 {
     HW_HOANGWEB::load_class('HW_String');
     /*foreach(array('xxx') as $option) {
           if(isset($values[$option])) $values[$option] = $values[$option]? true:false;
       }*/
     $values = $this->pure_fields_result($_values);
     $values = $values['sidebars'];
     if (!empty($values['sidebar_id'])) {
         $id = $values['sidebar_id'];
     } else {
         $id = strtolower(HW_Validation::valid_objname(HW_String::vn_str_filter($values['sidebar_name'])));
     }
     $sidebar = array('id' => $id, 'name' => $values['sidebar_name'], 'description' => isset($values['sidebar_desc']) ? $values['sidebar_desc'] : '', 'before_widget' => $values['before_widget'], 'before_title' => $values['before_title'], 'after_title' => $values['after_title'], 'after_widget' => $values['after_widget']);
     if (!empty($sidebar['id'])) {
         hwawc_register_sidebar($sidebar);
     }
     return $_values;
     //un-save
 }
Ejemplo n.º 6
0
 /**
  * parse theme config using wrx format
  * @param $file
  */
 public function parse($file)
 {
     $site = $menus = $assets = $libs = $modules = $plugins = $positions = $configuration = array();
     $xml = HW_WXR_Parser_SimpleXML::read_simplexml_object($file);
     $namespaces = $xml->namespaces;
     $xml = $xml->xml;
     $xml_parser = new HW_WXR_Parser();
     //::get_instance();
     $simplexml_parser = $xml_parser->simplexml_parser;
     //site meta
     if (isset($xml->site)) {
         $hw = $xml->site->children($namespaces['hw']);
         if (isset($hw->name)) {
             $site['name'] = (string) $hw->name;
         }
         if (isset($hw->description)) {
             $site['description'] = (string) $hw->description;
         }
         if (isset($hw->logo)) {
             $site['logo'] = (string) $hw->logo;
         }
         if (isset($hw->banner)) {
             $site['banner'] = (string) $hw->banner;
         }
         if (isset($hw->phone)) {
             $site['phone'] = (string) $hw->phone;
         }
         if (isset($hw->email)) {
             $site['admin_email'] = (string) $hw->email;
         }
         if (isset($hw->address)) {
             $site['address'] = (string) $hw->address;
         }
         if (isset($hw->testimonials)) {
             $site['testimonials'] = (string) $hw->testimonials;
         }
         if (!empty($hw->footer_text)) {
             $site['footer'] = (string) $hw->footer_text;
         }
     }
     //configuration
     if (isset($xml->configuration)) {
         $hw = $xml->configuration->children($namespaces['hw']);
         $configuration['sample_data'] = (string) $hw->sample_data;
         $media = $hw->media->children('hw');
         $configuration['media'] = array();
         foreach ($media as $image) {
             foreach ($image as $size) {
                 $atts = $size->attributes();
                 $configuration['media'][$size->getName()] = array('width' => (string) $atts->width, 'height' => (string) $atts->height, 'crop' => (string) $atts->crop);
             }
         }
         /*if(!empty($media->thumbnail)) $configuration['media']['thumbnail'] = (string) $media->thumbnail;
           if(!empty($media->medium)) $configuration['media']['medium'] = (string) $media->medium;
           if(!empty($media->large)) $configuration['media']['large'] = (string) $media->large;*/
         $configuration['locale'] = (string) $hw->locale;
     }
     //fetch menus
     foreach ($xml->xpath('/theme/menus/hw:menu') as $menu) {
         $atts = $menu->attribute();
         $menus[(string) $atts['slug']] = (string) $menu;
     }
     //fetch sidebars
     $sidebars = array();
     #$simplexml_parser->grab_sidebars($xml->xpath('/theme')[0], $namespaces);
     foreach ($xml->xpath('/theme/sidebars/hw:sidebar') as $sidebar_widgets) {
         $atts = $sidebar_widgets->attributes();
         $skin = (string) $atts['skin'];
         //sidebar skin
         $sidebar_name = (string) $atts['name'];
         if (!isset($sidebars[(string) $atts['name']])) {
             $sidebars[$sidebar_name] = array('skin' => $skin, 'widgets' => array(), 'params' => array());
         }
         //get widgets in sidebar
         $hw = $sidebar_widgets->children($namespaces['hw']);
         foreach ($hw->widget as $widget) {
             $name = (string) $widget->attributes()->name;
             $sidebars[$sidebar_name]['widgets'][] = $name;
         }
         //sidebar params
         $sidebars[$sidebar_name]['params'] = array('name' => $sidebar_name);
         if (!empty($hw->params)) {
             $sidebars[$sidebar_name]['params'] = array_merge($sidebars[$sidebar_name]['params'], $simplexml_parser->recursive_option_data($hw->params[0]->children())->option);
         }
     }
     //fetch assets
     foreach ($xml->xpath('/theme/assets') as $items) {
         $atts = $items->attributes();
         $page = isset($atts['page']) ? (string) $atts['page'] : '__all__';
         //group by page
         if (!isset($assets[$page])) {
             $assets[$page] = array();
         }
         foreach ($items as $item) {
             $atts = $item->attributes();
             $file = array();
             $file['type'] = !empty($atts['type']) ? (string) $atts['type'] : '';
             //dependencies
             if (!empty($atts['depends'])) {
                 $file['depends'] = explode(',', (string) $atts['depends']);
             } else {
                 $file['depends'] = false;
             }
             //handle
             if (!empty($atts['handle'])) {
                 $file['handle'] = (string) $atts['handle'];
             }
             if (!empty($atts['ver'])) {
                 $file['ver'] = (string) $atts['ver'];
             }
             //version
             $file['name'] = (string) $item;
             $assets[$page][] = $file;
         }
     }
     //fetch libs
     foreach ($xml->xpath('/theme/libs/lib') as $item) {
         $atts = $item->attributes();
         $lib = isset($atts['name']) ? (string) $atts['name'] : (string) $item;
         $libs[] = $lib;
     }
     //fetch modules
     $modules_list = $xml->xpath('/theme/modules');
     if ($modules_list) {
         $only_list = (string) $modules_list[0]->attributes()->only_list;
     } else {
         $only_list = 0;
     }
     if (!$only_list) {
         $installed_modules = HW_TGM_Module_Activation::get_register_modules(array('active' => 1, 'core' => 1), 'or');
         #HW_Logger::log_file($installed_modules);   //get installed modules, refer to core modules
         foreach ($installed_modules as $slug => $module) {
             $modules[$slug] = array('name' => $slug, 'status' => 1, 'core' => !empty($module['force_activation']), 'active' => 1);
         }
     }
     foreach ($xml->xpath('/theme/modules/module') as $item) {
         $atts = $item->attributes();
         $module['name'] = isset($atts['name']) ? (string) $atts['name'] : (string) $item;
         $module['status'] = isset($atts['status']) ? (string) $atts['status'] : 1;
         //active module as default
         $modules[$module['name']] = $module;
     }
     //fetch wp plugins
     foreach ($xml->xpath('/theme/plugins/plugin') as $item) {
         $atts = $item->attributes();
         $plugin['name'] = isset($atts['name']) ? (string) $atts['name'] : (string) $item;
         $plugin['status'] = isset($atts['status']) ? (string) $atts['status'] : 1;
         //active plugin as default
         $plugins[$plugin['name']] = $plugin;
     }
     //positions
     foreach ($xml->xpath('/theme/positions/position') as $item) {
         $atts = $item->attributes();
         //valid hook name
         $name = isset($atts['name']) ? (string) $atts['name'] : (string) $item;
         $name = strtolower(HW_Validation::valid_objname($name));
         //display text
         $text = (string) $item;
         if (empty($text) && $name) {
             $text = $name;
         }
         $positions[] = array('name' => $name, 'text' => $text);
     }
     unset($xml);
     return array('assets' => $assets, 'libs' => $libs, 'modules' => $modules, 'plugins' => $plugins, 'positions' => $positions, 'sidebars' => $sidebars, 'menus' => $menus, 'site' => $site, 'configuration' => $configuration);
 }
/**
 * 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
}
 /**
  * generate unique name to wrap js function in current widget
  * @return string
  */
 private function generate_object_name()
 {
     if (!$this->valid_widget()) {
         return;
     }
     //return 'hw_toggle_'.preg_replace('/[@#\$%\^&\*\(\)\|\{\}+\=\-\~\!]+/','_',$this->generate_name('Expand'));
     return 'hw_toggle_' . HW_Validation::valid_objname($this->generate_name('Expand'));
 }
Ejemplo n.º 9
0
 /**
  * generate field id
  * @param $name
  * @return string
  */
 private function get_field_id($name)
 {
     $widget = $this->widget_ref;
     //get current widget
     //valid name
     if (is_object($widget) && $widget instanceof WP_Widget) {
         //if whether object reference of widget instance
         $fname = $widget->get_field_id($name);
         //get field name if context is widget
     } else {
         $fname = $name;
     }
     //valid object name
     $fname = class_exists('HW_Validation') ? HW_Validation::valid_objname($fname) : $this->valid_objname($fname);
     return $fname;
 }