<?php

if (isset($_POST['myisam_override'])) {
    hw_yarpp_set_option('myisam_override', true);
    $enabled = $hw_yarpp->enable_fulltext();
    if ($enabled) {
        update_option('hw_yarpp_fulltext_disabled', 0);
        echo '<div class="updated" style="padding:5px">' . __('The MyISAM check has been overridden. You may now use the "consider titles" and "consider bodies" relatedness criteria.', 'hw-yarpp') . "</div>";
    } else {
        hw_yarpp_set_option('myisam_override', 0);
        echo '<div class="updated" style="padding:5px">' . '<span style="color:red;font-weight:bold">Fulltext Index creation did not work!</span><br/>' . 'Trying to force fulltext indexing on your table resulted in an error. Your posts table does not have fulltext indexing capabilities.<br/>' . 'The "consider titles" and "consider bodies" relatedness criteria will remain disabled.' . '</div>';
    }
}
$table_type = $hw_yarpp->diagnostic_myisam_posts();
if ((bool) $table_type !== true) {
    $hw_yarpp->disable_fulltext();
}
if (!(bool) hw_yarpp_get_option('myisam_override') && (bool) $hw_yarpp->diagnostic_fulltext_disabled()) {
    echo "<div class='updated' style='padding:15px'>" . '<p>' . '<strong>"Consider Titles"</strong> and <strong>"Consider Bodies"</strong> are currently disabled. ' . 'As a result, "Pages" may not display in the "Related Posts" sections.' . '&nbsp;&nbsp;<a href="#" id="hw_yarpp_fulltext_expand">Show Details [+]</a>' . '</p>' . '<div id="hw_yarpp_fulltext_details" class="hidden">' . '<p>' . sprintf('YARPP&#39;s "consider titles" and "consider bodies" relatedness criteria require your <code>%s</code> ' . 'table to use the <code>MyISAM</code> engine' . 'fulltext indexing feature. Unfortunately your table seems to be using the <code>%s</code> engine. ' . 'Because fulltext indexing is not supported by your current table engine, these two options have been disabled.', $wpdb->posts, $table_type) . '</p>' . '<p>' . sprintf('To restore these features, please do the following:<br/>' . '<ol>' . '<li>' . 'Convert your <code>%s</code> table to <code>MyISAM</code> engine by executing the ' . 'following SQL code on your MySQL client or terminal:<br/>' . '<code style="display:inline-block;margin:1.5em 1em">ALTER TABLE `%s` ENGINE = MyISAM;</code>' . '</li>', $wpdb->posts, $wpdb->posts) . sprintf('<li>' . 'Once your <code>%s</code> table has been successfully converted to the <code>MyISAM</code> engine, ' . 'click the button below to create the fulltext indices.<br/>', $wpdb->posts) . '<form method="post" style="display:inline-block;margin:1.5em 1em">' . "<input type='submit' class='button' name='myisam_override' value='Create fulltext indexes'/>" . "</form>" . '</li>' . '</ol>' . "</p>" . '<p>' . 'Note that, although no data should be lost by altering the table&#39;s engine, it is always recommended to perform a ' . 'full backup of the data before attempting to perform changes to your database.<br/>' . 'See MySQL <a href="http://dev.mysql.com/doc/refman/5.0/en/storage-engines.html" target="_blank">storage engines</a> ' . 'documentation for details on MySQL engines.' . '</p>' . '</div>' . "</div>";
}
                $new_options['require_tax'][$tax] = 2;
            }
        }
    }
    if (isset($_POST['auto_display_post_types'])) {
        $new_options['auto_display_post_types'] = array_keys($_POST['auto_display_post_types']);
    } else {
        $new_options['auto_display_post_types'] = array();
    }
    $new_options['recent'] = isset($_POST['recent_only']) ? $_POST['recent_number'] . ' ' . $_POST['recent_units'] : false;
    if (isset($_POST['exclude'])) {
        $new_options['exclude'] = implode(',', array_keys($_POST['exclude']));
    } else {
        $new_options['exclude'] = '';
    }
    $new_options['template'] = $_POST['use_template'] == 'custom' ? $_POST['template_file'] : ($_POST['use_template'] == 'thumbnails' ? 'thumbnails' : false);
    $new_options['rss_template'] = $_POST['rss_use_template'] == 'custom' ? $_POST['rss_template_file'] : ($_POST['rss_use_template'] == 'thumbnails' ? 'thumbnails' : false);
    $new_options = apply_filters('hw_yarpp_settings_save', $new_options);
    hw_yarpp_set_option($new_options);
    echo '<div class="updated fade"><p>' . __('Options saved!', 'hw-yarpp') . '</p></div>';
}
wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false);
wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false);
wp_nonce_field('hw_yarpp_display_demo', 'hw_yarpp_display_demo-nonce', false);
wp_nonce_field('hw_yarpp_display_exclude_terms', 'hw_yarpp_display_exclude_terms-nonce', false);
wp_nonce_field('hw_yarpp_optin_data', 'hw_yarpp_optin_data-nonce', false);
wp_nonce_field('hw_yarpp_set_display_code', 'hw_yarpp_set_display_code-nonce', false);
if (!count($hw_yarpp->admin->get_templates()) && $hw_yarpp->admin->can_copy_templates()) {
    wp_nonce_field('hw_yarpp_copy_templates', 'hw_yarpp_copy_templates-nonce', false);
}
include HW_YARPP_DIR . '/includes/phtmls/hw_yarpp_options.phtml';