function yarpp_related_exist($type, $args)
{
    global $wpdb, $post;
    $options = array('threshold' => 'threshold', 'show_pass_post' => 'show_pass_post', 'past_only' => 'past_only');
    $optvals = array();
    foreach (array_keys($options) as $option) {
        if (isset($args[$option])) {
            $optvals[$option] = stripslashes($args[$option]);
        } else {
            $optvals[$option] = stripslashes(stripslashes(yarpp_get_option($options[$option])));
        }
    }
    extract($optvals);
    $result = $wpdb->get_var(yarpp_sql($type, $args, false, $domain));
    return $result > 0 ? true : false;
}
예제 #2
0
 function update($reference_ID)
 {
     global $wpdb, $yarpp_debug;
     // $reference_ID must be numeric
     if (!is_int($reference_ID)) {
         return new WP_Error('yarpp_cache_error', "update's reference ID must be an int");
     }
     $original_related = $this->related($reference_ID);
     //error_log('original:' . implode(':', $original_related));
     // clear out the cruft
     $this->clear($reference_ID);
     $wpdb->query("insert into {$wpdb->prefix}" . YARPP_TABLES_RELATED_TABLE . " (reference_ID,ID,score) " . yarpp_sql(array(), true, $reference_ID) . " on duplicate key update date = now()");
     if ($wpdb->rows_affected) {
         $new_related = $this->related($reference_ID);
         //error_log('new:' . implode(':', $new_related));
         if ($yarpp_debug) {
             echo "<!--YARPP just set the cache for post {$reference_ID}-->";
         }
         // Clear the caches of any items which are no longer related or are newly related.
         if (count($original_related)) {
             $this->clear(array_diff($original_related, $new_related));
             $this->clear(array_diff($new_related, $original_related));
         }
     } else {
         $wpdb->query("insert into {$wpdb->prefix}" . YARPP_TABLES_RELATED_TABLE . " (reference_ID,ID,score) values ({$reference_ID},0,0) on duplicate key update date = now()");
         if (!$wpdb->rows_affected) {
             return false;
         }
         // Clear the caches of those which are no longer related.
         if (count($original_related)) {
             $this->clear($original_related);
         }
     }
 }
예제 #3
0
" title="Bookmark at Digg" rel="nofollow" target="_blank"><img src="<?php 
        bloginfo('template_directory');
        ?>
/images/ico-soc4.gif" alt="Icon" /></a> </div>
        <div class="clr"></div>
      </div>
      <div class="clr"></div>
    </div>
    <!--/box -->
    <div class="box post-rel">
      <div class="content border">
        <div class="subcols">
          <div class="col1">
            <h2>Related Posts</h2>
            <?php 
        $results = $wpdb->get_results(yarpp_sql(array('post'), array()));
        foreach ((array) $results as $_post) {
            $_post = get_post($_post->ID);
            ?>
            <div class="th fl"><a href="<?php 
            echo get_permalink($_post->ID);
            ?>
"><img src="<?php 
            echo get_post_meta($_post->ID, 'post-img', true);
            ?>
" alt="" /></a></div>
            <div><a href="<?php 
            echo get_permalink($_post->ID);
            ?>
"><?php 
            echo $_post->post_title;
예제 #4
0
 function update($reference_ID)
 {
     global $wpdb, $yarpp_debug;
     // $reference_ID must be numeric
     if (!is_int($reference_ID)) {
         return new WP_Error('yarpp_cache_error', "reference ID must be an int");
     }
     $original_related = $this->related($reference_ID);
     $related = $wpdb->get_results(yarpp_sql(array(), true, $reference_ID), ARRAY_A);
     $new_related = array_map(create_function('$x', 'return $x["ID"];'), $related);
     if (count($new_related)) {
         update_post_meta($reference_ID, YARPP_POSTMETA_RELATED_KEY, $related);
         if ($yarpp_debug) {
             echo "<!--YARPP just set the cache for post {$reference_ID}-->";
         }
         // Clear the caches of any items which are no longer related or are newly related.
         if (count($original_related)) {
             $this->clear(array_diff($original_related, $new_related));
             $this->clear(array_diff($new_related, $original_related));
         }
     } else {
         update_post_meta($reference_ID, YARPP_POSTMETA_RELATED_KEY, YARPP_NO_RELATED);
         // Clear the caches of those which are no longer related.
         if (count($original_related)) {
             $this->clear($original_related);
         }
     }
 }
예제 #5
0
function yarpp_cache_enforce($type = array('post'), $reference_ID, $force = false)
{
    global $wpdb, $yarpp_debug;
    if ($reference_ID === '' || $reference_ID === false) {
        return false;
    }
    if (!$force) {
        if ($wpdb->get_var("select count(*) as count from {$wpdb->prefix}yarpp_related_cache where reference_ID = {$reference_ID}")) {
            // 3.1.3: removed the cache timeout
            // and date > date_sub(now(),interval 600 minute)
            if ($yarpp_debug) {
                echo "<!--YARPP is using the cache right now.-->";
            }
            return false;
        }
    }
    yarpp_cache_keywords($reference_ID);
    // clear out the cruft
    yarpp_cache_clear(array($reference_ID));
    // let's update the related posts
    $wpdb->query("insert into {$wpdb->prefix}yarpp_related_cache (reference_ID,ID,score) " . yarpp_sql($type, array(), true, $reference_ID) . " on duplicate key update date = now()");
    $affected = $wpdb->rows_affected;
    if ($affected and $yarpp_debug) {
        echo "<!--YARPP just set the cache for post {$reference_ID}-->";
    }
    // if changes were made, let's find out which ones are new. We'll want to clear their caches
    // so that they will be rebuilt when they're hit next.
    if ($affected && !yarpp_get_option('past_only')) {
        $new_relations = $wpdb->get_col("select ID from {$wpdb->prefix}yarpp_related_cache where reference_ID = {$reference_ID} and ID != 0");
        yarpp_cache_clear($new_relations);
    }
    if (!$affected) {
        $wpdb->query("insert into {$wpdb->prefix}yarpp_related_cache (reference_ID,ID,score) values ({$reference_ID},0,0) on duplicate key update date = now()");
        if (!$wpdb->rows_affected) {
            return false;
        }
    }
    return true;
}