-
Notifications
You must be signed in to change notification settings - Fork 36
/
solr-options-page.php
421 lines (371 loc) · 20.1 KB
/
solr-options-page.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
<?php
/*
Copyright (c) 2009 Matt Weber
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
//get the plugin settings
$s4w_settings = s4w_get_option('plugin_s4w_settings');
//get a a list of all the available content types so we render out some options
$post_types = s4w_get_all_post_types();
#set defaults if not initialized
if ($s4w_settings['s4w_solr_initialized'] != 1) {
$options['s4w_index_all_sites'] = 0;
$options['s4w_server']['info']['single']= array('host'=>'localhost','port'=>8983, 'path'=>'/solr');
$options['s4w_server']['info']['master']= array('host'=>'localhost','port'=>8983, 'path'=>'/solr');
$options['s4w_server']['type']['search'] = 'master';
$options['s4w_server']['type']['update'] = 'master';
//by default we index pages and posts, and remove them from index if there status changes.
$options['s4w_content']['index'] = array('page'=>'1', 'post'=>'1');
$options['s4w_content']['delete'] = array('page'=>'1', 'post'=>'1');
$options['s4w_content']['private'] = array('page'=>'1', 'post'=>'1');
$options['s4w_index_pages'] = 1;
$options['s4w_index_posts'] = 1;
$options['s4w_delete_page'] = 1;
$options['s4w_delete_post'] = 1;
$options['s4w_private_page'] = 1;
$options['s4w_private_post'] = 1;
$options['s4w_output_info'] = 1;
$options['s4w_output_pager'] = 1;
$options['s4w_output_facets'] = 1;
$options['s4w_exclude_pages'] = array();
$options['s4w_exclude_pages'] = '';
$options['s4w_num_results'] = 5;
$options['s4w_cat_as_taxo'] = 1;
$options['s4w_solr_initialized'] = 1;
$options['s4w_max_display_tags'] = 10;
$options['s4w_facet_on_categories'] = 1;
$options['s4w_facet_on_taxonomy'] = 1;
$options['s4w_facet_on_tags'] = 1;
$options['s4w_facet_on_author'] = 1;
$options['s4w_facet_on_type'] = 1;
$options['s4w_enable_dym'] = 1;
$options['s4w_index_comments'] = 1;
$options['s4w_connect_type'] = 'solr';
$options['s4w_index_custom_fields'] = array();
$options['s4w_facet_on_custom_fields'] = array();
$options['s4w_index_custom_fields'] = '';
$options['s4w_facet_on_custom_fields'] = '';
//update existing settings from multiple option record to a single array
//if old options exist, update to new system
$delete_option_function = 'delete_option';
if (is_multisite()) {
$indexall = get_site_option('s4w_index_all_sites');
$delete_option_function = 'delete_site_option';
}
//find each of the old options function
//update our new array and delete the record.
foreach($options as $key => $value ) {
if( $existing = get_option($key)) {
$options[$key] = $existing;
$indexall = FALSE;
//run the appropriate delete options function
$delete_option_function($key);
}
}
$s4w_settings = $options;
//save our options array
s4w_update_option($options);
}
wp_reset_vars(array('action'));
# save form settings if we get the update action
# we do saving here instead of using options.php because we need to use
# s4w_update_option instead of update option.
# As it stands we have 27 options instead of making 27 insert calls (which is what update_options does)
# Lets create an array of all our options and save it once.
if ($_POST['action'] == 'update') {
//lets loop through our setting fields $_POST['settings']
foreach ($s4w_settings as $option => $old_value ) {
$value = $_POST['settings'][$option];
switch ($option) {
case 's4w_solr_initialized':
$value = trim($old_value);
break;
case 's4w_server':
//remove empty server entries
$s_value = &$value['info'];
foreach ($s_value as $key => $v) {
//lets rename the array_keys
if(!$v['host']) unset($s_value[$key]);
}
break;
}
if ( !is_array($value) ) $value = trim($value);
$value = stripslashes_deep($value);
$s4w_settings[$option] = $value;
}
// if we are in single server mode set the server types to master
// and configure the master server to the values of the single server
if ($s4w_settings['s4w_connect_type'] =='solr_single'){
$s4w_settings['s4w_server']['info']['master']= $s4w_settings['s4w_server']['info']['single'];
$s4w_settings['s4w_server']['type']['search'] = 'master';
$s4w_settings['s4w_server']['type']['update'] = 'master';
}
// if this is a multi server setup we steal the master settings
// and stuff them into the single server settings in case the user
// decides to change it later
else {
$s4w_settings['s4w_server']['info']['single']= $s4w_settings['s4w_server']['info']['master'];
}
//lets save our options array
s4w_update_option($s4w_settings);
//we need to make call for the options again
//as we need them to come out in an a sanitised format
//otherwise fields that need to run s4w_filter_list2str will come up with nothin
$s4w_settings = s4w_get_option('plugin_s4w_settings');
?>
<div id="message" class="updated fade"><p><strong><?php _e('Success!', 'solr4wp') ?></strong></p></div>
<?php
}
# checks if we need to check the checkbox
function s4w_checkCheckbox( $fieldValue, $option = array(), $field = false) {
$option_value = (is_array($option) && $field)? $option[$field] : $option;
if( $fieldValue == '1' || $option_value == '1'){
echo 'checked="checked"';
}
}
function s4w_checkConnectOption($optionType, $connectType) {
if ( $optionType === $connectType ) {
echo 'checked="checked"';
}
}
# check for any POST settings
if ($_POST['s4w_ping']) {
if (s4w_ping_server()) {
?>
<div id="message" class="updated fade"><p><strong><?php _e('Ping Success!', 'solr4wp') ?></strong></p></div>
<?php
} else {
?>
<div id="message" class="updated fade"><p><strong><?php _e('Ping Failed!', 'solr4wp') ?></strong></p></div>
<?php
}
} else if ($_POST['s4w_deleteall']) {
s4w_delete_all();
?>
<div id="message" class="updated fade"><p><strong><?php _e('All Indexed Pages Deleted!', 'solr4wp') ?></strong></p></div>
<?php
} else if ($_POST['s4w_optimize']) {
s4w_optimize();
?>
<div id="message" class="updated fade"><p><strong><?php _e('Index Optimized!', 'solr4wp') ?></strong></p></div>
<?php
} else if ($_POST['s4w_init_blogs']) {
s4w_copy_config_to_all_blogs();
?>
<div id="message" class="updated fade"><p><strong><?php _e('Solr for Wordpress Configured for All Blogs!', 'solr4wp') ?></strong></p></div>
<?php } ?>
<div class="wrap">
<h2><?php _e('Solr For WordPress', 'solr4wp') ?></h2>
<form method="post" action="options-general.php?page=solr-for-wordpress/solr-for-wordpress.php">
<h3><?php _e('Configure Solr', 'solr4wp') ?></h3>
<div class="solr_admin clearfix">
<div class="solr_adminR">
<div class="solr_adminR2" id="solr_admin_tab2">
<label><?php _e('Solr Host', 'solr4wp') ?></label>
<input name="settings[s4w_server][type][update]" type="hidden" value="master" />
<input name="settings[s4w_server][type][search]" type="hidden" value="master" />
<p><input type="text" name="settings[s4w_server][info][single][host]" value="<?php echo $s4w_settings['s4w_server']['info']['single']['host']?>" /></p>
<label><?php _e('Solr Port', 'solr4wp') ?></label>
<p><input type="text" name="settings[s4w_server][info][single][port]" value="<?php echo $s4w_settings['s4w_server']['info']['single']['port']?>" /></p>
<label><?php _e('Solr Path', 'solr4wp') ?></label>
<p><input type="text" name="settings[s4w_server][info][single][path]" value="<?php echo $s4w_settings['s4w_server']['info']['single']['path']?>" /></p>
</div>
<div class="solr_adminR2" id="solr_admin_tab3">
<table>
<tr>
<?php
//we are working with multiserver setup so lets
//lets provide an extra fields for extra host on the fly by appending an empty array
//this will always give a count of current servers+1
$serv_count = count($s4w_settings['s4w_server']['info']);
$s4w_settings['s4w_server']['info'][$serv_count] = array('host'=>'','port'=>'', 'path'=>'');
foreach ($s4w_settings['s4w_server']['info'] as $server_id => $server) {
if ($server_id == "single")
continue;
//lets set serverIDs
$new_id =(is_numeric($server_id)) ? 'slave_'.$server_id : $server_id ;
?>
<td>
<label><?php _e('ServerID', 'solr4wp') ?>: <strong><?php echo $new_id; ?></strong></label>
<p>Update Server: <input name="settings[s4w_server][type][update]" type="radio" value="<?php echo $new_id?>" <?php s4w_checkConnectOption($s4w_settings['s4w_server']['type']['update'], $new_id); ?> /></p>
<p>Search Server: <input name="settings[s4w_server][type][search]" type="radio" value="<?php echo $new_id?>" <?php s4w_checkConnectOption($s4w_settings['s4w_server']['type']['search'], $new_id); ?> /></p>
<label><?php _e('Solr Host', 'solr4wp') ?></label>
<p><input type="text" name="settings[s4w_server][info][<?php echo $new_id ?>][host]" value="<?php echo $server['host'] ?>" /></p>
<label><?php _e('Solr Port', 'solr4wp') ?></label>
<p><input type="text" name="settings[s4w_server][info][<?php echo $new_id ?>][port]" value="<?php echo $server['port'] ?>" /></p>
<label><?php _e('Solr Path', 'solr4wp') ?></label>
<p><input type="text" name="settings[s4w_server][info][<?php echo $new_id ?>][path]" value="<?php echo $server['path'] ?>" /></p>
</td>
<?php
}
?>
</tr>
</table>
</div>
</div>
<ol>
<li id="solr_admin_tab1_btn" class="solr_admin_tab1">
</li>
<li id="solr_admin_tab2_btn" class="solr_admin_tab2">
<h4><input id="solrconnect_single" name="settings[s4w_connect_type]" type="radio" value="solr_single" <?php s4w_checkConnectOption($s4w_settings['s4w_connect_type'], 'solr_single'); ?> onclick="switch1();" />Single Solr Server</h4>
<ol>
<li>Download, install and configure your own <a href="http://lucene.apache.org/solr/">Apache Solr</a> instance</li>
</ol>
</li>
<li id="solr_admin_tab3_btn" class="solr_admin_tab3">
<h4><input id="solrconnect_separated" name="settings[s4w_connect_type]" type="radio" value="solr_separated" <?php s4w_checkConnectOption($s4w_settings['s4w_connect_type'], 'solr_separated'); ?> onclick="switch1();" />Separated Solr Servers</h4>
<ol>
<li>Separate URL's for updates and searches.</li>
</ol>
</li>
</ol>
</div>
<hr />
<h3><?php _e('Indexing Options', 'solr4wp') ?></h3>
<table class="form-table">
<?php
foreach ($post_types as $post_key => $post_type) {?>
<tr valign="top">
<th scope="row" style="width:200px;"><?php _e('Index '.ucfirst($post_type), 'solr4wp') ?></th>
<td style="width:10px;float:left;"><input type="checkbox" name="settings[s4w_content][index][<?php echo $post_type?>]" value="1" <?php echo s4w_checkCheckbox(FALSE, $s4w_settings['s4w_content']['index'], $post_type); ?> /></td>
<th scope="row" style="width:200px;"><?php _e('Remove '.ucfirst($post_type).' on Delete', 'solr4wp') ?></th>
<td style="width:10px;float:left;"><input type="checkbox" name="settings[s4w_content][delete][<?php echo $post_type?>]" value="1" <?php echo s4w_checkCheckbox(FALSE, $s4w_settings['s4w_content']['delete'], $post_type); ?> /></td>
<th scope="row" style="width:200px;"><?php _e('Remove '.ucfirst($post_type).' on Status Change', 'solr4wp') ?></th>
<td style="width:10px;float:left;"><input type="checkbox" name="settings[s4w_content][private][<?php echo $post_type?>]" value="1" <?php echo s4w_checkCheckbox(FALSE, $s4w_settings['s4w_content']['private'], $post_type); ?> /></td>
</tr>
<?php }?>
<tr valign="top">
<th scope="row" style="width:200px;"><?php _e('Index Comments', 'solr4wp') ?></th>
<td style="width:10px;float:left;"><input type="checkbox" name="settings[s4w_index_comments]" value="1" <?php echo s4w_checkCheckbox($s4w_settings['s4w_index_comments']); ?> /></td>
</tr>
<?php
//is this a multisite installation
if (is_multisite() && is_main_site()) {
?>
<tr valign="top">
<th scope="row" style="width:200px;"><?php _e('Index all Sites', 'solr4wp') ?></th>
<td style="width:10px;float:left;"><input type="checkbox" name="settings[s4w_index_all_sites]" value="1" <?php echo s4w_checkCheckbox($s4w_settings['s4w_index_all_sites']); ?> /></td>
</tr>
<?php
}
?>
<tr valign="top">
<th scope="row"><?php _e('Index custom fields (comma separated names list)') ?></th>
<td><input type="text" name="settings[s4w_index_custom_fields]" value="<?php print( s4w_filter_list2str($s4w_settings['s4w_index_custom_fields'], 'solr4wp')); ?>" /></td>
</tr>
<tr valign="top">
<th scope="row"><?php _e('Excludes Posts or Pages (comma separated ids list)') ?></th>
<td><input type="text" name="settings[s4w_exclude_pages]" value="<?php print(s4w_filter_list2str($s4w_settings['s4w_exclude_pages'], 'solr4wp')); ?>" /></td>
</tr>
</table>
<hr />
<h3><?php _e('Result Options', 'solr4wp') ?></h3>
<table class="form-table">
<tr valign="top">
<th scope="row" style="width:200px;"><?php _e('Output Result Info', 'solr4wp') ?></th>
<td style="width:10px;float:left;"><input type="checkbox" name="settings[s4w_output_info]" value="1" <?php echo s4w_checkCheckbox($s4w_settings['s4w_output_info']); ?> /></td>
<th scope="row" style="width:200px;float:left;margin-left:20px;"><?php _e('Output Result Pager', 'solr4wp') ?></th>
<td style="width:10px;float:left;"><input type="checkbox" name="settings[s4w_output_pager]" value="1" <?php echo s4w_checkCheckbox($s4w_settings['s4w_output_pager']); ?> /></td>
</tr>
<tr valign="top">
<th scope="row" style="width:200px;"><?php _e('Output Facets', 'solr4wp') ?></th>
<td style="width:10px;float:left;"><input type="checkbox" name="settings[s4w_output_facets]" value="1" <?php echo s4w_checkCheckbox($s4w_settings['s4w_output_facets']); ?> /></td>
<th scope="row" style="width:200px;float:left;margin-left:20px;"><?php _e('Category Facet as Taxonomy', 'solr4wp') ?></th>
<td style="width:10px;float:left;"><input type="checkbox" name="settings[s4w_cat_as_taxo]" value="1" <?php echo s4w_checkCheckbox($s4w_settings['s4w_cat_as_taxo']); ?> /></td>
</tr>
<tr valign="top">
<th scope="row" style="width:200px;"><?php _e('Categories as Facet', 'solr4wp') ?></th>
<td style="width:10px;float:left;"><input type="checkbox" name="settings[s4w_facet_on_categories]" value="1" <?php echo s4w_checkCheckbox($s4w_settings['s4w_facet_on_categories']); ?> /></td>
<th scope="row" style="width:200px;float:left;margin-left:20px;"><?php _e('Tags as Facet', 'solr4wp') ?></th>
<td style="width:10px;float:left;"><input type="checkbox" name="settings[s4w_facet_on_tags]" value="1" <?php echo s4w_checkCheckbox($s4w_settings['s4w_facet_on_tags']); ?> /></td>
</tr>
<tr valign="top">
<th scope="row" style="width:200px;"><?php _e('Author as Facet', 'solr4wp') ?></th>
<td style="width:10px;float:left;"><input type="checkbox" name="settings[s4w_facet_on_author]" value="1" <?php echo s4w_checkCheckbox($s4w_settings['s4w_facet_on_author']); ?> /></td>
<th scope="row" style="width:200px;float:left;margin-left:20px;"><?php _e('Type as Facet', 'solr4wp') ?></th>
<td style="width:10px;float:left;"><input type="checkbox" name="settings[s4w_facet_on_type]" value="1" <?php echo s4w_checkCheckbox($s4w_settings['s4w_facet_on_type']); ?> /></td>
</tr>
<tr valign="top">
<th scope="row" style="width:200px;"><?php _e('Taxonomy as Facet', 'solr4wp') ?></th>
<td style="width:10px;float:left;"><input type="checkbox" name="settings[s4w_facet_on_taxonomy]" value="1" <?php echo s4w_checkCheckbox($s4w_settings['s4w_facet_on_taxonomy']); ?> /></td>
</tr>
<tr valign="top">
<th scope="row"><?php _e('Custom fields as Facet (comma separated ordered names list)') ?></th>
<td><input type="text" name="settings[s4w_facet_on_custom_fields]" value="<?php print( s4w_filter_list2str($s4w_settings['s4w_facet_on_custom_fields'], 'solr4wp')); ?>" /></td>
</tr>
<tr valign="top">
<th scope="row" style="width:200px;"><?php _e('Enable Spellchecking', 'solr4wp') ?></th>
<td style="width:10px;float:left;"><input type="checkbox" name="settings[s4w_enable_dym]" value="1" <?php echo s4w_checkCheckbox($s4w_settings['s4w_enable_dym']); ?> /></td>
</tr>
<tr valign="top">
<th scope="row"><?php _e('Number of Results Per Page', 'solr4wp') ?></th>
<td><input type="text" name="settings[s4w_num_results]" value="<?php _e($s4w_settings['s4w_num_results'], 'solr4wp'); ?>" /></td>
</tr>
<tr valign="top">
<th scope="row"><?php _e('Max Number of Tags to Display', 'solr4wp') ?></th>
<td><input type="text" name="settings[s4w_max_display_tags]" value="<?php _e($s4w_settings['s4w_max_display_tags'], 'solr4wp'); ?>" /></td>
</tr>
</table>
<hr />
<?php settings_fields('s4w-options-group'); ?>
<p class="submit">
<input type="hidden" name="action" value="update" />
<input id="settingsbutton" type="submit" class="button-primary" value="<?php _e('Save Changes', 'solr4wp') ?>" />
</p>
</form>
<hr />
<form method="post" action="options-general.php?page=solr-for-wordpress/solr-for-wordpress.php">
<h3><?php _e('Actions', 'solr4wp') ?></h3>
<table class="form-table">
<tr valign="top">
<th scope="row"><?php _e('Check Server Settings', 'solr4wp') ?></th>
<td><input type="submit" class="button-primary" name="s4w_ping" value="<?php _e('Execute', 'solr4wp') ?>" /></td>
</tr>
<?php if(is_multisite()) { ?>
<tr valign="top">
<th scope="row"><?php _e('Push Solr Configuration to All Blogs', 'solr4wp') ?></th>
<td><input type="submit" class="button-primary" name="s4w_init_blogs" value="<?php _e('Execute', 'solr4wp') ?>" /></td>
</tr>
<?php } ?>
<?php foreach ($post_types as $post_key => $post_type) {
if ($s4w_settings['s4w_content']['index'][$post_type]==1) {
?>
<tr valign="top">
<th scope="row"><?php _e('Index all '.ucfirst($post_type), 'solr4wp') ?></th>
<td><input type="submit" class="button-primary content_load" name="s4w_content_load[<?php echo $post_type?>]" value="<?php _e('Execute', 'solr4wp') ?>" /></td>
</tr>
<?php
}
}
if (count($s4w_settings['s4w_content']['index'])>0) {
?>
<tr valign="top">
<th scope="row"><?php _e('Index All Content', 'solr4wp') ?></th>
<td><input type="submit" class="button-primary content_load" name="s4w_content_load[all]" value="<?php _e('Execute', 'solr4wp') ?>" /></td>
</tr>
<?php }?>
<tr valign="top">
<th scope="row"><?php _e('Optimize Index', 'solr4wp') ?></th>
<td><input type="submit" class="button-primary" name="s4w_optimize" value="<?php _e('Execute', 'solr4wp') ?>" /></td>
</tr>
<tr valign="top">
<th scope="row"><?php _e('Delete All', 'solr4wp') ?></th>
<td><input type="submit" class="button-primary" name="s4w_deleteall" value="<?php _e('Execute', 'solr4wp') ?>" /></td>
</tr>
</table>
</form>
</div>