function yarpp_reinforce() { if (!get_option('yarpp_version')) { yarpp_activate(); } yarpp_upgrade_check(true); }
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; }
function yarpp_related_exist($type, $args, $reference_ID = false) { global $post, $yarpp_cache; yarpp_upgrade_check(); if (is_object($post) and !$reference_ID) { $reference_ID = $post->ID; } if ($yarpp_cache->yarpp_time) { // if we're already in a YARPP loop, stop now. return false; } if (yarpp_get_option('cross_relate')) { $type = array('post', 'page'); } yarpp_cache_enforce($reference_ID); $yarpp_cache->begin_yarpp_time($reference_ID); // get ready for YARPP TIME! $related_query = new WP_Query(); // Note: why is this 10000? Should we just make it 1? $related_query->query(array('p' => $reference_ID, 'showposts' => 10000, 'post_type' => $type)); $return = $related_query->have_posts(); unset($related_query); $yarpp_cache->end_yarpp_time(); // YARPP time is over. :( return $return; }
<?php global $wpdb, $yarpp_value_options, $yarpp_binary_options, $wp_version, $yarpp_cache; // Reenforce YARPP setup: if (!get_option('yarpp_version')) { yarpp_activate(); } else { yarpp_upgrade_check(); } // if action=flush, reset the cache if (isset($_GET['action']) && $_GET['action'] == 'flush') { $yarpp_cache->flush(); } // check to see that templates are in the right place $yarpp_templateable = count(glob(STYLESHEETPATH . '/yarpp-template-*.php')) > 0; if (!$yarpp_templateable) { if (count(glob(WP_CONTENT_DIR . '/plugins/yet-another-related-posts-plugin/yarpp-templates/yarpp-template-*.php'))) { echo "<div class='updated'>" . str_replace("TEMPLATEPATH", STYLESHEETPATH, __("Please move the YARPP template files into your theme to complete installation. Simply move the sample template files (currently in <code>wp-content/plugins/yet-another-related-posts-plugin/yarpp-templates/</code>) to the <code>TEMPLATEPATH</code> directory.", 'yarpp')) . "</div>"; } else { echo "<div class='updated'>" . str_replace('TEMPLATEPATH', STYLESHEETPATH, __("No YARPP template files were found in your theme (<code>TEMPLATEPATH</code>) so the templating feature has been turned off.", 'yarpp')) . "</div>"; } yarpp_set_option('use_template', false); yarpp_set_option('rss_use_template', false); } 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();