Merged in release/release-1.09 (pull request #10)

Release/release 1.09

* Install missing plugins 
* rs set to 1

* rebase pantheon for aws

* rebase pantheon for aws

* prod config change

* prod config change

* fix campaing issue

* revert


Approved-by: Jay Sharma
This commit is contained in:
Rachit Bhargava
2023-12-27 20:55:58 +00:00
committed by Jay Sharma
parent 779393381f
commit 22f10a9edd
2154 changed files with 22313 additions and 209875 deletions

View File

@@ -1,190 +0,0 @@
<?php
/**
* /premium/tabs/attachments-tab.php
*
* Prints out the Premium Attachments tab in Relevanssi settings.
*
* @package Relevanssi_Premium
* @author Mikko Saari
* @license https://wordpress.org/about/gpl/ GNU General Public License
* @see https://www.relevanssi.com/
*/
/**
* Prints out the Premium attachments tab in Relevanssi settings.
*/
function relevanssi_attachments_tab() {
$index_post_types = get_option( 'relevanssi_index_post_types' );
$index_pdf_parent = get_option( 'relevanssi_index_pdf_parent' );
global $wpdb;
$read_new_files = '';
$send_pdf_files = '';
$link_pdf_files = '';
$us_selected = '';
$eu_selected = '';
if ( 'on' === get_option( 'relevanssi_read_new_files' ) ) {
$read_new_files = 'checked';
}
if ( 'on' === get_option( 'relevanssi_send_pdf_files' ) ) {
$send_pdf_files = 'checked';
}
if ( 'on' === get_option( 'relevanssi_link_pdf_files' ) ) {
$link_pdf_files = 'checked';
}
if ( 'us' === get_option( 'relevanssi_server_location' ) ) {
$us_selected = 'selected';
}
if ( 'eu' === get_option( 'relevanssi_server_location' ) ) {
$eu_selected = 'selected';
}
$indexing_attachments = false;
if ( in_array( 'attachment', $index_post_types, true ) ) {
$indexing_attachments = true;
}
?>
<div id="attachments_tab">
<table class="form-table" role="presentation">
<tr>
<td>
<input type='button' id='index' value='<?php esc_html_e( 'Read all unread attachments', 'relevanssi' ); ?>' class='button-primary' /><br /><br />
</td>
<td>
<p class="description" id="indexing_button_instructions">
<?php /* translators: the placeholder has the name of the custom field for PDF content */ ?>
<?php printf( esc_html__( 'Clicking the button will read the contents of all the unread attachments files and store the contents to the %s custom field for future indexing. Attachments with errors will be skipped, except for the files with timeout and connection related errors: those will be attempted again.', 'relevanssi' ), '<code>_relevanssi_pdf_content</code>' ); ?>
</p>
<div id='relevanssi-note' style='display: none'></div>
<div id='relevanssi-progress' class='rpi-progress'><div></div></div>
<div id='relevanssi-timer'><?php esc_html_e( 'Time elapsed', 'relevanssi' ); ?>: <span id="relevanssi_elapsed">0:00:00</span> | <?php esc_html_e( 'Time remaining', 'relevanssi' ); ?>: <span id="relevanssi_estimated"><?php esc_html_e( 'some time', 'relevanssi' ); ?></span></div>
<label for="relevanssi_results" class="screen-reader-text"><?php esc_html_e( 'Results', 'relevanssi' ); ?></label>
<textarea id='relevanssi_results' rows='10' cols='80'></textarea>
</td>
</tr>
<tr>
<th scope="row"><?php esc_html_e( 'State of the attachments', 'relevanssi' ); ?></td>
<?php
$pdf_count = wp_cache_get( 'relevanssi_pdf_count' );
if ( false === $pdf_count ) {
$pdf_count = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->postmeta WHERE meta_key = '_relevanssi_pdf_content' AND meta_value != ''" );
wp_cache_set( 'relevanssi_pdf_count', $pdf_count );
}
$pdf_error_count = wp_cache_get( 'relevanssi_pdf_error_count' );
if ( false === $pdf_error_count ) {
$pdf_error_count = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->postmeta WHERE meta_key = '_relevanssi_pdf_error' AND meta_value != ''" );
wp_cache_set( 'relevanssi_pdf_error_count', $pdf_error_count );
}
?>
<td id="stateofthepdfindex">
<p><?php echo esc_html( $pdf_count ); ?> <?php echo esc_html( _n( 'document has read attachment content.', 'documents have read attachment content.', $pdf_count, 'relevanssi' ) ); ?></p>
<p><?php echo esc_html( $pdf_error_count ); ?> <?php echo esc_html( _n( 'document has an attachment reading error.', 'documents have attachment reading errors.', $pdf_error_count, 'relevanssi' ) ); ?>
<?php if ( $pdf_error_count > 0 ) : ?>
<span id="relevanssi_show_pdf_errors"><?php esc_html_e( 'Show errors', 'relevanssi' ); ?></span>.
<?php endif; ?></p>
<label for="relevanssi_pdf_errors" class="screen-reader-text"><?php esc_html_e( 'Attachment reading errors', 'relevanssi' ); ?></label>
<textarea id="relevanssi_pdf_errors" rows="4" cols="120"></textarea>
</td>
</tr>
<tr>
<th scope="row"><label for="relevanssi_server_location"><?php esc_html_e( 'Server location', 'relevanssi' ); ?></label></th>
<td>
<select name="relevanssi_server_location" id="relevanssi_server_location">
<option value="us" <?php echo esc_html( $us_selected ); ?>><?php esc_html_e( 'United States', 'relevanssi' ); ?></option>
<option value="eu" <?php echo esc_html( $eu_selected ); ?>><?php esc_html_e( 'European Union', 'relevanssi' ); ?></option>
</select>
</td>
</tr>
<tr>
<th scope="row"><?php esc_html_e( 'Reset attachment content', 'relevanssi' ); ?></td>
<td>
<input type="button" id="reset" value="<?php esc_html_e( 'Reset all attachment data from posts', 'relevanssi' ); ?>" class="button-primary" />
<?php /* translators: the placeholders are the names of the custom fields */ ?>
<p class="description"><?php printf( esc_html__( "This will remove all %1\$s and %2\$s custom fields from all posts. If you want to reread all attachment files, use this to clean up; clicking the reading button doesn't wipe the slate clean like it does in regular indexing.", 'relevanssi' ), '<code>_relevanssi_pdf_content</code>', '<code>_relevanssi_pdf_error</code>' ); ?></p>
<p class="description"><?php esc_html_e( 'If you have posts where you have modified the attachment content after reading it, this will leave those posts untouched.', 'relevanssi' ); ?></p>
</td>
</tr>
<tr>
<th scope="row">
<?php esc_html_e( 'Read new files', 'relevanssi' ); ?>
</th>
<td>
<fieldset>
<legend class="screen-reader-text"><?php esc_html_e( 'Read new files automatically', 'relevanssi' ); ?></legend>
<label for='relevanssi_read_new_files'>
<input type='checkbox' name='relevanssi_read_new_files' id='relevanssi_read_new_files' <?php echo esc_attr( $read_new_files ); ?> />
<?php esc_html_e( 'Read new files automatically', 'relevanssi' ); ?>
</label>
<p class="description"><?php esc_html_e( 'If this option is enabled, Relevanssi will automatically read the contents of new attachments as they are uploaded. This may cause unexpected delays in uploading posts. If this is not enabled, new attachments are not read automatically and need to be manually read and reindexed.', 'relevanssi' ); ?></p>
</fieldset>
</td>
</tr>
<tr>
<th scope="row">
<?php esc_html_e( 'Upload files', 'relevanssi' ); ?>
</th>
<td>
<fieldset>
<legend class="screen-reader-text"><?php esc_html_e( 'Upload files for reading', 'relevanssi' ); ?></legend>
<label for='relevanssi_send_pdf_files'>
<input type='checkbox' name='relevanssi_send_pdf_files' id='relevanssi_send_pdf_files' <?php echo esc_attr( $send_pdf_files ); ?> />
<?php esc_html_e( 'Upload files for reading', 'relevanssi' ); ?>
</label>
<p class="description"><?php esc_html_e( "By default, Relevanssi only sends a link to the attachment to the attachment reader. If your files are not accessible (for example your site is inside an intranet, password protected, or a local dev site, and the files can't be downloaded if given the URL of the file), check this option to upload the whole file to the reader.", 'relevanssi' ); ?></p>
</fieldset>
</td>
</tr>
<tr>
<th scope="row">
<?php esc_html_e( 'Link to files', 'relevanssi' ); ?>
</th>
<td>
<fieldset>
<legend class="screen-reader-text"><?php esc_html_e( 'Link search results directly to the files', 'relevanssi' ); ?></legend>
<label for='relevanssi_link_pdf_files'>
<input type='checkbox' name='relevanssi_link_pdf_files' id='relevanssi_link_pdf_files' <?php echo esc_attr( $link_pdf_files ); ?> />
<?php esc_html_e( 'Link search results directly to the files', 'relevanssi' ); ?>
</label>
<p class="description"><?php esc_html_e( 'If this option is checked, attachment results in search results will link directly to the file. Otherwise the results will link to the attachment page.', 'relevanssi' ); ?></p>
<?php if ( ! $indexing_attachments ) : ?>
<?php /* translators: the placeholder has name of the post type */ ?>
<p class="important description"><?php printf( esc_html__( "You're not indexing the %s post type, so this setting doesn't have any effect.", 'relevanssi' ), '<code>attachment</code>' ); ?>
<?php endif; ?>
<?php if ( ! $indexing_attachments && ! $index_pdf_parent ) : ?>
<?php /* translators: the placeholder has name of the post type */ ?>
<p class="important description"><?php printf( esc_html__( "You're not indexing the %s post type and haven't connected the files to the parent posts in the indexing settings. You won't be seeing any files in the results.", 'relevanssi' ), '<code>attachment</code>' ); ?>
<?php endif; ?>
</fieldset>
</td>
</tr>
<tr>
<th scope="row"><?php esc_html_e( 'Instructions', 'relevanssi' ); ?></th>
<td>
<?php /* translators: placeholder has the name of the custom field */ ?>
<p><?php printf( esc_html__( 'When Relevanssi reads attachment content, the text is extracted and saved in the %s custom field for the attachment post. This alone does not add the attachment content in the Relevanssi index; it just makes the contents of the attachments easily available for the regular Relevanssi indexing process.', 'relevanssi' ), '<code>_relevanssi_pdf_content</code>' ); ?></p>
<?php /* translators: placeholder has the name of the post type */ ?>
<p><?php printf( esc_html__( 'There are two ways to index the attachment content. If you choose to index the %s post type, Relevanssi will show the attachment posts in the results.', 'relevanssi' ), '<code>attachment</code>' ); ?></p>
<p><?php esc_html_e( "You can also choose to index the attachment content for the parent post, in which case Relevanssi will show the parent post in the results (this setting can be found on the indexing settings). Obviously this does not find the content in attachments that are not attached to another post  if you just upload a file to the WordPress Media Library, it is not attached and won't be found unless you index the attachment posts.", 'relevanssi' ); ?></p>
<p><?php esc_html_e( "If you need to reread a file, you can do read individual files from Media Library. Choose an attachment and click 'Edit more details' to read the content.", 'relevanssi' ); ?></p>
</td>
</tr>
<tr>
<th scope="row"><?php esc_html_e( 'Key not valid?', 'relevanssi' ); ?></th>
<td>
<p><?php esc_html_e( "Are you a new Relevanssi customer and seeing 'Key xxxxxx is not valid' error messages? New API keys are delivered to the server once per hour, so if try again an hour later, the key should work.", 'relevanssi' ); ?></p>
<p><?php esc_html_e( "A 'Key 0 is not valid' error message means you're on a multisite, but have only entered the API key in the subsite settings. Set the API key in the network settings to fix that.", 'relevanssi' ); ?></p>
</td>
</tr>
<tr>
<th scope="row"><?php esc_html_e( 'Important!', 'relevanssi' ); ?></th>
<td>
<p><?php esc_html_e( "In order to read the contents of the files, the files are sent over to Relevanssiservices.com, a processing service hosted on a Digital Ocean Droplet. There are two servers: one in the US and another in the EU. The service creates a working copy of the files. The copy is removed after the file has been processed, but there are no guarantees that someone with an access to the server couldn't see the files. Do not read files with confidential information in them. In order to block individual files from reading, use the Relevanssi post controls on attachment edit page to exclude attachment posts from indexing.", 'relevanssi' ); ?></p>
</td>
</tr>
</table>
</div>
<?php
}

View File

@@ -1,167 +0,0 @@
<?php
/**
* /premium/tabs/import-export-tab.php
*
* Prints out the Premium import/export tab in Relevanssi settings.
*
* @package Relevanssi_Premium
* @author Mikko Saari
* @license https://wordpress.org/about/gpl/ GNU General Public License
* @see https://www.relevanssi.com/
*/
/**
* Prints out the Premium import/export tab in Relevanssi settings.
*/
function relevanssi_import_export_tab() {
$serialized_options = relevanssi_serialize_options();
?>
<h2 id="options"><?php esc_html_e( 'Import or export options', 'relevanssi' ); ?></h2>
<p><?php esc_html_e( 'Here you find the current Relevanssi Premium options in a text format. Copy the contents of the text field to make a backup of your settings. You can also paste new settings here to change all settings at the same time. This is useful if you have default settings you want to use on every system.', 'relevanssi' ); ?></p>
<table class="form-table" role="presentation">
<tr>
<th scope="row"><label for="relevanssi_settings"><?php esc_html_e( 'Current Settings', 'relevanssi' ); ?></label></th>
<td>
<p>
<textarea
id='relevanssi_settings'
name='relevanssi_settings'
rows='4'
cols='80'><?php echo esc_html( $serialized_options ); ?></textarea>
</p>
<input
type='submit'
name='import_options'
id='import_options'
value='<?php esc_html_e( 'Import settings', 'relevanssi' ); ?>'
class='button'
/>
</td>
</tr>
</table>
<p><?php esc_html_e( "Note! Make sure you've got correct settings from a right version of Relevanssi. Settings from a different version of Relevanssi may or may not work and may or may not mess your settings.", 'relevanssi' ); ?></p>
<?php
}
/**
* Collects all Relevanssi options to one array and JSON encodes it.
*
* @return string An array of Relevanssi options converted to JSON.
*/
function relevanssi_serialize_options() {
$serialize_options = array();
$bg_col = get_option( 'relevanssi_bg_col' );
$txt_col = get_option( 'relevanssi_txt_col' );
$index_taxonomies_list = get_option( 'relevanssi_index_taxonomies_list' );
$index_terms = get_option( 'relevanssi_index_terms' );
$txt_col = relevanssi_sanitize_hex_color( $txt_col );
$bg_col = relevanssi_sanitize_hex_color( $bg_col );
if ( empty( $index_post_types ) ) {
$index_post_types = array();
}
if ( empty( $index_taxonomies_list ) ) {
$index_taxonomies_list = array();
}
if ( empty( $index_terms ) ) {
$index_terms = array();
}
$serialize_options['relevanssi_admin_search'] = get_option( 'relevanssi_admin_search' );
$serialize_options['relevanssi_api_key'] = get_option( 'relevanssi_api_key' );
$serialize_options['relevanssi_bg_col'] = $bg_col;
$serialize_options['relevanssi_body_stopwords'] = get_option( 'relevanssi_body_stopwords' );
$serialize_options['relevanssi_cat'] = get_option( 'relevanssi_cat' );
$serialize_options['relevanssi_class'] = get_option( 'relevanssi_class' );
$serialize_options['relevanssi_comment_boost'] = get_option( 'relevanssi_comment_boost' );
$serialize_options['relevanssi_content_boost'] = get_option( 'relevanssi_content_boost' );
$serialize_options['relevanssi_css'] = get_option( 'relevanssi_css' );
$serialize_options['relevanssi_db_version'] = get_option( 'relevanssi_db_version' );
$serialize_options['relevanssi_default_orderby'] = get_option( 'relevanssi_default_orderby' );
$serialize_options['relevanssi_disable_or_fallback'] = get_option( 'relevanssi_disable_or_fallback' );
$serialize_options['relevanssi_disable_shortcodes'] = get_option( 'relevanssi_disable_shortcodes' );
$serialize_options['relevanssi_do_not_call_home'] = get_option( 'relevanssi_do_not_call_home' );
$serialize_options['relevanssi_exact_match_bonus'] = get_option( 'relevanssi_exact_match_bonus' );
$serialize_options['relevanssi_excat'] = get_option( 'relevanssi_excat' );
$serialize_options['relevanssi_excerpt_allowable_tags'] = get_option( 'relevanssi_excerpt_allowable_tags' );
$serialize_options['relevanssi_excerpt_custom_fields'] = get_option( 'relevanssi_excerpt_custom_fields' );
$serialize_options['relevanssi_excerpt_length'] = get_option( 'relevanssi_excerpt_length' );
$serialize_options['relevanssi_excerpt_type'] = get_option( 'relevanssi_excerpt_type' );
$serialize_options['relevanssi_excerpts'] = get_option( 'relevanssi_excerpts' );
$serialize_options['relevanssi_exclude_posts'] = get_option( 'relevanssi_exclude_posts' );
$serialize_options['relevanssi_expand_highlights'] = get_option( 'relevanssi_expand_highlights' );
$serialize_options['relevanssi_expand_shortcodes'] = get_option( 'relevanssi_expand_shortcodes' );
$serialize_options['relevanssi_extag'] = get_option( 'relevanssi_extag' );
$serialize_options['relevanssi_fuzzy'] = get_option( 'relevanssi_fuzzy' );
$serialize_options['relevanssi_hide_branding'] = get_option( 'relevanssi_hide_branding' );
$serialize_options['relevanssi_hide_post_controls'] = get_option( 'relevanssi_hide_post_controls' );
$serialize_options['relevanssi_highlight'] = get_option( 'relevanssi_highlight' );
$serialize_options['relevanssi_highlight_comments'] = get_option( 'relevanssi_highlight_comments' );
$serialize_options['relevanssi_highlight_docs'] = get_option( 'relevanssi_highlight_docs' );
$serialize_options['relevanssi_hilite_title'] = get_option( 'relevanssi_hilite_title' );
$serialize_options['relevanssi_implicit_operator'] = get_option( 'relevanssi_implicit_operator' );
$serialize_options['relevanssi_index_author'] = get_option( 'relevanssi_index_author' );
$serialize_options['relevanssi_index_comments'] = get_option( 'relevanssi_index_comments' );
$serialize_options['relevanssi_index_excerpt'] = get_option( 'relevanssi_index_excerpt' );
$serialize_options['relevanssi_index_fields'] = get_option( 'relevanssi_index_fields' );
$serialize_options['relevanssi_index_image_files'] = get_option( 'relevanssi_index_image_files' );
$serialize_options['relevanssi_index_limit'] = get_option( 'relevanssi_index_limit' );
$serialize_options['relevanssi_index_pdf_parent'] = get_option( 'relevanssi_index_pdf_parent' );
$serialize_options['relevanssi_index_post_type_archives'] = get_option( 'relevanssi_index_post_type_archives' );
$serialize_options['relevanssi_index_post_types'] = get_option( 'relevanssi_index_post_types' );
$serialize_options['relevanssi_index_subscribers'] = get_option( 'relevanssi_index_subscribers' );
$serialize_options['relevanssi_index_synonyms'] = get_option( 'relevanssi_index_synonyms' );
$serialize_options['relevanssi_index_taxonomies'] = get_option( 'relevanssi_index_taxonomies' );
$serialize_options['relevanssi_index_taxonomies_list'] = $index_taxonomies_list;
$serialize_options['relevanssi_index_terms'] = $index_terms;
$serialize_options['relevanssi_index_user_fields'] = get_option( 'relevanssi_index_user_fields' );
$serialize_options['relevanssi_index_users'] = get_option( 'relevanssi_index_users' );
$serialize_options['relevanssi_internal_links'] = get_option( 'relevanssi_internal_links' );
$serialize_options['relevanssi_link_boost'] = get_option( 'relevanssi_link_boost' );
$serialize_options['relevanssi_link_pdf_files'] = get_option( 'relevanssi_link_pdf_files' );
$serialize_options['relevanssi_log_queries'] = get_option( 'relevanssi_log_queries' );
$serialize_options['relevanssi_log_queries_with_ip'] = get_option( 'relevanssi_log_queries_with_ip' );
$serialize_options['relevanssi_max_excerpts'] = get_option( 'relevanssi_max_excerpts' );
$serialize_options['relevanssi_min_word_length'] = get_option( 'relevanssi_min_word_length' );
$serialize_options['relevanssi_mysql_columns'] = get_option( 'relevanssi_mysql_columns' );
$serialize_options['relevanssi_omit_from_logs'] = get_option( 'relevanssi_omit_from_logs' );
$serialize_options['relevanssi_polylang_all_languages'] = get_option( 'relevanssi_polylang_all_languages' );
$serialize_options['relevanssi_post_type_ids'] = get_option( 'relevanssi_post_type_ids' );
$serialize_options['relevanssi_post_type_weights'] = get_option( 'relevanssi_post_type_weights' );
$serialize_options['relevanssi_punctuation'] = get_option( 'relevanssi_punctuation' );
$serialize_options['relevanssi_read_new_files'] = get_option( 'relevanssi_read_new_files' );
$serialize_options['relevanssi_recency_bonus'] = get_option( 'relevanssi_recency_bonus' );
$serialize_options['relevanssi_redirects'] = get_option( 'relevanssi_redirects' );
$serialize_options['relevanssi_related_settings'] = get_option( 'relevanssi_related_settings' );
$serialize_options['relevanssi_related_style'] = get_option( 'relevanssi_related_style' );
$serialize_options['relevanssi_respect_exclude'] = get_option( 'relevanssi_respect_exclude' );
$serialize_options['relevanssi_searchblogs'] = get_option( 'relevanssi_searchblogs' );
$serialize_options['relevanssi_searchblogs_all'] = get_option( 'relevanssi_searchblogs_all' );
$serialize_options['relevanssi_send_pdf_files'] = get_option( 'relevanssi_send_pdf_files' );
$serialize_options['relevanssi_seo_noindex'] = get_option( 'relevanssi_seo_noindex' );
$serialize_options['relevanssi_server_location'] = get_option( 'relevanssi_server_location' );
$serialize_options['relevanssi_show_matches'] = get_option( 'relevanssi_show_matches' );
$serialize_options['relevanssi_show_matches_text'] = get_option( 'relevanssi_show_matches_text' );
$serialize_options['relevanssi_show_post_controls'] = get_option( 'relevanssi_show_post_controls' );
$serialize_options['relevanssi_spamblock'] = get_option( 'relevanssi_spamblock' );
$serialize_options['relevanssi_stopwords'] = get_option( 'relevanssi_stopwords' );
$serialize_options['relevanssi_synonyms'] = get_option( 'relevanssi_synonyms' );
$serialize_options['relevanssi_thousand_separator'] = get_option( 'relevanssi_thousand_separator' );
$serialize_options['relevanssi_throttle'] = get_option( 'relevanssi_throttle' );
$serialize_options['relevanssi_throttle_limit'] = get_option( 'relevanssi_throttle_limit' );
$serialize_options['relevanssi_title_boost'] = get_option( 'relevanssi_title_boost' );
$serialize_options['relevanssi_trim_logs'] = get_option( 'relevanssi_trim_logs' );
$serialize_options['relevanssi_txt_col'] = $txt_col;
$serialize_options['relevanssi_update_translations'] = get_option( 'relevanssi_update_translations' );
$serialize_options['relevanssi_wpml_only_current'] = get_option( 'relevanssi_wpml_only_current' );
$serialized_options = wp_json_encode( $serialize_options );
return $serialized_options;
}

View File

@@ -1,157 +0,0 @@
<?php
/**
* /premium/tabs/redirects-tab.php
*
* Prints out the Premium Redirects tab in Relevanssi settings.
*
* @package Relevanssi_Premium
* @author Mikko Saari
* @license https://wordpress.org/about/gpl/ GNU General Public License
* @see https://www.relevanssi.com/
*/
/**
* Prints out the Premium Redirects tab in Relevanssi settings.
*/
function relevanssi_redirects_tab() {
$site_url = site_url();
$redirects = get_option( 'relevanssi_redirects' );
if ( ! isset( $redirects['empty'] ) ) {
$redirects['empty'] = '';
}
if ( ! isset( $redirects['no_terms'] ) ) {
$redirects['no_terms'] = '';
}
?>
<h2 id="options"><?php esc_html_e( 'Redirects', 'relevanssi' ); ?></h2>
<p><?php esc_html_e( 'If you want a particular search to always lead to a specific page, you can use the redirects. Whenever the search query matches a redirect, the search is automatically bypassed and the user is redirected to the target page.', 'relevanssi' ); ?></p>
<p><?php esc_html_e( 'Enter the search term and the target URL, which may be relative to your site home page or an absolute URL. If "Partial match" is checked, the redirect happens if the query word appears anywhere in the search query, even inside a word, so use it with care. If the search query matches multiple redirections, the first one it matches will trigger.', 'relevanssi' ); ?></p>
<p><?php esc_html_e( 'The "Hits" column shows how many times each redirect has been used.', 'relevanssi' ); ?></p>
<table class="form-table" role="presentation">
<tbody>
<tr>
<th scope="row"><label for="redirect_empty_searches"><?php esc_html_e( 'Redirect empty searches', 'relevanssi' ); ?></label></th>
<td><input type="text" id="redirect_empty_searches" name="redirect_empty_searches" size="60" value="<?php echo esc_attr( str_replace( $site_url, '', $redirects['empty'] ) ); ?>" />
<p class="description"><?php esc_html_e( 'Enter an URL here to redirect all searches that find nothing to this URL.', 'relevanssi' ); ?></p></td>
</tr>
<tr>
<th scope="row"><label for="redirect_no_terms"><?php esc_html_e( 'Redirect searches without terms', 'relevanssi' ); ?></label></th>
<td><input type="text" id="redirect_no_terms" name="redirect_no_terms" size="60" value="<?php echo esc_attr( str_replace( $site_url, '', $redirects['no_terms'] ) ); ?>" />
<p class="description"><?php esc_html_e( 'Enter an URL here to redirect all searches without any search terms.', 'relevanssi' ); ?></p></td>
</tr>
</tbody>
</table>
<table class="form-table" id="redirect_table">
<thead>
<tr>
<th><?php esc_html_e( 'Query', 'relevanssi' ); ?></th>
<th><?php esc_html_e( 'Partial match', 'relevanssi' ); ?></th>
<th><?php esc_html_e( 'URL', 'relevanssi' ); ?></th>
<th><?php esc_html_e( 'Hits', 'relevanssi' ); ?></th>
</tr>
</thead>
<tbody>
<?php
if ( ! isset( $redirects[0] ) ) {
?>
<tr class="redirect_table_row" id="row_0">
<td><input type="text" name="query_0" size="60" />
<div class="row-actions">
<span class="copy"><a href="#" class="copy"><?php esc_html_e( 'Copy', 'relevanssi' ); ?></a> |</span>
<span class="delete"><a href="#" class="remove"><?php esc_html_e( 'Remove', 'relevanssi' ); ?></a></span>
</div>
</td>
<td><input type="checkbox" name="partial_0" /></td>
<td><input type="text" name="url_0" size="60" /></td>
<td><input type="hidden" name="hits_0" /><span>0</span></td>
</tbody>
</tr>
<?php
} else {
$row = 0;
foreach ( $redirects as $redirect ) {
if ( ! isset( $redirect['query'] ) ) {
continue;
}
$row_id = esc_attr( $row );
$query = esc_attr( $redirect['query'] );
$partial = '';
if ( $redirect['partial'] ) {
$partial = 'checked="checked"';
}
$url = esc_attr( $redirect['url'] );
$url = str_replace( $site_url, '', $url );
$hits = $redirect['hits'] ?? 0;
// phpcs:disable WordPress.Security.EscapeOutput.OutputNotEscaped ?>
<tr class="redirect_table_row" id="row_<?php echo $row_id; ?>">
<td>
<label
class="screen-reader-text"
for="query_<?php echo $row_id; ?>">
<?php esc_html_e( 'Query string', 'relevanssi' ); ?>
</label>
<input
type="text"
id="query_<?php echo $row_id; ?>"
name="query_<?php echo $row_id; ?>"
size="60"
value="<?php echo $query; ?>" />
<div class="row-actions">
<span class="copy"><a href="#" class="copy"><?php esc_html_e( 'Copy', 'relevanssi' ); ?></a> |</span>
<span class="delete"><a href="#" class="remove"><?php esc_html_e( 'Remove', 'relevanssi' ); ?></a></span>
</div>
</td>
<td>
<label
class="screen-reader-text"
for="partial_<?php echo $row_id; ?>">
<?php esc_html_e( 'Partial match', 'relevanssi' ); ?>
</label>
<input
type="checkbox"
id="partial_<?php echo $row_id; ?>"
name="partial_<?php echo $row_id; ?>"
<?php echo $partial; ?> />
</td>
<td>
<label
class="screen-reader-text"
for="url_<?php echo $row_id; ?>">
<?php esc_html_e( 'Target URL', 'relevanssi' ); ?>
</label>
<input
type="text"
name="url_<?php echo $row_id; ?>"
id="url_<?php echo $row_id; ?>"
size="60"
value="<?php echo $url; ?>" />
</td>
<td>
<input
type="hidden"
name="hits_<?php echo $row_id; ?>"
id="hits_<?php echo $row_id; ?>"
value="<?php echo $hits; ?>" />
<span><?php echo $hits; ?></span>
</td>
</tr>
<?php
$row++;
}
}
?>
</tbody>
</table>
<button type="button" class="secondary" id="add_redirect"><?php esc_html_e( 'Add a redirect', 'relevanssi' ); ?></button>
<p><?php esc_html_e( "Once you're done, remember to click the save button below!", 'relevanssi' ); ?></p>
<?php
}

View File

@@ -1,516 +0,0 @@
<?php
/**
* /premium/tabs/related-tab.php
*
* Prints out the Premium Related tab in Relevanssi settings.
*
* @package Relevanssi_Premium
* @author Mikko Saari
* @license https://wordpress.org/about/gpl/ GNU General Public License
* @see https://www.relevanssi.com/
*/
/**
* Prints out the Premium Related posts tab in Relevanssi settings.
*/
function relevanssi_related_tab() {
global $relevanssi_variables;
wp_enqueue_media();
add_action( 'admin_footer', 'relevanssi_media_selector_print_scripts' );
$settings = get_option( 'relevanssi_related_settings', array() );
if ( empty( $settings ) ) {
$settings = relevanssi_related_default_settings();
update_option( 'relevanssi_related_settings', $settings );
}
$enabled = $settings['enabled'] ?? 'off';
$append = $settings['append'] ?? '';
$number = $settings['number'] ?? 6;
$months = $settings['months'] ?? 0;
$keyword = $settings['keyword'] ?? 'title';
$restrict = $settings['restrict'] ?? '';
$nothing = $settings['nothing'] ?? 'nothing';
$notenough = $settings['notenough'] ?? 'random';
$post_types = $settings['post_types'] ?? 'post';
$cache_for_admins = $settings['cache_for_admins'] ?? 'off';
$keyword_sources = explode( ',', $keyword );
$restrict_taxos = explode( ',', $restrict );
$nothing_selected = '';
$random_selected = '';
$random_cat_selected = '';
if ( 'nothing' === $nothing ) {
$nothing_selected = 'selected="selected"';
}
if ( 'random' === $nothing ) {
$random_selected = 'selected="selected"';
}
if ( 'random_cat' === $nothing ) {
$random_cat_selected = 'selected="selected"';
}
$dontfillup_selected = '';
$randomfillup_selected = '';
$randomcatfillup_selected = '';
if ( 'nothing' === $notenough ) {
$dontfillup_selected = 'selected="selected"';
}
if ( 'random' === $notenough ) {
$randomfillup_selected = 'selected="selected"';
}
if ( 'random_cat' === $notenough ) {
$randomcatfillup_selected = 'selected="selected"';
}
$append_array = explode( ',', $append );
$post_type_array = explode( ',', $post_types );
$matching_checked = '';
if ( 'matching_post_type' === $post_types ) {
$matching_checked = 'checked="checked"';
}
$enabled = relevanssi_check( $enabled );
$cache_for_admins = relevanssi_check( $cache_for_admins );
$disabled = '';
if ( empty( $enabled ) ) {
$disabled = 'disabled="disabled"';
}
$style = get_option( 'relevanssi_related_style', array() );
$style = array_merge( relevanssi_related_default_styles(), $style );
$width = $style['width'];
$titles = relevanssi_check( $style['titles'] );
$excerpts = relevanssi_check( $style['excerpts'] );
$thumbnails = relevanssi_check( $style['thumbnails'] );
$thumbnail_id = $style['default_thumbnail'];
$display_default_thumbnail = '';
if ( empty( $thumbnails ) ) {
$display_default_thumbnail = 'class="screen-reader-text"';
}
$display_thumbnail_preview = '';
if ( ! $thumbnail_id ) {
$display_thumbnail_preview = 'style="display: none"';
}
?>
<h2 id="options"><?php esc_html_e( 'Related Posts', 'relevanssi' ); ?></h2>
<p><?php esc_html_e( "Relevanssi Related Posts feature shows related posts on posts pages, based on keywords like post title, tags and categories. This feature uses the Relevanssi index to find the best-matching related posts. All results are cached, so your site performance won't suffer.", 'relevanssi' ); ?></p>
<?php // Translators: %s is the WP CLI command. ?>
<p><?php printf( esc_html__( 'A pro tip: you can regenerate related posts for all posts with the WP CLI command %s.', 'relevanssi' ), '<code>wp relevanssi regenerate_related</code>' ); ?></p>
<h3><?php esc_html_e( 'Displaying the related posts', 'relevanssi' ); ?></h3>
<table class="form-table" role="presentation">
<tr>
<th scope="row">
<?php esc_html_e( 'Enable related posts', 'relevanssi' ); ?>
</th>
<td>
<label>
<input type='checkbox' name='relevanssi_related_enabled' id='relevanssi_related_enabled' <?php echo esc_html( $enabled ); ?> />
<?php esc_html_e( 'If this is unchecked, related posts will be completely disabled.', 'relevanssi' ); ?>
</label>
</td>
</tr>
<tr id="tr_relevanssi_related_append">
<th scope="row"><?php esc_html_e( 'Automatically add to these post types', 'relevanssi' ); ?></th>
<td>
<fieldset>
<legend class="screen-reader-text"><?php esc_html_e( 'Automatically add to these post types', 'relevanssi' ); ?></legend>
<?php
$args = array(
'public' => true,
);
$post_types = get_post_types( $args, 'objects' );
foreach ( $post_types as $post_type ) {
$checked = '';
if ( in_array( $post_type->name, $append_array, true ) ) {
$checked = 'checked="checked"';
}
if ( in_array( $post_type->name, relevanssi_get_forbidden_post_types(), true ) ) {
continue;
}
printf(
'<p><label><input type="checkbox" name="relevanssi_related_append[]" value="%1$s" %2$s %4$s>%3$s</label></p>',
esc_attr( $post_type->name ),
$checked, // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
esc_html( $post_type->labels->singular_name ),
$disabled // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
);
}
?>
</fieldset>
<?php // Translators: %1$s is the_content, %2$s is relevanssi_related_priority. ?>
<p class="description"><?php printf( esc_html__( 'The related posts will be automatically displayed for these post types. The element is added using %1$s filter hook with priority 99 (you can adjust that with the %2$s filter hook).', 'relevanssi' ), '<code>the_content</code>', '<code>relevanssi_related_priority</code>' ); ?></p>
<?php // Translators: %1$s is the template function name, %2$s is the shortcode name. ?>
<p class="description"><?php printf( esc_html__( "If you don't choose to display the related posts automatically, you need to add them manually to your template. You can use the template function %1\$s or the shortcode %2\$s to display the related posts.", 'relevanssi' ), '<code>relevanssi_related_posts( $post_id )</code>', '<code>[relevanssi_related_posts]</code>' ); ?></p>
</td>
</tr>
</table>
<h3><?php esc_html_e( 'Choosing the related posts', 'relevanssi' ); ?></h3>
<table class="form-table" role="presentation">
<tr id="tr_relevanssi_related_keyword">
<th scope="row"><?php esc_html_e( 'Keyword sources', 'relevanssi' ); ?></th>
<td>
<fieldset>
<legend class="screen-reader-text"><?php esc_html_e( 'Keyword sources', 'relevanssi' ); ?></legend>
<table>
<tbody>
<?php
$title_object = new stdClass();
$title_object->name = 'title';
$title_object->labels = new stdClass();
$title_object->labels->name = __( 'Title', 'relevanssi' );
$taxos = get_taxonomies( '', 'objects' );
array_unshift( $taxos, $title_object );
$taxonomies_list = array_flip( get_option( 'relevanssi_index_taxonomies_list' ) );
$taxonomies_list['title'] = true;
$not_indexed = array();
foreach ( $taxos as $taxonomy ) {
if ( in_array( $taxonomy->name, relevanssi_get_forbidden_taxonomies(), true ) ) {
continue;
}
if ( ! isset( $taxonomies_list[ $taxonomy->name ] ) ) {
$not_indexed[] = $taxonomy->labels->name;
continue;
}
$checked = '';
if ( in_array( $taxonomy->name, $keyword_sources, true ) ) {
$checked = 'checked="checked"';
}
$restrict_checked = '';
if ( in_array( $taxonomy->name, $restrict_taxos, true ) ) {
$restrict_checked = 'checked="checked"';
}
printf(
'<tr><td style="padding-top: 5px; padding-bottom: 5px"><label><input type="checkbox" name="relevanssi_related_keyword[]" %1$s value="%2$s" %4$s/> %3$s</label><td style="padding-top: 5px; padding-bottom: 5px">',
$checked, // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
esc_attr( $taxonomy->name ),
esc_html( $taxonomy->labels->name ),
$disabled // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
);
if ( 'title' !== $taxonomy->name ) {
printf(
'<label><input type="checkbox" name="relevanssi_related_restrict[]" %1$s value="%2$s" %3$s/> %4$s %5$s</label>',
$restrict_checked, // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
esc_attr( $taxonomy->name ),
$disabled, // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
esc_html__( 'Restrict to taxonomy ', 'relevanssi' ),
esc_html( $taxonomy->labels->name )
);
}
echo '</td></tr>';
}
$not_indexed = implode( ', ', $not_indexed );
?>
</tbody>
</table>
</fieldset>
<p class="description"><?php esc_html_e( "The sources Relevanssi uses for related post keywords. Keywords from these sources are then used to search the Relevanssi index to find related posts. Make sure you choose something, otherwise you won't see results or will see random results. In addition of these sources, you can also define your own keywords for each post from the post edit screen.", 'relevanssi' ); ?></p>
<p class="description"><?php esc_html_e( 'If you choose to restrict to the taxonomy, those keywords will only match in the same category. For example restricted category search terms will only match to category, not to post content. This may lead to better precision, depending on how the taxonomy terms are used.', 'relevanssi' ); ?></p>
<?php
if ( ! empty( $not_indexed ) ) {
?>
<p class="description">
<?php
esc_html_e( "These taxonomies are missing here, because Relevanssi isn't set to index them:", 'relevanssi' );
echo ' ' . esc_html( $not_indexed ) . '.';
?>
</p>
<?php
}
?>
</td>
</tr>
<tr>
<th scope="row"><label for="relevanssi_related_number"><?php esc_html_e( 'Number of posts', 'relevanssi' ); ?></label></th>
<td>
<input type='number' name='relevanssi_related_number' id='relevanssi_related_number' size='4' placeholder='6' value='<?php echo esc_attr( $number ); ?>' <?php echo $disabled; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>/>
<p class="description"><?php esc_html_e( 'The number of related posts to show.', 'relevanssi' ); ?></p>
</td>
</tr>
<tr>
<th scope='row'><label for='relevanssi_related_months'><?php esc_html_e( 'Months to use', 'relevanssi' ); ?></label></th>
<td>
<input type='number' name='relevanssi_related_months' id='relevanssi_related_months' size='4' placeholder='12' value='<?php echo esc_attr( $months ); ?>' <?php echo $disabled; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>/>
<p class="description"><?php esc_html_e( 'Use only posts published within this many months. (For more fine-grained date controls, use filters.)', 'relevanssi' ); ?></p>
</td>
</tr>
<tr id="tr_relevanssi_related_post_types">
<th scope="row"><?php esc_html_e( 'Post types to use', 'relevanssi' ); ?></th>
<td>
<fieldset>
<legend class="screen-reader-text"><?php esc_html_e( 'Post types to use', 'relevanssi' ); ?></legend>
<p>
<label>
<input
type="checkbox"
class="matching"
name="relevanssi_related_post_types[]"
value="matching_post_type"
<?php echo $matching_checked; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
<?php echo $disabled; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
/>
<?php esc_html_e( 'Matching post type', 'relevanssi' ); ?>
<span class="screen-reader-text"><?php esc_html_e( 'Uncheck this option to choose other post types.', 'relevanssi' ); ?></span>
</label>
</p>
<?php
$post_types = get_post_types();
foreach ( $post_types as $type ) {
$post_type = get_post_type_object( $type );
$checked = '';
if ( in_array( $type, $post_type_array, true ) ) {
$checked = 'checked="checked"';
}
$row_disabled = '';
if ( $matching_checked ) {
$row_disabled = 'disabled="disabled"';
}
if ( $disabled ) {
$row_disabled = $disabled;
}
if ( in_array( $type, relevanssi_get_forbidden_post_types(), true ) ) {
continue;
}
printf(
'<p><label><input type="checkbox" class="nonmatching" name="relevanssi_related_post_types[]" value="%1$s" %2$s %3$s>%4$s</label></p>',
esc_attr( $type ),
$checked, // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
$row_disabled, // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
esc_html( $post_type->labels->singular_name )
);
}
?>
</fieldset>
<p class="description"><?php esc_html_e( 'The post types to use for related posts. Matching post type means that for each post type, only posts from the same post type are used for related posts.', 'relevanssi' ); ?></p>
</td>
</tr>
<tr>
<th scope="row"><label for="relevanssi_related_nothing"><?php esc_html_e( 'No related posts found', 'relevanssi' ); ?></label></th>
<td>
<select name="relevanssi_related_nothing" id="relevanssi_related_nothing" <?php echo $disabled; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>>
<option value="nothing" <?php echo esc_html( $nothing_selected ); ?>><?php esc_html_e( 'Show nothing', 'relevanssi' ); ?></option>
<option value="random" <?php echo esc_html( $random_selected ); ?>><?php esc_html_e( 'Random posts', 'relevanssi' ); ?></option>
<option value="random_cat" <?php echo esc_html( $random_cat_selected ); ?>><?php esc_html_e( 'Random posts from same category', 'relevanssi' ); ?></option>
</select>
<p class="description"><?php esc_html_e( 'What to do when no related posts are found? The options are to show nothing and just disable the whole element, or to show random posts (either fully random, or from the same category). Do note that the related posts are cached, so the random posts do not change on every page load.', 'relevanssi' ); ?></p>
</td>
</tr>
<tr>
<th scope="row"><label for="relevanssi_related_notenough"><?php esc_html_e( 'Not enough related posts found', 'relevanssi' ); ?></label></th>
<td>
<select name="relevanssi_related_notenough" id="relevanssi_related_notenough" <?php echo $disabled; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>>
<option value="nothing" <?php echo esc_html( $dontfillup_selected ); ?>><?php esc_html_e( 'Show the found posts', 'relevanssi' ); ?></option>
<option value="random" <?php echo esc_html( $randomfillup_selected ); ?>><?php esc_html_e( 'Fill with random posts', 'relevanssi' ); ?></option>
<option value="random_cat" <?php echo esc_html( $randomcatfillup_selected ); ?>><?php esc_html_e( 'Fill with random posts from same category', 'relevanssi' ); ?></option>
</select>
<p class="description"><?php esc_html_e( 'What to do when not enough related posts are found? The options are to show what was found, or to fill up the display with random posts. Do note that the related posts are cached, so the random posts do not change on every page load.', 'relevanssi' ); ?></p>
</td>
</tr>
</table>
<h3><?php esc_html_e( 'Style options', 'relevanssi' ); ?></h3>
<p><?php esc_html_e( 'When you add the related posts to your site, Relevanssi will use a template to print out the results. These settings control how that template displays the posts. If you need to modify the related posts in a way these settings do not allow, you can always create your own template.', 'relevanssi' ); ?></p>
<p>
<?php
// Translators: %1$s is the default template filename, %2$s is the theme template directory.
printf( esc_html__( "To create your own template, it's best if you begin with the default Relevanssi template, which can be found in the file %1\$s. Copy the template in the %2\$s folder in your theme and make the necessary changes. Relevanssi will then use your template file to display the related posts.", 'relevanssi' ), '<code>' . esc_html( $relevanssi_variables['plugin_dir'] ) . 'premium/templates/relevanssi-related.php</code>', '<code>' . esc_html( get_stylesheet_directory() ) . '/templates/</code>' );
?>
</p>
<table class="form-table" role="presentation">
<tr>
<th scope="row">
<?php esc_html_e( 'Display titles', 'relevanssi' ); ?>
</th>
<td>
<label>
<input type='checkbox' name='relevanssi_related_titles' id='relevanssi_related_titles' <?php echo esc_html( $titles ); ?> <?php echo $disabled; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>/>
<?php esc_html_e( 'Display titles for related posts.', 'relevanssi' ); ?>
</label>
</td>
</tr>
<tr>
<th scope="row">
<?php esc_html_e( 'Display thumbnails', 'relevanssi' ); ?>
</th>
<td>
<label>
<input type='checkbox' name='relevanssi_related_thumbnails' id='relevanssi_related_thumbnails' <?php echo esc_html( $thumbnails ); ?> <?php echo $disabled; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>/>
<?php esc_html_e( 'Display thumbnails for related posts.', 'relevanssi' ); ?>
</label>
<p class="description"><?php esc_html_e( 'If enabled, this will show the featured image for the post if the post has one.', 'relevanssi' ); ?></p>
</td>
</tr>
<tr id="defaultthumbnail" <?php echo $display_default_thumbnail; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>>
<th scope="row">
<?php esc_html_e( 'Default thumbnail', 'relevanssi' ); ?>
</th>
<td>
<div class='image-preview-wrapper' <?php echo $display_thumbnail_preview; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>>
<img id='image-preview' alt="Thumbnail image preview" src='<?php echo esc_attr( wp_get_attachment_url( $thumbnail_id ) ); ?>' width='100' height='100' style='max-height: 100px; width: 100px;'>
</div>
<input id="upload_image_button" type="button" class="button" value="<?php echo esc_attr( __( 'Select image', 'relevanssi' ) ); ?>" <?php echo $disabled; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>/>
<input type='hidden' name='relevanssi_default_thumbnail' id='relevanssi_default_thumbnail' value='<?php echo esc_attr( $thumbnail_id ); ?>'>
<p class="description"><?php esc_html_e( "If a post doesn't have a featured image, this image will be used instead.", 'relevanssi' ); ?></p>
<label>
<input type='checkbox' name='relevanssi_remove_default_thumbnail' <?php echo $disabled; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>/>
<?php esc_html_e( 'Check this post to remove the default thumbnail.', 'relevanssi' ); ?>
</label>
</td>
</tr>
<tr>
<th scope="row">
<?php esc_html_e( 'Display excerpts', 'relevanssi' ); ?>
</th>
<td>
<label >
<input type='checkbox' name='relevanssi_related_excerpts' id='relevanssi_related_excerpts' <?php echo esc_html( $excerpts ); ?> <?php echo $disabled; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>/>
<?php esc_html_e( 'Display excerpts for related posts.', 'relevanssi' ); ?>
</label>
<?php // Translators: name of the filter hook. ?>
<p class="description"><?php printf( esc_html__( 'This uses the manually created post excerpt if one exists, otherwise the beginning of the post is used. Default length is 50 characters, use the %s filter hook to adjust that.', 'relevanssi' ), '<code>relevanssi_related_excerpt_length</code>' ); ?></p>
</td>
</tr>
<tr>
<th scope="row">
<label for="relevanssi_related_width"><?php esc_html_e( 'Minimum width', 'relevanssi' ); ?>
<span class="screen-reader-text"><?php esc_html_e( 'in pixels', 'relevanssi' ); ?></span>
</label>
</th>
<td>
<input type='text' name='relevanssi_related_width' id='relevanssi_related_width' size='4' value='<?php echo esc_attr( $width ); ?>' <?php echo $disabled; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>/> px
<p class="description"><?php esc_html_e( 'The minimum width of the related post element.', 'relevanssi' ); ?></p>
</td>
</tr>
</table>
<h3><?php esc_html_e( 'Caching', 'relevanssi' ); ?></h3>
<p><?php esc_html_e( 'The related posts are cached using WordPress transients. The related posts for each post are stored in a transient that is stored for two weeks. The cache for each post is flushed whenever the post is saved. When a post is made non-public (returned to draft, trashed), Relevanssi automatically flushes all related post caches where that post appears.', 'relevanssi' ); ?></p>
<table class="form-table" role="presentation">
<tr>
<th scope="row">
<?php esc_html_e( 'Use cache for admins', 'relevanssi' ); ?>
</th>
<td>
<label >
<input type='checkbox' name='relevanssi_related_cache_for_admins' id='relevanssi_related_cache_for_admins' <?php echo esc_html( $cache_for_admins ); ?> <?php echo $disabled; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>/>
<?php esc_html_e( 'Use the cache for admin users.', 'relevanssi' ); ?>
</label>
<p class="description"><?php esc_html_e( 'Disable this option when adjusting the settings to see changes on the site.', 'relevanssi' ); ?></p>
</td>
</tr>
<tr>
<th scope="row">
<?php esc_html_e( 'Flush cache', 'relevanssi' ); ?>
</th>
<td>
<label >
<input type='checkbox' name='relevanssi_flush_related_cache' id='relevanssi_flush_related_cache' <?php echo $disabled; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>/>
<?php esc_html_e( 'Flush the caches.', 'relevanssi' ); ?>
</label>
<p class="description"><?php esc_html_e( 'Check this box to flush all related posts caches.', 'relevanssi' ); ?></p>
</td>
</tr>
</table>
<?php
}
/**
* Prints the media selector scripts for the related posts tab.
*
* From: https://jeroensormani.com/how-to-include-the-wordpress-media-selector-in-your-plugin/
* and https://mikejolley.com/2012/12/21/using-the-new-wordpress-3-5-media-uploader-in-plugins/
*
* @author Jeroen Sormani
* @author Mike Jolly
*/
function relevanssi_media_selector_print_scripts() {
$style = get_option( 'relevanssi_related_style', array() );
$style = array_merge( relevanssi_related_default_styles(), $style );
$thumbnail_id = $style['default_thumbnail'];
if ( empty( $thumbnail_id ) ) {
$thumbnail_id = 0;
}
?>
<script type='text/javascript'>
jQuery( document ).ready( function( $ ) {
// Uploading files
var file_frame;
var wp_media_post_id = wp.media.model.settings.post.id; // Store the old id
var set_to_post_id = <?php echo $thumbnail_id; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>;
console.log(set_to_post_id);
jQuery('#upload_image_button').on('click', function( event ){
event.preventDefault();
// If the media frame already exists, reopen it.
if ( file_frame ) {
// Set the post ID to what we want
file_frame.uploader.uploader.param( 'post_id', set_to_post_id );
// Open frame
file_frame.open();
return;
} else {
// Set the wp.media post id so the uploader grabs the ID we want when initialised
wp.media.model.settings.post.id = set_to_post_id;
}
// Create the media frame.
file_frame = wp.media.frames.file_frame = wp.media({
title: 'Select a image to upload',
button: {
text: 'Use this image',
},
multiple: false // Set to true to allow multiple files to be selected
});
// When an image is selected, run a callback.
file_frame.on( 'select', function() {
// We set multiple to false so only get one image from the uploader
attachment = file_frame.state().get('selection').first().toJSON();
// Do something with attachment.id and/or attachment.url here
$( '#image-preview' ).attr( 'src', attachment.url ).css( 'width', 'auto' );
$( '#relevanssi_default_thumbnail' ).val( attachment.id );
// Restore the main post ID
wp.media.model.settings.post.id = wp_media_post_id;
$( '.image-preview-wrapper' ).show();
});
// Finally, open the modal
file_frame.open();
});
// Restore the main ID when the add media button is pressed
jQuery( 'a.add_media' ).on( 'click', function() {
wp.media.model.settings.post.id = wp_media_post_id;
$(".image-preview-wrapper").show();
});
});
</script>
<?php
}

View File

@@ -1,132 +0,0 @@
<?php
/**
* /premium/tabs/spamblock-tab.php
*
* Prints out the Premium Spam Block tab in Relevanssi settings.
*
* @package Relevanssi_Premium
* @author Mikko Saari
* @license https://wordpress.org/about/gpl/ GNU General Public License
* @see https://www.relevanssi.com/
*/
/**
* Prints out the Premium Spam Block tab in Relevanssi settings.
*/
function relevanssi_spamblock_tab() {
$spamblock = get_option( 'relevanssi_spamblock' );
if ( ! isset( $spamblock['keywords'] ) ) {
$spamblock['keywords'] = '';
}
if ( ! isset( $spamblock['regex'] ) ) {
$spamblock['regex'] = '';
}
if ( ! isset( $spamblock['chinese'] ) ) {
$spamblock['chinese'] = '';
}
if ( ! isset( $spamblock['cyrillic'] ) ) {
$spamblock['cyrillic'] = '';
}
if ( ! isset( $spamblock['emoji'] ) ) {
$spamblock['emoji'] = '';
}
if ( ! isset( $spamblock['bots'] ) ) {
$spamblock['bots'] = '';
}
$chinese = relevanssi_check( $spamblock['chinese'] );
$cyrillic = relevanssi_check( $spamblock['cyrillic'] );
$emoji = relevanssi_check( $spamblock['emoji'] );
$bots = relevanssi_check( $spamblock['bots'] );
?>
<h2 id="options"><?php esc_html_e( 'Spam Blocking', 'relevanssi' ); ?></h2>
<p><?php esc_html_e( "These tools can be used to block spam searches on your site. It's best if the spam searches can be blocked earlier on server level before WordPress starts at all, but if that's not possible, this is a fine option.", 'relevanssi' ); ?></p>
<p>
<?php
printf(
// Translators: %1$s is '?s=', %2$s is '/search/', %3$ is the filter hook name and %4$ is 'highlight'.
esc_html__( 'These filters are applied to all searches done using the %1$s parameter, the %2$s pretty URLs (if your pretty URLs are using a different prefix, you can use the %3$s filter hook to adjust the spam block) and also on page views with the %4$s parameter.', 'relevanssi' ),
'<code>?s=</code>',
'<code>/search/</code>',
'<code>relevanssi_search_url_prefix</code>',
'<code>highlight</code>'
);
?>
</p>
<p><?php esc_html_e( "You can figure out the suitable keywords from your User searches page. Look for common terms. Often spam queries contain URLs, and the top level domain names are good keywords, things like '.shop', '.online', '.com' those appear rarely in legitimate searches.", 'relevanssi' ); ?></p>
<table class="form-table" role="presentation">
<tbody>
<tr>
<th scope="row"><label for="relevanssi_spamblock_keywords"><?php esc_html_e( 'Keyword spam blocking', 'relevanssi' ); ?></label></th>
<td><textarea name="relevanssi_spamblock_keywords" id="relevanssi_spamblock_keywords" rows="9" cols="60"><?php echo esc_textarea( $spamblock['keywords'] ); ?></textarea>
<p class="description"><?php esc_html_e( 'Enter keywords, one per line. If these keywords appear anywhere in the search string, the search will be stopped. Use as short keywords as possible, but be careful to avoid blocking legitimate searches. The keywords are case insensitive.', 'relevanssi' ); ?></p></td>
</tr>
<tr>
<th scope="row"><label for="relevanssi_spamblock_regex"><?php esc_html_e( 'Regex keywords', 'relevanssi' ); ?></label></th>
<td><textarea name="relevanssi_spamblock_regex" id="relevanssi_spamblock_regex" rows="9" cols="60"><?php echo esc_textarea( $spamblock['regex'] ); ?></textarea>
<?php // Translators: %1$s is <code>/.../iu</code>. ?>
<p class="description"><?php printf( esc_html__( 'These keywords support the use of regular expressions with preg_match(). The keywords will be wrapped with %1$s.', 'relevanssi' ), '<code>/.../iu</code>' ); ?></p></td>
</tr>
<tr>
<th scope="row"><label for="relevanssi_spamblock_chinese"><?php esc_html_e( 'Block Chinese queries', 'relevanssi' ); ?></label></th>
<td><input type='checkbox' name='relevanssi_spamblock_chinese' id='relevanssi_spamblock_chinese' <?php echo esc_attr( $chinese ); ?> />
<?php esc_html_e( 'Block queries that contain Chinese characters.', 'relevanssi' ); ?>
</tr>
<tr>
<th scope="row"><label for="relevanssi_spamblock_cyrillic"><?php esc_html_e( 'Block Cyrillic queries', 'relevanssi' ); ?></label></th>
<td><input type='checkbox' name='relevanssi_spamblock_cyrillic' id='relevanssi_spamblock_cyrillic' <?php echo esc_attr( $cyrillic ); ?> />
<?php esc_html_e( 'Block queries that contain Cyrillic characters.', 'relevanssi' ); ?>
</tr>
<tr>
<th scope="row"><label for="relevanssi_spamblock_emoji"><?php esc_html_e( 'Block emoji queries', 'relevanssi' ); ?></label></th>
<td><input type='checkbox' name='relevanssi_spamblock_emoji' id='relevanssi_spamblock_emoji' <?php echo esc_attr( $emoji ); ?> />
<?php esc_html_e( 'Block queries that contain emoji characters.', 'relevanssi' ); ?>
</tr>
<tr>
<th scope="row"><label for="relevanssi_spamblock_bots"><?php esc_html_e( 'Block bot queries', 'relevanssi' ); ?></label></th>
<td><input type='checkbox' name='relevanssi_spamblock_bots' id='relevanssi_spamblock_bots' <?php echo esc_attr( $bots ); ?> />
<?php esc_html_e( 'Block queries from bots. Only applied to searches, not to page views with highlights.', 'relevanssi' ); ?>
<p class="description">
<?php
esc_html_e( 'Current list of bots: ', 'relevanssi' );
/**
* Filter documented in /premium/spamblock.php.
*/
echo esc_html( implode( ', ', array_keys( apply_filters( 'relevanssi_bots_to_block', relevanssi_bot_block_list() ) ) ) . '. ' );
// Translators: %1$s is the name of the filter hook.
printf( esc_html__( 'You can add new bots to the list with the filter hook %1$s.', 'relevanssi' ), '<code>relevanssi_bots_to_block</code>' );
?>
</p>
</tr>
</tbody>
</table>
<h3><?php esc_html_e( 'Blocking bots', 'relevanssi' ); ?></h3>
<p><?php esc_html_e( "You can use the Relevanssi spam block to also block requests from bots. In general there's very little reason to allow bots to crawl search results pages. They can create lots of really quite pointless traffic. On one of my sites, out of 20.000 search queries, 16.000 were useless queries by the Bing bot. Nice bots will obey the robots.txt instructions. This code snippet adds robots.txt rules that block rule-obeying bots from accessing search results pages:", 'relevanssi' ); ?></p>
<p><pre>
add_action( 'do_robots', 'rlv_block_bots_robots_txt' );
function rlv_block_bots_robots_txt() {
?&gt;
User-agent: *
Disallow: /search/
Disallow: /?s=
&lt;?php
}
</pre></p>
<h3><?php esc_html_e( 'Blocking at the server level', 'relevanssi' ); ?></h3>
<p><?php esc_html_e( "It's best if the blocking is done before WordPress starts up in the first place: that will increase security and will save server resources. These tools can be used to block bot traffic on your site, but using them requires expertise on server settings. Use them only if you know what you're doing, or have a professional help you.", 'relevanssi' ); ?></p>
<ul>
<li><a href="https://github.com/mitchellkrogza/nginx-ultimate-bad-bot-blocker">NGINX Ultimate Bad Bot & Referrer Blocker</a></li>
<li><a href="https://github.com/mitchellkrogza/apache-ultimate-bad-bot-blocker">Apache Ultimate Bad Bot & Referrer Blocker</a></li>
</ul>
<?php
}

View File

@@ -1,121 +0,0 @@
<?php
/**
* /premium/tabs/support-tab.php
*
* Prints out the Premium Support tab in Relevanssi settings.
*
* @package Relevanssi_Premium
* @author Mikko Saari
* @license https://wordpress.org/about/gpl/ GNU General Public License
* @see https://www.relevanssi.com/
*/
/**
* Prints out the Premium Support tab in Relevanssi settings.
*/
function relevanssi_support_tab() {
global $relevanssi_variables;
if ( isset( $_REQUEST['relevanssi_support_form'] ) ) {
check_admin_referer( 'relevanssi_support_form', 'relevanssi_support_form' );
relevanssi_support_send_email( $_REQUEST );
}
$support_email = $relevanssi_variables['autoupdate']->get_remote_license();
?>
<h2 id="options"><?php esc_html_e( 'Support', 'relevanssi' ); ?></h2>
<?php
if ( ! $support_email ) {
?>
<p><?php echo relevanssi_get_api_key_notification(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></p>
<?php
} else {
?>
<p>
<?php
printf(
// Translators: %1$s opens the link to the support form, %2$s closes the link, %3$s is the support email address.
esc_html__( 'This form sends out an email to the Relevanssi support. If you have a question, please fill in the form below and we will get back to you as soon as possible. If you don\'t hear from us in a day or two, it\'s possible your email has gone astray. In that case, please contact us again and use %1$sthe support form at Relevanssi.com%2$s. You can also email us directly at %3$s. Expect slower response times during June and July.', 'relevanssi' ),
'<a href="https://www.relevanssi.com/support/">',
'</a>',
'<em>' . esc_html( $support_email ) . '</em>'
);
?>
</p>
<p>
<?php
// Translators: %1$s opens the link to the knowledge base, %2$s closes the link.
printf( esc_html__( 'We have a large knowledge base. %1$sTake a look there%2$s, perhaps your question is already answered there.', 'relevanssi' ), '<a href="https://www.relevanssi.com/category/knowledge-base/">', '</a>' );
?>
</p>
<p><?php esc_html_e( 'Instead of telling us "X doesn\'t work", please try be as specific as possible. Please tell us what you expect to happen and what actually happens.', 'relevanssi' ); ?></p>
<p><?php esc_html_e( 'Feel free to ask questions in English or Finnish. Please do not send us video questions.', 'relevanssi' ); ?></p>
<form method="post">
<?php wp_nonce_field( 'relevanssi_support_form', 'relevanssi_support_form' ); ?>
<input type="hidden" name="relevanssi_support_to_email" value="<?php echo esc_attr( $support_email ); ?>" />
<table class="form-table">
<tr>
<th scope="row"><label for="relevanssi_support_email"><?php esc_html_e( 'Your email address', 'relevanssi' ); ?></label></th>
<td><input type="text" name="relevanssi_support_email" id="relevanssi_support_email" value="" size="40" /></td>
</tr>
<tr>
<th scope="row"><label for="relevanssi_support_subject"><?php esc_html_e( 'Subject', 'relevanssi' ); ?></label></th>
<td><input type="text" name="relevanssi_support_subject" id="relevanssi_support_subject" value="" size="40" /></td>
</tr>
<tr>
<th scope="row"><label for="relevanssi_support_message"><?php esc_html_e( 'Message', 'relevanssi' ); ?></label></th>
<td><textarea name="relevanssi_support_message" id="relevanssi_support_message" rows="10" cols="50"></textarea></td>
</tr>
<tr>
<th scope="row"></th>
<td><input type="submit" name="relevanssi_support_submit" id="relevanssi_support_submit" value="<?php esc_attr_e( 'Send', 'relevanssi' ); ?>" class="button button-primary" /></td>
</tr>
</table>
</form>
<?php
}
?>
<?php
}
/**
* Sends out an email to Relevanssi support.
*
* @param array $request The request array.
*/
function relevanssi_support_send_email( $request ) {
global $wp_version, $relevanssi_variables;
$message = $request['relevanssi_support_message'];
$from = 'From: ' . $request['relevanssi_support_email'];
$to = $request['relevanssi_support_to_email'];
$subject = $request['relevanssi_support_subject'];
$message_intro = 'WP version: ' . $wp_version . "\n";
$message_intro .= 'PHP version: ' . phpversion() . "\n";
$message_intro .= 'Relevanssi version: ' . $relevanssi_variables['plugin_version'] . "\n";
$message_intro .= "\n";
$message = $message_intro . stripslashes( $message );
$success = wp_mail( $to, $subject, $message, array( $from ) );
if ( $success ) {
?>
<div id="message" class="updated fade">
<p><?php esc_html_e( 'Email sent!', 'relevanssi' ); ?></p>
</div>
<?php
} else {
?>
<div id="message" class="error">
<p><?php esc_html_e( 'Email failed!', 'relevanssi' ); ?></p>
</div>
<?php
}
}