Changeset 1056819
- Timestamp:
- 12/30/2014 10:43:46 AM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
opensearchserver-search/trunk/opensearchserver_admin.php
r1045620 r1056819 102 102 } 103 103 } 104 if (isset($custom_fields) && $custom_fields != null) { 105 $custom_fields_array = explode(',', $custom_fields); 106 foreach ($custom_fields_array as $field) { 107 $field = opensearchserver_clean_field($field); 108 if (strlen($field) > 0) { 109 opensearchserver_setField($schema,$schema_xml,'custom_'.$field,NULL,'yes','yes','no','yes','no'); 110 } 111 } 112 } 113 104 //Add custom fields schema 105 $custom_field_lables = opensearchserver_get_all_custom_fields(); 106 foreach($custom_field_lables as $custom_field_label => $key) { 107 $check_custom_field_label = 'oss_custom_field_'.strtolower(str_replace(' ', '_', $custom_field_label)); 108 if(get_option($check_custom_field_label)==1) { 109 opensearchserver_setField($schema,$schema_xml,'custom_field_'.strtolower(str_replace(' ', '_', $custom_field_label)),'TextAnalyzer','yes','yes','no','yes','no'); 110 opensearchserver_setField($schema,$schema_xml,'custom_field_'.strtolower(str_replace(' ', '_', $custom_field_label)).'_notAnalyzed',NULL,'no','yes','yes','yes','no'); 111 } 112 } 114 113 /* 115 114 * action "oss_create_schema" … … 163 162 $query_template->setReturnField('search','taxonomy_'.$taxonomy.'_notAnalyzed'); 164 163 } 164 } 165 $custom_field_lables = opensearchserver_get_all_custom_fields(); 166 foreach($custom_field_lables as $custom_field_label => $key) { 167 $check_custom_field_label = 'oss_custom_field_'.strtolower(str_replace(' ', '_', $custom_field_label)); 168 if(get_option($check_custom_field_label)==1) { 169 $query_template->setReturnField('search','custom_field_'.strtolower(str_replace(' ', '_', $custom_field_label))); 170 $query_template->setReturnField('search','custom_field_'.strtolower(str_replace(' ', '_', $custom_field_label)).'_notAnalyzed'); 171 } 165 172 } 166 173 if (isset($custom_fields) && $custom_fields != null) { … … 452 459 453 460 // Handling custom fields 454 $custom_clean_all=''; 455 if($customFields) { 456 $custom_fields_array = explode(',',$customFields); 457 foreach ($custom_fields_array as $field) { 458 $field = trim($field); 459 $custom_content = ''; 460 $custom_values=get_post_custom_values($field, $post->ID); 461 if(is_array($custom_values)) { 462 foreach ($custom_values as $values) { 463 $custom_content .= $values.' '; 461 $custom_field_lables = opensearchserver_get_all_custom_fields(); 462 foreach($custom_field_lables as $custom_field_label => $key) { 463 $check_custom_field_label = 'oss_custom_field_'.strtolower(str_replace(' ', '_', $custom_field_label)); 464 if(get_option($check_custom_field_label)==1) { 465 $field = trim($custom_field_label); 466 $custom_content = ''; 467 $custom_values=get_post_custom_values($field, $post->ID); 468 if(is_array($custom_values)) { 469 foreach ($custom_values as $values) { 470 $custom_content .= $values.' '; 471 } 472 }else { 473 $custom_content = $custom_values; 464 474 } 465 }else { 466 $custom_content = $custom_values; 467 } 468 $content_br = nl2br($custom_content); 469 $content_clean=str_replace('<br />', ' ', $content_br); 470 $document->newField('custom_'.opensearchserver_clean_field($field), opensearchserver_stripInvalidXml(strip_tags($content_clean))); 471 $custom_clean_all .=' '.$content_clean; 472 } 473 $custom_fields_array = null; 474 } 475 $document->newField('custom_field_'.strtolower(str_replace(' ', '_', $custom_field_label)), $custom_content); 476 $document->newField('custom_field_'.strtolower(str_replace(' ', '_', $custom_field_label)).'_notAnalyzed', $custom_content); 477 } 478 } 479 475 480 // Build all content field 476 481 $all_content = opensearchserver_stripInvalidXml(strip_tags($post->post_title)). ' '.$content; … … 763 768 update_option('oss_taxonomy_'.$taxonomy, $check_taxonomy_name); 764 769 } 770 $custom_field_lables = opensearchserver_get_all_custom_fields(); 771 foreach($custom_field_lables as $custom_field_label => $key) { 772 $check_custom_field_label = 'oss_custom_field_'.strtolower(str_replace(' ', '_', $custom_field_label)); 773 $check_custom_field_value = (int)$_POST[$check_custom_field_label]; 774 update_option($check_custom_field_label, $check_custom_field_value); 775 } 765 776 $oss_enable_autoindexation = isset($_POST['oss_enable_autoindexation']) ? $_POST['oss_enable_autoindexation'] : NULL; 766 777 update_option('oss_enable_autoindexation', (int)$oss_enable_autoindexation); … … 774 785 update_option('oss_enable_translation_wpml', $oss_enable_translation_wpml); 775 786 } 787 function opensearchserver_get_all_custom_fields() { 788 $args = array( 789 'post_status' => array('publish','draft','pending','future'), 790 'post_type' => 'any', 791 'posts_per_page' => -1, 792 ); 793 $allposts = get_posts($args); 794 foreach ( $allposts as $post ) : setup_postdata($post); 795 $post_id = $post->ID; 796 $fields = get_post_custom_keys($post_id); 797 if ($fields) { 798 foreach ($fields as $key => $value) { 799 if ($value[0] != '_') { 800 $custom_fields[$value] = isset($custom_fields[$value]) ? $custom_fields[$value] + 1 : 1; 801 } 802 } 803 } 804 endforeach; wp_reset_postdata(); 805 return $custom_fields; 806 } 807 776 808 777 809 function opensearchserver_is_search_only() { … … 785 817 } 786 818 787 function opensearchserver_admin_set_custom_fields_settings() {788 $oss_custom_field = isset($_POST['oss_custom_field']) ? $_POST['oss_custom_field'] :NULL;789 update_option('oss_custom_field', $oss_custom_field);790 opensearchserver_display_messages('OpenSearchServer Custom Fields Settings have been updated.');791 }792 819 793 820 function opensearchserver_admin_set_reindex() { … … 843 870 } elseif ($action == 'index_settings') { 844 871 opensearchserver_admin_set_index_settings(); 845 } elseif ($action == 'custom_field_settings') {846 opensearchserver_admin_set_custom_fields_settings();847 872 } elseif ($action == 'opensearchserver_reindex') { 848 873 opensearchserver_admin_set_reindex(); … … 1247 1272 ?> 1248 1273 </fieldset> 1274 <fieldset> 1275 <legend>Custom Fields to index</legend> 1276 <?php 1277 $custom_field_lables = opensearchserver_get_all_custom_fields(); 1278 foreach($custom_field_lables as $custom_field_label => $key) { 1279 $check_custom_field_label = 'oss_custom_field_'.strtolower(str_replace(' ', '_', $custom_field_label)); 1280 ?> 1281 <input type="checkbox" name="<?php print $check_custom_field_label;?>" 1282 value="1" <?php checked( 1 == get_option($check_custom_field_label)); ?> id="<?php print $check_custom_field_label;?>"/> <label 1283 for="<?php print $check_custom_field_label;?>"><?php print $custom_field_label;?> </label><br /> 1284 <?php 1285 } 1286 ?> 1287 </fieldset> 1249 1288 <fieldset> 1250 1289 <legend>Auto Indexation </legend> … … 1298 1337 endif; 1299 1338 ?> 1300 <div class="postbox closed" id="fourth"> 1301 <div class="handlediv" title="Click to toggle"> 1302 <br /> 1303 </div> 1304 <h3 class="hndle"> 1305 <span>Custom fields settings </span> 1306 </h3> 1307 <div class="inside"> 1308 <form id="custom_field_settings" name="custom_field_settings" 1309 method="post" action=""> 1310 <p> 1311 <label for="custom_fields_oss">Enter the fields from the Custom 1312 Field Template. Get useful information <a target="_blank" 1313 href="http://wordpress.org/extend/plugins/custom-field-template/">here</a> 1314 </label>:<br /> 1315 <textarea rows="5" cols="80" name="oss_custom_field" 1316 wrap="off"><?php 1317 print stripslashes(get_option('oss_custom_field')); 1318 ?></textarea> 1319 </p> 1320 <p> 1321 <input type="hidden" name="oss_submit" 1322 value="custom_field_settings" /><input type="submit" 1323 name="opensearchserver_submit" 1324 value="Update Custom Fields Settings" class="button-primary" /><br /> 1325 </p> 1326 </form> 1327 </div> 1328 1329 </div> 1330 1331 <?php 1339 <?php 1332 1340 if(!opensearchserver_is_search_only()) : 1333 1341 ?>
Note: See TracChangeset
for help on using the changeset viewer.