0 ) $this->edit_meta_value( $_REQUEST['post'] ); exit(); } if ( is_user_logged_in() && isset($_REQUEST['id']) && $_REQUEST['page'] == 'custom-field-template/custom-field-template.php' ) { echo $this->load_custom_field( $_REQUEST['id'] ); exit(); } if( strstr($_SERVER['REQUEST_URI'], 'wp-admin/plugins.php') && ((isset($_GET['activate']) && $_GET['activate'] == 'true') || (isset($_GET['activate-multi']) && $_GET['activate-multi'] == 'true') ) ) { $options = $this->get_custom_field_template_data(); if( !$options ) { $this->install_custom_field_template_data(); $this->install_custom_field_template_css(); } } if ( substr($wp_version, 0, 3) >= '2.7' ) { add_action( 'manage_posts_custom_column', array(&$this, 'add_manage_posts_custom_column'), 10, 2 ); add_filter( 'manage_posts_columns', array(&$this, 'add_manage_posts_columns') ); add_action( 'manage_pages_custom_column', array(&$this, 'add_manage_posts_custom_column'), 10, 2 ); add_filter( 'manage_pages_columns', array(&$this, 'add_manage_pages_columns') ); add_action( 'quick_edit_custom_box', array(&$this, 'add_quick_edit_custom_box'), 10, 2 ); } if ( substr($wp_version, 0, 3) < '2.5' ) { add_action( 'simple_edit_form', array(&$this, 'insert_custom_field'), 1 ); add_action( 'edit_form_advanced', array(&$this, 'insert_custom_field'), 1 ); add_action( 'edit_page_form', array(&$this, 'insert_custom_field'), 1 ); } else { require_once(ABSPATH . 'wp-admin/includes/template.php'); add_meta_box('cftdiv', __('Custom Field Template', 'custom-field-template'), array(&$this, 'insert_custom_field'), 'post', 'normal', 'core'); add_meta_box('cftdiv', __('Custom Field Template', 'custom-field-template'), array(&$this, 'insert_custom_field'), 'page', 'normal', 'core'); } } function add_quick_edit_custom_box($column_name, $type) { global $wp_version; $options = $this->get_custom_field_template_data(); if( $options == null) return; if ( !$options['css'] ) { $this->install_custom_field_template_css(); $options = $this->get_custom_field_template_data(); } $out .= '
' . "\n"; $out .= '
'; $out .= ''; if ( count($options['custom_fields'])>1 ) { $out .= ''; } $out .= ''; $out .= '
'; $out .= '
'; $out .= '
' . "\n"; $out .= '
' . "\n"; echo $out; } function custom_field_template_admin_head() { global $wp_version; if ( substr($wp_version, 0, 3) >= '2.7' && is_user_logged_in() && ( strstr($_SERVER['REQUEST_URI'], 'wp-admin/edit.php') || strstr($_SERVER['REQUEST_URI'], 'wp-admin/edit-pages.php') ) && !strstr($_SERVER['REQUEST_URI'], 'page=') ) { ?> $val) : if ( substr($key, 0, 1) == '_' || !$val[0] ) continue; $content .= '

' . $key . '

' . "\n"; foreach($val as $val2) : $val2 = htmlspecialchars($val2, ENT_QUOTES); if ( $flag ) : $content .= '

' . $val2 . '

' . "\n"; else : if ( function_exists( mb_strlen ) ) : if ( mb_strlen($val2) > 50 ) : $before_content = mb_substr($val2, 0, 50); $after_content = mb_substr($val2, 50); $content .= '

' . $before_content . '[[[break]]]' . '

' . $after_content . '

' . "\n"; $flag = 1; else : $content .= '

' . $val2 . '

' . "\n"; endif; else : if ( strlen($val2) > 50 ) : $before_content = substr($val2, 0, 50); $after_content = substr($val2, 50); $content .= '

' . $before_content . '[[[break]]]' . '

' . $after_content . '

' . "\n"; $flag = 1; else : $content .= '

' . $val2 . '

' . "\n"; endif; endif; endif; endforeach; endforeach; if ( $content ) : $content = preg_replace('/([^\n]+)\n([^\n]+)\n([^\n]+)\n([^\n]+)\n([^$]+)/', '\1\2\3\4[[[break]]]\5', $content); list($before, $after) = explode('[[[break]]]', $content, 2); $after = preg_replace('/\[\[\[break\]\]\]/', '', $after); $output .= '
'; $output .= balanceTags($before, true); if ( $after ) : $output .= '... ' . __('read more', 'custom-field-template') . ''; $output .= '' . balanceTags($after, true) . ''; $output .= '[^]'; endif; $output .= '
'; else : $output .= ' '; endif; endif; echo $output; } function add_manage_posts_columns($columns) { $new_columns = array(); foreach($columns as $key => $val) : $new_columns[$key] = $val; if ( $key == 'tags' ) $new_columns['custom-fields'] = __('Custom Fields', 'custom-field-template'); endforeach; return $new_columns; } function add_manage_pages_columns($columns) { $new_columns = array(); foreach($columns as $key => $val) : $new_columns[$key] = $val; if ( $key == 'author' ) $new_columns['custom-fields'] = __('Custom Fields', 'custom-field-template'); endforeach; return $new_columns; } function media_send_to_custom_field($html) { $options = $this->get_custom_field_template_data(); $out = '' . "\n"; echo $out; if ($options['custom_field_template_use_multiple_insert']) { return; } else { exit(); } } function wpaq_filter_plugin_actions($links, $file){ static $this_plugin; if( ! $this_plugin ) $this_plugin = plugin_basename(__FILE__); if( $file == $this_plugin ){ $settings_link = '' . __('Settings') . ''; $links = array_merge( array($settings_link), $links); } return $links; } function custom_field_template_admin_scripts() { wp_enqueue_script( 'jquery' ); wp_enqueue_script( 'jquery-form' ); } function install_custom_field_template_data() { $options['custom_fields'][0]['title'] = __('Default Template', 'custom-field-template'); $options['custom_fields'][0]['content'] = '[Plan] type = text size = 35 label = Where are you going to go? [Plan] type = textfield size = 35 hideKey = true [Favorite Fruits] type = checkbox value = apple # orange # banana # grape default = orange # grape [Miles Walked] type = radio value = 0-9 # 10-19 # 20+ default = 10-19 clearButton = true [Temper Level] type = select value = High # Medium # Low default = Low [Hidden Thought] type = textarea rows = 4 cols = 40 tinyMCE = true mediaButton = true'; $options['shortcode_format'][0] = '
Plan[Plan]
Favorite Fruits[Favorite Fruits] Miles Walked[Miles Walked]
Temper Level[Temper Level]
Hidden Thought[Hidden Thought]
'; update_option('custom_field_template_data', $options); } function install_custom_field_template_css() { $options = get_option('custom_field_template_data'); $options['css'] = '#cft dl { clear:both; margin:0; padding:0; width:100%; } #cft dt { float:left; font-weight:bold; margin:0; text-align:center; width:20%; } #cft dt .hideKey { visibility:hidden; } #cft dd { float:left; margin:0; text-align:left; width:80%; } #cft dd p.label { font-weight:bold; margin:0; } #cft_instruction { margin:10px; } '; update_option('custom_field_template_data', $options); } function get_custom_field_template_data() { $options = get_option('custom_field_template_data'); return $options; } function custom_field_template_admin_menu() { add_options_page(__('Custom Field Template', 'custom-field-template'), __('Custom Field Template', 'custom-field-template'), 8, basename(__FILE__), array(&$this, 'custom_field_template_admin')); } function custom_field_template_the_content($content) { global $wp_query, $post; $options = $this->get_custom_field_template_data(); if ( count($options['hook']) > 0 ) : $categories = get_the_category(); $cats = array(); foreach( $categories as $val ) : $cats[] = $val->cat_ID; endforeach; for ( $i=0; $iget_custom_field_template_data(); if($_POST["custom_field_template_set_options_submit"]) : unset($options['custom_fields']); $j = 0; $options['custom_field_template_replace_keys_by_labels'] = $_POST['custom_field_template_replace_keys_by_labels']; $options['custom_field_template_use_multiple_insert'] = $_POST['custom_field_template_use_multiple_insert']; $options['custom_field_template_use_wpautop'] = $_POST['custom_field_template_use_wpautop']; $options['custom_field_template_use_autosave'] = $_POST['custom_field_template_use_autosave']; for($i=0;$iinstall_custom_field_template_data(); $this->install_custom_field_template_css(); $options = $this->get_custom_field_template_data(); $message = __('Options resetted.', 'custom-field-template'); elseif ($_POST['custom_field_template_delete_options_submit']) : delete_option('custom_field_template_data'); $options = $this->get_custom_field_template_data(); $message = __('Options deleted.', 'custom-field-template'); endif; ?>



TEMPLATE #

:

:

:
/>

:

:
/>

:
/>

:
/>

:
/>




FORMAT #



ex. `text` and `textarea`:
$value = 'Yes we can.';

ex. `radio` and `select`:
$values = array('dog', 'cat', 'monkey'); $default = 'cat';
ex. `checkbox`:
$values = array('dog', 'cat', 'monkey'); $defaults = array('dog', 'cat');
CODE #


HOOK #

:
/> />

:

:


ex.
[Plan]
type = textfield
size = 35
hideKey = true
typetext or textfieldcheckboxradioselecttextarea
hideKeyhideKey = truehideKey = truehideKey = truehideKey = truehideKey = true
labellabel = ABClabel = DEFlabel = GHIlabel = JKLlabel = MNO
sizesize = 30
valuevalue = apple # orange # bananavalue = apple # orange # bananavalue = apple # orange # banana
valueLabelvalueLabel = apples # oranges # bananasvalueLabel = apples # oranges # bananasvalueLabel = apples # oranges # bananas
defaultdefault = orangedefault = orange # bananadefault = orangedefault = orangedefault = orange
clearButtonclearButton = true
rowsrows = 4
colscols = 40
tinyMCEtinyMCE = true
mediaButtonmediaButton = true
codecode = 0code = 0code = 0code = 0code = 0
editCodeeditCode = 0editCode = 0editCode = 0editCode = 0editCode = 0
levellevel = 1level = 3level = 5level = 7level = 9
insertTaginsertTag = trueinsertTag = trueinsertTag = trueinsertTag = trueinsertTag = true
outputoutput = trueoutput = trueoutput = trueoutput = trueoutput = true
outputCodeoutputCode = 0outputCode = 0outputCode = 0outputCode = 0outputCode = 0
blankblank = trueblank = trueblank = trueblank = trueblank = true
sortsort = ascsort = descsort = ascsort = descsort = asc
searchsearch = truesearch = truesearch = truesearch = truesearch = true
classclass = textclass = checkboxclass = radioclass = selectclass = textarea



get_custom_field_template_data(); if ( !$options['custom_fields'][$id] ) return null; $custom_fields = $this->parse_ini_str( $options['custom_fields'][$id]['content'], true ); return $custom_fields; } function make_textfield( $name, $sid, $size = 25, $default, $hideKey, $label, $code, $class ) { $options = $this->get_custom_field_template_data(); $title = $name; $name = $this->sanitize_name( $name ); if ( is_numeric($code) ) : eval(stripcslashes($options['php'][$code])); endif; if( isset( $_REQUEST[ 'post' ] ) ) { $value = get_post_meta( $_REQUEST[ 'post' ], $title ); if ( $value ) { $value = $value[ $sid ]; } } else { $value = $default; } if ( $enforced_value ) : $value = $enforced_value; endif; if ( $hideKey == true ) $hide = ' class="hideKey"'; if ( !empty($class) ) $class = ' class="' . $class . '"'; if ( !empty($label) && $options['custom_field_template_replace_keys_by_labels'] ) $title = stripcslashes($label); $out .= '
' . '
' . $title . '
' . '
'; if ( !empty($label) && !$options['custom_field_template_replace_keys_by_labels'] ) $out .= '

' . stripcslashes($label) . '

'; $out .= '
' . '
'; return $out; } function make_checkbox( $name, $sid, $value, $valueLabel, $checked, $hideKey, $label, $code, $class ) { $options = $this->get_custom_field_template_data(); $title = $name; $name = $this->sanitize_name( $name ); if ( !$value ) $value = "true"; if( isset( $_REQUEST[ 'post' ] ) && $_REQUEST[ 'post' ] > 0 ) { $selected = get_post_meta( $_REQUEST[ 'post' ], $title ); if ( $selected ) { if ( in_array(stripcslashes($value), $selected) ) $checked = 'checked="checked"'; } } else { if( $checked == true ) $checked = 'checked="checked"'; } if ( $hideKey == true ) $hide = ' class="hideKey"'; if ( !empty($class) ) $class = ' class="' . $class . '"'; if ( !empty($label) && $options['custom_field_template_replace_keys_by_labels'] ) $title = stripcslashes($label); $out .= '
' . '
' . $title . '
' . '
'; if ( !empty($label) && !$options['custom_field_template_replace_keys_by_labels'] ) $out .= '

' . stripcslashes($label) . '

'; $out .= '
'; $out .= '
'; return $out; } function make_radio( $name, $sid, $values, $valueLabel, $clearButton, $default, $hideKey, $label, $code, $class ) { $options = $this->get_custom_field_template_data(); $title = $name; $name = $this->sanitize_name( $name ); if ( is_numeric($code) ) : eval(stripcslashes($options['php'][$code])); endif; if( isset( $_REQUEST[ 'post' ] ) && $_REQUEST[ 'post' ] > 0 ) { $selected = get_post_meta( $_REQUEST[ 'post' ], $title ); $selected = $selected[ $sid ]; } else { $selected = $default; } if ( $hideKey == true ) $hide = ' class="hideKey"'; if ( !empty($class) ) $class = ' class="' . $class . '"'; if ( !empty($label) && $options['custom_field_template_replace_keys_by_labels'] ) $title = stripcslashes($label); $out .= '
' . '
' . $title . ''; if( $clearButton == true ) { $out .= ''; } $out .= '
' . '
'; if ( !empty($label) && !$options['custom_field_template_replace_keys_by_labels'] ) $out .= '

' . stripcslashes($label) . '

'; $i = 0; foreach( $values as $val ) { $id = $name . '_' . $this->sanitize_name( $val ); $checked = ( trim( $val ) == trim( $selected ) ) ? 'checked="checked"' : ''; $out .= '
'; $i++; } $out .= '
'; return $out; } function make_select( $name, $sid, $values, $valueLabel, $default, $hideKey, $label, $code, $class ) { $options = $this->get_custom_field_template_data(); $title = $name; $name = $this->sanitize_name( $name ); if ( is_numeric($code) ) : eval(stripcslashes($options['php'][$code])); endif; if( isset( $_REQUEST[ 'post' ] ) && $_REQUEST[ 'post' ] > 0 ) { $selected = get_post_meta( $_REQUEST[ 'post' ], $title ); if ( $selected ) { $selected = $selected[ $sid ]; } } else { $selected = $default; } if ( $hideKey == true ) $hide = ' class="hideKey"'; if ( !empty($class) ) $class = ' class="' . $class . '"'; if ( !empty($label) && $options['custom_field_template_replace_keys_by_labels'] ) $title = stripcslashes($label); $out .= '
' . '
' . $title . '
' . '
'; if ( !empty($label) && !$options['custom_field_template_replace_keys_by_labels'] ) $out .= '

' . stripcslashes($label) . '

'; $out .= '
'; return $out; } function make_textarea( $name, $sid, $rows, $cols, $tinyMCE, $mediaButton, $default, $hideKey, $label, $code, $class ) { $options = $this->get_custom_field_template_data(); global $wp_version; $title = $name; $name = $this->sanitize_name( $name ); if ( is_numeric($code) ) : eval(stripcslashes($options['php'][$code])); endif; if( isset( $_REQUEST[ 'post' ] ) ) { $value = get_post_meta( $_REQUEST[ 'post' ], $title ); $value = $value[ $sid ]; } else { $value = $default; } $rand = rand(); if( $tinyMCE == true ) { $out = ''; } if ( substr($wp_version, 0, 3) >= '2.5' ) { if ( !strstr($_SERVER['REQUEST_URI'], 'wp-admin/edit.php') && !strstr($_SERVER['REQUEST_URI'], 'wp-admin/edit-pages.php') ) { if ( $mediaButton == true ) { $media_upload_iframe_src = "media-upload.php"; $media_title = __('Add Media'); $image_upload_iframe_src = apply_filters('image_upload_iframe_src', "$media_upload_iframe_src?type=image"); $image_title = __('Add an Image'); $video_upload_iframe_src = apply_filters('video_upload_iframe_src', "$media_upload_iframe_src?type=video"); $video_title = __('Add Video'); $audio_upload_iframe_src = apply_filters('audio_upload_iframe_src', "$media_upload_iframe_src?type=audio"); $audio_title = __('Add Audio'); $media = <<$image_title $video_title $audio_title $media_title EOF; } $switch = '
'; if( $tinyMCE == true && user_can_richedit() ) { $switch .= '' . __('Toggle', 'custom-field-template') . ''; } $switch .= '
'; } } if ( $hideKey == true ) $hide = ' class="hideKey"'; if ( !empty($class) ) $class = ' class="' . $class . '"'; if ( !empty($label) && $options['custom_field_template_replace_keys_by_labels'] ) $title = stripcslashes($label); $out .= '
' . '
' . $title . '
' . $media . $switch . '
' . '
'; if ( !empty($label) && !$options['custom_field_template_replace_keys_by_labels'] ) $out .= '

' . stripcslashes($label) . '

'; $out .= '
' . '
'; return $out; } function load_custom_field( $id = 0 ) { global $userdata; get_currentuserinfo(); $level = $userdata->user_level; $options = $this->get_custom_field_template_data(); $fields = $this->get_custom_fields( $id ); if( $fields == null) return; if ( $options['custom_fields'][$id]['instruction'] ) $out .= '
' . stripcslashes($options['custom_fields'][$id]['instruction']) . '
'; $out .= '
'; $out .= ''; foreach( $fields as $title => $data ) { for($i = 0; $i $level ) continue; endif; if( $data[$i]['type'] == 'break' ) { $out .= '
'; } else if( $data[$i]['type'] == 'textfield' || $data[$i]['type'] == 'text' ) { $out .= $this->make_textfield( $title, $i, $data[$i]['size'], $data[$i]['default'], $data[$i]['hideKey'], $data[$i]['label'], $data[$i]['code'], $data[$i]['class'] ); } else if( $data[$i]['type'] == 'checkbox' ) { $out .= $this->make_checkbox( $title, $i, $data[$i]['value'], $data[$i]['valueLabel'], $data[$i]['checked'], $data[$i]['hideKey'], $data[$i]['label'], $data[$i]['code'], $data[$i]['class'] ); } else if( $data[$i]['type'] == 'radio' ) { $out .= $this->make_radio( $title, $i, explode( '#', $data[$i]['value'] ), explode( '#', $data[$i]['valueLabel'] ), $data[$i]['clearButton'], $data[$i]['default'], $data[$i]['hideKey'], $data[$i]['label'], $data[$i]['code'], $data[$i]['class'] ); } else if( $data[$i]['type'] == 'select' ) { $out .= $this->make_select( $title, $i, explode( '#', $data[$i]['value'] ), explode( '#', $data[$i]['valueLabel'] ), $data[$i]['default'], $data[$i]['hideKey'], $data[$i]['label'], $data[$i]['code'], $data[$i]['class'] ); } else if( $data[$i]['type'] == 'textarea' ) { if ( $options['tinyMCE'][$_REQUEST['post']][$this->sanitize_name($title)][$i] ) $data[$i]['rows'] = $options['tinyMCE'][$_REQUEST['post']][$this->sanitize_name($title)][$i]; $out .= $this->make_textarea( $title, $i, $data[$i]['rows'], $data[$i]['cols'], $data[$i]['tinyMCE'], $data[$i]['mediaButton'], $data[$i]['default'], $data[$i]['hideKey'], $data[$i]['label'], $data[$i]['code'], $data[$i]['class'] ); } } } $out .= '
'; $out .= '
'; return $out; } function insert_custom_field() { global $wp_version; $options = $this->get_custom_field_template_data(); if( $options == null) return; if ( !$options['css'] ) { $this->install_custom_field_template_css(); $options = $this->get_custom_field_template_data(); } if ( substr($wp_version, 0, 3) < '2.5' ) { $out .= '

' . __('Custom Field Template', 'custom-field-template') . '

'; } $out .= ''; $out .= ''; $body = $this->load_custom_field(); if ( count($options['custom_fields'])>1 ) { $out .= ''; } $out .= ''; $out .= '
'; $out .= $body; $out .= '
'; $out .= '
'; $out .= ' '; $out .= ''; $out .= '
'; if ( substr($wp_version, 0, 3) < '2.5' ) { $out .= '
'; } echo $out; } function edit_meta_value( $id ) { global $wpdb, $wp_version; $options = $this->get_custom_field_template_data(); if( !isset( $id ) ) $id = $_REQUEST[ 'post_ID' ]; if( !current_user_can('edit_post', $id) ) return $id; if( !wp_verify_nonce($_REQUEST['custom-field-template-verify-key'], 'custom-field-template') ) return $id; $fields = $this->get_custom_fields($_REQUEST['custom-field-template-id']); if ( $fields == null ) return; foreach( $fields as $title => $data) { $name = $this->sanitize_name( $title ); $title = $wpdb->escape(stripcslashes(trim($title))); delete_post_meta($id, $title); } if ( !class_exists('SimpleTags') ) $tags_input = explode(",", $_POST['tags_input']); foreach( $fields as $title => $data) { for($i = 0; $isanitize_name( $title ); $title = $wpdb->escape(stripcslashes(trim($title))); $meta_value = stripcslashes(trim($_REQUEST[ "$name" ][$i])); if ( $options['custom_field_template_use_wpautop'] && $data[$i]['type'] == 'textarea' && !empty($meta_value) ) $meta_value = wpautop($meta_value); if( isset( $meta_value ) && strlen( $meta_value ) ) { if ( is_numeric($data[$i]['editCode']) ) : eval(stripcslashes($options['php'][$data[$i]['editCode']])); endif; add_post_meta( $id, $title, $meta_value ); if ( $data[$i]['insertTag'] == true ) $tags_input[] = $meta_value; if ( $_REQUEST['TinyMCE_' . $name . trim($_REQUEST[ $name."_rand" ][$i]) . '_size'] ) { preg_match('/cw=[0-9]+&ch=([0-9]+)/', $_REQUEST['TinyMCE_' . $name . trim($_REQUEST[ $name."_rand" ][$i]) . '_size'], $matched); $options['tinyMCE'][$id][$name][$i] = (int)($matched[1]/20); } } else if ( $data[$i]['blank'] == true ) add_post_meta( $id, $title, "" ); } } if ( is_array($tags_input) ) : if ( class_exists('SimpleTags') ) : wp_cache_flush(); $taxonomy = wp_get_object_terms($id, 'post_tag', array()); if ( $taxonomy ) foreach($taxonomy as $val) $tags[] = $val->name; if ( is_array($tags) ) $tags_input = array_merge($tags, $tags_input); endif; $tags_input = array_unique($tags_input); if ( substr($wp_version, 0, 3) >= '2.3' ) wp_set_post_tags( $id, $tags_input ); endif; $options['posts'][$id] = $_REQUEST['custom-field-template-id']; update_option('custom_field_template_data', $options); } function parse_ini_str($Str,$ProcessSections = TRUE) { $options = $this->get_custom_field_template_data(); $Section = NULL; $Data = array(); $Sections = array(); $id = 0; if ($Temp = strtok($Str,"\r\n")) { do { switch ($Temp{0}) { case ';': case '#': break; case '[': if (!$ProcessSections) { break; } $Pos = strpos($Temp,'['); $Section = substr($Temp,$Pos+1,strpos($Temp,']',$Pos)-1); if ( in_array($Section, $Sections) ) { $id++; } else { $id = 0; $Data[$Section] = array(); } $Sections[] = $Section; if($Data[$Section]) break; default: $Pos = strpos($Temp,'='); if ($Pos === FALSE) { break; } $Value = array(); $Value["NAME"] = trim(substr($Temp,0,$Pos)); $Value["VALUE"] = trim(substr($Temp,$Pos+1)); if ($ProcessSections) { $Data[$Section][$id][$Value["NAME"]] = $Value["VALUE"]; } else { $Data[$Value["NAME"]] = $Value["VALUE"]; } break; } } while ($Temp = strtok("\r\n")); foreach($Data as $title => $data) { foreach($data as $key => $val) { if($val["type"] == "checkbox") { if ( is_numeric($val["code"]) ) : eval(stripcslashes($options['php'][$val["code"]])); else : $values = explode( '#', $val["value"] ); $valueLabel = explode( '#', $val["valueLabel"] ); $defaults = explode( '#', $val["default"] ); endif; if ( is_array($defaults) ) foreach($defaults as $dkey => $dval) $defaults[$dkey] = trim($dval); $tmp = $key; if ( is_array($values) ) : $i = 0; foreach($values as $value) { $Data[$title][$key]["type"] = "checkbox"; $Data[$title][$key]["value"] = trim($value); if ( $valueLabel[$i] ) $Data[$title][$key]["valueLabel"] = trim($valueLabel[$i]); if ( $tmp!=$key ) $Data[$title][$key]["hideKey"] = true; if ( is_array($defaults) ) if ( in_array(trim($value), $defaults) ) $Data[$title][$key]["checked"] = true; if ( $val["level"] ) $Data[$title][$key]["level"] = $val["level"]; if ( $val["insertTag"] == true ) $Data[$title][$key]["insertTag"] = true; if ( $val["output"] == true ) $Data[$title][$key]["output"] = true; $key++; $i++; } endif; } } } } return $Data; } function output_custom_field_values($attr) { global $post; $options = $this->get_custom_field_template_data(); extract(shortcode_atts(array( 'post_id' => $post->ID, 'template' => 0, 'format' => '' ), $attr)); if ( is_numeric($format) && $output = $options['shortcode_format'][$format] ) : $data = get_post_custom($post_id); if( $data == null) return; $count = count($options['custom_fields']); if ( $count ) : for ($i=0;$i<$count;$i++) : $fields = $this->get_custom_fields( $i ); foreach ( $fields as $key => $val ) : if ( count($data[$key]) > 1 ) : if ( $val[0]['sort'] == 'asc' ) sort($data[$key]); elseif ( $val[0]['sort'] == 'desc' ) rsort($data[$key]); $replace_val = '
    '; foreach ( $data[$key] as $val2 ) : $value = $val2; if ( is_numeric($val[0]['outputCode']) ) : eval(stripcslashes($options['php'][$val[0]['outputCode']])); endif; $replace_val .= '
  • '.$value.'
  • '; endforeach; $replace_val .= '
'; elseif ( count($data[$key]) == 1 ) : $value = $data[$key][0]; if ( is_numeric($val[0]['outputCode']) ) : eval(stripcslashes($options['php'][$val[0]['outputCode']])); endif; $replace_val = $value; else : $replace_val = ''; endif; $key = preg_quote($key, '/'); $output = preg_replace('/\['.$key.'\]/', $replace_val, $output); endforeach; endfor; endif; else : $fields = $this->get_custom_fields( $template ); if( $fields == null) return; $output = '
' . "\n"; foreach ( $fields as $key => $val ) : $values = get_post_meta( $post_id, $key ); if ($values): if ( $val[0]['sort'] == 'asc' ) sort($values); elseif ( $val[0]['sort'] == 'desc' ) rsort($values); foreach ( $val as $key2 => $val2 ) : $hide = ''; if ( $val2['output'] == true ) : $value = $values[$key2]; if ( is_numeric($val2['outputCode']) ) : eval(stripcslashes($options['php'][$val2['outputCode']])); endif; if ( $val2['hideKey'] == true ) $hide = ' class="hideKey"'; if ( !empty($val2['label']) && $options['custom_field_template_replace_keys_by_labels'] ) $key = stripcslashes($val2['label']); if ( $val2['type'] == 'checkbox' ) : if( in_array($val2['value'], $values) ) : $output .= '
' . $key . '
' . "\n"; $output .= '
' . $value . '
' . "\n"; endif; else : $output .= '
' . $key . '
' . "\n"; $output .= '
' . $value . '
' . "\n"; endif; endif; endforeach; endif; endforeach; $output .= '
' . "\n"; endif; return stripcslashes($output); } function search_custom_field_values($attr) { global $post; $options = $this->get_custom_field_template_data(); extract(shortcode_atts(array( 'template' => 0, 'format' => '' ), $attr)); if ( is_numeric($format) && $output = $options['shortcode_format'][$format] ) : $output = '
' . "\n" . $output; $count = count($options['custom_fields']); if ( $count ) : for ($i=0;$i<$count;$i++) : $fields = $this->get_custom_fields( $i ); foreach ( $fields as $key => $val ) : $replace_val = ""; switch ( $val[0]['type'] ) : case 'text': case 'textarea': $replace_val .= ''; break; case 'checkbox': if ( count($val) > 1 ) : $replace_val .= '
    '; foreach( $val as $val2 ) : $replace_val .= '
  • '; if ( $val2['valueLabel'] ) $replace_val .= stripcslashes($val2['valueLabel']); else $replace_val .= stripcslashes($val2['value']); $replace_val .= '
  • '; endforeach; else : $replace_val .= ' '; if ( $val[0]['valueLabel'] ) $replace_val .= stripcslashes($val[0]['valueLabel']); else $replace_val .= stripcslashes($val[0]['value']); endif; break; case 'radio': $values = explode( '#', $val[0]['value'] ); $valueLabels = explode( '#', $val[0]['valueLabel'] ); $j=0; foreach ( $values as $metaval ) : $metaval = trim($metaval); $replace_val .= ' '; if ( $val[0]['valueLabel'] ) $replace_val .= stripcslashes(trim($valueLabels[$j])); else $replace_val .= stripcslashes($metaval); $j++; endforeach; break; case 'select': $values = explode( '#', $val[0]['value'] ); $valueLabels = explode( '#', $val[0]['valueLabel'] ); $replace_val .= '' . "\n"; break; endswitch; $key = preg_quote($key, '/'); $output = preg_replace('/\['.$key.'\]/', $replace_val, $output); endforeach; endfor; endif; $output .= '

    ' . "\n"; $output .= '' . "\n"; else : $fields = $this->get_custom_fields( $template ); if ( $fields == null ) return; $output = '
    ' . "\n"; foreach( $fields as $key => $val) : if ( $val[0]['search'] == true ) : if ( !empty($val[0]['label']) && $options['custom_field_template_replace_keys_by_labels'] ) $key = stripcslashes($val[0]['label']); $output .= '
    ' ."\n"; $output .= '
    ' ."\n"; foreach ( $val as $key2 => $val2 ) : switch ( $val2['type'] ) : case 'text': case 'textarea': $output .= '
    '; break; case 'checkbox': $output .= '
    '; if ( $val2['valueLabel'] ) $output .= stripcslashes($val2['valueLabel']); else $output .= stripcslashes($val2['value']); $output .= '
    ' . "\n"; break; case 'radio': $values = explode( '#', $val2['value'] ); $valueLabels = explode( '#', $val2['valueLabel'] ); $output .= '
    '; $i=0; foreach ( $values as $metaval ) : $metaval = trim($metaval); $output .= ' '; if ( $val2['valueLabel'] ) $output .= stripcslashes(trim($valueLabels[$i])); else $output .= stripcslashes($metaval); $i++; endforeach; $output .= '
    ' . "\n"; break; case 'select': $values = explode( '#', $val2['value'] ); $valueLabels = explode( '#', $val2['valueLabel'] ); $output .= '
    ' . "\n"; break; endswitch; endforeach; $output .= '
    ' ."\n"; endif; endforeach; $output .= '

    ' . "\n"; $output .= '
    ' . "\n"; endif; return stripcslashes($output); } function custom_field_template_posts_where($where) { global $wp_query, $wp_version, $wpdb; if ( isset($_REQUEST['ss']) ) : $wp_query->query_vars['s'] = $_REQUEST['ss']; endif; if ( is_array($_REQUEST['cftsearch']) ) : foreach ( $_REQUEST['cftsearch'] as $key => $val ) : if ( $val ) : $where .= " AND ROW(ID,1) IN (SELECT post_id,count(post_id) FROM wp_postmeta WHERE (" . $wpdb->postmeta . ".meta_key = '" . urldecode($key) . "' AND " . $wpdb->postmeta . ".meta_value LIKE '%" . $val . "%') GROUP BY post_id) "; endif; endforeach; endif; return $where; } function custom_field_template_posts_orderby($orderby) { $orderby = $_REQUEST['custom_f_orderby']; if (!empty($orderby)) : $sql = $orderby; $ascdesc = $_REQUEST['custom_f_ascdesc']; if (!empty($ascdesc)) $sql .= " ".$ascdesc; endif; return $sql; } } $custom_field_template = new custom_field_template(); ?>