Version Description
Download this release
Release Info
Developer | Hiroaki Miyashita |
Plugin | Custom Field Template |
Version | 1.0.6 |
Comparing to | |
See all releases |
Code changes from version 1.0.5 to 1.0.6
- custom-field-template.php +96 -32
- readme.txt +1 -1
custom-field-template.php
CHANGED
@@ -4,7 +4,7 @@ Plugin Name: Custom Field Template
|
|
4 |
Plugin URI: http://wordpressgogo.com/development/custom-field-template.html
|
5 |
Description: This plugin adds the default custom fields on the Write Post/Page.
|
6 |
Author: Hiroaki Miyashita
|
7 |
-
Version: 1.0.
|
8 |
Author URI: http://wordpressgogo.com/
|
9 |
*/
|
10 |
|
@@ -31,7 +31,9 @@ class custom_field_template {
|
|
31 |
add_filter( 'the_content', array(&$this, 'custom_field_template_the_content') );
|
32 |
|
33 |
if ( $_REQUEST['cftsearch_submit'] ) :
|
|
|
34 |
add_filter( 'posts_where', array(&$this, 'custom_field_template_posts_where') );
|
|
|
35 |
endif;
|
36 |
|
37 |
if ( function_exists('add_shortcode') ) :
|
@@ -438,16 +440,18 @@ mediaButton = true';
|
|
438 |
|
439 |
for ( $i=0; $i<count($options['hook']); $i++ ) :
|
440 |
if ( $options['hook'][$i]['category'] ) :
|
441 |
-
|
442 |
-
|
443 |
-
|
444 |
-
if ( $
|
445 |
-
|
446 |
-
|
447 |
-
|
448 |
-
|
449 |
-
|
450 |
-
|
|
|
|
|
451 |
else :
|
452 |
if ( $options['hook'][$i]['position'] == 0 )
|
453 |
$content .= $options['hook'][$i]['content'];
|
@@ -809,6 +813,9 @@ hideKey = true<br />
|
|
809 |
<tr>
|
810 |
<th>class</th><td>class = text</td><td>class = checkbox</td><td>class = radio</td><td>class = select</td><td>class = textarea</td>
|
811 |
</tr>
|
|
|
|
|
|
|
812 |
</tbody>
|
813 |
</table>
|
814 |
</div>
|
@@ -1204,6 +1211,9 @@ EOF;
|
|
1204 |
|
1205 |
if ( $fields == null )
|
1206 |
return;
|
|
|
|
|
|
|
1207 |
|
1208 |
if ( (!$_REQUEST['post'] || $_REQUEST['post']<0) && $options['custom_fields'][$id]['category'] && $_REQUEST['cft_mode'] != 'ajaxload' )
|
1209 |
return;
|
@@ -1222,7 +1232,8 @@ EOF;
|
|
1222 |
if ( $data[$i]['level'] > $level ) continue;
|
1223 |
endif;
|
1224 |
if( $data[$i]['type'] == 'break' ) {
|
1225 |
-
$
|
|
|
1226 |
}
|
1227 |
else if( $data[$i]['type'] == 'textfield' || $data[$i]['type'] == 'text' ) {
|
1228 |
$out .= $this->make_textfield( $title, $i, $data[$i]['size'], $data[$i]['default'], $data[$i]['hideKey'], $data[$i]['label'], $data[$i]['code'], $data[$i]['class'] );
|
@@ -1373,9 +1384,9 @@ jQuery("#edButtonPreview").trigger("click"); }' . "\n";
|
|
1373 |
$categories = explode(',', $val['category']);
|
1374 |
foreach($categories as $cat_id) :
|
1375 |
if ( is_numeric($cat_id) ) :
|
1376 |
-
$out .= ' jQuery(\'#in-category-' . $cat_id . '\').click(function(){if(jQuery(\'#in-category-' . $cat_id . '\').attr(\'checked\') == true) { if(tinyMCEID.length) { for(i=0;i<tinyMCEID.length;i++) {tinyMCE.execCommand(\'mceRemoveControl\', false, tinyMCEID[i]);} tinyMCEID
|
1377 |
if ( $options['custom_field_template_use_autosave'] ) :
|
1378 |
-
$out .= 'var fields = jQuery(\'#cft :input\').fieldSerialize();';
|
1379 |
$out .= 'jQuery.ajax({type: \'POST\', url: \'?page=custom-field-template/custom-field-template.php&cft_mode=ajaxsave&post=\'+jQuery(\'#post_ID\').val()+\'&custom-field-template-verify-key=\'+jQuery(\'#custom-field-template-verify-key\').val()+\'&\'+fields, success: function(){jQuery(\'#custom_field_template_select\').val(\'' . $key . '\');jQuery.ajax({type: \'GET\', url: \'?page=custom-field-template/custom-field-template.php&cft_mode=ajaxload&id=' . $key . '&post=\'+jQuery(\'#post_ID\').val(), success: function(html) {';
|
1380 |
if ( $options['custom_field_template_replace_the_title'] ) :
|
1381 |
$out .= 'jQuery(\'#cftdiv h3 span\').text(\'' . $options['custom_fields'][$key]['title'] . '\');';
|
@@ -1441,8 +1452,8 @@ jQuery("#edButtonPreview").trigger("click"); }' . "\n";
|
|
1441 |
endif;
|
1442 |
}
|
1443 |
$out .= '</select> ';
|
1444 |
-
$out .= '<input type="button" class="button" value="' . __('Load', 'custom-field-template') . '" onclick="if(tinyMCEID.length) { for(i=0;i<tinyMCEID.length;i++) {tinyMCE.execCommand(\'mceRemoveControl\', false, tinyMCEID[i]);} tinyMCEID
|
1445 |
-
$out .= 'var cftloading_select = function() {jQuery.ajax({type: \'GET\', url: \'?page=custom-field-template/custom-field-template.php&cft_mode=ajaxload&id=\'+jQuery(\'#custom_field_template_select\').val()+\'&post=\'+jQuery(\'#post_ID\').val(), success: function(html) {';
|
1446 |
if ( $options['custom_field_template_replace_the_title'] ) :
|
1447 |
$out .= 'jQuery(\'#cftdiv h3 span\').text(jQuery(\'#custom_field_template_select :selected\').text());';
|
1448 |
endif;
|
@@ -1530,8 +1541,12 @@ jQuery("#edButtonPreview").trigger("click"); }' . "\n";
|
|
1530 |
if ( is_numeric($data[$i]['editCode']) ) :
|
1531 |
eval(stripcslashes($options['php'][$data[$i]['editCode']]));
|
1532 |
endif;
|
1533 |
-
|
|
|
1534 |
if ( $data[$i]['insertTag'] == true ) $tags_input[] = $value;
|
|
|
|
|
|
|
1535 |
|
1536 |
if ( $_REQUEST['TinyMCE_' . $name . trim($_REQUEST[ $name."_rand" ][$i]) . '_size'] ) {
|
1537 |
preg_match('/cw=[0-9]+&ch=([0-9]+)/', $_REQUEST['TinyMCE_' . $name . trim($_REQUEST[ $name."_rand" ][$i]) . '_size'], $matched);
|
@@ -1637,6 +1652,8 @@ jQuery("#edButtonPreview").trigger("click"); }' . "\n";
|
|
1637 |
$Data[$title][$key]["level"] = $val["level"];
|
1638 |
if ( $val["insertTag"] == true )
|
1639 |
$Data[$title][$key]["insertTag"] = true;
|
|
|
|
|
1640 |
if ( $val["output"] == true )
|
1641 |
$Data[$title][$key]["output"] = true;
|
1642 |
$key++;
|
@@ -1775,7 +1792,7 @@ jQuery("#edButtonPreview").trigger("click"); }' . "\n";
|
|
1775 |
|
1776 |
if ( is_numeric($format) && $output = $options['shortcode_format'][$format] ) :
|
1777 |
$output = stripcslashes($output);
|
1778 |
-
$output = '<form method="get" action="/" id="cftsearch">' . "\n" . $output;
|
1779 |
|
1780 |
$count = count($options['custom_fields']);
|
1781 |
if ( $count ) :
|
@@ -1801,12 +1818,15 @@ jQuery("#edButtonPreview").trigger("click"); }' . "\n";
|
|
1801 |
|
1802 |
foreach( $replace as $rkey => $rval ) :
|
1803 |
$replace_val[$rkey] = "";
|
|
|
1804 |
switch ( $rval[0]['type'] ) :
|
1805 |
case 'text':
|
1806 |
case 'textarea':
|
1807 |
-
$
|
|
|
1808 |
break;
|
1809 |
case 'checkbox':
|
|
|
1810 |
$values = $valueLabels = array();
|
1811 |
if ( $rkey == 0 ) :
|
1812 |
foreach( $rval as $rval2 ) :
|
@@ -1821,19 +1841,20 @@ jQuery("#edButtonPreview").trigger("click"); }' . "\n";
|
|
1821 |
$replace_val[$rkey] .= '<ul>';
|
1822 |
$j=0;
|
1823 |
foreach( $values as $metavalue ) :
|
1824 |
-
$replace_val[$rkey] .= '<li><input type="checkbox" name="cftsearch[' . urlencode($key) . '][' . $rkey . '][]" value="' . attribute_escape($metavalue) . '" /> ';
|
1825 |
if ( $valueLabels[$j] ) $replace_val[$rkey] .= stripcslashes($valueLabels[$j]);
|
1826 |
else $replace_val[$rkey] .= stripcslashes($metavalue);
|
1827 |
$replace_val[$rkey] .= '</li>';
|
1828 |
$j++;
|
1829 |
endforeach;
|
1830 |
else :
|
1831 |
-
$replace_val[$rkey] .= '<input type="checkbox" name="cftsearch[' . urlencode($key) . '][' . $rkey . '][]" value="' . attribute_escape(trim($values[0])) . '" /> ';
|
1832 |
if ( $valueLabel[0] ) $replace_val[$rkey] .= stripcslashes(trim($valueLabels[0]));
|
1833 |
else $replace_val[$rkey] .= stripcslashes(trim($values[0]));
|
1834 |
endif;
|
1835 |
break;
|
1836 |
case 'radio':
|
|
|
1837 |
$values = explode( '#', $rval[0]['value'] );
|
1838 |
$valueLabels = explode( '#', $rval[0]['valueLabel'] );
|
1839 |
if ( count($values) > 1 ) :
|
@@ -1841,22 +1862,23 @@ jQuery("#edButtonPreview").trigger("click"); }' . "\n";
|
|
1841 |
$j=0;
|
1842 |
foreach ( $values as $metaval ) :
|
1843 |
$metaval = trim($metaval);
|
1844 |
-
$replace_val[$rkey] .= '<li><input type="radio" name="cftsearch[' . urlencode($key) . '][' . $rkey . '][]" value="' . attribute_escape($metaval) . '" /> ';
|
1845 |
if ( $valueLabels[$j] ) $replace_val[$rkey] .= stripcslashes(trim($valueLabels[$j]));
|
1846 |
else $replace_val[$rkey] .= stripcslashes($metaval);
|
1847 |
$replace_val[$rkey] .= '</li>';
|
1848 |
$j++;
|
1849 |
endforeach;
|
1850 |
else :
|
1851 |
-
$replace_val[$rkey] .= '<input type="radio" name="cftsearch[' . urlencode($key) . '][]" value="' . attribute_escape(trim($values[0])) . '" /> ';
|
1852 |
if ( $valueLabels[0] ) $replace_val[$rkey] .= stripcslashes(trim($valueLabels[0]));
|
1853 |
else $replace_val[$rkey] .= stripcslashes(trim($values[0]));
|
1854 |
endif;
|
1855 |
break;
|
1856 |
case 'select':
|
|
|
1857 |
$values = explode( '#', $rval[0]['value'] );
|
1858 |
$valueLabels = explode( '#', $rval[0]['valueLabel'] );
|
1859 |
-
$replace_val[$rkey] .= '<select name="cftsearch[' . urlencode($key) . '][' . $rkey . '][]">';
|
1860 |
$replace_val[$rkey] .= '<option value=""></option>';
|
1861 |
$j=0;
|
1862 |
foreach ( $values as $metaval ) :
|
@@ -1885,7 +1907,8 @@ jQuery("#edButtonPreview").trigger("click"); }' . "\n";
|
|
1885 |
endfor;
|
1886 |
endif;
|
1887 |
|
1888 |
-
$output .= '<p><input type="submit"
|
|
|
1889 |
$output .= '</form>' . "\n";
|
1890 |
else :
|
1891 |
$fields = $this->get_custom_fields( $template );
|
@@ -1893,7 +1916,7 @@ jQuery("#edButtonPreview").trigger("click"); }' . "\n";
|
|
1893 |
if ( $fields == null )
|
1894 |
return;
|
1895 |
|
1896 |
-
$output = '<form method="get" action="/" id="cftsearch">' . "\n";
|
1897 |
foreach( $fields as $key => $val) :
|
1898 |
if ( $val[0]['search'] == true ) :
|
1899 |
if ( !empty($val[0]['label']) && $options['custom_field_template_replace_keys_by_labels'] )
|
@@ -1901,13 +1924,16 @@ jQuery("#edButtonPreview").trigger("click"); }' . "\n";
|
|
1901 |
$output .= '<dl>' ."\n";
|
1902 |
$output .= '<dt><label>' . $key . '</label></dt>' ."\n";
|
1903 |
foreach ( $val as $key2 => $val2 ) :
|
|
|
1904 |
switch ( $val2['type'] ) :
|
1905 |
case 'text':
|
1906 |
case 'textarea':
|
1907 |
-
|
|
|
1908 |
break;
|
1909 |
case 'checkbox':
|
1910 |
-
|
|
|
1911 |
if ( $val2['valueLabel'] )
|
1912 |
$output .= stripcslashes($val2['valueLabel']);
|
1913 |
else
|
@@ -1915,12 +1941,13 @@ jQuery("#edButtonPreview").trigger("click"); }' . "\n";
|
|
1915 |
$output .= '</dd>' . "\n";
|
1916 |
break;
|
1917 |
case 'radio':
|
|
|
1918 |
$values = explode( '#', $val2['value'] );
|
1919 |
$valueLabels = explode( '#', $val2['valueLabel'] );
|
1920 |
$i=0;
|
1921 |
foreach ( $values as $metaval ) :
|
1922 |
$metaval = trim($metaval);
|
1923 |
-
$output .= '<dd>' . '<input type="radio" name="cftsearch[' . urlencode($key) . '][' . $rkey . '][]" value="' . attribute_escape($metaval) . '" /> ';
|
1924 |
if ( $val2['valueLabel'] )
|
1925 |
$output .= stripcslashes(trim($valueLabels[$i]));
|
1926 |
else
|
@@ -1930,9 +1957,10 @@ jQuery("#edButtonPreview").trigger("click"); }' . "\n";
|
|
1930 |
endforeach;
|
1931 |
break;
|
1932 |
case 'select':
|
|
|
1933 |
$values = explode( '#', $val2['value'] );
|
1934 |
$valueLabels = explode( '#', $val2['valueLabel'] );
|
1935 |
-
$output .= '<dd><select name="cftsearch[' . urlencode($key) . '][' . $rkey . '][]">';
|
1936 |
$output .= '<option value=""></option>';
|
1937 |
$i=0;
|
1938 |
foreach ( $values as $metaval ) :
|
@@ -1954,7 +1982,8 @@ jQuery("#edButtonPreview").trigger("click"); }' . "\n";
|
|
1954 |
$output .= '</dl>' ."\n";
|
1955 |
endif;
|
1956 |
endforeach;
|
1957 |
-
$output .= '<p><input type="submit"
|
|
|
1958 |
$output .= '</form>' . "\n";
|
1959 |
endif;
|
1960 |
|
@@ -2026,9 +2055,25 @@ jQuery("#edButtonPreview").trigger("click"); }' . "\n";
|
|
2026 |
endif;
|
2027 |
$where .= " AND " . $wpdb->posts . ".post_type = 'post'";
|
2028 |
endif;
|
2029 |
-
|
2030 |
return $where;
|
2031 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2032 |
|
2033 |
function EvalBuffer($string) {
|
2034 |
ob_start();
|
@@ -2037,6 +2082,25 @@ jQuery("#edButtonPreview").trigger("click"); }' . "\n";
|
|
2037 |
ob_end_clean();
|
2038 |
return $ret;
|
2039 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2040 |
}
|
2041 |
|
2042 |
$custom_field_template = new custom_field_template();
|
4 |
Plugin URI: http://wordpressgogo.com/development/custom-field-template.html
|
5 |
Description: This plugin adds the default custom fields on the Write Post/Page.
|
6 |
Author: Hiroaki Miyashita
|
7 |
+
Version: 1.0.6
|
8 |
Author URI: http://wordpressgogo.com/
|
9 |
*/
|
10 |
|
31 |
add_filter( 'the_content', array(&$this, 'custom_field_template_the_content') );
|
32 |
|
33 |
if ( $_REQUEST['cftsearch_submit'] ) :
|
34 |
+
add_filter( 'posts_join', array(&$this, 'custom_field_template_posts_join') );
|
35 |
add_filter( 'posts_where', array(&$this, 'custom_field_template_posts_where') );
|
36 |
+
add_filter( 'posts_orderby', array(&$this, 'custom_field_template_posts_orderby' ) );
|
37 |
endif;
|
38 |
|
39 |
if ( function_exists('add_shortcode') ) :
|
440 |
|
441 |
for ( $i=0; $i<count($options['hook']); $i++ ) :
|
442 |
if ( $options['hook'][$i]['category'] ) :
|
443 |
+
if ( is_category() || is_single() ) :
|
444 |
+
$needle = explode(',', $options['hook'][$i]['category']);
|
445 |
+
foreach ( $needle as $val ) :
|
446 |
+
if ( in_array($val, $cats ) ) :
|
447 |
+
if ( $options['hook'][$i]['position'] == 0 )
|
448 |
+
$content .= $options['hook'][$i]['content'];
|
449 |
+
else
|
450 |
+
$content = $options['hook'][$i]['content'] . $content;
|
451 |
+
break;
|
452 |
+
endif;
|
453 |
+
endforeach;
|
454 |
+
endif;
|
455 |
else :
|
456 |
if ( $options['hook'][$i]['position'] == 0 )
|
457 |
$content .= $options['hook'][$i]['content'];
|
813 |
<tr>
|
814 |
<th>class</th><td>class = text</td><td>class = checkbox</td><td>class = radio</td><td>class = select</td><td>class = textarea</td>
|
815 |
</tr>
|
816 |
+
<tr>
|
817 |
+
<th>valueCount</th><td>valueCount = text</td><td>valueCount = checkbox</td><td>valueCount = radio</td><td>valueCount = select</td><td>valueCount = textarea</td>
|
818 |
+
</tr>
|
819 |
</tbody>
|
820 |
</table>
|
821 |
</div>
|
1211 |
|
1212 |
if ( $fields == null )
|
1213 |
return;
|
1214 |
+
|
1215 |
+
if ( $options['custom_fields'][$id]['category'] && (strstr($_SERVER['REQUEST_URI'], 'wp-admin/page-new.php') || strstr($_SERVER['REQUEST_URI'], 'wp-admin/page.php')) )
|
1216 |
+
return;
|
1217 |
|
1218 |
if ( (!$_REQUEST['post'] || $_REQUEST['post']<0) && $options['custom_fields'][$id]['category'] && $_REQUEST['cft_mode'] != 'ajaxload' )
|
1219 |
return;
|
1232 |
if ( $data[$i]['level'] > $level ) continue;
|
1233 |
endif;
|
1234 |
if( $data[$i]['type'] == 'break' ) {
|
1235 |
+
if ( !empty($data[$i]['class']) ) $class = ' class="' . $data[$i]['class'] . '"';
|
1236 |
+
$out .= '</div><div' . $class . '>';
|
1237 |
}
|
1238 |
else if( $data[$i]['type'] == 'textfield' || $data[$i]['type'] == 'text' ) {
|
1239 |
$out .= $this->make_textfield( $title, $i, $data[$i]['size'], $data[$i]['default'], $data[$i]['hideKey'], $data[$i]['label'], $data[$i]['code'], $data[$i]['class'] );
|
1384 |
$categories = explode(',', $val['category']);
|
1385 |
foreach($categories as $cat_id) :
|
1386 |
if ( is_numeric($cat_id) ) :
|
1387 |
+
$out .= ' jQuery(\'#in-category-' . $cat_id . '\').click(function(){if(jQuery(\'#in-category-' . $cat_id . '\').attr(\'checked\') == true) { if(tinyMCEID.length) { for(i=0;i<tinyMCEID.length;i++) {tinyMCE.execCommand(\'mceRemoveControl\', false, tinyMCEID[i]);} tinyMCEID.length=0;};';
|
1388 |
if ( $options['custom_field_template_use_autosave'] ) :
|
1389 |
+
$out .= ' var fields = jQuery(\'#cft :input\').fieldSerialize();';
|
1390 |
$out .= 'jQuery.ajax({type: \'POST\', url: \'?page=custom-field-template/custom-field-template.php&cft_mode=ajaxsave&post=\'+jQuery(\'#post_ID\').val()+\'&custom-field-template-verify-key=\'+jQuery(\'#custom-field-template-verify-key\').val()+\'&\'+fields, success: function(){jQuery(\'#custom_field_template_select\').val(\'' . $key . '\');jQuery.ajax({type: \'GET\', url: \'?page=custom-field-template/custom-field-template.php&cft_mode=ajaxload&id=' . $key . '&post=\'+jQuery(\'#post_ID\').val(), success: function(html) {';
|
1391 |
if ( $options['custom_field_template_replace_the_title'] ) :
|
1392 |
$out .= 'jQuery(\'#cftdiv h3 span\').text(\'' . $options['custom_fields'][$key]['title'] . '\');';
|
1452 |
endif;
|
1453 |
}
|
1454 |
$out .= '</select> ';
|
1455 |
+
$out .= '<input type="button" class="button" value="' . __('Load', 'custom-field-template') . '" onclick="if(tinyMCEID.length) { for(i=0;i<tinyMCEID.length;i++) {tinyMCE.execCommand(\'mceRemoveControl\', false, tinyMCEID[i]);} tinyMCEID.length=0;};';
|
1456 |
+
$out .= ' var cftloading_select = function() {jQuery.ajax({type: \'GET\', url: \'?page=custom-field-template/custom-field-template.php&cft_mode=ajaxload&id=\'+jQuery(\'#custom_field_template_select\').val()+\'&post=\'+jQuery(\'#post_ID\').val(), success: function(html) {';
|
1457 |
if ( $options['custom_field_template_replace_the_title'] ) :
|
1458 |
$out .= 'jQuery(\'#cftdiv h3 span\').text(jQuery(\'#custom_field_template_select :selected\').text());';
|
1459 |
endif;
|
1541 |
if ( is_numeric($data[$i]['editCode']) ) :
|
1542 |
eval(stripcslashes($options['php'][$data[$i]['editCode']]));
|
1543 |
endif;
|
1544 |
+
if ( strlen( $value ) )
|
1545 |
+
add_post_meta( $id, $title, apply_filters('cft_'.urlencode($title), $value) );
|
1546 |
if ( $data[$i]['insertTag'] == true ) $tags_input[] = $value;
|
1547 |
+
if ( $data[$i]['valueCount'] == true ) :
|
1548 |
+
$options['value_count'][$value] = $this->set_value_count($value);
|
1549 |
+
endif;
|
1550 |
|
1551 |
if ( $_REQUEST['TinyMCE_' . $name . trim($_REQUEST[ $name."_rand" ][$i]) . '_size'] ) {
|
1552 |
preg_match('/cw=[0-9]+&ch=([0-9]+)/', $_REQUEST['TinyMCE_' . $name . trim($_REQUEST[ $name."_rand" ][$i]) . '_size'], $matched);
|
1652 |
$Data[$title][$key]["level"] = $val["level"];
|
1653 |
if ( $val["insertTag"] == true )
|
1654 |
$Data[$title][$key]["insertTag"] = true;
|
1655 |
+
if ( $val["valueCount"] == true )
|
1656 |
+
$Data[$title][$key]["valueCount"] = true;
|
1657 |
if ( $val["output"] == true )
|
1658 |
$Data[$title][$key]["output"] = true;
|
1659 |
$key++;
|
1792 |
|
1793 |
if ( is_numeric($format) && $output = $options['shortcode_format'][$format] ) :
|
1794 |
$output = stripcslashes($output);
|
1795 |
+
$output = '<form method="get" action="/" id="cftsearch'.(int)$format.'">' . "\n" . $output;
|
1796 |
|
1797 |
$count = count($options['custom_fields']);
|
1798 |
if ( $count ) :
|
1818 |
|
1819 |
foreach( $replace as $rkey => $rval ) :
|
1820 |
$replace_val[$rkey] = "";
|
1821 |
+
$class = "";
|
1822 |
switch ( $rval[0]['type'] ) :
|
1823 |
case 'text':
|
1824 |
case 'textarea':
|
1825 |
+
if ( $rval[0]['class'] ) $class = ' class="' . $rval[0]['class'] . '"';
|
1826 |
+
$replace_val[$rkey] .= '<input type="text" name="cftsearch[' . urlencode($key) . '][' . $rkey . '][]" value="' . attribute_escape($_REQUEST['cftsearch'][urlencode($key)]) . '"' . $class . ' />';
|
1827 |
break;
|
1828 |
case 'checkbox':
|
1829 |
+
if ( $rval[0]['class'] ) $class = ' class="' . $rval[0]['class'] . '"';
|
1830 |
$values = $valueLabels = array();
|
1831 |
if ( $rkey == 0 ) :
|
1832 |
foreach( $rval as $rval2 ) :
|
1841 |
$replace_val[$rkey] .= '<ul>';
|
1842 |
$j=0;
|
1843 |
foreach( $values as $metavalue ) :
|
1844 |
+
$replace_val[$rkey] .= '<li><input type="checkbox" name="cftsearch[' . urlencode($key) . '][' . $rkey . '][]" value="' . attribute_escape($metavalue) . '"' . $class . ' /> ';
|
1845 |
if ( $valueLabels[$j] ) $replace_val[$rkey] .= stripcslashes($valueLabels[$j]);
|
1846 |
else $replace_val[$rkey] .= stripcslashes($metavalue);
|
1847 |
$replace_val[$rkey] .= '</li>';
|
1848 |
$j++;
|
1849 |
endforeach;
|
1850 |
else :
|
1851 |
+
$replace_val[$rkey] .= '<input type="checkbox" name="cftsearch[' . urlencode($key) . '][' . $rkey . '][]" value="' . attribute_escape(trim($values[0])) . '"' . $class . ' /> ';
|
1852 |
if ( $valueLabel[0] ) $replace_val[$rkey] .= stripcslashes(trim($valueLabels[0]));
|
1853 |
else $replace_val[$rkey] .= stripcslashes(trim($values[0]));
|
1854 |
endif;
|
1855 |
break;
|
1856 |
case 'radio':
|
1857 |
+
if ( $rval[0]['class'] ) $class = ' class="' . $rval[0]['class'] . '"';
|
1858 |
$values = explode( '#', $rval[0]['value'] );
|
1859 |
$valueLabels = explode( '#', $rval[0]['valueLabel'] );
|
1860 |
if ( count($values) > 1 ) :
|
1862 |
$j=0;
|
1863 |
foreach ( $values as $metaval ) :
|
1864 |
$metaval = trim($metaval);
|
1865 |
+
$replace_val[$rkey] .= '<li><input type="radio" name="cftsearch[' . urlencode($key) . '][' . $rkey . '][]" value="' . attribute_escape($metaval) . '"' . $class . ' /> ';
|
1866 |
if ( $valueLabels[$j] ) $replace_val[$rkey] .= stripcslashes(trim($valueLabels[$j]));
|
1867 |
else $replace_val[$rkey] .= stripcslashes($metaval);
|
1868 |
$replace_val[$rkey] .= '</li>';
|
1869 |
$j++;
|
1870 |
endforeach;
|
1871 |
else :
|
1872 |
+
$replace_val[$rkey] .= '<input type="radio" name="cftsearch[' . urlencode($key) . '][]" value="' . attribute_escape(trim($values[0])) . '"' . $class . ' /> ';
|
1873 |
if ( $valueLabels[0] ) $replace_val[$rkey] .= stripcslashes(trim($valueLabels[0]));
|
1874 |
else $replace_val[$rkey] .= stripcslashes(trim($values[0]));
|
1875 |
endif;
|
1876 |
break;
|
1877 |
case 'select':
|
1878 |
+
if ( $rval[0]['class'] ) $class = ' class="' . $rval[0]['class'] . '"';
|
1879 |
$values = explode( '#', $rval[0]['value'] );
|
1880 |
$valueLabels = explode( '#', $rval[0]['valueLabel'] );
|
1881 |
+
$replace_val[$rkey] .= '<select name="cftsearch[' . urlencode($key) . '][' . $rkey . '][]"' . $class . '>';
|
1882 |
$replace_val[$rkey] .= '<option value=""></option>';
|
1883 |
$j=0;
|
1884 |
foreach ( $values as $metaval ) :
|
1907 |
endfor;
|
1908 |
endif;
|
1909 |
|
1910 |
+
$output .= '<p><input type="submit" value="' . $search_label . '" class="cftsearch_submit" /></p>' . "\n";
|
1911 |
+
$output .= '<input type="hidden" name="cftsearch_submit" value="1" /></p>' . "\n";
|
1912 |
$output .= '</form>' . "\n";
|
1913 |
else :
|
1914 |
$fields = $this->get_custom_fields( $template );
|
1916 |
if ( $fields == null )
|
1917 |
return;
|
1918 |
|
1919 |
+
$output = '<form method="get" action="/" id="cftsearch'.(int)$format.'">' . "\n";
|
1920 |
foreach( $fields as $key => $val) :
|
1921 |
if ( $val[0]['search'] == true ) :
|
1922 |
if ( !empty($val[0]['label']) && $options['custom_field_template_replace_keys_by_labels'] )
|
1924 |
$output .= '<dl>' ."\n";
|
1925 |
$output .= '<dt><label>' . $key . '</label></dt>' ."\n";
|
1926 |
foreach ( $val as $key2 => $val2 ) :
|
1927 |
+
$class = "";
|
1928 |
switch ( $val2['type'] ) :
|
1929 |
case 'text':
|
1930 |
case 'textarea':
|
1931 |
+
if ( $val2['class'] ) $class = ' class="' . $val2['class'] . '"';
|
1932 |
+
$output .= '<dd><input type="text" name="cftsearch[' . urlencode($key) . '][' . $rkey . '][]" value="' . attribute_escape($_REQUEST['cftsearch'][urlencode($key)]) . '"' . $class . ' /></dd>';
|
1933 |
break;
|
1934 |
case 'checkbox':
|
1935 |
+
if ( $val2['class'] ) $class = ' class="' . $val2['class'] . '"';
|
1936 |
+
$output .= '<dd><input type="checkbox" name="cftsearch[' . urlencode($key) . '][' . $rkey . '][]" value="' . attribute_escape($val2['value']) . '"' . $class . ' /> ';
|
1937 |
if ( $val2['valueLabel'] )
|
1938 |
$output .= stripcslashes($val2['valueLabel']);
|
1939 |
else
|
1941 |
$output .= '</dd>' . "\n";
|
1942 |
break;
|
1943 |
case 'radio':
|
1944 |
+
if ( $val2['class'] ) $class = ' class="' . $val2['class'] . '"';
|
1945 |
$values = explode( '#', $val2['value'] );
|
1946 |
$valueLabels = explode( '#', $val2['valueLabel'] );
|
1947 |
$i=0;
|
1948 |
foreach ( $values as $metaval ) :
|
1949 |
$metaval = trim($metaval);
|
1950 |
+
$output .= '<dd>' . '<input type="radio" name="cftsearch[' . urlencode($key) . '][' . $rkey . '][]" value="' . attribute_escape($metaval) . '"' . $class . ' /> ';
|
1951 |
if ( $val2['valueLabel'] )
|
1952 |
$output .= stripcslashes(trim($valueLabels[$i]));
|
1953 |
else
|
1957 |
endforeach;
|
1958 |
break;
|
1959 |
case 'select':
|
1960 |
+
if ( $val2['class'] ) $class = ' class="' . $val2['class'] . '"';
|
1961 |
$values = explode( '#', $val2['value'] );
|
1962 |
$valueLabels = explode( '#', $val2['valueLabel'] );
|
1963 |
+
$output .= '<dd><select name="cftsearch[' . urlencode($key) . '][' . $rkey . '][]"' . $class . '>';
|
1964 |
$output .= '<option value=""></option>';
|
1965 |
$i=0;
|
1966 |
foreach ( $values as $metaval ) :
|
1982 |
$output .= '</dl>' ."\n";
|
1983 |
endif;
|
1984 |
endforeach;
|
1985 |
+
$output .= '<p><input type="submit" value="' . $search_label . '" class="cftsearch_submit" /></p>' . "\n";
|
1986 |
+
$output .= '<input type="hidden" name="cftsearch_submit" value="1" /></p>' . "\n";
|
1987 |
$output .= '</form>' . "\n";
|
1988 |
endif;
|
1989 |
|
2055 |
endif;
|
2056 |
$where .= " AND " . $wpdb->posts . ".post_type = 'post'";
|
2057 |
endif;
|
2058 |
+
|
2059 |
return $where;
|
2060 |
}
|
2061 |
+
|
2062 |
+
function custom_field_template_posts_join($sql) {
|
2063 |
+
if ( ($_REQUEST['order'] == 'ASC' || $_REQUEST['order'] == 'DESC') && $_REQUEST['orderby'] ) :
|
2064 |
+
global $wpdb;
|
2065 |
+
|
2066 |
+
$sql = " LEFT JOIN `" . $wpdb->postmeta . "` AS meta ON (`" . $wpdb->posts . "`.ID = meta.post_id AND meta.meta_key = '". $_REQUEST['orderby'] . "')";
|
2067 |
+
return $sql;
|
2068 |
+
endif;
|
2069 |
+
}
|
2070 |
+
|
2071 |
+
function custom_field_template_posts_orderby($sql) {
|
2072 |
+
if ( ($_REQUEST['order'] == 'ASC' || $_REQUEST['order'] == 'DESC') && $_REQUEST['orderby'] ) :
|
2073 |
+
$sql = " meta.meta_value " . $_REQUEST['order'];
|
2074 |
+
return $sql;
|
2075 |
+
endif;
|
2076 |
+
}
|
2077 |
|
2078 |
function EvalBuffer($string) {
|
2079 |
ob_start();
|
2082 |
ob_end_clean();
|
2083 |
return $ret;
|
2084 |
}
|
2085 |
+
|
2086 |
+
function set_value_count($value) {
|
2087 |
+
global $wpdb;
|
2088 |
+
|
2089 |
+
$query = $wpdb->prepare("SELECT COUNT(meta_id) FROM `". $wpdb->postmeta."` WHERE `". $wpdb->postmeta."`.meta_value = %s;", $value);
|
2090 |
+
$count = $wpdb->get_var($query);
|
2091 |
+
|
2092 |
+
return (int)$count;
|
2093 |
+
}
|
2094 |
+
|
2095 |
+
function get_value_count($value = '') {
|
2096 |
+
$options = $this->get_custom_field_template_data();
|
2097 |
+
|
2098 |
+
if ( $value ) :
|
2099 |
+
return $options['value_count'][$value];
|
2100 |
+
else:
|
2101 |
+
return $options['value_count'];
|
2102 |
+
endif;
|
2103 |
+
}
|
2104 |
}
|
2105 |
|
2106 |
$custom_field_template = new custom_field_template();
|
readme.txt
CHANGED
@@ -4,7 +4,7 @@ Donate link: http://wordpressgogo.com/development/custom-field-template.html
|
|
4 |
Tags: custom, fields, field, template, meta, custom field, custom fields, custom field template
|
5 |
Requires at least: 2.1
|
6 |
Tested up to: 2.7.1
|
7 |
-
Stable tag: 1.0.
|
8 |
|
9 |
This plugin adds the default custom fields on the Write Post/Page.
|
10 |
|
4 |
Tags: custom, fields, field, template, meta, custom field, custom fields, custom field template
|
5 |
Requires at least: 2.1
|
6 |
Tested up to: 2.7.1
|
7 |
+
Stable tag: 1.0.6
|
8 |
|
9 |
This plugin adds the default custom fields on the Write Post/Page.
|
10 |
|