menu (array|string) - (string) -> this the name of the parent Top-Level-Menu or a TopPage object to create * this page as a sub menu to. * (array) -> top - Slug for the New Top level Menu page to create. * > page_title (string) - The name of this page (good for Top level and sub menu pages) * > capability (string) (optional) - The capability needed to view the page (good for Top level and sub menu pages) * > menu_title (string) - The name of the Top-Level-Menu (Top level Only) * > menu_slug (string) - A unique string identifying your new menu (Top level Only) * > icon_url (string) (optional) - URL to the icon, decorating the Top-Level-Menu (Top level Only) * > position (string) (optional) - The position of the Menu in the ACP (Top level Only) * > option_group (string) (required) - the name of the option to create in the database * * */ public function __construct($args) { if(is_array($args)) { if (isset($args['option_group'])){ $this->option_group = $args['option_group']; } $this->args = $args; } else { $array['page_title'] = $args; $this->args = $array; } // If we are not in admin area exit. if ( ! is_admin() ) return; //set defualts $this->_div_or_row = true; $this->saved = false; //store args $this->args = $args; //sub $menu if(!is_array($args['menu'])) { if(is_object($args['menu'])) { $this->Top_Slug = $args['menu']->Top_Slug; }else{ switch($args['menu']) { case 'posts': $this->Top_Slug = 'edit.php'; break; case 'dashboard': $this->Top_Slug = 'index.php'; break; case 'media': $this->Top_Slug = 'upload.php'; break; case 'links': $this->Top_Slug = 'link-manager.php'; break; case 'pages': $this->Top_Slug = 'edit.php?post_type=page'; break; case 'comments': $this->Top_Slug = 'edit-comments.php'; break; case 'theme': $this->Top_Slug = 'themes.php'; break; case 'plugins': $this->Top_Slug = 'plugins.php'; break; case 'users': $this->Top_Slug = 'users.php'; break; case 'tools': $this->Top_Slug = 'tools.php'; break; case 'settings': $this->Top_Slug = 'options-general.php'; break; default: if(post_type_exists($args['menu'])) { $this->Top_Slug = 'edit.php?post_type='.$args['menu']; } else { $this->Top_Slug = $args['menu']; } } } add_action('admin_menu', array($this, 'AddMenuSubPage')); }else{ //top page $this->Top_Slug = $args['menu']['top']; add_action('admin_menu', array($this, 'AddMenuTopPage')); } // Assign page values to local variables and add it's missed values. $this->_Page_Config = $args; $this->_fields = &$this->_Page_Config['fields']; $this->_Local_images = (isset($args['local_images'])) ? true : false; $this->_div_or_row = (isset($args['div_or_row'])) ? $args['div_or_row'] : false; $this->add_missed_values(); if (isset($args['use_with_theme'])){ if ($args['use_with_theme'] === true){ $this->SelfPath = get_stylesheet_directory_uri() . '/admin'; }elseif($args['use_with_theme'] === false){ $this->SelfPath = plugins_url( 'admin', plugin_basename( dirname( __FILE__ ) ) ); }else{ $this->SelfPath = $args['use_with_theme']; } } else{ $this->SelfPath = plugins_url( 'admin', plugin_basename( dirname( __FILE__ ) ) ); } // Load common js, css files // Must enqueue for all pages as we need js for the media upload, too. //add_action('admin_head', array($this, 'loadScripts')); } /** * Does all the complicated stuff to build the menu and its first page * * @since 0.1 * @access public */ public function AddMenuTopPage() { $default = array( 'capability' => 'edit_themes', 'menu_title' => '', 'id' => 'id', 'icon_url' => $this->SelfPath . '/images/menu_icon.png', 'position' => null ); $this->args = array_merge($default, $this->args); $id = add_menu_page($this->args['page_title'], $this->args['page_title'], $this->args['capability'], $this->args['id'], array($this, 'DisplayPage'), $this->args['icon_url'], $this->args['position']); $page = add_submenu_page($id, $this->args['page_title'], $this->args['page_title'], $this->args['capability'], $this->args['id'], array($this, 'DisplayPage')); if ($page){ $this->_Slug = $page; // Adds my_help_tab when my_admin_page loads add_action('load-'.$page, array($this,'Load_page_hooker')); } } /** * Does all the complicated stuff to build the page * * @since 0.1 * @access public */ public function AddMenuSubPage() { $default = array( 'capability' => 'edit_themes', ); $this->args = array_merge($default, $this->args); $page = add_submenu_page($this->Top_Slug, $this->args['page_title'], $this->args['page_title'], $this->args['capability'], $this->createSlug(), array($this, 'DisplayPage')); if ($page){ $this->_Slug = $page; add_action('load-'.$page, array($this,'Load_page_hooker')); } } /** * loads scripts and styles for the page * * @author Brandon Bell * @since 0.1 * @access public */ public function Load_page_hooker(){ $page = $this->_Slug; //help tabs add_action('admin_head-'.$page, array($this,'admin_add_help_tab')); //scripts and styles add_action( 'admin_print_styles', array( &$this, 'load_scripts_styles' ) ); //panel script add_action('admin_footer-' . $page, array($this,'panel_script')); //add mising scripts add_action('admin_enqueue_scripts',array($this,'Finish')); if(isset($_POST['action']) && $_POST['action'] == 'save') { $this->save(); $this->saved_flag = true; } } /** * Creates an unique slug out of the page_title and the current menu_slug * * @since 0.1 * @access private */ private function createSlug() { $slug = $this->args['page_title']; $slug = strtolower($slug); $slug = str_replace(' ','_',$slug); return $this->Top_Slug.'_'.$slug; } /** add Help Tab * * @since 0.1 * @access public * @param $args (mixed|array) contains everything needed to build the field * * Possible keys within $args: * > id (string) (required)- Tab ID. Must be HTML-safe and should be unique for this menu * > title (string) (required)- Title for the tab. * > content (string) (required)- Help tab content in plain text or HTML. * * * Will only work on wordpres version 3.3 and up */ public function HelpTab($args){ $this->_help_tabs[] = $args; } /* print Help Tabs for current screen * * @access public * @since 0.1 * @author Brandon Bell * * Will only work on wordpres version 3.3 and up */ public function admin_add_help_tab(){ $screen = get_current_screen(); /* * Check if current screen is My Admin Page * Don't add help tab if it's not */ if ( $screen->id != $this->_Slug ) return; // Add help_tabs for current screen foreach((array)$this->_help_tabs as $tab){ $screen->add_help_tab($tab); } } /* print out panel Script * * @access public * @since 0.1 */ public function panel_script(){ echo ''; } /* print out panel Style (deprecated) * * @access public * @since 0.1 */ public function panel_style(){ //echo ''; } /** * Outputs all the HTML needed for the new page * * @access public * @param $args (mixed|array) contains everything needed to build the field * @param $repeater (boolean) * @since 0.1 */ public function DisplayPage() { echo '
'; echo '




'; wp_nonce_field( basename(__FILE__), 'AIOBTN_Admin_Page_Class_nonce' ); if ($this->saved_flag) echo '

'.__('Settings saved.', 'aiobtn').'

'; $saved = get_option($this->option_group); $this->_saved = $saved; $skip = array('title','paragraph','subtitle','TABS','CloseDiv','TABS_Listing','OpenTab','custom'); foreach($this->_fields as $field) { if (!in_array($field['type'],$skip)){ if(!$this->table) { if ($this->_div_or_row){ echo ''; $this->table = true; }else{ echo '
'; $this->table = true; } } if ($this->_div_or_row){ //echo '
'; //echo ''; }else{ //echo '
'; //echo '
'; } }else{ if($this->table) { if ($this->_div_or_row){echo '
';}else{echo '
';} $this->table = false; } } $data = ''; if (isset($saved[$field['id']])) $data = $saved[$field['id']]; if (isset($field['std']) && $data === '') $data = $field['std']; if (method_exists($this,'show_field_' . $field['type'])){ if ($this->_div_or_row){echo '';}else{echo apply_filters('admin_page_class_field_container_open','
',$field);} call_user_func ( array( &$this, 'show_field_' . $field['type'] ), $field, $data ); if ($this->_div_or_row){echo '';}else{echo apply_filters('admin_page_class_field_container_close','
',$field);} }else{ switch($field['type']) { case 'TABS': echo '
'; break; case 'CloseDiv': $this->tab_div = false; echo '
'; break; case 'TABS_Listing': echo '
'; break; case 'OpenTab': $this->tab_div = true; echo '
'; break; case 'title': echo '

'.$field['label'].'

'; break; case 'subtitle': echo '

'.$field['label'].'

'; break; case 'paragraph': echo '

'.$field['text'].'

'; break; case 'repeater': $this->output_repeater_fields($field,$data); break; } } if (!in_array($field['type'],$skip)){ echo '';} } if($this->table) echo ''; if($this->tab_div) echo '
'; echo '
'; echo ''; echo ''; } /** * Adds tabs current page * * @access public * @param $args (mixed|array) contains everything needed to build the field * @since 0.1 */ public function OpenTabs_container($text= null) { $args['type'] = 'TABS'; $text = (null == $text)? '': $text; $args['text'] = $text; $args['id'] = 'TABS'; $args['std'] = ''; $this->SetField($args); } /** * Close open Div * * @access public * @param $args (mixed|array) contains everything needed to build the field * @param $repeater (boolean) * @since 0.1 */ public function CloseDiv_Container() { $args['type'] = 'CloseDiv'; $args['id'] = 'CloseDiv'; $args['std'] = ''; $this->SetField($args); } /** * Adds tabs listing in ul li * * @access public * @param $args (mixed|array) contains everything needed to build the field * @param $repeater (boolean) * @since 0.1 */ public function TabsListing($args) { $args['type'] = 'TABS_Listing'; $args['id'] = 'TABS_Listing'; $args['std'] = ''; $this->SetField($args); } /** * Opens a Div * * @access public * @param $args (mixed|array) contains everything needed to build the field * @param $repeater (boolean) * @since 0.1 */ public function OpenTab($name) { $args['type'] = 'OpenTab'; $args['id'] = $name; $args['std'] = ''; $this->SetField($args); } /** * close a Div * * @access public * @since 0.1 */ public function CloseTab() { $args['type'] = 'CloseDiv'; $args['id'] = 'CloseDiv'; $args['std'] = ''; $this->SetField($args); } /** * Does the repetive tasks of adding a field * * @param $args (mixed|array) contains everything needed to build the field * @param $repeater (boolean) * @since 0.1 * * @access private */ private function SetField($args) { $default = array( 'std' => '', 'id' => '' ); $args = array_merge($default, $args); $this->buildOptions($args); $this->_fields[] = $args; } /** * Builds all the options with their std values * * @access public * @param $args (mixed|array) contains everything needed to build the field * @since 0.1 * @access private */ private function buildOptions($args) { $default = array( 'std' => '', 'id' => '' ); $args = array_merge($default, $args); $saved = get_option($this->option_group); if (isset($saved[$args['id']])){ if($saved[$args['id']] === false) { $saved[$args['id']] = $args['std']; update_option($this->args['option_group'],$saved); } } } /** * Adds a heading to the current page * * @access public * @param $args (mixed|array) contains everything needed to build the field * @param $repeater (boolean) * @since 0.1 * * @param string $label simply the text for your heading */ public function Title($label,$repeater = false) { $args['type'] = 'title'; $args['std'] = ''; $args['label'] = $label; $args['id'] = 'title'.$label; $this->SetField($args); } /** * Adds a sub-heading to the current page * * @access public * @param $args (mixed|array) contains everything needed to build the field * @param $repeater (boolean) * @since 0.1 * * @param string $label simply the text for your heading */ public function Subtitle($label,$repeater = false) { $args['type'] = 'subtitle'; $args['label'] = $label; $args['id'] = 'title'.$label; $args['std'] = ''; $this->SetField($args); } /** * Adds a paragraph to the current page * * @access public * @param $args (mixed|array) contains everything needed to build the field * @param $repeater (boolean) * @since 0.1 * * @param string $text the text you want to display */ public function Paragraph($text,$repeater = false) { $args['type'] = 'paragraph'; $args['text'] = $text; $args['id'] = 'paragraph'; $args['std'] = ''; $this->SetField($args); } /** * Load all Javascript and CSS * * @since 0.1 * @access public */ public function load_scripts_styles() { // Get Plugin Path $plugin_path = $this->SelfPath; $this->check_field_upload(); $this->check_field_color(); $this->check_field_date(); $this->check_field_time(); $this->check_field_code(); // @TODO only load styles and js when needed wp_enqueue_script('common'); //wp_enqueue_script('jquery-color'); //wp_admin_css('thickbox'); //wp_print_scripts('post'); //wp_print_scripts('media-upload'); //wp_print_scripts('jquery'); //wp_print_scripts('jquery-ui-core'); if ($this->has_Field('TABS')){ wp_print_scripts('jquery-ui-tabs'); } if ($this->has_Field('editor')){ global $wp_version; if ( version_compare( $wp_version, '3.2.1' ) < 1 ) { wp_print_scripts('tiny_mce'); wp_print_scripts('editor'); wp_print_scripts('editor-functions'); } } wp_enqueue_script('utils'); // Enqueue admin page Style wp_enqueue_style( 'Admin_Page_Class', $plugin_path . '/css/Admin_Page_Class.css' ); // Enqueue admin page Scripts wp_enqueue_script( 'Admin_Page_Class', $plugin_path . '/js/Admin_Page_Class.js', array( 'jquery' ), null, true ); //anyway wp_enqueue_script( 'jquery-ui-sortable' ); } /** * Check Field code editor * * @since 0.1 * @access public */ public function check_field_code() { if ( $this->has_field( 'code' ) && $this->is_edit_page() ) { $plugin_path = $this->SelfPath; // Enqueu codemirror js and css wp_enqueue_style( 'at-code-css', $plugin_path .'/js/codemirror/codemirror.css',array(),null); wp_enqueue_style( 'at-code-css-dark', $plugin_path .'/js/codemirror/solarizedDark.css',array(),null); wp_enqueue_style( 'at-code-css-light', $plugin_path .'/js/codemirror/solarizedLight.css',array(),null); wp_enqueue_script('at-code-js',$plugin_path .'/js/codemirror/codemirror.js',array('jquery'),false,true); wp_enqueue_script('at-code-js-xml',$plugin_path .'/js/codemirror/xml.js',array('jquery'),false,true); wp_enqueue_script('at-code-js-javascript',$plugin_path .'/js/codemirror/javascript.js',array('jquery'),false,true); wp_enqueue_script('at-code-js-css',$plugin_path .'/js/codemirror/css.js',array('jquery'),false,true); wp_enqueue_script('at-code-js-clike',$plugin_path .'/js/codemirror/clike.js',array('jquery'),false,true); wp_enqueue_script('at-code-js-php',$plugin_path .'/js/codemirror/php.js',array('jquery'),false,true); } } /** * Check the Field Upload, Add needed Actions * * @since 0.1 * @access public */ public function check_field_upload() { // Check if the field is an image or file. If not, return. if ( ! $this->has_field( 'image' ) && ! $this->has_field( 'file' ) ) return; // Add data encoding type for file uploading. add_action( 'post_edit_form_tag', array( &$this, 'add_enctype' ) ); // Make upload feature work event when custom post type doesn't support 'editor' wp_enqueue_script( 'media-upload' ); add_thickbox(); wp_enqueue_script( 'jquery-ui-core' ); wp_enqueue_script( 'jquery-ui-sortable' ); // Add filters for media upload. add_filter( 'media_upload_gallery', array( &$this, 'insert_images' ) ); add_filter( 'media_upload_library', array( &$this, 'insert_images' ) ); add_filter( 'media_upload_image', array( &$this, 'insert_images' ) ); // Delete all attachments when delete custom post type. add_action( 'wp_ajax_at_delete_file', array( &$this, 'delete_file' ) ); add_action( 'wp_ajax_at_reorder_images', array( &$this, 'reorder_images' ) ); // Delete file via Ajax add_action( 'wp_ajax_at_delete_mupload', array( $this, 'wp_ajax_delete_image' ) ); } /** * Add data encoding type for file uploading * * @since 0.1 * @access public */ public function add_enctype () { echo ' enctype="multipart/form-data"'; } /** * Process images added to meta field. * * Modified from Faster Image Insert plugin. * * @return void * @author Cory Crowley */ public function insert_images() { // If post variables are empty, return. if ( ! isset( $_POST['at-insert'] ) || empty( $_POST['attachments'] ) ) return; // Security Check check_admin_referer( 'media-form' ); // Create Security Nonce $nonce = wp_create_nonce( 'at_ajax_delete' ); // Get Post Id and Field Id $id = $_POST['field_id']; // Modify the insertion string $html = ''; foreach( $_POST['attachments'] as $attachment_id => $attachment ) { // Strip Slashes $attachment = stripslashes_deep( $attachment ); // If not selected or url is empty, continue in loop. if ( empty( $attachment['selected'] ) || empty( $attachment['url'] ) ) continue; $li = "
  • "; $li .= "image_{$attachment_id}"; //$li .= "" . __( 'Delete', 'aiobtn' ) . ""; $li .= "" . __( "; $li .= ""; $li .= "
  • "; $html .= $li; } // End For Each return media_send_to_editor( $html ); } /** * Delete attachments associated with the post. * * @since 0.1 * @access public * */ public function delete_attachments( $post_id ) { // Get Attachments $attachments = get_posts( array( 'numberposts' => -1, 'post_type' => 'attachment', 'post_parent' => $post_id ) ); // Loop through attachments, if not empty, delete it. if ( ! empty( $attachments ) ) { foreach ( $attachments as $att ) { wp_delete_attachment( $att->ID ); } } } /** * Ajax callback for deleting files. * Modified from a function used by "Verve Meta Boxes" plugin (http://goo.gl/LzYSq) * @since 0.1 * @access public */ public function wp_ajax_delete_image() { $field_id = isset( $_GET['field_id'] ) ? $_GET['field_id'] : 0; $attachment_id = isset( $_GET['attachment_id'] ) ? intval( $_GET['attachment_id'] ) : 0; $ok = false; if (strpos($field_id, '[') === false){ check_admin_referer( "at-delete-mupload_".urldecode($field_id)); $temp = get_option($this->args['option_group']); unset($temp[$field_id]); update_option($this->args['option_group'],$temp); $ok = wp_delete_attachment( $attachment_id ); }else{ $f = explode('[',urldecode($field_id)); $f_fiexed = array(); foreach ($f as $k => $v){ $f[$k] = str_replace(']','',$v); } $temp = get_option($this->args['option_group']); $saved = $temp[$f[0]]; if (isset($saved[$f[1]][$f[2]])){ unset($saved[$f[1]][$f[2]]); $temp[$f[0]] = $saved; update_option($this->args['option_group'],$temp); $ok = wp_delete_attachment( $attachment_id ); } } if ( $ok ){ echo json_encode( array('status' => 'success' )); die(); }else{ echo json_encode(array('message' => __( 'Cannot delete file. Something\'s wrong.', 'aiobtn'))); die(); } } /** * Ajax callback for reordering Images. * * @since 0.1 * @access public */ public function reorder_images() { if ( ! isset( $_POST['data'] ) ) die(); list( $order, $post_id, $key, $nonce ) = explode( '|', $_POST['data'] ); if ( ! wp_verify_nonce( $nonce, 'at_ajax_reorder' ) ) die( '1' ); parse_str( $order, $items ); $items = $items['item']; $order = 1; foreach ( $items as $item ) { wp_update_post( array( 'ID' => $item, 'post_parent' => $post_id, 'menu_order' => $order ) ); $order++; } die( '0' ); } /** * Check Field Color * * @since 0.1 * @access public */ public function check_field_color() { if ( $this->has_field( 'color' ) && $this->is_edit_page() ) { // Enqueu built-in script and style for color picker. wp_enqueue_style( 'farbtastic' ); wp_enqueue_script( 'farbtastic' ); } } /** * Check Field Date * * @since 0.1 * @access public */ public function check_field_date() { if ( $this->has_field( 'date' ) && $this->is_edit_page() ) { // Enqueu JQuery UI, use proper version. wp_enqueue_style( 'at-jquery-ui-css', 'http://ajax.googleapis.com/ajax/libs/jqueryui/' . $this->get_jqueryui_ver() . '/themes/base/jquery-ui.css' ); wp_enqueue_script( 'at-jquery-ui', 'https://ajax.googleapis.com/ajax/libs/jqueryui/' . $this->get_jqueryui_ver() . '/jquery-ui.min.js', array( 'jquery' ) ); } } /** * Check Field Time * * @since 0.1 * @access public */ public function check_field_time() { if ( $this->has_field( 'time' ) && $this->is_edit_page() ) { $plugin_path = $this->SelfPath; // Enqueu JQuery UI, use proper version. wp_enqueue_style( 'at-jquery-ui-css', 'http://ajax.googleapis.com/ajax/libs/jqueryui/' . $this->get_jqueryui_ver() . '/themes/base/jquery-ui.css' ); wp_enqueue_script( 'at-jquery-ui', 'https://ajax.googleapis.com/ajax/libs/jqueryui/' . $this->get_jqueryui_ver() . '/jquery-ui.min.js', array( 'jquery' ) ); wp_enqueue_script( 'at-timepicker', $plugin_path . '/js/time-and-date/jquery-ui-timepicker-addon.js', array( 'jquery' ), null, true ); } } /** * Add Meta Box for multiple post types. * * @since 0.1 * @access public */ public function add() { // Loop through array foreach ( $this->_meta_box['pages'] as $page ) { add_meta_box( $this->_meta_box['id'], $this->_meta_box['title'], array( &$this, 'show' ), $page, $this->_meta_box['context'], $this->_meta_box['priority'] ); } } /** * Callback function to show fields in Page. * * @since 0.1 * @access public */ public function show() { global $post; wp_nonce_field( basename(__FILE__), 'AIOBTN_Admin_Page_Class_nonce' ); echo ''; foreach ( $this->_fields as $field ) { $meta = get_post_meta( $post->ID, $field['id'], !$field['multiple'] ); $meta = ( $meta !== '' ) ? $meta : $field['std']; if ('image' != $field['type'] && $field['type'] != 'repeater') $meta = is_array( $meta ) ? array_map( 'esc_attr', $meta ) : esc_attr( $meta ); echo ''; // Call Separated methods for displaying each type of field. call_user_func ( array( &$this, 'show_field_' . $field['type'] ), $field, $meta ); echo ''; } echo '
    '; } /** * Show Repeater Fields. * * @param string $field * @param string $meta * @since 0.1 * @modified at 0.4 added sortable option * @access public */ public function show_field_repeater( $field, $meta ) { // Get Plugin Path $plugin_path = $this->SelfPath; $this->show_field_begin( $field, $meta ); $class = ''; if ($field['sortable']) $class = " repeater-sortable"; echo "
    "; $c = 0; $meta = isset($this->_saved[$field['id']])? $this->_saved[$field['id']]: ''; if (count($meta) > 0 && is_array($meta) ){ foreach ($meta as $me){ //for labling toggles $mmm = $me[$field['fields'][0]['id']]; echo '
    '.$mmm.'
    '; if ($field['inline']){ echo ''; } foreach ($field['fields'] as $f){ //reset var $id for repeater $id = ''; $id = $field['id'].'['.$c.']['.$f['id'].']'; $m = $me[$f['id']]; $m = ( $m !== '' ) ? $m : $f['std']; if ('image' != $f['type'] && $f['type'] != 'repeater') $m = is_array( $m) ? array_map( 'esc_attr', $m ) : esc_attr( $m); //set new id for field in array format $f['id'] = $id; if (!$field['inline']){ echo ''; } call_user_func ( array( &$this, 'show_field_' . $f['type'] ), $f, $m); if (!$field['inline']){ echo ''; } } if ($field['inline']){ echo ''; } echo ' Edit '.__('Remove', 'aiobtn').'
    '; $c = $c + 1; } } echo ''.__('Add', 'aiobtn').'
    '; //create all fields once more for js function and catch with object buffer ob_start(); echo '
    '; if ($field['inline']){ echo ''; } foreach ($field['fields'] as $f){ //reset var $id for repeater $id = ''; $id = $field['id'].'[CurrentCounter]['.$f['id'].']'; $f['id'] = $id; if (!$field['inline']){ echo ''; } call_user_func ( array( &$this, 'show_field_' . $f['type'] ), $f, ''); if (!$field['inline']){ echo ''; } } if ($field['inline']){ echo ''; } echo '
    '.__('Remove', 'aiobtn').'
    '; $counter = 'countadd_'.$field['id']; $js_code = ob_get_clean (); $js_code = str_replace("'","\"",$js_code); $js_code = str_replace("CurrentCounter","' + ".$counter." + '",$js_code); echo ''; echo '
    '; $this->show_field_end($field, $meta); } /** * Begin Field. * * @param string $field * @param string $meta * @since 0.1 * @access public */ public function show_field_begin( $field, $meta) { if (isset($field['group'])){ if ($field['group'] == "start"){ echo ""; } }else{ echo ""; } if ( $field['name'] != '' || $field['name'] != FALSE ) { echo "
    "; echo ""; echo "
    "; } } /** * End Field. * * @param string $field * @param string $meta * @since 0.1 * @access public */ public function show_field_end( $field, $meta=NULL ,$group = false) { if (isset($field['group'])){ if ($group == 'end'){ if ( $field['desc'] != '' ) { echo "
    {$field['desc']}
    "; } else { echo ""; } }else { if ( $field['desc'] != '' ) { echo "
    {$field['desc']}

    "; }else{ echo '
    '; } } }else{ if ( $field['desc'] != '' ) { echo "
    {$field['desc']}
    "; } else { echo ""; } } } /** * Show Sortable Field * @author Brandon Bell * @since 0.4 * @access public * @param (array) $field * @param (array) $meta * @return void */ public function show_field_sortable( $field, $meta ) { $this->show_field_begin( $field, $meta ); $re = '
    '; echo $re; $this->show_field_end( $field, $meta ); } /** * Show Field Text. * * @param string $field * @param string $meta * @since 0.1 * @access public */ public function show_field_text( $field, $meta) { $this->show_field_begin( $field, $meta ); echo ""; $this->show_field_end( $field, $meta ); } /** * Show Field code editor. * * @param string $field * @author Brandon Bell * @param string $meta * @since 0.1 * @access public */ public function show_field_code( $field, $meta) { $this->show_field_begin( $field, $meta ); echo ""; $this->show_field_end( $field, $meta ); } /** * Show Field hidden. * * @param string $field * @param string|mixed $meta * @since 0.1 * @access public */ public function show_field_hidden( $field, $meta) { //$this->show_field_begin( $field, $meta ); echo ""; //$this->show_field_end( $field, $meta ); } /** * Show Field Paragraph. * * @param string $field * @since 0.1 * @access public */ public function show_field_paragraph( $field) { //$this->show_field_begin( $field, $meta ); echo '

    '.$field['value'].'

    '; //$this->show_field_end( $field, $meta ); } /** * Show Field Textarea. * * @param string $field * @param string $meta * @since 0.1 * @access public */ public function show_field_textarea( $field, $meta ) { $this->show_field_begin( $field, $meta ); echo ""; $this->show_field_end( $field, $meta ); } /** * Show Field Select. * * @param string $field * @param string $meta * @since 0.1 * @access public */ public function show_field_select( $field, $meta ) { if ( ! is_array( $meta ) ) $meta = (array) $meta; $this->show_field_begin( $field, $meta ); echo ""; $this->show_field_end( $field, $meta ); } /** * Show Radio Field. * * @param string $field * @param string $meta * @since 0.1 * @access public */ public function show_field_radio( $field, $meta ) { if ( ! is_array( $meta ) ) $meta = (array) $meta; $this->show_field_begin( $field, $meta ); foreach ( $field['options'] as $key => $value ) { echo " {$value}"; } $this->show_field_end( $field, $meta ); } /** * Show Checkbox Field. * * @param string $field * @param string $meta * @since 0.1 * @access public */ public function show_field_checkbox( $field, $meta ) { $this->show_field_begin($field, $meta); echo ""; $this->show_field_end( $field, $meta ); } /** * Show conditinal Checkbox Field. * * @param string $field * @param string $meta * @since 0.5 * @access public */ public function show_field_cond( $field, $meta ) { $this->show_field_begin($field, $meta); $checked = false; if (is_array($meta) && isset($meta['enabled']) && $meta['enabled'] == 'on'){ $checked = true; } echo ""; //start showing the fields $display = ' style="display: none;"'; if ($checked){ $display = ''; } echo '
    '; foreach ((array)$field['fields'] as $f){ //reset var $id for cond $id = ''; $id = $field['id'].'['.$f['id'].']'; $m = ''; if ($checked){ $m = (isset($meta[$f['id']])) ? $meta[$f['id']]: ''; } $m = ( $m !== '' ) ? $m : $f['std']; if ('image' != $f['type'] && $f['type'] != 'repeater') $m = is_array( $m) ? array_map( 'esc_attr', $m ) : esc_attr( $m); //set new id for field in array format $f['id'] = $id; call_user_func ( array( &$this, 'show_field_' . $f['type'] ), $f, $m); } echo '
    '; $this->show_field_end( $field, $meta ); } /** * Show Wysiwig Field. * * @param string $field * @param string $meta * @since 0.1 * @access public */ public function show_field_wysiwyg( $field, $meta ) { $this->show_field_begin( $field, $meta ); // Add TinyMCE script for WP version < 3.3 global $wp_version; if ( version_compare( $wp_version, '3.2.1' ) < 1 ) { echo ""; }else{ // Use new wp_editor() since WP 3.3 wp_editor( stripslashes(stripslashes(html_entity_decode($meta))), $field['id'], array( 'editor_class' => 'at-wysiwyg' ) ); } $this->show_field_end( $field, $meta ); } /** * Show File Field. * * @param string $field * @param string $meta * @since 0.1 * @access public */ public function show_field_file( $field, $meta ) { global $post; if ( ! is_array( $meta ) ) $meta = (array) $meta; $this->show_field_begin( $field, $meta ); echo "{$field['desc']}
    "; if ( ! empty( $meta ) ) { $nonce = wp_create_nonce( 'at_ajax_delete' ); echo '
    ' . __('Uploaded files', 'aiobtn') . '
    '; echo '
      '; foreach ( $meta as $att ) { // if (wp_attachment_is_image($att)) continue; // what's image uploader for? echo "
    1. " . wp_get_attachment_link( $att, '' , false, false, ' ' ) . " (" . __( 'Delete', 'aiobtn' ) . ")
    2. "; } echo '
    '; } // show form upload echo "
    "; echo "" . __( 'Upload new files', 'aiobtn' ) . ""; echo "
    "; echo "
    "; echo "
    "; echo ""; echo "
    "; echo "" . __( 'Add more files', 'aiobtn' ) . ""; echo "
    "; echo ""; } /** * Show Image Field. * * @param array $field * @param array $meta * @since 0.1 * @access public */ public function show_field_image( $field, $meta ) { $this->show_field_begin( $field, $meta ); $html = wp_nonce_field( "at-delete-mupload_{$field['id']}", "nonce-delete-mupload_".$field['id'], false, false ); $height = (isset($field['preview_height']))? $field['preview_height'] : '150px'; $width = (isset($field['preview_width']))? $field['preview_width'] : '150px'; if (is_array($meta)){ if(isset($meta[0]) && is_array($meta[0])) $meta = $meta[0]; } if (is_array($meta) && isset($meta['src']) && $meta['src'] != ''){ $html .= ""; $html .= ""; $html .= ""; $html .= ""; }else{ $html .= ""; $html .= ""; $html .= ""; $html .= ""; } echo $html; } /** * Show Typography Field. * * @author Brandon Bell * @param array $field * @param array $meta * @since 0.3 * @access public * * @last modified 0.4 - faster better selected handeling */ public function show_field_typo( $field, $meta ) { $this->show_field_begin( $field, $meta ); if (!is_array($meta)){ $meta = array( 'size' => '', 'face' => '', 'style' => '', 'color' => '#', ); } $html = ''; // Font Face $html .= ''; // Font Weight $html .= ''; // Font Color $html .= ""; $html .= ""; $html .= ""; echo $html; } /** * Show Color Field. * * @param string $field * @param string $meta * @since 0.1 * @access public */ public function show_field_color( $field, $meta ) { if ( empty( $meta ) ) $meta = '#'; $this->show_field_begin( $field, $meta ); echo ""; echo ""; echo ""; $this->show_field_end($field, $meta); } /** * Show Checkbox List Field * * @param string $field * @param string $meta * @since 0.1 * @access public */ public function show_field_checkbox_list( $field, $meta ) { if ( ! is_array( $meta ) ) $meta = (array) $meta; $this->show_field_begin($field, $meta); $html = array(); foreach ($field['options'] as $key => $value) { $html[] = " {$value}"; } echo implode( '
    ' , $html ); $this->show_field_end($field, $meta); } /** * Show Date Field. * * @param string $field * @param string $meta * @since 0.1 * @access public */ public function show_field_date( $field, $meta ) { $this->show_field_begin( $field, $meta ); echo ""; $this->show_field_end( $field, $meta ); } /** * Show time field. * * @param string $field * @param string $meta * @since 0.1 * @access public */ public function show_field_time( $field, $meta ) { $this->show_field_begin( $field, $meta ); echo ""; $this->show_field_end( $field, $meta ); } /** * Show Posts field. * used creating a posts/pages/custom types checkboxlist or a select dropdown * @param string $field * @param string $meta * @since 0.1 * @access public */ public function show_field_posts($field, $meta) { global $post; if (!is_array($meta)) $meta = (array) $meta; $this->show_field_begin($field, $meta); $options = $field['options']; $posts = get_posts($options['args']); // checkbox_list if ('checkbox_list' == $options['type']) { foreach ($posts as $p) { echo "ID, $meta), true, false) . " /> $p->post_title
    "; } } // select else { echo ""; } $this->show_field_end($field, $meta); } /** * Show Taxonomy field. * used creating a category/tags/custom taxonomy checkboxlist or a select dropdown * @param string $field * @param string $meta * @since 0.1 * @access public * * @uses get_terms() */ public function show_field_taxonomy($field, $meta) { global $post; if (!is_array($meta)) $meta = (array) $meta; $this->show_field_begin($field, $meta); $options = $field['options']; $terms = get_terms($options['taxonomy'], $options['args']); // checkbox_list if ('checkbox_list' == $options['type']) { foreach ($terms as $term) { echo "slug, $meta), true, false) . " /> $term->name "; } } // select else { echo ""; } $this->show_field_end($field, $meta); } /** * Show Role field. * used creating a Wordpress roles list checkboxlist or a select dropdown * @param string $field * @param string $meta * @since 0.1 * @access public * * @uses global $wp_roles; * @uses checked(); */ public function show_field_WProle($field, $meta) { if (!is_array($meta)) $meta = (array) $meta; $this->show_field_begin($field, $meta); $options = $field['options']; global $wp_roles; if ( ! isset( $wp_roles ) ) $wp_roles = new WP_Roles(); $names = $wp_roles->get_names(); if ($names){ // checkbox_list if ('checkbox_list' == $options['type']) { foreach ($names as $n) { echo " $n
    "; } } // select else { echo ""; } } $this->show_field_end($field, $meta); } /** * Save Data from page * * @param string $repeater (false ) * @since 0.1 * @access public */ public function save($repeater = false) { $saved = get_option($this->option_group); $this->_saved = $saved; $post_data = isset($_POST)? $_POST : NULL; If ($post_data == NULL) return; $skip = array('title','paragraph','subtitle','TABS','CloseDiv','TABS_Listing','OpenTab'); //check nonce if ( ! check_admin_referer( basename( __FILE__ ), 'AIOBTN_Admin_Page_Class_nonce') ) return; foreach ( $this->_fields as $field ) { if(!in_array($field['type'],$skip)){ $name = $field['id']; $type = $field['type']; $old = isset($saved[$name])? $saved[$name]: NULL; $new = ( isset( $_POST[$name] ) ) ? $_POST[$name] : ( ( isset($field['multiple']) && $field['multiple']) ? array() : '' ); // Validate meta value if ( class_exists( 'AIOBTN_Admin_Page_Class_Validate' ) && method_exists( 'AIOBTN_Admin_Page_Class_Validate', $field['validate_func'] ) ) { $new = call_user_func( array( 'AIOBTN_Admin_Page_Class_Validate', $field['validate_func'] ), $new ); } // Call defined method to save meta value, if there's no methods, call common one. $save_func = 'save_field_' . $type; if ( method_exists( $this, $save_func ) ) { call_user_func( array( &$this, 'save_field_' . $type ), $field, $old, $new ); } else { $this->save_field( $field, $old, $new ); } }//END Skip } // End foreach update_option($this->args['option_group'],$this->_saved); } /** * Common function for saving fields. * * @param string $field * @param string $old * @param string|mixed $new * @since 0.1 * @access public */ public function save_field( $field, $old, $new ) { $name = $field['id']; unset($this->_saved[$name]); if ( $new === '' || $new === array() ) return; if ( isset($field['multiple'] ) && $field['multiple']) { foreach ( $new as $add_new ) { $temp[] = $add_new; } $this->_saved[$name] = $temp; } else { $this->_saved[$name] = $new; } } /** * function for saving image field. * * @param string $field * @param string $old * @param string|mixed $new * @since 0.1 * @access public */ public function save_field_image( $field, $old, $new ) { $name = $field['id']; unset($this->_saved[$name]); if ( $new === '' || $new === array() || $new['id'] == '' || $new['src'] == '') return; $this->_saved[$name] = $new; } /* * Save Wysiwyg Field. * * @param string $field * @param string $old * @param string $new * @since 0.1 * @access public */ public function save_field_wysiwyg( $field, $old, $new ) { $this->save_field( $field, $old, htmlentities($new) ); } /** * Save repeater Fields. * * @param string $field * @param string|mixed $old * @param string|mixed $new * @since 0.1 * @access public */ public function save_field_repeater( $field, $old, $new ) { if (is_array($new) && count($new) > 0){ foreach ($new as $n){ foreach ( $field['fields'] as $f ) { $type = $f['type']; switch($type) { case 'wysiwyg': $n[$f['id']] = wpautop( $n[$f['id']] ); break; case 'file': $n[$f['id']] = $this->save_field_file_repeater($f,'',$n[$f['id']]); break; default: break; } } if(!$this->is_array_empty($n)) $temp[] = $n; } if (isset($temp) && count($temp) > 0 && !$this->is_array_empty($temp)){ $this->_saved[$field['id']] = $temp; }else{ if (isset($this->_saved[$field['id']])) unset($this->_saved[$field['id']]); } }else{ // remove old meta if exists if (isset($this->_saved[$field['id']])) unset($this->_saved[$field['id']]); } } /** * Add missed values for Page. * * @since 0.1 * @access public */ public function add_missed_values() { // Default values for admin //$this->_meta_box = array_merge( array( 'context' => 'normal', 'priority' => 'high', 'pages' => array( 'post' ) ), $this->_meta_box ); // Default values for fields foreach ( $this->_fields as &$field ) { $multiple = in_array( $field['type'], array( 'checkbox_list', 'file', 'image' ) ); $std = $multiple ? array() : ''; $format = 'date' == $field['type'] ? 'yy-mm-dd' : ( 'time' == $field['type'] ? 'hh:mm' : '' ); $field = array_merge( array( 'multiple' => $multiple, 'std' => $std, 'desc' => '', 'format' => $format, 'validate_func' => '' ), $field ); } // End foreach } /** * Check if field with $type exists. * * @param string $type * @since 0.1 * @access public */ public function has_field( $type ) { foreach ( $this->_fields as $field ) { if ( $type == $field['type'] ) return true; } return false; } /** * Check if current page is edit page. * * @since 0.1 * @access public */ public function is_edit_page() { //global $pagenow; return true; //return in_array( $pagenow, array( 'post.php', 'post-new.php' ) ); } /** * Fixes the odd indexing of multiple file uploads. * * Goes from the format: * $_FILES['field']['key']['index'] * to * The More standard and appropriate: * $_FILES['field']['index']['key'] * * @param string $files * @since 0.1 * @access public */ public function fix_file_array( &$files ) { $output = array(); foreach ( $files as $key => $list ) { foreach ( $list as $index => $value ) { $output[$index][$key] = $value; } } return $files = $output; } /** * Get proper JQuery UI version. * * Used in order to not conflict with WP Admin Scripts. * * @since 0.1 * @access public */ public function get_jqueryui_ver() { global $wp_version; if ( version_compare( $wp_version, '3.1', '>=') ) { return '1.8.10'; } return '1.7.3'; } /** * Add Field to page (generic function) * @author Brandon Bell * @since 0.1 * @access public * @param $id string field id, i.e. the meta key * @param $args mixed|array */ public function addField($id,$args){ $new_field = array('id'=> $id,'std' => '','desc' => '','style' =>''); $new_field = array_merge($new_field, $args); $this->_fields[] = $new_field; } /** * Add typography Field * * @author Brandon Bell * @since 0.3 * * @access public * * @param $id string id of the field * @param $args mixed|array * @param boolean $repeater=false */ public function addTypo($id,$args,$repeater=false){ $new_field = array( 'type' => 'typo', 'id'=> $id, 'std' => array( 'size' => '12px', 'color' => '#000000', 'face' => 'arial', 'style' => 'normal' ), 'desc' => '', 'style' =>'', 'name'=> 'Typography field' ); $new_field = array_merge($new_field, $args); $this->_fields[] = $new_field; } /** * Add Text Field to Page * @author Brandon Bell * @since 0.1 * @access public * @param $id string field id, i.e. the meta key * @param $args mixed|array * 'name' => // field name/label string optional * 'desc' => // field description, string optional * 'std' => // default value, string optional * 'style' => // custom style for field, string optional * 'validate_func' => // validate function, string optional * @param $repeater bool is this a field inside a repeatr? true|false(default) */ public function addText($id,$args,$repeater=false){ $new_field = array('type' => 'text','id'=> $id,'std' => '','desc' => '','style' =>'','name' => 'Text Field'); $new_field = array_merge($new_field, $args); if(false === $repeater){ $this->_fields[] = $new_field; }else{ return $new_field; } } /** * Add Hidden Field to Page * @author Brandon Bell * @since 0.1 * @access public * @param $id string field id, i.e. the meta key * @param $args mixed|array * 'name' => // field name/label string optional * 'desc' => // field description, string optional * 'std' => // default value, string optional * 'style' => // custom style for field, string optional * 'validate_func' => // validate function, string optional * @param $repeater bool is this a field inside a repeatr? true|false(default) */ public function addHidden($id,$args,$repeater=false){ $new_field = array('type' => 'hidden','id'=> $id,'std' => '','desc' => '','style' =>'','name' => 'Text Field'); $new_field = array_merge($new_field, $args); if(false === $repeater){ $this->_fields[] = $new_field; }else{ return $new_field; } } /** * Add code Editor to page * @author Brandon Bell * @since 0.1 * @access public * @param $id string field id, i.e. the meta key * @param $args mixed|array * 'name' => // field name/label string optional * 'desc' => // field description, string optional * 'std' => // default value, string optional * 'style' => // custom style for field, string optional * 'syntax' => // syntax language to use in editor (php,javascript,css,html) * 'validate_func' => // validate function, string optional * @param $repeater bool is this a field inside a repeatr? true|false(default) */ public function addCode($id,$args,$repeater=false){ $new_field = array('type' => 'code','id'=> $id,'std' => '','desc' => '','style' =>'','name' => 'Code Editor Field','syntax' => 'php', 'theme' => 'defualt'); $new_field = array_merge($new_field, $args); if(false === $repeater){ $this->_fields[] = $new_field; }else{ return $new_field; } } /** * Add Paragraph to Page * @author Brandon Bell * @since 0.1 * @access public * * @param $p paragraph html * @param $repeater bool is this a field inside a repeatr? true|false(default) */ public function addParagraph($p,$repeater=false){ $new_field = array('type' => 'paragraph','id'=> '','value' => $p); if(false === $repeater){ $this->_fields[] = $new_field; }else{ return $new_field; } } /** * Add Checkbox Field to Page * @author Brandon Bell * @since 0.1 * @access public * @param $id string field id, i.e. the meta key * @param $args mixed|array * 'name' => // field name/label string optional * 'desc' => // field description, string optional * 'std' => // default value, string optional * 'validate_func' => // validate function, string optional * @param $repeater bool is this a field inside a repeatr? true|false(default) */ public function addCheckbox($id,$args,$repeater=false){ $new_field = array('type' => 'checkbox','id'=> $id,'std' => '','desc' => '','style' =>'','name' => 'Checkbox Field'); $new_field = array_merge($new_field, $args); if(false === $repeater){ $this->_fields[] = $new_field; }else{ return $new_field; } } /** * Add Checkbox conditional Field to Page * @author Brandon Bell * @since 0.5 * @access public * @param $id string field id, i.e. the key * @param $args mixed|array * 'name' => // field name/label string optional * 'desc' => // field description, string optional * 'std' => // default value, string optional * 'validate_func' => // validate function, string optional * 'fields' => list of fields to show conditionally. * @param $repeater bool is this a field inside a repeatr? true|false(default) */ public function addCondition($id,$args,$repeater=false){ $new_field = array('type' => 'cond','id'=> $id,'std' => '','desc' => '','style' =>'','name' => 'Conditional Field','fields' => array()); $new_field = array_merge($new_field, $args); if(false === $repeater){ $this->_fields[] = $new_field; }else{ return $new_field; } } /** * Add CheckboxList Field to Page * @author Brandon Bell * @since 0.1 * @access public * @param $id string field id, i.e. the meta key * @param $options (array) array of key => value pairs for select options * @param $args mixed|array * 'name' => // field name/label string optional * 'desc' => // field description, string optional * 'std' => // default value, string optional * 'validate_func' => // validate function, string optional * @param $repeater bool is this a field inside a repeatr? true|false(default) * * @return : remember to call: $checkbox_list = get_post_meta(get_the_ID(), 'meta_name', false); * which means the last param as false to get the values in an array */ public function addCheckboxList($id,$options,$args,$repeater=false){ $new_field = array('type' => 'checkbox_list','id'=> $id,'std' => '','desc' => '','style' =>'','name' => 'Checkbox List Field'); $new_field = array_merge($new_field, $args); if(false === $repeater){ $this->_fields[] = $new_field; }else{ return $new_field; } } /** * Add Textarea Field to Page * @author Brandon Bell * @since 0.1 * @access public * @param $id string field id, i.e. the meta key * @param $args mixed|array * 'name' => // field name/label string optional * 'desc' => // field description, string optional * 'std' => // default value, string optional * 'style' => // custom style for field, string optional * 'validate_func' => // validate function, string optional * @param $repeater bool is this a field inside a repeatr? true|false(default) */ public function addTextarea($id,$args,$repeater=false){ $new_field = array('type' => 'textarea','id'=> $id,'std' => '','desc' => '','style' =>'','name' => 'Textarea Field'); $new_field = array_merge($new_field, $args); if(false === $repeater){ $this->_fields[] = $new_field; }else{ return $new_field; } } /** * Add Select Field to Page * @author Brandon Bell * @since 0.1 * @access public * @param $id string field id, i.e. the meta key * @param $options (array) array of key => value pairs for select options * @param $args mixed|array * 'name' => // field name/label string optional * 'desc' => // field description, string optional * 'std' => // default value, (array) optional * 'multiple' => // select multiple values, optional. Default is false. * 'validate_func' => // validate function, string optional * @param $repeater bool is this a field inside a repeatr? true|false(default) */ public function addSelect($id,$options,$args,$repeater=false){ $new_field = array('type' => 'select','id'=> $id,'std' => array(),'desc' => '','style' =>'','name' => 'Select Field','multiple' => false,'options' => $options); $new_field = array_merge($new_field, $args); if(false === $repeater){ $this->_fields[] = $new_field; }else{ return $new_field; } } /** * Add Sortable Field to Page * @author Brandon Bell * @since 0.4 * @access public * @param $id string field id, i.e. the meta key * @param $options (array) array of key => value pairs for sortable options as value => label * @param $args mixed|array * 'name' => // field name/label string optional * 'desc' => // field description, string optional * 'std' => // default value, (array) optional * 'validate_func' => // validate function, string optional * @param $repeater bool is this a field inside a repeatr? true|false(default) */ public function addSortable($id,$options,$args,$repeater=false){ $new_field = array('type' => 'sortable','id'=> $id,'std' => array(),'desc' => '','style' =>'','name' => 'Select Field','multiple' => false,'options' => $options); $new_field = array_merge($new_field, $args); if(false === $repeater){ $this->_fields[] = $new_field; }else{ return $new_field; } } /** * Add Radio Field to Page * @author Brandon Bell * @since 0.1 * @access public * @param $id string field id, i.e. the meta key * @param $options (array) array of key => value pairs for radio options * @param $args mixed|array * 'name' => // field name/label string optional * 'desc' => // field description, string optional * 'std' => // default value, string optional * 'validate_func' => // validate function, string optional * @param $repeater bool is this a field inside a repeatr? true|false(default) */ public function addRadio($id,$options,$args,$repeater=false){ $new_field = array('type' => 'radio','id'=> $id,'std' => array(),'desc' => '','style' =>'','name' => 'Radio Field','options' => $options); $new_field = array_merge($new_field, $args); if(false === $repeater){ $this->_fields[] = $new_field; }else{ return $new_field; } } /** * Add Date Field to Page * @author Brandon Bell * @since 0.1 * @access public * @param $id string field id, i.e. the meta key * @param $args mixed|array * 'name' => // field name/label string optional * 'desc' => // field description, string optional * 'std' => // default value, string optional * 'validate_func' => // validate function, string optional * 'format' => // date format, default yy-mm-dd. Optional. Default "'d MM, yy'" See more formats here: http://goo.gl/Wcwxn * @param $repeater bool is this a field inside a repeatr? true|false(default) */ public function addDate($id,$args,$repeater=false){ $new_field = array('type' => 'date','id'=> $id,'std' => '','desc' => '','format'=>'d MM, yy','name' => 'Date Field'); $new_field = array_merge($new_field, $args); if(false === $repeater){ $this->_fields[] = $new_field; }else{ return $new_field; } } /** * Add Time Field to Page * @author Brandon Bell * @since 0.1 * @access public * @param $id string- field id, i.e. the meta key * @param $args mixed|array * 'name' => // field name/label string optional * 'desc' => // field description, string optional * 'std' => // default value, string optional * 'validate_func' => // validate function, string optional * 'format' => // time format, default hh:mm. Optional. See more formats here: http://goo.gl/83woX * @param $repeater bool is this a field inside a repeatr? true|false(default) */ public function addTime($id,$args,$repeater=false){ $new_field = array('type' => 'time','id'=> $id,'std' => '','desc' => '','format'=>'hh:mm','name' => 'Time Field'); $new_field = array_merge($new_field, $args); if(false === $repeater){ $this->_fields[] = $new_field; }else{ return $new_field; } } /** * Add Color Field to Page * @author Brandon Bell * @since 0.1 * @access public * @param $id string field id, i.e. the meta key * @param $args mixed|array * 'name' => // field name/label string optional * 'desc' => // field description, string optional * 'std' => // default value, string optional * 'validate_func' => // validate function, string optional * @param $repeater bool is this a field inside a repeatr? true|false(default) */ public function addColor($id,$args,$repeater=false){ $new_field = array('type' => 'color','id'=> $id,'std' => '','desc' => '','name' => 'ColorPicker Field'); $new_field = array_merge($new_field, $args); if(false === $repeater){ $this->_fields[] = $new_field; }else{ return $new_field; } } /** * Add Image Field to Page * @author Brandon Bell * @since 0.1 * @access public * @param $id string field id, i.e. the meta key * @param $args mixed|array * 'name' => // field name/label string optional * 'desc' => // field description, string optional * 'validate_func' => // validate function, string optional * @param $repeater bool is this a field inside a repeatr? true|false(default) */ public function addImage($id,$args,$repeater=false){ $new_field = array('type' => 'image','id'=> $id,'desc' => '','name' => 'Image Field'); $new_field = array_merge($new_field, $args); if(false === $repeater){ $this->_fields[] = $new_field; }else{ return $new_field; } } /** * Add WYSIWYG Field to Page * @author Brandon Bell * @since 0.1 * @access public * @param $id string field id, i.e. the meta key * @param $args mixed|array * 'name' => // field name/label string optional * 'desc' => // field description, string optional * 'std' => // default value, string optional * 'style' => // custom style for field, string optional Default 'width: 300px; height: 400px' * 'validate_func' => // validate function, string optional * @param $repeater bool is this a field inside a repeatr? true|false(default) */ public function addWysiwyg($id,$args,$repeater=false){ $new_field = array('type' => 'wysiwyg','id'=> $id,'std' => '','desc' => '','style' =>'width: 300px; height: 400px','name' => 'WYSIWYG Editor Field'); $new_field = array_merge($new_field, $args); if(false === $repeater){ $this->_fields[] = $new_field; }else{ return $new_field; } } /** * Add Taxonomy Field to Page * @author Brandon Bell * @since 0.1 * @access public * @param $id string field id, i.e. the meta key * @param $options mixed|array options of taxonomy field * 'taxonomy' => // taxonomy name can be category,post_tag or any custom taxonomy default is category * 'type' => // how to show taxonomy? 'select' (default) or 'checkbox_list' * 'args' => // arguments to query taxonomy, see http://goo.gl/uAANN default ('hide_empty' => false) * @param $args mixed|array * 'name' => // field name/label string optional * 'desc' => // field description, string optional * 'std' => // default value, string optional * 'validate_func' => // validate function, string optional * @param $repeater bool is this a field inside a repeatr? true|false(default) */ public function addTaxonomy($id,$options,$args,$repeater=false){ $q = array('hide_empty' => 0); $tax = 'category'; $type = 'select'; $temp = array('taxonomy'=> $tax,'type'=>$type,'args'=>$q); $options = array_merge($temp,$options); $new_field = array('type' => 'taxonomy','id'=> $id,'desc' => '','name' => 'Taxonomy Field','options'=> $options); $new_field = array_merge($new_field, $args); if(false === $repeater){ $this->_fields[] = $new_field; }else{ return $new_field; } } /** * Add WP_Roles Field to Page * @author Brandon Bell * @since 0.1 * @access public * @param $id string field id, i.e. the meta key * @param $options mixed|array options of taxonomy field * 'type' => // how to show taxonomy? 'select' (default) or 'checkbox_list' * @param $args mixed|array * 'name' => // field name/label string optional * 'desc' => // field description, string optional * 'std' => // default value, string optional * 'validate_func' => // validate function, string optional * @param $repeater bool is this a field inside a repeatr? true|false(default) */ public function addRoles($id,$options,$args,$repeater=false){ $type = 'select'; $temp = array('type'=>$type); $options = array_merge($temp,$options); $new_field = array('type' => 'WProle','id'=> $id,'desc' => '','name' => 'WP Roles Field','options'=> $options); $new_field = array_merge($new_field, $args); if(false === $repeater){ $this->_fields[] = $new_field; }else{ return $new_field; } } /** * Add posts Field to Page * @author Brandon Bell * @since 0.1 * @access public * @param $id string field id, i.e. the meta key * @param $options mixed|array options of taxonomy field * 'post_type' => // post type name, 'post' (default) 'page' or any custom post type * type' => // how to show posts? 'select' (default) or 'checkbox_list' * args' => // arguments to query posts, see http://goo.gl/is0yK default ('posts_per_page' => -1) * @param $args mixed|array * 'name' => // field name/label string optional * 'desc' => // field description, string optional * 'std' => // default value, string optional * 'validate_func' => // validate function, string optional * @param $repeater bool is this a field inside a repeatr? true|false(default) */ public function addPosts($id,$options,$args,$repeater=false){ $q = array('posts_per_page' => -1); $temp = array('post_type' =>'post','type'=>'select','args'=>$q); $options = array_merge($temp,$options); $new_field = array('type' => 'posts','id'=> $id,'desc' => '','name' => 'Posts Field','options'=> $options); $new_field = array_merge($new_field, $args); if(false === $repeater){ $this->_fields[] = $new_field; }else{ return $new_field; } } /** * Add repeater Field Block to Page * @author Brandon Bell * @since 0.1 * @access public * @param $id string field id, i.e. the meta key * @param $args mixed|array * 'name' => // field name/label string optional * 'desc' => // field description, string optional * 'std' => // default value, string optional * 'style' => // custom style for field, string optional * 'validate_func' => // validate function, string optional * 'fields' => //fields to repeater * @modified 0.4 added sortable option */ public function addRepeaterBlock($id,$args){ $new_field = array('type' => 'repeater','id'=> $id,'name' => 'Reapeater Field','fields' => array(),'inline'=> false, 'sortable' => false); $new_field = array_merge($new_field, $args); $this->_fields[] = $new_field; } /** * Finish Declaration of Page * @author Brandon Bell * @since 0.1 * @access public */ public function Finish() { $this->add_missed_values(); $this->check_field_upload(); $this->check_field_color(); $this->check_field_date(); $this->check_field_time(); $this->check_field_code(); } /** * Helper function to check for empty arrays * @author Brandon Bell * @since 0.1 * @access public * @param $args mixed|array */ public function is_array_empty($array){ if (!is_array($array)) return true; foreach ($array as $a){ if (is_array($a)){ foreach ($a as $sub_a){ if (!empty($sub_a) && $sub_a != '') return false; } }else{ if (!empty($a) && $a != '') return false; } } return true; } /** * Get the list of avialable Fonts * * @author Brandon Bell * @since 0.3 * @access public * * @return mixed|array */ public function get_fonts_family($font=null) { $fonts = array( 'open-sans' => array( 'name' => 'Open Sans', 'import' => '@import url(http://fonts.googleapis.com/css?family=Open+Sans);', 'css' => "font-family: 'Open Sans', sans-serif;", 'api' => "Open+Sans" ), 'lato' => array( 'name' => 'Lato', 'import' => '@import url(http://fonts.googleapis.com/css?family=Lato);', 'css' => "font-family: 'Lato', sans-serif;", 'api' => "Lato" ), 'arial' => array( 'name' => 'Arial', 'css' => "font-family: Arial, sans-serif;", ), 'verdana' => array( 'name' => "Verdana, Geneva", 'css' => "font-family: Verdana, Geneva;", ), 'trebuchet' => array( 'name' => "Trebuchet", 'css' => "font-family: Trebuchet;", ), 'georgia' => array( 'name' => "Georgia", 'css' => "font-family: Georgia;", ), 'times' => array( 'name' => "Times New Roman", 'css' => "font-family: Times New Roman;", ), 'tahoma' => array( 'name' => "Tahoma, Geneva", 'css' => "font-family: Tahoma, Geneva;", ), 'palatino' => array( 'name' => "Palatino", 'css' => "font-family: Palatino;", ), 'helvetica' => array( 'name' => "Verdana, Geneva", 'css' => "font-family: Helvetica*;", ), ); $fonts = apply_filters( 'BF_available_fonts_family', $fonts ); if ($font === null){ return $fonts; }else{ foreach ($fonts as $f => $value) { if ($f == $font) return $value; } } } /** * Get list of font faces * * @author Brandon Bell * @since 0.3 * @access public * * @return array */ public function get_font_style(){ $default = array( 'normal' => 'Normal', 'italic' => 'Italic', 'bold' => 'Bold', 'bold italic' => 'Bold Italic' ); return apply_filters( 'BF_available_fonts_style', $default ); } } // End Class require_once(aiobtn_path .'inc/admin/options.php'); } // End Check Class Exists