WordPress.org

Plugin Directory

Changeset 804358


Ignore:
Timestamp:
11/14/13 12:27:59 (5 months ago)
Author:
donncha
Message:
  • Correctly fetch ratings for the last 2 days from Polldaddy
  • Use hreview-aggregate for rich snippets
File:
1 edited

Legend:

Unmodified
Added
Removed
  • polldaddy/trunk/polldaddy-org.php

    r792441 r804358  
    10311031    global $polldaddy_object; 
    10321032    $polldaddy = $polldaddy_object->get_client( WP_POLLDADDY__PARTNERGUID, get_option( 'pd-rating-usercode' ) ); 
    1033     $response = $polldaddy->get_rating_results( $rating[ 'id' ], 2, 0, 15 ); 
    1034     $ratings = $response->ratings; 
    1035     if ( empty( $ratings ) ) 
    1036         return false; 
    1037  
    1038     polldaddy_update_ratings_cache( $ratings ); 
     1033    $rating_id = get_option( 'pd-rating-posts-id' ); 
     1034    $finished = false; 
     1035    $c = 0; 
     1036    while ( !$finished ) { 
     1037        $response = $polldaddy->get_rating_results( $rating_id, 2, $c, 50 ); 
     1038        $ratings = $response->rating; 
     1039        if ( false == is_array( $ratings ) ) 
     1040            $finished = true; 
     1041        else 
     1042            polldaddy_update_ratings_cache( $ratings ); 
     1043        $c += 50; 
     1044        if ( $c > 1000 ) // gotta stop somewhere 
     1045            $finished = true; 
     1046    } 
     1047    return true; 
    10391048} 
    10401049 
     
    10671076    else 
    10681077        $average = $rating[ 'average' ]; 
    1069     return $content . ' 
    1070         <div itemtype="http://schema.org/AggregateRating" itemscope itemprop="aggregateRating"> 
    1071         <meta itemprop="ratingValue" content=' . $average . '> 
    1072         <meta itemprop="ratingCount" content=' . $rating[0][ 'votes' ] . '> 
    1073         </div>'; 
     1078    if ( $average < 0 ) 
     1079        return $content; 
     1080    global $post; 
     1081    return $content . '<span class="hreview-aggregate"><span class="item"><span class="fn">"' . $post->post_title . '"</span></span>, <span class="rating"><span class="average">' . $average . '</span> out of <span class="best">5</span> based on <span class="votes">' . $rating[0][ 'votes' ] . '</span> ratings.</span></span>'; 
    10741082} 
    10751083add_filter( 'the_content', 'polldaddy_post_rating' ); 
Note: See TracChangeset for help on using the changeset viewer.