Пример #1
0
function yarpp_activate()
{
    global $yarpp_version, $wpdb, $yarpp_binary_options, $yarpp_value_options, $yarpp_cache;
    foreach (array_keys($yarpp_value_options) as $option) {
        if (get_option("yarpp_{$option}") === false) {
            add_option("yarpp_{$option}", $yarpp_value_options[$option] . ' ');
        }
    }
    foreach (array_keys($yarpp_binary_options) as $option) {
        if (get_option("yarpp_{$option}") === false) {
            add_option("yarpp_{$option}", $yarpp_binary_options[$option]);
        }
    }
    $wpdb->get_results("show index from {$wpdb->posts} where Key_name='yarpp_title'");
    if (!$wpdb->num_rows) {
        $wpdb->query("ALTER TABLE {$wpdb->posts} ADD FULLTEXT `yarpp_title` ( `post_title` )");
    }
    $wpdb->get_results("show index from {$wpdb->posts} where Key_name='yarpp_content'");
    if (!$wpdb->num_rows) {
        $wpdb->query("ALTER TABLE {$wpdb->posts} ADD FULLTEXT `yarpp_content` ( `post_content` )");
    }
    if (!yarpp_enabled()) {
        // If we are still not enabled, run the cache abstraction's setup method.
        $yarpp_cache->setup();
        // If we're still not enabled, give up.
        if (!yarpp_enabled()) {
            return 0;
        }
    }
    if (!get_option('yarpp_version')) {
        add_option('yarpp_version', YARPP_VERSION);
        yarpp_version_json(true);
    } else {
        yarpp_upgrade_check();
    }
    return 1;
}
Пример #2
0
        // if it's not *exactly* true
        echo "<div class='updated'>" . sprintf(__("YARPP's \"consider titles\" and \"consider bodies\" relatedness criteria require your <code>%s</code> table to use the <a href='http://dev.mysql.com/doc/refman/5.0/en/storage-engines.html'>MyISAM storage engine</a>, but the table seems to be using the <code>%s</code> engine. These two options have been disabled.", 'yarpp'), $wpdb->posts, $yarpp_check_return) . "<br />" . sprintf(__("To restore these features, please update your <code>%s</code> table by executing the following SQL directive: <code>ALTER TABLE `%s` ENGINE = MyISAM;</code> . No data will be erased by altering the table's engine, although there are performance implications.", 'yarpp'), $wpdb->posts, $wpdb->posts) . "<br />" . sprintf(__("If, despite this check, you are sure that <code>%s</code> is using the MyISAM engine, press this magic button:", 'yarpp'), $wpdb->posts) . "<br />" . "<form method='post'><input type='submit' class='button' name='myisam_override' value='" . __("Trust me. Let me use MyISAM features.", 'yarpp') . "'></input></form>" . "</div>";
        yarpp_set_option('title', 1);
        yarpp_set_option('body', 1);
        $yarpp_myisam = false;
    }
}
$yarpp_twopointfive = true;
if (version_compare('2.5', $wp_version) > 0) {
    echo "{$wp_version}<div class='updated'>The \"consider tags\" and \"consider categories\" options require WordPress version 2.5. These two options have been disabled.</div>";
    yarpp_set_option('categories', 1);
    yarpp_set_option('tags', 1);
    $yarpp_twopointfive = false;
}
if ($yarpp_myisam) {
    if (!yarpp_enabled()) {
        echo '<div class="updated"><p>';
        if (yarpp_activate()) {
            _e('The YARPP database had an error but has been fixed.', 'yarpp');
        } else {
            __('The YARPP database has an error which could not be fixed.', 'yarpp') . str_replace('<A>', '<a href=\'http://mitcho.com/code/yarpp/sql.php?prefix=' . urlencode($wpdb->prefix) . '\'>', __('Please try <A>manual SQL setup</a>.', 'yarpp'));
        }
        echo '</div></p>';
    }
}
yarpp_reinforce();
// just in case, set default options, etc.
if (isset($_POST['update_yarpp'])) {
    foreach (array_keys($yarpp_value_options) as $option) {
        if (is_string($_POST[$option])) {
            yarpp_set_option($option, addslashes($_POST[$option]));
Пример #3
0
function yarpp_upgrade_check($inuse = false)
{
    global $wpdb, $yarpp_value_options, $yarpp_binary_options;
    foreach (array_keys($yarpp_value_options) as $option) {
        if (get_option("yarpp_{$option}", YARPP_UNLIKELY_DEFAULT) == YARPP_UNLIKELY_DEFAULT) {
            add_option("yarpp_{$option}", $yarpp_value_options[$option] . ' ');
        }
    }
    foreach (array_keys($yarpp_binary_options) as $option) {
        if (get_option("yarpp_{$option}", YARPP_UNLIKELY_DEFAULT) == YARPP_UNLIKELY_DEFAULT) {
            add_option("yarpp_{$option}", $yarpp_binary_options[$option]);
        }
    }
    // upgrade check
    if (get_option('threshold') and get_option('limit') and get_option('len')) {
        yarpp_activate();
        yarpp_upgrade_one_five();
        update_option('yarpp_version', '1.5');
    }
    if (version_compare('3.1.3', get_option('yarpp_version')) > 0) {
        $wpdb->query("ALTER TABLE {$wpdb->prefix}yarpp_related_cache DROP PRIMARY KEY ,\n                  ADD PRIMARY KEY ( score , date , reference_ID , ID )");
    }
    update_option('yarpp_version', YARPP_VERSION);
    // just in case, try to add the index one more time.
    if (!yarpp_enabled()) {
        $wpdb->query("ALTER TABLE {$wpdb->posts} ADD FULLTEXT `yarpp_title` ( `post_title`)");
        $wpdb->query("ALTER TABLE {$wpdb->posts} ADD FULLTEXT `yarpp_content` ( `post_content`)");
    }
}
Пример #4
0
if (isset($_POST['myisam_override'])) {
    yarpp_set_option('myisam_override', 1);
    echo "<div class='updated'>" . __("The MyISAM check has been overridden. You may now use the \"consider titles\" and \"consider bodies\" relatedness criteria.", 'yarpp') . "</div>";
}
$yarpp_myisam = true;
if (!yarpp_get_option('myisam_override')) {
    $yarpp_check_return = yarpp_myisam_check();
    if ($yarpp_check_return !== true) {
        // if it's not *exactly* true
        echo "<div class='updated'>" . sprintf(__("YARPP's \"consider titles\" and \"consider bodies\" relatedness criteria require your <code>%s</code> table to use the <a href='http://dev.mysql.com/doc/refman/5.0/en/storage-engines.html'>MyISAM storage engine</a>, but the table seems to be using the <code>%s</code> engine. These two options have been disabled.", 'yarpp'), $wpdb->posts, $yarpp_check_return) . "<br />" . sprintf(__("To restore these features, please update your <code>%s</code> table by executing the following SQL directive: <code>ALTER TABLE `%s` ENGINE = MyISAM;</code> . No data will be erased by altering the table's engine, although there are performance implications.", 'yarpp'), $wpdb->posts, $wpdb->posts) . "<br />" . sprintf(__("If, despite this check, you are sure that <code>%s</code> is using the MyISAM engine, press this magic button:", 'yarpp'), $wpdb->posts) . "<br />" . "<form method='post'><input type='submit' class='button' name='myisam_override' value='" . __("Trust me. Let me use MyISAM features.", 'yarpp') . "'></input></form>" . "</div>";
        yarpp_set_option('title', 1);
        yarpp_set_option('body', 1);
        $yarpp_myisam = false;
    }
}
if ($yarpp_myisam && !yarpp_enabled()) {
    echo '<div class="updated"><p>';
    if (yarpp_activate()) {
        _e('The YARPP database had an error but has been fixed.', 'yarpp');
    } else {
        __('The YARPP database has an error which could not be fixed.', 'yarpp') . str_replace('<A>', '<a href=\'http://mitcho.com/code/yarpp/sql.php?prefix=' . urlencode($wpdb->prefix) . '\'>', __('Please try <A>manual SQL setup</a>.', 'yarpp'));
    }
    echo '</div></p>';
}
if (isset($_POST['update_yarpp'])) {
    foreach (array_keys($yarpp_value_options) as $option) {
        if (isset($_POST[$option]) && is_string($_POST[$option])) {
            yarpp_set_option($option, addslashes($_POST[$option]));
        }
    }
    foreach (array('title', 'body', 'tags', 'categories') as $key) {
function yarpp_upgrade_check($inuse = false)
{
    global $wpdb, $yarpp_value_options, $yarpp_binary_options;
    foreach (array_keys($yarpp_value_options) as $option) {
        if (!get_option("yarpp_{$option}") or get_option("yarpp_{$option}") == '') {
            add_option("yarpp_{$option}", $yarpp_value_options[$option] . ' ');
        }
    }
    foreach (array_keys($yarpp_binary_options) as $option) {
        if (!get_option("yarpp_{$option}") or get_option("yarpp_{$option}") == '') {
            add_option("yarpp_{$option}", $yarpp_binary_options[$option] . " ");
        }
    }
    // upgrade check
    if (get_option('threshold') and get_option('limit') and get_option('len')) {
        yarpp_activate();
        yarpp_upgrade_one_five();
        update_option('yarpp_version', '1.5');
    }
    if (get_option('yarpp_version') < 2) {
        foreach (array_keys($yarpp_value_options) as $option) {
            if (!get_option("yarpp_{$option}")) {
                add_option("yarpp_{$option}", $yarpp_value_options[$option] . ' ');
            }
        }
        foreach (array_keys($yarpp_binary_options) as $option) {
            if (!get_option("yarpp_{$option}")) {
                add_option("yarpp_{$option}", $yarpp_binary_options[$option]);
            }
        }
        if (!$inuse) {
            echo '<div id="message" class="updated fade" style="background-color: rgb(207, 235, 247);">' . __('<h3>An important message from YARPP:</h3><p>Thank you for upgrading to YARPP 2. YARPP 2.0 adds the much requested ability to limit related entry results by certain tags or categories. 2.0 also brings more fine tuned control of the magic algorithm, letting you specify how the algorithm should consider or not consider entry content, titles, tags, and categories. Make sure to adjust the new settings to your liking and perhaps readjust your threshold.</p><p>For more information, check out the <a href="http://mitcho.com/code/yarpp/">YARPP documentation</a>. (This message will not be displayed again.)</p>', 'yarpp') . '</div>';
        }
    }
    if (get_option('yarpp_version') < 2.03) {
        $wpdb->query("ALTER TABLE {$wpdb->posts} ADD FULLTEXT `yarpp_title` ( `post_title`)");
        $wpdb->query("ALTER TABLE {$wpdb->posts} ADD FULLTEXT `yarpp_content` ( `post_content`)");
        update_option('yarpp_version', '2.03');
    }
    if (get_option('yarpp_version') < 2.16) {
        update_option('yarpp_version', '2.16');
    }
    // just in case, try to add the index one more time.
    if (!yarpp_enabled()) {
        $wpdb->query("ALTER TABLE {$wpdb->posts} ADD FULLTEXT `yarpp_title` ( `post_title`)");
        $wpdb->query("ALTER TABLE {$wpdb->posts} ADD FULLTEXT `yarpp_content` ( `post_content`)");
    }
}