array()), $css = array('_deps'=>array()), $html = ''; var $inline = ''; function __construct() { $this->_webnukes = &$GLOBALS['_webnukes']; /** Clone the fw_base_class object */ $this->_webnukes->load('validation_class'); /** Load validation class */ add_action( 'admin_print_scripts', array($this, 'admin_script'), 11 ); add_action( 'admin_print_styles', array($this, 'admin_style'), 11 ); } function admin_script() { foreach($this->js as $k=>$v) { if($k == '_deps') wp_enqueue_script($v); else { wp_register_script($k, $v, '', '', true); wp_enqueue_script($k); } } } function admin_style() { foreach($this->css as $k=>$v) { if($k == '_deps') wp_enqueue_style($v); else { wp_register_style($k, $v); wp_enqueue_style($k); } } } /** * Load javascript * * Load the javascript files * * @access public * @param string|array of the javascript file(s) names or urls * @param string the url basepath where the file is located * @param bool used for inline javascripts * @return void */ function js($files = array(), $basepath = '', $deps = array()) { if ( ! is_array($files)) $files = array($files); /** Create the files array */ $this->js['_deps'] = array_merge((array)$this->js['_deps'], $deps); foreach($files as $file) { if(preg_match('@http://|/@', $file)) /** Check if the path is already given */ { $hash = md5($file); /** Unique hash to avoide multiple loadings */ $this->js[$hash] = $file; //wp_register_script($hash, $file); /** Built-in wordpress function to load file */ //wp_enqueue_script($hash); }else { $ext = end(explode('.', $file)); $filename = ($ext != 'js') ? $file.'.js' : $file; $src = ($basepath) ? $basepath.$filename : THEME_URL.'/includes/views/js/'.$filename; $hash = $src; $this->js[$hash] = $src; //wp_register_script($hash, $src); //wp_enqueue_script($hash); //$this->js[$file] = ($basepath) ? $basepath.$filename : THEME_URL.'/includes/js/'.$filename; } } } /** * Load stylesheets * * Load stylesheets files * * @access public * @param string|array of the stylesheet file(s) names or urls * @param string the url basepath where the file is located * @return void */ function css($files = array(), $basepath = '', $deps = array()) { if ( ! is_array($files)) $files = array($files); /** Create the files array */ $this->css['_deps'] = array_merge((array)$this->css['_deps'], $deps); foreach($files as $file) { if(preg_match('@http://|/@', $file)) /** Check if the path is already given */ { $hash = md5($file); /** Unique hash to avoide multiple loadings */ $this->css[$hash] = $file; //wp_register_style($hash, $file); /** Built-in wordpress function to load file */ //wp_enqueue_style($hash); }else { $ext = end(explode('.', $file)); $filename = ($ext != 'css') ? $file.'.css' : $file; $src = ($basepath) ? $basepath.$filename : THEME_URL.'/includes/views/css/'.$filename; $hash = $src; $this->css[$hash] = $src; //wp_register_style($hash, $src); //wp_enqueue_style($hash); } } } /** * Load Inline HTML * * Load Inline Javascript and CSS code * * @access private * @param string code to load * @param string head or footer (default is head) * @param int priority * @return void */ function inline($code, $section = 'head', $priority = 10) { $this->inline = ($this->inline) ? $this->inline."\n".$code : $code; if($section == 'footer') add_action('admin_footer', array($this, 'admin_footer'), $priority); else add_action('admin_head', array($this, 'admin_head'), $priority); } function admin_head() { echo $this->inline; $this->inline = ''; } function admin_footer() { echo $this->inline; $this->inline = ''; } /** * Load layout * * Load the layout file * * @access public * @param string file name to load * @param array data vairables * @param bool to return the generated html * @return string if the return param is true */ function layout($file = '', $data = array(), $return = false) { if( ! $file) return; @extract($data); ob_start(); $file = (strstr($file, '.php')) ? $file : $file.'.php'; $path = (file_exists($file)) ? $file : FW_ADMIN_SKIN.$file; include($path); $html = ob_get_contents(); ob_end_clean(); if($return) return $html; $this->html[$file] = $html; } /** * Build HTML * * Build the final HTML * * @access public * @param bool to release the load of memory * @return string of generated HTML */ function build($autoclear = true) { $html = implode('', (array)$this->html); if($autoclear) $this->html = ''; return $html; } /** * HTML generator * * Generate the option HTML * * @access public * @param string|int key * @param string value * @param array of settings * @param string (html|element|array) * @return string */ function generator($field, $settings, $user_settings, $return = 'html') { if( ! is_array($settings)) return; $default_value = (isset($_POST[$field])) ? $_POST[$field] : $this->_webnukes->kvalue($user_settings, $field); $default = array('type'=>'input','settings'=>'','attrs'=>array(),'label'=>'','std'=>'','info'=>'','value'=>''); $settings = array_merge($default, $settings); $html = array(); $html['label'] = ''; $html['info'] = (!empty($settings['info'])) ? ''.$settings['info'].'' : ''; switch($settings['type']) { case "input": $html['element'] = form_input(array_merge(array('name'=>$field,'value'=>$default_value,'id'=>$field), (array) $settings['attrs'])); break; case "password": $html['element'] = ''; break; case "dropdown": $settings['attrs'] = array_to_string(array_merge((array) $settings['attrs'], array('id'=>$field))); $html['element'] = ''.form_dropdown($field, $settings['value'], $this->_webnukes->validation->set_value($field, $default_value), $settings['attrs']).''; break; case "multiselect": $size = (count($settings['value']) < 10) ? count($settings['value']) * 20 : 220; $settings['attrs'] = array_to_string(array_merge((array) $settings['attrs'], array('id'=>$field, 'style'=>"height:".$size."px;"))); $html['element'] = form_multiselect($field.'[]', $settings['value'], $this->_webnukes->validation->set_value($field, $default_value), $settings['attrs'] ); break; case "textarea": $settingsvalue = empty($user_settings[$field]) ? $settings['value'] : $user_settings[$field]; $html['element'] = form_textarea(array_merge(array('name'=>$field,'value'=>$this->_webnukes->validation->set_value($field, $settingsvalue),'id'=>$field), (array) $settings['attrs'])); break; case "image": $counter = (is_numeric($field)) ? $field : 1; $html['element'] = ''.form_input(array_merge(array('name'=>$field,'value'=>$this->_webnukes->validation->set_value($field, $default_value),'id'=>$field), (array) $settings['attrs'])); $html['element'] .= 'Upload'; /** Sample Code **/ if(isset($settings['settings']['preview'])) { $image = $this->_webnukes->validation->set_value($field, $default_value); $preview = '
'; if($return == 'html') $html['info'] = $html['info'].$preview; else $html['element'] .= $preview; } break; case "switch" : $html['element'] = ''; //foreach($settings['value'] as $key=>$val) //{ //$selected = ($this->_webnukes->kvalue($user_settings, $field) == $key) ? $selected = 'btn-active' : ''; //$html['element'] .= ''.$val.''; //} $checked = ($this->_webnukes->kvalue($user_settings, $field) == 'on') ? 'checked="checked"' : ''; $html['element'] = ''; //$html['element'] = '